Temporal Difference Flows


Abstract

Predictive models of the future are fundamental for an agent's ability to reason and plan. A common strategy learns a world model and unrolls it step-by-step at inference, where small errors can rapidly compound. Geometric Horizon Models (GHMs) offer a compelling alternative by directly making predictions of future states, avoiding cumulative inference errors. While GHMs can be conveniently learned by a generative analog to temporal difference (TD) learning, existing methods are negatively affected by bootstrapping predictions at train time and struggle to generate high-quality predictions at long horizons. This paper introduces Temporal Difference Flows (TD-Flow), which leverages the structure of a novel Bellman equation on probability paths alongside flow-matching techniques to learn accurate GHMs at over 5× the horizon length of prior methods. Theoretically, we establish a new convergence result and primarily attribute TD-Flow's efficacy to reduced gradient variance during training. We further show that similar arguments can be extended to diffusion-based methods. Empirically, we validate TD-Flow across a diverse set of domains on both generative metrics and downstream tasks including policy evaluation. Moreover, integrating TD-Flow with recent behavior foundation models for planning over pre-trained policies demonstrates substantial performance gains, underscoring its promise for long-horizon decision-making.


ICML 2025
Oral Presentation

Motivation

World models enable agents to reason and plan by simulating future states, but standard one-step dynamics models must be unrolled sequentially at inference time—causing small single-step inaccuracies to compound rapidly over long horizons.

Geometric Horizon Models (GHMs), or γ\gamma-models, sidestep inference-time compounding error by directly learning a generative model of a policy’s normalized successor measure mπ(⋅∣s,a)m^\pi(\cdot \mid s, a), the γ\gamma-discounted distribution of future states visited by π\pi:

mπ(X∣s,a)=(1−γ)∑k=0∞γkPr⁡(Sk+1∈X∣S0=s,A0=a,π).m^\pi(X \mid s, a) = (1 - \gamma)\sum_{k=0}^{\infty} \gamma^k \Pr(S_{k+1} \in X \mid S_0 = s, A_0 = a, \pi).

Because mπm^\pi satisfies the off-policy Bellman equation mπ=Tπmπ:=(1−γ)P+γPπmπm^\pi = \mathcal{T}^\pi m^\pi := (1 - \gamma)P + \gamma P^\pi m^\pi and maps any reward function rr to action-values via Qπ(s,a)=(1−γ)−1EX∼mπ(⋅∣s,a)[r(X)]Q^\pi(s, a) = (1 - \gamma)^{-1}\mathbb{E}_{X \sim m^\pi(\cdot \mid s, a)}[r(X)], GHMs can be trained off-policy with temporal-difference (TD) bootstrapping. In practice, however, naive generative TD methods (GANs, VAEs, and standard flow or diffusion models) suffer from bootstrapping instability and high gradient variance, breaking down beyond horizons of 20–50 steps.

Method

Flow Matching constructs a time-dependent probability path mt(⋅∣s,a)m_t(\cdot \mid s, a) for t∈[0,1]t \in [0, 1] transporting a simple prior m0=p0m_0 = p_0 to the target distribution m1≈mπm_1 \approx m^\pi via a neural ODE ddtψt(x∣s,a)=v~t(ψt(x∣s,a)∣s,a;θ)\frac{\mathrm{d}}{\mathrm{d}t}\psi_t(x \mid s, a) = \tilde{v}_t(\psi_t(x \mid s, a) \mid s, a; \theta). To learn v~t\tilde{v}_t off-policy from one-step transitions (S,A,S′)∼ρ(S, A, S') \sim \rho, we introduce three progressively more structured TD-Flow algorithms:

  1. TD-CFM: Draws a bootstrapped endpoint X1∼(1−γ)δS′+γδψ~1(n)(X0∣S′,π(S′))X_1 \sim (1 - \gamma)\delta_{S'} + \gamma \delta_{\tilde{\psi}_1^{(n)}(X_0 \mid S', \pi(S'))} and constructs a fresh conditional path Xt∼pt∣1(⋅∣X1)X_t \sim p_{t|1}(\cdot \mid X_1). Re-sampling independent noise discards the ODE correspondence and creates crossing paths.
  2. Coupled TD-CFM (TD-CFM(C)\text{TD-CFM(C)}): Preserves the natural endpoint coupling Z=(X0,X1)Z = (X_0, X_1) between the initial noise X0X_0 and its bootstrapped ODE sample X1X_1, interpolating directly along Xt=αtX1+βtX0X_t = \alpha_t X_1 + \beta_t X_0 to align conditional paths and lower transport cost.
  3. TD2\text{TD}^2-CFM: Exploits the linearity of the Bellman operator to decompose the target probability path into two separate flows—a standard conditional flow-matching term on one-step transitions S′S' and a bootstrapped velocity term that integrates the target ODE only up to time tt (X^t=ψ~t(n)(X0∣S′,π(S′))\widehat{X}_t = \tilde{\psi}_t^{(n)}(X_0 \mid S', \pi(S'))) and regresses directly onto the target velocity field v~t(n)\tilde{v}_t^{(n)}:
ℓTD2-CFM(θ)=(1−γ)E ⁣[∥v~t(X⃗t∣S,A;θ)−u⃗t∣1(X⃗t∣S′)∥2]+γE ⁣[∥v~t(X^t∣S,A;θ)−v~t(n)(X^t∣S′,π(S′))∥2].\begin{aligned} \ell_{\text{TD}^2\text{-CFM}}(\theta) &= (1 - \gamma)\mathbb{E}\!\left[\|\tilde{v}_t(\vec{X}_t \mid S, A; \theta) - \vec{u}_{t|1}(\vec{X}_t \mid S')\|^2\right] \\ &\quad + \gamma\mathbb{E}\!\left[\|\tilde{v}_t(\widehat{X}_t \mid S, A; \theta) - \tilde{v}_t^{(n)}(\widehat{X}_t \mid S', \pi(S'))\|^2\right]. \end{aligned}
Visual comparison of TD-CFM, Coupled TD-CFM, and TD2-CFM illustrating ODE trajectories, conditional paths, endpoint coupling, and direct target velocity bootstrapping

Figure 1. Visual depiction of TD-Flow variants. Dashed lines show the neural ODE trajectory and solid lines show conditional probability paths. TD-CFM creates crossing paths by resampling noise; Coupled TD-CFM aligns the endpoints (X₀, X₁); TD²-CFM solves the ODE up to time t to regress directly onto the target velocity field.

Extension to Denoising Diffusion (TD2\text{TD}^2-DD). Using the Fokker-Planck equation for mixtures of diffusion processes, the same TD2\text{TD}^2 principle extends directly to score-based diffusion models: one-step transitions use the standard denoising score-matching target, while bootstrapped transitions regress directly onto the target network’s score (or noise) prediction along the reverse SDE trajectory.

Convergence and Variance Reduction

Theoretical analysis explains both why TD-Flow converges and why TD2\text{TD}^2-CFM dramatically outperforms naive bootstrapping at long horizons:

  • Bellman operator on probability paths: At every flow time t∈[0,1]t \in [0, 1], TD-CFM, TD-CFM(C), and TD2\text{TD}^2-CFM all implement the update mt(n+1)=Btπmt(n):=(1−γ)Pt+γPπmt(n)m_t^{(n+1)} = \mathcal{B}_t^\pi m_t^{(n)} := (1 - \gamma)P_t + \gamma P^\pi m_t^{(n)}, where Pt(⋅∣s,a)=∫pt∣1(⋅∣x1)P(dx1∣s,a)P_t(\cdot \mid s, a) = \int p_{t|1}(\cdot \mid x_1)P(\mathrm{d}x_1 \mid s, a). Btπ\mathcal{B}_t^\pi is a γ\gamma-contraction in 11-Wasserstein distance whose unique fixed point matches the Monte-Carlo Conditional Flow Matching path.
  • Reduced gradient variance: Comparing unbiased sample-based gradient estimators shows that TD-CFM and TD-CFM(C) incur an additional computational variance term proportional to γ2\gamma^2 relative to TD2\text{TD}^2-CFM—growing sharply as γ→1\gamma \to 1. With non-intersecting straight conditional paths, TD-CFM(C) matches TD2\text{TD}^2-CFM’s variance, whereas on curved paths TD-CFM(C) incurs extra variance while TD2\text{TD}^2-CFM remains unaffected.

Key Results

We benchmark TD-Flow and TD-Diffusion variants against modern relativistic GAN and β\beta-VAE baselines on 10M off-policy ExoRL transitions spanning 22 tasks across four DeepMind Control Suite domains (Pointmass Maze, Walker, Cheetah, and Quadruped).

Horizon Scaling and Single-Policy Evaluation

Evaluating effective horizons (1−γ)−1∈{5,10,20,50,100}(1 - \gamma)^{-1} \in \{5, 10, 20, 50, 100\} on the Pointmass Loop task confirms our variance analysis: while TD-VAE, TD-GAN, TD-DD, and vanilla TD-CFM deteriorate rapidly as the horizon grows, TD2\text{TD}^2-CFM and TD2\text{TD}^2-DD remain stable—improving value-function MSE by nearly four orders of magnitude at horizon 100.

Log-scale plot of Value Function MSE versus effective horizon from 5 to 100 on Pointmass Loop comparing TD-DD, TD-VAE, TD-GAN, TD-CFM, TD-CFM(C), TD2-DD, and TD2-CFM

Figure 2. Scaling effective horizon on Pointmass Loop. Value-function prediction MSE across effective horizons from 5 to 100 (γ from 0.8 to 0.99). Both TD²-CFM and TD²-DD stay robust out to effective horizon 100, outperforming naive baselines by nearly four orders of magnitude.

Across all four domains at γ=0.99\gamma = 0.99 (horizon 100), TD2\text{TD}^2-CFM achieves a 10×10\times reduction in value-function MSE, 1.5×1.5\times reduction in Earth Mover’s Distance, and 3×3\times improvement in normalized negative log-likelihood relative to TD-CFM. Consistent with theory, TD-CFM(C) performs comparably with straight linear paths but degrades substantially when switched to curved sinusoidal paths, whereas TD2\text{TD}^2-CFM preserves—and slightly improves—its accuracy.

Planning via Generalized Policy Improvement

To test downstream long-horizon decision-making, we train policy-conditioned GHMs mπwm^{\pi_w} over reward embeddings w∈Sd−1(d)w \in \mathbb{S}^{d-1}(\sqrt{d}) learned by a pre-trained Forward-Backward (FB) behavior foundation model. At test time, we perform Generalized Policy Improvement (GPI) by evaluating 256 candidate policies with samples from mπwm^{\pi_w}:

wt∈arg⁡max⁡w∼D(W)(1−γ)−1EX∼mπw(⋅∣st,πw(st))[r(X)].w_t \in \arg\max_{w \sim D(\mathsf{W})} (1 - \gamma)^{-1} \mathbb{E}_{X \sim m^{\pi_w}(\cdot \mid s_t, \pi_w(s_t))}[r(X)].
Bar chart showing percentage return improvement over zero-shot Forward-Backward policies when planning with Generalized Policy Improvement across Random, Train Distribution, and Local Perturbation sampling

Figure 3. Planning via Generalized Policy Improvement (22 tasks, 4 domains). Coupled TD-CFM and TD²-CFM consistently improve zero-shot FB policies by +29% to +36% across all policy-sampling distributions, whereas FB’s own value-function GPI degrades performance on average.

Across all three embedding-sampling distributions (Random, Train Distribution, and Local Perturbation), flow-based GPI with Coupled TD-CFM and TD2\text{TD}^2-CFM delivers +29%+29\% to +36%+36\% return improvements over zero-shot FB policies with minimal sensitivity to the sampling distribution—whereas FB-GPI degrades performance (-57%, -59%, -38%) due to value-estimation errors over out-of-distribution policies.

Citing

To cite this paper, please use the following reference:

@inproceedings{farebrother25tdflow,
	title        = {Temporal Difference Flows},
	author       = {
		Farebrother, Jesse and Pirotta, Matteo and Tirinzoni, Andrea
		and Munos, Rémi and Lazaric, Alessandro and Touati, Ahmed
	},
	year         = 2025,
	booktitle    = {International Conference on Machine Learning (ICML)},
}