Implement VISReg (Variance-Invariance-Sketching Regularization) loss + examples
#1,960 opened on 2026年7月2日
Repository metrics
- Stars
- (3,775 stars)
- PR merge metrics
- (PR metrics pending)
説明
Add VISReg loss + examples
Paper: https://arxiv.org/abs/2606.02572 (Wu, Balestriero, Levine, Jun 2026) Official repo: https://github.com/HaiyuWu/visreg
Sits between VICRegLoss and SIGReg/LeJEPALoss: keeps the variance term from VICReg, replaces covariance with a sliced-Wasserstein sketching term against an isotropic Gaussian. O(NDK), and unlike SIGReg the gradient doesn't vanish under collapse (their Fig. 2).
Note: the official repo is CC BY-NC 4.0, non-commercial. Fine as a reference for the math (Algorithm 1 is unambiguous), but we shouldn't port code directly given our license.
Two PRs:
PR 1: Loss
lightly/loss/visreg_loss.py, structured likeLeJEPALoss- Don't forget to reference the paper and authors.
- register in
lightly/loss/__init__.py - update
docs/source/lightly.loss.rst(autodoc entry, same pattern asVICRegLoss/LeJEPALoss)
class VISRegLoss(nn.Module):
def __init__(
self,
lambda_param: float = 0.9,
num_slices: int = 4096,
lambda_scale: float = 1.0,
lambda_shape: float = 1.0,
lambda_center: float = 1.0,
gather_distributed: bool = False,
eps: float = 1e-4,
):
...
def forward(self, z: Tensor) -> Tensor:
...
Open points:
- Distributed: paper generates K slices per GPU, no batch gather (Sec 3.2, Fig. 6). Use that instead of the SIGReg
all_reducepattern from #1920. - Return component losses (scale/shape/center/pred) separately — same as #1422 for VICReg. Table 12 shows shape-loss weight is the main tuning lever for long-tailed/low-rank data.
- Reuse
LeJEPAProjectionHead, no new head needed (no changes tolightly/models/modules/heads.pyexpected). - Use the best hyperparameters combinations defined in the paper.
Tests:
- Try to match same testing patterns for the other losses.
PR 2: Examples (depends on PR 1)
examples/pytorch/visreg.pyexamples/pytorch_lightning/visreg.pyexamples/pytorch_lightning_distributed/visreg.pydocs/source/examples/visreg.rst, same format asvicreg.rst, plus adding it to the examples toctree/index- add VISReg to the model list in the main README and docs landing page
Follow the VICReg examples structure: backbone + LeJEPAProjectionHead + VISRegLoss, multi-crop augmentation per paper's A.1 setup.