Repository navigation
Studio diffusion: arm FLUX.1 prompt-length dynamic shapes so int8 does not recompile on a long prompt or new size - #14689
Merged
Conversation
…or new size does not recompile An int8 / fp8 FLUX.1 (the default load) compiles with automatic dynamic, so the first prompt past 256 T5 tokens and the first new resolution each recompiled both repeated blocks. Add FluxTransformer2DModel to _FAMILY_SOURCES with the sources PROMPT_LENGTH_POLICY already lists, as FLUX.3 and Qwen-Image are.
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Summary
On the default speed tier FLUX.1 (schnell / dev / Krea-dev, and Kontext, which uses the same
FluxTransformer2DModel) recompiles both repeated blocks on follow-up prompts:The default load picks int8 for FLUX.1, and a torchao denoiser compiles with automatic dynamic (
compile_dynamicreturnsNone), so the first compile is static and the first new text length and the first new image size each pay a generalising recompile. #14387 classified FLUX.1's prompt-length inputs inPROMPT_LENGTH_POLICYbut left them out of_FAMILY_SOURCES("a new length there can still recompile. That is the dynamic-text compile change, not this PR"). This is that change for FLUX.1: its block inputs are armed from the first forward, as FLUX.3 and Qwen-Image already are.Measured (real weights, unsloth/FLUX.1-schnell, default settings, one process, B200, torch 2.13)
Follow-up sequence on the Images defaults (speed unset, memory auto, which resolves to int8 + regional compile + CUDA graphs):
Recompile reasons on main:
tensor 'image_rotary_emb[0]' size mismatch at index 0. expected 4352, actual 4608(text 256 to 512) andtensor 'hidden_states' size mismatch at index 1. expected 4096, actual 3840(new resolution).Images: the long-prompt, new-resolution and batch-2 renders are byte-identical to main's (main ran the same generalised graph after recompiling). The first render now runs that dynamic graph from the start instead of main's static first graph: against the speed-off bf16 render of the same seed, LPIPS-alex 0.054 here vs 0.035 on main (one image; main's own long-prompt render is 0.119 and its new-resolution render 0.082 against bf16, so this is inside the int8 default's spread). Renders whose prompt length matches the first one differ from main's by LPIPS 0.01-0.03 on simple scenes and up to 0.22 on a dense night-market scene, same composition (kernel numerics of the static vs dynamic graph).
The host was heavily loaded (load average above 1000), so the wall times above are what one user saw on that host, not a clean benchmark; the recompile and capture counts are the result.
Changes
diffusion_dynamic_text._FAMILY_SOURCES: addFluxTransformer2DModel: _FLUX1_SOURCES(the sources Studio diffusion: record a prompt length's CUDA graph on the first render only #14387 already defined). Only automatic-dynamic compiles arm them (installwithdynamic=None), so a bf16 FLUX.1 (dynamic=True) and a static compile are unchanged.test_flux1_new_prompt_length_and_resolution_reuse_the_first_graphs(a two-block FLUX.1 stand-in compiled with automatic dynamic: unarmed it compiles again on a new text length and on a new image length; armed, the first compile covers both). Fails on main (installarms nothing), passes here. The policy test now lists FLUX.1 among the armed classes.Testing
pytest tests/test_diffusion_dynamic_text.py tests/test_diffusion_prompt_length_policy.py: 33 passed (the new test fails on main).Not covered
dynamic=Trueand did not recompile in the same sequence; an int8 Z-Image (bf16 does not fit) was not run here.