Assignment 11: Denoising Diffusion Models

Discussion: July 1st
Deadline: June 30th, 23:59

In this assignment, we will implement the final “class” of generative models that have been treated in this course. Diffusion models have seen a stark rise in popularity recently. They are stable to train and can produce very high-quality outputs.

See the reference paper here. In what follows, we will list the main steps required for a successful implementation.

Forward Process

First, make sure that you have understood the forward process and verified your implementation of it.

Model

To train the backward process, we need a parametric model that basically separates the noise from the data. You can use any kind of model that takes an input with the same shape as the data, and returns the same shape as well. Papers tend to use U-net-like models, which are basically encoder-decoder networks with skip-connections connecting encoder layers to decoder layers operating at the same resolution. Building such a model should be simple in principle. There is just one complication…

Conditioning on t

In the mathematical framework of diffusion models, our network has to be able to return different outputs depending on where we are in the process (step t). Thus, t needs to be given as input to the model in some shape or form, or the model has to be otherwise conditioned on it. Some possible choices were discussed in the exercise, but the large t we tend to deal with in diffusion models makes many of these infeasible.

For a working model, it should suffice to add t only to the input, but note that the paper proposes adding it to each residual block in the model!

Training

Training is surprisingly simple; just follow algorithm 1 on page 4 of the paper. For each training step

You may have trouble doing all these steps in tensorflow. But note that everything before running the actual model does not need to be backpropagated through. That is, you can do all these steps “outside” the training step, using general Python code, numpy etc.

Sampling

For sampling, we have to fully implement the “backward process”. This is given in algorithm 2 of the paper.

That’s it! Have fun with your model. Besides straight generation, you can also do a few more things with the diffusion process: