"You trained me on your left wrist. I now meet a chest strap, a stranger, and a microphone in the same second. Tell me again which of us is the anomaly."
A Well-Traveled AI Agent
Prerequisites
This section assumes the self-supervised machinery of the earlier sections: the contrastive objective and its augmentation view of invariance from Section 17.2, masked reconstruction from Section 17.3, and any encoder that maps a window to a vector (Chapter 13). It leans on the sampling, resampling, and time-alignment discipline of Chapter 3, the leakage-safe splitting rules of Chapter 5, and the measurement-model reasoning of Chapter 2. Familiarity with distribution shift (Chapter 66) sharpens why any of this is hard.
The Big Picture
Everything you pretrained so far quietly assumed the deployment world looks like the pretraining world: the same watch model, worn by similar people, streaming the same channels. Reality breaks all three assumptions at once. A model trained on one accelerometer meets a different chip with a different noise floor and mounting (the device gap); it meets a new person whose gait, resting heart rate, and skin tone move the signal statistics (the user gap); and increasingly it must fuse channels that were never jointly labeled, learning that a spike in acceleration and a change in the photoplethysmography (PPG) waveform are two views of the same run (the modality gap). Cross-device, cross-user, cross-modal pretraining is the art of building one encoder whose representation survives all three shifts, so that the label-efficiency win of self-supervision does not evaporate the moment the model leaves the lab. The unifying idea is simple and powerful: treat device, subject, and modality not as fixed conditions but as additional axes of nuisance variation to be made invariant to, or additional views to be aligned, using the very same positive-and-negative geometry you already know.
Three gaps, one geometry
Name the shifts precisely, because each demands a different move. The device gap is a change in the measurement model: a new IMU has a different sensitivity, bias, sampling rate, and axis convention, so the same motion produces a numerically different window. The user gap is a change in the underlying signal source: person B's ECG morphology, stride length, or perfusion differs from person A's, so even an identical device yields a different distribution. The modality gap is structural: accelerometer, gyroscope, PPG, audio, and barometer live in different physical units, at different rates, with different information about the same latent event.
The reason one section can cover all three is that self-supervised learning already gives you the two verbs you need. To close a gap by invariance, you make windows that differ only along the nuisance axis into a positive pair, so the encoder is trained to ignore that axis. To close a gap by alignment, you take two genuinely different signals of the same event and pull their embeddings together, exactly the cross-modal contrastive move that CLIP made famous for images and text. Device and user gaps are usually attacked by invariance; the modality gap is usually attacked by alignment, though the boundary blurs.
Key Insight
The choice of what counts as a positive pair is your generalization target. Sample your two contrastive views from the same time window on two different devices, and you are commanding device invariance. Sample the anchor and positive from different subjects performing the same labeled activity, and you push toward user invariance (at the cost of erasing person-specific detail, which is wrong if the downstream task is biometric identity). Sample accelerometer and PPG from the same wall-clock instant as a positive, and you are learning a shared cross-modal space. The augmentation catalogue of Section 17.2 was one special case of this: a synthetic second view. Here the second view is often a real second sensor, which is strictly better evidence than any augmentation you could invent.
Closing the device and user gaps
Device invariance has three complementary levers. First, canonicalize the input so devices are less different before the network sees them: resample every stream to a common rate (Chapter 3), normalize units, and, for tri-axial inertial data, remove the orientation nuisance with rotation augmentation or a gravity-aligned frame. Second, treat device identity as an augmentation: if you have any windows recorded simultaneously on two devices, they are a free, physically exact positive pair, better than jitter or scaling because the difference is the true hardware gap rather than a guess at it. Third, discourage the encoder from encoding device identity at all, either with a domain-adversarial head that is trained to predict the device while the encoder is trained to fool it, or simply by including enough device diversity that device becomes uninformative.
The user gap yields to the same toolkit with one addition: batch and split by subject. Positives drawn across subjects who share an activity push the representation toward person-agnostic features, and, critically, evaluation must use leave-one-subject-out or grouped splits so that no window from a test person ever appears in training. Subject-level leakage is the single most common way a wearable paper reports a number it cannot reproduce in the field; the grouped-split discipline of Chapter 5 is not optional here. When some personalization is allowed at deployment, a small per-user adapter or a few labeled calibration windows recovers most of the person-specific accuracy without retraining the backbone, the pattern developed for wearable foundation models in Chapter 20.
Negative transfer is real
Pooling more devices, users, and modalities is not monotonically good. If two sources genuinely disagree about what a signal means, forcing them into one representation degrades both, a phenomenon called negative transfer. A wrist PPG and a fingertip pulse oximeter measure related but not identical physiology; aligning them too aggressively can blur the exact feature a downstream task needs. The tell is a pretraining loss that drops smoothly while every downstream probe gets worse. Guard against it by measuring per-source downstream accuracy, not just the aggregate, and by allowing modality-specific or device-specific parameters (a private encoder branch, a learned source token) so the model can keep what should stay separate.
Closing the modality gap by alignment
Cross-modal pretraining treats time-synchronized channels as paired views of one event and learns a shared embedding space with a symmetric contrastive loss. Give each modality \(m\) its own encoder \(f_m\) mapping a window to a unit vector. For a batch of \(N\) synchronized instants, modality-A embedding \(z^A_i\) and modality-B embedding \(z^B_i\) from the same instant \(i\) are a positive pair; all mismatched instants are negatives. The InfoNCE loss, run in both directions and averaged, is
$$\mathcal{L} = -\frac{1}{2N}\sum_{i=1}^{N}\left[\log\frac{\exp(z^A_i\!\cdot z^B_i/\tau)}{\sum_{j}\exp(z^A_i\!\cdot z^B_j/\tau)} + \log\frac{\exp(z^B_i\!\cdot z^A_i/\tau)}{\sum_{j}\exp(z^B_i\!\cdot z^A_j/\tau)}\right].$$
This is exactly the sensor analogue of image-text alignment, with wall-clock synchronization playing the role that human captions play for images. After pretraining, the shared space supports zero-shot cross-modal retrieval (find the PPG segment that matches this accelerometer burst) and, more usefully, graceful missing-modality behavior: because every modality maps into the same space, a downstream head trained on the fused embedding still functions when one sensor drops out, the robustness property studied in depth in Chapter 50. The alignment also opens the door to describing signals in language, the sensor-to-text bridge of Chapter 21.
The listing below is the complete cross-modal contrastive step. Two per-modality encoders produce embeddings for the same synchronized batch; the symmetric InfoNCE above is computed as two cross-entropies over the shared similarity matrix, matching the equation term for term.
import torch
import torch.nn.functional as F
def cross_modal_infonce(z_a, z_b, temperature=0.1):
# z_a, z_b: (N, D) embeddings; row i of BOTH is the SAME synchronized instant
z_a = F.normalize(z_a, dim=1)
z_b = F.normalize(z_b, dim=1)
logits = z_a @ z_b.t() / temperature # (N, N): logits[i, j] = A_i . B_j
targets = torch.arange(z_a.size(0), device=z_a.device) # positive of i is i
loss_a2b = F.cross_entropy(logits, targets) # accel query -> match its PPG
loss_b2a = F.cross_entropy(logits.t(), targets) # PPG query -> match its accel
return 0.5 * (loss_a2b + loss_b2a) # symmetric, CLIP-style
logits holds the true (same-instant) pairs; the two cross_entropy calls implement the two directions of the loss above. Swap z_a/z_b for any modality pair (accelerometer and PPG, audio and vibration, radar and camera). Correct synchronization is the whole ballgame: a fixed offset between the streams silently poisons every positive pair.Practical Example: one encoder for a fragmented smart-ring fleet
A digital-health startup ships three smart-ring hardware revisions. Rev 1 has only an accelerometer at 25 Hz; Rev 2 adds green PPG at 100 Hz; Rev 3 adds red and infrared PPG and a skin-temperature channel. Labeled sleep-stage data exists for a few hundred Rev 2 users only. Training separately per revision wastes the millions of unlabeled Rev 1 and Rev 3 hours and produces three models to maintain. Instead the team pretrains a single encoder: accelerometer windows are canonicalized to a common rate and made rotation-invariant, simultaneous accelerometer-and-PPG windows from Rev 2 and Rev 3 supply real cross-modal positive pairs via the InfoNCE loss above, and inherited masking lets the model consume windows with whichever channels are present, so Rev 1 (accelerometer only) still contributes. Batches are grouped by user and evaluated leave-one-subject-out. The result is one backbone that runs on all three rings, degrades gracefully when PPG is missing, and, fine-tuned on the small Rev 2 sleep labels, transfers zero-shot to Rev 3, whose extra channels it had never seen labeled. This is the fragmented-fleet reality that motivates the large sensor models of Chapter 20.
Right Tool: don't rebuild the multi-encoder trainer
A correct multi-modal contrastive trainer, with per-modality encoders, synchronized multi-stream loading, resampling, a missing-modality collate that pads absent channels, gathering embeddings across GPUs for a large negative pool, and the symmetric loss, is roughly 400 to 600 lines. Frameworks such as lightly (SSL heads and losses), tsai (time-series-first pipelines), or a small wrapper around torchmultimodal reduce the core loop to about 30 lines: you provide one encoder per modality and a synchronized dataset, and the library owns the cross-GPU gather, the temperature schedule, and the InfoNCE bookkeeping. Keep synchronization and the choice of what is paired in your own hands; that is the domain knowledge no library can supply.
Research Frontier: learning from incomplete, multi-device, multi-rate data
The frontier has moved from single-sensor SSL to models built to be cross-device and cross-modal from the start. Google's Large Sensor Model (LSM) and its successor LSM-2 pretrain on very large, heterogeneous wearable corpora and introduce adaptive and inherited masking, which lets one model learn from windows with arbitrary missing channels and devices rather than discarding incomplete data. Apple-style biosignal foundation models pretrain PPG, ECG, and accelerometer jointly at population scale, aligning modalities so a single backbone serves many downstream tasks (Chapter 20). Open questions remain sharp: how to align modalities that are only loosely synchronized or sampled at wildly different rates; how to prevent negative transfer when pooling clinical-grade and consumer-grade sensors; and how to do cross-user pretraining without centralizing biometric data at all, which is where privacy-preserving and federated training (Chapter 64) meets self-supervision. Verify any named model and its claims before citing; this literature moves fast.
Exercise
Take a public multi-device human-activity dataset that records the same activities on a wrist and a waist sensor (or synthesize one by holding out a device). (1) Pretrain an encoder using only single-device augmentation positives, then evaluate leave-one-device-out: train a linear probe on wrist windows, test on waist. Record the drop. (2) Now add cross-device positives (same time window, both devices) to the pretraining and repeat. Quantify how much of the device gap the cross-device positives closed. (3) Add a domain-adversarial head that predicts the device from the embedding. Does making the embedding device-unpredictable help the leave-one-device-out probe, or does it start erasing signal the activity task needs? Explain the result using the negative-transfer discussion above.
Self-Check
- Distinguish the device gap, the user gap, and the modality gap in one sentence each, and say for each whether it is more naturally closed by invariance or by alignment.
- In cross-modal InfoNCE, what real-world quantity plays the role that human captions play in image-text CLIP, and what goes wrong if it is off by a fixed offset?
- You pretrain on pooled clinical ECG and consumer wrist PPG and every downstream probe gets worse while the pretraining loss keeps dropping. Name the failure and two concrete design changes that would let the model keep the sources appropriately separate.
What's Next
In Section 17.7, we stop assuming a good representation and start measuring one. You will learn the probing toolkit, linear and few-shot probes, retrieval and clustering metrics, and leakage-safe evaluation, that tells you whether all this cross-device, cross-user, cross-modal pretraining actually produced features worth deploying, or merely a loss curve that looked reassuring.