This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/scripts/sycl/profile_decode.sh
T
claudeandClaude Opus 5.5 bce0f4db70 libxe2: the DFlash2 path fast -- exact draft head, DPAS verify GEMV, parallel rerank
- gemm_nt_q over the zero-point grids at M <= 16 (the drafter's 2-bit vocabulary head, N=248320):
  a sub-group a column, the group sums exact integers in f32, libref's group terms added in group
  order through lane broadcasts -- bit-identical to the exact kernel on the live head (checked in
  the engine: 0 differing bytes of 3.5 MB, every round). 252 ms -> well under 1 ms a call.
- m2xfp4 at 2 <= M <= 16 (the verify width) on XMX: a lane a column decodes its codes a 64-byte line
  at a time into its sub-group's VNNI slice of local memory (subnormal-bit fp16 pairs times
  (1 + k/4) * 2^(e - e_max + 14)), eight K16 DPAS a step against the permuted fp16 activation,
  K split for narrow N, partials added in order. On the vector ALUs M = 8 cost five times M = 1;
  gate_up at M = 8 1159 -> ~490 us. rad-kbench on the 27B: 50/50, rel_l2 ~8.5e-4 (tol 4e-2).
- logit_rerank: a work-group a row, a sub-group a candidate along K, libref's double sum as a float
  pair (two-product, two-sum, a fixed lane tree), libref's selection; 136 ms -> negligible a call.
- the gated delta net's gate, beta and decay (libref's double exp / log1p) once a (token, head)
  in a prepass instead of once a column block; still bit-identical (10/10 at rel_l2 0).
- profile_decode.sh: KEEP=DIR keeps the per-geometry tables.

27B on the B65, greedy: 12.1 tok/s plain, 13.2 tok/s with the drafter (device time a token
217 -> 76 ms under speculation). The drafter's text now departs from plain decoding at a
near-tie (byte 246 of 256 tokens): the verify forward runs the M = 8 DPAS path and plain decoding
the M = 1 GEMV, whose roundings differ (~1e-3); with the exact kernels the two were identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
2026-10-24 04:37:16 +02:00

61 lines
3.1 KiB
Bash
Executable File

#!/bin/sh
# profile_decode.sh -- per-op device time of decode steps alone, on the SYCL backend.
#
# --profile-ops reports every op over a whole run, so a prompt's prefill and the decode steps after
# it are mixed. This runs the same request twice in two fresh servers -- one generating 1 token, one
# generating 1 + STEPS -- and prints the difference per op type, divided by STEPS: the device time a
# decode step spends in each op at the prompt's context length. The numbers carry --profile-ops'
# synchronisations, so compare them with each other, not with unprofiled tok/s.
#
# Usage: scripts/sycl/profile_decode.sh MODEL PROMPT_FILE [STEPS] [extra radiance flags...]
# PROMPT_FILE plain text, sent as one /v1/completions prompt
# STEPS decode steps measured (default 128)
# Needs the oneAPI environment (it sources setvars.sh if icpx is not on PATH) and build-sycl/.
# KEEP=DIR keeps the two servers' logs (the per-geometry tables) in DIR.
set -eu
model=${1:?usage: profile_decode.sh MODEL PROMPT_FILE [STEPS] [flags...]}
prompt=${2:?usage: profile_decode.sh MODEL PROMPT_FILE [STEPS] [flags...]}
steps=${3:-128}
[ $# -ge 3 ] && shift 3 || shift $#
root=$(cd "$(dirname "$0")/../.." && pwd)
if ! command -v icpx >/dev/null; then set +u; . /opt/intel/oneapi/setvars.sh >/dev/null; set -u; fi
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
port=${PORT:-8139}
run() { # run TOKENS FLAGS... -> $work/TOKENS.tsv: op, total ms, calls
tok=$1; shift
RADIANCE_SYCL_TIMING=1 RADIANCE_HOME="$root/build-sycl/radiance_home" \
"$root/build-sycl/bin/radiance" --model "$model" --profile-ops --max-num-seqs 1 \
--host 127.0.0.1 --port "$port" "$@" > "$work/$tok.log" 2>&1 &
pid=$!
i=0
until grep -q 'server: listening' "$work/$tok.log"; do
i=$((i + 1)); [ $i -lt 600 ] || { echo "the server did not start" >&2; kill $pid; exit 1; }
kill -0 $pid 2>/dev/null || { tail -5 "$work/$tok.log" >&2; exit 1; }
sleep 1
done
python3 -I -c 'import json,sys; print(json.dumps({"prompt": open(sys.argv[1]).read(),
"max_tokens": int(sys.argv[2]), "temperature": 0}))' "$prompt" "$tok" > "$work/req.json"
curl -sf -m 3600 "http://127.0.0.1:$port/v1/completions" -H 'Content-Type: application/json' \
-d @"$work/req.json" > /dev/null
kill -INT $pid
wait $pid 2>/dev/null || true
n=$(grep -n -E 'calls +total ms' "$work/$tok.log" | tail -1 | cut -d: -f1)
awk -v from="$n" 'NR > from && $4 == "dev" { t[$7] += $2; c[$7] += $1 }
END { for (o in t) print o, t[o], c[o] }' \
"$work/$tok.log" | sort > "$work/$tok.tsv"
}
run 1 "$@"
run $((steps + 1)) "$@"
[ -n "${KEEP:-}" ] && cp "$work"/*.log "$KEEP"/
join "$work/1.tsv" "$work/$((steps + 1)).tsv" | awk -v n="$steps" '
{ d = $4 - $2; T += d; a[$1] = d; k[$1] = ($5 - $3) / n }
END {
for (o in a)
printf "%8.3f ms/step %5.1f%% %5.1f calls/step %7.1f us/call %s\n", a[o] / n,
100 * a[o] / T, k[o], (k[o] > 0 ? 1000 * a[o] / n / k[o] : 0), o
printf "%8.3f ms/step of device time over %d decode steps\n", T / n, n
}' | sort -rn