Repository navigation
[ROCm][Inductor] Fix CKTILE float16 autotune dtype mismatch - #193902
jagadish-amd wants to merge 5 commits into
Conversation
ops() named half-precision instances "FP16" while check_dtypes compared against _TORCH_DTYPE_TO_CK[float16] == "F16", so every fp16 kernel was silently dropped. Rename ops() and ck_dtype_to_size to "F16" to match the existing C++ alias. This is a follow-up to the CK-Tile inductor GEMM fix pytorch#189646 Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193902
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 3d379af with merge base 4863ab7 ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
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. |
|
@pytorchbot label "topic: not user facing" |
|
@claude review these changes |
|
Claude finished @jansel's task in 9m 24s —— View job The dtype-label rename is correct and the new fp16 subtest is a genuine regression test, but flipping Full review (AI-generated by Claude, reviewed output below)PR Review: #193902SummaryRenames the half-precision CK-Tile dtype label from Code QualityThe label
That duplication is the bug. Testingbf16 compile coverage is lost. The regression test is far more expensive than it needs to be. I traced the new The e2e RecommendationRequest Changes — narrowly, on the bf16 coverage regression in |
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
jeffdaily
left a comment
There was a problem hiding this comment.
Reviewed this with an AI assistant; findings below are all in the new test, the production fix looks right to me. Expanding the dtype axis is fine, don't trim it — the extra compile time is acceptable.
Requesting changes. The production fix is correct: _TORCH_DTYPE_TO_CK[torch.float16]
is "F16", which matches both check_dtypes and the `using F16 = ck_tile::half_t;`
alias in globals(). Pre-fix, "FP16" instances would not have compiled even if they
had passed the filter. All the problems below are in the test.
1. test_ck_backend.py:818 - `assertEqual(labels, sized)` can never fail. ops() now
builds its dtype list from ck_dtype_to_size (ck_tile_universal_gemm_template.py:190),
so labels is by construction exactly set(ck_dtype_to_size). Only the
`labels - mapped` assertion carries any signal.
2. The test does not check what ck_tile_template.py:24 says it checks. That comment
says the keys must match the C++ aliases in globals(), but the test compares
against _TORCH_DTYPE_TO_CK.values() = {F32, F64, F16, BF16, I32, I8, F8, BF8},
while globals() only declares F8, BF8, F16, F32, BF16. emit_ck_instance splices
the label straight into `using ADataType = {{datatype_a}};`
(ck_tile_universal_gemm_template.py:676-678), so a label like I8 or F64 would pass
this test and produce HIP that does not compile. Please hoist the aliases in
globals() into a dict, render globals() from it, and assert against that.
3. ck_dtype_to_size now does two unrelated jobs. It lives on the base CKTileTemplate
and is documented as bytes-per-element for alignment math (check_alignments,
check_block_tile_size). After this PR its keys also decide which universal GEMM
instances exist. A future ck_tile template (scaled mm, conv) that needs fp8
alignment math would add F8/BF8 to that table and silently generate a full fp8
GEMM catalog that has never been compile-tested. Declare the GEMM dtype list
explicitly in ck_tile_universal_gemm_template.py and keep the dependency one-way:
assert in the test that every GEMM dtype has a size entry, rather than deriving
the catalog from the size table.
4. test_ck_backend.py:627 and :636 - the `dtype=torch.float16` defaults on
_make_template and _find_ck_tile_op are dead; all five call sites pass dtype
explicitly. Leaving the default means the next test added to this class silently
gets fp16-only coverage, which is how bf16 coverage was lost in the first revision
of this PR. Make dtype a required parameter.
5. test_ck_backend.py:625 - `self._ck_tile.ops.cache_clear()` has no effect. Nothing
in the suite mutates ck_dtype_to_size, so this just rebuilds the instance catalog
before every test in the class. Drop it, or say which test needs it.
6. The five-line @parametrize("dtype", ...) block is repeated four times (:820, :838,
:870, :894) plus once at :345. Hoist it to a module-level
`_parametrize_dtype = parametrize("dtype", (torch.float16, torch.bfloat16),
name_fn=_dtype_test_name)` and apply it as a decorator. Reuse across functions is
safe; _TestParametrizer.__call__ only writes to the function it decorates.
Not asking for any change to the dtype coverage itself. Parametrizing
test_offered_instance_compiles over both dtypes is right, keep it.
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
The consistency test added in this PR asserts relations that hold by construction and cannot fail. ops() builds its dtype list from GEMM_DTYPES, so labels == set(GEMM_DTYPES) is an identity; globals() renders from _CK_DTYPE_ALIASES, so comparing the rendered aliases back to that dict is the same identity. Reproducing the original mistake under the new structure, GEMM_DTYPES = ("FP16", "BF16") with a matching size-table key, leaves the test green.
The seam that actually broke is unguarded: emit_ck_instance splices the dtype label straight into `using ADataType = {{datatype_a}};`, so a label with no rendered alias emits HIP that does not compile. Asserting labels <= cpp_aliases covers that, is not an identity because the two sides come from the instance catalog and from the rendered source respectively, and subsumes the `cpp_aliases - {"Row", "Col"}` fixup, which hardcoded the current contents of CKTileGemmTemplate.globals() and would have failed spuriously the next time that method gained a `using`.
Kept the labels == set(GEMM_DTYPES) assertion even though it is an identity today. It is the only line tying ops() output to the declared catalog, and it costs nothing if a future instance family hardcodes a dtype literal instead of iterating GEMM_DTYPES. The alias comparison was different: its only reachable failure mode was a false positive.
Also renders the alias block through writeline rather than hand-indenting each line by 16 spaces so that IndentedBuffer.splice's textwrap.dedent strips them back off; the emitted source is byte-identical. The ck_dtype_to_size comment claimed its keys must match _CK_DTYPE_ALIASES, which is false in the direction it reads, {F16, BF16} against five aliases, and enforced by nothing; it now says what the table is for and points at GEMM_DTYPES as the catalog.
Test Plan:
Ran the CK-Tile template tests on gfx90a, ROCm 7.14:
```
python test/inductor/test_ck_backend.py TestCKTileUniversalGemmTemplate
```
37 tests, 13 skipped. The 12 test_offered_instance_compiles cells skip without a configured rocm.ck_dir; they exercise hipcc in CI.
Confirmed the tightened assertion catches the bug this PR fixes by reintroducing it, GEMM_DTYPES = ("FP16", "BF16") plus the matching ck_dtype_to_size key, and rerunning:
```
python test/inductor/test_ck_backend.py TestCKTileUniversalGemmTemplate.test_ops_dtype_labels_agree_with_maps
```
Before this commit: OK. After: AssertionError, {'FP16', 'BF16'} not <= {'BF8', 'F8', 'Col', 'F32', 'BF16', 'Row', 'F16'}.
Authored with the assistance of Claude.
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…193902) Fix CK-Tile float16 autotune silently dropping all fp16 GEMM kernels. ops() named half-precision instances "FP16" while check_dtypes compared against _TORCH_DTYPE_TO_CK[float16] == "F16", so every fp16 kernel was filtered out before autotuning. Rename catalog labels to "F16" to match the existing C++ alias in globals(). Also decouple the universal GEMM dtype catalog from ck_dtype_to_size. GEMM_DTYPES explicitly declares which dtypes get GEMM instances. ck_dtype_to_size remains for alignment and padding math only. _CK_DTYPE_ALIASES is the single source of truth for C++ using aliases, and globals() renders from it. Tests parametrize fp16 and bf16 across template emit and compile coverage, and assert that ops() implements GEMM_DTYPES, that rendered globals() matches _CK_DTYPE_ALIASES, and that every GEMM dtype has a size-table entry. This is a follow-up to the CK-Tile inductor GEMM fix pytorch#189646 Authored with Cursor Grok 4.6. Pull Request resolved: pytorch#193902 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
Fix CK-Tile float16 autotune silently dropping all fp16 GEMM kernels. ops() named half-precision instances "FP16" while check_dtypes compared against _TORCH_DTYPE_TO_CK[float16] == "F16", so every fp16 kernel was filtered out before autotuning. Rename catalog labels to "F16" to match the existing C++ alias in globals().
Also decouple the universal GEMM dtype catalog from ck_dtype_to_size. GEMM_DTYPES explicitly declares which dtypes get GEMM instances. ck_dtype_to_size remains for alignment and padding math only. _CK_DTYPE_ALIASES is the single source of truth for C++ using aliases, and globals() renders from it.
Tests parametrize fp16 and bf16 across template emit and compile coverage, and assert that ops() implements GEMM_DTYPES, that rendered globals() matches _CK_DTYPE_ALIASES, and that every GEMM dtype has a size-table entry.
This is a follow-up to the CK-Tile inductor GEMM fix #189646
Authored with Cursor Grok 4.6.
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben