Skip to content

[Enhancement] Add eager-mode support for tilelang.autotune#1906

Merged
SiriusNEO merged 3 commits intotile-ai:mainfrom
ColmaLiu:autotune-0306
Mar 12, 2026
Merged

[Enhancement] Add eager-mode support for tilelang.autotune#1906
SiriusNEO merged 3 commits intotile-ai:mainfrom
ColmaLiu:autotune-0306

Conversation

@ColmaLiu
Copy link
Copy Markdown
Contributor

@ColmaLiu ColmaLiu commented Mar 6, 2026

Currently @tilelang.autotune only works with lazy mode kernels. This PR extends @tilelang.autotune to better support eager mode.

Summary by CodeRabbit

  • New Features

    • Added compile() for direct kernel compilation.
    • Introduced lazy/eager execution modes for autotuning.
    • Enhanced kernel cache to store both kernel and chosen configuration.
    • Autotuner now saves/loads an out_idx.json to preserve selected output index.
  • Tests

    • Added end-to-end autotuning tests for a tiled matrix-multiply (including compile path and symbolic/dynamic-dimension cases).

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 6, 2026

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 6, 2026

📝 Walkthrough

Walkthrough

Adds a new end-to-end TileLang autotuning test for a tiled matmul and enhances the autotuner with argument normalization, a public compile() API, lazy/eager execution modes, and persistent out_idx save/load behavior.

Changes

Cohort / File(s) Summary
New autotune tests
testing/python/autotune/test_tilelang_autotune_eager_mode.py
Adds an end-to-end TileLang autotuning test module: CPU/PyTorch reference, config generator, JIT/autotuned tiled GEMM kernel, orchestration helpers, and three test cases (autotune, compile-only, symbolic dimension).
Autotuner persistence
tilelang/autotuner/param.py
Adds OUT_IDX_PATH = "out_idx.json", writes out_idx.json when saving, reads it when loading to override compile args, and logs save/load of the out_idx file.
Autotuner core / API
tilelang/autotuner/tuner.py
Introduces _normalize_value, normalizes kernel args/kwargs for stable keys, expands internal kernel parameter shape, updates set_kernel_parameters signature, changes __call__ flow to support lazy vs eager modes and returning kernels, adds compile() method, and adjusts caching to store kernel+config.
Minor doc updates
testing/python/autotune/test_tilelang_autotune.py, testing/python/autotune/test_tilelang_autotune_with_inputs.py
Docstring type hints updated from numpy to torch in reference tests; no behavioral changes.

Sequence Diagram(s)

sequenceDiagram
  participant Test as Test Runner
  participant AT as AutoTuneImpl
  participant JIT as JITCompiler/Cache
  participant FS as Disk (out_idx.json)

  Test->>AT: call (args, kwargs) or compile(...)
  AT->>AT: _normalize_value(args/kwargs)
  AT->>AT: compute cache key
  AT->>JIT: check cache / compile kernel
  JIT-->>AT: kernel + selected_config
  AT->>FS: save out_idx.json (on save)
  FS-->>AT: load out_idx.json (on load)
  AT-->>Test: return kernel (compile mode) or execute and return result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • LeiWang1999
  • kurisu6912
  • tzj-fxz

Poem

🐰 I hop through configs, bright and bold,

Tiles and stages, shared memory gold.
Out_idx saved, a tidy little tune,
Compile or run — I hum and swoon.
Hooray for kernels, warm and quick as noon!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely identifies the main change: adding eager-mode support to the tilelang.autotune decorator, which aligns with the changeset that introduces an eager-mode test, enhances the autotuner implementation, and updates related test documentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@testing/python/autotune/test_tilelang_autotune_eager_mode.py`:
- Around line 110-116: The test only exercises the direct-call path for symbolic
dimensions, leaving matmul.compile uncovered; update the test
(test_autotune_matmul_symbolic_m) to run both paths: wrap both
matmul.compile(M=M, N=N, K=K) (when return_kernel True) and matmul(a, b) (when
return_kernel False) inside the same set_autotune_inputs([a, b]) block so the
compile path is exercised with symbolic dims too, ensuring the compile
invocation uses the explicit M/N/K kwargs while the direct call uses inference.

In `@tilelang/autotuner/param.py`:
- Around line 439-443: The code currently opens path / OUT_IDX_PATH and assigns
out_idx_override from the JSON, which will raise FileNotFoundError for older
caches; modify the block around OUT_IDX_PATH to catch FileNotFoundError (or
check existence) and on missing file set out_idx_override =
compile_args.out_idx, while keeping the verbose logger.debug message and only
attempting json.load when the file exists; reference the OUT_IDX_PATH constant,
the out_idx_override variable, and compile_args.out_idx so you update the
correct assignment logic.

In `@tilelang/autotuner/tuner.py`:
- Around line 344-347: _kernel_parameters currently has an incorrect type and
inconsistent structure across lazy and eager paths; update its annotation from
tuple[str, ...] to a 2-tuple representing (args_tuple, kwargs_tuple) (e.g.,
tuple[tuple[Any, ...], tuple[tuple[str, Any], ...]]) and normalize both code
paths so set_kernel_parameters always stores (args,
tuple(sorted(kwargs.items()))) (ensure args are converted to a tuple and kwargs
to a sorted tuple of items) — change the lazy-mode call that currently passes
raw (args, tuple(sorted(kwargs.items()))) if needed to the normalized form and
ensure eager-mode already using (norm_args, norm_kwargs) matches that exact
format, and update any docstring/comments for _kernel_parameters and
set_kernel_parameters to reflect the normalized structure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d9a0326-3395-4f40-a638-ee4166e54a76

📥 Commits

Reviewing files that changed from the base of the PR and between 0fb658e and 1fca875.

📒 Files selected for processing (3)
  • testing/python/autotune/test_tilelang_autotune_eager_mode.py
  • tilelang/autotuner/param.py
  • tilelang/autotuner/tuner.py

Comment thread testing/python/autotune/test_tilelang_autotune_eager_mode.py
Comment thread tilelang/autotuner/param.py
Comment thread tilelang/autotuner/tuner.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extends @tilelang.autotune to support eager-mode @tilelang.jit kernels by enabling eager compilation/execution workflows and improving autotuner artifact persistence.

Changes:

  • Update autotune invocation to handle eager vs. lazy JIT modes and add an AutoTuneImpl.compile() API.
  • Improve autotuner caching to store both the best kernel and its best config, and adjust cache-key generation for callable config providers.
  • Persist and restore eager-mode out_idx_override in autotune disk cache; add eager-mode autotune matmul tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
tilelang/autotuner/tuner.py Adds eager-mode path to autotune wrapper, normalizes call keys, caches best kernel+config, and introduces compile() helper.
tilelang/autotuner/param.py Saves/loads an out_idx_override value alongside autotune artifacts to restore eager-mode output behavior.
testing/python/autotune/test_tilelang_autotune_eager_mode.py New test validating eager-mode autotune execution and the new compile() workflow for a matmul kernel.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tilelang/autotuner/tuner.py
Comment thread tilelang/autotuner/param.py
Comment thread testing/python/autotune/test_tilelang_autotune_eager_mode.py
Comment thread testing/python/autotune/test_tilelang_autotune_eager_mode.py
Copy link
Copy Markdown
Collaborator

@SiriusNEO SiriusNEO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some comments. And you can also have a look at the comments from Copilot (You can ignore some Copilot comments if you think it's OK, since it just gives suggestions based on common programming knowledge)

Comment thread tilelang/autotuner/param.py
Comment thread tilelang/autotuner/param.py
Comment thread tilelang/autotuner/tuner.py Outdated
Comment thread tilelang/autotuner/tuner.py Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tilelang/autotuner/tuner.py`:
- Around line 351-353: AutoTuneImpl is overwriting raw invocation data when
normalizing kernel parameters: instead of reusing self._kernel_parameters (which
holds the normalized cache key) to call the configs callable and assigning its
materialized result to self.configs, keep raw invocation args separate from the
normalized key; call the configs callable using a local variable (e.g., configs
= self._kernel_parameters_raw or the local kernel_args/kernel_kwargs passed into
__call__), set key_data["configs"] to that local (raw) configs value, and ensure
run() uses the local/config-callable (not self.configs) so you do not replace
the callable with a frozen materialized list; alternatively introduce a distinct
attribute (like _kernel_key_params) for the normalized key and leave
self.configs as the original callable so subsequent run() calls receive raw
tensors/Vars rather than normalized tuples/strings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 762bbe26-5e88-4c8a-ad69-56c734c909ab

📥 Commits

Reviewing files that changed from the base of the PR and between 1fca875 and 61a7e25.

📒 Files selected for processing (4)
  • testing/python/autotune/test_tilelang_autotune.py
  • testing/python/autotune/test_tilelang_autotune_eager_mode.py
  • testing/python/autotune/test_tilelang_autotune_with_inputs.py
  • tilelang/autotuner/tuner.py
✅ Files skipped from review due to trivial changes (1)
  • testing/python/autotune/test_tilelang_autotune.py

Comment thread tilelang/autotuner/tuner.py
@SiriusNEO SiriusNEO merged commit 7b6b64f into tile-ai:main Mar 12, 2026
4 of 6 checks passed
Hale423 pushed a commit to Hale423/tilelang that referenced this pull request Mar 17, 2026
)

* [Enhancement] Add eager-mode support for tilelang.autotune

* Fix type annotation and improve code structure in tuner.py

* Fix misleading docstring in autotune tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants