Skip to content
Merged
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
14 changes: 13 additions & 1 deletion neural_compressor/model/torch_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,18 @@ def export_compressed_model(
gptq_config = self.gptq_config if hasattr(self, "gptq_config") else {}

autoround_config = self.autoround_config if hasattr(self, "autoround_config") else {}
# check available device, priority: ["xpu", "cuda", "cpu"]
availiable_device = []
if hasattr(torch, "xpu") and torch.xpu.is_available():
availiable_device.append("xpu")
if torch.cuda.is_available():
availiable_device.append("cuda")
availiable_device.append("cpu")
orig_device = device
if device not in availiable_device and "cuda" not in device: # cuda in cuda:0
logger.info(f"{device} is not detected in current environment, please check.")
device = availiable_device[0]
logger.info(f"The compression device has been changed to {device}.")
if gptq_config:
for k, v in weight_config.items():
logger.debug(f"Compressing {k} on device {device}")
Expand Down Expand Up @@ -558,7 +570,7 @@ def export_compressed_model(
new_module.pack(int_weight, gptq_scale, gptq_zp, m.bias, gptq_perm)
set_module(self.model, k, new_module)
elif autoround_config:
if device == "xpu":
if orig_device == "xpu":
for k, v in weight_config.items():
logger.debug(f"Compressing {k} on device {device}")
if v["dtype"] == "fp32":
Expand Down