Skip to content

[Inductor] Split very large reductions out of combo kernel partitioning - #186668

Closed
karthickai wants to merge 2 commits into
gh/karthickai/90/basefrom
gh/karthickai/90/head
Closed

karthickai wants to merge 2 commits into
gh/karthickai/90/basefrom
gh/karthickai/90/head

Conversation

@karthickai

@karthickai karthickai commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

🔗 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 SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure, 1 Unrelated Failure

As of commit a571ca8 with merge base 083e261 (image):

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.

@karthickai
karthickai marked this pull request as draft June 8, 2026 23:18
@karthickai
karthickai requested a review from eellison June 10, 2026 19:52
@karthickai
karthickai marked this pull request as ready for review June 10, 2026 19:53

@eellison eellison left a comment

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.

lgtm although as discussed offline this will be solved generically by not combining kernels with largely different num warps

@karthickai

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 10, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 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 team Raised by workflow job

[ghstack-poisoned]
karthickai added a commit that referenced this pull request Jun 12, 2026
@karthickai

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request Sep 2, 2026
…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
Sanskaaar1 pushed a commit to Sanskaaar1/pytorch that referenced this pull request Sep 8, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor release notes: inductor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants