Skip to content

Commit

Permalink
Fix precision related issues in Kandinsky Pipelines (huggingface#5098)
Browse files Browse the repository at this point in the history
* fix failing tests

* make style
  • Loading branch information
DN6 authored Sep 19, 2023
1 parent edcbb6f commit 431dd2f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/pipelines/kandinsky/test_kandinsky_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def test_offloads(self):
def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=1e-2)

def test_dict_tuple_outputs_equivalent(self):
super().test_dict_tuple_outputs_equivalent(expected_max_difference=5e-4)


class KandinskyPipelineImg2ImgCombinedFastTests(PipelineTesterMixin, unittest.TestCase):
pipeline_class = KandinskyImg2ImgCombinedPipeline
Expand Down Expand Up @@ -233,6 +236,9 @@ def test_offloads(self):
def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=1e-2)

def test_dict_tuple_outputs_equivalent(self):
super().test_dict_tuple_outputs_equivalent(expected_max_difference=5e-4)


class KandinskyPipelineInpaintCombinedFastTests(PipelineTesterMixin, unittest.TestCase):
pipeline_class = KandinskyInpaintCombinedPipeline
Expand Down Expand Up @@ -332,3 +338,6 @@ def test_offloads(self):

def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=1e-2)

def test_dict_tuple_outputs_equivalent(self):
super().test_dict_tuple_outputs_equivalent(expected_max_difference=5e-4)
3 changes: 3 additions & 0 deletions tests/pipelines/kandinsky/test_kandinsky_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ def test_offloads(self):
assert np.abs(image_slices[0] - image_slices[1]).max() < 1e-3
assert np.abs(image_slices[0] - image_slices[2]).max() < 1e-3

def test_dict_tuple_outputs_equivalent(self):
super().test_dict_tuple_outputs_equivalent(expected_max_difference=5e-4)


@slow
@require_torch_gpu
Expand Down
18 changes: 18 additions & 0 deletions tests/pipelines/kandinsky_v22/test_kandinsky_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def test_offloads(self):
def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=1e-2)

def test_dict_tuple_outputs_equivalent(self):
super().test_dict_tuple_outputs_equivalent(expected_max_difference=5e-4)

def test_model_cpu_offload_forward_pass(self):
super().test_model_cpu_offload_forward_pass(expected_max_diff=5e-4)


class KandinskyV22PipelineImg2ImgCombinedFastTests(PipelineTesterMixin, unittest.TestCase):
pipeline_class = KandinskyV22Img2ImgCombinedPipeline
Expand Down Expand Up @@ -237,6 +243,12 @@ def test_offloads(self):
def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=1e-2)

def test_dict_tuple_outputs_equivalent(self):
super().test_dict_tuple_outputs_equivalent(expected_max_difference=5e-4)

def test_model_cpu_offload_forward_pass(self):
super().test_model_cpu_offload_forward_pass(expected_max_diff=5e-4)


class KandinskyV22PipelineInpaintCombinedFastTests(PipelineTesterMixin, unittest.TestCase):
pipeline_class = KandinskyV22InpaintCombinedPipeline
Expand Down Expand Up @@ -336,3 +348,9 @@ def test_offloads(self):

def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=1e-2)

def test_dict_tuple_outputs_equivalent(self):
super().test_dict_tuple_outputs_equivalent(expected_max_difference=5e-4)

def test_model_cpu_offload_forward_pass(self):
super().test_model_cpu_offload_forward_pass(expected_max_diff=5e-4)
9 changes: 9 additions & 0 deletions tests/pipelines/kandinsky_v22/test_kandinsky_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ def test_kandinsky_inpaint(self):
def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=3e-3)

def test_model_cpu_offload_forward_pass(self):
super().test_inference_batch_single_identical(expected_max_diff=5e-4)

def test_save_load_optional_components(self):
super().test_save_load_optional_components(expected_max_difference=5e-4)

def test_sequential_cpu_offload_forward_pass(self):
super().test_sequential_cpu_offload_forward_pass(expected_max_diff=5e-4)


@slow
@require_torch_gpu
Expand Down

0 comments on commit 431dd2f

Please sign in to comment.