Migrate cpu sdpa from NS flash attn - #2092
Conversation
41e938e to
32356f9
Compare
f90eab3 to
d4a3493
Compare
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
…dpa benchmark Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
…(phase 2 step 1) Signed-off-by: jijiaz <jijia.zhou@intel.com>
…phase 2 step 2) Signed-off-by: jijiaz <jijia.zhou@intel.com>
…2 step 3) Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
…hase 4 step 1) Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
for more information, see https://pre-commit.ci
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
for more information, see https://pre-commit.ci
Signed-off-by: jijiaz <jijia.zhou@intel.com>
for more information, see https://pre-commit.ci
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
for more information, see https://pre-commit.ci
| @pytest.mark.parametrize("layout", ["HND", "NHD"]) | ||
| def test_bestla_mixed_sdpa_matches_torch(kv_dtype, is_causal, layout): | ||
| torch.manual_seed(4003) | ||
| batch, heads_q, heads_kv, head_dim, seq = 1, 8, 2, 64, 64 |
There was a problem hiding this comment.
better also have medium and large size test for acc and performance
maybe take some shape from really LLMs
There was a problem hiding this comment.
Added LLM shape tests and benchmarks
| "auto_round_kernel", reason="compiled ARK extension not built in this environment" | ||
| ) | ||
|
|
||
| _TOL = {torch.float16: (3e-2, 3e-2), torch.bfloat16: (8e-2, 8e-2)} |
There was a problem hiding this comment.
the TOL seem a little bit too high for float
maybe you could try to set a lower threshold
| *.pyc No newline at end of file | ||
| *.pyc | ||
| *.csv.venv/ | ||
| auto_round_extension/ark/auto_round_kernel/build_*/ |
There was a problem hiding this comment.
I don‘t think we need add more here
build
xbuild
*.csv
*.so
*.pyc
I believe the above already included what you add
| | [test_matmul.py](test/test_matmul.py) | Low-level matmul | | ||
| | [test_packq.py](test/test_packq.py) | Weight packing utilities | | ||
| Notes: | ||
| * The patch only routes calls to ARK on XPU when the inputs match ARK kernel constraints; otherwise it falls back to the original torch SDPA. |
There was a problem hiding this comment.
“ The patch only routes calls to ARK on XPU when the inputs match ARK kernel constraints; otherwise it falls back to the original torch SDPA.”
why here mention xpu ? all the code should only focus on cpu right ?
There was a problem hiding this comment.
Merge remains, now removed in the new commits.
| docs/plan/ | ||
| .venv/ | ||
| auto_round_extension/ark/auto_round_kernel/build_*/ | ||
| auto_round_extension/ark/build-*/ |
37f00a8 to
3c2f775
Compare
Signed-off-by: jijiaz <jijia.zhou@intel.com> (cherry picked from commit 37f00a8)
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Defect-1 (workspace cache) + Defect-2 (fp16-bf16-AMX prefill) already in tree; this snapshot captures the JIT-accelerated BF16 K/V update paths that were in the working tree before the GCC12 investigation. Signed-off-by: jijiaz <jijia.zhou@intel.com>
Signed-off-by: jijiaz <jijia.zhou@intel.com>
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
Adds CPU support to ARK’s SDPA API using scalar and BestLA-accelerated routes, including packed KV caching.
Changes:
- Implements CPU SDPA dispatch, packed caches, and mixed/homogeneous precision routes.
- Adds CPU tests, benchmarks, validation tooling, and CI.
- Updates build configuration, BestLA kernels, documentation, and dependencies.
Reviewed changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
.gitignore |
Ignores ARK build artifacts. |
.github/workflows/ark_cpu_sdpa.yml |
Adds CPU SDPA CI. |
auto_round_extension/ark/.gitignore |
Normalizes ignored Python artifacts. |
auto_round_extension/ark/README.md |
Documents SDPA evaluation usage. |
auto_round_extension/ark/requirements.txt |
Adds CPU feature detection dependency. |
auto_round_extension/ark/test/validate_non_int8_cpu_sdpa.py |
Adds route readiness runbook. |
auto_round_extension/ark/test/test_ark_cpu_sdpa.py |
Tests public CPU SDPA behavior. |
auto_round_extension/ark/test/test_ark_cpu_mixed_bestla_sdpa.py |
Tests mixed-precision BestLA routes. |
auto_round_extension/ark/test/bench_ark_cpu_sdpa.py |
Benchmarks CPU SDPA routes. |
auto_round_extension/ark/auto_round_kernel/CMakeLists.txt |
Builds CPU SDPA sources and feature flags. |
auto_round_extension/ark/auto_round_kernel/__init__.py |
Exposes CPU SDPA and packed-cache APIs. |
auto_round_extension/ark/auto_round_kernel/ark.cpp |
Adds native CPU dispatch and bindings. |
auto_round_extension/ark/auto_round_kernel/ark/cpu/mha_dense.cpp |
Implements scalar CPU attention. |
auto_round_extension/ark/auto_round_kernel/ark/cpu/mha_dense.h |
Defines CPU attention contracts. |
auto_round_extension/ark/auto_round_kernel/ark/cpu/sdpa.h |
Declares BestLA SDPA routes and cache helpers. |
auto_round_extension/ark/auto_round_kernel/bestla/bestla/bestla_gemm.h |
Adds masked tail stores. |
auto_round_extension/ark/auto_round_kernel/wrapper/include/sycl_tla_common.hpp |
Removes obsolete SDPA documentation. |
auto_round_extension/ark/auto_round_kernel/wrapper/include/utils.hpp |
Updates unsupported-type assertion. |
Suppressed comments (1)
auto_round_extension/ark/auto_round_kernel/init.py:835
- This repeats the nonexistent
ARK_UNSAFE_BESTLA_MIXED_SDPAgate forn_padding. Document the actualARK_ENABLE_INTERNAL_SDPA_FEATURES=ONbuild requirement so users do not set an ineffective environment variable.
- n_padding: Number of valid (non-padding) K/V positions when the K/V
sequence is right-padded. Must be in (0, seq_kv] and mutually exclusive
with is_causal. Only supported on the BestLA mixed-precision CPU path
with ARK_UNSAFE_BESTLA_MIXED_SDPA=1. [CPU-only]
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: jijiaz <jijia.zhou@intel.com>
for more information, see https://pre-commit.ci
Signed-off-by: jijiaz <jijia.zhou@intel.com>
Description
Migrate CPU SDPA backend from Neural Speed to
auto_round_kernel, providing a drop-in CPUimplementation with the same public API as the existing XPU
sdpa(). The implementationleverages BestLA kernels for mixed-precision (f32 Q + f16/bf16 KV) and homogeneous
(fp16/bf16) dispatch, with a scalar fallback for unsupported configurations.
auto_round_kernel.sdpa()now acceptsdevice="cpu"tensors. SupportsHND/NHD layouts, causal masking, additive masks, GQA, and multi-tile K/V sequences.
Mixed-dtype (f32 Q + f16/bf16 KV) is transparently accelerated via a hidden packed KV cache.
test_ark_cpu_sdpa.py(public API semantics),test_ark_cpu_mixed_bestla_sdpa.py(mixed-dtype accuracy with real LLM shapes),
bench_ark_cpu_sdpa.py(correctness benchmark),benchmark_sdpa.py(perf micro-benchmark). ISA-aware skip guards for AVX2/AVX512F/AMX-BF16/AVX512-FP16.
fp16 → 1–2e-2, bf16 → 3–5e-2 (empirically measured; softmax amplifies BF16's 7-bit
mantissa error ~3–5× vs FP16's 10-bit).
Performance
ARK CPU SDPA delivers 1.3–1.6× speedup over Torch FP32 SDPA for decode workloads across
real-world LLM attention shapes on 32-thread Xeon with AMX-BF16. Representative results
(geomean across all non-scalar routes: 1.28×):