[CPU] optimize flash_attn_varlen_func#15708
Merged
Kangyan-Zhou merged 25 commits intosgl-project:mainfrom Jan 30, 2026
Merged
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
2 tasks
c4f7b38 to
3ed12d0
Compare
6 tasks
6 tasks
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
fcce838 to
1d4bebf
Compare
1d4bebf to
786910c
Compare
charlesHsuGG
pushed a commit
to charlesHsuGG/sglang
that referenced
this pull request
Jan 30, 2026
sfiisf
pushed a commit
to sfiisf/sglang
that referenced
this pull request
Feb 5, 2026
blzheng
pushed a commit
to blzheng/sglang
that referenced
this pull request
Feb 9, 2026
Johnsonms
pushed a commit
to Johnsonms/sglang
that referenced
this pull request
Feb 14, 2026
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.
Motivation
provide apple to apple function of
flash_attn_varlen_funcon CPU, optimized with intel AMX. Newly enabled models such as omni and sglang diffusion usedflash_attn_varlen_funcdirectly on CUDA device, so need to provide a counterpart on other devices.Modifications
Add
flash_attn.cppin sgl-kernel, the kernel itself is pretty much the same as 2nd stage of extend attention.Accuracy Tests
Add
test_flash_attn.pyin test cases.Benchmarking and Profiling
The existing
scaled_dot_product_attentionfrom torch doesn't support varlen functionalities, so here compare BS=1 withflash_attn_varlen_func, tested with qwen3 omni shape on single socket Intel(R) Xeon(R) 6979P with 40C:The result can be reproduced by test_flash_attn_varlen.py
The kernel on sglang is slightly faster than the version that we implemented in torch. Anyway it should be possible to further optimize this kernel to reuse the packed key and value results for adjacent query blocks that belongs to the same head dimension. Put this as TODO.
Checklist