Skip to content

Optimize DistMuon packing copies - #4250

Open
jadenmach2 wants to merge 3 commits into
pytorch:mainfrom
jadenmach2:perf/batch-distmuon-packing-copies
Open

Optimize DistMuon packing copies#4250
jadenmach2 wants to merge 3 commits into
pytorch:mainfrom
jadenmach2:perf/batch-distmuon-packing-copies

Conversation

@jadenmach2

@jadenmach2 jadenmach2 commented Aug 20, 2026

Copy link
Copy Markdown

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.

Metric Baseline Batched copies Change
Async copies per rank 493 423 -14.2%
Non-RCCL kernel launches per rank 1,474 1,421.5 -3.6%
DistMuon GPU span 93.12 ms 92.54 ms -0.6%
DistMuon CPU span 92.29 ms 92.64 ms +0.4%
RCCL launches per rank 8 8 unchanged

The optimization measurably reduces copy and launch overhead. End-to-end optimizer latency remains effectively unchanged within run-to-run noise.

@meta-cla

meta-cla Bot commented Aug 20, 2026

Copy link
Copy Markdown

Hi @jadenmach2!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 20, 2026
@meta-cla

meta-cla Bot commented Aug 20, 2026

Copy link
Copy Markdown

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)

@weifengpy weifengpy Aug 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants