Skip to content

[inductor] Fix PrecomputedGrid match for pipelining-disabled retry (#203016) - #203016

Closed
karimelazzouni wants to merge 2 commits into
pytorch:mainfrom
karimelazzouni:export-D128937194
Closed

karimelazzouni wants to merge 2 commits into
pytorch:mainfrom
karimelazzouni:export-D128937194

Conversation

@karimelazzouni

@karimelazzouni karimelazzouni commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

When the Triton config chosen for a kernel exceeds shared memory at launcher creation, _make_launchers retries via compile_by_disabling_pipelining, which lowers num_stages to 1. For kernels with a PrecomputedGrid, PrecomputedGrid.generate then required an exact config match, so the retry failed with "Precomputed grid not found" instead of launching with the precomputed grid.

Move candidate matching into a shared PrecomputedGrid.find_candidate_index(inductor_meta, config) used by PrecomputedGrid.generate, run_triton_kernel_with_autotune, and generate_aoti_kernel_config_header. A candidate matches when its config and the lookup config have equal keys and values on everything except num_stages; the first matching candidate wins. The retry lowers num_stages, so it reuses the chosen config's grid. Leaving num_stages out is safe because a grid reads launch options only through the config kwargs, which carry one only when the kernel declares a parameter of that name (Dynamo copies the value in). So when the kernel declares num_stages as a constexpr, num_stages stays in the match key and the retried config matches nothing. num_warps and the other launch options always stay in the key: a kernel that declares them can read them in its grid, and the retry does not change them. A config with a NUM_STAGES kernel kwarg still raises after the retry, because the retry lowers that kwarg too and it must match exactly. When nothing matches, find_candidate_index raises RuntimeError with the config and candidates. The generated lazy-grid switch throws on an unknown config_index instead of launching a wrong grid.

Alternative considered: strip every launch option from the key and put back only the declared ones. Comparing them directly is simpler, needs no list of launch options, and relaxes nothing beyond what the retry changes.

Repro (fresh compile, B200): a deterministic training graph failed compiling its backward embedding kernel with
Precomputed grid not found for {BLOCK_EMB_1: 64, BLOCK_EMB_2: 64, BLOCK_EMB_3: 64, num_warps: 8, num_stages: 1}
against candidates stored with num_stages=2.

Test Plan:
Unit tests: the full target, which includes TestPrecomputedGridConfigMatching and runs on remote GPU, so the end-to-end retry tests execute:

buck2 test fbcode//caffe2/test/inductor:triton_heuristics

https://www.internalfb.com/intern/testinfra/testrun/14636699006161781

Regression check: with the previous revision's _match_key restored and the new tests kept, both test_num_warps_must_match variants fail ('8' != '4': the key picked the first BLOCK=128 candidate rather than the num_warps=4 one), and the rest of the class passes:

buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching

https://www.internalfb.com/intern/testinfra/testrun/3659175108981162

Coverage in TestPrecomputedGridConfigMatching: matching on every config key except num_stages; configs differing only in num_stages sharing the first candidate; num_warps always matching, declared or not (the retry picks the candidate with its num_warps, not the first one with its BLOCK); the num_stages=1 retry selecting the chosen config's candidate; NUM_STAGES never matching a different value; equal key sets required; a declared num_stages constexpr staying in the match key (an equal value matches, the retried value raises) on the find_candidate_index, generate, lazy-autotune, and AOTI-header paths; BLOCK mismatches raising; the AOTI config header selecting/raising; run_triton_kernel_with_autotune selecting/raising; the generated lazy-grid default throwing; _make_launchers -> compile_by_disabling_pipelining -> GridExpr.from_meta with a real triton.Config; and end-to-end GPU tests running a user triton.autotune kernel through torch.compile with every pipelined config failing launcher creation (OutOfResources), in both the Python and cpp_wrapper paths (the latter with triton.autotune_at_compile_time pinned to False so the lazy-grid switch is generated and compiled).

End-to-end (previous revision): the B200 graph from the repro, which failed fresh compilation with the error above, compiled and ran. Not re-run on this revision; its retried config differs from the chosen config only in num_stages, which the match key still ignores.

arc lint -a on all changed files: ok, no issues.

PyTorch lint (lintrunner is not available in fbsource, so the OSS linters were run directly with PyTorch's configs): ruff 0.15.4 with pyproject.toml is clean on all changed files (CI's ruff 0.14.4 flagged the now-removed # noqa: B950 as unused, RUF100); pyrefly built from fbcode//pyrefly/pyrefly:pyrefly with pyrefly.toml reproduces CI's bad-argument-type at cpp_wrapper_gpu.py:196 before the InductorMeta cast and reports nothing on the diff's changed lines after it; the usort import order was checked by hand.

After the lint fixes, the class reruns green:

buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching

https://www.internalfb.com/intern/testinfra/testrun/30680772514800465

Differential Revision: D128937194

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 Nov 2, 2026

Copy link
Copy Markdown

This appears to be a diff that was exported from phabricator, but the PR author does not have sufficient permissions to run CI. @karimelazzouni, please do step 2 of internal wiki to get write access so you do not need to get CI approvals in the future. If you think this is a mistake, please contact the Pytorch Dev Infra team.

@pytorch-bot

pytorch-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:

The PR moves PrecomputedGrid candidate lookup into a shared helper,
`PrecomputedGrid.find_candidate_index`, used by the Python, lazy-autotune and
AOTI-header paths. It matches on the whole config, ignoring `num_stages` unless
it is a declared constexpr, and makes the lazy-grid `default:` case throw.
Recommendation: Approve. Every point the review raises is non-blocking.

Findings (4):

[minor] torch/_inductor/runtime/triton_heuristics.py:5834
Non-blocking: the `_match_key` comment states the wrong condition (the same
applies to the test comment at test/inductor/test_triton_heuristics.py:2063).
The last review raised this and it is still present. The comment says a grid
sees `num_stages` only when the kernel declares it as a constexpr. In fact
Dynamo copies `num_stages` into `config.kwargs`, where the grid can read it, for
any kernel parameter with that name, constexpr or not
(triton_kernel_wrap.py:2307, :2440-2463, :2617). The key itself checks
`declared_constexpr_names`, which holds only constexprs (wrapper.py:4998-5001).
The mismatch looks unreachable in practice, because Inductor fills a
`num_stages` parameter only when it is a constexpr
(triton_heuristics.py:1423-1428). Suggested wording: "a grid can read num_stages
only through a kernel parameter of that name, which Inductor supports only as a
constexpr."

[minor] torch/_inductor/runtime/triton_heuristics.py:5862
Non-blocking: the "not found" error hides the root cause. The last review raised
this and it is still present. The wording is unchanged, but the PR now also
raises it on the lazy and AOTI paths, which used to fail silently, so users will
see it more often. The message leaves out `inductor_meta["kernel_name"]`, which
is always set for these kernels (wrapper.py:5041). It prints the whole
`precomputed_grids` entries instead of just their configs. It also does not say
the miss came after the pipelining-disabled retry; the `OutOfResources` that
caused the retry is only logged at debug level (:1249).

[minor] test/inductor/test_triton_heuristics.py:2400
Non-blocking: `test_lazy_grid_default_throws` repeats the generated C++ line
verbatim (lines 2399-2402). It copies the f-string at
cpp_wrapper_gpu.py:683-687, so any change to the message's wording breaks the
test. Checking for `default: throw std::runtime_error(` plus the kernel name
would test the same thing.

[minor] test/inductor/test_triton_heuristics.py:2252
Non-blocking, optional hardening: the end-to-end tests check only `actual == x +
y`. Today a correct result does show that the `num_stages=1` retry ran: every
`add_kernel_autotuned` config has `num_stages` 3 or 4, and without the retry
`_make_launchers` would raise `NoTritonLaunchersError`. But if those configs
ever moved to `num_stages=1`, the tests would still pass without exercising the
fix. Record the `num_stages == 1` calls in the patched `make_launcher` and
assert that at least one happened.

Reviewed commit: 70d89ac (NOT the current head fa7f215)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit fa7f215 with merge base 0341691 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@meta-codesync

meta-codesync Bot commented Nov 2, 2026

Copy link
Copy Markdown

@karimelazzouni has exported this pull request. If you are a Meta employee, you can view the originating Diff in D128937194.

@pytorch-bot

pytorch-bot Bot commented Nov 2, 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 Nov 2, 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.

@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 2, 2026
@karimelazzouni

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Nov 2, 2026
github-actions[bot]

This comment was marked as outdated.

@meta-codesync meta-codesync Bot changed the title [inductor] Fix PrecomputedGrid match for pipelining-disabled retry [inductor] Fix PrecomputedGrid match for pipelining-disabled retry (#203016) Nov 2, 2026
karimelazzouni added a commit to karimelazzouni/pytorch that referenced this pull request Nov 2, 2026
…ytorch#203016)

Summary:

When the Triton config chosen for a kernel exceeds shared memory
at launcher creation, _make_launchers retries via
compile_by_disabling_pipelining (num_stages=1). For kernels with
a PrecomputedGrid, GridExpr.generate then looked for an exact
config match including num_stages, so the retry died with
"Precomputed grid not found for {..., 'num_stages': 1}" instead
of launching with the precomputed grid.

The launch grid depends on tensor sizes and BLOCK constexprs,
not on num_warps/num_stages (the stored candidates carry
identical grids across those variants). Exclude num_warps and
num_stages from the candidate config match in
PrecomputedGrid.generate so the pipelining-disabled retry can
reuse the precomputed grid. Different BLOCK sizes still reject.

Repro (fresh compile, B200): an APS deterministic NE training
graph failed compiling its backward embedding kernel with
  Precomputed grid not found for {'BLOCK_EMB_1': 64,
  'BLOCK_EMB_2': 64, 'BLOCK_EMB_3': 64, 'num_warps': 8,
  'num_stages': 1}
in [{'config': {..., 'num_warps': 4, 'num_stages': 2}, ...},
    {'config': {..., 'num_warps': 8, 'num_stages': 2}, ...}]

Test Plan:
Unit tests (focused, this diff):
buck2 test fbcode//caffe2/test/inductor:triton_heuristics --
--regex 'TestPrecomputedGridConfigMatching'
Result: Tests finished: Pass 3. Fail 0. EXIT=0
(testrun 20547673364105641; the two new tests plus listing.
test_matches_pipelining_disabled_retry_config verifies the
num_stages=1 retry config returns the precomputed grid;
test_still_rejects_different_block_sizes verifies a BLOCK
mismatch still raises AssertionError.)

End-to-end: with this change, the B200 deterministic NE graph
that previously failed fresh compilation with
"Precomputed grid not found for {..., 'num_stages': 1}"
compiles and runs (baseline generation + forward verification
on B200, local, APS NE trainer graph).

arc lint -a on both changed files: ok, no issues.

Differential Revision: D128937194
github-actions[bot]

This comment was marked as outdated.

karimelazzouni added a commit to karimelazzouni/pytorch that referenced this pull request Nov 3, 2026
…ytorch#203016)

Summary:

When the Triton config chosen for a kernel exceeds shared memory at launcher creation, _make_launchers retries via compile_by_disabling_pipelining (num_stages=1). For kernels with a PrecomputedGrid, GridExpr.generate then looked for an exact config match including num_stages, so the retry died with "Precomputed grid not found for {..., num_stages: 1}" instead of launching with the precomputed grid.

The launch grid depends on tensor sizes and BLOCK constexprs, not on num_warps/num_stages (the stored candidates carry identical grids across those variants). Exclude num_warps and num_stages from the candidate config match in PrecomputedGrid.generate so the pipelining-disabled retry can reuse the precomputed grid. Different BLOCK sizes still reject.

Update addressing automated GitHub review comments: candidate matching now lives in the shared PrecomputedGrid.find_candidate_index helper, used by PrecomputedGrid.generate, run_triton_kernel_with_autotune, and generate_aoti_kernel_config_header, so every selection path ignores num_warps/num_stages. The two lazy paths raise when no candidate matches instead of leaving config_index unset or emitting CONFIG_INDEX=-1, and the generated PrecomputedGrid switch now defaults to a zero grid (launch skipped by the existing guard) rather than a wrong 1x1x1 grid.

Repro (fresh compile, B200): an APS deterministic NE training graph failed compiling its backward embedding kernel with
  Precomputed grid not found for {BLOCK_EMB_1: 64, BLOCK_EMB_2: 64, BLOCK_EMB_3: 64, num_warps: 8, num_stages: 1}
in [{config: {..., num_warps: 4, num_stages: 2}, ...}, {config: {..., num_warps: 8, num_stages: 2}, ...}]

Test Plan:
Unit tests (focused, this diff):
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching
Result: Tests finished: Pass 6. Fail 0. EXIT=0
(testrun 11540474260835065. test_matches_pipelining_disabled_retry_config verifies the num_stages=1 retry config returns the precomputed grid; test_candidate_order_does_not_change_result verifies two candidates differing only in num_warps (4 vs 8) select the same candidate/grid regardless of order; test_still_rejects_different_block_sizes verifies a BLOCK mismatch still raises AssertionError; test_aoti_config_header_matches_pipelining_disabled_config verifies the AOTI lazy header emits CONFIG_INDEX 0 for a num_stages=1 config; test_aoti_config_header_rejects_unmatched_config verifies the AOTI lazy path raises when no candidate matches.)

End-to-end: with this change, the B200 deterministic NE graph that previously failed fresh compilation with "Precomputed grid not found for {..., num_stages: 1}" compiles and runs (baseline generation + forward verification on B200, local, APS NE trainer graph).

arc lint -a on all changed files: ok, no issues. arc pyrefly check-owning-targets: typing is not enabled for these targets, so no type check was performed.

Re-run on submitted version 463077376 (commit 32f06c20fd0b):
- Focused tests again: Pass 6, Fail 0 (testrun 21392098294693009, revision 32f06c20fd0b).
- B200 NE end-to-end on RE (stacked D128589853@c49463b671): testrun 18577348527581008, RE session reSessionID-4515d0f8-7324-493b-bbef-22851e574ff6, ran 997s, Infra Failure 0, Fatal 0. The graph compiled and trained end-to-end (no Precomputed grid error); the single test failure is the B200 NE numerical comparison, the same single failure D128589853 CI reports for this target/baseline, unrelated to grid selection.

Differential Revision: D128937194
github-actions[bot]

This comment was marked as outdated.

karimelazzouni added a commit to karimelazzouni/pytorch that referenced this pull request Nov 3, 2026
…ytorch#203016)

Summary:

When the Triton config chosen for a kernel exceeds shared memory at launcher creation, _make_launchers retries via compile_by_disabling_pipelining (num_stages=1). For kernels with a PrecomputedGrid, GridExpr.generate then looked for an exact config match including num_stages, so the retry died with "Precomputed grid not found for {..., num_stages: 1}" instead of launching with the precomputed grid.

The launch grid depends on tensor sizes and BLOCK constexprs, not on num_warps/num_stages (the stored candidates carry identical grids across those variants). Exclude num_warps and num_stages from the candidate config match in PrecomputedGrid.generate so the pipelining-disabled retry can reuse the precomputed grid. Different BLOCK sizes still reject.

Update addressing automated GitHub review comments: candidate matching now lives in the shared PrecomputedGrid.find_candidate_index helper, used by PrecomputedGrid.generate, run_triton_kernel_with_autotune, and generate_aoti_kernel_config_header. Matching is tiered (exact, then ignoring num_stages, then ignoring num_warps as well) so a user grid that depends on num_warps still selects its own candidate, while the pipelining-disabled retry (num_stages=1) reuses the chosen candidate. The two lazy paths raise when no candidate matches instead of leaving config_index unset or emitting CONFIG_INDEX=-1, and the generated PrecomputedGrid switch throws std::runtime_error on an unknown config_index rather than silently launching a wrong grid or skipping the launch.

Repro (fresh compile, B200): an APS deterministic NE training graph failed compiling its backward embedding kernel with
  Precomputed grid not found for {BLOCK_EMB_1: 64, BLOCK_EMB_2: 64, BLOCK_EMB_3: 64, num_warps: 8, num_stages: 1}
in [{config: {..., num_warps: 4, num_stages: 2}, ...}, {config: {..., num_warps: 8, num_stages: 2}, ...}]

Test Plan:
Unit tests (focused, this diff):
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching
Latest result: Tests finished: Pass 7. Fail 0. EXIT=0 (testrun 14918173981714925, RE session reSessionID-ed169047-b0a8-40cc-a594-f2af831fe45c; earlier on submitted version 463077376: Pass 6, testrun 21392098294693009, revision 32f06c20fd0b).
- test_exact_match_selects_warps_dependent_grid: candidates with distinct num_warps-dependent grids select their own candidate on an exact config.
- test_matches_pipelining_disabled_retry_config: the num_stages=1 retry config still selects the num_warps=8 candidate (index 1).
- test_candidate_order_does_not_change_result: candidate order does not change the selected candidate or grid.
- test_still_rejects_different_block_sizes: a BLOCK mismatch still raises AssertionError / returns None.
- test_aoti_config_header_matches_pipelining_disabled_config: the AOTI lazy header emits CONFIG_INDEX 1 for a num_stages=1, num_warps=8 config.
- test_aoti_config_header_rejects_unmatched_config: the AOTI lazy path raises when no candidate matches.

End-to-end (previous version): with this change, the B200 deterministic NE graph that previously failed fresh compilation with "Precomputed grid not found for {..., num_stages: 1}" compiles and runs. Re-run on version 463077376 stack (D128589853@c49463b671): B200 NE E2E on RE, testrun 18577348527581008, RE session reSessionID-4515d0f8-7324-493b-bbef-22851e574ff6, ran 997s, Infra Failure 0, Fatal 0; the single failure is the B200 NE numerical comparison, the same single failure D128589853 CI reports for this target/baseline, unrelated to grid selection.

arc lint -a on all changed files: ok, no issues. arc pyrefly check-owning-targets: typing is not enabled for these targets, so no type check was performed.

Differential Revision: D128937194
github-actions[bot]

This comment was marked as outdated.

@laithsakka
laithsakka requested review from eellison and mlazos November 3, 2026 19:19
karimelazzouni added a commit to karimelazzouni/pytorch that referenced this pull request Nov 3, 2026
…ytorch#203016)

Summary:

When the Triton config chosen for a kernel exceeds shared memory at launcher creation, _make_launchers retries via compile_by_disabling_pipelining (num_stages=1). For kernels with a PrecomputedGrid, GridExpr.generate then looked for an exact config match including num_stages, so the retry died with "Precomputed grid not found for {..., num_stages: 1}" instead of launching with the precomputed grid.

Candidate matching in PrecomputedGrid.generate is tiered: an exact config match first (a user grid can depend on num_warps/num_stages, so candidates differing only in those values may carry different grids), then a retry tier that accepts a different num_stages/NUM_STAGES only when the lookup value is 1, which is exactly what compile_by_disabling_pipelining produces. Different BLOCK sizes still reject.

Update addressing automated GitHub review comments: candidate matching now lives in the shared PrecomputedGrid.find_candidate_index helper, used by PrecomputedGrid.generate, run_triton_kernel_with_autotune, and generate_aoti_kernel_config_header. Matching is tiered as described above, so a user grid that depends on num_warps/num_stages still selects its own candidate, while the pipelining-disabled retry (num_stages and NUM_STAGES lowered to 1) reuses the chosen candidate. The two lazy paths raise when no candidate matches instead of leaving config_index unset or emitting CONFIG_INDEX=-1, and the generated PrecomputedGrid switch throws std::runtime_error on an unknown config_index rather than silently launching a wrong grid or skipping the launch.

Repro (fresh compile, B200): an APS deterministic NE training graph failed compiling its backward embedding kernel with
  Precomputed grid not found for {BLOCK_EMB_1: 64, BLOCK_EMB_2: 64, BLOCK_EMB_3: 64, num_warps: 8, num_stages: 1}
in [{config: {..., num_warps: 4, num_stages: 2}, ...}, {config: {..., num_warps: 8, num_stages: 2}, ...}]

Test Plan:
Unit tests (focused, this diff):
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex 'TestPrecomputedGridConfigMatching'
Latest result: Tests finished: Pass 10. Fail 0. EXIT=0. The TestPrecomputedGridConfigMatching class has 9 tests; buck also counts the target listing entry in the Pass total. (Earlier combined run with the static-launcher suite: Pass 13, testrun 20829148341781464.)
- test_exact_match_selects_warps_dependent_grid: candidates with distinct num_warps-dependent grids select their own candidate on an exact config.
- test_exact_match_distinguishes_num_stages: candidates differing only in num_stages select their own candidate; the exact tier is not relaxed onto the first candidate.
- test_retry_tier_matches_num_stages_kwarg_only_at_one: the NUM_STAGES kwarg relaxes only at the retry-produced value 1; NUM_STAGES=2 finds no candidate.
- test_matches_pipelining_disabled_retry_config: the num_stages=1 retry config still selects the num_warps=8 candidate (index 1).
- test_candidate_order_does_not_change_result: candidate order does not change the selected candidate or grid.
- test_still_rejects_different_block_sizes: a BLOCK mismatch still raises AssertionError / returns None.
- test_aoti_config_header_matches_pipelining_disabled_config: the AOTI lazy header emits CONFIG_INDEX 1 for a num_stages=1, num_warps=8 config.
- test_aoti_config_header_rejects_unmatched_config: the AOTI lazy path raises when no candidate matches.
- test_from_meta_with_retried_config: drives GridExpr.from_meta (the entry point make_launcher uses) with candidates stored from a NUM_STAGES=3 pre-retry config and the retried num_stages/NUM_STAGES=1 lookup. (A fuller retry-chain test in test_static_triton_launcher.py was removed from this diff: that file's GitHub base lacks the anchoring test from the closed-unmerged PR pytorch#200459, so ShipIt could not apply the patch; see below.)

End-to-end (earlier version): with this change, the B200 deterministic NE graph that previously failed fresh compilation with "Precomputed grid not found for {..., num_stages: 1}" compiles and runs. Re-run on version 463077376 stack (D128589853@c49463b671): B200 NE E2E on RE, testrun 18577348527581008, RE session reSessionID-4515d0f8-7324-493b-bbef-22851e574ff6, ran 997s, Infra Failure 0, Fatal 0; the single failure is the B200 NE numerical comparison, the same single failure D128589853 CI reports for this target/baseline, unrelated to grid selection.

arc lint -a on all changed files: ok, no issues. arc pyrefly check-owning-targets: typing is not enabled for these targets, so no type check was performed.

Rebased onto trunk (master@bf4054759a76) after the GitHub export failed to apply the patch to test/inductor/test_static_triton_launcher.py on the stale base; rebase merged cleanly. Focused tests re-run on the rebased commit 30389e9bdf11: Pass 13, Fail 0 (testrun 15762598912051375).
Export note: the GitHub export of version 464127200 failed in CodeSync because the added test in test_static_triton_launcher.py anchors after test_tensor_memory_autotuner_retries_without_pipelining, which exists in fbsource trunk (from PR pytorch#200459) but that PR is closed-unmerged on GitHub, so the patch context does not exist on GitHub main. Rebasing inside fbsource cannot fix an fbsource<->GitHub base divergence, so that file is no longer touched by this diff.

Differential Revision: D128937194
github-actions[bot]

This comment was marked as outdated.

karimelazzouni added a commit to karimelazzouni/pytorch that referenced this pull request Nov 3, 2026
…ytorch#203016)

Summary:

When the Triton config chosen for a kernel exceeds shared memory at launcher creation, _make_launchers retries via compile_by_disabling_pipelining (num_stages=1). For kernels with a PrecomputedGrid, GridExpr.generate then looked for an exact config match including num_stages, so the retry died with "Precomputed grid not found for {..., num_stages: 1}" instead of launching with the precomputed grid.

Candidate matching in PrecomputedGrid.generate is tiered: an exact config match first (a user grid can depend on num_warps/num_stages, so candidates differing only in those values may carry different grids), then a retry tier that accepts a different num_stages/NUM_STAGES only when the lookup value is 1, which is exactly what compile_by_disabling_pipelining produces. Different BLOCK sizes still reject.

Update addressing automated GitHub review comments: candidate matching now lives in the shared PrecomputedGrid.find_candidate_index helper, used by PrecomputedGrid.generate, run_triton_kernel_with_autotune, and generate_aoti_kernel_config_header. Matching is tiered as described above, so a user grid that depends on num_warps/num_stages still selects its own candidate, while the pipelining-disabled retry (num_stages and NUM_STAGES lowered to 1) rebinds to a stored candidate. The relaxed tier cannot tell which candidate the retried config came from, so when several relaxed matches carry different grids it raises instead of silently picking the first; a stored grid is reused as-is (a grid that reads NUM_STAGES is not recomputed for the retried config). The two lazy paths raise when no candidate matches instead of leaving config_index unset or emitting CONFIG_INDEX=-1, and the generated PrecomputedGrid switch throws std::runtime_error on an unknown config_index rather than silently launching a wrong grid or skipping the launch.

Repro (fresh compile, B200): an APS deterministic NE training graph failed compiling its backward embedding kernel with
  Precomputed grid not found for {BLOCK_EMB_1: 64, BLOCK_EMB_2: 64, BLOCK_EMB_3: 64, num_warps: 8, num_stages: 1}
in [{config: {..., num_warps: 4, num_stages: 2}, ...}, {config: {..., num_warps: 8, num_stages: 2}, ...}]

Test Plan:
Unit tests (focused, this diff):
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex 'TestPrecomputedGridConfigMatching'
Latest result: Tests finished: Pass 14. Fail 0. EXIT=0 (testrun 15762598912076552). The TestPrecomputedGridConfigMatching class has 13 tests; buck also counts the target listing entry in the Pass total. (Earlier combined run with the static-launcher suite: Pass 13, testrun 20829148341781464.)
- test_exact_match_selects_warps_dependent_grid: candidates with distinct num_warps-dependent grids select their own candidate on an exact config.
- test_exact_match_distinguishes_num_stages: candidates differing only in num_stages select their own candidate; the exact tier is not relaxed onto the first candidate.
- test_retry_tier_matches_num_stages_kwarg_only_at_one: the NUM_STAGES kwarg relaxes only at the retry-produced value 1; NUM_STAGES=2 finds no candidate.
- test_matches_pipelining_disabled_retry_config: the num_stages=1 retry config still selects the num_warps=8 candidate (index 1).
- test_candidate_order_does_not_change_result: candidate order does not change the selected candidate or grid.
- test_still_rejects_different_block_sizes: a BLOCK mismatch still raises AssertionError / returns None.
- test_aoti_config_header_matches_pipelining_disabled_config: the AOTI lazy header emits CONFIG_INDEX 1 for a num_stages=1, num_warps=8 config.
- test_aoti_config_header_rejects_unmatched_config: the AOTI lazy path raises when no candidate matches.
- test_make_launchers_retries_with_precomputed_grid: drives the real chain _make_launchers -> compile_by_disabling_pipelining -> make_launcher -> GridExpr.from_meta with a real triton.Config (so from_meta's config_to_dict conversion runs) and candidates built by config_to_dict, mirroring wrapper.py; the retry produces the num_warps=8 candidate's grid.
- test_exact_tier_wins_over_relaxed_tier: a num_stages=1 lookup with an exact candidate selects it over an earlier num_stages=3 candidate.
- test_relaxed_tier_raises_on_ambiguous_grids / test_relaxed_tier_accepts_identical_grids: relaxed matches with different grids raise; identical grids return the first match.
- test_from_meta_with_retried_config: drives GridExpr.from_meta with hand-written dicts as a lightweight complement.

End-to-end (earlier version): with this change, the B200 deterministic NE graph that previously failed fresh compilation with "Precomputed grid not found for {..., num_stages: 1}" compiles and runs. Re-run on version 463077376 stack (D128589853@c49463b671): B200 NE E2E on RE, testrun 18577348527581008, RE session reSessionID-4515d0f8-7324-493b-bbef-22851e574ff6, ran 997s, Infra Failure 0, Fatal 0; the single failure is the B200 NE numerical comparison, the same single failure D128589853 CI reports for this target/baseline, unrelated to grid selection.

arc lint -a on all changed files: ok, no issues. arc pyrefly check-owning-targets: typing is not enabled for these targets, so no type check was performed.

Rebased onto trunk (master@bf4054759a76) after the GitHub export failed to apply the patch to test/inductor/test_static_triton_launcher.py on the stale base; rebase merged cleanly. Focused tests re-run on the rebased commit 30389e9bdf11: Pass 13, Fail 0 (testrun 15762598912051375).
Export note: the GitHub export of version 464127200 failed in CodeSync because the added test in test_static_triton_launcher.py anchors after test_tensor_memory_autotuner_retries_without_pipelining, which exists in fbsource trunk (from PR pytorch#200459) but that PR is closed-unmerged on GitHub, so the patch context does not exist on GitHub main. Rebasing inside fbsource cannot fix an fbsource<->GitHub base divergence, so that file is no longer touched by this diff.

Differential Revision: D128937194
karimelazzouni added a commit to karimelazzouni/pytorch that referenced this pull request Nov 5, 2026
…ytorch#203016)

Summary:

When the Triton config chosen for a kernel exceeds shared memory at launcher creation, _make_launchers retries via compile_by_disabling_pipelining, which lowers num_stages to 1. For kernels with a PrecomputedGrid, PrecomputedGrid.generate then required an exact config match, so the retry failed with "Precomputed grid not found" instead of launching with the precomputed grid.

Move candidate matching into a shared PrecomputedGrid.find_candidate_index(inductor_meta, config) used by PrecomputedGrid.generate, run_triton_kernel_with_autotune, and generate_aoti_kernel_config_header. A candidate matches when its config and the lookup config have equal keys and values on everything except num_stages; the first matching candidate wins. The retry lowers num_stages, so it reuses the chosen config's grid. Leaving num_stages out is safe because a grid reads launch options only through the config kwargs, which carry one only when the kernel declares a parameter of that name (Dynamo copies the value in). So when the kernel declares num_stages as a constexpr, num_stages stays in the match key and the retried config matches nothing. num_warps and the other launch options always stay in the key: a kernel that declares them can read them in its grid, and the retry does not change them. A config with a NUM_STAGES kernel kwarg still raises after the retry, because the retry lowers that kwarg too and it must match exactly. When nothing matches, find_candidate_index raises RuntimeError with the config and candidates. The generated lazy-grid switch throws on an unknown config_index instead of launching a wrong grid.

Alternative considered: strip every launch option from the key and put back only the declared ones. Comparing them directly is simpler, needs no list of launch options, and relaxes nothing beyond what the retry changes.

Repro (fresh compile, B200): a deterministic training graph failed compiling its backward embedding kernel with
  Precomputed grid not found for {BLOCK_EMB_1: 64, BLOCK_EMB_2: 64, BLOCK_EMB_3: 64, num_warps: 8, num_stages: 1}
against candidates stored with num_stages=2.

Test Plan:
Unit tests: the full target, which includes TestPrecomputedGridConfigMatching and runs on remote GPU, so the end-to-end retry tests execute:

```
buck2 test fbcode//caffe2/test/inductor:triton_heuristics
```

https://www.internalfb.com/intern/testinfra/testrun/14636699006161781

Regression check: with the previous revision's _match_key restored and the new tests kept, both test_num_warps_must_match variants fail ('8' != '4': the key picked the first BLOCK=128 candidate rather than the num_warps=4 one), and the rest of the class passes:

```
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching
```

https://www.internalfb.com/intern/testinfra/testrun/3659175108981162

Coverage in TestPrecomputedGridConfigMatching: matching on every config key except num_stages; configs differing only in num_stages sharing the first candidate; num_warps always matching, declared or not (the retry picks the candidate with its num_warps, not the first one with its BLOCK); the num_stages=1 retry selecting the chosen config's candidate; NUM_STAGES never matching a different value; equal key sets required; a declared num_stages constexpr staying in the match key (an equal value matches, the retried value raises) on the find_candidate_index, generate, lazy-autotune, and AOTI-header paths; BLOCK mismatches raising; the AOTI config header selecting/raising; run_triton_kernel_with_autotune selecting/raising; the generated lazy-grid default throwing; _make_launchers -> compile_by_disabling_pipelining -> GridExpr.from_meta with a real triton.Config; and end-to-end GPU tests running a user triton.autotune kernel through torch.compile with every pipelined config failing launcher creation (OutOfResources), in both the Python and cpp_wrapper paths (the latter with triton.autotune_at_compile_time pinned to False so the lazy-grid switch is generated and compiled).

End-to-end (previous revision): the B200 graph from the repro, which failed fresh compilation with the error above, compiled and ran. Not re-run on this revision; its retried config differs from the chosen config only in num_stages, which the match key still ignores.

arc lint -a on all changed files: ok, no issues.

PyTorch lint (lintrunner is not available in fbsource, so the OSS linters were run directly with PyTorch's configs): ruff 0.15.4 with pyproject.toml is clean on all changed files (CI's ruff 0.14.4 flagged the now-removed `# noqa: B950` as unused, RUF100); pyrefly built from fbcode//pyrefly/pyrefly:pyrefly with pyrefly.toml reproduces CI's bad-argument-type at cpp_wrapper_gpu.py:196 before the InductorMeta cast and reports nothing on the diff's changed lines after it; the usort import order was checked by hand.

After the lint fixes, the class reruns green:

```
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching
```

https://www.internalfb.com/intern/testinfra/testrun/30680772514800465

Differential Revision: D128937194
github-actions[bot]

This comment was marked as outdated.

karimelazzouni added a commit to karimelazzouni/pytorch that referenced this pull request Nov 5, 2026
…ytorch#203016)

Summary:

When the Triton config chosen for a kernel exceeds shared memory at launcher creation, _make_launchers retries via compile_by_disabling_pipelining, which lowers num_stages to 1. For kernels with a PrecomputedGrid, PrecomputedGrid.generate then required an exact config match, so the retry failed with "Precomputed grid not found" instead of launching with the precomputed grid.

Move candidate matching into a shared PrecomputedGrid.find_candidate_index(inductor_meta, config) used by PrecomputedGrid.generate, run_triton_kernel_with_autotune, and generate_aoti_kernel_config_header. A candidate matches when its config and the lookup config have equal keys and values on everything except num_stages; the first matching candidate wins. The retry lowers num_stages, so it reuses the chosen config's grid. Leaving num_stages out is safe because a grid reads launch options only through the config kwargs, which carry one only when the kernel declares a parameter of that name (Dynamo copies the value in). So when the kernel declares num_stages as a constexpr, num_stages stays in the match key and the retried config matches nothing. num_warps and the other launch options always stay in the key: a kernel that declares them can read them in its grid, and the retry does not change them. A config with a NUM_STAGES kernel kwarg still raises after the retry, because the retry lowers that kwarg too and it must match exactly. When nothing matches, find_candidate_index raises RuntimeError with the config and candidates. The generated lazy-grid switch throws on an unknown config_index instead of launching a wrong grid.

Alternative considered: strip every launch option from the key and put back only the declared ones. Comparing them directly is simpler, needs no list of launch options, and relaxes nothing beyond what the retry changes.

Repro (fresh compile, B200): a deterministic training graph failed compiling its backward embedding kernel with
  Precomputed grid not found for {BLOCK_EMB_1: 64, BLOCK_EMB_2: 64, BLOCK_EMB_3: 64, num_warps: 8, num_stages: 1}
against candidates stored with num_stages=2.

Test Plan:
Unit tests: the full target, which includes TestPrecomputedGridConfigMatching and runs on remote GPU, so the end-to-end retry tests execute:

```
buck2 test fbcode//caffe2/test/inductor:triton_heuristics
```

https://www.internalfb.com/intern/testinfra/testrun/14636699006161781

Regression check: with the previous revision's _match_key restored and the new tests kept, both test_num_warps_must_match variants fail ('8' != '4': the key picked the first BLOCK=128 candidate rather than the num_warps=4 one), and the rest of the class passes:

```
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching
```

https://www.internalfb.com/intern/testinfra/testrun/3659175108981162

Coverage in TestPrecomputedGridConfigMatching: matching on every config key except num_stages; configs differing only in num_stages sharing the first candidate; num_warps always matching, declared or not (the retry picks the candidate with its num_warps, not the first one with its BLOCK); the num_stages=1 retry selecting the chosen config's candidate; NUM_STAGES never matching a different value; equal key sets required; a declared num_stages constexpr staying in the match key (an equal value matches, the retried value raises) on the find_candidate_index, generate, lazy-autotune, and AOTI-header paths; BLOCK mismatches raising; the AOTI config header selecting/raising; run_triton_kernel_with_autotune selecting/raising; the generated lazy-grid default throwing; _make_launchers -> compile_by_disabling_pipelining -> GridExpr.from_meta with a real triton.Config; and end-to-end GPU tests running a user triton.autotune kernel through torch.compile with every pipelined config failing launcher creation (OutOfResources), in both the Python and cpp_wrapper paths (the latter with triton.autotune_at_compile_time pinned to False so the lazy-grid switch is generated and compiled).

End-to-end (previous revision): the B200 graph from the repro, which failed fresh compilation with the error above, compiled and ran. Not re-run on this revision; its retried config differs from the chosen config only in num_stages, which the match key still ignores.

arc lint -a on all changed files: ok, no issues.

PyTorch lint (lintrunner is not available in fbsource, so the OSS linters were run directly with PyTorch's configs): ruff 0.15.4 with pyproject.toml is clean on all changed files (CI's ruff 0.14.4 flagged the now-removed `# noqa: B950` as unused, RUF100); pyrefly built from fbcode//pyrefly/pyrefly:pyrefly with pyrefly.toml reproduces CI's bad-argument-type at cpp_wrapper_gpu.py:196 before the InductorMeta cast and reports nothing on the diff's changed lines after it; the usort import order was checked by hand.

After the lint fixes, the class reruns green:

```
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching
```

https://www.internalfb.com/intern/testinfra/testrun/30680772514800465

Differential Revision: D128937194

@github-actions github-actions Bot 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.

Automated review of 70d89ac: nothing blocking; ready for human review.

The PR moves PrecomputedGrid candidate lookup into a shared helper, PrecomputedGrid.find_candidate_index, used by the Python, lazy-autotune and AOTI-header paths. It matches on the whole config, ignoring num_stages unless it is a declared constexpr, and makes the lazy-grid default: case throw. Recommendation: Approve. Every point the review raises is non-blocking.

⚪ 4 non-blocking findings

# kwarg, which stays in the key). A grid sees num_stages only when the

Non-blocking: the _match_key comment states the wrong condition (the same applies to the test comment at test/inductor/test_triton_heuristics.py:2063). The last review raised this and it is still present. The comment says a grid sees num_stages only when the kernel declares it as a constexpr. In fact Dynamo copies num_stages into config.kwargs, where the grid can read it, for any kernel parameter with that name, constexpr or not (triton_kernel_wrap.py:2307, :2440-2463, :2617). The key itself checks declared_constexpr_names, which holds only constexprs (wrapper.py:4998-5001). The mismatch looks unreachable in practice, because Inductor fills a num_stages parameter only when it is a constexpr (triton_heuristics.py:1423-1428). Suggested wording: "a grid can read num_stages only through a kernel parameter of that name, which Inductor supports only as a constexpr."


Non-blocking: the "not found" error hides the root cause. The last review raised this and it is still present. The wording is unchanged, but the PR now also raises it on the lazy and AOTI paths, which used to fail silently, so users will see it more often. The message leaves out inductor_meta\["kernel_name"\], which is always set for these kernels (wrapper.py:5041). It prints the whole precomputed_grids entries instead of just their configs. It also does not say the miss came after the pipelining-disabled retry; the OutOfResources that caused the retry is only logged at debug level (:1249).


'default: throw std::runtime_error("Invalid config_index " + std::to_string(fake_kernel_result.config_index) + " for kernel fake_kernel");',

Non-blocking: test_lazy_grid_default_throws repeats the generated C++ line verbatim (lines 2399-2402). It copies the f-string at cpp_wrapper_gpu.py:683-687, so any change to the message's wording breaks the test. Checking for default: throw std::runtime_error( plus the kernel name would test the same thing.


self.assertEqual(actual, x + y)

Non-blocking, optional hardening: the end-to-end tests check only actual == x + y. Today a correct result does show that the num_stages=1 retry ran: every add_kernel_autotuned config has num_stages 3 or 4, and without the retry _make_launchers would raise NoTritonLaunchersError. But if those configs ever moved to num_stages=1, the tests would still pass without exercising the fix. Record the num_stages == 1 calls in the patched make_launcher and assert that at least one happened.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 5, 2026
@warrendeng

Copy link
Copy Markdown
Contributor

@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

@meta-codesync

meta-codesync Bot commented Nov 6, 2026

Copy link
Copy Markdown

@pytorchbot merge

(Initiating merge automatically since Phabricator Diff has merged)

@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.

@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

@pytorch-auto-revert

Copy link
Copy Markdown

@pytorchbot revert -m "Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable" -c autorevert

This PR is attributed to have caused regression in:

Autorevert dashboard as of 2026-11-06 11:05:03 UTC

Note: This revert was accelerated by the AI advisor: AI advisor: related (confidence=0.97)

Please investigate and fix the issues.
@claude Can you please read this revert comment, follow the links and read the errors, to then give a brief diagnostics on the cause of the error? If you judge the error to be legitimate reason for a revert, please provide brief guidance on how the author could fix it.

@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Claude finished @pytorch-auto-revert[bot]'s task in 53s —— View job


The revert is justified: lint on main fails with two F821 Undefined name 'types' errors in tests this PR added. This looks like a land race, not a mistake in the PR itself.

Diagnosis and fix

Error

lintrunner-noclang-all / lint, at commit 2d1918a (this PR as merged):

>>> Lint for test/inductor/test_triton_heuristics.py:
  Error (RUFF) F821  Undefined name `types`.
    2178 |        autotuner.device_props = types.SimpleNamespace(type="cuda", index=0)
  Error (RUFF) F821  Undefined name `types`.
    2304 |        autotuner.launchers = [types.SimpleNamespace(config=config)]

Cause

The new tests (test_make_launchers_retries_with_precomputed_grid and the lazy-autotune helper) call types.SimpleNamespace and depend on a module-level import types. That import existed when the PR was reviewed: an earlier automated review cites "types at line 10". It is gone from current main, where line 10 is import tempfile. So a commit that landed in parallel most likely removed the then-unused import types, and this PR merged on top without being re-linted. The test file would also fail with NameError at runtime, so this is a real breakage, not a cosmetic lint issue.

Other types.SimpleNamespace uses also appear later in the file on main (around lines 2890-2909). After the revert, check whether main's lint is still red for those. If it is, a separate commit has the same problem.

Fix

When relanding, rebase on current main and add the import back at the top of test/inductor/test_triton_heuristics.py:

import tempfile
import types
import unittest

Or use from types import SimpleNamespace and replace the types.SimpleNamespace calls. Then run lintrunner -m origin/main (or spin lint) on the rebased commit before merging.

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@karimelazzouni your PR has been successfully reverted.

…ytorch#203016)

Summary:

When the Triton config chosen for a kernel exceeds shared memory at launcher creation, _make_launchers retries via compile_by_disabling_pipelining, which lowers num_stages to 1. For kernels with a PrecomputedGrid, PrecomputedGrid.generate then required an exact config match, so the retry failed with "Precomputed grid not found" instead of launching with the precomputed grid.

Move candidate matching into a shared PrecomputedGrid.find_candidate_index(inductor_meta, config) used by PrecomputedGrid.generate, run_triton_kernel_with_autotune, and generate_aoti_kernel_config_header. A candidate matches when its config and the lookup config have equal keys and values on everything except num_stages; the first matching candidate wins. The retry lowers num_stages, so it reuses the chosen config's grid. Leaving num_stages out is safe because a grid reads launch options only through the config kwargs, which carry one only when the kernel declares a parameter of that name (Dynamo copies the value in). So when the kernel declares num_stages as a constexpr, num_stages stays in the match key and the retried config matches nothing. num_warps and the other launch options always stay in the key: a kernel that declares them can read them in its grid, and the retry does not change them. A config with a NUM_STAGES kernel kwarg still raises after the retry, because the retry lowers that kwarg too and it must match exactly. When nothing matches, find_candidate_index raises RuntimeError with the config and candidates. The generated lazy-grid switch throws on an unknown config_index instead of launching a wrong grid.

Alternative considered: strip every launch option from the key and put back only the declared ones. Comparing them directly is simpler, needs no list of launch options, and relaxes nothing beyond what the retry changes.

Repro (fresh compile, B200): a deterministic training graph failed compiling its backward embedding kernel with
  Precomputed grid not found for {BLOCK_EMB_1: 64, BLOCK_EMB_2: 64, BLOCK_EMB_3: 64, num_warps: 8, num_stages: 1}
against candidates stored with num_stages=2.

Test Plan:
Unit tests: the full target, which includes TestPrecomputedGridConfigMatching and runs on remote GPU, so the end-to-end retry tests execute:

```
buck2 test fbcode//caffe2/test/inductor:triton_heuristics
```

https://www.internalfb.com/intern/testinfra/testrun/14636699006161781

Regression check: with the previous revision's _match_key restored and the new tests kept, both test_num_warps_must_match variants fail ('8' != '4': the key picked the first BLOCK=128 candidate rather than the num_warps=4 one), and the rest of the class passes:

```
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching
```

https://www.internalfb.com/intern/testinfra/testrun/3659175108981162

Coverage in TestPrecomputedGridConfigMatching: matching on every config key except num_stages; configs differing only in num_stages sharing the first candidate; num_warps always matching, declared or not (the retry picks the candidate with its num_warps, not the first one with its BLOCK); the num_stages=1 retry selecting the chosen config's candidate; NUM_STAGES never matching a different value; equal key sets required; a declared num_stages constexpr staying in the match key (an equal value matches, the retried value raises) on the find_candidate_index, generate, lazy-autotune, and AOTI-header paths; BLOCK mismatches raising; the AOTI config header selecting/raising; run_triton_kernel_with_autotune selecting/raising; the generated lazy-grid default throwing; _make_launchers -> compile_by_disabling_pipelining -> GridExpr.from_meta with a real triton.Config; and end-to-end GPU tests running a user triton.autotune kernel through torch.compile with every pipelined config failing launcher creation (OutOfResources), in both the Python and cpp_wrapper paths (the latter with triton.autotune_at_compile_time pinned to False so the lazy-grid switch is generated and compiled).

End-to-end (previous revision): the B200 graph from the repro, which failed fresh compilation with the error above, compiled and ran. Not re-run on this revision; its retried config differs from the chosen config only in num_stages, which the match key still ignores.

arc lint -a on all changed files: ok, no issues.

PyTorch lint (lintrunner is not available in fbsource, so the OSS linters were run directly with PyTorch's configs): ruff 0.15.4 with pyproject.toml is clean on all changed files (CI's ruff 0.14.4 flagged the now-removed `# noqa: B950` as unused, RUF100); pyrefly built from fbcode//pyrefly/pyrefly:pyrefly with pyrefly.toml reproduces CI's bad-argument-type at cpp_wrapper_gpu.py:196 before the InductorMeta cast and reports nothing on the diff's changed lines after it; the usort import order was checked by hand.

After the lint fixes, the class reruns green:

```
buck2 test fbcode//caffe2/test/inductor:triton_heuristics -- --regex TestPrecomputedGridConfigMatching
```

https://www.internalfb.com/intern/testinfra/testrun/30680772514800465

Differential Revision: D128937194
pytorch#200916 removed the module-level `import types` when it deleted
TestFastLauncherDeviceSupport, its only user at the time. The new tests in
this PR call `types.SimpleNamespace` and rely on that import, so once both
landed, lint failed with F821 and this PR was auto-reverted. Restore the import.

Test Plan:
lintrunner is not installed in this environment. The changed files match the
merge commit that CI linted (2d1918a) except for this line, and that lint
run's only errors were the two F821s fixed here:

```
git diff 2d1918a -- test/inductor/test_triton_heuristics.py torch/_inductor/codegen/cpp_wrapper_gpu.py torch/_inductor/runtime/hints.py torch/_inductor/runtime/triton_heuristics.py torch/_inductor/runtime/triton_lazy_compile.py
python3 -m py_compile test/inductor/test_triton_heuristics.py
```

Authored with an AI assistant (Claude Code).
@karimelazzouni

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Approvers from one of the following sets are needed:

  • Metamates (aditvenk, andrewor14, angelayi, anshul-si, aorenste, ...)
  • Greenlight Review Bot (pytorchgreenlight)
  • Core Reviewers (mruberry, lezcano, Skylion007, ngimel, peterbell10, ...)
  • Core Maintainers (soumith, gchanan, ezyang, malfet, albanD, ...)
Details for Dev Infra team

Raised by workflow job

Failing merge rule: Core Maintainers

@warrendeng

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged meta-exported module: inductor ready for review Automated review passed, ready for a final review by a maintainer. release notes: inductor (aoti) Reverted topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants