Skip to content

Studio static step skip: SDXL U-Net, max tier every 2 at 25 steps - #18826

Merged
danielhanchen merged 4 commits into
mainfrom
studio-step-skip-sdxl
Nov 22, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-step-skip-sdxl

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

SDXL is the one U-Net family in Studio, and it never got the static step skip: install_static_step_skip and the layer lookup only looked at pipe.transformer, so a pipeline with pipe.unet was declined ("pipeline has no transformer"). This lets the layer sit on pipe.unet when 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 returns pipe.transformer, else pipe.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.
  • Studio compiles the SDXL U-Net whole (unet.compile()), and that compiled call reads forward, which is where the layer sits. Two fixes keep the compiled path intact:
    • The layer's bookkeeping frames are wrapped in 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:

arm mean LPIPS speedup
static skip every 2 (this row) 0.059 1.49x
static skip every 3 0.115 1.77x
DeepCache, interval 2 0.248 1.74x
16 / 13 plain steps 0.266 / 0.303 1.48 / 1.77x

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:

  • Memory auto: the load reported transformer_cache: static with compiled and cuda_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):

  • the layer installs on and uninstalls from pipe.unet, and a transformer still wins over a U-Net;
  • the SDXL row plans every 2 at 25 steps on max only, and turbo or fewer steps compute every step;
  • a fake U-Net run computes 16 of 25 calls;
  • the layer stays in the call path through accelerate hook add / remove cycles, the way diffusers' model offload re-attaches them.

tests/test_diffusion_step_skip_unet.py also covers the compiled path: under module.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.py checks that the layer fronts GraphedCompiledCall and that both uninstall orders restore it. Both fail without the fixes.

test_diffusion_step_skip_defaults.py lists SDXL as measured, and the family-data freeze fixture is refreshed (only the SDXL auto_static_skip entry 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:

    run GPU load first render second render capture warnings calls computed
    main T4 86 s 476 s 24.3 s none 25 of 25
    before the fixes T4 31 s 1142 s 80.7 s JIT in capture, capture failed, empty graph 16 of 25
    this PR L4 91 / 104 s 523 / 529 s 6.0 / 5.8 s none 16 of 25

    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.

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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T03:19:53.380073Z d3bd394 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.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: 🔄 Running

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

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-11-22T02:18:54.141065Z a464def PR opened
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a464deff93

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

…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]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: d3bd3948ae

ℹ️ 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 66bc7d5 into main Nov 22, 2026
@danielhanchen
danielhanchen deleted the studio-step-skip-sdxl branch November 22, 2026 05:37
danielhanchen added a commit that referenced this pull request Nov 23, 2026
…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.
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