Repository navigation
[Perf][Diffusion] MAGI-2: reuse SP MoE sequence-size metadata - #7120
NancyFyong wants to merge 3 commits into
Conversation
Pass request-scoped Ulysses split sizes through transformer layers so SP4 MoE dispatch avoids repeated scalar all-gathers in every layer. Keep the collective fallback for direct callers and add four-rank Gloo and NCCL parity regressions. Refs vllm-project#7085 Signed-off-by: NancyFyong <NancyFyong@users.noreply.github.com>
The existing CUDA regression called the MoE module directly with explicit split sizes, so the production Magi2TransformerLayer propagation was only covered by the CPU/Gloo parity test. Add a two-GPU NCCL test that runs the real transformer under an uneven SP2 split and compares the reused-metadata output against the same ranks forced back onto the per-layer collective, requiring exact equality and one baseline collective per MoE layer. Refs vllm-project#7085 Signed-off-by: NancyFyong <NancyFyong@users.noreply.github.com>
Break one Magi2MultiHeadMoELayer step into the components vllm-project#7085 M3 asks about: sequence-size exchange, head dispatch/undispatch, TP reduction, routed expert compute and the shared-expert branch. Includes an overlap probe that runs the shared branch while the dispatch all-to-all collective is in flight, so the value of compute/communication overlap is measured rather than assumed. Refs vllm-project#7085 Signed-off-by: NancyFyong <NancyFyong@users.noreply.github.com>
|
Same change measured on MTT S5000 (MUSA), MAGI-2 272p/125 frames/100 steps at SP4xCFG2: passing |
|
@NancyFyong Are you planning to continue work on this PR? Please reply by 2026-10-20 04:15:52 UTC. A yes or a brief plan is enough; code changes do not need to be finished within these three days. If you are waiting on a review or other maintainer action, please let us know. If there is no reply, new commit, or maintainer takeover by then, we will recheck the PR's status before deciding whether to close it as inactive. It can be reopened when work resumes. |
Purpose
Refs #7085 (M3). Two parts:
Remove the repeated MoE sequence-size exchange on the SP path.
Magi2MultiHeadMoE.forwardgathered the per-rank sequence length with a scalar
torch.distributed.all_gatherplus a host.item()before everyep_dispatch. MAGI-2 Preview runs MoE in 36 of its 40 layers, so onetransformer forward paid that metadata round-trip 36 times per denoising step, even though the
transformer already knows the Ulysses split for the request. This passes the existing
request-scoped
cp_split_sizesdown to the MoE layer, so the production SP path performs zeroper-layer metadata collectives. Shard ownership, routing and expert compute are unchanged.
Add a component profiler (
benchmarks/diffusion/magi2_moe_communication.py) covering theareas M3 names — sequence-size exchange, head dispatch/undispatch, TP reduction, routed expert
compute, and the routed/shared branch split — plus a probe that overlaps the shared branch with
the dispatch collective, so the value of compute/communication overlap is measured rather than
assumed.
What this PR claims, and what it does not. It removes 36 redundant collectives per transformer
forward, with bit-exact decoded output and unchanged peak memory. The saving is reproducible at the
layer level (0.23 ms/layer, about 8.2 ms/forward at SP4), and a 31-pair interleaved end-to-end study
resolves it at roughly +0.4% on the 272p/100-step T2VA workload, with the mean paired delta
landing exactly on the value predicted by the component profile. It is a small effect: the honest
summary is "removes provably redundant work, output-preserving, no memory cost, with a measurable but
sub-percent latency benefit", not a headline speedup.
Scope notes:
tensor-valued
cp_split_sizesstill takes the legacy path.reductions, shared-expert execution restructuring, and compute/communication overlap are
profiled and, based on the measurements below, not worth pursuing on this hardware class.
Test Plan
vLLM Version: 0.28.0
vLLM-Omni Commit: 3237096
sand-ai/MAGI-2-previewrevision2dea51b64db47ee5b4402d36fd90829a0c58913b32370968/92a13868Test 4 runs the same ranks and weights twice — once on the production path and once forced back
onto the per-layer collective — and requires exact output equality plus one baseline collective per
MoE layer. Mutation check: reverting the propagation in
Magi2TransformerLayer.forwardtosequence_split_sizes = Nonemust turn test 4 red.Test Result
tests/diffusion/models/magi2,core_model and cpumax_error=0,scalar_all_gathers=0still performs per-layer sequence-size collectives (2 scalar all_gather calls)End-to-end numerical equality — exact
MAGI2_DETERMINISTIC=1, seed 42, full 100-step trajectory, released checkpoint, resident SP4.Decoded streams, not container bytes, because the MP4 container is not byte-reproducible:
T2VA:
3237096862cc40426983d942f4555c01a192f34392a1386862cc40426983d942f4555c01a192f343Both streams are identical, so the change is output-preserving on a real trajectory, not only on the
synthetic module tests. Frame count, geometry, frame rate and the 44.1 kHz stereo audio contract are
preserved by construction since the streams match bit for bit.
Note for anyone repeating this: default (non-deterministic) mode does not reproduce byte-identical
output across runs even with a fixed seed, so equality must be checked with
MAGI2_DETERMINISTIC=1.I2VA, same geometry and parallelism, first frame supplied as the conditioning image:
32370968570bf6a41d6dd9d31d21956548514ffb92a13868570bf6a41d6dd9d31d21956548514ffbBoth conditioning modes required by the acceptance criteria are therefore covered, and both are
bit-exact on the full 100-step trajectory. Each decoded output was verified to match the MAGI-2 output
contract before comparison: 448x256, 125 frames, 44.1 kHz stereo, 10.000 s.
End-to-end latency — small but resolved
31 interleaved pairs, each pair running base then candidate back to back so machine drift affects both
arms of a pair almost equally. 62 runs total, zero failures, engine-reported generation time
(checkpoint load excluded).
Paired delta (base minus candidate), n=31:
How to read this honestly: the two mean-based confidence intervals marginally include zero, because the
delta distribution carries two symmetric Tukey outliers (-6.65 s and +5.70 s) that inflate the
variance. The rank-based tests, which are the appropriate ones under those outliers, are significant
(p=0.011 and p=0.024), the median and trimmed mean are both larger than the mean, and the mean lands
exactly on the independently predicted 8.2 ms/forward x 100 steps. The consistent reading is a real
effect of roughly 0.35-0.45%, bounded above by about 0.7% at 95%.
Peak worker memory was 66,830.00 MiB (65.26 GiB) in all 62 runs of both arms, so there is no memory
regression and no memory improvement.
Transparency notes:
predicted effect. That was an ordering artifact; it was discarded and re-run interleaved. It is
recorded here so those numbers are not later quoted as a speedup.
supersedes it. The required sample size was estimated from that pilot's paired sd before running.
Component profile at the released SP4 layout
Released Preview geometry (40 layers, hidden 3072, 12 MoE heads, head dim 256, 256 experts, top-k 6,
expert/shared/modality intermediate 1280), 7,500 local tokens per rank, BF16, 5 warmup + 30 measured
iterations, rank-max median. Min/max stayed within about 1% of the median for every row.
split_linearmerge_linearep_undispatchep_dispatchSecondary layouts, same workload: SP2 removes 0.180 ms/layer; TP2 removes about 0 because the TP
path returns before the exchange, and its
merge_linearreduction costs 0.202 ms/layer.Two conclusions:
it grows with world size (0.180 ms at SP2 to 0.228 ms at SP4), for a change that adds no new state
and no new collective.
the layer, while local expert compute is 70.9%. That points at M2, not further M3 communication work.
Negative result: shared/routed overlap is not worth it
The shared-expert branch depends only on
normalized, not on the routed result, so it can legally runwhile the dispatch collective is in flight. Measured with an async
all_to_all_singleand the sharedbranch in the gap:
The difference is +0.03% at SP4 and +0.01% at SP2, inside run-to-run spread, and it repeated across
runs. The dispatch is only 0.27 ms and the two branches contend for the same SMs, so there is nothing
meaningful to hide. Recommendation: do not restructure the layer for overlap on this hardware
class. Reported so the next contributor does not repeat the experiment.
Compatibility
Magi2MultiHeadMoEcallers without split metadatacp_split_sizesNote for #7112: its regional-compile refactor calls
self.mlp.moe_mlp(routed)directly, so whicheverlands second needs to forward the split metadata through that call.