Repository navigation
[Kernel] Integrate FA4 SM90 FP8 MMA for Gemma-4 full attention #60372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vllm-bot
merged 26 commits into
vllm-project:main
from
katec846:fa4-fp8mma-draft-20261007
Nov 5, 2026
Merged
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a962321
[Attention] Integrate SM90 d512 FP8 MMA with vLLM routing
0530c91
[Test] Supply parallel config for SM90 attention fixtures
d20b103
[Test] Narrow FP8 rejection reason for mypy
katec846 5fc01d3
[Attention] Consolidate SM90 FP8 wrapper dispatch flags
katec846 7ea8800
[Attention] Guard unvalidated SM90 FP8 noncausal full attention
katec846 b283eac
[Review] Trim SM90 FP8 selector tests and comments
katec846 e9344ed
[Review] Remove redundant Diff-KV probe cache check
katec846 fc937f5
[Review] Remove remaining added attention tests
katec846 847cee6
[Review] Clarify FP8 MMA comments and noncausal error
katec846 ac73cba
[Review] Simplify SM90 FP8 guards and error messages
katec846 6c178bc
[Attention] Remove the unreachable FA4 -> FA3 FP8 fallback on SM90
simon-veitner-redhat f116077
[Attention] Reject DCP with FA4 SM90 FP8 KV at impl init
simon-veitner-redhat d0d39b0
[Test] Cover FA4 SM90 FP8 MMA routing in a CPU selector test
simon-veitner-redhat 9fe5c82
[CI] Add Hopper GSM8K eval for Gemma-4 with FP8 KV (FA4 SM90 FP8 MMA)
simon-veitner-redhat 237043e
Update SM90 FP8 MMA FlashAttention review fixes
katec846 3a01ead
Pin merged FlashAttention SM90 FP8 MMA commit
katec846 0ffdc07
Merge branch 'main' into fa4-fp8mma-draft-20261007
MatthewBonanni 501e7e3
Skip SM90 FP8 MMA selection test without CUDA FA extensions
MatthewBonanni f2d8259
Merge remote-tracking branch 'upstream-main-now' into fix-60372-ci
MatthewBonanni 78e295c
Merge branch 'main' into fa4-fp8mma-draft-20261007
DarkLight1337 cf3b814
[Test] Remove obsolete input dtype from Zen MoE conversion test
katec846 feba607
Merge branch 'main' into fa4-fp8mma-draft-20261007
DarkLight1337 419626d
Move Gemma-4 FP8 KV eval into the H100 large-model nightly
MatthewBonanni 7894b61
Set Gemma-4 FP8 KV GSM8K reference to the measured 0.937
MatthewBonanni f2e9e8f
Merge branch 'main' into fa4-fp8mma-draft-20261007
MatthewBonanni 7928f5f
Merge branch 'main' into fa4-fp8mma-draft-20261007
MatthewBonanni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
17 changes: 17 additions & 0 deletions
17
tests/evals/gsm8k/configs/gemma-4-31B-it-FP8-dynamic-fp8kv-TP2.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Gemma-4 full-attention layers (head_size=512) with an FP8 KV cache take the | ||
| # FA4 SM90 FP8 MMA path on Hopper; the sliding-window layers use FA3 FP8. | ||
| # The hf-override makes the model text-only. Without it Gemma-4 is an | ||
| # mm-prefix LM, which FLASH_ATTN does not support with FP8 KV on SM90. | ||
| model_name: "RedHatAI/gemma-4-31B-it-FP8-dynamic" | ||
| # Measured 0.970 on 2x H200 with this harness and FA PR 199. | ||
| accuracy_threshold: 0.96 | ||
| num_questions: 1319 | ||
| num_fewshot: 5 | ||
| use_chat_completions: true | ||
| max_tokens: 512 | ||
| server_args: >- | ||
| --tensor-parallel-size 2 | ||
| --max-model-len 4096 | ||
| --kv-cache-dtype fp8 | ||
| --attention-backend FLASH_ATTN | ||
| --hf-overrides '{"text_config":{"use_bidirectional_attention":null}}' |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| gemma-4-31B-it-FP8-dynamic-fp8kv-TP2.yaml |
179 changes: 179 additions & 0 deletions
179
tests/v1/attention/test_flash_attn_sm90_fp8_mma_selection.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Routing of the FA4 SM90 FP8 MMA path (head_size=512 with an FP8 KV cache). | ||
|
|
||
| The device capability is mocked, so no GPU is needed. | ||
| """ | ||
|
|
||
| from contextlib import contextmanager | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from vllm.platforms.interface import DeviceCapability | ||
|
|
||
| fa_interface = pytest.importorskip("vllm.vllm_flash_attn.flash_attn_interface") | ||
|
|
||
| from vllm.v1.attention.backends.fa_utils import get_flash_attn_version # noqa: E402 | ||
| from vllm.v1.attention.backends.flash_attn import ( # noqa: E402 | ||
| FlashAttentionBackend, | ||
| FlashAttentionImpl, | ||
| ) | ||
|
|
||
| SM80 = DeviceCapability(8, 0) | ||
| SM90 = DeviceCapability(9, 0) | ||
| SM100 = DeviceCapability(10, 0) | ||
|
|
||
|
|
||
| @contextmanager | ||
| def _device(capability, *, head_size, kv_cache_dtype, fa_version=None, dcp=1): | ||
| platform = MagicMock() | ||
| platform.is_xpu.return_value = False | ||
| platform.is_rocm.return_value = False | ||
| platform.is_cuda.return_value = True | ||
| platform.get_device_capability.return_value = capability | ||
| platform.is_device_capability_family.side_effect = ( | ||
| lambda family, device_id=0: capability.to_int() // 10 == family // 10 | ||
| ) | ||
| config = MagicMock() | ||
| config.attention_config.flash_attn_version = fa_version | ||
| config.model_config.is_diffusion = False | ||
| config.model_config.get_head_size.return_value = head_size | ||
| config.cache_config.cache_dtype = kv_cache_dtype | ||
| config.parallel_config.decode_context_parallel_size = dcp | ||
| config.parallel_config.dcp_comm_backend = "ag_rs" | ||
| backends = "vllm.v1.attention.backends" | ||
| with ( | ||
| patch(f"{backends}.fa_utils.current_platform", platform), | ||
| patch(f"{backends}.flash_attn.current_platform", platform), | ||
| patch.object(fa_interface, "is_fa_version_supported", return_value=True), | ||
| patch("vllm.config.get_current_vllm_config_or_none", return_value=config), | ||
| patch( | ||
| f"{backends}.flash_attn.get_current_vllm_config_or_none", | ||
| return_value=config, | ||
| ), | ||
| patch( | ||
| "vllm.distributed.parallel_state.get_dcp_world_size_and_rank", | ||
| return_value=(dcp, 0), | ||
| ), | ||
| ): | ||
| yield | ||
|
|
||
|
|
||
| def _supports_combination(capability, head_size, kv_cache_dtype, block_size=64): | ||
| return FlashAttentionBackend.supports_combination( | ||
| head_size=head_size, | ||
| dtype=torch.bfloat16, | ||
| kv_cache_dtype=kv_cache_dtype, | ||
| block_size=block_size, | ||
| use_mla=False, | ||
| has_sink=False, | ||
| use_sparse=False, | ||
| use_mm_prefix=False, | ||
| device_capability=capability, | ||
| ) | ||
|
|
||
|
|
||
| def _impl(head_size, kv_cache_dtype): | ||
| return FlashAttentionImpl( | ||
| num_heads=8, | ||
| head_size=head_size, | ||
| scale=head_size**-0.5, | ||
| num_kv_heads=1, | ||
| alibi_slopes=None, | ||
| sliding_window=None, | ||
| kv_cache_dtype=kv_cache_dtype, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "head_size,kv_cache_dtype,fa_version,sm90_fp8_mma", | ||
| [ | ||
| (512, "fp8", 4, True), | ||
| (512, "fp8_e4m3", 4, True), | ||
| # Gemma-4 sliding-window layers stay on FA3 FP8 with an FP8 query. | ||
| (256, "fp8", 3, False), | ||
| (512, "auto", 4, False), | ||
| ], | ||
| ) | ||
| def test_sm90_routing(head_size, kv_cache_dtype, fa_version, sm90_fp8_mma): | ||
| with _device(SM90, head_size=head_size, kv_cache_dtype=kv_cache_dtype): | ||
| assert get_flash_attn_version(head_size=head_size) == fa_version | ||
| assert _supports_combination(SM90, head_size, kv_cache_dtype) is None | ||
| impl = _impl(head_size, kv_cache_dtype) | ||
| assert impl.vllm_flash_attn_version == fa_version | ||
| # The FP8 MMA kernel quantizes Q in-kernel, so vLLM must not quantize it. | ||
| assert impl.supports_quant_query_input is not sm90_fp8_mma | ||
|
|
||
|
|
||
| def test_sm90_fp8_mma_block_size(): | ||
| with _device(SM90, head_size=512, kv_cache_dtype="fp8"): | ||
| assert FlashAttentionBackend.get_supported_kernel_block_sizes() == [64] | ||
| assert "block size" in _supports_combination(SM90, 512, "fp8", 16) | ||
| with _device(SM90, head_size=512, kv_cache_dtype="auto"): | ||
| assert _supports_combination(SM90, 512, "auto", 16) is None | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "capability,head_size,fa_version", | ||
| [ | ||
| (SM90, 256, 4), # forced FA4 with an FP8 KV cache needs head_size=512 | ||
| (SM100, 512, None), # FA4 on Blackwell does not support head_size=512 | ||
| (SM80, 512, None), # FA2 has no FP8 KV cache | ||
| ], | ||
| ) | ||
| def test_fp8_kv_rejected(capability, head_size, fa_version): | ||
| with _device( | ||
| capability, head_size=head_size, kv_cache_dtype="fp8", fa_version=fa_version | ||
| ): | ||
| assert _supports_combination(capability, head_size, "fp8") is not None | ||
| with pytest.raises(NotImplementedError, match="fp8 kv-cache"): | ||
| _impl(head_size, "fp8") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "head_size,kv_cache_dtype,rejected", | ||
| [(512, "fp8", True), (512, "auto", False), (256, "fp8", False)], | ||
| ) | ||
| def test_sm90_fp8_mma_rejects_dcp(head_size, kv_cache_dtype, rejected): | ||
| with _device(SM90, head_size=head_size, kv_cache_dtype=kv_cache_dtype, dcp=2): | ||
| if rejected: | ||
| with pytest.raises(NotImplementedError, match="context parallelism"): | ||
| _impl(head_size, kv_cache_dtype) | ||
| else: | ||
| assert _impl(head_size, kv_cache_dtype).dcp_world_size == 2 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "head_size,q_dtype,causal,match", | ||
| [ | ||
| # FA4 + FP8 KV below d512 raises; no silent switch to FA3. | ||
| (256, torch.float8_e4m3fn, True, "q=torch.float8_e4m3fn/256"), | ||
| (128, torch.float8_e4m3fn, False, "head_size=512"), | ||
| (256, torch.bfloat16, True, "q=torch.bfloat16/256"), | ||
| (512, torch.bfloat16, False, "noncausal"), | ||
| ], | ||
| ) | ||
| def test_wrapper_rejects_unsupported_sm90_fp8(head_size, q_dtype, causal, match): | ||
| q = torch.zeros(4, 8, head_size, dtype=q_dtype) | ||
| k = torch.zeros(1, 64, 1, head_size, dtype=torch.float8_e4m3fn) | ||
| fa3 = MagicMock() | ||
| with ( | ||
| patch("torch.cuda.get_device_capability", return_value=(9, 0)), | ||
| patch.object(torch.ops, "_vllm_fa3_C", fa3, create=True), | ||
| pytest.raises(NotImplementedError, match=match), | ||
| ): | ||
| fa_interface.flash_attn_varlen_func( | ||
| q, | ||
| k, | ||
| k, | ||
| max_seqlen_q=4, | ||
| cu_seqlens_q=torch.tensor([0, 4], dtype=torch.int32), | ||
| max_seqlen_k=4, | ||
| seqused_k=torch.tensor([4], dtype=torch.int32), | ||
| block_table=torch.zeros(1, 1, dtype=torch.int32), | ||
| causal=causal, | ||
| fa_version=4, | ||
| ) | ||
| fa3.fwd.assert_not_called() |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this restriction needs to be stricken? or it's just missing from previous PR.
Will removing this change breaks Gemma4 + FP8 KV + FP8 MMA for hd 512?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check was missing from the previous vLLM integration. PR164 already requires equal K/V head dimensions, but the vLLM support check only checked the Q/K dimension.
Removing this addition would not break Gemma-4 with FP8 KV + FP8 MMA, since its full-attention Q/K/V dimensions are all 512. It would, however, allow unsupported Diff-KV shapes through backend selection.