Skip to content

[OPUS] [JIT] Key the MXFP8 BMM tuned lookup on cu_num - #5668

Closed
RElbers wants to merge 10 commits into
mainfrom
opus/cu_num_tune_lookup
Closed

RElbers wants to merge 10 commits into
mainfrom
opus/cu_num_tune_lookup

Conversation

@RElbers

@RElbers RElbers commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

MI350P and MI355X are both gfx950, but have 128 and 256 CUs respectively. The MXFP8 BMM tuned lookup currently keys only on (gfx, b, m, n, k), so it cannot distinguish them. This can cause a kernel tuned for 256 CU to be selected on a device with 128CU. The CK batched gemm already keys on both gfx and cu_num (aiter/ops/batched_gemm_op_a8w8.py:84), as well as opus A16W16 (aiter/ops/opus/policy.py:51). Opus MXFP8 BMM does not.

Changes

  • Key both MXFP8 BMM loaders on (gfx, cu_num, b, m, n, k).
  • Resolve cu_num inside the lookup functions, alongside gfx, without changing call sites.
  • Update opus_bmm_mxscale_tune.py to record cu_num in generated rows.
  • Backfill the 77 existing gfx950 rows with cu_num=256.
  • Preserve compatibility with CSVs that do not have a cu_num column. They continue using the old (gfx, b, m, n, k) key and print a warning message.
  • Add index_tuned_by_cu_num for merged tables containing both rows both with and without CU. The update_config_files function joins the per-model CSVs and fills a missing cu_num with 0 (aiter/jit/core.py:385). The index_tuned_by_cu_num function removes defaulted 0 cu_num from the keys.

Testing

Added tests for:

  • selecting different rows for 128- and 256-CU devices;
  • loading and resolving a legacy CSV without cu_num;
  • rejecting rows that are still duplicates under the new key; and
  • emitting cu_num from the tuner.

@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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5668 --add-label <label>

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 opt this PR out.

@RElbers
RElbers force-pushed the opus/cu_num_tune_lookup branch from 968bd15 to e366c08 Compare September 18, 2026 13:24
- Adds cu_num to the MXFP8 BMM tuned key in both loaders, so two devices that
  share an architecture but differ in CU count no longer resolve to one row.
- Falls back to the previous gfx-only key, with a warning, when a tuned CSV has
  no cu_num column, so files written before this change keep loading.
- Resolves cu_num inside lookup_mxscale_bmm_config from the running device,
  alongside the gfx it already reads, so no call site changes.
- Emits cu_num from the BMM tuner and adds it to the tuned key and sort order,
  so newly tuned files carry the column the loaders now look for.
- Records cu_num on the shipped gfx950 rows, binding them to the CU count they
  were tuned on rather than to every device of that architecture.
- Covers resolving two CU counts to different rows, the legacy fallback, and
  rejection of rows that stay duplicates under the new key.

Without cu_num the key could not express a second variant of an architecture:
its rows matched the other variant silently, and adding them tripped the
duplicate-shape check, which rejects the whole file rather than the one shape.
@RElbers
RElbers force-pushed the opus/cu_num_tune_lookup branch from e366c08 to c004f2a Compare September 18, 2026 13:59
@RElbers
RElbers marked this pull request as ready for review September 18, 2026 14:03
@RElbers
RElbers requested a review from a team September 18, 2026 14:03
@github-actions github-actions Bot changed the title Key the MXFP8 BMM tuned lookup on cu_num [OPUS] Key the MXFP8 BMM tuned lookup on cu_num Sep 18, 2026
@github-actions github-actions Bot added the OPUS label Sep 18, 2026
@RElbers RElbers added the ci:all label Sep 18, 2026
@RElbers
RElbers requested a review from valarLip September 18, 2026 14:26
…okup

# Conflicts:
#	aiter/configs/model_configs/dsv4_batched_gemm_a8w8_blockscale_mxscale_tuned.csv
#	aiter/ops/batched_gemm_op_a8w8.py
#	aiter/ops/opus/policy.py
#	csrc/opus_gemm/opus_bmm_mxscale_tune.py
#	op_tests/tuning_tests/test_config_shape_collision.py
The lookup keeps its own padded-M loop, which tries the cu_num key and then
the gfx-only key at each padding level. The helper takes a single key
function, so adopting it would let a padded-M row tuned for this CU count
win over an exact-M row that is not.
@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Oct 15, 2026
- Takes main's batched_gemm_op_a8w8.py, whose MXFP8 BMM loader and lookup now
  delegate to opus.policy, so the cu_num key lives in policy alone.
- Keeps main's per-layout table selection in the policy loader and adds cu_num
  to its key, with the gfx-only fallback for tables and rows that carry none.
- Re-applies cu_num to main's rewritten BMM tuner through its key list, which
  the preshuffled-B tuner inherits.
- Fills a missing cu_num with 0 when the tuner reads a table, so writing a table
  back leaves other devices' rows unbound instead of binding them to this one.
- Counts an unbound tuned row as tuned for every CU count of its arch, so a
  rerun over a table without cu_num skips the shapes it already holds.
- Reads w_scale_block from the last key field in the preshuffle BMM test, which
  holds for both the bound and the gfx-only key.
- Indexes bound rows on the numeric cu_num, so a non-numeric cell cannot make a
  key that the integer device CU count never matches.
- Documents cu_num in the preshuffle BMM README key and tuned header.
- Normalizes cu_num in the BMM loader before the duplicate check, so a missing
  column, a blank and a non-positive value all leave a row keyed on gfx alone.
- Replaces index_tuned_by_cu_num and the separate missing-column path with that
  one rule, which keeps the loader in main's statement order.
- Logs unbound rows at info level, since the shipped preshuffled-B table stays
  without cu_num on purpose and a warning there is not actionable.
- Logs cu_num alone in the tuned config line, as the other mxscale loaders do.
- Normalizes cu_num the same way in the BMM tuner and inserts a missing column
  after gfx as 0, so writing a table back never binds other devices' rows.
- Counts an unbound tuned row as tuned for every CU count when the tuner skips
  shapes it already holds.
- Keeps cu_num 0 rows in the base tuner run_config filter, which otherwise
  benchmarked nothing from a table without cu_num.
- Sorts and deduplicates in sortResults only on key columns the file has, so a
  run with nothing to tune no longer fails on a table without cu_num.
- Adds cu_num to the empty preshuffled-B template header, matching the README.
- Covers the lookup and the tuner in one test each, including blank and
  negative cu_num, write-back, run_config and the written column order.
- Stubs get_cu_num in the invalid kid test, which otherwise needs a GPU.
Copilot AI balanced review requested due to automatic review settings October 15, 2026 20:06
@github-actions github-actions Bot changed the title [OPUS] Key the MXFP8 BMM tuned lookup on cu_num [OPUS] [JIT] Key the MXFP8 BMM tuned lookup on cu_num Oct 15, 2026
@github-actions github-actions Bot added the JIT label Oct 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Merging multiple legacy tuner CSVs fails before the new CU defaults are applied.

1 open finding
What changed in this PR

Makes MXFP8 batched GEMM tuning distinguish GPUs with the same architecture but different compute-unit counts.

Changes:

  • Adds CU-aware lookup keys with legacy-row fallback.
  • Updates tuner handling and marks 77 existing rows as 256-CU configurations.
  • Extends compatibility tests and documents the schema.
File Description
op_tests/​tuning_tests/​test_config_shape_collision.py Updates expected lookup keys.
op_tests/​test_opus_a8w8_interface.py Tests CU selection and legacy compatibility.
op_tests/​test_batched_gemm_a8w8_mxscale_bpreshuffle.py Adjusts scale-block key access.
csrc/​opus_gemm/​opus_bmm_mxscale_tune.py Adds CU-aware tuning and normalization.
csrc/​bmm_a8w8_mxscale/​README.md Documents CU keys and legacy behavior.
aiter/​utility/​base_tuner.py Adjusts sorting and benchmark filtering.
aiter/​ops/​opus/​policy.py Implements CU-specific lookup and fallback.
aiter/​ops/​batched_gemm_op_a8w8.py Updates loader docstring.
aiter/​jit/​core.py Clarifies a comment about optional columns.
aiter/​configs/​model_configs/​dsv4_batched_gemm_a8w8_blockscale_mxscale_tuned.csv Backfills 256-CU values.
aiter/​configs/​batched_gemm_a8w8_blockscale_mxscale_bpreshuffle_tuned.csv Adds the CU header column.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread csrc/opus_gemm/opus_bmm_mxscale_tune.py Resolved
- Deduplicates merged tuner tables only on the key columns present, so loading
  several MXFP8 BMM tables without cu_num no longer raises KeyError before the
  tuner fills the column with 0.
- Applies the same rule when a _tag column is present, which used to restore
  the full key list.
- Drops the MXFP8 BMM example from the sortResults comment, since the rule
  applies to any tuner.
- Covers merging two MXFP8 BMM tables without cu_num, which must keep both
  rows unbound.
Copilot AI balanced review requested due to automatic review settings October 15, 2026 20:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Shared tuner behavior and device-specific dispatch need regression validation before human approval.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Oct 16, 2026
@RElbers

RElbers commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Closed. #6937 already keys the OPUS tuned lookups on cu_num and the tuners record it.

@RElbers RElbers closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants