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
41255527
Commit
41255527
authored
Dec 02, 2023
by
AUTOMATIC1111
Committed by
GitHub
Dec 02, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14170 from MrCheeze/sd-turbo
Add support for SD 2.1 Turbo
parents
e294e46d
6080045b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
7 deletions
+19
-7
modules/sd_hijack.py
modules/sd_hijack.py
+6
-3
modules/sd_models.py
modules/sd_models.py
+13
-4
No files found.
modules/sd_hijack.py
View file @
41255527
...
@@ -38,9 +38,6 @@ ldm.models.diffusion.ddpm.print = shared.ldm_print
...
@@ -38,9 +38,6 @@ ldm.models.diffusion.ddpm.print = shared.ldm_print
optimizers
=
[]
optimizers
=
[]
current_optimizer
:
sd_hijack_optimizations
.
SdOptimization
=
None
current_optimizer
:
sd_hijack_optimizations
.
SdOptimization
=
None
ldm_original_forward
=
patches
.
patch
(
__file__
,
ldm
.
modules
.
diffusionmodules
.
openaimodel
.
UNetModel
,
"forward"
,
sd_unet
.
UNetModel_forward
)
sgm_original_forward
=
patches
.
patch
(
__file__
,
sgm
.
modules
.
diffusionmodules
.
openaimodel
.
UNetModel
,
"forward"
,
sd_unet
.
UNetModel_forward
)
def
list_optimizers
():
def
list_optimizers
():
new_optimizers
=
script_callbacks
.
list_optimizers_callback
()
new_optimizers
=
script_callbacks
.
list_optimizers_callback
()
...
@@ -258,6 +255,9 @@ class StableDiffusionModelHijack:
...
@@ -258,6 +255,9 @@ class StableDiffusionModelHijack:
import
modules.models.diffusion.ddpm_edit
import
modules.models.diffusion.ddpm_edit
ldm_original_forward
=
patches
.
patch
(
__file__
,
ldm
.
modules
.
diffusionmodules
.
openaimodel
.
UNetModel
,
"forward"
,
sd_unet
.
UNetModel_forward
)
sgm_original_forward
=
patches
.
patch
(
__file__
,
sgm
.
modules
.
diffusionmodules
.
openaimodel
.
UNetModel
,
"forward"
,
sd_unet
.
UNetModel_forward
)
if
isinstance
(
m
,
ldm
.
models
.
diffusion
.
ddpm
.
LatentDiffusion
):
if
isinstance
(
m
,
ldm
.
models
.
diffusion
.
ddpm
.
LatentDiffusion
):
sd_unet
.
original_forward
=
ldm_original_forward
sd_unet
.
original_forward
=
ldm_original_forward
elif
isinstance
(
m
,
modules
.
models
.
diffusion
.
ddpm_edit
.
LatentDiffusion
):
elif
isinstance
(
m
,
modules
.
models
.
diffusion
.
ddpm_edit
.
LatentDiffusion
):
...
@@ -303,6 +303,9 @@ class StableDiffusionModelHijack:
...
@@ -303,6 +303,9 @@ class StableDiffusionModelHijack:
self
.
layers
=
None
self
.
layers
=
None
self
.
clip
=
None
self
.
clip
=
None
patches
.
undo
(
__file__
,
ldm
.
modules
.
diffusionmodules
.
openaimodel
.
UNetModel
,
"forward"
)
patches
.
undo
(
__file__
,
sgm
.
modules
.
diffusionmodules
.
openaimodel
.
UNetModel
,
"forward"
)
sd_unet
.
original_forward
=
None
sd_unet
.
original_forward
=
None
...
...
modules/sd_models.py
View file @
41255527
...
@@ -230,15 +230,19 @@ def select_checkpoint():
...
@@ -230,15 +230,19 @@ def select_checkpoint():
return
checkpoint_info
return
checkpoint_info
checkpoint_dict_replacements
=
{
checkpoint_dict_replacements
_sd1
=
{
'cond_stage_model.transformer.embeddings.'
:
'cond_stage_model.transformer.text_model.embeddings.'
,
'cond_stage_model.transformer.embeddings.'
:
'cond_stage_model.transformer.text_model.embeddings.'
,
'cond_stage_model.transformer.encoder.'
:
'cond_stage_model.transformer.text_model.encoder.'
,
'cond_stage_model.transformer.encoder.'
:
'cond_stage_model.transformer.text_model.encoder.'
,
'cond_stage_model.transformer.final_layer_norm.'
:
'cond_stage_model.transformer.text_model.final_layer_norm.'
,
'cond_stage_model.transformer.final_layer_norm.'
:
'cond_stage_model.transformer.text_model.final_layer_norm.'
,
}
}
checkpoint_dict_replacements_sd2_turbo
=
{
# Converts SD 2.1 Turbo from SGM to LDM format.
'conditioner.embedders.0.'
:
'cond_stage_model.'
,
}
def
transform_checkpoint_dict_key
(
k
):
def
transform_checkpoint_dict_key
(
k
,
replacements
):
for
text
,
replacement
in
checkpoint_dict_
replacements
.
items
():
for
text
,
replacement
in
replacements
.
items
():
if
k
.
startswith
(
text
):
if
k
.
startswith
(
text
):
k
=
replacement
+
k
[
len
(
text
):]
k
=
replacement
+
k
[
len
(
text
):]
...
@@ -249,9 +253,14 @@ def get_state_dict_from_checkpoint(pl_sd):
...
@@ -249,9 +253,14 @@ def get_state_dict_from_checkpoint(pl_sd):
pl_sd
=
pl_sd
.
pop
(
"state_dict"
,
pl_sd
)
pl_sd
=
pl_sd
.
pop
(
"state_dict"
,
pl_sd
)
pl_sd
.
pop
(
"state_dict"
,
None
)
pl_sd
.
pop
(
"state_dict"
,
None
)
is_sd2_turbo
=
'conditioner.embedders.0.model.ln_final.weight'
in
pl_sd
and
pl_sd
[
'conditioner.embedders.0.model.ln_final.weight'
]
.
size
()[
0
]
==
1024
sd
=
{}
sd
=
{}
for
k
,
v
in
pl_sd
.
items
():
for
k
,
v
in
pl_sd
.
items
():
new_key
=
transform_checkpoint_dict_key
(
k
)
if
is_sd2_turbo
:
new_key
=
transform_checkpoint_dict_key
(
k
,
checkpoint_dict_replacements_sd2_turbo
)
else
:
new_key
=
transform_checkpoint_dict_key
(
k
,
checkpoint_dict_replacements_sd1
)
if
new_key
is
not
None
:
if
new_key
is
not
None
:
sd
[
new_key
]
=
v
sd
[
new_key
]
=
v
...
...
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