pub struct CompiledVocabulary { /* private fields */ }Expand description
A prepared, reusable vocabulary; build once and reuse across binds. Cheap to clone.
Implementations§
Source§impl CompiledVocabulary
impl CompiledVocabulary
Sourcepub fn new(vocabulary: Arc<Vocabulary>) -> Result<Self, CompileError>
pub fn new(vocabulary: Arc<Vocabulary>) -> Result<Self, CompileError>
Wraps vocabulary, inferring the mask width from its largest token/EOS id.
Sourcepub fn with_logits_vocab_size(
vocabulary: Arc<Vocabulary>,
logits_vocab_size: usize,
) -> Result<Self, CompileError>
pub fn with_logits_vocab_size( vocabulary: Arc<Vocabulary>, logits_vocab_size: usize, ) -> Result<Self, CompileError>
new, with an explicit mask width (e.g. a model whose logits are padded wider than the
tokenizer’s own id range). Rejected if narrower than the largest token/EOS id present.
Sourcepub fn from_packed(
token_bytes: &[u8],
byte_offsets: &[u32],
token_ids: &[u32],
id_offsets: &[u32],
eos_token_id: u32,
) -> Result<Self, CompileError>
pub fn from_packed( token_bytes: &[u8], byte_offsets: &[u32], token_ids: &[u32], id_offsets: &[u32], eos_token_id: u32, ) -> Result<Self, CompileError>
Builds directly from four packed CSR buffers, skipping an intermediate
Vocabulary/HashMap.
Sourcepub fn from_handle(handle: VocabularyHandle) -> Self
pub fn from_handle(handle: VocabularyHandle) -> Self
Wraps an already-built VocabularyHandle, skipping re-canonicalization.
Sourcepub fn mask_vocab_size(&self) -> usize
pub fn mask_vocab_size(&self) -> usize
The mask width: write_mask buffers must hold ceil(mask_vocab_size / 32) words.
Sourcepub fn eos_token_id(&self) -> u32
pub fn eos_token_id(&self) -> u32
This vocabulary’s EOS token id.
Sourcepub fn token_bytes(&self, token_id: u32) -> Option<&[u8]>
pub fn token_bytes(&self, token_id: u32) -> Option<&[u8]>
Exact raw bytes associated with token_id, or None for an absent/special id.
Trait Implementations§
Source§impl Clone for CompiledVocabulary
impl Clone for CompiledVocabulary
Source§impl TryFrom<Arc<Vocabulary>> for CompiledVocabulary
impl TryFrom<Arc<Vocabulary>> for CompiledVocabulary
Auto Trait Implementations§
impl Freeze for CompiledVocabulary
impl RefUnwindSafe for CompiledVocabulary
impl Send for CompiledVocabulary
impl Sync for CompiledVocabulary
impl Unpin for CompiledVocabulary
impl UnsafeUnpin for CompiledVocabulary
impl UnwindSafe for CompiledVocabulary
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
Mutably borrows from an owned value. Read more