Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
7fd90128
Commit
7fd90128
authored
Oct 22, 2022
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a guard for hypernet training that will stop early if weights are getting no gradients
parent
1cd3ed7d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
0 deletions
+11
-0
modules/hypernetworks/hypernetwork.py
modules/hypernetworks/hypernetwork.py
+11
-0
No files found.
modules/hypernetworks/hypernetwork.py
View file @
7fd90128
...
...
@@ -310,6 +310,8 @@ def train_hypernetwork(hypernetwork_name, learn_rate, batch_size, data_root, log
scheduler
=
LearnRateScheduler
(
learn_rate
,
steps
,
ititial_step
)
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
...
...
@@ -332,8 +334,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."
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment