CleanJepa
Readable, hackable JEPAs and latent world models in plain PyTorch.
Quick start · Methods · Library · Roadmap · Contributing
A JEPA learns by predicting the representation of what it cannot see, instead of reconstructing pixels. JEPA world models go one step further: they predict the next latent state from an action, then plan by searching for actions whose predicted future matches a goal image.
CleanJepa implements this family in plain PyTorch, in the spirit of
nanoGPT and CleanRL.
The library is about 2,000 lines with torch as its only dependency, and every training script is
a single file you can read top to bottom.
- Plain PyTorch. No trainer classes, config systems, or custom runtimes between you and the
- Reusable blocks. Encoders, predictors, anti-collapse regularizers, planners, and evaluation
- One file per recipe. Each recipe keeps its training loop in view, from data to
loss.backward() and optimizer.step().
- Fast without magic. Flash attention through SDPA,
torch.compile, mixed precision, fused
torchrun.
Quick start
git clone https://github.com/HappyFox001/CleanJepa.git && cd CleanJepa
pip install -e .
Train a small LeWM-style world model on synthetic moving squares (no download needed)
python recipes/train_wm.py --synthetic --epochs 2
Or skip training: download a pretrained toy world model and watch it plan. --device auto uses
CUDA, then Apple-silicon MPS, then the CPU.
pip install -e ".[wm]"
hf download CleanJepa/toy-square-wm lpwm/seed0.pt --local-dir models
python recipes/eval_toy.py --ckpt models/lpwm/seed0.pt --num-eval 10 --device auto
See what it learns: this trains a model with and without SIGReg and plots their latent spaces side by side.
pip install -e ".[viz]"
python recipes/demo_manifold.py --epochs 40 --out manifold.png
Train on real data, in the LeWM HDF5 format (for example
quentinll/lewm-pusht), then probe what the
latents encode:
pip install -e ".[wm]"
python recipes/train_wm.py --data pusht_expert_train.h5 --amp bf16 --save-dir runs/pusht
python recipes/probe_wm.py --ckpt runs/pusht/epoch_10.pt --data pusht_expert_train.h5 --targets proprio
Compare methods on the toy world in one command: train each --preset, probe the latents, plan with
CEM, and print a table across seeds:
python recipes/toy_benchmark.py --out runs/toy_bench --methods lewm,lpwm,vicreg --seeds 0,1,2
Methods
LeWMtrain_wm.py --preset lewmViTEncoder · ARPredictor · SIGReg (LeJEPA) |
LpWMtrain_wm.py --preset lpwmRDMReg (Rectified LpJEPA) |
VICReg world modeltrain_wm.py --preset vicregVICReg |
DINO-WMtrain_wm.py --preset dino-wmFrozenDINOv2Encoder |
Token world modeltrain_wm.py --rep patches --head residualTokenPredictor (joint or factorized) |
V-JEPA 2-ACtrain_vjepa2_ac.pyACPredictor · VJEPA2ACWorldModel |
I-JEPAtrain_ijepa.pyViTEncoder · EMAEncoder |
V-JEPAtrain_vjepa.pyVideoViTEncoder · EMAEncoder |
World models plan with CEMSolver, MPPISolver, or GradientPlanner. Each recipe lists its
differences from the official code in its docstring.
Planning results
| Success rate | LpWM | DINO-WM | LeWM | VICReg | Random actions | |---|---|---|---|---|---| | Toy square world | 0.93 ± 0.06 | 0.92 ± 0.08 | 0.78 ± 0.17 | 0.76 ± 0.04 | 0.22 ± 0.15 |
Mean ± 95% CI over 3 seeds. Toy square world: toy_benchmark.py (30 epochs per method, CEM on 100 random
start/goal tasks reachable within 3 actions). Raw results, training logs, and the exact
command: CleanJepa/results.
Use it as a library
import torch
from cleanjepa import CEMSolver, JEPAWorldModel, SIGReg, ViTEncoder
encoder = ViTEncoder(img_size=224, patch_size=14, embed_dim=192, depth=12, heads=3)
model = JEPAWorldModel(encoder, action_dim=10, embed_dim=192, history_size=3)
sigreg = SIGReg()
pixels = torch.randn(8, 4, 3, 224, 224) # (B, T, C, H, W)
actions = torch.randn(8, 4, 10) # (B, T, A)
emb = model.encode_pixels(pixels) # (B, T, D)
pred = model.predict(emb[:, :3], model.encode_actions(actions)[:, :3])
loss = (pred - emb[:, 1:]).pow(2).mean() + 0.09 * sigreg(emb)
loss.backward()
Plan 5 action blocks that move the last frame towards a goal image.
planner = CEMSolver(model, horizon=5, num_samples=300, topk=30)
plan = planner.plan(pixels[:, :1], pixels[:, 3:], action_dim=10) # (B, 5, A)
Repository layout
cleanjepa/ The library: models, regularizers, planners, data, evaluation (torch only)
recipes/ One script per task: training, probing, planning evaluation, benchmarking
tests/ Fast CPU tests, one file per area
Learn more
- ROADMAP.md: goals and directions
- CONTRIBUTING.md: adding a method and reporting results
Citation
@software{cleanjepa,
title = {CleanJepa: Readable JEPAs and Latent World Models in PyTorch},
author = {{CleanJepa contributors}},
url = {https://github.com/HappyFox001/CleanJepa},
year = {2026}
}
Acknowledgements
CleanJepa builds on the papers and official code of LeWM, LeJEPA, DINO-WM, LpWM, Rectified LpJEPA, I-JEPA, V-JEPA, and VICReg, and on the design of nanoGPT and CleanRL.