TD-MPC and Control-Centric Representations › Temporal-Difference Model Predictive Control
World Models HandbookAll chapters TD-MPC and Control-Centric Representations › Temporal-Difference Model Predictive ControlOne section · Sections in this chapter3 / 9 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
We now have a model that predicts rewards and latents, and a value function that estimates returns. The remaining question is how to convert them into an action at every control step. TD-MPC uses a receding-horizon sampling planner, run entirely inside latent space, with the value function supplying the tail of the objective.
Recall from Sampling-Based Planning and Model Predictive Control that the MPPI-style planner samples action sequences, evaluates them under the model, and refits a sampling distribution toward high-scoring candidates. It does not differentiate through the planned rollout. That avoids relying on rollout gradients, but sampling can still exploit errors in the learned model or critic.
The planning objective
Let be the current latent, and let be a candidate action sequence over a horizon of steps. Roll the latent dynamics forward deterministically, . The planner scores each candidate by
The first term estimates rewards along a candidate model rollout; the second evaluates the tail after that rollout. The paper's Equation (3) writes the terminal term as , leaving the terminal action abstract in that notation. The released 2022 implementation instantiates it as
The terminal action is sampled from the learned policy using the configured minimum standard deviation because the candidate sequence ends at step . The two online critics are combined by a minimum; this choice alone is not a guarantee against optimistic scoring. The planner needs only a numeric score, while the policy's separate training objective uses gradients through its proposed action. The score resembles an -step bootstrapped return, but planning optimizes actions using model predictions, whereas TD learning fits a value function to targets. They are related operations, not identical algorithms.
Two error sources enter the score. Errors in reward and latent predictions can change the scores of candidate sequences; for a fixed sampled terminal action, error in the twin-critic terminal estimate contributes , where is the estimation error of at that terminal state and action. Policy sampling adds another source of score variation. These effects depend on which states the optimizer visits. A shorter horizon reduces exposure to model rollouts but puts more weight on the critic. No fixed ranking of the errors follows without measuring the model, critic, and candidate distribution.
The MPPI update
MPPI maintains a time-varying Gaussian over action sequences and improves it over a few iterations. Each iteration does four things.
- Sample. Draw action sequences from and clip each action to the environment's bounds. Add policy-guided trajectories; the original implementation injects noise into policy actions so these proposals are not duplicates.
- Score. Roll every candidate through and , accumulate the discounted predicted reward, and add the terminal value.
- Fit. Keep the top candidates (the elites) and refit:
where is the largest elite score and controls weight sharpness. Subtracting the maximum is a numerically stable softmax shift; it does not normalize score variance or make the weighting invariant to reward scale. The original planner uses this max shift, not the z-score normalization illustrated separately below. 4. Repeat for a fixed number of iterations.
In the released TD-MPC planner, the first action comes from a trajectory sampled among the final elites according to their weights. During training, exploration noise is then added using the final elite spread; evaluation omits that extra noise. The code does not clamp the action again after adding this final noise. This is distinct from the toy planner below, which samples from its refitted Gaussian and clips the result. Neither action-selection rule guarantees useful coverage when the model and critic are poor.
The next illustration asks a counterfactual question: what would z-score normalization do to weights under a reward-scale change? It is useful for understanding softmax sensitivity, but it is not a diagram of the original TD-MPC planner. The weights use deterministic return vectors, with no sampling.
## Elite weights under raw versus normalized returns at two reward scales (deterministic).
mppi_temperature = 1.5
elite_index = np.arange(1, 9)
elite_returns_small = np.linspace(1.0, 3.0, 8)
elite_returns_large = elite_returns_small * 100.0
def _softmax_weights(values, temperature):
scaled = temperature * (values - values.max())
weights = np.exp(scaled)
return weights / weights.sum()
def _normalized_weights(values, temperature):
normed = (values - values.mean()) / (values.std() + 1e-6)
return _softmax_weights(normed, temperature)
weights_raw_small = _softmax_weights(elite_returns_small, mppi_temperature)
weights_raw_large = _softmax_weights(elite_returns_large, mppi_temperature)
weights_normalized = _normalized_weights(elite_returns_large, mppi_temperature)
Policy-guided proposals can put candidates near actions the learned critic rates highly, especially in larger action spaces. The original implementation adds noise to these trajectories so repeated proposals can explore different continuations. This guidance may help but can also inherit critic errors; it is not a guarantee that prior and planner improve together.
What the model is and is not used for
This is the point where TD-MPC most sharply diverges from Dreamer, so it is worth being precise.
The model is used in training and at decision time. Training samples real trajectories from replay, then repeatedly applies learned latent dynamics along their recorded actions. Reward and value predictions on these predicted latents receive gradients through the unroll. At decision time, the planner searches over new candidate action sequences in the same learned model.
The TD bootstrap in released code uses observed successors. This is narrower than saying model predictions never enter learning: the value prediction is fitted on model-unrolled latent states, and its gradient shapes the model. Unlike Dreamer's policy-learning rollouts, these unrolls follow replayed actions rather than a newly imagined policy trajectory.
This distinction matters for diagnosing failure. A model error can affect both planning scores and value predictions during recurrent training, even when the TD target begins from an encoded observed successor. Off-policy replay permits reuse of past data but does not make arbitrary stale or poorly covered trajectories harmless.
The planner and critic remain coupled through the terminal score and policy proposals. If the critic is optimistic for candidate actions or terminal states outside replay coverage, optimization can exploit that error. The method limits rollout length but offers no general divergence guarantee.
Putting the pieces in order
The complete online loop is short enough to state in full.
- Reset the environment, encode the observation to .
- At each step, run MPPI on the current latent with the model and value function, take the sampled action, and step the environment.
- Store in the replay buffer.
- Sample replay sequences, optimize the weighted model/critic losses and the separate policy objective, then update target parameters by exponential moving average.
- Repeat for a fixed number of episodes or environment steps, using a short random-action warm-up at the start to seed the buffer.
Warm-up supplies initial replay data before relying on an untrained planner. The released loop normally runs one optimization update per collected decision transition, not per underlying simulator frame when actions repeat; our short toy groups updates differently. Neither setting establishes that the toy has learned a useful controller.
The original implementation plans at each control step, uses a short horizon and sampled action sequences, and normally takes one training update per collected decision transition. The horizon is scheduled upward during early training. TD-MPC2 uses a short horizon too, but differences in architecture, task mix, and evaluation prevent attributing its gains solely to a stronger critic or a shorter plan.