ArticleslgStudy

biology

Latent diffusion model

Latent diffusion model is a biology 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 Latent diffusion model rather than just read about it. In short: The latent diffusion model (LDM) is a diffusion model architecture developed by the CompVis (Computer Vision & Learning) group at LMU Munich. Introduced in 2015, diffusion models (DMs) are trained with the objective of removing successive applications of noise (commonly Gaussian) on training images.

Latent diffusion model — main illustration
Latent diffusion model — illustration

Key takeaways

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

Reference excerpt

The latent diffusion model (LDM) is a diffusion model architecture developed by the CompVis (Computer Vision & Learning) group at LMU Munich. Introduced in 2015, diffusion models (DMs) are trained with the objective of removing successive applications of noise (commonly Gaussian) on training images. The LDM is an improvement on standard DM by performing diffusion modeling in a latent space, and by allowing self-attention and cross-attention conditioning. LDMs are widely used in practical diffusion models. For instance, Stable Diffusion versions 1.1 to 2.1 were based on the LDM architecture.

Version history Diffusion models were introduced in 2015 as a method to learn a model that can sample from a highly complex probability distribution. They used techniques from non-equilibrium thermodynamics, especially diffusion. It was accompanied by a software implementation in Theano. A 2019 paper proposed the noise conditional score network (NCSN) or score-matching with Langevin dynamics (SMLD). The paper was accompanied by a software package written in PyTorch release on GitHub. A 2020 paper proposed the denoising diffusion probabilistic model (DDPM), which improves upon the previous method by variational inference. The paper was accompanied by a software package written in TensorFlow release on GitHub. It was reimplemented in PyTorch by lucidrains. On December 20, 2021, the LDM paper was published on arXiv, and both Stable Diffusion and LDM repositories were published on GitHub. However, they remained roughly the same. Substantial information concerning Stable Diffusion v1 was only added to GitHub on August 10, 2022. All of Stable Diffusion (SD) versions 1.1 to XL were particular instantiations of the LDM architecture. SD 1.1 to 1.4 were released by CompVis in August 2022. There is no "version 1.0". SD 1.1 was a LDM trained on the laion2B-en dataset. SD 1.1 was finetuned to 1.2 on more aesthetic images. SD 1.2 was finetuned to 1.3, 1.4 and 1.5, with 10% of text-conditioning dropped, to improve classifier-free guidance. SD 1.5 was released by RunwayML in October 2022.

Architecture

While the LDM can work for generating arbitrary data conditional on arbitrary data, for concreteness, we describe its operation in conditional text-to-image generation. LDM consists of a variational autoencoder (VAE), a modified U-Net, and a text encoder. The VAE encoder compresses the image from pixel space to a smaller dimensional latent space, capturing a more fundamental semantic meaning of the image. Gaussian noise is iteratively applied to the compressed latent representation during forward diffusion. The U-Net block, composed of a ResNet backbone, denoises the output from forward diffusion backwards to obtain a latent representation. Finally, the VAE decoder generates the final image by converting the representation back into pixel space. The denoising step can be conditioned on a string of text, an image, or another modality. The encoded conditioning data is exposed to denoising U-Nets via a cross-attention mechanism. For conditioning on text, the fixed, a pretrained CLIP ViT-L/14 text encoder is used to transform text prompts to an embedding space.

Variational Autoencoder To compress the image data, a variational autoencoder (VAE) is first trained on a dataset of images. The encoder part of the VAE takes an image as input and outputs a lower-dimensional latent representation of the image. This latent representation is then used as input to the U-Net. Once the model is trained, the encoder is used to encode images into latent representations, and the decoder is used to decode latent representations back into images. Let the encoder and the decoder of the VAE be E,D. To encode an RGB image, its three channels are divided by the maximum value, resulting in a tensor x of shape (3,512,512) with all entries within range [0,1]. The encoded vector is 0.18215×E(2x−1), with shape (4,64,64), where 0.18215 is a hyperparameter, which the original authors picked to roughly whiten the encoded vector to roughly unit variance. Conversely, given a latent tensor y, the decoded image is (D(y/0.18125)+1)/2, then clipped to the range [0,1]. In the implemented version, the encoder is a convolutional neural network (CNN) with a single self-attention mechanism near the end. It takes a tensor of shape (3,H,W) and outputs a tensor of shape (8,H/8,W/8), being the concatenation of the predicted mean and variance of the latent vector, each of shape (4,H/8,W/8). The variance is used in training, but after training, usually only the mean is taken, with the variance discarded. The decoder is also a CNN with a single self-attention mechanism near the end. It takes a tensor of shape (4,H/8,W/8) and outputs a tensor of shape (3,H,W).

U-Net The U-Net backbone takes the following kinds of inputs:

A latent image array, produced by the VAE encoder. It has dimensions (channel,width,height). Typically, (channel,width,height)=(4,64,64). A timestep-embedding vector, which tells the backbone how much noise there is in the image. For example, an embedding of timestep t=0 would indicate that the input image is already noiseless, while t=100 would mean there is much noise. A modality-embedding vector sequence, which indicates to the backbone about additional conditions for denoising. For example, in text-to-image generation, the text is divided into a sequence of tokens, then encoded by a text encoder, such as a CLIP encoder, before feeding into the backbone. As another example, an input image can be processed by a Vision Transformer into a sequence of vectors, which can then be used to condition the backbone for tasks such as generating an image in the same style. Each run through the U-Net backbone produces a predicted noise vector. This noise vector is scaled down and subtracted away from the latent image array, resulting in a slightly less noisy latent image. The denoising is repeated according to a denoising schedule ("noise schedule"), and the output of the last step is processed by the VAE decoder into a finished image.

Similar to the standard U-Net, the U-Net backbone used in the SD 1.5 is essentially composed of down-scaling layers followed by up-scaling layers. However, the U-Net backbone has additional modules to allow for it to handle the embedding. As an illustration, we describe a single down-scaling layer in the backbone:

… excerpt ends here. Continue reading the full article.

Illustrations

Latent diffusion model: Block diagram for the full Transformer architecture. The stack on the right is a standard pre-LN Transformer decoder, which is essentially the same as the SpatialTransformer.
Block diagram for the full Transformer architecture. The stack on the right is a standard pre-LN Transformer decoder, which is essentially the same as the SpatialTransformer.

Worked examples

Example 1 — a first encounter with Latent diffusion model

Start with the simplest possible case. Write down what Latent diffusion model claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In biology, 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 Latent 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 Latent 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 Latent diffusion model

In research
Latent diffusion model appears in biology 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 Latent 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
Latent diffusion model is common in secondary-school and first-year university syllabi. It links to neighbouring topics 2021 software, Deep learning, Generative AI, so understanding it makes those chapters shorter.
In everyday life
Look for Latent 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 “Latent diffusion model” →

How to study Latent diffusion model in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Latent 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 Latent diffusion model out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Latent diffusion model in simple terms?

The latent diffusion model (LDM) is a diffusion model architecture developed by the CompVis (Computer Vision & Learning) group at LMU Munich. Introduced in 2015, diffusion models (DMs) are trained with the objective of removing successive applications of noise (commonly Gaussian) on training images.

Why does Latent diffusion model matter?

Because it connects several biology 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 Latent 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 Latent diffusion model.

Tags

  • 2021 software
  • Deep learning
  • Generative AI
  • Image processing
  • Text-to-image generation
  • Unsupervised learning

Keep exploring