Part XII: Edge, Embedded, Streaming, and Federated Sensor AI
Chapter 62: On-Device Continual Learning

Safety of self-updating models

"Every night I taught myself something new. Nobody checked my homework. By spring I had quietly become a different model than the one they certified, and no one could say exactly when."

An Unsupervised AI Agent

The Big Picture

The whole chapter has been about giving a deployed model the right to change itself: to replay old data, imprint a new class, personalise to one wearer. That right is also the hazard. A model that updates in the field has no code review, no staging environment, and no on-call engineer watching the loss curve. It learns from whatever the sensor feeds it, including a mislabelled tap, a stuck accelerometer, a spoofed signal, or an adversary who has worked out that six confident examples will register a new prototype. The update that was supposed to keep the model fresh can instead silently degrade it, forget a safety-critical class, drift outside its certified envelope, or absorb a poisoned label, and because it happened autonomously across a fleet of thousands, nobody notices until the field failures roll in. Safety of self-updating models is the discipline of granting that right conditionally: an update is accepted only if it passes a gate, its effect is bounded, and it can always be undone. This section is about the machinery that turns "the device learns" into "the device learns safely."

This section closes Chapter 62 by adding guardrails around every mechanism the earlier sections built: the replay of Section 62.3, the prototype imprinting of Section 62.4, and the personalisation of Section 62.6. It assumes you are comfortable with calibrated confidence and rejection (Chapter 18) and with distribution shift as a first-class problem (Chapter 66). It sets up the fleet-scale and functional-safety treatments of Chapter 69 and Chapter 68.

The threat model: what can go wrong when a model teaches itself

Name the failures before defending against them. On-device self-updating faces four distinct hazards, and they demand different countermeasures. Silent degradation is the base case: honest data, honest labels, but the update overfits a personalisation quirk or amplifies catastrophic forgetting (Section 62.2) so that overall accuracy quietly falls. Label poisoning is adversarial: a wearer, or an attacker with physical access to the sensor, supplies inputs whose accepted labels steer the model, for example registering the attacker's own gait as the authorised user, or teaching a fault detector that a real fault is "normal". Concept-drift capture is subtler: a genuinely shifted but transient input (a temporary sensor fault, an unusual environment) gets learned as if it were the new steady state. Envelope violation is the certification hazard: even a beneficial update moves a model that was validated and, in regulated domains, frozen at a specific version outside the state that a regulator or a functional-safety case signed off on. The unifying observation is that on-device learning removes the human gate that a normal MLOps pipeline (Chapter 69) relies on, so the gate has to be reconstructed in software, on the device, before the weights are allowed to move.

Key Insight

A safe self-update is defined by three properties, not by the learning rule that produced it. It is gated: the candidate weights are evaluated against a frozen, trusted sentinel set before they replace the live model, so an update that hurts is rejected rather than applied. It is bounded: the parameter change lives inside a trust region, so no single learning step can move the model arbitrarily far, which caps the damage a poisoned batch can do. And it is reversible: the previous known-good checkpoint is retained, so any regression detected later can be rolled back atomically. Continual learning gives you plasticity; safety is the machinery that makes plasticity conditional, bounded, and undoable. If an update cannot be evaluated, limited, and reverted, it should not be allowed to happen autonomously.

The accept-or-reject gate and the sentinel set

The central mechanism is a validation gate. The device keeps a small, immutable sentinel set: a few dozen to a few hundred labelled examples, curated at build time to cover the safety-critical classes and the base distribution, stored in read-only flash so no field process can alter it. An update is never applied in place. Instead the candidate weights \(\theta'\) are computed off to the side, scored on the sentinel set, and adopted only if they do not regress it. Formally, accept \(\theta'\) over the incumbent \(\theta\) only when

\[ \mathcal{A}_{\text{sent}}(\theta') \;\ge\; \mathcal{A}_{\text{sent}}(\theta) - \varepsilon, \]

where \(\mathcal{A}_{\text{sent}}\) is accuracy (or a cost-weighted metric that punishes false negatives on critical classes) and \(\varepsilon\) is a small tolerance, often zero for safety-critical classes and slightly positive elsewhere to allow benign noise. The sentinel set is deliberately not the personalisation stream: it is the memory of what the model must never lose. Because it is leakage-safe by construction (curated once, never touched by field data, echoing the split discipline of Chapter 5), a pass on the sentinel is trustworthy evidence that the update did not trade away known competence for a few new samples. To bound the update, clip the parameter delta to a trust region of radius \(\rho\), \(\lVert \theta' - \theta \rVert_2 \le \rho\); to detect poisoning, require that accepted new examples clear a confidence or conformal-rejection threshold (Chapter 18) so that a wildly out-of-distribution "teaching" sample is refused rather than learned.

import numpy as np

def safe_update(theta, learn_step, sentinel_X, sentinel_y,
                rho=0.5, eps=0.0):
    """Gate + bound + rollback around one on-device learning step."""
    base_acc = accuracy(theta, sentinel_X, sentinel_y)   # score incumbent

    theta_new = learn_step(theta)                        # candidate weights

    delta = theta_new - theta                            # bound the change
    norm = np.linalg.norm(delta)
    if norm > rho:                                       # trust region clip
        theta_new = theta + delta * (rho / norm)

    new_acc = accuracy(theta_new, sentinel_X, sentinel_y)
    if new_acc >= base_acc - eps:                        # gate on sentinel
        return theta_new, "accepted"                     # commit new checkpoint
    return theta, "rejected: sentinel regression"        # roll back to known-good

def gate_sample(x, conf, tau=0.9):                       # poisoning guard
    return conf >= tau        # only confidently-labelled samples may teach
Listing 62.7.1. A minimal safe-update wrapper. safe_update scores the incumbent on the frozen sentinel set, produces a candidate, clips its parameter delta to a trust region of radius \(\rho\), and commits it only if sentinel accuracy does not regress by more than \(\varepsilon\); otherwise it returns the unchanged weights, which is the rollback. gate_sample refuses low-confidence inputs before they ever enter learn_step.

Listing 62.7.1 makes the three safety properties concrete in one function: the trust-region clip is the bound, the sentinel comparison is the gate, and returning the old theta on failure is the reversibility. Notice that the learning rule itself, learn_step, is a black box; the safety wrapper does not care whether it is a replay update, a prototype imprint, or a gradient step. That separation is what lets you bolt these guarantees onto any of the earlier sections' methods.

Real-World Application: a continuous glucose sensor that must never unlearn hypoglycaemia

A wearable continuous glucose monitor personalises its trend model to each patient over weeks, exactly the on-device adaptation of Section 62.6. The catastrophic failure is not a small trend error; it is failing to raise a low-glucose alarm at night. The device carries a sentinel set of curated hypoglycaemia episodes in read-only flash. Every nightly personalisation update is computed as a candidate, scored on that sentinel set, and committed only if its recall on the hypo episodes does not drop, with \(\varepsilon = 0\) for that class. One night the wearer's sensor develops a compression artefact that looks like a plunge; the candidate update tries to absorb it, sentinel recall falls, and the gate rejects the update and keeps the prior weights. The personalisation stalls for a day rather than silently degrading a life-safety alarm. Because the decision and its sentinel scores are logged, the clinical-validation and regulatory trail of Chapter 34 stays intact even though the model changed in the field.

Envelopes, logging, and knowing when to stop learning

Gating each update is necessary but not sufficient, because many small accepted steps can drift a model a long way. Two additional controls matter. First, an update budget and drift monitor: track the cumulative parameter movement and the running sentinel margin, and when the model approaches the boundary of its validated envelope, freeze self-updating and require an authenticated over-the-air model from the fleet operator instead. This is where on-device learning hands back to fleet MLOps (Chapter 69). Second, an audit log: record for every update the timestamp, the number of samples, their gated confidences, the sentinel scores before and after, and the accept/reject decision, so that a field regression is diagnosable after the fact rather than a mystery. In functionally-safe domains the safest choice is often to let the model propose and a human or a fleet server dispose: the device accumulates candidate updates and evidence, but the certified weights change only through the governed channel, keeping the deployed model inside the envelope that ISO 26262 and the SOTIF framing of ISO 21448 (Chapter 68) assume.

The Right Tool

Rolling your own gate, trust-region clip, checkpoint store, and audit trail is a few hundred lines once you handle atomic checkpoint swaps, corrupted-write recovery, and structured logging. River (the online-learning library) supplies streaming metrics and drift detectors (ADWIN, Page-Hinkley) that raise the freeze signal for you, and MLflow or a lightweight model registry supplies versioned checkpoints with atomic promotion and rollback, so a sentinel gate plus drift-triggered freeze plus reversible checkpoints drops from several hundred lines to roughly thirty of glue. What no library decides for you is the content of the sentinel set and the value of \(\varepsilon\) per class: those encode which competencies are non-negotiable, and that is a safety judgement, not a default.

Research Frontier

The open problem is certifying a model whose weights change after deployment. Classical functional-safety cases assume a frozen artifact; a self-updating model breaks that assumption, and regulators from the FDA (with its Predetermined Change Control Plan guidance for adaptive medical AI) to automotive safety bodies are actively defining what a "learning-enabled" system may change and still remain certified. On the technical side, current directions include provable-forgetting and machine-unlearning guarantees so a poisoned sample can be provably removed, robust aggregation and Byzantine-resilient on-device updates borrowed from federated learning (Chapter 64) to defend against poisoning at fleet scale, and formal runtime monitors that bound a network's output over a certified input region. The unresolved tension is the one running through this whole chapter: the plasticity that keeps a field model relevant is exactly what a safety case wants to eliminate, and the frontier is making adaptation auditable and bounded enough that a certifier will accept it rather than forbidding on-device learning outright.

Exercise

Take the personalisation or imprinting head you built earlier in this chapter and wrap it with safe_update from Listing 62.7.1. Curate a sentinel set of 50 examples covering your base classes. Now stage two attacks: (a) a poisoning stream where 20% of "teaching" samples carry a flipped label, and (b) a transient-drift stream where a stuck-sensor pattern appears for 100 steps then vanishes. For each, run the model once with the gate disabled and once enabled, and plot sentinel accuracy over time. Report how much accuracy the gate preserves, how many updates it rejects, and the false-reject rate on genuinely helpful updates. Then sweep the trust-region radius \(\rho\) and the sample-confidence threshold \(\tau\) and describe the safety-versus-plasticity tradeoff you observe.

Self-Check

1. Name the three defining properties of a safe self-update and identify the line in Listing 62.7.1 that implements each.

2. Why must the sentinel set be immutable and separate from the field data stream? What guarantee would be lost if field samples were allowed to enter it?

3. Gating every individual update still lets a model drift far over time. What additional control stops this, and how does it decide when to hand control back to the fleet operator?

Lab 62

Implement latent-replay continual learning for a wearable model under a memory/energy budget.

What's Next

In Chapter 63, we drop the assumption that the device even has continuous power. When a sensor node harvests its energy and computes in intermittent bursts between brownouts, inference and learning must survive being interrupted mid-step, checkpoint their state, and resume, pushing the safety and continuity ideas of this chapter down to the level of a single capacitor's charge.

Bibliography

On-device and continual-learning safety

Gu, Dolan-Gavitt, and Garg (2017). BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain. arXiv.

The canonical demonstration that a few crafted training samples can implant a hidden backdoor, which is precisely the label-poisoning threat a self-updating field model faces without a gate.

Prabhu, Torr, and Dokania (2020). GDumb: A Simple Approach that Questions Our Progress in Continual Learning. ECCV.

Shows how easily continual-learning gains evaporate under honest evaluation, motivating the frozen sentinel set as an incorruptible measure of what an update must not lose.

Machine unlearning and reversibility

Bourtoule et al. (2019). Machine Unlearning. IEEE S&P.

Introduces SISA training for efficiently removing the influence of specific data, the formal basis for provably rolling back a poisoned on-device update.

Kirkpatrick et al. (2017). Overcoming Catastrophic Forgetting in Neural Networks (EWC). PNAS.

Elastic Weight Consolidation constrains parameter movement to protect prior knowledge, the conceptual ancestor of the trust-region bound used here to cap update damage.

Poisoning, drift, and robust aggregation

Koh and Liang (2017). Understanding Black-box Predictions via Influence Functions. ICML.

Quantifies how a single training example shifts a model's predictions, the analytical tool for reasoning about how much one gated sample may move an on-device model.

Blanchard et al. (2017). Machine Learning with Adversaries: Byzantine Tolerant Gradient Descent (Krum). NeurIPS.

Byzantine-resilient aggregation that filters malicious updates, directly applicable when self-updating devices contribute to a fleet or federated model.

Gama et al. (2014). A Survey on Concept Drift Adaptation. ACM Computing Surveys.

The reference survey on detecting and reacting to drift (ADWIN, Page-Hinkley), the signal that tells a self-updating device when to freeze and hand back to the operator.

Regulation and functional safety of adaptive AI

U.S. FDA (2024). Predetermined Change Control Plans for Machine Learning-Enabled Medical Devices. Guidance.

Regulatory template for pre-authorising bounded, specified model changes after deployment, the governance frame a self-updating medical sensor must fit inside.

ISO (2022). ISO 21448: Road Vehicles - Safety of the Intended Functionality (SOTIF).

Defines safety for correctly-functioning systems facing unforeseen conditions, the standard whose validated envelope an on-device update must not silently leave.