Skip to content

fix(looper): detect tied lm_head from storage identity, not nested config (#4369) - #4410

Merged
Qubitium merged 1 commit into
mainfrom
fix/lm-head-tied-4369
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/lm-head-tied-4369

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4369.

Problem

ModuleLooper._lm_head_is_tied() treated a nested text_config.tie_word_embeddings=True as proof that lm_head is tied. Composite/VLM models routinely leave that nested flag at its default True while the loaded model keeps independent input/output embeddings — Qwen3-VL-30B-A3B-Instruct has top-level tie_word_embeddings=False, text_config True, and find_tied_parameters() == []. With lm_head=True, quantize() then raised NotImplementedError("quantization of lm_head layer with tied weights is not supported"). untie_word_embeddings() cleared only the top-level flag, so the false positive survived it too.

Fix

_lm_head_is_tied() now decides in this order:

  1. Real storage identity — input embedding weight and output head weight are the same object, or share materialized storage (meta tensors are skipped because they all report data_ptr() == 0).
  2. Accelerate's tied-parameter report (find_tied_parameters), unchanged.
  3. Checkpoint shape for lazy shells — a tied checkpoint omits lm_head.weight, unchanged.
  4. Root config only — model.config.tie_word_embeddings plus the declared _tied_weights_keys entry, for checkpoints that do store lm_head.weight while the loader still ties it (Qwen3).

The nested-text_config walker (_config_declares_tied_embeddings) is deleted: it described a sub-config, not the loaded model's storage.

Tests

tests/test_lm_head_tied_detection.py:

  • nested text_config=True with independent embeddings → untied (fails before the fix);
  • same, with materialized independent embeddings (Qwen3-VL shape) → untied;
  • nested text_config=True but genuinely shared storage → still tied;
  • existing tied/untied/meta-shell cases unchanged.

tests/test_lm_head_tied_detection.py tests/test_requant_embed_lm_head.py tests/test_pre_lm_head_norm_resolution.py → 40 passed, 12 skipped. ruff check → clean.

Also checked against the real Qwen/Qwen3-VL-30B-A3B-Instruct config: top_tie=False, text_tie=True, storage identity False, _lm_head_is_tied → False.

Residual risk

  • The root-config + declared-tied-key fallback still rejects a composite model with root tie_word_embeddings=True but genuinely independent storage. The reported Qwen3-VL case (root False) is fixed.
  • find_tied_parameters() compares materialized parameters only; the meta-shell fallback still relies on the checkpoint's missing lm_head.weight.

@Qubitium
Qubitium merged commit 0b78e47 into main Nov 16, 2026
8 of 9 checks passed
@Qubitium
Qubitium deleted the fix/lm-head-tied-4369 branch November 16, 2026 13:07
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