Backward Passes and Optimizers #
Gradient extraction and optimizer updates for eager sessions, including the CUDA paths that keep parameter mirrors and moment buffers on device.
Run reverse-mode backprop on the CUDA tape, returning device gradients for all tape entries.
This is the CUDA analogue of backwardDenseAll, but it does not download gradients back to the
host. This is primarily useful for implementing GPU-native optimizer steps.
Instances For
Run CUDA backward from a scalar loss with seed 1, returning device gradient buffers.
Instances For
Run scalar-loss CUDA backprop and return gradients only for trainable parameter leaves.
The tape walk uses an array indexed by node id rather than a persistent hash map. Only trainable parameter gradients are packed into the returned map, so optimizer updates stay on device without paying hash-table costs at every intermediate node.
Instances For
Run reverse-mode backprop and return a dense gradient array for all tape entries.
seed is the upstream gradient for out (like PyTorch's backward(gradient=...)).
Instances For
Run backward from a scalar loss with seed 1.
PyTorch comparison: loss.backward() for a scalar loss.
Instances For
Extract the gradient for a particular TensorRef from a dense gradient array.
Instances For
Apply an SGD update to all parameters recorded via use.
PyTorch comparison: for p in params: p.data -= lr * p.grad.
Instances For
Apply an SGD update to all parameters recorded via use, using CUDA device gradients.
This avoids downloading the full dense gradient array and keeps updated parameters in each
Param's CUDA mirror. Host tensors are synchronized later by explicit parameter readback.
Instances For
Check every trainable parameter, gradient, tape value, and optional Adam state before an optimizer changes a parameter. This prevents a malformed gradient map or checkpoint state from producing a partially applied update.
Instances For
Apply SGD from a sparse CUDA gradient map.
This is the path used by the CUDA trainer. It updates only parameter leaves and avoids allocating zero gradients for every forward activation in the tape.
Instances For
Apply Adam using an already-computed sparse CUDA gradient map.
Instances For
Apply AdamW from a sparse CUDA gradient map.
Normal training uses this sparse map so activation gradients can be released as soon as their contributions have been propagated.