aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authordiscus0434 <66945496+discus0434@users.noreply.github.com>2022-10-22 22:00:59 +0900
committerGitHub <noreply@github.com>2022-10-22 22:00:59 +0900
commit97749b7c7d9e0b27613aa79197f6094b4f6441d8 (patch)
tree6f4402badf1253bb77d2e973d31ec1228e9fbbab /modules
parent7912acef725832debef58c4c7bf8ec22fb446c0b (diff)
parent7fd90128eb6d1820045bfe2c2c1269661023a712 (diff)
Merge branch 'AUTOMATIC1111:master' into master
Diffstat (limited to 'modules')
-rw-r--r--modules/hypernetworks/hypernetwork.py11
-rw-r--r--modules/ui.py3
2 files changed, 14 insertions, 0 deletions
diff --git a/modules/hypernetworks/hypernetwork.py b/modules/hypernetworks/hypernetwork.py
index 7d12e0ff..3372aae2 100644
--- a/modules/hypernetworks/hypernetwork.py
+++ b/modules/hypernetworks/hypernetwork.py
@@ -325,6 +325,8 @@ def train_hypernetwork(hypernetwork_name, learn_rate, batch_size, data_root, log
# if optimizer == "AdamW": or else Adam / AdamW / SGD, etc...
optimizer = torch.optim.AdamW(weights, lr=scheduler.learn_rate)
+ steps_without_grad = 0
+
pbar = tqdm.tqdm(enumerate(ds), total=steps - ititial_step)
for i, entries in pbar:
hypernetwork.step = i + ititial_step
@@ -347,8 +349,17 @@ def train_hypernetwork(hypernetwork_name, learn_rate, batch_size, data_root, log
losses[hypernetwork.step % losses.shape[0]] = loss.item()
optimizer.zero_grad()
+ weights[0].grad = None
loss.backward()
+
+ if weights[0].grad is None:
+ steps_without_grad += 1
+ else:
+ steps_without_grad = 0
+ assert steps_without_grad < 10, 'no gradient found for the trained weight after backward() for 10 steps in a row; this is a bug; training cannot continue'
+
optimizer.step()
+
mean_loss = losses.mean()
if torch.isnan(mean_loss):
raise RuntimeError("Loss diverged.")
diff --git a/modules/ui.py b/modules/ui.py
index eca887ca..6336a890 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -1648,6 +1648,9 @@ Requested path was: {f}
css = ""
for cssfile in modules.scripts.list_files_with_name("style.css"):
+ if not os.path.isfile(cssfile):
+ continue
+
with open(cssfile, "r", encoding="utf8") as file:
css += file.read() + "\n"