Issue
I am trying to move my device onto a gpu. After running the function to determine if there is an available GPU, and determined there is one (see below)
> device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
> device
device(type='cuda', index=0)
When I call model.to(device)
I get no change in the model attribute?
> model.to(device)
S2SModel(
(encoder): Encoder(
(lstm): LSTM(5, 32, batch_first=True)
)
(decoder): Decoder(
(lstm): LSTM(4, 32, batch_first=True)
)
(output_layer): Linear(in_features=32, out_features=1, bias=True)
)
> model.device
'cpu'
Though I have read that you do not need to assign the model.to()
calls back to the object, i have tried that too.
> model = model.to(device)
> model.device
'cpu'
Solution
device
is likely to be a user-defined attribute here that is different to the actual device the model sits on. This seems to be the reason why model.device
returns 'cpu' To check if your model is on CPU or GPU, you can look at its first parameter:
>>> next(model.parameters()).device
Answered By - Ivan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.