Planning with Learned Values: TD-MPC
Short-horizon planning with a learned value at the end.
Plan five steps ahead and let a learned value function judge everything after: that is the bargain of TD-MPC and its relatives. This lesson proves what a terminal value buys a short-horizon planner, shows that the classical bound is attained by planners that replan at every step (and why a widely quoted tighter bound needs a planner that commits to its plans), adds model error and asks what the bound says about choosing the horizon, and then dissects TD-MPC and TD-MPC2: what they learn, how they plan, and what their ablations show.
What you’ll learn
- Prove that -step lookahead with an exact model and a terminal value within of loses at most , and construct an example in which a replanning controller attains the bound.
- Extend the bound to a learned model, and explain why under uniform error bounds it never favors an intermediate horizon.
- Describe POLO and LOOP, including LOOP's actor-divergence problem.
- Specify TD-MPC and TD-MPC2 (latent model, losses, MPPI planner with a policy prior) and interpret their ablations.
What a terminal value buys
A terminal value closes the gap that MPC leaves at its horizon. An -step lookahead policy solves, at each state, over -step plans (closed-loop plans in a stochastic MDP), executes the first action and replans. With it is the myopic MPC of Optimal Control & Model Predictive Control; with even is optimal, because acting greedily with respect to is optimal.
(a) The performance-difference lemma, with the optimal policy as the reference, writes the loss as the discounted one-step shortfalls along 's own trajectory:
Each shortfall is at most . With optimal in , and because is greedy:
Summing gives (a). (b) The lookahead policy is greedy with respect to . Since is a -contraction with fixed point , , hence ; apply (a) with .
The terminal value's error is discounted by , but the factor remains: a replanning controller makes a fresh decision at every step, and each decision can be off by .
The bound is tight: procrastination
POLO (Lowrey et al., 2019, Lemma 2) and LOOP (Sikchi, Zhou & Held, 2021, Theorem 1) state bounds with in place of , which would make lookahead far more forgiving. Both proofs pay the value error once per steps, which is right for a controller that carries out each optimized -step plan before planning again. LOOP says so: its appendix proves the theorem for such a controller and sets the receding-horizon case aside for simplicity. POLO states its lemma for the MPC policy that executes only the first action and replans, but its proof (Appendix C) compares the -step trajectory that this policy generates with the optimized plan, as if the policy followed the plan. For plan-committing controllers both bounds hold, and the example respects them: the committing controller loses only . For receding-horizon MPC, which is what POLO, LOOP and TD-MPC actually run, the example shows that the factor cannot be improved, so POLO's lemma holds only with the committing qualification; its message that lookahead discounts value errors by survives. Replanning protects against model error and noise, but against value error alone it can do worse than committing.
In the procrastination example with , and , what does the replanning controller lose as approaches the tie value ?
Show the answer
14.58
: the full bound. A controller that commits to its plan loses , within POLO's .
Adding a learned model: the horizon trade-off
Let in the environment and in the model. Both operators map into itself, so every has span at most , and centering gives , as in Model Errors & Value-Equivalent Models. Applied to the same function, the two operators therefore differ by at most :
Split into a contraction term and a one-step model error, and unroll from :
The lookahead Q-values add one more model step: , where is the exact-model lookahead, which is within of as before. The triangle inequality and part (a) of the previous theorem finish the proof.
Read the bound as a function of the horizon: is affine in . If the value function is worse than the model's whole-horizon error, , the bound falls with and favors planning as far as possible; otherwise it rises and favors . This bound never favors an intermediate horizon.
The intermediate horizons used in practice, such as TD-MPC's , must therefore be justified by what uniform bounds ignore: model errors that grow faster along a rollout as it leaves the data (the compounding of Model Errors & Value-Equivalent Models), value errors that are small on the data but large elsewhere, and a planner that improves on an imperfect policy network. Charging model error through the drift of the rollout's state distribution, as LOOP's bound does, does not by itself change the verdict: when the terminal value's range is the full , the model term of LOOP's bound works out to for every , so that bound too only falls as grows.
TD-MPC plans steps ahead with . By what factor does that lookahead shrink the value-error term, that is, what is ?
Show the answer
0.951
: five steps of lookahead remove only about 5% of a value error, since the effective horizon is 100 steps. The worst-case bound alone cannot explain why planning helps TD-MPC; the experiments below point elsewhere.
POLO, LOOP and TD-MPC
POLO (Lowrey, Rajeswaran, Kakade, Todorov & Mordatch, 2019; "plan online, learn offline") assumed the dynamics are known, as in a simulator, and learned only a terminal value: MPPI planned with it at every step, the value was fitted offline to targets computed at the states visited, and an ensemble of value functions with randomized priors supplied optimism for exploration. It solved tasks such as a simulated humanoid getting up from the floor.
LOOP (Sikchi, Zhou & Held, 2021) combined a learned ensemble of dynamics models with a terminal value from an off-policy actor–critic. It identified actor divergence: the data are collected by the planner, while the critic's targets are computed with the actor, two different policies, which can destabilize value learning. Its fix, Actor Regularized Control, keeps the planner's distribution over action sequences close to one derived from the actor through a KL constraint, which leads to an MPPI-like closed-form update.
TD-MPC (Hansen, Wang & Su, 2022) learns everything, in a latent space and without a decoder. Its task-oriented latent dynamics model has an encoder , latent dynamics , a reward head , a value and a policy , all trained on short replayed segments by unrolling the latent dynamics from the first encoded state.
To act, TD-MPC runs MPPI in the latent space with horizon . Each candidate action sequence is scored by its predicted rewards plus the terminal value, . It samples 512 sequences from a Gaussian plus about 5% more from the policy , weights the top 64 by to refit the Gaussian, repeats for 6 iterations (8 for the Dog tasks, 12 for Humanoid), and warm-starts from the previous step's plan. Early in training the horizon grows from 1 to , because the model is still poor.
import torch
@torch.no_grad()
def plan(z0, dyn, rew, q, pi, act_dim, mean=None, H=5, iters=6, n=512, n_pi=25, k=64, temp=0.5, gamma=0.99):
"""Latent MPPI with a policy prior. z0: (d,) encoded state. Returns the action and the plan's mean."""
mean = torch.zeros(H, act_dim) if mean is None else mean # warm start: last plan shifted by one
std = torch.full((H, act_dim), 2.0)
for _ in range(iters):
acts = (mean + std * torch.randn(n, H, act_dim)).clamp(-1, 1)
z, prior = z0.expand(n_pi, -1), []
for t in range(H): # sequences proposed by the policy
a = pi(z); prior.append(a); z = dyn(z, a)
acts = torch.cat([acts, torch.stack(prior, dim=1)])
z, G = z0.expand(len(acts), -1), torch.zeros(len(acts))
for t in range(H): # predicted rewards along the rollout ...
G += gamma ** t * rew(z, acts[:, t]); z = dyn(z, acts[:, t])
G += gamma ** H * q(z, pi(z)) # ... plus the learned terminal value
top = G.topk(k).indices
w = torch.softmax(temp * G[top], dim=0) # weights proportional to exp(temp * G)
mean = (w[:, None, None] * acts[top]).sum(0)
std = (w[:, None, None] * (acts[top] - mean) ** 2).sum(0).sqrt().clamp_min(0.05)
return mean[0], meanA simplified sketch of TD-MPC's planner, not its exact code: the paper also adds exploration noise to the executed action, lowers the spread's floor over training and grows the horizon early on. The policy's proposals keep the search anchored near behavior that the value function has been trained on.
TD-MPC2, and what the experiments show
TD-MPC2 (Hansen, Su & Wang, 2024) kept the recipe and changed what makes it robust and scalable. The consistency target is the stop-gradient encoding ; rewards and values are learned by discrete regression, a cross-entropy over bins in a log-transformed space, as in DreamerV3; the policy prior is a maximum-entropy policy; an ensemble of 5 Q-functions supplies targets from the minimum of two randomly chosen members; every network uses LayerNorm and Mish activations; and the latent state is normalized by SimNorm, which splits into groups of entries and applies a softmax to each, with , biasing the latent toward sparsity. One set of hyperparameters served 104 continuous-control tasks across 4 domains, and a single 317-million-parameter agent learned 80 tasks spanning several domains, embodiments and action spaces.
| Claim | Evidence | Caveat |
|---|---|---|
| Planning beats the learned policy alone | In TD-MPC the policy network was inferior to planning on complex tasks, with a larger gap for high-dimensional action spaces such as the Quadruped tasks | Planning costs an optimization at every step |
| Latent consistency is a good model target | Over 15 DMControl tasks, reconstruction and contrastive losses improved on no regularization, and latent consistency more consistently | Results on state-based control tasks |
| Sample efficiency | TD-MPC learned Humanoid and Dog locomotion from states in about 1 million environment steps and reported better sample efficiency and final performance than prior methods on DMControl and Meta-World | Comparisons depend on implementation details and compute |
| Stability and scale | TD-MPC2's authors found SimNorm essential to stable training, and larger models scored higher in the multi-task setting | Reported by the method's authors |
Key takeaways
- A replanning -step lookahead with an exact model and a terminal value within of loses at most : lookahead discounts the value's error by but keeps the .
- The bound is attained: in the procrastination chain, value errors make "act next step" always look better than "act now". The bounds of POLO and LOOP hold for controllers that commit to their plans.
- With a model whose one-step error is , the lookahead error is , affine in , so uniform bounds never favor an intermediate horizon; practical short horizons rest on errors that grow along rollouts and on improving an imperfect policy.
- TD-MPC learns a decoder-free latent model with reward, TD and latent-consistency losses and plans with MPPI over 5 steps plus a learned Q, seeded by a policy prior; TD-MPC2 adds SimNorm, discrete regression, a Q ensemble and a maximum-entropy prior to cover 104 tasks with one configuration and to train a 317M-parameter multi-task agent.
- Planning helped most where the policy network was weakest, consistent with decision-time planning acting as policy improvement rather than as a correction of the value.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
With an exact model and a terminal value within of , what is the worst-case loss of an -step lookahead controller that replans at every step?
- , independent of
- Zero for
- , and the procrastination example attains it
Show the answer
D. , and the procrastination example attains it
Lookahead shrinks the error of the decisions' Q-values to , and a fresh decision every step can lose each time, adding up to . The procrastination chain shows the bound cannot be improved.
Why does the replanning controller never take the good action in the procrastination example?
- The good action's true value is lower than waiting
- At every step the value error makes "wait one step, then act" look better than "act now", and each replanning postpones again
- The model gets the transitions wrong
- The horizon is too long
Show the answer
B. At every step the value error makes "wait one step, then act" look better than "act now", and each replanning postpones again
The plan "wait, then act" ends its horizon in a state whose value is overestimated, while "act now" ends in one whose value is underestimated. The planner always intends to act next step, and replanning never lets it.
Under uniform error bounds, the lookahead error is . What does this imply about choosing the horizon?
- is affine in , so it is smallest at or as , never at an intermediate horizon
- The best horizon is always
- Longer horizons always help
- The horizon does not matter
Show the answer
A. is affine in , so it is smallest at or as , never at an intermediate horizon
moves monotonically with , in the direction set by whether the value or the model is the worse source of error. Intermediate horizons need error models that uniform bounds do not capture.
What target does TD-MPC's latent-consistency loss use for the predicted latent ?
- The next observation's pixels
- The reward of the step
- The encoding of the next real state by a target encoder, a moving average of the online encoder
- The policy's next action
Show the answer
C. The encoding of the next real state by a target encoder, a moving average of the online encoder
TD-MPC never decodes observations. The predicted latent is pulled toward , and the slowly moving target encoder, like a stop-gradient, keeps this self-prediction from collapsing.
Further reading
- S. P. Singh & R. C. Yee, "An upper bound on the loss from approximate optimal-value functions," Machine Learning 16, 227–233 (1994).
- D. P. Bertsekas, Reinforcement Learning and Optimal Control (Athena Scientific, 2019).
- K. Lowrey, A. Rajeswaran, S. Kakade, E. Todorov & I. Mordatch, "Plan online, learn offline: efficient learning and exploration via model-based control," ICLR (2019).
- H. Sikchi, W. Zhou & D. Held, "Learning off-policy with online planning," Conference on Robot Learning (2021).
- N. Hansen, X. Wang & H. Su, "Temporal difference learning for model predictive control," ICML (2022).
- N. Hansen, H. Su & X. Wang, "TD-MPC2: scalable, robust world models for continuous control," ICLR (2024).