Skip to content

feat(ck_tile): RowColQuant does support PreshuffleB — drop it from the gate - #3770

Closed
ThomasNing wants to merge 2 commits into
ROCm:developfrom
ThomasNing:thomas/rowcol-supports-preshuffleb
Closed

ThomasNing wants to merge 2 commits into
ROCm:developfrom
ThomasNing:thomas/rowcol-supports-preshuffleb

Conversation

@ThomasNing

Copy link
Copy Markdown
Contributor

Stacked on #3769 (the BQ-extent fix) — that one should land first, since without it the rowcol path fails verification on its own and this combination cannot be judged.

What

run_gemm_quant_example.inc rejects PreshuffleB for AQuantGrouped, RowColQuant and bf16_fp4 in a single condition. RowColQuant does not belong there. The kernel treats quant mode and B layout as orthogonal axes — the pipeline is invoked plainly and the scales are applied through the epilogue's scale windows — so a preshuffled B is just a different B layout to it.

Evidence (gfx950, MI350X)

In this example, on top of #3769:

run result
rowcol -preshuffleb=1, 512³ correct (×2 runs)
rowcol -preshuffleb=1, 1024×2688×6144 correct
rowcol -preshuffleb=0, 512³ (control) correct

Independently, driving the same combination through AITER's a8w8 tuner: errRatio 0.0000 across 7 GEMM shapes with per-token A scales and per-channel B scales, beating the flatmm path by 8–11% at three of them:

shape (M,N,K) rowcol + preshuffle flatmm Δ
256, 2688, 6144 24.69 µs 27.44 +11.2%
1920, 6144, 12288 178.81 193.21 +8.1%
2048, 6144, 12288 184.70 204.36 +10.6%

That combination — preshuffled weights with per-token × per-channel scales — is the common shape for FP8 LLM inference with online activation quantization, so having it reachable matters beyond this example.

AQuantGrouped and bf16_fp4 are left gated; not investigated here.

🤖 Generated with Claude Code

ThomasNing and others added 2 commits September 5, 2026 04:44
… N scales

38_block_scale_gemm fails its own verification for -quant_mode=rowcol on
gfx950, non-deterministically (8.2% then 7.8% wrong across identical runs,
max err: inf), while abquant and tensor pass in the same harness.

RowColQuant shares its AQK/BQK/BQN branch with TensorQuant and inherits
BQN = 1, so the BQ tensor is allocated as (BQK=1, BQN=1) -- a single element.
stride_BQ, however, is computed a few lines later for a (1, N) tensor, and the
kernel reads one scale per output column. The kernel therefore reads N values
out of a one-element buffer: hence the inf/NaN and the run-to-run variation.
BQN = 1 is correct for TensorQuant, which is why the shared branch hid it.

Split the branch and give RowColQuant BQN = N.

  quant_mode  before                                   after
  rowcol      fail (8.2%, 7.8%, max err inf)           correct (x2 runs)
  rowcol      fail at default dims                     correct
  abquant     correct                                  correct
  tensor      correct                                  correct

Reproduce: tile_example_gemm_quant -prec=fp8 -quant_mode=rowcol -m=512 -n=512
-k=512 -v=1

Co-Authored-By: Claude Fable 5 <[email protected]>
…he gate

run_gemm_quant_example.inc rejects PreshuffleB for AQuantGrouped, RowColQuant
and bf16_fp4 in one condition. RowColQuant does not belong there: the kernel
treats the quant mode and the B layout as orthogonal axes -- the pipeline is
invoked plainly and the scales are applied through the epilogue's scale windows
-- so a preshuffled B is simply a different B layout to it.

Verified in this example on gfx950, on top of the BQ-extent fix (without that
fix the rowcol path fails verification on its own, which is plausibly why the
combination was gated):

  rowcol -preshuffleb=1  512x512x512        correct (x2 runs)
  rowcol -preshuffleb=1  1024x2688x6144     correct
  rowcol -preshuffleb=0  512x512x512        correct   (control)

Independently, driving the same combination through AITER's a8w8 tuner on
MI350X gave errRatio 0.0000 across 7 GEMM shapes with per-token A scales and
per-channel B scales, and it beat the flatmm path by 8-11% at three of them
(24.69 vs 27.44us at 256x2688x6144, 178.81 vs 193.21 at 1920x6144x12288,
184.70 vs 204.36 at 2048x6144x12288).

AQuantGrouped and bf16_fp4 are left gated: not investigated here.

Co-Authored-By: Claude Fable 5 <[email protected]>
@ThomasNing

Copy link
Copy Markdown
Contributor Author

Withdrawing this — my example-side evidence is invalid. Closing rather than leaving a wrong claim open.

The -preshuffleb flag is not part of the LUT key for rowcol: gen_lut_key only appends it for bquant/abquant (gemm_quant.cpp:50-71), and the registered rowcol entries are keyed {"fp8", "rowcol"} / {"bf8", "rowcol"} (gemm_quant_rowcol.cpp:13,21). So -preshuffleb=1 and -preshuffleb=0 dispatch to the same kernel, whose GemmConfig::PreshuffleB is false — which is also why the throw never fired in my runs. Both of my "before/after" runs executed the identical non-preshuffle kernel.

Compounding it: the pipeline selection sends RowColQuant to GemmPipelineAgBgCrCompV3 unconditionally (run_gemm_quant_example.inc:198-201), so even a config with PreshuffleB=true would not reach a weight-preshuffle pipeline through this path today.

What a correct version of this change needs, and what I'll open when I have it working and measured:

  1. a rowcol GemmConfig with PreshuffleB=true, registered under a {prec, "rowcol", "preshuffleb"} LUT key so the flag actually selects it;
  2. pipeline selection routing rowcol + preshuffle to a weight-preshuffle pipeline (WP2) instead of CompV3;
  3. WeightPreshufflePipelineAGmemBGmemCRegV2 announcing PreshuffleB — the quant kernel detects preshuffle by SFINAE on GemmPipeline::PreshuffleB (gemm_quant_kernel.hpp:104-106) and silently defaults to false, so pairing it with WP2 today makes the kernel treat preshuffled weights as plain;
  4. then the actual before/after.

Note that #3769 (the rowcol BQ-extent fix) is unaffected — that test was real: rowcol failed non-deterministically before and passes after, with abquant/tensor unchanged as controls.

The underlying claim also still stands on independent evidence: driving RowColQuant + WP2 directly through AITER on MI350X gives errRatio 0.0000 across 7 shapes and beats the flatmm path by 8-11% at three of them. That is what motivated this PR; the example-side demonstration I attached to it was simply not testing what I said it was.

@ThomasNing ThomasNing closed this Sep 4, 2026
assistant-librarian Bot pushed a commit that referenced this pull request Sep 25, 2026
=?UTF-8?q?feat(ck=5Ftile):=20make=20weight-preshuffled=20?=
 =?UTF-8?q?B=20usable=20with=20RowCol=20(per-token=20=C3=97=20per-channel)?=
 =?UTF-8?q?=20scales=20(#11721)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

ISSUE ID : #3766

Replaces my #3770, which I withdrew because its evidence was vacuous —
the `-preshuffleb` flag was not part of the rowcol LUT key, so both arms
of that "before/after" ran the same non-preshuffle kernel. This PR fixes
that (among other things) and the test now genuinely toggles.

Two commits: the first is #3769 (the rowcol BQ-extent fix), included
because the enablement cannot be evaluated without it — rowcol fails its
own verification until `BQN = N`. If #3769 merges first this rebases
cleanly.

## The defect

`WeightPreshufflePipelineAGmemBGmemCRegV2` never announced
`PreshuffleB`. `QuantGemmKernel` detects a preshuffled B by SFINAE on
`GemmPipeline::PreshuffleB` (`gemm_quant_kernel.hpp:104-106`) and
**defaults to false when the member is absent** — so pairing the quant
kernel with the weight-preshuffle pipeline made it read preshuffled
weights as a plain B. No error, just wrong numbers.

Measured by removing the announcement again on an otherwise-identical
build (gfx950):

| | result |
|---|---|
| rowcol + preshuffleb, **without** the announcement | **fail — 39.47%
wrong, max err 386.78** |
| rowcol + preshuffleb, **with** it | correct |
| rowcol, preshuffleb=0 (control) | correct in both builds |

## Making the combination reachable

- rowcol routes to the weight-preshuffle pipeline when `PreshuffleB` is
set (it was pinned to `GemmPipelineAgBgCrCompV3` unconditionally);
- new `GemmConfigPreshuffleB_RowCol_Prefill`;
- `-preshuffleb` joins the rowcol LUT key — without it the flag selected
the same kernel either way, so the configuration could not be tested at
all;
- `RowColQuant` leaves the `PreshuffleB` rejection list.

## Results in this example (gfx950 / MI350X, fp8, verification on)

| shape | preshuffleb=0 | preshuffleb=1 |
|---|---|---|
| 512³ | correct | correct |
| 1024×2688×6144 | 0.1014 ms, 333 TF | **0.0471 ms, 718 TF** |
| 2048×6144×12288 | 0.7211 ms, 429 TF | **0.2102 ms, 1471 TF** |

**Caveat**: the two arms differ in tile shape as well (the existing
rowcol config is decode-shaped 16×64, the new one prefill-shaped
128×128), so read these as *the new preshuffled config vs the only
rowcol config the example had at these shapes*, not as preshuffle in
isolation.

## Independent measurement, stated carefully

Driving this same composition through AITER's tuner on MI350X — 1754
measurements across 6 GLM-shaped GEMMs, full candidate space (259 flatmm
tiles + 44 rowcol tiles), **errRatio 0.0000 on every one**:

| shape (M,N,K) | best rowcol | best flatmm | winner |
|---|---|---|---|
| 1, 2688, 6144 | — (no divisible tile) | 11.008 µs | flatmm |
| 64, 2688, 6144 | 12.640 µs (rank 5) | 11.325 µs | flatmm, −11.6% |
| 256, 2688, 6144 | 19.190 µs (rank 10) | 17.590 µs | flatmm, −9.1% |
| 1024, 2688, 6144 | 41.226 µs (rank 35) | 35.491 µs | flatmm, −16.2% |
| **2048, 6144, 12288** | **158.661 µs (rank 1)** | 175.943 µs |
**rowcol, +9.8%** |
| **16384, 6144, 12288** | **1165.842 µs (rank 1)** | 1258.569 µs |
**rowcol, +7.4%** |

So it is a genuine per-shape winner on large-M / prefill-shaped GEMMs
and **not** a global replacement; across 184 matched (tile, BlockPerCu)
pairs the median is −0.9%, with the advantage concentrated in wide-N
tiles and growing with M. Also note **M=1 cannot dispatch to this
route** — no MTile divides 1 and it is instantiated unpadded; that needs
`kPadM` wired through separately.

(Earlier revisions of this description quoted "+8-11% over flatmm" from
a restricted candidate set; the table above supersedes it. See the
comments for the full correction history.)

Per-token × per-channel scales on preshuffled weights is the standard
shape for FP8 LLM inference with online activation quantization, so
having it reachable — and not silently mis-typed as plain B — matters
beyond this example.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant