Repository navigation
[Frontend] has_triton, the conv heuristic and the SDPA flags are upstream's (PTB rule 16) - #435
Merged
YWHyuk merged 3 commits intoOct 23, 2026
Conversation
…face and the torchsim driver answer them _claim_triton_present replaced torch.utils._triton.has_triton, scheduler.has_triton and triton_hash_with_backend with constants. On torch 2.14 with the PTB torchsim driver none of that is needed: has_triton() walks the registered device interfaces, and npu's ExtensionDeviceInterface says it is available and Triton capable; triton_hash_with_backend() hashes the active driver's backend, which is torchsim's CPUDriver. Pin: tests/system/test_patch_scope.py test_triton_presence_is_upstream parent: [True, False, False] (has_triton a lambda, hash = our constant) this: [True, True, True] Refs #427
…n every choices class
_size_conv_blocks_from_the_machine replaced InductorChoices.get_config_heuristics for
every subclass and every caller. Inductor reaches it only through V.choices
(kernel/conv.py, choices.py get_conv_configs/get_depthwise_conv_configs/flex), and
V.choices is NPUChoices, so the override now lives there and upstream's class is left
alone. The deprecated torch._inductor.template_heuristics shim imports
(inductor_patches.py, codegen/tiling.py) now name torch._inductor.heuristics.template.
Pin: tests/system/test_patch_scope.py test_conv_heuristics_are_upstream_outside_npu_choices
[InductorChoices("npu") BLOCK_N == upstream BaseConfigHeuristic's,
NPUChoices("npu") BLOCK_N == [vector_lanes]]
parent: [False, True] this: [True, True]
Refs #427
… them openreg._lazy_init turned flash SDPA off and set overrideable/math on for the whole process. npu's _fused_sdp_choice (device/csrc/aten/native/Extra.cpp) reads only the overrideable flag, which is on by default, so the npu route is unchanged; the flash flag only ever reached cpu, whose fused choice fell from FLASH (1) to MATH (0). Pin: tests/system/test_patch_scope.py test_sdpa_flags_are_upstream compares [flash, mem_efficient, math, overrideable, cpu _fused_sdp_choice] with a process started with TORCH_DEVICE_BACKEND_AUTOLOAD=0 parent: [0, 1, 1, 1, 0] vs [1, 1, 1, 1, 1] this: equal npu: tests/ops/attention/test_sdpa.py 16/16 and test_fused_sdpa.py 11/11, route lines identical to the parent's. Refs #427
YWHyuk
force-pushed
the
item11/public-extension-points
branch
from
October 23, 2026 09:51
4c3009d to
5db43bf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #427
Scope trimmed (2026-10-23). The post-grad pass hookup (was b0cb85d) and the npu-only histc/polar decompositions (was 4c3009d) are dropped from this PR: #433 rewrites the same code as
post_grad_passregistered throughdevice_custom_pass. A probe on #433 (cpu-in/cpu-out graph using npu inside:topk(a.to(npu)*2, 4)) showsaten.topkdoes not reach lowering and the values match, with a cpu-only control where it does — so the coverage concern that made this PR keep the list form does not apply to #433. This PR keeps the three changes #433 does not make.Why
PTB rule 16: the backend attaches to PyTorch/Inductor only through public extension points. Three places in PTS replaced or wrapped upstream behaviour globally (for every device), or duplicated what upstream already does once npu's device interface is registered. Each one is removed or moved onto an npu-scoped extension point.
What changed (before -> after)
_claim_triton_present(frontend/inductor_patches.py) forcedhas_triton()/triton_hash_with_backend()has_triton()(torch/utils/_triton.py:208-239) already answers True via npu's registeredExtensionDeviceInterface; the hash goes through the active torchsimCPUDriver.InductorChoices.get_config_heuristics(all devices)NPUChoices.get_config_heuristicsreturns the lane-wide conv table for"npu"; Inductor reaches it only viaV.choices(kernel/conv.py:655,728,1087). Shim imports retargeted totorch._inductor.heuristics.template.*.device/torch_openreg/openreg/__init__.py:88-90called threetorch._C._set_sdp_use_*on importExtra.cpp:15-48reads onlyuserEnabledOverrideableSDP).Tests (each fails on its parent for the stated reason)
tests/system/test_patch_scope.py::test_triton_presence_is_upstream[True,False,False][True,True,True]...::test_conv_heuristics_are_upstream_outside_npu_choices[False,True]...::test_sdpa_flags_are_upstream(vs. subprocess withTORCH_DEVICE_BACKEND_AUTOLOAD=0)[0,1,1,1,0]vs[1,1,1,1,1]tests/ops/misc/test_complex_to_real.pynow traces with npu inputs (the graph the pass actually runs on); with CPU inputs it only saw polar decomposed because of the leak 4c3009d closes. It passes on the parent too.Verification
Container on image
topk-ptb:pts-base-92028c8; each pin checked on its parent by overlaying the parent's files. Independent review re-ran every pin and the smoke in a separate container.Smoke on HEAD 4c3009d, all rc=0: test_patch_scope 10/10, test_topk 5/5, test_grouped_mm 1/1, test_row_matmul 4/4, test_complex_to_real 2/2, test_histc 3/3, test_polar 2/2, test_group_conv 1/1; on earlier commits of this branch also test_sdpa 16/16 (route lines identical to base), test_fused_sdpa 11/11, test_conv2d 14/14, test_eager_to_compile_recursion, test_reduction_tiling.
Post-grad position: a probe recording each
GraphLowering's call_function targets and externs for npu topk, row mm, row addmm and RoPE gives identical output on base and on this branch; the five kernels'07-regularized.mlirare byte-identical.Stacking / dependencies
Not stacked. Based on
pytorchsim-triton-backend@ 069878a; #421 and #423 are already merged there and touch none of these files.git merge-treeagainst the current base (5fb15ee) is clean. Open #430 editsNPUChoices.uuidininductor_patches.pyin a different hunk. No PTB change; PTBorigin/mainreferences none of the removed symbols.Open issues
requires_gradgrad error moved0.000e+00->5.535e-07(CPU reference backward now uses upstream flash SDPA instead of math); well under the 1e-4 tolerance._claim_triton_presentused to raise a clear error whentritonwas not importable; now a badPYTHONPATHmakeshas_triton()return False (cached)._npu_config_heuristiccaches a class in a module global; it could be a module-level class.rewrite_grouped_mm(targettransformers.grouped_mm_fallback) has no test; test_grouped_mm coversaten._grouped_mm.NpuPostGradPasses.uuid()is a fixed string, so editing a pass body does not invalidate the FX cache (same as the old_Chain).torch._C._get_overrideable_sdp_enabled,torch._fused_sdp_choice,mock.patch.object(GraphLowering, "run")), in tests only.AlgorithmSelectorCachepatches, convolution and degenerate-gemm lowering wraps, conv grid functions, theGPU_TYPESappend.🤖 Generated with Claude Code
https://claude.ai/code/session_01UnJWSTNtd6944XAzy4bhk5