Skip to main content

GgufMetadata

Struct GgufMetadata 

Source
pub struct GgufMetadata {
    pub strings: HashMap<String, String>,
    pub numerics: HashMap<String, u64>,
    pub floats_32: HashMap<String, f32>,
    pub floats_64: HashMap<String, f64>,
    /* private fields */
}
Expand description

Parsed GGUF metadata key-value store.

GGUF stores arbitrary scalar KV pairs. We keep strings and numeric values in typed maps; signed integers are additionally kept in signed_numerics so callers can distinguish bit-preserved negatives from large unsigned UINT64 values. Array values are skipped (their byte contents remain available via the original file buffer if needed).

Fields§

§strings: HashMap<String, String>

String-typed KV pairs (e.g. general.architecture = "olmoe").

§numerics: HashMap<String, u64>

Numeric-typed KV pairs coerced to u64 (e.g. olmoe.expert_count = 64).

§floats_32: HashMap<String, f32>

f32-typed KV pairs.

§floats_64: HashMap<String, f64>

f64-typed KV pairs.

Implementations§

Source§

impl GgufMetadata

Source

pub fn architecture(&self) -> &str

Convenience: architecture string (general.architecture) or "unknown".

Examples found in repository?
examples/inspect_gguf.rs (line 82)
79fn print_inventory(layout: &GgufLayout, path: &Path, load_ms: f64) {
80    println!("path:          {}", path.display());
81    println!("load_ms:       {load_ms:.2}");
82    println!("architecture:  {}", layout.metadata.architecture());
83    println!("quantization:  {}", layout.metadata.quantization());
84    println!("alignment:     {}", layout.alignment);
85    println!("tensor_count:  {}", layout.tensors.len());
86    println!("block_count:   {:?}", layout.metadata.block_count());
87    println!("expert_count:  {:?}", layout.metadata.expert_count());
88    println!("expert_used:   {:?}", layout.metadata.expert_used_count());
89    println!("embed_len:     {:?}", layout.metadata.embedding_length());
90}
Source

pub fn numeric(&self, key: &str) -> Option<usize>

Convenience: numeric KV coerced to usize.

Signed integer KVs are checked first: a negative value returns None. Unsigned UINT64 values larger than i64::MAX are still accepted as long as they fit in usize.

Source

pub fn quantization(&self) -> String

Convenience: quantization label.

Prefers the string KV general.quantization_type. When that is missing, falls back to the current general.file_type numeric (GGUF enum): 0 → "F32", 1 → "F16", otherwise "GGUF(n)". Returns "unknown" when neither is present. Derived at call time so Default + public map edits stay consistent.

Examples found in repository?
examples/inspect_gguf.rs (line 83)
79fn print_inventory(layout: &GgufLayout, path: &Path, load_ms: f64) {
80    println!("path:          {}", path.display());
81    println!("load_ms:       {load_ms:.2}");
82    println!("architecture:  {}", layout.metadata.architecture());
83    println!("quantization:  {}", layout.metadata.quantization());
84    println!("alignment:     {}", layout.alignment);
85    println!("tensor_count:  {}", layout.tensors.len());
86    println!("block_count:   {:?}", layout.metadata.block_count());
87    println!("expert_count:  {:?}", layout.metadata.expert_count());
88    println!("expert_used:   {:?}", layout.metadata.expert_used_count());
89    println!("embed_len:     {:?}", layout.metadata.embedding_length());
90}
Source

pub fn arch_numeric(&self, key: &str) -> Option<usize>

Convenience: numeric KV coerced to usize, looking up {architecture}.{key} (e.g. olmoe.block_count).

Returns None if the architecture is unknown or the key is missing.

Source

pub fn block_count(&self) -> Option<usize>

Convenience: block count from {architecture}.block_count.

Examples found in repository?
examples/inspect_gguf.rs (line 86)
79fn print_inventory(layout: &GgufLayout, path: &Path, load_ms: f64) {
80    println!("path:          {}", path.display());
81    println!("load_ms:       {load_ms:.2}");
82    println!("architecture:  {}", layout.metadata.architecture());
83    println!("quantization:  {}", layout.metadata.quantization());
84    println!("alignment:     {}", layout.alignment);
85    println!("tensor_count:  {}", layout.tensors.len());
86    println!("block_count:   {:?}", layout.metadata.block_count());
87    println!("expert_count:  {:?}", layout.metadata.expert_count());
88    println!("expert_used:   {:?}", layout.metadata.expert_used_count());
89    println!("embed_len:     {:?}", layout.metadata.embedding_length());
90}
Source

pub fn expert_count(&self) -> Option<usize>

Convenience: expert count from {architecture}.expert_count (some models use num_experts instead).

Examples found in repository?
examples/inspect_gguf.rs (line 87)
79fn print_inventory(layout: &GgufLayout, path: &Path, load_ms: f64) {
80    println!("path:          {}", path.display());
81    println!("load_ms:       {load_ms:.2}");
82    println!("architecture:  {}", layout.metadata.architecture());
83    println!("quantization:  {}", layout.metadata.quantization());
84    println!("alignment:     {}", layout.alignment);
85    println!("tensor_count:  {}", layout.tensors.len());
86    println!("block_count:   {:?}", layout.metadata.block_count());
87    println!("expert_count:  {:?}", layout.metadata.expert_count());
88    println!("expert_used:   {:?}", layout.metadata.expert_used_count());
89    println!("embed_len:     {:?}", layout.metadata.embedding_length());
90}
Source

pub fn expert_used_count(&self) -> Option<usize>

Convenience: number of experts used per token from {architecture}.expert_used_count (some models use num_experts_per_tok).

Examples found in repository?
examples/inspect_gguf.rs (line 88)
79fn print_inventory(layout: &GgufLayout, path: &Path, load_ms: f64) {
80    println!("path:          {}", path.display());
81    println!("load_ms:       {load_ms:.2}");
82    println!("architecture:  {}", layout.metadata.architecture());
83    println!("quantization:  {}", layout.metadata.quantization());
84    println!("alignment:     {}", layout.alignment);
85    println!("tensor_count:  {}", layout.tensors.len());
86    println!("block_count:   {:?}", layout.metadata.block_count());
87    println!("expert_count:  {:?}", layout.metadata.expert_count());
88    println!("expert_used:   {:?}", layout.metadata.expert_used_count());
89    println!("embed_len:     {:?}", layout.metadata.embedding_length());
90}
Source

pub fn embedding_length(&self) -> Option<usize>

Convenience: embedding length from {architecture}.embedding_length.

Examples found in repository?
examples/inspect_gguf.rs (line 89)
79fn print_inventory(layout: &GgufLayout, path: &Path, load_ms: f64) {
80    println!("path:          {}", path.display());
81    println!("load_ms:       {load_ms:.2}");
82    println!("architecture:  {}", layout.metadata.architecture());
83    println!("quantization:  {}", layout.metadata.quantization());
84    println!("alignment:     {}", layout.alignment);
85    println!("tensor_count:  {}", layout.tensors.len());
86    println!("block_count:   {:?}", layout.metadata.block_count());
87    println!("expert_count:  {:?}", layout.metadata.expert_count());
88    println!("expert_used:   {:?}", layout.metadata.expert_used_count());
89    println!("embed_len:     {:?}", layout.metadata.embedding_length());
90}
Source

pub fn head_count(&self) -> Option<usize>

Convenience: attention head count from {architecture}.attention.head_count.

Source

pub fn string(&self, key: &str) -> Option<&str>

Generic string metadata lookup.

Source

pub fn float32(&self, key: &str) -> Option<f32>

Generic f32 metadata lookup.

Source

pub fn float64(&self, key: &str) -> Option<f64>

Generic f64 metadata lookup.

Trait Implementations§

Source§

impl Clone for GgufMetadata

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GgufMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GgufMetadata

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.