RepetitionPenalty

RepetitionPenalty divides the logit of any token that appeared in the recent window (see PenaltyContextSize) by the penalty value. Values above 1.0 make recently-seen tokens less likely to be picked again.

Quick reference

Type float
Default 1.1
Range 1.0 = disabled, above 1.0 = active
Category Repetition penalty
Field on SamplerParameters.RepetitionPenalty

What it does

For each token that appeared at least once in the penalty window, divide its logit by RepetitionPenalty before sampling. The higher the penalty, the stronger the suppression.

  • 1.0 — no penalty; behaves as if disabled.
  • 1.051.15 — gentle. Breaks common loop patterns without starving the sampler of basic words.
  • 1.21.3 — aggressive. Useful when the model loops persistently, but risks under-generating common words like “the” or “and”.
  • 1.5+ — very aggressive. The model will work hard to use different words; output quality usually drops.

When to change it

Scenario Value
Disabled 1.0
Default (most chat) 1.1
Model loops occasionally 1.15
Model loops persistently 1.2
Do not change beyond 1.3 without reason

If raising RepetitionPenalty past 1.2 still does not solve looping, switch to DryMultiplier (DRY) — it catches phrase-level repeats that token-level penalty misses.

Example

var preset = new Qwen25Preset();
preset.SamplerParameters.RepetitionPenalty = 1.15f;
preset.SamplerParameters.PenaltyContextSize = 256;

using var api = AsposeLLMApi.Create(preset);
string reply = await api.SendMessageAsync("Describe spring in three sentences.");
Console.WriteLine(reply);

Interactions

What’s next