TorchLean API

NN.IR.Program

Typed interchange programs #

Program attaches element types and an input/output interface to the existing Graph. Shapes and dependencies remain in that graph; there is no second node language. Ordinary operators have homogeneous signatures, so a frontend must make its promotions explicit. Casts and registered heterogeneous primitives use the existing custom-node shape contract and a separate element-type signature.

The custom node's name is for display. Its typed primitive entry, indexed by node id, determines its meaning. An unregistered custom operation is rejected rather than inferred from a spelling. Interpreters must supply the implementation of every primitive they execute.

Type checking establishes consistency of the declared program, not equivalence with a frontend or correctness of an external numerical backend.

Typed extension of a custom node; shape contracts remain in OpKind.custom.

Instances For
    def NN.IR.instDecidableEqPrimitive.decEq (x✝ x✝¹ : Primitive) :
    Decidable (x✝ = x✝¹)
    Instances For
      @[instance_reducible]
      structure NN.IR.Program :

      One canonical graph together with its SSA type assignment and external interface.

      • graph : Graph

        Shared graph syntax, including all operation shape attributes.

      • dtypes : Array DType

        Element type of every node result, indexed by node id.

      • inputs : Array ℕ

        All runtime input nodes, in argument order.

      • outputs : Array ℕ

        Designated result nodes, in return order.

      • primitives : Array (Option Primitive)

        Typed bodies for custom nodes. Empty means no registrations; otherwise aligned with nodes.

      Instances For
        @[instance_reducible]

        Recover a result's declared element type, reporting an invalid SSA index.

        Instances For

          Typed primitive attached to a node. An empty table represents no registrations.

          Instances For

            Check one node's element-type rule; graph validation separately checks shape and arity.

            Instances For

              Check ids, shapes, element types, primitive signatures, and the input/output interface.

              Instances For
                theorem NN.IR.Program.check_wellShaped {program : Program} (h : program.check = Except.ok ()) :

                Passing the typed checker supplies the shape hypothesis used by graph semantics.

                def NN.IR.Program.ofGraph (graph : Graph) (outputs : Array ℕ) :

                Embed a scalar-polymorphic graph without changing its operations or dependencies.

                Instances For

                  Append a shape-preserving cast to a typed program and return its result id.

                  The target type is the result's entry in the typing context; the rounding direction is the primitive's explicit attribute. Existing custom-node shape checks remain applicable.

                  Instances For