Skip to main content

Module checkpoint

Module checkpoint 

Source
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:

BackendWrapsFeaturePayload
GgufBackendcrate::GgufLayoutdefaultborrowed
GgufMmapBackendGgufLayoutMmapmmapborrowed
SafetensorsBackendsafetensors::SafetensorsCheckpointsafetensorsowned (bounded read)
SafetensorsMmapBackendsafetensors::SafetensorsCheckpointMmapsafetensors + mmapborrowed

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

This module has no numerical execution, device, or MoE concepts. Model topology and role discovery are out of scope.

Structs§

CheckpointMetadata
Sorted metadata key-value store.
CheckpointSource
Identity of an opened checkpoint: format, input path, and payload files.
GgufBackend
Checkpoint over an owned GgufLayout (whole file in memory).
GgufMmapBackend
Checkpoint over a memory-mapped crate::GgufLayoutMmap.
SafetensorsBackend
Checkpoint over a SafetensorsCheckpoint (bounded per-tensor reads).
SafetensorsMmapBackend
Checkpoint over a memory-mapped crate::safetensors::SafetensorsCheckpointMmap (borrowed payloads).
TensorInfo
Format-independent description of one tensor.
TensorLocation
Where a tensor payload lives.
TensorShape
Tensor shape normalized to outermost-first order.

Enums§

AnyCheckpoint
A checkpoint whose backend was chosen at runtime.
CheckpointFormat
On-disk checkpoint container format.
DimOrder
Order of TensorShape::dims in the format’s native directory.
MetadataValue
Owned scalar metadata value.
SourceKind
How the checkpoint input was laid out on disk.
TensorDType
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.