Speed program: ledger V5/V7 analysis of the flag waits (no kernel overhead to remove; the loss is the CPU leg's arrival), cupti_flag_waits.py

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-10 18:55:34 +01:00
co-authored by Claude Sonnet 5.5
parent b56e5afb58
commit 456f5336b1
2 changed files with 110 additions and 2 deletions
+2 -2
View File
@@ -97,9 +97,9 @@ Structure first, then the layer steps in graph order: embed (R7), mixer half (V3
| verify: shared expert on a side stream (V4a) | shared expert on a side stream, forked after the doorbell, joined before the combine (`LELEKA_SM120_SIDE_SHARED`, code `255159a89`, off) | 27.6 us before the first expert | 15.0 us | section delta (`CE.1` against `CL.1`): doorbell to first expert 27.6 -> 10.9 us (VANL 15.0), FFN phase 6.600 -> 6.267 ms (-0.333; qsa layers 99.8 -> 87.6, gdn 109.3 -> 102.7 us p50), graph p50 12.386 -> 11.944 ms (-0.44); identity `spd-sqid1` P4 PASS: 2057 rows bit-identical, draft trace 518/518; A/B `ab-sqe` (L against E, n=10): decode tok/s +0.29 %, CI -0.43..+1.01 % (not significant); ms/round -0.61 (-2.97 %), CI -6.08..+0.15 %; tokens/round 3.64 -> 3.54 (live replay placement noise, numerics are identical); stays OFF; the CUPTI section gain (-0.33 ms) is of the size the replay cannot resolve at n=10, so 10 more pairs (`spd-sqe2`) and the set A/B M against all side parts (`verify-side-branches-ab-mixer-only-vs-all-branches`) are queued | CUPTI | device | fixed (closed 2026-11-09 by section delta + identity (owner method); set A/B `verify-side-branches-ab-mixer-only-vs-all-branches` (M mixer only against U all three side parts, n=10 pairs, 27 requests a block, 2026-11-10): decode tok/s 179.11 -> 182.90, +2.11 %, CI +1.18..+3.04 % (ms/token 5.583 -> 5.467); end-to-end 162.29 -> 164.70, +1.49 %, CI +0.17..+2.80 %; ms/round 20.06 -> 19.90, -0.80 %, CI -3.80..+2.21 % (not significant); tokens/round 3.59 -> 3.64, CI -2.01..+4.60 %; no regression; out_sha equal in 15 of 300 live requests, which is replay placement noise, the identity gate is the teacher-forced `spd-sqid1`) |
| V4b | routed experts on their own branch (VANL: plan wait, VRAM experts, `fetch_blobs`, CPU wait, `add_hits` on a side stream; main stream does the shared expert and the next norm) | all on the capture stream | branch | rest of V2 after V4a, not yet known | CUPTI | device | open |
| V4c | norms and hyper-connection reads (`gr_norm_split`, `gr_down`, `gr_up`) as separate branches | main stream | main stream (VANL does not branch them; a layer's `gr_*` chain stays on the main stream) | no structural difference; kernels in K8..K10 | CUPTI | device | proved-equal |
| V5 | flag waits on the CPU leg (`verify_wait_flag_ge` 96 x 26.9 us + `chain_wait_copy_i32` 48 x 5.4 us against `wait_flag_ge` 144 x 8.1 us) | 2.836 | 1.160 | +1.676 | CUPTI | device | open |
| V5 | flag waits on the CPU leg (`verify_wait_flag_ge` 96 x 26.9 us + `chain_wait_copy_i32` 48 x 5.4 us against `wait_flag_ge` 144 x 8.1 us) | 2.836 | 1.160 | +1.676 | CUPTI | device | open (analysis 2026-11-10, no code and no switch: the wait kernels have no overhead part to remove; script `scripts/e2e/codex/speed/cupti_flag_waits.py`, windows `verify-new-switches-cupti-windows/CL.2` (LEL) and `cupti/VANL`, request 29. Per graph from the window: LEL A 0.215 + B 0.718 + M 1.816 = 2.748 ms (the cell 2.836 is the earlier graph set), VANL 0.266 + 0.099 + 0.791 = 1.156 ms. What is waited on: A = flag A, the plan the host publishes after the doorbell; B = flag B, the PCIe copies landed (DMA mode: raised behind the copy batch, the wait ends 3.3 us (p50 3.0) after the last copy ends); M = flag M, the CPU rows in mapped memory. Three waits a layer in both (144 nodes) and the same poll loop (`while (*flag < v) __nanosleep(100); __threadfence_system()` in `original_verify.cu`, `chain_window.cu`, upstream `dp4a.hpp`). Overhead part: a wait whose flag is already set when it starts lasts 1.3-1.4 us for B and M in both sessions (VANL B median 2.2) and 2.2 us for A with the plan copy fused (VANL: wait 1.7 + separate copy 3.2-3.7), i.e. 48 x (2.2 + 1.3 + 1.4) = 0.24 ms a graph against about 0.25 ms in VANL; the poll latency after the flag is set is at most the same 1.4 us on about 35 blocked waits a graph, <= 0.05 ms, also in VANL. The rest is real waiting. By wait, LEL minus VANL: A -0.051, B +0.619, M +1.025 ms. B: 13.9 % of LEL layers have a DMA PCIe leg (3.9 MB p50, B wait 99 us mean there); in VANL 21.3 % of layers have a `fetch_blobs` above 2 us and pay the PCIe time as kernel time on the GPU stream (V6, -1.621), so V5 and V6 move the same time between wait and kernel (V7). M: the wait does not start early (M start after the doorbell, layers without a PCIe leg: LEL 70.7 us, VANL 60.1 us); the CPU rows arrive later: layers with CPU work (M wait > 4 us) 37.1 % against 24.3 %, M end after the doorbell 133.5 against 98.9 us mean (p50 111.6 against 92.8); at equal T the same (T=4: 45.5 % / 142.1 us against 24.4 % / 109.2 us; T=3: 36.5 % / 125.2 against 24.8 % / 95.6). So the loss is the arrival time of the CPU leg, not the graph kernels; to look at on the host/tier side (hand-over to `hex-finish`): the PCIe/CPU split (LEL `engine.log` `pcie_frac=0.45` fixed; VANL's PcieAuto in the same session went 0.55, 0.40, 0.35), tier state (request stats of the window's request: LEL VRAM 92.6 %, PCIe 2.2 %, CPU 5.2 %; VANL about 93.7 / 1.3 / 5.0 % from its `strata serve` lines, windows not matched), host pickup and plan latency (not visible: the trace has no timestamp of the flag word; upstream `wait_flag_ge_stamped`, `verify_kernels.cu:1250`, would give flag arrival against poll latency and needs a GPU run, not done)) |
| V6 | PCIe fetch and CPU-row hand-over (doorbell, mapped copies, `fetch_blobs`, `add_hits`, `rebase_ptrs`) | 0.488 | 2.109 | -1.621 | CUPTI | device | proved-equal (LEL ahead) |
| V7 | V5 + V6, the whole miss-leg handling | 3.324 | 3.269 | +0.055 (+0.17 by an earlier count of the same sets) | CUPTI | device | open |
| V7 | V5 + V6, the whole miss-leg handling | 3.324 | 3.269 | +0.055 (+0.17 by an earlier count of the same sets) | CUPTI | device | open (analysis 2026-11-10 with V5: V5 +1.676 and V6 -1.621 are the same PCIe time counted as wait in LEL (DMA, flag B) and as kernel time in VANL (`fetch_blobs`, `rebase_ptrs`, `copy_rows_from_mapped`), so the sum is flat and no graph kernel is left to change; what remains is the CPU leg arriving 25-35 us later after the doorbell in the layers that have CPU work (V5), a host/tier/split question; closes when that is A/B'd or the tier states of the two sessions are matched) |
| K11 | routed experts in the verify graph, role total (gate/up/SwiGLU, down) | 2.507 | 2.484 | +0.023 (entry mix differs; at equal entry counts LEL is faster: `window_moe_down_20` 13.6 us with 40 entries against 17.4 us, `sm120_moe_gu_swiglu_22` 12.3 us with 50 entries against 26 us with 40) | CUPTI | device | open |
| K15 | hit tally `add_hits` (48 x 1.2 us against 48 x 1.3 us) | 0.059 | 0.063 | -0.004 | CUPTI | device | proved-equal (LEL ahead) |
| S2 | `GU_SWIGLU` (routed expert gate/up + SwiGLU + q8_1) | on since lever 1 | on | as S1 | gap doc lever 1 | device | fixing (needs a CUPTI section delta) |
+108
View File
@@ -0,0 +1,108 @@
"""Flag waits on the CPU/PCIe leg of the verify graph, per layer, from one CUPTI window (ledger rows V5, V7).
usage: python3 cupti_flag_waits.py TRACE_DIR LEL|VANL [T]
Per layer (doorbell to the next doorbell) the three waits in stream order are: A (plan published; LEL fuses the plan copy
into `chain_wait_copy_i32`, VANL has `wait_flag_ge` + `copy_i32_from_mapped`), B (PCIe copies landed) and M (CPU rows
written). A wait whose flag was already set when it started shows its floor (1.3-1.4 us: one mapped read and the fence);
a longer wait is the real wait for the other side. The script prints, per layer class (with / without a PCIe leg),
the share of layers, the wait durations, when the M wait started and ended relative to the doorbell, and each wait's
contribution to one graph (48 layers). For LEL the PCIe leg is a B wait above 3 us (DMA, flag B behind the copies);
for VANL it is a `fetch_blobs` kernel above 2 us. Optional T keeps only windows of T tokens (the grid of the CPU-row
copy is T * 10 blocks). Host-side Python only; reads the trace, uses no GPU.
"""
import collections
import statistics as stats
import sys
sys.path.insert(0, "/data/leleka-e2e/decode/tools")
import lct as L # noqa: E402
FLOOR_US = {"LEL": 3.0, "VANL": 2.0}
LONG_M_US = 4.0
def load(path):
t = L.Trace(path)
by_corr = collections.defaultdict(list)
for k in t.kernels:
by_corr[k.corr].append(k)
graphs = [c for c, v in by_corr.items() if len(v) >= 900]
graphs.sort(key=lambda c: min(k.start for k in by_corr[c]))
return t, [sorted(by_corr[c], key=lambda k: k.start) for c in graphs[2:-2]]
def is_wait(name):
return "wait_flag_ge" in name or "wait_copy_i32" in name
def layer_record(name_of, seg, doorbell, mode):
waits = [k for k in seg if is_wait(name_of(k))]
if len(waits) != 3:
return None
a, b, m = waits
if mode == "LEL":
pcie = (b.end - b.start) / 1e3 > FLOOR_US["LEL"]
else:
fetch = [k for k in seg if "fetch_blobs" in name_of(k)]
pcie = bool(fetch) and (fetch[0].end - fetch[0].start) / 1e3 > FLOOR_US["VANL"]
copy_rows = [k for k in seg if "copy_rows" in name_of(k)]
us = lambda x: x / 1e3 # noqa: E731
return dict(
pcie=pcie, tokens=copy_rows[0].gx // 10 if copy_rows else -1,
a=us(a.end - a.start), b=us(b.end - b.start), m=us(m.end - m.start),
m_start=us(m.start - doorbell.start), m_end=us(m.end - doorbell.start),
)
def layers(path, mode, tokens):
t, graphs = load(path)
name_of = lambda k: t.names.get(k.name, "") # noqa: E731
out = []
for ks in graphs:
bells = [k for k in ks if "doorbell_publish" in name_of(k)]
if len(bells) != 48:
continue
for i, bell in enumerate(bells):
end = bells[i + 1].start if i < 47 else bell.start + 400000
rec = layer_record(name_of, [k for k in ks if bell.start <= k.start < end], bell, mode)
if rec and (tokens is None or rec["tokens"] == tokens):
out.append(rec)
return out
def quantiles(values):
v = sorted(values)
n = len(v)
return "mean %.1f p10 %.1f p50 %.1f p90 %.1f" % (stats.mean(v), v[n // 10], v[n // 2], v[9 * n // 10])
def report_class(rows, total, label):
share = len(rows) / total
print("%s: %.1f%% of layers (%d)" % (label, 100 * share, len(rows)))
for key in ("a", "b", "m"):
print(" wait %s duration: %s; per graph %.3f ms" % (
key.upper(), quantiles([r[key] for r in rows]), 48 * share * stats.mean(r[key] for r in rows) / 1e3))
print(" M wait start after doorbell: %s" % quantiles([r["m_start"] for r in rows]))
print(" M wait end after doorbell: %s" % quantiles([r["m_end"] for r in rows]))
long_m = [r for r in rows if r["m"] > LONG_M_US]
if long_m:
print(" M wait longer than %.0f us (CPU rows not yet there): %.1f%% of these layers, end after doorbell: %s" % (
LONG_M_US, 100 * len(long_m) / len(rows), quantiles([r["m_end"] for r in long_m])))
def main():
path, mode = sys.argv[1], sys.argv[2]
tokens = int(sys.argv[3]) if len(sys.argv) > 3 else None
rows = layers(path, mode, tokens)
print("%s %s layers %d (graphs %d)" % (mode, path, len(rows), len(rows) // 48))
for flag, label in ((False, "layers without a PCIe leg"), (True, "layers with a PCIe leg")):
subset = [r for r in rows if r["pcie"] == flag]
if subset:
report_class(subset, len(rows), label)
total = {k: 48 * stats.mean(r[k] for r in rows) / 1e3 for k in ("a", "b", "m")}
print("per graph: A %.3f + B %.3f + M %.3f = %.3f ms" % (total["a"], total["b"], total["m"], sum(total.values())))
if __name__ == "__main__":
main()