Skip to content

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

fix vlm hf config loading issue (#624)

Weiwei514939043a88
diff --git a/auto_round/utils.py b/auto_round/utils.py
index 48ef3d987..326529201 100644
--- a/auto_round/utils.py
+++ b/auto_round/utils.py
@@ -1334,13 +1334,26 @@ def mllm_load_model(
import json
import transformers
from transformers import AutoProcessor, AutoTokenizer, AutoModelForCausalLM
- from huggingface_hub import HfApi, HfFileSystem
+ from huggingface_hub import HfApi, hf_hub_download, HfFileSystem
if os.path.isdir(pretrained_model_name_or_path):
config = json.load(open(os.path.join(pretrained_model_name_or_path, "config.json")))
else:
- hf_file = HfFileSystem()
- config = json.load(hf_file.open(pretrained_model_name_or_path + "/config.json"))
+ from huggingface_hub import hf_hub_download, list_repo_files
+ file_list = list_repo_files(pretrained_model_name_or_path)
+ if "config.json" in file_list:
+ # Load plain JSON
+ config_path = hf_hub_download(pretrained_model_name_or_path, "config.json")
+ with open(config_path, "r", encoding="utf-8") as f:
+ config = json.load(f)
+ elif "config.json.gz" in file_list:
+ # Load gzipped JSON
+ import gzip
+ config_path = hf_hub_download(pretrained_model_name_or_path, "config.json.gz")
+ with gzip.open(config_path, "rt", encoding="utf-8") as f:
+ config = json.load(f)
+ else:
+ raise FileNotFoundError(f"No config.json or config.json.gz found for {pretrained_model_name_or_path}")
if "model_type" in config:
model_type = config["model_type"]
@@ -1830,3 +1843,4 @@ def get_gguf_qtype_by_layer_config(layer_config):
if bits == 8 and sym and group_size == 32:
return gguf.GGMLQuantizationType.Q8_0
raise ValueError(f"Unknown layer config")
+