Skip to content

Fix FLUX and SD3 T5 prompt truncation warning slicing - #15499

Open
ansh-rohilla wants to merge 1 commit into
huggingface:mainfrom
ansh-rohilla:fix/flux-sd3-t5-truncation-warning
Open

ansh-rohilla wants to merge 1 commit into
huggingface:mainfrom
ansh-rohilla:fix/flux-sd3-t5-truncation-warning

Conversation

@ansh-rohilla

Copy link
Copy Markdown

What does this PR do?

Fixes the T5 prompt truncation warning slicing in FLUX, SD3, their # Copied from / non-copied variants, and modular SD3:

  • FluxPipeline._get_t5_prompt_embeds (and synced # Copied from FLUX / VisualCloze pipelines) + FluxControlNetPipeline._get_t5_prompt_embeds: replaced untruncated_ids[:, self.tokenizer_max_length - 1 : -1] with untruncated_ids[:, max_sequence_length - 1 : -1].
  • StableDiffusion3Pipeline._get_t5_prompt_embeds (and synced # Copied from SD3 / ControlNet-SD3 / PAG-SD3 pipelines): replaced untruncated_ids[:, self.tokenizer_max_length - 1 : -1] with untruncated_ids[:, max_sequence_length - 1 : -1].
  • diffusers.modular_pipelines.stable_diffusion_3.encoders._get_t5_prompt_embeds: replaced untruncated_ids[:, tokenizer.model_max_length - 1 : -1] with untruncated_ids[:, max_sequence_length - 1 : -1].

Previously, self.tokenizer_max_length (77, from CLIP) or tokenizer.model_max_length (512) was used to slice the untruncated T5 token IDs even when truncation occurred at max_sequence_length, causing the warning to log the wrong tail (often ['']) instead of the discarded T5 tokens.

Fixes #15495

Tests & Verification

  • Added offline CPU regression tests test_t5_prompt_truncation_warning in tests/pipelines/flux/test_pipeline_flux.py (TestFluxPipeline) and tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3.py (TestStableDiffusion3Pipeline, also covering diffusers.modular_pipelines.stable_diffusion_3.encoders._get_t5_prompt_embeds).
  • python utils/check_copies.py: All checks passed!
  • ruff check and ruff format --check on all 24 touched files: passed (24 files already formatted).
  • pytest offline CPU run on TestFluxPipeline and TestStableDiffusion3Pipeline (test_t5_prompt_truncation_warning): passed (2 passed). Prior to the 1-line formatting adjustment in test_pipeline_stable_diffusion_3.py, the non-slow FLUX + SD3 pipeline suites ran with 126 passed, 44 skipped (accelerator/memory/slow skipped, test_sd3_lora deselected offline).

Self-review notes

  • Reviewed against .ai/references/review-rules.md, code_style.md, pipelines.md, and testing.md.
  • Blocking issues: None.
  • Non-blocking / scope note: All # Copied from files were propagated with check_copies.py --fix_and_overwrite, and pipeline_flux_controlnet.py (which does not use # Copied from on _get_t5_prompt_embeds) was updated alongside them. Audited remaining self.tokenizer_max_length - 1 occurrences in src/: all remaining hits are in CLIP prompt encoders (tokenizer / self.tokenizer), and modular_pipelines/flux/encoders.py already uses max_sequence_length - 1 : -1.
  • Dead code: None introduced or left behind.
  • Verdict: READY.

Before submitting

  • Did you use an AI agent (Claude Code, Codex, Cursor, etc.) to help with this PR? If so:
    • Did you read the Coding with AI agents guide?
    • Did you run the self-review skill on the diff?
    • Did you share the final self-review notes in the PR description or a comment?
  • Did you read the contributor guideline?
  • Did you read our philosophy doc? (important for complex PRs)
  • Was this discussed/approved via a GitHub issue or GitHub Discussions? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Are you the author (or part of the team we work with) of the model/pipeline this PR relates to?

Who can review?

@yiyixuxu @sayakpaul

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