Repository navigation
[CI] The bundle copies a workload from the last bundle when its key is unchanged - #407
Merged
Merged
Conversation
…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.
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)
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.
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 whosePREV/keys/<workload>.jsonholds this run's key (and whosePREV/out/<workload>/manifest.jsonexists) is copied fromPREV/out/<workload>. Only the misses go tolargest_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, defaultOUT/../keys), written after its manifest and only when no launch isheuristic. 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 ofpytorchsim/,device/andscripts/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.config.RUN_SETTINGS) andTORCHSIM_TARGET.TORCHSIM_*,TORCHINDUCTOR_*andTRITON_*variable in the container's environment, from the base image or the workflow'sdocker run -e, except the paths a run picks for itself:TORCHSIM_DUMP_PATH,TORCHSIM_LOG_PATH, and the cache dirsTORCHINDUCTOR_CACHE_DIR/TRITON_CACHE_DIRthat config and Inductor set while compiling. An Inductor/Triton env change in the workflow file therefore rebuilds. The workflow file itself is not inPTS_INPUTS, so a CI-only push that changes no such variable still reuses.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, besidebundle/outand not inside it.ptb_bundle_pr.shstill copies onlybundle/out, so the bundle proposed to PTB is unchanged. A key insideout/would hold the tree id, change on every push and open or refresh the PR.previous_picks.shis replaced byprevious_bundle.sh PICKS PREV. It does the same listing (push runs on the branch, newest first, skipping this run, first non-expiredpts-bundlethat hasrecord/) and takes the record andout/+keys/from that one artifact. A rebuilt workload that shares a lookup key with a reused one (e.g.gemm_1024x2048x128and the layer's prefill projection, kernelirwmpeez) then gets the pick the reused one was built with. The script never fails. With no artifact, or none withkeys/(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 /prevon all threebundle.pyprocesses. The artifact now carriesbundle/{out,record,keys,*.log}. The Propose step is unchanged.Test:
tests/system/test_bundle_reuse.pyis wired into thepytorchsim_test.ymlmatrix andtriton_route_passing.txt. It buildsvector_slice_8x128with keys, then reuses it with build patched to count calls: 0 builds andoutbyte-identical. It checks that a row dropped from the CSV is not carried over, and that a changedPTS_INPUTS, a changedTORCHINDUCTOR_PERSISTENT_REDUCTIONS, a plantedheuristictile source, and noPTS_INPUTSeach rebuild. A differentTORCHSIM_DUMP_PATH/TORCHSIM_LOG_PATH/TRITON_CACHE_DIRstill reuses. One67e923it fails withTypeError: main() got an unexpected keyword argument 'prev'. Against the first commit (f4d84cf) the env assertions fail: the Inductor env change was reused, and withTRITON_CACHE_DIRkeyed 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.selection.jsonl, merge skippedTOPK=2, one softmax row's C 128 → 192vector_softmax_1024x192built, 3 reused;1024x128not carrieddiff -rofout/(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 intile_sources(timed→recorded); the hash is the same.a192dc5). Before it,vector_softmax_1024x128built withTORCHINDUCTOR_PERSISTENT_REDUCTIONS=0gives kernelsoftmax_dnzg64oz. But--reuseof a default-env bundle copiedsoftmax_4ujjgst4, a stale reuse. Now that run rebuildsdnzg64oz(byte-identical to a no-reuse build), and a run that changes onlyTORCHSIM_DUMP_PATHreuses4ujjgst4. The 8-workload CI reproduction re-run ona192dc5gives cold 8 built / 30 s and warm 8 reused / 7 s.out/and the record are identical, and all 8 key hashes are equal. KeyingTRITON_CACHE_DIRhad made the 3 GEMMs miss: Inductor sets it in the pool worker while compiling, so the parent's key never matched.previous_bundle.shagainst the live repo picked run 39544924634. Its record is byte-identical to the oneprevious_picks.shgave, itsout/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)
pytorchsim/**ordevice/**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.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-bundleis 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.event=pushruns, asprevious_picks.shdid. Shouldworkflow_dispatchartifacts count too?CUT_FACTORunder load stays frozen until its key changes. The record already does this.🤖 Generated with Claude Code
https://claude.ai/code/session_01UnJWSTNtd6944XAzy4bhk5