Merge pull request #4842 from R-N/vae-as-default
Option to use selected VAE as default fallback instead of primary option
This commit is contained in:
commit
3951806058
|
@ -83,7 +83,19 @@ def refresh_vae_list(vae_path=vae_path, model_path=model_path):
|
||||||
return vae_list
|
return vae_list
|
||||||
|
|
||||||
|
|
||||||
def resolve_vae(checkpoint_file, vae_file="auto"):
|
def get_vae_from_settings(vae_file="auto"):
|
||||||
|
# else, we load from settings, if not set to be default
|
||||||
|
if vae_file == "auto" and shared.opts.sd_vae is not None:
|
||||||
|
# if saved VAE settings isn't recognized, fallback to auto
|
||||||
|
vae_file = vae_dict.get(shared.opts.sd_vae, "auto")
|
||||||
|
# if VAE selected but not found, fallback to auto
|
||||||
|
if vae_file not in default_vae_values and not os.path.isfile(vae_file):
|
||||||
|
vae_file = "auto"
|
||||||
|
print("Selected VAE doesn't exist")
|
||||||
|
return vae_file
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_vae(checkpoint_file=None, vae_file="auto"):
|
||||||
global first_load, vae_dict, vae_list
|
global first_load, vae_dict, vae_list
|
||||||
|
|
||||||
# if vae_file argument is provided, it takes priority, but not saved
|
# if vae_file argument is provided, it takes priority, but not saved
|
||||||
|
@ -98,14 +110,9 @@ def resolve_vae(checkpoint_file, vae_file="auto"):
|
||||||
shared.opts.data['sd_vae'] = get_filename(vae_file)
|
shared.opts.data['sd_vae'] = get_filename(vae_file)
|
||||||
else:
|
else:
|
||||||
print("VAE provided as command line argument doesn't exist")
|
print("VAE provided as command line argument doesn't exist")
|
||||||
# else, we load from settings
|
# fallback to selector in settings, if vae selector not set to act as default fallback
|
||||||
if vae_file == "auto" and shared.opts.sd_vae is not None:
|
if not shared.opts.sd_vae_as_default:
|
||||||
# if saved VAE settings isn't recognized, fallback to auto
|
vae_file = get_vae_from_settings(vae_file)
|
||||||
vae_file = vae_dict.get(shared.opts.sd_vae, "auto")
|
|
||||||
# if VAE selected but not found, fallback to auto
|
|
||||||
if vae_file not in default_vae_values and not os.path.isfile(vae_file):
|
|
||||||
vae_file = "auto"
|
|
||||||
print("Selected VAE doesn't exist")
|
|
||||||
# vae-path cmd arg takes priority for auto
|
# vae-path cmd arg takes priority for auto
|
||||||
if vae_file == "auto" and shared.cmd_opts.vae_path is not None:
|
if vae_file == "auto" and shared.cmd_opts.vae_path is not None:
|
||||||
if os.path.isfile(shared.cmd_opts.vae_path):
|
if os.path.isfile(shared.cmd_opts.vae_path):
|
||||||
|
|
|
@ -335,6 +335,7 @@ options_templates.update(options_section(('sd', "Stable Diffusion"), {
|
||||||
"sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Dropdown, lambda: {"choices": modules.sd_models.checkpoint_tiles()}, refresh=sd_models.list_models),
|
"sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Dropdown, lambda: {"choices": modules.sd_models.checkpoint_tiles()}, refresh=sd_models.list_models),
|
||||||
"sd_checkpoint_cache": OptionInfo(0, "Checkpoints to cache in RAM", gr.Slider, {"minimum": 0, "maximum": 10, "step": 1}),
|
"sd_checkpoint_cache": OptionInfo(0, "Checkpoints to cache in RAM", gr.Slider, {"minimum": 0, "maximum": 10, "step": 1}),
|
||||||
"sd_vae": OptionInfo("auto", "SD VAE", gr.Dropdown, lambda: {"choices": list(sd_vae.vae_list)}, refresh=sd_vae.refresh_vae_list),
|
"sd_vae": OptionInfo("auto", "SD VAE", gr.Dropdown, lambda: {"choices": list(sd_vae.vae_list)}, refresh=sd_vae.refresh_vae_list),
|
||||||
|
"sd_vae_as_default": OptionInfo(False, "Use selected VAE as default fallback instead"),
|
||||||
"sd_hypernetwork": OptionInfo("None", "Hypernetwork", gr.Dropdown, lambda: {"choices": ["None"] + [x for x in hypernetworks.keys()]}, refresh=reload_hypernetworks),
|
"sd_hypernetwork": OptionInfo("None", "Hypernetwork", gr.Dropdown, lambda: {"choices": ["None"] + [x for x in hypernetworks.keys()]}, refresh=reload_hypernetworks),
|
||||||
"sd_hypernetwork_strength": OptionInfo(1.0, "Hypernetwork strength", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.001}),
|
"sd_hypernetwork_strength": OptionInfo(1.0, "Hypernetwork strength", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.001}),
|
||||||
"inpainting_mask_weight": OptionInfo(1.0, "Inpainting conditioning mask strength", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.01}),
|
"inpainting_mask_weight": OptionInfo(1.0, "Inpainting conditioning mask strength", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.01}),
|
||||||
|
|
1
webui.py
1
webui.py
|
@ -82,6 +82,7 @@ def initialize():
|
||||||
modules.sd_models.load_model()
|
modules.sd_models.load_model()
|
||||||
shared.opts.onchange("sd_model_checkpoint", wrap_queued_call(lambda: modules.sd_models.reload_model_weights()))
|
shared.opts.onchange("sd_model_checkpoint", wrap_queued_call(lambda: modules.sd_models.reload_model_weights()))
|
||||||
shared.opts.onchange("sd_vae", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False)
|
shared.opts.onchange("sd_vae", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False)
|
||||||
|
shared.opts.onchange("sd_vae_as_default", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False)
|
||||||
shared.opts.onchange("sd_hypernetwork", wrap_queued_call(lambda: modules.hypernetworks.hypernetwork.load_hypernetwork(shared.opts.sd_hypernetwork)))
|
shared.opts.onchange("sd_hypernetwork", wrap_queued_call(lambda: modules.hypernetworks.hypernetwork.load_hypernetwork(shared.opts.sd_hypernetwork)))
|
||||||
shared.opts.onchange("sd_hypernetwork_strength", modules.hypernetworks.hypernetwork.apply_strength)
|
shared.opts.onchange("sd_hypernetwork_strength", modules.hypernetworks.hypernetwork.apply_strength)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue