Expand description
Format-independent checkpoint and tensor access.
Checkpoint is one consumer-facing contract over GGUF and
Safetensors. Research code can inventory tensors, read metadata, and
fetch raw payload bytes without branching on the container format:
use engram_parser::{Checkpoint, open_checkpoint};
fn inventory(ckpt: &dyn Checkpoint) -> engram_parser::Result<()> {
println!("{} from {}", ckpt.format(), ckpt.source().path.display());
for t in ckpt.tensors() {
println!("{} {} {:?} {}B", t.name, t.dtype, t.shape.dims(), t.byte_len);
}
if let Some(first) = ckpt.tensors().first() {
assert_eq!(ckpt.tensor_bytes(&first.name)?.len(), first.byte_len);
}
Ok(())
}
let ckpt = open_checkpoint("model.gguf")?;
inventory(&ckpt)?;§Backends
The backends are thin adapters over the existing format modules, which stay fully reachable:
| Backend | Wraps | Feature | Payload |
|---|---|---|---|
GgufBackend | crate::GgufLayout | default | borrowed |
GgufMmapBackend | GgufLayoutMmap | mmap | borrowed |
SafetensorsBackend | safetensors::SafetensorsCheckpoint | safetensors | owned (bounded read) |
SafetensorsMmapBackend | safetensors::SafetensorsCheckpointMmap | safetensors + mmap | borrowed |
open_checkpoint picks a backend at runtime and returns an
AnyCheckpoint, whose as_* accessors hand back the
format-specific handle (for example GgufLayout for
crate::analysis::moe::list_experts /
crate::analysis::moe::extract_expert).
§Contract
- Inventory order.
Checkpoint::tensorsis sorted by name and identical across calls and across owned/mmap backends of one file. - Shape order.
TensorShape::dimsis outermost-first for every format. GGUF dims (innermost-first on disk) are reversed;TensorShape::native_dimsrestores the on-disk order. - Dtypes. Plain scalar types normalize to shared variants. GGML
quantized layouts stay
TensorDType::GgufPackedwith the exact wire code;TensorInfo::native_dtypekeeps the source label. - Payloads.
Checkpoint::tensor_bytesreturns raw bytes exactly as stored (no decode, no dequant, packed blocks intact), with length equal toTensorInfo::byte_len. Borrowed for GGUF and mmap backends; owned for the bounded-read Safetensors backend. - Location.
TensorLocation::sourceis relative toCheckpointSource::root;data_offsetis relative to the file’s tensor-data section;file_offsetis absolute when known. - Errors. Unknown names return
crate::ParserError::MissingTensor.
This module has no numerical execution, device, or MoE concepts. Model topology and role discovery are out of scope.
Structs§
- Checkpoint
Metadata - Sorted metadata key-value store.
- Checkpoint
Source - Identity of an opened checkpoint: format, input path, and payload files.
- Gguf
Backend Checkpointover an ownedGgufLayout(whole file in memory).- Gguf
Mmap Backend Checkpointover a memory-mappedcrate::GgufLayoutMmap.- Safetensors
Backend Checkpointover aSafetensorsCheckpoint(bounded per-tensor reads).- Safetensors
Mmap Backend Checkpointover a memory-mappedcrate::safetensors::SafetensorsCheckpointMmap(borrowed payloads).- Tensor
Info - Format-independent description of one tensor.
- Tensor
Location - Where a tensor payload lives.
- Tensor
Shape - Tensor shape normalized to outermost-first order.
Enums§
- AnyCheckpoint
- A checkpoint whose backend was chosen at runtime.
- Checkpoint
Format - On-disk checkpoint container format.
- DimOrder
- Order of
TensorShape::dimsin the format’s native directory. - Metadata
Value - Owned scalar metadata value.
- Source
Kind - How the checkpoint input was laid out on disk.
- TensorD
Type - Normalized tensor element type.
Traits§
- Checkpoint
- Consumer-facing, format-independent checkpoint contract.
Functions§
- open_
checkpoint - Open any supported checkpoint, reading GGUF into memory and serving Safetensors with bounded per-tensor reads.
- open_
checkpoint_ mmap - Like
open_checkpoint, but memory-maps GGUF files and Safetensors shards so payloads are borrowed from the mappings.