TorchLean API

NN.Examples.DeepDives.IRAxisOps

IR axis operations #

Evaluate axis operations with the IR semantics.

This tutorial constructs and evaluates three IR operations with an explicit axis:

The axis is part of each operation's meaning. The evaluator checks graph and input shapes, then computes the selected output with the IR semantics, in Lean tensor operations. This example does not dispatch to LibTorch or select a GPU device; --arithmetic chooses the scalar implementation.

Run:

scripts/lake.sh exe torchlean ir_axis_ops --arithmetic ieee

Command-line help for the IR axis-ops tutorial.

Instances For

    Small IR Graphs #

    Softmax along a chosen axis of the example's [2, 3, 4] input.

    Instances For

      LayerNorm over the suffix starting at axis. The default normalizes [3, 4] together, rather than just the final dimension.

      Instances For

        Join [2, 3, 4] and [2, 5, 4] along axis one. Other axis choices demonstrate shape rejection: the remaining dimensions must agree and the declared output must match the inferred shape.

        Instances For

          Runner Helpers #

          Print a compact preview of a tensor.

          Instances For
            def NN.Examples.DeepDives.IRAxisOps.print {α : Type} {σ : Spec.Shape} [TorchLean.Storage α] [Context α] [ToString α] (tag : String) (g : IR.Graph) (payload : IR.Payload α) (x : TorchLean.Tensor α σ) (outputId : Fin g.nodes.size) :

            Evaluate an example graph with Lean tensor operations and print its selected output.

            Instances For

              Run every axis-op example at scalar type α.

              Generic in α so the tutorial can be run under native Float or under the bit-level IEEE model with no change to the graphs.

              Instances For

                Entry point; --arithmetic picks the scalar type the whole tutorial runs at.

                Instances For