(rontolisp) docs
← Functions

torch:backward

(torch:backward tensor)

Runs reverse-mode automatic differentiation from a scalar (one-element) tensor: seeds its gradient with 1.0, walks the recorded tape in reverse topological order, and accumulates each operation's input gradients into its parents -- so a tensor reached over more than one path (a residual connection, a reused embedding row) collects the sum. Read the results with torch:grad; returns nil. A tensor with more than one element signals.

Gradients are retained on intermediate tensors too, and repeated backward calls keep accumulating -- clear parameters with torch:zero-grad between training steps.