Module format

Module format 

Source
Expand description

Aprender Model Format (.apr)

Binary format for ML model serialization with built-in quality (Jidoka):

  • CRC32 checksum (integrity)
  • Ed25519 signatures (provenance)
  • AES-256-GCM encryption (confidentiality)
  • Zstd compression (efficiency)
  • Quantization (Q8_0, Q4_0, Q4_1 - GGUF compatible)
  • Streaming/mmap (JIT loading)

§Format Structure

┌─────────────────────────────────────────┐
│ Header (32 bytes, fixed)                │
├─────────────────────────────────────────┤
│ Metadata (variable, MessagePack)        │
├─────────────────────────────────────────┤
│ Chunk Index (if STREAMING flag)         │
├─────────────────────────────────────────┤
│ Salt + Nonce (if ENCRYPTED flag)        │
├─────────────────────────────────────────┤
│ Payload (variable, compressed)          │
├─────────────────────────────────────────┤
│ Signature Block (if SIGNED flag)        │
├─────────────────────────────────────────┤
│ Checksum (4 bytes, CRC32)               │
└─────────────────────────────────────────┘

§Example

use aprender::format::{save, load, ModelType, SaveOptions};
use aprender::linear_model::LinearRegression;

let model = LinearRegression::new();
// ... train model ...

// Save with compression
save(&model, ModelType::LinearRegression, "model.apr", SaveOptions::default())?;

// Load with verification
let loaded: LinearRegression = load("model.apr", ModelType::LinearRegression)?;

Re-exports§

pub use model_card::ModelCard;
pub use model_card::TrainingDataInfo;

Modules§

gguf
GGUF Export (spec §7.2)
model_card
Model Card for .apr format (spec §11)

Structs§

DistillationInfo
Complete distillation provenance (spec §6.3.2)
DistillationParams
Distillation hyperparameters (spec §6.3.2)
Flags
Feature flags (bitmask) - spec §3.2
Header
File header (32 bytes)
LayerMapping
Layer mapping for progressive distillation (spec §6.3.2)
LicenseInfo
Commercial license information (spec §9.1)
Metadata
Model metadata (MessagePack-encoded)
ModelInfo
Model information (from inspection)
SaveOptions
Options for saving models
TeacherProvenance
Teacher model provenance for audit trails (spec §6.3.2)
TrainingInfo
Training information

Enums§

Compression
Compression algorithm
DistillMethod
Distillation method used (spec §6.3.1)
LicenseTier
License tier levels (spec §9.1)
ModelType
Model type identifiers

Constants§

FORMAT_VERSION
Current format version (1.0)
HEADER_SIZE
Header size in bytes
MAGIC
Magic number: “APRN” in ASCII (0x4150524E)
MAX_UNCOMPRESSED_SIZE
Maximum uncompressed size (1GB safety limit)
MMAP_THRESHOLD
Threshold for switching to mmap loading (1MB)

Functions§

inspect
Inspect a model file without loading the payload
inspect_bytes
Inspect model data without loading the payload (spec §1.1)
load
Load a model from .apr format
load_auto
Load a model with automatic strategy selection based on file size
load_from_bytes
Load a model from a byte slice (spec §1.1 - Single Binary Deployment)
load_mmap
Load a model using memory-mapped I/O (zero-copy where possible)
save
Save a model to .apr format