Skip to content

perf(megamoe): overlap MXFP8 input replay and accelerate weighted backward - #7

Merged
davidhe91 merged 2 commits into
davidhe91:megamoe-ascend950-integrationfrom
dz-ssk:perf/mxfp8-replay-integration-latest
Dec 3, 2026
Merged

davidhe91 merged 2 commits into
davidhe91:megamoe-ascend950-integrationfrom
dz-ssk:perf/mxfp8-replay-integration-latest

Conversation

@dz-ssk

@dz-ssk dz-ssk commented Dec 3, 2026 •

Copy link
Copy Markdown

MXFP8 selective input replay currently runs as a separate dispatch/quantization launch before backward, and activation replay loses the adjacent-expert Vector preparation pipeline. The weighted SwiGLU-gradient path also uses a small scalar-synchronized reduction tile. This change overlaps Pull input restoration with backward and reduces weighted-backward overhead while retaining both probability-weighting modes.

  • Join input replay into the backward task graph, reuse the consumed BF16 dY receive buffer and the per-expert Combine destination, and preserve dX/Combine priority over weight gradients. Combine waits for both dX and the input-replay reader; all dY GETs precede replay GETs on each FIFO owner.
  • Preserve the adjacent-expert activation-replay pipeline and use queue-bounded probability-gradient reduction tiling. TN tasks fully overwrite dW; cold experts are zeroed on device rather than relying on a host-side zero-fill.
  • Keep MegaMoeNumericsOptions(apply_probs_before_fc2=...) and its default False. Both before- and after-FC2 branches remain available. Keep the upstream delayed conversion for post-FC2 weighting. Push retains its separate replay path; Token Wave retains its existing supported combinations.

Matched single-host eight-card results

Base 3b677e1; candidate 2f3c1b2. Ascend950, CANN 9.2.2 / PTA 2.12, EP8, 4096 tokens/card, H7168, I2560, 64 routed experts, TopK8, one same-width fused shared expert, fixed balanced routing, Pull, FP32 partial weight gradients. Device routing is enabled for all ten benchmark cases.

100 warmups followed by 3 × 100 samples per case; take the maximum across eight ranks for each iteration, then P50. Forward/backward use Event timing; full F+B uses independently measured wall time. The measured MoE includes preparation, routed/shared expert execution, communication and waits. Router logits/top-k generation, Attention, FSDP, optimizer, inter-iteration gradient clearing and the pre-timing barrier are outside the window. Independent phase maxima/P50s are not additive.

This performance-only rerun reuses the pinned native payloads and prior exact-source numerical validation. It does not repeat numerical comparisons, profiling or phase-memory sampling.

Probability placement / saving Forward ms, base → candidate Backward ms, base → candidate Full F+B wall ms, base → candidate F+B time reduction
after FC2 (default) / saved tensors 7.342 → 7.534 12.342 → 11.851 19.907 → 19.519 2.0%
after FC2 (default) / input + activation replay 7.439 → 7.457 13.634 → 12.610 21.281 → 20.260 4.8%
before FC2 / saved tensors 6.888 → 7.232 19.414 → 11.785 26.492 → 19.218 27.5%
before FC2 / input + activation replay 6.721 → 7.305 21.838 → 12.551 28.758 → 20.078 30.2%
after FC2 (default) / full MoE checkpoint 7.653 → 7.780 19.078 → 18.570 26.938 → 26.536 1.5%

With input + activation replay, candidate backward adds 0.759 ms (6.4%) after FC2, or 0.766 ms (6.5%) before FC2, relative to its own saved-tensor path. These selective cases do not separately enable shared-expert replay. Full MoE checkpoint includes the shared expert; its backward timing includes the recomputed forward and does not represent a full Transformer-layer checkpoint.

Before-FC2 forward regresses by 5.0% without replay and 8.7% with input + activation replay; its cause is not established. The gain is concentrated in backward. The 1.5% full-checkpoint and 2.0% default saved-path reductions are small observations; the run has no confidence interval or randomized case ordering. Prior matched saving-mode memory checks found peak allocated memory effectively unchanged. This change targets overlap/throughput rather than additional peak-memory savings. Single-host EP8 does not validate EP64 inter-node performance.

Full-module useful MFU uses 865 TFLOPS/card and 4.058744 TFLOP/card forward, twice that backward; replay FLOPs are excluded. Candidate F+B MFU is 73.25% before FC2 without replay, 70.11% before FC2 with input + activation replay, and 53.05% for after-FC2 full MoE checkpoint. These are module measurements, not core-kernel measurements.

Validation

  • 512 MegaMoE CPU tests passed; repository checks parsed 314 Python files and verified 17 locked patches; git diff --check passed.
  • Both pinned native payloads built and loaded in the matching CANN/PTA environment. Source and native-build identities were verified before device execution.
  • Registered device regressions passed: independent CANN selective-recompute oracle, EP2 Push/Pull selective recompute, and EP8 Token Wave with QP counts 4 and 1. Mixed Push/Pull regressions use their supported routing configuration; full-shape benchmark cases explicitly exercise device routing.
  • Independent CANN cold-expert regressions passed for both weighting modes with 193 tokens, eight cold experts, and NaN-poisoned dW outputs. Outputs and all checked gradients are bitwise equal to the standalone reference.
  • Additional EP1 CANN composition checks at target H7168/I2560 passed in both weighting modes with input + activation replay, 193 tokens, eight cold experts and NaN-poisoned dW: all 14 output/gradient comparisons are bitwise equal. These reports were independently checked; the supplementary launcher failed only in its empty-benchmark CSV aggregation after the numerical checks. Local aggregation is corrected without rerunning NPU work; its original failed status is retained.
  • All 64 rank/case correctness reports passed for output, dX, probability gradients, and routed/shared weight gradients against the same backend/placement without recompute. Raw all-rank timings and 192 phase-memory samples were checked independently; allocations return to the warmed baseline.
  • Markdownlint and Pylint for new files pass. Full touched-file static hooks are not clean: existing Pylint findings remain, with no added findings; Lizard also flags the fused replay planner and two credit/FIFO regression helpers. These checks are not presented as passing.

ModelArts job: c3798e42-09b7-47dc-9539-1c01333d4a52. Evidence: obs://s3-asset-g-ma-hlge-infra-training/r00988599/ai-trials/20261203-ep8-rebased-integration-v3/results/ep8-rebased-integration-20261203T045539Z-832f602b/node0/ (comparison CSV/JSON, all-rank timing/numerics/memory, device-test XML and native/source identities).

Target-width reports: obs://s3-asset-g-ma-hlge-infra-training/r00988599/ai-trials/20261203-ep8-rebased-integration-fullwidth-oracle-v5/results/ep8-rebased-integration-20261203T050914Z-a1cdb2c4/node0/ (full-width-p0.json, full-width-p1.json; original status records the post-test summary error).

Latest performance-only evidence: obs://s3-asset-g-ma-hlge-infra-training/r00988599/ai-trials/20261203-megamoe-ep8-fullshape-perf-2f3c1b2-v1/results/fullshape-performance-20261203T053812Z-f3977f57/node0/ (10 cases, 24,000 rank/iteration samples and 80 resolved-runtime records independently checked; source/native identities, raw global-max P50s and useful MFU verified).

@dz-ssk
dz-ssk requested a review from davidhe91 as a code owner December 3, 2026 05:14
@davidhe91
davidhe91 merged commit 1a3dcd6 into davidhe91:megamoe-ascend950-integration Dec 3, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants