xqiuvu
commited on
Commit
•
132d44a
1
Parent(s):
414c0cb
Initial Commit
Browse files- CODE_OF_CONDUCT.md +9 -0
- LICENSE +21 -0
- README.md +289 -3
- SECURITY.md +41 -0
- SUPPORT.md +25 -0
- config.json +151 -0
- configuration_phi3_v.py +218 -0
- generation_config.json +7 -0
- model-00001-of-00002.safetensors +3 -0
- model-00002-of-00002.safetensors +3 -0
- model.safetensors.index.json +599 -0
- modeling_phi3_v.py +1942 -0
- preprocessor_config.json +21 -0
- processing_phi3_v.py +478 -0
- processor_config.json +6 -0
- special_tokens_map.json +36 -0
- tokenizer.json +0 -0
- tokenizer_config.json +412 -0
CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Microsoft Open Source Code of Conduct
|
2 |
+
|
3 |
+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
4 |
+
|
5 |
+
Resources:
|
6 |
+
|
7 |
+
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
|
8 |
+
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
9 |
+
- Contact [[email protected]](mailto:[email protected]) with questions or concerns
|
LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) Microsoft Corporation.
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE
|
README.md
CHANGED
@@ -1,3 +1,289 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
license_link: https://huggingface.co/microsoft/Phi-3.5-vision-instruct/resolve/main/LICENSE
|
4 |
+
language:
|
5 |
+
- multilingual
|
6 |
+
pipeline_tag: image-text-to-text
|
7 |
+
tags:
|
8 |
+
- nlp
|
9 |
+
- code
|
10 |
+
- vision
|
11 |
+
inference:
|
12 |
+
parameters:
|
13 |
+
temperature: 0.7
|
14 |
+
widget:
|
15 |
+
- messages:
|
16 |
+
- role: user
|
17 |
+
content: <|image_1|>Can you describe what you see in the image?
|
18 |
+
library_name: transformers
|
19 |
+
---
|
20 |
+
## Model Summary
|
21 |
+
|
22 |
+
Phi-3.5-vision is a lightweight, state-of-the-art open multimodal model built upon datasets which include - synthetic data and filtered publicly available websites - with a focus on very high-quality, reasoning dense data both on text and vision. The model belongs to the Phi-3 model family, and the multimodal version comes with 128K context length (in tokens) it can support. The model underwent a rigorous enhancement process, incorporating both supervised fine-tuning and direct preference optimization to ensure precise instruction adherence and robust safety measures.
|
23 |
+
|
24 |
+
🏡 [Phi-3 Portal](https://azure.microsoft.com/en-us/products/phi-3) <br>
|
25 |
+
📰 [Phi-3 Microsoft Blog](https://aka.ms/phi3.5-techblog) <br>
|
26 |
+
📖 [Phi-3 Technical Report](https://arxiv.org/abs/2404.14219) <br>
|
27 |
+
👩🍳 [Phi-3 Cookbook](https://github.com/microsoft/Phi-3CookBook) <br>
|
28 |
+
🖥️ [Try It](https://aka.ms/try-phi3.5vision) <br>
|
29 |
+
|
30 |
+
**Phi-3.5**: [[mini-instruct]](https://huggingface.co/microsoft/Phi-3.5-mini-instruct); [[MoE-instruct]](https://huggingface.co/microsoft/Phi-3.5-MoE-instruct) ; [[vision-instruct]](https://huggingface.co/microsoft/Phi-3.5-vision-instruct)
|
31 |
+
|
32 |
+
## Intended Uses
|
33 |
+
|
34 |
+
### Primary Use Cases
|
35 |
+
|
36 |
+
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:
|
37 |
+
|
38 |
+
1) Memory/compute constrained environments
|
39 |
+
2) Latency bound scenarios
|
40 |
+
3) General image understanding
|
41 |
+
4) Optical character recognition
|
42 |
+
5) Chart and table understanding
|
43 |
+
6) Multiple image comparison
|
44 |
+
7) Multi-image or video clip summarization
|
45 |
+
|
46 |
+
Our model is designed to accelerate research on language and multimodal models, for use as a building block for generative AI powered features.
|
47 |
+
|
48 |
+
### Use Case Considerations
|
49 |
+
|
50 |
+
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 fariness before using within a specific downstream use case, particularly for high risk scenarios. 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.
|
51 |
+
|
52 |
+
***Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.***
|
53 |
+
|
54 |
+
## Release Notes
|
55 |
+
|
56 |
+
In this release, the model enables multi-frame image understanding and reasoning which is based on valuable customer feedback. The hero example multi-frame capabilities include detailed image comparison, multi-image summarization/storytelling and video summarization, which have broad applications in Office scenarios. We also observed performance improvement on most single image benchmarks, e.g., boost MMMU performance from 40.2 to 43.0, MMBench performance from 80.5 to 81.9, document understanding benchmark TextVQA from 70.9 to 72.0. We believe most use cases will benefit from this release, but we encourage users to test the new model in their AI applications. We appreciate the enthusiastic adoption of the Phi-3 model family and continue to welcome all the feedback from the community.
|
57 |
+
|
58 |
+
Below are the comparison results on existing multi-image benchmarks. On average, our model outperforms competitor models on the same size and competitive with much bigger models on multi-frame capabilities and video summarization.
|
59 |
+
|
60 |
+
**BLINK**: a benchmark with 14 visual tasks that humans can solve very quickly but are still hard for current multimodal LLMs.
|
61 |
+
|
62 |
+
| Benchmark | Phi-3.5-vision-instruct | LlaVA-Interleave-Qwen-7B | InternVL-2-4B | InternVL-2-8B | Gemini-1.5-Flash | GPT-4o-mini | Claude-3.5-Sonnet | Gemini-1.5-Pro | GPT-4o |
|
63 |
+
|--|--|--|--|--|--|--|--|--|--|
|
64 |
+
| Art Style | 87.2 | 62.4 | 55.6 | 52.1 | 64.1 | 70.1 | 59.8 | 70.9 | 73.3 |
|
65 |
+
| Counting | 54.2 | 56.7 | 54.2 | 66.7 | 51.7 | 55.0 | 59.2 | 65.0 | 65.0 |
|
66 |
+
| Forensic Detection | 92.4 | 31.1 | 40.9 | 34.1 | 54.5 | 38.6 | 67.4 | 60.6 | 75.8 |
|
67 |
+
| Functional Correspondence | 29.2 | 34.6 | 24.6 | 24.6 | 33.1 | 26.9 | 33.8 | 31.5 | 43.8 |
|
68 |
+
| IQ Test | 25.3 | 26.7 | 26.0 | 30.7 | 25.3 | 29.3 | 26.0 | 34.0 | 19.3 |
|
69 |
+
| Jigsaw | 68.0 | 86.0 | 55.3 | 52.7 | 71.3 | 72.7 | 57.3 | 68.0 | 67.3 |
|
70 |
+
| Multi-View Reasoning | 54.1 | 44.4 | 48.9 | 42.9 | 48.9 | 48.1 | 55.6 | 49.6 | 46.6 |
|
71 |
+
| Object Localization | 49.2 | 54.9 | 53.3 | 54.1 | 44.3 | 57.4 | 62.3 | 65.6 | 68.0 |
|
72 |
+
| Relative Depth | 69.4 | 77.4 | 63.7 | 67.7 | 57.3 | 58.1 | 71.8 | 76.6 | 71.0 |
|
73 |
+
| Relative Reflectance | 37.3 | 34.3 | 32.8 | 38.8 | 32.8 | 27.6 | 36.6 | 38.8 | 40.3 |
|
74 |
+
| Semantic Correspondence | 36.7 | 31.7 | 31.7 | 22.3 | 32.4 | 31.7 | 45.3 | 48.9 | 54.0 |
|
75 |
+
| Spatial Relation | 65.7 | 75.5 | 78.3 | 78.3 | 55.9 | 81.1 | 60.1 | 79.0 | 84.6 |
|
76 |
+
| Visual Correspondence | 53.5 | 40.7 | 34.9 | 33.1 | 29.7 | 52.9 | 72.1 | 81.4 | 86.0 |
|
77 |
+
| Visual Similarity | 83.0 | 91.9 | 48.1 | 45.2 | 47.4 | 77.8 | 84.4 | 81.5 | 88.1 |
|
78 |
+
| **Overall** | **57.0** | **53.1** | **45.9** | **45.4** | **45.8** | **51.9** | **56.5** | **61.0** | **63.2** |
|
79 |
+
|
80 |
+
**Video-MME**: comprehensively assess the capabilities of MLLMs in processing video data, covering a wide range of visual domains, temporal durations, and data modalities.
|
81 |
+
|
82 |
+
| Benchmark | Phi-3.5-vision-instruct | LlaVA-Interleave-Qwen-7B | InternVL-2-4B | InternVL-2-8B | Gemini-1.5-Flash | GPT-4o-mini | Claude-3.5-Sonnet | Gemini-1.5-Pro | GPT-4o |
|
83 |
+
|--|--|--|--|--|--|--|--|--|--|
|
84 |
+
| short (<2min) | 60.8 | 62.3 | 60.7 | 61.7 | 72.2 | 70.1 | 66.3 | 73.3 | 77.7 |
|
85 |
+
| medium (4-15min) | 47.7 | 47.1 | 46.4 | 49.6 | 62.7 | 59.6 | 54.7 | 61.2 | 68.0 |
|
86 |
+
| long (30-60min) | 43.8 | 41.2 | 42.6 | 46.6 | 52.1 | 53.9 | 46.6 | 53.2 | 59.6 |
|
87 |
+
| **Overall** | **50.8** | **50.2** | **49.9** | **52.6** | **62.3** | **61.2** | **55.9** | **62.6** | **68.4** |
|
88 |
+
|
89 |
+
## Usage
|
90 |
+
|
91 |
+
### Requirements
|
92 |
+
|
93 |
+
The current `transformers` version can be verified with: `pip list | grep transformers`.
|
94 |
+
|
95 |
+
Examples of required packages:
|
96 |
+
```
|
97 |
+
flash_attn==2.5.8
|
98 |
+
numpy==1.24.4
|
99 |
+
Pillow==10.3.0
|
100 |
+
Requests==2.31.0
|
101 |
+
torch==2.3.0
|
102 |
+
torchvision==0.18.0
|
103 |
+
transformers==4.43.0
|
104 |
+
accelerate==0.30.0
|
105 |
+
```
|
106 |
+
|
107 |
+
Phi-3.5-vision-Instruct is also available in [Azure AI Studio](https://aka.ms/try-phi3.5vision).
|
108 |
+
|
109 |
+
### Input Formats
|
110 |
+
Given the nature of the training data, the Phi-3.5-vision model is best suited for prompts using the chat format as follows:
|
111 |
+
|
112 |
+
Single image:
|
113 |
+
```
|
114 |
+
<|user|>\n<|image_1|>\n{prompt}<|end|>\n<|assistant|>\n
|
115 |
+
```
|
116 |
+
|
117 |
+
Multi-turn conversations:
|
118 |
+
```
|
119 |
+
<|user|>\n<|image_1|>\n{prompt_1}<|end|>\n<|assistant|>\n{response_1}<|end|>\n<|user|>\n{prompt_2}<|end|>\n<|assistant|>\n
|
120 |
+
```
|
121 |
+
|
122 |
+
For multi-image usage, add multiple image placeholders in the front of the prompts. <|image_{}|> index should start from 1. One example of prompt is shown as follows:
|
123 |
+
```
|
124 |
+
<|user|>\n<|image_1|>\n<|image_2|>\n<|image_3|>\n<|image_4|>\n{prompt}<|end|>\n<|assistant|>\n
|
125 |
+
```
|
126 |
+
|
127 |
+
### Loading the model locally
|
128 |
+
After obtaining the Phi-3.5-vision-instruct model checkpoints, users can use this sample code for inference.
|
129 |
+
|
130 |
+
```python
|
131 |
+
from PIL import Image
|
132 |
+
import requests
|
133 |
+
from transformers import AutoModelForCausalLM
|
134 |
+
from transformers import AutoProcessor
|
135 |
+
|
136 |
+
model_id = "microsoft/Phi-3.5-vision-instruct"
|
137 |
+
|
138 |
+
# Note: set _attn_implementation='eager' if you don't have flash_attn installed
|
139 |
+
model = AutoModelForCausalLM.from_pretrained(
|
140 |
+
model_id,
|
141 |
+
device_map="cuda",
|
142 |
+
trust_remote_code=True,
|
143 |
+
torch_dtype="auto",
|
144 |
+
_attn_implementation='flash_attention_2'
|
145 |
+
)
|
146 |
+
|
147 |
+
# for best performance, use num_crops=4 for multi-frame, num_crops=16 for single-frame.
|
148 |
+
processor = AutoProcessor.from_pretrained(model_id,
|
149 |
+
trust_remote_code=True,
|
150 |
+
num_crops=4
|
151 |
+
)
|
152 |
+
|
153 |
+
images = []
|
154 |
+
placeholder = ""
|
155 |
+
|
156 |
+
# Note: if OOM, you might consider reduce number of frames in this example.
|
157 |
+
for i in range(1,20):
|
158 |
+
url = f"https://image.slidesharecdn.com/azureintroduction-191206101932/75/Introduction-to-Microsoft-Azure-Cloud-{i}-2048.jpg"
|
159 |
+
images.append(Image.open(requests.get(url, stream=True).raw))
|
160 |
+
placeholder += f"<|image_{i}|>\n"
|
161 |
+
|
162 |
+
messages = [
|
163 |
+
{"role": "user", "content": placeholder+"Summarize the deck of slides."},
|
164 |
+
]
|
165 |
+
|
166 |
+
prompt = processor.tokenizer.apply_chat_template(
|
167 |
+
messages,
|
168 |
+
tokenize=False,
|
169 |
+
add_generation_prompt=True
|
170 |
+
)
|
171 |
+
|
172 |
+
inputs = processor(prompt, images, return_tensors="pt").to("cuda:0")
|
173 |
+
|
174 |
+
generation_args = {
|
175 |
+
"max_new_tokens": 1000,
|
176 |
+
"temperature": 0.0,
|
177 |
+
"do_sample": False,
|
178 |
+
}
|
179 |
+
|
180 |
+
generate_ids = model.generate(**inputs,
|
181 |
+
eos_token_id=processor.tokenizer.eos_token_id,
|
182 |
+
**generation_args
|
183 |
+
)
|
184 |
+
|
185 |
+
# remove input tokens
|
186 |
+
generate_ids = generate_ids[:, inputs['input_ids'].shape[1]:]
|
187 |
+
response = processor.batch_decode(generate_ids,
|
188 |
+
skip_special_tokens=True,
|
189 |
+
clean_up_tokenization_spaces=False)[0]
|
190 |
+
|
191 |
+
print(response)
|
192 |
+
```
|
193 |
+
|
194 |
+
Notes:
|
195 |
+
+ to achieve best performances we suggest to set _num_crops=4_ for multi-frame and _num_crops=16_ for single-frame.
|
196 |
+
+ to turn off flash_attention users can set __attn_implementation='eager'_
|
197 |
+
|
198 |
+
## Responsible AI Considerations
|
199 |
+
|
200 |
+
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:
|
201 |
+
* 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.
|
202 |
+
* 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.
|
203 |
+
* 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.
|
204 |
+
* Information Reliability: Language models can generate nonsensical content or fabricate content that might sound reasonable but is inaccurate or outdated.
|
205 |
+
* 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.
|
206 |
+
|
207 |
+
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:
|
208 |
+
|
209 |
+
* 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.
|
210 |
+
* 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.
|
211 |
+
* 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).
|
212 |
+
* Generation of Harmful Content: Developers should assess outputs for their context and use available safety classifiers or custom solutions appropriate for their use case.
|
213 |
+
* 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.
|
214 |
+
* 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).
|
215 |
+
|
216 |
+
## Training
|
217 |
+
|
218 |
+
### Models
|
219 |
+
|
220 |
+
**Architecture:** Phi-3.5-vision has 4.2B parameters and contains image encoder, connector, projector, and Phi-3 Mini language model.<br>
|
221 |
+
**Inputs:** Text and Image. It’s best suited for prompts using the chat format.<br>
|
222 |
+
**Context length:** 128K tokens<br>
|
223 |
+
**GPUs:** 256 A100-80G<br>
|
224 |
+
**Training time:** 6 days<br>
|
225 |
+
**Training data:** 500B tokens (vision tokens + text tokens)<br>
|
226 |
+
**Outputs:** Generated text in response to the input<br>
|
227 |
+
**Dates:** Trained between July and August 2024<br>
|
228 |
+
**Status:** This is a static model trained on an offline text dataset with cutoff date March 15, 2024. Future versions of the tuned models may be released as we improve models.<br>
|
229 |
+
**Release date:** August 2024<br>
|
230 |
+
|
231 |
+
### Data Overview
|
232 |
+
|
233 |
+
Our training data includes a wide variety of sources, and is a combination of
|
234 |
+
1) publicly available documents filtered rigorously for quality, selected high-quality educational data and code;
|
235 |
+
2) selected high-quality image-text interleave data;
|
236 |
+
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, newly created multi-image and video data, e.g., short video clips/pair of two similar images;
|
237 |
+
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.
|
238 |
+
|
239 |
+
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. More details about data can be found in the [Phi-3 Technical Report](https://arxiv.org/pdf/2404.14219).
|
240 |
+
|
241 |
+
### How to finetune?
|
242 |
+
We recommend user to take a look at the [Phi-3 CookBook finetuning recipe for Vision](https://github.com/microsoft/Phi-3CookBook/blob/main/md/04.Fine-tuning/FineTuning_Vision.md)
|
243 |
+
|
244 |
+
## Benchmarks
|
245 |
+
|
246 |
+
To understand the capabilities, we compare Phi-3.5-vision with a set of models over a variety of zero-shot benchmarks using our internal benchmark platform. At the high-level overview of the model quality on representative benchmarks:
|
247 |
+
|
248 |
+
| Category | Benchmark | Phi-3.5-vision-instruct | Intern-VL-2-4B | Intern-VL-2-8B | Gemini-1.5-Flash | GPT-4o-mini 2024-7-18 | Claude-3.5-Sonnet | Gemini-1.5-Pro | GPT-4o 2024-5-13 |
|
249 |
+
|--|--|--|--|--|--|--|--|--|--|
|
250 |
+
| Popular aggregated benchmark | MMMU (val) | 43.0 | 44.22 | 46.33 | 49.33 | 52.1 | 52.67 | 54.11 | 61.78 |
|
251 |
+
| | MMBench (dev-en) | 81.9 | 83.4 | 87.0 | 85.7 | 83.8 | 82.3 | 87.9 | 88.4 |
|
252 |
+
| Visual scientific knowledge reasoning | ScienceQA (img-test) | 91.3 | 94.9 | 95.9 | 84.5 | 84.0 | 73.8 | 86.0 | 88.5 |
|
253 |
+
| Visual math reasoning | MathVista (testmini) | 43.9 | 53.7 | 51.1 | 55.3 | 38.8 | 54.0 | 57.4 | 54.4 |
|
254 |
+
| | InterGPS (test) | 36.3 | 45.6 | 53.2 | 39.4 | 39.9 | 45.6 | 58.2 | 46.9 |
|
255 |
+
| Chart reasoning | AI2D (test) | 78.1 | 77.3 | 81.4 | 78.4 | 75.2 | 68.9 | 75.6 | 82.8 |
|
256 |
+
| | ChartQA (test) | 81.8 | 78.8 | 80.4 | 57.6 | 54.5 | 73.2 | 68.2 | 64.0 |
|
257 |
+
| Document Intelligence | TextVQA (val) | 72.0 | 66.2 | 68.8 | 67.4 | 70.9 | 70.5 | 64.5 | 75.6 |
|
258 |
+
| Object visual presence verification | POPE (test) | 86.1 | 83.3 | 84.2 | 86.1 | 83.6 | 76.6 | 89.3 | 87.0 |
|
259 |
+
|
260 |
+
## Safety Evaluation and Red-Teaming
|
261 |
+
|
262 |
+
**Approach**
|
263 |
+
The Phi-3 family of models has adopted a robust safety post-training approach. This approach leverages a variety of both open-source and in-house generated datasets.
|
264 |
+
The overall technique employed to do the safety alignment is a combination of SFT (Supervised Fine-Tuning) and RLHF (Reinforcement Learning from Human Feedback) approaches
|
265 |
+
by utilizing human-labeled and synthetic English-language datasets, including publicly available datasets focusing on helpfulness and harmlessness as well as various
|
266 |
+
questions and answers targeted to multiple safety categories.
|
267 |
+
|
268 |
+
**Safety Evaluation**
|
269 |
+
We leveraged various evaluation techniques including red teaming, adversarial conversation simulations, and safety evaluation benchmark datasets to evaluate Phi-3.5
|
270 |
+
models' propensity to produce undesirable outputs across multiple risk categories. Several approaches were used to compensate for the limitations of one approach alone.
|
271 |
+
Please refer to the [technical report](https://arxiv.org/pdf/2404.14219) for more details of our safety alignment.
|
272 |
+
|
273 |
+
|
274 |
+
## Software
|
275 |
+
* [PyTorch](https://github.com/pytorch/pytorch)
|
276 |
+
* [Transformers](https://github.com/huggingface/transformers)
|
277 |
+
* [Flash-Attention](https://github.com/HazyResearch/flash-attention)
|
278 |
+
|
279 |
+
## Hardware
|
280 |
+
Note that by default, the Phi-3.5-Mini-Instruct model uses flash attention, which requires certain types of GPU hardware to run. We have tested on the following GPU types:
|
281 |
+
* NVIDIA A100
|
282 |
+
* NVIDIA A6000
|
283 |
+
* NVIDIA H100
|
284 |
+
|
285 |
+
## License
|
286 |
+
The model is licensed under the [MIT license](./LICENSE).
|
287 |
+
|
288 |
+
## Trademarks
|
289 |
+
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.
|
SECURITY.md
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.9 BLOCK -->
|
2 |
+
|
3 |
+
## Security
|
4 |
+
|
5 |
+
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin).
|
6 |
+
|
7 |
+
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below.
|
8 |
+
|
9 |
+
## Reporting Security Issues
|
10 |
+
|
11 |
+
**Please do not report security vulnerabilities through public GitHub issues.**
|
12 |
+
|
13 |
+
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report).
|
14 |
+
|
15 |
+
If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp).
|
16 |
+
|
17 |
+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
|
18 |
+
|
19 |
+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
20 |
+
|
21 |
+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
22 |
+
* Full paths of source file(s) related to the manifestation of the issue
|
23 |
+
* The location of the affected source code (tag/branch/commit or direct URL)
|
24 |
+
* Any special configuration required to reproduce the issue
|
25 |
+
* Step-by-step instructions to reproduce the issue
|
26 |
+
* Proof-of-concept or exploit code (if possible)
|
27 |
+
* Impact of the issue, including how an attacker might exploit the issue
|
28 |
+
|
29 |
+
This information will help us triage your report more quickly.
|
30 |
+
|
31 |
+
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs.
|
32 |
+
|
33 |
+
## Preferred Languages
|
34 |
+
|
35 |
+
We prefer all communications to be in English.
|
36 |
+
|
37 |
+
## Policy
|
38 |
+
|
39 |
+
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd).
|
40 |
+
|
41 |
+
<!-- END MICROSOFT SECURITY.MD BLOCK -->
|
SUPPORT.md
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# TODO: The maintainer of this repo has not yet edited this file
|
2 |
+
|
3 |
+
**REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project?
|
4 |
+
|
5 |
+
- **No CSS support:** Fill out this template with information about how to file issues and get help.
|
6 |
+
- **Yes CSS support:** Fill out an intake form at [aka.ms/onboardsupport](https://aka.ms/onboardsupport). CSS will work with/help you to determine next steps.
|
7 |
+
- **Not sure?** Fill out an intake as though the answer were "Yes". CSS will help you decide.
|
8 |
+
|
9 |
+
*Then remove this first heading from this SUPPORT.MD file before publishing your repo.*
|
10 |
+
|
11 |
+
# Support
|
12 |
+
|
13 |
+
## How to file issues and get help
|
14 |
+
|
15 |
+
This project uses GitHub Issues to track bugs and feature requests. Please search the existing
|
16 |
+
issues before filing new issues to avoid duplicates. For new issues, file your bug or
|
17 |
+
feature request as a new Issue.
|
18 |
+
|
19 |
+
For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE
|
20 |
+
FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER
|
21 |
+
CHANNEL. WHERE WILL YOU HELP PEOPLE?**.
|
22 |
+
|
23 |
+
## Microsoft Support Policy
|
24 |
+
|
25 |
+
Support for this **PROJECT or PRODUCT** is limited to the resources listed above.
|
config.json
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "Phi-3.5-vision-instruct",
|
3 |
+
"architectures": [
|
4 |
+
"Phi3VForCausalLM"
|
5 |
+
],
|
6 |
+
"attention_dropout": 0.0,
|
7 |
+
"auto_map": {
|
8 |
+
"AutoConfig": "configuration_phi3_v.Phi3VConfig",
|
9 |
+
"AutoModelForCausalLM": "modeling_phi3_v.Phi3VForCausalLM"
|
10 |
+
},
|
11 |
+
"bos_token_id": 1,
|
12 |
+
"embd_layer": {
|
13 |
+
"embedding_cls": "image",
|
14 |
+
"hd_transform_order": "sub_glb",
|
15 |
+
"projection_cls": "mlp",
|
16 |
+
"use_hd_transform": true,
|
17 |
+
"with_learnable_separator": true
|
18 |
+
},
|
19 |
+
"embd_pdrop": 0.0,
|
20 |
+
"eos_token_id": 2,
|
21 |
+
"hidden_act": "silu",
|
22 |
+
"hidden_size": 3072,
|
23 |
+
"img_processor": {
|
24 |
+
"image_dim_out": 1024,
|
25 |
+
"model_name": "openai/clip-vit-large-patch14-336",
|
26 |
+
"name": "clip_vision_model",
|
27 |
+
"num_img_tokens": 144
|
28 |
+
},
|
29 |
+
"initializer_range": 0.02,
|
30 |
+
"intermediate_size": 8192,
|
31 |
+
"max_position_embeddings": 131072,
|
32 |
+
"model_type": "phi3_v",
|
33 |
+
"num_attention_heads": 32,
|
34 |
+
"num_hidden_layers": 32,
|
35 |
+
"num_key_value_heads": 32,
|
36 |
+
"original_max_position_embeddings": 4096,
|
37 |
+
"pad_token_id": 32000,
|
38 |
+
"resid_pdrop": 0.0,
|
39 |
+
"rms_norm_eps": 1e-05,
|
40 |
+
"rope_scaling": {
|
41 |
+
"long_factor": [
|
42 |
+
1.0800000429153442,
|
43 |
+
1.1100000143051147,
|
44 |
+
1.1399999856948853,
|
45 |
+
1.340000033378601,
|
46 |
+
1.5899999141693115,
|
47 |
+
1.600000023841858,
|
48 |
+
1.6200000047683716,
|
49 |
+
2.620000123977661,
|
50 |
+
3.2300000190734863,
|
51 |
+
3.2300000190734863,
|
52 |
+
4.789999961853027,
|
53 |
+
7.400000095367432,
|
54 |
+
7.700000286102295,
|
55 |
+
9.09000015258789,
|
56 |
+
12.199999809265137,
|
57 |
+
17.670000076293945,
|
58 |
+
24.46000099182129,
|
59 |
+
28.57000160217285,
|
60 |
+
30.420001983642578,
|
61 |
+
30.840002059936523,
|
62 |
+
32.590003967285156,
|
63 |
+
32.93000411987305,
|
64 |
+
42.320003509521484,
|
65 |
+
44.96000289916992,
|
66 |
+
50.340003967285156,
|
67 |
+
50.45000457763672,
|
68 |
+
57.55000305175781,
|
69 |
+
57.93000411987305,
|
70 |
+
58.21000289916992,
|
71 |
+
60.1400032043457,
|
72 |
+
62.61000442504883,
|
73 |
+
62.62000274658203,
|
74 |
+
62.71000289916992,
|
75 |
+
63.1400032043457,
|
76 |
+
63.1400032043457,
|
77 |
+
63.77000427246094,
|
78 |
+
63.93000411987305,
|
79 |
+
63.96000289916992,
|
80 |
+
63.970001220703125,
|
81 |
+
64.02999877929688,
|
82 |
+
64.06999969482422,
|
83 |
+
64.08000183105469,
|
84 |
+
64.12000274658203,
|
85 |
+
64.41000366210938,
|
86 |
+
64.4800033569336,
|
87 |
+
64.51000213623047,
|
88 |
+
64.52999877929688,
|
89 |
+
64.83999633789062
|
90 |
+
],
|
91 |
+
"short_factor": [
|
92 |
+
1.08,
|
93 |
+
1.1,
|
94 |
+
1.1300000000000001,
|
95 |
+
1.2800000000000002,
|
96 |
+
1.3100000000000003,
|
97 |
+
1.4500000000000004,
|
98 |
+
1.4500000000000004,
|
99 |
+
1.9500000000000008,
|
100 |
+
2.030000000000001,
|
101 |
+
2.4299999999999926,
|
102 |
+
2.5699999999999896,
|
103 |
+
2.9499999999999815,
|
104 |
+
3.729999999999965,
|
105 |
+
3.869999999999962,
|
106 |
+
4.189999999999955,
|
107 |
+
4.43999999999995,
|
108 |
+
4.6399999999999455,
|
109 |
+
4.979999999999938,
|
110 |
+
5.159999999999934,
|
111 |
+
5.279999999999932,
|
112 |
+
5.759999999999922,
|
113 |
+
5.889999999999919,
|
114 |
+
5.889999999999919,
|
115 |
+
5.969999999999917,
|
116 |
+
6.089999999999915,
|
117 |
+
6.2799999999999105,
|
118 |
+
6.7699999999999,
|
119 |
+
6.8899999999998975,
|
120 |
+
7.109999999999893,
|
121 |
+
7.129999999999892,
|
122 |
+
7.179999999999891,
|
123 |
+
7.289999999999889,
|
124 |
+
7.339999999999888,
|
125 |
+
7.559999999999883,
|
126 |
+
7.619999999999882,
|
127 |
+
7.69999999999988,
|
128 |
+
7.879999999999876,
|
129 |
+
7.879999999999876,
|
130 |
+
7.879999999999876,
|
131 |
+
7.939999999999875,
|
132 |
+
7.949999999999875,
|
133 |
+
7.979999999999874,
|
134 |
+
8.19999999999987,
|
135 |
+
8.439999999999864,
|
136 |
+
8.469999999999864,
|
137 |
+
8.589999999999861,
|
138 |
+
8.809999999999857,
|
139 |
+
8.999999999999853
|
140 |
+
],
|
141 |
+
"type": "su"
|
142 |
+
},
|
143 |
+
"rope_theta": 10000.0,
|
144 |
+
"sliding_window": 262144,
|
145 |
+
"tie_word_embeddings": false,
|
146 |
+
"torch_dtype": "bfloat16",
|
147 |
+
"transformers_version": "4.38.1",
|
148 |
+
"use_cache": true,
|
149 |
+
"vocab_size": 32064,
|
150 |
+
"_attn_implementation": "flash_attention_2"
|
151 |
+
}
|
configuration_phi3_v.py
ADDED
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 Microsoft and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
""" Phi-3-V model configuration"""
|
17 |
+
|
18 |
+
|
19 |
+
from transformers.configuration_utils import PretrainedConfig
|
20 |
+
from transformers.utils import logging
|
21 |
+
|
22 |
+
|
23 |
+
logger = logging.get_logger(__name__)
|
24 |
+
|
25 |
+
PHI3V_PRETRAINED_CONFIG_ARCHIVE_MAP = {
|
26 |
+
"microsoft/Phi-3-vision-128k-instruct": "https://huggingface.co/microsoft/Phi-3-vision-128k-instruct/resolve/main/config.json",
|
27 |
+
"microsoft/Phi-3.5-vision-instruct": "https://huggingface.co/microsoft/Phi-3.5-vision-instruct/resolve/main/config.json",
|
28 |
+
}
|
29 |
+
|
30 |
+
|
31 |
+
class Phi3VConfig(PretrainedConfig):
|
32 |
+
r"""
|
33 |
+
This is the configuration class to store the configuration of a [`Phi3VModel`]. It is used to instantiate a Phi-3
|
34 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
35 |
+
defaults will yield a similar configuration to that of the
|
36 |
+
[microsoft/Phi-3-vision-128k-instruct](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct).
|
37 |
+
|
38 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
39 |
+
documentation from [`PretrainedConfig`] for more information.
|
40 |
+
|
41 |
+
Args:
|
42 |
+
vocab_size (`int`, *optional*, defaults to 32064):
|
43 |
+
Vocabulary size of the Phi-3-V model. Defines the number of different tokens that can be represented by the
|
44 |
+
`inputs_ids` passed when calling [`Phi3VModel`].
|
45 |
+
hidden_size (`int`, *optional*, defaults to 3072):
|
46 |
+
Dimension of the hidden representations.
|
47 |
+
intermediate_size (`int`, *optional*, defaults to 8192):
|
48 |
+
Dimension of the MLP representations.
|
49 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
50 |
+
Number of hidden layers in the Transformer decoder.
|
51 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
52 |
+
Number of attention heads for each attention layer in the Transformer decoder.
|
53 |
+
num_key_value_heads (`int`, *optional*):
|
54 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
55 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
56 |
+
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
57 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
58 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
59 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
60 |
+
`num_attention_heads`.
|
61 |
+
resid_pdrop (`float`, *optional*, defaults to 0.0):
|
62 |
+
Dropout probability for mlp outputs.
|
63 |
+
embd_pdrop (`int`, *optional*, defaults to 0.0):
|
64 |
+
The dropout ratio for the embeddings.
|
65 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
66 |
+
The dropout ratio after computing the attention scores.
|
67 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
68 |
+
The non-linear activation function (function or string) in the decoder.
|
69 |
+
max_position_embeddings (`int`, *optional*, defaults to 4096):
|
70 |
+
The maximum sequence length that this model might ever be used with.
|
71 |
+
original_max_position_embeddings (`int`, *optional*, defaults to 4096):
|
72 |
+
The maximum sequence length that this model was trained with. This is used to determine the size of the
|
73 |
+
original RoPE embeddings when using long scaling.
|
74 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
75 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
76 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-05):
|
77 |
+
The epsilon value used for the RMSNorm.
|
78 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
79 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
80 |
+
relevant if `config.is_decoder=True`. Whether to tie weight embeddings or not.
|
81 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
82 |
+
Whether to tie weight embeddings
|
83 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
84 |
+
The base period of the RoPE embeddings.
|
85 |
+
rope_scaling (`dict`, *optional*):
|
86 |
+
The scaling strategy for the RoPE embeddings. If `None`, no scaling is applied. If a dictionary, it must
|
87 |
+
contain the following keys: `type`, `short_factor` and `long_factor`. The `type` must be either `su` or `yarn` and
|
88 |
+
the `short_factor` and `long_factor` must be lists of numbers with the same length as the hidden size
|
89 |
+
divided by the number of attention heads divided by 2.
|
90 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
91 |
+
The id of the "beginning-of-sequence" token.
|
92 |
+
eos_token_id (`int`, *optional*, defaults to 32000):
|
93 |
+
The id of the "end-of-sequence" token.
|
94 |
+
pad_token_id (`int`, *optional*, defaults to 32000):
|
95 |
+
The id of the padding token.
|
96 |
+
sliding_window (`int`, *optional*):
|
97 |
+
Sliding window attention window size. If `None`, no sliding window is applied.
|
98 |
+
embd_layer (`str`, *optional*, defaults to `"default"`):
|
99 |
+
The embedding layer to use. Can be either `"default"` or `"image"`. "default" uses the standard embedding for text.
|
100 |
+
|
101 |
+
Example:
|
102 |
+
|
103 |
+
```python
|
104 |
+
>>> from transformers import Phi3VModel, Phi3VConfig
|
105 |
+
|
106 |
+
>>> # Initializing a Phi-3-V style configuration
|
107 |
+
>>> configuration = Phi3Config.from_pretrained("microsoft/Phi-3-vision-128k-instruct")
|
108 |
+
|
109 |
+
>>> # Initializing a model from the configuration
|
110 |
+
>>> model = Phi3VModel(configuration)
|
111 |
+
|
112 |
+
>>> # Accessing the model configuration
|
113 |
+
>>> configuration = model.config
|
114 |
+
```"""
|
115 |
+
|
116 |
+
model_type = "phi3_v"
|
117 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
118 |
+
|
119 |
+
def __init__(
|
120 |
+
self,
|
121 |
+
vocab_size=32064,
|
122 |
+
hidden_size=3072,
|
123 |
+
intermediate_size=8192,
|
124 |
+
num_hidden_layers=32,
|
125 |
+
num_attention_heads=32,
|
126 |
+
num_key_value_heads=None,
|
127 |
+
resid_pdrop=0.0,
|
128 |
+
embd_pdrop=0.0,
|
129 |
+
attention_dropout=0.0,
|
130 |
+
hidden_act="silu",
|
131 |
+
max_position_embeddings=4096,
|
132 |
+
original_max_position_embeddings=4096,
|
133 |
+
initializer_range=0.02,
|
134 |
+
rms_norm_eps=1e-5,
|
135 |
+
use_cache=True,
|
136 |
+
tie_word_embeddings=False,
|
137 |
+
rope_theta=10000.0,
|
138 |
+
rope_scaling=None,
|
139 |
+
bos_token_id=1,
|
140 |
+
eos_token_id=32000,
|
141 |
+
pad_token_id=32000,
|
142 |
+
sliding_window=None,
|
143 |
+
embd_layer: str = "default",
|
144 |
+
**kwargs,
|
145 |
+
):
|
146 |
+
self.vocab_size = vocab_size
|
147 |
+
self.hidden_size = hidden_size
|
148 |
+
self.intermediate_size = intermediate_size
|
149 |
+
self.num_hidden_layers = num_hidden_layers
|
150 |
+
self.num_attention_heads = num_attention_heads
|
151 |
+
|
152 |
+
if num_key_value_heads is None:
|
153 |
+
num_key_value_heads = num_attention_heads
|
154 |
+
|
155 |
+
self.num_key_value_heads = num_key_value_heads
|
156 |
+
self.resid_pdrop = resid_pdrop
|
157 |
+
self.embd_pdrop = embd_pdrop
|
158 |
+
self.attention_dropout = attention_dropout
|
159 |
+
self.hidden_act = hidden_act
|
160 |
+
self.max_position_embeddings = max_position_embeddings
|
161 |
+
self.original_max_position_embeddings = original_max_position_embeddings
|
162 |
+
self.initializer_range = initializer_range
|
163 |
+
self.rms_norm_eps = rms_norm_eps
|
164 |
+
self.use_cache = use_cache
|
165 |
+
self.rope_theta = rope_theta
|
166 |
+
self.rope_scaling = rope_scaling
|
167 |
+
self._rope_scaling_validation()
|
168 |
+
self.sliding_window = sliding_window
|
169 |
+
self.embd_layer = embd_layer
|
170 |
+
|
171 |
+
|
172 |
+
super().__init__(
|
173 |
+
bos_token_id=bos_token_id,
|
174 |
+
eos_token_id=eos_token_id,
|
175 |
+
pad_token_id=pad_token_id,
|
176 |
+
tie_word_embeddings=tie_word_embeddings,
|
177 |
+
**kwargs,
|
178 |
+
)
|
179 |
+
|
180 |
+
def _rope_scaling_validation(self):
|
181 |
+
"""
|
182 |
+
Validate the `rope_scaling` configuration.
|
183 |
+
"""
|
184 |
+
if self.rope_scaling is None:
|
185 |
+
return
|
186 |
+
|
187 |
+
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 3:
|
188 |
+
raise ValueError(
|
189 |
+
"`rope_scaling` must be a dictionary with three fields, `type`, `short_factor` and `long_factor`, "
|
190 |
+
f"got {self.rope_scaling}"
|
191 |
+
)
|
192 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
193 |
+
rope_scaling_short_factor = self.rope_scaling.get("short_factor", None)
|
194 |
+
rope_scaling_long_factor = self.rope_scaling.get("long_factor", None)
|
195 |
+
if rope_scaling_type is None or rope_scaling_type not in ["su", "yarn"]:
|
196 |
+
raise ValueError(f"`rope_scaling`'s type field must be one of ['su', 'yarn'], got {rope_scaling_type}")
|
197 |
+
if not (
|
198 |
+
isinstance(rope_scaling_short_factor, list)
|
199 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_short_factor)
|
200 |
+
):
|
201 |
+
raise ValueError(
|
202 |
+
f"`rope_scaling`'s short_factor field must be a list of numbers, got {rope_scaling_short_factor}"
|
203 |
+
)
|
204 |
+
if not len(rope_scaling_short_factor) == self.hidden_size // self.num_attention_heads // 2:
|
205 |
+
raise ValueError(
|
206 |
+
f"`rope_scaling`'s short_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_short_factor)}"
|
207 |
+
)
|
208 |
+
if not (
|
209 |
+
isinstance(rope_scaling_long_factor, list)
|
210 |
+
and all(isinstance(x, (int, float)) for x in rope_scaling_long_factor)
|
211 |
+
):
|
212 |
+
raise ValueError(
|
213 |
+
f"`rope_scaling`'s long_factor field must be a list of numbers, got {rope_scaling_long_factor}"
|
214 |
+
)
|
215 |
+
if not len(rope_scaling_long_factor) == self.hidden_size // self.num_attention_heads // 2:
|
216 |
+
raise ValueError(
|
217 |
+
f"`rope_scaling`'s long_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_long_factor)}"
|
218 |
+
)
|
generation_config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 1,
|
4 |
+
"eos_token_id": 2,
|
5 |
+
"pad_token_id": 32000,
|
6 |
+
"transformers_version": "4.38.1"
|
7 |
+
}
|
model-00001-of-00002.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:be7bdee601478b3560aeb7122fe87a7d68445bb21b5f1ca88a764e8530b3aab8
|
3 |
+
size 4944122112
|
model-00002-of-00002.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:94621eca6936d7a2fb94bd90f37edb0e28850235e7ba2c5e20445d2fc56bcaed
|
3 |
+
size 3349208776
|
model.safetensors.index.json
ADDED
@@ -0,0 +1,599 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 8293242880
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"lm_head.weight": "model-00002-of-00002.safetensors",
|
7 |
+
"model.embed_tokens.weight": "model-00001-of-00002.safetensors",
|
8 |
+
"model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
9 |
+
"model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
10 |
+
"model.layers.0.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
11 |
+
"model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
12 |
+
"model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
13 |
+
"model.layers.0.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
14 |
+
"model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
15 |
+
"model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
16 |
+
"model.layers.1.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
17 |
+
"model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
18 |
+
"model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
19 |
+
"model.layers.1.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
20 |
+
"model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
21 |
+
"model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
22 |
+
"model.layers.10.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
23 |
+
"model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
24 |
+
"model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
25 |
+
"model.layers.10.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
26 |
+
"model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
27 |
+
"model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
28 |
+
"model.layers.11.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
29 |
+
"model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
30 |
+
"model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
31 |
+
"model.layers.11.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
32 |
+
"model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
33 |
+
"model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
34 |
+
"model.layers.12.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
35 |
+
"model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
36 |
+
"model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
37 |
+
"model.layers.12.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
38 |
+
"model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
39 |
+
"model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
40 |
+
"model.layers.13.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
41 |
+
"model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
42 |
+
"model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
43 |
+
"model.layers.13.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
44 |
+
"model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
45 |
+
"model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
46 |
+
"model.layers.14.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
47 |
+
"model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
48 |
+
"model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
49 |
+
"model.layers.14.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
50 |
+
"model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
51 |
+
"model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
52 |
+
"model.layers.15.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
53 |
+
"model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
54 |
+
"model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
55 |
+
"model.layers.15.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
56 |
+
"model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
57 |
+
"model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
58 |
+
"model.layers.16.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
59 |
+
"model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
60 |
+
"model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
61 |
+
"model.layers.16.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
62 |
+
"model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
63 |
+
"model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
64 |
+
"model.layers.17.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
65 |
+
"model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
66 |
+
"model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
67 |
+
"model.layers.17.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
68 |
+
"model.layers.18.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
69 |
+
"model.layers.18.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
70 |
+
"model.layers.18.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
71 |
+
"model.layers.18.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
72 |
+
"model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
73 |
+
"model.layers.18.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
74 |
+
"model.layers.19.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
75 |
+
"model.layers.19.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
76 |
+
"model.layers.19.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
77 |
+
"model.layers.19.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
78 |
+
"model.layers.19.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
79 |
+
"model.layers.19.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
80 |
+
"model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
81 |
+
"model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
82 |
+
"model.layers.2.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
83 |
+
"model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
84 |
+
"model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
85 |
+
"model.layers.2.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
86 |
+
"model.layers.20.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
87 |
+
"model.layers.20.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
88 |
+
"model.layers.20.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
89 |
+
"model.layers.20.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
90 |
+
"model.layers.20.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
91 |
+
"model.layers.20.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
92 |
+
"model.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
93 |
+
"model.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
94 |
+
"model.layers.21.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
95 |
+
"model.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
96 |
+
"model.layers.21.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
97 |
+
"model.layers.21.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
98 |
+
"model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
99 |
+
"model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
100 |
+
"model.layers.22.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
101 |
+
"model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
102 |
+
"model.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
103 |
+
"model.layers.22.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
104 |
+
"model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
105 |
+
"model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
106 |
+
"model.layers.23.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
107 |
+
"model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
108 |
+
"model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
109 |
+
"model.layers.23.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
110 |
+
"model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
111 |
+
"model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
112 |
+
"model.layers.24.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
113 |
+
"model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
114 |
+
"model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
115 |
+
"model.layers.24.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
116 |
+
"model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
117 |
+
"model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
118 |
+
"model.layers.25.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
119 |
+
"model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
120 |
+
"model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
121 |
+
"model.layers.25.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
122 |
+
"model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
123 |
+
"model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
124 |
+
"model.layers.26.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
125 |
+
"model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
126 |
+
"model.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
127 |
+
"model.layers.26.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
128 |
+
"model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
129 |
+
"model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
130 |
+
"model.layers.27.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
131 |
+
"model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
132 |
+
"model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
133 |
+
"model.layers.27.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
134 |
+
"model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
135 |
+
"model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
136 |
+
"model.layers.28.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
137 |
+
"model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
138 |
+
"model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
139 |
+
"model.layers.28.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
140 |
+
"model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
141 |
+
"model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
142 |
+
"model.layers.29.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
143 |
+
"model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
144 |
+
"model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
145 |
+
"model.layers.29.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
146 |
+
"model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
147 |
+
"model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
148 |
+
"model.layers.3.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
149 |
+
"model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
150 |
+
"model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
151 |
+
"model.layers.3.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
152 |
+
"model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
153 |
+
"model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
154 |
+
"model.layers.30.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
155 |
+
"model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
156 |
+
"model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
157 |
+
"model.layers.30.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
158 |
+
"model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
|
159 |
+
"model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
160 |
+
"model.layers.31.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
|
161 |
+
"model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
162 |
+
"model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
|
163 |
+
"model.layers.31.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
|
164 |
+
"model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
165 |
+
"model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
166 |
+
"model.layers.4.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
167 |
+
"model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
168 |
+
"model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
169 |
+
"model.layers.4.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
170 |
+
"model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
171 |
+
"model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
172 |
+
"model.layers.5.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
173 |
+
"model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
174 |
+
"model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
175 |
+
"model.layers.5.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
176 |
+
"model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
177 |
+
"model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
178 |
+
"model.layers.6.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
179 |
+
"model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
180 |
+
"model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
181 |
+
"model.layers.6.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
182 |
+
"model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
183 |
+
"model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
184 |
+
"model.layers.7.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
185 |
+
"model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
186 |
+
"model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
187 |
+
"model.layers.7.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
188 |
+
"model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
189 |
+
"model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
190 |
+
"model.layers.8.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
191 |
+
"model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
192 |
+
"model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
193 |
+
"model.layers.8.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
194 |
+
"model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
|
195 |
+
"model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
196 |
+
"model.layers.9.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
|
197 |
+
"model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
198 |
+
"model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
199 |
+
"model.layers.9.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
|
200 |
+
"model.norm.weight": "model-00002-of-00002.safetensors",
|
201 |
+
"model.vision_embed_tokens.glb_GN": "model-00001-of-00002.safetensors",
|
202 |
+
"model.vision_embed_tokens.img_processor.vision_model.embeddings.class_embedding": "model-00001-of-00002.safetensors",
|
203 |
+
"model.vision_embed_tokens.img_processor.vision_model.embeddings.patch_embedding.weight": "model-00001-of-00002.safetensors",
|
204 |
+
"model.vision_embed_tokens.img_processor.vision_model.embeddings.position_embedding.weight": "model-00001-of-00002.safetensors",
|
205 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
206 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
207 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
208 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
209 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
210 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
211 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
212 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
213 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
214 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
215 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
216 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
217 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
218 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
219 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
220 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
221 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
222 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
223 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
224 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
225 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
226 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
227 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
228 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
229 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
230 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
231 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
232 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
233 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
234 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
235 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
236 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
237 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
238 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
239 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
240 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
241 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
242 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
243 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
244 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
245 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
246 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
247 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
248 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
249 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
250 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
251 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
252 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
253 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
254 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
255 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
256 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
257 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
258 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
259 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
260 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
261 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
262 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
263 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
264 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
265 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
266 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
267 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
268 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
269 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
270 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
271 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
272 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
273 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
274 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
275 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
276 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
277 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
278 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
279 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
280 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
281 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
282 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
283 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
284 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
285 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
286 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
287 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
288 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
289 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
290 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
291 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
292 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
293 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
294 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
295 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
296 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
297 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
298 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
299 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
300 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
301 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
302 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
303 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
304 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
305 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
306 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
307 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
308 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
309 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
310 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
311 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
312 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
313 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
314 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
315 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
316 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
317 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
318 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
319 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
320 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
321 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
322 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
323 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
324 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
325 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
326 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
327 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
328 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
329 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
330 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
331 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
332 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
333 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
334 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
335 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
336 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
337 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
338 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
339 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
340 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
341 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
342 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
343 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
344 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
345 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
346 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
347 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
348 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
349 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
350 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
351 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
352 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
353 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
354 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
355 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
356 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
357 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
358 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
359 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
360 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
361 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
362 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
363 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
364 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
365 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
366 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
367 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
368 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
369 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
370 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
371 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
372 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
373 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
374 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
375 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
376 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
377 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
378 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
379 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
380 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
381 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
382 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
383 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
384 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
385 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
386 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
387 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
388 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
389 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
390 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
391 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
392 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
393 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
394 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
395 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
396 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
397 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
398 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
399 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
400 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
401 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
402 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
403 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
404 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
405 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
406 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
407 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
408 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
409 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
410 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
411 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
412 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
413 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
414 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
415 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
416 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
417 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
418 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
419 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
420 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
421 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
422 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
423 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
424 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
425 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
426 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
427 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
428 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
429 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
430 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
431 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
432 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
433 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
434 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
435 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
436 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
437 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
438 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
439 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
440 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
441 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
442 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
443 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
444 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.21.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
445 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
446 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
447 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
448 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
449 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
450 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
451 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
452 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
453 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
454 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
455 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
456 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
457 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
458 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
459 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
460 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.22.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
461 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
462 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
463 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
464 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
465 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
466 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
467 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
468 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
469 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
470 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
471 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
472 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
473 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
474 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
475 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
476 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.23.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
477 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
478 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
479 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
480 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
481 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
482 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
483 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
484 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
485 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
486 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
487 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
488 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
489 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
490 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
491 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
492 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
493 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
494 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
495 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
496 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
497 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
498 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
499 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
500 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
501 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
502 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
503 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
504 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
505 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
506 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
507 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
508 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
509 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
510 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
511 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
512 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
513 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
514 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
515 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
516 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
517 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
518 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
519 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
520 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
521 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
522 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
523 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
524 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
525 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
526 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
527 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
528 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
529 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
530 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
531 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
532 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
533 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
534 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
535 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
536 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
537 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
538 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
539 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
540 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
541 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
542 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
543 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
544 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
545 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
546 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
547 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
548 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
549 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
550 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
551 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
552 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
553 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
554 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
555 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
556 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
557 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
558 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
559 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
560 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
561 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
562 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
563 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
564 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
565 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
566 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
567 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
568 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
569 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
570 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
571 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
572 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
573 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.layer_norm1.bias": "model-00001-of-00002.safetensors",
|
574 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.layer_norm1.weight": "model-00001-of-00002.safetensors",
|
575 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.layer_norm2.bias": "model-00001-of-00002.safetensors",
|
576 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.layer_norm2.weight": "model-00001-of-00002.safetensors",
|
577 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.mlp.fc1.bias": "model-00001-of-00002.safetensors",
|
578 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.mlp.fc1.weight": "model-00001-of-00002.safetensors",
|
579 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.mlp.fc2.bias": "model-00001-of-00002.safetensors",
|
580 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.mlp.fc2.weight": "model-00001-of-00002.safetensors",
|
581 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
|
582 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
583 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.self_attn.out_proj.bias": "model-00001-of-00002.safetensors",
|
584 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.self_attn.out_proj.weight": "model-00001-of-00002.safetensors",
|
585 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
|
586 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
587 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
|
588 |
+
"model.vision_embed_tokens.img_processor.vision_model.encoder.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
589 |
+
"model.vision_embed_tokens.img_processor.vision_model.post_layernorm.bias": "model-00001-of-00002.safetensors",
|
590 |
+
"model.vision_embed_tokens.img_processor.vision_model.post_layernorm.weight": "model-00001-of-00002.safetensors",
|
591 |
+
"model.vision_embed_tokens.img_processor.vision_model.pre_layrnorm.bias": "model-00001-of-00002.safetensors",
|
592 |
+
"model.vision_embed_tokens.img_processor.vision_model.pre_layrnorm.weight": "model-00001-of-00002.safetensors",
|
593 |
+
"model.vision_embed_tokens.img_projection.0.bias": "model-00001-of-00002.safetensors",
|
594 |
+
"model.vision_embed_tokens.img_projection.0.weight": "model-00001-of-00002.safetensors",
|
595 |
+
"model.vision_embed_tokens.img_projection.2.bias": "model-00001-of-00002.safetensors",
|
596 |
+
"model.vision_embed_tokens.img_projection.2.weight": "model-00001-of-00002.safetensors",
|
597 |
+
"model.vision_embed_tokens.sub_GN": "model-00001-of-00002.safetensors"
|
598 |
+
}
|
599 |
+
}
|
modeling_phi3_v.py
ADDED
@@ -0,0 +1,1942 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 Microsoft and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
""" PyTorch Phi-3-V model."""
|
17 |
+
|
18 |
+
import inspect
|
19 |
+
import math
|
20 |
+
import warnings
|
21 |
+
from typing import List, Optional, Tuple, Union
|
22 |
+
|
23 |
+
import torch
|
24 |
+
import torch.nn.functional as F
|
25 |
+
import torch.utils.checkpoint
|
26 |
+
from torch import nn
|
27 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
28 |
+
|
29 |
+
from transformers.activations import ACT2FN
|
30 |
+
from transformers.cache_utils import Cache, DynamicCache
|
31 |
+
from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask
|
32 |
+
from transformers.modeling_outputs import (
|
33 |
+
BaseModelOutputWithPast,
|
34 |
+
CausalLMOutputWithPast,
|
35 |
+
SequenceClassifierOutputWithPast,
|
36 |
+
TokenClassifierOutput,
|
37 |
+
)
|
38 |
+
from transformers.modeling_utils import PreTrainedModel
|
39 |
+
from transformers.utils import (
|
40 |
+
add_code_sample_docstrings,
|
41 |
+
add_start_docstrings,
|
42 |
+
add_start_docstrings_to_model_forward,
|
43 |
+
is_flash_attn_greater_or_equal_2_10,
|
44 |
+
logging,
|
45 |
+
replace_return_docstrings,
|
46 |
+
)
|
47 |
+
from .configuration_phi3_v import Phi3VConfig
|
48 |
+
|
49 |
+
try:
|
50 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
51 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
52 |
+
|
53 |
+
_flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
|
54 |
+
except ImportError:
|
55 |
+
pass
|
56 |
+
|
57 |
+
import torch
|
58 |
+
from torch import nn
|
59 |
+
from transformers import CLIPVisionConfig, CLIPVisionModel, PretrainedConfig
|
60 |
+
from transformers.models.clip.modeling_clip import CLIPAttention
|
61 |
+
from transformers.utils import logging
|
62 |
+
|
63 |
+
logger = logging.get_logger(__name__)
|
64 |
+
|
65 |
+
|
66 |
+
MAX_INPUT_ID = int(1e9)
|
67 |
+
|
68 |
+
CLIP_VIT_LARGE_PATCH14_336_CONFIG = CLIPVisionConfig(
|
69 |
+
attention_dropout=0.0,
|
70 |
+
dropout=0.0,
|
71 |
+
hidden_act="quick_gelu",
|
72 |
+
hidden_size=1024,
|
73 |
+
image_size=336,
|
74 |
+
initializer_factor=1.0,
|
75 |
+
initializer_range=0.02,
|
76 |
+
intermediate_size=4096,
|
77 |
+
layer_norm_eps=1e-05,
|
78 |
+
num_attention_heads=16,
|
79 |
+
num_channels=3,
|
80 |
+
num_hidden_layers=24,
|
81 |
+
patch_size=14,
|
82 |
+
projection_dim=768
|
83 |
+
)
|
84 |
+
|
85 |
+
class CLIPAttentionFA2(CLIPAttention):
|
86 |
+
"""Add flash attention 2 to CLIPAttention. (This is only used in the vision encoder)"""
|
87 |
+
|
88 |
+
def forward(self,
|
89 |
+
hidden_states,
|
90 |
+
attention_mask=None,
|
91 |
+
causal_attention_mask=None,
|
92 |
+
output_attentions=False,
|
93 |
+
):
|
94 |
+
"""Input shape: Batch x Time x Channel"""
|
95 |
+
|
96 |
+
assert attention_mask is None, "CLIPAttentionFA2 does not support attention_mask"
|
97 |
+
assert causal_attention_mask is None, "CLIPAttentionFA2 does not support causal_attention_mask"
|
98 |
+
assert output_attentions is False, "CLIPAttentionFA2 does not support output_attentions"
|
99 |
+
|
100 |
+
bsz, tgt_len, embed_dim = hidden_states.size()
|
101 |
+
query_states = self.q_proj(hidden_states).reshape(bsz, tgt_len, self.num_heads, self.head_dim)
|
102 |
+
key_states = self.k_proj(hidden_states).reshape(bsz, tgt_len, self.num_heads, self.head_dim)
|
103 |
+
value_states = self.v_proj(hidden_states).reshape(bsz, tgt_len, self.num_heads, self.head_dim)
|
104 |
+
|
105 |
+
attn_output = flash_attn_func(
|
106 |
+
query_states,
|
107 |
+
key_states,
|
108 |
+
value_states,
|
109 |
+
dropout_p=self.dropout if self.training else 0.0,
|
110 |
+
softmax_scale=self.scale,
|
111 |
+
causal=False,
|
112 |
+
).reshape(bsz, tgt_len, embed_dim)
|
113 |
+
|
114 |
+
attn_output = self.out_proj(attn_output)
|
115 |
+
return attn_output, None
|
116 |
+
|
117 |
+
|
118 |
+
class Phi3ImageEmbedding(nn.Module):
|
119 |
+
"""Phi3 Image embedding."""
|
120 |
+
|
121 |
+
def __init__(self, config: PretrainedConfig, wte=None, **kwargs) -> None:
|
122 |
+
super().__init__()
|
123 |
+
|
124 |
+
# n_embed or hidden_size
|
125 |
+
hidden_size = config.n_embd if hasattr(config, 'n_embd') else config.hidden_size
|
126 |
+
if hasattr(config, 'embd_pdrop') or hasattr(config, 'embed_pdrop'):
|
127 |
+
embd_drop = config.embd_pdrop if hasattr(config, 'embd_pdrop') else config.embed_pdrop
|
128 |
+
self.drop = nn.Dropout(embd_drop)
|
129 |
+
else:
|
130 |
+
self.drop = None
|
131 |
+
|
132 |
+
self.wte = wte
|
133 |
+
|
134 |
+
if isinstance(config.img_processor, dict) and config.img_processor.get('name', None) == 'clip_vision_model':
|
135 |
+
assert 'model_name' in config.img_processor, 'model_name must be provided for CLIPVisionModel'
|
136 |
+
assert 'image_dim_out' in config.img_processor, 'image_dim_out must be provided for CLIPVisionModel'
|
137 |
+
assert 'num_img_tokens' in config.img_processor, 'num_img_tokens must be provided for CLIPVisionModel'
|
138 |
+
assert config.img_processor['model_name'] == 'openai/clip-vit-large-patch14-336'
|
139 |
+
clip_config = CLIP_VIT_LARGE_PATCH14_336_CONFIG
|
140 |
+
self.img_processor = CLIPVisionModel(clip_config)
|
141 |
+
image_dim_out = config.img_processor['image_dim_out']
|
142 |
+
self.num_img_tokens = config.img_processor['num_img_tokens']
|
143 |
+
|
144 |
+
# FA2 in CLIP
|
145 |
+
if config._attn_implementation == 'flash_attention_2':
|
146 |
+
for layer in self.img_processor.vision_model.encoder.layers:
|
147 |
+
clip_fa2 = CLIPAttentionFA2(clip_config)
|
148 |
+
del layer.self_attn
|
149 |
+
layer.self_attn = clip_fa2
|
150 |
+
else:
|
151 |
+
raise NotImplementedError(f'img_processor = {config.img_processor}, not implemented')
|
152 |
+
|
153 |
+
self.image_dim_out = image_dim_out
|
154 |
+
self.img_sizes = None
|
155 |
+
|
156 |
+
# global_gn and sub_gn for hd transform, serves as line separator
|
157 |
+
self.use_hd_transform = kwargs.get('use_hd_transform', False)
|
158 |
+
self.with_learnable_separator = kwargs.get('with_learnable_separator', False)
|
159 |
+
self.hd_transform_order = kwargs.get('hd_transform_order', 'glb_sub')
|
160 |
+
# with_hd_transform and with_learnable_separator should have same value
|
161 |
+
assert self.use_hd_transform == self.with_learnable_separator, 'use_hd_transform and with_learnable_separator should have same value'
|
162 |
+
if self.with_learnable_separator:
|
163 |
+
assert self.use_hd_transform, 'learnable separator is only for hd transform'
|
164 |
+
# 1024 * 4, merge spatial to channel dimension
|
165 |
+
self.glb_GN = nn.Parameter(torch.zeros([1, 1, self.image_dim_out * 4]))
|
166 |
+
self.sub_GN = nn.Parameter(torch.zeros([1, 1, 1, self.image_dim_out * 4]))
|
167 |
+
logger.info(f'learnable separator enabled for hd transform, hd_transform_order = {self.hd_transform_order}')
|
168 |
+
|
169 |
+
projection_cls = kwargs.get('projection_cls', 'linear')
|
170 |
+
if projection_cls == 'linear':
|
171 |
+
self.img_projection = nn.Linear(image_dim_out, hidden_size)
|
172 |
+
elif projection_cls == 'mlp' and self.use_hd_transform:
|
173 |
+
dim_projection = hidden_size
|
174 |
+
depth = 2
|
175 |
+
layers = [nn.Linear(image_dim_out * 4, dim_projection)]
|
176 |
+
for _ in range(1, depth):
|
177 |
+
layers.extend([nn.GELU(),
|
178 |
+
nn.Linear(dim_projection, dim_projection)])
|
179 |
+
self.img_projection = nn.Sequential(*layers)
|
180 |
+
elif projection_cls == 'mlp':
|
181 |
+
dim_projection = hidden_size
|
182 |
+
depth = 2
|
183 |
+
layers = [nn.Linear(image_dim_out, dim_projection)]
|
184 |
+
for _ in range(1, depth):
|
185 |
+
layers.extend([nn.GELU(),
|
186 |
+
nn.Linear(dim_projection, dim_projection)])
|
187 |
+
self.img_projection = nn.Sequential(*layers)
|
188 |
+
else:
|
189 |
+
raise NotImplementedError(f'projection_cls = {projection_cls}, not implemented')
|
190 |
+
|
191 |
+
self.vocab_size = config.vocab_size
|
192 |
+
self.img_features = None
|
193 |
+
|
194 |
+
if isinstance(config.img_processor, dict):
|
195 |
+
self.layer_idx = config.img_processor.get('layer_idx', -2)
|
196 |
+
self.type_feature = config.img_processor.get('type_feature', 'patch')
|
197 |
+
else:
|
198 |
+
self.layer_idx = -2
|
199 |
+
self.type_feature = 'patch'
|
200 |
+
|
201 |
+
|
202 |
+
def set_img_features(self, img_features: torch.FloatTensor) -> None:
|
203 |
+
self.img_features = img_features
|
204 |
+
|
205 |
+
def set_img_sizes(self, img_sizes: torch.LongTensor) -> None:
|
206 |
+
self.img_sizes = img_sizes
|
207 |
+
|
208 |
+
def get_img_features(self, img_embeds: torch.FloatTensor) -> torch.FloatTensor:
|
209 |
+
LAYER_IDX = self.layer_idx
|
210 |
+
TYPE_FEATURE = self.type_feature
|
211 |
+
|
212 |
+
img_processor_output = self.img_processor(img_embeds, output_hidden_states=True)
|
213 |
+
img_feature = img_processor_output.hidden_states[LAYER_IDX]
|
214 |
+
|
215 |
+
if TYPE_FEATURE == "patch":
|
216 |
+
patch_feature = img_feature[:, 1:]
|
217 |
+
return patch_feature
|
218 |
+
|
219 |
+
raise NotImplementedError
|
220 |
+
|
221 |
+
def forward(
|
222 |
+
self, input_ids: torch.LongTensor, pixel_values: torch.FloatTensor, image_sizes=None
|
223 |
+
) -> torch.FloatTensor:
|
224 |
+
input_shape = input_ids.size()
|
225 |
+
input_ids = input_ids.view(-1, input_shape[-1])
|
226 |
+
|
227 |
+
# positions for image tokens
|
228 |
+
positions = torch.nonzero((input_ids < 0) & (input_ids > -MAX_INPUT_ID), as_tuple=True)
|
229 |
+
has_image = len(positions[0].tolist()) > 0
|
230 |
+
input_ids = input_ids.clamp_min(0).clamp_max(self.vocab_size).detach()
|
231 |
+
hidden_states = self.wte(input_ids)
|
232 |
+
|
233 |
+
if has_image:
|
234 |
+
assert self.use_hd_transform
|
235 |
+
num_images, num_crops, c, h, w = pixel_values.shape
|
236 |
+
assert c == 3 and h == w == 336
|
237 |
+
img_features = self.get_img_features(pixel_values.flatten(0, 1)).reshape(
|
238 |
+
num_images, num_crops, -1, self.image_dim_out
|
239 |
+
)
|
240 |
+
image_features_proj = self.hd_feature_transform(img_features, image_sizes)
|
241 |
+
hidden_states = hidden_states.index_put(
|
242 |
+
positions, image_features_proj, accumulate=False
|
243 |
+
)
|
244 |
+
|
245 |
+
if self.drop is not None:
|
246 |
+
hidden_states = self.drop(hidden_states)
|
247 |
+
|
248 |
+
return hidden_states
|
249 |
+
|
250 |
+
def hd_feature_transform(self, image_features, image_sizes):
|
251 |
+
"""
|
252 |
+
image_features: (num_images, num_crops+1, 24*24, 1024)
|
253 |
+
"""
|
254 |
+
assert (
|
255 |
+
self.hd_transform_order == 'sub_glb'
|
256 |
+
), f'hd_transform_order `{self.hd_transform_order}` not implemented'
|
257 |
+
if isinstance(self.img_projection, nn.Sequential):
|
258 |
+
target_device = self.img_projection[0].bias.device
|
259 |
+
target_dtype = self.img_projection[0].bias.dtype
|
260 |
+
else: # It's a single nn.Linear layer
|
261 |
+
target_device = self.img_projection.bias.device
|
262 |
+
target_dtype = self.img_projection.bias.dtype
|
263 |
+
|
264 |
+
global_image_features = image_features[:, 0] # (num_images, 24*24, 1024)
|
265 |
+
# global feature can be viewed as a special HD case with num_crops 1x1
|
266 |
+
global_image_features_hd = self.reshape_hd_patches_2x2merge(global_image_features, 1, 1)
|
267 |
+
global_image_features_hd_newline = self.add_image_newline(global_image_features_hd)
|
268 |
+
|
269 |
+
all_image_embeddings = []
|
270 |
+
# need a for loop to process each image because of different image sizes
|
271 |
+
# (patch arrangement is different for each image)
|
272 |
+
for i, img_size in enumerate(image_sizes):
|
273 |
+
h, w = img_size
|
274 |
+
h_crop = h // 336
|
275 |
+
w_crop = w // 336
|
276 |
+
num_crops = h_crop * w_crop
|
277 |
+
|
278 |
+
# NOTE: real num_crops is padded
|
279 |
+
# (num_crops, 24*24, 1024)
|
280 |
+
sub_image_features = image_features[i, 1 : 1 + num_crops]
|
281 |
+
sub_image_features_hd = self.reshape_hd_patches_2x2merge(
|
282 |
+
sub_image_features, h_crop, w_crop
|
283 |
+
)
|
284 |
+
sub_image_features_hd_newline = self.add_image_newline(sub_image_features_hd)
|
285 |
+
|
286 |
+
# [sub features, separator, global features]
|
287 |
+
all_image_embeddings.extend(
|
288 |
+
[
|
289 |
+
sub_image_features_hd_newline.squeeze(0), # (h_crop*12*(w_crop*12+1), 4096)
|
290 |
+
self.glb_GN.squeeze(0),
|
291 |
+
global_image_features_hd_newline[i],
|
292 |
+
]
|
293 |
+
)
|
294 |
+
|
295 |
+
image_features_proj = self.img_projection(
|
296 |
+
torch.cat(all_image_embeddings, dim=0).to(target_device).to(target_dtype)
|
297 |
+
)
|
298 |
+
|
299 |
+
return image_features_proj
|
300 |
+
|
301 |
+
def reshape_hd_patches_2x2merge(self, image_features, h_crop, w_crop):
|
302 |
+
"""
|
303 |
+
image_features: (num_images*num_crops, 24*24, 1024)
|
304 |
+
output: (num_images, h_crop*12, w_crop*12, 4096), h_crop*w_crop == num_crops
|
305 |
+
"""
|
306 |
+
N, L, C = image_features.shape
|
307 |
+
assert L == 24 * 24 and C == 1024 and N % (h_crop * w_crop) == 0
|
308 |
+
num_images = N // (h_crop * w_crop)
|
309 |
+
H = int(L**0.5)
|
310 |
+
image_features_hd = (
|
311 |
+
image_features.reshape(N, H, H, C) # N, 24, 24, 1024
|
312 |
+
.reshape(N, H // 2, 2, H // 2, 2, C) # N, 12, 2, 12, 2, 1024
|
313 |
+
.permute(0, 1, 3, 2, 4, 5) # N, 12, 12, 2, 2, 1024
|
314 |
+
.reshape(N, -1, 4 * C) # N, 144, 4096
|
315 |
+
.reshape(
|
316 |
+
num_images, h_crop, w_crop, H // 2, H // 2, -1
|
317 |
+
) # n_img, h_crop, w_crop, 12, 12, 4096
|
318 |
+
.permute(0, 1, 3, 2, 4, 5) # n_img, h_crop, 12, w_crop, 12, 4096
|
319 |
+
.reshape(
|
320 |
+
num_images, h_crop * H // 2, w_crop * H // 2, 4 * C
|
321 |
+
) # n_img, h_crop*12, w_crop*12, 4096
|
322 |
+
)
|
323 |
+
|
324 |
+
# alternative implementation using einops
|
325 |
+
# from einops import rearrange
|
326 |
+
# image_features_nhwc = rearrange(
|
327 |
+
# image_features,
|
328 |
+
# 'N (H W) c -> N H W c',
|
329 |
+
# H=H,
|
330 |
+
# W=H,
|
331 |
+
# )
|
332 |
+
# image_features_2x2merge = rearrange(
|
333 |
+
# image_features_nhwc,
|
334 |
+
# 'N (h h_pool) (w w_pool) c -> N h w (h_pool w_pool c)',
|
335 |
+
# h_pool=2,
|
336 |
+
# w_pool=2,
|
337 |
+
# )
|
338 |
+
# image_features_hd = rearrange(
|
339 |
+
# image_features_2x2merge,
|
340 |
+
# '(n_img h_crop w_crop) h w C -> n_img (h_crop h) (w_crop w) C',
|
341 |
+
# h_crop=h_crop,
|
342 |
+
# w_crop=w_crop,
|
343 |
+
# )
|
344 |
+
|
345 |
+
return image_features_hd
|
346 |
+
|
347 |
+
def add_image_newline(self, image_features_hd):
|
348 |
+
"""
|
349 |
+
image_features_hd: (num_images, h_crop*12, w_crop*12, 4096)
|
350 |
+
output: (num_images, (h_crop*12) * (w_crop*12+1), 4096)
|
351 |
+
"""
|
352 |
+
num_images, h, w, hid_dim = image_features_hd.shape
|
353 |
+
# add the newline token to the HD image feature patches
|
354 |
+
newline_embeddings = self.sub_GN.expand(num_images, h, -1, -1) # (n_img, h, 1, hid_dim)
|
355 |
+
image_features_hd_newline = torch.cat(
|
356 |
+
[image_features_hd, newline_embeddings], dim=2
|
357 |
+
).reshape(num_images, -1, hid_dim)
|
358 |
+
return image_features_hd_newline
|
359 |
+
|
360 |
+
|
361 |
+
logger = logging.get_logger(__name__)
|
362 |
+
|
363 |
+
_CHECKPOINT_FOR_DOC = "microsoft/Phi-3-vision-128k-instruct"
|
364 |
+
_CONFIG_FOR_DOC = "Phi3VConfig"
|
365 |
+
|
366 |
+
PHI3V_PRETRAINED_MODEL_ARCHIVE_LIST = [
|
367 |
+
"microsoft/Phi-3-vision-128k-instruct",
|
368 |
+
# See all Phi-3 models at https://huggingface.co/models?filter=Phi-3
|
369 |
+
]
|
370 |
+
|
371 |
+
|
372 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->Phi3
|
373 |
+
class Phi3RMSNorm(nn.Module):
|
374 |
+
def __init__(self, hidden_size, eps=1e-6):
|
375 |
+
"""
|
376 |
+
Phi3RMSNorm is equivalent to T5LayerNorm
|
377 |
+
"""
|
378 |
+
super().__init__()
|
379 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
380 |
+
self.variance_epsilon = eps
|
381 |
+
|
382 |
+
def forward(self, hidden_states):
|
383 |
+
input_dtype = hidden_states.dtype
|
384 |
+
hidden_states = hidden_states.to(torch.float32)
|
385 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
386 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
387 |
+
return self.weight * hidden_states.to(input_dtype)
|
388 |
+
|
389 |
+
|
390 |
+
# Copied from transformers.models.llama.modeling_llama._get_unpad_data
|
391 |
+
def _get_unpad_data(attention_mask):
|
392 |
+
seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
|
393 |
+
indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
|
394 |
+
max_seqlen_in_batch = seqlens_in_batch.max().item()
|
395 |
+
cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0))
|
396 |
+
return (
|
397 |
+
indices,
|
398 |
+
cu_seqlens,
|
399 |
+
max_seqlen_in_batch,
|
400 |
+
)
|
401 |
+
|
402 |
+
|
403 |
+
# Copied from transformers.models.gemma.modeling_gemma.GemmaRotaryEmbedding with gemma->phi3, Gemma->Phi3
|
404 |
+
class Phi3RotaryEmbedding(nn.Module):
|
405 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
|
406 |
+
super().__init__()
|
407 |
+
|
408 |
+
self.dim = dim
|
409 |
+
self.max_position_embeddings = max_position_embeddings
|
410 |
+
self.base = base
|
411 |
+
self.register_buffer("inv_freq", None, persistent=False)
|
412 |
+
|
413 |
+
@torch.no_grad()
|
414 |
+
def forward(self, x, position_ids, seq_len=None):
|
415 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
416 |
+
if self.inv_freq is None:
|
417 |
+
self.inv_freq = 1.0 / (
|
418 |
+
self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim)
|
419 |
+
)
|
420 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
421 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
422 |
+
# Force float32 since bfloat16 loses precision on long contexts
|
423 |
+
# See https://github.com/huggingface/transformers/pull/29285
|
424 |
+
device_type = x.device.type
|
425 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
426 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
427 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
428 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
429 |
+
cos = emb.cos()
|
430 |
+
sin = emb.sin()
|
431 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
432 |
+
|
433 |
+
|
434 |
+
class Phi3SuScaledRotaryEmbedding(Phi3RotaryEmbedding):
|
435 |
+
def __init__(self, dim, config, device=None):
|
436 |
+
super().__init__(dim, config.max_position_embeddings, config.rope_theta, device)
|
437 |
+
|
438 |
+
self.short_factor = config.rope_scaling["short_factor"]
|
439 |
+
self.long_factor = config.rope_scaling["long_factor"]
|
440 |
+
self.original_max_position_embeddings = config.original_max_position_embeddings
|
441 |
+
|
442 |
+
@torch.no_grad()
|
443 |
+
def forward(self, x, position_ids, seq_len=None):
|
444 |
+
seq_len = seq_len or torch.max(position_ids) + 1
|
445 |
+
if seq_len > self.original_max_position_embeddings:
|
446 |
+
ext_factors = torch.tensor(self.long_factor, dtype=torch.float32, device=x.device)
|
447 |
+
else:
|
448 |
+
ext_factors = torch.tensor(self.short_factor, dtype=torch.float32, device=x.device)
|
449 |
+
|
450 |
+
inv_freq_shape = torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim
|
451 |
+
self.inv_freq = 1.0 / (ext_factors * self.base**inv_freq_shape)
|
452 |
+
|
453 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
454 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
455 |
+
|
456 |
+
# Force float32 since bfloat16 loses precision on long contexts
|
457 |
+
# See https://github.com/huggingface/transformers/pull/29285
|
458 |
+
device_type = x.device.type
|
459 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
460 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
461 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
462 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
463 |
+
|
464 |
+
scale = self.max_position_embeddings / self.original_max_position_embeddings
|
465 |
+
if scale <= 1.0:
|
466 |
+
scaling_factor = 1.0
|
467 |
+
else:
|
468 |
+
scaling_factor = math.sqrt(1 + math.log(scale) / math.log(self.original_max_position_embeddings))
|
469 |
+
|
470 |
+
cos = emb.cos() * scaling_factor
|
471 |
+
sin = emb.sin() * scaling_factor
|
472 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
473 |
+
|
474 |
+
|
475 |
+
class Phi3YarnScaledRotaryEmbedding(Phi3RotaryEmbedding):
|
476 |
+
def __init__(self, dim, config, device=None):
|
477 |
+
super().__init__(dim, config.max_position_embeddings, config.rope_theta, device)
|
478 |
+
|
479 |
+
self.short_factor = config.rope_scaling["short_factor"]
|
480 |
+
self.long_factor = config.rope_scaling["long_factor"]
|
481 |
+
self.original_max_position_embeddings = config.original_max_position_embeddings
|
482 |
+
|
483 |
+
@torch.no_grad()
|
484 |
+
def forward(self, x, position_ids, seq_len=None):
|
485 |
+
seq_len = torch.max(position_ids) + 1
|
486 |
+
if seq_len > self.original_max_position_embeddings:
|
487 |
+
ext_factors = torch.tensor(self.long_factor, dtype=torch.float32, device=x.device)
|
488 |
+
else:
|
489 |
+
ext_factors = torch.tensor(self.short_factor, dtype=torch.float32, device=x.device)
|
490 |
+
|
491 |
+
inv_freq_shape = torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim
|
492 |
+
self.inv_freq = 1.0 / (ext_factors * self.base**inv_freq_shape)
|
493 |
+
|
494 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
|
495 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
496 |
+
|
497 |
+
# Force float32 since bfloat16 loses precision on long contexts
|
498 |
+
# See https://github.com/huggingface/transformers/pull/29285
|
499 |
+
device_type = x.device.type
|
500 |
+
device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
|
501 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
502 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
503 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
504 |
+
|
505 |
+
scale = self.max_position_embeddings / self.original_max_position_embeddings
|
506 |
+
if scale <= 1.0:
|
507 |
+
scaling_factor = 1.0
|
508 |
+
else:
|
509 |
+
scaling_factor = 0.1 * math.log(scale) + 1.0
|
510 |
+
|
511 |
+
cos = emb.cos() * scaling_factor
|
512 |
+
sin = emb.sin() * scaling_factor
|
513 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
514 |
+
|
515 |
+
|
516 |
+
# Copied from transformers.models.llama.modeling_llama.rotate_half
|
517 |
+
def rotate_half(x):
|
518 |
+
"""Rotates half the hidden dims of the input."""
|
519 |
+
x1 = x[..., : x.shape[-1] // 2]
|
520 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
521 |
+
return torch.cat((-x2, x1), dim=-1)
|
522 |
+
|
523 |
+
|
524 |
+
# Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
|
525 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
526 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
527 |
+
|
528 |
+
Args:
|
529 |
+
q (`torch.Tensor`): The query tensor.
|
530 |
+
k (`torch.Tensor`): The key tensor.
|
531 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
532 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
533 |
+
position_ids (`torch.Tensor`, *optional*):
|
534 |
+
Deprecated and unused.
|
535 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
536 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
537 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
538 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
539 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
540 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
541 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
542 |
+
Returns:
|
543 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
544 |
+
"""
|
545 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
546 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
547 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
548 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
549 |
+
return q_embed, k_embed
|
550 |
+
|
551 |
+
|
552 |
+
class Phi3MLP(nn.Module):
|
553 |
+
def __init__(self, config):
|
554 |
+
super().__init__()
|
555 |
+
|
556 |
+
self.config = config
|
557 |
+
self.gate_up_proj = nn.Linear(config.hidden_size, 2 * config.intermediate_size, bias=False)
|
558 |
+
self.down_proj = nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
|
559 |
+
|
560 |
+
self.activation_fn = ACT2FN[config.hidden_act]
|
561 |
+
|
562 |
+
def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
|
563 |
+
up_states = self.gate_up_proj(hidden_states)
|
564 |
+
|
565 |
+
gate, up_states = up_states.chunk(2, dim=-1)
|
566 |
+
up_states = up_states * self.activation_fn(gate)
|
567 |
+
|
568 |
+
return self.down_proj(up_states)
|
569 |
+
|
570 |
+
|
571 |
+
# Copied from transformers.models.llama.modeling_llama.repeat_kv with llama->phi
|
572 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
573 |
+
"""
|
574 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
575 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
576 |
+
"""
|
577 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
578 |
+
if n_rep == 1:
|
579 |
+
return hidden_states
|
580 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
581 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
582 |
+
|
583 |
+
|
584 |
+
class Phi3Attention(nn.Module):
|
585 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
586 |
+
|
587 |
+
def __init__(self, config: Phi3VConfig, layer_idx: Optional[int] = None):
|
588 |
+
super().__init__()
|
589 |
+
self.config = config
|
590 |
+
self.layer_idx = layer_idx
|
591 |
+
if layer_idx is None:
|
592 |
+
logger.warning_once(
|
593 |
+
f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
|
594 |
+
"lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
|
595 |
+
"when creating this class."
|
596 |
+
)
|
597 |
+
|
598 |
+
self.attention_dropout = config.attention_dropout
|
599 |
+
self.hidden_size = config.hidden_size
|
600 |
+
self.num_heads = config.num_attention_heads
|
601 |
+
self.head_dim = self.hidden_size // self.num_heads
|
602 |
+
self.num_key_value_heads = config.num_key_value_heads
|
603 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
604 |
+
self.max_position_embeddings = config.max_position_embeddings
|
605 |
+
self.original_max_position_embeddings = config.original_max_position_embeddings
|
606 |
+
self.rope_theta = config.rope_theta
|
607 |
+
self.rope_scaling = config.rope_scaling
|
608 |
+
self.is_causal = True
|
609 |
+
|
610 |
+
if (self.head_dim * self.num_heads) != self.hidden_size:
|
611 |
+
raise ValueError(
|
612 |
+
f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
|
613 |
+
f" and `num_heads`: {self.num_heads})."
|
614 |
+
)
|
615 |
+
|
616 |
+
op_size = self.num_heads * self.head_dim + 2 * (self.num_key_value_heads * self.head_dim)
|
617 |
+
self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
|
618 |
+
self.qkv_proj = nn.Linear(self.hidden_size, op_size, bias=False)
|
619 |
+
self._init_rope()
|
620 |
+
|
621 |
+
def _init_rope(self):
|
622 |
+
if self.rope_scaling is None:
|
623 |
+
self.rotary_emb = Phi3RotaryEmbedding(
|
624 |
+
self.head_dim,
|
625 |
+
max_position_embeddings=self.max_position_embeddings,
|
626 |
+
base=self.rope_theta,
|
627 |
+
)
|
628 |
+
else:
|
629 |
+
scaling_type = self.config.rope_scaling["type"]
|
630 |
+
if scaling_type == "su":
|
631 |
+
self.rotary_emb = Phi3SuScaledRotaryEmbedding(self.head_dim, self.config)
|
632 |
+
elif scaling_type == "yarn":
|
633 |
+
self.rotary_emb = Phi3YarnScaledRotaryEmbedding(self.head_dim, self.config)
|
634 |
+
else:
|
635 |
+
raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
|
636 |
+
|
637 |
+
def forward(
|
638 |
+
self,
|
639 |
+
hidden_states: torch.Tensor,
|
640 |
+
attention_mask: Optional[torch.Tensor] = None,
|
641 |
+
position_ids: Optional[torch.LongTensor] = None,
|
642 |
+
past_key_value: Optional[Cache] = None,
|
643 |
+
output_attentions: bool = False,
|
644 |
+
use_cache: bool = False,
|
645 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
646 |
+
logger.warning_once("You are not running the flash-attention implementation, expect numerical differences.")
|
647 |
+
|
648 |
+
bsz, q_len, _ = hidden_states.size()
|
649 |
+
|
650 |
+
qkv = self.qkv_proj(hidden_states)
|
651 |
+
query_pos = self.num_heads * self.head_dim
|
652 |
+
query_states = qkv[..., :query_pos]
|
653 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
654 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
655 |
+
|
656 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
657 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
658 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
659 |
+
|
660 |
+
kv_seq_len = key_states.shape[-2]
|
661 |
+
if past_key_value is not None:
|
662 |
+
if self.layer_idx is None:
|
663 |
+
raise ValueError(
|
664 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
665 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
666 |
+
"with a layer index."
|
667 |
+
)
|
668 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
669 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
|
670 |
+
|
671 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
672 |
+
|
673 |
+
if past_key_value is not None:
|
674 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
675 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
676 |
+
|
677 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
678 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
679 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
680 |
+
|
681 |
+
attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
|
682 |
+
|
683 |
+
if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
|
684 |
+
raise ValueError(
|
685 |
+
f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
|
686 |
+
f" {attn_weights.size()}"
|
687 |
+
)
|
688 |
+
|
689 |
+
if attention_mask is not None:
|
690 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
691 |
+
raise ValueError(
|
692 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
693 |
+
)
|
694 |
+
attn_weights = attn_weights + attention_mask
|
695 |
+
|
696 |
+
# upcast attention to fp32
|
697 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(value_states.dtype)
|
698 |
+
attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
|
699 |
+
|
700 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
701 |
+
|
702 |
+
if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
|
703 |
+
raise ValueError(
|
704 |
+
f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
|
705 |
+
f" {attn_output.size()}"
|
706 |
+
)
|
707 |
+
|
708 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
709 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
710 |
+
|
711 |
+
attn_output = self.o_proj(attn_output)
|
712 |
+
|
713 |
+
if not output_attentions:
|
714 |
+
attn_weights = None
|
715 |
+
|
716 |
+
return attn_output, attn_weights, past_key_value
|
717 |
+
|
718 |
+
|
719 |
+
class Phi3FlashAttention2(Phi3Attention):
|
720 |
+
"""
|
721 |
+
Phi-3 flash attention module. This module inherits from `Phi3Attention` as the weights of the module stays
|
722 |
+
untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
|
723 |
+
flash attention and deal with padding tokens in case the input contains any of them.
|
724 |
+
"""
|
725 |
+
|
726 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
|
727 |
+
def __init__(self, *args, **kwargs):
|
728 |
+
super().__init__(*args, **kwargs)
|
729 |
+
|
730 |
+
# TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
|
731 |
+
# flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
|
732 |
+
# Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
|
733 |
+
self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
|
734 |
+
|
735 |
+
def forward(
|
736 |
+
self,
|
737 |
+
hidden_states: torch.Tensor,
|
738 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
739 |
+
position_ids: Optional[torch.LongTensor] = None,
|
740 |
+
past_key_value: Optional[Cache] = None,
|
741 |
+
output_attentions: bool = False,
|
742 |
+
use_cache: bool = False,
|
743 |
+
**kwargs,
|
744 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
745 |
+
# Phi3FlashAttention2 attention does not support output_attentions
|
746 |
+
|
747 |
+
if not _flash_supports_window_size:
|
748 |
+
logger.warning_once(
|
749 |
+
"The current flash attention version does not support sliding window attention. Please use `attn_implementation='eager'` or upgrade flash-attn library."
|
750 |
+
)
|
751 |
+
raise ValueError("The current flash attention version does not support sliding window attention.")
|
752 |
+
|
753 |
+
output_attentions = False
|
754 |
+
|
755 |
+
if "padding_mask" in kwargs:
|
756 |
+
warnings.warn(
|
757 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
758 |
+
)
|
759 |
+
|
760 |
+
# overwrite attention_mask with padding_mask
|
761 |
+
attention_mask = kwargs.pop("padding_mask")
|
762 |
+
|
763 |
+
bsz, q_len, _ = hidden_states.size()
|
764 |
+
|
765 |
+
qkv = self.qkv_proj(hidden_states)
|
766 |
+
query_pos = self.num_heads * self.head_dim
|
767 |
+
query_states = qkv[..., :query_pos]
|
768 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
769 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
770 |
+
|
771 |
+
# Flash attention requires the input to have the shape
|
772 |
+
# batch_size x seq_length x head_dim x hidden_dim
|
773 |
+
# therefore we just need to keep the original shape
|
774 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
775 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
776 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
777 |
+
|
778 |
+
kv_seq_len = key_states.shape[-2]
|
779 |
+
if past_key_value is not None:
|
780 |
+
if self.layer_idx is None:
|
781 |
+
raise ValueError(
|
782 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
783 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
784 |
+
"with a layer index."
|
785 |
+
)
|
786 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
787 |
+
|
788 |
+
# Because the input can be padded, the absolute sequence length depends on the max position id.
|
789 |
+
rotary_seq_len = max(kv_seq_len, position_ids[:, -1].max().item()) + 1
|
790 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=rotary_seq_len)
|
791 |
+
|
792 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
793 |
+
|
794 |
+
use_sliding_windows = (
|
795 |
+
_flash_supports_window_size
|
796 |
+
and getattr(self.config, "sliding_window", None) is not None
|
797 |
+
and kv_seq_len > self.config.sliding_window
|
798 |
+
)
|
799 |
+
|
800 |
+
if past_key_value is not None:
|
801 |
+
# Activate slicing cache only if the config has a value `sliding_windows` attribute
|
802 |
+
cache_has_contents = past_key_value.get_seq_length(self.layer_idx) > 0
|
803 |
+
if (
|
804 |
+
getattr(self.config, "sliding_window", None) is not None
|
805 |
+
and kv_seq_len > self.config.sliding_window
|
806 |
+
and cache_has_contents
|
807 |
+
):
|
808 |
+
slicing_tokens = 1 - self.config.sliding_window
|
809 |
+
|
810 |
+
past_key = past_key_value[self.layer_idx][0]
|
811 |
+
past_value = past_key_value[self.layer_idx][1]
|
812 |
+
|
813 |
+
past_key = past_key[:, :, slicing_tokens:, :].contiguous()
|
814 |
+
past_value = past_value[:, :, slicing_tokens:, :].contiguous()
|
815 |
+
|
816 |
+
if past_key.shape[-2] != self.config.sliding_window - 1:
|
817 |
+
raise ValueError(
|
818 |
+
f"past key must have a shape of (`batch_size, num_heads, self.config.sliding_window-1, head_dim`), got"
|
819 |
+
f" {past_key.shape}"
|
820 |
+
)
|
821 |
+
|
822 |
+
if attention_mask is not None:
|
823 |
+
attention_mask = attention_mask[:, slicing_tokens:]
|
824 |
+
attention_mask = torch.cat([attention_mask, torch.ones_like(attention_mask[:, -1:])], dim=-1)
|
825 |
+
|
826 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
827 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
828 |
+
|
829 |
+
# repeat k/v heads if n_kv_heads < n_heads
|
830 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
831 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
832 |
+
|
833 |
+
attn_dropout = self.attention_dropout if self.training else 0.0
|
834 |
+
|
835 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
836 |
+
# therefore the input hidden states gets silently casted in float32. Hence, we need
|
837 |
+
# cast them back in the correct dtype just to be sure everything works as expected.
|
838 |
+
# This might slowdown training & inference so it is recommended to not cast the LayerNorms
|
839 |
+
# in fp32.
|
840 |
+
|
841 |
+
if query_states.dtype == torch.float32:
|
842 |
+
if torch.is_autocast_enabled():
|
843 |
+
target_dtype = torch.get_autocast_gpu_dtype()
|
844 |
+
# Handle the case where the model is quantized
|
845 |
+
elif hasattr(self.config, "_pre_quantization_dtype"):
|
846 |
+
target_dtype = self.config._pre_quantization_dtype
|
847 |
+
else:
|
848 |
+
target_dtype = self.qkv_proj.weight.dtype
|
849 |
+
|
850 |
+
logger.warning_once(
|
851 |
+
f"The input hidden states seems to be silently casted in float32, this might be related to"
|
852 |
+
f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
|
853 |
+
f" {target_dtype}."
|
854 |
+
)
|
855 |
+
|
856 |
+
query_states = query_states.to(target_dtype)
|
857 |
+
key_states = key_states.to(target_dtype)
|
858 |
+
value_states = value_states.to(target_dtype)
|
859 |
+
|
860 |
+
# Reashape to the expected shape for Flash Attention
|
861 |
+
query_states = query_states.transpose(1, 2)
|
862 |
+
key_states = key_states.transpose(1, 2)
|
863 |
+
value_states = value_states.transpose(1, 2)
|
864 |
+
|
865 |
+
attn_output = self._flash_attention_forward(
|
866 |
+
query_states,
|
867 |
+
key_states,
|
868 |
+
value_states,
|
869 |
+
attention_mask,
|
870 |
+
q_len,
|
871 |
+
dropout=attn_dropout,
|
872 |
+
use_sliding_windows=use_sliding_windows,
|
873 |
+
)
|
874 |
+
|
875 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
|
876 |
+
attn_output = self.o_proj(attn_output)
|
877 |
+
|
878 |
+
if not output_attentions:
|
879 |
+
attn_weights = None
|
880 |
+
|
881 |
+
return attn_output, attn_weights, past_key_value
|
882 |
+
|
883 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._flash_attention_forward
|
884 |
+
def _flash_attention_forward(
|
885 |
+
self,
|
886 |
+
query_states,
|
887 |
+
key_states,
|
888 |
+
value_states,
|
889 |
+
attention_mask,
|
890 |
+
query_length,
|
891 |
+
dropout=0.0,
|
892 |
+
softmax_scale=None,
|
893 |
+
use_sliding_windows=False,
|
894 |
+
):
|
895 |
+
"""
|
896 |
+
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
|
897 |
+
first unpad the input, then computes the attention scores and pad the final attention scores.
|
898 |
+
|
899 |
+
Args:
|
900 |
+
query_states (`torch.Tensor`):
|
901 |
+
Input query states to be passed to Flash Attention API
|
902 |
+
key_states (`torch.Tensor`):
|
903 |
+
Input key states to be passed to Flash Attention API
|
904 |
+
value_states (`torch.Tensor`):
|
905 |
+
Input value states to be passed to Flash Attention API
|
906 |
+
attention_mask (`torch.Tensor`):
|
907 |
+
The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
|
908 |
+
position of padding tokens and 1 for the position of non-padding tokens.
|
909 |
+
dropout (`float`):
|
910 |
+
Attention dropout
|
911 |
+
softmax_scale (`float`, *optional*):
|
912 |
+
The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
|
913 |
+
use_sliding_windows (`bool`, *optional*):
|
914 |
+
Whether to activate sliding window attention.
|
915 |
+
"""
|
916 |
+
if not self._flash_attn_uses_top_left_mask:
|
917 |
+
causal = self.is_causal
|
918 |
+
else:
|
919 |
+
# TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in LlamaFlashAttention2 __init__.
|
920 |
+
causal = self.is_causal and query_length != 1
|
921 |
+
|
922 |
+
# Contains at least one padding token in the sequence
|
923 |
+
if attention_mask is not None:
|
924 |
+
batch_size = query_states.shape[0]
|
925 |
+
query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
|
926 |
+
query_states, key_states, value_states, attention_mask, query_length
|
927 |
+
)
|
928 |
+
|
929 |
+
cu_seqlens_q, cu_seqlens_k = cu_seq_lens
|
930 |
+
max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
|
931 |
+
|
932 |
+
if not use_sliding_windows:
|
933 |
+
attn_output_unpad = flash_attn_varlen_func(
|
934 |
+
query_states,
|
935 |
+
key_states,
|
936 |
+
value_states,
|
937 |
+
cu_seqlens_q=cu_seqlens_q,
|
938 |
+
cu_seqlens_k=cu_seqlens_k,
|
939 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
940 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
941 |
+
dropout_p=dropout,
|
942 |
+
softmax_scale=softmax_scale,
|
943 |
+
causal=causal,
|
944 |
+
)
|
945 |
+
else:
|
946 |
+
attn_output_unpad = flash_attn_varlen_func(
|
947 |
+
query_states,
|
948 |
+
key_states,
|
949 |
+
value_states,
|
950 |
+
cu_seqlens_q=cu_seqlens_q,
|
951 |
+
cu_seqlens_k=cu_seqlens_k,
|
952 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
953 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
954 |
+
dropout_p=dropout,
|
955 |
+
softmax_scale=softmax_scale,
|
956 |
+
causal=causal,
|
957 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
958 |
+
)
|
959 |
+
|
960 |
+
attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
|
961 |
+
else:
|
962 |
+
if not use_sliding_windows:
|
963 |
+
attn_output = flash_attn_func(
|
964 |
+
query_states,
|
965 |
+
key_states,
|
966 |
+
value_states,
|
967 |
+
dropout,
|
968 |
+
softmax_scale=softmax_scale,
|
969 |
+
causal=causal,
|
970 |
+
)
|
971 |
+
else:
|
972 |
+
attn_output = flash_attn_func(
|
973 |
+
query_states,
|
974 |
+
key_states,
|
975 |
+
value_states,
|
976 |
+
dropout,
|
977 |
+
softmax_scale=softmax_scale,
|
978 |
+
causal=causal,
|
979 |
+
window_size=(self.config.sliding_window, self.config.sliding_window),
|
980 |
+
)
|
981 |
+
|
982 |
+
return attn_output
|
983 |
+
|
984 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._upad_input
|
985 |
+
def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
|
986 |
+
batch_size, kv_seq_len, num_heads, head_dim = key_layer.shape
|
987 |
+
|
988 |
+
# On the first iteration we need to properly re-create the padding mask
|
989 |
+
# by slicing it on the proper place
|
990 |
+
if kv_seq_len != attention_mask.shape[-1]:
|
991 |
+
attention_mask_num_tokens = attention_mask.shape[-1]
|
992 |
+
attention_mask = attention_mask[:, attention_mask_num_tokens - kv_seq_len :]
|
993 |
+
|
994 |
+
indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
|
995 |
+
|
996 |
+
key_layer = index_first_axis(key_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
997 |
+
value_layer = index_first_axis(value_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
|
998 |
+
|
999 |
+
if query_length == kv_seq_len:
|
1000 |
+
query_layer = index_first_axis(
|
1001 |
+
query_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k
|
1002 |
+
)
|
1003 |
+
cu_seqlens_q = cu_seqlens_k
|
1004 |
+
max_seqlen_in_batch_q = max_seqlen_in_batch_k
|
1005 |
+
indices_q = indices_k
|
1006 |
+
elif query_length == 1:
|
1007 |
+
max_seqlen_in_batch_q = 1
|
1008 |
+
cu_seqlens_q = torch.arange(
|
1009 |
+
batch_size + 1, dtype=torch.int32, device=query_layer.device
|
1010 |
+
) # There is a memcpy here, that is very bad.
|
1011 |
+
indices_q = cu_seqlens_q[:-1]
|
1012 |
+
query_layer = query_layer.squeeze(1)
|
1013 |
+
else:
|
1014 |
+
# The -q_len: slice assumes left padding.
|
1015 |
+
attention_mask = attention_mask[:, -query_length:]
|
1016 |
+
query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
|
1017 |
+
|
1018 |
+
return (
|
1019 |
+
query_layer,
|
1020 |
+
key_layer,
|
1021 |
+
value_layer,
|
1022 |
+
indices_q,
|
1023 |
+
(cu_seqlens_q, cu_seqlens_k),
|
1024 |
+
(max_seqlen_in_batch_q, max_seqlen_in_batch_k),
|
1025 |
+
)
|
1026 |
+
|
1027 |
+
|
1028 |
+
# copied from transformers.models.llama.modeling_llama.LlamaSdpaAttention with Llama->Phi3
|
1029 |
+
# TODO @Arthur no longer copied from LLama after static cache
|
1030 |
+
class Phi3SdpaAttention(Phi3Attention):
|
1031 |
+
"""
|
1032 |
+
Phi3 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
|
1033 |
+
`Phi3Attention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
|
1034 |
+
SDPA API.
|
1035 |
+
"""
|
1036 |
+
|
1037 |
+
# Adapted from Phi3Attention.forward
|
1038 |
+
def forward(
|
1039 |
+
self,
|
1040 |
+
hidden_states: torch.Tensor,
|
1041 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1042 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1043 |
+
past_key_value: Optional[Cache] = None,
|
1044 |
+
output_attentions: bool = False,
|
1045 |
+
use_cache: bool = False,
|
1046 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
1047 |
+
if output_attentions:
|
1048 |
+
# TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
|
1049 |
+
logger.warning_once(
|
1050 |
+
"Phi3Model is using Phi3SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
|
1051 |
+
'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
|
1052 |
+
)
|
1053 |
+
return super().forward(
|
1054 |
+
hidden_states=hidden_states,
|
1055 |
+
attention_mask=attention_mask,
|
1056 |
+
position_ids=position_ids,
|
1057 |
+
past_key_value=past_key_value,
|
1058 |
+
output_attentions=output_attentions,
|
1059 |
+
use_cache=use_cache,
|
1060 |
+
)
|
1061 |
+
|
1062 |
+
bsz, q_len, _ = hidden_states.size()
|
1063 |
+
|
1064 |
+
qkv = self.qkv_proj(hidden_states)
|
1065 |
+
query_pos = self.num_heads * self.head_dim
|
1066 |
+
query_states = qkv[..., :query_pos]
|
1067 |
+
key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
|
1068 |
+
value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
|
1069 |
+
|
1070 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
1071 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
1072 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
1073 |
+
|
1074 |
+
kv_seq_len = key_states.shape[-2]
|
1075 |
+
if past_key_value is not None:
|
1076 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
1077 |
+
cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
|
1078 |
+
|
1079 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
1080 |
+
|
1081 |
+
if past_key_value is not None:
|
1082 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
1083 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
1084 |
+
|
1085 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
1086 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
1087 |
+
|
1088 |
+
if attention_mask is not None:
|
1089 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
1090 |
+
raise ValueError(
|
1091 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
1092 |
+
)
|
1093 |
+
|
1094 |
+
# SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
|
1095 |
+
# Reference: https://github.com/pytorch/pytorch/issues/112577.
|
1096 |
+
if query_states.device.type == "cuda" and attention_mask is not None:
|
1097 |
+
query_states = query_states.contiguous()
|
1098 |
+
key_states = key_states.contiguous()
|
1099 |
+
value_states = value_states.contiguous()
|
1100 |
+
|
1101 |
+
attn_output = torch.nn.functional.scaled_dot_product_attention(
|
1102 |
+
query_states,
|
1103 |
+
key_states,
|
1104 |
+
value_states,
|
1105 |
+
attn_mask=attention_mask,
|
1106 |
+
dropout_p=self.attention_dropout if self.training else 0.0,
|
1107 |
+
# The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
|
1108 |
+
is_causal=self.is_causal and attention_mask is None and q_len > 1,
|
1109 |
+
)
|
1110 |
+
|
1111 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
1112 |
+
attn_output = attn_output.view(bsz, q_len, self.hidden_size)
|
1113 |
+
|
1114 |
+
attn_output = self.o_proj(attn_output)
|
1115 |
+
|
1116 |
+
return attn_output, None, past_key_value
|
1117 |
+
|
1118 |
+
|
1119 |
+
PHI3_ATTENTION_CLASSES = {
|
1120 |
+
"eager": Phi3Attention,
|
1121 |
+
"flash_attention_2": Phi3FlashAttention2,
|
1122 |
+
"sdpa": Phi3SdpaAttention,
|
1123 |
+
}
|
1124 |
+
|
1125 |
+
|
1126 |
+
class Phi3DecoderLayer(nn.Module):
|
1127 |
+
def __init__(self, config: Phi3VConfig, layer_idx: int):
|
1128 |
+
super().__init__()
|
1129 |
+
|
1130 |
+
self.config = config
|
1131 |
+
self.self_attn = PHI3_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx=layer_idx)
|
1132 |
+
|
1133 |
+
self.mlp = Phi3MLP(config)
|
1134 |
+
self.input_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
1135 |
+
|
1136 |
+
self.resid_attn_dropout = nn.Dropout(config.resid_pdrop)
|
1137 |
+
self.resid_mlp_dropout = nn.Dropout(config.resid_pdrop)
|
1138 |
+
self.post_attention_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
1139 |
+
|
1140 |
+
def forward(
|
1141 |
+
self,
|
1142 |
+
hidden_states: torch.Tensor,
|
1143 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1144 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1145 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
1146 |
+
output_attentions: Optional[bool] = False,
|
1147 |
+
use_cache: Optional[bool] = False,
|
1148 |
+
**kwargs,
|
1149 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
1150 |
+
if "padding_mask" in kwargs:
|
1151 |
+
warnings.warn(
|
1152 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
1153 |
+
)
|
1154 |
+
"""
|
1155 |
+
Args:
|
1156 |
+
hidden_states (`torch.FloatTensor`):
|
1157 |
+
input to the layer of shape `(batch, seq_len, embed_dim)`
|
1158 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
1159 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
1160 |
+
position_ids (`torch.LongTensor` of shape `({0})`, *optional*):
|
1161 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range
|
1162 |
+
`[0, config.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
|
1163 |
+
output_attentions (`bool`, *optional*):
|
1164 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
1165 |
+
returned tensors for more detail.
|
1166 |
+
use_cache (`bool`, *optional*):
|
1167 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
1168 |
+
(see `past_key_values`).
|
1169 |
+
past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
|
1170 |
+
"""
|
1171 |
+
|
1172 |
+
residual = hidden_states
|
1173 |
+
|
1174 |
+
hidden_states = self.input_layernorm(hidden_states)
|
1175 |
+
|
1176 |
+
# Self Attention
|
1177 |
+
attn_outputs, self_attn_weights, present_key_value = self.self_attn(
|
1178 |
+
hidden_states=hidden_states,
|
1179 |
+
attention_mask=attention_mask,
|
1180 |
+
position_ids=position_ids,
|
1181 |
+
past_key_value=past_key_value,
|
1182 |
+
output_attentions=output_attentions,
|
1183 |
+
use_cache=use_cache,
|
1184 |
+
)
|
1185 |
+
|
1186 |
+
hidden_states = residual + self.resid_attn_dropout(attn_outputs)
|
1187 |
+
|
1188 |
+
residual = hidden_states
|
1189 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
1190 |
+
hidden_states = self.mlp(hidden_states)
|
1191 |
+
hidden_states = residual + self.resid_mlp_dropout(hidden_states)
|
1192 |
+
|
1193 |
+
outputs = (hidden_states,)
|
1194 |
+
|
1195 |
+
if output_attentions:
|
1196 |
+
outputs += (self_attn_weights,)
|
1197 |
+
|
1198 |
+
if use_cache:
|
1199 |
+
outputs += (present_key_value,)
|
1200 |
+
|
1201 |
+
return outputs
|
1202 |
+
|
1203 |
+
|
1204 |
+
PHI3V_START_DOCSTRING = r"""
|
1205 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
1206 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
1207 |
+
etc.)
|
1208 |
+
|
1209 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
1210 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
1211 |
+
and behavior.
|
1212 |
+
|
1213 |
+
Parameters:
|
1214 |
+
config ([`Phi3VConfig`]):
|
1215 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
1216 |
+
load the weights associated with the model, only the configuration. Check out the
|
1217 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
1218 |
+
"""
|
1219 |
+
|
1220 |
+
|
1221 |
+
@add_start_docstrings(
|
1222 |
+
"The bare Phi-3-V model outputting raw hidden-states without any specific head on top.",
|
1223 |
+
PHI3V_START_DOCSTRING,
|
1224 |
+
)
|
1225 |
+
class Phi3VPreTrainedModel(PreTrainedModel):
|
1226 |
+
config_class = Phi3VConfig
|
1227 |
+
base_model_prefix = "model"
|
1228 |
+
supports_gradient_checkpointing = True
|
1229 |
+
_no_split_modules = ["Phi3DecoderLayer"]
|
1230 |
+
_skip_keys_device_placement = "past_key_values"
|
1231 |
+
_supports_flash_attn_2 = True
|
1232 |
+
_supports_sdpa = False
|
1233 |
+
_supports_cache_class = True
|
1234 |
+
|
1235 |
+
_version = "0.0.5"
|
1236 |
+
|
1237 |
+
def _init_weights(self, module):
|
1238 |
+
std = self.config.initializer_range
|
1239 |
+
if isinstance(module, nn.Linear):
|
1240 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
1241 |
+
if module.bias is not None:
|
1242 |
+
module.bias.data.zero_()
|
1243 |
+
elif isinstance(module, nn.Embedding):
|
1244 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
1245 |
+
if module.padding_idx is not None:
|
1246 |
+
module.weight.data[module.padding_idx].zero_()
|
1247 |
+
|
1248 |
+
|
1249 |
+
PHI3V_INPUTS_DOCSTRING = r"""
|
1250 |
+
Args:
|
1251 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
1252 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
1253 |
+
it.
|
1254 |
+
|
1255 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
1256 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
1257 |
+
|
1258 |
+
[What are input IDs?](../glossary#input-ids)
|
1259 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
1260 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
1261 |
+
|
1262 |
+
- 1 for tokens that are **not masked**,
|
1263 |
+
- 0 for tokens that are **masked**.
|
1264 |
+
|
1265 |
+
[What are attention masks?](../glossary#attention-mask)
|
1266 |
+
|
1267 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
1268 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
1269 |
+
|
1270 |
+
If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
|
1271 |
+
`past_key_values`).
|
1272 |
+
|
1273 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
1274 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
1275 |
+
information on the default strategy.
|
1276 |
+
|
1277 |
+
- 1 indicates the head is **not masked**,
|
1278 |
+
- 0 indicates the head is **masked**.
|
1279 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
1280 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
1281 |
+
config.n_positions - 1]`.
|
1282 |
+
|
1283 |
+
[What are position IDs?](../glossary#position-ids)
|
1284 |
+
past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
1285 |
+
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
1286 |
+
blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
|
1287 |
+
returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
|
1288 |
+
|
1289 |
+
Two formats are allowed:
|
1290 |
+
- a [`~cache_utils.Cache`] instance;
|
1291 |
+
- Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
1292 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
|
1293 |
+
cache format.
|
1294 |
+
|
1295 |
+
The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
|
1296 |
+
legacy cache format will be returned.
|
1297 |
+
|
1298 |
+
If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
|
1299 |
+
have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
|
1300 |
+
of shape `(batch_size, sequence_length)`.
|
1301 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
1302 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
1303 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
1304 |
+
model's internal embedding lookup matrix.
|
1305 |
+
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)):
|
1306 |
+
The tensors corresponding to the input images. Pixel values can be obtained using [`AutoImageProcessor`].
|
1307 |
+
See [`Phi3ImageProcessor.__call__`] for details.
|
1308 |
+
image_sizes (`torch.LongTensor` of shape `(batch_size, 2)`, *optional*):
|
1309 |
+
The sizes of the images in the batch, being (height, width) for each image.
|
1310 |
+
use_cache (`bool`, *optional*):
|
1311 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
1312 |
+
`past_key_values`).
|
1313 |
+
output_attentions (`bool`, *optional*):
|
1314 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
1315 |
+
tensors for more detail.
|
1316 |
+
output_hidden_states (`bool`, *optional*):
|
1317 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
1318 |
+
more detail.
|
1319 |
+
return_dict (`bool`, *optional*):
|
1320 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
1321 |
+
"""
|
1322 |
+
|
1323 |
+
|
1324 |
+
@add_start_docstrings(
|
1325 |
+
"The bare Phi-3-V model outputting raw hidden-states without any specific head on top.",
|
1326 |
+
PHI3V_START_DOCSTRING,
|
1327 |
+
)
|
1328 |
+
class Phi3VModel(Phi3VPreTrainedModel):
|
1329 |
+
"""
|
1330 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Phi3DecoderLayer`]
|
1331 |
+
|
1332 |
+
Args:
|
1333 |
+
config: Phi3Config
|
1334 |
+
"""
|
1335 |
+
|
1336 |
+
def __init__(self, config: Phi3VConfig):
|
1337 |
+
super().__init__(config)
|
1338 |
+
self.padding_idx = config.pad_token_id
|
1339 |
+
self.vocab_size = config.vocab_size
|
1340 |
+
|
1341 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
1342 |
+
self.embed_dropout = nn.Dropout(config.embd_pdrop)
|
1343 |
+
|
1344 |
+
self.vision_embed_tokens = None
|
1345 |
+
if isinstance(config.embd_layer, dict):
|
1346 |
+
# vision embedding layer
|
1347 |
+
embedding_config = {
|
1348 |
+
'embedding_cls': config.embd_layer['embedding_cls'],
|
1349 |
+
**config.embd_layer
|
1350 |
+
}
|
1351 |
+
self.vision_embed_tokens = Phi3ImageEmbedding(config, wte=self.embed_tokens, **embedding_config)
|
1352 |
+
# # set wte the same for vision embedding
|
1353 |
+
# self.vision_embed_tokens.wte.weight = self.embed_tokens.weight
|
1354 |
+
|
1355 |
+
self.layers = nn.ModuleList(
|
1356 |
+
[Phi3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
1357 |
+
)
|
1358 |
+
self._attn_implementation = config._attn_implementation
|
1359 |
+
self.norm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
1360 |
+
|
1361 |
+
self.gradient_checkpointing = False
|
1362 |
+
# Initialize weights and apply final processing
|
1363 |
+
self.post_init()
|
1364 |
+
|
1365 |
+
def get_input_embeddings(self):
|
1366 |
+
return self.embed_tokens
|
1367 |
+
|
1368 |
+
def set_input_embeddings(self, value):
|
1369 |
+
self.embed_tokens = value
|
1370 |
+
|
1371 |
+
@add_start_docstrings_to_model_forward(PHI3V_INPUTS_DOCSTRING)
|
1372 |
+
def forward(
|
1373 |
+
self,
|
1374 |
+
input_ids: torch.LongTensor = None,
|
1375 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1376 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1377 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
1378 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1379 |
+
pixel_values: Optional[torch.FloatTensor] = None,
|
1380 |
+
image_sizes: Optional[torch.LongTensor] = None,
|
1381 |
+
use_cache: Optional[bool] = None,
|
1382 |
+
output_attentions: Optional[bool] = None,
|
1383 |
+
output_hidden_states: Optional[bool] = None,
|
1384 |
+
return_dict: Optional[bool] = None,
|
1385 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
1386 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
1387 |
+
output_hidden_states = (
|
1388 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
1389 |
+
)
|
1390 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
1391 |
+
|
1392 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1393 |
+
|
1394 |
+
# retrieve input_ids and inputs_embeds
|
1395 |
+
if input_ids is not None and inputs_embeds is not None:
|
1396 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
1397 |
+
elif input_ids is not None:
|
1398 |
+
batch_size, seq_length = input_ids.shape[:2]
|
1399 |
+
elif inputs_embeds is not None:
|
1400 |
+
batch_size, seq_length = inputs_embeds.shape[:2]
|
1401 |
+
else:
|
1402 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
1403 |
+
|
1404 |
+
past_key_values_length = 0
|
1405 |
+
|
1406 |
+
if self.gradient_checkpointing and self.training:
|
1407 |
+
if use_cache:
|
1408 |
+
logger.warning_once(
|
1409 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
1410 |
+
)
|
1411 |
+
use_cache = False
|
1412 |
+
|
1413 |
+
if use_cache:
|
1414 |
+
use_legacy_cache = not isinstance(past_key_values, Cache)
|
1415 |
+
if use_legacy_cache:
|
1416 |
+
past_key_values = DynamicCache.from_legacy_cache(past_key_values)
|
1417 |
+
past_key_values_length = past_key_values.get_usable_length(seq_length)
|
1418 |
+
|
1419 |
+
if position_ids is None:
|
1420 |
+
device = input_ids.device if input_ids is not None else inputs_embeds.device
|
1421 |
+
position_ids = torch.arange(
|
1422 |
+
past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
|
1423 |
+
)
|
1424 |
+
position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
|
1425 |
+
else:
|
1426 |
+
position_ids = position_ids.view(-1, seq_length).long()
|
1427 |
+
|
1428 |
+
if inputs_embeds is None:
|
1429 |
+
if pixel_values is not None and image_sizes is not None:
|
1430 |
+
assert self.vision_embed_tokens is not None, "Vision embedding layer is not defined"
|
1431 |
+
inputs_embeds = self.vision_embed_tokens(input_ids, pixel_values=pixel_values, image_sizes=image_sizes)
|
1432 |
+
else:
|
1433 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
1434 |
+
|
1435 |
+
if attention_mask is not None and self._attn_implementation == "flash_attention_2" and use_cache:
|
1436 |
+
is_padding_right = attention_mask[:, -1].sum().item() != batch_size
|
1437 |
+
if is_padding_right:
|
1438 |
+
raise ValueError(
|
1439 |
+
"You are attempting to perform batched generation with padding_side='right'"
|
1440 |
+
" this may lead to unexpected behaviour for Flash Attention version of Phi3. Make sure to "
|
1441 |
+
" call `tokenizer.padding_side = 'left'` before tokenizing the input. "
|
1442 |
+
)
|
1443 |
+
|
1444 |
+
if self._attn_implementation == "flash_attention_2":
|
1445 |
+
# 2d mask is passed through the layers
|
1446 |
+
attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
|
1447 |
+
else:
|
1448 |
+
# 4d mask is passed through the layers
|
1449 |
+
attention_mask = _prepare_4d_causal_attention_mask(
|
1450 |
+
attention_mask,
|
1451 |
+
(batch_size, seq_length),
|
1452 |
+
inputs_embeds,
|
1453 |
+
past_key_values_length,
|
1454 |
+
sliding_window=self.config.sliding_window,
|
1455 |
+
)
|
1456 |
+
|
1457 |
+
hidden_states = inputs_embeds
|
1458 |
+
|
1459 |
+
# decoder layers
|
1460 |
+
all_hidden_states = () if output_hidden_states else None
|
1461 |
+
all_self_attns = () if output_attentions else None
|
1462 |
+
next_decoder_cache = None
|
1463 |
+
|
1464 |
+
for decoder_layer in self.layers:
|
1465 |
+
if output_hidden_states:
|
1466 |
+
all_hidden_states += (hidden_states,)
|
1467 |
+
|
1468 |
+
if self.gradient_checkpointing and self.training:
|
1469 |
+
layer_outputs = self._gradient_checkpointing_func(
|
1470 |
+
decoder_layer.__call__,
|
1471 |
+
hidden_states,
|
1472 |
+
attention_mask,
|
1473 |
+
position_ids,
|
1474 |
+
past_key_values,
|
1475 |
+
output_attentions,
|
1476 |
+
use_cache,
|
1477 |
+
)
|
1478 |
+
else:
|
1479 |
+
layer_outputs = decoder_layer(
|
1480 |
+
hidden_states,
|
1481 |
+
attention_mask=attention_mask,
|
1482 |
+
position_ids=position_ids,
|
1483 |
+
past_key_value=past_key_values,
|
1484 |
+
output_attentions=output_attentions,
|
1485 |
+
use_cache=use_cache,
|
1486 |
+
)
|
1487 |
+
|
1488 |
+
hidden_states = layer_outputs[0]
|
1489 |
+
|
1490 |
+
if use_cache:
|
1491 |
+
next_decoder_cache = layer_outputs[2 if output_attentions else 1]
|
1492 |
+
|
1493 |
+
if output_attentions:
|
1494 |
+
all_self_attns += (layer_outputs[1],)
|
1495 |
+
|
1496 |
+
hidden_states = self.norm(hidden_states)
|
1497 |
+
|
1498 |
+
# add hidden states from the last decoder layer
|
1499 |
+
if output_hidden_states:
|
1500 |
+
all_hidden_states += (hidden_states,)
|
1501 |
+
|
1502 |
+
next_cache = None
|
1503 |
+
if use_cache:
|
1504 |
+
next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
|
1505 |
+
if not return_dict:
|
1506 |
+
return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
|
1507 |
+
return BaseModelOutputWithPast(
|
1508 |
+
last_hidden_state=hidden_states,
|
1509 |
+
past_key_values=next_cache,
|
1510 |
+
hidden_states=all_hidden_states,
|
1511 |
+
attentions=all_self_attns,
|
1512 |
+
)
|
1513 |
+
|
1514 |
+
|
1515 |
+
class Phi3VForCausalLM(Phi3VPreTrainedModel):
|
1516 |
+
_tied_weights_keys = ["lm_head.weight"]
|
1517 |
+
|
1518 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.__init__ with Llama->Phi3
|
1519 |
+
def __init__(self, config):
|
1520 |
+
super().__init__(config)
|
1521 |
+
self.model = Phi3VModel(config)
|
1522 |
+
self.vocab_size = config.vocab_size
|
1523 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
1524 |
+
|
1525 |
+
# Initialize weights and apply final processing
|
1526 |
+
self.post_init()
|
1527 |
+
|
1528 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_input_embeddings
|
1529 |
+
def get_input_embeddings(self):
|
1530 |
+
return self.model.embed_tokens
|
1531 |
+
|
1532 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_input_embeddings
|
1533 |
+
def set_input_embeddings(self, value):
|
1534 |
+
self.model.embed_tokens = value
|
1535 |
+
|
1536 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_output_embeddings
|
1537 |
+
def get_output_embeddings(self):
|
1538 |
+
return self.lm_head
|
1539 |
+
|
1540 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_output_embeddings
|
1541 |
+
def set_output_embeddings(self, new_embeddings):
|
1542 |
+
self.lm_head = new_embeddings
|
1543 |
+
|
1544 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_decoder
|
1545 |
+
def set_decoder(self, decoder):
|
1546 |
+
self.model = decoder
|
1547 |
+
|
1548 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_decoder
|
1549 |
+
def get_decoder(self):
|
1550 |
+
return self.model
|
1551 |
+
|
1552 |
+
# Ignore copy
|
1553 |
+
@add_start_docstrings_to_model_forward(PHI3V_INPUTS_DOCSTRING)
|
1554 |
+
@replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
1555 |
+
def forward(
|
1556 |
+
self,
|
1557 |
+
input_ids: torch.LongTensor = None,
|
1558 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1559 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1560 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
1561 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1562 |
+
pixel_values: Optional[torch.FloatTensor] = None,
|
1563 |
+
image_sizes: Optional[torch.LongTensor] = None,
|
1564 |
+
labels: Optional[torch.LongTensor] = None,
|
1565 |
+
use_cache: Optional[bool] = None,
|
1566 |
+
output_attentions: Optional[bool] = None,
|
1567 |
+
output_hidden_states: Optional[bool] = None,
|
1568 |
+
return_dict: Optional[bool] = None,
|
1569 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
1570 |
+
r"""
|
1571 |
+
Args:
|
1572 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
1573 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
1574 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
1575 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
1576 |
+
|
1577 |
+
Returns:
|
1578 |
+
|
1579 |
+
Example:
|
1580 |
+
|
1581 |
+
```python
|
1582 |
+
>>> from transformers import AutoTokenizer, Phi3ForCausalLM
|
1583 |
+
|
1584 |
+
>>> model = Phi3ForCausalLM.from_pretrained("microsoft/phi-3-mini-4k-instruct")
|
1585 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-3-mini-4k-instruct")
|
1586 |
+
|
1587 |
+
>>> prompt = "This is an example script ."
|
1588 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
1589 |
+
|
1590 |
+
>>> # Generate
|
1591 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
1592 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
1593 |
+
'This is an example script .\n Certainly! Below is a sample script that demonstrates a simple task, such as calculating the sum'
|
1594 |
+
```"""
|
1595 |
+
|
1596 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
1597 |
+
output_hidden_states = (
|
1598 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
1599 |
+
)
|
1600 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1601 |
+
|
1602 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
1603 |
+
outputs = self.model(
|
1604 |
+
input_ids=input_ids,
|
1605 |
+
attention_mask=attention_mask,
|
1606 |
+
position_ids=position_ids,
|
1607 |
+
past_key_values=past_key_values,
|
1608 |
+
inputs_embeds=inputs_embeds,
|
1609 |
+
pixel_values=pixel_values,
|
1610 |
+
image_sizes=image_sizes,
|
1611 |
+
use_cache=use_cache,
|
1612 |
+
output_attentions=output_attentions,
|
1613 |
+
output_hidden_states=output_hidden_states,
|
1614 |
+
return_dict=return_dict,
|
1615 |
+
)
|
1616 |
+
|
1617 |
+
hidden_states = outputs[0]
|
1618 |
+
logits = self.lm_head(hidden_states)
|
1619 |
+
logits = logits.float()
|
1620 |
+
|
1621 |
+
loss = None
|
1622 |
+
if labels is not None:
|
1623 |
+
# Shift so that tokens < n predict n
|
1624 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
1625 |
+
shift_labels = labels[..., 1:].contiguous()
|
1626 |
+
# Flatten the tokens
|
1627 |
+
loss_fct = CrossEntropyLoss()
|
1628 |
+
shift_logits = shift_logits.view(-1, self.config.vocab_size)
|
1629 |
+
shift_labels = shift_labels.view(-1)
|
1630 |
+
# Enable model parallelism
|
1631 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
1632 |
+
loss = loss_fct(shift_logits, shift_labels)
|
1633 |
+
|
1634 |
+
if not return_dict:
|
1635 |
+
output = (logits,) + outputs[1:]
|
1636 |
+
return (loss,) + output if loss is not None else output
|
1637 |
+
|
1638 |
+
return CausalLMOutputWithPast(
|
1639 |
+
loss=loss,
|
1640 |
+
logits=logits,
|
1641 |
+
past_key_values=outputs.past_key_values,
|
1642 |
+
hidden_states=outputs.hidden_states,
|
1643 |
+
attentions=outputs.attentions,
|
1644 |
+
)
|
1645 |
+
|
1646 |
+
# Copied from transformers.models.persimmon.modeling_persimmon.PersimmonForCausalLM.prepare_inputs_for_generation
|
1647 |
+
def prepare_inputs_for_generation(
|
1648 |
+
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, pixel_values=None, image_sizes=None, **kwargs
|
1649 |
+
):
|
1650 |
+
# When the first time input length reached long and short factor switching point, enforce re-compute cache
|
1651 |
+
# It will cause downside of slower at this single token position, however, better than current failure.
|
1652 |
+
if past_key_values and self.config.rope_scaling and input_ids.shape[1] >= self.config.original_max_position_embeddings + 1:
|
1653 |
+
past_length = past_key_values.seen_tokens if isinstance(past_key_values, Cache) else past_key_values[0][0].shape[2]
|
1654 |
+
if past_length <= self.config.original_max_position_embeddings:
|
1655 |
+
past_key_values = None
|
1656 |
+
|
1657 |
+
if past_key_values is not None:
|
1658 |
+
if isinstance(past_key_values, Cache):
|
1659 |
+
cache_length = past_key_values.get_seq_length()
|
1660 |
+
past_length = past_key_values.seen_tokens
|
1661 |
+
max_cache_length = past_key_values.get_max_length()
|
1662 |
+
else:
|
1663 |
+
cache_length = past_length = past_key_values[0][0].shape[2]
|
1664 |
+
max_cache_length = None
|
1665 |
+
|
1666 |
+
# Keep only the unprocessed tokens:
|
1667 |
+
# 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
|
1668 |
+
# some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
|
1669 |
+
# input)
|
1670 |
+
if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
|
1671 |
+
input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
|
1672 |
+
# 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
|
1673 |
+
# input_ids based on the past_length.
|
1674 |
+
elif past_length < input_ids.shape[1]:
|
1675 |
+
input_ids = input_ids[:, past_length:]
|
1676 |
+
# 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
|
1677 |
+
|
1678 |
+
# If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
|
1679 |
+
if (
|
1680 |
+
max_cache_length is not None
|
1681 |
+
and attention_mask is not None
|
1682 |
+
and cache_length + input_ids.shape[1] > max_cache_length
|
1683 |
+
):
|
1684 |
+
attention_mask = attention_mask[:, -max_cache_length:]
|
1685 |
+
|
1686 |
+
position_ids = kwargs.get("position_ids", None)
|
1687 |
+
if attention_mask is not None and position_ids is None:
|
1688 |
+
# create position_ids on the fly for batch generation
|
1689 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
1690 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
1691 |
+
if past_key_values:
|
1692 |
+
position_ids = position_ids[:, -input_ids.shape[1] :]
|
1693 |
+
|
1694 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
1695 |
+
if inputs_embeds is not None and past_key_values is None:
|
1696 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
1697 |
+
else:
|
1698 |
+
model_inputs = {"input_ids": input_ids}
|
1699 |
+
|
1700 |
+
model_inputs.update(
|
1701 |
+
{
|
1702 |
+
"position_ids": position_ids,
|
1703 |
+
"past_key_values": past_key_values,
|
1704 |
+
"use_cache": kwargs.get("use_cache"),
|
1705 |
+
"attention_mask": attention_mask,
|
1706 |
+
"pixel_values": pixel_values,
|
1707 |
+
"image_sizes": image_sizes,
|
1708 |
+
}
|
1709 |
+
)
|
1710 |
+
return model_inputs
|
1711 |
+
|
1712 |
+
@staticmethod
|
1713 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM._reorder_cache
|
1714 |
+
def _reorder_cache(past_key_values, beam_idx):
|
1715 |
+
reordered_past = ()
|
1716 |
+
for layer_past in past_key_values:
|
1717 |
+
reordered_past += (
|
1718 |
+
tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
|
1719 |
+
)
|
1720 |
+
return reordered_past
|
1721 |
+
|
1722 |
+
|
1723 |
+
@add_start_docstrings(
|
1724 |
+
"""
|
1725 |
+
The [`Phi3VModel`] with a sequence classification head on top (linear layer).
|
1726 |
+
|
1727 |
+
[`Phi3VForSequenceClassification`] uses the last token in order to do the classification, as other causal models
|
1728 |
+
(e.g. GPT-2) do.
|
1729 |
+
|
1730 |
+
Since it does classification on the last token, it requires to know the position of the last token. If a
|
1731 |
+
`pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
|
1732 |
+
no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
|
1733 |
+
padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
|
1734 |
+
each row of the batch).
|
1735 |
+
""",
|
1736 |
+
PHI3V_START_DOCSTRING,
|
1737 |
+
)
|
1738 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaForSequenceClassification with Llama->Phi3, LLAMA->PHI3, self.transformer->self.model, transformer_outputs->model_outputs
|
1739 |
+
class Phi3VForSequenceClassification(Phi3VPreTrainedModel):
|
1740 |
+
def __init__(self, config):
|
1741 |
+
super().__init__(config)
|
1742 |
+
self.num_labels = config.num_labels
|
1743 |
+
self.model = Phi3VModel(config)
|
1744 |
+
self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
|
1745 |
+
|
1746 |
+
# Initialize weights and apply final processing
|
1747 |
+
self.post_init()
|
1748 |
+
|
1749 |
+
def get_input_embeddings(self):
|
1750 |
+
return self.model.embed_tokens
|
1751 |
+
|
1752 |
+
def set_input_embeddings(self, value):
|
1753 |
+
self.model.embed_tokens = value
|
1754 |
+
|
1755 |
+
@add_start_docstrings_to_model_forward(PHI3V_INPUTS_DOCSTRING)
|
1756 |
+
def forward(
|
1757 |
+
self,
|
1758 |
+
input_ids: torch.LongTensor = None,
|
1759 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1760 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1761 |
+
past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,
|
1762 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1763 |
+
pixel_values: Optional[torch.FloatTensor] = None,
|
1764 |
+
image_sizes: Optional[torch.LongTensor] = None,
|
1765 |
+
labels: Optional[torch.LongTensor] = None,
|
1766 |
+
use_cache: Optional[bool] = None,
|
1767 |
+
output_attentions: Optional[bool] = None,
|
1768 |
+
output_hidden_states: Optional[bool] = None,
|
1769 |
+
return_dict: Optional[bool] = None,
|
1770 |
+
) -> Union[Tuple, SequenceClassifierOutputWithPast]:
|
1771 |
+
r"""
|
1772 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
1773 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
1774 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
1775 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
1776 |
+
"""
|
1777 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1778 |
+
|
1779 |
+
model_outputs = self.model(
|
1780 |
+
input_ids,
|
1781 |
+
attention_mask=attention_mask,
|
1782 |
+
position_ids=position_ids,
|
1783 |
+
past_key_values=past_key_values,
|
1784 |
+
inputs_embeds=inputs_embeds,
|
1785 |
+
pixel_values=pixel_values,
|
1786 |
+
image_sizes=image_sizes,
|
1787 |
+
use_cache=use_cache,
|
1788 |
+
output_attentions=output_attentions,
|
1789 |
+
output_hidden_states=output_hidden_states,
|
1790 |
+
return_dict=return_dict,
|
1791 |
+
)
|
1792 |
+
hidden_states = model_outputs[0]
|
1793 |
+
logits = self.score(hidden_states)
|
1794 |
+
|
1795 |
+
if input_ids is not None:
|
1796 |
+
batch_size = input_ids.shape[0]
|
1797 |
+
else:
|
1798 |
+
batch_size = inputs_embeds.shape[0]
|
1799 |
+
|
1800 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
1801 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
1802 |
+
if self.config.pad_token_id is None:
|
1803 |
+
sequence_lengths = -1
|
1804 |
+
else:
|
1805 |
+
if input_ids is not None:
|
1806 |
+
# if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
|
1807 |
+
sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
|
1808 |
+
sequence_lengths = sequence_lengths % input_ids.shape[-1]
|
1809 |
+
sequence_lengths = sequence_lengths.to(logits.device)
|
1810 |
+
else:
|
1811 |
+
sequence_lengths = -1
|
1812 |
+
|
1813 |
+
pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
|
1814 |
+
|
1815 |
+
loss = None
|
1816 |
+
if labels is not None:
|
1817 |
+
labels = labels.to(logits.device)
|
1818 |
+
if self.config.problem_type is None:
|
1819 |
+
if self.num_labels == 1:
|
1820 |
+
self.config.problem_type = "regression"
|
1821 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
1822 |
+
self.config.problem_type = "single_label_classification"
|
1823 |
+
else:
|
1824 |
+
self.config.problem_type = "multi_label_classification"
|
1825 |
+
|
1826 |
+
if self.config.problem_type == "regression":
|
1827 |
+
loss_fct = MSELoss()
|
1828 |
+
if self.num_labels == 1:
|
1829 |
+
loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
|
1830 |
+
else:
|
1831 |
+
loss = loss_fct(pooled_logits, labels)
|
1832 |
+
elif self.config.problem_type == "single_label_classification":
|
1833 |
+
loss_fct = CrossEntropyLoss()
|
1834 |
+
loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
|
1835 |
+
elif self.config.problem_type == "multi_label_classification":
|
1836 |
+
loss_fct = BCEWithLogitsLoss()
|
1837 |
+
loss = loss_fct(pooled_logits, labels)
|
1838 |
+
if not return_dict:
|
1839 |
+
output = (pooled_logits,) + model_outputs[1:]
|
1840 |
+
return ((loss,) + output) if loss is not None else output
|
1841 |
+
|
1842 |
+
return SequenceClassifierOutputWithPast(
|
1843 |
+
loss=loss,
|
1844 |
+
logits=pooled_logits,
|
1845 |
+
past_key_values=model_outputs.past_key_values,
|
1846 |
+
hidden_states=model_outputs.hidden_states,
|
1847 |
+
attentions=model_outputs.attentions,
|
1848 |
+
)
|
1849 |
+
|
1850 |
+
|
1851 |
+
@add_start_docstrings(
|
1852 |
+
"""
|
1853 |
+
[`Phi3VModel`] with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
|
1854 |
+
Named-Entity-Recognition (NER) tasks.
|
1855 |
+
""",
|
1856 |
+
PHI3V_START_DOCSTRING,
|
1857 |
+
)
|
1858 |
+
# Copied from transformers.models.mpt.modeling_mpt.MptForTokenClassification with Mpt->Phi3,MPT->PHI3,self.transformer->self.model,transformer_outputs->model_outputs
|
1859 |
+
class Phi3VForTokenClassification(Phi3VPreTrainedModel):
|
1860 |
+
def __init__(self, config: Phi3VConfig):
|
1861 |
+
super().__init__(config)
|
1862 |
+
self.num_labels = config.num_labels
|
1863 |
+
|
1864 |
+
self.model = Phi3VModel(config)
|
1865 |
+
if hasattr(config, "classifier_dropout") and config.classifier_dropout is not None:
|
1866 |
+
classifier_dropout = config.classifier_dropout
|
1867 |
+
elif hasattr(config, "hidden_dropout") and config.hidden_dropout is not None:
|
1868 |
+
classifier_dropout = config.hidden_dropout
|
1869 |
+
else:
|
1870 |
+
classifier_dropout = 0.1
|
1871 |
+
self.dropout = nn.Dropout(classifier_dropout)
|
1872 |
+
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
|
1873 |
+
|
1874 |
+
# Initialize weights and apply final processing
|
1875 |
+
self.post_init()
|
1876 |
+
|
1877 |
+
@add_start_docstrings_to_model_forward(PHI3V_INPUTS_DOCSTRING)
|
1878 |
+
@add_code_sample_docstrings(
|
1879 |
+
checkpoint=_CHECKPOINT_FOR_DOC,
|
1880 |
+
output_type=TokenClassifierOutput,
|
1881 |
+
config_class=_CONFIG_FOR_DOC,
|
1882 |
+
)
|
1883 |
+
def forward(
|
1884 |
+
self,
|
1885 |
+
input_ids: Optional[torch.LongTensor] = None,
|
1886 |
+
past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
|
1887 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1888 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
1889 |
+
pixel_values: Optional[torch.FloatTensor] = None,
|
1890 |
+
image_sizes: Optional[torch.LongTensor] = None,
|
1891 |
+
labels: Optional[torch.Tensor] = None,
|
1892 |
+
use_cache: Optional[bool] = None,
|
1893 |
+
output_attentions: Optional[bool] = None,
|
1894 |
+
output_hidden_states: Optional[bool] = None,
|
1895 |
+
return_dict: Optional[bool] = None,
|
1896 |
+
**deprecated_arguments,
|
1897 |
+
) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]:
|
1898 |
+
r"""
|
1899 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
1900 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
1901 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
1902 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
1903 |
+
"""
|
1904 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1905 |
+
|
1906 |
+
model_outputs = self.model(
|
1907 |
+
input_ids,
|
1908 |
+
past_key_values=past_key_values,
|
1909 |
+
attention_mask=attention_mask,
|
1910 |
+
inputs_embeds=inputs_embeds,
|
1911 |
+
pixel_values=pixel_values,
|
1912 |
+
image_sizes=image_sizes,
|
1913 |
+
use_cache=use_cache,
|
1914 |
+
output_attentions=output_attentions,
|
1915 |
+
output_hidden_states=output_hidden_states,
|
1916 |
+
return_dict=return_dict,
|
1917 |
+
)
|
1918 |
+
|
1919 |
+
hidden_states = model_outputs[0]
|
1920 |
+
hidden_states = self.dropout(hidden_states)
|
1921 |
+
logits = self.classifier(hidden_states)
|
1922 |
+
|
1923 |
+
loss = None
|
1924 |
+
if labels is not None:
|
1925 |
+
# move labels to correct device to enable model parallelism
|
1926 |
+
labels = labels.to(logits.device)
|
1927 |
+
batch_size, seq_length = labels.shape
|
1928 |
+
loss_fct = CrossEntropyLoss()
|
1929 |
+
loss = loss_fct(
|
1930 |
+
logits.view(batch_size * seq_length, self.num_labels), labels.view(batch_size * seq_length)
|
1931 |
+
)
|
1932 |
+
|
1933 |
+
if not return_dict:
|
1934 |
+
output = (logits,) + model_outputs[2:]
|
1935 |
+
return ((loss,) + output) if loss is not None else output
|
1936 |
+
|
1937 |
+
return TokenClassifierOutput(
|
1938 |
+
loss=loss,
|
1939 |
+
logits=logits,
|
1940 |
+
hidden_states=model_outputs.hidden_states,
|
1941 |
+
attentions=model_outputs.attentions,
|
1942 |
+
)
|
preprocessor_config.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"auto_map": {
|
3 |
+
"AutoImageProcessor": "processing_phi3_v.Phi3VImageProcessor",
|
4 |
+
"AutoProcessor": "processing_phi3_v.Phi3VProcessor"
|
5 |
+
},
|
6 |
+
"do_convert_rgb": true,
|
7 |
+
"image_mean": [
|
8 |
+
0.48145466,
|
9 |
+
0.4578275,
|
10 |
+
0.40821073
|
11 |
+
],
|
12 |
+
"image_processor_type": "Phi3VImageProcessor",
|
13 |
+
"image_std": [
|
14 |
+
0.26862954,
|
15 |
+
0.26130258,
|
16 |
+
0.27577711
|
17 |
+
],
|
18 |
+
"num_crops": 4,
|
19 |
+
"num_img_tokens": 144,
|
20 |
+
"processor_class": "Phi3VProcessor"
|
21 |
+
}
|
processing_phi3_v.py
ADDED
@@ -0,0 +1,478 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 Microsoft and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
"""
|
17 |
+
Processor class for Phi3-V.
|
18 |
+
"""
|
19 |
+
import re
|
20 |
+
from typing import List, Optional, Union
|
21 |
+
|
22 |
+
import torch
|
23 |
+
|
24 |
+
import transformers
|
25 |
+
from transformers.feature_extraction_utils import BatchFeature
|
26 |
+
from transformers.image_utils import ImageInput
|
27 |
+
from transformers.processing_utils import ProcessorMixin
|
28 |
+
from transformers.tokenization_utils_base import PaddingStrategy, TextInput, TruncationStrategy
|
29 |
+
from transformers.utils import TensorType
|
30 |
+
|
31 |
+
|
32 |
+
"""Image processor class for Phi3-V."""
|
33 |
+
|
34 |
+
from typing import List, Optional, Union
|
35 |
+
|
36 |
+
import numpy as np
|
37 |
+
|
38 |
+
from transformers.image_processing_utils import BaseImageProcessor, BatchFeature
|
39 |
+
from transformers.image_transforms import (
|
40 |
+
convert_to_rgb,
|
41 |
+
)
|
42 |
+
from transformers.image_utils import (
|
43 |
+
OPENAI_CLIP_MEAN,
|
44 |
+
OPENAI_CLIP_STD,
|
45 |
+
ImageInput,
|
46 |
+
make_list_of_images,
|
47 |
+
valid_images,
|
48 |
+
)
|
49 |
+
from transformers.utils import TensorType, is_vision_available, logging
|
50 |
+
|
51 |
+
from transformers import AutoImageProcessor
|
52 |
+
|
53 |
+
logger = logging.get_logger(__name__)
|
54 |
+
|
55 |
+
|
56 |
+
if is_vision_available():
|
57 |
+
from PIL import Image
|
58 |
+
|
59 |
+
import torch
|
60 |
+
import torchvision
|
61 |
+
|
62 |
+
def padding_336(b):
|
63 |
+
width, height = b.size
|
64 |
+
tar = int(np.ceil(height / 336) * 336)
|
65 |
+
top_padding = int((tar - height)/2)
|
66 |
+
bottom_padding = tar - height - top_padding
|
67 |
+
left_padding = 0
|
68 |
+
right_padding = 0
|
69 |
+
b = torchvision.transforms.functional.pad(b, [left_padding, top_padding, right_padding, bottom_padding], fill=[255,255,255])
|
70 |
+
|
71 |
+
return b
|
72 |
+
|
73 |
+
def calc_padded_size(width, height, padding_unit=336):
|
74 |
+
target_height = int(np.ceil(height / padding_unit) * padding_unit)
|
75 |
+
top_padding = int((target_height - height) / 2)
|
76 |
+
bottom_padding = target_height - height - top_padding
|
77 |
+
left_padding = 0
|
78 |
+
right_padding = 0
|
79 |
+
padded_width = width + left_padding + right_padding
|
80 |
+
padded_height = height + top_padding + bottom_padding
|
81 |
+
return padded_width, padded_height
|
82 |
+
|
83 |
+
def HD_transform(img, hd_num=16):
|
84 |
+
width, height = img.size
|
85 |
+
trans = False
|
86 |
+
if width < height:
|
87 |
+
img = img.transpose(Image.TRANSPOSE)
|
88 |
+
trans = True
|
89 |
+
width, height = img.size
|
90 |
+
ratio = (width/ height)
|
91 |
+
scale = 1
|
92 |
+
while scale*np.ceil(scale/ratio) <= hd_num:
|
93 |
+
scale += 1
|
94 |
+
scale -= 1
|
95 |
+
new_w = int(scale * 336)
|
96 |
+
new_h = int(new_w / ratio)
|
97 |
+
|
98 |
+
img = torchvision.transforms.functional.resize(img, [new_h, new_w],)
|
99 |
+
img = padding_336(img)
|
100 |
+
width, height = img.size
|
101 |
+
if trans:
|
102 |
+
img = img.transpose(Image.TRANSPOSE)
|
103 |
+
|
104 |
+
return img
|
105 |
+
|
106 |
+
def calc_hd_transform_size(width, height, hd_num=16):
|
107 |
+
transposed = False
|
108 |
+
if width < height:
|
109 |
+
width, height = height, width
|
110 |
+
transposed = True
|
111 |
+
|
112 |
+
ratio = width / height
|
113 |
+
scale = 1
|
114 |
+
while scale * np.ceil(scale / ratio) <= hd_num:
|
115 |
+
scale += 1
|
116 |
+
scale -= 1
|
117 |
+
|
118 |
+
new_width = int(scale * 336)
|
119 |
+
new_height = int(new_width / ratio)
|
120 |
+
|
121 |
+
padded_width, padded_height = calc_padded_size(new_width, new_height)
|
122 |
+
|
123 |
+
if transposed:
|
124 |
+
padded_width, padded_height = padded_height, padded_width
|
125 |
+
|
126 |
+
return padded_width, padded_height
|
127 |
+
|
128 |
+
def pad_to_max_num_crops_tensor(images, max_crops=5):
|
129 |
+
"""
|
130 |
+
images: B x 3 x H x W, B<=max_crops
|
131 |
+
"""
|
132 |
+
B, _, H, W = images.shape
|
133 |
+
if B < max_crops:
|
134 |
+
pad = torch.zeros(max_crops - B, 3, H, W, dtype=images.dtype, device=images.device)
|
135 |
+
images = torch.cat([images, pad], dim=0)
|
136 |
+
return images
|
137 |
+
|
138 |
+
|
139 |
+
class Phi3VImageProcessor(BaseImageProcessor):
|
140 |
+
r"""
|
141 |
+
Constructs a Phi3 image processor. Based on [`CLIPImageProcessor`] with incorporation of additional techniques
|
142 |
+
for processing high resolution images as explained in the [InternLM-XComposer2-4KHD](https://arxiv.org/pdf/2404.06512)
|
143 |
+
|
144 |
+
Args:
|
145 |
+
image_mean (`float` or `List[float]`, *optional*, defaults to `[0.48145466, 0.4578275, 0.40821073]`):
|
146 |
+
Mean to use if normalizing the image. This is a float or list of floats the length of the number of
|
147 |
+
channels in the image. Can be overridden by the `image_mean` parameter in the `preprocess` method.
|
148 |
+
image_std (`float` or `List[float]`, *optional*, defaults to `[0.26862954, 0.26130258, 0.27577711]`):
|
149 |
+
Standard deviation to use if normalizing the image. This is a float or list of floats the length of the
|
150 |
+
number of channels in the image. Can be overridden by the `image_std` parameter in the `preprocess` method.
|
151 |
+
Can be overridden by the `image_std` parameter in the `preprocess` method.
|
152 |
+
do_convert_rgb (`bool`, *optional*, defaults to `True`):
|
153 |
+
Whether to convert the image to RGB.
|
154 |
+
"""
|
155 |
+
|
156 |
+
model_input_names = ["pixel_values"]
|
157 |
+
|
158 |
+
def __init__(
|
159 |
+
self,
|
160 |
+
num_crops: int = 1,
|
161 |
+
image_mean: Optional[Union[float, List[float]]] = None,
|
162 |
+
image_std: Optional[Union[float, List[float]]] = None,
|
163 |
+
do_convert_rgb: bool = True,
|
164 |
+
**kwargs,
|
165 |
+
) -> None:
|
166 |
+
super().__init__(**kwargs)
|
167 |
+
self.num_crops = num_crops
|
168 |
+
self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN
|
169 |
+
self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD
|
170 |
+
self.do_convert_rgb = do_convert_rgb
|
171 |
+
|
172 |
+
def calc_num_image_tokens(
|
173 |
+
self,
|
174 |
+
images: ImageInput
|
175 |
+
):
|
176 |
+
""" Calculate the number of image tokens for each image.
|
177 |
+
Args:
|
178 |
+
images (`ImageInput`):
|
179 |
+
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
|
180 |
+
passing in images with pixel values between 0 and 1, set `do_rescale=False`.
|
181 |
+
"""
|
182 |
+
images = make_list_of_images(images)
|
183 |
+
|
184 |
+
if not valid_images(images):
|
185 |
+
raise ValueError(
|
186 |
+
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
|
187 |
+
"torch.Tensor, tf.Tensor or jax.ndarray."
|
188 |
+
)
|
189 |
+
|
190 |
+
images = [image.convert('RGB') for image in images]
|
191 |
+
# (H, W, C)
|
192 |
+
elems = [HD_transform(im, hd_num = self.num_crops) for im in images]
|
193 |
+
shapes = [[im.size[1], im.size[0]] for im in elems]
|
194 |
+
num_img_tokens = [int((h//336*w//336+1)*144 + 1 + (h//336+1)*12) for h, w in shapes]
|
195 |
+
return num_img_tokens
|
196 |
+
|
197 |
+
def calc_num_image_tokens_from_image_size(self, width, height):
|
198 |
+
"""
|
199 |
+
Calculate the number of image tokens for a given image size.
|
200 |
+
Args:
|
201 |
+
width (`int`): Width of the image.
|
202 |
+
height (`int`): Height of the image.
|
203 |
+
"""
|
204 |
+
new_width, new_height = calc_hd_transform_size(width, height, hd_num=self.num_crops)
|
205 |
+
num_img_tokens = int((new_height // 336 * new_width // 336 + 1) * 144 + 1 + (new_height // 336 + 1) * 12)
|
206 |
+
return num_img_tokens
|
207 |
+
|
208 |
+
def preprocess(
|
209 |
+
self,
|
210 |
+
images: ImageInput,
|
211 |
+
image_mean: Optional[Union[float, List[float]]] = None,
|
212 |
+
image_std: Optional[Union[float, List[float]]] = None,
|
213 |
+
do_convert_rgb: bool = None,
|
214 |
+
return_tensors: Optional[Union[str, TensorType]] = None,
|
215 |
+
):
|
216 |
+
"""
|
217 |
+
Args:
|
218 |
+
images (`ImageInput`):
|
219 |
+
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
|
220 |
+
passing in images with pixel values between 0 and 1, set `do_rescale=False`.
|
221 |
+
image_mean (`float` or `List[float]`, *optional*, defaults to `self.image_mean`):
|
222 |
+
Image mean to use for normalization. Only has an effect if `do_normalize` is set to `True`.
|
223 |
+
image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
|
224 |
+
Image standard deviation to use for normalization. Only has an effect if `do_normalize` is set to
|
225 |
+
`True`.
|
226 |
+
do_convert_rgb (`bool`, *optional*, defaults to `self.do_convert_rgb`):
|
227 |
+
Whether to convert the image to RGB.
|
228 |
+
return_tensors (`str` or `TensorType`, *optional*):
|
229 |
+
The type of tensors to return. Can be one of:
|
230 |
+
- Unset: Return a list of `np.ndarray`.
|
231 |
+
- `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
|
232 |
+
- `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
|
233 |
+
- `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
|
234 |
+
- `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
|
235 |
+
"""
|
236 |
+
image_mean = image_mean if image_mean is not None else self.image_mean
|
237 |
+
image_std = image_std if image_std is not None else self.image_std
|
238 |
+
do_convert_rgb = do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb
|
239 |
+
|
240 |
+
images = make_list_of_images(images)
|
241 |
+
|
242 |
+
if not valid_images(images):
|
243 |
+
raise ValueError(
|
244 |
+
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
|
245 |
+
"torch.Tensor, tf.Tensor or jax.ndarray."
|
246 |
+
)
|
247 |
+
|
248 |
+
if do_convert_rgb:
|
249 |
+
images = [convert_to_rgb(image) for image in images]
|
250 |
+
|
251 |
+
image_sizes = []
|
252 |
+
img_processor = torchvision.transforms.Compose([
|
253 |
+
torchvision.transforms.ToTensor(),
|
254 |
+
torchvision.transforms.Normalize(image_mean, image_std)
|
255 |
+
])
|
256 |
+
|
257 |
+
# PIL images
|
258 |
+
# HD_transform pad images to size of multiiply of 336, 336
|
259 |
+
# convert to RGB first
|
260 |
+
images = [image.convert('RGB') for image in images]
|
261 |
+
elems = [HD_transform(im, hd_num = self.num_crops) for im in images]
|
262 |
+
# tensor transform and normalize
|
263 |
+
hd_images = [img_processor(im) for im in elems]
|
264 |
+
# create global image
|
265 |
+
global_image = [torch.nn.functional.interpolate(im.unsqueeze(0).float(), size=(336, 336), mode='bicubic',).to(im.dtype) for im in hd_images]
|
266 |
+
|
267 |
+
# [(3, h, w)], where h, w is multiple of 336
|
268 |
+
shapes = [[im.size(1), im.size(2)] for im in hd_images]
|
269 |
+
num_img_tokens = [int(((h//336)*(w//336)+1)*144 + 1 + (h//336+1)*12) for h, w in shapes]
|
270 |
+
# reshape to channel dimension -> (num_images, num_crops, 3, 336, 336)
|
271 |
+
# (1, 3, h//336, 336, w//336, 336) -> (1, h//336, w//336, 3, 336, 336) -> (h//336*w//336, 3, 336, 336)
|
272 |
+
hd_images_reshape = [im.reshape(1, 3, h//336, 336, w//336, 336).permute(0,2,4,1,3,5).reshape(-1, 3, 336, 336).contiguous() for im, (h, w) in zip(hd_images, shapes)]
|
273 |
+
# concat global image and local image
|
274 |
+
hd_images_reshape = [torch.cat([_global_image] + [_im], dim=0) for _global_image, _im in zip(global_image, hd_images_reshape)]
|
275 |
+
|
276 |
+
# pad to max_num_crops
|
277 |
+
image_transformed = [pad_to_max_num_crops_tensor(im, self.num_crops+1) for im in hd_images_reshape]
|
278 |
+
image_transformed = torch.stack(image_transformed, dim=0)
|
279 |
+
image_sizes = [torch.LongTensor(_shapes) for _shapes in shapes]
|
280 |
+
padded_images = image_transformed
|
281 |
+
image_sizes = shapes
|
282 |
+
|
283 |
+
data = {"pixel_values": padded_images,
|
284 |
+
"image_sizes": image_sizes,
|
285 |
+
"num_img_tokens": num_img_tokens
|
286 |
+
}
|
287 |
+
|
288 |
+
return BatchFeature(data=data, tensor_type=return_tensors)
|
289 |
+
|
290 |
+
AutoImageProcessor.register("Phi3VImageProcessor", Phi3VImageProcessor)
|
291 |
+
|
292 |
+
transformers.Phi3VImageProcessor = Phi3VImageProcessor
|
293 |
+
|
294 |
+
class Phi3VProcessor(ProcessorMixin):
|
295 |
+
r"""
|
296 |
+
Constructs a Phi3-V processor which wraps a Phi3-V image processor and a LLaMa tokenizer into a single processor.
|
297 |
+
|
298 |
+
[`Phi3VProcessor`] offers all the functionalities of [`Phi3VImageProcessor`] and [`LlamaTokenizerFast`]. See the
|
299 |
+
[`~Phi3VProcessor.__call__`] and [`~Phi3VProcessor.decode`] for more information.
|
300 |
+
|
301 |
+
Args:
|
302 |
+
image_processor ([`Phi3VImageProcessor`], *optional*):
|
303 |
+
The image processor is a required input.
|
304 |
+
tokenizer ([`LlamaTokenizerFast`], *optional*):
|
305 |
+
The tokenizer is a required input.
|
306 |
+
"""
|
307 |
+
|
308 |
+
attributes = ["image_processor", "tokenizer"]
|
309 |
+
image_processor_class = "Phi3VImageProcessor"
|
310 |
+
tokenizer_class = ("LlamaTokenizer", "LlamaTokenizerFast")
|
311 |
+
special_image_token = "<|image|>"
|
312 |
+
|
313 |
+
def __init__(self, image_processor, tokenizer):
|
314 |
+
self.image_processor = image_processor
|
315 |
+
self.tokenizer = tokenizer
|
316 |
+
self.num_img_tokens = image_processor.num_img_tokens
|
317 |
+
self.img_tokens = [f"<|image_{i+1}|>" for i in range(1000000)]
|
318 |
+
|
319 |
+
def __call__(
|
320 |
+
self,
|
321 |
+
text: Union[TextInput, List[TextInput]],
|
322 |
+
images: ImageInput = None,
|
323 |
+
padding: Union[bool, str, PaddingStrategy] = False,
|
324 |
+
truncation: Union[bool, str, TruncationStrategy] = None,
|
325 |
+
max_length=None,
|
326 |
+
return_tensors: Optional[Union[str, TensorType]] = TensorType.PYTORCH,
|
327 |
+
) -> BatchFeature:
|
328 |
+
"""
|
329 |
+
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
|
330 |
+
and `kwargs` arguments to LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to encode
|
331 |
+
the text. To prepare the image(s), this method forwards the `images` and `kwrags` arguments to
|
332 |
+
Phi3ImageProcessor's [`~Phi3ImageProcessor.__call__`] if `images` is not `None`. Please refer to the doctsring
|
333 |
+
of the above two methods for more information.
|
334 |
+
|
335 |
+
Args:
|
336 |
+
text (`str`, `List[str]`, `List[List[str]]`):
|
337 |
+
The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
|
338 |
+
(pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
|
339 |
+
`is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
|
340 |
+
images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
|
341 |
+
The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
|
342 |
+
tensor. Both channels-first and channels-last formats are supported.
|
343 |
+
padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `False`):
|
344 |
+
Select a strategy to pad the returned sequences (according to the model's padding side and padding
|
345 |
+
index) among:
|
346 |
+
- `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
|
347 |
+
sequence if provided).
|
348 |
+
- `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
|
349 |
+
acceptable input length for the model if that argument is not provided.
|
350 |
+
- `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
|
351 |
+
lengths).
|
352 |
+
max_length (`int`, *optional*):
|
353 |
+
Maximum length of the returned list and optionally padding length (see above).
|
354 |
+
truncation (`bool`, *optional*):
|
355 |
+
Activates truncation to cut input sequences longer than `max_length` to `max_length`.
|
356 |
+
return_tensors (`str` or [`~utils.TensorType`], *optional*):
|
357 |
+
If set, will return tensors of a particular framework. Acceptable values are:
|
358 |
+
|
359 |
+
- `'tf'`: Return TensorFlow `tf.constant` objects.
|
360 |
+
- `'pt'`: Return PyTorch `torch.Tensor` objects.
|
361 |
+
- `'np'`: Return NumPy `np.ndarray` objects.
|
362 |
+
- `'jax'`: Return JAX `jnp.ndarray` objects.
|
363 |
+
|
364 |
+
Returns:
|
365 |
+
[`BatchFeature`]: A [`BatchFeature`] with the following fields:
|
366 |
+
|
367 |
+
- **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
|
368 |
+
- **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
|
369 |
+
`return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
|
370 |
+
`None`).
|
371 |
+
- **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
|
372 |
+
"""
|
373 |
+
if images is not None:
|
374 |
+
image_inputs = self.image_processor(images, return_tensors=return_tensors)
|
375 |
+
else:
|
376 |
+
image_inputs = {}
|
377 |
+
inputs = self._convert_images_texts_to_inputs(image_inputs, text, padding=padding, truncation=truncation, max_length=max_length, return_tensors=return_tensors)
|
378 |
+
return inputs
|
379 |
+
|
380 |
+
def calc_num_image_tokens(self, images: ImageInput):
|
381 |
+
""" Calculate the number of image tokens for each image.
|
382 |
+
Args:
|
383 |
+
images (`ImageInput`):
|
384 |
+
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
|
385 |
+
passing in images with pixel values between 0 and 1, set `do_rescale=False`.
|
386 |
+
"""
|
387 |
+
return self.image_processor.calc_num_image_tokens(images)
|
388 |
+
|
389 |
+
def calc_num_image_tokens_from_image_size(self, width, height):
|
390 |
+
""" Calculate the number of image token for an image with given width and height.
|
391 |
+
Args:
|
392 |
+
width (`int`):
|
393 |
+
Width of the image.
|
394 |
+
height (`int`):
|
395 |
+
Height of the image.
|
396 |
+
"""
|
397 |
+
return self.image_processor.calc_num_image_tokens_from_image_size(width, height)
|
398 |
+
|
399 |
+
|
400 |
+
@property
|
401 |
+
def special_image_token_id(self):
|
402 |
+
return self.tokenizer.convert_tokens_to_ids(self.special_image_token)
|
403 |
+
|
404 |
+
def get_special_image_token_id(self):
|
405 |
+
return self.tokenizer.convert_tokens_to_ids(self.special_image_token)
|
406 |
+
|
407 |
+
def _convert_images_texts_to_inputs(self, images, texts, padding=False, truncation=None, max_length=None, return_tensors=None):
|
408 |
+
|
409 |
+
if not len(images):
|
410 |
+
model_inputs = self.tokenizer(texts, return_tensors=return_tensors, padding=padding, truncation=truncation, max_length=max_length)
|
411 |
+
return BatchFeature(data={**model_inputs})
|
412 |
+
|
413 |
+
pattern = r"<\|image_\d+\|>"
|
414 |
+
prompt_chunks = [self.tokenizer(chunk).input_ids for chunk in re.split(pattern, texts)]
|
415 |
+
|
416 |
+
if 'num_img_tokens' in images:
|
417 |
+
num_img_tokens = images['num_img_tokens']
|
418 |
+
else:
|
419 |
+
assert 'num_crops' in images, 'num_crops must be provided in images if num_img_tokens is not provided'
|
420 |
+
num_crops = images['num_crops']
|
421 |
+
num_img_tokens = [_num_crops * self.num_img_tokens for _num_crops in num_crops]
|
422 |
+
|
423 |
+
images, image_sizes = images['pixel_values'], images['image_sizes']
|
424 |
+
|
425 |
+
# image_tags needs to start from 1 to n
|
426 |
+
image_tags = re.findall(pattern, texts)
|
427 |
+
# image_ids = [int(s.split("|")[1].split("_")[-1]) * -1 for s in image_tags]
|
428 |
+
# image_ids_pad = [[iid]*num_img_tokens[i] for i, iid in enumerate(image_ids)]
|
429 |
+
image_ids = [int(s.split("|")[1].split("_")[-1]) for s in image_tags]
|
430 |
+
unique_image_ids = sorted(list(set(image_ids)))
|
431 |
+
# image_ids must start from 1, and must be continuous int, e.g. [1, 2, 3], cannot be [1, 4, 5]
|
432 |
+
# check the condition
|
433 |
+
assert unique_image_ids == list(range(1, len(unique_image_ids)+1)), f"image_ids must start from 1, and must be continuous int, e.g. [1, 2, 3], cannot be {unique_image_ids}"
|
434 |
+
# total images must be the same as the number of image tags
|
435 |
+
assert len(unique_image_ids) == len(images), f"total images must be the same as the number of image tags, got {len(unique_image_ids)} image tags and {len(images)} images"
|
436 |
+
|
437 |
+
image_ids_pad = [[-iid]*num_img_tokens[iid-1] for iid in image_ids]
|
438 |
+
|
439 |
+
def insert_separator(X, sep_list):
|
440 |
+
if len(X) > len(sep_list):
|
441 |
+
sep_list.append([])
|
442 |
+
return [ele for sublist in zip(X, sep_list) for ele in sublist]
|
443 |
+
input_ids = []
|
444 |
+
offset = 0
|
445 |
+
for x in insert_separator(prompt_chunks, image_ids_pad):
|
446 |
+
input_ids.extend(x[offset:])
|
447 |
+
|
448 |
+
input_ids = torch.tensor(input_ids, dtype=torch.long).unsqueeze(0)
|
449 |
+
attention_mask = (input_ids > -1000000).to(torch.long)
|
450 |
+
|
451 |
+
return BatchFeature(data={"input_ids": input_ids,
|
452 |
+
"attention_mask": attention_mask,
|
453 |
+
"pixel_values": images,
|
454 |
+
"image_sizes": image_sizes})
|
455 |
+
|
456 |
+
|
457 |
+
# Copied from transformers.models.clip.processing_clip.CLIPProcessor.batch_decode with CLIP->Llama
|
458 |
+
def batch_decode(self, *args, **kwargs):
|
459 |
+
"""
|
460 |
+
This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
|
461 |
+
refer to the docstring of this method for more information.
|
462 |
+
"""
|
463 |
+
return self.tokenizer.batch_decode(*args, **kwargs)
|
464 |
+
|
465 |
+
# Copied from transformers.models.clip.processing_clip.CLIPProcessor.decode with CLIP->Llama
|
466 |
+
def decode(self, *args, **kwargs):
|
467 |
+
"""
|
468 |
+
This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
|
469 |
+
the docstring of this method for more information.
|
470 |
+
"""
|
471 |
+
return self.tokenizer.decode(*args, **kwargs)
|
472 |
+
|
473 |
+
@property
|
474 |
+
# Copied from transformers.models.clip.processing_clip.CLIPProcessor.model_input_names
|
475 |
+
def model_input_names(self):
|
476 |
+
tokenizer_input_names = self.tokenizer.model_input_names
|
477 |
+
image_processor_input_names = self.image_processor.model_input_names
|
478 |
+
return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))
|
processor_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"auto_map": {
|
3 |
+
"AutoProcessor": "processing_phi3_v.Phi3VProcessor"
|
4 |
+
},
|
5 |
+
"processor_class": "Phi3VProcessor"
|
6 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<|system|>",
|
4 |
+
"<|end|>",
|
5 |
+
"<|user|>",
|
6 |
+
"<|end|>"
|
7 |
+
],
|
8 |
+
"bos_token": {
|
9 |
+
"content": "<s>",
|
10 |
+
"lstrip": false,
|
11 |
+
"normalized": false,
|
12 |
+
"rstrip": false,
|
13 |
+
"single_word": false
|
14 |
+
},
|
15 |
+
"eos_token": {
|
16 |
+
"content": "<|endoftext|>",
|
17 |
+
"lstrip": false,
|
18 |
+
"normalized": false,
|
19 |
+
"rstrip": false,
|
20 |
+
"single_word": false
|
21 |
+
},
|
22 |
+
"pad_token": {
|
23 |
+
"content": "<|endoftext|>",
|
24 |
+
"lstrip": false,
|
25 |
+
"normalized": false,
|
26 |
+
"rstrip": false,
|
27 |
+
"single_word": false
|
28 |
+
},
|
29 |
+
"unk_token": {
|
30 |
+
"content": "<unk>",
|
31 |
+
"lstrip": false,
|
32 |
+
"normalized": false,
|
33 |
+
"rstrip": false,
|
34 |
+
"single_word": false
|
35 |
+
}
|
36 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,412 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": true,
|
3 |
+
"add_eos_token": false,
|
4 |
+
"added_tokens_decoder": {
|
5 |
+
"0": {
|
6 |
+
"content": "<unk>",
|
7 |
+
"lstrip": false,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false,
|
11 |
+
"special": true
|
12 |
+
},
|
13 |
+
"1": {
|
14 |
+
"content": "<s>",
|
15 |
+
"lstrip": false,
|
16 |
+
"normalized": false,
|
17 |
+
"rstrip": false,
|
18 |
+
"single_word": false,
|
19 |
+
"special": true
|
20 |
+
},
|
21 |
+
"2": {
|
22 |
+
"content": "</s>",
|
23 |
+
"lstrip": false,
|
24 |
+
"normalized": false,
|
25 |
+
"rstrip": true,
|
26 |
+
"single_word": false,
|
27 |
+
"special": false
|
28 |
+
},
|
29 |
+
"32000": {
|
30 |
+
"content": "<|endoftext|>",
|
31 |
+
"lstrip": false,
|
32 |
+
"normalized": false,
|
33 |
+
"rstrip": false,
|
34 |
+
"single_word": false,
|
35 |
+
"special": true
|
36 |
+
},
|
37 |
+
"32001": {
|
38 |
+
"content": "<|assistant|>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": false,
|
41 |
+
"rstrip": true,
|
42 |
+
"single_word": false,
|
43 |
+
"special": true
|
44 |
+
},
|
45 |
+
"32002": {
|
46 |
+
"content": "<|placeholder1|>",
|
47 |
+
"lstrip": false,
|
48 |
+
"normalized": false,
|
49 |
+
"rstrip": true,
|
50 |
+
"single_word": false,
|
51 |
+
"special": true
|
52 |
+
},
|
53 |
+
"32003": {
|
54 |
+
"content": "<|placeholder2|>",
|
55 |
+
"lstrip": false,
|
56 |
+
"normalized": false,
|
57 |
+
"rstrip": true,
|
58 |
+
"single_word": false,
|
59 |
+
"special": true
|
60 |
+
},
|
61 |
+
"32004": {
|
62 |
+
"content": "<|placeholder3|>",
|
63 |
+
"lstrip": false,
|
64 |
+
"normalized": false,
|
65 |
+
"rstrip": true,
|
66 |
+
"single_word": false,
|
67 |
+
"special": true
|
68 |
+
},
|
69 |
+
"32005": {
|
70 |
+
"content": "<|placeholder4|>",
|
71 |
+
"lstrip": false,
|
72 |
+
"normalized": false,
|
73 |
+
"rstrip": true,
|
74 |
+
"single_word": false,
|
75 |
+
"special": true
|
76 |
+
},
|
77 |
+
"32006": {
|
78 |
+
"content": "<|system|>",
|
79 |
+
"lstrip": false,
|
80 |
+
"normalized": false,
|
81 |
+
"rstrip": false,
|
82 |
+
"single_word": false,
|
83 |
+
"special": true
|
84 |
+
},
|
85 |
+
"32007": {
|
86 |
+
"content": "<|end|>",
|
87 |
+
"lstrip": false,
|
88 |
+
"normalized": false,
|
89 |
+
"rstrip": false,
|
90 |
+
"single_word": false,
|
91 |
+
"special": true
|
92 |
+
},
|
93 |
+
"32008": {
|
94 |
+
"content": "<|placeholder5|>",
|
95 |
+
"lstrip": false,
|
96 |
+
"normalized": false,
|
97 |
+
"rstrip": true,
|
98 |
+
"single_word": false,
|
99 |
+
"special": true
|
100 |
+
},
|
101 |
+
"32009": {
|
102 |
+
"content": "<|placeholder6|>",
|
103 |
+
"lstrip": false,
|
104 |
+
"normalized": false,
|
105 |
+
"rstrip": true,
|
106 |
+
"single_word": false,
|
107 |
+
"special": true
|
108 |
+
},
|
109 |
+
"32010": {
|
110 |
+
"content": "<|user|>",
|
111 |
+
"lstrip": false,
|
112 |
+
"normalized": false,
|
113 |
+
"rstrip": false,
|
114 |
+
"single_word": false,
|
115 |
+
"special": true
|
116 |
+
},
|
117 |
+
"32011": {
|
118 |
+
"content": "<|placeholder7|>",
|
119 |
+
"lstrip": false,
|
120 |
+
"normalized": false,
|
121 |
+
"rstrip": true,
|
122 |
+
"single_word": false,
|
123 |
+
"special": true
|
124 |
+
},
|
125 |
+
"32012": {
|
126 |
+
"content": "<|placeholder8|>",
|
127 |
+
"lstrip": false,
|
128 |
+
"normalized": false,
|
129 |
+
"rstrip": true,
|
130 |
+
"single_word": false,
|
131 |
+
"special": true
|
132 |
+
},
|
133 |
+
"32013": {
|
134 |
+
"content": "<|placeholder9|>",
|
135 |
+
"lstrip": false,
|
136 |
+
"normalized": false,
|
137 |
+
"rstrip": true,
|
138 |
+
"single_word": false,
|
139 |
+
"special": true
|
140 |
+
},
|
141 |
+
"32014": {
|
142 |
+
"content": "<|placeholder10|>",
|
143 |
+
"lstrip": false,
|
144 |
+
"normalized": false,
|
145 |
+
"rstrip": true,
|
146 |
+
"single_word": false,
|
147 |
+
"special": true
|
148 |
+
},
|
149 |
+
"32015": {
|
150 |
+
"content": "<|placeholder11|>",
|
151 |
+
"lstrip": false,
|
152 |
+
"normalized": false,
|
153 |
+
"rstrip": true,
|
154 |
+
"single_word": false,
|
155 |
+
"special": true
|
156 |
+
},
|
157 |
+
"32016": {
|
158 |
+
"content": "<|placeholder12|>",
|
159 |
+
"lstrip": false,
|
160 |
+
"normalized": false,
|
161 |
+
"rstrip": true,
|
162 |
+
"single_word": false,
|
163 |
+
"special": true
|
164 |
+
},
|
165 |
+
"32017": {
|
166 |
+
"content": "<|placeholder13|>",
|
167 |
+
"lstrip": false,
|
168 |
+
"normalized": false,
|
169 |
+
"rstrip": true,
|
170 |
+
"single_word": false,
|
171 |
+
"special": true
|
172 |
+
},
|
173 |
+
"32018": {
|
174 |
+
"content": "<|placeholder14|>",
|
175 |
+
"lstrip": false,
|
176 |
+
"normalized": false,
|
177 |
+
"rstrip": true,
|
178 |
+
"single_word": false,
|
179 |
+
"special": true
|
180 |
+
},
|
181 |
+
"32019": {
|
182 |
+
"content": "<|placeholder15|>",
|
183 |
+
"lstrip": false,
|
184 |
+
"normalized": false,
|
185 |
+
"rstrip": true,
|
186 |
+
"single_word": false,
|
187 |
+
"special": true
|
188 |
+
},
|
189 |
+
"32020": {
|
190 |
+
"content": "<|placeholder16|>",
|
191 |
+
"lstrip": false,
|
192 |
+
"normalized": false,
|
193 |
+
"rstrip": true,
|
194 |
+
"single_word": false,
|
195 |
+
"special": true
|
196 |
+
},
|
197 |
+
"32021": {
|
198 |
+
"content": "<|placeholder17|>",
|
199 |
+
"lstrip": false,
|
200 |
+
"normalized": false,
|
201 |
+
"rstrip": true,
|
202 |
+
"single_word": false,
|
203 |
+
"special": true
|
204 |
+
},
|
205 |
+
"32022": {
|
206 |
+
"content": "<|placeholder18|>",
|
207 |
+
"lstrip": false,
|
208 |
+
"normalized": false,
|
209 |
+
"rstrip": true,
|
210 |
+
"single_word": false,
|
211 |
+
"special": true
|
212 |
+
},
|
213 |
+
"32023": {
|
214 |
+
"content": "<|placeholder19|>",
|
215 |
+
"lstrip": false,
|
216 |
+
"normalized": false,
|
217 |
+
"rstrip": true,
|
218 |
+
"single_word": false,
|
219 |
+
"special": true
|
220 |
+
},
|
221 |
+
"32024": {
|
222 |
+
"content": "<|placeholder20|>",
|
223 |
+
"lstrip": false,
|
224 |
+
"normalized": false,
|
225 |
+
"rstrip": true,
|
226 |
+
"single_word": false,
|
227 |
+
"special": true
|
228 |
+
},
|
229 |
+
"32025": {
|
230 |
+
"content": "<|placeholder21|>",
|
231 |
+
"lstrip": false,
|
232 |
+
"normalized": false,
|
233 |
+
"rstrip": true,
|
234 |
+
"single_word": false,
|
235 |
+
"special": true
|
236 |
+
},
|
237 |
+
"32026": {
|
238 |
+
"content": "<|placeholder22|>",
|
239 |
+
"lstrip": false,
|
240 |
+
"normalized": false,
|
241 |
+
"rstrip": true,
|
242 |
+
"single_word": false,
|
243 |
+
"special": true
|
244 |
+
},
|
245 |
+
"32027": {
|
246 |
+
"content": "<|placeholder23|>",
|
247 |
+
"lstrip": false,
|
248 |
+
"normalized": false,
|
249 |
+
"rstrip": true,
|
250 |
+
"single_word": false,
|
251 |
+
"special": true
|
252 |
+
},
|
253 |
+
"32028": {
|
254 |
+
"content": "<|placeholder24|>",
|
255 |
+
"lstrip": false,
|
256 |
+
"normalized": false,
|
257 |
+
"rstrip": true,
|
258 |
+
"single_word": false,
|
259 |
+
"special": true
|
260 |
+
},
|
261 |
+
"32029": {
|
262 |
+
"content": "<|placeholder25|>",
|
263 |
+
"lstrip": false,
|
264 |
+
"normalized": false,
|
265 |
+
"rstrip": true,
|
266 |
+
"single_word": false,
|
267 |
+
"special": true
|
268 |
+
},
|
269 |
+
"32030": {
|
270 |
+
"content": "<|placeholder26|>",
|
271 |
+
"lstrip": false,
|
272 |
+
"normalized": false,
|
273 |
+
"rstrip": true,
|
274 |
+
"single_word": false,
|
275 |
+
"special": true
|
276 |
+
},
|
277 |
+
"32031": {
|
278 |
+
"content": "<|placeholder27|>",
|
279 |
+
"lstrip": false,
|
280 |
+
"normalized": false,
|
281 |
+
"rstrip": true,
|
282 |
+
"single_word": false,
|
283 |
+
"special": true
|
284 |
+
},
|
285 |
+
"32032": {
|
286 |
+
"content": "<|placeholder28|>",
|
287 |
+
"lstrip": false,
|
288 |
+
"normalized": false,
|
289 |
+
"rstrip": true,
|
290 |
+
"single_word": false,
|
291 |
+
"special": true
|
292 |
+
},
|
293 |
+
"32033": {
|
294 |
+
"content": "<|placeholder29|>",
|
295 |
+
"lstrip": false,
|
296 |
+
"normalized": false,
|
297 |
+
"rstrip": true,
|
298 |
+
"single_word": false,
|
299 |
+
"special": true
|
300 |
+
},
|
301 |
+
"32034": {
|
302 |
+
"content": "<|placeholder30|>",
|
303 |
+
"lstrip": false,
|
304 |
+
"normalized": false,
|
305 |
+
"rstrip": true,
|
306 |
+
"single_word": false,
|
307 |
+
"special": true
|
308 |
+
},
|
309 |
+
"32035": {
|
310 |
+
"content": "<|placeholder31|>",
|
311 |
+
"lstrip": false,
|
312 |
+
"normalized": false,
|
313 |
+
"rstrip": true,
|
314 |
+
"single_word": false,
|
315 |
+
"special": true
|
316 |
+
},
|
317 |
+
"32036": {
|
318 |
+
"content": "<|placeholder32|>",
|
319 |
+
"lstrip": false,
|
320 |
+
"normalized": false,
|
321 |
+
"rstrip": true,
|
322 |
+
"single_word": false,
|
323 |
+
"special": true
|
324 |
+
},
|
325 |
+
"32037": {
|
326 |
+
"content": "<|placeholder33|>",
|
327 |
+
"lstrip": false,
|
328 |
+
"normalized": false,
|
329 |
+
"rstrip": true,
|
330 |
+
"single_word": false,
|
331 |
+
"special": true
|
332 |
+
},
|
333 |
+
"32038": {
|
334 |
+
"content": "<|placeholder34|>",
|
335 |
+
"lstrip": false,
|
336 |
+
"normalized": false,
|
337 |
+
"rstrip": true,
|
338 |
+
"single_word": false,
|
339 |
+
"special": true
|
340 |
+
},
|
341 |
+
"32039": {
|
342 |
+
"content": "<|placeholder35|>",
|
343 |
+
"lstrip": false,
|
344 |
+
"normalized": false,
|
345 |
+
"rstrip": true,
|
346 |
+
"single_word": false,
|
347 |
+
"special": true
|
348 |
+
},
|
349 |
+
"32040": {
|
350 |
+
"content": "<|placeholder36|>",
|
351 |
+
"lstrip": false,
|
352 |
+
"normalized": false,
|
353 |
+
"rstrip": true,
|
354 |
+
"single_word": false,
|
355 |
+
"special": true
|
356 |
+
},
|
357 |
+
"32041": {
|
358 |
+
"content": "<|placeholder37|>",
|
359 |
+
"lstrip": false,
|
360 |
+
"normalized": false,
|
361 |
+
"rstrip": true,
|
362 |
+
"single_word": false,
|
363 |
+
"special": true
|
364 |
+
},
|
365 |
+
"32042": {
|
366 |
+
"content": "<|placeholder38|>",
|
367 |
+
"lstrip": false,
|
368 |
+
"normalized": false,
|
369 |
+
"rstrip": true,
|
370 |
+
"single_word": false,
|
371 |
+
"special": true
|
372 |
+
},
|
373 |
+
"32043": {
|
374 |
+
"content": "<|placeholder39|>",
|
375 |
+
"lstrip": false,
|
376 |
+
"normalized": false,
|
377 |
+
"rstrip": true,
|
378 |
+
"single_word": false,
|
379 |
+
"special": true
|
380 |
+
},
|
381 |
+
"32044": {
|
382 |
+
"content": "<|image|>",
|
383 |
+
"lstrip": false,
|
384 |
+
"normalized": false,
|
385 |
+
"rstrip": true,
|
386 |
+
"single_word": false,
|
387 |
+
"special": true
|
388 |
+
}
|
389 |
+
},
|
390 |
+
"additional_special_tokens": [
|
391 |
+
"<|system|>",
|
392 |
+
"<|end|>",
|
393 |
+
"<|user|>",
|
394 |
+
"<|end|>"
|
395 |
+
],
|
396 |
+
"auto_map": {
|
397 |
+
"AutoProcessor": "processing_phi3_v.Phi3VProcessor"
|
398 |
+
},
|
399 |
+
"bos_token": "<s>",
|
400 |
+
"chat_template": "{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}{{- '<|assistant|>\n' -}}{% endif %}",
|
401 |
+
"clean_up_tokenization_spaces": false,
|
402 |
+
"eos_token": "<|endoftext|>",
|
403 |
+
"legacy": false,
|
404 |
+
"model_max_length": 131072,
|
405 |
+
"pad_token": "<|endoftext|>",
|
406 |
+
"padding_side": "right",
|
407 |
+
"processor_class": "Phi3VProcessor",
|
408 |
+
"sp_model_kwargs": {},
|
409 |
+
"tokenizer_class": "LlamaTokenizer",
|
410 |
+
"unk_token": "<unk>",
|
411 |
+
"use_default_system_prompt": false
|
412 |
+
}
|