Ancestral sampling is the step-by-step generative procedure in a Denoising Diffusion Probabilistic Model (DDPM). Starting from pure Gaussian noise, the model applies a learned reverse process over multiple timesteps. At each step, it predicts and removes a portion of the noise, while also injecting a small, stochastic amount of new noise defined by the model's fixed variance schedule. This process follows the exact reverse of the Markov chain defined during training.
Glossary
Ancestral Sampling

What is Ancestral Sampling?
Ancestral sampling is the standard stochastic sampling procedure used in diffusion models to generate new data by iteratively denoising pure noise.
This method is called 'ancestral' because each new sample is directly descended from the previous one in the chain. The injected noise at each step is crucial, as it ensures the sampling trajectory explores the full probabilistic distribution learned by the model, rather than taking a deterministic path. While accurate, this iterative nature makes ancestral sampling computationally intensive compared to newer, faster samplers like DDIM or Consistency Models.
Key Characteristics of Ancestral Sampling
Ancestral sampling is the fundamental stochastic procedure for generating data from a trained diffusion model. It follows the learned reverse Markov chain, step-by-step, to denoise a sample of pure Gaussian noise into a coherent data point.
Stochastic, Stepwise Denoising
Ancestral sampling is an iterative process where each step is inherently stochastic. Starting from pure noise x_T ~ N(0, I), the model predicts a slightly denoised sample x_{t-1}. Crucially, this prediction is not deterministic; a new, small amount of Gaussian noise is added at each step according to the learned reverse process variance. This stochasticity is essential for generating diverse samples and exploring the data distribution.
- Process: x_T → x_{T-1} → ... → x_0
- Core Operation: x_{t-1} = μ_θ(x_t, t) + σ_t * z, where z ~ N(0, I)
- Outcome: A single, unique sample from the model's learned distribution.
Follows the Reverse Markov Chain
The procedure strictly adheres to the reverse Markov chain defined by the trained model's parameters. Each step conditions only on the immediate previous state (x_t), not the full history. This Markov property is a direct inversion of the forward diffusion process and is encoded in the model's learned denoising function.
- Mathematical Basis: p_θ(x_{0:T}) = p(x_T) ∏{t=1}^{T} p_θ(x{t-1} | x_t)
- Conditional Distribution: p_θ(x_{t-1} | x_t) = N(x_{t-1}; μ_θ(x_t, t), Σ_θ(x_t, t))
- Contrast with DDIM: Unlike deterministic samplers (DDIM), it does not skip steps or use a non-Markovian process.
Parameterized by Learned Variances
The amount of new noise injected at each denoising step is not arbitrary; it is governed by the model's learned variance schedule Σ_θ(x_t, t). In foundational models like DDPM, this is often fixed to a schedule derived from the forward process betas. However, the model can also learn to predict these variances, allowing the sampling process to adaptively control stochasticity.
- Common Practice (DDPM): Σ_θ(x_t, t) = σ_t² I, where σ_t² is a fixed scalar from the
noise schedule. - Learned Variances: More advanced models parameterize Σ_θ(x_t, t) with the neural network, potentially improving sample quality.
- Impact: The variance controls the trade-off between sample diversity and fidelity at each step.
Connection to Score-Based Models
Ancestral sampling in variance-preserving diffusion models is mathematically equivalent to sampling via Langevin dynamics using a learned score function. The model's noise prediction ϵ_θ(x_t, t) is directly proportional to the score (gradient of the log data density). Each sampling step can be viewed as moving towards higher data density (via the score) while adding noise for exploration.
- Equivalence: ϵ_θ(x_t, t) ∝ -score(x_t, t)
- Langevin Step: x_{t-1} = x_t + (α * score(x_t, t)) + (√(2α) * z)
- Foundation: This bridges Denoising Diffusion Probabilistic Models (DDPM) and Score Matching generative models.
Computational Cost and Speed
The primary drawback of ancestral sampling is its computational expense. Generating a single sample requires performing a full forward pass of the neural network (e.g., a U-Net) at every timestep in the reverse chain. For high-fidelity image generation, this often means 50 to 1000 sequential evaluations, making it slow compared to single-step generators.
- Typical Steps: 50 (fast sampling) to 1000 (high quality) neural network evaluations.
- Bottleneck: Sequential dependency prevents parallelization across timesteps.
- Driver for Research: This cost motivates faster samplers (DDIM) and distillation methods (Consistency Models).
The Foundation for Conditional Generation
Ancestral sampling is the backbone for conditional generation techniques like Classifier-Free Guidance (CFG). In CFG, the core denoising step is modified. The model makes two predictions: one conditional (e.g., on a text prompt) and one unconditional. The final noise prediction is a weighted combination, steering the ancestral sampling trajectory towards regions of the data space that better match the condition.
- CFG Update: ϵ̃ = ϵ_uncond + guidance_scale * (ϵ_cond - ϵ_uncond)
- Process: This modified ϵ̃ is used in the standard ancestral sampling update rule.
- Result: Dramatically improved adherence to the input prompt or class label.
Ancestral Sampling vs. Other Sampling Methods
A comparison of key characteristics between ancestral sampling and other prominent sampling techniques used in diffusion models and generative AI.
| Feature / Metric | Ancestral Sampling | Deterministic Sampling (e.g., DDIM) | Stochastic Sampling (e.g., DDPM) |
|---|---|---|---|
Core Mechanism | Adds new noise at each reverse step | Follows a deterministic ODE trajectory | Follows the learned stochastic reverse process |
Markovian Property | Yes, follows the learned reverse Markov chain | No, uses a non-Markovian forward process | Yes, follows the learned reverse Markov chain |
Output Determinism | Stochastic (different noise seeds produce different outputs) | Deterministic (same seed produces identical output) | Stochastic (different noise seeds produce different outputs) |
Sampling Speed (Steps) | Typically requires the full number of training steps (e.g., 1000) | Can use far fewer steps (e.g., 20-50) with minimal quality loss | Typically requires the full number of training steps (e.g., 1000) |
Primary Use Case | Baseline sampling, theoretical analysis | Fast inference, latent space interpolation | High-fidelity, diverse sample generation |
Noise Injection | Explicitly adds Gaussian noise (σₜ) at each step | No explicit noise addition after the initial sample | Adds noise scaled by the learned variance (Σₜ) |
Relation to Training Objective | Directly implements the trained reverse process variances | Derived from the probability flow ODE of the trained model | Directly implements the trained reverse process means and variances |
Sample Quality vs. Diversity Trade-off | Balanced, as defined by the trained model | Often higher perceived quality but lower diversity per step count | Balanced, as defined by the trained model |
Frequently Asked Questions
Answers to common technical questions about the ancestral sampling procedure used in diffusion models.
Ancestral sampling is the standard, stochastic procedure for generating data from a trained diffusion model. It works by iteratively denoising a sample of pure Gaussian noise, following the learned reverse Markov chain. At each denoising step, the model predicts the noise component, and a new sample is drawn from a Gaussian distribution whose mean is the denoised estimate and whose variance is defined by the model's learned or fixed noise schedule. This injection of fresh noise at each step makes the process stochastic, meaning multiple runs from the same initial noise can yield different outputs.
This method is called "ancestral" because it directly samples from the conditional distributions defined by the model's reverse process, moving step-by-step from a simple prior distribution (noise) to the complex data distribution. It is the foundational sampling algorithm for models like Denoising Diffusion Probabilistic Models (DDPMs).
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Ancestral sampling is a core procedure within the broader framework of diffusion models. The following terms define the key components and alternative methodologies that interact with or enable this stochastic generation process.
Denoising Diffusion Probabilistic Model (DDPM)
The foundational class of generative model that formalizes the framework for ancestral sampling. A DDPM learns to reverse a fixed forward process of gradually adding Gaussian noise to data. The model is trained to predict the noise at each timestep, enabling the iterative denoising procedure that defines ancestral sampling.
- Core Mechanism: Defines the Markov chain structure that ancestral sampling follows.
- Training Objective: Noise prediction, which is equivalent to learning the score function.
- Relation to Ancestral Sampling: Provides the learned reverse transition distributions
p_θ(x_{t-1} | x_t)used in each sampling step.
Reverse Process
The learned generative trajectory that ancestral sampling executes. Starting from pure noise x_T, this process applies a sequence of learned denoising steps to produce a data sample x_0. Each step is a stochastic transition defined by the model's parameters.
- Mathematical Definition:
p_θ(x_{0:T}) = p(x_T) ∏_{t=1}^{T} p_θ(x_{t-1} | x_t) - Stochasticity: In ancestral sampling, each reverse step injects new noise based on a learned variance schedule.
- Contrast with Deterministic Samplers: Unlike DDIM, the reverse process here is inherently Markovian and stochastic.
Noise Schedule
A predefined function β_t that controls the variance of the Gaussian noise added at each timestep t during the forward process. This schedule is critical because it determines the variances used in the ancestral sampling reverse steps.
- Key Parameters: Defines
β_t(orα_t = 1 - β_t), which sets the noise level per step. - Variance Types: Can be variance-preserving (total variance constant) or variance-exploding.
- Impact on Sampling: The learned reverse process variances in ancestral sampling are typically derived from this forward schedule.
Score Matching
An alternative training objective for generative models that is fundamentally connected to diffusion models. Instead of predicting noise, a score network is trained to estimate the score function—the gradient of the log data density.
- Score Function:
∇_x log p(x); points toward regions of higher data density. - Equivalence: Under certain parameterizations, training a diffusion model's noise prediction network is equivalent to score matching.
- Sampling Link: Ancestral sampling in a trained model effectively follows the estimated score, with added noise for exploration.
DDIM Sampling
Denoising Diffusion Implicit Models, a class of deterministic samplers that represent a key alternative to stochastic ancestral sampling. DDIMs redefine the forward process as non-Markovian, enabling faster generation with fewer steps.
- Deterministic vs. Stochastic: DDIM sampling follows an ODE, producing the same output for a given starting noise. Ancestral sampling is stochastic, producing varied outputs.
- Speed vs. Diversity: DDIM enables 10-50 step sampling versus 1000+ for ancestral sampling, but may trade off some mode coverage diversity.
- Same Model Weights: Both methods can use the same trained diffusion model backbone.
Probability Flow ODE
An ordinary differential equation derived from the continuous-time limit of a diffusion model's reverse-time SDE. It describes a deterministic trajectory that shares the same marginal distributions as the stochastic process used in ancestral sampling.
- Theoretical Bridge: Connects stochastic (ancestral) and deterministic (DDIM) sampling under one framework.
- Sampling Method: Solving this ODE with a numerical solver (like Euler) is a deterministic alternative to ancestral sampling.
- Flexibility: Allows for trade-offs between sampling speed and fidelity via choice of solver and step count.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us