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
f8ff8c06
Commit
f8ff8c06
authored
Aug 08, 2023
by
AUTOMATIC1111
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge errors
parent
54c3e5c9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
18 deletions
+55
-18
modules/sd_samplers_cfg_denoiser.py
modules/sd_samplers_cfg_denoiser.py
+21
-2
modules/sd_samplers_common.py
modules/sd_samplers_common.py
+5
-1
modules/sd_samplers_kdiffusion.py
modules/sd_samplers_kdiffusion.py
+12
-5
modules/sd_samplers_timesteps.py
modules/sd_samplers_timesteps.py
+17
-10
No files found.
modules/sd_samplers_cfg_denoiser.py
View file @
f8ff8c06
...
...
@@ -38,16 +38,24 @@ class CFGDenoiser(torch.nn.Module):
negative prompt.
"""
def
__init__
(
self
,
model
,
sampler
):
def
__init__
(
self
,
sampler
):
super
()
.
__init__
()
self
.
inner_model
=
model
self
.
model_wrap
=
None
self
.
mask
=
None
self
.
nmask
=
None
self
.
init_latent
=
None
self
.
steps
=
None
self
.
step
=
0
self
.
image_cfg_scale
=
None
self
.
padded_cond_uncond
=
False
self
.
sampler
=
sampler
self
.
model_wrap
=
None
self
.
p
=
None
@
property
def
inner_model
(
self
):
raise
NotImplementedError
()
def
combine_denoised
(
self
,
x_out
,
conds_list
,
uncond
,
cond_scale
):
denoised_uncond
=
x_out
[
-
uncond
.
shape
[
0
]:]
...
...
@@ -68,10 +76,21 @@ class CFGDenoiser(torch.nn.Module):
def
get_pred_x0
(
self
,
x_in
,
x_out
,
sigma
):
return
x_out
def
update_inner_model
(
self
):
self
.
model_wrap
=
None
c
,
uc
=
self
.
p
.
get_conds
()
self
.
sampler
.
sampler_extra_args
[
'cond'
]
=
c
self
.
sampler
.
sampler_extra_args
[
'uncond'
]
=
uc
def
forward
(
self
,
x
,
sigma
,
uncond
,
cond
,
cond_scale
,
s_min_uncond
,
image_cond
):
if
state
.
interrupted
or
state
.
skipped
:
raise
sd_samplers_common
.
InterruptedException
if
sd_samplers_common
.
apply_refiner
(
self
):
cond
=
self
.
sampler
.
sampler_extra_args
[
'cond'
]
uncond
=
self
.
sampler
.
sampler_extra_args
[
'uncond'
]
# at self.image_cfg_scale == 1.0 produced results for edit model are the same as with normal sampling,
# so is_edit_model is set to False to support AND composition.
is_edit_model
=
shared
.
sd_model
.
cond_stage_key
==
"edit"
and
self
.
image_cfg_scale
is
not
None
and
self
.
image_cfg_scale
!=
1.0
...
...
modules/sd_samplers_common.py
View file @
f8ff8c06
...
...
@@ -202,8 +202,9 @@ class Sampler:
self
.
conditioning_key
=
shared
.
sd_model
.
model
.
conditioning_key
self
.
model_wra
p
=
None
self
.
p
=
None
self
.
model_wrap_cfg
=
None
self
.
sampler_extra_args
=
None
def
callback_state
(
self
,
d
):
step
=
d
[
'i'
]
...
...
@@ -215,6 +216,7 @@ class Sampler:
shared
.
total_tqdm
.
update
()
def
launch_sampling
(
self
,
steps
,
func
):
self
.
model_wrap_cfg
.
steps
=
steps
state
.
sampling_steps
=
steps
state
.
sampling_step
=
0
...
...
@@ -234,6 +236,8 @@ class Sampler:
return
p
.
steps
def
initialize
(
self
,
p
)
->
dict
:
self
.
p
=
p
self
.
model_wrap_cfg
.
p
=
p
self
.
model_wrap_cfg
.
mask
=
p
.
mask
if
hasattr
(
p
,
'mask'
)
else
None
self
.
model_wrap_cfg
.
nmask
=
p
.
nmask
if
hasattr
(
p
,
'nmask'
)
else
None
self
.
model_wrap_cfg
.
step
=
0
...
...
modules/sd_samplers_kdiffusion.py
View file @
f8ff8c06
...
...
@@ -52,17 +52,24 @@ k_diffusion_scheduler = {
}
class
CFGDenoiserKDiffusion
(
sd_samplers_cfg_denoiser
.
CFGDenoiser
):
@
property
def
inner_model
(
self
):
if
self
.
model_wrap
is
None
:
denoiser
=
k_diffusion
.
external
.
CompVisVDenoiser
if
shared
.
sd_model
.
parameterization
==
"v"
else
k_diffusion
.
external
.
CompVisDenoiser
self
.
model_wrap
=
denoiser
(
shared
.
sd_model
,
quantize
=
shared
.
opts
.
enable_quantization
)
return
self
.
model_wrap
class
KDiffusionSampler
(
sd_samplers_common
.
Sampler
):
def
__init__
(
self
,
funcname
,
sd_model
):
super
()
.
__init__
(
funcname
)
self
.
extra_params
=
sampler_extra_params
.
get
(
funcname
,
[])
self
.
func
=
funcname
if
callable
(
funcname
)
else
getattr
(
k_diffusion
.
sampling
,
self
.
funcname
)
denoiser
=
k_diffusion
.
external
.
CompVisVDenoiser
if
sd_model
.
parameterization
==
"v"
else
k_diffusion
.
external
.
CompVisDenoiser
self
.
model_wrap
=
denoiser
(
sd_model
,
quantize
=
shared
.
opts
.
enable_quantization
)
self
.
model_wrap_cfg
=
sd_samplers_cfg_denoiser
.
CFGDenoiser
(
self
.
model_wrap
,
self
)
self
.
model_wrap_cfg
=
CFGDenoiserKDiffusion
(
self
)
self
.
model_wrap
=
self
.
model_wrap_cfg
.
inner_model
def
get_sigmas
(
self
,
p
,
steps
):
discard_next_to_last_sigma
=
self
.
config
is
not
None
and
self
.
config
.
options
.
get
(
'discard_next_to_last_sigma'
,
False
)
...
...
modules/sd_samplers_timesteps.py
View file @
f8ff8c06
...
...
@@ -44,10 +44,10 @@ class CompVisTimestepsVDenoiser(torch.nn.Module):
class
CFGDenoiserTimesteps
(
CFGDenoiser
):
def
__init__
(
self
,
model
,
sampler
):
super
()
.
__init__
(
model
,
sampler
)
def
__init__
(
self
,
sampler
):
super
()
.
__init__
(
sampler
)
self
.
alphas
=
model
.
inner
_model
.
alphas_cumprod
self
.
alphas
=
shared
.
sd
_model
.
alphas_cumprod
def
get_pred_x0
(
self
,
x_in
,
x_out
,
sigma
):
ts
=
int
(
sigma
.
item
())
...
...
@@ -60,6 +60,14 @@ class CFGDenoiserTimesteps(CFGDenoiser):
return
pred_x0
@
property
def
inner_model
(
self
):
if
self
.
model_wrap
is
None
:
denoiser
=
CompVisTimestepsVDenoiser
if
shared
.
sd_model
.
parameterization
==
"v"
else
CompVisTimestepsDenoiser
self
.
model_wrap
=
denoiser
(
shared
.
sd_model
)
return
self
.
model_wrap
class
CompVisSampler
(
sd_samplers_common
.
Sampler
):
def
__init__
(
self
,
funcname
,
sd_model
):
...
...
@@ -68,9 +76,7 @@ class CompVisSampler(sd_samplers_common.Sampler):
self
.
eta_option_field
=
'eta_ddim'
self
.
eta_infotext_field
=
'Eta DDIM'
denoiser
=
CompVisTimestepsVDenoiser
if
sd_model
.
parameterization
==
"v"
else
CompVisTimestepsDenoiser
self
.
model_wrap
=
denoiser
(
sd_model
)
self
.
model_wrap_cfg
=
CFGDenoiserTimesteps
(
self
.
model_wrap
,
self
)
self
.
model_wrap_cfg
=
CFGDenoiserTimesteps
(
self
)
def
get_timesteps
(
self
,
p
,
steps
):
discard_next_to_last_sigma
=
self
.
config
is
not
None
and
self
.
config
.
options
.
get
(
'discard_next_to_last_sigma'
,
False
)
...
...
@@ -106,7 +112,7 @@ class CompVisSampler(sd_samplers_common.Sampler):
self
.
model_wrap_cfg
.
init_latent
=
x
self
.
last_latent
=
x
extra_args
=
{
self
.
sampler_
extra_args
=
{
'cond'
:
conditioning
,
'image_cond'
:
image_conditioning
,
'uncond'
:
unconditional_conditioning
,
...
...
@@ -114,7 +120,7 @@ class CompVisSampler(sd_samplers_common.Sampler):
's_min_uncond'
:
self
.
s_min_uncond
}
samples
=
self
.
launch_sampling
(
t_enc
+
1
,
lambda
:
self
.
func
(
self
.
model_wrap_cfg
,
xi
,
extra_args
=
extra_args
,
disable
=
False
,
callback
=
self
.
callback_state
,
**
extra_params_kwargs
))
samples
=
self
.
launch_sampling
(
t_enc
+
1
,
lambda
:
self
.
func
(
self
.
model_wrap_cfg
,
xi
,
extra_args
=
self
.
sampler_
extra_args
,
disable
=
False
,
callback
=
self
.
callback_state
,
**
extra_params_kwargs
))
if
self
.
model_wrap_cfg
.
padded_cond_uncond
:
p
.
extra_generation_params
[
"Pad conds"
]
=
True
...
...
@@ -132,13 +138,14 @@ class CompVisSampler(sd_samplers_common.Sampler):
extra_params_kwargs
[
'timesteps'
]
=
timesteps
self
.
last_latent
=
x
s
amples
=
self
.
launch_sampling
(
steps
,
lambda
:
self
.
func
(
self
.
model_wrap_cfg
,
x
,
extra_args
=
{
s
elf
.
sampler_extra_args
=
{
'cond'
:
conditioning
,
'image_cond'
:
image_conditioning
,
'uncond'
:
unconditional_conditioning
,
'cond_scale'
:
p
.
cfg_scale
,
's_min_uncond'
:
self
.
s_min_uncond
},
disable
=
False
,
callback
=
self
.
callback_state
,
**
extra_params_kwargs
))
}
samples
=
self
.
launch_sampling
(
steps
,
lambda
:
self
.
func
(
self
.
model_wrap_cfg
,
x
,
extra_args
=
self
.
sampler_extra_args
,
disable
=
False
,
callback
=
self
.
callback_state
,
**
extra_params_kwargs
))
if
self
.
model_wrap_cfg
.
padded_cond_uncond
:
p
.
extra_generation_params
[
"Pad conds"
]
=
True
...
...
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