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
...@@ -177,15 +177,15 @@ class HunyuanDiTPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -177,15 +177,15 @@ class HunyuanDiTPAGPipelineFastTests(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." )
def test_pag_disable_enable(self): def test_pag_disable_enable(self):
device = "cpu" # ensure determinism for the device-dependent torch.Generator device = "cpu" # ensure determinism for the device-dependent torch.Generator
...@@ -198,9 +198,9 @@ class HunyuanDiTPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -198,9 +198,9 @@ class HunyuanDiTPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
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]
components = self.get_dummy_components() components = self.get_dummy_components()
......
...@@ -140,9 +140,9 @@ class KolorsPAGPipelineFastTests( ...@@ -140,9 +140,9 @@ class KolorsPAGPipelineFastTests(
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
......
...@@ -120,9 +120,9 @@ class PixArtSigmaPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -120,9 +120,9 @@ class PixArtSigmaPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
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.__call__).parameters, (
"pag_scale" not in inspect.signature(pipe.__call__).parameters f"`pag_scale` should not be a call parameter of the base pipeline {pipe.__class__.__name__}."
), f"`pag_scale` should not be a call parameter of the base pipeline {pipe.__class__.__name__}." )
out = pipe(**inputs).images[0, -3:, -3:, -1] out = pipe(**inputs).images[0, -3:, -3:, -1]
# pag disabled with pag_scale=0.0 # pag disabled with pag_scale=0.0
......
...@@ -268,9 +268,9 @@ class SanaPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -268,9 +268,9 @@ class SanaPAGPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
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]
components = self.get_dummy_components() components = self.get_dummy_components()
......
...@@ -154,9 +154,9 @@ class StableDiffusionPAGPipelineFastTests( ...@@ -154,9 +154,9 @@ class StableDiffusionPAGPipelineFastTests(
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
...@@ -328,9 +328,9 @@ class StableDiffusionPAGPipelineIntegrationTests(unittest.TestCase): ...@@ -328,9 +328,9 @@ class StableDiffusionPAGPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.58251953, 0.5722656, 0.5683594, 0.55029297, 0.52001953, 0.52001953, 0.49951172, 0.45410156, 0.50146484] [0.58251953, 0.5722656, 0.5683594, 0.55029297, 0.52001953, 0.52001953, 0.49951172, 0.45410156, 0.50146484]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
def test_pag_uncond(self): def test_pag_uncond(self):
pipeline = AutoPipelineForText2Image.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16) pipeline = AutoPipelineForText2Image.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16)
...@@ -345,6 +345,6 @@ class StableDiffusionPAGPipelineIntegrationTests(unittest.TestCase): ...@@ -345,6 +345,6 @@ class StableDiffusionPAGPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.5986328, 0.52441406, 0.3972168, 0.4741211, 0.34985352, 0.22705078, 0.4128418, 0.2866211, 0.31713867] [0.5986328, 0.52441406, 0.3972168, 0.4741211, 0.34985352, 0.22705078, 0.4128418, 0.2866211, 0.31713867]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
...@@ -170,9 +170,9 @@ class StableDiffusion3PAGPipelineFastTests(unittest.TestCase, PipelineTesterMixi ...@@ -170,9 +170,9 @@ class StableDiffusion3PAGPipelineFastTests(unittest.TestCase, PipelineTesterMixi
# 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."
...@@ -186,15 +186,15 @@ class StableDiffusion3PAGPipelineFastTests(unittest.TestCase, PipelineTesterMixi ...@@ -186,15 +186,15 @@ class StableDiffusion3PAGPipelineFastTests(unittest.TestCase, PipelineTesterMixi
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_pag_disable_enable(self): def test_pag_disable_enable(self):
device = "cpu" # ensure determinism for the device-dependent torch.Generator device = "cpu" # ensure determinism for the device-dependent torch.Generator
...@@ -207,9 +207,9 @@ class StableDiffusion3PAGPipelineFastTests(unittest.TestCase, PipelineTesterMixi ...@@ -207,9 +207,9 @@ class StableDiffusion3PAGPipelineFastTests(unittest.TestCase, PipelineTesterMixi
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]
components = self.get_dummy_components() components = self.get_dummy_components()
......
...@@ -149,9 +149,9 @@ class StableDiffusion3PAGImg2ImgPipelineFastTests(unittest.TestCase, PipelineTes ...@@ -149,9 +149,9 @@ class StableDiffusion3PAGImg2ImgPipelineFastTests(unittest.TestCase, PipelineTes
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]
components = self.get_dummy_components() components = self.get_dummy_components()
...@@ -254,9 +254,9 @@ class StableDiffusion3PAGImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -254,9 +254,9 @@ class StableDiffusion3PAGImg2ImgPipelineIntegrationTests(unittest.TestCase):
0.17822266, 0.17822266,
] ]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
def test_pag_uncond(self): def test_pag_uncond(self):
pipeline = AutoPipelineForImage2Image.from_pretrained( pipeline = AutoPipelineForImage2Image.from_pretrained(
...@@ -272,6 +272,6 @@ class StableDiffusion3PAGImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -272,6 +272,6 @@ class StableDiffusion3PAGImg2ImgPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.1508789, 0.16210938, 0.17138672, 0.16210938, 0.17089844, 0.16137695, 0.16235352, 0.16430664, 0.16455078] [0.1508789, 0.16210938, 0.17138672, 0.16210938, 0.17089844, 0.16137695, 0.16235352, 0.16430664, 0.16455078]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
...@@ -161,9 +161,9 @@ class StableDiffusionPAGImg2ImgPipelineFastTests( ...@@ -161,9 +161,9 @@ class StableDiffusionPAGImg2ImgPipelineFastTests(
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
...@@ -267,9 +267,9 @@ class StableDiffusionPAGImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -267,9 +267,9 @@ class StableDiffusionPAGImg2ImgPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.58251953, 0.5722656, 0.5683594, 0.55029297, 0.52001953, 0.52001953, 0.49951172, 0.45410156, 0.50146484] [0.58251953, 0.5722656, 0.5683594, 0.55029297, 0.52001953, 0.52001953, 0.49951172, 0.45410156, 0.50146484]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
def test_pag_uncond(self): def test_pag_uncond(self):
pipeline = AutoPipelineForImage2Image.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16) pipeline = AutoPipelineForImage2Image.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16)
...@@ -285,6 +285,6 @@ class StableDiffusionPAGImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -285,6 +285,6 @@ class StableDiffusionPAGImg2ImgPipelineIntegrationTests(unittest.TestCase):
[0.5986328, 0.52441406, 0.3972168, 0.4741211, 0.34985352, 0.22705078, 0.4128418, 0.2866211, 0.31713867] [0.5986328, 0.52441406, 0.3972168, 0.4741211, 0.34985352, 0.22705078, 0.4128418, 0.2866211, 0.31713867]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
...@@ -302,9 +302,9 @@ class StableDiffusionPAGPipelineIntegrationTests(unittest.TestCase): ...@@ -302,9 +302,9 @@ class StableDiffusionPAGPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.38793945, 0.4111328, 0.47924805, 0.39208984, 0.4165039, 0.41674805, 0.37060547, 0.36791992, 0.40625] [0.38793945, 0.4111328, 0.47924805, 0.39208984, 0.4165039, 0.41674805, 0.37060547, 0.36791992, 0.40625]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
def test_pag_uncond(self): def test_pag_uncond(self):
pipeline = AutoPipelineForInpainting.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16) pipeline = AutoPipelineForInpainting.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16)
...@@ -319,6 +319,6 @@ class StableDiffusionPAGPipelineIntegrationTests(unittest.TestCase): ...@@ -319,6 +319,6 @@ class StableDiffusionPAGPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.3876953, 0.40356445, 0.4934082, 0.39697266, 0.41674805, 0.41015625, 0.375, 0.36914062, 0.40649414] [0.3876953, 0.40356445, 0.4934082, 0.39697266, 0.41674805, 0.41015625, 0.375, 0.36914062, 0.40649414]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
...@@ -167,9 +167,9 @@ class StableDiffusionXLPAGPipelineFastTests( ...@@ -167,9 +167,9 @@ class StableDiffusionXLPAGPipelineFastTests(
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
...@@ -331,9 +331,9 @@ class StableDiffusionXLPAGPipelineIntegrationTests(unittest.TestCase): ...@@ -331,9 +331,9 @@ class StableDiffusionXLPAGPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.3123679, 0.31725878, 0.32026544, 0.327533, 0.3266391, 0.3303998, 0.33544615, 0.34181812, 0.34102726] [0.3123679, 0.31725878, 0.32026544, 0.327533, 0.3266391, 0.3303998, 0.33544615, 0.34181812, 0.34102726]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
def test_pag_uncond(self): def test_pag_uncond(self):
pipeline = AutoPipelineForText2Image.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16) pipeline = AutoPipelineForText2Image.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16)
...@@ -348,6 +348,6 @@ class StableDiffusionXLPAGPipelineIntegrationTests(unittest.TestCase): ...@@ -348,6 +348,6 @@ class StableDiffusionXLPAGPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.47400922, 0.48650584, 0.4839625, 0.4724013, 0.4890427, 0.49544555, 0.51707107, 0.54299414, 0.5224372] [0.47400922, 0.48650584, 0.4839625, 0.4724013, 0.4890427, 0.49544555, 0.51707107, 0.54299414, 0.5224372]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
...@@ -215,9 +215,9 @@ class StableDiffusionXLPAGImg2ImgPipelineFastTests( ...@@ -215,9 +215,9 @@ class StableDiffusionXLPAGImg2ImgPipelineFastTests(
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
...@@ -316,9 +316,9 @@ class StableDiffusionXLPAGImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -316,9 +316,9 @@ class StableDiffusionXLPAGImg2ImgPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.20301354, 0.21078318, 0.2021082, 0.20277798, 0.20681083, 0.19562206, 0.20121682, 0.21562952, 0.21277016] [0.20301354, 0.21078318, 0.2021082, 0.20277798, 0.20681083, 0.19562206, 0.20121682, 0.21562952, 0.21277016]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
def test_pag_uncond(self): def test_pag_uncond(self):
pipeline = AutoPipelineForImage2Image.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16) pipeline = AutoPipelineForImage2Image.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16)
...@@ -333,6 +333,6 @@ class StableDiffusionXLPAGImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -333,6 +333,6 @@ class StableDiffusionXLPAGImg2ImgPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.21303111, 0.22188407, 0.2124992, 0.21365267, 0.18823743, 0.17569828, 0.21113116, 0.19419771, 0.18919235] [0.21303111, 0.22188407, 0.2124992, 0.21365267, 0.18823743, 0.17569828, 0.21113116, 0.19419771, 0.18919235]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
...@@ -220,9 +220,9 @@ class StableDiffusionXLPAGInpaintPipelineFastTests( ...@@ -220,9 +220,9 @@ class StableDiffusionXLPAGInpaintPipelineFastTests(
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
...@@ -322,9 +322,9 @@ class StableDiffusionXLPAGInpaintPipelineIntegrationTests(unittest.TestCase): ...@@ -322,9 +322,9 @@ class StableDiffusionXLPAGInpaintPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.41385046, 0.39608297, 0.4360491, 0.26872507, 0.32187328, 0.4242474, 0.2603805, 0.34167895, 0.46561807] [0.41385046, 0.39608297, 0.4360491, 0.26872507, 0.32187328, 0.4242474, 0.2603805, 0.34167895, 0.46561807]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
def test_pag_uncond(self): def test_pag_uncond(self):
pipeline = AutoPipelineForInpainting.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16) pipeline = AutoPipelineForInpainting.from_pretrained(self.repo_id, enable_pag=True, torch_dtype=torch.float16)
...@@ -339,6 +339,6 @@ class StableDiffusionXLPAGInpaintPipelineIntegrationTests(unittest.TestCase): ...@@ -339,6 +339,6 @@ class StableDiffusionXLPAGInpaintPipelineIntegrationTests(unittest.TestCase):
expected_slice = np.array( expected_slice = np.array(
[0.41597816, 0.39302617, 0.44287828, 0.2687074, 0.28315824, 0.40582314, 0.20877528, 0.2380802, 0.39447647] [0.41597816, 0.39302617, 0.44287828, 0.2687074, 0.28315824, 0.40582314, 0.20877528, 0.2380802, 0.39447647]
) )
assert ( assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-3, (
np.abs(image_slice.flatten() - expected_slice).max() < 1e-3 f"output is different from expected, {image_slice.flatten()}"
), f"output is different from expected, {image_slice.flatten()}" )
...@@ -260,9 +260,9 @@ class PixArtSigmaPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -260,9 +260,9 @@ class PixArtSigmaPipelineFastTests(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."
...@@ -276,15 +276,15 @@ class PixArtSigmaPipelineFastTests(PipelineTesterMixin, unittest.TestCase): ...@@ -276,15 +276,15 @@ class PixArtSigmaPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
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." )
@slow @slow
......
...@@ -266,7 +266,7 @@ class ShapEImg2ImgPipelineIntegrationTests(unittest.TestCase): ...@@ -266,7 +266,7 @@ class ShapEImg2ImgPipelineIntegrationTests(unittest.TestCase):
def test_shap_e_img2img(self): def test_shap_e_img2img(self):
input_image = load_image( input_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/shap_e/corgi.png" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/shap_e/corgi.png"
) )
expected_image = load_numpy( expected_image = load_numpy(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
......
...@@ -198,12 +198,12 @@ class StableCascadeCombinedPipelineFastTests(PipelineTesterMixin, unittest.TestC ...@@ -198,12 +198,12 @@ class StableCascadeCombinedPipelineFastTests(PipelineTesterMixin, unittest.TestC
assert image.shape == (1, 128, 128, 3) assert image.shape == (1, 128, 128, 3)
expected_slice = np.array([0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0]) expected_slice = np.array([0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0])
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):
......
...@@ -293,15 +293,15 @@ class StableDiffusionPipelineFastTests( ...@@ -293,15 +293,15 @@ class StableDiffusionPipelineFastTests(
inputs["sigmas"] = sigma_schedule inputs["sigmas"] = sigma_schedule
output_sigmas = sd_pipe(**inputs).images output_sigmas = sd_pipe(**inputs).images
assert ( assert np.abs(output_sigmas.flatten() - output_ts.flatten()).max() < 1e-3, (
np.abs(output_sigmas.flatten() - output_ts.flatten()).max() < 1e-3 "ays timesteps and ays sigmas should have the same outputs"
), "ays timesteps and ays sigmas should have the same outputs" )
assert ( assert np.abs(output.flatten() - output_ts.flatten()).max() > 1e-3, (
np.abs(output.flatten() - output_ts.flatten()).max() > 1e-3 "use ays timesteps should have different outputs"
), "use ays timesteps should have different outputs" )
assert ( assert np.abs(output.flatten() - output_sigmas.flatten()).max() > 1e-3, (
np.abs(output.flatten() - output_sigmas.flatten()).max() > 1e-3 "use ays sigmas should have different outputs"
), "use ays sigmas should have different outputs" )
def test_stable_diffusion_prompt_embeds(self): def test_stable_diffusion_prompt_embeds(self):
components = self.get_dummy_components() components = self.get_dummy_components()
...@@ -656,9 +656,9 @@ class StableDiffusionPipelineFastTests( ...@@ -656,9 +656,9 @@ class StableDiffusionPipelineFastTests(
sd_pipe.enable_freeu(s1=0.9, s2=0.2, b1=1.2, b2=1.4) sd_pipe.enable_freeu(s1=0.9, s2=0.2, b1=1.2, b2=1.4)
output_freeu = sd_pipe(prompt, num_inference_steps=1, output_type="np", generator=torch.manual_seed(0)).images output_freeu = sd_pipe(prompt, num_inference_steps=1, output_type="np", generator=torch.manual_seed(0)).images
assert not np.allclose( assert not np.allclose(output[0, -3:, -3:, -1], output_freeu[0, -3:, -3:, -1]), (
output[0, -3:, -3:, -1], output_freeu[0, -3:, -3:, -1] "Enabling of FreeU should lead to different results."
), "Enabling of FreeU should lead to different results." )
def test_freeu_disabled(self): def test_freeu_disabled(self):
components = self.get_dummy_components() components = self.get_dummy_components()
...@@ -681,9 +681,9 @@ class StableDiffusionPipelineFastTests( ...@@ -681,9 +681,9 @@ class StableDiffusionPipelineFastTests(
prompt, num_inference_steps=1, output_type="np", generator=torch.manual_seed(0) prompt, num_inference_steps=1, output_type="np", generator=torch.manual_seed(0)
).images ).images
assert np.allclose( assert np.allclose(output[0, -3:, -3:, -1], output_no_freeu[0, -3:, -3:, -1]), (
output[0, -3:, -3:, -1], output_no_freeu[0, -3:, -3:, -1] "Disabling of FreeU should lead to results similar to the default pipeline results."
), "Disabling of FreeU should lead to results similar to the default pipeline results." )
def test_fused_qkv_projections(self): def test_fused_qkv_projections(self):
device = "cpu" # ensure determinism for the device-dependent torch.Generator device = "cpu" # ensure determinism for the device-dependent torch.Generator
...@@ -706,15 +706,15 @@ class StableDiffusionPipelineFastTests( ...@@ -706,15 +706,15 @@ class StableDiffusionPipelineFastTests(
image = sd_pipe(**inputs).images image = sd_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-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." )
def test_pipeline_interrupt(self): def test_pipeline_interrupt(self):
components = self.get_dummy_components() components = self.get_dummy_components()
......
...@@ -171,9 +171,9 @@ class StableDiffusion3PipelineFastTests(unittest.TestCase, PipelineTesterMixin): ...@@ -171,9 +171,9 @@ class StableDiffusion3PipelineFastTests(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."
...@@ -187,15 +187,15 @@ class StableDiffusion3PipelineFastTests(unittest.TestCase, PipelineTesterMixin): ...@@ -187,15 +187,15 @@ class StableDiffusion3PipelineFastTests(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_skip_guidance_layers(self): def test_skip_guidance_layers(self):
components = self.get_dummy_components() components = self.get_dummy_components()
......
...@@ -242,15 +242,15 @@ class StableDiffusionXLPipelineFastTests( ...@@ -242,15 +242,15 @@ class StableDiffusionXLPipelineFastTests(
inputs["sigmas"] = sigma_schedule inputs["sigmas"] = sigma_schedule
output_sigmas = sd_pipe(**inputs).images output_sigmas = sd_pipe(**inputs).images
assert ( assert np.abs(output_sigmas.flatten() - output_ts.flatten()).max() < 1e-3, (
np.abs(output_sigmas.flatten() - output_ts.flatten()).max() < 1e-3 "ays timesteps and ays sigmas should have the same outputs"
), "ays timesteps and ays sigmas should have the same outputs" )
assert ( assert np.abs(output.flatten() - output_ts.flatten()).max() > 1e-3, (
np.abs(output.flatten() - output_ts.flatten()).max() > 1e-3 "use ays timesteps should have different outputs"
), "use ays timesteps should have different outputs" )
assert ( assert np.abs(output.flatten() - output_sigmas.flatten()).max() > 1e-3, (
np.abs(output.flatten() - output_sigmas.flatten()).max() > 1e-3 "use ays sigmas should have different outputs"
), "use ays sigmas should have different outputs" )
def test_ip_adapter(self): def test_ip_adapter(self):
expected_pipe_slice = None expected_pipe_slice = None
...@@ -742,9 +742,9 @@ class StableDiffusionXLPipelineFastTests( ...@@ -742,9 +742,9 @@ class StableDiffusionXLPipelineFastTests(
inputs_1 = {**inputs, **{"denoising_end": split_1, "output_type": "latent"}} inputs_1 = {**inputs, **{"denoising_end": split_1, "output_type": "latent"}}
latents = pipe_1(**inputs_1).images[0] latents = pipe_1(**inputs_1).images[0]
assert ( assert expected_steps_1 == done_steps, (
expected_steps_1 == done_steps f"Failure with {scheduler_cls.__name__} and {num_steps} and {split_1} and {split_2}"
), f"Failure with {scheduler_cls.__name__} and {num_steps} and {split_1} and {split_2}" )
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
inputs_2 = { inputs_2 = {
...@@ -771,9 +771,9 @@ class StableDiffusionXLPipelineFastTests( ...@@ -771,9 +771,9 @@ class StableDiffusionXLPipelineFastTests(
pipe_3(**inputs_3).images[0] pipe_3(**inputs_3).images[0]
assert expected_steps_3 == done_steps[len(expected_steps_1) + len(expected_steps_2) :] assert expected_steps_3 == done_steps[len(expected_steps_1) + len(expected_steps_2) :]
assert ( assert expected_steps == done_steps, (
expected_steps == done_steps f"Failure with {scheduler_cls.__name__} and {num_steps} and {split_1} and {split_2}"
), f"Failure with {scheduler_cls.__name__} and {num_steps} and {split_1} and {split_2}" )
for steps in [7, 11, 20]: for steps in [7, 11, 20]:
for split_1, split_2 in zip([0.19, 0.32], [0.81, 0.68]): for split_1, split_2 in zip([0.19, 0.32], [0.81, 0.68]):
......
...@@ -585,9 +585,9 @@ class StableDiffusionXLInpaintPipelineFastTests( ...@@ -585,9 +585,9 @@ class StableDiffusionXLInpaintPipelineFastTests(
inputs_1 = {**inputs, **{"denoising_end": split_1, "output_type": "latent"}} inputs_1 = {**inputs, **{"denoising_end": split_1, "output_type": "latent"}}
latents = pipe_1(**inputs_1).images[0] latents = pipe_1(**inputs_1).images[0]
assert ( assert expected_steps_1 == done_steps, (
expected_steps_1 == done_steps f"Failure with {scheduler_cls.__name__} and {num_steps} and {split_1} and {split_2}"
), f"Failure with {scheduler_cls.__name__} and {num_steps} and {split_1} and {split_2}" )
inputs_2 = { inputs_2 = {
**inputs, **inputs,
...@@ -601,9 +601,9 @@ class StableDiffusionXLInpaintPipelineFastTests( ...@@ -601,9 +601,9 @@ class StableDiffusionXLInpaintPipelineFastTests(
pipe_3(**inputs_3).images[0] pipe_3(**inputs_3).images[0]
assert expected_steps_3 == done_steps[len(expected_steps_1) + len(expected_steps_2) :] assert expected_steps_3 == done_steps[len(expected_steps_1) + len(expected_steps_2) :]
assert ( assert expected_steps == done_steps, (
expected_steps == done_steps f"Failure with {scheduler_cls.__name__} and {num_steps} and {split_1} and {split_2}"
), f"Failure with {scheduler_cls.__name__} and {num_steps} and {split_1} and {split_2}" )
for steps in [7, 11, 20]: for steps in [7, 11, 20]:
for split_1, split_2 in zip([0.19, 0.32], [0.81, 0.68]): for split_1, split_2 in zip([0.19, 0.32], [0.81, 0.68]):
......
...@@ -167,9 +167,9 @@ class DownloadTests(unittest.TestCase): ...@@ -167,9 +167,9 @@ class DownloadTests(unittest.TestCase):
download_requests = [r.method for r in m.request_history] download_requests = [r.method for r in m.request_history]
assert download_requests.count("HEAD") == 15, "15 calls to files" assert download_requests.count("HEAD") == 15, "15 calls to files"
assert download_requests.count("GET") == 17, "15 calls to files + model_info + model_index.json" assert download_requests.count("GET") == 17, "15 calls to files + model_info + model_index.json"
assert ( assert len(download_requests) == 32, (
len(download_requests) == 32 "2 calls per file (15 files) + send_telemetry, model_info and model_index.json"
), "2 calls per file (15 files) + send_telemetry, model_info and model_index.json" )
with requests_mock.mock(real_http=True) as m: with requests_mock.mock(real_http=True) as m:
DiffusionPipeline.download( DiffusionPipeline.download(
...@@ -179,9 +179,9 @@ class DownloadTests(unittest.TestCase): ...@@ -179,9 +179,9 @@ class DownloadTests(unittest.TestCase):
cache_requests = [r.method for r in m.request_history] cache_requests = [r.method for r in m.request_history]
assert cache_requests.count("HEAD") == 1, "model_index.json is only HEAD" assert cache_requests.count("HEAD") == 1, "model_index.json is only HEAD"
assert cache_requests.count("GET") == 1, "model info is only GET" assert cache_requests.count("GET") == 1, "model info is only GET"
assert ( assert len(cache_requests) == 2, (
len(cache_requests) == 2 "We should call only `model_info` to check for _commit hash and `send_telemetry`"
), "We should call only `model_info` to check for _commit hash and `send_telemetry`" )
def test_less_downloads_passed_object(self): def test_less_downloads_passed_object(self):
with tempfile.TemporaryDirectory() as tmpdirname: with tempfile.TemporaryDirectory() as tmpdirname:
...@@ -217,9 +217,9 @@ class DownloadTests(unittest.TestCase): ...@@ -217,9 +217,9 @@ class DownloadTests(unittest.TestCase):
assert download_requests.count("HEAD") == 13, "13 calls to files" assert download_requests.count("HEAD") == 13, "13 calls to files"
# 17 - 2 because no call to config or model file for `safety_checker` # 17 - 2 because no call to config or model file for `safety_checker`
assert download_requests.count("GET") == 15, "13 calls to files + model_info + model_index.json" assert download_requests.count("GET") == 15, "13 calls to files + model_info + model_index.json"
assert ( assert len(download_requests) == 28, (
len(download_requests) == 28 "2 calls per file (13 files) + send_telemetry, model_info and model_index.json"
), "2 calls per file (13 files) + send_telemetry, model_info and model_index.json" )
with requests_mock.mock(real_http=True) as m: with requests_mock.mock(real_http=True) as m:
DiffusionPipeline.download( DiffusionPipeline.download(
...@@ -229,9 +229,9 @@ class DownloadTests(unittest.TestCase): ...@@ -229,9 +229,9 @@ class DownloadTests(unittest.TestCase):
cache_requests = [r.method for r in m.request_history] cache_requests = [r.method for r in m.request_history]
assert cache_requests.count("HEAD") == 1, "model_index.json is only HEAD" assert cache_requests.count("HEAD") == 1, "model_index.json is only HEAD"
assert cache_requests.count("GET") == 1, "model info is only GET" assert cache_requests.count("GET") == 1, "model info is only GET"
assert ( assert len(cache_requests) == 2, (
len(cache_requests) == 2 "We should call only `model_info` to check for _commit hash and `send_telemetry`"
), "We should call only `model_info` to check for _commit hash and `send_telemetry`" )
def test_download_only_pytorch(self): def test_download_only_pytorch(self):
with tempfile.TemporaryDirectory() as tmpdirname: with tempfile.TemporaryDirectory() as tmpdirname:
......
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