6.5.8 · HinglishResearch Frontiers & Practice

Federated learning

3,162 words14 min readRead in English

6.5.8 · AI-ML › Research Frontiers & Practice

Yeh Kaunsi Problem Solve Karta Hai?

Classic centralized ML workflow:

  1. Millions of devices se user data collect karo → central server
  2. Aggregated dataset pe model train karo
  3. 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:

  1. Initialize global model
  2. 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):

  1. Receive server se
  2. Local training: Local data pe epochs of SGD run karo:
  3. 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:

  1. Zyada local epochs aggregating se pehle har client ko better local minimum dhundhne mein help karta hai
  2. Client sampling: Har round mein diverse clients sample karo
  3. 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:

  1. Gradient inversion: Gradients se training samples reconstruct karo

    • diya, ke liye solve karo
    • Chhote batches, high-res images ke liye possible hai
  2. 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):

  1. Har client ek random mask generate karta hai jo doosre clients ke saath share hota hai (pairwise keys ke zariye)
  2. Client server ko bhejta hai
  3. Server sum karta hai:
  4. 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:

  1. Ek insaan ("server") kaagaz pe kuch basic autocorrect rules likhta hai.
  2. Woh 100 copies banata hai aur har dost ko ek bhejta hai.
  3. Har dost apne KHUD ke texts pe (privately!) practice karta hai aur apni copy of rules improve karta hai.
  4. Dost SIRF apne improved rules wapas bhejte hain (apne texts nahi!).
  5. 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."
  6. 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.

Aggregation mein clients ko unke dataset size se kyun weight karte hain?
Taaki har data point global model mein equally contribute kare. 10× zyada data wale client ka model pe 10× zyada influence hona chahiye. Yeh mathematical objective se match karta hai.
Local epochs se controlled communication cost trade-off kya hai?
Bada → kam rounds (kam communication) lekin zyada client drift (local models diverge). Chhota → zyada rounds (zyada communication) lekin kam drift. Zyada tar tasks ke liye optimal .
-differential privacy ek sentence mein kya hai?
Kisi bhi ek insaan ka data add ya remove karne se algorithm ke output ki probability zyada se zyada (multiplicatively) plus se badlegi, provably information leakage bound karta hai.
Differential privacy federated learning mein kaunse attack ke khilaf defend karti hai?
Gradient inversion attacks, jahan ek adversary gradients/weight updates se training samples reconstruct karta hai. DP updates mein calibrated noise add karta hai, reconstruction impossible banata hai.
Non-IID data federated learning ke liye problem kyun hai?
Clients alag-alag objectives optimize karte hain ( jab data distributions differ karein). Contradictory local models ko average karna oscillation aur global optimum tak slower convergence cause karta hai.
Secure aggregation kya hai?
Cryptographic protocol jahan server client updates ka SUM seekhta hai lekin individual nahi dekh sakta. Malicious server se bachata hai jo individual updates se info infer karne ki koshish kare.
Cross-device vs. cross-silo: kis mein zyada clients hain aur client per less data hai?
Cross-device (millions of smartphones, KBs-MBs each). Cross-silo mein 10-100 organizations hain jiske paas GBs-TBs each hain.
Client drift kya hai aur kab hota hai?
Jab clients kaafi local epochs ke dauran local data pe overfit ho jaate hain, unke models global optimum se diverge ho jaate hain. Bade aur highly non-IID data ke saath hota hai. Chhote ya FedAdam jaise adaptive optimizers se mitigate hota hai.

Concept Map

causes

motivates

principle

enables

produces

preserves privacy

minimizes

uses

implemented by

server does

client does

sends back

weighted by

Centralized ML

Privacy, Bandwidth, Regulatory, Latency problems

Federated Learning

Send model to data

Local training on device

Only weight updates shared

Global loss F theta

Data-size weighting nk over n

FedAvg McMahan 2017

Server aggregation

Client E epochs of SGD