Skip to content

[None][fix] Load DeepSeek V4 mixed-precision NVFP4 checkpoints#16433

Merged
lfr-0531 merged 7 commits into
NVIDIA:mainfrom
lfr-0531:user/fanrongl/dsv4-nvfp4-mixed-precision-20260715
Jul 23, 2026
Merged

[None][fix] Load DeepSeek V4 mixed-precision NVFP4 checkpoints#16433
lfr-0531 merged 7 commits into
NVIDIA:mainfrom
lfr-0531:user/fanrongl/dsv4-nvfp4-mixed-precision-20260715

Conversation

@lfr-0531

@lfr-0531 lfr-0531 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai summary

Description

The nvidia/DeepSeek-V4-Pro-NVFP4 Hugging Face checkpoint uses a global MIXED_PRECISION quantization configuration, FP8 block-scale weights for non-routed-expert modules, and layer-specific NVFP4 configurations for routed experts. DeepSeek V4 previously rejected the global configuration during decoder initialization. After removing that rejection, loading the actual checkpoint also showed that the global mixed-precision setting caused FP8 base modules to be constructed without their required block-scale parameters.

Following the per-module resolution approach in #12149, this PR keeps the routed experts' layer-specific NVFP4 configuration while disabling ambiguous layer-level NVFP4 fusions. For DeepSeek V4 checkpoints whose inline Hugging Face configuration declares FP8 128x128 block scales, it resolves the non-expert/base configuration to FP8_BLOCK_SCALES, preserves runtime-populated quantization fields, and retains the NVFP4 expert entries in quant_config_dict.

Regression tests cover both decoder construction with mixed-precision NVFP4 experts and FP8 base-config resolution, including cached quantization modes and the runtime torch.dtype cache field. The change is model-specific and does not alter public APIs or add dependencies.

Related PR: #12149

Test Coverage

  • Full build/install from this branch:
    • python scripts/build_wheel.py --trt_root /usr/local/tensorrt --micro_benchmarks --use_ccache --cuda_architectures '90-real;100-real' --configure_cmake --job_count 64 --install --yes (passed)
    • Verified imports resolve to this worktree's tensorrt_llm, modeling_deepseekv4.py, and rebuilt bindings.cpython-312-x86_64-linux-gnu.so.
  • DeepSeek V4 unit tests on an idle B200:
    • pytest -q tests/unittest/_torch/modeling/test_modeling_deepseekv4.py -k 'mixed_precision or fused_a_weight_scale or routed_moe_quant_config' (7 passed, 26 deselected)
    • pytest -q tests/unittest/_torch/modeling/test_modeling_deepseekv4.py (33 passed)
  • Existing quant-config regression coverage:
    • pytest -c tests/unittest/pytest.ini tests/unittest/llmapi/test_llm_quant.py -k "quant_cfg_from_quant_cfg_json or quant_cfg_top_level_overlay or quant_cfg_from_hf_quant_config or mixed_precision_kv_cache_conflict" -q (4 passed)
  • Actual checkpoint load on 8 idle NVIDIA B200 GPUs:
    • Model: nvidia/DeepSeek-V4-Pro-NVFP4, Hugging Face revision 1449d1e641023406daf6b432361486c768aad740
    • PyTorch backend with TP8/EP8; all 64/64 safetensors shards and 2686/2686 parameters loaded on every rank.
    • LLM(...) completed with LOAD_OK elapsed_seconds=687.9, followed by SHUTDOWN_OK.
  • pre-commit run --files tensorrt_llm/_torch/models/modeling_deepseekv4.py tests/unittest/_torch/modeling/test_modeling_deepseekv4.py (passed)

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.

Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
@lfr-0531
lfr-0531 requested a review from a team as a code owner July 15, 2026 14:26
@lfr-0531
lfr-0531 requested a review from WeiHaocheng July 15, 2026 14:26
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

DeepSeek v4 decoder layers now handle mixed-precision quantization without asserting, disabling layer-level NVFP4 when appropriate. A unit test verifies the decoder flag, MoE quantization override, and routed-expert quantization configuration.

Changes

DeepSeek v4 mixed-precision quantization

Layer / File(s) Summary
Mixed-precision NVFP4 gating and validation
tensorrt_llm/_torch/models/modeling_deepseekv4.py, tests/unittest/_torch/modeling/test_modeling_deepseekv4.py
Decoder-layer NVFP4 is enabled only for non-mixed-precision algorithms, and a mocked unit test validates global and routed-expert quantization configuration.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: weihaocheng, jiaganc

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title is concise, follows the repository template, and accurately summarizes the main change.
Description check ✅ Passed The description includes the required Description, Test Coverage, and PR Checklist sections and is sufficiently detailed.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

🧹 Nitpick comments (1)
tests/unittest/_torch/modeling/test_modeling_deepseekv4.py (1)

447-503: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Coverage is sufficient for the changed gating behavior.

The test correctly isolates and validates the new is_nvfp4 mixed-precision gating and the interaction with _get_experts_quant_config's per-expert override, using the module-attribute monkeypatch trick so the direct DeepseekV4MoE._get_experts_quant_config call at line 503 still exercises the real implementation. This is sufficient coverage for the code change in modeling_deepseekv4.py.

One untested edge case (pre-existing, not touched by this PR): the MTP-excluded-layer branch (is_module_excluded_from_quantization) combined with a MIXED_PRECISION global config. Low risk since that path already resolves quant_algo=None regardless, but could be added as a follow-up if maintainers want explicit regression coverage for that combination.

As per path instructions, "Act as a QA engineer reviewing test changes and coverage for TensorRT-LLM... suggest concrete list file names and whether coverage is sufficient, insufficient, or needs follow-up outside the PR."

🤖 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/modeling/test_modeling_deepseekv4.py` around lines 447
- 503, Coverage for the mixed-precision expert gating and per-expert override is
sufficient; no code changes are required. Optionally record the
MTP-excluded-layer combined with MIXED_PRECISION scenario as follow-up coverage
outside this PR, targeting the existing DeepseekV4 modeling test file.

Source: 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.

Nitpick comments:
In `@tests/unittest/_torch/modeling/test_modeling_deepseekv4.py`:
- Around line 447-503: Coverage for the mixed-precision expert gating and
per-expert override is sufficient; no code changes are required. Optionally
record the MTP-excluded-layer combined with MIXED_PRECISION scenario as
follow-up coverage outside this PR, targeting the existing DeepseekV4 modeling
test file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 03219f51-8187-4120-ac91-0ad72132a39b

📥 Commits

Reviewing files that changed from the base of the PR and between 0846183 and d1bbd17.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/models/modeling_deepseekv4.py
  • tests/unittest/_torch/modeling/test_modeling_deepseekv4.py

@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59640 [ run ] triggered by Bot. Commit: d1bbd17 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59640 [ run ] completed with state SUCCESS. Commit: d1bbd17
/LLM/main/L0_MergeRequest_PR pipeline #48077 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 Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59743 [ run ] triggered by Bot. Commit: d1bbd17 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59743 [ run ] completed with state SUCCESS. Commit: d1bbd17
/LLM/main/L0_MergeRequest_PR pipeline #48167 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 Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60211 [ run ] triggered by Bot. Commit: db008e4 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60211 [ run ] completed with state FAILURE. Commit: db008e4
/LLM/main/L0_MergeRequest_PR pipeline #48585 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 Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60295 [ run ] triggered by Bot. Commit: db008e4 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60295 [ run ] completed with state FAILURE. Commit: db008e4
/LLM/main/L0_MergeRequest_PR pipeline #48647 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 Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60541 [ run ] triggered by Bot. Commit: 0bfbd51 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60541 [ run ] completed with state SUCCESS. Commit: 0bfbd51
/LLM/main/L0_MergeRequest_PR pipeline #48857 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 added 2 commits July 21, 2026 13:21
Treat the non-expert weights in DeepSeek V4 NVFP4 checkpoints as
FP8 block-scale weights while retaining the per-layer NVFP4 expert
configuration.

Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
@lfr-0531
lfr-0531 requested a review from a team as a code owner July 21, 2026 15:21
lfr-0531 added 2 commits July 21, 2026 15:39
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60718 [ run ] triggered by Bot. Commit: 9811652 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60718 [ run ] completed with state FAILURE. Commit: 9811652
/LLM/main/L0_MergeRequest_PR pipeline #49006 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 Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60837 [ run ] triggered by Bot. Commit: 9811652 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60837 [ run ] completed with state SUCCESS. Commit: 9811652
/LLM/main/L0_MergeRequest_PR pipeline #49114 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 Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60904 [ run ] triggered by Bot. Commit: 9811652 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60904 [ run ] completed with state SUCCESS. Commit: 9811652
/LLM/main/L0_MergeRequest_PR pipeline #49173 completed with status: 'SUCCESS'

CI Report

Link to invocation

@lfr-0531
lfr-0531 merged commit f52f3fe into NVIDIA:main Jul 23, 2026
7 checks passed
hhzhang16 added a commit to hhzhang16/TensorRT-LLM that referenced this pull request Jul 23, 2026
…nnahz/dep-1083-port-flashinfer-stable-va-lifecycle-for-native-all-reduce

* 'main' of https://github.com/NVIDIA/TensorRT-LLM: (83 commits)
  [None][feat] Bind SourceIdentity to checkpoint artifacts (NVIDIA#16159)
  [None][infra] Waive 4 failed cases for main in pre-merge 49550 (NVIDIA#16798)
  [None][fix] Make FlashInfer sampling op wrappers opaque to Dynamo (NVIDIA#16732)
  [None][feat] top-k: route decode to CuTe DSL GVR top-k in e2e (NVIDIA#16420)
  [None][feat] Default GLM-5 to the Python KV-cache transceiver (NVIDIA#16524)
  [None][chore] Add NVTX ranges to per-iteration ADP sync points in PyExecutor (NVIDIA#16422)
  [https://nvbugs/6426850][test] Unwaive Qwen3.5 397B NVFP4 ADP4 TRTLLM test (NVIDIA#16348)
  [https://nvbugs/6445456][fix] Restore inplace ops for functionalization v2 (NVIDIA#16410)
  [None][infra] Waive 1 failed cases for main in pre-merge 49229 (NVIDIA#16786)
  [None][fix] Load DeepSeek V4 mixed-precision NVFP4 checkpoints (NVIDIA#16433)
  [None][feat] ADP conversation router: configurable least-queued placement for new conversations (NVIDIA#16294)
  [None][infra] Waive 1 failed cases for main in pre-merge 49424 (NVIDIA#16780)
  [None][infra] Waive 1 failed cases for main in pre-merge 49424 (NVIDIA#16781)
  [TRTLLMINF-188][infra] Require approval for PerfSanity wildcard runs (NVIDIA#16777)
  [TRTLLM-13969][feat] Support MiniMax M3 for Disaggregated Serving (NVIDIA#16017)
  [NVIDIA#11932][fix] Filter CUTLASS MoE GEMM tile configs by device shared memory on SM121 (NVIDIA#12704)
  [None][chore] Remove attention backend test waivers (NVIDIA#16723)
  [TRTLLM-14540][perf] Skip fp32 state round-trip in FlashInfer GDN pre… (NVIDIA#16703)
  [TRTLLM-13694][feat] Add IBDB recipe provenance and refresh configs (NVIDIA#16254)
  [None][infra] Preview/bump/main (NVIDIA#16758)
  ...

Signed-off-by: Hannah Zhang <hannahz@nvidia.com>
yuanjingx87 pushed a commit to yuanjingx87/TensorRT-LLM that referenced this pull request Jul 26, 2026
…A#16433)

Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Co-authored-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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants