Table of Contents

Class GgufMetadata

Namespace
LMKit.Model.Gguf
Assembly
LM-Kit.NET.dll

Purely managed reader for GGUF model metadata: the file header, the complete key-value store, and the tensor-info table. No native library is involved and tensor weights are never read, so inspection is near-instant even for very large files and is safe to run on untrusted input before native code touches it.

public sealed class GgufMetadata
Inheritance
GgufMetadata
Inherited Members

Remarks

GGUF versions 2 and 3 are supported. Malformed or hostile input (bad magic, truncated data, implausible counts, or declared sizes that exceed hard allocation ceilings) is rejected with InvalidModelException.

Properties

Architecture

Gets the model architecture (the general.architecture key), or null when the file does not declare one.

ChatTemplate

Gets the chat template (the tokenizer.chat_template key), or null when the file does not declare one.

ContextLength

Gets the trained context length in tokens (the {architecture}.context_length key), or 0 when the architecture or the key is absent.

EmbeddingLength

Gets the embedding (hidden state) size (the {architecture}.embedding_length key), or 0 when the architecture or the key is absent.

License

Gets the model license identifier (the general.license key), or null when the file does not declare one.

Name

Gets the human-readable model name (the general.name key), or null when the file does not declare one.

ParameterCount

Gets the total number of weight elements declared by the tensor-info table: the sum, over all tensors, of the product of their dimensions. This matches the parameter count usually quoted for a model.

Quantization

Gets a short label for the dominant quantization scheme, derived from the most frequent ggml storage type among tensors with two or more dimensions (for example Q4_K, Q8_0, or F16). Unknown type ids are reported as type_<id>. Returns null when the file declares no such tensor.

TensorCount

Gets the number of tensors declared by the file header.

Tensors

Gets the tensor-info table: one descriptor per tensor declared by the file, in file order. Tensor weights are never read.

Values

Gets the complete key-value metadata store. Values are bool, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, string, or object[] for arrays; nested arrays appear as nested object[] instances.

Version

Gets the GGUF format version declared by the file header (2 or 3).

Methods

ReadFromFile(string)

Reads the metadata of the GGUF file at path without loading tensor weights and without any native dependency.

ReadFromStream(Stream, bool)

Reads GGUF metadata from stream, starting at its current position, which must be the GGUF magic. The stream position is not preserved.

Share