gguf

Library Listed

GGUF file parser

Checked · Sources

Downloads
2,472
Dependents
4
Stars
25
Forks
5
Contributors
5
Commits
94
Latest release
0.1.8 ·

About

From the project README ·

GGUF-RS

A Rust library for parsing and reading GGUF (GGML Universal Format) files. GGUF files are binary files that contain key-value metadata and tensors, commonly used for storing quantized machine learning models.

Features

  • ✅ Decode GGUF files (v1, v2, v3)
  • ✅ Access key-value metadata
  • ✅ Access tensor information
  • ✅ Support for little-endian and big-endian files
  • ✅ CLI tool for quick inspection
  • ✅ Zero-copy metadata access
  • ✅ Memory-mapped file support (optional mmap feature)
  • ✅ Async I/O support (optional async feature)
  • ✅ Write GGUF files

Installation

Add to your Cargo.toml:

[dependencies]
gguf-rs = "0.1"

Or install the CLI tool:

cargo install gguf-rs

Usage

Library

Basic usage:

use gguf_rs::get_gguf_container;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Open a GGUF file
    let mut container = get_gguf_container("model.gguf")?;
    let model = container.decode()?;

    // Print model info
    println!("GGUF version: {}", model.get_version());
    println!("Architecture: {}", model.model_family());
    println!("Parameters: {}", model.model_parameters());
    println!("File type: {}", model.file_type());
    println!("Number of tensors: {}", model.num_tensor());

    Ok(())
}
Read the full README

Access specific metadata:

use gguf_rs::get_gguf_container;

let mut container = get_gguf_container("model.gguf")?;
let model = container.decode()?;

// Get specific metadata values
let metadata = model.metadata();
if let Some(arch) = metadata.get("general.architecture") {
    println!("Architecture: {}", arch);
}

// Check context length
if let Some(ctx_len) = metadata.get("llama.context_length") {
    println!("Context length: {}", ctx_len);
}

Work with tensors:

use gguf_rs::get_gguf_container;

let mut container = get_gguf_container("model.gguf")?;
let model = container.decode()?;

// List all tensors
for tensor in model.tensors() {
    println!("{}: shape={:?}, offset={}, size={}", 
        tensor.name, tensor.shape, tensor.offset, tensor.size);
}

// Find specific tensor
let embed_tensor = model.tensors()
    .iter()
    .find(|t| t.name.contains("token_embd"));
    
if let Some(tensor) = embed_tensor {
    println!("Embedding tensor shape: {:?}", tensor.shape);
}

Read full tokenizer vocabulary:

use gguf_rs::get_gguf_container_array_size;

// Use get_gguf_container_array_size to read full arrays
// (default get_gguf_container truncates arrays to 3 elements)
let mut container = get_gguf_container_array_size("model.gguf", u64::MAX)?;
let model = container.decode()?;

// Now you can access full tokenizer arrays
let metadata = model.metadata();
if let Some(tokens) = metadata.get("tokenizer.ggml.tokens") {
    println!("Vocabulary size: {:?}", tokens);
}
CLI

Show model metadata:

gguf path_to_your_model.gguf

Show tensors:

gguf path_to_your_model.gguf --tensors

Supported GGML Types

TypeDescription
F3232-bit float
F1616-bit float
Q4_04-bit quantization (type 0)
Q4_14-bit quantization (type 1)
Q5_05-bit quantization (type 0)
Q5_15-bit quantization (type 1)
Q8_08-bit quantization (type 0)
Q2_K - Q6_KK-quant types
IQ seriesI-quant types (IQ1_S, IQ2_XXS, etc.)
BF16Brain float 16

API Documentation

Full API documentation is available at docs.rs/gguf-rs.

Performance

  • Zero-copy metadata access: Metadata is parsed once and stored in memory for fast repeated access
  • Lazy tensor data: Tensor metadata is parsed, but actual tensor data is not loaded into memory
  • Array truncation: By default, arrays in metadata are truncated to 3 elements for performance. Use get_gguf_container_array_size() with u64::MAX to read full arrays when needed
Memory Usage

The library has minimal memory overhead:

  • Metadata storage: O(n_kv + n_tensors) where n_kv = number of key-value pairs, n_tensors = number of tensors
  • No tensor data is loaded into memory unless explicitly requested
Memory-Mapped Files

For large GGUF files (multiple GB), use the mmap feature for efficient access:

[dependencies]
gguf-rs = { version = "0.1", features = ["mmap"] }
use gguf_rs::mmap::MmapGGUF;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mmap = MmapGGUF::open("large_model.gguf")?;
    let model = mmap.decode()?;
    
    println!("Architecture: {}", model.model_family());
    println!("Tensors: {}", model.num_tensor());
    
    Ok(())
}

Benefits of memory mapping:

  • Lazy loading: Only accessed pages are loaded into memory
  • OS-managed paging: The operating system handles memory management
  • Fast random access: Direct pointer access to file data
Async I/O

For async applications, enable the async feature:

[dependencies]
gguf-rs = { version = "0.1", features = ["async"] }
use gguf_rs::async_io::AsyncGGUF;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut container = AsyncGGUF::open("model.gguf").await?;
    let model = container.decode().await?;

    println!("Architecture: {}", model.model_family());
    println!("Tensors: {}", model.num_tensor());

    Ok(())
}
Writing GGUF Files

Create and write GGUF files:

use gguf_rs::writer::{GGUFWriter, TensorInfo};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create writer for GGUF v3
    let mut writer = GGUFWriter::new("output.gguf", 3)?;

    // Add metadata
    writer.add_metadata("general.architecture", "llama");
    writer.add_metadata_u32("llama.block_count", 12);
    writer.add_metadata_f32("test.value", 3.14);

    // Add tensor info
    let tensor = TensorInfo {
        name: "token_embd.weight".to_string(),
        shape: vec![4096, 32000],
        dtype: 0, // F32
    };
    writer.add_tensor(tensor);

    // Write header and metadata
    writer.write()?;

    // Write tensor data
    let data: Vec<u8> = vec![0; 4096 * 32000 * 4]; // F32 = 4 bytes
    writer.write_tensor_data(0, &data)?;

    // Finalize
    writer.finalize()?;

    Ok(())
}

Compatibility

  • Rust version: Requires Rust 1.56+ (edition 2021)
  • GGUF versions: Supports v1, v2, and v3
  • Byte order: Both little-endian and big-endian files
  • Platforms: Works on all platforms supported by Rust (Linux, macOS, Windows, BSD, etc.)

Testing

cargo test

Benchmarks

Run performance benchmarks:

cargo bench

Benchmarks measure:

  • File parsing performance
  • Metadata access speed
  • Tensor iteration overhead

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and clippy
  5. Submit a pull request

Security

Please report security vulnerabilities to zackshen0526@gmail.com. See SECURITY.md for more information.

GGUF Specification

This library implements the GGUF specification.

License

MIT License - see LICENSE for details.

Credits

Runs on
GPU support unknown
What shows it
  • no dependency or feature matches a backend row
Native code
None found
  • No native code found
Python bindings
No Python binding crate found
License
MIT

Compare with similar projects

Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.

gguf beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
gguf This page Listed

GGUF file parser

2,472 downloads over 30 days 4 25 0.1.8 GPU support unknown No native code found MIT
safetensors Featured

Provides functions to read and write safetensors which aim to be safer than their PyTorch counterpart.

5,486,837 downloads over 30 days 531 3,943 0.8.0 GPU support unknown No native code found Apache-2.0

Minimal ONNX model loader for extracting weights, tensors, operations, and graph structure

3,975 downloads over 30 days 4 6 0.5.2 GPU support unknown No native code found MIT
onnx-rs Listed

Zero-dependency ONNX model parser in Rust

453 downloads over 30 days 5 6 0.1.3 GPU support unknown No native code found MIT
cmf App Listed

One backbone, many specialists. CMF is a self-describing, memory-mappable single-file format and a dependency-free runtime for quantized LLMs — zero-copy execution on CPU or GPU (Vulkan · Metal · DX12) that overlays task-specialized skills onto one shared model, with no per-model duplication.

24 binary downloads per release Not applicable 52 Not measured Not measured Apache-2.0
compressr App New

Model conversion and quantization with no Python: reads SafeTensors, GGUF, TCF and PyTorch state dicts, writes SafeTensors, GGUF and TCF, and quantizes to Q2_K through Q8_0 and IQ4 formats, including Q4_K_M mixes. GPTQ, AWQ, NF4, FP8, EXL2 and ONNX input are not implemented.

Python bindings

23 downloads over 30 days Not applicable 0 0.2.1 GPU support unknown No native code found Apache-2.0
Why ListedNo archive, New or Featured rule places it, so it is Listed.

What it lacks for Featured

  • It has 3 active dependents and 3 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 25 stars, 5 forks and 5 contributors. It needs 4,539 stars, 434 forks and 79 contributors together.

What else the check found

  • The last activity is on 15 Jun 2026, 147 days ago. The rules expect an update within 400 days. Dormancy rule

Exact rules: Listed, Featured library. The check on applied thresholds version 9.

Every rule outcome, as the check records it
  • expected-interval: version 0.1.8 base 450, capped at 8 releases = 400: E = 400 days
  • dormancy: last activity 2026-06-15, 147 days ago, E = 400: active
  • featured: not featured: active_users 3 < 11 and new_adopters 3 < 9 and repository route stars 25 (needs 4539), forks 5 (needs 434), contributors 5 (needs 79)
  • listed: listed: no archive, new or featured rule applies

Measurements and sources

Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.

Sources6 sources
Adoption3 active dependents, 3 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents3crates.io database dumpYes
New dependents (365 days)3crates.io database dumpYes
Peak active dependents3crates.io database dumpYes
Active dependents as a share of the peak1crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 4 months ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-06-15GitHub repositoryYes
Latest release2026-06-15crates.io database dumpYes
First release2024-01-04crates.io database dumpYes
Latest version0.1.8crates.io database dumpYes
Days the oldest outside issue waits for a reply90GitHub repositoryYes
Maintainer replies over 365 days6GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementnonecrates.io database dumpYes
Distribution8 releases, 2,472 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases8crates.io database dumpYes
Downloads over 30 days2472crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository25 stars, 5 forks, 5 contributors, 94 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars25GitHub repositoryYes — one part of the repository route
GitHub forks5GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account5GitHub contributorsYes — one part of the repository route
Commits on the default branch94GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseMITcrates.io database dumpNo
Runs on, from listed crates and their direct dependenciesGPU support unknowncrates.io database dumpNo
What shows each backendno dependency or feature matches a backend rowcrates.io database dumpNo
Native code, from listed crates and their dependenciesNo native code foundcrates.io database dumpNo
Python bindings, from direct dependencies of listed cratesNo Python binding crate foundcrates.io database dumpNo
Crates that depend on a listed crate directly4crates.io database dumpNo

Corrections and review history

Report a correction

No correction applies to this entry.

Judgments

A judgment enters only through an approved issue and a merged pull request.

No judgment applies to this entry.