huggingface/transformers · error · ValueError

Config has `out_features` set to {out_features_from_config}

Error message

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.

What it means

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.

Source

Thrown at src/transformers/backbone_utils.py:237

    def _init_timm_backbone(self, backbone) -> None:
        """
        Initialize the backbone model from timm. The backbone must already be loaded to backbone
        """

        out_features_from_config = getattr(self.config, "out_features", None)
        stage_names_from_config = getattr(self.config, "stage_names", None)

        # These will disagree with the defaults for the transformers models e.g. for resnet50
        # the transformer model has out_features = ['stem', 'stage1', 'stage2', 'stage3', 'stage4']
        # the timm model has out_features = ['act', 'layer1', 'layer2', 'layer3', 'layer4']
        self.stage_names = [stage["module"] for stage in backbone.feature_info.info]
        self.num_features = [stage["num_chs"] for stage in backbone.feature_info.info]

        out_indices = list(backbone.feature_info.out_indices)
        out_features = backbone.feature_info.module_name()

        if out_features_from_config is not None and out_features_from_config != out_features:
            raise ValueError(
                f"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."
            )

        if stage_names_from_config is not None and stage_names_from_config != self.stage_names:
            raise ValueError(
                f"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."
            )

        # We set, align and verify out indices, out features and stage names
        self.config.stage_names = self.stage_names
        self.config.set_output_features_output_indices(out_features, out_indices)

    def _init_transformers_backbone(self) -> None:
        self.stage_names = self.config.stage_names
        self.config.verify_out_features_out_indices()
        # Number of channels for each stage. This is set in the transformer backbone model init

View on GitHub (pinned to a597f97485)

Solutions

  1. Set config.out_features = None (and out_indices = None) before loading so defaults from feature_info are used
  2. Or align names: use the timm vocabulary ('act','layer1',...) when using the timm backend
  3. Re-check the checkpoint's saved out_features/out_indices match the backbone the config declares

Example fix

# before
config.out_features = ['stem', 'stage1', 'stage2', 'stage3', 'stage4']
model = TimmBackbone(config, backbone='resnet50')

# after
config.out_features = None
config.out_indices = None
model = TimmBackbone(config, backbone='resnet50')  # picks timm feature_info defaults
Defensive patterns

Strategy: validation

Validate before calling

from transformers.utils.import_utils import is_timm_available
if use_timm_backend:
    if config.out_features not in (None, ['act', 'layer1', 'layer2', 'layer3', 'layer4']):
        config.out_features = None  # let feature_info decide
        config.out_indices = None

Try / catch

try:
    backbone = TimmBackbone(config, backbone=name)
except ValueError as e:
    if "out_features" in str(e):
        config.out_features, config.out_indices = None, None
        backbone = TimmBackbone(config, backbone=name)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/89fa367b95a2b8d3. Report an issue: GitHub.