5.3.2 · AI-ML › MLOps & Deployment
Intuition Ek saansi mein core idea
Machine learning industrial speed pe chalayi jaane wali empirical science hai. Aap hundreds of
training experiments run karte ho, har ek thodi si variation ke saath. Bina ek disciplined log ke,
aap ye nahi answer kar sakte ki "kis change ne model ko better banaya?" — aur usse bhi bura, aap
re-create nahi kar sakte wo winning model jo chhe mahine pehle tha. Experiment tracking
= lab notebook. Reproducibility = guarantee ki same inputs se same outputs milenge. Ek
observability hai, doosra determinism .
Definition Experiment tracking
Experiment tracking har ek training run ke input, configuration, aur
output ki systematic recording hai taaki runs ko compare, search, aur reproduce kiya ja sake.
Ek ML training run ek aisi function hai jo dono trained model aur uske measured metrics return karti hai:
( artifacts , metrics ) = f ( code , data , hyperparameters , environment , random seed )
Ek result reproduce karne ke liye aapko right-hand side ka har argument pin karna hoga . Agar ek bhi
un-pinned raha, toh f non-deterministic ban jaata hai aur result reproducible nahi hota.
Definition Reproducibility (levels)
Repeatability : same team, same setup → same result.
Reproducibility : alag team, same description → same result.
Replicability : alag data/setup → same conclusion .
Wo paanch cheezein jo aapko ZAROOR version karni hain:
Axis
KYA pin karna hai
Tool example
Code
git commit SHA
git
Data
dataset hash / version
DVC, LakeFS
Config
saare hyperparameters
YAML / config logged to tracker
Environment
library versions, CUDA
Docker image digest, requirements.txt lock
Randomness
seed
seed=42 logged
Intuition "Pichle mangalwaar mere machine pe kaam kiya tha" wali catastrophe
Aapko 94% accuracy milti hai. Boss production mein maangta hai. Aap phir se train karte ho… 89%. Panic.
Difference ek unpinned axis mein chhupa hai: shayad pandas upgrade ho gaya, shayad data file
overwrite ho gayi, shayad seed drift kar gaya. Tracking ek mystery ko ek diff mein badal deta hai.
Economic 80/20: ~20% tracking discipline (log config + git SHA + data hash + seed)
~80% "cannot reproduce" incidents rokti hai. Full bit-for-bit determinism (remaining
20%) expensive hai aur aksar zaroori nahi.
Hum ye yaad nahi karte ki ek tracker kya store karta hai — hum ise derive karte hain. Poocho: "Run ko recreate karne aur compare karne ke liye minimum kya chahiye?"
Recreate karne ke liye → f ka har argument chahiye: code_sha, data_hash, params, env, seed.
Compare karne ke liye → outputs chahiye: metrics (accuracy, loss curves).
Reuse karne ke liye → produced object chahiye: artifacts (model weights, plots).
Baad mein dhundhne ke liye → identity + context chahiye: run_id, timestamp, tags, user.
Ye derivation hi MLflow / Weights & Biases ka schema hai:
Worked example Worked: meri reproducibility leak kahan hai?
Pipeline: data load (p = 1.0 ) → shuffle (p = 0.7 , unseeded) → train (p = 0.9 , GPU nondeterminism) → eval (p = 1.0 ).
Step — product compute karo. Ye step kyun? Kyunki independent stages multiply hote hain.
P = 1.0 × 0.7 × 0.9 × 1.0 = 0.63.
Sirf 63% reruns match karte hain. Fix: shuffle ko seed karo (p → 1.0 ) aur set karo
torch.use_deterministic_algorithms(True) (p →≈ 1.0 ) → P ≈ 1.0 .
Ye fix kyun karta hai: humne wo do sub-unity factors hataaye jo product ko dominate kar rahe the.
Worked example Worked: do experiments sahi se compare karna
Run A: lr=0.01, seed=1 → 91.0%. Run B: lr=0.001, seed=7 → 92.0%.
Question: "Kya B better hai kyunki lr kam hai?"
Step 1 — check karo kya change hua. Kyun? Valid comparison mein ek variable change hota hai
(controlled experiment). Yahan do change hue (lr AUR seed), toh 1% pure seed noise bhi ho sakta hai.
Step 2 — seed fixed rakh ke phir se run karo. Kyun? lr ka causal effect isolate karne ke liye, seed
constant hona chahiye, confounder nahi. Seed track karna hi ye diagnosis possible banata hai.
Worked example Worked: data hash ek silent leak pakad leta hai
Aap compute karte ho hash(train.csv) = a1b2.... Agle hafte same run logs karta hai hash = ff99....
Step — hashes compare karo. Kyun? Hash ek fingerprint hai; alag fingerprint ⇒
"same" file silently modify ho gayi (kisi ne re-export ki). Aap ab jaante ho ki metric
drop ek data problem hai, code problem nahi — seconds mein; tracking ke bina, ye ek lost week hota.
Common mistake "Git already sab kuch track karta hai, toh main reproducible hoon."
Kyun sahi lagta hai: git aapka code perfectly pin karta hai, aur code main variable lagta hai.
Kyun galat hai: git aapka data , aapke installed library versions , GPU
nondeterminism, ya runtime pe pass kiya seed track nahi karta. f ke paanch arguments hain; git ek pin karta hai.
Fix: data hash + requirements.txt lock (ya Docker digest) + seed SHA ke saath log karo.
Common mistake "Main bas final accuracy number ek spreadsheet mein save kar lunga."
Kyun sahi lagta hai: number hi wo cheez hai jo matter karti hai; baaki sab overhead lagta hai.
Kyun galat hai: number bina inputs ke attached kiye un-actionable hai — aap use reproduce
nahi kar sakte ya explain nahi kar sakte. Ye ek orphan metric hai.
Fix: metrics hamesha full run tuple ke saath log karo, automatically, haath se nahi.
np.random.seed(42) set karne se training deterministic ho jaati hai."
Kyun sahi lagta hai: numpy wo RNG hai jo aap sabse zyada dekhte ho.
Kyun galat hai: PyTorch/TF ke apne alag RNGs hain, aur GPU parallel reductions
nondeterministic hain seed ke saath bhi . Aapne kaafi p i mein se ek seed kiya.
Fix: saare generators seed karo AUR deterministic kernels enable karo
(torch.use_deterministic_algorithms(True), CUBLAS_WORKSPACE_CONFIG set karo).
Common mistake "Reproducibility ka matlab hai bit-for-bit identical weights."
Kyun sahi lagta hai: identical sunne mein gold standard lagta hai.
Kyun galat hai: alag hardware pe ye aksar infeasible hai; useful goal ye hai ki
conclusions aur metrics tolerance ke andar reproduce hon .
Fix: reproducibility ko "metric within ± ϵ " define karo, na ki "weights identical".
Recall Answers cover karo. Pehle predict karo (Forecast-then-Verify), phir reveal karo.
Training function f ke 5 arguments kya hain?
→ code, data, hyperparameters, environment, random seed.
f ke 2 outputs kya hain? → artifacts (model, plots) aur metrics.
Stage determinism probabilities multiply kyun hoti hain?
→ whole-pipeline reproducibility ko saare stages simultaneously reproducible chahiye (independent events ka AND multiply hota hai).
Git kya pin NAHI karta? → data, env/library versions, seed, GPU nondeterminism.
Reproducibility ka 80/20 kya hai? → log config+SHA+data hash+seed → zyaatar incidents cheaply rokta hai.
Recall Feynman: 12-saal ke bachche ko explain karo
Socho tumne ek amazing cake banaya. Exactly wohi cake phir se banane ke liye, "cake" likhna
kaafi nahi — tumhe recipe chahiye (steps), ingredients aur unka brand (data), har ek kitna
(settings), tumhare oven ka temperature (environment), aur woh kaun sa chamcha tha jisse tune
hilaaya agar wo taste change karta hai (random seed). Experiment tracking matlab hai ye sab har
baar likh lena. Tab jab tumhara cake great ho, tum phir bana sakte ho — aur jab bura ho,
tum apne notes dekh sakte ho aur exactly dekh sakte ho kya alag kiya tha.
"CHESS run ko pin karta hai"
C ode (SHA), H yperparameters, E nvironment, S eed, S et-of-data (hash).
Ek square miss karo aur tumhari reproducibility check mein hai.
Experiment tracking kya ki systematic recording hai, taaki runs compare aur reproduce ho sakein? Har input (code, data, hyperparameters, environment, seed), output (metrics), aur product (artifacts) ki ek training run ki.
Training function f ke wo paanch arguments jo reproducibility ke liye pin karne zaroori hain? Code (git SHA), Data (hash/version), Hyperparameters/config, Environment (library+CUDA versions), Random seed.
Training function f ke do outputs kya hain? Artifacts (model weights, plots) aur metrics (accuracy, loss curves) — dono run tuple mein capture hone chahiye.
Git alone reproducibility guarantee kyun NAHI karta? Git sirf code pin karta hai; ye data, library/env versions, runtime seed, ya GPU nondeterminism track nahi karta.
n independent stages wali pipeline ki reproducibility probability ka formula? P_repro = i ke upar p_i ka product (har stage simultaneously reproducible hona chahiye → AND events multiply hote hain).
Stage determinism probabilities multiply kyun hoti hain, add kyun nahi? Whole-pipeline reproducibility ke liye SAARE stages ek saath reproducible hone chahiye; independent AND events multiply hote hain.
Ek unseeded stage jiska p=0.5 ho, ek careful pipeline ke saath kya karta hai? Overall P_repro ko ≤0.5 tak cap kar deta hai regardless of other stages, kyunki ye product mein ek factor hai.
'Orphan metric' kya hota hai? Ek recorded result number jiske saath koi inputs (config/data/code) attached nahi, toh use reproduce ya explain nahi kiya ja sakta.
Reproducibility ka 80/20 kya hai? Config + git SHA + data hash + seed log karna cheaply ~80% "cannot reproduce" incidents rokta hai.
Kya np.random.seed(42) PyTorch GPU training ko deterministic banata hai? Nahi — Torch ka apna RNG hai aur GPU reductions nondeterministic hain; saare RNGs seed karne padte hain aur deterministic algorithms enable karne padte hain.
CHESS mnemonic expand hota hai? Code(SHA), Hyperparameters, Environment, Seed, Set-of-data(hash).
Debugging mein data hash kyun valuable hai? Changed hash turant reveal karta hai ki data file silently modify ho gayi, data problem ko code problem se alag karta hai.
Do runs compare karte waqt kisi hyperparameter ko credit dene ke liye kya constant rakhna chahiye? Random seed (aur baaki saare axes) — warna metric difference seed noise ho sakta hai, hyperparameter ka effect nahi.
cannot reproduce catastrophe
repeat, reproduce, replicate