Skip to content

PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度

fix --device_map cuda and xpu issue (#1383)

Wenhua Chengf132c0c44285
diff --git a/auto_round/auto_scheme/utils.py b/auto_round/auto_scheme/utils.py
index c64b17e88..3c19acc42 100644
--- a/auto_round/auto_scheme/utils.py
+++ b/auto_round/auto_scheme/utils.py
@@ -241,6 +241,8 @@ def dispatch_model_by_all_available_devices(
device = int(device.split(":")[-1])
elif device == "cpu":
device = "cpu"
+ elif isinstance(device, str):
+ device = 0
else:
raise ValueError(f"Unsupported device {device} in device_map: {device_map}")
new_max_memory[device] = max_memory[device]
diff --git a/auto_round/compressors/base.py b/auto_round/compressors/base.py
index b9537ea08..8e6d1fbae 100644
--- a/auto_round/compressors/base.py
+++ b/auto_round/compressors/base.py
@@ -2150,6 +2150,8 @@ class BaseCompressor(object):
device = int(device.split(":")[-1])
elif device == "cpu":
device = "cpu"
+ elif isinstance(device, str):
+ device = 0
else:
raise ValueError(f"Unsupported device {device} in device_map: {self.device_map}")
# Use 90% of the reported max memory to leave headroom for activations,
diff --git a/test/test_cuda/export/test_gguf.py b/test/test_cuda/export/test_gguf.py
index e71af74c4..60182aa48 100644
--- a/test/test_cuda/export/test_gguf.py
+++ b/test/test_cuda/export/test_gguf.py
@@ -66,7 +66,7 @@ class TestAutoRound:
save_dir = os.path.join(os.path.dirname(__file__), "saved")
res = os.system(
f"PYTHONPATH='{AUTO_ROUND_PATH}:$PYTHONPATH' {sys.executable} -m auto_round --model {tiny_qwen_model_path} --iter 2 "
- f"--output_dir {save_dir} --nsample 2 --format gguf:q4_0 --device 0"
+ f"--output_dir {save_dir} --nsample 2 --format gguf:q4_0 --device cuda"
)
print(save_dir)
assert not (res > 0 or res == -1), "qwen2 tuning fail"