{"record":{"id":"7c05aa2ccce2f694","repo":"huggingface/transformers","slug":"backbone-type-self-backbone-type-not-supported","errorCode":null,"errorMessage":"backbone_type {self.backbone_type} not supported.","messagePattern":"backbone_type (.+?) not supported\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/backbone_utils.py","lineNumber":205,"sourceCode":"\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"\n        Method to initialize the backbone. This method is called by the constructor of the base class after the\n        pretrained model weights have been loaded.\n        \"\"\"\n        super().__init__(*args, **kwargs)\n        timm_backbone = kwargs.pop(\"timm_backbone\", None)\n        if timm_backbone is not None:\n            self.backbone_type = BackboneType.TIMM\n        else:\n            self.backbone_type = BackboneType.TRANSFORMERS\n\n        if self.backbone_type == BackboneType.TIMM:\n            self._init_timm_backbone(backbone=timm_backbone)\n        elif self.backbone_type == BackboneType.TRANSFORMERS:\n            self._init_transformers_backbone()\n        else:\n            raise ValueError(f\"backbone_type {self.backbone_type} not supported.\")\n\n    def post_init(self):\n        \"\"\"\n        Override `post_init` to always install capturing hooks, as backbone will ALWAYS capture outputs. We need to do\n        it in `post_init`, as modules need to be already instantiated.\n        It avoids some mixups with `torch.compile`, as the first hook installation will need/create a graph break,\n        which can clash with external user call such as `model = torch.compile(model...)`.\n        \"\"\"\n        # NOTE: Since this class is ALWAYS used as a Mixin with another PreTrainedModel class, this `super` call\n        # will call the PreTrained's `post_init`\n        super().post_init()\n        maybe_install_capturing_hooks(self)\n\n    def _init_timm_backbone(self, backbone) -> None:\n        \"\"\"\n        Initialize the backbone model from timm. The backbone must already be loaded to backbone\n        \"\"\"\n","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/backbone_utils.py#L187-L223","documentation":"Defensive ValueError in BackboneMixin.__init__: after determining backbone_type from the presence of the timm_backbone kwarg (TIMM if present, TRANSFORMERS otherwise), an else-branch raises if backbone_type is neither enum value. With the current code path this is effectively unreachable — the if/else above always assigns one of the two enum members. Hitting it means backbone_type was set to an unexpected value externally (e.g. manually assigned or a stale pickle) or the mixin was used outside its intended flow.","triggerScenarios":"Manually setting backbone_type on a BackboneMixin subclass to a non-BackboneType value before super().__init__() logic runs; monkeypatching; loading a state dict/class whose __init__ was overridden so the assignment above is skipped but a bogus attribute is present.","commonSituations":"Custom model classes inheriting BackboneMixin with a custom __init__ that forgets to call the mixin init properly; deepcopy/pickling edge cases; almost never seen in normal usage.","solutions":["Do not assign backbone_type yourself; let the mixin derive it from the timm_backbone kwarg","Ensure your subclass __init__ calls super().__init__(*args, **kwargs) unchanged","If you need a timm backbone, pass use_timm_backend=True / timm_backbone kwarg instead of forcing the enum"],"exampleFix":"# before\nself.backbone_type = 'timm'  # string, not enum\n\n# after\n# let the mixin decide: pass the timm_backbone kwarg\nmodel = MyBackbone(config, timm_backbone='resnet50')","handlingStrategy":"validation","validationCode":"from transformers.modeling_backbones import BackboneType\nassert backbone_type in (BackboneType.TIMM, BackboneType.TRANSFORMERS) or backbone_type is None","typeGuard":"from transformers.modeling_backbones import BackboneType\n\ndef is_backbone_type(v) -> bool:\n    return v is None or v in (BackboneType.TIMM, BackboneType.TRANSFORMERS)","tryCatchPattern":null,"preventionTips":["Never assign backbone_type manually; pass the timm_backbone kwarg instead","Keep your subclass __init__ delegating to super().__init__(*args, **kwargs)","Prefer composition (use an existing backbone class) over extending BackboneMixin directly"],"tags":["backbone","internal","defensive","config"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}