logo Mr.Robota 具身智能学习手册 中文
Chapter 12: 12 Interview Questions

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 X∼N(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2) (with a mean of μ\mu and a variance of σ2\sigma^2), we can break it down as follows:

X=μ+σ⋅ϵX = \mu + \sigma \cdot \epsilon

Here, ϵ\epsilon is a standard normal distribution pure noise ϵ∼N(0,1)\epsilon \sim \mathcal{N}(0, 1).

In simple terms: Any state = a definite base value + (random noise ×\times noise intensity). Remember this formula; it is the core of the entire derivation.


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 x0x_0. We continuously add noise to it, and by step tt, it becomes xtx_t.

DDPM proves a highly important conclusion: We don’t need to add noise step by step; we can directly jump from x0x_0 to xtx_t in one go.

The formula is as follows:

xt=αˉtx0+1−αˉtϵx_t = \sqrt{\bar{\alpha}_t} x_0 + \sqrt{1 - \bar{\alpha}_t} \epsilon
  • x0x_0: Initial clean data.
  • xtx_t: Noisy data from step tt.
  • αˉt\bar{\alpha}_t: A coefficient between 0 and 1. You can consider it as “signal retention rate”. As the number of steps tt increases, αˉt\bar{\alpha}_t becomes smaller (approaching 0).
  • 1−αˉt1 - \bar{\alpha}_t: “noise intensity”.
  • ϵ\epsilon: Pure noise following a standard normal distribution.

In one sentence: The data xtx_t in step tt is “clean data after attenuation” plus “gradually increasing noise.”


Step 3: Reverse Thinking — How to Guess x0x_0 from xtx_t?

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 xtx_t. Its task is: to predict what the noise ϵ\epsilon in this data is.

Assume we have trained a large divine model, denoted as ϵθ(xt,t)\epsilon_\theta(x_t, t). It can accurately predict the noise in the current xtx_t.

Since the noise has been guessed, can we use the formula from step 2 to backtrack (guess) out the clean x0x_0?

We move and transform the formula xt=αˉtx0+1−αˉtϵx_t = \sqrt{\bar{\alpha}_t} x_0 + \sqrt{1 - \bar{\alpha}_t} \epsilon in the second step to obtain x0x_0:

预测的 x0=xt−1−αˉt⋅ϵθ(xt,t)αˉt\text{预测的 } x_0 = \frac{x_t - \sqrt{1 - \bar{\alpha}_t} \cdot \epsilon_\theta(x_t, t)}{\sqrt{\bar{\alpha}_t}}

(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 tt.


Step 4: The Core Magic of DDIM — Reassembling xt−1x_{t-1}

In traditional DDPM, it is necessary to rely on the Markov chain to regress step by step (xt→xt−1→xt−2x_t \rightarrow x_{t-1} \rightarrow x_{t-2}).

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 xt−1x_{t-1}.

DDIM believes that the data xt−1x_{t-1} in step t−1t-1 can be assembled from three parts:

xt−1=部分1+部分2+部分3x_{t-1} = \text{部分1} + \text{部分2} + \text{部分3}

Let’s write out these three parts in detail (don’t worry about the length; we’ll break it down):

xt−1=αˉt−1⋅(xt−1−αˉt⋅ϵθ(xt,t)αˉt)⏟部分1:指向预测的 x0+1−αˉt−1−σt2⋅ϵθ(xt,t)⏟部分2:指向 xt 的方向+σt⋅ϵt⏟部分3:随机噪声x_{t-1} = \underbrace{\sqrt{\bar{\alpha}_{t-1}} \cdot \left( \frac{x_t - \sqrt{1 - \bar{\alpha}_t} \cdot \epsilon_\theta(x_t, t)}{\sqrt{\bar{\alpha}_t}} \right)}_{\text{部分1:指向预测的 } x_0} + \underbrace{\sqrt{1 - \bar{\alpha}_{t-1} - \sigma_t^2} \cdot \epsilon_\theta(x_t, t)}_{\text{部分2:指向 } x_t \text{ 的方向}} + \underbrace{\sigma_t \cdot \epsilon_t}_{\text{部分3:随机噪声}}

Let’s translate these three parts one by one:

  1. Part 1 (pointing toward x0x_0): The expression in parentheses is the x0x_0 predicted in Step 3. Multiplying it by αˉt−1\sqrt{\bar{\alpha}_{t-1}} determines how much of the x0x_0 signal to retain.
  2. Part 2 (pointing in the direction of xtx_t): For a smooth transition, we add back some of the predicted noise ϵθ(xt,t)\epsilon_\theta(x_t, t). The coefficient 1−αˉt−1−σt2\sqrt{1 - \bar{\alpha}_{t-1} - \sigma_t^2} keeps the total variance consistent.
  3. Part 3 (random noise): σt\sigma_t is a controllable variance parameter, and ϵt\epsilon_t 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 σt=0\sigma_t = 0 (eliminate randomness)

The paper author of DDIM pointed out that if we directly remove the randomness, that is, set the variance parameter σt=0\sigma_t = 0.

At this point, Part 3 in the formula disappears directly!

xt−1=αˉt−1⋅(预测的 x0)+1−αˉt−1⋅ϵθ(xt,t)x_{t-1} = \sqrt{\bar{\alpha}_{t-1}} \cdot (\text{预测的 } x_0) + \sqrt{1 - \bar{\alpha}_{t-1}} \cdot \epsilon_\theta(x_t, t)

What does this mean? It means that the process from xtx_t to xt−1x_{t-1} becomes deterministic! As long as the input noise is constant, no matter how many times it is generated, the result will be exactly the same. This is crucial for the stability of embodied AI robots!

Manipulation 2: Accelerated Sampling

If you look closely at this simplified formula, you will find that: When calculating xt−1x_{t-1}, we only use xtx_t, the prediction of the large model ϵθ\epsilon_\theta, and αˉt−1\bar{\alpha}_{t-1}.

The t−1t-1 here is just a symbol; it doesn’t have to be the previous integer!

In other words, we can set the time steps as a subsequence. For example, we can directly jump from t=1000t=1000 to t=900t=900, and use 900900 as “t−1t-1” in the formula for calculation.

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

  1. We used the large model to predict the current noise ϵθ\epsilon_\theta.
  2. Using this noise, we derived clean data x0x_0.
  3. DDIM constructed a new formula that combines the predicted x0x_0 and the predicted noise in a specific ratio to directly compute a deterministic prior state.
  4. 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 x0x_0 to xtx_t?

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 AA and variance BB, when combined, the resulting variable is still normal, and the variance adds up, equaling A+BA + B.

In the diffusion model, we define the single-step noisy process as follows (just adding a little bit of noise each time):

x1=α1x0+1−α1ϵ0x_1 = \sqrt{\alpha_1} x_0 + \sqrt{1 - \alpha_1} \epsilon_0
x2=α2x1+1−α2ϵ1x_2 = \sqrt{\alpha_2} x_1 + \sqrt{1 - \alpha_2} \epsilon_1

All the ϵ0,ϵ1\epsilon_0, \epsilon_1s here are pure noise following a standard normal distribution (mean = 0, variance = 1). The coefficient α\alpha is what we call “signal retention rate”.

Now, we will challenge ourselves to represent x2x_2 directly using x0x_0:

Substitute the formula of x1x_1 directly into the formula of x2x_2:

x2=α2(α1x0+1−α1ϵ0)+1−α2ϵ1x_2 = \sqrt{\alpha_2} (\sqrt{\alpha_1} x_0 + \sqrt{1 - \alpha_1} \epsilon_0) + \sqrt{1 - \alpha_2} \epsilon_1

We break down the parentheses:

x2=α1α2x0+α2(1−α1)ϵ0+1−α2ϵ1⏟这里是两坨噪声相加x_2 = \sqrt{\alpha_1 \alpha_2} x_0 + \underbrace{\sqrt{\alpha_2(1 - \alpha_1)} \epsilon_0 + \sqrt{1 - \alpha_2} \epsilon_1}_{\text{这里是两坨噪声相加}}

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: α2(1−α1)=α2−α1α2\alpha_2(1 - \alpha_1) = \alpha_2 - \alpha_1 \alpha_2

The variance of the second noise patch is: 1−α21 - \alpha_2

According to the theorem, when two noises are added together, the variance adds up:

(α2−α1α2)+(1−α2)=1−α1α2(\alpha_2 - \alpha_1 \alpha_2) + (1 - \alpha_2) = 1 - \alpha_1 \alpha_2

In other words, after combining these two clusters of noise, they become a completely new standard noise with a variance of 1−α1α21 - \alpha_1 \alpha_2 (we call it ϵˉ\bar{\epsilon}):

x2=α1α2x0+1−α1α2ϵˉx_2 = \sqrt{\alpha_1 \alpha_2} x_0 + \sqrt{1 - \alpha_1 \alpha_2} \bar{\epsilon}

Look! The x1x_1 in the middle has disappeared perfectly!

If we define αˉt=α1×α2×...×αt\bar{\alpha}_t = \alpha_1 \times \alpha_2 \times ... \times \alpha_t for convenience of writing (i.e., the product of the signal retention rates at the previous tt steps),

By following this pattern, if we substitute the template repeatedly into step tt, we will obtain the core conclusion:

xt=αˉtx0+1−αˉtϵx_t = \sqrt{\bar{\alpha}_t} x_0 + \sqrt{1 - \bar{\alpha}_t} \epsilon

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 tt without going through the intermediate x1,x2...x_1, x_2....


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 t−1t-1 step xt−1x_{t-1} adheres to the forward formula we derived in the first step.

In other words, xt−1x_{t-1} must meet the following requirements:

xt−1=αˉt−1x0+1−αˉt−1⋅(总噪声)x_{t-1} = \sqrt{\bar{\alpha}_{t-1}} x_0 + \sqrt{1 - \bar{\alpha}_{t-1}} \cdot (\text{总噪声})

2. “Decomposition” of Total Noise (Core Principle)

Now, we have three known pieces of information:

  1. The predicted clean image (x0x_0)
  2. The current noisy image (xtx_t)
  3. The noise patch we predicted, included in xtx_t (ϵθ\epsilon_\theta)

In the above ultimate target formula, the variance of “total noise” (or its total intensity) must be 1−αˉt−11 - \bar{\alpha}_{t-1}.

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 ϵθ\epsilon_\theta that has been predicted by our large model, so it has a definite direction (pointing to xtx_t).
  • One part is stochastic: Introduce a little bit of completely random noise ϵt\epsilon_t, and we set its variance to σt2\sigma_t^2.

Just like dividing a cake, the total variance budget is 1−αˉt−11 - \bar{\alpha}_{t-1}:

Since I have allocated a share to “random noise” σt2\sigma_t^2, the remaining share for “deterministic noise” is only:

(1−αˉt−1)−σt2(1 - \bar{\alpha}_{t-1}) - \sigma_t^2

3. Assemble and Form

According to the above “dividing the cake” logic, we rewrite the original xt−1x_{t-1} formula:

xt−1=干净信号部分+确定性噪声部分+随机噪声部分x_{t-1} = \text{干净信号部分} + \text{确定性噪声部分} + \text{随机噪声部分}

Apply the corresponding variance coefficient:

xt−1=αˉt−1⋅x0⏟干净信号部分+1−αˉt−1−σt2⋅ϵθ⏟确定性噪声部分+σt⋅ϵt⏟随机噪声部分x_{t-1} = \underbrace{\sqrt{\bar{\alpha}_{t-1}} \cdot x_0}_{\text{干净信号部分}} + \underbrace{\sqrt{1 - \bar{\alpha}_{t-1} - \sigma_t^2} \cdot \epsilon_\theta}_{\text{确定性噪声部分}} + \underbrace{\sigma_t \cdot \epsilon_t}_{\text{随机噪声部分}}

Finally, since we don’t know the actual x0x_0, we can only replace x0x_0 in the formula with x0x_0 (that is, the expression derived from middle school algebra transposition, as you mentioned) predicted by the large model.

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 σt\sigma_t) to 0, the entire process becomes a completely deterministic acceleration step.


Core Theorem: The Square Scaling Property of Variance

In probability theory, if you have a random variable XX, its variance is Var(X)Var(X). If you multiply it by a constant cc, then the variance of the new variable is equal to the original variance multiplied by the square of the constant cc.

Written as a formula is:

Var(c⋅X)=c2⋅Var(X)Var(c \cdot X) = c^2 \cdot Var(X)

Apply the theorem to our derivation

In the diffusion model, all our base noise ϵ\epsilon (whether ϵ0,ϵ1\epsilon_0, \epsilon_1 or ϵt\epsilon_t) is defined as a standard normal distribution.

The standard normal distribution has one of the most important characteristics: its mean is 0, and its variance is 1.

That is to say: Var(ϵ)=1Var(\epsilon) = 1.

Now, let’s look at the first chunk of noise you captured:

α2(1−α1)⏟常数系数 c⋅ϵ0⏟随机变量 X\underbrace{\sqrt{\alpha_2(1 - \alpha_1)}}_{\text{常数系数 } c} \cdot \underbrace{\epsilon_0}_{\text{随机变量 } X}

Let’s calculate the variance of this entire block:

  1. The constant c=α2(1−α1)c = \sqrt{\alpha_2(1 - \alpha_1)} is strictly maintained here.
  2. According to the theorem above, the variance of this quantity equals c2⋅Var(ϵ0)c^2 \cdot Var(\epsilon_0).
  3. When we square cc, the square root is directly eliminated, resulting in: α2(1−α1)\alpha_2(1 - \alpha_1).
  4. Additionally, considering the variance of the base noise Var(ϵ0)=1Var(\epsilon_0) = 1.
  5. Therefore, the final variance is α2(1−α1)⋅1=α2(1−α1)\alpha_2(1 - \alpha_1) \cdot 1 = \alpha_2(1 - \alpha_1).

Similarly, let’s look at the second lump of noise:

1−α2⏟常数系数 c⋅ϵ1⏟随机变量 X\underbrace{\sqrt{1 - \alpha_2}}_{\text{常数系数 } c} \cdot \underbrace{\epsilon_1}_{\text{随机变量 } X}

Its variance is the square of the coefficient multiplied by 1, that is: (1−α2)2⋅1=1−α2(\sqrt{1 - \alpha_2})^2 \cdot 1 = 1 - \alpha_2.


Last step: Combine and repackage again

Because ϵ0\epsilon_0 and ϵ1\epsilon_1 are two completely independent random draws (independent and identically distributed), the total variance when they are combined is simply the sum of their individual variances (this is what we called the “hack theorem” earlier):

总方差=α2(1−α1)+(1−α2)=1−α1α2\text{总方差} = \alpha_2(1 - \alpha_1) + (1 - \alpha_2) = 1 - \alpha_1\alpha_2

Now, we have obtained the total variance of these two lumps of noise combined, which is 1−α1α21 - \alpha_1\alpha_2.

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 1−α1α21 - \alpha_1\alpha_2, then according to Var(c⋅X)=c2⋅Var(X)Var(c \cdot X) = c^2 \cdot Var(X), the new coefficient cc we are looking for must be the square root of the total variance.

Therefore, the combined noise term is naturally written as:

1−α1α2⋅ϵˉ\sqrt{1 - \alpha_1\alpha_2} \cdot \bar{\epsilon}($\bar{\epsilon}$)

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:

  1. 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.
  2. Only 10 iterations (fast inference): Thanks to the DDIM step formula ddim_assemble_formula, which would originally require for to 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.
  3. 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.