PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
fix bug in PR-1244 (#1422)
Xin He81383e92316c
diff --git a/auto_round/__main__.py b/auto_round/__main__.pyindex 5b9616f65..8ee9ed7f6 100644--- a/auto_round/__main__.py+++ b/auto_round/__main__.py@@ -737,7 +737,7 @@ def setup_eval_parser():def run_eval():from auto_round.logger import logger- from auto_round.utils import is_mllm_model+ from auto_round.utils import is_gguf_model, is_mllm_modelargs = setup_eval_parser()assert args.model or args.model_name, "[model] or --model MODEL_NAME should be set."@@ -747,7 +747,7 @@ def run_eval():if "llama" in args.model.lower() and not args.add_bos_token:logger.warning("set add_bos_token=True for llama model.")args.add_bos_token = True- if is_mllm_model(args.model):+ if not is_gguf_model(args.model) and is_mllm_model(args.model):args.mllm = Trueif args.eval_task_by_task:diff --git a/auto_round/export/export_to_gguf/convert.py b/auto_round/export/export_to_gguf/convert.pyindex 1f93bbba6..1ebbbdfd8 100644--- a/auto_round/export/export_to_gguf/convert.py+++ b/auto_round/export/export_to_gguf/convert.py@@ -419,9 +419,8 @@ def prepare_tensors(cls):breakif skip:continue- # sync with new version of gguf- # data = data_torch.squeeze()- data = data_torch+ # squeeze is necessary for reloading in transformers.+ data = data_torch.squeeze()n_dims = len(data.shape)data_qtype: gguf.GGMLQuantizationType | bool = cls.tensor_force_quant(name, new_name, bid, n_dims)@@ -550,14 +549,13 @@ def prepare_tensors(cls):gguf.GGMLQuantizationType.BF16,gguf.GGMLQuantizationType.F32,]:- # sync with new version of gguf- # data = data_torch.squeeze().cpu().numpy()+ # squeeze is necessary for reloading in transformers.+ data = data_torch.squeeze().cpu().numpy()# if data ends up empty, it means data_torch was a scalar tensor -> restoreif len(data_torch.shape) == 0:data = data_torch.numpy()try:- data = data_torch.cpu().numpy()data = gguf.quants.quantize(data, data_qtype)except gguf.QuantError as e:logger.warning("%s, %s", e, "falling back to F16")diff --git a/auto_round/utils/model.py b/auto_round/utils/model.pyindex 94fb7198b..3c265f9ed 100644--- a/auto_round/utils/model.py+++ b/auto_round/utils/model.py@@ -563,6 +563,19 @@ def is_mllm_model(model_or_path: Union[str, torch.nn.Module], platform: str = Noreturn False+def is_gguf_model(model_path: Union[str, torch.nn.Module]) -> bool:+ is_gguf_file = False+ if isinstance(model_path, str):+ if os.path.isfile(model_path) and model_path.endswith(".gguf"):+ is_gguf_file = True+ elif os.path.exists(model_path):+ for file in os.listdir(model_path):+ if file.endswith(".gguf"):+ is_gguf_file = True+ break+ return is_gguf_file++def is_diffusion_model(model_or_path: Union[str, object]) -> bool:from auto_round.utils.common import LazyImport