A delivery robot learns from a hundred human drives around a pretzel cart. Half went left, half went right. A model that averages them drives straight into the cart. This lab fogs the route map, lifts the fog in passes, and drives the robot with the result: the real DDPM and DDIM math from Unit 1 of the Hugging Face Diffusion Models Course, pointed at the reason robotics cares. About 75 minutes of play.
A courier robot has to get from the depot to the bakery. A pretzel cart sits in the road. The dispatcher drove the courier by joystick a hundred times and logged every drive: fifty went left around the cart, fifty went right, none through it. Those logs are the demonstrations, and the question of this lab is what to learn from them. Every term with a wavy red underline is tappable.
Covers HF Diffusion Course, Unit 1 overview: what a generative model is for · Diffusion Policy §4.1: multi-modal action distributions
Each drive is logged as a route sheet. Log a few by hand, then dump the whole book. Every dot on the map is one logged position from one drive, coloured by which way that drive went.
The simplest way to learn from the logs is behaviour cloning: fit a model that maps "where I am" to "where I go next", scored by mean squared error. Squared error has a fixed answer to an ambiguous question: the average of the plausible answers. Ask the clerk what the route is, and he averages every sheet in the book.
Diffusion's trick is to make a hard problem (draw a route) out of a thousand easy ones (make this slightly foggy map slightly clearer). To do that you first need fog you can control. The forward process mixes each logged position with Gaussian noise by an amount set by the timestep t, from 0 (clean) to 999 (pure fog). No learning happens here: it's arithmetic.
Covers notebook 02, "The corruption process" and notebook 01, step 3: DDPMScheduler, add_noise, the linear and cosine schedules
DDPM adds a little noise βt at each of 1,000 steps. You never apply it a thousand times: ᾱt = ∏(1 − βi) gives a shortcut straight to any t. Two knobs: √ᾱ is the map's volume and √(1−ᾱ) the fog's; their squares always sum to 1, so the fog replaces the map instead of piling on top of it.
Linear is diffusers' default (β from 0.0001 to 0.02): half fog by t ≈ 260. Cosine (squaredcos_cap_v2) fogs slowly at first: half fog by t ≈ 500. Notebook 01 trains with cosine, and so does Diffusion Policy.
Now the learned half. The denoiser is a network (a UNet in the course, a 1-D one in Diffusion Policy) trained on millions of (foggy map, true map) pairs at every fog level, scored by squared error. Here she is the cartographer, and here you can watch her best single guess: for every foggy dot, the clean guess x̂₀ she would draw. Under the hood this lab uses the exact best guess for the toy data, which is what a perfectly trained network converges to.
Covers notebook 02, "The model" and "Training the network": the blur at high noise · notebook 02, "Training objective": predicting ε vs predicting x₀
The toy in notebook 02 trains the network to output the clean map. DDPM (and notebook 01) trains it to output the noise that was added instead. They're the same prediction in different clothes: knowing the foggy map, t and the noise, you can solve the forward formula for the clean map. The chalk box does that for one dot.
If one guess from pure fog is a smudge, how does diffusion ever draw a real route? By not trusting the first guess. Start from pure fog, ask the cartographer for her guess, then lift only part of the fog toward it. Now the map leans, faintly, one way. Her next guess conditions on that lean and is less averaged. Repeat: each pass commits a little more, until the map has picked a side. This is the reverse process, and the rule for how much to lift per pass is the sampler.
Covers notebook 02, "Sampling": the 5-step and 40-step loops · notebook 01, step 6: scheduler.step() · notebook 02, "Sampling" (DDPM comparison): step size and churn
600 pins from 600 different fogs, for the schedule and sampler above. Each pin is one sampled position, where a route passes the cart; the wispy lines are the sampler's path through the fog, not the courier driving. Where variety comes from: the starting fog. Different fog, different side.
DDIMScheduler defaults to "leading", 900, 800, … 0, which never starts a chain at pure fog, so under it one pass wouldn't be the clerk.An image generator can take a second to draw a butterfly. A robot can't afford to: while the card is being drawn the courier stands still, and the lookout's report goes stale. Every pass is one run of the network, so passes cost time, and the time that matters is measured against the card itself: 8 pins at 10 pins a second (the paper's Ta = 8 at 10 Hz) is 0.8 s of driving. DDIM decouples training from inference: Diffusion Policy trains at 100 steps and samples in 10, and reports 0.1 s per card on an RTX 3080, an eighth of the card, which is where the 10 ms per pass below comes from. Sampling every step of this course's 1,000-step schedule would take 10 s: twelve cards' worth of driving spent standing still, on a report twelve cards old. The paper found position-control policies keep peak performance with latency of up to 4 steps.
Covers notebook 02, "Comparison to DDPM · Sampling": step size and fewer steps · Diffusion Policy §3.4: accelerating inference for real-time control
So far the cart never moved, so "draw a route" meant the same thing every day. A robot's world isn't like that. Diffusion Policy conditions the denoiser on the observation: the last two camera frames, each encoded by a ResNet-18, plus the robot's end-effector pose. Its CNN variant injects that into every layer of the network with FiLM; its transformer variant feeds it in as tokens. In the square, that's the lookout's report: "cart at +0.7 today." With it on her desk, the cartographer draws routes around where the cart is. Blindfolded, she draws them around where it used to be.
Covers Diffusion Policy §3.1: FiLM conditioning on Oₜ · contrast with Unit 2, notebook 02: class labels concatenated as input channels
Everything so far, put on the road. The cartographer no longer draws one dot: she draws a card of 16 pins (the paper's Tp = 16), the courier drives the first 8 (Ta = 8), then the lookout sends a fresh report and she draws a new card. Predict a short horizon, execute the first part, re-plan: receding-horizon control, the model-predictive-control idea running on a diffusion sampler. Every card here is denoised from fresh fog with the passes you pick (DDIM, η = 0). Benchmarked across 15 tasks from 4 suites, the paper's policy beat the prior state of the art by 46.9% on average. The newer action heads in π0 and GR00T N1 swap diffusion for flow matching, a relative that needs fewer passes; the picture is the same.
Covers Diffusion Policy §3: To = 2, Tp = 16, Ta = 8, DDIM at 10 steps · §4.3: the trade-off in Ta · model-predictive control's receding horizon
Three dispatch rules came back with incident reports. For each: run the rule as dispatched, pick a fix, re-drive twenty times, and name the cause. The tempting wrong fixes are on the list, and they fail for the reason the step taught. Each case is scored on the re-drive and the cause.
Eight questions. Answer each by operating the widget in the step named, not from memory. Six or more earns the check.
squaredcos_cap_v2) schedules built the way diffusers builds them; the denoiser, which is the exact Bayes posterior mean E[x₀ | x_t] for the toy demonstration distribution (what a perfectly trained noise-prediction network converges to, with no training error); the ε ↔ x̂₀ conversion; DDIM sampling with η (Song et al., 2021, eq. 12) on diffusers' "trailing" timestep spacing (999, 899, …; its DDIMScheduler defaults to "leading"); the mixture mean as the squared-error-optimal single guess; and every number quoted from the Diffusion Policy paper.Sources: the Hugging Face Diffusion Models Course, Unit 1 (both notebooks) · Ho, Jain & Abbeel, Denoising Diffusion Probabilistic Models (2020) · Song, Meng & Ermon, Denoising Diffusion Implicit Models (2021) · Nichol & Dhariwal, Improved DDPM (2021) for the cosine schedule · Chi et al., Diffusion Policy: Visuomotor Policy Learning via Action Diffusion (2023) for Tp/Ta/To, DDIM at 10 steps, 0.1 s on an RTX 3080, FiLM, the square cosine schedule and the 46.9% figure. Further reading: The Annotated Diffusion Model, and lerobot/diffusion_pusht for a real Diffusion Policy you can run.