Skip to content

Commit eff83b1

Browse files
authored
Print static_shapes settings value along with config for accurate repro (#649)
1 parent 25a3f4e commit eff83b1

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

helion/autotuner/base_search.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ def benchmark_function(self, config: Config, fn: CompiledConfig) -> float:
135135
except Exception as e:
136136
action = classify_triton_exception(e)
137137
if action == "raise":
138-
raise exc.TritonError(f"{type(e).__qualname__}: {e}", config) from e
138+
raise exc.TritonError(
139+
f"{type(e).__qualname__}: {e}",
140+
self.kernel.format_kernel_decorator(config, self.settings),
141+
) from e
139142
if action == "warn":
140143
self.log.warning(format_triton_compile_failure(config, e))
141144
else:
@@ -182,9 +185,8 @@ def extract_launcher(
182185
return PrecompileFuture.skip(self, config, True)
183186
except Exception:
184187
log.warning(
185-
"Helion autotuner precompile error for config %r, settings %r",
186-
config,
187-
self.settings,
188+
"Helion autotuner precompile error for %s",
189+
self.kernel.format_kernel_decorator(config, self.settings),
188190
exc_info=True,
189191
)
190192
raise
@@ -240,10 +242,11 @@ def autotune(self) -> Config:
240242
self.log.reset()
241243
best = self._autotune()
242244
end = time.perf_counter()
245+
kernel_decorator = self.kernel.format_kernel_decorator(best, self.settings)
243246
self.log(
244247
f"Autotuning complete in {end - start:.1f}s after searching {self.counters['benchmark']} configs.\n"
245248
"One can hardcode the best config and skip autotuning with:\n"
246-
f" @helion.kernel(config={best!r})\n",
249+
f" {kernel_decorator}\n",
247250
level=logging.INFO + 5,
248251
)
249252
if self.settings.print_output_code:

helion/runtime/kernel.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ def configs(self) -> list[Config]:
382382
"""
383383
return self.kernel.configs
384384

385+
def format_kernel_decorator(self, config: Config, settings: Settings) -> str:
386+
"""Return the @helion.kernel decorator snippet capturing configs and settings that influence Triton code generation."""
387+
return (
388+
f"@helion.kernel(config={config!r}, static_shapes={settings.static_shapes})"
389+
)
390+
385391
def to_triton_code(
386392
self, config: ConfigLike | None = None, emit_repro_caller: bool = False
387393
) -> str:
@@ -432,9 +438,8 @@ def compile_config(
432438
module = PyCodeCache.load(triton_code)
433439
except Exception:
434440
log.warning(
435-
"Helion compiler triton codegen error for config %r, settings %r",
436-
config,
437-
self.settings,
441+
"Helion compiler triton codegen error for %s",
442+
self.format_kernel_decorator(config, self.settings),
438443
exc_info=True,
439444
)
440445
raise
@@ -563,7 +568,8 @@ def _implicit_config(self) -> Config | None:
563568
return configs[0]
564569
if len(configs) == 0 and self.kernel.settings.use_default_config:
565570
config = self.config_spec.default_config()
566-
print(f"Using default config: {config}", file=sys.stderr)
571+
kernel_decorator = self.format_kernel_decorator(config, self.settings)
572+
print(f"Using default config: {kernel_decorator}", file=sys.stderr)
567573
return config
568574
return None
569575

0 commit comments

Comments
 (0)