Skip to content

Fix T5 truncation warnings to report the actual discarded tokens - #15498

Open
Kulraj69 wants to merge 1 commit into
huggingface:mainfrom
Kulraj69:fix-t5-truncation-discarded-text
Open

Kulraj69 wants to merge 1 commit into
huggingface:mainfrom
Kulraj69:fix-t5-truncation-discarded-text

Conversation

@Kulraj69

@Kulraj69 Kulraj69 commented Dec 5, 2026

Copy link
Copy Markdown

What

_get_t5_prompt_embeds decodes the discarded prompt suffix from self.tokenizer_max_length - 1 (the CLIP limit) instead of max_sequence_length. When max_sequence_length is below the CLIP limit (for example 8), the slice is empty, so the truncation warning reports [''] instead of the actually discarded T5 tokens.

Reproduced on current main with the issue's tiny-flux-pipe example: the warning printed [''], while the T5 tokenizer decodes the discarded suffix as o three four five six seven eight nine ten.

Change

  • Slice untruncated_ids[:, max_sequence_length - 1 : -1] in the two source methods (FluxPipeline._get_t5_prompt_embeds, StableDiffusion3Pipeline._get_t5_prompt_embeds), mirroring how the CLIP path uses self.tokenizer_max_length - 1.
  • Synced all # Copied from copies with python utils/check_copies.py --fix_and_overwrite (18 files, one line each).

Tests

  • Added regression tests to the Flux and SD3 pipeline test suites asserting the truncation warning contains the actual discarded T5 text. Both fail before this change and pass after.
  • Ran both full fast test classes: 44 passed, 8 skipped.
  • ruff format and ruff check clean.

Fixes #15495

Prepared with AI assistance; every test above was executed locally on CPU (PyTorch 2.14.1+cpu, transformers 5.20.2).

_get_t5_prompt_embeds sliced untruncated ids from tokenizer_max_length - 1
(the CLIP limit) instead of max_sequence_length, so the truncation warning
for the T5 prompt decoded an empty string instead of the discarded suffix
whenever max_sequence_length was smaller than the CLIP limit.

Slice from max_sequence_length - 1 in the Flux and SD3 source methods and
sync all '# Copied from' copies. Add regression tests asserting the warning
contains the actual discarded T5 text (they fail before this change).

Fixes huggingface#15495

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FLUX and SD3 report the wrong discarded T5 prompt tokens

1 participant