Skip to content

[inductor] Prune GEMM configs that cannot fit in shared memory by default - #194161

Closed
anijain2305 wants to merge 5 commits into
gh/anijain2305/1322/basefrom
gh/anijain2305/1322/head
Closed

anijain2305 wants to merge 5 commits into
gh/anijain2305/1322/basefrom
gh/anijain2305/1322/head

Conversation

@anijain2305

@anijain2305 anijain2305 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

A GEMM template config whose shared memory footprint exceeds the device limit
compiles fine and then fails to build a launcher with OutOfResources. When no
config for that kernel survives, CachingAutotuner._make_launchers falls back to
rewriting the config with num_stages=1 and compiling the kernel a second time.
That second compile is cold, LLVM plus ptxas, and it runs serially in the
benchmarking path rather than in the precompile worker pool.

On internal models this is where most of compile time goes. Instrumenting
compile_by_disabling_pipelining on a source build:

model1 28/0:  388 fallback compiles, 926.9s of a 1293.2s compile
model1 19/0:   52 fallback compiles, 128.3s of a  167.7s compile
model2 18/1:   71 fallback compiles, 146.5s of a  533.3s compile

The configs miss by a wide margin, so this is not a borderline estimate problem:

device shared_memory_per_block_optin: 232448
Required: 262144 / 294912 / 393216   (13% to 69% over)

Mean GPU utilization over one whole 166s compile is 5.6%, with 91% of samples
under 10%, because the phase reported as autotuning is really Triton compilation.
Meanwhile roughly 32 compile_threads workers sit idle for 86.8s.

max_autotune_prune_choices_based_on_shared_mem already drops these configs before
they reach the compiler; it was just off by default, on the grounds that the
estimate is an upper bound and may over-prune. Turning it on:

                 before      after     summed best kernel time
model1 28/0     1364.2s     315.7s     246.0708ms -> 246.0401ms
model1 19/0      166.5s      31.5s       5.8646ms ->   5.8651ms

Kernel choice does not measurably change. That is expected: the pruned configs
were the ones being silently rewritten to num_stages=1, and those rewrites lose
the autotune anyway. On 28/0 both runs autotune 145 kernels and pick the same
mix of extern and Triton winners.

Over-pruning is real, though. With pruning enabled the TMA addmm template lost
every config and compilation failed with NoValidChoicesError, because the
estimate does not model that template. So pruning now never empties the candidate
list: if every config looks too large, keep them all and let the compiler decide.
That preserves the win here, where many valid configs remain, and restores
today's behavior for any template the estimate mismodels.

Test Plan:

python -m pytest -q -p no:randomly test/inductor/test_triton_heuristics.py
# 54 passed, 4 skipped

python -m pytest -q -p no:randomly test/inductor/test_max_autotune.py
# 406 passed, 177 skipped

python -m pytest -q -p no:randomly \
  test/inductor/test_max_autotune.py::TestMaxAutotuneAsyncPipelined
# 147 passed, 91 skipped

test_triton_heuristics covers both settings of the flag explicitly, so flipping
the default does not change what it asserts. The full test_max_autotune run
reported one additional failure,
TestMaxAutotuneAsyncPipelined::test_triton_template_generated_code_caching_bmm,
which passes in isolation with and without this change and passes when its whole
class is run; its log shows a FileNotFoundError on a temporary cache path, so it
is cross-class order dependence rather than a regression here.

This commit was authored with the assistance of an AI agent (Claude Code).

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194161

Note: Links to docs will display an error until the docs builds have been completed.

❌ 4 New Failures, 3 Cancelled Jobs, 1 Unrelated Failure, 1 Unclassified Failure

As of commit cda2e59 with merge base 6a0eb75 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • Check mergeability of ghstack PR / ghstack-mergeability-check (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    cherry-pick

    AI verdict: AI verdict: probably related

    The ghstack mergeability check fails because the PR's commit cannot be cleanly cherry-picked onto main, indicating merge conflicts between the PR's code changes and trunk. This is directly caused by the content of the commit diverging from the current state of main.

    Full reasoning on HUD →

CANCELLED JOBS - The following jobs were cancelled. Please retry:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot

pytorch-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

anijain2305 added a commit that referenced this pull request Aug 20, 2026
…ault

A GEMM template config whose shared memory footprint exceeds the device limit
compiles fine and then fails to build a launcher with OutOfResources. When no
config for that kernel survives, CachingAutotuner._make_launchers falls back to
rewriting the config with num_stages=1 and compiling the kernel a second time.
That second compile is cold, LLVM plus ptxas, and it runs serially in the
benchmarking path rather than in the precompile worker pool.

On internal ads models this is where most of compile time goes. Instrumenting
compile_by_disabling_pipelining on a source build:

    inline CTR/CVR 28/0:  388 fallback compiles, 926.9s of a 1293.2s compile
    inline CTR/CVR 19/0:   52 fallback compiles, 128.3s of a  167.7s compile
    FB foundational 18/1:  71 fallback compiles, 146.5s of a  533.3s compile

The configs miss by a wide margin, so this is not a borderline estimate problem:

    device shared_memory_per_block_optin: 232448
    Required: 262144 / 294912 / 393216   (13% to 69% over)

Mean GPU utilization over one whole 166s compile is 5.6%, with 91% of samples
under 10%, because the phase reported as autotuning is really Triton compilation.
Meanwhile roughly 32 compile_threads workers sit idle for 86.8s.

max_autotune_prune_choices_based_on_shared_mem already drops these configs before
they reach the compiler; it was just off by default, on the grounds that the
estimate is an upper bound and may over-prune. Turning it on:

                     before      after     summed best kernel time
    inline 28/0     1364.2s     315.7s     246.0708ms -> 246.0401ms
    inline 19/0      166.5s      31.5s       5.8646ms ->   5.8651ms

Kernel choice does not measurably change. That is expected: the pruned configs
were the ones being silently rewritten to num_stages=1, and those rewrites lose
the autotune anyway. On 28/0 both runs autotune 145 kernels and pick the same
mix of extern and Triton winners.

Over-pruning is real, though. With pruning enabled the TMA addmm template lost
every config and compilation failed with NoValidChoicesError, because the
estimate does not model that template. So pruning now never empties the candidate
list: if every config looks too large, keep them all and let the compiler decide.
That preserves the win here, where many valid configs remain, and restores
today's behavior for any template the estimate mismodels.

Test Plan:

```
python -m pytest -q -p no:randomly test/inductor/test_triton_heuristics.py
# 54 passed, 4 skipped

python -m pytest -q -p no:randomly test/inductor/test_max_autotune.py
# 406 passed, 177 skipped

python -m pytest -q -p no:randomly \
  test/inductor/test_max_autotune.py::TestMaxAutotuneAsyncPipelined
# 147 passed, 91 skipped
```

test_triton_heuristics covers both settings of the flag explicitly, so flipping
the default does not change what it asserts. The full test_max_autotune run
reported one additional failure,
TestMaxAutotuneAsyncPipelined::test_triton_template_generated_code_caching_bmm,
which passes in isolation with and without this change and passes when its whole
class is run; its log shows a FileNotFoundError on a temporary cache path, so it
is cross-class order dependence rather than a regression here.

This commit was authored with the assistance of an AI agent (Claude Code).


ghstack-source-id: 63cf325
Pull-Request: #194161
@anijain2305
anijain2305 requested review from eellison and mlazos August 20, 2026 14:33
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Aug 20, 2026
…ault

A GEMM template config whose shared memory footprint exceeds the device limit
compiles fine and then fails to build a launcher with OutOfResources. When no
config for that kernel survives, CachingAutotuner._make_launchers falls back to
rewriting the config with num_stages=1 and compiling the kernel a second time.
That second compile is cold, LLVM plus ptxas, and it runs serially in the
benchmarking path rather than in the precompile worker pool.

On internal ads models this is where most of compile time goes. Instrumenting
compile_by_disabling_pipelining on a source build:

    inline CTR/CVR 28/0:  388 fallback compiles, 926.9s of a 1293.2s compile
    inline CTR/CVR 19/0:   52 fallback compiles, 128.3s of a  167.7s compile
    FB foundational 18/1:  71 fallback compiles, 146.5s of a  533.3s compile

The configs miss by a wide margin, so this is not a borderline estimate problem:

    device shared_memory_per_block_optin: 232448
    Required: 262144 / 294912 / 393216   (13% to 69% over)

Mean GPU utilization over one whole 166s compile is 5.6%, with 91% of samples
under 10%, because the phase reported as autotuning is really Triton compilation.
Meanwhile roughly 32 compile_threads workers sit idle for 86.8s.

max_autotune_prune_choices_based_on_shared_mem already drops these configs before
they reach the compiler; it was just off by default, on the grounds that the
estimate is an upper bound and may over-prune. Turning it on:

                     before      after     summed best kernel time
    inline 28/0     1364.2s     315.7s     246.0708ms -> 246.0401ms
    inline 19/0      166.5s      31.5s       5.8646ms ->   5.8651ms

Kernel choice does not measurably change. That is expected: the pruned configs
were the ones being silently rewritten to num_stages=1, and those rewrites lose
the autotune anyway. On 28/0 both runs autotune 145 kernels and pick the same
mix of extern and Triton winners.

Over-pruning is real, though. With pruning enabled the TMA addmm template lost
every config and compilation failed with NoValidChoicesError, because the
estimate does not model that template. So pruning now never empties the candidate
list: if every config looks too large, keep them all and let the compiler decide.
That preserves the win here, where many valid configs remain, and restores
today's behavior for any template the estimate mismodels.

Test Plan:

```
python -m pytest -q -p no:randomly test/inductor/test_triton_heuristics.py
# 54 passed, 4 skipped

python -m pytest -q -p no:randomly test/inductor/test_max_autotune.py
# 406 passed, 177 skipped

python -m pytest -q -p no:randomly \
  test/inductor/test_max_autotune.py::TestMaxAutotuneAsyncPipelined
# 147 passed, 91 skipped
```

test_triton_heuristics covers both settings of the flag explicitly, so flipping
the default does not change what it asserts. The full test_max_autotune run
reported one additional failure,
TestMaxAutotuneAsyncPipelined::test_triton_template_generated_code_caching_bmm,
which passes in isolation with and without this change and passes when its whole
class is run; its log shows a FileNotFoundError on a temporary cache path, so it
is cross-class order dependence rather than a regression here.

This commit was authored with the assistance of an AI agent (Claude Code).


ghstack-source-id: 225f3e0
Pull-Request: #194161
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Aug 20, 2026
…ault

A GEMM template config whose shared memory footprint exceeds the device limit
compiles fine and then fails to build a launcher with OutOfResources. When no
config for that kernel survives, CachingAutotuner._make_launchers falls back to
rewriting the config with num_stages=1 and compiling the kernel a second time.
That second compile is cold, LLVM plus ptxas, and it runs serially in the
benchmarking path rather than in the precompile worker pool.

On internal ads models this is where most of compile time goes. Instrumenting
compile_by_disabling_pipelining on a source build:

    inline CTR/CVR 28/0:  388 fallback compiles, 926.9s of a 1293.2s compile
    inline CTR/CVR 19/0:   52 fallback compiles, 128.3s of a  167.7s compile
    FB foundational 18/1:  71 fallback compiles, 146.5s of a  533.3s compile

The configs miss by a wide margin, so this is not a borderline estimate problem:

    device shared_memory_per_block_optin: 232448
    Required: 262144 / 294912 / 393216   (13% to 69% over)

Mean GPU utilization over one whole 166s compile is 5.6%, with 91% of samples
under 10%, because the phase reported as autotuning is really Triton compilation.
Meanwhile roughly 32 compile_threads workers sit idle for 86.8s.

max_autotune_prune_choices_based_on_shared_mem already drops these configs before
they reach the compiler; it was just off by default, on the grounds that the
estimate is an upper bound and may over-prune. Turning it on:

                     before      after     summed best kernel time
    inline 28/0     1364.2s     315.7s     246.0708ms -> 246.0401ms
    inline 19/0      166.5s      31.5s       5.8646ms ->   5.8651ms

Kernel choice does not measurably change. That is expected: the pruned configs
were the ones being silently rewritten to num_stages=1, and those rewrites lose
the autotune anyway. On 28/0 both runs autotune 145 kernels and pick the same
mix of extern and Triton winners.

Over-pruning is real, though. With pruning enabled the TMA addmm template lost
every config and compilation failed with NoValidChoicesError, because the
estimate does not model that template. So pruning now never empties the candidate
list: if every config looks too large, keep them all and let the compiler decide.
That preserves the win here, where many valid configs remain, and restores
today's behavior for any template the estimate mismodels.

Test Plan:

```
python -m pytest -q -p no:randomly test/inductor/test_triton_heuristics.py
# 54 passed, 4 skipped

python -m pytest -q -p no:randomly test/inductor/test_max_autotune.py
# 406 passed, 177 skipped

python -m pytest -q -p no:randomly \
  test/inductor/test_max_autotune.py::TestMaxAutotuneAsyncPipelined
# 147 passed, 91 skipped
```

test_triton_heuristics covers both settings of the flag explicitly, so flipping
the default does not change what it asserts. The full test_max_autotune run
reported one additional failure,
TestMaxAutotuneAsyncPipelined::test_triton_template_generated_code_caching_bmm,
which passes in isolation with and without this change and passes when its whole
class is run; its log shows a FileNotFoundError on a temporary cache path, so it
is cross-class order dependence rather than a regression here.

This commit was authored with the assistance of an AI agent (Claude Code).


ghstack-source-id: 2c313e1
Pull-Request: #194161
anijain2305 added a commit that referenced this pull request Aug 20, 2026
…ault

A GEMM template config whose shared memory footprint exceeds the device limit
compiles fine and then fails to build a launcher with OutOfResources. When no
config for that kernel survives, CachingAutotuner._make_launchers falls back to
rewriting the config with num_stages=1 and compiling the kernel a second time.
That second compile is cold, LLVM plus ptxas, and it runs serially in the
benchmarking path rather than in the precompile worker pool.

On internal models this is where most of compile time goes. Instrumenting
compile_by_disabling_pipelining on a source build:

    model1 28/0:  388 fallback compiles, 926.9s of a 1293.2s compile
    model1 19/0:   52 fallback compiles, 128.3s of a  167.7s compile
    model2 18/1:   71 fallback compiles, 146.5s of a  533.3s compile

The configs miss by a wide margin, so this is not a borderline estimate problem:

    device shared_memory_per_block_optin: 232448
    Required: 262144 / 294912 / 393216   (13% to 69% over)

Mean GPU utilization over one whole 166s compile is 5.6%, with 91% of samples
under 10%, because the phase reported as autotuning is really Triton compilation.
Meanwhile roughly 32 compile_threads workers sit idle for 86.8s.

max_autotune_prune_choices_based_on_shared_mem already drops these configs before
they reach the compiler; it was just off by default, on the grounds that the
estimate is an upper bound and may over-prune. Turning it on:

                     before      after     summed best kernel time
    model1 28/0     1364.2s     315.7s     246.0708ms -> 246.0401ms
    model1 19/0      166.5s      31.5s       5.8646ms ->   5.8651ms

Kernel choice does not measurably change. That is expected: the pruned configs
were the ones being silently rewritten to num_stages=1, and those rewrites lose
the autotune anyway. On 28/0 both runs autotune 145 kernels and pick the same
mix of extern and Triton winners.

Over-pruning is real, though. With pruning enabled the TMA addmm template lost
every config and compilation failed with NoValidChoicesError, because the
estimate does not model that template. So pruning now never empties the candidate
list: if every config looks too large, keep them all and let the compiler decide.
That preserves the win here, where many valid configs remain, and restores
today's behavior for any template the estimate mismodels.

Test Plan:

```
python -m pytest -q -p no:randomly test/inductor/test_triton_heuristics.py
# 54 passed, 4 skipped

python -m pytest -q -p no:randomly test/inductor/test_max_autotune.py
# 406 passed, 177 skipped

python -m pytest -q -p no:randomly \
  test/inductor/test_max_autotune.py::TestMaxAutotuneAsyncPipelined
# 147 passed, 91 skipped
```

test_triton_heuristics covers both settings of the flag explicitly, so flipping
the default does not change what it asserts. The full test_max_autotune run
reported one additional failure,
TestMaxAutotuneAsyncPipelined::test_triton_template_generated_code_caching_bmm,
which passes in isolation with and without this change and passes when its whole
class is run; its log shows a FileNotFoundError on a temporary cache path, so it
is cross-class order dependence rather than a regression here.

This commit was authored with the assistance of an AI agent (Claude Code).

ghstack-source-id: 2c313e1
Pull-Request: #194161

return [c for c in configs if not is_exceeding_shared_memory(c, dtype_size)]
pruned = [c for c in configs if not is_exceeding_shared_memory(c, dtype_size)]
# The estimate is an upper bound and does not model every template, so it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would it take to have this estimate (from max_autotune_prune_choices_based_on_shared_mem) account for all gemm templates? @njriasan and i have been discussing creating a static perf model for config selection (such that ideally, we never consider configs that exceed SMEM in the first place, and we also autotune just a small subset of configs to solve the compile time issue). could that be a more robust solution here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will be a better solution, yes. I am ok closing this PR if that work is close to be done.

But if that work is going to take some time, I think there is value in landing this because I have seen quite a few models suffering from this, and this will improve our OSS users life as well.

Comment thread torch/_inductor/config.py
# regresses for that reason.
max_autotune_prune_choices_based_on_shared_mem = (
os.environ.get("TORCHINDUCTOR_MAX_AUTOTUNE_PRUNE_CHOICES_BASED_ON_SHARED_MEM", "0")
os.environ.get("TORCHINDUCTOR_MAX_AUTOTUNE_PRUNE_CHOICES_BASED_ON_SHARED_MEM", "1")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering that the heuristics used in _prune_exceeding_max_shared_mem_configs may not extend to other gemms (addmm and bmm probably), not sure we can say with confidence that we should always use that pruning strategy (as you mentioned in the pr summary, we're likely to overprune). should we keep it off by default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it hard to believe that any gemm-based operator like addmm, bmm will prefer a config that exceeds smem size. If that happens to be the case, its most likely because our original config space were scarce in configs that fall inside the smem limit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this one - "Over-pruning is real, though. With pruning enabled the TMA addmm template lost
every config and compilation failed with NoValidChoicesError, because the
estimate does not model that template."

I am also ok if we want to make this more shallow and if there is a way to mark a template as being covered by smem modeling, and if not, we can skip pruning it.

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Aug 22, 2026
…ault

A GEMM template config whose shared memory footprint exceeds the device limit
compiles fine and then fails to build a launcher with OutOfResources. When no
config for that kernel survives, CachingAutotuner._make_launchers falls back to
rewriting the config with num_stages=1 and compiling the kernel a second time.
That second compile is cold, LLVM plus ptxas, and it runs serially in the
benchmarking path rather than in the precompile worker pool.

On internal models this is where most of compile time goes. Instrumenting
compile_by_disabling_pipelining on a source build:

    model1 28/0:  388 fallback compiles, 926.9s of a 1293.2s compile
    model1 19/0:   52 fallback compiles, 128.3s of a  167.7s compile
    model2 18/1:   71 fallback compiles, 146.5s of a  533.3s compile

The configs miss by a wide margin, so this is not a borderline estimate problem:

    device shared_memory_per_block_optin: 232448
    Required: 262144 / 294912 / 393216   (13% to 69% over)

Mean GPU utilization over one whole 166s compile is 5.6%, with 91% of samples
under 10%, because the phase reported as autotuning is really Triton compilation.
Meanwhile roughly 32 compile_threads workers sit idle for 86.8s.

max_autotune_prune_choices_based_on_shared_mem already drops these configs before
they reach the compiler; it was just off by default, on the grounds that the
estimate is an upper bound and may over-prune. Turning it on:

                     before      after     summed best kernel time
    model1 28/0     1364.2s     315.7s     246.0708ms -> 246.0401ms
    model1 19/0      166.5s      31.5s       5.8646ms ->   5.8651ms

Kernel choice does not measurably change. That is expected: the pruned configs
were the ones being silently rewritten to num_stages=1, and those rewrites lose
the autotune anyway. On 28/0 both runs autotune 145 kernels and pick the same
mix of extern and Triton winners.

Over-pruning is real, though. With pruning enabled the TMA addmm template lost
every config and compilation failed with NoValidChoicesError, because the
estimate does not model that template. So pruning now never empties the candidate
list: if every config looks too large, keep them all and let the compiler decide.
That preserves the win here, where many valid configs remain, and restores
today's behavior for any template the estimate mismodels.

Test Plan:

```
python -m pytest -q -p no:randomly test/inductor/test_triton_heuristics.py
# 54 passed, 4 skipped

python -m pytest -q -p no:randomly test/inductor/test_max_autotune.py
# 406 passed, 177 skipped

python -m pytest -q -p no:randomly \
  test/inductor/test_max_autotune.py::TestMaxAutotuneAsyncPipelined
# 147 passed, 91 skipped
```

test_triton_heuristics covers both settings of the flag explicitly, so flipping
the default does not change what it asserts. The full test_max_autotune run
reported one additional failure,
TestMaxAutotuneAsyncPipelined::test_triton_template_generated_code_caching_bmm,
which passes in isolation with and without this change and passes when its whole
class is run; its log shows a FileNotFoundError on a temporary cache path, so it
is cross-class order dependence rather than a regression here.

This commit was authored with the assistance of an AI agent (Claude Code).

ghstack-source-id: 91509ce
Pull-Request: #194161
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Aug 24, 2026
…ault

A GEMM template config whose shared memory footprint exceeds the device limit
compiles fine and then fails to build a launcher with OutOfResources. When no
config for that kernel survives, CachingAutotuner._make_launchers falls back to
rewriting the config with num_stages=1 and compiling the kernel a second time.
That second compile is cold, LLVM plus ptxas, and it runs serially in the
benchmarking path rather than in the precompile worker pool.

On internal models this is where most of compile time goes. Instrumenting
compile_by_disabling_pipelining on a source build:

    model1 28/0:  388 fallback compiles, 926.9s of a 1293.2s compile
    model1 19/0:   52 fallback compiles, 128.3s of a  167.7s compile
    model2 18/1:   71 fallback compiles, 146.5s of a  533.3s compile

The configs miss by a wide margin, so this is not a borderline estimate problem:

    device shared_memory_per_block_optin: 232448
    Required: 262144 / 294912 / 393216   (13% to 69% over)

Mean GPU utilization over one whole 166s compile is 5.6%, with 91% of samples
under 10%, because the phase reported as autotuning is really Triton compilation.
Meanwhile roughly 32 compile_threads workers sit idle for 86.8s.

max_autotune_prune_choices_based_on_shared_mem already drops these configs before
they reach the compiler; it was just off by default, on the grounds that the
estimate is an upper bound and may over-prune. Turning it on:

                     before      after     summed best kernel time
    model1 28/0     1364.2s     315.7s     246.0708ms -> 246.0401ms
    model1 19/0      166.5s      31.5s       5.8646ms ->   5.8651ms

Kernel choice does not measurably change. That is expected: the pruned configs
were the ones being silently rewritten to num_stages=1, and those rewrites lose
the autotune anyway. On 28/0 both runs autotune 145 kernels and pick the same
mix of extern and Triton winners.

Over-pruning is real, though. With pruning enabled the TMA addmm template lost
every config and compilation failed with NoValidChoicesError, because the
estimate does not model that template. So pruning now never empties the candidate
list: if every config looks too large, keep them all and let the compiler decide.
That preserves the win here, where many valid configs remain, and restores
today's behavior for any template the estimate mismodels.

Test Plan:

```
python -m pytest -q -p no:randomly test/inductor/test_triton_heuristics.py
# 54 passed, 4 skipped

python -m pytest -q -p no:randomly test/inductor/test_max_autotune.py
# 406 passed, 177 skipped

python -m pytest -q -p no:randomly \
  test/inductor/test_max_autotune.py::TestMaxAutotuneAsyncPipelined
# 147 passed, 91 skipped
```

test_triton_heuristics covers both settings of the flag explicitly, so flipping
the default does not change what it asserts. The full test_max_autotune run
reported one additional failure,
TestMaxAutotuneAsyncPipelined::test_triton_template_generated_code_caching_bmm,
which passes in isolation with and without this change and passes when its whole
class is run; its log shows a FileNotFoundError on a temporary cache path, so it
is cross-class order dependence rather than a regression here.

This commit was authored with the assistance of an AI agent (Claude Code).

ghstack-source-id: 73ac8ea
Pull-Request: #194161
return configs

return [c for c in configs if not is_exceeding_shared_memory(c, dtype_size)]
pruned = [c for c in configs if not is_exceeding_shared_memory(c, dtype_size)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can gate this (and the other changes in this PR) behind TORCHINDUCTOR_MAX_AUTOTUNE_PRUNE_CHOICES_BASED_ON_SHARED_MEM=1, keep the default as TORCHINDUCTOR_MAX_AUTOTUNE_PRUNE_CHOICES_BASED_ON_SHARED_MEM=0, and turn on this env var for models that need it?

@github-actions

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants