Repository navigation
Fix XPU flash-attention performance on DPC++ 2026.1 - #921
Merged
Merged
Conversation
The AOT gate in dep-sycl-tla.cmake matched DPCPP_VERSION against an explicit list that stops at 2026.0. DPC++ 2026.1 -- used by every current XPU build variant, including torch214-xpu20261 -- falls through to the else branch and ships JIT-only device code with none of the sycl-tla SPIR-V extensions, which is several times slower on Intel GPUs. Both lists were already contiguous ranges, so compare versions instead. A missing entry does not fail the build, it silently degrades performance, so new DPC++ releases should have to opt out of AOT rather than opt in.
Member
|
Thanks a lot for fixing this! Feel free to ping me on Slack to fast-track the changes (and any kernel rebuilds needed) once this PR goes out of draft. |
sycl-tla v0.9.2 rewrote the flash-attention v2 forward mainloop and introduced a performance regression on Intel GPUs. On an Arc Pro B60 (BMG) the forward kernel is up to 8x slower than with v0.8, and the gap grows with sequence length. v0.9.3 fixes it. Measured with an otherwise identical flash-attn2 build (same sources, same compiler, same flags, same card, cold cache); only the sycl-tla include path was swapped. Times are fp16, causal, head_dim 64: B x S x H x D v0.8 v0.9.2 v0.9.3 4x512x8x64 0.091 ms 0.145 ms 0.100 ms 4x1024x8x64 0.217 ms 0.509 ms 0.143 ms 4x2048x8x64 0.391 ms 3.291 ms 0.432 ms 4x2048x16x64 0.729 ms 6.891 ms 0.817 ms 8x1024x8x64 0.219 ms 1.134 ms 0.244 ms v0.9.3 restores v0.8 performance and improves on it at 1024. The v0.9.2 numbers match what the published kernels-community/flash-attn2 torch214-xpu20261 build does today (3.347 ms at 4x2048x8x64), so this regression is what users currently get from the Hub. cri kernel support is retained; v0.9.3 was verified to compile for the pvc, bmg-g21 and cri AOT targets.
jiqing-feng
force-pushed
the
xpu-aot-min-version
branch
from
October 23, 2026 06:09
30a1a74 to
2278b15
Compare
jiqing-feng
marked this pull request as ready for review
October 23, 2026 14:39
danieldk
approved these changes
Oct 24, 2026
Member
|
Thanks a lot for fixing this! |
github-actions Bot
pushed a commit
to huggingface/kernels-community
that referenced
this pull request
Oct 26, 2026
Move to `main` to get the improvements from huggingface/kernels#921
Cyrilvallez
added a commit
to huggingface/transformers
that referenced
this pull request
Oct 27, 2026
* Bump kernels-community/flash-attn2 to v4 The v3 branch of the flash-attn2 kernel repo ships an XPU build that predates huggingface/kernels#921, so it has ahead-of-time compilation silently disabled and is built against a sycl-tla revision with a flash-attention forward regression. v4 carries both fixes. v3 and v4 produce bit-identical logits, so this is a build-level change only. * only on recent versions --------- Co-authored-by: Cyril Vallez <cyril.vallez@gmail.com>
github-actions Bot
pushed a commit
to huggingface/kernels-community
that referenced
this pull request
Oct 28, 2026
Same issue as #1275. megablocks still pins kernel-builder at `d054906` (before huggingface/kernels#921), so the `xpu20261` variants are built without AOT: the `.so` only carries a `spir64` JIT image. The CRI grouped GEMM (`MoE::xe35`) is AOT-only by design (#1066), so it is missing from these builds entirely. On CRI, `xpu_fused_moe` segfaults in `getDeviceKernelInfo` when it dispatches to the xe35 kernel. | variant | `.so` size | offload sections | |---|---|---| | `torch213-xpu20260` | 8.3 MB | `spir64_gen` + `spir64` | | `torch214/215-xpu20261` | 3.9 MB | `spir64` only | This moves megablocks to kernel-builder `main` (same lock as flash-attn2). Note that this also bumps sycl-tla from v0.9.2 to v0.9.3.
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.
Two independent problems make the published XPU kernels slow. Both are in
dep-sycl-tla.cmake.End-to-end result for
flash-attn2, built through the normalnix build .#redistributable.torch214-xpu20261-x86_64-linuxpath. Intel Arc Pro B60, torch 2.14.0+xpu, fp16, causal, cold compiler cache. Baseline is the same build with sycl-tla pinned back to v0.8, i.e. the behaviour before the regression; all three columns are full 86-TU builds with identical AOT targets, so the only difference is what this PR changes. Throughput relative to that baseline, higher is better:That is a 2.4x to 9.3x gain over the artifact users get today, and lands between 0.78x and 1.06x of pre-regression throughput. The remainder is v0.9.3 itself, which is still slightly behind v0.8 at head_dim 64 and 96; it is not something this PR can close, and v0.9.3 wins at the larger head dims.
The rest of this description explains the two causes separately.
1. AOT is silently disabled on 2026.1
Two gates match
DPCPP_VERSIONagainst explicit lists that do not include2026.1— the version used by every current XPU variant (torch214-xpu20261,torch215-xpu20261).Missing an entry does not fail the build, it silently drops the AOT images and the
SPV_INTEL_2d_block_io/subgroup_matrix_multiply_accumulateextensions. Kernels that useXE_2D_*fail to link (exit code 18); kernels that don't, likeflash-attn2, just ship JIT-only.Both lists were already contiguous ranges, so this is behaviour-preserving for every version in
build-variants.jsonand additionally fixes 2026.1. New DPC++ releases now opt out of AOT rather than opt in.preamble.cmakeenables AOT by default for XPU; this gate is the only place that turns it back off.I added the AOT gate in #734, when
2026.0was the only XPU version that existed. 2026.1 landed six days later in #784, which didn't touch this file.Probe kernel on
torch214-xpu20261-x86_64-linux, before and after:For
flash-attn2this is a first-call effect: 2023.9 ms -> 147.8 ms on a cold compiler cache. It does not change steady-state kernel time — that is problem 2.2. sycl-tla v0.9.2 has a flash-attention forward regression
v0.9.2 rewrote the FMHA forward mainloop and regressed throughput on Intel GPUs by up to 9x. It is fixed in v0.9.3.
Same flash-attn2 sources, same compiler, same flags, same card (Arc Pro B60), cold cache. The only variable is the sycl-tla include path. fp16, causal, head_dim 64. Throughput relative to v0.8, higher is better:
v0.9.2 drops to a ninth of v0.8 throughput at 2048, and the gap grows with sequence length. v0.9.3 is back to roughly v0.8 and is 1.5x faster at 1024.
These three builds are a reduced configuration — forward only, head_dim 64 — so that the sycl-tla revision is the single variable. The published
kernels-community/flash-attn2torch214-xpu20261artifact pins kernel-builder atd054906, which resolves to v0.9.2, and measures in line with the v0.9.2 column.The revision is pinned in two places, both bumped to v0.9.3:
kernel-builder/src/pyproject/templates/xpu/dep-sycl-tla.cmakenix-builder/pkgs/xpu-packages/sycl-tla.nixcrikernel support is retained — v0.9.3 was verified to compile for thepvc,bmg-g21andcriAOT targets.The sycl-tla revision gate keeps its explicit list — its fall-through is
FATAL_ERROR, so it can't be forgotten silently.Notes
Numerics unchanged (
max|diff|~1.2e-4 vs torch SDPA flash backend).AOT images cost build time and artifact size; the
spir64JIT image is kept as a fallback for devices outside the AOT list.Existing kernels won't pick this up until they bump their
flake.lock—kernels-community/flash-attn2currently pins kernel-builder atd054906— and are rebuilt.