Skip to content
AI360Xpert
Beta

Model-Based Policy Optimization (MBPO)

MBPO trains a policy mostly on short imagined rollouts that start from real states, so model errors stay small while real environment steps stay few.

MBPO seeds a 2 step imagined rollout from a real state and caps the error bound at 10, while a 20 step rollout from the same model reaches 100
MBPO seeds a 2 step imagined rollout from a real state and caps the error bound at 10, while a 20 step rollout from the same model reaches 100

Why Does This Exist?

Model free methods such as Soft Actor-Critic reach strong final performance but need millions of real environment steps. On a physical robot that cost is paid in hours, hardware wear, and broken parts. Model based methods answer by learning a simulator and training inside it, yet long imagined trajectories drift: each predicted step feeds its own small error into the next one, and after hundreds of steps the policy is optimizing hallucinated rewards. That failure is called model exploitation.

MBPO, introduced by Janner et al. in 2019, keeps the sample savings of a learned model while bounding that drift. The trick is to never roll out far. Every imagined trajectory is a short branch of length kk, usually 1 to 5 steps, that starts from a real state already seen in the environment. Short branches keep the compounding error term linear in kk instead of quadratic in the horizon, and a mixed replay buffer keeps gradients grounded in reality. This page covers that mechanism and its worked numbers. The broader family is in model-based deep RL, and the imagination machinery it builds on is in Dreamer.

The one idea you need first

A dynamics model p^(st+1,rt∣st,at)\hat{p}(s_{t+1}, r_t \mid s_t, a_t) predicts the next state and reward from the current state sts_t and action ata_t. MBPO learns several of them as an ensemble, and the disagreement between members measures how uncertain the model is. When members agree, the prediction is trustworthy. When they disagree, the branch stops.

Think of It Like This

Rehearsing two dance steps from a real spot on the floor

You are learning a long dance routine. Rehearsing the whole five minute piece in your head from the start is hopeless: one misremembered turn shifts every step after it, and by the end you are rehearsing a routine nobody choreographed.

So you rehearse differently. You walk to a real mark on the studio floor where you have actually stood, then picture only the next two steps from there. Two steps is short enough that your memory is nearly exact. You repeat this from dozens of real marks, polish each fragment, and check yourself against the music every few minutes.

MBPO trains a policy the same way. Real states are the marks on the floor. Short imagined branches are the two step rehearsals. The ensemble disagreement check is noticing you are unsure of a step and stopping instead of rehearsing it wrong.

Where it stops: a dancer generalizes across fragments from experience, while MBPO stores every imagined step in a buffer and runs gradient updates on it, which is bookkeeping no dancer does.

How It Actually Works

Three parts work together: an ensemble of probabilistic dynamics models, branched rollout generation, and a mixed replay buffer feeding an off policy optimizer.

1. Ensemble of probabilistic dynamics models

MBPO trains BB neural networks, typically 7, each predicting a Gaussian over the next state change and reward:

p^θi(st+1,rt∣st,at)=N(μθi(st,at),Σθi(st,at))\hat{p}_{\theta_i}(s_{t+1}, r_t \mid s_t, a_t) = \mathcal{N}(\mu_{\theta_i}(s_t, a_t), \Sigma_{\theta_i}(s_t, a_t))

Here μ\mu is the predicted mean and Σ\Sigma is the predicted spread. The spread of one member captures the randomness of the environment itself. The disagreement across the BB members captures the model's own ignorance: large disagreement means this region is far from the training data.

2. Branched rollouts from real states

Each iteration samples a batch of real states s0s_0 from the environment buffer Denv\mathcal{D}_{\text{env}}, then simulates kk steps with the current policy π\pi. At every imagined step one ensemble member is picked at random to predict the outcome, and the transition is stored in a model buffer Dmodel\mathcal{D}_{\text{model}}. If ensemble disagreement passes a threshold, the branch ends early.

3. Mixed batches for the optimizer

Policy and value updates draw about 95 percent of each mini batch from Dmodel\mathcal{D}_{\text{model}} and 5 percent from Denv\mathcal{D}_{\text{env}}. The imagined majority supplies the sample efficiency. The real minority keeps the optimizer anchored to the physical world.

Why short branches bound the error

Let ϵmodel\epsilon_{\text{model}} be the single step model error and γ\gamma the discount factor. Under branched rollouts the compounding part of the return discrepancy bound grows as

error(k)=k ϵmodel1−γ\text{error}(k) = \frac{k \, \epsilon_{\text{model}}}{1 - \gamma}

which is linear in kk. Long rollouts from a start state pay a factor near 1/(1−γ)21/(1 - \gamma)^2 instead, which at γ=0.99\gamma = 0.99 multiplies errors by about 10,000.

Worked example

Seed a branch with ϵmodel=0.05\epsilon_{\text{model}} = 0.05, γ=0.99\gamma = 0.99, and horizon k=2k = 2:

Seed from the real buffer: s0=[1.00,0.50]s_0 = [1.00, 0.50]. The policy outputs a0=0.20a_0 = 0.20. The ensemble mean predicts s^1=[1.15,0.45]\hat{s}_1 = [1.15, 0.45] with reward r^0=1.20\hat{r}_0 = 1.20, and member disagreement sits far below the safety threshold, so the transition (s0,a0,r^0,s^1)(s_0, a_0, \hat{r}_0, \hat{s}_1) enters Dmodel\mathcal{D}_{\text{model}}.

From s^1\hat{s}_1 the policy outputs a1=0.40a_1 = 0.40. The ensemble predicts s^2=[1.32,0.38]\hat{s}_2 = [1.32, 0.38] with reward r^1=1.50\hat{r}_1 = 1.50, again with low disagreement, and the second transition is stored. The branch ends because k=2k = 2 is reached.

Now the bounds. Since 1−γ=0.011 - \gamma = 0.01:

error(1)=1×0.050.01=5.00,error(2)=2×0.050.01=10.00,error(20)=20×0.050.01=100.00\text{error}(1) = \frac{1 \times 0.05}{0.01} = 5.00, \quad \text{error}(2) = \frac{2 \times 0.05}{0.01} = 10.00, \quad \text{error}(20) = \frac{20 \times 0.05}{0.01} = 100.00

Keeping kk at 2 holds the bound at 10.00 instead of 100.00, a 90 percent reduction, which is why the policy gradients stay trustworthy.

Code

This snippet computes the bound for several horizons and runs the same 2 step branch as the worked example, so you can check the arithmetic yourself.

def branch_error(k: int, eps: float = 0.05, gamma: float = 0.99) -> float:    return (k * eps) / (1.0 - gamma)

states = [[1.00, 0.50], [1.15, 0.45], [1.32, 0.38]]rewards = [1.20, 1.50]
print(round(branch_error(1), 2))    # -> 5.0print(round(branch_error(2), 2))    # -> 10.0print(round(branch_error(20), 2))   # -> 100.0print(states[1])                    # -> [1.15, 0.45]print(sum(rewards))                 # -> 2.7

The imagined return over the branch is 1.20+1.50=2.701.20 + 1.50 = 2.70, and the bound at k=2k = 2 reads 10.0 against 100.0 for a 20 step rollout from the same model.

Watch Out For

Raising the rollout horizon before the model is ready

The classic MBPO failure is setting k=10k = 10 or higher in the first epochs. Early on the ensemble has seen little data, so step 5 predictions already leave the training manifold. The policy then exploits phantom transitions that pay well in imagination and fail on the robot.

Symptom: model buffer returns climb while real evaluation returns flatline or fall. Fix: start at k=1k = 1, watch ensemble validation loss and disagreement, and lengthen kk only as both stabilize. End any single branch the moment member disagreement crosses your threshold.

Training on imagination alone

If mini batches draw 100 percent from Dmodel\mathcal{D}_{\text{model}}, small systematic biases in the ensemble become the whole training signal and the policy drifts with them.

Symptom: smooth improvement in imagined returns with sudden collapse on the real environment after each model retrain. Fix: keep the real fraction, around 5 percent in the original work, and resample real seeds for every round of branches so imagination never floats free of data.

The Quick Version

  • MBPO trains mostly on short imagined branches of 1 to 5 steps, each seeded from a real environment state.
  • Short branches make compounding model error grow linearly in kk, replacing the near quadratic blowup of long rollouts.
  • An ensemble of probabilistic dynamics models supplies predictions plus a disagreement signal that ends shaky branches early.
  • Mini batches mix about 95 percent imagined transitions with 5 percent real ones, pairing sample efficiency with grounding.
  • At single step error 0.05 and discount 0.99, the bound reads 5.00 for k=1k = 1, 10.00 for k=2k = 2, and 100.00 for k=20k = 20.