ArticleslgStudy

computer science

Diffusion model

Diffusion model is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Diffusion model rather than just read about it. In short: In machine learning, diffusion models, also known as diffusion-based generative models or score-based generative models, are a class of latent variable generative models. A diffusion model consists of two major components: the forward diffusion process, and the reverse sampling process.

Diffusion model — main illustration
Diffusion model — illustration

Key takeaways

  • Diffusion model belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Diffusion model to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Diffusion model from memory before moving on to harder problems.

Reference excerpt

In machine learning, diffusion models, also known as diffusion-based generative models or score-based generative models, are a class of latent variable generative models. A diffusion model consists of two major components: the forward diffusion process, and the reverse sampling process. The goal of diffusion models is to learn a diffusion process for a given dataset, such that the process can generate new elements that are distributed similarly as the original dataset. A diffusion model models data as generated by a diffusion process, whereby a new datum performs a random walk with drift through the space of all possible data. A trained diffusion model can be sampled in many ways, with different efficiency and quality. There are various equivalent formalisms, including Markov chains, denoising diffusion probabilistic models, noise conditioned score networks, and stochastic differential equations. They are typically trained using variational inference. The model responsible for denoising is typically called its "backbone". The backbone may be of any kind, but they are typically U-nets or transformers. As of 2024, diffusion models are mainly used for computer vision tasks, including image denoising, inpainting, super-resolution, image generation, and video generation. These typically involve training a neural network to sequentially denoise images corrupted by Gaussian noise. The model is trained to reverse the process of adding noise to an image. After training to convergence, it can be used for image generation by starting with an image composed of random noise, and applying the network iteratively to denoise the image. Diffusion-based image generators have seen widespread commercial interest, such as Stable Diffusion and DALL-E. These models typically combine diffusion models with other models, such as text-encoders and cross-attention modules to allow text-conditioned generation. Other than computer vision, diffusion models have also found applications in natural language processing such as text generation and summarization, sound generation, and reinforcement learning.

Denoising diffusion model

Non-equilibrium thermodynamics Diffusion models were introduced in 2015 as a method to train a model that can sample from a highly complex probability distribution. They used techniques from non-equilibrium thermodynamics, especially diffusion. Consider, for example, how one might model the distribution of all naturally occurring photos. Each image is a point in the space of all images, and the distribution of naturally occurring photos is a "cloud" in space, which, by repeatedly adding noise to the images, diffuses out to the rest of the image space, until the cloud becomes all but indistinguishable from a Gaussian distribution 𝒩(0,I). A model that can approximately undo the diffusion can then be used to sample from the original distribution. This is studied in "non-equilibrium" thermodynamics, as the starting distribution is not in equilibrium, unlike the final distribution. The equilibrium distribution is the Gaussian distribution 𝒩(0,I), with pdf ρ(x)∝e−12‖x‖2. This is just the Maxwell–Boltzmann distribution of particles in a potential well V(x)=12‖x‖2 at temperature 1. The initial distribution, being very much out of equilibrium, would diffuse towards the equilibrium distribution, making biased random steps that are a sum of pure randomness (like a Brownian walker) and gradient descent down the potential well. The randomness is necessary: if the particles were to undergo only gradient descent, then they will all fall to the origin, collapsing the distribution.

Denoising Diffusion Probabilistic Model (DDPM) The 2020 paper proposed the Denoising Diffusion Probabilistic Model (DDPM), which improves upon the previous method by variational inference.

Forward diffusion To present the model, some notation is required.

β1,...,βT∈(0,1) are fixed constants. αt:=1−βt α¯t:=α1⋯αt σt:=1−α¯t σ~t:=σt−1σtβt μ~t(xt,x0):=αt(1−α¯t−1)xt+α¯t−1(1−αt)x0σt2 𝒩(μ,Σ) is the Gaussian distribution with mean μ and variance Σ, and 𝒩(x|μ,Σ) is the probability density at x. A vertical bar denotes conditioning. A forward diffusion process starts at some starting point x0∼q, where q is the probability distribution to be learned, then repeatedly adds noise to it byxt=1−βtxt−1+βtztwhere z1,...,zT are IID (Independent and identically distributed random variables) samples from 𝒩(0,I). The coefficients 1−βt and βt ensure that Var(Xt)=I assuming that Var(X0)=I. The values of βt are chosen such that for any starting distribution of x0, if it has finite second moment, then limt→∞xt|x0 converges to 𝒩(0,I). The entire diffusion process then satisfiesq(x0:T)=q(x0)q(x1|x0)⋯q(xT|xT−1)=q(x0)𝒩(x1|α1x0,β1I)⋯𝒩(xT|αTxT−1,βTI)orln⁡q(x0:T)=ln⁡q(x0)−∑t=1T12βt‖xt−1−βtxt−1‖2+Cwhere C is a normalization constant and often omitted. In particular, we note that x1:T|x0 is a Gaussian process, which affords us considerable freedom in reparameterization. For example, by standard manipulation with Gaussian process, xt|x0∼N(α¯tx0,σt2I)xt−1|xt,x0∼𝒩(μ~t(xt,x0),σ~t2I)In particular, notice that for large t, the variable xt|x0∼N(α¯tx0,σt2I) converges to 𝒩(0,I). That is, after a long enough diffusion process, we end up with some xT that is very close to 𝒩(0,I), with all traces of the original x0∼q gone. For example, sincext|x0∼N(α¯tx0,σt2I)we can sample xt|x0 directly "in one step", instead of going through all the intermediate steps x1,x2,...,xt−1.

Backward diffusion The key idea of DDPM is to use a neural network parametrized by θ. The network takes in two arguments xt,t, and outputs a vector μθ(xt,t) and a matrix Σθ(xt,t), such that each step in the forward diffusion process can be approximately undone by xt−1∼𝒩(μθ(xt,t),Σθ(xt,t)). This then gives us a backward diffusion process pθ defined bypθ(xT)=𝒩(xT|0,I)pθ(xt−1|xt)=𝒩(xt−1|μθ(xt,t),Σθ(xt,t))The goal now is to learn the parameters θ such that pθ(x0) is as close to q(x0) as possible. To do that, we use maximum likelihood estimation with variational inference.

… excerpt ends here. Continue reading the full article.

Illustrations

Diffusion model illustration
Diffusion model illustration
Diffusion model illustration
Diffusion model: Transport by rectified flow[41]
Transport by rectified flow[41]
Diffusion model: The reflow process[41]
The reflow process[41]

Worked examples

Example 1 — a first encounter with Diffusion model

Start with the simplest possible case. Write down what Diffusion model claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Diffusion model before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Diffusion model ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Diffusion model

In research
Diffusion model appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Diffusion model in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Diffusion model is common in secondary-school and first-year university syllabi. It links to neighbouring topics Machine learning algorithms, Markov models, so understanding it makes those chapters shorter.
In everyday life
Look for Diffusion model outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Diffusion model” →

How to study Diffusion model in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Diffusion model means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Diffusion model out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Diffusion model in simple terms?

In machine learning, diffusion models, also known as diffusion-based generative models or score-based generative models, are a class of latent variable generative models. A diffusion model consists of two major components: the forward diffusion process, and the reverse sampling process.

Why does Diffusion model matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Diffusion model?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Diffusion model.

Tags

  • Machine learning algorithms
  • Markov models

Keep exploring