Use dynamic FLUX T5 seq len (small speed / mem improvement) #7400
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.
Summary
This PR adds the option to dynamically select a T5 sequence length based on the length of the input prompt.
Using a smaller sequence length can improve inference speed and reduce peak memory, but will produce slightly different outputs.
Speed Improvement
Config: 1024x1024, bf16
T5 seq len = 512: 0.481 secs / it
T5 seq len = 128: 0.461 secs / it (4.1% speedup)
Memory improvement
Config: 1024x1024, bf16
T5 seq len = 512: 23355.16 MB peak VRAM
T5 seq len = 128: 23292.12 MB peak VRAM (63 MB saved)
Image difference
TODO: Add sample images showing the difference in output as T5 sequence len is varied.
Related Issues / Discussions
QA Instructions
Merge Plan
Checklist
What's New
copy (if doing a release after this PR)