Skip to content

Commit 22c9f1c

Browse files
authored
Merge pull request #177 from rupeshs/add-hyper-sd-1-step-support
Add Hyper-SD 1 step support
2 parents e3208b8 + f751592 commit 22c9f1c

15 files changed

+223
-142
lines changed

Readme.md

+171-109
Large diffs are not rendered by default.

configs/lcm-lora-models.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
latent-consistency/lcm-lora-sdv1-5
22
latent-consistency/lcm-lora-sdxl
3-
latent-consistency/lcm-lora-ssd-1b
3+
latent-consistency/lcm-lora-ssd-1b
4+
rupeshs/hypersd-sd1-5-1-step-lora

configs/lcm-models.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
stabilityai/sd-turbo
22
rupeshs/sdxs-512-0.9-orig-vae
3+
rupeshs/hyper-sd-sdxl-1-step
34
rupeshs/SDXL-Lightning-2steps
45
stabilityai/sdxl-turbo
56
SimianLuo/LCM_Dreamshaper_v7

configs/openvino-lcm-models.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
rupeshs/sd-turbo-openvino
22
rupeshs/sdxs-512-0.9-openvino
3+
rupeshs/hyper-sd-sdxl-1-step-openvino-int8
34
rupeshs/SDXL-Lightning-2steps-openvino-int8
45
rupeshs/sdxl-turbo-openvino-int8
56
rupeshs/LCM-dreamshaper-v7-openvino
6-
Disty0/LCM_SoteMix
7+
Disty0/LCM_SoteMix

docs/images/fastsdcpu-webui.png

371 KB
Loading

install-mac.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BASEDIR=$(pwd)
2424
$PYTHON_COMMAND -m venv "$BASEDIR/env"
2525
# shellcheck disable=SC1091
2626
source "$BASEDIR/env/bin/activate"
27-
pip install torch==2.2.1
27+
pip install torch==2.2.2
2828
pip install -r "$BASEDIR/requirements.txt"
2929
chmod +x "start.sh"
3030
chmod +x "start-webui.sh"

install.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ for /f "tokens=2" %%I in ('%PYTHON_COMMAND% --version 2^>^&1') do (
2323
echo Python version: %python_version%
2424

2525
%PYTHON_COMMAND% -m venv "%~dp0env"
26-
call "%~dp0env\Scripts\activate.bat" && pip install torch==2.2.1 --index-url https://download.pytorch.org/whl/cpu
26+
call "%~dp0env\Scripts\activate.bat" && pip install torch==2.2.2 --index-url https://download.pytorch.org/whl/cpu
2727
call "%~dp0env\Scripts\activate.bat" && pip install -r "%~dp0requirements.txt"
2828
echo FastSD CPU env installation completed.
2929
pause

install.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BASEDIR=$(pwd)
2424
$PYTHON_COMMAND -m venv "$BASEDIR/env"
2525
# shellcheck disable=SC1091
2626
source "$BASEDIR/env/bin/activate"
27-
pip install torch==2.2.1 --index-url https://download.pytorch.org/whl/cpu
27+
pip install torch==2.2.2 --index-url https://download.pytorch.org/whl/cpu
2828
if [[ "$1" == "--disable-gui" ]]; then
2929
#! For termux , we don't need Qt based GUI
3030
packages="$(grep -v "^ *#\|^PyQt5" requirements.txt | grep .)"
@@ -33,6 +33,7 @@ if [[ "$1" == "--disable-gui" ]]; then
3333
else
3434
pip install -r "$BASEDIR/requirements.txt"
3535
fi
36+
3637
chmod +x "start.sh"
3738
chmod +x "start-webui.sh"
3839
read -n1 -r -p "FastSD CPU installation completed,press any key to continue..." key

requirements.txt

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
accelerate==0.23.0
2-
diffusers==0.23.0
3-
transformers==4.35.0
1+
accelerate==0.29.3
2+
diffusers==0.27.2
3+
transformers==4.39.3
44
PyQt5
55
Pillow==9.4.0
6-
openvino==2023.2.0
7-
optimum==1.14.0
8-
optimum-intel==1.12.1
9-
onnx==1.15.0
10-
onnxruntime==1.16.1
6+
openvino==2024.0.0
7+
optimum-intel==1.16.0
8+
onnx==1.16.0
9+
onnxruntime==1.17.3
1110
pydantic==2.4.2
1211
typing-extensions==4.8.0
1312
pyyaml==6.0.1
14-
gradio==3.39.0
13+
gradio==4.21.0
1514
peft==0.6.1
1615
opencv-python==4.8.1.78
1716
omegaconf==2.3.0

src/backend/controlnet.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
def load_controlnet_adapters(lcm_diffusion_setting) -> dict:
1616
controlnet_args = {}
1717
if (
18-
lcm_diffusion_setting.controlnet == None
19-
or lcm_diffusion_setting.controlnet.enabled == False
18+
lcm_diffusion_setting.controlnet is None
19+
or not lcm_diffusion_setting.controlnet.enabled
2020
):
2121
return controlnet_args
2222

@@ -39,8 +39,8 @@ def load_controlnet_adapters(lcm_diffusion_setting) -> dict:
3939
def update_controlnet_arguments(lcm_diffusion_setting) -> dict:
4040
controlnet_args = {}
4141
if (
42-
lcm_diffusion_setting.controlnet == None
43-
or lcm_diffusion_setting.controlnet.enabled == False
42+
lcm_diffusion_setting.controlnet is None
43+
or not lcm_diffusion_setting.controlnet.enabled
4444
):
4545
return controlnet_args
4646

@@ -61,12 +61,12 @@ def controlnet_settings_from_dict(
6161
lcm_diffusion_setting,
6262
dictionary,
6363
) -> None:
64-
if lcm_diffusion_setting == None or dictionary == None:
64+
if lcm_diffusion_setting is None or dictionary is None:
6565
logging.error("Invalid arguments!")
6666
return
6767
if (
68-
not "controlnet" in dictionary
69-
or dictionary["controlnet"] == None
68+
"controlnet" not in dictionary
69+
or dictionary["controlnet"] is None
7070
or len(dictionary["controlnet"]) == 0
7171
):
7272
logging.warning("ControlNet settings not found, ControlNet will be disabled")
@@ -82,9 +82,9 @@ def controlnet_settings_from_dict(
8282
if controlnet.enabled:
8383
try:
8484
controlnet._control_image = Image.open(image_path)
85-
except (AttributeError, FileNotFoundError) as e:
86-
pass
87-
if controlnet._control_image == None:
85+
except (AttributeError, FileNotFoundError) as err:
86+
print(err)
87+
if controlnet._control_image is None:
8888
logging.error("Wrong ControlNet control image! Disabling ControlNet")
8989
controlnet.enabled = False
9090
lcm_diffusion_setting.controlnet = controlnet

src/backend/lcm_text_to_image.py

+7
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ def init(
254254
adapters = self.pipeline.get_active_adapters()
255255
print(f"Active adapters : {adapters}")
256256

257+
def _get_timesteps(self):
258+
time_steps = self.pipeline.scheduler.config.get("timesteps")
259+
time_steps_value = [int(time_steps)] if time_steps else None
260+
return time_steps_value
261+
257262
def generate(
258263
self,
259264
lcm_diffusion_setting: LCMDiffusionSetting,
@@ -355,8 +360,10 @@ def generate(
355360
width=lcm_diffusion_setting.image_width,
356361
height=lcm_diffusion_setting.image_height,
357362
num_images_per_prompt=lcm_diffusion_setting.number_of_images,
363+
timesteps=self._get_timesteps(),
358364
**controlnet_args,
359365
).images
366+
360367
elif (
361368
lcm_diffusion_setting.diffusion_task
362369
== DiffusionTask.image_to_image.value

src/backend/lora.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import glob
22
from os import path
3-
from paths import get_file_name
3+
from paths import get_file_name, FastStableDiffusionPaths
4+
from pathlib import Path
45

56

67
# A basic class to keep track of the currently loaded LoRAs and
@@ -62,7 +63,8 @@ def load_lora_weight(
6263
if lcm_diffusion_setting.lora.enabled:
6364
print(f"LoRA adapter name : {current_lora.adapter_name}")
6465
pipeline.load_lora_weights(
65-
current_lora.path,
66+
FastStableDiffusionPaths.get_lora_models_path(),
67+
weight_name=Path(lcm_diffusion_setting.lora.path).name,
6668
local_files_only=True,
6769
adapter_name=current_lora.adapter_name,
6870
)

src/backend/pipelines/lcm_lora.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_lcm_lora_pipeline(
3939
lcm_lora_id,
4040
)
4141

42-
if "lcm" in lcm_lora_id.lower():
42+
if "lcm" in lcm_lora_id.lower() or "hypersd" in lcm_lora_id.lower():
4343
print("LCM LoRA model detected so using recommended LCMScheduler")
4444
pipeline.scheduler = LCMScheduler.from_config(pipeline.scheduler.config)
4545

src/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from os import environ
22

3-
APP_VERSION = "v1.0.0 beta 29"
3+
APP_VERSION = "v1.0.0 beta 30"
44
LCM_DEFAULT_MODEL = "stabilityai/sd-turbo"
55
LCM_DEFAULT_MODEL_OPENVINO = "rupeshs/sd-turbo-openvino"
66
APP_NAME = "FastSD CPU"

src/frontend/webui/controlnet_ui.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@ def on_user_input(
1919
control_image: Image,
2020
preprocessor: str,
2121
):
22+
if not isinstance(adapter_name, str):
23+
gr.Warning("Please select a valid ControlNet model")
24+
return gr.Checkbox(value=False)
2225

2326
settings = app_settings.settings.lcm_diffusion_setting
2427
if settings.controlnet is None:
2528
settings.controlnet = ControlNetSetting()
2629

2730
if enable and (adapter_name is None or adapter_name == ""):
2831
gr.Warning("Please select a valid ControlNet adapter")
29-
return gr.Checkbox.update(value=False)
32+
return gr.Checkbox(value=False)
3033
elif enable and not control_image:
3134
gr.Warning("Please provide a ControlNet control image")
32-
return gr.Checkbox.update(value=False)
35+
return gr.Checkbox(value=False)
3336

3437
if control_image is None:
35-
return gr.Checkbox.update(value=enable)
38+
return gr.Checkbox(value=enable)
3639

3740
if preprocessor == "None":
3841
processed_control_image = control_image
@@ -62,7 +65,7 @@ def on_user_input(
6265
settings.rebuild_pipeline = True
6366
_controlnet_enabled = settings.controlnet.enabled
6467
_adapter_path = settings.controlnet.adapter_path
65-
return gr.Checkbox.update(value=enable)
68+
return gr.Checkbox(value=enable)
6669

6770

6871
def on_change_conditioning_scale(cond_scale):
@@ -84,6 +87,10 @@ def get_controlnet_ui() -> None:
8487
_controlnet_models_map = get_lora_models(
8588
app_settings.settings.lcm_diffusion_setting.dirs["controlnet"]
8689
)
90+
controlnet_models = list(_controlnet_models_map.keys())
91+
default_model = (
92+
controlnet_models[0] if len(controlnet_models) else None
93+
)
8794

8895
enabled_checkbox = gr.Checkbox(
8996
label="Enable ControlNet",
@@ -94,7 +101,7 @@ def get_controlnet_ui() -> None:
94101
_controlnet_models_map.keys(),
95102
label="ControlNet model",
96103
info="ControlNet model to load (.safetensors format)",
97-
# value=valid_model,
104+
value=default_model,
98105
interactive=True,
99106
)
100107
conditioning_scale_slider = gr.Slider(

0 commit comments

Comments
 (0)