{"record":{"id":"95ee9a4c19c11dfb","repo":"huggingface/transformers","slug":"config-has-stage-names-set-to-stage-names-from","errorCode":null,"errorMessage":"Config has `stage_names` set to {stage_names_from_config} which doesn't match `stage_names` from backbone's feature_info. Please check if your checkpoint has correct `stage_names` saved.","messagePattern":"Config has `stage_names` set to (.+?) which doesn't match `stage_names` from backbone's feature_info\\. Please check if your checkpoint has correct `stage_names` saved\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/backbone_utils.py","lineNumber":243,"sourceCode":"        stage_names_from_config = getattr(self.config, \"stage_names\", None)\n\n        # These will disagree with the defaults for the transformers models e.g. for resnet50\n        # the transformer model has out_features = ['stem', 'stage1', 'stage2', 'stage3', 'stage4']\n        # the timm model has out_features = ['act', 'layer1', 'layer2', 'layer3', 'layer4']\n        self.stage_names = [stage[\"module\"] for stage in backbone.feature_info.info]\n        self.num_features = [stage[\"num_chs\"] for stage in backbone.feature_info.info]\n\n        out_indices = list(backbone.feature_info.out_indices)\n        out_features = backbone.feature_info.module_name()\n\n        if out_features_from_config is not None and out_features_from_config != out_features:\n            raise ValueError(\n                f\"Config has `out_features` set to {out_features_from_config} which doesn't match `out_features` \"\n                \"from backbone's feature_info. Please check if your checkpoint has correct out features/indices saved.\"\n            )\n\n        if stage_names_from_config is not None and stage_names_from_config != self.stage_names:\n            raise ValueError(\n                f\"Config has `stage_names` set to {stage_names_from_config} which doesn't match `stage_names` \"\n                \"from backbone's feature_info. Please check if your checkpoint has correct `stage_names` saved.\"\n            )\n\n        # We set, align and verify out indices, out features and stage names\n        self.config.stage_names = self.stage_names\n        self.config.set_output_features_output_indices(out_features, out_indices)\n\n    def _init_transformers_backbone(self) -> None:\n        self.stage_names = self.config.stage_names\n        self.config.verify_out_features_out_indices()\n        # Number of channels for each stage. This is set in the transformer backbone model init\n        self.num_features = None\n\n    @property\n    def out_features(self):\n        return self.config._out_features\n","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/backbone_utils.py#L225-L261","documentation":"Raised in _init_timm_backbone when config.stage_names (if set) does not equal [stage['module'] for stage in backbone.feature_info.info] — the stage names reported by the instantiated timm backbone. Like the out_features check, this catches configs authored for (or mutated against) a different backbone implementation or a different timm model than the one being constructed. After the checks pass, the config's stage_names is overwritten with the timm-derived names.","triggerScenarios":"Loading a timm-backed model whose config carries transformers-style stage_names; passing a backbone='resnet50' with a config built for a different architecture (e.g. saved from resnet152 with more stages); hand-editing stage_names.","commonSituations":"Cross-implementation migration (transformers-native <-> timm backend); checkpoint reuse across model variants of the same family; configs serialized before stage_names were auto-managed.","solutions":["Clear the stale value: config.stage_names = None before constructing the timm backbone","Ensure the config actually corresponds to the backbone= argument you pass to the timm model","Regenerate the config from AutoConfig.for_model(...) / the intended checkpoint"],"exampleFix":"# before\nconfig.stage_names = ['stem', 'stage1', 'stage2', 'stage3', 'stage4']\nmodel = TimmBackbone(config, backbone='resnet50')\n\n# after\nconfig.stage_names = None  # let feature_info define stage names\nmodel = TimmBackbone(config, backbone='resnet50')","handlingStrategy":"validation","validationCode":"if use_timm_backend and getattr(config, 'stage_names', None) is not None:\n    timm_names = [s['module'] for s in timm.create_model(name, pretrained=False).feature_info.info]\n    if config.stage_names != timm_names:\n        config.stage_names = None  # defer to feature_info","typeGuard":null,"tryCatchPattern":"try:\n    backbone = TimmBackbone(config, backbone=name)\nexcept ValueError as e:\n    if 'stage_names' in str(e):\n        config.stage_names = None\n        backbone = TimmBackbone(config, backbone=name)\n    else:\n        raise","preventionTips":["Clear stage_names when reusing a config across backbones or model variants","Load configs with AutoConfig.from_pretrained(checkpoint) matched to the same checkpoint's backbone","Treat stage_names as derived state owned by the backbone, not user input"],"tags":["backbone","timm","config","checkpoint-mismatch"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}