Is there a way of saving and restoring the current state of autograd?
eg:
saved_state = torch.autograd.get_grad_enabled() # How do I do this?
torch.autograd.set_grad_enabled(temporary_state)
# do things for great justice
torch.autograd.set_grad_enabled(saved_state)
The Source code for
torch.autograd.grad_mode
hints at a solution:It seems that this function is currently undocumented.