Repository navigation
perf(EPv2/gfx1250): EP8 bf16 on the 96-CU partitions sends a token once a card and folds each card's rows - #1007
Merged
Merged
Conversation
…ce a card and folds the rows of each card in the push combine Two partitions share a card. For bf16 dispatch with the bf16 push combine, EP8, hidden 7168, topk 6 on gfx1250/96cu: a token with experts on both partitions of another card is sent to only one of them, picked by token parity, and the other gets a forward entry; that partition then copies the row from its sibling over the in-card link, in a second launch for calls up to 256 tokens and in 16 extra blocks of the dispatch launch above that. The LL128 dispatch sends the units past the first of such a token once to the card, and the partition they land on writes them on to its sibling (ll128Dedup). In the push combine the landing partition adds its sibling's row into its own before the row leaves the card, so each card sends back one row a token; with the fold on, the LL128 path covers up to 160 tokens a rank instead of 176. Tables: _CARD_TABLE (16 pull blocks, second launch up to 256 tokens) and the gfx1250/96cu rows of _BF16_PUSH_TABLE and _LL128_TABLE; the device keys gain the CU count when it is known. dispatch(snapshot=True) is refused on this geometry, since the fold reads the latest dispatch; MORI_EP_BF16_PUSH=0 restores the previous path.
…locks of an EP4 rank Two ranks share each card. For bf16 dispatch with the bf16 push combine, EP8, hidden 7168, topk 6 on gfx1250/96cu, each rank now takes half the blocks the gfx1250 EP4 rows give a rank at the same tokens a card: dispatch 32x16 up to 1024 tokens a rank and 64x16 above, the push combine 32 blocks, LL128 32x16, and 8 card pull blocks instead of 16. The fp8 and fp4 dispatch rows stay those of gfx1250.
The card forward holder was declared in every dispatch build. Unused, it still changed the register allocation of the plain fp8 dispatch (EP4 64x8, 64x16 and 128x16 with scales: 116 VGPRs to 115). It is now an int unless cardDedup is on, and the plain kernels again differ from main only in kernarg offsets and an assert line.
The sibling pull of the card dedup took 8 blocks a rank. With 4 the EP8 bf16 dispatch plus combine (hidden 7168, topk 6, MI450 in DPX) is unchanged up to 1024 tokens a rank and 0.5-1.7% slower at 2048 and 4096, and every rank keeps 4 more CUs for the GEMMs that run beside it.
…card-dedup # Conflicts: # python/mori/ops/dispatch_combine_v2/README.md # python/mori/ops/dispatch_combine_v2/hip_backend.py
…re the bf16 card fold is on
… again on gfx1250 On a gfx1250 op with bf16 push plans, a combine that is not on the LL128 plans and whose input already sits in combine_in_view() runs the schedule's gather combine again, at every token count: #964's first rule without its in_view_pull_max cap. A plain tensor still pushes, read where it is with no copy; weights and snapshot handles still pull; which calls go to LL128 is unchanged (low_latency, or max_num_inp_token_across_ranks at most the LL128 max_tok). All ranks of a call must pass their input the same way, from combine_in_view() or not; their token counts may differ. Where the bf16 card fold is on (EP8 on 96-CU gfx1250 partitions), an input in combine_in_view() pushes, as before. test_bf16_push_select.py expects an input in combine_in_view() to pull, or to push where the fold is on, and drops the case that passed it from combine_in_view() on alternate ranks only.
On a second MI450 node in DPX + NPS2, 4 pull blocks cost 5.4-6.6% of the EP8 bf16 dispatch plus combine (hidden 7168, topk 6) at 2048, 4096 and 8192 tokens a rank, all of it in dispatch: 527.57 / 996.51 / 1933.86 us against 500.40 / 939.83 / 1814.49 with 8 (one build, only the pull blocks changed, 4 alternating rounds). 16 blocks would take off another 9.61 / 10.62 / 20.01 us (1.1-1.9%). Calls of up to 256 tokens a rank launch no pull blocks and are unchanged; the push combine stays at 32 blocks.
…28 tokens a rank With 32x16 blocks, the LL128 dispatch and combine of EP8 bf16 (hidden 7168, topk 6) on gfx1250/96cu took 102.9 us at 128 tokens a rank, against 77.7 us for the 32-block dispatch and push combine (one build, LL128 on or off, 3 alternating rounds). The edges the row had, 176 tokens and 160 with the card fold on, were set for LL128 64x16. It now covers up to 127 tokens with the fold on or off, so ll128() loses its card_fold argument. Calls of 1 to 96 tokens a rank have not been timed against the 32-block schedule.
…4 tokens a rank With 32x16 blocks, the LL128 dispatch and combine of EP8 bf16 (hidden 7168, topk 6) on gfx1250/96cu beat the 32-block dispatch and push combine at every power of two from 1 to 32 tokens a rank (24.8 against 45.5 us at 1 token, 44.1 against 56.1 us at 32) and lost at 64 (64.5 against 62.9 us) and 128 (102.9 against 77.7 us); one build, LL128 on or off, 4 alternating rounds (3 at 128). The edge is set on powers of two, so it moves from 127 to 63 tokens.
Contributor
|
GPU CI for
Test groups (the steps that run in those jobs): epv2. Lanes follow the changed files. Adding |
…m every block all the way The push combine with the card fold (EP8 bf16 on the 96-CU partitions) changes in three places. No table, no other plan and no Python changes. - The reducing warps of a block hand its rows to the sibling device (the copy into the window and the flag) right after the block's sort. The store waves did that while they waited for a chunk, or after their last store; with the fabric busy they seldom waited, so the rows that add a sibling row were held back until the sibling's block had sent everything. - From 96 received rows a block (1024 tokens a rank in the bench), block b takes rows b, b + blocks, b + 2 * blocks, ... instead of one contiguous range, and starts at its own place in that list, so the blocks of all ranks do not send to the same rank at the same time. A row that adds its sibling's is sorted with its token group instead of after every other row; the sort table's top bit marks it. The received rows are ordered by source rank: of 32 blocks, 8 held only rows of their own card and were done after a third of the send, and the tokens of the folded rows completed in its last third. Now every block sends to other cards from start to end and tokens complete all along. - On a call with at most 8 reduce units a reducing warp (up to 292 tokens a rank here) the 7 passes of a token's reduce are units of their own, so the warps that have nothing to send share a token. Measured on one node of MI450 in DPX mode (8 devices of 96 CUs), EP8, bf16, hidden 7168, topk 6, 48 experts a rank, HIP graph, no MORI_EP_* variable, the parent commit against this one in one batch: per token count one eager CHECK run each (all pass), then 4 alternating rounds (ITERS=50); dispatch + combine = sum in us, medians: tokens a rank parent this commit change 64 31.84 + 31.04 = 62.88 31.23 + 29.93 = 61.16 -2.7% 128 40.70 + 36.82 = 77.52 40.19 + 35.63 = 75.82 -2.2% 256 55.20 + 51.89 = 107.09 54.74 + 51.41 = 106.15 -0.9% 512 78.50 + 78.09 = 156.59 78.71 + 78.03 = 156.74 +0.1% 1024 129.07 + 135.16 = 264.23 128.81 + 130.56 = 259.37 -1.8% 2048 227.72 + 245.54 = 473.26 225.98 + 235.88 = 461.86 -2.4% 4096 422.78 + 472.00 = 894.78 417.17 + 442.67 = 859.84 -3.9% 8192 815.03 + 917.80 = 1732.83 796.98 + 837.91 = 1634.89 -5.7% Every round of every count but 512 has this commit ahead; at 512 it is 0.0 to 0.6 us behind a round. Calls below 64 tokens a rank run the LL128 plans, whose instructions are the parent's. Checks: eager CHECK passes at 1, 2, 4, ..., 8192 tokens a rank (from 2048 up without the weighted pair), at 200, 292, 293, 300, 680, 700, 720, 1000, 3000 and 5000 with another seed, and at 128, 300, 1024 and 4096 with the combine input in a buffer of its own; test_ll128_split.py (97) and test_bf16_push_select.py (17) pass; test_jit_binding.py -k card (18) and test_gfx1250_strict_arch.py pass without a GPU. clang-format 20.1.8 changes no line. Compiled without a GPU, 13 combine plans without the fold (bf16 push at 8, 16 and 24 warps, fp8 and fp4 push, pull; EP4 and EP8) have the parent's instructions line for line; so have the 60 other plans this configuration compiled (LL128, dispatch, pull combine), 4 of them apart from code offsets. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…n the 96-CU partitions, 32 blocks for every dtype The card dedup and the card fold of the bf16 path now serve the fp8 and fp4 dispatches and the fp8 / fp4 push combines (e8m0 scales), and every 96-CU row runs 32 blocks, half the 64 that every unpartitioned row keeps under the capped profile. - EpCardDedupOk admits an fp4 dispatch wherever its payload takes the general loops (past four ranks, more warps a block than ranks), as fp8 and bf16 do; EpCardCombineOk admits the fp8 / fp4 push combine on 16 warps. No kernel source changes; plans without the card options compile to the same code as before. - The op turns the card layout on for quant_type fp8_blockwise / fp4_blockwise when every combine row of its schedule is 16 warps and within the fold's rows a block; the LL128 plans of a split op stay unfolded. - gfx1250/96cu rows: dispatch 32x16 for every dtype (plus the 8 pull blocks), the gather combine 32x8, the fp8 / fp4 push combine 32x16, LL128 up to 64 tokens a rank for fp8 (from 96 the schedule's plans are ahead: 62.0 against 64.0 us at 96, 65.6 against 79.1 at 128) and up to 128 for fp4. Measured on one node of MI450 in DPX mode (8 devices of 96 CUs), EP8, hidden 7168, topk 6, 48 experts a rank, HIP graph, no MORI_EP_* variable; per token count one eager CHECK run (all pass), then one graph round (ITERS=50); us: tokens a rank fp4 dispatch fp4 combine fp8 dispatch fp8 combine bf16 dispatch bf16 combine 1 11.41 10.33 11.88 10.65 13.61 11.21 2 11.75 10.35 12.24 10.65 14.92 11.54 4 12.37 10.95 13.47 11.42 16.72 11.90 8 13.51 10.71 15.52 12.56 17.74 12.62 16 15.13 11.91 17.35 12.57 20.17 14.87 32 17.13 12.43 20.64 15.35 23.88 20.20 64 20.97 17.83 28.24 21.17 31.04 29.90 128 29.83 27.02 32.56 33.07 40.25 35.47 256 34.84 37.98 45.00 49.85 54.73 51.33 512 49.09 47.12 58.44 65.86 78.42 78.18 1024 68.57 76.23 88.20 104.74 128.88 130.51 2048 115.71 127.99 146.67 177.87 230.31 232.79 4096 201.66 221.48 258.27 316.24 426.01 437.33 8192 372.31 410.06 483.70 585.66 815.54 834.57 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On MI450 in DPX mode each card shows up as two gfx1250 devices of 96 CUs. For EP8 (hidden 7168, topk 6) on such devices, with bf16, fp8 or fp4 dispatch and the bf16, fp8 or fp4 push combine, this PR moves rows between the two devices of a card over the in-card link instead of sending them across the fabric twice:
Two ranks share a card, so on these devices a rank takes half the 64 blocks every unpartitioned row keeps under the capped profile (#1003), for every dtype and token count: dispatch 32x16 plus the 8 pull blocks, push combine 32x16 (bf16 32x8 up to 128 tokens a rank), gather combine 32x8, LL128 32x16. LL128 takes bf16 calls below 64 tokens a rank, fp8 calls up to 64 and fp4 calls up to 128: dispatch + combine took 44.07 us on LL128 and 56.13 us on the schedule's plans at 32 tokens a rank with bf16, and 64.50 against 62.90 us at 64; with fp8 49.10 against 58.53 at 64, 64.01 against 62.02 at 96 and 79.07 against 65.58 at 128; with fp4 56.97 against 62.31 at 128 (3 or 4 alternating rounds).
On the other gfx1250 parts, a bf16 combine whose input is in
combine_in_view()pulls again (last section).Which devices and ops
_device_keys()adds the CU count when the first KFD GPU node reports a non-zero ASIC revision:("gfx1250/<N>cu", "gfx1250"). Onlygfx1250/96cuhas rows:_CARD_TABLE, andgfx1250/96curows in_DISPATCH_TABLE,_COMBINE_TABLE,_COMBINE_PUSH_TABLE(fp8 / fp4),_BF16_PUSH_TABLEand_LL128_TABLE. Any other CU count (256 on other MI450 cards, 128 on their DPX partitions, 192 when a card of 96-CU devices runs in SPX) has no row under its own key and takes thegfx1250rows, as on main. Revision 0 parts still get("gfx1250-strict", "gfx1250"); MI355X is unchanged.The card path is on only for an intranode op that is not async_ll, with a bf16 combine dtype, a tuned schedule (geometry not pinned by the caller), a
_CARD_TABLEentry for its shape (EP8, hidden 7168, topk 6), and eitherquant_type="none"with bf16 dispatch, a bf16 push layout andMORI_EP_BF16_PUSHnot0, orquant_type="fp8_blockwise"or"fp4_blockwise"with bf16, fp8 or fp4 dispatch, every combine row of the schedule on 16 warps, and at most 2048 rows a combine block.An fp4 dispatch with a warp a rank, or at four ranks, packs its payload and keeps the card path off.
API: on such an op
dispatch(snapshot=True)raisesValueErrorbefore it launches, and combining a snapshot handle raisesNotImplementedError: the fold reads the routing of the latest dispatch. Withquant_type="none",MORI_EP_BF16_PUSH=0turns the card path off together with the push plans.Kernel (
ep_intranode_1250x.hpp,ep_cfg.hpp,ep_spec.*,plan_api.py)EpCfggainscardDedup,cardPullBlocks,cardFwdMark,cardCombineandll128Dedup, all off by default;Renderomits defaults, so the JIT cache keys of existing plans do not change.EpArgsgainscardPullandoffFwdMap(8 more kernarg bytes for every plan). The new arena regionfwd_mapholds the forward entries and the fold's marks; it is optional, and required only whencardDeduporcardCombineis set.EpCfgIsValidallowscardDeduponly on a dispatch that is not LL128 (an fp4 one only past four ranks and with more warps a block than ranks, where its payload takes the general loops), with an even world size below 32, more than 8 warps a block and at least one warp a rank, andcardCombineonly on the bf16, fp8 or fp4 (e8m0 scales) push combine with 16 warps a block, EP8 or more, and at most 2048 rows a block.Tests
test_jit_binding.py: the card fields, their validity rules and whatdescribe()builds for them, the fp8 / fp4 fold and the fp4 dispatch included (CPU only; 23 tests with-k card).test_ll128_split.py: where the card fold is on, a schedule call withsnapshot=Truemust be refused before it launches and leave the next call's result as it was.test_bf16_push_select.py: where the card fold is on, thesnapshot=Truecall must be refused instead. An input incombine_in_view()is expected to pull, or to push where the fold is on; the case that passed it fromcombine_in_view()on alternate ranks only is dropped.Checks
0b50f4c7cagainst3bcbd9790(no kernel source changed after it on either side; the later commits here change only Python: thegfx1250/96curows and thecombine_in_view()rule):lookup,ll128,bf16_push; 4495 each) are identical under 8 faked device identities: 256 CUs, 128 CUs (a 256-CU card in DPX), 192 CUs (a card of 96-CU devices in SPX), revision 0 with 256 and with 96 CUs, gfx1250 and gfx1250-strict without KFD, MI355X. Onlygfx1250/96cuchanges.__assert_fail, and code offsets.3bcbd9790, with the combine input in a plain tensor (the later commits do not change that path). Dispatch / combine in us, medians of 3 alternating rounds (ITERS=50); the per-round differences change sign at every count:MORI_EP_*variables: eager CHECK passes at 1, 2, 4, ..., 8192 tokens a rank (14 counts; from 2048 up without the weighted pair, see Not measured), at 200, 292, 293, 300, 680, 700, 720, 1000, 3000 and 5000 with another seed, and at 128, 300, 1024 and 4096 with the combine input in a buffer of its own;test_ll128_split.py(97 passed) andtest_bf16_push_select.py(17 passed) pass.b07382dfd, fp8 / fp4 and the 32-block rows) on MI450 DPX, noMORI_EP_*variable: eager CHECK passes with bf16, fp8 and fp4 dispatch (fp8 / fp4 with the matching push combine) at 1, 2, 4, ..., 8192 tokens a rank (42 runs);test_ll128_split.py(97 passed),test_bf16_push_select.py(17 passed) andtest_jit_binding.pyon one device (135 passed) pass. Compiled in a container without a GPU, the 13 combine plans without the card options have the parent's instructions line for line; no kernel source changes in this commit.0857705b8(the fold's push combine) against its parent, compiled in a container without using a GPU: 13 combine plans without the fold (bf16 push at 8, 16 and 24 warps a block, fp8 and fp4 push, pull; EP4 and EP8) have the parent's instructions line for line, and so have the 60 other plans the DPX configuration compiles (LL128 dispatch and combine, dispatch, pull combine), 4 of them apart from code offsets. Only the bf16 push combine with the fold changes.Performance on MI450 DPX
This head, EP8 on one node, hidden 7168, topk 6, 48 experts a rank, HIP graph, no
MORI_EP_*variable; bf16 dispatch with the bf16 combine, fp8 / fp4 dispatch with the fp8 / fp4 push combine; one eager CHECK run a count (all pass), then one graph round (ITERS=50); us:The 32-block rows give up time at large calls for the CUs they leave to the GEMMs: with 64 dispatch blocks, fp4 dispatch took 91.43 / 155.98 / 277.60 us at 2048 / 4096 / 8192 tokens a rank and fp8 137.50 / 246.49 / 456.73 (one round each, same window as 32 blocks); bf16 dispatch + combine moved less than 1% from 64 to 32 dispatch blocks.
Earlier: the card path at 64 blocks
Same kernels as this PR with 64 blocks a rank and 16 pull blocks, EP8 on one node, bf16, hidden 7168, topk 6, 48 experts a rank, HIP graph, dispatch + combine in us; each column is the median of 3 alternating rounds, the two columns a day apart on the same node:
Halving the blocks (this PR's rows) was measured on the same node two days later, when the 64-block configuration took 454.89 / 856.20 / 1652.73 us at 2048 / 4096 / 8192 tokens a rank; each comparison changes one thing at these sizes, 4 alternating rounds. The push combine at 32 blocks instead of 64 adds 36.20 / 72.69 / 141.59 us (8.0-8.6%), and 8 pull blocks instead of 16 add 9.61 / 10.62 / 20.01 us (1.1-2.0%); 4 pull blocks would add another 27.17 / 56.68 / 119.37 us (5.4-6.6%). The blocks a rank gives up are left to the GEMMs that share the device.
The fold's push combine in the last commit
0857705b8changes how the push combine with the fold sends and reduces; tables, block counts and every other plan stay as they were.btakes rowsb,b + blocks,b + 2 * blocks, ... instead of one contiguous range, each block starting at its own place in that list so that the blocks of all ranks do not send to one rank at the same time, and a row that adds its sibling's is sorted with its token group instead of after every other row. The received rows are ordered by source rank, so of 32 blocks 8 held only rows of their own card and were done after a third of the send; now every block sends to other cards from start to end, and tokens complete all along instead of in the last third.Same node, parent
ffc63d254against0857705b8in one batch, noMORI_EP_*variable; one eager CHECK run a count (all pass), then 4 alternating rounds (ITERS=50); dispatch + combine = sum in us, medians:Every round of every count but 512 has the new commit ahead; at 512 it is 0.0 to 0.6 us behind a round. Calls below 64 tokens a rank run the LL128 plans, whose instructions did not change.
Not measured
_CARD_TABLEentry, so the card path stays off).Other gfx1250 parts: an input in
combine_in_view()pullsOn a gfx1250 op with bf16 push plans, a combine that is not on the LL128 plans and whose input already sits in
combine_in_view()runs the schedule's gather combine again, at every token count: #964's first rule without itsin_view_pull_maxcap; main pushes such an input. A plain tensor still pushes, read where it is with no copy; weights and snapshot handles still pull; which calls go to LL128 is unchanged (low_latency, ormax_num_inp_token_across_ranksat most the LL128max_tok). All ranks of a call must pass their input the same way, fromcombine_in_view()or not; their token counts may differ. Where the bf16 card fold is on (EP8 on the 96-CU partitions), an input incombine_in_view()pushes, as before.Combine in us with the input in
combine_in_view(), MI450 with 256 CUs, EP4 on one node, topk 6, 96 experts a rank, bf16 dispatch, HIP graph; medians of 3 alternating rounds, every round in the same direction, CHECK passes on both:fp8 dispatch moves the same way. On a second 256-CU MI450 system, the parent commit (push) against this change took 20.6-20.8 / 17.5-17.8 us at 128 tokens a rank, 60.2-60.6 / 47.9-48.4 at 1024, 172.9-173.5 / 144.1-144.6 at 4096 and 320.0-320.7 / 272.3-272.8 at 8192 (ranges of 3 alternating rounds). On nodes with an older interconnect driver the pull is ahead up to 3072 tokens a rank and behind from 4096: by 1% at 4096, 5% at 8192 and 8% at 16384. At 16384 on the system of the table one short round (5 iterations) gave 616.91 us for main and 542.75 for this change. The bench's 128-token calls do not go to LL128; a call whose
max_num_inp_token_across_ranksis at most the LL128max_tokstill does.🤖 Generated with Claude Code