Repository navigation
Probe xformers support on sm_120 instead of disabling it by version - #6828
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces the hardcoded compute-capability check for disabling xformers on sm_120+ GPUs with a dynamic probe that verifies if the xformers kernel can actually run on the device. It also adds a regression test suite to validate this behavior. The review feedback points out that the probe uses torch.bfloat16 unconditionally, which will cause test failures on older GPUs (like Turing or Volta) that do not support bfloat16 but have a working xformers build. It is recommended to dynamically select the data type based on hardware support.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 888bb39cf1
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 819a1d217f
ℹ️ 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".
|
@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: 819a1d217f
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7b1bb3136e
ℹ️ 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".
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
|
@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: 677bea28e4
ℹ️ 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".
Unsloth blanket-disables xformers on any GPU with compute capability >= 12 (RTX 50-series, sm_120) and falls back to SDPA. On packed training that wastes a large amount of attention memory: the SDPA fallback materializes a dense block-diagonal mask while xformers does not.
Closes #4631
Problem
The guard added in #4342 disables xformers by GPU version alone:
The comment claims xformers kernels "only support compute capability <= 9.0". That is too strong. The shipped wheels have no native sm_120 kernel, but
memory_efficient_attentionstill runs there when its cutlass kernel JIT-compiles forward from the8.0+PTXbuild target. On builds where it runs, disabling it throws away a real memory saving. The load-time guard inmodels/_utils.py(broken FA3 dispatch on xformers <= 0.0.32.post2) already blocks the genuinely broken versions, so this version check is redundant.Fix
Replace the version guess with a runtime probe, gated to sm_120+ so nothing changes for any other GPU. At sm_120+ it runs one tiny
memory_efficient_attentionforward and keeps xformers only if that succeeds. Otherwise it falls back to SDPA exactly as before. The worst case on a broken sm_120 build is unchanged behavior, never a new crash.Below sm_120 the probe never runs, so there is no import-time cost or behavior change for Ada, Hopper, B200, and so on.
Hardenings from the review rounds:
SUPPORTS_BFLOAT16(bf16 on sm_80+, else fp16), so pre-Ampere GPUs with a working fp16 xformers are not misreported as broken.torch.cuda.synchronize()after the probe call, so an async kernel failure is caught here instead of surfacing as a false success.One companion fix rides along. On sm_100+ xformers' fp32-capable cutlass op is capability-rejected and only its fp16/bf16 flash-2 op exists, so the existing #1013 fp32 DoRA downcast now also applies to the xformers backend there. Without it, fp32 Q/K/V raises
No operator found for memory_efficient_attention_forwardon those GPUs.Verification
Verified on the exact hardware class the report is about: an RTX 5090 (sm_120, Ubuntu 24.04, driver 580) with the environment Unsloth ships (torch 2.10.0, xformers 0.0.35 from the pinned cu128 wheel, no flash-attn).
The gate itself, main vs this branch, on the same box:
Packed forward and backward through the real
run_attention(8 GQA heads, head_dim 128, bf16):So on sm_120 the fallback this PR removes is not just slower: it cannot run a packed 4 x 4096 batch at all at this head count.
The fp32 downcast was exercised live on the same GPU. With it, fp32 Q/K/V runs and matches the bf16 run exactly. With the flag forced off, the same call raises
No operator found for memory_efficient_attention_forward.Earlier measurement on a B200 (sm_100, same PTX forward-compat path) agrees: 539 MB vs 1242 MB peak, max diff 3.9e-3.
Added
tests/utils/test_xformers_capability_gate.py: the decision logic across Ada, Hopper, B200, sm_120-works, and sm_120-broken, the probe dtype selection, the synchronize behavior, plus a real-GPU check that the probe shapes are valid so a malformed probe cannot silently disable xformers everywhere. Also added xformers cases totests/utils/test_attention_dispatch_dora_dtype.pyfor the fp32 downcast. Both files pass on the 5090 (13 passed, 1 skipped: the real-GPU check skips on sm_120+, where False is a legitimate probe answer) and on an Ada/Ampere box (14 passed).