Skip to content

About

Read a GGUF header and see what a file actually contains, without loading the weights

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

gguf-inspect

Read a GGUF header and see what a file actually contains, without loading the weights.

$ gguf-inspect stories15M-q4_0.gguf
stories15M-q4_0.gguf  18.19 MiB
  architecture   llama  (GGUF v3)
  name           llama
  parameters     24.41M  across 57 tensors
  context        128 tokens
  tokenizer      llama
  chat template  no
  bits/param     6.25

  quantization
    Q8_0                1 tensors     9.22M params    9.34 MiB   53.4%
    Q4_0               43 tensors    15.19M params    8.15 MiB   46.6%
    F32                13 tensors     3.74K params   14.62 KiB    0.1%

That output comes from the real file, unmodified.

Why

llama.cpp fails with messages like unknown model architecture or quantization type 36 is not supported by this build, and the usual way to find out why is to load a multi-gigabyte file and wait for it to fail. Everything needed to answer those questions sits in the file's header and tensor directory, a few kilobytes at the start of the file.

This reads that, and nothing else. No dependencies, no mmap of the weights, no model architecture assumptions.

Answers, in one command:

  • Which quantization is this, per tensor, and how much of the file is which
  • Does it carry a chat template, and which tokenizer does it expect
  • Context length, parameter count, bits per parameter
  • Is it part of a split set
  • Which GGUF version

Install

No dependencies, Python 3.10 or newer.

$ pip install git+https://github.com/abd1rahmane/gguf-inspect.git

Or just copy gguf_inspect/reader.py into your project, it has no imports outside the standard library.

Usage

$ gguf-inspect model.gguf                 # summary
$ gguf-inspect model.gguf --tensors       # every tensor, shape and quantization type
$ gguf-inspect model.gguf --json          # machine readable
$ gguf-inspect model.gguf --json --tensors

Exit codes: 0 parsed, 1 the file is not a readable GGUF, 2 the path does not exist. Usable as a pre-flight check:

$ gguf-inspect candidate.gguf --json | jq -e '.chat_template' && echo "ready for instruct prompts"

From Python:

from gguf_inspect import read_header

info = read_header("model.gguf")
print(info.architecture, info.context_length, info.quant_breakdown())

What it refuses to guess

  • A file whose magic is not GGUF is rejected, not partially parsed.
  • Version 1 (32-bit lengths) is rejected with a clear message, current tools cannot load it either.
  • A truncated file says how many bytes were missing, because that is the actual fault.
  • An unknown tensor type prints as unknown(36) rather than being mapped to a guess.

Test

$ python -m unittest discover -s tests -v

The tests write GGUF files byte by byte from the spec, so the parser is checked against the format rather than against another parser's output.

Licence: MIT.

About

Read a GGUF header and see what a file actually contains, without loading the weights

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages