Repository navigation
fix(studio): evict a torch-mismatched xFormers after the Linux repair - #11559
Closed
InfoSage05 wants to merge 4 commits into
Closed
InfoSage05 wants to merge 4 commits into
InfoSage05 wants to merge 4 commits into
Conversation
The final torch repair (step 13) already re-selects torchao when it moves torch to fix the venv's flavor (unslothai#10493), but left xFormers alone. xFormers links its extension against one exact (torch, CUDA) pair; beside any other its ops go mute or raise instead of failing at import, and diffusers/peft import xFormers eagerly -- so a resident xFormers built for a torch that is no longer installed (often not even from this venv's own install history) surfaces as an unrelated- looking aten::_flash_attention_forward schema crash the first time an image/diffusion model loads, well after Repair Installation reported success. Reuse _evict_xformers_built_for_another_torch(), already proven on the Windows-on-ARM64 wheelhouse path (unslothai#10282), instead of adding a new check: it already does exactly this eviction, just was never wired into the general Linux path. Generalized its note text, which hardcoded "windows on arm" even though the function itself has no platform dependency. Fixes unslothai#11545
InfoSage05
marked this pull request as ready for review
September 22, 2026 16:29
This was referenced Sep 22, 2026
Member
|
Confirmed the Linux repair in install_python_stack.py re-selects torchao when torch moves but never checks xFormers, and calling the existing _evict_xformers_built_for_another_torch there looks right for #11545. Will get this reviewed. |
This was referenced Sep 24, 2026
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Linux, Unsloth Desktop's Repair Installation re-selects
torchaowhen the repair movestorch(fixed for #10493), but never re-checkedxFormers. xFormers links its compiled extension against one exact(torch, CUDA)pair; beside any other pair its ops go mute or raise instead of failing cleanly at import, anddiffusers/peftimport xFormers eagerly — so a resident xFormers built for a torch that Repair Installation just replaced surfaces as an unrelated-lookingaten::_flash_attention_forwardschema crash the first time an image/diffusion model loads, well after the repair itself reported success.This PR reuses
_evict_xformers_built_for_another_torch()— the exact eviction primitive already proven on the Windows-on-ARM64 wheelhouse path (#10282) — in the Linux final-repair step, right alongside the existingtorchaore-selection call.Root Cause
The root cause is
studio/install_python_stack.py's Linux "step 13" final torch repair (install_python_stack(), around theif _torch_after_repair and _torch_after_repair != _torch_before_repair:block) re-selectingtorchaofor the newly-repaired torch but never re-checkingxFormers, because_resync_torch_coupled_packages()— the function that already does both — is only reached from the Windows torch-flavor-repair path (_ensure_expected_torch_flavor), and #10493's fix added a standalonetorchao-only call to Linux's step 13 without adding the equivalent for xFormers.This matches issue #11545 exactly: repairing a GTX 960M (Maxwell, compute capability 5.0) moved torch from a CPU-only build to
2.6.0+cu124(correctly landed via the existing GPU-architecture-aware torch selection), but left a resident xFormers0.0.35built fortorch 2.10.0+cu128, Python 3.10.19completely untouched — not even from this venv's own install history — which then crasheddiffusers/peft's import chain the first time an image/diffusion model was loaded.Changes
studio/install_python_stack.py:_install_torchao_for_torch(_torch_after_repair), call_evict_xformers_built_for_another_torch()under the same "torch actually moved during this repair" guard._evict_xformers_built_for_another_torch()'s note text, which hardcoded"windows on arm:"even though the function itself has no platform dependency — it's now reused from a general Linux path too.tests/studio/install/test_cuda_repair.py: two new tests following this file's own establishedinspect.getsource(...)wiring-verification idiom (seeTestTheWindowsXpuTritonSwapReachesADirectRunfor precedent) — one confirms the eviction call is wired into step 13's torch-moved guard in the right order relative to thetorchaocall, the other confirms the reused eviction function's note text no longer claims "windows on arm".No new elaborate mocking harness was built for the deeply-nested procedural
install_python_stack()entry point itself — the eviction logic (_evict_xformers_built_for_another_torch,_resident_xformers_build_torch) is already extensively covered by existing tests intest_windows_arm64_wheelhouse_tags.pyandtest_cuda_repair.py'sTestThePackagesTiedToTheTorchReleaseAreResettled, which I did not touch.Investigation
Verified the actual "Repair Installation" desktop-button code path end-to-end rather than assuming: frontend
desktop-repair-control.tsx→useTauriRepairController().repairInstall()→ Tauri commandstart_managed_repair(force_installer: true) →install::run_install_for_repair→resolve_install_scriptpicksinstall.shon Linux →install.shrunsunsloth studio update, which (per this file's own Windows-path docstring: "unsloth studio updateruns setup.ps1 and this script [install_python_stack.py]") is what actually executesinstall_python_stack.py's repair steps on Linux.Testing
test_cuda_repair.py: 268/268 passed (both new tests included).test_cross_platform_parity.py,test_e2e_no_torch_sandbox.py,test_flash_attn_install_python_stack.py,test_install_python_stack.py,test_no_torch_filtering.py,test_torchcodec_torch_compat.py,test_windows_arm64_requirement_markers.py,test_windows_arm64_wheelhouse_tags.py,test_windows_no_torch_setup.py): 1667 passed, 9 failed, 7 skipped. All 9 failures reproduce identically against the unmodified upstream baseline (confirmed viagit stash) — they come from a broken WSL2 sandbox in this specific CI/dev environment (Failed to attach disk '...ext4.vhdx' to WSL2), unrelated to this change.Checklist
test_cuda_repair.py)Fixes #11545)Fixes #11545