Skip to content

make pipelines tests device-agnostic (part2) #9400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 78 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
275b6af
enable on xpu
faaany Sep 9, 2024
f422d55
add 1 more
faaany Sep 9, 2024
84540d9
add one more
faaany Sep 9, 2024
b94f751
enable more
faaany Sep 9, 2024
fa508a4
add 1 more
faaany Sep 9, 2024
a04fedf
add more
faaany Sep 9, 2024
7442dc1
enable 1
faaany Sep 9, 2024
658789a
enable more cases
faaany Sep 9, 2024
06c77c7
enable
faaany Sep 9, 2024
1bf9b0c
enable
faaany Sep 10, 2024
6296e88
update comment
faaany Sep 10, 2024
6d0b378
one more
faaany Sep 10, 2024
0d9f975
enable 1
faaany Sep 10, 2024
732ff3a
add more cases
faaany Sep 10, 2024
3803d93
enable xpu
faaany Sep 10, 2024
1825fd5
Merge branch 'main' into enable_xpu
faaany Sep 12, 2024
0666a53
Merge branch 'main' into enable_xpu
faaany Sep 13, 2024
e00bcca
add one more caswe
faaany Sep 13, 2024
6513201
add more cases
faaany Sep 13, 2024
3cb0f96
add 1
faaany Sep 13, 2024
314e76d
add more
faaany Sep 13, 2024
65c95e9
add more cases
faaany Sep 13, 2024
2882ee4
add case
faaany Sep 13, 2024
f604bce
enable
faaany Sep 13, 2024
0c66254
add more
faaany Sep 13, 2024
c699d7a
add more
faaany Sep 13, 2024
961a8e5
add more
faaany Sep 13, 2024
266f5f9
enbale more
faaany Sep 13, 2024
405bc16
add more
faaany Sep 13, 2024
48b67d6
update code
faaany Sep 13, 2024
1117427
update test marker
faaany Sep 13, 2024
88d289a
add skip back
faaany Sep 13, 2024
b534c50
update comment
faaany Sep 13, 2024
496e0be
Merge branch 'main' into enable_xpu
faaany Sep 14, 2024
1da965b
Merge branch 'main' into xpu_more3
faaany Sep 14, 2024
ab4bc3a
remove single files
faaany Sep 14, 2024
769d713
remove
faaany Sep 14, 2024
bf5e0b2
Merge branch 'xpu_more3' into enable_xpu
faaany Sep 14, 2024
daeb966
style
faaany Sep 14, 2024
28a73ac
add
faaany Sep 14, 2024
3052847
revert
faaany Sep 14, 2024
a5384ff
reformat
faaany Sep 14, 2024
2089e26
Merge branch 'huggingface:main' into enable_xpu
faaany Sep 17, 2024
186cdb6
enable
faaany Sep 17, 2024
59a00e4
enable esingle g
faaany Sep 18, 2024
8702062
add 2 more
faaany Sep 18, 2024
563124e
Merge branch 'main' into enable_xpu
faaany Sep 18, 2024
feb9fd2
Merge branch 'main' into enable_xpu
faaany Sep 19, 2024
0e39938
Merge branch 'main' into enable_xpu
faaany Sep 20, 2024
58de480
Merge branch 'main' into enable_xpu
faaany Sep 23, 2024
ac90301
Merge branch 'main' into enable_xpu
faaany Sep 26, 2024
2d08678
Merge branch 'main' into enable_xpu
sayakpaul Oct 14, 2024
d1b81ec
Merge branch 'huggingface:main' into enable_xpu
faaany Oct 15, 2024
da9c5c9
Merge branch 'huggingface:main' into enable_xpu
faaany Oct 23, 2024
34a0a7b
update decorator
faaany Oct 23, 2024
3e7490e
Merge branch 'huggingface:main' into enable_xpu
faaany Oct 23, 2024
bad2a3e
update
faaany Oct 23, 2024
f157e98
update
faaany Oct 23, 2024
359754e
update
faaany Oct 23, 2024
9052f83
Merge branch 'main' into enable_xpu
faaany Oct 31, 2024
ed55b90
Merge branch 'main' into enable_xpu
faaany Nov 6, 2024
f73a38a
Merge branch 'huggingface:main' into enable_xpu
faaany Nov 11, 2024
7ef5dab
Update tests/pipelines/deepfloyd_if/test_if.py
faaany Nov 11, 2024
915c741
Update src/diffusers/utils/testing_utils.py
faaany Nov 11, 2024
e0507b5
Update tests/pipelines/animatediff/test_animatediff_controlnet.py
faaany Nov 11, 2024
97f0e9e
Update tests/pipelines/animatediff/test_animatediff.py
faaany Nov 11, 2024
451790f
Update tests/pipelines/animatediff/test_animatediff_controlnet.py
faaany Nov 11, 2024
b671e25
update float16
faaany Nov 11, 2024
35de6d3
no unitest.skipt
faaany Nov 11, 2024
64ef84a
update
faaany Nov 11, 2024
9c4db33
Merge branch 'main' into enable_xpu
faaany Nov 14, 2024
227ea9f
Merge branch 'main' into enable_xpu
sayakpaul Nov 18, 2024
c045524
apply style check
faaany Nov 18, 2024
7078261
Merge branch 'huggingface:main' into xpu_more
faaany Nov 26, 2024
f1d8a00
Merge branch 'main' into xpu_more2
faaany Nov 26, 2024
a9855c5
Merge branch 'xpu_more2' into xpu_more
faaany Nov 26, 2024
9fb4851
adapt style
faaany Nov 28, 2024
447c40d
Merge branch 'main' into xpu_more
faaany Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/single_file/single_file_testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ def test_single_file_components_with_original_config_local_files_only(
def test_single_file_format_inference_is_same_as_pretrained(self, expected_max_diff=1e-4):
sf_pipe = self.pipeline_class.from_single_file(self.ckpt_path, safety_checker=None)
sf_pipe.unet.set_attn_processor(AttnProcessor())
sf_pipe.enable_model_cpu_offload()
sf_pipe.enable_model_cpu_offload(device=torch_device)

inputs = self.get_inputs(torch_device)
image_single_file = sf_pipe(**inputs).images[0]

pipe = self.pipeline_class.from_pretrained(self.repo_id, safety_checker=None)
pipe.unet.set_attn_processor(AttnProcessor())
pipe.enable_model_cpu_offload()
pipe.enable_model_cpu_offload(device=torch_device)

inputs = self.get_inputs(torch_device)
image = pipe(**inputs).images[0]
Expand Down
10 changes: 6 additions & 4 deletions tests/single_file/test_model_controlnet_single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
ControlNetModel,
)
from diffusers.utils.testing_utils import (
backend_empty_cache,
enable_full_determinism,
require_torch_gpu,
require_torch_accelerator,
slow,
torch_device,
)


enable_full_determinism()


@slow
@require_torch_gpu
@require_torch_accelerator
class ControlNetModelSingleFileTests(unittest.TestCase):
model_class = ControlNetModel
ckpt_path = "https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15_canny.pth"
Expand All @@ -41,12 +43,12 @@ class ControlNetModelSingleFileTests(unittest.TestCase):
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def test_single_file_components(self):
model = self.model_class.from_pretrained(self.repo_id)
Expand Down
10 changes: 6 additions & 4 deletions tests/single_file/test_model_sd_cascade_unet_single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
from diffusers import StableCascadeUNet
from diffusers.utils import logging
from diffusers.utils.testing_utils import (
backend_empty_cache,
enable_full_determinism,
require_torch_gpu,
require_torch_accelerator,
slow,
torch_device,
)


Expand All @@ -33,17 +35,17 @@


@slow
@require_torch_gpu
@require_torch_accelerator
class StableCascadeUNetSingleFileTest(unittest.TestCase):
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def test_single_file_components_stage_b(self):
model_single_file = StableCascadeUNet.from_single_file(
Expand Down
9 changes: 5 additions & 4 deletions tests/single_file/test_model_vae_single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
AutoencoderKL,
)
from diffusers.utils.testing_utils import (
backend_empty_cache,
enable_full_determinism,
load_hf_numpy,
numpy_cosine_similarity_distance,
require_torch_gpu,
require_torch_accelerator,
slow,
torch_device,
)
Expand All @@ -35,7 +36,7 @@


@slow
@require_torch_gpu
@require_torch_accelerator
class AutoencoderKLSingleFileTests(unittest.TestCase):
model_class = AutoencoderKL
ckpt_path = (
Expand All @@ -48,12 +49,12 @@ class AutoencoderKLSingleFileTests(unittest.TestCase):
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def get_file_format(self, seed, shape):
return f"gaussian_noise_s={seed}_shape={'_'.join([str(s) for s in shape])}.npy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
from diffusers.utils import load_image
from diffusers.utils.testing_utils import (
backend_empty_cache,
enable_full_determinism,
numpy_cosine_similarity_distance,
require_torch_gpu,
require_torch_accelerator,
slow,
torch_device,
)
Expand All @@ -27,7 +28,7 @@


@slow
@require_torch_gpu
@require_torch_accelerator
class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionControlNetPipeline
ckpt_path = (
Expand All @@ -41,12 +42,12 @@ class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SD
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
generator = torch.Generator(device=generator_device).manual_seed(seed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
from diffusers.utils import load_image
from diffusers.utils.testing_utils import (
backend_empty_cache,
enable_full_determinism,
numpy_cosine_similarity_distance,
require_torch_gpu,
require_torch_accelerator,
slow,
torch_device,
)

from .single_file_testing_utils import (
Expand All @@ -26,7 +28,7 @@


@slow
@require_torch_gpu
@require_torch_accelerator
class StableDiffusionControlNetInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionControlNetInpaintPipeline
ckpt_path = "https://huggingface.co/botp/stable-diffusion-v1-5-inpainting/blob/main/sd-v1-5-inpainting.ckpt"
Expand All @@ -36,12 +38,12 @@ class StableDiffusionControlNetInpaintPipelineSingleFileSlowTests(unittest.TestC
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def get_inputs(self):
control_image = load_image(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from diffusers.loaders.single_file_utils import _extract_repo_id_and_weights_name
from diffusers.utils import load_image
from diffusers.utils.testing_utils import (
backend_empty_cache,
enable_full_determinism,
numpy_cosine_similarity_distance,
require_torch_gpu,
require_torch_accelerator,
slow,
torch_device,
)

from .single_file_testing_utils import (
Expand All @@ -26,7 +28,7 @@


@slow
@require_torch_gpu
@require_torch_accelerator
class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionControlNetPipeline
ckpt_path = (
Expand All @@ -40,12 +42,12 @@ class StableDiffusionControlNetPipelineSingleFileSlowTests(unittest.TestCase, SD
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def get_inputs(self):
control_image = load_image(
Expand Down
16 changes: 9 additions & 7 deletions tests/single_file/test_stable_diffusion_img2img_single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
)
from diffusers.utils import load_image
from diffusers.utils.testing_utils import (
backend_empty_cache,
enable_full_determinism,
require_torch_gpu,
require_torch_accelerator,
slow,
torch_device,
)

from .single_file_testing_utils import SDSingleFileTesterMixin
Expand All @@ -20,7 +22,7 @@


@slow
@require_torch_gpu
@require_torch_accelerator
class StableDiffusionImg2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionImg2ImgPipeline
ckpt_path = (
Expand All @@ -34,12 +36,12 @@ class StableDiffusionImg2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDSin
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
generator = torch.Generator(device=generator_device).manual_seed(seed)
Expand All @@ -63,7 +65,7 @@ def test_single_file_format_inference_is_same_as_pretrained(self):


@slow
@require_torch_gpu
@require_torch_accelerator
class StableDiffusion21Img2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionImg2ImgPipeline
ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-2-1/blob/main/v2-1_768-ema-pruned.safetensors"
Expand All @@ -73,12 +75,12 @@ class StableDiffusion21Img2ImgPipelineSingleFileSlowTests(unittest.TestCase, SDS
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
generator = torch.Generator(device=generator_device).manual_seed(seed)
Expand Down
16 changes: 9 additions & 7 deletions tests/single_file/test_stable_diffusion_inpaint_single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
)
from diffusers.utils import load_image
from diffusers.utils.testing_utils import (
backend_empty_cache,
enable_full_determinism,
require_torch_gpu,
require_torch_accelerator,
slow,
torch_device,
)

from .single_file_testing_utils import SDSingleFileTesterMixin
Expand All @@ -20,7 +22,7 @@


@slow
@require_torch_gpu
@require_torch_accelerator
class StableDiffusionInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionInpaintPipeline
ckpt_path = "https://huggingface.co/botp/stable-diffusion-v1-5-inpainting/blob/main/sd-v1-5-inpainting.ckpt"
Expand All @@ -30,12 +32,12 @@ class StableDiffusionInpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSin
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
generator = torch.Generator(device=generator_device).manual_seed(seed)
Expand Down Expand Up @@ -78,7 +80,7 @@ def test_single_file_components_with_original_config_local_files_only(self):


@slow
@require_torch_gpu
@require_torch_accelerator
class StableDiffusion21InpaintPipelineSingleFileSlowTests(unittest.TestCase, SDSingleFileTesterMixin):
pipeline_class = StableDiffusionInpaintPipeline
ckpt_path = (
Expand All @@ -90,12 +92,12 @@ class StableDiffusion21InpaintPipelineSingleFileSlowTests(unittest.TestCase, SDS
def setUp(self):
super().setUp()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def tearDown(self):
super().tearDown()
gc.collect()
torch.cuda.empty_cache()
backend_empty_cache(torch_device)

def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0):
generator = torch.Generator(device=generator_device).manual_seed(seed)
Expand Down
Loading
Loading