Skip to content

(prototype) Add the backbone protocols and a torchvision ResNet adapter - #2034

Draft
gabrielfruet wants to merge 1 commit into
simclr-v2-01-batch-contractfrom
simclr-v2-02-backbones
Draft

(prototype) Add the backbone protocols and a torchvision ResNet adapter#2034
gabrielfruet wants to merge 1 commit into
simclr-v2-01-batch-contractfrom
simclr-v2-02-backbones

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.

2 of 7 in a stack. Base: #2033.

A masked vision transformer exists once per backbone source today: 1,951 LOC across 8 files, where both wrappers implement the same seven members and the only real difference is what the wrapped model calls its parts. A third source costs a third copy of masking that has nothing to do with masking.

Backbone declares feature_dim and embed(images) -> (B, feature_dim). DenseBackbone adds feature_map, which returns (B, N, D) plus the grid, and is the granularity a dense loss and a segmentation probe read. embed is deliberately not spelled forward_features: that name is timm's, where it returns tokens or a feature map, so a raw timm model would satisfy the old spelling and return the wrong rank.

TorchvisionResNetBackbone is the first adapter, and the user names it rather than a factory picking it. small_image_stem is the 3x3 stride-1 stem the CIFAR benchmark used through ResNetGenerator.

mypy checks that a member exists with the right signature. It cannot check that a member does what the contract says, since raise NotImplementedError is a body. tests/backbones/test_conformance.py is the second check, parameterised over a registry every adapter joins.

Testing: pytest tests/backbones, 14 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: d3baee9500

ℹ️ 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".

The same model, so it composes with the adapter on one line.
"""
conv1 = model.conv1
model.conv1 = Conv2d(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the original stem's device and dtype

When small_image_stem is applied to a ResNet that has already been moved to CUDA or converted to a non-default dtype, this newly constructed convolution remains a CPU float32 module while the rest of the model retains its prior device/dtype. The next forward pass then fails with a device or scalar-type mismatch. Construct the replacement on conv1.weight.device and with conv1.weight.dtype (and ideally preserve its parameter freezing state).

Useful? React with 👍 / 👎.

@gabrielfruet gabrielfruet changed the title Add the backbone protocols and a torchvision ResNet adapter (prototype) Add the backbone protocols and a torchvision ResNet adapter 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