Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! #106

Open
treeson-li opened this issue Sep 4, 2021 · 1 comment

Comments

@treeson-li
Copy link

I use Py-THUMT as the framework of new NMT algorithm. I only replace Transformer with another module and other parts remain unchanged. I use THUMT add_name() to add parameters to variables pool. When I run the code, I encount the following error. I don't know what reason cause the error. Would you give me some advice?

Traceback (most recent call last):
File "../neuron/thumt/bin/trainer.py", line 528, in
cli_main()
File "../neuron/thumt/bin/trainer.py", line 524, in cli_main
process_fn(0, parsed_args)
File "../neuron/thumt/bin/trainer.py", line 502, in process_fn
main(local_args)
File "../neuron/thumt/bin/trainer.py", line 467, in main
optimizer.apply_gradients(grads_and_vars)
File "/data/code/nmt/neuron/thumt/optimizers/optimizers.py", line 480, in apply_gradients
self.optimizer.apply_gradients(zip(grads, var_list))
File "/data/code/nmt/neuron/thumt/optimizers/optimizers.py", line 231, in apply_gradients
m.mul
(beta_1).add_(grad, alpha=1 - beta_1)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

@treeson-li
Copy link
Author

This bug is caused by tensors defined by torch.FloatTensor(), while all tensors in the original framework are defined by torch.Tensor(). Why this happens is unknown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant