@@ -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 ()
@@ -838,10 +870,8 @@ def model_combo_changed(widget):
838870
839871 model_combo .connect ("changed" , model_combo_changed )
840872 model_combo .connect ("changed" , model_sensitive_combo_changed )
841-
842-
843-
844873 adv_checkbox .connect ("toggled" , model_sensitive_combo_changed )
874+ adv_power_mode_combo .connect ("changed" , model_sensitive_combo_changed )
845875
846876
847877
@@ -864,9 +894,7 @@ def model_combo_changed(widget):
864894 #adv_checkbox.set_sensitive(False)
865895 prompt = prompt_text .get_text ()
866896 negative_prompt = negative_prompt_text .get_text ()
867-
868-
869-
897+
870898
871899 if adv_checkbox .get_active ():
872900
@@ -891,8 +919,6 @@ def model_combo_changed(widget):
891919
892920
893921
894-
895-
896922 if initialImage_checkbox .get_active () and n_layers == 1 :
897923 if len (file_entry .get_text ()) != 0 :
898924 initial_image = file_entry .get_text ()
@@ -931,12 +957,28 @@ def model_combo_changed(widget):
931957
932958 model_name = config .get_property ("model_name" )
933959
960+ if adv_checkbox .get_active ():
961+
962+ if "int8" in model_name :
963+ device_power_mode = config .get_property ("power_mode" )
964+
965+ else :
966+ device_power_mode = None
967+
968+ else :
969+
970+ if "int8" in model_name :
971+ device_power_mode = "Best performance"
972+
973+ else :
974+ device_power_mode = None
975+
934976
935977 server = "stable-diffusion-ov-server.py"
936978 server_path = os .path .join (config_path , server )
937979
938980
939- run_load_model_thread = threading .Thread (target = async_load_models , args = (python_path , server_path , model_name ,supported_devices , dialog ))
981+ run_load_model_thread = threading .Thread (target = async_load_models , args = (python_path , server_path , model_name ,supported_devices , device_power_mode , dialog ))
940982 run_load_model_thread .start ()
941983
942984 continue
@@ -1020,6 +1062,14 @@ class StableDiffusion(Gimp.PlugIn):
10201062 False ,
10211063 GObject .ParamFlags .READWRITE ,
10221064 ),
1065+
1066+ "power_mode" : (
1067+ str ,
1068+ _ ("Power Mode" ),
1069+ "Power Mode: 'Balanced', 'Best performance'" ,
1070+ "Best performance" ,
1071+ GObject .ParamFlags .READWRITE ,
1072+ ),
10231073
10241074 "use_initial_image" : (
10251075 bool ,
@@ -1075,6 +1125,7 @@ def do_create_procedure(self, name):
10751125 procedure .add_argument_from_property (self , "model_name" )
10761126
10771127 procedure .add_argument_from_property (self , "advanced_setting" )
1128+ procedure .add_argument_from_property (self , "power_mode" )
10781129
10791130 procedure .add_argument_from_property (self , "use_initial_image" )
10801131
0 commit comments