Repository navigation
[ROCm] Add support for fp32 configs for CK-Tile Group GEMM backend - #202073
TheRealMichaelWang wants to merge 9 commits into
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Findings (4): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202073
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 Cancelled Jobs, 2 Unrelated Failures, 1 Unclassified FailureAs of commit 6ba0475 with merge base aa6d3e9 ( NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following jobs failed, but the AI CI Advisor judged the failures not to be evidence against this change:
UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
CANCELLED JOBS - The following jobs were cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
e2665c9 to
ab084bc
Compare
Adds a CkTileGroupGemmConfigs<GFX950, ck_tile::fp32_t> specialization and lets
ck_tile_group_gemm_supported accept fp32 inputs on gfx950 (gfx942 has no fp32
configs, so fp32 there keeps falling back to hipBLASLt).
fp32 fragments take twice the registers of bf16, so four-wave tiles with 256
rows or columns spill at K_Tile 32, and the backward layouts read transposed
operands from LDS with narrow loads. Eight-wave tiles cut both costs: dX/dW
went from ~73-136 to ~97-148 TFLOPS in the standalone harness. The candidate
lists came from a sweep of ~220 configs (tile shape, wave count, fp32 MFMA warp
tile, K_Tile, CK pipeline and scheduler), with load_cost selection simulated
over every candidate subset; the chosen lists are within ~2% of a per-shape
best pick, and adding the 30 best other configs improves the best by <=1%.
fp32 ck_tile is only faster than hipBLASLt on small experts (mostly M=512):
forward on 64/396 Primus MoE shapes (up to 1.41x), dX and dW on ~10 each (up
to 1.17x); elsewhere it is 0.81-0.98x. rocprofv3 shows the same MFMA work on
both backends; the gap is LDS: dX hits bank conflicts on ~31% of LDS-active
cycles, and dW uses a 128x128 tile (hipBLASLt: 224x256) with narrow transposed
reads, 3.5x the LDS instructions. Neither is reachable through configs, so a
dispatcher should route fp32 to ck_tile only for small per-expert sizes.
test_grouped_gemm_rocm_backend now also runs fp32 with atol=1e-4, rtol=1e-5.
ck_tile accumulates each output over K in one fp32 accumulator; against a
float64 reference its error matches an emulated sequential fp32 sum, while
hipBLASLt kernels that split K have up to 2x lower RMS error on long K, which
pushed a few elements per tensor just past the default atol=1e-5.
Test Plan:
python3 test/test_linalg.py -k TestGroupedMM -v
python3 test/test_matmul_cuda.py -k grouped -v
On MI355X (gfx950): 1048 passed, 0 failed, 835 skipped (CPU/MPS variants and
the existing unaligned-case skips) for TestGroupedMM, including 192 fp32
test_grouped_gemm_rocm_backend cases; 1 passed for test_matmul_cuda. These ran
on a build with `float` in place of the identical `ck_tile::fp32_t` alias.
Performance and accuracy (agent_space scripts, not part of this change):
python3 agent_space/eval/fp32_bench.py fp32_hipblaslt.csv
ROCM_ALLOW_GROUP_GEMM_CK_TILE=1 python3 agent_space/eval/fp32_bench.py fp32_cktile.csv --check
All ck_tile fp32 outputs over the 396 shapes matched hipBLASLt to 8.5e-6
relative.
This change was authored with the help of an AI assistant (Claude Code).
ab084bc to
faead33
Compare
|
These are the performance results for the CK-tile group gemm backend and the default hipBLASlt based backend, for fp32. Note G=2^30. Note the speedup shows the speedup of the CK-tile backend over the default backend. gfx950 on MI355X perf
gfx942 on MI300X perf
|
jeffdaily
left a comment
There was a problem hiding this comment.
Three things need to change before this can go in; details below.
My agent came up with this analysis, but I've read and approved it.
test_grouped_gemm_ck_tile_config_coverage(test/test_linalg.py) only runs bf16, and_GROUPED_MM_CK_TILE_CONFIGSonly lists bf16 configs. The 20 new fp32 configs use different tile shapes, so nothing shows thattest_grouped_gemm_rocm_backendever launches them (for example the gfx950 256x256x16 eight-wave forward or the gfx942 128x64x64). Please parametrize the coverage test over dtype and add the fp32 expected config sets for each (arch, CUs).- GroupedBlas.cpp: the new
isGPUArch({"gfx942", "gfx950"})inck_tile_group_gemm_supportedduplicates the check its only caller makes just before calling it, and costs a second device-property lookup on every grouped_mm call. Please drop it. Also, the comment at ck_tile_group_gemm.hip:62 ("Only a 16-bit C vector width of 1 needs NoSplitKEpilogue") is now wrong: the fp32AnyShapetakes that path too.- In your fp32 table, ck_tile backward is 0.83-0.89x of hipBLASLt for every bucket above 4G, and forward drops below 1x above 128G. Which arch is the table from? Please add gfx942 numbers and split backward into dX and dW.
ROCM_ALLOW_GROUP_GEMM_CK_TILEcovers all dtypes, so anyone who enables it for bf16 also gets these fp32 kernels. Either show where fp32 wins, or leave out the layouts that lose. Please also use the current PR template, with a summary and a test plan.
|
@pytorchbot review |
I reject the changes you request. You are relitigating an non-issue I have already marked resolved. The heuristics for backend selection will be added in an independent PR. This is an internal AMD project, and the plan has already been established. My agent has responded and I've reviewed the changes
|
|
@pytorchbot review |
jeffdaily
left a comment
There was a problem hiding this comment.
Fine to defer the fp32 selection heuristic and the dX/dW split to the follow-up, since everything here stays behind ROCM_ALLOW_GROUP_GEMM_CK_TILE. Please link the follow-up here when it exists. Approving; two small test fixes to make before merging:
My agent came up with this analysis, but I've read and approved it.
- test/test_linalg.py:12500: the new
self.failruns for any gfx942/gfx950 device whose (arch, CUs, dtype) key is not in the table, so the test now fails on MI300A (228 CUs), MI308X (80 CUs) and CPX partitions, where it used to skip. Please fail only when the (arch, CUs) pair is listed for another dtype but not this one, and skip when the CU count itself is unlisted. That still catches a missing dtype entry.- test/test_linalg.py:12506: the comment "the unaligned 16-bit cases _check_grouped_gemm skips" is wrong here;
_check_grouped_gemmonly skips them whennot torch.version.hip, and this test only runs on ROCm.
…ses as test_grouped_gemm_rocm_backend
Both of the requested changes to the tests have been added in 6ba0475. |
There was a problem hiding this comment.
Automated review of 6ba0475: nothing blocking; ready for human review.
The PR adds fp32 CK-tile grouped GEMM tile configs for gfx950 and gfx942, sends kFloat through ck_tile_group_gemm_supported and with_ck_type, and extends the ROCm grouped_mm correctness and config-coverage tests to fp32. Recommendation: Approve. Nothing blocks: jeffdaily's requested test fixes are in, he agreed to defer the earlier blocking point, and the remaining points are all non-blocking clean-ups.
⚪ 4 non-blocking findings
Non-blocking: fp32 ignores the TF32 / fp32_precision setting. Nothing under aten/src/ATen/native/hip/ reads it. Before this PR, fp32 grouped_mm always took _grouped_mm_fallback, which goes through at::mm_out/bmm_out to hipBLASLt. That path sets CUBLAS_COMPUTE_32F_FAST_TF32 when precision is TF32 (CublasLtUtils.h:328-332, no USE_ROCM guard). So a user who sets ROCM_ALLOW_GROUP_GEMM_CK_TILE=1 and opts into TF32 now gets IEEE fp32 on aligned shapes. This is confirmed for gfx942 (see the XF32 handling in Blas.cpp:121-134). On gfx950 it depends on hipBLASLt's xf32 support. The tests force allow_tf32 = False, so they cannot catch it. Fix: return false from ck_tile_group_gemm_supported for kFloat when TF32 is requested, or document the difference.
An earlier comment near this line has replies: #202073 (comment)
Non-blocking: the gfx950 fp32 rationale contradicts the gfx942 configs. The comment says "four-wave tiles with 256 rows or columns spill at K_Tile 32", and the reason it gives doesn't depend on the arch (fp32 fragments take twice the registers). Yet gfx942 fp32 Forward ships exactly that shape: CkTileGroupGemmConfig<256, 128, 32, 16, 16, 16, 2, 2, ...> (:299), and both arches have the same register budget. Either say this was measured on gfx950 only, or reconcile the two. Whether either tile actually spills can't be checked without a build.
Line 12462 in 6ba0475
Non-blocking: the fp32 tolerance comment overstates how tight it is (repeated at :12491). tol(atol=1e-4, rtol=1e-5) is about 10x the default fp32 atol and about 7.7x the default rtol, not "up to 2x the rounding error". The "on long K" reason conflicts with "Contractions stay small" (:12305); the longest contraction that reaches ck_tile is 224. The override also covers fp32 cases that go to hipBLASLt. Fix the comment, or apply the tolerance per case as 2d_3d_sparse_decode does (:12294).
Line 12318 in 6ba0475
Non-blocking: the tail-path comment no longer holds for fp32 (test/test_linalg.py:12303-12307). It says "eight-wave configs see 1 to 7 K tiles", which covers the one-tile Odd tail of FourWaveTailCompV3. The new K_Tile-16 eight-wave forward/dX configs only ever see 2 to 8 K tiles, so that path never runs for them. These are gfx950 RC 256x256x16, RR 256x128x16 and RR 128x128x16, and gfx942 RR 128x128x16 and RR 256x128x16. The gfx942 CR 128x128x16 8w --K dW config also sees 2 to 14 tiles, never 1. Fix: add a case with a contraction of 16, or narrow the comment to the K_Tile-32 configs.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
Withdrawn: the automated review of 6ba0475 found nothing blocking.
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 5 checks: pull / linux-jammy-py3.11-gcc11 / build, Lint / Test collect_env (without_torch, linux.24_04.4x), Lint / Test collect_env (with_torch, linux.24_04.4x), Lint / Test collect_env (older_python_version, linux.24_04.4x), trunk / win-vs2022-cpu-py3 / test (default, 11, 12, windows.4xlarge.nonephemeral) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Add tuned configs for fp32 on gfx950 and gfx942 for the group gemm CK-tile backend. This PR does not add support for mixed input types for ck-tile group GEMM, and will be added later in another PR.
Supported by @jeffdaily
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang