Skip to content

Studio: split guided Z-Image on the background-compile recording render - #15057

Merged
danielhanchen merged 3 commits into
mainfrom
studio-zimage-bg-compile-split-shape
Oct 24, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-zimage-bg-compile-split-shape

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Since #14868, a guided Z-Image render that records inputs for a pending background compile runs the guided call batched at 2B. The background compile then builds a 2B graph. Every later compiled render splits guidance into two batch-B calls, finds no B graph, and compiles every block inline. That is the compile background compile exists to hide. #14955 inherits the same rule through _eager_now.

This PR makes the recording render split, the same way the compiled renders will, so the recorder stores B inputs and the background compile builds the graph that later renders replay.

Details

  • diffusion_bg_compile.recording(module) is a new helper. It is True only when the call is eager-forced, not under no_record(), and a BackgroundCompile hooked on that module is still recording with room for more samples (BackgroundCompile.wants_samples()).
  • _eager_now in diffusion_zimage_cfg_split.py no longer treats such a render as eager, so the render splits. guided_runs_at_guidance_off_batch reads the same function, so the request guard prices the recording render at the guidance-off batch, matching how it now runs.
  • Unchanged:
  • Pixels: the recording render now produces the split output, which is what it produced before Studio: split Z-Image guided steps only while the denoiser is compiled or replaying graphs #14868. Each half is bit-equal to running that branch alone, and it matches the batched call within the existing split-vs-batched tolerance (atol=1e-5, rtol=1e-4).

New dynamo graphs in the first compiled guided render after the background replay. The setup is the real diffusers ZImageTransformer2DModel with a tiny config, Studio's per-block torch.compile(dynamic=True), the real BackgroundCompile recorder and the _rebuild replay:

tree samples recorded new graphs in the next compiled render
main 1 x batch-2 (two latents, t of shape (2,)) 3 (every block kind recompiles)
this PR 2 x batch-1 (16, 1, 8, 8) 0

Tests

  • New test_background_compile_recording_render_splits_and_records_the_compiled_shape. It records under a real BackgroundCompile, replays like kick(), then runs a compiled guided render and asserts:

    • 0 new graphs;
    • B-shaped samples;
    • guidance-off pricing;
    • outputs within tolerance of the batched call.

    It fails on main (assert (6 - 3) == 0) and passes here.

  • test_compiled_only_honours_the_background_compile_eager_gate now asserts the corrected rule: eager-forced with nothing recording (no recorder, or one already compiling) stays batched and records nothing, and a compiled render splits.

  • studio/backend, python -m pytest -q -p no:cacheprovider:

    test file result
    tests/test_diffusion_zimage_cfg_split.py 36 passed
    tests/test_diffusion_cold_start.py 39 passed
    tests/test_diffusion_regional_compile.py 17 passed
    tests/test_diffusion_block_graph.py 40 passed, 18 skipped
    tests/test_diffusion_speed.py 223 passed
    tests/test_diffusion_vae_oom.py 114 passed, 2 skipped
    tests/test_diffusion_gguf_compile.py 1 skipped
  • Not measured: the wall-clock seconds saved on a real Z-Image checkpoint on GPU, and the batching speed the one recording render gives up.

The eager render that records inputs for a pending background compile ran the
guided call batched (2B), so the background compile built a 2B graph that no
compiled render replays. Compiled renders split guidance into two B calls and
compiled every block inline on the first render after the background compile.

The recording render now splits like the compiled renders will, so the recorder
stores B inputs. Other eager renders, including ones under the eager gate while
the compile already runs, keep the batched call.
@danielhanchen danielhanchen self-assigned this Oct 24, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-10-24T01:30:41.217669Z 86d25d7 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: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 86d25d7c8a

ℹ️ 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 c785486 into main Oct 24, 2026
42 checks passed
@danielhanchen
danielhanchen deleted the studio-zimage-bg-compile-split-shape branch October 24, 2026 03:40
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