Repository navigation
fix(looper): rebuild the subset early-stop state every calibration batch (#4738) - #4752
Merged
Merged
Conversation
…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.
This was referenced Nov 17, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
#4703 replaced the declared-last
forward_hook_lastwith_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_membersand clearsforward_hook_laston 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
tests/test_moe_subset_early_stop_batches_4738.py→ 2 passed.mlp.experts.*.{gate,up,down}_projhasbatches == 3.ruff check gptqmodel docs testsclean.docs/quantization-lifecycle-contracts.mddocuments thatsubset_early_stopis a per-forward control.