Unverified Commit 150142c5 authored by Dhruv Nair's avatar Dhruv Nair Committed by GitHub
Browse files

[Tests] Fix precision related issues in slow pipeline tests (#8720)

update
parent 35f45ecd
...@@ -364,9 +364,7 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin): ...@@ -364,9 +364,7 @@ class IPAdapterSDIntegrationTests(IPAdapterNightlyTestsMixin):
images = pipeline(**inputs).images images = pipeline(**inputs).images
image_slice = images[0, :3, :3, -1].flatten() image_slice = images[0, :3, :3, -1].flatten()
expected_slice = np.array( expected_slice = np.array([0.3237, 0.3186, 0.3406, 0.3154, 0.2942, 0.3220, 0.3188, 0.3528, 0.3242])
[0.32714844, 0.3239746, 0.3466797, 0.31835938, 0.30004883, 0.3251953, 0.3215332, 0.3552246, 0.3251953]
)
max_diff = numpy_cosine_similarity_distance(image_slice, expected_slice) max_diff = numpy_cosine_similarity_distance(image_slice, expected_slice)
assert max_diff < 5e-4 assert max_diff < 5e-4
...@@ -427,9 +425,7 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin): ...@@ -427,9 +425,7 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin):
images = pipeline(**inputs).images images = pipeline(**inputs).images
image_slice = images[0, :3, :3, -1].flatten() image_slice = images[0, :3, :3, -1].flatten()
expected_slice = np.array( expected_slice = np.array([0.0596, 0.0539, 0.0459, 0.0580, 0.0560, 0.0548, 0.0501, 0.0563, 0.0500])
[0.0576596, 0.05600825, 0.04479006, 0.05288461, 0.05461192, 0.05137569, 0.04867965, 0.05301541, 0.04939842]
)
max_diff = numpy_cosine_similarity_distance(image_slice, expected_slice) max_diff = numpy_cosine_similarity_distance(image_slice, expected_slice)
assert max_diff < 5e-4 assert max_diff < 5e-4
...@@ -644,9 +640,8 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin): ...@@ -644,9 +640,8 @@ class IPAdapterSDXLIntegrationTests(IPAdapterNightlyTestsMixin):
inputs["cross_attention_kwargs"]["ip_adapter_masks"] = [masks1, masks2] inputs["cross_attention_kwargs"]["ip_adapter_masks"] = [masks1, masks2]
images = pipeline(**inputs).images images = pipeline(**inputs).images
image_slice = images[0, :3, :3, -1].flatten() image_slice = images[0, :3, :3, -1].flatten()
expected_slice = np.array(
[0.23551631, 0.20476806, 0.14099443, 0.0, 0.07675594, 0.05672678, 0.0, 0.0, 0.02099729] expected_slice = np.array([0.2323, 0.1026, 0.1338, 0.0638, 0.0662, 0.0000, 0.0000, 0.0000, 0.0199])
)
max_diff = numpy_cosine_similarity_distance(image_slice, expected_slice) max_diff = numpy_cosine_similarity_distance(image_slice, expected_slice)
assert max_diff < 5e-4 assert max_diff < 5e-4
......
...@@ -348,6 +348,7 @@ class KandinskyPipelineInpaintCombinedFastTests(PipelineTesterMixin, unittest.Te ...@@ -348,6 +348,7 @@ class KandinskyPipelineInpaintCombinedFastTests(PipelineTesterMixin, unittest.Te
def test_inference_batch_single_identical(self): def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=1e-2) super().test_inference_batch_single_identical(expected_max_diff=1e-2)
@unittest.skip("Difference between FP16 and FP32 too large on CI")
def test_float16_inference(self): def test_float16_inference(self):
super().test_float16_inference(expected_max_diff=5e-1) super().test_float16_inference(expected_max_diff=5e-1)
......
...@@ -263,7 +263,7 @@ class LatentConsistencyModelImg2ImgPipelineSlowTests(unittest.TestCase): ...@@ -263,7 +263,7 @@ class LatentConsistencyModelImg2ImgPipelineSlowTests(unittest.TestCase):
assert image.shape == (1, 512, 512, 3) assert image.shape == (1, 512, 512, 3)
image_slice = image[0, -3:, -3:, -1].flatten() image_slice = image[0, -3:, -3:, -1].flatten()
expected_slice = np.array([0.1950, 0.1961, 0.2308, 0.1786, 0.1837, 0.2320, 0.1898, 0.1885, 0.2309]) expected_slice = np.array([0.3479, 0.3314, 0.3555, 0.3430, 0.3649, 0.3423, 0.3239, 0.3117, 0.3240])
assert np.abs(image_slice - expected_slice).max() < 1e-3 assert np.abs(image_slice - expected_slice).max() < 1e-3
def test_lcm_multistep(self): def test_lcm_multistep(self):
...@@ -279,5 +279,5 @@ class LatentConsistencyModelImg2ImgPipelineSlowTests(unittest.TestCase): ...@@ -279,5 +279,5 @@ class LatentConsistencyModelImg2ImgPipelineSlowTests(unittest.TestCase):
assert image.shape == (1, 512, 512, 3) assert image.shape == (1, 512, 512, 3)
image_slice = image[0, -3:, -3:, -1].flatten() image_slice = image[0, -3:, -3:, -1].flatten()
expected_slice = np.array([0.3756, 0.3816, 0.3767, 0.3718, 0.3739, 0.3735, 0.3863, 0.3803, 0.3563]) expected_slice = np.array([0.1442, 0.1201, 0.1598, 0.1281, 0.1412, 0.1502, 0.1455, 0.1544, 0.1231])
assert np.abs(image_slice - expected_slice).max() < 1e-3 assert np.abs(image_slice - expected_slice).max() < 1e-3
...@@ -201,6 +201,9 @@ class StableDiffusionAttendAndExcitePipelineFastTests( ...@@ -201,6 +201,9 @@ class StableDiffusionAttendAndExcitePipelineFastTests(
def test_karras_schedulers_shape(self): def test_karras_schedulers_shape(self):
super().test_karras_schedulers_shape(num_inference_steps_for_strength_for_iterations=3) super().test_karras_schedulers_shape(num_inference_steps_for_strength_for_iterations=3)
def test_from_pipe_consistent_forward_pass_cpu_offload(self):
super().test_from_pipe_consistent_forward_pass_cpu_offload(expected_max_diff=5e-3)
@require_torch_gpu @require_torch_gpu
@nightly @nightly
......
...@@ -361,6 +361,9 @@ class StableDiffusionFullAdapterPipelineFastTests( ...@@ -361,6 +361,9 @@ class StableDiffusionFullAdapterPipelineFastTests(
expected_slice = np.array([0.4858, 0.5500, 0.4278, 0.4669, 0.6184, 0.4322, 0.5010, 0.5033, 0.4746]) expected_slice = np.array([0.4858, 0.5500, 0.4278, 0.4669, 0.6184, 0.4322, 0.5010, 0.5033, 0.4746])
assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-3 assert np.abs(image_slice.flatten() - expected_slice).max() < 5e-3
def test_from_pipe_consistent_forward_pass_cpu_offload(self):
super().test_from_pipe_consistent_forward_pass_cpu_offload(expected_max_diff=6e-3)
class StableDiffusionLightAdapterPipelineFastTests(AdapterTests, PipelineTesterMixin, unittest.TestCase): class StableDiffusionLightAdapterPipelineFastTests(AdapterTests, PipelineTesterMixin, unittest.TestCase):
def get_dummy_components(self, time_cond_proj_dim=None): def get_dummy_components(self, time_cond_proj_dim=None):
......
...@@ -1072,8 +1072,9 @@ class StableDiffusionXLPipelineIntegrationTests(unittest.TestCase): ...@@ -1072,8 +1072,9 @@ class StableDiffusionXLPipelineIntegrationTests(unittest.TestCase):
prompt = "a red car standing on the side of the street" prompt = "a red car standing on the side of the street"
image = sd_pipe(prompt, num_inference_steps=4, guidance_scale=8.0).images[0] image = sd_pipe(
prompt, num_inference_steps=4, guidance_scale=8.0, generator=torch.Generator("cpu").manual_seed(0)
).images[0]
expected_image = load_image( expected_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/lcm_full/stable_diffusion_ssd_1b_lcm.png" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/lcm_full/stable_diffusion_ssd_1b_lcm.png"
) )
......
...@@ -786,7 +786,12 @@ class PipelineFromPipeTesterMixin: ...@@ -786,7 +786,12 @@ class PipelineFromPipeTesterMixin:
if hasattr(component, "set_default_attn_processor"): if hasattr(component, "set_default_attn_processor"):
component.set_default_attn_processor() component.set_default_attn_processor()
pipe_original.set_progress_bar_config(disable=None) pipe_original.set_progress_bar_config(disable=None)
pipe_from_original = self.pipeline_class.from_pipe(pipe_original, **current_pipe_additional_components) pipe_from_original = self.pipeline_class.from_pipe(pipe_original, **current_pipe_additional_components)
for component in pipe_from_original.components.values():
if hasattr(component, "set_default_attn_processor"):
component.set_default_attn_processor()
pipe_from_original.enable_model_cpu_offload() pipe_from_original.enable_model_cpu_offload()
pipe_from_original.set_progress_bar_config(disable=None) pipe_from_original.set_progress_bar_config(disable=None)
inputs = self.get_dummy_inputs_pipe(torch_device) inputs = self.get_dummy_inputs_pipe(torch_device)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment