Implicit Diffusion: Efficient optimization through stochastic sampling

Pierre Marion, Anna Korba, Peter Bartlett, Mathieu Blondel, Valentin De Bortoli, Arnaud Doucet, Felipe Llinares-López, Courtney Paquette, Quentin Berthet

Abstract

Sampling and automatic differentiation are both ubiquitous in modern machine learning. At its intersection, differentiating through a sampling operation, with respect to the parameters of the sampling process, is a problem that is both challenging and broadly applicable. We introduce a general framework and a new algorithm for first-order optimization of parameterized stochastic diffusions, performing jointly, in a single loop, optimization and sampling steps. This approach is inspired by recent advances in bilevel optimization and automatic implicit differentiation, leveraging the point of view of sampling as optimization over the space of probability distributions. We provide theoretical and experimental results showcasing the performance of our method.

Introduction

In modern machine learning, we often need to differentiate through a sampling operation. For example, if you have a diffusion model, you might want to "finetune" its weights so that the images it generates maximize a specific reward, such as aesthetic quality or brightness.

The standard approach is a "nested loop": you run the full sampling process (which might take hundreds of steps), calculate the reward, and then backpropagate through the entire chain. This is incredibly slow and memory-intensive, often requiring "unrolling" the chain in memory. Alternatively, one might use Reinforcement Learning (RL) or adjoint methods, but these often struggle with high-dimensional parameter spaces or non-differentiable rewards. The authors identify a gap: we lack a general, efficient first-order optimization method for these implicitly parameterized distributions.

Methods: Sampling as Optimization

The core idea of Implicit Diffusion is to view sampling as optimization over the space of probability distributions. This allows the authors to borrow techniques from bilevel optimization, treating sampling as the "inner" problem and parameter tuning as the "outer" problem.

Implicit Gradient Estimation

Instead of a closed-form gradient, they define a function $\Gamma$ that provides an estimate of the gradient of the loss with respect to the parameters $\theta$. They derive specific versions of $\Gamma$ for Langevin dynamics (using a REINFORCE-like covariance trick) and denoising diffusion (using the differential adjoint method).

Single-Loop Optimization and the Queuing Trick

Unlike the "nested loop" baseline, their algorithm performs one sampling step and one parameter update step jointly in a single loop. This reduces the complexity from $O(K \times T)$ to $O(K)$, where $K$ is the number of optimization steps and $T$ is the sampling chain length.

For finite-time processes like denoising diffusion, they use a parallelized queue. This allows the model to maintain a "pipeline" of samples at different stages of the diffusion process, ensuring that the parameter $\theta$ receives a gradient signal at every step without waiting for a full image to be generated. Theoretically, they show that by making the parameter updates move slower than the sampling updates (two-timescale dynamics), the system converges to a stationary point.

Experimental Results

The authors evaluated their method on several standard generative modeling benchmarks, demonstrating successful distribution shifting for specific rewards.

MNIST and CIFAR-10 Finetuning

On the MNIST dataset, the reward was "average brightness." The method successfully produced "brighter" digits that were thicker and bolder while still looking like digits. On CIFAR-10, the model was optimized for "redness" (maximizing the red channel), successfully shifting the color distribution of natural images.

Optimization of MNIST digits for brightness. The central image represents the base model, while the left and right images show the effects of negative and positive brightness gradients respectively.
Finetuning CIFAR-10 images for redness. The model successfully shifts the color distribution while preserving object identity.

Performance and Convergence

In Langevin experiments, Implicit Diffusion reached target log-likelihood thresholds significantly faster than nested-loop or unrolling baselines. For a given number of gradient evaluations, it consistently outperformed competitors. The authors also provide the first convergence rates for this type of single-loop optimization in the context of Langevin diffusions, showing a rate of $O(K^{-1/3})$ for the average gradient.

Key Insights and Discussion

The "aha moment" of the paper is that for a fixed computational budget, it is better to take many small, noisy steps (single-loop) than a few very accurate, expensive steps (nested-loop). Furthermore, for Langevin processes, the derivation shows that you can optimize a reward even if it's a discrete "black box" (like an indicator function), because the gradient depends on the covariance between the reward and the score function, not the reward's derivative.

Limitations

Despite its efficiency, the method has limitations:

  • Hyperparameter Sensitivity: Performance is sensitive to the choice of learning rates and the ratio between "inner" and "outer" step sizes.
  • Mode Collapse: In extreme reward scenarios, the model can lose the diversity of the original dataset to chase the reward.
  • Bias: The gradient estimates are inherently biased because they use samples from a distribution that hasn't fully converged yet.

Conclusion

Implicit Diffusion offers a robust framework for efficiently optimizing parameterized stochastic diffusions. By leveraging implicit differentiation and single-loop dynamics, it bypasses the memory and computational bottlenecks of traditional unrolling methods, opening new doors for finetuning large-scale generative models.

Summary updated

BibTeX
@inproceedings{marion2025implicit,
  author = {Pierre Marion and Anna Korba and Peter Bartlett and Mathieu Blondel and Valentin De Bortoli and Arnaud Doucet and Felipe Llinares-López and Courtney Paquette and Quentin Berthet},
  title = {{Implicit Diffusion: Efficient optimization through stochastic sampling}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2025},
  url = {https://openreview.net/forum?id=r5F7Z8s0Qk},
}
Figure