# RNN and It's Variant Starting Point in Pytorch

**URL:** <https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858>\
**Category:** vision\
**Created:** [July 13, 2017, 5:05pm UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858 "2017-07-13T17:05:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![herleeyandi](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/herleeyandi/32/948_2.png) [@herleeyandi](https://discuss.pytorch.org/u/herleeyandi)\
**Post date:** [July 13, 2017, 5:05pm UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858/1 "2017-07-13T17:05:47Z")

</div>

Hello I am really new in pytorch. I really like Pytorch because it so helpful and giving a good tutorial, however sometimes it not in complete form. Last Time I have try to learn RNN and it’s variant like LSTM, and GRU. I follow this tutorial [NLP From Scratch: Classifying Names with a Character-Level RNN — PyTorch Tutorials 2.2.0+cu121 documentation](http://pytorch.org/tutorials/intermediate/char_rnn_classification_tutorial.html) . I see the graph like this 🙂 ![](https://discuss.pytorch.org/uploads/default/original/1X/20df562367fbe3f99550b4ad8b8d075203f97796.png)  
It is the graph of RNN. Where I can find similar guide to implement LSTM and GRU in pytorch?  
Is there any suggestion where I can start to learn “Stacked LSTM” in pytorch?  
Is it possible to continue the pytorch tutorial completely?, since it looks like never been updated in the long time.  
-Thank you-

---

<div class="post-metadata">

**Author:** ![dgriff](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dgriff/32/1361_2.png) [@dgriff](https://discuss.pytorch.org/u/dgriff)\
**Post date:** [July 13, 2017, 8:36pm UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858/2 "2017-07-13T20:36:21Z")

</div>

As pytorch is a library for efficient creation of models and so they provide built in classes for lstm and gru for you. No need to create yourself but as always you can always create your own custom class for them. The code and formulas for lstm and gru classes can be found here: [https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/rnn.py](https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/rnn.py)

---

<div class="post-metadata">

**Author:** ![samarth-robo](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/samarth-robo/32/3487_2.png) [@samarth-robo](https://discuss.pytorch.org/u/samarth-robo)\
**Post date:** [July 13, 2017, 9:34pm UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858/3 "2017-07-13T21:34:28Z")

</div>

I also have some sample code [here](https://discuss.pytorch.org/t/resolved-lstm-with-image-data-how-to-save-gpu-memory/4231/2?u=samarth-robo).

---

<div class="post-metadata">

**Author:** ![dgriff](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dgriff/32/1361_2.png) [@dgriff](https://discuss.pytorch.org/u/dgriff)\
**Post date:** [July 13, 2017, 9:38pm UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858/4 "2017-07-13T21:38:53Z")

</div>

This blog also provides a great breakdown of lstm networks: [http://colah.github.io/posts/2015-08-Understanding-LSTMs/](http://colah.github.io/posts/2015-08-Understanding-LSTMs/)

---

<div class="post-metadata">

**Author:** ![herleeyandi](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/herleeyandi/32/948_2.png) [@herleeyandi](https://discuss.pytorch.org/u/herleeyandi)\
**Post date:** [July 14, 2017, 12:24am UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858/5 "2017-07-14T00:24:20Z")

</div>

Thank you for Reply, based on the tutorial links, I want to use that as video classification. Which of the picture is true?

 ![](https://discuss.pytorch.org/uploads/default/original/1X/b4c62c0e873e17a3cb1124104ffda475d25ee456.png)

---

<div class="post-metadata">

**Author:** ![hughperkins](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/hughperkins/32/915_2.png) [@hughperkins](https://discuss.pytorch.org/u/hughperkins)\
**Post date:** [July 14, 2017, 12:28am UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858/6 "2017-07-14T00:28:41Z")

</div>

My immediate reaction is, obviously the first one, since you have a sequence.

However, if you’re always using eaxctly four frames, you can actually do either, and see which works well for you.

The second version will run faster, since more easily parallelizable. The first one invokes Amdahls law, and is slow-tastic.

---

<div class="post-metadata">

**Author:** ![dgriff](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dgriff/32/1361_2.png) [@dgriff](https://discuss.pytorch.org/u/dgriff)\
**Post date:** [July 14, 2017, 2:42am UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858/7 "2017-07-14T02:42:45Z")

</div>

The second one as your doing video is the general format for sequences

first one would be the nn.LSTMCELL

second one is layer nn.LSTM

---

<div class="post-metadata">

**Author:** ![herleeyandi](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/herleeyandi/32/948_2.png) [@herleeyandi](https://discuss.pytorch.org/u/herleeyandi)\
**Post date:** [July 24, 2017, 8:17am UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858/8 "2017-07-24T08:17:48Z")

</div>

Anyone know in here how to implement `stacked LSTM` ?

---

<div class="post-metadata">

**Author:** ![moskomule](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/moskomule/32/4429_2.png) [@moskomule](https://discuss.pytorch.org/u/moskomule)\
**Post date:** [July 24, 2017, 11:18pm UTC](https://discuss.pytorch.org/t/rnn-and-its-variant-starting-point-in-pytorch/4858/9 "2017-07-24T23:18:05Z")

</div>

HI, `num_layers` argument stacks `LSTM` layers
