Repository navigation
[Triton/Gluon] Move the sage-attention launch params into the config tree - #5106
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags: |
There was a problem hiding this comment.
Pull request overview
Moves Sage-attention (fav3_sage) forward launch parameters out of Python and into the nested Triton config tree, so launch tuning is data-driven and consistent with the rest of the config-loading machinery.
Changes:
- Add nested-layout
DEFAULT.jsonconfig tables forfav3_sageon gfx942 and gfx950, and forfav3_sage_mxfp4on gfx950. - Update
fav3_sageto load per-arch configs viaresolve_config_dir()/load_config_json(), with a deterministic gfx942 fallback when the running arch has no table. - Update the MXFP4 wrapper to load its forward launch config from the config tree (gfx950-only).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| aiter/ops/triton/configs/gfx950/triton/attention/fav3_sage/DEFAULT.json | Adds gfx950 default + optional fwd_a3_tuned preset for fav3_sage forward launch params. |
| aiter/ops/triton/configs/gfx950/triton/attention/fav3_sage_mxfp4/DEFAULT.json | Adds gfx950 default forward launch params for the MXFP4 variant. |
| aiter/ops/triton/configs/gfx942/triton/attention/fav3_sage/DEFAULT.json | Adds gfx942 default + optional fwd_a3_tuned preset for fav3_sage forward launch params. |
| aiter/ops/triton/attention/fav3_sage.py | Replaces hardcoded arch-specific dicts with config-tree loading + gfx942 fallback. |
| aiter/ops/triton/attention/fav3_sage_attention_mxfp4_wrapper.py | Replaces hardcoded launch dict with config-tree loading for gfx950. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
"Tuning values live in JSON, never in Python" -- two sage config selectors
still returned hardcoded dicts:
attention/fav3_sage.py three arch branches, one dict each
attention/fav3_sage_attention_mxfp4_wrapper.py one dict behind an arch guard
Both now read <arch>/triton/attention/{fav3_sage,fav3_sage_mxfp4}/DEFAULT.json
through resolve_config_dir() + load_config_json(). The a3_tuned preset moves
into the JSON as a `fwd_a3_tuned` overlay on `fwd`; the `if a3_tuned:` branch
and the mxfp4 wrapper's non-gfx950 guard are control flow and stay in Python.
The JSON carries exactly the numbers the Python returned. Verified by
extracting both versions of the function and comparing their output for every
architecture across the full block_m x block_n x a3_tuned matrix -- equal in
value, key order and value type (PRE_LOAD_V stays a bool, not 0).
Two things a reviewer should weigh in on:
- The old `else:` branch was byte-identical to gfx942, so arches with no tuned
table of their own read the gfx942 file through an explicit
`arch=_FALLBACK_ARCH` retry. That preserves today's behaviour exactly, but it
is a second instance of the arch-fallback pattern that so far only MHC uses.
Tuning those arches and dropping the fallback is the better end state.
- Both functions copy before returning. load_config_json hands back the shared
cached dict and get_sage_fwd_configs mutates what it returns, so without the
copy an a3_tuned=True call would poison the cache for every later caller.
60081ea to
9c09646
Compare
Removed comments regarding import behavior and tracing paths.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (1)
aiter/ops/triton/attention/fav3_sage.py:44
- os.scandir() returns an iterator that holds an open directory handle; relying on implicit closure after sorted() can leave the fd open longer than intended (especially on non-CPython runtimes). Use a context manager to deterministically close the scandir handle once the entries are consumed.
for entry in sorted(os.scandir(AITER_TRITON_CONFIGS_PATH), key=lambda e: e.name):
brunomazzottiamd
left a comment
There was a problem hiding this comment.
I have a small change request: please guarantee that fallback arch is present in the config table after loading it.
get_sage_fwd_configs() reads
_SAGE_FWD_TABLES.get(arch_info.get_arch(), _SAGE_FWD_TABLES[_FALLBACK_ARCH])
and dict.get() evaluates its default eagerly, so the gfx942 lookup runs on
every call whether or not the fallback is needed. A missing gfx942 table would
therefore raise KeyError on every architecture, including the ones that ship a
tuned table of their own, and it would surface deep inside a launch rather than
where the file is actually absent.
Assert the invariant in _load_sage_fwd_tables() instead, naming the path that
is missing. Two arches ship a table today, gfx942 and gfx950, so the assert
holds; removing the gfx942 file makes it fire at import with that path in the
message.
Reported by @brunomazzottiamd in review.
There was a problem hiding this comment.
🟡 Changes recommended
The new config-loading path has avoidable import-time exception overhead and relies on an assert plus a potentially non-optional "fwd_a3_tuned" key access that can lead to harder-to-diagnose runtime failures.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
Previously missed (2) — in code that hasn't changed since the last review.
aiter/ops/triton/attention/fav3_sage.py:96
- get_sage_fwd_configs(a3_tuned=True) assumes every per-arch table contains "fwd_a3_tuned"; if an arch later adds a minimal table without that key, this will raise KeyError even though the docstring describes it as optional. Use a default empty dict (or guard) so a3_tuned remains optional.
aiter/ops/triton/attention/fav3_sage.py:52 - _load_sage_fwd_tables() probes every arch directory via load_config_json(..., required=False). In this repo only gfx942/gfx950 ship the file, so the other probes trigger FileNotFoundError exceptions at import time, which is unnecessarily expensive and can slow module import.
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
There was a problem hiding this comment.
🟡 Changes recommended
The new import-time config loader uses assert for a required runtime invariant (bypassable under -O) and should close os.scandir() via a context manager to avoid leaking a file descriptor.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
aiter/ops/triton/attention/fav3_sage.py:50
os.scandir()returns an iterator that should be closed; wrapping it in a context manager avoids leaking a file descriptor during module import.
for entry in sorted(os.scandir(AITER_TRITON_CONFIGS_PATH), key=lambda e: e.name):
if not entry.is_dir():
continue
cfg_dir = resolve_config_dir(
"attention", _CONFIG_NAME, backend="triton", arch=entry.name
)
table = load_config_json(f"{cfg_dir}/DEFAULT.json", required=False)
aiter/ops/triton/attention/fav3_sage.py:63
- Using
assertto enforce the presence of the fallback config can be bypassed when Python is run with optimizations (-O), which would defer the failure to a laterKeyErrorand make it harder to diagnose. Prefer an explicit runtime check that raises a deterministic exception naming the missing file.
assert _FALLBACK_ARCH in tables, (
f"no {_CONFIG_NAME} table for the fallback architecture "
f"{_FALLBACK_ARCH!r}: expected "
f"{resolve_config_dir('attention', _CONFIG_NAME, backend='triton', arch=_FALLBACK_ARCH)}"
"/DEFAULT.json"
)
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
No description provided.