TorchLean API

NN.Examples.DeepDives.AutogradTransforms

Autograd Transforms #

Advanced differentiation operations are kept out of the first autograd tutorial:

Build this module after NN.Examples.Quickstart.AutogradBasics.

Run:

scripts/lake.sh exe torchlean autograd_transforms

Subcommand name, used in the usage text and in argument-error messages.

Instances For

    Componentwise squaring, whose Jacobian is the diagonal matrix 2x. Small enough that the printed rows can be checked by hand.

    Instances For

      Mean of the squares: a scalar-valued function, so it has a Hessian to compute.

      Instances For

        One linear layer 2 -> 3, seeded deterministically so the printed numbers are reproducible.

        Instances For

          Run higher-order and directional differentiation examples.

          Instances For

            Help text; the demo takes no flags.

            Instances For

              Add elementwise squaring to a proved graph, for any tensor shape.

              autograd composes mathlib's scalar rules and lifts them to tensors; snoc carries the certificate into the composed graph. No shape-specific proof is needed.

              Instances For

                Squaring twice reuses the same primitive proof; no new backward rule is needed.

                Instances For

                  The second square is the output; the input and first square remain saved graph values.

                  Instances For

                    A successful checked reverse pass computes the adjoint of the forward function's derivative.

                    This theorem is about the exact-real graph. Running the same arithmetic in floating point needs a separate rounding-error argument, and higher derivatives need more than this first-order proof.

                    Apply exp(x*x) to a tensor, using the caller's scalar backend and shape.

                    Instances For

                      Every derivative order, tensor shape, and direction tuple share one proof.

                      The seed and extraction functions are also used by autograd.model.derivative. This theorem checks the tensor computation between them; model lowering requires its own correctness evidence.

                      Record squaring and exponentiation as two graph operations, for any scalar backend.

                      Instances For

                        Recording succeeds and the resulting graph evaluates the two requested operations.

                        The proof keeps the scalar backend abstract: recording checks shapes and indices, not numerical values. This also prevents the proof from expanding real or nested-dual arithmetic internals.

                        Nested-dual execution of the recorded graph computes every mixed derivative of its real run.

                        Unlike the tensor-only example above, this statement includes the actual recorder and graph execution. It does not assert correctness of arbitrary model lowering or the reverse pass.

                        A parameter-free model using the same square layer as executable neural networks.

                        Instances For

                          The public IO transform returns the exact mixed derivative, for every shape and order.

                          There is no assumed lowering result: the proof checks model validation, graph recording, and execution before applying autograd to the arithmetic. The empty direction list is included.