Repository navigation
[https://nvbugs/6641122][fix] Bump CUTLASS DSL to 4.6.2 to unblock FA4 split-KV #18290
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
Closed
Closed
Changes from all commits
Commits
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Numerical parity for FlashAttn4's sm100 split-KV kernel. | ||
|
|
||
| FlashAttn4Attention passes ``num_splits=0``, so FA4's heuristic picks the split | ||
| count and any count above 1 selects a separate split-KV kernel. That kernel is | ||
| compiled by the CuTe DSL at first use, so a DSL that rejects it takes down every | ||
| FA4 config at pipeline load rather than at import. The other FA4 tests use K/V | ||
| short enough that the heuristic returns 1 (it short-circuits at | ||
| ``num_n_blocks <= 4``), leaving the split-KV kernel uncovered; the K/V length | ||
| here is what reaches it. | ||
|
|
||
| Requires CUDA (FA4 is GPU-only). | ||
| """ | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| try: | ||
| from tensorrt_llm._torch.visual_gen.attention_backend.flash_attn4 import _flash_attn_fwd | ||
|
|
||
| FA4_AVAILABLE = _flash_attn_fwd is not None | ||
| except ImportError: | ||
| FA4_AVAILABLE = False | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.skipif(not torch.cuda.is_available(), reason="FA4 requires CUDA"), | ||
| pytest.mark.skipif(not FA4_AVAILABLE, reason="FA4 kernel not available"), | ||
| ] | ||
|
|
||
| # S_kv must stay well above FA4's `num_n_blocks <= 4` short-circuit for the | ||
| # `auto` case to reach the split-KV kernel; the short S_q keeps occupancy low | ||
| # enough that the heuristic prefers splitting, which is the LTX-2 cross-attn shape. | ||
| B, S_Q, S_KV, H, D = 1, 64, 4096, 8, 128 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("num_splits", [0, 8], ids=["auto", "forced"]) | ||
| def test_split_kv_matches_sdpa(num_splits): | ||
| """FA4 split-KV output matches SDPA. Fails to compile on CUTLASS DSL < 4.6.2.""" | ||
| torch.manual_seed(0) | ||
| device = "cuda" | ||
| q, k, v = ( | ||
| torch.randn(B, s, H, D, dtype=torch.bfloat16, device=device) for s in (S_Q, S_KV, S_KV) | ||
| ) | ||
|
|
||
| out, _, *_ = _flash_attn_fwd( | ||
| q, | ||
| k, | ||
| v, | ||
| seqused_k=None, | ||
| softmax_scale=D**-0.5, | ||
| causal=False, | ||
| window_size_left=None, | ||
| window_size_right=None, | ||
| learnable_sink=None, | ||
| softcap=0.0, | ||
| pack_gqa=None, | ||
| mask_mod=None, | ||
| block_sparse_tensors=None, | ||
| return_lse=True, | ||
| num_splits=num_splits, | ||
| ) | ||
|
|
||
| # SDPA wants [B, H, S, D]; FA4 uses [B, S, H, D]. | ||
| ref = torch.nn.functional.scaled_dot_product_attention( | ||
| q.transpose(1, 2), k.transpose(1, 2), v.transpose(1, 2) | ||
| ).transpose(1, 2) | ||
|
|
||
| torch.testing.assert_close( | ||
| out, | ||
| ref, | ||
| rtol=2e-2, | ||
| atol=2e-2, | ||
| msg=f"FA4 num_splits={num_splits} diverges from SDPA", | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main([__file__, "-v"]) | ||
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add annotations to
test_split_kv_matches_sdpa.Annotate
num_splitsand theNonereturn value.Test coverage summary:
test_split_kv_matches_sdpa.tests/integration/test_lists/test-db/l0_b200.ymlincludes this test file.As per coding guidelines, “Annotate every function.”
Proposed fix
`@pytest.mark.parametrize`("num_splits", [0, 8], ids=["auto", "forced"]) -def test_split_kv_matches_sdpa(num_splits): +def test_split_kv_matches_sdpa(num_splits: int) -> None:📝 Committable suggestion
🤖 Prompt for AI Agents
Sources: Coding guidelines, Path instructions