Opennmt-py: RuntimeError: Trying to backward through the graph a second time

Created on 28 Mar 2018  路  1Comment  路  Source: OpenNMT/OpenNMT-py

i came across the following error with pytorch 0.4.0
(commit id : 0f198fa7239fff38f0d9e21025faa19b7d9ff466):

Loading train dataset from data/demo.train.1.pt, number of examples: 10000
/home/zhaoxiao/test/OpenNMT-py/onmt/modules/GlobalAttention.py:176: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
align_vectors = self.sm(align.view(batch*targetL, sourceL))
/home/zhaoxiao/anaconda3-cpu/envs/pytorch-040/lib/python3.6/site-packages/torch/nn/modules/container.py:91: UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.
input = module(input)
/home/zhaoxiao/test/OpenNMT-py/onmt/Loss.py:144: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
return onmt.Statistics(loss[0], non_padding.sum(), num_correct)
Traceback (most recent call last):
File "train.py", line 438, in
main()
File "train.py", line 430, in main
train_model(model, fields, optim, data_type, model_opt)
File "train.py", line 252, in train_model
train_stats = trainer.train(train_iter, epoch, report_func)
File "/home/zhaoxiao/test/OpenNMT-py/onmt/Trainer.py", line 178, in train
report_stats, normalization)
File "/home/zhaoxiao/test/OpenNMT-py/onmt/Trainer.py", line 311, in _gradient_accumulation
trunc_size, self.shard_size, normalization)
File "/home/zhaoxiao/test/OpenNMT-py/onmt/Loss.py", line 124, in sharded_compute_loss
loss.div(normalization).backward()
File "/home/zhaoxiao/anaconda3-cpu/envs/pytorch-040/lib/python3.6/site-packages/torch/autograd/variable.py", line 120, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "/home/zhaoxiao/anaconda3-cpu/envs/pytorch-040/lib/python3.6/site-packages/torch/autograd/__init__.py", line 81, in backward
variables, grad_variables, retain_graph, create_graph)
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.

Most helpful comment

0.4 is not released yet, so currently we only support 0.3. We will try to move to 0.4 when it nears release.

>All comments

0.4 is not released yet, so currently we only support 0.3. We will try to move to 0.4 when it nears release.

Was this page helpful?
0 / 5 - 0 ratings