← 开源

Clean, minimal, pure-PyTorch JEPA & latent world models (LeWM, LpWM, I-JEPA, V-JEPA, DINO-WM) for ML researchers — zero framework bloat.

Python
增长势头
+10424 小时新增 Star+31.8%
431
Star
37
Fork
9
贡献者
创建于 2026-11-30 · 更新于 2026-12-06 · 今日第 180 名
主要开发者
HappyFox001chiragroy2007omarelshamy25x
README

CleanJepa

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

World model's first exam

📝 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

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_plan.py --env grid9-l1 --ckpt runs/grid9_l1/epoch_10.pt

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
LeWAM
train_lewam.py --preset gr
LeWAM (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.

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, LeWAM, I-JEPA, V-JEPA, and VICReg, and on the design of nanoGPT and CleanRL.

License

MIT

排名相邻

AI Rank iPhone 版

随时追踪 AI 模型榜单

在 App Store 下载