Repository navigation
Fixes from reading the refactor: a queued TOGSimulator launch, npu RNG state, grouped_mm and sort fallbacks, stale stage directories - #464
Merged
Conversation
…its held attribute copy goes at shutdown Inside `with torch.npu.TOGSimulator()` with timing on, the first launch failed: torch.npu.launch_kernel queues the launch on the stream and returns None, and TritonNPULauncher took a non-int as a standalone result and indexed result["total_cycles"] (TypeError: 'NoneType' object is not subscriptable). run_togsim now returns None for a queued launch, and the launcher logs it as queued. Each queued launch of a kernel with runtime attributes copied them into launch-<pid>/runtime_attribute-* for the session to read later, and nothing removed the copies. The session now keeps them in TOGSimProcess.held and removes them in shutdown, after the Simulator has exited. test_togsim_result: a held copy is gone after shutdown and the original stays; a queued launch returns None. A 256x256 add compiled and timed inside a TOGSimulator now passes (2741 cycles).
…again
openreg/random.py kept the openreg example's device name: get_rng_state and set_rng_state defaulted
to device="openreg" and turned an index into torch.device("openreg", i), a device type torch no longer
knows once PrivateUse1 is renamed npu. Called with no device (torch.utils.checkpoint's preserve_rng_state
does) or with an index, both raised "Expected one of cpu, cuda, ... device string: openreg". They now
name npu.
test_device_interface: the state reads and writes back for the default device, 0, "npu" and "npu:0";
it fails with the old default.
… and a plan with no tile declines
The fallback (eager calls, and compiled ones plan declines) concatenated the groups' products, so with
offs ending before A's last row it returned offs[-1] rows where aten._grouped_mm and transformers'
grouped_mm_fallback return A's S rows; the kernel already allocates [S, N]. It now writes each group
into an [S, N] output whose rows past offs[-1] are zero, as transformers' fallback gives them (aten
leaves them unspecified). A bias was added to every row; aten refuses one ("Bias not supported yet"),
and so does the fallback now. plan took the first GEMM tile candidate unchecked, an IndexError on a
machine whose scratchpad holds none; it declines instead. The kernel is unchanged.
test_grouped_mm: tail (offs[-1] < S, eager rows past it zero, compiled rows up to it match) and bias
(refused); all 7 cases pass.
…ot an IsADirectoryError clear_stale removes what another identity built, matching "[0-9][0-9]-*" among others, with os.remove, and since #462 raises any removal error but a file already gone. The compiler at PTB 2abb4a3 leaves each stage's per-pass dumps as a directory (08-passes, 09-passes), so the first rebuild of such a workdir under another identity failed the compile with IsADirectoryError. A directory is now removed with shutil.rmtree; a symlink or file still with os.remove. test_cache_identity: a workdir with 08-passes/, kernel.json and a stage file keeps only the spec; on the old code it raises IsADirectoryError.
…t32's plan takes int32, int64 and float32 only, so a float64 sort always runs the fallback, and the fallback keyed every float through t.float(): float64 values one float32 holds as equal (1 + 2^-30, 1, 1 + 2^-40) kept their input order. A float64 is now keyed by its 64 bits (NaN canonical and last, -0 as +0, as the 32-bit key); every other float still by float32's, so the kernel's keys and the fallback's still agree. test_sort: a float64 row of such values, -0, 0, NaN and -1, both orders, gives torch.sort's indices; the old fallback gave [6, 3, 4, 0, 1, 2, 5] for [6, 3, 4, 1, 2, 0, 5]. All 26 cases pass.
student-Jungmin
marked this pull request as ready for review
October 24, 2026 15:09
student-Jungmin
merged commit Oct 24, 2026
e1d8aa3
into
pytorchsim-triton-backend
2 of 3 checks passed
student-Jungmin
added a commit
that referenced
this pull request
Oct 24, 2026
device/torch_openreg/lib is no longer tracked: a local build symlink from #464 broke the device build in CI
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.
Draft: waiting for verification (CI) before review.
Bugs found reading the merged refactor (pytorchsim-triton-backend 338b42d), each reproduced first. One commit per bug; no commit depends on another, and no default changes. Each fix comes with a test that fails on the old code.
What
[Simulator])with torch.npu.TOGSimulator()with timing on, the first launch raisedTypeError: 'NoneType' object is not subscriptable. The cause:torch.npu.launch_kernelqueues the launch and returns None, and the launcher indexed that None as a standalone result.run_togsimnow returns None for a queued launch (after its copy nodes, as [GEMM Timing Validation][Frontend] An npu mm the compiler's copy_node.plan holds runs the resident mm, as v6e XLA runs it #457 queues them), and the launcher logs it as queued.[Device])get_rng_stateandset_rng_statedefaulted todevice="openreg", a device torch no longer knows once PrivateUse1 is renamed npu. Called with no device, astorch.utils.checkpointcalls them, or with an index, they raised.[Dispatcher])offs[-1] < Sit returnedoffs[-1]rows; aten and transformers return S. Rows pastoffs[-1]are now zero, as transformers gives them.planindexed the first GEMM tile candidate unchecked; with no candidate it now declines. The kernel is unchanged.clear_staleon a stage directory ([Backend], a regression from [Refactor 7/9] One place for each fact: tool paths in config, the runtime attribute directory, build identity, launch hooks, template records #462)08-passes/and09-passes/directories.os.removeraisedIsADirectoryError, which failed the first rebuild of a workdir under another identity.shutil.rmtree.[Dispatcher])Checked locally
Setup: this branch on PTB 6f88e2b (this branch's pin), TOGSim 5791272, target tpuv6e.
tailandbiasnew)Known gap, not from this PR:
test_conv_decompositionfails onconv1dat lower ("3 access(es) leave their scratchpad buffer's slot"). It fails the same way on the base 338b42d. Bisected to PSAL-POSTECH/PyTorchSim-Triton-Backend ef0d13df (fit-to-numel cuts a dot's K below the block the matmul lowering reads); its parent f6ddd80f compiles the kernel. The fix goes to the compiler.