Auto-dispatching wrapper that loads the backbone of any family.
"Backbone" means the family base class with no task head attached
(e.g. ResNet, not ResNetForImageClassification). Use this
when you want raw feature outputs or intend to attach a custom head
on top.
Notes
Each registered model carries a _task tag; this class filters on
_task == "base". A given name can resolve to different classes
under different AutoModelFor* shells — for example,
AutoModel resolves to the bare backbone (ResNet) whereas
AutoModelForImageClassification.from_pretrained("resnet_50_cls")
returns ResNetForImageClassification. The two are separate
registry entries, and only the classifier has published weights.
Examples
A classifier's backbone is not published on its own — the weights
were trained with the head and are kept with it — so asking for one
is refused, and the refusal names the factory that has them rather
than handing back a model that is "pretrained" and random.
>>> from lucid.models import AutoModel
>>> AutoModel.from_pretrained("resnet_50")
Traceback (most recent call last):
...
NotImplementedError: No pretrained weights are published for resnet_50; resnet_50(pretrained=True) cannot be honoured. Use resnet_50_cls for the checkpointed variant.
Families whose backbone *is* checkpointed load through the same call;
gpt is one. For an architecture without weights, build it
directly instead:
>>> import lucid
>>> from lucid.models import create_model
>>> backbone = create_model("resnet_50").eval()
>>> type(backbone).__name__
'ResNet'
>>> backbone(lucid.randn(1, 3, 224, 224)).last_hidden_state.shape
(1, 2048, 7, 7)