Repository navigation
Fix FLUX and SD3 T5 prompt truncation warning slicing - #15499
Open
ansh-rohilla wants to merge 1 commit into
Open
ansh-rohilla wants to merge 1 commit into
ansh-rohilla wants to merge 1 commit into
Conversation
This branch has not been deployed
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 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 fromFLUX / VisualCloze pipelines) +FluxControlNetPipeline._get_t5_prompt_embeds: replaceduntruncated_ids[:, self.tokenizer_max_length - 1 : -1]withuntruncated_ids[:, max_sequence_length - 1 : -1].StableDiffusion3Pipeline._get_t5_prompt_embeds(and synced# Copied fromSD3 / ControlNet-SD3 / PAG-SD3 pipelines): replaceduntruncated_ids[:, self.tokenizer_max_length - 1 : -1]withuntruncated_ids[:, max_sequence_length - 1 : -1].diffusers.modular_pipelines.stable_diffusion_3.encoders._get_t5_prompt_embeds: replaceduntruncated_ids[:, tokenizer.model_max_length - 1 : -1]withuntruncated_ids[:, max_sequence_length - 1 : -1].Previously,
self.tokenizer_max_length(77, from CLIP) ortokenizer.model_max_length(512) was used to slice the untruncated T5 token IDs even when truncation occurred atmax_sequence_length, causing the warning to log the wrong tail (often['']) instead of the discarded T5 tokens.Fixes #15495
Tests & Verification
test_t5_prompt_truncation_warningintests/pipelines/flux/test_pipeline_flux.py(TestFluxPipeline) andtests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3.py(TestStableDiffusion3Pipeline, also coveringdiffusers.modular_pipelines.stable_diffusion_3.encoders._get_t5_prompt_embeds).python utils/check_copies.py:All checks passed!ruff checkandruff format --checkon all 24 touched files: passed (24 files already formatted).pytestoffline CPU run onTestFluxPipelineandTestStableDiffusion3Pipeline(test_t5_prompt_truncation_warning): passed (2 passed). Prior to the 1-line formatting adjustment intest_pipeline_stable_diffusion_3.py, the non-slow FLUX + SD3 pipeline suites ran with126 passed, 44 skipped(accelerator/memory/slow skipped,test_sd3_loradeselected offline).Self-review notes
.ai/references/review-rules.md,code_style.md,pipelines.md, andtesting.md.# Copied fromfiles were propagated withcheck_copies.py --fix_and_overwrite, andpipeline_flux_controlnet.py(which does not use# Copied fromon_get_t5_prompt_embeds) was updated alongside them. Audited remainingself.tokenizer_max_length - 1occurrences insrc/: all remaining hits are in CLIP prompt encoders (tokenizer/self.tokenizer), andmodular_pipelines/flux/encoders.pyalready usesmax_sequence_length - 1 : -1.Before submitting
self-reviewskill on the diff?Who can review?
@yiyixuxu @sayakpaul