Skip to content

fix(moe): pad BF16 TRTLLM-Gen intermediates to 128 KiB - #4319

Merged
leejnau merged 5 commits into
flashinfer-ai:mainfrom
nvpohanh:fix/bf16-moe-tma-128k
Aug 10, 2026
Merged

leejnau merged 5 commits into
flashinfer-ai:mainfrom
nvpohanh:fix/bf16-moe-tma-128k

Conversation

@nvpohanh

@nvpohanh nvpohanh commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

[by Codex]

Summary

  • pad the BF16 TRTLLM-Gen MoE GEMM1 and GEMM2 intermediate allocations to at least 128 KiB
  • reuse Routing::maybeGetMinTokenCount, matching the existing FP8/MXFP launchers
  • calculate the GEMM1 and GEMM2 row counts independently because their hidden dimensions can differ

Why

On Blackwell, the TRTLLM-Gen BMM2 kernel can use TMA BASE_128KB address generation based on the logical tensor-map shape. With a small eager decode batch, the BF16 launcher currently allocates only the logical 16/32-KiB intermediate. That leaves less than 128 KiB mapped after the activation base and can produce an illegal memory access in UTMALDG.4D.

The quantized launchers already call maybeGetMinTokenCount for both intermediates. Applying the same allocation policy to the BF16 launcher gives the TMA transaction the required backing without changing the logical token count passed to routing or GEMM.

Validation

  • pre-commit run --all-files
  • B200x8 patched-JIT compile/load preflight
  • six consecutive Miles/SGLang rollout runs with the original reproducer setting:
    • pinned image and model revision
    • FlashInfer TRTLLM backend, TP8
    • four train/rollout steps per run
    • 256 one-token post-update health probes per step boundary
    • no descriptor-bit override, TMA-OOB disablement, extra allocation-padding knob, or synchronization workaround

Result: six consecutive valid passes on B200x8. Every run exited normally, completed all four steps, passed the diagnostic evidence gate, and had zero IMA/sanitizer/segfault matches.

Summary by CodeRabbit

  • Bug Fixes
    • Improved BF16 Mixture-of-Experts processing by ensuring intermediate buffers have sufficient capacity for required token mappings.
    • Increased reliability for GEMM-based operations across varying tensor dimensions while preserving expected output shapes and device placement.
    • Helps prevent capacity-related processing failures in workloads with larger or uneven token distributions.

Signed-off-by: Po-Han Huang <pohanh@nvidia.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c8d55d7c-436b-4d0a-999b-5e2842e76c15

📥 Commits

Reviewing files that changed from the base of the PR and between c8a3734 and d428307.

📒 Files selected for processing (1)
  • csrc/trtllm_fused_moe_kernel_launcher.cu
🚧 Files skipped from review as they are similar to previous changes (1)
  • csrc/trtllm_fused_moe_kernel_launcher.cu

📝 Walkthrough

Walkthrough

BF16 MoE GEMM1 and GEMM2 output buffers now use separate minimum token capacities derived from output dimensions and BF16 element size.

Changes

BF16 MoE capacity allocation

Layer / File(s) Summary
Calculate minimum buffer capacities
csrc/trtllm_fused_moe_kernel_launcher.cu
prepare_moe calls Routing::maybeGetMinTokenCount for GEMM1 and GEMM2, then allocates both BF16 buffers with the adjusted capacities.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: run-ci

Suggested reviewers: aleozlx, sricketts, yzh119

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the change, motivation, implementation, and validation results, although it does not use every template heading.
Title check ✅ Passed The title concisely identifies the BF16 TRTLLM-Gen MoE intermediate allocation padding change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nvpohanh
nvpohanh marked this pull request as ready for review August 3, 2026 05:25
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@nvpohanh

nvpohanh commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/bot run

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !1105 has been created, and the CI pipeline #60808548 is currently running. I'll report back once the pipeline job completes.

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

[FAILED] Pipeline #60808548 — 11/18 executed test jobs passed

Compared with nightly #60712014.

Unit Tests

GPU CUDA 12.9 CUDA 13.0 Notes
5090 ⚠️ Infra ⚠️ Infra Infrastructure: CI infrastructure failure (2 jobs; CUDA 12.9, CUDA 13.0)
B300 ✅ Pass ✅ Pass
GB200 ✅ Pass ❌ New New: tests.comm.test_ulysses_communicator (1 failure; CUDA 13.0)
GB300 ✅ Pass ✅ Pass
H100 ❌ New 🟡 Old New: tests.attention.test_hopper (1818 failures; CUDA 12.9)
Old: tests.gemm.test_sm_constraint_gemm (55296 failures; CUDA 12.9, CUDA 13.0)
Old: tests.gemm.test_mm_fp4 (47916 failures; CUDA 12.9, CUDA 13.0)
… and 159 more
RTX Pro 6000 Blackwell ✅ Pass ✅ Pass

✅ Pass · 🟡 Old failure · ❌ New failure · ⏱ Test timeout · ⚠️ Infrastructure · ❔ Unknown or unclassified · — Not run

Multi-GPU and Multi-Node Tests — 4/6 passed

GPU CUDA 12.9 CUDA 13.0 Notes
B300 (multi-GPU) ❔ Failed ❔ Failed
GB200 (multi-node) ✅ Pass ✅ Pass
GB300 (multi-node) ✅ Pass ✅ Pass
Failure details

New relative to nightly (attribution uncertain)

  • tests.attention.test_hopper — 1818 failures on H100 / CUDA 12.9
  • tests.comm.test_ulysses_communicator — 1 failure on GB200 / CUDA 13.0
    • failed on setup with "torch.distributed.DistNetworkError: The server socket has failed to listen on any local network address. port: 37005, useIpv6: false, code: -98, name: EADD…

Pre-existing failures

  • tests.gemm.test_sm_constraint_gemm — 55296 failures on H100 / CUDA 12.9, H100 / CUDA 13.0
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.gemm.test_mm_fp4 — 47916 failures on H100 / CUDA 12.9, H100 / CUDA 13.0
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.attention.test_rope — 30254 failures on H100 / CUDA 12.9
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.gemm.test_mm_bf16 — 15126 failures on H100 / CUDA 12.9, H100 / CUDA 13.0
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.attention.test_trtllm_gen_attention_prefill — 14804 failures on H100 / CUDA 12.9
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.attention.test_trtllm_gen_mla — 14075 failures on H100 / CUDA 12.9
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.attention.test_sliding_window — 11792 failures on H100 / CUDA 12.9
    • failed on setup with "RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program star…
  • tests.moe.test_trtllm_gen_routed_fused_moe — 7418 failures on H100 / CUDA 12.9, H100 / CUDA 13.0
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.gdn.test_prefill_delta_rule — 7088 failures on H100 / CUDA 12.9, H100 / CUDA 13.0
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.gemm.test_bmm_fp8 — 6912 failures on H100 / CUDA 12.9, H100 / CUDA 13.0
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.gemm.test_groupwise_scaled_gemm_mxfp4 — 6912 failures on H100 / CUDA 12.9, H100 / CUDA 13.0
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • tests.utils.test_norm — 5774 failures on H100 / CUDA 12.9, H100 / CUDA 13.0
    • RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the availab…
  • … and 148 more failing test groups

Timeouts, infrastructure, or incomplete jobs

@nvpohanh

nvpohanh commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

This will fix #3427

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !1105 has been updated with latest changes, and the CI pipeline #60945480 is currently running. I'll report back once the pipeline job completes.

@nvpohanh

nvpohanh commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/bot run

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !1105 has been updated with latest changes, and the CI pipeline #61135895 is currently running. I'll report back once the pipeline job completes.

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

[FAILED] Pipeline #61135895 — 8/18 executed test jobs passed

Compared with nightly #60831563.

Unit Tests

GPU CUDA 12.9 CUDA 13.0 Notes
5090 ❔ Unknown ❔ Unknown Unknown: script failed before producing a JUnit report (2 jobs; CUDA 12.9, CUDA 13.0)
B300 ❌ New ❌ New New: tests.trace.test_template_registry (2 failures; CUDA 12.9, CUDA 13.0)
Infrastructure: test infrastructure interrupted the job (2 jobs; CUDA 12.9, CUDA 13.0)
GB200 ⚠️ Infra ⚠️ Infra Infrastructure: test infrastructure interrupted the job (2 jobs; CUDA 12.9, CUDA 13.0)
GB300 ⚠️ Infra ❌ New New: tests.gemm.test_groupwise_scaled_gemm_fp8 (1 failure; CUDA 13.0)
Infrastructure: test infrastructure interrupted the job (2 jobs; CUDA 12.9, CUDA 13.0)
H100 ❌ New ❌ New New: tests.utils.test_nvfp4_per_token_quantize_large_m (8 failures; CUDA 12.9, CUDA 13.0)
New: tests.trace.test_template_registry (2 failures; CUDA 12.9, CUDA 13.0)
RTX Pro 6000 Blackwell ❌ New ❌ New New: tests.trace.test_template_registry (2 failures; CUDA 12.9, CUDA 13.0)

✅ Pass · 🟡 Old failure · ❌ New failure · ⏱ Test timeout · ⚠️ Infrastructure · ❔ Unknown or unclassified · — Not run

Multi-GPU and Multi-Node Tests — 4/6 passed

GPU CUDA 12.9 CUDA 13.0 Notes
B300 (multi-GPU) ❔ Failed ❔ Failed
GB200 (multi-node) ✅ Pass ✅ Pass
GB300 (multi-node) ✅ Pass ✅ Pass
Failure details

New relative to nightly (attribution uncertain)

  • tests.utils.test_nvfp4_per_token_quantize_large_m — 8 failures on H100 / CUDA 12.9, H100 / CUDA 13.0
    • cutlass.base_dsl.compiler.CompilerDiagnosticError: #x1B[91merror:#x1B[0m NVVM backend compilation failed #x1B[91merror:#x1B[0m libNVVM failed while compiling generated device IR…
  • tests.trace.test_template_registry — 6 failures on B300 / CUDA 12.9, B300 / CUDA 13.0, H100 / CUDA 12.9, H100 / CUDA 13.0, RTX Pro 6000 Blackwell / CUDA 12.9, RTX Pro 6000 Blackwell / CUDA 13.0
    • AssertionError: assert {'flashinfer....cat_ops', ...} == {'flashinfer....cat_ops', ...} Extra items in the right set: 'flashinfer.kda' Full diff: { 'flashinfer.activation', 'fla…
  • tests.gemm.test_groupwise_scaled_gemm_fp8 — 1 failure on GB300 / CUDA 13.0
    • AssertionError: Tensor-likes are not close! Mismatched elements: 124 / 8192 (1.5%) Greatest absolute difference: 1.71875 at index (8, 42) (up to 0.01 allowed) Greatest relative…

Timeouts, infrastructure, or incomplete jobs

@nvpohanh

nvpohanh commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

/bot run

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !1105 has been updated with latest changes, and the CI pipeline #61387766 is currently running. I'll report back once the pipeline job completes.

@aleozlx aleozlx added the run-ci label Aug 6, 2026
@aleozlx

aleozlx commented Aug 6, 2026

Copy link
Copy Markdown
Member

/bot run tests/moe

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !1105 has been created, and the CI pipeline #61461786 is currently running. I'll report back once the pipeline job completes.

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

[FAILED] Pipeline #61461786 — 14/18 executed test jobs passed

Compared with nightly #61182354.

Unit Tests

GPU CUDA 12.9 CUDA 13.0 Notes
5090 ✅ Pass ✅ Pass
B300 ✅ Pass ✅ Pass
GB200 ❔ Failed ❔ Failed
GB300 ✅ Pass ✅ Pass
H100 ✅ Pass ✅ Pass
RTX Pro 6000 Blackwell ✅ Pass ✅ Pass

✅ Pass · 🟡 Old failure · ❌ New failure · ⏱ Test timeout · ⚠️ Infrastructure · ❔ Unknown or unclassified · — Not run

Multi-GPU and Multi-Node Tests — 4/6 passed

GPU CUDA 12.9 CUDA 13.0 Notes
B300 (multi-GPU) ❔ Failed ❔ Failed
GB200 (multi-node) ✅ Pass ✅ Pass
GB300 (multi-node) ✅ Pass ✅ Pass

No individual test or infrastructure failures could be extracted.

@leejnau leejnau added run-ci and removed run-ci labels Aug 7, 2026
@b8zhong

b8zhong commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Hi, is there anything blocking the merge of this PR? It occurs during GLM 5.2 draft MoE, so ideally I'm wondering if it can be merged soon

@nvpohanh

Copy link
Copy Markdown
Contributor Author

/bot run tests/moe

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !1105 has been updated with latest changes, and the CI pipeline #61889462 is currently running. I'll report back once the pipeline job completes.

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

[SUCCESS] Pipeline #61889462: 18/18 executed test jobs passed

@leejnau
leejnau merged commit 2fb785c into flashinfer-ai:main Aug 10, 2026
28 of 37 checks passed
@henrylhtsang

Copy link
Copy Markdown

@nvpohanh dumb question why not consider the cutlass fix for tma descriptor? since it seems like it is the same issue? or am I wrong?

  if (driver_version <= 13010) {
    if (cute::bits_to_bytes(
          cute::cosize(tensor_cwhdn.layout()) *
          cute::sizeof_bits<typename EngineA::value_type>::value) < 131072) {
      reinterpret_cast<uint64_t*>(&tma_desc)[1] &= ~(1llu << 21);
    }
  }

https://github.com/NVIDIA/cutlass/blob/6c68991985ca8b09594ac6fd43abbfd5830c4140/include/cute/atom/copy_traits_sm90_im2col.hpp#L474-L483

@nvpohanh

Copy link
Copy Markdown
Contributor Author

TBH I think that fix is a little ugly 😹 And padding workspace to 128KiB should be almost harmless

@nlima-prog

Copy link
Copy Markdown

Hatch Session

This PR was worked on in a Hatch coding session.

Session 6493ed5f-d798-40ac-88c2-392844ffd43c
User nlima-prog
Environment Hatch (Local)
Agent Abacus (Local)
Sandbox local
Time 2026-08-25T16:58:07.185Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants