Skip to content

Fix XPU flash-attention performance on DPC++ 2026.1 - #921

Merged
danieldk merged 3 commits into
huggingface:mainfrom
jiqing-feng:xpu-aot-min-version
Oct 24, 2026
Merged

danieldk merged 3 commits into
huggingface:mainfrom
jiqing-feng:xpu-aot-min-version

Conversation

@jiqing-feng

@jiqing-feng jiqing-feng commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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 normal nix build .#redistributable.torch214-xpu20261-x86_64-linux path. 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:

B x S x H x D before the regression Hub today this PR
4x512x8x64 1.00x 0.56x 0.90x
4x1024x8x64 1.00x 0.32x 0.87x
4x2048x8x64 1.00x 0.12x 0.81x
4x2048x16x64 1.00x 0.11x 0.80x
8x1024x8x64 1.00x 0.21x 0.83x
1x4096x32x128 1.00x 0.11x 1.06x
4x2048x16x96 1.00x 0.08x 0.78x
4x2048x8x192 1.00x 0.42x 1.00x
1x4096x32x192 1.00x 0.16x 1.01x
first call 1.00x 0.07x 0.93x

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_VERSION against explicit lists that do not include 2026.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_accumulate extensions. Kernels that use XE_2D_* fail to link (exit code 18); kernels that don't, like flash-attn2, just ship JIT-only.

-if(DPCPP_VERSION STREQUAL "2026.0")
+set(DPCPP_AOT_MIN_VERSION "2026.0")
+if(DPCPP_VERSION VERSION_GREATER_EQUAL DPCPP_AOT_MIN_VERSION)

-if(DPCPP_VERSION STREQUAL "2025.2" OR ... STREQUAL "2026.0" OR SYCL_TLA_REVISION STREQUAL "v0.5")
+set(DPCPP_BLOCK_IO_MIN_VERSION "2025.2")
+if(DPCPP_VERSION VERSION_GREATER_EQUAL DPCPP_BLOCK_IO_MIN_VERSION OR SYCL_TLA_REVISION STREQUAL "v0.5")

Both lists were already contiguous ranges, so this is behaviour-preserving for every version in build-variants.json and additionally fixes 2026.1. New DPC++ releases now opt out of AOT rather than opt in. preamble.cmake enables 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.0 was 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:

before:  RequiresExtension: SPV_INTEL_2d_block_io
         icpx: error: llvm-spirv command failed with exit code 18

after:   [16] __CLANG_OFFLOAD_BUNDLE__sycl-spir64_gen   <- AOT
         [17] __CLANG_OFFLOAD_BUNDLE__sycl-spir64       <- JIT fallback

For flash-attn2 this 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:

B x S x H x D v0.8 v0.9.2 v0.9.3
4x512x8x64 1.00x 0.63x 0.91x
4x1024x8x64 1.00x 0.43x 1.52x
4x2048x8x64 1.00x 0.12x 0.91x
4x2048x16x64 1.00x 0.11x 0.89x
8x1024x8x64 1.00x 0.19x 0.90x

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-attn2 torch214-xpu20261 artifact pins kernel-builder at d054906, 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.cmake
  • nix-builder/pkgs/xpu-packages/sycl-tla.nix

cri kernel support is retained — v0.9.3 was verified to compile for the pvc, bmg-g21 and cri AOT 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 spir64 JIT 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-attn2 currently pins kernel-builder at d054906 — and are rebuilt.

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.
@danieldk

Copy link
Copy Markdown
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 jiqing-feng changed the title Gate XPU AOT compilation on a minimum DPC++ version instead of an exact match Fix XPU flash-attention performance on DPC++ 2026.1 Oct 23, 2026
@jiqing-feng
jiqing-feng marked this pull request as ready for review October 23, 2026 14:39
@danieldk
danieldk merged commit 165527c into huggingface:main Oct 24, 2026
38 of 43 checks passed
@danieldk

Copy link
Copy Markdown
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
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.
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.

2 participants