TorchLean API

NN.Examples.Models.Vision.Vit

ViT-Style Real-Data Example #

Runnable torchlean vit example. It trains a compact ViT-style image classifier on a prepared CIFAR-10 minibatch: patch embedding by convolution, token reshape, transformer block, and linear head.

The reusable model wiring lives behind the public TorchLean.nn.models.vit constructor. The command adds CIFAR loader construction and the step-limited training loop.

python3 scripts/datasets/download_example_data.py --cifar10
lake -R -K cuda=true exe torchlean vit --device cuda --n-total 1 --steps 1

This command is a small runtime check. Larger image-token runs belong in runtime profiling work, not the default quick path.

CLI subcommand name used in terminal banners and parser errors.

Instances For

    Default JSON loss-curve path for this command.

    Instances For

      Static minibatch size for the ViT example.

      The batch axis is part of the checked model type, so changing this value changes the input and output shapes at compile time.

      Instances For

        CIFAR image channels.

        Instances For

          Height of the CIFAR crop used by this runnable ViT command.

          Instances For

            Width of the CIFAR crop used by this runnable ViT command.

            Instances For

              Patch height used by the convolutional patch embedding.

              Instances For

                Patch width used by the convolutional patch embedding.

                Instances For

                  Patch stride; equal to patch size here, so patches do not overlap.

                  Instances For

                    No zero-padding for the patch embedding.

                    Instances For

                      Transformer feature width. The 4×4 crop yields four 2×2 image patches, plus the learned class token used by the classifier.

                      Instances For

                        CIFAR class count, hence the output-logit width.

                        Instances For

                          Number of attention heads in each encoder block.

                          Instances For

                            Feed-forward hidden width inside the encoder block.

                            Instances For

                              Number of Transformer encoder blocks.

                              Instances For
                                @[reducible, inline]

                                Shared ViT configuration used by shapes and the reusable public model constructor.

                                Instances For
                                  @[reducible, inline]

                                  Batch shape used by this training example.

                                  Instances For
                                    @[reducible, inline]

                                    Batched image shape derived from modelConfig.

                                    Instances For
                                      @[reducible, inline]

                                      Batched classifier output derived from modelConfig.

                                      Instances For

                                        Compact ViT-style classifier from the public model API.

                                        The constructor builds patch embedding, token reshape, positional embeddings, the configured encoder stack, token pooling, and the classifier head.

                                        Instances For

                                          Train the CIFAR ViT with the public Trainer surface.

                                          Instances For

                                            CLI entrypoint for CIFAR ViT training on the selected runtime device.

                                            Instances For