Skip to content

Commit 8d0f387

Browse files
committed
initial comit
1 parent c28db0a commit 8d0f387

22 files changed

+210
-122
lines changed

tests/models/test_modeling_common.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
get_python_version,
5858
is_torch_compile,
5959
require_torch_2,
60+
require_torch_accelerator,
6061
require_torch_accelerator_with_training,
61-
require_torch_gpu,
6262
require_torch_multi_gpu,
6363
run_test_in_subprocess,
6464
torch_all_close,
@@ -543,7 +543,7 @@ def test_set_xformers_attn_processor_for_determinism(self):
543543
assert torch.allclose(output, output_3, atol=self.base_precision)
544544
assert torch.allclose(output_2, output_3, atol=self.base_precision)
545545

546-
@require_torch_gpu
546+
@require_torch_accelerator
547547
def test_set_attn_processor_for_determinism(self):
548548
if self.uses_custom_attn_processor:
549549
return
@@ -1068,7 +1068,7 @@ def test_wrong_adapter_name_raises_error(self):
10681068

10691069
self.assertTrue(f"Adapter name {wrong_name} not found in the model." in str(err_context.exception))
10701070

1071-
@require_torch_gpu
1071+
@require_torch_accelerator
10721072
def test_cpu_offload(self):
10731073
config, inputs_dict = self.prepare_init_args_and_inputs_for_common()
10741074
model = self.model_class(**config).eval()
@@ -1098,7 +1098,7 @@ def test_cpu_offload(self):
10981098

10991099
self.assertTrue(torch.allclose(base_output[0], new_output[0], atol=1e-5))
11001100

1101-
@require_torch_gpu
1101+
@require_torch_accelerator
11021102
def test_disk_offload_without_safetensors(self):
11031103
config, inputs_dict = self.prepare_init_args_and_inputs_for_common()
11041104
model = self.model_class(**config).eval()
@@ -1132,7 +1132,7 @@ def test_disk_offload_without_safetensors(self):
11321132

11331133
self.assertTrue(torch.allclose(base_output[0], new_output[0], atol=1e-5))
11341134

1135-
@require_torch_gpu
1135+
@require_torch_accelerator
11361136
def test_disk_offload_with_safetensors(self):
11371137
config, inputs_dict = self.prepare_init_args_and_inputs_for_common()
11381138
model = self.model_class(**config).eval()
@@ -1191,7 +1191,7 @@ def test_model_parallelism(self):
11911191

11921192
self.assertTrue(torch.allclose(base_output[0], new_output[0], atol=1e-5))
11931193

1194-
@require_torch_gpu
1194+
@require_torch_accelerator
11951195
def test_sharded_checkpoints(self):
11961196
torch.manual_seed(0)
11971197
config, inputs_dict = self.prepare_init_args_and_inputs_for_common()
@@ -1223,7 +1223,7 @@ def test_sharded_checkpoints(self):
12231223

12241224
self.assertTrue(torch.allclose(base_output[0], new_output[0], atol=1e-5))
12251225

1226-
@require_torch_gpu
1226+
@require_torch_accelerator
12271227
def test_sharded_checkpoints_with_variant(self):
12281228
torch.manual_seed(0)
12291229
config, inputs_dict = self.prepare_init_args_and_inputs_for_common()
@@ -1261,7 +1261,7 @@ def test_sharded_checkpoints_with_variant(self):
12611261

12621262
self.assertTrue(torch.allclose(base_output[0], new_output[0], atol=1e-5))
12631263

1264-
@require_torch_gpu
1264+
@require_torch_accelerator
12651265
def test_sharded_checkpoints_device_map(self):
12661266
config, inputs_dict = self.prepare_init_args_and_inputs_for_common()
12671267
model = self.model_class(**config).eval()

tests/pipelines/allegro/test_allegro.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from diffusers.utils.testing_utils import (
2525
enable_full_determinism,
2626
numpy_cosine_similarity_distance,
27-
require_torch_gpu,
27+
require_torch_accelerator,
2828
slow,
2929
torch_device,
3030
)
@@ -299,7 +299,7 @@ def test_vae_tiling(self, expected_diff_max: float = 0.2):
299299

300300

301301
@slow
302-
@require_torch_gpu
302+
@require_torch_accelerator
303303
class AllegroPipelineIntegrationTests(unittest.TestCase):
304304
prompt = "A painting of a squirrel eating a burger."
305305

@@ -317,7 +317,7 @@ def test_allegro(self):
317317
generator = torch.Generator("cpu").manual_seed(0)
318318

319319
pipe = AllegroPipeline.from_pretrained("rhymes-ai/Allegro", torch_dtype=torch.float16)
320-
pipe.enable_model_cpu_offload()
320+
pipe.enable_model_cpu_offload(device=torch_device)
321321
prompt = self.prompt
322322

323323
videos = pipe(

tests/pipelines/animatediff/test_animatediff.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from diffusers.utils.testing_utils import (
2323
numpy_cosine_similarity_distance,
2424
require_accelerator,
25-
require_torch_gpu,
25+
require_torch_accelerator,
2626
slow,
2727
torch_device,
2828
)
@@ -547,19 +547,25 @@ def test_vae_slicing(self):
547547

548548

549549
@slow
550-
@require_torch_gpu
550+
@require_torch_accelerator
551551
class AnimateDiffPipelineSlowTests(unittest.TestCase):
552552
def setUp(self):
553553
# clean up the VRAM before each test
554554
super().setUp()
555555
gc.collect()
556-
torch.cuda.empty_cache()
556+
if torch_device == "cuda":
557+
torch.cuda.empty_cache()
558+
elif torch_device == "xpu":
559+
torch.xpu.empty_cache()
557560

558561
def tearDown(self):
559562
# clean up the VRAM after each test
560563
super().tearDown()
561564
gc.collect()
562-
torch.cuda.empty_cache()
565+
if torch_device == "cuda":
566+
torch.cuda.empty_cache()
567+
elif torch_device == "xpu":
568+
torch.xpu.empty_cache()
563569

564570
def test_animatediff(self):
565571
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2")
@@ -573,7 +579,7 @@ def test_animatediff(self):
573579
clip_sample=False,
574580
)
575581
pipe.enable_vae_slicing()
576-
pipe.enable_model_cpu_offload()
582+
pipe.enable_model_cpu_offload(device=torch_device)
577583
pipe.set_progress_bar_config(disable=None)
578584

579585
prompt = "night, b&w photo of old house, post apocalypse, forest, storm weather, wind, rocks, 8k uhd, dslr, soft lighting, high quality, film grain"

tests/pipelines/cogvideo/test_cogvideox.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from diffusers.utils.testing_utils import (
2525
enable_full_determinism,
2626
numpy_cosine_similarity_distance,
27-
require_torch_gpu,
27+
require_torch_accelerator,
2828
slow,
2929
torch_device,
3030
)
@@ -321,7 +321,7 @@ def test_fused_qkv_projections(self):
321321

322322

323323
@slow
324-
@require_torch_gpu
324+
@require_torch_accelerator
325325
class CogVideoXPipelineIntegrationTests(unittest.TestCase):
326326
prompt = "A painting of a squirrel eating a burger."
327327

@@ -339,7 +339,7 @@ def test_cogvideox(self):
339339
generator = torch.Generator("cpu").manual_seed(0)
340340

341341
pipe = CogVideoXPipeline.from_pretrained("THUDM/CogVideoX-2b", torch_dtype=torch.float16)
342-
pipe.enable_model_cpu_offload()
342+
pipe.enable_model_cpu_offload(device=torch_device)
343343
prompt = self.prompt
344344

345345
videos = pipe(

tests/pipelines/cogvideo/test_cogvideox_image2video.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from diffusers.utils.testing_utils import (
2727
enable_full_determinism,
2828
numpy_cosine_similarity_distance,
29-
require_torch_gpu,
29+
require_torch_accelerator,
3030
slow,
3131
torch_device,
3232
)
@@ -344,25 +344,31 @@ def test_fused_qkv_projections(self):
344344

345345

346346
@slow
347-
@require_torch_gpu
347+
@require_torch_accelerator
348348
class CogVideoXImageToVideoPipelineIntegrationTests(unittest.TestCase):
349349
prompt = "A painting of a squirrel eating a burger."
350350

351351
def setUp(self):
352352
super().setUp()
353353
gc.collect()
354-
torch.cuda.empty_cache()
354+
if torch_device == "cuda":
355+
torch.cuda.empty_cache()
356+
elif torch_device == "xpu":
357+
torch.xpu.empty_cache()
355358

356359
def tearDown(self):
357360
super().tearDown()
358361
gc.collect()
359-
torch.cuda.empty_cache()
362+
if torch_device == "cuda":
363+
torch.cuda.empty_cache()
364+
elif torch_device == "xpu":
365+
torch.xpu.empty_cache()
360366

361367
def test_cogvideox(self):
362368
generator = torch.Generator("cpu").manual_seed(0)
363369

364370
pipe = CogVideoXImageToVideoPipeline.from_pretrained("THUDM/CogVideoX-5b-I2V", torch_dtype=torch.bfloat16)
365-
pipe.enable_model_cpu_offload()
371+
pipe.enable_model_cpu_offload(device=torch_device)
366372

367373
prompt = self.prompt
368374
image = load_image(

tests/pipelines/cogview3/test_cogview3plus.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from diffusers.utils.testing_utils import (
2525
enable_full_determinism,
2626
numpy_cosine_similarity_distance,
27-
require_torch_gpu,
27+
require_torch_accelerator,
2828
slow,
2929
torch_device,
3030
)
@@ -232,7 +232,7 @@ def test_attention_slicing_forward_pass(
232232

233233

234234
@slow
235-
@require_torch_gpu
235+
@require_torch_accelerator
236236
class CogView3PlusPipelineIntegrationTests(unittest.TestCase):
237237
prompt = "A painting of a squirrel eating a burger."
238238

@@ -250,7 +250,7 @@ def test_cogview3plus(self):
250250
generator = torch.Generator("cpu").manual_seed(0)
251251

252252
pipe = CogView3PlusPipeline.from_pretrained("THUDM/CogView3Plus-3b", torch_dtype=torch.float16)
253-
pipe.enable_model_cpu_offload()
253+
pipe.enable_model_cpu_offload(device=torch_device)
254254
prompt = self.prompt
255255

256256
images = pipe(

0 commit comments

Comments
 (0)