PyTorch-Tutorial icon indicating copy to clipboard operation
PyTorch-Tutorial copied to clipboard

PyTorch-Tutorial/tutorial-contents/403_RNN_regressor.py contains a weird line of code

Open BlackTentacle opened this issue 7 years ago • 3 comments

I tried some RNN regression learning based on the code in the "PyTorch-Tutorial/tutorial-contents/403_RNN_regressor.py" file, which did not work for me at all.

According to an accepted answer on stack-overflow (https://stackoverflow.com/questions/52857213/recurrent-network-rnn-wont-learn-a-very-simple-function-plots-shown-in-the-q?noredirect=1#comment92916825_52857213), it turns out that the line

h_state = h_state.data

of the tutorial file does not do what it is supposed to be doing. It does not actually break the connection to the previous iteration as specified in the commment. Rather the line

h_state = None

should do the trick (according to the accepted answer).

BlackTentacle avatar Oct 26 '18 20:10 BlackTentacle

Indeed, I guess the comment is for the case whereby elements in batches are unrelated, like the MNIST example, however the code is correct here for continuous data.

simon19891101 avatar Oct 27 '18 03:10 simon19891101

Is the bug related to pytorch's version? The pytorch '0.4.1' runs fine.

MorvanZhou avatar Oct 29 '18 01:10 MorvanZhou

when I use torchvision.datasets.MNIST, why occurs TypeError: init() missing 1 required positional argument: 'total'

SkatingLiu avatar Mar 08 '19 05:03 SkatingLiu