(prototype) Add the backbone protocols and a torchvision ResNet adapter - #2034
(prototype) Add the backbone protocols and a torchvision ResNet adapter#2034gabrielfruet 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: 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( |
There was a problem hiding this comment.
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 👍 / 👎.
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.
Backbonedeclaresfeature_dimandembed(images) -> (B, feature_dim).DenseBackboneaddsfeature_map, which returns(B, N, D)plus the grid, and is the granularity a dense loss and a segmentation probe read.embedis deliberately not spelledforward_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.TorchvisionResNetBackboneis the first adapter, and the user names it rather than a factory picking it.small_image_stemis the 3x3 stride-1 stem the CIFAR benchmark used throughResNetGenerator.mypy checks that a member exists with the right signature. It cannot check that a member does what the contract says, since
raise NotImplementedErroris a body.tests/backbones/test_conformance.pyis the second check, parameterised over a registry every adapter joins.Testing:
pytest tests/backbones, 14 cases.