TorchLean API

NN.MLTheory.Optimization.Muon.Core

Muon Orthogonalization Contracts #

Muon is more than momentum with a different name: after the momentum buffer is updated, the parameter direction is supposed to be an orthogonalized matrix direction. The runtime optimizer therefore takes an explicit orthogonalizer backend, while this file records the proof contract that such a backend should satisfy.

There are two useful levels:

The theorems below connect those contracts to the executable Muon step: if the backend satisfies one of these contracts, the direction used in the parameter update is certified at the same level.

@[reducible, inline]
abbrev Optim.Muon.MatrixTensor (α : Type) (m n : ) :

A matrix-shaped TorchLean tensor.

Instances For
    def Optim.Muon.columnGram {α : Type} [Context α] {m n : } (Q : MatrixTensor α m n) :

    The column Gram matrix $Q^\mathsf{T}Q$.

    Instances For
      def Optim.Muon.HasExactColumnGram {α : Type} [Context α] {m n : } (Q : MatrixTensor α m n) :

      Exact column orthogonality for a matrix-shaped update direction.

      Instances For

        A backend exactly orthogonalizes one specified momentum buffer.

        Instances For
          def Optim.Muon.columnGramResidual {α : Type} [Context α] {m n : } (Q : MatrixTensor α m n) :

          Residual matrix $Q^\mathsf{T}Q-I$, used for approximate orthogonalization certificates.

          Instances For
            def Optim.Muon.HasApproxColumnGram {α : Type} [Context α] {m n : } (eps : α) (Q : MatrixTensor α m n) :

            Entrywise approximate column orthogonality.

            For an exact backend use HasExactColumnGram. For Newton-Schulz or CUDA implementations, this is the certificate shape we want the backend to establish or export: every entry of $Q^\mathsf{T}Q-I$ is bounded by $\varepsilon$.

            Instances For
              def Optim.Muon.ApproxOrthogonalizesBuffer {α : Type} [Context α] {m n : } (eps : α) (orthogonalizer : Orthogonalizer α (Spec.Shape.dim m (Spec.Shape.dim n Spec.Shape.scalar))) (buffer : MatrixTensor α m n) :

              A backend approximately orthogonalizes one specified momentum buffer.

              Instances For

                An exact matrix Muon orthogonalizer maps every momentum buffer to a direction whose columns have Gram matrix $I$.

                Instances For

                  An approximate matrix Muon orthogonalizer maps every momentum buffer to a direction whose Gram residual is entrywise bounded by $\varepsilon$.

                  Instances For

                    Certified backend records #

                    Unconditionally certified exact Muon backend.

                    Use this when the orthogonalizer is known to return an exact $Q^\mathsf{T}Q=I$ direction for every buffer of a fixed matrix shape.

                    Instances For
                      structure Optim.Muon.ApproxCertifiedOrthogonalizer (α : Type) [Context α] (m n : ) (eps : α) :

                      Unconditionally certified approximate Muon backend.

                      Use this when the orthogonalizer is known to return a direction whose Gram residual is bounded by $\varepsilon$ for every buffer of a fixed matrix shape.

                      Instances For

                        Checked exact Muon backend with a per-buffer success predicate.

                        This is the practical interface for algorithms whose correctness has preconditions on the matrix being orthogonalized. The QR backend below is the first instance: its success predicate is positive executable R pivots.

                        Instances For
                          structure Optim.Muon.CheckedApproxOrthogonalizer (α : Type) [Context α] (m n : ) (eps : α) :

                          Checked approximate Muon backend with a per-buffer success predicate.

                          This is the intended proof shape for Newton-Schulz/CUDA-style backends: the kernel may be fast and approximate, but the exported proof or checker must establish Success buffer, which then gives the entrywise $Q^\mathsf{T}Q-I$ bound.

                          Instances For