Repository navigation
[inductor] Prune GEMM configs that cannot fit in shared memory by default - #194161
anijain2305 wants to merge 5 commits into
Conversation
[ghstack-poisoned]
🔗 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 FailureAs of commit cda2e59 with merge base 6a0eb75 ( 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:
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. |
This PR needs a
|
…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
[ghstack-poisoned]
…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]
…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
…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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| # 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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]
…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]
…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)] |
There was a problem hiding this comment.
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?
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
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:
The configs miss by a wide margin, so this is not a borderline estimate problem:
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:
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:
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