pub enum AnyTokenizer {
Bpe(Box<Gpt2Tokenizer>),
Char(CharTokenizer),
}Expand description
Either tokenizer, for callers that pick one at runtime (the TUI and the
wasm facade both do). Generation stays generic over impl Tokenizer, so
this dispatches without a vtable.
Variants§
Bpe(Box<Gpt2Tokenizer>)
Boxed because a Gpt2Tokenizer (four hash maps plus a compiled regex)
is ~6× the size of a CharTokenizer, and every value of this enum
would otherwise pay for the larger one.
Char(CharTokenizer)
Implementations§
Trait Implementations§
Source§impl Tokenizer for AnyTokenizer
impl Tokenizer for AnyTokenizer
fn encode(&self, text: &str) -> Result<Vec<u32>>
fn decode(&self, ids: &[u32]) -> String
Source§fn decode_bytes(&self, ids: &[u32]) -> Vec<u8> ⓘ
fn decode_bytes(&self, ids: &[u32]) -> Vec<u8> ⓘ
Raw byte-level decode. Must be append-only per token — i.e.
decode_bytes(a ++ b)
equals decode_bytes(a) ++ decode_bytes(b) — because the streaming path
emits only the valid-UTF-8 prefix of the accumulated bytes.fn vocab_size(&self) -> usize
Auto Trait Implementations§
impl Freeze for AnyTokenizer
impl RefUnwindSafe for AnyTokenizer
impl Send for AnyTokenizer
impl Sync for AnyTokenizer
impl Unpin for AnyTokenizer
impl UnsafeUnpin for AnyTokenizer
impl UnwindSafe for AnyTokenizer
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
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>
Converts
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>
Converts
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