Skip to content

Studio diffusion: key the CFG-batch verdict on the weight quant, not just the module layout - #15047

Merged
danielhanchen merged 5 commits into
mainfrom
studio-cfg-batch-verdict-quant-key
Oct 24, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
studio-cfg-batch-verdict-quant-key

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

The cross-process CFG-batch verdict store (#14849) keys the batched-vs-plain decision on a load identity that cannot tell a bf16 load from a torchao INT8 or FP8 dynamic load of the same model. A verdict timed on one is reused on the other without timing. This PR adds the weight tensor classes and the engaged transformer_quant to the key, and bumps the store version so old entries simply miss. Every other part of the verdict store is unchanged, so a shape still takes one path in every process.

Details

  • After torchao quantize_, layers are still nn.Linear and the weights still report torch.bfloat16, so _load_identity hashed bf16, INT8-dynamic and FP8-dynamic (PerRow) to the same sha1. An INT8 or FP8 load could then be stuck on the path that was faster for bf16, or miss a gain. Pixels were within the batched tolerance either way, so this is speed only.
  • _load_identity now also hashes each parameter's tensor class and, for torchao subclasses, their non-tensor attributes (mm_config, act_quant_kwargs, kernel_preference, dtype; block_size is skipped since it only follows the layer shape). This separates fp8 with and without fast accumulate too.
  • install_cfg_batch takes transformer_quant. The image (diffusion.py) and video (video.py) loads pass transformer_quant_engaged, the scheme the load already records, so GGUF and other non-torchao quant paths are covered as well.
  • The key also carries the live attention backend (_unsloth_attention_backend), read when the verdict is looked up. set_attention_backend() changes neither the module classes nor the config, so the load identity alone missed a backend switch.
  • The store version goes from 1 to 2, and the reader ignores a file of another version. Old entries simply miss and are replaced on the next write.

Tests

New tests in studio/backend/tests/test_diffusion_cfg_batch.py, all 6 fail on main and pass here:

  • test_the_verdict_key_tells_bf16_from_torchao_int8_and_fp8_loads: bf16, INT8, FP8 fast accumulate on and off all give different keys.
  • test_the_verdict_key_includes_the_engaged_transformer_quant
  • test_the_same_load_gives_a_stable_verdict_key: a deep copy of each load gives the same key.
  • test_install_keys_the_router_on_the_engaged_quant
  • test_the_verdict_key_follows_the_live_attention_backend
  • test_a_version_1_verdict_store_is_not_read

pytest tests/test_diffusion_cfg_batch.py tests/test_diffusion_cfg_batch_sync.py: 48 passed, 2 skipped. tests/test_diffusion_memory_vram_budget.py -k cfg: 3 passed. CPU only. The speed effect on a real GPU of reusing a bf16 verdict on an INT8 or FP8 load was not measured.

…and quant scheme

A torchao INT8 or FP8 dynamic load keeps nn.Linear and a bf16 .dtype, so the
stored batched-vs-plain verdict of a bf16 load was reused on its quantized
load without timing, and the reverse. Hash the weight tensor subclasses (with
their non-tensor attributes, e.g. fp8 fast accumulate) and the engaged
transformer_quant, and bump the store version so old entries are not read.

A compute-bound plain verdict comes from one plain pair with no doubled call
timed; keep it for the load only instead of storing it for every process.
@danielhanchen danielhanchen self-assigned this Oct 24, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@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-24T00:49:19.719642Z — 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. Hooray!

Reviewed commit: 54b02c8548

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

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.

ℹ️ 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 a1d9411 into main Oct 24, 2026
42 checks passed
@danielhanchen
danielhanchen deleted the studio-cfg-batch-verdict-quant-key branch October 24, 2026 03:28
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