Skip to content

[minor] fix for GLM4.7 mtp module in PTQ#1630

Merged
Fridah-nv merged 2 commits into
mainfrom
fridah/nvbug-6108133
Jun 5, 2026
Merged

[minor] fix for GLM4.7 mtp module in PTQ#1630
Fridah-nv merged 2 commits into
mainfrom
fridah/nvbug-6108133

Conversation

@Fridah-nv
Copy link
Copy Markdown
Contributor

@Fridah-nv Fridah-nv commented Jun 4, 2026

What does this PR do?

Type of change: Bug fix

_keys_to_prefixes now drops a top-level "model" key fragment instead of emitting it as a prefix. Without this guard, an inlined-MTP key like model.layers.92.eh_proj.weight would emit "model" → exporter wraps it as "model*" in quantization_config.exclude_modulesfnmatch in TRT-LLM matches every model.layers.X.* module → entire backbone is treated as unquantized → FP8 weights get loaded into BF16 buffers via .view(bf16) (which halves the last dim of an FP8 tensor) → loader crashes with tensor a (5120) must match tensor b (2560) at non-singleton dimension 1.

The main-branch caller in load_mtp_weights (PR #1532) already filters inlined keys before invoking _keys_to_prefixes, so this guard is defense-in-depth on main today. It freezes the invariant in code rather than as a docstring caveat — the same regression cannot return if a future caller forgets to filter. Adds a focused unit test that pins the behavior.

Usage

# Add a code snippet demonstrating how to use this

Testing

  • New unit test tests/examples/llm_ptq/test_example_utils.py::test_keys_to_prefixes_drops_model_top_level: passes with this PR, would fail without the guard.

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: ✅
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: N/A
  • Did you get Claude approval on this PR?: ✅

Additional Information

Summary by CodeRabbit

  • Bug Fixes

    • Fixed prefix handling in LLM post-training quantization examples: the top-level "model" prefix is now omitted when deriving exclusion prefixes to avoid overly broad wildcard exclusions.
  • Tests

    • Added test coverage verifying correct conversion of tensor keys to exclusion prefixes, including cases with top-level "model" keys.

Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
@Fridah-nv Fridah-nv requested a review from a team as a code owner June 4, 2026 21:03
@Fridah-nv Fridah-nv requested a review from Edwardf0t1 June 4, 2026 21:03
@Fridah-nv
Copy link
Copy Markdown
Contributor Author

/claude review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

PR changed again? Review this PR in Change Stack to compare snapshots and stay oriented.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 73b6f36c-5b49-4c99-bf05-f10919dc0ace

📥 Commits

Reviewing files that changed from the base of the PR and between a58c571 and 78a897d.

📒 Files selected for processing (1)
  • examples/llm_ptq/example_utils.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/llm_ptq/example_utils.py

📝 Walkthrough

Walkthrough

Updated _keys_to_prefixes in examples/llm_ptq/example_utils.py to skip the top-level "model" segment when deriving module-exclude prefixes; docstring updated and a unit test added to validate behavior with mixed mtp.* and inlined model.* keys.

Changes

Top-level model prefix exclusion in key conversion

Layer / File(s) Summary
Fix _keys_to_prefixes to drop model top-level prefix and add validation test
examples/llm_ptq/example_utils.py, tests/examples/llm_ptq/test_example_utils.py
_keys_to_prefixes now omits the top-level "model" segment when generating module-exclude prefixes (docstring updated). New test test_keys_to_prefixes_drops_model_top_level verifies the function returns expected prefixes for mixed "mtp.*" and inlined "model.layers.<n>.*" keys.

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

Suggested reviewers:

  • ChenhanYu
  • yueshen2016
  • claude
🚥 Pre-merge checks | ✅ 4 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions 'GLM4.7 mtp module' but the actual change is a general fix to _keys_to_prefixes logic that drops the top-level 'model' prefix, not specific to GLM4.7 or mtp modules. Consider a more accurate title that describes the actual change, such as 'Fix _keys_to_prefixes to drop top-level model prefix' or 'Fix model prefix handling in _keys_to_prefixes for PTQ'.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Security Anti-Patterns ✅ Passed No security anti-patterns detected. Changes modify _keys_to_prefixes() function and add test; no unsafe deserialization, code execution, hardcoded values, or dependencies.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fridah/nvbug-6108133

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.60%. Comparing base (6b73e93) to head (78a897d).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1630      +/-   ##
==========================================
- Coverage   77.38%   76.60%   -0.78%     
==========================================
  Files         482      488       +6     
  Lines       52960    55032    +2072     
==========================================
+ Hits        40984    42159    +1175     
- Misses      11976    12873     +897     
Flag Coverage Δ
examples 43.13% <ø> (+1.13%) ⬆️
unit 54.00% <ø> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@Edwardf0t1 Edwardf0t1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Comment thread examples/llm_ptq/example_utils.py Outdated
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
@Fridah-nv Fridah-nv merged commit de52597 into main Jun 5, 2026
40 checks passed
@Fridah-nv Fridah-nv deleted the fridah/nvbug-6108133 branch June 5, 2026 20:23
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-06-05 20:23 UTC

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.

2 participants