LeVJEPA README

README проекта с github.com/MLO-lab/LeVJEPA. Одним файлом markdown: README.md.

LeVJEPA: Efficient & Scalable Video Pretraining without the Heuristics

Official implementation of LeVJEPA, the first video encoder trained under LeJEPA's collapse-free objective.

Lukas Kuhn, Lucas Maes, Giuseppe Serra, Quentin Le Lidec, Yann LeCun, Randall Balestriero, Florian Buettner

Paper on arXiv Project Page Model on Hugging Face

What is LeVJEPA?

Self-supervised video pretraining has so far relied on architectural machinery to avoid representation collapse:

LeVJEPA dispenses with all of it. A single encoder is trained with an invariance loss over global and local views of a clip. The loss is regularized by SIGReg, the Sketched Isotropic Gaussian Regularizer from LeJEPA, which constrains the embedding distribution to an isotropic Gaussian and so rules out collapse with a provable guarantee. The trainable architecture reduces to an encoder and a small projector, and the objective has a single hyperparameter, λ.

Because there is no target-encoder forward pass and no predictor, the cost of a training step depends only on the number of tokens the encoder sees. The paper develops two consequences of this:

Results

LeVJEPA-1.5-Large was trained on ~5,300 unique video hours with 151 exaflops of compute. That is 25.7× less data and 5.6× less compute than V-JEPA 1, and 321× less data and ~28.5× less compute than V-JEPA 2. All three encoders are evaluated frozen with attentive probing. The table shows mean accuracy (%):

LeVJEPA 1.5 Large V-JEPA 1 V-JEPA 2
Image (15 datasets) 83.34 83.03 84.90
Video (7 datasets) 68.94 72.79 74.61
Overall (22 datasets) 78.76 79.77 81.63

Per-dataset results and the training budget are on the model card.

Versions

This repository holds the second version of the code. The encoder of the paper and the released checkpoint (v1) uses a [cls] token over the whole clip and block-causal attention. The v1 code remains available as legacy/vision_transformer.py so that v1 checkpoints load and evaluate here (see Loading v1 models).

The v2 encoder (model.py) is built for streaming:

Pretraining is otherwise the paper's recipe:

Pretrained checkpoint

A ViT-L/16 is released as LeVJEPA-1.5-Large. It is a v1 encoder with 303M parameters, trained on 1.8M clips from Kinetics-710, Something-Something v2, Walking Tours and PE-Video. The released tensors are the EMA copy of the encoder.

It loads without this repository through transformers:

import torch
from transformers import AutoModel

model = AutoModel.from_pretrained("galilai-group/LeVJEPA-1.5-Large", trust_remote_code=True).eval()

video = torch.randn(1, 3, 16, 224, 224)   # (B, C, T, H, W), ImageNet-normalised, 16 frames at ~7.5 fps
with torch.no_grad():
    out = model(pixel_values=video)
out.last_hidden_state   # (1, 3137, 1024): [cls] + 16*14*14 patch tokens
out["pooler_output"]    # (1, 1024): the [cls] token

For a single image, repeat it along the time axis: image.unsqueeze(2).repeat(1, 1, 16, 1, 1). To see the features rather than just extract them, notebooks/feature_visualization.ipynb reproduces the paper's dense-feature visualizations: patch-token PCA on images and query-patch cosine similarity on videos. Leave config.attn_mode at "block_causal". The weights were trained causal, and full attention returns worse features without raising an error. The checkpoint is meant for frozen feature extraction and has no classification head. Like the v1 encoder code, the weights are under CC BY-NC 4.0.

Loading v1 models

legacy/encoder.py wraps the v1 encoder behind the v2 interface. It loads:

from legacy.encoder import load_legacy_encoder

encoder = load_legacy_encoder("galilai-group/LeVJEPA-1.5-Large", name="vit_large", num_frames=16)
cls, patches, _ = encoder(clip)   # clip (B, T, C, H, W) -> (B, D), (B, T, 196, D)

The evaluation below runs on v1 models with configs/model/levjepa_v1_vitl.yaml:

python -m eval.eval model=levjepa_v1_vitl checkpoint=galilai-group/LeVJEPA-1.5-Large
python -m eval.eval model=levjepa_v1_vitl checkpoint=/path/to/v1/last.ckpt   # ema=false probes the student

Setup

The project is managed with uv and runs from the repository root:

uv sync                   # training environment (CUDA 12.8 wheels on Linux)
uv sync --extra data      # + decord / yt-dlp, only to build the Walking Tours store (decord: Linux and Windows)
uv sync --extra notebook  # + matplotlib / jupyterlab / PyAV, for the notebooks

Data

Training and evaluation read Lance stores with one frame per row:

column type used by
frame binary encoded image (JPEG or PNG)
episode_idx int the video a row belongs to
label int class label (evaluation only)

All rows of one episode must be contiguous and in temporal order. Images are episodes of length 1. Stores written for v1, with schema (episode_idx, step_idx, frame, h, w, label), work unchanged.

Every training store needs an episode index, which you build once:

python scripts/build_episodes.py data/kinetics/train.lance   # writes data/kinetics/train.episodes.npz

Walking Tours

Walking Tours (Venkataramanan et al., Is ImageNet worth 1 video?, ICLR 2024) consists of 10 long (1–7 h), continuous, first-person city walks. It lets you reproduce video pretraining end to end from public data. The Hugging Face dataset ships only the YouTube URLs, so the build has two steps:

  1. Download the videos at 720p60 (~25 GB).
  2. Encode them into a Lance store (~33 GB) at 15 fps, short edge 384, JPEG quality 90, in 128-frame episodes. The episode index is written at the end.
bash scripts/download_walking_tours.sh                                       # network-bound
uv run python scripts/build_lance_walking_tours.py --workers 16             # CPU-bound, use many cores

Both default to data/walking_tours/. To keep the data elsewhere, pass the paths explicitly and set LEVJEPA_DATA_ROOT=/path/to/data for training; the store is then read from $LEVJEPA_DATA_ROOT/walking_tours/train.lance.

Pretraining

python train.py dataset=walking_tours             # ViT-B on Walking Tours, clips at 7.5 fps
python train.py                                   # configs/config.yaml: ViT-B on configs/dataset/single.yaml
python train.py dataset=mixture                   # several stores, see configs/dataset/mixture.yaml
torchrun --nproc_per_node=4 train.py trainer.devices=4

If you'd rather start small, notebooks/training_workshop.ipynb walks through the whole method in miniature. It builds a ViT-Tiny from this repository's components and trains it inside the notebook on five minutes of a Walking Tours video, using the same views and loss as train.py. It runs on a CUDA GPU, an Apple Silicon Mac (MPS) or plain CPU.

Any config value can be overridden on the command line with Hydra syntax, for example data.batch_size=32 wandb.mode=offline. Under Slurm, launch one task per GPU with srun. Ranks are read from SLURM_PROCID / SLURM_NTASKS (or RANK / WORLD_SIZE under torchrun).

The main settings in configs/config.yaml:

Muon

When muon is set, the encoder's transformer blocks are trained with Muon. These are the attention qkv/proj matrices and the SwiGLU gate/up/down matrices, selected by MUON_MODULES in train.py. Muon keeps a momentum buffer per weight matrix and orthogonalises it with a few Newton–Schulz iterations before each update. The update therefore has the same strength in every direction, rather than being dominated by a few large singular directions. Muon is only defined for 2-D matrices, so every other parameter stays on AdamW: the patch embedding, readout token, norms and projector. Both optimizers use the same learning-rate schedule. With adjust_lr_fn: match_rms_adamw, Muon's update is rescaled to the RMS of an AdamW update, so the AdamW learning rate and weight decay can be reused:

muon: {lr: 4e-4, weight_decay: 0.04, momentum: 0.95, nesterov: true, adjust_lr_fn: match_rms_adamw}

Evaluation

The encoder stays frozen while an attentive probe is trained on its patch tokens. The probe is V-JEPA 2's AttentiveClassifier with depth 4: three self-attention blocks over the tokens, then one learned query that cross-attends to them, then a linear classifier. The datasets follow V-JEPA's frozen-evaluation protocols:

python -m eval.eval checkpoint=/path/to/last.ckpt                    # ImageNet-1k
python -m eval.eval checkpoint=/path/to/last.ckpt benchmark=ssv2     # Something-Something v2, 16x2x3

When a checkpoint was trained with an EMA, the probe uses the EMA weights unless you set ema=false.

Learning rate and training length. The default learning rate is 3e-5. For the best numbers, search over learning rates when compute allows:

python -m eval.eval checkpoint=/path/to/last.ckpt "optimizer.lr=[3e-5,1e-4,3e-4,1e-3]"

Each learning rate trains its own probe on the same frozen tokens. The encoder still runs once per batch, so a search costs only the extra probe compute. Each probe logs val/top1@<lr>, and val/best_top1 is the best value over all learning rates and epochs so far.

Probes train for up to 50 epochs with early stopping: the run ends once no probe has improved its val/top1 for 10 epochs. Change this with trainer.max_epochs=... and early_stopping.patience=..., or turn early stopping off with early_stopping=null.

Repository layout

train.py                     pretraining entry point (optimizers, schedule, loss step)
model.py                     v2 encoder (sliding-window causal ViT, readout token) and projector
loss.py                      SIGReg
data.py                      lance loading, episode / mixture sampling, GPU view augmentation
eval/eval.py                 frozen attentive-probe evaluation
eval/datasets.py             V-JEPA image and video evaluation datasets
eval/probe.py                V-JEPA 2 attentive probe (depth 4) and its lr / weight-decay schedule
legacy/vision_transformer.py v1 encoder (the paper's ViT), for v1 checkpoints
legacy/encoder.py            v1 checkpoint loading behind the v2 encoder interface
scripts/build_episodes.py    episode index of a lance store
scripts/*walking_tours*      Walking Tours download and Lance store build
configs/                     Hydra configs (model, dataset, benchmark)
notebooks/                   training workshop and feature visualization of the released checkpoint

Citation

@misc{kuhn2026levjepaefficientscalable,
      title={LeVJEPA: Efficient & Scalable Video Pretraining without the Heuristics},
      author={Lukas Kuhn and Lucas Maes and Giuseppe Serra and Quentin Le Lidec and Yann LeCun and Randall Balestriero and Florian Buettner},
      year={2026},
      eprint={2608.27395},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2608.27395},
}

License

MIT (see LICENSE). eval/probe.py is adapted from Meta's V-JEPA 2, which is also MIT-licensed. Code adapted from Meta's V-JEPA remains under CC BY-NC 4.0:

The released checkpoint is also under CC BY-NC 4.0.

LeVJEPA (MLO-lab/LeVJEPA)

Ищем в базе…

Что это такое?Официальная реализация LeVJEPA — видеомодели с самостоятельным (self-supervised) обучением, которая тренируется с помощью свободной от коллапса (collapse-free) функции потерь из LeJEPA. В отличие от V-JEPA или VideoMAE, ей не нужны целевой энкодер с EMA, stop-gradient, предиктор или декодер для восстановления пикселей: только энкодер, небольшой проектор и один гиперпараметр функции потерь.
Это библиотека, которую можно установить через pip, или кодовая база, которую я запускаю сам?Это исследовательская кодовая база, которую вы запускаете прямо из репозитория, а не устанавливаемый пакет: окружением управляет uv, обучение идёт через точку входа Hydra (main.py), и есть два Jupyter-ноутбука — один для визуализации признаков, другой — мини-воркшоп по обучению с пошаговым руководством.
Как его запустить?Склонируйте репозиторий и выполните 'uv sync' (для ноутбуков добавьте '--extra notebook'). Самый быстрый старт — выпущенная контрольная точка (checkpoint): загрузите LeVJEPA-VideoMix-Large с HuggingFace с trustremotecode=True или откройте notebooks/featurevisualization.ipynb, чтобы изучить её признаки.
Есть ли подводные камни при использовании выпущенной контрольной точки?Несколько: нужен trustremotecode=True, так как код модели поставляется вместе с весами; на вход подаются 16 кадров (~2 секунды при 7.5 кадрах/с) с нормализацией ImageNet, а статичное изображение повторяется вдоль временной оси; оставьте блоково-каузальное (blockcausal) внимание по умолчанию — полное внимание тоже работает, но незаметно ухудшает признаки.
Какие-то части некоммерческие?Репозиторий под лицензией MIT, но module.py (адаптирован из V-JEPA от Meta) и веса выпущенной контрольной точки — под CC BY-NC 4.0, то есть эти части можно использовать только в некоммерческих целях.
Могу ли я пропустить обучение и просто скачать предобученные веса?Да — выпущена LeVJEPA-VideoMix-Large (ViT-L/16, 303 млн параметров), обученная на 1,8 млн клипов из Kinetics-710, Something-Something v2, Walking Tours и PE-Video. При замороженном внимательном пробировании (attentive probing) она даёт 69,5% top-1 на ImageNet-1K и 55,0% на SSv2, и предназначена для извлечения признаков в замороженном виде — классификационной головы у неё нет.
На каких данных обучается рецепт по умолчанию?Конфигурация по умолчанию обучает ViT-B/16 на Walking Tours: 10 видео городских прогулок от первого лица (по 1–7 часов каждое), скачанных с YouTube в 720p60 (~25 ГБ) и закодированных в хранилище кадров Lance размером ~33 ГБ, так что предобучение воспроизводится от начала до конца на общедоступных данных. Для других данных достаточно yaml-файла в conf/data/ для хранилища Lance с той же схемой.
Как он сравнивается с V-JEPA 2?При равном числе эпох он не уступает или превосходит V-JEPA 2 на всех размерах ViT-S/B/L, затрачивая в 5,6–20,8 раза меньше суммарных вычислений на предобучение — LeVJEPA ViT-L обходится дешевле, чем половина вычислений V-JEPA 2 ViT-S. При равном бюджете FLOP (ViT-B) он выигрывает +7,6 пункта на ImageNet-1K (61,0%) и показывает лучший линейный пробинг на Kinetics-400 (44,6%).
Почему во время обучения отбрасывается 95% токенов патчей?С функцией потерь, свободной от коллапса, отбрасывание токенов работает как аугментация, а не как приближение: равномерное случайное отбрасывание монотонно повышает точность пробинга на замороженном ImageNet (с 33,9% при всех токенах до 47,6% при отбрасывании 95%), одновременно снижая стоимость каждого шага до 20 раз, тогда как структурированное трубчатое маскирование (tube masking) заметно вредит (с 50,7% до 39,6%).
Какие есть похожие проекты?dinov3, dinov2, sam2, pointdit, pytorch-image-models, CLIP, vision_transformer, Transformers-Tutorials
Автор
MLO-lab
Размер
1.4 MB
Звёзды
293
Обновлён
КоммитNov 02
Возраст
3 мес
Коммиты · 90 дней