gguf

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gguf reads the metadata header of a GGUF model file: enough of it to size the KV cache exactly (flockd#46) and to learn the training context when the catalog does not say. Tensor data is never touched.

Format (v2/v3, little-endian): magic "GGUF", uint32 version, uint64 tensor count, uint64 kv count, then kv pairs of (string key, uint32 type, value). Arrays carry an element type and count. The tokenizer vocabulary lives in these pairs too, so a header can be several MB; values we do not need are skipped, not stored.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Meta

type Meta struct {
	Architecture    string
	BlockCount      int // transformer layers
	HeadCount       int
	HeadCountKV     int // total across layers when the header lists per-layer counts
	HeadCountKVList bool
	EmbeddingLength int
	KeyLength       int // per head; defaults to EmbeddingLength/HeadCount
	ValueLength     int
	ContextLength   int // training window
}

Meta is the subset of the header that sizing needs. Zero means absent.

func Read

func Read(r io.Reader) (Meta, error)

Read parses the header from r.

func ReadMeta

func ReadMeta(path string) (Meta, error)

ReadMeta reads the header of the GGUF at path. For a sharded model pass the first shard: that is where the metadata lives.

func (Meta) KVBytesPerToken

func (m Meta) KVBytesPerToken() int64

KVBytesPerToken is the f16 KV-cache cost of one context token across all layers: 2 (K and V) × layers × kv heads × head size × 2 bytes. That is what llama-server allocates per --ctx-size token with its default cache type; models whose header lacks the geometry return 0 so callers fall back to their heuristic. Sliding-window and MLA architectures cost less than this figure, never more, so the estimate errs safe.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL