Skip to content

[None][feat] Enable MEGAMOE_DEEPGEMM backend for DeepSeek V4#14129

Merged
Tabrizian merged 1 commit into
NVIDIA:feat/deepseek_v4from
Barry-Delaney:feat/deepseek_v4_megamoe
May 14, 2026
Merged

[None][feat] Enable MEGAMOE_DEEPGEMM backend for DeepSeek V4#14129
Tabrizian merged 1 commit into
NVIDIA:feat/deepseek_v4from
Barry-Delaney:feat/deepseek_v4_megamoe

Conversation

@Barry-Delaney

Copy link
Copy Markdown
Collaborator

Enables MegaMoE backend on DeepSeek-V4 and added related CI tests.

V4-Flash routed experts use the MXFP4 byte layout that MegaMoEDeepGemm's
fused fp8_fp4_mega_moe kernel was designed for, but several wiring gaps
kept users from selecting the backend end-to-end:

- llmapi: MoeConfig.backend Literal omitted "MEGAMOE_DEEPGEMM", so YAML
  overrides via --extra_llm_api_options failed Pydantic validation
  before any backend code ran.

- create_moe: the model unconditionally forwards swiglu_limit_scalar
  (V4-Flash uses uniform SwiGLU clamp), but the allow-list assert and
  per-backend dispatch never threaded it through MegaMoEDeepGemm. Add
  MegaMoEDeepGemm to the assert (with explicit per-expert-tensor
  rejection, since DG only supports the scalar form) and map
  swiglu_limit_scalar -> activation_clamp in the dispatch branch.

- mega_moe_deepgemm: _resolve_ep_pg required torch.distributed to be
  initialized, which is the Ray / DeviceMesh contract. TRT-LLM's default
  executor uses raw mpi4py and never calls init_process_group. Add an
  MPI fallback that, when dist is uninitialized, derives rank /
  world_size from MPI.COMM_WORLD, picks an intra-node local rank via
  Split_type(COMM_TYPE_SHARED) with OMPI_COMM_WORLD_LOCAL_RANK env-var
  fallback, uses setdefault for the four rendezvous vars so Slurm / Ray /
  torchrun setups stay intact, bcasts MASTER_ADDR / MASTER_PORT, and
  wraps init_process_group with one retry on a fresh port to absorb
  the close() -> NCCL bind() race on busy hosts.

- can_implement: accept SM100-family (SM100 + SM103). DG's
  fp8_fp4_mega_moe cubin is sm_100f SASS, compatible with both B200 and
  B300.

- quantization: in W4A8MXFP4MXFP8MegaMoEDeepGemmMethod._transform_main_weights,
  free the three raw checkpoint Parameters (w3_w1_weight,
  w3_w1_weight_scale, w2_weight_scale) after the DG transform builds
  the DG-form _t_l1 / _t_l2 views. DG allocates fresh storage for L1
  (interleaved) and both SF tensors, so those are pure duplicates; L2
  weight is passed through unchanged and stays alive via _t_l2[0].
  data_ptr asserts guard the invariant so a future DG that view-passes
  L1 surfaces here at model-build time instead of dangling at forward.
  Frees ~560 MB/layer => ~24 GiB/rank on V4-Flash (43 MoE layers, EP=4),
  enough headroom for the 8.69 GiB combine_token_buffer SymmBuffer
  introduced by DG nv_dev_67fc648.

- tests: parametrize TestDeepSeekV4Flash::test_nvfp4_4gpus_static_eplb
  with the new MEGAMOE_DEEPGEMM backend and register it in
  l0_dgx_b300_ds.yml. The TP=4 EP=4 attention-DP layout is the one
  validated below; this enforces the end-to-end wire-up so a future
  config-plumbing regression cannot slip through silently.

Validated on DeepSeek-V4-Flash, B200 TP=4 EP=4 attention-DP:
- gsm8k 1319 samples = 95.49 % (TRTLLM ref 95.11 %).
- trtllm-bench ISL=1024 OSL=1024 500 reqs: +15.3 % throughput and
  -12.7 % latency vs TRTLLM MoE backend on the same model and config.

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
@Barry-Delaney Barry-Delaney self-assigned this May 14, 2026
@Barry-Delaney
Barry-Delaney requested review from a team as code owners May 14, 2026 08:29
@Barry-Delaney
Barry-Delaney requested review from HuiGao-NV and schetlur-nv and removed request for a team May 14, 2026 08:29
@Barry-Delaney Barry-Delaney changed the title [None][feat] Enable MEGAMOE_DEEPGEMM backend for DeepSeek V4-Flash [None][feat] Enable MEGAMOE_DEEPGEMM backend for DeepSeek V4 May 14, 2026
@Barry-Delaney
Barry-Delaney requested review from a team and lfr-0531 May 14, 2026 08:30
@Barry-Delaney

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48338 [ run ] triggered by Bot. Commit: 867402f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48338 [ run ] completed with state SUCCESS. Commit: 867402f
/LLM/main/L0_MergeRequest_PR pipeline #38146 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

@Barry-Delaney

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48384 [ run ] triggered by Bot. Commit: 867402f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48384 [ run ] completed with state SUCCESS. Commit: 867402f
/LLM/main/L0_MergeRequest_PR pipeline #38188 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

@lfr-0531

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48403 [ run ] triggered by Bot. Commit: 867402f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48403 [ run ] completed with state SUCCESS. Commit: 867402f
/LLM/main/L0_MergeRequest_PR pipeline #38206 completed with status: 'SUCCESS'

CI Report

Link to invocation

@Tabrizian
Tabrizian merged commit 7964767 into NVIDIA:feat/deepseek_v4 May 14, 2026
9 checks passed
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request May 29, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
(cherry picked from commit 7964767)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 1, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
(cherry picked from commit 7964767)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 3, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
(cherry picked from commit 7964767)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 7, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
(cherry picked from commit 7964767)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 10, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 11, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 12, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 12, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
(cherry picked from commit 7964767)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 13, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
(cherry picked from commit 7964767)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 16, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
(cherry picked from commit 7964767)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 17, 2026
…14129)

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
(cherry picked from commit 7964767)
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants