EpiJEPA-LeWM: best checkpoint per environment (TwoRoom, Push-T, Cube, Reacher)
Browse files- README.md +55 -0
- cube/config.json +49 -0
- cube/weights.pt +3 -0
- module.py +306 -0
- pusht/config.json +49 -0
- pusht/weights.pt +3 -0
- reacher/config.json +49 -0
- reacher/weights.pt +3 -0
- tworoom/config.json +49 -0
- tworoom/weights.pt +3 -0
README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- world-model
|
| 5 |
+
- jepa
|
| 6 |
+
- planning
|
| 7 |
+
- robotics
|
| 8 |
+
- lewm
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# EpiJEPA-LeWM: LeWorldModel trained with epiplexity instead of SIGReg
|
| 12 |
+
|
| 13 |
+
These are the best checkpoints from replacing [LeWorldModel](https://github.com/lucas-maes/le-wm)'s SIGReg
|
| 14 |
+
anti-collapse term with the epiplexity score from EpiJEPA. The code, the full analysis and our replication of LeWM's
|
| 15 |
+
SIGReg recipe are in [the-puzzler/epijepa](https://github.com/the-puzzler/epijepa) (`worldmodel/`).
|
| 16 |
+
|
| 17 |
+
There is one folder per environment, laid out like LeWM's own releases:
|
| 18 |
+
|
| 19 |
+
| Folder | Environment | λ | Steps | Seed | paper-50 | n=200 | n=500 | Released LeWM (paper-50 / n=200 / n=500) |
|
| 20 |
+
|---|---|---|---|---|---|---|---|---|
|
| 21 |
+
| `tworoom/` | TwoRoom | 0.03 | 30k | 1 | 100 | 100 | 100.0 | 86 / 85.0 / 82.8 |
|
| 22 |
+
| `pusht/` | Push-T | 0.1 | 60k | 3 | 90 | 90.0 | 89.0 | 96 / 83.5 / 84.6 |
|
| 23 |
+
| `cube/` | Cube (OGBench, single) | 0.03 | 60k | 3 | 74 | 75.5 | 72.4 | 68 / 63.0 / 66.0 |
|
| 24 |
+
| `reacher/` | Reacher (DMC) | 0.3 | 200k | 1 | 76 | 72.0 | 76.6 | 52 / 62.0 / 60.8 |
|
| 25 |
+
|
| 26 |
+
These are planning success rates (%) with LeWM's CEM planner and evaluation (`eval.py`). The 3-seed means of the
|
| 27 |
+
same recipe are TwoRoom 99.9, Push-T 88.5, Cube 71.5 and Reacher 73.5 on n=500. Each folder holds the seed with the
|
| 28 |
+
best n=500 score; every seed's number is in the repo's `worldmodel/analysis/scores/all_scores.csv`.
|
| 29 |
+
|
| 30 |
+
## Model
|
| 31 |
+
|
| 32 |
+
The architecture is LeWM's released one: a ViT-tiny encoder (patch 14, 224 px), an AdaLN transformer predictor with
|
| 33 |
+
history 3, and MLP projectors, with 18M parameters. The only change is a non-affine BatchNorm on the projector output
|
| 34 |
+
(`module.ProjectorBN`, included here). It is trained with
|
| 35 |
+
|
| 36 |
+
loss = ||pred(z_t, a_t) - z_t+1||^2 - lambda * S(z) / S0
|
| 37 |
+
|
| 38 |
+
where S is the epiplexity of the embeddings with respect to a frozen random CNN reservoir of the same frames.
|
| 39 |
+
|
| 40 |
+
## Usage
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
# with the repo's worldmodel/ folder on PYTHONPATH (config.json refers to module.ProjectorBN)
|
| 44 |
+
hf download basilboy/epijepa-lewm --local-dir $STABLEWM_HOME/checkpoints/epijepa_lewm
|
| 45 |
+
cd epijepa/worldmodel
|
| 46 |
+
python eval.py --config-name=pusht.yaml policy=epijepa_lewm/pusht # LeWM's eval: paper-50
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
import stable_worldmodel as swm
|
| 51 |
+
model = swm.wm.utils.load_pretrained("epijepa_lewm/pusht") # resolved under $STABLEWM_HOME/checkpoints
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
The weights are plain state dicts (`weights.pt`, fp32, about 72 MB), saved with stable-worldmodel's `save_pretrained`
|
| 55 |
+
(transformers-5 ViT key layout).
|
cube/config.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_target_": "stable_worldmodel.wm.lewm.LeWM",
|
| 3 |
+
"encoder": {
|
| 4 |
+
"_target_": "stable_pretraining.backbone.utils.vit_hf",
|
| 5 |
+
"size": "tiny",
|
| 6 |
+
"patch_size": 14,
|
| 7 |
+
"image_size": 224,
|
| 8 |
+
"pretrained": false,
|
| 9 |
+
"use_mask_token": false
|
| 10 |
+
},
|
| 11 |
+
"predictor": {
|
| 12 |
+
"_target_": "stable_worldmodel.wm.lewm.module.Predictor",
|
| 13 |
+
"num_frames": 3,
|
| 14 |
+
"input_dim": 192,
|
| 15 |
+
"hidden_dim": 192,
|
| 16 |
+
"output_dim": 192,
|
| 17 |
+
"depth": 6,
|
| 18 |
+
"heads": 16,
|
| 19 |
+
"mlp_dim": 2048,
|
| 20 |
+
"dim_head": 64,
|
| 21 |
+
"dropout": 0.1,
|
| 22 |
+
"emb_dropout": 0.0
|
| 23 |
+
},
|
| 24 |
+
"action_encoder": {
|
| 25 |
+
"_target_": "stable_worldmodel.wm.lewm.module.Embedder",
|
| 26 |
+
"input_dim": 25,
|
| 27 |
+
"emb_dim": 192
|
| 28 |
+
},
|
| 29 |
+
"projector": {
|
| 30 |
+
"_target_": "module.ProjectorBN",
|
| 31 |
+
"input_dim": 192,
|
| 32 |
+
"output_dim": 192,
|
| 33 |
+
"hidden_dim": 2048,
|
| 34 |
+
"norm_fn": {
|
| 35 |
+
"_target_": "torch.nn.BatchNorm1d",
|
| 36 |
+
"_partial_": true
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"pred_proj": {
|
| 40 |
+
"_target_": "stable_worldmodel.wm.lewm.module.MLP",
|
| 41 |
+
"input_dim": 192,
|
| 42 |
+
"output_dim": 192,
|
| 43 |
+
"hidden_dim": 2048,
|
| 44 |
+
"norm_fn": {
|
| 45 |
+
"_target_": "torch.nn.BatchNorm1d",
|
| 46 |
+
"_partial_": true
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
}
|
cube/weights.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:47085d56d06202b43e36a6ec7165c0efc83dd5d136de7a63106aac47a1c45db7
|
| 3 |
+
size 72294347
|
module.py
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from torch import nn
|
| 3 |
+
import torch.nn.functional as F
|
| 4 |
+
from einops import rearrange
|
| 5 |
+
|
| 6 |
+
def modulate(x, shift, scale):
|
| 7 |
+
"""AdaLN-zero modulation"""
|
| 8 |
+
return x * (1 + scale) + shift
|
| 9 |
+
|
| 10 |
+
class SIGReg(torch.nn.Module):
|
| 11 |
+
"""Sketch Isotropic Gaussian Regularizer (single-GPU!)"""
|
| 12 |
+
|
| 13 |
+
def __init__(self, knots=17, num_proj=1024):
|
| 14 |
+
super().__init__()
|
| 15 |
+
self.num_proj = num_proj
|
| 16 |
+
t = torch.linspace(0, 3, knots, dtype=torch.float32)
|
| 17 |
+
dt = 3 / (knots - 1)
|
| 18 |
+
weights = torch.full((knots,), 2 * dt, dtype=torch.float32)
|
| 19 |
+
weights[[0, -1]] = dt
|
| 20 |
+
window = torch.exp(-t.square() / 2.0)
|
| 21 |
+
self.register_buffer("t", t)
|
| 22 |
+
self.register_buffer("phi", window)
|
| 23 |
+
self.register_buffer("weights", weights * window)
|
| 24 |
+
|
| 25 |
+
def forward(self, proj):
|
| 26 |
+
"""
|
| 27 |
+
proj: (T, B, D)
|
| 28 |
+
"""
|
| 29 |
+
# sample random projections
|
| 30 |
+
A = torch.randn(proj.size(-1), self.num_proj, device=proj.device)
|
| 31 |
+
A = A.div_(A.norm(p=2, dim=0))
|
| 32 |
+
# compute the epps-pulley statistic
|
| 33 |
+
x_t = (proj @ A).unsqueeze(-1) * self.t
|
| 34 |
+
err = (x_t.cos().mean(-3) - self.phi).square() + x_t.sin().mean(-3).square()
|
| 35 |
+
statistic = (err @ self.weights) * proj.size(-2)
|
| 36 |
+
return statistic.mean() # average over projections and time
|
| 37 |
+
|
| 38 |
+
class FeedForward(nn.Module):
|
| 39 |
+
"""FeedForward network used in Transformers"""
|
| 40 |
+
|
| 41 |
+
def __init__(self, dim, hidden_dim, dropout=0.0):
|
| 42 |
+
super().__init__()
|
| 43 |
+
self.net = nn.Sequential(
|
| 44 |
+
nn.LayerNorm(dim),
|
| 45 |
+
nn.Linear(dim, hidden_dim),
|
| 46 |
+
nn.GELU(),
|
| 47 |
+
nn.Dropout(dropout),
|
| 48 |
+
nn.Linear(hidden_dim, dim),
|
| 49 |
+
nn.Dropout(dropout),
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
def forward(self, x):
|
| 53 |
+
return self.net(x)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class Attention(nn.Module):
|
| 57 |
+
"""Scaled dot-product attention with causal masking"""
|
| 58 |
+
|
| 59 |
+
def __init__(self, dim, heads=8, dim_head=64, dropout=0.0):
|
| 60 |
+
super().__init__()
|
| 61 |
+
inner_dim = dim_head * heads
|
| 62 |
+
project_out = not (heads == 1 and dim_head == dim)
|
| 63 |
+
self.heads = heads
|
| 64 |
+
self.scale = dim_head**-0.5
|
| 65 |
+
self.dropout = dropout
|
| 66 |
+
self.norm = nn.LayerNorm(dim)
|
| 67 |
+
self.attend = nn.Softmax(dim=-1)
|
| 68 |
+
self.to_qkv = nn.Linear(dim, inner_dim * 3, bias=False)
|
| 69 |
+
self.to_out = (
|
| 70 |
+
nn.Sequential(nn.Linear(inner_dim, dim), nn.Dropout(dropout))
|
| 71 |
+
if project_out
|
| 72 |
+
else nn.Identity()
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
def forward(self, x, causal=True):
|
| 76 |
+
"""
|
| 77 |
+
x : (B, T, D)
|
| 78 |
+
"""
|
| 79 |
+
x = self.norm(x)
|
| 80 |
+
drop = self.dropout if self.training else 0.0
|
| 81 |
+
qkv = self.to_qkv(x).chunk(3, dim=-1) # q, k, v: (B, heads, T, dim_head)
|
| 82 |
+
q, k, v = (rearrange(t, "b t (h d) -> b h t d", h=self.heads) for t in qkv)
|
| 83 |
+
out = F.scaled_dot_product_attention(q, k, v, dropout_p=drop, is_causal=causal)
|
| 84 |
+
out = rearrange(out, "b h t d -> b t (h d)")
|
| 85 |
+
return self.to_out(out)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class ConditionalBlock(nn.Module):
|
| 89 |
+
"""Transformer block with AdaLN-zero conditioning"""
|
| 90 |
+
|
| 91 |
+
def __init__(self, dim, heads, dim_head, mlp_dim, dropout=0.0):
|
| 92 |
+
super().__init__()
|
| 93 |
+
|
| 94 |
+
self.attn = Attention(dim, heads=heads, dim_head=dim_head, dropout=dropout)
|
| 95 |
+
self.mlp = FeedForward(dim, mlp_dim, dropout=dropout)
|
| 96 |
+
self.norm1 = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-6)
|
| 97 |
+
self.norm2 = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-6)
|
| 98 |
+
self.adaLN_modulation = nn.Sequential(
|
| 99 |
+
nn.SiLU(), nn.Linear(dim, 6 * dim, bias=True)
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
nn.init.constant_(self.adaLN_modulation[-1].weight, 0)
|
| 103 |
+
nn.init.constant_(self.adaLN_modulation[-1].bias, 0)
|
| 104 |
+
|
| 105 |
+
def forward(self, x, c):
|
| 106 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = (
|
| 107 |
+
self.adaLN_modulation(c).chunk(6, dim=-1)
|
| 108 |
+
)
|
| 109 |
+
x = x + gate_msa * self.attn(modulate(self.norm1(x), shift_msa, scale_msa))
|
| 110 |
+
x = x + gate_mlp * self.mlp(modulate(self.norm2(x), shift_mlp, scale_mlp))
|
| 111 |
+
return x
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
class Block(nn.Module):
|
| 115 |
+
"""Standard Transformer block"""
|
| 116 |
+
|
| 117 |
+
def __init__(self, dim, heads, dim_head, mlp_dim, dropout=0.0):
|
| 118 |
+
super().__init__()
|
| 119 |
+
|
| 120 |
+
self.attn = Attention(dim, heads=heads, dim_head=dim_head, dropout=dropout)
|
| 121 |
+
self.mlp = FeedForward(dim, mlp_dim, dropout=dropout)
|
| 122 |
+
self.norm1 = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-6)
|
| 123 |
+
self.norm2 = nn.LayerNorm(dim, elementwise_affine=False, eps=1e-6)
|
| 124 |
+
|
| 125 |
+
def forward(self, x):
|
| 126 |
+
x = x + self.attn(self.norm1(x))
|
| 127 |
+
x = x + self.mlp(self.norm2(x))
|
| 128 |
+
return x
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
class Transformer(nn.Module):
|
| 132 |
+
"""Standard Transformer with support for AdaLN-zero blocks"""
|
| 133 |
+
|
| 134 |
+
def __init__(
|
| 135 |
+
self,
|
| 136 |
+
input_dim,
|
| 137 |
+
hidden_dim,
|
| 138 |
+
output_dim,
|
| 139 |
+
depth,
|
| 140 |
+
heads,
|
| 141 |
+
dim_head,
|
| 142 |
+
mlp_dim,
|
| 143 |
+
dropout=0.0,
|
| 144 |
+
block_class=Block,
|
| 145 |
+
):
|
| 146 |
+
super().__init__()
|
| 147 |
+
self.norm = nn.LayerNorm(hidden_dim)
|
| 148 |
+
self.layers = nn.ModuleList([])
|
| 149 |
+
|
| 150 |
+
self.input_proj = (
|
| 151 |
+
nn.Linear(input_dim, hidden_dim)
|
| 152 |
+
if input_dim != hidden_dim
|
| 153 |
+
else nn.Identity()
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
self.cond_proj = (
|
| 157 |
+
nn.Linear(input_dim, hidden_dim)
|
| 158 |
+
if input_dim != hidden_dim
|
| 159 |
+
else nn.Identity()
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
self.output_proj = (
|
| 163 |
+
nn.Linear(hidden_dim, output_dim)
|
| 164 |
+
if hidden_dim != output_dim
|
| 165 |
+
else nn.Identity()
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
for _ in range(depth):
|
| 169 |
+
self.layers.append(
|
| 170 |
+
block_class(hidden_dim, heads, dim_head, mlp_dim, dropout)
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
def forward(self, x, c=None):
|
| 174 |
+
|
| 175 |
+
if hasattr(self, "input_proj"):
|
| 176 |
+
x = self.input_proj(x)
|
| 177 |
+
|
| 178 |
+
if c is not None and hasattr(self, "cond_proj"):
|
| 179 |
+
c = self.cond_proj(c)
|
| 180 |
+
|
| 181 |
+
for block in self.layers:
|
| 182 |
+
x = block(x) if isinstance(block, Block) else block(x, c)
|
| 183 |
+
x = self.norm(x)
|
| 184 |
+
|
| 185 |
+
if hasattr(self, "output_proj"):
|
| 186 |
+
x = self.output_proj(x)
|
| 187 |
+
return x
|
| 188 |
+
|
| 189 |
+
class Embedder(nn.Module):
|
| 190 |
+
def __init__(
|
| 191 |
+
self,
|
| 192 |
+
input_dim=10,
|
| 193 |
+
smoothed_dim=10,
|
| 194 |
+
emb_dim=10,
|
| 195 |
+
mlp_scale=4,
|
| 196 |
+
):
|
| 197 |
+
super().__init__()
|
| 198 |
+
self.patch_embed = nn.Conv1d(input_dim, smoothed_dim, kernel_size=1, stride=1)
|
| 199 |
+
self.embed = nn.Sequential(
|
| 200 |
+
nn.Linear(smoothed_dim, mlp_scale * emb_dim),
|
| 201 |
+
nn.SiLU(),
|
| 202 |
+
nn.Linear(mlp_scale * emb_dim, emb_dim),
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
def forward(self, x):
|
| 206 |
+
"""
|
| 207 |
+
x: (B, T, D)
|
| 208 |
+
"""
|
| 209 |
+
x = x.float()
|
| 210 |
+
x = x.permute(0, 2, 1)
|
| 211 |
+
x = self.patch_embed(x)
|
| 212 |
+
x = x.permute(0, 2, 1)
|
| 213 |
+
x = self.embed(x)
|
| 214 |
+
return x
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
class MLP(nn.Module):
|
| 218 |
+
"""Simple MLP with optional normalization and activation"""
|
| 219 |
+
|
| 220 |
+
def __init__(
|
| 221 |
+
self,
|
| 222 |
+
input_dim,
|
| 223 |
+
hidden_dim,
|
| 224 |
+
output_dim=None,
|
| 225 |
+
norm_fn=nn.LayerNorm,
|
| 226 |
+
act_fn=nn.GELU,
|
| 227 |
+
):
|
| 228 |
+
super().__init__()
|
| 229 |
+
norm_fn = norm_fn(hidden_dim) if norm_fn is not None else nn.Identity()
|
| 230 |
+
self.net = nn.Sequential(
|
| 231 |
+
nn.Linear(input_dim, hidden_dim),
|
| 232 |
+
norm_fn,
|
| 233 |
+
act_fn(),
|
| 234 |
+
nn.Linear(hidden_dim, output_dim or input_dim),
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
def forward(self, x):
|
| 238 |
+
"""
|
| 239 |
+
x: (B*T, D)
|
| 240 |
+
"""
|
| 241 |
+
return self.net(x)
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
class ARPredictor(nn.Module):
|
| 245 |
+
"""Autoregressive predictor for next-step embedding prediction."""
|
| 246 |
+
|
| 247 |
+
def __init__(
|
| 248 |
+
self,
|
| 249 |
+
*,
|
| 250 |
+
num_frames,
|
| 251 |
+
depth,
|
| 252 |
+
heads,
|
| 253 |
+
mlp_dim,
|
| 254 |
+
input_dim,
|
| 255 |
+
hidden_dim,
|
| 256 |
+
output_dim=None,
|
| 257 |
+
dim_head=64,
|
| 258 |
+
dropout=0.0,
|
| 259 |
+
emb_dropout=0.0,
|
| 260 |
+
):
|
| 261 |
+
super().__init__()
|
| 262 |
+
self.pos_embedding = nn.Parameter(torch.randn(1, num_frames, input_dim))
|
| 263 |
+
self.dropout = nn.Dropout(emb_dropout)
|
| 264 |
+
self.transformer = Transformer(
|
| 265 |
+
input_dim,
|
| 266 |
+
hidden_dim,
|
| 267 |
+
output_dim or input_dim,
|
| 268 |
+
depth,
|
| 269 |
+
heads,
|
| 270 |
+
dim_head,
|
| 271 |
+
mlp_dim,
|
| 272 |
+
dropout,
|
| 273 |
+
block_class=ConditionalBlock,
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
def forward(self, x, c):
|
| 277 |
+
"""
|
| 278 |
+
x: (B, T, d)
|
| 279 |
+
c: (B, T, act_dim)
|
| 280 |
+
"""
|
| 281 |
+
T = x.size(1)
|
| 282 |
+
x = x + self.pos_embedding[:, :T]
|
| 283 |
+
x = self.dropout(x)
|
| 284 |
+
x = self.transformer(x, c)
|
| 285 |
+
return x
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
# ---------------------------------------------------------------------------
|
| 289 |
+
# Added for EpiJEPA (not part of LeWM): the only architectural change of the Epi arm.
|
| 290 |
+
# ---------------------------------------------------------------------------
|
| 291 |
+
class ProjectorBN(nn.Module):
|
| 292 |
+
"""LeWM projector followed by a non-affine BatchNorm on the output (EpiJEPA arm).
|
| 293 |
+
|
| 294 |
+
The epiplexity score grows without bound with the embedding scale, so the scale is pinned
|
| 295 |
+
here, exactly as the CIFAR/Imagenette EpiJEPA encoders do. SIGReg needs no such layer: its
|
| 296 |
+
N(0, I) target already fixes the scale."""
|
| 297 |
+
|
| 298 |
+
def __init__(self, input_dim, hidden_dim, output_dim=None, norm_fn=nn.LayerNorm, act_fn=nn.GELU):
|
| 299 |
+
super().__init__()
|
| 300 |
+
# same MLP class as the released checkpoints, so the only architectural difference is out_norm
|
| 301 |
+
from stable_worldmodel.wm.lewm.module import MLP as LibMLP
|
| 302 |
+
self.mlp = LibMLP(input_dim, hidden_dim, output_dim, norm_fn=norm_fn, act_fn=act_fn)
|
| 303 |
+
self.out_norm = nn.BatchNorm1d(output_dim or input_dim, affine=False)
|
| 304 |
+
|
| 305 |
+
def forward(self, x):
|
| 306 |
+
return self.out_norm(self.mlp(x))
|
pusht/config.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_target_": "stable_worldmodel.wm.lewm.LeWM",
|
| 3 |
+
"encoder": {
|
| 4 |
+
"_target_": "stable_pretraining.backbone.utils.vit_hf",
|
| 5 |
+
"size": "tiny",
|
| 6 |
+
"patch_size": 14,
|
| 7 |
+
"image_size": 224,
|
| 8 |
+
"pretrained": false,
|
| 9 |
+
"use_mask_token": false
|
| 10 |
+
},
|
| 11 |
+
"predictor": {
|
| 12 |
+
"_target_": "stable_worldmodel.wm.lewm.module.Predictor",
|
| 13 |
+
"num_frames": 3,
|
| 14 |
+
"input_dim": 192,
|
| 15 |
+
"hidden_dim": 192,
|
| 16 |
+
"output_dim": 192,
|
| 17 |
+
"depth": 6,
|
| 18 |
+
"heads": 16,
|
| 19 |
+
"mlp_dim": 2048,
|
| 20 |
+
"dim_head": 64,
|
| 21 |
+
"dropout": 0.1,
|
| 22 |
+
"emb_dropout": 0.0
|
| 23 |
+
},
|
| 24 |
+
"action_encoder": {
|
| 25 |
+
"_target_": "stable_worldmodel.wm.lewm.module.Embedder",
|
| 26 |
+
"input_dim": 10,
|
| 27 |
+
"emb_dim": 192
|
| 28 |
+
},
|
| 29 |
+
"projector": {
|
| 30 |
+
"_target_": "module.ProjectorBN",
|
| 31 |
+
"input_dim": 192,
|
| 32 |
+
"output_dim": 192,
|
| 33 |
+
"hidden_dim": 2048,
|
| 34 |
+
"norm_fn": {
|
| 35 |
+
"_target_": "torch.nn.BatchNorm1d",
|
| 36 |
+
"_partial_": true
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"pred_proj": {
|
| 40 |
+
"_target_": "stable_worldmodel.wm.lewm.module.MLP",
|
| 41 |
+
"input_dim": 192,
|
| 42 |
+
"output_dim": 192,
|
| 43 |
+
"hidden_dim": 2048,
|
| 44 |
+
"norm_fn": {
|
| 45 |
+
"_target_": "torch.nn.BatchNorm1d",
|
| 46 |
+
"_partial_": true
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
}
|
pusht/weights.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bf57e9b51913e99d2bff4ad2ea60ec990ff19132afd4dbf3b423a17003d545ea
|
| 3 |
+
size 72293771
|
reacher/config.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_target_": "stable_worldmodel.wm.lewm.LeWM",
|
| 3 |
+
"encoder": {
|
| 4 |
+
"_target_": "stable_pretraining.backbone.utils.vit_hf",
|
| 5 |
+
"size": "tiny",
|
| 6 |
+
"patch_size": 14,
|
| 7 |
+
"image_size": 224,
|
| 8 |
+
"pretrained": false,
|
| 9 |
+
"use_mask_token": false
|
| 10 |
+
},
|
| 11 |
+
"predictor": {
|
| 12 |
+
"_target_": "stable_worldmodel.wm.lewm.module.Predictor",
|
| 13 |
+
"num_frames": 3,
|
| 14 |
+
"input_dim": 192,
|
| 15 |
+
"hidden_dim": 192,
|
| 16 |
+
"output_dim": 192,
|
| 17 |
+
"depth": 6,
|
| 18 |
+
"heads": 16,
|
| 19 |
+
"mlp_dim": 2048,
|
| 20 |
+
"dim_head": 64,
|
| 21 |
+
"dropout": 0.1,
|
| 22 |
+
"emb_dropout": 0.0
|
| 23 |
+
},
|
| 24 |
+
"action_encoder": {
|
| 25 |
+
"_target_": "stable_worldmodel.wm.lewm.module.Embedder",
|
| 26 |
+
"input_dim": 10,
|
| 27 |
+
"emb_dim": 192
|
| 28 |
+
},
|
| 29 |
+
"projector": {
|
| 30 |
+
"_target_": "module.ProjectorBN",
|
| 31 |
+
"input_dim": 192,
|
| 32 |
+
"output_dim": 192,
|
| 33 |
+
"hidden_dim": 2048,
|
| 34 |
+
"norm_fn": {
|
| 35 |
+
"_target_": "torch.nn.BatchNorm1d",
|
| 36 |
+
"_partial_": true
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"pred_proj": {
|
| 40 |
+
"_target_": "stable_worldmodel.wm.lewm.module.MLP",
|
| 41 |
+
"input_dim": 192,
|
| 42 |
+
"output_dim": 192,
|
| 43 |
+
"hidden_dim": 2048,
|
| 44 |
+
"norm_fn": {
|
| 45 |
+
"_target_": "torch.nn.BatchNorm1d",
|
| 46 |
+
"_partial_": true
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
}
|
reacher/weights.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9dbd72d4cda8b59cf378198d04723a6e1b142913e2b7f1a2001f29eba96184eb
|
| 3 |
+
size 72294083
|
tworoom/config.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_target_": "stable_worldmodel.wm.lewm.LeWM",
|
| 3 |
+
"encoder": {
|
| 4 |
+
"_target_": "stable_pretraining.backbone.utils.vit_hf",
|
| 5 |
+
"size": "tiny",
|
| 6 |
+
"patch_size": 14,
|
| 7 |
+
"image_size": 224,
|
| 8 |
+
"pretrained": false,
|
| 9 |
+
"use_mask_token": false
|
| 10 |
+
},
|
| 11 |
+
"predictor": {
|
| 12 |
+
"_target_": "stable_worldmodel.wm.lewm.module.Predictor",
|
| 13 |
+
"num_frames": 3,
|
| 14 |
+
"input_dim": 192,
|
| 15 |
+
"hidden_dim": 192,
|
| 16 |
+
"output_dim": 192,
|
| 17 |
+
"depth": 6,
|
| 18 |
+
"heads": 16,
|
| 19 |
+
"mlp_dim": 2048,
|
| 20 |
+
"dim_head": 64,
|
| 21 |
+
"dropout": 0.1,
|
| 22 |
+
"emb_dropout": 0.0
|
| 23 |
+
},
|
| 24 |
+
"action_encoder": {
|
| 25 |
+
"_target_": "stable_worldmodel.wm.lewm.module.Embedder",
|
| 26 |
+
"input_dim": 10,
|
| 27 |
+
"emb_dim": 192
|
| 28 |
+
},
|
| 29 |
+
"projector": {
|
| 30 |
+
"_target_": "module.ProjectorBN",
|
| 31 |
+
"input_dim": 192,
|
| 32 |
+
"output_dim": 192,
|
| 33 |
+
"hidden_dim": 2048,
|
| 34 |
+
"norm_fn": {
|
| 35 |
+
"_target_": "torch.nn.BatchNorm1d",
|
| 36 |
+
"_partial_": true
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"pred_proj": {
|
| 40 |
+
"_target_": "stable_worldmodel.wm.lewm.module.MLP",
|
| 41 |
+
"input_dim": 192,
|
| 42 |
+
"output_dim": 192,
|
| 43 |
+
"hidden_dim": 2048,
|
| 44 |
+
"norm_fn": {
|
| 45 |
+
"_target_": "torch.nn.BatchNorm1d",
|
| 46 |
+
"_partial_": true
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
}
|
tworoom/weights.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4b6a1bf510087aeada1d66c9bee21785b8eb3dae1596720dbc54974e7787980c
|
| 3 |
+
size 72293771
|