AI Hero Club

Diffusion Models and Flow Matching · Lesson 3

Marked Complete by You0 / 8

Saved in this browser only. Marking a lesson complete does not mean the project has passed verification.

Lesson Outline 7 subsections
Course Contents 8 lessons
Full course plan.
Diffusion Models and Flow Matching / Learning Plan ↗

LESSON 03 / 8Suggested study 180 minutes

DDPM Posteriors, Variational Objectives and Reverse Sampling

Given a noisy sample and a clean endpoint, how do we compute the previous-step Gaussian posterior and connect it to training?

3 Questions for This Lesson
  • Complete a square to guide Gaussian conditions.
  • Rebuilding items and internal KLs from the lower side of Jensen.
  • Motivate noise MSE weights and identify label leaks
Course Project ZIP ↓

Task: From a Computable Posterior to a Trainable Reverse Model

This chapter follows a step forward. jj: Clean data is x0x_0 Noise terminal is... xJx_J. Generate a model from terminal to zero and write it as a priori p(xJ)p(x_J) With a series of reverse conditions pθ(xj−1∣xj)p_\theta(x_{j-1}\mid x_j) . We will deduce a Gaussian test that can be calculated when a clean sample is known, and then explain how it provides oversight to the network. It is important to distinguish between “The back of the clean answer known.” and “Conditions that are really available at the time of generation”; to mix the two and steal training labels in the sampling function.

Assume a forward schedule. 0<βj<10<\beta_j<1. Remember the cumulative retention rate at the previous time a=αˉj−1a=\bar\alpha_{j-1}, the current one-step retention rate α=αj\alpha=\alpha_j, the current cumulative rate αa\alpha a. In order to avoid a vector formula that hides algebra, the algebra is deduced from one coordinates, and the exact matrix of the same Gaussian Gossi is a marker multiplying array, which allows for the same formulas to be obtained by coordinates. All points and conditions density are for continuous variables and the probabilistic mass function cannot be written directly.

1. Completing the Square to Derive the Exact Conditional Posterior

To the previous state to be inferred as y=xj−1y=x_{j-1}, the current observation is x=xjx=x_j. The Bayesian results are compared to those of the q(x∣y)q(y∣x0)q(x\mid y)q(y\mid x_0). Ignore with yy It's not about the number of negative logarithms. (x−αy)2/βj+(y−ax0)2/(1−a)(x-\sqrt\alpha y)^2/\beta_j+(y-\sqrt a x_0)^2/(1-a)..and when it is expanded, y2y^2 The coefficient is called accuracy, equal to α/βj+1/(1−a)\alpha/\beta_j+1/(1-a) ; yy . The square is a square that returns the secondary function to the accuracy multiplied by “Variable Impairment”, not an average.

β~j=(αjβj+11−αˉj−1)−1=βj(1−αˉj−1)1−αˉj\tilde\beta_j=\left(\frac{\alpha_j}{\beta_j}+\frac{1}{1-\bar\alpha_{j-1}}\right)^{-1}=\frac{\beta_j(1-\bar\alpha_{j-1})}{1-\bar\alpha_j}
This formula requires j2; clean samples are known at zero as degraded boundaries.

Once again, the item factor is divided by accuracy and the average is obtained. αj+βj=1\alpha_j+\beta_j=1, no new noise agenda is introduced. In vectors, the two metric coefficients are multiplied by the clean vectors observed at present. The two coefficients are generally not equal, because random variables change scales; they are misconstrued as normal condensations and are wrongly re-assimilated.

μ~j=αˉj−1βj1−αˉjx0+αj(1−αˉj−1)1−αˉjxj\tilde\mu_j=\frac{\sqrt{\bar\alpha_{j-1}}\beta_j}{1-\bar\alpha_j}x_0+\frac{\sqrt{\alpha_j}(1-\bar\alpha_{j-1})}{1-\bar\alpha_j}x_j
The exact thing is q(x_{j−1}|x_j,x₀), which is still known as x0 at the training stage.

Example 1: Computing the Posterior Rather Than Simply Reversing Noising

The first step is to take a noise differential of zero point two, and a second step zero three. The previous cumulative rate of zero eight, the current one-step rate of zero seven, and the current one-step rate of zero five six. The next step is zero three times zero two two, divided by four, and obtained about zero one, three, three, six, six, six, six, six, six.

Simply to remove the previous state from its current value root 0:07, it will be about 1:952, neglecting the uncertainty of noise and the condition of clean data; this is not a Bayesian post-record. The other error is to subtract the true second step of noise elimination factor from the current value. If you save that noise in a training simulation, you can actually restore the path, but it was created without it. What we need is to see only the reverse distribution of current predictions, rather than using the failure to provide information for algebra reversals.

2. Why These Posteriors Appear in the Variational Bound

Generate marginal density pθ(x0)p_\theta(x_0) It is often difficult to calculate directly if you want to add the whole hidden chain. q(x1:J∣x0)q(x_{1:J}\mid x_0) Multiplies the same item without changing the points; when expectations are met, the logarithm is used to obtain a logarithmic expectation that is not less than the expected logarithm. This is the role of the Jensen diversity here. The lower bounds are not precise, and the intervals between the two are determined by the corresponding post-mortem KL; and the visual quality of the lower level of training that does not equal any random sample is necessarily improved.

log⁡pθ(x0)≥Eq ⁣[log⁡pθ(x0:J)q(x1:J∣x0)]\log p_\theta(x_0)\geq\mathbb E_q\!\left[\log\frac{p_\theta(x_{0:J})}{q(x_{1:J}\mid x_0)}\right]
The forward distribution is an auxiliary distribution; model parameters only appear in the production chain.

Recombine forward distributions to the reverse condition of known clean samples and offset the logarithms by item, with three parts: KL between the edge of the terminal and the a priori; KL between the second and last steps, between the real condition and the reverse condition of the model; and the first step to reconstruct negative logarithmic entries for clean data. KL is a non-negative but asymmetrical ratio to the desired number density under the first distribution. The terminal item is fixed prior to schedule and does not contain network parameters; The first step of reconstruction cannot be replaced by a zero-variety Gaussian KL.

Lbound=DKL(q(xJ∣x0)∥p(xJ))+∑j=2JEqDKL(q(xj−1∣xj,x0)∥pθ(xj−1∣xj))−Eqlog⁡pθ(x0∣x1)\mathcal L_{\rm bound}=D_{\rm KL}(q(x_J\mid x_0)\|p(x_J))+\sum_{j=2}^{J}\mathbb E_q D_{\rm KL}(q(x_{j-1}\mid x_j,x_0)\|p_\theta(x_{j-1}\mid x_j))-\mathbb E_q\log p_\theta(x_0\mid x_1)
This is the decomposition of the lower negative threshold; real training data need to be averaged.

Select model condition to Gauss, average value from network, variance sj2Is_j^2I In each internal step, the portion of the Goose KL that is relevant to the mean value is a two-digit square distance divided by a two-fold model difference, and the rest relates only to the given range. This step explains why the square error naturally occurs and limits the conclusion: if you learn the difference, all remaining items cannot be discarded as constants.

Example 2: Error Weighting and Noise Parameterization

In line with the above example, the average value of the network deviates from the real condition mean value of zero two points at a coordinate, and the average value of KL is equal to about one hundred and forty-six and sixty-seven. The same zero-two deviation occurs at a smaller step. Thus, unweighted MSE at different times is not automatically equivalent to this goal.

The training is done in direct form from chapter II. x0x_0 Write xjx_j And real noise. ϵ\epsilon , and insert the mean value after checking; sorted to have the mean value as root number αj\alpha_j , minus a noise correction. Using network noise predictions to replace real noise, the common mean parameter is used. The mean error and the noise error are multiple times the mark, so that squares generate a clear time weight.

μθ(xj,j)=1αj(xj−βj1−αˉjϵθ(xj,j)),wj=βj22sj2αj(1−αˉj)\mu_\theta(x_j,j)=\frac{1}{\sqrt{\alpha_j}}\left(x_j-\frac{\beta_j}{\sqrt{1-\bar\alpha_j}}\epsilon_\theta(x_j,j)\right),\quad w_j=\frac{\beta_j^2}{2s_j^2\alpha_j(1-\bar\alpha_j)}
The mean value of the internal KL is equal to w_j by default square.

Will wjw_j In turn, it is a reweighted training option, often called simplified noise targets; it can be of practical value but can no longer be described as exactly the lower end of the line. When network capacity is limited, time is unevenly sampled, or failure is optimized, changes in weight may affect the moment of learning better. “To deduce the target.” “Achievement of selected objectives” “Observed mass” Three separate statements are presented, rather than using the title of the paper as a substitute for the statement of achievement.

3. Sampling Boundaries and Uncertainty Beyond Gaussian Formulas

When a clean sample is given, the first step is that sample, so the condition is degraded; but the clean sample is not known at the time of generation. q(x0∣x1)q(x_0\mid x_1) It is not necessarily a point. It is often achieved without random noise that the sampler agrees that there is no uncertainty about the actual data after the condition degradation can be proved. The same is true for internal steps: once all possible clean data are mixed, the real reverse conditions are usually no longer single Gus, and the Gaussian model is a close family.

An implementable reverse algorithm also needs to fix a terminal a priori, which variable to use, whether to jump, and the coordinates of final output. Learning mean value is two different designs from the selection margin; noise prediction networks are given, and none of these agreements are automatically given. Our two-dimensional project does not achieve this complete DDPM training and random reverse chain, so this chapter is delivered by deference and independent numerical reconciliation, and the actual neural network project will apply conditions in Chapter VII, which will maintain clarity on capability boundaries.

The laxity of the lower boundary can also be accurately written as a difference: the true logarithm seems to be equal to the logarithm expectations under the aid distribution, plus KL, which is "the default chain for the auxiliary hider's back-to-back model." Both tests are defined by the same clean observation, so that KL is not negative; only if they are almost identical everywhere, the lower limit is reached. Here the assistive postcheck is the distribution of the entire chain, not an internal Gaussian. This relationship explains why only a few internal values are well aligned, and it does not automatically prove that completeness has been accurately calculated.

The computer also makes a distinction between deviations and standard deviations. If the reverse condition requires that the harmonised variance be a positive mass multiplied by a square array, the standard normal actually added to the mean value must be multiplied by the square root of the rule. If the difference is directly treated as a sampling factor, the actual harmonic difference will again be squared; if the mean network and training losses are completely unchanged, the end distribution has changed. An independent one-step test should fix the current point, repeat the sample and measure the mean value and the variance, and it cannot simply see whether the reverse path is moving roughly towards a centre.

Standalone ProgramCompletes a square numerical check and does not read any post-training image weight.
from math import sqrt
a=0.8;alpha=0.7;beta=0.3
variance=beta*(1-a)/(1-alpha*a)
mu=sqrt(a)*beta/(1-alpha*a)*2+sqrt(alpha)*(1-a)/(1-alpha*a)*1
precision=alpha/beta+1/(1-a)
independent_mu=(sqrt(alpha)/beta+sqrt(a)*2/(1-a))/precision
assert abs(variance-1/precision)<1e-12
assert abs(mu-independent_mu)<1e-12
print(variance,mu,0.2**2/(2*variance))

Three Exercises and Solutions

TRY IT YOURSELF

Practice a single piece of precision.

The difference is one and three, respectively. What is the difference between the averages of the multipliers when they have been revalued?

Hint 1
The Gaussian factor is multiplied by the accuracy, which is the reverse of the difference.
Hint 2
The mean is weighted by accuracy and the total accuracy is removed; a negative log entry is then expanded to independently check the location point and the curvature.
Compare with the Solution
The first is one, the second is one third, and the total is four divided by three, so the difference is three divided by four. The mean molecule is zero times one plus two times one third, two thirds divided by four divided by three, and one half divided by two. The difference is seven and five less than two factors, reflecting both constraints. The mean is not a simple average of two values, but is more inclined to higher accuracy and zero with smaller variations. It can also be expanded to a secondary function on variables, with zero independent checks at one level; the second factor gives the same overall accuracy.

TRY IT YOURSELF

The cost of practicing a two-by-one fixed deviation.

An average error of 0. 1, and how does the average KL-related increase change when the model is changed from 0.2 to 0.05? Can this result in a direct declaration that the latter model is worse?

Hint 1
The denominator of the KL entry is twice the model variance when the fixed mean error is involved.
Hint 2
The two variants are added separately and the remaining KL co-ordinated with the log line item is listed in its entirety, indicating that local items cannot rank overall objectives.
Compare with the Solution
The error square is zero-one, divided by twice zero-two, received zero-two-five; and divided by two times zero-five, obtained zero-one-one-fold. This is only a fair-value component, and the whole Gospel KL also contains a logarithm-column line item. Changing the model's variance itself has changed the distribution family and the complete goal, which cannot be used to sort the model as a whole. The correct conclusion is that the smaller model's variance is more severe for the mean deviation at the given step, the specified mean error.

TRY IT YOURSELF

Practice three-thirties to detect a leak in the tags in the sample.

A program reverses the sampling by entering a true clean spot into the network and calls an exact after-checking average accordingly. The sample is very close to the training point. Why not complete unconditional generation?

Hint 1
Training after testing can be monitored by x 0, and which input is allowed by the interface when genuinely and unconditionally sampled?
Hint 2
Try running after removing the true clean spot to see if the current noise and network is sufficient; a beautiful output does not prove that no answer has been leaked.
Compare with the Solution
Precision tests require a true clean spot as a condition, which can be constructed and monitored for training. The unconditional procedure is created with only end noise and trained parameters. This achieves by using the target answer as input, and the task has been re-established under known sample conditions. The test is to remove clean point input: if the function cannot continue, there will be no unconditional interface to fulfil the requirement. If you cannot detect such information crossing the border just by looking at the output close to the training point, a list of parameters should be checked against the source of data when running. A real model needs to predict the amount of inverse statistics available from current noise state.

CHECK YOUR UNDERSTANDING

Check Your Understanding

Answer first, then open the explanation to check your reasoning. These questions help reveal gaps in understanding; independent implementation and transfer require separate evaluation.

1. What are the precise conditions for internal tests?

Show ExplanationThe training after-use tests contain clean samples that cannot be accessed directly at the time of generation.
2. What is the average KL value when fixing the normal variance?

Show ExplanationSecond entry from Gus KL to mean value.
3. Simplified MSE equals the whole lower limit?

Show ExplanationTime weights and boundaries cannot be omitted unconditionally.
4. The first step of degradation indicates that it must be real?

Show ExplanationThe condition information is different and the degradation conclusion is followed when clean samples cannot be removed.

Manual completion records your progress; it does not certify your project.