Robot learning · world models

Inside Cosmo: one small network that imagines the future and acts on it

How a 51M-parameter world-action model is put together and trained: from compressing camera frames, through a single diffusion transformer that generates frames, robot states and actions at once, to the loop that runs it on a real arm.

Code, results and the full experiment log: github.com/Mandred009/Cosmo_Small_WAM

The final model stacking cubes on a real SO-101 arm with only a wrist camera: the live view (left) next to the frames the model imagines (right).
Left: an episode imagined by the model; right: the simulator replaying the same actions
The model imagining a whole episode (left) while a simulator replays the actions it chose (right).

A robot policy answers one question: what should I do now? A world model answers another: what will I see if I do this? A world-action model (WAM) answers both with one network. That forces it to learn how the scene moves, not only which action usually comes next, and it makes the model inspectable: you can watch what it expects to happen. Here is how Cosmo does it, piece by piece.

1Seeing in latents

Diffusion on raw 256×256 images would be far too expensive for one GPU, so a convolutional VAE first compresses every camera frame into a small latent grid. Everything the WAM sees and generates lives in this space, and the VAE decoder turns generated latents back into images.

camera frame256 × 256 × 3 encoder4 levels, ÷2 each latent16 × 16 × 32 decodermirror image reconstruction256 × 256 × 3 Trained first and then frozen. Loss: pixel MSE + a tiny KL term (β = 10⁻⁶), so the latent keeps detail. The WAM always uses the latent mean, which is deterministic and noise-free.
A 48× compression per frame (256×256×3 values into 16×16×32). The WAM never touches pixels.

One lesson from tuning it: with a standard KL weight the latents collapsed and carried almost no information. Weighting KL a thousand times less kept them informative, and using the mean rather than a random sample removed noise the WAM would otherwise have to model.

2Everything becomes one token sequence

The WAM is a transformer, so frames, actions and robot states all have to become tokens. The trick is to give the network the noisy versions of what it must generate, next to the clean context it can rely on.

inputstoken sequence last 8 framesclean latents (context) history encoder1×1 convs, 8 → 1 map next 8 framesnoisy latents (to generate) stack as channels,patchify 2 × 2+ position encoding next 8 actionsnoisy (to generate) linear+ learned position per step next 8 robot statesnoisy (to generate) linear+ learned position per step 64 frametokens 8 action tokens 8 state tokens current frame256 × 256 camera image DINOv2-smallfrozen, pretrained pool to 8 × 8, linearadded to each frame token 80 tokens → 10 transformer blocks
Every frame token sees the same image patch across all 8 future frames and the compressed history, stacked as channels.

Why DINOv2 too? The VAE latents are trained to reconstruct pixels, not to say where the cube is, and on the robot the policy turned out to be very sensitive to the setup. Features from DINOv2, a frozen vision model pretrained on a huge image collection, describe objects and their positions robustly. Added to the frame tokens (with a projection that starts at zero, so fine-tuning starts from the pretrained model), they made the policy work in conditions where it had failed.

Stacking the 8 future frames as channels of one token, instead of giving each frame its own tokens, keeps the sequence at 80 tokens and lets the model generate a whole chunk of the future in one pass. After the last block, small heads map each token group back: frame tokens to latent patches, action tokens to joint commands, state tokens to joint positions.

3Inside a block: conditioning with adaLN-Zero

Information that is not being generated, such as the instruction, the current joint state, the last actions and the noise levels, enters through conditioning rather than as tokens. It is all summed into one vector that steers every block, the design used by the Diffusion Transformer (DiT).

tokens in LayerNorm × (1+γ₁) + β₁scale, shift self-attention × α₁gate + residual LayerNorm × (1+γ₂) + β₂scale, shift MLP (4× wide) × α₂gate + tokens out conditioning vector → γ, β, α (all blocks, both rows) frames/statesnoise level actionnoise level instruction currentjoint state last 7actions historynoise level embed each, sum
The gates α start at zero, so every block starts as the identity and training opens it up gradually (the "Zero" in adaLN-Zero).

"Adaptive layer norm" means the conditioning decides how each layer's activations are scaled and shifted, for every token at once. It is a cheap and very stable way to inject global information. (I also tried feeding the state and past actions as tokens instead. Losses improved but the policy got worse: the model started copying its own recent motion instead of looking at the scene.)

4One network, three jobs: two noise levels

Diffusion trains a network to remove noise of a given strength. Cosmo uses two independent noise levels: one for the frames and states, one for the actions (the idea comes from Unified World Models). Which job the network does depends only on where in this square you sample.

action noise level: clean → pure noise frame / state noise: clean → pure noise rest of training:random pairs World model (left edge: actions clean) "If I do these actions, what will I see?"→ generates the next frames and states Policy (top edge: frames pure noise) "What should I do?"→ generates the actions Joint (diagonal: one shared level) Imagine and act together→ frames, states and actions at once (used on the robot)
In training, a quarter of the samples sit on the left edge, a quarter on the top edge, and the rest anywhere in the square.

Because every combination is seen in training, the same weights can be asked a different question at inference time just by choosing the two noise levels. Nothing about the architecture changes between "world model", "policy" and "both".

5One training step

demonstrations: frames, joints, actions VAE-encode every frame once (cached) cut a window: 8 history frames +targets: next 8 frames, 8 states, 8 actions draw two noise levels (25% world, 25% policy) noise the targets; target = velocity vv = √ᾱ·noise − √(1−ᾱ)·clean (v-prediction) WAM predicts v for frames, states and actions MSE per modality, masked past episode end AdamW step + EMA copy for sampling corrupt the history drop whole frames (20%)add noise of a random level,and tell the model the level standardize withtraining statistics
The whole objective is one sum of three masked MSE losses; everything else is about what goes in.

The design choices that made the difference, each found the hard way:

6The control loop on a real arm

On the SO-101 arm, with only a wrist camera, the model runs in joint mode: every plan contains 8 actions and the 8 frames it expects to see, which are shown next to the live camera.

wrist camera + jointsevery 1/15 s last 8 frames (VAE)+ DINOv2, state, past actions sample a plan10 DDIM steps, joint mode 8 actionsjoint targets relative to state keep the first 4the rest is replanned send 4 actionstarget = current state + delta 8 imagined framesVAE decode screen + videolive view | dream repeat
Actions are relative to the joint state measured right before each is sent, exactly as in training.
Top: real wrist-camera frames; bottom: the model's imagined frames over 30 steps
Top: the real wrist camera at steps 1, 5, 10, 20 and 30 of a held-out demonstration. Bottom: what the model imagines on its own predictions. Layout and objects hold; fine detail blurs with the horizon.

The final model stacks the cube in about half of the attempts. Replanning every 4 actions keeps the arm reacting to fresh frames. Averaging the overlapping parts of consecutive plans (temporal ensembling, from ACT) helped earlier models, whose plans jittered because they read the scene poorly. For the final model it made things worse: once the plans are good, mixing in a plan made from an older frame only adds lag.

7Pretrain broadly, fine-tune narrowly

community data236 SO-100/101 datasets12.6k episodes, wrist only pretrainVAE + WAM, ~1 day fine-tune91 own demos + DINOv2keep pretrained normalization real robotstacks ~50% of tries Trained only on its own scene, the model was sharper offline but fragile on the robot; pretraining made it robust.
A few dozen demonstrations are enough to specialize a model that has already seen hundreds of setups.

Two details matter when fine-tuning. Keep the pretrained model's normalization statistics: recomputing them from a few dozen demonstrations rescaled the joint inputs by about 10×, which the pretrained weights would first have had to unlearn. And scale the training steps with the data: with 91 instead of 61 demonstrations at the same step budget, the model was under-trained and grasped worse.

Where this goes next. The weak spot is stability: two plans made a few steps apart still disagree more than they should, and the imagination is not yet reliable enough to plan with. Building on a large pretrained video model, consistent per-step noise levels, and choosing among several imagined futures with a learned value are the natural next steps.