cicdatopea commited on
Commit
dc7decd
1 Parent(s): fb77034

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +130 -0
README.md ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - NeelNanda/pile-10k
4
+ base_model:
5
+ - deepseek-ai/deepseek-vl2
6
+ ---
7
+ ## Model Details
8
+
9
+ This model is an int4 model(The vision module has also been quantized) 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).
10
+
11
+ ## How to Use
12
+ ### INT4 Inference
13
+ ```python
14
+ from auto_round import AutoRoundConfig ##must import for auto-round format
15
+ import requests
16
+ import torch
17
+ from PIL import Image
18
+ from transformers import AutoModelForCausalLM
19
+
20
+ from deepseek_vl2.models import DeepseekVLV2Processor, DeepseekVLV2ForCausalLM
21
+
22
+
23
+ # specify the path to the model
24
+ model_path = "OPEA/deepseek-vl2-int4-sym-inc"
25
+ vl_chat_processor: DeepseekVLV2Processor = DeepseekVLV2Processor.from_pretrained(model_path)
26
+ tokenizer = vl_chat_processor.tokenizer
27
+
28
+ vl_gpt: DeepseekVLV2ForCausalLM = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, device_map="auto", torch_dtype="auto")
29
+ vl_gpt = vl_gpt.eval()
30
+
31
+ image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
32
+ content = "Describe this image."
33
+
34
+ ## single image conversation example
35
+ conversation = [
36
+ {
37
+ "role": "<|User|>",
38
+ "content": content,
39
+ },
40
+ {"role": "<|Assistant|>", "content": ""},
41
+ ]
42
+
43
+ # load images and prepare for inputs
44
+ pil_images = Image.open(requests.get(image_url, stream=True).raw)
45
+ prepare_inputs = vl_chat_processor(
46
+ conversations=conversation,
47
+ images=[pil_images],
48
+ force_batchify=True,
49
+ system_prompt=""
50
+ )
51
+ prepare_inputs = prepare_inputs.to(vl_gpt.device)
52
+
53
+ # run image encoder to get the image embeddings
54
+ inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)
55
+
56
+ # run the model to get the response
57
+ outputs = vl_gpt.language.generate(
58
+ input_ids = prepare_inputs["input_ids"],
59
+ inputs_embeds=inputs_embeds,
60
+ attention_mask=prepare_inputs.attention_mask,
61
+ pad_token_id=tokenizer.eos_token_id,
62
+ bos_token_id=tokenizer.bos_token_id,
63
+ eos_token_id=tokenizer.eos_token_id,
64
+ max_new_tokens=512,
65
+ do_sample=False,
66
+ use_cache=True
67
+ )
68
+
69
+ answer = tokenizer.decode(outputs[0].cpu().tolist(), skip_special_tokens=True)
70
+ print(f"{prepare_inputs['sft_format'][0]}", answer)
71
+
72
+ #INT4:
73
+ ## 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.
74
+ #BF16:
75
+ ## 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.
76
+
77
+ image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
78
+ content = "How many people are there on the baseball field in the image?"
79
+ #INT4:
80
+ #There are no people on the baseball field in the image.
81
+ #BF16:
82
+ # There are no people visible on the baseball field in the image.
83
+
84
+ image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
85
+ content = "This image represents which company?"
86
+ #INT4:
87
+ # 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!
88
+ #BF16:
89
+ # 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.
90
+ ```
91
+
92
+ ### Generate the model
93
+ Here is the sample command to reproduce the model.
94
+ ```bash
95
+ pip install auto-round
96
+ auto-round-mllm \
97
+ --model deepseek-ai/deepseek-vl2 \
98
+ --device 0 \
99
+ --group_size 128 \
100
+ --bits 4 \
101
+ --iters 1000 \
102
+ --nsample 512 \
103
+ --seqlen 2048 \
104
+ --format 'auto_round' \
105
+ --output_dir "./tmp_autoround"
106
+ ```
107
+
108
+ ## Ethical Considerations and Limitations
109
+
110
+ 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.
111
+
112
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
113
+
114
+ ## Caveats and Recommendations
115
+
116
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
117
+
118
+ Here are a couple of useful links to learn more about Intel's AI software:
119
+
120
+ - Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
121
+
122
+ ## Disclaimer
123
+
124
+ 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.
125
+
126
+ ## Cite
127
+
128
+ @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} }
129
+
130
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)