Skip to content

Remove xFormers built for another torch after Linux repair - #11783

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
tweekli:fix/evict-xformers-mismatch-after-repair
Oct 1, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
tweekli:fix/evict-xformers-mismatch-after-repair

Conversation

@tweekli

@tweekli tweekli commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #11639

Motivation

The mismatched xFormers eviction currently runs only in the Windows-on-ARM wheelhouse path. A Linux torch repair can also change the installed torch release, leaving behind an xFormers build that cannot load its C++/CUDA extensions.

Changes

  • Scope the existing xFormers mismatch check.
  • Run the same eviction after a Linux torch repair.
  • Report the repair scope in the warning so the reason is clear.

Tests

pytest tests/studio/install/test_cuda_repair.py::TestEvictXformersMismatch

Focused tests pass locally.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the Linux repair in studio/install_python_stack.py re-selects torchao when torch changes but never checked for a stale xFormers, which matches the mismatch in #11639. Will get this reviewed.

…uirement check after the Linux repair

The build check now runs whether or not this run moved torch, so an xFormers left
mismatched by an earlier run is removed too, and a blocked uninstall is warned about
instead of reported as removed.
…nged

PyPI's xFormers 0.0.35 is built for 2.10.0+cu128 and loads its extension under
2.11.0+cu130 (stable ABI since 0.0.34), so an exact build-string compare removed a
working xFormers from every CUDA install. Compare cuda / rocm / xpu / cpu instead.
xFormers' _C.so links libcudart.so.<major>; a cu130 torch ships only the CUDA 13
runtime, so a cu128 build cannot load there unless a system CUDA 12 runtime happens
to be on the loader path.
@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #11783, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#262.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror fd6567f73 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/install_python_stack.py (on the mirror)

@@ -7349,19 +7349,43 @@ def _install_wheelhouse_optionals() -> None:
         _note(f"windows on arm: installed {name}=={version} from the wheelhouse")
 
 
-def _evict_xformers_built_for_another_torch() -> bool:
+def _torch_build_family(label: str) -> str:
+    """cuda / rocm / xpu / cpu from a torch.__version__ local tag, "" when it names none."""
+    tag = label.partition("+")[2].strip().lower()
+    for prefix, family in (("cu", "cuda"), ("rocm", "rocm"), ("xpu", "xpu"), ("cpu", "cpu")):
+        if tag.startswith(prefix):
+            return family

P1 Badge Distinguish CUDA majors before retaining xFormers

When the Linux repair moves torch from CUDA 12 to CUDA 13 (for example, +cu128 to +cu130), this maps both builds to cuda, so family_only retains an xFormers extension linked against the old CUDA runtime. The repository maintains separate cu12/cu13 xFormers wheels for this reason, and the subsequent requirement check cannot catch the mismatch because it explicitly ignores local tags in studio/backend/utils/wheel_utils.py:318-320; the result is an update that leaves xFormers' compiled operations unavailable. Preserve the stable PyTorch-ABI relaxation only when the CUDA runtime major is also compatible.

Useful? React with 👍 / 👎.

Accepted on the mirror

Reply from danielhanchen:

Fixed in 2b62f90: the Linux check now treats a CUDA major change as a different family. Verified with the ld.so cache inhibited: the cu128 _C.so needs libcudart.so.12, which a cu130 torch does not ship, so memory_efficient_attention had no operator.

Round 2: reviewed mirror 22a1d6c86 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 22a1d6c862

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 22a1d6c86 (no equivalent commit found on this PR).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen merged commit 0dd7dfc into unslothai:main Oct 1, 2026
76 of 77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] AMD: the Linux installer puts a CUDA build of xFormers on ROCm hosts

4 participants