{"record":{"id":"34abc01604e6f208","repo":"huggingface/pytorch-image-models","slug":"this-version-of-pytorch-does-not-have-f-scaled-dot","errorCode":null,"errorMessage":"This version of pytorch does not have F.scaled_dot_product_attention, fused_attn flag ignored.","messagePattern":"This version of pytorch does not have F\\.scaled_dot_product_attention, fused_attn flag ignored\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"timm/layers/config.py","lineNumber":149,"sourceCode":"        global _NO_JIT\n        global _NO_ACTIVATION_JIT\n        _SCRIPTABLE, _EXPORTABLE, _NO_JIT, _NO_ACTIVATION_JIT = self.prev\n        return False\n\n\ndef use_fused_attn(experimental: bool = False) -> bool:\n    # NOTE: ONNX export cannot handle F.scaled_dot_product_attention as of pytorch 2.0\n    if not _HAS_FUSED_ATTN or _EXPORTABLE:\n        return False\n    if experimental:\n        return _USE_FUSED_ATTN > 1\n    return _USE_FUSED_ATTN > 0\n\n\ndef set_fused_attn(enable: bool = True, experimental: bool = False):\n    global _USE_FUSED_ATTN\n    if not _HAS_FUSED_ATTN:\n        warnings.warn('This version of pytorch does not have F.scaled_dot_product_attention, fused_attn flag ignored.')\n        return\n    if experimental and enable:\n        _USE_FUSED_ATTN = 2\n    elif enable:\n        _USE_FUSED_ATTN = 1\n    else:\n        _USE_FUSED_ATTN = 0\n\n\ndef use_reentrant_ckpt() -> bool:\n    return _USE_REENTRANT_CKPT\n\n\ndef set_reentrant_ckpt(enable: bool = True):\n    global _USE_REENTRANT_CKPT\n    _USE_REENTRANT_CKPT = enable\n","sourceCodeStart":131,"sourceCodeEnd":166,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/layers/config.py#L131-L166","documentation":"timm.layers.config.set_fused_attn enables fused scaled-dot-product attention globally, but if the installed PyTorch lacks torch.nn.functional.scaled_dot_product_attention (pre-2.0), it warns that the flag is ignored and leaves the setting unchanged — timm falls back to its manual attention implementation.","triggerScenarios":"Calling set_fused_attn(True) (or a model factory doing so) under torch < 2.0; environments where an old torch is pinned by another dependency.","commonSituations":"CUDA-driver or conda constraints forcing torch 1.13 or older; CI images with legacy torch. Functionality is unaffected (slower attention); the warning explains why fused attention never activates.","solutions":["Upgrade to torch >= 2.0 to actually get fused attention","If stuck on old torch, remove the set_fused_attn call to silence the warning","Verify with timm.layers.config.is_fused_attn() what state you're in"],"exampleFix":"# before\nimport torch; print(torch.__version__)  # 1.13\nfrom timm.layers.config import set_fused_attn\nset_fused_attn(True)  # warning\n# after\npip install -U 'torch>=2.0'\nset_fused_attn(True)","handlingStrategy":"fallback","validationCode":"import torch\\nHAS_SDPA = hasattr(torch.nn.functional, 'scaled_dot_product_attention')\\nif HAS_SDPA:\\n    set_fused_attn(True)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin torch>=2.0 in project requirements when using timm fused attention","Check timm.layers.config.is_fused_attn() after enabling"],"tags":["attention","pytorch-version","feature-detection","timm"],"backgroundTag":"incompatible-library-version","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}