{"record":{"id":"941465fb9839f16a","repo":"Stability-AI/generative-models","slug":"no-sdp-backend-available-likely-because-you-are-r","errorCode":null,"errorMessage":"No SDP backend available, likely because you are running in pytorch versions < 2.0. In fact, you are using PyTorch {torch.__version__}. You might want to consider upgrading.","messagePattern":"No SDP backend available, likely because you are running in pytorch versions < 2\\.0\\. In fact, you are using PyTorch (.+?)\\. You might want to consider upgrading\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"sgm/modules/attention.py","lineNumber":43,"sourceCode":"        SDPBackend.FLASH_ATTENTION: {\n            \"enable_math\": False,\n            \"enable_flash\": True,\n            \"enable_mem_efficient\": False,\n        },\n        SDPBackend.EFFICIENT_ATTENTION: {\n            \"enable_math\": False,\n            \"enable_flash\": False,\n            \"enable_mem_efficient\": True,\n        },\n        None: {\"enable_math\": True, \"enable_flash\": True, \"enable_mem_efficient\": True},\n    }\nelse:\n    from contextlib import nullcontext\n\n    SDP_IS_AVAILABLE = False\n    sdp_kernel = nullcontext\n    BACKEND_MAP = {}\n    logpy.warn(\n        f\"No SDP backend available, likely because you are running in pytorch \"\n        f\"versions < 2.0. In fact, you are using PyTorch {torch.__version__}. \"\n        f\"You might want to consider upgrading.\"\n    )\n\ntry:\n    import xformers\n    import xformers.ops\n\n    XFORMERS_IS_AVAILABLE = True\nexcept:\n    XFORMERS_IS_AVAILABLE = False\n    logpy.warn(\"no module 'xformers'. Processing without...\")\n\n# from .diffusionmodules.util import mixed_checkpoint as checkpoint\n\n\ndef exists(val):","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/modules/attention.py#L25-L61","documentation":"attention.py imports torch.nn.functional.sdp_kernel / scaled_dot_product_attention guarded by a version check. If torch.nn does not expose SDP (PyTorch < 2.0), it logs this warning, sets SDP_IS_AVAILABLE=False, and substitutes a nullcontext — meaning attention runs through slower fallback paths.","triggerScenarios":"Importing sgm.modules.attention with PyTorch < 2.0 installed (or a build without SDP support); the message is emitted at import time and includes the detected torch.__version__.","commonSituations":"Old environments pinned to torch 1.13 or earlier; CPU-only or custom torch builds lacking SDP kernels; forgetting to upgrade torch after cloning newer generative-models code.","solutions":["Upgrade PyTorch to >= 2.0: pip install --upgrade torch","If you must stay on 1.x, accept the warning and ensure xformers is installed so attention still runs efficiently","Pin your environment (requirements.txt) to torch>=2.0 for this codebase"],"exampleFix":"// before\ntorch 1.13.1\n// after\npip install \"torch>=2.0.0\"","handlingStrategy":"validation","validationCode":"import torch\nassert tuple(map(int, torch.__version__.split(\"+\")[0].split(\".\")[:2])) >= (2, 0), \\\n    f\"need torch>=2.0, got {torch.__version__}\"","typeGuard":"def sdp_available() -> bool:\n    return hasattr(torch.nn.functional, \"scaled_dot_product_attention\")","tryCatchPattern":"try:\n    import sgm.modules.attention  # may warn at import\nexcept Exception:\n    pass\nif not sdp_available():\n    print(\"install torch>=2.0 for SDP attention\")","preventionTips":["Pin torch>=2.0 in requirements","Log torch.__version__ at startup","Smoke-test imports in CI on the target torch build"],"tags":["python","pytorch","performance","version-compatibility"],"backgroundTag":"pytorch-version-too-old","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}