When to Trust a Model: MBPO
Short branched rollouts and a bound on model-based policy improvement.
Model-generated data is cheap but biased; real data is unbiased but stale, collected by an older policy. Janner, Fu, Zhang and Levine (2019) turned this trade-off into bounds, found that the first one literally recommends never using the model, repaired it with an empirical fact about how models generalize, and arrived at a simple recipe: many short rollouts branched from real states. This lesson derives the bounds and weighs what the experiments show.
What you’ll learn
- Prove a returns bound for two processes that differ in dynamics and policy, with state-distribution error growing linearly in time.
- State MBPO's monotonic-improvement bound, prove it, and show that it is vacuous at realistic discount factors.
- Explain branched rollouts and the -step bound, why it is minimized at as stated, and how an empirical model of generalization yields an optimal .
- Describe the MBPO algorithm, what its experiments do and do not show, and the competing explanation from high update-to-data model-free methods.
Two errors, one returns bound
Write for the true return of a policy and for its return in the learned model (Janner et al. write and ); rewards satisfy . The model was trained on data from an earlier policy . Two errors separate from :
- Model error : the model's generalization error, measured where the data came from, and estimable as a validation loss.
- Policy shift : how far the new policy has moved. In practice it is controlled through a KL divergence and Pinsker's inequality.
Let and be the state and state–action distributions at time . The total variation of a joint distribution is at most that of the first marginal plus the expected TV of the conditional, so the policy adds at most :
The same decomposition for the next state adds the dynamics error, so the state distributions drift apart at most linearly, from at :
Bound each step's reward difference by times the distance, which is twice the TV, and sum with and .
Monotonic improvement, and why the bound is vacuous
The model is only known to be accurate where goes, so add and subtract :
compares two policies in the true dynamics (, ). compares in the true dynamics with in the model (, ). Apply the returns bound to each:
Adding the two gives exactly . The policy shift appears twice because it is paid twice: once to compare with , once again inside the model comparison.
Take , and small errors, . What is the improvement margin that the model return must exceed?
Show the answer
598
, while every return lies in . No policy can clear that margin, so the guarantee never fires. The bound charges the model for compounding over the whole effective horizon, which is the motivation for using the model only over short stretches.
Branched rollouts: model bias against off-policy error
A branched rollout starts from a state drawn from the old policy's state distribution, in practice from the replay buffer, and runs steps of the new policy in the model. Dyna's planning updates are the case . Formally the scheme executes a non-stationary policy that follows in the true dynamics until the branch point and then in the model for steps; call its return .
Read the terms. Those with charge for the part of the return that still rests on stale, off-policy states; a longer branch discounts them away. The term linear in charges for steps of model error. In the first bound that term grows like , larger than anything the terms can save, so the bound is best at : taken literally, it says never use the model. The flaw is pessimism about generalization: the first bound assumes the model's error on the new policy's states can be as large as .
Janner et al. measured instead how the model's error grows as the policy moves away from the data (on Hopper and Walker2d) and found a slow, roughly linear growth, , with a slope that shrinks as the model is trained on more data. With a small slope, the second bound is minimized at some .
Collect the terms of the second bound's bracket, using :
Lengthen the branch by one step: the stale-data term shrinks by a factor , and one more step of model error is added.
So falls while and rises afterward. The best length is the first at which the saving drops below the model error, and it is positive exactly when . Branch longer when the effective horizon is long and when the model generalizes well relative to how far the policy moves. In the first bound the per-step cost is , which always exceeds : there .
With , policy shift and model error on the new policy's states , which integer rollout length minimizes the second bound?
Show the answer
16
, so : still exceeds , while does not. The penalty falls from at , where returns span , to about . The derivation treats as the error on real states of the new policy; inside a rollout the model also meets its own drifting predictions (Model Errors & Value-Equivalent Models), so long branches are worse than the linear term admits.
MBPO in practice, and what the experiments show
MBPO(epochs, E, M, k, G): # after Janner et al. (2019), Algorithm 2
ensemble ← B = 7 probabilistic networks, each p(s′, r | s, a) = Gaussian(μ_θ, diag Σ_θ)
for each epoch:
fit every member to D_env by maximum likelihood
repeat E times:
act with π in the real environment; add the transition to D_env
repeat M times: # many short branched rollouts
s ← a state drawn uniformly from D_env
repeat k times:
a ~ π(· | s); pick an ensemble member at random
(s′, r) ~ that member; add (s, a, r, s′) to D_model; s ← s′
repeat G times: # G ≈ 20–40 updates per real step
update the policy (and SAC's critics) on minibatches from D_model
raise k on a schedule (for example 1 → 15 over training on Hopper)Probabilistic members capture noise in the transitions (aleatoric uncertainty); disagreement among members trained on bootstrapped data captures epistemic uncertainty, and drawing a random member at every step stops the policy from exploiting the quirks of any one of them. The policy learner is soft actor–critic.
On the MuJoCo benchmarks, at their standard length of 1,000 steps, MBPO learned substantially faster than the model-free methods of its time, an order of magnitude on some tasks, while reaching comparable final performance: its return on Ant after 300 thousand steps matched soft actor–critic's after 3 million. It also learned high-dimensional tasks such as Ant, which posed problems for the purely planning-based PETS. The ablations were as informative:
- Short rollouts suffice. A rollout length fixed at kept much of the benefit, a baseline the authors found "surprisingly difficult to beat". The model was accurate enough for 200-step rollouts, but these trained worse policies, and 500-step rollouts were too inaccurate to learn from.
- No exploitation at short range. Returns predicted by the model tracked real returns closely on Hopper, and across tasks the model tended to underestimate real returns. Short branches give the policy little room to steer into the model's errors.
- The model is not just more updates. Soft actor–critic run with the same high number of gradient updates per environment step, but without model data, sped up only marginally.
MBPO uses short rollouts to make training data. Value expansion uses them to make targets: MVE (Feinberg et al., 2018) imagines only to a fixed depth and bootstraps from a learned value beyond it, and STEVE (Buckman et al., 2018) interpolates between rollout horizons separately for each example, using a horizon only where it does not introduce large errors. M2AC (Pan, He, Tu & He, 2020) instead masks model rollouts, keeping predictions only where the model is confident. When Janner et al. added value expansion to soft actor–critic, a single model step was again a surprisingly effective baseline, as it had been for branched rollouts.
Key takeaways
- Two processes that differ by in dynamics and in policy drift apart linearly in total variation, so their returns differ by .
- MBPO's monotonic-improvement bound needs the model return to beat the old policy by , which at and 1% errors is about 600: vacuous.
- Branched rollouts trade off-policy error (terms in ) against model error (linear in ). With pessimistic generalization the bound prefers ; with measured error it prefers .
- MBPO (short rollouts from buffer states, a probabilistic ensemble, SAC, many updates per step) matched soft actor–critic's final performance with far fewer samples; single-step rollouts were a strong baseline, and REDQ suggests stable high update ratios explain much of the gain.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Taken literally, which rollout length minimizes the penalty in the first branched-rollout bound (Theorem 4.2)?
- : the per-step model term outweighs what longer branches save on off-policy error
- , as in Dyna
- , the effective horizon
- The longest rollout the model can produce
Show the answer
A. : the per-step model term outweighs what longer branches save on off-policy error
Lengthening the branch from to saves in the terms but adds in the linear one, and always, so every extra step makes the bound worse. Replacing that pessimistic cost by the measured error is what makes optimal.
Why does MBPO start its model rollouts from states in the replay buffer rather than from the initial state distribution?
- Replay-buffer states have exact model predictions
- It decouples the rollout length from the task horizon: many short rollouts cover the visited state distribution while each stays short enough to limit compounding error
- The initial state distribution is unknown
- It makes the rollouts on-policy for the data-collecting policy
Show the answer
B. It decouples the rollout length from the task horizon: many short rollouts cover the visited state distribution while each stays short enough to limit compounding error
Starting from the initial states, covering a 1,000-step task needs 1,000-step rollouts, which compound errors badly; earlier methods often shortened the benchmarks instead. Branching from buffer states reaches deep into the task with of 1 to about 15.
Which finding most complicates attributing MBPO's sample efficiency to its learned model?
- Its model returns underestimate real returns
- Its rollouts are only 1 to 15 steps long
- It uses an ensemble of 7 dynamics models
- A model-free agent with a very high update-to-data ratio and an ensemble of Q-functions (REDQ) performed as well as a state-of-the-art model-based method
Show the answer
D. A model-free agent with a very high update-to-data ratio and an ensemble of Q-functions (REDQ) performed as well as a state-of-the-art model-based method
MBPO performs 20–40 gradient updates per real step; REDQ showed that a model-free agent made stable at a similar update ratio can match model-based sample efficiency. The model may contribute mainly by regularizing many updates per sample.
Further reading
- M. Janner, J. Fu, M. Zhang & S. Levine, "When to trust your model: Model-based policy optimization," NeurIPS (2019).
- V. Feinberg, A. Wan, I. Stoica, M. I. Jordan, J. E. Gonzalez & S. Levine, "Model-based value estimation for efficient model-free reinforcement learning," arXiv:1803.00101 (2018).
- J. Buckman, D. Hafner, G. Tucker, E. Brevdo & H. Lee, "Sample-efficient reinforcement learning with stochastic ensemble value expansion," NeurIPS (2018).
- F. Pan, J. He, D. Tu & Q. He, "Trust the model when it is confident: Masked model-based actor-critic," NeurIPS (2020).
- X. Chen, C. Wang, Z. Zhou & K. W. Ross, "Randomized ensembled double Q-learning: Learning fast without a model," ICLR (2021).