Struct GenerateOptions

Source
pub struct GenerateOptions<'a> {
Show 20 fields pub min_length: Option<i64>, pub max_length: Option<i64>, pub max_new_tokens: Option<i64>, pub early_stopping: Option<bool>, pub num_return_sequences: Option<i64>, pub num_beams: Option<i64>, pub num_beam_groups: Option<i64>, pub do_sample: Option<bool>, pub temperature: Option<f64>, pub top_k: Option<i64>, pub top_p: Option<f64>, pub repetition_penalty: Option<f64>, pub length_penalty: Option<f64>, pub no_repeat_ngram_size: Option<i64>, pub diversity_penalty: Option<f64>, pub decoder_start_token_id: Option<i64>, pub forced_bos_token_id: Option<i64>, pub prefix_allowed_tokens_fn: Option<PrefixAllowedFunction<'a>>, pub bad_word_ids: Option<&'a Vec<Vec<i64>>>, pub output_scores: bool,
}
Expand description

Type alias for a function defining allowed tokens based on current tokens generated. This function should take a batch_id and associated tensor of already generated tokens and should return a vector of allowed tokens. This is useful for controlled generation, i.e. deterministic generation of a token continuation if a sequence of token occurs.

§Generation options for text generation.

When provided to a generate method, these options will take priority over the GenerateConfig used to create the LanguageGenerator. Some of these options may be left as None, options without a value will individually default to the GenerateConfig.

Fields§

§min_length: Option<i64>

Minimum sequence length

§max_length: Option<i64>

Maximum sequence length

§max_new_tokens: Option<i64>

Maximum number of new tokens to generate (useful for causal generation models). Only one of max_length and max_new_tokens should be provided. When both are given, max_new_tokens is ignored and the max_length setting is used.

§early_stopping: Option<bool>

Early stopping flag indicating if the beam search should stop as soon as num_beam hypotheses have been generated

§num_return_sequences: Option<i64>

Number of sequences to return for each prompt text

§num_beams: Option<i64>

Number of beams for beam search

§num_beam_groups: Option<i64>§do_sample: Option<bool>

Sampling flag. If true, will perform top-k and/or nucleus sampling on generated tokens, otherwise greedy (deterministic) decoding

§temperature: Option<f64>

Temperature setting. Values higher than 1 will improve originality at the risk of reducing relevance

§top_k: Option<i64>

Top_k values for sampling tokens. Value higher than 0 will enable the feature

§top_p: Option<f64>

Top_p value for Nucleus sampling, Holtzman et al.. Keep top tokens until cumulative probability reaches top_p

§repetition_penalty: Option<f64>

Repetition penalty (mostly useful for CTRL decoders). Values higher than 1 will penalize tokens that have been already generated.

§length_penalty: Option<f64>

Exponential penalty based on the length of the hypotheses generated

§no_repeat_ngram_size: Option<i64>

Number of allowed repetitions of n-grams. Values higher than 0 turn on this feature

§diversity_penalty: Option<f64>

Diversity penalty for diverse beam search. High values will enforce more difference between beam groups

§decoder_start_token_id: Option<i64>

Decoder start token id

§forced_bos_token_id: Option<i64>

Forced first token generated

§prefix_allowed_tokens_fn: Option<PrefixAllowedFunction<'a>>

Function to control the generation process. The function should take a batch_id (i64) and a tensor of token_ids already generated and returns a Vec<i64> of allowed tokens.

§bad_word_ids: Option<&'a Vec<Vec<i64>>>

List of bad word ids (may be a sequence of word ids) that will be banned during the generation

§output_scores: bool

Flag indicating if text generation scores should be returned

Trait Implementations§

Source§

impl<'a> Clone for GenerateOptions<'a>

Source§

fn clone(&self) -> GenerateOptions<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Default for GenerateOptions<'a>

Source§

fn default() -> GenerateOptions<'a>

Returns the “default value” for a type. Read more
Source§

impl<'a> Copy for GenerateOptions<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for GenerateOptions<'a>

§

impl<'a> !RefUnwindSafe for GenerateOptions<'a>

§

impl<'a> !Send for GenerateOptions<'a>

§

impl<'a> !Sync for GenerateOptions<'a>

§

impl<'a> Unpin for GenerateOptions<'a>

§

impl<'a> !UnwindSafe for GenerateOptions<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T