保存和恢复自动分级启用状态

时间:2018-11-23 13:13:38

标签: 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)

1 个答案:

答案 0 :(得分:0)

Source code for torch.autograd.grad_mode提示解决方案:

torch.is_grad_enabled()

似乎是this function is currently undocumented