Skip to content

[FlyDSL] [gfx1250] gate_up GEMM with a fused SwiGLU + MXFP8 quant epilogue (on #7668) - #8057

Open
yhl-amd wants to merge 15 commits into
ROCm:mainfrom
yhl-amd:hyi/gfx1250-shared-gate-up-silu-mxfp8
Open

yhl-amd wants to merge 15 commits into
ROCm:mainfrom
yhl-amd:hyi/gfx1250-shared-gate-up-silu-mxfp8

Conversation

@yhl-amd

@yhl-amd yhl-amd commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

A shared expert whose down projection reads MXFP8 runs three launches after the input quant: the gate_up GEMM (bf16 [M, 2*I]), silu_and_mul (bf16 [M, I]) and quantize_fp8 (e4m3 [M, I] + e8m0 [M, I/32]), with two round trips of the activation through HBM. On gfx1250 the batched mxfp8_32 FlyDSL GEMM already has a fused group-32 MXFP8 epilogue (#7667); this PR lets the same kernel apply the SwiGLU activation before that quant, so the three launches become one.

Stacked on #7668 (which is on #7667); only the last two commits are new here. Please merge #7667, then #7668; this PR will be rebased onto main after that.

Technical Details

launch_gemm_a8w8 (aiter/ops/flydsl/kernels/gemm_a8w8_gfx1250.py) gains fuse_act_mul / act_limit constexprs (batched mxfp8_32 with a 32x32 B scale, fuse_quant_out, no K tail, 64-column multiples per tile and per wave):

  • No weight reorder. B is the unmodified [gate; up] weight. Each CTA gathers its tile_n B rows as tile_n/64 blocks of [32 gate rows, the matching 32 up rows] through one nested TDM view, and the 32x32 scale rows the same way, so each wave's 64-column block holds gate and up of the same 32 outputs in the same lanes.
  • Epilogue. The accumulators are rounded to bf16 (as the bf16 GEMM output would be), bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)) is formed like aiter silu_and_mul (L = 0 skips the clamp, as silu_and_mul does; the gate is clamped with fmin_f32 and rounded back to bf16 and the up value with fclamp_f32 (v_med3), as silu_and_mul does, so the clamp matches it for every L; the clamp is taken where L as f32 is positive), and each 32-column group is quantized to e4m3 + e8m0 (amax floored at 1e-10, ceil pow2 of amax/448). The per-group quant to LDS and the scale-row store are [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667's emit_mxfp8_acc_pair_to_lds / emit_mxfp8_scale_rows_store (kernels/quant_utils.py); only the e4m3 TDM store is a local helper, shared with the accumulator-quant epilogue. Against the unfused chain an e4m3 code can differ by one step; where the differing value is its group's amax at 448·2^k, the group's e8m0 scale moves by one instead (and so all 32 codes).
  • act_limit must be finite and >= 0; the kernel name gets a _silu<exact limit>q suffix (symbol-safe), so it never collides with the plain GEMM.

aiter/ops/flydsl/batched_gemm_a8w8_gfx1250.py adds:

  • gate_up_silu_supported(n2, k): whether this device and a [n2, k] gate_up weight have fused tiles (gfx1250 with the measured CU count, the measured DSV4.1 shared-expert [2I, K]). Independent of the row count, so a model decides once when it is built.
  • run_gate_up_silu_mxfp8_32_gfx1250(XQ, WQ, x_scale, w_scale, Out, y_scale_out, swiglu_limit, kernel_name=None): the raw launch. XQ [M, K] e4m3, row-contiguous, with row-major x_scale [M, K/32]; WQ [2I, K] contiguous, 16x16-preshuffled, with its raw [2I/32, K/32] 32x32 scale; writes Out [M, I] e4m3 and y_scale_out [M, I/32] e8m0 (uint8 storage also accepted). The dtypes, strides and shapes of XQ, WQ, Out and y_scale_out, the devices and 16-byte base alignment of all operands, the limit and the kernel name are validated before the arch check; the e8m0 x_scale / w_scale dtype and shape after it (_check_e8m0, which loads FlyDSL). swiglu_limit is read as the f32 silu_and_mul receives: a finite positive f32 clamps; 0, -0.0, f32 inf and +inf clamp nothing; a negative or NaN f32 raises ValueError. kernel_name=None picks the tile from the runtime row count; past GATE_UP_SILU_MAX_ROWS that is the largest bucket's tile (not measured there).
  • gate_up_silu_kernel_for(m, n2, k): the table tile for 1 <= m <= GATE_UP_SILU_MAX_ROWS where gate_up_silu_supported, else None. A host helper for code that sees the real row count (eager code, the body of a custom op); not for branching in a traced forward.
  • gate_up_silu_kernel_ok(name) (only the table's kernelNames, the ones the gfx1250 op test runs; the structural check runs once on the table at import), gate_up_silu_limit(limit), GATE_UP_SILU_MAX_ROWS. Each table tile pins its K loop with _pl.

aiter/ops/batched_gemm_op_a8w8.py adds the functional registered op gate_up_silu_mxfp8_32(XQ, WQ, x_scale, w_scale, swiglu_limit) -> (act, act_scale): picks the tile inside from the runtime row count, allocates and returns e4m3 / e8m0 outputs, mutates nothing. A compiled graph replayed for other row counts without guard checks still runs each call's tile. A caller that keeps its own unfused chain above GATE_UP_SILU_MAX_ROWS makes that split inside its own op, where the row count is real (ATOM#3446 does).

No new environment variables; existing kernels and their names are unchanged.

Test Plan

  • op_tests/test_flydsl_gate_up_silu_host.py (new, CPU): gate_up_silu_supported and the picker buckets / rejections (unmeasured shapes, other arch or CU count, undeterminable device), _pl pins, gate_up_silu_kernel_ok, limit semantics (including f32-zero limits), a CPU model of the clamp step that documents why the gate is rounded to bf16 (its bf16-rounded model performs the same operations as its silu_and_mul model, so their agreement holds by construction; it does not test the kernel), launch validation (dtypes, strides, shapes, buffers, kernel name, arch), the runtime tile pick of the launch (kernel launch stubbed), and the functional op in one fullgraph dynamic-shape graph across row counts, each call launching its own row count's tile.
  • op_tests/test_flydsl_batched_gemm.py (gfx1250) test_gate_up_silu_fused: for every tile bucket (M = 1, 7, 384, 500, 640, 768, 960, 1152, 1345, 2048, 4096) at 2I = 4608, K = 5120, with swiglu_limit 10, 0 and 5.02 (a limit bf16 cannot hold), the fused launch vs the bf16 GEMM on the same tile + aiter.silu_and_mul + the torch mirror of ATOM quantize_fp8 (scales exact, e4m3 codes at most one step apart, and per case at most max(2, 1/10000 of its codes) of them), and the registered op byte-equal to the launch. The M = 1 case keeps its one row as data. Fails if, on the measured part, the picker misses a bucket. gfx1250-strict runs it too.
  • Full op_tests/test_flydsl_batched_gemm.py, op_tests/test_gemm_host_dispatch_cache.py and the fused-quant tuned-row tests for regressions of the existing batched / fused-quant / pipelined paths.

Test Result

  • At 7d78cf69e (this head; the stack rebased onto main 3fd42598c): CPU host + dispatch-cache tests 86 passed; the 10 failures are CUDA-only cases that fail the same way on main. black / ruff clean. No idle gfx950 GPU for a rerun. The results below are at 4ebcaa840, whose own commits are replayed here unchanged.
  • Offline gfx1250 compile at 4ebcaa840 (flydsl 0.5.0, null pointers, no GPU), final ISA: the seven SwiGLU configs (the five table tiles at limit 10, t64x128 at limit 0, t128x256 at limit 5.02) match the previous head 4136bc792 opcode for opcode; the only difference is two scalar registers that hold constants swapping numbers (limit 0: byte-identical). Same VGPR counts (312 to 551), no VGPR / SGPR spill, no scratch. Nine plain / fused-quant / _pl configs are byte-identical to [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668's head e9476df89.
  • gfx950 at 4ebcaa840: python op_tests/test_flydsl_batched_gemm.py exits 0 and prints the same correctness columns as [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668's head on the same box (the gfx1250 kernel is not reached there).
  • CPU at 4ebcaa840 (GPU-less container): python -m pytest op_tests/test_flydsl_gate_up_silu_host.py op_tests/test_gemm_host_dispatch_cache.py 84 passed, 16 skipped; the one failure is the pre-existing test_mxscale_config_precheck_matches_padded_walk, which needs CUDA and fails the same way at 4136bc792.
  • gfx1250 run at this head: pending (to be posted before merge). The last gfx1250 run was at 3d4ffbac7: op_tests/test_flydsl_batched_gemm.py exit 0, gate_up SwiGLU 33 cases with 0 scale and 0 far mismatches.

PR Self-Review

Reviewed revision

7d78cf6

Behavior and intent

Validation and unverified scope

  • Offline gfx1250 compile at this head: SwiGLU ISA matches 4136bc792 opcode for opcode (two scalar constant registers swap numbers), no spill or scratch; plain / fused-quant / _pl ISA byte-identical to [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668's head.
  • gfx950 at this head: op_tests/test_flydsl_batched_gemm.py exits 0, same correctness columns as [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668's head.
  • CPU at this head (no GPU visible): the host test and the dispatch-cache test pass, except the pre-existing CUDA-only case named above.
  • gfx1250 at 3d4ffbac7 (same epilogue instructions as this head, per the ISA comparison above): python op_tests/test_flydsl_batched_gemm.py exits 0 (one GPU). Fused quant and pipelined checks ALL BIT-EXACT; gate_up SwiGLU 33 cases with 0 scale and 0 far mismatches at limits 10, 0 and 5.02; registered op byte-equal to the launch; picker right for every bucket.
  • black 26.10.1 and ruff clean on the changed files.
  • Unverified: the gfx1250 op test at this exact head (pending, to be posted before merge), and an end-to-end serving run through it (an earlier head ran end to end through perf(dsv4): run the shared expert's SwiGLU and MXFP8 quant in the gate_up GEMM epilogue on gfx1250 ATOM#3446, see the PR comments). CI has no gfx1250 runner for these FlyDSL op tests.

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

Changed op tests

  • op_tests/test_bmm_a8w8_fused_quant_tuned_row.py: comes from [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667 (CPU test of the fused entry's tuned-row lookup); unchanged here.
  • op_tests/test_gemm_host_dispatch_cache.py: comes from [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668 (CPU checks that only _pl selects the pipelined loop); unchanged here.
  • op_tests/test_flydsl_batched_gemm.py (gfx1250): test_gate_up_silu_fused compares the fused launch with the bf16 GEMM on the same tile + aiter.silu_and_mul + the torch mirror of ATOM quantize_fp8, for every tile bucket, with limits 10, 0 and 5.02, rows past the clamp, tiny rows and a zero row (M = 1 keeps its one row as data), checks the registered op byte-equal to the launch, and fails if the picker misses a bucket on the measured part. Not redundant: it is the only numerical test of the new epilogue and of the gate/up gather.
  • op_tests/test_flydsl_gate_up_silu_host.py (new, CPU): shape / device gating, _pl pins, limit and operand validation, a numerical model of the clamp step, the runtime tile pick and the functional op under a fullgraph dynamic-shape compile. Before the follow-up commits it fails (no limit or operand checks, no runtime pick, no functional op). Not redundant: CI's standard shards run no gfx1250 kernel, so this is the only CI coverage of the host side.

🤖 Generated with Claude Code

@yhl-amd
yhl-amd requested a review from a team November 16, 2026 18:18
@yhl-amd yhl-amd added the FlyDSL label Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
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 8057 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aiter-bot

aiter-bot commented Nov 16, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 7d78cf69e737 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

- Branch: #7667 (`d4016d527`, on main `3fd42598c`) and #7668 (`1683901ce`) as they are now, plus two commits. `95d0ca59a` is the previous seven commits squashed while rebasing (the epilogue conflicted with #7667's shared quant helpers); its message is the corrected squash text and describes this head (functional op with `mutates_args=[]`; the gate clamp rounded to bf16; the picker returns a tile only for the measured device and shape; the scale can move by one at 448·2^k; `gate_up_silu_kernel_for` is not for branching in a traced forward; the e8m0 scale checks run after the arch check). `7d78cf69e` limits `gate_up_silu_kernel_ok` to the table's names and fixes the clamp formula in the kernel header comment. Previous heads kept as `bak/8057-pre1123a` / `-pre1123b` / `-pre1125a` / `-pre1127a` on the fork. `95d0ca59a` / `7d78cf69e` are `8e8af1776` / `4ebcaa840` replayed unchanged.
- Before: a shared expert with an MXFP8 down projection needs the gate_up GEMM, `silu_and_mul` and `quantize_fp8`: three launches and two activation round trips through HBM.
- After: on gfx1250, where `gate_up_silu_supported` holds, the launch or the functional registered op runs them as one GEMM; the tile follows the runtime row count, so it stays right in a graph compiled once and replayed for every row count. `swiglu_limit` follows `silu_and_mul`. Existing kernels and their names do not change: `fuse_act_mul` defaults to off, and the plain fused-quant kernels compile to the same ISA as #7668's head.

Validation and unverified scope

- Offline gfx1250 compile at this head: SwiGLU ISA matches `4136bc792` opcode for opcode (two scalar constant registers swap numbers), no spill or scratch; plain / fused-quant / `_pl` ISA byte-identical to #7668's head.
- gfx950 at this head: `op_tests/test_flydsl_batched_gemm.py` exits 0, same correctness columns as #7668's head.
- CPU at this head (no GPU visible): the host test and the dispatch-cache test pass, except the pre-existing CUDA-only case named above.
- gfx1250 at `3d4ffbac7` (same epilogue instructions as this head, per the ISA comparison above): `python op_tests/test_flydsl_batched_gemm.py` exits 0 (one GPU). Fused quant and pipelined checks ALL BIT-EXACT; gate_up SwiGLU 33 cases with 0 scale and 0 far mismatches at limits 10, 0 and 5.02; registered op byte-equal to the launch; picker right for every bucket.
- black 26.10.1 and ruff clean on the changed files.
- Unverified: the gfx1250 op test at this exact head (pending, to be posted before merge), and an end-to-end serving run through it (an earlier head ran end to end through ROCm/ATOM#3446, see the PR comments). CI has no gfx1250 runner for these FlyDSL op tests.

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

- This PR's own commits change no configuration file. The fused tiles live in the table in `batched_gemm_a8w8_gfx1250.py`, keyed by M bucket, and apply only to gfx1250 with the measured CU count at gate_up `[2I, K]` = `[4608, 5120]`; only the new launch and op read them. The configuration change in this branch comes from #7668: `dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv` rows `gfx1250, cu_num 256, 32x32, (M, N, K)` = `(576, 32768, 1280)` and `(768, 32768, 1280)`; see #7668.
- Unrelated shapes: existing entries never set `fuse_act_mul`, and the kernel name of every existing configuration is unchanged, so their selection and compiled kernels are the same as before; the plain fused-quant kernels compile to the same gfx1250 ISA as #7668's head.

Changed op tests

- `op_tests/test_bmm_a8w8_fused_quant_tuned_row.py`: comes from #7667 (CPU test of the fused entry's tuned-row lookup); unchanged here.
- `op_tests/test_gemm_host_dispatch_cache.py`: comes from #7668 (CPU checks that only `_pl` selects the pipelined loop); unchanged here.
- `op_tests/test_flydsl_batched_gemm.py` (gfx1250): `test_gate_up_silu_fused` compares the fused launch with the bf16 GEMM on the same tile + `aiter.silu_and_mul` + the torch mirror of ATOM `quantize_fp8`, for every tile bucket, with limits 10, 0 and 5.02, rows past the clamp, tiny rows and a zero row (M = 1 keeps its one row as data), checks the registered op byte-equal to the launch, and fails if the picker misses a bucket on the measured part. Not redundant: it is the only numerical test of the new epilogue and of the gate/up gather.
- `op_tests/test_flydsl_gate_up_silu_host.py` (new, CPU): shape / device gating, `_pl` pins, limit and operand validation, a numerical model of the clamp step, the runtime tile pick and the functional op under a fullgraph dynamic-shape compile. Before the follow-up commits it fails (no limit or operand checks, no runtime pick, no functional op). Not redundant: CI's standard shards run no gfx1250 kernel, so this is the only CI coverage of the host side.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@yhl-amd

yhl-amd commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the current #7668 head 96c03e69a (which is on #7667); new head 8810af9cd, still one commit of its own. Merge order: #7667, #7668, then this PR. The previous head is kept on the fork as bak/8057-pre1117u.

Rebase conflict. #7667 now has a _group_scale(amax) helper (amax floor, e8m0 ceil scale, its f32 value) for its two quant epilogues, defined inside the plain-GEMM quant block. This PR's SwiGLU epilogue had its own copy of the same steps. In the resolution, the helper and the shared quant imports move into one if const_expr(fuse_quant_out) block ahead of the epilogues. The plain-GEMM block keeps fuse_quant_out and not fuse_act_mul for its own s8 / GN / scale-row setup, and the SwiGLU epilogue now calls _group_scale too. The emitted operations are the same as before.

gfx1250 run at b7ba5296f (same code as this head; the head differs only in #7668's CSV-value commit underneath): python op_tests/test_flydsl_batched_gemm.py rc = 0:

gate_up silu M=1    ... t64x128x256  nb4: scale mismatch 0/72,     e4m3 mismatch 0/2304    (off by more than one code: 0)
gate_up silu M=384  ... t64x128x256  nb4: scale mismatch 0/27648,  e4m3 mismatch 1/884736  (off by more than one code: 0)
gate_up silu M=1345 ... t128x256x256 nb3: scale mismatch 0/96840,  e4m3 mismatch 3/3098880 (off by more than one code: 0)
gate_up silu M=4096 ... t128x256x256 nb3: scale mismatch 0/294912, e4m3 mismatch 11/9437184 (off by more than one code: 0)
gate_up silu fused epilogue OK
fused quant epilogue ALL BIT-EXACT
pipelined K loop ALL BIT-EXACT

All 11 buckets have 0 scale mismatches and at most a one-code e4m3 difference, as before the rebase. python -m pytest op_tests/test_gemm_host_dispatch_cache.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py op_tests/test_bmm_a8w8_fused_quant_supported.py: 41 passed.

Description is updated with the PR Self-Review section (Reviewed revision 8810af9cd).

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-shared-gate-up-silu-mxfp8 branch 2 times, most recently from 0f8a0db to d3c9932 Compare November 17, 2026 18:50
@yhl-amd

yhl-amd commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto #7668's new head 292a532f8 (a name without a K-loop suffix gets default_pipelined_k_loop()'s pick again, and _nopl pins the single-fence loop). No conflicts; this PR's own commit is unchanged (d3c99322a).

The tiles in _GATE_UP_SILU_TILES carry no suffix, so they now get the default pick, the same K loop as under the earlier automatic rule; the output bits are the same with either loop.

gfx1250 at d3c99322a: python op_tests/test_flydsl_batched_gemm.py exits 0 (gate_up SiLU fused epilogue OK in every bucket, pipelined K loop and fused quant epilogue all bit-exact), and the three CPU pytest files pass. The previous head is kept on the fork as bak/8057-pre1118.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (6)

  1. Reject swiglu_limit <= 0 and non-finite limits in run_gate_up_silu_mxfp8_32_gfx1250, or give 0 the no-clamp meaning. In aiter silu_and_mul, 0 means "no clamp" and a negative limit is rejected (activation_kernels.cu:1450-1453). The fused _act always clamps, so limit=0 returns all zeros, a negative limit returns garbage, and inf raises OverflowError in int(act_limit * 1000) (kernels/gemm_a8w8_gfx1250.py:316). Probe: probe/probe_limit0.py. ATOM #3446 only avoids this because it checks swiglu_limit > 0 itself. That is a copy of an aiter rule on the consumer side. Also fix the "bit-matching ... silu_and_mul" docstring (batched_gemm_a8w8_gfx1250.py:795-797) and the "all ... bit-matching" kernel comment. Your own test allows one-code e4m3 differences.
  2. Make the picker safe to call from a traced forward. ATOM calls gate_up_silu_kernel_for inside torch.compile. Dynamo ignores lru_cache and traces into parse_bmm_mx32_kernel_name. With symbolic M and fullgraph=True, it fails at re.Match.groupdict (probe/probe_picker.py). Precompute the bucket table as plain ints at import (no regex at call time). Also add a torch_compile_guard op with a fake for the launch in aiter/ops/batched_gemm_op_a8w8.py, declaring Out and y_scale_out as mutated, so callers do not launch raw FlyDSL from a traced region.
  3. Pin the K loop in _GATE_UP_SILU_TILES instead of inheriting #7668's default pick. All 8 tiles currently resolve to pipelined=1 only through default_pipelined_k_loop(). #7668 has changes requested to remove that rule. Write _pl (or _nopl) explicitly on each tile, matching the loop you timed.
  4. Return None from gate_up_silu_kernel_for for shapes that were never measured, or move the table into a tuned CSV. The comment says the buckets were measured only at 2I=4608, K=5120. The function still returns a tile for any divisible shape, e.g. (512, 3072, 7168). It also ignores cu_num. Other mxscale bmm entries read (gfx, cu_num, M, N, K) rows from aiter/configs.
  5. Add CPU tests, and make the gfx1250 test unable to pass vacuously. No CI job runs test_gate_up_silu_fused: the standard shards are MI35X/gfx950, and the FFM label only runs triton_tests. Add CPU cases next to op_tests/test_gemm_host_dispatch_cache.py for the picker buckets and rejections, gate_up_silu_kernel_ok, and the limit and shape validation. In _run_gate_up_silu, fail if no bucket returned a kernel.
  6. Land #7667, then #7668, then rebase. Both are open with changes requested. Only d3c99322a belongs to this PR.

Optional: parenthesise far in the test ((... != 0) | (... > 1)). It works today only because | binds tighter than >. Use round() (or repr) for the _silu suffix. Use get_gfx_runtime() for the dispatch gate (aiter/ops/flydsl/AGENTS.md:40). Share the scale-row store and the e4m3 TDM store with the existing accumulator-quant epilogue.

The gather strides, [g,g,u,u] lane mapping, amax shuffle, LDS sizes and OOB guards all check out. The default path is unchanged: everything is behind const_expr(fuse_act_mul), and existing names are unchanged. CI: MI35X shard 4 died in the middle of test_gemm_a8w8_blockscale.py, which this PR does not touch, and the Test Gate fails because of that shard.


Reviewed at d3c9932 (own commit only; stacked on #7668 @ 292a532 / #7667 @ 6807132).

@yhl-amd

yhl-amd commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All six points and the optional items are addressed in a484d81c0 (on top of d3c99322a; the #7667 / #7668 commits underneath are unchanged; previous head kept as bak/8057-pre1118e on the fork).

  1. swiglu_limit semantics. Aligned with silu_and_mul: a positive limit clamps, 0 means no clamp (the kernel skips the clamp via const_expr), and a negative or NaN limit raises ValueError (gate_up_silu_limit). +inf clamps nothing in silu_and_mul (fminf / fmed3 with inf), so it runs the same no-clamp kernel instead of overflowing. launch_gemm_a8w8 also rejects a negative or non-finite act_limit itself. The kernel name now carries the exact limit (repr, . spelled p) instead of int(limit * 1000). The docstring and the kernel comment no longer claim bit-matching: scales match exactly, e4m3 codes up to one step. The gfx1250 op test now runs every bucket with limits 10 and 0. With this, the consumer side (ATOM revert back the copilot extra operation in pr 3338 ci: remove compression-level: 0 from aiter wheel upload-artifact step #3446) no longer needs its own copy of the rule.
  2. Traced callers. gate_up_silu_kernel_for no longer has lru_cache or any regex at call time: _GATE_UP_SILU_TILES holds final kernel names, checked once at import; the shape check is plain == compares; the device check is an assume_constant_result helper. Added the registered op aiter.ops.batched_gemm_op_a8w8.gate_up_silu_mxfp8_32 (same arguments, Out / y_scale_out in mutates_args, returns nothing, no-op fake). A new CPU test compiles the picker + op with fullgraph=True, dynamic=True (aot_eager, launch stubbed) and checks the writes reach the caller's tensors; your probe shape (symbolic M, fullgraph) fails on the old picker and traces on the new one. The ATOM caller (revert back the copilot extra operation in pr 3338 ci: remove compression-level: 0 from aiter wheel upload-artifact step #3446) should call the registered op from its traced forward.
  3. K loop pinned. Every tile in the table (and GATE_UP_SILU_DEFAULT_KERNEL) ends in _pl, the loop each tile resolved to (and was timed with) under the default pick; the CPU test asserts the suffix and pipelined == 1.
  4. Unmeasured shapes. The picker now returns None unless the device is gfx1250 with the CU count the tiles were measured on and (n2, k) is the measured DSV4.1 shared-expert gate_up shape (_GATE_UP_SILU_SHAPES). (512, 3072, 7168) and other divisible shapes return None; CPU tests cover this plus other arch / CU count / no GPU. I kept the table in code rather than a tuned CSV since it has a single consumer and one shape; happy to move it into aiter/configs if you prefer.
  5. Tests. New op_tests/test_flydsl_gate_up_silu_host.py (CPU, arch-independent, runs in the standard shards): picker buckets and rejections, device gate, _pl pins, gate_up_silu_kernel_ok rejections, limit semantics, launch validation of limit / shapes / buffers / kernel name / arch (the launch now validates everything before the arch check), the registered op, and the traced test above. In _run_gate_up_silu the cases always use the table's tiles and the test fails if, on the measured part, the picker does not return the table tile for every bucket.
  6. Order. Understood: [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667, then [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668, then I rebase this onto main. Only d3c99322a and a484d81c0 belong to this PR.

Optional items: far is now two named boolean masks combined explicitly; the kernel-name suffix uses repr (exact); the dispatch and arch gates use get_gfx_runtime(); the accumulator-quant epilogue and the SwiGLU epilogue now share the group quant-to-LDS step (_quant_group_to_lds) and the scale-row + e4m3 TDM store (_store_quant_tile). The compiled-handle key also includes the device now.

Validation: CPU (no GPU visible) python op_tests/test_flydsl_gate_up_silu_host.py passes, and op_tests/test_gemm_host_dispatch_cache.py matches the previous head (only the GPU-needing case fails without a GPU); black 26.10.1 and ruff clean. gfx950 at this head: python op_tests/test_flydsl_batched_gemm.py exits 0 and pytest op_tests/test_flydsl_gate_up_silu_host.py op_tests/test_gemm_host_dispatch_cache.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py op_tests/test_bmm_a8w8_fused_quant_supported.py passes (the gfx1250 kernel is not reached there). gfx1250 validation pending. Description and Self-Review updated.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (3)

  1. Move the per-M tile choice inside the registered op, and stop calling gate_up_silu_kernel_for "safe in a traced forward". The picker picks the bucket with Python compares on m (aiter/ops/flydsl/batched_gemm_a8w8_gfx1250.py:809-827). That is only correct while Dynamo re-checks guards. ATOM compiles the forward once at --level 3 (the default) and then reruns the first compiled code for every M without checking guards (atom/utils/decorators.py:546-589).

    • ATOM's warmup first M is max_num_batched_tokens (16384 > 4096). The picker returns None there, so the fused path is never taken.
    • With DP8 the first M is 2048, so the t192x128 tile runs for every M, including M > 4096.
    • Both cases were reproduced on CPU with ATOM's bytecode-hook and code-swap mechanism. Numerics stay correct; the feature is dead or mis-tiled.
    • Fix: let gate_up_silu_mxfp8_32 / run_* pick the tile from the runtime XQ.shape[0] when kernel_name is None, and give callers a query that does not depend on M (arch, CU count, (n2, k)). The M > 4096 split then has to be decided inside the op as well.
    • Also, kernel_name or GATE_UP_SILU_DEFAULT_KERNEL (:886) silently runs the default tile when it gets the picker's None. The op docstring (batched_gemm_op_a8w8.py) tells callers to pass exactly that value.
    • This came from my earlier ask #2; sorry for steering it there.
  2. Validate XQ/WQ like the sibling runner does. run_gate_up_silu_mxfp8_32_gfx1250 (:869-905) hard-codes lda = k and passes raw data_ptrs, but never checks:

    • XQ/WQ element size or dtype;
    • XQ.stride() == (k, 1);
    • WQ.is_contiguous();
    • Out dtype (it checks only element_size()).

    A bf16 XQ, a row-strided fp8 XQ view or a non-contiguous WQ launches and silently writes wrong activations (CPU probe). Reuse the checks in _check_bmm_operands (:399-459).

  3. Land #7667, then #7668, then rebase. Both are still open with changes requested. Only d3c99322a and a484d81c0 belong to this PR.

Also before merge: run op_tests/test_flydsl_batched_gemm.py on gfx1250 at this head. The refactor of the existing accumulator fused-quant epilogue (_quant_group_to_lds / _store_quant_tile) reads op-for-op identical to the base, but it has not run on its only arch, and no CI runner covers it.

Nits:

  • _act clamps the gate in f32. silu_and_mul rounds fminf(g, L) back to bf16 (activation_kernels.cu:80-83), so limits that bf16 cannot represent exactly (7.3, 1e-3) differ on clamped elements, while the docstring/comment blames only exp/rcp. Either round the clamped gate to bf16 or fix the text. L = 10 and L = 0 are unaffected.
  • The _silu{repr}q suffix gets a + for limits ≥ 1e16 (1e+16), and format_kernel_name maps only -. llvm-mc rejects that symbol. Map + too.
  • _gate_up_silu_device_measured catches only RuntimeError, so KeyError (unknown arch), AssertionError (mixed CU counts) and ValueError (bad CU_NUM) escape the picker instead of returning None.

Already fixed: limit semantics (0 = no clamp; negative/NaN rejected; inf allowed), _pl pins, None for unmeasured shapes and CU counts, CPU host test (collected by the standard shards), gfx1250 test can no longer pass vacuously, far, repr suffix, get_gfx_runtime, shared quant helpers. CI: the MI35X shards fail in "Run the container" after about 1.5 min (infra, not this PR). No gfx1250 runner.


Reviewed at a484d81 (Deep; full A–C on own commits d3c9932 + a484d81, stacked on unmerged #7668 @ 292a532 / #7667 @ 6807132; 6 hunters, 2 verifiers + C2). Already fixed: r40 asks 1, 3, 4, 5 and all optional items; ask 2 fixed as asked but see 1.

@yhl-amd

yhl-amd commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. All three points and the nits are addressed in 7aa707829 (on top of a484d81c0; #7667 / #7668 untouched; previous head kept as bak/8057-pre1118g on the fork).

  1. Per-M choice inside the op.
    • run_gate_up_silu_mxfp8_32_gfx1250 with kernel_name=None now picks the tile from XQ.shape[0] at launch time; GATE_UP_SILU_DEFAULT_KERNEL is gone, so a None can no longer silently mean "the default tile".
    • The registered op is now functional: gate_up_silu_mxfp8_32(XQ, WQ, x_scale, w_scale, swiglu_limit) -> (act, act_scale), no kernel name, mutates_args=[], allocates and returns e4m3 / e8m0, and picks the tile inside from the runtime row count. A new CPU test compiles it once (fullgraph, dynamic) and replays it for M = 5000, 7, 1345, 2048: one graph, and each call launches its own row count's tile (kernel launch stubbed below _run_compiled).
    • New gate_up_silu_supported(n2, k): the M-independent query (arch, CU count, (n2, k)) for deciding once at model build time.
    • The docstring no longer claims gate_up_silu_kernel_for is safe in a traced forward; it is now documented as a host helper for code that sees the real row count (eager code or a custom-op body), with the replay-without-guards reason.
    • M > 4096: the op runs any M; past GATE_UP_SILU_MAX_ROWS it uses the largest bucket's tile, which computes the same values but was not measured to beat the unfused chain. I did not put an unfused fallback inside the AITER op because the unfused chain the fused kernel was measured against is the caller's (ATOM's tuned gate_up GEMM plus ATOM's own quantize_fp8 kernel); an AITER-side copy would produce different bytes from the path it replaces. ATOM#3446 now makes that split inside its own functional op, from the real row count (see the update there). If you would rather have the AITER op fall back itself above the table, tell me which unfused chain it should use and I will add it.
  2. Operand validation. The launch now checks, before the arch check: XQ / WQ 2-D, e4m3 (or uint8 storage); XQ.stride() == (K, 1); WQ.is_contiguous(); Out e4m3 (or uint8) and y_scale_out e8m0 (or uint8), plus the existing shape / contiguity checks. CPU tests cover a bf16 XQ, a row-strided XQ view, a transposed WQ, a 3-D XQ, and int8 / bf16 Out. I wrote the checks inline rather than calling _check_bmm_operands, which is built around the 3-D [M, B, N] output and checks the arch first.
  3. Order. Understood: [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667, then [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668, then I rebase this onto main. Only d3c99322a, a484d81c0 and 7aa707829 belong to this PR.

On running op_tests/test_flydsl_batched_gemm.py on gfx1250 at this head: gfx1250 validation pending. The op test now also checks the registered op byte-equal to the explicit-tile launch.

Nits:

  • Gate clamp rounding: I fixed the text rather than the kernel. The comment and the docstring now say the gate is clamped in f32 where silu_and_mul rounds the clamped gate to bf16, which gives the same value whenever bf16 holds L (10 and 0 included). The kernel is unchanged, because I cannot re-run it on gfx1250 right now.
  • + in the suffix: now dropped (1e+16 -> 1e16). - was already mapped by format_kernel_name.
  • Device check: now also returns False on KeyError, AssertionError and ValueError; a CPU test covers each.

Other validation: CPU host test passes (black 26.10.1, ruff clean). On gfx950, op_tests/test_flydsl_batched_gemm.py exits 0 and the host / fused-quant tests pass (the kernel is not reached there). The description and Self-Review are updated.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (3)

  1. Round the clamped gate to bf16 in _act, or stop promising "the same scales". aiter/ops/flydsl/kernels/gemm_a8w8_gfx1250.py:1440-1441 clamps the gate in f32 (minnumf(g, L)). silu_and_mul rounds fminf(g, L) to bf16 (csrc/kernels/activation_kernels.cu:78-83). This was my r42 nit; the new text names the f32 clamp but still says "the same scales and the same e4m3 codes up to one step" (batched_gemm_a8w8_gfx1250.py:880, and op_tests/test_flydsl_batched_gemm.py:636: "e8m0 scales must match exactly").
    • That is false for limits bf16 cannot hold. Example: L = 7.49 (bf16 7.5) with a saturated element. The kernel gives 56.0 and the reference gives 56.25, so e8m0 is 124 vs 125. The group's scale halves and all 32 e4m3 codes move by a binade. L = 5.02 and 5.14 flip it the other way. About 0.2% of non-bf16 L in [0.5, 64] hit this (CPU probes, two verifiers).
    • L = 10 and L = 0 are unaffected, which is all the tests use.
    • Fix: g = fx.Float32(fx.minnumf(g, lim)).to(out_cls).to(fx.Float32). That is one cvt and gives bit-equal clamp semantics for every L. Then add a non-bf16 limit (e.g. 5.02) to GATE_UP_SILU_LIMITS.
  2. Make the M=1 case of test_gate_up_silu_fused carry data, then run op_tests/test_flydsl_batched_gemm.py on gfx1250 at this head. At m = 1, x[: max(m//8,1)] *= 8, x[m//4 : …] *= 1e-3 and x[m - 1] = 0 all hit row 0 (op_tests/test_flydsl_batched_gemm.py:651-653). The only 1-row (decode) check is therefore all zeros against all zeros, including the op-vs-launch compare. No other M leaves a 1-row last tile. Guard the zero row with if m > 1. The description still says "gfx1250 validation pending". That run is also the only check of the refactored accumulator fused-quant epilogue (_quant_group_to_lds / _store_quant_tile), which is an existing gfx1250 path.
  3. Land #7667, then #7668, then rebase. Both are still open with changes requested. Only d3c99322a, a484d81c0 and 7aa707829 belong to this PR.

Nits:

  • gate_up_silu_limit checks the Python double. A limit in (0, ~7e-46) is accepted, and the kernel takes the clamp branch with an f32 bound of 0, so every activation is 0. silu_and_mul gets 0.0f and does not clamp. Compare np.float32(limit) > 0 instead (batched_gemm_a8w8_gfx1250.py:848-859).
  • test_flydsl_batched_gemm.py main() never runs _run_gate_up_silu on gfx1250-strict: it returns early in the epilogue_only branch (:801, :866-873). _GFX1250_ARCHS still serves that arch.
  • "Above the last bound the 2-D compute GEMM … was faster" (:737-740) and "past MAX_ROWS … computes the same values" (op and launch docstrings) have no measurement or GPU run past M = 4096. Say "not measured" instead.

Pre-existing: the launch, like _check_bmm_operands, never checks that all operands are on XQ's device or that base pointers are 16-byte aligned for TDM (a4w4_mxscale_bpreshuffle_gemm_gfx1250.py does). ATOM #3446 is not exposed.

Already fixed (r42): ask 1 (the tile is picked from runtime rows inside the launch and op, :823-846 / :931; gate_up_silu_supported; functional op batched_gemm_op_a8w8.py:532-578; default kernel removed), ask 2 (operand checks, :897-930), the + in the symbol (kernels/…:325), device-check exceptions (:809). CI: shard 5 fails in test_flydsl_allreduce_rank_agreement.py, which this PR does not touch, and the Test Gate fails on that shard. The new host test passes in shard 6.


Reviewed at 7aa7078 (Deep; full A–C on own commits d3c9932..7aa7078, stacked on #7668 @ 292a532 / #7667 @ 6807132; 4 hunters + 4 verifiers + C2). Already fixed: r42 asks 1, 2, nits 2 and 3; nit 1 only half (text).

@yhl-amd

yhl-amd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Addressed in 3ecba659b (on top of 7aa707829; #7667 / #7668 untouched; previous head kept as bak/8057-pre1118h on the fork).

  1. Clamped gate rounded to bf16. _act now does g = fx.Float32(fx.minnumf(g, lim)).to(out_cls).to(fx.Float32), which is your line. The up clamp stays in f32, as in silu_and_mul. GATE_UP_SILU_LIMITS is now (10.0, 0.0, 5.02). The docstring and the op-test text now describe the scales and codes the way the op test checks them.
    • Without a gfx1250 I checked the clamp semantics with a CPU numerical model, test_clamped_gate_rounding_matches_silu_and_mul in the host test. For L = 7.49, 5.02 and 5.14 it takes a gate past the limit and every bf16 up value in (0, L], one element per group, and compares three things:
      • a model of silu_and_mul (the gate clamped in f32 and cast to bf16, the up through fmed3);
      • the old epilogue clamp (f32 gate);
      • the new one (bf16-rounded gate).
    • The f32 clamp gives a different e8m0 than the reference at each of the three limits, which reproduces your example (L = 7.49: 56.0 vs 56.25, e8m0 124 vs 125). The bf16-rounded clamp matches the reference in values and in e8m0 everywhere. For bf16-representable limits (10, 7.5, 0.5) the two clamps are identical.
    • This is a model of the clamp step, with the SiLU written identically on both sides. The kernel-side run on gfx1250 is pending.
  2. M = 1 carries data. The zero row is now guarded with if m > 1. The tiny-row scaling is guarded too (m >= 4), since m // 4 is row 0 below that. At M = 1 the single row is the clamped one. On running op_tests/test_flydsl_batched_gemm.py on gfx1250 at this head: per the current instruction I am not using gfx1250 machines for now; the run is pending. It will also be the first check of the refactored accumulator fused-quant epilogue on its arch.
  3. Order. Understood: [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667, then [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668, then rebase. Only d3c99322a, a484d81c0, 7aa707829 and 3ecba659b belong to this PR.

Nits:

  • f32 limit: gate_up_silu_limit now treats a limit whose np.float32 value is not > 0 as no clamp (1e-46 and 5e-324 map to 0.0; CPU tests). The kernel builder takes the clamp branch only when np.float32(act_limit) > 0 (act_clamp).
  • gfx1250-strict: main() now runs _run_gate_up_silu in the epilogue_only branch as well.
  • "not measured": the table comment, the launch docstring and the op docstring now say past GATE_UP_SILU_MAX_ROWS the largest bucket's tile is not measured. "Same values" and "was faster" are gone.
  • Pre-existing device / alignment checks: added to this PR's launch, since it was small: all operands on XQ.device, base pointers 16-byte aligned. Both have CPU tests. _check_bmm_operands, which the other batched runners share, is unchanged here; I will do that in a separate PR so this one does not touch the existing runners.

Validation:

  • CPU host test passes (58 cases); black 26.10.1 and ruff clean.
  • gfx950 at this head: op_tests/test_flydsl_batched_gemm.py exits 0 and the host / dispatch-cache / fused-quant tests pass (the kernel is not reached there).
  • gfx1250: pending.

Description and Self-Review are updated.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (2)

  1. Run op_tests/test_flydsl_batched_gemm.py on gfx1250 at this head (r44 ask 2, second half). The kernel change in _act (aiter/ops/flydsl/kernels/gemm_a8w8_gfx1250.py:1445-1447) and the shared-helper refactor of the existing accumulator fused-quant epilogue (_quant_group_to_lds / _store_quant_tile, since a484d81c0) have not run on their only arch. No CI runner covers them. The host-test clamp model cannot stand in for this run: _epilogue_model(round_gate=True) performs the same ops as _silu_and_mul_ref, so new == ref holds by construction. The 5.02 limit you added does catch the old f32 clamp, but only through the e4m3 code-mismatch budget: a CPU model of the test data gives about 39% one-step codes and 0 scale flips. So the run must show 0 scale and 0 far mismatches at 5.02 as well.
  2. Land #7667, then #7668, then rebase. Both are still open with changes requested (#7667 @ 6807132, #7668 @ 292a532). Only d3c99322a, a484d81c0, 7aa707829 and 3ecba659b belong to this PR.

Nits:

  • gate_up_silu_limit (batched_gemm_a8w8_gfx1250.py:855-863) still tests the sign on the double, and it recognises f32 inf only when the double is itself inf.
    • -1e-46 is -0.0f to silu_and_mul, which runs it as no clamp, but here it raises ValueError.
    • 1e39 is inf as f32, but it is returned as is. It warns "overflow encountered in cast" on every call, here and again at kernels/…:143, and builds a separate _silu1e39q clamp kernel. The values still match silu_and_mul.
    • Fix: take f = np.float32(limit) under np.errstate(over="ignore"), then raise if not f >= 0 and return 0.0 if not (np.isfinite(f) and f > 0).
  • The PR body says operand "dtypes … shapes … are validated before the arch check". x_scale / w_scale dtype and shape are checked only by _check_e8m0 (:955-956), which runs after get_gfx_runtime() (:950-952). Reword the sentence, or check the scales before the arch check.
  • op_tests/test_flydsl_batched_gemm.py:23-30 still says gfx1250-strict runs the fused-quant check "and the compute kernelName cases alone". It now also runs _run_gate_up_silu (:877-878), and the gate_up check is not mentioned at all.

Pre-existing: _check_bmm_operands and the other batched runners still have no device or 16-byte base checks. You said you will handle that in a separate PR.

Already fixed (r44): the clamped gate is rounded to bf16 (kernels/…:1446), and the gate is now taken where f32 L > 0 (:143). 5.02 is in GATE_UP_SILU_LIMITS. M=1 keeps its row as data (test_flydsl_batched_gemm.py:653-657). The f32-zero limit is handled. gfx1250-strict now runs the gate_up check. The "not measured" wording is in. Device and alignment checks are in this launch.

CI: Black, Ruff and the build pass. Standard Tests (MI35X) are still pending. There is no gfx1250 runner.


Reviewed at 3ecba65 (Deep; full A–C on own commits d3c9932..3ecba65 on #7668 @ 292a532 / #7667 @ 6807132; 4 hunters, 2 verifiers, C2). Already fixed: r44 ask 1, the M=1 half of ask 2, nits 1-3, and the device / alignment checks.

@yhl-amd

yhl-amd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Nits addressed in bed4bc437 (on top of 3ecba659b; #7667 / #7668 untouched; previous head kept as bak/8057-pre1119b on the fork).

  1. gfx1250 run: gfx1250 machines are off-limits for now; will run before merge. That run has to show 0 scale and 0 far mismatches at 5.02 as well as at 10 and 0. You are right about the host test: _epilogue_model(round_gate=True) does the same operations as _silu_and_mul_ref, so new == ref holds by construction. It only documents why the gate is rounded (the f32-clamp side does reproduce your 7.49 case: 56.0 vs 56.25, e8m0 124 vs 125); it does not stand in for the GPU run. The test docstring, the module header and the PR description now say so. Until that run, the bf16-rounded clamp in _act and the shared-helper refactor of the accumulator fused-quant epilogue are unverified on their arch.
  2. Order: unchanged. [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667 -> [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668 -> rebase. Only d3c99322a, a484d81c0, 7aa707829, 3ecba659b and bed4bc437 belong to this PR.

Nits:

  • gate_up_silu_limit: now takes f = np.float32(limit) under np.errstate(over="ignore"), raises if not f >= 0, and returns 0.0 if not (np.isfinite(f) and f > 0). The kernel builder reads the limit the same way: under errstate it requires a finite f32 >= 0 and clamps only when it is > 0. New cases: -1e-46 -> 0.0, 1e39 -> 0.0, both checked with warnings raised as errors. 5e-324 / 1e-46 and the rejections are unchanged. The host test also runs clean under -W error::RuntimeWarning.
  • "validated before the arch check": reworded rather than moved. _check_e8m0 comes with the FlyDSL import, which only happens after the arch check. The description now says: XQ / WQ / Out / y_scale_out dtypes, strides and shapes, all operands' devices and 16-byte alignment, the limit and the kernel name are checked before the arch check; the x_scale / w_scale e8m0 dtype and shape are checked after it.
  • Op-test header: now says gfx1250-strict runs the fused-quant check, the gate_up check and the compute cases. It also describes the gate_up check: the launch and the registered op vs bf16 GEMM + silu_and_mul + quantize_fp8, scales exact, isolated one-step codes, every bucket, limits 10 / 0 / 5.02.

Pre-existing: _check_bmm_operands and the other batched runners will get the device / 16-byte checks in a separate PR, as said.

Validation:

  • CPU host test passes (60 cases); black 26.10.1 and ruff clean.
  • gfx950 was not re-run for this head: the change is host-side limit handling and test text, which the CPU test covers, and the gfx950 GPUs were busy.
  • gfx1250: pending as above.

Description and Self-Review are updated.

@yhl-amd

yhl-amd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

gfx1250 run at bed4bc437: PASS.

python op_tests/test_flydsl_batched_gemm.py on gfx1250 (one GPU; aiter at this head, JIT modules rebuilt from it; FlyDSL 0.5.0): exit code 0, no failed check.

  • test_gate_up_silu_fused: all 33 cases (M = 1, 7, 384, 500, 640, 768, 960, 1152, 1345, 2048, 4096 at 2I = 4608, K = 5120, each with limit 10, 0 and 5.02) report scale mismatch 0 and 0 e4m3 codes more than one step off. That holds at 5.02 as well as at 10 and 0. Isolated one-step codes: 0 at M = 1 and 7, otherwise 1 to 11 per case (largest: 11 of 9,437,184 at M = 4096), the same count for all three limits. The registered-op byte-equality and the per-bucket picker checks pass (gate_up silu fused epilogue OK (33 cases)).
  • Accumulator fused-quant epilogue after the shared-helper refactor (first run on its arch): fused quant epilogue ALL BIT-EXACT. Scale and fp8 mismatch are 0 for every heuristic and explicit tile, including _pl / _nopl.
  • Pipelined K loop: ALL BIT-EXACT. Existing batched compute cases: 96 checkAllclose passed, none failed.

End to end through ROCm/ATOM#3446 at 9e92620ad (V4.1-Flash, DEP4, default compilation level, DSpark): the fused _silu10p0q kernels run, both in the CUDA graphs and eagerly, and GSM8K is 0.9196. Details are in that PR.

The full log is kept.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (4)

  1. Run op_tests/test_flydsl_batched_gemm.py on gfx1250 at the final head and post the output (r44/r46 ask, still open). No gfx1250 run has been posted yet. The PR body says "gfx1250: validation pending at this head". Two things have never run on their only arch: the bf16-rounded gate clamp in _act (aiter/ops/flydsl/kernels/gemm_a8w8_gfx1250.py:1447) and the shared-helper refactor of the accumulator fused-quant epilogue. The run must show 0 scale mismatches and 0 far mismatches at all three limits (10, 0 and 5.02), with the per-case one-step counts from item 3.
  2. Land #7667, then #7668, then rebase (still open). Both PRs are OPEN with changes requested, and their heads are unchanged (#7667 @ 6807132, #7668 @ 292a532).
  3. Apply the one-step e4m3 allowance per case, not pooled. At op_tests/test_flydsl_batched_gemm.py:737-742, code_bad * 10000 > total sums over all 33 (M, limit) cases, which is about 82M codes, so up to about 8,225 one-step codes are allowed in total. The three M=1 cases have 6,912 codes, so every M=1 code could be one step off and the test would still pass. That contradicts the docstring (:31-34, "in a negligible fraction, for every tile bucket") and the "M = 1 keeps its row as data" claim. Fix: fail when any case has r[1] > max(2, m * (n2 // 2) // 10000). The test is seeded and the expected rate is about 1e-7, so this cannot make it flaky.
  4. Use the existing clamp helpers in _act. At kernels/gemm_a8w8_gfx1250.py:1447-1448 the clamp is written by hand: fx.minnumf(g, lim) and fx.maxnumf(fx.minnumf(u, lim), nlim). The repo already has fmin_f32 / fclamp_f32 in kernels/gemm_common_gfx1250.py:161/166, and the existing gfx1250 SwiGLU clamp uses them (fused_silu_swiglu_elem, :186-187).
    • Use u = fclamp_f32(u, nlim, lim) and g = fx.Float32(fmin_f32(g, lim)).to(out_cls).to(fx.Float32), and add the two names to the existing import at :18.
    • This uses v_med3 as silu_and_mul does (activation_kernels.cu:83), so it matches the "fmed3 clamp" the comment at :1441 names, including for a NaN up value (+L today vs -L in silu_and_mul).
    • Output is identical for non-NaN inputs.

Already fixed (r46 nits):

  • gate_up_silu_limit now reads the limit as the f32 silu_and_mul receives (batched_gemm_a8w8_gfx1250.py:848-863). -1e-46 and 1e39 both give 0.0 without a warning, and every limit class agrees with silu_and_mul and with the builder (kernels/…:135-144).
  • The PR body's validation-order wording now matches the code.
  • The op-test header (:23-34) now names the gate_up check and says gfx1250-strict runs it.

Pre-existing, not required for this PR: _check_bmm_operands still has no device or 16-byte base checks (you said a separate PR will handle this).

CI at bed4bc4: only the pull_request_target workflows have run (PR Self-Review and the title check pass). Checks / Aiter Test have not run at this head. At 3ecba65, the Standard Tests (MI35X) failures were in test_flydsl_hgemm.py (graph replay mismatch) and in test_flydsl_allreduce_rank_agreement.py (CustomAllreduce has no _is_gfx1250). This PR does not touch those files.


Reviewed at bed4bc4 (Deep; full A–C on own commits d3c9932..bed4bc4 on #7668 @ 292a532, plus D; 3 hunters, 3 verifiers, C2). Items 3-4 are in code from earlier commits that earlier rounds missed. Already fixed: r46 nits 1-3.

@yhl-amd

yhl-amd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

gfx1250 run at 3d4ffbac7 (this head): PASS.

python op_tests/test_flydsl_batched_gemm.py on gfx1250 (one GPU, FlyDSL 0.5.0, aiter at this head): exit code 0.

  • Fused quant epilogue (accumulator and LDS-staged, after the shared-helper refactor): ALL BIT-EXACT.
  • Pipelined K loop: ALL BIT-EXACT.
  • Existing batched compute cases: all checkAllclose checks pass, none fail.
  • test_gate_up_silu_fused: gate_up silu fused epilogue OK (33 cases). Every case has 0 scale mismatches and 0 codes more than one step off, and its one-step count is within the new per-case budget max(2, M * I // 10000). The registered op is byte-equal to the launch, and the picker returns the table tile for every bucket.

Per case (2I = 4608, K = 5120):

M limit scale mismatch one-step e4m3 codes codes budget more than one step
1 10.0 0 0 2304 2 0
1 0.0 0 0 2304 2 0
1 5.02 0 0 2304 2 0
7 10.0 0 0 16128 2 0
7 0.0 0 0 16128 2 0
7 5.02 0 0 16128 2 0
384 10.0 0 1 884736 88 0
384 0.0 0 1 884736 88 0
384 5.02 0 1 884736 88 0
500 10.0 0 2 1152000 115 0
500 0.0 0 2 1152000 115 0
500 5.02 0 2 1152000 115 0
640 10.0 0 4 1474560 147 0
640 0.0 0 4 1474560 147 0
640 5.02 0 4 1474560 147 0
768 10.0 0 4 1769472 176 0
768 0.0 0 4 1769472 176 0
768 5.02 0 4 1769472 176 0
960 10.0 0 3 2211840 221 0
960 0.0 0 3 2211840 221 0
960 5.02 0 3 2211840 221 0
1152 10.0 0 3 2654208 265 0
1152 0.0 0 3 2654208 265 0
1152 5.02 0 3 2654208 265 0
1345 10.0 0 3 3098880 309 0
1345 0.0 0 3 3098880 309 0
1345 5.02 0 3 3098880 309 0
2048 10.0 0 3 4718592 471 0
2048 0.0 0 3 4718592 471 0
2048 5.02 0 3 4718592 471 0
4096 10.0 0 11 9437184 943 0
4096 0.0 0 11 9437184 943 0
4096 5.02 0 11 9437184 943 0

The one-step counts are the same for all three limits. They are consistent with the earlier run at bed4bc437 (issuecomment-7004850798: 0 at M = 1 and 7, at most 11 at M = 4096), as expected: the fmin_f32 / fclamp_f32 change in _act is the same for non-NaN inputs.

@yhl-amd

yhl-amd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Addressed in 3d4ffbac7 (on top of bed4bc437; #7667 / #7668 untouched; previous head kept as bak/8057-pre1119c on the fork).

  1. gfx1250 run. One had been posted 3 minutes before this review, at bed4bc437 (issuecomment-7004850798): 33 cases, 0 scale and 0 far mismatches, 5.02 included. Items 3 and 4 change code, so I ran it again at the final head 3d4ffbac7. It passes; the per-case one-step counts are in the comment above. Fused quant (after the shared-helper refactor) and pipelined checks are ALL BIT-EXACT. All 33 gate_up cases have 0 scale mismatches and 0 far mismatches at 10, 0 and 5.02, and every case is within its per-case budget.
  2. Order / CONFLICTING: the conflict is in the stacked base, not in this PR's commits. Main's [FlyDSL] [gfx1250] Compute GEMM: fused MXFP8 epilogue; untuned prefill-sized batched mxfp8_32 runs the compute kernel #7673 (merged) touches op_tests/test_flydsl_batched_gemm.py, which conflicts with [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667's commit, and aiter/ops/flydsl/batched_gemm_a8w8_gfx1250.py, which conflicts with [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668's. So, as planned: [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667, then [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668, then I rebase this PR onto main. Only d3c99322a, a484d81c0, 7aa707829, 3ecba659b, bed4bc437 and 3d4ffbac7 belong to this PR.
  3. Per-case allowance: _run_gate_up_silu now fails when any case has r[1] > max(2, m * (n2 // 2) // 10000), and it names the case. The pooled code_bad * 10000 > total is gone. The op-test header says per case.
  4. Clamp helpers: _act now uses g = fx.Float32(fmin_f32(g, lim)).to(out_cls).to(fx.Float32) and u = fclamp_f32(u, nlim, lim). Both names are added to the gemm_common_gfx1250 import. The gfx1250 counts are consistent with the previous head, as expected for non-NaN inputs.

The description and Self-Review are updated (gfx1250 result at this head). black 26.10.1 and ruff are clean on the changed files.

@yhl-amd

yhl-amd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

gfx950 at 3d4ffbac7 (the kernel is not reached there): python op_tests/test_flydsl_batched_gemm.py exits 0, and pytest op_tests/test_flydsl_gate_up_silu_host.py op_tests/test_gemm_host_dispatch_cache.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py op_tests/test_bmm_a8w8_fused_quant_supported.py passes (103).

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (4)

  1. Land #7667, then #7668, then rebase this PR onto main (still open). #7667 was rebased onto main e8baf0696 at 305f898e7b; #7668 (292a532f84) and this PR still sit on the old #7667 head 68071323b6, and all three are CONFLICTING. Post a fresh gfx1250 run of op_tests/test_flydsl_batched_gemm.py after the rebase.
  2. Limit gate_up_silu_kernel_ok to the tile shapes the GPU test runs. aiter/ops/flydsl/batched_gemm_a8w8_gfx1250.py:760. Every _GATE_UP_SILU_TILES entry has tile_n // n_warp == 64, so the epilogue loop at kernels/gemm_a8w8_gfx1250.py:~1455 only runs blk == 0 on gfx1250, yet the predicate and the public kernel_name= accept 108 untested names (e.g. t64x256 nw2, and tile_n=192 tiles whose vec<3 x i8> scale store at 1-byte offsets has never run). Fix: cfg["tile_n"] in (128, 256) and cfg["tile_n"] // cfg["n_warp"] == 64 (== 64 alone still accepts t64x192 nw3), and add a 128-cols/wave and a tile_n=192 name to test_kernel_ok_rejects. Checked: all 8 table tiles pass, all existing reject names stay rejected.
  3. Count e4m3 NaN codes as "far" in the one-step metric. op_tests/test_flydsl_batched_gemm.py:708-709: |(a&0x7F)-(r&0x7F)| == 1 accepts 0x7F (NaN) vs 0x7E (448) and 0xFF vs 0xFE as an allowed one-step code. Mark a mismatching pair far when (a & 0x7F) == 0x7F or (r & 0x7F) == 0x7F; replayed over all 256×256 pairs, only those 4 NaN pairs change.
  4. Fix the text that no longer matches the code.
    • The run_gate_up_silu_mxfp8_32_gfx1250 docstring (batched_gemm_a8w8_gfx1250.py:884-889) and kernel comment (kernels/gemm_a8w8_gfx1250.py:1320-1324) name only a one-step e4m3 code; when the differing activation is its group's amax at 448·2^k, the e8m0 scale moves by one instead (448 vs 450 → 127 vs 128) and all 32 codes change. Say so.
    • This repo squash-merges with COMMIT_MESSAGES, so reword/squash during the rebase: a484d81c0 ("declared mutated, no-op fake"; head is functional, mutates_args=[], batched_gemm_op_a8w8.py:532-569), 7aa707829 (gate "clamped in f32"; head rounds to bf16, kernels/…:1449), d3c99322a (tile "at shapes the tiles divide"; head returns one only for the measured device/shape, :813-845).
    • PR description: drop "kernel side is the pending gfx1250 run", "(gfx1250 check pending)" and "this head changes only host-side…" (3d4ffbac7 also changes _act).

Checked and correct at this head: _act now matches silu_and_mul (all bf16 patterns × 13 limits, 0 differences incl. NaN up); the per-case one-step budget counts m·I codes and a fully wrong M=1 case fails; the posted gfx1250 table matches the test; no default-path cost; no open review threads.


Reviewed at 3d4ffba (Deep; two independent full A–C passes on own commits 292a532..3d4ffba plus D; 6 hunters, 8 verifiers, 2 C2). Items 2-4 are in code/text earlier rounds missed. Already fixed: r47 items 1 (gfx1250 run posted), 3 (per-case budget), 4 (fmin_f32/fclamp_f32).

@yhl-amd

yhl-amd commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Items 2–4 are addressed in 4136bc792 (on top of 3d4ffbac7; #7667 / #7668 untouched; previous head kept as bak/8057-pre1120a on the fork).

  1. Rebase and gfx1250 run: understood. Order is [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667 -> [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668 -> rebase this PR onto main. [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667 is being rebased separately, and I do not touch [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667 / [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668 here. After the rebase I will post a fresh gfx1250 run of op_tests/test_flydsl_batched_gemm.py at the rebased head. Until then the last gfx1250 run is the one at 3d4ffbac7; this commit changes no kernel instruction.
  2. gate_up_silu_kernel_ok: now cfg["tile_n"] in (128, 256) and cfg["tile_n"] // cfg["n_warp"] == 64 (plus split-K / cluster 1), i.e. only the table's tile shapes, which are what the gfx1250 test runs. All 8 table tiles still pass. test_kernel_ok_rejects adds a 128-columns-per-wave name (t64x256 nw2) and a tile_n = 192 name (t64x192 nw3); the existing reject names stay rejected.
  3. NaN codes: a mismatching pair counts as far when either code is an e4m3 NaN ((a & 0x7F) == 0x7F or (r & 0x7F) == 0x7F). So 0x7F vs 0x7E and 0xFF vs 0xFE are no longer one-step codes.
  4. Text:

CPU host test passes at this head (62 cases); black 26.10.1 and ruff clean. This round does not use gfx1250.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (4)

  1. Land #7667, then #7668, then rebase this PR onto main, and reuse #7667's quant helpers when you do (still open, extended). All three PRs are still CONFLICTING. #7667 (e552b7c00) now has 085326080, which moves the accumulator group-32 quant into kernels/quant_utils.py: emit_mxfp8_group32_scale, emit_mxfp8_acc_pair_to_lds and emit_mxfp8_scale_rows_store. This PR's nested _group_scale, _quant_group_to_lds and the scale-row loop of _store_quant_tile (kernels/gemm_a8w8_gfx1250.py:1336-1413) do the same work, op for op.
    • On rebase, call those helpers from both the accumulator and SwiGLU epilogues, and keep only the local e4m3 TDM store.
    • Passing the already bf16-rounded hs through the helper's .to(out_cls).to(f32) is a no-op. We checked every bf16 pattern, including inf, NaN, ±0 and subnormals.
    • Then post a fresh gfx1250 op_tests/test_flydsl_batched_gemm.py run at the rebased head.
  2. Fix the squash text when you rebase (still open, plus four more false claims). Besides the three already listed (a484d81c0 "declared mutated, no-op fake", 7aa707829 "clamped in f32", d3c99322a "at shapes the tiles divide"), these also contradict the head:
    • d3c99322a "Scales match the unfused chain exactly". The docstring at batched_gemm_a8w8_gfx1250.py:884-893 says the scale can move by one at 448·2^k.
    • a484d81c0 "gate_up_silu_kernel_for is safe inside torch.compile". Its docstring at :837-842 says not to branch on it in a traced forward.
    • a484d81c0 "e4m3 codes match … up to one step". The scale can move instead.
    • a484d81c0 "validates … before the arch check, so all of it is testable without a GPU". _check_e8m0 for x_scale / w_scale runs after the arch check (:954-958).
    • No need to rewrite history: write the corrected text as the squash message when merging, or post it in the description.
  3. Make gate_up_silu_kernel_ok match its docstring. batched_gemm_a8w8_gfx1250.py:760-774. Our r48 predicate was incomplete. It still accepts names the gfx1250 test never runs: _nopl, names with no K-loop suffix, and t16x128x128 mw1 nw2 or t256x256x512 mw4 nw4. tile_k and m_warp change the new gate/up gather and the epilogue's wmb. The docstring (:761-764) says "the only ones the gfx1250 op test runs".
    • Fix: return name in {n for _, n in _GATE_UP_SILU_TILES}, and keep the structural check in _check_gate_up_silu_tiles.
    • Replayed: all 8 table tiles are accepted, every test_kernel_ok_rejects name is still rejected, and test_run_rejects_kernel and the runtime pick still pass. ATOM#3446 passes no kernel_name.
  4. Fix the clamp formula in the kernel header comment. kernels/gemm_a8w8_gfx1250.py:132 says bf16(silu(min(g, L)) * clamp(u, -L, L)). Since 3ecba659b, _act (:1450-1451) rounds the clamped gate first. Write bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)). The two differ for limits bf16 cannot hold, such as 5.02.

Items 2 (extra claims), 3 and 4 are in text and code that earlier rounds missed. Nothing else is open: CPU host test 62 passed under stubs; no default-path change (the plain-GEMM names and steps are unchanged; the import-time table check is about 23 µs and pure Python); limit handling, gather mapping, M-tail masking and the NaN/one-step metric all checked. CI at head: only evaluate and tag-title have run (both pass); Aiter Test has not run, and no lane runs the gfx1250 op test.


Reviewed at 4136bc7 (Deep; full A–C on own commits 292a532..4136bc7 plus D; 3 hunters + review-pr skill agents, 2 verifiers, C2). Already fixed: r48 items 2 (tile_n / per-wave limits), 3 (NaN codes far), 4a (scale-move wording), 4c (PR description).

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-shared-gate-up-silu-mxfp8 branch from 4136bc7 to 4ebcaa8 Compare November 23, 2026 07:42
@yhl-amd

yhl-amd commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@valarLip Thanks. Rebased onto #7668's new head e9476df89 (on #7667 dfc62154e). New head: 4ebcaa840.

1. Rebase, reusing #7667's quant helpers. Done in 8e8af1776.

  • The SwiGLU epilogue now calls emit_mxfp8_acc_pair_to_lds and emit_mxfp8_scale_rows_store. _group_scale, _quant_group_to_lds and the scale-row loop of _store_quant_tile are deleted.
  • The only local piece left is the e4m3 TDM store (_store_e4m3_tile). The SwiGLU and accumulator-quant epilogues share it.
  • The accumulator-quant path is [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667's code as is, apart from calling that store.
  • The already-bf16 hs goes through the helper's round, as you suggested.
  • Offline gfx1250 compile (flydsl 0.5.0, null pointers, no GPU):
    • The seven SwiGLU configs (five table tiles at limit 10, t64x128 at 0, t128x256 at 5.02) match 4136bc792 opcode for opcode. The only change is that two scalar registers holding constants swap numbers. Limit 0 is byte-identical. The helper's extra round is folded away.
    • Same VGPR counts, no spill, no scratch.
    • Nine plain / fused-quant / _pl configs are byte-identical to [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668's head.
  • gfx1250 op_tests/test_flydsl_batched_gemm.py at this head: pending. I will post it before merge.

2. Squash text. The rebase conflicted with #7667's helper move in most of the seven commits, so I squashed them into 8e8af1776 and wrote its message as the corrected squash text. It describes the head:

  • the op is functional (mutates_args=[]);
  • the gate clamp is rounded to bf16;
  • the picker returns a tile only for the measured device and shape;
  • the e8m0 scale can move by one at 448·2^k;
  • gate_up_silu_kernel_for is not for branching in a traced forward;
  • the e8m0 x_scale / w_scale checks run after the arch check.

The PR description is updated to match.

3. gate_up_silu_kernel_ok. Done in 4ebcaa840.

  • It now returns name in _GATE_UP_SILU_NAMES, the table's names.
  • The structural check (split-K / cluster 1, tile_n 128 or 256 with 64 columns per wave, _pl) moved into _check_gate_up_silu_tiles.
  • test_kernel_ok_rejects adds a table tile without _pl, t16x128x128 mw1 nw2 and t256x256x512 mw4 nw4.

4. Clamp comment. Done in 4ebcaa840. The kernel header now reads bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)).

Validation at 4ebcaa840:

  • CPU (GPU-less container): test_flydsl_gate_up_silu_host.py + test_gemm_host_dispatch_cache.py give 84 passed. The one failure is the pre-existing CUDA-only test_mxscale_config_precheck_matches_padded_walk, which fails the same way at 4136bc792.
  • gfx950: test_flydsl_batched_gemm.py exits 0, with the same correctness columns as [FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it #7668's head.
  • black 26.10.1 and ruff are clean.
  • The previous head is kept as bak/8057-pre1123a on the fork.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-shared-gate-up-silu-mxfp8 branch from 4ebcaa8 to 9c9ff68 Compare November 23, 2026 09:23
@yhl-amd

yhl-amd commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto #7668's new head 910f36881, which merges main to clear a docstring conflict in op_tests/test_gemm_host_dispatch_cache.py with #8291. The two commits of this PR are replayed unchanged (head 9c9ff68d4). CPU host tests pass (same single CUDA-only failure as before), black and ruff are clean. No idle gfx950 GPU was available, so the GPU rerun was skipped; gfx1250 is still pending.

yhl-amd and others added 6 commits November 25, 2026 23:51
…ed entry runs the tuned row

Fused MXFP8 epilogue: when the warp tile holds an even number of 16-column
WMMA tiles (even wmma_n_rep), the group-32 quant reads the accumulators
instead of staging the bf16 C tile in LDS and re-reading it per group. A lane
holds 8 consecutive columns of one row per 16x16 tile, so a 32-column group
is two adjacent tiles across lanes l and l^16 and its amax is one
shuffle_xor(16). Values are rounded to the output dtype first, exactly as the
bf16 path stores them, so the e4m3 codes and e8m0 scales are unchanged; the
e4m3 and scale bytes still go through LDS for the TDM store. An odd
wmma_n_rep keeps the LDS-staged quant. The epilogue has three peer branches
(bf16 store, accumulator quant, LDS-staged quant) with the quant setup and
the group-32 scale step shared by the two quant branches.

batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant looks the shape up in the
same preshuffle table as the bf16 entry and passes a flydsl row's kernelName
to the runner, so both entries run the same tuned tile. No row, an opus row
or a compute-kernel row leaves the tile to the runner; any other name is
passed through, so a name the runner does not accept raises, as for the bf16
entry.

Tests: op_tests/test_flydsl_batched_gemm.py checks the fused quant on tuned
tiles that pin each epilogue branch (two LDS-staged, seven accumulator) at
ragged M against quantize_fp8 of the bf16 GEMM on the same tile;
op_tests/test_bmm_a8w8_fused_quant_tuned_row.py is a CPU test of the
tuned-row lookup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the merge with main's gfx950 fused quant, one _fused_quant_tuned_kernel
serves both arches. The CPU test now also checks a gfx950 flydsl row (passed
through) and a gfx950 opus row or no row (runner's choice).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The batched mxfp8_32 kernel's accumulator quant and the 256x256 compute
kernel's fused epilogue emitted the same per-group step (round to the output
dtype, h0/h1 amax with one shuffle_xor(16), 1e-10 floor, RoundUp e8m0,
scaled fp8 conversion, e4m3 and scale bytes into LDS) and the same scale-row
store. Both now call emit_mxfp8_acc_pair_to_lds and
emit_mxfp8_scale_rows_store in kernels/quant_utils.py, next to
emit_mx_e8m0_scale; emit_mxfp8_group32_scale (floor + RoundUp scale) is also
used by the batched kernel's LDS-staged quant. Each kernel keeps its own e4m3
TDM store. No change in the emitted code is intended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FUSED_QUANT_TILES adds t64x32x512 mw4 nw1 (one quant group per tile row) and
t160x128x256 nw2 (more tile rows than threads, so the scale rows take a
second pass), both shipped DSv4.1 rows on the accumulator branch that no test
pinned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The scale-row store loops ceil(tile_m / block) times, so a thread copies
rows tid, tid + block, ...; say that in the helper docstring and at both
kernel call sites instead of "one row per thread". In quant_utils, the
native-scale helper no longer refers to a function that does not exist,
and the module docstring names the dtypes _DTYPE_CFG actually defines.
The gfx950 tuned-row test uses the DSv4 batched preshuffle table's row for
its shape. Comments and test data only; no kernel change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…red group-32 scale

_fused_quant_tuned_kernel imports the gfx1250 compute-kernel name check
only on gfx1250, after the table lookup; gfx950 returns the flydsl row's
name directly, as before the merge with the gfx1250 lookup. The gfx950 bmm
fused epilogue calls emit_mxfp8_group32_scale instead of its own copy of
the same steps (1e-10 floor, RoundUp e8m0, f32 scale). Two docstrings no
longer say the fused epilogue always quantizes the bf16 C tile.

Tests: FUSED_QUANT_TILES also pins the DSv4.1 wo_a tuned tiles the fused
entry runs (t192x128x256, t128x256x256 mw1 nw4, t96x128x256, and the
LDS-staged t32x32x512); the gfx1250 tuned-row fixture uses a CU count
other than the gfx950 one so the lookup must forward the caller's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-shared-gate-up-silu-mxfp8 branch 2 times, most recently from 6b2409f to 62a8807 Compare November 25, 2026 16:15
@yhl-amd

yhl-amd commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Re-stacked on #7668 b21a4a943 (head 62a880745, previous head kept as bak/8057-pre1125a). The two commits are replayed unchanged, with the same tree as before. CPU host tests pass (the CUDA-only failures match main), and black and ruff are clean. gfx1250 is still pending.

yhl-amd and others added 9 commits November 27, 2026 11:26
Two LDS-staged tiles (t16x64 nw4, t32x32 nw2) and seven accumulator tiles,
as the tuple and the module docstring list them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fragments of k-step g+1 are read from LDS while the WMMAs of k-step g
run, across K-tile boundaries too, so LDS reads, WMMAs and the TDM refill
overlap. The fence before the next K-tile is split into signal/wait (the
primitives the 256x256 compute kernel already uses) around the two halves of
the last k-step's WMMAs, and the per-stage LDS read bases are formed a tile
ahead. Every accumulator sees its k-steps in the same order with the same
operands, so results are bit-identical to the single-fence loop.

New pipelined constexpr, appended after fuse_quant_out: -1 (default)
takes the pipelined loop for mxfp8_32, no scale preload, no cluster,
split_k 1, tile_k >= 256 when the accumulators plus two in-flight fragment
sets fit the register estimate; 1 forces it (batched kernel names may end
in _pl; tile_k < 256 is rejected), 0 keeps the old loop. No new
environment variable.

The DSv4.1 mxscale table rows for N=5120, K=8192 at M 672/768 and for
N=32768, K=1280 at M 576/672/768 are replaced in place with tiles that
use the pipelined loop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pipelined constexpr now defaults to 0 and takes only 0 or 1; the
automatic rule that moved every eligible mx32 tile onto the new loop is
gone, so existing tuned rows keep the loop they were timed on. A trailing
_pl in a batched or 2-D mxfp8_32 kernelName is the only way to select it,
and check_pipelined_k_loop() is the single place that rejects it where the
loop does not apply (it replaces the batched runner's tile_k check).

The DSv4.1 rows validated with the pipelined loop now carry _pl: N=5120,
K=8192 at M 576 / 672 / 768 (the latter two are the t192x128x256 rows that
relied on the automatic rule); the N=32768, K=1280 rows already did.

Also drop the unused pipelined argument of bmm_mx32_kernel_name, share the
fragment join of load_a / load_b and the serpentine WMMA order with the
pipelined loop, and fix the tail fence comment.

Tests: CPU checks of the _pl name round trip (batched and 2-D) and of the
rejections in op_tests/test_gemm_host_dispatch_cache.py; on gfx1250,
op_tests/test_flydsl_batched_gemm.py compares _pl with the single-fence loop
bit for bit on a ragged K and on a shipped _pl row, and runs the fused quant
epilogue on a _pl tile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in's tile; test nb3/nb4

Re-timed the pipelined rows against the retuned tiles now on main for the
six DSv4.1 2-D keys on one gfx1250 box. The pipelined t192x256x256 tile stays
ahead at M 576 and 768 for N=32768, K=1280; the other four keys keep main's
rows. PIPELINED_CASES also compares the pipelined and single-fence loops on a
three-buffer and a four-buffer tile, where the tail fences differ from the
steady loop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the fence wait the wave refills the stage tile kt held and then reads
the first fragments of tile kt+1; the comment had the two steps swapped.
Comment only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The us, tflops and bw of the two kept _pl rows (N=32768, K=1280 at M 576 and
768) were main's values scaled by a paired ratio. Replace them with values
measured on gfx1250 through the MXFP8 GEMM tuner's harness (its data
generation, B=1 batched run path, mp_tuner timing, error check and
throughput formula), bw in the unit of the neighbouring gfx1250 rows. The
kernelName of both rows is unchanged, so dispatch is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`_pl` stays the only switch of the software-pipelined K loop: a kernelName
without it runs the single-fence loop it was tuned on, in the batched and
the 2-D paths alike. CPU tests pin that:

- untagged 2-D names on which the pipelined loop would apply (tile_k 256,
  split_k 1, before and after cluster_m is fitted to M) resolve to the
  single-fence loop, and their `_pl` names to the pipelined one; no other
  suffix parses;
- every mxfp8_32 kernelName in the shipped tuned tables runs the pipelined
  loop exactly when it ends in `_pl`.

Kernel comments: the early per-stage LDS bases are formed a tile ahead only
when `early` holds, and the tail's max(..., 0) only touches the last tile's
unused fence count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A shared expert whose down projection reads MXFP8 runs the gate_up GEMM
(bf16 [M, 2I]), silu_and_mul and quantize_fp8 as three launches. The
batched mxfp8_32 gfx1250 kernel now applies the SwiGLU before its fused
group-32 MXFP8 epilogue, so the three become one GEMM.

Kernel (kernels/gemm_a8w8_gfx1250.py), new fuse_act_mul / act_limit
constexprs (batched mxfp8_32, 32x32 B scale, fuse_quant_out, no K tail):
- B is the unmodified [gate; up] weight. Each CTA gathers its tile_n B
  rows, and their scale rows, as tile_n/64 blocks of [32 gate rows, the
  matching 32 up rows] through one nested TDM view, so a wave's 64 columns
  hold gate and up of the same 32 outputs in the same lanes.
- The epilogue rounds the accumulators to bf16 and forms
  bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)) as aiter silu_and_mul
  does (L = 0: no clamp), then quantizes each 32-column group with ROCm#7667's
  emit_mxfp8_acc_pair_to_lds / emit_mxfp8_scale_rows_store; only the e4m3
  TDM store stays local, shared with the accumulator-quant epilogue.
- Against the bf16 GEMM + silu_and_mul + quantize_fp8 chain, a SwiGLU
  value can sit one bf16 step from silu_and_mul's (exp/rcp rounding), so
  an e4m3 code can differ by one step; where that value is its group's
  amax at 448 * 2**k, the group's e8m0 scale moves by one instead (and so
  all 32 codes).
- The kernel name gets a _silu<limit>q suffix, so it never collides with
  the plain GEMM; fuse_act_mul defaults to off.

Host (batched_gemm_a8w8_gfx1250.py):
- run_gate_up_silu_mxfp8_32_gfx1250: the raw launch. Operand dtypes,
  strides, shapes, devices, alignment, the limit and the kernel name are
  checked before the arch check; the e8m0 x_scale / w_scale checks run
  after it. swiglu_limit is read as the f32 silu_and_mul receives.
  kernel_name=None picks the tile from the runtime row count.
- gate_up_silu_supported(n2, k): gfx1250 with the measured CU count at
  the measured [2I, K]; independent of the row count.
- gate_up_silu_kernel_for(m, n2, k): the table tile for the measured
  device and shape only, else None. A host helper for code that sees the
  real row count; not for branching in a traced forward.
- The table tiles end in _pl (the pipelined K loop).

Op (batched_gemm_op_a8w8.py): functional registered op
gate_up_silu_mxfp8_32 (mutates_args=[]) that picks the tile from the
runtime row count and returns the e4m3 / e8m0 outputs.

Tests: op_tests/test_flydsl_gate_up_silu_host.py (CPU: gating, picker,
limit and operand validation, functional op under fullgraph dynamic
shapes) and test_gate_up_silu_fused in op_tests/test_flydsl_batched_gemm.py
(gfx1250: every tile bucket, limits 10, 0 and 5.02, vs the unfused chain).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gate_up_silu_kernel_ok now accepts exactly the kernelNames of
_GATE_UP_SILU_TILES, the ones the gfx1250 op test runs; another tile_k,
m_warp or K loop changes the gate/up gather or the epilogue's rows. The
structural check (split-K / cluster 1, tile_n 128 or 256 with 64 columns
per wave, `_pl`) moves to _check_gate_up_silu_tiles, which runs once at
import. The CPU test rejects a table tile without `_pl` and two table-like
shapes the op test does not run.

The kernel header comment gives the clamp as the epilogue computes it,
bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-shared-gate-up-silu-mxfp8 branch from 62a8807 to 7d78cf6 Compare November 27, 2026 03:31
@yhl-amd

yhl-amd commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Re-stacked on #7668 1683901ce (head 7d78cf69e, previous head kept as bak/8057-pre1127a). The two commits replayed cleanly and are unchanged. Against the previous head, the tree differs only in that test comment, which comes from #7667 / #7668. black and ruff are clean, and gfx1250 is still pending.

This branch has not been deployed

No deployments
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.

4 participants