Skip to content

[BugFix][MoE] Guard fused mapping edge tiles#20

Open
JayceSu98 wants to merge 1 commit into
deepseek-ai:mainfrom
JayceSu98:jayce/moe-fused-mapping-edge-tiles
Open

[BugFix][MoE] Guard fused mapping edge tiles#20
JayceSu98 wants to merge 1 commit into
deepseek-ai:mainfrom
JayceSu98:jayce/moe-fused-mapping-edge-tiles

Conversation

@JayceSu98

Copy link
Copy Markdown

Context

Full H100/CuTeDSL coverage exercises MoE routing shapes where the generated loops are rounded up to alignment or warp-size boundaries while the logical tensors keep the real token, hidden, and scaling-factor extents.

That exposed three TileKernels-side assumptions:

  • expand_to_fused wrote all lanes in hidden_aligned / hidden_sf_aligned, even when the destination tensor only has hidden / hidden_sf columns.
  • get_fused_mapping used a Select expression for the aligned tail. The inactive branch still exposed a topk_idx_1d[i] expression to lowering when i >= numel.
  • The fallback allocation estimate for num_expanded_tokens == 0 used an aligned expression that could round the per-expert alignment upper bound down.

Fix

  • Guard aligned expand_to_fused writes with the real hidden and scaling-factor extents.
  • Initialize the shared cumsum buffer for all threads before T.cumsum.
  • Replace the tail Select load with an explicit guarded load into a local expert_idx initialized to -1.
  • Reserve a rounded-up upper bound for independently aligned expert ranges before trimming with synchronized expert counts.

Why this belongs in TileKernels

The kernels intentionally schedule aligned work, but the memory operations still need to respect the logical tensor shape. These guards and allocation sizing changes make that relationship explicit and are independent of a particular CuTeDSL version.

Validation

Validated as part of the H100 PCIe CuTeDSL full correctness and benchmark run after the matching TileLang CuTeDSL fixes were applied.

Local sanity checks for this branch:

  • git diff --check origin/main..2dfff4e
  • ruff check on the changed TileKernels Python files

JayceSu98 jayce.su@enflame-tech.com authored and validated this patch.

Co-authored-by: dingsg shengge.ding@enflame-tech.com

Full H100/CuTeDSL coverage exercises MoE routing shapes where the generated work loops are rounded up to alignment or warp-size boundaries. The logical tensors remain sized by the real hidden dimension, scaling-factor dimension, and token-topk count.

The expand-to-fused kernel previously iterated over aligned hidden and scaling-factor extents and wrote every lane into the destination tensors. For tail dimensions this can address columns outside the real tensor shape, especially with TMA-aligned column-major scaling-factor layouts.

The fused mapping kernel also used a Select expression whose inactive arm could still expose an out-of-range topk_idx load to code generation, and its fallback allocation estimate rounded the per-expert alignment upper bound down to an alignment multiple.

Guard aligned expand stores with the real hidden/scaling-factor extents, initialize the shared cumsum buffer for all threads, avoid the speculative out-of-range topk load, and reserve a rounded-up per-expert alignment upper bound before trimming with the synchronized expert counts.

Co-authored-by: dingsg <shengge.ding@enflame-tech.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant