Repository navigation
feat(sd3): support LoRAs - #9824
Open
Pfannkuchensack wants to merge 3 commits into
Open
Pfannkuchensack wants to merge 3 commits into
Pfannkuchensack wants to merge 3 commits into
Conversation
Identify diffusers, PEFT, SimpleTuner LyCORIS and kohya SD 3/3.5 LoRAs (and DreamBooth folders) with their Medium/Large size instead of misfiling them as Qwen-Image or SDXL; refuse layouts that cannot be applied. Add sd3_lora_loader/collection_loader; the denoise refuses LoRAs of another size before loading, patches transformer and CLIP-L/G (T5 skipped), and reserves sidecar patches under FP8 Storage. Record the SD 3 size on mains and LoRAs, filter the webv2 concept picker by it, and document LoRA support.
# Conflicts: # docs/src/content/docs/Users Guide/03.Models/03.model-format-support.mdx # docs/src/content/docs/Users Guide/04.Image Generation/generate-panel.mdx # invokeai/backend/model_manager/configs/lora.py # invokeai/frontend/api/schema.ts # tests/app/invocations/test_sd3_text_encoder.py
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SD 3 / 3.5 LoRAs could not be used, and most installed as another model:
After this PR, SD 3 LoRAs are identified with their size and applied:
Formats:
transformer.,base_model.model.), includingattn2, the convpos_embed.projand top-level modules.lycoris_with flattened names, LoKR).checkpoint-*copies.Recognition: SD 3 is identified by its widths (1536 Medium, 2432 Large), because Qwen-Image uses the same attention names. The Qwen-Image probe now rejects SD 3 widths and CogView4's
attn1. The generic SD/SDXL probe rejects kohyajoint_blocks.Size: new optional
variant(sd3_medium/sd3_large) on SD 3 Diffusers mains and SD 3 LoRAs, set at install. SD 3 Medium and 3.5 Medium sharesd3_medium. The webv2 concept picker hides LoRAs of the other size when both sides record one.Nodes: new
sd3_lora_loaderandsd3_lora_collection_loaderwith transformer, CLIP-L and CLIP-G fields.sd3_text_encoderpatches CLIP-L and CLIP-G with separate prefixes.sd3_denoise(1.2.0 → 1.3.0) refuses, before it loads the transformer:It patches in place, or through a sidecar with FP8 Storage, and then reserves the patches.
webv2 and docs: SD 3 joins
LORA_SUPPORTED_BASES, the graph routes transformer and CLIP-L/G through the collection loader, and the size has labels and options in the model manager. The docs add a LoRA section to the SD 3 page and update the format matrix and the Generate panel page.Related Issues / Discussions
Closes #9741
QA Instructions
Automated:
CUDA_VISIBLE_DEVICES="" uv run --no-sync pytest -n 4 tests/backend/model_manager tests/backend/patches tests/backend/architectures tests/model_identification tests/app: 10,903 passed. The only failures were the bitsandbytes nf4/int8 tests, which need CUDA; with the GPU visible,tests/backend/model_manager/load/model_cache/torch_module_autocastpasses. Each new test file also passes on its own.convert_sd3_transformer_checkpoint_to_diffuserson random MMDiT weights, for Medium withattn2and for Large.Clybius/mspaint-style-sd3.5mediumand a DreamBooth folder.invoke()hands CLIP-L and CLIP-G their own layers.pnpm -C invokeai/frontend/api lintandtest,pnpm -C invokeai/frontend/webv2 lint, and the webv2 generation/model tests (incl. settings/taxonomy and the concepts browser test): passed. webv1tschas the same 16 errors asmain.HF_ENDPOINTpoints at a mirror that lacks the Xet endpoints; they pass without it.Manual E2E on an RTX 4090 with SD 3.5 Medium (Diffusers), same seed with and without LoRA:
LoRAs:
AdamLucek/sd3.5M-jareklfoto-LoRA-DreamBooth(diffusers)bghira/sd35m-sfwbooru-lycoris(SimpleTuner LoKR)jieliu/SD3.5M-FlowGRPO-PickScore(PEFT)Clybius/mspaint-style-sd3.5medium(kohya, withattn2and the swapped adaLN)linoyts/Yarn_art_SD3_LoRA(diffusers with CLIP-L/G)tensorart/stable-diffusion-3.5-medium-turbo(4 steps)Each applies visibly. Yarn with the text-encoder part differs from yarn with the transformer part only. The turbo LoRA gives a clean image at 4 steps where the base model does not.
FP8 Storage: mspaint and yarn with CLIP.
Logs: the server log contains no
Failed to find module for LoRA layer keyorSkipping LoRA layer.Browser (webv2): for SD 3.5 Medium, the concepts slot shows only Medium LoRAs, and a LoRA marked
sd3_largeis hidden. Sending a Large LoRA through a hand-built graph fails before loading with "LoRA '…' was trained for SD 3.5 Large and does not fit this SD 3 / 3.5 Medium model."Review
The review findings are resolved:
lora_transformer_prefix is gone. No SD 3 file uses it, and it tied with FLUX OneTrainer files.override_fieldsis no longer mutated.Remaining limitations:
lora_transformer_and also train both text encoders are still taken as SDXL, as before this PR.Compatibility / Rollout
variantis optional and defaults toNone, so stored SD 3 records stay valid and discriminator tags do not change. New installs record it. Existing mains and LoRAs get it, and misfiled LoRAs get the right base, through Re-identify in the Model Manager. Re-identify also resets a model's default settings, which the docs note. The picker and the denoise accept records without a size, and the denoise then checks the shapes.SD3VariantTypejoins the variant unions; the OpenAPI schema and types are regenerated.generateGraphNodeTypes.jsonregenerated.Checklist
What's Newcopy (if doing a release after this PR)Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.