Repository navigation
Conversation
deepspeedai#8840 copies each pinned CPU master partition to the device in float32 and casts it there. It moved the whole sub-group at once, so step() needed a float32 device temporary of the whole sub-group: up to 3.73 GiB at the default sub_group_size of 1e9. Its description says that the copy goes in pieces of 2**26 elements (0.25 GiB). The copy now goes in pieces of 2**26 elements, in order on one stream, so each piece reuses the memory of the previous one. Signed-off-by: Xinyu Lian <lian7@illinois.edu>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
0z5a
left a comment
There was a problem hiding this comment.
Read at 8e6295a1. This looks right to me: the pieces are views of the pinned buffer, so non_blocking still applies, and since they run in order on one stream, the allocator can reuse each piece's temporary for the next one.
Your test skips on the CPU accelerator, so I checked the chunking directly. I called _copy_pinned_master_to_device with PINNED_MASTER_COPY_NUMEL patched to 1000, a no-op event (the CPU accelerator has none) and an fp32 source of 0, 1, 999, 1000, 2000 and 2500 elements: the bf16 destination equals src.to(torch.bfloat16) every time, tails and the empty case included. I can't check the device-memory numbers here. A small test along those lines, with the constant patched down, would let the CPU job cover the tail logic too.
|
thank you for contributing this. the #8840 assumes OOM not an issue and the chunked buffer idea is dropped. My bad of missing updating the PR description accordingly. |
|
LGTM, @sfc-gh-truwase , would you mind taking a look as well? ;--) |
|
@xylian86 my concern with @pengdurice's original code is that the OOM risk is minimal to justify the extra complexity of a chunked approach. Did you encounter an OOM issue? |
|
@sfc-gh-truwase No, not in a real run.
So this PR can still let a slightly larger model fit, but I'm also fine with closing it. |
|
@xylian86 thanks for confirming the details. I think we can close for now as there are multiple efforts to improve offloading performance :). I am very delighted by the renewed focus on offloading. |
Summary
#8840 copies each pinned CPU master partition to the device in float32 and casts it there. It moves the whole sub-group at once, so with
offload_optimizer.pin_memory: true(the default)step()needs a float32 device temporary of a whole sub-group: up to 3.73 GiB at the defaultsub_group_sizeof 1e9. The description of #8840 says the copy goes in pieces of 2**26 elements (0.25 GiB); the merged code does not. No release has #8840 yet.This PR copies in pieces of 2**26 elements, in order on one stream, so each piece reuses the memory of the previous one. ZeRO-1/2 cast on the host into a pinned 16-bit buffer and have no device temporary; SuperOffload and ZenFlow's overlap step copy the masters their own way.
No open issue or PR covers this.
Fixes
Before → after, 1 GH200, bf16, ZeRO-3 with
offload_optimizer: {device: cpu, pin_memory: true}, base1a956270f. Device memory thatstep()takes on top of what is allocated before it:sub_group_size(one sub-group of 1007M elements): 3.75 → 0.25 GiB.The step time does not change (1.0B: 0.178 → 0.178 s; copy-back 12.7 → 12.8 ms).