Edge AI Lab

Classify images and detect objects with real ONNX models in your browser, try quantization and pruning, and compare edge with cloud.

8interactive experiments

Federated and on-device learning

Updating models without collecting raw data: FedAvg, heterogeneity challenges and the limits of privacy.

Advanced11 min read

Educational draft content that needs expert review before it is used as an academic reference. Specifications, versions and licences change; check the official source. No experimental result is shown here unless it was actually run.

Learning objectives

  • Explain the FedAvg algorithm
  • Describe the non-IID challenge
  • Understand the privacy limits of federated learning

In federated learning each device trains a copy of the model on its local data and sends only the weight update to a server that aggregates updates. The classic FedAvg algorithm computes a weighted average by each client’s sample count: w ← Σ (nₖ / n) · wₖ.

Challenges: data is non-IID across devices, connectivity is intermittent and device resources are limited. Although raw data is not sent, updates can leak information, so techniques such as secure aggregation and differential privacy are used; they improve protection but do not guarantee it absolutely.

On-device learning is harder than inference because training needs more memory and energy, so it is often used to fine-tune a few layers or small models. This module is theoretical; the lab contains no real federated-training experiment.

Terminology (with Arabic equivalents)

Federated learningالتعلم الاتحادي
FedAvgمتوسط اتحادي
Non-IIDبيانات غير متجانسة
Secure aggregationتجميع آمن
Differential privacyخصوصية تفاضلية

Worked example

Three clients with 100, 300 and 600 samples and resulting weights w₁, w₂, w₃: the server computes 0.1·w₁ + 0.3·w₂ + 0.6·w₃. The client with the most data has more influence.

Code snippet

PythonSimplified FedAvg
import numpy as np

def fedavg(weights, counts):
    n = sum(counts)
    return sum(w * (c / n) for w, c in zip(weights, counts))

w = [np.array([1.0, 2.0]), np.array([2.0, 0.0]), np.array([0.0, 1.0])]
print(fedavg(w, [100, 300, 600]))

An illustrative snippet that was not executed in the lab environment; check library versions in their official documentation before use.

Check yourself

  1. What does a client send in federated learning?

    • Its raw data
    • A weight update
    • Screenshots
    • Passwords
    Answer and explanation

    A weight update — It sends an update computed locally, not the data.

  2. By what is each client weighted in FedAvg?

    • By its number of samples
    • By screen size
    • By device age
    • No weighting
    Answer and explanation

    By its number of samples — It is weighted in proportion to its number of samples.

  3. Does federated learning guarantee absolute privacy?

    • Yes
    • No; updates may reveal information
    • Yes, if the model is small
    • It sends nothing
    Answer and explanation

    No; updates may reveal information — Secure aggregation and differential privacy are needed, and there is no absolute protection.

References

Suggested reading (links not verified yet)

  • McMahan et al. (2017). Communication-Efficient Learning of Deep Networks from Decentralized Data. AISTATS Not verified

Image and audio processing in the experiments runs inside your browser. Your images and audio are never uploaded and conversations are not stored. Privacy