pub struct GgufReader {
pub version: u32,
pub tensor_count: u64,
pub tensors: Vec<GgufTensorMeta>,
pub data_offset: usize,
pub metadata: BTreeMap<String, GgufValue>,
/* private fields */
}Expand description
Parsed GGUF file for import
Fields§
§version: u32Format version
tensor_count: u64Number of tensors
tensors: Vec<GgufTensorMeta>Tensor infos (name, dims, dtype, data_offset)
data_offset: usizeOffset where tensor data section starts
metadata: BTreeMap<String, GgufValue>Metadata key-value pairs (extracted from GGUF)
Implementations§
Source§impl GgufReader
impl GgufReader
Sourcepub fn from_file<P>(path: P) -> Result<GgufReader, AprenderError>
pub fn from_file<P>(path: P) -> Result<GgufReader, AprenderError>
Load and parse a GGUF file
Sourcepub fn from_file_full<P>(path: P) -> Result<GgufReader, AprenderError>
pub fn from_file_full<P>(path: P) -> Result<GgufReader, AprenderError>
Load a GGUF file preserving ALL metadata keys (no architecture whitelist).
Used by the sharded-GGUF merge (super::merge::merge_gguf_shards) so
arbitrary <arch>.* config keys (gemma., phi3., deepseek2.*, …)
survive into the merged file — otherwise the merged model is unloadable
for any architecture outside the parse whitelist.
Sourcepub fn from_bytes(data: Vec<u8>) -> Result<GgufReader, AprenderError>
pub fn from_bytes(data: Vec<u8>) -> Result<GgufReader, AprenderError>
Parse GGUF from bytes (whitelist metadata — back-compat default).
Sourcepub fn from_bytes_keep(
data: Vec<u8>,
keep_all: bool,
) -> Result<GgufReader, AprenderError>
pub fn from_bytes_keep( data: Vec<u8>, keep_all: bool, ) -> Result<GgufReader, AprenderError>
Parse GGUF from bytes. When keep_all is true EVERY metadata key is
retained; otherwise only tokenizer. / general. / known-arch keys are
parsed (the rest skipped for efficiency).
Sourcepub fn vocabulary(&self) -> Option<Vec<String>>
pub fn vocabulary(&self) -> Option<Vec<String>>
Get vocabulary tokens from metadata
Returns the token strings indexed by token ID. Uses “tokenizer.ggml.tokens” key from GGUF metadata.
Sourcepub fn tokenizer_model(&self) -> Option<String>
pub fn tokenizer_model(&self) -> Option<String>
Get tokenizer model type (e.g., “llama”, “gpt2”)
Sourcepub fn bos_token_id(&self) -> Option<u32>
pub fn bos_token_id(&self) -> Option<u32>
Get BOS (beginning of sequence) token ID
Sourcepub fn eos_token_id(&self) -> Option<u32>
pub fn eos_token_id(&self) -> Option<u32>
Get EOS (end of sequence) token ID
Sourcepub fn merges(&self) -> Option<Vec<String>>
pub fn merges(&self) -> Option<Vec<String>>
Get BPE merge rules from metadata (PMAT-171)
Returns the merge rules as “token1 token2” strings for BPE encoding. Uses “tokenizer.ggml.merges” key from GGUF metadata.
Sourcepub fn architecture(&self) -> Option<String>
pub fn architecture(&self) -> Option<String>
Get general architecture name (e.g., “llama”, “qwen2”)
Sourcepub fn model_name(&self) -> Option<String>
pub fn model_name(&self) -> Option<String>
Get model name from metadata
Get hidden dimension (embedding_length)
Sourcepub fn num_layers(&self) -> Option<usize>
pub fn num_layers(&self) -> Option<usize>
Get number of transformer layers (block_count)
Sourcepub fn num_kv_heads(&self) -> Option<usize>
pub fn num_kv_heads(&self) -> Option<usize>
Get number of key-value heads (for GQA)
Sourcepub fn vocab_size(&self) -> Option<usize>
pub fn vocab_size(&self) -> Option<usize>
Get vocabulary size
Sourcepub fn intermediate_size(&self) -> Option<usize>
pub fn intermediate_size(&self) -> Option<usize>
Get FFN intermediate dimension
Sourcepub fn context_length(&self) -> Option<usize>
pub fn context_length(&self) -> Option<usize>
Get maximum context length
Sourcepub fn rope_theta(&self) -> Option<f32>
pub fn rope_theta(&self) -> Option<f32>
Get RoPE theta (frequency base)
Sourcepub fn rms_norm_eps(&self) -> Option<f32>
pub fn rms_norm_eps(&self) -> Option<f32>
Get RMS norm epsilon (or standard LayerNorm epsilon for GPT-2)
Sourcepub fn token_type(&self) -> Option<Vec<i32>>
pub fn token_type(&self) -> Option<Vec<i32>>
Get per-token type array (tokenizer.ggml.token_type) Values: 1=normal, 2=unknown, 3=control/special, 4=user_defined, etc.
Sourcepub fn padding_token_id(&self) -> Option<u32>
pub fn padding_token_id(&self) -> Option<u32>
Get padding token ID (tokenizer.ggml.padding_token_id)
Sourcepub fn add_bos_token(&self) -> Option<bool>
pub fn add_bos_token(&self) -> Option<bool>
Get add_bos_token flag (tokenizer.ggml.add_bos_token)
Sourcepub fn chat_template(&self) -> Option<String>
pub fn chat_template(&self) -> Option<String>
Get chat template (tokenizer.chat_template)
Sourcepub fn pre_tokenizer_type(&self) -> Option<String>
pub fn pre_tokenizer_type(&self) -> Option<String>
GH-277: Get pre-tokenizer type (tokenizer.ggml.pre)
Source§impl GgufReader
impl GgufReader
Sourcepub fn get_tensor_f32(
&self,
name: &str,
) -> Result<(Vec<f32>, Vec<usize>), AprenderError>
pub fn get_tensor_f32( &self, name: &str, ) -> Result<(Vec<f32>, Vec<usize>), AprenderError>
Extract a tensor as F32 data (dequantizing if needed)
Postcondition: data.len() == shape.iter().product()
Sourcepub fn get_all_tensors_f32(
&self,
) -> Result<BTreeMap<String, (Vec<f32>, Vec<usize>)>, AprenderError>
pub fn get_all_tensors_f32( &self, ) -> Result<BTreeMap<String, (Vec<f32>, Vec<usize>)>, AprenderError>
Get all tensors as F32
Sourcepub fn get_all_tensors_f32_with_progress(
&self,
progress: impl Fn(usize, usize, &str),
) -> Result<BTreeMap<String, (Vec<f32>, Vec<usize>)>, AprenderError>
pub fn get_all_tensors_f32_with_progress( &self, progress: impl Fn(usize, usize, &str), ) -> Result<BTreeMap<String, (Vec<f32>, Vec<usize>)>, AprenderError>
Get all tensors as F32 with per-tensor progress callback.
Contract: GH-692 — progress feedback for large GGUF dequantization. Callback receives (current_index, total_count, tensor_name).
Sourcepub fn get_tensor_raw(
&self,
name: &str,
) -> Result<(Vec<u8>, Vec<usize>, u32), AprenderError>
pub fn get_tensor_raw( &self, name: &str, ) -> Result<(Vec<u8>, Vec<usize>, u32), AprenderError>
Get raw tensor bytes without dequantization (preserves Q4K/Q6K)
Returns (raw_bytes, shape, ggml_dtype) where dtype is per GGML spec:
- 0=F32, 1=F16, 2=Q4_0, 3=Q4_1, 8=Q8_0
- 10=Q2_K, 11=Q3_K, 12=Q4_K, 13=Q5_K, 14=Q6_K
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GgufReader
impl RefUnwindSafe for GgufReader
impl Send for GgufReader
impl Sync for GgufReader
impl Unpin for GgufReader
impl UnsafeUnpin for GgufReader
impl UnwindSafe for GgufReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more