Skip to content

Install a CUDA-matched xFormers on Windows instead of whatever PyPI serves - #8156

Merged
danielhanchen merged 17 commits into
mainfrom
nv/p0-xformers-pkg
Aug 9, 2026
Merged

danielhanchen merged 17 commits into
mainfrom
nv/p0-xformers-pkg

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

Summary

On Windows the managed xFormers wheel does not match the runtime it ships beside, so its CUDA extensions never load and memory-efficient attention is silently gone.

Reading the actual artifacts rather than inferring, PyPI publishes exactly one win_amd64
xFormers flavour, and its cpp_lib.json reads:

cu128 wheel: {"cuda": 1208, "torch": "2.10.0+cu128", "python": "3.10.11"}
cu130 wheel: {"cuda": 1300, "torch": "2.10.0+cu130"}

The installer selects torch from the cu130 index, so the cu128 wheel lands next to a cu130 torch.
torch.ops.load_library then raises, and xformers/_cpp_lib.py downgrades that to a logger
warning, so the package imports, reports a version, and has no memory-efficient attention, SwiGLU
or sparse ops. unslothai/unsloth#4381 is an open report of exactly this.

The Python half of the report is a red herring: these are cp39-abi3 wheels, so the
interpreter they were built on does not matter. The CUDA mismatch is the whole bug.

Correction to the original framing of this PR

I first wrote that the published unsloth wheel pulls xFormers in as an unbounded core dependency,
so a plain managed install lands the mismatched wheel. That is true of the published 2026.8.8
wheel but not of this tree, where the heavy dependencies have moved into extras. install.ps1
installs plain unsloth (the $PackageName regex forbids [), so the windows extra is never
selected and nothing in the managed install path installs xFormers at all.

The reachable path is narrower: studio/backend/core/inference/diffusion_attention.py hands pip
the bare package name with --no-deps, which by construction stops pip reading
Requires-Dist: torch==2.10.0, so it resolves the single PyPI wheel and "succeeds" while the
extension never loads. That fires only on an explicit backend request, since auto never selects
xFormers. So the install.ps1 half of this change is as much a new capability as a repair, and
should be judged on that basis.

What changed

  • pyproject.toml: bound the windows extra's xFormers spec. The CUDA-matched Windows route is the existing cuXXX-torchYYY extras, which have carried win_amd64 rows since cu124-torch240; the bound keeps the plain extra self-consistent rather than pretending it can work off PyPI alone.
  • install.ps1: after the torch flavour repair, select the xFormers version for the resident torch release and CUDA family and install it from the same index torch came from. No match means nothing is installed. UNSLOTH_SKIP_XFORMERS=1 opts out.
  • studio/backend/utils/wheel_utils.py: linux_wheel_platform_tag becomes wheel_platform_tag and emits win_amd64. Windows is opt-in via include_windows on probe_torch_wheel_env, so flash-attn, causal-conv1d and mamba-ssm behaviour is byte-identical.
  • studio/backend/core/inference/diffusion_attention.py: the on-demand install resolved xformers with no version pin, no index and --no-deps, which by construction prevents pip from ever reading the wheel's Requires-Dist: torch==X. It now resolves a matched URL or refuses, returning the reason.

Verification

All 40 URLs the matrix can produce return HTTP 200 (cu126, cu128, cu129, cu130 crossed with 0.0.31.post1 through 0.0.34, both win_amd64 and manylinux_2_28_x86_64). I read cpp_lib.json out of eight of them and confirmed each reports exactly its own release and family. That enumerate-and-HEAD sweep is now a test: a 404 fails, a network outage skips.

  • studio/backend/tests -k "wheel or attention": 171 passed, 1 skipped
  • studio/backend/tests -k "wheel or attention or diffusion": 1482 passed, 1 skipped
  • tests/python/: 933 passed, 79 skipped
  • install.ps1 parses clean via Parser::ParseFile; the selector helpers run under pwsh, Pester 17/17

Three pre-existing failures excluded, each confirmed by resetting to the base commit: test_e2e_no_torch_sandbox (HTTP 401), test_studio_runtime_gate (reads an untouched file), and the test_tokenizers_and_torch_constraint negative control.

Notes and risks

  • This adds roughly a 100 MB download to Windows installs. Against the currently released wheel it replaces an already-downloaded broken PyPI xFormers, so it is not a net addition today.
  • Self-review found four dead URLs (xFormers 0.0.30 has no cp313 wheel) and three real defects: the index leaf was keyed off $TorchIndexUrl, which the flavour repair does not always reconcile, so a migrated venv could hold +cu128 torch while the leaf said /cpu, where only xFormers 0.0.22.post4 is served; the resident-build check compared only the build tag, so a resident 0.0.35 was mis-reported as matching; and the torch 2.7.0 row lacked an interpreter guard.
  • Not fixed here, flagged as the same class of bug: the cu118onlytorch280 to cu126 URL shift at pyproject.toml:390-401 and its siblings look like a pre-existing off-by-one, serving a neighbouring CUDA family's wheel.
  • Runtime repair of an already-installed mismatched xFormers is deliberately not here. Detection and reporting is a separate change.

Reported in an external QA pass as the single fix-before-launch item.

Daniel Han and others added 7 commits August 8, 2026 08:48
The `windows` extra resolved `xformers>=0.0.22.post7` from PyPI with no upper
bound and no index. PyPI publishes exactly one win_amd64 flavour of xFormers,
built against CUDA 12.8 (0.0.34's cpp_lib.json reads `torch 2.10.0+cu128`), so
next to the cu130 torch install.ps1 pulls from download.pytorch.org the
xformers/_C.pyd fails torch.ops.load_library and _cpp_lib.py turns that into a
warning: memory-efficient attention, SwiGLU and the sparse ops all disappear
while the import still reports success.

Unbounded, the same spec now resolves to 0.0.35, which is published as a
py39-none wheel with no compiled extension at all (2.6 MB vs 103 MB) and whose
torch>=2.10 floor lets pip drag a pinned torch forward.

Bound the fallback and document the route that IS CUDA-matched on Windows: the
cuXXX-torchYYY extras, every one of which has carried win_amd64 rows since
cu124-torch240. Verified live on download.pytorch.org (HTTP 200) for
cu126/cu128/cu130 x xformers 0.0.33.post1 / 0.0.33.post2 / 0.0.34, and read
cpp_lib.json back out of the cu128 and cu130 0.0.34 wheels to confirm they
really are built for 2.10.0+cu128 and 2.10.0+cu130 respectively.
install.ps1 never mentioned xFormers. It installed torch from a cu126 / cu128 /
cu130 index and then plain `unsloth`, leaving xFormers to whatever pip resolved
later -- and PyPI publishes exactly one win_amd64 flavour, built against CUDA
12.8. On a cu130 host that is the NVIDIA QA report verbatim: "xFormers was built
for PyTorch 2.10.0+cu128 with CUDA 1208 (you have 2.10.0+cu130)", after which
xformers/_cpp_lib.py logs a warning and drops memory-efficient attention, SwiGLU
and the sparse ops while the import still succeeds.

Select the wheel from the CUDA family the resident torch actually carries and
install it from the same index the torch install used, so
UNSLOTH_TORCH_INDEX_URL / UNSLOTH_TORCH_INDEX_FAMILY / UNSLOTH_PYTORCH_MIRROR
keep working unchanged. Additive and best-effort: no wheel for this (torch,
CUDA) pair means install nothing rather than a mismatch, a failed install warns
and the run continues on torch SDPA, and UNSLOTH_SKIP_XFORMERS=1 opts out.

Three details that are easy to get wrong:
  - The step runs after the torch flavor repair, which can itself reinstall
    torch from a different index.
  - xFormers publishes one wheel per exact torch PATCH (2.9.0 -> 0.0.33.post1,
    2.9.1 -> 0.0.33.post2, 2.10.0 -> 0.0.34), so the table is keyed on the full
    release, not the minor.
  - cu126, cu128 and cu130 all publish the SAME xformers version string, so a
    wrong-CUDA wheel is invisible to a version check. The repair reads the
    resident xformers/cpp_lib.json (the same metadata xFormers quotes in its own
    error) and force-replaces the package when it disagrees.

Every row in the table was HEAD-verified live on download.pytorch.org and its
cpp_lib.json read back. install.ps1 parses clean under
[System.Management.Automation.Language.Parser]::ParseFile, and the new selector
tests execute the extracted helpers under pwsh.
linux_wheel_platform_tag() returned None for Windows, so nothing in the backend
could resolve a Windows wheel URL at all. Rename it to wheel_platform_tag() and
emit win_amd64, since download.pytorch.org does publish CUDA-matched win_amd64
xFormers wheels.

Both call sites were inside this module, but probe_torch_wheel_env() is a real
behaviour risk: its three production callers all resolve flash-attn /
causal-conv1d / mamba-ssm assets, and those upstreams publish no win_amd64
wheels, so returning an env on Windows would only build 404s. Windows is
therefore opt-in there via include_windows, leaving every existing caller
byte-identical.

Add the resolver: torch release + torch.version.cuda -> the exact
download.pytorch.org wheel. The probe payload grows torch_version and
cuda_version because neither existing key can pick the right wheel -- xFormers
publishes one wheel per torch PATCH (2.9.0 -> 0.0.33.post1, 2.9.1 ->
0.0.33.post2) and per CUDA MINOR (cu126 and cu128 are different builds carrying
the same version string). Unlisted pairs resolve to None so callers install
nothing; serving a neighbouring CUDA family is the bug, not the fallback.
The on-demand backend installer ran `pip install --only-binary :all: --no-deps
xformers`, with no version and no index. Three things then line up badly:

  - PyPI publishes exactly one win_amd64 xFormers flavour, built against CUDA
    12.8, so a cu130 host installs a mismatched extension every time.
  - --no-deps deliberately stops pip from ever reading the wheel's
    `Requires-Dist: torch==X`, so nothing checks the pairing.
  - the failure is SILENT. torch.ops.load_library raises, xformers/_cpp_lib.py
    catches it and logs a warning, and the import still succeeds -- so find_spec
    reports the backend as present while memory-efficient attention, SwiGLU and
    the sparse ops are all gone. The old comment ("An ABI mismatch just fails to
    import") described the flash-attn case, not this one.

Unbounded also means 0.0.35 today, which ships no compiled extension at all.

Resolve the exact download.pytorch.org wheel for the running torch build and
install that URL, or refuse. Refusing is the point: no matched wheel means no
install, the caller stays on torch SDPA, and the reason comes back from
_ensure_attention_backend_installed (previously -> None) so it is reportable
rather than only logged. Like the kernels/hub gate this is a policy refusal, so
it records nothing in _INSTALL_ATTEMPTED.

This changes Linux too, and deliberately: the same PyPI cu128 build lands beside
a cu130 Linux torch. Torch versions with no published wheel (2.11, 2.12) now
refuse instead of installing 0.0.35, which diffusers would accept at set time
and then fail inside the denoise loop.

Verified end to end against the real torch in this checkout (2.9.1+cu128 ->
cu128/xformers-0.0.33.post2-cp39-abi3-manylinux_2_28_x86_64.whl, live HEAD).
Self-review caught this: enumerating every URL the matrix can produce and
HEAD-checking all 44 found 4 dead ones. xFormers only switched to a single
cp39-abi3 wheel at 0.0.31; the 0.0.30 row (torch 2.7.0) publishes one wheel per
interpreter and stops at cp312, so a 3.13 host built a URL that does not exist.

Gate the pre-abi3 branch on the interpreter range those wheels actually cover.
diffusion_attention already url_exists-gated before installing, so this was not
user visible, but xformers_wheel_url is a public helper and should not hand a
caller a dead link.

Add the enumerate-and-HEAD check as a test so no future row can be added
without a live wheel behind it: a 404 fails (that row is wrong), a network
outage skips, matching tests/version_compat/_fetch.py.
Two things I had written down were wrong. I inferred both from wheel sizes
instead of opening the wheels; a reviewer opened them.

  - xFormers 0.0.35 DOES ship a compiled extension. cu130's py39-none wheel
    carries a 19.4 MB xformers/_C.pyd and a cpp_lib.json reading
    {"cuda":1300,"torch":"2.10.0+cu130"}; cu128's carries an 8.4 MB one. The
    103 MB -> 2.6 MB drop is the bundled flash_attn_3/_C.pyd going away, not the
    extension. The real hazard is narrower and still worth the pin: 0.0.35's
    extension is built for torch 2.10.0 while its metadata asks only for
    torch>=2.10, so pip may pair it with a torch it cannot load. 0.0.34 declares
    torch==2.10.0, an exact pair.
  - PyPI's WINDOWS torch has no CUDA at all. torch 2.10.0's win_amd64 wheel
    reports __version__ '2.10.0+cpu' with cuda = None; only the Linux wheel is
    +cu128. So `unsloth[windows]` cannot produce a working CUDA xFormers on any
    PyPI-only install, which strengthens rather than weakens the case for the
    cuXXX-torchYYY route.

Real defects:

  - install.ps1 keyed the index leaf off $TorchIndexUrl, and the comment claimed
    the flavor repair had already reconciled it with the resident torch. It has
    not: the repair is skipped when the expected tag is 'cpu' or unrecognised, so
    a migrated venv can hold a +cu128 torch while the leaf says /cpu -- and
    whl/cpu serves only xformers 0.0.22.post4, with --default-index leaving no
    fallback. Derive the leaf from the resident torch, reusing $TorchIndexUrl
    (and any custom mirror) only when it already points at that family.
  - Get-InstalledXformersBuild compared only the build tag, so a resident 0.0.35
    matching the torch made the step print "xFormers 0.0.34 already matches" and
    skip. Compare version AND build tag.
  - The torch 2.7.0 / xFormers 0.0.30 row predates the abi3 switch: one wheel per
    interpreter, stopping at cp312, while this installer defaults to Python 3.13.
    wheel_utils had a guard for it, install.ps1 did not. Drop the row from both
    rather than carry two per-interpreter gates for a torch that resolves to
    nothing on the default install.

Also from review: resolution no longer HEAD-checks the URL (it can run under
_generate_lock, since the video loader has no out-of-lock pre-install hop), the
probe timeout drops 120s -> 30s to match the other probe_torch_wheel_env
callers, only DETERMINISTIC refusals are memoised so one probe timeout cannot
disable xFormers for a whole session, the memo takes a lock, the wheel filename
tag is a verified range instead of an open-ended floor, and the backend test
suite pins UNSLOTH_DIFFUSION_ATTENTION_INSTALL=0 so no future test can shell out
to a real pip.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59dc73ff6d

ℹ️ 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".

Comment thread install.ps1 Outdated
Comment on lines +4195 to +4198
$_xfIndexUrl = $TorchIndexUrl
if (-not $_xfIndexUrl -or (Get-TorchIndexLeafName $_xfIndexUrl) -ne $_xfCudaTag) {
$_xfBase = if ($env:UNSLOTH_PYTORCH_MIRROR) { $env:UNSLOTH_PYTORCH_MIRROR.TrimEnd('/') } else { "https://download.pytorch.org/whl" }
$_xfIndexUrl = "$_xfBase/$_xfCudaTag"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve explicitly pinned custom indexes for xFormers

When UNSLOTH_TORCH_INDEX_URL is a full custom PEP 503 URL whose final component is not the CUDA family (for example, an authenticated https://mirror.example/simple), this condition discards the authoritative index that successfully supplied the resident CUDA torch and reconstructs a download.pytorch.org URL instead. Air-gapped installations then cannot install the matched xFormers wheel, despite the documented full-URL override; reuse $TorchIndexUrl when $TorchIndexPinned is true rather than requiring its leaf to equal $_xfCudaTag.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and a full-URL override is documented precisely so it can be an authenticated mirror whose leaf is not a CUDA family. Fixed in b6343fe: when $TorchIndexPinned is set the pinned $TorchIndexUrl is reused whole, no leaf comparison at all. The leaf check is gone from the block, which test_installer_installs_xformers_from_the_torch_index now asserts.

Comment thread install.ps1 Outdated
# --reinstall-package: cu126 / cu128 / cu130 all publish the SAME xformers
# version string, so a wrong-CUDA wheel is invisible to a version check and
# would otherwise be left in place on an upgrade of a broken install.
$_xfExit = Invoke-InstallCommandRetry -Label "install xFormers" { uv pip install --python $VenvPython --no-deps --reinstall-package xformers "xformers==$_xfVersion" --default-index $_xfIndexUrl }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Isolate the matched xFormers index from UV_INDEX

When the user or machine config sets UV_INDEX to an index containing the same xFormers version (notably PyPI's CUDA-12.8 build), --default-index does not restrict resolution to $_xfIndexUrl: local uv pip install --help defines --index/UV_INDEX as URLs used “in addition to the default index.” Since cu126, cu128, and cu130 intentionally share the same version string, uv can therefore reinstall the wrong-CUDA artifact and recreate the silent extension failure this step is meant to fix; make the selected index exclusive or install a direct wheel URL.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on the uv semantics. Fixed in b6343fe by installing the direct wheel URL on the unpinned path -- $base/$cudaTag/xformers-$version-$pyTag-win_amd64.whl, with the filename tag resolved by Get-XformersFilenamePythonTag (cp39-abi3 for 0.0.31..0.0.34, py39-none for 0.0.35, mirroring the Python resolver, and asserted equal to it by test_the_direct_wheel_filename_tag_matches_the_python_resolver). A URL cannot be re-resolved from UV_INDEX. An explicitly pinned index still goes through --default-index, since that is the users own authoritative index, and an unknown filename shape falls back to the index rather than guessing a URL that 404s.

Comment thread studio/backend/utils/wheel_utils.py Outdated
Comment on lines +321 to +323
return (
f"{PYTORCH_WHEEL_INDEX_BASE_URL}/{family}"
f"/xformers-{version}-{python_tag}-{platform_leaf}.whl"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor the configured PyTorch mirror for on-demand xFormers

When Studio runs behind an air-gapped or corporate mirror, the new on-demand path always constructs a direct download.pytorch.org URL, bypassing both pip's configured index and the repository's existing UNSLOTH_PYTORCH_MIRROR convention (studio/install_python_stack.py uses it for _PYTORCH_WHL_BASE). A mirror-only deployment that has the matched wheel therefore fails the explicit xFormers request and falls back to native attention; derive this base URL from the configured PyTorch mirror before constructing the family-specific URL.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, and the mirror is the one lever an air-gapped install has. Fixed in b6343fe: wheel_utils gained pytorch_wheel_index_base_url(), read per call so the env var still applies after import, and xformers_wheel_url builds off it. Same convention as install_python_stack._PYTORCH_WHL_BASE. Tests: TestPytorchMirror.

Comment on lines +235 to +236
except urllib.error.HTTPError as exc:
dead.append(f"{exc.code} {url}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip transient HTTP failures in the live wheel test

When download.pytorch.org responds with a transient HTTP status such as 429, 500, or 503 during the 14-request sweep, this handler records every HTTPError as a dead wheel and fails the suite. That contradicts the test's stated contract that only a missing artifact should fail while an upstream/network outage should skip, making otherwise-correct CI runs dependent on the availability and rate limits of an external service; treat only 404 as a dead matrix row and skip or retry transient statuses.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that contradicts the test docstring. Fixed in b6343fe: only a 404 counts as a dead matrix row now; any other HTTP status skips with the code in the message, alongside the existing URLError / timeout skip.

danielhanchen and others added 3 commits August 8, 2026 10:14
…gh $script:UvExe

Deep validation of this branch turned up one merge hazard and four comments
that do not survive checking against the live indexes.

The install call was the only bare `uv` left in install.ps1 once #8161 lands.
That branch rewrites every other invocation to `& $script:UvExe` so a profile
alias named uv cannot capture them, and the two branches merge cleanly with
zero conflict markers -- so git would silently reintroduce the one hole #8161
exists to close. Resolve through the variable when something has set it, and
fall back to the bare name otherwise, so the call is correct on this branch
alone and correct after the merge. Get-Variable rather than a bare read keeps
the lookup safe under a profile's Set-StrictMode.

The comment claiming no cu118 / cu121 / cu124 win_amd64 xFormers wheel exists
is wrong; cu124/xformers-0.0.28.post1-cp312-cp312-win_amd64.whl is live. The
real reason those families are absent is that they all stop before the
cp39-abi3 switch at 0.0.31, so their wheels are one file per interpreter and
the single filename template cannot name them.

"Every cuXXX-torchYYY extra has carried win_amd64 rows since cu124-torch240"
is likewise wrong: the cu118 and cu121 rows carry none and cu130onlytorch280
is empty. And the suggested `pip install "unsloth[cu130-torch2100]"` is not
enough on its own -- the extra pins xFormers by URL but pins no torch, and
PyPI's Windows torch is 2.10.0+cpu with cuda None, so without --index-url it
lands a cu130 extension beside a CPU torch: the same mismatch, inverted.

Linux aarch64 gets a platform tag, so it never reaches the "this platform has
no xFormers wheel" refusal that names it. It lands on the other one, which
reported only torch and CUDA and so read as "upstream never built this pair"
when the truth is "not for this arch". Name the platform there and stop
claiming aarch64 in the branch it cannot reach.

Finally, record why a mismatched xFormers that is ALREADY installed is not
repaired here: find_spec sees it and returns before the matched-wheel block.
Repairing under _generate_lock would mean a 100 MB download blocking unload
and cancel, on a package the user may have pinned deliberately. install.ps1
does that repair outside any request. What this path prevents is Studio
creating the mismatch, which is how it was made.
…5 history

Three more comments that do not survive checking against the published
artifacts. All comment-only; no behaviour changes.

"PyPI publishes only the CUDA-12.8 flavour" is true of 0.0.34 and 0.0.35 but
reads as an invariant, and it is not one: the single PyPI win_amd64 wheel has
been cu124 at 0.0.29.post2, cu126 at 0.0.30, cu128 at 0.0.32, cu130 at 0.0.33
and cu128 again from 0.0.33.post1. That churn is a better argument for
resolving a URL than the fixed-flavour version was. Worth recording too that
cpp_lib.json's `cuda` is the NVCC toolkit version and not torch's family --
the cu126 0.0.34 wheel also reports 1208, so only the `torch` field separates
the flavours, which is the field this resolver already keys on.

0.0.35 did not move its extension behind torch.ops.load_library; 0.0.34 loads
through exactly the same call, and the two _cpp_lib.py files are identical.
What changed is setup.py dropping py_limited_api=True in favour of a custom
bdist_wheel that force-tags py39-none, on the stated grounds that the
extension never bound the CPython ABI at all -- which holds up: its _C.so
defines no PyInit and references no Py* symbol.

Finally, name the two places the table is deliberately stricter or narrower
than the ABI requires, so neither gets "fixed" by interpolation. Keying on the
CUDA minor is stricter than needed -- the cu126 and cu128 extensions have
identical undefined-symbol sets and both link libcudart.so.12, and only a
major bump changes that -- but the minor names a real index directory, so an
exact hit is what guarantees the URL exists. And the table stops at torch
2.10.0 because upstream does: 2.11 through 2.13 are released, 0.0.35 declares
torch>=2.10 yet every published 0.0.35 wheel was compiled against 2.10.0, and
only the unreleased 0.0.35.dev1130 targets 2.11.
@danielhanchen

Copy link
Copy Markdown
Member Author

Two things surfaced while validating this branch that reviewers should see.

Conflict with #6955. That PR adds torch2110 extras pinning xFormers 0.0.35, while this one caps the windows extra at <0.0.35. Both are defensible on their own and they will fight if they land together, so the cap and the pin need reconciling before the second one merges. My cap exists because 0.0.35 declares only torch>=2.10 while shipping a single _C built against 2.10.0, which is the same class of mismatch this PR is fixing. If #6955's pin is deliberate for torch 2.11, the cleaner shape is probably a per-torch-minor bound rather than a flat cap.

Related open issue: #4381. "No xformers and Flash-attention under Windows?" is exactly this failure mode, reported independently on an RTX 3090 with torch 2.10.0+cu130 and xformers 0.0.35 giving Xformers = None. Worth closing out against this PR and #8157 once both land.

@danielhanchen

Copy link
Copy Markdown
Member Author

I surveyed every xFormers release rather than reasoning from the two wheels in front of me, and it changes my own conclusion. The <0.0.35 cap in this PR is probably wrong and I think it should come out.

Every stable release, and what it pins

version date torch pin wheel tag win_amd64
0.0.29 2024-12-27 torch==2.5.1 cp3x-cp3x no
0.0.29.post2/3 2025-02 torch==2.6.0 cp3x-cp3x yes
0.0.30 2025-04-28 torch==2.7.0 cp3x-cp3x yes (no cp313)
0.0.31, .post1 2025-06/07 torch==2.7.1 cp39-abi3 yes
0.0.32.post1/2 2025-08 torch==2.8.0 cp39-abi3 yes
0.0.33, .post1 2025-11 torch==2.9.0 cp39-abi3 yes
0.0.33.post2 2025-12-04 torch==2.9.1 cp39-abi3 yes
0.0.34 2026-01-23 torch==2.10.0 cp39-abi3 yes
0.0.35 2026-02-20 torch>=2.10 py39-none yes

73 releases total; 0.0.35 is the current PyPI latest.

Why I now think the cap is wrong

I capped <0.0.35 on the reasoning that it declares only torch>=2.10 while shipping a single _C built against 2.10.0. The upstream release notes say that is deliberate and supported. From v0.0.34:

Migrated xFormers to the PyTorch stable API/ABI, which means that binary builds targeting PyTorch 2.10+ will be compatible with any later version

So the loosened pin in 0.0.35 is the consequence of a real ABI migration, not an oversight. The cp39-abi3 to py39-none tag change is the other half of the same story, plus v0.0.35's "Supported free-threading Python": the _C is loaded through torch.ops.load_library, not imported as a CPython extension, so it has no CPython ABI dependency to declare.

The cap also has a cost I had not weighed. 0.0.34 pins torch==2.10.0 exactly, so a user on torch 2.10.1 cannot install it at all. 0.0.35 is the release that fixes that, and torch is already at 2.13.0 upstream.

What the real matching axis is

Not the torch version. The CUDA family and the arch list. Every cpp_lib.json I pulled:

PyPI          0.0.34 win -> cuda 1208, torch 2.10.0+cu128, arch "7.5 8.0+PTX 8.0 9.0a"
PyPI          0.0.35 win -> cuda 1208, torch 2.10.0+cu128, arch "7.5 8.0+PTX 8.0 9.0a"
pytorch/cu126 0.0.35 win -> cuda 1208, torch 2.10.0+cu126, arch "7.5 8.0+PTX 8.0 9.0a"
pytorch/cu128 0.0.35 win -> cuda 1208, torch 2.10.0+cu128, arch "7.5 8.0+PTX 8.0 9.0a"
pytorch/cu130 0.0.35 win -> cuda 1300, torch 2.10.0+cu130, arch "7.5 8.0+PTX 8.0 9.0a 10.0a 10.3a 11.0a 12.0a 12.1a"

Two things worth having on the record:

  1. PyPI serves a cu128 build for every version, 0.0.34 and 0.0.35 alike. That is the mismatch this PR's selector fixes, and it is unaffected by which version you allow.
  2. Only the cu130 wheels carry Blackwell SASS. cu126 and cu128 stop at 9.0a, so on an RTX 5090 (sm_120) or B200 (sm_100) they have no native kernels and fall back to PTX JIT from 8.0+PTX. That is a second, independent reason the reporter's 5090 saw no benefit, and it is an arch problem rather than a CUDA-version problem. It also means the cu130 wheel is the only correct choice on Blackwell regardless of driver.

Index coverage, for completeness: cu126/cu128/cu130 all carry 0.0.33.post1 through 0.0.35 with Windows wheels; cu129 stops at 0.0.32.post2; cu118/cu121/cu124 are stale; rocm6.4 reaches 0.0.33.post2 with no Windows; the cpu index only has 0.0.22.post4.

Consequences for this PR and for #6955

  • I intend to drop the <0.0.35 bound unless someone objects, and keep the CUDA-family matching, which is the part that actually addresses the bug.
  • That also dissolves the conflict I raised with Add cu128/cu126/cu130 torch 2.11.0 extras (torch2110) with xformers 0.0.35 #6955. Pinning 0.0.35 there is reasonable, and on the stable-ABI reading it is the better default for torch 2.11.
  • The arch-list point argues for preferring the cu130 wheel on any sm_100+ card even where the driver would allow cu128.

The cap was wrong. I bounded the windows extra at <0.0.35 on the reasoning
that 0.0.35 declares torch>=2.10 while its extension is built for 2.10.0, so
pip could pair it with torch 2.11 and recreate the mismatch this branch
exists to fix. Upstream says that pairing is supported. v0.0.34's notes
record the migration to the PyTorch stable API/ABI, "which means that binary
builds targeting PyTorch 2.10+ will be compatible with any later version",
and 0.0.35's loosened pin plus its py39-none tag are both consequences of
that, not oversights.

The cap also cost more than it bought. 0.0.34 pins torch==2.10.0 exactly, so
anyone on 2.10.1 could install no xFormers at all.

The axis that has to match is the CUDA family, which the extra cannot see and
install.ps1 already handles. Verified from the wheels rather than inferred:
every PyPI wheel, 0.0.34 and 0.0.35 alike, reports cuda 1208 / torch
2.10.0+cu128, while the cu130 wheels report cuda 1300. Only the cu130 build
carries Blackwell SASS -- cu126 and cu128 stop at 9.0a, so on sm_100 or
sm_120 they have no native kernels and fall back to PTX JIT from 8.0+PTX.

Both selector tables gain 2.11.0, 2.12.0 and 2.13.0 rows mapping to 0.0.35,
keyed per release so an unknown torch still resolves to nothing rather than
borrowing a neighbour's wheel. All six 0.0.35 URLs the tables can emit return
200.

Two test docstrings asserted 0.0.35 was extension-less and shipped no
cpp_lib.json. Both are false: the PyPI wheel carries an 8.2 MB _C.pyd and the
cu130 wheel a 19 MB one, and every release from 0.0.31 on ships cpp_lib.json.
The 103 MB to 2.6 MB drop was the bundled flash_attn_3 kernels going away.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf106e41ab

ℹ️ 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".

Comment thread install.ps1 Outdated
# "not in the table", which also covers families we have no row for (cu118,
# cu124) as well as torch releases upstream never built against.
substep "no matching xFormers wheel for torch $_xfTorchVersion -- skipping it (attention falls back to torch SDPA)."
} elseif ((Get-InstalledXformersBuild -PythonExe $VenvPython) -eq "$_xfVersion $_xfTorchVersion") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compare 0.0.35 against its actual build target

When a migrated environment already contains the correct xFormers 0.0.35 wheel alongside torch 2.11–2.13, Get-InstalledXformersBuild reports the wheel's recorded build target (0.0.35 2.10.0+cuXXX), since the new matrix deliberately reuses the stable-ABI torch-2.10 build. This comparison instead expects the resident torch version, so the valid wheel is always considered mismatched and force-reinstalled, potentially producing a misleading failure warning when the index is unavailable; compare against the selected wheel's expected build target rather than $_xfTorchVersion.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and the consequence is worse than a wasted reinstall: on an unreachable index it warns that xFormers failed to install while a perfectly good wheel is already resident. Fixed in b6343fe with Get-XformersExpectedTorchBuild, which returns the floor release for a stable-ABI wheel and the resident torch for an exact-era one; the comparison now uses that. test_the_already_installed_check_uses_the_wheels_own_build_target pins both arms.

"are per-interpreter and unnameable here",
),
("2.10.0+cu124", "12.4", "cu124 stopped at xFormers 0.0.29"),
("2.11.0+cu130", "13.0", "torch 2.11 has no xFormers wheel on any index"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the stale torch 2.11 refusal case

The newly added resolver matrix maps 2.11.0+cu130 to xFormers 0.0.35, so this parameter makes xformers_wheel_url(...) return a URL rather than None and deterministically fails the test in a provisioned test run. The same stale refusal expectation appears in test_diffusion_attention.py::test_deterministic_refusal_is_memoised; update these cases to agree with the new stable-ABI mapping, or remove the 2.11 matrix row.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and it was failing CI already: the Python 3.10-3.13 legs on this PR are red on exactly these two cases and nothing else. Fixed in b6343fe by repointing both at a pair that genuinely has no wheel (2.11.0+cu124, since cu124 stopped at 0.0.29 and the stable-ABI era does not rescue a family that publishes nothing) rather than deleting the coverage.

Comment thread studio/backend/utils/wheel_utils.py Outdated
Comment on lines +339 to +340
release = str(torch_version).split("+", 1)[0].strip()
return _XFORMERS_WHEEL_VERSIONS.get(release, {}).get(cuda_family)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle supported patch releases in the stable-ABI lookup

For a supported resident build such as 2.12.1+cu130, this exact release lookup misses because the stable-ABI matrix contains only 2.11.0, 2.12.0, and 2.13.0, so Studio refuses to install xFormers even though the same file documents 0.0.35 as compatible with every later torch and elsewhere explicitly treats torch 2.12.1 as supported. The PowerShell selector has the same exact-key behavior, and 2.10.1 is similarly excluded despite the new pyproject.toml explanation citing it as a reason to use 0.0.35; cover the supported patch releases or apply a bounded stable-ABI fallback.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and enumerating patches is not even possible: they are published after this code ships. Fixed in b6343fe with a bounded fallback in both selectors -- any release strictly above the stable-ABI floor (2.10.0) resolves to 0.0.35 for the families that publish it, exact rows still win, and below the floor an unlisted pair still resolves to nothing. Covered by TestStableAbiPatchReleases in test_wheel_utils_xformers.py and, for the PowerShell side, test_both_selectors_agree_outside_the_exact_tables, which asserts the two implementations give the same answer on 2.10.1 / 2.11.1 / 2.12.4 / 2.14.0 and on the two refusals.

…he listed ones

- an exact-key matrix refuses every patch release published after it ships,
  so 2.10.1 / 2.11.1 / 2.12.1 got no xFormers at all; above the stable-ABI
  floor the answer is known without a row, in both selectors.
- the direct wheel URL hard-coded download.pytorch.org, the one path in the
  installer stack that ignored UNSLOTH_PYTORCH_MIRROR.
- install.ps1 threw away an explicitly pinned index whose leaf did not happen
  to name the CUDA family, which is exactly what a documented full-URL
  override looks like.
- an unpinned install now goes through the direct wheel URL: --default-index
  does not make an index exclusive, and cu126 / cu128 / cu130 share a version
  string, so UV_INDEX could still supply the wrong-CUDA artifact.
- the already-installed check compared the wheel's recorded build target
  against the resident torch, so a correct 0.0.35 was force-reinstalled on
  every run.
- the live wheel sweep treated any HTTP status as a dead row, failing the
  suite on a 429 from the CDN.
- and the two torch 2.11 refusal cases were stale as of the new matrix.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5dd2b3a2f9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread install.ps1 Outdated
Comment on lines +4266 to +4267
if ($TorchIndexPinned -and $TorchIndexUrl) {
$_xfIndexUrl = $TorchIndexUrl

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use direct xFormers URLs for family pins

When the user sets a one-shot family pin such as UNSLOTH_TORCH_INDEX_FAMILY=cu130, $TorchIndexPinned is true, so this branch falls back to installing xformers==$_xfVersion from --default-index $_xfIndexUrl instead of the direct wheel URL. I checked uv pip install --help: --index/UV_INDEX are used “in addition to the default index”, so a machine-level UV_INDEX containing the same xFormers version can still satisfy the pin with the wrong CUDA-family wheel. Fresh evidence beyond the earlier UV_INDEX issue is that this condition also captures non-opaque family pins, which can safely build the direct $_xfCudaTag URL while reserving the index path for full custom UNSLOTH_TORCH_INDEX_URL mirrors.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and the family pin is exactly the case that can be rebuilt. The index branch is now gated on UNSLOTH_TORCH_INDEX_URL being set (a full-URL override, possibly an authenticated mirror), so UNSLOTH_TORCH_INDEX_FAMILY=cu130 takes the direct $_xfCudaTag wheel URL. test_a_family_pin_still_gets_the_direct_wheel_url pins it. dc36485.

refusal,
)
return refusal
package = wheel_url

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Redact credentialed mirror URLs before logging

When UNSLOTH_PYTORCH_MIRROR contains userinfo or a tokenized URL for a private PyTorch mirror, xformers_wheel_url() returns that full URL and this assignment makes the later info/warning messages log it verbatim as the package name. The PowerShell installer redacts index credentials before printing them, but the Studio on-demand path now exposes the mirror secret in backend logs whenever it installs or fails to install xFormers; keep a sanitized display string separate from the URL passed to pip.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. pip still receives the real URL; the log line now uses a redacted copy, and pip's stderr goes through the same filter since pip echoes the URL back. Rule matches the installer's Remove-IndexUrlCredentials (no userinfo, no query, no fragment). Tests: test_a_private_mirrors_credentials_never_reach_the_log and test_a_query_string_token_is_stripped_too. dc36485.

…als out of the log

UNSLOTH_TORCH_INDEX_FAMILY sets $TorchIndexPinned as well, so a plain cu130 pin took
the --default-index path. uv's --index / UV_INDEX are used "in addition to" the default
index, and cu126 / cu128 / cu130 publish the same xFormers version string, so a
machine-level UV_INDEX could satisfy the pin with a wheel from the wrong CUDA family --
the silent extension failure this step exists to prevent. A family pin names a leaf, so
it can have a direct URL; only a full UNSLOTH_TORCH_INDEX_URL override, which may be an
authenticated mirror nothing here can rebuild, still goes through the index.

And UNSLOTH_PYTORCH_MIRROR is allowed to carry userinfo or a token. The Studio
on-demand path bakes it into the wheel URL and then logged that URL verbatim as the
package name, so the first install (or failed install) wrote the secret into the backend
log. pip still gets the real URL; the log gets a redacted one, and pip's stderr is put
through the same filter because pip echoes back what it was handed. Same rule as the
installer's Remove-IndexUrlCredentials: no userinfo, no query, no fragment.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb16a1f26c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread install.ps1 Outdated
$_xfExit = if ($_xfWheelUrl) {
Invoke-InstallCommandRetry -Label "install xFormers" { & $_xfUv pip install --python $VenvPython --no-deps --reinstall-package xformers $_xfWheelUrl }
} else {
Invoke-InstallCommandRetry -Label "install xFormers" { & $_xfUv pip install --python $VenvPython --no-deps --reinstall-package xformers "xformers==$_xfVersion" --default-index $_xfIndexUrl }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make full-URL xFormers indexes exclusive

When UNSLOTH_TORCH_INDEX_URL is set, including a full .../cu130 URL or an authenticated mirror, this fallback still resolves xformers==$_xfVersion with --default-index. I checked uv pip install --help: --index/UV_INDEX are used “in addition to the default index”, so a machine-level UV_INDEX containing the same xFormers version can still satisfy this install from a different CUDA-family index and recreate the silent extension mismatch. Fresh evidence beyond the earlier UV_INDEX thread is that the current full-URL override branch still reaches this --default-index command; make this install use only the chosen index, or use a direct URL when the full URL names a CUDA leaf.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both halves taken. When the override names a CUDA leaf (the documented shape) the wheel is now addressed directly under it via Join-UrlPath, and the one case that still has to resolve -- a mirror root whose leaf is not a family -- runs with UV_INDEX and UV_EXTRA_INDEX_URL cleared in a try/finally, so the chosen index really is the only one. Tests: test_a_full_url_override_naming_a_cuda_leaf_gets_a_direct_url and test_the_index_fallback_hides_the_machine_level_indexes. d2d8eaa.

Comment thread studio/backend/utils/wheel_utils.py Outdated
Comment on lines +410 to +411
f"{pytorch_wheel_index_base_url()}/{family}"
f"/xformers-{version}-{python_tag}-{platform_leaf}.whl"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve query-token mirrors when appending wheel paths

When UNSLOTH_PYTORCH_MIRROR uses query-string authentication, e.g. https://mirror.example/whl?token=abc, this appends /cu130/... after the query and produces a URL whose path is still only /whl while the token value becomes abc/cu130/xformers-.... That makes the on-demand xFormers install fail for tokenized private mirrors even though this path is meant to honor the configured mirror; insert the CUDA/wheel path before ?/# (and mirror the same fix in the PowerShell direct-URL builder).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and it broke the exact shape the setting exists for. Both sides join before the ?/# now: join_wheel_url in wheel_utils and Join-UrlPath in install.ps1, the latter exercised through pwsh so the two cannot drift. Tests: test_a_query_token_mirror_keeps_its_token, test_a_fragment_survives_the_join_too, test_the_url_join_keeps_a_tokenized_mirrors_query. d2d8eaa.

Daniel Han added 2 commits August 8, 2026 20:00
…en mirror usable

Two ways the wrong wheel could still be installed, or none at all.

A full UNSLOTH_TORCH_INDEX_URL override went to --default-index, which uv does not treat
as exclusive: --index / UV_INDEX are used "in addition to" it, and cu126 / cu128 / cu130
all publish the same xFormers version, so a machine-level index could satisfy the pin
from the wrong family. When the override names a CUDA leaf -- the documented shape -- the
wheel is addressed under it directly instead. A mirror root whose leaf is not a family
still has to be resolved, and for that one call UV_INDEX and UV_EXTRA_INDEX_URL are
cleared, in a finally, so the chosen index really is the only one.

And a mirror may authenticate by query string. Appending "/cu130/..." after the query put
the wheel path inside the token value, leaving the request path at /whl -- so the
tokenized private mirror UNSLOTH_PYTORCH_MIRROR exists for was the one shape that could
not resolve a wheel at all. Both sides join before the ?/# now: join_wheel_url in Python,
Join-UrlPath in the installer, with the PowerShell one exercised through pwsh.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: d2d8eaa1e6

ℹ️ 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".

@danielhanchen
danielhanchen merged commit e219b46 into main Aug 9, 2026
84 of 93 checks passed
@danielhanchen
danielhanchen deleted the nv/p0-xformers-pkg branch August 9, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant