Repository navigation
ZeRO-1/2 gradient accumulation: close the executable test gaps from #8957 - #3
kritikagarg wants to merge 1 commit into
Conversation
Issue deepspeedai#8957 lists checks still missing after deepspeedai#8949. These are the ones that can be executed and can actually fail on a CPU-only host with two ranks. tests/unit/v1/zero/test_zero2_offload_multi_backward.py adds five two-rank end-to-end tests over a padded, rank-split parameter group (3 + 6 gradient elements padded to 12, so rank 1 owns its fragment at a non-zero source offset behind three padding elements): - late first use of a parameter in a multi-request window, including an overlap_comm variant, - a non-finite window followed by finite windows with fp32 accumulation, - clipping and Inf detection for a parameter that only ever contributes on a non-boundary backward, - fractional contributions (1 and 1/256) whose sum bf16 cannot hold, so the configured accumulation dtype is observable, - managed_gradient_accumulation=false with several backwards per step(). Every gradient and update is checked against an independently derived reference: the sum-loss gradient of a bias-free linear layer is the input column sums, the update comes from plain torch SGD, and the clipped update from torch.nn.utils.clip_grad_norm_. No assertion uses the sibling offload/non-offload path as its oracle. tests/unit/v1/zero/test_zero_cpu_offload_grad_accum.py previously only checked that the host-partition norm moved between micro-steps. It now also checks the accumulated gradient against the analytic micro-batch sum, which a wrong accumulation magnitude cannot pass. ZeRO-1 with overlap_comm is excluded from the new matrix: it returns a different wrong gradient for each half of the split parameter on its own, a reduction defect that needs its own report. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
PR Summary — deepspeedai#8957: ZeRO-1/2 gradient accumulation test coverage
What the issue asks fordeepspeedai#8957 is a maintainer-authored checklist of test gaps left over from PR #8949 ("ZeRO-1/2: preserve gradients across request boundaries until step"), which is merged. It is pure test work — no runtime change should appear in this diff. The issue also criticises the existing tests on three specific grounds, which constrain how the new ones must be written: flowchart LR
C1["existing tests call optimizer<br/>helpers on a <b>partial object</b>"] --> R1["→ drive real engine APIs instead"]
C2["existing tests use the <b>sibling path</b><br/>as the oracle"] --> R2["→ anchor to an <b>independent</b><br/>summed-loss reference"]
C3["existing tests set only <b>one</b><br/>accumulation boundary"] --> R3["→ several boundaries before one step()"]
style R1 fill:#1b5e20,color:#fff
style R2 fill:#1b5e20,color:#fff
style R3 fill:#1b5e20,color:#fff
Checklist from the issue
|
| Component | Status | Workaround in use |
|---|---|---|
cpu_adam |
❌ cannot build | use "torch_adam": true where the test allows |
fused_adam |
❌ cannot build | avoid |
deepspeed_shm_comm |
❌ cannot build | DS_TEST_DISABLE_SHM=1 → plain gloo |
Consequence for review: the final report must separate items proven by an actual run here from items written but only runnable where cpu_adam builds. The second group may well be larger. Pass counts alone will overstate the coverage.
Why it is taking a long time
Not a hang — measured directly:
- 2 physical cores, ~1 GB free RAM
- torch defaults to 2 intra-op threads per process; each
DistributedTestspawns 2 ranks → ~4 threads on 2 cores (2× oversubscription) - the agent runs one test at a time, each under its own
timeout, so CPU arrives in bursts separated by decision gaps - 9 checklist items × (write → run → interpret) on that hardware
Verification status
| Check | Status |
|---|---|
| Tests written | ~490 lines across 2 files |
| Confirmed test run | ❌ not yet |
pre-commit |
❌ not yet |
| Teeth-check (fails without deepspeedai#8949 behaviour) | ❌ not yet |
| Items proven vs. unprovable, itemised | ❌ pending report |
Not done
- No DCO
Signed-off-by. - Not submitted upstream. Fork PR is a draft deliberately.
062c461 to
b4368e3
Compare
✅ Verified — replaces the draft notice abovePR Summary — deepspeedai#8957: ZeRO-1/2 gradient accumulation test coverage
What was builtSix new tests closing the executable portion of deepspeedai#8957's checklist. Every end-to-end test runs over a two-rank, padded, rank-split parameter group built from flowchart TD
M["SplitProjectionModel<br/>first.weight: 3 elems · second.weight: 6 elems<br/>total 9 → <b>padded to 12</b>"]
M --> R0["<b>rank 0</b> partition (size 6)<br/>grad_position {0:[0,0,0,3], 1:[0,0,3,3]}<br/>owns all of first.weight<br/>+ first half of second.weight"]
M --> R1["<b>rank 1</b> partition (size 6)<br/>grad_position {1:[0,3,0,3]}<br/><b>source_offset = 3 > 0</b><br/>behind <b>3 padding elements</b><br/>owns NO fragment of first.weight"]
R0 --> W["⇒ exercises split params, non-zero source offset,<br/>padding, and a param absent from a rank"]
R1 --> W
style R1 fill:#5d4037,color:#fff
style W fill:#1b5e20,color:#fff
The oracle is analytic, not the sibling pathThis was the issue's central complaint about existing coverage. Every assertion anchors to an independently derived reference: flowchart LR
A["sum-loss gradient of a<br/>bias-free Linear =<br/><b>input column sums</b><br/><i>(calculus)</i>"] --> AS["gradient assertions"]
B["<b>torch.optim.SGD</b><br/>on fp32 copies"] --> BS["update assertions"]
C["<b>torch.nn.utils<br/>.clip_grad_norm_</b>"] --> CS["clipped-update assertions"]
D["L2 norm of the independent<br/>gradient vs public<br/><b>engine.get_global_grad_norm()</b>"] --> DS["norm assertions"]
style A fill:#1b5e20,color:#fff
Fixture inputs are eighths, so every per-backward gradient and every partial sum is exact in bf16 (numerator < 256). That allows Checklist disposition
Teeth-check — 9 mutations, each caughtSource was mutated one line at a time, then restored. Highlights:
I re-ran that last one independently — it is the key resultThis is exactly the defect class deepspeedai#8957 complained about: the old test asserts only that the host-partition norm changes, which any wrong-magnitude accumulation satisfies. Also self-discriminating without any mutation: Verified results
🔴 Incidental finding — possible real bug, needs its own issueFound on unmutated master
Corrections to my briefing — the agent was right
It triaged against the current code rather than the issue snapshot, and launched its own ranks via Sandbox workarounds — local only, NOT committed
Both module paths ( Not validatedGPU/CUDA of any kind · FP16 end to end · CPUAdam and No convergence/throughput/memory numbers — correctly N/A, since this adds tests only and changes no numerics. Hardware: CPU only, aarch64, 2 cores, no accelerator, gloo, torch 2.15.0+cpu, Python 3.13.18, no C++ compiler. Not done
|
Addresses deepspeedai#8957 (ZeRO-1/2 gradient accumulation: remaining test coverage).
Review PR against my own fork — not submitted upstream. DRAFT: work in progress.
Status
This is an in-progress snapshot, pushed while the authoring agent is still running its test suite. Nothing here has been verified yet — no confirmed test run, no pre-commit check, no teeth-check. Do not review for correctness yet; it will be force-updated with the verified commit when testing completes.
Currently +490 lines across:
tests/unit/v1/zero/test_zero2_offload_multi_backward.pytests/unit/v1/zero/test_zero_cpu_offload_grad_accum.pyContext
deepspeedai#8957 is a maintainer-authored checklist of missing test coverage, a follow-up to PR deepspeedai#8949 ("ZeRO-1/2: preserve gradients across request boundaries until step"), which is merged. It is test-only work — no production code should change.
Known environment limitation (important for judging the evidence)
This work was prepared on a CPU-only aarch64 box, 2 cores, with no C++ compiler. Consequently
DeepSpeedCPUAdam,fused_adamanddeepspeed_shm_commcannot be JIT-built.That matters a lot here: deepspeedai#8957's checklist is largely about CPU-offload gradient accumulation, and CPU offload requires
DeepSpeedCPUAdam. So a meaningful share of the checklist is not executable in this environment at all, regardless of whether the tests are written correctly. Expect the final report to separate:cpu_adam.AI assistance
AI assistance (Claude Code) was used to write these tests. Per
AGENTS.md, a human must read every changed line and add the DCOSigned-off-bybefore anything goes upstream — no sign-off has been added, and this is explicitly not upstream-ready.