Skip to content

[inductor] Only run is_big_gpu SM check when GEMM templates are in play - #192375

Closed
rgbkrk wants to merge 2 commits into
pytorch:mainfrom
rgbkrk:fix-spurious-sm-warning
Closed

rgbkrk wants to merge 2 commits into
pytorch:mainfrom
rgbkrk:fix-spurious-sm-warning

Conversation

@rgbkrk

@rgbkrk rgbkrk commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

On Apple silicon, using the MPS backend, torch.compile emits a “Not enough SMs” warning. That warning is confusing: MPS is running on an Apple GPU, and neither Triton nor CUTLASS templates are candidates.

AI-generated summary, reviewed by me:

use_triton_template and use_cutlass_template evaluated the GPU-size heuristic before checking whether autotuning and the relevant template backend were enabled. Consequently, default-mode MPS compilation could report “Not enough SMs” even though neither Triton nor CUTLASS templates were candidates.

Reorder the eligibility checks so unsupported template paths short-circuit before is_big_gpu. The existing small-GPU heuristic still applies whenever a template is genuinely under consideration.

Testing:

  • With Inductor caches disabled, stock PyTorch 2.10 emitted the warning.
  • Applying the reordered Triton predicate suppressed the warning and compilation succeeded.

AI assistance disclosure: Claude prepared the implementation under human direction. Codex reviewed it against current main, verified the reproduction, and rebased the branch.

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 Aug 6, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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 a516fbe with merge base 3601a49 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: rgbkrk / name: Kyle Kelley (80b10d4)

@pytorch-bot

pytorch-bot Bot commented Aug 6, 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 Aug 6, 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.

@rgbkrk

rgbkrk commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

CLA now signed

@rgbkrk

rgbkrk commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

This fixes a user-visible warning on the MPS backend, so the MPS release-note category is the most relevant.

@pytorchbot label "release notes: mps"

@pytorch-bot pytorch-bot Bot added the release notes: mps Release notes category label Aug 6, 2026

@kurtamohler kurtamohler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know too much about inductor, but this seems reasonable to me

Comment thread torch/_inductor/utils.py Resolved
@jansel

jansel commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

@claude review this, will it change the behavior of any non-MPS backends?

@claude

claude Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

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


Review: does this change behavior on non-MPS backends?

Short answer: no functional change on any backend — the return values are identical. What changes on non-MPS backends is when the log lines fire (fewer/later warnings), plus one narrow edge case worth a look.

Detailed analysis

Tasks

  • Read the diff (git diff HEAD~2 HEAD -- torch/_inductor/utils.py)
  • Trace _use_template_for_gpu / is_big_gpu / has_backend_feature for side effects
  • Enumerate all callers of use_triton_template / use_cutlass_template / is_big_gpu
  • Check for tests that depend on evaluation order
  • Answer the non-MPS behavior question

1. Return value: provably unchanged

Both edits are pure reorderings of operands in an and chain. and is commutative w.r.t. its result, and every operand is a pure predicate over config / device properties:

  • use_triton_template (torch/_inductor/utils.py:1928-1940): A and B and C and D → B and C and D and A, where A is the device/dtype/is_big_gpu gate, B the max-autotune gate, C _use_autotune_backend("TRITON"), D has_backend_feature(..., TRITON_TEMPLATES).
  • use_cutlass_template (torch/_inductor/utils.py:2300-2304): same shape, _use_template_for_gpu moved last.

No operand mutates state that another operand reads, so for CUDA / ROCm / XPU / MTIA / CPU the boolean result is bit-identical in every configuration. The CPU branch (layout.device.type == "cpu" and layout.dtype in layout_dtypes) is untouched, and has_backend_feature was already in the old chain, so CPU results don't move either.

2. What does change on non-MPS backends: log side effects

is_big_gpu (torch/_inductor/utils.py:1776-1802) is the only side-effecting operand — it emits log.warning("Not enough SMs to use max_autotune_gemm mode") (or on ROCm "GPU arch does not support max_autotune_gemm mode usage"). It's now reached only when a template is genuinely a candidate. Consequences beyond MPS:

  • Small CUDA GPU (<68 SMs), XPU (<16 subslices), MTIA (hardcoded multi_processor_count = 64), old ROCm archs, in default mode: the warning disappears. Several callers pass check_max_autotune=False (kernel/bmm.py:230,326, kernel/mm_plus_mm.py:168, kernel/mm.py:726,1074,1252), so B is True even without max-autotune — meaning these backends were getting the warning on plain torch.compile too. Suppressing it there looks right: the message explicitly talks about max_autotune_gemm mode, which the user hasn't enabled.
  • max_autotune_gemm_backends without TRITON (e.g. ATEN,CUTLASS): the Triton path no longer warns. The CUTLASS path still does when CUTLASS is enabled. Note CUTLASS isn't in the default ATEN,TRITON,CPP, so on default CUDA the cutlass reorder alone removes a warning.
  • cuda_backend=halide/pallas: D is False (only TritonScheduling/CUDACombinedScheduling advertise TRITON_TEMPLATES, codegen/triton.py:7965), so no more warning. Correct — Triton templates aren't in play.
  • Interaction with @functools.cache on is_big_gpu — arguably an improvement. Before, a default-mode compile populated the cache and burned the one-shot warning; a later max_autotune=True compile in the same process then stayed silent. After this change the default-mode compile never calls is_big_gpu, so the max-autotune compile is the one that logs. Users who actually asked for max-autotune are now more likely to see it.

Also: the log.debug for a disallowed layout dtype in _use_template_for_gpu becomes similarly conditional. Debug-only, no concern.

3. One edge case worth flagging (low risk)

has_backend_feature → get_backend_features raises AssertionError(f"no scheduling registered for device {device_type}") (torch/_inductor/codegen/common.py:468). Previously A short-circuited first, so a device type that is neither a GPU_TYPES member nor "cpu" returned False without ever calling D. Now D is evaluated whenever B and C hold — which, given the check_max_autotune=False callers, is true in default mode with stock config.

In practice every device that reaches inductor lowering is registered (cpu/cuda/xpu/mps/mtia/tpu, plus privateuse1 when its custom mod resolves), so this needs a privateuse1 backend whose registration silently failed at codegen/common.py:625-639 — which would blow up later in codegen anyway. I'd call it acceptable, but if you want it airtight, gating on the device type before has_backend_feature restores the old short-circuit:

    return (
        (config.max_autotune or config.max_autotune_gemm or not check_max_autotune)
        and _use_autotune_backend("TRITON")
        and (is_gpu(layout.device.type) or layout.device.type == "cpu")
        and has_backend_feature(layout.device, BackendFeature.TRITON_TEMPLATES)
        and (...)
    )

Fix this →

Minor perf note in the other direction: get_backend_features is uncached and constructs a scheduling object per call (codegen/common.py:469), and it's now called on paths where A would have short-circuited it. It also triggers init_backend_registration() slightly earlier. Both are negligible against compile time, and are offset by skipping the DeviceProperties.create path more often.

4. Tests

Nothing in test/ mocks or asserts on use_triton_template, _use_template_for_gpu, or the warning text, and the is_big_gpu mock in test/inductor/test_max_autotune.py:1723-1752 patches the module attribute (still reached via _use_template_for_gpu under max_autotune=True), so it's unaffected. Given the whole point of the PR is a log line, consider locking it in with a small test — patch DeviceProperties.create (or is_big_gpu's inputs) to look like a small GPU, compile an mm in default mode, and use assertNoLogs("torch._inductor.utils", "WARNING"). Note is_big_gpu is functools.cached, so such a test needs to clear the cache to be order-independent.

5. Nits

  • is_gpu(layout.device.type) and _use_template_for_gpu(layout, layout_dtypes) at line 1935 is redundant — _use_template_for_gpu opens with the same is_gpu check (line 1878). Pre-existing, so fine to leave.
  • The comment at lines 1924-1927 reads well post-@kurtamohler's suggestion. The use_cutlass_template comment (2298-2299) still names is_big_gpu; for consistency with the other site you could drop that detail, but it's genuinely informative here, so either way.

Verdict

Reordering is sound; no non-MPS backend changes what it compiles. Non-MPS backends with small/unsupported GPUs stop seeing an SM warning they shouldn't have seen in default mode, and are more likely to see it when they do enable max-autotune. The only thing I'd ask you to consider is the has_backend_feature short-circuit in §3.

| Branch: `fix-spurious-sm-warning`

@jansel

jansel commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 20, 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

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.

@kurtamohler

Copy link
Copy Markdown
Collaborator

@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

rgbkrk and others added 2 commits August 28, 2026 15:58
use_triton_template and use_cutlass_template called _use_template_for_gpu
before checking autotune configuration and backend support. On MPS this
reached is_big_gpu and warned about the SM count even though no Triton or
CUTLASS template could be selected.

Reorder the eligibility checks so irrelevant paths short-circuit before
the SM heuristic. Keep the heuristic unchanged when templates are actual
candidates; changing min_sms is a separate issue.

Test Plan:
```bash
TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 /Users/kylekelley/books/reasoning-from-scratch/.venv/bin/python /Users/kylekelley/projects/pytorch/.context/verify_sm_warning.py
TORCHINDUCTOR_FORCE_DISABLE_CACHES=1 /Users/kylekelley/books/reasoning-from-scratch/.venv/bin/python /Users/kylekelley/projects/pytorch/.context/verify_sm_warning.py --patched
PATH="$PWD/.venv/bin:$PATH" .venv/bin/lintrunner -a --skip PYREFLY torch/_inductor/utils.py
git diff --check origin/main...HEAD
```

PYREFLY was skipped because its whole-project analysis requires a built
PyTorch checkout; all other configured linters for the changed file passed.

This change was authored with Claude under human direction and reviewed
and verified with Codex.
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased fix-spurious-sm-warning onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout fix-spurious-sm-warning && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the fix-spurious-sm-warning branch from 6321192 to a516fbe Compare August 28, 2026 15:58
@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 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

@kurtamohler

Copy link
Copy Markdown
Collaborator

@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

orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
…ay (pytorch#192375)

On Apple silicon, using the MPS backend, torch.compile emits a “Not enough SMs” warning. That warning is confusing: MPS is running on an Apple GPU, and neither Triton nor CUTLASS templates are candidates.

AI-generated summary, reviewed by me:

use_triton_template and use_cutlass_template evaluated the GPU-size heuristic before checking whether autotuning and the relevant template backend were enabled. Consequently, default-mode MPS compilation could report “Not enough SMs” even though neither Triton nor CUTLASS templates were candidates.

Reorder the eligibility checks so unsupported template paths short-circuit before is_big_gpu. The existing small-GPU heuristic still applies whenever a template is genuinely under consideration.

Testing:

- With Inductor caches disabled, stock PyTorch 2.10 emitted the warning.
- Applying the reordered Triton predicate suppressed the warning and compilation succeeded.

AI assistance disclosure: Claude prepared the implementation under human direction. Codex reviewed it against current main, verified the reproduction, and rebased the branch.

Pull Request resolved: pytorch#192375
Approved by: https://github.com/kurtamohler, https://github.com/jansel

Co-authored-by: kurtamohler <[email protected]>
Sanskaaar1 pushed a commit to Sanskaaar1/pytorch that referenced this pull request Sep 8, 2026
…ay (pytorch#192375)

On Apple silicon, using the MPS backend, torch.compile emits a “Not enough SMs” warning. That warning is confusing: MPS is running on an Apple GPU, and neither Triton nor CUTLASS templates are candidates.

AI-generated summary, reviewed by me:

use_triton_template and use_cutlass_template evaluated the GPU-size heuristic before checking whether autotuning and the relevant template backend were enabled. Consequently, default-mode MPS compilation could report “Not enough SMs” even though neither Triton nor CUTLASS templates were candidates.

Reorder the eligibility checks so unsupported template paths short-circuit before is_big_gpu. The existing small-GPU heuristic still applies whenever a template is genuinely under consideration.

Testing:

- With Inductor caches disabled, stock PyTorch 2.10 emitted the warning.
- Applying the reordered Triton predicate suppressed the warning and compilation succeeded.

AI assistance disclosure: Claude prepared the implementation under human direction. Codex reviewed it against current main, verified the reproduction, and rebased the branch.

Pull Request resolved: pytorch#192375
Approved by: https://github.com/kurtamohler, https://github.com/jansel

Co-authored-by: kurtamohler <[email protected]>
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: mps Release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants