Skip to content

fix(quantization): preserve dense converters in mixed compressed-tensors checkpoints - #50466

Open
Shoryamishra61 wants to merge 5 commits into
huggingface:mainfrom
Shoryamishra61:fix/50426-compressed-tensors-dense-conversions
Open

Shoryamishra61 wants to merge 5 commits into
huggingface:mainfrom
Shoryamishra61:fix/50426-compressed-tensors-dense-conversions

Conversation

@Shoryamishra61

@Shoryamishra61 Shoryamishra61 commented Nov 7, 2026 •

Copy link
Copy Markdown

🤗 Transformers CI

What does this PR do?

Fixes #50426

Problem

When loading mixed-precision \compressed-tensors\ checkpoints (such as models with quantized MoE experts and dense fused attention projections, e.g., \RedHatAI/GLM-5.3-Flash-NVFP4), converted modules that the checkpoint leaves unquantized are incorrectly rewritten with serialized/dequantize transformations.
Because source patterns are name-boundary anchored ((?!\w)), the checkpoint's dense .weight\ keys fail to match the rewritten serialized companion patterns (e.g. \weight_packed\ / \weight_scale\ / \weight_shape), leaving the dense modules reported as UNEXPECTED and the fused parameters silently randomly initialized.

Root cause

In \HfQuantizer.update_weight_conversions, the rewrite was applied globally across all converters matching .weight\ whenever \self.serialized_names\ contains companion keys (derived globally from the quantization config groups). The converter selection did not inspect whether the checkpoint actually serializes companion keys for those specific converter sources or leaves them dense.

Fix

  1. Checkpoint Key Resolution (\src/transformers/modeling_utils.py): Resolves available checkpoint keys via lightweight metadata inspection (sharded \weight_map\ or safetensors header \safe_open().keys()\ without eager tensor reads) and forwards \checkpoint_keys\ to \get_model_conversion_mapping.
  2. Selective Converter Classification (\src/transformers/quantizers/base.py): Added \HfQuantizer.is_quantized_converter, which verifies whether companion tensors exist in the checkpoint for the converter's source patterns (taking scoped patterns, regular expressions, and \WeightRenaming\ into account). If a converter's tensors exist only as dense weights, it is preserved dense without injecting serialized companion names or dequantization operations.
  3. Compressed-Tensors Converter Specialization (\src/transformers/quantizers/quantizer_compressed_tensors.py): Implemented \CompressedTensorsWeightConverter(WeightConverter)\ to retain _original_source_patterns\ as \�ase_source_patterns, properly routing reverse transformations when saving and reloading models (\save_pretrained), while preserving \scope_prefix, \�ase_model_prefix, and \ orce_cpu. Also provides fallback classification based on \config_groups\ targets/ignore when checkpoint keys are unresolvable.
  4. Companion Integrity & Dequantization Guards (\src/transformers/integrations/compressed_tensors.py): In \CompressedTensorsDequantize, added validation for missing companion scale tensors, mismatched entry counts, and empty lists, raising explicit errors instead of silent corruption.

Regression coverage

Added \ ests/quantization/compressed_tensors_integration/test_mixed_precision_conversions.py\ covering:

  • Mixed dense attention fusion with float8 MoE expert decompression (\ est_01).
  • FP8 scale application and save/reload numerical parity (\ est_02).
  • Packed INT4 compressed experts with dense attention fusion and numerical decode verification against mathematical oracle + mutation tests (\ est_03).
  • Malformed/missing companion scale tensors and empty list validation (\ est_04).
  • Separate converter scope isolation and reversal (\ est_05).
  • Regex source pattern matching and weight renaming (\ est_06).
  • Standard unquantized checkpoint loading regression (\ est_07).
  • Sharded safetensors metadata-only checkpoint key discovery via \weight_map\ (\ est_08).
  • \dequantize=True\ save and reload parity with _IdentityOp\ preservation (\ est_09).
  • Converter classification fallback when \checkpoint_keys is None\ (\ est_10).
  • Generic \HfQuantizer.is_quantized_converter\ compatibility across other quantizers like FineGrainedFP8 and Mxfp4 (\ est_11).

Compatibility

Verification

  • \pytest tests/quantization/compressed_tensors_integration/test_mixed_precision_conversions.py\ (11 passed in 1.66s)
  • \pytest tests/quantization/compressed_tensors_integration/test_compressed_tensors.py -k "test_config_args or test_config_to_from_dict"\ (2 passed in 1.11s)
  • \pytest tests/utils/test_core_model_loading.py\ (43 passed in 1.45s)
  • \pytest tests/utils/test_modeling_utils.py -k "test_conversion or test_weight or test_load"\ (3 passed in 1.59s)

  • uff check\ on all modified files (All checks passed)

  • uff format --check\ on all modified files (All files formatted)

Before submitting

Who can review?

@SunMarc @ArthurZucker

Copilot AI balanced review requested due to automatic review settings November 7, 2026 19:32

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution 🤗!

CI Security Gate — automatic approval blocked

This PR was not automatically approved for CI because the security gate failed.

Possible reasons:

  • The PR touches 50 or more files — only PRs with fewer than 50 changed files are automatically approved
  • A changed file is outside the allowed directories (src/, tests/, docs/, utils/), has a disallowed extension (only .py, .txt, .md permitted outside tests/ and docs/), or is not .md/.yml inside docs/ — this covers files the PR deletes or renames, not only the ones it edits
  • A new security issue was detected in the changed Python files (Bandit check) — a high-severity one, shell execution, exec/eval, a URL fetch, or disabled TLS verification
  • The PR touches a path this repository protects from untrusted PRs, such as the file that decides who reviews it — a maintainer must make that change in a separate PR

See the workflow run for the exact violations.

A maintainer can review and manually approve CI if a finding is a false positive.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution 🤗!

CI Security Gate — waiting for maintainer approval

CI is approved automatically only for authors who already have a contribution merged in this repository. A maintainer will review this PR and approve CI to run on it.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: compressed_tensors_integration

@ArthurZucker ArthurZucker 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.

#50245 should make this simpler.

@Shoryamishra61

Copy link
Copy Markdown
Author

Thanks @ArthurZucker and @kylesayrs for the direction. I see the overlap with #50593 and the broader per-layer quantization plan in #50245, so I don't want to maintain a competing loader change in #50466.

I can move the focused regression coverage to whichever PR is the intended landing point: numerical Q/K/V fusion against checkpoint tensors (not just missing/unexpected-key counts), dense attention alongside quantized experts, FP8/NVFP4 companion-key handling, and malformed-companion cases.

One edge case worth preserving: if a converter pattern spans multiple layers, detecting any companion key may still rewrite dense sources in other layers. The per-layer approach in #50245 seems particularly relevant here.

I also understand that compressed-tensors MoE loading without llmcompressor.utils.load_context is a separate limitation, not something the conv-QKV fix should claim to resolve.

Would you prefer the regression coverage contributed to #50593 or held until #50245 lands? I'm happy to close #50466 if it's superseded, once the relevant cases are accounted for.

Thanks!

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.

[Bug] Mixed-precision compressed-tensors checkpoints randomly initialize converted modules the checkpoint leaves dense

3 participants