{"record":{"id":"0846a06ba8c8f061","repo":"Stability-AI/generative-models","slug":"no-module-xformers-processing-without","errorCode":null,"errorMessage":"no module 'xformers'. Processing without...","messagePattern":"no module 'xformers'\\. Processing without\\.\\.\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"sgm/modules/attention.py","lineNumber":56,"sourceCode":"    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):\n    return val is not None\n\n\ndef uniq(arr):\n    return {el: True for el in arr}.keys()\n\n\ndef default(val, d):\n    if exists(val):\n        return val\n    return d() if isfunction(d) else d\n\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/modules/attention.py#L38-L74","documentation":"The module tries `import xformers` at load time; on ImportError it sets XFORMERS_IS_AVAILABLE=False and logs this warning. It is informational — the library still works — but xformers-accelerated attention modes will be unavailable and non-'softmax' attention modes will silently fall back to 'softmax'.","triggerScenarios":"Importing sgm.modules.attention in an environment without the xformers package installed, or with an xformers build incompatible with the installed torch (import fails inside the try).","commonSituations":"Fresh conda/venv setups; torch upgraded without reinstalling matching xformers wheels; using a non-softmax attn_mode in config and unknowingly getting native attention instead.","solutions":["Install xformers: pip install xformers (matching your torch/CUDA version from the xformers release matrix)","If xformers is not needed, ignore the warning — the code falls back to PyTorch SDP native attention","Verify import works: python -c \"import xformers.ops\""],"exampleFix":"// before\nModuleNotFoundError: No module named 'xformers'\n// after\npip install xformers  # version matching your torch build","handlingStrategy":"fallback","validationCode":"try:\n    import xformers.ops\n    xformers_ok = True\nexcept ImportError:\n    xformers_ok = False","typeGuard":"def xformers_available() -> bool:\n    try:\n        import xformers.ops\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    import xformers\n    XFORMERS_OK = True\nexcept ImportError:\n    XFORMERS_OK = False\n    logger.warning(\"xformers missing; attention will use SDP fallback\")","preventionTips":["Install xformers wheels matching your torch/CUDA combo","Check XFORMERS_IS_AVAILABLE before requesting xformers attn_mode","Reinstall xformers after every torch upgrade"],"tags":["python","xformers","optional-dependency","performance"],"backgroundTag":"missing-optional-dependency","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}