Repository navigation
[CK] [FlyDSL] [JIT] [Kernel] Add gfx950 4-wave INT8 bpreshuffle GEMM - #6828
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
dbe12fd to
6f7d083
Compare
johannes-graner
left a comment
There was a problem hiding this comment.
Thanks for the work on this. The speedup claims reproduced on an identical MI355X, with both warm and cold cache. Below are the items I would like to see addressed before merge, with a few exceptions: items left to you (this PR or a follow-up), one nit, and some design questions.
Numbered items
- Padded-K weights select an incompatible tuned row
- The ASM-only lookup breaks on the new FlyDSL rows
- The existing GEMM sweep calls the new candidate unconditionally
- Inline assembly and non-stable FlyDSL APIs
- The CI entry point does not run the new correctness cases
- The benchmark correctness reference is a candidate
- Dispatch assertions depend on the production tuning table
- The new kernel is not enrolled in the common tuner
- Untuned small-M INT8 fallback performance
- CU count validation in the XCD derivation
- XCD power-of-two assert
Design questions
- Should consumers of the shared bpreshuffle tuned table filter rows by
libtypeand K before they use a kernel name? Items 1 and 2 both come from a consumer that reads this table without that check. - Is adding bias after BF16 conversion required by the intended consumer, or is it mainly a way to keep the device kernel specialized? The existing generic preshuffle bias epilogue adds bias before conversion, so the two are not numerically interchangeable. Bias-enabled calls were not part of the performance comparison (
aiter/ops/gemm_op_a8w8.py:802). - Which existing generic FlyDSL INT8 configurations did you compare against before choosing a separate pipeline? The harness includes one
flydsl_genericconfiguration, and the common tuner covers other tiles and split-K. A comparison against that family would establish the separate kernel's incremental benefit.
Lower importance
nit, lower importance. Could the PR body add the flydsl-kernel-code-cleanup completion checkbox once that pass is done? Keeping the rationale for each assembly boundary lets reviewers tell intentional exceptions from leftovers.
2359f19 to
13b2e0c
Compare
|
Thanks for the thorough review. All numbered items are addressed in the latest push, which is also rebased onto current main; per-item replies are on each thread. Performance on the three measured shapes is unchanged versus the reviewed head (same MI355X, back-to-back runs, within 0.5%). Design questions
Nit: The |
|
Thanks for the following up quickly, in general it now looks very nice! A few small comments though:
Once the docstring and description are updated, I will approve and you can open for further review. |
|
Thanks! All addressed in the latest push:
|
Signed-off-by: Kristian Sikiric <[email protected]>
Signed-off-by: Kristian Sikiric <[email protected]>
Signed-off-by: Kristian Sikiric <[email protected]>
Signed-off-by: Kristian Sikiric <[email protected]>
Signed-off-by: Kristian Sikiric <[email protected]>
Signed-off-by: Kristian Sikiric <[email protected]>
Signed-off-by: Kristian Sikiric <[email protected]>
gemm_a8w8_ASM and the tuner's --run_config accepted an INT8 row only
when its libtype was "" or "asm". pandas reads a blank libtype as NaN
("nan"), and merging a table without the column fills it with 0, so such
rows were skipped and gemm_a8w8_ASM fell back to the heuristic kernel
with splitK=1. Before FlyDSL INT8 every INT8 row was ASM; now only the
FlyDSL rows are skipped. The dispatch checks cover blank, NaN, "0", 0 and
missing libtype.
|
LGTM |
Main's #6828, merged in with #8030, adds signed-INT8 operands to gemm_a8w8_bpreshuffle and makes its FP8 path assert that XQ has WQ's dtype. The fast path checked only WQ's dtype, so an XQ of another dtype with an FP8 WQ ran the CK kernel where the custom op now raises. The fast path now declines unless XQ and WQ are both FP8. INT8 calls run FlyDSL kernels, which it never stands in for, and reach the custom op as before. #6828 also documents the INT8 contract on the custom op's body, which this PR keeps as the private _gemm_a8w8_bpreshuffle_op, while the public gemm_a8w8_bpreshuffle had a one-line, FP8-only docstring. The docstring moves unchanged to the public function. op_tests/test_a8w8_eager.py: a BF16 XQ with an FP8 WQ reaches the custom op and its "dtypes must match" assertion. With the new check removed, the call takes the fast path and the test fails.
…function Which kernel a bpreshuffle GEMM runs was decided twice: in _gemm_a8w8_bpreshuffle_into for the custom op, and again in the eager fast path, which repeated the FP8 table lookup and the gfx1250 exception for untuned shapes. #6828 just changed that routing on main (INT8), and every such change had to be made in both places. _bpreshuffle_kernel(m, n, k, w_k, q_dtype) now makes the decision and returns it as data: the tuned row (a CK, CKTile or FlyDSL row runs that libtype with its splitK) and, without one, the FlyDSL kernel the shape falls back to (INT8's default 4-wave kernel, the closest fitting one on gfx1250); with neither, the default CK kernel runs. _gemm_a8w8_bpreshuffle_into launches what it returns, pads a K-padded XQ, logs the fallback warnings and wraps default-kernel errors as before. The fast path calls the CK entry directly for a CK row, or with splitK 0 when there is neither a row nor a fallback, and declines otherwise; it has no gfx1250 check of its own. The kernel choice, the warnings and the error text are unchanged: with the launchers, the table lookup and the arch replaced by recorders, the op path makes the same calls before and after this commit in all 168 cases of a grid of rows (CK with and without split-K, CKTile, FlyDSL, an unparsable FlyDSL name, asm, none) x FP8 / INT8 x K-padded or not x gfx942 / gfx1250 x a failing CK launch. Host time of one gemm_a8w8_bpreshuffle call on MI308X, weighted over the four tuned CK shapes of Qwen3.8-Flash-Next PTPC FP8 at TP2, three alternating runs each, before -> after this commit: fast path 13.89 -> 14.13 us warm, 29.16 -> 29.11 us cold; custom op through the dispatcher 21.84 -> 22.23 us warm, 44.57 -> 43.96 us cold. The public call on main is 22.59 / 45.56 us.
* style: ruff-format the loading backends and runner utils Upstream lints whole changed files since the pre-commit CI (#798, #806), and the AITER INT8 change touches these files. Formatting only, plus one trailing whitespace fix in runner_utils.py; no behavior change. * feat(rocm): add AITER INT8 GEMMs for Wan2.2 T2V Adds xFuserAiterInt8Linear, an INT8 linear on AITER's signed-INT8 gemm_a8w8_bpreshuffle (the gfx950 4-wave FlyDSL GEMM, ROCm/aiter#6828), and an AITER INT8 format backend that --gemm_quantization int8 selects on ROCm. - Activations are quantized per row with round-to-nearest in a Triton kernel; weights are quantized per output channel and preshuffled once at load. Bias is added after the GEMM. - The backend is available when AITER has #6828 and the GPU is gfx950; otherwise the probe reports why. - Only Wan2.2 T2V opts in (use_aiter_int8_gemms), for both transformers. Models that declare TorchAO INT8 only, such as Z-Image, are not routed to AITER. * fix(rocm): import Triton only where it is installed PR CI installs the CPU torch wheel, which has no Triton, so importing xfuser.model_executor.layers failed and no CPU test could be collected. Guard the import the way xfuser/core/vsa_attention.py does. * test(rocm): tighten the AITER INT8 tests - Restore upstream's cross-product contract test: a model with TorchAO INT8 only must not get AITER INT8. - Fold the INT8 FSDP case into the MXFP4 FSDP test and drop the test that only asserted descriptor constants. - Test that Wan2.2 T2V accepts --gemm_quantization int8 and Wan2.1 T2V rejects it, instead of asserting capability flags. - Fold the zero-input case into the linear test as zero padding rows. * fix(rocm): name the missing AITER module, not a PR number, when INT8 is unavailable * fix(wan): check projection types before their weights in the SDMA Q/K-first check _qk_first_eligible read weight.shape on to_q/to_k/to_v before checking that they are nn.Linear. AITER INT8 linears have no weight, so --gemm_quantization int8 with --ulysses_a2a sdma --ulysses_sdma_overlap_qkv raised AttributeError instead of falling back to the standard path. * fix(rocm): declare AITER INT8 independently of TorchAO INT8 use_int8_gemms now declares only TorchAO INT8 and use_aiter_int8_gemms only AITER INT8, so Wan2.2 T2V no longer accepts --gemm_quantization int8 on CUDA, where it was never run. The CLI accepts int8 for a model that declares either backend, and the load contract refuses the one it lacks. The model reference names the INT8 platform (CUDA or ROCm gfx950) instead of a check mark, and INT8 joins FP4 in select_runtime_quantization's routing branch. * refactor(rocm): share the Linear-replacement walker between FP8 blockscale and INT8 - One _replace_linear_leaves walk for quantize_linear_layers_to_fp8_blockscale and quantize_linear_layers_to_aiter_int8. INT8 now frees the BF16 weight before quantizing, as FP8 blockscale did. - INT8 picks layers with AITER's supports_4wave_int8_shape instead of a local copy of its rules, and its unit test goes with the copy. - Drop offload_to_cpu from the INT8 adapter; the INT8 placement never passed it.
Summary
Closes #6827.
Add a public gfx950 FlyDSL signed-INT8 GEMM to
aiter.gemm_a8w8_bpreshuffle, with tuned 256-CU dispatch, a correct untunedfallback, and AOT/run-only support.
The kernel uses a 256x256x128 workgroup tile, one wave per SIMD,
v_mfma_i32_16x16x64_i8with INT32 accumulation, two LDS buffers, and FP32row/column scales before BF16 stores.
Motivation
AITER already ships gfx950 INT8 ASM bpreshuffle kernels. This change adds a
distinct FlyDSL implementation through
gemm_a8w8_bpreshuffle, with highermeasured throughput, tuned and untuned routing, tests, and deployable AOT
support.
Changes
exceeds active CUs; use non-persistent dispatch for K=13824 and general
supported shapes.
rows that run on FlyDSL at the physical K (4-wave rows, and generic rows the
FlyDSL launcher accepts at that M and K) and otherwise takes the 4-wave
fallback, because the generic launcher's CK fallback is FP8-only.
gemm_a8w8_ASMskips the FlyDSL rows and uses every other INT8 row, asbefore, also when
libtypeis blank or filled in by a table merge;--run_configroutes INT8 rows the same way.before output allocation and config lookup.
operands, so the tuned rows compile into the cache.
slp-vectorize-once-usedoff for the kernel, as every gfx950 FlyDSL GEMMdoes since the FlyDSL 0.4.1 pin.
op_tests/test_gemm_a8w8.py, tuner candidates inop_tests/tuning_tests/test_tuner_infra.py, and the XCD count intests/test_chip_info_xcds.py.Public contract
XQ,WQ: contiguous signedtorch.int8;WQusesshuffle_weight(..., layout=(16, 16)).K >= 256,K % 128 == 0,K_w % 128 == 0,N % 16 == 0. A K-paddedWQ(K_w > K) dispatches atK_w.M*N*2,M*K_wandN*K_wmust each be below2**31.K_w <= 130944: the kernel accumulates in INT32, andK_wfull-rangeproducts of
128 * 128must stay below2**31.biasmust beNone. INT8 calls with a bias tensor are rejected beforedispatch; callers add bias after the GEMM.
Performance
Measured sequentially on one fixed physical AMD Instinct MI355X with FlyDSL
0.5.0:
ASM baseline (best ASM kernel for all three shapes):
_ZN5aiter42I8gemm_bf16_perTokenI8_BpreShuffle_160x128EThese numbers come from a standalone CUDA-graph harness that is not part of
this PR. In the repository,
op_tests/test_gemm_a8w8.pytimes the same kernel(its
ck bpreshuffle uscolumn) against CK:It uses its own timing, so its numbers differ from the table, and on gfx950 it
does not time the INT8 ASM kernels.
128-CU support
Runtime and offline AOT derive or accept the 128-CU / 4-XCD topology
explicitly, and the persistent and non-persistent
_xcd4variants arebit-exact against the reference. No 128-CU hardware was available, so this PR
includes no unmeasured 128-CU tuning rows or performance claims. Those devices
use the correct untuned fallback until separately measured rows are available.
Validation
See "Validation and unverified scope" under PR Self-Review.
PR Self-Review
Reviewed revision
d18737f
Behavior and intent
gemm_a8w8_bpreshufflenow accepts signed INT8XQ/WQand runsthem on the new 4-wave FlyDSL kernel: the three tuned 256-CU rows, and a
logged 4-wave fallback for any other supported shape. Before, INT8 calls
failed its FP8-only assertion, and INT8 bpreshuffle was available only
through the ASM kernels, which are 1.78-1.92x slower on the measured shapes.
gemm_a8w8_ASMuses every INT8 row of the sharedtable except the FlyDSL ones, as before this PR, and
--run_configroutesINT8 rows the same way.
Validation and unverified scope
All on MI355X (gfx950, 256 CUs) with FlyDSL 0.5.0, the current main pin.
At a617357:
python op_tests/test_gemm_a8w8.py --no-flydsl-csv --no-legacy: INT8 4-wavecorrectness passed (4 bit-exact shapes, padded K, signed extrema including
all-(-128) operands at K=130944, zero rows, contract rejections including
K=131072,
torch.compile, CUDA graph and a side stream), and so did theINT8 dispatch checks. When the test sees gfx942, both log as skipped and the
script exits 0.
python op_tests/tuning_tests/test_tuner_infra.py: the four FlyDSLbpreshuffle candidate tests pass. Two
TestGroupedFmoeResultToCsvtestserror the same way on current main.
pytest tests/test_chip_info_xcds.py tests/test_flydsl_aot_replay.py: 43passed, including
test_int8_csv_rows_reach_the_4wave_kernel_through_public_replay.python -m aiter.aot.flydsl.gemm --csv <the three INT8 rows>into anempty cache (3 rows and 29 bisected smaller M, no failures), then
--check.The three tuned shapes ran bit-exact with
FLYDSL_RUNTIME_RUN_ONLY=1, and anuntuned shape was refused.
_xcd4variants are bit-exact againstthe reference.
alternating rounds per side on one GPU: the medians are within 0.2% on all
three shapes. The final ISA has the same instruction sequence apart from two
address additions scheduled earlier, the same AGPR and SGPR counts, no
spills, and 4 fewer VGPRs at K=5120.
Unverified:
op_tests/test_gemm_a8w8.pyon this branch.PR-specific question
Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
_check_int8_bpreshuffle_contractraisesNotImplementedErroron any other arch before dispatch.XQandWQbothtorch.int8, FP32 per-row and per-columnscales, BF16 output,
bias=None; anything else raises before dispatch. FP8inputs never take the INT8 path.
K_w >= K, K_w <= 130944 (so full-range products accumulate in INT32) and N a
multiple of 16, with
M*N*2,M*K_wandN*K_wbelow2**31. Tuned rowsare looked up at the physical K_w.
in the public checker before output allocation, config lookup or launch.
INT8 dispatch uses a tuned row only if it runs on FlyDSL at the launch M and
K (a 4-wave row, or a generic row whose name parses and whose M and K the
launcher accepts); any other row takes the 4-wave fallback, so INT8 operands
never reach the FP8-only CK fallback.
Changed op tests
op_tests/test_gemm_a8w8.py:run_int8_4wave_ci_correctness()runs from theCI script entry and checks INT8 bit-exactly on 4 shapes through the untuned
fallback, padded K_w, signed extrema (including all-(-128) operands at the
INT32 K limit, K=130944) and zero rows, plus contract rejections (including
the next K),
torch.compile, CUDA graph capture and a side stream.run_int8_4wave_dispatch_checks()runs next to it with fake tuned rows andlaunches: the tuned-row lookup at the physical K, the 4-XCD fallback on a
128-CU tuning miss, use of only tuned rows that run on FlyDSL,
gemm_a8w8_ASMskipping only FlyDSL rows (blank, NaN,0and missinglibtypestay ASM), contract rejections before thetuned-row lookup, and the 4-wave compile guards. Both run only on gfx950.
The INT8 case generator and exact reference (FP32 GEMM of the INT8 values
with the FP32 scales, rounded to BF16) live in this file.
test_gemmnowruns per-token INT8 through bpreshuffle where the 4-wave kernel supports the
shape. No other op test reaches the INT8 path of
gemm_a8w8_bpreshuffle.op_tests/tuning_tests/test_tuner_infra.py:TestFlydslA8w8BpreshuffleCandidatesalso checks theint8_4wavepipelineorder, the names of generic INT8 candidates, and the K, topology and
persistence of the 4-wave candidates.