This is because the .cuda() creates a new Tensor. you should do it inside the Tensor creation.
Note that the requires grad is already done by the nn.Parameter so no need to repeat it.
Ho right my bad. the legacy api with capital letters does not support this.
The new api for this is: torch.empty([7, 32, 32], dtype=torch.float, device="cuda") (keep in mind that the returned Tensor (like with the old api) contains uninitialized memory).
Yes, as @ptrblck said, you might want to double check that this is still detected as a parameter properly (it won’t).
You want to use self.weight = torch.nn.Parameter(torch.empty([7, 32, 32], dtype=torch.float, device="cuda")) to make sure that what is saved is an nn.Parameter and not what is returned by the .to() operation (which will be a Tensor).
This will create an empty tensor. How can i create a memory allocated cuda tensor. Want to initalise it in model and use it as W param for traning purposes. Is using a Variable good option?