Skip to content

[Misc] add env for default target/backend/verbose#1512

Merged
LeiWang1999 merged 8 commits intotile-ai:mainfrom
lucifer1004:example-argparse
Dec 24, 2025
Merged

[Misc] add env for default target/backend/verbose#1512
LeiWang1999 merged 8 commits intotile-ai:mainfrom
lucifer1004:example-argparse

Conversation

@lucifer1004
Copy link
Collaborator

@lucifer1004 lucifer1004 commented Dec 23, 2025

With these env vars, we can batch run examples for a specific target/backend.

Summary by CodeRabbit

  • New Features

    • Environment-driven defaults: new TILELANG_* vars to set default target, execution backend, and verbosity.
    • Public APIs now accept optional parameters (target, execution backend, verbose, etc.) and will read defaults from the environment when omitted.
    • Example updated to use the direct JIT decorator instead of the previous autotune wrapper.
  • Documentation

    • Docstrings and usage docs updated to describe environment-driven defaults and the new environment variables.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link

👋 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
Contributor

coderabbitai bot commented Dec 23, 2025

📝 Walkthrough

Walkthrough

Environment-driven defaults were added for compilation parameters. New TILELANG_* env vars and Environment accessors were introduced. Autotuner, JIT, and cache APIs now accept None for target/execution_backend/verbose and resolve defaults from the environment when parameters are omitted.

Changes

Cohort / File(s) Summary
Environment Variable Definitions
tilelang/env.py
Added EnvVars TILELANG_DEFAULT_TARGET, TILELANG_DEFAULT_EXECUTION_BACKEND, TILELANG_DEFAULT_VERBOSE (defaults: "auto", "auto", "0"). Added accessors get_default_target(), get_default_execution_backend(), get_default_verbose() (parses verbose to bool).
AutoTuner Integration
tilelang/autotuner/tuner.py
AutoTuner.set_compile_args signature now accepts None for target, execution_backend, target_host, and verbose. Imports tilelang.env and applies env.get_default_*() when args are None. Removed duplicate local import; applied env defaults before normalization.
JIT Public API Updates
tilelang/jit/__init__.py
Public APIs (compile, par_compile, jit, lazy_jit) updated to accept None for target, target_host, execution_backend, and verbose. Docstrings updated to reference TILELANG_* env vars; runtime resolution deferred to environment/upstream.
Cache API & KernelCache
tilelang/cache/__init__.py, tilelang/cache/kernel_cache.py
cached and KernelCache.cached signatures updated to accept None for target, target_host, execution_backend, and verbose. Added env-driven default resolution block early in argument normalization.
Examples / Decorator Change
examples/flash_decoding/example_gqa_decode_varlen_logits.py
Removed @autotune(...) and related tilelang.disable_cache() call; function now uses @tilelang.jit(out_idx=[-2, -1]).
Minor Import/Control-flow Changes
.../tuner.py, .../kernel_cache.py
Centralized from tilelang import env usages and applied environment defaults early in normalization flows; small control-flow reorderings to use env values prior to target/backend normalization.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant API as "Autotuner/JIT/Cache API"
  participant Env as "tilelang.env"
  participant Resolver as "Target/Backend Resolver"
  participant Backend as "Execution Backend"

  Caller->>API: call(func, target=None, execution_backend=None, verbose=None)
  API->>Env: get_default_target()
  API->>Env: get_default_execution_backend()
  API->>Env: get_default_verbose()
  Env-->>API: return defaults (e.g., "auto", "auto", False)
  API->>Resolver: normalize target/backend (may remain "auto")
  Resolver-->>Backend: select/initialize backend
  Backend-->>API: backend handle
  API-->>Caller: return compiled kernel / JIT wrapper
  Note over API,Env: Env-driven defaults applied before normalization
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • chengyupku

Poem

"I nibbled defaults in the code tonight,
TILELANG whispers turned None to light.
Env seeds scattered, compile args align,
A rabbit's hop and the kernels shine.
🐰✨"

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.75% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[Misc] add env for default target/backend/verbose' accurately describes the main changes: adding environment variables for default compilation parameters.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07b5ec0 and 8f027ec.

📒 Files selected for processing (1)
  • examples/flash_decoding/example_gqa_decode_varlen_logits.py
💤 Files with no reviewable changes (1)
  • examples/flash_decoding/example_gqa_decode_varlen_logits.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Test for Python 3.12 with Nightly-ROCm-7.1 (on self-hosted-amd)
  • GitHub Check: Test for Python 3.12 with Metal (on macos-latest)
  • GitHub Check: Test for Python 3.12 with CUDA-12.8 (on self-hosted-nvidia)

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
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: 2

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 783694f and b3868b2.

📒 Files selected for processing (3)
  • tilelang/autotuner/tuner.py
  • tilelang/env.py
  • tilelang/jit/__init__.py
🧰 Additional context used
🧬 Code graph analysis (2)
tilelang/autotuner/tuner.py (1)
tilelang/env.py (3)
  • get_default_target (298-300)
  • get_default_execution_backend (302-304)
  • get_default_verbose (306-308)
tilelang/jit/__init__.py (1)
tilelang/env.py (3)
  • get_default_target (298-300)
  • get_default_execution_backend (302-304)
  • get_default_verbose (306-308)
🪛 Ruff (0.14.10)
tilelang/jit/__init__.py

148-148: PEP 484 prohibits implicit Optional

Convert to Optional[T]

(RUF013)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test for Python 3.12 with Metal (on macos-latest)
  • GitHub Check: Test for Python 3.12 with Nightly-ROCm-7.1 (on self-hosted-amd)
🔇 Additional comments (9)
tilelang/env.py (2)

248-252: LGTM!

The new environment variable declarations follow the existing patterns in the codebase with sensible defaults. The naming convention using TILELANG_ prefix for the environment variable keys is consistent.


298-308: LGTM!

The accessor methods are clean and follow existing patterns (e.g., is_cache_globally_disabled). The get_default_verbose method correctly parses truthy string values to boolean.

tilelang/autotuner/tuner.py (3)

12-12: LGTM!

The import is correctly placed with other tilelang imports.


172-178: LGTM!

The environment variable defaults are applied correctly before the target resolution logic. The order ensures that explicit parameters take precedence over environment variables.


164-167: LGTM!

Good documentation of the environment variables. This helps users understand how to configure defaults.

tilelang/jit/__init__.py (4)

27-27: LGTM!

The import is correctly placed with other tilelang imports.


94-100: LGTM!

The environment variable defaulting logic is correctly placed before the assertion and target resolution. The pattern is consistent with other functions in the PR.


184-191: LGTM!

Consistent implementation with the compile function. The defaults are applied before passing to the thread pool executor.


546-552: LGTM!

The jit decorator correctly applies environment defaults before creating the JITImpl. This ensures the decorator can be used without arguments while still respecting environment configuration.

Copy link
Member

@LeiWang1999 LeiWang1999 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but left some performance concerns.

Copy link
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: 2

🧹 Nitpick comments (1)
tilelang/cache/kernel_cache.py (1)

128-128: Consider explicit Optional type annotation.

The type annotation dict = None should be dict | None = None for PEP 484 compliance. This is pre-existing code but can be improved for consistency with the newly updated parameters above.

🔎 Proposed fix for explicit Optional
-    pass_configs: dict = None,
+    pass_configs: dict | None = None,

Similarly, check line 129 for compile_flags:

-    compile_flags: list[str] | str | None = None,
+    compile_flags: list[str] | str | None = None,

(Line 129 already appears correct)

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1dd1bf and 76c4c47.

📒 Files selected for processing (3)
  • tilelang/cache/__init__.py
  • tilelang/cache/kernel_cache.py
  • tilelang/jit/__init__.py
🧰 Additional context used
🧬 Code graph analysis (3)
tilelang/cache/kernel_cache.py (1)
tilelang/env.py (3)
  • get_default_target (298-300)
  • get_default_execution_backend (302-304)
  • get_default_verbose (306-308)
tilelang/cache/__init__.py (1)
tilelang/language/ast/ir.py (1)
  • target (1677-1707)
tilelang/jit/__init__.py (3)
tilelang/language/ast/ir.py (1)
  • target (1677-1707)
tilelang/jit/kernel.py (1)
  • JITKernel (38-767)
tilelang/env.py (1)
  • get (178-181)
🪛 Ruff (0.14.10)
tilelang/cache/kernel_cache.py

128-128: PEP 484 prohibits implicit Optional

Convert to Optional[T]

(RUF013)

tilelang/jit/__init__.py

120-120: PEP 484 prohibits implicit Optional

Convert to Optional[T]

(RUF013)

🔇 Additional comments (7)
tilelang/jit/__init__.py (4)

48-109: Well-structured environment variable integration.

The function signature correctly accepts None for compilation parameters, and the docstring comprehensively documents the environment variable fallback behavior. The delegation of None resolution to cached() maintains clean separation of concerns.


436-534: Comprehensive environment variable integration for jit decorator.

The overloads, implementation, and documentation are well-aligned. The docstring clearly explains the environment variable fallback mechanism, making the API behavior transparent to users.


536-593: Clean implementation with appropriate documentation reference.

The lazy_jit decorator correctly mirrors the jit pattern for None-accepting parameters. The concise docstring that references jit for detailed parameter and environment variable documentation follows good DRY principles.


99-108: The downstream None handling for execution_backend, target, and verbose is correctly implemented in KernelCache.cached() (tilelang/cache/kernel_cache.py:119-160). These parameters are properly resolved using environment variable accessors (env.get_default_target(), env.get_default_execution_backend(), env.get_default_verbose()) when None is passed, before being forwarded to the JITKernel constructor. No changes needed.

tilelang/cache/kernel_cache.py (3)

124-127: LGTM! Signature correctly updated for environment-driven defaults.

The parameter types now properly accept None, enabling callers to opt into environment-variable resolution. The union type syntax is clean and follows modern Python typing conventions.


134-157: LGTM! Documentation clearly explains the environment-driven defaults.

The documentation properly describes the centralized environment variable processing and the behavior when parameters are None. The emphasis on this being the "ONLY place" for such processing establishes a clear architectural pattern.


158-166: LGTM! Environment variable processing is clean and correctly placed.

The environment variable resolution happens at the right point in the flow—before target normalization and backend resolution. The logic correctly preserves explicitly-provided values while filling in defaults only when parameters are None.

Copy link
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: 0

🧹 Nitpick comments (1)
tilelang/jit/__init__.py (1)

421-421: Cleaner cache lookup implementation.

The simplification from self._kernel_cache.get(key, None) to self._kernel_cache.get(key) is a good stylistic improvement since dict.get() returns None by default when the key is not found.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76c4c47 and 07b5ec0.

📒 Files selected for processing (3)
  • examples/flash_decoding/example_gqa_decode_varlen_logits.py
  • tilelang/cache/__init__.py
  • tilelang/jit/__init__.py
🧰 Additional context used
🧬 Code graph analysis (3)
tilelang/cache/__init__.py (1)
tilelang/language/ast/ir.py (1)
  • target (1677-1707)
examples/flash_decoding/example_gqa_decode_varlen_logits.py (1)
tilelang/autotuner/tuner.py (1)
  • autotune (691-786)
tilelang/jit/__init__.py (2)
tilelang/jit/kernel.py (1)
  • JITKernel (38-767)
tilelang/env.py (1)
  • get (178-181)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test for Python 3.12 with Nightly-ROCm-7.1 (on self-hosted-amd)
  • GitHub Check: Test for Python 3.12 with Metal (on macos-latest)
🔇 Additional comments (8)
examples/flash_decoding/example_gqa_decode_varlen_logits.py (1)

200-200: LGTM! Explicit decorator path improves consistency.

The change from @autotune to @tilelang.autotune makes the decorator path explicit and aligns with the PR's introduction of environment-driven defaults. This is consistent with the existing usage of @tilelang.jit on Line 201 and tilelang.disable_cache() on Line 10.

tilelang/cache/__init__.py (1)

20-23: LGTM! Type annotations and defaults are now consistent.

The function signature correctly accepts None for target, target_host, execution_backend, and verbose, with proper type hints including | None for all parameters. The implementation appropriately delegates environment variable resolution to the kernel cache layer.

tilelang/jit/__init__.py (6)

48-108: Well-structured environment-driven defaults implementation.

The compile function correctly accepts None for execution_backend, target, and verbose, and the docstring clearly documents how environment variables (TILELANG_TARGET, TILELANG_EXECUTION_BACKEND, TILELANG_VERBOSE) provide defaults when parameters are omitted. The implementation properly delegates to the cached layer.


111-190: Parallel compilation correctly inherits environment variable support.

The par_compile function signature and docstring are consistent with the compile function. Type annotations properly include | None for all optional parameters, including the previously fixed num_workers. The implementation correctly delegates to compile() which handles environment variable resolution.


265-268: Dataclass fields correctly support optional environment-driven defaults.

The JITImpl dataclass properly declares execution_backend, target, target_host, and verbose with | None type hints, allowing environment variable defaults to be resolved at compilation time.


436-533: JIT decorator properly supports environment-driven configuration.

The jit function and its overloads correctly accept None for target, target_host, execution_backend, and verbose. The comprehensive docstring clearly explains how environment variables provide defaults, making it easy for users to configure batch operations via TILELANG_TARGET, TILELANG_EXECUTION_BACKEND, and TILELANG_VERBOSE.


536-593: Lazy JIT decorator aligns with environment variable pattern.

The lazy_jit function correctly mirrors the jit function's support for environment-driven defaults. The concise docstring appropriately references the jit documentation for parameter details and environment variables, avoiding duplication while maintaining clarity.


48-593: Environment variable resolution is correctly implemented.

Verification confirms:

  • TILELANG_TARGET defaults to "auto" (set in tilelang/env.py line 250)
  • TILELANG_EXECUTION_BACKEND defaults to "auto" (set in tilelang/env.py line 251)
  • TILELANG_VERBOSE defaults to False (set to "0" in tilelang/env.py line 252, parsed in get_default_verbose())

The compile() function correctly delegates to cached() in tilelang/cache/kernel_cache.py, which applies these environment variable defaults when parameters are None (lines 159-162 of kernel_cache.py).

@LeiWang1999 LeiWang1999 merged commit 0006621 into tile-ai:main Dec 24, 2025
5 of 6 checks passed
sgjzfzzf added a commit to sgjzfzzf/tilelang that referenced this pull request Dec 24, 2025
Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>
LeiWang1999 pushed a commit that referenced this pull request Dec 26, 2025
…1483)

* refactor kernel_cache

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* set key to auto when execution_backend is None

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* fix type error on _load_kernel_source override

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* put kernel cache subclasses in adapter

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* remove auto in execution_backend

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* remove _save_kernel_source_code_to_disk for NVRTCKernelCache

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* refactor all cutedsl if statements

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* remove unused kernel_cubin_path

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* add func arguments

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* remove ctypes

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* update ci.yaml to test kernel cache

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* fix bugs after #1512 merged

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>

* test: fix kernel cache test

* fix: ruff

* fix: ruff

* fix: coderabbit

* fix: coderabbit

* fix: ruff

* fix: MMA

* fix: coderabbit

* fix: codex

* fix: coderabbit

* fix: coderabbit

---------

Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>
Co-authored-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
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.

2 participants