Repository navigation
Conversation
…plan kernel The compact plan used to be one kernel that tallied local routes, pushed the histogram to every peer, spun on the peer done counter, and then derived the compact rows. While spinning it kept its 32 waves and LDS occupied, which hurts when the plan overlaps the previous expert GEMM on a side stream. Split it into three back-to-back kernels on the same stream: - tdm_compact_plan_arrive: tally routes, push histogram to peers, bump each peer's done counter. Never waits on a peer. - tdm_compact_plan_sync: one wave, the only cross-rank wait. - tdm_compact_plan_finish: read the allgathered histograms, write masked_m / psum / send_base and rewrite tok_map. LDS does not survive a kernel boundary, so the packed per-route word goes through tok_map and finish re-reads the histograms from the arena. The split kernels are single-block (PLAN_BLOCKS == 1); the dead multi-block paths are removed and guarded with a ValueError. The compile/launch signature is unchanged.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
Motivation
The gfx1250 MegaMoE compact plan (
tdm_compact_plan) was a single kernel that tallied local routes, pushed its histogram to every peer, spun on the peerdonecounter, and only then derived the compact rows. While waiting on a peer it kept all of its waves and LDS resident. The plan runs on a side stream and overlaps the previous layer's expert GEMM, so a spinning, LDS-heavy kernel is a poor neighbour, and the peer wait is charged to the plan's own time.What changed
compile_tdm_compact_plannow launches three back-to-back kernels on the same stream (the compile/launch signature is unchanged, somega_moe.pycall sites are untouched):tdm_compact_plan_arrivedonecounter. Never waits on a peer.tdm_compact_plan_synctdm_compact_plan_finishmasked_m/psum/send_base, rewritetok_mapto the final compact rows.Implementation notes:
segment | intra << 16) is staged throughtok_map(the formermerge_routesLDS shortcut is gone) andfinishre-reads the histograms from the arena. The protocol (gen counter,hist_pingpong, slot-specificoff_hist/off_done, dense/sparse/TDM/fallback hist layouts) is otherwise unchanged.PLAN_BLOCKS == 1, which is already the value). The deadplan_blocks > 1grid-barrier paths are removed andcompile_tdm_compact_planraisesValueErrorifPLAN_BLOCKS != 1.block_histis still accepted but unused.compact_plan.pyandMegaMoEGfx1250.prefetch_compact_planupdated.Testing
Run on gfx1250, 2 ranks (the other GPUs were fully occupied by an unrelated serving job, so no 4-rank / end-to-end run):
masked_m,psum,send_baseand every route's destination row (including invalid expert ids) against a pure-python reference. Covered dense-TDM, dense buffer_store fallback, sparse histogram, double-slot alternation andhist_pingpong=True, 4 iterations each with varying token counts. All PASS.npes=2,epr=96,topk=6, 128 tok/rank, median of 30):tdm_compact_plan23.0 usCaveats / what I did not verify
tok_mapwrite/read round trip). The intended benefit is that the wait no longer holds the plan's waves/LDS and is no longer counted as plan time; I have not measured the effect under a real GEMM overlap.torch.cuda._sleep) is noisy, so the "waiting rank" numbers only show that the wait moved intosync, not exact values.bench_mega_moe.py ... --stage1_fused 1 --combine fusedon 4 ranks,mainvs this branch, once the GPUs are free.