Repository navigation
[CK] [Bugfix] Write grouped MoE tuning results back in place - #6395
Conversation
GroupedFmoeTuner.result_to_csv went through update_tunedf and a pandas round trip, which broke tuned_grouped_fmoe.csv in two ways: - The tuner keys on gate_mode, which the CSV does not have, so a re-tuned row was appended next to the old one, with a new gate_mode column, instead of replacing it. The lookup ignores gate_mode and takes the row with the lower us, so the stale row could still win. - pandas reads a column that has a blank cell as floats, so the other rows came back with "16.0" for 16. Read the file as text, match rows on the key columns the file has, replace a re-tuned row in place, and keep the other rows byte for byte. In a column without blank cells, a re-tuned row gets the value a blank cell means rather than a blank, so the config merge does not turn that column into floats. Signed-off-by: Jin Pan <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
The fix correctly prevents duplicate rows and unintended gate_mode insertion when retuning the current clean config; @yzhou103 could you please confirm the tuning flow before approval? |
|
Thanks,please have look this problem _BLANK_VALUE is incomplete — rolled_drain and persistent_workers2 will get blank cells Severity: medium — same class of bug this PR fixes The production CSV tuned_grouped_fmoe.csv has two columns (rolled_drain, persistent_workers2) that:
These columns will land in the no_blanks set, so _blank_means() is called for them on re-tuned rows. But since neither mapping covers them, _blank_means() returns "" — introducing a blank cell into a previously all-filled column. This defeats the purpose of the no_blanks logic: the next pandas read of that column will coerce the entire column to floats. Fix: Add to _BLANK_VALUE: Minor observations
|
… write-back - rolled_drain and persistent_workers2 get the value grouped_moe_gfx1250 reads a blank cell as (0), like the other columns the tuner does not set. - A written row takes the file's columns; only a missing key is added. Re-tuning a row of tuned_grouped_fmoe.csv no longer adds max_m and grouped_persistent_m, which #6269 dropped, blank in every other row. - A column without blank cells and without a known blank value stops the tuner before it times a candidate, and result_to_csv before it writes. - _csv_text writes an integral number in any notation as the integer.
|
@yzhou103 Thanks, fixed in 4c6aa76, on top of a merge of main.
End to end, on a copy of the current file: I re-tuned its first row and merged it with the model config through |
Refs #6346: these are the two write-back problems that #6356 describes and leaves alone.
GroupedFmoeTuner.result_to_csvwrotetuned_grouped_fmoe.csvback throughupdate_tunedfandastype(str). Writing one re-tuned A8W4 row (7168 x 768, 384 experts, T = 4096) into a copy of the file on main:gate_modecolumn (118 rows instead of 117). The tuner keys ongate_mode, which the CSV does not have. The lookup does not readgate_mode(kernelName1names the layout) and takes the row with the lowerus, so the stale row could still win.16became16.0).The tuner now reads the file as text, matches rows on the key columns the file has, replaces a re-tuned row in place, and appends new shapes. The rows it does not tune keep their text. A written row takes the file's columns: only a missing key column is added, and not
gate_mode, which the lookup does not read. So re-tuning a row does not bring backmax_mandgrouped_persistent_m, which #6269 dropped from the file; they would be blank in every other row, and the AOT parser readsmax_mwithint(). The same write now changes one line.The columns the tuner does not set (the stage-2 tiles, the TDM options,
rolled_drainandpersistent_workers2) mean what a blank cell means, because the tuner timed the candidate with them blank. Where the file already has blank cells in such a column, the re-tuned row leaves it blank. Where it has none, the row gets the valuegrouped_moe_gfx1250reads a blank cell as (for examplesplit_k1 = 1,tile_m2 = tile_m,rolled_drain = 0). One blank cell would make the AITER config merge read the whole column as floats, which the AOT parser'sint()rejects. When such a column has no known blank value, the tuner raises before it times a candidate, andresult_to_csvbefore it writes, so a column added later cannot get a blank cell unnoticed.Numbers with an integral value are written as integers, whatever their notation (
16.0,1e5).op_tests/tuning_tests/test_tuner_infra.pyaddsTestGroupedFmoeResultToCsv, which fails on main and passes with this PR. Besides a synthetic file, it re-tunes a row of a copy of the realtuned_grouped_fmoe.csvand checks that only that line changes, the header stays and no filled column gets a blank cell.@zufayu, could you help review this?