Skip to content

[DeepSeek-V4][fix] Detect MTP routed-expert layout separately#16276

Open
waynehacking8 wants to merge 1 commit into
NVIDIA:mainfrom
waynehacking8:wayne/fix-16196-fused-a-dequant
Open

[DeepSeek-V4][fix] Detect MTP routed-expert layout separately#16276
waynehacking8 wants to merge 1 commit into
NVIDIA:mainfrom
waynehacking8:wayne/fix-16196-fused-a-dequant

Conversation

@waynehacking8

@waynehacking8 waynehacking8 commented Jul 11, 2026

Copy link
Copy Markdown

Description

#16433 merged the base mixed-precision construction and loading fix for nvidia/DeepSeek-V4-Pro-NVFP4, superseding the earlier construction commits in this PR. This PR now contains only the remaining MTP-specific fix, authored by @d3nb.

The checkpoint stores dense routed experts as NVFP4 (U8) but leaves MTP routed experts at the base model's MXFP4 layout (I8). _set_deepseek_v4_routed_moe_quant_config() previously detected one layout from layers.0 and assigned it to every MoE layer, so MTP speculative decoding received NVFP4 configuration and crashed in fused_moe scale loading.

The loader now probes the MTP expert header separately and assigns MXFP4 or NVFP4 configuration to the MTP layer range only when its layout differs from the dense experts. Matching or absent MTP headers retain the existing dense configuration.

Related: #16196, #16433.

Test Coverage

  • @d3nb validated the equivalent change on the actual 851 GB nvidia/DeepSeek-V4-Pro-NVFP4 checkpoint using 4x B300, TP4, and the TRT-LLM MoE backend.
  • Weights loaded completely, the server generated successfully with MTP=1 and MTP=3, and observed MTP acceptance length was approximately 2.86.
  • The original commit and authorship are preserved after rebasing onto current main.

PR Checklist

  • Scope reflects the remaining non-superseded fix
  • Commit is signed off
  • Validated on real weights and hardware

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

DeepSeek V4 mixed-precision handling now derives FP8 block-scale configurations, dequantizes fused-A weights for unquantized destinations, and applies consistent quantization settings to attention, shared-expert, and MTP projections.

Changes

DeepSeek V4 mixed-precision quantization

Layer / File(s) Summary
Mixed-precision configuration resolution
tensorrt_llm/_torch/models/modeling_deepseekv4.py
Adds helpers for FP8 block-scale configuration and updates per-layer expert quantization resolution.
Fused-A weight loading
tensorrt_llm/_torch/models/modeling_deepseekv4.py
Dequantizes fused-A checkpoint weights when the destination module lacks weight_scale.
Projection quantization wiring
tensorrt_llm/_torch/models/modeling_deepseekv4.py
Applies derived mixed-precision configuration to attention, shared-expert, and MTP projections.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% 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
Linked Issues check ✅ Passed The changes match #16196 by fixing excluded-module FP8 loading, per-layer NVFP4 selection, and checkpoint-native expert key handling.
Out of Scope Changes check ✅ Passed The modified loader and quantization paths all support the DeepSeek-V4 NVFP4 loading fix; no unrelated code changes are evident.
Title check ✅ Passed The title is concise and accurately describes the remaining fix: detecting MTP routed-expert layout separately.
Description check ✅ Passed The description follows the template well, with clear problem/solution, test coverage, and checklist notes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

waynehacking8 added a commit to waynehacking8/TensorRT-LLM that referenced this pull request Jul 11, 2026
Addresses the CodeRabbit docstring-coverage warning on NVIDIA#16276.

Signed-off-by: WEI CHENG CHIU <waynehacking8@gmail.com>
@waynehacking8
waynehacking8 requested a review from a team as a code owner July 12, 2026 08:57
waynehacking8 added a commit to waynehacking8/TensorRT-LLM that referenced this pull request Jul 18, 2026
Addresses the CodeRabbit docstring-coverage warning on NVIDIA#16276.

Signed-off-by: WEI CHENG CHIU <waynehacking8@gmail.com>
@waynehacking8
waynehacking8 force-pushed the wayne/fix-16196-fused-a-dequant branch from 5816fa5 to e64f1a0 Compare July 18, 2026 02:25
@waynehacking8
waynehacking8 requested review from a team as code owners July 18, 2026 02:25
@mikeiovine
mikeiovine requested review from mikeiovine and removed request for schetlur-nv July 20, 2026 15:30
@waynehacking8
waynehacking8 force-pushed the wayne/fix-16196-fused-a-dequant branch from e64f1a0 to 0113873 Compare July 27, 2026 01:25
…MXFP4)

The ModelOpt experts-only NVFP4 repacks (e.g. nvidia/DeepSeek-V4-Pro-NVFP4)
re-quantize only the dense routed experts to NVFP4 (U8) and leave the MTP
routed experts at the base model's MXFP4 (I8). _set_deepseek_v4_routed_moe_
quant_config detected a single layout from layers.0 and applied it to every
MoE layer including the MTP layer, so the MTP experts got NVFP4 and crashed in
fused_moe load_quant_scales. Detect the MTP expert dtype separately and assign
the MTP layer indices the correct (MXFP4) config.

Validated end-to-end on real weights: nvidia/DeepSeek-V4-Pro-NVFP4 on 4x B300,
TP4, moe_backend=TRTLLM, rc15.post1 (equivalent change), with the construction
fix from 3972f5e: loads 100% + serves + generates, MTP=1 and MTP=3
(mtp_eagle_one_model builds one shared MTP layer). MTP accept_len ~2.86.

Signed-off-by: d3nb <wanxiren@gmail.com>
@waynehacking8
waynehacking8 force-pushed the wayne/fix-16196-fused-a-dequant branch from 0113873 to bbb07f9 Compare July 27, 2026 01:26
@waynehacking8 waynehacking8 changed the title [#16196][fix] Support MIXED_PRECISION experts-only NVFP4 DeepSeek-V4 checkpoints [DeepSeek-V4][fix] Detect MTP routed-expert layout separately Jul 27, 2026
@waynehacking8

Copy link
Copy Markdown
Author

@mikeiovine I rebased onto current main after #16433 and narrowed the PR to the remaining MTP layout commit; it is mergeable and DCO is green. When convenient, could you trigger /bot run for the rebuilt head?

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