-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Resume get RuntimeError: expected type torch.FloatTensor but got torch.cuda.FloatTensor #522
Comments
Did this error occur after you pulled the merged version? The lines:
Weren't actually removed, they were only moved up, so the model is transferred to the GPU prior to the optimizer being initialized. EDIT: The merge was for the pytorch-1.0 branch btw, perhaps it should still be merged into pytorch-0.4.0/main branch |
Yes. I use pytorch1.0 branch, train and resume with --cuda. Before I edit, above the line
there are no
they are below line
And I add those lines above "adam", and it worked. |
Ah okay.
Above the optimizer initialization (see here). It is mentioned in the PyTorch documentation that it is best practice to first move the model to the GPU prior to initializing the optimizer. That way the optimizer will automatically/correctly be moved to the GPU as well. Are you still running into a problem or error? |
No, the problem is solved. Thx for your reply. It seems that I clone before the commit that fix 'solve error when resuming training'. My fault.. Thx again. |
@LinSHP if problem is solved, please go ahead and close the issue |
When I resume training, I encountered a Runtime error
Traceback (most recent call last): File "trainval_net.py", line 339, in <module> optimizer.step() File "/pytorch/lib/python3.6/site-packages/torch/optim/sgd.py", line 101, in step buf.mul_(momentum).add_(1 - dampening, d_p) RuntimeError: expected type torch.FloatTensor but got torch.cuda.FloatTensor
I search through the issues and find issue #475 has the same error. But it seems the problem has been solved and merged.
So I add the lines that the merge request removed and problem is solved.
add lines
So I think there are still some problems with the RuntimeError.
The text was updated successfully, but these errors were encountered: