Repository navigation
Add coalesced full gradient access - #8374
Marchematics wants to merge 6 commits into
Conversation
Signed-off-by: Marchematics <Marchematics@163.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2ad7b07915
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@Marchematics thanks for the PR. Please address the agent feedback. |
Signed-off-by: Marchematics <Marchematics@163.com>
|
Addressed the agent feedback in 5e314ed: fixed unmapped ZeRO parameters in the coalesced collective, added the regression test, and documented the public API. All commits are signed off. |
Signed-off-by: Marchematics <Marchematics@163.com>
|
Thanks for the PR, how does this work with when autoTP or autoEP is enabled. |
|
The current implementation handles ZeRO data-parallel groups only. AutoTP and AutoEP use additional tensor/expert-parallel sharding, so this helper does not yet reconstruct their full gradients. I can add dedicated AutoTP/AutoEP coverage and reduction handling if you want this API to support those paths. |
Would it make sense to merge this PR with the scope explicitly limited to ZeRO data-parallel groups, and handle AutoTP/AutoEP support in a follow-up PR? |
|
@Marchematics reduced scope is fine. |
Signed-off-by: Marchematics <Marchematics@163.com>
|
Added the reduced-scope documentation and regression coverage in ab0f4dd. The helper reconstructs ZeRO data-parallel gradients; AutoTP/AutoEP shards remain local. ZeRO-3 keeps the existing per-parameter accessor. All 7 targeted tests passed on Apple M4 CPU/Gloo with PyTorch 2.14.1, including two-process ZeRO-1/2 FP32 comparisons against an ordinary PyTorch model. Pre-commit passed on the changed files. The earlier eb0c37c commit deletes 30 workflows and leaves merge conflicts with master. Restoring those workflows is awaiting authorization. GPU, mixed-precision, offload, and ZeRO-3 validation remains. |
Restore workflows to the upstream versions and keep gradient tests under tests/unit/v1/zero. Share fragment assembly with the per-parameter accessor so BF16 reconstruction uses only the owned fragment and preserves fp32 accumulation. Signed-off-by: Marchematics <Marchematics@163.com>
|
Synced with upstream 0eb3a8b in ac0c8a6 and resolved the conflicts. The coalesced helper now shares the upstream BF16 fragment assembly and preserves FP32 accumulation. The two regression cases failed before the fix; all 17 targeted tests now pass on Apple M4 CPU/Gloo with PyTorch 2.14.1, including two-process ZeRO-1/2/3 BF16 accumulation and ZeRO-2 CPU offload. Pre-commit passed. @sfc-gh-truwase Jiahao Zhang marchematics@gmail.com, the author of eb0c37c, has confirmed authorship, the right to contribute under the project license, compliance with DCO 1.1, and agreement to the public, lasting record of the contribution and sign-off. Please review this author confirmation and handle the existing DCO check through the maintainer process. The commit history is preserved. The PR workflows for formatting, CPU tests, Python install smoke, CUDA op compilation, and DCO validation currently show |
Add
safe_get_full_model_gradsfor model-wide gradient access afterbackwardand beforestep. ZeRO-1/2 uses one coalesced reduction per data-parallel group when supported by the backend, with per-parameter reductions as the fallback. ZeRO-3 uses the existing accessor. AutoTP/AutoEP shards remain local.The coalesced path shares fragment assembly with
safe_get_full_grad, including the upstream BF16 fixes: contribute only the owned fragment and prefer FP32 accumulation over the low-precision staging gradient. Parameters owned by another rank still contribute zero buffers to the collective.Fixes #7644. The open-PR search for #7644 returns this PR.
Synced with upstream
0eb3a8bccand resolved the conflicts..githubmatches upstream exactly; the PR diff contains the utility export, implementation, API documentation, and tensor-fragment tests undertests/unit/v1/zero.Validation on one Apple M4 host, macOS 15.7.3, CPU/Gloo with two worker processes, Python 3.12.12, PyTorch 2.14.1:
DS_ACCELERATOR=cpu LOCAL_SIZE=2 DS_UNITTEST_TIMEOUT=90 python -m pytest tests/unit/v1/zero/test_zero_tensor_fragment.py -k 'safe_get_full_model_grads or TestFullModelGrads or full_gradient_reconstruction_uses_only_the_owned_fragment or test_safe_get_full_grad_preserves_fp32_accumulated_average' --torch_ver=2.14.1 -q— 17 passed. Covers ZeRO-1/2 FP32 against an ordinary PyTorch model, BF16 with FP32 accumulation on ZeRO-1/2/3, ZeRO-2 CPU optimizer offload and noncontiguous gradients, remote-owned parameters, fallback, and separate groups.pre-commit run --files deepspeed/utils/__init__.py deepspeed/utils/tensor_fragment.py docs/code-docs/source/zero3.rst tests/unit/v1/zero/test_zero_tensor_fragment.py— passed.python ci/tests_fetcher.py --base upstream/master— selects 88 test files, includingtests/unit/v1/zero/test_zero_tensor_fragment.py.GPU, FP16, NVMe-offload, AutoTP/AutoEP, throughput, peak-memory, and convergence measurements remain. This machine has no CUDA accelerator or driver.
Updated with AI assistance. The author has confirmed the DCO statement for
eb0c37c; maintainer handling of its existing DCO check is pending.