I use .to(device) methods and works perfectly fine for me,
Also to be sure that your script has accessible cuda, you can check by the following code
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
print(device)