pub struct GgufBpeTokenizer { /* private fields */ }Expand description
A real BPE tokenizer built from a GGUF file’s own
tokenizer.ggml.tokens / tokenizer.ggml.merges metadata arrays.
Supports GPT-2 byte-remap BPE (tokenizer.ggml.model == "gpt2") and
Gemma-4 SPM-style BPE ("gemma4": escape spaces to ▁, merge on
raw UTF-8, newline-only pre-split).
Verified against tests/fixtures/llama-bpe-vocab.gguf (GPT-2 path).
See crates/ferrox-models/tests/gguf_vocab.rs.
Implementations§
Source§impl GgufBpeTokenizer
impl GgufBpeTokenizer
Sourcepub fn from_gguf(file: &impl TensorSource) -> Result<Self, TokenizerLoadError>
pub fn from_gguf(file: &impl TensorSource) -> Result<Self, TokenizerLoadError>
Loads the vocabulary + merge table from a GGUF file’s metadata.
Merges are optional (some tokenizer types, e.g. byte-level
unigram, don’t use them); if absent, encoding falls back to
per-byte token lookup. tokenizer.ggml.model == "gemma4" selects
SPM-whitespace BPE; everything else with merges uses GPT-2 style.
pub fn vocab_size(&self) -> usize
pub fn has_merges(&self) -> bool
Sourcepub fn encode_word(&self, word: &str) -> Vec<u32>
pub fn encode_word(&self, word: &str) -> Vec<u32>
Greedy BPE merge over one pre-split chunk. GPT-2 style remaps
bytes through byte_to_unicode; Gemma-4 style merges raw UTF-8
codepoints (after " " → ▁ escaping in encode).
Auto Trait Implementations§
impl Freeze for GgufBpeTokenizer
impl RefUnwindSafe for GgufBpeTokenizer
impl Send for GgufBpeTokenizer
impl Sync for GgufBpeTokenizer
impl Unpin for GgufBpeTokenizer
impl UnsafeUnpin for GgufBpeTokenizer
impl UnwindSafe for GgufBpeTokenizer
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
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