Files
leleka/docs/upstream-port-plan.md
T

59 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's cuda_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_dma is raised by cuStreamWriteValue32 on Linux (original_gpu_schedule_ffi.rs::raise_flag_after; a host callback only with LELEKA_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) With LELEKA_PCIE_FLAGB=host the callback thread exists but is created before the host thread pins itself: publish_gpu_plan of the first window group enqueues the host function before DirectCpuPool::compute_group pins the caller (pin_caller, CPU 0). Measured with a thread listing during decode (job upspeed-06-threads, 3 requests of 9e3, FLAGB default/host x warm-up off/on): host thread mask 0, expert workers masks 1..15, every driver thread (cuda..., cuda-EvtHandlr, and in the host-flag runs the callback thread, named after its creator) mask 0-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 + cuStreamSynchronize at 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 (job upspeed-31-ab-256k was prepared, never reached the GPU and was removed from the queue); a 12-16 GB card (laptop commands are in docs/windows.md).
  • Quality (jobs upspeed-31-q-auto and -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):

  1. 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.
  2. Q5_1/Q8_0 down-row dots: our DownFormat is Iq4Nl | Q2_0 and the IQ3_S pack's down matrices are IQ4_NL, so no row would use them.
  3. 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-in STRATA_IQ_GATHER.
  4. 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-in LELEKA_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 in docs/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-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 (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):

  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 +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_window 19.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.
  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 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).
  6. Quality gate Q (job rest-q-256k, replay of night5-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: HostAllocation with a 20,000 MiB prefix cache and a loaded host) and is kept as rest-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).

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.

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).