with torch.no_grad() code example
Example 1: with torch.no_grad()
The wrapper "with torch.no_grad()"
temporarily set all the requires_grad flag to false.
Example 2: with torch.no_grad() if condition
with torch.set_grad_enabled(not no_grad_condition):
out=network(input)