Skip to content

Studio diffusion: give stored-fp8 denoisers their own planner label instead of dense - #14631

Merged
danielhanchen merged 3 commits into
mainfrom
fp8_stored_quant_label
Oct 22, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fp8_stored_quant_label

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Follow-up to #14549. A denoiser whose single-file fp8 weights stay stored in fp8 was identified by the memory planner as a plain dense denoiser, so it borrowed the dense placement data instead of its own.

The stored-fp8 Linear (NativeWeightOnlyLinear, fp8 scheme) keeps its codes and per-row scales as buffers (weight_q, weight_scale). The two planner helpers that decide the denoiser's format only looked at parameters:

  • denoiser_quant_label saw the float biases and norms and returned dense:float16 / dense:bfloat16.
  • _pipe_denoisers_hold_packed returned False.

Consequences:

  1. refine_plan_from_loaded_weights used the fp16 dense eager table as a static seed (measured_static_seed=True, 3072 MiB reserve on FLUX.2-klein) for a build that table never measured. The stored layer widens each Linear per call (fp32 codes, fp32 scaled, then the compute dtype: about 160 MiB for a 4096x4096 Linear against 32 MiB of resident bf16 weight).
  2. A stored-fp8 load and a widened load of the same file shared one learned-peak key, so the two builds read and wrote each other's measured peaks.

Changes

studio/backend/core/inference/diffusion_memory.py:

  • New _holds_fp8_stored(module), reading the _unsloth_fp8_stored count both load paths already set (diffusion_single_file_converters.py, diffusion_comfy_quant.py).
  • _pipe_denoisers_hold_packed returns True for a stored-fp8 denoiser (any of transformer, transformer_2, unconditional_transformer, unet). Refinement then places it the way GGUF and int8 packed denoisers are placed: from a learned peak recorded for its exact build, which includes the per-layer widen. With no learned peak yet, the flat plan stands.
  • denoiser_quant_label returns fp8_stored:<float dtypes>#<variant digest> for it. The digest is the existing graph_variant tag, which already reads the weight_q buffers, so E4M3 and E5M2 codes get different keys.

Labels for dense, torchao, GGUF and packed:int8 denoisers are unchanged, so learned peaks already recorded for them still match. Weight byte accounting (_loaded_component_mib), offload sizing and the compile-cache graph variant already count buffers and need no change.

No change to the learned-peak store's runtime stamp. Peaks a stored-fp8 run wrote under the dense key before this fix can only be higher than the dense build's own peak, and learned peaks only ever raise a reservation. So the leftover entries make dense placement more cautious, never less safe. Bumping the store version would throw away every recorded peak on every host.

Tests

New studio/backend/tests/test_diffusion_fp8_stored_label.py (CPU only, built from the real stored-fp8 layer class):

  • label: fp8_stored: for bf16 and fp16, distinct from the dense label of the same model, E4M3 vs E5M2 distinct, two-expert pipes
  • the learned-peak key does not collide with the dense build's key
  • the packed detector sees the stored layers
  • refinement: no dense static seed; a dense learned peak is not read; its own learned peak places it (measured_static_seed=False)
  • controls: the dense, GGUF and packed:int8 labels are unchanged, and an fp16 dense load still takes the 3072 MiB static seed

The stored-fp8 Linear keeps its codes and scales as buffers, so
denoiser_quant_label and _pipe_denoisers_hold_packed (parameters only)
read it as dense: refinement took the fp16 dense static seed for a build
that widens every Linear per call, and its learned peaks shared the key
of a widened load of the same file.

Label it fp8_stored:<float dtypes>#<variant> and treat it as packed
(learned peak only). Dense, torchao, GGUF and packed:int8 labels are
unchanged.
@danielhanchen danielhanchen self-assigned this Oct 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 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-10-22T09:58:55.413252Z 796289e 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: 937a4c2289

ℹ️ 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 +1655 to +1656
if _holds_fp8_stored(getattr(pipe, name, None)):
return 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.

P1 Badge Disable static seeds for mixed stored-FP8 denoisers

When a supported ComfyUI checkpoint mixes torchao-backed layers with FP8 layers that fall back to stored form—for example, E4M3 plus E5M2 with FP8 storage forced—_pipe_denoisers_hold_torchao() makes dense_mib be None, so the static_seed expression short-circuits before this new packed verdict is consulted and leaves static_seed=True. The first load can consequently be placed from a generic measured table that never included the stored layers' per-forward widening, rather than waiting for this build's learned peak, risking the same under-reservation/OOM this change is intended to prevent. Stored FP8 should disable static seeding independently of whether the denoiser also contains torchao weights.

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.

Good catch. In a ComfyUI file whose int8 layers run on torchao while its fp8 layers stay stored, dense_mib was None, so the static_seed expression short-circuited before the packed verdict and the first load could be seeded from the measured quant table, which never priced the stored layers' per-forward widen. Fixed: any denoiser holding stored fp8 layers now places from its learned peak alone, regardless of torchao presence. Added test_stored_fp8_beside_torchao_layers_never_takes_a_static_seed (fails before the change, passes after), with a torchao-only control that still takes its seed.

…tic seed

A ComfyUI file mixing torchao-backed layers with stored fp8 layers left
dense_mib None, so static_seed stayed True and the first load could be
placed from a measured quant table that never priced the per-forward
widen. Any stored fp8 denoiser now places from its learned peak alone.

[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. 🚀

Reviewed commit: 796289e2d2

ℹ️ 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 38570e2 into main Oct 22, 2026
@danielhanchen
danielhanchen deleted the fp8_stored_quant_label branch October 22, 2026 17:58
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