Repository navigation
[QUALITY] Multi-GPU data-parallel forward races the shared subset early-stop state (#4752): MoE expert Hessians silently lose 3-6% of routed calibration tokens on 2 GPUs, nondeterministically (OLMoE: 76190/78752); all 7 qwen3_moe multi-GPU recovery tests red #4904
Description
Found on main @ 4f287eb, 2 GPUs (RTX 5090 + RTX 4090), torch 2.15 + CUDA 13.2, Python 3.14 (GIL on).
What is wrong
With the default auto_forward_data_parallel=True on 2+ GPUs, MoE quantization silently drops a share of the routed calibration tokens from the expert Hessians. The amount varies between runs. One GPU, or auto_forward_data_parallel=False, keeps every token.
The subset early-stop state that #4703/#4752 added (gptqmodel/looper/stage_subset.py:1068-1086 and _mark_subset_member at :1742-1756) is one object per subset pass:
- one
pending_membersset; - one
_reset_subset_early_stoppre-hook that refills it; forward_hook_lastflags set on the original subset modules (the closure'smodule, not the_modulethe hook was called with).
ForwardExecutor.run_parallel (gptqmodel/looper/forward_executor.py:681-830) runs the layer concurrently on several replicas: the original module on the base device, plus copy.deepcopy clones on the others. The deep copy keeps the closures, so every replica shares that one set and keeps flipping the flag on the original modules. While batch 0 runs on the cuda:0 replica, the cuda:1 replica (batch 2) refills or drains the shared set and sets forward_hook_last on an original expert. HookedLinear then raises StopForward in the middle of the cuda:0 forward, and the experts after it never see that batch.
#4752 fixed the serial form of this (#4738: the state was never reset between batches). The data-parallel path still shares the state across threads.
Dense subsets are mostly spared. Members fire in a fixed order there, so the flag lands on the member that runs last anyway; the cross-thread resets only cost extra forward work. In an MoE subset, the completing member depends on routing and on the other thread's timing.
Repro 1: real model (OLMoE-1B-7B-0924, truncated to 2 layers via num_hidden_layers=2 in a config copy)
cfg = GPTQConfig(bits=4, group_size=128, offload_to_disk=False) # auto_forward_data_parallel defaults to True
m = GPTQModel.load("OLMoE-1B-7B-0924 (2 layers)", quantize_config=cfg, dtype=torch.bfloat16)
# record GPTQ.nsamples per module by wrapping GPTQ.finalize_hessian
m.quantize(CalibrationConfig(dataset=c4_texts[:32]))Sum of nsamples over the 64 experts per layer. Every token is routed to exactly 8 experts, so this total is fixed by the calibration set (32 samples -> 78752):
| run | L0 gate/up | L0 down | L1 gate/up | L1 down |
|---|---|---|---|---|
1 GPU (CUDA_VISIBLE_DEVICES=<one>) |
78752 | 78752 | 78752 | 78752 |
2 GPUs, auto_forward_data_parallel=False |
78752 | 78752 | 78752 | 78752 |
| 2 GPUs, default | 76190 (-3.3%) | 76486 | 73946 (-6.1%) | 77037 |
In the default 2-GPU run, 55 of 128 experts end up with gate_proj.nsamples != down_proj.nsamples. Those two projections see the same routed tokens by construction.
Repro 2: tiny fixture, deterministic shape of the loss
This uses the tests/test_checkpoint_quantization.py::build_native_model("qwen3_moe", ...) fixture: 2 layers, 4 experts, MoEConfig(routing=ExpertsRoutingOverride()) so every expert gets every token, and 4 calibration rows of 32 tokens.
2 GPUs (default): layers.0.experts.{1,2,3}.gate_proj nsamples = 96 (down_proj = 128; expert 0 = 128)
1 GPU: every expert projection = 128
2 GPUs, DP off: every expert projection = 128 (also 256/256 with 8 rows)
The --audit-hessians mode of tests/checkpoint_quantization_driver.py shows the missing batch. Layer-0 experts 1..3 gate_proj receive batch indices [1, 2, 3]: batch 0, the first batch on the cuda:0 replica, which runs concurrently with batch 2 on cuda:1, is dropped. With normal routing (no override, 8 rows), L0 expert 1 gate_proj gets 114 tokens on 2 GPUs vs 127 on 1 GPU, while its down_proj gets 127 in both.
Consequences
- Silent accuracy loss: MoE expert Hessians are built from 3-6% fewer tokens than the calibration set provides. For tail experts, whole batches go missing.
- Non-determinism: three back-to-back default 2-GPU runs of the tiny fixture gave 0/141, then 19/141 tensors different from run 1 (
layers.0.mlp.experts.3.{gate,up,down}_proj.qweight, ...). Single-GPU runs are bitwise identical. - All 7
tests/test_checkpoint_devices.py::test_real_multigpu_partial_hessian_recovery[*-qwen3_moe]cases fail on a 2-GPU host (AssertionError: model.layers.1.mlp.experts.1.gate_proj.qweightnot equal between baseline and resumed run), because the baseline itself is not reproducible. All thellamacases pass. - Every processor with
subset_early_stop=Trueorreplay_after_process(GPTQ, EXL3, MACaQ, ...) uses this path.
Suggested fix
Make the early-stop state per forward pass, not per subset stage:
- Keep
pendingper replica or per thread, e.g. in a dict keyed byid(replica), or reset insideforward_batch_worker. - Set the flag on the module that actually ran (
_module.forward_hook_last = Trueinmarked), not on the closure's original module. Clear it at the start of the next batch on that same replica.
Alternatively, disable subset early stop in run_parallel when more than one forward device is active. The serial-path behavior from #4752 stays unchanged either way.
Test that should have caught it
test_real_multigpu_partial_hessian_recovery[*-qwen3_moe] already fails on 2 GPUs. Add a 2-GPU unit test that runs run_parallel on a tiny MoE layer with ExpertsRoutingOverride and asserts that every expert's nsamples equals the total token count.
Severity
High for multi-GPU MoE quantization: silent, nondeterministic calibration loss on the default multi-GPU path.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4904is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent release:
agent-root-4904finished this issue. Fix: #4982, squash-merged as 15e94aa.Data-parallel replicas now keep the subset early-stop pending set in thread-local storage and flag only the module that actually ran, so a replica can no longer stop another replica's forward mid-batch. Verified with a new 2-GPU regression test (
tests/test_dp_subset_early_stop_4904.py: red 1 failed/1 passed onmain, green 5 passed on the fix) and theqwen3_moemulti-GPU partial-Hessian recovery matrix (main: 6 failed/1 passed -> fix: 7 passed).