Skip to content

fix(looper): rebuild the subset early-stop state every calibration batch (#4738) - #4752

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-4738
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-4738

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

What

#4703 replaced the declared-last forward_hook_last with _mark_subset_member: the member whose hook empties the pending set flips the stop flag, so a subset is cut off only after every member fired once, whatever order the model calls them in (#4679).

The pending set was built once per subset pass, and the flag the completing member set was only cleared at the end of the pass. From the second calibration batch on the set was already empty, so the first member to fire flipped the flag and stopped the forward. Every other member of the subset — every other expert of a MoE layer — received calibration from exactly one batch. That silently under-trains GPTQ/AWQ/EXL3/Paro/MACaQ on MoE models with more than one calibration batch.

Fixes #4738 (regression from #4703).

Fix

Register a forward pre-hook on the layer module that refills pending_members and clears forward_hook_last on every batch, before any subset member runs. #4703's ordering guarantee is untouched: within a batch the forward still stops only after every member fired.

Evidence

  • Red on parent (source change stashed, tests kept): both new tests fail — every routed expert saw 1 batch instead of 3.
  • Green: tests/test_moe_subset_early_stop_batches_4738.py → 2 passed.
    • AWQ: every mlp.experts.*.{gate,up,down}_proj has batches == 3.
    • GPTQ: every expert Hessian accumulated all 3 batch indices.
    • Fixture: 1-layer Qwen3-MoE, 8 experts, top-8, batch_size=1, 3 batches.
  • ruff check gptqmodel docs tests clean.
  • docs/quantization-lifecycle-contracts.md documents that subset_early_stop is a per-forward control.

…tch (#4738)

#4703 made the member that empties the pending set flip forward_hook_last, so a
subset is cut off only after every member fired once. But the pending set was
built once per subset pass and the flag was only cleared at the end of the
pass. From the second calibration batch on the set was already empty, so the
first member to fire stopped the forward: every sibling - every other routed
expert of a MoE layer - captured exactly one batch.

Register a forward pre-hook on the layer module that refills the pending set and
clears the flag once per batch, before any subset member runs. The #4703
ordering guarantee is unchanged.
@Qubitium
Qubitium merged commit 7de0d0d into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4738 branch November 17, 2026 13:41
sLaffey pushed a commit to sLaffey/GPTQModel that referenced this pull request Nov 18, 2026
…op state (ModelCloud#4982)

`ForwardExecutor.run_parallel` forwards one replica of a layer per device on
a device-dedicated worker thread. The replicas are deep copies, but a deep
copy keeps the subset stage's closures and the modules they capture, so every
replica shared one `pending_members` set and the stop flag was written to the
subset's *original* modules. While the cuda:0 replica forwarded batch 0, the
cuda:1 replica could refill or drain the shared set and set
`forward_hook_last` on an original expert; `HookedLinear` then raised
`StopForward` mid-forward and every routed expert after that member silently
lost the batch from its Hessian. Dense subsets were mostly spared by their
fixed member order; MoE subsets were not, because the completing member
depends on routing and on the other thread's timing.

Keep the pending set in thread-local storage and reset it from the layer
pre-hook on the replica that is about to forward. Flag the module that
actually ran (`_module`) instead of the closure's original module, and clear
the flag on the executing replica's member. The serial path keeps the ModelCloud#4752
behaviour: the state is rebuilt for every calibration batch.

Regression: `tests/test_dp_subset_early_stop_4904.py` runs the tiny two-layer
Qwen3-MoE fixture with `ExpertsRoutingOverride` on two GPUs and asserts every
expert projection sees all 4 x 32 calibration tokens, that two back-to-back
runs agree, and that the single-GPU and `auto_forward_data_parallel=False`
controls still see every token.
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