Skip to content

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

fix deadlock issue when do quantization on hpu. (#1571)

lkk093324c1956a
diff --git a/auto_round/export/export_to_llmcompressor/export_to_static_fp.py b/auto_round/export/export_to_llmcompressor/export_to_static_fp.py
index 01a6be76d..6c534f8fc 100644
--- a/auto_round/export/export_to_llmcompressor/export_to_static_fp.py
+++ b/auto_round/export/export_to_llmcompressor/export_to_static_fp.py
@@ -36,6 +36,7 @@ from auto_round.utils import (
get_module,
get_packing_device,
is_gaudi2,
+ is_hpex_available,
logger,
set_module,
unsupported_meta_device,
@@ -154,17 +155,22 @@ def save_quantized_as_static_fp(
if not torch.cuda.is_available() and not torch.xpu.is_available():
max_workers = 2 ## 2 with cuda packing will cause hang occasionally
if not unsupported_meta_device(model):
- with ThreadPoolExecutor(max_workers=max_workers) as executor:
- with tqdm(total=len(names), leave=True) as pbar:
- def wrapper(name):
- pbar.set_description(f"packing {name}")
- with tctl.threadpool_limits(limits=1):
- pack_layer(name, model, serialization_dict.get("data_type", "fp8"), device)
- pbar.update(1)
-
- for _ in executor.map(wrapper, names):
- pass
+ if is_hpex_available(): # packing will cause hang occasionally on hpu
+ for name in tqdm(names, total=len(names), leave=True, desc="packing"):
+ pack_layer(name, model, serialization_dict.get("data_type", "fp8"), device)
+ else:
+ with ThreadPoolExecutor(max_workers=max_workers) as executor:
+ with tqdm(total=len(names), leave=True) as pbar:
+
+ def wrapper(name):
+ pbar.set_description(f"packing {name}")
+ with tctl.threadpool_limits(limits=1):
+ pack_layer(name, model, serialization_dict.get("data_type", "fp8"), device)
+ pbar.update(1)
+
+ for _ in executor.map(wrapper, names):
+ pass
# Get llm-compressor format config
check_compressed_tensors_supported()