Repository navigation
[Refactor 5/9] simulator/ is functional/ and timing/; postgrad/ by op family; cleanup; verify golden fix; CI runs the new tests - #455
Merged
student-Jungmin merged 1 commit intoOct 24, 2026
Conversation
student-Jungmin
force-pushed
the
refactor/r441-7-simulator
branch
from
October 24, 2026 07:32
51a5a2a to
75d965d
Compare
student-Jungmin
changed the base branch from
refactor/r441-6-codegen
to
refactor/r441-5-autotune
October 24, 2026 07:32
student-Jungmin
force-pushed
the
refactor/r441-5-autotune
branch
from
October 24, 2026 08:17
291f563 to
8ca3b66
Compare
student-Jungmin
force-pushed
the
refactor/r441-7-simulator
branch
from
October 24, 2026 08:17
75d965d to
05e738c
Compare
… the verify golden fixed, CI runs the new tests functional/ holds tensor io and replay, with spike.py beside it; timing/ holds the cycle tables and the per-launch files, with gem5.py and togsim.py beside them. Each file opens with what the others call. poisson_request_generator is the README's example code, not a simulator API. A .raw file's dtype is the compiler's contract's (kernel_object.NP_DTYPE), so fp8 leaves the frontend's tables until the contract has it. post_grad_pass is postgrad/, one module per op family (histc, gemm, convolution, complex), the pass and register_rewrite in its __init__; its uuid hashes every module. Comments inside function bodies go or move into docstrings, and no except Exception hides why a value is missing. The per-kernel verify's CPU golden ran in-place ops on the real inputs (_to_cpu returned a CPU tensor itself) and failed on Inductor's reinplaced foreach, so test_mlp's Optimizer case failed under TORCHSIM_FUNCTIONAL_VERIFY_PER_KERNEL=1; it now copies and reads a reinplaced op as the argument it wrote (test_verify_golden). histc over a floating input with min == max is left to aten, which refuses a range that is not finite (test_histc). The tests this refactor added join the allowlist and the CI matrix. Comments and docstrings in the files this part changes are at most three lines, none inside a function body. What they no longer say: backend/codecache.py: torchsim_compile is synchronous on purpose: a thread pool buys nothing until the pipeline itself is proven. backend/compiler_input.py: a block Inductor fixed in the kernel body is skipped because passing it would not match the signature; Adam's step is the 0-d CPU tensor case. backend/template_timing.py: a recorded pick is the pick without an epilogue, so a recorded template built with one fused is RECORDED_UNFUSED. frontend/inductor/__init__.py: in timing mode a template with an epilogue is picked by its fused cycles, Inductor timing the top configs one at a time in this process (TritonNPUScheduling.benchmark_codegened_module). frontend/inductor/postgrad/__init__.py: a rewrite returns plain torch code for the node's place, or a Decline that leaves it (logged, counted in CALLS); docs/post_grad_rewrite.md says how to add one. codegen/kernel_metadata.py: writes_arg returns True when nothing is recorded, so it narrows only where there is a measurement to narrow it with. codegen/verify.py: the golden runs the original aten graph (V.graph.module) on CPU once per graph execution; the first divergent buffer pinpoints the fused op-cluster, the finest granularity observable since ops inside a kernel are not materialized; tolerances TORCHSIM_FUNCTIONAL_VERIFY_RTOL/ATOL (1e-4); the config is read on each call because it can change inside a torch.npu.TOGSimulator block. pytorchsim/simulator/functional/__init__.py: run -- a replayed result is not one the simulator produced today; replay is for the inner loop, not for reporting. pytorchsim/simulator/functional/__init__.py: read_outputs -- view_as would be the same defect as .contiguous(); the kernel wrote the addresses the strides name. pytorchsim/simulator/functional/__init__.py: _replay_key -- the ELF's bytes, so a fix anywhere in the compiler misses; the Triton source is already in the workdir path. pytorchsim/simulator/functional/__init__.py: _replay_root -- a cache inside a workdir would be deleted with outputs/triton_* exactly when it was most wanted. pytorchsim/simulator/timing/__init__.py: _write_extents -- the grid belongs to the launch, so the file goes in this process's launch directory. device/torch_openreg/openreg/__init__.py: eager_to_compile -- measured: torch.cat over two complex64 tensors with aten::cat.out registered hit RecursionError; Inductor declines complex, emits aten.cat.default, whose out-variant path lands back on the wrapper (Kimi-VL MoonViT 2D rope table). Without the registration the same program runs. device/torch_openreg/openreg/__init__.py: Stream.__del__ -- interpreter shutdown can clear module globals before __del__; destroy only when the runtime handle and the stream are still valid. tests/ops/misc/test_histc.py: test_histc_integral -- NotImplementedError: "histogram_cpu" not implemented for 'Int'; transformers' MoE router (integrations/moe.py) picks its histc dtype by device name, which stopped DeepSeek-V3 under transformers 5.15.0. Both int32 and int64 because they take different paths back. tests/ops/misc/test_polar.py: test_polar_on_transposed -- aten::polar is CompositeExplicitAutograd and beats the boxed CPU fallback; assert_size_stride(buf14, (1, 32, 32), (1024, 1, 32)) fails with "expected size 32==32, stride 32==1 at dim=1".
student-Jungmin
force-pushed
the
refactor/r441-5-autotune
branch
from
October 24, 2026 11:15
8ca3b66 to
f7a0cf3
Compare
student-Jungmin
force-pushed
the
refactor/r441-7-simulator
branch
from
October 24, 2026 11:16
05e738c to
d6ea410
Compare
student-Jungmin
marked this pull request as ready for review
October 24, 2026 14:00
student-Jungmin
changed the base branch from
refactor/r441-5-autotune
to
pytorchsim-triton-backend
October 24, 2026 14:00
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 and the validation reports) before review.
Part 5 of 9 of the frontend refactor. It is one commit (75d965d) of this part's final state, so each part reviews on its own. Stacked on #453 (
refactor/r441-5-autotune); review only this PR's commit.This PR absorbs #456.
What
functional/ holds tensor io and replay, with spike.py beside it; timing/ holds the cycle tables
and the per-launch files, with gem5.py and togsim.py beside them. Each file opens with what the
others call. poisson_request_generator is the README's example code, not a simulator API. A .raw
file's dtype is the compiler's contract's (kernel_object.NP_DTYPE), so fp8 leaves the frontend's
tables until the contract has it.
post_grad_pass is postgrad/, one module per op family (histc, gemm, convolution, complex), the
pass and register_rewrite in its init; its uuid hashes every module. Comments inside function
bodies go or move into docstrings, and no except Exception hides why a value is missing.
The per-kernel verify's CPU golden ran in-place ops on the real inputs (_to_cpu returned a CPU
tensor itself) and failed on Inductor's reinplaced foreach, so test_mlp's Optimizer case failed
under TORCHSIM_FUNCTIONAL_VERIFY_PER_KERNEL=1; it now copies and reads a reinplaced op as the
argument it wrote (test_verify_golden). histc over a floating input with min == max is left to
aten, which refuses a range that is not finite (test_histc). The tests this refactor added join
the allowlist and the CI matrix.
Behavior change
Checked locally
At this PR's tip, with PTB 522042a (this branch's pin) and TOGSim b9c9519, everything passes: system: test_module_form, test_device_interface, test_verify_golden, test_togsim_exit, test_togsim_result, test_patch_scope, test_cache_identity, test_attribute_sources, test_eager, test_select (TIMING_MODE=1); ops: test_add 5/5, test_matmul 11/11, test_histc, test_topk, test_conv_transpose 5/5, test_custom_fused_kernel.
No cycle numbers here: nothing in this part is meant to change a kernel's cycles. The CI validation report is the check.
Comments and docstrings in the files these parts change are at most three lines, none inside a function body. What they no longer say is in the commit message. Test files whose only change here is an import rename (test_result -> check_result) and scripts/ keep their comments, as this change did not touch that code.
Known gap
On the compiler pin (PTB 522042a), test_conv_decomposition's depthwise_grad case fails in the compiler's lower step. It reports
runtime attribute: the index tile of "torchsim.transfer" ... is no one entry per position of its gatherfor the forward stencil kernel of the training graph. The other 6 cases pass. On #441 the same backward does not run at all (convolution_backward_overrideable: NotImplementedError). On the earlier compiler (PTB 1b35878) the case passed. Cause: PTB's fit-transfers-to-descriptor folded the gather's data tile but not its tile-shaped index tile. Fixed in PSAL-POSTECH/PyTorchSim-Triton-Backend#351; with it, all 11 cases pass. This case needs a compiler pin that carries #351.