I guess the other .py file doesn’t use a guard such as if __name__ == "__main__", but executes code in the global space directly. If that’s the case, move the executable code (which would start the training) into the if-clause protection.


Make sure all model parameters as well as the inputs and targets are transferred properly to the GPU via .cuda() or .to('cuda'). Based on the error message it seems that at least some tensors are still on the CPU.