Optimize DistMuon packing copies - #4250
Conversation
|
Hi @jadenmach2! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
| for destination, source in zip(destinations, sources, strict=True) | ||
| ) | ||
| if foreach_compatible: | ||
| torch._foreach_copy_(destinations, sources) |
There was a problem hiding this comment.
this is good change! we can make it default, without considering backward compatibility. i do think optimizer has uniform dtype, layout, device
how about this via a minimal lines of code, example #4271 (my cheap ai slop to make things concrete)
- only do foreach_compatible logic
torch._foreach_copy_check compatbility- rename to
_batched_copy_
There was a problem hiding this comment.
@weifengpy Pushed the requested simplification, following the approach demonstrated in #4271:
• removed the compatibility checks and fallback;
• renamed the helper to batched_copy;
• updated tests for dtype conversion and shape mismatch behavior.
I also reran the four-GPU Kimi DistMuon FSDP+EP E2E test on AMD MI250 (ROCm). It completed successfully with matching loss and gradient norm across all ranks. Thanks for the review!
Motivation
DistMuon’s redistribution runtime packs and unpacks tensor regions around its all-to-all collectives. Each region was copied with an individual
Tensor.copy_()call.For parameters split into multiple regions, this produces several small copy operations and GPU launches for each redistribution phase. Profiling the Kimi K2.7 DistMuon configuration on four AMD MI250 GPUs showed an average of 493 asynchronous copies and 1,474 non-RCCL kernel launches per rank during the optimizer step.
Benchmark
Measured on four AMD MI250 GPUs with ROCm using the Kimi K2.7 debug model with DistMuon, FSDP degree 4, and expert-parallel degree 2.
Values are averages across four ranks for the same profiled optimizer step.
The optimization measurably reduces copy and launch overhead. End-to-end optimizer latency remains effectively unchanged within run-to-run noise.