Add repetition penalty to the llm-runner - #176
Open
stikves wants to merge 4 commits into
Open
Conversation
stikves
requested review from
alejandro-isaza,
carinapeng,
chpriyal,
kevchengcodes and
tjia1818
August 15, 2026 18:36
Penalizes tokens that appear in recent generation history, discouraging repetitive output. Applied as a separate logit modification step before the existing sampling pipeline (temperature/topK/topP/minP). - Add repetitionPenalty and repetitionPenaltyWindow to SamplingConfiguration - Add RepetitionPenaltyProcessor (deduplicates, sign-aware divide/multiply) - Integrate into Sequential, StaticShape, VLM, and Constrained engines - Only penalize generated tokens (not prompt) via generationStartOffset - Pipelined engine: hard fail with clear error (GPU path in follow-up) - CLI: --repetition-penalty and --repetition-penalty-window flags
stikves
force-pushed
the
sukru/repetition-penalty
branch
3 times, most recently
from
August 15, 2026 19:02
1b9a3fc to
5225f38
Compare
Extend MPSGraphCompositeSampler with an optional penalty stage (penaltyEnabled flag at init). When active, the compiled graph applies sign-aware penalty (divide positive logits, multiply negative) before topK. Refactor the monolithic graph-building init into composable static stage helpers (applyPenaltyStage, topKStage, temperatureStage, softmaxStage, minPStage, topPStage, maskAndNormalizeStage, multinomialStage, gatherTokenStage) that can be unit-tested independently. RepetitionPenaltyGPUState manages per-pipeline-depth rotating penalty buffers with dirty-tracking: recordToken() updates only CPU-side ring state, and buffer(forStep:) applies pending writes at encode time when the gate guarantees no in-flight GPU read on that slot. Inherent 2-token staleness from pipelineDepth=3 is acceptable for practical window sizes. Greedy + penalty on pipelined is rejected at entry (use sequential).
stikves
force-pushed
the
sukru/repetition-penalty
branch
from
August 15, 2026 19:04
5225f38 to
0442649
Compare
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.
Adds repetition penalty to existing sampler pipelines.
For sequential ones, provides immediate logits penalty
For pipelined engine, it lags by the pipeline depth - 1 (currently: 2)
Closes: #43
A follow up should provide a better interface for logits buffer manipulation (currently only contained sampling and repetition penalty, so duplication is acceptable)