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
6450d24a
Commit
6450d24a
authored
Jun 08, 2024
by
AUTOMATIC1111
Committed by
GitHub
Jun 08, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15806 from huchenlei/inpaint_fix
[Performance 4/6] Precompute is_sdxl_inpaint flag
parents
64bf57b5
3e20b36e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
22 deletions
+22
-22
modules/processing.py
modules/processing.py
+11
-17
modules/sd_models.py
modules/sd_models.py
+7
-0
modules/sd_models_xl.py
modules/sd_models_xl.py
+4
-5
No files found.
modules/processing.py
View file @
6450d24a
...
@@ -115,10 +115,7 @@ def txt2img_image_conditioning(sd_model, x, width, height):
...
@@ -115,10 +115,7 @@ def txt2img_image_conditioning(sd_model, x, width, height):
return
x
.
new_zeros
(
x
.
shape
[
0
],
2
*
sd_model
.
noise_augmentor
.
time_embed
.
dim
,
dtype
=
x
.
dtype
,
device
=
x
.
device
)
return
x
.
new_zeros
(
x
.
shape
[
0
],
2
*
sd_model
.
noise_augmentor
.
time_embed
.
dim
,
dtype
=
x
.
dtype
,
device
=
x
.
device
)
else
:
else
:
sd
=
sd_model
.
model
.
state_dict
()
if
getattr
(
sd_model
.
model
,
"is_sdxl_inpaint"
,
False
):
diffusion_model_input
=
sd
.
get
(
'diffusion_model.input_blocks.0.0.weight'
,
None
)
if
diffusion_model_input
is
not
None
:
if
diffusion_model_input
.
shape
[
1
]
==
9
:
# The "masked-image" in this case will just be all 0.5 since the entire image is masked.
# The "masked-image" in this case will just be all 0.5 since the entire image is masked.
image_conditioning
=
torch
.
ones
(
x
.
shape
[
0
],
3
,
height
,
width
,
device
=
x
.
device
)
*
0.5
image_conditioning
=
torch
.
ones
(
x
.
shape
[
0
],
3
,
height
,
width
,
device
=
x
.
device
)
*
0.5
image_conditioning
=
images_tensor_to_samples
(
image_conditioning
,
image_conditioning
=
images_tensor_to_samples
(
image_conditioning
,
...
@@ -392,10 +389,7 @@ class StableDiffusionProcessing:
...
@@ -392,10 +389,7 @@ class StableDiffusionProcessing:
if
self
.
sampler
.
conditioning_key
==
"crossattn-adm"
:
if
self
.
sampler
.
conditioning_key
==
"crossattn-adm"
:
return
self
.
unclip_image_conditioning
(
source_image
)
return
self
.
unclip_image_conditioning
(
source_image
)
sd
=
self
.
sampler
.
model_wrap
.
inner_model
.
model
.
state_dict
()
if
getattr
(
self
.
sampler
.
model_wrap
.
inner_model
.
model
,
"is_sdxl_inpaint"
,
False
):
diffusion_model_input
=
sd
.
get
(
'diffusion_model.input_blocks.0.0.weight'
,
None
)
if
diffusion_model_input
is
not
None
:
if
diffusion_model_input
.
shape
[
1
]
==
9
:
return
self
.
inpainting_image_conditioning
(
source_image
,
latent_image
,
image_mask
=
image_mask
)
return
self
.
inpainting_image_conditioning
(
source_image
,
latent_image
,
image_mask
=
image_mask
)
# Dummy zero conditioning if we're not using inpainting or depth model.
# Dummy zero conditioning if we're not using inpainting or depth model.
...
...
modules/sd_models.py
View file @
6450d24a
...
@@ -380,6 +380,13 @@ def load_model_weights(model, checkpoint_info: CheckpointInfo, state_dict, timer
...
@@ -380,6 +380,13 @@ def load_model_weights(model, checkpoint_info: CheckpointInfo, state_dict, timer
model
.
is_sd2
=
not
model
.
is_sdxl
and
hasattr
(
model
.
cond_stage_model
,
'model'
)
model
.
is_sd2
=
not
model
.
is_sdxl
and
hasattr
(
model
.
cond_stage_model
,
'model'
)
model
.
is_sd1
=
not
model
.
is_sdxl
and
not
model
.
is_sd2
model
.
is_sd1
=
not
model
.
is_sdxl
and
not
model
.
is_sd2
model
.
is_ssd
=
model
.
is_sdxl
and
'model.diffusion_model.middle_block.1.transformer_blocks.0.attn1.to_q.weight'
not
in
state_dict
.
keys
()
model
.
is_ssd
=
model
.
is_sdxl
and
'model.diffusion_model.middle_block.1.transformer_blocks.0.attn1.to_q.weight'
not
in
state_dict
.
keys
()
# Set is_sdxl_inpaint flag.
diffusion_model_input
=
state_dict
.
get
(
'diffusion_model.input_blocks.0.0.weight'
,
None
)
model
.
is_sdxl_inpaint
=
(
model
.
is_sdxl
and
diffusion_model_input
is
not
None
and
diffusion_model_input
.
shape
[
1
]
==
9
)
if
model
.
is_sdxl
:
if
model
.
is_sdxl
:
sd_models_xl
.
extend_sdxl
(
model
)
sd_models_xl
.
extend_sdxl
(
model
)
...
...
modules/sd_models_xl.py
View file @
6450d24a
...
@@ -35,10 +35,9 @@ def get_learned_conditioning(self: sgm.models.diffusion.DiffusionEngine, batch:
...
@@ -35,10 +35,9 @@ def get_learned_conditioning(self: sgm.models.diffusion.DiffusionEngine, batch:
def
apply_model
(
self
:
sgm
.
models
.
diffusion
.
DiffusionEngine
,
x
,
t
,
cond
):
def
apply_model
(
self
:
sgm
.
models
.
diffusion
.
DiffusionEngine
,
x
,
t
,
cond
):
sd
=
self
.
model
.
state_dict
()
"""WARNING: This function is called once per denoising iteration. DO NOT add
diffusion_model_input
=
sd
.
get
(
'diffusion_model.input_blocks.0.0.weight'
,
None
)
expensive functionc calls such as `model.state_dict`. """
if
diffusion_model_input
is
not
None
:
if
self
.
is_sdxl_inpaint
:
if
diffusion_model_input
.
shape
[
1
]
==
9
:
x
=
torch
.
cat
([
x
]
+
cond
[
'c_concat'
],
dim
=
1
)
x
=
torch
.
cat
([
x
]
+
cond
[
'c_concat'
],
dim
=
1
)
return
self
.
model
(
x
,
t
,
cond
)
return
self
.
model
(
x
,
t
,
cond
)
...
...
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