Skip to content

Commit eb1abee

Browse files
authored
[ONNX] Fix flaky tests (huggingface#1593)
* [ONNX] Fix flaky tests * revert
1 parent 5e03692 commit eb1abee

4 files changed

+24
-5
lines changed

tests/pipelines/stable_diffusion/test_onnx_stable_diffusion.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def test_inference_default_pndm(self):
5858
sd_pipe = OnnxStableDiffusionPipeline.from_pretrained(
5959
"CompVis/stable-diffusion-v1-4",
6060
revision="onnx",
61+
safety_checker=None,
62+
feature_extractor=None,
6163
provider=self.gpu_provider,
6264
sess_options=self.gpu_options,
6365
)
@@ -82,6 +84,8 @@ def test_inference_ddim(self):
8284
"runwayml/stable-diffusion-v1-5",
8385
revision="onnx",
8486
scheduler=ddim_scheduler,
87+
safety_checker=None,
88+
feature_extractor=None,
8589
provider=self.gpu_provider,
8690
sess_options=self.gpu_options,
8791
)
@@ -105,6 +109,8 @@ def test_inference_k_lms(self):
105109
"runwayml/stable-diffusion-v1-5",
106110
revision="onnx",
107111
scheduler=lms_scheduler,
112+
safety_checker=None,
113+
feature_extractor=None,
108114
provider=self.gpu_provider,
109115
sess_options=self.gpu_options,
110116
)
@@ -147,6 +153,8 @@ def test_callback_fn(step: int, timestep: int, latents: np.ndarray) -> None:
147153
pipe = OnnxStableDiffusionPipeline.from_pretrained(
148154
"runwayml/stable-diffusion-v1-5",
149155
revision="onnx",
156+
safety_checker=None,
157+
feature_extractor=None,
150158
provider=self.gpu_provider,
151159
sess_options=self.gpu_options,
152160
)
@@ -170,9 +178,10 @@ def test_stable_diffusion_no_safety_checker(self):
170178
pipe = OnnxStableDiffusionPipeline.from_pretrained(
171179
"runwayml/stable-diffusion-v1-5",
172180
revision="onnx",
181+
safety_checker=None,
182+
feature_extractor=None,
173183
provider=self.gpu_provider,
174184
sess_options=self.gpu_options,
175-
safety_checker=None,
176185
)
177186
assert isinstance(pipe, OnnxStableDiffusionPipeline)
178187
assert pipe.safety_checker is None

tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_img2img.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def test_inference_default_pndm(self):
6262
pipe = OnnxStableDiffusionImg2ImgPipeline.from_pretrained(
6363
"CompVis/stable-diffusion-v1-4",
6464
revision="onnx",
65+
safety_checker=None,
66+
feature_extractor=None,
6567
provider=self.gpu_provider,
6668
sess_options=self.gpu_options,
6769
)
@@ -100,6 +102,8 @@ def test_inference_k_lms(self):
100102
"runwayml/stable-diffusion-v1-5",
101103
revision="onnx",
102104
scheduler=lms_scheduler,
105+
safety_checker=None,
106+
feature_extractor=None,
103107
provider=self.gpu_provider,
104108
sess_options=self.gpu_options,
105109
)
@@ -113,14 +117,14 @@ def test_inference_k_lms(self):
113117
image=init_image,
114118
strength=0.75,
115119
guidance_scale=7.5,
116-
num_inference_steps=10,
120+
num_inference_steps=20,
117121
generator=generator,
118122
output_type="np",
119123
)
120124
images = output.images
121125
image_slice = images[0, 255:258, 383:386, -1]
122126

123127
assert images.shape == (1, 512, 768, 3)
124-
expected_slice = np.array([0.7950, 0.7923, 0.7903, 0.5516, 0.5501, 0.5476, 0.4965, 0.4933, 0.4910])
128+
expected_slice = np.array([0.8043, 0.926, 0.9581, 0.8119, 0.8954, 0.913, 0.7209, 0.7463, 0.7431])
125129
# TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues
126130
assert np.abs(image_slice.flatten() - expected_slice).max() < 2e-2

tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def test_inference_default_pndm(self):
6464
pipe = OnnxStableDiffusionInpaintPipeline.from_pretrained(
6565
"runwayml/stable-diffusion-inpainting",
6666
revision="onnx",
67+
safety_checker=None,
68+
feature_extractor=None,
6769
provider=self.gpu_provider,
6870
sess_options=self.gpu_options,
6971
)
@@ -104,6 +106,8 @@ def test_inference_k_lms(self):
104106
"runwayml/stable-diffusion-inpainting",
105107
revision="onnx",
106108
scheduler=lms_scheduler,
109+
safety_checker=None,
110+
feature_extractor=None,
107111
provider=self.gpu_provider,
108112
sess_options=self.gpu_options,
109113
)
@@ -117,13 +121,13 @@ def test_inference_k_lms(self):
117121
image=init_image,
118122
mask_image=mask_image,
119123
guidance_scale=7.5,
120-
num_inference_steps=10,
124+
num_inference_steps=20,
121125
generator=generator,
122126
output_type="np",
123127
)
124128
images = output.images
125129
image_slice = images[0, 255:258, 255:258, -1]
126130

127131
assert images.shape == (1, 512, 512, 3)
128-
expected_slice = np.array([0.2520, 0.2743, 0.2643, 0.2641, 0.2517, 0.2650, 0.2498, 0.2688, 0.2529])
132+
expected_slice = np.array([0.0086, 0.0077, 0.0083, 0.0093, 0.0107, 0.0139, 0.0094, 0.0097, 0.0125])
129133
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3

tests/pipelines/stable_diffusion/test_onnx_stable_diffusion_inpaint_legacy.py

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def test_inference(self):
7070
pipe = OnnxStableDiffusionInpaintPipelineLegacy.from_pretrained(
7171
"CompVis/stable-diffusion-v1-4",
7272
revision="onnx",
73+
safety_checker=None,
74+
feature_extractor=None,
7375
provider=self.gpu_provider,
7476
sess_options=self.gpu_options,
7577
)

0 commit comments

Comments
 (0)