-
Notifications
You must be signed in to change notification settings - Fork 92
[3/5] autotune: add offline config artifacts (#770) #786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jhinpan
wants to merge
3
commits into
ROCm:main
Choose a base branch
from
jhinpan:feat/autotune-offline-configs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Offline autotune configs | ||
|
|
||
| FlyDSL can serve a previously tuned config without benchmarking. This extends | ||
| the direct-JIT autotuner with one opt-in argument: | ||
|
|
||
| ```python | ||
| @flyc.jit | ||
| def launch(x, out, N: fx.Constexpr[int], BLOCK: fx.Constexpr[int]): | ||
| ... | ||
|
|
||
|
|
||
| tuned = autotune( | ||
| configs=[Config(BLOCK=128), Config(BLOCK=256)], | ||
| key=["N"], | ||
| default=lambda x, out, N: Config(BLOCK=256), | ||
| artifact_name="my_kernel", | ||
| )(launch) | ||
| ``` | ||
|
|
||
| `artifact_name` enables lookup when `FLYDSL_AUTOTUNE_CONFIG_DIR` is set. Normal | ||
| calls use the first available source: | ||
|
|
||
| ```text | ||
| searched winner cache -> matching artifact -> default -> search | ||
| ``` | ||
|
|
||
| `FLYDSL_AUTOTUNE=1` bypasses those serving decisions, searches the existing | ||
| configs, updates the scratch winner cache, and atomically writes an artifact. | ||
| A normal fallback search updates only the scratch cache. | ||
| While artifact lookup is active, scratch winners use the same device descriptor | ||
| so a same-architecture product cannot shadow the matching artifact. | ||
|
|
||
| ## Identity and compatibility | ||
|
|
||
| Artifact identity is the stable `artifact_name`, the declared `key` values, | ||
| and the call device's product name, target architecture, and compute-unit | ||
| count. Use a globally unique name for each kernel/config schema. The JSON is | ||
| self-describing; its filename is an identity digest. | ||
|
|
||
| The declared `key` is the single owner of portable tuning axes. Include every | ||
| shape, dtype, layout, or mode that can change the winner. Keep structural knobs | ||
| as JIT `Constexpr` parameters on the existing entry point; offline tuning does | ||
| not need a build factory or a second key callback. | ||
|
|
||
| Artifacts intentionally do not include a compiler or kernel-source fingerprint. | ||
| Treat them as reviewed deployment inputs and retune after a compiler, kernel, | ||
| compile-hint, or search-space change that can affect the winner. | ||
|
|
||
| ## Failure behavior | ||
|
|
||
| Missing, unreadable, mismatched, or structurally invalid artifacts are ignored, | ||
| and normal lookup continues to the default or search path. Artifact config | ||
| values cannot overwrite arguments supplied by the caller or declared key axes. | ||
| Values must preserve their types when encoded as JSON. `Config.pre_hook` is | ||
| process-local code, so it blocks forced artifact generation. | ||
|
|
||
| Once a matching artifact has been accepted, its compile, launch, and runtime | ||
| errors propagate normally; FlyDSL does not hide them by retrying the default. | ||
| If forced generation cannot establish a device identity or write its artifact, | ||
| it fails clearly without caching the winner. | ||
|
|
||
| Generate deployment artifacts on the intended GPU under controlled benchmark | ||
| conditions. CI should verify deterministic emit-and-load behavior, not commit a | ||
| winner selected from noisy shared-runner timing. |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also an atomic write function in JitCacheManager (jit_function.py). Can we improve it ? Reuse this function ?