Files
leleka/scripts/cuda-q5-oracle/README.md
T

4.7 KiB
Raw Blame History

Independent Q5_K projection oracle

Test-only fixtures for STRA-142. They do not run a model forward pass, measure performance, or install a Toolkit on the GPU server. Production uses its existing owned CUDA Driver boundary and embedded PTX.

Reference and independent expectations

native_fixture.cu links the unchanged imported engine/strata/src/kernels/cuda/native_mmvq.cu (SHA-256 f2fc636e5e8f6db9bbb8146fbf2b78a717c0e0076bf8c72ac2b784df7b3f455f). The native source is pinned through c3020b71ba6cc49a81d8b374c29dd3be36fe239c and attributed to llama.cpp 3cf03257f219afbe7334045ff7c6a06ac68c627d. Its source/MIT notice is preserved; no quantizer or projection implementation is copied into this test runner.

Build with verified CUDA 13.0.88, -arch=sm_120 --use_fast_math -O3. --use_fast_math is essential: FTZ, approximate division and contraction are the native baseline. Function/data sections and linker garbage collection remove unused format dispatch references without editing the original translation unit. scripts/prepare-cuda-q5-oracle-toolkit.py PRIVATE_OUTPUT fetches only the six hash-pinned compiler/runtime components in deploy/cuda-toolkit.lock.json, verifies the manifest and archive hashes, and records the selection. BLAS is not needed. scripts/build-cuda-q5-oracle.sh TOOLKIT PRIVATE_ELF refuses an existing output, checks the native source hash, and compiles the bounded reference. Build in a GPU-hidden isolated Linux amd64 CPU container; preserve its actual architecture, compiler versions, exact commands, source hashes and ELF hash as evidence.

The native runner accepts a private input file: three little-endian u32 words (magic 0x35314b51, M, N), exactly M*(N/256)*176 packed bytes, then 4*N bytes of finite F32 activation. Bounds are 1 <= M <= 640, 256 <= N <= 6144, N%256=0. It quantizes one native scratch allocation, then calls native_q5_k_f32 with a second fresh native scratch and checks those native bytes agree. Neither native call receives candidate scratch. Separately it loads the trusted candidate asset and launches only leleka_quantize_q8_1 in the private test Driver boundary. All allocations, stream and module are consumed on success; errors terminate the isolated process. Original native quantization is never fed nonfinite inputs.

Output has four LE u32 words (magic 0x35314f51, M, N, candidate admission status), then native Q8 bytes, candidate Q8 bytes, and native F32 output bits. These are separate assertions: every Q8 byte must match; finite/zero/Inf outputs require identical bits; NaN outputs require NaN classification. No tolerance is calibrated from candidate results.

tests/q5_oracle.rs independently constructs/decodes GGUF six-bit scales/minima, high bits and nibbles; its packed words and exact scalar dot are recorded hand expectations. It does not import a production decoder. The GPU hand case uses constant activation 127: native d8=1 and original-input sums are exact, yielding 959104 per Q5 block. CPU scalar arithmetic is supplementary and does not redefine native fast-math output.

Executable gates

  • tests/q5_gpu.rs: installed-driver opt-in tests. The standard test covers M=1/3/4/5 × N=256/512/2048/2560/6144, ties away from zero, signed zeros, cancellation, half-scale underflow, FP16 range, hand arithmetic and nonfinite weight halves. Public calls repeat against the frozen native result, verify immutable caller inputs and zero remaining temporary charge. Six numeric refusal cases exercise the native status path and preserve caller output.
  • Its separate real-tensor test accepts only the explicitly selected Qwen blk.4.ffn_up_shexp.weight 640×2560 private fixture and our deterministic synthetic activation. This proves one projection, not model quality or forward execution. Packed weights stay outside Git.
  • tests/q5_mock.rs / q5_mock_cuda.c: independent CPU ELF routing, geometry, admission, cache, delayed argument ownership, sync/restore poison, and consuming cleanup proof. The existing fixture is included unchanged. Synthetic mock scratch/output arithmetic is not the native numerical oracle.
  • test-cuda-driver-bootstrap.sh preserves the complete existing CPU gate and adds the focused Q5 matrix and an output-alias compile refusal.

GPU tests require LELEKA_CUDA_REAL_GPU=1, use one test thread and a bounded outer timeout. The parity test additionally requires absolute private paths in LELEKA_Q5_EVIDENCE, LELEKA_Q5_NATIVE_ORACLE, LELEKA_Q5_TRUSTED_PTX. The real-tensor test also requires LELEKA_Q5_REAL_INPUT. Fixture subprocesses have 30-second deadlines. Capture stdout/stderr/exits and hardware/driver/pre-post GPU state, retain private digests and remove only owned remote resources. Ordinary cargo test leaves these GPU tests ignored.