PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
Support Wan2.2 S2V Quantization (#1924)
Wang, Changca37879959dc
diff --git a/auto_round/export/export_to_autoround/export_to_fp8.py b/auto_round/export/export_to_autoround/export_to_fp8.pyindex 467df50ef..c40f5a33a 100644--- a/auto_round/export/export_to_autoround/export_to_fp8.py+++ b/auto_round/export/export_to_autoround/export_to_fp8.py@@ -280,8 +280,10 @@ def save_quantized_as_autoround(immediate_saving = is_immediate_saving_mode(model, serialization_dict)if os.path.exists(output_dir) and not immediate_saving:logger.warning(f"{output_dir} already exists, this may cause model conflict")- if tokenizer is not None:+ if tokenizer is not None and hasattr(tokenizer, "save_pretrained"):tokenizer.save_pretrained(output_dir)+ else:+ print(f"Skip tokenizer save, tokenizer={tokenizer}")if processor is not None:processor.save_pretrained(output_dir)diff --git a/auto_round/export/export_to_autoround/export_to_nvfp_mx.py b/auto_round/export/export_to_autoround/export_to_nvfp_mx.pyindex c9607ae40..045f8f70f 100644--- a/auto_round/export/export_to_autoround/export_to_nvfp_mx.py+++ b/auto_round/export/export_to_autoround/export_to_nvfp_mx.py@@ -269,8 +269,10 @@ def save_quantized_as_fp(immediate_saving = is_immediate_saving_mode(model, serialization_dict)if os.path.exists(output_dir) and not immediate_saving:logger.warning(f"{output_dir} already exists, this may cause model conflict")- if tokenizer is not None:+ if tokenizer is not None and hasattr(tokenizer, "save_pretrained"):tokenizer.save_pretrained(output_dir)+ else:+ print(f"Skip tokenizer save, tokenizer={tokenizer}")if processor is not None:processor.save_pretrained(output_dir)diff --git a/auto_round/utils/model.py b/auto_round/utils/model.pyindex a809ccd60..1cd28df7a 100644--- a/auto_round/utils/model.py+++ b/auto_round/utils/model.py@@ -18,7 +18,7 @@ import osimport refrom collections import UserDictfrom pathlib import Path-from typing import TYPE_CHECKING, Union+from typing import TYPE_CHECKING, Optional, Unionimport psutilimport torch@@ -949,10 +949,16 @@ _is_mllm_model_cache: dict = {}_LLM_ONLY_MODEL_TYPES = {"bagel"}+def get_model_name_or_path(model_or_path: Union[str, torch.nn.Module]) -> Optional[str]:+ if isinstance(model_or_path, str):+ return model_or_path+ return getattr(model_or_path, "_name_or_path", None) or getattr(model_or_path, "name_or_path", None)++def is_mllm_model(model_or_path: Union[str, torch.nn.Module], platform: str = None):from auto_round.utils.common import MM_KEYS- model_path = model_or_path if isinstance(model_or_path, str) else model_or_path.name_or_path+ model_path = get_model_name_or_path(model_or_path)# Fast path: return cached result for already-seen pathsif model_path in _is_mllm_model_cache:@@ -999,7 +1005,7 @@ def is_mllm_model(model_or_path: Union[str, torch.nn.Module], platform: str = Nobreak# Cache by the original path key (model_path may have been resolved above)- original_key = model_or_path if isinstance(model_or_path, str) else model_or_path.name_or_path+ original_key = get_model_name_or_path(model_or_path)_is_mllm_model_cache[original_key] = resultreturn result