Table of Contents

Class NativeAPI.RepetitionPenaltyConfig

public static class NativeAPI.RepetitionPenaltyConfig
Inheritance
object
NativeAPI.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:

  1. Multiplicative penalty (repetition_penalty)
  2. Subtractive penalties (presence_penalty and frequency_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

config nint

The 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

config nint

The config to modify.

frequencyPenalty float

A 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

config nint

The config to modify.

presencePenalty float

A 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

config nint

The config to modify.

repetitionPenalty float

A 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

config nint

The config to modify.

windowSize int

The 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.