{"record":{"id":"751c90e95f0694d7","repo":"huggingface/pytorch-image-models","slug":"features-only-not-implemented-for-vision-transform-751c90","errorCode":null,"errorMessage":"features_only not implemented for Vision Transformer models.","messagePattern":"features_only not implemented for Vision Transformer models\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"timm/models/convit.py","lineNumber":416,"sourceCode":"            x = blk(x)\n        x = self.norm(x)\n        return x\n\n    def forward_head(self, x, pre_logits: bool = False):\n        if self.global_pool:\n            x = x[:, 1:].mean(dim=1) if self.global_pool == 'avg' else x[:, 0]\n        x = self.head_drop(x)\n        return x if pre_logits else self.head(x)\n\n    def forward(self, x):\n        x = self.forward_features(x)\n        x = self.forward_head(x)\n        return x\n\n\ndef _create_convit(variant, pretrained=False, **kwargs):\n    if kwargs.get('features_only', None):\n        raise RuntimeError('features_only not implemented for Vision Transformer models.')\n\n    return build_model_with_cfg(ConVit, variant, pretrained, **kwargs)\n\n\ndef _cfg(url='', **kwargs):\n    return {\n        'url': url,\n        'num_classes': 1000, 'input_size': (3, 224, 224), 'pool_size': None,\n        'mean': IMAGENET_DEFAULT_MEAN, 'std': IMAGENET_DEFAULT_STD, 'fixed_input_size': True,\n        'first_conv': 'patch_embed.proj', 'classifier': 'head', 'license': 'apache-2.0',\n        **kwargs\n    }\n\n\ndefault_cfgs = generate_default_cfgs({\n    # ConViT\n    'convit_tiny.fb_in1k': _cfg(hf_hub_id='timm/'),\n    'convit_small.fb_in1k': _cfg(hf_hub_id='timm/'),","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/models/convit.py#L398-L434","documentation":"ConViT factory functions reject features_only=True because the model is a plain Vision Transformer (single feature resolution, non-CNN layout) and is not wired into timm's feature-extraction wrapper. The check is in _create_convit before the model is built.","triggerScenarios":"Calling timm.create_model('convit_tiny'|'convit_small'|'convit_base', features_only=True).","commonSituations":"Generic backbone-registry code that passes features_only=True to every model; migrating a detection/segmentation pipeline from a CNN to ConViT without adjusting the feature-extraction strategy.","solutions":["Create the model without features_only and use forward_intermediates(x, indices=...) to pull intermediate block outputs","Pick a ViT variant that supports feature extraction (many timm ViTs expose feature_cfgs, e.g. 'vit_small_patch16_224' with features_only=True)","Wrap the model and manually take the output of self.blocks[i] via hooks"],"exampleFix":"# before\nmodel = timm.create_model('convit_small', pretrained=True, features_only=True)\n# after\nmodel = timm.create_model('convit_small', pretrained=True)\nfeats = model.forward_intermediates(x, indices=[3, 7, 11], output_fmt='NCHW')","handlingStrategy":"validation","validationCode":"import timm\nm = timm.create_model('convit_small')\nif not hasattr(m, 'feature_info'):\n    raise SystemExit('convit does not support features_only; use forward_intermediates')","typeGuard":"def supports_features_only(name: str) -> bool:\n    import timm\n    m = timm.create_model(name)\n    ok = hasattr(m, 'feature_info')\n    del m\n    return ok","tryCatchPattern":"try:\n    model = timm.create_model('convit_tiny', features_only=True)\nexcept RuntimeError:\n    model = timm.create_model('convit_tiny')\n    feats = lambda x: model.forward_intermediates(x, indices=[3, 7, 11])","preventionTips":["Gate features_only by a model compatibility check before building","Use forward_intermediates in generic pipelines","Document which backbones are feature-extraction capable in your config"],"tags":["timm","convit","features-only","unsupported-operation"],"backgroundTag":"unsupported-features-only-request","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}