Repository navigation
Fix device-dependent kernel count in test_combo_kernel_split_large_reductions - #195564
Closed
ZhaoqiongZ wants to merge 2 commits into
Closed
ZhaoqiongZ wants to merge 2 commits into
ZhaoqiongZ wants to merge 2 commits into
Conversation
…ductions
test_combo_kernel_split_large_reductions guards one invariant, stated in its
own comment: the two very large reductions (sum over [0,2,3] of
[512,64,55,55]) must not be co-fused into a single combo kernel. It asserted
that invariant indirectly, via an absolute total kernel count
(generated_kernel_count == 5). That total is device dependent, so the test
fails on Intel BMG with "Expected 5 but got 4" while passing on PVC.
Root cause: both reductions have numel=64, rnumel=1548800.
InductorChoices.reduction_split_factor (torch/_inductor/choices.py:580)
returns 1 as soon as numel_hint >= 2 * multi_processor_count. BMG reports
multi_processor_count=20, so 64 >= 40 holds and neither reduction is split
into a partial+final pair; PVC-class hardware reports 64, the same call
returns 12, each reduction becomes two kernels, the two small finals co-fuse,
and the total lands on 5. The asserted 5 is simply unreachable on a 20-SM GPU.
Worse, the count could not distinguish correct from regressed codegen there.
Measured on this hardware:
correct co-fused (the regression)
BMG (20 SM) 4 3
PVC-sim (64) 5 4
so 4 -- which the old comment labelled "the regression" -- is BMG's correct
value, and on BMG the old assertion failed on correct codegen and would have
kept failing on regressed codegen for a different reason.
The fix asserts 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. Co-fusion emits both sub-kernels inside one
async_compile.triton block, which drops the count to 1 on every
configuration, so the regression is still caught. Reading generated code
means codegen must actually run, hence the fresh_cache() wrapper -- the same
pattern the neighbouring run_and_get_code tests in this file use.
The alternative was to keep an absolute count and make it conditional on
multi_processor_count. That encodes a split-reduction heuristic the test does
not care about into a combo-kernel partitioning test, and would need updating
whenever that heuristic changes; asserting the guarded invariant is both
narrower and device independent.
Test Plan:
Ran the fixed test on an Intel BMG GPU (Arc Pro B60,
multi_processor_count=20), both the base class and the
per-subkernel-blocks subclass:
```
pytest -sv test/inductor/test_combo_kernels.py \
-k "test_combo_kernel_split_large_reductions"
```
Both pass (previously both failed with "Expected 5 but got 4").
Confirmed the new assertion retains its regression power by re-enabling
co-fusion -- raising only the partitioner's LARGE_NUMELS, after the test
module has already bound the real 51_200_000 for its own gate -- and
re-running the same two node ids: both fail with "Expected 2 but got 1".
Confirmed device independence by forcing DeviceProperties.multi_processor_count
to a PVC-like 64 (the only device property the old total depended on): both
node ids pass on correct codegen and both fail when co-fusion is re-enabled.
The full 2x2 matrix of {BMG, PVC-sim} x {correct, regressed} therefore agrees.
Also applied the assertion's logic to the six captured code dumps: 2 for each
of the three correct-codegen dumps, 1 for each of the three co-fused dumps.
This change was authored with the assistance of an AI coding agent (Claude).
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195564
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit ba29c9b with merge base 717f18c ( CRCR (non-blocking) - The following CRCR downstream CI job failed but is non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
etaf
reviewed
Sep 2, 2026
karthickai
approved these changes
Sep 2, 2026
Collaborator
Author
|
@pytorchbot merge |
Collaborator
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 |
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
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.
test_combo_kernel_split_large_reductionsfails on Intel BMG withExpected 5 but got 4while passing on PVC.Root cause
The test was added in #186668 together with the
very_large_reductionpartitioning 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 oncenumel_hint >= 2 * multi_processor_count. BMG reportsmulti_processor_count=20, so64 >= 40holds 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:
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_partitionshows 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_NUMELSgate the partitioner itself applies, and require exactly 2.xnumel * rnumelis 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 onmulti_processor_count. Co-fusion emits both sub-kernels inside a singleasync_compile.tritonblock, 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 neighbouringrun_and_get_codetests 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:pytest -sv test/inductor/test_combo_kernels.py -k "test_combo_kernel_split_large_reductions"Expected 5 but got 4)Expected 2 but got 1multi_processor_count=64), correct codegenThe 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 real51_200_000for its own gate.lintrunner -a test/inductor/test_combo_kernels.pyreports no issues.Fixes intel/torch-xpu-ops#5079
This change was authored with the assistance of an AI coding agent (Claude).
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo