Kukedlc commited on
Commit
1078db6
1 Parent(s): fd31185

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +2 -176
README.md CHANGED
@@ -29,81 +29,13 @@ Resources and Technical Documentation:
29
  + [Phi-3 Cookbook](https://github.com/microsoft/Phi-3CookBook)
30
 
31
 
32
- | | Short Context | Long Context |
33
- | ------- | ------------- | ------------ |
34
- | Mini | 4K [[HF]](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct) ; [[ONNX]](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx) ; [[GGUF]](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-gguf) | 128K [[HF]](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct) ; [[ONNX]](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct-onnx)|
35
- | Small | 8K [[HF]](https://huggingface.co/microsoft/Phi-3-small-8k-instruct) ; [[ONNX]](https://huggingface.co/microsoft/Phi-3-small-8k-instruct-onnx-cuda) | 128K [[HF]](https://huggingface.co/microsoft/Phi-3-small-128k-instruct) ; [[ONNX]](https://huggingface.co/microsoft/Phi-3-small-128k-instruct-onnx-cuda)|
36
- | Medium | 4K [[HF]](https://huggingface.co/microsoft/Phi-3-medium-4k-instruct) ; [[ONNX]](https://huggingface.co/microsoft/Phi-3-medium-4k-instruct-onnx-cuda) | 128K [[HF]](https://huggingface.co/microsoft/Phi-3-medium-128k-instruct) ; [[ONNX]](https://huggingface.co/microsoft/Phi-3-medium-128k-instruct-onnx-cuda)|
37
- | Vision | | 128K [[HF]](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct)|
38
-
39
- ## Intended Uses
40
-
41
- **Primary use cases**
42
-
43
- The model is intended for broad commercial and research use in English. The model provides uses for general purpose AI systems and applications with visual and text input capabilities which require
44
-
45
- 1) memory/compute constrained environments;
46
- 2) latency bound scenarios;
47
- 3) general image understanding;
48
- 4) OCR;
49
- 5) chart and table understanding.
50
-
51
- Our model is designed to accelerate research on efficient language and multimodal models, for use as a building block for generative AI powered features.
52
-
53
- **Use case considerations**
54
-
55
- Our models are not specifically designed or evaluated for all downstream purposes. Developers should consider common limitations of language models as they select use cases, and evaluate and mitigate for accuracy, safety, and fairness before using within a specific downstream use case, particularly for high-risk scenarios.
56
- Developers should be aware of and adhere to applicable laws or regulations (including privacy, trade compliance laws, etc.) that are relevant to their use case.
57
-
58
- Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.
59
-
60
- ## How to Use
61
-
62
- Phi-3-vision-128K-Instruct has been integrated in the development version (4.40.2) of `transformers`. Until the official version is released through `pip`, ensure that you are doing one of the following:
63
- * When loading the model, ensure that `trust_remote_code=True` is passed as an argument of the `from_pretrained()` function.
64
-
65
- * Update your local `transformers` to the development version: `pip uninstall -y transformers && pip install git+https://github.com/huggingface/transformers`. The previous command is an alternative to cloning and installing from the source.
66
-
67
- The current `transformers` version can be verified with: `pip list | grep transformers`.
68
-
69
- Examples of required packages:
70
- ```
71
- flash_attn==2.5.8
72
- numpy==1.24.4
73
- Pillow==10.3.0
74
- Requests==2.31.0
75
- torch==2.3.0
76
- torchvision==0.18.0
77
- transformers==4.40.2
78
- ```
79
-
80
- Phi-3-Vision-128K-Instruct is also available in [Azure AI Studio](https://aka.ms/phi3-azure-ai).
81
-
82
- ### Chat Format
83
-
84
- Given the nature of the training data, the Phi-3-Vision-128K-Instruct model is best suited for a single image input wih prompts using the chat format as follows.
85
- You can provide the prompt as a single image with a generic template as follow:
86
- ```markdown
87
- <|user|>\n<|image_1|>\n{prompt}<|end|>\n<|assistant|>\n
88
- ```
89
-
90
- where the model generates the text after `<|assistant|>` . In case of multi-turn conversation, the prompt can be formatted as follows:
91
-
92
- ```markdown
93
- <|user|>\n<|image_1|>\n{prompt_1}<|end|>\n<|assistant|>\n{response_1}<|end|>\n<|user|>\n{prompt_2}<|end|>\n<|assistant|>\n
94
- ```
95
-
96
- ### Sample inference code
97
-
98
- This code snippets show how to get quickly started with running the model on a GPU:
99
-
100
  ```python
101
  from PIL import Image
102
  import requests
103
  from transformers import AutoModelForCausalLM
104
  from transformers import AutoProcessor
105
 
106
- model_id = "microsoft/Phi-3-vision-128k-instruct"
107
 
108
  model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cuda", trust_remote_code=True, torch_dtype="auto")
109
 
@@ -134,111 +66,5 @@ generate_ids = model.generate(**inputs, eos_token_id=processor.tokenizer.eos_tok
134
  generate_ids = generate_ids[:, inputs['input_ids'].shape[1]:]
135
  response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
136
 
137
- print(response)
138
- ```
139
-
140
- Additional basic examples are provided [here](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct/blob/main/sample_inference.py).
141
-
142
-
143
- ## Responsible AI Considerations
144
-
145
- Like other models, the Phi family of models can potentially behave in ways that are unfair, unreliable, or offensive. Some of the limiting behaviors to be aware of include:
146
-
147
- + Quality of Service: The Phi models are trained primarily on English text. Languages other than English will experience worse performance. English language varieties with less representation in the training data might experience worse performance than standard American English.
148
- + Representation of Harms & Perpetuation of Stereotypes: These models can over- or under-represent groups of people, erase representation of some groups, or reinforce demeaning or negative stereotypes. Despite safety post-training, these limitations may still be present due to differing levels of representation of different groups or prevalence of examples of negative stereotypes in training data that reflect real-world patterns and societal biases.
149
- + Inappropriate or Offensive Content: These models may produce other types of inappropriate or offensive content, which may make it inappropriate to deploy for sensitive contexts without additional mitigations that are specific to the use case.
150
- + Information Reliability: Language models can generate nonsensical content or fabricate content that might sound reasonable but is inaccurate or outdated.
151
- + Limited Scope for Code: Majority of Phi-3 training data is based in Python and use common packages such as "typing, math, random, collections, datetime, itertools". If the model generates Python scripts that utilize other packages or scripts in other languages, we strongly recommend users manually verify all API uses.
152
-
153
- Developers should apply responsible AI best practices and are responsible for ensuring that a specific use case complies with relevant laws and regulations (e.g. privacy, trade, etc.). Important areas for consideration include:
154
-
155
- + Allocation: Models may not be suitable for scenarios that could have consequential impact on legal status or the allocation of resources or life opportunities (ex: housing, employment, credit, etc.) without further assessments and additional debiasing techniques.
156
- + High-Risk Scenarios: Developers should assess suitability of using models in high-risk scenarios where unfair, unreliable or offensive outputs might be extremely costly or lead to harm. This includes providing advice in sensitive or expert domains where accuracy and reliability are critical (ex: legal or health advice). Additional safeguards should be implemented at the application level according to the deployment context.
157
- + Misinformation: Models may produce inaccurate information. Developers should follow transparency best practices and inform end-users they are interacting with an AI system. At the application level, developers can build feedback mechanisms and pipelines to ground responses in use-case specific, contextual information, a technique known as Retrieval Augmented Generation (RAG).
158
- + Generation of Harmful Content: Developers should assess outputs for their context and use available safety classifiers or custom solutions appropriate for their use case.
159
- + Misuse: Other forms of misuse such as fraud, spam, or malware production may be possible, and developers should ensure that their applications do not violate applicable laws and regulations.
160
- + Identification of individuals: models with vision capabilities may have the potential to uniquely identify individuals in images. Safety post-training steers the model to refuse such requests, but developers should consider and implement, as appropriate, additional mitigations or user consent flows as required in their respective jurisdiction, (e.g., building measures to blur faces in image inputs before processing.
161
-
162
- ## Training
163
-
164
- ### Model
165
-
166
- * Architecture: Phi-3-Vision-128K-Instruct has 4.2B parameters and contains image encoder, connector, projector, and Phi-3 Mini language model.
167
- * Inputs: Text and Image. It’s best suited for prompts using the chat format.
168
- * Context length: 128K tokens
169
- * GPUs: 512 H100-80G
170
- * Training time: 1.5 days
171
- * Training data: 500B vision and text tokens
172
- * Outputs: Generated text in response to the input
173
- * Dates: Our models were trained between February and April 2024
174
- * Status: This is a static model trained on an offline text dataset with cutoff date Mar 15, 2024. Future versions of the tuned models may be released as we improve models.
175
- * Release Type: Open weight release
176
- * Release dates: The model weight is released on May 21, 2024.
177
-
178
- ### Datasets
179
-
180
- Our training data includes a wide variety of sources, and is a combination of
181
-
182
- 1) publicly available documents filtered rigorously for quality, selected high-quality educational data and code;
183
- 2) selected high-quality image-text interleave;
184
- 3) newly created synthetic, “textbook-like” data for the purpose of teaching math, coding, common sense reasoning, general knowledge of the world (science, daily activities, theory of mind, etc.), newly created image data, e.g., chart/table/diagram/slides;
185
- 4) high quality chat format supervised data covering various topics to reflect human preferences on different aspects such as instruct-following, truthfulness, honesty and helpfulness.
186
-
187
- The data collection process involved sourcing information from publicly available documents, with a meticulous approach to filtering out undesirable documents and images. To safeguard privacy, we carefully filtered various image and text data sources to remove or scrub any potentially personal data from the training data.
188
-
189
- More details can be found in the [Phi-3 Technical Report](https://aka.ms/phi3-tech-report).
190
-
191
- ## Benchmarks
192
-
193
- To understand the capabilities, we compare Phi-3 Vision-128K-Instruct with a set of models over a variety of zero-shot benchmarks using our internal benchmark platform.
194
-
195
- |Benchmark|Phi-3 Vision-128K-In|LlaVA-1.6 Vicuna-7B|QWEN-VL Chat|Llama3-Llava-Next-8B|Claude-3 Haiku|Gemini 1.0 Pro V|GPT-4V-Turbo|
196
- |---------|---------------------|------------------|------------|--------------------|--------------|----------------|------------|
197
- |MMMU|40.4|34.2|39.0|36.4|40.7|42.0|55.5| 
198
- |MMBench|80.5|76.3|75.8|79.4|62.4|80.0|86.1|
199
- |ScienceQA|90.8|70.6|67.2|73.7|72.0|79.7|75.7|
200
- |MathVista|44.5|31.5|29.4|34.8|33.2|35.0|47.5|
201
- |InterGPS|38.1|20.5|22.3|24.6|32.1|28.6|41.0|
202
- |AI2D|76.7|63.1|59.8|66.9|60.3|62.8|74.7|
203
- |ChartQA|81.4|55.0|50.9|65.8|59.3|58.0|62.3|
204
- |TextVQA|70.9|64.6|59.4|55.7|62.7|64.7|68.1|
205
- |POPE|85.8|87.2|82.6|87.0|74.4|84.2|83.7|
206
-
207
-
208
- ## Software
209
-
210
- * [PyTorch](https://github.com/pytorch/pytorch)
211
- * [Transformers](https://github.com/huggingface/transformers)
212
- * [Flash-Attention](https://github.com/HazyResearch/flash-attention)
213
-
214
- ## Hardware
215
- Note that by default, the Phi-3-Vision-128K model uses flash attention, which requires certain types of GPU hardware to run. We have tested on the following GPU types:
216
- * NVIDIA A100
217
- * NVIDIA A6000
218
- * NVIDIA H100
219
-
220
- ### Running on Windows or without flash attention
221
- To enable the model on these enviroment here are steps that you may consider to follow:
222
-
223
- Step 1: comment flash attention import code in modeling_phi3_v.py from line 52 to line 56.
224
- ```python
225
- # if is_flash_attn_2_available():
226
- # from flash_attn import flash_attn_func, flash_attn_varlen_func
227
- # from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
228
-
229
- # _flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
230
- ```
231
-
232
- Step 2: change _"_attn_implementation"_ from _"flash_attention_2"_ to _"eager"_ in config.json or disable flash attention when you create the model as below.
233
-
234
- ```python
235
- model = AutoModelForCausalLM.from_pretrained('microsoft/Phi-3-vision-128k-instruct', device_map="cuda", trust_remote_code=True, torch_dtype="auto", _attn_implementation="eager")
236
  ```
237
-
238
- ## License
239
-
240
- The model is licensed under the [MIT license](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct/resolve/main/LICENSE).
241
-
242
- ## Trademarks
243
-
244
- This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft’s Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.
 
29
  + [Phi-3 Cookbook](https://github.com/microsoft/Phi-3CookBook)
30
 
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  ```python
33
  from PIL import Image
34
  import requests
35
  from transformers import AutoModelForCausalLM
36
  from transformers import AutoProcessor
37
 
38
+ model_id = "Kukedlc/Phi-3-Vision-Win-snap"
39
 
40
  model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cuda", trust_remote_code=True, torch_dtype="auto")
41
 
 
66
  generate_ids = generate_ids[:, inputs['input_ids'].shape[1]:]
67
  response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
68
 
69
+ print(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  ```