Repository navigation
[inductor] Fix PrecomputedGrid match for pipelining-disabled retry (#203016) - #203016
karimelazzouni wants to merge 2 commits into
Conversation
|
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. |
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (4): Reviewed commit: 🔗 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 FailuresAs of commit fa7f215 with merge base 0341691 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@karimelazzouni has exported this pull request. If you are a Meta employee, you can view the originating Diff in D128937194. |
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
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 label "topic: not user facing" |
…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
c0850ca to
bccb9da
Compare
bccb9da to
f874845
Compare
…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
…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
f874845 to
e0aad96
Compare
e0aad96 to
4ae8901
Compare
…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
…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
…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
…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
0d1b8d3 to
70d89ac
Compare
There was a problem hiding this comment.
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
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).
pytorch/test/inductor/test_triton_heuristics.py
Line 2400 in 70d89ac
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.
pytorch/test/inductor/test_triton_heuristics.py
Line 2252 in 70d89ac
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
|
@pytorchmergebot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
|
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 |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
@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 finished @pytorch-auto-revert[bot]'s task in 53s —— View job The revert is justified: lint on main fails with two Diagnosis and fixErrorlintrunner-noclang-all / lint, at commit 2d1918a (this PR as merged): CauseThe new tests ( Other FixWhen relanding, rebase on current main and add the import back at the top of import tempfile
import types
import unittestOr use |
|
@pytorchbot successfully started a revert job. Check the current status here. |
|
@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).
|
@pytorchbot merge |
Merge failedReason: Approvers from one of the following sets are needed:
|
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
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:
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:
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: B950as 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:
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