Skip to content

Studio: skip xFormers when its torch requirement is unmet - #11847

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:worktree-xformers-torch-mismatch
Sep 25, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:worktree-xformers-torch-mismatch

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Studio's Linux installer can pair xFormers 0.0.35 (torch>=2.10) with torch 2.6.0+cu124, causing diffusers imports to fail (reported on Reddit and also #11545). This PR removes or hides incompatible xFormers so attention falls back to torch SDPA.

This fixes the xFormers failure. Torch 2.6 hosts have a second, independent problem with Studio's current default diffusers main build: it imports FqnToConfig, which torchao 0.14.0 lacks, and fails the same way with no xFormers installed at all. That is not addressed here, so the tests below use diffusers 0.40.0 (UNSLOTH_DIFFUSERS_MAIN=0), the version the reporter had.

Cause

install.sh pins torch through --overrides, bypassing xFormers' torch requirement. The existing Linux repair leaves the incompatible pair installed when torch is unchanged.

Fix

  • Check xFormers' declared torch requirement using metadata, without importing it. Keep compatible versions and leave unreadable metadata alone.
  • Remove incompatible xFormers after the final Linux torch repair, even when torch is unchanged.
  • Hide it before diffusers imports in existing environments. Skip on-demand replacement downloads while it remains hidden until restart.

Before and after

Fresh installs on an RTX 6000 Ada, using torch 2.6.0+cu124 and diffusers 0.40.0. Tested unsloth/sdxl-turbo at 512x512, one step.

Check main This PR
uv pip check xFormers/torch conflict Clean
Model load xFormers import error Loaded
Generation No model loaded One image

The updated backend also loaded and generated from an existing broken environment without uninstalling xFormers. Explicitly selecting xFormers fell back successfully without downloading a replacement.

Tests

  • Coverage for requirement parsing, import guards, installer removal, and skipped replacement downloads.
  • Installer suite: 7566 passed, 1631 skipped. Related backend suites: 333 passed, 2 skipped. Lint and formatting passed.

Scope

@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence at oobabooga#300.

@danielhanchen danielhanchen self-assigned this Sep 25, 2026
@danielhanchen

Copy link
Copy Markdown
Member

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

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 e5987a8e8b (this PR's 7540937a6)

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

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

Reviewed commit: e5987a8e8b

No triage reaction was recorded on the mirror

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

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: e5987a8e8b

View security finding report

Only the user who started this review can view the report in Codex.

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror e5987a8e8b (this PR's 7540937a6).

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 14ceddf into unslothai:main Sep 25, 2026
62 of 65 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…11847)

Studio's Linux installer could pair xFormers 0.0.35 (torch>=2.10) with torch 2.6.0, which made every diffusers import fail. xFormers is now checked against its declared torch requirement from package metadata: an incompatible build is hidden before diffusers imports it (attention falls back to torch SDPA), the final Linux torch repair removes it even when torch is unchanged, and on-demand reinstalls are skipped while it is hidden. Compatible builds are kept.
danielhanchen added a commit to tweekli/unsloth that referenced this pull request Sep 30, 2026
…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.
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.

2 participants