Add forward all-gather overlap#5513
Conversation
0ca3392 to
89490e3
Compare
wujingyue
left a comment
There was a problem hiding this comment.
Notes from the review meeting:
Even though the PR delayed releases, F_i still happens before AG_{i+1} on CPU. As a result, F_i's kernel(s) is often scheduled on GPU before AG_{i+1}'s ncclAllGather kernel. This may cause F_i's kernel(s) to occupy all the SMs before the ncclAllGather, preventing the overlap. In addition, the CPU overhead may delay the launch of the ncclAllGather, further reducing the chance of overlap.
I'll try to reproduce these issues by making the layers use more compute.
Potential options to alleviate this:
- Prefetch
AG_{i+1}beforeF_i. We'll have to capture and keep a global (per-context, more precisely) list of modules so we know what's the next module to run. - Make allgather SM free. This assumes certain hardware architectures that some customers might not have.
- Green context so some SMs are dedicated for communication. But I'm told for Hopper these SMs can't be reused for compute when the communication is done.
cc @shjwudp, @Autumn1998 and @lhb8125
|
To follow up on #5513 (review), I prototyped and measured several approaches based on https://github.com/NVIDIA/Megatron-LM/pull/5513/changes#diff-91a39bc60a4a92f082088142637e0e73984537670406511f973df8e50355f9b8R314 Observations (Eos H100; dim=4096 fixed, M=8192 for the cited timing; M swept 4k–64k, bf16)
External corroboration — PyTorch FSDP2
Recommendations
cc @shjwudp, @Autumn1998 and @lhb8125 |
Signed-off-by: Jingyue Wu <wujingyue@gmail.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
The overlap test synchronized after the profiler context exited, so the profiler finalized its trace before in-flight device kernels completed and recorded no CUDA events. Move the synchronize inside the profiler window (matching test_symmetric_memory.py) and drop the no-op prof.step(). Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
The name-based compute filter matched only gemm/cutlass/cublas, but on the CI H100 stack (torch 2.12 / CUDA 13) bf16 GEMMs are cuBLASLt nvjet_sm90_* kernels, so the filter found nothing and the test failed at the compute-event assertion. Add nvjet to the token set and rename compute_events -> gemm_events to reflect that it matches GEMM kernels by name. Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
@wujingyue I am still concerned about the launch timing in CPU cases, which are almost everywhere in real workloads. Full-iter CG and SM-free comm are not validated as universal methodologies. Could you explain a little bit about the "prefetch for 2+ layers by tuning |
|
/ok to test 9f5989c |
Yes, I'm also concerned. Therefore, I plan to go simple first (this PR) and then revisit after #5614 bringing us some realistic workload. #5719 is the draft PR that implements explicit prefetching if you'd like to preview!
Yes. http://nv/mfsdp-schedule-design => the "prefetching" section |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29037499391 |
Summary
Implements part of http://nv/mfsdp-schedule-design
FsdpContextthat lazily owns a CUDA all-gather stream for one FSDP subtree.num_children - 1all-gather/compute overlaps.Scope
post_backwardbefore autograd reaches the next module’spre_backwardall-gather.Testing
python -m torch.distributed.run --nproc-per-node 2 -m pytest -q tests/unit_tests/distributed/megatron_fsdp/test_context.py tests/unit_tests/distributed/megatron_fsdp/test_experimental_fully_shard.py --tb=short --disable-warnings -rNgit diff --check