-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(moe): handle CuTe DSL finalize output tails #4186
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef255f2
fix(moe): reject CuteDSL MoE tactics whose N-tiling overruns the outp…
YangXu1990uiuc 7d80fc6
fix(moe): simplify the no-valid-tactics path per review
YangXu1990uiuc 16d9e82
fix(moe): handle finalize output tails
S1ro1 6b02424
Improve warning message for invalid tactics in tuner
aleozlx 2dbbd90
Merge branch 'fix-3957-cluster-padding' into fix/cutedsl-moe-tail-store
S1ro1 72a5113
Merge branch 'main' into fix/cutedsl-moe-tail-store
S1ro1 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| """Directed host-side checks for the gh #3957 N-tail handling. | ||
|
|
||
| The finalize epilogue limits its bulk transfer to the remaining output columns, | ||
| including for cluster-padding CTAs. The gemm1 SFC store is still unpredicated, | ||
| so only gemm1 must reject configurations that leave a partial N tile. These are | ||
| pure classmethod checks -- no GPU work. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| cutlass = pytest.importorskip("cutlass") | ||
|
|
||
| from flashinfer.fused_moe.cute_dsl.blackwell.blockscaled_contiguous_gather_grouped_gemm_act_fusion import ( # noqa: E501 | ||
| BlockScaledContiguousGatherGroupedGemmKernel, | ||
| ) | ||
| from flashinfer.fused_moe.cute_dsl.blackwell.blockscaled_contiguous_grouped_gemm_finalize_fusion import ( # noqa: E501 | ||
| Sm100BlockScaledContiguousGroupedGemmFinalizeFusionKernel, | ||
| ) | ||
|
|
||
|
|
||
| def _finalize_ok(n, mma_tiler_mn, cluster_shape_mn): | ||
| return Sm100BlockScaledContiguousGroupedGemmFinalizeFusionKernel.can_implement( | ||
| ab_dtype=cutlass.Float4E2M1FN, | ||
| sf_dtype=cutlass.Float8E4M3FN, | ||
| sf_vec_size=16, | ||
| out_dtype=cutlass.BFloat16, | ||
| final_scale_dtype=cutlass.Float32, | ||
| mma_tiler_mn=mma_tiler_mn, | ||
| cluster_shape_mn=cluster_shape_mn, | ||
| m=1024, | ||
| n=n, | ||
| k=512, | ||
| l=8, | ||
| a_major="k", | ||
| b_major="k", | ||
| out_major="n", | ||
| ) | ||
|
|
||
|
|
||
| def _gemm1_ok(n, mma_tiler_mn, cluster_shape_mn): | ||
| return BlockScaledContiguousGatherGroupedGemmKernel.can_implement( | ||
| ab_dtype=cutlass.Float4E2M1FN, | ||
| sf_dtype=cutlass.Float8E4M3FN, | ||
| sf_vec_size=16, | ||
| c_dtype=cutlass.Float4E2M1FN, | ||
| mma_tiler_mn=mma_tiler_mn, | ||
| cluster_shape_mn=cluster_shape_mn, | ||
| m=1024, | ||
| n=n, | ||
| k=512, | ||
| l=8, | ||
| a_major="k", | ||
| b_major="k", | ||
| c_major="n", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "n,mma,cluster,expect", | ||
| [ | ||
| # A padding CTA has no remaining columns and skips its row transfer. | ||
| (256, (128, 256), (1, 2), True), | ||
| # 2 exact tiles / cluster_n=2 -> exact cluster tiling: fine. | ||
| (512, (128, 256), (1, 2), True), | ||
| # A partial tile transfers only columns 256..383. | ||
| (384, (128, 256), (1, 2), True), | ||
| # The same tail handling applies without an N cluster. | ||
| (384, (128, 256), (1, 1), True), | ||
| # 3 exact 128-tiles, no cluster: fine. | ||
| (384, (128, 128), (1, 1), True), | ||
| ], | ||
| ) | ||
| def test_finalize_n_tiling(n, mma, cluster, expect): | ||
| assert _finalize_ok(n, mma, cluster) is expect | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "n,mma,expect", | ||
| [ | ||
| # The scale-factor store requires exact tiling under mma_n=256. | ||
| (384, (128, 256), False), | ||
| # Exact tiling: fine. | ||
| (512, (128, 256), True), | ||
| (384, (128, 128), True), | ||
| ], | ||
| ) | ||
| def test_gemm1_n_tiling_guard(n, mma, expect): | ||
| # gemm1 requires cluster_n == 1 (enforced independently). | ||
| assert _gemm1_ok(n, mma, (1, 1)) is expect |
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
Correct the no-valid-tactics warning.
get_valid_tacticsreturns an empty list. It does not fall back toDEFAULT_MOE_TACTIC. The warning at Line 545 reports the opposite behavior. This can mislead users during autotuning failures.Proposed fix
logger.warning( "No valid tactics found for problem dims " "(tokens=%d, hidden=%d, intermediate=%d, experts=%d, top_k=%d). " - "Falling back to default tactic.", + "Returning no tactics.",As per coding guidelines, keep documentation synchronized with code changes.
🤖 Prompt for AI Agents
Source: Coding guidelines