Repository navigation
miotts: apply repetition_penalty once per distinct token (HF semantics) - #906
Merged
0xShug0 merged 1 commit intoOct 14, 2026
Merged
Conversation
apply_repetition_penalty walked the whole history and rescaled a logit again for every occurrence, so a speech token (or EOS) that had already appeared n times was penalized penalty^n. transformers' RepetitionPenaltyLogitsProcessor, and this repo's own HfLogitsProcessor::apply_repetition_penalty, rescale each distinct token in the history exactly once. Remember which speech tokens (and EOS) were already rescaled in this step and skip the repeats. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
@zlatkoviz-png Thanks! PR merged. |
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.
What
apply_repetition_penaltyinsrc/models/miotts/causal_lm.cppwalks the whole history and rescales a logit once per occurrence. A speech token that has already been generatedntimes is therefore penalizedpenalty^ninstead ofpenalty.transformers'
RepetitionPenaltyLogitsProcessor(gather atinput_ids, scatter back) and this repo's ownHfLogitsProcessor::apply_repetition_penaltyrescale each distinct token in the history exactly once. This PR does the same for MioTTS: it remembers which speech tokens (and EOS) were already rescaled in the current step and skips the repeats. No other code is touched.Impact (honest summary)
repetition_penalty = 1.0(the default when the checkpoint has norepetition_penaltyingeneration_config.json, as withAratako/MioTTS-1.7B): the function returns early, so nothing changes.repetition_penalty = 1.005. At that point the old code's choice no longer matches transformers (details below).So this is a parity/correctness fix with a small practical footprint at common settings, not a quality fix you would hear at 1.05.
Validation
Everything below is CPU only, with public assets only:
Aratako/MioTTS-1.7Bconverted withaudiocpp_gguf --type f16;samples/en_ref1.wavfrom the MioTTS-1.7B HF repo;do_sample=false),--seed 0,--threads 8,--backend cpu;The base is
main@571c92cf; "old" ismain, "new" is this branch.Build:
Run (one batch session per setting):
Sentences (8, English):
The 3-sentence runs use 03, 04 and 05 (the ones that loop at 1.0).
1. Regression: outputs unchanged where the bug cannot trigger
The 1.0 runs use plain builds of
mainand of this branch. The 1.02/1.05 runs (and section 2) use the same two builds with the diagnostic print below added, so that the token multiplicity could be counted; the print does not touch any computation. As a control,cmpdoes report a difference between outputs that really differ, e.g. sentence 03 at 1.0 vs 1.05.At 1.0 (greedy) the stock model runs into a token loop and hits
max_tokens(700) on 5 of the 8 sentences. That is the same for old and new and is not related to this PR.2. A case where the bug triggers, compared with transformers
To see the generated token ids I used a local, not included, diagnostic patch. It prints
out.token_ids(as<|s_N|>indices) to stderr whenAUDIOCPP_MIOTTS_DUMP_TOKENS=1is set; the patch is below. The transformers reference isAutoModelForCausalLMin fp32 on CPU:The prompt is built with
apply_chat_template(..., add_generation_prompt=True)andadd_special_tokens=False, which is the same prompt audio.cpp builds.repetition_penalty = 1.005, greedy:At step 61 of sentence 05, speech token
6449had already been generated twice. transformers and the new code penalize it once (/1.005), and it stays the argmax. The old code penalizes it twice (/1.005^2), so it picks12273instead. From that step on, the old sequence differs, and it ends 6 tokens longer. In the reference,6449ends up occurring 6 times in that sentence; in the old output, no token occurs more than twice. The WAV for 05 differs between old and new; 03 and 04 are bit-identical.The transformers run was
transformers5.14.1 withtorch2.10.0 on CPU in fp32, against audio.cpp F16 on CPU. They agree token for token on all three sentences, so the only disagreement in this table is the bug.diagnostic patch (local only, not part of this PR)
Notes
HfLogitsProcessoralready has a generation-stampedseen_scratch. I kept the fix model-local, in line with CONTRIBUTING's guidance, instead of rewiring MioTTS onto the shared sampler. A per-stepstd::vector<uint8_t>ofspeech_token_countbytes is negligible next to a decode step.🤖 Generated with Claude Code