A general rule of thumb is that code that works on the CPU (that you wrote using pytorch) should also work on a GPU (as long as your tensors and models are converted to CUDA with .cuda(…) or .to(…) calls).