Solved by ptrblck in post #2 
              
              
                Yes, you can depend on runtime errors and as long as no errors are raised, you code should be fine. 
One difference would be that you are not allowed to set the requires_grad attribute on tensors from an inference_mode context: 
with torch.no_grad():
    x = torch.randn(1)
    y = x + 1

y.requires_…