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
OpenDAS
diffusers
Commits
7271f8b7
Unverified
Commit
7271f8b7
authored
Oct 03, 2023
by
Patrick von Platen
Committed by
GitHub
Oct 03, 2023
Browse files
Fix UniPC scheduler for 1D (#5276)
parent
dfcce3ca
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
27 additions
and
36 deletions
+27
-36
src/diffusers/schedulers/scheduling_ddim.py
src/diffusers/schedulers/scheduling_ddim.py
+3
-4
src/diffusers/schedulers/scheduling_ddim_parallel.py
src/diffusers/schedulers/scheduling_ddim_parallel.py
+3
-4
src/diffusers/schedulers/scheduling_ddpm.py
src/diffusers/schedulers/scheduling_ddpm.py
+3
-4
src/diffusers/schedulers/scheduling_ddpm_parallel.py
src/diffusers/schedulers/scheduling_ddpm_parallel.py
+3
-4
src/diffusers/schedulers/scheduling_deis_multistep.py
src/diffusers/schedulers/scheduling_deis_multistep.py
+3
-4
src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
+3
-4
src/diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py
...sers/schedulers/scheduling_dpmsolver_multistep_inverse.py
+3
-4
src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
+3
-4
src/diffusers/schedulers/scheduling_unipc_multistep.py
src/diffusers/schedulers/scheduling_unipc_multistep.py
+3
-4
No files found.
src/diffusers/schedulers/scheduling_ddim.py
View file @
7271f8b7
...
...
@@ -276,13 +276,13 @@ class DDIMScheduler(SchedulerMixin, ConfigMixin):
https://arxiv.org/abs/2205.11487
"""
dtype
=
sample
.
dtype
batch_size
,
channels
,
height
,
width
=
sample
.
shape
batch_size
,
channels
,
*
remaining_dims
=
sample
.
shape
if
dtype
not
in
(
torch
.
float32
,
torch
.
float64
):
sample
=
sample
.
float
()
# upcast for quantile calculation, and clamp not implemented for cpu half
# Flatten sample for doing quantile calculation along each image
sample
=
sample
.
reshape
(
batch_size
,
channels
*
height
*
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
*
np
.
prod
(
remaining_dims
)
)
abs_sample
=
sample
.
abs
()
# "a certain percentile absolute pixel value"
...
...
@@ -290,11 +290,10 @@ class DDIMScheduler(SchedulerMixin, ConfigMixin):
s
=
torch
.
clamp
(
s
,
min
=
1
,
max
=
self
.
config
.
sample_max_value
)
# When clamped to min=1, equivalent to standard clipping to [-1, 1]
s
=
s
.
unsqueeze
(
1
)
# (batch_size, 1) because clamp will broadcast along dim=0
sample
=
torch
.
clamp
(
sample
,
-
s
,
s
)
/
s
# "we threshold xt0 to the range [-s, s] and then divide by s"
sample
=
sample
.
reshape
(
batch_size
,
channels
,
height
,
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
,
*
remaining_dims
)
sample
=
sample
.
to
(
dtype
)
return
sample
...
...
src/diffusers/schedulers/scheduling_ddim_parallel.py
View file @
7271f8b7
...
...
@@ -298,13 +298,13 @@ class DDIMParallelScheduler(SchedulerMixin, ConfigMixin):
https://arxiv.org/abs/2205.11487
"""
dtype
=
sample
.
dtype
batch_size
,
channels
,
height
,
width
=
sample
.
shape
batch_size
,
channels
,
*
remaining_dims
=
sample
.
shape
if
dtype
not
in
(
torch
.
float32
,
torch
.
float64
):
sample
=
sample
.
float
()
# upcast for quantile calculation, and clamp not implemented for cpu half
# Flatten sample for doing quantile calculation along each image
sample
=
sample
.
reshape
(
batch_size
,
channels
*
height
*
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
*
np
.
prod
(
remaining_dims
)
)
abs_sample
=
sample
.
abs
()
# "a certain percentile absolute pixel value"
...
...
@@ -312,11 +312,10 @@ class DDIMParallelScheduler(SchedulerMixin, ConfigMixin):
s
=
torch
.
clamp
(
s
,
min
=
1
,
max
=
self
.
config
.
sample_max_value
)
# When clamped to min=1, equivalent to standard clipping to [-1, 1]
s
=
s
.
unsqueeze
(
1
)
# (batch_size, 1) because clamp will broadcast along dim=0
sample
=
torch
.
clamp
(
sample
,
-
s
,
s
)
/
s
# "we threshold xt0 to the range [-s, s] and then divide by s"
sample
=
sample
.
reshape
(
batch_size
,
channels
,
height
,
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
,
*
remaining_dims
)
sample
=
sample
.
to
(
dtype
)
return
sample
...
...
src/diffusers/schedulers/scheduling_ddpm.py
View file @
7271f8b7
...
...
@@ -330,13 +330,13 @@ class DDPMScheduler(SchedulerMixin, ConfigMixin):
https://arxiv.org/abs/2205.11487
"""
dtype
=
sample
.
dtype
batch_size
,
channels
,
height
,
width
=
sample
.
shape
batch_size
,
channels
,
*
remaining_dims
=
sample
.
shape
if
dtype
not
in
(
torch
.
float32
,
torch
.
float64
):
sample
=
sample
.
float
()
# upcast for quantile calculation, and clamp not implemented for cpu half
# Flatten sample for doing quantile calculation along each image
sample
=
sample
.
reshape
(
batch_size
,
channels
*
height
*
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
*
np
.
prod
(
remaining_dims
)
)
abs_sample
=
sample
.
abs
()
# "a certain percentile absolute pixel value"
...
...
@@ -344,11 +344,10 @@ class DDPMScheduler(SchedulerMixin, ConfigMixin):
s
=
torch
.
clamp
(
s
,
min
=
1
,
max
=
self
.
config
.
sample_max_value
)
# When clamped to min=1, equivalent to standard clipping to [-1, 1]
s
=
s
.
unsqueeze
(
1
)
# (batch_size, 1) because clamp will broadcast along dim=0
sample
=
torch
.
clamp
(
sample
,
-
s
,
s
)
/
s
# "we threshold xt0 to the range [-s, s] and then divide by s"
sample
=
sample
.
reshape
(
batch_size
,
channels
,
height
,
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
,
*
remaining_dims
)
sample
=
sample
.
to
(
dtype
)
return
sample
...
...
src/diffusers/schedulers/scheduling_ddpm_parallel.py
View file @
7271f8b7
...
...
@@ -344,13 +344,13 @@ class DDPMParallelScheduler(SchedulerMixin, ConfigMixin):
https://arxiv.org/abs/2205.11487
"""
dtype
=
sample
.
dtype
batch_size
,
channels
,
height
,
width
=
sample
.
shape
batch_size
,
channels
,
*
remaining_dims
=
sample
.
shape
if
dtype
not
in
(
torch
.
float32
,
torch
.
float64
):
sample
=
sample
.
float
()
# upcast for quantile calculation, and clamp not implemented for cpu half
# Flatten sample for doing quantile calculation along each image
sample
=
sample
.
reshape
(
batch_size
,
channels
*
height
*
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
*
np
.
prod
(
remaining_dims
)
)
abs_sample
=
sample
.
abs
()
# "a certain percentile absolute pixel value"
...
...
@@ -358,11 +358,10 @@ class DDPMParallelScheduler(SchedulerMixin, ConfigMixin):
s
=
torch
.
clamp
(
s
,
min
=
1
,
max
=
self
.
config
.
sample_max_value
)
# When clamped to min=1, equivalent to standard clipping to [-1, 1]
s
=
s
.
unsqueeze
(
1
)
# (batch_size, 1) because clamp will broadcast along dim=0
sample
=
torch
.
clamp
(
sample
,
-
s
,
s
)
/
s
# "we threshold xt0 to the range [-s, s] and then divide by s"
sample
=
sample
.
reshape
(
batch_size
,
channels
,
height
,
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
,
*
remaining_dims
)
sample
=
sample
.
to
(
dtype
)
return
sample
...
...
src/diffusers/schedulers/scheduling_deis_multistep.py
View file @
7271f8b7
...
...
@@ -268,13 +268,13 @@ class DEISMultistepScheduler(SchedulerMixin, ConfigMixin):
https://arxiv.org/abs/2205.11487
"""
dtype
=
sample
.
dtype
batch_size
,
channels
,
height
,
width
=
sample
.
shape
batch_size
,
channels
,
*
remaining_dims
=
sample
.
shape
if
dtype
not
in
(
torch
.
float32
,
torch
.
float64
):
sample
=
sample
.
float
()
# upcast for quantile calculation, and clamp not implemented for cpu half
# Flatten sample for doing quantile calculation along each image
sample
=
sample
.
reshape
(
batch_size
,
channels
*
height
*
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
*
np
.
prod
(
remaining_dims
)
)
abs_sample
=
sample
.
abs
()
# "a certain percentile absolute pixel value"
...
...
@@ -282,11 +282,10 @@ class DEISMultistepScheduler(SchedulerMixin, ConfigMixin):
s
=
torch
.
clamp
(
s
,
min
=
1
,
max
=
self
.
config
.
sample_max_value
)
# When clamped to min=1, equivalent to standard clipping to [-1, 1]
s
=
s
.
unsqueeze
(
1
)
# (batch_size, 1) because clamp will broadcast along dim=0
sample
=
torch
.
clamp
(
sample
,
-
s
,
s
)
/
s
# "we threshold xt0 to the range [-s, s] and then divide by s"
sample
=
sample
.
reshape
(
batch_size
,
channels
,
height
,
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
,
*
remaining_dims
)
sample
=
sample
.
to
(
dtype
)
return
sample
...
...
src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
View file @
7271f8b7
...
...
@@ -288,13 +288,13 @@ class DPMSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
https://arxiv.org/abs/2205.11487
"""
dtype
=
sample
.
dtype
batch_size
,
channels
,
height
,
width
=
sample
.
shape
batch_size
,
channels
,
*
remaining_dims
=
sample
.
shape
if
dtype
not
in
(
torch
.
float32
,
torch
.
float64
):
sample
=
sample
.
float
()
# upcast for quantile calculation, and clamp not implemented for cpu half
# Flatten sample for doing quantile calculation along each image
sample
=
sample
.
reshape
(
batch_size
,
channels
*
height
*
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
*
np
.
prod
(
remaining_dims
)
)
abs_sample
=
sample
.
abs
()
# "a certain percentile absolute pixel value"
...
...
@@ -302,11 +302,10 @@ class DPMSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
s
=
torch
.
clamp
(
s
,
min
=
1
,
max
=
self
.
config
.
sample_max_value
)
# When clamped to min=1, equivalent to standard clipping to [-1, 1]
s
=
s
.
unsqueeze
(
1
)
# (batch_size, 1) because clamp will broadcast along dim=0
sample
=
torch
.
clamp
(
sample
,
-
s
,
s
)
/
s
# "we threshold xt0 to the range [-s, s] and then divide by s"
sample
=
sample
.
reshape
(
batch_size
,
channels
,
height
,
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
,
*
remaining_dims
)
sample
=
sample
.
to
(
dtype
)
return
sample
...
...
src/diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py
View file @
7271f8b7
...
...
@@ -298,13 +298,13 @@ class DPMSolverMultistepInverseScheduler(SchedulerMixin, ConfigMixin):
https://arxiv.org/abs/2205.11487
"""
dtype
=
sample
.
dtype
batch_size
,
channels
,
height
,
width
=
sample
.
shape
batch_size
,
channels
,
*
remaining_dims
=
sample
.
shape
if
dtype
not
in
(
torch
.
float32
,
torch
.
float64
):
sample
=
sample
.
float
()
# upcast for quantile calculation, and clamp not implemented for cpu half
# Flatten sample for doing quantile calculation along each image
sample
=
sample
.
reshape
(
batch_size
,
channels
*
height
*
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
*
np
.
prod
(
remaining_dims
)
)
abs_sample
=
sample
.
abs
()
# "a certain percentile absolute pixel value"
...
...
@@ -312,11 +312,10 @@ class DPMSolverMultistepInverseScheduler(SchedulerMixin, ConfigMixin):
s
=
torch
.
clamp
(
s
,
min
=
1
,
max
=
self
.
config
.
sample_max_value
)
# When clamped to min=1, equivalent to standard clipping to [-1, 1]
s
=
s
.
unsqueeze
(
1
)
# (batch_size, 1) because clamp will broadcast along dim=0
sample
=
torch
.
clamp
(
sample
,
-
s
,
s
)
/
s
# "we threshold xt0 to the range [-s, s] and then divide by s"
sample
=
sample
.
reshape
(
batch_size
,
channels
,
height
,
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
,
*
remaining_dims
)
sample
=
sample
.
to
(
dtype
)
return
sample
...
...
src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
View file @
7271f8b7
...
...
@@ -302,13 +302,13 @@ class DPMSolverSinglestepScheduler(SchedulerMixin, ConfigMixin):
https://arxiv.org/abs/2205.11487
"""
dtype
=
sample
.
dtype
batch_size
,
channels
,
height
,
width
=
sample
.
shape
batch_size
,
channels
,
*
remaining_dims
=
sample
.
shape
if
dtype
not
in
(
torch
.
float32
,
torch
.
float64
):
sample
=
sample
.
float
()
# upcast for quantile calculation, and clamp not implemented for cpu half
# Flatten sample for doing quantile calculation along each image
sample
=
sample
.
reshape
(
batch_size
,
channels
*
height
*
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
*
np
.
prod
(
remaining_dims
)
)
abs_sample
=
sample
.
abs
()
# "a certain percentile absolute pixel value"
...
...
@@ -316,11 +316,10 @@ class DPMSolverSinglestepScheduler(SchedulerMixin, ConfigMixin):
s
=
torch
.
clamp
(
s
,
min
=
1
,
max
=
self
.
config
.
sample_max_value
)
# When clamped to min=1, equivalent to standard clipping to [-1, 1]
s
=
s
.
unsqueeze
(
1
)
# (batch_size, 1) because clamp will broadcast along dim=0
sample
=
torch
.
clamp
(
sample
,
-
s
,
s
)
/
s
# "we threshold xt0 to the range [-s, s] and then divide by s"
sample
=
sample
.
reshape
(
batch_size
,
channels
,
height
,
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
,
*
remaining_dims
)
sample
=
sample
.
to
(
dtype
)
return
sample
...
...
src/diffusers/schedulers/scheduling_unipc_multistep.py
View file @
7271f8b7
...
...
@@ -282,13 +282,13 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
https://arxiv.org/abs/2205.11487
"""
dtype
=
sample
.
dtype
batch_size
,
channels
,
height
,
width
=
sample
.
shape
batch_size
,
channels
,
*
remaining_dims
=
sample
.
shape
if
dtype
not
in
(
torch
.
float32
,
torch
.
float64
):
sample
=
sample
.
float
()
# upcast for quantile calculation, and clamp not implemented for cpu half
# Flatten sample for doing quantile calculation along each image
sample
=
sample
.
reshape
(
batch_size
,
channels
*
height
*
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
*
np
.
prod
(
remaining_dims
)
)
abs_sample
=
sample
.
abs
()
# "a certain percentile absolute pixel value"
...
...
@@ -296,11 +296,10 @@ class UniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
s
=
torch
.
clamp
(
s
,
min
=
1
,
max
=
self
.
config
.
sample_max_value
)
# When clamped to min=1, equivalent to standard clipping to [-1, 1]
s
=
s
.
unsqueeze
(
1
)
# (batch_size, 1) because clamp will broadcast along dim=0
sample
=
torch
.
clamp
(
sample
,
-
s
,
s
)
/
s
# "we threshold xt0 to the range [-s, s] and then divide by s"
sample
=
sample
.
reshape
(
batch_size
,
channels
,
height
,
width
)
sample
=
sample
.
reshape
(
batch_size
,
channels
,
*
remaining_dims
)
sample
=
sample
.
to
(
dtype
)
return
sample
...
...
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