Repository navigation
A launch directory per kernel launch; a model test's forward in one TOGSim session - #529
Merged
student-Jungmin merged 2 commits intoNov 10, 2026
Conversation
…a record of its call A kernel's launch directory was per kernel and per process, so two launches of one compiled kernel shared its shape, tensor and held runtime attribute files, and a session could read the second launch's files for the first. Its meta.json named the first call site's buffers for every launch (Qwen3-8B prefill's v_proj read as a second k_proj). Each launch now gets launch-<pid>-<n>-<unique> beside the kernel's shared tog.so and cycle tables (symlinked), holding that launch's files and launch.json: the kernel, and per argument the name the wrapper passes (bufN, also through reinterpret_tensor), shape, stride, dtype and data_ptr. The names are written into each npu kernel call at codegen by TritonNPUWrapperCodegen, taken from Inductor's IR nodes (get_name, a ReinterpretView's buffer, or a call arg the graph knows as a buffer or input), never parsed from rendered strings; numel and literal arguments are None. Nothing inspects frames. A process removes its launch directories when it exits unless TORCHSIM_KEEP_LAUNCHES=1, which a user keeps to map a session trace back to tensors. workdir_of returns the kernel workdir for a copy node's handle too. Pins: tests/system/test_launch_record.py (one kernel launched twice in a session, and an inline reinterpret_tensor argument) and test_launch_dir.py (a name an earlier run with the same pid left, removal at exit and keeping), failing on the tree before. Qwen3-8B cycles unchanged.
… the session prints its cycles Each kernel launch ran TOGSim standalone and a layer's cycles were the sum of those runs, each starting from an empty simulator, so a layer had no single timeline and its DRAM trace could not be laid end to end. A session is what a caller opens: every model test (one_layer.run for every --part layer row, its MLA decode, and the lm, body or fixed-input call of twenty model tests) now runs its device call inside `with torch.npu.TOGSimulator():`; the CPU reference stays outside. A launch outside any block still runs standalone, as before. A block's launches print nothing of their own, so TOGSimulator, when its block closes without an exception, prints one "[TOGSim] session simulated: N cycles, K launches" line from the result TOGSim wrote, which run_grid already sums as it summed the standalone launches' lines. tests/system/test_session_cycles.py pins it: two kernels in one block give that line once; on the tree before, the block printed none. Qwen3-8B layer decode 1024: 462,104 summed, 456,635 in one session; prefill 128: 603,709 and 597,573. Kernels run back to back; each is a little shorter without a standalone run's start and drain.
student-Jungmin
changed the base branch from
pr/pts-4-decode-writes-kv
to
pytorchsim-triton-backend
November 10, 2026 18:07
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.
Summary
Stacked on #528.
launch-<pid>-<n>-<unique>) withlaunch.jsonrecording the call: two launches of one compiled kernel (Qwen3-8B prefill's k_proj and v_proj) used to share and overwrite each other's shape, address and runtime-attribute files, and a session could read the second's for the first. Argument names come from Inductor's IR at codegen.TORCHSIM_KEEP_LAUNCHES=1keeps the directories past exit.The two graph_prefetch system tests' mocked launchers now take the new
torchsim_arg_nameskeyword.Verification
test_launch_record.py and test_launch_dir.py fail on the tree before; Qwen3-8B cycles unchanged.