Skip to main content

CleanJepa logo

CleanJepa

Readable, hackable JEPAs and latent world models in plain PyTorch.

CI Python 3.10+ PyTorch 2.1+ License: MIT

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 with torchrun.

World model's first exam

  • 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.

Animation: in each of the six Grid9 levels a world model imagines candidate rollouts, picks a plan, and acts in the real world until it reaches the goal Grid9 planning success rate per level: LeWM, LpWM, and random actions

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

Each model trains with train_wm.py --preset <method> --frameskip 1 (10 epochs) and plans with eval_grid9.py (CEM MPC on 50 start/goal tasks per level). Raw results, training logs, and the exact commands: CleanJepa/results.

Quick start

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_grid9.py --ckpt runs/grid9_l1/epoch_10.pt --level l1

Methods

LeWM
train_wm.py --preset lewm
ViTEncoder · ARPredictor · SIGReg (LeJEPA)
LpWM
train_wm.py --preset lpwm
RDMReg (Rectified LpJEPA)
VICReg world model
train_wm.py --preset vicreg
VICReg
DINO-WM
train_wm.py --preset dino-wm
FrozenDINOv2Encoder
Token world model
train_wm.py --rep patches --head residual
TokenPredictor (joint or factorized)
V-JEPA 2-AC
train_vjepa2_ac.py
ACPredictor · VJEPA2ACWorldModel
I-JEPA
train_ijepa.py
ViTEncoder · EMAEncoder
V-JEPA
train_vjepa.py
VideoViTEncoder · EMAEncoder

World models plan with CEMSolver, MPPISolver, or GradientPlanner. Each recipe lists its differences from the official code in its docstring.

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

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

MIT

Metadata

Release files for cleanjepa 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cleanjepa 0.2.0
File Size Uploaded Provenance Actions
cleanjepa-0.2.0.tar.gz 99.3 kB With provenance Details for cleanjepa-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cleanjepa 0.2.0
File Interpreter ABI Platform Actions
cleanjepa-0.2.0-py3-none-any.whl Python 3 none any Details for cleanjepa-0.2.0-py3-none-any.whl

Total release size: 165.1 kB

Release files / cleanjepa-0.2.0.tar.gz

Download URL cleanjepa-0.2.0.tar.gz
Size 99.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9eefac6d7579a6dd4a3c6429d6581f41d73b72e98d6212218221d84b89027c4b
BLAKE2b-256 checksum
How to use checksums
4e7da9c8ceebef1a9925c6ffc52d1e42c2e3352a6869c4b24670295489ac4d45
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 4, 2026.

Transparency log

Release files / cleanjepa-0.2.0-py3-none-any.whl

Download URL cleanjepa-0.2.0-py3-none-any.whl
Size 65.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a929d5182014b9344a98b3f8f5a72df0b08d88fd444212f918f8a2402f0ed90
BLAKE2b-256 checksum
How to use checksums
3179359febc36f2bea0ab45b7f12f4335b537afe0f15a83cfa526ec9ed25ea79
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 4, 2026.

Transparency log

Security for cleanjepa 0.2.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.

Select from 2 files

Attestation for cleanjepa-0.2.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 4, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page