-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds Hyper SDXL LoRA loading for inference using Flax interceptor. --------- Co-authored-by: Juan Acevedo <[email protected]>
- Loading branch information
1 parent
9238bc9
commit 1deeca5
Showing
26 changed files
with
1,441 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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): | ||
# 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.