forward_batch refactored into forward_batch_inner(+optional taps) with thin
forward_batch / forward_batch_taps wrappers (existing signature unchanged).
Captures the 4 DSpark target taps: visit 5 (prelude ip5 entry residual),
visit 23 (core pass1 ip11 entry), visit 41 (core pass2 ip17 entry), and
visit 48 = output-normed final depth mix (model.llm.norm over attn_res_mix).
These feed dspark_context per committed token.
Test forward_batch_taps_capture: logits BIT-IDENTICAL to forward_batch (capture
is pure copies) and tap48 last row unembeds (cast+gemm, no re-norm) to exactly
those logits; all taps finite/nonzero. CPU -D warnings green; ld GPU 55/55.
- Drafter proj weights now BF16 (f32-act x bf16-w via router_gemv_batched is
exact vs reference matmul_f32); norms/fuse stay f32; qkv/gate_up fused bf16.
- dspark_context(): per layer mix(row=il,dflare_norm_il) -> k/v_proj_ctx ->
per-head k_norm_ctx + NeoX half-RoPE -> k/v [M,kv_dim] f32; frnn = row-3 mix
with markov_head.dflare_norm. bf16 ring scatter left to the caller (b5).
- GPU-vs-CPU-oracle parity on the REAL mtp weights: max_rel 3.0e-6 (global-scale
metric; per-entry rel explodes on near-zero RoPE outputs).
CPU -D warnings green; ld GPU 54/54.
Exact port of strata k_dspark_mix_taps (softmax(fuse_w[row]) weighted sum of 4
target taps + RMSNorm) and k_dspark_rmsnorm_rope (per-head RMSNorm + NeoX
half-split RoPE pairs (d,d+hd/2)). f32 activations; bf16 store is the caller's.
RoPE freq/trig computed in f64 internally (f32 angle) for tight parity at large
pos; the downstream bf16 ctx store makes the extra precision moot.
Host wrappers dspark_mix_taps / dspark_rmsnorm_rope + CPU-oracle parity tests
(both < 1e-4). hip 39/39; CPU -D warnings green; speculative_draft.lean 0 err.
Brick 1 of DSpark Step 1 (proof-first per AGENTS invariant 6):
- spec_lossless: one speculative round (draft, batched causal verify, accept
longest matching prefix, emit correction/bonus) emits EXACTLY the plain-greedy
prefix of length match_len+1 for ANY draft => speculation changes throughput,
never the token sequence.
- kept_rejected_disjoint: with ring R >= window+chunk, kept window and rejected
draft tail occupy disjoint ring slots => rollback = truncate history length,
no KV data restore needed.
Core tactics only; 0 sorryAx; all 7 proofs green.
Punto 2: the 40 SWA pools now store a circular ring of swa_win+SWA_CHUNK_CAP(512)
=1536 positions (slot=pos%seq) instead of the whole 32768 context (~5GiB wasted);
the 8 global pools keep a linear max_context cache allocated ONCE. KV capacities
are fixed per layer kind => no drop+realloc when a session crosses a 4096 multiple.
kv_store{,_f16,_f16_batched} write pos%seq; flash decode/prefill/prefill_wmma read
p%seq (global seq>pos => identity). snapshot/restore map the window onto ring slots
with 1 or 2 pitched copies (wrap). serve clamps prefill chunk to SWA_CHUNK_CAP so
ring>=swa_win+chunk holds. proofs/prefix_cache.lean Part E (0 sorryAx): slot_inj,
window_slots_distinct, ring_no_clobber, global_slot_id. New GPU swa_ring_kv_parity
(R=1536, P=2000) vs an independent host LINEAR oracle: 1.48e-5.
Punto 1: BUF_POOL buckets pooled allocs in (4KiB,64MiB] to a power of two so variable
batch tails / future speculative B converge to a closed size set (no hipMalloc/Free
churn); larger allocs stay exact. Weight uploads (load_raw/load_bf16_as_f32/expert
matrix/arena) switched to alloc_unpooled: resident, exact, never pooled (rounding
them had added ~11GiB).
MEASURED gfx1150 FP16 KV chunk256: READY ~21.0GB; multi-turn 2048->13000->2048->5000
vram flat ~23.1-23.7GB (only bounded cap-8 checkpoint turnover, no KV resize);
prefill 2048 ~12.2s, 13000 ~78.6s (~6ms/tok). Suite GREEN hip37 ld23 gw4, CPU23, Lean6.
strata-ctl always sends max_new=16384, so any prompt > MAX_CONTEXT-16386 (16504 /
16686 seen live in sessions.db) hit the hard error and returned 0 tokens, killing
the agent mid-window. Now clamp_max_new(): hard-error only when the prompt itself
overflows (n_prompt+2 >= max_context); otherwise effective_max_new =
min(g.max_new, max_context-n_prompt-2) drives max_seq, history reserve, the decode
loop and the length finish. Resident window configurable like strata:
VETTA_MAX_CONTEXT env / serve --max-context N (>=4096), advertised in READY.
CPU test clamp_max_new_budget (16504/16686 clamp, 32765->1, 32766->None, 65536 full).
MEASURED live: 16504-token prompt GEN2 now runs (2 tokens, DONE 107.6s ~6.5ms/tok)
where it previously returned ERR 0 tokens; READY 32768 default / 65536 with flag.
gw serve_gen 4/4 EXACT; CPU -D warnings green.
serve_gen passed the per-request 4096 bucket (cap) to restore/forward, so after a
long session (states_cap=32768) a shorter request (bucket 20480) failed the
st.max_seq == max_seq reuse check and reallocated the persistent KV from scratch
(free 6.4GB, alloc 4GB) -> the VRAM drop+regrow Federico observed (31.7->25.9GB).
Now cap = eng.states_cap.get() after the grow-check: restore/forward use the actual
persistent stride, so returning to a shorter context reuses the KV (no realloc).
Measured: GEN1 5000tok then 100tok -> vram_end 23.56GB both (no drop). gw GPU 4/4.
a6 (persistent states): serve_gen allocated+freed ~3.75GB KV every request
(the +/-3.75GB sawtooth, max_new=16384). InklingEngine now holds persistent
per-layer states sized to a 4096-bucket cap >= prompt+max_new, reused across
requests and grown only on a bucket crossing. restore reuses a correctly-sized
state; a cold request resets the ShortConv hist rings (reset_history, async)
since the KV prefix is overwritten by prefill before any causal read. Verified:
two identical GEN16384 requests -> vram 23.46/23.49GB flat (no sawtooth),
identical reference output; twice-paris cold-reuse output identical.
a8 (SWA-window checkpoints): 40 of 48 KV pools are SWA (swa_win=1024) but the
snapshot stored the full seq_len on all of them (~510MB/checkpoint at seq2600).
Now SWA layers checkpoint only the last min(seq,1024) positions (kv_start offset
via new DeviceBuf::copy2d_at); full-attn layers keep the whole prefix. Checkpoint
~210MB. proofs/prefix_cache.lean Part D proves kvStart_le_winStart containment +
swa_window_restore_equiv (windowed restore observationally exact). Verified:
cold vs restored(1536, window truncated to [512,1536)) emit identical tokens.
Measured 5-turn VRAM climb +2.6GB -> +1.16GB (bounded by cap 8), KV flat.
Suite green: ld23 hip33 gw4 GPU serial, CPU -D warnings, Lean 0 sorryAx.
best_match/restore never refreshed ck.lru, so the grid checkpoint just used
at turn 2 kept its turn-1 tick and was evicted by turn 2 prompt-boundary +
full-sequence saves; turn 3 fell back to the pinned 1024 anchor (~1min again).
Fix (audit §1): restore takes &mut self and bumps lru on hit; eviction prefers
non-grid entries (is_grid) so stable 512-grid prefixes survive; replace
pos%512==0 with a monotonic next_grid threshold that splits a chunk exactly on
each 512 boundary regardless of start. Cap 8. Verified 4-turn probe: restored
advances 1536->1686->1778 (no fallback), turn2+ prefill ~1-3.5s vs ~30s cold.
load_msg_queries rebuilt the stacked cross-pass queries [4,hidden] on EVERY
core visit: 2 sync D2H + 1 sync H2D of STATIC model weights = 72 PCIe stalls
per prefill chunk (720/prompt) and 24 per decode token (audit §3.1). Memoize
the 12 device buffers once in WeightCache.msg_queries => zero host round-trips
on the hot path. Measured prefill 2048tok 40.9 -> 38.5s.
new_state zeroed ~3.75GB KV via host vec![0u8] + blocking h2d_bytes every
request (system-RAM alloc + CPU zero + sync PCIe copy, ~0.5-1.5s stall, even
on a prefix-cache hit). Replace with async device hipMemsetAsync (zero_async,
~7.5ms GPU): removes the blocking copy while keeping the cache deterministic
for the full-byte parity tests (causal attention only reads [0..=pos]).
The exact-size thread-local BUF_POOL never called hipFree: every distinct
batched tail size (bu = suffix % chunk, varies per turn) parked ~100-160MiB
forever => unbounded multi-turn VRAM leak (audit 2026-12-02 §2.1). Track
POOL_BYTES and hipFree a dropped buffer once the pool exceeds MAX_POOL_BYTES
(512MiB); hot fixed-size intermediates still recycle. Also add the symmetric
e<0||e>=128 guard to k_moe_scatter_buckets (count_buckets had it) so a corrupt
router id cannot write exp_cur out of bounds.
Peer review P2: layers 20-23 MXFP8 grouped GEMV was scalar (256 threads/row +
shared reduction). Rewrite both k_mxfp8_grouped_gemv_f16 (M=B) and
mxfp8_gemv_f16_body (M=1 decode/indirect) as Wave32 mirrors of the NVFP4 path:
one wave per row (8 rows/block), E4M3 group dequantized once to exact FP16 (3
mantissa bits => exact in f16), hardware fdot2_f32 partial dot + scale-fma, DPP
wave32_sum (no shared mem). Both paths share the per-token group order => M=1 and
M=B stay BIT-EXACT (forward_batch_parity max_abs=0.0 restored; mxfp8 grouped oracle
1.3e-6 < 2e-3). MoE GPU time 2727->1888ms/chunk (-31%, the 65% hotspot). Prefill
2048: 44.4->40.9s. Suite GREEN ld23 hip33 gw4 (serial, server stopped), CPU -D
warnings, Lean 6/6. Cumulative prefill 60->40.9s (-32%).
Under VETTA_PROF, sync before/after moe_batched so EXPERT_NS measures real GPU MoE
time, not async launch. Measured: MoE = 2727ms of 4176ms/chunk = 65% of batched
prefill (the dominant hotspot; trunk GEMM + flash are minority). Production path
(no VETTA_PROF) unchanged.
Replace 1-thread-per-output scalar GEMM with a 16x16 output-tile block staging
16-wide K slabs of X/W in LDS (loaded once, reused across 256 outputs). Serial-K
ascending accumulation preserved => bit-exact vs scalar (hip gemm parity, ld 23
batched bit-exact, gw 4 serve greedy vs reference all EXACT). Prefill 2048:
52.3 -> 44.4 s (-15%). WMMA tensor-core is the further pass (changes f32 accum
order => needs greedy re-verification).
The prompt re-rendered by strata-ctl diverges on the last ~2 turn-tag tokens once
turn 1 becomes history (live log: common_prefix=2644 vs checkpoint len=2646), so
best_match (full-checkpoint prefix) discarded everything and turn 2 cold-prefilled.
Save an intermediate checkpoint every 512 tokens during prefill (strata --auto-ckpt
grid): turn 2 now restores the longest 512-grid checkpoint that is a full prefix
(2560 for common=2644) and prefills only the new suffix (-93%). Verified: turn2
restored=1024 RESUME 1024, prefill 2631ms vs 25816ms cold (~9.8x), parity EXACT.
Also enrich VETTA_DBG_PREFIX to log per-checkpoint common_prefix on a miss.
prewarm eagerly loaded all per-expert ExpertMatrix tensors (host run_experts
path, ~16 GiB), but the production serve uses device-routed MoE which loads a
SECOND contiguous ExpertArena copy of the same expert bytes lazily on the first
forward. Measured: 25 GiB after prewarm climbing to 42 GiB during the first
prefill chunk (~0.6-0.9 GiB/layer = arena load), near the 48 GiB HIP aperture.
Fix: prewarm now loads the expert ARENAS (the layout device MoE actually reads);
the forward reuses the memoized arenas. VRAM 42 -> 20 GiB (-22), prefill 60 -> 56 s
(no lazy arena NVMe load mid-forward). Parity EXACT (serve GPU 4/4, ld 23, hip 33).
Also adds VETTA_PROF batched phase+VRAM profiling (BPROF) used to diagnose this.
serve_gen prefills the prompt suffix in chunks of VETTA_PREFILL_CHUNK (default
256) via eng.forward_batched -> forward_batch (M=B), amortizing weight streaming
+ kernel launches across B tokens instead of one model pass per token. take==1
falls back to the M=1 forward; chunk=1 restores the sequential path (A/B).
Aligns decode to f16 device MoE (VETTA_DEVICE_MOE) to match the batched prefill
precision (moe_device bit-identical to moe_batched).
Verified EXACT through the serve: serve_gen_multi_token_parity (5-tok prompt ->
batched chunk, 16 decode tokens identical to reference) + serve_gen_emits_eos_then_stop
(27-tok prompt -> batched chunk, EOS exact). gw CPU 14 + GPU 5 green.
forward_batch embeds B tokens and runs the proven schedule (inkling_loop.lean)
at M=B: prelude [0,6) -> core [6,18) x3 with DEVICE-SIDE bank rollback (arena
sub-range via copy_f32_sub, cur<-prelude copy, blocks.truncate) + cross-pass
msgs (attn_res_mix over bank, nq=4) + controllers on passes 1,2 -> coda [18,24)
-> final depth mix + unembed LAST token. run_layer_batched dispatches SWA/full.
No host D2H/H2D gather anywhere in the batched path (graph-capturable shape).
copy_f32_sub: device f32 copy from src offset (extract bank / last token).
forward_batch_parity (real weights, B=4, f16 KV + device MoE): logits for the
last token BIT-EXACT (max_abs=0.0) AND argmax identical (111) vs 4 sequential
forward_inkling_with_state calls. The full batched prefill is verified.
k_l2_clip indexed the per-head scale as scale[r*hd] with r=row. For M=1
rows=n_head so r=head (correct); for batched rows=M*n_head the rows >= n_head
read the [n_head,hd] scale OUT OF BOUNDS, corrupting q/r (r_raw clipped to 0).
Add scale_rows param: sc = scale[(r % scale_rows)*hd]. l2_clip passes rows
(M=1 unchanged); new l2_clip_batched passes n_head. Regression test
l2_clip_batched_parity (M=8,n_head=24,hd=128) bit-exact vs sequential.
Also: k_gather_channel (strided msgs channel [B*nq,h]->[B,h] for batched
controllers), copy_f32_at (offset copy into depth-block arena). Flash prefill
parity test now exercises the real config (n_head=24,n_kv=8,hd=128,win=1024).
k_copy_f32 (dst=src, n elements): enables device-side depth-block snapshot and
core-loop bank rollback in the batched forward, eliminating the M=1 host D2H/H2D
round-trips (layer.rs block snapshot + bank rollback). Exact (test copy_f32_exact).
Additive — decode default unchanged. Foundation for the device-resident depth-block
arena [n_blocks,B,h] that attn_res_mix reads directly (already M>1).
Verified: hip GPU 32 green, workspace CPU -D warnings green, 6 Lean 0 sorryAx.
k_situ_f16_batched: SiTU over M rows (gu [M,2*inter] interleaved -> act [M,inter]
FP16), one row per blockIdx.y. Activates all grouped-MoE w13 output rows at once.
k_mxfp8_grouped_gemv_f16<MT=8>: MXFP8 analogue of the NVFP4 grouped GEMM, grid
(N, n_experts), bucket-indexed; 32-byte E4M3 group dequantized once per MT-token
tile (UE8M0 scale, no outer), block reduction per token. Covers layers 20-23.
Parity: SiTU batched BYTE-IDENTICAL to M sequential; grouped MXFP8 vs CPU oracle
B=20 4 experts 160 pairs max_rel 0.0 (UE8M0 scales in realistic range).
Additive — decode default unchanged. All batched MoE compute now complete for
BOTH quant formats (NVFP4 layers 0-19 + MXFP8 20-23).
Verified: hip GPU 28 green, workspace CPU -D warnings green, 6 Lean 0 sorryAx.
k_kv_store_f16_batched: grid (n_kv, M); k_in/v_in [M,n_kv,hd]; each token m writes
FP16 cache position pos[m] (K as-is post-clip, V RMS-normalized then __float2half_rn).
Same semantics as the M=1 kv_store_f16. Batched prefill stores all B K/V before the
causal flash M=B reads the cache.
Parity vs B sequential kv_store_f16: B=20 n_kv=2 hd=128, K/V caches BYTE-IDENTICAL.
Additive — decode default unchanged.
Verified: hip GPU 26 green, workspace CPU -D warnings green, 6 Lean 0 sorryAx.
k_shortconv4_prefill_par (exact strata k2_shortconv4_prefill_par): one thread per
channel processes a tile of 16 contiguous tokens; 3-token history seeded from hist
[3,C] (bf16-rounded f32, same ring as decode) for t0<3 else in_x bf16 round-trip.
Static 1/sqrt(5) or dynamic taps [B,n_heads,4] 1/3. Replaces B sequential decode
calls with one parallel launch (grid C-tiles x ceil(B/16)).
k_shortconv4_update_hist: roll history <- last 3 in_x (bf16), shift for B<3.
Parity vs B sequential decode steps: B=37 (partial last tile) C=64, output AND
history BIT-EXACT (0.0). Note: k_attn_res_mix already supports M>1 (grid nq x M).
Additive — decode default unchanged. Remaining batched attention: causal flash
M=B + kv_store B positions + batched depth-blocks/controllers/bank, then
forward_batch orchestration + serve wiring + EXACT parity.
Verified: hip GPU 24 green, workspace CPU -D warnings green, 6 Lean 0 sorryAx.
k_nvfp4_grouped_gemv_f16<MT=16>: grid.y=n_experts, expert eid processes its bucket
tokens [exp_off[eid],exp_off[eid+1]) read from bucket_tok; W group dequantized once
per MT-token tile (fdot2), amortizing expert weight bandwidth MT-fold across the
tokens routed to that expert. X [B,K] f16 gathered by bucket_tok -> Y [total,N]
f32 in bucket order. This is the prefill MoE GEMM (w13/w2 NVFP4); composes with the
landed bucket CSR (count/prefix/scatter). SiTU + reduce_buckets_masked follow.
Parity vs CPU dequant oracle per (token,expert) pair: B=20, 4 experts, 160 pairs,
max_rel_err 2.79e-5. Additive — decode default unchanged.
Verified: hip GPU 22 green, workspace CPU -D warnings green, 6 Lean 0 sorryAx.
Next: reduce_buckets_masked + batched SiTU, then batched attention -> forward_batch.
Port strata k_moe_count/prefix/scatter_buckets: for total=B*top_k (token,expert)
pairs build exp_off[129] CSR offsets, bucket_tok[total] (bucket->token) and
slotk_to_bidx[total] (pair->bucket position), entirely on device (no host
round-trip). This lets the grouped expert GEMM read each expert weights ONCE for
all tokens routed to it — the prefill weight-bandwidth amortization behind the
reference 40:1 prefill speedup.
Parity vs CPU oracle (B=37, top_k=8): CSR offsets == prefix-sum of counts,
slotk_to_bidx consistent bijection, per-expert bucket token multiset exact
(scatter order within a bucket is non-deterministic via atomicAdd, so invariants
are checked rather than element order).
Verified: hip GPU 21 green, workspace CPU -D warnings green, 6 Lean 0 sorryAx.
Next: grouped w13/w2 GEMM indexed by bucket_tok + reduce_buckets_masked, then
batched attention -> forward_batch.
Port strata k_sf4_gemv<MT> multi-token path: k_nvfp4_gemv_f16_mt<MT=16>, one wave
per output row, the W group is dequantized ONCE and reused across MT tokens
(fdot2 per token), M tiled by blockIdx.y. X [M,K] f16 -> Y [M,N] f32. This is the
expert-GEMM foundation for batched prefill: reading each expert weight once per
MT tokens instead of once per token amortizes the dominant NVFP4 weight bandwidth
MT-fold. For M=1 the math reduces to the decode GEMV (same fdot2 + scale-fma).
Parity vs CPU dequant oracle [M,N]: M=37 (exercises 2 full MT tiles + 5-token
remainder) max_rel_err 1.75e-6. Additive — decode default unchanged.
Verified: hip GPU green (incl. new mt parity), workspace CPU -D warnings green,
6 Lean proofs 0 sorryAx. Next: batched MoE (router M=B + grouped expert GEMM +
reduce M=B) and batched attention/depth-blocks -> forward_batch for prefill.
moe_device runs the whole MoE on device: router ids/weights stay on device, the
arena indirect GEMV selects experts on device, per-expert outputs accumulate in a
device y_part via a STATIC y_offset=kk*hidden (added to both indirect kernels).
No ids D2H, no per-expert output D2H/H2D => the MoE block is now graph-capturable.
WeightCache gains a memoized expert_arena(ip,mat) accessor. Both SWA and full-attn
MoE blocks dispatch to moe_device under VETTA_DEVICE_MOE=1; the default f32 host
path is unchanged (parity baseline preserved).
Parity: 16/16 greedy tokens IDENTICAL between VETTA_DEVICE_MOE=1 and the
VETTA_F16_EXPERT=1 host path (same kernels/data). Arena indirect bit-exact vs
direct on real weights (NVFP4 layer 0 + MXFP8 layer 20).
Verified: ld GPU 19 + hip GPU 19 green, workspace CPU -D warnings green, 6 Lean
proofs 0 sorryAx. Next: device-resident depth-block/bank machinery, then HIP graph
capture of the decode step.
ExpertArena loads a whole layer expert tensor in ONE contiguous device buffer
(the safetensors already store [n_exp,N,K/2] NVFP4 / [n_exp,N,K] MXFP8), with a
per-expert outer_scale array. The indirect GEMV indexes expert id from a DEVICE
buffer (ids[slot]) => static launch params, no host ids round-trip.
Add MXFP8 f16 indirect kernel (mirrors NVFP4: shared device body + direct +
indirect wrappers). expert_arena_gemv_f16 dispatches NVFP4/MXFP8.
Parity on REAL weights: arena-indirect BIT-EXACT vs per-expert direct for layer 0
(NVFP4) and layer 20 (MXFP8), 4 routed experts each. Additive — forward default
unchanged (wiring into the device-resident MoE path is the next brick).
Verified: ld GPU 19 + hip GPU 19 green, workspace CPU -D warnings green, 6 Lean
proofs 0 sorryAx.
Refactor k_nvfp4_gemv_f16 into a shared device body + direct wrapper + indirect
wrapper. The indirect variant reads the expert id from a DEVICE buffer (ids[slot])
and indexes a contiguous per-layer weight arena (packed/scales/outer), so launch
parameters stay static — no host ids round-trip. This is the prerequisite for
HIP graph capture of the decode step (current MoE dispatch is host-mediated).
Math identical to the direct kernel (same body): parity test builds a synthetic
4-expert arena and routes 4 slots, asserting BIT-EXACT equality indirect vs direct.
Additive only — default forward path unchanged.
Verified: hip GPU 19 green (incl. new indirect parity), workspace CPU -D warnings
green, 6 Lean proofs 0 sorryAx.
Port the exact strata k_sf4_gemv path (the 'performance pass' the original
correctness-first kernel deferred): one wave per output row (8 rows/block),
E2M1->FP16 register LUT dequant, hardware v_dot2_f32_f16 (fdot2_f32) over
vectorized uint4 activation loads, DPP wave32 reduction. Adds sf4_e2m1_f16,
fdot2_f32, wave32_sum helpers (gfx1150 builtins).
Parity verified: real expert w13 f16 max_rel_err 8.4e-5 (tol 2e-3); hip 18 + ld 18
GPU green. MEASURED decode (64 tok greedy, eager-resident): f32-scalar 4.63 tok/s
vs f16-fdot2 4.86 tok/s (1.05x). Profiler shows why it is modest: experts are only
~45ms of ~185ms/token; decode is dominated by attention + ~1300 kernel launches
(host submission), not expert compute. This kernel is the verified foundation for
the WMMA M>1 prefill GEMM (next brick); the decode lever is HIP graph capture.
Bug: serve_gen called WeightCache::new(&eng.ar) PER REQUEST, creating empty
memoization maps each turn -> every request re-read ~15-23 GiB of weights from
NVMe and re-uploaded to device (the 'resident' comment was contradicted by the
per-request instantiation). Federico spotted the symptom: model only loaded at
the first message, unlike the reference which loads at boot.
Fix:
- WeightCache now owns Arc<SafetensorsArchive> (was &'a borrow) so ONE cache lives
resident in InklingEngine across all requests; loaded once, never re-read.
- WeightCache::prewarm(d, n_layers) eagerly loads the whole model (trunk + every
SWA/full layer + core controllers + all expert matrices). run_serve calls it at
boot by DEFAULT (model ~23 GiB <= 80 GiB full-UMA-residency policy); READY is
emitted only after residency. VETTA_LAZY_LOAD=1 defers to first use (still
resident across requests once loaded).
- Arc deref coercion keeps all CPU-oracle test reads (&ar) unchanged.
Verified (gfx1150, Inkling-2-Mini, FP16 KV): eager VRAM 23.60 GiB at READY before
any message, boot 3.6s, STABLE across 3 requests (no reload/growth), clean release
0.34 GiB on QUIT; lazy option 0.34 GiB at boot. Parity EXACT preserved: CPU 91 +
ld GPU 18 + gw GPU 5 green.
Root cause (traced across strata-ctl + strata): strata-ctl build_prompt re-renders
the chat template from conversation TEXT and re-encodes every turn; the assistant
reply round-trips through detokenize/re-encode (special tokens stripped), so it is
NOT token-identical to the generated ids. The first port saved a checkpoint only at
the post-decode pos (prompt+generated), exactly the part that diverges -> no match
on turn 2 -> full cold re-prefill (Federico measured 734s vs 783s, no speedup).
Fix mirrors strata ink_serve.h:949 (prompt-end checkpoint, longest-prefix match):
also save a checkpoint at the PROMPT boundary, the stable system+history prefix
that re-renders identically across turns. best_match picks the longest valid
prefix, so turn 2 restores the prompt and prefills only the new dialogue suffix.
Emit RESUME <start> via on_prefill_complete (was hardcoded 0) so strata-ctl reports
reused/cached tokens. VETTA_DBG_PREFIX logs match/save for live diagnosis.
Verified (gfx1150, Inkling-2-Mini, FP16 KV, greedy): realistic turn-2 with a
DIFFERENT assistant tail restores the 300-token prompt boundary (debug restored=300),
parity EXACT vs cold, prefill 6.02s vs 72.42s (12x). CPU 91 + gw GPU 5 green, Lean 0
sorryAx. Absolute first-turn prefill speed still needs batched prefill (next brick).