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 math.
- Reusable blocks. Encoders, predictors, anti-collapse regularizers, planners, and evaluation tools import on their own, with tensor shapes documented on every public function.
- One file per recipe. Each recipe keeps its training loop in view, from data to
loss.backward()andoptimizer.step(). - Fast without magic. Flash attention through SDPA,
torch.compile, mixed precision, fused AdamW, and multi-GPU training withtorchrun.
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
The library is on PyPI and needs only PyTorch; the recipes stay in the repository.
pip install cleanjepa
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.
License
Metadata
Release files for cleanjepa 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cleanjepa-0.1.0.tar.gz | 93.4 kB | With provenance | Details for cleanjepa-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cleanjepa-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for cleanjepa-0.1.0-py3-none-any.whl |
Total release size: 156.0 kB
Release files / cleanjepa-0.1.0.tar.gz
| Download URL | cleanjepa-0.1.0.tar.gz |
|---|---|
| Size | 93.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7559b3cbeae447ac79fca3779a36315a6a743d678b67ace08df944d12eeb4a17
|
|
BLAKE2b-256 checksum How to use checksums |
f58e11e8b94828851e86fc35e1ac9e112cea3e0a3c036de89f5fbbce81bd89a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / cleanjepa-0.1.0-py3-none-any.whl
| Download URL | cleanjepa-0.1.0-py3-none-any.whl |
|---|---|
| Size | 62.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37bb7fbe2722807bfdaedb6a8f9b57e435ea3d0cfb91c27340d0933942a5c451
|
|
BLAKE2b-256 checksum How to use checksums |
54c7a4d3902b89ab3370c2d2482efb98b10c227a285948e114209a72799ca67c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logSecurity for cleanjepa 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for cleanjepa-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.