Generative Diffusion Modeling
A Practical Handbook · 2024
Read Generative Diffusion Modeling by A Practical Handbook (2024) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2412-17162.txt.
Introduction
Zihan Ding and Chi Jin wrote a practical handbook in 2024 on diffusion models, a popular way for computers to make new images and other content. These models learn by adding noise to data step by step, then learning to remove it. The handbook aims to link the math in papers to working code.
The book uses one shared set of symbols across many model types, from early diffusion models to newer fast ones. It covers how the models are first trained, then refined with tricks like shrinking them for speed or tuning them with rewards. The focus stays on the methods people use most. Readers get a clear, hands-on guide rather than deep theory.
Catalog record
| CREATOR | A Practical Handbook |
|---|---|
| YEAR | 2024 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 118 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2412-17162
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Generative Diffusion Modeling A Practical Handbook Abstract This handbook offers a unified perspective on diffusion models, encompassing diffusion probabilistic models, score-based generative models, consistency models, rectified flow, and related methods. By standardizing notations and aligning them with code implementations, it aims to bridge the “paper-to-code” gap and facilitate robust implementations and fair comparisons. The content encompasses the fundamentals of diffusion models, the pre-training process, and various post-training methods. Post-training techniques include model distillation and reward-based fine-tuning. Designed as a practical guide, it emphasizes clarity and usability over theoretical depth, focusing on widely adopted approaches in generative modeling with diffusion models. Authors: Zihan Ding Chi Jin [email protected] [email protected] 1 Introduction Diffusion models [ Sohl-Dickstein et al., 2015 , Song and Ermon, 2019 , Ho et al., 2020 , Song et al., 2021 ] have recently revolutionized generative modeling, achieving remarkable advancements in generating images [ Rombach et al., 2022 , Ramesh et al., 2022 ] , audio [ Liu et al., 2023a , Polyak et al., 2024 ] , video [ Brooks et al., 2024 , Polyak et al., 2024 ] , 3D content [ Poole et al., 2022 , Wang et al., 2024c ] , and even 4D representations [ Wang et al., 2024b ] . Despite this rapid progress, existing research often presents the concepts and notations of diffusion models in inconsistent ways, even when the underlying methodologies are similar. Compounding this issue, the formulations in many papers often differ from their their corresponding code implementations or lack sufficient implementation details, creating what is referred to as the “paper-to-code” gap. These inconsistencies make it challenging for practitioners to directly implement methods from the literature, hindering robust implementations and fair cross-method comparisons. This handbook seeks to provide a unified perspective on various models, collectively referred to here as ‘‘diffusion models” as an umbrella term 1 1 1 This might be inappropriate, as some may differentiate score-based generative models from diffusion probabilistic models and instead prefer the umbrella term “generative diffusion processes”. . These include diffusion probabilistic models [ Sohl-Dickstein et al., 2015 , Ho et al., 2020 ] , score-based generative models [ Song et al., 2021 ] , consistency models [ Song et al., 2023 ] , rectified flow [ Liu et al., 2022 ] , flow matching [ Lipman et al., 2022 ] , TrigFlow [ Lu and Song, 2024 ] , and others. The authors have made every effort to standardize the notations across these methods and align them closely with their code implementations to minimize the paper-to-code gap. Additionally, this handbook aims to clarify the relationships among these different methods, highlighting existing transformations and unifications that connect them. While diffusion models are theoretically grounded in fields such as non-equilibrium statistical physics, optimal transport, and score matching, this handbook intentionally avoids delving deeply into these theoretical foundations. Instead, its primary purpose is to serve as a practical guide for researchers and practitioners. It is important to note that this handbook does not aim to provide a comprehensive overview of diffusion models for generative modeling. Rather, it focuses on a subset of the most popular and widely adopted works that are frequently applied in practice. Notations a,b,c Vectors or scalars or constants. \mathbf{A} A matrix. q(x_{t}|x_{t-1}) Single-step conditional distribution of diffusion process. q(x_{t-1}|x_{t}) Single-step posterior distribution of denoising process in diffusion. p_{\theta}(x_{t-1}|x_{t}) Neural network approximated single-step distribution of denoising process in diffusion. q(x) Sample distribution of training dataset. x_{0} Clean sample from sample distribution, 0 indicates timestep t=0 in diffusion process. \hat{x}_{0} Predicted clean sample. x_{\theta} Predicted clean sample \hat{x}_{0} with model parameterized by \theta . \mathcal{N}(0,\mathbf{I}) Normal distribution. \varepsilon Sampled Gaussian noise. \epsilon_{\theta} Predicted noise with parameterized model by \theta . The above notations are kept consistent across the entire paper. 2 Diffusion Model Basics 2.1 Problem Formulation We consider samples x^{(1)},x^{(2)},\dots x^{(n)}\sim q(x) , and try to fit a parameterized distribution p_{\theta}(x) from these samples. After that, new samples can be drawn x\sim p_{\theta}(x) . The classical choice of p_{\theta}(x) can be Gaussian distributions, Gaussian mixture models, etc. In general, the maximum likelihood estimation \max_{\theta}\sum_{i}^{n}\log p_{\theta}(x=x^{(i)}) is intractable for the integration in the log-probability estimation: \displaystyle\log p_{\theta}(x) \displaystyle=\log\int p_{\theta}(x,z)dz \displaystyle=\log\int p_{\theta}(x|z)p(z)dz Variational inference offers a way: \displaystyle\log p_{\theta}(x) \displaystyle=\log\int p_{\theta}(x,z)dz \displaystyle=\log\int p_{\theta}(x|z)p(z)dz \displaystyle=\log\int q_{\phi}(z|x)\frac{p_{\theta}(x|z)p(z)}{q_{\phi}(z|x)}dz\quad\quad\text{(with approximate posterior $q_{\phi}(z|x)$)} \displaystyle\geq\mathbb{E}_{q_{\phi}(z|x)}\left[\log p_{\theta}(x|z)+\log p(z)-\log{q_{\phi}(z|x)}\right]\quad\quad\text{(Jensen's Inequality)} with the evidence lower bound (ELBO) \mathcal{L}(\phi,\theta;x)=\mathbb{E}_{q_{\phi}(z|x)}\left[\log p_{\theta}(x|z)\right]-D_{\text{KL}}(q_{\phi}(z|x)\|p(z)) as a tractable objective. With additional loss term D_{\text{KL}}(q_{\phi}(z|x)\|p_{\theta}(z|x)) , it constitutes the variational auto-encoder (VAE) [ Kingma, 2013 ] . Apart from variational autoencoders (VAEs), other generative methods such as energy-based models, normalizing flows, and generative adversarial networks (GANs) offer diverse approaches to estimating the probability distributions of training data. Among these, diffusion models stand out for their exceptional tractability and flexibility. Definition 2.1 (Diffusion Model) For the data sampled from distribution x_{0}\sim q(x_{0}) , the forward diffusion process corrupts the data distribution to a Gaussian distribution as following: \displaystyle x_{t}=\bar{a}_{t}x_{0}+\bar{b}_{t}\varepsilon,\varepsilon\sim\mathcal{N}(0,\mathbf{I}) with t\in\{1,2,\dots,T\} for discrete-time cases and t\in[0,T] for continuous-time cases. \bar{a}_{t} and \bar{b}_{t} are time-dependent coefficients specified by a given noise schedule. The general diffusion models learn the backward process, which is the reverse-time counterpart to the forward diffusion process. For discrete-time cases, the forward process can be alternatively written as per-step diffusion process as follows. Given x_{0}\sim q(x_{0}) , we have the forward diffusion process: \displaystyle x_{t}=a_{t}x_{t-1}+b_{t}\varepsilon_{t-1},\varepsilon_{t-1}\sim\mathcal{N}(0,\mathbf{I}) with t\in\{1,2,\dots,T\} and existence of the representation of \bar{a}_{t} and \bar{b}_{t} by a_{t} and b_{t} . The diffusion process can be characterized as the solution to a stochastic differential equation (SDE), which is commonly expressed in the following general form: \displaystyle dx=f(x,t)dt+g(x,t)dw, (1) where f(x,t) is the drift coefficient, g(x,t) is the diffusion coefficient, w is the standard Wiener process. An instantiation of diffusion models can select different schedules a_{t} and b_{t} . For example, for a discrete-time diffusion process with a variance preserving schedule a_{t}=\sqrt{1-\beta_{t}},b_{t}=\sqrt{\beta_{t}} , the corresponding SDE is: \displaystyle dx=-\frac{1}{2}\beta_{t}xdt+\sqrt{\beta_{t}}dw In diffusion models, there’s also often an interest in the backward SDE for sampling, which has the following form for general SDE as Eq. ( 1 ) [ Anderson, 1982 ] : \displaystyle dx=\big[f(x,t)-\nabla_{x}\cdot[g(x,t)g(x,t)^{\intercal}]-g(x,t)g(x,t)^{\intercal}\nabla_{x}\log p_{t}(x)\big]dt+g(x,t)\,d\bar{w}, (2) where p_{t}(x) is the probability distribution of x_{t} at diffusion time t , and \bar{w} is a reverse-time Wiener process. For above SDE, there exists an ordinary differential equation (ODE), with equivalent marginal distribution p_{t}(x) [ Song et al., 2021 ] : \displaystyle dx=\big[f(x,t)-\frac{1}{2}\nabla_{x}\cdot[g(x,t)g(x,t)^{\intercal}]-\frac{1}{2}g(x,t)g(x,t)^{\intercal}\nabla_{x}\log p_{t}(x)\big]dt In Eq. ( 2 ), when g(x,t) does not depend on x , as g(t) in diffusion models, we have a simplified form: \displaystyle dx=\big[f(x,t)-g(t)g(t)^{\intercal}\nabla_{x}\log p_{t}(x)\big]dt+g(t)\,d\bar{w}, (3) since the divergence \nabla_{x}\cdot[g(\cdot,t)g(\cdot,t)^{\intercal}]=0 . The corresponding simplified reverse ODE is: \displaystyle dx=\big[f(x,t)-\frac{1}{2}g(t)g(t)^{\intercal}\nabla_{x}\log p_{t}(x)\big]dt (4) It is observed that estimating the score function, \nabla\log p_{t}(x) , is a crucial requirement in the reverse sampling process, serving as one of the fundamental components of diffusion models. 2.2 Diffusion Model Diffusion models are a class of generative models that iteratively transform simple noise distributions into complex data distributions through a sequence of forward and reverse processes. This section offers a detailed introduction to the derivation of diffusion model fundamentals, training objectives, and inference mechanisms. 2.2.1 Foundamentals Suppose the data is sampled from distribution x_{0}\sim q(x_{0}) , the diffusion model is trained to generate samples \hat{x}_{0} that follow the