Denoising diffusion probabilistic models (DDPM)
4.5.11· AI-ML › Generative Models
Overview
Denoising Diffusion Probabilistic Models (DDPMs) generative models hain jo data create karna seekhte hain ek gradual noising process ko reverse karke. Data distribution ko directly seekhne ki jagah, yeh models ek Markov chain ke har step par denoising seekhte hain, jisse learning problem tractable ban jaati hai.
Yeh kyun kaam karta hai: Chhote denoising steps Gaussian distributions ko approximate karte hain (Central Limit Theorem ki wajah se), jinhe hum neural networks se model karna jaante hain.
The Forward Diffusion Process
Yeh Kya Karta Hai
Forward process dheere dheere data mein Gaussian noise add karta hai timesteps ke upar, structure ko tabah karta hai jab tak sirf pure noise nahi bach jaati.
jahaan ek variance schedule hai jisme .
Yeh Form Kyun?
se multiply kyun karte hain? Total variance ko control karne ke liye. Agar hum sirf noise add karte, toh variance unboundedly badhta: . Scaling factor variance ko stable rakhta hai.
Derivation from scratch: ko variance ke saath shuru karte hue:
Phir:
Agar hum chahte hain (unit variance), toh initial data normalized hona chahiye. Yeh property math ko enormously simplify kar deti hai.
Yeh powerful kyun hai: Hum ko KISI BHI timestep par directly se sample kar sakte hain, bina saare intermediate steps iterate kiye!
Derivation:
substitute karte hue:
Kyunki dono noise terms Gaussian hain, yeh combine ho jaate hain:
Simplify karte hue:
steps ke liye induction se: .

The Reverse Process (Generation)
Hum Kya Chahte Hain
Data generate karne ke liye, humein diffusion ko reverse karna hai: noise se shuru karke dheere dheere tak denoise karna hai.
Saccha reverse process intractable hai kyunki iske liye poori data distribution jaanna zaroori hai. Lekin par conditioned hone par, reverse step Gaussian hoti hai!
jahaan:
Yeh form kyun? Yeh do Gaussians ko multiply karke aur square complete karke aata hai.
Derivation from Bayes:
Dono Gaussians hain. ke liye, log density hai .
Expand karte hue:
Sum karo aur terms collect karo variance ke liye, linear terms mean ke liye. Algebra se aur milta hai.
Learned Reverse Process
Hum reverse ko ek neural network se approximate karte hain:
Training Objective
Variational Lower Bound
Negative log-likelihood ka ek variational lower bound hai:
Yeh in terms mein decompose hota hai:
Yeh terms kyun?
- Pehla term: Hamari final noise standard Gaussian se kitni door hai? (Koi parameters nahi, ignore karo)
- Middle sum: Hamara learned reverse, true reverse se kitna match karta hai?
- Aakhri term: Reconstruction likelihood
jahaan aur .
Mean ki jagah noise predict kyun karte hain? Kyunki hum reparameterize kar sakte hain:
Noise predict karna empirically ya directly predict karne se better kaam karta hai—yeh timesteps ke across ek zyada stable learning target hai.
Reparameterization ki derivation: se, ke liye solve karo:
formula mein substitute karo aur use karke simplify karo upar wali form paane ke liye.
Step 1: Ek training image sample karo (jaise ek billi ki photo, tak normalized).
Step 2: Ek random timestep uniformly sample karo.
Step 3: Noise image ke same shape mein sample karo.
Step 4: compute karo (precomputed).
Step 5: Noised image banao:
Step 6: aur ko network mein feed karo, prediction lo.
Step 7: Loss compute karo: , backpropagate karo.
Yeh step kyun? par, image moderately noised hai. Network seekhta hai: "Diye hue specific noise level aur partially corrupted image ke saath, exactly woh noise predict karo jo add ki gayi thi." Bahut saare examples mein, bahut saare timesteps par, yeh full denoising distribution seekh leta hai.
Sampling (Generation)
Step 1: sample karo (pure noise, jaise random numbers ka tensor).
Step 2: ke liye:
- Noise predict karo:
- Mean compute karo:
- Noise sample karo agar , warna
- Update karo:
Step 3: return karo (generated image).
Har step mein noise kyun? Reverse process stochastic hai—hum ek distribution se sample kar rahe hain, koi deterministic function compute nahi kar rahe. Added noise reverse step mein uncertainty account karta hai.
par noise kyun nahi? Final step mein, hum ka mode (most likely value) chahte hain, jo mean hai.
Key Design Choices
Variance Schedule
Common choices:
- Linear:
- Cosine: jahaan
Network Architecture
Typically ek U-Net hota hai jisme:
- Timestep sinusoidal positional encoding ke roop mein embed hota hai
- Skip connections dono high aur low-level features pass karne ke liye
- Global structure capture karne ke liye Self-attention layers
U-Net kyun? Denoising task ke liye dono local (texture) aur global (object shape) context chahiye. U-Net ki architecture ismein excel karti hai.
DDPMs ke Advantages
- High-quality samples: State-of-art image generation quality (GANs ke saath competitive FID scores)
- Stable training: Koi adversarial dynamics nahi, sirf noise prediction par regression
- Flexible: Condition karna aasaan (class labels, text, etc.) mein conditioning add karke
- Probabilistic: Explicit likelihood bound, GANs ke unlike
Class labels ke saath train karo. Generation time par:
- Class sample karo (ya choose karo)
- ke saath sampling algorithm chalao
Result: Specified class ki images. Yeh text conditioning tak extend hota hai (CLIP ke zariye text embeddings) text-to-image models jaise Stable Diffusion ke liye.
Common Mistakes
Steel-man: Chhoti noise ke liye, single-step denoising (jaise denoising autoencoders) theek kaam karta hai. "Simpler is better" ki intuition generally sound hai.
Yeh galat kyun hai: Pure noise → structured image ek bahut hi complex mapping hai. Distribution multimodal, sharply peaked structure rakhti hai—single neural network pass ke liye intractable. chhote steps mein todne se, har step ek Gaussian approximate karta hai (unimodal, smooth), jise networks aasaani se model kar sakti hain.
Fix: Iterative nature accept karo. Bahut saare steps hi problem ko learnable banate hain. (Modern research better schedules aur distillation se steps kam karta hai, lekin fundamentally multiple steps zaroori hain.)
Yeh galat kyun hai: Ek bura schedule (jaise bahut jaldi zyada noise) early timesteps ko unlearnable bana deta hai—network signal ko noise se distinguish nahi kar sakta. Bahut slow schedule redundant easy denoising steps par capacity waste karta hai.
Fix: Proven schedules use karo (images ke liye cosine). Schedule ek hyperparameter hai jo model ke learning ki difficulties ka curriculum shape karta hai.
Yeh galat kyun hai: Empirically, predict karna faster convergence aur better sample quality deta hai. Reason: timesteps ke across ek zyada balanced target hai (hamesha same distribution), jabki high noise levels par prediction poorly constrained hoti hai.
Fix: Noise prediction parameterization use karo (ya velocity prediction, ek newer variant). Architectural choices ke liye empirical evidence ko guide karne do.
Connections to Other Concepts
- Score-based generative models: DDPMs score matching ke equivalent hain Langevin dynamics ke saath; score approximate karta hai
- Variational Autoencoders (VAE): DDPMs similar ELBO optimize karte hain, lekin fixed encoder (forward process) ke saath
- Stochastic Differential Equations: DDPMs ka continuous-time limit ek reverse-time SDE deta hai
- Markov Chain Monte Carlo: Sampling iterative refinement hai, MC jaisi, lekin learned transitions ke saath
- U-Net architecture: Image DDPMs mein ka backbone
- Classifier-free guidance: Conditional aur unconditional predictions mix karke conditional generation strengthen karne ki technique
- Latent diffusion models: Efficiency ke liye compressed latent space (VAE encoder) mein diffusion chalao—Stable Diffusion ka basis
Ya yaad rakho: "Forward fuzes, backward builds"—forward process images ko noise mein fuse karta hai, backward unhe wapas build karta hai.
Recall Ek 12-saal ke bachche ko Explain Karo
Socho tumhare paas ek sundar painting hai, aur koi dheere dheere uske upar 1000 seconds mein raat baraata hai. Har second, thodi aur raat painting ko dhak deti hai, jab tak ki end mein, tum painting bilkul nahi dekh sakte—sirf raat.
Ab, agar tumhare paas ek jaadu ka tool hota jo raat ko ek second ek time par, reverse mein, hata sakta? Second 999 par, yeh thodi si raat hataata hai aur tumhe rang ki ek chhoti si jhalak dikhti hai. Second 500 par, tum shapes dekhna shuru kar sakte ho. Second 1 tak, painting phir se saaf hai.
Yahi ek diffusion model karta hai! Computer us jaadu ke tool banna seekhta hai. Hum usse bahut saari paintings dikhate hain jo raat se dhaaki ja rahi hain (yeh forward process hai—noise add karna). Phir hum use unhe step by step un-cover karna sikhate hain (yeh reverse process hai—noise remove karna). Ek baar jab yeh seekh jaata hai, hum pure raat (random noise) se shuru kar sakte hain aur ise ek aisi painting "uncover" karne de sakte hain jo pehle kabhi thi hi nahi—yeh destruction process ko reverse karke naya art create kar raha hai!
Clever part yeh hai: ek baar mein saari raat hatana seekhna bahut mushkil hai. Lekin thodi thodi raat ek baar mein hatana? Woh bahut aasaan hai, jaise ek baar mein ek speck of dust saaf karna rather than poora ghar saaf karna. Toh hum problem ko 1000 chhote chhote cleaning steps mein tod dete hain, aur computer har ek mein bahut achha ho jaata hai.
Practice Questions
#flashcards/ai-ml
DDPM mein forward diffusion process kya hai? :: Ek Markov chain jo dheere dheere data mein T timesteps ke upar Gaussian noise add karta hai: , structure ko tabah karta hai jab tak sirf noise nahi bach jaati.
Forward process sirf noise add karne ki jagah se multiply kyun karta hai?
se directly sample karne ka closed-form kya hai? :: jahaan . Yeh bina iterate kiye kisi bhi timestep par jump karne deta hai.
DDPM neural network kya predict karna seekhta hai?
DDPM ka simplified training objective kya hai? :: jahaan aur .
Reverse process mean compute karne ke liye ka use kaise karte hain?
Generation ke liye sampling algorithm kya hai?
Original image ki jagah noise predict kyun karte hain?
Variance schedule ka kya role hai? :: Yeh control karta hai ki forward process mein noise kitni jaldi add hoti hai. Ek achha schedule timesteps ke across learning difficulty balance karta hai—bahut jaldi early steps ko unlearnable banata hai, bahut dheere capacity easy steps par waste karta hai. Common: linear ya cosine schedules.