Skip to content

fix(models): honor Ling-2.6-flash remote-code layout and declare MLA projections (#4373) - #4429

Merged
Qubitium merged 1 commit into
mainfrom
fix/ling-remote-code
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/ling-remote-code

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Ling-2.6-flash is registered as model_type=bailing_hybrid, but its checkpoint ships a remote-code auto_map pointing at modeling_bailing_moe.BailingMoeForCausalLM. resolve_trust_remote_code force-nativized any natively supported model_type unless the caller passed an explicit trust_remote_code, so the remote layout was never used and loading crashed. Even with remote code enabled, BailingMoeQModel only declared the Ling-2.0 attention.query_key_value / attention.dense branch and would have missed the remote MLA projections (q_a_proj, kv_a_proj_with_mqa, g_proj, q_b_proj, kv_b_proj) and checkpoint-owned attention norms, so those weights would never be quantized.

Fixes #4373.

What Changed

  • gptqmodel/utils/hf.py: resolve_trust_remote_code now honors an explicit trust_remote_code=True when a natively supported checkpoint's auto_map names a different model class, or when the config carries the bailing_hybrid + q_lora_rank MLA marker. A checkpoint whose auto_map resolves to the installed native class still loads natively (no behavior change there).
  • gptqmodel/models/definitions/bailing_moe.py: declare the remote attention MLA projections and their low-rank staging order (query_key_value/q_a/kv_a/g_proj -> q_b/kv_b -> dense), plus the never-quantized attention norms. layer_modules_strict=False resolves only the branch each layer owns, so the native linear-attention branch keeps working.
  • New regressions: loader-decision tests (tests/test_ling_remote_code_4373.py), a state_dict-based module-plan test for the remote MLA layout (tests/module_tree/test_bailing_moe_remote_mla_4373.py), and refreshed Bailing plan fixture + [BUG] BailingMoe shared experts are still ungrouped: down_proj is in the same subset as gate/up (incomplete fix of #4175) #4325 shared-expert assertions.

Tests

PYTHONPATH=/root/work-4373 /root/venv/bin/python -m pytest \
  tests/test_ling_remote_code_4373.py tests/module_tree/test_bailing_moe_remote_mla_4373.py \
  tests/module_tree/test_registered_module_plans.py \
  tests/module_tree/test_bailing_moe_shared_experts_4325.py \
  tests/test_trust_remote_code_isolation.py -q
436 passed

/root/venv/bin/python -m ruff check gptqmodel/models/definitions/bailing_moe.py \
  gptqmodel/utils/hf.py tests/test_ling_remote_code_4373.py \
  tests/module_tree/test_bailing_moe_remote_mla_4373.py \
  tests/module_tree/test_bailing_moe_shared_experts_4325.py tests/test_bailing_hybrid_support.py
All checks passed!

Real Ling-2.6-flash checkpoint instantiation was not run here (no checkpoint access in this container); the loader decision and the module plan are covered by unit tests using the checkpoint's real auto_map/config shape and a synthetic state_dict.

Model Support / Module Plan

  • Registry plan case for BailingMoeQModel/gptq updated in tests/module_tree/fixtures/registered_module_plans.json; every registered case is asserted by test_registered_module_plans.py.
  • Remote MLA layout is asserted against a synthetic checkpoint state_dict so checkpoint weight ownership and ordering are pinned.

Logic Flow Documentation

Changes the trust_remote_code resolution decision (native vs remote class). The decision table is documented in the docstring and covered by the new loader-decision tests; no docs page added.

Review Requirements

  • Reviewed, matches existing structure/conventions.
  • No monkeypatching beyond the project's existing loader hooks.

#4373)

resolve_trust_remote_code now keeps an explicit trust_remote_code=True when a natively supported checkpoint's auto_map names a different model class (or carries the bailing_hybrid q_lora_rank MLA marker), instead of force-nativizing from model_type alone. A checkpoint whose auto_map points at the installed native class still loads natively.

BailingMoeQModel declares the remote attention MLA projections (q_a_proj, kv_a_proj_with_mqa, g_proj, q_b_proj, kv_b_proj, dense) and the checkpoint-owned attention norms, while the native query_key_value/dense branch keeps resolving. Add loader-decision and state_dict-based module-plan regressions and refresh the Bailing plan fixture.
@Qubitium
Qubitium merged commit d01e8fd into main Nov 16, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/ling-remote-code branch November 16, 2026 14:32
Qubitium added a commit that referenced this pull request Nov 17, 2026
#4429 split the remote Ling `attention` tree into
`query_key_value/q_a/kv_a/g` (0), `q_b/kv_b` (1) and `dense` (2). A Ling 2.0
layer owns no MLA pair, so block 1 resolved to no module; the `dense` block
then fell back to `last_module`, which still pointed at `input_layernorm`
because the preceding block ended on an absent `g_proj`. The two norm-sourced
groups merged into `input_layernorm -> [query_key_value, dense]`, rescaling
`attention.dense`'s input columns with no compensation (13-14% logit change).

Track whether the previous block declared only modules this layer does not
own and refuse the `last_module` fallback for the next block. The group is
then left unscaled, which is the pre-#4429 behavior; nothing else about the
selection changes.
Qubitium added a commit that referenced this pull request Nov 17, 2026
…) (#4708)

#4429 split the remote Ling `attention` tree into
`query_key_value/q_a/kv_a/g` (0), `q_b/kv_b` (1) and `dense` (2). A Ling 2.0
layer owns no MLA pair, so block 1 resolved to no module; the `dense` block
then fell back to `last_module`, which still pointed at `input_layernorm`
because the preceding block ended on an absent `g_proj`. The two norm-sourced
groups merged into `input_layernorm -> [query_key_value, dense]`, rescaling
`attention.dense`'s input columns with no compensation (13-14% logit change).

Track whether the previous block declared only modules this layer does not
own and refuse the `last_module` fallback for the next block. The group is
then left unscaled, which is the pre-#4429 behavior; nothing else about the
selection changes.
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