{"record":{"id":"89fa367b95a2b8d3","repo":"huggingface/transformers","slug":"config-has-out-features-set-to-out-features-fro","errorCode":null,"errorMessage":"Config has `out_features` set to {out_features_from_config} which doesn't match `out_features` from backbone's feature_info. Please check if your checkpoint has correct out features/indices saved.","messagePattern":"Config has `out_features` set to (.+?) which doesn't match `out_features` from backbone's feature_info\\. Please check if your checkpoint has correct out features/indices saved\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/backbone_utils.py","lineNumber":237,"sourceCode":"    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\n        out_features_from_config = getattr(self.config, \"out_features\", None)\n        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","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/backbone_utils.py#L219-L255","documentation":"Raised in BackboneMixin._init_timm_backbone when the config's saved out_features disagrees with the out_features derived from the timm backbone's feature_info. Transformers backbones and timm backbones use different stage naming (e.g. transformers resnet50: ['stem','stage1'..'stage4'] vs timm: ['act','layer1'..'layer4']), so a config saved with one vocabulary and a timm backbone expecting the other fails this check. It protects against silently loading a checkpoint whose feature taps point at the wrong stages.","triggerScenarios":"Loading a timm-backed model (use_timm_backend=True / TimmBackbone) with a config whose out_features was authored for the transformers implementation (or vice versa); checkpoints saved with an older naming scheme; manually editing config.out_features to timm-style names while feature_info disagrees.","commonSituations":"Switching a pipeline from the native transformers backbone to use_timm_backend=True on a config inherited from the transformers version; fine-tuned checkpoints re-saved after partial edits; typos in stage names.","solutions":["Set config.out_features = None (and out_indices = None) before loading so defaults from feature_info are used","Or align names: use the timm vocabulary ('act','layer1',...) when using the timm backend","Re-check the checkpoint's saved out_features/out_indices match the backbone the config declares"],"exampleFix":"# before\nconfig.out_features = ['stem', 'stage1', 'stage2', 'stage3', 'stage4']\nmodel = TimmBackbone(config, backbone='resnet50')\n\n# after\nconfig.out_features = None\nconfig.out_indices = None\nmodel = TimmBackbone(config, backbone='resnet50')  # picks timm feature_info defaults","handlingStrategy":"validation","validationCode":"from transformers.utils.import_utils import is_timm_available\nif use_timm_backend:\n    if config.out_features not in (None, ['act', 'layer1', 'layer2', 'layer3', 'layer4']):\n        config.out_features = None  # let feature_info decide\n        config.out_indices = None","typeGuard":null,"tryCatchPattern":"try:\n    backbone = TimmBackbone(config, backbone=name)\nexcept ValueError as e:\n    if \"out_features\" in str(e):\n        config.out_features, config.out_indices = None, None\n        backbone = TimmBackbone(config, backbone=name)\n    else:\n        raise","preventionTips":["Null out out_features/out_indices when switching a config to the timm backend","Remember the two name vocabularies: stem/stage1.. (transformers) vs act/layer1.. (timm)","After building a timm backbone, read back config.out_features to learn the authoritative names"],"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"}