KEMBAR78
feat: Add support for benchmarking individual gemms in MOE benchmark by djns99 · Pull Request #6080 · NVIDIA/TensorRT-LLM · GitHub
Skip to content

Conversation

@djns99
Copy link
Collaborator

@djns99 djns99 commented Jul 16, 2025

Summary by CodeRabbit

  • New Features

    • Added the ability to profile individual GEMM operations or the full Mixture of Experts (MoE) layer in backend benchmarks.
    • Introduced a new benchmark parameter to select which GEMM to profile.
    • Enhanced benchmark configuration with dynamic parameter generation and additional profiling options.
  • Bug Fixes

    • Corrected calculation for the number of experts per node in GEMM profiling.
  • Documentation

    • Added cautionary disclaimers to benchmark documentation and help output, advising users about the intended use and quality standards of the benchmarks.
  • Chores

    • Disabled float32 benchmarks and updated help text to reflect supported data types.

@djns99 djns99 force-pushed the user/djns99/benchmark_individual_gemms branch 7 times, most recently from e79ba96 to d723c5c Compare July 16, 2025 04:57
@djns99 djns99 requested a review from hyukn July 16, 2025 05:21
@djns99 djns99 force-pushed the user/djns99/benchmark_individual_gemms branch from d723c5c to 9b53b24 Compare July 16, 2025 05:22
@djns99 djns99 requested review from Tracin and hlu1 July 16, 2025 05:27
@djns99
Copy link
Collaborator Author

djns99 commented Jul 16, 2025

/bot run

@djns99 djns99 requested a review from zongfeijing July 16, 2025 05:30
@tensorrt-cicd
Copy link
Collaborator

PR_Github #12026 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12026 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #8930 completed with status: 'FAILURE'

Signed-off-by: Daniel Stokes <40156487+djns99@users.noreply.github.com>
@djns99 djns99 force-pushed the user/djns99/benchmark_individual_gemms branch from 9b53b24 to 98a9407 Compare July 16, 2025 22:04
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Walkthrough

The updates introduce a new profiling mode for the Mixture of Experts (MoE) backend benchmark, allowing selective profiling of individual GEMM operations or the full layer. The benchmark configuration generation script and fixture are refactored to support this, with new parameters, buffer management, and tactic selection logic. Documentation and help text are updated with cautionary disclaimers.

Changes

File(s) Change Summary
cpp/micro_benchmarks/README.md Added a disclaimer to the MoE Backend Benchmark section, clarifying its intended use for developer evaluation and warning about quality standards.
cpp/micro_benchmarks/gen-moe-benchmark-file.py Major refactor: new benchmark parameters (gemm_to_profile), nested loop config generation, dynamic tp_size/ep_size, routing strategy logic, and JSON output adjustments.
cpp/micro_benchmarks/mixtureOfExpertsBackendBenchmarkFixture.h Added GemmToProfile enum, extended MixtureOfExpertsBenchmark for selective GEMM profiling, updated buffer/tactic logic, and introduced new member variables and methods for profiling.
cpp/micro_benchmarks/mixtureOfExpertsBackendBenchmarkLauncher.cu Added support for gemm_to_profile parameter, adjusted tactic handling, enforced uniform routing for GEMM profiling, updated help text, and disabled float32 benchmarks.
cpp/tensorrt_llm/kernels/cutlass_kernels/include/moe_kernels.h Changed calculation of experts per node in GemmProfilerBackend::init to use only ep_size (not ep_size * tp_size); clarified comment on inter_size assignment.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BenchmarkLauncher
    participant BenchmarkFixture
    participant GemmProfilerBackend

    User->>BenchmarkLauncher: Provide benchmark config (incl. gemm_to_profile)
    BenchmarkLauncher->>BenchmarkFixture: Initialize benchmark with config
    BenchmarkFixture->>BenchmarkFixture: Allocate buffers (based on gemm_to_profile)
    BenchmarkFixture->>GemmProfilerBackend: Prepare profiler (if profiling GEMM_1 or GEMM_2)
    BenchmarkFixture->>BenchmarkFixture: Select tactics (per GEMM)
    loop For each benchmark iteration
        BenchmarkFixture->>GemmProfilerBackend: Run selected GEMM (if GEMM_1 or GEMM_2)
        BenchmarkFixture->>BenchmarkFixture: Or run full MoE layer (if LAYER)
    end
    BenchmarkFixture-->>BenchmarkLauncher: Report results
    BenchmarkLauncher-->>User: Output benchmark summary
Loading

Poem

🐇
A hop and a skip, new profiles abound,
GEMM_1 or GEMM_2, let tactics be found!
Buffers reshuffled, disclaimers in place,
Benchmarks for devs—proceed at your pace.
With caution we leap, in code we delight,
MoE now profiles with granular insight!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@djns99
Copy link
Collaborator Author

djns99 commented Jul 16, 2025

/bot run

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
cpp/tensorrt_llm/kernels/cutlass_kernels/include/moe_kernels.h (1)

848-851: Verify the expert count calculation change for tensor parallelism scenarios.

The removal of tp_size from the mNumExpertsPerNode calculation appears correct given that inter_size is already divided by tp_size. However, this needs verification to ensure it doesn't cause issues in TP>1 scenarios.

Please confirm that this change:

  1. Correctly calculates the number of experts per node for all TP/EP configurations
  2. Addresses the autotuner issues mentioned in the past review comments for TP>1
#!/bin/bash
# Search for other usages of mNumExpertsPerNode to understand the impact
rg -A 5 -B 5 "mNumExpertsPerNode" --type cpp

# Look for test cases or benchmarks that validate expert count calculations
fd -e cpp -e cu | xargs rg -l "GemmProfilerBackend.*init" | head -20
🧹 Nitpick comments (2)
cpp/micro_benchmarks/gen-moe-benchmark-file.py (1)

72-101: Configuration generation logic looks good with comprehensive parameter coverage.

The nested loops effectively test different parallelism configurations, and the conditional routing strategy is appropriate. The gemm_to_profile parameter correctly iterates over all profiling modes.

Consider logging when configurations are skipped due to alignment issues:

 if inter_size % (tp_size * 128) != 0:
+    print(f"Skipping config: ep_size={ep_size}, tp_size={tp_size}, inter_size={inter_size} - insufficient alignment")
     continue  # Insufficient alignment
cpp/micro_benchmarks/mixtureOfExpertsBackendBenchmarkFixture.h (1)

955-1009: Well-structured profiling dispatch logic.

The switch statement cleanly separates the profiling logic for individual GEMMs vs full layer execution.

Consider refactoring the duplicate MoE runner calls to reduce code duplication:

+auto runMoeLayer = [&]() {
+    mMoERunner.runMoe(mInputTensor + mInputTensorSize * mBufferIndex, nullptr,
+        mSelectedExperts + mSelectedExpertsSize * mBufferIndex,
+        mUseFinalScale ? mScaleProbs + mScaleProbsSize * mBufferIndex : nullptr,
+        mExpertWeight1 + mExpertWeight1Size * mBufferIndex, mExpertBias1 + mExpertBias1Size * mBufferIndex,
+        mActType, mExpertWeight2 + mExpertWeight2Size * mBufferIndex,
+        mExpertBias2 + mExpertBias2Size * mBufferIndex, mQuantParams[mBufferIndex], mTotalTokens, mHiddenSize,
+        mInterSize, mNumExperts, mK, mWorkspace + mWorkspaceSize * mBufferIndex,
+        mFinalOutput + mFinalOutputSize * mBufferIndex,
+        mSourceToExpandedMap + mSourceToExpandedMapSize * mBufferIndex, parallelism_config,
+#ifdef USING_OSS_CUTLASS_MOE_GEMM
+        /*enable_alltoall=*/false,
+#endif
+        mUseLora, mLoraParams[mBufferIndex],
+        /*use_fp8_block_scaling=*/false, /*min_latency_mode=*/false, min_latency_params, stream);
+};
+
 case GemmToProfile::LAYER:
 {
     auto stream = streamPtr->get();
     MoeMinLatencyParams min_latency_params;
-#ifdef USING_OSS_CUTLASS_MOE_GEMM
-    mMoERunner.runMoe(...);
-#else
-    mMoERunner.runMoe(...);
-#endif
+    runMoeLayer();
     break;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e09e409 and 98a9407.

📒 Files selected for processing (5)
  • cpp/micro_benchmarks/README.md (1 hunks)
  • cpp/micro_benchmarks/gen-moe-benchmark-file.py (2 hunks)
  • cpp/micro_benchmarks/mixtureOfExpertsBackendBenchmarkFixture.h (19 hunks)
  • cpp/micro_benchmarks/mixtureOfExpertsBackendBenchmarkLauncher.cu (10 hunks)
  • cpp/tensorrt_llm/kernels/cutlass_kernels/include/moe_kernels.h (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (4)
cpp/micro_benchmarks/README.md (1)

14-16: Good addition of cautionary disclaimer.

The disclaimer appropriately warns users about the experimental nature of this benchmark tool and sets proper expectations.

cpp/micro_benchmarks/mixtureOfExpertsBackendBenchmarkLauncher.cu (1)

632-634: Excellent documentation updates.

The disclaimer and parameter documentation are clear and comprehensive, helping users understand the experimental nature of the benchmark and how to use the new profiling features.

Also applies to: 662-662, 703-703, 720-721

cpp/micro_benchmarks/mixtureOfExpertsBackendBenchmarkFixture.h (2)

74-79: Clean enum definition for profiling modes.

The GemmToProfile enum properly maps to the backend profiler types and provides a clear interface for selecting profiling targets.


577-738: Efficient buffer allocation based on profiling mode.

The conditional buffer allocation based on gemm_to_profile is well-implemented and reduces memory usage when profiling individual GEMMs. The padSize helper ensures proper memory alignment.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12117 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12117 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9002 completed with status: 'FAILURE'

@djns99
Copy link
Collaborator Author

djns99 commented Jul 17, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12133 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12133 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9014 completed with status: 'FAILURE'

@djns99
Copy link
Collaborator Author

djns99 commented Jul 17, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12154 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12154 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9026 completed with status: 'SUCCESS'

@djns99 djns99 merged commit ae28b3a into NVIDIA:main Jul 17, 2025
4 checks passed
reasonsolo pushed a commit to reasonsolo/TensorRT-LLM that referenced this pull request Jul 21, 2025
…VIDIA#6080)

Signed-off-by: Daniel Stokes <40156487+djns99@users.noreply.github.com>
NVShreyas pushed a commit to NVShreyas/TensorRT-LLM that referenced this pull request Jul 28, 2025
…VIDIA#6080)

Signed-off-by: Daniel Stokes <40156487+djns99@users.noreply.github.com>
Signed-off-by: Shreyas Misra <shreyasm@nvidia.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.

4 participants