pub struct DominoMasker { /* private fields */ }Expand description
The DOMINO constrained decoding masker. Combines a token trie with a grammar state machine to produce logit masks.
Implementations§
Source§impl DominoMasker
impl DominoMasker
Sourcepub fn prepare_owned(
&self,
budget: DominoPreparationBudget,
) -> Result<PreparedDomino, &'static str>
pub fn prepare_owned( &self, budget: DominoPreparationBudget, ) -> Result<PreparedDomino, &'static str>
Cold clone admits every trie node, map/vector capacity and grammar buffer before cloning. Trie depth is structurally capped at MAX_TRIE_DEPTH.
Source§impl DominoMasker
impl DominoMasker
Sourcepub fn new(vocab: &[(u32, String)]) -> Self
pub fn new(vocab: &[(u32, String)]) -> Self
Create a new masker from a vocabulary. The trie is built once (cold path).
Sourcepub fn apply_mask(&mut self, logits: &mut [f32])
pub fn apply_mask(&mut self, logits: &mut [f32])
Apply the constraint mask to logits. Sets disallowed tokens to -inf.
When inactive, this is a no-op.
Hot path — reuses internal scratch buffer, no allocation.
Sourcepub fn apply_mask_preserving(&mut self, logits: &mut [f32])
pub fn apply_mask_preserving(&mut self, logits: &mut [f32])
Apply the constraint mask while preserving original logit values. Uses a snapshot approach: first save valid logits, then mask all, then restore valid ones.
Sourcepub fn feed_token(&mut self, bytes: &[u8])
pub fn feed_token(&mut self, bytes: &[u8])
Feed a decoded token into the grammar state machine.
Sourcepub fn feed_token_id(&mut self, token_id: u32, vocab: &[(u32, String)])
pub fn feed_token_id(&mut self, token_id: u32, vocab: &[(u32, String)])
Feed a decoded token ID by looking up its bytes in the vocabulary.
Sourcepub fn grammar_state(&self) -> GrammarState
pub fn grammar_state(&self) -> GrammarState
Get the current grammar state.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DominoMasker
impl RefUnwindSafe for DominoMasker
impl Send for DominoMasker
impl Sync for DominoMasker
impl Unpin for DominoMasker
impl UnsafeUnpin for DominoMasker
impl UnwindSafe for DominoMasker
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
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