{"record":{"id":"99cfba35c45548ad","repo":"Stability-AI/generative-models","slug":"we-do-not-support-vanilla-attention-anymore-as-it","errorCode":null,"errorMessage":"We do not support vanilla attention anymore, as it is too expensive. Sorry.","messagePattern":"We do not support vanilla attention anymore, as it is too expensive\\. Sorry\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sgm/modules/attention.py","lineNumber":486,"sourceCode":"        context_dim=None,\n        gated_ff=True,\n        checkpoint=True,\n        disable_self_attn=False,\n        attn_mode=\"softmax\",\n        sdp_backend=None,\n    ):\n        super().__init__()\n        assert attn_mode in self.ATTENTION_MODES\n        if attn_mode != \"softmax\" and not XFORMERS_IS_AVAILABLE:\n            logpy.warn(\n                f\"Attention mode '{attn_mode}' is not available. Falling \"\n                f\"back to native attention. This is not a problem in \"\n                f\"Pytorch >= 2.0. FYI, you are running with PyTorch \"\n                f\"version {torch.__version__}.\"\n            )\n            attn_mode = \"softmax\"\n        elif attn_mode == \"softmax\" and not SDP_IS_AVAILABLE:\n            logpy.warn(\n                \"We do not support vanilla attention anymore, as it is too \"\n                \"expensive. Sorry.\"\n            )\n            if not XFORMERS_IS_AVAILABLE:\n                assert (\n                    False\n                ), \"Please install xformers via e.g. 'pip install xformers==0.0.16'\"\n            else:\n                logpy.info(\"Falling back to xformers efficient attention.\")\n                attn_mode = \"softmax-xformers\"\n        attn_cls = self.ATTENTION_MODES[attn_mode]\n        if version.parse(torch.__version__) >= version.parse(\"2.0.0\"):\n            assert sdp_backend is None or isinstance(sdp_backend, SDPBackend)\n        else:\n            assert sdp_backend is None\n        self.disable_self_attn = disable_self_attn\n        self.attn1 = attn_cls(\n            query_dim=dim,","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/modules/attention.py#L468-L504","documentation":"When attn_mode is 'softmax' but PyTorch SDP (SDP_IS_AVAILABLE False, torch < 2.0) is unavailable, the code warns that vanilla (naive) attention is no longer supported because it is too expensive, and then asserts False — terminating with AssertionError if xformers is also missing (the assert's message directs to installing xformers).","triggerScenarios":"Running with PyTorch < 2.0 (no SDP) AND xformers not installed, while instantiating attention with the default attn_mode='softmax'.","commonSituations":"Legacy torch 1.x environments without xformers attempting to run the SD model; stripped-down deployments lacking both backends; CPU-only images where xformers is hard to install.","solutions":["Upgrade PyTorch to >= 2.0 so SDP attention is available","Install xformers so the assert's fallback (memory-efficient attention) succeeds: pip install xformers","If neither is possible, patch attention.py to allow a naive-attention implementation (not recommended — very slow/high memory)"],"exampleFix":"// before\npip list  # torch 1.13.0, no xformers -> AssertionError in attention.py\n// after\npip install \"torch>=2.0\" xformers","handlingStrategy":"validation","validationCode":"import torch\nsdp = hasattr(torch.nn.functional, \"scaled_dot_product_attention\")\ntry:\n    import xformers.ops\n    xf = True\nexcept ImportError:\n    xf = False\nassert sdp or xf, \"need torch>=2.0 SDP or xformers before building the model\"","typeGuard":"def any_attention_backend() -> bool:\n    import torch\n    if hasattr(torch.nn.functional, \"scaled_dot_product_attention\"):\n        return True\n    try:\n        import xformers.ops\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    model = instantiate_from_config(config)\nexcept AssertionError:\n    raise RuntimeError(\"No attention backend: install torch>=2.0 or xformers\")","preventionTips":["Check torch and xformers versions in an env preflight script","Never run torch 1.x without xformers in this codebase","Add a startup assertion for attention backend availability"],"tags":["python","pytorch","xformers","attention","assertionerror"],"backgroundTag":"no-attention-backend-available","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}