Learn R Programming

torch (version 0.8.1)

with_no_grad: Temporarily modify gradient recording.

Description

Temporarily modify gradient recording.

Usage

with_no_grad(code)

Arguments

code

code to be executed with no gradient recording.

Examples

Run this code
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
}

Run the code above in your browser using DataLab