Repository navigation
fix(triton): resolve autotuner future on pruning exceptions (#4477) - #4527
Merged
Merged
Conversation
_get_config_for_key published the per-key CacheFuture and then called prune_configs before entering the try/finally that sets the future Event and removes the key. A pruning exception therefore left the future pending: waiters blocked forever on future.event.wait() and same-key retries reused the unresolved future. Move prune_configs inside the owner-finalization try so every exit path records the error, signals the Event, and pops the key. Add a regression test and document the finalization contract.
…ner-prune-futures
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.
Fixes #4477
TL;DR
_get_config_for_keypublished a per-keyCacheFutureand then ranprune_configs()before entering thetry/finallythat resolves the future.A pruning exception escaped with the future still pending, so every waiter and
every same-key retry parked on
future.event.wait()forever. Pruning now runsinside the owner-finalization scope (+30/−13 in
nogil_patcher.py).1. The problem
flowchart TD A["_get_config_for_key(key)"] --> B{"_cache has key"} B -- yes --> C["return cached config"] B -- no --> D{"_cache_futures has key"} D -- yes --> E["waiter: future.event.wait (no timeout)"] D -- no --> F["owner: publish CacheFuture"] F --> G["prune_configs(kwargs)"] G -- "raises" --> H["exception escapes: future retained, Event unset, error None"] H --> I["waiters and same-key retries block forever"] G -- ok --> J["try: benchmark / cache / return"]prune_configsatutils/nogil_patcher.py:355(461b42023), outside thetryat:369prune_configsis the first statement inside the ownertry_cache_futures,future.eventunset,future.errorunsetfuture.errorset,future.eventset, key popped infinallyfuture.event.wait()with no timeout2. The new flow
flowchart TD A["_get_config_for_key(key)"] --> B{"_cache has key"} B -- yes --> C["return cached config"] B -- no --> D{"_cache_futures has key"} D -- yes --> E["waiter: future.event.wait"] E --> F{"future.error set"} F -- yes --> G["raise future.error"] F -- no --> H["return future.config"] D -- no --> I["owner: publish CacheFuture"] I --> J["try: prune_configs(kwargs)"] J -- "raises" --> K["except BaseException: future.error = exc"] J -- ok --> L["benchmark, disk cache, store best config"] L --> M["return best config"] K --> N["finally: future.event.set"] M --> N N --> O["finally: _cache_futures.pop(key)"]3. Failure contract
prune_configsraisesexcept BaseException)4. Tests / guarantees
tests/test_triton_patch_api.py::test_patched_autotuner_pruning_exception_resolves_futureValueError:future.error is exc_info.value,future.event.is_set(), a same-key retry completes as a new owner, and_cache_futuresis empty5. Validation
All runs with
OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 OPENBLAS_NUM_THREADS=4 NUMEXPR_NUM_THREADS=4.Before the fix, the new test fails with the user-visible symptom:
After the fix:
Issue probe (the shipped
CacheFuture/_get_config_for_keyexecuted via AST,with a fake
Autotunerwhoseprune_configsraises):Before:
After:
ruff check gptqmodel docs/eora tests setup.py->All checks passed!The branch was merged with
git merge --no-edit origin/main(main at76272a7fb) and ruff plus both test-file runs were repeated with the sameresults.
6. Hardware / limitations
GPU-d458708b-c760-bbf1-08fb-8b8803a2157d; ROCm: AMD R9700(
HIP_VISIBLE_DEVICES=2).installs the shipped patch on a fake
Autotuner; the probe executes theshipped
CacheFutureand_get_config_for_keythrough AST with a fakeobject. The defect and the fix are pure Python future-lifecycle control flow.
tests/test_triton_patch_api.py::test_patched_autotuner_lazily_initializes_concurrent_first_lookupis a known ~1/5 pre-existing flake; it passed in every run here and is not
claimed as a regression.
docs/concurrency.md(section 2, "Autotuner single-flightfutures resolve on every owner exit"), linked from
README.md.