Skip to content

Studio: size the default image canvas from how much of the card the weights hold - #11549

Closed
danielhanchen wants to merge 5 commits into
mainfrom
studio-canvas-vram
Closed

danielhanchen wants to merge 5 commits into
mainfrom
studio-canvas-vram

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Replaces the per-family canvas table from #11548 with the rule it should have been: if the weights this load is holding take most of the card, default the image size to 512 instead of 1024.

Why the table had to go

#11548 shipped a hardcoded list, Qwen-Image-2.1 plus the quant schemes that trigger it. That is wrong in both directions. It shrinks the canvas for a quantised Qwen-Image-2.1 on a 180 GB B200, where there is no shortage of anything, and it does nothing for the next family that has the same problem until someone remembers to add a row.

The thing actually worth keying on is not which model it is, it is how much of this card the model already holds.

The rule

recommended_canvas_px(model_dense_mib, device_total_mib) in the memory planner, which is the one place that knows both terms:

weights / total VRAM >= 0.70  ->  512
otherwise                     ->  1024

Deliberately a ratio of the WHOLE card rather than of the safe budget, and of the WEIGHTS rather than of a predicted peak. The question being answered is "how much of this card does the model hold before a single activation is allocated", and someone reading the number off nvidia-smi should land on the same answer we did.

0.70 because it puts the boundary where the reports are:

model card ratio canvas
17 GB 24 GB 0.708 512
18 GB 24 GB 0.750 512
17 GB 40 GB 0.425 1024
16.5 GB 24 GB 0.688 1024

The third row is the point: the SAME model on a bigger card keeps 1024. This is about the card being tight, not about the model being big.

Why it is worth anything: quantising shrinks the weights and leaves the activations alone, so past a certain occupancy the canvas is the only lever left. 1024 costs roughly 7 GB more than 512 on a Qwen-Image-2.1-class model, measured about 26 GB against about 19 GB, which is the whole remaining margin once the weights hold 70% of a 24 GB card.

It is a seed, not a cap

The user's choice wins, at every layer:

  • the backend applies nothing. recommended_canvas is reported on the status payload and read by nobody else. Whatever width and height the generate request carries is what renders.
  • the UI seeds the size fields once per resident model. That is the existing seededResident guard, so a later status poll cannot overwrite a size the user typed.
  • a stored recipe is the user's own choice and already returns before the seed runs.

So the precedence is: explicit width and height, then a stored recipe, then this recommendation, then 1024.

No opinion is not 512

None on unified memory, on a load the planner could not size, and on a backend older than the field. All three keep 1024 rather than shrinking on a guess, and there is a test for each. Unified memory is excluded because a fraction of a pool shared with the host does not mean the same thing as a fraction of dedicated VRAM.

Tests

  • test_diffusion_memory.py, 104 passed. Three new: the ratio at its boundary (including the same model on a 40 GB card staying at 1024), every unsizable input returning None, and the value arriving in plan.estimates where the loader reads it.
  • test_diffusion_backend.py + test_diffusion_memory.py together: 604 passed, 1 failed. The failure is test_every_third_party_bf16_pipeline_the_catalog_offers_is_mirrored, already red on main and unrelated.
  • Frontend: 2 node tests, npm run typecheck clean, biome clean on the changed files.

The typecheck earned its keep here: the field was on the Pydantic model and in the status payload but not in the hand-written DiffusionStatus TS type, and four call sites were silently typed as errors until it was declared.

Not measured

The 26 GB against 19 GB figures are from the report this came out of, not from a run I did on a 24 GB card. The ratio and the plumbing are tested; where exactly the boundary should sit is a judgement call, and 0.70 is chosen to match the observations rather than derived from anything.

@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: 46d450c1ac

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

// above) and a stored recipe has already returned before it, so a size the user typed is never
// overwritten by a later status poll, and the backend applies nothing: whatever width and
// height the request carries is what renders.
const size = resolutionFor({ recommendedCanvas: status?.recommended_canvas });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Seed the recommendation after page-initiated loads

When a user selects and loads a model on this page, handleLoad sets lastLoad.current before the status containing recommended_canvas arrives, so the early return at line 2348 prevents this call from ever applying the recommendation. Consequently, the primary fresh-load flow keeps the previous 1024×1024 fields even when the backend recommends 512×512, defeating the change on the constrained cards it is intended to protect; only models discovered after navigation (or an explicit Default reset) receive the new size.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 6badfb1. The load poll's ready branch now seeds the canvas from recommended_canvas for a load a pick started, through the same seedCanvas helper the resident seed uses. It only replaces the size the page last seeded itself, so a size the user chose before the pick or during the download is kept, and a preset taken after the pick still wins. Reapply and a recalled generation are not picks and keep the size the user set up.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 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-22T19:19:59.163799Z 4110f0e 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 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: 01954dbf79

ℹ️ 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 +819 to +821
"recommended_canvas_px": recommended_canvas_px(
model_dense_mib, device_memory.total_mib, is_unified = device_memory.is_unified
),

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 Calculate the canvas from weights that remain resident

When the plan selects group/model offload—automatically or through balanced/low_vram—model_dense_mib still represents the complete model, including weights that will be streamed from CPU. Comparing that total with card capacity can therefore report 512 even though only companions or one component reside on the card and 1024 has ample activation headroom; this unnecessarily reduces output quality for precisely the models whose placement already solved the VRAM pressure. Derive the recommendation from the selected policy's resident weight footprint rather than the pre-offload total.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing this. Offload streams the weights, not the activations, and the activations are what the canvas controls. Keying on the resident footprint would also switch the rule off in the case it exists for: with a 17 GB model on a 24 GB card, the planner picks group offload (resident_required 23552 MiB against a 20619 MiB safe budget), so the resident weights are only the companions and the recommendation would stay at 1024. The PR deliberately uses total weights over total card for that reason.

Comment on lines +72 to +75
if (current.width !== seeded.width || current.height !== seeded.height) {
return null;
}
const id = repoId.toLowerCase();
const matched = QUANTISED_CANVAS.find(
(entry) => id.includes(entry.match) && entry.schemes.includes(scheme),
);
return matched
? { width: matched.width, height: matched.height }
: DEFAULT_RESOLUTION;
return resolutionFor({ recommendedCanvas });

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 Track canvas ownership instead of comparing dimensions

When a stored/restored recipe or an explicit user action selects the same dimensions as the page's previous seed (commonly 1024×1024), this equality test treats the fields as untouched and replaces them with the newly loaded model's recommendation. Thus a user-owned 1024×1024 recipe can silently become 512×512 after a load; dimension equality cannot establish provenance, so ownership needs to be recorded when presets, restores, or manual controls write the fields.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 4110f0e. setWidth/setHeight now count every size write (presets, stored-recipe hydration, gallery restore, the manual controls) and seedCanvas records the count it seeded at, so the ready branch seeds only when nothing has written the size since the page's own last seed. A restore or preset that lands on the same 1024x1024 now keeps it; the new test covers exactly that case.

@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: 4110f0e37c

ℹ️ 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 +819 to +821
"recommended_canvas_px": recommended_canvas_px(
model_dense_mib, device_memory.total_mib, is_unified = device_memory.is_unified
),

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 Compute the ratio from the selected pipeline weights

For Hub pipeline loads, model_dense_mib comes from _cache_bytes, which sums every cached file in the live snapshot rather than only the files the pipeline will load. If the user has cached an alternate weight variant or another unused large artifact from the same repository, those bytes can push this ratio above 0.70 even though they are not resident, causing the UI to default a model that comfortably fits to 512×512. Derive the recommendation from the selected files or the actual resident-weight estimate instead of the aggregate cache size.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing this here. model_dense_mib is the planner's existing resident estimate, the same number plan_diffusion_memory already uses to choose the offload policy on main. The recommendation deliberately reads it rather than computing a second size. If a hand-populated cache holding unused variants inflates it, the offload decision is off in the same way, so the fix belongs in the shared estimator (_cache_bytes selection), not in a second estimate for the canvas. Here the effect is only a default size, and the user can change it.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 4110f0e37c

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

@oobabooga

Copy link
Copy Markdown
Member

I measured this against real loads, and I suggest closing it. The 512 default fires on loads that already run 1024 fine, including the page's default model.

What the PR does. It lowers the default image size from 1024 to 512 whenever the model's weights take 70% or more of the card's VRAM.

Why that misses. 1024 does run out of memory when a big quantized model sits entirely on a 24 GB card. But Studio never puts it there. The memory planner already reserves room for 1024 images when it decides placement (runtime_headroom_mib = 8192). When the weights don't leave that room, it keeps part of the model in CPU memory and streams it in ("group offload"). With that placement, 1024 fits easily.

Measured on an RTX 3090 (24 GB):

load where the weights live PR's default 1024x1024 result
Qwen-Image-2.1, INT8 and fp8 text encoder, forced fully onto the GPU all on GPU 512 out of memory (512 fits at 19.1 GiB)
Qwen-Image-2.1, default load group offload 512 works, 7.22 GiB peak (10.57 GiB reserved)
Z-Image-Turbo, default load group offload 512 works, 2.55 GiB peak (6.55 GiB reserved)

The first row is a placement the planner refuses on this card. The default load logs "an artifact-sized plan for int8 still offloads on this card" and uses the bf16 transformer with group offload instead. In an offline _plan_memory run, the quantized build only stays fully on the GPU from 40 GB (fast mode) or 48 GB (auto). On those cards the PR already picks 1024.

The regression. Z-Image-Turbo is the page's default model. Main gives it 1024. This PR gives it 512 on every card from 12 to 32 GB. My follow-up commit 6badfb1 applies that default on every model pick, so merging would spread it further.

#11548 does not have this problem on 24 GB. Its 512 only applies when the quantized transformer actually engages (the engaged transformer_quant). On the 24 GB default load that value is null, so main keeps 1024. It can only engage on a card of 40 GB or more, which I have not measured at 1024.

I have not measured the other large families, any fully-on-GPU load on a 32 GB or larger card, B200, or unified memory.

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.

2 participants