Repository navigation
Studio: ship built-in float specialisations so a fresh install's first compiled render traces once - #16939
Merged
Conversation
…first compile traces once
…d them on CUDA, keep them in the seed file
Codex Review Summary: ✅ CompletedThis 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. |
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
Member
Author
|
@codex review |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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
#16917 pre-seeds the Dynamo float specialisation names (norm
eps, dropoutp, ...) that an image load's first compiled render learned, so a returning start traces each block type once. A first-ever start has no saved file yet, so it still paid the full restart: the default tier compiles the repeated blocks withdynamic=True, the first attempt fails on the float values (TensorifyScalarRestartAnalysis) and Dynamo traces every block type again.This PR ships those names per known denoiser, so a fresh install starts from the same seeds a returning user already has:
_FLOAT_SEED_DEFAULTSindiffusion_bg_compile.py: the names a real first compile learns, for FLUX.2-klein 4B / 9B (and base), FLUX.2-dev, FLUX.1-dev / schnell / Krea / Kontext, Qwen-Image / 2512, Z-Image / Turbo, Wan2.1-T2V-1.3B, Wan2.2-T2V-A14B and Wan2.2-TI2V-5B._default_float_seed_key: torch minor, diffusers version, the transformer config less its layer counts, and per repeated block class every submodule class, the source of every forward and attention processor it runs, and the module-level helpers they call by name. A Studio load patch (arch fusions, fused RoPE, int8 swaps), a LoRA, another diffusers or torch version or any other config moves the key, so nothing is seeded and the compile restarts exactly as on main.UNSLOTH_DIFFUSION_BG_COMPILE_FLOAT_SEEDS=0(all seeding), andUNSLOTH_DIFFUSION_FLOAT_SEED_DEFAULTS=0(only the built-in names).How the table was recorded: one layer of each model (real config, random weights) on an A100 through this backend's own load patches and
_compile_repeated_blocks, under the Studio install (torch 2.13.0+cu130, diffusers 0.42.1). Dynamo numbers a SymFloat from a hash of its source name (ShapeEnv._generate_unique_id), not from tensor sizes, so the names do not depend on the layer count or resolution (checked: 64 vs 256 tokens, real vs shrunk widths give the same names). For the two families timed below, the recorded names equal what a real fresh start wrote to its seed file.Results
Colab A100-SXM4-40GB, one VM per run, Studio installed with
install.sh --local(python 3.13.16, torch 2.13.0+cu130, diffusers 0.42.1). Base =06d5015f28(main), head = base + this change. 1024x1024, 3 prompts after the first render, 3 reps with base and head interleaved (B H, H B, B H). Fresh = new process, empty Studio home and inductor / Triton caches; returning = later processes on that home.FLUX.2-klein-4B, this PR's code (the later commits only touch tests and comments):
Z-Image-Turbo, an earlier revision with the same table and key (it differed only in not yet writing the built-in names to the seed file, so its returning runs seeded from the table again rather than the file; the +0.37 s median there is inside both arms' 0.50 / 0.56 s spread):
_compile.compile_inneron a fresh klein start: base 10.24 + 5.07 s with acompile_attempt_1per block type, head 7.01 + 3.48 s with none. The head logsdiffusion.float_seeds: 11 built-in float specialisation(s) pre-seeded for the Flux2Transformer2DModel compile(7 forZImageTransformer2DModel); its returning runs then read the same 11 names from the seed file, like base.Same images, same graphs
head_inbase) hits both AOTAutograd entries the unseeded base compile wrote, 0 misses, so the seeded first trace produces the same graphs as main's restarted one.fullgraph=True). Recompiles: 0 for klein; 1 for Z-Image on both arms alike (a pre-existing guard onadaln_inputbeingNone).Tests
tests/test_diffusion_float_seed_defaults.py(new, CPU,aot_eager): a fresh compile with a matching key traces once into the same output as main's restarted compile and writes the names to the seed file; the next load reads them from the file; saved names win over the table; both kill switches keep the restart; a name no float carries is never consulted and a missing one is still learned by the restart, output unchanged; the key ignores layer counts but moves with the config, a swapped submodule, an instance forward, a class forward patch, a swapped helper function, and is absent for a LoRA-adapted or config-less module; the table is well formed.test_diffusion_inline_float_seeds.py,test_video_float_seeds.py,test_diffusion_bg_compile_float_seeds.py,test_diffusion_backend.py,test_video_backend.py: 1249 passed, 1 skipped (torch 2.12.1). The four seed test files also pass on torch 2.10.0, 2.13.0 and 2.14.1.Not proven
expand_timestepsflag sets); the video backend's own first-clip path was not timed.