Skip to content

util_viewer reads wallclock's breakdown by its own names; Inductor's FX cache key names the machine - #430

Merged
YWHyuk merged 2 commits into
pytorchsim-triton-backendfrom
item8/viewer-and-fx-key
Oct 23, 2026
Merged

YWHyuk merged 2 commits into
pytorchsim-triton-backendfrom
item8/viewer-and-fx-key

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Closes #426

Why

Two readers disagreed with the code that writes their input:

  • scripts/util_viewer.py looked for breakdown.json and read compile records under "the compiler" (a leftover of a blanket rename). pytorchsim/simulator/wallclock.py writes breakdown_<run-id>.json (the _at_exit hook) and keys the records "torchsim-compile". So --breakdown <dump> found nothing, and given the file by name timing_from_breakdowns returned {} and torchsim-compile sorted after spike.
  • NPUChoices.uuid() (pytorchsim/frontend/inductor_patches.py) was "pytorchsim-npu-choices-3-" + record_digest(). The digest is "none" for any machine with no recorded picks, so every such TORCHSIM_TARGET gave Inductor the same FX graph cache key and reused another machine's cached graphs, even though tiling and reduction_split_factor read the machine. Torch builds the key from inductor_choices_class().uuid() (torch/utils/_config_module.py:678, _cache_config_factory_keys).

What changed (before -> after)

  1. c88e7a8 [Tools] util_viewer reads the breakdown wallclock writes, by wallclock's own names
    • wallclock.py: records written under the TORCHSIM_COMPILE constant; new GROUPS (derived from ORDER) replaces the two hard-coded group tuples in render. Pure refactor: GROUPS == ('torchsim-compile','spike','gem5','togsim'), the same tuples as before.
    • util_viewer.py: imports pytorchsim.simulator.wallclock (no torch import) and reads PREFIX, TORCHSIM_COMPILE, GROUPS from it — one name per concept. Search pattern breakdown.json -> breakdown*.json (still matches an old breakdown.json).
    • New tests/system/test_breakdown_viewer.py, added to the matrix in .github/workflows/pytorchsim_test.yml.
  2. 56142ad [Frontend] Inductor's graph cache key names the machine
    • pytorchsim/driver/select.py: new graph_digest() = sha256 over the target's name, target().as_dict(), num_cores and record_digest(); machine part is None on NoTarget.
    • inductor_patches.py: uuid() = "pytorchsim-npu-choices-4-" + graph_digest().
    • New test_graph_cache_key_names_the_machine in tests/system/test_select.py: three machine files all named m.yml (tpuv6e as is, num_cores=2, vpu_spad_size_kb_per_lane=512), no recorded picks.

Tests (parent 069878a vs branch 56142ad)

Test Parent Branch
test_breakdown_viewer.test_viewer_finds_the_file_wallclock_writes FAIL: find_breakdowns(dump) == [] PASS
test_breakdown_viewer.test_viewer_reads_the_compile_records FAIL: timing_from_breakdowns == {}, groups ['spike','torchsim-compile','elsewhere'] PASS
test_select.test_graph_cache_key_names_the_machine FAIL: all three uuids pytorchsim-npu-choices-3-none PASS

The cache-key pin is not vacuous: all three machines share the name m; num_cores is not in as_dict() (PTB contract/target.py:186), so dropping it from the digest fails the cores case; dropping as_dict fails the spad case.

Verification

Container from topk-ptb:pts-base-92028c8 (compiler at 92028c8, not the pin 1b35878; these checks only use its target module and the add smoke). Independently re-run by a reviewer in a separate worktree/container.

  • Smoke on the branch: test_select test_a_refused_config… and test_a_config_running_past_the_cut… pass; tests/system/test_patch_scope.py passes (after building device/ as docker/Dockerfile does); tests/ops/elementwise/test_add.py with TORCHSIM_BREAKDOWN=1: rc=0, 5 passed. On that dump the viewer found the real breakdown_<run>.json, read compile records keyed by kernel, groups ['torchsim-compile','spike','elsewhere'].
  • util_viewer.py --help works when run from /.
  • Not run: test_select_record_and_rebuild, full suites.

Stacking / dependencies

Based on origin/pytorchsim-triton-backend at 069878a, which already contains #421 and #423 — not stacked. PTB pin 1b35878 unchanged.

Open issues

  • The FX key's "machine" is {name, as_dict, num_cores}. In timing mode TOGSim reads machine-file keys outside as_dict (DRAM, NoC, …), so two machines differing only there still share a key. select.identity() (select.py:181) and codecache.identity() (codecache.py:160) use as_dict too, so this is consistent with existing design; follow-up candidate: digest the machine file itself.
  • Rename leftovers not touched: scripts/util_viewer.py:8, :1134 ("the the compiler"), --timing help near :1218; codecache.py:89 docstring; codecache.py:158 build-stamp key "the compiler" (a separate concept — written and compared by the same function; renaming it would make every cached stamp miss).
  • .claude/CLAUDE.md is stale: the test list at line 99 lacks test_breakdown_viewer, line 182 says breakdown.json.
  • util_viewer.py now imports pytorchsim.config (needs PyYAML) via a sys.path insert (util_viewer.py:26-27).

🤖 Generated with Claude Code

https://claude.ai/code/session_01UnJWSTNtd6944XAzy4bhk5

…k's own names

The viewer looked for breakdown.json and read its compile records under
"the compiler" (a leftover of a blanket rename); wallclock writes
breakdown_<run>.json and keys the records "torchsim-compile". So --breakdown
over a dump path found nothing, and given the file by name
timing_from_breakdowns returned {} and torchsim-compile sorted after spike.

wallclock now writes the records under TORCHSIM_COMPILE and states its group
order as GROUPS; util_viewer imports wallclock and reads PREFIX,
TORCHSIM_COMPILE and GROUPS from it.

tests/system/test_breakdown_viewer.py writes a breakdown through wallclock
(span, ingest_compile, the exit hook) and reads it with the viewer. On the
parent: find_breakdowns(dump) == [], timing_from_breakdowns(file) == {},
groups ['spike', 'torchsim-compile', 'elsewhere']. Added to the CI matrix.

Refs #426
NPUChoices.uuid() was "pytorchsim-npu-choices-3-" + record_digest(), and the
digest is "none" for any machine with no recorded picks, so every such
TORCHSIM_TARGET handed Inductor the same FX cache key and reused another
machine's cached graphs, though tiling and reduction_split_factor read the
machine.

select.graph_digest() digests the target's name, target().as_dict() and
num_cores together with record_digest(); uuid() is
"pytorchsim-npu-choices-4-" + that digest.

test_select.test_graph_cache_key_names_the_machine loads three machine files
named m.yml (tpuv6e as is, num_cores 2, vpu_spad_size_kb_per_lane 512) with
no record; on the parent all three uuids are
'pytorchsim-npu-choices-3-none'.

Refs #426
@YWHyuk YWHyuk self-assigned this Oct 23, 2026
@YWHyuk
YWHyuk merged commit 706d9a2 into pytorchsim-triton-backend Oct 23, 2026
@YWHyuk
YWHyuk deleted the item8/viewer-and-fx-key branch October 26, 2026 05:43
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