Skip to content

fix usage of gpu #11

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

Conversation

alishahali1382
Copy link
Contributor

when calling model.to(device), a new instance of model is created and loaded on the device and returns the new model. But by calling this and using the previous model, all operations are performed on the previous device (here it is cpu).
therefore GPU is not used in current code.

@amirhossein-razlighi
Copy link
Collaborator

Please look at the example below:

model = nn.Linear(1, 1)
print(model.weight.device)
> cpu
model.cuda()
print(model.weight.device)
> cuda:0

x = torch.randn(1)
print(x.device)
> cpu
x.cuda() # ERROR!!!
print(x.device)
> cpu

So, as you can see, despite tensors, the nn.Module instances' weights are moved to the cuda device inplace! So, no bugs here as self.model is an instance of nn.Module and not a tensor.
Please refer to this discussion on PyTorch's forum for further info.

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

Successfully merging this pull request may close these issues.

2 participants