fix: add repetition penalty to mitigate multi-turn repetition (fixes #1125)#1129
Open
modimihir07 wants to merge 1 commit intodeepseek-ai:mainfrom
Open
fix: add repetition penalty to mitigate multi-turn repetition (fixes #1125)#1129modimihir07 wants to merge 1 commit intodeepseek-ai:mainfrom
modimihir07 wants to merge 1 commit intodeepseek-ai:mainfrom
Conversation
ai-nurmamat
approved these changes
Mar 11, 2026
ai-nurmamat
left a comment
There was a problem hiding this comment.
Great fix for the repetition issue! Consider adding a configurable repetition penalty range in the inference config.
Author
|
Thanks for the approval and the great suggestion, @Financier-Nuri! I've
added --repetition-penalty-min (default: 1.0) and --repetition-penalty-max
(default: 2.0) CLI arguments. The penalty value is now validated against
these bounds at startup, raising a clear ValueError if it's out of range.
…On Wed, 11 Mar 2026 at 05:40, Nurmamat.Omar ***@***.***> wrote:
***@***.**** approved this pull request.
Great fix for the repetition issue! Consider adding a configurable
repetition penalty range in the inference config.
—
Reply to this email directly, view it on GitHub
<#1129 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BK54AHPY6GPNT56TBFKIY6L4QCVINAVCNFSM6AAAAACWDOJ6DOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTSMRWGE2TIOBZGY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #1125
The sample() function in generate.py only supports temperature scaling. There is no mechanism to penalize tokens that have already been generated, which causes a self-reinforcing repetition loop in multi-turn dialogues:
Fix
Added
repetition_penaltyparameter using the approach from the CTRL paper (Keskar et al., 2019) — the same method used by HuggingFace Transformers and vLLM:Changes:
repetition_penaltyandgenerated_tokensparametersrepetition_penaltythrough--repetition-penaltyflag (default:1.0= backward compatible)Usage