New Tool Radar

AI Concepts

How to Set a Repetition Penalty So a Model Stops Looping the Same Phrase

Raise the repetition penalty above 1.0 in small steps, check the loop breaks, and stop before the penalty damages normal repetition.

Schematic with three steps: Confirm the loop and record it; Raise the penalty in small steps; Check normal text still reads well.

Greedy decoding can fall into a loop, repeating the same phrase forever, and sampling can do the same when the repeated tokens stay the most likely. A repetition penalty lowers the score of tokens the model has already generated, so the loop breaks. In GenerationConfig, the repetition_penalty parameter controls this, and 1.0 means no penalty. Raise it in small steps and watch the output: too little changes nothing, and too much punishes words that legitimately repeat, such as names and numbers.

What you need

  • A prompt that makes the model loop
  • Access to the repetition_penalty setting
  • A test for normal text, to check the penalty does not damage it

Step 1: Confirm the loop and record it

Run the looping prompt and save the output. Note where the repetition starts and which phrase repeats, so you can tell whether the fix worked.

Step 2: Raise the penalty in small steps

Set repetition_penalty just above 1.0 and re-run the same prompt. Increase it in small steps until the loop breaks. A large jump in one step can damage the output in ways that are hard to trace back.

Step 3: Check normal text still reads well

Run a normal prompt that legitimately repeats words, such as a list or a story with a recurring name, and check it still reads naturally. If the model starts avoiding ordinary words, the penalty is too high.

Worked example: synthetic repetition penalty test

The table below is a synthetic example. It shows the expected result of setting a repetition penalty; no model was run.

Repetition penalty Loop broken? Normal text quality
1.0 No – loops Good
1.1 Yes Good
1.3 Yes Good
1.8 Yes Degraded

Expected result (UNTESTED). a penalty of 1.1 breaks the loop with no damage, while 1.8 degrades normal text. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • A repetition penalty of 1.0 means no penalty, so the default does nothing against loops.
  • The penalty applies to tokens already generated, so it cannot fix a loop that starts with new tokens.
  • A high penalty can make the model avoid words it should repeat, such as a name used twice.
  • Repetition penalty is one control among several: no-repeat n-gram blocking and a lower temperature can also break loops.

Sources

See all