← Back to Pull requests

[zero] Run ZeRO-3's rank-agreement checks and barriers over the partition group #9076

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 13, 2026 01:45 UTC
Author

ZeRO-3's rank-agreement checks and init barriers ran over the world. They now run over the parameters' partition group, so a ZeRO-3 engine can train on a subset of the ranks while the other ranks hold no engine. With the default group the same ranks take part as before.

This is the first commit of #9074, sent on its own because it does not depend on RFC #9026 and is small (52 lines added and 19 removed in deepspeed/, 21 of the added lines from the third commit, which answers the review), plus a regression test as a second commit (85 lines in tests/unit/v1/zero/test_zero.py).

What breaks on master. Give deepspeed.initialize an mpu whose data-parallel group is a subset of the world, for example ranks 1-2 of three, and leave rank 0 without an engine (a trainer next to inference-only ranks, or two trainer layouts in the same processes):

  • DeepSpeedZeroOptimizer_Stage3._setup_for_real_optimizer calls dist.barrier() over the world, twice, and _create_fp16_partitions_with_defragmentation once more. The trainer ranks wait for rank 0, which never calls it.

  • assert_ints_same_as_other_ranks broadcasts from global rank 0 over the world (assert_lst_len_same_as_other_ranks, get_lst_from_rank0). It is called when a trace is recorded (PartitionedParameterCoordinator), in the coalesced all-gather (Init._all_gather) and, with enable_sanity_checks, in the gradient reduction. Rank 0 is outside the group and never sends.
  • Root cause. These calls predate engines over a subgroup: the data path of ZeRO-3 already uses the partition group (all_gather, reduce_scatter and the parameter broadcasts all pass it), and only the checks and barriers around it still assumed the world.

    The change

  • zero/utils.py: assert_ints_same_as_other_ranks, assert_lst_len_same_as_other_ranks and get_lst_from_rank0 take an optional group and broadcast from the group's first rank. group=None is the old behaviour, so other callers are unaffected.

  • stage3.py: the three barriers pass self.dp_process_group; the gradient bucket's sanity check passes the bucket's partition group, the group that reduces it (third commit, from the review).

  • partition_parameters.py: the two checks in _all_gather pass the parameters' ds_process_group.

  • partitioned_param_coordinator.py: takes process_group (default None) and passes it to its three trace checks. parameter_offload.py hands it the parameters' partition group when they all share one, and None (the world, as before) otherwise or when that group is the world. Not the optimizer's dp_process_group: a model partitioned by zero.Init before AutoTP keeps the world as its partition group while the optimizer works over a smaller one, and the check has to cover the ranks of the all-gathers (third commit, from the review).
  • Validation

    One node with 4× RTX 3090 (24 GB), driver 595.58.03, torch 2.13.0+cu130, NCCL 2.29.7.

    Regression test TestZero3OverSubgroup (in tests/unit/v1/zero/test_zero.py): a world of three, ZeRO-3 over ranks 1-2 through an mpu, rank 0 without an engine. Three SGD steps are compared with plain torch SGD on the same model and batch. SGD with gradient_clipping set to 0, so that the comparison sees the scale of the averaged gradient (an engine clips to norm 1.0 by default, and Adam hides a constant scale).

    | Tree | Tests (python -m pytest -q -rfEs, from tests/) | Result |
    | --- | --- | --- |
    | master + the test commit | unit/v1/zero/test_zero.py::TestZero3OverSubgroup | does not finish; killed after 5 minutes |
    | this PR, GPU (NCCL) | same | 1 passed in 9.4 s |
    | this PR, CPU (gloo, DS_ACCELERATOR=cpu) | same | 1 passed in 30 s |
    | this PR, GPU | unit/v1/zero/test_zero.py, unit/v1/zero/test_zero_init_pg_contradiction.py, unit/runtime/zero/test_zero_context.py | 137 passed, 1 skipped (marked "not working" on master) |

    I did not look at where the run on master blocks; the first world barrier in _setup_for_real_optimizer is the first call rank 0 never answers.

    The third commit (the two review findings), on one node with 4× H100 (94 GB), driver 580.105.08, torch 2.13.0+cu130, NCCL 2.29.7:

    | Tree | Tests | Result |
    | --- | --- | --- |
    | this PR, GPU (NCCL) | unit/v1/zero/test_zero.py::TestZero3OverSubgroup | 1 passed |
    | this PR, CPU (gloo, DS_ACCELERATOR=cpu) | same | 1 passed |
    | this PR, GPU | unit/v1/zero/test_zero.py, unit/v1/zero/test_zero_init_pg_contradiction.py, unit/runtime/zero/test_zero_context.py | 137 passed, 1 skipped |
    | this PR, GPU | unit/checkpoint/test_zero_affine.py (with TestAutoTPStorageMaps: TP2 × DP2, including zero.Init before AutoTP), unit/v1/moe/test_moe.py (expert and dense parameters in different partition groups) | 70 passed |
    | the first two commits, GPU | same | 70 passed |

    Compatibility

  • Default group: an engine's default dp_process_group holds every rank, so the same ranks take part in every barrier and check as before. The ZeRO test files above run at the default group.

  • Validated on a subgroup: ZeRO-3, fp32, SGD, no offload, GPU (NCCL) and CPU (gloo), one node. #9074 adds Adam on a subgroup in its tests (a trainer on one of two ranks, and a trainer moving between layouts) and a bf16 model trained on two of four ranks in its DP4 → DP2 → DP4 run.

  • Not validated on a subgroup: fp16, parameter or optimizer offload, NVMe, enable_sanity_checks, several nodes.

  • Not covered: save_checkpoint and _commit_decoupled_checkpoint in engine.py still call dist.barrier() over the world, so a subgroup engine cannot save a checkpoint while the other ranks stay out. That is a separate change.

  • ZeRO-1/2 are not touched.
  • AI assistance: AI assistance was used. The code, the test and this description were drafted with an AI coding agent (Claude Code). The submitter reviewed every changed line and ran the tests above.

    cc @Achyuthan-S @jinyouzhi

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: LiRunGuo Review duration: 26260m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #9076"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%