Archived
scripts: stampgaps.py -- RADIANCE_AQL_STAMP's CSV per kind of pass: wall, busy union, idle share, gaps before ordered starts
The stamps are one line a dispatch; what they are taken for is a pass's idle time and the gaps a barrier leaves, which need the union over the queues and the kinds of pass told apart. Standard library only, beside cardclock.py and statsdump.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
09f80b8b1e
commit
ca713b4732
3 files changed
+161
-3
No files matched your search
+1
-1
@@ -3489,7 +3489,7 @@ The four slots are what the amdgpu kernel driver leaves to user queues. It keeps
|
||||
| `RADIANCE_CALIB_TOKENS` | with `RADIANCE_CALIB_DIR`, the tokens the calibration tap accumulates before it writes and switches itself off (default 65536) |
|
||||
| `RADIANCE_G3_CALIB_LAYERS` | `lo:hi`: `arch/gemma3`'s calibration tap over layers lo to hi - 1 only, to take a large model's Grams in passes (docs/ARCHITECTURES.md) |
|
||||
| `RADIANCE_PROFILE_EVERY` | with `--profile-ops`, dump the per-op table every N steps (default 32) |
|
||||
| `RADIANCE_AQL_STAMP`, `RADIANCE_AQL_STAMP_OUT` | `N`: every dispatch of one recorded pass in N on card 0 gets a completion signal of its own, which carries its start and end; the barrier bits and chains stay as unstamped, unlike `--profile-ops`, which plays no recorded pass. One CSV line a dispatch (pass, record, queue, kernel, whether it waited for the one before, whether it was chained, start and end in ns) is appended to `RADIANCE_AQL_STAMP_OUT` (default `/tmp/radiance-stamps-<pid>.csv`) once the card is done with it. AQL backend only |
|
||||
| `RADIANCE_AQL_STAMP`, `RADIANCE_AQL_STAMP_OUT` | `N`: every dispatch of one recorded pass in N on card 0 gets a completion signal of its own, which carries its start and end; the barrier bits and chains stay as unstamped, unlike `--profile-ops`, which plays no recorded pass. One CSV line a dispatch (pass, record, queue, kernel, whether it waited for the one before, whether it was chained, start and end in ns) is appended to `RADIANCE_AQL_STAMP_OUT` (default `/tmp/radiance-stamps-<pid>.csv`) once the card is done with it; `scripts/stampgaps.py` reads it per kind of pass (idle share, gaps before ordered starts, kernels by time). AQL backend only |
|
||||
| `RADIANCE_LOG_STEPS` | log one line per step: its phase, sequences, and each one's token count and context (§4.5) |
|
||||
|
||||
Engine development has its own instruments: `RADIANCE_DEBUG_*` (residual probes, routing and issue
|
||||
|
||||
+3
-2
@@ -10,8 +10,8 @@ checkout the script is in, and default to containers under `$HOME/models/rad/` a
|
||||
`$HOME/models/<org>/<name>`. A script that starts a server first stops any `radiance` already
|
||||
running (`oracle.sh` only the one on its own port) and logs to `$HOME/<script>.log`. Most defaults
|
||||
are environment overrides (`M=` for the container, `P=` for the port, and so on); each script's
|
||||
header lists its own. Scripts that only attach to a live server need `curl` and `jq`; `cardclock.py`
|
||||
and `agentreplay.py` need `python3`. Scripts find each other through `$(dirname "$0")`.
|
||||
header lists its own. Scripts that only attach to a live server need `curl` and `jq`; `cardclock.py`,
|
||||
`agentreplay.py` and `stampgaps.py` need `python3`. Scripts find each other through `$(dirname "$0")`.
|
||||
|
||||
## Bringing a model up
|
||||
|
||||
@@ -40,6 +40,7 @@ and `agentreplay.py` need `python3`. Scripts find each other through `$(dirname
|
||||
| `ident.sh` | Run-to-run reproducibility at a fixed configuration: one hash per (temperature, question), to compare against another run of the same configuration. A speculative run need not match a non-speculative one byte for byte (the split-K count is chosen from M, so reduction orders differ and a near-tie can flip late in a long answer), but a divergence within the first sentence or two is a defect. |
|
||||
| `cardclock.py` | What holds each card's clock under sustained load, and which card a tensor-parallel step waits for (the slowest rank ends the step). Reads every AMD card's `gpu_metrics` table ten times a second and counts a throttler bit only when the clock is lower while it is set (some firmware keeps a bit on at idle). Shows the engine's step counters per window, so a slow window is attributed to slower steps, fewer tokens per step or host time between steps. Drives its own greedy load, or with `--watch` only samples a server under real traffic; `--compare` shows two saved runs side by side. Read-only on the cards. |
|
||||
| `statsdump.py` | Records `/stats` to a JSONL file, one row per poll (`--every`, default 1 s), so the dashboard's figures can be read back over time on a machine without a Prometheus scraper. A row is the engine's snapshot verbatim plus the poll's time `t` and the gap since the last good poll `dt_s`; nothing is derived. The file is appended to and rotated at `--max-mib` (default 256, five generations). A failed poll leaves no row; a run that wrote no row, or can no longer write its file, exits 1. The key is taken from `--api-key` or `RADIANCE_API_KEY`. |
|
||||
| `stampgaps.py` | Reads the CSV that `RADIANCE_AQL_STAMP=N` writes (every dispatch of one recorded pass in N on card 0, start and end) and prints per kind of pass (told apart by tape length) the median wall, the busy time as the union over the queues, the idle share, the gap before an ordered start (p50, p90, sum) and the kernels by share of the dispatch time. The idle share is what chained launches could win at most, the gaps what they would remove. Stamping costs throughput of its own when passes are short (one in 50: 0.3 % at one GLM-5.3 stream, 4 % at eight), so take N larger at high concurrency. |
|
||||
| `oracle.sh` | Every op compared against libref on the operands the model issued, which rad-kbench cannot do: its operands are its own (dense, rank 2), while the engine's are arena slices and weights loaded from a file. Starts its own server on :8302. Read it for `MISMATCH` lines, and for `NOT CHECKED` lines naming rows whose weight layout has no published inverse and so cannot be compared. |
|
||||
|
||||
## Regression checks against a live server
|
||||
|
||||
Executable
+157
@@ -0,0 +1,157 @@
|
||||
#!/usr/bin/env python3
|
||||
# stampgaps.py -- where a recorded pass leaves the card idle, from RADIANCE_AQL_STAMP's CSV.
|
||||
#
|
||||
# RADIANCE_AQL_STAMP=50 RADIANCE_AQL_STAMP_OUT=/tmp/st.csv build/radiance ... (drive a load)
|
||||
# scripts/stampgaps.py /tmp/st.csv [label] [--top 12]
|
||||
#
|
||||
# The engine writes one line a dispatch of every Nth pass on card 0: pass, seq (its record),
|
||||
# queue, kernel, ordered (the packet waited for the one before it on its queue), chained, start_ns,
|
||||
# end_ns, play, records. A pass is the plays of one tape from its record 0; its tape length
|
||||
# (`records`) tells kinds of pass apart (draft, verify, each prefill size), so every figure is per
|
||||
# kind, the median over that kind's passes.
|
||||
#
|
||||
# Per pass: the wall (first start to last end), the busy time as the union of every queue's
|
||||
# intervals (two queues running at once count once), the idle share (wall minus busy over wall),
|
||||
# the overlap between queues (the sum of per-queue busy times minus the union), and the gap before
|
||||
# each ordered start (its start minus the latest end of the earlier dispatches on its queue). The
|
||||
# gaps are what a chained form would save; the idle share is the most it could. Over several
|
||||
# queues a gap also holds the time its queue waited for another one (a second lane's dispatch
|
||||
# waits for its join), so there the summed gaps overstate and the p50 and the idle share are the
|
||||
# figures to read. Per kernel name: its share of the summed dispatch time.
|
||||
#
|
||||
# A pass with fewer lines than the longest of its kind (the stamp's signal pool ran out mid-pass)
|
||||
# or with a line without times is left out and counted. The stamping costs throughput of its own
|
||||
# (on GLM-5.3 at TP8, one pass in 50: 0.3 % at one stream, 4 % at eight), so take N larger where
|
||||
# many streams make the passes short. Standard library only.
|
||||
import csv
|
||||
import statistics
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def union(iv):
|
||||
"""The length of the union of half-open intervals [a, b)."""
|
||||
tot, cur_a, cur_b = 0, None, None
|
||||
for a, b in sorted(iv):
|
||||
if cur_b is None or a > cur_b:
|
||||
if cur_b is not None:
|
||||
tot += cur_b - cur_a
|
||||
cur_a, cur_b = a, b
|
||||
elif b > cur_b:
|
||||
cur_b = b
|
||||
if cur_b is not None:
|
||||
tot += cur_b - cur_a
|
||||
return tot
|
||||
|
||||
|
||||
def pct(v, p):
|
||||
if not v:
|
||||
return 0.0
|
||||
v = sorted(v)
|
||||
k = (len(v) - 1) * p
|
||||
lo = int(k)
|
||||
hi = min(lo + 1, len(v) - 1)
|
||||
return v[lo] + (v[hi] - v[lo]) * (k - lo)
|
||||
|
||||
|
||||
def read(path):
|
||||
passes = defaultdict(list)
|
||||
with open(path, newline="") as f:
|
||||
for r in csv.DictReader(f):
|
||||
passes[int(r["pass"])].append(r)
|
||||
return passes
|
||||
|
||||
|
||||
def analyse(rows):
|
||||
"""One pass's figures; None when a line has no times."""
|
||||
if any(not r["start_ns"] or not r["end_ns"] for r in rows):
|
||||
return None
|
||||
rows = sorted(rows, key=lambda r: int(r["seq"]))
|
||||
iv = [(int(r["start_ns"]), int(r["end_ns"])) for r in rows]
|
||||
t0 = min(a for a, _ in iv)
|
||||
wall = max(b for _, b in iv) - t0
|
||||
busy = union(iv)
|
||||
per_q = defaultdict(list)
|
||||
for r, x in zip(rows, iv):
|
||||
per_q[r["queue"]].append(x)
|
||||
busy_q = {q: union(v) for q, v in per_q.items()}
|
||||
gaps = []
|
||||
last_end = {}
|
||||
for r, (a, b) in zip(rows, iv):
|
||||
q = r["queue"]
|
||||
if r["ordered"] == "1" and q in last_end:
|
||||
gaps.append(max(0, a - last_end[q]))
|
||||
last_end[q] = max(last_end.get(q, 0), b)
|
||||
kern = defaultdict(int)
|
||||
for r, (a, b) in zip(rows, iv):
|
||||
kern[r["kernel"]] += b - a
|
||||
return {
|
||||
"n": len(rows),
|
||||
"ordered": sum(r["ordered"] == "1" for r in rows),
|
||||
"chained": sum(r["chained"] == "1" for r in rows),
|
||||
"plays": len({r["play"] for r in rows}),
|
||||
"queues": len(per_q),
|
||||
"wall": wall,
|
||||
"busy": busy,
|
||||
"idle": wall - busy,
|
||||
"overlap": sum(busy_q.values()) - busy,
|
||||
"gaps": gaps,
|
||||
"kern": kern,
|
||||
"dev": sum(b - a for a, b in iv),
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
top = 12
|
||||
if "--top" in args:
|
||||
i = args.index("--top")
|
||||
top = int(args[i + 1])
|
||||
del args[i:i + 2]
|
||||
if not args:
|
||||
sys.exit("usage: stampgaps.py CSV [label] [--top K]")
|
||||
path = args[0]
|
||||
label = args[1] if len(args) > 1 else path
|
||||
passes = read(path)
|
||||
by_kind = defaultdict(list)
|
||||
for p, rows in sorted(passes.items()):
|
||||
by_kind[int(rows[0]["records"])].append(rows)
|
||||
print(f"{label}: {len(passes)} stamped passes in {path}\n")
|
||||
for kind, ps in sorted(by_kind.items(), key=lambda kv: -len(kv[1])):
|
||||
full = max(len(rows) for rows in ps)
|
||||
res = [a for a in (analyse(rows) if len(rows) == full else None for rows in ps) if a]
|
||||
dropped = len(ps) - len(res)
|
||||
print(f"pass of {kind} records")
|
||||
if not res:
|
||||
print(f" no complete pass ({dropped} incomplete)\n")
|
||||
continue
|
||||
med = lambda k: statistics.median(a[k] for a in res)
|
||||
ms = lambda ns: ns / 1e6
|
||||
gap50 = statistics.median(pct(a["gaps"], 0.5) for a in res)
|
||||
gap90 = statistics.median(pct(a["gaps"], 0.9) for a in res)
|
||||
gapsum = statistics.median(sum(a["gaps"]) for a in res)
|
||||
idle = statistics.median(a["idle"] / a["wall"] for a in res if a["wall"] > 0)
|
||||
print(f" passes complete / incomplete {len(res)} / {dropped}")
|
||||
print(f" dispatches a pass {med('n'):.0f}")
|
||||
print(f" ordered / chained {med('ordered'):.0f} / {med('chained'):.0f}")
|
||||
print(f" plays / queues {med('plays'):.0f} / {med('queues'):.0f}")
|
||||
print(f" wall ms {ms(med('wall')):.3f}")
|
||||
print(f" busy ms (union) {ms(med('busy')):.3f}")
|
||||
print(f" idle ms / share {ms(med('idle')):.3f} / {100 * idle:.1f} %")
|
||||
print(f" overlap between queues ms {ms(med('overlap')):.3f}")
|
||||
print(f" summed dispatch time ms {ms(med('dev')):.3f}")
|
||||
print(f" gap before an ordered start us p50 {gap50 / 1e3:.2f} p90 {gap90 / 1e3:.2f}")
|
||||
print(f" summed gaps ms {ms(gapsum):.3f}")
|
||||
kern = defaultdict(int)
|
||||
dev = sum(a["dev"] for a in res)
|
||||
for a in res:
|
||||
for k, v in a["kern"].items():
|
||||
kern[k] += v
|
||||
print(f" top {top} kernels (share of dispatch time, ms a pass)")
|
||||
for k, v in sorted(kern.items(), key=lambda kv: -kv[1])[:top]:
|
||||
print(f" {100 * v / dev:5.1f} % {ms(v / len(res)):8.3f} {k}")
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user