A model stuck in a loop repeats the same phrase until it runs out of tokens. Penalties are a blunt fix applied at sampling time.
How it works
Before each next token is drawn, the server adjusts the scores of tokens already generated.
| Setting | What vLLM’s docs say it penalises | Range and default |
|---|---|---|
presence_penalty |
Tokens “based on whether they appear in the generated text so far” | OpenAI: -2.0 to 2.0, default 0 |
frequency_penalty |
Tokens “based on their frequency in the generated text so far” | OpenAI: -2.0 to 2.0, default 0 |
repetition_penalty |
Tokens “based on whether they appear in the prompt and the generated text so far” | vLLM and Hugging Face: 1.0 means no penalty |
Positive values push away from used tokens; negative values make repeats more likely. OpenAI says a positive frequency penalty lowers “the model’s likelihood to repeat the same line verbatim”, and a positive presence penalty raises “the model’s likelihood to talk about new topics”. For repetition_penalty, vLLM says values above 1 favour new tokens and values below 1 favour repetition. Hugging Face’s docs point to the CTRL paper for this penalty.
{"model": "...", "messages": [...], "frequency_penalty": 0.5, "presence_penalty": 0.3}
Why it matters
- Loops in long outputs. Agents and long summaries can fall into repeating text. A small penalty can break the loop, and a hard max_tokens limit caps the damage.
- Side effects. Penalties act on tokens, not ideas. A strong one can stop a model reusing words it needs, such as a variable name in code, a JSON key, or a name in an Arabic text that repeats by design. Start at 0 and change in small steps.
- Overlap with sampling. Temperature and top-p also change variety. Change one setting at a time when you test.
On BroadNet Inference
BroadNet’s API reference does not document frequency_penalty, presence_penalty or repetition_penalty. Test them before relying on them: send a prompt that tends to repeat, with and without the field, and compare. If repetition shows up in long runs, try a clearer prompt, a lower output limit, or stop the run and resume from a checkpoint; the overnight agent runs post covers that pattern.
Common mistakes
- Setting penalties high to fix a prompt problem. Repetition often means the model has no clear stopping point.
- Using a penalty on structured output, where keys must repeat.