Repository navigation
Say when xformers is installed but cannot load, and how to fix it - #13410
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50c15a12ec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "Unsloth: xformers is installed but cannot load with torch " | ||
| f"{torch_version}{f' (it was built for {_built_for.group(1)})' if _built_for else ''}, " | ||
| "so PyTorch attention is used instead.\n" | ||
| "To install a matching xformers, run `unsloth install-kernels xformers`, " | ||
| "or `pip uninstall xformers` to hide this. UNSLOTH_ENABLE_LOGGING=1 shows the full error." |
There was a problem hiding this comment.
Preserve the Blackwell-specific repair instructions
On SM 10/11/12 GPUs with xformers <= 0.0.32.post2 (for example, an RTX 50-series GPU with torch 2.8), this handler receives the deliberate compatibility exception raised above rather than a loader failure. The generic recommendation is ineffective: studio/backend/utils/wheel_utils.py maps torch 2.8 back to xformers 0.0.32.post2, and install_kernel returns “already installed and loads” because _register_extensions() succeeds, leaving xformers disabled. Preserve the original “upgrade to >= 0.0.33 or build from source” guidance for this exception, and use this message only for actual extension-load failures.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ab5f698: Unsloth's own version guards (Blackwell FA3 dispatch, old torch) now print their own fix; the install-kernels hint is only for extension load failures. Covered by test_version_guard_keeps_its_own_fix.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab5f698e62
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "Unsloth: xformers is installed but cannot load with torch " | ||
| f"{torch_version}{f' (it was built for {_built_for.group(1)})' if _built_for else ''}, " | ||
| "so PyTorch attention is used instead.\n" | ||
| "To install a matching xformers, run `unsloth install-kernels xformers`, " |
There was a problem hiding this comment.
Avoid recommending an installer with no matching wheel
On CUDA platforms without a published prebuilt wheel, such as Linux aarch64/Jetson, this advertised fix cannot install xformers. The CLI help explicitly says install-kernels is prebuilt-only and skips kernels when no wheel matches; studio/backend/utils/wheel_utils.py:303-307 only maps linux_x86_64 and win_amd64, while studio/backend/utils/kernel_install.py:349-351 returns without installing when resolution fails. Users on these supported CUDA systems therefore remain on the fallback after following the message; gate this recommendation by platform/wheel availability or provide source-build guidance.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: on a platform with no prebuilt wheel, install-kernels prints that none matches this torch and stays on the fallback, and the same message offers pip uninstall xformers. The common broken case (PyPI wheel beside a cu130 torch on win_amd64 / linux_x86_64) is covered.
|
|
||
|
|
||
| def test_broken_xformers_is_reported(): | ||
| out = _run(_BREAK_XFORMERS + _IMPORT_UNSLOTH) |
There was a problem hiding this comment.
Make the generic tests bypass the Blackwell version guard
On an SM 10/11/12 host with xformers <= 0.0.32.post2, this subprocess reaches the existing compatibility guard before the injected _register_extensions failure, so it prints the FA3-dispatch message instead and the generic-message assertions fail. test_working_xformers_prints_nothing fails similarly because the same guard deliberately sets u.xformers to None. Force a non-Blackwell capability or otherwise neutralize the version guard in the two generic tests, leaving only test_version_guard_keeps_its_own_fix to exercise that path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 2d83951: the generic tests pin xformers.version past the Blackwell guard, so only test_version_guard_keeps_its_own_fix exercises it.
| out = _run(_BREAK_XFORMERS + _IMPORT_UNSLOTH) | ||
| assert "XFORMERS_IS_NONE True" in out | ||
| assert "xformers is installed but cannot load with torch" in out | ||
| assert "(it was built for " in out |
There was a problem hiding this comment.
Allow xformers installations without build metadata
On a CUDA host with a pure-Python or no-extension xformers installation, xformers._cpp_lib._build_metadata is None; the injected xFormersInvalidLibException then reports only that xformers was built for a different PyTorch/Python version and contains no PyTorch ... with CUDA ... text for the production regex to extract. The module-level marker still enables this test, so this unconditional assertion fails even though the diagnostic correctly omits the unavailable build version. Either require non-None build metadata in the skip condition or make the parsed-version assertion conditional.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 2d83951: the built-for assertion now follows whether xformers has build metadata.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
pre-commit.ci run |
Summary
When xformers is installed but its CUDA extension cannot load, Unsloth falls back to PyTorch attention without saying why. xformers' own warning is silenced right before the import, and Unsloth's explanation only prints under
UNSLOTH_ENABLE_LOGGING, so all the user gets isFA [Xformers = None. FA2 = False]in the banner.That is what #4381 reports: torch 2.10.0+cu130 on Windows next to xformers 0.0.35 from PyPI. PyPI's xformers wheels are cu128 builds (
cpp_lib.json:torch 2.10.0+cu128, cuda 1208) and their_Clinks the CUDA 12 runtime (libcudart.so.12/cudart64_12.dll). A cu130 torch only ships the CUDA 13 runtime, sotorch.ops.load_libraryfails.Now, on CUDA and outside
UNSLOTH_ENABLE_LOGGING, Unsloth prints one message that names the torch the wheel was built for and the fix:unsloth install-kernels xformers(shipped in 2026.10.3) already replaces a non-loading xformers with the wheel from the matching CUDA index. For the reporter's setup (win_amd64, torch 2.10.0+cu130) it pickshttps://download.pytorch.org/whl/cu130/xformers-0.0.34-cp39-abi3-win_amd64.whl(HTTP 200).Nothing changes when xformers loads, when it is not installed, under
UNSLOTH_ENABLE_LOGGING, or on ROCm / XPU / CPU.Fixes #4381
Verification
To reproduce the reporter's loader failure on Linux, I copied the PyPI xformers 0.0.35 package and repointed its
_C.sodependency fromlibcudart.so.12to a missing name (patchelf --replace-needed). That is what a cu130-only machine sees. Then I loadedhf-internal-testing/tiny-random-LlamaForCausalLMwithFastLanguageModel:Xformers = NoneXformers = NoneXformers = 0.0.35, no messagelibcudart.so.13and loads with torch 2.13.0+cu130. Itscpp_lib.jsonsaystorch 2.10.0+cu130, cuda 1300.tests/utils/test_xformers_broken_message.py: it raises xformers' ownxFormersInvalidLibExceptionfrom_register_extensionsin a subprocess, so the parsed text comes from the installed package. It also checks that a working xformers prints nothing. 2 passed on this branch. On main,test_broken_xformers_is_reportedfails and the quiet-path test passes.