I meet a few error at the very beginning of the tutorial

I am currently running the very beginning of the tutorial.

(Note. my version is 0.4.0 for Pytorch)

At the second step, I meet a few error and asking for solutions of these.

python train.py -data data/demo -save_model demo-model

The first error is that inside “OpenNMT-py/onmt/Models.py” line 611, give me an error like:

  File "OpenNMT-py/onmt/Models.py", line 611, in detach
    h.detach_()
RuntimeError: Can't detach views in-place. Use detach() instead

So I simply change it to detach() from detach_() as it recommended.

Also, after I fix it, I meet an another error in below of “OpenNMT-py/onmt/Loss.py”.

RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.

To fix this, I add “retain_graph=True”.
After then, I meet an another error in “OpenNMT-py/onmt/Trainer.py”, line 51, in ppl". The error message is:

File "OpenNMT-py/onmt/Trainer.py", line 51, in ppl
    return math.exp(min(self.loss / self.n_words, 100))
RuntimeError: Expected object of type torch.FloatTensor but found type torch.LongTensor for argument #2 'other'

Now, I have no ideas to fix this.

The problem is solved, I just degrade pytorch to 0.3.1 from 0.4.0

that also worked for me, thanks!