models: load_resnet accepts a Hugging Face repo id (microsoft/resnet-50) - #256
Merged
Conversation
…snet-50) load_resnet was torchvision-only (a depth). HF's ResNet is architecturally identical -- only the weight names differ -- so a repo id (detected by '/') now loads via transformers and its state_dict is remapped to torchvision names (_hf_resnet_to_tv), after which Vision._build runs unchanged. microsoft/resnet-50 matches HF logits at cosine 1.0000 (argmax match). Tests: off-device pure-remap key checks (bottleneck + basic) and an on-device resnet-50-vs-HF logit match. torchvision depths unchanged (16 tests pass).
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.
What
load_resnetwas torchvision-only (a depth: 50, "resnet50"). It now also accepts a Hugging Face ResNet repo id (detected by a "/"), e.g.af.load_resnet(\"microsoft/resnet-50\").How
HF's ResNet is architecturally identical to torchvision's -- only the weight names differ (stem
embedder.embedder, blocksencoder.stages.{s}.layers.{l}.layer.{0,1,2},shortcut, headclassifier.1)._hf_resnet_to_tvis a pure rename into torchvision keys (conv1/bn1, layerX.i.conv{1,2,3}/bn{1,2,3}, downsample.0/1, fc), after whichVision._buildruns unchanged -- BN fold, V1.5 stride-on-3x3, and residual-projection detection all as-is.Verification
microsoft/resnet-50matches HF logits at cosine 1.0000 (argmax match) on a preprocessed image.Tests (
tests/test_hf_resnet.py):requires_ane): resnet-50 vs HF logit cosine + argmaxtorchvision depth path unchanged:
test_resnet_depths.py16 passed.