Skip to content

fix(module-tree): quantize consumers after producers in six definitions (#4372) - #4427

Merged
Qubitium merged 1 commit into
mainfrom
fix/module-tree-subset-order
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/module-tree-subset-order

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4372.

Problem

Six definitions declared a consumer Linear in the same quantization subset as — or an earlier subset than — its producer. Sequential replay then feeds non-quantized activations to the consumer, lowering GPTQ/AWQ quality (and, for AWQ, the scale grouping).

Fixes (per-model before → after)

Definition Before After
longcat_flash Nested self_attn/mlps containers: both attention sub-blocks emitted before both MLPs; q_a/q_b and kv_a/kv_b shared group 0; o_proj:1 Flattened per-sub-block entries in real forward order: self_attn.0 (q_a/kv_a:0, q_b/kv_b:1, o:2) → mlps.0 (gate/up:0, down:1) → self_attn.1 (same) → mlps.1. Emitted subsets 0–9
kimi_linear (native KimiLinearNativeQModel) o_proj:1 shared with g_b_proj, forget_gate.f_b_proj, q_b_proj, kv_b_proj o_proj:2
nemotron_h (shared by NemotronOmniQModel) in_proj:2, out_proj:2 in_proj:2, out_proj:3
lfm2_moe "conv": ("in_proj", "out_proj") — both group 0 "conv": ("in_proj:0", "out_proj:1"), as in lfm2.py
bailing_moe kv_b_proj:1, o_proj:1 kv_b_proj:1, o_proj:2
deepseek_vl_v2 q_a:0/q_b:0, kv_a:0/kv_b:0, o_proj:1 q_a/kv_a:0, q_b/kv_b:1, o_proj:2 (same MLA split as deepseek_v2)

Forward order was verified against the transformers 5.22.1 modeling code for each architecture; no deviations from the issue's suggested indices. nemotron_h's out_proj:3 intentionally shares subset 3 with dense gate/up, which never coexist in one layer (single mixer type per layer), as the issue notes.

Reconciled with #4374 (merged): deepseek_vl_v2 keeps that PR's k_proj:0/v_proj:0 additions and gets this PR's MLA index split; nemotron_h keeps its fc1_latent_proj/fc2_latent_proj declarations. The checked-in plan fixture was regenerated from the definitions, so it carries both changes.

Tests

New tests/module_tree/test_definition_subset_ordering.py (302 lines) — static declaration checks plus a data-flow check per model: noise is added to a producer Linear's output and the consumers whose inputs change must have strictly greater subset indices.

Pre-fix (definitions reverted, tests kept): 12 failed — LongCat q_a/q_b both 0 and mlps.0 (subset 4) before attn1 (subset 2); Kimi g_b/f_b/q_b/kv_b (1) before o_proj (1); Nemotron in_proj/out_proj both 2; LFM2-MoE conv both 0; Bailing kv_b_proj/o_proj both 1.

Post-fix: test_definition_subset_ordering, test_registered_module_plans, test_subset_plan, test_awq_scaling_groups → 551 passed, 6 skipped. Also test_shared_input_cpu_forward → 261 passed; test_awq_relationships -k longcat → 5 passed; test_fusable_models -k "not native_parent_fusion" → 103 passed. ruff check → clean.

Residual risk

  • deepseek_vl_v2 has no executable tiny-forward test (remote code needs timm); coverage is static plus the shared MLA ordering.
  • Kimi-Linear native has no new full-output AWQ neutral-fold test: a prototype fold check hit a pre-existing sparse-layer failure (post_attention_layernorm → mlp.shared_experts.gate_proj/up_proj, ~1.7e-2) unrelated to the o_proj subset change, so it stayed out of scope.
  • The LongCat tree shape changed from nested self_attn/mlps containers to dotted top-level entries. Registry, plan, fusion-topology, shared-input and longcat AWQ tests pass, but out-of-tree code introspecting raw dict keys would see the new shape.
  • nemotron_h relies on the one-mixer-type-per-layer invariant for out_proj:3.

…ns (#4372)

LongCat-Flash interleaves attn0 -> mlps0 -> attn1 -> mlps1, but the tree
emitted both attention sub-blocks before both MLPs. Its MLA q_a/kv_a and
q_b/kv_b also shared a subset. Restructure the layer declaration into
per-sub-block entries so the emitted subsets follow the forward order, and
split the MLA stages.

Also move the attention output projection after its producers in
kimi_linear, nemotron_h (including the Nemotron Omni copy), bailing_moe,
and deepseek_vl_v2, and give lfm2_moe's conv in_proj/out_proj distinct
subsets.

Add static subset-order assertions and a generic tiny-model data-flow
probe that perturbs each declared Linear and requires every consumer to be
in a later subset. Update the registered module-plan fixture, the bailing
shared-expert plan test, and teach _tiny_config about lfm2_moe layer types.
Add lfm2_moe to the AWQ fold-preservation families.
@Qubitium
Qubitium merged commit 3fe8266 into main Nov 16, 2026
8 of 9 checks passed
@Qubitium
Qubitium deleted the fix/module-tree-subset-order branch November 16, 2026 13:58
Qubitium added a commit that referenced this pull request Nov 16, 2026
…uantize (#4381) (#4426)

* fix: restore base modules and re-pick CPU kernels after weight-only quantize (#4381)

* fix(module-tree): quantize consumers after producers in six definitions (#4372) (#4427)

LongCat-Flash interleaves attn0 -> mlps0 -> attn1 -> mlps1, but the tree
emitted both attention sub-blocks before both MLPs. Its MLA q_a/kv_a and
q_b/kv_b also shared a subset. Restructure the layer declaration into
per-sub-block entries so the emitted subsets follow the forward order, and
split the MLA stages.

Also move the attention output projection after its producers in
kimi_linear, nemotron_h (including the Nemotron Omni copy), bailing_moe,
and deepseek_vl_v2, and give lfm2_moe's conv in_proj/out_proj distinct
subsets.

Add static subset-order assertions and a generic tiny-model data-flow
probe that perturbs each declared Linear and requires every consumer to be
in a later subset. Update the registered module-plan fixture, the bailing
shared-expert plan test, and teach _tiny_config about lfm2_moe layer types.
Add lfm2_moe to the AWQ fold-preservation families.

* fix(awq): resolve fp16-only GEMV dtype before calibration (#4394) (#4424)

AWQ FORMAT.GEMV/GEMV_FAST/LLM_AWQ kernels declare SUPPORTS_DTYPES=[fp16], but the quantize path loaded a bf16 shell model and only failed in layer-0 finalize after the AWQ search had run. Extend _coerce_quantized_awq_dtype to the quantize path and teach it that AUTO selects fp16-only kernels for those layouts: auto-selected dtypes are fixed to fp16 (logged, whole model) while an explicit unsupported dtype raises a ValueError naming the conflict and both fixes. Apply the same explicit-dtype contract to checkpoint loads.

* fix: honour cpu_workers and live kernel policy; warn on retired env vars (#4396) (#4423)

* fix(gguf): serialize ggml-cuda entry process-wide (#4378) (#4421)

* fix(gguf): serialize ggml-cuda entry process-wide (#4378)

`_GGMLBridge.cuda_backend_lock` handed out one lock per CUDA device, so forwards on cuda:0 and cuda:1 could be inside ggml-cuda at the same time. ggml-cuda shares cuBLAS handles and memory pools across devices; on 2x RTX 4090 with PYTHON_GIL=0, 4 threads x 200 forwards aborted 5 of 20 runs in cublasGemmEx.

Return one re-entrant process-wide lock from `cuda_backend_lock`. The per-device backend-handle map is unchanged, and single-thread latency is unchanged because a forward already took one lock.

Add CPU-runnable regression tests that assert both devices share one lock and that cross-device forwards never overlap inside the backend critical section. They fail on the pre-fix code (max_active == 2).

Update the GIL=0 ledger with the concurrency contract change.

* test(gguf): give the plan-weight fake the process-wide backend lock

The kernel takes the bridge's cuda_backend_lock for every ggml-cuda entry,
but _FakeBridge predated that contract and had no such method, so
test_kernel_builds_the_weight_once_for_many_batch_sizes failed whenever a
CUDA device was visible. Expose the lock from the fake.

* test(gguf): collect worker failures as Exception, not BaseException

Code Quality flagged the two worker-thread handlers. They still re-raise the
collected failure in the main thread; narrowing the catch keeps
KeyboardInterrupt/SystemExit out of the collected list.

* fix: restore base modules and re-pick CPU kernels after weight-only quantize (#4381)

* test(insession): use one import style for gptqmodel.models.base

Code Quality flagged the test for importing the module both as an alias and
with from-import. The two monkeypatches now target the module path by string,
which still rebinds the global that rehome_quantized_kernel looks up.
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