(prototype) SimCLR-family transforms return labelled views - #2037
(prototype) SimCLR-family transforms return labelled views#2037gabrielfruet wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 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): |
There was a problem hiding this comment.
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}, | |||
There was a problem hiding this comment.
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 👍 / 👎.
5 of 7 in a stack. Base: #2036. This is where PR 1's
Viewstarts being used.SimCLRTransformreturnslist[View]instead oflist[Tensor].MoCoV1Transform,MoCoV2TransformandDenseCLTransformsubclass 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 toMultiViewTransform: 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 separatingMultiViewTransformfromMultiViewTransformV2. 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.