Skip to content

[None][fix] Fix nemotron-h quant and loading config - #16833

Merged
Wanli-Jiang merged 2 commits into
NVIDIA:mainfrom
Wanli-Jiang:user/williamj/check-nano35-main
Jul 28, 2026
Merged

[None][fix] Fix nemotron-h quant and loading config#16833
Wanli-Jiang merged 2 commits into
NVIDIA:mainfrom
Wanli-Jiang:user/williamj/check-nano35-main

Conversation

@Wanli-Jiang

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

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Nemotron-H (Mamba2) weight mapping
    • Updated NemotronHHfWeightMapper.preprocess_weights to split mixer.in_proj.*_scale structurally using an expected d_in_proj dim-0 row-count heuristic (via new _num_rows) rather than checking quant_algo == "NVFP4" / relying on string-based NVFP4 detection.
    • Ensures only per-output-channel block scales that share dim-0 with the in_proj weights get split; per-tensor scalar scales remain unchanged.
    • Added KV duplication override _duplicate_kv_weights so that for replicated k_proj/v_proj weights, companion weight_scale tensors are duplicated when they share the same dim-0 row count as the weight (generalizing beyond NVFP4-only assumptions).
  • lm_head quantization resolution
    • Added _checkpoint_has_lm_head_scale (header check for lm_head.weight_scale) and _resolve_lm_head_quant_config in DecoderModelForCausalLM to centralize/guard when lm_head should be quantized.
    • lm_head quantization is now derived from quant_config_dict["lm_head"] when present; otherwise for homogeneous checkpoints it uses config.quant_config only if the checkpoint actually contains lm_head.weight_scale.
    • Preserved existing guards forcing lm_head back to unquantized when exclude_modules excludes lm_head, tie_word_embeddings is enabled, or enable_attention_dp + enable_lm_head_tp_in_adp makes quantized/packed weights incompatible.
  • Other touched correctness-adjacent areas
    • Updated Mistral processor references in unit tests (Mistral3InputProcessorMistralHFInputProcessor).
    • Adjusted multi-GPU linear tests to remove the “odd hidden_size must raise” expectation.
    • Tweaked microbenchmark MoE routing flags/search pruning and added a GLM-5 model spec.

QA Engineer Review

Test-list changes (CI / QA routing)

  • tests/integration/test_lists/qa/llm_perf_core.yml
    • Reduced reqs for qwen3_30b_a3b-bench-pytorch-bfloat16-maxnt from reqs:256reqs:64.
    • Removed/added several llama_v3.3_nemotron_super_49b performance test entries to reflect timeout/interconnect constraints (notably moving a previously present input_output_len:8000,1000 set and adding it back under a different block with accompanying comments).
  • tests/integration/test_lists/waives.txt
    • Removed SKIPs for:
      • accuracy/test_llm_api_pytorch.py::TestMistralLarge3_675B test_fp8[latency_moe_deepgemm] and test_nvfp4_4gpus[...] cases.
      • full:DGX_H100/.../test_linear.py::test_column_linear[2-unbalanced].
      • unittest/_torch/modeling -k "modeling_qwen" and .../test_modeling_qwen3_5_vl.py::test_qwen35_dense_vl_resolves_mamba_ssm_cache_dtype.
      • unittest/_torch/multi_gpu/test_linear.py::test_row_linear[2-unbalanced].

Verdict: needs follow-up (test-list coverage data / CBTS linkage for the associated changes is not provided here).

Test code changes

  • tests/unittest/_torch/modeling/test_modeling_mistral.py
    • Modified test_processor_get_num_tokens_per_image to use MistralHFInputProcessor.
    • Modified _make_dummy_processor usage to construct MistralHFInputProcessor directly (affecting the dummy-input contract for downstream assertions in test_mistral_attention_swa_layer_types).
  • tests/unittest/_torch/multi_gpu/test_linear.py
    • Modified test_column_linear and test_row_linear to remove conditional failure expectations for odd hidden_size; now asserts all results are True.

Coverage in tests/integration/test_lists/: not determinable from provided context (no mapping from these unit tests to specific CI lists included here).

Verdict: needs follow-up

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
Wanli-Jiang requested a review from a team as a code owner July 24, 2026 08:41
@Wanli-Jiang
Wanli-Jiang requested a review from nv-guomingz July 24, 2026 08:41
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Updates Nemotron-H weight preprocessing to detect structured scale tensors by row count and duplicate compatible KV projection scales. Decoder model initialization now centralizes lm_head quantization selection using checkpoint metadata and model configuration.

Changes

Quantization updates

Layer / File(s) Summary
Nemotron-H weight preprocessing
tensorrt_llm/_torch/models/checkpoints/hf/nemotron_h_weight_mapper.py
Computes the Mamba2 in-projection size, splits structured per-output-row scales while preserving scalar scales, and duplicates matching weight_scale tensors for KV projections across supported quantization formats.
lm_head quantization resolution
tensorrt_llm/_torch/models/modeling_utils.py
Adds checkpoint scale detection and centralized lm_head quantization resolution, including exclusion, tied-embedding, and TP-in-ADP conditions, then uses the result during LMHead construction.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • NVIDIA/TensorRT-LLM#16468: Updates another HF weight mapper to duplicate accompanying KV projection scale tensors for quantized checkpoints.

Suggested reviewers: schetlur-nv

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is mostly the template placeholder and lacks the required issue, solution, and test coverage details. Fill in the Description with the problem and fix, and add Test Coverage entries for the relevant validation cases.
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the PR template and summarizes the main fix to Nemotron-H quantization and loading config.
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

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

@Wanli-Jiang

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61545 [ run ] triggered by Bot. Commit: d8b4bb6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61545 [ run ] completed with state SUCCESS. Commit: d8b4bb6
/LLM/main/L0_MergeRequest_PR pipeline #49757 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 #61572 [ run ] triggered by Bot. Commit: d8b4bb6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

…ckpoints

DecoderModelForCausalLM only resolved the lm_head quant entry from the
per-layer quant_config_dict (MIXED_PRECISION checkpoints). A homogeneous
checkpoint with a single global quant_algo that quantizes lm_head (and
does not exclude it) built lm_head unquantized, so loading its packed
NVFP4 weight failed with a shape mismatch (e.g. Nemotron-Nano-3.5 NVFP4:
'size of tensor a (2688) must match tensor b (1344)').

Resolve lm_head_quant_config from config.quant_config when
quant_config_dict is None and the global config quantizes, and share the
exclude_modules / tie_word_embeddings / lm-head-TP-in-ADP guards across
both sources. No-op for existing models: the MIXED_PRECISION path is
unchanged, and homogeneous checkpoints that keep lm_head in FP16 list it
in exclude_modules, so the exclude guard keeps it unquantized as before.

Verified on Nemotron-Nano-3.5 NVFP4 (W4A16_NVFP4 + FP8 KV) on H100:
single-GPU and 4-GPU attention-DP + EP now load and generate coherently
(with and without MTP).

Signed-off-by: Wanli Jiang <35160485+Wanli-Jiang@users.noreply.github.com>
…ole quant family under GQA+TP

NemotronH weight loading gated per-output-row block-scale handling on the quant
algo (mamba in_proj on quant_algo == "NVFP4"; attention kv-head scale on
has_nvfp4()). Both miss W4A16_NVFP4 and the FP8/MXFP8-scaled tensors in
MIXED_PRECISION (W4A4) checkpoints, so under GQA + TP the mamba in_proj block
scale was not structurally [z,x,B,C,dt]-split while the weight was (garbage
output), and the attention fused-QKV kv weight_scale was not duplicated alongside
the replicated kv weight (load size mismatch 1152 vs 1280).

Detect a per-output-row block scale by shape (shares dim 0 with the weight),
scoped to the NemotronH mapper (override of _duplicate_kv_weights + shape-based
in_proj split), leaving the shared HfWeightMapper base untouched.

Signed-off-by: Wanli Jiang <35160485+Wanli-Jiang@users.noreply.github.com>
@Wanli-Jiang
Wanli-Jiang force-pushed the user/williamj/check-nano35-main branch from d8b4bb6 to 40e733a Compare July 27, 2026 11:53
@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)
tensorrt_llm/_torch/models/checkpoints/hf/nemotron_h_weight_mapper.py (1)

196-210: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Complete the helper type annotations.

_num_rows leaves tensor untyped, and _duplicate_kv_weights uses an unparameterized dict and has no return annotation. As per coding guidelines, “Annotate every function” and “prefer built-in generic types and |.”

🤖 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/models/checkpoints/hf/nemotron_h_weight_mapper.py` around
lines 196 - 210, Complete the annotations for _num_rows and
_duplicate_kv_weights: type the tensor parameter using the appropriate supported
tensor or lazy-slice type, parameterize weights with built-in generic syntax,
and add the correct return annotation to _duplicate_kv_weights. Use | for unions
where applicable and preserve the existing behavior.

Source: Coding guidelines

🤖 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/checkpoints/hf/nemotron_h_weight_mapper.py`:
- Around line 196-232: Update _duplicate_kv_weights to call _num_kv_heads() and
pass its returned integer to _duplicate_kv instead of passing the bound method.
Keep the existing duplication conditions and tensor_parallel_size handling
unchanged.

---

Nitpick comments:
In `@tensorrt_llm/_torch/models/checkpoints/hf/nemotron_h_weight_mapper.py`:
- Around line 196-210: Complete the annotations for _num_rows and
_duplicate_kv_weights: type the tensor parameter using the appropriate supported
tensor or lazy-slice type, parameterize weights with built-in generic syntax,
and add the correct return annotation to _duplicate_kv_weights. Use | for unions
where applicable and preserve the existing behavior.
🪄 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: eca1dc7e-1ff9-451e-bc3c-5929aa8b9ec9

📥 Commits

Reviewing files that changed from the base of the PR and between d8b4bb6 and 40e733a.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/models/checkpoints/hf/nemotron_h_weight_mapper.py
  • tensorrt_llm/_torch/models/modeling_utils.py

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61903 [ run ] triggered by Bot. Commit: 40e733a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61903 [ run ] completed with state FAILURE. Commit: 40e733a
/LLM/main/L0_MergeRequest_PR pipeline #50094 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 #62034 [ run ] triggered by Bot. Commit: 40e733a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62034 [ run ] completed with state SUCCESS. Commit: 40e733a
/LLM/main/L0_MergeRequest_PR pipeline #50221 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 #62116 [ run ] triggered by Bot. Commit: 40e733a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62116 [ run ] completed with state SUCCESS. Commit: 40e733a
/LLM/main/L0_MergeRequest_PR pipeline #50298 completed with status: 'SUCCESS'

CI Report

Link to invocation

@Wanli-Jiang
Wanli-Jiang merged commit becf773 into NVIDIA:main Jul 28, 2026
10 checks passed
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