pub struct LlamaTokenDataArray {
pub data: Vec<LlamaTokenData>,
pub selected: Option<usize>,
pub sorted: bool,
}Expand description
A safe wrapper around llama_token_data_array — the candidate set consumed
(and mutated) by sampling.
Fields§
§data: Vec<LlamaTokenData>The underlying candidate data.
selected: Option<usize>The index of the selected token in data, if a sampler has chosen one.
sorted: boolWhether data is sorted by logit (descending).
Implementations§
Source§impl LlamaTokenDataArray
impl LlamaTokenDataArray
Sourcepub fn new(data: Vec<LlamaTokenData>, sorted: bool) -> Self
pub fn new(data: Vec<LlamaTokenData>, sorted: bool) -> Self
Create a new LlamaTokenDataArray from a vector and whether the data is
sorted by logit.
Sourcepub fn from_iter<T>(data: T, sorted: bool) -> LlamaTokenDataArraywhere
T: IntoIterator<Item = LlamaTokenData>,
pub fn from_iter<T>(data: T, sorted: bool) -> LlamaTokenDataArraywhere
T: IntoIterator<Item = LlamaTokenData>,
Create a new LlamaTokenDataArray from an iterator of LlamaTokenData.
Sourcepub fn from_logits(logits: &[f32]) -> Self
pub fn from_logits(logits: &[f32]) -> Self
Build from a logits slice (id = index). Probabilities start at 0 and
the data is unsorted.
Sourcepub fn selected_token(&self) -> Option<LlamaToken>
pub fn selected_token(&self) -> Option<LlamaToken>
The currently selected token, if a sampler has chosen one.
Sourcepub fn apply_repetition_penalties(
&mut self,
ctx: &mut LlamaContext<'_>,
last_tokens: &[LlamaToken],
penalty_repeat: f32,
penalty_freq: f32,
penalty_present: f32,
)
pub fn apply_repetition_penalties( &mut self, ctx: &mut LlamaContext<'_>, last_tokens: &[LlamaToken], penalty_repeat: f32, penalty_freq: f32, penalty_present: f32, )
Apply repetition / frequency / presence penalties in place over the most
recent last_tokens.
Wraps ik’s legacy llama_sample_repetition_penalties. An empty
last_tokens slice is a no-op. Logits are mutated in place; candidate
order is preserved.
Trait Implementations§
Source§impl Clone for LlamaTokenDataArray
impl Clone for LlamaTokenDataArray
Source§fn clone(&self) -> LlamaTokenDataArray
fn clone(&self) -> LlamaTokenDataArray
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more