Search

Search papers and lessons

TD-MPC2: Scalable, Robust World Models for Continuous Control

Nicklas Hansen, Hao Su, Xiaolong Wang · 2023

TD-MPC2 learns a latent world model that predicts rewards and values without decoding observations, plans with it, and uses one hyperparameter set across 104 control tasks.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • Reinforcement learning
  • Linear algebra
  • Neural network basics
  • World models
  • Sign in to see your progress

TL;DR

TD-MPC2 is a model-based reinforcement learning agent. It learns a world model in a compact latent space, trained to predict rewards and values rather than future observations, and it chooses each action by planning with that model. One set of hyperparameters works across 104 continuous-control tasks, and the same design scales to a single 317M-parameter agent trained on 80 tasks.

Where you'll see it: continuous robot-control benchmarks where one policy must handle many tasks, and as the main reference point for latent planning in the TD-MPC family.

The problem

Continuous control means choosing real-valued actions, such as joint torques, at every step. Model-based RL learns a model of the environment and plans with it, which can be far more data-efficient than trial and error alone. The paper names three problems that made this hard to scale across many tasks:

  1. Hyperparameter sensitivity. Most RL algorithms, including SAC and the original TD-MPC, use per-task hyperparameters and have no principled way to choose them. A method that must learn many tasks at once cannot be retuned for each one.
  2. Scaling failure. Naively making TD-MPC's world model larger and training it on more data often lowers performance. The paper's Figure 1 states this as a net decrease in agent performance.
  3. Expensive imitation data. Generalist embodied agents trained by behavior cloning assume near-expert demonstrations, which are scarce. The authors want an algorithm that learns from large, uncurated datasets whose behaviors range from random to expert.

Reconstruction-based world models add a fourth difficulty. Predicting raw future images or proprioceptive features over long horizons is hard, and accurate prediction does not guarantee good control.

Key idea

TD-MPC2 asks for a model that is maximally useful for control, not one that reproduces the world. The model predicts what matters for decisions: the reward of a step, and the discounted return from a latent state. It never decodes observations.

Picture a planner that imagines a few steps ahead in latent space, then hands off to a learned value function that estimates everything beyond that horizon. The planner only needs the model to score imagined futures correctly, which is a much smaller job than predicting pixels correctly.

The method

Components

The agent has five learned pieces, all conditioned on a task embedding e\mathbf{e}. Each is a small MLP.

ComponentFormJob
Encoderz=h(s,e)\mathbf{z}=h(\mathbf{s},\mathbf{e})Maps an observation to a latent state
Latent dynamicsz′=d(z,a,e)\mathbf{z}^{\prime}=d(\mathbf{z},\mathbf{a},\mathbf{e})Predicts the next latent state
Rewardr^=R(z,a,e)\hat{r}=R(\mathbf{z},\mathbf{a},\mathbf{e})Predicts the reward of one transition
Terminal valueq^=Q(z,a,e)\hat{q}=Q(\mathbf{z},\mathbf{a},\mathbf{e})Predicts the discounted return from a state-action pair
Policy priora^=p(z,e)\hat{\mathbf{a}}=p(\mathbf{z},\mathbf{e})Proposes an action that should score well under QQ

During training the agent keeps a replay buffer and alternates two steps: update the model on sampled sequences, then collect new environment data by planning with the model.

The learning objective

The encoder, dynamics, reward and value components are trained together on sampled sequences of length HH:

L(θ)=E(s,a,r,s′)0:H∼B[∑t=0Hλt(∥zt′−sg⁡(h(st′))∥22+CE⁡(r^t,rt)+CE⁡(q^t,qt))]\mathcal{L}(\theta)=\mathbb{E}_{(\mathbf{s},\mathbf{a},r,\mathbf{s}^{\prime})_{0:H}\sim\mathcal{B}}\left[\sum_{t=0}^{H}\lambda^{t}\left(\|\mathbf{z}_{t}^{\prime}-\operatorname{sg}(h(\mathbf{s}_{t}^{\prime}))\|_2^2+\operatorname{CE}(\hat{r}_{t},r_{t})+\operatorname{CE}(\hat{q}_{t},q_{t})\right)\right]

Each of the three terms does one job:

  • Joint-embedding prediction. The predicted next latent zt′\mathbf{z}_t^{\prime} is pulled toward the encoding of the real next observation. The stop-gradient sg⁡\operatorname{sg} means that target is not pushed back through the encoder, which prevents the trivial solution where every observation maps to one constant vector.
  • Reward prediction. A cross-entropy loss on the predicted reward.
  • Value prediction. A cross-entropy loss on the predicted value against the TD target qt=rt+γQˉ(zt′,p(zt′))q_t = r_t + \gamma \bar{Q}(\mathbf{z}_t^{\prime}, p(\mathbf{z}_t^{\prime})).

Here λ∈(0,1]\lambda \in (0,1] down-weights farther time steps, and Qˉ\bar{Q} is an exponential moving average of QQ, which keeps the TD target from chasing itself. Reward and value are not regressed as raw numbers. The paper treats them as discrete classes in a log-transformed space, with 101 bins, and trains with cross-entropy using the target as a soft label. The paper says this makes the magnitude of the two loss terms independent of the magnitude of the task rewards. The joint-embedding term keeps continuous (squared-error) regression, because the latent is already normalized by SimNorm and discrete regression would need NN bins for every latent dimension.

The policy prior

The policy prior pp is a stochastic policy trained with maximum-entropy RL. It maximizes the value of its action plus an entropy bonus:

Lp(θ)=E(s,a)0:H∼B[∑t=0Hλt[α Q(zt,p(zt))−β H(p(⋅∣zt))]]\mathcal{L}_p(\theta)=\mathbb{E}_{(\mathbf{s},\mathbf{a})_{0:H}\sim\mathcal{B}}\left[\sum_{t=0}^{H}\lambda^{t}\left[\alpha\, Q(\mathbf{z}_t,p(\mathbf{z}_t))-\beta\,\mathcal{H}(p(\cdot\mid\mathbf{z}_t))\right]\right]

The entropy H\mathcal{H} has a closed form. The weights α\alpha and β\beta balance the value term against the entropy term, because the value scale changes across tasks and training stages, and too little entropy makes the policy collapse early. The paper tunes α\alpha from moving statistics of the value estimate and reports no significant difference from an entropy-target scheme.

Architecture and SimNorm

Every component is an MLP with linear layers, LayerNorm and Mish activations. The latent z\mathbf{z} is normalized by SimNorm. It splits the latent into LL groups of VV values and applies a softmax with temperature τ\tau to each group:

z∘=[g1,…,gL],gi=ezi:i+V/τ∑j=1Vezi:i+V/τ\mathbf{z}^{\circ}=[\mathbf{g}_1,\dots,\mathbf{g}_L],\qquad \mathbf{g}_i=\frac{e^{\mathbf{z}_{i:i+V}/\tau}}{\sum_{j=1}^{V}e^{\mathbf{z}_{i:i+V}/\tau}}

Each group becomes a probability vector, which bounds the norm of the latent and pushes it toward sparse groups without a hard constraint. The paper says SimNorm is essential to training stability. The default 5M model uses latent dimension 512, V=8V=8 (so 64 groups) and τ=1\tau=1 (Table 8).

Value learning uses an ensemble of five QQ-functions, each with 1% dropout after its first layer, and each with its own EMA target Qˉ\bar{Q}. TD targets take the minimum of two randomly subsampled target Q-functions.

Planning

At each decision step the agent runs Model Predictive Path Integral (MPPI) planning. It samples action sequences of horizon HH from a diagonal Gaussian, scores each by rolling it out in latent space, and moves the Gaussian toward high-scoring sequences. The objective is

μ∗,σ∗=arg⁡max⁡(μ,σ)E(at,…,at+H)∼N(μ,σ2)[γHQ(zt+H,at+H)+∑h=tH−1γhR(zh,ah)]\mu^{*},\sigma^{*}=\arg\max_{(\mu,\sigma)}\mathbb{E}_{(\mathbf{a}_t,\dots,\mathbf{a}_{t+H})\sim\mathcal{N}(\mu,\sigma^2)}\left[\gamma^{H}Q(\mathbf{z}_{t+H},\mathbf{a}_{t+H})+\sum_{h=t}^{H-1}\gamma^{h}R(\mathbf{z}_h,\mathbf{a}_h)\right]

The learned value at the end of the horizon makes the plan a full RL objective rather than a short-sighted one. Only the first action of the best plan is executed, and then planning restarts from the new state. Some sampled sequences come from the policy prior, and the Gaussian is warm-started from the previous step's solution shifted by one.

Table 8 gives the defaults: horizon H=3H=3, 6 iterations (8 if the action dimension is at least 20), population 512, 64 elites, 24 policy-prior samples, temperature 0.5, and minimum and maximum standard deviations 0.05 and 2.

Training across tasks

To train one agent on many tasks with different observation and action sizes, the paper does three things:

  • Learnable task embedding. A 96-dimensional vector e\mathbf{e} conditions all five components. Its norm is constrained to at most 1 for training stability, and the paper reports that this also makes task embeddings more semantically coherent.
  • Zero-padding and action masking. Inputs and outputs are padded to the largest sizes, and invalid action dimensions are masked out in the policy prior and in planning. This keeps padding errors out of TD targets and stops the entropy from inflating on small action spaces.
  • Same hyperparameters everywhere. No per-task tuning is used. The discount factor and the number of seed steps are set by heuristics (Appendix H), not tuned per task.

Worked examples

Example 1: SimNorm on one group (analytic, illustrative values). Take V=4V=4, τ=0.5\tau=0.5, and the group z=(2, 1, 0, −1)\mathbf{z}=(2,\,1,\,0,\,-1).

  1. Divide by τ\tau: (4, 2, 0, −2)(4,\,2,\,0,\,-2).
  2. Exponentiate: (54.598, 7.389, 1, 0.135)(54.598,\ 7.389,\ 1,\ 0.135).
  3. Sum: 63.12263.122.
  4. Divide: g=(0.865, 0.117, 0.016, 0.002)\mathbf{g}=(0.865,\ 0.117,\ 0.016,\ 0.002), which sums to 1 up to rounding.

Interpretation: the largest entry dominates, so the group is nearly one-hot. Lowering τ\tau makes it sparser, and raising it makes it more uniform. The latent stays a set of probability vectors whatever the raw scale of z\mathbf{z}.

Example 2: the discount heuristic. The paper sets γ=clip⁡(T/5−1T/5, [0.95, 0.995])\gamma = \operatorname{clip}\left(\frac{T/5-1}{T/5},\,[0.95,\,0.995]\right), where TT is the expected episode length after action repeat.

  1. T=500T=500: T/5=100T/5=100, so γ=99/100=0.99\gamma=99/100=0.99, inside the clip range.
  2. T=1000T=1000: T/5=200T/5=200, so γ=199/200=0.995\gamma=199/200=0.995, exactly the upper clip value.
  3. T=50T=50: T/5=10T/5=10, so γ=9/10=0.9\gamma=9/10=0.9, which is clipped up to 0.950.95.

Interpretation: longer episodes need a discount closer to 1 so that the return still sees the rewards at the end. The clip keeps the value in a range the paper's setting supports.

Example 3: planning compute per decision (estimate from Table 8). With 6 iterations and 512 sampled sequences per iteration, a decision evaluates about 6×512=30726 \times 512 = 3072 sequences. Each has horizon 3, so roughly 92169216 latent steps are simulated, not counting the 24 policy-prior samples per iteration or the terminal value calls. Interpretation: planning is the main per-step compute cost. The paper reports code-level optimizations that roughly double planning throughput, which keep its wall-clock time comparable to TD-MPC despite the larger network.

Results

Numbers below come from the paper's text and tables.

Single-task control (104 tasks, 4 domains). The primary comparison is against SAC (model-free), DreamerV3 (model-based, about 20M parameters) and the original TD-MPC. TD-MPC2 uses a 5M-parameter agent with one set of hyperparameters, with 3 seeds and 95% confidence intervals. It outperforms the baselines across all four domains. The authors ran no TD-MPC2 experiments on MyoSuite before the reported results. On high-dimensional locomotion (Humanoid, with 21 action dimensions, and Dog, with 38) and on object manipulation, the margin is described as large. The paper says TD-MPC sometimes diverges from exploding gradients, while TD-MPC2 stays stable. DreamerV3 shows numerical instabilities on Dog and struggles with fine manipulation such as lift, pick and stack.

Visual observations. On 10 image-based DMControl tasks, with a shallow convolutional encoder and no hyperparameter changes, TD-MPC2 is comparable to DrQ-v2 and DreamerV3, the two best baselines.

Scaling (Table 1). Models range from 1M to 317M parameters, trained on 80 tasks (50 Meta-World and 30 DMControl) from 545M transitions taken from the replay buffers of 240 single-task agents. Multitask training uses batch size 1024.

Params (M)GPU days (RTX 3090)Normalized score
13.716.0
54.249.5
195.357.1
481268.0
3173370.6

The paper reports that the normalized score appears to rise linearly with the log of parameter count, and that the largest model has not saturated. It explicitly declines to state a scaling law.

Few-shot finetuning. A 19M-parameter agent pretrained on 70 tasks, then finetuned to 10 held-out tasks with an empty replay buffer and unchanged hyperparameters, improves about 2x over learning from scratch in the 20k-environment-step regime. The paper calls finetuning world models an open problem and presents these results as exploratory.

Ablations. The paper ablates the actor, normalization, regression objective and number of Q-functions. It reports that every design choice contributes, and that the relative importance of each choice is consistent between single-task and multitask settings.

Task embeddings. A t-SNE plot of the embeddings learned on 80 tasks shows that similar tasks, such as Door Open and Door Close, sit close together. The paper says closeness follows dynamics (embodiment and objects) more than objective (walk versus run). This comes from a t-SNE visualization.

Why it mattered

The paper states what it changed. It makes model-based RL robust across tasks with one hyperparameter set, shows that a latent world model without a decoder can scale to 317M parameters, and releases over 300 checkpoints, datasets and code. Its lessons section argues that algorithmic robustness lowers the barrier to RL for small teams.

The paper also lists what it leaves open. Extending TD-MPC2 to discrete action spaces is an open problem, and the paper says DreamerV3 performs better on discrete tasks such as Atari and Minecraft. The method relies on reward signals, and the paper names success labels, human preferences and goal-embedding distances as possible generalized rewards whose use for large-scale pretraining is still open. Its risks section names misspecified rewards, unsafe autonomy on physical robots, and data costs that could concentrate power. Finally, it proposes that massively multitask world models could be used zero-shot on seen embodiments and finetuned on new ones, and notes that such generalization will likely need far more tasks than are available now.

Reading guide

Read the paper in this order and use these lessons for the sections that need them.

  1. Introduction and Background (Sections 1 and 2): Reinforcement Learning for the MDP setup, and Model-Based Reinforcement Learning for why planning with a learned model is attractive. Model Predictive Control introduces the receding-horizon idea that Section 2 formalizes.
  2. Components and objective (Section 3.1): Temporal-Difference Learning for the TD target, Exponential Moving Average for the target network Qˉ\bar{Q}, Cross-Entropy Loss and Softmax for the discrete reward and value heads and the SimNorm projection, and Layer Normalization for the normalized MLPs.
  3. Planning (Section 3.2): Model Predictive Control for replanning at each step, and Cross-Entropy Method for the closely related sampling-based planner that MPPI builds on.
  4. Multitask training (Section 3.3): no new prerequisites. The task embedding and masking use the concepts above.
  5. Experiments and ablations (Section 4): Learning Latent Dynamics for Planning from Pixels (PlaNet) and World Models for the earlier latent-model lineage, and Mastering Diverse Domains through World Models (DreamerV3) for the main model-based baseline.
  6. Lessons, opportunities and risks (Section 5): no new prerequisites.

Check yourself

QuestionThe joint-embedding loss uses a stop-gradient on the encoding of the next observation. What would go wrong without it?Show answer
The loss pulls the predicted latent toward the encoding of the next observation. If gradients also flowed into that target, the encoder could map every observation to the same vector and drive this term to zero without learning anything useful. The stop-gradient keeps the target fixed for this term, so the dynamics model must predict the next latent accurately.
QuestionWith T=1000T=1000 expected steps after action repeat, what discount does the paper's heuristic give?Show answer
First compute T/5=200T/5=200. Then γ=(200−1)/200=199/200=0.995\gamma=(200-1)/200=199/200=0.995. This is exactly the top of the clip range [0.95,0.995][0.95, 0.995], so no further clipping applies.
QuestionWhy does the planner add the learned value QQ to the sum of rewards over the horizon?Show answer
Planning over a horizon of H=3H=3 steps sees only three rewards, so it would be short-sighted. The value at the end of the horizon estimates the discounted return from there onward. Adding it gives the planner an estimate of the full RL objective, which addresses the local optimality of pure trajectory optimization that the paper describes in its background section.
QuestionA team wants to run TD-MPC2 on a robot whose action dimension is larger than any training task. Based on the paper's design, what should they check first?Show answer
They must confirm that the robot's action dimension fits within the largest padded size used in training, since the model's inputs and outputs are zero-padded to that size. They should also check that action masking covers the new dimensions in the policy prior and in planning. Finally, the paper's default rule raises planning iterations from 6 to 8 for action dimensions of 20 or more, so the planning budget and its compute cost should be re-measured for a larger action space.

Sources

Read the full paper

Nicklas Hansen, Hao Su, Xiaolong Wang, 2023. arXiv:2310.16828