Repository navigation
Conversation
…ithout untuned CSV (Refs #6255) The a4w4_blockscale tuner dispatched every CK instance and ASM kernel for every shape. On N=96, K=5120 the CK instances (NPerBLOCK >= 128, preshuffled B, no N padding) fault the worker ("Memory access fault by GPU"), and four ASM kernels (192x256, 224x256, 256x256 split-K, 128x512 split-K) return wrong results unless N % tile_N == 0. The default ASM heuristic could pick one of them (wrong output at N=96, M=48/64). - Shared predicates a4w4_ck_shape_legal / a4w4_asm_shape_legal / a4w4_kernel_shape_legal in aiter/ops/gemm_op_a4w4.py, used by the tuner candidate loops and by gemm_a4w4 (an illegal tuned row is ignored with a one-time warning). - f4gemm kernel table gets a full_n_tile column; the C++ default selection reads it instead of the hard-coded 128x512 case. - gemm_a4w4 falls back to the default ASM selection, with a one-time warning, when a CK row names an instance that is not in the compiled registry. - --run_config <tuned_csv> no longer needs the default untuned CSV unless --compare or --all is given. - CPU tests: op_tests/tuning_tests/test_a4w4_shape_legality.py.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…t a partial N tile (192x256, 224x256) A gfx950 sweep of every f4gemm bpreshuffle kernel at N = 32..1536 (K = 1024, 5120) with a relative-L2 check against torch shows that only 192x256 and 224x256 give wrong results when N % tile_N != 0. The split-K 256x256 and 128x512 kernels and the persistent 256x256 kernel stay at the bf16 split-K noise floor, so full_n_tile is cleared for them (the earlier 1% element check flagged split-K rounding). The C++ default selection keeps its previous 128x512 rule. No committed tuned row falls back any more. Document the CK partial-tile over-read as a known gap. Store the new test with LF line endings. Refs #6255
…he heuristic here Move the CK tuner / run-time shape legality (gemm_op_a4w4.py, gemm_a4w4_blockscale_tune.py, the tuner README) and the --run_config base-tuner fix out of this PR, which stays the ASM part (one backend per PR): the full_n_tile column, hsa/codegen.py giving the field a zero default when a table has no such column, and the get_heuristic_kernel read. The CK part continues as a PR stacked on this branch and the base-tuner part as its own PR. Replace the legality test by test_a4w4_asm_full_n_tile.py. Refs #6255
Refs #6255 (the 128-CU
cu_num=128tuning coverage stays open, this PR does not add tuned rows).Part of a stack split by backend (CONTRIBUTE.md: one backend per PR): this PR is the ASM part. The CK part (tuner and run-time shape legality, run-time fallbacks) is a new Draft PR stacked on this branch. The
--run_configbase-tuner fix is #8857.Summary
The default ASM selection of
gemm_a4w4(get_heuristic_kernel) can pick an f4gemm kernel that gives wrong results for the shape. This PR marks the two kernels that do (192x256, 224x256) in the f4gemm table and makes the heuristic skip them unlessN % tile_N == 0.Motivation
get_heuristic_kernelonly excluded 128x512 at a partial last N tile (a hard-coded rule). A sweep of every bpreshuffle f4gemm kernel shows that 192x256 and 224x256 are the kernels that return wrong results at a partial N tile; the heuristic can still pick them. Onmain, the default selection is wrong for M=4097, N=2400 at K = 1024, 5120 and 7168 (relative L2 error 0.09-0.23, measured earlier with themainversions of the two files).Changes
hsa/gfx950/f4gemm/f4gemm_bf16_per1x32Fp4.csv: newfull_n_tilecolumn. It is 1 only for 192x256 and 224x256: a sweep of all 35 bpreshuffle kernels at N = 32..1536 (K = 1024, 5120) gave a relative L2 error of 0.3-0.9 for them whenN % tile_N != 0, and 4e-3 or less (bf16 split-K noise) for every other kernel.hsa/codegen.py:DEFAULT_COLUMNS = {"f4gemm": {"full_n_tile": 0}}. A launcher reads the field, so it exists in the generated struct with value 0 even when no manifest of the module (for example another arch) has the column, and the C++ always compiles.csrc/py_itfs_cu/asm_gemm_a4w4.cu:get_heuristic_kernelskips afull_n_tilekernel unlessN % cfg.tile_N == 0. Its earlier hard-coded 128x512 rule (N % 512 == 0) stays as it was onmain; the sweep found 128x512 correct at partial N, but this PR does not lift it.op_tests/tuning_tests/test_a4w4_asm_full_n_tile.py(new, CPU only) and its entry in.github/scripts/split_tests.sh.No Python run-time code, tuner or CK file changes here. Overlap with other work: #8825 and #7979 touch the a4w4 tuner and
gemm_a4w4, which this PR does not.Performance (if applicable)
Not a performance change. The heuristic only drops two kernels at a partial last N tile, where they gave wrong results.
Testing
Tested on MI350X (gfx950), see the Self-Review. Not tested on the MI350P of the issue.
Documentation
The
full_n_tilemeaning is documented in the header comment of the f4gemm CSV and in the comment atDEFAULT_COLUMNS; no user-facing option changes.Dependencies
Breaking Changes
None. For shapes with
N % tile_N == 0the selection is unchanged; for a partial last N tile the two flagged kernels are no longer chosen, so the default selection now returns correct results instead of wrong ones.PR Self-Review
Reviewed revision
df07919
Behavior and intent
The default ASM selection of
gemm_a4w4never picks a kernel that is wrong for a partial last N tile. Which kernels those are is data in the f4gemm table (full_n_tile), read by the C++ heuristic, andhsa/codegen.pyguarantees the field exists on every arch. The 128x512 rule keeps its previous behavior.Validation and unverified scope
Hardware: mi350x8, MI350X (gfx950, 256 CU), image
rocm/atom-dev:sglang-latestwith this branch (git archiveof the reviewed revision) overlaid, the ASM module rebuilt from it.gemm_a4w4_asm, no kernel name,log2_k_split=-1), re-run on this revision: 312 shapes (K = 1024, 5120, 7168; M = 1, 7, 33, 100, 257, 1000, 4097, 16384; N = 32..2400, 13 values), error as relative L2 against torch: 0 shapes above 2e-2, worst 6.5e-3. With themainversions ofasm_gemm_a4w4.cuand the table (earlier run): 3 shapes wrong (M=4097, N=2400, K = 1024, 5120, 7168: error 0.09-0.23), the selection picking afull_n_tilekernel at a partial N tile.op_tests/tuning_tests/test_a4w4_asm_full_n_tile.py, 4 passed.main), clean.Not verified:
full_n_tilecolumn and get 0 fromcodegen.py(covered by a codegen unit test, not by a build on another arch).PR-specific question
full_n_tileis a new column of the f4gemm manifest. Do the maintainers prefer it there (one table, read by the codegen and the heuristic), or hard-coded in the heuristic next to the existing 128x512 rule?Changed op tests
op_tests/tuning_tests/test_a4w4_asm_full_n_tile.py(new, CPU only, registered insplit_tests.sh, runs as a script throughunittest.main()):full_n_tilecolumn marks exactly 192x256 and 224x256 among the bpreshuffle kernels, and they are not split-K or persistent;hsa/codegen.pygenerates thefull_n_tilefield and the flags match the table;No other op test changes.