Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
@coderfeli this PR fixes two tuner bugs and replaces 18 gfx1250 FlyDSL grouped-MoE rows—not CK1—with author-measured 5.9–55.6% gains; please confirm the target shapes and tuning results from the gfx1250 side. |
0b64f4d to
07ec5a1
Compare
|
@coderfeli @yadaish Rebased on main after #6269, which rewrote #6269 also changed the gfx1250 grouped GEMM kernel, so I re-timed the rows against main on gfx1250 (MI450-class, 256 CUs) with the protocol of the description:
The noise is 0.979 to 1.019 for the kernels and 0.983 to 1.006 for the whole call. Old and new rows give bit-identical outputs on every shape. One row no longer qualifies: A4W4, 7168 x 3072, 96 experts, T = 8192. With #6269 its kernels take 0.996 of the time of main's row (GEMMs 0.992), so this PR now leaves that row as main has it and replaces 17 rows: 9 A8W4 and 8 A4W4. Per row
Tiles are tile_m/tile_n/tile_k; the new rows leave the stage-2 cells blank, so stage 2 reuses the stage-1 tiles. |
|
No activity for 15 days, so this is now labelled |
tuned_grouped_fmoe.csv: keep main's rows for the 11 7168x3072 E96 keys that #6709 re-tuned, and apply this branch's values only to the 6 7168x768 E384 keys that main left unchanged (a_preshuffle stays 0).
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
@yadaish @coderfeli Please review this PR. The last reviewer comment was on Oct 12.
|
Fixes #6346.
Merged main at 0f6cb2f. Since the measurements below, #6709 changed the gfx1250 grouped MoE kernel (A-preshuffle, new scheduling defaults) and replaced the tiles of main's 7168 x 3072 (96 experts) rows without timing them again: their
usis still the old value. This PR now keeps main's 7168 x 3072 rows and replaces only the 6 rows of 7168 x 768 (384 experts): T = 2048, 4096 and 8192, A8W4 and A4W4. The 7168 x 3072 rows in the tables below are no longer part of this PR. The tuner fix is still needed: on main,_find_grouped_configis still cached on the shape only, and the tuner still runs a8w4 candidates with FP4 activations.@yadaish, could you tune the 7168 x 3072 rows again on current main with this tuner fix?
The tables below were measured before #6269; the re-timing against main with #6269 is in this comment.
Tuner
On gfx1250,
GroupedFmoeTunertimed every candidate of an A8W4 shape with the default tiles and FP4 activations, so its pick did not depend on the candidates:fused_moequantizes the activations to FP4 on gfx1250 unless the caller asks for FP8 (quant_dtype_a, orAITER_FORCE_A8W4=1). The a8w4 candidate ran as A4W4, its row (q_dtype_a = torch.float8_e4m3fn) never matched, and the default tiles ran. The tuner now passesquant_dtype_afrom the row._find_grouped_configis anlru_cachekeyed on the shape, not on the CSV path, so after the first candidate every lookup returned the first result. The tuner now clears it together with_GROUPED_CONFIG_CACHE.One shape (7168 x 768, 384 experts, top-k 6, T = 4096) with
AITER_GROUPED_DEBUG=1:q_dtype_a = torch.float4_e2m1fn_x2, no match; all 24 calls on the default tilestorch.float8_e4m3fnrowA8W4 rows
With the fixed tuner I re-tuned the A8W4 rows for 7168 x 768 (384 experts) and 7168 x 3072 (96 experts), top-k 6, T = 8 to 8192 (22 rows). Then I timed the old and the new CSV through
fused_moe(..., quant_dtype_a=fp8), withAITER_CONFIG_GROUPED_FMOEnaming the CSV, in one process on the same inputs: gfx1250 (MI450-class, 256 CUs), random routing (each token picks 6 distinct experts), median of 15 interleaved samples of the whole call. A copy of the old CSV, timed the same way, gives the noise: 0.975 to 1.009 of the old time. Old and new rows give bit-identical outputs on all 22 shapes.This PR replaces the 9 rows that are at least 3% faster (the tuner's
--min_improvement_pctdefault):The other 13 rows stay as they are. Their new / old ratio is 0.979 to 1.032, except T = 512 on 7168 x 3072, where the tuner's pick is 1.162: the tuner spreads the tokens evenly over the experts, and with random routing the current row is faster.
The new rows leave the stage-2 and TDM cells blank, as the tuner timed them, so the kernel uses its defaults (stage 2 reuses the stage-1 tiles). The exception is the columns that have no blank cell in the merged grouped configs (
split_k1,split_k2,tdm_as_in_prologue,cluster_n,waves_per_tensor_tdm,next_stage_prefetch,lds_soa_load_interleave). There the rows carry the value that a blank cell means, because one blank cell makes pandas write the whole column as floats when AITER merges the config files, and the AOT build then fails onsplit_k1 = "1.0". Theusof the new rows is the tuner's.A4W4 rows
The cache bug also hit the A4W4 rows of the same two shapes (
q_dtype_a = torch.float4_e2m1fn_x2). Most of them have the sameus, 468.05. I re-tuned these 22 rows and timed them as above, with FP4 activations (the gfx1250 default). The noise is 0.973 to 1.015. This PR replaces the 9 rows where the whole call is at least 3% faster and the GEMMs are not slower. Old and new rows give bit-identical outputs on these shapes:After #6269, the T = 8192 row on 7168 x 3072 runs as fast as main's row (kernels 0.996 of its time), so this PR no longer changes it.
The other 13 rows stay as they are. Their new / old ratio is 0.983 to 1.031, with three exceptions on 7168 x 3072. At T = 8 and 256 the tuner's pick is slower (1.092 and 1.076). At T = 512 the call is 0.960, but the GEMMs are 4% slower, so the gain does not come from the new row.
Write-back
I put the rows in place with a script rather than through
result_to_csv, which does not write them correctly into this CSV:gate_mode, whichtuned_grouped_fmoe.csvdoes not have, so it appends the new row next to the old one instead of replacing it. The lookup then takes the row with the lowerus.16becomes16.0).This PR does not change either one; #6395 fixes both.
Default config files (not changed here)
With
AITER_CONFIG_GROUPED_FMOEunset, the lookup reads the file thatupdate_config_filesmerges with pandas, and there every numeric column that has a blank cell comes out as floats. Since #6425,_as_inton main reads those cells; #6360 also makes the lookup match anep_fusedwritten as1.0and parses the cells exactly.@zufayu, could you help review this?
PR Self-Review
Reviewed revision
955281d
Behavior and intent
Two fixes to
GroupedFmoeTuneron gfx1250. It passesquant_dtype_afrom the row, so an a8w4 candidate runs with FP8 activations instead of FP4. It also clears thelru_cacheof_find_grouped_configbetween candidates, so each candidate runs with its own row instead of the first one. Without them the tuner timed every candidate on the same tiles, so its picks did not depend on the candidates. Both bugs are still on main at 0f6cb2f. With the fixed tuner, 6 rows oftuned_grouped_fmoe.csvchange: 7168 x 768, 384 experts, top-k 6, T = 2048, 4096 and 8192, A8W4 and A4W4.Validation and unverified scope
fused_moemedian of 15 interleaved samples, bit-identical outputs).us, and get main's newa_preshufflecolumn as 0, the value main has on these rows.python3 -m pytestontest_csv_validation,test_config_shape_collision,test_grouped_ep_fused_lookup,test_grouped_gemm_launch_abi,test_tuner_infraandtest_fast_tuninggave the same results as on main: 149 passed, and the same 13 cases failed because they need a GPU.PR-specific question
The tuner change runs only in
GroupedFmoeTuner._run_candidate, the gfx1250 grouped FlyDSL tuner.quant_dtype_ais FP8 only when_data_formatreturnsa8w4for the row'sq_dtype_a; otherwise it stays FP4, the previous gfx1250 default. No kernel source changes. The 6 CSV rows apply only to gfx1250 with 256 CUs, BF16, SiLU,per_1x32, 7168 x 768 with 384 experts and top-k 6, at T = 2048, 4096 and 8192._find_grouped_configmatches every key column, so other shapes keep their rows.Changed op tests
None