feat(ark): add INT4 S4 pre-packed Q*K kernel for SageAttention - #2319
Draft
luoyu-intel wants to merge 3 commits into
Draft
luoyu-intel wants to merge 3 commits into
luoyu-intel wants to merge 3 commits into
Conversation
Replace SageAttention V1 INT8 Q*K path with signed INT4 DPAS on Arc Pro B60 (BMG G21). Pre-packed INT4 Q/K only; P*V remains FP16/BF16. - sycl_tla_sdpa.hpp: typed make_gmem_ptr, MMA ops templated on ElementQ/K, INT4 conditional shapes (K tile 64), locked M=256/Stages=2. - CMakeLists.txt: bake two INT4 sycl-tla header patches (integer_subbyte default arg; copy_traits_xe_2d raw_pointer_cast) so fresh builds compile INT4 without manual edits. - api/entry: sage_s4 in __init__.py, ark.cpp pybind, sdpa.cpp launchers + sdpa_impl_qks4_pvhalf; kernel/wrapper updates accordingly. - tests: bench_sage_int4.py (pre-packed S4 vs S8) + test_sage_int4.py. - root .gitignore: ignore out-of-source xbuild* build dirs. On B=1/H=40/S=10240/D=128: S4 ~11.8% faster than S8 (18.89 vs 21.41 ms), max_diff=0. Regression: test_sage_int4 6 passed, test_sdpa_parity 9 passed.
for more information, see https://pre-commit.ci
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.
feat(ark): add INT4 S4 pre-packed Q*K kernel for SageAttention
Summary
Replace SageAttention V1's INT8 Q*K path with standard signed INT4 DPAS on Intel Arc Pro B60 (Battlemage G21). This PR introduces a pre-packed INT4 Q/K path that achieves ~11.8% throughput improvement over the existing INT8 path on the benchmark shape, with exact numerical correctness (max_diff = 0).
Motivation
INT4 Q*K via
XE_DPAS_TTon Intel GPU offers native 4-bit dot-product accumulation, halving the data bandwidth of the Q*K matmul compared to INT8 while maintaining signed precision. This is the first step toward a full INT4 attention pipeline; P*V remains FP16/BF16 in this PR.What's Changed
sycl_tla_sdpa.hppmake_gmem_ptrfor subbyte iterators; MMA ops templated onElementQ/ElementK; INT4 conditional tile shapes (K tile = 64); locked M=256 / Stages=2CMakeLists.txtinteger_subbyte.hdrop default template arg;copy_traits_xe_2d.hppraw_pointer_castsubbyte fix) so fresh builds compile without manual edits__init__.pysage_s4public APIark.cppsage_s4pybind entry pointsdpa.cpplaunch_prefill_kernel_{f16,bf16}_{64,128}_sage_s4) +sdpa_impl_qks4_pvhalfdispatchxe_sage_fwd_kernel.hppsycl_s8_wrapper.hppsycl_tla_common.hppsycl_tla_s8_gemm.hpptest/bench_sage_int4.pytest/test_sage_int4.py.gitignorexbuild*build dirsTechnical Details
XE_DPAS_TT<cute::gcd(SGTileQ, 8), int32_t, ElementQ, ElementK>(signed 4-bit dot product into int32 accumulator).XE_DPAS_TT<cute::gcd(SGTileQ, 8), float, ElementO>— unchanged, FP16/BF16.Shape<_256, _64, _64>(K tile 64 vs INT8's 32); PV =Shape<_256, _32, _64>; Out =Shape<_256, _128>.cutlass/integer_subbyte.h: remove= truedefault fromtemplate <int Bits, bool Signed = true>→template <int Bits, bool Signed>.cute/atom/copy_traits_xe_2d.hpp:base_ptr((uint64_t) &*src.data())→base_ptr(reinterpret_cast<uint64_t>(raw_pointer_cast(&*src.data())))— required becausesubbyte_iteratorhas no implicit conversion touint64_t.Performance
Testing
test_sage_int4.py: 6 passed (accuracy across shapes/dtypes)test_sdpa_parity.py: 9 passed (SAGE/SDPA regression — no existing kernel broken)bench_sage_int4.py: S4 vs S8 benchmark, printss4_ms,s8_ms, speedup ratio,max_diff,mean_diffScope / Deferred
This PR covers pre-packed INT4 Q/K only. The following are intentionally deferred:
Build & Run