TorchLean API

NN.Runtime.Autograd.IRExec.Core

Forward IR Execution #

This module validates an op-tagged NN.IR.Graph and translates its nodes into the shape-indexed ForwardData representation used for evaluation. ForwardGraph packages that result with its input and intermediate shapes.

The translation is forward-only. It neither supplies derivative rules nor performs optimization, fusion, scheduling, or native code generation. The semantic-equivalence theorem for the supported IR fragment lives in NN.Runtime.Autograd.IRExec.Correctness.SemanticEquivalence so ordinary runtime imports do not pull in that proof.

Main declarations #

Numeric IR node identifiers are converted through checked typed indices (Idx). The resulting types contain no derivative operations: lowering to ForwardGraph cannot be mistaken for an autograd lowering.

@[simp]
theorem Runtime.Autograd.IRExec.Except.ok_bind {ε α β : Type} (a : α) (f : αExcept ε β) :
Except.ok a >>= f = f a

simp rule for Except-do chains: binding an .ok value is just function application.

@[simp]
theorem Runtime.Autograd.IRExec.Except.error_bind {ε α β : Type} (e : ε) (f : αExcept ε β) :

simp rule for Except-do chains: binding an .error short-circuits.

Used heavily when discharging impossible branches in lowering correctness proofs.

One forward-only SSA node over the typed context Γ.

Instances For

    A shape-indexed forward SSA graph.

    Unlike autograd GraphData, this representation has no JVP or VJP fields. It is therefore impossible to request derivatives from an artifact produced by the forward IR lowering pass.

    Instances For

      Evaluate every node and return the input followed by all intermediate values.

      Instances For

        A forward-executable SSA graph derived from an NN.IR.Graph.

        The lowered graph stores:

        • one distinguished input shape (inShape),
        • one shape per lowered node (ss, corresponding to IR node ids 1..n-1),
        • and forward-only node closures (body) consumed by ForwardData.eval.
        • inShape : Spec.Shape

          The distinguished IR input node’s shape (node id 0).

        • Shapes of the IR nodes 1..(n-1) (one per executable SSA node).

        • body : ForwardData α [self.inShape] self.ss

          Forward SSA/DAG for nodes 1..(n-1); inputs live in Γ := [inShape].

        Instances For

          Evaluate the lowered forward graph on a concrete input tensor.

          The result is the full typed runtime context [inShape] ++ ss, i.e. input followed by every lowered node value in topological order.

          Instances For

            Denotation Table Helper #

            ForwardGraph.eval produces a typed runtime context TorchLean.TensorPack α ([inShape] ++ ss).

            For debugging and for the forward-correctness development in NN.Runtime.Autograd.IRExec.Correctness, we provide a helper that erases this context into an IR-style value table Array (Spec.SomeTensor α) in node-id order.

            Convert a typed runtime context TorchLean.TensorPack α ss into an IR-style value table.

            This is phrased in terms of Array (Spec.SomeTensor α) because the IR denotation functions (denoteAll*) are array-based, while forward-graph execution evaluates into a typed context (TorchLean.TensorPack).

            Instances For

              Convert the full evaluated context into an IR-style value table (one Spec.SomeTensor per node id).

              This is the bridge used to compare forward-graph evaluation with NN.IR.Graph.denoteAll*.

              Instances For