Federated Learning
1. Motivation: Why Federated Learning?
Traditional machine learning requires centralizing all training data on a single server. This approach faces several critical challenges in the modern world:
- Privacy Regulations: Laws like GDPR, HIPAA, and CCPA restrict how personal data can be collected, stored, and transferred.
- Data Sensitivity: Medical records, financial data, and personal communications are too sensitive to centralize.
- Data Volume: Edge devices (smartphones, IoT sensors) generate massive data volumes that are expensive to transmit.
- Data Sovereignty: Data may be legally required to remain within national borders.
- Competitive Concerns: Organizations may want to collaboratively train models without sharing proprietary data.
2. Federated Averaging (FedAvg) Algorithm
FedAvg (McMahan et al., 2017) is the foundational algorithm for federated learning. It combines local SGD with periodic model averaging.
- Server initializes global model parameters w0.
- For each round t = 1, 2, …, T:
- Server selects a random subset St of K clients (out of N total).
- Server broadcasts current global model wt to selected clients.
- Each client k ∈ St performs E epochs of SGD on its local dataset Dk:
wkt+1 = wt − η · ∇L(wt; Dk) (repeated for E epochs) - Each client sends updated model wkt+1 back to the server.
- Server aggregates by weighted averaging:
wt+1 = ∑k ∈ St (nk / n) · wkt+1
where nk = number of samples on client k, n = total samples across selected clients.
- Return final global model wT.
2.1 Key Hyperparameters
| Parameter | Symbol | Description | Effect |
|---|---|---|---|
| Client Fraction | C | Fraction of clients selected per round | Higher C → better convergence, more communication |
| Local Epochs | E | SGD epochs per client per round | Higher E → fewer rounds, but risk of client drift |
| Local Batch Size | B | Mini-batch size for local SGD | Smaller B → more stochasticity, potentially better generalization |
| Learning Rate | η | Step size for local SGD | Must be tuned carefully; may need decay |
3. Communication Efficiency
Communication is the primary bottleneck in federated learning. Transmitting millions of parameters each round over mobile networks is expensive. Several strategies address this.
3.1 Compression Techniques
- Gradient Quantization: Reduce precision of transmitted values (e.g., from 32-bit floats to 8-bit or even 1-bit). SignSGD transmits only the sign of each gradient component.
- Gradient Sparsification: Transmit only the top-k largest gradient components (by magnitude). Residuals are accumulated locally for future rounds.
- Structured Updates: Restrict model updates to a low-rank subspace, reducing the number of parameters communicated.
3.2 Reducing Communication Rounds
- Increase local computation (E): More local epochs before communication reduce the total number of rounds needed.
- Adaptive aggregation: Only communicate when local models diverge significantly from the global model.
- Knowledge distillation: Instead of transmitting model weights, clients send soft predictions on a shared public dataset.
4. Non-IID Data Challenges
In real-world FL, data across clients is typically non-IID (not independently and identically distributed). This is one of the most significant challenges in federated learning.
- Label skew: Different clients have different label distributions (e.g., one hospital mostly sees cardiac cases, another sees respiratory).
- Feature skew: Same labels but different feature distributions (e.g., photos from different climates).
- Quantity skew: Clients have vastly different amounts of data.
- Concept drift: The relationship between features and labels varies across clients.
4.1 Impact of Non-IID Data
- Client drift: Local models diverge from each other and the optimal global model during local training.
- Slow convergence: FedAvg may require many more rounds to converge compared to IID settings.
- Accuracy degradation: The global model may perform poorly on individual clients with very different data distributions.
4.2 Solutions for Non-IID Data
- FedProx: Adds a proximal term to the local objective: Lk(w) + (μ/2) · ||w − wt||², which prevents local models from drifting too far from the global model.
- SCAFFOLD: Uses control variates to correct for client drift in gradient updates.
- Per-FedAvg: Combines federated learning with MAML (Model-Agnostic Meta-Learning) for personalization.
- Data sharing: Share a small amount of globally representative data with all clients.
- Clustered FL: Group clients with similar data distributions and train separate models per cluster.
5. Differential Privacy in Federated Learning
Even though FL avoids sharing raw data, model updates can still leak information about individual training examples. Differential privacy (DP) provides formal privacy guarantees.
P(M(D) ∈ S) ≤ eε · P(M(D′) ∈ S) + δ
ε (privacy budget) controls the privacy-utility trade-off; smaller ε means stronger privacy.
5.1 DP-FedAvg
The standard approach to DP in FL involves two steps applied to each client’s update before aggregation:
- Clipping: Bound the L2 norm of each client’s model update: Δwk → Δwk · min(1, C / ||Δwk||), where C is the clipping threshold.
- Noise addition: Add calibrated Gaussian noise to the aggregated update: wt+1 = wt + (1/K)(∑ Δwk + N(0, σ²C²I))
The noise scale σ is chosen based on the desired (ε, δ) guarantee using the moments accountant or Rényi DP composition.
6. Secure Aggregation
Secure aggregation (SecAgg) ensures that the server can only see the aggregate of client updates, not individual updates, even if the server is curious.
6.1 How Secure Aggregation Works
- Each pair of clients (i, j) agrees on a random mask pij using Diffie-Hellman key exchange.
- Client i sends masked update: yi = wi + ∑j>i pij − ∑j<i pij
- When the server sums all masked updates, the pairwise masks cancel out: ∑i yi = ∑i wi
7. Horizontal vs Vertical Federated Learning
Federated learning architectures differ based on how data is partitioned across clients.
7.1 Horizontal FL (Sample-Partitioned)
This is the most common FL setting. FedAvg is designed for horizontal FL.
7.2 Vertical FL (Feature-Partitioned)
Vertical FL typically requires entity alignment (matching records across datasets) and uses techniques like split learning, where different parts of a model are trained on different clients.
7.3 Federated Transfer Learning
When clients differ in both feature space and sample space, federated transfer learning bridges the gap by learning shared representations that transfer across domains.
| Aspect | Horizontal FL | Vertical FL | Federated Transfer Learning |
|---|---|---|---|
| Feature Space | Same | Different | Different |
| Sample Space | Different | Same (overlapping) | Different |
| Algorithm | FedAvg, FedProx | Split Learning, SecureBoost | Transfer + FL |
| Example | Multiple hospitals | Bank + retailer | Cross-lingual NLP |
8. Applications of Federated Learning
8.1 Healthcare
FL enables training medical AI models across hospitals without sharing patient records. Applications include:
- Tumor segmentation from distributed MRI data (FeTS initiative)
- Drug discovery across pharmaceutical companies
- Electronic health record analysis across hospital networks
- Rare disease detection by pooling data from geographically dispersed institutions
8.2 Mobile Applications
- Next-word prediction: Google Gboard trains on user typing patterns.
- Voice recognition: Apple uses FL for Siri improvements.
- Auto-complete & ranking: Personalized search suggestions.
8.3 Finance
- Fraud detection across banks without sharing transaction data.
- Credit risk modeling with data from multiple financial institutions.
- Anti-money-laundering systems that pool patterns without exposing customer data.
9. Comparison with Centralized Learning
| Aspect | Centralized Learning | Federated Learning |
|---|---|---|
| Data Location | Single server | Distributed across clients |
| Privacy | Low (data centralized) | Higher (data stays local) |
| Communication | Data upload once | Multiple rounds of model exchange |
| Convergence | Standard SGD guarantees | Slower, especially with non-IID data |
| Model Quality | Generally optimal | Can approach centralized with enough rounds |
| Scalability | Limited by server storage/compute | Scales to millions of clients |
| Regulatory Compliance | Challenging | Easier (data doesn’t leave jurisdiction) |
10. Summary & GATE DA Key Takeaways
- Know the FedAvg algorithm steps: broadcast, local training, aggregation by weighted average.
- Understand the difference between horizontal (same features, different samples) and vertical (different features, same samples) FL.
- Know that non-IID data causes client drift and slows convergence.
- Understand differential privacy: clipping + noise addition; the role of ε.
- Communication efficiency: gradient compression (sparsification, quantization) and increasing local epochs.
- FedSGD is the special case of FedAvg with E = 1 and full-batch gradient.
- Secure aggregation hides individual updates; DP protects aggregate statistics.
- FL trains models without centralizing data, preserving privacy and regulatory compliance.
- FedAvg: local SGD + weighted averaging; controlled by C, E, B, η.
- Communication efficiency via compression, sparsification, and more local computation.
- Non-IID data is the fundamental challenge; addressed by FedProx, SCAFFOLD, clustering.
- Differential privacy (clip + noise) provides formal privacy guarantees.
- Horizontal FL (sample split) vs Vertical FL (feature split) vs Federated Transfer Learning.
- Applications span healthcare, mobile, finance, and cross-organizational collaboration.