pub enum AllowedSet {
Only(BTreeSet<u32>),
Mask(Vec<bool>),
}Expand description
Which next-token ids a constraint permits at the current step.
Two shapes, because two very different constraints want very different storage:
AllowedSet::Only— a sparse set: “only these handful of ids, mask everything else”. Right for a fixed tool-name enum over a 150k vocab, where listing the allowed ids is far cheaper than a 150k-entry bool vector.AllowedSet::Mask— a dense allow-mask, oneboolper vocab id. Right for a structural constraint that has to test every candidate token anyway (seeJsonStructure::allowed), so the per-id answer is already computed.
Variants§
Only(BTreeSet<u32>)
Only these ids are allowed; every other id is masked.
Mask(Vec<bool>)
One bool per vocab id: mask[id] allowed iff true. An id past the
end of the vector is treated as not allowed.
Implementations§
Source§impl AllowedSet
impl AllowedSet
Sourcepub fn contains(&self, id: u32) -> bool
pub fn contains(&self, id: u32) -> bool
Is token id allowed by this set?
For AllowedSet::Mask, an id at or past the mask length is not
allowed — a mask sized to a smaller vocab than the logits row can never
accidentally green-light a token it never considered.
Trait Implementations§
Source§impl Clone for AllowedSet
impl Clone for AllowedSet
Source§fn clone(&self) -> AllowedSet
fn clone(&self) -> AllowedSet
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AllowedSet
impl Debug for AllowedSet
impl Eq for AllowedSet
Source§impl PartialEq for AllowedSet
impl PartialEq for AllowedSet
impl StructuralPartialEq for AllowedSet
Auto Trait Implementations§
impl Freeze for AllowedSet
impl RefUnwindSafe for AllowedSet
impl Send for AllowedSet
impl Sync for AllowedSet
impl Unpin for AllowedSet
impl UnsafeUnpin for AllowedSet
impl UnwindSafe for AllowedSet
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.