Inside the world model
13.9M parameters: a 5.2M tokenizer and an 8.6M world model, learned from scratch from pixels and actions alone. One cold training run is under 10 minutes on one A100, about $0.1 of compute.
what it does
Four RL agents played 500k transitions of Craftax-Classic, a 2D Minecraft: they reach diamonds, die in every way the game allows, break their own crafting habits and walk back to places they saw before. tinywmcraft learns the game from those frames and actions: given a history of frames and an action, it generates the next frame, the reward and whether the episode ends. Feed its own frames back in and you can play inside it. No game state, tile labels or pretrained features enter the model.

inside the model
Tokenizer. A 63×63 frame becomes a 4×4×32 latent. The 81 tiles of 7×7 pixels are tokens for six transformer blocks, then a stride-2 conv and four residual conv blocks. The decoder mirrors it. A third of each batch is clean, a third has half its tiles grey and a third is noised; the target is always the clean frame. Without the masked and noised thirds, game logic falls apart.
World model. Six transformer blocks of width 256 alternate spatial attention over the 16 latent tokens with causal attention across 32 frames. The action, each frame's noise level and the sampler's step size condition adaLN-zero blocks. Flow matching predicts the clean latent, and eight Euler steps generate each frame.
Losses. Next to flow matching, a shortcut loss teaches one step to land where two half steps would. An eighth of the training windows start at a real game start, so the model can imagine a first frame from nothing: every world in the player starts that way, and the player re-rolls the rare first frame that looks mid-game.
Heads. A reward head (two-hot over 255 symlog bins) and a termination head read each frame's mean token, so the model returns frames, rewards and episode ends. Their gradient into the trunk drops to a tenth in the second half of training.
Optimizer. Muon on every matrix and conv kernel, with five Polar Express steps in bf16 and same-shape matrices stacked; AdamW on the action embedding, biases and norms. Warmup, constant, then linear decay over the last 20% of steps: 9k tokenizer steps, then 19k world-model steps.
Kernels. At width 256 a training step is bound by memory traffic. Two Pallas kernels read the activations in place: attention over a frame's tokens or causally over the frames, and a gated residual add fused with the next modulated RMS norm. They make a world-model step 2x faster than plain XLA, which runs everywhere else.
Sampling. Spatial attention stays within a frame and temporal attention is causal, so the past frames' keys and values are computed once per new frame, and each Euler step runs only the new frame's 16 tokens. The browser player does the same: about 7 GFLOP per action on WebGPU.
Tried and dropped. These parts cost code or time and did not move the score over three seeds: the tokenizer seeing the frame before, training on the model's own generated past, a loss on how latents change from frame to frame, NorMuon's per-neuron step sizes, a separate optimizer for the heads, oversampling the hardest windows, and most of the custom kernels. The time now goes to more world-model steps: 534 lines instead of 1113, the same score.
the whole model on one page
train_tiny.py is the complete model in one file, for reading: tokenizer, world model, heads and training in 178 lines, no custom kernels. It is iteration 1 on the benchmark: 0.287 ± 0.019 over seeds 0, 1 and 2. Read it on screen or print it as a poster.
references
Craftax · Flow Matching · Diffusion Forcing · DiT · Dreamer 4 · Shortcut Models · Muon · FVD