Solved by albanD in post #7 
              
              
                Yes that looks like a suspicious place. 
And yes this is the right way to use the guard. This is the same as using with torch.no_grad() in python. 
Does this fix your issue?