Abstract
Diffusion models have been successful on a range of conditional generation tasks including molecular design and text-to-image generation. However, these achievements have primarily depended on task-specific conditional training or error-prone heuristic approximations. Ideally, a conditional generation method should provide exact samples for a broad range of conditional distributions without requiring task-specific training. To this end, we introduce the Twisted Diffusion Sampler, or TDS. TDS is a sequential Monte Carlo (SMC) algorithm that targets the conditional distributions of diffusion models. The main idea is to use twisting, an SMC technique that enjoys good computational efficiency, to incorporate heuristic approximations without compromising asymptotic exactness. We first find in simulation and on MNIST image inpainting and class-conditional generation tasks that TDS provides a computational statistical trade-off, yielding more accurate approximations with many particles but with empirical improvements over heuristics with as few as two particles. We then turn to motif-scaffolding, a core task in protein design, using a TDS extension to Riemannian diffusion models. On benchmark test cases, TDS allows flexible conditioning criteria and often outperforms the state of the art.
Introduction
Diffusion models are currently the gold standard for generating complex data, from high-resolution images to intricate molecular structures. However, generating samples that satisfy specific constraints—known as conditional sampling—remains a significant challenge. Currently, researchers typically choose between two suboptimal paths: computationally expensive task-specific retraining or the use of guidance heuristics. While popular, these heuristics are often "unqualified approximations" that can introduce artifacts or lead to samples that deviate from the underlying model's true distribution.
To bridge this gap, we present the Twisted Diffusion Sampler (TDS). TDS is a practical, theoretically grounded algorithm that enables mathematically exact conditional sampling from pre-trained diffusion models without requiring retraining. By leveraging Sequential Monte Carlo (SMC) and a technique known as "twisting," TDS provides a flexible framework that converges to the true conditional distribution as computational resources increase.
The Twisted Diffusion Sampler (TDS)
TDS conceptualizes the diffusion process as a sequence of steps solvable via Sequential Monte Carlo. In this framework, the algorithm maintains a set of "particles" (candidate samples). At each time step, these particles are weighted based on how well they satisfy the desired condition.
The Power of Twisting
The core innovation of TDS is the application of "twisting." In standard SMC, particles are often weighted only after they move, which can be inefficient. Twisting uses a guiding function to nudge particles toward high-likelihood regions during the proposal step.
Because the perfect guiding function is analytically intractable, TDS utilizes a clever approximation: it uses the diffusion model's own "denoised" estimate of the final sample ($\hat{x}_\theta$) at each step to estimate the likelihood. Crucially, the SMC weighting process automatically corrects the errors introduced by this approximation. This ensures asymptotic exactness, meaning that as the number of particles ($K$) increases, the sampler is guaranteed to produce samples from the true conditional distribution.
Experimental Evaluation
Image Generation and Inpainting
The authors evaluated TDS on standard image benchmarks, including MNIST, CIFAR-10, and ImageNet (256x256). In class-conditional generation and inpainting tasks, TDS produced samples that were more authentic and free of the artifacts typically associated with standard gradient guidance. Even with as few as two particles, the method showed empirical improvements over traditional heuristics.
Protein Design and Motif-Scaffolding
A significant contribution of this work is the extension of TDS to Riemannian manifolds, which is essential for modeling the 3D rotations and translations of protein backbones. The authors tested TDS on a benchmark of 24 "motif-scaffolding" problems—tasks where a stable protein scaffold must be built around a specific functional structure (the motif).
Despite using a base model not specifically trained for this task, TDS achieved success rates comparable to or better than RFdiffusion, the current state-of-the-art model designed specifically for motif-scaffolding. TDS proved particularly effective for smaller protein scaffolds (under 100 residues) and demonstrated unique flexibility in handling "degrees of freedom," such as cases where the motif's exact location within the sequence is unknown.
Key Insights
- Computational-Statistical Trade-off: TDS allows users to trade compute for accuracy. Unlike fixed heuristics, increasing the particle count directly improves the fidelity of the samples to the conditional distribution.
- Denoising as Guidance: The research demonstrates that a diffusion model’s internal ability to predict a clean image from noise is a powerful tool for guiding the sampling process.
- Mathematical Rigor: By providing an asymptotically exact method, TDS moves conditional generation away from "hacks" and toward a mathematically rigorous foundation.
Limitations and Future Directions
While powerful, TDS is more computationally demanding than simple guidance heuristics, as its cost scales linearly with the number of particles and requires backpropagation through the network at each step. Future work will focus on developing more efficient twisting functions and improved resampling strategies to reduce the particle count required for high-dimensional tasks. Additionally, the "twist scale" hyperparameter currently requires manual tuning, representing an opportunity for further automation in the sampling pipeline.
Summary updated