diff --git a/gptqmodel/models/base.py b/gptqmodel/models/base.py index c5de0c658..2833f8d3e 100644 --- a/gptqmodel/models/base.py +++ b/gptqmodel/models/base.py @@ -466,7 +466,7 @@ def store_input_hook(_, args, kwargs): example[k] = move_to(v, cur_layer_device) try: if is_ovis: - self.generate(inputs=example.pop("input_ids"), **example) + self.generate(inputs=example.pop("input_ids"), max_new_tokens=1024, **example) else: self.model(**example) except ValueError: diff --git a/gptqmodel/models/definitions/qwen2_vl.py b/gptqmodel/models/definitions/qwen2_vl.py index 000ec0dcb..b5ffc2706 100644 --- a/gptqmodel/models/definitions/qwen2_vl.py +++ b/gptqmodel/models/definitions/qwen2_vl.py @@ -1,7 +1,9 @@ +import os.path +import shutil from typing import Dict, Optional from PIL import Image -from transformers import AutoModelForVision2Seq, AutoProcessor +from transformers import AutoModelForVision2Seq, AutoProcessor, AutoTokenizer from ..base import BaseGPTQModel from ...utils.calibration import batched @@ -82,7 +84,20 @@ def prepare_dataset( calibration_dataset, batch_size: int = 1, tokenizer=None, ): - processor = AutoProcessor.from_pretrained(self.model_id_or_path) + import tempfile + import json + + if tokenizer is None: + tokenizer = AutoTokenizer.from_pretrained(self.model_id_or_path) + + with tempfile.TemporaryDirectory() as tmp_dir: + chat_template_file = os.path.join(self.model_id_or_path, "chat_template.json") + if os.path.exists(chat_template_file): + shutil.copyfile(chat_template_file, os.path.join(tmp_dir, "chat_template.json")) + tokenizer.save_pretrained(tmp_dir) + with open(os.path.join(tmp_dir, "preprocessor_config.json"), "w") as f: + f.write(json.dumps(self.quant_override_files["preprocessor_config.json"])) + processor = AutoProcessor.from_pretrained(tmp_dir) calib_data = [] for batch in batched(calibration_dataset, batch_size, process_func=self.preprocess_dataset): text = processor.apply_chat_template( diff --git a/tests/models/ovis/image_to_test_dataset.py b/tests/models/ovis/image_to_test_dataset.py index 22645c4eb..bc0eccecb 100644 --- a/tests/models/ovis/image_to_test_dataset.py +++ b/tests/models/ovis/image_to_test_dataset.py @@ -47,6 +47,6 @@ def get_calib_dataset(model): return prepare_dataset(format_ovis_dataset, n_sample=20) if isinstance(model, Qwen2VLGPTQ): - return prepare_dataset(format_qwen2_vl_dataset, n_sample=20) + return prepare_dataset(format_qwen2_vl_dataset, n_sample=1) raise NotImplementedError(f"Unsupported MODEL: {model.__class__}")