TorchLean API

NN.API.Models.Vit

ViT-Style Model Helpers (API) #

This module provides a compact, reusable ViT-style model constructor used by runnable examples.

This is intentionally minimal:

The point is to keep examples readable while still exercising: Conv2d + tokenization + attention + FFN on both CPU and CUDA eager backends.

Configuration for a small ViT-style classifier.

Shapes:

  • input: N×C×H×W
  • output: N×outDim
Instances For
    @[reducible, inline]
    Instances For
      @[reducible, inline]
      Instances For
        @[reducible, inline]
        Instances For
          @[reducible, inline]
          Instances For

            Patch-tokenization adapter: N×C×H×W -> N×(H*W)×C.

            This is the “low-hanging fruit” to move out of examples: the reshape needs a small size proof.

            Instances For
              def NN.API.nn.models.vit1 (cfg : VitConfig) (h_inC : cfg.inC 0 := by decide) (h_patchH : cfg.patchH 0 := by decide) (h_patchW : cfg.patchW 0 := by decide) (h_seqLen : cfg.seqLen 0 := by decide) (h_dModel : cfg.dModel 0 := by decide) :

              One-block ViT-style classifier.

              This is the constructor used by torchlean vit. Keeping it here makes the example a one-liner: def mkModel := nn.models.vit1 cfg.

              Instances For