Repository navigation
Don't carry source tensors a dequantizing load already folded into the weights - #2733
Draft
shengliangxu wants to merge 2 commits into
Draft
shengliangxu wants to merge 2 commits into
shengliangxu wants to merge 2 commits into
Conversation
The export carries every source tensor unplaced_source_keys reports, and that pass replayed only the model's stock conversion mapping. Loading can add to the mapping, and what it adds consumes tensors the stock mapping never mentions: - A dequantizing quantizer. Mxfp4Config(dequantize=True), which examples/hf_ptq uses for gpt-oss, folds each expert's *_blocks and *_scales into a bf16 gate_up_proj/down_proj; FineGrainedFP8Config(dequantize=True) folds every FP8 weight_scale_inv into its weight. - A patched mapping, such as an on-the-fly decompressor that feeds compressed-tensors weight_packed/weight_scale experts in. Each such tensor read as unplaced, so the export copied it in beside the weight it had become. A tiny gpt-oss checkpoint loaded the way hf_ptq loads it reports all four expert block/scale tensors; a tiny FP8-block Llama, all seven scales. Found on an expert-parallel Kimi-K3 export through such a decompressor: 494,592 packed expert tensors were carried, the checkpoint grew from 1.5 TB to 2.8 TB, and rank 0 spent 21 of the run's 37 minutes writing them. from_pretrained records the conversions it actually ran on the model (_weight_conversions, the list transformers' own save path replays), the additions included. A key now counts as placed when either that record or the stock mapping resolves it to a parameter: the record keeps only the conversions some key used, so the stock mapping still answers for weights one of our own loaders placed. Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
Reassigning the filtered list kept the type of its first assignment, list[dict | None], so handing an element to _resolve_target failed type checking. Filter a tuple of the two candidate plans into a fresh name instead. Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
Contributor
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2733 +/- ##
==========================================
- Coverage 69.47% 69.47% -0.01%
==========================================
Files 646 646
Lines 71672 71681 +9
==========================================
+ Hits 49796 49798 +2
- Misses 21876 21883 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Type of change: Bug fix
The export copies every source tensor
unplaced_source_keysreports into the checkpoint verbatim. That pass replayed only the model's stock conversion mapping, so it missed whatever loading added on top, and those additions consume tensors the stock mapping never mentions:Mxfp4Config(dequantize=True), whichexamples/hf_ptquses for gpt-oss, folds each expert's*_blocks/*_scalesinto a bf16gate_up_proj/down_proj.FineGrainedFP8Config(dequantize=True)folds every FP8weight_scale_invinto its weight.weight_packed/weight_scaleexperts in.Each such tensor read as unplaced, so the export carried it in beside the weight it had become: stale pre-quantization copies under the source names, plus matching
exclude_modulesentries.Fix:
from_pretrainedrecords the conversions it actually ran on the model (model._weight_conversions, the list transformers' own save path replays, and the one our quant-aware reverse conversion inquant_aware_conversion.pyalready prefers), with quantizer and patch additions included. A key now counts as placed when either that record or the stock mapping resolves it to a parameter. The record keeps only conversions some key used, so the stock mapping still answers for weights one of our own loaders placed (the FSDP2 meta-device load).Usage
N/A: internal to the export's carry-over of unplaced weights.
Testing
tests/unit/torch/utils/test_unplaced_source_keys.py. It runs a realfrom_pretrainedon CPU of a tiny FP8-block Llama (FineGrainedFP8Config(dequantize=True)) and a tiny gpt-oss (Mxfp4Config(dequantize=True)). Each checkpoint also holds one genuinely stray tensor.tests/unit/torch/utils/test_model_load_utils.py,tests/examples/hf_ptq/test_carry_over_layouts.py,tests/examples/hf_ptq/test_example_utils.pyandtests/unit/torch/export/{test_unified_export_hf,test_vllm_fakequant_hf,test_get_quantization}.py: 161 passed.Before your PR is "Ready for review"
CONTRIBUTING.md: N/AAdditional Information
Prerequisite of the HF expert-parallel PTQ (hfep) stack, which is rebased on top of it.