Skip to content

fix(ck_tile): RowColQuant example allocates a 1x1 BQ tensor but reads N scales - #3769

Closed
ThomasNing wants to merge 1 commit into
ROCm:developfrom
ThomasNing:thomas/fix-rowcol-bq-extent
Closed

ThomasNing wants to merge 1 commit into
ROCm:developfrom
ThomasNing:thomas/fix-rowcol-bq-extent

Conversation

@ThomasNing

Copy link
Copy Markdown
Contributor

Problem

38_block_scale_gemm fails its own verification for -quant_mode=rowcol on gfx950, and does so non-deterministically, while abquant and tensor pass in the same harness:

tile_example_gemm_quant -prec=fp8 -quant_mode=rowcol -m=512 -n=512 -k=512 -v=1
  run 1: max err: inf, 21504 errors, 8.203125% wrong values -> fail
  run 2: max err: inf, 20480 errors, 7.812500% wrong values -> fail

Cause

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. But stride_BQ is computed a few lines later for a (1, N) tensor, and the kernel reads one scale per output column. The kernel reads N values out of a one-element buffer, which is exactly why the failure carries inf/NaN and changes between identical runs.

BQN = 1 is correct for TensorQuant — which is what hid this in the shared branch.

Fix

Split the branch; give RowColQuant BQN = N.

quant_mode before after
rowcol, 512³ fail (8.2%, then 7.8%, max err inf) correct (×2 runs)
rowcol, default dims fail correct
abquant, 512³ correct correct
tensor, 512³ correct correct

Found while investigating whether RowColQuant + PreshuffleB is really unsupported (the throw at run_gemm_quant_example.inc:~995). That question is separate and left alone here — it cannot be answered honestly while the rowcol path fails verification on its own, and this may well be why the combination was gated in the first place.

🤖 Generated with Claude Code

… 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]>
@ThomasNing

Copy link
Copy Markdown
Contributor Author

Closing here and reopening in the active repository: ROCm/rocm-libraries#11720. This mirror is read-only, so a PR against it cannot land. Content is unchanged.

@ThomasNing ThomasNing closed this Sep 5, 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)
CongMa13 pushed a commit to ROCm/rocm-libraries that referenced this pull request Sep 25, 2026
… N scales (#11720)

ISSUE ID : ROCm/composable_kernel#3766

## Problem

`38_block_scale_gemm` fails its **own** verification for
`-quant_mode=rowcol` on gfx950, and does so *non-deterministically*,
while `abquant` and `tensor` pass in the same harness:

```
tile_example_gemm_quant -prec=fp8 -quant_mode=rowcol -m=512 -n=512 -k=512 -v=1
  run 1: max err: inf, 21504 errors, 8.203125% wrong values -> fail
  run 2: max err: inf, 20480 errors, 7.812500% wrong values -> fail
```

## Cause

`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. But `stride_BQ` is computed a few lines later for a
`(1, N)` tensor, and the kernel reads one scale per output column. The
kernel reads N values out of a one-element buffer, which is exactly why
the failure carries `inf`/NaN and changes between identical runs.

`BQN = 1` is correct for `TensorQuant` — which is what hid this in the
shared branch.

## Fix

Split the branch; give `RowColQuant` `BQN = N`.

| quant_mode | before | after |
|---|---|---|
| rowcol, 512³ | fail (8.2%, then 7.8%, max err inf) | **correct** (×2
runs) |
| rowcol, default dims | fail | **correct** |
| abquant, 512³ | correct | correct |
| tensor, 512³ | correct | correct |

Found while investigating whether `RowColQuant` + `PreshuffleB` is
really unsupported (the `throw` at `run_gemm_quant_example.inc:~995`).
That question is separate and left alone here — it cannot be answered
honestly while the rowcol path fails verification on its own, and this
may well be why the combination was gated in the first place.

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

---

*Migrated from ROCm/composable_kernel#3769 — that repository is now a
read-only mirror. All measurements quoted above were taken on the CK
tree at the time of that PR and are unchanged; the diff applies cleanly
to `develop` here.*

---------

Co-authored-by: ThomasNing <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
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