pub struct StopTokens { /* private fields */ }Expand description
The set of token ids a decode loop must stop on, carried as one value so a caller cannot accidentally carry only half of it.
This type exists because Option<usize> was the shape of a real bug:
every ferrox-server decode loop threaded a single eos_id from the
loader to the sampler, so a Llama-3 or gemma checkpoint served over
HTTP ran past <|eot_id|> / <end_of_turn> to max_tokens even
after eog_token_ids landed for the CLI. Passing a StopTokens
makes “I only have the metadata EOS” an explicit choice
(StopTokens::from_eos, for the synthetic-weights and Kimi paths
that have no GGUF metadata to read) rather than the default.
Implementations§
Source§impl StopTokens
impl StopTokens
Sourcepub fn from_gguf(file: &impl TensorSource) -> Self
pub fn from_gguf(file: &impl TensorSource) -> Self
Everything eog_token_ids finds in this checkpoint: the
eos/eot/eom metadata ids plus every vocabulary entry whose
text is on llama.cpp’s literal EOG list.
Sourcepub fn from_eos(eos: Option<usize>) -> Self
pub fn from_eos(eos: Option<usize>) -> Self
Just the one id. For callers with no GGUF metadata behind them — the synthetic random-weights demo model, and the Kimi checkpoint directory whose tokenizer is a separate file format.
Sourcepub fn from_special_tokens<'a>(
specials: impl IntoIterator<Item = (&'a str, u32)>,
) -> Self
pub fn from_special_tokens<'a>( specials: impl IntoIterator<Item = (&'a str, u32)>, ) -> Self
For checkpoints whose vocabulary is not GGUF metadata — Kimi K3
ships a tokenizer_config.json with a name→id special-token map.
Folds in every entry whose text is on llama.cpp’s EOG list, so
[EOT] stops a turn there exactly as it does in a GGUF.
Sourcepub fn with_id(self, id: Option<usize>) -> Self
pub fn with_id(self, id: Option<usize>) -> Self
Folds one more id in — used to keep a metadata eos_token_id that
a vocabulary spells in a way the literal list does not know.
pub fn contains(&self, id: usize) -> bool
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Trait Implementations§
Source§impl Clone for StopTokens
impl Clone for StopTokens
Source§fn clone(&self) -> StopTokens
fn clone(&self) -> StopTokens
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StopTokens
impl Debug for StopTokens
Source§impl Default for StopTokens
impl Default for StopTokens
Source§fn default() -> StopTokens
fn default() -> StopTokens
Auto Trait Implementations§
impl Freeze for StopTokens
impl RefUnwindSafe for StopTokens
impl Send for StopTokens
impl Sync for StopTokens
impl Unpin for StopTokens
impl UnsafeUnpin for StopTokens
impl UnwindSafe for StopTokens
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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