Skip to content

[CK] [Bugfix] Write grouped MoE tuning results back in place - #6395

Merged
yzhou103 merged 3 commits into
mainfrom
jhinpan/grouped-tuner-writeback
Oct 22, 2026
Merged

yzhou103 merged 3 commits into
mainfrom
jhinpan/grouped-tuner-writeback

Conversation

@jhinpan

@jhinpan jhinpan commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Refs #6346: these are the two write-back problems that #6356 describes and leaves alone.

GroupedFmoeTuner.result_to_csv wrote tuned_grouped_fmoe.csv back through update_tunedf and astype(str). Writing one re-tuned A8W4 row (7168 x 768, 384 experts, T = 4096) into a copy of the file on main:

  • The row was appended next to the old one, and the file got a gate_mode column (118 rows instead of 117). The tuner keys on gate_mode, which the CSV does not have. The lookup does not read gate_mode (kernelName1 names the layout) and takes the row with the lower us, so the stale row could still win.
  • Every column that has a blank cell came back as floats in the other rows (16 became 16.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 back max_m and grouped_persistent_m, which #6269 dropped from the file; they would be blank in every other row, and the AOT parser reads max_m with int(). The same write now changes one line.

The columns the tuner does not set (the stage-2 tiles, the TDM options, rolled_drain and persistent_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 value grouped_moe_gfx1250 reads a blank cell as (for example split_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's int() rejects. When such a column has no known blank value, the tuner raises before it times a candidate, and result_to_csv before 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.py adds TestGroupedFmoeResultToCsv, which fails on main and passes with this PR. Besides a synthetic file, it re-tunes a row of a copy of the real tuned_grouped_fmoe.csv and checks that only that line changes, the header stays and no filled column gets a blank cell.

@zufayu, could you help review this?

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]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6395 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot changed the title [Bugfix] Write grouped MoE tuning results back in place [CK] [Bugfix] Write grouped MoE tuning results back in place Oct 11, 2026
@github-actions github-actions Bot added the CK label Oct 11, 2026
@zufayu
zufayu requested a review from yzhou103 October 12, 2026 05:03
@zufayu

zufayu commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

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?

@yzhou103

Copy link
Copy Markdown
Contributor

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:

  • Are NOT in self.columns (the tuner doesn't set them)
  • Have NO blank cells currently (all values are 0 or 1)
  • Are NOT in _BLANK_SAME_AS or _BLANK_VALUE

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:
"rolled_drain": 0,
"persistent_workers2": 0,
Both default to 0 in the kernel code (grouped_moe_gfx1250.py:595,597).

Minor observations

  1. Test CSV header diverges from production — The test includes max_m in the header (matching self.columns), but the production CSV does not have max_m. The test exercises the logic correctly, but an additional test case with the exact production column layout would increase confidence.
  2. _csv_text doesn't handle scientific notation — "1e5" or "1.5e2" would pass through unmodified. This is unlikely to appear in the grouped MoE CSV but worth noting.
  3. no_blanks condition is fragile — Any new column added to the production CSV by a future PR (without updating _BLANK_VALUE) will silently hit the same _blank_means → "" path. A defensive approach would be to log a warning or raise when _blank_means returns "" for a column in no_blanks, since by definition that column should never have blanks.

… 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.
@jhinpan

jhinpan commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@yzhou103 Thanks, fixed in 4c6aa76, on top of a merge of main.

  • rolled_drain and persistent_workers2 are in _BLANK_VALUE as 0, the value grouped_moe_gfx1250 reads a blank cell as.
  • Merging main showed a second path to the same failure. [FlyDSL] Dev/yadai moe v1 #6269 dropped max_m and grouped_persistent_m from the file, and the write-back added every tuner column that the file lacked, so one re-tuned row brought both back, blank in the other 143 rows. A written row now takes the file's columns; only a missing key column is added (still not gate_mode).
  • Point 3: a column without blank cells and without a known blank value now raises a ValueError that names it. tune() checks the output file before it times any candidate, and result_to_csv checks again before it writes, so a long run cannot end in a corrupted file.
  • Point 1: the new cases run on a copy of the real tuned_grouped_fmoe.csv: one re-tuned row changes one line, the header stays, and no filled column gets a blank cell. The synthetic case stays for a file that still has max_m.
  • Point 2: _csv_text parses numbers exactly with Decimal, so 1e5 and 1.5e2 are written as 100000 and 150.

End to end, on a copy of the current file: I re-tuned its first row and merged it with the model config through AITER_CONFIGS.update_config_files, as AITER does. Without 4c6aa76 (the previous head merged with main), aot.parse_csv on the merged file failed with ValueError: invalid literal for int() with base 10: '64.0' (max_m), and rolled_drain and persistent_workers2 came back as 0.0 and 1.0 in 179 rows. With 4c6aa76 it parses all 356 jobs, and the merged file has no blank or float cell in those columns. The 5 new test cases fail without 4c6aa76; test_tuner_infra.py passes (28 tests).

@yzhou103
yzhou103 merged commit 75647da into main Oct 22, 2026
@yzhou103
yzhou103 deleted the jhinpan/grouped-tuner-writeback branch October 22, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants