Skip to content

Fix all_gather/reduce_scatter for raw process groups on torch 2.13#563

Open
jlamypoirier wants to merge 1 commit into
mainfrom
jlp_fix_torch_2_13_gloo_allgather
Open

Fix all_gather/reduce_scatter for raw process groups on torch 2.13#563
jlamypoirier wants to merge 1 commit into
mainfrom
jlp_fix_torch_2_13_gloo_allgather

Conversation

@jlamypoirier

Copy link
Copy Markdown
Collaborator

Claude Sonnet 5:

Summary

CI on main was failing (all tests/models/test_model.py distributed tests, cascading through pytest-depends) with:

AttributeError: 'torch._C._distributed_c10d.ProcessGroupGloo' object has no attribute 'all_gather_single'

Root cause: setup.cfg pins torch>=2.9.0 with no upper bound, so CI picked up torch 2.13.0 (released between the last two scheduled CI runs). In 2.13, the deprecated torch.distributed.all_gather_into_tensor/reduce_scatter_tensor now dispatch through new all_gather_single/reduce_scatter_single methods. Those are only bound on the generic ProcessGroup wrapper returned by torch.distributed.new_group() — not on the raw Backend-derived objects (ProcessGroupGloo, ProcessGroupNCCL) that Fast-LLM constructs directly (fast_llm/engine/distributed/distributed.py deliberately bypasses init_process_group). Confirmed via PyTorch's C++ pybind bindings at the v2.13.0 tag.

Fix

fast_llm/core/distributed.py: reimplement all_gather_into_tensor/reduce_scatter_tensor to call group._allgather_base(...)/group._reduce_scatter_base(...) directly, bypassing torch's deprecated public wrapper entirely. These are the actual underlying virtual methods (verified to have an identical signature on Backend across torch 2.9.0, 2.13.0, and current main), so this works uniformly across supported torch versions without a version check.

fast_llm/engine/multi_stage/fsdp.py imported reduce_scatter_tensor straight from torch.distributed (same bug, on the FSDP gradient reduce-scatter path) — routed through fast_llm.core.distributed instead, consistent with the rest of the codebase.

Test plan

  • tests/models/test_model.py --models gpt_2 (30 tests, incl. dp2/tp2/sdp2 distributed variants on Gloo) passes locally against torch 2.11.0 — no regression on the previously-working version.
  • CI on this PR exercises torch 2.13.0 and should confirm the actual fix (not reproducible locally; torch 2.13.0 isn't installed in the local dev venv).

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant