with_no_grad | R Documentation |
Temporarily modify gradient recording.
with_no_grad(code)
local_no_grad(.env = parent.frame())
code |
code to be executed with no gradient recording. |
.env |
The environment to use for scoping. |
local_no_grad()
: Disable autograd until it goes out of scope
if (torch_is_installed()) {
x <- torch_tensor(runif(5), requires_grad = TRUE)
with_no_grad({
x$sub_(torch_tensor(as.numeric(1:5)))
})
x
x$grad
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.