Repository navigation
Conversation
📝 WalkthroughWalkthroughAdds 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. ChangesQwen3.5 NVFP4 loading
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tensorrt_llm/_torch/models/modeling_qwen3_5.py (1)
656-696: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd 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
📒 Files selected for processing (1)
tensorrt_llm/_torch/models/modeling_qwen3_5.py
|
/bot run --disable-fail-fast |
|
PR_Github #59524 [ run ] triggered by Bot. Commit: |
408e9de to
cab4a84
Compare
|
PR_Github #59524 [ run ] completed with state
|
cab4a84 to
c5c408a
Compare
|
/bot run |
|
PR_Github #59757 [ run ] triggered by Bot. Commit: |
|
PR_Github #59757 [ run ] completed with state
|
…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]>
c5c408a to
9192a16
Compare
|
/bot run |
|
PR_Github #59780 [ run ] triggered by Bot. Commit: |
|
PR_Github #59780 [ run ] completed with state
|
brnguyen2
left a comment
There was a problem hiding this comment.
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_mtpand there: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 (fakeweightsdict in, expected keys/values out), including the zero-scale case. Same for_regex_targets_mtp. Also worth noting indocs/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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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:") |
There was a problem hiding this comment.
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.
|
I hit the same packed-name issue while validating |
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 FP8weight_scaleis 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
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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin 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.