Skip to content

Commit f6745fd

Browse files
authored
Fix diffusion multi-device ut issue (#1002)
1 parent daeb3bb commit f6745fd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

auto_round/compressors/diffusion/compressor.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,20 @@ def calib(self, nsamples, bs):
308308
total = nsamples if not hasattr(self.dataloader, "len") else min(nsamples, len(self.dataloader))
309309
if self.pipe.dtype != self.model.dtype:
310310
self.pipe.to(self.model.dtype)
311+
312+
if (
313+
hasattr(self.model, "hf_device_map")
314+
and len(self.model.hf_device_map) > 0
315+
and self.pipe.device != self.model.device
316+
and torch.device(self.model.device).type in ["cuda", "xpu"]
317+
):
318+
logger.error(
319+
"Diffusion model is activated sequential model offloading, it will crash during moving to GPU/XPU. "
320+
"Please use model path for quantization or "
321+
"move the pipeline object to GPU/XPU before passing them into API."
322+
)
323+
exit(-1)
324+
311325
if self.pipe.device != self.model.device:
312326
self.pipe.to(self.model.device)
313327
with tqdm(range(1, total + 1), desc="cache block inputs") as pbar:

test/test_cuda/test_diffusion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def tearDownClass(self):
2828
@require_optimum
2929
def test_diffusion_tune(self):
3030
## load the model
31-
pipe = AutoPipelineForText2Image.from_pretrained(self.model_name)
31+
pipe = AutoPipelineForText2Image.from_pretrained(self.model_name).to("cuda")
3232
model = pipe.transformer
3333

3434
layer_config = {}

0 commit comments

Comments
 (0)