Fix CI on torch 2.13: raw-process-group collectives + flaky GSPO metrics tolerance#563
Merged
Merged
Conversation
torch 2.13 routes the deprecated all_gather_into_tensor/reduce_scatter_tensor through new all_gather_single/reduce_scatter_single methods that only exist on the generic ProcessGroup wrapper (torch.distributed.new_group()), not on the raw Backend objects (ProcessGroupGloo/ProcessGroupNCCL) Fast-LLM constructs directly, breaking every distributed CI test on the Gloo (CPU) backend. Call group._allgather_base/_reduce_scatter_base directly instead: these are the actual underlying implementations, present with a stable signature across torch 2.9-2.13+. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
_check_policy_metrics compared each metric with a relative-only threshold (min_threshold=0), so a near-zero-scale metric (e.g. kl_new_old ~4e-3) got an effective bound of 5e-5 * scale ~= 2e-7, below the float32 accumulation noise floor. Reference (naive loop) and implementation (fused kernel + tensor-parallel all-reduce) sum in different orders and differ by a few e-7 absolute, so the check tripped once float32 rounding shifted (surfaced on torch 2.13). Add a 1e-6 absolute floor, matching every other rms_close_relative call in the file (loss and log-prob comparisons). The floor only engages when 5e-5 * scale < 1e-6 (scale < 2e-2), so O(1)-scale metrics keep the full relative tolerance. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Claude Opus 4.8:
Two independent fixes needed to get CI green on
mainagain. Both surfaced when CI auto-upgraded to torch 2.13.0 (setup.cfgpinstorch>=2.9.0, unbounded), so they land together.Fix 1 —
all_gather/reduce_scatteron raw process groups (torch 2.13)CI was crashing on every
tests/models/test_model.pydistributed test (cascading through pytest-depends) with:In torch 2.13, the deprecated
torch.distributed.all_gather_into_tensor/reduce_scatter_tensornow dispatch through newall_gather_single/reduce_scatter_singlemethods. Those are only bound on the genericProcessGroupwrapper fromtorch.distributed.new_group()— not on the rawBackend-derived objects (ProcessGroupGloo,ProcessGroupNCCL) that Fast-LLM constructs directly (fast_llm/engine/distributed/distributed.pydeliberately bypassesinit_process_group). Confirmed against PyTorch's C++ pybind bindings at thev2.13.0tag.fast_llm/core/distributed.py: reimplement both to callgroup._allgather_base(...)/group._reduce_scatter_base(...)directly — the actual underlying virtual methods, with an identical signature onBackendacross torch 2.9.0, 2.13.0, and currentmain, so no version check is needed.fast_llm/engine/multi_stage/fsdp.pyimportedreduce_scatter_tensorstraight fromtorch.distributed(same bug, FSDP gradient reduce-scatter path) — now routed throughfast_llm.core.distributedlike everything else.Fix 2 — flaky GSPO/GRPO metrics tolerance (regression from #555)
Once Fix 1 let the distributed suite run,
test_lm_loss_distributed[...gspo_metrics...]failed:_check_policy_metrics(added in #555) compared each metric with a relative-only threshold (min_threshold=0). A near-zero-scale metric (e.g.kl_new_old≈ 4e-3) got an effective bound of5e-5 × scale ≈ 2.2e-7, below the float32 accumulation noise floor. The reference (naive loop) and implementation (fused kernel + tensor-parallel all-reduce) sum in different orders and differ by a few e-7 absolute; torch 2.13's rounding shifted it just over the line. Add a1e-6absolute floor, matching every otherrms_close_relativecall in the file (loss + log-prob comparisons). The floor only engages when5e-5 × scale < 1e-6(scale < 2e-2), so O(1)-scale metrics keep the full relative tolerance.Test plan
tests/models/test_model.py --models gpt_2(30 tests, incl.dp2/tp2/sdp2on Gloo) passes locally on torch 2.11.0 — no regression on the previously-working version.tests/layers/test_lm_losses.py(582 passed / 21 skipped, incl. the full distributed GSPO/GRPO metrics chain) passes locally on torch 2.11.0.