Policies Learned in Imagination › Actor-Critic Learning Inside a Model
World Models HandbookAll chapters Policies Learned in Imagination › Actor-Critic Learning Inside a ModelOne section · Sections in this chapter3 / 10 ↓
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
Once we can generate rollouts, we need a learning signal. The natural choice is actor-critic, because it gives us both a critic that can reason about the tail of the horizon and an actor that can be optimized directly.
Actor-critic is itself a classical idea, and it is helpful to place it in that lineage. In approximate dynamic programming, the value function is the object of interest: policy iteration alternates between evaluating a policy and improving it greedily with respect to the value function. Actor-critic methods combine those two steps into a single loop with two function approximators, one for the value and one for the policy. Inside a learned model, the loop is unchanged in structure, but every state, reward, and transition it uses is synthetic. This is the sense in which imagination-based learning is classical control with a learned simulator swapped in: the algorithm is familiar, the data is not.
Recall from Chapter 6 of Part II that a critic estimates the expected discounted return from a state. Inside imagination, the critic is trained by regression onto multi-step return targets computed from the imaginary rewards. The standard target is the -return, a geometric blend of -step returns that trades bias against variance. Define the temporal-difference residual along the rollout as
where:
- : the temporal-difference residual at step , measuring the surprise of the imagined reward relative to the critic's prediction
- : the imagined reward at step
- : the discount factor
- : the critic's value estimate at the next latent
- : the critic's value estimate at the current latent
with the boundary condition that is the last latent and is the bootstrap value. The -return is then
where:
- : the -return target at step , blending -step returns to balance bias and variance
- : the critic's baseline value estimate at the current latent
- : the blending parameter between one-step and Monte Carlo returns
- : the temporal-difference residual at future step
- : the imagination horizon
which can be computed with a single backward pass over the rollout using the recursion or, more simply, by accumulating an auxiliary variable and returning . The critic loss is the mean squared error between and the detached target:
where:
- : the critic loss as a function of the value-network parameters
- : the expectation over imagined rollouts
- : the number of rollout steps
- : the detached -return target at step
- : the critic's predicted value at the latent state
In this separate critic regression, the target is detached during each update. Other algorithms deliberately differentiate through targets, so detachment is a design choice rather than a universal rule.
Why use a -return rather than only a one-step or full-rollout target? A one-step target relies heavily on the critic's bootstrap and can inherit its bias. A full sampled return avoids intermediate value bootstraps but may have higher sampling variance; in a deterministic model, that variance need not be large. If the rollout ends before the task does, its terminal bootstrap still carries value error. The -return interpolates among these targets. Its useful bias-variance balance depends on critic accuracy, model accuracy, and stochasticity rather than on a universal ordering.
For the actor there are two fundamentally different gradient estimators, and the distinction is one of the most important ideas in this chapter.
The score-function estimator. Also called REINFORCE or the likelihood-ratio estimator, this treats the sampled action as a fixed constant and reweights its log-probability by how good the outcome turned out to be:
where:
- : the gradient of the finite, -step discounted imagined-reward objective
- : sampled discounted reward-to-go from step through the truncated rollout
- : a state-dependent baseline, often the critic, whose expectation against the action score is zero
- : the time weight required by the stated discounted objective
- : the log-probability of the sampled action under the current policy
The likelihood-ratio identity is unbiased for this finite imagined objective when is sampled from the stated rollout distribution and the baseline depends on state, not the sampled action. A practical update may replace with a bootstrapped -return and use as an advantage; with an approximate critic and , that surrogate is generally biased. The estimator works with discrete actions and non-differentiable transitions. Original Dreamer used analytic gradients through latent dynamics; DreamerV3 uses a REINFORCE-style actor update.
For one sampled action, the score is weighted by how far its return lies above or below the baseline. The magnitude matters, but the estimator does not observe the derivative of reward with respect to an untried nearby action. Sampling supplies that information indirectly. A critic baseline reduces variance by subtracting predictable state value without changing the exact score identity.
The pathwise estimator. Also called the analytic or reparameterized gradient, this differentiates directly through the reward and dynamics:
Here and are total derivatives through all earlier sampled actions and transitions. If the actor objective includes a terminal bootstrap, its derivative must be included too. On a smooth reparameterized model, pathwise gradients often have lower variance than score-function gradients, though long Jacobian products can be unstable. They estimate the gradient of the imagined objective without requiring the model to be correct; model accuracy is needed to identify that gradient with the real-environment gradient. Discrete or discontinuous models may require a relaxation, straight-through estimator, or score-function route.
The score-function estimator uses sampled outcomes; the pathwise estimator additionally uses local model derivatives. Those derivatives can provide efficient credit assignment, but can also be misleading outside the training distribution. Neither estimator removes model bias. Their relative variance and learning speed depend on the model, horizon, policy, and optimizer.
The two can also be mixed, but their weights and bootstrap treatment define the actual objective. A REINFORCE-style bootstrapped actor surrogate, as used in later Dreamer variants, is:
The entropy coefficient can discourage premature concentration. Its effect depends on reward and gradient scales. The toy actor below has a learned global log-standard-deviation, so it cannot modulate exploration by state. Its optional actor.dist(s).entropy() term measures the pre-squash Normal's entropy, a surrogate regularizer rather than the entropy of bounded actions after . The plotted experiments set to isolate the two gradient routes.
At exactly zero variance, a point-mass policy has no ordinary log-density score; very small variance can make score estimates ill-conditioned and leave too little exploration. Entropy can prevent premature concentration, but stochasticity does not by itself protect against model exploitation.
Two possible stability tools are target critics and return normalization. A slowly updated target critic can reduce target movement; a return scale estimated independently of the current actor batch can moderate gradient magnitude across reward scales. They are not universal requirements. Our toy implementation instead uses a fixed reward scale, bounded actions, a conservative learning rate, and gradient clipping; its exact score-function branch does not normalize the sampled advantage.
Bootstrapping with function approximation can destabilize value learning, especially with off-policy data. Target networks can damp one feedback loop, while scaling changes optimizer step sizes. Neither proves convergence, and scaling the advantage using statistics of the same sampled actions can change the exact score-gradient estimator. The code below keeps that distinction visible.
Finally, note what the actor is not doing. It is not maximizing the true return. The objective is
where:
- : the imagined return objective as a function of policy parameters
- : the expectation taken under the learned model and the current policy
- : the discount factor
- : the model's reward prediction at latent state and action
an expectation under the model. Everything that follows is about the gap between and the real .
It is worth stating the mismatch in the sharpest possible terms. The world model is trained to predict observations, rewards, and transitions, which is a prediction objective. The actor is trained to maximize return under the model, which is a control objective. These two objectives are not the same, and nothing in the training procedure guarantees that the model's predictions are accurate on the states the actor will visit. This is sometimes called objective mismatch, and it is the structural reason that improving the model's average prediction error does not automatically improve the policy. A model can become better at predicting the data it was trained on while becoming worse as a training environment, if the improvement comes from fitting incidental structure that the policy then exploits.