This repository contains a full implementation of the architecture described in:
VL-JEPA: Joint Embedding Predictive Architecture for Vision-language (arXiv:2512.10942v2, Feb 2, 2026).
The code includes:
- VL-JEPA model (
X-Encoder, query-conditionedPredictor,Y-Encoder) - Bi-directional InfoNCE training objective in embedding space
- Two-stage training pipelines (
pretraining,SFT) - Inference for captioning, discriminative VQA, and selective decoding
- Retrieval/classification utilities via embedding similarity
- Unit tests for critical utility and algorithmic components
- OS: Linux/macOS (Windows should work with equivalent commands)
- Python: 3.10+ recommended
- Disk: at least 10 GB free for CPU setup, more for GPU + large checkpoints
- Optional for paper-scale configs: internet access to download Hugging Face models/checkpoints
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip setuptools wheelThis path is stable for smoke tests and development.
pip install --index-url https://download.pytorch.org/whl/cpu torch torchvision
pip install Pillow PyYAML tqdm pytestOptional (only needed for non-toy text/vision models):
pip install transformersUse this when training larger models or running paper-scale configs.
- Confirm GPU is visible:
nvidia-smi- Install PyTorch CUDA wheels (example for CUDA 12.1):
pip install --index-url https://download.pytorch.org/whl/cu121 torch torchvision
pip install Pillow PyYAML tqdm pytest transformersIf your system uses a different CUDA build, choose the matching PyTorch index URL from official PyTorch install docs.
python -c "import torch; print('torch', torch.__version__, 'cuda', torch.cuda.is_available())"
python -c "import torchvision, PIL, yaml, tqdm; print('deps ok')"Expected:
- CPU setup:
cuda False - GPU setup:
cuda True(if driver/runtime are correct)
This repo has two practical config tracks:
- Tiny/offline configs (works without external model downloads):
vljepa/configs/pretrain_tiny.yamlvljepa/configs/inference_tiny.yaml
- Paper-style configs (require heavier backbones/model downloads):
vljepa/configs/pretrain.yamlvljepa/configs/sft.yamlvljepa/configs/inference.yaml
Edit these keys in YAML:
runtime.device:cpuorcudamodel.vision_backbone:- tiny/offline:
toy_cnn - heavier:
vit_b_16,vit_l_16, or supported HF model viahf:<model_name>
- tiny/offline:
model.query_model_nameandmodel.y_encoder_name:- tiny/offline:
toy - paper-style: real Hugging Face model names
- tiny/offline:
CPU tiny end-to-end:
PYTHONPATH=. python scripts/make_tiny_data.py
PYTHONPATH=. python scripts/train_pretrain.py --config vljepa/configs/pretrain_tiny.yaml
PYTHONPATH=. python scripts/run_inference.py \
--config vljepa/configs/inference_tiny.yaml \
--checkpoint outputs/tiny_pretrain/step_0000002.pt \
--manifest data/tiny_infer_manifest.jsonl \
--text-bank data/tiny_text_bank.txt \
--mode captionInteractive chat loop:
PYTHONPATH=. python scripts/chat_vljepa.py \
--config vljepa/configs/inference_tiny.yaml \
--checkpoint outputs/tiny_pretrain/step_0000002.pt \
--text-bank data/tiny_text_bank.txt \
--image data/tiny/red.pngModuleNotFoundError: vljepa- Run commands with
PYTHONPATH=.from repository root.
- Run commands with
- CUDA not detected even on GPU machine
- Check
nvidia-smi, CUDA driver compatibility, and PyTorch CUDA wheel index.
- Check
- Out-of-memory on GPU
- Reduce batch size, image size, num frames, or use tiny configs first.
- Download/auth failures for HF models
- Use tiny configs (
toy_*) for offline validation first.
- Use tiny configs (
Training uses JSONL manifests. Each line:
{"image":"path/to/image.jpg","query":"Describe the scene.","target":"A person is cooking."}or:
{"video":"path/to/video.mp4","query":"What happens next?","target":"The person opens the door.","candidates":["open door","sit down","wash hands"]}Examples:
data/pretrain_manifest.example.jsonldata/sft_manifest.example.jsonl
Implemented paper choices:
- Frozen visual encoder + trainable predictor + trainable text target encoder.
- Shared projection space with 1536-d target embedding space.
- Query-conditioned embedding prediction.
- Bi-directional InfoNCE for anti-collapse and alignment.
- Y-encoder learning-rate multiplier (
0.05default). - Two-stage schedule structure:
- Stage 1 pretraining: constant LR (
5e-5) - Stage 2 SFT: cosine annealing
- Stage 1 pretraining: constant LR (
- Selective decoding using temporal segmentation with Ward-style agglomerative clustering.
Notes:
- The paper uses V-JEPA2 and specific internal data mixtures (Datacomp/YFCC/Action100M/PLM). This implementation provides the same training logic and interfaces, with user-provided datasets/checkpoints.
- Default backbone/model names are placeholders that can be replaced with available checkpoints.
- Copy template manifest:
cp data/pretrain_manifest.example.jsonl data/pretrain_manifest.jsonl- Run:
python scripts/train_pretrain.py --config vljepa/configs/pretrain.yaml- Copy template manifest:
cp data/sft_manifest.example.jsonl data/sft_manifest.jsonl- Run:
python scripts/train_sft.py \
--config vljepa/configs/sft.yaml \
--checkpoint outputs/pretrain/step_0001000.ptpython scripts/run_inference.py \
--config vljepa/configs/inference.yaml \
--checkpoint outputs/sft/step_0001000.pt \
--manifest data/sft_manifest.jsonl \
--text-bank data/text_bank.example.txt \
--mode captionpython scripts/run_inference.py \
--config vljepa/configs/inference.yaml \
--checkpoint outputs/sft/step_0001000.pt \
--manifest data/sft_manifest.jsonl \
--mode discriminative_vqapython scripts/run_inference.py \
--config vljepa/configs/inference.yaml \
--checkpoint outputs/sft/step_0001000.pt \
--manifest data/single_video.jsonl \
--text-bank data/text_bank.example.txt \
--mode selective \
--num-segments 12Use this path to verify end-to-end execution without external model downloads:
- local toy vision/text encoders
- synthetic local image data
- CPU-only tiny run
Commands:
python scripts/make_tiny_data.py
python scripts/train_pretrain.py --config vljepa/configs/pretrain_tiny.yaml
python scripts/run_inference.py \
--config vljepa/configs/inference_tiny.yaml \
--checkpoint outputs/tiny_pretrain/step_0000002.pt \
--manifest data/tiny_infer_manifest.jsonl \
--text-bank data/tiny_text_bank.txt \
--mode captionExpected smoke-test behavior:
- training finishes 2 steps and saves checkpoints under
outputs/tiny_pretrain/ - inference prints one JSON line with a predicted label from the tiny text bank
You can talk to the model in a multi-turn terminal loop:
python scripts/chat_vljepa.py \
--config vljepa/configs/inference_tiny.yaml \
--checkpoint outputs/tiny_pretrain/step_0000002.pt \
--text-bank data/tiny_text_bank.txt \
--image data/tiny/red.pngInside the prompt:
- type normal text to ask questions
/image path/to/new_image.pngswitches visual context/resetclears conversation memory/exitquits
Important:
- this is chat-style interaction around VL-JEPA embedding retrieval
- replies are selected from the provided text bank (not free-form token generation)
vljepa/models/vljepa.py: core VL-JEPA model and parameter groupsvljepa/models/losses.py: bi-directional InfoNCEvljepa/train/trainer.py: training loop/checkpointingvljepa/inference/decoder.py: lightweight readout decodervljepa/inference/selective.py: temporal selective decodingvljepa/eval/tasks.py: discriminative match/retrieval helpersscripts/*.py: CLI entrypoints (train,inference,chat)
- Determinism:
- training scripts call
set_seed(..., deterministic=True) - deterministic algorithm mode is enabled where possible
- training scripts call
- Explicit config control:
- all hyperparameters live in YAML config files
- each run writes
resolved_config.yamlinto its output directory
- Run metadata:
- trainer writes
run_meta.json(PyTorch/CUDA/device/platform)
- trainer writes
- Logs and checkpoints:
- step-wise JSONL logs:
train_log.jsonl
- step-wise JSONL logs:
- periodic checkpoints:
step_XXXXXXX.pt
Run:
pytest -qCurrent tests cover:
- InfoNCE loss correctness/guards
- selective decoding segmentation behavior
- config validation and RNG determinism
- Delong Chen, Mustafa Shukor, Théo Moutakanni, Willy Chung, Jade Yu, Tejaswi Kasarla,
Yejin Bang, Allen Bolourchi, Yann LeCun, Pascale Fung.
VL-JEPA: Joint Embedding Predictive Architecture for Vision-language. arXiv:2512.10942v2, February 2, 2026.