powered by
Context-manager that enables gradient calculation. Enables gradient calculation, if it has been disabled via with_no_grad.
with_enable_grad(code)
code to be executed with gradient recording.
This context manager is thread local; it will not affect computation in other threads.
if (torch_is_installed()) { x <- torch_tensor(1, requires_grad = TRUE) with_no_grad({ with_enable_grad({ y <- x * 2 }) }) y$backward() x$grad }
Run the code above in your browser using DataLab