Skip to content

enable group_offload cases and quanto cases on XPU #11405

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 6 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/pipelines/test_pipelines_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
require_accelerator,
require_hf_hub_version_greater,
require_torch,
require_torch_gpu,
require_torch_accelerator,
require_transformers_version_greater,
skip_mps,
torch_device,
Expand Down Expand Up @@ -2210,7 +2210,7 @@ def test_layerwise_casting_inference(self):
inputs = self.get_dummy_inputs(torch_device)
_ = pipe(**inputs)[0]

@require_torch_gpu
@require_torch_accelerator
def test_group_offloading_inference(self):
if not self.test_group_offloading:
return
Expand Down
26 changes: 16 additions & 10 deletions tests/quantization/quanto/test_quanto.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
from diffusers.models.attention_processor import Attention
from diffusers.utils import is_optimum_quanto_available, is_torch_available
from diffusers.utils.testing_utils import (
backend_empty_cache,
backend_reset_peak_memory_stats,
enable_full_determinism,
nightly,
numpy_cosine_similarity_distance,
require_accelerate,
require_big_gpu_with_torch_cuda,
require_big_accelerator,
require_torch_cuda_compatibility,
torch_device,
)
Expand All @@ -23,9 +26,11 @@

from ..utils import LoRALayer, get_memory_consumption_stat

enable_full_determinism()


@nightly
@require_big_gpu_with_torch_cuda
@require_big_accelerator
@require_accelerate
class QuantoBaseTesterMixin:
model_id = None
Expand All @@ -39,13 +44,13 @@ class QuantoBaseTesterMixin:
_test_torch_compile = False

def setUp(self):
torch.cuda.reset_peak_memory_stats()
torch.cuda.empty_cache()
backend_reset_peak_memory_stats(torch_device)
backend_empty_cache(torch_device)
gc.collect()

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

def get_dummy_init_kwargs(self):
Expand Down Expand Up @@ -89,7 +94,7 @@ def test_keep_modules_in_fp32(self):
self.model_cls._keep_in_fp32_modules = self.keep_in_fp32_module

model = self.model_cls.from_pretrained(**self.get_dummy_model_init_kwargs())
model.to("cuda")
model.to(torch_device)

for name, module in model.named_modules():
if isinstance(module, torch.nn.Linear):
Expand All @@ -107,7 +112,7 @@ def test_modules_to_not_convert(self):
init_kwargs.update({"quantization_config": quantization_config})

model = self.model_cls.from_pretrained(**init_kwargs)
model.to("cuda")
model.to(torch_device)

for name, module in model.named_modules():
if name in self.modules_to_not_convert:
Expand All @@ -122,7 +127,8 @@ def test_dtype_assignment(self):

with self.assertRaises(ValueError):
# Tries with a `device` and `dtype`
model.to(device="cuda:0", dtype=torch.float16)
device_0 = f"{torch_device}:0"
model.to(device=device_0, dtype=torch.float16)

with self.assertRaises(ValueError):
# Tries with a cast
Expand All @@ -133,7 +139,7 @@ def test_dtype_assignment(self):
model.half()

# This should work
model.to("cuda")
model.to(torch_device)

def test_serialization(self):
model = self.model_cls.from_pretrained(**self.get_dummy_model_init_kwargs())
Expand Down
Loading