Skip to main content

Gguf

Struct Gguf 

Source
pub struct Gguf {
    pub version: u32,
    pub meta: BTreeMap<String, MetaValue>,
    pub order: Vec<String>,
    pub arch: Arch,
    /* private fields */
}
Expand description

A parsed GGUF file: the metadata, the tensor directory, and where the data section starts.

Fields§

§version: u32§meta: BTreeMap<String, MetaValue>§order: Vec<String>

The metadata keys in the order the file lists them.

§arch: Arch

Implementations§

Source§

impl Gguf

Source

pub fn open(path: &Path) -> Result<Gguf>

Open and parse a GGUF file’s header, metadata and tensor directory. The weights stay on disk until read.

Source

pub fn data_start(&self) -> u64

Where the data section starts: a tensor’s bytes sit at data_start() + offset.

Source

pub fn header_digest(&mut self) -> Result<u64>

The FNV-1a 64 digest of everything before the data section — the header, the metadata and the tensor directory: a program compiled against this checkpoint checks it reads the same file.

Source

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

A metadata value by its full key.

Source

pub fn arch_meta(&self, suffix: &str) -> Option<&MetaValue>

A metadata value under the architecture prefix ({arch}.{suffix}).

Source

pub fn decode_read_bytes(&self) -> Result<u64>

The bytes of weights one decode step reads for a token. That is every tensor of the model’s blocks and around them, with three exceptions:

  • the token embedding, where an output matrix of its own stands beside it (the step reads one of its rows);
  • each expert matrix, counted in the share of its experts a token is routed to (expert_used_count of expert_count);
  • the draft blocks appended for multi-token prediction, which count nothing. A tensor in a format this crate does not read is an error.
Source

pub fn tensors(&self) -> &[TensorInfo]

The tensor directory, in file order.

Source

pub fn info(&self, name: &str) -> Option<&TensorInfo>

One tensor’s directory entry.

Source

pub fn tensor_type(&self, name: &str) -> Result<GgmlType>

The format of a tensor, or why it is not one this crate reads.

Source

pub fn row_bytes( &mut self, name: &str, first: usize, count: usize, ) -> Result<Vec<u8>>

The raw bytes of rows [first, first + count) of a tensor, a row being its dims[0] fastest elements.

Source

pub fn dequant_rows( &mut self, name: &str, first: usize, count: usize, ) -> Result<Vec<f32>>

Rows [first, first + count) of a tensor dequantized to f32, whatever its format.

Source

pub fn dequant_tensor(&mut self, name: &str) -> Result<Vec<f32>>

A whole tensor dequantized to f32, whatever its format.

Source

pub fn dims2(&self, name: &str) -> Option<(usize, usize)>

(in = ne0, out = ne1) for a 2-D weight tensor (y = W·x uses out×in).

Source

pub fn dims(&self, name: &str) -> Option<&[u64]>

The [ne0, ne1, …] dims of a tensor (ggml order: ne0 is the fastest / in-features).

Source

pub fn tensor_names(&self) -> Vec<(String, Vec<u64>, u32)>

Every tensor’s (name, dims, ggml_type) — for inspecting an unfamiliar checkpoint’s layout.

Source

pub fn has(&self, name: &str) -> bool

true if the named tensor exists.

Source

pub fn f32_tensor(&mut self, name: &str) -> Result<Vec<f32>>

Read an F32 tensor’s data in full (the RMSNorm weights).

Source

pub fn f16_tensor(&mut self, name: &str) -> Result<Vec<f32>>

Read an F16 tensor, widened to f32. The Qwen3.8 vision tower (mmproj-*.gguf) stores every weight as F16.

Source

pub fn float_tensor(&mut self, name: &str) -> Result<Vec<f32>>

Read an F32 or F16 tensor as f32, whichever the checkpoint stored.

Source

pub fn q8_0_matrix(&mut self, name: &str) -> Result<(Vec<i8>, Vec<f32>)>

Read a whole Q8_0 tensor as (quants i8 [out*in] row-major, scales f32 [out*in/32]). dequant W[o][t] = quants[o*in+t] * scales[o*nb + t/32]. Works for 2-D [in, out] AND 3-D expert stacks [in, out_per_expert, n_expert] — for the latter out folds to out_per_expert · n_expert, so ffn_gate_exps/ffn_up_exps come out as the stacked [E·dff, d] (and ffn_down_exps as [E·d, dff]) layout emit_moe_forward consumes, expert e’s rows at e·dff.

Source

pub fn q8_0_dequant_row(&mut self, name: &str, row: usize) -> Result<Vec<f32>>

Dequantize a single Q8_0 row to f32 (a token embedding row).

Source

pub fn q8_0_tile_blocks( &mut self, name: &str, rows: usize, cols: usize, ) -> Result<(Vec<i32>, Vec<f32>)>

Read a rows × cols Q8_0 sub-tile as (quants, scales): the int8 values (rows*cols, row-major) AND the per-32-block f32 scales (rows * cols/32). The full Q8_0 weight (dequant = quant * scale), the form a real block-scaled GEMM consumes.

Source

pub fn q8_0_tile( &mut self, name: &str, rows: usize, cols: usize, ) -> Result<Vec<i32>>

The raw int8 weights of the first rows × cols sub-tile of a Q8_0 2-D tensor, row-major over the tensor’s ggml layout. cols must be ≤ ne0 and a multiple of 32, rows ≤ ne1.

Trait Implementations§

Source§

impl SpecSource for Gguf

Source§

fn arch(&self) -> &str

general.architecture.
Source§

fn arch_meta(&self, suffix: &str) -> Option<&MetaValue>

The architecture key {arch}.{suffix}.
Source§

fn dims(&self, name: &str) -> Option<&[u64]>

A tensor’s dims, dims[0] the fastest-varying.
Source§

fn tensor_names(&self) -> Vec<&str>

Every tensor’s name, in the directory’s order.
Source§

fn has(&self, name: &str) -> bool

Source§

impl WeightSource for Gguf

Source§

fn describe(&self, name: &str) -> Result<(GgmlType, Vec<u64>)>

A tensor’s format and dims.
Source§

fn row_bytes( &mut self, name: &str, first: usize, count: usize, ) -> Result<Vec<u8>>

The bytes of rows [first, first + count), a row being the tensor’s dims[0] elements.
Source§

fn has(&self, name: &str) -> bool

Auto Trait Implementations§

§

impl Freeze for Gguf

§

impl RefUnwindSafe for Gguf

§

impl Send for Gguf

§

impl Sync for Gguf

§

impl Unpin for Gguf

§

impl UnsafeUnpin for Gguf

§

impl UnwindSafe for Gguf

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Checkpoint for T

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,