forking paths

Spending imagination in RaoDreamer, and what an audit of 248 agents overturned.

Update, October 2026: This note was originally written as an argument for branching at the root of an imagined trajectory. When we later audited the actor gradient directly, that explanation did not hold up: Rao-Blackwellizing the first imagined action reduces gradient variance by only 1.5%, because almost all of the variance enters downstream through later TD errors. RaoDreamer now replaces every subsequent TD error with its expectation under the world model. The audit and revised estimator are documented below; a related issue observed in the critics of the same Breakout agents is written up in the past is a foreign country.

In model-based reinforcement learning, considerable compute goes into learning latent dynamics, while relatively little attention is paid to how imagination is allocated once the model exists. Under a fixed budget of model transitions, it is not obvious whether an agent should unroll a single trajectory far into the future, evaluate several shallow counterfactuals at the root, or combine the two.

Dreamer learns a latent transition model of its environment and trains an actor-critic entirely on trajectories unrolled inside that latent space. When the actor πθ(a∣z) is discrete, the action-dependent part of the imagined policy gradient at a latent root state z has the score-function form:

g(z) = Σa∈𝒜 πθ(a∣z) Y(z,a) ∇θ log πθ(a∣z)

Here Y(z,a) is Dreamer’s stop-gradient, long-horizon advantage coefficient. Standard discrete Dreamer estimates this sum by sampling a single action from πθ and unrolling one trajectory, relying on batch averaging to absorb the noise. This keeps rollouts inexpensive, though it retains the full variance of discrete action selection at the root.

The initial hypothesis for RaoDreamer was that this root variance could be reduced without changing the expected objective. Rather than committing immediately to a single root action, RaoDreamer evaluates a weighted bank of counterfactual actions branching from the same latent state:

ℬ(z) = {(ai,wi)}i=1B

The bank is constructed so that its weighted expectation matches the exact policy expectation. To leave the downstream rollout distribution identical to standard Dreamer, a single branch I∼Categorical(w) is sampled and unrolled to full horizon H as usual. The marginal distribution of long-horizon trajectories is therefore unchanged.

Instead of discarding the remaining B − 1 branches, or paying to unroll all of them to depth H, we evaluate them at a short horizon and use them to form a control variate:

ĝRao = YIsI + β [Σi=1B wiCisi − CIsI]

Because the expected difference between the full bank and the sampled branch is zero when conditioned on the bank,

𝔼I[ΣiwiCisi − CIsI ∣ ℬ] = 0

this estimator preserves Dreamer’s exact expected pre-optimizer actor gradient while removing root action-selection variance. The short-horizon control Ci does not need to be an unbiased estimate of the true return; any bias in Ci cancels in expectation and affects only the amount of variance reduction achieved. Setting B = 1 causes the bracketed correction to vanish and recovers standard Dreamer directly. In principle, this provides a way to trade off action breadth, trajectory depth, and root diversity within a fixed compute budget.

first results

12 paired training seeds; 100 evaluation episodes per policy at 1M frames.
metric Dreamer Rao B=4 paired / relative
mean score8.9711.41+2.44
paired mediann/an/a+1.52
paired wins3/129/12n/a
paired-effect SDn/an/a4.80
95% intervaln/an/a[−0.62, +5.49]
preregistered two-sided pn/an/a0.107
logical transitions1.00×1.20×+20%
wall time / policy1.73 h1.85 h+6.9%
Paired Dreamer and Rao B=4 Pong scores for twelve training seeds, alongside ordered paired effects
Fresh 1M-frame policies by paired training seed.
Mean online Pong learning curves for Dreamer and Rao B=4 across twelve paired training seeds
Fresh 12-seed learning curves, mean ± SEM.

Across twelve paired seeds in Pong, B = 4 won 9 of 12 pairs and increased the mean score by 2.44 points for a 6.9% increase in wall time. At that point it was tempting to treat the result as evidence for shallow counterfactual breadth. Even so, the setup felt somewhat ad hoc: the model was not deciding how to allocate its imagination, and we were hardcoding where to branch and where to truncate. Before attempting to let an actor-critic allocate its own imagination budget, we needed to check whether the root control variate was actually reducing variance as intended.

every TD error

An estimator that looks tidy in derivation and wins nine of twelve seeds at p = 0.107 is easy to trust prematurely. Once we stopped looking only at Pong returns and measured the variance of the actor gradient directly, the root-branching explanation failed. Dreamer’s advantage weight at step t is not a local quantity; it is an exponentially weighted sum of temporal-difference errors over the full imagined horizon:

Gλt:H − v̂(St) = Σk=tH−1 Γt,k δk,    Γt,k = Πi=t+1k λγi

Each score term at step t is multiplied by the compounded stochasticity of every transition and action sampled at steps k > t. Most of the actor gradient is noise, and comparing counterfactual actions at the first step removes only 1.5% of it. The Pong improvement above is not strong evidence for shallow root breadth; it is consistent with noise.

Because the variance enters through the entire chain of future TD errors, the estimator has to address that chain rather than the root alone. The revised RaoDreamer therefore Rao-Blackwellizes the full λ-return (RB-λ). At the credited step t, we sum explicitly over the discrete action space; at each subsequent step k > t along the trajectory, we replace the sampled TD error δk with its conditional expectation under the world model, estimated using K latent states drawn from the transition prior (𝔼K):

ĝRB ∝ Σt ωt [ Σa 𝔼K[δt∣St,a] ∇π(a∣St) + ∇log π(At∣St) Σk>t Γt,k 𝔼K[δk∣Sk] ]

Since the difference between the Rao-Blackwellized gradient and the raw sample gradient has zero expectation, we can interpolate between them with any batch-independent scalar β without introducing bias:

ĝβ = ĝ + β(ĝRB − ĝ),    𝔼[ĝβ] = 𝔼[ĝ]

Setting β = 0 recovers standard Dreamer, while β = 1 gives pure RB-λ. Although β = 1 is unbiased in expectation, the variance-minimizing β depends on how the correction covaries with the raw gradient, so β = 1 does not automatically guarantee lower variance. Sharing forward passes across actions and prior samples puts the full RB-λ update at roughly three to six times the compute cost of a standard Dreamer step.

Policy-gradient variance relative to Dreamer, K = 4; lower is better. Geometric mean and 95% interval over trained agents; held-out: β chosen per agent on other batches (exploratory).
environment agents β = 1 held-out median β
Breakout960.61 [0.60, 0.63]0.550.73
Pong240.77 [0.76, 0.78]0.760.80
Space Invaders320.84 [0.80, 0.88]0.720.60
Seaquest320.88 [0.80, 0.96]0.640.57
Asterix321.00 [0.85, 1.17]0.690.56
Freeway321.92 [1.71, 2.16]0.760.30

Auditing 248 trained agents across six games at K = 4 gave a more mixed result than a uniform reduction in variance. Fixing β = 1 lowers policy-gradient variance substantially in four of the six environments (to 0.61× in Breakout and 0.77× in Pong), leaves Asterix roughly unchanged, and increases variance to 1.92× in Freeway. Empirical zero-bias tests passed in Breakout and Pong, whereas more agents failed the bias check in the other four games than chance alone would explain. However, when β is chosen per agent on held-out batches rather than fixed at 1, variance falls below Dreamer’s for every audited agent (including Freeway, where the median held-out value is around β = 0.30), and K = 1 retains most of that reduction at lower cost.

Each audited agent’s actor-gradient variance relative to Dreamer, recomputed from its per-batch audit at the chosen β. β = 0 is Dreamer, β = 1 is RB-λ; the held-out view shows each agent’s cross-fitted β (exploratory).

The next step is to estimate the variance-minimizing β online from running batch statistics, set K = 1, and compare those agents against standard Dreamer under equal-FLOP budgets.

the past is a foreign country examines the critic’s side of sixteen of these Breakout agents, where stale replay buffers introduce persistent error into the world model.

The figures are regenerated from retained per-seed evaluations and training time series; the interactive figure recomputes each audited agent’s variance from its retained per-batch audit.