Repository navigation
fix(looper): give every data-parallel replica its own subset early-stop state (#4904) - #4982
Merged
Merged
Conversation
Qubitium
force-pushed
the
root/dp-subset-state-4904
branch
from
November 17, 2026 20:45
b67b6e5 to
177c1cb
Compare
…op state `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 #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.
Qubitium
force-pushed
the
root/dp-subset-state-4904
branch
from
November 17, 2026 20:49
177c1cb to
e9ffcb4
Compare
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.
Summary
Fixes #4904. With the default
auto_forward_data_parallel=Trueon two or more GPUs, MoE quantization silently dropped 3-6% of the routed calibration tokens from the expert Hessians, nondeterministically.ForwardExecutor.run_parallelforwards one replica of a layer per device on a device-dedicated worker thread, but every replica shared the subset early-stop state added by #4703/#4752.That state was one
pending_membersset per subset pass plus oneforward_hook_lastflag written to the subset's original modules (the closure'smodule, not the_modulethe hook was called with). A deep copy keeps the closures, so while the cuda:0 replica forwarded batch 0, the cuda:1 replica could refill or drain the shared set and set the stop flag on an original expert.HookedLinearthen raisedStopForwardmid-forward and every routed expert after that member never saw the batch. 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.What Changed
gptqmodel/looper/stage_subset.py_SubsetEarlyStopStatekept inthreading.local, so each data-parallel replica's worker thread owns its own set. The layer pre-hook rebuilds it once per batch on the replica that is about to forward, keeping the fix(looper): rebuild the subset early-stop state every calibration batch (#4738) #4752 guarantee that the state never leaks between calibration batches._mark_subset_membersetsforward_hook_laston the module that actually ran (_module), never on the closure's original module._subset_member_for_replica), because the subset dict still points at the original modules.docs/quantization-lifecycle-contracts.md: the early-stop state is documented as per-forward-replica as well as per-batch.Tests
New
tests/test_dp_subset_early_stop_4904.py:test_dp_replicas_keep_every_routed_token(2 GPUs, default DP): runs thetests/test_checkpoint_quantization.py::build_native_model("qwen3_moe", ...)fixture (2 layers, 4 experts,MoEConfig(routing=ExpertsRoutingOverride()), 4 calibration rows x 32 tokens = 128 tokens per projection) and asserts every expert'sgate_proj/up_proj/down_projsaw all 128 tokens, then repeats the 2-GPU run and requires identicalnsamplesfor every module (the issue reports the amount varies run to run).test_single_gpu_and_dp_off_controls_keep_every_routed_token: the single-GPU andauto_forward_data_parallel=Falsecontrols.nsamplesper expert projection, 2 GPUs, defaultauto_forward_data_parallel=True(expected 128 everywhere):The loss moves between runs, which is the non-determinism the test also pins down. Another origin/main run of the same fixture (before the fix) lost
layers.0.experts.3.{gate,up}_proj(96 each),layers.0.experts.{1,2,3}.down_proj(64 each), andlayers.1.experts.3.{gate,up}_proj(96 each) instead; the issue's own repro loses layer-0 experts. Single-GPU andauto_forward_data_parallel=Falseruns were 128 for every projection in every run, before and after.Regression suites, run identically on
origin/mainand on this branch (2 GPUs, same env):Model Support / Module Plan
Not applicable: no model definition, alias, or module-plan change.
AWQ onboarding safety
Not applicable: no model onboarding and no AWQ grouping/search/replay/fold change. The shared subset early-stop path is covered by the existing AWQ tests in the regression command above.