KAR CUDA smoke target
Experimental expert component
ResidentExpert (kar_expert.hpp) stages one selected expert's gate, up and
down compressed slices from an already verified immutable KAR mapping. It
requires top-down group-32 three-dimensional expert tensors, explicit level
1–8 and at most eight input tokens. Three compressed matrices stay resident;
one F32 matrix scratch buffer is reused for decode, multiply, SiLU and down
projection. Allocations happen in open, with a fixed geometry cap and GPU
headroom check. Its own stream/event controls ownership and completion.
The component has an opt-in native verifier cache-miss adapter described below. It has no LRU scheduler, and staging waits for its own upload. Its F32 activation arithmetic differs from native quantized expert arithmetic. No default, model quality or speed claim follows from its oracle passing.
On an unused NVIDIA GPU, scripts/check-kar-expert-gpu.sh checks exact decoded
bytes, scalar FP64 multiply (absolute tolerance 1e-6 for the synthetic
fixture), one/eight-token windows, expert replacement/reuse and invalid state.
For private target-model evidence, build strata-kar-expert-probe and run:
strata-kar-expert-probe MODEL.kar LAYER EXPERT LEVEL TOKENS NEW_PRIVATE_DIRECTORY
python3 scripts/check-kar-expert-result.py --archive MODEL.kar --result NEW_PRIVATE_DIRECTORY
The probe verifies all archive payload CRCs before extracting an expert. The
offline NumPy oracle independently decodes its selected archive slices and
compares every F32 byte (tolerance zero), then compares expert output with FP64
matrix arithmetic (relative L2 at most 2e-5, max absolute error at most
1e-4 * max(1, max(abs(reference)))). It does not compare KAR with source GGUF
weights. All reconstructed matrices and results must remain outside Git.
Initial actual-model component check (2026-10-05, RTX 5090, driver 595.91.07,
CUDA 13.2.2) used layer 0, expert 17, level 2 and eight deterministic inputs
from archive SHA-256
536d612ca60eab460cb978f51748fc6fa4e9d611d4601e777884e8b51385afa5.
All three reconstructed matrices matched the independent CPU decoder exactly.
Output relative L2 error against FP64 was 1.6218124241392543e-7, maximum
absolute error 4.847555814223303e-9. Explicit allocations were 1,536,768 bytes
for compressed weights and 6,758,400 bytes for matrix/activation scratch;
CUDA context overhead is excluded. This is one expert component, not full-model
serving or a comparison with the original IQ3 expert.
Experimental native verifier misses
Build the engine with STRATA_NEXT_EXPERIMENTAL_KAR_EXPERTS=ON and
STRATA_NEXT_KAR_DIR pointing to this directory. This option is off by default
and requires Linux CUDA. Set STRATA_NEXT_KAR_EXPERTS_ARCHIVE to a trusted,
immutable, separately SHA/provenance-verified target-model KAR archive and
STRATA_NEXT_KAR_EXPERTS_LEVEL explicitly to its supported level (1–8).
The reader checks directory integrity, every payload CRC and every layer's
expert geometry before allocating its bounded GPU buffers. This integrity
check does not authenticate the archive's pairing with the loaded GGUF.
Large archives can take minutes to verify; configure an appropriate worker
startup deadline. Keep both model and archive unchanged for the worker's life.
The adapter requires the native pack, expert pool and a single GPU. It computes
native verifier-window misses, including short prompt ingestion and decode.
Native resident hits, batched prefill, dense weights, PLE and MTP retain their
existing paths. It sets the PCIe miss fraction to zero;
use --pcie-frac 0 in the comparison baseline as well. This is a mixed precision
experimental arm, not full KAR model residency. Each missed expert is staged
and computed serially on the component's own nonblocking CUDA stream. Its
completed host rows preserve routing order and bypass the CPU expert jobs.
The bounded matrix scratch is reused; no decoded expert bank is allocated.
The exit diagnostic reports computed route entries and explicit GPU bytes.
The GPU test script also uses the production Rust archive writer to make a
model-free expert bank. It tests eight-token grouped routing against a scalar
oracle (absolute tolerance 1e-6), preservation of VRAM/PCIe/remote/completed
rows, unsupported archive shape/level and invalid routed IDs. Production
serving does not invoke the fixture generator or Python.
The optional strata_next_kar_ple_probe target belongs to the imported
Strata engine build when STRATA_NEXT_EXPERIMENTAL_KAR_PLE=ON. It exercises
the separate CPU PLE quality arm on real KAR rows. A successful checksum does
not imply the sparse CUDA packet path is wired into serving.
For a same-process CPU gather comparison on the target model, run
strata_next_kar_ple_probe --compare-random BASE.kar 2 PLE.gguf 4096 42 5 200000000. The final number bounds the sampled global row IDs; use the row
count of the selected KAR part when matching a sparse CUDA packet run. The
probe alternates native and KAR gathers after one warmup of each and reports
the median over the requested repeats. The first native gather may incur
storage page faults, while KAR opening already scanned the archive; compare
the warm medians and report first-run times separately.
For a model-free reader check, run leleka-api model ple-smoke-fixture --output /tmp/ple-smoke.kar, then strata_next_kar_ple_probe /tmp/ple-smoke.kar 2 --expected-rows 4 0 1 2 3. The four checksums must match those printed by
the Rust fixture command. Remove the temporary archive afterward.
vendor/libkar.h and vendor/libkar.cu are copied unchanged from local koference commit 806d2398ae1daaceb2917242911e5680cbfb3608, paths r08/code/libkar.h and r08/code/libkar.cu. Their SHA-256 values are 1d725069fd2c275423f5db70fb4190e7d51760e0c48a2a5ebe8c91993936ca92 and 331babd2a2f260abb7de602d414edd97399542ec1bccb23ffcdfad69dc0ade28 respectively. Keep these bytes and upstream provenance traceable when making local changes.
On Linux with CUDA 13 and a supported NVIDIA GPU, create a model-free fixture and compare its CPU and GPU decode checksums:
leleka-api model smoke-fixture --output /tmp/strata-smoke.kar
cmake -S gpu/kar -B artifacts/kar-gpu-build -G Ninja -DCMAKE_CUDA_ARCHITECTURES=120
cmake --build artifacts/kar-gpu-build --target strata-kar-gpu-smoke
artifacts/kar-gpu-build/strata-kar-gpu-smoke /tmp/strata-smoke.kar smoke.expert 2 30
leleka-api model checksum-kar-preview /tmp/strata-smoke.kar smoke.expert 2
artifacts/kar-gpu-build/strata-kar-gpu-smoke /tmp/strata-smoke.kar smoke.expert 2 30 --row 0
leleka-api model checksum-kar-row /tmp/strata-smoke.kar smoke.expert 2 --row 0
An optional fifth argument is an overlay archive. The smoke target opens both
archives with payload CRC verification, checks their virtual-F32 source identity
and every replacement's name, shape, source dtype, source digest, and source
offset, then reserves and decodes
the requested tensor from the overlay when it is present there. It prints
source=base or source=overlay. For a real overlay, first run
leleka-api model resolve-kar-overlay --base BASE.kar --overlay OVERLAY.kar:
that Rust verifier additionally checks complete archive SHA-256 values and
provenance. Keep both files unchanged between resolution and this smoke run.
The smoke target alone does not authenticate the archive files against
provenance and is not a serving loader.
For a bounded resident-row experiment, append --rows COUNT SEED instead of
--row ID. The smoke validates the archive, copies one compressed record's
level prefix into VRAM once, generates COUNT deterministic random row IDs
within that record, uploads those IDs, then times repeated CUDA decoding into
F32 output. It reports the initial reserve_ms separately from the warm
decode_median_ms. The warm loop reuses both the compressed record and the
same row IDs; it excludes row-ID transfer, cache admission and eviction,
matrix multiplication, and the rest of inference. For example:
strata-kar-gpu-smoke MODEL.kar 'per_layer_token_embd.weight#strata-part-001-of-002' 2 100 --rows 4096 42
--rows-ple COUNT SEED uses the same deterministic row generator as
strata_next_kar_ple_probe --compare-random; compare their whole-output
kar_fnv1a64 and output_fnv1a64 for an independent CPU/CUDA parity check.
Use the selected part's row count as the CPU probe's MAX_ROW.
--rows-ple-vary COUNT SEED starts from that same first batch, then changes
every ID before each timed decode. It uses pinned host ID storage and reports
separate GPU-event medians for ID upload, decode, and their combined duration.
The output checksum is for the final, changed batch and therefore does not
match the CPU probe's initial batch. Both modes keep the complete selected
compressed record resident in VRAM; the timing excludes host ID generation,
archive verification, cache admission, eviction, matrix multiplication, and
the rest of inference.
The smoke program validates the KAR container and payload CRCs, reserves a chosen tensor's compressed level prefix in VRAM, decodes it on a CUDA stream, and reports a warm kernel median over the requested iterations. Compare output_fnv1a64 with the native CPU command above using the selected archive, tensor, and level. This is a kernel smoke measurement, not an end-to-end inference comparison or a model quality result. It does not yet link the decoder into Strata's serving path. Use the original model digest, archive digest, driver/CUDA versions, GPU, tensor, cache state, and iteration count when recording results.
Before any CUDA allocation, the smoke program checks the selected prefix, F32 output, and optional row ID against currently free VRAM. It leaves at least 512 MiB or one sixteenth of total VRAM free, whichever is larger, and refuses the run if that reserve would be crossed. This admission check protects shared GPU experiments; another process can still allocate memory afterward, so CUDA allocation errors remain possible. It is not an inference scheduler.
--row ROW_ID selects the CUDA row-gather decoder for one row of a compressed record. The row ID is local to the selected KAR part, so --row 0 on a split PLE part addresses that part's first row. This mode stages the same complete compressed level prefix with kar_reserve, then allocates and writes only one F32 row. It reports mode=row and the one-row output checksum. Compare a real-model result with model checksum-kar-row on the selected archive and part name; that CPU command verifies the complete archive before bounded range decoding. The one-row synthetic fixture above has the same checksum as its full-tensor decode. Row mode does not reduce the initial PCIe transfer of that part and does not make the full model fit in VRAM.
The smoke program caps the decoded F32 output at 100 million elements. A large PLE part can therefore be used with --row if its selected compressed prefix fits the available VRAM; its complete tensor need not fit the full-output cap.
For a private real-model overlay, scripts/check-kar-cuda-records.py accepts a JSON list of {name, elements} records (or a report with a records array), an archive, the Rust CLI, and the CUDA smoke binary. It checks byte-level CPU/CUDA output parity for each record, using the full tensor up to one million values and row 0 above that limit. It writes the complete result outside Git with mode 0600. Its event timings cover warm CUDA decoding only; it does not time PCIe transfer or multiply, and parity with the CPU KAR decoder is separate from quality against GGUF or end-to-end inference.
Bounded compressed-row GPU cache probe
strata-kar-row-cache-smoke exercises an experimental 1–1024 MiB VRAM cache
for the level-2, group-32, 160-value PLE geometry. Each GPU slot uses 64
bytes for a 50-byte compressed row. A CPU LRU map assigns slots; the program
uploads only missed rows and the batch's slot IDs, scatters misses into VRAM,
and decodes the selected rows with CUDA. Every batch is checked byte for byte
against a fresh CPU decode from the verified archive. This probe is not wired
into serving and its event time does not include archive verification, CPU
planning, output readback, or the parity check.
Build with cmake --build artifacts/kar-gpu-build --target strata-kar-row-cache-smoke. Invoke as strata-kar-row-cache-smoke ARCHIVE.kar 'per_layer_token_embd.weight#strata-part-001-of-002' 2 64 TRACE.txt. The
private trace contains one batch per line with up to 128 space-separated,
part-local decimal row IDs. The cache refuses to run if its allocation would
leave less than 512 MiB or one sixteenth of total VRAM free, whichever is
greater. Keep traces and models outside Git. See
spec node experiments/2026-10-03-bounded-ple-cache-smoke.md for the first real
archive checks.
Selective row transfer prototype
strata-kar-sparse-row-smoke tests a different staging geometry. The upstream kar_decode_rows computes only requested rows but kar_reserve first transfers the record's complete level prefix. The prototype verifies the KAR archive, gathers only the selected rows' codebook, group scales, and bit-plane words from the mapped file into a compact host packet, transfers that packet once, and decodes the rows on CUDA. It does not modify the pinned libkar source. Its output is compared with model checksum-kar-row for each selected row.
cmake --build artifacts/kar-gpu-build --target strata-kar-sparse-row-smoke
artifacts/kar-gpu-build/strata-kar-sparse-row-smoke OVERLAY.kar blk.0.ffn_gate_inp.weight 3 30 0 1
artifacts/kar-gpu-build/strata-kar-sparse-row-smoke BASE.kar 'per_layer_token_embd.weight#strata-part-001-of-002' 2 1000 --range 0 4096
artifacts/kar-gpu-build/strata-kar-sparse-row-smoke BASE.kar 'per_layer_token_embd.weight#strata-part-001-of-002' 2 1000 --random 4096 42
Append --row-major-cache to --random, --range, or explicit row IDs for a
private layout experiment. After archive payload verification, the smoke
transposes one compressed group-32 row tensor into RAM with each row's scales
and selected bit planes adjacent. It refuses more than 12 GiB of host cache
or less than 8 GiB of reported available RAM after allocation. The data are
never written as another model file; the CUDA packet and decoder stay the
same. row_major_build_ms and row_major_cache_bytes are reported separately
from first and warm packet assembly. This measures an upper bound for a
row-oriented storage layout under warm host-memory conditions. It is not a
bounded GPU cache and does not measure cold random storage access.
The smoke reports packet bytes, the full-record prefix bytes, warm H2D event time, warm CUDA decode event time, and per-row byte checksums. It reports archive verification and one packet build separately as host wall time; those are not included in the GPU event times. Page faults, output transfer, matrix multiplication, and runtime scheduling need separate accounting. Random rows may trigger storage reads and CPU work, so fewer PCIe bytes do not by themselves establish lower request latency. A production path needs a bounded packet cache, coalescing across requests, provenance binding, backpressure, and integration with the PLE consumer before it can be evaluated as inference.
The --range START COUNT form generates consecutive local row IDs, up to 200,000 rows and the same 100-million-value output cap. --random COUNT SEED generates deterministic pseudorandom local IDs within the selected tensor record. Both omit individual row checksums for more than 128 rows but still report the whole output checksum. The contiguous selection is useful for GPU transfer scaling; random selection probes host packet assembly with scattered rows. Neither selection is a representative storage page-fault benchmark because archive payload verification reads the complete file first and can warm the page cache. The smoke times both first packet assembly and a median of five repeated assemblies on the same rows. It also times an upload of the same number of F32 rows from pinned host memory into the output buffer. That upload is the GPU stage of Strata's current PLE prefill path. The comparison excludes its CPU row decoding; compare it with the separate CPU gather probe. Compare the measured stages at the same row count rather than inferring latency from byte counts alone.