huggingface/pytorch-image-models · error · RuntimeError

features_only not implemented for Vision Transformer models.

Error message

features_only not implemented for Vision Transformer models.

What it means

CoaT factory functions explicitly reject features_only=True because CoaT's hierarchical attention design does not expose standard feature maps through timm's feature extraction wrapper. The check happens in _create_coat before build_model_with_cfg is invoked.

Source

Thrown at timm/models/coat.py:746

def checkpoint_filter_fn(state_dict, model):
    out_dict = {}
    state_dict = state_dict.get('model', state_dict)
    for k, v in state_dict.items():
        # original model had unused norm layers, removing them requires filtering pretrained checkpoints
        if k.startswith('norm1') or \
                (k.startswith('norm2') and getattr(model, 'norm2', None) is None) or \
                (k.startswith('norm3') and getattr(model, 'norm3', None) is None) or \
                (k.startswith('norm4') and getattr(model, 'norm4', None) is None) or \
                (k.startswith('aggregate') and getattr(model, 'aggregate', None) is None) or \
                (k.startswith('head') and getattr(model, 'head', None) is None):
            continue
        out_dict[k] = v
    return out_dict


def _create_coat(variant, pretrained=False, default_cfg=None, **kwargs):
    if kwargs.get('features_only', None):
        raise RuntimeError('features_only not implemented for Vision Transformer models.')

    model = build_model_with_cfg(
        CoaT,
        variant,
        pretrained,
        pretrained_filter_fn=checkpoint_filter_fn,
        **kwargs,
    )
    return model


def _cfg_coat(url='', **kwargs):
    return {
        'url': url,
        'num_classes': 1000, 'input_size': (3, 224, 224), 'pool_size': None,
        'crop_pct': .9, 'interpolation': 'bicubic', 'fixed_input_size': True,
        'mean': IMAGENET_DEFAULT_MEAN, 'std': IMAGENET_DEFAULT_STD,
        'first_conv': 'patch_embed1.proj', 'classifier': 'head',

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Use features_only=False and take the hierarchical feature maps directly from CoaT.forward_features stages if you need multi-scale features
  2. Switch to a backbone that supports features_only (check timm.list_features() or the model's feature_cfgs)
  3. Write a small wrapper that hooks CoaT's stage outputs via forward_intermediates or module hooks

Example fix

# before
model = timm.create_model('coat_lite_mini', pretrained=True, features_only=True)
# after
model = timm.create_model('coat_lite_mini', pretrained=True)
feats = model.forward_features(x)  # use stage tokens directly
Defensive patterns

Strategy: validation

Validate before calling

import timm
name = 'coat_lite_mini'
probe = timm.create_model(name)
supports_fo = hasattr(probe, 'feature_info')
del probe
if supports_fo:
    model = timm.create_model(name, features_only=True)
else:
    model = timm.create_model(name)

Type guard

def supports_features_only(name: str) -> bool:
    import timm
    m = timm.create_model(name)
    ok = hasattr(m, 'feature_info')
    del m
    return ok

Try / catch

try:
    model = timm.create_model(name, features_only=True)
except RuntimeError:
    model = timm.create_model(name)  # use forward_intermediates instead

Prevention

When it happens

Trigger: Calling timm.create_model('coat_tiny', features_only=True) or any coat_/coat_lite_ variant with features_only=True.

Common situations: Swapping a CNN backbone out of a feature-pyramid (FPN/Detectron/U-Net) pipeline and passing the same features_only=True flag used for ResNet/EfficientNet; writing generic backbone code that assumes all timm models support feature extraction.

Related errors


AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27). Data as JSON: /api/errors/b288cf25c541649c. Report an issue: GitHub.