aboutsummaryrefslogtreecommitdiffstats
path: root/modules/hypernetworks/ui.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-01-04 15:57:14 +0000
committerGitHub <noreply@github.com>2023-01-04 15:57:14 +0000
commit32547f2721c92794779e6ff9fb325243d5857cae (patch)
treed4d5f1a9705e59eef5029cc1be3bff57fbd389c2 /modules/hypernetworks/ui.py
parentfe6e2362e8fa5d739de6997ab155a26686d20a49 (diff)
parent3dae545a03f5102ba5d9c3f27bb6241824c5a916 (diff)
downloadstable-diffusion-webui-gfx803-32547f2721c92794779e6ff9fb325243d5857cae.tar.gz
stable-diffusion-webui-gfx803-32547f2721c92794779e6ff9fb325243d5857cae.tar.bz2
stable-diffusion-webui-gfx803-32547f2721c92794779e6ff9fb325243d5857cae.zip
Merge branch 'master' into xygrid_infotext_improvements
Diffstat (limited to 'modules/hypernetworks/ui.py')
-rw-r--r--modules/hypernetworks/ui.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/modules/hypernetworks/ui.py b/modules/hypernetworks/ui.py
new file mode 100644
index 00000000..e7f9e593
--- /dev/null
+++ b/modules/hypernetworks/ui.py
@@ -0,0 +1,41 @@
+import html
+import os
+import re
+
+import gradio as gr
+import modules.hypernetworks.hypernetwork
+from modules import devices, sd_hijack, shared
+
+not_available = ["hardswish", "multiheadattention"]
+keys = list(x for x in modules.hypernetworks.hypernetwork.HypernetworkModule.activation_dict.keys() if x not in not_available)
+
+def create_hypernetwork(name, enable_sizes, overwrite_old, layer_structure=None, activation_func=None, weight_init=None, add_layer_norm=False, use_dropout=False):
+ filename = modules.hypernetworks.hypernetwork.create_hypernetwork(name, enable_sizes, overwrite_old, layer_structure, activation_func, weight_init, add_layer_norm, use_dropout)
+
+ return gr.Dropdown.update(choices=sorted([x for x in shared.hypernetworks.keys()])), f"Created: {filename}", ""
+
+
+def train_hypernetwork(*args):
+
+ initial_hypernetwork = shared.loaded_hypernetwork
+
+ assert not shared.cmd_opts.lowvram, 'Training models with lowvram is not possible'
+
+ try:
+ sd_hijack.undo_optimizations()
+
+ hypernetwork, filename = modules.hypernetworks.hypernetwork.train_hypernetwork(*args)
+
+ res = f"""
+Training {'interrupted' if shared.state.interrupted else 'finished'} at {hypernetwork.step} steps.
+Hypernetwork saved to {html.escape(filename)}
+"""
+ return res, ""
+ except Exception:
+ raise
+ finally:
+ shared.loaded_hypernetwork = initial_hypernetwork
+ shared.sd_model.cond_stage_model.to(devices.device)
+ shared.sd_model.first_stage_model.to(devices.device)
+ sd_hijack.apply_optimizations()
+