Documentation

LeanMlir.Proofs.Codegen.ChapterGraphs

The chapter-net graphs and their printers (chapters 1–4) #

The whole-net forward (and, for the MLP and the MNIST CNN, backward) SHlo graphs of the book's small nets, and the renderModule printers that write the committed verified_mlir/ forwards from them (ChapterArtifacts' #evals):

netgraphprinter
linear (ch 1)fwdGraph, backGraph, lossCotGraph (in StableHLO)linearFwdModuleV, linearBackModuleV, linearTrainStepModuleV
MLP (ch 2)mlpFwdGraph, mlpBackGraphmlpFwdModuleV
MNIST CNN (ch 3)cnnFwdGraph, cnnBackGraphcnnFwdModuleV
CIFAR CNN (ch 4)cifarFwdGraph, cifar8FwdGraph, cifar8BnFwdGraphcifarFwdModuleV, cifar8FwdModuleV, cifar8BnFwdModuleV

The MLP graphs' faithfulness theorems are here; that the chapter 3–4 graphs denote their nets is ChapterGraphTies, since the IR imports no net. The op vocabulary, den, pretty and renderModule are StableHLO / StableHLO.Pretty, which the batched ImageNet nets share, so an edit to a chapter net stays out of their rebuild.

def Proofs.StableHLO.mlpFwdGraph {e₀ e₁ e₂ e₃ : ℕ} (W₀ : Mat e₀ e₁) (b₀ : Vec e₁) (W₁ : Mat e₁ e₂) (b₁ : Vec e₂) (W₂ : Mat e₂ e₃) (b₂ : Vec e₃) (x : Vec e₀) :
SHlo e₃

Whole-MLP forward graph dense W₂ ∘ relu ∘ dense W₁ ∘ relu ∘ dense W₀.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Proofs.StableHLO.mlpFwdGraph_faithful {e₀ e₁ e₂ e₃ : ℕ} (W₀ : Mat e₀ e₁) (b₀ : Vec e₁) (W₁ : Mat e₁ e₂) (b₁ : Vec e₂) (W₂ : Mat e₂ e₃) (b₂ : Vec e₃) (x : Vec e₀) :
    den (mlpFwdGraph W₀ b₀ W₁ b₁ W₂ b₂ x) = mlpForward W₀ b₀ W₁ b₁ W₂ b₂ x

    MLP forward faithfulness. The forward graph denotes mlpForward.

    def Proofs.StableHLO.mlpBackGraph {e₀ e₁ e₂ e₃ : ℕ} (W₀ : Mat e₀ e₁) (W₁ : Mat e₁ e₂) (W₂ : Mat e₂ e₃) (p₀ : Vec e₁) (p₁ : Vec e₂) (dy : Vec e₃) :
    SHlo e₀

    Whole-MLP backward (input-VJP) graph: dotOut W₀ ∘ select(p₀) ∘ dotOut W₁ ∘ select(p₁) ∘ dotOut W₂, pᵢ the ReLU pre-activations.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Proofs.StableHLO.mlpBackGraph_faithful {e₀ e₁ e₂ e₃ : ℕ} (W₀ : Mat e₀ e₁) (b₀ : Vec e₁) (W₁ : Mat e₁ e₂) (b₁ : Vec e₂) (W₂ : Mat e₂ e₃) (b₂ : Vec e₃) (x : Vec e₀) (h0 : ∀ (k : Fin e₁), dense W₀ b₀ x k ≠ 0) (h1 : ∀ (k : Fin e₂), dense W₁ b₁ (relu e₁ (dense W₀ b₀ x)) k ≠ 0) (dy : Vec e₃) :
      den (mlpBackGraph W₀ W₁ W₂ (dense W₀ b₀ x) (dense W₁ b₁ (relu e₁ (dense W₀ b₀ x))) dy) = (mlpHasVJPAt W₀ b₀ W₁ b₁ W₂ b₂ x h0 h1).backward dy

      MLP backward faithfulness (smooth point). The backward graph denotes the proven mlpHasVJPAt.backward — the per-op dot_general/select ops assembled into the proven whole-network VJP (cf. IR.mlp_whole_bridge).

      def Proofs.StableHLO.cnnFwdGraph {ic c h w d1 nClasses kH kW : ℕ} (W₁ : Kernel4 c ic kH kW) (b₁ : Vec c) (W₂ : Kernel4 c c kH kW) (b₂ : Vec c) (W₃ : Mat (c * h * w) d1) (b₃ : Vec d1) (W₄ : Mat d1 d1) (b₄ : Vec d1) (W₅ : Mat d1 nClasses) (b₅ : Vec nClasses) (x : Vec (ic * (2 * h) * (2 * w))) :
      SHlo nClasses

      Whole MNIST-CNN forward graph: dense ∘ relu ∘ dense ∘ relu ∘ dense ∘ maxPool ∘ relu ∘ conv ∘ relu ∘ conv.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def Proofs.StableHLO.cifarFwdGraph {ic c1 c2 h w d1 nClasses kH kW : ℕ} (W₁ : Kernel4 c1 ic kH kW) (b₁ : Vec c1) (W₂ : Kernel4 c1 c1 kH kW) (b₂ : Vec c1) (W₃ : Kernel4 c2 c1 kH kW) (b₃ : Vec c2) (W₄ : Kernel4 c2 c2 kH kW) (b₄ : Vec c2) (W₅ : Mat (c2 * h * w) d1) (b₅ : Vec d1) (W₆ : Mat d1 d1) (b₆ : Vec d1) (W₇ : Mat d1 nClasses) (b₇ : Vec nClasses) (x : Vec (ic * (2 * (2 * h)) * (2 * (2 * w)))) :
        SHlo nClasses

        Whole CIFAR-CNN forward graph (Chapter 4): two conv→relu→conv→relu→maxPool stages (channels ic→c1→c1, then c1→c2→c2) then dense→relu→dense→relu→dense. The Chapter-4 peer of cnnFwdGraph.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          def Proofs.StableHLO.cifar8FwdGraph {ic c1 c2 c3 c4 h w d1 nClasses kH kW : ℕ} (W₁ : Kernel4 c1 ic kH kW) (b₁ : Vec c1) (W₂ : Kernel4 c1 c1 kH kW) (b₂ : Vec c1) (W₃ : Kernel4 c2 c1 kH kW) (b₃ : Vec c2) (W₄ : Kernel4 c2 c2 kH kW) (b₄ : Vec c2) (W₅ : Kernel4 c3 c2 kH kW) (b₅ : Vec c3) (W₆ : Kernel4 c3 c3 kH kW) (b₆ : Vec c3) (W₇ : Kernel4 c4 c3 kH kW) (b₇ : Vec c4) (W₈ : Kernel4 c4 c4 kH kW) (b₈ : Vec c4) (W₉ : Mat (c4 * h * w) d1) (b₉ : Vec d1) (Wa : Mat d1 d1) (ba : Vec d1) (Wb : Mat d1 nClasses) (bb : Vec nClasses) (x : Vec (ic * (2 * (2 * (2 * (2 * h)))) * (2 * (2 * (2 * (2 * w)))))) :
          SHlo nClasses

          Whole deeper (8-conv) CIFAR-CNN forward graph: four conv→relu→conv→relu→maxPool stages (channels ic→c1→c1, c1→c2→c2, c2→c3→c3, c3→c4→c4) then dense→relu→dense→relu→dense. The 4-stage peer of cifarFwdGraph.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            def Proofs.StableHLO.cifar8BnFwdGraph {ic c1 c2 c3 c4 h w d1 nClasses kH kW : ℕ} (epsStr : String) (W₁ : Kernel4 c1 ic kH kW) (b₁ : Vec c1) (ε₁ : ℝ) (γ₁ β₁ : Vec c1) (W₂ : Kernel4 c1 c1 kH kW) (b₂ : Vec c1) (ε₂ : ℝ) (γ₂ β₂ : Vec c1) (W₃ : Kernel4 c2 c1 kH kW) (b₃ : Vec c2) (ε₃ : ℝ) (γ₃ β₃ : Vec c2) (W₄ : Kernel4 c2 c2 kH kW) (b₄ : Vec c2) (ε₄ : ℝ) (γ₄ β₄ : Vec c2) (W₅ : Kernel4 c3 c2 kH kW) (b₅ : Vec c3) (ε₅ : ℝ) (γ₅ β₅ : Vec c3) (W₆ : Kernel4 c3 c3 kH kW) (b₆ : Vec c3) (ε₆ : ℝ) (γ₆ β₆ : Vec c3) (W₇ : Kernel4 c4 c3 kH kW) (b₇ : Vec c4) (ε₇ : ℝ) (γ₇ β₇ : Vec c4) (W₈ : Kernel4 c4 c4 kH kW) (b₈ : Vec c4) (ε₈ : ℝ) (γ₈ β₈ : Vec c4) (W₉ : Mat (c4 * h * w) d1) (b₉ : Vec d1) (Wa : Mat d1 d1) (ba : Vec d1) (Wb : Mat d1 nClasses) (bb : Vec nClasses) (x : Vec (ic * (2 * (2 * (2 * (2 * h)))) * (2 * (2 * (2 * (2 * w)))))) :
            SHlo nClasses

            Whole deeper (8-conv) BN-CIFAR forward graph: each of the eight convs is followed by a per-channel bnPerChannelF before its ReLU. epsStr is the shared ε literal; the eight BN layers carry per-channel γ/β inputs %g{i}/%bt{i}. The BN peer of cifar8FwdGraph.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              noncomputable def Proofs.StableHLO.cnnBackGraph {ic c h w d1 nClasses kH kW : ℕ} (W₁ : Kernel4 c ic kH kW) (b₁ : Vec c) (W₂ : Kernel4 c c kH kW) (b₂ : Vec c) (W₃ : Mat (c * h * w) d1) (b₃ : Vec d1) (W₄ : Mat d1 d1) (b₄ : Vec d1) (W₅ : Mat d1 nClasses) (x : Vec (ic * (2 * h) * (2 * w))) (dy : Vec nClasses) :
              SHlo (ic * (2 * h) * (2 * w))

              Whole MNIST-CNN backward (input-VJP) graph, reversing cnnFwdGraph: convBack W₁ ∘ select(a₁) ∘ convBack W₂ ∘ select(a₂) ∘ maxPoolBack ∘ dotOut W₃ ∘ select(a₃) ∘ dotOut W₄ ∘ select(a₄) ∘ dotOut W₅, with aᵢ the ReLU pre-activations and the conv/maxpool saved inputs threaded by name.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                def Proofs.StableHLO.linearFwdModuleV (B d₀ d₁ : ℕ) (W : Mat d₀ d₁) (b : Vec d₁) (x : Vec d₀) :

                @linear_fwd rendered from the verified AST.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def Proofs.StableHLO.linearBackModuleV (B d₀ d₁ : ℕ) (W : Mat d₀ d₁) (dy : Vec d₁) :

                  @linear_back rendered from the verified AST.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def Proofs.StableHLO.linearTrainStepModuleV (B d₀ d₁ : ℕ) (lr : String) (W : Mat d₀ d₁) (b : Vec d₁) (x : Vec d₀) :

                    The full @linear_train_step rendered from the verified AST: forward + softmax-CE cotangent come from pretty (lossCotGraph …) (the %onehot operand value is pretty-irrelevant, so any placeholder renders the same text — at runtime %onehot is a graph input); the weight grad (dot_general over the batch axis), bias grad (reduce), and the SGD multiply/subtract updates are appended. Returns the two updated params. The verified-AST peer of IRPrint.linearTrainStepModule.

                    Instances For
                      def Proofs.StableHLO.mlpFwdModuleV (B d₀ d₁ d₂ d₃ : ℕ) (W₀ : Mat d₀ d₁) (b₀ : Vec d₁) (W₁ : Mat d₁ d₂) (b₁ : Vec d₂) (W₂ : Mat d₂ d₃) (b₂ : Vec d₃) (x : Vec d₀) :

                      @mlp_fwd rendered from the verified forward AST mlpFwdGraph.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        def Proofs.StableHLO.cnnFwdModuleV (B ic c h w d1 nClasses kH kW : ℕ) (W₁ : Kernel4 c ic kH kW) (b₁ : Vec c) (W₂ : Kernel4 c c kH kW) (b₂ : Vec c) (W₃ : Mat (c * h * w) d1) (b₃ : Vec d1) (W₄ : Mat d1 d1) (b₄ : Vec d1) (W₅ : Mat d1 nClasses) (b₅ : Vec nClasses) (x : Vec (ic * (2 * h) * (2 * w))) :

                        @cnn_fwd rendered from the verified CNN forward AST cnnFwdGraph.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          def Proofs.StableHLO.cifarFwdModuleV (B ic c1 c2 h w d1 nClasses kH kW : ℕ) (W₁ : Kernel4 c1 ic kH kW) (b₁ : Vec c1) (W₂ : Kernel4 c1 c1 kH kW) (b₂ : Vec c1) (W₃ : Kernel4 c2 c1 kH kW) (b₃ : Vec c2) (W₄ : Kernel4 c2 c2 kH kW) (b₄ : Vec c2) (W₅ : Mat (c2 * h * w) d1) (b₅ : Vec d1) (W₆ : Mat d1 d1) (b₆ : Vec d1) (W₇ : Mat d1 nClasses) (b₇ : Vec nClasses) (x : Vec (ic * (2 * (2 * h)) * (2 * (2 * w)))) :

                          @cifar_fwd rendered from the verified CIFAR forward AST cifarFwdGraph.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            def Proofs.StableHLO.cifar8FwdModuleV (B ic c1 c2 c3 c4 h w d1 nClasses kH kW : ℕ) (W₁ : Kernel4 c1 ic kH kW) (b₁ : Vec c1) (W₂ : Kernel4 c1 c1 kH kW) (b₂ : Vec c1) (W₃ : Kernel4 c2 c1 kH kW) (b₃ : Vec c2) (W₄ : Kernel4 c2 c2 kH kW) (b₄ : Vec c2) (W₅ : Kernel4 c3 c2 kH kW) (b₅ : Vec c3) (W₆ : Kernel4 c3 c3 kH kW) (b₆ : Vec c3) (W₇ : Kernel4 c4 c3 kH kW) (b₇ : Vec c4) (W₈ : Kernel4 c4 c4 kH kW) (b₈ : Vec c4) (W₉ : Mat (c4 * h * w) d1) (b₉ : Vec d1) (Wa : Mat d1 d1) (ba : Vec d1) (Wb : Mat d1 nClasses) (bb : Vec nClasses) (x : Vec (ic * (2 * (2 * (2 * (2 * h)))) * (2 * (2 * (2 * (2 * w)))))) :

                            @cifar8_fwd rendered from the verified 8-conv CIFAR forward AST cifar8FwdGraph (cifar8FwdGraph_faithful proves it denotes cifarCnn8Forward). The 4-stage peer of cifarFwdModuleV — the committed verified_mlir/cifar8_fwd.mlir is renderModule(provenGraph).

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def Proofs.StableHLO.cifar8BnFwdModuleV (B ic c1 c2 c3 c4 h w d1 nClasses kH kW : ℕ) (epsStr : String) (W₁ : Kernel4 c1 ic kH kW) (b₁ : Vec c1) (ε₁ : ℝ) (γ₁ β₁ : Vec c1) (W₂ : Kernel4 c1 c1 kH kW) (b₂ : Vec c1) (ε₂ : ℝ) (γ₂ β₂ : Vec c1) (W₃ : Kernel4 c2 c1 kH kW) (b₃ : Vec c2) (ε₃ : ℝ) (γ₃ β₃ : Vec c2) (W₄ : Kernel4 c2 c2 kH kW) (b₄ : Vec c2) (ε₄ : ℝ) (γ₄ β₄ : Vec c2) (W₅ : Kernel4 c3 c2 kH kW) (b₅ : Vec c3) (ε₅ : ℝ) (γ₅ β₅ : Vec c3) (W₆ : Kernel4 c3 c3 kH kW) (b₆ : Vec c3) (ε₆ : ℝ) (γ₆ β₆ : Vec c3) (W₇ : Kernel4 c4 c3 kH kW) (b₇ : Vec c4) (ε₇ : ℝ) (γ₇ β₇ : Vec c4) (W₈ : Kernel4 c4 c4 kH kW) (b₈ : Vec c4) (ε₈ : ℝ) (γ₈ β₈ : Vec c4) (W₉ : Mat (c4 * h * w) d1) (b₉ : Vec d1) (Wa : Mat d1 d1) (ba : Vec d1) (Wb : Mat d1 nClasses) (bb : Vec nClasses) (x : Vec (ic * (2 * (2 * (2 * (2 * h)))) * (2 * (2 * (2 * (2 * w)))))) :

                              @cifar8_bn_fwd rendered from the verified 8-conv per-channel-BN CIFAR forward AST cifar8BnFwdGraph (cifar8BnFwdGraph_faithful proves it denotes cifarCnnBn8Forward). The BN peer of cifar8FwdModuleV.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For