Solved by albanD in post #3 
              
              
                Hi, 
I think the problem here is that all cuda calls made with pytorch are asynchronous, and so the only point where it actually waits for the computations to be done is when you use them: when you want to send them back to the cpu. 
You can either use torch.cuda.synchronize() after some operations …