Repository navigation
[Inductor] Split very large reductions out of combo kernel partitioning - #186668
karthickai wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/186668
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 1 New Failure, 1 Unrelated FailureAs of commit a571ca8 with merge base 083e261 ( NEW FAILURE - The following job has failed:
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. |
eellison
left a comment
There was a problem hiding this comment.
lgtm although as discussed offline this will be solved generically by not combining kernels with largely different num warps
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 2 jobs have failed, first few of them are: trunk / win-vs2022-cuda13.0-py3 / build, trunk / win-vs2022-cpu-py3 / build Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 2 checks: torchtitan-test / torchtitan-x-pytorch-test / test-osdc (torchtitan_models_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8), torchtitan-test / torchtitan-x-pytorch-test / test-osdc (torchtitan_features_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…ductions (#195564) `test_combo_kernel_split_large_reductions` fails on Intel BMG with `Expected 5 but got 4` while passing on PVC. ## Root cause The test was added in #186668 together with the `very_large_reduction` partitioning rule it guards: the two very large reductions (sum over `[0,2,3]` of `[512,64,55,55]`) must not be co-fused into one combo kernel. It asserts that invariant indirectly, via an absolute total kernel count (`generated_kernel_count == 5`), and one of those 5 kernels comes from an unrelated, SM-count-dependent heuristic. Both reductions have `numel=64`, `rnumel=1548800`. `InductorChoices.reduction_split_factor` (`torch/_inductor/choices.py:580`) returns 1 once `numel_hint >= 2 * multi_processor_count`. BMG reports `multi_processor_count=20`, so `64 >= 40` holds and neither reduction is split. A 64-SM part makes the same call return 12: each reduction becomes a partial + final pair, the two small finals co-fuse, and the total reaches 5. The asserted 5 is unreachable on a 20-SM GPU. The total also cannot distinguish correct from regressed codegen there: | | correct codegen | co-fused (the regression) | |-----------------|-----------------|---------------------------| | BMG (20 SM) | **4** | 3 | | PVC-sim (64 SM) | **5** | 4 | So 4 — which the old comment labelled "the regression" — is BMG's *correct* value. The guarded behaviour itself is intact on BMG: instrumenting `_default_custom_combo_kernel_horizontal_partition` shows the two reductions landing in separate partitions `[['op2'], ['op3']]`, exactly as the comment requires. ## Fix Assert the invariant directly instead of a proxy for it: count the generated kernels that contain a very large reduction, using the same `xnumel * rnumel > LARGE_NUMELS` gate the partitioner itself applies, and require exactly 2. `xnumel * rnumel` is conserved when a reduction is split — both the unsplit kernel (`64 * 1548800`) and the partial (`768 * 129067`) carry the graph's ~99.1M element total — so the count does not depend on `multi_processor_count`. Co-fusion emits both sub-kernels inside a single `async_compile.triton` block, dropping the count to 1 on every configuration, so the regression is still caught. `fresh_cache()` is added because the assertion reads generated code, the same pattern the neighbouring `run_and_get_code` tests in this file use. The test is defined once and inherited by `ComboKernelTestsPerSubkernelBlocks`, so one edit covers both failing node ids. ## Test plan On an Intel BMG GPU (Arc Pro B60, `multi_processor_count=20`), both node ids: ```bash pytest -sv test/inductor/test_combo_kernels.py -k "test_combo_kernel_split_large_reductions" ``` | Configuration | Result | |---|---| | Fixed test | **2 passed** (was: 2 failed, `Expected 5 but got 4`) | | Regression reintroduced (co-fusion re-enabled) | **2 failed**, `Expected 2 but got 1` | | PVC-sim (`multi_processor_count=64`), correct codegen | **2 passed** | | PVC-sim, regression reintroduced | **2 failed** | The full 2x2 matrix of {BMG, PVC-sim} x {correct, regressed} agrees, so the new assertion is device independent and keeps its regression power. Co-fusion was reintroduced by raising only the partitioner's `LARGE_NUMELS`, after the test module had already bound the real `51_200_000` for its own gate. `lintrunner -a test/inductor/test_combo_kernels.py` reports no issues. Fixes intel/torch-xpu-ops#5079 <sub>This change was authored with the assistance of an AI coding agent (Claude).</sub> Pull Request resolved: #195564 Approved by: https://github.com/etaf, https://github.com/karthickai
…ductions (pytorch#195564) `test_combo_kernel_split_large_reductions` fails on Intel BMG with `Expected 5 but got 4` while passing on PVC. ## Root cause The test was added in pytorch#186668 together with the `very_large_reduction` partitioning rule it guards: the two very large reductions (sum over `[0,2,3]` of `[512,64,55,55]`) must not be co-fused into one combo kernel. It asserts that invariant indirectly, via an absolute total kernel count (`generated_kernel_count == 5`), and one of those 5 kernels comes from an unrelated, SM-count-dependent heuristic. Both reductions have `numel=64`, `rnumel=1548800`. `InductorChoices.reduction_split_factor` (`torch/_inductor/choices.py:580`) returns 1 once `numel_hint >= 2 * multi_processor_count`. BMG reports `multi_processor_count=20`, so `64 >= 40` holds and neither reduction is split. A 64-SM part makes the same call return 12: each reduction becomes a partial + final pair, the two small finals co-fuse, and the total reaches 5. The asserted 5 is unreachable on a 20-SM GPU. The total also cannot distinguish correct from regressed codegen there: | | correct codegen | co-fused (the regression) | |-----------------|-----------------|---------------------------| | BMG (20 SM) | **4** | 3 | | PVC-sim (64 SM) | **5** | 4 | So 4 — which the old comment labelled "the regression" — is BMG's *correct* value. The guarded behaviour itself is intact on BMG: instrumenting `_default_custom_combo_kernel_horizontal_partition` shows the two reductions landing in separate partitions `[['op2'], ['op3']]`, exactly as the comment requires. ## Fix Assert the invariant directly instead of a proxy for it: count the generated kernels that contain a very large reduction, using the same `xnumel * rnumel > LARGE_NUMELS` gate the partitioner itself applies, and require exactly 2. `xnumel * rnumel` is conserved when a reduction is split — both the unsplit kernel (`64 * 1548800`) and the partial (`768 * 129067`) carry the graph's ~99.1M element total — so the count does not depend on `multi_processor_count`. Co-fusion emits both sub-kernels inside a single `async_compile.triton` block, dropping the count to 1 on every configuration, so the regression is still caught. `fresh_cache()` is added because the assertion reads generated code, the same pattern the neighbouring `run_and_get_code` tests in this file use. The test is defined once and inherited by `ComboKernelTestsPerSubkernelBlocks`, so one edit covers both failing node ids. ## Test plan On an Intel BMG GPU (Arc Pro B60, `multi_processor_count=20`), both node ids: ```bash pytest -sv test/inductor/test_combo_kernels.py -k "test_combo_kernel_split_large_reductions" ``` | Configuration | Result | |---|---| | Fixed test | **2 passed** (was: 2 failed, `Expected 5 but got 4`) | | Regression reintroduced (co-fusion re-enabled) | **2 failed**, `Expected 2 but got 1` | | PVC-sim (`multi_processor_count=64`), correct codegen | **2 passed** | | PVC-sim, regression reintroduced | **2 failed** | The full 2x2 matrix of {BMG, PVC-sim} x {correct, regressed} agrees, so the new assertion is device independent and keeps its regression power. Co-fusion was reintroduced by raising only the partitioner's `LARGE_NUMELS`, after the test module had already bound the real `51_200_000` for its own gate. `lintrunner -a test/inductor/test_combo_kernels.py` reports no issues. Fixes intel/torch-xpu-ops#5079 <sub>This change was authored with the assistance of an AI coding agent (Claude).</sub> Pull Request resolved: pytorch#195564 Approved by: https://github.com/etaf, https://github.com/karthickai
Stack from ghstack (oldest at bottom):
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo