diff --git a/.github/workflows/pytorchsim_test.yml b/.github/workflows/pytorchsim_test.yml index fa45e3ddb..147fb7861 100644 --- a/.github/workflows/pytorchsim_test.yml +++ b/.github/workflows/pytorchsim_test.yml @@ -73,6 +73,7 @@ jobs: - tests/ops/misc/test_widen_dtype.py - tests/ops/reduce/test_batchnorm.py - tests/ops/view/test_view3D_2D.py + - tests/system/test_bundle_reuse.py - tests/system/test_compiler_failure.py - tests/system/test_eager.py - tests/system/test_patch_scope.py diff --git a/.github/workflows/pytorchsim_triton_backend.yml b/.github/workflows/pytorchsim_triton_backend.yml index efcdab14b..b377fcdc8 100644 --- a/.github/workflows/pytorchsim_triton_backend.yml +++ b/.github/workflows/pytorchsim_triton_backend.yml @@ -25,7 +25,7 @@ on: - 'scripts/ci/triton_route_*' - 'scripts/ci/bundle.py' - 'scripts/ci/ptb_bundle_pr.sh' - - 'scripts/ci/previous_picks.sh' + - 'scripts/ci/previous_bundle.sh' - '.github/workflows/pytorchsim_triton_backend.yml' workflow_dispatch: inputs: @@ -241,34 +241,36 @@ jobs: printf %s "$TOKEN" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin - name: Pull the base image run: docker pull "$BASE_IMAGE" - # The record the last bundle on the branch left: a config it holds is taken without timing it. - - name: Previous picks + # The last bundle on the branch, its record and its kernels: a config the record holds is taken without + # timing it, and a workload whose key it holds is copied without building it. + - name: Previous bundle env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} - run: rm -rf picks && bash scripts/ci/previous_picks.sh picks + run: rm -rf picks prev && bash scripts/ci/previous_bundle.sh picks prev # The GEMMs and the layer (its projections are mm templates) in timing mode, their configs picked by # TOGSim cycles where the record has none, beside the other suites without it: three runs, since a # process keeps the timing mode it started in. The GEMMs build in four processes, largest first. The # layer, only its rows under the compiler's CI cap, builds in four processes (87 min measured, against ~3.8 h in one: its prefill at S 4096 alone is ~85 min). - # The record, with this run's picks folded in, is uploaded beside the bundle (bundle/record) for the - # next run. + # The record, with this run's picks folded in, and the workloads' keys are uploaded beside the bundle + # (bundle/record, bundle/keys) for the next run; PTS_INPUTS are the git ids the keys hash. - name: Build the bundle run: | mkdir -p bundle && chmod 777 bundle - docker run --rm -e PTS_COMMIT="$SOURCE_SHA" -e TORCHSIM_FUNCTIONAL_MODE=0 \ - -v "$PWD:/src:ro" -v "$PWD/picks:/picks:ro" -v "$PWD/bundle:/bundle" "${BASE_IMAGE}" bash -lc ' + PTS_INPUTS="$(git rev-parse HEAD:pytorchsim HEAD:device HEAD:scripts/ci/bundle.py | tr '\n' ' ')" + docker run --rm -e PTS_COMMIT="$SOURCE_SHA" -e PTS_INPUTS="$PTS_INPUTS" -e BASE_IMAGE -e TORCHSIM_FUNCTIONAL_MODE=0 \ + -v "$PWD:/src:ro" -v "$PWD/picks:/picks:ro" -v "$PWD/prev:/prev:ro" -v "$PWD/bundle:/bundle" "${BASE_IMAGE}" bash -lc ' set -euo pipefail mkdir -p "$TORCHSIM_DIR" tar -C /src --exclude=./.git --exclude=./.github -cf - . | tar -C "$TORCHSIM_DIR" -xf - (cd "$TORCHSIM_DIR/device" && python -m pip install -q --no-build-isolation -e .) cd "$TORCHSIM_DIR" mkdir -p pytorchsim/selection && cp /picks/*.json pytorchsim/selection/ 2>/dev/null || true - TORCHSIM_TIMING_MODE=1 TORCHSIM_DUMP_PATH=/tmp/gemm python3 scripts/ci/bundle.py /bundle/out gemm --jobs 4 \ + TORCHSIM_TIMING_MODE=1 TORCHSIM_DUMP_PATH=/tmp/gemm python3 scripts/ci/bundle.py /bundle/out gemm --jobs 4 --reuse /prev \ > /bundle/gemm.log 2>&1 & gemm=$! - TORCHSIM_TIMING_MODE=1 TORCHSIM_DUMP_PATH=/tmp/layer python3 scripts/ci/bundle.py /bundle/out layer --jobs 4 \ + TORCHSIM_TIMING_MODE=1 TORCHSIM_DUMP_PATH=/tmp/layer python3 scripts/ci/bundle.py /bundle/out layer --jobs 4 --reuse /prev \ > /bundle/layer.log 2>&1 & layer=$! - TORCHSIM_DUMP_PATH=/tmp/rest python3 scripts/ci/bundle.py /bundle/out vector attention \ + TORCHSIM_DUMP_PATH=/tmp/rest python3 scripts/ci/bundle.py /bundle/out vector attention --reuse /prev \ > /bundle/rest.log 2>&1 & rest=$! rc=0; wait $gemm || rc=1; wait $layer || rc=1; wait $rest || rc=1 grep "^\[bundle\]" /bundle/gemm.log /bundle/layer.log /bundle/rest.log || true diff --git a/scripts/ci/bundle.py b/scripts/ci/bundle.py index 6347f052a..8b52ae539 100644 --- a/scripts/ci/bundle.py +++ b/scripts/ci/bundle.py @@ -25,10 +25,15 @@ kernel a timed run picks. One recorded without its fused epilogue ("recorded_unfused") is kept and named in a warning. The picks the GEMMs were timed to are appended to selection.jsonl in the dump path, for scripts/selection_merge.py. + +--reuse PREV copies PREV/out/ when PREV/keys/.json holds the key this run writes to +KEYS (--keys, default OUT/../keys, not in OUT): a hash of env PTS_INPUTS and BASE_IMAGE, torch, the +selection identity, the run settings and the row. Without PTS_INPUTS nothing is keyed or reused. """ import argparse import csv +import hashlib import importlib.util import json import multiprocessing @@ -258,7 +263,7 @@ def compiler_suite(suite): def workloads(suites=None): - """(name, suite, dims, fn, inputs maker) per measured row of `suites` (default all); a CAPPED + """(name, suite, dims, fn, inputs maker, csv) per measured row of `suites` (default all); a CAPPED suite's rows over the compiler's CI cap are left out.""" for suite, csv_name, keys, program, call in SUITES: if suites and suite not in suites: @@ -275,7 +280,7 @@ def workloads(suites=None): fn, make = call(dims) name = "_".join([suite, *(dims[k] for k in keys if k in TEXT_COLUMNS), "x".join(str(dims[k]) for k in keys if k not in TEXT_COLUMNS), DTYPE]) - yield name, suite, dims, fn, make + yield name, suite, dims, fn, make, csv_name LAUNCHED = [] @@ -315,24 +320,93 @@ def pts_commit(): cwd=config.CONFIG_TORCHSIM_DIR).stdout.strip() -def build(out, suite, name): - """Build `suite`'s workload `name` into out/: (name, kernels launched, unpicked, unfused, externs).""" - dims, fn, make = next(w[2:] for w in workloads({suite}) if w[0] == name) +KEYED_ENV = ("TORCHSIM_", "TORCHINDUCTOR_", "TRITON_") +PER_RUN_ENV = {"TORCHSIM_DUMP_PATH", "TORCHSIM_LOG_PATH", "TORCHINDUCTOR_CACHE_DIR", "TRITON_CACHE_DIR"} + + +def keyed_env(): + """The environment PyTorchSim, Inductor and Triton read, less the cache and output paths each run + picks for itself (Inductor sets TORCHINDUCTOR_CACHE_DIR and TRITON_CACHE_DIR while compiling).""" + return {k: v for k, v in os.environ.items() if k.startswith(KEYED_ENV) and k not in PER_RUN_ENV} + + +def key_inputs(suite, name, dims, csv_name): + """What decides workload `name`'s kernels, as ids and values; None without env PTS_INPUTS.""" + pts = os.environ.get("PTS_INPUTS", "").split() + if not pts: + return None + return {"pts": pts, "base_image": os.environ.get("BASE_IMAGE", ""), "torch": torch.__version__, + "env": keyed_env(), + "identity": select.identity(), "target": config.CONFIG_TORCHSIM_TARGET, + "run": {s: getattr(config, s) for s in config.RUN_SETTINGS}, + "workload": {"suite": suite, "csv": csv_name, "name": name, "dims": dims, "dtype": DTYPE}} + + +def workload_key(inputs): + return hashlib.sha256(json.dumps(inputs, sort_keys=True).encode()).hexdigest() + + +def write_key(keys, name, inputs, sources, externs): + os.makedirs(keys, exist_ok=True) + with open(os.path.join(keys, f"{name}.json"), "w") as f: + json.dump({"key": workload_key(inputs), "inputs": inputs, "tile_sources": sources, + "externs": externs}, f, indent=1, sort_keys=True) + + +def build(out, suite, name, keys=None): + """Build `suite`'s workload `name` into out/, and its key into keys/.json unless a launch + is unpicked: (name, kernels launched, unpicked, unfused, externs).""" + dims, fn, make, csv_name = next(w[2:] for w in workloads({suite}) if w[0] == name) shutil.rmtree(os.path.join(out, name), ignore_errors=True) + if keys: + _remove(os.path.join(keys, f"{name}.json")) launches, sources, externs = capture(name, fn, make, out) with open(os.path.join(out, name, "manifest.json"), "w") as f: json.dump({"workload": name, "suite": suite, **dims, "dtype": DTYPE, "launches": launches, "externs": externs}, f, indent=1) unpicked = [la["kernel"] for la, s in zip(launches, sources) if s == select.HEURISTIC] unfused = [la["kernel"] for la, s in zip(launches, sources) if s == select.RECORDED_UNFUSED] - return name, [la["kernel"] for la in launches], unpicked, unfused, [e["call"] for e in externs] + calls = [e["call"] for e in externs] + inputs = key_inputs(suite, name, dims, csv_name) + if keys and inputs is not None and not unpicked: + write_key(keys, name, inputs, sources, calls) + return name, [la["kernel"] for la in launches], unpicked, unfused, calls + + +def _remove(path): + try: + os.remove(path) + except FileNotFoundError: + pass + + +def reuse(prev, out, keys, suite, name, dims, csv_name): + """Copy prev/out/ into out/ when prev/keys/.json holds today's key and no unpicked + launch: (name, kernels, [], unfused, externs), else None.""" + inputs = key_inputs(suite, name, dims, csv_name) + try: + with open(os.path.join(prev, "keys", f"{name}.json")) as f: + old = json.load(f) + with open(os.path.join(prev, "out", name, "manifest.json")) as f: + manifest = json.load(f) + except (OSError, ValueError): + return None + if inputs is None or old.get("key") != workload_key(inputs) \ + or select.HEURISTIC in old.get("tile_sources", [select.HEURISTIC]): + return None + shutil.rmtree(os.path.join(out, name), ignore_errors=True) + shutil.copytree(os.path.join(prev, "out", name), os.path.join(out, name)) + write_key(keys, name, inputs, old["tile_sources"], old["externs"]) + kernels = [la["kernel"] for la in manifest["launches"]] + unfused = [k for k, s in zip(kernels, old["tile_sources"]) if s == select.RECORDED_UNFUSED] + return name, kernels, [], unfused, old["externs"] def largest_first(suites): """(suite, workload name) of `suites`, each suite's ordered by the compiler's rank where it has one.""" names = [] for suite in dict.fromkeys(s[0] for s in SUITES if not suites or s[0] in suites): - mine = [(n, d) for n, s, d, _, _ in workloads({suite})] + mine = [(w[0], w[2]) for w in workloads({suite})] rank = _rank(suite) names += [(suite, n) for n, d in (sorted(mine, key=lambda w: -rank(w[1])) if rank else mine)] return names @@ -347,21 +421,30 @@ def _rank(suite): return (lambda d: mod.cost(d, keys)) if hasattr(mod, "cost") else None -def main(out, suites=None, jobs=1): +def main(out, suites=None, jobs=1, keys=None, prev=None): """Write `suites`' workloads (default all) into `out`, replacing each one's directory there, in - `jobs` processes.""" + `jobs` processes; each one whose key `prev` holds is copied from it instead of built.""" os.makedirs(out, exist_ok=True) + keys = keys or os.path.join(os.path.dirname(out), "keys") unpicked, unfused = [], [] - names = largest_first(suites) + names, reused = largest_first(suites), [] + if prev: + rows = {(w[1], w[0]): (w[2], w[5]) for w in workloads(suites)} + reused = [r for r in (reuse(prev, out, keys, s, n, *rows[s, n]) for s, n in names) if r] + names = [n for n in names if n[1] not in {r[0] for r in reused}] if jobs > 1: pool = multiprocessing.get_context("spawn").Pool(jobs) - built = pool.imap_unordered(_build, [(out, *n) for n in names]) + built = pool.imap_unordered(_build, [(out, *n, keys) for n in names]) else: - pool, built = None, (build(out, *n) for n in names) + pool, built = None, (build(out, *n, keys) for n in names) + for name, kernels, up, uf, externs in reused: + unfused += [(name, k) for k in uf] + print(f"[bundle] {name}: reused {kernels}" + (f" extern {externs}" if externs else ""), flush=True) for name, kernels, up, uf, externs in built: unpicked += [(name, k) for k in up] unfused += [(name, k) for k in uf] print(f"[bundle] {name}: {kernels}" + (f" extern {externs}" if externs else ""), flush=True) + print(f"[bundle] {len(reused)} reused, {len(names)} built", flush=True) if pool is not None: pool.close() pool.join() @@ -383,5 +466,8 @@ def _build(args): ap.add_argument("out") ap.add_argument("suites", nargs="*", help="suites to build (default: all)") ap.add_argument("--jobs", type=int, default=1, help="processes building workloads at once") + ap.add_argument("--keys", help="where the workloads' keys are written (default: OUT/../keys)") + ap.add_argument("--reuse", metavar="PREV", help="a previous bundle (PREV/out, PREV/keys) to copy matches from") a = ap.parse_args() - main(os.path.abspath(a.out), set(a.suites), a.jobs) + main(os.path.abspath(a.out), set(a.suites), a.jobs, a.keys and os.path.abspath(a.keys), + a.reuse and os.path.abspath(a.reuse)) diff --git a/scripts/ci/previous_bundle.sh b/scripts/ci/previous_bundle.sh new file mode 100755 index 000000000..d41ae7ece --- /dev/null +++ b/scripts/ci/previous_bundle.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# The newest pts-bundle on BRANCH with a selection record, whole: record/ to PICKS, out/ and keys/ to PREV (for +# bundle.py --reuse), so the picks and the kernels are one run's. Never fails; with none both stay empty. +# GH_TOKEN=... REPO=owner/name scripts/ci/previous_bundle.sh PICKS PREV +set -uo pipefail +: "${GH_TOKEN:?a token that reads the actions of this repository}" +: "${REPO:?owner/name}" +: "${BRANCH:=pytorchsim-triton-backend}" +: "${WORKFLOW:=pytorchsim_triton_backend.yml}" +: "${EVENT:=push}" +PICKS=${1:?the directory to write the record to} +PREV=${2:?the directory to write the previous bundle to} +mkdir -p "$PICKS" "$PREV" + +api() { curl -fsSL -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$@"; } + +RUNS=$(api "https://api.github.com/repos/$REPO/actions/workflows/$WORKFLOW/runs?branch=$BRANCH&event=$EVENT&per_page=30") \ + || { echo "::warning::could not list the bundle runs on $BRANCH: every workload is built"; exit 0; } +for run in $(jq -r --arg me "${GITHUB_RUN_ID:-0}" '.workflow_runs[] | select((.id|tostring) != $me) | .id' <<<"$RUNS"); do + id=$(api "https://api.github.com/repos/$REPO/actions/runs/$run/artifacts?per_page=100" \ + | jq -r '[.artifacts[] | select(.name == "pts-bundle" and (.expired|not))][0].id // empty') || continue + [ -n "$id" ] || continue + zip=$(mktemp) && api -o "$zip" "https://api.github.com/repos/$REPO/actions/artifacts/$id/zip" || { rm -f "$zip"; continue; } + python3 -I - "$zip" "$PICKS" "$PREV" <<'PY' || { rm -f "$zip"; rm -rf "${PICKS:?}"/* "${PREV:?}"/*; continue; } +import os, sys, zipfile +z, picks, prev = zipfile.ZipFile(sys.argv[1]), sys.argv[2], sys.argv[3] +names = z.namelist() +record = [n for n in names if n.startswith("record/") and n.endswith(".json")] +if not record: + sys.exit(1) +for n in record: + with open(os.path.join(picks, os.path.basename(n)), "wb") as f: + f.write(z.read(n)) +for n in names: + if n.startswith(("out/", "keys/")) and not n.endswith("/"): + z.extract(n, prev) +PY + rm -f "$zip" + echo "bundle of run $run: picks $(ls "$PICKS"), $(ls "$PREV/keys" 2>/dev/null | wc -l) keyed workloads" + exit 0 +done +echo "::warning::no bundle run on $BRANCH left a selection record: every workload is built" +exit 0 diff --git a/scripts/ci/previous_picks.sh b/scripts/ci/previous_picks.sh deleted file mode 100755 index 1f04a9b81..000000000 --- a/scripts/ci/previous_picks.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -# The selection record the newest bundle job on BRANCH left (record/ in its pts-bundle artifact), as OUT/.json: -# the bundle takes a recorded config without timing it, and times only what the record lacks or no longer holds -# (another compiler, machine or TOGSim voids the record; a changed template, its entries). Leaves OUT empty when -# there is none, and never fails the job: without it every GEMM is timed. -# GH_TOKEN=... REPO=owner/name scripts/ci/previous_picks.sh OUT -set -uo pipefail -: "${GH_TOKEN:?a token that reads the actions of this repository}" -: "${REPO:?owner/name}" -: "${BRANCH:=pytorchsim-triton-backend}" -: "${WORKFLOW:=pytorchsim_triton_backend.yml}" -: "${EVENT:=push}" -OUT=${1:?the directory to write} -mkdir -p "$OUT" - -api() { curl -fsSL -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$@"; } - -RUNS=$(api "https://api.github.com/repos/$REPO/actions/workflows/$WORKFLOW/runs?branch=$BRANCH&event=$EVENT&per_page=30") \ - || { echo "::warning::could not list the bundle runs on $BRANCH: every GEMM is timed"; exit 0; } -for run in $(jq -r --arg me "${GITHUB_RUN_ID:-0}" '.workflow_runs[] | select((.id|tostring) != $me) | .id' <<<"$RUNS"); do - id=$(api "https://api.github.com/repos/$REPO/actions/runs/$run/artifacts?per_page=100" \ - | jq -r '[.artifacts[] | select(.name == "pts-bundle" and (.expired|not))][0].id // empty') || continue - [ -n "$id" ] || continue - api -o "$OUT/a.zip" "https://api.github.com/repos/$REPO/actions/artifacts/$id/zip" || continue - python3 - "$OUT/a.zip" "$OUT" <<'EOF' || { rm -f "$OUT"/*; continue; } -import os, sys, zipfile -z = zipfile.ZipFile(sys.argv[1]) -names = [n for n in z.namelist() if n.startswith("record/") and n.endswith(".json")] -if not names: - sys.exit(1) -for n in names: - with open(os.path.join(sys.argv[2], os.path.basename(n)), "wb") as f: - f.write(z.read(n)) -EOF - rm -f "$OUT/a.zip" - echo "picks of run $run: $(ls "$OUT")" - exit 0 -done -echo "::warning::no bundle run on $BRANCH left a selection record: every GEMM is timed" -exit 0 diff --git a/scripts/ci/triton_route_passing.txt b/scripts/ci/triton_route_passing.txt index d12367bd4..9655088a2 100644 --- a/scripts/ci/triton_route_passing.txt +++ b/scripts/ci/triton_route_passing.txt @@ -273,6 +273,7 @@ tests/ops/misc/test_user_triton_kernel.py tests/ops/misc/test_widen_dtype.py tests/ops/reduce/test_batchnorm.py tests/ops/view/test_view3D_2D.py +tests/system/test_bundle_reuse.py tests/system/test_eager.py tests/system/test_patch_scope.py tests/system/test_togsim_exit.py diff --git a/tests/system/test_bundle_reuse.py b/tests/system/test_bundle_reuse.py new file mode 100644 index 000000000..b63a618df --- /dev/null +++ b/tests/system/test_bundle_reuse.py @@ -0,0 +1,90 @@ +"""scripts/ci/bundle.py --reuse: a workload whose key the previous bundle holds is copied byte for byte +without building it, and every built one gets a key; a changed input or Inductor/Triton/PyTorchSim env, +an unpicked launch, no PTS_INPUTS or a row no longer measured is not reused; a per-run path is no input.""" +import filecmp +import importlib.util +import json +import os +import shutil +import tempfile +from unittest import mock + +TORCHSIM_DIR = os.environ.get("TORCHSIM_DIR", default="/workspace/PyTorchSim") +os.environ.setdefault("TORCHSIM_FUNCTIONAL_MODE", "0") + +spec = importlib.util.spec_from_file_location("bundle", os.path.join(TORCHSIM_DIR, "scripts", "ci", "bundle.py")) +bundle = importlib.util.module_from_spec(spec) +spec.loader.exec_module(bundle) + +NAME = "vector_slice_8x128_bf16" +INPUTS = "tree-a device-a bundle-a" +_all = bundle.workloads + + +def _one(suites=None): + return (w for w in _all(suites) if w[0] == NAME) + + +def _same(a, b): + cmp = filecmp.dircmp(a, b) + assert not (cmp.left_only or cmp.right_only or cmp.funny_files), (a, b) + _, mismatch, errors = filecmp.cmpfiles(a, b, cmp.common_files, shallow=False) + assert not mismatch and not errors, (a, b, mismatch, errors) + for d in cmp.common_dirs: + _same(os.path.join(a, d), os.path.join(b, d)) + + +def _run(root, prev=None, inputs=INPUTS, extra=None): + """main() into root/out and root/keys, with env `extra` set: the workloads it built.""" + built, real = [], bundle.build + + def build(out, suite, name, keys=None): + built.append(name) + return real(out, suite, name, keys) + env = dict({"PTS_INPUTS": inputs} if inputs else {}, **(extra or {})) + with mock.patch.dict(os.environ, env), mock.patch.object(bundle, "workloads", _one), \ + mock.patch.object(bundle, "build", build): + if not inputs: + os.environ.pop("PTS_INPUTS", None) + bundle.main(os.path.join(root, "out"), {"vector"}, 1, prev=prev) + return built + + +def test_reuse(): + with tempfile.TemporaryDirectory() as tmp: + a, b, c, d, e = (os.path.join(tmp, x) for x in "abcde") + assert _run(a) == [NAME] + with open(os.path.join(a, "keys", f"{NAME}.json")) as f: + key = json.load(f) + assert key["inputs"]["pts"] == INPUTS.split() and bundle.select.HEURISTIC not in key["tile_sources"] + + shutil.copytree(os.path.join(a, "out", NAME), os.path.join(a, "out", "vector_dropped_1x1_bf16")) + shutil.copy(os.path.join(a, "keys", f"{NAME}.json"), os.path.join(a, "keys", "vector_dropped_1x1_bf16.json")) + assert _run(b, prev=a) == [] + _same(os.path.join(a, "out", NAME), os.path.join(b, "out", NAME)) + assert not os.path.exists(os.path.join(b, "out", "vector_dropped_1x1_bf16")) + with open(os.path.join(b, "keys", f"{NAME}.json")) as f: + assert json.load(f)["key"] == key["key"] + + assert _run(c, prev=a, inputs="tree-b device-a bundle-a") == [NAME] + _same(os.path.join(a, "out", NAME), os.path.join(c, "out", NAME)) + + x, y = os.path.join(tmp, "x"), os.path.join(tmp, "y") + assert _run(x, prev=a, extra={"TORCHINDUCTOR_PERSISTENT_REDUCTIONS": "0"}) == [NAME] + assert _run(y, prev=a, extra={"TORCHSIM_DUMP_PATH": os.path.join(tmp, "dump"), + "TORCHSIM_LOG_PATH": os.path.join(tmp, "log"), + "TRITON_CACHE_DIR": os.path.join(tmp, "triton")}) == [] + + shutil.copytree(a, d) + with open(os.path.join(d, "keys", f"{NAME}.json"), "w") as f: + json.dump(dict(key, tile_sources=[bundle.select.HEURISTIC]), f) + assert _run(e, prev=d) == [NAME] + + shutil.rmtree(e) + assert _run(e, prev=a, inputs=None) == [NAME] + assert not os.path.exists(os.path.join(e, "keys", f"{NAME}.json")) + + +if __name__ == "__main__": + test_reuse() + print("PASS")