Skip to content

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

fix cuda ut bug of use_deterministic_algorithms (#805)

Heng Guo886d657125bd
diff --git a/auto_round/autoround.py b/auto_round/autoround.py
index 94b3e66a4..03e012578 100644
--- a/auto_round/autoround.py
+++ b/auto_round/autoround.py
@@ -224,7 +224,8 @@ class AutoRound(object):
to_quant_block_names: Union[str, list, None] = kwargs.pop("to_quant_block_names", None)
enable_norm_bias_tuning: bool = kwargs.pop("enable_norm_bias_tuning", False)
enable_quanted_input: bool = kwargs.pop("enable_quanted_input", True)
- disable_deterministic_algorithms = kwargs.pop("disable_deterministic_algorithms", False)
+ disable_deterministic_algorithms = kwargs.pop("disable_deterministic_algorithms", True)
+ enable_deterministic_algorithms = kwargs.pop("enable_deterministic_algorithms", False)
static_kv_dtype = kwargs.pop("static_kv_dtype", None)
device = kwargs.pop("device", None)
self.quant_lm_head = kwargs.pop("quant_lm_head", False)
@@ -234,11 +235,19 @@ class AutoRound(object):
if kwargs:
logger.warning(f"unrecognized keys {list(kwargs.keys())} were passed. Please check them.")
+ if "CUBLAS_WORKSPACE_CONFIG" not in os.environ:
+ os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
+ # deprecated, default not to use torch.use_deterministic_algorithms
+ if not disable_deterministic_algorithms or enable_deterministic_algorithms:
+ if not disable_deterministic_algorithms:
+ logger.warning(
+ "default not use deterministic_algorithms. disable_deterministic_algorithms is deprecated,"
+ " please use enable_deterministic_algorithms instead. "
+ )
- if not disable_deterministic_algorithms:
- if "CUBLAS_WORKSPACE_CONFIG" not in os.environ:
- os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
torch.use_deterministic_algorithms(True, warn_only=False)
+ else:
+ torch.use_deterministic_algorithms(True, warn_only=True)
if device is not None:
logger.warning("`device` is deprecated, please use `device_map` instead")
diff --git a/auto_round/script/llm.py b/auto_round/script/llm.py
index cbf30edb1..1d0ee5b2b 100644
--- a/auto_round/script/llm.py
+++ b/auto_round/script/llm.py
@@ -206,7 +206,12 @@ class BasicArgumentParser(argparse.ArgumentParser):
self.add_argument("--enable_alg_ext", action="store_true", help="whether to enable probably better algorithm")
self.add_argument(
- "--disable_deterministic_algorithms", action="store_true", help="disable torch deterministic algorithms."
+ "--disable_deterministic_algorithms",
+ action="store_true",
+ help="deprecated, disable torch deterministic algorithms.",
+ )
+ self.add_argument(
+ "--enable_deterministic_algorithms", action="store_true", help="enable torch deterministic algorithms."
)
self.add_argument(
@@ -543,6 +548,11 @@ def tune(args):
scheme = args.scheme.upper()
if scheme not in PRESET_SCHEMES:
raise ValueError(f"{scheme} is not supported. only {PRESET_SCHEMES.keys()} are supported ")
+ if args.disable_deterministic_algorithms:
+ logger.warning(
+ "default not use deterministic_algorithms. disable_deterministic_algorithms is deprecated,"
+ " please use enable_deterministic_algorithms instead. "
+ )
autoround = round(
model=model,
tokenizer=tokenizer,
@@ -580,7 +590,7 @@ def tune(args):
super_group_size=args.super_group_size,
super_bits=args.super_bits,
disable_opt_rtn=args.disable_opt_rtn,
- disable_deterministic_algorithms=args.disable_deterministic_algorithms,
+ enable_deterministic_algorithms=args.enable_deterministic_algorithms,
enable_alg_ext=args.enable_alg_ext,
**mllm_kwargs,
)
diff --git a/auto_round/script/mllm.py b/auto_round/script/mllm.py
index 162b2ee54..bbb2b42eb 100644
--- a/auto_round/script/mllm.py
+++ b/auto_round/script/mllm.py
@@ -173,7 +173,13 @@ class BasicArgumentParser(argparse.ArgumentParser):
self.add_argument("--enable_torch_compile", action="store_true", help="whether to enable torch compile")
self.add_argument(
- "--disable_deterministic_algorithms", action="store_true", help="disable torch deterministic algorithms."
+ "--disable_deterministic_algorithms",
+ action="store_true",
+ help="deprecated, disable torch deterministic algorithms.",
+ )
+
+ self.add_argument(
+ "--enable_deterministic_algorithms", action="store_true", help="enable torch deterministic algorithms."
)
## ======================= VLM =======================
@@ -435,7 +441,11 @@ def tune(args):
scheme = args.scheme.upper()
if scheme not in PRESET_SCHEMES:
raise ValueError(f"{scheme} is not supported. only {PRESET_SCHEMES.keys()} are supported ")
-
+ if args.disable_deterministic_algorithms:
+ logger.warning(
+ "default not use deterministic_algorithms. disable_deterministic_algorithms is deprecated,"
+ " please use enable_deterministic_algorithms instead. "
+ )
autoround = round(
model,
tokenizer,
@@ -473,7 +483,7 @@ def tune(args):
model_kwargs=model_kwargs,
data_type=args.data_type,
disable_opt_rtn=args.disable_opt_rtn,
- disable_deterministic_algorithms=args.disable_deterministic_algorithms,
+ enable_deterministic_algorithms=args.enable_deterministic_algorithms,
)
model_name = args.model.rstrip("/")