{"slug": "one-more-measured-note-for-transformers-with-a-runnable-check", "title": "One more measured note for transformers, with a runnable check", "summary": "A reproduction of Hugging Face Transformers issue #51093 on versions 5.25.0 and 5.24.1 found that repetition penalty diverges between solo and left-padded batched generation when prompts are supplied as inputs_embeds only: with repetition_penalty=2.0, only 1 of 4 padding conditions (0, 1, 3, 5) produced identical continuations, versus 4/4 when input_ids or both IDs and embeddings were passed. The author attributes the mismatch to token-ID history starting empty for embeddings-only input while the offset derived from the padded prompt is still applied to generated IDs, and reports a caller-side workaround — passing RepetitionPenaltyLogitsProcessor(2.0, prompt_ignore_length=None) explicitly with repetition_penalty=1.0 — that restored 4/4 equal continuations on both releases.", "body_md": "I also checked this on Transformers 5.25.0 itself:\n\nI reproduced the difference reported in [#51093](https://github.com/huggingface/transformers/issues/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.\n\n| Prompt supplied to `generate()` | `repetition_penalty=1.0` | `repetition_penalty=2.0` | \n|---|---|---|\n| `input_ids` | 4/4 equal | 4/4 equal | \n| `inputs_embeds` only | 4/4 equal | 1/4 equal | \n| Both IDs and corresponding embeddings | 4/4 equal | 4/4 equal | \n\nEach 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.\n\nFor embeddings-only input and penalty 2.0, the solo continuation was `[34, 14, 21, 48, 13, 8, 39, 45]`. The batched continuations were:\n\n| Left-padding positions | Newly generated token IDs for the short row | \n|---|---|\n| 0 | `[34, 14, 21, 48, 13, 8, 39, 45]` | \n| 1 | `[34, 34, 45, 19, 20, 31, 23, 5]` | \n| 3 | `[34, 34, 34, 34, 16, 19, 20, 31]` | \n| 5 | `[34, 34, 34, 34, 34, 34, 16, 19]` | \n\nThe 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.\n\nThere 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:\n\n| Processor style | Automatic `repetition_penalty` | Explicit repetition processor | Equal continuations | \n|---|---|---|---|\n| Ordinary automatic construction | 2.0 | None | 1/4 | \n| Same-type custom replacement | 2.0 | `RepetitionPenaltyLogitsProcessor(2.0, prompt_ignore_length=None)` | 4/4 | \n| Explicit processor only | 1.0 | `RepetitionPenaltyLogitsProcessor(2.0, prompt_ignore_length=None)` | 4/4 | \n\nIf the desired policy is to penalize generated IDs only, I would start with the explicit-only form, provided the other processors are ordered appropriately:\n\n``` python\nfrom transformers import RepetitionPenaltyLogitsProcessor\n\nresult = model.generate(\n    inputs_embeds=prompt_embeds,\n    attention_mask=attention_mask,\n    repetition_penalty=1.0,\n    logits_processor=[\n        RepetitionPenaltyLogitsProcessor(2.0, prompt_ignore_length=None)\n    ],\n    max_new_tokens=8,\n    do_sample=False,\n    pad_token_id=0,\n)\n```\n\nThe 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).\n\n| Input requirement | Suggested first route | \n|---|---|\n| Ordinary text | Real `input_ids` and mask. | \n| Known IDs and embeddings | Supply both where the model supports it; worked here. | \n| Embeddings without meaningful IDs | Solo or equal-length batches if feasible. | \n| Variable-length padded embeddings only, with repetition control | Explicit generated-only processor, as above. | \n\nDo 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.\n\nThe [5.25.0 release](https://github.com/huggingface/transformers/releases/tag/v5.25.0) still contains the mask-derived offset, and the CPU run establishes reachability on the tested path.", "url": "https://wpnews.pro/news/one-more-measured-note-for-transformers-with-a-runnable-check", "canonical_source": "https://discuss.huggingface.co/t/one-more-measured-note-for-transformers-with-a-runnable-check/192475#post_2", "published_at": "2026-12-02 02:01:36+00:00", "updated_at": "2026-12-02 02:15:01.921611+00:00", "lang": "en", "topics": ["large-language-models", "ai-research", "developer-tools", "natural-language-processing"], "entities": ["Hugging Face", "Transformers", "Transformers 5.25.0", "Transformers 5.24.1", "Llama", "RepetitionPenaltyLogitsProcessor"], "also_reported_by": [], "takeaway": "With embeddings-only input and repetition_penalty=2.0, left-padded batches diverged from solo generation in 3 of 4 padding lengths, while an explicit RepetitionPenaltyLogitsProcessor(2.0, prompt_ignore_length=None) with repetition_penalty=1.0 restored 4/4 equal continuations.", "recommendation": {"advice": "When generating from inputs_embeds with repetition control, pass RepetitionPenaltyLogitsProcessor(2.0, prompt_ignore_length=None) explicitly and set repetition_penalty=1.0; the source measured 4/4 equal continuations versus 1/4 with automatic construction.", "playbook": "inference-serving", "playbook_url": "https://wpnews.pro/playbooks/inference-serving"}, "alternates": {"html": "https://wpnews.pro/news/one-more-measured-note-for-transformers-with-a-runnable-check", "markdown": "https://wpnews.pro/news/one-more-measured-note-for-transformers-with-a-runnable-check.md", "text": "https://wpnews.pro/news/one-more-measured-note-for-transformers-with-a-runnable-check.txt", "jsonld": "https://wpnews.pro/news/one-more-measured-note-for-transformers-with-a-runnable-check.jsonld"}}