← All tutorials

Self-Supervised Learning Failure Modes and Checks

On this page

1 Overlapping receptive fields give the network a shortcut 2 Collapse puts embeddings on one point or a few directions 3 Batch size, temperature and augmentation decide success 4 BatchNorm can leak information across a batch 5 A probe score is not the whole story 6 Five checks to watch while training 7 References

Every method here learns embeddings (output vectors) and fails when it can solve its training task without learning the objects, their parts and the scene.

Failure and its signFix
Shared pixelslearns edges, not objectsgap and jitter between patches, drop color, hide 75%
Complete collapselowest loss, chance accuracystop-gradient, predictor or negatives
Dimensional collapsenear-zero singular valuesprojection head, then probe the encoder output
Too few negativesaccuracy falls with batchqueue or no negatives
BatchNorm leaktraining task solved almost perfectly, k-NN (a nearest-neighbor vote) fallsshuffle or sync BatchNorm
Figure 1. Each failure, the sign to look for, and its fix.

The stop-gradient and predictor are taught in Non-Contrastive Self-Supervised Learning, and the 75% mask in Masked Image Modeling. Image-Text Contrastive Learning (CLIP) uses the other captions in its batch as negatives, so a small batch gives it the “Too few negatives” failure too.

1 Overlapping receptive fields give the network a shortcut

A receptive field is the part of the input an output sees. When the inputs seen by the two compared outputs overlap or touch, the network can match the shared pixels and learn nothing about the objects in the image.

1.1 Patch position needed a gap, jitter and no color

Doersch et al. (2015) asked a network which of eight positions a second 96 px patch sat at around the first. Shared edges, continuing lines and a lens’s color fringe (chromatic aberration) gave it away, so they added a gap, a random shift (jitter) and dropped color.

patch A patch B shortcuts edges cross lines line up color fringe patch A patch B fixes 48 px gap jitter, 7 px drop color
Figure 2. Top, the red shortcuts; bottom, the green fixes that remove them.
overlapgap
gap used in the paper (half a patch)

Figure 3. Only a wide gap plus jitter leaves content as the only clue.

1.2 Predicting further ahead leaves the overlap behind

CPC (Contrastive Predictive Coding, van den Oord et al. 2018) learns from speech: from the audio so far it predicts summaries of the next K short stretches. The nearest stretches overlap the current one, so predicting them can copy shared samples. The accuracy of a linear classifier at naming the phoneme (speech sound, 41 classes, LibriSpeech) from the learned vectors shows which K learns more.

current 1 ahead 2 ahead 3 ahead none shared input samples shared with the current one
Figure 4. Each bar is the 29 ms of audio that one vector sees; bars start 10 ms apart.
Phoneme accuracy2030405060702481216K, the number of steps predictedfrom K = 3, adds stepswith no shared input28.564.6
Figure 5. Accuracy against K (CPC Table 2); from K = 3 each added step shares no input.

2 Collapse puts embeddings on one point or a few directions

Complete collapse maps every input to one embedding; the loss reaches its lowest value while accuracy falls to chance, as SimSiam does when its stop-gradient (a block on gradients to the target side) is removed. In dimensional collapse (Jing et al. 2022), the embeddings spread along only a few directions, so a linear probe scores poorly.

Negatives do not prevent it: the dimensional-collapse paper (Fig. 2) finds that SimCLR’s 128-number embeddings leave several directions unused. It has two causes. Edits that change images along a direction more than real images differ along it teach the encoder to ignore that direction (sec. 4). Stacked layers also pull their weights toward few directions (implicit regularization), even under weak edits (sec. 5).

Average every image’s outer product around the batch mean into one table, the covariance; its near-zero singular values reveal unused directions.
ci = (zi − z̄)(zi − z̄)T
Each image contributes one table of how its numbers move together. zi is image i’s embedding, a column of numbers. z̄ (z bar) is the batch mean. Subtracting it centers the cloud, so only how each image differs from the average counts. The superscript T turns the second copy into a row, so column times row is a square table with one entry for each pair of numbers. An entry is positive when both numbers sit above, or both below, their means. That table ci is image i’s contribution to the average.
C = 1N Σi=1N ci
The covariance C averages the contributions of all N images in the batch into one table. Its diagonal holds each number’s variance, and the rest says how pairs of numbers move together. Its singular values λ are the variance, the squared spread, along each of its directions. When the embeddings fill only a flat slice, the directions across the slice get λ near zero, which is dimensional collapse.

Figure 6. The top 2 directions plot looks fine; in spread per direction, bars below the dashed line are unused.

3 Batch size, temperature and augmentation decide success

Three settings decide whether contrastive training works. Batch size sets how many negatives (images pushed away) SimCLR sees. The temperature τ sets how sharply the loss focuses on the closest negatives. Augmentation sets what the two views share.

Temperature τ SimCLR, batch 4096, 100 epochs 59.7 64.4 60.7 58.0 0.05 0.1 0.5 1 Batch size SimCLR, 200 epochs (reported by MoCo v2) 61.9 66.6 256 8192
Figure 7. ResNet-50 linear probe top-1 (%) on ImageNet; bars start at 55%.
SettingRuleTaught in
Temperaturetune; best 0.1 for SimCLR, 0.2 for MoCo v2Contrastive Learning, InfoNCE
Augmentationstrong; crops alone cost both methods accuracy (bars of Figure 8)Contrastive Learning, augmentations; Section 2, collapse
Data other than photosedits that keep what the sample isRegularization, Data Augmentation for Wearables
Top-1 (%), all edits against crops only BYOL, all edits 72.5 BYOL, crops only 59.4 SimCLR, all edits 67.9 SimCLR, crops only 40.3
Figure 8. Each setting, its rule and where it is taught; bars from BYOL Fig. 3b and App. F.3.

4 BatchNorm can leak information across a batch

BatchNorm normalizes each feature with the mean and variance of the samples on one GPU. In MoCo, the query is one view’s embedding and its positive key is the other view’s. If the two sit in the same GPU batch, they share those statistics, and the network can match them by that shared signal instead of by content (MoCo App. A.9). MoCo shuffles keys across GPUs; SimCLR averages statistics over all devices (SyncBatchNorm on GPUs).

same order GPU 1, queries 1, 2 keys 1, 2 GPU 2, queries 3, 4 keys 3, 4 query 1 and key 1 share statistics keys shuffled GPU 1, queries 1, 2 keys 3, 4 GPU 2, queries 3, 4 keys 1, 2 statistics come from different subsets
Figure 9. In same order, query 1 and key 1 share statistics; keys shuffled breaks that.

5 A probe score is not the whole story

A probe and fine-tuning (training the encoder too) can rank methods differently. MoCo v2 tested two changes on MoCo: an MLP projection head and blur augmentation (Table 1, ResNet-50, 200 epochs). The head helps the frozen-encoder probe more; blur helps more once the encoder is fine-tuned for object detection (drawing boxes around objects, PASCAL VOC).

probe top-1 % detection VOC AP50 1st 2nd MLP head 66.2% blur 63.4% blur 82.2 MLP head 82.0
Figure 10. Lines join probe rank to detection rank (AP50, a box counts at half overlap).

6 Five checks to watch while training

Five cheap checks catch these failures early. Alignment (how close pairs sit) and uniformity (how evenly embeddings spread) come from Wang and Isola’s paper.

Check over traininghealthybroken
Spread (mean standard deviation per number), near 1/√d
Effective rank (directions in use), far from 1
Alignment (positive-pair distance), low but above 0
Uniformity loss, never above 0, lower is more even
k-NN accuracy, rising
Figure 11. Sketched shapes; a collapsed run still reaches the lowest loss.
WhenMoCo plots k-NN through training (Fig. A.1); no paper sets an interval
Dataa held-out batch; k-NN adds a bank of labeled training embeddings
Costforward passes only

The first snippet checks one batch of d-number embeddings; eff_rank counts the directions in use (Roy and Vetterli 2007).

import torch
import torch.nn as nn
import torch.nn.functional as F

N, d = 256, 128
encoder = nn.Linear(32, d)                       # stand-in
x = torch.randn(N, 32)
with torch.no_grad():
    Z = F.normalize(encoder(x), dim=1)           # [N, d], unit rows
spread = Z.std(dim=0).mean()                     # near 1/sqrt(d)
C = torch.cov(Z.T, correction=0)                 # divide by N
lam = torch.linalg.svdvals(C)
shares = lam / lam.sum()
eff_rank = torch.special.entr(shares).sum().exp()   # 1 to d
  1. 1One batch of unit embeddings Z, the zi of Section 2 eq line 1.
  2. 2Spread per dimension, the first row of Figure 11.
  3. 3Covariance C, eq lines 1 and 2.
  4. 4Singular values and the effective rank, the bars in Figure 6.

The second follows that paper’s code; both numbers fall as training works.

import torch
import torch.nn.functional as F

ALPHA, UNIF_T = 2, 2                             # the paper's defaults
N, d = 256, 128
z1 = F.normalize(torch.randn(N, d), dim=1)
z2 = F.normalize(z1 + 0.1 * torch.randn(N, d), dim=1)
align = (z1 - z2).norm(dim=1).pow(ALPHA).mean()
sq = torch.pdist(z1).pow(2)                      # every pair, squared
uniform = torch.exp(-UNIF_T * sq).mean().log()   # at most 0
  1. 1Toy positive pairs, two views per image, the pairs measured in the alignment row of Figure 11.
  2. 2Alignment, the positive-pair distance, the third row of Figure 11. A larger ALPHA weights pairs that sit far apart more; at 2 it is the squared distance.
  3. 3Uniformity over all pairs, the fourth row of Figure 11. A larger UNIF_T scores only the closest pairs; a smaller one scores all pairs evenly. The paper’s best runs used t = 2 (STL-10, NYU-Depth-V2), 3 (ImageNet-100) and 5 (BookCorpus).

The third is k-NN accuracy, a majority vote of the 20 nearest training embeddings.

import torch
import torch.nn.functional as F

K_NEIGHBORS, n_train, n_val, d = 20, 1000, 200, 128
bank = F.normalize(torch.randn(n_train, d), dim=1)
train_y = torch.randint(0, 10, (n_train,))
query = F.normalize(torch.randn(n_val, d), dim=1)
val_y = torch.randint(0, 10, (n_val,))

sim = query @ bank.T                             # [n_val, n_train]
top = sim.topk(K_NEIGHBORS, dim=1)
pred = train_y[top.indices].mode(dim=1).values   # majority vote
knn_acc = (pred == val_y).float().mean()
  1. 1A bank of labeled training embeddings and queries to classify, for the last row of Figure 11.
  2. 2Cosine, top 20, majority vote and accuracy, the last row of Figure 11. More neighbors give a smoother but blurrier vote; at 1 a single noisy neighbor decides. DINO found 20 neighbors best with a similarity-weighted vote; a plain majority vote is the simplest version.

Knowledge Distillation, a trained encoder teaching a smaller student, is a related tutorial.

7 References