Repository navigation
Conversation
|
This pull request has merge conflicts that must be resolved before it can be |
6548416 to
76f9a69
Compare
4892a23 to
cd7b5c0
Compare
frida-andersson
left a comment
There was a problem hiding this comment.
Thanks for the PR! Can you add the serve and bench commands to the description? A concurrency 1 point would also help, since that's where a per-layer all-reduce change shows most. And the Validation section still describes the CPU-only test with stand-in layers. Can you post the run of the current test file on this head?
| if layer_idx in self.aux_hidden_state_layers and self._aux_needs_reduce( | ||
| layer_idx | ||
| ): | ||
| hidden_states = tensor_model_parallel_all_reduce(hidden_states) |
There was a problem hiding this comment.
This adds an extra all-reduce for every EAGLE3 capture after a deferring layer: the capture reduces a copy, and the next layer's input norm then reduces the same tensor again. The NVIDIA model splits the layer into forward_input_norm and forward_after_input_norm and clones residual after the norm instead. Can you do the same here? Then _aux_needs_reduce isn't needed either
There was a problem hiding this comment.
Good catch, thanks! Split forward into forward_input_norm + forward_after_input_norm to match the NVIDIA model. The loop now captures residual.clone() after the norm has already completed the deferred all-reduce, so there's no extra all-reduce per capture. Removed _aux_needs_reduce and the _maybe_add_hidden_state override entirely.
| if residual is None: | ||
| residual = hidden_states | ||
| attn_input = self.input_layernorm(hidden_states) | ||
| elif self.fuse_input_allreduce and not self.fuse_input_norm_mxfp8: |
There was a problem hiding this comment.
Once #65310 lands, its per-token FP8 norm (VLLM_MINIMAX_M3_FUSE_NORM_FP8=1) comes after this branch, so it would never run behind a deferring layer. Can you sync with @vorapolsiloai on the order?
There was a problem hiding this comment.
Dropped a comment on #65310 with a suggestion on ordering. I think this might land before that one so I proposed they handle the combined case on top of mine. Offered to help test the interaction, and if anything breaks I can pick it up in my follow-up perf PR that builds on this work!
| # specialized decode kernels expect reduced layer outputs. | ||
| defer_ffn_all_reduce = ( | ||
| vllm_config.parallel_config.pipeline_parallel_size == 1 | ||
| and not mono_envs.MONO_ENABLE |
There was a problem hiding this comment.
Minor: Mono decode only turns on at TP4 without DP, PP or EP (_config_refusal), but this turns deferral off whenever the env var is set. Can the config-only checks in _config_refusal be reused here?
There was a problem hiding this comment.
Makes sense, fixed. Now checks whether mono would actually activate (MONO_ENABLE + TP4 + DP1 + no EP) instead of just the env var.
| return MiniMaxM3Model(vllm_config=vllm_config, prefix="model") | ||
|
|
||
|
|
||
| def test_each_deferred_all_reduce_completes_once(dist_init, checkpoint): |
There was a problem hiding this comment.
Nit: This test and the next one only check the flags and a private helper, and the TP2 test already covers the outputs and the captures. Can we drop them?
There was a problem hiding this comment.
Agreed, dropped both. The TP2 test covers the real behavior
|
|
||
|
|
||
| @pytest.mark.parametrize("use_aiter", [False, True]) | ||
| def test_deferred_matches_reduced_at_tp2(checkpoint, monkeypatch, use_aiter): |
There was a problem hiding this comment.
Nit: The reference model sets MONO_ENABLE, which imports flydsl through MonoDecode. Can you add pytest.importorskip("flydsl") like the mono test does?
|
Thanks for the thorough review @frida-andersson ! Updated the PR body with the serve and bench commands, added a c1/remeasured data point on MI355X (TPOT 5.34ms vs 5.35ms, identical) since that was the node available on hand. and EAGLE3 spec decode verification. Test count is 4 after dropping the two flag-only tests per your suggestion. |
5137667 to
ae18b29
Compare
frida-andersson
left a comment
There was a problem hiding this comment.
Thanks @akii96 for the updates! I added two new comments. Also, the description says the test file gives 4 passed on CPU only, but it has three test cases now and they need ROCm GPUs. Can you post the output from this head?
| hidden_states, residual = layer.forward_input_norm( | ||
| hidden_states, residual | ||
| ) | ||
| self._maybe_capture_aux(aux_hidden_states, idx, residual) |
There was a problem hiding this comment.
It looks like a PP stage no longer captures its end_layer, so a capture layer at a stage boundary is lost. E.g. with PP2 the second stage starts at layer 30, which is a default EAGLE3 layer, and the first step then fails with a KeyError on aux_hidden_states_1. Does it make sense to do what e.g. the NVIDIA model does here: skip idx == self.start_layer on later stages and capture self.end_layer before returning IntermediateTensors?
There was a problem hiding this comment.
Thanks, good catch! Fixed it the same way the NVIDIA model does. A PP stage that is not the last one now captures end_layer before it returns, and the next stage skips its own start_layer, so each boundary layer is captured exactly once. I also added a real PP2 test that checks the first stage sends the right aux slots and the last stage only returns its own.
There was a problem hiding this comment.
Minor: It looks like the loop below now captures idx == 0 as well, so layer 0 would be captured twice if it's in the aux layers. Can we move this into the specialized decode branch, since that's the only path still using idx + 1?
There was a problem hiding this comment.
Good point, done. The pre-loop capture now only runs on the specialized decode path, since that is the only one still using idx + 1. The final norm capture had the same problem in reverse on that path, so it now only runs on the normal loop. The TP2 test now captures every layer from 0 to the final norm and also runs the specialized decode loop, so a double capture at either end would fail it.
|
This pull request has merge conflicts that must be resolved before it can be |
ae18b29 to
79bd0f7
Compare
|
This pull request has merge conflicts that must be resolved before it can be |
…'s norm The NVIDIA MiniMax-M3 model leaves each FFN output un-reduced and lets the next layer's input_layernorm (or the final norm) complete that all-reduce through fused_allreduce_gemma_rms_norm. The AMD model only fused the attention-site all-reduce, so every layer paid a separate FFN all-reduce plus a norm. Port the wiring: MoE/MLP built with reduce_results=False, the chain set up in MiniMaxM3Model, and the final norm absorbing the last layer's reduce. EAGLE3 captures after a deferring layer reduce a copy so they never record a per-rank partial. Deferral is off under PP>1 (hidden states cross stages), with mono decode or specialized decode (their kernels expect reduced layer outputs), and for MTP (adds the residual directly). Layers whose input norm also quantizes to MXFP8 all-reduce first and keep that fusion. Co-authored-by: Claude (DSH agent) Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
- Split DecoderLayer.forward into forward_input_norm + forward_after_input_norm
so the model loop can capture residual for EAGLE3 after the norm completes the
deferred all-reduce. This eliminates the extra all-reduce per capture that the
previous _maybe_add_hidden_state override performed, matching the NVIDIA model.
- Remove _aux_needs_reduce and _maybe_add_hidden_state override; replace with
_maybe_capture_aux which clones residual after the norm.
- Capture residual.clone() at the final norm for end-layer EAGLE3 captures.
- Tighten the mono decode guard: only disable deferral when mono would actually
activate (MONO_ENABLE + TP4 + DP1 + no EP), not just when the env var is set.
- Drop two flag-only unit tests (TP2 test covers the actual behavior).
- Add pytest.importorskip('flydsl') to the TP2 test.
- Update test toggle: use PP>1 in config instead of MONO_ENABLE at TP2.
Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
vllm#61813 dropped vllm.transformers_utils.configs.minimax_m3.MiniMaxM3Config. Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
…XFP8 deferred norm - Capture each aux layer exactly once: drop the pre-loop layer-0 capture on the stock path, skip a later PP stage start_layer, send end_layer from non-last PP stages, and keep the final-norm capture off the specialized decode path. - Gate deferral on mono.dispatch.deployment_refusal, the config-only checks MonoDecode itself uses, instead of re-deriving TP4/DP1/no-EP. - Finish a deferred reduce before an MXFP8 input norm through allreduce_gemma_rms_norm_mxfp8 so the fused all-reduce + norm kernels apply. - Tests: MXFP8 input-norm variant at TP2, all aux layers incl. 0 and the final norm, the specialized decode loop, a PP2 boundary capture, and both sides of the mono gate. Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
… fused norm helper changes Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
d724a69 to
ba4ee03
Compare
|
Thanks @frida-andersson! Rebased onto main and addressed both comments. A few other fixes along the way:
|
|
This pull request has merge conflicts that must be resolved before it can be |
| hidden_states, residual = layer(positions, hidden_states, residual) | ||
| self._maybe_add_hidden_state( | ||
| aux_hidden_states, idx + 1, hidden_states, residual | ||
| hidden_states, residual = layer.forward_input_norm( |
There was a problem hiding this comment.
The stock loop now calls forward_input_norm and forward_after_input_norm directly instead of layer(...), so forward pre-hooks on MiniMaxM3DecoderLayer no longer fire. Could you update _install/_replay, take #67038's pinned test list on rebase, and run pytest models/minimax_m3/amd_specialized_decode on this head?
| # norm. PP ships hidden states across stages, and the mono and | ||
| # specialized decode kernels expect reduced layer outputs. | ||
| mono_decode = False | ||
| if mono_envs.MONO_ENABLE: |
There was a problem hiding this comment.
Two paths bypass forward_input_norm and assume reduced layer outputs: the --monokernel FFN kernels (specialized_decode/runtime/executor.py:111) and mono's dense prefix (mono/runner.py:197). This gate only stays in sync with them by predicting their init-time decisions. #66184 (cc @micah-wil) deletes mono/envs.py, so this line becomes a NameError. It also sets specialized_decode_config only after make_layers, so on the obvious rebase that term is always None. With --monokernel at TP4 under the default FULL_AND_PIECEWISE, deployment_refusal refuses on piecewise but specialized decode is still built. Every layer then defers, and the kernel layers norm un-reduced partials, so decode output is silently wrong.
There was a problem hiding this comment.
Agreed, the old check was guessing too early. Fixed in e2dfc2e: with --monokernel on, deferral is now always off. If a layer ever still defers when those kernels start, the server fails at startup instead of giving wrong output. Added a test that mimics the #66184 ordering. I'll handle the envs.py removal on whichever of the two PRs lands second (cc @micah-wil).
| ), residual | ||
| return self.input_layernorm(hidden_states, residual) | ||
|
|
||
| def forward_after_input_norm( |
There was a problem hiding this comment.
#67072 (cc @vgokhale) adds a decode-only glue that all-reduces the MoE output inside the producer (glue/decode.py: tensor_model_parallel_all_reduce(moe_out), or an Mxfp8Carry), and its moe_half call merges cleanly into this method. Whichever lands second needs the glue to honour ffn_all_reduce_deferred, and forward_input_norm needs to handle the carry ahead of its deferred-reduce branch.
There was a problem hiding this comment.
Yes, if both land as-is that MoE output would be reduced twice. Whichever PR lands second should make the glue skip its all-reduce when the layer defers. Happy to do it on my side if this one lands second (cc @vgokhale).
| positions = torch.arange(37, device=device) | ||
|
|
||
| def run(model, vllm_config): | ||
| with torch.inference_mode(), set_forward_context(None, vllm_config): |
There was a problem hiding this comment.
Here attention runs with no metadata and returns zeros (rocm_aiter_unified_attn.py:273, triton_attn.py:629). So the input-norm output, bf16 or the new MXFP8 x_q/x_scale (model.py:1727-1738), reaches nothing that is compared; only the residual stream and the final norm are. Dropping the MXFP8 sub-branch, or passing it the wrong norm weight, still passes at rtol=0, so "bitwise ... with MXFP8 attention" in the description overstates the check. The GSM8K/NIAH runs used fp8_per_channel attention and don't reach this branch either. Yet it is M3.1's prefill path, above the one-stage fused all-reduce + norm size. Could you compare the forward_input_norm outputs of both models directly, and add one M3.1 TP4 GSM8K run?
There was a problem hiding this comment.
Good catch. The test didn't actually check the input norm, and the description said more than it proved. Fixed in e2dfc2e: the test now compares each layer's input norm output directly. To make sure it catches real bugs, I broke that code path on purpose. The old test still passed, the new one fails.
M3.1 TP4 GSM8K on MI355X, which does use that path:
| this PR | main | |
|---|---|---|
| run 1 | 0.955 | 0.963 |
| run 2 | 0.964 | 0.959 |
Same within noise. Description updated.
Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com> # Conflicts: # .buildkite/test-amd.yaml # .buildkite/test_areas/models_basic.yaml
…el, check the input norm outputs Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
|
This pull request has merge conflicts that must be resolved before it can be |
Overview
Make the AMD MiniMax-M3 model defer each layer's FFN all-reduce into the next layer's norm, the same way the NVIDIA model already does. On its own this does not change performance. It is the groundwork for wiring MiniMax-M3 into the fused AITER all-reduce + norm kernels that have already landed (ROCm/aiter#6404). See Details.
Claims
f5d93296) and MI355X (7 configs over two nightlies, full AITER, including c1).Validation
Serve command used for MI355X runs:
The ablation runs on nightly
cf5cea2daused the same command withoutVLLM_ROCM_USE_AITER_FLYDSL_QR_INT4andVLLM_ROCM_QUICK_REDUCE_USE_FLYDSL, which no longer exist on main. That nightly ships AITER 0.1.28.post1, which includes the ROCm/aiter#7258 fix.Bench command:
Unit test.
pytest tests/models/minimax_m3/test_xlayer_allreduce_fusion.pygives9 passedon MI355X. At TP2 the deferred model's final hidden states, every EAGLE3 capture (layer 0 through the final norm) and every layer's input norm output (bf16, or MXFP8 forqkv_proj) match the non-deferred model, exactly without AITER, on both the stock and the specialized decode layer loop. The input norm outputs are compared directly because attention runs without metadata here, so nothing else that is compared depends on them. Giving the deferred MXFP8 norm the wrong weight fails the test. A PP2 run checks that a stage boundary is captured once. The mono tests check that deferral is off exactly when mono decode can run (TP4), stays on at TP2 and under EP, and is off whenever--monokernelis set.pytest tests/models/minimax_m3/amd_specialized_decode/test_model.pygives5 passedon this head, and the other pinned MiniMax-M3 monokernel steps give119 passed, 1 skipped.Performance A/B on MI355X. TP4, nightly
dd4e4014. A is this PR, B is baseline. 0 failed requests.Performance A/B on MI350X. TP4, nightly
2b009fc6d. A is this PR, B is baseline. 0 failed requests.Rerun of this head on MI350X. TP4, nightly
f5d93296, this PR (GPUs 0-3) and the nightly (GPUs 4-7) side by side, three rounds of the two long-context points on one server each. 0 failed requests.Ablation with the follow-up #65858 on MI355X. TP4, nightly
cf5cea2da(AITER 0.1.28.post1). Same image for every column, only the changed Python files swapped. Output tok/s, 4 warmups, 3x concurrency prompts, 0 failed requests. All columns include #65995, which a server with INT4 QuickReduce needs to start on AITER 0.1.28.Gains are relative to the nightly. This PR alone is flat. Each point is a single run, so treat differences below about 1% as noise.
EAGLE3 spec decode. Verified on MI350X (TP4, nightly
40941f2c4) with--speculative-config '{"method": "eagle3", "model": "amd/MiniMax-M3-EAGLE3.1", "num_speculative_tokens": 3, "attention_backend": "TRITON_ATTN"}'. Server loaded, served single and concurrent requests with coherent output, no errors.Quality. GSM8K 5-shot (full, 1319 samples) via lm-eval 0.4.13 (
local-chat-completions,--apply_chat_template --fewshot_as_multiturn, seed 1234, 32 concurrent). The run usedVLLM_ROCM_QUICK_REDUCE_USE_FLYDSL=0to work around a known upstream AITER scale-clipping bug (#59478, fix in ROCm/aiter#7258).On MI355X nightly
cf5cea2da, which has the AITER fix and so no workaround, the same GSM8K setup gives 0.9234 with this PR and 0.9196 on the nightly (flexible-extract, standard error about 0.007).The runs above use
fp8_per_channelattention, so they never reach the MXFP8 input norm. MiniMax-M3.1 does:MiniMaxAI/MiniMax-M3.1-Flashat TP4 on MI355X, nightlybe47189f3, recipe flags plus--reasoning-parser minimax_m3, logsdeferring 60/60 FFN all-reduces into the next norm (59 before an MXFP8 input norm). GSM8K 5-shot viatests/evals/gsm8k/gsm8k_eval.py(chat completions, all 1319 questions, 4096 max tokens):Details
What changes. The NVIDIA model (
vllm/models/minimax_m3/nvidia/model.py) leaves each layer's FFN output un-reduced. The next layer'sinput_layernorm, or the final norm, then finishes the all-reduce throughfused_allreduce_gemma_rms_norm. The AMD model never got this wiring. At TP > 1, every AMD layer pays for a separate full-size all-reduce and a separate norm on its FFN output. This PR ports the NVIDIA wiring:MiniMaxM3MoEandMiniMaxM3MLPare built withreduce_results=False.MiniMaxM3DecoderLayer.ffn_all_reduce_deferredreports whether a layer left its FFN output un-reduced.MiniMaxM3Model._configure_allreduce_fusionsetsfuse_input_allreduceon each layer that follows a deferring layer. The final norm picks up the last layer's reduce.is_mtp_block=True) and PP > 1 keep reducing as before. MTP adds the residual directly, and PP sends hidden states across stages.DecoderLayer.forwardis split intoforward_input_normandforward_after_input_norm, matching the NVIDIA model. Between the two it capturesresidual.clone()for EAGLE3, after the norm has already completed the deferred all-reduce. The model loop still calls each layer as a module, so forward hooks on it keep firing. No extra all-reduce per capture. Each layer is captured once: a later PP stage skips itsstart_layer, which the stage before sends.allreduce_gemma_rms_norm_mxfp8, so the fused all-reduce + norm kernels apply there too.--monokerneland when mono decode can run, decided bydeployment_refusalinmono/dispatch.py, the same config checksMonoDecodemakes. Both read reduced layer outputs but pick their kernels only after the layers exist, so the gate keys on the flags, and setting up either one raises if a layer still defers.Why land this before it shows a speedup. The fused AITER all-reduce + norm kernels for MiniMax-M3 have already landed (ROCm/aiter#6404) and ship in AITER 0.1.28. The follow-up #65858 wires MiniMax-M3 to use them at prefill sizes. Those kernels can only reach the FFN all-reduce if the model defers it into the next norm, which is what this PR does. The ablation table shows the effect: #65858 alone gives about +2%, and with this PR underneath it gives up to +5%. NVIDIA already does this, so it also brings the two models in line.
Landing order. This PR does not depend on any other open PR and can land first. To reproduce the ablation on a current nightly, #65995 is needed: since AITER 0.1.28 renamed
QuickAllReduceInt4.compile(), a server with INT4 QuickReduce fails at startup without it. The follow-ups land after this PR: #57547 (FlyDSL fused all-reduce + RMSNorm inQuickAllReduce), then #65858. Two open PRs touch the same code: #66184 removesmono/envs.py, so itsMONO_ENABLEterm in the gate goes away on rebase, and #67072's decode glue all-reduces the MoE output, so it needs to honourffn_all_reduce_deferred. Whichever lands second takes the small change.Not a duplicate. Two earlier PRs tried the same deferral. #47270 was closed by its author after a flat A/B; this PR is flat on its own too, and the ablation above shows what it unlocks with #65858. #52680 is an idle draft with no description or results that also adds the AR + GemmaNorm fusion itself.
Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.