Repository navigation
[Benchmark] Built-in profiler and a report that explains slow cards - #285
Open
okada-shogo wants to merge 3 commits into
Open
okada-shogo wants to merge 3 commits into
okada-shogo wants to merge 3 commits into
Conversation
okada-shogo
marked this pull request as ready for review
November 24, 2026 01:02
…ench-report The engine records an event on its stream each time the work changes family (attention, KV store, dense products, norms, routing, experts on the GPU, copies) or waits (expert uploads, CPU experts, host gaps), with the kernel launches in each, and adds the times up by prompt and decode and by context length. A prompt's calls are all split; one decode token in STRATA_PROFILE_EVERY (16) is launched kernel by kernel to split it, the others record start and end only. A window's tokens count as keep() keeps them. Off by default: no event is recorded and the launches are as before. Launches: a replay adds its recording's kernel nodes; on Linux the engine's direct launches are counted through the runtime's launch call wrapped at link time (launch_count.cpp). STRATA_PROFILE=1 in normal use writes the session's profile after every request (STRATA_PROFILE_OUT). --bench-report FILE [--long] probes H2D/D2H, GPU memory, RAM and the CPU experts' dot kernel, then reads prompts of 302, 2,048 and 8,192 tokens of a fixed synthetic English text (--bench-text, terminal/tools/bench_text.py) with 128 answered after each, with the settings' guesses and again a token a call (and with --long one conversation in chunks to 8K..128K), and writes FILE.json and FILE.md with an explain section and no paths, user or host names. The PCIe link comes from NVML (NVIDIA, any OS), SetupAPI (Windows) or sysfs (Linux), all loaded at run time; the commit from -DSTRATA_GIT_COMMIT, git or a COMMIT file. polystrata.py bench-report runs it with a model's own settings; tools/bench_reports.py compares reports per card and checks a file for private details; an issue form asks for the report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo
force-pushed
the
port/bench-report
branch
from
November 24, 2026 01:05
7658ca8 to
18763c4
Compare
…t round trips) A "## Diagnosis" section (and JSON "diagnosis") for decode and the longest prompt: a verdict for the token and for each kernel family, a roofline line (bytes at the probed read bandwidth against the time, kernels at the probed per-kernel cost), the expert cache line, and the three largest recoverable ms. - Kernel probes (bench_kernels.cu, ~1 s): an empty kernel launched and replayed, a small dependent kernel launched and replayed (the per-kernel cost the verdicts use), the same across the card, a host round trip and a small copy to the host waited for, read-only bandwidth, fp32 FMA. - A byte model per call: dense weights each visit (the router's apart), KV rows (Inkling 2; a batch reads them once per 64 queries), routed experts on the GPU and the CPU (a prompt batch counts each once a layer). - Replayed graph nodes counted apart from direct launches; host round trips (the host waiting for router scores) counted as their own category. - A warning when the expert hit rate is above 97% (the bench text keeps to the cached experts more than real chats), and polystrata.py bench-report --text docs for real text. - Unit tests: the RX 9070 XT measured under WSL2 (not launch-bound, host round trips first), a synthetic launch-bound card, a bandwidth-bound decode, and a prompt's hit rate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…setup) A read's first mark was the copies' (kCopyH2D), and nothing launches until the host has set the read up (the caches grown, staging taken back from the expert cache), so that host time was charged to "copies to the GPU": 48% of an 8K prompt on the RX 9070 XT under WSL2 (the remap stall), ~0.3 s a long read on CUDA. The read now marks host_setup right after its ProfCall, and the copies before its first launch on the three read paths. host_setup is an idle family, explained and listed among what to recover. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem and result
This PR adds an opt-in profiler (
STRATA_PROFILE=1) and a bench report (--bench-report) to strata-poly. From thereport alone, a maintainer can see why a card is slow: whether the GPU waits for expert uploads, for the CPU's experts,
or for the host. Both are off by default; with them off, no event is recorded and every launch is as before. With the
profiler on, prompt and decode speed on an RTX 2070 Super change by +0.0% and +0.1%.
Why: we can't see where speed is lost on cards and PCs we don't have, and a user's tok/s alone doesn't say what the
GPU is waiting for.
The PR has three parts:
STRATA_PROFILE=1: an event profiler. It records the GPU stream's time by kernel family (attention, KV store,dense products, norms, routing, experts on the GPU, copies), the kernel launches in each, and its waits (expert
uploads, CPU experts, host gaps).
Prompt and decode are kept apart, and every call is bucketed by its context length. In normal
strata serveuse itwrites the session's profile after every request (
strata-profile.json) and a line to the log, so real long chatsget profiled without any extra waiting.
strata-poly --bench-report FILE [--long](python polystrata.py bench-report --model <name>runs it with themodel's own settings). It runs a few seconds of probes (host-to-device copies from pinned and pageable memory,
device-to-host copies, GPU memory, RAM read on all threads, the CPU experts' dot kernel). Then it runs prompts of
302, 2,048 and 8,192 tokens of a fixed synthetic English text. Each is answered with 128 tokens using the settings'
draft guesses (
--window), and again one token per call. It writesFILE.jsonandFILE.mdwith the hardware, commit, settings, results, profile, probes, and an "Explain" section that compares eachphase to the probed limits. The files contain no paths, user or host names, serial numbers or prompts.
A "Diagnosis" section in the report, for decode and for the longest prompt:
experts or uploads, host round trips, or compute/latency;
The verdicts use extra kernel probes: launch cost, the cost of a small kernel, a host round trip, and read
bandwidth.
Profiler cost, RTX 2070 Super 8 GB, Inkling 2 Mini IQ4_NL, 2,048-token prompt + 256 generated tokens,
--window 1(no draft guesses),
STRATA_FREEZE_EXPERTS=1. Mean of 4 alternating runs; all 8 runs gave the same tokens:Time the bench report takes to run, after the model loads:
--long, one conversation to 128KEach run (tok/s)
What the diagnosis says for decode with one token per call, IQ4_NL:
RX 9070 XT, Windows 11 against WSL2 on the same PC
IQ4_NL,
--vram-reserve-mib 700,--threads 11.In the profiled (kernel-by-kernel) calls, the routing family (the host waiting for the router's scores) takes
10.9 ms against 5.3.
24 ms token, and the report does not call it launch-bound. For comparison, a host round trip costs 5 µs on the
RTX 2070 Super (native Linux).
Reports from four cards (quick tier, tok/s)
All with
--window 4 --max-context 32768 --kv q8_0and bench text v2. Decode "one token a call" is the same answerwith no draft guesses.
What the Explain sections found:
embeddings and the CPU experts' sums, a few MB. The 8K prompt also reads slower than the 2K one. The explain
section now flags an in-stream copy share over 10%.
The CPU dot kernel probes at 2.5–3.1 GB/s on 3 threads.
against 11.4 ms for a replayed graph, so on fast cards the profiled shares are kernels plus launch gaps. The explain section now says so.
for uploads. In decode, CPU experts take 10% of a token, at 25.7 GB/s against a 34.6 GB/s dot probe. With
--long,decode falls from 37.4 tok/s at 8K to 19.9 at 128K, and attention goes from 10% to 38% of a split token.
Related discussion
none yet. This needs the maintainer's view on scope, because it adds a new opt-in feature and an issue form.
Approach
family (
Engine::pmark(), profile.hpp). A family's time runs from its first launch to the next family's; the waitshave families of their own where the engine knows why it waits. The segments of a call follow each other on one
stream, so they add up to the stream's whole time, and with the gaps between calls to the wall time.
STRATA_PROFILE_EVERY(16) is split, and islaunched kernel by kernel, as the first tokens are before any CUDA graph is recorded. The other tokens record only
their start and end. No event ever goes into a CUDA graph, so the graph replays are unchanged. A window's tokens are
counted as
keep()keeps them, not as they were fed together with their draft guesses.graph is recorded. On Linux
the engine's own direct launches are counted too: the runtime's launch call is wrapped at link time
(
launch_count.cpp;cudaLaunchKernel/cudaLaunchKernelExC,hipLaunchKernel), and the wrapper counts onlywhile the profiler is on. Elsewhere only the replays are counted, and the report says so. A BLAS library's own
kernels are not counted. On the RTX 2070 Super, IQ4_NL: 803–1,123 launches a decode token, 28,168 for a 2,048-token
prompt.
Stats(the counters behindthe "CPU experts ms/token, router wait" line). Expert copies on the upload stream are timed beside the work as a
span, with their bytes.
terminal/tools/bench_text.pywrites plain English from fixed word lists and a fixed seed; thewrapper tokenizes it with the model's tokenizer (
--bench-text). Random token ids are routed unlike real text: onIQ4_NL, a 2K prompt of them ran at 535 tok/s with 6% upload waits, where real text runs at 329 tok/s with 41%. Their
answers also loop, so draft guesses gave 93 tok/s.
<path>,--modelis described by its metadata, andAPI key variables are hidden. JSON values are scrubbed one by one of the user, host, home and working folder
names.
tools/bench_reports.py --check-privacyscans a file for paths, e-mails, UUIDs, MAC/IP/PCI addresses andkeys.
tools/bench_reports.py r1.json r2.json ...builds one table per card and flags numbers under 75% of the medianof the same card's other reports.
.github/ISSUE_TEMPLATE/bench-report.ymlasks for the report.Families and what counts in each
Inkling 2 is split inside its layer head; the other families' layer heads count as attention. With
--layer-splitthe profile is the first card's.
Validation
Passed:
(a9f2b14), and the host_setup family (687eee1). After the rebase, the CUDA (75;86) and HIP (gfx1201;gfx1100)
builds, the unit tests and the settings register check pass again. On the RTX 2070 Super, 3 runs with the profiler
off and 3 with it on give the same tokens at
--window 1and--window 4. Prompt is +0.2% at both windows. Decodeis +1.1% at window 1 and +6.3% at window 4 (the draft-policy shift described under Limits). The quick tier ran with
rc=0 in 45 s.
poly_bench_report_test: profile sums, JSON, settings without paths, explain flags, a whole report scanned forinjected user and host names, and a user named like a JSON key.
python -m unittest tools/test_bench_reports.py: privacy scan, per-card table, outliers, bad fields, Markdownescaping, and the C++ test's report through the scan with
BENCH_REPORT_TEST_BIN.terminal/tools/test_bench_text.py,tools/test_settings_register.py,python tools/settings_register.py --check.recoverable ms; a synthetic card with an 8.5 µs kernel cost is called launch-bound; a bandwidth-bound decode is not
called launch-bound; a prompt counts its experts once per layer.
-DCMAKE_CUDA_ARCHITECTURES="75;86": strata-poly and test.poly_bench_report_testbuild at3081045, and the unit test passes there.
STRATA_FREEZE_EXPERTS=1: the profiler off and on give thesame tokens.
--window 4: 3 off + 3 on, 128 tokens.--window 1: 4 off + 4 on, 256 tokens. Again after the reviewfixes (24cce32), 3 off + 3 on at each window: SAME. Decode counts the kept tokens (127 for 128 generated).
--window 1and--window 4.Window 4 decode was 115.2 tok/s off and 113.2 on (−1.7%). At window 1 that box was too noisy to measure the cost
(one run at 28.9 among ~48).
--bench-reportran with rc=0 on all four cards above. The RTX 2070 Super also ran--longat a 131072 context.Every report file and the session file pass
--check-privacywith the user and host names added.STRATA_PROFILE=1under--serve: the session file is written after the request, with its log line.More checks: totals against wall time, harness comparison, Windows run, and checks of each commit
PCIe link: NVML (NVIDIA, any OS, loaded at run time), then SetupAPI (Windows, any vendor), then sysfs (Linux); the
report names the source. NVML read gen3 x16 on the RTX 2070 Super.
Totals against wall time (same runs): prompt timeline 6,226 ms against the engine's prompt time of 6,227 ms;
decode 5,192 ms against 5,192 ms.
Like for like with our end-to-end harness, the same binary with one set of flags (
--prompt-int8, w4a8, fp16 KV,default window, 32K):
The bench's prompts here are the harness's own. The harness varies about ±7% run to run with 2 rounds.
Prompt breakdown, IQ4_NL 2K, main (
--window 4 --kv q8_0): wait_upload 2,528 ms (41%), experts 2,178, attention696, dense 345, norms 345, KV 48, routing 33, host gaps 17. Our earlier nsys trace of a faster stack has the same
shape: upload idle largest, then the int8 products, then norms. Its attention is 2 ms because that stack has a
faster prompt attention kernel.
Native Windows 11 GPU run, RX 9070 XT 16 GB, IQ4_NL,
--window 4 --kv q8_0 --vram-reserve-mib 3072(1,043experts in VRAM), 3081045:
--bench-reportrc=0 and the privacy scan clean. PCIe gen5 x16 read through SetupAPI.Prompt 315 / 438 / 374 tok/s at 302 / 2K / 8K; decode one token per call 37.2 / 37.3 / 34.9 tok/s. That run showed
two probe bugs, now fixed: H2D read 32 TB/s, because the copy probes were timed by stream events that a WDDM copy
engine does not bracket (they now use the host's clock); and a memory "peak" from AMD's clock came out below the
measured rate (it is now left out).
After the launch counts (7658ca8, RTX 2070 Super, 3 off + 3 on each): same tokens at
--window 1and--window 4. Window 1: prompt 356.9 → 357.0 tok/s, decode 20.81 → 20.83. Window 4: prompt +0.1%; decode +5.6%,the draft-policy shift described under Limits.
The diagnosis (a9f2b14), RTX 2070 Super, profiler off/on, 3 runs each way:
--window 1and--window 4;RX 9070 XT, WSL2, with the number of experts in VRAM fixed (
STRATA_GPU_EXPERTS=1600): same tokens off and on atwindows 1 and 4. Decode −3.0% / −2.0%. Without a fixed count, a load places as many experts as the free VRAM holds.
On WSL2 that moved from 2,270 to 2,399 between runs, and it changed the tokens with the profiler off as well,
because an expert on the CPU rounds differently from one on the card.
host_setup (687eee1), RTX 2070 Super, IQ4_NL:
"41–48% copies" at 8K, which was really the host stalled inside the setup on WSL2.
prompt +0.1%.
Failed:
--serve --max-context 32768 --kv q8_0(232 MiB of VRAM freeafter load), the second request (2,048 tokens after a 302-token one) ends with
ERR cudaGraphInstantiate: out of memory. It fails the same way with the profiler off and on (3 runs), so it is main's behaviour at that VRAM margin([Engine] Retry instead of failing when a CUDA graph is out of VRAM #301 addresses it).
GPU asking the CPU workers for missing experts on an 8 GB card) it never finished, so it was replaced by
kernel-by-kernel launches (above).
Not run:
--bench-reportrefuses.Limits
the
--window 4runs. The cost table uses--window 1for that reason.--window 4the tokens are not always the same from run to run, with the profiler off as well. How many guessesa call verifies depends on timing, and a verify of several rows can round differently from single rows. On the
RTX 2070 Super with the experts fixed at 882, 1 of 3 runs differed with the profiler off and 1 of 3 with it on. The
earlier window-4 checks above happened to be all the same. Identity is checked at
--window 1.RTX 3090), so its shares are kernels plus launch gaps; the explain section says so when it happens.
after a real 2,048-token text, because its answers reuse more of the cached experts. Reports compare with each
other, not with a user's chats;
STRATA_PROFILE=1profiles those.-DSTRATA_GIT_COMMITwhen the build host passes it, otherwise git's at configure time,otherwise a
COMMITfile besideengine/, otherwiseunknown.Inkling 2 only; for other families the report says "not modelled". Kernel cost is the probed small kernel's cost
times the launches; the per-launch time of the engine's own kernels is not measured.
report warns above 97%.
polystrata.py bench-report --text docsuses the checkout's README and docs instead.🤖 Generated with Claude Code