Skip to content

[https://nvbugs/6108841][fix] add hidden_dim=6144 router GEMM instantiation for GLM-5 - #13740

Merged
yijingl-nvidia merged 4 commits into
NVIDIA:mainfrom
yijingl-nvidia:fix_ampere_fallback
May 14, 2026
Merged

[https://nvbugs/6108841][fix] add hidden_dim=6144 router GEMM instantiation for GLM-5#13740
yijingl-nvidia merged 4 commits into
NVIDIA:mainfrom
yijingl-nvidia:fix_ampere_fallback

Conversation

@yijingl-nvidia

@yijingl-nvidia yijingl-nvidia commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Description

GLM-5 has hidden_size=6144 with 256 MoE experts, but the dsv3_router_gemm custom kernel only had compile-time instantiations for hidden_dim=7168 (DeepSeek-V3). On Blackwell this caused the routing GEMM to fall through to cublas_mm_out, which dispatched BF16xBF16->FP32 to cutlass_80_simt_sgemm_64x64_8x5_tn_align1 (Ampere SIMT, no tensor cores) — ~5.4% / ~1 ms per decode iter on GLM-5 FP8 MTP=3 BS=1 ISL=1K B200 TP=8.

The router_gemm_kernel template is generic over kHiddenDim as long as kHiddenDim is divisible by VPT*kBlockSize = 1024. 6144/1024 = 6 iterations, so adding the 16 num_token instantiations is sufficient.

dsv3_router_gemm_op now dispatches between K=7168 and K=6144 paths; unsupported shapes still fall back to cublas_mm_out.

Test Coverage

Test coverage extended to hidden_size in {7168, 6144}.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

Summary by CodeRabbit

  • New Features

    • Router GEMM kernel now supports additional configuration options for improved model inference flexibility.
  • Tests

    • Expanded test coverage for router GEMM operations across multiple configurations.

@yijingl-nvidia yijingl-nvidia changed the title [6108841][fix] add hidden_dim=6144 router GEMM instantiation for GLM-5 [https://nvbugs/6108841][fix] add hidden_dim=6144 router GEMM instantiation for GLM-5 May 4, 2026
@yijingl-nvidia
yijingl-nvidia requested a review from 2ez4bz May 4, 2026 22:31
@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR extends the DeepSeek V3 router GEMM operation to support an additional hidden dimension value of 6144 alongside the existing 7168. The change introduces explicit kernel template instantiations for the new dimension and updates the operator dispatch logic to conditionally select the appropriate kernel variant based on input hidden dimension.

Changes

Router GEMM Hidden Dimension Support

Layer / File(s) Summary
Kernel Compilation Variants
cpp/tensorrt_llm/kernels/dsv3MinLatencyKernels/dsv3RouterGemm.cu
Explicit template instantiations of invokeRouterGemm<__nv_bfloat16, N, 256, 6144> are added for token counts N=1 through 16, complementing the existing 7168 variants.
Operator Dispatch Logic
cpp/tensorrt_llm/thop/dsv3RouterGemmOp.cpp
Two kHiddenDim constants (7168 and 6144) replace a single constant. A shared shape_ok validation gate checks token range (1–16), expert count, bf16 input, and fp32 output. Two conditional branches dispatch to LoopUnroller<..., kHiddenDim7168> or LoopUnroller<..., kHiddenDim6144> based on matched hidden dimension; fallback to cublas_mm_out when conditions are unmet.
Test Coverage
tests/unittest/_torch/thop/parallel/test_dsv3_router_gemm.py
Test parameters expanded to include hidden_size = 6144 alongside the existing 7168 value.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a hidden_dim=6144 router GEMM instantiation for GLM-5 support, with proper ticket reference and type annotation.
Description check ✅ Passed The PR description comprehensively explains the problem (GLM-5 performance regression), the solution (adding 6144 instantiation), test coverage (extended to both 7168 and 6144), and addresses the PR checklist items.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
cpp/tensorrt_llm/thop/dsv3RouterGemmOp.cpp (1)

1-3: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Update the NVIDIA copyright header year in this modified file.

The header still ends at 2024, but this file is modified in this PR.

📝 Suggested header update
- * SPDX-FileCopyrightText: Copyright (c) 1993-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright (c) 1993-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

As per coding guidelines: "Include NVIDIA copyright header on all new files; update year on modified files."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tensorrt_llm/thop/dsv3RouterGemmOp.cpp` around lines 1 - 3, Update the
file header year range in the SPDX copyright block to include 2025 (or the
current year) since this file was modified; locate the top-of-file comment
containing "SPDX-FileCopyrightText" and the "SPDX-License-Identifier" lines in
dsv3RouterGemmOp.cpp and change the trailing year from 2024 to the current year
so the header reflects the modification.
cpp/tensorrt_llm/kernels/dsv3MinLatencyKernels/dsv3RouterGemm.cu (1)

1-3: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Update the copyright year in this modified CUDA file.

The header currently ends at 2023, but this file is modified in this PR.

📝 Suggested header update
- * Copyright (c) 2019-2023, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2019-2026, NVIDIA CORPORATION.  All rights reserved.

As per coding guidelines: "Include NVIDIA copyright header on all new files; update year on modified files."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tensorrt_llm/kernels/dsv3MinLatencyKernels/dsv3RouterGemm.cu` around
lines 1 - 3, Update the copyright header line that currently reads "Copyright
(c) 2019-2023, NVIDIA CORPORATION." to include the current modification year
(e.g., "Copyright (c) 2019-2026, NVIDIA CORPORATION.") so the header reflects
this PR's changes; locate the header comment containing that exact string at the
top of dsv3RouterGemm.cu and modify the end year accordingly.
🧹 Nitpick comments (1)
tests/unittest/_torch/thop/parallel/test_dsv3_router_gemm.py (1)

13-13: ⚡ Quick win

Add one unsupported-hidden-size case to validate fallback dispatch.

This matrix now covers both supported custom-kernel shapes, which is great. Please add one unsupported hidden_size (for example, 4096) so this test also exercises the fallback path and catches future dispatch regressions.

✅ Minimal test matrix extension
-@pytest.mark.parametrize("hidden_size", [7168, 6144])
+@pytest.mark.parametrize("hidden_size", [7168, 6144, 4096])

Also, because this PR only touches unittest scope, QA integration test-list updates are unnecessary here.

As per coding guidelines: "Assess whether new/changed tests cover happy path, important edge cases, and failure modes relevant to the feature or fix."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/_torch/thop/parallel/test_dsv3_router_gemm.py` at line 13, The
parametrize matrix in
tests/unittest/_torch/thop/parallel/test_dsv3_router_gemm.py only covers
supported hidden sizes and misses an unsupported case to exercise the fallback
dispatch; update the pytest.mark.parametrize("hidden_size", ...) invocation (in
test_dsv3_router_gemm.py) to include an unsupported hidden size such as 4096 so
the test matrix contains [7168, 6144, 4096], thereby exercising the fallback
path and catching dispatch regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/tensorrt_llm/kernels/dsv3MinLatencyKernels/dsv3RouterGemm.cu`:
- Around line 245-292: The PR added new explicit instantiations for
invokeRouterGemm<__nv_bfloat16, N, 256, 6144> (N=1..16) but lacks
perf-regression coverage for the 6144 hidden_dim path; update tests to include a
perf case exercising the new 6144 router-GEMM dispatch: add or modify a perf
test in tests/integration/defs/perf/test_perf_sanity.py to run a
small-but-representative workload that triggers invokeRouterGemm with
hidden_dim=6144 (matching the instantiated templates), then add this test to the
authoritative CI perf list tests/integration/test_lists/test-db/l0_perf.yml and
the corresponding QA perf list(s) under
tests/integration/test_lists/qa/llm_perf_*.yml so CI will catch regressions for
the new 6144 path. Ensure the test references the same configuration (data type
__nv_bfloat16 and block sizes) used by the template instantiations so the 6144
dispatch is exercised during perf runs.

In `@cpp/tensorrt_llm/thop/dsv3RouterGemmOp.cpp`:
- Around line 89-103: shape_ok currently misses validating the inner dimension
of mat_b, so LoopUnroller::unroll may be dispatched with a compile-time K that
doesn't match mat_b; update the dispatch guard to also verify mat_b.sizes()[0]
== hidden_dim (or equivalent runtime check) before calling LoopUnroller for the
kHiddenDim7168 and kHiddenDim6144 paths (i.e. augment shape_ok or add an extra
condition using hidden_dim and mat_b.sizes()[0] prior to the
LoopUnroller<...>::unroll calls to prevent malformed inputs from reaching the
custom kernel).

---

Outside diff comments:
In `@cpp/tensorrt_llm/kernels/dsv3MinLatencyKernels/dsv3RouterGemm.cu`:
- Around line 1-3: Update the copyright header line that currently reads
"Copyright (c) 2019-2023, NVIDIA CORPORATION." to include the current
modification year (e.g., "Copyright (c) 2019-2026, NVIDIA CORPORATION.") so the
header reflects this PR's changes; locate the header comment containing that
exact string at the top of dsv3RouterGemm.cu and modify the end year
accordingly.

In `@cpp/tensorrt_llm/thop/dsv3RouterGemmOp.cpp`:
- Around line 1-3: Update the file header year range in the SPDX copyright block
to include 2025 (or the current year) since this file was modified; locate the
top-of-file comment containing "SPDX-FileCopyrightText" and the
"SPDX-License-Identifier" lines in dsv3RouterGemmOp.cpp and change the trailing
year from 2024 to the current year so the header reflects the modification.

---

Nitpick comments:
In `@tests/unittest/_torch/thop/parallel/test_dsv3_router_gemm.py`:
- Line 13: The parametrize matrix in
tests/unittest/_torch/thop/parallel/test_dsv3_router_gemm.py only covers
supported hidden sizes and misses an unsupported case to exercise the fallback
dispatch; update the pytest.mark.parametrize("hidden_size", ...) invocation (in
test_dsv3_router_gemm.py) to include an unsupported hidden size such as 4096 so
the test matrix contains [7168, 6144, 4096], thereby exercising the fallback
path and catching dispatch regressions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8e030565-df06-4a65-853f-7fe7f9a7ae7b

📥 Commits

Reviewing files that changed from the base of the PR and between e527a9f and a531a36.

📒 Files selected for processing (3)
  • cpp/tensorrt_llm/kernels/dsv3MinLatencyKernels/dsv3RouterGemm.cu
  • cpp/tensorrt_llm/thop/dsv3RouterGemmOp.cpp
  • tests/unittest/_torch/thop/parallel/test_dsv3_router_gemm.py

Comment thread cpp/tensorrt_llm/kernels/dsv3MinLatencyKernels/dsv3RouterGemm.cu
Comment thread cpp/tensorrt_llm/thop/dsv3RouterGemmOp.cpp
@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

Coderabbit suggested accuracy tests on new kernel dimension range. Will work on that later

@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

Ran GLM-5 QA tests on nsc-svg, no significant regression

@yijingl-nvidia
yijingl-nvidia force-pushed the fix_ampere_fallback branch 2 times, most recently from f226b9a to 301fe88 Compare May 9, 2026 07:00
@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47488 [ run ] triggered by Bot. Commit: 301fe88 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47488 [ run ] completed with state SUCCESS. Commit: 301fe88
/LLM/main/L0_MergeRequest_PR pipeline #37408 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

GLM-5 has hidden_size=6144 with 256 MoE experts, but the
dsv3_router_gemm custom kernel only had compile-time instantiations
for hidden_dim=7168 (DeepSeek-V3). On Blackwell this caused the
routing GEMM to fall through to cublas_mm_out, which dispatched
BF16xBF16->FP32 to cutlass_80_simt_sgemm_64x64_8x5_tn_align1
(Ampere SIMT, no tensor cores) — ~5.4% / ~1 ms per decode iter
on GLM-5 FP8 MTP=3 BS=1 ISL=1K B200 TP=8.

The router_gemm_kernel template is generic over kHiddenDim as long
as kHiddenDim is divisible by VPT*kBlockSize = 1024. 6144/1024 = 6
iterations, so adding the 16 num_token instantiations is sufficient.

dsv3_router_gemm_op now dispatches between K=7168 and K=6144 paths;
unsupported shapes still fall back to cublas_mm_out.

Test coverage extended to hidden_size in {7168, 6144}.

Refs: nvbug 6108841 — TRT-LLM vs TileRT GLM-5 perf gap, target NVIDIA#4
in COMPARISON_TRTLLM_VS_TILERT.md (cutlass_80_simt_sgemm Ampere
fallback).

Signed-off-by: Yijing Li <257409031+yijingl-nvidia@users.noreply.github.com>
Signed-off-by: Yijing Li <257409031+yijingl-nvidia@users.noreply.github.com>
Signed-off-by: Yijing Li <257409031+yijingl-nvidia@users.noreply.github.com>
Signed-off-by: Yijing Li <257409031+yijingl-nvidia@users.noreply.github.com>
@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47554 [ run ] triggered by Bot. Commit: 4990d77 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47554 [ run ] completed with state SUCCESS. Commit: 4990d77
/LLM/main/L0_MergeRequest_PR pipeline #37467 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@yijingl-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47602 [ run ] triggered by Bot. Commit: 4990d77 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47602 [ run ] completed with state SUCCESS. Commit: 4990d77
/LLM/main/L0_MergeRequest_PR pipeline #37508 completed with status: 'SUCCESS'

CI Report

Link to invocation

@yijingl-nvidia
yijingl-nvidia requested review from a team, byshiue and dongxuy04 and removed request for a team May 11, 2026 16:54
@yijingl-nvidia
yijingl-nvidia merged commit 7d2bed7 into NVIDIA:main May 14, 2026
6 checks passed
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.

3 participants