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
3fe026e0
Commit
3fe026e0
authored
Jun 13, 2022
by
anton-l
Browse files
Glide tensor format
parent
bf13b76a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
5 deletions
+12
-5
src/diffusers/pipelines/conversion_glide.py
src/diffusers/pipelines/conversion_glide.py
+1
-1
src/diffusers/pipelines/pipeline_glide.py
src/diffusers/pipelines/pipeline_glide.py
+11
-4
src/diffusers/schedulers/glide_ddim.py
src/diffusers/schedulers/glide_ddim.py
+0
-0
No files found.
src/diffusers/pipelines/conversion_glide.py
View file @
3fe026e0
...
@@ -97,7 +97,7 @@ superres_model = GLIDESuperResUNetModel(
...
@@ -97,7 +97,7 @@ superres_model = GLIDESuperResUNetModel(
superres_model
.
load_state_dict
(
ups_state_dict
,
strict
=
False
)
superres_model
.
load_state_dict
(
ups_state_dict
,
strict
=
False
)
upscale_scheduler
=
DDIMScheduler
(
timesteps
=
1000
,
beta_schedule
=
"linear"
,
beta_start
=
0.0001
,
beta_end
=
0.02
)
upscale_scheduler
=
DDIMScheduler
(
timesteps
=
1000
,
beta_schedule
=
"linear"
,
beta_start
=
0.0001
,
beta_end
=
0.02
,
tensor_format
=
"pt"
)
glide
=
GLIDE
(
glide
=
GLIDE
(
text_unet
=
text2im_model
,
text_unet
=
text2im_model
,
...
...
src/diffusers/pipelines/pipeline_glide.py
View file @
3fe026e0
...
@@ -30,7 +30,6 @@ from transformers.modeling_outputs import BaseModelOutput, BaseModelOutputWithPo
...
@@ -30,7 +30,6 @@ from transformers.modeling_outputs import BaseModelOutput, BaseModelOutputWithPo
from
transformers.modeling_utils
import
PreTrainedModel
from
transformers.modeling_utils
import
PreTrainedModel
from
transformers.utils
import
(
from
transformers.utils
import
(
ModelOutput
,
ModelOutput
,
add_start_docstrings
,
add_start_docstrings_to_model_forward
,
add_start_docstrings_to_model_forward
,
logging
,
logging
,
replace_return_docstrings
,
replace_return_docstrings
,
...
@@ -860,6 +859,9 @@ class GLIDE(DiffusionPipeline):
...
@@ -860,6 +859,9 @@ class GLIDE(DiffusionPipeline):
nonzero_mask
=
(
t
!=
0
).
float
().
view
(
-
1
,
*
([
1
]
*
(
len
(
image
.
shape
)
-
1
)))
# no noise when t == 0
nonzero_mask
=
(
t
!=
0
).
float
().
view
(
-
1
,
*
([
1
]
*
(
len
(
image
.
shape
)
-
1
)))
# no noise when t == 0
image
=
mean
+
nonzero_mask
*
torch
.
exp
(
0.5
*
log_variance
)
*
noise
image
=
mean
+
nonzero_mask
*
torch
.
exp
(
0.5
*
log_variance
)
*
noise
image
=
image
[:
1
].
permute
(
0
,
2
,
3
,
1
)
return
image
# 4. Run the upscaling step
# 4. Run the upscaling step
batch_size
=
1
batch_size
=
1
image
=
image
[:
1
]
image
=
image
[:
1
]
...
@@ -872,10 +874,10 @@ class GLIDE(DiffusionPipeline):
...
@@ -872,10 +874,10 @@ class GLIDE(DiffusionPipeline):
# Sample gaussian noise to begin loop
# Sample gaussian noise to begin loop
image
=
torch
.
randn
(
image
=
torch
.
randn
(
(
batch_size
,
self
.
unet
.
in_channels
,
self
.
unet
.
resolution
,
self
.
unet
.
resolution
),
(
batch_size
,
self
.
upscale_
unet
.
in_channels
//
2
,
self
.
upscale_
unet
.
resolution
,
self
.
upscale_
unet
.
resolution
),
generator
=
generator
,
generator
=
generator
,
)
)
image
=
image
.
to
(
torch_device
)
image
=
image
.
to
(
torch_device
)
*
upsample_temp
# See formulas (12) and (16) of DDIM paper https://arxiv.org/pdf/2010.02502.pdf
# See formulas (12) and (16) of DDIM paper https://arxiv.org/pdf/2010.02502.pdf
# Ideally, read DDIM paper in-detail understanding
# Ideally, read DDIM paper in-detail understanding
...
@@ -887,10 +889,15 @@ class GLIDE(DiffusionPipeline):
...
@@ -887,10 +889,15 @@ class GLIDE(DiffusionPipeline):
# - eta -> η
# - eta -> η
# - pred_image_direction -> "direction pointingc to x_t"
# - pred_image_direction -> "direction pointingc to x_t"
# - pred_prev_image -> "x_t-1"
# - pred_prev_image -> "x_t-1"
num_trained_timesteps
=
self
.
upscale_noise_scheduler
.
timesteps
inference_step_times
=
range
(
0
,
num_trained_timesteps
,
num_trained_timesteps
//
num_inference_steps_upscale
)
self
.
upscale_noise_scheduler
.
rescale_betas
(
num_inference_steps_upscale
)
for
t
in
tqdm
.
tqdm
(
reversed
(
range
(
num_inference_steps_upscale
)),
total
=
num_inference_steps_upscale
):
for
t
in
tqdm
.
tqdm
(
reversed
(
range
(
num_inference_steps_upscale
)),
total
=
num_inference_steps_upscale
):
# 1. predict noise residual
# 1. predict noise residual
with
torch
.
no_grad
():
with
torch
.
no_grad
():
time_input
=
torch
.
tensor
([
t
]
*
image
.
shape
[
0
],
device
=
torch_device
)
time_input
=
torch
.
tensor
([
inference_step_times
[
t
]
]
*
image
.
shape
[
0
],
device
=
torch_device
)
model_output
=
self
.
upscale_unet
(
image
,
time_input
,
low_res
)
model_output
=
self
.
upscale_unet
(
image
,
time_input
,
low_res
)
noise_residual
,
pred_variance
=
torch
.
split
(
model_output
,
3
,
dim
=
1
)
noise_residual
,
pred_variance
=
torch
.
split
(
model_output
,
3
,
dim
=
1
)
...
...
src/diffusers/schedulers/glide_ddim.py
deleted
100644 → 0
View file @
bf13b76a
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