gguf_rs
A Rust library for reading and writing GGUF (GGML Universal Format) files, designed for machine learning model storage and manipulation.
Overview
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.
Features
- ๐ Fast and Memory Efficient: Zero-copy parsing where possible with optional memory mapping support
- ๐ Type Safe: Strongly typed API that prevents common errors when working with GGUF files
- ๐ฆ Serde Integration: Built-in serialization and deserialization support
- ๐ฏ No Unsafe Code: Pure safe Rust implementation (by default)
- ๐ Async Support: Optional async I/O support with Tokio
- ๐ ๏ธ CLI Tool: Command-line utility for inspecting and manipulating GGUF files
- ๐ Well Documented: Comprehensive documentation with examples
- ๐งช Thoroughly Tested: Extensive test suite including property-based tests
Quick Start
Add this to your Cargo.toml:
[]
= "0.2.0"
Basic Usage
use ;
use File;
Async Usage (with async feature)
use ;
use File;
async
Memory Mapping (with mmap feature)
use ;
CLI Tool
The gguf-cli tool provides command-line access to GGUF functionality:
# Install the CLI tool
# Inspect a GGUF file
# List all tensors
# Extract metadata
# Validate file integrity
Feature Flags
std(default): Standard library supportasync: Async I/O support with Tokiommap: Memory mapping support for large filescli: Build the command-line tool
Performance
This library is designed for performance:
- Zero-copy parsing where possible
- Optional memory mapping for large files
- Efficient tensor data access
- Minimal allocations during parsing
Benchmarks show that gguf_rs can parse large GGUF files significantly faster than equivalent Python implementations.
Safety
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.
Contributing
Contributions are welcome! Please see our Contributing Guide for details.
Development Setup
# Clone the repository
# Run tests
# Run benchmarks
# Check formatting and linting
License
This project is licensed under the MIT License - see the LICENSE file for details.
Authors
- Claude Code
- Wyatt Roersma
Acknowledgments
- The GGML project for the GGUF format specification
- The Rust community for excellent crates that make this library possible