Conversation
_save_lora passed the denoiser adapter through diffusers' convert_state_dict_to_diffusers(), whose PEFT_TO_DIFFUSERS table only renames to_q/to_k/to_v/to_out.0. Any target outside attention kept its PEFT name, so a wide-target checkpoint was written with two naming schemes in one file. diffusers decides whether to convert back from a single key, guesses wrong on such a file, and silently drops every diffusers-named tensor. Write get_peft_model_state_dict() verbatim instead, matching the controlnet branch five lines above and the final export in trainer.py. convert_diffusers_to_comfyui() emitted .alpha only inside its .lora.down. branch, so it must normalise both spellings before deriving alpha or ComfyUI exports would lose every alpha once checkpoints are PEFT-named.
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.
This pull request makes several important improvements to LoRA (Low-Rank Adaptation) format handling, conversion, and testing. The main focus is on standardizing the naming conventions for LoRA weights, ensuring compatibility between PEFT and Diffusers formats, and adding comprehensive tests to guarantee correct conversions and saves. It also introduces new test utilities and fixes to ensure consistent behavior when saving and loading LoRA weights.
LoRA Format Handling and Conversion:
detect_state_dict_formatwas simplified by removing redundant checks for mixed or ambiguous LoRA naming schemes, making format detection more robust.convert_diffusers_to_comfyuifunction was refactored to consistently map.lora.down.to.lora_A.and.lora.up.to.lora_B., and to ensure that alpha values are attached correctly. Legacy handling for mixed naming conventions was removed.Saving LoRA Weights:
_save_lorawas updated to always use the PEFT naming scheme (i.e.,.lora_A.weightand.lora_B.weight) when saving LoRA weights, instead of converting to the Diffusers format. This prevents mixed or ambiguous naming in saved checkpoints. [1] [2]Testing and Test Utilities:
tests/test_lora_format.py) was added to verify that LoRA format conversions are correct, that both PEFT and Diffusers spellings are handled consistently, and that saved weights maintain their intended structure and can be loaded as expected.tests/test_lora_metadata.pyto facilitate testing of save hooks and ensure that LoRA weights are always written and loaded in a consistent, compatible manner. [1] [2] [3]Regression and Compatibility Tests:
These changes improve reliability and interoperability when training, saving, and loading LoRA weights across different toolkits and workflows.