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
fcfdd95f
Unverified
Commit
fcfdd95f
authored
Nov 18, 2022
by
Patrick von Platen
Committed by
GitHub
Nov 18, 2022
Browse files
Fix/Enable all schedulers for in-painting (#1331)
* inpaint fix k lms * onnox as well * up
parent
5dcef138
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
3 deletions
+42
-3
src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py
...table_diffusion/pipeline_onnx_stable_diffusion_inpaint.py
+1
-1
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py
...nes/stable_diffusion/pipeline_stable_diffusion_inpaint.py
+1
-2
tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py
...pelines/stable_diffusion/test_stable_diffusion_inpaint.py
+40
-0
No files found.
src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py
View file @
fcfdd95f
...
...
@@ -408,8 +408,8 @@ class OnnxStableDiffusionInpaintPipeline(DiffusionPipeline):
# expand the latents if we are doing classifier free guidance
latent_model_input
=
np
.
concatenate
([
latents
]
*
2
)
if
do_classifier_free_guidance
else
latents
# concat latents, mask, masked_image_latnets in the channel dimension
latent_model_input
=
np
.
concatenate
([
latent_model_input
,
mask
,
masked_image_latents
],
axis
=
1
)
latent_model_input
=
self
.
scheduler
.
scale_model_input
(
torch
.
from_numpy
(
latent_model_input
),
t
)
latent_model_input
=
np
.
concatenate
([
latent_model_input
,
mask
,
masked_image_latents
],
axis
=
1
)
latent_model_input
=
latent_model_input
.
cpu
().
numpy
()
# predict the noise residual
...
...
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py
View file @
fcfdd95f
...
...
@@ -586,9 +586,8 @@ class StableDiffusionInpaintPipeline(DiffusionPipeline):
latent_model_input
=
torch
.
cat
([
latents
]
*
2
)
if
do_classifier_free_guidance
else
latents
# concat latents, mask, masked_image_latents in the channel dimension
latent_model_input
=
torch
.
cat
([
latent_model_input
,
mask
,
masked_image_latents
],
dim
=
1
)
latent_model_input
=
self
.
scheduler
.
scale_model_input
(
latent_model_input
,
t
)
latent_model_input
=
torch
.
cat
([
latent_model_input
,
mask
,
masked_image_latents
],
dim
=
1
)
# predict the noise residual
noise_pred
=
self
.
unet
(
latent_model_input
,
t
,
encoder_hidden_states
=
text_embeddings
).
sample
...
...
tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py
View file @
fcfdd95f
...
...
@@ -22,6 +22,7 @@ import torch
from
diffusers
import
(
AutoencoderKL
,
LMSDiscreteScheduler
,
PNDMScheduler
,
StableDiffusionInpaintPipeline
,
UNet2DConditionModel
,
...
...
@@ -421,6 +422,45 @@ class StableDiffusionInpaintPipelineIntegrationTests(unittest.TestCase):
assert
image
.
shape
==
(
512
,
512
,
3
)
assert
np
.
abs
(
expected_image
-
image
).
max
()
<
1e-2
def
test_stable_diffusion_inpaint_pipeline_k_lms
(
self
):
init_image
=
load_image
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
"/in_paint/overture-creations-5sI6fQgYIuo.png"
)
mask_image
=
load_image
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
"/in_paint/overture-creations-5sI6fQgYIuo_mask.png"
)
expected_image
=
load_numpy
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/in_paint"
"/yellow_cat_sitting_on_a_park_bench_k_lms.npy"
)
model_id
=
"runwayml/stable-diffusion-inpainting"
pipe
=
StableDiffusionInpaintPipeline
.
from_pretrained
(
model_id
,
safety_checker
=
None
)
pipe
.
to
(
torch_device
)
# switch to LMS
pipe
.
scheduler
=
LMSDiscreteScheduler
.
from_config
(
pipe
.
scheduler
.
config
)
pipe
.
set_progress_bar_config
(
disable
=
None
)
pipe
.
enable_attention_slicing
()
prompt
=
"Face of a yellow cat, high resolution, sitting on a park bench"
generator
=
torch
.
Generator
(
device
=
torch_device
).
manual_seed
(
0
)
output
=
pipe
(
prompt
=
prompt
,
image
=
init_image
,
mask_image
=
mask_image
,
generator
=
generator
,
output_type
=
"np"
,
)
image
=
output
.
images
[
0
]
assert
image
.
shape
==
(
512
,
512
,
3
)
assert
np
.
abs
(
expected_image
-
image
).
max
()
<
1e-2
@
unittest
.
skipIf
(
torch_device
==
"cpu"
,
"This test is supposed to run on GPU"
)
def
test_stable_diffusion_pipeline_with_sequential_cpu_offloading
(
self
):
torch
.
cuda
.
empty_cache
()
...
...
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