Skip to content

(prototype) SimCLR-family transforms return labelled views - #2037

Draft
gabrielfruet wants to merge 1 commit into
simclr-v2-04-optimfrom
simclr-v2-05-view-transforms
Draft

(prototype) SimCLR-family transforms return labelled views#2037
gabrielfruet wants to merge 1 commit into
simclr-v2-04-optimfrom
simclr-v2-05-view-transforms

Conversation

@gabrielfruet

@gabrielfruet gabrielfruet commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Prototype. Do not merge. This is a design exploration for the LightlySSL 2.0
refactor, opened to be read and argued with, not to land on master. The whole
stack goes together or not at all, and the shape is still open.

5 of 7 in a stack. Base: #2036. This is where PR 1's View starts being used.

SimCLRTransform returns list[View] instead of list[Tensor]. MoCoV1Transform, MoCoV2Transform and DenseCLTransform subclass it, so they come along. Every other transform is untouched and keeps returning tensors until its own method is ported.

The views are labelled at the line that builds them, so no training loop has to recover the grouping from views[:2]. Symmetric methods are finished at that; asymmetric ones override __call__ and state the asymmetry they already know.

A new base, ViewTransform, rather than a change to MultiViewTransform: an override cannot narrow the base's return type without a mypy error, and flipping the base means flipping all 16 subclasses in one PR. It takes *args, which is the one line separating MultiViewTransform from MultiViewTransformV2. The two bases merge when the last method is ported.

44 of the 46 files are one line each. The examples, benchmarks and tutorials that use these four transforms take collate_fn=legacy_collate, which hands them the tuple they were written against. The README quickstart moves to the new contract instead.

Testing: pytest tests/transforms, 93 cases.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4b920278e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".



class SimCLRTransform(MultiViewTransform):
class SimCLRTransform(ViewTransform):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add a view-aware collator to the SimCLR examples

After this base-class change, the three SimCLR Python examples and their notebook equivalents still construct a default DataLoader (for example, examples/pytorch/simclr.py:43-58) rather than using collate or legacy_collate. When these examples fetch their first batch, PyTorch's default collator encounters the new View dataclass instances and raises a TypeError, so none of the bundled SimCLR examples can begin training.

Useful? React with 👍 / 👎.

@@ -79,7 +80,6 @@ def warn_with_traceback(message, category, filename, lineno, file=None, line=Non
"dclw": {"model": dclw.DCLW, "transform": dclw.transform},
"dino": {"model": dino.DINO, "transform": dino.transform},
"mocov2": {"model": mocov2.MoCoV2, "transform": mocov2.transform},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore SimCLR to the ImageNet benchmark registry

Removing the simclr entry disables an existing benchmark even though the new conditional legacy_collate in pretrain() now supports its ViewTransform: invoking this script with --methods simclr reaches METHODS[method] and raises KeyError, while an invocation without --methods silently stops running SimCLR altogether. The existing benchmarks/imagenet/resnet50/simclr.py model and transform remain present, so the entry should stay registered.

Useful? React with 👍 / 👎.

@gabrielfruet gabrielfruet changed the title SimCLR-family transforms return labelled views (prototype) SimCLR-family transforms return labelled views Aug 16, 2026
@gabrielfruet
gabrielfruet marked this pull request as draft August 16, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant