It works! Thanks a lot!
I replaced .to(device) with device=device key word argument and it works.
Now learned that to(device) is used for device conversion and device=device represents the device on which a tensor is or will be allocated.
You really hepled me a lot!