Section 38.4: Transformer world models (IRIS)

"The tokenizer is not preprocessing; it is the alphabet the world model is allowed to think in."

A Latent Sequence That Behaves Like Language
Technical illustration for Section 38.4: Transformer world models (IRIS), showing an embodied agent predicting futures, testing actions, and revising behavior from feedback.
Figure 38.4A: The opener illustration frames transformer world models (iris) as a closed-loop problem: a prediction is valuable only if it changes action selection and survives contact with reality.
Big Picture

IRIS asks a different question from RSSM: what if world modeling is a sequence-modeling problem over discrete visual tokens and actions? The payoff is long-range dependency modeling with the same machinery that made autoregressive language models powerful.

Builder Route

Read this section by following the tokenization pipeline. First compress frames into discrete codes, then prepend actions to the token sequence, then ask whether causal attention keeps enough temporal structure to support control from imagination.

Key Insight

The tokenizer is not a preprocessing detail. It defines the alphabet the world model can think in, so it directly limits what control-relevant structure the transformer can preserve.

Problem First

Recurrent world models summarize history in a fixed-size hidden state. That is efficient, but it can bottleneck long-range structure. Transformer world models were introduced to test whether image-token sequences and causal attention can capture temporally extended dependencies more faithfully, especially when the environment behaves like a structured visual language.

Core Model

IRIS discretizes visual observations with a tokenizer, then models action-conditioned token sequences autoregressively: $$c_t = \mathrm{Tokenizer}(o_t), \qquad p(c_{t+1} \mid c_{\le t}, a_{\le t}) = \prod_i p(c_{t+1,i} \mid c_{\le t}, a_{\le t}, c_{t+1,

This changes the inductive bias. An RSSM assumes a compact hidden state should summarize the past; IRIS assumes the model can recover what matters by attending over a token history. The benefit is flexible long-range dependency modeling. The cost is quadratic sequence processing and a strong dependence on the tokenizer's ability to preserve the variables the controller needs.

For control, the model must still satisfy the same decision criterion as any world model: generated futures must be action-conditional, temporally stable, and sufficiently aligned with reward-relevant state that a policy trained in imagination transfers back to real trajectories.

IRIS Pipeline

Encode each frame into discrete visual tokens, interleave or condition on action tokens, roll the sequence forward with a causal transformer, then decode the predicted tokens or use them directly for policy learning. The tokenizer is not a side detail; it defines the symbolic alphabet the world model reasons over.

Minimal Probe

The probe below mirrors the core IRIS idea with toy tokens. It rolls a short token sequence forward under actions and checks whether the generated symbol stream still preserves the task-relevant state transition pattern.

# Roll a tokenized world state forward under action-conditioned updates.
# The token history acts like a tiny visual language for the world model.
token_state = [3, 7, 2]
actions = [1, 0, 2]
generated = []
for action in actions:
    next_token = (token_state[-1] + action + token_state[0]) % 10
    generated.append(next_token)
    token_state = token_state[1:] + [next_token]
print({"generated_tokens": generated, "final_context": token_state})

{'generated_tokens': [6, 3, 1], 'final_context': [6, 3, 1]}

Expected behavior: The generated token pattern should depend on both the rolling context and the chosen actions. If changing the actions barely changes the sampled future tokens, the model has become a passive video predictor instead of an action-conditioned world model.

Code Fragment 1: This toy rollout demonstrates the central IRIS move: future visual codes are predicted autoregressively from prior tokens plus actions. The final context shows how the model's own predictions become the history for later imagination steps.
Library Shortcut

The from-scratch token loop takes about 10 lines. In practice, a maintained transformer stack such as transformers or the official IRIS repository collapses the same pattern to a few API calls while handling causal masks, batching, key-value caching, and optimizer scaffolding internally.

Practical Recipe

  1. Audit the tokenizer first; if it destroys small but action-relevant details, no amount of attention depth will fix the problem.
  2. Measure action sensitivity by changing only the action prefix and checking whether sampled futures diverge in the correct way.
  3. Keep track of context length because attention quality can improve even while compute and memory costs become unacceptable for control loops.
  4. Compare the transformer against an RSSM on matched rollout horizon and wall-clock budget, not only sample efficiency.
Warning

A transformer world model can look impressive while the tokenizer quietly deletes the variables that matter for action. If token changes do not reflect action changes, the model is doing video language, not control.

Practical Example

In an Atari-style control benchmark, a transformer world model can attend to a longer token history than a compact recurrent state, which helps when distant events still matter for the next reward. In robotics, that same flexibility is attractive for long-horizon visual context but becomes costly if the control loop needs low latency or multi-camera tokens at high frequency.

Research Frontier

The frontier question is whether token-based world models can scale from game-like visual dynamics to real embodied systems without losing the tight action semantics required by robots and vehicles. Current research is exploring better video tokenizers, hierarchical attention, and hybrids that combine token transformers with compact latent planners.

Cross-Reference Thread

For tokenizer and representation issues, relate this section to Chapter 40. For sequence-model planning and decision transformers, compare with Chapter 26. For simulator benchmarks where IRIS became prominent, revisit Chapter 12.

IRIS is important less because transformers always beat recurrent models and more because it reframed world modeling as discrete sequence prediction. That move lets researchers borrow a mature set of tools from language modeling: tokenization, causal masking, long-context studies, and sampling diagnostics.

The hidden engineering challenge is semantic granularity. If one token change corresponds to a tiny texture difference, the model may look visually sharp but remain weak for control. If tokens are too coarse, the model may ignore subtle collision, grasp, or lane-position cues. In other words, tokenization is where control relevance is won or lost.

Self Check

Can you name one task where token attention is likely to beat a compact recurrent state and one robotic setting where the attention cost may be harder to justify than the extra memory is worth?

Key Takeaway

Transformer world models succeed when tokenization and action conditioning preserve the semantics the controller needs, not merely when the sampled frames look coherent.

Exercise 38.4.1

Propose a benchmark that would fairly compare an RSSM and a transformer world model on the same embodied task. Which three metrics must be matched so that the comparison says something about control rather than only about visual generation?

Bibliography & Further Reading

Primary References And Tools

Reference Micheli, V., Alonso, E., and Fleuret, F.. "Transformers Are Sample-Efficient World Models." (2022). https://arxiv.org/abs/2209.00588

IRIS is the foundational reference for tokenized transformer world models in this chapter.

Reference Eloi Alonso et al.. "IRIS GitHub Repository." (2022). https://github.com/eloialonso/iris

The codebase is useful for seeing how tokenization, transformer rollout, and policy learning fit together.

Reference Hafner, D. et al.. "Mastering Diverse Domains through World Models." (2023). https://arxiv.org/abs/2301.04104

DreamerV3 is the natural recurrent comparison point when assessing IRIS-style architectures.