# facebookresearch/vjepa2 architecture

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

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

## Overview

#### Purpose and entry points
V-JEPA 2 is a PyTorch research codebase for self-supervised video representation learning, action-conditioned world-model post-training, frozen-backbone evaluation, and model consumption through PyTorch Hub. Local and SLURM training dispatch through `app/main.py` and `app/main_distributed.py`; evaluation equivalents are `evals/main.py` and `evals/main_distributed.py`. Hub exports are defined by `hubconf.py`.

#### Training dispatch and experiment variants
The app entrypoints load a YAML experiment and select one of three training families: baseline V-JEPA 2, V-JEPA 2.1, or DROID action-conditioned post-training. Each family owns its train loop, transforms, and setup utilities:
- `app/vjepa/train.py`
- `app/vjepa_2_1/train.py`
- `app/vjepa_droid/train.py`

Experiment configs form the boundary between reusable code and run-specific topology, data locations, checkpoints, model scale, and phase (pretrain/cooldown/post-train): `configs/train/`, `configs/train_2_1/`.

#### Video data and augmentation pipeline
Training/evaluation consume image or video datasets through shared dataset construction, sampling, decoding, and worker infrastructure. Video transforms are applied before model tokenization; mask generation is a separate stage driven by training configuration.
- `src/datasets/data_manager.py`
- `src/datasets/video_dataset.py`
- `src/datasets/utils/video/transforms_builder.py`

The material decoder dependency is `decord`; the project is intended for CUDA-capable PyTorch environments and uses multi-GPU execution where configured.

#### Masked latent-prediction backbone
The core representation stack is a Vision Transformer that turns video/image patches into latent tokens, plus a predictor that estimates target latents from visible context. Masking policies define which spatiotemporal tokens are context versus prediction targets.
- `src/models/vision_transformer.py`
- `src/models/predictor.py`
- `src/masks/multiseq_multiblock3d.py`

V-JEPA 2.1 maintains a dedicated model implementation for its dense predictive loss and deep, intermediate-layer supervision:
- `app/vjepa_2_1/models/vision_transformer.py`
- `app/vjepa_2_1/models/predictor.py`
- `app/vjepa_2_1/models/utils/masks_dist.py`

#### Action-conditioned world model
The DROID branch post-trains a pretrained V-JEPA encoder on robot trajectories. It introduces action-conditioned latent prediction, enabling scoring/planning over robot action sequences rather than merely learning passive video features.
- `app/vjepa_droid/droid.py`
- `app/vjepa_droid/train.py`
- `src/models/ac_predictor.py`

The included planning-facing examples wrap this learned model and use trajectory/energy-landscape workflows: `notebooks/utils/world_model_wrapper.py`, `notebooks/utils/mpc_utils.py`.

#### Evaluation and probes
Evaluation freezes a pretrained backbone, extracts its features, and trains or runs task-specific attentive probes. The evaluation dispatcher selects video classification, image classification, or EPIC-KITCHENS action anticipation implementations.
- `evals/video_classification_frozen/eval.py`
- `evals/image_classification_frozen/eval.py`
- `evals/action_anticipation_frozen/eval.py`

Evaluation and inference configs parameterize benchmark datasets, backbone checkpoints, probe checkpoints, and run mode under `configs/eval/`, `configs/eval_2_1/`, and `configs/inference/`.

#### Checkpoints, distributed execution, and external model services
Checkpoint loading, logging/monitoring, scheduling, and distributed primitives are centralized rather than embedded in model code:
- `src/utils/checkpoint_loader.py`
- `src/utils/distributed.py`
- `src/utils/schedulers.py`

Distributed launch targets SLURM through the distributed entrypoints/scaffolds. Pretrained weights are obtained externally from Meta public download URLs or Hugging Face; PyTorch Hub model/preprocessor construction is exposed through `src/hub/backbones.py` and `evals/hub/preprocessor.py`.

Main entry points: [`app/vjepa/train.py`](https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa/train.py) (V-JEPA 2 training), [`app/main.py`](https://github.com/facebookresearch/vjepa2/blob/main/app/main.py) (Training dispatcher), [`app/vjepa_droid/train.py`](https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa_droid/train.py) (DROID post-training), [`src/models/vision_transformer.py`](https://github.com/facebookresearch/vjepa2/blob/main/src/models/vision_transformer.py) (V-JEPA encoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_train["Training"]
  node_train_dispatch["Training dispatcher<br/>PyTorch entrypoint<br/>[main.py]"]
  node_distributed_train["Distributed training<br/>SLURM entrypoint"]
  node_train_configs["Training experiments<br/>YAML configs"]
  node_baseline_train["V-JEPA 2 training<br/>train loop<br/>[train.py]"]
  node_v21_train["V-JEPA 2.1 training<br/>train loop<br/>[train.py]"]
  node_droid_train["DROID post-training<br/>train loop<br/>[train.py]"]
end

subgraph group_core["Data &amp; representation"]
  node_dataset_manager["Dataset construction<br/>data pipeline<br/>[data_manager.py]"]
  node_video_dataset["Video sampling &amp; decode<br/>dataset<br/>[video_dataset.py]"]
  node_transforms["Video transforms<br/>augmentation"]
  node_mask_policy["Token mask policy<br/>mask generator"]
  node_vit["V-JEPA encoder<br/>Vision Transformer"]
  node_predictor["Latent predictor<br/>[predictor.py]"]
  node_v21_models["V-JEPA 2.1 models<br/>dedicated encoder"]
  node_ac_predictor["Action-conditioned predictor<br/>world model<br/>[ac_predictor.py]"]
end

subgraph group_eval["Evaluation &amp; consumption"]
  node_eval_dispatch["Evaluation dispatcher<br/>PyTorch entrypoint<br/>[main.py]"]
  node_video_probe["Video classification probe<br/>frozen evaluation<br/>[eval.py]"]
  node_image_probe["Image classification probe<br/>frozen evaluation<br/>[eval.py]"]
  node_anticipation_probe["Action anticipation probe<br/>frozen evaluation<br/>[eval.py]"]
  node_world_model_wrapper["Planning wrapper<br/>notebook utility"]
  node_hub_backbones["Hub backbones<br/>PyTorch Hub export<br/>[backbones.py]"]
end

subgraph group_runtime["Runtime services"]
  node_checkpointing[("Checkpoints<br/>model lifecycle")]
  node_distributed_utils["Distributed primitives<br/>multi-GPU runtime<br/>[distributed.py]"]
  node_schedulers["Learning-rate schedules<br/>optimization runtime<br/>[schedulers.py]"]
end

node_distributed_train -->|"launches"| node_train_dispatch
node_train_configs -->|"selects run"| node_train_dispatch
node_train_dispatch -->|"baseline"| node_baseline_train
node_train_dispatch -->|"2.1"| node_v21_train
node_train_dispatch -->|"DROID"| node_droid_train
node_baseline_train -->|"builds data"| node_dataset_manager
node_v21_train -->|"builds data"| node_dataset_manager
node_droid_train -->|"robot data"| node_dataset_manager
node_dataset_manager -->|"constructs"| node_video_dataset
node_video_dataset -->|"applies"| node_transforms
node_baseline_train -->|"configures"| node_mask_policy
node_mask_policy -->|"masks tokens"| node_vit
node_vit -->|"context latents"| node_predictor
node_baseline_train -->|"optimizes"| node_vit
node_v21_train -->|"trains"| node_v21_models
node_droid_train -->|"starts from encoder"| node_vit
node_droid_train -->|"trains"| node_ac_predictor
node_ac_predictor -->|"planning model"| node_world_model_wrapper
node_checkpointing -->|"restore/save"| node_baseline_train
node_checkpointing -->|"restore/save"| node_v21_train
node_checkpointing -->|"loads encoder"| node_droid_train
node_distributed_utils -->|"supports"| node_distributed_train
node_schedulers -->|"schedules"| node_baseline_train
node_eval_dispatch -->|"video task"| node_video_probe
node_eval_dispatch -->|"image task"| node_image_probe
node_eval_dispatch -->|"EPIC task"| node_anticipation_probe
node_checkpointing -->|"loads backbone"| node_eval_dispatch
node_vit -->|"exported as"| node_hub_backbones

click node_train_dispatch "https://github.com/facebookresearch/vjepa2/blob/main/app/main.py"
click node_distributed_train "https://github.com/facebookresearch/vjepa2/blob/main/app/main_distributed.py"
click node_train_configs "https://github.com/facebookresearch/vjepa2/tree/main/configs/train"
click node_baseline_train "https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa/train.py"
click node_v21_train "https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa_2_1/train.py"
click node_droid_train "https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa_droid/train.py"
click node_dataset_manager "https://github.com/facebookresearch/vjepa2/blob/main/src/datasets/data_manager.py"
click node_video_dataset "https://github.com/facebookresearch/vjepa2/blob/main/src/datasets/video_dataset.py"
click node_transforms "https://github.com/facebookresearch/vjepa2/blob/main/src/datasets/utils/video/transforms_builder.py"
click node_mask_policy "https://github.com/facebookresearch/vjepa2/blob/main/src/masks/multiseq_multiblock3d.py"
click node_vit "https://github.com/facebookresearch/vjepa2/blob/main/src/models/vision_transformer.py"
click node_predictor "https://github.com/facebookresearch/vjepa2/blob/main/src/models/predictor.py"
click node_v21_models "https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa_2_1/models/vision_transformer.py"
click node_ac_predictor "https://github.com/facebookresearch/vjepa2/blob/main/src/models/ac_predictor.py"
click node_eval_dispatch "https://github.com/facebookresearch/vjepa2/blob/main/evals/main.py"
click node_video_probe "https://github.com/facebookresearch/vjepa2/blob/main/evals/video_classification_frozen/eval.py"
click node_image_probe "https://github.com/facebookresearch/vjepa2/blob/main/evals/image_classification_frozen/eval.py"
click node_anticipation_probe "https://github.com/facebookresearch/vjepa2/blob/main/evals/action_anticipation_frozen/eval.py"
click node_world_model_wrapper "https://github.com/facebookresearch/vjepa2/blob/main/notebooks/utils/world_model_wrapper.py"
click node_hub_backbones "https://github.com/facebookresearch/vjepa2/blob/main/src/hub/backbones.py"
click node_checkpointing "https://github.com/facebookresearch/vjepa2/blob/main/src/utils/checkpoint_loader.py"
click node_distributed_utils "https://github.com/facebookresearch/vjepa2/blob/main/src/utils/distributed.py"
click node_schedulers "https://github.com/facebookresearch/vjepa2/blob/main/src/utils/schedulers.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_train_dispatch,node_distributed_train,node_train_configs,node_baseline_train,node_v21_train,node_droid_train toneBlue
class node_dataset_manager,node_video_dataset,node_transforms,node_mask_policy,node_vit,node_predictor,node_v21_models,node_ac_predictor toneAmber
class node_eval_dispatch,node_video_probe,node_image_probe,node_anticipation_probe,node_world_model_wrapper,node_hub_backbones toneMint
class node_checkpointing,node_distributed_utils,node_schedulers toneRose
```

## Components

### Training

- [Training dispatcher](https://github.com/facebookresearch/vjepa2/blob/main/app/main.py): PyTorch entrypoint · Selects baseline, 2.1, or DROID training from YAML. · `app/main.py`
- [Distributed training](https://github.com/facebookresearch/vjepa2/blob/main/app/main_distributed.py): SLURM entrypoint · `app/main_distributed.py`
- [Training experiments](https://github.com/facebookresearch/vjepa2/tree/main/configs/train): YAML configs · Defines run topology, data, checkpoints, scale, and phase. · `configs/train`
- [V-JEPA 2 training](https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa/train.py): train loop · `app/vjepa/train.py`
- [V-JEPA 2.1 training](https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa_2_1/train.py): train loop · Uses dense predictive loss and intermediate supervision. · `app/vjepa_2_1/train.py`
- [DROID post-training](https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa_droid/train.py): train loop · Post-trains an encoder on robot trajectories. · `app/vjepa_droid/train.py`

### Data & representation

- [Dataset construction](https://github.com/facebookresearch/vjepa2/blob/main/src/datasets/data_manager.py): data pipeline · `src/datasets/data_manager.py`
- [Video sampling & decode](https://github.com/facebookresearch/vjepa2/blob/main/src/datasets/video_dataset.py): dataset · Uses decord-backed image and video loading. · `src/datasets/video_dataset.py`
- [Video transforms](https://github.com/facebookresearch/vjepa2/blob/main/src/datasets/utils/video/transforms_builder.py): augmentation · `src/datasets/utils/video/transforms_builder.py`
- [Token mask policy](https://github.com/facebookresearch/vjepa2/blob/main/src/masks/multiseq_multiblock3d.py): mask generator · Separates visible context and prediction targets. · `src/masks/multiseq_multiblock3d.py`
- [V-JEPA encoder](https://github.com/facebookresearch/vjepa2/blob/main/src/models/vision_transformer.py): Vision Transformer · Converts image or video patches into latent tokens. · `src/models/vision_transformer.py`
- [Latent predictor](https://github.com/facebookresearch/vjepa2/blob/main/src/models/predictor.py): predictor · Predicts target latents from visible context. · `src/models/predictor.py`
- [V-JEPA 2.1 models](https://github.com/facebookresearch/vjepa2/blob/main/app/vjepa_2_1/models/vision_transformer.py): dedicated encoder · Variant-specific encoder, predictor, and distributed masks. · `app/vjepa_2_1/models/vision_transformer.py`
- [Action-conditioned predictor](https://github.com/facebookresearch/vjepa2/blob/main/src/models/ac_predictor.py): world model · Conditions latent prediction on robot actions. · `src/models/ac_predictor.py`

### Evaluation & consumption

- [Evaluation dispatcher](https://github.com/facebookresearch/vjepa2/blob/main/evals/main.py): PyTorch entrypoint · Runs frozen-backbone benchmark evaluation. · `evals/main.py`
- [Video classification probe](https://github.com/facebookresearch/vjepa2/blob/main/evals/video_classification_frozen/eval.py): frozen evaluation · `evals/video_classification_frozen/eval.py`
- [Image classification probe](https://github.com/facebookresearch/vjepa2/blob/main/evals/image_classification_frozen/eval.py): frozen evaluation · `evals/image_classification_frozen/eval.py`
- [Action anticipation probe](https://github.com/facebookresearch/vjepa2/blob/main/evals/action_anticipation_frozen/eval.py): frozen evaluation · `evals/action_anticipation_frozen/eval.py`
- [Planning wrapper](https://github.com/facebookresearch/vjepa2/blob/main/notebooks/utils/world_model_wrapper.py): notebook utility · Exposes learned dynamics to trajectory and energy-landscape workflows. · `notebooks/utils/world_model_wrapper.py`
- [Hub backbones](https://github.com/facebookresearch/vjepa2/blob/main/src/hub/backbones.py): PyTorch Hub export · Constructs pretrained models and preprocessors. · `src/hub/backbones.py`

### Runtime services

- [Checkpoints](https://github.com/facebookresearch/vjepa2/blob/main/src/utils/checkpoint_loader.py): model lifecycle · Loads pretrained and resumed model weights. · `src/utils/checkpoint_loader.py`
- [Distributed primitives](https://github.com/facebookresearch/vjepa2/blob/main/src/utils/distributed.py): multi-GPU runtime · Supports distributed and SLURM execution. · `src/utils/distributed.py`
- [Learning-rate schedules](https://github.com/facebookresearch/vjepa2/blob/main/src/utils/schedulers.py): optimization runtime · `src/utils/schedulers.py`

## Connections

- Distributed training → Training dispatcher: launches
- Training experiments → Training dispatcher: selects run
- Training dispatcher → V-JEPA 2 training: baseline
- Training dispatcher → V-JEPA 2.1 training: 2.1
- Training dispatcher → DROID post-training: DROID
- V-JEPA 2 training → Dataset construction: builds data
- V-JEPA 2.1 training → Dataset construction: builds data
- DROID post-training → Dataset construction: robot data
- Dataset construction → Video sampling & decode: constructs
- Video sampling & decode → Video transforms: applies
- V-JEPA 2 training → Token mask policy: configures
- Token mask policy → V-JEPA encoder: masks tokens
- V-JEPA encoder → Latent predictor: context latents
- V-JEPA 2 training → V-JEPA encoder: optimizes
- V-JEPA 2.1 training → V-JEPA 2.1 models: trains
- DROID post-training → V-JEPA encoder: starts from encoder
- DROID post-training → Action-conditioned predictor: trains
- Action-conditioned predictor → Planning wrapper: planning model
- Checkpoints → V-JEPA 2 training: restore/save
- Checkpoints → V-JEPA 2.1 training: restore/save
- Checkpoints → DROID post-training: loads encoder
- Distributed primitives → Distributed training: supports
- Learning-rate schedules → V-JEPA 2 training: schedules
- Evaluation dispatcher → Video classification probe: video task
- Evaluation dispatcher → Image classification probe: image task
- Evaluation dispatcher → Action anticipation probe: EPIC task
- Checkpoints → Evaluation dispatcher: loads backbone
- V-JEPA encoder → Hub backbones: exported as
