Class RepetitionPenaltyConfig
public sealed class RepetitionPenaltyConfig : LiteRTLMNativeHandle
- Inheritance
-
objectRepetitionPenaltyConfig
- Inherited Members
Constructors
RepetitionPenaltyConfig()
Creates a LiteRT LM Repetition Penalty Config with default values
(repetition_penalty = 1.0f, presence_penalty = 0.0f,
frequency_penalty = 0.0f, window_size = 0, which means all history with
no penalties active).
public RepetitionPenaltyConfig()
Remarks
When multiple penalties are configured and active, the order of application to output logits during decoding is:
- Multiplicative penalty (
repetition_penalty) - Subtractive penalties (
presence_penaltyandfrequency_penalty).
The caller is responsible for disposing the wrapper using Dispose().
Exceptions
- InvalidOperationException
Thrown if the native object could not be created.
Methods
ReleaseUnmanagedResources()
protected override void ReleaseUnmanagedResources()
SetFrequencyPenalty(float)
Sets the subtractive frequency penalty for the repetition penalty config.
public void SetFrequencyPenalty(float frequencyPenalty)
Parameters
frequencyPenaltyfloatA scalar subtracted from a token's logit, scaled linearly by the number of times that token has previously appeared inside the generated window history. Positive values discourage repetition, while negative values reward repeating tokens (OpenAI style). Defaults to 0.0f.
SetPresencePenalty(float)
Sets the subtractive presence penalty for the repetition penalty config.
public void SetPresencePenalty(float presencePenalty)
Parameters
presencePenaltyfloatA scalar subtracted from a token's logit if that token has appeared at least once inside the generated window history. Positive values discourage repetition, while negative values reward repeating tokens (OpenAI style). Defaults to 0.0f.
SetRepetitionPenalty(float)
Sets the multiplicative repetition penalty for the repetition penalty config.
public void SetRepetitionPenalty(float repetitionPenalty)
Parameters
repetitionPenaltyfloatA multiplicative penalty applied to a token's logit if that token has appeared at least once inside the generated window history (e.g., 1.0 = no penalty, 1.2 = moderate penalty). Positive logits are divided by this parameter, and negative logits are multiplied (HuggingFace style). The parameter must be >= 1.0f; values less than 1.0f are automatically clamped to 1.0f during execution.
SetWindowSize(int)
Sets the window size for the repetition penalty config.
public void SetWindowSize(int windowSize)
Parameters
windowSizeintThe maximum number of recent tokens in generation history to consider when computing penalization. Tokens generated prior to this window are forgotten. A value of 0 means tracking all infinite generation history. Must be >= 0; negative values are clamped to 0 during execution.