diff --git a/docs/upstream-port-plan.md b/docs/upstream-port-plan.md index f775c9b9..09491c1d 100644 --- a/docs/upstream-port-plan.md +++ b/docs/upstream-port-plan.md @@ -38,8 +38,8 @@ the run-to-run control); **L** live Codex session. | 2.1 | sm_120 bitwise decode set (`SIDE_MIXER=2`, `ATTN_DAILY`, `GR_UP75`, `GR_DOWN_TG=1`, `GU_SWIGLU`; interleaved MMVQ 2-4 columns; `ba2c2d5f`, `94104176`, `75afe3f4`, `ffac97f7`, ...) | compare each against our chain kernels / MMVQ; port what is not already ours | I, R | diff list below, nothing implemented | | 2.2 | #783 decode series and F7 ports (multi-token router, float4 combine, fused per-head RMSNorm+RoPE, batched K/V append, exact-T GDN, MTP catch-up skipping rejected rows, late shared-expert fork, multi-block argmax) | diff the list against `docs/chain-kernels.md`; port the missing | I, R | diff list below, nothing implemented | | 2.3 | CPU expert rows (`2a669f3c`, `79376a27`, `16c4da94`, `5ece068f`): router accumulators in registers, Q5_1/Q8_0 down-row dots, 512-bit gathers, default worker count | copy job into `crates/native-cpu-expert` | U, R | **3 of 4 sub-items do not apply to this model and these CPUs; worker plan ported opt-in**; see Results | -| 2.4 | Bitwise prefill kernels (`4e69f974`, `c675f5b7`, `5f843a92`): GDN 3 value heads per thread, quantize each token's MoE input once, `DEQUANT_WIDE` | port the prefill kernels | I, R | todo | -| 2.5 | QSA top-k at long context (wide kernel past 135K cells, cluster top-k on sm_90+; `586367cb`, `d05d26e9`, `6ef23b89`) | compare with our `qsa_late`; keep the better | I, R | todo | +| 2.4 | Bitwise prefill kernels (`4e69f974`, `c675f5b7`, `5f843a92`): GDN 3 value heads per thread, quantize each token's MoE input once, `DEQUANT_WIDE` | port the prefill kernels | I, R | **done, see Results 2026-10-27**: `gdn_rec_kh` opt-in (-6 % per launch, not worth enabling), GDN out-norm without the dead store (on, bit-identical, ~1 % of the GDN stage), quantize-once and `DEQUANT_WIDE` not ported (reasons in the analysis table) | +| 2.5 | QSA top-k at long context (wide kernel past 135K cells, cluster top-k on sm_90+; `586367cb`, `d05d26e9`, `6ef23b89`) | compare with our `qsa_late`; keep the better | I, R | **done, see Results 2026-10-27**: wide prompt top-k (QSA stage -4 % at chunk 2048, -6 % at 8192 in the replay) and the cluster decode top-k (window -8..-10 % per round in the replay, bit-identical) are the defaults | | 2.6 | WSL KV host copy pinned with `cudaHostRegister` (`c41c0ebb`) | laptop only | L (laptop) | todo | ## Phase 3: output-changing, experimental flags (each needs its own quality gate) @@ -134,6 +134,39 @@ variant of the IQ3_S/IQ4_NL dots selected by cpuid 7.1 EAX bit 4 + XCR0, integer Conclusion: nothing from Maya survives as a kernel port for the 5090 beyond what row 2.5 already took; the two items worth a task are the SSD conversation state (f, STRA-236) and the AVX-VNNI CPU tier (laptop). +## Results of the 2026-10-27 session (branch `claude/upstream-rest`, server `rnr5090`, RTX 5090 + Ryzen 9 9950X3D, driver 595.99.02, CUDA 13.2.2, Qwen3.8-Flash-Next IQ3_S + KAR level 2 pack, MTP pack `data/mtp-rt`) + +### Rows 2.4 / 2.5 (gates I and R) + +* **U**: `leleka-cuda-driver` lib 395 passed (`--features "cuda-driver sm86"`), `leleka-runtime` lib 631 passed (server, release). +* **I, kernels (model-free, `qsa_late::gpu_tests`, `prefill_stage_gdn_gpu`)**: every top-k variant (`fast`, `wide`, `sample` + `wide_failed`, `cluster`) writes the same ids as the Original's `qsa_topk_ref`, whole output buffer, in 24 cases (prompt tiles of 256 rows and decode calls of 1..5 rows, positions 100..261,500, continuous / heavy-tailed / 16 tied levels / all equal scores, the `n_kv <= width` identity branch included). `leleka_prefill_gdn_rec_kh` equals the Original's `gdn_rec_cols_pipe` in state, readout and witness for t = 1, 2, 7, 8, 9, 200, 1500, 2048, 8192 and for an infinite state, a NaN input and an overflow. The no-store out-norm writes the same `y16` and the same four status words (3 cases incl. non-finite inputs). +* **I, end to end (job `rest-id-256k`, replay of `night5-long-256k`, 5 requests 45,766..242,849 tokens, teacher forced, static tier, one CPU worker, fixed window; 8 arms in one process: baseline, kh, two-barrier rec, wide, cluster, all, no-store, baseline again):** `q_tail_gate` over 1,502 forced rows: d_top1 median / p99 / max 0.0000 and 0 argmax flips for all 7 arms against the baseline. The final-residual hashes of the first 100 prefill chunks (requests 0..3, up to 198k tokens) are equal in all arms; request 4 starts from another prefix-cache checkpoint in five of the arms (reused 194,560 instead of 196,608 tokens: the auto prefix budget under host memory pressure), so its chunk hashes are not comparable (its logprob rows are equal anyway). +* **R, kernel level (model-free, warm, mean of 20 launches):** wide against fast top-k per 256-row tile: 91.7 vs 144.6 us at 100k, 138 vs 251 us at 180k, 172 vs 334 us at 245k tokens (equal below ~32k tokens); decode top-k `qsa_topk_ref` vs cluster per call (1..5 queries): 157 vs 17 us at 131k, 183 vs 19.5 us at 245k tokens, 12 QSA layers per window; `qsa_decode_scores` is 14-52 us at the same depths (not the cost). GDN recurrence per 8192 tokens and layer: Original 4.31 ms, two-barrier 3.91, kh 4.04 (the 5090 is latency bound at 4.5 warps per SM; upstream's kh kernel was tuned for 64-80 SM cards). +* **R, replay A/B (job `rest-ab-256k`, `night5-long-256k` replayed in one process, fresh stack per arm, teacher forced, production env, prefix cache 20,000 MiB; B/X/K at chunk 2048 and D/Y at chunk 8192, 3 repetitions per arm; X/Y = wide + cluster + no-store, K = kh only):** host load made the wall times useless (B: 132..273 s for the same work, swap at 40 GB), so the PREFILL-PROFILE stage sums (sd < 1 %) and the decode window time are the measurements. QSA stage: 18,247 -> 17,491 ms (-4.1 %, chunk 2048), 13,846 -> 13,059 ms (-5.7 %, chunk 8192; -7 % past 100k tokens). GDN stage: kh -1 %, no-store -1 % (chunk 8192). Decode `round.run_window` per round: B 19.5 / 20.4, X 18.0 / 18.0 / 18.5 ms (-8..-11 %); decode tok/s 83.2 / 82.7 (B) against 93.5 / 93.0 / 90.1 (X). The kh kernel alone (K) shows no stage gain worth a default. +* Quantize-once and `DEQUANT_WIDE` were not ported (analysis table above): bounded by 0.3 % of a chunk and sm_86-only. + +### The 5090 gap to vanilla Strata on the 256k session (owner's priority item, 2026-10-27 evening) + +Same text (`long_session.py`, 5 turns to ~245k tokens, 300 output tokens), TTFT s / decode tok/s per turn (`scripts/upstream-rest/turns.py`): + +| run | turn 1 | 2 | 3 | 4 | 5 | sum TTFT | mean decode | wall | +|---|---|---|---|---|---|---|---|---| +| night5 (chunk 2048, uniform per-layer slots) | 26.0 / 88.9 | 26.8 / 91.1 | 30.6 / 85.8 | 25.2 / 102.6 | 25.7 / 80.0 | 134.3 | 89.7 | 151 s | +| night6 (chunk 8192) | 12.7 / 88.7 | 11.5 / 96.1 | 13.6 / 83.3 | 12.0 / 91.8 | 11.0 / 92.3 | 60.7 | 90.4 | 77.6 s | +| rest-before1 (night6 config, new binary, branch features off) | 14.2 / 83.3 | 12.2 / 96.8 | 13.8 / 79.2 | 12.4 / 90.7 | 11.2 / 77.5 | 63.8 | 85.5 | 81.6 s | +| rest-before2 | 10.7 / 91.8 | 11.3 / 94.2 | 14.0 / 80.2 | 12.4 / 90.1 | 10.9 / 81.3 | 59.2 | 87.5 | 76.6 s | +| rest-after1 (branch defaults) | 11.3 / 104.3 | 11.5 / 104.8 | 13.3 / 97.4 | 11.9 / 115.6 | 10.9 / 91.6 | 58.8 | 102.7 | 73.8 s | +| rest-after2 | 15.0 / 95.1 | 13.9 / 109.4 | 13.3 / 99.9 | 12.1 / 113.1 | 10.9 / 90.0 | 65.2 | 101.5 | 80.3 s | +| vanilla Strata 0.2.6 / engine 0.1.50 | 6.9 / 121.7 | 8.3 / 144.2 | 9.4 / 147.7 | 8.2 / 164.4 | 8.5 / 194.3 | 41.3 | 154.5 | 51.2 s | + +Findings (runs `rest-before*`, `rest-after*` under `~/work/leleka-e2e/runs/`; before = the same binary with `LELEKA_ORIGINAL_SERVE_PER_LAYER_SIZED=0 LELEKA_QSA_CLUSTER=0 LELEKA_QSA_TOPK=fast LELEKA_PREFILL_GDN_NOSTORE=0`): + +1. **Chunk 8192 is the prefill fix** (night5 -> night6: 134 -> 61 s of TTFT); it is not the default of the shipped deploy profile yet. +2. **Slot sizing, root cause.** `run-e2e.sh` (and the `rtx5090-32g` profile `engine_env`) set `LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER=yes`. `original_cache_startup::open` took the profile-sized path only for `!per_layer`; with per-layer it opened `slots` slots of the LARGEST layer blob (2.54 MiB; 8,701 slots in 21.57 GiB) with per-layer admission, while the Original's per-layer plan (generate.cpp ~6333, #369) gives every layer `quota` slots of its OWN blob (1.94 MiB average). Fixed: the same VRAM now holds **11,280 slots** (21.50 GiB; the Original/vanilla reach 12,575 in 23.87 GiB because they have 2.2 GiB more free before the cache). `LELEKA_ORIGINAL_SERVE_PER_LAYER_SIZED=0` restores the uniform plan. The output is not bit-identical to the uniform plan (more experts run on the GPU, which rounds differently from the CPU): quality gate `rest-q-256k`. +3. **Decode +17 %** (mean over the turns 85.5 / 87.5 -> 102.7 / 101.5 tok/s; per turn +10..+26 %): sized slots plus the cluster top-k; per round `round.run_window` 19.2 -> 18.4 ms and fewer rounds (697 against 787 for the same tokens). Still 1.5x behind vanilla (154 tok/s; its round is ~14 ms). Vanilla's route-tail skip (lossy, on by default) is not copied. Global admission (`PER_LAYER=no`, owner's job night7) is not covered here. +4. **Prefill is still 1.4x behind vanilla** (59-65 s against 41 s of TTFT). Per chunk of 8192 at position 139k (PREFILL-PROFILE): gdn 469, qsa 468, moe 654 (ring 456, prepare 123), total 1,677 ms. The session totals hardly moved between before and after (qsa 13.85 -> 13.76 s, moe.ring 15.6 -> 15.4 s). **`moe.ring` did not change when the resident slots went from 8,701 to 11,280**: our prompt path streams every expert of every layer through the ring whatever is resident (docs/prefill-throughput.md: the tier removes 0.6 % of the entries); vanilla's `stream_all` streams only the non-resident experts, reads the resident ones in place (`STRATA_MMQ_DIRECT`, `mmq_resident_sort.hpp`) and runs the prompt experts on the fused int8 kernels (`STRATA_PF_FUSED=1`, row 3.2, lossy). That is the next item: a pointer-table MMQ for resident experts would take roughly half of the 15.4 s of ring time off the session (11,280 of 24,576 experts are resident). Not started. +5. The wide prompt top-k did not show up in the e2e stage sums (qsa 13.85 s before, 13.76 s after) although the replay with the explicit `!wide` flag shows -5.7 %: unresolved. The binary of `rest-q-256k` logs the chosen kernels once (`leleka-serve qsa prompt top-k: ...`, `... decode top-k: ...`) and one arm runs the default flags, to settle it. + ## Not taken (reasons in the digest) Qwen3.6-35B-A3B path, Metal/SYCL/HIP-only changes, K8V4 streaming and elastic KV (`--kv-grow`; our serve path excludes K8V4), the installers and host app. diff --git a/scripts/upstream-rest/turns.py b/scripts/upstream-rest/turns.py new file mode 100644 index 00000000..a4287041 --- /dev/null +++ b/scripts/upstream-rest/turns.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +"""Per-turn TTFT / decode tok/s / wall of the long-session.json of e2e run directories: turns.py RUN_DIR [RUN_DIR ...]""" +import json +import os +import sys + +for r in sys.argv[1:]: + d = json.load(open(os.path.join(r, "long-session.json"))) + turns = d if isinstance(d, list) else d.get("turns") or d.get("results") or [] + if isinstance(d, dict) and not turns: + print(r, list(d)[:8]) + continue + cells = " ".join(f"{t.get('ttft_s')}/{t.get('decode_tok_s')}" for t in turns) + wall = sum(t.get("wall_s", 0) for t in turns) + ttft = sum(t.get("ttft_s", 0) for t in turns) + dec = sum(t.get("decode_tok_s", 0) for t in turns) / max(len(turns), 1) + print(f"{os.path.basename(r):<24} ttft/decode per turn: {cells} | sum ttft {ttft:.1f} s, mean decode {dec:.1f} tok/s, sum wall {wall:.1f} s")