Repository navigation
studio: offer the undistilled z-image base for lora training - #8291
Conversation
Z-Image LoRA training offered only the distilled Tongyi-MAI/Z-Image-Turbo, while the upstream DreamBooth recipe in diffusers trains on Tongyi-MAI/Z-Image. That repo was absent from _TRUSTED_NON_GGUF_REPOS, so _assert_trusted_base_model refused it before anything was fetched. The same gap broke an inference pick. unsloth/Z-Image-GGUF carries base_model: Tongyi-MAI/Z-Image, and _resolve_base_repo drops a card tag that fails _is_trusted_diffusion_repo, so it fell back to the Turbo companions and denoised on their shift 3.0 scheduler instead of the base's 6.0. Add the base to the allowlist and to the z-image train_base_repos, keeping the nf4 Turbo repo first so the picker default is unchanged. Share the Qwen3-4B pre-cast text encoder through _TE_EQUIVALENT_BASES: the shards are sha256 identical across both checkpoints, so the base reuses the 4.41 GB artifact instead of pulling 8.04 GB dense. Price the base's download correctly. The family factor of 2.0 exists because Turbo publishes fp32 (24,619,634,944 bytes); the base ships bf16 (12,309,817,472 bytes) and downloads what it occupies, so hub_download_factor pins it at 1.0 through a per-base table. Without it the free-disk gate demanded twice the real size.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d814a88b2
ℹ️ 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".
Both hosted z-image checkpoints are baked from the distilled Turbo transformer, but family_prequant_repo fell back to them for any base without its own variant row. The base_model_id check refuses the artifact at load time, long after planning acted on it: auto declined the dense path whenever the Turbo artifact was uncached, and an explicit int8/fp8 request downloaded it, hit the refusal, and found no dense shards staged. Add prequant_excluded_bases so a base whose weights genuinely differ resolves to None and plans from its own dense transformer, and list Tongyi-MAI/Z-Image there. Key both per-base tables in diffusion_auto_policy on the lowercased canonical id. canonical_base preserves the caller's casing for a non-mirror, so a base typed as tongyi-mai/z-image cleared the case-insensitive trust gate and then missed its download override. _BASE_REPO_BF16_GB had the same defect: a lowercase FLUX.2-klein-base-9B was sized as the 4B.
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Checked the four factual claims against the Hub and they all hold:
One blocker though.
|
|
Correction to my first bullet above: I had the two dtypes the wrong way round. Your table is the correct one. Read back off the safetensors headers just now:
So the base is the bf16 one and Turbo is the fp32 one, exactly as the PR body says, and it is the distilled Turbo that earns the family factor of 2.0. The conclusion is unchanged: pinning the base at 1.0 is right, and charging it the family factor would make the free-disk gate demand 24.6 GB for a 12.3 GB download. The other three claims stand as checked. |
… hosted checkpoint family_prequant_repo is shared with the video loader, which calls it with a VideoFamily. That class has no prequant_excluded_bases, so the new plain attribute read raises AttributeError, and resolve_prequant_source catches it in the bare except that exists to survive a bad family object and returns None. The result is that every video family silently loses its hosted prequant denoiser and falls back to dense whenever a base_repo is passed, which the H3 modular load always does. Two existing tests caught it, both passing at the merge base 9959212 and failing on the head: tests/test_video_backend.py::test_download_plan_stages_the_prequant_denoiser_it_drops_the_dense_shards_for tests/test_video_backend.py::test_h3_modular_load_pins_a_hosted_prequant_denoiser_out_of_the_offload_rotation Same defensive read the surrounding code already uses for cross-family fields, plus a regression test that pins family_prequant_repo and resolve_prequant_source on a VideoFamily directly.
|
No round-trip needed, I have pushed the one-liner to the branch as 086b031 since maintainer edits are on. Nothing else in the PR changed. # getattr, because the video loader calls this with a VideoFamily, which has no such
# field. A plain attribute read raises AttributeError, resolve_prequant_source swallows it
# in its bare except and hands back None, and every video family silently loses its hosted
# prequant checkpoint to the dense path whenever a base_repo is passed.
if base in (getattr(fam, "prequant_excluded_bases", ()) or ()):
return NonePlus a regression test in Full
The set difference is exactly the two video tests: (one more line, After 086b031, 396 passed across On the CI: the four Backend CI Python jobs are killed at the 15 minute Thanks for the careful writeup, the sizing correction in particular was the right call and I had it backwards. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 086b031361
ℹ️ 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".
| train_base_repos = ( | ||
| "unsloth/Z-Image-Turbo-unsloth-bnb-4bit", | ||
| "Tongyi-MAI/Z-Image-Turbo", | ||
| "Tongyi-MAI/Z-Image", |
There was a problem hiding this comment.
Make the generation hints match the undistilled base
When a user selects this newly offered base, trains an adapter, and clicks Deploy, handleDeployAdapter correctly initializes the Create page to 20 steps and guidance 4 via defaultsFor; however, the visible Steps and Guidance hints in studio/frontend/src/features/images/images-page.tsx still explicitly recommend Z-Image-Turbo's 9-step, guidance-0 recipe. Users following those instructions will switch the undistilled model to its distilled sibling's settings and get poor output, so the hints need to become model-aware or neutral before advertising this deployment path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not this PR. Those two hints are static strings on ImagesPage, the single Create page every diffusion family renders through, and they have read that way since #6763:
studio/frontend/src/features/images/images-page.tsx:3615 hint="9 is the recommended setting for Z-Image-Turbo. More steps rarely help."
studio/frontend/src/features/images/images-page.tsx:3625 hint="Keep this at 0 for Z-Image-Turbo. Higher values make its output worse. Other models use guidance."
Byte identical at this branch's merge base 9959212 and at the head, and the PR does not touch that file at all. They already mis-advise FLUX.1, Qwen-Image, Lumina, HiDream and the Z-Image base itself, which has been loadable for inference through unsloth/Z-Image-GGUF the whole time, so this is not a path the PR opens.
The machine-readable side is right and stays right, which you note yourself: _GENERATION_DEFAULTS resolves Tongyi-MAI/Z-Image to 20 steps at guidance 4 behind the more specific z-image-turbo key, and Deploy seeds the Create page from defaultsFor. Making the hint text model-aware is worth doing, but it is a pre-existing copy fix for the whole page and belongs in its own change rather than bolted onto a training-base allowlist entry.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Resolves the diffusion_families.py DiffusionFamily field conflict by keeping both new fields: prequant_excluded_bases from this branch and prequant_filenames from main.
Summary
Z-Image LoRA training offered only the distilled
Tongyi-MAI/Z-Image-Turbo, whileexamples/dreambooth/README_z_image.mdandtrain_dreambooth_lora_z_image.pyin diffusers train onTongyi-MAI/Z-Image. That repo was absent from_TRUSTED_NON_GGUF_REPOS, so_assert_trusted_base_modelrefused it before anything was fetched and no custom-base entry could reach it.
Fixes #8270.
What changed
tongyi-mai/z-imageto_TRUSTED_NON_GGUF_REPOSandTongyi-MAI/Z-Imageto the z-imagetrain_base_repos._TE_EQUIVALENT_BASES.hub_download_factor.The allowlist gap also broke an inference pick
unsloth/Z-Image-GGUFcarriesbase_model: Tongyi-MAI/Z-Image._resolve_base_repodrops a card tagthat fails
_is_trusted_diffusion_repo, so that pick fell back to the curated family default and loadedthe Turbo companions. Their scheduler is
shift: 3.0against the base'sshift: 6.0, so the base GGUFdenoised on the wrong sigma schedule. The same allowlist entry fixes both paths. This is the defect the
existing klein-9B comment in that table already records for FLUX.2.
Correction to the issue's sizing claim
#8270 states that Z-Image ships fp32 and that
_FAMILY_HUB_DOWNLOAD_FACTOR["z-image"] = 2.0thereforealready covers the base. It is the other way round. Read from the Hub:
Tongyi-MAI/Z-ImageTongyi-MAI/Z-Image-TurboBoth hold 521 tensors and identical configs, so the 12.3 GB bf16-resident figure in
_FAMILY_BF16_GBstays correct for both. The family factor of 2.0 exists because the distilled Turbo publishes fp32, and
charging it to the base made the free-disk gate demand 24.6 GB for a 12.3 GB download.
_BASE_REPO_HUB_DOWNLOAD_FACTORpins the base at 1.0, mirroring the shape of the existing_BASE_REPO_BF16_GBoverride.The rest of the issue's analysis holds.
_ZIMAGE_TARGETSalready matches the upstream script's["to_k", "to_q", "to_v", "to_out.0"], z-image is not inAUTO_FLOW_SHIFT_FAMILIESsoflow_shiftdefaults to 1.0 and the scheduler's static shift is baked in at init, and
_GENERATION_DEFAULTSalreadyresolves the base to 20 steps at guidance 4 behind the more specific
z-image-turbokey.Text encoder, VAE and tokenizer are byte identical
Compared through the Hub paths-info API:
text_encoder/model-00001-of-00003.safetensors328a91d3122359d5547f9d79521205bc0a46e1f79a792dfe650e99fc2d651223text_encoder/model-00002-of-00003.safetensors6cd087b316306a68c562436b5492edbcf6e16c6dba3a1308279caa5a58e21ca5text_encoder/model-00003-of-00003.safetensors7ca841ee75b9c61267c0c6148fd8d096d3d21b6d3e161256a9b878154f91fc52vae/diffusion_pytorch_model.safetensorsf5b59a26851551b67ae1fe58d32e76486e1e812def4696a4bea97f16604d40a3Only the transformers differ. Without the
_TE_EQUIVALENT_BASESentry the validator refuses theTurbo-baked artifact for the base and every base run re-pulls the encoder dense, 8.04 GB instead of 4.41 GB.
What this PR deliberately leaves out
No deploy pairing.
deploy_base_repois family-wide anddeployBaseForrewrites any repo listed inbase_repos, so pairing z-image to Turbo would also rewriteunsloth/Z-Image-Turbo-unsloth-bnb-4bitandsend a QLoRA run's preview to a dense fp32 load. Per-variant
deploy_base_reposis #8267's work and is noton main. An adapter previews on whichever checkpoint it trained on, which is what the upstream recipe does.
No model-picker row for the base.
unsloth/Z-Imagedoes not exist on the Hub, andtest_every_third_party_bf16_pipeline_the_catalog_offers_is_mirroredrequires an unsloth mirror for everyvendor bf16 pipeline the catalog offers. A mirror row for a repo that is not published would send
prefer_ungated_mirrorto a 404. Deploy does not need the row:handleDeployAdaptercallshandleLoad(baseRepo, { kind: "pipeline" })with the id directly, and the frontendMODEL_DEFAULTStablealready resolves
Tongyi-MAI/Z-Imageto 20 steps at guidance 4. The catalog entry should land togetherwith the mirror once one is published.
Base is not the default. The nf4 Turbo repo stays first in
train_base_repos, so the picker default,download size and VRAM floor are unchanged for existing users. #8267 earned its base-first flip with a
measured comparison; nothing equivalent exists for Z-Image yet.
Testing
test_diffusion_more_families.py,test_diffusion_auto_policy.py,test_diffusion_te_prequant.py,test_diffusion_dit_trainer.pyand the catalog mirror invariant intest_diffusion_backend.py.Turbo is still unmeasured, matching what Studio: Z-Image LoRA training only offers the distilled Turbo checkpoint, while the upstream recipe trains on Tongyi-MAI/Z-Image #8270 says about its own scope.