feat(benchmarks): add VISReg to the ImageNet vitb16 benchmark - #1997
Merged
gabrielfruet merged 2 commits intoAug 3, 2026
Merged
Conversation
Register VISReg as a selectable method in the imagenet/vitb16 runner: a new visreg.py (VISReg LightningModule + 4-global/6-local multi-crop transform) and a two-line entry in main.py's METHODS registry. The module mirrors lejepa.py so the two run head-to-head on the same backbone, optimizer, and eval, differing only where VISReg's paper requires. Settings are VISReg's paper-best, each cross-checked against the paper and the official reference implementation: ViT-S/16, 4 global + 6 local views, lr 9e-4, lambda 0.9, K=2048, a GELU projector to 256-d, and gather_distributed=True. Two spots follow the reference code over the paper's prose: the projector runs on the last-layer CLS token only, and a single uniform augmentation is shared by all crops. Purely additive; no lightly/ source is touched and VISRegLoss is only imported. Related to lightly-ai#1960. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
gabrielfruet
enabled auto-merge (squash)
August 3, 2026 19:36
gabrielfruet
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #1960 — adds the ViT benchmark requested in this maintainer comment, building on the
VISRegLossfrom #1968.Description
Registers VISReg as a selectable method in the
imagenet/vitb16runner: a newbenchmarks/imagenet/vitb16/visreg.py(VISRegLightningModule+ multi-croptransform) plus a two-line entry inmain.py'sMETHODSdict. The module mirrorslejepa.pyso the two run head-to-head on the same backbone, optimizer, and eval, differing only where VISReg's paper says they should.Per the maintainer note ("use the best setting in the paper as much as possible, like LeJEPA"), the settings are VISReg's own paper-best, each cross-checked against the paper and the official repo (not just the paper prose, which diverges from the code in two places):
vit_small_patch16_224n_global: 4(needs a customMultiViewTransform;DINOTransformis fixed at 2 global)_shared_aug9e-4lr: 9e-4embed→2048→2048→256, BatchNorm + GELU, last layer bareViTEncoder.proj(proj_gelu: true); projects the last-layer CLS onlyVISRegLoss(num_slices=2048, gather_distributed=True)gather_distributed=Truematches the reference's autograd-awareall_gatherbefore the reg statistics, and the sibling LeJEPA0.9/5e-2Two spots where the reference code overrides the paper's own text, worth noting since they look like bugs otherwise: the projector runs on the last-layer CLS token only (
self.proj(last_cls)), not the "concatenated last-two-layer CLS" the paper describes — that concat is the eval-probe embedding — soinput_dim=embed_dim, not2×; and the augmentation is a single distribution shared by all crops, with no DINO-style global asymmetry.Purely additive: no
lightly/source is touched,VISRegLossis only imported, and the newMETHODS["visreg"]key affects a run only when--methods visregis passed.Tests
Benchmark method modules aren't unit-tested in this repo (same as
dino.py,lejepa.py, etc.) and sit outside thepytest/mypytargets, so I verified with a smoke test plus the standard checks. Before:--methods visregis not a registered method. After: it constructs and trains a step end-to-end.smoke test: transform emits 4 global + 6 local, projector is the paper's GELU
384->2048->2048->256, and one training step runs end-to-end
python - <<'PY'
import sys; sys.path.insert(0, "benchmarks/imagenet/vitb16")
import torch, visreg
from PIL import Image
v = visreg.transform(Image.new("RGB", (256, 256)))
print(len(v), "views;", sum(x.shape[-1] == 224 for x in v), "global,", sum(x.shape[-1] == 96 for x in v), "local")
m = visreg.VISReg(batch_size_per_device=4, num_classes=10)
m.log = m.log_dict = lambda *a, **k: None
b = [torch.randn(4, 3, 224, 224)] * 4 + [torch.randn(4, 3, 96, 96)] * 6
print("loss", float(m.training_step((b, torch.randint(0, 10, (4,)), [""] * 4), 0).detach()))
PY
-> 10 views; 4 global, 6 local
-> loss ~3 (finite scalar; exact value varies with random init)
make format-check # All checks passed!
make lint # All checks passed!
make type-check # Success: no issues found in 542 source files
make test-fast # 1687 passed, 249 skipped; 4 failures are pre-existing macOS/Py3.9 env issues, not hit by CI and unrelated to this diff
ruff check benchmarks/imagenet/vitb16/visreg.py benchmarks/imagenet/vitb16/main.py # All checks passed!