TorchLean API

NN.Runtime.Autograd.Torch.LinkedSession.Autograd

Proof-Linked Session: Differentiation and Backpropagation #

Backward + SGD (runtime tape loop on the compiled tape) #

Compile the recorded proved graph into a runtime tape.

This uses Graph.compileAuxData (the same compiler used by the proof pipeline) and extracts the runtime tape component.

Instances For

    Run reverse-mode backprop for the whole recorded context and return a dense gradient array.

    seed is the upstream gradient for out (same convention as PyTorch's loss.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 tensor for a particular TensorRef from a dense gradient array.

        This is the typed analogue of looking up grads[x.id] and casting it to the expected shape.

        Instances For

          Forward-mode: JVP (compiled only) #

          Like mkIdxOrThrow, but restricted to leaves Γ only.

          Instances For

            Convert a dense tangent array (aligned with leaf creation order) into a typed TList α Γ.

            This is the main adapter needed to call the proved GraphData.jvpCtx forward-mode routine.

            Instances For

              Jacobian-vector product for the current session snapshot.

              dxs is a dense array of tangents for leaf tensors, aligned with leaf creation order.

              Instances For
                def Runtime.Autograd.Torch.Internal.SessionIR.jvpLeaf {α : Type} (s : SessionIR α) [Zero α] [DecidableEq Spec.Shape] {shOut shX : Spec.Shape} (out : TensorRef α shOut) (x : TensorRef α shX) (dx : Spec.Tensor α shX) :
                IO (Spec.Tensor α shOut)

                JVP for a single leaf: tangent is nonzero only at x.

                Instances For

                  Scalar-loss JVP for a single leaf.

                  Instances For
                    def Runtime.Autograd.Torch.Internal.SessionIR.sgdStepAll {α : Type} (s : SessionIR α) [Sub α] [Mul α] [Add α] [Zero α] [DecidableEq Spec.Shape] (lr : α) (grads : Array (AnyTensor α)) :

                    Apply an SGD update to all parameters recorded via use.

                    grads is expected to be the dense gradient array returned by backwardDenseAll / backwardScalarDenseAll. Only entries corresponding to parameters (leaves that were produced by use) are used to update Param.value. PyTorch comparison: like iterating params and doing p.data -= lr * p.grad.

                    Instances For

                      Pure correctness hook: session snapshot ↔ proved IR backprop #

                      Core proof-link: running the runtime reverse-mode loop on the compiled tape equals proved backprop.

                      This theorem is the "hook" that lets a session-style API be backed by the proved IR: compileAuxData produces a tape, and Tape.backwardDenseFrom is shown equal to GraphData.backpropAllCtx (up to the TList.toAnyArray representation change).