Skip to main content

SamplingContext

Struct SamplingContext 

Source
pub struct SamplingContext<'a> {
    pub step: usize,
    pub sampling_params: &'a SamplingParams,
    pub logits: &'a mut [f32],
    pub previous_tokens: &'a [TokenId],
    pub token_frequencies: &'a HashMap<TokenId, usize>,
    pub vocab_size: usize,
    pub metadata: HashMap<String, f32>,
}
Expand description

Sampling context passed to logits processors and samplers

Fields§

§step: usize

Current generation step (0-based)

§sampling_params: &'a SamplingParams

Request-specific sampling parameters

§logits: &'a mut [f32]

Current logits (mutable for processing)

§previous_tokens: &'a [TokenId]

Previous token IDs in sequence

§token_frequencies: &'a HashMap<TokenId, usize>

Token frequencies for repetition penalty

§vocab_size: usize

Vocabulary size

§metadata: HashMap<String, f32>

Additional metadata

Implementations§

Source§

impl<'a> SamplingContext<'a>

Source

pub fn new( step: usize, sampling_params: &'a SamplingParams, logits: &'a mut [f32], previous_tokens: &'a [TokenId], token_frequencies: &'a HashMap<TokenId, usize>, vocab_size: usize, ) -> Self

Create new sampling context

Source

pub fn get_logit(&self, token_id: TokenId) -> Option<f32>

Get logit value for specific token

Source

pub fn set_logit(&mut self, token_id: TokenId, value: f32) -> bool

Set logit value for specific token

Source

pub fn mask_tokens(&mut self, token_ids: &[TokenId])

Mask (set to negative infinity) specific tokens

Trait Implementations§

Source§

impl<'a> Debug for SamplingContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SamplingContext<'a>

§

impl<'a> RefUnwindSafe for SamplingContext<'a>

§

impl<'a> Send for SamplingContext<'a>

§

impl<'a> Sync for SamplingContext<'a>

§

impl<'a> Unpin for SamplingContext<'a>

§

impl<'a> UnsafeUnpin for SamplingContext<'a>

§

impl<'a> !UnwindSafe for SamplingContext<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V