Part XII: Edge, Embedded, Streaming, and Federated Sensor AI
Chapter 64: Federated and Privacy-Preserving Sensor AI

Federated evaluation, security, and failure modes

"You asked me to report my accuracy. But I cannot see the test set, one in twenty of my teachers is lying to me on purpose, and a third of them go offline before the bell rings. My confidence interval, it turns out, is a leap of faith."

A Skeptical AI Agent

Prerequisites

This section closes the chapter, so it assumes the whole arc: FedAvg and non-IID sensor fleets (Section 64.2), personalization (Section 64.3), and the differential-privacy and secure-aggregation machinery of Section 64.4. It leans on leakage-safe, subject-disjoint splitting (Chapter 5) and on the general vocabulary of calibration and worst-group metrics (Chapter 18). The statistics are elementary: means, medians, and quantiles of per-client numbers.

The Big Picture

Everything so far assumed the federated system behaves: clients train faithfully, report truthfully, and stay online. Deployment breaks all three assumptions at once. You must evaluate a model whose test data you are forbidden to gather in one place, defend an aggregator that any of a million strangers can send a crafted update to, and keep the whole thing converging while devices die mid-round. This section is the reliability engineering of federated sensing. It answers three coupled questions: how do you measure a federated model faithfully when the ground truth is scattered and hidden, how do you keep a malicious minority from steering or backdooring the shared model, and what silent failure modes erode a fleet that no one is watching. The uncomfortable theme is that the privacy protections of Section 64.4 and the security defenses of this one are frequently in direct conflict: the very encryption that hides an honest client's gradient also hides an attacker's poison.

Federated evaluation: measuring a model you cannot pool

Centralized evaluation computes one number on one held-out set. Federated evaluation cannot, because the test data lives on the same devices as the training data and is equally forbidden to move. The how mirrors training: the server broadcasts the current global model, each client runs inference on its own local held-out split, and each returns only aggregate statistics (loss, per-class counts, a confusion matrix), which the server averages. The why it is hard is that a single averaged accuracy is now a summary of a distribution, and the distribution is where the truth lives. A model that scores 94 percent averaged can be 99 percent on the majority of clients and 55 percent on a skewed tenth, which for a fall detector or an arrhythmia flag is the tenth that matters.

So federated evaluation reports the distribution over clients, not just its mean. The three numbers that matter are the population average, weighted by client sample count \(n_k\), and the tails:

\[ \text{Acc}_{\text{avg}} = \sum_k \frac{n_k}{n}\,a_k, \qquad \text{Acc}_{q} = \operatorname{Quantile}_{q}\big(\{a_k\}\big), \]

where \(a_k\) is client \(k\)'s local accuracy and the low quantile \(\text{Acc}_{0.1}\) (the worst-decile client) is the operational headline for any safety-relevant fleet. Two subtleties turn this from arithmetic into engineering. First, the split must be leakage-safe within each client: a subject's data cannot straddle its own train and test partitions, exactly the discipline of Chapter 5, now enforced a thousand times over with no central auditor to check it. Second, only clients that participate in an evaluation round contribute, and participation is not random: devices that are charging, on Wi-Fi, and idle are systematically different from those that are not, so the reported average is a biased estimate of true fleet performance. This participation bias is the federated analogue of survivorship bias, and it flatters your metrics.

Key Insight

In federated sensing the mean accuracy is the least informative number you can report. Heterogeneity guarantees that the interesting behavior is in the tail, and privacy guarantees you cannot inspect that tail directly. The correct instinct is to treat every reported metric as a random variable over a self-selected sample of clients, and to publish its low quantile and its participation rate alongside its mean. A federated result without a worst-decile and a participation figure is not a measurement; it is a hope.

Security: poisoning, backdoors, and Byzantine robustness

Open a training loop to a million untrusted devices and you have opened it to attackers who control some of them. The threat model splits by intent. Data poisoning corrupts a client's local training set (mislabeling, or injecting crafted sensor samples) so its honest-looking update nudges the global model wrong. Model poisoning is stronger: a compromised client ignores its data entirely and sends a hand-crafted weight vector, and because FedAvg simply averages, one large malicious update can drag the mean arbitrarily far, an attack the literature calls Byzantine because the faulty node may behave adversarially rather than merely crash. The most insidious variant is a backdoor: the attacker leaves the model's accuracy untouched on ordinary inputs but plants a trigger, so a specific accelerometer pattern or an RF watermark makes the model output an attacker-chosen label. Backdoors survive averaging surprisingly well and are nearly invisible to the distribution-level evaluation above, because the model looks healthy on every client's real data.

The defense replaces the mean with a robust aggregation rule that a minority of outliers cannot dominate. Coordinate-wise median and trimmed mean discard extreme values per parameter; Krum (Blanchard et al., NeurIPS 2017) selects the single update closest to its neighbors, on the logic that honest updates cluster and a poison vector sits far out; Bulyan and coordinate-wise median variants trade compute for stronger guarantees. The when: any cross-device deployment with open enrollment needs at least a trimmed mean; a cross-silo deployment among a few vetted hospitals or factories can rely more on authentication and less on statistics. The listing below shows why the mean is indefensible and how one line of robust aggregation restores it.

import numpy as np
rng = np.random.default_rng(0)

# 20 honest clients agree on an update near the true direction; 3 are poisoned.
true = np.array([1.0, -0.5])
honest = true + rng.normal(0, 0.1, size=(20, 2))
poison = np.tile([50.0, 50.0], (3, 1))          # 3 large model-poisoning updates
updates = np.vstack([honest, poison])

def trimmed_mean(U, beta=0.15):                  # drop top/bottom beta fraction per coord
    k = int(beta * len(U))
    return np.mean(np.sort(U, axis=0)[k:len(U) - k], axis=0)

print("plain mean :", np.mean(updates, axis=0).round(2))   # hijacked by 3 clients
print("coord median:", np.median(updates, axis=0).round(2))
print("trimmed mean:", trimmed_mean(updates).round(2))     # recovers the true update
Listing 64.7.1. A 23-client aggregation with three model-poisoning updates. The plain FedAvg mean is dragged toward \([7.4, 6.0]\), miles from the honest consensus near \([1.0, -0.5]\); the coordinate-wise median and the trimmed mean both ignore the outliers and recover the true direction. Robust aggregation is the difference between one bad actor owning your model and one bad actor being discarded.

As Listing 64.7.1 shows, robustness is cheap to add and expensive to omit. But it collides head-on with the privacy layer. Secure aggregation (Section 64.4) is designed so the server sees only the sum of masked client updates and never an individual vector, which is exactly what a median or a Krum score needs to inspect. You cannot trim outliers you are cryptographically forbidden to see. Reconciling the two, robust aggregation under secure aggregation, via zero-knowledge range proofs or verifiable secret sharing, is one of the live tensions of the field.

Real-World Application: a backdoored gesture-unlock across a smart-lock fleet

A smart-lock vendor trains a wrist-gesture authenticator federated across a hundred thousand users' wearables (Chapter 27). An attacker enrolls a few hundred sock-puppet devices and, on each, trains the model to accept one specific figure-eight flick as anyone's valid unlock, scaling the malicious update to survive averaging. Federated evaluation stayed green: false-accept and false-reject rates on every honest user's real gestures were unchanged, because the backdoor only fires on the trigger. The team caught it not from accuracy but from an update-space monitor that flagged a tight cluster of anomalously large, mutually similar updates arriving from newly enrolled clients. They switched aggregation from FedAvg to a trimmed mean with norm-clipping, rate-limited new-enrollee influence, and added a canary set of trigger-like probes to evaluation. The lesson generalizes: a healthy accuracy number is not a security property, and the same functional-safety mindset as sensor spoofing (Chapter 68) applies to the training channel, not just the inference input.

Failure modes: the fleet that quietly rots

Most federated systems do not die from attacks; they degrade from mundane systems failures that no exception ever surfaces. Stragglers and dropout are chronic: a client that starts a round but loses power or connectivity contributes nothing, and if slow devices (older hardware, weaker links) drop out systematically, the global model is trained on a faster, richer, non-representative slice of the fleet. Staleness afflicts asynchronous designs, where an update computed against an old global model arrives rounds later and pulls the current model backward. Non-participation bias is the training twin of the evaluation bias above: models learn the world of charging, idle, well-connected devices and underserve everyone else. And silent quality collapse is the worst, because the server, forbidden to see data, is half-blind: a firmware update that recalibrates a sensor, a seasonal distribution shift (Chapter 66), or a slow drift in labeling quality can erode accuracy for months with no error thrown. The defenses are operational, not algorithmic: monitor participation demographics, track the per-client metric distribution over time (not just its mean), version the model per client, and keep a small trusted validation cohort whose data can be inspected as a tripwire, the federated corner of MLOps for sensor fleets (Chapter 69).

Research Frontier

The 2023 to 2026 frontier is reconciling the three tensions this section exposed. On robustness-under-privacy, work on verifiable and zero-knowledge secure aggregation (building on Bonawitz et al.'s protocol and Google's production federated stack) lets a server enforce norm bounds and outlier rejection without ever decrypting a client's update. On backdoor durability, defenses such as differentially-private training with norm-clipping, spectral-signature detection, and per-client update auditing compete with steadily stealthier attacks in an unresolved arms race. On evaluation, the open problem is certifying per-client calibration and worst-group guarantees (Chapter 18) when the certifier is structurally blind to the data, with federated conformal prediction an active thread. The plain state of the art: strong empirical defenses exist for each threat in isolation, but a system that is simultaneously private, Byzantine-robust, and truthfully evaluated remains a research target, not a shipping default.

The Right Tool

You do not implement Krum, trimmed mean, or federated evaluation aggregation from scratch. Flower ships robust strategies and a federated-evaluation loop as configuration: swap the aggregation rule and pass an evaluation function, and the framework fans it across clients and collects the per-client distribution for you.

import flwr as fl

# Robust aggregation + built-in federated evaluation, no plumbing.
strategy = fl.server.strategy.Krum(          # or FedTrimmedAvg, FedMedian
    num_clients_to_keep=1,
    fraction_evaluate=0.5,                    # sample half the fleet each eval round
    evaluate_metrics_aggregation_fn=weighted_and_quantiles,  # your worst-decile reducer
)
fl.simulation.start_simulation(client_fn=client_fn, num_clients=100000,
                               strategy=strategy)
Listing 64.7.2. Byzantine-robust aggregation plus distribution-aware federated evaluation in a handful of lines. Hand-rolling the Krum score computation, the client sampling for evaluation, and the per-client metric collection is several hundred lines; here it is a strategy swap and one reducer function. The science you still own is the threat model and the choice of worst-group metric.

Exercise

Extend Listing 64.7.1 into a small sweep. Vary the number of poisoned clients from 0 to 10 out of 23, and for each, record the L2 error between the true update and (a) the plain mean, (b) the coordinate median, (c) the trimmed mean at \(\beta \in \{0.1, 0.2\}\). Plot error versus attacker count for all four rules and identify the breakdown point of each, the fraction of poison it tolerates before failing. Then add a stealthy attacker that scales its poison to just below the trimming threshold, and show which defense it defeats. State in one sentence why no aggregation rule can tolerate a poison fraction at or above one half.

Self-Check

1. Why is the population-average accuracy the wrong headline metric for a safety-relevant federated fleet, and what two numbers should accompany or replace it?

2. Distinguish data poisoning, model poisoning, and a backdoor. Which one is nearly invisible to distribution-level federated evaluation, and why?

3. Explain the direct conflict between secure aggregation and robust aggregation. What class of technique aims to resolve it?

Lab 64

Simulate federated training across users/devices for a wearable model; add differential privacy and measure the utility cost.

What's Next

In Chapter 65, we lift the evaluation discipline glimpsed here (worst-group metrics, leakage-safe splits, honest reporting under bias) out of the federated special case and make it the general contract for any sensor model, centralized or not: task versus operational metrics, user and site and device and session splits, time-aware cross-validation, and the field-validation protocols that separate a benchmark number from a deployable claim.

Bibliography

Federated learning foundations and systems

McMahan, Moore, Ramage, Hampson, Aguera y Arcas (2017). Communication-Efficient Learning of Deep Networks from Decentralized Data. AISTATS.

The FedAvg paper. Its size-weighted averaging is exactly the aggregation rule that robust methods must replace, so it defines the attack surface this section defends.

Kairouz, McMahan, et al. (2021). Advances and Open Problems in Federated Learning. Foundations and Trends in ML.

The field's reference survey. Its chapters on robustness, privacy, and evaluation frame the three tensions organized here, and catalogue the open problems named in the frontier callout.

Security, poisoning, and Byzantine robustness

Blanchard, El Mhamdi, Guerraoui, Stainer (2017). Machine Learning with Adversaries: Byzantine Tolerant Gradient Descent. NeurIPS.

Introduces Krum, the archetypal robust aggregation rule that selects the update closest to its neighbors. The formal basis for the defense in Listing 64.7.1.

Yin, Chen, Kannan, Bartlett (2018). Byzantine-Robust Distributed Learning: Towards Optimal Statistical Rates. ICML.

Establishes the coordinate-wise median and trimmed-mean estimators with breakdown-point guarantees, the exact rules and the one-half limit the exercise asks you to verify.

Bagdasaryan, Veit, Hua, Estrin, Shmatikov (2020). How To Backdoor Federated Learning. AISTATS.

Shows model-replacement backdoors that survive averaging while leaving benign accuracy intact, the attack behind the smart-lock example and the reason accuracy is not a security property.

Privacy attacks and secure aggregation

Bonawitz, Ivanov, Kreuter, et al. (2017). Practical Secure Aggregation for Privacy-Preserving Machine Learning. ACM CCS.

The production secure-aggregation protocol whose server-sees-only-the-sum design is precisely what collides with robust aggregation; the frontier work builds directly on it.

Zhu, Liu, Han (2019). Deep Leakage from Gradients. NeurIPS.

Demonstrates reconstructing training samples from shared gradients, the concrete privacy attack that motivates why federated updates cannot be treated as safe to expose.

Frameworks

Beutel, Topal, Mathur, et al. (2020). Flower: A Friendly Federated Learning Research Framework.

The library behind the Right-Tool listing. Provides FedMedian, FedTrimmedAvg, Krum, and a federated-evaluation loop as configuration rather than plumbing.