| Crates.io | gguf-rs-lib |
| lib.rs | gguf-rs-lib |
| version | 0.2.5 |
| created_at | 2025-09-02 03:12:14.083551+00 |
| updated_at | 2025-09-02 03:28:58.202435+00 |
| description | A Rust library for reading and writing GGUF (GGML Universal Format) files |
| homepage | https://github.com/ThreatFlux/gguf_rs |
| repository | https://github.com/ThreatFlux/gguf_rs |
| max_upload_size | |
| id | 1820518 |
| size | 1,934,776 |
A Rust library for reading and writing GGUF (GGML Universal Format) files, designed for machine learning model storage and manipulation.
GGUF (GGML Universal Format) is a binary format for storing machine learning models, particularly those used with the GGML library. This crate provides a safe, efficient, and ergonomic interface for working with GGUF files in Rust.
Add this to your Cargo.toml:
[dependencies]
gguf-rs-lib = "0.2.0"
use gguf_rs_lib::{GGUFFile, GGUFError};
use std::fs::File;
fn main() -> Result<(), GGUFError> {
// Read a GGUF file
let file = File::open("model.gguf")?;
let gguf = GGUFFile::read(file)?;
// Access metadata
println!("Model name: {}", gguf.metadata().get("general.name").unwrap());
println!("Number of tensors: {}", gguf.tensors().len());
// Iterate over tensors
for tensor in gguf.tensors() {
println!("Tensor: {} ({:?})", tensor.name(), tensor.shape());
}
Ok(())
}
async feature)use gguf_rs_lib::{GGUFFile, GGUFError};
use tokio::fs::File;
#[tokio::main]
async fn main() -> Result<(), GGUFError> {
let file = File::open("model.gguf").await?;
let gguf = GGUFFile::read_async(file).await?;
// Work with the GGUF file asynchronously
println!("Loaded {} tensors", gguf.tensors().len());
Ok(())
}
mmap feature)use gguf_rs_lib::{GGUFFile, GGUFError};
fn main() -> Result<(), GGUFError> {
// Memory map a large GGUF file for efficient access
let gguf = GGUFFile::mmap("large_model.gguf")?;
// Access data without loading entire file into memory
for tensor in gguf.tensors() {
let data = tensor.data(); // Zero-copy access to tensor data
// Process tensor data...
}
Ok(())
}
The gguf-cli tool provides command-line access to GGUF functionality:
# Install the CLI tool
cargo install gguf --features=cli
# Inspect a GGUF file
gguf-cli info model.gguf
# List all tensors
gguf-cli tensors model.gguf
# Extract metadata
gguf-cli metadata model.gguf --format json
# Validate file integrity
gguf-cli validate model.gguf
std (default): Standard library supportasync: Async I/O support with Tokiommap: Memory mapping support for large filescli: Build the command-line toolThis library is designed for performance:
Benchmarks show that gguf_rs can parse large GGUF files significantly faster than equivalent Python implementations.
This crate uses only safe Rust by default. The optional mmap feature uses memory mapping, which involves some inherent platform-specific risks, but the API remains safe to use.
Contributions are welcome! Please see our Contributing Guide for details.
# Clone the repository
git clone https://github.com/ThreatFlux/gguf_rs.git
cd gguf_rs
# Run tests
cargo test
# Run benchmarks
cargo bench
# Check formatting and linting
cargo fmt --check
cargo clippy -- -D warnings
This project is licensed under the MIT License - see the LICENSE file for details.