Repository navigation
Key triton < 3.4 driver module cache by Python version - #13409
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes #2760
Root cause
triton 3.2.0 and 3.3.x (the versions torch 2.6 and 2.7 pin) compile
cuda_utilsand every kernel launcher with gcc at run time and cache the result under a hash of the C source only, ascuda_utils.so. Nothing in the key or the file name says which Python built it. A module built by Python 3.13 callsPyArg_ParseTuple, which in 3.13 always takesPy_ssize_tlengths; the same symbol in Python 3.12 and older is the legacy one, so when a 3.12 process picks up that cached module,load_binary("ss#ii")raises:at the first Triton kernel launch. That is the reporter's setup (torch 2.7.0, triton 3.3.0,
requires-python = "==3.12.0"), and why deleting~/.triton/cacheis the workaround that keeps working in triton-lang/triton#5919 and pytorch/pytorch#153737. triton 3.4 fixed it upstream by naming the cached file with the fullEXT_SUFFIX(cuda_utils.cpython-312-x86_64-linux-gnu.so).The check added in #11023 reads
driver.cfor a missing macro, but every published triton wheel defines it, so it never fires for this case.Change
fix_triton_module_cache_python_key()inunsloth/import_fixes.py, run early in_gpu_init.pybefore anything brings up the triton driver. When a backend driver defines its owncompile_module_from_src(triton 3.2 / 3.3, CUDA and ROCm), it is wrapped to append a/* unsloth: <EXT_SUFFIX> */comment to the C source, so the cache key differs per Python version, matching what triton 3.4 does. On triton 3.4 and newer the driver imports the already keyed function fromtriton.runtime.build, and nothing is patched. Idempotent,functools.update_wrapper, original kept as__wrapped__.Cost: affected installs (torch 2.6 / 2.7) recompile
cuda_utilsand each launcher once into the new key; later runs hit the cache as before. Nothing on the per-call path changes.Evidence
Reproduced with triton 3.3.0 wheels: a Python 3.13 process fills the cache, then Python 3.12 reuses it.
CudaUtils().load_binaryon 3.12 after 3.13 filled the cacheSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formatsfast_rms_layernormon GPU, torch 2.7.0+cu128, Python 3.12, cache seeded by 3.13SystemErrorSystemErrorPatch applied on triton 3.2.0 (nvidia, amd), inert on 3.4.0 and 3.8.0.
Tests:
tests/test_triton_module_cache_key.py(a 3.3 style backend loaded the waytriton.backendsloads it gets keyed once; a 3.4 style one is left alone), plustests/test_import_time_floors.py: 84 passed.