Skip to content

Commit 8482cc6

Browse files
committed
update
1 parent f20aba3 commit 8482cc6

File tree

3 files changed

+40
-115
lines changed

3 files changed

+40
-115
lines changed

tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3.py

Lines changed: 15 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -124,37 +124,22 @@ def get_dummy_inputs(self, device, seed=0):
124124
}
125125
return inputs
126126

127-
def test_stable_diffusion_3_different_prompts(self):
128-
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
129-
130-
inputs = self.get_dummy_inputs(torch_device)
131-
output_same_prompt = pipe(**inputs).images[0]
132-
133-
inputs = self.get_dummy_inputs(torch_device)
134-
inputs["prompt_2"] = "a different prompt"
135-
inputs["prompt_3"] = "another different prompt"
136-
output_different_prompts = pipe(**inputs).images[0]
137-
138-
max_diff = np.abs(output_same_prompt - output_different_prompts).max()
139-
140-
# Outputs should be different here
141-
assert max_diff > 1e-2
142-
143-
def test_stable_diffusion_3_different_negative_prompts(self):
144-
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
145-
146-
inputs = self.get_dummy_inputs(torch_device)
147-
output_same_prompt = pipe(**inputs).images[0]
127+
def test_inference(self):
128+
components = self.get_dummy_components()
129+
pipe = self.pipeline_class(**components)
148130

149131
inputs = self.get_dummy_inputs(torch_device)
150-
inputs["negative_prompt_2"] = "deformed"
151-
inputs["negative_prompt_3"] = "blurry"
152-
output_different_prompts = pipe(**inputs).images[0]
132+
image = pipe(**inputs).images[0]
133+
generated_slice = image.flatten()
134+
generated_slice = np.concatenate([generated_slice[:8], generated_slice[-8:]])
153135

154-
max_diff = np.abs(output_same_prompt - output_different_prompts).max()
136+
# fmt: off
137+
expected_slice = np.array([0.5112, 0.5228, 0.5235, 0.5524, 0.3188, 0.5017, 0.5574, 0.4899, 0.6812, 0.5991, 0.3908, 0.5213, 0.5582, 0.4457, 0.4204, 0.5616])
138+
# fmt: on
155139

156-
# Outputs should be different here
157-
assert max_diff > 1e-2
140+
self.assertTrue(
141+
np.allclose(generated_slice, expected_slice, atol=1e-3), "Output does not match expected slice."
142+
)
158143

159144
def test_fused_qkv_projections(self):
160145
device = "cpu" # ensure determinism for the device-dependent torch.Generator
@@ -268,40 +253,9 @@ def test_sd3_inference(self):
268253

269254
image = pipe(**inputs).images[0]
270255
image_slice = image[0, :10, :10]
271-
expected_slice = np.array(
272-
[
273-
0.4648,
274-
0.4404,
275-
0.4177,
276-
0.5063,
277-
0.4800,
278-
0.4287,
279-
0.5425,
280-
0.5190,
281-
0.4717,
282-
0.5430,
283-
0.5195,
284-
0.4766,
285-
0.5361,
286-
0.5122,
287-
0.4612,
288-
0.4871,
289-
0.4749,
290-
0.4058,
291-
0.4756,
292-
0.4678,
293-
0.3804,
294-
0.4832,
295-
0.4822,
296-
0.3799,
297-
0.5103,
298-
0.5034,
299-
0.3953,
300-
0.5073,
301-
0.4839,
302-
0.3884,
303-
]
304-
)
256+
# fmt: off
257+
expected_slice = np.array([0.4648, 0.4404, 0.4177, 0.5063, 0.4800, 0.4287, 0.5425, 0.5190, 0.4717, 0.5430, 0.5195, 0.4766, 0.5361, 0.5122, 0.4612, 0.4871, 0.4749, 0.4058, 0.4756, 0.4678, 0.3804, 0.4832, 0.4822, 0.3799, 0.5103, 0.5034, 0.3953, 0.5073, 0.4839, 0.3884])
258+
# fmt: on
305259

306260
max_diff = numpy_cosine_similarity_distance(expected_slice.flatten(), image_slice.flatten())
307261

tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_img2img.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -128,37 +128,22 @@ def get_dummy_inputs(self, device, seed=0):
128128
}
129129
return inputs
130130

131-
def test_stable_diffusion_3_img2img_different_prompts(self):
132-
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
131+
def test_inference(self):
132+
components = self.get_dummy_components()
133+
pipe = self.pipeline_class(**components)
133134

134135
inputs = self.get_dummy_inputs(torch_device)
135-
output_same_prompt = pipe(**inputs).images[0]
136-
137-
inputs = self.get_dummy_inputs(torch_device)
138-
inputs["prompt_2"] = "a different prompt"
139-
inputs["prompt_3"] = "another different prompt"
140-
output_different_prompts = pipe(**inputs).images[0]
141-
142-
max_diff = np.abs(output_same_prompt - output_different_prompts).max()
143-
144-
# Outputs should be different here
145-
assert max_diff > 1e-2
146-
147-
def test_stable_diffusion_3_img2img_different_negative_prompts(self):
148-
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
149-
150-
inputs = self.get_dummy_inputs(torch_device)
151-
output_same_prompt = pipe(**inputs).images[0]
152-
153-
inputs = self.get_dummy_inputs(torch_device)
154-
inputs["negative_prompt_2"] = "deformed"
155-
inputs["negative_prompt_3"] = "blurry"
156-
output_different_prompts = pipe(**inputs).images[0]
136+
image = pipe(**inputs).images[0]
137+
generated_slice = image.flatten()
138+
generated_slice = np.concatenate([generated_slice[:8], generated_slice[-8:]])
157139

158-
max_diff = np.abs(output_same_prompt - output_different_prompts).max()
140+
# fmt: off
141+
expected_slice = np.array([0.4564, 0.5486, 0.4868, 0.5923, 0.3775, 0.5543, 0.4807, 0.4177, 0.3778, 0.5957, 0.5726, 0.4333, 0.6312, 0.5062, 0.4838, 0.5984])
142+
# fmt: on
159143

160-
# Outputs should be different here
161-
assert max_diff > 1e-2
144+
self.assertTrue(
145+
np.allclose(generated_slice, expected_slice, atol=1e-3), "Output does not match expected slice."
146+
)
162147

163148
@unittest.skip("Skip for now.")
164149
def test_multi_vae(self):

tests/pipelines/stable_diffusion_3/test_pipeline_stable_diffusion_3_inpaint.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -132,37 +132,23 @@ def get_dummy_inputs(self, device, seed=0):
132132
}
133133
return inputs
134134

135-
def test_stable_diffusion_3_inpaint_different_prompts(self):
136-
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
135+
def test_inference(self):
136+
components = self.get_dummy_components()
137+
pipe = self.pipeline_class(**components)
137138

138139
inputs = self.get_dummy_inputs(torch_device)
139-
output_same_prompt = pipe(**inputs).images[0]
140+
image = pipe(**inputs).images[0]
141+
generated_slice = image.flatten()
142+
generated_slice = np.concatenate([generated_slice[:8], generated_slice[-8:]])
140143

141-
inputs = self.get_dummy_inputs(torch_device)
142-
inputs["prompt_2"] = "a different prompt"
143-
inputs["prompt_3"] = "another different prompt"
144-
output_different_prompts = pipe(**inputs).images[0]
145-
146-
max_diff = np.abs(output_same_prompt - output_different_prompts).max()
147-
148-
# Outputs should be different here
149-
assert max_diff > 1e-2
150-
151-
def test_stable_diffusion_3_inpaint_different_negative_prompts(self):
152-
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
153-
154-
inputs = self.get_dummy_inputs(torch_device)
155-
output_same_prompt = pipe(**inputs).images[0]
156-
157-
inputs = self.get_dummy_inputs(torch_device)
158-
inputs["negative_prompt_2"] = "deformed"
159-
inputs["negative_prompt_3"] = "blurry"
160-
output_different_prompts = pipe(**inputs).images[0]
144+
# fmt: off
145+
expected_slice = np.array([0.5035, 0.6661, 0.5859, 0.413, 0.4224, 0.4234, 0.7181, 0.5062, 0.5183, 0.6877, 0.5074, 0.585, 0.6111, 0.5422, 0.5306, 0.5891])
146+
# fmt: on
161147

162-
max_diff = np.abs(output_same_prompt - output_different_prompts).max()
163-
164-
# Outputs should be different here
165-
assert max_diff > 1e-2
148+
self.assertTrue(
149+
np.allclose(generated_slice, expected_slice, atol=1e-3), "Output does not match expected slice."
150+
)
166151

152+
@unittest.skip("Skip for now.")
167153
def test_multi_vae(self):
168154
pass

0 commit comments

Comments
 (0)