auto-diffusers 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- auto_diffusers-1.0.0/LICENSE +28 -0
- auto_diffusers-1.0.0/PKG-INFO +107 -0
- auto_diffusers-1.0.0/README.md +77 -0
- auto_diffusers-1.0.0/setup.cfg +4 -0
- auto_diffusers-1.0.0/setup.py +47 -0
- auto_diffusers-1.0.0/src/auto_diffusers/__init__.py +6 -0
- auto_diffusers-1.0.0/src/auto_diffusers/checker/__init__.py +1 -0
- auto_diffusers-1.0.0/src/auto_diffusers/checker/get_checkpoint_type.py +139 -0
- auto_diffusers-1.0.0/src/auto_diffusers/checker/memorize_config.py +80 -0
- auto_diffusers-1.0.0/src/auto_diffusers/model_path/Perform_path_search.py +228 -0
- auto_diffusers-1.0.0/src/auto_diffusers/model_path/__init__.py +7 -0
- auto_diffusers-1.0.0/src/auto_diffusers/model_path/create_pipeline.py +253 -0
- auto_diffusers-1.0.0/src/auto_diffusers/model_path/flax_config.py +70 -0
- auto_diffusers-1.0.0/src/auto_diffusers/model_path/mix_class.py +15 -0
- auto_diffusers-1.0.0/src/auto_diffusers/model_path/search_civitai.py +385 -0
- auto_diffusers-1.0.0/src/auto_diffusers/model_path/search_hugface.py +418 -0
- auto_diffusers-1.0.0/src/auto_diffusers/py.typed +1 -0
- auto_diffusers-1.0.0/src/auto_diffusers/setup/Base_config.py +213 -0
- auto_diffusers-1.0.0/src/auto_diffusers/setup/__init__.py +1 -0
- auto_diffusers-1.0.0/src/auto_diffusers/setup/data_class.py +130 -0
- auto_diffusers-1.0.0/src/auto_diffusers/setup/device_config.py +42 -0
- auto_diffusers-1.0.0/src/auto_diffusers/setup/runtime_config.py +49 -0
- auto_diffusers-1.0.0/src/auto_diffusers/utils/__init__.py +1 -0
- auto_diffusers-1.0.0/src/auto_diffusers/utils/device_config.py +40 -0
- auto_diffusers-1.0.0/src/auto_diffusers/utils/get_custom_logger.py +22 -0
- auto_diffusers-1.0.0/src/auto_diffusers/utils/hide_warning.py +8 -0
- auto_diffusers-1.0.0/src/auto_diffusers/utils/process_bar.py +173 -0
- auto_diffusers-1.0.0/src/auto_diffusers/utils/run_download.py +140 -0
- auto_diffusers-1.0.0/src/auto_diffusers.egg-info/PKG-INFO +107 -0
- auto_diffusers-1.0.0/src/auto_diffusers.egg-info/SOURCES.txt +31 -0
- auto_diffusers-1.0.0/src/auto_diffusers.egg-info/dependency_links.txt +1 -0
- auto_diffusers-1.0.0/src/auto_diffusers.egg-info/requires.txt +7 -0
- auto_diffusers-1.0.0/src/auto_diffusers.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, suzukimain
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: auto_diffusers
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Model search functionality using hugface API and civitai API, etc.
|
|
5
|
+
Home-page: https://github.com/suzukimain/auto_diffusers
|
|
6
|
+
Author: suzukimain
|
|
7
|
+
Author-email: subarucosmosmain@gmail.com
|
|
8
|
+
License: BSD 3-Clause License
|
|
9
|
+
Keywords: Added the ability to search models and more to diffusers
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Education
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: diffusers
|
|
24
|
+
Requires-Dist: transformers
|
|
25
|
+
Requires-Dist: huggingface-hub
|
|
26
|
+
Requires-Dist: requests
|
|
27
|
+
Requires-Dist: torch
|
|
28
|
+
Requires-Dist: jax
|
|
29
|
+
Requires-Dist: natsort
|
|
30
|
+
|
|
31
|
+
# auto_diffusers
|
|
32
|
+
|
|
33
|
+
[](
|
|
34
|
+
https://github.com/suzukimain/auto_diffusers/blob/main/LICENSE)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
<div>
|
|
38
|
+
<img src=https://visit-counter.vercel.app/counter.png?page=https://github.com/suzukimain/auto_diffusers/main&c=00ffff&ff=flat&tb=viewer:%20&s=20>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
>CONTENTS
|
|
43
|
+
+ [About The Project](#About_The_Project)
|
|
44
|
+
+ [How to use](#How_to_use)
|
|
45
|
+
+ [Description](#Description)
|
|
46
|
+
+ [License](#License)
|
|
47
|
+
+ [Acknowledgement](#Acknowledgement)
|
|
48
|
+
|
|
49
|
+
## About The Project<a name = "About_The_Project"></a>
|
|
50
|
+
Enhance the functionality of diffusers.
|
|
51
|
+
* Search models from huggingface and Civitai.
|
|
52
|
+
(etc..)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## How to use<a name = "How_to_use"></a>
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
pip install diffusers
|
|
59
|
+
pip install git+https://github.com/suzukimain/auto_diffusers
|
|
60
|
+
|
|
61
|
+
from diffusers import StableDiffusionPipeline
|
|
62
|
+
from auto_diffusers import run_search
|
|
63
|
+
|
|
64
|
+
model_path = run_search(<keyword>, auto=True, download=False)
|
|
65
|
+
pipe = StableDIffusionPipeline.from_single_file(model_path)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Description<a name = "Description"></a>
|
|
69
|
+
> Arguments of `run_ search`
|
|
70
|
+
>
|
|
71
|
+
| Name | Type | Default | Input Available | Description |
|
|
72
|
+
|:--------------:|:------:|:-----------:|:----------------:|:--------------------------------------------------------:|
|
|
73
|
+
| search_word | string | ー | [Details](#search-word) | Keywords to search models |
|
|
74
|
+
| auto | bool | True | ー | Minimize user input by selecting the highest-rated models. |
|
|
75
|
+
| download | bool | False | ー | Returns the path where the file was downloaded. |
|
|
76
|
+
| model_type | string | "Checkpoint"| 1. `Checkpoint`<br>2. `TextualInversion`<br>3. `Hypernetwork`<br>4. `AestheticGradient`<br>5. `LORA`<br>6. `Controlnet`<br>7. `Poses` | Valid only in Civitai. |
|
|
77
|
+
| return_path | bool | True | ー | Returns only the path or `[model_path, status_dict]`. |
|
|
78
|
+
| branch | string | "main" | ー | Specify the branches of huggingface and civitai. |
|
|
79
|
+
| local_file_only| bool | False | ー | Search local folders only. |
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
<a id="search-word"></a>
|
|
83
|
+
<details open>
|
|
84
|
+
<summary>search_word</summary>
|
|
85
|
+
|
|
86
|
+
| Type | Description |
|
|
87
|
+
| :--------------------------: | :--------------------------------------------------------------------: |
|
|
88
|
+
| keyword | Keywords to search model<br> |
|
|
89
|
+
| url | Can be any URL other than huggingface or Civitai. |
|
|
90
|
+
| Local directory or file path | Search for files with the extensions: `.safetensors`, `.ckpt`, `.bin` |
|
|
91
|
+
| huggingface path | The following format: `< creator > / < repo >` |
|
|
92
|
+
|
|
93
|
+
</details>
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## License<a name = "License"></a>
|
|
97
|
+
In accordance with [BSD-3-Clause license](LICENSE)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## Acknowledgement<a name = "Acknowledgement"></a>
|
|
102
|
+
|
|
103
|
+
I have used open source resources and free tools in the creation of this project.
|
|
104
|
+
|
|
105
|
+
I would like to take this opportunity to thank the open source community and those who provided free tools.
|
|
106
|
+
|
|
107
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# auto_diffusers
|
|
2
|
+
|
|
3
|
+
[](
|
|
4
|
+
https://github.com/suzukimain/auto_diffusers/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
<div>
|
|
8
|
+
<img src=https://visit-counter.vercel.app/counter.png?page=https://github.com/suzukimain/auto_diffusers/main&c=00ffff&ff=flat&tb=viewer:%20&s=20>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
>CONTENTS
|
|
13
|
+
+ [About The Project](#About_The_Project)
|
|
14
|
+
+ [How to use](#How_to_use)
|
|
15
|
+
+ [Description](#Description)
|
|
16
|
+
+ [License](#License)
|
|
17
|
+
+ [Acknowledgement](#Acknowledgement)
|
|
18
|
+
|
|
19
|
+
## About The Project<a name = "About_The_Project"></a>
|
|
20
|
+
Enhance the functionality of diffusers.
|
|
21
|
+
* Search models from huggingface and Civitai.
|
|
22
|
+
(etc..)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## How to use<a name = "How_to_use"></a>
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
pip install diffusers
|
|
29
|
+
pip install git+https://github.com/suzukimain/auto_diffusers
|
|
30
|
+
|
|
31
|
+
from diffusers import StableDiffusionPipeline
|
|
32
|
+
from auto_diffusers import run_search
|
|
33
|
+
|
|
34
|
+
model_path = run_search(<keyword>, auto=True, download=False)
|
|
35
|
+
pipe = StableDIffusionPipeline.from_single_file(model_path)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Description<a name = "Description"></a>
|
|
39
|
+
> Arguments of `run_ search`
|
|
40
|
+
>
|
|
41
|
+
| Name | Type | Default | Input Available | Description |
|
|
42
|
+
|:--------------:|:------:|:-----------:|:----------------:|:--------------------------------------------------------:|
|
|
43
|
+
| search_word | string | ー | [Details](#search-word) | Keywords to search models |
|
|
44
|
+
| auto | bool | True | ー | Minimize user input by selecting the highest-rated models. |
|
|
45
|
+
| download | bool | False | ー | Returns the path where the file was downloaded. |
|
|
46
|
+
| model_type | string | "Checkpoint"| 1. `Checkpoint`<br>2. `TextualInversion`<br>3. `Hypernetwork`<br>4. `AestheticGradient`<br>5. `LORA`<br>6. `Controlnet`<br>7. `Poses` | Valid only in Civitai. |
|
|
47
|
+
| return_path | bool | True | ー | Returns only the path or `[model_path, status_dict]`. |
|
|
48
|
+
| branch | string | "main" | ー | Specify the branches of huggingface and civitai. |
|
|
49
|
+
| local_file_only| bool | False | ー | Search local folders only. |
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
<a id="search-word"></a>
|
|
53
|
+
<details open>
|
|
54
|
+
<summary>search_word</summary>
|
|
55
|
+
|
|
56
|
+
| Type | Description |
|
|
57
|
+
| :--------------------------: | :--------------------------------------------------------------------: |
|
|
58
|
+
| keyword | Keywords to search model<br> |
|
|
59
|
+
| url | Can be any URL other than huggingface or Civitai. |
|
|
60
|
+
| Local directory or file path | Search for files with the extensions: `.safetensors`, `.ckpt`, `.bin` |
|
|
61
|
+
| huggingface path | The following format: `< creator > / < repo >` |
|
|
62
|
+
|
|
63
|
+
</details>
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## License<a name = "License"></a>
|
|
67
|
+
In accordance with [BSD-3-Clause license](LICENSE)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## Acknowledgement<a name = "Acknowledgement"></a>
|
|
72
|
+
|
|
73
|
+
I have used open source resources and free tools in the creation of this project.
|
|
74
|
+
|
|
75
|
+
I would like to take this opportunity to thank the open source community and those who provided free tools.
|
|
76
|
+
|
|
77
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from setuptools import find_packages, setup
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
with open("./requirements.txt", "r", encoding="utf-8") as _file:
|
|
9
|
+
_deps = _file.read().splitlines()
|
|
10
|
+
|
|
11
|
+
deps = {b: a for a, b in (re.findall(r"^(([^!=<>~]+)(?:[!=<>~].*)?$)", x)[0] for x in _deps)}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def deps_list(*pkgs):
|
|
15
|
+
return [deps[pkg] for pkg in pkgs]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
version_range_max = max(sys.version_info[1], 10) + 1
|
|
19
|
+
|
|
20
|
+
setup(
|
|
21
|
+
name="auto_diffusers",
|
|
22
|
+
version="1.0.0",
|
|
23
|
+
description="Model search functionality using hugface API and civitai API, etc.",
|
|
24
|
+
long_description=open("README.md", "r", encoding="utf-8").read(),
|
|
25
|
+
long_description_content_type="text/markdown",
|
|
26
|
+
keywords="Added the ability to search models and more to diffusers",
|
|
27
|
+
license="BSD 3-Clause License",
|
|
28
|
+
author="suzukimain",
|
|
29
|
+
author_email="subarucosmosmain@gmail.com",
|
|
30
|
+
url="https://github.com/suzukimain/auto_diffusers",
|
|
31
|
+
package_dir={"": "src"},
|
|
32
|
+
packages=find_packages("src"),
|
|
33
|
+
package_data={"": ["py.typed"]},
|
|
34
|
+
include_package_data=True,
|
|
35
|
+
install_requires=list(_deps),
|
|
36
|
+
classifiers=[
|
|
37
|
+
"Development Status :: 5 - Production/Stable",
|
|
38
|
+
"Intended Audience :: Developers",
|
|
39
|
+
"Intended Audience :: Education",
|
|
40
|
+
"Intended Audience :: Science/Research",
|
|
41
|
+
"License :: OSI Approved :: Apache Software License",
|
|
42
|
+
"Operating System :: OS Independent",
|
|
43
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
44
|
+
"Programming Language :: Python :: 3",
|
|
45
|
+
]
|
|
46
|
+
+ [f"Programming Language :: Python :: 3.{i}" for i in range(8, version_range_max)]
|
|
47
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .memorize_config import config_check
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import torch
|
|
3
|
+
import requests
|
|
4
|
+
import yaml
|
|
5
|
+
from io import BytesIO
|
|
6
|
+
|
|
7
|
+
from ..setup.Base_config import Basic_config
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class checkpoint_type(Basic_config):
|
|
11
|
+
def __init__(self):
|
|
12
|
+
super().__init__()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def checkpoint_type_get(
|
|
16
|
+
self,
|
|
17
|
+
checkpoint_path_or_dict,
|
|
18
|
+
config_files = None,
|
|
19
|
+
original_config_file = None,
|
|
20
|
+
model_type = None,
|
|
21
|
+
is_upscale = False
|
|
22
|
+
):
|
|
23
|
+
"""
|
|
24
|
+
NOTE:
|
|
25
|
+
Return SD if you do not know, because an error may occur if None is used.
|
|
26
|
+
|
|
27
|
+
About model_type:
|
|
28
|
+
The model_type itself will be left for possible use at some point.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from_safetensors = False
|
|
32
|
+
checkpoint = None
|
|
33
|
+
if isinstance(checkpoint_path_or_dict, str):
|
|
34
|
+
if os.path.isfile(checkpoint_path_or_dict):
|
|
35
|
+
from_safetensors: bool = self.check_for_safetensors(checkpoint_path_or_dict)
|
|
36
|
+
if from_safetensors:
|
|
37
|
+
from safetensors.torch import load_file as safe_load
|
|
38
|
+
checkpoint = safe_load(checkpoint_path_or_dict, device=self.device)
|
|
39
|
+
else:
|
|
40
|
+
checkpoint = torch.load(checkpoint_path_or_dict, map_location=self.device)
|
|
41
|
+
elif os.path.isdir(checkpoint_path_or_dict):
|
|
42
|
+
model_index_path = os.path.join(checkpoint_path_or_dict,"model_index.json")
|
|
43
|
+
if os.path.isfile(model_index_path):
|
|
44
|
+
with open(model_index_path,"r") as loaded_model_index:
|
|
45
|
+
cls_name = loaded_model_index["_class_name"]
|
|
46
|
+
#Fixed in due course.
|
|
47
|
+
if "XL" in cls_name:
|
|
48
|
+
return "SDXL"
|
|
49
|
+
else:
|
|
50
|
+
return "SD"
|
|
51
|
+
|
|
52
|
+
elif isinstance(checkpoint_path_or_dict, dict):
|
|
53
|
+
checkpoint = checkpoint_path_or_dict
|
|
54
|
+
else:
|
|
55
|
+
raise TypeError(f"checkpoint_path_or_dict: {checkpoint_path_or_dict}")
|
|
56
|
+
|
|
57
|
+
if "global_step" in checkpoint:
|
|
58
|
+
global_step = checkpoint["global_step"]
|
|
59
|
+
else:
|
|
60
|
+
global_step = None
|
|
61
|
+
|
|
62
|
+
while "state_dict" in checkpoint:
|
|
63
|
+
checkpoint = checkpoint["state_dict"]
|
|
64
|
+
if original_config_file is None:
|
|
65
|
+
key_name_v2_1 = "model.diffusion_model.input_blocks.2.1.transformer_blocks.0.attn2.to_k.weight"
|
|
66
|
+
key_name_sd_xl_base = "conditioner.embedders.1.model.transformer.resblocks.9.mlp.c_proj.bias"
|
|
67
|
+
key_name_sd_xl_refiner = "conditioner.embedders.0.model.transformer.resblocks.9.mlp.c_proj.bias"
|
|
68
|
+
#is_upscale = pipeline_class == StableDiffusionUpscalePipeline
|
|
69
|
+
config_url = None
|
|
70
|
+
# model_type = "v1"
|
|
71
|
+
if config_files is not None and "v1" in config_files:
|
|
72
|
+
original_config_file = config_files["v1"]
|
|
73
|
+
else:
|
|
74
|
+
config_url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
|
|
75
|
+
|
|
76
|
+
if key_name_v2_1 in checkpoint and checkpoint[key_name_v2_1].shape[-1] == 1024:
|
|
77
|
+
# model_type = "v2"
|
|
78
|
+
if config_files is not None and "v2" in config_files:
|
|
79
|
+
original_config_file = config_files["v2"]
|
|
80
|
+
else:
|
|
81
|
+
config_url = "https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference-v.yaml"
|
|
82
|
+
if global_step == 110000:
|
|
83
|
+
# v2.1 needs to upcast attention
|
|
84
|
+
upcast_attention = True
|
|
85
|
+
|
|
86
|
+
elif key_name_sd_xl_base in checkpoint:
|
|
87
|
+
# only base xl has two text embedders
|
|
88
|
+
if config_files is not None and "xl" in config_files:
|
|
89
|
+
original_config_file = config_files["xl"]
|
|
90
|
+
else:
|
|
91
|
+
config_url = "https://raw.githubusercontent.com/Stability-AI/generative-models/main/configs/inference/sd_xl_base.yaml"
|
|
92
|
+
|
|
93
|
+
elif key_name_sd_xl_refiner in checkpoint:
|
|
94
|
+
# only refiner xl has embedder and one text embedders
|
|
95
|
+
if config_files is not None and "xl_refiner" in config_files:
|
|
96
|
+
original_config_file = config_files["xl_refiner"]
|
|
97
|
+
else:
|
|
98
|
+
config_url = "https://raw.githubusercontent.com/Stability-AI/generative-models/main/configs/inference/sd_xl_refiner.yaml"
|
|
99
|
+
|
|
100
|
+
if is_upscale:
|
|
101
|
+
config_url = "https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/x4-upscaling.yaml"
|
|
102
|
+
|
|
103
|
+
if config_url is not None:
|
|
104
|
+
try:
|
|
105
|
+
original_config_file = BytesIO(requests.get(config_url).content)
|
|
106
|
+
except:
|
|
107
|
+
self.logger.error(f"Could not download the Config_file to find out the model type from the following URL: {config_url}")
|
|
108
|
+
if model_type is None:
|
|
109
|
+
self.logger.warning("model_type is set to None")
|
|
110
|
+
return model_type
|
|
111
|
+
else:
|
|
112
|
+
with open(original_config_file, "r") as f:
|
|
113
|
+
original_config_file = f.read()
|
|
114
|
+
else:
|
|
115
|
+
with open(original_config_file, "r") as f:
|
|
116
|
+
original_config_file = f.read()
|
|
117
|
+
|
|
118
|
+
original_config = yaml.safe_load(original_config_file)
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
model_type is None
|
|
122
|
+
and "cond_stage_config" in original_config["model"]["params"]
|
|
123
|
+
and original_config["model"]["params"]["cond_stage_config"] is not None
|
|
124
|
+
):
|
|
125
|
+
|
|
126
|
+
model_type = original_config["model"]["params"]["cond_stage_config"]["target"].split(".")[-1]
|
|
127
|
+
return "SD"
|
|
128
|
+
|
|
129
|
+
elif model_type is None and original_config["model"]["params"]["network_config"] is not None:
|
|
130
|
+
if original_config["model"]["params"]["network_config"]["params"]["context_dim"] == 2048:
|
|
131
|
+
model_type = "SDXL"
|
|
132
|
+
else:
|
|
133
|
+
model_type = "SDXL-Refiner"
|
|
134
|
+
return "SDXL"
|
|
135
|
+
|
|
136
|
+
else:
|
|
137
|
+
if model_type is None:
|
|
138
|
+
self.logger.warning("model_type is set to None")
|
|
139
|
+
return model_type
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class config_check:
|
|
6
|
+
base_config_json = "/tmp/auto_diffusers_config.json"
|
|
7
|
+
def __init__(self):
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_json_dict(self):
|
|
12
|
+
"""Retrieve the JSON dictionary from the config file."""
|
|
13
|
+
config_dict = {}
|
|
14
|
+
if os.path.isfile(self.base_config_json):
|
|
15
|
+
try:
|
|
16
|
+
with open(self.base_config_json, "r") as basic_json:
|
|
17
|
+
config_dict = json.load(basic_json)
|
|
18
|
+
except json.JSONDecodeError:
|
|
19
|
+
pass
|
|
20
|
+
return config_dict
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def update_json_dict(self, key, value):
|
|
24
|
+
"""Update the JSON dictionary with a new key-value pair."""
|
|
25
|
+
basic_json_dict = self.get_json_dict()
|
|
26
|
+
basic_json_dict[key] = value
|
|
27
|
+
with open(self.base_config_json, "w") as json_file:
|
|
28
|
+
json.dump(basic_json_dict, json_file, indent=4)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def check_func_hist(self,*return_key, **kwargs):
|
|
32
|
+
"""
|
|
33
|
+
Check and optionally update the history of a given element.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
*return_key (str): Variable for which to get the history.
|
|
37
|
+
**kwargs: Keyword arguments for additional options.
|
|
38
|
+
- update (bool): Whether to update the dictionary. Default is True.
|
|
39
|
+
- return_value (bool): Whether to return the element value. Default is False.
|
|
40
|
+
- key (str): Specific key to look up in the dictionary.
|
|
41
|
+
- value (Any): Value to be matched or updated in the dictionary.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
Any: The historical value if `return_value` is True, or a boolean indicating
|
|
45
|
+
if the value matches the historical value.
|
|
46
|
+
"""
|
|
47
|
+
update = kwargs.pop("update", True)
|
|
48
|
+
return_value = kwargs.pop("return_value", False)
|
|
49
|
+
if kwargs:
|
|
50
|
+
if "key" in kwargs:
|
|
51
|
+
key = kwargs["key"]
|
|
52
|
+
if "value" in kwargs:
|
|
53
|
+
value = kwargs["value"]
|
|
54
|
+
else:
|
|
55
|
+
value = None
|
|
56
|
+
update = False
|
|
57
|
+
return_value = True
|
|
58
|
+
else:
|
|
59
|
+
key, value = next(iter(kwargs.items()))
|
|
60
|
+
elif return_key:
|
|
61
|
+
key, value = return_key[0], None
|
|
62
|
+
update = False
|
|
63
|
+
return_value = True
|
|
64
|
+
else:
|
|
65
|
+
raise TypeError("Missing 'key' argument.")
|
|
66
|
+
|
|
67
|
+
basic_json_dict = self.get_json_dict()
|
|
68
|
+
hist_value = basic_json_dict.get(key)
|
|
69
|
+
if hist_value == value:
|
|
70
|
+
value_match = True
|
|
71
|
+
else:
|
|
72
|
+
value_match = False
|
|
73
|
+
|
|
74
|
+
if update:
|
|
75
|
+
self.update_json_dict(key, value)
|
|
76
|
+
|
|
77
|
+
if return_value:
|
|
78
|
+
return hist_value
|
|
79
|
+
else:
|
|
80
|
+
return value_match
|