Skip to content

[None][feat] Support MARLIN MoE with MTP and attention DP + EP - #16597

Merged
Wanli-Jiang merged 1 commit into
NVIDIA:mainfrom
Wanli-Jiang:user/support-marlin-mtp
Jul 24, 2026
Merged

[None][feat] Support MARLIN MoE with MTP and attention DP + EP#16597
Wanli-Jiang merged 1 commit into
NVIDIA:mainfrom
Wanli-Jiang:user/support-marlin-mtp

Conversation

@Wanli-Jiang

@Wanli-Jiang Wanli-Jiang commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Features

Enable serving NemotronH MTP-graft MIXED_PRECISION checkpoints with the MARLIN (W4A16 NVFP4, SM90) MoE backend:

  • create_moe: fall back MARLIN -> Cutlass for non-NVFP4 layers (e.g. unquantized MTP draft layers) instead of raising.
  • moe_scheduler: force separated routing whenever an external comm strategy is active, enabling attention DP + EP for Marlin; remove the backend's ADP rejection hook.
  • model_loader: propagate the explicit kv_cache_config.dtype override into per-layer quant_config_dict entries so the KV pool and attention modules agree on KV element size (fixes illegal memory access with fp8 KV on MIXED_PRECISION checkpoints).
  • modeling_utils: apply the per-layer lm_head quant entry to the replicated lm_head under attention DP (fixes weight-load shape mismatch for quantized lm_head).
  • quickstart_advanced: derive --moe_backend choices from the MoeConfig.backend Literal.
  • Add unit tests (kv propagation, backend selection fallback) and focused multi-GPU module coverage (DEP + ALLGATHER) for Marlin.

Verified on 4x H100: multi-GPU module tests vs single-GPU reference and end-to-end trtllm-serve with tp4/ep4 attention DP + MARLIN + MTP + fp8 KV cache. Dynamic EPLB remains unsupported for Marlin.

Dev Engineer Review

  • Added support for serving NemotronH MTP-graft MIXED_PRECISION checkpoints with the MARLIN W4A16 NVFP4 SM90 MoE backend.
  • Implemented MARLIN→Cutlass fallback: get_moe_cls now warns and falls back to CutlassFusedMoE when the backend is MARLIN but the layer/quant config is missing NVFP4 capability (instead of failing fast).
  • Updated MARLIN MoE behavior:
    • Removed MarlinFusedMoE.validate_configurable_moe, eliminating the prior rejection of MoE setups needing external all-to-all dispatch/combine when moe.use_dp and dp_size > 1.
    • Added/clarified EP non-local token/expert handling (clamped to local expert 0, processed then discarded in combine) and preserved the statement that dynamic EPLB remains unsupported.
  • Adjusted routing/dispatch behavior for external-comm scenarios:
    • ExternalCommMoEScheduler now broadens requires_separated_routing when moe.comm is active, forcing host-precomputed/separated routing and affecting whether/when moe.routing_method.apply(...) runs and the dispatch tensors produced.
  • KV-cache quantization propagation:
    • validate_and_set_kv_cache_quant now mutates model_config (returns None) and propagates mapped KV cache quantization into each per-layer kv_cache_quant_algo when quant_config_dict is present.
    • Added unit coverage for both explicit quant propagation vs "auto" leaving per-layer kv_cache_quant_algo unset.
  • Fixed/standardized lm_head quant-config handling for attention-DP:
    • Compute lm_head_quant_config once and pass it into the attention-DP LMHead(...).
    • When quant_config_dict is used, lm_head_quant_config is read from quant_config_dict.get("lm_head") and explicitly cleared when (a) the module is excluded from quantization, (b) tie_word_embeddings is enabled, and (c) attention-DP with enable_attention_dp && enable_lm_head_tp_in_adp.
    • In the non-attention-DP path, if a custom LoRA lm_head is detected, lm_head_quant_config is forced to None to avoid unintended quantization of the custom head.
  • Expanded MoE dev guide documentation for SM90 MarlinFusedMoE backend behavior, including external-comm routing precomputation and fallback notes.

QA Engineer Review

Test code changes

  • Unit tests (MoE backend selection): tests/unittest/_torch/modules/moe/test_moe_backend.py

    • Added Marlin unit tests for get_moe_cls (NVFP4 selects MarlinFusedMoE; non-NVFP4/None/FP8 falls back to CutlassFusedMoE; per-layer override_quant_config can force Cutlass fallback).
  • Unit tests (multi-GPU test generation): tests/unittest/_torch/modules/moe/test_moe_module.py

    • Added focused multi-GPU parameter generator used to provide dedicated coverage for Marlin (and adjusted how focused MegaMoE params are assembled).
  • Unit tests (KV cache quant propagation): tests/unittest/_torch/test_model_config.py

    • Added tests for validate_and_set_kv_cache_quant() propagation into quant_config_dict and "auto" behavior.
  • Integration accuracy test (4 GPUs): tests/integration/defs/accuracy/test_llm_api_pytorch.py

    • Added TestNemotronV3Ultra.test_nvfp4_marlin_adp_4gpus(self, mtp_nextn) (Hopper-only) for MARLIN MoE under attention-DP + EP with MTP, asserting llm.args.quant_config.quant_algo == QuantAlgo.MIXED_PRECISION and evaluating MMLU and GSM8K.
    • The test is wired to use mtp_nextn=3.

Test-list-only changes

  • Modified tests/integration/test_lists/qa/llm_function_core.txt

    • Added: accuracy/test_llm_api_pytorch.py::TestNemotronV3Super::test_nvfp4_marlin_adp_4gpus[mtp_nextn=3]
  • Modified tests/integration/test_lists/test-db/l0_dgx_h100.yml

    • Updated MoE backend coverage notes to include CUTLASS and MARLIN and added the H100-focused MoE multi-GPU entry:
      • unittest/_torch/modules/moe/test_moe_module.py::test_configurable_moe_multi_gpu -k "MARLIN"
  • Modified tests/integration/test_lists/test-db/l0_dgx_h200.yml

    • Added: accuracy/test_llm_api_pytorch.py::TestNemotronV3Super::test_nvfp4_marlin_adp_4gpus[mtp_nextn=3]

Coverage verdict

  • Needs follow-up: CI failures were reported during the PR’s requested reruns; although the new unit tests and integration accuracy test hooks/list entries are present, MARLIN MoE + MTP + attention-DP coverage still requires successful CI/accuracy guard confirmation.

Description

Test Coverage

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • 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.

@Wanli-Jiang

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60283 [ run ] triggered by Bot. Commit: 76711d2 Link to invocation

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Marlin MoE selection now falls back to Cutlass for unsupported quantization and uses precomputed routing for external communication. LM-head and per-layer KV-cache quantization handling are updated, with focused unit and integration coverage.

Changes

Marlin backend and routing flow

Layer / File(s) Summary
Marlin selection and external routing
tensorrt_llm/_torch/modules/fused_moe/*, tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.md
MARLIN falls back to CutlassFusedMoE for non-NVFP4 configurations, communication-enabled execution precomputes routing, and Marlin’s external-communication behavior is documented.
Focused MoE coverage
tests/unittest/_torch/modules/moe/*, tests/integration/defs/accuracy/test_llm_api_pytorch.py, tests/integration/test_lists/*
Tests cover backend selection, focused multi-GPU parameter generation, and NVFP4 Marlin attention-DP execution on H100 and H200 test lists.

Quantization configuration consistency

Layer / File(s) Summary
Language-model head quantization
tensorrt_llm/_torch/models/modeling_utils.py
LM-head quantization is computed centrally, cleared for tied embeddings, excluded modules, attention-DP tensor parallelism, and custom LoRA heads, then passed to the attention-DP head.
Per-layer KV-cache propagation
tensorrt_llm/_torch/pyexecutor/model_loader.py, tests/unittest/_torch/test_model_config.py
Explicit KV-cache quantization is propagated to per-layer configurations, while auto leaves per-layer values unset; both paths are tested.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ModelConfig
  participant get_moe_cls
  participant ExternalCommMoEScheduler
  participant routing_method
  participant MarlinFusedMoE
  ModelConfig->>get_moe_cls: provide MARLIN and quantization configuration
  get_moe_cls->>MarlinFusedMoE: select NVFP4 Marlin backend or Cutlass fallback
  ExternalCommMoEScheduler->>routing_method: precompute routing for active communication
  routing_method-->>ExternalCommMoEScheduler: return routing and scales
  ExternalCommMoEScheduler->>MarlinFusedMoE: dispatch routed tokens
Loading

Possibly related PRs

Suggested reviewers: xxi-nv, chienchunhung

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% 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 matches the main change and is concise and specific.
Description check ✅ Passed The description covers the feature, rationale, and checks, though the Test Coverage section isn't explicitly filled.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
tests/integration/test_lists/test-db/l0_dgx_h100.yml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'

tests/integration/test_lists/test-db/l0_dgx_h200.yml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


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

@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: 1

🧹 Nitpick comments (3)
tests/unittest/_torch/modules/moe/test_moe_module.py (1)

1380-1381: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid shadowing the helper inputs.

Lines 1380-1381 overwrite backend_type and quant_algo passed to the helper. Rename the generated case values and use those for the per-case skip check and parameter tuple.

🤖 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/modules/moe/test_moe_module.py` around lines 1380 -
1381, Rename the generated case values in the test helper instead of overwriting
its backend_type and quant_algo inputs. Use the renamed values consistently for
the per-case skip check and the parameter tuple.

Source: Coding guidelines

tests/unittest/_torch/modules/moe/test_moe_backend.py (1)

334-338: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Annotate the new reusable helper interfaces.

Both helpers are new non-test APIs and should use precise parameter and return types, including built-in parameterized generics.

  • tests/unittest/_torch/modules/moe/test_moe_backend.py#L334-L338: annotate quant_algo and return ModelConfig.
  • tests/unittest/_torch/modules/moe/test_moe_module.py#L1346-L1353: annotate all inputs, use a precise Callable[...] | None for should_skip_fn, and replace bare List with a parameterized built-in generic.

As per coding guidelines, “Annotate every function” and “prefer built-in generic types.”

🤖 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/modules/moe/test_moe_backend.py` around lines 334 -
338, Annotate _marlin_model_config in
tests/unittest/_torch/modules/moe/test_moe_backend.py:334-338 with the precise
QuantAlgo | None parameter type and ModelConfig return type. In
tests/unittest/_torch/modules/moe/test_moe_module.py:1346-1353, annotate every
helper parameter, use a precise Callable[...] | None type for should_skip_fn,
and replace bare List with an appropriate parameterized built-in generic.

Source: Coding guidelines

tests/unittest/_torch/test_model_config.py (1)

137-166: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add return annotations to the new helper and tests.

Annotate _make_mixed_precision_model_config() and both test functions (-> ModelConfig / -> None). Coverage in tests/unittest/_torch/test_model_config.py is otherwise sufficient for the explicit override and auto paths. As per coding guidelines, “Annotate every function.”

🤖 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/test_model_config.py` around lines 137 - 166, Add
return annotations to _make_mixed_precision_model_config, returning ModelConfig,
and to both test_validate_and_set_kv_cache_quant_propagates_to_quant_config_dict
and test_validate_and_set_kv_cache_quant_auto_keeps_quant_config_dict, returning
None. Preserve their existing behavior and assertions.

Sources: Coding guidelines, Path instructions

🤖 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 `@tensorrt_llm/_torch/models/modeling_utils.py`:
- Around line 390-418: Clear lm_head_quant_config when both
config.mapping.enable_attention_dp and config.mapping.enable_lm_head_tp_in_adp
are enabled, before constructing LMHead, so LM-head TP under attention DP always
uses a dense weight. Preserve the existing exclusion and tied-embedding checks
for other modes.

---

Nitpick comments:
In `@tests/unittest/_torch/modules/moe/test_moe_backend.py`:
- Around line 334-338: Annotate _marlin_model_config in
tests/unittest/_torch/modules/moe/test_moe_backend.py:334-338 with the precise
QuantAlgo | None parameter type and ModelConfig return type. In
tests/unittest/_torch/modules/moe/test_moe_module.py:1346-1353, annotate every
helper parameter, use a precise Callable[...] | None type for should_skip_fn,
and replace bare List with an appropriate parameterized built-in generic.

In `@tests/unittest/_torch/modules/moe/test_moe_module.py`:
- Around line 1380-1381: Rename the generated case values in the test helper
instead of overwriting its backend_type and quant_algo inputs. Use the renamed
values consistently for the per-case skip check and the parameter tuple.

In `@tests/unittest/_torch/test_model_config.py`:
- Around line 137-166: Add return annotations to
_make_mixed_precision_model_config, returning ModelConfig, and to both
test_validate_and_set_kv_cache_quant_propagates_to_quant_config_dict and
test_validate_and_set_kv_cache_quant_auto_keeps_quant_config_dict, returning
None. Preserve their existing behavior and assertions.
🪄 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: 4326179f-562e-41ad-8dad-e469f66934b0

📥 Commits

Reviewing files that changed from the base of the PR and between 826922f and 76711d2.

📒 Files selected for processing (10)
  • examples/llm-api/quickstart_advanced.py
  • tensorrt_llm/_torch/models/modeling_utils.py
  • tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.md
  • tensorrt_llm/_torch/modules/fused_moe/create_moe.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_marlin.py
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tests/unittest/_torch/modules/moe/test_moe_backend.py
  • tests/unittest/_torch/modules/moe/test_moe_module.py
  • tests/unittest/_torch/test_model_config.py
💤 Files with no reviewable changes (1)
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_marlin.py

Comment thread tensorrt_llm/_torch/models/modeling_utils.py
@Wanli-Jiang
Wanli-Jiang requested review from JadoTu and xuantengh July 20, 2026 06:28
@Wanli-Jiang

Copy link
Copy Markdown
Collaborator Author

need to add an accuracy guard for the feature (MARLIN moe + MTP + ADP)

@xuantengh xuantengh 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, thanks.

@xuantengh

xuantengh commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

You may add end-to-end accuracy test for NT models in https://github.com/NVIDIA/TensorRT-LLM/blob/main/tests/integration/defs/accuracy/test_llm_api_pytorch.py with the new ADP and MTP features.

Also update https://github.com/NVIDIA/TensorRT-LLM/blob/main/tests/integration/test_lists/qa/llm_function_core.txt and https://github.com/NVIDIA/TensorRT-LLM/blob/main/tests/integration/test_lists/test-db/l0_dgx_h200.yml if you add new test methods.

Comment thread examples/llm-api/quickstart_advanced.py Outdated
Comment thread tensorrt_llm/_torch/modules/fused_moe/fused_moe_marlin.py

@BowenFu BowenFu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM — MARLIN fallback + attention-DP/EP wiring are MARLIN-scoped; the lm_head quant hoist and per-layer kv-cache propagation are gated on quant_config_dict (MIXED_PRECISION checkpoints, None for normal models); and moe_scheduler.py's 'or moe.comm is not None' only affects the external-comm flow (which already requires precomputed routing). No default Cutlass/TRTLLM MoE path change.

Comment thread tensorrt_llm/_torch/pyexecutor/model_loader.py Outdated

@nv-guomingz nv-guomingz 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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60685 [ run ] completed with state FAILURE. Commit: 2eadcb1
/LLM/main/L0_MergeRequest_PR pipeline #48979 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

Comment thread examples/llm-api/quickstart_advanced.py Outdated
Comment thread tensorrt_llm/_torch/modules/fused_moe/create_moe.py Outdated
@Wanli-Jiang
Wanli-Jiang force-pushed the user/support-marlin-mtp branch 2 times, most recently from 14f32b3 to 4903f2a Compare July 22, 2026 05:30
@Wanli-Jiang

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@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: 1

🧹 Nitpick comments (1)
tests/integration/defs/accuracy/test_llm_api_pytorch.py (1)

7026-7027: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use max_draft_len here.
num_nextn_predict_layers is deprecated/internal and only kept for compatibility; pass max_draft_len=mtp_nextn instead.

Test coverage summary: test_nvfp4_marlin_adp_4gpus[mtp_nextn=3] is listed in tests/integration/test_lists/qa/llm_function_core.txt and tests/integration/test_lists/test-db/l0_dgx_h200.yml, but not in the H100 test-db list. Coverage verdict: insufficient for H100 CI.

🤖 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/integration/defs/accuracy/test_llm_api_pytorch.py` around lines 7026 -
7027, Update the MTPDecodingConfig construction to pass mtp_nextn through the
public max_draft_len parameter instead of the deprecated
num_nextn_predict_layers parameter, while preserving mtp_eagle_one_model=True.
Add the corresponding test case to the H100 test-db list so
test_nvfp4_marlin_adp_4gpus[mtp_nextn=3] is covered in H100 CI.
🤖 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/integration/test_lists/test-db/l0_dgx_h100.yml`:
- Around line 171-178: Add the new accuracy-guard test entry to the H100 CI list
alongside the existing CUTLASS and MARLIN filters, using the same pytest target
and filter registration used in QA or l0_dgx_h200.yml. Keep the Hopper-only
backend selection unchanged and ensure the accuracy guard runs in the 4x H100
test matrix.

---

Nitpick comments:
In `@tests/integration/defs/accuracy/test_llm_api_pytorch.py`:
- Around line 7026-7027: Update the MTPDecodingConfig construction to pass
mtp_nextn through the public max_draft_len parameter instead of the deprecated
num_nextn_predict_layers parameter, while preserving mtp_eagle_one_model=True.
Add the corresponding test case to the H100 test-db list so
test_nvfp4_marlin_adp_4gpus[mtp_nextn=3] is covered in H100 CI.
🪄 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: feace091-0e1e-496c-9cec-b943712a61c3

📥 Commits

Reviewing files that changed from the base of the PR and between 76711d2 and 4903f2a.

📒 Files selected for processing (13)
  • tensorrt_llm/_torch/models/modeling_utils.py
  • tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.md
  • tensorrt_llm/_torch/modules/fused_moe/create_moe.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_marlin.py
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tests/integration/test_lists/qa/llm_function_core.txt
  • tests/integration/test_lists/test-db/l0_dgx_h100.yml
  • tests/integration/test_lists/test-db/l0_dgx_h200.yml
  • tests/unittest/_torch/modules/moe/test_moe_backend.py
  • tests/unittest/_torch/modules/moe/test_moe_module.py
  • tests/unittest/_torch/test_model_config.py
🚧 Files skipped from review as they are similar to previous changes (8)
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
  • tensorrt_llm/_torch/modules/fused_moe/create_moe.py
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_marlin.py
  • tensorrt_llm/_torch/models/modeling_utils.py
  • tests/unittest/_torch/modules/moe/test_moe_backend.py
  • tests/unittest/_torch/test_model_config.py
  • tests/unittest/_torch/modules/moe/test_moe_module.py

Comment thread tests/integration/test_lists/test-db/l0_dgx_h100.yml
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60896 [ run ] triggered by Bot. Commit: 4903f2a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60896 [ run ] completed with state FAILURE. Commit: 4903f2a
/LLM/main/L0_MergeRequest_PR pipeline #49164 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

@Wanli-Jiang

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60992 [ run ] triggered by Bot. Commit: 4903f2a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60992 [ run ] completed with state FAILURE. Commit: 4903f2a
/LLM/main/L0_MergeRequest_PR pipeline #49248 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

@Wanli-Jiang
Wanli-Jiang force-pushed the user/support-marlin-mtp branch from 4903f2a to e10d405 Compare July 23, 2026 01:42

@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.

🧹 Nitpick comments (1)
tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py (1)

377-384: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a regression test for external-communication routing.

This broadens separated routing to every moe.comm path, but the supplied tests do not exercise ExternalCommMoEScheduler with Marlin plus attention-DP/EP. Add a focused test asserting that routing is precomputed and its expert IDs/scales are passed to dispatch and run_moe.

🤖 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 `@tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py` around lines 377 -
384, Add a focused regression test for ExternalCommMoEScheduler covering
MarlinFusedMoE with attention-DP and EP enabled. Assert that routing is
precomputed and that the resulting expert IDs and scales are forwarded to both
the external dispatch step and run_moe, using the existing scheduler test
helpers and mocks.
🤖 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.

Nitpick comments:
In `@tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py`:
- Around line 377-384: Add a focused regression test for
ExternalCommMoEScheduler covering MarlinFusedMoE with attention-DP and EP
enabled. Assert that routing is precomputed and that the resulting expert IDs
and scales are forwarded to both the external dispatch step and run_moe, using
the existing scheduler test helpers and mocks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 20782a06-900a-461e-8edf-39ef2e5ec13f

📥 Commits

Reviewing files that changed from the base of the PR and between 4903f2a and e10d405.

📒 Files selected for processing (13)
  • tensorrt_llm/_torch/models/modeling_utils.py
  • tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.md
  • tensorrt_llm/_torch/modules/fused_moe/create_moe.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_marlin.py
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tests/integration/test_lists/qa/llm_function_core.txt
  • tests/integration/test_lists/test-db/l0_dgx_h100.yml
  • tests/integration/test_lists/test-db/l0_dgx_h200.yml
  • tests/unittest/_torch/modules/moe/test_moe_backend.py
  • tests/unittest/_torch/modules/moe/test_moe_module.py
  • tests/unittest/_torch/test_model_config.py
🚧 Files skipped from review as they are similar to previous changes (9)
  • tests/integration/test_lists/qa/llm_function_core.txt
  • tensorrt_llm/_torch/modules/fused_moe/create_moe.py
  • tests/integration/test_lists/test-db/l0_dgx_h100.yml
  • tensorrt_llm/_torch/models/modeling_utils.py
  • tests/unittest/_torch/test_model_config.py
  • tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.md
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tests/unittest/_torch/modules/moe/test_moe_module.py

Enable the MARLIN (SM90 W4A16-NVFP4) MoE backend to run with MTP
speculative decoding and attention DP + expert parallelism:

- create_moe.get_moe_cls: fall back to CutlassFusedMoE (warn instead of
  raise) for non-NVFP4 layers, so MIXED_PRECISION checkpoints with
  unquantized MTP draft layers keep main-model experts on MARLIN.
- fused_moe_marlin: allow attention DP (drop the ConfigurableMoE
  rejection); document the EP non-local masking perf follow-up.
- moe_scheduler: require separated routing whenever an external MoE
  communication strategy is attached, so scheduler-precomputed routing
  feeds the dispatch under attention DP + EP.
- model_loader.validate_and_set_kv_cache_quant: propagate an explicit
  kv_cache_config.dtype override into the per-layer quant configs of
  MIXED_PRECISION checkpoints (KV pool allocated with the overridden
  dtype while attention layers used the checkpoint dtype caused
  out-of-bounds access); fix the return annotation to None.
- modeling_utils.DecoderModelForCausalLM: resolve the per-layer lm_head
  quant entry once and pass it to both LMHead constructions
  (ADP-replicated and TP); exclude_modules, tie_word_embeddings, custom
  LoRA lm_head, and lm_head TP in ADP all keep lm_head dense.

Tests: unit tests for per-layer kv propagation and MARLIN backend
selection/fallback; a focused MARLIN DEP+ALLGATHER multi-GPU matrix
selected in H100 pre-merge (l0_dgx_h100.yml); and an end-to-end
accuracy guard TestNemotronV3Super::test_nvfp4_marlin_adp_4gpus
(MMLU+GSM8K with tp4/ep4 + attention DP + MTP3 + fp8 KV) registered in
l0_dgx_h200.yml and llm_function_core.txt. MoE developer guide updated.

Signed-off-by: Wanli Jiang <35160485+Wanli-Jiang@users.noreply.github.com>
@Wanli-Jiang
Wanli-Jiang force-pushed the user/support-marlin-mtp branch from e10d405 to dd26aa7 Compare July 23, 2026 02:18
@Wanli-Jiang

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@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: 1

🤖 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/unittest/_torch/modules/moe/test_moe_backend.py`:
- Around line 334-368: Add type annotations to _marlin_model_config, including
its quant_algo parameter and return type, and mark the three new test functions
in test_moe_backend.py as returning None. In
tests/unittest/_torch/modules/moe/test_moe_module.py lines 1346-1353, annotate
_generate_focused_multi_gpu_test_params parameters and return value, replacing
bare List with an appropriate parameterized built-in generic.
🪄 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: 3c35228a-a371-405f-a274-c636288881e5

📥 Commits

Reviewing files that changed from the base of the PR and between e10d405 and dd26aa7.

📒 Files selected for processing (13)
  • tensorrt_llm/_torch/models/modeling_utils.py
  • tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.md
  • tensorrt_llm/_torch/modules/fused_moe/create_moe.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_marlin.py
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tests/integration/test_lists/qa/llm_function_core.txt
  • tests/integration/test_lists/test-db/l0_dgx_h100.yml
  • tests/integration/test_lists/test-db/l0_dgx_h200.yml
  • tests/unittest/_torch/modules/moe/test_moe_backend.py
  • tests/unittest/_torch/modules/moe/test_moe_module.py
  • tests/unittest/_torch/test_model_config.py
🚧 Files skipped from review as they are similar to previous changes (10)
  • tests/integration/test_lists/qa/llm_function_core.txt
  • tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.md
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
  • tests/integration/test_lists/test-db/l0_dgx_h200.yml
  • tensorrt_llm/_torch/modules/fused_moe/create_moe.py
  • tensorrt_llm/_torch/models/modeling_utils.py
  • tensorrt_llm/_torch/modules/fused_moe/fused_moe_marlin.py
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tests/unittest/_torch/test_model_config.py
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py

Comment thread tests/unittest/_torch/modules/moe/test_moe_backend.py
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61154 [ run ] triggered by Bot. Commit: dd26aa7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61154 [ run ] completed with state FAILURE. Commit: dd26aa7
/LLM/main/L0_MergeRequest_PR pipeline #49403 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

@Wanli-Jiang

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61252 [ run ] triggered by Bot. Commit: dd26aa7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61252 [ run ] completed with state FAILURE. Commit: dd26aa7
/LLM/main/L0_MergeRequest_PR pipeline #49489 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

@Wanli-Jiang

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61458 [ run ] triggered by Bot. Commit: dd26aa7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61458 [ run ] completed with state SUCCESS. Commit: dd26aa7
/LLM/main/L0_MergeRequest_PR pipeline #49679 completed with status: 'SUCCESS'

CI Report

Link to invocation

@Wanli-Jiang
Wanli-Jiang merged commit 16bdc6d into NVIDIA:main Jul 24, 2026
10 checks passed
yuanjingx87 pushed a commit to yuanjingx87/TensorRT-LLM that referenced this pull request Jul 26, 2026
…A#16597)

Signed-off-by: Wanli Jiang <35160485+Wanli-Jiang@users.noreply.github.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.

10 participants