-
Notifications
You must be signed in to change notification settings - Fork 70
Hyper SDXL Lora support #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d706152
lora wip - skelleton
jfacevedo-google 6cd91c3
Merge branch 'main' into lora_support
jfacevedo-google f02a372
add lora layers to sd models.
jfacevedo-google b73222f
prototype lora with flax interceptors.
jfacevedo-google d161485
clean up uneeded layers.
jfacevedo-google 14ed2ee
lora wip - todo - conv layer issue.
jfacevedo-google 7db33b4
load lora params
jfacevedo-google db76c7c
attempt to inject lora layers for text encoders.
jfacevedo-google df11714
load network_alphas from lora ckpt.
jfacevedo-google 5b8f660
Merge branch 'main' into lora_support
jfacevedo-google 1aae85d
load lora from config.
jfacevedo-google cf669c4
update generate code to support hypersdxl lora.
jfacevedo-google cc2514c
create and fix unit tests + formatter.
jfacevedo-google 4e40024
Merge branch 'main' into lora_support
jfacevedo-google 1413e86
fix linting errors.
jfacevedo-google 829b9ca
Merge branch 'main' into lora_support
jfacevedo-google File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Binary file not shown.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Copyright 2023 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from .lora_pipeline import StableDiffusionLoraLoaderMixin |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # Copyright 2023 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from ..models.modeling_utils import load_state_dict | ||
| from ..utils import _get_model_file | ||
|
|
||
| import safetensors | ||
|
|
||
|
|
||
| class LoRABaseMixin: | ||
| """Utility class for handing LoRAs""" | ||
|
|
||
| _lora_lodable_modules = [] | ||
| num_fused_loras = 0 | ||
|
|
||
| def load_lora_weights(self, **kwargs): | ||
| raise NotImplementedError("`load_lora_weights()` is not implemented.") | ||
|
|
||
| @classmethod | ||
| def _fetch_state_dict( | ||
| cls, | ||
| pretrained_model_name_or_path_or_dict, | ||
| weight_name, | ||
| use_safetensors, | ||
| local_files_only, | ||
| cache_dir, | ||
| force_download, | ||
| resume_download, | ||
| proxies, | ||
| use_auth_token, | ||
| revision, | ||
| subfolder, | ||
| user_agent, | ||
| allow_pickle, | ||
| ): | ||
| from .lora_pipeline import LORA_WEIGHT_NAME_SAFE | ||
|
|
||
| model_file = None | ||
| if not isinstance(pretrained_model_name_or_path_or_dict, dict): | ||
|
anfals marked this conversation as resolved.
|
||
| # Let's first try to load .safetensors weights | ||
| if (use_safetensors and weight_name is None) or (weight_name is not None and weight_name.endswith(".safetensors")): | ||
| try: | ||
| # Here we're relaxing the loading check to enable more Inference API | ||
| # friendliness where sometimes, it's not at all possible to automatically | ||
| # determine `weight_name`. | ||
| if weight_name is None: | ||
| weight_name = cls._best_guess_weight_name( | ||
| pretrained_model_name_or_path_or_dict, | ||
| file_extension=".safetensors", | ||
| local_files_only=local_files_only, | ||
| ) | ||
| model_file = _get_model_file( | ||
| pretrained_model_name_or_path_or_dict, | ||
| weights_name=weight_name or LORA_WEIGHT_NAME_SAFE, | ||
| cache_dir=cache_dir, | ||
| force_download=force_download, | ||
| resume_download=resume_download, | ||
| proxies=proxies, | ||
| local_files_only=local_files_only, | ||
| use_auth_token=use_auth_token, | ||
| revision=revision, | ||
| subfolder=subfolder, | ||
| user_agent=user_agent, | ||
| ) | ||
| state_dict = safetensors.torch.load_file(model_file, device="cpu") | ||
| except (IOError, safetensors.SafetensorError) as e: | ||
| if not allow_pickle: | ||
| raise e | ||
| # try loading non-safetensors weights | ||
| model_file = None | ||
| pass | ||
|
|
||
| if model_file is None: | ||
| if weight_name is None: | ||
| weight_name = cls._best_guess_weight_name( | ||
| pretrained_model_name_or_path_or_dict, file_extension=".bin", local_files_only=local_files_only | ||
| ) | ||
| model_file = _get_model_file( | ||
| pretrained_model_name_or_path_or_dict, | ||
| weights_name=weight_name or LORA_WEIGHT_NAME_SAFE, | ||
| cache_dir=cache_dir, | ||
| force_download=force_download, | ||
| resume_download=resume_download, | ||
| proxies=proxies, | ||
| local_files_only=local_files_only, | ||
| use_auth_token=use_auth_token, | ||
| revision=revision, | ||
| subfolder=subfolder, | ||
| user_agent=user_agent, | ||
| ) | ||
| state_dict = load_state_dict(model_file) | ||
| else: | ||
| state_dict = pretrained_model_name_or_path_or_dict | ||
|
|
||
| return state_dict | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeated line?