[fix] Autotuner: propagate the tuned function's return value#899
Open
aryaman-gupta wants to merge 2 commits into
Open
[fix] Autotuner: propagate the tuned function's return value#899aryaman-gupta wants to merge 2 commits into
aryaman-gupta wants to merge 2 commits into
Conversation
_run_with_hints called self.fn(*args, **kwargs) on both branches without returning it, so Autotuner.__call__ always yielded None even though _run_config already returns _run_with_hints(...). Any autotuned function that produces its result as a return value (rather than writing into a caller-owned output buffer) silently got None. Add the missing return on both branches; backward compatible for callers that ignore the return value.
Add a regression test that the tuned function's return value propagates through __call__ on both the search and cache-hit paths, plus a guard that in-place kernels (which return None) still return None. The first test fails without the _run_with_hints fix.
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.
Summary
Autotuner._run_with_hintscallsself.fn(*args, **kwargs)on both branches (with and without compiler hints) but does not return it. As a resultAutotuner.__call__always yieldsNone, even though_run_configdoesreturn self._run_with_hints(...)and__call__returns_run_config(...)— the value is threaded all the way up to this one method, which drops it.Any autotuned function that produces its result as a return value (rather than writing into a caller-owned output buffer) therefore silently gets
None. Callers currently work around this by allocating an output tensor themselves, passing it in, and returning that buffer instead of trusting the autotuner's return.Fix
Add the missing
returnon both branches of_run_with_hints.Backward compatible:
out) are unaffected — the fn still returnsNone, so the tuner still returnsNone.Test
Adds two cases to
tests/unit/test_autotune.py(GPU-free):test_call_returns_tuned_fn_value— the tuned fn's return value propagates through__call__on both the search path and the cache-hit path. Fails without the fix (assert None == ('result', 64)).test_call_returns_none_when_fn_returns_none— an in-place fn that returns nothing still yieldsNone, confirming the fix only forwards the value and doesn't fabricate one.Run: