What is the difference between model.to(device) and model=model.to(device)?

No semantic difference. nn.Module.to function moves the model to the device.

But be cautious.

For tensors (documentation):

# tensor a is in CPU
device = torch.device('cuda:0')
b = a.to(device)
# a is still in CPU!
# b is in GPU!
# a and b are different 

For models (documentation):

# model a is in CPU
device = torch.device('cuda:0')
b = a.to(device)
# a and b are in GPU
# a and b point to the same model 

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)