Readable, hackable JEPAs and latent world models in plain PyTorch.
First exam · 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 builds both:
- Plain PyTorch. Only
torch. No trainer classes, no config system, no custom runtime. - One file per recipe. The whole training loop in view, from data to
optimizer.step(). - Reusable blocks. Encoders, predictors, regularizers, planners, and evaluation, each usable on its own, with documented tensor shapes.
- Fast. SDPA flash attention,
torch.compile, mixed precision, fused AdamW, and multi-GPU withtorchrun.
📝 Blog post: The First Exam For World Models
- Trains on an RTX 3060. One consumer GPU, minutes per level instead of days.
- Six levels, six problems. Movement, walls, distractors, contact, randomness, hidden state.
| Level | Dataset | World | What it tests |
|---|---|---|---|
| L0 | grid9-l0-empty | Empty board | Plain movement |
| L1 | grid9-l1-maze | S-maze | Walls that force detours |
| L2 | grid9-l2-distractor | Maze with flicker and a drifting square | Ignoring motion the actions do not cause |
| L3 | grid9-l3-push | One pushable block | Sparse contact, irreversible corners |
| L4 | grid9-l4-stochastic | Moves slip half the time | Two-outcome dynamics |
| L5 | grid9-l5-wind | Hidden per-episode wind | Partial observability |
Train LeWM on Grid9 L1 (the maze), then plan with it:
git clone https://github.com/HappyFox001/CleanJepa.git && cd CleanJepa
pip install -e ".[wm]"
python recipes/train_wm.py --preset lewm --data CleanJepa/grid9-l1-maze/grid_l1.h5 --frameskip 1 \
--amp bf16 --save-dir runs/grid9_l1
python recipes/eval_plan.py --env grid9-l1 --ckpt runs/grid9_l1/epoch_10.ptLeWMtrain_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 |
LeWAMtrain_lewam.py --preset grLeWAM (world model and policy) · LeWAMPlanner |
World models plan with CEMSolver, MPPISolver, or GradientPlanner; LeWAM also with
LeWAMPlanner, which refines samples of its own policy. Each recipe lists its
differences from the official code in its docstring.
The library is on PyPI and needs only PyTorch; the recipes stay in the repository.
pip install cleanjepaimport 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)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
- ROADMAP.md: goals and directions
- CONTRIBUTING.md: adding a method and reporting results
@software{cleanjepa,
title = {CleanJepa: Readable JEPAs and Latent World Models in PyTorch},
author = {{CleanJepa contributors}},
url = {https://github.com/HappyFox001/CleanJepa},
year = {2026}
}CleanJepa builds on the papers and official code of LeWM, LeJEPA, DINO-WM, LpWM, Rectified LpJEPA, LeWAM, I-JEPA, V-JEPA, and VICReg, and on the design of nanoGPT and CleanRL.