Skip to content

fix(weight-only): share the tied-head check with the module looper (#5027) - #5041

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-5027
Nov 18, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-5027

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5027

Root cause

WeightOnlyLooper refused lm_head=True on a tied model with

if any(f"{lm_head_name}.weight" in names for names in find_tied_parameters(self.gptq_model.model)):

find_tied_parameters only compares materialized parameters. With the default offload_to_disk=True the model is a lazy shell: lm_head.weight and embed_tokens.weight are independent META parameters that are not tied yet, so the guard never fired. The run quantized every layer and then died on the head with an unrelated error:

NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty() ...
  weight_only_looper.py:503 _quantize_named_module -> :439 _prepare_named_module_for_quantization -> move_module_to_device

The module looper hit the same problem and fixed it in #4034; the weight-only looper was never switched over.

Changes

Verification

New tests/test_weight_only_tied_lm_head_5027.py (6 tests):

  • unit: a materialized tied pair is tied; a materialized untied pair is not;

  • unit: a lazy shell whose checkpoint omits lm_head.weight is tied (the [BUG] RTN/weight-only quantize with lm_head=True on a tied-embedding model runs every layer then crashes 'Cannot copy out of meta tensor': WeightOnlyLooper tie guard uses find_tied_parameters, blind on the lazy shell (#4034 fixed only ModuleLooper) #5027 shape); a lazy shell with an independent head tensor is not;

  • end-to-end, RTNConfig(bits=4, group_size=32, lm_head=True) on a real tiny tied LlamaForCausalLM, parametrized over offload_to_disk True/False: quantize() raises NotImplementedError: ... tied weights is not supported and layers[0].self_attn.q_proj is still an nn.Linear, proving the refusal happens before the layer loop.

  • New file: 6 passed.

  • Red on parent (git checkout origin/main -- gptqmodel/looper/weight_only_looper.py, then restored): 1 failed, 5 passed — test_rtn_lm_head_on_a_tied_model_is_refused_before_any_layer[True], i.e. exactly the default-offload path this issue is about; the offload_to_disk=False case already worked.

  • Neighbours: tests/test_weight_only_looper.py tests/test_lm_head_tied_detection.py tests/test_internvl_tied_head_4973.py tests/test_cpu_offload_tied_both_copies_4943.py → 56 passed, 1 failed; the failure is the pre-existing test_weight_only_looper_respects_dense_and_moe_vram_strategy_devices, which expects three GPUs and fails identically on the parent on this single-GPU host. Post-merge re-run of the new file plus the tied-head detection suite: 13 passed.

  • ruff check gptqmodel tests clean.

Residual risk

  • The end-to-end case uses a tiny two-layer tied Llama on CPU; a real Qwen2.5-0.5B RTN run with lm_head=True was not executed here.
  • The helper is now shared, so a change to the tie decision affects both loopers. That is the point, but it also means fix(checkpoint): accept 5.4.x gptaq booleans and quantize untied lm_head (#4013) #4034's heuristics are now load-bearing for RTN/GGUF/FP8/BnB/NF12 refusal as well; the four unit cases pin the materialized and lazy-shell shapes, and the pre-existing InternVL/tied-copies suites stay green.
  • get_output_embeddings() may return a wrapper (not a tensor-holding module) for some architectures; that path already fell through to find_tied_parameters before this change and is unchanged.

…5027)

`WeightOnlyLooper` refused `lm_head=True` on a tied model with
`find_tied_parameters(model)`, which only compares materialized parameters.
With the default `offload_to_disk=True` the model is a lazy shell whose
`lm_head.weight` and `embed_tokens.weight` are independent META parameters, so
the guard never fired: the run quantized every layer and then died on the
head's meta tensor (`Cannot copy out of meta tensor; no data!`), an error that
points away from the real cause. The module looper had already been fixed in
#4034.

Move `ModuleLooper._lm_head_is_tied` into
`utils.tied_weights.lm_head_quantization_is_tied()` and call it from both
loopers, so one check decides the answer: real storage identity, then
accelerate's tied report, then the lazy-shell checkpoint evidence, then the
resolved tie snapshot, then the root config declaration.

Fixes #5027
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant