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
e5e557fa
Commit
e5e557fa
authored
Dec 10, 2022
by
AUTOMATIC1111
Committed by
GitHub
Dec 10, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5404 from szhublox/merger-ram-usage
Merger ram usage
parents
22f916df
681c450e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
18 deletions
+19
-18
modules/extras.py
modules/extras.py
+19
-18
No files found.
modules/extras.py
View file @
e5e557fa
...
@@ -234,7 +234,7 @@ def run_pnginfo(image):
...
@@ -234,7 +234,7 @@ def run_pnginfo(image):
return
''
,
geninfo
,
info
return
''
,
geninfo
,
info
def
run_modelmerger
(
primary_model_name
,
secondary_model_name
,
ter
it
ary_model_name
,
interp_method
,
multiplier
,
save_as_half
,
custom_name
,
checkpoint_format
):
def
run_modelmerger
(
primary_model_name
,
secondary_model_name
,
ter
ti
ary_model_name
,
interp_method
,
multiplier
,
save_as_half
,
custom_name
,
checkpoint_format
):
def
weighted_sum
(
theta0
,
theta1
,
alpha
):
def
weighted_sum
(
theta0
,
theta1
,
alpha
):
return
((
1
-
alpha
)
*
theta0
)
+
(
alpha
*
theta1
)
return
((
1
-
alpha
)
*
theta0
)
+
(
alpha
*
theta1
)
...
@@ -246,30 +246,25 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam
...
@@ -246,30 +246,25 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam
primary_model_info
=
sd_models
.
checkpoints_list
[
primary_model_name
]
primary_model_info
=
sd_models
.
checkpoints_list
[
primary_model_name
]
secondary_model_info
=
sd_models
.
checkpoints_list
[
secondary_model_name
]
secondary_model_info
=
sd_models
.
checkpoints_list
[
secondary_model_name
]
ter
itary_model_info
=
sd_models
.
checkpoints_list
.
get
(
terit
ary_model_name
,
None
)
ter
tiary_model_info
=
sd_models
.
checkpoints_list
.
get
(
terti
ary_model_name
,
None
)
result_is_inpainting_model
=
False
result_is_inpainting_model
=
False
print
(
f
"Loading {primary_model_info.filename}..."
)
theta_0
=
sd_models
.
read_state_dict
(
primary_model_info
.
filename
,
map_location
=
'cpu'
)
print
(
f
"Loading {secondary_model_info.filename}..."
)
theta_1
=
sd_models
.
read_state_dict
(
secondary_model_info
.
filename
,
map_location
=
'cpu'
)
if
teritary_model_info
is
not
None
:
print
(
f
"Loading {teritary_model_info.filename}..."
)
theta_2
=
sd_models
.
read_state_dict
(
teritary_model_info
.
filename
,
map_location
=
'cpu'
)
else
:
theta_2
=
None
theta_funcs
=
{
theta_funcs
=
{
"Weighted sum"
:
(
None
,
weighted_sum
),
"Weighted sum"
:
(
None
,
weighted_sum
),
"Add difference"
:
(
get_difference
,
add_difference
),
"Add difference"
:
(
get_difference
,
add_difference
),
}
}
theta_func1
,
theta_func2
=
theta_funcs
[
interp_method
]
theta_func1
,
theta_func2
=
theta_funcs
[
interp_method
]
print
(
f
"Merging..."
)
if
theta_func1
and
not
tertiary_model_info
:
return
[
"Failed: Interpolation method requires a tertiary model."
]
+
[
gr
.
Dropdown
.
update
(
choices
=
sd_models
.
checkpoint_tiles
())
for
_
in
range
(
4
)]
print
(
f
"Loading {secondary_model_info.filename}..."
)
theta_1
=
sd_models
.
read_state_dict
(
secondary_model_info
.
filename
,
map_location
=
'cpu'
)
if
theta_func1
:
if
theta_func1
:
print
(
f
"Loading {tertiary_model_info.filename}..."
)
theta_2
=
sd_models
.
read_state_dict
(
tertiary_model_info
.
filename
,
map_location
=
'cpu'
)
for
key
in
tqdm
.
tqdm
(
theta_1
.
keys
()):
for
key
in
tqdm
.
tqdm
(
theta_1
.
keys
()):
if
'model'
in
key
:
if
'model'
in
key
:
if
key
in
theta_2
:
if
key
in
theta_2
:
...
@@ -279,6 +274,11 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam
...
@@ -279,6 +274,11 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam
theta_1
[
key
]
=
torch
.
zeros_like
(
theta_1
[
key
])
theta_1
[
key
]
=
torch
.
zeros_like
(
theta_1
[
key
])
del
theta_2
del
theta_2
print
(
f
"Loading {primary_model_info.filename}..."
)
theta_0
=
sd_models
.
read_state_dict
(
primary_model_info
.
filename
,
map_location
=
'cpu'
)
print
(
"Merging..."
)
for
key
in
tqdm
.
tqdm
(
theta_0
.
keys
()):
for
key
in
tqdm
.
tqdm
(
theta_0
.
keys
()):
if
'model'
in
key
and
key
in
theta_1
:
if
'model'
in
key
and
key
in
theta_1
:
a
=
theta_0
[
key
]
a
=
theta_0
[
key
]
...
@@ -307,6 +307,7 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam
...
@@ -307,6 +307,7 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam
theta_0
[
key
]
=
theta_1
[
key
]
theta_0
[
key
]
=
theta_1
[
key
]
if
save_as_half
:
if
save_as_half
:
theta_0
[
key
]
=
theta_0
[
key
]
.
half
()
theta_0
[
key
]
=
theta_0
[
key
]
.
half
()
del
theta_1
ckpt_dir
=
shared
.
cmd_opts
.
ckpt_dir
or
sd_models
.
model_path
ckpt_dir
=
shared
.
cmd_opts
.
ckpt_dir
or
sd_models
.
model_path
...
@@ -332,5 +333,5 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam
...
@@ -332,5 +333,5 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam
sd_models
.
list_models
()
sd_models
.
list_models
()
print
(
f
"Checkpoint saved."
)
print
(
"Checkpoint saved."
)
return
[
"Checkpoint saved to "
+
output_modelname
]
+
[
gr
.
Dropdown
.
update
(
choices
=
sd_models
.
checkpoint_tiles
())
for
_
in
range
(
4
)]
return
[
"Checkpoint saved to "
+
output_modelname
]
+
[
gr
.
Dropdown
.
update
(
choices
=
sd_models
.
checkpoint_tiles
())
for
_
in
range
(
4
)]
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