Skip to main content

logicaffeine_compile/model/
mod.rs

1//! Models as data. A checkpoint's own metadata describes its architecture ([`spec`]); this module reads it — a GGUF
2//! file ([`gguf`]), or a Hugging Face directory of safetensors shards in place ([`hf`], [`safetensors`]) —,
3//! dequantizes its weights in every format a model ships in ([`quant`]), tokenizes text as the checkpoint's vocabulary
4//! does ([`tokenizer`]), hashes Qwen3.8-Flash-Next's n-gram embedding rows ([`ngram_hash`]), writes what it computes as
5//! a LOGOS program ([`author`]) whose weights it binds to the checkpoint's tensors ([`bind`]) as the layout its arms
6//! read presents them ([`layout`]), names each cut of that
7//! one program every backend lowers ([`program`]), and evaluates that computation in `f64` as the oracle every lane is
8//! measured against ([`reference`](mod@reference)).
9
10pub mod author;
11pub mod bind;
12pub mod gguf;
13pub mod hf;
14pub mod layout;
15pub mod ngram_hash;
16pub mod program;
17pub mod quant;
18pub mod reference;
19pub mod safetensors;
20pub mod spec;
21pub mod tokenizer;
22pub mod triage;
23
24/// A checkpoint a model is brought up from: its metadata, which [`spec::ModelSpec::from_source`] reads, and its tensors,
25/// which the reference and every host read through their bindings — a GGUF file or a Hugging Face directory.
26pub trait Checkpoint: spec::SpecSource + reference::WeightSource {}
27
28impl<T: spec::SpecSource + reference::WeightSource> Checkpoint for T {}
29
30/// The checkpoint at `path`: a Hugging Face directory (`config.json` beside its safetensors shards) or a GGUF file,
31/// presented in the layout the spec's arms read ([`layout::presented`]).
32pub fn open_checkpoint(path: &std::path::Path) -> std::io::Result<Box<dyn Checkpoint>> {
33    let opened: Box<dyn Checkpoint> =
34        if path.is_dir() { Box::new(hf::HfCheckpoint::open(path)?) } else { Box::new(gguf::Gguf::open(path)?) };
35    layout::presented(opened)
36}