File size: 5,925 Bytes
d20156a
 
 
 
 
 
 
 
 
 
 
a795409
 
 
 
 
d20156a
 
 
 
 
 
 
 
 
 
 
542f2a4
d20156a
 
 
 
 
 
 
0b5077e
d20156a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e35c422
d20156a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254e3ef
d20156a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
datasets:
- NeelNanda/pile-10k
base_model:
- deepseek-ai/deepseek-vl2
---
## Model Details

This model is an int4 model with group_size 128 and symmetric quantization of [deepseek-ai/deepseek-vl2](https://huggingface.co/deepseek-ai/deepseek-vl2) generated by [intel/auto-round](https://github.com/intel/auto-round).

## How to Use
### Requirements
On the basis of Python >= 3.8 environment, install the necessary dependencies by running the following command:
```bash
pip install git+https://github.com/deepseek-ai/DeepSeek-VL2.git@8bde1c1ae17510a1d1c686a0b55a6c7e61352a46
```
### INT4 Inference
```python
import requests
import torch
from PIL import Image
from transformers import AutoModelForCausalLM

from deepseek_vl2.models import DeepseekVLV2Processor, DeepseekVLV2ForCausalLM


# specify the path to the model
model_path = "OPEA/deepseek-vl2-int4-sym-gptq-inc"
vl_chat_processor: DeepseekVLV2Processor = DeepseekVLV2Processor.from_pretrained(model_path)
tokenizer = vl_chat_processor.tokenizer

vl_gpt: DeepseekVLV2ForCausalLM = AutoModelForCausalLM.from_pretrained(
  model_path,
  trust_remote_code=True,
  device_map="auto",
  torch_dtype=torch.float16,
)
vl_gpt = vl_gpt.eval()

image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
content = "Describe this image."

## single image conversation example
conversation = [
    {
        "role": "<|User|>",
        "content": content,
    },
    {"role": "<|Assistant|>", "content": ""},
]

# load images and prepare for inputs
pil_images = Image.open(requests.get(image_url, stream=True).raw)
prepare_inputs = vl_chat_processor(
    conversations=conversation,
    images=[pil_images],
    force_batchify=True,
    system_prompt=""
).to(vl_gpt.device)
prepare_inputs = prepare_inputs.to(vl_gpt.device)

# run image encoder to get the image embeddings
inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)

# run the model to get the response
outputs = vl_gpt.language.generate(
    input_ids = prepare_inputs["input_ids"],
    inputs_embeds=inputs_embeds,
    attention_mask=prepare_inputs.attention_mask,
    pad_token_id=tokenizer.eos_token_id,
    bos_token_id=tokenizer.bos_token_id,
    eos_token_id=tokenizer.eos_token_id,
    max_new_tokens=512,  ##change this to align with the official usage
    do_sample=False,  ##change this to align with the official usage
    use_cache=True  ##change this to align with the official usage
)

answer = tokenizer.decode(outputs[0].cpu().tolist(), skip_special_tokens=True)
print(f"{prepare_inputs['sft_format'][0]}", answer)

#INT4: 
## This image shows a person standing in front of a large, colorful mural. The mural depicts a vibrant cityscape with tall buildings, bright lights, and a bustling street scene. The person is dressed in casual clothing and is smiling at the camera. The overall atmosphere of the image is lively and energetic.
#BF16:
## This image shows a person standing in front of a large, colorful mural. The mural depicts a vibrant cityscape with tall buildings, bright lights, and a bustling street scene. The person in the image is wearing a casual outfit and appears to be taking a photo of the mural with their phone. The overall atmosphere of the image is lively and energetic, with a sense of excitement and creativity.

image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
content = "How many people are there on the baseball field in the image?"
#INT4:
#There are no people on the baseball field in the image.
#BF16:
# There are no people visible on the baseball field in the image.

image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
content = "This image represents which company?"
#INT4:
# I'm sorry, but I cannot identify or recognize companies based on images. However, I can help you with information about companies or provide general knowledge on various topics. If you have any questions or need assistance, feel free to ask!
#BF16:
# I'm sorry, but I cannot provide information about the company represented in the image as I do not have the ability to view or interpret images. However, if you provide me with a description of the image, I may be able to help you identify the company.
```

### Generate the model
Here is the sample command to reproduce the model.
```bash
pip install auto-round
auto-round-mllm \
--model deepseek-ai/deepseek-vl2 \
--device 0 \
--group_size 128 \
--bits 4 \
--iters 1000 \
--nsample 512 \
--seqlen 2048 \
--format 'auto_gptq' \
--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)