Skip to content

[Deps] torch 2.14 / triton 3.8, to match PyTorchSim-Triton-Backend - #331

Merged
student-Jungmin merged 15 commits into
pytorchsim-triton-backendfrom
torch-2.14
Oct 9, 2026
Merged

student-Jungmin merged 15 commits into
pytorchsim-triton-backendfrom
torch-2.14

Conversation

@student-Jungmin

@student-Jungmin student-Jungmin commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #329 (inductor-patches) and carries #330's one commit ([CI] Follow PTB's artifact names and stage tags), so the diff shrinks as those land. Needs PyTorchSim-Triton-Backend #37, #38 and #39; the compiler pin points at their merge (integration-torch214, without the sink pass of the closed #40) until they are on main.

Why

PyTorchSim-Triton-Backend moved to Triton 3.8 on 2026-10-07; the first Inductor that targets Triton 3.8 is torch 2.14's. The pins move to torch 2.14.0 / torchvision 0.29.0 / triton 3.8.0 (Dockerfile.base), and the frontend follows the Inductor APIs that changed on the way (the [Deps] commit: optimization_hint, inductor_choices_class.uuid(), scheduling registered as a class, is_available/is_triton_capable on the device interface, the Runner-class wrapper and write_header's self.imports, KernelCallLine kwargs, combo_grid_meta(size_hints_list), C++20).

What else had to change for the allowlist to pass on 2.14

commit problem fix
Autotune only in timing mode; a template too big retries the next tile template autotune compiled the top-4 mm tiles with --tog + gem5 + TOGSim even in functional-only runs (llama: 10 min in autotune, then timeout; llama3x, gemma, qwen the same); a template kernel's spad overflow retried nothing (mobilenet's 1x1 conv via mm at BLOCK_M=16384); a tile whose ELF spills was a hard failure (qwen_next's mm 16x8192x64) autotune gated on pytorchsim_timing_mode; _smaller_tiles yields the other mapped tiles for an mm template, the fixed_config halvings otherwise, and the retry loop also fires on [binary] spill not allowed
A numel of 1 pins a block of 1 _covers left a numel-1 axis at the lane-wide block, so a sort over 256x64 with one valid row became a tile of digits whose mask the DMA refused (deepseek, qwen) the lanes go to the other axis
CompilerError carries the compiler's own stage diagnostic the compiler's indented failure paragraph was filtered out the paragraph's first line is taken first
A kernel's scalar parameters are passed at launch, not baked into the ELF (PTB #39) Inductor unwraps a 0-d CPU input (Adam's step) to step.item(); the compiler baked scalars into the driver, so an earlier commit on this branch kept it a pointer by patching should_unwrap_unspec_arg. That patch is gone: collect_meta records call_params, the launch binds them to the call and spike_run appends each scalar after the .raw paths; the C++ (CPU island) kernel call is rendered plainly, as upstream does the kernel is the one every other Triton backend compiles
fill_ and zero_ run natively; eager_to_compile no longer touches dynamo's mode stack both were in DEFAULT_EAGER_TO_COMPILE, so every eager constant (and the constants Inductor folds while lowering) went through a nested torch.compile, which reset dynamo's non-reentrant TorchFunctionModeStackStateManager ("trying to pop from empty mode stack", swinv2). An earlier commit put the stack back through a private dynamo symbol; that is gone device memory is host memory, so fill_/zero_ are host writes on a CPU view, like _copy_from
No foreach combo kernels on npu; an npu kernel call is a Triton call Inductor fuses torch._foreach_* into one combo kernel that picks tensors by program id; that branch is one the TOG cannot time (every form was refused by the trace producer, so test_mlp never had a timing mode). call_kernel passed triton=False, so a 0-d input was not unwrapped at the call, and the deferred call line was rendered under the CPU island's device BackendFeature.FOREACH dropped from the npu scheduling (Inductor's hook for this): one kernel per tensor; calls go through prepare_triton_kernel_call under the kernel's device
An eager op reached while a compile is in flight runs on the host eager_to_compile was also reached from inside the compiler: Inductor folds a constant by running its ops on the device, and a registered op (fill_ for torch.zeros; mul in torch.ones(4) * 3 reproduces it on demand) started a torch.compile under the running one, which is what emptied dynamo's mode stack torch.compiler.is_compiling() true -> the op runs on the host, like the recursion guard; the device interface's Worker.current_device stops falling through to torch.xpu
test_fp8 leaves the allowlist the compiler refuses 8-bit floats by decision (ops_fp8_roundtrip.py); the CI matrix already lacked the test allowlist and matrix agree again

Verified (torch 2.14.0+cpu, compiler at integration-torch214, cleared caches)

scripts/ci/triton_route_sweep.py over the allowlist (43 tests, functional config, -j 4): 43 of 43 pass, run twice, the second time with the foreach/call commit on top. Models that timed out before torch 2.14 and pass now: llama 240 s, llama3x 290 s, gemma 782 s, qwen 519 s, yolo 348 s; deepseek 290 s and qwen_next 314 s (the numel-1 and spill-retry commits); diffusion 335 s and mllama 154 s (PTB #37); mobilenet 1094 s; swinv2 67 s; test_mlp None s. Total 6119 s of test time.

Timing mode (gem5 + TOGSim, ..._tpuv6e.yml): test_add passes (5 checks); test_mlp passes for the first time (10 checks, 140 s, 24 TOGSim launches) now that its Adam step is one kernel per tensor rather than a combo kernel the TOG could not time.

Compiler: tests/run.py on integration-torch214 539 of 539, no movement against the baseline but the two refusal reproducers that now pass; YOLOv6 (test_yolo.py --version v6, ConvTranspose) passes end to end with PTB #38 (7 checks, 210 s).

Known gaps outside the allowlist

test_sort's 64-row kernel (PTB: a rank-5 indirect tile in 4 descriptor dims), test_indirect_access (tt.atomic_rmw on a pointer tile; the compiler has no atomics), fp8 (refused by decision). No compile starts inside a compile any more (the eager guard above), so dynamo's non-reentrant mode-stack manager is out of reach.

After merging

The CI base image tag follows Dockerfile.base, so the image rebuilds; the compiler pin moves to PTB main once #37-#39 land. Anyone with a local toolchain reruns setup/toolchain.sh ext (new plugin pass) and rebuilds PyTorchSimDevice (new native kernels).

student-Jungmin added a commit that referenced this pull request Oct 9, 2026
…ackend

docker-image.yml triggered on pull requests into master and develop only,
so no PR into the branch PyTorchSim-Triton-Backend pins has ever been
gated: #329, #330 and #331 show no checks. The branch everyone shares
joins the list.
PyTorchSim-Triton-Backend moved to Triton 3.8 on 2026-10-07, and the first
Inductor that targets Triton 3.8 is torch 2.14's. The pins move from torch
2.10 / torchvision 0.25 / triton 3.6 to 2.14.0 / 0.29.0 / 3.8.0, and the
frontend follows the Inductor APIs that changed on the way:

  sizevars.size_hint          -> optimization_hint (inductor_patches,
                                 kernel_spec, launch)
  inductor_choices_class      must implement uuid(); reduction_split_factor
                                 is an instance method and calls super()
  register_backend_for_device takes the scheduling class, not a factory
  has_triton()                asks every device interface is_available()
                                 and is_triton_capable(); npu answers yes
  write_header                puts the imports in self.imports, and the
                                 wrapper's call() is a method of a Runner
                                 class, so the copied generate/write_prefix
                                 go: write_header splices our setup after
                                 super(), write_args adds verify_init, and
                                 run_wrapper_ir_passes inserts the
                                 per-buffer verify lines as WrapperLines
  KernelCallLine.codegen      passes inductor_meta and friends as kwargs
  ComboKernel.combo_grid_meta takes the sub-kernels' size hints
  torch 2.14's headers need C++20 (PyTorchSimDevice/CMakeLists.txt)

Verified on a cleared cache with torch 2.14.0+cpu and PTB main bb37976: the
allowlist sweep (scripts/ci/triton_route_sweep.py) passes 40 of 44 with the
commits that follow this one; the four left are deepseek, qwen and qwen_next
(fixed next) and test_fp8, whose f8E5M2 the compiler no longer lowers.
…chine retries the next mapped tile

Template autotune compiled the top-4 mm tiles each with --tog, gem5 and a
TOGSim run, in a functional-only run as well, where no cycle is ever read.
That is where the big models' time went: test_llama alone spent 10 minutes
in autotune (one bmm candidate took 204 s) and timed out the sweep, as did
llama3x, gemma and qwen. Autotune now runs only when pytorchsim_timing_mode
is on, since cycles are what it ranks by. test_llama passes in 239 s on the
functional config, gemma in 804 s, llama3x in 292 s.

The scratchpad-overflow retry knew only pointwise and reduction blocks: a
template kernel's BLOCK_M/N/K are literals in its source, so nothing was
retried and mobilenet's 1x1 conv via mm stopped at BLOCK_M=16384 with
458880 bytes/lane over 262144. _smaller_tiles now yields the other mapped
tiles of an mm template (best first) and the fixed_config halvings for
every other kernel, and the same loop retries when the ELF spills: the
compiler refuses any vector register spill ([binary] spill not allowed),
and a tile that spills is a tile too big for the register file the same
way. qwen_next's mm 16x8192x64 spilled at BLOCK_N=8192 and compiles at
4096; test_qwen_next passes in 364 s, test_mobilenet in 1148 s.
The compiler prints one failure paragraph under the stage that failed:

    [2/2] torchsim-compile:lower  FAIL  (0.4s)  ...

      no fold or peel states this rank-5 tile [16, 2, 8, 4, 2] in 4
      descriptor dims: ...

The message filter skipped it: _SIGNAL rejects indented lines, and the
paragraph is indented, so a failure like the one above reached Inductor as
three "[transform] ..." progress lines. The paragraph's first line is now
taken first, _SIGNAL second; the latter also accepts a dotted exception
name with its message (DigitRefused) and the [transform]/[lower]/[binary]
refusals, which it missed before.
Inductor unwraps a 0-d CPU tensor input into a scalar kernel argument on
every device but cpu (should_unwrap_unspec_arg), so the kernel signature
said fp32 while the spec, built from the argument types, said *fp32, and
the launch passed a tensor where the compiler had baked a scalar. Adam's
step counter is such an input, so test_mlp's training step failed at its
first fused kernel.

The compiler bakes scalars into the ELF, and this one changes on every
call, so on npu the input stays a tensor the kernel loads. test_mlp passes
(10 checks, 37 s).
A compiled call under `with torch.device("npu")` failed with "trying to pop
from empty mode stack". Dynamo saves the torch-function mode stack in a
module-level TorchFunctionModeStackStateManager while it traces, and
restores it when tracing ends. An op the device has no eager kernel for
reaches eager_to_compile from inside Inductor's tracing (Dynamo runs the
graph's constants eagerly), and its own torch.compile entered the same
manager, whose __exit__ reset the saved stack to [] -- so the outer trace
restored nothing and the device context's __exit__ had nothing to pop.

The nested compile now puts the outer stack back on the manager when it
returns. test_swinv2, which names the default device for the compiled
call, passes (86 s).
_covers left an axis whose numel is 1 at the lane-wide block, on the
reasoning that a block of 1 leaves the lanes none. For a reduction kernel
that is the wrong axis to spend them on: a sort over 64 values with
xnumel = 1 became a 256x64 tile with one valid row, TritonGPU laid its
lanes over both axes, materialize_layouts cut the rows into digits, and
the masked store on that axis was refused:

    DigitRefused: a DMA masked_axes on a dim cut into digits

which stopped DeepSeek-V3 and Qwen3 at their first top-k sort kernel, and
test_sort at its first kernel. With XBLOCK = 1 the tile is 1x64, the lanes
go to the reduction axis, and the same kernel compiles; a pointwise kernel
of one element compiles at a block of 1 too, so nothing needs the old
exception any more.

Verified on cleared caches: test_deepseek_v3_base passes (333 s), test_qwen
(514 s), test_topk (6 s); test_sort gets past its first ten checks and now
stops at a 64-row kernel the compiler cannot fit into four descriptor
dims, which is the compiler's gap, not this one's.
…d into the ELF

The compiler took every scalar parameter (`r0_numel`, and an input Inductor
unwraps to a value) as a literal in the spec's `scalar_values` and compiled
it into the driver, so the previous commit had to keep Adam's step counter
a pointer by patching Inductor's should_unwrap_unspec_arg. PyTorchSim-
Triton-Backend 7787b4c reads the scalars off argv after the tensor paths
and lists them in kernel.json, so that patch goes and the kernel is the one
every other Triton backend compiles.

collect_meta records `call_params`, the kernel's parameter names in call
order, and leaves a scalar out of the tensor args; scalar_args gives a numel
its codegen value as the default and an unwrapped input none; the launch
binds call_params to the call's arguments, and spike_run appends each
scalar's value (argv_scalars) after the .raw paths. write_shape reads the
parallel numels by name instead of taking the trailing integers, which a
runtime integer scalar would have joined. gem5 passes no argv and keeps the
defaults; the trace producer never reads a scalar.

The wrapper applied prepare_triton_kernel_call to every kernel call, so the
CPU island's C++ foreach kernel (the step counters' `+= 1`) was handed
`.item()` values where it expects tensors once the unwrap was on. A C++
kernel's call is now rendered plainly, as Inductor's own path does.

The compiler pin moves to 7787b4c (branch runtime-scalars, PSAL-POSTECH/
PyTorchSim-Triton-Backend#39) for the ABI and for the pass that lowers the
shared-body foreach kernel Inductor emits once the scalar is a scalar.

Verified: test_mlp passes 10 checks in 28 s (Adam over four parameters, the
step a scalar parameter of the combo kernel); test_add, test_topk,
test_swinv2 pass; allowlist sweep in the PR.
…ches dynamo's mode stack

fill_.Scalar and zero_ were in DEFAULT_EAGER_TO_COMPILE, so every constant
the device made in eager mode (`torch.zeros(..., device="npu")`, and the
constants Inductor folds while lowering a graph) went through its own
torch.compile. A compile nested inside a compile is what broke swinv2: the
nested one reset dynamo's module-level TorchFunctionModeStackStateManager,
and the previous commit put the saved stack back through a private dynamo
symbol.

The device's memory is host memory, so a fill is a host write on the same
storage, the way _copy_from already copies: fill_ and zero_ are registered
for npu over a CPU view of the tensor, and leave the eager-to-compile list.
Nothing is simulated for them, which is also true of cudaMemset; the
nested compile for a constant is gone, and with it the dynamo patch.

The ops left in DEFAULT_EAGER_TO_COMPILE (cat, mm, pooling, argmax, ...)
would still nest a compile if Inductor folded one as a constant; none of
the allowlisted models does, and the proper fix for that is a reentrant
state manager upstream.

Verified: test_swinv2 passes (`with torch.device("npu")` around the
compiled call, 92 s); the dynamo repro (torch.zeros inside a compiled
function under the device context) passes.
PyTorchSim-Triton-Backend refuses 8-bit floats by decision
(tests/cases/mechanism/ops/ops_fp8_roundtrip.py: "not on this backend's
path ... what remains is upstream LLVM or a fork of the RISC-V backend, and
we are not carrying it"), since its adapt-ttgir rework. The test fails at
the first fp8 kernel with "f8E5M2 is not an element type this machine
runs" and cannot gate a PR. The CI matrix in pytorchsim_test.yml already
lacked it, so the two agree again.
…#38 and #39

The three compiler changes this branch needs are open as separate pull
requests (replica reads through a gather or a merging collapse; the
gathered axis matched by tensor axis; scalar parameters at launch and the
shared-body foreach kernel). Until they land on main the pin is their
merge, branch integration-torch214, so the CI image carries all three;
it moves to main once they do.
…iton call

Inductor fuses torch._foreach_* over a parameter list into one combo kernel
that picks each sub-kernel's tensors by program id and runs one body. That
dispatch is a GPU launch-overhead trade this machine has nothing to gain
from, and the branch is one the TOG cannot time: every form of the kernel,
the per-branch bodies of before and the shared body of now, was refused by
the trace producer ("15 loop(s) survive into the trace without a TOG node"),
so test_mlp never had a timing mode. BackendFeature.FOREACH is dropped from
the npu scheduling's features, the hook Inductor gives a backend for this,
and a foreach op lowers to one kernel per tensor. The compiler's
sink-into-pointer-ifs pass stays for the Triton that does pick pointers by
program id.

call_kernel passed triton=False, which was how the call escaped the stream
and grid rendering; the wrapper's helper now takes triton=True as the npu
path, so the call goes through prepare_triton_kernel_call and a 0-d CPU
input is unwrapped to its value as the kernel's signature says. The helper
renders the line under the kernel's own device: the line is emitted after
the CPU island's, when the graph's current device is cpu, where the unwrap
is decided the other way for a mutated input.

Verified: test_mlp passes 10 checks in functional mode (29 s) and, for the
first time, in timing mode (140 s, 24 TOGSim launches); test_add passes.
…m-Triton-Backend #37, #38, #39)

The pass that lowered Inductor's shared-body foreach kernel is its own pull
request now (#40), and nothing on npu asks for that kernel form since
BackendFeature.FOREACH went, so the pin is the merge of the three the
branch needs. test_mlp, test_add and test_swinv2 pass against it.
… host, not through a second compile

eager_to_compile exists so model work that lands in eager mode (a graph
break, an op with no eager kernel) is still compiled and simulated. It was
also reached from INSIDE the compiler: Inductor folds a constant by running
its ops on the device at compile time, and a registered op (fill_ for
torch.zeros, mul in `torch.ones(4) * 3`) then started a torch.compile under
the one already running. Dynamo keeps the torch-function mode stack in one
non-reentrant manager, so the inner compile emptied what the outer one
restores and `with torch.device("npu")` failed on exit ("trying to pop from
empty mode stack"); on torch 2.14 that is how swinv2 died, and
`torch.ones(4) * 3` with mul registered reproduces it on demand.

Compile-time work is not the workload: the constant is computed once, by
the compiler, and never timed. So an eager op that finds
torch.compiler.is_compiling() true runs on the host, like the recursion
guard already did, and no compile ever starts inside a compile. The rule
is the public API's; the earlier private-symbol patch is not needed.

The device interface's Worker.current_device fell through to
torch.xpu.current_device(), a leftover of the XPU interface it was copied
from, which Inductor's decode_device hits for a factory op whose device has
no index (`torch.device("npu")`). It answers torch.npu.current_device().

Verified: the mul reproducer passes with the device given with and without
an index; test_eager, test_eager_to_compile_recursion, test_swinv2 (48 s)
and test_deepseek_v3_base (259 s, which registers its own eager ops) pass.
…#41 and #39 merged

The integration branch the pin pointed at is retired; main carries the
replica reads through a gather or a merging collapse (#37), the gathered
axis matched by tensor axis (#41, the retargeted #38) and the scalar
parameters at launch with DRAM arguments by tensor ordinal (#39).
…ackend

docker-image.yml triggered on pull requests into master and develop only,
so no PR into the branch PyTorchSim-Triton-Backend pins has ever been
gated: #329, #330 and #331 show no checks. The branch everyone shares
joins the list.
@student-Jungmin
student-Jungmin merged commit 7a9cce8 into pytorchsim-triton-backend Oct 9, 2026
@student-Jungmin
student-Jungmin deleted the torch-2.14 branch October 9, 2026 15:25
student-Jungmin added a commit that referenced this pull request Oct 9, 2026
…s the test stack

PyTorchSim-Triton-Backend publishes an image per commit (images.yml:
ghcr.io/psal-postech/pytorchsim-triton-backend:<sha>), built on the
vcix-accelerator environment image -- Ubuntu 22.04 with python3.11, the
RISC-V toolchain, pk, Spike, gem5 -- with LLVM, Triton and the torchsim
backend, the model, the compiler, its dialect and extension, doctor and
smoke passed. This repository's CI ignored it: Dockerfile.ptb cloned the
compiler at the pin and ran toolchain.sh llvm triton vcixenv vcix dialect
ext, building all of that again from source, on top of a base image that
itself installed python3.11 and torch on a bare Ubuntu. A moved pin cost
an hour of toolchain build before the first test could run, and the clone
needed a token for the private repository, which is what stopped #331's
first gated run.

Dockerfile.base is now FROM the compiler's image at the pin, adding only
`python`, boost, PyTorch 2.14 / torchvision 0.29 (CPU) and the packages
the tests import, and the environment the compiler route reads
(TORCHSIM_COMPILE_DIR, the Triton source tree on PYTHONPATH, the
extension, gem5). Its tag hashes the compiler pin as well, so a moved pin
rebuilds it; nothing of the compiler is built here. Dockerfile.ptb and
ptb_base_pin.sh go, as do the "Check PTB access" job and every use of a
token: the compiler's package grants this repository read access, and the
default Actions token pulls it. The app image removes the compiler's
PyTorchSim checkout before copying the tree under test to the same path,
so the compiler's trace producer reads this tree's TOGSim headers. The
base job moves to the big self-hosted runner, where a ~10 GB image fits.
pytorchsim_triton_backend.yml gates PRs into pytorchsim-triton-backend as
well, and watches Dockerfile.base in place of Dockerfile.ptb.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant