Temporarily modify gradient recording.

with_no_grad(code)

Arguments

code

code to be executed with no gradient recording.

Examples

x <- tensor(runif(5), requires_grad = TRUE) with_no_grad({x$sub_(tensor(as.numeric(1:5)))}) x
#> tensor #> -0.1445 #> -1.6950 #> -2.2636 #> -3.0590 #> -4.1390 #> [ Variable[CPUFloatType]{5} ]