IRExec #
IR → executable SSA graph bridge.
This module lets us run an op-tagged NN.IR.Graph by compiling it into an executable
Proofs.Autograd.Algebra.GraphData (the SSA/DAG representation used by the proof-compiled runtime).
Why this exists:
- Verification tooling already targets
NN.IR.Graph(an op-tagged DAG with external payloads). - The runtime
.compiledpath executesGraphData(closures for each node). - To enforce a single shared IR contract, we provide a checked translation
IR.Graph → GraphData. The supported-fragment forward-correctness theorem connectingGraphData.evalto the IR denotation (NN.IR.Graph.denote*) lives inNN.Runtime.Autograd.Compiled.IRExec.Correctness.SemanticEquivalence(split out so routine runtime imports do not pull in the full semantic proof).
Important:
- The produced
GraphDatais meant for forward execution; the theorem layer states exactly which fragment is forward-correct and which domain side conditions are assumed. - Today
jvp/vjpare forward-only sentinels; this bridge is intended for forward execution and for closing the shared-IR semantics gap, not for training-style gradient computation.
PyTorch intuition #
If you’re coming from PyTorch:
- This is closer in spirit to compiled graph execution (TorchScript /
torch.compile) than to eager mode. NN.IR.Graphis the "shared IR" we want verifiers and runtimes to agree on.GraphDatais the executable SSA/DAG form: each node becomes a closure that reads parent values from a typed runtime context.- PyTorch’s autograd engine computes gradients by recording an eager tape; this bridge is about running the forward pass of an IR graph with a proof that it matches the IR semantics.
Reading map #
ExecGraphDatapackages a compiled graph with its input shape.IRExec.dValsOfCtxconverts typed runtime contexts back into IR-style value arrays.IRExec.buildFromis the compiler fromNN.IR.Graphto executable graph data.IRExec.execGraphOfIRis the main user-facing bridge entry point.
Main definitions #
ExecGraphData: compiled executable graph package.IRExec.mkIdx: checked parent-id to typed-index bridge.IRExec.mkFwdNode: forward-only node constructor used during lowering.IRExec.buildFrom: recursive compiler from IR graph to executable SSA graph.IRExec.execGraphOfIR: user-facing compile entrypoint.
Implementation notes #
- This bridge covers forward semantics; gradient compilation is a separate contract.
jvp/vjpare sentinels in this layer because gradient compilation is a separate concern from proving forward semantic equivalence.- Lowering untyped numeric ids goes through typed indices (
Idx) and explicit shape checks.
References #
Tags #
ir, compiler, runtime, graphdata, forward-semantics
simp rule for Except-do chains: binding an .error short-circuits.
Used heavily when discharging impossible branches in compilation correctness proofs.
Definitional simplification for Except.bind on .ok.
Definitional simplification for Except.bind on .error.
A forward-executable SSA graph derived from an NN.IR.Graph.
The compiled graph stores:
- one distinguished input shape (
inShape), - one shape per compiled node (
ss, corresponding to IR node ids1..n-1), - and executable node closures (
g) consumed byGraphData.eval.
- inShape : Spec.Shape
The distinguished IR input node’s shape (node id 0).
- ss : List Spec.Shape
Shapes of the IR nodes 1..(n-1) (one per executable SSA node).
Executable SSA/DAG graph for nodes 1..(n-1); inputs live in
Γ := [inShape].
Instances For
Evaluate the compiled executable SSA graph on a concrete input tensor.
The result is the full typed runtime context [inShape] ++ ss, i.e. input followed by every
compiled node value in topological order.
Instances For
Denotation Table Helper #
ExecGraphData.eval produces a typed runtime context TList α ([inShape] ++ ss).
For debugging and for the forward-correctness development in
NN.Runtime.Autograd.Compiled.IRExec.Correctness,
we provide a helper that erases this context
into an IR-style value table Array (NN.IR.DVal α) in node-id order.
Convert a runtime AnyTensor (shape carried as a field) into an IR denotation value DVal.
Instances For
Convert a typed runtime context TList α ss into an IR-style value table.
This is phrased in terms of Array (DVal α) because the IR denotation functions (denoteAll*)
are array-based, while the compiled runtime evaluates into a typed context (TList).
Instances For
Convert the full evaluated context into an IR-style value table (one DVal per node id).
This is the concrete bridge used in semantic equivalence statements that compare compiled evaluation against
NN.IR.Graph.denoteAll*.