The wrapper "with torch.no_grad()" temporarily set all the requires_grad flag to false.
with torch.set_grad_enabled(not no_grad_condition): out=network(input)