Skip to main content

CompiledVocabulary

Struct CompiledVocabulary 

Source
pub struct CompiledVocabulary { /* private fields */ }
Expand description

A prepared, reusable vocabulary; build once and reuse across binds. Cheap to clone.

Implementations§

Source§

impl CompiledVocabulary

Source

pub fn new(vocabulary: Arc<Vocabulary>) -> Result<Self, CompileError>

Wraps vocabulary, inferring the mask width from its largest token/EOS id.

Source

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.

Source

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.

Source

pub fn from_handle(handle: VocabularyHandle) -> Self

Wraps an already-built VocabularyHandle, skipping re-canonicalization.

Source

pub fn mask_vocab_size(&self) -> usize

The mask width: write_mask buffers must hold ceil(mask_vocab_size / 32) words.

Source

pub fn eos_token_id(&self) -> u32

This vocabulary’s EOS token id.

Source

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

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 TryFrom<Arc<Vocabulary>> for CompiledVocabulary

Source§

type Error = CompileError

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

fn try_from(vocabulary: Arc<Vocabulary>) -> Result<Self, Self::Error>

Performs the conversion.

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.