Repository navigation
Add triton_metadata_redirect module with with_metadata_path decorator - #1172
Merged
Merged
Conversation
Core Features:
- `with_custom_metadata_path()` decorator for custom kernel metadata storage
- Thread-safe global registry for kernel-to-directory mappings
- Automatic patching of CompiledKernel.__init__ method
- Full backward compatibility with existing @triton.jit usage
Example usage:
```python
from aiter.utility.triton.triton_metadata_redirect import with_custom_metadata_path
@with_custom_metadata_path("/custom/metadata/path")
@triton.jit
def my_kernel(...):
...
```
jwu10003
force-pushed
the
jian.wu.triton_metadata_redirect
branch
from
October 13, 2025 03:08
55a1251 to
8fb645c
Compare
Contributor
Author
jwu10003
requested review from
Dewei-Wang-sh,
carlushuang,
coderfeli and
zhanglx13
October 14, 2025 07:33
azaidy
pushed a commit
that referenced
this pull request
Oct 17, 2025
…#1172) * Add triton_metadata_redirect module with with_metadata_path decorator Core Features: - `with_custom_metadata_path()` decorator for custom kernel metadata storage - Thread-safe global registry for kernel-to-directory mappings - Automatic patching of CompiledKernel.__init__ method - Full backward compatibility with existing @triton.jit usage Example usage: ```python from aiter.utility.triton.triton_metadata_redirect import with_custom_metadata_path @with_custom_metadata_path("/custom/metadata/path") @triton.jit def my_kernel(...): ... ``` * update code format
eliotwang
pushed a commit
to eliotwang/aiter
that referenced
this pull request
Oct 21, 2025
…ROCm#1172) * Add triton_metadata_redirect module with with_metadata_path decorator Core Features: - `with_custom_metadata_path()` decorator for custom kernel metadata storage - Thread-safe global registry for kernel-to-directory mappings - Automatic patching of CompiledKernel.__init__ method - Full backward compatibility with existing @triton.jit usage Example usage: ```python from aiter.utility.triton.triton_metadata_redirect import with_custom_metadata_path @with_custom_metadata_path("/custom/metadata/path") @triton.jit def my_kernel(...): ... ``` * update code format
sjfeng1999
pushed a commit
that referenced
this pull request
Oct 28, 2025
…#1172) * Add triton_metadata_redirect module with with_metadata_path decorator Core Features: - `with_custom_metadata_path()` decorator for custom kernel metadata storage - Thread-safe global registry for kernel-to-directory mappings - Automatic patching of CompiledKernel.__init__ method - Full backward compatibility with existing @triton.jit usage Example usage: ```python from aiter.utility.triton.triton_metadata_redirect import with_custom_metadata_path @with_custom_metadata_path("/custom/metadata/path") @triton.jit def my_kernel(...): ... ``` * update code format
sjfeng1999
pushed a commit
that referenced
this pull request
Oct 31, 2025
…#1172) * Add triton_metadata_redirect module with with_metadata_path decorator Core Features: - `with_custom_metadata_path()` decorator for custom kernel metadata storage - Thread-safe global registry for kernel-to-directory mappings - Automatic patching of CompiledKernel.__init__ method - Full backward compatibility with existing @triton.jit usage Example usage: ```python from aiter.utility.triton.triton_metadata_redirect import with_custom_metadata_path @with_custom_metadata_path("/custom/metadata/path") @triton.jit def my_kernel(...): ... ``` * update code format
sjfeng1999
pushed a commit
that referenced
this pull request
Oct 31, 2025
…#1172) * Add triton_metadata_redirect module with with_metadata_path decorator Core Features: - `with_custom_metadata_path()` decorator for custom kernel metadata storage - Thread-safe global registry for kernel-to-directory mappings - Automatic patching of CompiledKernel.__init__ method - Full backward compatibility with existing @triton.jit usage Example usage: ```python from aiter.utility.triton.triton_metadata_redirect import with_custom_metadata_path @with_custom_metadata_path("/custom/metadata/path") @triton.jit def my_kernel(...): ... ``` * update code format
6 tasks done
valarLip
pushed a commit
that referenced
this pull request
Mar 18, 2026
…#1172) * Add triton_metadata_redirect module with with_metadata_path decorator Core Features: - `with_custom_metadata_path()` decorator for custom kernel metadata storage - Thread-safe global registry for kernel-to-directory mappings - Automatic patching of CompiledKernel.__init__ method - Full backward compatibility with existing @triton.jit usage Example usage: ```python from aiter.utility.triton.triton_metadata_redirect import with_custom_metadata_path @with_custom_metadata_path("/custom/metadata/path") @triton.jit def my_kernel(...): ... ``` * update code format
9 of 11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Core Features:
with_custom_metadata_path()decorator for custom kernel metadata storageUsage
Dump Custom .json/.hsaco Files to a Custom Directory
First you need to dump the metadata files to a custom directory(copy ~/.triton/cache/{hash}/{kernel_name}.json and ~/.triton/cache/{hash}/{kernel_name}*.hsaco to a custom directory).
For JIT Compilation (Using Decorator)
For AOT Compilation (Using Context Manager)
For Separate Compile And Run
Motivation
Users hope to be able to use the kernel metadata files (.json and.hsaco) compiled by the new version of Triton to achieve performance optimizations of the new version without upgrading the old version of Triton.
Technical Details
The module patches the
CompiledKernel.__init__method to intercept metadata file path assignments during Triton kernel compilation. When a kernel is registered (either via decorator or context manager), the module redirects the output paths for:{kernel_name}.json - Kernel metadata file
{kernel_name}.hsaco - Compiled kernel binary
NOTE
Critical: For the same kernel name with different template parameters, you must store the generated .json and .hsaco files in separate directories. The module does not differentiate between kernel variants based on template parameters - it only uses the kernel name.
This module implements a simple kernel name to directory mapping without considering compilation parameter variations. In order to handle multiple instantiations, we need to include information about the compilation parameters in the path. However, due to the instability of the hash value (which depends on the environment such as
TRITON_PATH,ENV, etc.), we haven't found a good way to deal with it for now.Hash Instability: Triton's hash values depend on TRITON_PATH and environment variables, making them unreliable for matching
Functional Equivalence: Even kernels with identical functionality may have different hashes due to external factors
Simplicity: The name-based approach provides a straightforward mapping mechanism
Test Plan
test for JIT Compilation
test for AOT Compilation
test for Separate Compile And Run
Test Result
pass python op_tests/triton_tests/triton_metadata_redirect/test_metadata_redirect.py
Submission Checklist