Skip to content

[TRTLLM-12242][feat] Add Marlin NVFP4 backend for MoE and Linear on Hopper - #13476

Merged
shuyixiong merged 29 commits into
NVIDIA:mainfrom
xuantengh:nvfp4-hopper
Jun 25, 2026
Merged

[TRTLLM-12242][feat] Add Marlin NVFP4 backend for MoE and Linear on Hopper#13476
shuyixiong merged 29 commits into
NVIDIA:mainfrom
xuantengh:nvfp4-hopper

Conversation

@xuantengh

@xuantengh xuantengh commented Apr 26, 2026

Copy link
Copy Markdown
Collaborator

This PR adds support for running Nemotron 120B on Hopper with NVFP4 format, with the multi-GPU support.

Introduce a Hopper-only (SM 9.x) W4A16 NVFP4 execution path backed by the Marlin kernel family. The new backend is strictly opt-in: users select it via moe_config.backend: MARLIN for MoE layers and nvfp4_gemm_config.allowed_backends: [marlin] for dense / Mamba Linear layers. Default paths on Blackwell (CUTLASS / cuBLASLt / CUDA-core / CuteDSL) and the TRT backend are unchanged.

Kernels (cpp/):

  • cpp/tensorrt_llm/kernels/marlin/: W4A16 NVFP4 GEMM, fused MoE GEMM, and GPTQ-style weight repack kernels with BF16 MMA and in-register FP4→BF16 dequant.
  • cpp/tensorrt_llm/thop/marlinNvfp4MM.cpp, marlinNvfp4MoeMM.cpp, marlinRepack.cpp: Torch operator bindings registered as trtllm::marlin_nvfp4_gemm, trtllm::marlin_nvfp4_moe_gemm, and trtllm::gptq_marlin_repack.

Python backend wiring:

  • MarlinNVFP4Runner plugs into NVFP4GemmUnifiedRunner alongside the existing CUTLASS / cuBLASLt / CUDA-core / CuteDSL runners; only contributes tactics when SM is 90-99. Weight repack is done eagerly in get_valid_tactics so that forward() is CUDA-graph safe.
  • MarlinNVFP4LinearMethod handles the dense Linear path, gated by nvfp4_allowed_backends == ["marlin"].
  • MarlinFusedMoE (NVFP4 only) is registered in create_moe, ConfigurableMoE, and MoeConfig.backend literal.
  • Attention / MLP / RMSNorm learn about the Marlin-only mode via a new is_marlin_only gate that disables CUTLASS-specific fused quantized paths which cannot feed a Marlin Linear.

Production correctness:

  • The existing SM 9.x/10.x range for fused_add_rms_norm_quant is preserved; Marlin only further gates it when marlin-only is selected.
  • MLP._use_fused_relu2_quant now requires SM >= 100 (matches the kernel's __CUDA_ARCH__ >= 1000 guard in fusedActivationQuant.cu) and is also disabled for marlin-only mode.
  • Mamba2 flashinfer path additionally requires d_state in {64, 128, 256} so Nemotron-Super-class models fall back to the native path instead of silently running an unsupported config.

Tests:

  • tests/unittest/trt/functional/test_fp4_gemm.py: standalone NVFP4 Marlin GEMM test (Hopper-only).
  • tests/unittest/_torch/thop/parallel/test_fp4_linear.py: Linear nvfp4_allowed_backends=['marlin'] path test.
  • tests/unittest/_torch/modules/moe/test_moe_backend.py: fused Marlin MoE GEMM test plus MoeBackendType.MARLIN wiring in backend/quantize utilities.
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py: TestNemotronHNvFP4Marlin.test_nvfp4_marlin MMLU accuracy task.

examples/configs/curated/nemotron-super-marlin.yaml provides a ready reference serving config.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added Marlin NVFP4 backend for W4A16 GEMM operations optimized for NVIDIA Hopper (SM 90) GPUs.
    • Introduced Marlin-based fused MoE backend for efficient mixture-of-experts inference with BF16 activations and FP4 weights.
    • Added GPTQ weight repacking and scale permutation utilities for Marlin kernel compatibility.
    • Extended configuration options and runner support to select Marlin backend for NVFP4 and MoE operations.
    • Introduced new Torch CUDA extension operators for Marlin GEMM, MoE GEMM, and weight repacking.
    • Added kernel implementations for Marlin NVFP4 GEMM, MoE GEMM, and GPQT repacking with optimized async pipelines and shared memory usage.
    • Added shape inference handlers and custom op bindings for Marlin operators.
    • Enabled model weight processing and runtime logic to work with Marlin backend including linear and fused MoE modules.
  • Tests

    • Added integration and unit tests validating Marlin NVFP4 GEMM and MoE fused kernels against float references.
    • Introduced runtime gating and GPU SM version checks to selectively enable Marlin paths.
    • Added new PyTorch integration tests running NVFP4 Marlin backend on multi-GPU setups.

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)

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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot help

@github-actions

Copy link
Copy Markdown

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental) --high-priority]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Supports wildcard * for pattern matching (e.g., "*PerfSanity*" matches all stages containing PerfSanity). Examples: "A10-PyTorch-1, xxx", "PerfSanity". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Supports wildcard * for pattern matching. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx", --extra-stage "Post-Merge".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

--high-priority (OPTIONAL) : Run the pipeline with high priority. This option is restricted to authorized users only and will route the job to a high-priority queue.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51022 [ run ] triggered by Bot. Commit: 60bdfc3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51022 [ run ] completed with state FAILURE. Commit: 60bdfc3
/LLM/main/L0_MergeRequest_PR pipeline #40469 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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51039 [ run ] triggered by Bot. Commit: 6273287 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51039 [ run ] completed with state SUCCESS. Commit: 6273287
/LLM/main/L0_MergeRequest_PR pipeline #40486 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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51157 [ run ] triggered by Bot. Commit: f554c44 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51157 [ run ] completed with state SUCCESS. Commit: f554c44
/LLM/main/L0_MergeRequest_PR pipeline #40591 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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51181 [ run ] triggered by Bot. Commit: f554c44 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51181 [ run ] completed with state SUCCESS. Commit: f554c44
/LLM/main/L0_MergeRequest_PR pipeline #40611 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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51238 [ run ] triggered by Bot. Commit: 82070d9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51238 [ run ] completed with state SUCCESS. Commit: 82070d9
/LLM/main/L0_MergeRequest_PR pipeline #40661 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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51244 [ run ] triggered by Bot. Commit: 4e913d0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51244 [ run ] completed with state SUCCESS. Commit: 4e913d0
/LLM/main/L0_MergeRequest_PR pipeline #40667 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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51281 [ run ] triggered by Bot. Commit: 4e913d0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51281 [ run ] completed with state SUCCESS. Commit: 4e913d0
/LLM/main/L0_MergeRequest_PR pipeline #40698 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

xuantengh added 10 commits June 23, 2026 21:24
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
Signed-off-by: Xuanteng Huang <xuantengh@nvidia.com>
@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

1 similar comment
@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55410 [ run ] triggered by Bot. Commit: e00b2e9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55410 [ run ] completed with state SUCCESS. Commit: e00b2e9
/LLM/main/L0_MergeRequest_PR pipeline #44353 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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55518 [ run ] triggered by Bot. Commit: 77aaf06 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55518 [ run ] completed with state FAILURE. Commit: 77aaf06
/LLM/main/L0_MergeRequest_PR pipeline #44442 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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55629 [ run ] triggered by Bot. Commit: 77aaf06 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55629 [ run ] completed with state FAILURE. Commit: 77aaf06
/LLM/main/L0_MergeRequest_PR pipeline #44545 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

@xuantengh

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55694 [ run ] triggered by Bot. Commit: 77aaf06 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55694 [ run ] completed with state SUCCESS. Commit: 77aaf06
/LLM/main/L0_MergeRequest_PR pipeline #44598 completed with status: 'SUCCESS'

CI Report

Link to invocation

@shuyixiong
shuyixiong merged commit bcb9441 into NVIDIA:main Jun 25, 2026
7 checks passed
BrianLi23 pushed a commit to BrianLi23/TensorRT-LLM that referenced this pull request Jul 9, 2026
…opper (NVIDIA#13476)

Signed-off-by: Xuanteng Huang <xuantengh@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.