Class NativeAPI.RepetitionPenaltyConfig
public static class NativeAPI.RepetitionPenaltyConfig
- Inheritance
-
objectNativeAPI.RepetitionPenaltyConfig
Methods
litert_lm_repetition_penalty_config_create()
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 static extern nint litert_lm_repetition_penalty_config_create()
Returns
- nint
A pointer to the created config, or nint.Zero on failure.
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 destroying the config using litert_lm_repetition_penalty_config_delete(nint).
litert_lm_repetition_penalty_config_delete(nint)
Destroys a LiteRT LM Repetition Penalty Config.
public static extern void litert_lm_repetition_penalty_config_delete(nint config)
Parameters
confignintThe config to destroy.
litert_lm_repetition_penalty_config_set_frequency_penalty(nint, float)
Sets the subtractive frequency penalty for the repetition penalty config.
public static extern void litert_lm_repetition_penalty_config_set_frequency_penalty(nint config, float frequencyPenalty)
Parameters
confignintThe config to modify.
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.
litert_lm_repetition_penalty_config_set_presence_penalty(nint, float)
Sets the subtractive presence penalty for the repetition penalty config.
public static extern void litert_lm_repetition_penalty_config_set_presence_penalty(nint config, float presencePenalty)
Parameters
confignintThe config to modify.
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.
litert_lm_repetition_penalty_config_set_repetition_penalty(nint, float)
Sets the multiplicative repetition penalty for the repetition penalty config.
public static extern void litert_lm_repetition_penalty_config_set_repetition_penalty(nint config, float repetitionPenalty)
Parameters
confignintThe config to modify.
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.
litert_lm_repetition_penalty_config_set_window_size(nint, int)
Sets the window size for the repetition penalty config.
public static extern void litert_lm_repetition_penalty_config_set_window_size(nint config, int windowSize)
Parameters
confignintThe config to modify.
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.