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

VICReg

VICReg (Variance–Invariance–Covariance Regularisation; Bardes, Ponce and LeCun, ICLR 2022) makes the anti-collapse mechanism explicit, with three terms. Invariance: the mean squared distance between the two views' embeddings. Variance: a hinge keeping each dimension's standard deviation above 1 across the batch. Covariance: a penalty on off-diagonal covariances, decorrelating dimensions. It needs no negatives, momentum, predictor or batch-wise normalisation, and its two branches can even have different architectures. This page covers the three terms and the two collapse modes they prevent. In the exercises you implement the terms, then train VICReg and two ablations. Full VICReg reached probe accuracy 0.70 with a well-spread, rank-6 embedding. Without the variance term, the embedding collapsed to a point (std 0.001, probe 0.27). Without the covariance term, it collapsed onto about 1.6 effective dimensions (probe 0.46). All three seeds agree.

Level 0: Foundation

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

Three rules: agree, stay spread out, do not repeat

VICReg writes down three simple rules for a good embedding. Two views of the same image should land close together (invariance). Across a batch, every dimension should keep varying: no dimension may shrink to a constant (variance). Different dimensions should carry different information (covariance). Each rule blocks a different way the network could cheat. The demo shows how an embedding’s spread over dimensions shrinks 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

VICReg’s explicit terms make training easy to monitor and debug. Because its branches need not share architecture, it also suits multimodal pairs such as camera and lidar.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The variance term keeps each dimension…
  2. 2. The covariance term makes dimensions…
  3. 3. The invariance term pulls together…

Level 1: Beginner

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

By hand

  • Invariance: s(Z, Z’) = mean ‖z − z’‖², the MSE between the views (1 for vectors of ones against zeros).
  • Variance: v(Z) = (1/d) Σ_j max(0, γ − √(Var(z_j) + ε)) with γ = 1. A dimension with std 0.3 costs 0.7; std 1.5 costs 0.
  • Covariance: c(Z) = (1/d) Σ_(i≠j) Cov(Z)_ij². [[1, 0.5], [0.5, 1]] gives (0.25 + 0.25)/2 = 0.25.
  • Total: ℓ = λ s(Z, Z’) + μ[v(Z) + v(Z’)] + ν[c(Z) + c(Z’)] with λ = μ = 25 and ν = 1.
    • For example, 25·0.1 + 25·0.2 + 1·3 = 10.5.
  • Collapse modes:
    • complete: all embeddings equal, std 0, prevented by the variance term;
    • dimensional: few directions used, low effective rank, prevented by the covariance term.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Variance hinge for std 0.3, γ = 1:
  2. 2. Covariance term of [[1, 0.5], [0.5, 1]]:
  3. 3. Default VICReg weights (λ, μ, ν):

Level 2: Intermediate

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

VICReg in code

Exercise 1.

  • The variance term was about 1 for collapsed data and 0 for spread data.
  • The invariance term was the MSE.
  • The covariance term was large for redundant dimensions and near 0 for independent ones.

Practice.

  • The paper used an expander (projector) of 8192 dimensions with batch norm, LARS, and λ = μ = 25, ν = 1.
  • VICReg tolerates different encoders on the two branches, which suits multimodal learning.
  • Log the three terms separately: a rising variance term warns of collapse.
inv = F.mse_loss(za, zb)
std = lambda z: torch.sqrt(z.var(0) + 1e-4)
var = F.relu(1 - std(za)).mean() + F.relu(1 - std(zb)).mean()
cov = lambda z: (lambda c: (c - torch.diag(torch.diag(c))).pow(2).sum() / z.shape[1])(torch.cov(z.T))
loss = 25 * inv + 25 * var + 1 * (cov(za) + cov(zb))
🐍 Exercise 1: the three terms
Implement VICReg's variance, invariance and covariance terms.
📝 Quick check (Level 2)
0/3 answered
  1. 1. VICReg's branches must share architecture?
  2. 2. A warning sign of collapse:
  3. 3. VICReg needs negatives or a predictor?

Level 3: Advanced

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

Theory

Explicit regularisation.

  • Methods like BYOL and SimSiam avoid collapse implicitly, through architecture and optimisation (predictor, stop-gradient, EMA).
  • VICReg puts the safeguards into the loss: the variance hinge forbids collapse to a point, and the covariance penalty forbids collapse onto a subspace.
  • Its behaviour depends far less on delicate training details.

Relation to Barlow Twins. Barlow Twins standardises features (fixing variance) and decorrelates the cross-correlation between branches. VICReg keeps variance with a hinge instead of normalisation, decorrelates within each branch, and uses an MSE invariance term. The two are close cousins, but VICReg’s terms act on each branch separately.

Information view. The variance and covariance terms approximately maximise the entropy of the embedding distribution (spread, decorrelated), while invariance maximises agreement between views. Together they approximate maximising information shared across views.

📝 Quick check (Level 3)
0/3 answered
  1. 1. VICReg prevents collapse…
  2. 2. Barlow Twins fixes variance by…
  3. 3. Variance + covariance terms approximately maximise…

Level 4: Expert

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

Which term prevents which collapse?

History.

  • A. Bardes, J. Ponce and Y. LeCun, “VICReg: variance-invariance-covariance regularization for self-supervised learning” (ICLR 2022).
  • Follow-ups include VICRegL (local features, 2022) and links to joint-embedding predictive architectures (I-JEPA).

Exercise 2.

  • Setup: the same style-dominated world as before, with encoder 32 → 64 → 16 and projector 16 → 32 → 16, 1000 steps.
  • Variants: the full VICReg loss (λ = μ = 25, ν = 1); without the variance term (μ = 0); and without the covariance term (ν = 0).
  • Measurements: probe accuracy, plus the projector outputs’ mean standard deviation and effective rank (of 16).
variant probe accuracy projector std effective rank
raw observations 0.522 — —
VICReg 0.700 0.977 6.31
no variance term 0.272 0.001 2.48
no covariance term 0.464 1.076 1.60
  • Without the variance term, the embedding collapses to a point (std 0.001): invariance is trivially satisfied, and the probe falls far below raw features.
  • Without the covariance term, it collapses dimensionally: each dimension still varies (std about 1), but they move together, giving an effective rank of 1.6. The probe drops by 0.24.
  • Each term blocks exactly one failure mode, as designed. Seeds 1 and 2 gave the same pattern: VICReg 0.73 and 0.70; no variance 0.28 and 0.30 (std 0); no covariance 0.62 and 0.55 (rank 1.9 and 1.8).
🐍 Exercise 2 (research): which term prevents which collapse?
Train VICReg and ablations without the variance and without the covariance term, measuring probe accuracy, spread and effective rank.

VICReg in AI, robotics and aerospace

  • Multimodal pre-training: camera–lidar or image–telemetry pairs with different encoders per modality.
  • Robust training: explicit terms make collapse visible early, which helps unattended training on new sensor data.
  • Design lesson: if you know the failure modes, regularise against each one directly, and log each term.

References

  1. A. Bardes, J. Ponce and Y. LeCun (2022). “VICReg: variance-invariance-covariance regularization for self-supervised learning.” ICLR.
  2. J. Zbontar, L. Jing, I. Misra, Y. LeCun and S. Deny (2021). “Barlow Twins: self-supervised learning via redundancy reduction.” Proc. ICML.