Files
leleka/crates/model-format
Pavlo RatushnyiandClaude Sonnet 5.5 97c33d8b2c Offline differentials: port the Strata 0.1.50 chat-template empty-turn filter, GGUF types 143-146, native PLE key types; fix two stale smokes
chat template (prompt bytes): ChatTemplate.render (#843) drops completed empty assistant turns
(no text after strip, no picture, no tool calls; the final message is kept; STRATA_KEEP_EMPTY_TURNS=1
keeps them) before the template runs. prompt.rs now does the same in Renderer::render and in the typed
render_with_images path. diff_chat_template: 136/3000 -> 0 (also 2 x 12000). chat_template_oracle.json
regenerated from the Original; one responses.rs test asserted the old behaviour.

gguf: block_geometry knows the APR trellis types 143-146 (PTQ1_0, TQ2_T, TQK6, TQK7); gguf_headers.json
regenerated. diff_gguf_header: 188/400 -> 0.

native pack: NATIVE_PLE_KEY gained IQ3_XXS/IQ4_XS (#381); NVFP4 expert tails and prism.hadamard experts
are refused (not ported, the runtime reads neither). diff_native_pack f16_nan uses a quiet NaN (numpy's
widening of a signaling NaN differs between builds). The live differential still needs one run on Linux.

smoke-mtp-pack.py reads the Q8_0 names from required[]/wq(); Dockerfile.systemd-smoke drops its apt
version pins. docs/ci-audit.md findings 14, 15, 16, 18 updated in place.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 03:39:53 +01:00
..

Leleka model format foundation

leleka-model-format exposes the existing bounded GGUF v3 parser as an independent Rust crate. It depends directly on sha2 and the standard library; it has no build script, C/FFI shim, GGML, Strata process/source link, CUDA or Python dependency. The existing control plane reexports its gguf module, so preparation, inspection, tokenizer extraction and tensor-export consumers keep their public paths.

The original parser geometry and its three tests were moved unchanged from control-plane/src/gguf.rs. Tensor block geometry and the legacy Flash-Next metadata guard retain their upstream references; see the provenance record. Those helpers inspect metadata and byte layout, not tensor values or inference. Recognizing a quantization block size is not support for decoding or serving it.

Contract and limits

  • inspect validates GGUF v3 header structure and reports metadata/layout.
  • tensor_index additionally requires known block geometry, checked dimensions, alignment, bounded nonoverlapping tensor spans and consistent file bounds.
  • tensor_sha256 hashes one indexed tensor through a fixed 1 MiB buffer.
  • tokenizer_metadata extracts the existing Qwen35 tokenizer fields after header inspection; the separate tokenizer crate implements tokenization.
  • check_flash_next_profile is the existing specialized metadata admission check. It does not validate a complete model, tokenizer or numerical output.

All preexisting bounds/rejections remain unchanged. Path-based functions reopen the source; callers must keep the verified file stable between inspection and reading. File length checks do not detect same-size replacement or mutation. VerifiedGgufFile::open is a separate owned-file API: it accepts a sha256:<64 hex digits> artifact digest, opens one regular file, hashes the full file with a buffer of at most 64 KiB, and parses the strict tensor index through that same handle. The private file/index pair is retained; index() offers only an immutable borrow. stream_tensor validates a requested tensor number and byte range before delivering at most 64 KiB per callback, and tensor_sha256 hashes the indexed payload through that stream. Neither tensor operation reopens the pathname or allocates the full tensor. A consumer may explicitly collect chunks or return an I/O error to abort. Empty ranges at the tensor end are valid.

Renaming or replacing the original pathname after opening does not redirect this handle to a different file. The preliminary path metadata check rejects ordinary nonregular paths; the opened-file metadata check determines whether the accepted handle is regular. This does not make pathname lookup atomic against a malicious concurrent substitution during opening. The caller must supply a stable regular source for opening and prevent in-place writes for the entire verification, indexing and read lifetime. Keeping a file descriptor does not make its bytes immutable: even same-size writes to the same file remain visible and are not caught by file length checks. The stored artifact digest records verification at open, not a later content attestation. Size changes are refused before/after streaming, and short reads propagate errors; callbacks already delivered before an I/O failure cannot be retracted.

The existing path APIs and tensor geometry remain unchanged. Descriptor, tensor and tokenizer semantics, memory admission, GPU allocation, readiness and real-model parity remain separate work. The current strata-control still has its legacy GGML/build dependencies; extracting this crate does not remove them from that package or its runtime.

Standalone checks

cargo test --locked -p leleka-model-format
cargo clippy --locked -p leleka-model-format --all-targets -- -D warnings
cargo tree --locked -p leleka-model-format

These are container/parser checks with sanitized synthetic bytes. They do not establish inference, model quality, GPU operation or performance.

Owned-file tests use generated synthetic GGUF bytes: full-digest and tensor-byte oracles, multi-chunk and partial streaming, malformed digest, nonregular source, tamper, truncate, unsupported version/type and overlapping geometry rejection, range/overflow checks before callbacks, callback abort/recovery, Unix pathname replacement retaining the original file, and an explicit same-size in-place mutation counterexample. These tests do not qualify an immutable artifact store or a complete model loader.