set_grad_enabled

class dragon.vm.torch.set_grad_enabled(mode)[source]

Context-manager to set gradient calculation on or off.

Examples:

x = torch.ones(2, 3, requires_grad=True)
with torch.set_grad_enabled(mode=False):
    y = x + 1
y.backward()  # RuntimeError

__init__

set_grad_enabled.__init__(mode)[source]

Create a set_grad_enabled context manager.

Parameters:
  • mode (bool) – Whether to enable calculation.