Federated learning
6.5.8· AI-ML › Research Frontiers & Practice
Yeh Kaunsi Problem Solve Karta Hai?
Classic centralized ML workflow:
- Millions of devices se user data collect karo → central server
- Aggregated dataset pe model train karo
- Model wapas devices pe deploy karo
Problems:
- Privacy: Sensitive data (health records, messages, photos) user ke control se bahar chali jaati hai
- Bandwidth: Terabytes of raw data transmission
- Regulatory: GDPR, HIPAA certain data ko move karne se rokti hain
- Latency: Har training batch ke liye cloud ka round-trip
Federated learning data ko decentralized rakhta hai phir bhi ek global model seekhta hai.
Federated Learning Kaise Kaam Karta Hai (Step-by-Step Derivation)
Setup
Hamare paas hai:
- clients (devices, hospitals, organizations), har ek ke paas local dataset jiska size hai
- Total data points:
- Goal: Ek shared model seekhna jo global loss minimize kare:
jahan client ki local loss hai.
Yeh weighting kyun? Har client apne data size ke proportional contribute karta hai. 1000 samples wale client ka model pe 10× zyada influence hona chahiye 100 samples wale se.
Algorithm: Federated Averaging (FedAvg)
Yeh breakthrough McMahan et al. (2017) algorithm hai:
Server (orchestrator) steps:
- Initialize global model
- Har round ke liye:
- clients ka subset sample karo (typically , yaani 10%)
- Selected clients ko current broadcast karo
- Client updates ka wait karo
- Aggregate: jahan
Client steps (jab select hota hai):
- Receive server se
- Local training: Local data pe epochs of SGD run karo:
- Send back (sirf updated weights, data nahi!)
Yeh kyun kaam karta hai—math:
Agar har client ek SGD step kare (, batch size ):
Server aggregation:
Yeh exactly pe gradient descent ka ek step hai! Multiple local epochs () isko zyada efficiently approximate karte hain.
Key Concepts Deep Dive
1. Communication Efficiency
Bottleneck: Networks pe model updates bhejna expensive hai (mobile data, slow hospital networks).
Kitne communication rounds chahiye accuracy ke liye?
Convergence analysis se derived (simplified):
Strongly convex ke liye, rounds ke baad:
- Pehla term: Zyada rounds se faster convergence
- Doosra term: Local drift se error (clients local epochs karne pe diverge karte hain)
Trade-off:
- Bada → kam rounds (kam communication) lekin zyada drift error
- Chhota → zyada rounds (zyada communication) lekin kam drift
Practical choice: se epochs per round zyada tar tasks ke liye accha kaam karta hai.
2. Non-IID Data Distribution
Real-world data clients ke across heterogeneous hoti hai:
- Label skew: User A sirf English mein type karta hai, User B Spanish mein
- Feature skew: Hospital A ke older patients hain, Hospital B ke younger
- Quantity skew: Kuch users 10× zyada data generate karte hain
Mathematical impact:
Local aur global optima ke beech divergence define karo:
jahan (client ka optimal) aur (global optimal) hai.
High → clients conflicting directions mein kheenchte hain → slower convergence.
Mitigation strategies:
- Zyada local epochs aggregating se pehle har client ko better local minimum dhundhne mein help karta hai
- Client sampling: Har round mein diverse clients sample karo
- Personalization: Clients ko small personalized layers rakhne do
3. Privacy Guarantees
Claim: "Federated learning private hai kyunki raw data kabhi devices se bahar nahi jaata."
Reality: Isse zyada nuanced hai.
Attack vectors:
-
Gradient inversion: Gradients se training samples reconstruct karo
- diya, ke liye solve karo
- Chhote batches, high-res images ke liye possible hai
-
Model memorization: Neural nets training examples yaad rakh lete hain
- Model ko prompts se query karo → woh training data regurgitate karta hai
Defense: Differential Privacy
Bhejna se pehle updates mein calibrated noise add karo:
jahan clipping threshold hai (gradient norm bound karo).
Trade-off: Zyada noise () → stronger privacy → lower accuracy.
Advanced Variants
Secure Aggregation
Problem: Agar server malicious hai toh model updates bhi info leak kar sakte hain.
Solution: Cryptographic protocol jahan server seekhta hai lekin individual nahi.
Kaise (simplified):
- Har client ek random mask generate karta hai jo doosre clients ke saath share hota hai (pairwise keys ke zariye)
- Client server ko bhejta hai
- Server sum karta hai:
- Masks cancel ho jaate hain, server individuals ko dekhe bina true aggregate paata hai
Cost: 2-3× zyada communication, cryptographic overhead.
Cross-Silo vs. Cross-Device
| Cross-Device | Cross-Silo | |
|---|---|---|
| Example | Smartphones, IoT | Hospitals, banks |
| # Clients | Millions | 10-100 |
| Availability | Intermittent (sirf jab charging ho) | Stable |
| Communication | Slow (mobile networks) | Fast (datacenter links) |
| Data per client | Small (KBs-MBs) | Large (GBs-TBs) |
| Strategy | Many rounds, small | Few rounds, large |
Yeh distinction kyun matter karta hai: Algorithm hyperparameters (, , learning rate) ko setting ke hisaab se adapt karna padta hai.
Worked Example: Binary Classification
Setup: 3 hospitals bina records share kiye patient vitals se disease predict karna chahte hain.
Data:
- Hospital 1: 1000 patients, 60% positive
- Hospital 2: 500 patients, 40% positive
- Hospital 3: 2000 patients, 70% positive
- Feature: Blood pressure (simplicity ke liye 1D)
- Model: Logistic regression
Loss:
Algorithm execution:
Round 0:
-
Server: initialize karo, saare 3 hospitals sample karo ()
-
Hospital 1: receive karta hai
- 1000 samples pe 5 epochs SGD run karta hai,
- Gradients compute karta hai: jahan
- Update karta hai: (maano)
- Yeh step kyun? Standard gradient descent—local data pe loss reduce karne ke liye weights move karo.
- wapas bhejta hai
-
Hospital 2: Similarly paata hai
-
Hospital 3: Similarly paata hai
-
Server aggregate karta hai:
Yeh weights kyun? Total . Hospital 3 ke paas sabse zyada data hai (57%), isliye woh ko apne ke sabse kareeb kheenchta hai.
Round 1: se repeat karo ...
100 rounds ke baad: (converged global model)
Privacy preserved: Hospitals ne kabhi patient records share nahi kiye, sirf learned model weights.
Common Pitfalls & How to Fix Them
Connections to Other Concepts
- Distributed Training: Federated learning privacy constraints aur non-IID data ke saath distributed training hai
- Differential Privacy: Federated updates ke liye formal privacy guarantee
- Optimization Theory: FedAvg SGD variant hai; convergence data heterogeneity pe depend karta hai
- Edge Computing: Federated learning computation ko edge devices pe push karta hai
- Multi-Task Learning: Personalized federated learning har client ko ek task treat karta hai
- Byzantine Robust Learning: Malicious clients ke khilaf defense jo bad updates bhejte hain
- Model Compression: Quantization + sparsity har round mein communication cost reduce karte hain
- Privacy-Preserving ML: Federated learning ek pillar hai; doosron mein homomorphic encryption, secure multi-party computation shamil hain
Recall Federated Learning ko ek 12-Saal-ke-Bacche ko Explain Karo
Socho tum aur 99 dost sabse best autocorrect banana chahte ho texting ke liye. Lekin problem hai: sabke texts bahut private hain—unhe share nahi kar sakte!
Purana tarika (kaam nahi karta): Sab apne saare texts ek insaan ko bhejte hain. Woh insaan SABKE messages padhta hai (creepy!) aur common patterns dhundta hai. Phir woh sabko autocorrect rules batata hai.
Federated learning ka tarika:
- Ek insaan ("server") kaagaz pe kuch basic autocorrect rules likhta hai.
- Woh 100 copies banata hai aur har dost ko ek bhejta hai.
- Har dost apne KHUD ke texts pe (privately!) practice karta hai aur apni copy of rules improve karta hai.
- Dost SIRF apne improved rules wapas bhejte hain (apne texts nahi!).
- Server sabke improvements combine karta hai: "80 logon ne paaya ki 'u' ka matlab usually 'you' hota hai, toh chalte hain yeh add karte hain."
- Server nayi better rules bhejta hai. Repeat!
50 rounds ke baad, sabke paas ek amazing autocorrect hai jo 100 logon ke texting styles se seekha—lekin kisine bhi kisi aur ke private messages nahi dekhe. Yahi federated learning hai: saath seekho, private raho.
Active Recall Questions
#flashcards/ai-ml
Federated learning aur centralized ML mein core difference kya hai? :: Federated learning MODEL ko DATA ke paas laata hai (training local devices pe hoti hai, sirf weight updates bheje jaate hain). Centralized ML DATA ko MODEL ke paas laata hai (raw data training ke liye central server pe upload hota hai).
Federated averaging update rule likho :: jahan client ka local model hai epochs of SGD ke baad, dataset size se weighted.