pub struct GenerationConfig {Show 20 fields
pub max_length: usize,
pub max_new_tokens: Option<usize>,
pub min_length: usize,
pub mode: GenerationMode,
pub temperature: f32,
pub repetition_penalty: f32,
pub frequency_penalty: f32,
pub presence_penalty: f32,
pub length_penalty: f32,
pub num_return_sequences: usize,
pub early_stopping: bool,
pub no_kv_cache: bool,
pub eos_token_id: Option<u32>,
pub pad_token_id: Option<u32>,
pub bos_token_id: Option<u32>,
pub stopping_criteria: Vec<StoppingCriteria>,
pub bad_words_ids: Vec<Vec<u32>>,
pub force_words_ids: Vec<Vec<u32>>,
pub repetition_penalty_decay: f32,
pub seed: Option<u64>,
}Expand description
Configuration for text generation
Fields§
§max_length: usizeMaximum length of generated sequence (including input)
max_new_tokens: Option<usize>Maximum number of NEW tokens to generate (alternative to max_length)
min_length: usizeMinimum length of generated sequence
mode: GenerationModeGeneration mode (greedy, beam search, sampling, etc.)
temperature: f32Temperature for sampling (higher = more random, lower = more deterministic) Applied before other sampling methods
repetition_penalty: f32Repetition penalty (>1.0 discourages repetition, <1.0 encourages it)
frequency_penalty: f32Frequency penalty - penalize tokens based on their frequency so far
presence_penalty: f32Presence penalty - penalize tokens that have appeared at all
length_penalty: f32Length penalty for beam search (>1.0 encourages longer sequences)
num_return_sequences: usizeNumber of beams to return (for beam search, must be <= num_beams)
early_stopping: boolEarly stopping for beam search
no_kv_cache: boolDisable key-value caching (slower but uses less memory)
eos_token_id: Option<u32>EOS token ID
pad_token_id: Option<u32>PAD token ID for batch generation
bos_token_id: Option<u32>BOS token ID
stopping_criteria: Vec<StoppingCriteria>Additional stopping criteria
bad_words_ids: Vec<Vec<u32>>Bad words that should not be generated (token IDs)
force_words_ids: Vec<Vec<u32>>Force specific tokens at specific positions
repetition_penalty_decay: f32Exponential decay factor for past tokens in repetition penalty
seed: Option<u64>Random seed for reproducible sampling
Implementations§
Source§impl GenerationConfig
impl GenerationConfig
Sourcepub fn beam_search(num_beams: usize) -> Self
pub fn beam_search(num_beams: usize) -> Self
Create a beam search config
Sourcepub fn contrastive_search(top_k: usize, alpha: f32) -> Self
pub fn contrastive_search(top_k: usize, alpha: f32) -> Self
Create a contrastive search config
Trait Implementations§
Source§impl Clone for GenerationConfig
impl Clone for GenerationConfig
Source§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>,
Auto Trait Implementations§
impl Freeze for GenerationConfig
impl RefUnwindSafe for GenerationConfig
impl Send for GenerationConfig
impl Sync for GenerationConfig
impl Unpin for GenerationConfig
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ConfigSerializable for Twhere
T: Serialize + for<'de> Deserialize<'de>,
impl<T> ConfigSerializable for Twhere
T: Serialize + for<'de> Deserialize<'de>,
Source§fn save_to_file(&self, path: &Path) -> Result<(), TrustformersError>
fn save_to_file(&self, path: &Path) -> Result<(), TrustformersError>
Source§fn load_from_file(path: &Path) -> Result<Self, TrustformersError>where
Self: Sized,
fn load_from_file(path: &Path) -> Result<Self, TrustformersError>where
Self: Sized,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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