Lab 02: Denoising Step
Annotated code reading lab. Running code is optional.
Denoising Step
This lab maps directly to the handbook section. Read the related handbook section first, then use the lab page and starter file to connect the concept to concrete variables, shapes, APIs, and interview-ready explanations.
Denoising Step
Read one reverse update as model prediction plus scheduler math.
Mechanism to keep in mind
- `model_input` is the current noisy latent.
- `noise_pred` is the denoiser output.
- `scheduler.step` owns the numeric update rule.
Annotated Code Preview
Open starter fileStarter preview
Excerpt from code/lab-02-denoising-step/denoising_step.py. The linked starter file is the source of truth.
# Denoising Step
# Annotated reading material. Running this file is optional.
# Source-of-truth focus: Read one reverse update as model prediction plus scheduler math.
latent = "x_t"
timestep = 500
noise_pred = f"unet({latent}, t={timestep}, condition=prompt_embeds)"
latent_prev = f"scheduler.step({noise_pred}, {timestep}, {latent})"
# What to explain while reading:
# - model_input is the current noisy latent.
# - noise_pred is the denoiser output.
# - scheduler.step owns the numeric update rule.
#
# Common traps:
# - Do not assume the model outputs pixels.
# - Do not mix epsilon, v-prediction and sample prediction without checking config.
What each block is doing
- Setup / contract
- `model_input` is the current noisy latent.
- Main transition
- `noise_pred` is the denoiser output.
- Interview hook
- `scheduler.step` owns the numeric update rule.
Reading checkpoints
- The model and scheduler have separate responsibilities.
- Prediction type must match scheduler expectations.
- One step is not the whole image generator.
What this lab prevents
- Do not assume the model outputs pixels.
- Do not mix epsilon, v-prediction and sample prediction without checking config.
How to say it out loud
Read one reverse update as model prediction plus scheduler math. Then explain the code by naming the state being transformed, the axis or shape that matters, and the tradeoff that would appear in a real system.
Additional intuition
- Use official docs and papers for API behavior and factual claims; use blogs only to improve the mental picture.
- If support matrices, performance behavior or backend choices are version-sensitive, check current docs before repeating them.
- A strong interview answer names the state object, the shape or axis it changes, and the tradeoff it creates.
