pub struct GenerationConfig {
pub max_new_tokens: usize,
pub temperature: f32,
pub top_k: Option<usize>,
pub top_p: Option<f32>,
pub repetition_penalty: f32,
pub eos_token_ids: Vec<u32>,
pub pad_token_id: Option<u32>,
pub do_sample: bool,
pub num_beams: usize,
pub length_penalty: f32,
pub early_stopping: bool,
}Expand description
Configuration for text generation.
Fields§
§max_new_tokens: usizeMaximum number of new tokens to generate
temperature: f32Temperature for sampling (1.0 = no change, <1.0 = more deterministic, >1.0 = more random)
top_k: Option<usize>Top-k sampling: only sample from top k tokens
top_p: Option<f32>Top-p (nucleus) sampling: sample from tokens with cumulative probability >= p
repetition_penalty: f32Repetition penalty (1.0 = no penalty, >1.0 = penalize repetition)
eos_token_ids: Vec<u32>Stop token IDs
pad_token_id: Option<u32>Pad token ID
do_sample: boolWhether to do greedy decoding
num_beams: usizeNumber of beams for beam search (1 = no beam search)
length_penalty: f32Length penalty for beam search
early_stopping: boolEarly stopping for beam search
Implementations§
Source§impl GenerationConfig
impl GenerationConfig
Sourcepub fn top_k_sampling(k: usize, temperature: f32) -> Self
pub fn top_k_sampling(k: usize, temperature: f32) -> Self
Creates a config for top-k sampling.
Sourcepub fn nucleus_sampling(p: f32, temperature: f32) -> Self
pub fn nucleus_sampling(p: f32, temperature: f32) -> Self
Creates a config for nucleus (top-p) sampling.
Sourcepub fn beam_search(num_beams: usize) -> Self
pub fn beam_search(num_beams: usize) -> Self
Creates a config for beam search.
Sourcepub fn with_max_tokens(self, max_new_tokens: usize) -> Self
pub fn with_max_tokens(self, max_new_tokens: usize) -> Self
Sets the maximum number of new tokens.
Sourcepub fn with_eos_token(self, eos_token_id: u32) -> Self
pub fn with_eos_token(self, eos_token_id: u32) -> Self
Sets the EOS token ID.
Sourcepub fn with_repetition_penalty(self, penalty: f32) -> Self
pub fn with_repetition_penalty(self, penalty: f32) -> Self
Sets the repetition penalty.
Trait Implementations§
Source§impl Clone for GenerationConfig
impl Clone for GenerationConfig
Source§fn clone(&self) -> GenerationConfig
fn clone(&self) -> GenerationConfig
Returns a duplicate of the value. Read more
1.0.0 · 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 GenerationConfig
impl Debug for GenerationConfig
Source§impl Default for GenerationConfig
impl Default for GenerationConfig
Source§impl<'de> Deserialize<'de> for GenerationConfig
impl<'de> Deserialize<'de> for GenerationConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for GenerationConfig
impl RefUnwindSafe for GenerationConfig
impl Send for GenerationConfig
impl Sync for GenerationConfig
impl Unpin for GenerationConfig
impl UnwindSafe for GenerationConfig
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more