Get an intuitive understanding of the difference between DDPM and DDIM:
Are you ready? Let’s begin!
Step 1: Preliminary Knowledge (Parametricization Techniques)
In diffusion models, we often use a technique: if you have a variable that follows a normal distribution
Here,
In simple terms: Any state = a definite base value + (random noise
Step 2: Basic Settings of DDPM (Adding Noise from Start to End)
In the original DDPM (Denoising Diffusion Probabilistic Model), we have a clear forward diffusion process.
Assume we have a clear image (or a perfect action of the robot), called
DDPM proves a highly important conclusion: We don’t need to add noise step by step; we can directly jump from
The formula is as follows:
: Initial clean data. : Noisy data from step . : A coefficient between 0 and 1. You can consider it as “signal retention rate”. As the number of steps increases, becomes smaller (approaching 0). : “noise intensity”. : Pure noise following a standard normal distribution.
In one sentence: The data
Step 3: Reverse Thinking — How to Guess from ?
Now, we enter the stage where the large model actually works: reverse denoising.
When a large model (such as a U-Net neural network) performs inference, it sees a noisy
Assume we have trained a large divine model, denoted as
Since the noise has been guessed, can we use the formula from step 2 to backtrack (guess) out the clean
We move and transform the formula
(This is just a simple move of terms in middle school algebra!)
This is the final clear result that the large model “imagines” in its mind at any step
Step 4: The Core Magic of DDIM — Reassembling
In traditional DDPM, it is necessary to rely on the Markov chain to regress step by step (
The genius of DDIM is that it breaks the rule of having to retreat step by step. It suggests that as long as I ensure the final edge distribution remains the same, I can do whatever I want in between! Thus, DDIM forcibly created a new formula for generating
DDIM believes that the data
Let’s write out these three parts in detail (don’t worry about the length; we’ll break it down):
Let’s translate these three parts one by one:
- Part 1 (pointing toward
): The expression in parentheses is the predicted in Step 3. Multiplying it by determines how much of the signal to retain. - Part 2 (pointing in the direction of
): For a smooth transition, we add back some of the predicted noise . The coefficient keeps the total variance consistent. - Part 3 (random noise):
is a controllable variance parameter, and is newly sampled random noise.
Step 5: The Moment of Witnessing the Miracle — Why It Speeds Up?
The above formula is the diffusion model sampling formula for generalization. Next comes where DDIM comes into play:
Manipulation 1: Let
The paper author of DDIM pointed out that if we directly remove the randomness, that is, set the variance parameter
At this point, Part 3 in the formula disappears directly!
What does this mean? It means that the process from
Manipulation 2: Accelerated Sampling
If you look closely at this simplified formula, you will find that: When calculating
The
In other words, we can set the time steps as a subsequence. For example, we can directly jump from
This has achieved a massive leap. Originally, it required 1,000 iterations, but now by jumping every 50 steps, we can get the final result in just 20 iterations! This is the fundamental principle of DDIM acceleration.
Summary
- We used the large model to predict the current noise
. - Using this noise, we derived clean data
. - DDIM constructed a new formula that combines the predicted
and the predicted noise in a specific ratio to directly compute a deterministic prior state. - Since the formula no longer relies on the strict continuity of the Markov chain, we can “compute step by step” with greater efficiency, achieving several times or even dozens of times faster computation.
First level of decryption: How to prove that it can directly jump from to ?
To prove this formula, we need to first prepare a very basic statistical “trick theorem” (additivity of the normal distribution):
Theorem: If you have two independent normal distribution variables, each with variance
and variance , when combined, the resulting variable is still normal, and the variance adds up, equaling .
In the diffusion model, we define the single-step noisy process as follows (just adding a little bit of noise each time):
All the
Now, we will challenge ourselves to represent
Substitute the formula of
We break down the parentheses:
The moment to witness the miracle has arrived! We use the “hack theorem” mentioned above to combine these two masses of noise:
The variance of the first lump of noise is:
The variance of the second noise patch is:
According to the theorem, when two noises are added together, the variance adds up:
In other words, after combining these two clusters of noise, they become a completely new standard noise with a variance of
Look! The
If we define
By following this pattern, if we substitute the template repeatedly into step
Conclusion: Due to the remarkable cancellation and combination properties of noise addition in a normal distribution, we can directly calculate the noisy result at step
Second Level Decryption: Why Does the DDIM Generation Formula Split into Three Parts?
This is not fabricated out of thin air, but rather the author has “compiled” a distribution that meets the requirements by reverse-engineering it.
1. What is the ultimate goal of DDIM author?
The core concept of DDIM is: No matter how the denoising process proceeds in reverse, I must ensure that the image at any
In other words,
2. “Decomposition” of Total Noise (Core Principle)
Now, we have three known pieces of information:
- The predicted clean image (
) - The current noisy image (
) - The noise patch we predicted, included in
( )
In the above ultimate target formula, the variance of “total noise” (or its total intensity) must be
The author thought: If I turn all this “total noise” into random noise, it will be a regular DDPM, and the result will be different each time. Can I “split” this total noise into two parts?
- One part is deterministic: Replace it with the noise
that has been predicted by our large model, so it has a definite direction (pointing to ). - One part is stochastic: Introduce a little bit of completely random noise
, and we set its variance to .
Just like dividing a cake, the total variance budget is
Since I have allocated a share to “random noise”
3. Assemble and Form
According to the above “dividing the cake” logic, we rewrite the original
Apply the corresponding variance coefficient:
Finally, since we don’t know the actual
This is the origin of the “three parts”!
It has no magic. Its principle is: while maintaining the total variance (noise intensity) unchanged, it skillfully divides the noise into a “predictable part” and a “purely random part.” When we set the purely random part (variance
Core Theorem: The Square Scaling Property of Variance
In probability theory, if you have a random variable
Written as a formula is:
Apply the theorem to our derivation
In the diffusion model, all our base noise
The standard normal distribution has one of the most important characteristics: its mean is 0, and its variance is 1.
That is to say:
Now, let’s look at the first chunk of noise you captured:
Let’s calculate the variance of this entire block:
- The constant
is strictly maintained here. - According to the theorem above, the variance of this quantity equals
. - When we square
, the square root is directly eliminated, resulting in: . - Additionally, considering the variance of the base noise
. - Therefore, the final variance is
.
Similarly, let’s look at the second lump of noise:
Its variance is the square of the coefficient multiplied by 1, that is:
Last step: Combine and repackage again
Because
Now, we have obtained the total variance of these two lumps of noise combined, which is
But we need to rewrite it back into the formula! What is needed in the formula is a coefficient multiplied by a standard noise.
Based on reverse derivation: Since the variance is
Therefore, the combined noise term is naturally written as:
In the Diffusion Policy of embodied AI (such as controlling a robotic arm to grab a cup), the output from the large model is no longer an image, but a sequence of robot actions (such as joint angles for the next 16 steps).
The following minimalistic Python pseudocode demonstrates how the DDIM formula we just derived operates at high speed in a robot’s brain:
Python# 假设我们训练好了一个扩散大模型 (U-Net),它能根据看到的画面预测动作里的噪声
# robot_camera_image: 机器人当前看到的画面 (作为生成动作的条件)
def ddim_fast_sample(robot_camera_image, unet_model, total_train_steps=1000, jump_steps=10):
"""
使用 DDIM 加速生成机器人动作轨迹
原本需要 1000 步,现在我们只跳跃计算 10 步 (极大提升速度,满足实时控制)
"""
# 1. 初始化:凭空捏造一条完全随机的动作轨迹 (纯噪声)
# 比如:随机生成未来 16 步的关节运动指令,这时的动作完全是乱抖的
action_t = generate_random_noise(shape=(16, joint_dim))
# 2. 规划跳步路线:比如从 1000 跳到 900, 800 ... 一直到 0
timesteps = get_jump_sequence(total_train_steps, jump_steps)
# 3. 核心逆向去噪循环 (DDIM 开始发威)
for i in range(len(timesteps)):
t = timesteps[i] # 当前时间步
t_prev = timesteps[i+1] if i < len(timesteps)-1 else 0 # 下一个要跳到的时间步
# [对应数学推导]:大模型登场!根据当前的乱码动作和看到的画面,预测出里面的噪声
predicted_noise = unet_model(action_t, t, condition=robot_camera_image)
# [对应数学推导的移项公式]:用当前带噪动作和预测的噪声,反推算出完全干净的完美动作 (x_0)
predicted_x0 = calculate_clean_x0(action_t, predicted_noise, t)
# [对应数学推导的三部分拼装]:DDIM 的确定性公式
# 这里直接消除了随机方差项 (sigma_t = 0),只用 x_0 和 预测噪声 组合出 t_prev 步的动作
action_t = ddim_assemble_formula(predicted_x0, predicted_noise, t_prev)
# 循环结束,这时的 action_t 已经从一团乱码,变成了一套极其平滑、精准的抓取动作!
return action_t
# ==========================================
# 机器人的真实物理控制循环 (例如每秒执行 10 次)
# ==========================================
while robot_is_turned_on:
# A. 睁开眼睛,看看当前环境
current_image = get_camera_frame()
# B. 大脑飞速运转:调用上面的 DDIM 算法,仅用 10 步算出未来 16 步的动作
action_trajectory = ddim_fast_sample(current_image, my_diffusion_model)
# C. 具身智能的特殊技巧:Receding Horizon Control (滚动时域控制)
# 虽然预测了未来 16 步,但为了应对突发情况,我们只执行前 8 步,然后重新看、重新算!
execute_on_physical_robot(action_trajectory[0:8])
Three key points in the pseudocode:
condition=robot_camera_image(Conditional Control): This is the essence of embodied AI. Traditional diffusion models generate images from text, while in embodied AI, the model uses the current visual scene to guide noise prediction, thereby generating actions that fit the current environment.- Only 10 iterations (fast inference): Thanks to the DDIM step formula
ddim_assemble_formula, which would originally requireforto run 1000 times, now only 10 or 20 iterations are needed. This reduces the computation delay from several seconds to just dozens of milliseconds, allowing the robot to move smoothly without lagging. - Receding Horizon execution: In the final main loop, the robot predicts a long sequence of actions each time, but executes only a small portion. This is similar to driving: the eyes look into the distance (predicting 16 steps), but the hands control the steering wheel in front of them (executing 8 steps), and this process repeats continuously—ensuring safety and robustness.