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
c661a8b1
Commit
c661a8b1
authored
Feb 07, 2024
by
comfyanonymous
Browse files
Don't use numpy for calculating sigmas.
parent
7daad468
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
7 deletions
+5
-7
comfy/ldm/modules/diffusionmodules/util.py
comfy/ldm/modules/diffusionmodules/util.py
+2
-2
comfy/model_sampling.py
comfy/model_sampling.py
+3
-5
No files found.
comfy/ldm/modules/diffusionmodules/util.py
View file @
c661a8b1
...
@@ -98,7 +98,7 @@ def make_beta_schedule(schedule, n_timestep, linear_start=1e-4, linear_end=2e-2,
...
@@ -98,7 +98,7 @@ def make_beta_schedule(schedule, n_timestep, linear_start=1e-4, linear_end=2e-2,
alphas
=
torch
.
cos
(
alphas
).
pow
(
2
)
alphas
=
torch
.
cos
(
alphas
).
pow
(
2
)
alphas
=
alphas
/
alphas
[
0
]
alphas
=
alphas
/
alphas
[
0
]
betas
=
1
-
alphas
[
1
:]
/
alphas
[:
-
1
]
betas
=
1
-
alphas
[
1
:]
/
alphas
[:
-
1
]
betas
=
np
.
cl
i
p
(
betas
,
a_
min
=
0
,
a_
max
=
0.999
)
betas
=
torch
.
cl
am
p
(
betas
,
min
=
0
,
max
=
0.999
)
elif
schedule
==
"squaredcos_cap_v2"
:
# used for karlo prior
elif
schedule
==
"squaredcos_cap_v2"
:
# used for karlo prior
# return early
# return early
...
@@ -113,7 +113,7 @@ def make_beta_schedule(schedule, n_timestep, linear_start=1e-4, linear_end=2e-2,
...
@@ -113,7 +113,7 @@ def make_beta_schedule(schedule, n_timestep, linear_start=1e-4, linear_end=2e-2,
betas
=
torch
.
linspace
(
linear_start
,
linear_end
,
n_timestep
,
dtype
=
torch
.
float64
)
**
0.5
betas
=
torch
.
linspace
(
linear_start
,
linear_end
,
n_timestep
,
dtype
=
torch
.
float64
)
**
0.5
else
:
else
:
raise
ValueError
(
f
"schedule '
{
schedule
}
' unknown."
)
raise
ValueError
(
f
"schedule '
{
schedule
}
' unknown."
)
return
betas
.
numpy
()
return
betas
def
make_ddim_timesteps
(
ddim_discr_method
,
num_ddim_timesteps
,
num_ddpm_timesteps
,
verbose
=
True
):
def
make_ddim_timesteps
(
ddim_discr_method
,
num_ddim_timesteps
,
num_ddpm_timesteps
,
verbose
=
True
):
...
...
comfy/model_sampling.py
View file @
c661a8b1
import
torch
import
torch
import
numpy
as
np
from
comfy.ldm.modules.diffusionmodules.util
import
make_beta_schedule
from
comfy.ldm.modules.diffusionmodules.util
import
make_beta_schedule
import
math
import
math
...
@@ -42,8 +41,7 @@ class ModelSamplingDiscrete(torch.nn.Module):
...
@@ -42,8 +41,7 @@ class ModelSamplingDiscrete(torch.nn.Module):
else
:
else
:
betas
=
make_beta_schedule
(
beta_schedule
,
timesteps
,
linear_start
=
linear_start
,
linear_end
=
linear_end
,
cosine_s
=
cosine_s
)
betas
=
make_beta_schedule
(
beta_schedule
,
timesteps
,
linear_start
=
linear_start
,
linear_end
=
linear_end
,
cosine_s
=
cosine_s
)
alphas
=
1.
-
betas
alphas
=
1.
-
betas
alphas_cumprod
=
torch
.
tensor
(
np
.
cumprod
(
alphas
,
axis
=
0
),
dtype
=
torch
.
float32
)
alphas_cumprod
=
torch
.
cumprod
(
alphas
,
dim
=
0
)
# alphas_cumprod_prev = np.append(1., alphas_cumprod[:-1])
timesteps
,
=
betas
.
shape
timesteps
,
=
betas
.
shape
self
.
num_timesteps
=
int
(
timesteps
)
self
.
num_timesteps
=
int
(
timesteps
)
...
@@ -58,8 +56,8 @@ class ModelSamplingDiscrete(torch.nn.Module):
...
@@ -58,8 +56,8 @@ class ModelSamplingDiscrete(torch.nn.Module):
self
.
set_sigmas
(
sigmas
)
self
.
set_sigmas
(
sigmas
)
def
set_sigmas
(
self
,
sigmas
):
def
set_sigmas
(
self
,
sigmas
):
self
.
register_buffer
(
'sigmas'
,
sigmas
)
self
.
register_buffer
(
'sigmas'
,
sigmas
.
float
()
)
self
.
register_buffer
(
'log_sigmas'
,
sigmas
.
log
())
self
.
register_buffer
(
'log_sigmas'
,
sigmas
.
log
()
.
float
()
)
@
property
@
property
def
sigma_min
(
self
):
def
sigma_min
(
self
):
...
...
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