Repository navigation
Studio static step skip: SDXL U-Net, max tier every 2 at 25 steps - #18826
Conversation
install_static_step_skip and the layer lookup took only pipe.transformer, so the one U-Net family (SDXL, pipe.unet) never got the static skip. They now use the transformer, else pipe.unet. The layer wraps the whole U-Net output; SDXL batches CFG into one call per step, which the per-step counter already handles. SDXL base gets a max-tier auto row: every 2 at 25 steps (Studio's default). On a T4 (fp16, 1024x1024, CFG 7, 8 prompts) mean LPIPS against the full 25-step render is 0.059 at 1.49x; every 3 measured 0.115 (over the max bar), DeepCache interval 2 0.248 at 1.74x, and 13 plain steps 0.303. Fewer than 25 steps and sdxl-turbo compute every step.
…et compile unet.compile() traces the forward slot, so dynamo guarded on the skip layer's step counters and recompiled every step until the recompile limit, which doubled the SDXL first render and broke CUDA graph capture. The schedule frames now run outside dynamo; the wrapped forward is still traced as one graph. Adds a CPU test (one graph, no recompiles, outputs match eager).
A whole-module compiled U-Net is served from _compiled_call_impl, which reads forward (the skip layer) inside the compiled region. The CUDA graph captured around that call baked one computed step in and replayed it on every step, so the schedule never ran once capture succeeded. GraphedCompiledCall now puts the skip in front of the call: the layer decides first and computes through the graphed call, whose own read of forward passes through. Both uninstall orders restore the slots, and bg-compile's capture check sees the fronted graph.
|
@codex review |
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. |
Codex Review Summary: 🔄 RunningThis 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". |
…graph, and keep detailer passes eager Two gaps in the SDXL skip on a whole-module compiled U-Net: - Only the CUDA graph install put the layer in front of the compiled call. With graphs off (env, ROCm) the max tier still compiles the U-Net whole with fullgraph=True, the layer stays in the forward slot inside that trace, and on torch 2.13+ its dynamo-disabled frames leave no compiled frame, so the first render raises. The layer now goes in front right after the whole-module compile and at install on an already compiled module; GraphedCompiledCall graphs the call such a layer fronts. - A detailer pass gates the compiled U-Net to eager, but the fronted layer routed every computed step back into the compiled (graphed) call, recompiling at each crop size. Under force_eager it now computes eagerly. [skip ci]
|
@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". |
…ntion plan keys, CUTLASS live race key, step-skip sample= shape (#18981) Four small fixes from a recheck of the merged FLUX.1 ConvRot GELU (#18766), INT8 attention sink fold (#18786), CUTLASS race key (#18797) and SDXL static step skip (#18826) changes. Each one is its own commit with a test that fails before it and passes after. ## Changes 1. **FLUX.1 ConvRot GELU gate traces on torch 2.10 / 2.11** (`diffusion_convrot_quant.py`). `convrot_gelu_act_quant` chose its row threshold with `rows[prefix is None]`. Dynamo on torch 2.10 and 2.11 cannot trace a tuple indexed by a bool. With `fullgraph=True` the compile raises `Unsupported`; without it, every armed FF / single-block down projection graph-breaks. torch 2.6 and 2.12+ accept it. The index is now `1 if prefix is None else 0`, which selects the same entry. 2. **INT8 attention launch plans follow the kernel switches** (`diffusion_int8_attention.py`). `_plan` reads `UNSLOTH_DIFFUSION_INT8_ATTENTION_RESID_FOLD`, and `kernel_variant` reads the sink order and native P switches, when a plan picks its kernels. The warm lookup in `_find_plan` did not key on them. Flipping the fold off in a running process therefore left warm shapes on the folded kernel until `forget_plans`. The plan key now includes the three switches as set. That costs three env reads, about 1.7 us of host time per call, and nothing under CUDA graph replay. 3. **CUTLASS race key covers the live row race** (`diffusion_int8_gemm.py`). `_live_row_race` decides which calls race and applies the `force` pick. It also writes its winner into the same disk entry that `_cutlass_plan` reads back on the next load. Neither it nor `live_race_enabled` was in `_RACE_SOURCES`, so an edit confined to the live race kept old verdicts. Both are keyed now. This applies cleanly on top of the open race-key closure change, whose closure test still passes with both applied. 4. **Step skip reads `sample=`** (`diffusion_step_skip.py`). The reuse key took the latent from `hidden_states` or the first positional argument. A `UNet2DConditionModel` called with `sample=` was therefore keyed with shape `None`, and a skipped step after a latent shape change returned the previous output at the old size. The stock SDXL pipeline passes the latent positionally, so Studio's own renders were not affected. ## Tests (CPU, base = parent commit, head = this branch) | Test | Base | Head | |---|---|---| | `test_diffusion_convrot_gelu_route_trace.py` on torch 2.10.0 / 2.11.0 | 2 failed, 1 passed | 3 passed | | same on torch 2.6.0 / 2.12.1 / 2.13.0 / 2.14.1 | n/a | 3 passed | | `test_diffusion_int8_attention_resid_fold.py::test_a_warm_plan_follows_the_kill_switch` | failed (warm plan reused) | passed | | `test_diffusion_int8_cutlass_race_key.py` (3 new live race cases) | 3 failed, 27 passed | 30 passed | | `test_diffusion_step_skip_unet.py::test_a_skipped_step_never_returns_another_latent_shape[True]` | failed (width 8 for a width 12 latent) | passed | The surrounding INT8 attention, CUTLASS, GEMM, step skip and FLUX.1 GELU suites have the same results on both arms. 8 FLUX.1 GELU tests fail on both base and head when they run in the same process after the step skip and INT8 suites, and they pass when that file runs alone. That failure predates this change. ## Not covered here - No GPU run. The four changes are host-side keys and gates, and each one is checked on CPU against the real module code. - The `+1.7 us` host cost per INT8 attention call was measured on CPU, not as end-to-end render time.
SDXL is the one U-Net family in Studio, and it never got the static step skip:
install_static_step_skipand the layer lookup only looked atpipe.transformer, so a pipeline withpipe.unetwas declined ("pipeline has no transformer"). This lets the layer sit onpipe.unetwhen there is no transformer, and gives SDXL base a max-tier auto row: every 2 at 25 steps, Studio's default for SDXL.Change
diffusion_step_skip.py: a small_denoiser(pipe)helper returnspipe.transformer, elsepipe.unet. Both install and lookup use it, so a transformer still wins when a pipeline has both. The layer wraps the whole U-Net output (taylor1 fill). SDXL batches CFG into one U-Net call per step, which the per-step counter already handles.diffusion_families.py:auto_static_skip = (("stabilityai/stable-diffusion-xl-base-1.0", (("max", 2), ("steps", 25))),)on the SDXL profile. Only the max tier skips automatically, as for every other family, and fewer than 25 steps compute every step. sdxl-turbo (1 step) has no row.unet.compile()), and that compiled call readsforward, which is where the layer sits. Two fixes keep the compiled path intact:torch.compiler.disable, so dynamo traces only the wrapped forward. Without this, dynamo guarded on the step counter and recompiled every step until the recompile limit.GraphedCompiledCall(the CUDA graph at_compiled_call_impl) now puts the layer in front of the graphed call. Without this, the graph captured one computed step and replayed it on every step, so the schedule never ran after capture. A skipped step now never enters the call, a computed one replays the graph, and both uninstall orders restore the slots.Numbers
T4, fp16, 1024x1024, 25 steps, CFG 7. LPIPS (AlexNet) is measured against the same process's full 25-step render. Wall time includes the VAE.
Harness (diffusers pipeline, eager), 8 prompts:
At about 1.75x the same layer is 2.2x closer to the full render than DeepCache, and it is far closer than simply running fewer steps.
Studio's own load path (
DiffusionBackend.begin_load,speed_mode="max"), Colab T4:transformer_cache: staticwithcompiledandcuda_graph, and the layer sat on the U-Net (every 2, auto). Every skipped render computed 16 of 25 U-Net calls. On 4 prompts LPIPS was 0.032 / 0.164 / 0.052 / 0.087 (mean 0.084). Warm wall time was about 23 s for the full render and 14.6 to 16.2 s skipped (1.49 to 1.58x). A full render repeated in the same process gives 0.0066 here, because the compiled T4 path is not bit-exact.memory_mode="low_vram"(model offload, which diffusers detaches and re-attaches around every call): the layer stayed in the call path across generations. Two skipped renders, one before and one after a full render, both computed 16 of 25 calls with identical output (LPIPS 0.027 vs the full render, A/A 0.000), at 18.0 and 16.4 s against 30.8 s.Tests
tests/test_diffusion_step_skip_unet.py(new, CPU):pipe.unet, and a transformer still wins over a U-Net;tests/test_diffusion_step_skip_unet.pyalso covers the compiled path: undermodule.compile(backend="eager")there is one graph, no recompiles, and output matches eager; with the layer in front of a compiled call, 16 of 25 calls enter it.tests/test_diffusion_cuda_graph.pychecks that the layer frontsGraphedCompiledCalland that both uninstall orders restore it. Both fail without the fixes.test_diffusion_step_skip_defaults.pylists SDXL as measured, and the family-data freeze fixture is refreshed (only the SDXLauto_static_skipentry changes).Static skip suites (unet, static_skip, step_skip_defaults, video_static_skip, family_data_freeze): 172 passed. test_differential: 6 tests fail on main and pass here, and none fail here. Broader diffusion suites (backend, cuda_graph, autoopt core and parity, cold_start, auto_placement, bg_compile_idle): 996 passed, 4 skipped, and 1 failed. That failure,
test_mirrored_base_still_trips_the_flux2_shape_guard, fails the same way on main.Not proven here
Cold start was measured on Studio's default compiled path (SDXL base, 25 steps, max tier), in a fresh process per arm:
The main and before-the-fixes rows ran on the same T4 VM. The before-the-fixes row is the extra warm-up these two fixes remove. The final branch was measured on two L4 VMs: one full 25-step render took 8.7 s, the skipped render 5.65 s (1.54x), and LPIPS against the full render was 0.103 on that prompt. The two prompts' outputs differ (LPIPS 0.86), so no stale graph was replayed. The final branch was not measured beside main on the same T4, so whether its first render matches main's 476 s there is not proven. On L4 its first render is one compile plus capture, and there are no capture warnings.
Only 4 prompts through Studio's path (8 in the harness), T4 only, no LoRA, no img2img. Auto skip stays txt2img-only, as for every family.
No AMD, Mac or Windows run. The change is OS-neutral.