apr-format
Sovereign .apr model container format — read + write, zero ML/GPU/tokenizer
dependencies.
apr-format is the leaf crate that owns the on-disk .apr container. It was
extracted from aprender-core (issue #2231 — "depend on the format, not the
framework") so that downstream consumers — realizar inference, xpile,
external tooling — can load and save .apr files without pulling the full
ML / GPU / tokenizer / quantization stack. aprender-core re-exports this
crate's public surface, so the extraction is API-compatible: existing
aprender::format::* paths keep working with no break.
Installation
[]
= "0.50"
# Optional: zero-copy memory-mapped loading (v2 container)
= { = "0.50", = ["mmap"] }
# Optional: LZ4 + Zstd payload compression (v1 container)
= { = "0.50", = ["compression"] }
# Everything except the security seams
= { = "0.50", = ["full"] }
What it is
- Container I/O only. Read and write the
.aprmodel container in two versions: v1 (APRNmagic) and the streaming, constant-memory v2 (APR\0). - Dependency-light. Structural dependencies are just
serde,rmp-serde,bincode,serde_json,half, andthiserror. Notrueno, no autograd, no tokenizer. - std-only (v1).
no_stdis an explicit deferred decision. - Structure vs. physics. The byte-only structural validator
(
validate_structure) is separated from framework-level "physics" checks so a corrupt file can be diagnosed without loading tensors into an ML runtime.
The GGUF / SafeTensors / ONNX converter deliberately stays in
aprender-core — it needs f32 physics and the ML stack. Only the container
moves here.
Usage
use ;
// Write a model's weights to an .apr container
let weights: = vec!;
save?;
// Read them back (v1/v2 auto-detected)
let restored: = load?;
assert_eq!;
// Inspect a container's header/metadata without deserializing tensors
let header = inspect?;
// Byte-only structural validation (no ML runtime required)
let check = validate_structure;
# Ok::
Zero-copy loading (with the mmap feature) and load-from-bytes helpers are also
exposed via load_mmap, load_auto, load_from_bytes, and inspect_bytes.
Features
| Feature | Description |
|---|---|
mmap |
Zero-copy memory-mapped loading of the v2 container (memmap2) |
compression |
LZ4 + Zstd payload compression for the v1 container |
encryption |
Placeholder seam for the sovereign-leaf security surface (Stage 2+) |
signing |
Placeholder seam for the sovereign-leaf security surface (Stage 2+) |
full |
Convenience meta-feature: mmap + compression (no security seams) |
Public surface
save/load/load_auto/load_from_bytes/load_mmap— container I/Oinspect/inspect_bytes— header + metadata inspectionvalidate_structure/StructureCheck— byte-only structural validationHeader,Metadata,Flags,ModelType,ModelInfo,SaveOptions,Compression— the container typesModelCard/TrainingDataInfo— model-card metadatacrc32,f32_to_f16,f16_to_f32— the deduplicated primitivesAprFormatError/Result— the sovereign error seam (aprender-coreFrom-wraps it)
License
MIT OR Apache-2.0
Part of the Aprender monorepo — a next-generation ML framework in pure Rust. See github.com/paiml/aprender for the full workspace, contracts, and book.