Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .claude/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ python tests/system/test_eager.py # eager-fallback registration

Run a model from `tests/models/Llama/`, `tests/models/DeepSeek/`, etc. similarly.

**CI coverage:** `.github/workflows/docker-image.yml` is the PR gate. It builds the base image FROM the compiler's own published image at the pinned commit (`ghcr.io/psal-postech/pytorchsim-triton-backend:<ref>`, one tag per commit from PyTorchSim-Triton-Backend's `images.yml`: Ubuntu 22.04 + python3.11, the vcix-accelerator environment with the RISC-V toolchain, pk, Spike and gem5, LLVM, Triton with the torchsim backend, the compiler and its extension) plus PyTorch and the test stack (`docker/Dockerfile.base`, rebuilt only when `scripts/ci/third_party_base_pin.sh` changes), then the app image, and calls `.github/workflows/pytorchsim_test.yml` once per hardware config. That workflow is a **matrix over `scripts/ci/triton_route_passing.txt`**, one Docker container per test -- so adding a test file gates PRs only once it is in that allowlist. Regenerate the allowlist with `python scripts/ci/triton_route_sweep.py --all --update-allowlist` and mirror it into the workflow.
**CI coverage:** `.github/workflows/docker-image.yml` is the PR gate. It builds the base image FROM the compiler's own published image at the pinned commit (`ghcr.io/psal-postech/pytorchsim-triton-backend:<ref>`, one tag per commit from PyTorchSim-Triton-Backend's `images.yml`: Ubuntu 22.04 + python3.11, the vcix-accelerator environment with the RISC-V toolchain, pk, Spike and gem5, LLVM, Triton with the torchsim backend, the compiler and its extension) plus PyTorch and the test stack (`docker/Dockerfile.base`, rebuilt only when `scripts/ci/third_party_base_pin.sh` changes), then the app image, and calls `.github/workflows/pytorchsim_test.yml` once per hardware config. That workflow is a matrix of test files **mirrored by hand from `scripts/ci/triton_route_passing.txt`**, one Docker container per test file, and not identical to it (a file the allowlist runs as several entries, Gemma's `--preset`, runs once without arguments; `test_compiler_failure`, `test_reduction_tiling` and `test_select`, and `test_patch_scope`, `test_togsim_exit` and `test_togsim_result`, which emit no kernel, run there but are not on the allowlist) -- so adding a test file gates PRs only once it is in that matrix. Regenerate the allowlist with `python scripts/ci/triton_route_sweep.py --all --update-allowlist` and mirror its files into the workflow.

`.github/workflows/pytorchsim_triton_backend.yml` runs when the compiler pin itself moves: the compiler's own smoke kernels end to end, plus the full coverage sweep (allowlist *and* the rest, reported not gated). Neither workflow needs a token: the compiler's package grants this repository read access, and the default Actions token pulls it. Nothing of the compiler, Triton, Spike or gem5 is built in this repository's CI.
`.github/workflows/pytorchsim_triton_backend.yml` runs when the compiler pin itself moves: the compiler's own smoke kernels end to end, plus the full coverage sweep (allowlist *and* the rest, all reported; an allowlisted test that fails, or stops emitting a kernel, fails the job, the rest do not). Neither workflow needs a token: the compiler's package grants this repository read access, and the default Actions token pulls it. Nothing of the compiler, Triton, Spike or gem5 is built in this repository's CI.

**For fast iteration** (skip functional check):
```bash
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/pytorchsim_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ on:
default: "tpuv6e"
type: string

# The list below IS scripts/ci/triton_route_passing.txt, one container per test.
# Regenerate that file with
# The list below is mirrored by hand from scripts/ci/triton_route_passing.txt, one container per
# test file, and is not identical to it: a file the allowlist runs as several entries (Gemma's
# --preset) runs here once without arguments, which runs the same presets in one process, and
# tests/system tests the allowlist leaves out run here too: test_compiler_failure,
# test_reduction_tiling and test_select, and test_patch_scope, test_togsim_exit and
# test_togsim_result, which emit no kernel and so are no route coverage.
# Regenerate the allowlist with
# python scripts/ci/triton_route_sweep.py --all --update-allowlist
# and mirror it here; a test absent from both is not gated anywhere.
# and mirror its files here; a test absent from both is not gated anywhere.
#
# Runner policy: every job is self-hosted. The image carries the PyTorchSim-Triton-Backend
# toolchain layer (~1.8 GiB on top of the base), which is more than a
Expand Down
25 changes: 15 additions & 10 deletions .github/workflows/pytorchsim_triton_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ name: Triton codegen route (PyTorchSim-Triton-Backend)
# Exercises the Triton codegen route: Inductor's own Triton backend produces the
# kernel and PyTorchSim-Triton-Backend lowers it to a RISC-V ELF.
#
# Separate from the main CI on purpose: it runs when the compiler pin moves, and
# its sweep reports rather than gates.
# Separate from the main CI on purpose: it runs when the compiler pin moves. Its sweep runs every
# test and reports them all; only a test on the allowlist (scripts/ci/triton_route_passing.txt)
# that fails fails the job.
#
# The base job makes sure of the base image; the route job (smoke + sweep) and the bundle job
# (the validation kernels for the compiler) then run beside each other in it. The base image is
# the compiler's published image at the pin plus the test stack (docker/Dockerfile.base); the
# compiler's package grants this repository read access, so the workflow's own token pulls it. The
# commit under test is not baked into an image: the checkout is mounted read-only and its device
# extension built in the container. What fails the route: no compiler image, the base build or its
# pull, the smoke kernels, the device extension, the job's time limit.
# pull, the smoke kernels, the device extension, an allowlisted test that fails (or a sweep that
# breaks), the job's time limit.

on:
push:
Expand Down Expand Up @@ -172,10 +174,12 @@ jobs:
python3 /src/scripts/ci/triton_route_previous.py "${GITHUB_REPOSITORY}" /out/results.json

# Runs whether or not the smoke kernels held. Reports every test, allowlist
# included; each failure leaves its kernel and stage IR behind. A device
# extension that does not build fails the step, a sweep result does not. A test on the
# allowlist gets twice the time: the slowest one runs within seconds of 900.
- name: Device extension + full sweep (the sweep reports)
# included; each failure leaves its kernel and stage IR behind. The step fails when the device
# extension does not build, or when the sweep exits nonzero: an allowlisted test failed, or the
# sweep broke. A test off the allowlist only reports. The report and the artifacts are written
# first either way. A test on the allowlist gets twice the time: the slowest one runs within
# seconds of 900.
- name: Device extension + full sweep (the allowlist gates)
if: ${{ !cancelled() && steps.pull.outcome == 'success' }}
env:
SWEEP_JOBS: ${{ inputs.sweep_jobs }}
Expand All @@ -196,14 +200,15 @@ jobs:
exit 1
fi
rm -f sweep/device-built
if [ "$rc" -ne 0 ]; then
echo "::warning::the sweep container exited $rc"
fi
if [ -f sweep/coverage.md ]; then
cat sweep/coverage.md >> "$GITHUB_STEP_SUMMARY"
else
echo "::warning::the sweep wrote no report"
fi
if [ "$rc" -ne 0 ]; then
echo "::error::the sweep exited $rc: an allowlisted test regressed (REGRESSION in the log and the summary), or the sweep itself broke"
exit "$rc"
fi

- uses: actions/upload-artifact@v4
if: always()
Expand Down
6 changes: 4 additions & 2 deletions scripts/ci/triton_route_in_container.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
# What the Triton route runs inside the base image: copies the checkout mounted read-only at /src
# to $TORCHSIM_DIR, builds the device extension as docker/Dockerfile does, then runs the sweep with
# the arguments given. Only the build can fail it; the sweep reports. $SWEEP_OUT/device-built says the build held.
# the arguments given. It exits with the sweep's status: nonzero when an allowlisted test regressed
# (a test off the allowlist only reports) or the sweep broke. $SWEEP_OUT/device-built says the build held.
set -euo pipefail
SRC="${SRC:-/src}"
DEST="${TORCHSIM_DIR:-/workspace/PyTorchSim}"
Expand All @@ -16,5 +17,6 @@ cd "$DEST"
rc=0
python3 scripts/ci/triton_route_sweep.py "$@" || rc=$?
if [ "$rc" -ne 0 ]; then
echo "::warning::the sweep exited $rc: an allowlisted test regressed, or the sweep itself broke (see its report)"
echo "the sweep exited $rc: an allowlisted test regressed, or the sweep itself broke (see its report)" >&2
fi
exit "$rc"
7 changes: 2 additions & 5 deletions scripts/ci/triton_route_passing.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Tests that pass THROUGH the Triton codegen route.
# Gated by scripts/ci/triton_route_sweep.py; regenerate with
# Tests that pass THROUGH the Triton codegen route. One that fails, or stops emitting a kernel, in
# the route job's sweep (pytorchsim_triton_backend.yml) fails that job; a test off this list only reports. Regenerate with
# python scripts/ci/triton_route_sweep.py --all --update-allowlist
# A test that passes without emitting a kernel is deliberately absent.
# WHAT WAS BLOCKED HERE AND IS NOT. tests/models/test_swinv2.py stopped after
Expand Down Expand Up @@ -276,6 +276,3 @@ 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
tests/system/test_togsim_result.py
38 changes: 28 additions & 10 deletions scripts/ci/triton_route_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
stage, and per-failure artifacts for reporting upstream.

python scripts/ci/triton_route_sweep.py # the allowlist, gating
python scripts/ci/triton_route_sweep.py --all # every test, reports
python scripts/ci/triton_route_sweep.py --all # every test and allowlist entry; still gates
python scripts/ci/triton_route_sweep.py --all --artifacts triton-failures
python scripts/ci/triton_route_sweep.py --all --order-from results.json

Expand Down Expand Up @@ -81,6 +81,18 @@ def discover(allow):
return sorted(out)


def regressions(results, allow):
"""The allowlisted results that fail the gate: failed, or passed without emitting a kernel,
which is no longer passing through the route."""
return [r for r in results if r["test"] in allow and not (r["ok"] and r["exercised"])]


def _why(r):
"""Why a regressed result fails the gate, for the report."""
return f"**{r['stage']}** [{r['bucket']}]" if not r["ok"] else \
"**passed without emitting a kernel** [route not exercised]"


def _slug(entry):
"""A directory name for an entry."""
return re.sub(r"[^\w.-]+", "_", entry.removesuffix(".py"))
Expand Down Expand Up @@ -221,8 +233,9 @@ def run_one(test, timeout, artifacts, scratch):
return r


def write_markdown(results, path):
"""The report a human reads: counts by cause, then every failure."""
def write_markdown(results, path, regressed=()):
"""The report a human reads: the allowlisted tests that regressed (what fails the job), counts
by cause, then every failure."""
passed = [r for r in results if r["ok"]]
failed = [r for r in results if not r["ok"]]
by = {}
Expand All @@ -234,6 +247,9 @@ def write_markdown(results, path):
f"**{len(real)}/{len(results)} pass through the Triton route.** "
f"({len(passed)-len(real)} more pass without exercising it -- CPU-only, "
f"eager fallback, or a path that bypasses Inductor.)", ""]
if regressed:
L += [f"## REGRESSION: {len(regressed)} allowlisted test(s) failed or left the route", ""]
L += [f"- `{r['test']}` — {_why(r)}" for r in regressed] + [""]
if failed:
L += ["| cause | count | owner |", "|---|---|---|"]
OWNER = {
Expand Down Expand Up @@ -301,7 +317,7 @@ def main():
args = ap.parse_args()

allow = load_allowlist()
tests = discover(allow) if args.all else allow
tests = sorted(set(discover(allow)) | set(allow)) if args.all else allow
if not tests:
print("no tests selected; the allowlist is empty and --all was not given")
return 1
Expand Down Expand Up @@ -350,6 +366,7 @@ def report(r):
passed = [r for r in results if r["ok"]]
failed = [r for r in results if not r["ok"]]
real = [r for r in passed if r["exercised"]]
regressed = regressions(results, allow)

print(f"\n{'='*72}\npassed {len(passed)}/{len(results)}"
f" ({len(real)} through the Triton route, "
Expand All @@ -373,27 +390,28 @@ def report(r):
json.dump(results, f, indent=2)
print(f"\nwrote {args.json}")
if args.markdown:
write_markdown(results, args.markdown)
write_markdown(results, args.markdown, regressed)
print(f"wrote {args.markdown}")
if args.artifacts and failed:
print(f"wrote {args.artifacts}/ ({len(failed)} failure dirs)")

if args.update_allowlist:
with open(PASSING, "w") as f:
f.write("# Tests that pass through the Triton codegen route.\n"
"# Gated by scripts/ci/triton_route_sweep.py; regenerate with\n"
f.write("# Tests that pass THROUGH the Triton codegen route. One that fails, or stops "
"emitting a kernel, in\n# the route job's sweep (pytorchsim_triton_backend.yml) fails that job; a test "
"off this list only reports. Regenerate with\n"
"# python scripts/ci/triton_route_sweep.py --all "
"--update-allowlist\n")
for r in real:
f.write(r["test"] + "\n")
print(f"wrote {PASSING} ({len(real)} tests)")
return 0

regressed = [r for r in failed if r["test"] in allow]
if regressed:
print(f"\nREGRESSION: {len(regressed)} allowlisted test(s) failed")
print(f"\nREGRESSION: {len(regressed)} allowlisted test(s) failed or left the route")
for r in regressed:
print(f" {r['test']} [{r['bucket']}] {r['error']}")
print(f" {r['test']} " + (f"[{r['bucket']}] {r['error']}" if not r["ok"]
else "passed without emitting a kernel"))
return 1
return 0

Expand Down