xFormers warns that its compiled kernels do not match your PyTorch
Your error
WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions. xFormers was built for:3 more lines it can showFix it fast
Most common cause, 1 of 3PyTorch was upgraded under an xformers release from before 0.0.34
Move xformers to 0.0.36.
pip install -U xformers mslk --index-url https://download.pytorch.org/whl/cu132Short answer
WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions means the installed xformers wheel was compiled for a different PyTorch or Python than the one running. Releases up to 0.0.33 were tied to one exact torch build. Install xformers 0.0.36, which is pure Python and works with any PyTorch 2.10 or newer, from your torch's CUDA index.
Which cause do you have?
Print the two versions side by side, then let xFormers report on itself. A torch of 2.10 or newer with an xformers older than 0.0.34 points to cause 1. A torch of 2.9 or older points to cause 2. A clean report from xformers 0.0.36 that only complains about mslk points to cause 3.
pip show torch xformers mslk | grep -E "^(Name|Version)"
python -m xformers.infoThen find the line you see in this list and open its fix:
- 1PyTorch was upgraded under an xformers release from before 0.0.34
The warning prints a 'built for' PyTorch version that differs from the '(you have ...)' version beside it - 2The project pins PyTorch 2.9 or older, below what new xformers needs
pip show torch reports 2.9.1 or older, and the project's requirements file holds that pin - 3On xformers 0.0.36, mslk is missing or was built for another torch
No WARNING[XFORMERS] line appears; importing xformers.ops warns that mslk could not be imported or that its native library could not be loaded
What does the error look like?
WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions. xFormers was built for:xFormers was built for a different version of PyTorch or Python.Please reinstall xformers (see https://github.com/facebookresearch/xformers#installing-xformers)Set XFORMERS_MORE_DETAILS=1 for more details
Cause 1 of 3
PyTorch was upgraded under an xformers release from before 0.0.34
You seeThe warning prints a 'built for' PyTorch version that differs from the '(you have ...)' version beside it
Check
xFormers can't load its C++/CUDA extensions here because the wheel's kernels were compiled against another torch release. The changelog pins each binary release to one PyTorch build: 0.0.32 to 2.8.0, 0.0.33 to 2.9.0, 0.0.33.post2 to 2.9.1. A UI or script that upgrades torch on its own leaves those kernels unloadable.
python -c "import torch; print(torch.__version__, torch.version.cuda)"Fix
Move xformers to 0.0.36. From that release it is a single pure-Python wheel with nothing compiled, so no torch upgrade can break it again. It needs PyTorch 2.10 or newer, and its attention kernels come from the mslk package, so install both from the PyTorch index that matches your torch build (cu132 here; swap in the cu tag of your own torch build).
pip install -U xformers mslk --index-url https://download.pytorch.org/whl/cu132Verify
The info report runs without any WARNING[XFORMERS] line, and pip show lists xformers 0.0.36.
python -m xformers.infoConfirmed by raw.githubusercontent.com
Cause 2 of 3
The project pins PyTorch 2.9 or older, below what new xformers needs
You seepip show torch reports 2.9.1 or older, and the project's requirements file holds that pin
Check
Since 0.0.34, xformers builds target the PyTorch 2.10 stable ABI, so they need torch 2.10 or later. A project frozen on an older torch has to use the older xformers binary that was compiled for exactly that torch, and its changelog entry names it.
grep -rniE "^(torch|xformers)" requirements*.txtFix
Install the xformers release built for your torch, from the same CUDA index the torch wheel came from. For torch 2.9.1 on CUDA 12.8 that is 0.0.33.post2. Keep the pair pinned together so the next install cannot split them.
pip install xformers==0.0.33.post2 --index-url https://download.pytorch.org/whl/cu128
# requirements.txt
torch==2.9.1
xformers==0.0.33.post2Verify
The built-for line disappears, and the info report shows its kernels as built and available.
python -m xformers.infoConfirmed by raw.githubusercontent.com
Cause 3 of 3
On xformers 0.0.36, mslk is missing or was built for another torch
You seeNo WARNING[XFORMERS] line appears; importing xformers.ops warns that mslk could not be imported or that its native library could not be loaded
Check
In 0.0.36 the attention implementation moved into the mslk package, and each mslk release targets one PyTorch version. On CUDA, a mismatched mslk drops to a python-only mode with a warning and the default backends still run. On ROCm, some backends such as CK stop being available.
pip show mslk torch | grep -E "^(Name|Version)"Fix
Reinstall mslk from the PyTorch index that matches your torch build, and pick the torch and mslk pair from the same row of the MSLK compatibility table when you need its native kernels.
pip install -U mslk --index-url https://download.pytorch.org/whl/cu132Verify
Importing xformers.ops prints no mslk warning.
python -c "import xformers.ops; print('ok')"Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Install torch, xformers and mslk in one pip command with one --index-url, so all three come from the same CUDA build.
- When a project must stay below PyTorch 2.10, pin torch and xformers on adjacent lines and change them only as a pair.
- Run python -m xformers.info in your container's start-up check so a broken pair fails at boot rather than mid-generation.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.