Repository navigation
Studio: compile the SDXL U-Net per block so the 4th image no longer waits for the whole compile - #16085
Merged
Conversation
…ackground compile The deferred profile compiled UNet2DConditionModel as one module (118-154 s, CPU bound) and the 4th render waited for all of it. The default tier now compiles the U-Net's repeated blocks (BasicTransformerBlock, ResnetBlock2D, Downsample2D, Upsample2D) behind the regional compile guard, and a render that finds that background compile in flight lets it run one slice (about one eager render), then parks it at the next block boundary and runs eager; the compile resumes after the render. UNSLOTH_DIFFUSION_UNET_REGIONAL=0 restores the whole-module compile, UNSLOTH_DIFFUSION_BG_COMPILE_YIELD=0 the wait, UNSLOTH_DIFFUSION_BG_COMPILE_SLICE_S sets the slice.
…e slice ends A render waited its slice plus the block graph in flight (A100: 4.4-7.4 s against a 2.8 s eager render). The compile now times its block graphs and the render asks for the pause that much earlier, so the wait stays about one slice; a released compile owes one graph before it parks again, so back-to-back renders cannot starve it.
…he deferred compile Until the worker pool is ready inductor compiles kernels in-process, so the first block graph of the background compile took 7.2 s against 0.8-3.6 s for the rest. AsyncCompile.warm_pool + wakeup on the 2nd image starts the workers in the background. UNSLOTH_DIFFUSION_BG_COMPILE_WARM_POOL=0 disables.
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. |
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 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 was referenced Oct 30, 2026
danielhanchen
added a commit
that referenced
this pull request
Oct 30, 2026
…#16088) `Repo tests (CPU, rest-2)` is red on main since #16062 (MXFP4 torch decode fallback: run ldexp on the operands' GPU). It fails on unrelated PRs such as #16085 and #16074: ``` tests/test_mxfp4_compressed_linear.py::test_torch_fallback_runs_ldexp_on_the_operands_gpu[dtype0..2] unsloth/models/mxfp4_compressed_linear.py:99: in _dequantize_torch_impl out[..., 0::2] = lut[(blocks & 0x0F).long()] RuntimeError: PyTorch is not linked with support for cuda devices ``` The test builds its operands on `cuda:1` inside `FakeTensorMode`. That works on any CUDA-linked torch, with or without a GPU, but a CPU-only build cannot dispatch a fake CUDA tensor. The CPU shards install CPU-only torch. I checked the same few lines on both builds: `2.13.0+cu130` with no visible GPU runs them, and `2.10.0+cpu` raises the error above. The product's device guard is fine; the test assumed a CUDA build. ## Changes - `test_torch_fallback_runs_ldexp_on_the_operands_gpu` now skips when `torch.backends.cuda.is_built()` is false. It still runs on CUDA builds, GPU or not. - New `test_the_torch_decode_runs_inside_its_operands_device_guard` runs on any build, so the CPU shards keep covering the guard. It checks three things: `_dequantize_torch` decodes with the operand's device current, puts the previous device back, and leaves the current device alone for a CPU operand or an index-less `cuda` operand. - The fake `torch.cuda.device` guard is shared by both tests. ## Verification - CPU-only torch 2.10: the file has 20 passed and 38 skipped, and the fake-tensor test skips with the reason above. On main it had 3 failures. - CUDA torch 2.13 with no visible GPU: the three fake-tensor cases and the new test pass (4 passed). - Sabotage: dropping `_operand_device_guard` from `_dequantize_torch` fails the new test on CPU-only torch.
danielhanchen
added a commit
that referenced
this pull request
Oct 30, 2026
#16069 (fill locale gaps and translate the sign-in, consent and Desktop startup screens) moved the update banners onto `t()`. Two checks that pinned the old English literals went red on main. They fail on unrelated PRs, for example #16085: ``` Repo tests (CPU, studio) test_update_release_notes.py::test_banners_toggle_inline_release_notes[banner1] test_update_release_notes.py::test_notes_toggle_shares_the_action_row[banner1-tauri-update-release-notes-toggle-Remind me later] test_desktop_reliability_frontend_contract.py::test_collapsed_tauri_keeps_history_arrows_and_adds_new_chat_by_model_picker Chat UI Tests [banner] FAIL 1440x900: three pending runtimes share the one card summary='llama.cpp, whisper.cpp, and audio.cpp · No restart needed' (same at all 6 viewports) ``` In both cases the product is right and the tests read the old text. ## Release notes toggle contract The Tauri banner now renders `t("desktopUpdate.banner.showNotes")`, `hideNotes` and `remindLater`. Their English, "Show release notes", "Hide release notes" and "Remind me later", is unchanged. A new `_shown_at(src, label)` helper finds a label either as literal text, which is how the web banner still renders it, or as a `t("key")` call whose `en.ts` value is that label. It uses the shared `tests/studio/_en_catalog.py` reader. The ordering check (toggle before the action, in the same row) uses the position of whichever form is present. A unit test pins the helper: literal, through the catalog, and a key whose English differs. ## Titlebar history arrows The titlebar's back and forward buttons now carry `aria-label={t("desktopShell.goBack")}` and `goForward`, and their English is still "Go back" and "Go forward". `_aria_label_count` counts a label written literally or through a `t()` key whose English matches, and a unit test pins it. ## Runtime card summary The card now joins runtime names with `Intl.ListFormat(locale, { type: "conjunction" })`, which is correct for every locale and gives English a serial comma. `playwright_update_banner_layout.py` now matches `llama\.cpp, whisper\.cpp,? and audio\.cpp`. The names must still appear in that order and joined as one list. ## Verification - `tests/studio/test_update_release_notes.py`: 2 failed on main, 203 passed here. - `tests/studio/test_desktop_reliability_frontend_contract.py`: 1 failed on main, 45 passed here. Pointing the back button at `goForward` fails it. - Sabotage: rendering nothing for the Tauri notes toggle fails `test_banners_toggle_inline_release_notes`. Switching the dismiss button from `remindLater` to `later` fails `test_notes_toggle_shares_the_action_row`. - The new matcher accepts the formatted summary and the old form. It rejects a missing or reordered runtime. - The tests that import the layout driver pass (218 passed with the release notes file). --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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 a fresh Studio home, SDXL's 4th image waited for the whole background compile of the U-Net: 119 to 126 s on
A100 and 140 to 142 s on L4. An eager render takes 2.8 s and 9.6 s. This PR compiles the U-Net per block and lets a
render pause that compile between blocks instead of waiting for all of it. With it, the 4th image takes 6.9 s on
A100 and 17.5 s on L4. Steady compiled speed and image quality match main.
Change
diffusion_speed._compile_unet_blocks,diffusion_autoopt/targets.py)UNet2DConditionModelcompiles eachBasicTransformerBlock,ResnetBlock2D,Downsample2DandUpsample2Dwith the same settings as before (fullgraph,dynamic=False, same inductorknobs). Before, it compiled the whole module.
reported. The outer forward stays eager inside the existing denoiser CUDA graph.
unet_graph=blocks. The dynamo recompile limit is 256 on this path.UNSLOTH_DIFFUSION_UNET_REGIONAL=0restores the whole-module compile.diffusion_bg_compile.BackgroundCompile.pause/resume/yield_point,diffusion._wait_or_pause_bg_compile)parks the compile thread at the next block boundary, renders eager, and resumes the compile afterwards. The park
point is in the compile guard, between two graphs, never inside a trace.
starve it.
UNSLOTH_DIFFUSION_BG_COMPILE_YIELD=0waits for the whole compile, as before.UNSLOTH_DIFFUSION_BG_COMPILE_SLICE_Soverrides the slice.diffusion_bg_compile.warm_compile_pool)AsyncCompile.warm_pool()andwakeup()start inductor's compile workers in the background on the 2nd image,once per process. Until those workers are ready, inductor compiles kernels in-process, so the first block graph
used to take 7.0 to 7.7 s instead of 4.2 to 4.4 s.
UNSLOTH_DIFFUSION_BG_COMPILE_WARM_POOL=0.Results
The setup for every table below:
back.
9a1ea09dc3. "Head before warm-up" is the branch without change 3.4th image (the first render after the deferred profile engages)
UNSLOTH_DIFFUSION_BG_COMPILE_YIELD=0UNSLOTH_DIFFUSION_UNET_REGIONAL=0speed_mode=off)How the head rows behave around the 4th image:
is 0.3 to 4.6 s.
is still 3 s faster: 32.3 to 32.5 s against 34.7 to 35.6 s, leaving out the first cell on the VM.
23 back-to-back renders, no think time (A100, same VM)
What the sums mean:
shape, and the whole module recompiles inline. Without that render, base sums to 172 to 174 s.
saving of 0.55 s per compiled render.
Steady state once compiled
..._YIELD=0)Recompiles: dynamo's unique graph count stays at 19 on every prompt after the compile completes. Base stays at 1
until the long prompt.
Accuracy
LPIPS on full-resolution images, A100, the 11 prompts that head rendered compiled in a 23-prompt run:
Over the first 7 prompts, head vs base is 0.023 to 0.035 on A100 and 0.025 to 0.034 on L4. Base vs base on those
prompts is 0.032 to 0.036 and 0.028 to 0.030. Images 1 and 2 are bit-identical in every arm.
Tests
studio/backend/tests/test_diffusion_unet_block_compile.pyadds 37 CPU tests:report, and the cache key
compile
failing test IDs before and after this change. Those failures are all outside this change.
Not proven
the same.
about 120 s for the whole module
unet_graph=blocksbundle