{"record":{"id":"0c6585d01c6e61f2","repo":"Stability-AI/generative-models","slug":"attention-mode-attn-mode-is-not-available-fal","errorCode":null,"errorMessage":"Attention mode '{attn_mode}' is not available. Falling back to native attention. This is not a problem in Pytorch >= 2.0. FYI, you are running with PyTorch version {torch.__version__}.","messagePattern":"Attention mode '(.+?)' is not available\\. Falling back to native attention\\. This is not a problem in Pytorch >= 2\\.0\\. FYI, you are running with PyTorch version (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sgm/modules/attention.py","lineNumber":478,"sourceCode":"    }\n\n    def __init__(\n        self,\n        dim,\n        n_heads,\n        d_head,\n        dropout=0.0,\n        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\"","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/modules/attention.py#L460-L496","documentation":"CrossAttention/MemoryEfficientAttention __init__ asserts attn_mode is a known mode, then warns and coerces the mode to 'softmax' if a non-default mode (e.g. 'xformers') was requested while xformers is not installed. The model still constructs, just with slower native attention.","triggerScenarios":"Config `attn_mode: 'xformers'` (or 'torch-sdp'/'vanilla' variants requiring backends) in a CrossAttention with XFORMERS_IS_AVAILABLE False — i.e. xformers import failed at module load.","commonSituations":"Reusing SD configs that specify xformers attention on machines without xformers; CI/CPU environments where xformers wheels are unavailable.","solutions":["Install xformers so the requested attention mode actually becomes available","Change attn_mode to 'softmax' explicitly in the config to silence the fallback warning","Verify XFORMERS_IS_AVAILABLE is True after importing sgm.modules.attention before relying on xformers speedups"],"exampleFix":"// before\nparams:\n  attn_mode: \"xformers\"   # xformers not installed -> silent fallback\n// after\npip install xformers\n# or\nparams:\n  attn_mode: \"softmax\"","handlingStrategy":"validation","validationCode":"import sgm.modules.attention as A\nif cfg_attn_mode != \"softmax\" and not A.XFORMERS_IS_AVAILABLE:\n    print(f\"{cfg_attn_mode} unavailable, will fall back to softmax\")","typeGuard":"def attn_mode_usable(mode: str) -> bool:\n    import sgm.modules.attention as A\n    return mode == \"softmax\" or A.XFORMERS_IS_AVAILABLE","tryCatchPattern":"try:\n    attn = CrossAttention(..., attn_mode=cfg_attn_mode)\nfinally:\n    if attn.attn_mode != cfg_attn_mode:\n        logger.warning(\"attention mode fell back to %s\", attn.attn_mode)","preventionTips":["Only set xformers attn_mode after verifying xformers imports","Default configs to attn_mode 'softmax' on torch>=2.0","Check the constructed module's final attn_mode in tests"],"tags":["python","xformers","attention","fallback","config"],"backgroundTag":"attention-mode-unavailable-fallback","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}