Skip to content

Studio: stop the max speed tier recompiling on every new prompt length - #11731

Merged
danielhanchen merged 9 commits into
mainfrom
studio-max-auto-dynamic
Sep 24, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
studio-max-auto-dynamic

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Problem

The max speed tier compiles every DiT's regional blocks with dynamic=False. On a DiT whose blocks see the text tokens, the sequence length changes with every new prompt, so each new prompt length forces a fresh max-autotune compile. Qwen-Image-2.1 is such a model: its blocks run over prompt + image tokens. On it, max paid an extra 3 to 7 s on about half of all new prompts. That cost more than the tier's few-percent steady-state gain.

Fix

  • The max tier now compiles DiT blocks with automatic dynamic (dynamic=None). The first shape still compiles static and autotuned. When a dimension changes, dynamo generalises that dimension once, and later prompt lengths reuse the graph.
  • U-Net whole-module compile stays fully static, as before.
  • The compile-cache fingerprint keys max on dynamic: null, so the old static bundles are never reused for the new mode.
  • Two comments in video.py that described max as dynamic=False are reworded. The MiniMax-H3 demotion and the HunyuanVideo attention-trim hold-off are unchanged.

Measurements

Qwen-Image-2.1 bf16, 1024x1024, 25 steps, CFG 1, B200, 12 new prompts in a row after one warm-up. Other tenants loaded the GPU during parts of this run (utilisation 40 to 86 percent at the start of some arms), so absolute seconds are noisy. The recompile count is not affected by that.

Arm Renders slower than 1.6x the arm's fastest Total for 12 new prompts Fastest render
max, static (before) 6 / 12 41.0 s 1.61 s
max, automatic dynamic (after) 1 / 12 (the one generalising recompile, 10.4 s) 35.5 s 1.82 s
default tier 0 / 12 28.9 s 1.93 s
max, static, repeat at the end 5 / 12 61.6 s 2.58 s

The static arm's slow renders are 4.8 to 9.6 s; with automatic dynamic, every prompt after the second stays between 1.8 and 2.8 s. Steady-state medians on a repeated prompt were 2.82 s (static) and 2.71 s (automatic dynamic), within the noise of this run. A paired, alternated rerun follows.

Paired rerun (static and automatic dynamic alternated twice)

Same model and settings, 12 new prompts per arm after a warm-up, then 5 repeats of already-seen prompts for the steady state. The GPU was idle when the first arm started (utilisation 0%). Another tenant then loaded it (38% and 44% at the start of the next two arms, 89% at the last), so the second pair is heavily contended.

Arm GPU util at start New-prompt renders (s) Recompile spikes Total, 12 new prompts Repeated-prompt median
static 1 0% 1.75, 11.9, 14.6, 2.53, 22.1, 2.76, 14.9, 1.81, 2.30, 18.4, 1.77, 1.80 5 96.6 s 2.36 s
automatic 1 38% 2.30, 18.2, 1.87, 1.83, 2.01, 1.80, 2.92, 2.83, 2.80, 2.91, 2.82, 2.88 1 45.1 s 1.86 s
static 2 44% 5.49, 10.1, 13.4, 6.68, 10.5, 3.92, 8.98, 4.79, 4.67, 8.50, 3.26, 3.45 several 83.9 s 4.52 s
automatic 2 89% 6.72, 11.1, 3.51, 3.53, 5.77, 6.90, 6.89, 6.79, 5.36, 5.34, 6.21, 6.82 1 75.0 s 6.25 s
  • The static tier recompiled on 5 of 12 new prompts in the uncontended pair, at 11.9 to 22.1 s each. Automatic dynamic recompiled once (18.2 s, on the second prompt), and never again.
  • For 12 new prompts, the total went from 96.6 s to 45.1 s.
  • Steady state shows no measurable loss. The repeated-prompt median is 1.86 s (automatic) against 2.36 s (static), and the first repeat of each was 1.77 s against 1.83 s. The contention makes a smaller difference unresolvable.
  • speed_optims is identical in every arm (compiled, cuda_graph, tf32, fused_qkv).

Tests

  • test_speed_max_enables_tf32_and_fused_qkv now asserts dynamic is None for max. The U-Net tests still assert dynamic=False.
  • tests/test_diffusion*.py tests/test_video*.py: 3826 passed. The failures are the same environment-only ones as on main: 15 in test_diffusion_dataset_api.py and one GGUF Q8_0 registry case.

dynamic=False recompiled the regional blocks on every new prompt length for
DiTs whose blocks see the text tokens (Qwen-Image-2.1 paid 4-6 s on about half
of new prompts). Automatic dynamic (None) keeps the first shape static and
autotuned and generalises a dimension once it changes. U-Net whole-module
compile stays static; the compile-cache fingerprint keys the new mode apart.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 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-09-24T00:03:31.114426Z 7924e03 Manual request
🔒 Security Review ⚠️ Failed 2026-09-23T20:30:42.519518Z 86f43cd 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86f43cdca5

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

Comment on lines +5565 to +5567
# max compiles DiTs with automatic dynamic (None); keyed apart from the old static
# bundles.
"dynamic": None if effective_speed == SPEED_MAX else True,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Persist the auto-dynamic generalized graph

For a max-tier DiT rendered at the same width, height, and batch size with different prompt token lengths, this initially saves only the first static artifact. When the second prompt triggers automatic generalization, the cache is not dirtied again: the generation path registers only (width, height, batch), and compiled_shapes_are_static() still classifies max as static, so register_shape() sees the existing tuple and save_async() remains a no-op. Consequently, each process restart reloads the static-only bundle and pays the prompt-length generalizing compile again; the cache lifecycle needs to re-save after automatic dynamic generalization or defer its initial save.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The max tier now marks its DiTs as automatic dynamic, generate counts dynamo's compiled graphs across the render, and compile_cache.mark_recompiled re-dirties the context when an automatic-dynamic DiT compiled new graphs at an already-registered shape, so save_async rewrites the bundle with the generalised graph. Fixed in b27c8fb, tests added.

…mension

Automatic dynamic recompiles on the first new text length at a (width, height,
batch) the bundle already covers, which register_shape cannot see. Count
dynamo's compiled graphs across the render and re-dirty the cache context when
an automatic-dynamic DiT compiled new ones, so a fresh process loads the
generalised graph instead of recompiling it.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b27c8fbf7d

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

Comment on lines +7513 to +7516
if auto_dynamic_active(state.pipe) and dynamo_graph_count() > graphs_before:
# Automatic dynamic recompiles on the first new text length at an already-registered
# (width, height, batch): persist those graphs too, or every fresh process pays them again.
compile_cache.mark_recompiled(state.compile_cache_ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Persist recompiles from cancelled renders

When a max-tier render is cancelled or raises after Dynamo has generalized the prompt-length graph, control exits before this success-only check. A later successful render can reuse that generalized in-memory graph, so unique_graphs does not increase, while register_shape() also stays clean because width, height, and batch were already recorded; the on-disk bundle therefore remains static-only and recompiles after restart. Fresh evidence beyond the prior comment is the cancellation/error path skipping this bookkeeping entirely, so the context should be dirtied when compilation occurred even if the render does not return successfully.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 45116b7. The render loop now has an exception path that compares the Dynamo graph count against the pre-render value and calls mark_recompiled before re-raising, so a later successful render's save_async rewrites the bundle even though it compiles nothing new.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 45116b7f2b

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

Comment on lines 385 to 388
``max`` compiles regional blocks with automatic dynamic (static until a dimension changes) and
U-Net whole-module is always static;
``default`` DiT compiles dynamic=True (one artifact across shapes). The compile-cache layer
keys on this to re-save its bundle when a session hits an uncovered shape."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid treating auto-dynamic DiTs as fully static

After a max-tier DiT has generalized a changed width, height, or batch dimension, later unseen values of that dimension reuse the symbolic graph without compiling. However, compiled_shapes_are_static() still returns true for every max-tier pipeline, so the generation path calls register_shape() for every new tuple and unnecessarily reserializes and rewrites the entire compile-cache bundle. This can also delay unloads, which wait for background saves. Keep static shape tracking for the U-Net path, but for auto-dynamic DiTs rely on the new Dynamo graph-count delta to dirty the cache only when a graph was actually compiled.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a69aa4a. compiled_shapes_are_static now returns False on the max tier when a DiT compiled auto-dynamic (U-Net whole-module compiles stay static), so register_shape no longer rewrites the bundle for every new tuple; the graph-count delta in generate is what dirties it.

@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: 7924e03231

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

pull Bot pushed a commit to ShinnChow/unsloth that referenced this pull request Sep 24, 2026
…k fail (unslothai#11749)

* Chat UI driver: wait for the Recents thread to load, and let the check fail

The Recents step clicked the first sidebar row, slept 500 ms and read the
turns once. Opening a chat runs a history loader that awaits the thread, its
active runs, its messages and its research state in sequence before anything
renders. On the Windows lane, which runs two Studios and two browsers on one
runner, that took longer than 500 ms in 15 of 57 Windows runs on 2026-09-23,
so the read found turns_text=''. The server logs of those runs show the
messages request returning 200 at or after the moment the driver navigated
away; the thread was loading, not empty.

It never failed a job because the soft_fail sat inside the try whose
except Exception was meant for click errors. In STRICT mode the
AssertionError was caught, logged as "recent-thread click 0 failed", and the
step passed. The FAIL line that shows up in failing runs of unslothai#11706 and
unslothai#11731 is this swallowed message; those jobs failed on other steps.

The step now:
- picks the Recents row whose title is a prompt this run sent, falling back
  to the listed order, since the most recent row need not be ours
- waits up to 20 s for the URL to name that thread and for a user turn to
  contain one of our prompts, instead of reading once after 500 ms
- raises outside the click retry, so a thread that opens without our turns
  fails the run in STRICT mode

tests/studio/test_chat_ui_recents_step.py runs the helper in Chromium
against a page whose thread renders after 1.5 s (passes), one that never
shows our prompts (fails), and one with an unrelated chat above ours
(checks ours), plus source checks for the sleep and the swallowing except.

* Chat UI driver: keep looking for this run's chat when Recents titles are generated

With auto-titling no Recents title equals a prompt this run sent, so the
fallback tried the newest row, stopped there, and failed after 20 s when
that row was someone else's chat, even with ours next in the list.

A row titled with our prompt is ours and must still show our turns. A row
reached only by the fallback is now judged when it loads: our prompt passes,
someone else's turns or none moves on to the next row, within a 60 s budget.

* Chat UI driver: do not judge a Recents row from the previous thread's turns

The chat keeps one runtime while the next thread loads, so the previous
thread's turns stay on screen for a while after the URL changes. Judging a
fallback row on those could reject our chat as someone else's, or, with our
thread already open, pass a different chat on our stale turns.

Snapshot the user turns and open thread before each click, and count turns
identical to that snapshot as not loaded yet unless the clicked row is the
thread that was already open. The fixture can now keep stale turns on screen
until the next thread loads, as the app does.

* Chat UI driver: reopen this run's chat by id in the Recents step

The prompts are fixed, so on a reused Studio home an earlier run's chat can
carry the same title and turns, and the title match would open it and pass
without ever reopening this run's chat.

Read this run's chat id while it is open, from ?thread= or the active Recents
row, and have the Recents step open exactly that row and require our turns in
it. The title search stays as the fallback when no id is on the page. A test
evaluates the driver's capture expression itself, since it only runs there.

* Chat UI driver: find this run's chat by id anywhere in the sidebar

Pinned and project chats use the same row testid as Recents, so on a
reused home this run's chat can sit past the first 20 rows the title
search reads. Locate the captured id directly across every row, and walk
candidate rows rather than indices so a strict row, known to be ours by
id or title, still has to show our turns.

* Recents step tests: skip when another file left a Playwright stand-in

Backend CI's CPU studio shard has no Playwright, and
test_heavy_thread_measurement_integrity.py installs a stand-in
playwright.sync_api whose every name raises RuntimeError. importorskip then
succeeds, and all 12 browser tests errored in that job. A stand-in that
raises now skips, like a missing package.
@danielhanchen
danielhanchen merged commit abb11de into main Sep 24, 2026
35 of 38 checks passed
@danielhanchen
danielhanchen deleted the studio-max-auto-dynamic branch September 24, 2026 07:29
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…k fail (unslothai#11749)

* Chat UI driver: wait for the Recents thread to load, and let the check fail

The Recents step clicked the first sidebar row, slept 500 ms and read the
turns once. Opening a chat runs a history loader that awaits the thread, its
active runs, its messages and its research state in sequence before anything
renders. On the Windows lane, which runs two Studios and two browsers on one
runner, that took longer than 500 ms in 15 of 57 Windows runs on 2026-09-23,
so the read found turns_text=''. The server logs of those runs show the
messages request returning 200 at or after the moment the driver navigated
away; the thread was loading, not empty.

It never failed a job because the soft_fail sat inside the try whose
except Exception was meant for click errors. In STRICT mode the
AssertionError was caught, logged as "recent-thread click 0 failed", and the
step passed. The FAIL line that shows up in failing runs of unslothai#11706 and
unslothai#11731 is this swallowed message; those jobs failed on other steps.

The step now:
- picks the Recents row whose title is a prompt this run sent, falling back
  to the listed order, since the most recent row need not be ours
- waits up to 20 s for the URL to name that thread and for a user turn to
  contain one of our prompts, instead of reading once after 500 ms
- raises outside the click retry, so a thread that opens without our turns
  fails the run in STRICT mode

tests/studio/test_chat_ui_recents_step.py runs the helper in Chromium
against a page whose thread renders after 1.5 s (passes), one that never
shows our prompts (fails), and one with an unrelated chat above ours
(checks ours), plus source checks for the sleep and the swallowing except.

* Chat UI driver: keep looking for this run's chat when Recents titles are generated

With auto-titling no Recents title equals a prompt this run sent, so the
fallback tried the newest row, stopped there, and failed after 20 s when
that row was someone else's chat, even with ours next in the list.

A row titled with our prompt is ours and must still show our turns. A row
reached only by the fallback is now judged when it loads: our prompt passes,
someone else's turns or none moves on to the next row, within a 60 s budget.

* Chat UI driver: do not judge a Recents row from the previous thread's turns

The chat keeps one runtime while the next thread loads, so the previous
thread's turns stay on screen for a while after the URL changes. Judging a
fallback row on those could reject our chat as someone else's, or, with our
thread already open, pass a different chat on our stale turns.

Snapshot the user turns and open thread before each click, and count turns
identical to that snapshot as not loaded yet unless the clicked row is the
thread that was already open. The fixture can now keep stale turns on screen
until the next thread loads, as the app does.

* Chat UI driver: reopen this run's chat by id in the Recents step

The prompts are fixed, so on a reused Studio home an earlier run's chat can
carry the same title and turns, and the title match would open it and pass
without ever reopening this run's chat.

Read this run's chat id while it is open, from ?thread= or the active Recents
row, and have the Recents step open exactly that row and require our turns in
it. The title search stays as the fallback when no id is on the page. A test
evaluates the driver's capture expression itself, since it only runs there.

* Chat UI driver: find this run's chat by id anywhere in the sidebar

Pinned and project chats use the same row testid as Recents, so on a
reused home this run's chat can sit past the first 20 rows the title
search reads. Locate the captured id directly across every row, and walk
candidate rows rather than indices so a strict row, known to be ours by
id or title, still has to show our turns.

* Recents step tests: skip when another file left a Playwright stand-in

Backend CI's CPU studio shard has no Playwright, and
test_heavy_thread_measurement_integrity.py installs a stand-in
playwright.sync_api whose every name raises RuntimeError. importorskip then
succeeds, and all 12 browser tests errored in that job. A stand-in that
raises now skips, like a missing package.
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
unslothai#11731)

* Studio: compile the max tier's DiT blocks with automatic dynamic

dynamic=False recompiled the regional blocks on every new prompt length for
DiTs whose blocks see the text tokens (Qwen-Image-2.1 paid 4-6 s on about half
of new prompts). Automatic dynamic (None) keeps the first shape static and
autotuned and generalises a dimension once it changes. U-Net whole-module
compile stays static; the compile-cache fingerprint keys the new mode apart.

* Studio: keep the video max-tier comments accurate under automatic dynamic

* Studio: re-save the compile cache after the max tier generalises a dimension

Automatic dynamic recompiles on the first new text length at a (width, height,
batch) the bundle already covers, which register_shape cannot see. Count
dynamo's compiled graphs across the render and re-dirty the cache context when
an automatic-dynamic DiT compiled new ones, so a fresh process loads the
generalised graph instead of recompiling it.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: dirty the compile cache when a cancelled or failed max render already generalised a graph

* Studio: track max-tier auto-dynamic DiT bundles by graph count, not per shape

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant