Repository navigation
Studio diffusion: faster returning first render and first clip (reuse tuned reductions, warm video compile keys) - #16981
Merged
Conversation
…a returning start Inductor's compile workers start with torch's default cache_key_tag, while the Studio process carries Unsloth's kernel tags, so a kernel tuned in a worker saved its best config under one key and every later process looked it up under another. A returning start re-benchmarked every multi-config reduction (SDXL on L4: about 40 kernels, 9.5 s of a 22 s first render). The parent now keys autotune lookups as the workers do; UNSLOTH_DIFFUSION_AUTOTUNE_KEY_PIN=0 turns it off.
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. |
…its tag to the compile workers [skip ci]
… key when an earlier test pinned it
Member
Author
|
@codex review |
…o load finishes The image path has done this since the first render started compiling inline; the video path never did, so a returning LTX-2.5 first clip hashed the Triton install (1.5 s on an L4) on the render thread. Same kill switch: UNSLOTH_DIFFUSION_DEFERRED_PREWARM=0.
Member
Author
|
@codex review |
Member
Author
|
@codex review |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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
Two one-time costs that every Studio restart paid again in its first compiled render or clip:
1. Autotune results keyed as the compile workers key them
.best_configfile whose name hashes the kernel file name andtorch.compiler.config.cache_key_tag.TORCH_COMPILE_CACHE_KEY_TAGenv var, else empty). The Studio process carries the tags Unsloth adds to that key (on these runs, Unsloth Zoo'sunsloth/inductor-rand4x-off, logged by the new info line).diffusion_aot_cache.pin_autotune_keyreplacesAutotuneCache._prepare_keywith the same formula under the workers' tag:_prepare_keyproduces anything else, or a future torch hands its tag to the workers, nothing is patched._compile_repeated_blocks(SDPA AOT cache, libdevice pin) and when a compile-cache context begins, so the VAE and GGUF dequant compiles are covered too.UNSLOTH_DIFFUSION_AUTOTUNE_KEY_PIN=0.2. Compiled video loads warm the workers and keys
A compiled CUDA video load now starts the same side warm-up the image path uses (inductor's compile workers, Triton's
triton_key(), inductor'storch_key()), once per process, so it runs while the rest of the load finishes. The 3rd-image engagement imports are not part of it. Same kill switch as the image path:UNSLOTH_DIFFUSION_DEFERRED_PREWARM=0.Results
Colab L4, torch 2.13.0+cu130, triton 3.7.1, diffusers 0.42.1, Studio installed with
install.sh --local, base and head interleaved on one VM per table. Fresh = new process with an empty Studio home and empty inductor / Triton caches; returning = a later process on that home.SDXL base 1.0, 1024x1024, 20 steps, CFG 5, compiled inside the first render (change 1)
Base =
42489f20e2, head = base + change 1, 3 reps (B H, H B, B H).Returning first render: median 21.90 s to 12.58 s (-9.3 s, -43%), outside the A/A spread of both arms (0.51 s base, 0.19 s head). A head process started on a base home (the caches an existing install already has) ran 1 benchmark and rendered its first image in 13.0 s.
That run measured the first revision of change 1 (same keys, computed through
cache_key_tag). The final code was re-checked on a second L4 VM against93e09c8e5a, 2 reps: returning first render 22.15 / 22.24 s base vs 12.91 / 12.64 s head, 39 vs 0 benchmarks, head on a base home 13.06 s with 1 benchmark, same image hashes as the first run.LTX-2.5, tiny random weights (real block structure), 768x512, 49 frames, 8 steps (both changes)
Base =
93e09c8e5a, head = this branch, 3 reps interleaved. The video path's compiling thread carries no tag, so change 1 does nothing here (its returning clip already ran 0 benchmarks); the gain is change 2.Warm first clip: median 10.47 s to 8.94 s (-1.53 s, -15%), outside both arms' spread (0.23 s base, 0.55 s head). The head log shows
triton key ready in 1.38 sduring the load.Same images
Tests
tests/test_diffusion_autotune_key_pin.py(new, CPU): with a tagged Studio process the key differs from a fresh worker interpreter's (the bug) and matches once pinned; the process's owncache_key_tagis unchanged; an untagged process keeps its key;TORCH_COMPILE_CACHE_KEY_TAGis honoured as the workers honour it; idempotent; kill switch; a torch without_prepare_key, with another key formula, or one that hands its tag to the workers is left alone; both entry points call it.tests/test_video_compile_prewarm.py(new, CPU): the warm-up runs the pool, Triton key and inductor key on its own thread, once per process, past a failing step; kill switch; the video load starts it only for a compiled CUDA load.Not proven