Class GgufMetadata
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.architecturekey), ornullwhen the file does not declare one.
- ChatTemplate
Gets the chat template (the
tokenizer.chat_templatekey), ornullwhen the file does not declare one.
- ContextLength
Gets the trained context length in tokens (the
{architecture}.context_lengthkey), or0when the architecture or the key is absent.
- EmbeddingLength
Gets the embedding (hidden state) size (the
{architecture}.embedding_lengthkey), or0when the architecture or the key is absent.
- License
Gets the model license identifier (the
general.licensekey), ornullwhen the file does not declare one.
- Name
Gets the human-readable model name (the
general.namekey), ornullwhen 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, orF16). Unknown type ids are reported astype_<id>. Returnsnullwhen 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 nestedobject[]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
pathwithout 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.