4.5.10 · HinglishGenerative Models

Diffusion models forward - reverse process

2,806 words13 min readRead in English

4.5.10 · AI-ML › Generative Models

The Big Picture

Traditional generative models (GANs, VAEs) ek hi baar mein data distribution seekhne ki koshish karte hain. Diffusion models ek bilkul alag approach lete hain: ye ek fixed forward process define karte hain jo gradually data ko destroy karta hai, phir ek reverse process seekhte hain jo us destruction ko undo kare.

Key insight yeh hai: Agar hum har noise level par data ko denoise karna seekh sakte hain, toh hum pure noise se shuru karke gradually denoise karte hue realistic samples tak pahunch sakte hain.

Figure — Diffusion models forward - reverse process

Forward Process (Diffusion): Systematic Noise Addition

Yeh Specific Form Kyun?

Gaussian noise kyun?

  • Central Limit Theorem guarantee karta hai ki bohot saare chote perturbations ka sum → Gaussian hoga
  • Gaussian distributions ke nice mathematical properties hain (closed-form posteriors)
  • Real-world noise aksar Gaussian characteristics rakhta hai

se shrink kyun karte hain?

  • Hum chahte hain ki variance har step par roughly constant rahe
  • Agar hum sirf noise add karte: → explode ho jaata
  • Shrinkage ke saath: small ke liye

Ek bada jump lene ki jagah bohot saare chote steps kyun?

  • Har step ek chhota, reversible perturbation hai
  • Neural networks chote steps ko zyada aasaani se reverse karna seekh sakte hain
  • Generation process par fine-grained control milta hai

Derivation: The Reparameterization Trick

Hum ko directly se sample kar sakte hain, bina saare intermediate steps se guzre:

Starting point:

Recursively expand karo:

Key observation: Independent Gaussians ka sum bhi Gaussian hota hai jisme variances add hote hain:

tak pahunchne ke liye expand karte raho. Define karo:

Yeh crucial kyun hai: Ab hum training ke liye random timesteps sample karke ko directly tak noise kar sakte hain, bina poori forward chain simulate kiye.

Example: Ek Image par Forward Process


Reverse Process (Denoising): Backwards Jaana Seekhna

Forward process data ko ek known tarike se destroy karta hai. Reverse process seekhta hai ki har noise-addition step ko undo kaise kiya jaaye.

Yeh Possible Kyun Hai?

Mathematical justification: Small ke liye, reverse conditional approximately Gaussian hota hai:

jahaan (Bayes' rule se):

Dikkat: Is formula ke liye jaanna zaroori hai, jo generation ke waqt hamare paas nahi hota!

Solution: Ek neural network se dekh kar predict karo.

Derivation: Noise Prediction Objective

Forward process reparameterization se:

Hum ke liye solve kar sakte hain:

Key insight: seedha predict karne ki jagah, wo noise predict karo jo add ki gayi thi! Yahi noise prediction parameterization hai.

Ek neural network train karo jo noisy aur timestep diye jaane par predict kare.

mein substitute karo:

Noise predict kyun karo ki jagah?

  • Empirically, networks noise predict karna zyada achha seekhte hain clean images se
  • Noise sabhi timesteps par zyada "uniform" hota hai (data domain par depend nahi karta)
  • Score matching se relate karta hai ( predict karna)

Training Objective

Training procedure:

  1. Ek training image sample karo
  2. Ek random timestep sample karo
  3. Noise sample karo
  4. Forward process formula se noisy image compute karo
  5. Neural network se noise predict karo
  6. True aur predicted noise ke beech MSE loss compute karo
  7. Backpropagate karo aur update karo

Example: Ek Denoising Step


Generation: Noise se Sampling

Ek baar train ho jaane ke baad, generation seedhi hai:

Algorithm:

  1. sample karo (pure noise)
  2. ke liye:
    • Noise predict karo:
    • Mean compute karo:
    • Sample karo: jahaan ,
  3. return karo

Time complexity: forward passes (standard DDPM ke liye 1000). Yeh GANs (1 pass) se slow hai lekin high-quality, diverse samples deta hai.


Common Mistakes & Misconceptions


Connections to Other Concepts

  • Score-based generative models: Diffusion models score function seekhne ke equivalent hain. Noise prediction, score se is tarah relate karta hai: .
  • Variational autoencoders: Diffusion models ko ek hierarchical VAE ki tarah dekha ja sakta hai jisme latent layers hain aur ek fixed encoder (forward process) hai.
  • Markov chains: Forward aur reverse dono processes Markov chains hain (memoryless: sirf par depend karta hai, poori history par nahi).
  • Langevin dynamics: Reverse process data distribution se Langevin MCMC sampling approximate karta hai.
  • DDIM sampling: Deterministic variant jo implicit generative model structure exploit karke sampling steps 1000 se 50 tak kam kar deta hai.
  • Classifier-free guidance: Ek technique jo noise prediction ko scale karke diversity aur sample quality ke beech trade karta hai.

Recall Feynman Explanation (12 saal ke bacche ko samjhao)

Socho tumhare paas ek sundar drawing hai. Ab tum us par roz thodi thodi ret daalte ho — har roz thodi thodi, 1000 din tak — jab tak drawing poori dab na jaaye aur dikhna band ho jaaye. Yahi forward process hai: hum picture ko step by step destroy kar rahe hain.

Ab yahan trick hai: hum ek smart robot train karte hain jo seekhe ki ret kaise hataayi jaaye, ek din ek baar, ulte jaate hue. Robot ret wali picture dekhta hai aur andaaza lagaata hai "aaj ki ret kahan daali gayi thi?" aur use hataa deta hai. Phir kal ki ret wali picture dekhta hai aur phir karta hai. Aur phir. 1000 baar ulte jaate hue.

Ek baar robot train ho jaaye, toh hum use sand ka ek bilkul random dher de sakte hain (jiske neeche kabhi picture thi hi nahi) aur keh sakte hain ki ret hatao jaise koi picture neeche ho. Aur amazing baat yeh hai ki wo ek nayi sundar drawing banata hai jo lagti hai jaise hamaari original pictures ke kisi artist ne banaai ho!

Jaadu yeh hai ki robot ne seedha draw karna nahi seekha. Usne pictures ko un-messup karna seekha, jo actually seekhna aasaan nikla. Aur kyunki mess up karna reversible hai (agar tum smart ho), toh un-mess-up karna banaane ke barabar hai!


#flashcards/ai-ml

What is the forward process in diffusion models? :: Ek fixed Markov chain jo timesteps par data mein gradually Gaussian noise add karta hai according to , systematically original data ko destroy karta hai jab tak wo pure noise na ban jaaye.

What is the reverse process in diffusion models?
Ek learned Markov chain jo step-by-step noise remove karta hai, ek neural network se parameterized jo predict karta hai, effectively har noise level par denoise karna seekhta hai.
What is the reparameterization trick for diffusion forward process?
Sabhi intermediate steps se sample karne ki jagah, hum directly sample kar sakte hain: jahaan aur . Yeh random timesteps sample karke efficient training allow karta hai.
Why do diffusion models predict noise instead of x_0 directly?
Noise prediction empirically better hai kyunki: (1) noise ke statistics sabhi timesteps par consistent hain, (2) yeh score matching se relate karta hai, (3) networks ko alag-alag par drastically alag output ranges (clean images vs noisy images) handle nahi karni padti.
What is the training objective for diffusion models?
jahaan hum random , real data , noise sample karte hain, compute karte hain, phir network ko train karte hain jo add ki gayi noise predict kare.
Why are β_t values kept small in diffusion models?
Chhota ensure karta hai ki reverse conditional distribution approximately Gaussian rahe, jise neural network model karna seekh sake. Bada reverse distribution ko non-Gaussian bana deta aur accurately seekhna impossible ho jaata.
How do you generate samples from a trained diffusion model?
(pure noise) se shuru karo, phir se tak: noise predict karo, denoised mean compute karo, aur sample karo jahaan . Yeh iteratively denoise karke produce karta hai.
What is ᾱ_t (alpha-bar) and why is it important?
cumulative noise schedule hai. Yeh timestep par signal-to-noise ratio control karta hai: ka signal coefficient aur noise coefficient hai. par, ensure karta hai ki pure noise ho.
What is the relationship between forward and reverse variance?
Reverse variance hai, Bayes' rule se derive kiya gaya. Yeh forward variance se chhota hai kyunki aur dono par conditioning, sirf par conditioning se zyada uncertainty reduce karta hai.
Why use T=1000 steps instead of fewer larger steps?
Bohot saare chote steps ensure karte hain ki har reverse step ek chhota perturbation ho jise neural networks accurately reverse karna seekh sakein. Kam bade steps Gaussian approximation violate karte aur reverse process seekhna bohot mushkil ho jaata.

Concept Map

add Gaussian noise

fixed Markov chain

controls noise level

shrink by sqrt 1-beta

sample x_t directly

start point

learns to denoise

undo destruction

training target

Original data x0

Forward process q

Pure Gaussian noise xT

Reverse process

Neural denoiser

Generated sample

Variance schedule beta_t

Reparameterization trick

Noisy x_t at step t