Skip to main content

frink_inference/
lib.rs

1//! Frink — a pure-Rust GGUF / MoE inference engine.
2//!
3//! This crate is a **facade**. It contains no logic of its own: it
4//! re-exports the workspace under one name so a dependent writes one
5//! line in `Cargo.toml` instead of six, and so the project is findable
6//! on crates.io (the name `frink` belongs to an unrelated crate).
7//!
8//! The command-line tools are not here. `cargo install frink-cli`
9//! installs the `frink` binary; `frink-server` is the
10//! OpenAI-compatible HTTP server. Shipping a second binary called
11//! `frink` from this crate would just fight the first one over
12//! `~/.cargo/bin`.
13//!
14//! # Layout
15//!
16//! The stack, bottom to top:
17//!
18//! | Module | Crate | What it is |
19//! |---|---|---|
20//! | [`gguf`] | `frink-gguf` | GGUF mmap reader, sharded checkpoints |
21//! | [`quant`] | `frink-quant` | Block layouts and fused dequant+dot |
22//! | [`safetensors`] | `frink-safetensors` | SafeTensors mmap reader |
23//! | [`core`] | `frink-core` | Tensor ops, RoPE, GQA, KV cache |
24//! | [`edge`] | `frink-edge` | Serving policy: `q*` split, radix prefix caches, output parsers |
25//! | [`moe`] | `frink-moe` | Expert routing and dispatch |
26//! | [`models`] | `frink-models` | Loaders and decoder stacks |
27//! | [`api`] | `frink-api` | Route constants + wire DTOs (feature `api`) |
28//!
29//! # Example
30//!
31//! ```no_run
32//! use frink_inference::gguf::ShardedGguf;
33//!
34//! let file = ShardedGguf::open("model.gguf")?;
35//! println!("{} tensors", file.tensor_count());
36//! # Ok::<(), Box<dyn std::error::Error>>(())
37//! ```
38//!
39//! # Features
40//!
41//! - `metal` — Apple Metal kernels. Apple Silicon only.
42//! - `cuda` — CUDA/NVRTC kernels. Needs a CUDA toolkit at build time.
43//!   Held to "must compile": there is no pinned benchmark host and no
44//!   published receipts for it. See `docs/FEATURES.md`.
45//! - `api` — pull in `frink-api` for client-side route constants.
46//!
47//! Neither GPU feature is on by default, because both are wrong to
48//! assume: `metal` does not build off Apple Silicon and `cuda` needs a
49//! toolkit that most machines do not have.
50
51#![forbid(unsafe_code)]
52
53pub use frink_core as core;
54pub use frink_gguf as gguf;
55pub use frink_models as models;
56pub use frink_moe as moe;
57pub use frink_quant as quant;
58pub use frink_safetensors as safetensors;
59
60#[cfg(feature = "api")]
61pub use frink_api as api;
62
63/// The workspace version this facade was built from.
64///
65/// Every crate in the workspace shares one version, so this is the
66/// version of the whole engine, not just of the facade.
67pub const VERSION: &str = env!("CARGO_PKG_VERSION");
68
69#[cfg(test)]
70mod tests {
71    /// The facade is only useful if it actually re-exports. These
72    /// paths would fail to COMPILE -- not merely assert false -- if a
73    /// module were dropped from `lib.rs`, which is the failure mode
74    /// worth catching: a facade that silently stops re-exporting one
75    /// layer looks fine until a dependent upgrades and cannot build.
76    #[allow(dead_code)]
77    fn every_layer_is_reachable_through_the_facade() {
78        let _: Option<super::gguf::ShardedGguf> = None;
79        let _: Option<super::quant::QuantError> = None;
80        let _: Option<super::core::cache::KvCache> = None;
81        let _: Option<super::safetensors::SafetensorsFile> = None;
82        let _ = std::mem::size_of::<super::models::Decoder>();
83        let _ = std::mem::size_of::<super::moe::MoeLayerConfig>();
84    }
85
86    #[test]
87    fn version_is_the_workspace_version() {
88        assert_eq!(super::VERSION, env!("CARGO_PKG_VERSION"));
89        assert!(!super::VERSION.is_empty());
90    }
91}