Expand description
Model-inference runtime (honest module name: crate::inference_runtime).
This is the runtime that runs model inference — not an “AI engine”. It does two ordinary
systems jobs: (1) reads the GGUF weight file format (tensors memory-mapped via memmap2,
zero heap copy) and (2) dispatches the tensor program to a GPU backend (DirectML 1.15 on
Windows x64; wgpu/WGSL — Vulkan/Metal/WebGPU — elsewhere).
The mathematics of inference is not here and is not proprietary: it lives in crate::solvers
as named STEM — GEMM (linear_algebra::gemm), activations/softmax/normalization
(activation), attention (attention), RoPE (rope), the SwiGLU FFN (feed_forward) — and
each kernel in this crate is proven equal to that library definition (the *_stem_parity_tests
and substrate_parity_tests). What remains here is plumbing: GPU command encoding, the KV
cache, weight loading, the autoregressive loop, and the GGUF/dequant codec.
Re-exports§
pub use crate::ggml_quants::fetch_token_embedding;pub use crate::ggml_quants::ExecutionError;
Modules§
- wasm_
cpu - Prepared CPU execution floor for browser WASM. This backend owns no wgpu objects and remains available when the browser exposes no WebGPU adapter. Qualia’s CPU-WASM LLM backend.
Structs§
- Gguf
Load Report - KvCache
Layout - Static ring-buffer KV layout:
[layer][slot][K | V]in f32, OR (W5a int8 mode) packed int8 + per-(slot,kv_head) f32 scale in the same 4-byte-element buffer.total_f32_elemscounts 4-byte slots either way (u32/f32 share the size), so the allocation math is unchanged. - QTensor
- Represents a Q4_K Quantized or standard float Tensor mapped from a monolithic GGUF file.
- QTensor
Engine - Streaming
Argmax Result - Streaming argmax result across chunked vocabulary projection.
Constants§
- KV_
ATTENTION_ MASK_ WORDS - KV attention bitmask words uploaded to
fused_attention.wgslbinding 5. - KV_
CACHE_ MAX_ BYTES - Maximum bytes for the static KV arena (load-time allocation only).
- MAX_
CONTEXT_ WINDOW - Hard context ceiling — sized to keep KV arena under the 512MB RAM floor (Gemma 42L).
- MAX_
PREFILL_ BATCH_ FLOATS - Max stacked embedding floats in a prefill chunk (
MAX_STACK_GEMM_IN × 64). - PREFILL_
CHUNK_ SIZE - Prompt tokens per prefill GPU batch (stack + staging footprint =
emb_dim ×this). - PREFILL_
CHUNK_ STACK_ FLOATS llm_agentstack chunk buffer (Gemma 2560 × 64).- VOCAB_
CHUNK_ ROWS - Vocabulary projection rows per chunked logits sweep. 10240 is the native GEMM output-buffer ceiling and a 256-row multiple, so resident logits chunk offsets stay storage-binding aligned while the current 49k-vocab model drops from six output chunks/token to five.
Statics§
- GPU_
WAIT_ COUNT - Decode-profiler: count of GPU
submit → poll(Maintain::Wait)round-trips. Incremented byQTensorEngine::poll_wait(every native blocking sync point routes through it); read/reset by the bench to derive per-token synchronization overhead.
Functions§
- dequantize_
token_ embedding_ into - Dequantize a mmap embedding row into caller-supplied
out(no heap allocation). - gpu_
wait_ count - Total native GPU blocking-wait round-trips since the last reset.
- reset_
gpu_ wait_ count - Reset the GPU blocking-wait counter before a measured run.