Migrate cpu sdpa from NS flash attn - #2092
Open
jijiaz wants to merge 64 commits into
Open
Conversation
jijiaz
force-pushed
the
copilot/migrate-cpu-flash-attention
branch
14 times, most recently
from
August 3, 2026 03:37
41e938e to
32356f9
Compare
jijiaz
force-pushed
the
copilot/migrate-cpu-flash-attention
branch
2 times, most recently
from
August 5, 2026 02:57
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>
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>
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>
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>
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
a32543254
self-requested a review
August 7, 2026 08:43
a32543254
reviewed
Aug 7, 2026
| @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 |
Contributor
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
| "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)} |
Contributor
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_*/ |
Contributor
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. |
Contributor
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 ?
| docs/plan/ | ||
| .venv/ | ||
| auto_round_extension/ark/auto_round_kernel/build_*/ | ||
| auto_round_extension/ark/build-*/ |
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.
Description
Migrate CPU SDPA backend from Neural Speed to
auto_round_kernel, providing a drop-in CPU implementation with the same public API as the existing XPUsdpa(). The implementation leverages 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. Supports HND/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.sdpa()path. Explicit lifecycle helpers (packed_kv_alloc,update_packed_kv,bestla_sdpa_packed) underauto_round_kernel.internal.cpufor power users.prefer_fp32) exposed throughauto_round_kernel.internal.cpufor opt-in use; rejected by the publicsdpa()contract.TestReorderKV,TestPersistentPackedKV,TestPackedForwardSetup,TestHomogeneousForwardSetup,TestMixedPaddingRight,TestMixedAlibiTanh,TestMixedNumericalFeatures.ark_cpu_sdpa.yml) with AVX2 (ubuntu-latest), AVX512F, and AMX-BF16 (self-hosted) runner tiers.TODO / Follow-up
debug_resolve_sdpa_routeanddebug_cpu_sdpa_routeonce route stability is confirmed in CI; tests should assert numerical parity rather than route integers.Type of Change
Feature
Checklist Before Submitting
/azp run Unit-Test-CUDA-AutoRound.