ai00_core/sampler/mod.rs
1pub mod bnf;
2pub mod mirostat;
3pub mod nucleus;
4pub mod typical;
5
6mod radix;
7
8pub trait Sampler {
9 /// Initialize the sampler state.
10 fn init(&mut self, model_tokens: &[u32]);
11 /// Update the raw model output.
12 fn transform(&self, output: &mut [f32]);
13 /// Select one token from the distribution, and also update the state.
14 fn sample(&mut self, probs: &[f32]) -> u32;
15}
16
17pub trait Formatter {
18 /// Update the raw model output.
19 fn transform(&self, output: &mut [f32]);
20 /// Update the internal state after a token is chosen. Return if the state machine is halt.
21 fn update(&mut self, token: u32) -> bool;
22}