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
renzhc
diffusers_dcu
Commits
a3ae4661
"vscode:/vscode.git/clone" did not exist on "d22dbec28b2dcc026b7c19a57ed71ce1ea9ed1b2"
Unverified
Commit
a3ae4661
authored
Feb 15, 2023
by
Will Berman
Committed by
GitHub
Feb 15, 2023
Browse files
schedulers add glide noising schedule (#2347)
parent
c613288c
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
226 additions
and
3 deletions
+226
-3
src/diffusers/schedulers/scheduling_ddim.py
src/diffusers/schedulers/scheduling_ddim.py
+2
-1
src/diffusers/schedulers/scheduling_deis_multistep.py
src/diffusers/schedulers/scheduling_deis_multistep.py
+1
-0
src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
+1
-0
src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
+1
-0
src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py
...ffusers/schedulers/scheduling_euler_ancestral_discrete.py
+36
-0
src/diffusers/schedulers/scheduling_euler_discrete.py
src/diffusers/schedulers/scheduling_euler_discrete.py
+37
-1
src/diffusers/schedulers/scheduling_heun_discrete.py
src/diffusers/schedulers/scheduling_heun_discrete.py
+36
-0
src/diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py
...users/schedulers/scheduling_k_dpm_2_ancestral_discrete.py
+36
-0
src/diffusers/schedulers/scheduling_k_dpm_2_discrete.py
src/diffusers/schedulers/scheduling_k_dpm_2_discrete.py
+36
-0
src/diffusers/schedulers/scheduling_lms_discrete.py
src/diffusers/schedulers/scheduling_lms_discrete.py
+36
-0
src/diffusers/schedulers/scheduling_pndm.py
src/diffusers/schedulers/scheduling_pndm.py
+1
-0
src/diffusers/schedulers/scheduling_repaint.py
src/diffusers/schedulers/scheduling_repaint.py
+1
-0
src/diffusers/schedulers/scheduling_unclip.py
src/diffusers/schedulers/scheduling_unclip.py
+1
-0
tests/pipelines/stable_diffusion_2/test_stable_diffusion_latent_upscale.py
...table_diffusion_2/test_stable_diffusion_latent_upscale.py
+1
-1
No files found.
src/diffusers/schedulers/scheduling_ddim.py
View file @
a3ae4661
...
...
@@ -46,6 +46,7 @@ class DDIMSchedulerOutput(BaseOutput):
pred_original_sample
:
Optional
[
torch
.
FloatTensor
]
=
None
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
)
->
torch
.
Tensor
:
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
...
...
@@ -72,7 +73,7 @@ def betas_for_alpha_bar(num_diffusion_timesteps, max_beta=0.999) -> torch.Tensor
t1
=
i
/
num_diffusion_timesteps
t2
=
(
i
+
1
)
/
num_diffusion_timesteps
betas
.
append
(
min
(
1
-
alpha_bar
(
t2
)
/
alpha_bar
(
t1
),
max_beta
))
return
torch
.
tensor
(
betas
)
return
torch
.
tensor
(
betas
,
dtype
=
torch
.
float32
)
class
DDIMScheduler
(
SchedulerMixin
,
ConfigMixin
):
...
...
src/diffusers/schedulers/scheduling_deis_multistep.py
View file @
a3ae4661
...
...
@@ -25,6 +25,7 @@ from ..configuration_utils import ConfigMixin, register_to_config
from
.scheduling_utils
import
KarrasDiffusionSchedulers
,
SchedulerMixin
,
SchedulerOutput
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
):
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
...
...
src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
View file @
a3ae4661
...
...
@@ -24,6 +24,7 @@ from ..configuration_utils import ConfigMixin, register_to_config
from
.scheduling_utils
import
KarrasDiffusionSchedulers
,
SchedulerMixin
,
SchedulerOutput
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
):
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
...
...
src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
View file @
a3ae4661
...
...
@@ -24,6 +24,7 @@ from ..configuration_utils import ConfigMixin, register_to_config
from
.scheduling_utils
import
KarrasDiffusionSchedulers
,
SchedulerMixin
,
SchedulerOutput
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
):
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
...
...
src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py
View file @
a3ae4661
...
...
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
from
dataclasses
import
dataclass
from
typing
import
List
,
Optional
,
Tuple
,
Union
...
...
@@ -45,6 +46,36 @@ class EulerAncestralDiscreteSchedulerOutput(BaseOutput):
pred_original_sample
:
Optional
[
torch
.
FloatTensor
]
=
None
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
)
->
torch
.
Tensor
:
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
(1-beta) over time from t = [0,1].
Contains a function alpha_bar that takes an argument t and transforms it to the cumulative product of (1-beta) up
to that part of the diffusion process.
Args:
num_diffusion_timesteps (`int`): the number of betas to produce.
max_beta (`float`): the maximum beta to use; use values lower than 1 to
prevent singularities.
Returns:
betas (`np.ndarray`): the betas used by the scheduler to step the model outputs
"""
def
alpha_bar
(
time_step
):
return
math
.
cos
((
time_step
+
0.008
)
/
1.008
*
math
.
pi
/
2
)
**
2
betas
=
[]
for
i
in
range
(
num_diffusion_timesteps
):
t1
=
i
/
num_diffusion_timesteps
t2
=
(
i
+
1
)
/
num_diffusion_timesteps
betas
.
append
(
min
(
1
-
alpha_bar
(
t2
)
/
alpha_bar
(
t1
),
max_beta
))
return
torch
.
tensor
(
betas
,
dtype
=
torch
.
float32
)
class
EulerAncestralDiscreteScheduler
(
SchedulerMixin
,
ConfigMixin
):
"""
Ancestral sampling with Euler method steps. Based on the original k-diffusion implementation by Katherine Crowson:
...
...
@@ -93,6 +124,9 @@ class EulerAncestralDiscreteScheduler(SchedulerMixin, ConfigMixin):
self
.
betas
=
(
torch
.
linspace
(
beta_start
**
0.5
,
beta_end
**
0.5
,
num_train_timesteps
,
dtype
=
torch
.
float32
)
**
2
)
elif
beta_schedule
==
"squaredcos_cap_v2"
:
# Glide cosine schedule
self
.
betas
=
betas_for_alpha_bar
(
num_train_timesteps
)
else
:
raise
NotImplementedError
(
f
"
{
beta_schedule
}
does is not implemented for
{
self
.
__class__
}
"
)
...
...
@@ -214,6 +248,8 @@ class EulerAncestralDiscreteScheduler(SchedulerMixin, ConfigMixin):
elif
self
.
config
.
prediction_type
==
"v_prediction"
:
# * c_out + input * c_skip
pred_original_sample
=
model_output
*
(
-
sigma
/
(
sigma
**
2
+
1
)
**
0.5
)
+
(
sample
/
(
sigma
**
2
+
1
))
elif
self
.
config
.
prediction_type
==
"sample"
:
raise
NotImplementedError
(
"prediction_type not implemented yet: sample"
)
else
:
raise
ValueError
(
f
"prediction_type given as
{
self
.
config
.
prediction_type
}
must be one of `epsilon`, or `v_prediction`"
...
...
src/diffusers/schedulers/scheduling_euler_discrete.py
View file @
a3ae4661
...
...
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
from
dataclasses
import
dataclass
from
typing
import
List
,
Optional
,
Tuple
,
Union
...
...
@@ -45,6 +46,36 @@ class EulerDiscreteSchedulerOutput(BaseOutput):
pred_original_sample
:
Optional
[
torch
.
FloatTensor
]
=
None
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
):
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
(1-beta) over time from t = [0,1].
Contains a function alpha_bar that takes an argument t and transforms it to the cumulative product of (1-beta) up
to that part of the diffusion process.
Args:
num_diffusion_timesteps (`int`): the number of betas to produce.
max_beta (`float`): the maximum beta to use; use values lower than 1 to
prevent singularities.
Returns:
betas (`np.ndarray`): the betas used by the scheduler to step the model outputs
"""
def
alpha_bar
(
time_step
):
return
math
.
cos
((
time_step
+
0.008
)
/
1.008
*
math
.
pi
/
2
)
**
2
betas
=
[]
for
i
in
range
(
num_diffusion_timesteps
):
t1
=
i
/
num_diffusion_timesteps
t2
=
(
i
+
1
)
/
num_diffusion_timesteps
betas
.
append
(
min
(
1
-
alpha_bar
(
t2
)
/
alpha_bar
(
t1
),
max_beta
))
return
torch
.
tensor
(
betas
,
dtype
=
torch
.
float32
)
class
EulerDiscreteScheduler
(
SchedulerMixin
,
ConfigMixin
):
"""
Euler scheduler (Algorithm 2) from Karras et al. (2022) https://arxiv.org/abs/2206.00364. . Based on the original
...
...
@@ -97,6 +128,9 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
self
.
betas
=
(
torch
.
linspace
(
beta_start
**
0.5
,
beta_end
**
0.5
,
num_train_timesteps
,
dtype
=
torch
.
float32
)
**
2
)
elif
beta_schedule
==
"squaredcos_cap_v2"
:
# Glide cosine schedule
self
.
betas
=
betas_for_alpha_bar
(
num_train_timesteps
)
else
:
raise
NotImplementedError
(
f
"
{
beta_schedule
}
does is not implemented for
{
self
.
__class__
}
"
)
...
...
@@ -245,7 +279,9 @@ class EulerDiscreteScheduler(SchedulerMixin, ConfigMixin):
sample
=
sample
+
eps
*
(
sigma_hat
**
2
-
sigma
**
2
)
**
0.5
# 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
if
self
.
config
.
prediction_type
==
"original_sample"
:
# NOTE: "original_sample" should not be an expected prediction_type but is left in for
# backwards compatibility
if
self
.
config
.
prediction_type
==
"original_sample"
or
self
.
config
.
prediction_type
==
"sample"
:
pred_original_sample
=
model_output
elif
self
.
config
.
prediction_type
==
"epsilon"
:
pred_original_sample
=
sample
-
sigma_hat
*
model_output
...
...
src/diffusers/schedulers/scheduling_heun_discrete.py
View file @
a3ae4661
...
...
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
from
typing
import
List
,
Optional
,
Tuple
,
Union
import
numpy
as
np
...
...
@@ -21,6 +22,36 @@ from ..configuration_utils import ConfigMixin, register_to_config
from
.scheduling_utils
import
KarrasDiffusionSchedulers
,
SchedulerMixin
,
SchedulerOutput
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
)
->
torch
.
Tensor
:
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
(1-beta) over time from t = [0,1].
Contains a function alpha_bar that takes an argument t and transforms it to the cumulative product of (1-beta) up
to that part of the diffusion process.
Args:
num_diffusion_timesteps (`int`): the number of betas to produce.
max_beta (`float`): the maximum beta to use; use values lower than 1 to
prevent singularities.
Returns:
betas (`np.ndarray`): the betas used by the scheduler to step the model outputs
"""
def
alpha_bar
(
time_step
):
return
math
.
cos
((
time_step
+
0.008
)
/
1.008
*
math
.
pi
/
2
)
**
2
betas
=
[]
for
i
in
range
(
num_diffusion_timesteps
):
t1
=
i
/
num_diffusion_timesteps
t2
=
(
i
+
1
)
/
num_diffusion_timesteps
betas
.
append
(
min
(
1
-
alpha_bar
(
t2
)
/
alpha_bar
(
t1
),
max_beta
))
return
torch
.
tensor
(
betas
,
dtype
=
torch
.
float32
)
class
HeunDiscreteScheduler
(
SchedulerMixin
,
ConfigMixin
):
"""
Implements Algorithm 2 (Heun steps) from Karras et al. (2022). for discrete beta schedules. Based on the original
...
...
@@ -69,6 +100,9 @@ class HeunDiscreteScheduler(SchedulerMixin, ConfigMixin):
self
.
betas
=
(
torch
.
linspace
(
beta_start
**
0.5
,
beta_end
**
0.5
,
num_train_timesteps
,
dtype
=
torch
.
float32
)
**
2
)
elif
beta_schedule
==
"squaredcos_cap_v2"
:
# Glide cosine schedule
self
.
betas
=
betas_for_alpha_bar
(
num_train_timesteps
)
else
:
raise
NotImplementedError
(
f
"
{
beta_schedule
}
does is not implemented for
{
self
.
__class__
}
"
)
...
...
@@ -197,6 +231,8 @@ class HeunDiscreteScheduler(SchedulerMixin, ConfigMixin):
pred_original_sample
=
model_output
*
(
-
sigma_input
/
(
sigma_input
**
2
+
1
)
**
0.5
)
+
(
sample
/
(
sigma_input
**
2
+
1
)
)
elif
self
.
config
.
prediction_type
==
"sample"
:
raise
NotImplementedError
(
"prediction_type not implemented yet: sample"
)
else
:
raise
ValueError
(
f
"prediction_type given as
{
self
.
config
.
prediction_type
}
must be one of `epsilon`, or `v_prediction`"
...
...
src/diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py
View file @
a3ae4661
...
...
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
from
typing
import
List
,
Optional
,
Tuple
,
Union
import
numpy
as
np
...
...
@@ -22,6 +23,36 @@ from ..utils import randn_tensor
from
.scheduling_utils
import
KarrasDiffusionSchedulers
,
SchedulerMixin
,
SchedulerOutput
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
)
->
torch
.
Tensor
:
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
(1-beta) over time from t = [0,1].
Contains a function alpha_bar that takes an argument t and transforms it to the cumulative product of (1-beta) up
to that part of the diffusion process.
Args:
num_diffusion_timesteps (`int`): the number of betas to produce.
max_beta (`float`): the maximum beta to use; use values lower than 1 to
prevent singularities.
Returns:
betas (`np.ndarray`): the betas used by the scheduler to step the model outputs
"""
def
alpha_bar
(
time_step
):
return
math
.
cos
((
time_step
+
0.008
)
/
1.008
*
math
.
pi
/
2
)
**
2
betas
=
[]
for
i
in
range
(
num_diffusion_timesteps
):
t1
=
i
/
num_diffusion_timesteps
t2
=
(
i
+
1
)
/
num_diffusion_timesteps
betas
.
append
(
min
(
1
-
alpha_bar
(
t2
)
/
alpha_bar
(
t1
),
max_beta
))
return
torch
.
tensor
(
betas
,
dtype
=
torch
.
float32
)
class
KDPM2AncestralDiscreteScheduler
(
SchedulerMixin
,
ConfigMixin
):
"""
Scheduler created by @crowsonkb in [k_diffusion](https://github.com/crowsonkb/k-diffusion), see:
...
...
@@ -71,6 +102,9 @@ class KDPM2AncestralDiscreteScheduler(SchedulerMixin, ConfigMixin):
self
.
betas
=
(
torch
.
linspace
(
beta_start
**
0.5
,
beta_end
**
0.5
,
num_train_timesteps
,
dtype
=
torch
.
float32
)
**
2
)
elif
beta_schedule
==
"squaredcos_cap_v2"
:
# Glide cosine schedule
self
.
betas
=
betas_for_alpha_bar
(
num_train_timesteps
)
else
:
raise
NotImplementedError
(
f
"
{
beta_schedule
}
does is not implemented for
{
self
.
__class__
}
"
)
...
...
@@ -254,6 +288,8 @@ class KDPM2AncestralDiscreteScheduler(SchedulerMixin, ConfigMixin):
pred_original_sample
=
model_output
*
(
-
sigma_input
/
(
sigma_input
**
2
+
1
)
**
0.5
)
+
(
sample
/
(
sigma_input
**
2
+
1
)
)
elif
self
.
config
.
prediction_type
==
"sample"
:
raise
NotImplementedError
(
"prediction_type not implemented yet: sample"
)
else
:
raise
ValueError
(
f
"prediction_type given as
{
self
.
config
.
prediction_type
}
must be one of `epsilon`, or `v_prediction`"
...
...
src/diffusers/schedulers/scheduling_k_dpm_2_discrete.py
View file @
a3ae4661
...
...
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
from
typing
import
List
,
Optional
,
Tuple
,
Union
import
numpy
as
np
...
...
@@ -21,6 +22,36 @@ from ..configuration_utils import ConfigMixin, register_to_config
from
.scheduling_utils
import
KarrasDiffusionSchedulers
,
SchedulerMixin
,
SchedulerOutput
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
)
->
torch
.
Tensor
:
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
(1-beta) over time from t = [0,1].
Contains a function alpha_bar that takes an argument t and transforms it to the cumulative product of (1-beta) up
to that part of the diffusion process.
Args:
num_diffusion_timesteps (`int`): the number of betas to produce.
max_beta (`float`): the maximum beta to use; use values lower than 1 to
prevent singularities.
Returns:
betas (`np.ndarray`): the betas used by the scheduler to step the model outputs
"""
def
alpha_bar
(
time_step
):
return
math
.
cos
((
time_step
+
0.008
)
/
1.008
*
math
.
pi
/
2
)
**
2
betas
=
[]
for
i
in
range
(
num_diffusion_timesteps
):
t1
=
i
/
num_diffusion_timesteps
t2
=
(
i
+
1
)
/
num_diffusion_timesteps
betas
.
append
(
min
(
1
-
alpha_bar
(
t2
)
/
alpha_bar
(
t1
),
max_beta
))
return
torch
.
tensor
(
betas
,
dtype
=
torch
.
float32
)
class
KDPM2DiscreteScheduler
(
SchedulerMixin
,
ConfigMixin
):
"""
Scheduler created by @crowsonkb in [k_diffusion](https://github.com/crowsonkb/k-diffusion), see:
...
...
@@ -70,6 +101,9 @@ class KDPM2DiscreteScheduler(SchedulerMixin, ConfigMixin):
self
.
betas
=
(
torch
.
linspace
(
beta_start
**
0.5
,
beta_end
**
0.5
,
num_train_timesteps
,
dtype
=
torch
.
float32
)
**
2
)
elif
beta_schedule
==
"squaredcos_cap_v2"
:
# Glide cosine schedule
self
.
betas
=
betas_for_alpha_bar
(
num_train_timesteps
)
else
:
raise
NotImplementedError
(
f
"
{
beta_schedule
}
does is not implemented for
{
self
.
__class__
}
"
)
...
...
@@ -237,6 +271,8 @@ class KDPM2DiscreteScheduler(SchedulerMixin, ConfigMixin):
pred_original_sample
=
model_output
*
(
-
sigma_input
/
(
sigma_input
**
2
+
1
)
**
0.5
)
+
(
sample
/
(
sigma_input
**
2
+
1
)
)
elif
self
.
config
.
prediction_type
==
"sample"
:
raise
NotImplementedError
(
"prediction_type not implemented yet: sample"
)
else
:
raise
ValueError
(
f
"prediction_type given as
{
self
.
config
.
prediction_type
}
must be one of `epsilon`, or `v_prediction`"
...
...
src/diffusers/schedulers/scheduling_lms_discrete.py
View file @
a3ae4661
...
...
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
import
warnings
from
dataclasses
import
dataclass
from
typing
import
List
,
Optional
,
Tuple
,
Union
...
...
@@ -43,6 +44,36 @@ class LMSDiscreteSchedulerOutput(BaseOutput):
pred_original_sample
:
Optional
[
torch
.
FloatTensor
]
=
None
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
):
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
(1-beta) over time from t = [0,1].
Contains a function alpha_bar that takes an argument t and transforms it to the cumulative product of (1-beta) up
to that part of the diffusion process.
Args:
num_diffusion_timesteps (`int`): the number of betas to produce.
max_beta (`float`): the maximum beta to use; use values lower than 1 to
prevent singularities.
Returns:
betas (`np.ndarray`): the betas used by the scheduler to step the model outputs
"""
def
alpha_bar
(
time_step
):
return
math
.
cos
((
time_step
+
0.008
)
/
1.008
*
math
.
pi
/
2
)
**
2
betas
=
[]
for
i
in
range
(
num_diffusion_timesteps
):
t1
=
i
/
num_diffusion_timesteps
t2
=
(
i
+
1
)
/
num_diffusion_timesteps
betas
.
append
(
min
(
1
-
alpha_bar
(
t2
)
/
alpha_bar
(
t1
),
max_beta
))
return
torch
.
tensor
(
betas
,
dtype
=
torch
.
float32
)
class
LMSDiscreteScheduler
(
SchedulerMixin
,
ConfigMixin
):
"""
Linear Multistep Scheduler for discrete beta schedules. Based on the original k-diffusion implementation by
...
...
@@ -91,6 +122,9 @@ class LMSDiscreteScheduler(SchedulerMixin, ConfigMixin):
self
.
betas
=
(
torch
.
linspace
(
beta_start
**
0.5
,
beta_end
**
0.5
,
num_train_timesteps
,
dtype
=
torch
.
float32
)
**
2
)
elif
beta_schedule
==
"squaredcos_cap_v2"
:
# Glide cosine schedule
self
.
betas
=
betas_for_alpha_bar
(
num_train_timesteps
)
else
:
raise
NotImplementedError
(
f
"
{
beta_schedule
}
does is not implemented for
{
self
.
__class__
}
"
)
...
...
@@ -223,6 +257,8 @@ class LMSDiscreteScheduler(SchedulerMixin, ConfigMixin):
elif
self
.
config
.
prediction_type
==
"v_prediction"
:
# * c_out + input * c_skip
pred_original_sample
=
model_output
*
(
-
sigma
/
(
sigma
**
2
+
1
)
**
0.5
)
+
(
sample
/
(
sigma
**
2
+
1
))
elif
self
.
config
.
prediction_type
==
"sample"
:
pred_original_sample
=
model_output
else
:
raise
ValueError
(
f
"prediction_type given as
{
self
.
config
.
prediction_type
}
must be one of `epsilon`, or `v_prediction`"
...
...
src/diffusers/schedulers/scheduling_pndm.py
View file @
a3ae4661
...
...
@@ -24,6 +24,7 @@ from ..configuration_utils import ConfigMixin, register_to_config
from
.scheduling_utils
import
KarrasDiffusionSchedulers
,
SchedulerMixin
,
SchedulerOutput
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
):
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
...
...
src/diffusers/schedulers/scheduling_repaint.py
View file @
a3ae4661
...
...
@@ -42,6 +42,7 @@ class RePaintSchedulerOutput(BaseOutput):
pred_original_sample
:
torch
.
FloatTensor
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
):
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
...
...
src/diffusers/schedulers/scheduling_unclip.py
View file @
a3ae4661
...
...
@@ -43,6 +43,7 @@ class UnCLIPSchedulerOutput(BaseOutput):
pred_original_sample
:
Optional
[
torch
.
FloatTensor
]
=
None
# Copied from diffusers.schedulers.scheduling_ddpm.betas_for_alpha_bar
def
betas_for_alpha_bar
(
num_diffusion_timesteps
,
max_beta
=
0.999
):
"""
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
...
...
tests/pipelines/stable_diffusion_2/test_stable_diffusion_latent_upscale.py
View file @
a3ae4661
...
...
@@ -89,7 +89,7 @@ class StableDiffusionLatentUpscalePipelineFastTests(PipelineTesterMixin, unittes
up_block_types
=
[
"UpDecoderBlock2D"
,
"UpDecoderBlock2D"
,
"UpDecoderBlock2D"
,
"UpDecoderBlock2D"
],
latent_channels
=
4
,
)
scheduler
=
EulerDiscreteScheduler
(
prediction_type
=
"
original_
sample"
)
scheduler
=
EulerDiscreteScheduler
(
prediction_type
=
"sample"
)
text_config
=
CLIPTextConfig
(
bos_token_id
=
0
,
eos_token_id
=
2
,
...
...
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