Skip to content

Studio: warm the compile workers and Triton / inductor keys during a load that compiles inline - #16918

Merged
danielhanchen merged 1 commit into
mainfrom
studio-inline-compile-prewarm
Nov 6, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-inline-compile-prewarm

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

A load that compiles at its first render (the default speed tier when it is not deferred) paid three one-time, model-free costs inside that render: starting inductor's compile workers, Triton's triton_key() (a hash of the Triton install) and inductor's torch_key() (a hash of torch's sources). The deferred tier already warms the first two on a side thread from the 2nd image (start_deferred_prewarm), and the first render of an inline load gets none of that.

This PR:

  • starts the same side warm-up from load_pipeline as soon as the compile-cache context begins on a CUDA target, so it runs while the rest of the load (speed layer, CUDA graph setup, placement) finishes;
  • adds inductor's torch_key() to the warm-up (warm_inductor_key). It is cached per process, so the first compile reads it instead of hashing torch's sources;
  • reuses the existing thread, once per process, joined by the deferred engagement as before. Kill switch: the existing UNSLOTH_DIFFUSION_DEFERRED_PREWARM=0 (warms the pool inline only).

Nothing about the compile itself changes: same knobs, same graphs, same cache keys.

Results

Colab G4 (RTX PRO 6000 Blackwell), one VM, torch 2.13.0+cu130, diffusers 0.42.1, Studio from install.sh --local. FLUX.2-klein-4B, 1024x1024, 4 steps. Base = ccc8a827d2, head = base + this change, 3 reps interleaved (B H, H B, B H). Fresh = new process with empty Studio home and inductor / Triton caches; returning = a second and third process on that home.

base head
first render, returning (6 processes each) 5.17 / 5.18 / 5.19 / 5.19 / 5.21 / 5.21 s 4.85 / 4.86 / 4.86 / 4.87 / 4.88 / 4.88 s
first render, fresh home 9.97 / 10.04 / 10.45 s 9.65 / 9.66 / 9.69 s
load, returning (median) 6.58 s (6.14-6.64) 6.65 s (6.63-6.69)
load, fresh 7.28 / 7.32 / 7.36 s 7.29 / 7.32 / 8.12 s
steady renders 0.452-0.478 s 0.451-0.477 s
process wall, returning 16.80-17.25 s 16.89-17.00 s

Returning first render: -0.32 s (-6%), outside the A/A spread of both arms (0.04 s base, 0.03 s head). The warm-up overlapping the load costs about +0.07 s of load time (median), so load-to-first-image drops by about 0.25 s on a returning start (process wall 17.19 to 16.97 s median). Fresh first render: -0.3 to -0.8 s. Steady renders are unchanged.

Tests

tests/test_diffusion_deferred_prewarm.py: the warm-up order now includes the inductor key, warm_inductor_key fills the key and never raises, and load_pipeline starts the warm-up after compile_cache.begin (AST check, like the existing 2nd-image check). 19 passed.

Not proven

  • Only one card and model was timed (FLUX.2-klein-4B, G4). On slower host CPUs the Triton key hash was measured at 1.3 s inside a returning first render (L4 py-spy profile), so the saving there is likely larger, but that was not A/B timed.
  • On a host with fewer cores the warm-up could cost the load more than the +0.07 s seen here.
  • ROCm, Windows and macOS were not run. The kick is gated on a CUDA target, the same gate the deferred path uses.

…load that compiles inline

A load that compiles at its first render (default tier, not deferred) paid Triton's triton_key()
hash, inductor's torch_key() hash and the compile worker start inside that render. The deferred
tier already warms these on a side thread from the 2nd image; a load whose compile cache context
begins now starts the same side warm-up while the rest of the load runs.
@danielhanchen danielhanchen self-assigned this Nov 6, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T14:17:33.332004Z eacb857 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: eacb8574cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen
danielhanchen merged commit 1624f01 into main Nov 6, 2026
@danielhanchen
danielhanchen deleted the studio-inline-compile-prewarm branch November 6, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant