diff --git a/src/accelerate/accelerator.py b/src/accelerate/accelerator.py index 8ded324a860..bc44dd1094d 100755 --- a/src/accelerate/accelerator.py +++ b/src/accelerate/accelerator.py @@ -1998,7 +1998,7 @@ def _prepare_ipex_or_xpu(self, *args): optimizer = obj if optimizer is not None and model is not None: dtype = torch.bfloat16 if self.state.mixed_precision == "bf16" else None - if self.device.type == "xpu" and model.device.type == "cpu": + if self.device.type == "xpu" and next(model.parameters()).device.type == "cpu": model = model.to(self.device) # ipex.optimize() is available only for IPEX, both IPEX-CPU and IPEX-XPU if is_ipex_available():