lokinfey commited on
Commit
f659e63
·
verified ·
1 Parent(s): 4fd3615

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +82 -3
README.md CHANGED
@@ -1,3 +1,82 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ # **Phi-3.5 Vision OpenVINO INT4 Model**
6
+
7
+ This is the OpenVINO format INT 4 quantized version of the Microsoft Phi-3.5 VISIOn. You can use run this script to convert
8
+
9
+ ```python
10
+
11
+ import requests
12
+ from pathlib import Path
13
+
14
+ if not Path("ov_phi3_vision.py").exists():
15
+ r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/phi-3-vision/ov_phi3_vision.py")
16
+ open("ov_phi3_vision.py", "w").write(r.text)
17
+
18
+
19
+ if not Path("gradio_helper.py").exists():
20
+ r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/phi-3-vision/gradio_helper.py")
21
+ open("gradio_helper.py", "w").write(r.text)
22
+
23
+ if not Path("notebook_utils.py").exists():
24
+ r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py")
25
+ open("notebook_utils.py", "w").write(r.text)
26
+
27
+ from ov_phi3_vision import convert_phi3_model
28
+
29
+ from pathlib import Path
30
+ import nncf
31
+
32
+
33
+ model_id = "microsoft/Phi-3.5-vision-instruct"
34
+ out_dir = Path("Save Your Phi-3.5-vision OpenVINO INT4 PATH")
35
+ compression_configuration = {
36
+ "mode": nncf.CompressWeightsMode.INT4_SYM,
37
+ "group_size": 64,
38
+ "ratio": 0.6,
39
+ }
40
+
41
+ convert_phi3_model(model_id, out_dir, compression_configuration)
42
+
43
+ ```
44
+
45
+ ## **Sample Code**
46
+
47
+
48
+ ```python
49
+
50
+ from ov_phi3_vision import OvPhi3Vision
51
+
52
+ from notebook_utils import device_widget
53
+
54
+ device = device_widget(default="GPU", exclude=["NPU"])
55
+
56
+ out_dir = Path("Your Phi-3.5-vision OpenVINO INT4 PATH")
57
+
58
+ model = OvPhi3Vision(out_dir, device.value)
59
+
60
+ import requests
61
+ from PIL import Image
62
+
63
+ image = Image.open(r"Your local image Path")
64
+
65
+ from transformers import AutoProcessor, TextStreamer
66
+
67
+ messages = [
68
+ {"role": "user", "content": "<|image_1|>\nPlease analyze the image"},
69
+ ]
70
+
71
+ processor = AutoProcessor.from_pretrained(out_dir, trust_remote_code=True)
72
+
73
+ prompt = processor.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
74
+
75
+ inputs = processor(prompt, [image], return_tensors="pt")
76
+
77
+ generation_args = {"max_new_tokens": 500, "do_sample": False, "streamer": TextStreamer(processor.tokenizer, skip_prompt=True, skip_special_tokens=True)}
78
+
79
+ print("Analyze:")
80
+ generate_ids = model.generate(**inputs, eos_token_id=processor.tokenizer.eos_token_id, **generation_args)
81
+
82
+ ```