|
--- |
|
license: apache-2.0 |
|
datasets: |
|
- NeelNanda/pile-10k |
|
--- |
|
## Model Details |
|
|
|
This model is an int4 model with group_size 128 and symmetric quantization of [Qwen/Qwen2-VL-72B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-72B-Instruct) generated by [intel/auto-round](https://github.com/intel/auto-round). Load the model with revision="e67cae7" to use AutoGPTQ format. |
|
|
|
## How To Use |
|
|
|
|
|
### Requirements |
|
The code of Qwen2-VL has been in the latest Hugging face transformers and we advise you to build from source with command `pip install git+https://github.com/huggingface/transformers`, or you might encounter the following error: |
|
``` |
|
KeyError: 'qwen2_vl' |
|
``` |
|
|
|
### INT4 Inference |
|
```python |
|
from auto_round import AutoRoundConfig ## must import for auto-round format |
|
import requests |
|
from PIL import Image |
|
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor |
|
quantized_model_path="OPEA/Qwen2-VL-72B-Instruct-int4-sym-inc" |
|
model = Qwen2VLForConditionalGeneration.from_pretrained( |
|
quantized_model_path, |
|
torch_dtype="auto", |
|
device_map="auto", |
|
##revision="e67cae7" ##AutoGPTQ format |
|
) |
|
processor = AutoProcessor.from_pretrained(quantized_model_path) |
|
image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg" |
|
messages = [ |
|
{ |
|
"role": "user", |
|
"content": [ |
|
{ |
|
"type": "image", |
|
"image": image_url, |
|
}, |
|
{"type": "text", "text": "Describe this image."}, |
|
], |
|
} |
|
] |
|
|
|
# Preparation for inference |
|
text = processor.apply_chat_template( |
|
messages, tokenize=False, add_generation_prompt=True |
|
) |
|
image_inputs = Image.open(requests.get(image_url, stream=True).raw) |
|
inputs = processor( |
|
text=[text], |
|
images=image_inputs, |
|
padding=True, |
|
return_tensors="pt", |
|
) |
|
inputs = inputs.to(model.device) |
|
|
|
generated_ids = model.generate(**inputs, max_new_tokens=128, do_sample=False) |
|
generated_ids_trimmed = [ |
|
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids) |
|
] |
|
output_text = processor.batch_decode( |
|
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False, |
|
) |
|
print(output_text[0]) |
|
|
|
##INT4: |
|
## The image depicts a serene beach scene at sunset. A woman is sitting on the sand, facing a large dog, likely a Labrador Retriever. The woman is wearing a plaid shirt and shorts, and she appears to be smiling as she interacts with the dog. The dog is wearing a harness and is giving the woman a paw. The sun is setting in the background, casting a warm glow over the entire scene, creating a peaceful and heartwarming atmosphere. The waves of the ocean can be seen gently rolling onto the shore behind them. |
|
|
|
##BF16: |
|
## The image depicts a serene beach scene at sunset. A person is sitting on the sand, facing the ocean, with their back to the camera. They are wearing a plaid shirt and shorts. Next to them, a large dog, possibly a Labrador Retriever, is sitting upright, facing the person. The dog is wearing a harness. The sun is setting in the background, casting a warm glow over the entire scene, creating a peaceful and tranquil atmosphere. The waves gently lap at the shore, adding to the calm ambiance. |
|
|
|
image_url = "http://images.cocodataset.org/train2017/000000411975.jpg" |
|
messages = [ |
|
{ |
|
"role": "user", |
|
"content": [ |
|
{ |
|
"type": "image", |
|
"image": image_url, |
|
}, |
|
{"type": "text", "text": "图片中的棒球场上有多少人?"}, |
|
], |
|
} |
|
] |
|
##INT4: |
|
## 图片中棒球场上有三个人。 |
|
|
|
##BF16: |
|
## 图片中没有描述棒球场上有多少人。 |
|
|
|
image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270" |
|
messages = [ |
|
{ |
|
"role": "user", |
|
"content": [ |
|
{ |
|
"type": "image", |
|
"image": image_url, |
|
}, |
|
{"type": "text", "text": "这张图片代表哪家公司?"}, |
|
], |
|
} |
|
] |
|
##INT4: |
|
## 这张图片代表的是Intel公司。图片中的标志是Intel Inside,这是Intel公司的标志性标语和标志。 |
|
|
|
##BF16: |
|
## 这张图片代表的是英特尔(Intel)公司。 |
|
|
|
``` |
|
|
|
## Evaluation the model |
|
pip3 install git+https://github.com/open-compass/VLMEvalKit.git@7de2dcb. The evaluation process may encounter errors that require changing model backend or evaluation code. Detailed instructions will be provided in a future update. |
|
```bash |
|
auto-round-mllm --eval --model OPEA/Qwen2-VL-7B-Instruct-int4-sym-inc --tasks MMBench_DEV_EN_V11,ScienceQA_VAL,TextVQA_VAL,POPE --output_dir "./eval_result" |
|
``` |
|
|Metric |16bits|Pile Calib INT4 | |
|
|:-------------------|:------|:------| |
|
|avg |87.80 |87.63 | |
|
|MMBench_DEV_EN_V11 |86.76 |86.30 | |
|
|ScienceQA_VAL |91.65 |91.23 | |
|
|TextVQA_VAL |85.45 |85.39 | |
|
|POPE |87.32 |87.61 | |
|
|
|
### Generate the model |
|
Here is the sample command to reproduce the model. |
|
```bash |
|
pip install auto-round |
|
auto-round-mllm |
|
--model Qwen/Qwen2-VL-72B-Instruct \ |
|
--device 0,1 \ |
|
--group_size 128 \ |
|
--bits 4 \ |
|
--iters 1000 \ |
|
--nsample 512 \ |
|
--seqlen 2048 \ |
|
--format 'auto_gptq,auto_round' \ |
|
--output_dir "./tmp_autoround" |
|
``` |
|
|
|
## Ethical Considerations and Limitations |
|
|
|
The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs. |
|
|
|
Therefore, before deploying any applications of the model, developers should perform safety testing. |
|
|
|
## Caveats and Recommendations |
|
|
|
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. |
|
|
|
Here are a couple of useful links to learn more about Intel's AI software: |
|
|
|
- Intel Neural Compressor [link](https://github.com/intel/neural-compressor) |
|
|
|
## Disclaimer |
|
|
|
The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes. |
|
|
|
## Cite |
|
|
|
@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} } |
|
|
|
[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round) |