Skip to content

[inductor] Route flex decoding get_split_k SM count via DeviceInterface - #196736

Closed
huangfei1199 wants to merge 2 commits into
pytorch:mainfrom
huangfei1199:flex-decoding-device-decoupling
Closed

huangfei1199 wants to merge 2 commits into
pytorch:mainfrom
huangfei1199:flex-decoding-device-decoupling

Conversation

@huangfei1199

@huangfei1199 huangfei1199 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replace the hardcoded torch.xpu/torch.cuda if-chain in flex_decoding.get_split_k with a query against the kernel's target device through the DeviceInterface capability (#190615), so the SM count that feeds the SPLIT_KV heuristic is sourced from whichever device the decode kernel actually targets instead of ambient xpu/cuda detection. Existing behavior is preserved for single-device cuda and xpu environments (same SM count, same SPLIT_KV); mixed-backend machines now route correctly, and backends with no registered interface get a clear error instead of crashing inside CUDA device property initialization.

Changes

torch/_inductor/kernel/flex/flex_decoding.py: get_split_k now takes the kernel target device as a required keyword argument (device: torch.device) and resolves its SM count via get_interface_for_device(device), then interface.get_multi_processor_count(device). The lazy import of torch._dynamo.device_interface keeps the dynamo dependency off this module's load path (matching the style of other decoupling sites). The split_k formula (num_SM // bh * 2, floored to 1) is unchanged -- only the source of num_SM moves from a hardcoded device string / is_available() probe to the device's own registered interface. The single call site (create_flex_decoding_kernel) now reads device = query.get_device() (the surrounding code already queried query.get_device().type two lines above) and passes it through, which also fixes a latent multi-card inaccuracy where the old code used the default "xpu"/"cuda" device instead of the kernel's actual device index.

Motivation

get_split_k feeds SPLIT_KV, which sizes the decode KV intermediate buffer (buf_ACC_shape). The original if-chain asked the ambient environment ("is xpu available?") rather than "which device is this kernel for": on a machine with both xpu and cuda, every cuda decode kernel wrongly took the xpu branch; on a machine with neither (mtia-only, cpu-triton), the code crashed inside torch.cuda device-property initialization with no path to a usable value; tpu and out-of-tree accelerators had no legal path at all. The DeviceInterface registry already exposes get_multi_processor_count (added in #190615, already consumed by hints.py): cuda reads the standard multi_processor_count field, xpu overrides with gpu_subslice_count, mtia defaults to 64. Routing get_split_k through the same contract lets each backend report its own SM count for the device the kernel actually targets, and surfaces a clear AttributeError ("must override") for a backend whose interface has not yet been adapted -- pointing the backend author at the one method to override -- instead of an opaque CUDA init failure.

Test Plan

CI: python -m pytest -q test/inductor/test_flex_attention.py CI: python test/inductor/test_flex_attention.py
CI: lintrunner -a torch/_inductor/kernel/flex/flex_decoding.py

Verified on GPU (cuda): flex decode end-to-end passes (the device matrix tests cover the SPLIT_KV-shaped buffer indirectly). Verified on CPU: pytest 2 passed, 582 skipped, 0 failed; python direct run 584 tests, OK (skipped=582). Same result in NPU mode and CPU mode. Verified on an Ascend NPU container: pytest 2 passed, 582 skipped, 0 failed in both NPU mode and CPU mode; the mainline get_split_k path is not reached on NPU (torch_npu overrides the flex decode lowering), so this confirms non-regression and import/collection integrity. lintrunner reports 0 violations on the changed file.

No new tests added: the existing decode end-to-end device matrix tests already cover SPLIT_KV indirectly (a changed value resizes buf_ACC_shape and turns the test red), and the must-override contract get_split_k now relies on is already tested by test_device_backend_hooks.py::TestMultiProcessorCount ::test_missing_standard_property (#190615). A standalone unit test for the formula / routing would be zero-increment over that coverage, so it is omitted to keep the PR a minimal source-only diff.

Notes

Behavior preservation: for any single-device cuda or xpu CI environment the SM count is identical to before (cuda reads the same multi_processor_count field; xpu's override returns the same gpu_subslice_count), so SPLIT_KV is unchanged and the formula is untouched. The behavioral changes are all on paths the old code could not handle correctly:

  • On a mixed xpu+cuda machine, a cuda decode kernel now reads multi_processor_count instead of wrongly taking the xpu branch. This is a bug fix; single-device CI is structurally unaffected.
  • On an mtia-only / no-xpu-no-cuda machine, the previous CUDA-init crash becomes a usable value (mtia default 64).
  • For an out-of-tree DeviceInterface that has not yet overridden get_multi_processor_count, the previous opaque crash becomes a clear AttributeError("must override") pointing at the method to implement; once the backend overrides it (returning its SM count), the decode heuristic works without a mainline patch. Part of the hardware decoupling effort: remove hardcoded device lists so backends register capability through their DeviceInterface instead. Authored with an AI assistant (Claude).

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

@pytorch-bot

pytorch-bot Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 57af077 with merge base 03ea905 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot

pytorch-bot Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@pytorch-bot

pytorch-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/inductor
  • ciflow/torchtitan

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@huangfei1199
huangfei1199 marked this pull request as draft September 11, 2026 09:46
@huangfei1199
huangfei1199 marked this pull request as ready for review September 17, 2026 08:53
@huangfei1199

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: inductor"

@liangel-02 liangel-02 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 17, 2026
@jansel

jansel commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

@claude review these changes

@claude

claude Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 1m 10s —— View job


Small, correct change: device routing through DeviceInterface gives the same SM count on CUDA and XPU. A few cleanups and a missing regression test block approval.

PR Review: #196736

Summary

The PR changes get_split_k so it gets the SM count from the decode kernel's own device through get_interface_for_device(device).get_multi_processor_count(device), replacing the ambient torch.xpu.is_available() / torch.cuda check. The routing is correct. CUDA and XPU give the same values as before: the XPU override falls back to gpu_subslice_count, and torch/csrc/xpu/Module.cpp exposes no multi_processor_count. I found no other callers of get_split_k, so the signature change is safe. The problems below are cleanups plus a missing test for the bug the PR says it fixes.

Code Quality

  • flex_decoding.py:159-162: the lazy import is justified by a false claim. The comment says the function-local import "keeps the dynamo dependency off this module's load path". But this module already imports ...select_algorithm at module level, and select_algorithm.py:32 does from torch._dynamo.device_interface import get_interface_for_device at top level. The same top-level import appears in utils.py, codegen/triton.py, autotune_process.py and elsewhere in inductor. Use a top-level from torch._dynamo.device_interface import get_interface_for_device and delete the comment. The comment also describes the PR's motivation rather than anything a reader needs, which conflicts with the CLAUDE.md style rules.
  • flex_decoding.py:158: the signature is unusual for no reason. def get_split_k(B, H, Mk, /, *, device) adds positional-only and keyword-only markers that nothing in this file uses. Plain def get_split_k(B: int, H: int, Mk: int, device: torch.device) -> int: matches the surrounding helpers.
  • flex_decoding.py:286-289: the new device local only feeds one call. query.get_device() is still called at lines 248, 280, 299, 305 and 309. Hoist device = query.get_device() near the top of create_flex_decoding_kernel and reuse it everywhere. That also lets the setdefault call go back to a single line, which CLAUDE.md prefers over the ruff line split.
  • flex_decoding.py:287: setdefault still evaluates get_split_k when the user passes SPLIT_KV. The PR argues an out-of-tree backend should get a clear "must override" error. But that backend still errors even when the user has passed kernel_options={"SPLIT_KV": ...} and doesn't need the heuristic. Guard it: if "SPLIT_KV" not in kernel_options: kernel_options["SPLIT_KV"] = get_split_k(...).

Testing

  • No regression test for the routing fix. The PR says it fixes two bugs: the wrong branch on a mixed XPU+CUDA machine, and the wrong device index on multi-GPU machines. The existing end-to-end tests only run on single-backend machines, so neither path is covered, and a revert would pass CI. A cheap unit test would patch the interface's get_multi_processor_count and assert that get_split_k(B, H, Mk, device=torch.device("cuda", 1)) queries that interface with cuda:1 and returns num_SM // (B*H) * 2. That runs without special hardware. Put it in test/inductor/test_flex_decoding.py (or next to TestMultiProcessorCount) using TestCase / run_tests.

Recommendation

Request Changes

The logic is sound. What blocks approval is the regression test for the bug fix, plus the small cleanups: the top-level import, the plain signature, hoisting device, and the SPLIT_KV guard.

@huangfei1199

Copy link
Copy Markdown
Contributor Author

Claude finished @jansel's task in 1m 10s —— View job

Small, correct change: device routing through DeviceInterface gives the same SM count on CUDA and XPU. A few cleanups and a missing regression test block approval.

PR Review: #196736

Thanks, all points are addressed in 350f68d. The regression test (TestGetSplitKDeviceRouting) is included in the same commit, and I've manually verified it in a container.

@jansel

jansel commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

@claude review again

@claude

claude Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 49s —— View job


Every point from the previous review is fixed in 350f68d, and one small test-style item is left.

PR Review: #196736 (re-review)

Summary

The PR makes get_split_k get the SM count from the decode kernel's own device through get_interface_for_device(device).get_multi_processor_count(device), and adds a regression test for that routing. I checked each previous point against the new diff:

  • The import is now at the top level.
  • The signature is plain.
  • device = query.get_device() is hoisted and reused at every call site.
  • get_split_k is skipped when the user passes SPLIT_KV.
  • A regression test was added.

The test would fail on the old code: the old code never calls the interface, and it reads torch.cuda's default device instead of cuda:1. It also runs on CPU-only CI, because get_interface_for_device only looks up the registry and the patched method never touches the device. There is one remaining issue.

Testing

  • test/inductor/test_flex_decoding.py:2410: TestGetSplitKDeviceRouting derives from common_utils.TestCase, while the other class in this file (TestFlexDecoding, line 356) uses InductorTestCase. The file's run_tests also comes from torch._inductor.test_case. Use InductorTestCase for consistency. It resets dynamo/inductor state between tests, so this test can't leak state into the rest of the file or pick it up from earlier tests.

Recommendation

Approve once the base class is switched. The logic is correct: CUDA and XPU keep the same SM count, and the routing bug now has a regression test.

@huangfei1199

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 8, 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: 1 jobs have failed, first few of them are: docs-build / linux-docs / build-docs-cpp-false

Details for Dev Infra team Raised by workflow job

@huangfei1199

Copy link
Copy Markdown
Contributor Author

@jansel The docs‑build failure is infra issue unrelated to this PR, same error seen before. Could you please rerun the failed jobs to unblock merge? Thanks!

@jansel

jansel commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased flex-decoding-device-decoupling onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout flex-decoding-device-decoupling && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the flex-decoding-device-decoupling branch from 350f68d to 0e7879b Compare October 8, 2026 03:39
@huangfei1199

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@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: 1 jobs have failed, first few of them are: trunk / macos-py3-arm64 / test (default, 3, 3, macos-m1-stable)

Details for Dev Infra team Raised by workflow job

@huangfei1199

Copy link
Copy Markdown
Contributor Author

@jansel Merge is still blocked by a single job: trunk / macos-py3-arm64 --inductor/test_remote_cache died with SIGBUS before pytest started (Dr. CI verdict: infra issue). Could you re-run the failed jobs on
https://github.com/pytorch/pytorch/actions/runs/37724120958 ? Thanks!

@jansel

jansel commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge -r

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

## Summary
Replace the hardcoded torch.xpu/torch.cuda if-chain in
flex_decoding.get_split_k with a query against the kernel's target device
through the DeviceInterface capability (pytorch#190615), so the SM count that feeds
the SPLIT_KV heuristic is sourced from whichever device the decode kernel
actually targets instead of ambient xpu/cuda detection. Existing behavior is
preserved for single-device cuda and xpu environments (same SM count, same
SPLIT_KV); mixed-backend machines now route correctly, and backends with no
registered interface get a clear error instead of crashing inside CUDA device
property initialization.

## Changes
torch/_inductor/kernel/flex/flex_decoding.py: get_split_k now takes the kernel
target device as a required keyword argument (`device: torch.device`) and
resolves its SM count via get_interface_for_device(device), then
interface.get_multi_processor_count(device). The lazy import of
torch._dynamo.device_interface keeps the dynamo dependency off this module's
load path (matching the style of other decoupling sites). The split_k formula
(num_SM // bh * 2, floored to 1) is unchanged -- only the source of num_SM
moves from a hardcoded device string / is_available() probe to the device's
own registered interface. The single call site (create_flex_decoding_kernel)
now reads `device = query.get_device()` (the surrounding code already queried
query.get_device().type two lines above) and passes it through, which also
fixes a latent multi-card inaccuracy where the old code used the default
"xpu"/"cuda" device instead of the kernel's actual device index.

## Motivation
get_split_k feeds SPLIT_KV, which sizes the decode KV intermediate buffer
(buf_ACC_shape). The original if-chain asked the ambient environment
("is xpu available?") rather than "which device is this kernel for": on a
machine with both xpu and cuda, every cuda decode kernel wrongly took the xpu
branch; on a machine with neither (mtia-only, cpu-triton), the code crashed
inside torch.cuda device-property initialization with no path to a usable
value; tpu and out-of-tree accelerators had no legal path at all. The
DeviceInterface registry already exposes get_multi_processor_count (added in
pytorch#190615, already consumed by hints.py): cuda reads the standard
multi_processor_count field, xpu overrides with gpu_subslice_count, mtia
defaults to 64. Routing get_split_k through the same contract lets each
backend report its own SM count for the device the kernel actually targets,
and surfaces a clear AttributeError ("must override") for a backend whose
interface has not yet been adapted -- pointing the backend author at the one
method to override -- instead of an opaque CUDA init failure.

## Test Plan
CI: python -m pytest -q test/inductor/test_flex_attention.py
CI: python test/inductor/test_flex_attention.py
CI: lintrunner -a torch/_inductor/kernel/flex/flex_decoding.py

Verified on GPU (cuda): flex decode end-to-end passes (the device matrix
tests cover the SPLIT_KV-shaped buffer indirectly).
Verified on CPU: pytest 2 passed, 582 skipped, 0 failed; python direct run
584 tests, OK (skipped=582). Same result in NPU mode and CPU mode.
Verified on an Ascend NPU container: pytest 2 passed, 582 skipped, 0 failed
in both NPU mode and CPU mode; the mainline get_split_k path is not reached
on NPU (torch_npu overrides the flex decode lowering), so this confirms
non-regression and import/collection integrity. lintrunner reports 0
violations on the changed file.

No new tests added: the existing decode end-to-end device matrix tests
already cover SPLIT_KV indirectly (a changed value resizes buf_ACC_shape and
turns the test red), and the must-override contract get_split_k now relies on
is already tested by test_device_backend_hooks.py::TestMultiProcessorCount
::test_missing_standard_property (pytorch#190615). A standalone unit test for the
formula / routing would be zero-increment over that coverage, so it is
omitted to keep the PR a minimal source-only diff.

## Notes
Behavior preservation: for any single-device cuda or xpu CI environment the
SM count is identical to before (cuda reads the same multi_processor_count
field; xpu's override returns the same gpu_subslice_count), so SPLIT_KV is
unchanged and the formula is untouched. The behavioral changes are all on
paths the old code could not handle correctly:
- On a mixed xpu+cuda machine, a cuda decode kernel now reads
  multi_processor_count instead of wrongly taking the xpu branch. This is a
  bug fix; single-device CI is structurally unaffected.
- On an mtia-only / no-xpu-no-cuda machine, the previous CUDA-init crash
  becomes a usable value (mtia default 64).
- For an out-of-tree DeviceInterface that has not yet overridden
  get_multi_processor_count, the previous opaque crash becomes a clear
  AttributeError("must override") pointing at the method to implement;
  once the backend overrides it (returning its SM count), the decode
  heuristic works without a mainline patch.
Part of the hardware decoupling effort: remove hardcoded device lists so
backends register capability through their DeviceInterface instead.
Authored with an AI assistant (Claude).
Import get_interface_for_device at module top level and drop the stale
lazy-import comment, flatten get_split_k to a plain positional signature,
hoist `device = query.get_device()` to the top of create_flex_decoding_kernel,
skip the get_split_k call when the user already passed SPLIT_KV, and add a
CPU-runnable regression test pinning that the SM count is queried from the
kernel's own device rather than ambient backend state.

Test Plan:
```
python test/inductor/test_flex_decoding.py -k TestGetSplitKDeviceRouting -v
```

Authored with an AI assistant.

Signed-off-by: huangfei1199 <[email protected]>
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased flex-decoding-device-decoupling onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout flex-decoding-device-decoupling && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the flex-decoding-device-decoupling branch from 0e7879b to 57af077 Compare October 8, 2026 16:48
@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: 3 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@jansel

jansel commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@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

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@huangfei1199

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@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

cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
…ce (pytorch#196736)

## Summary
Replace the hardcoded torch.xpu/torch.cuda if-chain in flex_decoding.get_split_k with a query against the kernel's target device through the DeviceInterface capability (pytorch#190615), so the SM count that feeds the SPLIT_KV heuristic is sourced from whichever device the decode kernel actually targets instead of ambient xpu/cuda detection. Existing behavior is preserved for single-device cuda and xpu environments (same SM count, same SPLIT_KV); mixed-backend machines now route correctly, and backends with no registered interface get a clear error instead of crashing inside CUDA device property initialization.

## Changes
torch/_inductor/kernel/flex/flex_decoding.py: get_split_k now takes the kernel target device as a required keyword argument (`device: torch.device`) and resolves its SM count via get_interface_for_device(device), then interface.get_multi_processor_count(device). The lazy import of torch._dynamo.device_interface keeps the dynamo dependency off this module's load path (matching the style of other decoupling sites). The split_k formula (num_SM // bh * 2, floored to 1) is unchanged -- only the source of num_SM moves from a hardcoded device string / is_available() probe to the device's own registered interface. The single call site (create_flex_decoding_kernel) now reads `device = query.get_device()` (the surrounding code already queried query.get_device().type two lines above) and passes it through, which also fixes a latent multi-card inaccuracy where the old code used the default "xpu"/"cuda" device instead of the kernel's actual device index.

## Motivation
get_split_k feeds SPLIT_KV, which sizes the decode KV intermediate buffer (buf_ACC_shape). The original if-chain asked the ambient environment ("is xpu available?") rather than "which device is this kernel for": on a machine with both xpu and cuda, every cuda decode kernel wrongly took the xpu branch; on a machine with neither (mtia-only, cpu-triton), the code crashed inside torch.cuda device-property initialization with no path to a usable value; tpu and out-of-tree accelerators had no legal path at all. The DeviceInterface registry already exposes get_multi_processor_count (added in pytorch#190615, already consumed by hints.py): cuda reads the standard multi_processor_count field, xpu overrides with gpu_subslice_count, mtia defaults to 64. Routing get_split_k through the same contract lets each backend report its own SM count for the device the kernel actually targets, and surfaces a clear AttributeError ("must override") for a backend whose interface has not yet been adapted -- pointing the backend author at the one method to override -- instead of an opaque CUDA init failure.

## Test Plan
CI: python -m pytest -q test/inductor/test_flex_attention.py CI: python test/inductor/test_flex_attention.py
CI: lintrunner -a torch/_inductor/kernel/flex/flex_decoding.py

Verified on GPU (cuda): flex decode end-to-end passes (the device matrix tests cover the SPLIT_KV-shaped buffer indirectly). Verified on CPU: pytest 2 passed, 582 skipped, 0 failed; python direct run 584 tests, OK (skipped=582). Same result in NPU mode and CPU mode. Verified on an Ascend NPU container: pytest 2 passed, 582 skipped, 0 failed in both NPU mode and CPU mode; the mainline get_split_k path is not reached on NPU (torch_npu overrides the flex decode lowering), so this confirms non-regression and import/collection integrity. lintrunner reports 0 violations on the changed file.

No new tests added: the existing decode end-to-end device matrix tests already cover SPLIT_KV indirectly (a changed value resizes buf_ACC_shape and turns the test red), and the must-override contract get_split_k now relies on is already tested by test_device_backend_hooks.py::TestMultiProcessorCount ::test_missing_standard_property (pytorch#190615). A standalone unit test for the formula / routing would be zero-increment over that coverage, so it is omitted to keep the PR a minimal source-only diff.

## Notes
Behavior preservation: for any single-device cuda or xpu CI environment the SM count is identical to before (cuda reads the same multi_processor_count field; xpu's override returns the same gpu_subslice_count), so SPLIT_KV is unchanged and the formula is untouched. The behavioral changes are all on paths the old code could not handle correctly:
- On a mixed xpu+cuda machine, a cuda decode kernel now reads multi_processor_count instead of wrongly taking the xpu branch. This is a bug fix; single-device CI is structurally unaffected.
- On an mtia-only / no-xpu-no-cuda machine, the previous CUDA-init crash becomes a usable value (mtia default 64).
- For an out-of-tree DeviceInterface that has not yet overridden get_multi_processor_count, the previous opaque crash becomes a clear AttributeError("must override") pointing at the method to implement; once the backend overrides it (returning its SM count), the decode heuristic works without a mainline patch. Part of the hardware decoupling effort: remove hardcoded device lists so backends register capability through their DeviceInterface instead. Authored with an AI assistant (Claude).

Pull Request resolved: pytorch#196736
Approved by: https://github.com/jansel, https://github.com/drisspg
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 open source release notes: inductor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants