Hi, I’m following the exact same tutorial as here: http://opennmt.net/OpenNMT-py/Library.html , but unfortunately get the error log as this (This is the error log with PyTorch 1.0.1.post2
:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-7-d303a24fca32> in <module>
9 train_steps=400,
10 valid_iter=valid_iter,
---> 11 valid_steps=200)
~/OpenNMT-py/onmt/trainer.py in train(self, train_iter, train_steps, save_checkpoint_steps, valid_iter, valid_steps)
207 self._gradient_accumulation(
208 batches, normalization, total_stats,
--> 209 report_stats)
210
211 if self.average_decay > 0 and i % self.average_every == 0:
~/OpenNMT-py/onmt/trainer.py in _gradient_accumulation(self, true_batches, normalization, total_stats, report_stats)
327 shard_size=self.shard_size,
328 trunc_start=j,
--> 329 trunc_size=trunc_size)
330
331 if loss is not None:
~/OpenNMT-py/onmt/utils/loss.py in __call__(self, batch, output, attns, normalization, shard_size, trunc_start, trunc_size)
156 batch_stats = onmt.utils.Statistics()
157 for shard in shards(shard_state, shard_size):
--> 158 loss, stats = self._compute_loss(batch, **shard)
159 loss.div(float(normalization)).backward()
160 batch_stats.update(stats)
~/OpenNMT-py/onmt/utils/loss.py in _compute_loss(self, batch, output, target)
231 bottled_output = self._bottle(output)
232
--> 233 scores = self.generator(bottled_output)
234 gtruth = target.view(-1)
235
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
--> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/container.py in forward(self, input)
90 def forward(self, input):
91 for module in self._modules.values():
---> 92 input = module(input)
93 return input
94
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
--> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/linear.py in forward(self, input)
65 @weak_script_method
66 def forward(self, input):
---> 67 return F.linear(input, self.weight, self.bias)
68
69 def extra_repr(self):
~/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py in linear(input, weight, bias)
1350 if input.dim() == 2 and bias is not None:
1351 # fused op is marginally faster
-> 1352 ret = torch.addmm(torch.jit._unwrap_optional(bias), input, weight.t())
1353 else:
1354 output = input.matmul(weight.t())
RuntimeError: Expected object of backend CPU but got backend CUDA for argument #4 'mat1'
My PyTorch version is '1.0.1.post2'
, GPU is GTX 1080Ti
, could someone help me out please? Is OpenNMT not compatible with the latest version of PyTorch?
UPDATE: I tried to downgrade my PyTorch version to 0.4.1
(with everything else the same) however i still get this error log. Seems like the data is still on CPU and not GPU, even though I have passed the correct device parameter = cuda
to DatasetLazyIter
. The code is exact same as the one here: http://opennmt.net/OpenNMT-py/Library.html (no changes to it, even the data is same).
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-8-d303a24fca32> in <module>
9 train_steps=400,
10 valid_iter=valid_iter,
---> 11 valid_steps=200)
~/OpenNMT-py/onmt/trainer.py in train(self, train_iter, train_steps, save_checkpoint_steps, valid_iter, valid_steps)
207 self._gradient_accumulation(
208 batches, normalization, total_stats,
--> 209 report_stats)
210
211 if self.average_decay > 0 and i % self.average_every == 0:
~/OpenNMT-py/onmt/trainer.py in _gradient_accumulation(self, true_batches, normalization, total_stats, report_stats)
327 shard_size=self.shard_size,
328 trunc_start=j,
--> 329 trunc_size=trunc_size)
330
331 if loss is not None:
~/OpenNMT-py/onmt/utils/loss.py in __call__(self, batch, output, attns, normalization, shard_size, trunc_start, trunc_size)
156 batch_stats = onmt.utils.Statistics()
157 for shard in shards(shard_state, shard_size):
--> 158 loss, stats = self._compute_loss(batch, **shard)
159 loss.div(float(normalization)).backward()
160 batch_stats.update(stats)
~/OpenNMT-py/onmt/utils/loss.py in _compute_loss(self, batch, output, target)
231 bottled_output = self._bottle(output)
232
--> 233 scores = self.generator(bottled_output)
234 gtruth = target.view(-1)
235
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
475 result = self._slow_forward(*input, **kwargs)
476 else:
--> 477 result = self.forward(*input, **kwargs)
478 for hook in self._forward_hooks.values():
479 hook_result = hook(self, input, result)
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/container.py in forward(self, input)
89 def forward(self, input):
90 for module in self._modules.values():
---> 91 input = module(input)
92 return input
93
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
475 result = self._slow_forward(*input, **kwargs)
476 else:
--> 477 result = self.forward(*input, **kwargs)
478 for hook in self._forward_hooks.values():
479 hook_result = hook(self, input, result)
~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/linear.py in forward(self, input)
53
54 def forward(self, input):
---> 55 return F.linear(input, self.weight, self.bias)
56
57 def extra_repr(self):
~/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py in linear(input, weight, bias)
1022 if input.dim() == 2 and bias is not None:
1023 # fused op is marginally faster
-> 1024 return torch.addmm(bias, input, weight.t())
1025
1026 output = input.matmul(weight.t())
RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #4 'mat1'