ESC
Type to search guides, tutorials, and reference documentation.
Verified by Garnet Grid

Federated Learning

Train machine learning models across distributed data sources without centralizing sensitive data. Covers federated averaging, privacy-preserving computation, communication efficiency, heterogeneous data handling, and the patterns that make federated learning practical.

Federated learning trains models across multiple devices or organizations without sharing raw data. Instead of sending data to a central server, each participant trains locally and sends only model updates (gradients). This enables ML on data that cannot leave its source — healthcare records, financial data, mobile device data.


How Federated Learning Works

Traditional ML:
  Device 1 data ─┐
  Device 2 data ──┼──→ Central Server → Train Model
  Device 3 data ─┘
  Problem: Raw data must leave device (privacy risk)

Federated Learning:
  Device 1: Train locally → Send gradients ─┐
  Device 2: Train locally → Send gradients ──┼──→ Aggregate → Global Model
  Device 3: Train locally → Send gradients ─┘
  
  Raw data never leaves device
  Only model updates transmitted

Federated Averaging (FedAvg)

# Server-side aggregation
class FederatedServer:
    def __init__(self, model):
        self.global_model = model
    
    def aggregate_round(self, client_updates: list):
        """Average client model updates weighted by data size."""
        total_samples = sum(u["num_samples"] for u in client_updates)
        
        aggregated_weights = {}
        for layer_name in self.global_model.state_dict():
            aggregated_weights[layer_name] = sum(
                u["weights"][layer_name] * (u["num_samples"] / total_samples)
                for u in client_updates
            )
        
        self.global_model.load_state_dict(aggregated_weights)
        return self.global_model

# Client-side training
class FederatedClient:
    def __init__(self, local_data, model):
        self.data = local_data
        self.model = model
    
    def local_train(self, global_weights, epochs=5, lr=0.01):
        """Train on local data, return updated weights."""
        self.model.load_state_dict(global_weights)
        optimizer = torch.optim.SGD(self.model.parameters(), lr=lr)
        
        for epoch in range(epochs):
            for batch in self.data:
                loss = self.model.compute_loss(batch)
                loss.backward()
                optimizer.step()
                optimizer.zero_grad()
        
        return {
            "weights": self.model.state_dict(),
            "num_samples": len(self.data)
        }

Privacy Enhancements

Differential Privacy:
  Add calibrated noise to gradients before sending
  Guarantees: Cannot determine if any individual's data was used
  Trade-off: More noise = more privacy = less accuracy

Secure Aggregation:
  Encrypt individual updates, server only sees aggregate
  No single client's update visible to server

Homomorphic Encryption:
  Compute on encrypted data
  Server aggregates without decrypting individual updates

Use Cases

DomainData SourceWhy Federated
HealthcareHospital patient recordsHIPAA, data cannot leave hospital
FinanceBank transaction dataRegulatory, competitive sensitivity
MobileDevice usage patternsPrivacy, bandwidth constraints
IoTSensor dataVolume, connectivity constraints
Cross-orgCompeting companies sharing insightsAnti-trust, IP protection

Anti-Patterns

Anti-PatternConsequenceFix
No differential privacyModel memorizes individual dataAdd DP noise to gradients
Ignoring data heterogeneityModel biased toward largest participantsWeighted aggregation, FedProx
Too many communication roundsBandwidth cost, latencyLocal epochs, compression
No Byzantine fault toleranceMalicious client poisons modelRobust aggregation (median, trimmed mean)
Homogeneous model assumptionDevices have different capabilitiesModel heterogeneity support

Federated learning is not just an ML technique — it is a paradigm shift in how we think about data access. The data stays where it is. The model comes to the data.

Jakub Dimitri Rezayev
Jakub Dimitri Rezayev
Founder & Chief Architect • Garnet Grid Consulting

Jakub holds an M.S. in Customer Intelligence & Analytics and a B.S. in Finance & Computer Science from Pace University. With deep expertise spanning D365 F&O, Azure, Power BI, and AI/ML systems, he architects enterprise solutions that bridge legacy systems and modern technology — and has led multi-million dollar ERP implementations for Fortune 500 supply chains.

View Full Profile →