Skip to content

[CI] The bundle copies a workload from the last bundle when its key is unchanged - #407

Merged
YWHyuk merged 2 commits into
pytorchsim-triton-backendfrom
ci/bundle-reuse
Oct 21, 2026
Merged

YWHyuk merged 2 commits into
pytorchsim-triton-backendfrom
ci/bundle-reuse

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #406.

What

The validation bundle job copies a workload from the previous bundle, without building it, when nothing that decides its kernels changed.

  • scripts/ci/bundle.py --reuse PREV: before scheduling, each workload whose PREV/keys/<workload>.json holds this run's key (and whose PREV/out/<workload>/manifest.json exists) is copied from PREV/out/<workload>. Only the misses go to largest_first / the Pool. The log prints [bundle] <name>: reused [...] and [bundle] N reused, M built.

  • Every workload that is built gets KEYS/<workload>.json (--keys, default OUT/../keys), written after its manifest and only when no launch is heuristic. A workload that fails the bundle that way is rebuilt next time.

  • The key is sha256 over json.dumps(sort_keys=True) of ids and values, never file text:

    • PTS_INPUTS: the git tree/blob ids of pytorchsim/, device/ and scripts/ci/bundle.py, computed outside the container (the container copies the tree without .git).
    • BASE_IMAGE: the content-hashed base tag (torch, Triton, compiler, TOGSim).
    • torch.__version__.
    • select.identity(): the compiler pin, the machine and the TOGSim ABI. The compiler decides the template picks and the scratchpad-overflow retries. This also keeps the key tied to the record: a record voided by a new identity cannot meet a matching key.
    • the run settings (config.RUN_SETTINGS) and TORCHSIM_TARGET.
    • every TORCHSIM_*, TORCHINDUCTOR_* and TRITON_* variable in the container's environment, from the base image or the workflow's docker run -e, except the paths a run picks for itself: TORCHSIM_DUMP_PATH, TORCHSIM_LOG_PATH, and the cache dirs TORCHINDUCTOR_CACHE_DIR / TRITON_CACHE_DIR that config and Inductor set while compiling. An Inductor/Triton env change in the workflow file therefore rebuilds. The workflow file itself is not in PTS_INPUTS, so a CI-only push that changes no such variable still reuses.
    • the workload row: suite, csv, name, dims, dtype.

    Without PTS_INPUTS (a local run) no key is computed, so nothing is reused and no key is written. Otherwise a dirty worktree could match a key built from HEAD.

  • Keys sit in bundle/keys, beside bundle/out and not inside it. ptb_bundle_pr.sh still copies only bundle/out, so the bundle proposed to PTB is unchanged. A key inside out/ would hold the tree id, change on every push and open or refresh the PR.

  • previous_picks.sh is replaced by previous_bundle.sh PICKS PREV. It does the same listing (push runs on the branch, newest first, skipping this run, first non-expired pts-bundle that has record/) and takes the record and out/ + keys/ from that one artifact. A rebuilt workload that shares a lookup key with a reused one (e.g. gemm_1024x2048x128 and the layer's prefill projection, kernel irwmpeez) then gets the pick the reused one was built with. The script never fails. With no artifact, or none with keys/ (every artifact before this lands), everything is built.

  • Selection record: a reused workload runs nothing, so it adds nothing to selection.jsonl. The record it came with is copied in and passes through. With 0 timed picks the merge is skipped and the record is byte-identical. When some workloads are rebuilt, only their keys are replaced (selection_merge.py).

  • Workflow: -e PTS_INPUTS -e BASE_IMAGE -v prev:/prev:ro, and --reuse /prev on all three bundle.py processes. The artifact now carries bundle/{out,record,keys,*.log}. The Propose step is unchanged.

  • Test: tests/system/test_bundle_reuse.py is wired into the pytorchsim_test.yml matrix and triton_route_passing.txt. It builds vector_slice_8x128 with keys, then reuses it with build patched to count calls: 0 builds and out byte-identical. It checks that a row dropped from the CSV is not carried over, and that a changed PTS_INPUTS, a changed TORCHINDUCTOR_PERSISTENT_REDUCTIONS, a planted heuristic tile source, and no PTS_INPUTS each rebuild. A different TORCHSIM_DUMP_PATH / TORCHSIM_LOG_PATH / TRITON_CACHE_DIR still reuses. On e67e923 it fails with TypeError: main() got an unexpected keyword argument 'prev'. Against the first commit (f4d84cf) the env assertions fail: the Inductor env change was reused, and with TRITON_CACHE_DIR keyed the per-run path assertion fails. On this branch it passes in about 8 s, with the image's own validation tables and with PTB main's.

Verification (local, image topk-pts:24ce740, PTB-main validation tables)

The CI step was reproduced on 8 workloads: gemm process (timing 1): gemm_128x768x768, gemm_1024x2048x128, layer_op_gmm_down_1x0. Layer process (timing 1): layer_op_router_post_128x0. Rest process (timing 0): vector_softmax_1024x128, vector_slice_8x128, attention_decode_16x8x128, layer_op_rmsnorm_1x0. Each run had a fresh dump, the record merge, and the record copied out.

run previous built / reused wall
cold none 8 / 0 (2 GEMM picks timed and merged) 31 s
warm cold (record + out + keys) 0 / 8, empty selection.jsonl, merge skipped 7 s
rebuilt cold record only, no prev 8 / 0 24 s
changed warm, gemm process at TOPK=2, one softmax row's C 128 → 192 gemm 3 built; layer 1 reused; rest: vector_softmax_1024x192 built, 3 reused; 1024x128 not carried 23 s
  • diff -r of out/ (27 files): cold == warm == rebuilt. In the changed run, every workload in both runs is identical. Keys cold == warm. The record is byte-identical across cold, warm and rebuilt. Keys of rebuilt-with-record differ from cold only in tile_sources (timed → recorded); the hash is the same.
  • Environment (commit a192dc5). Before it, vector_softmax_1024x128 built with TORCHINDUCTOR_PERSISTENT_REDUCTIONS=0 gives kernel softmax_dnzg64oz. But --reuse of a default-env bundle copied softmax_4ujjgst4, a stale reuse. Now that run rebuilds dnzg64oz (byte-identical to a no-reuse build), and a run that changes only TORCHSIM_DUMP_PATH reuses 4ujjgst4. The 8-workload CI reproduction re-run on a192dc5 gives cold 8 built / 30 s and warm 8 reused / 7 s. out/ and the record are identical, and all 8 key hashes are equal. Keying TRITON_CACHE_DIR had made the 3 GEMMs miss: Inductor sets it in the pool worker while compiling, so the parent's key never matched.
  • previous_bundle.sh against the live repo picked run 39544924634. Its record is byte-identical to the one previous_picks.sh gave, its out/ is identical to the downloaded artifact (469 workloads), and it found 0 keyed workloads, so the first run after this builds everything. With a bad token it warns, exits 0 and leaves both dirs empty.

Expected hit rate (stated plainly)

  • Of the last 21 push runs, 14 changed pytorchsim/** or device/** and 11 moved the pin or base. Only 3/21 would reuse under this key. Workflow-dispatch re-runs, CI-only pushes, and the rebuild after a partial failure would also reuse. Keys are written per workload that completed, so a failed run's finished workloads can be reused.
  • Pin moves are not cacheable by design: the compiler decides picks and retries. On those pushes the Build step was measured at 52–54 min, against 23–24 min when the record held.
  • Artifacts of consecutive pushes show 84–94% of workloads byte-identical even when pytorchsim/** changed. A whole-tree key cannot see that. (Opinion) a later per-kernel layer could catch it, but it still runs Inductor and the TOGSim launch. Skipping the per-launch TOGSim run in bundle mode may be a bigger lever. Not measured on large rows; out of scope here.
  • pts-bundle is 2.7 MB zipped (run 39544924634).

Known gaps / open questions

  • device/** is part of the key but is not a push trigger of this workflow. This gap already existed.
  • The fetch still reads only event=push runs, as previous_picks.sh did. Should workflow_dispatch artifacts count too?
  • A pick made by wall-time CUT_FACTOR under load stays frozen until its key changes. The record already does this.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UnJWSTNtd6944XAzy4bhk5

…s unchanged

bundle.py --reuse PREV copies PREV/out/<workload> instead of building it when
PREV/keys/<workload>.json holds the key this run computes, and writes a key for
every workload it builds without an unpicked launch. The key hashes the git ids of
pytorchsim/, device/ and scripts/ci/bundle.py (env PTS_INPUTS), the base image tag,
torch, select.identity() (compiler pin, machine, TOGSim ABI), the run settings, the
target and the workload's row. Keys live in bundle/keys, beside bundle/out, so the
bundle proposed to PTB is unchanged.

previous_picks.sh becomes previous_bundle.sh: one artifact gives the record (picks/)
and the previous bundle (prev/out, prev/keys), so a rebuilt workload takes the picks
the reused ones were built with. Refs #406.
The key saw only RUN_SETTINGS and TORCHSIM_TARGET of the container's env, so an env var that changes the
generated kernels (set by the base image or by the workflow's docker -e, a push-triggering file outside
PTS_INPUTS) reused the previous bundle's kernels. Reproduced: vector_softmax_1024x128 built with
TORCHINDUCTOR_PERSISTENT_REDUCTIONS=0 gives softmax_dnzg64oz, while --reuse of a default-env bundle
copied softmax_4ujjgst4.

The key now holds every TORCHSIM_*, TORCHINDUCTOR_* and TRITON_* variable except the paths each run
picks for itself: TORCHSIM_DUMP_PATH, TORCHSIM_LOG_PATH, and the cache dirs TORCHINDUCTOR_CACHE_DIR and
TRITON_CACHE_DIR, which config and Inductor set while compiling (with TRITON_CACHE_DIR keyed, a GEMM
built in a pool worker after compiling never matched the key the parent computed for reuse). The workflow file stays out of PTS_INPUTS, so a CI-only push still hits.
@YWHyuk
YWHyuk merged commit f703453 into pytorchsim-triton-backend Oct 21, 2026
@YWHyuk
YWHyuk deleted the ci/bundle-reuse branch October 23, 2026 03:03
YunseonShin added a commit that referenced this pull request Nov 18, 2026
…t8 on the matrix unit, kernel format 11) and #408 (the JSON spec states on_chip)
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