gguf-rs
gguf-rs-lib is a Rust library for inspecting and creating
GGUF files. Its
stable path is synchronous GGUF v3 header, metadata, and tensor-descriptor I/O.
The API also includes tensor data helpers and optional preview APIs for Tokio
and memory mapping.
The crate does not execute models, quantize tensors, or provide inference.
Support at a glance
| Capability | Status |
|---|---|
| GGUF version | Version 3 only |
| Byte order | Little-endian only |
| Metadata | All GGUF value IDs 0–12; validated ASCII hierarchical keys |
| Tensor descriptors | Canonical type IDs 0–3, 6–30, 34–35, and 39–42 |
| Tensor dimensions | Exactly 1–4 dimensions per descriptor |
| Unquantized payloads | Raw read/write with exact size checks |
| Quantized payloads | Exact recognized block sizes; no codec |
| Synchronous reader/writer | Implemented with std |
no_std |
Data structures and helpers with alloc; no file/stream I/O |
Tokio async |
Preview: validates only magic and version |
mmap |
Preview: maps a file and validates only magic and version |
| CLI | Workspace inspection, validation, and comparison tool |
See format support and features before using the crate with quantized model payloads, async I/O, memory mapping, or untrusted files.
Install
The library package on crates.io is gguf-rs-lib:
[]
= "0.3"
The similarly named crates.io package gguf is unrelated. The source tree can
be ahead of the latest published gguf-rs-lib release; pin a Git revision when
depending directly on the repository. Version 0.3 corrects public tensor-type
discriminants; applications that cast or persist GGUFTensorType values should
review the migration note.
Read a file
use GGUFFileReader;
use Result;
use File;
GGUFFileReader::new parses the header, metadata, and tensor descriptors and
validates that declared payload ranges fit the source. It does not load tensor
payload bytes by default. Use load_tensor_data or load_all_tensor_data when
those bytes are needed.
Run the complete example with:
Create a file
use GGUFBuilder;
use Result;
The high-level builder is the recommended writing API. It computes relative
tensor offsets and validates raw payload lengths for the represented tensor
type. Tensor convenience methods return Result<GGUFBuilder> so invalid ranks,
payload sizes, and quantization block geometry fail at the call site.
Quantized inputs must already be encoded in the recognized GGML block layout;
the crate does not quantize values. The builder adds and validates
general.quantization_version = 2 whenever a quantized tensor is present.
Features
| Feature | Default | What it enables |
|---|---|---|
std |
Yes | File/stream I/O, builders, errors, Serde derives |
alloc |
Via std |
Allocating data structures for no_std builds |
async |
No | Tokio-based, header-only preview reader; implies std |
mmap |
No | Memory-map and byte-reader preview APIs; implies std |
The minimum supported Rust version is 1.87.
Useful checks:
A bare --no-default-features build is not a supported configuration; enable
alloc. Details and examples are in the feature guide.
CLI
gguf-cli is currently a workspace-only package. Install it from a clone:
Implemented paths include:
The CLI uses the complete synchronous parser. Directory validation checks
direct .gguf children or all descendants with --recursive; --integrity
also reads every declared tensor payload. Comparison checks metadata and tensor
descriptors by default and exact payload bytes with --data. These operations
do not provide a cryptographic integrity, authenticity, or model-correctness
guarantee. See the CLI guide.
Performance and safety
No cross-language or absolute performance claim is made. The synchronous reader parses metadata and descriptors eagerly and tensor bytes on request. Benchmark the operations, files, and feature set that match your workload.
The default feature set does not execute an unsafe block. The mmap feature
has an explicitly unsafe constructor because callers must ensure a mapped file
is not concurrently truncated or modified. Parsing also has defensive limits,
but it is not a complete semantic, checksum, or authenticity validation of a
model.
Read safety and validation for the exact boundaries.
Documentation
- Documentation index
- Changelog
- Format and type support
- Feature semantics
- Safety and validation
- CLI guide
- Examples
- Testing guide
- Contributing
API documentation is published on docs.rs.
Development
The workspace tracks Cargo.lock because it contains the gguf-cli
application. Use --locked in CI and release-oriented commands.
Security
See the security policy. Report suspected vulnerabilities through GitHub private vulnerability reporting; do not open a public issue for an undisclosed vulnerability.
License
Licensed under the MIT License.