The elastic global K/V grew one visit at a time (new buffer, copy, free the old one), so the card needed one old visit buffer extra and a long request stopped 1.2 to 1.8 GB short of the
context that had been planned ("VRAM exhausted growing elastic global KV cache", 503), and the plan was set before the drafter (DSpark's fused weights, DFlash 2 codebooks and rings)
took its memory.
- ink_runner.cuh: with ONE slot on ONE card (no layer split, no elastic 1M mode, K/V not split to host at the start) every global visit's K, V and scale buffers are address ranges for the
requested context (strata::core::VmmRange, src/core/vmm.cpp, now also linked into the CUDA backend) and physical memory is mapped behind them as the context grows; the pointers never
move, so no peak of old + new. A failed mapping falls back to the host tail (kv_spill_tail, the earlier code, now a function) or to a refused request, as before.
STRATA_INK_KV_VMM=0 takes the earlier growth back.
- ink_dspark.cuh: the classic drafter's global context grows the same way (ctx_vmm).
- ink_cuda_backend.cu: after the drafter has loaded (--kv-offload off), max_ctx is set to what the card holds (ink_kv_reach_ctx, 256 MiB kept free), up or down, never above
--max-context ("max_ctx A -> B" line); --kv-prealloc / STRATA_INK_KV_PREALLOC=1 maps that whole context at start-up (and refuses to start, with a message, if the mapping fails); a request
that fails to grow says how much video memory is free now and what to do.
- ink_serve.h + InkBackend::kv_reachable_tokens(): a prompt the card can no longer hold (another program took video memory after the plan, --kv-offload off) is refused at the start with
a message instead of ending with 0 tokens; the engine stays up.
- strata/core/ink_kv_grow.hpp: ink_kv_reach_ctx() and its test (ink_kv_grow_test). Register: STRATA_INK_KV_PREALLOC (opt-in), STRATA_INK_KV_VMM (rollback); docs/INKLING_KV.md, SETTINGS.md.
Measured (RTX 4090, SQ-20 v2, --kv fp8 --kv-offload off, prompts of 90K / 100K / 110K / 128K tokens; VRAM ballast taken before the first allocation to get the Windows 4090's room;
phaseA-tests/rel0224/ink-kv/RESULTS.md, REPLY-6770.md): no ballast: tokens identical old / new / --kv-prealloc, decode equal; 700 MiB ballast, classic drafter: old ends the 110K request at
100,864 tokens with 0 tokens, new answers it; default drafter: old plans 104,192 and refuses 110K and 128K, new answers both; 1,300 MiB: old plans 74,240, new raises it to 109,568 and
answers a 100K prompt; every answer identical to the unballasted run; short prompts: same tokens, speed within 0.5%; ballast after the start: --kv-offload auto answers (host tail), off
refuses with a message. An RTX A6000 with a 128K prompt: identical tokens. Builds: CUDA sm_86 and sm_89 (Linux), sm_120 (MSVC), HIP gfx1151.
The measurements (phaseA-tests/rel0224/ink-kv/RESULTS.md) made FP8 a good default where the card likes it and a bad one where it does not:
- CUDA: FP8 on every card and slot count (KL 0.005, top-1 95-98%, FASTQ subset SQ-20 v2 201/213 FP16 against 202/213 FP8, 64 slots +24 to +27% and a 32K
decode x2.5 on 12 and 16 GB cards because the cache is half the size and stays on the card; -1 to -3% on an RTX A6000 that has no native FP8).
- HIP (AMD): the 0.2.23 rule is back, unchanged: FP16, FP8 from 16 slots on a card of 36 GiB or less, STRATA_HIP_KV_FP8_SMALL and the Strix Halo FP8_KV_C64 set as before.
On the Radeon AI PRO R9700 FP8 costs 7% decode at 4K and 17% at 32K (prefill -8% at 32K); the retirement of STRATA_HIP_KV_FP8_SMALL is undone.
- Metal (Mac): FP16 ("auto: Mac default"); --kv fp8 (#6983) and the opt-in M5 Max fast set are as they were.
- SYCL (Intel): FP16, FP8 from 16 slots and in the Intel Arc fast set, as before (Arc A750: FP8 decode -6%, KL 0.0044 at 4K and 0.0054 at 32K).
ink_kv_auto_rule() now takes the parallel slots, the card's memory and what the backend's default is (fp8_by_default / fp8_from_slots / card cap / its sentence), so
the rule and its reasons stay in one place; every backend prints "[kv] <backend>: K/V cache <type> (auto: <reason>)". ink_main no longer sets FP8 at 16 slots for every
backend (that made a Mac and an Intel card take FP8 by the back door); the CPU reference keeps its own FP8-from-16-slots rule in its backend. The plan
(inkling_fit.auto_fp8_kv) follows: FP8 for CUDA and an unnamed backend, the 0.2.23 rule for HIP, FP16 for Metal and SYCL. Tests: ink_kv_rule_test (host only),
test_inkling_kv_auto.py, and the planner tests that pinned FP16 numbers pin them with fp8_kv=False.
After #6983 an explicit `--kv fp8` is honoured on every Metal GPU (the M5 Max fast set still picks FP8 by itself). `--kv auto` stays FP16 outside the M5 Max set: INK-PR measured
FP8 on an M5 Max at KL 0.0053 / top-1 96% against FP16 with the K/V halved, but decode -10 to -12% at 4K to 16K, so it is a choice there, not a default (the owner decides).
The [kv] line says which of the two happened, and says so when `--kv fp16` meets the M5 Max set's own FP8.
`--kv auto` (the default) now stores the K/V cache as FP8 wherever the backend can (CUDA, HIP; SYCL stays FP16 by default until its A750 / B70
numbers are in, Metal takes FP8 only in the M5 Max set) and FP16 where it cannot. K8V8 and K8V4 are only chosen when asked for (--kv k8v8, --kv k8v4).
An explicit --kv always wins. Before, every backend had its own rule (CUDA: FP16 unless 16+ slots, a card of 13 GB or less with the K/V offload off, sm_89+ with a
context over 16K, three RTX 50 rows; HIP: FP16 below 16 slots; SYCL: FP16).
- engine/include/strata/core/ink_kv_rule.hpp: the one rule (host only) and the one start-up line, "[kv] cuda: K/V cache fp8 (auto: default)"; the CUDA, HIP, SYCL
and Metal backends call it. Test: engine/tests/core/ink_kv_rule_test.cpp.
- CUDA: plan_vram_reserve() takes the type from the rule; STRATA_INK_ELASTIC_1M + STRATA_INK_KV_K8V4 remains the tester's way to K8V4. HIP: the old small-card
switch STRATA_HIP_KV_FP8_SMALL is retired (register entry marked retired in 0.2.24).
- ink_main --help: the --kv line says what auto is.
- --dump-ref / --kld-eval: a row-selected form for long documents (INK_KLD_TAIL=N INK_KLD_STRIDE=s keep the logits of every s-th of the last N positions; the file
then starts with -n_tokens; INK_KLD_CHUNK / INK_KLD_CHUNK_TAIL set the prompt chunk of the head and of the scored part). The old file format and behaviour are unchanged;
the --kld-eval line gains refPPL and dNLL at its end.
- terminal: the memory plan (inkling_fit.auto_fp8_kv) sizes FP8 for every backend except SYCL and Metal; compute_unified and recommend take fp8_kv like compute does.
Tests that pinned the FP16 numbers now pin them with fp8_kv=False; test_inkling_kv_auto.py covers the new rule, the launcher's k8v8 / k8v4 clamp and that every backend
calls the one rule. docs/INKLING_KV.md; docs/SETTINGS.md regenerated.
Measurements (phaseA-tests/rel0224/ink-kv/RESULTS.md): teacher-forced KL of FP8 against FP16 K/V 0.005-0.007 and top-1 95-98% on 4K / 32K / 128K documents
on RTX A6000 (SQ-20 v2), RTX A4000 (SQ-15), R9700 (SQ-15), Arc A750 (SQ-10, 4K), RTX 5070; the needle misses are the same with FP16.
The Hy4-Flash GGUF engine (f-hy4-clean + f-hy4-mla + the E2E fixes: CPU expert rows equal to the GPU rows bit for bit, the engine's
out-of-memory message, the plan reserve for A40 / RTX A6000), opt-in:
- CUDA: STRATA_BUILD_HY4_FLASH, OFF by default (configured only with CUDA on and no HIP);
- Metal: STRATA_BUILD_HY4_FLASH_METAL, OFF by default (the f-hy4-e2e side linked the Hy4 engine into the Metal strata
unconditionally; here its targets, the strata link and STRATA_HAVE_HY4_FLASH are behind the option).
Conflicts: engine/CMakeLists.txt (f-hy4-e2e had the whole file in CRLF; next-0224's file kept, the Hy4 option and include re-applied by
hand) and engine/metal/CMakeLists.txt (next-0224's ggml handling kept; mtl_rt split into mtl_rt_core + mtl_rt as the merged
gguf_lite.cpp needs, Hy4 targets behind the option).
Which experts of a token run on the CPU and which on the GPU depends on timing (CPU split auto), and the two arithmetics
differed in the last bits (8 lane partials without fused multiply-add and libm's exp on the CPU; 32 lane partials with fused
multiply-adds, an xor butterfly and the CUDA exp on the GPU). The model is sensitive enough that this moved the logits from
run to run with CPU experts on (KL 1e-3 to 3e-2 between two identical runs), while CPU experts off was bit-identical.
The CPU row kernels (scalar, AVX2, VNNI tiers) now follow the GPU decode kernels' reduction contract (own_decode.hpp), and the
SwiGLU exponential is one shared function (own/swiglu_math.hpp, host and device give the same bits) used by the CPU expert
glue and by the GPU decode quantiser. New test hy4_flash_cpu_gpu_rows_parity: the CPU tiers against own::mmvq on the GPU for
Q4_K / Q6_K / Q8_0 (217k outputs), the rule-E quantiser, the exponential over a dense sweep and the clamped SwiGLU image.
cpu_experts_test compares tiers with the production silu.
Measured on an A40 (sm_86), chat-advice and json-raw, 64 rows each: before, two runs with CPU experts on differ (KL 0.00145 and
0.0221) and differ from CPU off; after, the dumps are byte-identical run to run and CPU on equals CPU off.
The autonomous window has no host loop, so it would not wait for the adaptive tier's copies to land. peer_autonomous_policy.hpp holds the rules
(overlap, sm_120 with the FORCE override, every expert on a card with the LOSSY opt-in); peer_autonomous_policy_test covers them; the guard in
generate.cpp uses it. SECOND_GPU.md and the register say 'refused', not 'do not combine'.
Topology probe, device set, planners, transports and the strata-topo program with their tests; the Terminal strata topo command. Nothing in the engine calls it yet.
The enum and the host/device macro come from rope_scaling_type.hpp; freq_scale, mscale, corr_dims, rope_yarn_ramp and rope_scaled_angle are one-line calls into
strata::kernels::yarn. The comments that named ggml as the contract now name the YaRN paper.
dp4a.hpp and its SYCL copy are replaced by the clean-room headers; strata_spin_pause keeps the old behaviour on HIP (sleeps on every target but CUDA below 7.0).
hip_compat/intrinsics.hpp: the gfx1010 / gfx1012 branch calls dp4a_rdna1 (new header).
The device residency table was copied from pageable memory on the refill stream with no event toward the window's stream,
flip_pending (STRATA_ADAPT_OVERLAP) never updated it, PeerPlanDevice held 64 entries while a window can route kWindowMaxT x 10,
peer_plan used one 128-thread block, and release_gpu_waits did not free the peer's wait on h_seq_.
New library engine/include/strata/mgpu + engine/src/mgpu, wired in cmake/backends/mgpu.cmake:
- DeviceSet: the topology data model (devices, per-pair links, measured figures), the
primary-card rule, JSON in and out (schema_version 1), synthetic builders for tests.
- DeviceGuard: RAII current-device switching.
- probe: PCIe link (sysfs / NVML), copy and memory bandwidth, mapped-host access, per pair
the staged route, peer copy where proven (the #2666 host-bridge rule and an exact data test
first), and the mapped-flag round trip. CUDA, and HIP through the hip_compat shim.
- strata-topo program and `strata topo [--json]` in the Terminal (new subcommand only).
- Transport interface: peer copy and host-staged implemented, doorbell a stub for P1;
choose_mode is a pure function of the measured link.
- Placement planner: plan_experts (cost model of one decode window, f = argmin instead of
STRATA_PEER_HOT; Rows / OrderedPartials / SumPartials; N cards) and plan_layers (the layer
split's fitted model as a pure function). Unit tests on synthetic pairs and quads.
- terminal/tools/mgpu_identity.py: greedy token-hash identity of a family's goldens, one
GPU against several.
Nothing in the engine calls any of it yet.
The similarity scan found ggml / llama.cpp derived text in strata-quant-common.h (through its generator), dot_avx2.cpp, dot_neon.cpp,
arm_act.inc, act_avx512.cpp, kq_avx2.cpp, split/iqdot_hip.cuh, sycl/iq2xs_host_tables.inc and strata_gguf.py, with no provenance wording
(dot_avx2, dot_neon and arm_act carried only our own copyright line). Each now says which parts are derived (MIT, Copyright (c) 2023-2026
The ggml authors, pin 3cf03257f; gguf-py's own licence line for strata_gguf.py) and that the rest is ours. Comments only: no code changes,
the generated header is regenerated from the changed generator (check passes).
The nine are `derived:` entries of tools/no_ggml_allowlist.txt, which is also rewritten for the files that now carry the wording.
tools/ggml_similarity.py reports the derived line numbers per file, which is how the parts were found. The tenth file of the scan,
strata_reader_layout_golden.inc, is a false positive (rows of 0x00) and gets no notice.
Brought over from f-mla-kernel: key tiles / 64-slot units no row can see are skipped (sliding windows, masks, dead sparse entries); the single-plane
tensor-core mode dequantises a Q8_0 latent once into an fp16 key tile; a 32-head tile for 16+ tiles of 32 heads outside the per-query mode; the chunk count of the
single-plane kernel from floor / ceiling of 2 x SMs / tiles by waves per chunk (the other kernels keep the 2 x SMs rule); mla_latent_suggest_splits for callers
that size scratch; slot bitmask and the n_kv cap by q_pos; tests for each.
Clean-room row kernels for the Hy4 CPU experts (Q4_K, Q6_K, Q8_0 weight rows times a rule-E activation row):
a portable scalar tier, an AVX2 tier and an AVX-512 VNNI tier (256-bit VNNI dot products), runtime cpuid
dispatch, integer sums exact and one fixed fp32 sequence (no fused multiply-add) in every tier, so a
token's row is the same alone and in any window, in any job order, on any worker and in any tier.
The activation quantiser is the rule of own/act_format.hpp; the vector one equals the scalar one bit for bit.
native_expert.cpp is now only the glue (geometry, SwiGLU with the clamp, calls into the rows). Removed:
every ggml / ggml-cpu use of the Hy4 CPU path, native_q81*.cpp, the aligned AVX-512 path with its 96 MiB
table and libmvec, the STRATA_HY4_FLASH_CPU_NATIVE_Q8K / CPU_Q81_ALIGNED switches, the ggml links of the
Hy4 targets, and the forced ggml configure for STRATA_BUILD_HY4_FLASH.
Tests rewritten against a float64 oracle written from FORMAT-SPEC.md (golden vectors bit-exact, synthetic
edge blocks, bound 1e-5 * (sum |w a| + min-term magnitude)).
moe_wave_plan.hpp, router_lookahead_v2.hpp, ssd_stream_scheduler.hpp and ink_cold_store.hpp carried a copyright line of the ggml authors above
their contributor's own. The token-shingle scan against llama.cpp at the pin finds no run of 60 tokens in any of them (at most 5 derived lines,
all idiom noise), and grep finds no ggml or llama.cpp text in them besides that line. The line is removed; the SPDX MIT line and the
contributor's and Strata contributors' lines stay.
- remove engine/src/hy4flash_gguf/mmq/*, cmake/hy4_flash_mmq.cmake (libstrata_kq, the NVFP4 objects),
and revert the edit of the vendored strata-llama quantize.cu (tools/check_vendored.py passes again)
- STRATA_BUILD_HY4_FLASH defaults to OFF
- strata::hy4_flash::pgemm: the prompt-GEMM interface the engine calls, with a "not built" stub for now
(every query says no, so the engine keeps its matvec / dequantise + cuBLAS paths)
- remove the dlopen hooks: STRATA_HY4_FLASH_REFERENCE_OPS_LIBRARY, DIAG_FA / DIAG_ROUTER / DIAG_NORM
(no dlfcn.h left in the engine, including shared elementwise.cu, which is main's again)
- own sigmoid router (own/router.cu) with a float64 reference test; the fused publish variant is gone
- own RMS norm (own/norm.cu) replaces the block-per-row kernels added to elementwise.cu
- remove the H20-only q4_pair_reuse path and its llama.cpp-derived oracle; the fused HC rms+quantise
- NVTX markers only where the header exists (CUDA 13 without the nvtx package)
- own activation block (own/act_format.hpp, rule D) shared by the coming kernels
- tools/hy4_flash/clean_gate.py: run the engine per case and compare logit dumps (top-1, KL, greedy-identical)
sel_mask / mask_words (per-token bit per slot, combined with every other rule), n_kv_cap_by_qpos (n_kv(t) = min(n_kv(t), q_pos[t] + 1) for verify windows that must equal one-token calls), an explicit n_split is no longer clamped by the number of units (the caller's merge expects that many chunks). Tests for both; 16K prefill shape in the bench.
strata/kernels/mla_latent_attn.hpp + src/kernels/cuda/mla_latent_attn.cu (+ mla_latent_attn_tc.inc): one kernel family for decode,
multi-token verify, chunked prefill and sparse selection over a latent KV cache [c_lat | k_pe] (interleaved or separate k_pe array,
flat or paged). Query token x 16 heads per block share each latent tile in shared memory; online softmax; round-robin split-K chunks
with an exact (max, denominator) merge, optional per-head sinks; kv_pos / q_pos / window visibility; n_kv as scalar, device scalar or
per-query array; device-scalar causal base for graph replay; per-query rows bit-identical to one-token calls (bit_exact_per_query).
Paths: scalar fp32 FMA (any sm_61+), tensor cores mma.sync m16n8k16 on sm_80+ with each fp32 operand split into fp16 hi + lo (about
fp32 accuracy, 3 products) or plain fp16 (fast, lossy); a generic one-head-per-block kernel for any R <= 1024.
tests/kernels: float64 reference tests per mode (decode / verify / prefill, f32 / f16 / Q8_0, paged, sparse, windows, sinks, split
counts, softmax-weight probes, bit-exactness) and a bench against Ling's original mla_attn.
Clean-room: designed from the maths and public CUDA / PTX documentation only.