I also checked this on Transformers 5.25.0 itself:
I reproduced the difference reported in #51093 on both 5.25.0 and 5.24.1, using the same small Llama fixture. I varied the input representation, leading-padding length and repetition penalty, and also checked two caller-side ways to supply an explicit repetition processor through the real generate() API.
| Prompt supplied to generate() | repetition_penalty=1.0 | repetition_penalty=2.0 | |---|---|---| | input_ids | 4/4 equal | 4/4 equal | | inputs_embeds only | 4/4 equal | 1/4 equal | | Both IDs and corresponding embeddings | 4/4 equal | 4/4 equal |
Each cell compares eight newly generated IDs for a short prompt alone and in the first row of a two-row batch, for left-padding lengths 0, 1, 3 and 5. Both releases gave the same 24-condition results. Equality means identical continuation IDs, not bitwise-identical scores. These are conditions on one seeded model, not independent models or a quality benchmark.
For embeddings-only input and penalty 2.0, the solo continuation was [34, 14, 21, 48, 13, 8, 39, 45]. The batched continuations were:
| Left-padding positions | Newly generated token IDs for the short row | |---|---| | 0 | [34, 14, 21, 48, 13, 8, 39, 45] | | 1 | [34, 34, 45, 19, 20, 31, 23, 5] | | 3 | [34, 34, 34, 34, 16, 19, 20, 31] | | 5 | [34, 34, 34, 34, 34, 34, 16, 19] |
The three-pad case matches the report exactly. In the three affected conditions the first different choice was the second generated token. The pattern supports a mismatch between prompt positions and token-ID history: when only embeddings are supplied, the ID history starts empty, but the offset derived from the padded prompt is applied to generated IDs. A correct attention mask alone cannot resolve that mismatch.
There is also a caller-side workaround for this particular decoder-only, embeddings-only use case. Both explicit processor styles below retained one effective repetition processor with penalty 2.0 and no ignore prefix. I checked them on both releases, with the same four padding lengths:
| Processor style | Automatic repetition_penalty | Explicit repetition processor | Equal continuations | |---|---|---|---| | Ordinary automatic construction | 2.0 | None | 1/4 | | Same-type custom replacement | 2.0 | RepetitionPenaltyLogitsProcessor(2.0, prompt_ignore_length=None) | 4/4 | | Explicit processor only | 1.0 | RepetitionPenaltyLogitsProcessor(2.0, prompt_ignore_length=None) | 4/4 |
If the desired policy is to penalize generated IDs only, I would start with the explicit-only form, provided the other processors are ordered appropriately:
from transformers import RepetitionPenaltyLogitsProcessor
result = model.generate(
inputs_embeds=prompt_embeds,
attention_mask=attention_mask,
repetition_penalty=1.0,
logits_processor=[
RepetitionPenaltyLogitsProcessor(2.0, prompt_ignore_length=None)
],
max_new_tokens=8,
do_sample=False,
pad_token_id=0,
)
The automatic penalty is neutralized, not the explicit processor. Use the actual model’s pad ID and mask; 0 is the fixture value. Same-type replacement is another option where processor ordering matters (section 5).
| Input requirement | Suggested first route | |---|---| | Ordinary text | Real input_ids and mask. | | Known IDs and embeddings | Supply both where the model supports it; worked here. | | Embeddings without meaningful IDs | Solo or equal-length batches if feasible. | | Variable-length padded embeddings only, with repetition control | Explicit generated-only processor, as above. |
Do not apply the generated-only workaround indiscriminately to ordinary ID-backed inputs: the earlier exclusion of real left-padding positions is useful, particularly when PAD and EOS share a value. Avoid fabricated prompt IDs. Penalty 1.0 alone is a diagnostic that gives up repetition control.
The 5.25.0 release still contains the mask-derived offset, and the CPU run establishes reachability on the tested path.