The scope of'cuda')

While reading a pytorch code there was comment where it said we have to once again move the model trained in the GPU to device using .to('CUDA'). So I was wondering the scope of .to('CUDA) ? Will it persist in the cuda memory until the program is terminated or the scope of function is terminated? what happens if we pass the model variable to another function? will it be affected?
Is transferring the model to run in GPU just a one time activity?


Yes it is a one time thing. And the weights will stay on the GPU until you delete the model, or move it back to the cpu().

This comment might be related to loading of a saved model maybe? With the saved model being on CPU.

1 Like