cleanjepa 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cleanjepa-0.1.0/LICENSE +21 -0
- cleanjepa-0.1.0/PKG-INFO +232 -0
- cleanjepa-0.1.0/README.md +183 -0
- cleanjepa-0.1.0/cleanjepa/__init__.py +133 -0
- cleanjepa-0.1.0/cleanjepa/accel.py +153 -0
- cleanjepa-0.1.0/cleanjepa/checkpoint.py +240 -0
- cleanjepa-0.1.0/cleanjepa/data/__init__.py +23 -0
- cleanjepa-0.1.0/cleanjepa/data/toy.py +149 -0
- cleanjepa-0.1.0/cleanjepa/data/trajectory.py +121 -0
- cleanjepa-0.1.0/cleanjepa/distributed.py +72 -0
- cleanjepa-0.1.0/cleanjepa/evaluation.py +274 -0
- cleanjepa-0.1.0/cleanjepa/models/__init__.py +23 -0
- cleanjepa-0.1.0/cleanjepa/models/ac_predictor.py +286 -0
- cleanjepa-0.1.0/cleanjepa/models/dinov2.py +95 -0
- cleanjepa-0.1.0/cleanjepa/models/jepa.py +188 -0
- cleanjepa-0.1.0/cleanjepa/models/masked_predictor.py +63 -0
- cleanjepa-0.1.0/cleanjepa/models/predictor.py +202 -0
- cleanjepa-0.1.0/cleanjepa/models/video_vit.py +85 -0
- cleanjepa-0.1.0/cleanjepa/models/vit.py +149 -0
- cleanjepa-0.1.0/cleanjepa/planners/__init__.py +36 -0
- cleanjepa-0.1.0/cleanjepa/planners/_common.py +83 -0
- cleanjepa-0.1.0/cleanjepa/planners/cem.py +93 -0
- cleanjepa-0.1.0/cleanjepa/planners/grad.py +104 -0
- cleanjepa-0.1.0/cleanjepa/planners/mppi.py +86 -0
- cleanjepa-0.1.0/cleanjepa/provenance.py +90 -0
- cleanjepa-0.1.0/cleanjepa/regularizers/__init__.py +8 -0
- cleanjepa-0.1.0/cleanjepa/regularizers/ema.py +68 -0
- cleanjepa-0.1.0/cleanjepa/regularizers/rdmreg.py +73 -0
- cleanjepa-0.1.0/cleanjepa/regularizers/sigreg.py +122 -0
- cleanjepa-0.1.0/cleanjepa/regularizers/vicreg.py +72 -0
- cleanjepa-0.1.0/cleanjepa/results.py +77 -0
- cleanjepa-0.1.0/cleanjepa/training.py +159 -0
- cleanjepa-0.1.0/cleanjepa/utils.py +24 -0
- cleanjepa-0.1.0/cleanjepa.egg-info/PKG-INFO +232 -0
- cleanjepa-0.1.0/cleanjepa.egg-info/SOURCES.txt +49 -0
- cleanjepa-0.1.0/cleanjepa.egg-info/dependency_links.txt +1 -0
- cleanjepa-0.1.0/cleanjepa.egg-info/requires.txt +20 -0
- cleanjepa-0.1.0/cleanjepa.egg-info/top_level.txt +1 -0
- cleanjepa-0.1.0/pyproject.toml +55 -0
- cleanjepa-0.1.0/setup.cfg +4 -0
- cleanjepa-0.1.0/tests/test_data.py +102 -0
- cleanjepa-0.1.0/tests/test_eval_wm.py +494 -0
- cleanjepa-0.1.0/tests/test_evaluation.py +188 -0
- cleanjepa-0.1.0/tests/test_infra.py +183 -0
- cleanjepa-0.1.0/tests/test_masked_recipes.py +260 -0
- cleanjepa-0.1.0/tests/test_models.py +445 -0
- cleanjepa-0.1.0/tests/test_planners.py +160 -0
- cleanjepa-0.1.0/tests/test_regularizers.py +302 -0
- cleanjepa-0.1.0/tests/test_toy.py +330 -0
- cleanjepa-0.1.0/tests/test_train_wm.py +445 -0
- cleanjepa-0.1.0/tests/test_training.py +100 -0
cleanjepa-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CleanJepa Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
cleanjepa-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cleanjepa
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Clean, minimal, composable PyTorch implementations of JEPA & latent world models.
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026 CleanJepa Contributors
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
Project-URL: Homepage, https://github.com/HappyFox001/CleanJepa
|
|
28
|
+
Project-URL: Repository, https://github.com/HappyFox001/CleanJepa
|
|
29
|
+
Project-URL: Issues, https://github.com/HappyFox001/CleanJepa/issues
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Requires-Dist: torch>=2.1
|
|
34
|
+
Provides-Extra: wm
|
|
35
|
+
Requires-Dist: h5py>=3.10; extra == "wm"
|
|
36
|
+
Requires-Dist: hdf5plugin>=4.4; extra == "wm"
|
|
37
|
+
Requires-Dist: numpy>=1.24; extra == "wm"
|
|
38
|
+
Provides-Extra: hub
|
|
39
|
+
Requires-Dist: huggingface_hub>=0.34; extra == "hub"
|
|
40
|
+
Provides-Extra: logging
|
|
41
|
+
Requires-Dist: wandb>=0.16; extra == "logging"
|
|
42
|
+
Provides-Extra: viz
|
|
43
|
+
Requires-Dist: matplotlib>=3.8; extra == "viz"
|
|
44
|
+
Requires-Dist: numpy>=1.24; extra == "viz"
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
47
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
<p align="center">
|
|
51
|
+
<img src="https://raw.githubusercontent.com/HappyFox001/CleanJepa/main/assets/logo.svg" width="108" height="108" alt="CleanJepa logo" />
|
|
52
|
+
</p>
|
|
53
|
+
|
|
54
|
+
<h1 align="center">CleanJepa</h1>
|
|
55
|
+
|
|
56
|
+
<p align="center">
|
|
57
|
+
<strong>Readable, hackable JEPAs and latent world models in plain PyTorch.</strong>
|
|
58
|
+
</p>
|
|
59
|
+
|
|
60
|
+
<p align="center">
|
|
61
|
+
<a href="https://github.com/HappyFox001/CleanJepa/actions/workflows/ci.yml"><img src="https://github.com/HappyFox001/CleanJepa/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
|
|
62
|
+
<img src="https://img.shields.io/badge/python-3.10%2B-blue" alt="Python 3.10+" />
|
|
63
|
+
<img src="https://img.shields.io/badge/pytorch-2.1%2B-ee4c2c" alt="PyTorch 2.1+" />
|
|
64
|
+
<a href="https://github.com/HappyFox001/CleanJepa/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License: MIT" /></a>
|
|
65
|
+
</p>
|
|
66
|
+
|
|
67
|
+
<p align="center">
|
|
68
|
+
<a href="#quick-start">Quick start</a> ·
|
|
69
|
+
<a href="#methods">Methods</a> ·
|
|
70
|
+
<a href="#use-it-as-a-library">Library</a> ·
|
|
71
|
+
<a href="https://github.com/HappyFox001/CleanJepa/blob/main/ROADMAP.md">Roadmap</a> ·
|
|
72
|
+
<a href="https://github.com/HappyFox001/CleanJepa/blob/main/CONTRIBUTING.md">Contributing</a>
|
|
73
|
+
</p>
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
A JEPA learns by predicting the representation of what it cannot see, instead of reconstructing
|
|
78
|
+
pixels. JEPA world models go one step further: they predict the next latent state from an action,
|
|
79
|
+
then plan by searching for actions whose predicted future matches a goal image.
|
|
80
|
+
|
|
81
|
+
CleanJepa implements this family in plain PyTorch, in the spirit of
|
|
82
|
+
[nanoGPT](https://github.com/karpathy/nanoGPT) and [CleanRL](https://github.com/vwxyzjn/cleanrl).
|
|
83
|
+
The library is about 2,000 lines with `torch` as its only dependency, and every training script is
|
|
84
|
+
a single file you can read top to bottom.
|
|
85
|
+
|
|
86
|
+
- **Plain PyTorch.** No trainer classes, config systems, or custom runtimes between you and the
|
|
87
|
+
math.
|
|
88
|
+
- **Reusable blocks.** Encoders, predictors, anti-collapse regularizers, planners, and evaluation
|
|
89
|
+
tools import on their own, with tensor shapes documented on every public function.
|
|
90
|
+
- **One file per recipe.** Each recipe keeps its training loop in view, from data to
|
|
91
|
+
`loss.backward()` and `optimizer.step()`.
|
|
92
|
+
- **Fast without magic.** Flash attention through SDPA, `torch.compile`, mixed precision, fused
|
|
93
|
+
AdamW, and multi-GPU training with `torchrun`.
|
|
94
|
+
|
|
95
|
+
## Quick start
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
git clone https://github.com/HappyFox001/CleanJepa.git && cd CleanJepa
|
|
99
|
+
pip install -e .
|
|
100
|
+
|
|
101
|
+
# Train a small LeWM-style world model on synthetic moving squares (no download needed)
|
|
102
|
+
python recipes/train_wm.py --synthetic --epochs 2
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or skip training: download a pretrained toy world model and watch it plan. `--device auto` uses
|
|
106
|
+
CUDA, then Apple-silicon MPS, then the CPU.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install -e ".[wm]"
|
|
110
|
+
hf download CleanJepa/toy-square-wm lpwm/seed0.pt --local-dir models
|
|
111
|
+
python recipes/eval_toy.py --ckpt models/lpwm/seed0.pt --num-eval 10 --device auto
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
See what it learns: this trains a model with and without SIGReg and plots their latent spaces side
|
|
115
|
+
by side.
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
pip install -e ".[viz]"
|
|
119
|
+
python recipes/demo_manifold.py --epochs 40 --out manifold.png
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Train on real data, in the LeWM HDF5 format (for example
|
|
123
|
+
[`quentinll/lewm-pusht`](https://huggingface.co/datasets/quentinll/lewm-pusht)), then probe what the
|
|
124
|
+
latents encode:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pip install -e ".[wm]"
|
|
128
|
+
python recipes/train_wm.py --data pusht_expert_train.h5 --amp bf16 --save-dir runs/pusht
|
|
129
|
+
python recipes/probe_wm.py --ckpt runs/pusht/epoch_10.pt --data pusht_expert_train.h5 --targets proprio
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Compare methods on the toy world in one command: train each `--preset`, probe the latents, plan with
|
|
133
|
+
CEM, and print a table across seeds:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
python recipes/toy_benchmark.py --out runs/toy_bench --methods lewm,lpwm,vicreg --seeds 0,1,2
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Methods
|
|
140
|
+
|
|
141
|
+
<table>
|
|
142
|
+
<tr>
|
|
143
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2603.19312">LeWM</a></b><br><code>train_wm.py --preset lewm</code><br><sub><code>ViTEncoder</code> · <code>ARPredictor</code> · <code>SIGReg</code> (<a href="https://arxiv.org/abs/2511.08544">LeJEPA</a>)</sub></td>
|
|
144
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2608.22764">LpWM</a></b><br><code>train_wm.py --preset lpwm</code><br><sub><code>RDMReg</code> (<a href="https://arxiv.org/abs/2602.01456">Rectified LpJEPA</a>)</sub></td>
|
|
145
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2105.04906">VICReg</a> world model</b><br><code>train_wm.py --preset vicreg</code><br><sub><code>VICReg</code></sub></td>
|
|
146
|
+
</tr>
|
|
147
|
+
<tr>
|
|
148
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2411.04983">DINO-WM</a></b><br><code>train_wm.py --preset dino-wm</code><br><sub><code>FrozenDINOv2Encoder</code></sub></td>
|
|
149
|
+
<td width="33%" valign="top"><b>Token world model</b><br><code>train_wm.py --rep patches --head residual</code><br><sub><code>TokenPredictor</code> (joint or factorized)</sub></td>
|
|
150
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2506.09985">V-JEPA 2-AC</a></b><br><code>train_vjepa2_ac.py</code><br><sub><code>ACPredictor</code> · <code>VJEPA2ACWorldModel</code></sub></td>
|
|
151
|
+
</tr>
|
|
152
|
+
<tr>
|
|
153
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2301.08243">I-JEPA</a></b><br><code>train_ijepa.py</code><br><sub><code>ViTEncoder</code> · <code>EMAEncoder</code></sub></td>
|
|
154
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2404.08471">V-JEPA</a></b><br><code>train_vjepa.py</code><br><sub><code>VideoViTEncoder</code> · <code>EMAEncoder</code></sub></td>
|
|
155
|
+
<td width="33%"></td>
|
|
156
|
+
</tr>
|
|
157
|
+
</table>
|
|
158
|
+
|
|
159
|
+
World models plan with `CEMSolver`, `MPPISolver`, or `GradientPlanner`. Each recipe lists its
|
|
160
|
+
differences from the official code in its docstring.
|
|
161
|
+
|
|
162
|
+
## Planning results
|
|
163
|
+
|
|
164
|
+
| Success rate | LpWM | DINO-WM | LeWM | VICReg | Random actions |
|
|
165
|
+
|---|---|---|---|---|---|
|
|
166
|
+
| Toy square world | 0.93 ± 0.06 | 0.92 ± 0.08 | 0.78 ± 0.17 | 0.76 ± 0.04 | 0.22 ± 0.15 |
|
|
167
|
+
|
|
168
|
+
Mean ± 95% CI over 3 seeds. Toy square world: `toy_benchmark.py` (30 epochs per method, CEM on 100 random
|
|
169
|
+
start/goal tasks reachable within 3 actions). Raw results, training logs, and the exact
|
|
170
|
+
command: [CleanJepa/results](https://huggingface.co/datasets/CleanJepa/results/tree/main/toy-square/2026-12-03).
|
|
171
|
+
|
|
172
|
+
## Use it as a library
|
|
173
|
+
|
|
174
|
+
The library is on PyPI and needs only PyTorch; the recipes stay in the repository.
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
pip install cleanjepa
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
import torch
|
|
182
|
+
from cleanjepa import CEMSolver, JEPAWorldModel, SIGReg, ViTEncoder
|
|
183
|
+
|
|
184
|
+
encoder = ViTEncoder(img_size=224, patch_size=14, embed_dim=192, depth=12, heads=3)
|
|
185
|
+
model = JEPAWorldModel(encoder, action_dim=10, embed_dim=192, history_size=3)
|
|
186
|
+
sigreg = SIGReg()
|
|
187
|
+
|
|
188
|
+
pixels = torch.randn(8, 4, 3, 224, 224) # (B, T, C, H, W)
|
|
189
|
+
actions = torch.randn(8, 4, 10) # (B, T, A)
|
|
190
|
+
|
|
191
|
+
emb = model.encode_pixels(pixels) # (B, T, D)
|
|
192
|
+
pred = model.predict(emb[:, :3], model.encode_actions(actions)[:, :3])
|
|
193
|
+
loss = (pred - emb[:, 1:]).pow(2).mean() + 0.09 * sigreg(emb)
|
|
194
|
+
loss.backward()
|
|
195
|
+
|
|
196
|
+
# Plan 5 action blocks that move the last frame towards a goal image.
|
|
197
|
+
planner = CEMSolver(model, horizon=5, num_samples=300, topk=30)
|
|
198
|
+
plan = planner.plan(pixels[:, :1], pixels[:, 3:], action_dim=10) # (B, 5, A)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Repository layout
|
|
202
|
+
|
|
203
|
+
```text
|
|
204
|
+
cleanjepa/ The library: models, regularizers, planners, data, evaluation (torch only)
|
|
205
|
+
recipes/ One script per task: training, probing, planning evaluation, benchmarking
|
|
206
|
+
tests/ Fast CPU tests, one file per area
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Learn more
|
|
210
|
+
|
|
211
|
+
- [ROADMAP.md](https://github.com/HappyFox001/CleanJepa/blob/main/ROADMAP.md): goals and directions
|
|
212
|
+
- [CONTRIBUTING.md](https://github.com/HappyFox001/CleanJepa/blob/main/CONTRIBUTING.md): adding a method and reporting results
|
|
213
|
+
|
|
214
|
+
## Citation
|
|
215
|
+
|
|
216
|
+
```bibtex
|
|
217
|
+
@software{cleanjepa,
|
|
218
|
+
title = {CleanJepa: Readable JEPAs and Latent World Models in PyTorch},
|
|
219
|
+
author = {{CleanJepa contributors}},
|
|
220
|
+
url = {https://github.com/HappyFox001/CleanJepa},
|
|
221
|
+
year = {2026}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Acknowledgements
|
|
226
|
+
|
|
227
|
+
CleanJepa builds on the papers and official code of LeWM, LeJEPA, DINO-WM, LpWM, Rectified LpJEPA,
|
|
228
|
+
I-JEPA, V-JEPA, and VICReg, and on the design of nanoGPT and CleanRL.
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
[MIT](https://github.com/HappyFox001/CleanJepa/blob/main/LICENSE)
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/HappyFox001/CleanJepa/main/assets/logo.svg" width="108" height="108" alt="CleanJepa logo" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">CleanJepa</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Readable, hackable JEPAs and latent world models in plain PyTorch.</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://github.com/HappyFox001/CleanJepa/actions/workflows/ci.yml"><img src="https://github.com/HappyFox001/CleanJepa/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
|
|
13
|
+
<img src="https://img.shields.io/badge/python-3.10%2B-blue" alt="Python 3.10+" />
|
|
14
|
+
<img src="https://img.shields.io/badge/pytorch-2.1%2B-ee4c2c" alt="PyTorch 2.1+" />
|
|
15
|
+
<a href="https://github.com/HappyFox001/CleanJepa/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License: MIT" /></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="#quick-start">Quick start</a> ·
|
|
20
|
+
<a href="#methods">Methods</a> ·
|
|
21
|
+
<a href="#use-it-as-a-library">Library</a> ·
|
|
22
|
+
<a href="https://github.com/HappyFox001/CleanJepa/blob/main/ROADMAP.md">Roadmap</a> ·
|
|
23
|
+
<a href="https://github.com/HappyFox001/CleanJepa/blob/main/CONTRIBUTING.md">Contributing</a>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
A JEPA learns by predicting the representation of what it cannot see, instead of reconstructing
|
|
29
|
+
pixels. JEPA world models go one step further: they predict the next latent state from an action,
|
|
30
|
+
then plan by searching for actions whose predicted future matches a goal image.
|
|
31
|
+
|
|
32
|
+
CleanJepa implements this family in plain PyTorch, in the spirit of
|
|
33
|
+
[nanoGPT](https://github.com/karpathy/nanoGPT) and [CleanRL](https://github.com/vwxyzjn/cleanrl).
|
|
34
|
+
The library is about 2,000 lines with `torch` as its only dependency, and every training script is
|
|
35
|
+
a single file you can read top to bottom.
|
|
36
|
+
|
|
37
|
+
- **Plain PyTorch.** No trainer classes, config systems, or custom runtimes between you and the
|
|
38
|
+
math.
|
|
39
|
+
- **Reusable blocks.** Encoders, predictors, anti-collapse regularizers, planners, and evaluation
|
|
40
|
+
tools import on their own, with tensor shapes documented on every public function.
|
|
41
|
+
- **One file per recipe.** Each recipe keeps its training loop in view, from data to
|
|
42
|
+
`loss.backward()` and `optimizer.step()`.
|
|
43
|
+
- **Fast without magic.** Flash attention through SDPA, `torch.compile`, mixed precision, fused
|
|
44
|
+
AdamW, and multi-GPU training with `torchrun`.
|
|
45
|
+
|
|
46
|
+
## Quick start
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
git clone https://github.com/HappyFox001/CleanJepa.git && cd CleanJepa
|
|
50
|
+
pip install -e .
|
|
51
|
+
|
|
52
|
+
# Train a small LeWM-style world model on synthetic moving squares (no download needed)
|
|
53
|
+
python recipes/train_wm.py --synthetic --epochs 2
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Or skip training: download a pretrained toy world model and watch it plan. `--device auto` uses
|
|
57
|
+
CUDA, then Apple-silicon MPS, then the CPU.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install -e ".[wm]"
|
|
61
|
+
hf download CleanJepa/toy-square-wm lpwm/seed0.pt --local-dir models
|
|
62
|
+
python recipes/eval_toy.py --ckpt models/lpwm/seed0.pt --num-eval 10 --device auto
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
See what it learns: this trains a model with and without SIGReg and plots their latent spaces side
|
|
66
|
+
by side.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install -e ".[viz]"
|
|
70
|
+
python recipes/demo_manifold.py --epochs 40 --out manifold.png
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Train on real data, in the LeWM HDF5 format (for example
|
|
74
|
+
[`quentinll/lewm-pusht`](https://huggingface.co/datasets/quentinll/lewm-pusht)), then probe what the
|
|
75
|
+
latents encode:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install -e ".[wm]"
|
|
79
|
+
python recipes/train_wm.py --data pusht_expert_train.h5 --amp bf16 --save-dir runs/pusht
|
|
80
|
+
python recipes/probe_wm.py --ckpt runs/pusht/epoch_10.pt --data pusht_expert_train.h5 --targets proprio
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Compare methods on the toy world in one command: train each `--preset`, probe the latents, plan with
|
|
84
|
+
CEM, and print a table across seeds:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
python recipes/toy_benchmark.py --out runs/toy_bench --methods lewm,lpwm,vicreg --seeds 0,1,2
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Methods
|
|
91
|
+
|
|
92
|
+
<table>
|
|
93
|
+
<tr>
|
|
94
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2603.19312">LeWM</a></b><br><code>train_wm.py --preset lewm</code><br><sub><code>ViTEncoder</code> · <code>ARPredictor</code> · <code>SIGReg</code> (<a href="https://arxiv.org/abs/2511.08544">LeJEPA</a>)</sub></td>
|
|
95
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2608.22764">LpWM</a></b><br><code>train_wm.py --preset lpwm</code><br><sub><code>RDMReg</code> (<a href="https://arxiv.org/abs/2602.01456">Rectified LpJEPA</a>)</sub></td>
|
|
96
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2105.04906">VICReg</a> world model</b><br><code>train_wm.py --preset vicreg</code><br><sub><code>VICReg</code></sub></td>
|
|
97
|
+
</tr>
|
|
98
|
+
<tr>
|
|
99
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2411.04983">DINO-WM</a></b><br><code>train_wm.py --preset dino-wm</code><br><sub><code>FrozenDINOv2Encoder</code></sub></td>
|
|
100
|
+
<td width="33%" valign="top"><b>Token world model</b><br><code>train_wm.py --rep patches --head residual</code><br><sub><code>TokenPredictor</code> (joint or factorized)</sub></td>
|
|
101
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2506.09985">V-JEPA 2-AC</a></b><br><code>train_vjepa2_ac.py</code><br><sub><code>ACPredictor</code> · <code>VJEPA2ACWorldModel</code></sub></td>
|
|
102
|
+
</tr>
|
|
103
|
+
<tr>
|
|
104
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2301.08243">I-JEPA</a></b><br><code>train_ijepa.py</code><br><sub><code>ViTEncoder</code> · <code>EMAEncoder</code></sub></td>
|
|
105
|
+
<td width="33%" valign="top"><b><a href="https://arxiv.org/abs/2404.08471">V-JEPA</a></b><br><code>train_vjepa.py</code><br><sub><code>VideoViTEncoder</code> · <code>EMAEncoder</code></sub></td>
|
|
106
|
+
<td width="33%"></td>
|
|
107
|
+
</tr>
|
|
108
|
+
</table>
|
|
109
|
+
|
|
110
|
+
World models plan with `CEMSolver`, `MPPISolver`, or `GradientPlanner`. Each recipe lists its
|
|
111
|
+
differences from the official code in its docstring.
|
|
112
|
+
|
|
113
|
+
## Planning results
|
|
114
|
+
|
|
115
|
+
| Success rate | LpWM | DINO-WM | LeWM | VICReg | Random actions |
|
|
116
|
+
|---|---|---|---|---|---|
|
|
117
|
+
| Toy square world | 0.93 ± 0.06 | 0.92 ± 0.08 | 0.78 ± 0.17 | 0.76 ± 0.04 | 0.22 ± 0.15 |
|
|
118
|
+
|
|
119
|
+
Mean ± 95% CI over 3 seeds. Toy square world: `toy_benchmark.py` (30 epochs per method, CEM on 100 random
|
|
120
|
+
start/goal tasks reachable within 3 actions). Raw results, training logs, and the exact
|
|
121
|
+
command: [CleanJepa/results](https://huggingface.co/datasets/CleanJepa/results/tree/main/toy-square/2026-12-03).
|
|
122
|
+
|
|
123
|
+
## Use it as a library
|
|
124
|
+
|
|
125
|
+
The library is on PyPI and needs only PyTorch; the recipes stay in the repository.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pip install cleanjepa
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import torch
|
|
133
|
+
from cleanjepa import CEMSolver, JEPAWorldModel, SIGReg, ViTEncoder
|
|
134
|
+
|
|
135
|
+
encoder = ViTEncoder(img_size=224, patch_size=14, embed_dim=192, depth=12, heads=3)
|
|
136
|
+
model = JEPAWorldModel(encoder, action_dim=10, embed_dim=192, history_size=3)
|
|
137
|
+
sigreg = SIGReg()
|
|
138
|
+
|
|
139
|
+
pixels = torch.randn(8, 4, 3, 224, 224) # (B, T, C, H, W)
|
|
140
|
+
actions = torch.randn(8, 4, 10) # (B, T, A)
|
|
141
|
+
|
|
142
|
+
emb = model.encode_pixels(pixels) # (B, T, D)
|
|
143
|
+
pred = model.predict(emb[:, :3], model.encode_actions(actions)[:, :3])
|
|
144
|
+
loss = (pred - emb[:, 1:]).pow(2).mean() + 0.09 * sigreg(emb)
|
|
145
|
+
loss.backward()
|
|
146
|
+
|
|
147
|
+
# Plan 5 action blocks that move the last frame towards a goal image.
|
|
148
|
+
planner = CEMSolver(model, horizon=5, num_samples=300, topk=30)
|
|
149
|
+
plan = planner.plan(pixels[:, :1], pixels[:, 3:], action_dim=10) # (B, 5, A)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Repository layout
|
|
153
|
+
|
|
154
|
+
```text
|
|
155
|
+
cleanjepa/ The library: models, regularizers, planners, data, evaluation (torch only)
|
|
156
|
+
recipes/ One script per task: training, probing, planning evaluation, benchmarking
|
|
157
|
+
tests/ Fast CPU tests, one file per area
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Learn more
|
|
161
|
+
|
|
162
|
+
- [ROADMAP.md](https://github.com/HappyFox001/CleanJepa/blob/main/ROADMAP.md): goals and directions
|
|
163
|
+
- [CONTRIBUTING.md](https://github.com/HappyFox001/CleanJepa/blob/main/CONTRIBUTING.md): adding a method and reporting results
|
|
164
|
+
|
|
165
|
+
## Citation
|
|
166
|
+
|
|
167
|
+
```bibtex
|
|
168
|
+
@software{cleanjepa,
|
|
169
|
+
title = {CleanJepa: Readable JEPAs and Latent World Models in PyTorch},
|
|
170
|
+
author = {{CleanJepa contributors}},
|
|
171
|
+
url = {https://github.com/HappyFox001/CleanJepa},
|
|
172
|
+
year = {2026}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Acknowledgements
|
|
177
|
+
|
|
178
|
+
CleanJepa builds on the papers and official code of LeWM, LeJEPA, DINO-WM, LpWM, Rectified LpJEPA,
|
|
179
|
+
I-JEPA, V-JEPA, and VICReg, and on the design of nanoGPT and CleanRL.
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
[MIT](https://github.com/HappyFox001/CleanJepa/blob/main/LICENSE)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""CleanJepa: minimal, composable PyTorch implementations of JEPA and latent world models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
# Acceleration
|
|
6
|
+
from cleanjepa.accel import (
|
|
7
|
+
enable_determinism,
|
|
8
|
+
enable_fast_math,
|
|
9
|
+
gpu_normalize_pixels,
|
|
10
|
+
make_adamw,
|
|
11
|
+
maybe_compile,
|
|
12
|
+
pick_device,
|
|
13
|
+
synchronize,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
# Checkpoints
|
|
17
|
+
from cleanjepa.checkpoint import (
|
|
18
|
+
CHECKPOINT_FORMAT,
|
|
19
|
+
build_world_model,
|
|
20
|
+
export_world_model,
|
|
21
|
+
load_world_model,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Data
|
|
25
|
+
from cleanjepa.data import HDF5TrajectoryDataset, ToyTrajectoryDataset, split_episodes
|
|
26
|
+
|
|
27
|
+
# Distributed training
|
|
28
|
+
from cleanjepa.distributed import all_gather_with_grad, cleanup_distributed, init_distributed
|
|
29
|
+
|
|
30
|
+
# Evaluation
|
|
31
|
+
from cleanjepa.evaluation import (
|
|
32
|
+
effective_rank,
|
|
33
|
+
latent_diagnostics,
|
|
34
|
+
logistic_probe,
|
|
35
|
+
ridge_probe,
|
|
36
|
+
roc_auc,
|
|
37
|
+
rollout_mse,
|
|
38
|
+
surprise_scores,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Models
|
|
42
|
+
from cleanjepa.models import (
|
|
43
|
+
ACPredictor,
|
|
44
|
+
ActionEmbedder,
|
|
45
|
+
ARPredictor,
|
|
46
|
+
FrozenDINOv2Encoder,
|
|
47
|
+
JEPAWorldModel,
|
|
48
|
+
MLPProjector,
|
|
49
|
+
TokenPredictor,
|
|
50
|
+
VideoViTEncoder,
|
|
51
|
+
ViTEncoder,
|
|
52
|
+
VJEPA2ACWorldModel,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Planners
|
|
56
|
+
from cleanjepa.planners import CEMSolver, GradientPlanner, MPPISolver, build_planner
|
|
57
|
+
|
|
58
|
+
# Provenance
|
|
59
|
+
from cleanjepa.provenance import file_fingerprint, run_metadata
|
|
60
|
+
|
|
61
|
+
# Regularizers
|
|
62
|
+
from cleanjepa.regularizers import EMAEncoder, RDMReg, SIGReg, VICReg
|
|
63
|
+
|
|
64
|
+
# Result files
|
|
65
|
+
from cleanjepa.results import load_results, make_result, summarize, write_result
|
|
66
|
+
|
|
67
|
+
# Utilities
|
|
68
|
+
from cleanjepa.utils import eval_mode
|
|
69
|
+
|
|
70
|
+
__version__ = "0.1.0"
|
|
71
|
+
|
|
72
|
+
__all__ = [
|
|
73
|
+
# Acceleration
|
|
74
|
+
"enable_determinism",
|
|
75
|
+
"enable_fast_math",
|
|
76
|
+
"gpu_normalize_pixels",
|
|
77
|
+
"make_adamw",
|
|
78
|
+
"maybe_compile",
|
|
79
|
+
"pick_device",
|
|
80
|
+
"synchronize",
|
|
81
|
+
# Checkpoints
|
|
82
|
+
"CHECKPOINT_FORMAT",
|
|
83
|
+
"build_world_model",
|
|
84
|
+
"export_world_model",
|
|
85
|
+
"load_world_model",
|
|
86
|
+
# Data
|
|
87
|
+
"HDF5TrajectoryDataset",
|
|
88
|
+
"ToyTrajectoryDataset",
|
|
89
|
+
"split_episodes",
|
|
90
|
+
# Distributed training
|
|
91
|
+
"all_gather_with_grad",
|
|
92
|
+
"cleanup_distributed",
|
|
93
|
+
"init_distributed",
|
|
94
|
+
# Evaluation
|
|
95
|
+
"effective_rank",
|
|
96
|
+
"latent_diagnostics",
|
|
97
|
+
"logistic_probe",
|
|
98
|
+
"ridge_probe",
|
|
99
|
+
"roc_auc",
|
|
100
|
+
"rollout_mse",
|
|
101
|
+
"surprise_scores",
|
|
102
|
+
# Models
|
|
103
|
+
"ACPredictor",
|
|
104
|
+
"ActionEmbedder",
|
|
105
|
+
"ARPredictor",
|
|
106
|
+
"FrozenDINOv2Encoder",
|
|
107
|
+
"JEPAWorldModel",
|
|
108
|
+
"MLPProjector",
|
|
109
|
+
"TokenPredictor",
|
|
110
|
+
"VideoViTEncoder",
|
|
111
|
+
"ViTEncoder",
|
|
112
|
+
"VJEPA2ACWorldModel",
|
|
113
|
+
# Planners
|
|
114
|
+
"CEMSolver",
|
|
115
|
+
"GradientPlanner",
|
|
116
|
+
"MPPISolver",
|
|
117
|
+
"build_planner",
|
|
118
|
+
# Provenance
|
|
119
|
+
"file_fingerprint",
|
|
120
|
+
"run_metadata",
|
|
121
|
+
# Regularizers
|
|
122
|
+
"EMAEncoder",
|
|
123
|
+
"RDMReg",
|
|
124
|
+
"SIGReg",
|
|
125
|
+
"VICReg",
|
|
126
|
+
# Result files
|
|
127
|
+
"load_results",
|
|
128
|
+
"make_result",
|
|
129
|
+
"summarize",
|
|
130
|
+
"write_result",
|
|
131
|
+
# Utilities
|
|
132
|
+
"eval_mode",
|
|
133
|
+
]
|