Qu

stop_grad

Builtin index · REPL & diagnostics

result = stop_grad(v)

Input: v · Output: result

What it is

Takes one argument, v — a tracked value produced by track/param.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = stop_grad(v)
v —not documented yet
result —
Returns the plain, untracked inner value (same numeric content and shape) detached from the tape, so gradients don't flow through it — e.g. holding a target/label steady, or truncating backprop through time.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

target = stop_grad(track(5.0))
x = track(2.0)
loss = (x - target) * (x - target)
dloss_dx = grad(loss, wrt=x)
print("dloss/dx = {dloss_dx}")

from repl-diagnostics

How it works

stop_grad(v) — detaches a tracked Tensor back to its plain inner value, so gradients don't flow through it (e.g. holding a target/label steady, or truncating backprop through time).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.