Skip to content

Commit

Permalink
[FIX] vl model test (ModelCloud#953)
Browse files Browse the repository at this point in the history
* Use quant_override_files["preprocessor_config.json"] to process input data

* qwen_vl use sample size 1

* add debug log

* Revert "add debug log"

This reverts commit 105b9e6.

* When calling OvisModel.generate(), you need to pass in max_new_tokens.

* cleanup
  • Loading branch information
ZX-ModelCloud authored Dec 23, 2024
1 parent fdcf53b commit 748a9c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gptqmodel/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 17 additions & 2 deletions gptqmodel/models/definitions/qwen2_vl.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/models/ovis/image_to_test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}")

0 comments on commit 748a9c7

Please sign in to comment.