Skip to content

Commit 7997fd3

Browse files
authored
[executorch][cuda] Find the tuned INT4 kernel's def under its module-level name too
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * __->__ #24096 `test_a_tuned_shape_traces_only_its_picked_config` finds the user kernel in Inductor's wrapper by the exact text `def _int4_w4a16_direct_kernel(`. That only matches the wrapper's `async_compile.triton('''...''')` string form, which keeps the kernel's own name. pytorch/pytorch#200502 makes Inductor's python wrapper define each Triton kernel as module-level code by default. There, the def takes Inductor's kernel name, `_int4_w4a16_direct_kernel_0`. The test failed on its DiffTrain import, D126740082, which was reverted partly for this. The test now matches `^def <name>\w*\(` and slices back to the `user_autotune(` before that match. The decorator's `configs=[...]` still comes right before the def in both forms, so the check that only the picked config is traced is unchanged. This lands ahead of the #200502 reland. ___ @landed-with-radar-review Differential Revision: D126992211 Pull Request resolved: #24096
1 parent bafd4c0 commit 7997fd3

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎backends/cuda/tests/test_int4_quantized_gemm.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import contextlib
2121
import os
2222
import pickle
23+
import re
2324
import statistics
2425
import tempfile
2526
import types
@@ -887,10 +888,10 @@ def linear(x):
887888
)
888889
source = "\n".join(code)
889890
name = autotuner.fn.fn.__name__
890-
self.assertIn(f"def {name}(", source)
891-
block = source[
892-
source.rindex("user_autotune(", 0, source.index(f"def {name}(")) :
893-
]
891+
# A module-level kernel's def is renamed to Inductor's kernel name: name plus a suffix.
892+
kernel_def = re.search(rf"^def {re.escape(name)}\w*\(", source, re.MULTILINE)
893+
self.assertIsNotNone(kernel_def, source)
894+
block = source[source.rindex("user_autotune(", 0, kernel_def.start()) :]
894895
configs = block[: block.index("],")]
895896
self.assertEqual(configs.count("'num_warps'"), 1)
896897
_check_close(self, compiled, eager)

0 commit comments

Comments
 (0)