Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
069657fb
Commit
069657fb
authored
May 21, 2023
by
comfyanonymous
Browse files
Add DPM-Solver++(2M) SDE and exponential scheduler.
exponential scheduler is the one recommended with this sampler.
parent
516119ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
2 deletions
+47
-2
comfy/k_diffusion/sampling.py
comfy/k_diffusion/sampling.py
+43
-0
comfy/samplers.py
comfy/samplers.py
+4
-2
No files found.
comfy/k_diffusion/sampling.py
View file @
069657fb
...
@@ -605,3 +605,46 @@ def sample_dpmpp_2m(model, x, sigmas, extra_args=None, callback=None, disable=No
...
@@ -605,3 +605,46 @@ def sample_dpmpp_2m(model, x, sigmas, extra_args=None, callback=None, disable=No
x
=
(
sigma_fn
(
t_next
)
/
sigma_fn
(
t
))
*
x
-
(
-
h
).
expm1
()
*
denoised_d
x
=
(
sigma_fn
(
t_next
)
/
sigma_fn
(
t
))
*
x
-
(
-
h
).
expm1
()
*
denoised_d
old_denoised
=
denoised
old_denoised
=
denoised
return
x
return
x
@
torch
.
no_grad
()
def
sample_dpmpp_2m_sde
(
model
,
x
,
sigmas
,
extra_args
=
None
,
callback
=
None
,
disable
=
None
,
eta
=
1.
,
s_noise
=
1.
,
noise_sampler
=
None
,
solver_type
=
'midpoint'
):
"""DPM-Solver++(2M) SDE."""
if
solver_type
not
in
{
'heun'
,
'midpoint'
}:
raise
ValueError
(
'solver_type must be
\'
heun
\'
or
\'
midpoint
\'
'
)
sigma_min
,
sigma_max
=
sigmas
[
sigmas
>
0
].
min
(),
sigmas
.
max
()
noise_sampler
=
BrownianTreeNoiseSampler
(
x
,
sigma_min
,
sigma_max
)
if
noise_sampler
is
None
else
noise_sampler
extra_args
=
{}
if
extra_args
is
None
else
extra_args
s_in
=
x
.
new_ones
([
x
.
shape
[
0
]])
old_denoised
=
None
h_last
=
None
for
i
in
trange
(
len
(
sigmas
)
-
1
,
disable
=
disable
):
denoised
=
model
(
x
,
sigmas
[
i
]
*
s_in
,
**
extra_args
)
if
callback
is
not
None
:
callback
({
'x'
:
x
,
'i'
:
i
,
'sigma'
:
sigmas
[
i
],
'sigma_hat'
:
sigmas
[
i
],
'denoised'
:
denoised
})
if
sigmas
[
i
+
1
]
==
0
:
# Denoising step
x
=
denoised
else
:
# DPM-Solver++(2M) SDE
t
,
s
=
-
sigmas
[
i
].
log
(),
-
sigmas
[
i
+
1
].
log
()
h
=
s
-
t
eta_h
=
eta
*
h
x
=
sigmas
[
i
+
1
]
/
sigmas
[
i
]
*
(
-
eta_h
).
exp
()
*
x
+
(
-
h
-
eta_h
).
expm1
().
neg
()
*
denoised
if
old_denoised
is
not
None
:
r
=
h_last
/
h
if
solver_type
==
'heun'
:
x
=
x
+
((
-
h
-
eta_h
).
expm1
().
neg
()
/
(
-
h
-
eta_h
)
+
1
)
*
(
1
/
r
)
*
(
denoised
-
old_denoised
)
elif
solver_type
==
'midpoint'
:
x
=
x
+
0.5
*
(
-
h
-
eta_h
).
expm1
().
neg
()
*
(
1
/
r
)
*
(
denoised
-
old_denoised
)
x
=
x
+
noise_sampler
(
sigmas
[
i
],
sigmas
[
i
+
1
])
*
sigmas
[
i
+
1
]
*
(
-
2
*
eta_h
).
expm1
().
neg
().
sqrt
()
*
s_noise
old_denoised
=
denoised
h_last
=
h
return
x
comfy/samplers.py
View file @
069657fb
...
@@ -495,10 +495,10 @@ def encode_adm(noise_augmentor, conds, batch_size, device):
...
@@ -495,10 +495,10 @@ def encode_adm(noise_augmentor, conds, batch_size, device):
class
KSampler
:
class
KSampler
:
SCHEDULERS
=
[
"normal"
,
"karras"
,
"simple"
,
"ddim_uniform"
]
SCHEDULERS
=
[
"normal"
,
"karras"
,
"exponential"
,
"simple"
,
"ddim_uniform"
]
SAMPLERS
=
[
"euler"
,
"euler_ancestral"
,
"heun"
,
"dpm_2"
,
"dpm_2_ancestral"
,
SAMPLERS
=
[
"euler"
,
"euler_ancestral"
,
"heun"
,
"dpm_2"
,
"dpm_2_ancestral"
,
"lms"
,
"dpm_fast"
,
"dpm_adaptive"
,
"dpmpp_2s_ancestral"
,
"dpmpp_sde"
,
"lms"
,
"dpm_fast"
,
"dpm_adaptive"
,
"dpmpp_2s_ancestral"
,
"dpmpp_sde"
,
"dpmpp_2m"
,
"ddim"
,
"uni_pc"
,
"uni_pc_bh2"
]
"dpmpp_2m"
,
"dpmpp_2m_sde"
,
"ddim"
,
"uni_pc"
,
"uni_pc_bh2"
]
def
__init__
(
self
,
model
,
steps
,
device
,
sampler
=
None
,
scheduler
=
None
,
denoise
=
None
,
model_options
=
{}):
def
__init__
(
self
,
model
,
steps
,
device
,
sampler
=
None
,
scheduler
=
None
,
denoise
=
None
,
model_options
=
{}):
self
.
model
=
model
self
.
model
=
model
...
@@ -532,6 +532,8 @@ class KSampler:
...
@@ -532,6 +532,8 @@ class KSampler:
if
self
.
scheduler
==
"karras"
:
if
self
.
scheduler
==
"karras"
:
sigmas
=
k_diffusion_sampling
.
get_sigmas_karras
(
n
=
steps
,
sigma_min
=
self
.
sigma_min
,
sigma_max
=
self
.
sigma_max
)
sigmas
=
k_diffusion_sampling
.
get_sigmas_karras
(
n
=
steps
,
sigma_min
=
self
.
sigma_min
,
sigma_max
=
self
.
sigma_max
)
elif
self
.
scheduler
==
"exponential"
:
sigmas
=
k_diffusion_sampling
.
get_sigmas_exponential
(
n
=
steps
,
sigma_min
=
self
.
sigma_min
,
sigma_max
=
self
.
sigma_max
)
elif
self
.
scheduler
==
"normal"
:
elif
self
.
scheduler
==
"normal"
:
sigmas
=
self
.
model_wrap
.
get_sigmas
(
steps
)
sigmas
=
self
.
model_wrap
.
get_sigmas
(
steps
)
elif
self
.
scheduler
==
"simple"
:
elif
self
.
scheduler
==
"simple"
:
...
...
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