Skip to content

Link ZeRO-1/2 fragments at their round-robin offsets - #8637

Closed
alanhuangyoo wants to merge 1 commit into
deepspeedai:masterfrom
alanhuangyoo:fix/round-robin-hp-offsets
Closed

alanhuangyoo wants to merge 1 commit into
deepspeedai:masterfrom
alanhuangyoo:fix/round-robin-hp-offsets

Conversation

@alanhuangyoo

@alanhuangyoo alanhuangyoo commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

With round_robin_gradients, ZeRO-1/2 lay the flat buffer out in round-robin order, but _link_all_hp_params only passed those offsets to link_hp_params when there was alignment padding (#8277). Without padding the mapping is summed up in bit16_groups order, so after the first reordered parameter everything points at a neighbour's slice. safe_get_full_fp32_param, safe_get_full_grad and the rest of the fragment API hand back another parameter's data, and universal checkpoints mislabel the fragments. Training itself is fine, it only touches the flat partitions.

I ran into it while working on #8609. On 2×H20, ZeRO-2, six layers:

  • safe_get_full_fp32_param(p) vs p: 0 without round robin, 5.9e-1 with it, 0 with this change.
  • A universal checkpoint saved without round robin and resumed with it (Adam, fp32) was 2.4 off after two steps. With this change it's bit-identical, and so are the other two combinations.

The fix just always passes the round-robin offsets. The existing fragment tests only check that the getters return something, which is probably why this has been around since tensor fragments came to ZeRO-2 (#2727). The new TestTensorFragmentValues compares them against a plain PyTorch copy of the model on the same batch; the round-robin cases fail on master and pass here.

Also ran test_zero_tensor_fragment.py, test_stage2_flatten_on_gpu.py, test_muon_checkpoint.py, the AutoEP grad parity and unit tests, and the fp32 cases of test_universal_checkpoint.py: 328 passed, 33 skipped.

Environment

NVIDIA H20-3e, driver 580.105.08, Python 3.11.15, torch 2.9.1+cu128; the runs above used 2 GPUs.

With round_robin_gradients the flat buffer is laid out in round-robin
order, but _link_all_hp_params only passed those offsets to
link_hp_params when there was alignment padding. Without padding the
mapping was summed up in bit16_groups order, so parameters pointed at
their neighbours' slices: safe_get_full_fp32_param, safe_get_full_grad
and the other fragment accessors returned another parameter's data, and
universal checkpoints mislabelled every fragment. Always pass the
round-robin offsets.

The fragment tests only checked that the getters return something.
TestTensorFragmentValues compares them against a plain PyTorch copy of
the model on the same batch.

Signed-off-by: alanhuangyoo <[email protected]>

@ghost ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent two-GPU RTX 5090 validation at head 747cbc8df6e81d52ba1b20060f8f9e04a4d4ff4e: the upstream TestTensorFragmentValues passed ZeRO-1/2 × round-robin off/on (4/4). I added a setter check with round-robin enabled for ZeRO-1/2 × parameter_alignment off/on (4/4). It asserted a nonidentity parameter reorder and the actual per-parameter padding state. The full FP32 getter matched every named parameter before the write; after writing one parameter with safe_set_full_fp32_param, that parameter matched the replacement and every neighbor remained unchanged.

These runs used the PR's exact changed source and test over installed DeepSpeed 0.19.7. They cover DP=2 reads and writes with and without per-parameter padding; checkpoint round-trip and DP=4 remain untested here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The offset mapping is correct and the regression test exercises both affected stages and layouts.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes ZeRO-1/2 tensor-fragment mappings for round-robin flat-buffer layouts.

Changes:

  • Always supplies actual flat-buffer offsets when linking parameters.
  • Adds value-based regression tests for parameters and gradients.
File Description
deepspeed/​runtime/​zero/​stage_1_and_2.py Maps fragments using round-robin offsets.
tests/​unit/​runtime/​zero/​test_zero_tensor_fragment.py Tests fragment values across ZeRO stages 1/2.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants