Repository navigation
fix(weight_only): repair counterless source parameters before finalize (RTN GEMM offload crash, #6595) - #6596
Merged
Conversation
#6595) The lazy source materializes a layer under inference_mode and the weight-only CPU move rebinds it with .data =, leaving parameters that are not inference tensors yet have no version counter (#4572). The AWQ packer (weight.t()) then raised for RTNConfig(format=GEMM) with the default offload_to_disk=True. #6564 only hardened the file-backed writer; fix the producer state once in WeightOnlyLooper._finalize_quantized_module with replace_inference_parameters. Fixes #6595 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #6595
Problem
#6564 hardened one consumer, the file-backed writer, but left the producer alone. In
WeightOnlyLooper, the lazy source materializes each layer underinference_mode._move_named_module_to_cputhen rebinds the module with.data =, which leaves parameters withis_inference() == Falseand no version counter (the #4572 state). The AWQ packer callsweight.t()on such a parameter, soRTNConfig(format=FORMAT.GEMM)with the defaultoffload_to_disk=Truestill crashed withInference tensors do not track version counteron CPU and CUDA. The same failure appears intests/test_awq_variable_length_ppl.py::test_awq_beats_rtn_with_variable_length_calibration. This was reported in the #6564 comments.Fix
In
WeightOnlyLooper._finalize_quantized_module, before pack and offload, call the existingreplace_inference_parameters(named.module)(#4450/#4572) underinference_mode(False). It clones only parameters that lack a usable counter, so modules that are already healthy are untouched. Every downstream consumer (packers, the writer, the in-session model) then sees ordinary parameters.flowchart TD A["pre_quantize: lazy source materializes layer (inference tensors)"] --> B["quantize_module"] B --> C["_move_named_module_to_cpu: param.data = cpu copy -> counterless"] C --> D["_finalize_quantized_module"] D --> E["NEW: replace_inference_parameters under inference_mode(False)"] E --> F["submodule_finalize: pack (AWQ weight.t(), GPTQ ...)"] F --> G["offload_to_disk: file-backed writer"]Tests
New
tests/test_weight_only_counterless_offload_6539.pyuses a tiny biased Llama checkpoint (attention_bias=True) with the defaultoffload_to_disk=True. It runs RTN in two export formats, GPTQ (BACKEND.TORCH) and AWQ GEMM (BACKEND.AWQ_TORCH), on both CPU andcuda:0. Each case asserts:quantize()completes;saveandGPTQModel.load, the logits are bit-identical to the in-session ones.[gptq-cpu, gptq-cuda][awq-gemm-cpu, awq-gemm-cuda]RuntimeError: Inference tensors do not track version counter(AWQ pack)test_awq_variable_length_ppl.py::test_awq_beats_rtn_with_variable_length_calibration(real Llama checkpoint, RTX 4090)tests/test_*{offload,filebacked,weight_only,weight_loader,rtn,insession,sinq,gguf_quant,bitsandbytes}*🤖 Generated with Claude Code