Skip to content

Commit 63763cb

Browse files
authored
Merge pull request #101 from intel/device_modes
Device modes
2 parents 774381c + 87ea56d commit 63763cb

File tree

4 files changed

+94
-16
lines changed

4 files changed

+94
-16
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This plugin is tested on Ubuntu 22.04. Building GIMP from source is recommended.
3535
For detailed steps and tips please refer to [Linux Installation Guide](./Docs/linux_install_guide.md).
3636

3737
# OpenVINO™ Image Generator Plugin with Stable Diffusion
38+
#### Power Mode is enabled for int8 SD models and systems that has a "NPU" only
3839
#### A. Prompt to Image
3940
1. Create or choose a layer
4041
2. Select Stable Diffusion from the drop down list in layers -> OpenVINO-AI-Plugins
@@ -93,9 +94,12 @@ _With Advanced Setting_
9394

9495
![](gifs/stable-diffusion1.png)
9596

97+
_With Power Mode in Advanced Setting for SD int8 based models_
98+
99+
![](gifs/stable-diffusion2.png)
96100

97101
_Note that the screenshots below are based on the previous UI_
98-
![](gifs/stable-diffusion.webp)
102+
99103

100104

101105
### OpenVINO™ Semantic Segmentation Plugin

gifs/stable-diffusion2.png

39.9 KB
Loading

gimpopenvino/plugins/stable-diffusion-ov/stable-diffusion-ov.py

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,22 @@ def is_server_running():
361361

362362
return False
363363

364-
def async_load_models(python_path, server_path, model_name, supported_devices, dialog):
364+
def async_load_models(python_path, server_path, model_name, supported_devices, device_power_mode,dialog):
365365

366366
device_name = "iGPU"
367367
if "GPU.1" in supported_devices:
368368
device_name = "dGPU"
369369

370+
if "NPU" in supported_devices: # and "GPU.1" not in supported_devices:
371+
if device_power_mode == "Balanced":
372+
device_name = "Balanced_NPU"
373+
if device_power_mode == "Best power efficiency":
374+
device_name = "NPU"
375+
if device_power_mode == "Best Performance" and "GPU.1" in supported_devices:
376+
device_name = "dGPU"
377+
378+
370379

371-
if "NPU" in supported_devices and "GPU.1" not in supported_devices:
372-
device_name = "NPU"
373380

374381
try:
375382
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -463,7 +470,12 @@ def run(procedure, run_mode, image, n_drawables, layer, args, data):
463470
list_models(config_path_output["weight_path"],"controlnet_scribble") +
464471
list_models(config_path_output["weight_path"],"controlnet_scribble_int8"))
465472

466-
model_name_enum = DeviceEnum(model_list)
473+
model_name_enum = DeviceEnum(model_list)
474+
if "NPU" in supported_devices:
475+
supported_modes = ["Best power efficiency", "Balanced", "Best performance"]
476+
else:
477+
supported_modes = ["Best performance"]
478+
device_name_enum = DeviceEnum(supported_modes)
467479

468480
config = procedure.create_config()
469481
config.begin_run(image, run_mode, args)
@@ -560,6 +572,12 @@ def run(procedure, run_mode, image, n_drawables, layer, args, data):
560572

561573
seed_text = _("Seed")
562574
seed_label = Gtk.Label(label=seed_text)
575+
576+
577+
adv_power_mode_label = Gtk.Label.new_with_mnemonic(_("_Power Mode"))
578+
adv_power_mode_combo = GimpUi.prop_string_combo_box_new(
579+
config, "power_mode", device_name_enum.get_tree_model(), 0, 1
580+
)
563581

564582

565583
adv_checkbox = GimpUi.prop_check_button_new(config, "advanced_setting",
@@ -609,6 +627,11 @@ def remove_all_advanced_widgets():
609627
grid.remove(seed_label)
610628
seed_label.hide()
611629

630+
grid.remove(adv_power_mode_label)
631+
adv_power_mode_label.hide()
632+
grid.remove(adv_power_mode_combo)
633+
adv_power_mode_combo.hide()
634+
612635
invisible_label4.show()
613636
invisible_label5.show()
614637
invisible_label6.show()
@@ -626,6 +649,15 @@ def populate_advanced_settings():
626649
grid.attach(gscale_spin, 1, 5, 1, 1)
627650
grid.attach(seed, 1, 6, 1, 1)
628651
grid.attach(seed_label, 0, 6, 1, 1)
652+
model_name = config.get_property("model_name")
653+
if "int8" in model_name:
654+
grid.attach(adv_power_mode_label, 0, 7, 1, 1)
655+
grid.attach(adv_power_mode_combo, 1, 7, 1, 1)
656+
adv_power_mode_label.show()
657+
adv_power_mode_combo.show()
658+
659+
660+
629661
steps_label.show()
630662
steps_spin.show()
631663
gscale_label.show()
@@ -789,6 +821,7 @@ def initImage_toggled(widget):
789821

790822

791823
model_name = config.get_property("model_name")
824+
device_power_mode = None
792825

793826
if model_name == "SD_1.5_square_lcm":
794827
negative_prompt_label.hide()
@@ -798,6 +831,16 @@ def initImage_toggled(widget):
798831

799832
if is_server_running():
800833
run_button.set_sensitive(True)
834+
if adv_checkbox.get_active():
835+
if "int8" in model_name:
836+
device_power_mode = config.get_property("power_mode")
837+
else:
838+
device_power_mode = None
839+
840+
841+
else:
842+
device_power_mode = None
843+
801844

802845

803846

@@ -806,6 +849,7 @@ def initImage_toggled(widget):
806849
# if model / devices are changed from what is currently loaded.
807850
def model_sensitive_combo_changed(widget):
808851
model_name_tmp = config.get_property("model_name")
852+
device_power_mode_tmp = None
809853

810854
# LCM model has no negative prompt
811855
if model_name_tmp == "SD_1.5_square_lcm":
@@ -822,10 +866,19 @@ def model_sensitive_combo_changed(widget):
822866
else:
823867
initialImage_checkbox.set_active(False)
824868

869+
if adv_checkbox.get_active():
870+
if "int8" in model_name:
871+
device_power_mode_tmp = config.get_property("power_mode")
872+
873+
else:
874+
device_power_mode_tmp = None
875+
876+
825877

826878

827879

828-
if (model_name_tmp==model_name):
880+
if (model_name_tmp==model_name and
881+
device_power_mode_tmp==device_power_mode):
829882
run_button.set_sensitive(True)
830883
else:
831884
run_button.set_sensitive(False)
@@ -838,10 +891,8 @@ def model_combo_changed(widget):
838891

839892
model_combo.connect("changed", model_combo_changed)
840893
model_combo.connect("changed", model_sensitive_combo_changed)
841-
842-
843-
844894
adv_checkbox.connect("toggled", model_sensitive_combo_changed)
895+
adv_power_mode_combo.connect("changed", model_sensitive_combo_changed)
845896

846897

847898

@@ -864,9 +915,7 @@ def model_combo_changed(widget):
864915
#adv_checkbox.set_sensitive(False)
865916
prompt = prompt_text.get_text()
866917
negative_prompt = negative_prompt_text.get_text()
867-
868-
869-
918+
870919

871920
if adv_checkbox.get_active():
872921

@@ -891,8 +940,6 @@ def model_combo_changed(widget):
891940

892941

893942

894-
895-
896943
if initialImage_checkbox.get_active() and n_layers == 1:
897944
if len(file_entry.get_text()) != 0:
898945
initial_image = file_entry.get_text()
@@ -931,12 +978,28 @@ def model_combo_changed(widget):
931978

932979
model_name = config.get_property("model_name")
933980

981+
if adv_checkbox.get_active():
982+
983+
if "int8" in model_name:
984+
device_power_mode = config.get_property("power_mode")
985+
986+
else:
987+
device_power_mode = None
988+
989+
else:
990+
991+
if "int8" in model_name:
992+
device_power_mode = "Best performance"
993+
994+
else:
995+
device_power_mode = None
996+
934997

935998
server = "stable-diffusion-ov-server.py"
936999
server_path = os.path.join(config_path, server)
9371000

9381001

939-
run_load_model_thread = threading.Thread(target=async_load_models, args=(python_path, server_path, model_name,supported_devices, dialog))
1002+
run_load_model_thread = threading.Thread(target=async_load_models, args=(python_path, server_path, model_name,supported_devices, device_power_mode,dialog))
9401003
run_load_model_thread.start()
9411004

9421005
continue
@@ -1020,6 +1083,14 @@ class StableDiffusion(Gimp.PlugIn):
10201083
False,
10211084
GObject.ParamFlags.READWRITE,
10221085
),
1086+
1087+
"power_mode": (
1088+
str,
1089+
_("Power Mode"),
1090+
"Power Mode: 'Balanced', 'Best performance'",
1091+
"Best performance",
1092+
GObject.ParamFlags.READWRITE,
1093+
),
10231094

10241095
"use_initial_image": (
10251096
bool,
@@ -1075,6 +1146,7 @@ def do_create_procedure(self, name):
10751146
procedure.add_argument_from_property(self, "model_name")
10761147

10771148
procedure.add_argument_from_property(self, "advanced_setting")
1149+
procedure.add_argument_from_property(self, "power_mode")
10781150

10791151
procedure.add_argument_from_property(self, "use_initial_image")
10801152

gimpopenvino/tools/stable-diffusion-ov-server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ def run(model_name,device_name):
133133
device = ["CPU","GPU.1","GPU.1"]
134134
device_int8 = ["CPU","GPU.1","GPU.1","GPU.1"]
135135

136-
if device_name == "NPU":
136+
if device_name == "Balanced_NPU":
137137
device_int8 = ["CPU","GPU","NPU","GPU"]
138+
if device_name == "NPU":
139+
device_int8 = ["CPU","NPU","NPU","GPU"]
138140

139141

140142
if model_name == "SD_1.5_square_int8":

0 commit comments

Comments
 (0)