pub struct Sampler {
pub temperature: f32,
pub top_k: Option<usize>,
pub top_p: Option<f32>,
pub repetition_penalty: Option<f32>,
/* private fields */
}Expand description
Sampling configuration and strategy.
Fields§
§temperature: f32Temperature for softmax scaling. > 1.0 = more random, < 1.0 = more deterministic.
top_k: Option<usize>Top-k: only sample from top k logits.
top_p: Option<f32>Top-p (nucleus sampling): sample from smallest set of tokens with cumulative prob >= p.
repetition_penalty: Option<f32>Repetition penalty: penalize tokens that appear in history.
Implementations§
Source§impl Sampler
impl Sampler
pub fn with_temperature(self, temp: f32) -> Self
pub fn with_top_k(self, k: usize) -> Self
pub fn with_top_p(self, p: f32) -> Self
pub fn with_repetition_penalty(self, penalty: f32) -> Self
pub fn with_seed(self, seed: u64) -> Self
Sourcepub fn sample(&mut self, logits: &[f32]) -> SamplingResult<usize>
pub fn sample(&mut self, logits: &[f32]) -> SamplingResult<usize>
Sample a token index from logits using configured strategy.
Sourcepub fn sample_with_history(
&mut self,
logits: &[f32],
history: &[usize],
) -> SamplingResult<usize>
pub fn sample_with_history( &mut self, logits: &[f32], history: &[usize], ) -> SamplingResult<usize>
Sample with history for repetition penalty.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sampler
impl RefUnwindSafe for Sampler
impl Send for Sampler
impl Sync for Sampler
impl Unpin for Sampler
impl UnsafeUnpin for Sampler
impl UnwindSafe for Sampler
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