Repository navigation
[Gemma4][Attention] Enable Gemma4 FA4 on SM90 with head-dim 512 support - #42019
Conversation
| or self.use_mla | ||
| or self.fa_skip_kv_cache | ||
| or metadata.swa_spec_metadata is not None | ||
| or metadata is self.full_cg_prefill_metadata |
There was a problem hiding this comment.
Could we check this before graph replay? Full prefill graph replay skips forward_extend(), so this guard never runs. A graph captured without images would still use causal attention for image requests, even after image_token_ranges is set. Falling back to eager for image batches would avoid this.
There was a problem hiding this comment.
I’ve modified the code so that prefill batches containing images fall back to eager mode in full-graph backend
5d452c3 to
1508bfe
Compare
|
One thing on the head_dim 80 and 96 get tile_n 144 when there is no causal or local masking. There the formula gives each thread 1 page-table entry, as the floor did before this PR. But the loader's last pass reads a second: the one I evaluated both forms on CPU at every SM90 tile this PR's That part is code reading plus the CPU check. My GPU runs of this form at tile_n 144 give wrong output, but they also hit a separate bug in the loader's partial last pass (Dao-AILab/flash-attention#2957, fix in Dao-AILab/flash-attention#2958). So they don't isolate the missing entry. That bug also means the ceil-divide alone doesn't make tile_n 144 correct. On SGLang main, head_dim 80 and 96 are still wrong with it and correct with both changes. My follow-up on #35757 has the runs and the vendored-copy diff. |
1508bfe to
05e7c12
Compare
@SamMausberg thanks for the detailed analysis, I’ve changed the allocation to ceiling division and confirmed on an H200 that it alone does not fix tile_n 144. Are you working on fixing the loader's partial last pass in SGLang? |
|
@cognaiger9 No, not yet. Would you like me to, or should someone else handle it? The fix is in Dao-AILab/flash-attention#2958, which is waiting for review. If you want tile_n 144 correct, the diff is in #35757 (comment). It's a few lines in paged_kv.py. If it's easiest, you're welcome to use it. |
7a0f3c8 to
aaa04e1
Compare
|
@SamMausberg got it, i just folded the diff in my PR and it has passed tile_n 144 |
|
@cognaiger9 Please fix the conflict |
|
@BBuf i just resolved |
|
/rerun-test test/registered/kernels/ops/attention/test_flash_attention_4.py test/registered/attention/unittests/dense/test_fa4.py test/registered/attention/test_flash_attention_4.py test/registered/unit/model_executor/test_prefill_cuda_graph_runner.py Targeted coverage for this PR:
The existing B200 end-to-end tests use Qwen models; they do not replace Gemma4 FA4 end-to-end multimodal validation. |
|
🚀 🚀 🚀 |
# Conflicts: # test/registered/unit/model_executor/test_prefill_cuda_graph_runner.py
|
Hi @BBuf , the failure in run 37569883960 isn’t from this PR. That rerun-test was pinned to the old head 0ce316a, which had main’s qv mValue arg mismatch from sgl-project/sglang#42239. It was fixed in sgl-project/sglang#42926, and the current head 2ef8ad8 includes it |
|
/rerun-test test/registered/kernels/ops/attention/test_flash_attention_4.py test/registered/unit/model_executor/test_prefill_cuda_graph_runner.py Merged current main and resolved the FA4 wrapper/test conflicts in 3fb0f12. Both image mask_mod and output-buffer out support are retained, together with the main-branch workspace regressions. Pre-commit and four CPU wrapper-forwarding checks passed; GPU numerical validation is requested above. |
|
🚀 🚀 🚀 |
Motivation
Enable opt-in FlashAttention 4 serving for Gemma4 on Hopper GPUs.
Gemma4 combines sliding-window attention with head dimension 256 and global attention with head dimension 512. The existing SM90 FA4 implementation does not support the latter, preventing Gemma4 from using this backend.
Modifications
Accuracy Tests
Kernel correctness
Passed 2 test methods covering 14 subcases on H200
GSM8K
Evaluation configuration:
RedHatAI/gemma-4-31B-it-FP8-blocksgl-eval==0.1.2, full GSM8K test set, one passSpeed Tests and Profiling
Measured using
sglang.bench_servingwith the same model and hardware configuration as the accuracy evaluation.Common serving settings:
Benchmark settings:
max(32, 8 × concurrency).Output throughput
Median TTFT
Time to first token, in milliseconds.
Median TPOT
Time per output token, excluding the first token, in milliseconds.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): 🚫 Run #37921815088
Latest PR Test (Extra): ❌ Run #37921814430
Latest PR Test (AMD ROCm 10): ❌ Run #37921814854