Skip to content

fix(weight_only): repair counterless source parameters before finalize (RTN GEMM offload crash, #6595) - #6596

Merged
Qubitium merged 1 commit into
mainfrom
fix/weight-only-counterless-producer
Dec 1, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/weight-only-counterless-producer

Conversation

@Qubitium

@Qubitium Qubitium commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Fixes #6595

Problem

#6564 hardened one consumer, the file-backed writer, but left the producer alone. In WeightOnlyLooper, the lazy source materializes each layer under inference_mode. _move_named_module_to_cpu then rebinds the module with .data =, which leaves parameters with is_inference() == False and no version counter (the #4572 state). The AWQ packer calls weight.t() on such a parameter, so RTNConfig(format=FORMAT.GEMM) with the default offload_to_disk=True still crashed with Inference tensors do not track version counter on CPU and CUDA. The same failure appears in tests/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 existing replace_inference_parameters(named.module) (#4450/#4572) under inference_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"]
Loading

Tests

New tests/test_weight_only_counterless_offload_6539.py uses a tiny biased Llama checkpoint (attention_bias=True) with the default offload_to_disk=True. It runs RTN in two export formats, GPTQ (BACKEND.TORCH) and AWQ GEMM (BACKEND.AWQ_TORCH), on both CPU and cuda:0. Each case asserts:

  • quantize() completes;
  • every in-session parameter keeps a version counter;
  • the in-session logits are finite;
  • after save and GPTQModel.load, the logits are bit-identical to the in-session ones.
origin/main 2a87e13 this PR
new test [gptq-cpu, gptq-cuda] pass (writer hardened by #6564) pass
new test [awq-gemm-cpu, awq-gemm-cuda] 2 failed: RuntimeError: Inference tensors do not track version counter (AWQ pack) pass
test_awq_variable_length_ppl.py::test_awq_beats_rtn_with_variable_length_calibration (real Llama checkpoint, RTX 4090) failed, same error passed (80 s)
53 files tests/test_*{offload,filebacked,weight_only,weight_loader,rtn,insession,sinq,gguf_quant,bitsandbytes}* n/a 729 passed, 23 skipped
ruff gate n/a All checks passed

🤖 Generated with Claude Code

#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]>
@Qubitium
Qubitium marked this pull request as ready for review December 1, 2026 05:13
@Qubitium
Qubitium merged commit c13a801 into main Dec 1, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/weight-only-counterless-producer branch December 1, 2026 05:13
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] RTN format=GEMM + default offload still crashes in AWQ pack: weight-only looper leaves counterless source Parameters (#6539 follow-up)

1 participant