标签: pytorch
是否可以保存和还原autograd的当前状态?
例如:
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)
答案 0 :(得分:0)
Source code for torch.autograd.grad_mode提示解决方案:
torch.autograd.grad_mode
torch.is_grad_enabled()
似乎是this function is currently undocumented。