# LSTM and LSTMCell ？

**URL:** <https://discuss.pytorch.org/t/lstm-and-lstmcell/7488>\
**Category:** Uncategorized\
**Created:** [September 17, 2017, 5:28am UTC](https://discuss.pytorch.org/t/lstm-and-lstmcell/7488 "2017-09-17T05:28:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bamtercelboo](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/b/58956e/32.png) [@bamtercelboo](https://discuss.pytorch.org/u/bamtercelboo)\
**Post date:** [September 17, 2017, 5:28am UTC](https://discuss.pytorch.org/t/lstm-and-lstmcell/7488/1 "2017-09-17T05:28:11Z")

</div>

I want to know the difference between the LSTM and LSTMCell in the pytorch document？And how to use it correctly.

---

<div class="post-metadata">

**Author:** ![tlaurent](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tlaurent/32/1502_2.png) [@tlaurent](https://discuss.pytorch.org/u/tlaurent)\
**Post date:** [September 17, 2017, 4:41pm UTC](https://discuss.pytorch.org/t/lstm-and-lstmcell/7488/2 "2017-09-17T16:41:30Z")

</div>

LSTMCell takes ONE input x\_t. You need to make a loop in order to do one pass of backprop through time.

LSTM takes a SEQUENCE of inputs x\_1,x\_2,…,x\_T. No need to write a loop to do one pass of backprop through time.

---

<div class="post-metadata">

**Author:** ![bamtercelboo](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/b/58956e/32.png) [@bamtercelboo](https://discuss.pytorch.org/u/bamtercelboo)\
**Post date:** [September 18, 2017, 12:45am UTC](https://discuss.pytorch.org/t/lstm-and-lstmcell/7488/3 "2017-09-18T00:45:15Z")

</div>

ok, Thanks for your answer, Is there any other difference?

---

<div class="post-metadata">

**Author:** ![bamtercelboo](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/b/58956e/32.png) [@bamtercelboo](https://discuss.pytorch.org/u/bamtercelboo)\
**Post date:** [September 18, 2017, 12:46am UTC](https://discuss.pytorch.org/t/lstm-and-lstmcell/7488/4 "2017-09-18T00:46:19Z")

</div>

@tlaurent ok, Thanks for your answer, Is there any other difference?

---

<div class="post-metadata">

**Author:** ![tlaurent](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tlaurent/32/1502_2.png) [@tlaurent](https://discuss.pytorch.org/u/tlaurent)\
**Post date:** [September 18, 2017, 1:45am UTC](https://discuss.pytorch.org/t/lstm-and-lstmcell/7488/5 "2017-09-18T01:45:23Z")

</div>

I would guess that using LSTM() is faster than writing your own loop with LSTMCell (because it is optimized by cudnn).

---

<div class="post-metadata">

**Author:** ![bamtercelboo](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/b/58956e/32.png) [@bamtercelboo](https://discuss.pytorch.org/u/bamtercelboo)\
**Post date:** [September 19, 2017, 2:34am UTC](https://discuss.pytorch.org/t/lstm-and-lstmcell/7488/6 "2017-09-19T02:34:04Z")

</div>

@tlaurent ok thanks gor your answer, I will try it.

---

<div class="post-metadata">

**Author:** ![nibor](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/nibor/32/17941_2.png) [@nibor](https://discuss.pytorch.org/u/nibor)\
**Post date:** [November 20, 2019, 10:46am UTC](https://discuss.pytorch.org/t/lstm-and-lstmcell/7488/7 "2019-11-20T10:46:18Z")

</div>

LSTMCell() is the building block of the LSTM(). In LSTM(), there are multiple LSTMCell() in one layer as equal as sequence length or unrolling length of network.

---

<div class="post-metadata">

**Author:** ![Carlos\_Jose\_Gonzalez](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/carlos_jose_gonzalez/32/12367_2.png) [@Carlos\_Jose\_Gonzalez](https://discuss.pytorch.org/u/Carlos_Jose_Gonzalez)\
**Post date:** [February 22, 2021, 5:14pm UTC](https://discuss.pytorch.org/t/lstm-and-lstmcell/7488/8 "2021-02-22T17:14:58Z")

</div>

I made this example, I hope it helps [RNNs/LSTMCellvsLSTM.ipynb at main · CarlosJose126/RNNs · GitHub](https://github.com/CarlosJose126/RNNs/blob/main/LSTMCellvsLSTM.ipynb)
