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

Update Ruff to latest Version (#10919)

* update

* update

* update

* update
parent 552cd320
...@@ -140,9 +140,9 @@ class FluxControlPipelineFastTests(unittest.TestCase, PipelineTesterMixin): ...@@ -140,9 +140,9 @@ class FluxControlPipelineFastTests(unittest.TestCase, PipelineTesterMixin):
# TODO (sayakpaul): will refactor this once `fuse_qkv_projections()` has been added # TODO (sayakpaul): will refactor this once `fuse_qkv_projections()` has been added
# to the pipeline level. # to the pipeline level.
pipe.transformer.fuse_qkv_projections() pipe.transformer.fuse_qkv_projections()
assert check_qkv_fusion_processors_exist( assert check_qkv_fusion_processors_exist(pipe.transformer), (
pipe.transformer "Something wrong with the fused attention processors. Expected all the attention processors to be fused."
), "Something wrong with the fused attention processors. Expected all the attention processors to be fused." )
assert check_qkv_fusion_matches_attn_procs_length( assert check_qkv_fusion_matches_attn_procs_length(
pipe.transformer, pipe.transformer.original_attn_processors pipe.transformer, pipe.transformer.original_attn_processors
), "Something wrong with the attention processors concerning the fused QKV projections." ), "Something wrong with the attention processors concerning the fused QKV projections."
...@@ -156,15 +156,15 @@ class FluxControlPipelineFastTests(unittest.TestCase, PipelineTesterMixin): ...@@ -156,15 +156,15 @@ class FluxControlPipelineFastTests(unittest.TestCase, PipelineTesterMixin):
image = pipe(**inputs).images image = pipe(**inputs).images
image_slice_disabled = image[0, -3:, -3:, -1] image_slice_disabled = image[0, -3:, -3:, -1]
assert np.allclose( assert np.allclose(original_image_slice, image_slice_fused, atol=1e-3, rtol=1e-3), (
original_image_slice, image_slice_fused, atol=1e-3, rtol=1e-3 "Fusion of QKV projections shouldn't affect the outputs."
), "Fusion of QKV projections shouldn't affect the outputs." )
assert np.allclose( assert np.allclose(image_slice_fused, image_slice_disabled, atol=1e-3, rtol=1e-3), (
image_slice_fused, image_slice_disabled, atol=1e-3, rtol=1e-3 "Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled."
), "Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled." )
assert np.allclose( assert np.allclose(original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2), (
original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2 "Original outputs should match when fused QKV projections are disabled."
), "Original outputs should match when fused QKV projections are disabled." )
def test_flux_image_output_shape(self): def test_flux_image_output_shape(self):
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
......
...@@ -134,9 +134,9 @@ class FluxControlInpaintPipelineFastTests(unittest.TestCase, PipelineTesterMixin ...@@ -134,9 +134,9 @@ class FluxControlInpaintPipelineFastTests(unittest.TestCase, PipelineTesterMixin
# TODO (sayakpaul): will refactor this once `fuse_qkv_projections()` has been added # TODO (sayakpaul): will refactor this once `fuse_qkv_projections()` has been added
# to the pipeline level. # to the pipeline level.
pipe.transformer.fuse_qkv_projections() pipe.transformer.fuse_qkv_projections()
assert check_qkv_fusion_processors_exist( assert check_qkv_fusion_processors_exist(pipe.transformer), (
pipe.transformer "Something wrong with the fused attention processors. Expected all the attention processors to be fused."
), "Something wrong with the fused attention processors. Expected all the attention processors to be fused." )
assert check_qkv_fusion_matches_attn_procs_length( assert check_qkv_fusion_matches_attn_procs_length(
pipe.transformer, pipe.transformer.original_attn_processors pipe.transformer, pipe.transformer.original_attn_processors
), "Something wrong with the attention processors concerning the fused QKV projections." ), "Something wrong with the attention processors concerning the fused QKV projections."
...@@ -150,15 +150,15 @@ class FluxControlInpaintPipelineFastTests(unittest.TestCase, PipelineTesterMixin ...@@ -150,15 +150,15 @@ class FluxControlInpaintPipelineFastTests(unittest.TestCase, PipelineTesterMixin
image = pipe(**inputs).images image = pipe(**inputs).images
image_slice_disabled = image[0, -3:, -3:, -1] image_slice_disabled = image[0, -3:, -3:, -1]
assert np.allclose( assert np.allclose(original_image_slice, image_slice_fused, atol=1e-3, rtol=1e-3), (
original_image_slice, image_slice_fused, atol=1e-3, rtol=1e-3 "Fusion of QKV projections shouldn't affect the outputs."
), "Fusion of QKV projections shouldn't affect the outputs." )
assert np.allclose( assert np.allclose(image_slice_fused, image_slice_disabled, atol=1e-3, rtol=1e-3), (
image_slice_fused, image_slice_disabled, atol=1e-3, rtol=1e-3 "Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled."
), "Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled." )
assert np.allclose( assert np.allclose(original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2), (
original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2 "Original outputs should match when fused QKV projections are disabled."
), "Original outputs should match when fused QKV projections are disabled." )
def test_flux_image_output_shape(self): def test_flux_image_output_shape(self):
pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device)
......
...@@ -21,12 +21,7 @@ import numpy as np ...@@ -21,12 +21,7 @@ import numpy as np
import torch import torch
from transformers import AutoTokenizer, BertModel, T5EncoderModel from transformers import AutoTokenizer, BertModel, T5EncoderModel
from diffusers import ( from diffusers import AutoencoderKL, DDPMScheduler, HunyuanDiT2DModel, HunyuanDiTPipeline
AutoencoderKL,
DDPMScheduler,
HunyuanDiT2DModel,
HunyuanDiTPipeline,
)
from diffusers.utils.testing_utils import ( from diffusers.utils.testing_utils import (
enable_full_determinism, enable_full_determinism,
numpy_cosine_similarity_distance, numpy_cosine_similarity_distance,
...@@ -179,9 +174,9 @@ class HunyuanDiTPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -179,9 +174,9 @@ class HunyuanDiTPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
# TODO (sayakpaul): will refactor this once `fuse_qkv_projections()` has been added # TODO (sayakpaul): will refactor this once `fuse_qkv_projections()` has been added
# to the pipeline level. # to the pipeline level.
pipe.transformer.fuse_qkv_projections() pipe.transformer.fuse_qkv_projections()
assert check_qkv_fusion_processors_exist( assert check_qkv_fusion_processors_exist(pipe.transformer), (
pipe.transformer "Something wrong with the fused attention processors. Expected all the attention processors to be fused."
), "Something wrong with the fused attention processors. Expected all the attention processors to be fused." )
assert check_qkv_fusion_matches_attn_procs_length( assert check_qkv_fusion_matches_attn_procs_length(
pipe.transformer, pipe.transformer.original_attn_processors pipe.transformer, pipe.transformer.original_attn_processors
), "Something wrong with the attention processors concerning the fused QKV projections." ), "Something wrong with the attention processors concerning the fused QKV projections."
...@@ -197,15 +192,15 @@ class HunyuanDiTPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -197,15 +192,15 @@ class HunyuanDiTPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
image_disabled = pipe(**inputs)[0] image_disabled = pipe(**inputs)[0]
image_slice_disabled = image_disabled[0, -3:, -3:, -1] image_slice_disabled = image_disabled[0, -3:, -3:, -1]
assert np.allclose( assert np.allclose(original_image_slice, image_slice_fused, atol=1e-2, rtol=1e-2), (
original_image_slice, image_slice_fused, atol=1e-2, rtol=1e-2 "Fusion of QKV projections shouldn't affect the outputs."
), "Fusion of QKV projections shouldn't affect the outputs." )
assert np.allclose( assert np.allclose(image_slice_fused, image_slice_disabled, atol=1e-2, rtol=1e-2), (
image_slice_fused, image_slice_disabled, atol=1e-2, rtol=1e-2 "Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled."
), "Outputs, with QKV projection fusion enabled, shouldn't change when fused QKV projections are disabled." )
assert np.allclose( assert np.allclose(original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2), (
original_image_slice, image_slice_disabled, atol=1e-2, rtol=1e-2 "Original outputs should match when fused QKV projections are disabled."
), "Original outputs should match when fused QKV projections are disabled." )
@unittest.skip( @unittest.skip(
"Test not supported as `encode_prompt` is called two times separately which deivates from about 99% of the pipelines we have." "Test not supported as `encode_prompt` is called two times separately which deivates from about 99% of the pipelines we have."
......
...@@ -240,12 +240,12 @@ class KandinskyPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -240,12 +240,12 @@ class KandinskyPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
expected_slice = np.array([1.0000, 1.0000, 0.2766, 1.0000, 0.5447, 0.1737, 1.0000, 0.4316, 0.9024]) expected_slice = np.array([1.0000, 1.0000, 0.2766, 1.0000, 0.5447, 0.1737, 1.0000, 0.4316, 0.9024])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
@require_torch_accelerator @require_torch_accelerator
def test_offloads(self): def test_offloads(self):
......
...@@ -98,12 +98,12 @@ class KandinskyPipelineCombinedFastTests(PipelineTesterMixin, unittest.TestCase) ...@@ -98,12 +98,12 @@ class KandinskyPipelineCombinedFastTests(PipelineTesterMixin, unittest.TestCase)
expected_slice = np.array([0.2893, 0.1464, 0.4603, 0.3529, 0.4612, 0.7701, 0.4027, 0.3051, 0.5155]) expected_slice = np.array([0.2893, 0.1464, 0.4603, 0.3529, 0.4612, 0.7701, 0.4027, 0.3051, 0.5155])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
@require_torch_accelerator @require_torch_accelerator
def test_offloads(self): def test_offloads(self):
...@@ -206,12 +206,12 @@ class KandinskyPipelineImg2ImgCombinedFastTests(PipelineTesterMixin, unittest.Te ...@@ -206,12 +206,12 @@ class KandinskyPipelineImg2ImgCombinedFastTests(PipelineTesterMixin, unittest.Te
expected_slice = np.array([0.4852, 0.4136, 0.4539, 0.4781, 0.4680, 0.5217, 0.4973, 0.4089, 0.4977]) expected_slice = np.array([0.4852, 0.4136, 0.4539, 0.4781, 0.4680, 0.5217, 0.4973, 0.4089, 0.4977])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
@require_torch_accelerator @require_torch_accelerator
def test_offloads(self): def test_offloads(self):
...@@ -318,12 +318,12 @@ class KandinskyPipelineInpaintCombinedFastTests(PipelineTesterMixin, unittest.Te ...@@ -318,12 +318,12 @@ class KandinskyPipelineInpaintCombinedFastTests(PipelineTesterMixin, unittest.Te
expected_slice = np.array([0.0320, 0.0860, 0.4013, 0.0518, 0.2484, 0.5847, 0.4411, 0.2321, 0.4593]) expected_slice = np.array([0.0320, 0.0860, 0.4013, 0.0518, 0.2484, 0.5847, 0.4411, 0.2321, 0.4593])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
@require_torch_accelerator @require_torch_accelerator
def test_offloads(self): def test_offloads(self):
......
...@@ -261,12 +261,12 @@ class KandinskyImg2ImgPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -261,12 +261,12 @@ class KandinskyImg2ImgPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
assert image.shape == (1, 64, 64, 3) assert image.shape == (1, 64, 64, 3)
expected_slice = np.array([0.5816, 0.5872, 0.4634, 0.5982, 0.4767, 0.4710, 0.4669, 0.4717, 0.4966]) expected_slice = np.array([0.5816, 0.5872, 0.4634, 0.5982, 0.4767, 0.4710, 0.4669, 0.4717, 0.4966])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
@require_torch_accelerator @require_torch_accelerator
def test_offloads(self): def test_offloads(self):
...@@ -321,7 +321,7 @@ class KandinskyImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -321,7 +321,7 @@ class KandinskyImg2ImgPipelineIntegrationTests(unittest.TestCase):
) )
init_image = load_image( init_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
) )
prompt = "A red cartoon frog, 4k" prompt = "A red cartoon frog, 4k"
...@@ -387,7 +387,7 @@ class KandinskyImg2ImgPipelineNightlyTests(unittest.TestCase): ...@@ -387,7 +387,7 @@ class KandinskyImg2ImgPipelineNightlyTests(unittest.TestCase):
) )
init_image = load_image( init_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/frog.png" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/frog.png"
) )
prompt = "A red cartoon frog, 4k" prompt = "A red cartoon frog, 4k"
......
...@@ -256,12 +256,12 @@ class KandinskyInpaintPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -256,12 +256,12 @@ class KandinskyInpaintPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
expected_slice = np.array([0.8222, 0.8896, 0.4373, 0.8088, 0.4905, 0.2609, 0.6816, 0.4291, 0.5129]) expected_slice = np.array([0.8222, 0.8896, 0.4373, 0.8088, 0.4905, 0.2609, 0.6816, 0.4291, 0.5129])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
def test_inference_batch_single_identical(self): def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=3e-3) super().test_inference_batch_single_identical(expected_max_diff=3e-3)
...@@ -319,7 +319,7 @@ class KandinskyInpaintPipelineIntegrationTests(unittest.TestCase): ...@@ -319,7 +319,7 @@ class KandinskyInpaintPipelineIntegrationTests(unittest.TestCase):
) )
init_image = load_image( init_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
) )
mask = np.zeros((768, 768), dtype=np.float32) mask = np.zeros((768, 768), dtype=np.float32)
mask[:250, 250:-250] = 1 mask[:250, 250:-250] = 1
......
...@@ -210,13 +210,13 @@ class KandinskyV22PipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -210,13 +210,13 @@ class KandinskyV22PipelineFastTests(PipelineTesterMixin, unittest.TestCase):
expected_slice = np.array([0.3420, 0.9505, 0.3919, 1.0000, 0.5188, 0.3109, 0.6139, 0.5624, 0.6811]) expected_slice = np.array([0.3420, 0.9505, 0.3919, 1.0000, 0.5188, 0.3109, 0.6139, 0.5624, 0.6811])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
def test_float16_inference(self): def test_float16_inference(self):
super().test_float16_inference(expected_max_diff=1e-1) super().test_float16_inference(expected_max_diff=1e-1)
......
...@@ -103,12 +103,12 @@ class KandinskyV22PipelineCombinedFastTests(PipelineTesterMixin, unittest.TestCa ...@@ -103,12 +103,12 @@ class KandinskyV22PipelineCombinedFastTests(PipelineTesterMixin, unittest.TestCa
expected_slice = np.array([0.3076, 0.2729, 0.5668, 0.0522, 0.3384, 0.7028, 0.4908, 0.3659, 0.6243]) expected_slice = np.array([0.3076, 0.2729, 0.5668, 0.0522, 0.3384, 0.7028, 0.4908, 0.3659, 0.6243])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
@require_torch_accelerator @require_torch_accelerator
def test_offloads(self): def test_offloads(self):
...@@ -227,12 +227,12 @@ class KandinskyV22PipelineImg2ImgCombinedFastTests(PipelineTesterMixin, unittest ...@@ -227,12 +227,12 @@ class KandinskyV22PipelineImg2ImgCombinedFastTests(PipelineTesterMixin, unittest
expected_slice = np.array([0.4445, 0.4287, 0.4596, 0.3919, 0.3730, 0.5039, 0.4834, 0.4269, 0.5521]) expected_slice = np.array([0.4445, 0.4287, 0.4596, 0.3919, 0.3730, 0.5039, 0.4834, 0.4269, 0.5521])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
@require_torch_accelerator @require_torch_accelerator
def test_offloads(self): def test_offloads(self):
...@@ -350,12 +350,12 @@ class KandinskyV22PipelineInpaintCombinedFastTests(PipelineTesterMixin, unittest ...@@ -350,12 +350,12 @@ class KandinskyV22PipelineInpaintCombinedFastTests(PipelineTesterMixin, unittest
expected_slice = np.array([0.5039, 0.4926, 0.4898, 0.4978, 0.4838, 0.4942, 0.4738, 0.4702, 0.4816]) expected_slice = np.array([0.5039, 0.4926, 0.4898, 0.4978, 0.4838, 0.4942, 0.4738, 0.4702, 0.4816])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
@require_torch_accelerator @require_torch_accelerator
def test_offloads(self): def test_offloads(self):
......
...@@ -210,13 +210,13 @@ class KandinskyV22ControlnetPipelineFastTests(PipelineTesterMixin, unittest.Test ...@@ -210,13 +210,13 @@ class KandinskyV22ControlnetPipelineFastTests(PipelineTesterMixin, unittest.Test
[0.6959826, 0.868279, 0.7558092, 0.68769467, 0.85805804, 0.65977496, 0.44885302, 0.5959111, 0.4251595] [0.6959826, 0.868279, 0.7558092, 0.68769467, 0.85805804, 0.65977496, 0.44885302, 0.5959111, 0.4251595]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
def test_float16_inference(self): def test_float16_inference(self):
super().test_float16_inference(expected_max_diff=1e-1) super().test_float16_inference(expected_max_diff=1e-1)
......
...@@ -218,12 +218,12 @@ class KandinskyV22ControlnetImg2ImgPipelineFastTests(PipelineTesterMixin, unitte ...@@ -218,12 +218,12 @@ class KandinskyV22ControlnetImg2ImgPipelineFastTests(PipelineTesterMixin, unitte
expected_slice = np.array( expected_slice = np.array(
[0.54985034, 0.55509365, 0.52561504, 0.5570494, 0.5593818, 0.5263979, 0.50285643, 0.5069846, 0.51196736] [0.54985034, 0.55509365, 0.52561504, 0.5570494, 0.5593818, 0.5263979, 0.50285643, 0.5069846, 0.51196736]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
def test_inference_batch_single_identical(self): def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=1.75e-3) super().test_inference_batch_single_identical(expected_max_diff=1.75e-3)
...@@ -254,7 +254,7 @@ class KandinskyV22ControlnetImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -254,7 +254,7 @@ class KandinskyV22ControlnetImg2ImgPipelineIntegrationTests(unittest.TestCase):
) )
init_image = load_image( init_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
) )
init_image = init_image.resize((512, 512)) init_image = init_image.resize((512, 512))
......
...@@ -228,12 +228,12 @@ class KandinskyV22Img2ImgPipelineFastTests(PipelineTesterMixin, unittest.TestCas ...@@ -228,12 +228,12 @@ class KandinskyV22Img2ImgPipelineFastTests(PipelineTesterMixin, unittest.TestCas
assert image.shape == (1, 64, 64, 3) assert image.shape == (1, 64, 64, 3)
expected_slice = np.array([0.5712, 0.5443, 0.4725, 0.6195, 0.5184, 0.4651, 0.4473, 0.4590, 0.5016]) expected_slice = np.array([0.5712, 0.5443, 0.4725, 0.6195, 0.5184, 0.4651, 0.4473, 0.4590, 0.5016])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
def test_float16_inference(self): def test_float16_inference(self):
super().test_float16_inference(expected_max_diff=2e-1) super().test_float16_inference(expected_max_diff=2e-1)
...@@ -261,7 +261,7 @@ class KandinskyV22Img2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -261,7 +261,7 @@ class KandinskyV22Img2ImgPipelineIntegrationTests(unittest.TestCase):
) )
init_image = load_image( init_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
) )
prompt = "A red cartoon frog, 4k" prompt = "A red cartoon frog, 4k"
......
...@@ -234,12 +234,12 @@ class KandinskyV22InpaintPipelineFastTests(PipelineTesterMixin, unittest.TestCas ...@@ -234,12 +234,12 @@ class KandinskyV22InpaintPipelineFastTests(PipelineTesterMixin, unittest.TestCas
[0.50775903, 0.49527195, 0.48824543, 0.50192237, 0.48644906, 0.49373814, 0.4780598, 0.47234827, 0.48327848] [0.50775903, 0.49527195, 0.48824543, 0.50192237, 0.48644906, 0.49373814, 0.4780598, 0.47234827, 0.48327848]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
assert ( assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}" )
def test_inference_batch_single_identical(self): def test_inference_batch_single_identical(self):
super().test_inference_batch_single_identical(expected_max_diff=3e-3) super().test_inference_batch_single_identical(expected_max_diff=3e-3)
...@@ -314,7 +314,7 @@ class KandinskyV22InpaintPipelineIntegrationTests(unittest.TestCase): ...@@ -314,7 +314,7 @@ class KandinskyV22InpaintPipelineIntegrationTests(unittest.TestCase):
) )
init_image = load_image( init_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png"
) )
mask = np.zeros((768, 768), dtype=np.float32) mask = np.zeros((768, 768), dtype=np.float32)
mask[:250, 250:-250] = 1 mask[:250, 250:-250] = 1
......
...@@ -157,9 +157,9 @@ class Kandinsky3PipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -157,9 +157,9 @@ class Kandinsky3PipelineFastTests(PipelineTesterMixin, unittest.TestCase):
expected_slice = np.array([0.3768, 0.4373, 0.4865, 0.4890, 0.4299, 0.5122, 0.4921, 0.4924, 0.5599]) expected_slice = np.array([0.3768, 0.4373, 0.4865, 0.4890, 0.4299, 0.5122, 0.4921, 0.4924, 0.5599])
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
def test_float16_inference(self): def test_float16_inference(self):
super().test_float16_inference(expected_max_diff=1e-1) super().test_float16_inference(expected_max_diff=1e-1)
......
...@@ -181,9 +181,9 @@ class Kandinsky3Img2ImgPipelineFastTests(PipelineTesterMixin, unittest.TestCase) ...@@ -181,9 +181,9 @@ class Kandinsky3Img2ImgPipelineFastTests(PipelineTesterMixin, unittest.TestCase)
[0.576259, 0.6132097, 0.41703486, 0.603196, 0.62062526, 0.4655338, 0.5434324, 0.5660727, 0.65433365] [0.576259, 0.6132097, 0.41703486, 0.603196, 0.62062526, 0.4655338, 0.5434324, 0.5660727, 0.65433365]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 f" expected_slice {expected_slice}, but got {image_slice.flatten()}"
), f" expected_slice {expected_slice}, but got {image_slice.flatten()}" )
def test_float16_inference(self): def test_float16_inference(self):
super().test_float16_inference(expected_max_diff=1e-1) super().test_float16_inference(expected_max_diff=1e-1)
......
...@@ -450,9 +450,9 @@ class AnimateDiffPAGPipelineFastTests( ...@@ -450,9 +450,9 @@ class AnimateDiffPAGPipelineFastTests(
inputs = self.get_dummy_inputs(device) inputs = self.get_dummy_inputs(device)
del inputs["pag_scale"] del inputs["pag_scale"]
assert ( assert "pag_scale" not in inspect.signature(pipe_sd.__call__).parameters, (
"pag_scale" not in inspect.signature(pipe_sd.__call__).parameters f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__class__.__name__}."
), f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__class__.__name__}." )
out = pipe_sd(**inputs).frames[0, -3:, -3:, -1] out = pipe_sd(**inputs).frames[0, -3:, -3:, -1]
components = self.get_dummy_components() components = self.get_dummy_components()
......
...@@ -169,9 +169,9 @@ class StableDiffusionControlNetPAGPipelineFastTests( ...@@ -169,9 +169,9 @@ class StableDiffusionControlNetPAGPipelineFastTests(
inputs = self.get_dummy_inputs(device) inputs = self.get_dummy_inputs(device)
del inputs["pag_scale"] del inputs["pag_scale"]
assert ( assert "pag_scale" not in inspect.signature(pipe_sd.__call__).parameters, (
"pag_scale" not in inspect.signature(pipe_sd.__call__).parameters f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__class__.__name__}."
), f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__class__.__name__}." )
out = pipe_sd(**inputs).images[0, -3:, -3:, -1] out = pipe_sd(**inputs).images[0, -3:, -3:, -1]
# pag disabled with pag_scale=0.0 # pag disabled with pag_scale=0.0
......
...@@ -165,9 +165,9 @@ class StableDiffusionControlNetPAGInpaintPipelineFastTests( ...@@ -165,9 +165,9 @@ class StableDiffusionControlNetPAGInpaintPipelineFastTests(
inputs = self.get_dummy_inputs(device) inputs = self.get_dummy_inputs(device)
del inputs["pag_scale"] del inputs["pag_scale"]
assert ( assert "pag_scale" not in inspect.signature(pipe_sd.__call__).parameters, (
"pag_scale" not in inspect.signature(pipe_sd.__call__).parameters f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__calss__.__name__}."
), f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__calss__.__name__}." )
out = pipe_sd(**inputs).images[0, -3:, -3:, -1] out = pipe_sd(**inputs).images[0, -3:, -3:, -1]
# pag disabled with pag_scale=0.0 # pag disabled with pag_scale=0.0
......
...@@ -187,9 +187,9 @@ class StableDiffusionXLControlNetPAGPipelineFastTests( ...@@ -187,9 +187,9 @@ class StableDiffusionXLControlNetPAGPipelineFastTests(
inputs = self.get_dummy_inputs(device) inputs = self.get_dummy_inputs(device)
del inputs["pag_scale"] del inputs["pag_scale"]
assert ( assert "pag_scale" not in inspect.signature(pipe_sd.__call__).parameters, (
"pag_scale" not in inspect.signature(pipe_sd.__call__).parameters f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__class__.__name__}."
), f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__class__.__name__}." )
out = pipe_sd(**inputs).images[0, -3:, -3:, -1] out = pipe_sd(**inputs).images[0, -3:, -3:, -1]
# pag disabled with pag_scale=0.0 # pag disabled with pag_scale=0.0
......
...@@ -189,9 +189,9 @@ class StableDiffusionXLControlNetPAGImg2ImgPipelineFastTests( ...@@ -189,9 +189,9 @@ class StableDiffusionXLControlNetPAGImg2ImgPipelineFastTests(
inputs = self.get_dummy_inputs(device) inputs = self.get_dummy_inputs(device)
del inputs["pag_scale"] del inputs["pag_scale"]
assert ( assert "pag_scale" not in inspect.signature(pipe_sd.__call__).parameters, (
"pag_scale" not in inspect.signature(pipe_sd.__call__).parameters f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__class__.__name__}."
), f"`pag_scale` should not be a call parameter of the base pipeline {pipe_sd.__class__.__name__}." )
out = pipe_sd(**inputs).images[0, -3:, -3:, -1] out = pipe_sd(**inputs).images[0, -3:, -3:, -1]
# pag disabled with pag_scale=0.0 # pag disabled with pag_scale=0.0
......
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