Skip to content

Commit bb49cab

Browse files
committed
update more cases
1 parent 013f555 commit bb49cab

38 files changed

+178
-143
lines changed

src/diffusers/utils/testing_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,6 @@ def _is_torch_fp64_available(device):
11191119

11201120
# This dispatches a defined function according to the accelerator from the function definitions.
11211121
def _device_agnostic_dispatch(device: str, dispatch_table: Dict[str, Callable], *args, **kwargs):
1122-
11231122
if device not in dispatch_table:
11241123
return dispatch_table["default"](*args, **kwargs)
11251124

@@ -1149,9 +1148,11 @@ def backend_device_count(device: str):
11491148
def backend_reset_peak_memory_stats(device: str):
11501149
return _device_agnostic_dispatch(device, BACKEND_RESET_PEAK_MEMORY_STATS)
11511150

1151+
11521152
def backend_reset_max_memory_allocated(device: str):
11531153
return _device_agnostic_dispatch(device, BACKEND_RESET_MAX_MEMORY_ALLOCATED)
11541154

1155+
11551156
def backend_max_memory_allocated(device: str):
11561157
return _device_agnostic_dispatch(device, BACKEND_MAX_MEMORY_ALLOCATED)
11571158

tests/lora/test_lora_layers_sd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434
from diffusers.utils.import_utils import is_accelerate_available
3535
from diffusers.utils.testing_utils import (
36+
backend_empty_cache,
3637
load_image,
3738
nightly,
3839
numpy_cosine_similarity_distance,

tests/lora/test_lora_layers_sd3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
from diffusers.utils import load_image
3131
from diffusers.utils.import_utils import is_accelerate_available
3232
from diffusers.utils.testing_utils import (
33+
backend_empty_cache,
3334
nightly,
3435
numpy_cosine_similarity_distance,
3536
require_big_gpu_with_torch_cuda,
3637
require_peft_backend,
3738
require_torch_accelerator,
38-
slow,
3939
torch_device,
4040
)
4141

tests/models/unets/test_models_unet_2d_condition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
from diffusers.utils.import_utils import is_xformers_available
3737
from diffusers.utils.testing_utils import (
3838
backend_empty_cache,
39+
backend_max_memory_allocated,
3940
backend_reset_max_memory_allocated,
4041
backend_reset_peak_memory_stats,
41-
backend_max_memory_allocated,
4242
enable_full_determinism,
4343
floats_tensor,
4444
is_peft_available,
@@ -1005,7 +1005,7 @@ def test_load_sharded_checkpoint_from_hub_subfolder(self, repo_id, variant):
10051005
assert loaded_model
10061006
assert new_output.sample.shape == (4, 4, 16, 16)
10071007

1008-
@require_torch_gpu
1008+
@require_torch_accelerator
10091009
def test_load_sharded_checkpoint_from_hub_local(self):
10101010
_, inputs_dict = self.prepare_init_args_and_inputs_for_common()
10111011
ckpt_path = snapshot_download("hf-internal-testing/unet2d-sharded-dummy")
@@ -1204,7 +1204,7 @@ def test_set_attention_slice_max(self):
12041204
_ = unet(latents, timestep=timestep, encoder_hidden_states=encoder_hidden_states).sample
12051205

12061206
mem_bytes = backend_max_memory_allocated(torch_device)
1207-
1207+
12081208
assert mem_bytes < 5 * 10**9
12091209

12101210
@require_torch_accelerator

tests/pipelines/controlnet/test_controlnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _test_stable_diffusion_compile(in_queue, out_queue, timeout):
7979
pipe = StableDiffusionControlNetPipeline.from_pretrained(
8080
"stable-diffusion-v1-5/stable-diffusion-v1-5", safety_checker=None, controlnet=controlnet
8181
)
82-
pipe.to("cuda")
82+
pipe.to(torch_device)
8383
pipe.set_progress_bar_config(disable=None)
8484

8585
pipe.unet.to(memory_format=torch.channels_last)

tests/pipelines/controlnet/test_controlnet_inpaint_sdxl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from diffusers.utils.testing_utils import (
4141
enable_full_determinism,
4242
floats_tensor,
43-
require_torch_gpu,
43+
require_torch_accelerator,
4444
torch_device,
4545
)
4646

@@ -245,7 +245,7 @@ def test_xformers_attention_forwardGenerator_pass(self):
245245
def test_inference_batch_single_identical(self):
246246
self._test_inference_batch_single_identical(expected_max_diff=2e-3)
247247

248-
@require_torch_gpu
248+
@require_torch_accelerator
249249
def test_stable_diffusion_xl_offloads(self):
250250
pipes = []
251251
components = self.get_dummy_components()
@@ -254,12 +254,12 @@ def test_stable_diffusion_xl_offloads(self):
254254

255255
components = self.get_dummy_components()
256256
sd_pipe = self.pipeline_class(**components)
257-
sd_pipe.enable_model_cpu_offload()
257+
sd_pipe.enable_model_cpu_offload(device=torch_device)
258258
pipes.append(sd_pipe)
259259

260260
components = self.get_dummy_components()
261261
sd_pipe = self.pipeline_class(**components)
262-
sd_pipe.enable_sequential_cpu_offload()
262+
sd_pipe.enable_sequential_cpu_offload(device=torch_device)
263263
pipes.append(sd_pipe)
264264

265265
image_slices = []

tests/pipelines/controlnet_flux/test_controlnet_flux.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from diffusers.models import FluxControlNetModel
3232
from diffusers.utils import load_image
3333
from diffusers.utils.testing_utils import (
34+
backend_empty_cache,
3435
enable_full_determinism,
3536
nightly,
3637
numpy_cosine_similarity_distance,
@@ -213,12 +214,12 @@ class FluxControlNetPipelineSlowTests(unittest.TestCase):
213214
def setUp(self):
214215
super().setUp()
215216
gc.collect()
216-
torch.cuda.empty_cache()
217+
backend_empty_cache(torch_device)
217218

218219
def tearDown(self):
219220
super().tearDown()
220221
gc.collect()
221-
torch.cuda.empty_cache()
222+
backend_empty_cache(torch_device)
222223

223224
def test_canny(self):
224225
controlnet = FluxControlNetModel.from_pretrained(

tests/pipelines/controlnet_sd3/test_controlnet_sd3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def test_canny(self):
237237
pipe = StableDiffusion3ControlNetPipeline.from_pretrained(
238238
"stabilityai/stable-diffusion-3-medium-diffusers", controlnet=controlnet, torch_dtype=torch.float16
239239
)
240-
pipe.enable_model_cpu_offload()
240+
pipe.enable_model_cpu_offload(device=torch_device)
241241
pipe.set_progress_bar_config(disable=None)
242242

243243
generator = torch.Generator(device="cpu").manual_seed(0)

tests/pipelines/deepfloyd_if/test_if_img2img_superresolution.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from diffusers.utils.testing_utils import (
2626
backend_empty_cache,
2727
backend_max_memory_allocated,
28+
backend_reset_max_memory_allocated,
2829
backend_reset_peak_memory_stats,
2930
floats_tensor,
3031
load_numpy,

tests/pipelines/deepfloyd_if/test_if_inpainting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from diffusers.utils.testing_utils import (
2626
backend_empty_cache,
2727
backend_max_memory_allocated,
28+
backend_reset_max_memory_allocated,
2829
backend_reset_peak_memory_stats,
2930
floats_tensor,
3031
load_numpy,

0 commit comments

Comments
 (0)