Foundations to Frontier
Tests
E. Deep Learning › E16 Self-Supervised and Contrastive Learning

SimSiam

SimSiam (Chen and He, CVPR 2021) strips non-contrastive learning to its core: one network processes two views, a predictor sits on one side, and the loss is the negative cosine similarity between the prediction and the other view's output. That output is treated as a constant. There are no negatives, no momentum encoder and no large batches. Chen and He showed that the stop-gradient is what prevents collapse, and suggested SimSiam can be read as an expectation–maximisation-like alternation. This page covers the architecture, the stop-gradient and the collapse diagnostics. In the exercises you implement the loss and an effective-rank measure, then train SimSiam and two ablations. SimSiam reached probe accuracy 0.67 with healthy embedding spread. Without stop-gradient (0.22) and without the predictor (0.30), it collapsed on all three seeds, with spread falling to 0.05.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Make two views agree, but only push one of them

SimSiam uses a single network on two altered views of an image. One side gets a small extra “predictor” and is trained to match the other side’s output. The trick is that the other side is held fixed while computing the update; no gradient flows into it. Without that one line, the network quickly learns to output the same thing for every image, which matches perfectly and means nothing. The demo shows the spread of an embedding shrinking as it collapses.

Self-supervised learning lab
Effective rank 15.6 of 16 dimensions. Non-contrastive methods need stop-gradients, predictors, centring or variance terms to keep the spectrum from collapsing to a few directions.
Why engineers care

SimSiam needs neither large batches nor a momentum encoder, which makes it one of the cheapest self-supervised methods to run on in-house data.

📝 Quick check (Level 0)
0/3 answered
  1. 1. SimSiam uses how many networks?
  2. 2. The 'other side' during an update is…
  3. 3. Without stop-gradient the network…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Architecture: shared encoder plus projector f gives z₁ = f(x₁), z₂ = f(x₂); a predictor h gives p₁ = h(z₁), p₂ = h(z₂).
  • Loss: L = ½D(p₁, sg(z₂)) + ½D(p₂, sg(z₁)) with D(p, z) = −cos(p, z), where sg is stop-gradient.
    • The minimum is −1 (aligned); halves of −1 and −0.5 give −0.75.
  • Collapse: a constant output also reaches −1, so the objective alone cannot rule it out.
  • Diagnostics:
    • the standard deviation of normalised outputs (about 1/√d when healthy, 0 when collapsed);
    • effective rank, exp(entropy of normalised singular values): 16 for 16 equal singular values, 1 for a single direction.
📝 Quick check (Level 1)
0/3 answered
  1. 1. D(p, z) for parallel p and z:
  2. 2. Symmetrised loss for halves −1 and −0.5:
  3. 3. Effective rank of a fully collapsed embedding:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

SimSiam in code

Exercise 1.

  • Negative cosine was −1 for parallel vectors.
  • Effective rank was above 6 for random 8-D data and 1 for data along a single direction.

Practice.

  • In PyTorch, z.detach() is the stop-gradient.
  • Use a predictor bottleneck (2048 → 512 → 2048 in the paper), batch norm in the projector, and SGD with a fixed predictor learning rate.
  • SimSiam works with batch sizes of 256 or even smaller.
  • Monitor the output standard deviation during training: a drop toward 0 signals collapse.
z1, z2 = proj(enc(x1)), proj(enc(x2))
p1, p2 = pred(z1), pred(z2)
loss = -(F.cosine_similarity(p1, z2.detach()).mean() + F.cosine_similarity(p2, z1.detach()).mean()) / 2
🐍 Exercise 1: loss and collapse diagnostics
Implement negative cosine, the symmetrised SimSiam loss and effective rank.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Stop-gradient in PyTorch:
  2. 2. SimSiam needs large batches?
  3. 3. A collapse signal:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

An EM-like view (Chen and He).

  • Treat the target representations η_x as extra variables. The loss is minimised alternately: (1) with η fixed, update the network to match η; (2) set η to the network’s output averaged over augmentations.
  • Stop-gradient implements step 1, where the target is fixed, and the predictor approximates the expectation over augmentations in step 2.
  • Back-propagating into the target merges the two steps into a single objective whose easiest solution is collapse.

Relation to BYOL. SimSiam is BYOL with momentum 0. Chen and He showed that the momentum encoder is not essential, while the stop-gradient and predictor are, though how robust this is depends on training details such as the learning rate.

Dynamics. Analyses of linear models show that the predictor aligns with the correlation structure of the representations, and stop-gradient keeps the dominant directions from shrinking, preventing dimensional collapse.

📝 Quick check (Level 3)
0/3 answered
  1. 1. In the EM view, stop-gradient implements…
  2. 2. SimSiam is BYOL with…
  3. 3. Back-propagating into the target leads to…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Is the stop-gradient really what prevents collapse?

History.

  • X. Chen and K. He, “Exploring simple Siamese representation learning” (CVPR 2021).
  • Y. Tian, X. Chen and S. Ganguli (ICML 2021), dynamics of non-contrastive learning.
  • L. Jing et al. (ICLR 2022), dimensional collapse in self-supervised learning.

Exercise 2.

  • Setup: the same style-dominated world, encoder (32 → 64 → 16), projector and predictor (16 → 32 → 16) as before, 1500 Adam steps at learning rate 0.003, symmetric loss.
  • Variants: SimSiam; without stop-gradient (gradients flow into both branches); and without the predictor.
variant probe accuracy embedding spread
raw observations 0.522 0.176
SimSiam 0.672 0.171
no stop-gradient 0.216 0.054
no predictor 0.304 0.058
  • Stop-gradient is essential: without it, the spread collapsed 3-fold and accuracy fell far below raw features. Seeds 1 and 2 gave 0.29 and 0.22.
  • So is the predictor: removing it collapsed training as well (0.28 and 0.26 on seeds 1 and 2).
  • SimSiam itself trained stably, at 0.59–0.68 across three seeds, without negatives or momentum.
  • A caveat from the BYOL page: the same network (BYOL without momentum) collapsed at learning rate 0.01. Stop-gradient is necessary but not sufficient; optimisation settings matter too.
🐍 Exercise 2 (research): is the stop-gradient really what prevents collapse?
Train SimSiam, SimSiam without stop-gradient and SimSiam without the predictor, measuring probe accuracy and embedding spread.

SimSiam in AI, robotics and aerospace

  • Low-cost pre-training: a strong default when compute is limited and data is unlabelled.
  • Edge and embedded learning: small batches and no extra encoders make on-device adaptation plausible.
  • Design lesson: when an objective has trivial solutions, check which architectural or optimisation choices keep training away from them, and verify with ablations.

References

  1. X. Chen and K. He (2021). “Exploring simple Siamese representation learning.” Proc. CVPR.
  2. Y. Tian, X. Chen and S. Ganguli (2021). “Understanding self-supervised learning dynamics without contrastive pairs.” Proc. ICML.
  3. L. Jing, P. Vincent, Y. LeCun and Y. Tian (2022). “Understanding dimensional collapse in contrastive self-supervised learning.” ICLR.