# facebookresearch/levit architecture

> Architecture diagram of the GitHub repository facebookresearch/levit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/facebookresearch/levit
- Repository: https://github.com/facebookresearch/levit

## Overview

LeViT is a PyTorch image-classification project providing model variants and pretrained weights, plus ImageNet-style training and evaluation. The principal workflow starts at `main.py`: it builds and transforms datasets, creates a LeViT model and training configuration, then delegates epochs or evaluation to `engine.py`, which computes losses and metrics. Distillation adds teacher predictions to training supervision; distributed helpers support multi-process runs. README documents several dataset/model and single-node/multinode capabilities. Some main-program wiring is unsampled, so uncertain links are omitted.

Main entry points: [`main.py`](https://github.com/facebookresearch/levit/blob/main/main.py) (Train/eval entry), [`engine.py`](https://github.com/facebookresearch/levit/blob/main/engine.py) (Epoch/eval engine), [`run_with_submitit.py`](https://github.com/facebookresearch/levit/blob/main/run_with_submitit.py) (Multinode launcher), [`hubconf.py`](https://github.com/facebookresearch/levit/blob/main/hubconf.py) (Hub model exports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Run orchestration"]
  node_main["Train/eval entry<br/>[main.py]"]
  node_submitit["Multinode launcher"]
end

subgraph group_data["Image data"]
  node_dataset["Dataset builders<br/>[datasets.py]"]
  node_sampler["Repeated sampler<br/>[samplers.py]"]
end

subgraph group_models["LeViT models"]
  node_model["LeViT variants<br/>[levit.py]"]
  node_conv_model["Conv LeViT<br/>[levit_c.py]"]
  node_hub["Hub model exports<br/>[hubconf.py]"]
end

subgraph group_learning["Training and evaluation"]
  node_engine["Epoch/eval engine<br/>[engine.py]"]
  node_loss["Distillation loss<br/>[losses.py]"]
  node_metrics["Metrics and logs<br/>[utils.py]"]
end

subgraph group_runtime["Distributed runtime"]
  node_distributed["Distributed helpers<br/>[utils.py]"]
end

node_user(("CLI user"))
node_image_data[("Image datasets")]
node_scheduler["Slurm/Submitit"]
node_checkpoints[("Model checkpoints")]
node_teacher["Teacher model"]

node_user -->|"starts run"| node_main
node_user -.->|"submits run"| node_submitit
node_submitit -.->|"submits job"| node_scheduler
node_submitit -.->|"invokes"| node_main
node_main -->|"builds data"| node_dataset
node_dataset -->|"loads images"| node_image_data
node_main -->|"samples data"| node_sampler
node_main -->|"creates model"| node_model
node_main -->|"selects variant"| node_conv_model
node_hub -->|"exports models"| node_model
node_hub -->|"exports models"| node_conv_model
node_main -->|"runs epochs"| node_engine
node_engine -->|"computes loss"| node_loss
node_loss -->|"gets predictions"| node_teacher
node_main -->|"loads/saves"| node_checkpoints
node_engine -->|"logs metrics"| node_metrics
node_main -->|"initializes"| node_distributed
node_engine -->|"synchronizes"| node_distributed

click node_main "https://github.com/facebookresearch/levit/blob/main/main.py"
click node_submitit "https://github.com/facebookresearch/levit/blob/main/run_with_submitit.py"
click node_dataset "https://github.com/facebookresearch/levit/blob/main/datasets.py"
click node_sampler "https://github.com/facebookresearch/levit/blob/main/samplers.py"
click node_model "https://github.com/facebookresearch/levit/blob/main/levit.py"
click node_conv_model "https://github.com/facebookresearch/levit/blob/main/levit_c.py"
click node_hub "https://github.com/facebookresearch/levit/blob/main/hubconf.py"
click node_engine "https://github.com/facebookresearch/levit/blob/main/engine.py"
click node_loss "https://github.com/facebookresearch/levit/blob/main/losses.py"
click node_metrics "https://github.com/facebookresearch/levit/blob/main/utils.py"
click node_distributed "https://github.com/facebookresearch/levit/blob/main/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_submitit,node_user toneBlue
class node_dataset,node_sampler,node_image_data,node_checkpoints toneAmber
class node_model,node_conv_model,node_hub toneMint
class node_engine,node_loss,node_metrics toneRose
class node_distributed,node_scheduler,node_teacher toneIndigo
```

## Components

### Run orchestration

- [Train/eval entry](https://github.com/facebookresearch/levit/blob/main/main.py): `main.py`
- [Multinode launcher](https://github.com/facebookresearch/levit/blob/main/run_with_submitit.py): `run_with_submitit.py`

### Image data

- [Dataset builders](https://github.com/facebookresearch/levit/blob/main/datasets.py): `datasets.py`
- [Repeated sampler](https://github.com/facebookresearch/levit/blob/main/samplers.py): `samplers.py`

### LeViT models

- [LeViT variants](https://github.com/facebookresearch/levit/blob/main/levit.py): `levit.py`
- [Conv LeViT](https://github.com/facebookresearch/levit/blob/main/levit_c.py): `levit_c.py`
- [Hub model exports](https://github.com/facebookresearch/levit/blob/main/hubconf.py): `hubconf.py`

### Training and evaluation

- [Epoch/eval engine](https://github.com/facebookresearch/levit/blob/main/engine.py): `engine.py`
- [Distillation loss](https://github.com/facebookresearch/levit/blob/main/losses.py): `losses.py`
- [Metrics and logs](https://github.com/facebookresearch/levit/blob/main/utils.py): `utils.py`

### Distributed runtime

- [Distributed helpers](https://github.com/facebookresearch/levit/blob/main/utils.py): `utils.py`

### Other components

- **CLI user**
- **Image datasets**
- **Slurm/Submitit**
- **Model checkpoints**
- **Teacher model**

## Connections

- CLI user → Train/eval entry: starts run
- CLI user → Multinode launcher: submits run
- Multinode launcher → Slurm/Submitit: submits job
- Multinode launcher → Train/eval entry: invokes
- Train/eval entry → Dataset builders: builds data
- Dataset builders → Image datasets: loads images
- Train/eval entry → Repeated sampler: samples data
- Train/eval entry → LeViT variants: creates model
- Train/eval entry → Conv LeViT: selects variant
- Hub model exports → LeViT variants: exports models
- Hub model exports → Conv LeViT: exports models
- Train/eval entry → Epoch/eval engine: runs epochs
- Epoch/eval engine → Distillation loss: computes loss
- Distillation loss → Teacher model: gets predictions
- Train/eval entry → Model checkpoints: loads/saves
- Epoch/eval engine → Metrics and logs: logs metrics
- Train/eval entry → Distributed helpers: initializes
- Epoch/eval engine → Distributed helpers: synchronizes
