Cannot change device of pytorch model
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)
&gt; device = torch.device(&quot;cuda:0&quot; if torch.cuda.is_available() else &quot;cpu&quot;)
&gt; device
device(type='cuda', index=0)

When I call model.to(device) I get no change in the model attribute?
&gt; 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)
)
&gt; 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.
&gt; model = model.to(device)
&gt; model.device
'cpu'


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:
&gt;&gt;&gt; next(model.parameters()).device

