Skip to content

models: load_resnet accepts a Hugging Face repo id (microsoft/resnet-50) - #256

Merged
sbryngelson merged 1 commit into
mainfrom
feat/hf-resnet-loader
Aug 31, 2026
Merged

models: load_resnet accepts a Hugging Face repo id (microsoft/resnet-50)#256
sbryngelson merged 1 commit into
mainfrom
feat/hf-resnet-loader

Conversation

@sbryngelson

Copy link
Copy Markdown
Owner

What

load_resnet was 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, blocks encoder.stages.{s}.layers.{l}.layer.{0,1,2}, shortcut, head classifier.1). _hf_resnet_to_tv is a pure rename into torchvision keys (conv1/bn1, layerX.i.conv{1,2,3}/bn{1,2,3}, downsample.0/1, fc), after which Vision._build runs unchanged -- BN fold, V1.5 stride-on-3x3, and residual-projection detection all as-is.

Verification

microsoft/resnet-50 matches HF logits at cosine 1.0000 (argmax match) on a preprocessed image.

Tests (tests/test_hf_resnet.py):

  • off-device: the remap produces the exact torchvision key names for bottleneck and basic blocks, and omits projections on non-first blocks
  • on-device (requires_ane): resnet-50 vs HF logit cosine + argmax

torchvision depth path unchanged: test_resnet_depths.py 16 passed.

…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).
@sbryngelson
sbryngelson merged commit a65fd05 into main Aug 31, 2026
19 checks passed
@sbryngelson
sbryngelson deleted the feat/hf-resnet-loader branch August 31, 2026 00:55
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