Fix silent quantized-buffer corruption in load_quantized_model() for Qwen3.6#35
Open
dogwood-flo wants to merge 15 commits into
Open
Fix silent quantized-buffer corruption in load_quantized_model() for Qwen3.6#35dogwood-flo wants to merge 15 commits into
dogwood-flo wants to merge 15 commits into
Conversation
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.
Summary
_check_load_state_dict_result()/_assert_quantized_modules_loaded()) so this class of bug fails fast instead of silently producing a broken model.This pull request should be reviewed after merging (#34).
Background
The root cause is that
transformersunconditionally rewrites saved checkpoint key prefixes for certain model types (e.g. Qwen3.6'sqwen3_5_text:model.layers.*becomesmodel.language_model.layers.*on disk), whilequantization_config's recorded module names stay as the original in-memory names._replace_quantized_layers()now actually moves matched tensors to the correct key instead of only using them to infer buffer shapes, so quantized weights are no longer silently loaded as all-zero.Details
Bug fix
load_quantized_model()silently loading quantized layers (GPTQ/DBF) with all-zero buffers when the checkpoint's on-disk key prefixes don't matchquantization_config's recorded module names (e.g. Qwen3.6:transformersunconditionally rewritesmodel.layers.*tomodel.language_model.layers.*on save, regardless of any OneComp save option)._replace_quantized_layers()now moves the matched tensors to the correct key beforeload_state_dict()instead of only using them to infer buffer shapes (onecomp/quantized_model_loader.py)_check_load_state_dict_result()/_assert_quantized_modules_loaded()post-load checks that fail fast instead of silently producing a model that generates garbage_resolve_state_dict_key()to consider the full key depth instead of a hardcoded 8-component limit_assert_quantized_modules_loaded()raising for every DBF-quantized model: it checked for a non-existentbpattribute onDoubleBinaryLinearinstead of the realscaling0/scaling2/scaling4/bp1/bp3(onecomp/quantized_model_loader.py)lm_head.weightis legitimately absent from the checkpoint (HF'ssave_pretraineddoes not duplicate a tensor sharing storage withembed_tokens.weight) and is no longer flagged as a critical missing key (onecomp/quantized_model_loader.py)Refactor
tie_weights()call inload_quantized_model()into_retie_lm_head_if_needed()(onecomp/quantized_model_loader.py)Test
tests/onecomp/runner/test_remap_state_dict_keys.py,tests/onecomp/runner/test_load_tied_embeddings.py)Verified
Verified the implementation with the following script: