Skip to content

Commit

Permalink
only move model to device when model is in cpu and target device is x…
Browse files Browse the repository at this point in the history
…pu (#3133)
  • Loading branch information
faaany authored Oct 7, 2024
1 parent cd93e35 commit 1077611
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/accelerate/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,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":
if self.device.type == "xpu" and model.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():
Expand Down
2 changes: 1 addition & 1 deletion src/accelerate/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def default_device(self) -> torch.device:
elif torch.cuda.is_available():
return torch.device("cuda")
elif is_xpu_available():
return torch.device("xpu:0")
return torch.device("xpu")
else:
return torch.device("cpu")

Expand Down

0 comments on commit 1077611

Please sign in to comment.