PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
Allow disabling copy_missing_tensors_from_source via env var, default enabled (#1623)
Xin He1897e5efc6e6
diff --git a/auto_round/envs.py b/auto_round/envs.pyindex b4576dece..7893b6e80 100644--- a/auto_round/envs.py+++ b/auto_round/envs.py@@ -31,6 +31,8 @@ environment_variables: dict[str, Callable[[], Any]] = {in ["1", "true"],"AR_OMP_NUM_THREADS": lambda: os.getenv("AR_OMP_NUM_THREADS", None),"AR_DISABLE_OFFLOAD": lambda: os.getenv("AR_DISABLE_OFFLOAD", "0").lower() in ("1", "true", "yes"),+ "AR_DISABLE_COPY_MTP_WEIGHTS": lambda: os.getenv("AR_DISABLE_COPY_MTP_WEIGHTS", "0").lower()+ in ("1", "true", "yes"),}diff --git a/auto_round/export/utils.py b/auto_round/export/utils.pyindex fa01e1da4..a71aad2ab 100644--- a/auto_round/export/utils.py+++ b/auto_round/export/utils.py@@ -17,6 +17,7 @@ import shutilimport torch.nn as nn+import auto_round.envs as envsfrom auto_round.utils import (copy_missing_tensors_from_source,copy_python_files_from_model_cache,@@ -191,18 +192,20 @@ def save_model(else:model.save_pretrained(save_dir, max_shard_size=max_shard_size, safe_serialization=safe_serialization)- try:- if (- hasattr(model, "config")- and hasattr(model.config, "_name_or_path")- and model.config.name_or_path is not None # set None for tiny model- ):- copy_missing_tensors_from_source(- source_dir=model.config._name_or_path,- target_dir=save_dir,- )- except Exception as e:- logger.warning("Skipping copy of missing tensors from source checkpoint due to error: %s", e)+ # Allow disabling copy_missing_tensors_from_source via env var AR_DISABLE_COPY_MTP_WEIGHTS, default enabled+ if not envs.AR_DISABLE_COPY_MTP_WEIGHTS:+ try:+ if (+ hasattr(model, "config")+ and hasattr(model.config, "_name_or_path")+ and model.config.name_or_path is not None # set None for tiny model+ ):+ copy_missing_tensors_from_source(+ source_dir=model.config._name_or_path,+ target_dir=save_dir,+ )+ except Exception as e:+ logger.warning("Skipping copy of missing tensors from source checkpoint due to error: %s", e)config_path = os.path.join(save_dir, "config.json")if dtype is not None and dtype != model.dtype and os.path.exists(os.path.join(save_dir, "config.json")):