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
d5efde89
"web/vscode:/vscode.git/clone" did not exist on "6a10640f0dd019dd7c74006909f38d0056c317bd"
Commit
d5efde89
authored
Jun 20, 2024
by
comfyanonymous
Browse files
Add ipndm_v sampler, works best with the exponential scheduler.
parent
45e10cac
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletion
+64
-1
comfy/k_diffusion/sampling.py
comfy/k_diffusion/sampling.py
+63
-0
comfy/samplers.py
comfy/samplers.py
+1
-1
No files found.
comfy/k_diffusion/sampling.py
View file @
d5efde89
...
...
@@ -882,3 +882,66 @@ def sample_ipndm(model, x, sigmas, extra_args=None, callback=None, disable=None,
buffer_model
.
append
(
d_cur
)
return
x_next
#From https://github.com/zju-pi/diff-sampler/blob/main/diff-solvers-main/solvers.py
#under Apache 2 license
def
sample_ipndm_v
(
model
,
x
,
sigmas
,
extra_args
=
None
,
callback
=
None
,
disable
=
None
,
max_order
=
4
):
extra_args
=
{}
if
extra_args
is
None
else
extra_args
s_in
=
x
.
new_ones
([
x
.
shape
[
0
]])
x_next
=
x
t_steps
=
sigmas
buffer_model
=
[]
for
i
in
trange
(
len
(
sigmas
)
-
1
,
disable
=
disable
):
t_cur
=
sigmas
[
i
]
t_next
=
sigmas
[
i
+
1
]
x_cur
=
x_next
denoised
=
model
(
x_cur
,
t_cur
*
s_in
,
**
extra_args
)
if
callback
is
not
None
:
callback
({
'x'
:
x
,
'i'
:
i
,
'sigma'
:
sigmas
[
i
],
'sigma_hat'
:
sigmas
[
i
],
'denoised'
:
denoised
})
d_cur
=
(
x_cur
-
denoised
)
/
t_cur
order
=
min
(
max_order
,
i
+
1
)
if
order
==
1
:
# First Euler step.
x_next
=
x_cur
+
(
t_next
-
t_cur
)
*
d_cur
elif
order
==
2
:
# Use one history point.
h_n
=
(
t_next
-
t_cur
)
h_n_1
=
(
t_cur
-
t_steps
[
i
-
1
])
coeff1
=
(
2
+
(
h_n
/
h_n_1
))
/
2
coeff2
=
-
(
h_n
/
h_n_1
)
/
2
x_next
=
x_cur
+
(
t_next
-
t_cur
)
*
(
coeff1
*
d_cur
+
coeff2
*
buffer_model
[
-
1
])
elif
order
==
3
:
# Use two history points.
h_n
=
(
t_next
-
t_cur
)
h_n_1
=
(
t_cur
-
t_steps
[
i
-
1
])
h_n_2
=
(
t_steps
[
i
-
1
]
-
t_steps
[
i
-
2
])
temp
=
(
1
-
h_n
/
(
3
*
(
h_n
+
h_n_1
))
*
(
h_n
*
(
h_n
+
h_n_1
))
/
(
h_n_1
*
(
h_n_1
+
h_n_2
)))
/
2
coeff1
=
(
2
+
(
h_n
/
h_n_1
))
/
2
+
temp
coeff2
=
-
(
h_n
/
h_n_1
)
/
2
-
(
1
+
h_n_1
/
h_n_2
)
*
temp
coeff3
=
temp
*
h_n_1
/
h_n_2
x_next
=
x_cur
+
(
t_next
-
t_cur
)
*
(
coeff1
*
d_cur
+
coeff2
*
buffer_model
[
-
1
]
+
coeff3
*
buffer_model
[
-
2
])
elif
order
==
4
:
# Use three history points.
h_n
=
(
t_next
-
t_cur
)
h_n_1
=
(
t_cur
-
t_steps
[
i
-
1
])
h_n_2
=
(
t_steps
[
i
-
1
]
-
t_steps
[
i
-
2
])
h_n_3
=
(
t_steps
[
i
-
2
]
-
t_steps
[
i
-
3
])
temp1
=
(
1
-
h_n
/
(
3
*
(
h_n
+
h_n_1
))
*
(
h_n
*
(
h_n
+
h_n_1
))
/
(
h_n_1
*
(
h_n_1
+
h_n_2
)))
/
2
temp2
=
((
1
-
h_n
/
(
3
*
(
h_n
+
h_n_1
)))
/
2
+
(
1
-
h_n
/
(
2
*
(
h_n
+
h_n_1
)))
*
h_n
/
(
6
*
(
h_n
+
h_n_1
+
h_n_2
)))
\
*
(
h_n
*
(
h_n
+
h_n_1
)
*
(
h_n
+
h_n_1
+
h_n_2
))
/
(
h_n_1
*
(
h_n_1
+
h_n_2
)
*
(
h_n_1
+
h_n_2
+
h_n_3
))
coeff1
=
(
2
+
(
h_n
/
h_n_1
))
/
2
+
temp1
+
temp2
coeff2
=
-
(
h_n
/
h_n_1
)
/
2
-
(
1
+
h_n_1
/
h_n_2
)
*
temp1
-
(
1
+
(
h_n_1
/
h_n_2
)
+
(
h_n_1
*
(
h_n_1
+
h_n_2
)
/
(
h_n_2
*
(
h_n_2
+
h_n_3
))))
*
temp2
coeff3
=
temp1
*
h_n_1
/
h_n_2
+
((
h_n_1
/
h_n_2
)
+
(
h_n_1
*
(
h_n_1
+
h_n_2
)
/
(
h_n_2
*
(
h_n_2
+
h_n_3
)))
*
(
1
+
h_n_2
/
h_n_3
))
*
temp2
coeff4
=
-
temp2
*
(
h_n_1
*
(
h_n_1
+
h_n_2
)
/
(
h_n_2
*
(
h_n_2
+
h_n_3
)))
*
h_n_1
/
h_n_2
x_next
=
x_cur
+
(
t_next
-
t_cur
)
*
(
coeff1
*
d_cur
+
coeff2
*
buffer_model
[
-
1
]
+
coeff3
*
buffer_model
[
-
2
]
+
coeff4
*
buffer_model
[
-
3
])
if
len
(
buffer_model
)
==
max_order
-
1
:
for
k
in
range
(
max_order
-
2
):
buffer_model
[
k
]
=
buffer_model
[
k
+
1
]
buffer_model
[
-
1
]
=
d_cur
.
detach
()
else
:
buffer_model
.
append
(
d_cur
.
detach
())
return
x_next
comfy/samplers.py
View file @
d5efde89
...
...
@@ -540,7 +540,7 @@ class Sampler:
KSAMPLER_NAMES
=
[
"euler"
,
"euler_ancestral"
,
"heun"
,
"heunpp2"
,
"dpm_2"
,
"dpm_2_ancestral"
,
"lms"
,
"dpm_fast"
,
"dpm_adaptive"
,
"dpmpp_2s_ancestral"
,
"dpmpp_sde"
,
"dpmpp_sde_gpu"
,
"dpmpp_2m"
,
"dpmpp_2m_sde"
,
"dpmpp_2m_sde_gpu"
,
"dpmpp_3m_sde"
,
"dpmpp_3m_sde_gpu"
,
"ddpm"
,
"lcm"
,
"ipndm"
]
"ipndm"
,
"ipndm_v"
]
class
KSAMPLER
(
Sampler
):
def
__init__
(
self
,
sampler_function
,
extra_options
=
{},
inpaint_options
=
{}):
...
...
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