Skip to content

Studio: keep bf16 for auto precision on image families that cannot compile - #11819

Merged
danielhanchen merged 23 commits into
mainfrom
studio-auto-quant-uncompilable
Sep 25, 2026
Merged

danielhanchen merged 23 commits into
mainfrom
studio-auto-quant-uncompilable

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Lumina-2 and HiDream-I1 get an automatic INT8 transformer today (the hosted *-FP8 artifacts carry an INT8 file too), but their diffusers transformer classes carry an empty _repeated_blocks, so compile_repeated_blocks raises and the quantised transformer runs eager. Eager dynamic INT8 is several times slower than the bf16 weights it replaced, and further from them.

With this change an auto precision keeps the released weights for a family whose denoiser cannot be regionally compiled, as long as they fit resident. Both places that decide agree: the pre-download seed decision (so the pull stages the bf16 shards instead of the INT8 artifact) and the loader. The resolved record says why (source: auto, value: off).

Unchanged:

  • explicit schemes (int8, fp8, ...) are honoured as before
  • every family whose class declares repeated blocks (FLUX, Qwen-Image, Z-Image, Krea-2, HunyuanImage-2.1, Ideogram-4, ...), plus SDXL
  • a class that is missing or predates _repeated_blocks counts as compilable, so nothing narrows on an older diffusers, and a diffusers that fills the list in widens this automatically
  • when the bf16 plan would offload, or the planner could not measure the card (it then stays resident without proving a fit), auto still quantises
  • hosts without the dense quant (ROCm, Mac, CPU, torchao stub) keep their existing path and reason

Results

B200, speed default, memory fast, 1024px, family default steps and CFG (Lumina-2 50 / 4, HiDream-I1 50 / 5), prompts and seeds from the frozen image_24 set. The B200s are shared with other jobs, so the per-arm GPU and contention are in the logs; ratios inside one table come from arms on the same class of card.

model arm path engaged s / image (new prompts) LPIPS vs bf16 (mean / max)
Lumina-2 main, auto int8, eager (compile raised) 22.6 / 27.5 (two runs) 0.039 / 0.072
Lumina-2 this PR, auto bf16, reason recorded 3.05 0.000 (bit-identical, 4/4)
Lumina-2 main, precision off bf16 3.08 to 4.5 0
HiDream-I1 main, auto int8, eager 104 to 123 0.151 / 0.242
HiDream-I1 this PR, auto bf16, reason recorded 39.7 to 41.3 0.00004
HiDream-I1 main, precision off bf16 19.1 to 23.8 (less loaded card) 0

Consumer GPU (Colab L4, 24 GB, exclusive VM), Lumina-2 1024px:

arm plan s / image
main, auto int8 resident, eager 101.7
this PR, auto int8 resident, eager (bf16 would offload, so the fit exception keeps the quant) 101.6
main, precision off bf16, group offload 47.0

So on an L4 this PR changes nothing, by design: the bf16 plan picks group offload there, and the "quantise to stay resident" exception keeps today's behaviour. Worth noting for a follow-up: on that card bf16 with group offload is 2.2x faster than the resident eager INT8 and exact, so the fit exception is only clearly right where the bf16 weights cannot be hosted at all (HiDream's 63 GB on a small host).

Every changed cell (14 families x 4 requests x 3 plans {measured resident, unmeasured resident, offload} x 3 kinds x 4 speeds = 2016 cells): 2004 unchanged, 12 moved, all of them lumina-2 / hidream-i1 + auto + bf16 resident, over pipeline and GGUF picks, speed eager / default / max. The two pipeline + eager cells were already declined before (speed eager refuses any quant), only the reason text moves.

Tests

  • test_diffusion_pipeline_prequant.py: seed decision keeps the released weights when they fit, still seeds when bf16 would offload, still seeds an explicit scheme, compilable family unchanged; load path keeps auto unquantised with the reason, still quantises when bf16 would offload, honours an explicit scheme.
  • test_diffusion_speed.py: the predicate over declared / empty / undeclared / missing classes and non-transformer denoisers.
  • Unmeasured budget (seed and load), a host without the dense quant, and the diffusers import taking the dynamo import-window guard first each have a test.
  • Reverting only the two functional hunks fails the two behaviour tests and passes the rest; the full diffusion + image suites: 3045 passed, 15 failed, the same 15 test_diffusion_dataset_api.py failures as main (datasets is not installed in that venv).

Screenshot

Images page, Advanced > Loaded build, after loading Alpha-VLLM/Lumina-Image-2.0 with precision left on auto (B200, bf16 fits resident on both sides). BEFORE is the merge base 1ecc01a30, AFTER is 0a82fd6ca. The transformer goes from AUTO: INT8 to AUTO: OFF | BF16, and the badge tooltip carries the new reason ("'lumina-2' cannot be regionally compiled ..."). The Attention row moves from cuDNN to native SDPA because the INT8 build forces speed default on main, while the kept bf16 build keeps the unset speed request, same as a precision-off load on main.

Loaded build, before and after

Lumina-2 and HiDream-I1 declare no regional compile blocks, so an auto
INT8 transformer ran eager torchao, several times slower than the bf16
weights it replaced. Auto now keeps the released weights for such a
family when they fit resident, both in the pre-download seed decision
and in the loader, and says why in the resolved record. Explicit
schemes and families that compile are unchanged.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 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-09-25T18:52:57.503120Z 1d87562 Manual request
🔒 Security Review ✅ Completed 2026-09-25T15:05:56.103720Z 0a82fd6 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[bot]

This comment was marked as resolved.

The pre-download seed decision asks family_compiles_regionally before
load_pipeline takes its own guard, so the diffusers import there could
race the background torch warm.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Sep 24, 2026
The planner stays resident when it cannot read the card, which proves
no fit, so keeping bf16 now needs a measured budget and requirement.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

- Judge the load-time decision on a pipeline plan re-priced from the bf16
  resident table, so fp32 shards (Lumina-2) do not force the eager quant.
- Price a hosted pre-cast text encoder in the pre-download bf16 plan.
- A resident plan proves a fit only when its requirement is within the
  budget; unified memory plans none regardless of size.
- Offline, keep a cached seed when the snapshot has no released shards.
- A GGUF baking LoRAs keeps the dense build, the only path that carries them.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…m's pre-cast TE4

- The offline keep-bf16 return now requires one snapshot whose transformer/
  holds every shard its index names, not any cached weight byte.
- The bf16 table plan prices HiDream's hosted pre-cast Llama text_encoder_4,
  which the generic pre-cast scale does not probe.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

- Offline, price the text encoder dense: an uncached pre-cast one loads dense.
- A numbered shard without its index is not a complete transformer.
- Offline, look for the released shards under the ungated mirror too.
- Always re-price HiDream pipelines from the table, which counts the Llama
  text_encoder_4 no cached plan sees.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Sep 25, 2026

@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: 6c33f16e1c

ℹ️ 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 +6362 to +6368
if (
getattr(fam, "name", None) != HIDREAM_FAMILY_NAME
and self._resident_sized_plan(
plan, fam, base, target, kind, text_encoder_quant = text_encoder_quant
)
is plan
):

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 Preserve measured sizing for custom HiDream pipelines

For any local or renamed pipeline identified as HiDream through its model index or family_override, this condition bypasses _resident_sized_plan entirely and replaces the measured checkpoint footprint with the fixed official-family table. A custom HiDream configuration with a larger transformer can therefore have its real plan select offload while the table appears resident, causing auto precision to be rewritten to off and loading the released transformer under offload instead of taking the resident quantized path. Fresh evidence beyond the standalone-encoder fix is that _resident_sized_plan deliberately refuses coarse family-table sizing for local and unrecognized bases, but this HiDream exception removes that safeguard; account for the standalone encoder without discarding the measured transformer size.

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.

Not changing this. Every HiDream-I1 checkpoint (Full, Dev, Fast and their mirrors) has the same 17B transformer the family table prices, and none ships text_encoder_4, which is exactly what the measured plan misses. A local fp8 or nf4 copy is smaller than the table, so the table errs toward keeping the quant. A larger custom HiDream transformer is hypothetical.

…'s cache root offline

- The seed planner prices a pre-cast encoder only when the hosted artifact
  resolved for this pull; otherwise the dense encoder is staged and loaded.
- The offline released-shard check reads the snapshot the loader will read:
  the first root, live then import-time, whose refs/main holds the manifest.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Sep 25, 2026

@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: add1e51774

ℹ️ 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 +3055 to +3059
self._released_transformer_cached(candidate)
for candidate in dict.fromkeys(
(
fetch_base,
base,

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 Check only the offline repo the loader will read

When local_files_only=True, accepting a complete transformer from any candidate can discard a usable cached seed even though the selected fetch_base lacks those shards. For example, if the upstream cache contains companion weights while the mirror contains the complete released transformer, the later offline mirror selection sees an empty base_files list and chooses the upstream because it has a weight; this probe instead succeeds on the mirror, returns None, and from_pretrained fails against the incomplete upstream snapshot. Fresh evidence beyond the earlier mirror report is that _run_load later selects exactly one fetch_base with prefer_ungated_mirror(..., files=base_files), so availability under another candidate cannot satisfy that load; resolve that selection first and check only its snapshot.

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.

The probe never reaches the mirror in that case. prefer_ungated_mirror(base) with no file list is the same call _run_load makes offline (files=[] and None both mean any weight), so when the upstream holds companion weights it returns the upstream and the candidate list is only upstream ids. The mirror is checked only when the loader would also pick it. Pinned by test_an_offline_pick_checks_only_the_repo_the_load_reads (passes before and after 4c6d4bc).

Comment on lines +3067 to +3068
):
return None

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 Fall back to a cached seed when bf16 cannot fit on disk

When the released bf16 weights fit GPU memory but are not cached, this return drops an already-cached pre-quantized seed without checking whether the cache volume can hold the replacement download. For Lumina-2 that can require roughly 21 GB of fp32 shards, so a nearly full cache subsequently fails the scoped download's disk preflight even though the cached seed and companions could have loaded successfully. The normal candidate resolver explicitly exempts cached prequant artifacts from its free-disk gate for this reason; apply an equivalent acquisition check before choosing bf16, or retain the cached seed when the missing released shards cannot be staged.

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.

Intended. On a card where the released weights fit, auto now prefers them because the uncompiled quantised denoiser is several times slower; that pull goes through the existing download disk preflight, which refuses before any byte moves with an actionable message, and an explicit int8/fp8 still uses the cached seed. Keeping a slower path to avoid a possible disk shortfall is not what auto should do.

variant=None loads only the default weights, so the offline completeness check
ignores .fp16 / .bf16 indexes and files. Also pins that the offline check reads
only the repo the loader selects.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@unslothai unslothai deleted a comment from danielhanchen Sep 25, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0a82fd6caf

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 0a82fd6caf

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: eeb982bbbc

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

@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 1d875629d9

ℹ️ 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 e5082af into main Sep 25, 2026
33 of 36 checks passed
@danielhanchen
danielhanchen deleted the studio-auto-quant-uncompilable branch September 25, 2026 19:06
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…mpile (unslothai#11819)

* Studio: keep bf16 for auto precision on families that cannot compile

Lumina-2 and HiDream-I1 declare no regional compile blocks, so an auto
INT8 transformer ran eager torchao, several times slower than the bf16
weights it replaced. Auto now keeps the released weights for such a
family when they fit resident, both in the pre-download seed decision
and in the loader, and says why in the resolved record. Explicit
schemes and families that compile are unchanged.

* Close the dynamo import window before probing the diffusers class

The pre-download seed decision asks family_compiles_regionally before
load_pipeline takes its own guard, so the diffusers import there could
race the background torch warm.

* Leave hosts without the dense quant on their existing reason

* Keep the auto quant when the memory budget could not be measured

The planner stays resident when it cannot read the card, which proves
no fit, so keeping bf16 now needs a measured budget and requirement.

* Studio: tighten the uncompilable-family auto bf16 decision

- Judge the load-time decision on a pipeline plan re-priced from the bf16
  resident table, so fp32 shards (Lumina-2) do not force the eager quant.
- Price a hosted pre-cast text encoder in the pre-download bf16 plan.
- A resident plan proves a fit only when its requirement is within the
  budget; unified memory plans none regardless of size.
- Offline, keep a cached seed when the snapshot has no released shards.
- A GGUF baking LoRAs keeps the dense build, the only path that carries them.

* Studio: offline seed check needs a complete transformer, price HiDream's pre-cast TE4

- The offline keep-bf16 return now requires one snapshot whose transformer/
  holds every shard its index names, not any cached weight byte.
- The bf16 table plan prices HiDream's hosted pre-cast Llama text_encoder_4,
  which the generic pre-cast scale does not probe.

* Studio: harden the offline and HiDream sizing of the auto bf16 decision

- Offline, price the text encoder dense: an uncached pre-cast one loads dense.
- A numbered shard without its index is not a complete transformer.
- Offline, look for the released shards under the ungated mirror too.
- Always re-price HiDream pipelines from the table, which counts the Llama
  text_encoder_4 no cached plan sees.

* Studio: size the pre-cast encoder only once resolved, read the loader's cache root offline

- The seed planner prices a pre-cast encoder only when the hosted artifact
  resolved for this pull; otherwise the dense encoder is staged and loaded.
- The offline released-shard check reads the snapshot the loader will read:
  the first root, live then import-time, whose refs/main holds the manifest.

* Studio: a dtype-variant twin is not a cached released transformer

variant=None loads only the default weights, so the offline completeness check
ignores .fp16 / .bf16 indexes and files. Also pins that the offline check reads
only the repo the loader selects.

* Studio: only canonical diffusers weight names make a cached released transformer

The offline completeness check matches the default index and unsharded weight
names from_pretrained(variant=None) reads, so an adapter or other auxiliary
checkpoint in transformer/ no longer counts.

* Studio: carry whether the pre-cast encoder resolved into the load-time decision

_run_load passes _te_prequant_resolved to load_pipeline, and the load-time
bf16 decision budgets the encoder dense when the hosted artifact did not
resolve for this pull, matching the pre-download plan.

* Studio: place kept bf16 weights by the plan that proved they fit

When auto keeps an uncompilable family's released weights because the
bf16-resident re-price fits, that plan now drives placement too, so Lumina-2's
fp32 shard bytes no longer offload a pipeline that fits resident.

* Studio: trim comments in auto precision uncompilable-family change

* Studio: wrap long re-pricing docstring

* Studio: skip the bf16 re-plan for families that compile regionally

* Studio: judge the cached transformer by the checkpoint diffusers loads

A partial safetensors index next to a complete .bin set was read as a
cached release, dropping an offline prequant seed for a load that then
fails on the missing safetensors shards. Diffusers prefers the
safetensors index and never reads a .bin index by default.

* Studio: honour an operator's pre-quant checkpoint under auto on uncompilable families

The auto bf16 preference for families that cannot compile regionally returned
before the seed planner and the loader looked at transformer_prequant_path, so
an allowlisted local checkpoint was silently replaced by the released weights.
A present, allowlisted checkpoint now skips that preference in both places.

* Studio: shorten two docstrings
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