Repository navigation
fix(weight_loader): write counterless tensors in file-backed offload (RTN quantize crash, #6539) - #6564
Merged
Conversation
…6539) Weight-only finalize (RTN/SINQ/GGUF ...) hands file_back_module tensors that were created under inference_mode and rebound with param.data = ... (the #4572 state: not inference, but no version counter). The #6473 writer serialized them through reshape/view, which raises 'Inference tensors do not track version counter', so quantize() crashed with the default offload_to_disk=True. Copy such a tensor once before taking its byte view. Fixes #6539 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
Release-sweep note: this PR does not cover a second consumer of the same counterless weight.
cfg = RTNConfig(bits=4, group_size=128, sym=False, format=FORMAT.GEMM, device="cuda:0") # offload_to_disk default True
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", quantize_config=cfg, dtype=torch.float16)
m.quantize(CalibrationConfig(dataset=[...], batch_size=1))
# weight_only_looper.py:506 _finalize_quantized_module -> weight_only_processor.py:389 submodule_finalize
# -> utils/model.py:1692 pack_module -> nn_modules/qlinear/torch_awq.py:189 pack: weight.t()
# RuntimeError: Inference tensors do not track version counter.
Suggestion: fix the producer that rebinds the weight with an inference-mode tensor on the offload path, so every consumer (writer, GPTQ/AWQ packers, later forwards) gets a normal tensor, rather than patching each consumer. |
This was referenced Dec 1, 2026
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
#6595) (#6596) 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 #6539
Problem
Weight-only finalize (RTN, and other direct-pack methods) passes
file_back_moduletensors that were created underinference_modeand later rebound withparam.data = ...(the #4572 state:is_inference() == False, no version counter). The packed module'sbiasaliases such a source tensor. The file-backed writer added in #6473 serializes throughreshape(-1).view(torch.uint8), and any view of a counterless tensor raisesRuntimeError: Inference tensors do not track version counter. Soquantize()with the defaultoffload_to_disk=Truecrashed for every model with biased linears (verified: opt-125m, Qwen2.5-0.5B-Instruct). Llama (no linear bias) was unaffected. Before #6473 (0043349bf^), the same script quantized fine.Fix
gptqmodel/weight_loader/filebacked.py:_viewable()copies a tensor once when it has no version counter, before the writer takes its byte view. This covers both the normal path (_host_bytes) and the raw-U8 path (dtypes without a safetensors name). Tensors that already have a counter take the existing path unchanged, with no extra copy.file_back_modulealready rebinds every tensor to a fresh file-backed view, so the in-session model ends up with normal, counter-tracking tensors.Tests
tests/test_weight_loader_filebacked.py::test_counterless_tensors_are_written_and_rebound[False|True]builds the exact producer state: a Parameter created underinference_mode, then.data = cpu_tensor. The test asserts that the counter is really missing, and covers both an fp16 bias and a raw-U8 float8_fnuz tensor. It file-backs the module from a normal caller and from aninference_modecaller. It then checks the values in memory and on disk, and that an in-place update works afterwards.RuntimeError: Inference tensors do not track version counteratfilebacked.py:104tests/test_weight_loader_filebacked.pytests/test_*{offload,filebacked,weight_only,weight_loader,rtn,insession}*)uvx [email protected] check ...)End-to-end (
GPTQModel.load→RTNConfig(bits=4, group_size=128)→quantize()→save→GPTQModel.load(backend=TORCH)→ generate → wikitext2 PPL, ctx 2048, RTX 4090):quantize()quantize()0043349bf^), opt-125mNo control flow change, so there is no diagram.
🤖 Generated with Claude Code