Skip to content

[TRTLLM-12635][feat] add bench_moe microbenchmark - #14507

Merged
xxi-nv merged 2 commits into
NVIDIA:mainfrom
xxi-nv:xxi/bench-moe-refactor-20260520-rebased
May 25, 2026
Merged

xxi-nv merged 2 commits into
NVIDIA:mainfrom
xxi-nv:xxi/bench-moe-refactor-20260520-rebased

Conversation

@xxi-nv

@xxi-nv xxi-nv commented May 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add a modular bench_moe microbenchmark for ConfigurableMoE with MPI/Slurm launch support.
  • Add search, routing-control, reporting, checkpoint/resume, and kernel timing plumbing for MoE sweeps.
  • Add a Markdown user guide and keep backend registry/import handling local to bench_moe without modifying the production CuteDSL backend.

Test plan

  • pre-commit hooks passed during commit amend
  • python3 -m py_compile on the modified bench_moe Python files
  • git diff --check on the modified bench_moe and fused_moe paths
  • Import smoke test could not run in this local Python environment because torch is not installed

@xxi-nv
xxi-nv requested a review from a team as a code owner May 25, 2026 00:44
@xxi-nv
xxi-nv requested a review from yuxianq May 25, 2026 00:44
@xxi-nv
xxi-nv removed the request for review from yuxianq May 25, 2026 00:51
@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR introduces a comprehensive MoE microbenchmark framework for TensorRT-LLM, including structured benchmark specifications, multi-dimensional search-space expansion, advanced routing-control planning with materialization, multiple timing implementations (eager, CUDA graph, CUPTI), per-candidate execution orchestration, MPI-based worker loops with resume and CUDA-poison recovery, dashboard-oriented JSON reporting, optional Excel workbook generation, and extensive design documentation. It also makes the CuTe DSL dependency optional to improve compatibility.

Changes

Complete MoE Microbenchmark Implementation

Layer / File(s) Summary
Spec dataclasses and context resolution
tests/microbenchmarks/bench_moe/specs.py, tests/microbenchmarks/bench_moe/cli.py (context parts)
Defines core data model (ModelSpec, ConfigSpec, WorkloadSpec, SearchSpec, RoutingControlSpec, RunResult) with computed properties, to_dict helpers, and built-in model registry; resolves benchmark context including activation/routing-logit dtypes.
CLI argument parsing and configuration loading
tests/microbenchmarks/bench_moe/cli.py, tests/microbenchmarks/bench_moe/cli.py (parse_args)
Parses CLI args with grouped options (launch, model, workload, routing, parallel, backend, timing, analysis, output), resolves specs, loads optional JSON config with CLI precedence, normalizes search axes.
Search space expansion and candidate validation
tests/microbenchmarks/bench_moe/search.py
Expands search dimensions into candidate ConfigSpec entries, validates each via backend capability and mapping resolution, prunes invalid candidates with structured skip reasons.
Routing control plan construction and materialization
tests/microbenchmarks/bench_moe/routing/builders.py, tests/microbenchmarks/bench_moe/routing/materialize.py, tests/microbenchmarks/bench_moe/routing/parsing.py
Builds canonical RoutingPlan from comm/expert patterns with slot-based dispatch matrices, materializes expert selections with per-rank token distribution, supports file-based matrix sidecars, provides observation metrics and error reporting.
Native logits projection and forced-mode routing patching
tests/microbenchmarks/bench_moe/routing/native_logits.py
Synthesizes router logits matching routing plans, classifies projection realism (exact/projected/rejected), provides context-manager wrappers to inject pre-materialized expert selections during forced routing mode.
Configuration builders and TensorRT-LLM mapping setup
tests/microbenchmarks/bench_moe/mapping.py
Constructs Mapping, routing-method instances (with special DeepSeekV3/MiniMax CUDA tensor handling), PretrainedConfig, and ModelConfig from benchmark specs with quantization support.
MoE module construction and preparation
tests/microbenchmarks/bench_moe/build.py
Constructs fresh MoE instances per (backend, num_tokens) case with environment setup, quantization-aware weight generation, device placement, and routing_logits_dtype propagation.
Eager, CUDA graph, and CUPTI timing modes
tests/microbenchmarks/bench_moe/timing/eager.py, tests/microbenchmarks/bench_moe/timing/cuda_graph.py, tests/microbenchmarks/bench_moe/timing/cupti.py, tests/microbenchmarks/bench_moe/timing/autotune.py
Implements three timing paths (eager with Kineto profiling, CUDA graph with external events, CUPTI activity breakdown), autotune pre-pass with AutoTuner override, kernel categorization into moe_forward vs other buckets.
MPI utilities, CUDA device setup, input generation
tests/microbenchmarks/bench_moe/utils.py
Provides rank-0-only logging, CUDA device selection by local MPI rank, MegaMoE distributed initialization, token distribution helpers, and synthetic input generation with optional seeding/caching.
Per-candidate case runner with routing-control orchestration
tests/microbenchmarks/bench_moe/case_runner.py
Orchestrates full candidate lifecycle: resolves layout/plan, builds MoE, selects routing inputs (native/forced), installs routing patches, runs autotune/timed forward (eager/CUDA graph), aggregates metrics, materializes routing observations.
Results aggregation and latency/kernel breakdown computation
tests/microbenchmarks/bench_moe/results.py
Implements MPI-based latency all-gather with slowest-rank stats, robust trimmed-mean scoring with MAD-based outlier filtering, kernel breakdown aggregation, bottleneck classification, v2 row serialization.
Dashboard JSON and XLSX analysis workbook generation
tests/microbenchmarks/bench_moe/reporting.py
Builds report payload with environment metadata, groups/ranks results by workload, generates minimal XLSX workbooks with kernel breakdown, raw per-rank/per-iteration timing, and workload-specific sheets using only Python stdlib.
MPI worker loop, resume support, CUDA poison recovery, and outer sweep driver
tests/microbenchmarks/bench_moe/worker.py, tests/microbenchmarks/sweep_moe.py
MPI worker loads/broadcasts resume state, iterates candidates with watchdog timeout, detects sticky CUDA poison with coordinated exit, performs incremental checkpointing; outer sweep driver orchestrates multi-leaf execution with retry/backoff.
Package initialization and entry point scripts
tests/microbenchmarks/bench_moe/__init__.py, tests/microbenchmarks/bench_moe/__main__.py
Sets up package structure with path adjustments, legacy import surface mirroring, and __main__.py entry point for python -m bench_moe execution.
Design documents and user guide
tests/microbenchmarks/BENCH_MOE_DESIGN.md, tests/microbenchmarks/BENCH_MOE_DASHBOARD_DESIGN.md, tests/microbenchmarks/BENCH_MOE_ROUTING_CONTROL_DESIGN.md, tests/microbenchmarks/bench_moe/BENCH_MOE_USER_GUIDE.md
Comprehensive design specs covering MPI-based benchmark architecture, dashboard integration goals, routing-control planning/materialization/injection, plus user guide with launch rules, examples, and troubleshooting.
Comprehensive CPU-only routing control tests
tests/microbenchmarks/test_bench_moe_routing_control.py
Tests routing pattern parsing, dispatch/expert matrix construction, full routing plan materialization, file-based matrix loading, RoutingControlSpec activation, native projection, robust latency scoring, CLI parsing, input generation determinism, Excel workbook generation.

Optional CuTe DSL Dependency

Layer / File(s) Summary
Optional CuTe DSL import wrapper
tensorrt_llm/_torch/modules/fused_moe/fused_moe_cute_dsl.py
Wraps cute_dsl_custom_ops import in try/except, defining sentinel _CuteDslUnavailable class that raises RuntimeError on instantiation when CUTLASS DSL is unavailable.

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • NVIDIA/TensorRT-LLM#13559: FP8 block-scale MoE routing/alignment implementation that depends on optional CuTe DSL availability made by this PR.

Suggested reviewers

  • yuxianq
  • nekorobov
  • hyukn
  • Funatiq
  • lfr-0531
  • mikeiovine
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

@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

🧹 Nitpick comments (12)
tests/microbenchmarks/bench_moe/__init__.py (1)

23-23: 💤 Low value

Optional: from __future__ import annotations is unnecessary.

Python 3.10+ (the minimum version for this project per setup.py) supports PEP 585 generics and type hints natively. This import can be removed.

♻️ Proposed cleanup
-from __future__ import annotations
-
 import importlib

Based on learnings: In TensorRT-LLM (Python requires >=3.10 and <4 as per setup.py), you can use Python 3.10+ features throughout the codebase, and you do not need to add from __future__ import annotations.

🤖 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/microbenchmarks/bench_moe/__init__.py` at line 23, Remove the
unnecessary future import: delete the line "from __future__ import annotations"
from tests/microbenchmarks/bench_moe/__init__.py since the project targets
Python 3.10+, which natively supports PEP 563/annotations behavior; no code
changes elsewhere are required.
tests/microbenchmarks/bench_moe/__main__.py (1)

33-33: 💤 Low value

Optional: from __future__ import annotations is unnecessary.

Python 3.10+ (the minimum version for this project) supports type hints natively without this future import.

♻️ Proposed cleanup
-from __future__ import annotations
-
 import sys

Based on learnings: In TensorRT-LLM (Python requires >=3.10 and <4 as per setup.py), you can use Python 3.10+ features throughout the codebase, and you do not need to add from __future__ import annotations.

🤖 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/microbenchmarks/bench_moe/__main__.py` at line 33, Remove the
unnecessary future import: delete the line "from __future__ import annotations"
from tests/microbenchmarks/bench_moe/__main__.py (the import statement itself is
the symbol to remove) since the project requires Python 3.10+, which natively
supports postponed evaluation of annotations; after removal, run tests/lint to
ensure no formatting or unused-import warnings remain.
tests/microbenchmarks/test_bench_moe_routing_control.py (1)

719-719: 💤 Low value

Consider tuple unpacking for cleaner concatenation.

For consistency with modern Python style, consider using unpacking instead of concatenation.

✨ Optional style improvement
-    assert search.comm_methods == bench_moe._FORCED_COMM_ENV_VALUES + ("AUTO",)
+    assert search.comm_methods == (*bench_moe._FORCED_COMM_ENV_VALUES, "AUTO")
🤖 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/microbenchmarks/test_bench_moe_routing_control.py` at line 719, Replace
the explicit tuple concatenation with tuple unpacking for cleaner style: update
the assertion comparing search.comm_methods to use a tuple constructed via
unpacking of bench_moe._FORCED_COMM_ENV_VALUES plus "AUTO" (i.e., build the
expected tuple with (*bench_moe._FORCED_COMM_ENV_VALUES, "AUTO") and compare
that to search.comm_methods).
tests/microbenchmarks/bench_moe/cli.py (3)

654-655: ⚡ Quick win

Specify encoding when opening JSON config file.

open(args.config_file) uses the platform default encoding which may vary. Explicitly specify encoding="utf-8" for consistent JSON parsing across platforms.

Proposed fix
-    with open(args.config_file) as f:
+    with open(args.config_file, encoding="utf-8") as f:
         cfg = json.load(f)
🤖 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/microbenchmarks/bench_moe/cli.py` around lines 654 - 655, The JSON
config is opened with open(args.config_file) which relies on platform default
encoding; update the file open call that loads cfg (the json.load call using
args.config_file) to explicitly pass encoding="utf-8" when opening the file so
JSON parsing is consistent across platforms.

540-551: ⚡ Quick win

Duplicate _coerce_str_tuple function.

This function is duplicated verbatim in search.py (lines 228-239). Consider keeping a single definition in one module and importing it in the other to reduce maintenance burden.

🤖 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/microbenchmarks/bench_moe/cli.py` around lines 540 - 551, There is a
duplicate function _coerce_str_tuple defined in this module and in search.py;
remove the duplicate here and import the single canonical definition instead (or
move it to a shared util module and import from there). Update the top-level
imports to import _coerce_str_tuple from the chosen module (or add the new util
import), and ensure callers in this file still reference _coerce_str_tuple
unchanged; run tests to confirm nothing else relies on the local definition.

125-479: 💤 Low value

Accessing private parser._actions for CLI tracking.

Lines 472-476 iterate over parser._actions to detect which flags were explicitly provided. This is a common pattern but relies on argparse internals. Consider documenting this as intentional or using argparse.Action's default sentinel pattern as an alternative.

Otherwise the argument grouping and help text are well-structured.

🤖 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/microbenchmarks/bench_moe/cli.py` around lines 125 - 479, The code uses
the private parser._actions in the parse_args function to build
args._cli_provided by scanning option_strings; either mark this as intentional
in a comment/PR note or replace with a public-safe approach: attach a custom
argparse.Action subclass (or use a unique default sentinel per argument) to
record when an option is explicitly set, and then populate args._cli_provided
from those Actions instead of iterating parser._actions; update references to
parser._actions, the option_strings loop, and args._cli_provided accordingly and
add a short comment explaining the chosen approach.
tests/microbenchmarks/bench_moe/search.py (2)

118-134: ⚡ Quick win

Prefix unused variable with underscore.

moe_ep from line 120 is never used. Prefix it with _ to signal intentional discard.

Proposed fix
     # Mapping layout gate.
     try:
-        moe_ep, moe_tp, enable_dp = _resolve_mapping_layout(config, world_size)
+        _moe_ep, moe_tp, enable_dp = _resolve_mapping_layout(config, world_size)
     except ValueError as exc:
         return False, str(exc)
🤖 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/microbenchmarks/bench_moe/search.py` around lines 118 - 134, The
variable moe_ep returned from _resolve_mapping_layout is unused; rename it to a
throwaway name (e.g., _moe_ep or simply _) in the assignment to indicate
intentional discard and satisfy linters: change the left-hand side of "moe_ep,
moe_tp, enable_dp = _resolve_mapping_layout(config, world_size)" to use a
prefixed-underscore variable for the first element while leaving moe_tp and
enable_dp unchanged.

36-54: 💤 Low value

Consider documenting the broad exception catch.

Line 53-54 catches a bare Exception, which static analysis flags. While this is defensive (any can_implement failure should skip the backend), adding a brief comment explaining why broad catching is intentional here would suppress reviewer/linter concerns.

The specific exceptions from can_implement may vary by backend implementation, so the current approach is pragmatic.

🤖 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/microbenchmarks/bench_moe/search.py` around lines 36 - 54, In
_check_backend_can_implement, add a short explanatory comment immediately above
the "except Exception as exc:" block explaining that we intentionally catch
broad exceptions from backend_cls.can_implement because backend implementations
may raise diverse, backend-specific errors and any failure should cause the
backend to be skipped; also include a linter hint/suppression (e.g., note about
deliberately broad catch or a noqa/B902) if your project linter requires it.
This documents intent and silences static-analysis warnings while preserving the
existing fallback behavior.
tests/microbenchmarks/bench_moe/routing/builders.py (1)

254-255: ⚡ Quick win

Specify explicit encoding when opening JSON files.

Opening files without an explicit encoding parameter relies on the platform default, which can vary. For JSON files, UTF-8 is the standard encoding.

♻️ Proposed fix
-    with open(path) as f:
+    with open(path, encoding="utf-8") as f:
         payload = json.load(f)
🤖 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/microbenchmarks/bench_moe/routing/builders.py` around lines 254 - 255,
The file opens a JSON file with open(path) and relies on platform default
encoding; update the open call to specify encoding='utf-8' so json.load reads
UTF-8 reliably (the lines around open(path) and payload = json.load(f) should be
changed to open with an explicit encoding argument).
tests/microbenchmarks/bench_moe/routing/__init__.py (1)

76-111: 💤 Low value

Consider sorting __all__ for consistency.

The static analysis tool notes that __all__ is not sorted. While the current ordering loosely groups by submodule, alphabetical sorting improves maintainability and makes it easier to spot missing/duplicate entries.

🤖 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/microbenchmarks/bench_moe/routing/__init__.py` around lines 76 - 111,
The __all__ list is not alphabetically sorted; please reorder the entries in the
__all__ list (the symbol named __all__) into ascending alphabetical order (by
string) while preserving existing quoted names and commas and without changing
any symbol names; ensure duplicates are removed if found and keep the final list
formatting consistent with the current style so imports/export behavior is
unchanged (e.g., entries like "_COMM_PATTERN_NAMES", "_EXPERT_PATTERN_NAMES",
"RoutingPlan", "_build_dispatch_matrix", etc. should be reordered
alphabetically).
tests/microbenchmarks/bench_moe/timing/cuda_graph.py (1)

66-130: 💤 Low value

Add strict=True to zip() for length mismatch detection.

Both cupti_times and forward_times_ms should have exactly iters elements. Adding strict=True will surface bugs if their lengths ever diverge.

♻️ Suggested fix
             forward_times_ms = [
-                ct if ct is not None else et for ct, et in zip(cupti_times, forward_times_ms)
+                ct if ct is not None else et for ct, et in zip(cupti_times, forward_times_ms, strict=True)
             ]
🤖 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/microbenchmarks/bench_moe/timing/cuda_graph.py` around lines 66 - 130,
The list comprehension that merges cupti_times with forward_times_ms should use
zip(..., strict=True) to ensure both sequences have exactly iters elements;
update the expression in the function that computes forward_times_ms (the list
comprehension using cupti_times and forward_times_ms) to call zip(cupti_times,
forward_times_ms, strict=True) so a length mismatch raises immediately (refer to
symbols cupti_times, forward_times_ms, and the list comprehension where they are
zipped). Ensure any test expectations or callers still produce exactly iters
elements.
tests/microbenchmarks/bench_moe/case_runner.py (1)

846-857: 💤 Low value

Consider logging the exception from moe.destroy() instead of silently passing.

The try-except-pass at line 852-853 silently swallows any exception during cleanup. While it's correct that cleanup failures shouldn't crash the benchmark, logging the exception would help diagnose resource leak or teardown issues during development.

♻️ Suggested improvement
         if moe is not None:
             try:
                 moe.destroy()
-            except Exception:
-                pass
+            except Exception as exc:
+                _maybe_print_rank0(f"[bench_moe] moe.destroy() failed: {type(exc).__name__}: {exc}")
🤖 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/microbenchmarks/bench_moe/case_runner.py` around lines 846 - 857, The
cleanup finally silently swallows exceptions from moe.destroy(); change the
except block to catch the exception as a variable (e.g., except Exception as e:)
and log it (using logging.exception or the module's existing logger) with a
clear message like "error destroying moe" so teardown failures are recorded but
not raised; keep the subsequent environment restoration for
TRTLLM_FORCE_COMM_METHOD unchanged.
🤖 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 `@tests/microbenchmarks/bench_moe/routing/native_logits.py`:
- Around line 237-240: The try/except around calling apply_orig(router_logits)
is catching all Exception and silently swallowing errors; change this to catch
only the expected exception(s) (e.g., AttributeError, TypeError, or a custom
expected exception) or check for the callable before calling (e.g., if
callable(apply_orig): ...), and if you must catch an error, log the failure at
debug level using the existing test/logger facility instead of pass; reference
apply_orig and router_logits when making the change so you only handle the
specific failure modes.

In `@tests/microbenchmarks/test_bench_moe_routing_control.py`:
- Line 302: The test unpacks obs_hist from the call to
bench_moe._observe_routing_metrics but never uses it; rename the unused unpacked
variable to start with an underscore (e.g., _obs_hist) in the tuple assignment
where bench_moe._observe_routing_metrics is called so it follows Python
conventions for unused variables and avoids linter warnings.

---

Nitpick comments:
In `@tests/microbenchmarks/bench_moe/__init__.py`:
- Line 23: Remove the unnecessary future import: delete the line "from
__future__ import annotations" from tests/microbenchmarks/bench_moe/__init__.py
since the project targets Python 3.10+, which natively supports PEP
563/annotations behavior; no code changes elsewhere are required.

In `@tests/microbenchmarks/bench_moe/__main__.py`:
- Line 33: Remove the unnecessary future import: delete the line "from
__future__ import annotations" from tests/microbenchmarks/bench_moe/__main__.py
(the import statement itself is the symbol to remove) since the project requires
Python 3.10+, which natively supports postponed evaluation of annotations; after
removal, run tests/lint to ensure no formatting or unused-import warnings
remain.

In `@tests/microbenchmarks/bench_moe/case_runner.py`:
- Around line 846-857: The cleanup finally silently swallows exceptions from
moe.destroy(); change the except block to catch the exception as a variable
(e.g., except Exception as e:) and log it (using logging.exception or the
module's existing logger) with a clear message like "error destroying moe" so
teardown failures are recorded but not raised; keep the subsequent environment
restoration for TRTLLM_FORCE_COMM_METHOD unchanged.

In `@tests/microbenchmarks/bench_moe/cli.py`:
- Around line 654-655: The JSON config is opened with open(args.config_file)
which relies on platform default encoding; update the file open call that loads
cfg (the json.load call using args.config_file) to explicitly pass
encoding="utf-8" when opening the file so JSON parsing is consistent across
platforms.
- Around line 540-551: There is a duplicate function _coerce_str_tuple defined
in this module and in search.py; remove the duplicate here and import the single
canonical definition instead (or move it to a shared util module and import from
there). Update the top-level imports to import _coerce_str_tuple from the chosen
module (or add the new util import), and ensure callers in this file still
reference _coerce_str_tuple unchanged; run tests to confirm nothing else relies
on the local definition.
- Around line 125-479: The code uses the private parser._actions in the
parse_args function to build args._cli_provided by scanning option_strings;
either mark this as intentional in a comment/PR note or replace with a
public-safe approach: attach a custom argparse.Action subclass (or use a unique
default sentinel per argument) to record when an option is explicitly set, and
then populate args._cli_provided from those Actions instead of iterating
parser._actions; update references to parser._actions, the option_strings loop,
and args._cli_provided accordingly and add a short comment explaining the chosen
approach.

In `@tests/microbenchmarks/bench_moe/routing/__init__.py`:
- Around line 76-111: The __all__ list is not alphabetically sorted; please
reorder the entries in the __all__ list (the symbol named __all__) into
ascending alphabetical order (by string) while preserving existing quoted names
and commas and without changing any symbol names; ensure duplicates are removed
if found and keep the final list formatting consistent with the current style so
imports/export behavior is unchanged (e.g., entries like "_COMM_PATTERN_NAMES",
"_EXPERT_PATTERN_NAMES", "RoutingPlan", "_build_dispatch_matrix", etc. should be
reordered alphabetically).

In `@tests/microbenchmarks/bench_moe/routing/builders.py`:
- Around line 254-255: The file opens a JSON file with open(path) and relies on
platform default encoding; update the open call to specify encoding='utf-8' so
json.load reads UTF-8 reliably (the lines around open(path) and payload =
json.load(f) should be changed to open with an explicit encoding argument).

In `@tests/microbenchmarks/bench_moe/search.py`:
- Around line 118-134: The variable moe_ep returned from _resolve_mapping_layout
is unused; rename it to a throwaway name (e.g., _moe_ep or simply _) in the
assignment to indicate intentional discard and satisfy linters: change the
left-hand side of "moe_ep, moe_tp, enable_dp = _resolve_mapping_layout(config,
world_size)" to use a prefixed-underscore variable for the first element while
leaving moe_tp and enable_dp unchanged.
- Around line 36-54: In _check_backend_can_implement, add a short explanatory
comment immediately above the "except Exception as exc:" block explaining that
we intentionally catch broad exceptions from backend_cls.can_implement because
backend implementations may raise diverse, backend-specific errors and any
failure should cause the backend to be skipped; also include a linter
hint/suppression (e.g., note about deliberately broad catch or a noqa/B902) if
your project linter requires it. This documents intent and silences
static-analysis warnings while preserving the existing fallback behavior.

In `@tests/microbenchmarks/bench_moe/timing/cuda_graph.py`:
- Around line 66-130: The list comprehension that merges cupti_times with
forward_times_ms should use zip(..., strict=True) to ensure both sequences have
exactly iters elements; update the expression in the function that computes
forward_times_ms (the list comprehension using cupti_times and forward_times_ms)
to call zip(cupti_times, forward_times_ms, strict=True) so a length mismatch
raises immediately (refer to symbols cupti_times, forward_times_ms, and the list
comprehension where they are zipped). Ensure any test expectations or callers
still produce exactly iters elements.

In `@tests/microbenchmarks/test_bench_moe_routing_control.py`:
- Line 719: Replace the explicit tuple concatenation with tuple unpacking for
cleaner style: update the assertion comparing search.comm_methods to use a tuple
constructed via unpacking of bench_moe._FORCED_COMM_ENV_VALUES plus "AUTO"
(i.e., build the expected tuple with (*bench_moe._FORCED_COMM_ENV_VALUES,
"AUTO") and compare that to search.comm_methods).
🪄 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: 1e56b205-d1ef-4f7f-a53f-e36a04576328

📥 Commits

Reviewing files that changed from the base of the PR and between a8cd4ff and b0e4b2a.

📒 Files selected for processing (29)
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_cute_dsl.py
  • tests/microbenchmarks/BENCH_MOE_DASHBOARD_DESIGN.md
  • tests/microbenchmarks/BENCH_MOE_DESIGN.md
  • tests/microbenchmarks/BENCH_MOE_ROUTING_CONTROL_DESIGN.md
  • tests/microbenchmarks/bench_moe/BENCH_MOE_USER_GUIDE.md
  • tests/microbenchmarks/bench_moe/__init__.py
  • tests/microbenchmarks/bench_moe/__main__.py
  • tests/microbenchmarks/bench_moe/build.py
  • tests/microbenchmarks/bench_moe/case_runner.py
  • tests/microbenchmarks/bench_moe/cli.py
  • tests/microbenchmarks/bench_moe/mapping.py
  • tests/microbenchmarks/bench_moe/reporting.py
  • tests/microbenchmarks/bench_moe/results.py
  • tests/microbenchmarks/bench_moe/routing/__init__.py
  • tests/microbenchmarks/bench_moe/routing/builders.py
  • tests/microbenchmarks/bench_moe/routing/materialize.py
  • tests/microbenchmarks/bench_moe/routing/native_logits.py
  • tests/microbenchmarks/bench_moe/routing/parsing.py
  • tests/microbenchmarks/bench_moe/search.py
  • tests/microbenchmarks/bench_moe/specs.py
  • tests/microbenchmarks/bench_moe/timing/__init__.py
  • tests/microbenchmarks/bench_moe/timing/autotune.py
  • tests/microbenchmarks/bench_moe/timing/cuda_graph.py
  • tests/microbenchmarks/bench_moe/timing/cupti.py
  • tests/microbenchmarks/bench_moe/timing/eager.py
  • tests/microbenchmarks/bench_moe/utils.py
  • tests/microbenchmarks/bench_moe/worker.py
  • tests/microbenchmarks/sweep_moe.py
  • tests/microbenchmarks/test_bench_moe_routing_control.py

@xxi-nv
xxi-nv force-pushed the xxi/bench-moe-refactor-20260520-rebased branch from b0e4b2a to 2c4e704 Compare May 25, 2026 01:03
@xxi-nv
xxi-nv requested review from leslie-fang25 and removed request for a team May 25, 2026 01:09
Add a modular MoE microbenchmark with routing-control workloads, resume/reporting support, and documented MPI/Slurm launch modes so GB200 benchmark sweeps are reproducible.

Signed-off-by: xxi <xxi@nvidia.com>
@xxi-nv
xxi-nv force-pushed the xxi/bench-moe-refactor-20260520-rebased branch from 2c4e704 to 201fabc Compare May 25, 2026 01:10
@xxi-nv xxi-nv changed the title [None][test] add bench_moe microbenchmark [TRTLLM-12635][feat] add bench_moe microbenchmark May 25, 2026

@leslie-fang25 leslie-fang25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, just left a few nits

Comment thread tests/microbenchmarks/bench_moe/cli.py Resolved
Tighten routing-control patch cleanup and reuse shared helpers so review feedback is resolved without changing benchmark behavior.

Signed-off-by: xxi <xxi@nvidia.com>
@xxi-nv
xxi-nv enabled auto-merge (squash) May 25, 2026 06:14
@xxi-nv

xxi-nv commented May 25, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50156 [ run ] triggered by Bot. Commit: 3213410 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50156 [ run ] completed with state SUCCESS. Commit: 3213410
/LLM/main/L0_MergeRequest_PR pipeline #39701 completed with status: 'SUCCESS'

CI Report

Link to invocation

@xxi-nv
xxi-nv merged commit 8c8765d into NVIDIA:main May 25, 2026
8 checks passed
@xxi-nv
xxi-nv deleted the xxi/bench-moe-refactor-20260520-rebased branch May 25, 2026 09:30
KleinBlueC pushed a commit to KleinBlueC/TensorRT-LLM that referenced this pull request May 26, 2026
bmarimuthu-nv pushed a commit to nv-auto-deploy/TensorRT-LLM that referenced this pull request May 28, 2026
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