LELEKA_PREFILL_QSA_PREFETCH, LELEKA_PREFILL_GDN_POOL and LELEKA_PREFILL_MOE_SPAN_CACHE now default on (=0 restores the old path). R hash of every prefill chunk and top-16 rows identical on 945-codex-crm (108 chunks) and night5-long-256k (34 chunks); paired replay at chunk 8192: prefill chunk time at >= 100k -2.8 % (QSA -6.2 %, MoE -3.5 %, GDN at noise). Real-stack A/B (rest-e2e-ab2) queued, not yet measured. docs/upstream-port-plan.md section "Closing the host gaps between dependent phases". Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
80 KiB
Porting plan: Strata upstream 41cf05a0 into the Leleka runtime
Source of the list: docs/upstream-digest-2026-10-25.md (ranked shortlist 1.1, defaults flipped 1.3, possible bugs of ours 1.4).
Owner's instruction (2026-10-25): take what upstream has, as a plan and actions, and try everything. Every item below is tried; an item is
kept only if it passes its gate, otherwise it stays behind a flag or is dropped with the numbers written here.
Rules for every item (AGENTS.md): no performance claim without a paired A/B on the same workload plus a quality result; synthetic and end-to-end
numbers reported separately; output-changing items are experimental flags until their own gate passes; the Original reference build stays the pinned
stra169-ladder (upstream builds are not a valid baseline, digest 1.3). The port is not bit-deterministic between processes (job 9n0: two runs of
the same build agree on 13.5 % of the rows, d_top1 p99 0.24, 0.65 % argmax flips), so "identical" claims need the run-to-run band as yardstick.
Gates: U unit/CPU test; I identity probe (kernel output bytes vs the old kernel, model-free); R replay A/B on the 5090 (9e3 CRM capture,
paired arms in one process, 3+ repeats); Q teacher-forced agreement (scripts/quality/q_tail_gate.py, rule: p99, max and flip rate each <= 1.25x
the run-to-run control); L live Codex session.
Phase 0: correctness, cheap, no GPU needed
| # | Item (upstream SHAs) | Action | Gate | Status |
|---|---|---|---|---|
| 0.1 | Control-token text in messages becomes real special tokens (c16f31f8, 98b7ea94, 0d613031) |
swap <think>, </think> and the other control literals in message text (user, tool, system, assistant history, tool-call arguments, tool descriptions) for private-use marks before the template renders; after it encode those spans as plain text (Tokenizer::encode plain spans); the template's own markers stay special; same path for token counting |
U (injection fixtures), L | U done (2026-10-25, native Windows cargo test: leleka-tokenizer lib 11 + marked 7 + fast_path 7 + oracle 3, strata-control 259 lib + 33 backend_worker_http, leleka-runtime lib 504, all green; the injection fixtures are in crates/tokenizer/tests/marked.rs, responses.rs tests and backend_worker_http.rs). leleka_tokenizer::LiteralMarks maps every type 3/4 literal to a plane-15 private-use mark (a forged mark is escaped); render_request marks instructions, message text, reasoning, call arguments, tool outputs, tool descriptions/schemas; the gateway's own <tool_call>/<tool_response> markers stay literal; Tokenizer::encode_marked is the one path for generation and /input_tokens; the text contract carries the marked string and leleka-runtime prepare_prompt reads it with encode_marked. Not done: strata-desktop-core (runtime_gateway, runtime_tools) still renders unmarked text; replayed assistant text keeps its marks too (a model-written </think> in history is replayed as text); an engine older than this change reads the marks as private-use characters. L todo (live Codex session) |
| 0.2 | --dump-logits header lies on native packs (504579da) |
check every parity harness that compared against it | U | checked, not affected; guard added (2026-10-26). Searched the whole tree (scripts, tools, benchmarks, docs, crates, desktop, control-plane; engine/strata excluded) for dump-logits, dump_logits, logits_identical, logits-dump readers and fixtures: the only reference is the manual debugging recipe in docs/gpu-bringup.md step f.5 ("re-run the first differing case with the CLI --dump-logits"), never executed by a harness. Every parity and quality harness of ours reads other channels: the serve-mode STRATA_LOGPOS top-k rows (scripts/quality/q_lib.py, q-common.sh, jobs 991-9973, scripts/numerics/num_lp*.py), the DBG residual window lines (num_cmp_resid.py, num_lad_tools.py) and text/token outputs (compare-chat-reports.py, the replay and smoke harnesses). The upstream defect is real for the pinned reference build stra169-ladder (older than 504579da: header written at open, n_prompt + max_new rows promised, a native pack never reaches the dump site), so the recipe in gpu-bringup.md now says to check the dump first, and scripts/quality/logits_dump_check.py (offline, no model; --selftest passes: honest file, header lying with no rows, count one too high, short body, truncated row, wrong vocabulary) trusts the file size instead of the header and refuses an empty dump. No code of ours changed. Not verified: the recipe itself was not re-run on the server (no GPU job) |
| 0.3 | Spec window / MTP drafts near the context end run past max_cells (e85567b6) |
test the controller at max_context - k |
U | U done (2026-10-26, server rnr5090, cargo test --release: leleka-runtime lib original_spec_controller + original_serve_engine 60 passed, leleka-cuda-driver --features cuda-driver lib 382 passed). Ours was not the upstream crash (the serve loop ended as length instead of "ran out of context") but had the same hole in two places: (a) verify_commit ended the request when p + t > max_context instead of taking the rows that fit (upstream generate.cpp room), losing up to 7 tokens at the end of a context, and the MTP chain drafted mtp_t - 1 cells whatever the context had left (upstream mtp.cpp: max_steps = min(.., max_cells - (p + a))); (b) the driver refused a draft launch when first + a + max_t - 1 > 262144 (mtp_original_full_drafter.rs, mtp_original_full_round.rs) although only draft 0 was needed: a request admitted at the edge (n + max_new + 8 = 262144, a window of up to 8 rows plus accept 7) died with InvalidQwenShape. Now: the window shrinks to max_context - p (no room = finished as context; a shrunk window is not observed by the adaptive policy), the chain is clamped to max_context - (p + a) through set_draft_plan and restored on the next round, chain_end_within_cells bounds the driver's chain loop, the staging checks bound what is staged (first + max(rows, a + 1)). Tests: spec_windows_and_drafts_never_pass_max_context_at_any_distance_from_the_end (max_t 2/4/6/8, k = 1..max_t+3 from the end, fixed / suffix / min_p / adaptive: no row or draft cell >= max_context, text = greedy of every row that fits), a_window_near_the_context_end_takes_only_the_rows_that_fit, the_chain_is_shortened_near_the_end_and_restored_after_it, a_chain_clamped_by_one_request_is_restored_for_the_next, serve_request_to_the_context_end_stays_inside_the_cells_and_ends_as_context (real engine over the fake port), the_chain_stops_at_the_last_cell_that_exists (driver). Mutation check: with the window shrink and the chain clamp removed, 5 of these fail. Not verified on a model (no GPU run: the driver check relaxation is exercised only by the pure helper test). Open: the MTP ring is fixed at MTP_ORIGINAL_MAX_CELLS = 262144 cells while leleka_context::geometry::MAX_CELLS is 524288: a 512K context cannot draft past cell 262143 (not changed here) |
| 0.4 | PLE gather_batch matches prefetched rows by position (36381540) |
test reordered and duplicated keys on our async PLE reader | U | U done, ours is not affected (2026-10-26, server, cargo test --release: leleka-model-format lib ple_reader 27 passed, leleka-runtime lib kar_ple_cache 5 passed, 2 ignored need the real archive). Upstream's bug is in its PleTable::gather_batch fast path, which compared the prefetch slot list with the requested token list position by position and re-read the rows of a reordered or duplicated batch (a second ticket; the bytes were right, the read was wasted). Ours has no such matching: PleReader::issue returns a Ticket that owns its output buffer (slot i = request row i; plan_reads records one Use per request slot, duplicates included) and the row cache is keyed by row id; the per-token path (ple_issue/ple_collect, original_window_ple) pairs a token with its own ticket, and the KAR PLE GPU cache (kar_ple_cache.rs, lookup_rows) is a RowMap keyed by row id. Pinned by ple_reader::tests::prefetched_keys_are_matched_by_row_never_by_position (the upstream cases: ordered, permutation, subset, duplicates, duplicate prefetch, missing key, extra prefetch, none, over the window, window overflow, plus out-of-range rows; cache 0 / 8192 rows, inline / threaded; every slot equals the byte oracle, tickets collected out of order, a row already fetched is not read again, a batch never reads more than its distinct rows) and kar_ple_cache::slot_tests::rows_are_matched_by_row_id_never_by_position_in_the_chunk (swapped, reversed, shifted, repeated, subset and mixed known/new chunks keep each row in its slot). No code change |
| 0.5 | Conversation/prefix cache edge cases (8824e217 cancelled between windows loses the restored conversation; 940011da full cache drops instead of evicting; aece46db 1-token prompt with spec) |
tests on the prefix store and serve loop | U | U done; one defect found and fixed (2026-10-26, server, cargo test --release -p leleka-runtime --lib: 557 passed, 56 ignored (GPU/model)). (1) 8824e217: ours was affected on the default conversation cache (ServeConversation, the prefix cache is off by default). begin clears the live claim of the session (live_ok = false until the request ends) and a request cancelled while its prompt was read (between two chunks or before the first one) finished with nothing noted, so the conversation it had restored (live session or checkpoint) was no longer continuable and the next request of the conversation read from its last checkpoint. Now prefill() that ends Cancelled hands the claim back when the state allows it (ServeConversation::note_cancelled_prefill: placed request, 0 < reached < prompt.len(), nothing broken, no state lag, draft ring at the session's position: the same predicate a live continuation needs at the next begin; otherwise nothing is claimed as before). A cancel in the decode phase already kept the claim (host.draft_in_step()). The prefix cache variant was already right (store kept, live truncated per chunk): new a_request_cancelled_right_after_restoring_its_session_keeps_it. Tests: a_request_cancelled_between_prompt_chunks_leaves_its_conversation_live (also shows the old behaviour: without the claim the retry restores a checkpoint), a_cancel_before_the_first_chunk_keeps_the_restored_session_and_a_session_that_is_not_in_step_keeps_nothing. (2) 940011da concerns upstream's parked-conversation RAM cache (not bound in ours: NO_PARKING); the equivalents are covered: ConversationCache evicts oldest-first by slots and bytes and refuses only an image bigger than the whole budget (a_full_cache_evicts_the_oldest_for_the_new_snapshot_by_slots_and_by_bytes), the prefix store evicts by value (a_full_store_evicts_the_session_idle_longest_so_the_newest_request_is_cached, plus the existing store tests), the checkpoint chain is bounded by LRU (the_chain_is_bounded_and_the_saved_points_follow_it). No code change. (3) aece46db was a CLI-only start-position sentinel (0 meant "speculation not started"); ours has no sentinel (position = n - 1, the controller starts at 0 for a 1-token prompt). Pinned by a_one_token_prompt_speculates_from_position_zero (controller: fixed, suffix and adaptive windows, greedy text), serve_request_with_a_one_token_prompt_speculates (real engine over the fake port), a_one_token_prompt_starts_empty_reads_nothing_and_checkpoints_nothing (conversation), a_one_token_prompt_reads_nothing_and_claims_nothing (prefix). Not verified live: the keep-claim path needs a cancelled request on a real stack (the smoke original_serve_conversation_smoke_resume_matches_a_full_read does not cancel); no job was run |
| 0.6 | Callback-thread affinity (0e20d9ae, c08fd902): one no-op host callback before the host thread pins itself; claimed 142.8 -> 207.8 tok/s on a 5090 + 9950X |
check our host functions (compute_drain, DMA staging); microbench the callback latency on the server |
R | not affected here, no speed claim; kept as a defensive Linux-only warm-up (LELEKA_CB_WARMUP=off skips it); see Results |
Phase 1: numerical robustness
| # | Item | Action | Gate | Status |
|---|---|---|---|---|
| 1.1 | q8_1 scale/sum overflow becomes NaN (2b726ba6, f6601bf8, 7a0e3023, e372d4ff) |
port the clamps to our sealed quantizers (q8_1_store, native_quantize_q8_1, SwiGLU quantizer, gr_q8_*) and regenerate the PTX; probe with extreme activations |
I, Q | U/I/Q done (2026-10-27; gate Q: new against old build is inside the run-to-run control: p99 d_top1 0.112 against 0.131, max 0.157 against 0.367, argmax flips 1 against 12; with the chain kernels p99 0.179 against 0.197, max 0.413 against 0.413, flips 3 against 13). Ours had the old formula everywhere (d = amax / 127, make_half2(d, sum), roundf(xi / d) stored as int8): the entries head_quant (mtp_original_full_head_native, native_head_native), mtp_original_quantize (mtp_original_tail, mtp_original_full_checks), quantize_q8_1_kernel (mtp_original_full_head_iq, native_head_iq: the routed experts' input and SwiGLU output) and chain_swiglu_quant_kernel (chain_window). gr_q8_*, q8_1_store and the shared-expert SwiGLU quantizer have no separate copy in our sealed set (the GR reads and the shared expert quantize through head_quant; the experts through quantize_q8_1_kernel). Not changed: the MMQ prompt quantizers (ggml quantize_mmq_q8_1, mtp_prefill_q8; upstream did not clamp them either) and the Q8_0 CPU-consistent quantizers. PTX not regenerated by a full compile: three of the sealed files were built with CUDA 13.0.88 (not installed anywhere) and a recompile renames the hashed anonymous-namespace entries, so only the quantizer entries are replaced (scripts/q8/splice_ptx.py, recipe scripts/q8/rebuild_quantizer_ptx.sh, nvcc 13.2.86; the recipe reproduces the sealed head_quant text byte for byte on a recompile of the old source); every other byte of each sealed file is unchanged. Pins (original_verify_window_{proj,moe,chain}.rs, native_head.rs), the seal-plan digests and the sm_86 companions (sm86_assets.py build: 131 companions, check OK; it also added the companions of chain_window and original_verify_window_pcie_fast that were missing before) moved with them (scripts/q8/repin.py). Tests on the server: leleka-cuda-driver lib 387 passed with --features "cuda-driver sm86", leleka-runtime lib 564, ptxas -arch=sm_120 accepts every spliced file. I (tools/q8-probe, scripts/q8/probe_all.sh, run directly on the 5090, log ~/work/gpu-runs/q8/probe_all.log): all 7 assets OK. 65,536 random blocks per asset (scales 1e-6..1e3, zero blocks, subnormals, ties, one big lane): 64,676 identical byte for byte, the 860 that differ are exactly the blocks whose float sum is past 65,000 or whose scale is past the half range (OLD stored inf there); 0 h words differ in the chain kernel. 15 edge/extreme blocks (sum 65504/65520/4e6, amax 8.0e6/8.4e6/1e9/1e30/FLT_MAX, +-inf, +inf and -inf, NaN lane, all NaN, zero): OLD stored a non-finite scale in 9 and a non-finite sum in 12; NEW stores a finite scale and sum in all of them except where the block really sums to NaN (it stays NaN so STRATA_DBG_NAN-style guards still see it), codes inside +-127 and equal to clamp(round(x / d)); a block that was finite before is the same bytes. Q (queued behind the other agent's upspeed-31-* jobs, job up2-q8-quality, log ~/work/gpu-runs/holder2/jobs/up2-q8-quality.log, runs ~/work/gpu-runs/quality/runs/Q8-*; NOT run yet): rt-old (this branch before the change) twice and rt-new once, teacher-forced along the Original paths, static tier, seed off, plus both with LELEKA_CHAIN=all; compare with python3 scripts/quality/q_pair.py Q8-A1-old/port.log Q8-B1-new/port.log --control Q8-A2-old/port.log (identical rows expected; if the port is not bit-deterministic run to run, read the deviation against the A1/A2 control with q_tail_gate.py's rule). Until that runs, "outputs for normal activations are bit-identical" is established for the quantizer kernels (I) and not end to end Merged into claude/port-gpu-bringup (2026-10-26): the bringup branch had sealed a different chain_window.ptx (new entry chain_gr_down_t2w8_nb4, commit c9ccd81), so the chain clamp was not taken as a file from either side: the bringup sealed file is the base and only chain_swiglu_quant_kernel was replaced (splice_ptx.py; the entry text is byte for byte what rebuild_quantizer_ptx.sh compiles from the merged chain_window.cu on the server, nvcc 13.2.86), every other entry is the bringup one. Its pin, the sm_86 companion set (sm86_assets.py build: 132 companions, check OK) and the table were regenerated on the merged tree; the six other quantizer assets and their companions are identical to the ones of this row. |
| 1.2 | NaN guard with self-healing, prompt retry after a non-finite window (f332a855, 894f133b; STRATA_NAN_GUARD=1) |
non-finite detection on the window logits, re-read from the last good checkpoint; port to the serve loop | U, L | U done, L done for the injected path, default OFF (2026-10-27). What a guarded round does: OriginalSpecController::verify_commit takes its round checkpoints and, with LELEKA_ORIGINAL_SERVE_NAN_GUARD=on (profile engine_env key; ..._RETRIES 0..8, default 2), runs the round again after the same restore when a window fails with NonFinite (verify, validation or output admission); other errors, a failed restore or take-back (then the original error, controller marked failed) and a window that stays non-finite after the retries behave as before. Each healed and unhealed window is logged (leleka-serve nan-guard: ...), counted (healed= in DBG spec-stats) and published in the telemetry document (nan_guard.healed_windows, unhealed_windows, last: leleka-memory telemetry::nan_guard_healed/unhealed). LELEKA_ORIGINAL_SERVE_NAN_INJECT=n[xK] (upstream STRATA_NAN_INJECT) makes the n-th checked window read as non-finite K times after it ran well. The fake-engine tests of 2026-10-26 were not enough, the live stack found two more things the guard has to undo: (1) a completed window that no commit was enqueued for keeps window_ready and an armed QSA journal in the driver, so the next run answered InvalidQwenShape (Failed(InvalidDimension): first live G1, run in original_verify_schedule.rs); (2) the window also leaves state behind that only the commit graph repairs: the PLE history (advanced row by row, set from the kept row's snapshot at commit) and the index tails/spare row, so a rerun that only cleared (1) completed but differed from the refused window (first row -0.000392 against -0.000368, another value for every further rerun, the same values in four processes). Now OriginalSpecEngine::discard_window (port discard_window, driver OriginalVerifier::discard_window and OriginalVerifyQsaJournal::discard_window) runs after the two restores: the journal writes back the index state and the PLE history it read when the window began (set_window_snapshots, on only when the guard has retries: twelve small reads and one 360 KB read per window) and the verifier takes the window back. Not healed: a non-finite value the driver detects inside run (stage checks, logits scan) releases the verifier (abort_gpu_waits), so the retry's discard fails and the request ends with the original NonFinite as before; and the cases of the next paragraph. Details: docs/upstream-port-numerics.md. Tests (server, cargo test --release): leleka-runtime lib 567 passed, leleka-memory lib 84. In original_spec_controller, the fake engine now refuses a window while a completed one is outstanding (as the driver does) so the retry tests fail without the take-back: the_retry_takes_the_refused_window_back_before_it_stages_the_rows_again (order: drain, both restores, take-back, same rows), a_window_that_cannot_be_taken_back_ends_the_healing_with_the_original_error, plus the 2026-10-26 set (the_guard_reads_its_three_switches_and_refuses_a_malformed_one, a_non_finite_window_is_run_again_from_its_checkpoint_and_the_request_completes, the_guard_costs_nothing_when_nothing_is_wrong (identical engine call log with the guard on and off), a_window_that_stays_non_finite_fails_the_request_after_the_retries, only_a_non_finite_failure_is_retried_and_a_guard_that_is_off_retries_nothing, a_checkpoint_that_cannot_be_restored_ends_the_healing_with_the_original_error, the_injection_exercises_the_same_path_on_a_good_window_and_counts_windows_across_requests); in original_serve_engine: a_refused_window_is_taken_back_only_after_it_drained_and_a_failed_take_back_poisons. Live (RTX 5090, binary rt-guard4 = this tree, guard on, jobs up3f-w1, up3h-det, up3g-def; runs ~/work/gpu-runs/quality/runs/Q8-D-*, Q8-H-W1-*, Q8-H-*; earlier attempts Q8-G1-*, Q8-G1b/c-*, Q8-G2b/c-* kept as the failure record): all 12 runs rc=0 with the nan-guard lines (G1 = window 7 once, G2 = window 25 twice; the injected window's position depends on the window cuts of that run: 122/132/133/126/113). Deterministic arm (LELEKA_ORIGINAL_SERVE_CPU_WORKERS=1 LELEKA_SPEC=4 LELEKA_SPEC_SUFFIX=0: one CPU expert worker, the fixed window, no timing-driven suffix choice): the control, G0 twice, is bit-identical in all 546 window blocks and all 711 forced rows; G1 and G2 equal G0 in every one of the 546 window blocks once the refused window is dropped (forced rows: 711 identical, 0 different, 0 argmax flips, q_pair.py), and every rerun is bit-equal to the window it replaces (rerun_check: G1 1 of 1, G2 2 of 2). Default tier (15 CPU workers, adaptive window): not bit-reproducible between processes, so only the envelope can be read: the control G0a/G0b has 215 of 514 common rows identical, max d_top1 0.166, p99 0.120, 2 argmax flips; G1 against G0b 58/483, max 0.362, p99 0.152, 6 flips; G2 against G0b 49/452, max 0.243, p99 0.159, 5 flips; (the earlier control of two runs of the unguarded build, Q8-A1-old against Q8-A2-old: 51/506, max 0.367, p99 0.131, 12 flips). Every rerun in G1 and G2 is bit-equal to its refused window here too. Default stays OFF (NanGuard::DEFAULT_ON): the unit test shows the guard changes no engine call when nothing fails, but the snapshots cost reads per window and the guard-on speed was not measured (no performance claim). Not covered: a non-finite prefill chunk (the deferred prompt guards poison the CUDA context by design, so there is nothing to retry on), a failure after the commit was enqueued, a real driver-detected non-finite inside run (see above), and upstream's gateway retry from token 0 |
Phase 2: decode speed, bitwise (no change of output)
| # | Item | Action | Gate | Status |
|---|---|---|---|---|
| 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 | 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)
| # | Item | Action | Gate | Status |
|---|---|---|---|---|
| 3.1 | Route tail skip (65268d99, b4e3407b, 6ab541f6, 55e2072c): a missed expert that every token of a window routes at rank >= 7 is neither copied nor computed; claimed +10..20 % decode on 12-16 GB cards, +11.5 % on a 5090 (NVFP4) |
port into the CPU-pool/stream path behind LELEKA_ROUTE_TAIL_SKIP=N, off at >= 90 % cached |
R, Q (KL) | implemented, experimental, default OFF; +15.2 % decode on the 9e3 replay but the quality gate FAILS; see Results |
| 3.2 | Fused int8 prompt experts (959e6c34, b1e0fdaa): prompt +7/+5/+3 % at 4K/20K/98K |
experimental prefill flag | R, Q | todo |
| 3.3 | PcieAuto (pcie_frac from the measured CPU speed), async tier by measurement, ADAPT_LAG (aa7b0cb1, ab97f174, b18700c8, b437b8ea, d69424c9) |
compare with our DMA-mode share (0.45) and adaptive swaps | R | todo |
| 3.4 | Chunked GDN prompt recurrence (0f78032f), speculation extras (cost-aware window, probabilistic acceptance, DFlash2, lookup chain) |
opt-in experiments | R | todo |
Results of the 2026-10-26 session (branch claude/upstream-speed, server rnr5090, RTX 5090 + Ryzen 9 9950X3D, driver 595.99.02, CUDA 13.2, test binary rt-a1 sha256 6e5bbc24..., pinned Qwen3.8-Flash-Next IQ3_S pack + KAR level-2 PLE)
Row 0.6 callback-thread affinity
- Microbench (synthetic; job
upspeed-06-cbaff-micro, upstream'scuda_callback_affinity.cpp, separate processes, 10 rounds interleaved): the effect is real on this machine. Lazy creation after pinning: median 988-989 us per callback (9 of 10 processes; one process 6.7 us). Warm-up before pinning: 1.7-6.8 us. - Our code does not hit it. (a) Flag B of
fetch_dmais raised bycuStreamWriteValue32on Linux (original_gpu_schedule_ffi.rs::raise_flag_after; a host callback only withLELEKA_PCIE_FLAGB=host, the WSL default, or when the driver refuses the write), so the default 5090 decode launches no host function and the driver creates no callback thread. (b) WithLELEKA_PCIE_FLAGB=hostthe callback thread exists but is created before the host thread pins itself:publish_gpu_planof the first window group enqueues the host function beforeDirectCpuPool::compute_grouppins the caller (pin_caller, CPU 0). Measured with a thread listing during decode (jobupspeed-06-threads, 3 requests of 9e3, FLAGB default/host x warm-up off/on): host thread mask0, expert workers masks1..15, every driver thread (cuda...,cuda-EvtHandlr, and in the host-flag runs the callback thread, named after its creator) mask0-31; no callback thread on CPU 0 in any run. - Decode tok/s of request 2 (9,556 tokens), two passes each, not a paired A/B: default/off 172.2, 174.5; default/on 173.2, 178.7; host/off 170.7, 173.9; host/on 168.4, 174.8. The mechanism is absent in both arms, so the 30-pass A/B was not run (it would measure noise).
- Kept: one no-op
cuLaunchHostFunc+cuStreamSynchronizeat the creation of the first stream (Linux only; Windows CPU sets are per thread), so a later change of the call order cannot reintroduce 1 ms callbacks. A guard, not a speed-up. Not verified: WSL (laptop route A), where flag B is a host callback by default.
Row 3.1 route tail skip (LELEKA_ROUTE_TAIL_SKIP=N, EXPERIMENTAL, default OFF, output changing)
Port: split_group_tail (original_serve_residency.rs). A missed expert (not resident, valid id) whose best rank over all entries that route it is >= N gets kind -2: not in the GPU plan, not staged over PCIe, not computed by the CPU pool, row zero (the CPU writes zeros for every entry it does not own), route weights not renormalised; skipped experts leave the miss count before the PCIe share is rounded. Off when at least LELEKA_ROUTE_TAIL_SKIP_MAX_CACHED (90) percent of the experts are in VRAM (21.5 % are here, so it is ON). Router ids are sorted by descending probability (router_top10.cu), so slot = rank as upstream. Unit tests in original_serve_residency (11 pass on the server). Replay arms: +tailN suffix of a LELEKA_SPEC_ARMS entry (in-process pass-level A/B), !tailN flag of a LELEKA_REPLAY_ARMS entry (per stack).
- Speed, end to end (job
upspeed-31-ab-9e3; one process; live CRM session capture 9e3, 24 requests, 34,443 recorded tokens per pass, teacher forced; auto tier 9,100 slots per layer, adapt-every 2,LELEKA_CHAIN=all, adaptive window @ 0; one warm-up pass, then 3 repetitions x 2 arms, arm order rotating): A (skip off) 167.00 tok/s (passes 166.93 / 166.89 / 167.17, sd 0.15, 95 % CI +-0.38) against B (skip 7) 192.38 (192.36 / 192.32 / 192.45, sd 0.07, CI +-0.17). Paired gain +15.2 % (15.23 / 15.24 / 15.12, sd 0.07). Rounds per pass 8,744 against 8,648; the skip removed about 1.01 M entries per pass of about 19 M (roughly 44 % of the entries the CPU and PCIe tiers would otherwise serve). n = 3 per arm, not 30: the queue was shared (the job started 3 hours after submission) and the pass-to-pass sd is 0.1 %, far below the effect; the job was stopped after the third repetition. Not measured: the 256k-class capture 9w2 (jobupspeed-31-ab-256kwas prepared, never reached the GPU and was removed from the queue); a 12-16 GB card (laptop commands are indocs/windows.md). - Quality (jobs
upspeed-31-q-autoand-ctl; teacher forced along the 9e3 recording, first 16 requests, 32,331 rows, top-16 log-probabilities, static auto tier, seed off, arms G = skip off and T = skip 7 in one process, control = the same reference with another chunk cut (4096);scripts/quality/q_tail_gate.py):
| d_top1 p99 | d_top1 max | argmax flips | |
|---|---|---|---|
| control (chunk cut, rounding noise) | 0.3995 | 3.37 | 470 (1.45 %) |
| skip 7 against skip off | 1.0050 | 5.81 | 895 (2.77 %) |
| limit (1.25 x control) | 0.499 | 4.22 | 1.81 % |
FAIL on all three (and outside the Original envelope 0.22 / 0.43 / 2.8 % for p99 and max). A +15 % decode gain that costs 2.5x the p99 deviation of rounding noise stays an experimental flag: not to be enabled in any profile. Not tried: rank 8 or 9 (fewer experts skipped), the 2048-slot tier (upspeed-31-q-2048, never ran), a downstream answer-quality check. Upstream's own gate was KL 0.003-0.006 on other packs; ours is another pack and another measure, the numbers are not comparable.
Row 2.3 CPU expert rows
The four upstream changes were checked against what our crate runs (crates/native-cpu-expert is Rust; its .cpp files are references):
- router accumulators in registers (
router_dot): used only by the router lookahead, which is opt-in (LELEKA_CPU_POOL_LOOKAHEAD=on) and only over file-mapped experts; it does not run in the 5090 decode. - Q5_1/Q8_0 down-row dots: our
DownFormatisIq4Nl | Q2_0and the IQ3_S pack's down matrices are IQ4_NL, so no row would use them. - 512-bit gathers: upstream enables them only on GenuineIntel parts with AVX-VNNI (Alder Lake, Sapphire Rapids and later,
cpu_gather_fast) and measured them slower on Zen 4. The 9950X3D is AMD and the laptop's i9-11900H (Tiger Lake, AVX-512 without AVX-VNNI) does not qualify either; our crate already has the opt-inSTRATA_IQ_GATHER. - default worker count: ported as
pool_plan(plan_pool_workers, upstream's mock-CPU test cases, cgroup quota, hybrid P/E counts; 7 tests pass on the server;default_workers()= 15 on the 9950X3D, equal to the stack's constant, so there is nothing to A/B on the 5090). Opt-inLELEKA_CPU_POOL_PLAN=on; on the laptop it would give 7 instead of 15 (8 of 15 workers have no core of their own there), unmeasured; commands indocs/windows.md. No scalar-reference row tests were written because no row kernel changed.
Rows 2.1 / 2.2
Diff list above; no implementation, nothing measured.
Not verified / not done
The 30-pass A/Bs (3 repetitions for 3.1, none for 0.6 because the mechanism is absent), the 256k-class A/B, the 2048-slot quality gate, anything on the laptop GPU. cargo build/test was not run on this laptop (by instruction); all builds and unit tests ran on the server from a tarball of the worktree.
Rows 2.4 / 2.5: analysis (2026-10-27, branch claude/upstream-rest, from claude/port-gpu-bringup c40531f)
Method: read the upstream sources (engine/strata/src/prefill/kernels.cu, src/kernels/cuda/qsa_select.cu, moe_mmq.cu, prefill.cpp) against ours (crates/cuda-driver/src/prefill_stage.cu,
qsa_late.cu, qsa_resident_index_program.rs, the sealed qsa_prompt_select.ptx that the decode window launches as qsa_topk_ref). The upstream repository has no history in our tree, so the
commits are identified by content. Where the 256k workload stands (night5-long-256k, job on 2026-10-27, 5090): a 5-turn session to 243k tokens has TTFT 25.2-30.6 s per turn (chunk 2048,
per-layer ring: expert DMA dominates, 0.8-1.1 s of a ~1.2 s chunk) and decode 80-103 tok/s against 130-170 at short context. Two different things can move at depth: the prompt stages whose
cost grows with the position (QSA index: scores, top-k) and the decode window's QSA select (one qsa_topk_ref CTA per query, 12 layers).
| Item | Upstream | What we have | Verdict |
|---|---|---|---|
GDN recurrence, 3 value heads per thread (4e69f974) |
gdn_rec_kh_kernel: 64 blocks, cp.async blocks of 8 tokens, 2 barriers per token |
the Original's gdn_rec_cols_pipe (192 blocks, 5 barriers) and our opt-in two-barrier leleka_prefill_gdn_rec |
ported (leleka_prefill_gdn_rec_kh, opt-in): bit-identical, but only -6 % per launch on the 5090 (see Results); 64 blocks on 170 SMs leaves the card two thirds idle |
| no dead FP32 store in the GDN output norm | gdn_out_norm without the y store |
leleka_prefill_gdn_out_norm writes y (nothing reads it afterwards: the projection takes y16) |
ported as leleka_prefill_gdn_out_norm_y16, bit-identical y16 and status words |
quantize each token's MoE input once, scatter to the K rows (c675f5b7) |
quantize_scatter_mmq_q8_1_cuda instead of a gather over T*K rows |
ggml quantize_mmq_q8_1 with the id gather over T*K rows (sealed Original MMQ asset) |
not ported: upstream's own number is 77.5 -> 58.1 ms for a 32K prompt on a 5090, i.e. at most ~5 ms of an 8192-token chunk (0.3 %), and it needs a new kernel in the MMQ q8_1 layout plus the inverse slot map |
DEQUANT_WIDE (5f843a92) |
wide dequantization of Q4_K/Q5_K/Q6_K/IQ4_XS, default on sm_86/sm_61 only | our leleka_prefill_dequant_* already run one thread per element (9 ms per chunk on the 5090, 36 ms per 2048-token chunk on the 3080) |
not applicable to sm_120; a thread-per-8-values variant could only matter on the 3080 (not measured) |
QSA top-k, 1,024-thread kernel past ~135K cells (586367cb) |
block_topk_wide_kernel (per-warp histograms, 4 radix passes + count + emit) |
qsa_topk_ref (Original, 256 threads, 704-byte stride between lanes) and our leleka_qsa_topk_fast (256 threads, coalesced, 6 passes) |
ported, faster than fast from ~10k blocks (-45 % at 180k, -49 % at 245k per 256-row tile); upstream's one-read sample kernel measured and not used |
QSA top-k on a thread-block cluster, sm_90+ (d05d26e9) |
block_topk_cluster_kernel: 8 CTAs of 1,024 threads per query, histograms pushed through distributed shared memory |
the decode window launches qsa_topk_ref with one 256-thread CTA per query (12 layers per window) |
ported (qsa_cluster.cu, cuLaunchKernelEx inside the captured window): 183 -> 19.5 us per call at 245k tokens (4 queries) in the model-free probe |
cluster greedy argmax (6ef23b89) |
sampler.cu |
one block per token, 79 us per window (docs/chain-kernels.md) |
row 2.1/2.2 item, tier 2 |
Project Maya (github.com/Ajay9o9/project-maya, MIT; analysis 2026-10-27, owner's request)
A Strata fork rewritten for GLM-5.3-Flash (321B MoE, DSA sparse attention, KDA layers, NextN MTP). Read: the README and the sources at commit 10b7b07 (shallow clone kept outside the tree; the
code that matters is src/core/glm_fast_path.cu, glm_prefill.cu, src/kernels/cuda/glm_batch.cu, src/kernels/cpu/kq_avx512.cpp, src/program/generate.cpp). Every number below is Maya's claim on Maya's
hardware (3090, V100, 4090, GLM), not ours. Their model is not ours: the indexer has 32 heads, the MTP block is a GLM NextN block with RAM-tier experts, the expert formats are Q3_K/Q2_K. Ranked by
expected value for the Qwen3.8-Flash-Next IQ3_S pack on the 5090 (primary) and the laptop:
| Rank | Candidate (Maya switch) | Maya claims | What we have | Verdict |
|---|---|---|---|---|
| 1 | (g) Next-layer expert prestaging while attention runs (STRATA_GLM_PRESTAGE, prompt ring; PREFETCH_N/RANK/AT for decode), (f) conversation state on SSD (STRATA_GLM_SLOTS: 4K tokens resume in 0.2 s instead of a re-read) |
prefetch decode 19.64 -> 20.22 tok/s on 3090+3060; no number for prestage | prompt: the per-layer ring plus stream_all from 4096 rows (already overlaps the next layers' DMA with the mixers); decode: router lookahead (LELEKA_CPU_POOL_LOOKAHEAD, opt-in), adaptive tier. Prefix cache and conversation cache are RAM only |
(f) is the one with a 256k payoff: a 245k re-read is 25-40 s of TTFT (night5) against seconds from an SSD slot; it is the tiered-cache epic STRA-236, not a kernel port. (g): small; the stream already does it above 4096 rows; for chunk 2048 the per-layer ring could prefetch layer l+1's routed set only after its router runs (the same limit Maya has). Not started |
| 2 | (d) Multi-token AVX-512 Q3_K/Q2_K CPU kernel (kq_avx512.cpp, STRATA_GLM_KQ, ~2x ggml from 8 tokens per expert) |
prompt-path CPU experts | crates/native-cpu-expert: IQ3_S/IQ4_NL (our pack) and Q2_0 kernels with RUNTIME dispatch AVX2 (iq_avx2, q2_avx2) / AVX-512 (iq512, avx512_ok(): F/BW/VL/DQ + XCR0) |
does not apply to our pack: Maya's kernel is for Q3_K/Q2_K weights and for prompt-path CPU experts; our prompt experts run on the GPU (MMQ) and decode has 1-4 tokens per expert, below Maya's break-even of 8. What it exposes is a gap in our CPU tiers (next paragraph) |
| 3 | (a) Sparse-attention indexer as FP32 register-tiled GEMM (STRATA_GLM_DSA_SCORE, 78.8 -> 5.6 ms at 4096 tokens, position 10K, 3090) and the mma.sync prompt attention (STRATA_GLM_PREFILL_ATTN, 832 -> 966 tok/s at 26.6K) |
against Maya's warp-per-pool kernel | our indexer scorer is already the Original's TF32 3-pass tensor-core kernel (block_scores_tc_kernel, 0.34 ms per 256-row tile at 147k tokens) and the prompt attention is already mma (113 ms per 8192-token chunk, ledger); the select was the top-k, now ported (row 2.5) |
already ahead of the baseline Maya fixes; folded into row 2.5: after the wide top-k the late-chunk QSA index is scores 131 + top-k ~45 ms of ~1.9 s. The tile size and 3xTF32 split of the scorer (7 TFLOP/s on 2.4 GFLOP) are the only headroom; not bitwise-safe to touch (the Original's score bits decide near-tie selections) |
| 4 | (c) Promotion of a fetched hot RAM-tier expert into VRAM only when its aged route count clears PROMOTE_MIN |
stops churn on a 4090 with 128 GB RAM; hurts with little RAM (29.6 -> 28.3 tok/s on 30 GB) | adaptive swaps (ADAPT_EVERY/SWAPS): replace the least-routed residents of a layer while the gain >= 1.5, counts decay 0.7 (hysteresis already) |
equivalent mechanism; revisit only if the e2e traces show swap churn at 256k (job 9r1 / telemetry swaps). No port |
| 5 | (b) Draft-expert filter (STRATA_GLM_MTP_KEEP: the NextN draft fetches only its best-scored missing experts) |
acceptance 76-81 -> 82-83 %, decode +5 % on 3090+3060 | the Qwen MTP block's experts are one n_expert * BLOB device allocation (original_mtp_bank.rs): the draft has no misses |
not applicable on the 5090 and (if the MTP bank is device resident there too) on the laptop; to be re-checked on the 3080 profile (docs/laptop-profile.md) before closing |
| 6 | (e) Idle spin sleep for pool threads (SERVICE_IDLE_MS) |
idle engine 1 % of a core instead of one core per GPU | rust_general_pool.rs workers spin self.spin and then park on a condvar; pool_plan sizes the workers to physical cores |
already have (not measured idle CPU here) |
CPU tiers (owner's rule: runtime dispatch, the AVX2 path stays the default and keeps being tuned, bit-identical integer dot products, nothing requires AVX-512 at build or run time). State of
crates/native-cpu-expert on 2026-10-27, from the sources (no CPU measurement made): (1) AVX2 baseline: present for IQ3_S/IQ4_NL/Q2_0 (iq_avx2.cpp, q2_avx2.cpp, kq_avx2.cpp,
rust_simd::avx2_ok); (2) AVX2 + AVX-VNNI (256-bit vpdpbusd): missing as a runtime tier. rust_ggml_native.rs probes cpuid 7.1 EAX bit 4 but only as a compile-time cfg!(target_feature = "avxvnni") branch of
ggml's types, so the binary neither uses it on an Alder/Raptor Lake/Core Ultra part nor requires it; the IQ dot kernels use maddubs + madd; (3) AVX-512(+VNNI): present with runtime dispatch
(Dispatch.iq512, avx512_ok(); STRATA_FORCE_AVX2=1 forces tier 1), the Q2_0 S2 path in expert.cpp is the VNNI-512 reference. The decode CPU legs are memory-bound (about 39 GB/s of 52, expert.cpp
comment), so an AVX-VNNI tier saves ALU work, not bytes: expect a gain only where the pool is compute-bound (laptop, 8 workers on 4-6 cores). A tier 2 would be an additional #[target_feature(enable = "avx2,avxvnni")]
variant of the IQ3_S/IQ4_NL dots selected by cpuid 7.1 EAX bit 4 + XCR0, integer-exact against tier 1 (same int32 sums, so bit identity by construction), measured with rust_bench on the laptop: todo, not started.
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-driverlib 395 passed (--features "cuda-driver sm86"),leleka-runtimelib 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'sqsa_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, then_kv <= widthidentity branch included).leleka_prefill_gdn_rec_khequals the Original'sgdn_rec_cols_pipein 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 samey16and the same four status words (3 cases incl. non-finite inputs). - I, end to end (job
rest-id-256k, replay ofnight5-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_gateover 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_refvs 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_scoresis 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-256kreplayed 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). Decoderound.run_windowper 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_WIDEwere 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 (sized per-layer cache only: the defaults flip of the kernels had not reached the server) | 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 |
| rest-full1 (all branch defaults: sized cache + cluster decode top-k + wide prompt top-k + no-store out-norm) | 11.3 / 105.3 | 11.2 / 112.4 | 13.0 / 112.8 | 11.5 / 121.7 | 10.5 / 104.4 | 57.6 | 111.3 | 71.3 s |
| rest-full2 | 11.0 / 105.2 | 11.2 / 109.3 | 13.2 / 110.3 | 11.5 / 126.2 | 10.5 / 102.8 | 57.3 | 110.7 | 71.2 s |
night7 (global slots, PER_LAYER=no, night binary, owner's job) |
13.6 / 103.7 | 11.6 / 100.4 | 13.8 / 90.5 | 13.4 / 96.6 | 10.9 / 92.0 | 63.3 | 96.6 | 79.0 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 |
The first rest-after* pair measured the sized cache alone: I committed the defaults flip of the three kernels and then synced the server tree from git ls-files -m, which no longer listed the committed files, so those binaries still had cluster / wide / no-store off (found when the log line leleka-serve qsa prompt top-k was missing from the binary; sync-rest now diffs against the base commit). rest-full* are the real defaults, with the kernels confirmed by leleka-serve qsa prompt top-k: wide and qsa decode top-k: thread-block cluster in the engine log.
Findings (runs rest-before*, rest-after*, rest-full* 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):
- Chunk 8192 is the prefill fix (night5 -> night6: 134 -> 61 s of TTFT); it is not the default of the shipped deploy profile yet.
- Slot sizing, root cause.
run-e2e.sh(and thertx5090-32gprofileengine_env) setLELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER=yes.original_cache_startup::opentook the profile-sized path only for!per_layer; with per-layer it openedslotsslots 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 layerquotaslots 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=0restores 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 gaterest-q-256k. - Decode +28 % (mean over the turns 85.5 / 87.5 before -> 111.3 / 110.7 tok/s with all defaults): the sized cache alone gives +17 % (102.7 / 101.5;
round.run_window19.2 -> 18.4 ms per round, 697 rounds against 787), the cluster top-k adds +9 % (16.9 / 16.0 ms per round, i.e. -12 % against before; QSA decode select was 12 x ~180 us per window). Per-layer sized slots (102 tok/s) are as good as global admission (night7, 96.6 tok/s, old binary): the per-layer admission is not what held decode back, the slot size was. Still 1.4x behind vanilla (154.5 tok/s; its round is ~14 ms). Vanilla's route-tail skip (lossy, on by default) is not copied. - 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.ringdid not change when the resident slots went from 8,701 to 11,280 (the ring already skips the experts the arena cache holds; its entry count fell from 17,770 to 15,534 per chunk, but the ring is compute bound, not DMA bound: see the section on the prefill expert stream below, which corrects an earlier reading of this paragraph). Vanilla runs the prompt experts on the fused int8 kernels (STRATA_PF_FUSED=1, row 3.2, lossy). - The wide prompt top-k shows in the e2e as the QSA stage: 13.85 s (before) -> 12.99 / 12.98 s (full), -6.2 %, as in the replay; TTFT sum 63.8 / 59.2 -> 57.6 / 57.3 s (-5..-10 %, inside the turn-to-turn noise of 1-2 s). Prefill is untouched otherwise (moe.ring 15.4 s, gdn 14.7-15.2 s of a 54.4 s prefill total).
- Quality gate Q (job
rest-q-256k, replay ofnight5-long-256k, teacher forced, production env: adaptive tier, 15 CPU workers, chunk 8192, prefix budget 6,000 MiB, top-16 log-probabilities, 1,501 rows; Z0 = all branch defaults (11,280 slots, wide, cluster, no-store), P1 / P2 = before (8,674 uniform per-layer slots, fast top-k, ref decode top-k, store);q_tail_gate.py --ref 1): Z0 against P1: d_top1 median 0.0038, p99 0.186, max 0.417, argmax flips 30 (2.00 %); the run-to-run control P2 against P1: median 0.0036, p99 0.196, max 0.384, flips 34 (2.27 %). Rule (each <= 1.25 x the control): p99 0.186 <= 0.245, max 0.417 <= 0.480, flips 2.00 % <= 2.84 %: PASS; both are also inside the Original envelope (p99 0.22, max 0.43, flips 2.8 %). The kernels alone are bit-identical (gate I); the deviation is the placement change of the larger cache, and it is smaller than the noise between two runs of the old build. A first try of this job failed to open the second stack of the process (driver error: HostAllocationwith a 20,000 MiB prefix cache and a loaded host) and is kept asrest-q-256k.first-try.log. Same job, speed (not a paired A/B: logprob tracing slows decode): TTFT sum 56.8 s (Z0) against 57.2 / 57.1 s (P1 / P2).
The prefill expert stream is not what holds a chunk back (job rest-dma-diag, 2026-10-27 22:00)
Question: does the ring skip experts that are resident, and is the copy stream exposed (21 GB/s over the stream window against 47-50 GB/s isolated DMA)? Replay of the first 3 requests of night5-long-256k (21 chunks, 162,040 tokens, chunk 8192, production env, 11,280 slots, 2,238 lent), two processes:
- Resident experts are already skipped (
begin_stream_inner:lease.cache_expert_span(layer, expert)?.is_some()-> no entry). Entries per chunk = 24,576 - (slots - lent): 15,534 = 24,576 - (11,280 - 2,238); with the uniform 8,701 slots it was 17,770 (24,576 - (8,701 - 1,895)) and the bytes per chunk fell from 36.96 to 32.44 GB with the larger cache. Vanilla at 12,575 - 2,089 streams about the same (14.1k entries). The earlier statement "the ring streams whatever is resident" (this document, finding 4 above) was wrong:moe.ringdid not move with the slot count because the ring is not DMA bound (below). - A:
LELEKA_PREFILL_COPY_STATS=1(timestamp event around every entry, all 15,534 entries sampled):PREFILL-COPY mode=thread entries=15534 calls=46602 bytes=32444043408 avg_call=696194 dma_gbps=44.6 sampled=15534 issue_ms=102.6 stream_ms=1584.0 avg_gbps_over_stream=20.5(the other chunks: dma_gbps 44.5 / 45.3, stream_ms 1597 / 1079). The pure DMA time of the 3 x 686 KB copies of an entry is 44.5-45.3 GB/s, i.e. 0.73 s of the 1.58 s stream window: the copy engine is idle for more than half of the window. The 21 GB/s is bytes over the window, and the window is the chunk: the issuer waits for theusedevent of entry k - 512 (ring of 512 slots, one layer ahead), so it is paced by the compute. - B:
LELEKA_PREFILL_DIAG_SKIP_EXPERT_DMA=1(no expert copies at all, wrong outputs, compute only): stage sums over the 21 chunks A -> B: total 33,321 -> 33,495 ms, moe 15,221 -> 15,616 ms, gdn 9,388 -> 9,288 ms, qsa 6,965 -> 6,849 ms. Removing the whole DMA does not shorten a chunk, so there is no exposed copy time and no overlap, ring size, depth or 3-copies-per-entry change can buy anything (hypotheses a-d are moot;streamsync398 calls / 1.06 s per chunk is the host waiting for compute). - Where the 1.63 s of a chunk go (position 139k, host spans, GPU kernels sum to about 1.2 s): gdn 464 (compute 381, state_in 35, state_out 41), qsa 437, moe 653 (prepare 122, spans 26, ring 454, finish 38), input 30, validate 12, attn_read 7, the rest below 30. About 0.3-0.4 s are host-side serialisation points between the kernels (per layer: GDN state upload/download, the router / route grouping readback in
moe.prepare, the finite-span walk inmoe.spans,moe.finish), and the MMQ + gather + combine kernels of the ring (255 + 47 + 28 ms in the ledger table). Vanilla's chunk (about 1.37 s) runs the prompt experts on the fused int8 kernels (PF_FUSED, lossy, row 3.2) and has not been profiled per stage here. Next candidates, none started: (1) hidegdn.state_in/out(76 ms, 4.7 %: a per-layer synchronous host round trip of the recurrent state), (2) pipelinemoe.prepare(122 ms: route readback and grouping of layer l+1 behind the GPU work of layer l), (3) row 3.2 as an opt-in experiment.
Host-blocking calls of one prefill chunk, per call site (job rest-sync-sites, LELEKA_PREFILL_STALL_TRACE=1, chunk 8192, 2026-10-27)
compute_drain::timed now records every kind (alloc, free, H2D, D2H, memset, drain, D2D, stream/event sync) per call site, ranked by blocked ms (PREFILL-SITE lines at the end of each chunk). One chunk, PREFILL-COPY ... blocking: alloc=83/6.7ms h2d=240/13.2ms d2h=479/31.3ms drain=949/68.5ms streamsync=398/733.9ms, stream window 1,242 ms. The 398 cuStreamSynchronize calls (734 ms in this chunk; 951-1,060 ms in the 1.6 s chunks of the other runs):
| # | call site (innermost first) | calls | blocked ms | what it waits for | on the critical path? |
|---|---|---|---|---|---|
| 1 | OriginalGdnPromptDevice::produce (end of a GDN layer) |
35 | 241.7 | the layer's GEMMs, conv, recurrence (GPU running) before the state download | the GPU is busy while it waits; after it returns the GPU idles through state_out (download, seal, stage) and the next layer's state_in (alloc + upload): about 76 ms per chunk |
| 2 | copy_ring::Ring::drain <- finish_statuses (end of a MoE layer) |
48 | 196.4 | the layer's gathers + grouped MMQ before the status words are read | GPU busy while waiting; then moe.finish (38 ms) and the next layer's moe.prepare run with an empty compute stream |
| 3 | QsaPromptIndexWorkspace::run_resident_arena (indexer: scores, top-k) |
12 | 89.1 | the 32 score + top-k tiles | GPU busy; the host then validates the selection |
| 4 | QsaPromptAttention::run_resident (attention) |
36 | 74.1 | attention kernels of 3 sub-steps per QSA layer | GPU busy |
| 5 | OriginalMoePromptDevice::run via prepare (kind 5 drain) |
92 | 53.1 | router, top-k, sort before the ids are read back to the host | needed: the host groups the routes of the layer from them |
| 6 | OriginalQsaPromptDevice::project |
60 | 29.4 | indexer q/k projections | GPU busy |
| 7 | OriginalMoePromptDevice::run (prepare / finish) kind 7 |
46 + 46 | 28.4 + 22.0 | router logits / combine | GPU busy |
| 8 | Transfer::copy (resident index copy of the prefix, KV copy_prefix) |
12 | 22.6 (+13.2 drain) | DMA of the whole prior index/KV prefix into the arena | grows with position |
| 9 | the remaining ~20 sites (D2H of flags and routing ids 479 calls / 31 ms, alloc 83 / 6.7 ms, GDN copy_from 35 / 10.7 ms, GdnChunkDevice::new allocations 70 / 5.5 ms) |
~60 | small copies and allocations | the D2H of the MMQ finite flags (48 / 18 ms) and the GDN state download (35 / 7 ms) block the host behind the layer |
Reading: nearly all of the 734 ms is the host waiting for kernels that are still running, so most of these syncs do not by themselves idle the GPU. What idles it is the host-only work after a sync returns and before the next layer's first launch: per chunk gdn.state_in 35 + gdn.state_out 41 + moe.prepare 122 (of which 53 is the drain of site 5) + moe.spans 26 + moe.finish 38 + input/validate/QSA host bookkeeping, i.e. the 0.3-0.4 s between the kernel sum (about 1.2 s) and the chunk (1.6 s). The in-situ DMA is 44.6 GB/s (gate above), so the "22 GB/s" of the stream window is the window, not the engine. Removing these syncs is not a matter of deferring status words: sites 1, 2, 5 gate the host's own next step (the route ids, the download of the recurrent state, the status words of the layer). It needs the host work of layer k+1 (router readback and grouping, state upload) to overlap the kernels of layer k, which is a double-buffered restructuring of prepare / produce / finish; not started. The exact deferral that exists is LELEKA_PREFILL_DEFER_GUARDS (on).
Is there 0.3-0.4 s of host-only time per chunk to pipeline away? (job rest-gdn-laps, LELEKA_PREFILL_PROFILE_SYNC=1, chunk 8192, 2026-10-27)
With every span drained (so a span shows its own GPU + host time) the chunk is 1,558 ms against 1,631 ms undrained: the drains cost nothing, the work is a serial chain. The same chunk (position 32k):
| span | drained ms | undrained ms (139k) | what is in it |
|---|---|---|---|
moe.prepare |
47.6 | 122 | router + top-k kernels, route-id readback, host grouping. The 122 ms of the undrained run contain the wait for the GPU work queued before it (attention / FFN reads, injects are asynchronous there: 7 ms each undrained, 70-83 ms drained) |
moe.spans |
25.7 | 26 | pure host loop over the ~512 experts of the layer (bank spans, descriptor checks) |
moe.finish |
38.0 | 38 | combine kernels + status read |
gdn.state_in / state_out |
24.5 / 37.0 | 35 / 41 | per layer: chunk start + 8,192 row keys 16.0 ms, state upload / alloc 8.4, seal (row edges) 8.7, owner.finish (3.1 MB download, finite scan of the host copy, mirror adopt) 28.2 |
GPU time of the chunk, summed over its commands (PREFILL-COMMANDS, includes the per-command launch overhead of the drained profile): GDN 369, QSA 275 + index 79 + KV 22, GR read / inject 184 (readn 124: gr_mix_r 48, three GEMMs 72; injectf gr_write_norm_rs 56), MoE (MMQ + gather + combine, ledger) ~330: about 1.27 s of the 1.56 s. So the GPU idle time is about 0.3 s, but the purely host-side items that a pipeline could hide add up to about 100-120 ms (state_in 25 + state_out 37 + spans 26 + the host part of prepare ~35 + input/validate/init ~30); the rest of the idle time is launch latency inside chains of small kernels. The cheap host trims that need no redesign (skip the finite scan of an already validated mirror-resident state, reuse the row keys across the 36 GDN layers of a chunk, pool the 3 MB state buffer) are worth about 20-30 ms per chunk (1.5 %), below the 1-2 % noise of a paired A/B. Hiding the rest means keeping layer k+1's route readback / grouping and state upload in flight under layer k's kernels, i.e. double-buffering ownership types that are single-owner by design (GdnChunkStart / GdnChunkRow capabilities, OriginalMoePromptLayer): large, and its ceiling is ~7 % of a chunk. Not started; a better lever is the GR read / inject pair, 180 ms of bandwidth-bound passes over the 335 MB residual (R is 4 streams x 8192 x 2560 x 4 B) that run at 2-3x their traffic floor: bit-identical fusion / re-tiling candidates (gr_mix_r, gr_write_norm_rs, the three read GEMMs) with a model-free byte-compare probe, no ownership changes.
The hyper-connection kernels of the prompt are on their traffic floor (model-free probe, 2026-10-27 22:05)
prefill_stage_gr_gpu::gr_kernels_run_near_their_traffic_floor_at_chunk_size (T = 8192 rows, R = 335.5 MB, 20 warm launches; the byte-compare probe gr_fused_guards_equal_the_separate_guard_kernels_bit_for_bit already exists and passes: 4 cases, outputs and flag words equal the Original's kernels + separate guards). Achieved bandwidth of the three kernels that make up readn / injectf (the RTX 5090's DRAM peak is 1.79 TB/s, about 1.5-1.6 TB/s is what a streaming kernel sustains):
| kernel | us per call | bytes it must move | achieved |
|---|---|---|---|
leleka_prefill_gr_norm_rs (R in, xn16 out) |
318 | 503 MB | 1.58 TB/s |
leleka_prefill_gr_mix_r (R and g in; mixed f32 + bf16 + f16 out) |
523 | 839 MB | 1.60 TB/s |
leleka_prefill_gr_write_norm_rs (R in and out, bo in, xn16 out) |
616 | 923 MB | 1.50 TB/s |
The "floor of 18 ms per pass" quoted before counted only one read of R: mix_r also reads the 335 MB gate tensor g and writes three images of mixed, write_norm_rs reads and writes R. Against their real traffic the kernels run at 84-89 % of the DRAM peak, so no re-tiling or fusion of these kernels can buy more than ~10 % of their 180 ms per chunk (about 5-8 ms), and the three GEMMs of readn (72 ms) are cuBLAS calls whose algorithm cannot change without changing bits. Same for the other large passes: the GDN convolution reads and writes the 335 MB h (0.47 ms per call against a 0.4 ms floor). The 8192-token prompt chunk is therefore bound by the memory traffic of fp32 activations 10,240 wide plus the serial host/GPU chain measured above; the only remaining bit-identical savings are the host trims (20-30 ms) and the launch latency of the small-kernel chains. Reducing the bytes (bf16/f16 activations, fused int8 prompt experts) changes numerics and is row 3.2 territory. No code changed for this item.
GPU idle-gap anatomy of one steady chunk (CUPTI, job rest-cupti-chunk, chunk 8192 at position 139,264, 2026-10-27 22:35)
Method: tools/cupti-trace injected into the replay (night5-long-256k, production env, branch defaults), a 7 s window opened when the previous chunk finished, scripts/profile/lct_report.py --stamps ... --chunk 1 for the window and the new scripts/upstream-rest/gap_anatomy.py for the causes (a gap = no kernel of ANY stream runs, at least 20 us; the cause is the first that applies: an expert copy completing within 4 us before the gap's end = copy-wait, a blocking host call covering 30 % of it = host-sync, launch calls covering 30 % = launch-bound, else host-gap). The traced chunk takes 1,841 ms (1,631 ms untraced: CUPTI adds ~12 %), 52,097 kernel launches, 47,944 copies. Port only: no Original trace of this chunk exists (the ledger's old 16k / 180k traces of the Original are from before the stream and the sized cache).
- GPU busy (union of all streams) 1,411.5 ms = 78.3 %, idle 392.0 ms = 21.7 %; gaps >= 20 us: 1,698, 373.6 ms (smaller gaps 18.4 ms). H2D copy engine busy 738 ms (40 %) at 46.4 GB/s over 32.5 GB in 46,746 copies, 69 % of the copy time overlaps kernels.
- By cause: host-gap 177.0 ms (9.8 %), host-sync 105.4 ms (5.8 %), copy-wait 75.2 ms (4.2 %), launch-bound 16.1 ms (0.9 %).
- Top sites by total idle ms (previous kernel family -> next, cause; per chunk):
| # | idle ms | gaps | site | cause | what it is |
|---|---|---|---|---|---|
| 1 | 56.2 (+6.4) | 33 | gdn_prefill_finite_f32 -> gr_scan |
host-gap | end of every GDN layer: seal, 3.1 MB state download, host finite scan, mirror adopt, stage (gdn.state_out) |
| 2 | 51.1 (+5.6 sync) | 47 | moe_prefill_finite_f32 -> mmq_zero |
host-gap | between a MoE layer's router/finite kernels and its first MMQ launch: route readback, host grouping, the finite-span walk (moe.prepare + moe.spans) |
| 3 | 50.1 | 769 | mmq_gather -> mmq_gather |
copy-wait | the compute stream waits for the copied event of the next expert (the DMA is behind compute for ~1/3 of the layer's entries) |
| 4 | 36.4 + 16.0 + 9.9 | 12 + 16 + 9 | qsa_index_scan -> kv_guard / qsa_scan_half / rms_rows |
host-sync / host-gap | per QSA layer (12): the stage copy of the whole prior KV prefix (147 MB at 46 GB/s = 3.2 ms) and its drains, kv copy_prefix in append_resident_arena, in the compute stream between the indexer and the attention |
| 5 | 20.8 + 12.3 + 10.9 | 306 + 48 + 44 | mmq_gather -> mmq_gather, mmq_finite -> mmq_gather |
host-gap | host issue of the per-expert gather launches (24,014 gather kernels of 2.8 us) |
| 6 | 17.7 + 10.5 | 13 + 4 | mmq_finite -> moe_prefill_combine |
host-sync / copy-wait | the layer's status drain before the combine |
| 7 | 14.3 (+7.7 +6.6) | 31 | gr_mix_r -> gdn_prefill_zero |
copy-wait / host | start of a GDN layer: chunk start, row keys, 8.4 ms of state upload / alloc |
| 8 | 5.4 | 8 | gr_mix_r -> qsa_scan_half [cuMemAlloc] |
host-sync | allocations in the QSA layer start |
Blocking calls overlapping the gaps: cuMemcpyDtoH_v2 229 gaps / 137 ms (498 calls per chunk: route ids, flags, the GDN state), cuStreamSynchronize 166 / 97 ms, cuMemcpyHtoD_v2 32 / 27 ms, cuMemAlloc_v2 20 / 18 ms.
Verdict. Launch latency inside chains of small kernels is not the problem (launch-bound 16 ms = 0.9 %; 52k launches cost the CPU 157 ms at 3 us but they are queued ahead of the GPU), so capturing per-layer small-kernel chains as CUDA graphs buys at most that 0.9 %; graph capture is not worth the ownership changes. The idle time is host work between dependent GPU phases (about 280 ms of 392 ms in the traced chunk, ~250 ms untraced, 15 %): GDN layer boundary 62 ms, MoE route readback + grouping + gather issue 100 ms, QSA prefix stage copy and drains 65 ms, status drains 28 ms, plus expert copy waits of 75 ms. None of them is a single removable item above the 3 % bar that is bit-identical without restructuring: the largest candidates are each 3-4 % and each needs a double-buffered owner (a second KV stage for the QSA prefix copy, which the Original lays out once in the shared arena; a second GDN state / row-key set; an asynchronous route-id readback with the grouping of layer k overlapping the kernels of layer k-1).
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.
DeepSeek-V4.1 engine: separate plan after this one (digest part 2; needs the disk work already done on the server, /data).
Rows 2.1 / 2.2: what upstream has that our window does not (diff list, 2026-10-26; no implementation)
Method: read the resulting upstream code (engine/strata, commit 41cf05a0) against our chain kernels (crates/cuda-driver/src/chain_window.cu, docs/chain-kernels.md) and the sealed Original window kernels,
which are the OLD upstream pin (so the old pin has none of sub16, up75, down_tg, SIDE_MIXER, COMMIT_BATCH, HEAD_MIX_MULTI, SH_FORK, native_qsa_rms_norm_rope). Every gain below is an
estimate from our own per-family microseconds (ledger section 5, docs/chain-kernels.md 2.4; chain 12.6 ms and round about 25 ms per 4-row window on the 5090), not a measurement; upstream's own
numbers are claims on other hardware (RTX PRO 5000, sm_86 cards). Nothing here was run. Re-sealing PTX (sm_120 and ptx-sm86) is a fixed extra cost for every item marked "seal".
| Item (upstream switch) | Our status | Estimated gain per window | Effort | Numerics |
|---|---|---|---|---|
GR_DOWN_TG=1 |
HAVE, better: chain_gr_down_t2w8_nb4 (9.7 us against the Original's 18.4 us at T=4) |
none | - | - |
| multi-token router, multi-token GR read/write | HAVE: the old pin already batches them; our chain GR is the better one | none | - | - |
HEAD_MIX_MULTI (one multi-token head-mix launch instead of 5 kernels per token, verify.cpp 301-316, 2327-2345; ours: plan_head_mix, original_verify_window_gr.rs:622) |
MISSING | 60-100 us (0.5-0.8 % of the chain); the chain GR kernels already take T tokens, maybe no new PTX | S | bitwise (verify byte for byte) |
COMMIT_BATCH + state-only GDN commit (verify.cpp 2646-2700, verify_kernels.cu 180-215, 1067-1087, 1160-1170; ours: verify_gdn_conv_commit_kernel + the full verify_gdn_step_norm_multi_kernel per layer, original_verify.rs:331-336, commit graph 158 kernels, 0.463 ms) |
MISSING | 250-350 us per ROUND (1.0-1.4 % of the round), on the critical path between rounds | M, seal | bitwise (gdn_parity) |
ATTN_DAILY (qsa_decode_attn.cu attn_chunk_kernel_pre75, reduce12, attn_merge_v2: 16 shuffles instead of 60, 2 cells per step) |
MISSING: ours is the literal old kernel (leleka_qsa_decode_chunk, qsa_native_decode.cu:81); chain_qsa_decode_chunk only hoists loads and measured slower |
140-235 us (1.1-1.9 %): 30-50 % of the 470 us chunk | M, seal | bitwise |
cluster argmax / top-k (sampler.cu, sm_90+) |
MISSING (our greedy argmax: one block per token, 79 us per window; draft sampler 38 us, row_top_prob 36 us) |
120-160 us per round (0.5-0.8 %); N/A on sm_86 | S-M (cuLaunchKernelEx inside capture), seal |
bitwise |
SIDE_MIXER=2 + SH_FORK_LATE (GDN a/b gates and the indexer chain on side stream 1, the gate projection and QSA query chain on stream 2, events inside the captured graph) |
MISSING: our window is one stream, no cross-stream edge | 300-700 us (2.4-5.5 % of the chain); the 5090 has 170 SMs and our kernels are small-grid; upstream claims -1.2 % (A4000) / -2.3 % (3060) | L (side streams + event capture in OriginalCapture, keep the QSA journal in order); no seal |
bitwise (scheduling only) |
GR_UP75 (interleaved reductions, tail dot over 4 rows) |
PARTIAL: chain_gr_up8/16 already hoist the loads |
50-100 us (0.4-0.8 %) | S, seal | bitwise |
batched K/V and indexer append (kv_q8.cu:193, native_qsa_indexer.cu:269,300) |
MISSING (one row per launch, original_verify_window_qsa.rs:530) |
50-90 us (0.5 %) | M, seal; keep the streamed host-mirror semantics | bitwise |
float4 combine (native_moe.cu 66-93; the fused combine_k10_vec4_hits is HIP-only) |
MISSING | 30-50 us (0.3 %) | S, seal | bitwise |
16-lane sub-warp expert kernels + GU_SWIGLU (iq_kernels.cu native_gu_multi_kernel<..SUB16> 1864, row_dot_80_sub16 1561, launch_gu_swiglu; ours window_moe_gu_*/window_moe_down_* are the old warp-per-row kernels, chain_swiglu_quant_kernel fuses SwiGLU with the quantizer only) |
MISSING / PARTIAL | 200-350 us (1.6-2.8 %): the old kernel idles half the lanes on the third pass; no upstream number | L (a 5.7k-line file, per-format parity), seal | bitwise (claimed) |
MMVQ_IL interleaved MMVQ, 2-4 and 5-8 columns (native_mmvq.cu 2979-3175, q8_1_il.cuh; tables only for IQ4_XS, Q4_K, Q5_K, Q6_K, Q3_K; the 5-8 column table is sm_120-only) |
MISSING (we run the old exact head_n*_t* kernels) |
100-400 us (0.8-3 %); bounded by dense 2,250 us against a floor of ~2,000; larger at T >= 5 where the old kernel falls back; which of our dense weight types the tables cover is unknown | L, seal | bitwise (claimed, mmvq_il_parity) |
fused per-head RMSNorm+RoPE (native_rope.cu 69-125, 175-245) |
MISSING (split_q, rms, rope: 7 launches against 3) | ~40 us (0.3 %) | S-M, seal; must match the sealed --use_fast_math pair bitwise |
bitwise (verify) |
| exact-T GDN a/b | PARTIAL (chain_gdn_ab_multi_kernel hoists weights across 96 warps) |
50 us or less | S, seal | bitwise |
MTP catch-up skipping rejected rows (mtp.cpp 73-79, 1580) |
MISSING | 20-80 us per round (0.1-0.3 %) | M | gate it (not claimed bitwise) |
ONE_TOKEN_COMMIT |
MISSING | about 0 at 3.06 tokens per round (only T=1 windows) | M, seal | bitwise |
Ranking by estimated gain per effort: (1) HEAD_MIX_MULTI, (2) COMMIT_BATCH + state-only GDN commit, (3) ATTN_DAILY, (4) cluster argmax, (5) SIDE_MIXER=2 + SH_FORK_LATE (the largest single item, L),
(6) GR_UP75 delta, (7) batched appends, (8) float4 combine, (9) sub16 experts + GU_SWIGLU (L), (10) MMVQ_IL (L), then the rest.
Measure first, all model-free (nothing needs a model load): the T distribution and T=1 share of the live windows (docs/e2e-data/945*: decides MMVQ_IL 5-8 columns and ONE_TOKEN_COMMIT); a per-kernel sum of the
72 GDN commit kernels from the job 9062 trace (bounds COMMIT_BATCH); a chain_probe gr-style shape for the head mix at T = 1..8 (byte-compare the per-token chain against the staged multi read);
tools/chain-probe/qsa_prof.cu extended with upstream's attn_chunk_kernel_pre75 + attn_merge_v2 against leleka_qsa_decode_chunk (cold weights, our 64-cell grid); an mb_pdl.cu-style two-branch graph for
the overlap bound of SIDE_MIXER / SH_FORK (a/b-sized kernels beside a qkv-sized MMVQ on 170 SMs); upstream's decode_cluster_parity --bench on 248,320 logits; window_moe_gu_16 / window_moe_down_20
against the sub16/sub8 kernels with random blobs, 30 groups, cold weights (gates the biggest item); mmvq_il_parity --bench on the 5090 with our shapes and T from 4 to 8.
Closing the host gaps between dependent phases: three bit-identical changes (2026-10-28)
The CUPTI anatomy named four host-side gaps per 8192-token chunk. Three were taken, each behind its own switch (all on by default now, =0 restores the old path;
replay arm flags !qpf/!noqpf, !gpool/!nogpool, !mspan/!nomspan). The fourth, the route readback, cannot be overlapped as proposed: the router of layer k reads the residual
that layer k-1 writes, so there is no earlier GPU work to hide the readback under; only the host work after it (grouping, spans, gather issue) can shrink.
| step | switch | what changed | where the time was |
|---|---|---|---|
| (a) QSA prefix-copy overlap | LELEKA_PREFILL_QSA_PREFETCH |
the 147 MB prior-KV prefix copy of a QSA layer starts at the beginning of the layer on a side stream (event after the compute stream's last write of the shared stage, copy, event the layer's own copy_prefix waits on) instead of in the compute stream between indexer and attention. No second stage is needed: the arena stage is free when the layer starts. Same bytes, same spans, earlier. |
qsa_index_scan -> kv_guard, 62 ms/chunk |
| (b) GDN state pool | LELEKA_PREFILL_GDN_POOL |
the two 3.1 MB buffers per GDN layer and chunk (ping-pong scratch, mirror spare) come from a pool of four instead of cuMemAlloc + cuMemFree (144 driver calls per chunk, each free a device-wide synchronization), and the downloaded state is scanned for finiteness once instead of twice. | gdn_prefill_finite -> gr_scan, cuMemAlloc gaps (18 ms) |
| (c) MoE span cache | LELEKA_PREFILL_MOE_SPAN_CACHE |
the resolved bank spans and formats of every admitted (layer, expert) are kept per bank (same lifetime as the finite-admission bitmap, keyed by the bank address); a later chunk skips the per-expert binding walk (moe.spans, 26 ms/chunk). bank.eligible and the format-equality check still run per expert. |
moe_prefill_finite -> mmq_zero |
Not done: a deferred (asynchronous) state download for the GDN layer end. GdnPrior owns the host values and is staged into the transaction before the next layer starts, so a deferral needs a lazy prior or a second ownership
chain; with the pool and the single scan the remaining boundary cost is the 3.1 MB synchronous download per layer (about 0.3 ms x 36).
Identity (gate I). Final residual hash of every prefill chunk (LELEKA_TRACE_PREFILL_R) and the top-16 rows of the teacher-forced decode, replay arms in one process each (a third fresh stack in one process fails with HostAllocation, so
the 256k job runs two arms per process):
945-codex-crm(84 requests of 10k-70k tokens, chunk 2048): arms B (all off), P, G, M (one switch each), ALL:cmp_rhashIDENTICAL on 108 / 108 chunks for P, G, M and ALL; 4,135 top-16 rows per arm with d_top1 and dmax16 exactly 0.0, 0 argmax flips.night5-long-256k(5 requests 45k-243k, chunk 8192, grid 8192, sized per-layer slots, decode capped at 48 tokens): B1 against A1, A2, B2, P, G, M, B3: IDENTICAL on 34 / 34 chunks each; top-16 rows B1 vs A1: 242 rows, d = 0, flips 0.
Paired timing (same replay, same process shape; arm_prof.py sums the prefill-chunk times of the PREFILL-PROFILE lines, positions >= 100k = 19 chunks, 141,844 tokens; B = all off, A = all on). The summed chunk time is stable to +-10 ms between repeats of the same arm; sum_ttft is not
(the first arm of a process is 1-2 s slower than the second, see the table), so the chunk sums are the comparison and the TTFT sums are given for completeness:
| arm (process order) | chunk sum all (ms) | chunk sum >= 100k (ms) | qsa >= 100k | moe >= 100k | gdn >= 100k | sum TTFT (s) |
|---|---|---|---|---|---|---|
| B1 (1st of proc 1) | 66,366 | 36,859 | 9,168 | 12,199 | 8,151 | 68.4 |
| A1 (2nd) | 63,455 | 35,817 | 8,600 | 11,807 | 8,050 | 65.0 |
| A2 (1st of proc 2) | 64,639 | 35,826 | 8,600 | 11,782 | 8,110 | 66.5 |
| B2 (2nd) | 64,875 | 36,864 | 9,171 | 12,233 | 8,109 | 66.4 |
| B3 (2nd of proc 4) | 64,917 | 36,847 | 9,169 | 12,230 | 8,122 | 66.5 |
| P (qpf only) | 65,641 | 36,363 | 8,600 | 12,224 | 8,164 | 67.6 |
| G (gpool only) | 64,802 | 36,781 | 9,176 | 12,195 | 8,057 | 66.4 |
| M (mspan only) | 65,385 | 36,489 | 9,170 | 11,838 | 8,159 | 67.3 |
Reading: at >= 100k, B (3 repeats) 36,857 +- 9 ms, A (2 repeats) 35,817 / 35,826 ms: -1.03 s = -2.8 % of the prefill chunk time, split exactly as designed: (a) QSA -569 ms (-6.2 %), (c) MoE -430 ms (-3.5 %), (b) GDN -17..-77 ms (-0.2..-0.9 %, at the
noise floor). Over all 34 chunks B is 64.9-66.4 s and A 63.5-64.6 s (the shorter chunks carry the first-arm effect). The single switches add up: P -494, G -76, M -368 ms at >= 100k. Sum TTFT of the five requests: B 66.5-68.4 s, A 65.0-66.5 s, about 1.3-3.4 s (2 %) lower, within the
order effect, so the claim is the chunk-time one. The replay is the production shape (chunk 8192, sized slots) but with LELEKA_TRACE_PREFILL_R=1 on in every arm and decode capped at 48 tokens; the real-stack 4-run A/B (rest-e2e-ab2, binary with the defaults on, before = the three switches =0) is queued; its numbers are not in this table.
Hardware / software: RTX 5090 (driver 595.99), CUDA 13.2.2, Rust release test binary rt-qpf3 (switch defaults off, env/arm override) for the table; rt-qpf4 / bin-e2e4 have the defaults on (the only difference). Model: Qwen3.8-Flash-Next IQ3_S + KAR L2, expert cache auto (sized per layer), prefix cache 6000 MiB.
Scripts: scripts/upstream-rest/jobs/rest-qpf-id2.sh, rest-qpf-256k.sh, rest-qpf-256k-b.sh, rest-e2e-ab2.sh.
Order of work and where it runs
Phase 0 and 1.2 run on the laptop in WSL (tests) and are committed one by one on claude/upstream-port; GPU gates (R, I, Q) go through the server queue
(~/work/gpu-runs/holder2/jobs), one job per item, results appended to this table with the numbers and the decision (kept / flagged / dropped).