Repository navigation
fix(qqq): keep per-channel empty s_group buffers in checkpoints (#5126) - #5186
Merged
Merged
Conversation
A per-channel QQQ layer (group_size == in_features) registers s_group = torch.empty(0). Every zero-element tensor reports storage pointer 0, so get_state_dict_for_save de-duplicated all of them as shared storage and dropped all but one. The fail-closed loader from #5032 then rejected the checkpoint for every missing s_group. Keep each named empty buffer in the save map (there is no data to share), and let the loader accept a missing entry for a buffer the live module legitimately holds empty, while a non-empty s_group stays required. The second half also unbreaks checkpoints written by the affected releases.
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.
Fixes #5126.
Problem
A per-channel QQQ layer (
QQQConfig(group_size=-1), or any layer whosegroup_size == in_features) registerss_group = torch.empty(0). Every zero-element tensor reports storage pointer 0:get_state_dict_for_save(gptqmodel/utils/model.py) de-duplicates by storage identity, so all per-channels_groupbuffers collapse into one "shared" group. All but one are removed withWARN Removed shared tensor {... .s_group ...}; a 2-layer Llama writes 13 of 14s_groupkeys. #5032 then made the loader fail closed onCHECKPOINT_REQUIRED_BUFFERS, so the saved checkpoint no longer loads:Only in-memory quantization (
offload_to_disk=False) is affected; disk-offload sources are offload references and load-then-resave keeps the keys.flowchart TD A["Per-channel QQQ layer<br/>s_group = torch.empty(0)"] --> B[get_state_dict_for_save] B --> C{"storage identity<br/>(device, 0, 0)"} C -->|"all empty tensors identical"| D["de-dup as shared storage"] D --> E["drops 13/14 s_group keys"] E --> F["#5032 fail-closed loader"] F --> G["ValueError: Missing required ... s_group"]Fix
Two halves, each independently useful:
get_state_dict_for_save): a zero-element tensor has no data to share, so key it by("empty", name)instead of storage identity. Every named empty buffer is written.validate_checkpoint_qweights): a newCHECKPOINT_OPTIONAL_EMPTY_BUFFERSdeclaration (("s_group",)on QQQ) accepts a missing entry only when the live module's buffer is actually empty. A non-emptys_groupstays required, so fix(qqq): publish dropped checkpoint buffers before an export and fail closed on load (#5010) #5032's fail-closed guarantee is unchanged. This also unbreaks checkpoints already written by the affected releases.flowchart TD A["Per-channel QQQ layer<br/>s_group = torch.empty(0)"] --> B[get_state_dict_for_save] B --> C{"numel == 0?"} C -->|yes| D["key = ('empty', name)"] D --> E["every s_group key written"] E --> F{"loader: buffer empty<br/>in live module?"} F -->|yes| G["optional-empty: accept missing key"] F -->|no| H["still required (fail closed)"] G --> I["GPTQModel.load + generate OK"]Before / after
main@ 307b688s_groupkeys (2-layer per-channel QQQ)ValueError: Missing required quantized weightss_groupkeysValueErrorQQQTorchLinear, CUDAQQQLinear)(1, 24)Tests
tests/test_qqq_per_channel_checkpoint_5126.py: 3 passed (writer keys + reload, legacy missing-empty acceptance, CUDA round-trip).mainwith the new test: 2 failed at the intended assertions (len(keys) == 14and the loaderValueError).test_qqq_per_channel_checkpoint_5126.py test_gsq_method_adapters.py test_checkpoint_modules.py test_checkpoint_quant_buffer_dtypes_4458.py test_awq_qqq_pack_shape_4567.py tests/qcfg: 313 passed.uvx [email protected] check gptqmodel tests setup.py: All checks passed.Unverified
QQQLinear) and CPU (QQQTorchLinear) paths are covered.group_size == in_featurescode path.