TorchLean API

NN.Examples.DeepDives.GraphSpec.Tutorial

GraphSpec tutorial #

GraphSpec is TorchLean's architecture-facing graph language. It is useful when you want a model to exist first as a typed graph that can later be interpreted in several ways:

That is why this folder is not a duplicate of NN.Spec.Models or NN.Examples.Models.

This tutorial does two things:

  1. It runs the smallest complete sequential-model path: GraphSpec.Models.mlp → ToSequential.toSeq → Trainer.new → trainer.train.
  2. It typechecks the broader GraphSpec model ladder: MLP, CNN, and a residual linear block.

Only the MLP is trained here because it is the compact check path for Seq lowering. The CNN and residual block remain architecture terms that graph passes, exporters, and proofs can consume.

Run:

lake exe torchlean graphspec --execution eager
lake exe torchlean graphspec --execution typed-graph

You can also pass the standard TorchLean runtime flags such as --arithmetic ieee, --execution eager, or --execution typed-graph.

Command name used in diagnostics and by the top-level example runner.

Instances For

    Command-line help for the GraphSpec tutorial.

    Instances For

      Small architecture terms that should typecheck #

      The smallest sequential GraphSpec model.

      Parameter ABI: [[3, 2], [3], [1, 3], [1]].

      Instances For

        The minimal DAG-native skip-connection example:

        $$ x\mapsto\operatorname{ReLU}(Wx+b+x). $$

        This is not a plain chain: representing it that way would either duplicate the input path or hide sharing in a special layer. That is the pedagogical reason GraphSpec.DAG exists.

        Instances For

          Print the architecture ladder this tutorial is checking.

          Instances For

            Tiny one-sample dataset for the lowered GraphSpec MLP training path.

            Instances For

              Run the compact MLP lowering/training path.

              Instances For

                Entry point: print the operation catalogue, then lower a GraphSpec MLP and train it for a few steps.

                Instances For