fix: raise informative ValueError on architecture mismatch when loading LoRA weights (SD 1.5 into SDXL)#13938
Open
Liauuu wants to merge 1 commit into
Open
fix: raise informative ValueError on architecture mismatch when loading LoRA weights (SD 1.5 into SDXL)#13938Liauuu wants to merge 1 commit into
Liauuu wants to merge 1 commit into
Conversation
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.
Description
This PR addresses and fixes Issue #11286, where loading an incompatible, older architecture LoRA (e.g., Stable Diffusion 1.5) into a newer pipeline (e.g., Stable Diffusion XL) triggers an unhandled
RuntimeError: size mismatchdeep within the tensor operation layers.Instead of allowing the program to mutably inject adapter shells and crash abruptly midway through tensor addition, this fix introduces a proactive, defensive dimension validation step.
Key Changes
_validate_lora_weight_compatibilityhelper insrc/diffusers/utils/peft_utils.py:state_dictkeys (lora_Aandlora_Bweights).model.get_submodule().in_features/in_channelsandndim).PeftAdapterMixin.load_lora_adapter(src/diffusers/loaders/peft.py) before PEFT commits mutations viainject_adapter_in_model.lora_base.pyfor text encoder pathways before executingtext_encoder.load_adapter.ValueErrormapping out the precise architecture discrepancy (e.g., 4D Conv LoRA vs 2D Linear layers, or 768-dim context vs 2048-dim target dimensions) so users instantly recognize version mismatches.Testing
tests/lora/test_lora_layers_sdxl.py:test_load_sd15_lora_into_sdxl_raises_incompatibility_error.state_dictand asserts the exactValueErrorcriteria and error strings.PASSED [100%](Ran locally usingpytest).Fixes #11286