Skip to content

[None][feat] Support llm-compressor compressed-tensors NVFP4 checkpoi… - #16447

Open
jhaotingc wants to merge 1 commit into
NVIDIA:mainfrom
jhaotingc:redhat-ckpt-pr
Open

jhaotingc wants to merge 1 commit into
NVIDIA:mainfrom
jhaotingc:redhat-ckpt-pr

Conversation

@jhaotingc

@jhaotingc jhaotingc commented Jul 15, 2026 •

Copy link
Copy Markdown
Collaborator
pareto_2ckpt_conc

The diff comes from RedHat didn't quantize QKV B A layers.

The Qwen3.5/3.6 loader assumed ModelOpt-style NVFP4 tensor names (weight / weight_scale / weight_scale
_2 / input_scale). llm-compressor (compressed-tensors, "nvfp4-pack-quantized") names the same tensors weight_packed / weight_scale / weight_global_scale / input_global_scale, so the fused-MoE and Linear NVFP4 loaders could not find the expert weights and asserted (w1_weight is not None).

Normalize compressed-tensors NVFP4 names to the ModelOpt names in _Qwen3_5VLModel.load_weights. The per-group FP8 weight_scale is byte-identical between the two formats and is left unchanged; the two global FP32 scalars are reciprocals -- compressed-tensors stores a quantization scale, ModelOpt a dequantization scale -- so they are inverted on rename (weight_scale_2 = 1/weight_global_scale, input_scale = 1/input_global_scale). The pass is guarded on the presence of a "*.weight_packed" key, so ModelOpt checkpoints (e.g. NVIDIA Qwen3.6-NVFP4) pass through untouched.

Validated on RedHatAI/Qwen3.6-35B-A3B-NVFP4 (B200, TP1, TRTLLM MoE): the model loads and produces coherent output (17*23=391); the NVIDIA Qwen3.6-NVFP4 path is unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Improved loading of Qwen3.5 vision-language model checkpoints using NVFP4 quantization.
    • Added compatibility for compressed tensor naming and scale formats, helping ensure quantized weights and their associated scaling data load correctly.

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.

@jhaotingc
jhaotingc requested a review from a team as a code owner July 15, 2026 19:11
@jhaotingc
jhaotingc requested a review from kaiyux July 15, 2026 19:11
@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds compressed-tensors NVFP4 weight-name and scale normalization for Qwen3.5 VL checkpoints, applying it to filtered weights before they are passed to the inner LLM loader.

Changes

Qwen3.5 NVFP4 loading

Layer / File(s) Summary
Normalize compressed-tensors weights before loading
tensorrt_llm/_torch/models/modeling_qwen3_5.py
Adds NVFP4 tensor-name remapping, scale inversion, and packed-weight renaming, then applies the normalization during Qwen3.5 VL weight loading.

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

Suggested reviewers: kaiyux, moraxu

🚥 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 clearly related to the main change: adding llm-compressor NVFP4 compressed-tensors support.
Description check ✅ Passed The description explains the problem, solution, and validation, but the Test Coverage section is not explicitly filled out.
✨ 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)
tensorrt_llm/_torch/models/modeling_qwen3_5.py (1)

656-696: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a unit test for the key/scale-remapping logic.

The suffix-matching and scale-inversion logic is intricate (mutually-exclusive suffix checks, dtype round-tripping through float()) and silently produces wrong dequantization scales if it ever regresses — there's no test guarding this critical load-time transform.

Example test sketch
def test_normalize_compressed_tensors_names():
    weights = {
        "a.weight_packed": torch.zeros(4, dtype=torch.uint8),
        "a.weight_scale": torch.tensor(2.0),
        "a.weight_global_scale": torch.tensor(4.0),
        "a.input_global_scale": torch.tensor(8.0),
    }
    out = _normalize_compressed_tensors_names(weights)
    assert set(out) == {"a.weight", "a.weight_scale", "a.weight_scale_2", "a.input_scale"}
    assert out["a.weight_scale_2"].item() == 0.25
    assert out["a.input_scale"].item() == 0.125
    assert out["a.weight_scale"].item() == 2.0  # unchanged
🤖 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/modeling_qwen3_5.py` around lines 656 - 696, Add a
unit test for _normalize_compressed_tensors_names covering weight_packed
renaming, unchanged weight_scale, and both global-scale suffix remappings with
reciprocal values. Verify the output keys exactly and assert the inverted scales
preserve the input tensor dtype after float-based computation.
🤖 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 `@tensorrt_llm/_torch/models/modeling_qwen3_5.py`:
- Around line 656-696: Add a unit test for _normalize_compressed_tensors_names
covering weight_packed renaming, unchanged weight_scale, and both global-scale
suffix remappings with reciprocal values. Verify the output keys exactly and
assert the inverted scales preserve the input tensor dtype after float-based
computation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a2910503-ebed-4483-961c-5e280ee3999f

📥 Commits

Reviewing files that changed from the base of the PR and between 287c12a and 408e9de.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/models/modeling_qwen3_5.py

@jhaotingc

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59524 [ run ] triggered by Bot. Commit: 408e9de Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59524 [ run ] completed with state SUCCESS. Commit: 408e9de
/LLM/main/L0_MergeRequest_PR pipeline #47977 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

@jhaotingc

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59757 [ run ] triggered by Bot. Commit: c5c408a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

…nts for Qwen3.5/3.6

The Qwen3.5/3.6 loader assumed ModelOpt-style NVFP4 tensor names
(weight / weight_scale / weight_scale_2 / input_scale). llm-compressor
(compressed-tensors, "nvfp4-pack-quantized") names the same tensors
weight_packed / weight_scale / weight_global_scale / input_global_scale,
so the fused-MoE and Linear NVFP4 loaders could not find the expert
weights and asserted (`w1_weight is not None`).

Normalize compressed-tensors NVFP4 names to the ModelOpt names in
`_Qwen3_5VLModel.load_weights`. The per-group FP8 `weight_scale` is
byte-identical between the two formats and is left unchanged; the two
global FP32 scalars are reciprocals -- compressed-tensors stores a
quantization scale, ModelOpt a dequantization scale -- so they are
inverted on rename (weight_scale_2 = 1/weight_global_scale,
input_scale = 1/input_global_scale). The pass is guarded on the
presence of a "*.weight_packed" key, so ModelOpt checkpoints (e.g.
NVIDIA Qwen3.6-NVFP4) pass through untouched.

Validated on RedHatAI/Qwen3.6-35B-A3B-NVFP4 (B200, TP1, TRTLLM MoE):
the model loads and produces coherent output (17*23=391); the NVIDIA
Qwen3.6-NVFP4 path is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Jhao-Ting Chen <[email protected]>
@jhaotingc

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59780 [ run ] triggered by Bot. Commit: 9192a16 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59780 [ run ] completed with state FAILURE. Commit: 9192a16
/LLM/main/L0_MergeRequest_PR pipeline #48205 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

@brnguyen2 brnguyen2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The rename/inversion direction is right and matches the existing precedent in tensorrt_llm/_torch/models/modeling_laguna.py:592 (LagunaHfWeightMapper.preprocess_weights), which does the identical compressed-tensors→ModelOpt NVFP4 translation. Worth reusing that code rather than duplicating it — it also carries a guard this version drops (see inline).

Two things beyond the code:

  • The description covers only the weight-name normalization. About a third of the diff — _regex_targets_mtp and the re: branch in _normalize_qwen35_exclude_modules — isn't mentioned. Please describe it, including which checkpoint field it's parsing.
  • Supporting a new checkpoint format is a feature, not a chore; a JIRA ticket in the title slot would be better than [None]. And there's no test — the rename + inversion is pure tensor-dict manipulation and is cheap to unit-test (fake weights dict in, expected keys/values out), including the zero-scale case. Same for _regex_targets_mtp. Also worth noting in docs/source/features/quantization.md (or wherever supported checkpoint formats are listed) that llm-compressor NVFP4 Qwen3.5/3.6 checkpoints now load.

for old_suffix, new_suffix in invert.items():
if k.endswith(old_suffix):
k = k[: -len(old_suffix)] + new_suffix
v = (1.0 / v.float()).to(v.dtype)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

1.0 / v.float() produces +Inf when a global scale is 0. That isn't hypothetical: some published compressed-tensors checkpoints store 0 for experts that got no calibration tokens (amax unavailable). The fused-MoE loader reduces input_scale with a max over all experts in the layer, so one Inf propagates to every expert's scale and alpha — the whole layer's activations go bad, silently.

LagunaHfWeightMapper.preprocess_weights (modeling_laguna.py:604-626) already handles this; its _invert_global_scale maps 0 -> 0 and nan_to_nums the rest so a dead expert is a no-op in the max. Please reuse it — factoring it into a shared helper (e.g. in tensorrt_llm/_torch/models/checkpoints/hf/) and calling it from both places would avoid a third copy the next time a compressed-tensors model lands.

Also: .to(v.dtype) round-trips through the source dtype; keep the result float32 since weight_scale_2/input_scale are consumed as FP32.

# weight_scale=1.0 and quantizes activations dynamically every step.
weight_mapper.init_model_and_config(self.llm, self.llm.model_config)
filtered_weights = {k: v for k, v in weights.items() if not k.startswith("model.visual.")}
filtered_weights = _normalize_compressed_tensors_names(filtered_weights)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This only converts the VLM path. Qwen3_5MoeForCausalLM / Qwen3_5ForCausalLM (L622/L651) inherit Qwen3NextForCausalLM.load_weights and never see the rename, so a text-only llm-compressor NVFP4 Qwen3.5/3.6 checkpoint still hits the w1_weight is not None assert — even though the exclude-module half of this PR does cover both paths.

Moving the conversion into Qwen3_5MoeHfWeightMapper.preprocess_weights (which both paths go through, and which is where Laguna does it) fixes the asymmetry and removes the need for the explicit call here. If the text-only path is deliberately out of scope, say so in the description.

the caller translate it into a TRT-LLM model.layers.<n> subtree
exclusion (ModelOpt instead emits explicit mtp.layers.0* globs)."""
try:
return re.match(regex, "mtp.layers.0.self_attn.o_proj") is not None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probing with a single sample string over-matches. Any broad regex in ignore — re:.*, re:.*self_attn.*, re:.*o_proj — also matches "mtp.layers.0.self_attn.o_proj", so the branch at L470 discards the caller's actual pattern and replaces it with model.layers.<n>*. The result is a silently narrowed exclusion: modules the checkpoint left unquantized get built quantized and load garbage, with no warning.

Suggest requiring the regex to be MTP-specific, e.g. also assert it does not match a non-MTP name like "model.layers.0.self_attn.o_proj" before translating, and logger.warning on any re: entry that is dropped or rewritten so this is debuggable from a log.

# matches model.layers.<n>...; translate it to a subtree exclusion
# of the MTP layer (mapped to model.layers.<num_hidden_layers>).
if (
name.startswith("re:")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A re: entry that isn't MTP-targeting (or n_hidden_layers is None) falls through to the in_proj_* regex substitutions at L484-486 and then into normalized with its re: prefix intact. Confirm is_module_excluded_from_quantization handles a re:-prefixed pattern with HF-namespaced content here — if it matches against TRT-LLM runtime names, an HF-namespaced regex like re:^model\.language_model\..* never fires and the exclusion is silently lost. The _LANG_PREFIX strip at L459 doesn't apply to re:-prefixed names.

@mihai-chiorean

Copy link
Copy Markdown
Contributor

I hit the same packed-name issue while validating unsloth/Qwen3.8-27B-NVFP4. I opened #17726 with the review feedback here incorporated: the Laguna transform is moved into a shared helper, Qwen uses that helper, suffix matching is exact, reciprocal conversion is zero-safe, and scalar/vector/zero plus Qwen-mapper cases have unit coverage. I intentionally left the homogeneous MTP-regex concern out so it can be reviewed separately. Happy to coordinate or defer to whichever version maintainers prefer.

This branch has not been deployed

No deployments
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.

4 participants