एक नए सैद्धांतिक नज़रिए से देखे गए scratch से diffusion models
- diffusion models ने हाल के generative modeling में प्रभावशाली परिणाम दिखाए हैं, और खास तौर पर multimodal distributions से sampling में उत्कृष्ट हैं.
- diffusion models न केवल text-to-image generation tool Stable Diffusion में व्यापक रूप से अपनाए गए हैं, बल्कि audio/video/3D generation, protein design, robotic path planning जैसे विविध application क्षेत्रों में भी बेहतरीन performance दिखाते हैं.
- यह tutorial optimization के नज़रिए से diffusion models का परिचय देता है, और theory तथा code दोनों को कवर करते हुए बताता है कि diffusion models को scratch से कैसे implement किया जाए.
diffusion models को train करना
- diffusion models का लक्ष्य training examples से सीखे गए set से samples generate करना है.
- diffusion model training में निम्न प्रक्रिया शामिल होती है:
- K से x0 sample करना,
σmin और σmax के बीच noise level σ sample करना, और N(0,I) से noise ϵ sample करना.
- noisy data
xσ=x0+σϵ बनाना.
- squared loss को minimize करते हुए
xσ से ϵ (noise की दिशा) predict करना.
- वास्तविक training
training_loop function के माध्यम से की जाती है, जो batch के x0 पर iterate करता है और generate_train_sample का उपयोग करके noise level sigma और noise vector eps sample करता है.
noise schedule
- व्यवहार में
σ को [σmin,σmax] interval से uniformly sample नहीं किया जाता, बल्कि इस interval को N अलग-अलग values वाले σ schedule में discretize किया जाता है.
Schedule class संभव sigmas की list को encapsulate करती है और training के दौरान इसी list से sampling करती है.
- इसमें log-linear schedule का उपयोग किया जाता है, और अन्य schedules की तुलना में default parameters के साथ इस schedule को compare करने वाले plots दिए गए हैं.
toy example
- इस tutorial में spiral से sample किए गए points वाला एक toy dataset इस्तेमाल किया गया है.
- इस सरल dataset के लिए denoiser को multilayer perceptron (MLP) से implement किया गया है.
- MLP,
x∈R2 और noise level σ के concatenation को input के रूप में लेता है और noise ϵ∈R2 को predict करता है.
- सभी आवश्यक components तैयार हो जाने पर diffusion model को train किया जा सकता है.
denoising को approximate projection के रूप में समझना
- diffusion training procedure denoiser
ϵθ(x,σ) को सीखती है, और paper में सीखे गए denoiser को data manifold K पर approximate projection के रूप में व्याख्यायित किया गया है.
- यह diffusion sampling algorithm के convergence analysis के लिए relative error approximation model पेश करने की प्रेरणा देता है.
distance और projection functions
- set
K⊆Rn के लिए distance function को distK(x) के रूप में परिभाषित किया जाता है, और x∈Rn का projection उन points के set के रूप में परिभाषित होता है जो इस distance को प्राप्त करते हैं.
- यदि
projK(x) unique हो, तो distK(x) का gradient उसी unique projection की ओर संकेत करता है.
ideal denoiser
- किसी विशेष noise level
σ के लिए ideal या optimal denoiser ϵ∗ training loss function का exact minimizer होता है.
- जब data, K पर किसी finite set के ऊपर discrete uniform distribution हो, तब ideal denoiser का एक सटीक closed-form expression होता है.
relative error model
- diffusion sampling algorithm के convergence analysis के लिए relative error model पेश किया गया है.
- यह model मानता है कि denoiser द्वारा predict किया गया projection
x−σϵθ(x,σ) input x के लिए projK(x) का अच्छा approximation है, जब σ, distK(x)/n का अच्छा अनुमान हो.
diffusion models से sampling
- सीखे गए denoiser
ϵθ(x,σ) से sampling करके K में आने वाला point x0 प्राप्त करने के लिए, noise xt और noise level σt वाला denoiser ϵθ(xt,σt) x0 को predict करता है.
diffusion sampling को distance minimization के रूप में समझना
- diffusion sampling iteration को function
f(x)=12distK(x)2 पर gradient descent के रूप में समझा जा सकता है.
σt schedule को कैसे चुना जाए, यह sampling के दौरान लिए जाने वाले gradient steps की संख्या और आकार तय करता है.
gradient estimation के ज़रिए बेहतर sampler
- gradient estimation के माध्यम से एक नया efficient sampler निकाला गया है.
- यह sampler मौजूदा DDIM sampler की तुलना में तेज convergence दिखाता है.
large-scale example
- ऊपर दिया गया training code केवल toy dataset ही नहीं, बल्कि image diffusion models को scratch से train करने के लिए भी इस्तेमाल किया जा सकता है.
- sampling code, pre-trained state-of-the-art latent diffusion model से sampling करने में बिना किसी बदलाव के काम करता है.
अन्य सामग्री
- diffusion models पर निम्न blog posts भी सुझाए गए हैं:
- What are diffusion models? discrete-time नज़रिए से, Markov process को उलटते हुए diffusion models का परिचय देता है.
- Generative modeling by estimating gradients of the data distribution continuous-time नज़रिए से, stochastic differential equations को उलटते हुए diffusion models का परिचय देता है.
- The annotated diffusion model diffusion models की PyTorch implementation को विस्तार से समझाता है.
GN⁺ की राय
- यह tutorial diffusion models को optimization के नज़रिए से परिचित कराता है और theoretical background तथा practical code implementation को जोड़कर समझाता है, जिससे शुरुआती software engineers के लिए भी इसकी पहुँच आसान हो जाती है.
- diffusion models को कई तरह के data types पर लागू किया जा सकता है, जो यह संकेत देता है कि multimodal distributions से sampling महत्वपूर्ण होने वाले विभिन्न applications में इनका उपयोगी होना संभव है.
- tutorial diffusion models की training और sampling प्रक्रिया को step-by-step समझाता है, जिससे model के काम करने के सिद्धांत और implementation method की गहरी समझ मिलती है.
- diffusion models की training और sampling प्रक्रिया अपेक्षाकृत जटिल है, और इसे समझने व implement करने के लिए machine learning और deep learning का बुनियादी ज्ञान आवश्यक है.
- इस तकनीक को अपनाते समय computational cost, training data की quality, और model complexity जैसे factors पर विचार करना चाहिए, और इसके माध्यम से अधिक परिष्कृत तथा विविध samples generate करने की क्षमता मिल सकती है.
1 टिप्पणियां
Hacker News टिप्पणियाँ
लेखक का कहना है: diffusion models को समझने की कोशिश करते समय उन्हें एहसास हुआ कि code और गणित को काफ़ी सरल बनाया जा सकता है, और इसी वजह से उन्होंने यह blog post और diffusion library लिखी। वे सवालों के जवाब देने के लिए तैयार हैं.
एक और शानदार लेख, 'Diffusion Models From Scratch', गणितीय विवरण को और गहराई से कवर करता है और इसके साथ 500 lines से कम का, समझने में आसान implementation भी है.
अच्छा लगा कि इस लेख में code शामिल है। diffusion papers बहुत सारे formulas के लिए मशहूर हैं, लेकिन code हमारे जैसे लोगों के लिए ज़्यादा साफ़ और समझने में आसान होता है। हर theoretical paper के साथ reference implementation code होना चाहिए.
diffusion transformer पर विस्तार देखना चाहूँगा। इसका उपयोग Sora और दूसरे video generation models को चलाने में होता है। अगर इस लेख और 'GPT From Scratch' को मिलाकर 'Diffusion Transformer From Scratch' जैसा परिचय बनाया जाए तो बढ़िया होगा.
लेख अच्छा है, लेकिन यह diffusion models की उस महत्वपूर्ण विशेषता को छोड़ देता है कि वे probability log के derivative यानी score function को model करते हैं, और diffusion sampling Langevin dynamics जैसा होता है। इससे समझ आता है कि इन्हें GAN की तुलना में train करना आसान क्यों है.
बहुत दिलचस्प। Iterative alpha-(de)Blending paper याद आ गया। वह भी conceptually ज़्यादा सरल diffusion model सेट करता है और उसे लगभग iterative projection process के रूप में formalize करता है। यह approach denoising error analysis जैसे और दिलचस्प experiments संभव बनाता है.
क्या diffusion का एक विचार यह है कि बहुत बड़ी मात्रा में training data हासिल की जाए? यानी, क्या random तरीके से diffused images और non-diffused images की तुलना की जाती है?
theory की अच्छी व्याख्या है। यह dataset-independent लगती है। image generation की specifics को लेकर जिज्ञासा है। उदाहरण के लिए, image generator को piano keys बनाना मुश्किल क्यों होता है? लगता है कि बेहतर mid-range constraint representation की ज़रूरत है.
याद रखो, सभी machine learning models convolution हैं.
इस लेख की टिप्पणियों का इस्तेमाल कर गुप्त संदेश भेजने वाला एक secret society है, इसलिए इसे Google मत करना.