Text Generation
Transformers
Safetensors
imp
custom_code
Oyoy1235 commited on
Commit
5a92362
1 Parent(s): 6139a29

update Imp-v1.5-3B-phi2

Browse files
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md CHANGED
@@ -1,3 +1,97 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: text-generation
4
+ datasets:
5
+ - liuhaotian/LLaVA-Pretrain
6
+ - liuhaotian/LLaVA-Instruct-150K
7
+ ---
8
+ # 😈 Imp
9
+
10
+ > A very small man can cast a very large shadow.
11
+ >
12
+ >           ——*George R.R. Martin, A Clash of Kings*
13
+
14
+
15
+ \[Technical report (coming soon)\]  [[Demo](https://xmbot.net/imp/)\]  [[Github](https://github.com/MILVLG/imp)\]
16
+
17
+ ## Introduction
18
+
19
+ The Imp project aims to provide a family of a strong multimodal `small` language models (MSLMs). Our `Imp-v1.5-3B-Phi2` is a strong MSLM with only **3B** parameters, which is build upon a small yet powerful SLM [Phi-2 ](https://huggingface.co/microsoft/phi-2)(2.7B) and a powerful visual encoder [SigLIP ](https://huggingface.co/google/siglip-so400m-patch14-384)(0.4B), and trained on the [LLaVA-v1.5](https://github.com/haotian-liu/LLaVA) training set.
20
+
21
+ As shown in the Table below, `Imp-v1.5-3B-Phi2` significantly outperforms the counterparts of similar model sizes, and even achieves slightly better performance than the strong LLaVA-7B model on various multimodal benchmarks.
22
+
23
+ We release our model weights and provide an example below to run our model . Detailed technical report and corresponding training/evaluation code will be released soon on our [GitHub repo](https://github.com/MILVLG/imp). We will persistently improve our model and release the next versions to further improve model performance :)
24
+
25
+
26
+ ## How to use
27
+
28
+
29
+ **Install dependencies**
30
+ ```bash
31
+ pip install transformers # latest version is ok, but we recommend v4.31.0
32
+ pip install -q pillow accelerate einops
33
+ ```
34
+
35
+ You can use the following code for model inference. The format of text instruction is similar to [LLaVA](https://github.com/haotian-liu/LLaVA). A Colab page to run this example is provided [here](https://colab.research.google.com/drive/1EBYky6xIPjnlPppo2gZaiNK6gEsjXgom?usp=drive_link#scrollTo=2-VpU6QzWCVZ). Note that the example can only be run on GPUs currently.
36
+
37
+ ```Python
38
+ import torch
39
+ from transformers import AutoModelForCausalLM, AutoTokenizer
40
+ from PIL import Image
41
+
42
+ torch.set_default_device("cuda")
43
+
44
+ #Create model
45
+ model = AutoModelForCausalLM.from_pretrained(
46
+ "MILVLG/Imp-v1.5-3B-Phi2",
47
+ torch_dtype=torch.float16,
48
+ device_map="auto",
49
+ trust_remote_code=True)
50
+ tokenizer = AutoTokenizer.from_pretrained("MILVLG/Imp-v1.5-3B-Phi2", trust_remote_code=True)
51
+
52
+ #Set inputs
53
+ text = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\nWhat are the colors of the bus in the image? ASSISTANT:"
54
+ image = Image.open("images/bus.jpg")
55
+
56
+ input_ids = tokenizer(text, return_tensors='pt').input_ids
57
+ image_tensor = model.image_preprocess(image)
58
+
59
+ #Generate the answer
60
+ output_ids = model.generate(
61
+ input_ids,
62
+ max_new_tokens=100,
63
+ images=image_tensor,
64
+ use_cache=True)[0]
65
+ print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
66
+ ```
67
+
68
+ ## Model evaluation
69
+ We conduct evaluation on 9 commonly-used benchmarks, including 5 academic VQA benchmarks and 4 popular MLLM benchmarks, to compare our Imp model with LLaVA (7B) and existing MSLMs of similar model sizes.
70
+
71
+ | Models | Size | VQAv2 | GQA | SQA(IMG) | TextVQA | POPE | MME(P) | MMB |MMBCN |MM-Vet|
72
+ |:--------:|:-----:|:----:|:-------------:|:--------:|:-----:|:----:|:-------:|:-------:|:-------:|:-------:|
73
+ | [LLaVA-v1.5-lora](https://huggingface.co/liuhaotian/llava-v1.5-7b) | 7B |79.10 | 63.00| 68.40 |58.20| 86.40 | 1476.9 | 66.10 |- |30.2|
74
+ | [TinyGPT-V](https://huggingface.co/Tyrannosaurus/TinyGPT-V) | 3B | - | 33.60 | - | - | -| - | - |- |-|
75
+ | [LLaVA-Phi](https://github.com/zhuyiche/llava-phi) | 3B | 71.40 | - | 68.40 | 48.60 | 85.00 | 1335.1 | 59.80 |-|28.9|
76
+ | [MobileVLM](https://huggingface.co/mtgv/MobileVLM-3B) | 3B | - | 59.00 | 61.00 | 47.50 | 84.90 | 1288.9 | 59.60 |- |-|
77
+ | [MC-LLaVA-3b](https://huggingface.co/visheratin/MC-LLaVA-3b) | 3B | 64.24 | 49.60 | - | 38.59 | 80.59 | - | - |- |-|
78
+ | **Imp-v1.5-3B-Phi2** | 3B | **81.18** | **63.54** | **72.78**| **59.84** | **88.87**| **1446.4** | **72.94**| 46.65 |**43.3**|
79
+
80
+ ## License
81
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](https://www.apache.org/licenses/LICENSE-2.0) file for details.
82
+
83
+ ## About us
84
+ This project is maintained by the [MILVLG](https://github.com/MILVLG)@Hangzhou Dianzi University (HDU) led by Prof. Zhou Yu and Jun Yu, and is mainly developed by Zhenwei Shao and Xuecheng Ouyang. We hope our model may serve as a strong baseline to inspire future research on MSLM, as well as its derivative applications on mobile devices and robots.
85
+
86
+ ## Citation
87
+
88
+ If you use our model or refer our work in your studies, please cite:
89
+
90
+ ```bibtex
91
+ @misc{imp2024,
92
+ author = {Shao, Zhenwei and Ouyang, Xuecheng and Yu, Zhou and Yu, Jun},
93
+ title = {Imp: An Emprical Study of Multimodal Small Language Models},
94
+ year = {2024},
95
+ url = {https://huggingface.co/MILVLG/imp-v1-3b}
96
+ }
97
+ ```
added_tokens.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "\t\t": 50294,
3
+ "\t\t\t": 50293,
4
+ "\t\t\t\t": 50292,
5
+ "\t\t\t\t\t": 50291,
6
+ "\t\t\t\t\t\t": 50290,
7
+ "\t\t\t\t\t\t\t": 50289,
8
+ "\t\t\t\t\t\t\t\t": 50288,
9
+ "\t\t\t\t\t\t\t\t\t": 50287,
10
+ " ": 50286,
11
+ " ": 50285,
12
+ " ": 50284,
13
+ " ": 50283,
14
+ " ": 50282,
15
+ " ": 50281,
16
+ " ": 50280,
17
+ " ": 50279,
18
+ " ": 50278,
19
+ " ": 50277,
20
+ " ": 50276,
21
+ " ": 50275,
22
+ " ": 50274,
23
+ " ": 50273,
24
+ " ": 50272,
25
+ " ": 50271,
26
+ " ": 50270,
27
+ " ": 50269,
28
+ " ": 50268,
29
+ " ": 50267,
30
+ " ": 50266,
31
+ " ": 50265,
32
+ " ": 50264,
33
+ " ": 50263,
34
+ " ": 50262,
35
+ " ": 50261,
36
+ " ": 50260,
37
+ " ": 50259,
38
+ " ": 50258,
39
+ " ": 50257,
40
+ "</s>": 50295,
41
+ "<image>": 50296
42
+ }
config.json ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "MILVLG/Imp-v1.5-3B-Phi2",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "ImpForCausalLM"
6
+ ],
7
+ "attn_pdrop": 0.0,
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_imp.ImpConfig",
10
+ "AutoModelForCausalLM": "modeling_imp.ImpForCausalLM"
11
+ },
12
+ "embd_pdrop": 0.0,
13
+ "eos_token_id": 50295,
14
+ "flash_attn": false,
15
+ "flash_rotary": false,
16
+ "freeze_mm_mlp_adapter": false,
17
+ "fused_dense": false,
18
+ "image_aspect_ratio": "square",
19
+ "image_token": "<image>",
20
+ "image_token_index": 50296,
21
+ "img_processor": null,
22
+ "initializer_range": 0.02,
23
+ "layer_norm_epsilon": 1e-05,
24
+ "mm_hidden_size": 1152,
25
+ "mm_projector_lr": 2e-05,
26
+ "mm_projector_type": "mlp2x_gelu",
27
+ "mm_use_im_patch_token": false,
28
+ "mm_use_im_start_end": false,
29
+ "mm_vision_select_feature": "patch",
30
+ "mm_vision_select_layer": -2,
31
+ "mm_vision_tower": "google/siglip-so400m-patch14-384",
32
+ "model_type": "imp",
33
+ "n_embd": 2560,
34
+ "n_head": 32,
35
+ "n_head_kv": null,
36
+ "n_inner": null,
37
+ "n_layer": 32,
38
+ "n_positions": 3072,
39
+ "pad_token_id": 50256,
40
+ "resid_pdrop": 0.1,
41
+ "rotary_dim": 32,
42
+ "tie_word_embeddings": false,
43
+ "tokenizer_model_max_length": 3072,
44
+ "tokenizer_padding_side": "right",
45
+ "torch_dtype": "float16",
46
+ "transformers_version": "4.31.0",
47
+ "use_cache": true,
48
+ "use_mm_proj": true,
49
+ "vision_tower_config": {
50
+ "attention_dropout": 0.0,
51
+ "hidden_act": "gelu_pytorch_tanh",
52
+ "hidden_size": 1152,
53
+ "image_size": 384,
54
+ "intermediate_size": 4304,
55
+ "layer_norm_eps": 1e-06,
56
+ "model_type": "siglip_vision_model",
57
+ "num_attention_heads": 16,
58
+ "num_channels": 3,
59
+ "num_hidden_layers": 27,
60
+ "patch_size": 14
61
+ },
62
+ "vocab_size": 51200
63
+ }
configuration_imp.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) MILVLG team.
2
+ # Licensed under the Apache 2.0 license.
3
+ #
4
+ # Some code here is copied from the project Phi-2 (https://huggingface.co/microsoft/phi-2),
5
+ # SigLIP@transformers==4.37.0.dev0 (https://huggingface.co/google/siglip-so400m-patch14-384),
6
+ # and Llava (https://github.com/haotian-liu/LLaVA), and modified by
7
+ # Zhenwei Shao ([email protected]) @ MILVLG. We thank them for their great works.
8
+ #
9
+ # We keep their original copyright statements as follows, which should be inherited:
10
+ # ------------------------------- Phi-2 ---------------------------------------------
11
+ # Copyright (c) Microsoft Corporation.
12
+ # Licensed under the MIT license.
13
+ # https://huggingface.co/google/siglip-so400m-patch14-384
14
+ #
15
+ # Copyright (c) 2022, Tri Dao, [email protected].
16
+ # Licensed under the BSD 3-Clause License.
17
+ # ------------------------------- SigLIP --------------------------------------------
18
+ # Copyright 2024 Google AI and The HuggingFace Team. All rights reserved.
19
+ #
20
+ # Licensed under the Apache License, Version 2.0 (the "License");
21
+ # you may not use this file except in compliance with the License.
22
+ # You may obtain a copy of the License at
23
+ #
24
+ # http://www.apache.org/licenses/LICENSE-2.0
25
+ #
26
+ # Unless required by applicable law or agreed to in writing, software
27
+ # distributed under the License is distributed on an "AS IS" BASIS,
28
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ # See the License for the specific language governing permissions and
30
+ # limitations under the License.
31
+ # ------------------------------- Llava ---------------------------------------------
32
+ # Copyright 2023 Haotian Liu
33
+ #
34
+ # Licensed under the Apache License, Version 2.0 (the "License");
35
+ # you may not use this file except in compliance with the License.
36
+ # You may obtain a copy of the License at
37
+ #
38
+ # http://www.apache.org/licenses/LICENSE-2.0
39
+ #
40
+ # Unless required by applicable law or agreed to in writing, software
41
+ # distributed under the License is distributed on an "AS IS" BASIS,
42
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43
+ # See the License for the specific language governing permissions and
44
+ # limitations under the License.
45
+ # -----------------------------------------------------------------------------------
46
+
47
+
48
+ import os
49
+ import math
50
+ from typing import Optional, Union
51
+
52
+ from transformers import PretrainedConfig
53
+ from transformers.utils import logging
54
+
55
+ logger = logging.get_logger(__name__)
56
+
57
+
58
+ class PhiConfig(PretrainedConfig):
59
+ """Phi configuration."""
60
+
61
+ model_type = "phi-msft"
62
+ attribute_map = {
63
+ "max_position_embeddings": "n_positions",
64
+ "hidden_size": "n_embd",
65
+ "num_attention_heads": "n_head",
66
+ "num_hidden_layers": "n_layer",
67
+ }
68
+
69
+ def __init__(
70
+ self,
71
+ vocab_size: int = 50304,
72
+ n_positions: int = 2048,
73
+ n_embd: int = 1024,
74
+ n_layer: int = 20,
75
+ n_inner: Optional[int] = None,
76
+ n_head: int = 16,
77
+ n_head_kv: Optional[int] = None,
78
+ rotary_dim: Optional[int] = 32,
79
+ activation_function: Optional[str] = "gelu_new",
80
+ flash_attn: bool = False,
81
+ flash_rotary: bool = False,
82
+ fused_dense: bool = False,
83
+ attn_pdrop: float = 0.0,
84
+ embd_pdrop: float = 0.0,
85
+ resid_pdrop: float = 0.0,
86
+ layer_norm_epsilon: float = 1e-5,
87
+ initializer_range: float = 0.02,
88
+ tie_word_embeddings: bool = False,
89
+ pad_vocab_size_multiple: int = 64,
90
+ **kwargs
91
+ ) -> None:
92
+ self.vocab_size = int(math.ceil(vocab_size / pad_vocab_size_multiple) * pad_vocab_size_multiple)
93
+ self.n_positions = n_positions
94
+ self.n_embd = n_embd
95
+ self.n_layer = n_layer
96
+ self.n_inner = n_inner
97
+ self.n_head = n_head
98
+ self.n_head_kv = n_head_kv
99
+ self.rotary_dim = min(rotary_dim, n_embd // n_head)
100
+ self.activation_function = activation_function
101
+ self.flash_attn = flash_attn
102
+ self.flash_rotary = flash_rotary
103
+ self.fused_dense = fused_dense
104
+ self.attn_pdrop = attn_pdrop
105
+ self.embd_pdrop = embd_pdrop
106
+ self.resid_pdrop = resid_pdrop
107
+ self.layer_norm_epsilon = layer_norm_epsilon
108
+ self.initializer_range = initializer_range
109
+
110
+ super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)
111
+
112
+
113
+
114
+ class SiglipVisionConfig(PretrainedConfig):
115
+
116
+ model_type = "siglip_vision_model"
117
+
118
+ def __init__(
119
+ self,
120
+ hidden_size=768,
121
+ intermediate_size=3072,
122
+ num_hidden_layers=12,
123
+ num_attention_heads=12,
124
+ num_channels=3,
125
+ image_size=224,
126
+ patch_size=16,
127
+ hidden_act="gelu_pytorch_tanh",
128
+ layer_norm_eps=1e-6,
129
+ attention_dropout=0.0,
130
+ **kwargs,
131
+ ):
132
+ super().__init__(**kwargs)
133
+
134
+ self.hidden_size = hidden_size
135
+ self.intermediate_size = intermediate_size
136
+ self.num_hidden_layers = num_hidden_layers
137
+ self.num_attention_heads = num_attention_heads
138
+ self.num_channels = num_channels
139
+ self.patch_size = patch_size
140
+ self.image_size = image_size
141
+ self.attention_dropout = attention_dropout
142
+ self.layer_norm_eps = layer_norm_eps
143
+ self.hidden_act = hidden_act
144
+
145
+ @classmethod
146
+ def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
147
+ cls._set_token_in_kwargs(kwargs)
148
+
149
+ config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
150
+
151
+ # get the vision config dict if we are loading from SiglipConfig
152
+ if config_dict.get("model_type") == "siglip":
153
+ config_dict = config_dict["vision_config"]
154
+
155
+ if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
156
+ logger.warning(
157
+ f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
158
+ f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
159
+ )
160
+
161
+ return cls.from_dict(config_dict, **kwargs)
162
+
163
+
164
+ class ImpConfig(PhiConfig):
165
+ model_type = "imp"
166
+
167
+ def __init__(self, **kwargs):
168
+ super().__init__(**kwargs)
169
+ self.image_token_index = getattr(self, "image_token_index", 50296)
170
+ self.image_token = getattr(self, "image_token", "<image>")
171
+
172
+ if not hasattr(self, "vision_tower_config") and hasattr(self, "mm_vision_tower"):
173
+ vision_tower_config = SiglipVisionConfig.from_pretrained(self.mm_vision_tower)
174
+ self.vision_tower_config = vision_tower_config.to_diff_dict()
175
+
176
+ @property
177
+ def vision_tower_cfg(self):
178
+ cfg = SiglipVisionConfig.from_dict(self.vision_tower_config)
179
+ # imp-v1 only supports `patch` feature for now w/o cls token
180
+ # cfg.mm_vision_select_feature = self.mm_vision_select_feature
181
+ cfg.mm_vision_select_layer = self.mm_vision_select_layer
182
+ cfg.mm_vision_tower = self.mm_vision_tower
183
+ return cfg
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "eos_token_id":50295,
3
+ "pad_token_id":50256,
4
+ "_from_model_config": true,
5
+ "transformers_version": "4.31.0"
6
+ }
images/bird.jpg ADDED
images/bus.jpg ADDED
images/car.jpg ADDED
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29f0e0859601ec012c410dc6471b8965c5d3d16875f84fa095782487cb83113f
3
+ size 996428776
model-00002-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:beda1bcee40de85570fd28e37eef166276cbe7fbf0835579f8f847e12494968a
3
+ size 996507088
model-00003-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20f3b15038f8d7191a99835d3e21aa63927a9361ad35e6c778a63b3136830b82
3
+ size 996512312
model-00004-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28422cb2f997225cf1a3a1771cb37e3b49e41c0312b989f98096fd9b4a31338a
3
+ size 996512088
model-00005-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c672e017ca169da27170ab02267b9a9deedb2e3b240fc6cefdc734aa6e262a13
3
+ size 996507152
model-00006-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa13bd6005ccb00d73a495f1c0d06009dbf0891ccaf659cca28af3a59a4e1722
3
+ size 1021447256
model-00007-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7bc6ecad02a265ac62054118b43c5485b769f398963da4c9f73d2ece152fb027
3
+ size 370061024
model.safetensors.index.json ADDED
@@ -0,0 +1,755 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 6373874240
4
+ },
5
+ "weight_map": {
6
+ "lm_head.linear.bias": "model-00007-of-00007.safetensors",
7
+ "lm_head.linear.weight": "model-00007-of-00007.safetensors",
8
+ "lm_head.ln.bias": "model-00007-of-00007.safetensors",
9
+ "lm_head.ln.weight": "model-00007-of-00007.safetensors",
10
+ "transformer.embd.wte.weight": "model-00001-of-00007.safetensors",
11
+ "transformer.h.0.ln.bias": "model-00001-of-00007.safetensors",
12
+ "transformer.h.0.ln.weight": "model-00001-of-00007.safetensors",
13
+ "transformer.h.0.mixer.Wqkv.bias": "model-00001-of-00007.safetensors",
14
+ "transformer.h.0.mixer.Wqkv.weight": "model-00001-of-00007.safetensors",
15
+ "transformer.h.0.mixer.out_proj.bias": "model-00001-of-00007.safetensors",
16
+ "transformer.h.0.mixer.out_proj.weight": "model-00001-of-00007.safetensors",
17
+ "transformer.h.0.mlp.fc1.bias": "model-00001-of-00007.safetensors",
18
+ "transformer.h.0.mlp.fc1.weight": "model-00001-of-00007.safetensors",
19
+ "transformer.h.0.mlp.fc2.bias": "model-00001-of-00007.safetensors",
20
+ "transformer.h.0.mlp.fc2.weight": "model-00001-of-00007.safetensors",
21
+ "transformer.h.1.ln.bias": "model-00001-of-00007.safetensors",
22
+ "transformer.h.1.ln.weight": "model-00001-of-00007.safetensors",
23
+ "transformer.h.1.mixer.Wqkv.bias": "model-00001-of-00007.safetensors",
24
+ "transformer.h.1.mixer.Wqkv.weight": "model-00001-of-00007.safetensors",
25
+ "transformer.h.1.mixer.out_proj.bias": "model-00001-of-00007.safetensors",
26
+ "transformer.h.1.mixer.out_proj.weight": "model-00001-of-00007.safetensors",
27
+ "transformer.h.1.mlp.fc1.bias": "model-00001-of-00007.safetensors",
28
+ "transformer.h.1.mlp.fc1.weight": "model-00001-of-00007.safetensors",
29
+ "transformer.h.1.mlp.fc2.bias": "model-00001-of-00007.safetensors",
30
+ "transformer.h.1.mlp.fc2.weight": "model-00001-of-00007.safetensors",
31
+ "transformer.h.10.ln.bias": "model-00002-of-00007.safetensors",
32
+ "transformer.h.10.ln.weight": "model-00002-of-00007.safetensors",
33
+ "transformer.h.10.mixer.Wqkv.bias": "model-00002-of-00007.safetensors",
34
+ "transformer.h.10.mixer.Wqkv.weight": "model-00002-of-00007.safetensors",
35
+ "transformer.h.10.mixer.out_proj.bias": "model-00002-of-00007.safetensors",
36
+ "transformer.h.10.mixer.out_proj.weight": "model-00002-of-00007.safetensors",
37
+ "transformer.h.10.mlp.fc1.bias": "model-00002-of-00007.safetensors",
38
+ "transformer.h.10.mlp.fc1.weight": "model-00002-of-00007.safetensors",
39
+ "transformer.h.10.mlp.fc2.bias": "model-00002-of-00007.safetensors",
40
+ "transformer.h.10.mlp.fc2.weight": "model-00002-of-00007.safetensors",
41
+ "transformer.h.11.ln.bias": "model-00002-of-00007.safetensors",
42
+ "transformer.h.11.ln.weight": "model-00002-of-00007.safetensors",
43
+ "transformer.h.11.mixer.Wqkv.bias": "model-00003-of-00007.safetensors",
44
+ "transformer.h.11.mixer.Wqkv.weight": "model-00003-of-00007.safetensors",
45
+ "transformer.h.11.mixer.out_proj.bias": "model-00003-of-00007.safetensors",
46
+ "transformer.h.11.mixer.out_proj.weight": "model-00003-of-00007.safetensors",
47
+ "transformer.h.11.mlp.fc1.bias": "model-00003-of-00007.safetensors",
48
+ "transformer.h.11.mlp.fc1.weight": "model-00003-of-00007.safetensors",
49
+ "transformer.h.11.mlp.fc2.bias": "model-00003-of-00007.safetensors",
50
+ "transformer.h.11.mlp.fc2.weight": "model-00003-of-00007.safetensors",
51
+ "transformer.h.12.ln.bias": "model-00003-of-00007.safetensors",
52
+ "transformer.h.12.ln.weight": "model-00003-of-00007.safetensors",
53
+ "transformer.h.12.mixer.Wqkv.bias": "model-00003-of-00007.safetensors",
54
+ "transformer.h.12.mixer.Wqkv.weight": "model-00003-of-00007.safetensors",
55
+ "transformer.h.12.mixer.out_proj.bias": "model-00003-of-00007.safetensors",
56
+ "transformer.h.12.mixer.out_proj.weight": "model-00003-of-00007.safetensors",
57
+ "transformer.h.12.mlp.fc1.bias": "model-00003-of-00007.safetensors",
58
+ "transformer.h.12.mlp.fc1.weight": "model-00003-of-00007.safetensors",
59
+ "transformer.h.12.mlp.fc2.bias": "model-00003-of-00007.safetensors",
60
+ "transformer.h.12.mlp.fc2.weight": "model-00003-of-00007.safetensors",
61
+ "transformer.h.13.ln.bias": "model-00003-of-00007.safetensors",
62
+ "transformer.h.13.ln.weight": "model-00003-of-00007.safetensors",
63
+ "transformer.h.13.mixer.Wqkv.bias": "model-00003-of-00007.safetensors",
64
+ "transformer.h.13.mixer.Wqkv.weight": "model-00003-of-00007.safetensors",
65
+ "transformer.h.13.mixer.out_proj.bias": "model-00003-of-00007.safetensors",
66
+ "transformer.h.13.mixer.out_proj.weight": "model-00003-of-00007.safetensors",
67
+ "transformer.h.13.mlp.fc1.bias": "model-00003-of-00007.safetensors",
68
+ "transformer.h.13.mlp.fc1.weight": "model-00003-of-00007.safetensors",
69
+ "transformer.h.13.mlp.fc2.bias": "model-00003-of-00007.safetensors",
70
+ "transformer.h.13.mlp.fc2.weight": "model-00003-of-00007.safetensors",
71
+ "transformer.h.14.ln.bias": "model-00003-of-00007.safetensors",
72
+ "transformer.h.14.ln.weight": "model-00003-of-00007.safetensors",
73
+ "transformer.h.14.mixer.Wqkv.bias": "model-00003-of-00007.safetensors",
74
+ "transformer.h.14.mixer.Wqkv.weight": "model-00003-of-00007.safetensors",
75
+ "transformer.h.14.mixer.out_proj.bias": "model-00003-of-00007.safetensors",
76
+ "transformer.h.14.mixer.out_proj.weight": "model-00003-of-00007.safetensors",
77
+ "transformer.h.14.mlp.fc1.bias": "model-00003-of-00007.safetensors",
78
+ "transformer.h.14.mlp.fc1.weight": "model-00003-of-00007.safetensors",
79
+ "transformer.h.14.mlp.fc2.bias": "model-00003-of-00007.safetensors",
80
+ "transformer.h.14.mlp.fc2.weight": "model-00003-of-00007.safetensors",
81
+ "transformer.h.15.ln.bias": "model-00003-of-00007.safetensors",
82
+ "transformer.h.15.ln.weight": "model-00003-of-00007.safetensors",
83
+ "transformer.h.15.mixer.Wqkv.bias": "model-00003-of-00007.safetensors",
84
+ "transformer.h.15.mixer.Wqkv.weight": "model-00003-of-00007.safetensors",
85
+ "transformer.h.15.mixer.out_proj.bias": "model-00003-of-00007.safetensors",
86
+ "transformer.h.15.mixer.out_proj.weight": "model-00003-of-00007.safetensors",
87
+ "transformer.h.15.mlp.fc1.bias": "model-00003-of-00007.safetensors",
88
+ "transformer.h.15.mlp.fc1.weight": "model-00003-of-00007.safetensors",
89
+ "transformer.h.15.mlp.fc2.bias": "model-00003-of-00007.safetensors",
90
+ "transformer.h.15.mlp.fc2.weight": "model-00003-of-00007.safetensors",
91
+ "transformer.h.16.ln.bias": "model-00003-of-00007.safetensors",
92
+ "transformer.h.16.ln.weight": "model-00003-of-00007.safetensors",
93
+ "transformer.h.16.mixer.Wqkv.bias": "model-00003-of-00007.safetensors",
94
+ "transformer.h.16.mixer.Wqkv.weight": "model-00003-of-00007.safetensors",
95
+ "transformer.h.16.mixer.out_proj.bias": "model-00003-of-00007.safetensors",
96
+ "transformer.h.16.mixer.out_proj.weight": "model-00003-of-00007.safetensors",
97
+ "transformer.h.16.mlp.fc1.bias": "model-00003-of-00007.safetensors",
98
+ "transformer.h.16.mlp.fc1.weight": "model-00003-of-00007.safetensors",
99
+ "transformer.h.16.mlp.fc2.bias": "model-00003-of-00007.safetensors",
100
+ "transformer.h.16.mlp.fc2.weight": "model-00003-of-00007.safetensors",
101
+ "transformer.h.17.ln.bias": "model-00003-of-00007.safetensors",
102
+ "transformer.h.17.ln.weight": "model-00003-of-00007.safetensors",
103
+ "transformer.h.17.mixer.Wqkv.bias": "model-00003-of-00007.safetensors",
104
+ "transformer.h.17.mixer.Wqkv.weight": "model-00003-of-00007.safetensors",
105
+ "transformer.h.17.mixer.out_proj.bias": "model-00003-of-00007.safetensors",
106
+ "transformer.h.17.mixer.out_proj.weight": "model-00003-of-00007.safetensors",
107
+ "transformer.h.17.mlp.fc1.bias": "model-00004-of-00007.safetensors",
108
+ "transformer.h.17.mlp.fc1.weight": "model-00004-of-00007.safetensors",
109
+ "transformer.h.17.mlp.fc2.bias": "model-00004-of-00007.safetensors",
110
+ "transformer.h.17.mlp.fc2.weight": "model-00004-of-00007.safetensors",
111
+ "transformer.h.18.ln.bias": "model-00004-of-00007.safetensors",
112
+ "transformer.h.18.ln.weight": "model-00004-of-00007.safetensors",
113
+ "transformer.h.18.mixer.Wqkv.bias": "model-00004-of-00007.safetensors",
114
+ "transformer.h.18.mixer.Wqkv.weight": "model-00004-of-00007.safetensors",
115
+ "transformer.h.18.mixer.out_proj.bias": "model-00004-of-00007.safetensors",
116
+ "transformer.h.18.mixer.out_proj.weight": "model-00004-of-00007.safetensors",
117
+ "transformer.h.18.mlp.fc1.bias": "model-00004-of-00007.safetensors",
118
+ "transformer.h.18.mlp.fc1.weight": "model-00004-of-00007.safetensors",
119
+ "transformer.h.18.mlp.fc2.bias": "model-00004-of-00007.safetensors",
120
+ "transformer.h.18.mlp.fc2.weight": "model-00004-of-00007.safetensors",
121
+ "transformer.h.19.ln.bias": "model-00004-of-00007.safetensors",
122
+ "transformer.h.19.ln.weight": "model-00004-of-00007.safetensors",
123
+ "transformer.h.19.mixer.Wqkv.bias": "model-00004-of-00007.safetensors",
124
+ "transformer.h.19.mixer.Wqkv.weight": "model-00004-of-00007.safetensors",
125
+ "transformer.h.19.mixer.out_proj.bias": "model-00004-of-00007.safetensors",
126
+ "transformer.h.19.mixer.out_proj.weight": "model-00004-of-00007.safetensors",
127
+ "transformer.h.19.mlp.fc1.bias": "model-00004-of-00007.safetensors",
128
+ "transformer.h.19.mlp.fc1.weight": "model-00004-of-00007.safetensors",
129
+ "transformer.h.19.mlp.fc2.bias": "model-00004-of-00007.safetensors",
130
+ "transformer.h.19.mlp.fc2.weight": "model-00004-of-00007.safetensors",
131
+ "transformer.h.2.ln.bias": "model-00001-of-00007.safetensors",
132
+ "transformer.h.2.ln.weight": "model-00001-of-00007.safetensors",
133
+ "transformer.h.2.mixer.Wqkv.bias": "model-00001-of-00007.safetensors",
134
+ "transformer.h.2.mixer.Wqkv.weight": "model-00001-of-00007.safetensors",
135
+ "transformer.h.2.mixer.out_proj.bias": "model-00001-of-00007.safetensors",
136
+ "transformer.h.2.mixer.out_proj.weight": "model-00001-of-00007.safetensors",
137
+ "transformer.h.2.mlp.fc1.bias": "model-00001-of-00007.safetensors",
138
+ "transformer.h.2.mlp.fc1.weight": "model-00001-of-00007.safetensors",
139
+ "transformer.h.2.mlp.fc2.bias": "model-00001-of-00007.safetensors",
140
+ "transformer.h.2.mlp.fc2.weight": "model-00001-of-00007.safetensors",
141
+ "transformer.h.20.ln.bias": "model-00004-of-00007.safetensors",
142
+ "transformer.h.20.ln.weight": "model-00004-of-00007.safetensors",
143
+ "transformer.h.20.mixer.Wqkv.bias": "model-00004-of-00007.safetensors",
144
+ "transformer.h.20.mixer.Wqkv.weight": "model-00004-of-00007.safetensors",
145
+ "transformer.h.20.mixer.out_proj.bias": "model-00004-of-00007.safetensors",
146
+ "transformer.h.20.mixer.out_proj.weight": "model-00004-of-00007.safetensors",
147
+ "transformer.h.20.mlp.fc1.bias": "model-00004-of-00007.safetensors",
148
+ "transformer.h.20.mlp.fc1.weight": "model-00004-of-00007.safetensors",
149
+ "transformer.h.20.mlp.fc2.bias": "model-00004-of-00007.safetensors",
150
+ "transformer.h.20.mlp.fc2.weight": "model-00004-of-00007.safetensors",
151
+ "transformer.h.21.ln.bias": "model-00004-of-00007.safetensors",
152
+ "transformer.h.21.ln.weight": "model-00004-of-00007.safetensors",
153
+ "transformer.h.21.mixer.Wqkv.bias": "model-00004-of-00007.safetensors",
154
+ "transformer.h.21.mixer.Wqkv.weight": "model-00004-of-00007.safetensors",
155
+ "transformer.h.21.mixer.out_proj.bias": "model-00004-of-00007.safetensors",
156
+ "transformer.h.21.mixer.out_proj.weight": "model-00004-of-00007.safetensors",
157
+ "transformer.h.21.mlp.fc1.bias": "model-00004-of-00007.safetensors",
158
+ "transformer.h.21.mlp.fc1.weight": "model-00004-of-00007.safetensors",
159
+ "transformer.h.21.mlp.fc2.bias": "model-00004-of-00007.safetensors",
160
+ "transformer.h.21.mlp.fc2.weight": "model-00004-of-00007.safetensors",
161
+ "transformer.h.22.ln.bias": "model-00004-of-00007.safetensors",
162
+ "transformer.h.22.ln.weight": "model-00004-of-00007.safetensors",
163
+ "transformer.h.22.mixer.Wqkv.bias": "model-00004-of-00007.safetensors",
164
+ "transformer.h.22.mixer.Wqkv.weight": "model-00004-of-00007.safetensors",
165
+ "transformer.h.22.mixer.out_proj.bias": "model-00004-of-00007.safetensors",
166
+ "transformer.h.22.mixer.out_proj.weight": "model-00004-of-00007.safetensors",
167
+ "transformer.h.22.mlp.fc1.bias": "model-00004-of-00007.safetensors",
168
+ "transformer.h.22.mlp.fc1.weight": "model-00004-of-00007.safetensors",
169
+ "transformer.h.22.mlp.fc2.bias": "model-00004-of-00007.safetensors",
170
+ "transformer.h.22.mlp.fc2.weight": "model-00004-of-00007.safetensors",
171
+ "transformer.h.23.ln.bias": "model-00004-of-00007.safetensors",
172
+ "transformer.h.23.ln.weight": "model-00004-of-00007.safetensors",
173
+ "transformer.h.23.mixer.Wqkv.bias": "model-00004-of-00007.safetensors",
174
+ "transformer.h.23.mixer.Wqkv.weight": "model-00004-of-00007.safetensors",
175
+ "transformer.h.23.mixer.out_proj.bias": "model-00004-of-00007.safetensors",
176
+ "transformer.h.23.mixer.out_proj.weight": "model-00004-of-00007.safetensors",
177
+ "transformer.h.23.mlp.fc1.bias": "model-00004-of-00007.safetensors",
178
+ "transformer.h.23.mlp.fc1.weight": "model-00004-of-00007.safetensors",
179
+ "transformer.h.23.mlp.fc2.bias": "model-00005-of-00007.safetensors",
180
+ "transformer.h.23.mlp.fc2.weight": "model-00005-of-00007.safetensors",
181
+ "transformer.h.24.ln.bias": "model-00005-of-00007.safetensors",
182
+ "transformer.h.24.ln.weight": "model-00005-of-00007.safetensors",
183
+ "transformer.h.24.mixer.Wqkv.bias": "model-00005-of-00007.safetensors",
184
+ "transformer.h.24.mixer.Wqkv.weight": "model-00005-of-00007.safetensors",
185
+ "transformer.h.24.mixer.out_proj.bias": "model-00005-of-00007.safetensors",
186
+ "transformer.h.24.mixer.out_proj.weight": "model-00005-of-00007.safetensors",
187
+ "transformer.h.24.mlp.fc1.bias": "model-00005-of-00007.safetensors",
188
+ "transformer.h.24.mlp.fc1.weight": "model-00005-of-00007.safetensors",
189
+ "transformer.h.24.mlp.fc2.bias": "model-00005-of-00007.safetensors",
190
+ "transformer.h.24.mlp.fc2.weight": "model-00005-of-00007.safetensors",
191
+ "transformer.h.25.ln.bias": "model-00005-of-00007.safetensors",
192
+ "transformer.h.25.ln.weight": "model-00005-of-00007.safetensors",
193
+ "transformer.h.25.mixer.Wqkv.bias": "model-00005-of-00007.safetensors",
194
+ "transformer.h.25.mixer.Wqkv.weight": "model-00005-of-00007.safetensors",
195
+ "transformer.h.25.mixer.out_proj.bias": "model-00005-of-00007.safetensors",
196
+ "transformer.h.25.mixer.out_proj.weight": "model-00005-of-00007.safetensors",
197
+ "transformer.h.25.mlp.fc1.bias": "model-00005-of-00007.safetensors",
198
+ "transformer.h.25.mlp.fc1.weight": "model-00005-of-00007.safetensors",
199
+ "transformer.h.25.mlp.fc2.bias": "model-00005-of-00007.safetensors",
200
+ "transformer.h.25.mlp.fc2.weight": "model-00005-of-00007.safetensors",
201
+ "transformer.h.26.ln.bias": "model-00005-of-00007.safetensors",
202
+ "transformer.h.26.ln.weight": "model-00005-of-00007.safetensors",
203
+ "transformer.h.26.mixer.Wqkv.bias": "model-00005-of-00007.safetensors",
204
+ "transformer.h.26.mixer.Wqkv.weight": "model-00005-of-00007.safetensors",
205
+ "transformer.h.26.mixer.out_proj.bias": "model-00005-of-00007.safetensors",
206
+ "transformer.h.26.mixer.out_proj.weight": "model-00005-of-00007.safetensors",
207
+ "transformer.h.26.mlp.fc1.bias": "model-00005-of-00007.safetensors",
208
+ "transformer.h.26.mlp.fc1.weight": "model-00005-of-00007.safetensors",
209
+ "transformer.h.26.mlp.fc2.bias": "model-00005-of-00007.safetensors",
210
+ "transformer.h.26.mlp.fc2.weight": "model-00005-of-00007.safetensors",
211
+ "transformer.h.27.ln.bias": "model-00005-of-00007.safetensors",
212
+ "transformer.h.27.ln.weight": "model-00005-of-00007.safetensors",
213
+ "transformer.h.27.mixer.Wqkv.bias": "model-00005-of-00007.safetensors",
214
+ "transformer.h.27.mixer.Wqkv.weight": "model-00005-of-00007.safetensors",
215
+ "transformer.h.27.mixer.out_proj.bias": "model-00005-of-00007.safetensors",
216
+ "transformer.h.27.mixer.out_proj.weight": "model-00005-of-00007.safetensors",
217
+ "transformer.h.27.mlp.fc1.bias": "model-00005-of-00007.safetensors",
218
+ "transformer.h.27.mlp.fc1.weight": "model-00005-of-00007.safetensors",
219
+ "transformer.h.27.mlp.fc2.bias": "model-00005-of-00007.safetensors",
220
+ "transformer.h.27.mlp.fc2.weight": "model-00005-of-00007.safetensors",
221
+ "transformer.h.28.ln.bias": "model-00005-of-00007.safetensors",
222
+ "transformer.h.28.ln.weight": "model-00005-of-00007.safetensors",
223
+ "transformer.h.28.mixer.Wqkv.bias": "model-00005-of-00007.safetensors",
224
+ "transformer.h.28.mixer.Wqkv.weight": "model-00005-of-00007.safetensors",
225
+ "transformer.h.28.mixer.out_proj.bias": "model-00005-of-00007.safetensors",
226
+ "transformer.h.28.mixer.out_proj.weight": "model-00005-of-00007.safetensors",
227
+ "transformer.h.28.mlp.fc1.bias": "model-00005-of-00007.safetensors",
228
+ "transformer.h.28.mlp.fc1.weight": "model-00005-of-00007.safetensors",
229
+ "transformer.h.28.mlp.fc2.bias": "model-00005-of-00007.safetensors",
230
+ "transformer.h.28.mlp.fc2.weight": "model-00005-of-00007.safetensors",
231
+ "transformer.h.29.ln.bias": "model-00005-of-00007.safetensors",
232
+ "transformer.h.29.ln.weight": "model-00005-of-00007.safetensors",
233
+ "transformer.h.29.mixer.Wqkv.bias": "model-00005-of-00007.safetensors",
234
+ "transformer.h.29.mixer.Wqkv.weight": "model-00005-of-00007.safetensors",
235
+ "transformer.h.29.mixer.out_proj.bias": "model-00005-of-00007.safetensors",
236
+ "transformer.h.29.mixer.out_proj.weight": "model-00005-of-00007.safetensors",
237
+ "transformer.h.29.mlp.fc1.bias": "model-00005-of-00007.safetensors",
238
+ "transformer.h.29.mlp.fc1.weight": "model-00005-of-00007.safetensors",
239
+ "transformer.h.29.mlp.fc2.bias": "model-00005-of-00007.safetensors",
240
+ "transformer.h.29.mlp.fc2.weight": "model-00005-of-00007.safetensors",
241
+ "transformer.h.3.ln.bias": "model-00001-of-00007.safetensors",
242
+ "transformer.h.3.ln.weight": "model-00001-of-00007.safetensors",
243
+ "transformer.h.3.mixer.Wqkv.bias": "model-00001-of-00007.safetensors",
244
+ "transformer.h.3.mixer.Wqkv.weight": "model-00001-of-00007.safetensors",
245
+ "transformer.h.3.mixer.out_proj.bias": "model-00001-of-00007.safetensors",
246
+ "transformer.h.3.mixer.out_proj.weight": "model-00001-of-00007.safetensors",
247
+ "transformer.h.3.mlp.fc1.bias": "model-00001-of-00007.safetensors",
248
+ "transformer.h.3.mlp.fc1.weight": "model-00001-of-00007.safetensors",
249
+ "transformer.h.3.mlp.fc2.bias": "model-00001-of-00007.safetensors",
250
+ "transformer.h.3.mlp.fc2.weight": "model-00001-of-00007.safetensors",
251
+ "transformer.h.30.ln.bias": "model-00005-of-00007.safetensors",
252
+ "transformer.h.30.ln.weight": "model-00005-of-00007.safetensors",
253
+ "transformer.h.30.mixer.Wqkv.bias": "model-00006-of-00007.safetensors",
254
+ "transformer.h.30.mixer.Wqkv.weight": "model-00006-of-00007.safetensors",
255
+ "transformer.h.30.mixer.out_proj.bias": "model-00006-of-00007.safetensors",
256
+ "transformer.h.30.mixer.out_proj.weight": "model-00006-of-00007.safetensors",
257
+ "transformer.h.30.mlp.fc1.bias": "model-00006-of-00007.safetensors",
258
+ "transformer.h.30.mlp.fc1.weight": "model-00006-of-00007.safetensors",
259
+ "transformer.h.30.mlp.fc2.bias": "model-00006-of-00007.safetensors",
260
+ "transformer.h.30.mlp.fc2.weight": "model-00006-of-00007.safetensors",
261
+ "transformer.h.31.ln.bias": "model-00006-of-00007.safetensors",
262
+ "transformer.h.31.ln.weight": "model-00006-of-00007.safetensors",
263
+ "transformer.h.31.mixer.Wqkv.bias": "model-00006-of-00007.safetensors",
264
+ "transformer.h.31.mixer.Wqkv.weight": "model-00006-of-00007.safetensors",
265
+ "transformer.h.31.mixer.out_proj.bias": "model-00006-of-00007.safetensors",
266
+ "transformer.h.31.mixer.out_proj.weight": "model-00006-of-00007.safetensors",
267
+ "transformer.h.31.mlp.fc1.bias": "model-00006-of-00007.safetensors",
268
+ "transformer.h.31.mlp.fc1.weight": "model-00006-of-00007.safetensors",
269
+ "transformer.h.31.mlp.fc2.bias": "model-00006-of-00007.safetensors",
270
+ "transformer.h.31.mlp.fc2.weight": "model-00006-of-00007.safetensors",
271
+ "transformer.h.4.ln.bias": "model-00001-of-00007.safetensors",
272
+ "transformer.h.4.ln.weight": "model-00001-of-00007.safetensors",
273
+ "transformer.h.4.mixer.Wqkv.bias": "model-00001-of-00007.safetensors",
274
+ "transformer.h.4.mixer.Wqkv.weight": "model-00001-of-00007.safetensors",
275
+ "transformer.h.4.mixer.out_proj.bias": "model-00001-of-00007.safetensors",
276
+ "transformer.h.4.mixer.out_proj.weight": "model-00001-of-00007.safetensors",
277
+ "transformer.h.4.mlp.fc1.bias": "model-00001-of-00007.safetensors",
278
+ "transformer.h.4.mlp.fc1.weight": "model-00001-of-00007.safetensors",
279
+ "transformer.h.4.mlp.fc2.bias": "model-00002-of-00007.safetensors",
280
+ "transformer.h.4.mlp.fc2.weight": "model-00002-of-00007.safetensors",
281
+ "transformer.h.5.ln.bias": "model-00002-of-00007.safetensors",
282
+ "transformer.h.5.ln.weight": "model-00002-of-00007.safetensors",
283
+ "transformer.h.5.mixer.Wqkv.bias": "model-00002-of-00007.safetensors",
284
+ "transformer.h.5.mixer.Wqkv.weight": "model-00002-of-00007.safetensors",
285
+ "transformer.h.5.mixer.out_proj.bias": "model-00002-of-00007.safetensors",
286
+ "transformer.h.5.mixer.out_proj.weight": "model-00002-of-00007.safetensors",
287
+ "transformer.h.5.mlp.fc1.bias": "model-00002-of-00007.safetensors",
288
+ "transformer.h.5.mlp.fc1.weight": "model-00002-of-00007.safetensors",
289
+ "transformer.h.5.mlp.fc2.bias": "model-00002-of-00007.safetensors",
290
+ "transformer.h.5.mlp.fc2.weight": "model-00002-of-00007.safetensors",
291
+ "transformer.h.6.ln.bias": "model-00002-of-00007.safetensors",
292
+ "transformer.h.6.ln.weight": "model-00002-of-00007.safetensors",
293
+ "transformer.h.6.mixer.Wqkv.bias": "model-00002-of-00007.safetensors",
294
+ "transformer.h.6.mixer.Wqkv.weight": "model-00002-of-00007.safetensors",
295
+ "transformer.h.6.mixer.out_proj.bias": "model-00002-of-00007.safetensors",
296
+ "transformer.h.6.mixer.out_proj.weight": "model-00002-of-00007.safetensors",
297
+ "transformer.h.6.mlp.fc1.bias": "model-00002-of-00007.safetensors",
298
+ "transformer.h.6.mlp.fc1.weight": "model-00002-of-00007.safetensors",
299
+ "transformer.h.6.mlp.fc2.bias": "model-00002-of-00007.safetensors",
300
+ "transformer.h.6.mlp.fc2.weight": "model-00002-of-00007.safetensors",
301
+ "transformer.h.7.ln.bias": "model-00002-of-00007.safetensors",
302
+ "transformer.h.7.ln.weight": "model-00002-of-00007.safetensors",
303
+ "transformer.h.7.mixer.Wqkv.bias": "model-00002-of-00007.safetensors",
304
+ "transformer.h.7.mixer.Wqkv.weight": "model-00002-of-00007.safetensors",
305
+ "transformer.h.7.mixer.out_proj.bias": "model-00002-of-00007.safetensors",
306
+ "transformer.h.7.mixer.out_proj.weight": "model-00002-of-00007.safetensors",
307
+ "transformer.h.7.mlp.fc1.bias": "model-00002-of-00007.safetensors",
308
+ "transformer.h.7.mlp.fc1.weight": "model-00002-of-00007.safetensors",
309
+ "transformer.h.7.mlp.fc2.bias": "model-00002-of-00007.safetensors",
310
+ "transformer.h.7.mlp.fc2.weight": "model-00002-of-00007.safetensors",
311
+ "transformer.h.8.ln.bias": "model-00002-of-00007.safetensors",
312
+ "transformer.h.8.ln.weight": "model-00002-of-00007.safetensors",
313
+ "transformer.h.8.mixer.Wqkv.bias": "model-00002-of-00007.safetensors",
314
+ "transformer.h.8.mixer.Wqkv.weight": "model-00002-of-00007.safetensors",
315
+ "transformer.h.8.mixer.out_proj.bias": "model-00002-of-00007.safetensors",
316
+ "transformer.h.8.mixer.out_proj.weight": "model-00002-of-00007.safetensors",
317
+ "transformer.h.8.mlp.fc1.bias": "model-00002-of-00007.safetensors",
318
+ "transformer.h.8.mlp.fc1.weight": "model-00002-of-00007.safetensors",
319
+ "transformer.h.8.mlp.fc2.bias": "model-00002-of-00007.safetensors",
320
+ "transformer.h.8.mlp.fc2.weight": "model-00002-of-00007.safetensors",
321
+ "transformer.h.9.ln.bias": "model-00002-of-00007.safetensors",
322
+ "transformer.h.9.ln.weight": "model-00002-of-00007.safetensors",
323
+ "transformer.h.9.mixer.Wqkv.bias": "model-00002-of-00007.safetensors",
324
+ "transformer.h.9.mixer.Wqkv.weight": "model-00002-of-00007.safetensors",
325
+ "transformer.h.9.mixer.out_proj.bias": "model-00002-of-00007.safetensors",
326
+ "transformer.h.9.mixer.out_proj.weight": "model-00002-of-00007.safetensors",
327
+ "transformer.h.9.mlp.fc1.bias": "model-00002-of-00007.safetensors",
328
+ "transformer.h.9.mlp.fc1.weight": "model-00002-of-00007.safetensors",
329
+ "transformer.h.9.mlp.fc2.bias": "model-00002-of-00007.safetensors",
330
+ "transformer.h.9.mlp.fc2.weight": "model-00002-of-00007.safetensors",
331
+ "transformer.mm_projector.0.bias": "model-00007-of-00007.safetensors",
332
+ "transformer.mm_projector.0.weight": "model-00007-of-00007.safetensors",
333
+ "transformer.mm_projector.2.bias": "model-00007-of-00007.safetensors",
334
+ "transformer.mm_projector.2.weight": "model-00007-of-00007.safetensors",
335
+ "transformer.vision_tower.vision_tower.vision_model.embeddings.patch_embedding.bias": "model-00006-of-00007.safetensors",
336
+ "transformer.vision_tower.vision_tower.vision_model.embeddings.patch_embedding.weight": "model-00006-of-00007.safetensors",
337
+ "transformer.vision_tower.vision_tower.vision_model.embeddings.position_embedding.weight": "model-00006-of-00007.safetensors",
338
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.layer_norm1.bias": "model-00006-of-00007.safetensors",
339
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.layer_norm1.weight": "model-00006-of-00007.safetensors",
340
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.layer_norm2.bias": "model-00006-of-00007.safetensors",
341
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.layer_norm2.weight": "model-00006-of-00007.safetensors",
342
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.mlp.fc1.bias": "model-00006-of-00007.safetensors",
343
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.mlp.fc1.weight": "model-00006-of-00007.safetensors",
344
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.mlp.fc2.bias": "model-00006-of-00007.safetensors",
345
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.mlp.fc2.weight": "model-00006-of-00007.safetensors",
346
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
347
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
348
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
349
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
350
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
351
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
352
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
353
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.0.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
354
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.layer_norm1.bias": "model-00006-of-00007.safetensors",
355
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.layer_norm1.weight": "model-00006-of-00007.safetensors",
356
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.layer_norm2.bias": "model-00006-of-00007.safetensors",
357
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.layer_norm2.weight": "model-00006-of-00007.safetensors",
358
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.mlp.fc1.bias": "model-00006-of-00007.safetensors",
359
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.mlp.fc1.weight": "model-00006-of-00007.safetensors",
360
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.mlp.fc2.bias": "model-00006-of-00007.safetensors",
361
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.mlp.fc2.weight": "model-00006-of-00007.safetensors",
362
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
363
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
364
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
365
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
366
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
367
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
368
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
369
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.1.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
370
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.layer_norm1.bias": "model-00006-of-00007.safetensors",
371
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.layer_norm1.weight": "model-00006-of-00007.safetensors",
372
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.layer_norm2.bias": "model-00006-of-00007.safetensors",
373
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.layer_norm2.weight": "model-00006-of-00007.safetensors",
374
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.mlp.fc1.bias": "model-00006-of-00007.safetensors",
375
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.mlp.fc1.weight": "model-00006-of-00007.safetensors",
376
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.mlp.fc2.bias": "model-00006-of-00007.safetensors",
377
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.mlp.fc2.weight": "model-00006-of-00007.safetensors",
378
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
379
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
380
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
381
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
382
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
383
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
384
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
385
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.10.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
386
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.layer_norm1.bias": "model-00006-of-00007.safetensors",
387
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.layer_norm1.weight": "model-00006-of-00007.safetensors",
388
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.layer_norm2.bias": "model-00006-of-00007.safetensors",
389
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.layer_norm2.weight": "model-00006-of-00007.safetensors",
390
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.mlp.fc1.bias": "model-00006-of-00007.safetensors",
391
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.mlp.fc1.weight": "model-00006-of-00007.safetensors",
392
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.mlp.fc2.bias": "model-00006-of-00007.safetensors",
393
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.mlp.fc2.weight": "model-00006-of-00007.safetensors",
394
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
395
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
396
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
397
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
398
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
399
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
400
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
401
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.11.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
402
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.layer_norm1.bias": "model-00006-of-00007.safetensors",
403
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.layer_norm1.weight": "model-00006-of-00007.safetensors",
404
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.layer_norm2.bias": "model-00006-of-00007.safetensors",
405
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.layer_norm2.weight": "model-00006-of-00007.safetensors",
406
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.mlp.fc1.bias": "model-00006-of-00007.safetensors",
407
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.mlp.fc1.weight": "model-00006-of-00007.safetensors",
408
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.mlp.fc2.bias": "model-00006-of-00007.safetensors",
409
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.mlp.fc2.weight": "model-00006-of-00007.safetensors",
410
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
411
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
412
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
413
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
414
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
415
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
416
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
417
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.12.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
418
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.layer_norm1.bias": "model-00006-of-00007.safetensors",
419
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.layer_norm1.weight": "model-00006-of-00007.safetensors",
420
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.layer_norm2.bias": "model-00006-of-00007.safetensors",
421
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.layer_norm2.weight": "model-00006-of-00007.safetensors",
422
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.mlp.fc1.bias": "model-00006-of-00007.safetensors",
423
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.mlp.fc1.weight": "model-00006-of-00007.safetensors",
424
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.mlp.fc2.bias": "model-00006-of-00007.safetensors",
425
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.mlp.fc2.weight": "model-00006-of-00007.safetensors",
426
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
427
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
428
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
429
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
430
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
431
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
432
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
433
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.13.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
434
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.layer_norm1.bias": "model-00006-of-00007.safetensors",
435
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.layer_norm1.weight": "model-00006-of-00007.safetensors",
436
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.layer_norm2.bias": "model-00006-of-00007.safetensors",
437
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.layer_norm2.weight": "model-00006-of-00007.safetensors",
438
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.mlp.fc1.bias": "model-00006-of-00007.safetensors",
439
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.mlp.fc1.weight": "model-00006-of-00007.safetensors",
440
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.mlp.fc2.bias": "model-00006-of-00007.safetensors",
441
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.mlp.fc2.weight": "model-00006-of-00007.safetensors",
442
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
443
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
444
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
445
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
446
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
447
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
448
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
449
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.14.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
450
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.layer_norm1.bias": "model-00006-of-00007.safetensors",
451
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.layer_norm1.weight": "model-00006-of-00007.safetensors",
452
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.layer_norm2.bias": "model-00006-of-00007.safetensors",
453
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.layer_norm2.weight": "model-00006-of-00007.safetensors",
454
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.mlp.fc1.bias": "model-00006-of-00007.safetensors",
455
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.mlp.fc1.weight": "model-00006-of-00007.safetensors",
456
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.mlp.fc2.bias": "model-00006-of-00007.safetensors",
457
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.mlp.fc2.weight": "model-00006-of-00007.safetensors",
458
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
459
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
460
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
461
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
462
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
463
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
464
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
465
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.15.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
466
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.layer_norm1.bias": "model-00006-of-00007.safetensors",
467
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.layer_norm1.weight": "model-00006-of-00007.safetensors",
468
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.layer_norm2.bias": "model-00006-of-00007.safetensors",
469
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.layer_norm2.weight": "model-00006-of-00007.safetensors",
470
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.mlp.fc1.bias": "model-00006-of-00007.safetensors",
471
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.mlp.fc1.weight": "model-00006-of-00007.safetensors",
472
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.mlp.fc2.bias": "model-00006-of-00007.safetensors",
473
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.mlp.fc2.weight": "model-00006-of-00007.safetensors",
474
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
475
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
476
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
477
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
478
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
479
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
480
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
481
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.16.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
482
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.layer_norm1.bias": "model-00006-of-00007.safetensors",
483
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.layer_norm1.weight": "model-00006-of-00007.safetensors",
484
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.layer_norm2.bias": "model-00006-of-00007.safetensors",
485
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.layer_norm2.weight": "model-00006-of-00007.safetensors",
486
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.mlp.fc1.bias": "model-00006-of-00007.safetensors",
487
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.mlp.fc1.weight": "model-00006-of-00007.safetensors",
488
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.mlp.fc2.bias": "model-00006-of-00007.safetensors",
489
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.mlp.fc2.weight": "model-00006-of-00007.safetensors",
490
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
491
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
492
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
493
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
494
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
495
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
496
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
497
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.17.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
498
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.layer_norm1.bias": "model-00006-of-00007.safetensors",
499
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.layer_norm1.weight": "model-00006-of-00007.safetensors",
500
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.layer_norm2.bias": "model-00006-of-00007.safetensors",
501
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.layer_norm2.weight": "model-00006-of-00007.safetensors",
502
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.mlp.fc1.bias": "model-00006-of-00007.safetensors",
503
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.mlp.fc1.weight": "model-00006-of-00007.safetensors",
504
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.mlp.fc2.bias": "model-00006-of-00007.safetensors",
505
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.mlp.fc2.weight": "model-00006-of-00007.safetensors",
506
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
507
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
508
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
509
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
510
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
511
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
512
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
513
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.18.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
514
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.layer_norm1.bias": "model-00006-of-00007.safetensors",
515
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.layer_norm1.weight": "model-00006-of-00007.safetensors",
516
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.layer_norm2.bias": "model-00006-of-00007.safetensors",
517
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.layer_norm2.weight": "model-00006-of-00007.safetensors",
518
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.mlp.fc1.bias": "model-00006-of-00007.safetensors",
519
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.mlp.fc1.weight": "model-00006-of-00007.safetensors",
520
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.mlp.fc2.bias": "model-00006-of-00007.safetensors",
521
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.mlp.fc2.weight": "model-00006-of-00007.safetensors",
522
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
523
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
524
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
525
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
526
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
527
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
528
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
529
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.19.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
530
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.layer_norm1.bias": "model-00006-of-00007.safetensors",
531
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.layer_norm1.weight": "model-00006-of-00007.safetensors",
532
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.layer_norm2.bias": "model-00006-of-00007.safetensors",
533
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.layer_norm2.weight": "model-00006-of-00007.safetensors",
534
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.mlp.fc1.bias": "model-00006-of-00007.safetensors",
535
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.mlp.fc1.weight": "model-00006-of-00007.safetensors",
536
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.mlp.fc2.bias": "model-00006-of-00007.safetensors",
537
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.mlp.fc2.weight": "model-00006-of-00007.safetensors",
538
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
539
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
540
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
541
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
542
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
543
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
544
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
545
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.2.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
546
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.layer_norm1.bias": "model-00006-of-00007.safetensors",
547
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.layer_norm1.weight": "model-00006-of-00007.safetensors",
548
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.layer_norm2.bias": "model-00006-of-00007.safetensors",
549
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.layer_norm2.weight": "model-00006-of-00007.safetensors",
550
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.mlp.fc1.bias": "model-00006-of-00007.safetensors",
551
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.mlp.fc1.weight": "model-00006-of-00007.safetensors",
552
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.mlp.fc2.bias": "model-00006-of-00007.safetensors",
553
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.mlp.fc2.weight": "model-00006-of-00007.safetensors",
554
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
555
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
556
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
557
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
558
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
559
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
560
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
561
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.20.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
562
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.layer_norm1.bias": "model-00006-of-00007.safetensors",
563
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.layer_norm1.weight": "model-00006-of-00007.safetensors",
564
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.layer_norm2.bias": "model-00006-of-00007.safetensors",
565
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.layer_norm2.weight": "model-00006-of-00007.safetensors",
566
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.mlp.fc1.bias": "model-00006-of-00007.safetensors",
567
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.mlp.fc1.weight": "model-00006-of-00007.safetensors",
568
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.mlp.fc2.bias": "model-00006-of-00007.safetensors",
569
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.mlp.fc2.weight": "model-00006-of-00007.safetensors",
570
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
571
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
572
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
573
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
574
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
575
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
576
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
577
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.21.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
578
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.layer_norm1.bias": "model-00006-of-00007.safetensors",
579
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.layer_norm1.weight": "model-00006-of-00007.safetensors",
580
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.layer_norm2.bias": "model-00006-of-00007.safetensors",
581
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.layer_norm2.weight": "model-00006-of-00007.safetensors",
582
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.mlp.fc1.bias": "model-00006-of-00007.safetensors",
583
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.mlp.fc1.weight": "model-00006-of-00007.safetensors",
584
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.mlp.fc2.bias": "model-00006-of-00007.safetensors",
585
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.mlp.fc2.weight": "model-00006-of-00007.safetensors",
586
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
587
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
588
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
589
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
590
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
591
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
592
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
593
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.22.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
594
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.layer_norm1.bias": "model-00007-of-00007.safetensors",
595
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.layer_norm1.weight": "model-00007-of-00007.safetensors",
596
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.layer_norm2.bias": "model-00007-of-00007.safetensors",
597
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.layer_norm2.weight": "model-00007-of-00007.safetensors",
598
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.mlp.fc1.bias": "model-00007-of-00007.safetensors",
599
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.mlp.fc1.weight": "model-00007-of-00007.safetensors",
600
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.mlp.fc2.bias": "model-00007-of-00007.safetensors",
601
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.mlp.fc2.weight": "model-00007-of-00007.safetensors",
602
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
603
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
604
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.self_attn.out_proj.bias": "model-00007-of-00007.safetensors",
605
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.self_attn.out_proj.weight": "model-00007-of-00007.safetensors",
606
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.self_attn.q_proj.bias": "model-00007-of-00007.safetensors",
607
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.self_attn.q_proj.weight": "model-00007-of-00007.safetensors",
608
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.self_attn.v_proj.bias": "model-00007-of-00007.safetensors",
609
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.23.self_attn.v_proj.weight": "model-00007-of-00007.safetensors",
610
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.layer_norm1.bias": "model-00007-of-00007.safetensors",
611
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.layer_norm1.weight": "model-00007-of-00007.safetensors",
612
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.layer_norm2.bias": "model-00007-of-00007.safetensors",
613
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.layer_norm2.weight": "model-00007-of-00007.safetensors",
614
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.mlp.fc1.bias": "model-00007-of-00007.safetensors",
615
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.mlp.fc1.weight": "model-00007-of-00007.safetensors",
616
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.mlp.fc2.bias": "model-00007-of-00007.safetensors",
617
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.mlp.fc2.weight": "model-00007-of-00007.safetensors",
618
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.self_attn.k_proj.bias": "model-00007-of-00007.safetensors",
619
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.self_attn.k_proj.weight": "model-00007-of-00007.safetensors",
620
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.self_attn.out_proj.bias": "model-00007-of-00007.safetensors",
621
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.self_attn.out_proj.weight": "model-00007-of-00007.safetensors",
622
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.self_attn.q_proj.bias": "model-00007-of-00007.safetensors",
623
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.self_attn.q_proj.weight": "model-00007-of-00007.safetensors",
624
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.self_attn.v_proj.bias": "model-00007-of-00007.safetensors",
625
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.24.self_attn.v_proj.weight": "model-00007-of-00007.safetensors",
626
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.layer_norm1.bias": "model-00007-of-00007.safetensors",
627
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.layer_norm1.weight": "model-00007-of-00007.safetensors",
628
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.layer_norm2.bias": "model-00007-of-00007.safetensors",
629
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.layer_norm2.weight": "model-00007-of-00007.safetensors",
630
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.mlp.fc1.bias": "model-00007-of-00007.safetensors",
631
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.mlp.fc1.weight": "model-00007-of-00007.safetensors",
632
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.mlp.fc2.bias": "model-00007-of-00007.safetensors",
633
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.mlp.fc2.weight": "model-00007-of-00007.safetensors",
634
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.self_attn.k_proj.bias": "model-00007-of-00007.safetensors",
635
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.self_attn.k_proj.weight": "model-00007-of-00007.safetensors",
636
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.self_attn.out_proj.bias": "model-00007-of-00007.safetensors",
637
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.self_attn.out_proj.weight": "model-00007-of-00007.safetensors",
638
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.self_attn.q_proj.bias": "model-00007-of-00007.safetensors",
639
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.self_attn.q_proj.weight": "model-00007-of-00007.safetensors",
640
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.self_attn.v_proj.bias": "model-00007-of-00007.safetensors",
641
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.25.self_attn.v_proj.weight": "model-00007-of-00007.safetensors",
642
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.layer_norm1.bias": "model-00006-of-00007.safetensors",
643
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.layer_norm1.weight": "model-00006-of-00007.safetensors",
644
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.layer_norm2.bias": "model-00006-of-00007.safetensors",
645
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.layer_norm2.weight": "model-00006-of-00007.safetensors",
646
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.mlp.fc1.bias": "model-00006-of-00007.safetensors",
647
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.mlp.fc1.weight": "model-00006-of-00007.safetensors",
648
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.mlp.fc2.bias": "model-00006-of-00007.safetensors",
649
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.mlp.fc2.weight": "model-00006-of-00007.safetensors",
650
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
651
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
652
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
653
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
654
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
655
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
656
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
657
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.3.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
658
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.layer_norm1.bias": "model-00006-of-00007.safetensors",
659
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.layer_norm1.weight": "model-00006-of-00007.safetensors",
660
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.layer_norm2.bias": "model-00006-of-00007.safetensors",
661
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.layer_norm2.weight": "model-00006-of-00007.safetensors",
662
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.mlp.fc1.bias": "model-00006-of-00007.safetensors",
663
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.mlp.fc1.weight": "model-00006-of-00007.safetensors",
664
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.mlp.fc2.bias": "model-00006-of-00007.safetensors",
665
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.mlp.fc2.weight": "model-00006-of-00007.safetensors",
666
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
667
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
668
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
669
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
670
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
671
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
672
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
673
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.4.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
674
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.layer_norm1.bias": "model-00006-of-00007.safetensors",
675
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.layer_norm1.weight": "model-00006-of-00007.safetensors",
676
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.layer_norm2.bias": "model-00006-of-00007.safetensors",
677
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.layer_norm2.weight": "model-00006-of-00007.safetensors",
678
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.mlp.fc1.bias": "model-00006-of-00007.safetensors",
679
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.mlp.fc1.weight": "model-00006-of-00007.safetensors",
680
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.mlp.fc2.bias": "model-00006-of-00007.safetensors",
681
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.mlp.fc2.weight": "model-00006-of-00007.safetensors",
682
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
683
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
684
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
685
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
686
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
687
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
688
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
689
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.5.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
690
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.layer_norm1.bias": "model-00006-of-00007.safetensors",
691
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.layer_norm1.weight": "model-00006-of-00007.safetensors",
692
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.layer_norm2.bias": "model-00006-of-00007.safetensors",
693
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.layer_norm2.weight": "model-00006-of-00007.safetensors",
694
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.mlp.fc1.bias": "model-00006-of-00007.safetensors",
695
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.mlp.fc1.weight": "model-00006-of-00007.safetensors",
696
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.mlp.fc2.bias": "model-00006-of-00007.safetensors",
697
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.mlp.fc2.weight": "model-00006-of-00007.safetensors",
698
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
699
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
700
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
701
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
702
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
703
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
704
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
705
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.6.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
706
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.layer_norm1.bias": "model-00006-of-00007.safetensors",
707
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.layer_norm1.weight": "model-00006-of-00007.safetensors",
708
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.layer_norm2.bias": "model-00006-of-00007.safetensors",
709
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.layer_norm2.weight": "model-00006-of-00007.safetensors",
710
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.mlp.fc1.bias": "model-00006-of-00007.safetensors",
711
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.mlp.fc1.weight": "model-00006-of-00007.safetensors",
712
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.mlp.fc2.bias": "model-00006-of-00007.safetensors",
713
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.mlp.fc2.weight": "model-00006-of-00007.safetensors",
714
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
715
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
716
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
717
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
718
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
719
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
720
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
721
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.7.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
722
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.layer_norm1.bias": "model-00006-of-00007.safetensors",
723
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.layer_norm1.weight": "model-00006-of-00007.safetensors",
724
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.layer_norm2.bias": "model-00006-of-00007.safetensors",
725
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.layer_norm2.weight": "model-00006-of-00007.safetensors",
726
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.mlp.fc1.bias": "model-00006-of-00007.safetensors",
727
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.mlp.fc1.weight": "model-00006-of-00007.safetensors",
728
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.mlp.fc2.bias": "model-00006-of-00007.safetensors",
729
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.mlp.fc2.weight": "model-00006-of-00007.safetensors",
730
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
731
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
732
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
733
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
734
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
735
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
736
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
737
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.8.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
738
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.layer_norm1.bias": "model-00006-of-00007.safetensors",
739
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.layer_norm1.weight": "model-00006-of-00007.safetensors",
740
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.layer_norm2.bias": "model-00006-of-00007.safetensors",
741
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.layer_norm2.weight": "model-00006-of-00007.safetensors",
742
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.mlp.fc1.bias": "model-00006-of-00007.safetensors",
743
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.mlp.fc1.weight": "model-00006-of-00007.safetensors",
744
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.mlp.fc2.bias": "model-00006-of-00007.safetensors",
745
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.mlp.fc2.weight": "model-00006-of-00007.safetensors",
746
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
747
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
748
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.self_attn.out_proj.bias": "model-00006-of-00007.safetensors",
749
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.self_attn.out_proj.weight": "model-00006-of-00007.safetensors",
750
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
751
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
752
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
753
+ "transformer.vision_tower.vision_tower.vision_model.encoder.layers.9.self_attn.v_proj.weight": "model-00006-of-00007.safetensors"
754
+ }
755
+ }
modeling_imp.py ADDED
@@ -0,0 +1,1262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) MILVLG team.
2
+ # Licensed under the Apache 2.0 license.
3
+ #
4
+ # Some code here is copied from the project Phi-2 (https://huggingface.co/microsoft/phi-2),
5
+ # SigLIP@transformers==4.37.0.dev0 (https://huggingface.co/google/siglip-so400m-patch14-384),
6
+ # and Llava (https://github.com/haotian-liu/LLaVA), and modified by
7
+ # Zhenwei Shao ([email protected]) @ MILVLG. We thank them for their great works.
8
+ # And their original licenses and copyright should be inherited (see the statements
9
+ # in `configuration_imp.py` for more details).
10
+
11
+
12
+ # Be careful: The way how `past_key_values.seqlen_offset` is updated is modified from
13
+ # the implementation of original Phi-2. See the comments below for details.
14
+
15
+ from __future__ import annotations
16
+ import os
17
+ import math
18
+ import re
19
+ from dataclasses import dataclass, field
20
+ from typing import Any, Dict, Optional, Tuple, Union, List
21
+ from abc import ABC, abstractmethod
22
+
23
+ import torch
24
+ import torch.nn as nn
25
+ from einops import rearrange, repeat
26
+ from transformers import (
27
+ PretrainedConfig,
28
+ PreTrainedModel,
29
+ AutoConfig,
30
+ AutoModelForCausalLM
31
+ )
32
+ from transformers.activations import ACT2FN
33
+ from transformers.modeling_outputs import CausalLMOutputWithPast
34
+ import sys
35
+ from .configuration_imp import PhiConfig, ImpConfig
36
+ from .vision_encoder import VisionTower
37
+
38
+ try:
39
+ from flash_attn.bert_padding import pad_input, unpad_input
40
+ from flash_attn.layers.rotary import RotaryEmbedding as FlashRotaryEmbedding
41
+ from flash_attn.modules.mha import FlashCrossAttention, FlashSelfAttention
42
+ from flash_attn.ops.fused_dense import FusedDense
43
+ except:
44
+ pad_input, unpad_input = None, None
45
+ FlashRotaryEmbedding = None
46
+ FlashSelfAttention, FlashCrossAttention = None, None
47
+ FusedDense = None
48
+
49
+
50
+ @dataclass
51
+ class InferenceParams:
52
+ """Inference parameters passed to model to efficiently calculate
53
+ and store context during inference.
54
+
55
+ Reference:
56
+ https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/utils/generation.py.
57
+
58
+ Args:
59
+ max_seqlen: Maximum sequence length.
60
+ max_batch_size: Maximum batch size.
61
+ seqlen_offset: Sequence length offset.
62
+ batch_size_offset: Batch size offset.
63
+ key_value_memory_dict: Key value memory dictionary.
64
+ lengths_per_sample: Lengths per sample.
65
+
66
+ """
67
+
68
+ max_seqlen: int = field(metadata={"help": "Maximum sequence length."})
69
+
70
+ max_batch_size: int = field(metadata={"help": "Maximum batch size."})
71
+
72
+ seqlen_offset: int = field(default=0, metadata={"help": "Sequence length offset."})
73
+
74
+ batch_size_offset: int = field(default=0, metadata={"help": "Batch size offset."})
75
+
76
+ key_value_memory_dict: Dict[str, Any] = field(
77
+ default_factory=dict, metadata={"help": "Key value memory dictionary."}
78
+ )
79
+
80
+ lengths_per_sample: torch.Tensor = field(default=None, metadata={"help": "Lengths per sample."})
81
+
82
+
83
+ class Embedding(nn.Module):
84
+ """Token embedding with dropout."""
85
+
86
+ def __init__(self, config: PretrainedConfig) -> None:
87
+ super().__init__()
88
+
89
+ self.wte = nn.Embedding(config.vocab_size, config.n_embd)
90
+ self.drop = nn.Dropout(config.embd_pdrop)
91
+
92
+ def forward(self, input_ids: torch.LongTensor) -> torch.FloatTensor:
93
+ input_shape = input_ids.size()
94
+ input_ids = input_ids.view(-1, input_shape[-1])
95
+
96
+ hidden_states = self.wte(input_ids)
97
+ hidden_states = self.drop(hidden_states)
98
+
99
+ return hidden_states
100
+
101
+
102
+
103
+ def _apply_rotary_emb(
104
+ x: torch.FloatTensor,
105
+ cos: torch.FloatTensor,
106
+ sin: torch.FloatTensor,
107
+ ) -> torch.FloatTensor:
108
+ _, seqlen, _, _ = x.shape
109
+ _, rotary_dim = cos.shape
110
+ rotary_dim *= 2
111
+
112
+ x_rot = x[:, :, :, :rotary_dim]
113
+ x_pass = x[:, :, :, rotary_dim:]
114
+
115
+ x1, x2 = x_rot.chunk(2, dim=-1)
116
+ c, s = rearrange(cos[:seqlen], "s d -> s 1 d"), rearrange(sin[:seqlen], "s d -> s 1 d")
117
+ x1, x2, c, s = [t.to(dtype=torch.float32) for t in [x1, x2, c, s]]
118
+
119
+ x_rot = torch.cat([x1 * c - x2 * s, x1 * s + x2 * c], axis=-1).to(x.dtype)
120
+
121
+ return torch.cat([x_rot, x_pass], axis=-1)
122
+
123
+
124
+ def _apply_rotary_emb_kv(
125
+ kv: torch.FloatTensor,
126
+ cos: torch.FloatTensor,
127
+ sin: torch.FloatTensor,
128
+ cos_k: Optional[torch.FloatTensor] = None,
129
+ sin_k: Optional[torch.FloatTensor] = None,
130
+ ) -> torch.FloatTensor:
131
+ _, seqlen, _, _, _ = kv.shape
132
+ _, rotary_dim = cos.shape
133
+ rotary_dim *= 2
134
+
135
+ k_rot = kv[:, :, 0, :, :rotary_dim]
136
+ k_pass = kv[:, :, 0, :, rotary_dim:]
137
+
138
+ k1, k2 = k_rot.chunk(2, dim=-1)
139
+ c, s = rearrange(cos[:seqlen], "s d -> s 1 d"), rearrange(sin[:seqlen], "s d -> s 1 d")
140
+ k1, k2, c, s = [t.to(dtype=torch.float32) for t in [k1, k2, c, s]]
141
+
142
+ k_rot = torch.cat([k1 * c - k2 * s, k1 * s + k2 * c], axis=-1).to(kv.dtype)
143
+
144
+ return torch.cat(
145
+ [
146
+ torch.cat([k_rot, k_pass], axis=-1).unsqueeze(2),
147
+ kv[:, :, 1:2, :, :],
148
+ ],
149
+ axis=2,
150
+ )
151
+
152
+
153
+ def _apply_rotary_emb_qkv(
154
+ qkv: torch.FloatTensor,
155
+ cos: torch.FloatTensor,
156
+ sin: torch.FloatTensor,
157
+ cos_k: Optional[torch.FloatTensor] = None,
158
+ sin_k: Optional[torch.FloatTensor] = None,
159
+ ) -> torch.FloatTensor:
160
+ _, seqlen, _, _, _ = qkv.shape
161
+ _, rotary_dim = cos.shape
162
+ rotary_dim *= 2
163
+
164
+ q_rot = qkv[:, :, 0, :, :rotary_dim]
165
+ q_pass = qkv[:, :, 0, :, rotary_dim:]
166
+
167
+ k_rot = qkv[:, :, 1, :, :rotary_dim]
168
+ k_pass = qkv[:, :, 1, :, rotary_dim:]
169
+
170
+ q1, q2 = q_rot.chunk(2, dim=-1)
171
+ k1, k2 = k_rot.chunk(2, dim=-1)
172
+ c, s = rearrange(cos[:seqlen], "s d -> s 1 d"), rearrange(sin[:seqlen], "s d -> s 1 d")
173
+ q1, q2, k1, k2, c, s = [t.to(dtype=torch.float32) for t in [q1, q2, k1, k2, c, s]]
174
+
175
+ q_rot = torch.cat([q1 * c - q2 * s, q1 * s + q2 * c], axis=-1).to(qkv.dtype)
176
+ k_rot = torch.cat([k1 * c - k2 * s, k1 * s + k2 * c], axis=-1).to(qkv.dtype)
177
+
178
+ return torch.cat(
179
+ [
180
+ torch.cat([q_rot, q_pass], axis=-1).unsqueeze(2),
181
+ torch.cat([k_rot, k_pass], axis=-1).unsqueeze(2),
182
+ qkv[:, :, 2:3, :, :],
183
+ ],
184
+ axis=2,
185
+ )
186
+
187
+
188
+ class RotaryEmbedding(nn.Module):
189
+ """Rotary positional embedding (RoPE).
190
+
191
+ Reference:
192
+ RoFormer: Enhanced Transformer with Rotary Position Embedding.
193
+ https://arxiv.org/pdf/2104.09864.pdf.
194
+
195
+ """
196
+
197
+ def __init__(
198
+ self,
199
+ dim: int,
200
+ base: int = 10000,
201
+ scale_base: Optional[float] = None,
202
+ pos_idx_in_fp32: bool = True,
203
+ max_position_embeddings: int = 2048,
204
+ device: Optional[str] = None,
205
+ **kwargs,
206
+ ) -> None:
207
+ super().__init__()
208
+
209
+ if scale_base is not None:
210
+ raise NotImplementedError
211
+
212
+ self.dim = dim
213
+ self.base = float(base)
214
+ self.scale_base = scale_base
215
+ self.pos_idx_in_fp32 = pos_idx_in_fp32
216
+ self.max_position_embeddings = max_position_embeddings
217
+ self.device = device
218
+
219
+ # Generate and save the inverse frequency buffer (non-trainable)
220
+ inv_freq = self._compute_inv_freq(device)
221
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
222
+
223
+ # Generate and save the scale buffer (non-trainable)
224
+ scale = (
225
+ (torch.arange(0, dim, 2, device=device, dtype=torch.float32) + 0.4 * dim) / (1.4 * dim)
226
+ if scale_base is not None
227
+ else None
228
+ )
229
+ self.register_buffer("scale", scale, persistent=False)
230
+
231
+ # Initialize cached attributes since ONNX can't rely on dynamic initialization
232
+ self._update_cos_sin_cache(max_position_embeddings, device=device, dtype=torch.float32)
233
+
234
+ def _compute_inv_freq(self, device: Optional[str] = None) -> torch.FloatTensor:
235
+ return 1.0 / (self.base ** (torch.arange(0, self.dim, 2, device=device, dtype=torch.float32) / self.dim))
236
+
237
+ def _update_cos_sin_cache(
238
+ self,
239
+ seqlen: int,
240
+ device: Optional[str] = None,
241
+ dtype: Optional[torch.dtype] = None,
242
+ ) -> None:
243
+ self._seq_len_cached = seqlen
244
+
245
+ # fp32 is preferred since the output of `torch.arange` can be quite large
246
+ # and bf16 would lose a lot of precision
247
+ if self.pos_idx_in_fp32:
248
+ t = torch.arange(seqlen, device=device, dtype=torch.float32)
249
+ if self.inv_freq.dtype != torch.float32:
250
+ inv_freq = self._compute_inv_freq(device=device)
251
+ else:
252
+ inv_freq = self.inv_freq
253
+ else:
254
+ t = torch.arange(seqlen, device=device, dtype=self.inv_freq.dtype)
255
+ inv_freq = self.inv_freq
256
+
257
+ # `torch.outer` is preferred since `torch.einsum` converts from fp32 to fp16 if used with AMP
258
+ freqs = torch.outer(t, inv_freq)
259
+ if self.scale is None:
260
+ self._cos_cached = torch.cos(freqs).to(dtype)
261
+ self._sin_cached = torch.sin(freqs).to(dtype)
262
+ else:
263
+ power = (
264
+ torch.arange(seqlen, dtype=self.scale.dtype, device=self.scale.device) - seqlen // 2
265
+ ) / self.scale_base
266
+ scale = self.scale.to(device=power.device) ** rearrange(power, "s -> s 1")
267
+
268
+ # Force the scale multiplication to happen in fp32
269
+ self._cos_cached = (torch.cos(freqs) * scale).to(dtype)
270
+ self._sin_cached = (torch.sin(freqs) * scale).to(dtype)
271
+ self._cos_k_cached = (torch.cos(freqs) / scale).to(dtype)
272
+ self._sin_k_cached = (torch.sin(freqs) / scale).to(dtype)
273
+
274
+ def forward(
275
+ self,
276
+ qkv: torch.Tensor,
277
+ kv: Optional[torch.Tensor] = None,
278
+ seqlen_offset: int = 0,
279
+ **kwargs,
280
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
281
+ if (
282
+ self._seq_len_cached < qkv.shape[1] + seqlen_offset
283
+ or self._cos_cached.device != qkv.device
284
+ or self._cos_cached.dtype != qkv.dtype
285
+ or (self.training and self._cos_cached.is_inference())
286
+ ):
287
+ self._update_cos_sin_cache(qkv.shape[1] + seqlen_offset, device=qkv.device, dtype=qkv.dtype)
288
+
289
+ if kv is None:
290
+ return _apply_rotary_emb_qkv(
291
+ qkv,
292
+ self._cos_cached[seqlen_offset:],
293
+ self._sin_cached[seqlen_offset:],
294
+ )
295
+ else:
296
+ q = _apply_rotary_emb(
297
+ qkv,
298
+ self._cos_cached[seqlen_offset:],
299
+ self._sin_cached[seqlen_offset:],
300
+ )
301
+ kv = _apply_rotary_emb_kv(
302
+ kv,
303
+ self._cos_cached[seqlen_offset:],
304
+ self._sin_cached[seqlen_offset:],
305
+ )
306
+
307
+ return q, kv
308
+
309
+
310
+ class MLP(nn.Module):
311
+ """Multi-Layer Perceptron.
312
+
313
+ Reference:
314
+ Attention Is All You Need.
315
+ https://arxiv.org/pdf/1706.03762.pdf.
316
+
317
+ """
318
+
319
+ def __init__(
320
+ self,
321
+ config: PretrainedConfig,
322
+ n_inner: Optional[int] = None,
323
+ act_fn: Optional[str] = None,
324
+ ) -> None:
325
+ super().__init__()
326
+
327
+ act_fn = config.activation_function if act_fn is None else act_fn
328
+
329
+ n_inner = getattr(config, "n_inner", None) if n_inner is None else n_inner
330
+ n_inner = n_inner if n_inner is not None else 4 * config.n_embd
331
+
332
+ self.fc1 = nn.Linear(config.n_embd, n_inner)
333
+ self.fc2 = nn.Linear(n_inner, config.n_embd)
334
+ self.act = ACT2FN[act_fn]
335
+
336
+ def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
337
+ hidden_states = self.fc1(hidden_states)
338
+ hidden_states = self.act(hidden_states)
339
+ hidden_states = self.fc2(hidden_states)
340
+
341
+ return hidden_states
342
+
343
+
344
+ class SelfAttention(nn.Module):
345
+ """Self-attention layer (compatible with PyTorch).
346
+
347
+ Reference:
348
+ https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/modules/mha.py.
349
+
350
+ """
351
+
352
+ def __init__(
353
+ self,
354
+ causal: bool = True,
355
+ softmax_scale: Optional[float] = None,
356
+ attention_dropout: float = 0.0,
357
+ ) -> None:
358
+ super().__init__()
359
+
360
+ self.causal = causal
361
+ self.softmax_scale = softmax_scale
362
+ self.drop = nn.Dropout(attention_dropout)
363
+
364
+ @torch.autocast("cpu", enabled=False)
365
+ @torch.autocast("cuda", enabled=False)
366
+ def forward(
367
+ self,
368
+ qkv: torch.FloatTensor,
369
+ causal: bool = None,
370
+ key_padding_mask: Optional[torch.BoolTensor] = None,
371
+ **kwargs,
372
+ ) -> torch.FloatTensor:
373
+ batch_size, seqlen = qkv.shape[0], qkv.shape[1]
374
+ q, k, v = qkv.unbind(dim=2)
375
+
376
+ q = q.to(torch.float32)
377
+ k = k.to(torch.float32)
378
+
379
+ causal = self.causal if causal is None else causal
380
+ softmax_scale = self.softmax_scale or 1.0 / math.sqrt(q.shape[-1])
381
+
382
+ # Autocast is manually disabled to avoid `torch.einsum` performing the operation
383
+ # using float16, which might lead to overflow
384
+ scores = torch.einsum("bthd,bshd->bhts", q, k * softmax_scale)
385
+
386
+ if key_padding_mask is not None:
387
+ padding_mask = torch.full((batch_size, seqlen), -10000.0, dtype=scores.dtype, device=scores.device)
388
+ padding_mask.masked_fill_(key_padding_mask, 0.0)
389
+
390
+ scores = scores + rearrange(padding_mask, "b s -> b 1 1 s")
391
+
392
+ if causal:
393
+ causal_mask = torch.triu(torch.full((seqlen, seqlen), -10000.0, device=scores.device), 1)
394
+ scores = scores + causal_mask.to(dtype=scores.dtype)
395
+
396
+ attention = torch.softmax(scores, dim=-1).to(v.dtype)
397
+ attention = self.drop(attention)
398
+
399
+ output = torch.einsum("bhts,bshd->bthd", attention, v)
400
+
401
+ return output
402
+
403
+
404
+ class CrossAttention(nn.Module):
405
+ """Cross-attention layer (compatible with PyTorch).
406
+
407
+ Reference:
408
+ https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/modules/mha.py.
409
+
410
+ """
411
+
412
+ def __init__(
413
+ self,
414
+ causal: bool = True,
415
+ softmax_scale: Optional[float] = None,
416
+ attention_dropout: float = 0.0,
417
+ ) -> None:
418
+ super().__init__()
419
+
420
+ self.causal = causal
421
+ self.softmax_scale = softmax_scale
422
+ self.drop = nn.Dropout(attention_dropout)
423
+
424
+ @torch.autocast("cpu", enabled=False)
425
+ @torch.autocast("cuda", enabled=False)
426
+ def forward(
427
+ self,
428
+ q: torch.FloatTensor,
429
+ kv: torch.FloatTensor,
430
+ causal: bool = None,
431
+ key_padding_mask: Optional[torch.BoolTensor] = None,
432
+ **kwargs,
433
+ ) -> torch.FloatTensor:
434
+ batch_size, seqlen_q = q.shape[0], q.shape[1]
435
+ seqlen_k = kv.shape[1]
436
+
437
+ if kv.shape[3] != q.shape[2]:
438
+ kv = repeat(kv, "... hkv d -> ... (hkv g) d", g=q.shape[2] // kv.shape[3])
439
+ k, v = kv.unbind(dim=2)
440
+
441
+ q = q.to(torch.float32)
442
+ k = k.to(torch.float32)
443
+
444
+ causal = self.causal if causal is None else causal
445
+ softmax_scale = self.softmax_scale or 1.0 / math.sqrt(q.shape[-1])
446
+
447
+ # Autocast is manually disabled to avoid `torch.einsum` performing the operation
448
+ # using float16, which might lead to overflow
449
+ scores = torch.einsum("bthd,bshd->bhts", q, k * softmax_scale)
450
+
451
+ if key_padding_mask is not None:
452
+ padding_mask = torch.full(
453
+ (batch_size, seqlen_k),
454
+ -10000.0,
455
+ dtype=scores.dtype,
456
+ device=scores.device,
457
+ )
458
+ padding_mask.masked_fill_(key_padding_mask, 0.0)
459
+
460
+ scores = scores + rearrange(padding_mask, "b s -> b 1 1 s")
461
+
462
+ if causal:
463
+ rows = rearrange(torch.arange(seqlen_q, device=q.device, dtype=torch.long), "s -> s 1")
464
+ cols = torch.arange(seqlen_k, device=k.device, dtype=torch.long)
465
+ causal_mask = cols > rows + seqlen_k - seqlen_q
466
+
467
+ scores = scores.masked_fill(causal_mask, -10000.0)
468
+
469
+ attention = torch.softmax(scores, dim=-1).to(v.dtype)
470
+ attention = self.drop(attention)
471
+
472
+ output = torch.einsum("bhts,bshd->bthd", attention, v)
473
+
474
+ return output
475
+
476
+
477
+ def _find_mha_dims(
478
+ config: PretrainedConfig,
479
+ n_head: Optional[int] = None,
480
+ n_head_kv: Optional[int] = None,
481
+ head_dim: Optional[int] = None,
482
+ ) -> Tuple[int, int]:
483
+ if n_head is None and head_dim is None:
484
+ head_dim = config.n_embd // config.n_head
485
+ n_head = config.n_head
486
+ elif n_head is None or head_dim is None:
487
+ raise ValueError("`n_head` and `head_dim` must be both specified or `None`.")
488
+
489
+ if n_head_kv is None:
490
+ n_head_kv = getattr(config, "n_head_kv", None) or n_head
491
+
492
+ return n_head, n_head_kv, head_dim
493
+
494
+
495
+ def _update_kv_cache(kv: torch.FloatTensor, inference_params: InferenceParams, layer_idx: int) -> torch.FloatTensor:
496
+ num_heads, head_dim = kv.shape[-2:]
497
+
498
+ if layer_idx not in inference_params.key_value_memory_dict:
499
+ inference_params.key_value_memory_dict[layer_idx] = torch.empty(
500
+ inference_params.max_batch_size,
501
+ inference_params.max_seqlen,
502
+ 2,
503
+ num_heads,
504
+ head_dim,
505
+ dtype=kv.dtype,
506
+ device=kv.device,
507
+ )
508
+
509
+ batch_start = inference_params.batch_size_offset
510
+ batch_end = batch_start + kv.shape[0]
511
+
512
+ sequence_start = inference_params.seqlen_offset
513
+ sequence_end = sequence_start + kv.shape[1]
514
+
515
+ # When the current sequence length is equal to or larger than the maximum sequence length,
516
+ # we need to concatenate the current `kv` with the cached `kv` to expand its length
517
+ if sequence_end >= inference_params.max_seqlen:
518
+ inference_params.key_value_memory_dict[layer_idx] = torch.concatenate((inference_params.key_value_memory_dict[layer_idx], kv), dim=1)
519
+
520
+ inference_params.key_value_memory_dict[layer_idx][batch_start:batch_end, sequence_start:sequence_end, ...] = kv
521
+ kv = inference_params.key_value_memory_dict[layer_idx][batch_start:batch_end, :sequence_end, ...]
522
+
523
+ return kv
524
+
525
+
526
+ class MHA(nn.Module):
527
+ """Multi-head attention layer."""
528
+
529
+ def __init__(
530
+ self,
531
+ config: PretrainedConfig,
532
+ dtype: Optional[torch.dtype] = None,
533
+ device: Optional[str] = None,
534
+ rotary_dim: Optional[int] = None,
535
+ rotary_base: float = 10000.0,
536
+ rotary_scale_base: Optional[float] = None,
537
+ n_head: Optional[int] = None,
538
+ n_head_kv: Optional[int] = None,
539
+ head_dim: Optional[int] = None,
540
+ bias: bool = True,
541
+ causal: bool = True,
542
+ softmax_scale: Optional[float] = None,
543
+ layer_idx: Optional[int] = None,
544
+ return_residual: bool = False,
545
+ checkpointing: bool = False,
546
+ ) -> None:
547
+ super().__init__()
548
+
549
+ # Rotary embedding
550
+ self.rotary_dim = rotary_dim if rotary_dim is not None else getattr(config, "rotary_dim", 0)
551
+ if self.rotary_dim > 0:
552
+ rotary_cls = FlashRotaryEmbedding if config.flash_rotary else RotaryEmbedding
553
+ if rotary_cls is None:
554
+ rotary_cls = RotaryEmbedding
555
+
556
+ rotary_kwargs = {}
557
+ if rotary_cls is RotaryEmbedding:
558
+ rotary_kwargs["max_position_embeddings"] = config.n_positions
559
+
560
+ self.rotary_emb = rotary_cls(
561
+ self.rotary_dim,
562
+ base=rotary_base,
563
+ scale_base=rotary_scale_base,
564
+ device=device,
565
+ **rotary_kwargs,
566
+ )
567
+
568
+ # MLP
569
+ self.n_head, self.n_head_kv, self.head_dim = _find_mha_dims(
570
+ config, n_head=n_head, n_head_kv=n_head_kv, head_dim=head_dim
571
+ )
572
+ op_size = self.head_dim * (self.n_head + 2 * self.n_head_kv)
573
+ hidden_size = config.n_embd
574
+
575
+ linear_cls = FusedDense if config.fused_dense else nn.Linear
576
+ if linear_cls is None:
577
+ linear_cls = nn.Linear
578
+
579
+ self.Wqkv = linear_cls(hidden_size, op_size, bias=bias, device=device, dtype=dtype)
580
+ self.out_proj = linear_cls(hidden_size, hidden_size, bias=bias, device=device, dtype=dtype)
581
+
582
+ # Attention
583
+ attn_cls = FlashSelfAttention if config.flash_attn else SelfAttention
584
+ if attn_cls is None:
585
+ attn_cls = SelfAttention
586
+
587
+ cross_attn_cls = FlashCrossAttention if config.flash_attn else CrossAttention
588
+ if cross_attn_cls is None:
589
+ cross_attn_cls = CrossAttention
590
+
591
+ self.inner_attn = attn_cls(
592
+ causal=causal,
593
+ softmax_scale=softmax_scale,
594
+ attention_dropout=config.attn_pdrop,
595
+ )
596
+ self.inner_cross_attn = cross_attn_cls(
597
+ causal=causal,
598
+ softmax_scale=softmax_scale,
599
+ attention_dropout=config.attn_pdrop,
600
+ )
601
+
602
+ self.flash_attn = config.flash_attn and attn_cls is FlashSelfAttention
603
+ self.layer_idx = layer_idx
604
+ self.return_residual = return_residual
605
+ self.checkpointing = checkpointing
606
+
607
+ def _forward_self_attn(
608
+ self, x: torch.FloatTensor, key_padding_mask: Optional[torch.BoolTensor]
609
+ ) -> torch.FloatTensor:
610
+ qkv = self.Wqkv(x)
611
+ qkv = rearrange(qkv, "... (three h d) -> ... three h d", three=3, d=self.head_dim)
612
+
613
+ if self.rotary_dim > 0:
614
+ qkv = self.rotary_emb(qkv)
615
+
616
+ if self.flash_attn:
617
+ batch_size, seqlen = qkv.shape[0], qkv.shape[1]
618
+
619
+ cu_seqlens, max_seqlen = None, None
620
+ if key_padding_mask is not None:
621
+ # If `key_padding_mask` is supplied, we need to unpad the input and retrieve
622
+ # the `cu_seqlens` and `max_seqlen` to be used by `flash-attn`
623
+ qkv, indices, cu_seqlens, max_seqlen = unpad_input(qkv, key_padding_mask)
624
+
625
+ if self.checkpointing:
626
+ attn_output = torch.utils.checkpoint.checkpoint(
627
+ self.inner_attn, qkv, cu_seqlens=cu_seqlens, max_seqlen=max_seqlen
628
+ )
629
+ else:
630
+ attn_output = self.inner_attn(qkv, cu_seqlens=cu_seqlens, max_seqlen=max_seqlen).to(qkv.device)
631
+
632
+ # If `key_padding_mask` is supplied, we need to pad the output back to the original shape
633
+ return pad_input(attn_output, indices, batch_size, seqlen) if key_padding_mask is not None else attn_output
634
+
635
+ if self.checkpointing:
636
+ return torch.utils.checkpoint.checkpoint(self.inner_attn, qkv, key_padding_mask=key_padding_mask)
637
+
638
+ return self.inner_attn(qkv, key_padding_mask=key_padding_mask)
639
+
640
+ def _forward_cross_attn(
641
+ self,
642
+ x: torch.FloatTensor,
643
+ past_key_values: Optional[InferenceParams],
644
+ key_padding_mask: Optional[torch.BoolTensor],
645
+ ) -> torch.FloatTensor:
646
+ batch_size = x.shape[0]
647
+
648
+ qkv = self.Wqkv(x)
649
+
650
+ q = qkv[..., : self.n_head * self.head_dim]
651
+ q = rearrange(q, "... (h d) -> ... h d", d=self.head_dim)
652
+
653
+ kv = qkv[..., self.n_head * self.head_dim :]
654
+ kv = rearrange(kv, "... (two hkv d) -> ... two hkv d", two=2, d=self.head_dim)
655
+
656
+ seqlen_offset = past_key_values.seqlen_offset if past_key_values is not None else 0
657
+ causal = None if seqlen_offset == 0 else False
658
+ if self.rotary_dim > 0:
659
+ q, kv = self.rotary_emb(q, kv=kv, seqlen_offset=seqlen_offset)
660
+
661
+ if past_key_values is not None:
662
+ kv = _update_kv_cache(kv, past_key_values, self.layer_idx)
663
+
664
+ if self.flash_attn:
665
+ batch_size, seqlen_q = q.shape[0], q.shape[1]
666
+ seqlen_k = kv.shape[1]
667
+
668
+ cu_seqlens_q, cu_seqlens_k, max_seqlen_q, max_seqlen_k = (
669
+ None,
670
+ None,
671
+ None,
672
+ None,
673
+ )
674
+ if key_padding_mask is not None:
675
+ kv, _, cu_seqlens_k, max_seqlen_k = unpad_input(kv, key_padding_mask)
676
+
677
+ if seqlen_q == 1:
678
+ key_padding_mask = torch.ones(batch_size, 1, device=q.device)
679
+ elif seqlen_q != seqlen_k:
680
+ key_padding_mask = key_padding_mask[:, -seqlen_q:]
681
+
682
+ q, indices_q, cu_seqlens_q, max_seqlen_q = unpad_input(q, key_padding_mask)
683
+
684
+ if self.checkpointing:
685
+ attn_output = torch.utils.checkpoint.checkpoint(
686
+ self.inner_cross_attn,
687
+ q,
688
+ kv,
689
+ causal=causal,
690
+ cu_seqlens=cu_seqlens_q,
691
+ max_seqlen=max_seqlen_q,
692
+ cu_seqlens_k=cu_seqlens_k,
693
+ max_seqlen_k=max_seqlen_k,
694
+ )
695
+ else:
696
+ attn_output = self.inner_cross_attn(
697
+ q,
698
+ kv,
699
+ causal=causal,
700
+ cu_seqlens=cu_seqlens_q,
701
+ max_seqlen=max_seqlen_q,
702
+ cu_seqlens_k=cu_seqlens_k,
703
+ max_seqlen_k=max_seqlen_k,
704
+ )
705
+
706
+ return (
707
+ pad_input(attn_output, indices_q, batch_size, max_seqlen_q)
708
+ if key_padding_mask is not None
709
+ else attn_output
710
+ )
711
+
712
+ if self.checkpointing:
713
+ return torch.utils.checkpoint.checkpoint(
714
+ self.inner_cross_attn,
715
+ q,
716
+ kv,
717
+ key_padding_mask=key_padding_mask,
718
+ causal=causal,
719
+ )
720
+
721
+ return self.inner_cross_attn(q, kv, key_padding_mask=key_padding_mask, causal=causal)
722
+
723
+ def forward(
724
+ self,
725
+ x: torch.FloatTensor,
726
+ past_key_values: Optional[InferenceParams] = None,
727
+ attention_mask: Optional[Union[torch.LongTensor, torch.BoolTensor]] = None,
728
+ **kwargs,
729
+ ) -> Tuple[torch.FloatTensor, torch.FloatTensor]:
730
+ if attention_mask is not None:
731
+ attention_mask = attention_mask.bool()
732
+ else:
733
+ attention_mask = None
734
+
735
+ # MHA
736
+ if self.n_head == self.n_head_kv:
737
+ if past_key_values is None:
738
+ # If `past_key_values` are not supplied, we run self-attention
739
+ attn_output = self._forward_self_attn(x, attention_mask)
740
+ else:
741
+ # If `past_key_values` are supplied, it means that we might have cached values and
742
+ # could take advantage of cross-attention
743
+ attn_output = self._forward_cross_attn(x, past_key_values, attention_mask)
744
+ # MQA / GQA
745
+ else:
746
+ # Regardless of `past_key_values` being supplied or not, it always use cross-attention
747
+ # because `q` and `kv` lengths might be different
748
+ attn_output = self._forward_cross_attn(x, past_key_values, attention_mask)
749
+
750
+ output = rearrange(attn_output, "... h d -> ... (h d)")
751
+ output = self.out_proj(output)
752
+
753
+ return output if not self.return_residual else (output, x)
754
+
755
+
756
+ class ParallelBlock(nn.Module):
757
+ """Parallel block.
758
+
759
+ This block applies parallel mixer and MLP layers to the input (used in GPT-J and CodeGen).
760
+
761
+ """
762
+
763
+ def __init__(
764
+ self,
765
+ config: PretrainedConfig,
766
+ block_idx: Optional[int] = None,
767
+ ) -> None:
768
+ super().__init__()
769
+
770
+ self.ln = nn.LayerNorm(config.n_embd, eps=config.layer_norm_epsilon)
771
+ self.resid_dropout = nn.Dropout(config.resid_pdrop)
772
+ self.block_idx = block_idx
773
+
774
+ self.mixer = MHA(config, layer_idx=block_idx)
775
+ self.mlp = MLP(config)
776
+
777
+ def forward(
778
+ self,
779
+ hidden_states: torch.FloatTensor,
780
+ past_key_values: Optional[Union[torch.FloatTensor, InferenceParams]] = None,
781
+ attention_mask: Optional[torch.BoolTensor] = None,
782
+ **kwargs,
783
+ ) -> torch.FloatTensor:
784
+ residual = hidden_states
785
+ hidden_states = self.ln(hidden_states)
786
+
787
+ attn_outputs = self.mixer(
788
+ hidden_states,
789
+ past_key_values=past_key_values,
790
+ attention_mask=attention_mask,
791
+ )
792
+ if isinstance(attn_outputs, tuple):
793
+ attn_outputs = attn_outputs[0]
794
+
795
+ attn_outputs = self.resid_dropout(attn_outputs)
796
+ feed_forward_hidden_states = self.resid_dropout(self.mlp(hidden_states))
797
+
798
+ hidden_states = attn_outputs + feed_forward_hidden_states + residual
799
+
800
+ return hidden_states
801
+
802
+
803
+ class CausalLMHead(nn.Module):
804
+ """Causal Language Modeling head.
805
+
806
+ Reference:
807
+ Improving Language Understanding by Generative Pre-Training.
808
+ https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf.
809
+
810
+ """
811
+
812
+ def __init__(self, config: PretrainedConfig) -> None:
813
+ super().__init__()
814
+
815
+ self.ln = nn.LayerNorm(config.n_embd, eps=config.layer_norm_epsilon)
816
+ self.linear = nn.Linear(config.n_embd, config.vocab_size)
817
+
818
+ def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
819
+ hidden_states = self.ln(hidden_states)
820
+ logits = self.linear(hidden_states).to(torch.float32)
821
+
822
+ return logits
823
+
824
+
825
+ class PhiPreTrainedModel(PreTrainedModel):
826
+ """Phi pre-trained model."""
827
+
828
+ config_class = PhiConfig
829
+ base_model_prefix = "transformer"
830
+ supports_gradient_checkpointing = True
831
+ _no_split_modules = ["ParallelBlock", "CLIPEncoderLayer", "Block"]
832
+
833
+ def __init__(self, *inputs, **kwargs) -> None:
834
+ super().__init__(*inputs, **kwargs)
835
+
836
+ def _init_weights(self, module: nn.Module) -> None:
837
+ if isinstance(module, (nn.Linear,)):
838
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
839
+ if module.bias is not None:
840
+ module.bias.data.zero_()
841
+ elif isinstance(module, nn.Embedding):
842
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
843
+ if module.padding_idx is not None:
844
+ module.weight.data[module.padding_idx].zero_()
845
+ elif isinstance(module, nn.LayerNorm):
846
+ if module.bias is not None:
847
+ module.bias.data.zero_()
848
+ module.weight.data.fill_(1.0)
849
+
850
+ def prepare_inputs_for_generation(
851
+ self,
852
+ input_ids: torch.LongTensor,
853
+ past_key_values: Optional[Union[torch.FloatTensor, InferenceParams]] = None,
854
+ attention_mask: Optional[Union[torch.LongTensor, torch.BoolTensor]] = None,
855
+ **kwargs,
856
+ ) -> Dict[str, Any]:
857
+ if past_key_values is None or not (isinstance(past_key_values, InferenceParams)):
858
+ past_key_values = InferenceParams(
859
+ max_seqlen=self.config.n_positions,
860
+ max_batch_size=input_ids.shape[0],
861
+ seqlen_offset=0,
862
+ batch_size_offset=0,
863
+ key_value_memory_dict={},
864
+ lengths_per_sample=None,
865
+ )
866
+ else:
867
+ # ======================================================================
868
+ # Assume that `past_key_values` has cached all tokens up to the last token in `input_ids`
869
+ # inference_params.key_value_memory_dict[layer_idx][batch_start:batch_end, sequence_start:sequence_end, ...]
870
+ # past_key_values.seqlen_offset = input_ids.shape[1] - 1
871
+ # ======================================================================
872
+ # I change the way of updating `past_key_values.seqlen_offset` to make the inference of imp work.
873
+ # [Edited by zhenwei - 2024-01-20 21:15]
874
+ input_ids = input_ids[:, -1].unsqueeze(-1)
875
+
876
+ return {
877
+ "input_ids": input_ids,
878
+ "past_key_values": past_key_values,
879
+ "attention_mask": attention_mask,
880
+ }
881
+
882
+
883
+ class LlavaMetaModel(ABC):
884
+ """
885
+ Define the APIs for building components that are related to image perceiving.
886
+ This implementation is based on the implementation from the Llave project.
887
+ """
888
+
889
+ def get_vision_tower(self):
890
+ vision_tower = getattr(self, 'vision_tower', None)
891
+ if type(vision_tower) is list:
892
+ vision_tower = vision_tower[0]
893
+ return vision_tower
894
+
895
+ def build_vision_tower(self, config):
896
+ self.vision_tower = VisionTower(config.vision_tower_cfg)
897
+
898
+ def build_vision_projector(self, config):
899
+ projector_type = getattr(config, 'mm_projector_type', 'linear')
900
+
901
+ if projector_type == 'linear':
902
+ self.mm_projector = nn.Linear(config.mm_hidden_size, config.hidden_size)
903
+ return
904
+
905
+ mlp_gelu_match = re.match(r'^mlp(\d+)x_gelu$', projector_type)
906
+ if mlp_gelu_match:
907
+ mlp_depth = int(mlp_gelu_match.group(1))
908
+ modules = [nn.Linear(config.mm_hidden_size, config.hidden_size)]
909
+ for _ in range(1, mlp_depth):
910
+ modules.append(nn.GELU())
911
+ modules.append(nn.Linear(config.hidden_size, config.hidden_size))
912
+ self.mm_projector = nn.Sequential(*modules)
913
+ return
914
+
915
+ if projector_type == 'identity':
916
+ self.mm_projector = nn.Identity()
917
+ return
918
+
919
+ raise ValueError(f'Unknown projector type: {projector_type}')
920
+
921
+
922
+ class ImpModel(PhiPreTrainedModel, LlavaMetaModel):
923
+ """Imp model. This implementation is modified from the implementation of Phi-2"""
924
+
925
+ config_class = ImpConfig
926
+ # _keys_to_ignore_on_load_missing = [""]
927
+ # _keys_to_ignore_on_load_unexpected = [r"h\.\d+\.mlp.(fc_in|fc_out)\.(weight|bias)"]
928
+
929
+ def __init__(self, config: ImpConfig) -> None:
930
+ super().__init__(config)
931
+
932
+ self.embd = Embedding(config)
933
+ self.h = nn.ModuleList([ParallelBlock(config, block_idx=i) for i in range(config.n_layer)])
934
+ self.gradient_checkpointing = False
935
+
936
+ if hasattr(config, "mm_vision_tower"):
937
+ self.build_vision_tower(config)
938
+ self.build_vision_projector(config)
939
+
940
+ self.post_init()
941
+
942
+ def embed_tokens(self, input_ids: torch.LongTensor) -> torch.FloatTensor:
943
+ return self.embd(input_ids)[0]
944
+
945
+ def get_input_embeddings(self) -> nn.Embedding:
946
+ return self.embd.wte
947
+
948
+ def set_input_embeddings(self, new_embeddings: nn.Embedding) -> None:
949
+ self.embd.wte = new_embeddings
950
+
951
+ def forward(
952
+ self,
953
+ input_ids: torch.LongTensor,
954
+ past_key_values: Optional[Union[torch.FloatTensor, InferenceParams]] = None,
955
+ attention_mask: Optional[torch.BoolTensor] = None,
956
+ inputs_embeds: Optional[torch.FloatTensor] = None
957
+ ) -> torch.FloatTensor:
958
+
959
+ if inputs_embeds is None:
960
+ hidden_states = self.embd(input_ids)
961
+ else:
962
+ hidden_states = inputs_embeds
963
+
964
+ for layer in self.h:
965
+ if self.gradient_checkpointing and self.training:
966
+
967
+ def create_custom_forward(module):
968
+ def custom_forward(*inputs):
969
+ # None for past_key_value
970
+ return module(*inputs)
971
+
972
+ return custom_forward
973
+
974
+ hidden_states = torch.utils.checkpoint.checkpoint(
975
+ create_custom_forward(layer),
976
+ hidden_states,
977
+ None,
978
+ attention_mask,
979
+ )
980
+ else:
981
+ hidden_states = layer(
982
+ hidden_states,
983
+ past_key_values=past_key_values,
984
+ attention_mask=attention_mask,
985
+ )
986
+
987
+ # I change the way of updating `past_key_values.seqlen_offset` to make the inference of imp work.
988
+ # [Edited by zhenwei - 2024-01-20 21:15]
989
+ if past_key_values is not None: # FIXME: when multi-batch inference, it is a bug
990
+ past_key_values.seqlen_offset += hidden_states.shape[1]
991
+
992
+ return hidden_states
993
+
994
+
995
+ class LlavaMetaForCausalLM(ABC):
996
+ """This implementation is based on the implementation from the Llave project."""
997
+
998
+ def init_constants(self, config):
999
+ self.IGNORE_INDEX = getattr(config, 'ignore_index', -100)
1000
+ self.IMAGE_TOKEN_INDEX = getattr(config, 'image_token_index', 50296)
1001
+ self.DEFAULT_IMAGE_TOKEN = getattr(config, 'image_token', "<image>")
1002
+
1003
+ @abstractmethod
1004
+ def get_model(self):
1005
+ pass
1006
+
1007
+ def get_vision_tower(self):
1008
+ return self.get_model().get_vision_tower()
1009
+
1010
+ def encode_images(self, images):
1011
+ image_features = self.get_model().get_vision_tower()(images)
1012
+ image_features = self.get_model().mm_projector(image_features)
1013
+ return image_features
1014
+
1015
+ def prepare_inputs_labels_for_multimodal(
1016
+ self, input_ids, position_ids, attention_mask, past_key_values, labels, images
1017
+ ):
1018
+ vision_tower = self.get_vision_tower()
1019
+ # if vision_tower is None or images is None or past_key_values.seqlen_offset != 0:
1020
+ if vision_tower is None or images is None or input_ids.shape[1] == 1:
1021
+ if past_key_values is not None and vision_tower is not None and images is not None and input_ids.shape[1] == 1:
1022
+ target_shape = past_key_values.seqlen_offset + 1
1023
+ # inference_params.key_value_memory_dict[layer_idx][batch_start:batch_end, sequence_start:sequence_end, ...]
1024
+ attention_mask = torch.cat((attention_mask, torch.ones(
1025
+ (attention_mask.shape[0], target_shape - attention_mask.shape[1]),
1026
+ dtype=attention_mask.dtype,
1027
+ device=attention_mask.device
1028
+ )), dim=1)
1029
+ position_ids = torch.sum(attention_mask, dim=1).unsqueeze(-1) - 1
1030
+ return input_ids, position_ids, attention_mask, past_key_values, None, labels
1031
+
1032
+ if type(images) is list or images.ndim == 5:
1033
+ concat_images = torch.cat([image for image in images], dim=0)
1034
+ concat_images = concat_images.to(device=self.device, dtype=vision_tower.dtype)
1035
+ image_features = self.encode_images(concat_images)
1036
+ split_sizes = [image.shape[0] for image in images]
1037
+ image_features = torch.split(image_features, split_sizes, dim=0)
1038
+ image_features = [x.flatten(0, 1).to(self.device) for x in image_features]
1039
+ else:
1040
+ images = images.to(device=self.device, dtype=vision_tower.dtype)
1041
+ image_features = self.encode_images(images).to(self.device)
1042
+
1043
+ # TODO: image start / end is not implemented here to support pretraining.
1044
+ if getattr(self.config, 'tune_mm_mlp_adapter', False) and getattr(self.config, 'mm_use_im_start_end', False):
1045
+ raise NotImplementedError
1046
+
1047
+ # Let's just add dummy tensors if they do not exist,
1048
+ # it is a headache to deal with None all the time.
1049
+ # But it is not ideal, and if you have a better idea,
1050
+ # please open an issue / submit a PR, thanks.
1051
+ _labels = labels
1052
+ _position_ids = position_ids
1053
+ _attention_mask = attention_mask
1054
+ if attention_mask is None:
1055
+ attention_mask = torch.ones_like(input_ids, dtype=torch.bool)
1056
+ else:
1057
+ attention_mask = attention_mask.bool()
1058
+ if position_ids is None:
1059
+ position_ids = torch.arange(0, input_ids.shape[1], dtype=torch.long, device=input_ids.device)
1060
+ if labels is None:
1061
+ labels = torch.full_like(input_ids, self.IGNORE_INDEX)
1062
+
1063
+ # remove the padding using attention_mask -- TODO: double check
1064
+ input_ids = [cur_input_ids[cur_attention_mask] for cur_input_ids, cur_attention_mask in zip(input_ids, attention_mask)]
1065
+ labels = [cur_labels[cur_attention_mask] for cur_labels, cur_attention_mask in zip(labels, attention_mask)]
1066
+
1067
+ new_input_embeds = []
1068
+ new_labels = []
1069
+ cur_image_idx = 0
1070
+ for batch_idx, cur_input_ids in enumerate(input_ids):
1071
+ num_images = (cur_input_ids == self.IMAGE_TOKEN_INDEX).sum()
1072
+ if num_images == 0:
1073
+ cur_image_features = image_features[cur_image_idx]
1074
+ cur_input_embeds_1 = self.get_model().embed_tokens(cur_input_ids)
1075
+ cur_input_embeds = torch.cat([cur_input_embeds_1, cur_image_features[0:0]], dim=0)
1076
+ new_input_embeds.append(cur_input_embeds)
1077
+ new_labels.append(labels[batch_idx])
1078
+ cur_image_idx += 1
1079
+ continue
1080
+
1081
+ image_token_indices = [-1] + torch.where(cur_input_ids == self.IMAGE_TOKEN_INDEX)[0].tolist() + [cur_input_ids.shape[0]]
1082
+ cur_input_ids_noim = []
1083
+ cur_labels = labels[batch_idx]
1084
+ cur_labels_noim = []
1085
+ for i in range(len(image_token_indices) - 1):
1086
+ cur_input_ids_noim.append(cur_input_ids[image_token_indices[i]+1:image_token_indices[i+1]])
1087
+ cur_labels_noim.append(cur_labels[image_token_indices[i]+1:image_token_indices[i+1]])
1088
+ split_sizes = [x.shape[0] for x in cur_labels_noim]
1089
+ cur_input_embeds = self.get_model().embed_tokens(torch.cat(cur_input_ids_noim))
1090
+ # print(cur_input_embeds.shape)
1091
+ cur_input_embeds_no_im = torch.split(cur_input_embeds, split_sizes, dim=0)
1092
+ cur_new_input_embeds = []
1093
+ cur_new_labels = []
1094
+
1095
+ for i in range(num_images + 1):
1096
+ cur_new_input_embeds.append(cur_input_embeds_no_im[i])
1097
+ cur_new_labels.append(cur_labels_noim[i])
1098
+ if i < num_images:
1099
+ cur_image_features = image_features[cur_image_idx]
1100
+ cur_image_idx += 1
1101
+ cur_new_input_embeds.append(cur_image_features)
1102
+ cur_new_labels.append(torch.full((cur_image_features.shape[0],), self.IGNORE_INDEX, device=cur_labels.device, dtype=cur_labels.dtype))
1103
+
1104
+ cur_new_input_embeds = torch.cat(cur_new_input_embeds)
1105
+ cur_new_labels = torch.cat(cur_new_labels)
1106
+
1107
+ new_input_embeds.append(cur_new_input_embeds)
1108
+ new_labels.append(cur_new_labels)
1109
+
1110
+ # Truncate sequences to max length as image embeddings can make the sequence longer
1111
+ tokenizer_model_max_length = getattr(self.config, 'tokenizer_model_max_length', None)
1112
+ if tokenizer_model_max_length is not None:
1113
+ new_input_embeds = [x[:tokenizer_model_max_length] for x in new_input_embeds]
1114
+ new_labels = [x[:tokenizer_model_max_length] for x in new_labels]
1115
+
1116
+ # Combine them
1117
+ max_len = max(x.shape[0] for x in new_input_embeds)
1118
+ batch_size = len(new_input_embeds)
1119
+
1120
+ new_input_embeds_padded = []
1121
+ new_labels_padded = torch.full((batch_size, max_len), self.IGNORE_INDEX, dtype=new_labels[0].dtype, device=new_labels[0].device)
1122
+ attention_mask = torch.zeros((batch_size, max_len), dtype=attention_mask.dtype, device=attention_mask.device)
1123
+ position_ids = torch.zeros((batch_size, max_len), dtype=position_ids.dtype, device=position_ids.device)
1124
+
1125
+ for i, (cur_new_embed, cur_new_labels) in enumerate(zip(new_input_embeds, new_labels)):
1126
+ cur_len = cur_new_embed.shape[0]
1127
+ if getattr(self.config, 'tokenizer_padding_side', 'right') == "left":
1128
+ new_input_embeds_padded.append(torch.cat((
1129
+ torch.zeros((max_len - cur_len, cur_new_embed.shape[1]), dtype=cur_new_embed.dtype, device=cur_new_embed.device),
1130
+ cur_new_embed
1131
+ ), dim=0))
1132
+ if cur_len > 0:
1133
+ new_labels_padded[i, -cur_len:] = cur_new_labels
1134
+ attention_mask[i, -cur_len:] = True
1135
+ position_ids[i, -cur_len:] = torch.arange(0, cur_len, dtype=position_ids.dtype, device=position_ids.device)
1136
+ else:
1137
+ new_input_embeds_padded.append(torch.cat((
1138
+ cur_new_embed,
1139
+ torch.zeros((max_len - cur_len, cur_new_embed.shape[1]), dtype=cur_new_embed.dtype, device=cur_new_embed.device)
1140
+ ), dim=0))
1141
+ if cur_len > 0:
1142
+ new_labels_padded[i, :cur_len] = cur_new_labels
1143
+ attention_mask[i, :cur_len] = True
1144
+ position_ids[i, :cur_len] = torch.arange(0, cur_len, dtype=position_ids.dtype, device=position_ids.device)
1145
+
1146
+ new_input_embeds = torch.stack(new_input_embeds_padded, dim=0)
1147
+
1148
+ if _labels is None:
1149
+ new_labels = None
1150
+ else:
1151
+ new_labels = new_labels_padded
1152
+
1153
+ if _attention_mask is None:
1154
+ attention_mask = None
1155
+ else:
1156
+ attention_mask = attention_mask.to(dtype=_attention_mask.dtype)
1157
+
1158
+ if _position_ids is None:
1159
+ position_ids = None
1160
+
1161
+ return None, position_ids, attention_mask, past_key_values, new_input_embeds, new_labels
1162
+
1163
+
1164
+ class ImpForCausalLM(PhiPreTrainedModel, LlavaMetaForCausalLM):
1165
+ """Imp for Causal Language Modeling."""
1166
+
1167
+ # _keys_to_ignore_on_load_missing = [""]
1168
+ # _keys_to_ignore_on_load_unexpected = [r"transformer\.h\.\d+\.mlp.(fc_in|fc_out)\.(weight|bias)"]
1169
+ config_class = ImpConfig
1170
+
1171
+ def __init__(self, config: ImpConfig) -> None:
1172
+ super().__init__(config)
1173
+
1174
+ self.transformer = ImpModel(config)
1175
+ self.lm_head = CausalLMHead(config)
1176
+
1177
+ self.post_init()
1178
+ self.init_constants(config)
1179
+
1180
+ def get_output_embeddings(self) -> nn.Linear:
1181
+ return self.lm_head.linear
1182
+
1183
+ def set_output_embeddings(self, new_embeddings: nn.Linear) -> None:
1184
+ self.lm_head.linear = new_embeddings
1185
+
1186
+ def get_model(self):
1187
+ return self.transformer
1188
+
1189
+ def image_preprocess(self, images):
1190
+ return self.get_vision_tower().image_processor(images)['pixel_values']
1191
+
1192
+ def backbone_forward(
1193
+ self,
1194
+ input_ids: torch.LongTensor,
1195
+ past_key_values: Optional[Union[torch.FloatTensor, InferenceParams]] = None,
1196
+ attention_mask: Optional[torch.BoolTensor] = None,
1197
+ labels: Optional[torch.LongTensor] = None,
1198
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1199
+ **kwargs,
1200
+ ) -> CausalLMOutputWithPast:
1201
+ hidden_states = self.transformer(input_ids, past_key_values=past_key_values, attention_mask=attention_mask, inputs_embeds=inputs_embeds)
1202
+ lm_logits = self.lm_head(hidden_states)
1203
+
1204
+ return CausalLMOutputWithPast(loss=None, logits=lm_logits, past_key_values=past_key_values)
1205
+
1206
+ def forward(
1207
+ self,
1208
+ input_ids: torch.LongTensor = None,
1209
+ attention_mask: Optional[torch.Tensor] = None,
1210
+ position_ids: Optional[torch.LongTensor] = None,
1211
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1212
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1213
+ labels: Optional[torch.LongTensor] = None,
1214
+ use_cache: Optional[bool] = None,
1215
+ output_attentions: Optional[bool] = None,
1216
+ output_hidden_states: Optional[bool] = None,
1217
+ images: Optional[torch.FloatTensor] = None,
1218
+ return_dict: Optional[bool] = None,
1219
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1220
+
1221
+ if inputs_embeds is None:
1222
+ (
1223
+ input_ids,
1224
+ position_ids,
1225
+ attention_mask,
1226
+ past_key_values,
1227
+ inputs_embeds,
1228
+ labels
1229
+ ) = self.prepare_inputs_labels_for_multimodal(
1230
+ input_ids,
1231
+ position_ids,
1232
+ attention_mask,
1233
+ past_key_values,
1234
+ labels,
1235
+ images
1236
+ )
1237
+
1238
+ return self.backbone_forward(
1239
+ input_ids=input_ids,
1240
+ attention_mask=attention_mask,
1241
+ position_ids=position_ids,
1242
+ past_key_values=past_key_values,
1243
+ inputs_embeds=inputs_embeds,
1244
+ labels=labels,
1245
+ use_cache=use_cache,
1246
+ output_attentions=output_attentions,
1247
+ output_hidden_states=output_hidden_states,
1248
+ return_dict=return_dict
1249
+ )
1250
+
1251
+ def prepare_inputs_for_generation(self, input_ids, past_key_values=None, inputs_embeds=None, **kwargs):
1252
+ images = kwargs.pop("images", None)
1253
+ _inputs = super().prepare_inputs_for_generation(
1254
+ input_ids, past_key_values=past_key_values, inputs_embeds=inputs_embeds, **kwargs
1255
+ )
1256
+ if images is not None:
1257
+ _inputs['images'] = images
1258
+ return _inputs
1259
+
1260
+
1261
+ AutoConfig.register("imp", ImpConfig)
1262
+ AutoModelForCausalLM.register(ImpConfig, ImpForCausalLM)
special_tokens_map.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "</s>",
4
+ "unk_token": "<|endoftext|>"
5
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "50296": {
6
+ "content": "<image>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "50295": {
14
+ "content": "</s>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "50256": {
22
+ "content": "<|endoftext|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "50257": {
30
+ "content": " ",
31
+ "lstrip": false,
32
+ "normalized": true,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": false
36
+ },
37
+ "50258": {
38
+ "content": " ",
39
+ "lstrip": false,
40
+ "normalized": true,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": false
44
+ },
45
+ "50259": {
46
+ "content": " ",
47
+ "lstrip": false,
48
+ "normalized": true,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": false
52
+ },
53
+ "50260": {
54
+ "content": " ",
55
+ "lstrip": false,
56
+ "normalized": true,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": false
60
+ },
61
+ "50261": {
62
+ "content": " ",
63
+ "lstrip": false,
64
+ "normalized": true,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": false
68
+ },
69
+ "50262": {
70
+ "content": " ",
71
+ "lstrip": false,
72
+ "normalized": true,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": false
76
+ },
77
+ "50263": {
78
+ "content": " ",
79
+ "lstrip": false,
80
+ "normalized": true,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": false
84
+ },
85
+ "50264": {
86
+ "content": " ",
87
+ "lstrip": false,
88
+ "normalized": true,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": false
92
+ },
93
+ "50265": {
94
+ "content": " ",
95
+ "lstrip": false,
96
+ "normalized": true,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": false
100
+ },
101
+ "50266": {
102
+ "content": " ",
103
+ "lstrip": false,
104
+ "normalized": true,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": false
108
+ },
109
+ "50267": {
110
+ "content": " ",
111
+ "lstrip": false,
112
+ "normalized": true,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": false
116
+ },
117
+ "50268": {
118
+ "content": " ",
119
+ "lstrip": false,
120
+ "normalized": true,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "50269": {
126
+ "content": " ",
127
+ "lstrip": false,
128
+ "normalized": true,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "50270": {
134
+ "content": " ",
135
+ "lstrip": false,
136
+ "normalized": true,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "50271": {
142
+ "content": " ",
143
+ "lstrip": false,
144
+ "normalized": true,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "50272": {
150
+ "content": " ",
151
+ "lstrip": false,
152
+ "normalized": true,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "50273": {
158
+ "content": " ",
159
+ "lstrip": false,
160
+ "normalized": true,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "50274": {
166
+ "content": " ",
167
+ "lstrip": false,
168
+ "normalized": true,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "50275": {
174
+ "content": " ",
175
+ "lstrip": false,
176
+ "normalized": true,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "50276": {
182
+ "content": " ",
183
+ "lstrip": false,
184
+ "normalized": true,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "50277": {
190
+ "content": " ",
191
+ "lstrip": false,
192
+ "normalized": true,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "50278": {
198
+ "content": " ",
199
+ "lstrip": false,
200
+ "normalized": true,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "50279": {
206
+ "content": " ",
207
+ "lstrip": false,
208
+ "normalized": true,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ },
213
+ "50280": {
214
+ "content": " ",
215
+ "lstrip": false,
216
+ "normalized": true,
217
+ "rstrip": false,
218
+ "single_word": false,
219
+ "special": false
220
+ },
221
+ "50281": {
222
+ "content": " ",
223
+ "lstrip": false,
224
+ "normalized": true,
225
+ "rstrip": false,
226
+ "single_word": false,
227
+ "special": false
228
+ },
229
+ "50282": {
230
+ "content": " ",
231
+ "lstrip": false,
232
+ "normalized": true,
233
+ "rstrip": false,
234
+ "single_word": false,
235
+ "special": false
236
+ },
237
+ "50283": {
238
+ "content": " ",
239
+ "lstrip": false,
240
+ "normalized": true,
241
+ "rstrip": false,
242
+ "single_word": false,
243
+ "special": false
244
+ },
245
+ "50284": {
246
+ "content": " ",
247
+ "lstrip": false,
248
+ "normalized": true,
249
+ "rstrip": false,
250
+ "single_word": false,
251
+ "special": false
252
+ },
253
+ "50285": {
254
+ "content": " ",
255
+ "lstrip": false,
256
+ "normalized": true,
257
+ "rstrip": false,
258
+ "single_word": false,
259
+ "special": false
260
+ },
261
+ "50286": {
262
+ "content": " ",
263
+ "lstrip": false,
264
+ "normalized": true,
265
+ "rstrip": false,
266
+ "single_word": false,
267
+ "special": false
268
+ },
269
+ "50287": {
270
+ "content": "\t\t\t\t\t\t\t\t\t",
271
+ "lstrip": false,
272
+ "normalized": true,
273
+ "rstrip": false,
274
+ "single_word": false,
275
+ "special": false
276
+ },
277
+ "50288": {
278
+ "content": "\t\t\t\t\t\t\t\t",
279
+ "lstrip": false,
280
+ "normalized": true,
281
+ "rstrip": false,
282
+ "single_word": false,
283
+ "special": false
284
+ },
285
+ "50289": {
286
+ "content": "\t\t\t\t\t\t\t",
287
+ "lstrip": false,
288
+ "normalized": true,
289
+ "rstrip": false,
290
+ "single_word": false,
291
+ "special": false
292
+ },
293
+ "50290": {
294
+ "content": "\t\t\t\t\t\t",
295
+ "lstrip": false,
296
+ "normalized": true,
297
+ "rstrip": false,
298
+ "single_word": false,
299
+ "special": false
300
+ },
301
+ "50291": {
302
+ "content": "\t\t\t\t\t",
303
+ "lstrip": false,
304
+ "normalized": true,
305
+ "rstrip": false,
306
+ "single_word": false,
307
+ "special": false
308
+ },
309
+ "50292": {
310
+ "content": "\t\t\t\t",
311
+ "lstrip": false,
312
+ "normalized": true,
313
+ "rstrip": false,
314
+ "single_word": false,
315
+ "special": false
316
+ },
317
+ "50293": {
318
+ "content": "\t\t\t",
319
+ "lstrip": false,
320
+ "normalized": true,
321
+ "rstrip": false,
322
+ "single_word": false,
323
+ "special": false
324
+ },
325
+ "50294": {
326
+ "content": "\t\t",
327
+ "lstrip": false,
328
+ "normalized": true,
329
+ "rstrip": false,
330
+ "single_word": false,
331
+ "special": false
332
+ }
333
+ },
334
+ "bos_token": {
335
+ "__type": "AddedToken",
336
+ "content": "<|endoftext|>",
337
+ "lstrip": false,
338
+ "normalized": true,
339
+ "rstrip": false,
340
+ "single_word": false
341
+ },
342
+ "clean_up_tokenization_spaces": true,
343
+ "eos_token": {
344
+ "__type": "AddedToken",
345
+ "content": "<|endoftext|>",
346
+ "lstrip": false,
347
+ "normalized": true,
348
+ "rstrip": false,
349
+ "single_word": false
350
+ },
351
+ "errors": "replace",
352
+ "model_max_length": 3072,
353
+ "pad_token": null,
354
+ "tokenizer_class": "CodeGenTokenizer",
355
+ "unk_token": {
356
+ "__type": "AddedToken",
357
+ "content": "<|endoftext|>",
358
+ "lstrip": false,
359
+ "normalized": true,
360
+ "rstrip": false,
361
+ "single_word": false
362
+ }
363
+ }
vision_encoder.py ADDED
@@ -0,0 +1,613 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) MILVLG team.
2
+ # Licensed under the Apache 2.0 license.
3
+ #
4
+ # Some code here is copied from the project Phi-2 (https://huggingface.co/microsoft/phi-2),
5
+ # SigLIP@transformers==4.37.0.dev0 (https://huggingface.co/google/siglip-so400m-patch14-384),
6
+ # and Llava (https://github.com/haotian-liu/LLaVA), and modified by
7
+ # Zhenwei Shao ([email protected]) @ MILVLG. We thank them for their great works.
8
+ # And their original licenses and copyright should be inherited (see the statements
9
+ # in `configuration_imp.py` for more details).
10
+
11
+
12
+ from typing import Any, Optional, Tuple, Union, List, Dict
13
+ from dataclasses import dataclass
14
+ import math
15
+ import warnings
16
+ from functools import partial, reduce
17
+
18
+
19
+ import numpy as np
20
+ from PIL import Image
21
+ import torch
22
+ import torch.utils.checkpoint
23
+ from torch import nn
24
+
25
+ from transformers.image_processing_utils import BatchFeature
26
+ from transformers.image_transforms import (
27
+ convert_to_rgb,
28
+ normalize,
29
+ rescale,
30
+ resize,
31
+ to_channel_dimension_format,
32
+ )
33
+ from transformers.image_utils import (
34
+ ChannelDimension,
35
+ PILImageResampling,
36
+ to_numpy_array,
37
+ )
38
+ from transformers.activations import ACT2FN
39
+ from transformers.modeling_outputs import BaseModelOutput, BaseModelOutputWithPooling
40
+ from transformers.modeling_utils import PreTrainedModel
41
+ from transformers.utils import ModelOutput
42
+
43
+ from .configuration_imp import SiglipVisionConfig
44
+
45
+
46
+ # ============================================================================
47
+ # A simple image preprocessor for SigLIP models.
48
+ # ============================================================================
49
+
50
+ def expand2square(pil_img, background_color):
51
+ width, height = pil_img.size
52
+ if width == height:
53
+ return pil_img
54
+ elif width > height:
55
+ result = Image.new(pil_img.mode, (width, width), background_color)
56
+ result.paste(pil_img, (0, (width - height) // 2))
57
+ return result
58
+ else:
59
+ result = Image.new(pil_img.mode, (height, height), background_color)
60
+ result.paste(pil_img, ((height - width) // 2, 0))
61
+ return result
62
+
63
+ def simple_image_processor(
64
+ images,
65
+ image_mean=(0.5, 0.5, 0.5),
66
+ image_std=(0.5, 0.5, 0.5),
67
+ size=(384, 384),
68
+ resample=PILImageResampling.BICUBIC,
69
+ rescale_factor=1 / 255,
70
+ data_format=ChannelDimension.FIRST,
71
+ return_tensors="pt"
72
+ ):
73
+
74
+ if isinstance(images, Image.Image):
75
+ images = [images]
76
+ else:
77
+ assert isinstance(images, list)
78
+
79
+ new_images = []
80
+ for image in images:
81
+ image = expand2square(image, tuple(int(x*255) for x in image_mean))
82
+ new_images.append(image)
83
+ images=new_images
84
+
85
+ transforms = [
86
+ convert_to_rgb,
87
+ to_numpy_array,
88
+ partial(resize, size=size, resample=resample, data_format=data_format),
89
+ partial(rescale, scale=rescale_factor, data_format=data_format),
90
+ partial(normalize, mean=image_mean, std=image_std, data_format=data_format),
91
+ partial(to_channel_dimension_format, channel_dim=data_format, input_channel_dim=data_format),
92
+ ]
93
+
94
+ images = reduce(lambda x, f: [*map(f, x)], transforms, images)
95
+ data = {"pixel_values": images}
96
+
97
+ return BatchFeature(data=data, tensor_type=return_tensors)
98
+
99
+ # ============================================================================
100
+ # Definitions for SigLIP models.
101
+ # ============================================================================
102
+
103
+ @dataclass
104
+ # Copied from transformers.models.clip.modeling_clip.CLIPVisionModelOutput with CLIP->Siglip
105
+ class SiglipVisionModelOutput(ModelOutput):
106
+ """
107
+ Base class for vision model's outputs that also contains image embeddings of the pooling of the last hidden states.
108
+
109
+ Args:
110
+ image_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim)` *optional* returned when model is initialized with `with_projection=True`):
111
+ The image embeddings obtained by applying the projection layer to the pooler_output.
112
+ last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
113
+ Sequence of hidden-states at the output of the last layer of the model.
114
+ hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
115
+ Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
116
+ one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
117
+
118
+ Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
119
+ attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
120
+ Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
121
+ sequence_length)`.
122
+
123
+ Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
124
+ heads.
125
+ """
126
+
127
+ image_embeds: Optional[torch.FloatTensor] = None
128
+ last_hidden_state: torch.FloatTensor = None
129
+ hidden_states: Optional[Tuple[torch.FloatTensor]] = None
130
+ attentions: Optional[Tuple[torch.FloatTensor]] = None
131
+
132
+
133
+ class SiglipVisionEmbeddings(nn.Module):
134
+ def __init__(self, config: SiglipVisionConfig):
135
+ super().__init__()
136
+ self.config = config
137
+ self.embed_dim = config.hidden_size
138
+ self.image_size = config.image_size
139
+ self.patch_size = config.patch_size
140
+
141
+ self.patch_embedding = nn.Conv2d(
142
+ in_channels=config.num_channels,
143
+ out_channels=self.embed_dim,
144
+ kernel_size=self.patch_size,
145
+ stride=self.patch_size,
146
+ padding="valid",
147
+ )
148
+
149
+ self.num_patches = (self.image_size // self.patch_size) ** 2
150
+ self.num_positions = self.num_patches
151
+ self.position_embedding = nn.Embedding(self.num_positions, self.embed_dim)
152
+ self.register_buffer("position_ids", torch.arange(self.num_positions).expand((1, -1)), persistent=False)
153
+
154
+ def forward(self, pixel_values: torch.FloatTensor) -> torch.Tensor:
155
+ patch_embeds = self.patch_embedding(pixel_values) # shape = [*, width, grid, grid]
156
+ embeddings = patch_embeds.flatten(2).transpose(1, 2)
157
+
158
+ embeddings = embeddings + self.position_embedding(self.position_ids)
159
+ return embeddings
160
+
161
+
162
+
163
+ class SiglipAttention(nn.Module):
164
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
165
+
166
+ # Copied from transformers.models.clip.modeling_clip.CLIPAttention.__init__
167
+ def __init__(self, config):
168
+ super().__init__()
169
+ self.config = config
170
+ self.embed_dim = config.hidden_size
171
+ self.num_heads = config.num_attention_heads
172
+ self.head_dim = self.embed_dim // self.num_heads
173
+ if self.head_dim * self.num_heads != self.embed_dim:
174
+ raise ValueError(
175
+ f"embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim} and `num_heads`:"
176
+ f" {self.num_heads})."
177
+ )
178
+ self.scale = self.head_dim**-0.5
179
+ self.dropout = config.attention_dropout
180
+
181
+ self.k_proj = nn.Linear(self.embed_dim, self.embed_dim)
182
+ self.v_proj = nn.Linear(self.embed_dim, self.embed_dim)
183
+ self.q_proj = nn.Linear(self.embed_dim, self.embed_dim)
184
+ self.out_proj = nn.Linear(self.embed_dim, self.embed_dim)
185
+
186
+ def forward(
187
+ self,
188
+ hidden_states: torch.Tensor,
189
+ attention_mask: Optional[torch.Tensor] = None,
190
+ output_attentions: Optional[bool] = False,
191
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
192
+ """Input shape: Batch x Time x Channel"""
193
+
194
+ batch_size, q_len, _ = hidden_states.size()
195
+
196
+ query_states = self.q_proj(hidden_states)
197
+ key_states = self.k_proj(hidden_states)
198
+ value_states = self.v_proj(hidden_states)
199
+
200
+ query_states = query_states.view(batch_size, q_len, self.num_heads, self.head_dim).transpose(1, 2)
201
+ key_states = key_states.view(batch_size, q_len, self.num_heads, self.head_dim).transpose(1, 2)
202
+ value_states = value_states.view(batch_size, q_len, self.num_heads, self.head_dim).transpose(1, 2)
203
+
204
+ k_v_seq_len = key_states.shape[-2]
205
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) * self.scale
206
+
207
+ if attn_weights.size() != (batch_size, self.num_heads, q_len, k_v_seq_len):
208
+ raise ValueError(
209
+ f"Attention weights should be of size {(batch_size, self.num_heads, q_len, k_v_seq_len)}, but is"
210
+ f" {attn_weights.size()}"
211
+ )
212
+
213
+ if attention_mask is not None:
214
+ if attention_mask.size() != (batch_size, 1, q_len, k_v_seq_len):
215
+ raise ValueError(
216
+ f"Attention mask should be of size {(batch_size, 1, q_len, k_v_seq_len)}, but is {attention_mask.size()}"
217
+ )
218
+ attn_weights = attn_weights + attention_mask
219
+
220
+ # upcast attention to fp32
221
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
222
+ attn_weights = nn.functional.dropout(attn_weights, p=self.dropout, training=self.training)
223
+ attn_output = torch.matmul(attn_weights, value_states)
224
+
225
+ if attn_output.size() != (batch_size, self.num_heads, q_len, self.head_dim):
226
+ raise ValueError(
227
+ f"`attn_output` should be of size {(batch_size, self.num_heads, q_len, self.head_dim)}, but is"
228
+ f" {attn_output.size()}"
229
+ )
230
+
231
+ attn_output = attn_output.transpose(1, 2).contiguous()
232
+ attn_output = attn_output.reshape(batch_size, q_len, self.embed_dim)
233
+
234
+ attn_output = self.out_proj(attn_output)
235
+
236
+ return attn_output, attn_weights
237
+
238
+
239
+ # Copied from transformers.models.clip.modeling_clip.CLIPMLP with CLIP->Siglip
240
+ class SiglipMLP(nn.Module):
241
+ def __init__(self, config):
242
+ super().__init__()
243
+ self.config = config
244
+ self.activation_fn = ACT2FN[config.hidden_act]
245
+ self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
246
+ self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)
247
+
248
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
249
+ hidden_states = self.fc1(hidden_states)
250
+ hidden_states = self.activation_fn(hidden_states)
251
+ hidden_states = self.fc2(hidden_states)
252
+ return hidden_states
253
+
254
+
255
+ # Copied from transformers.models.clip.modeling_clip.CLIPEncoderLayer with CLIP->Siglip
256
+ class SiglipEncoderLayer(nn.Module):
257
+ def __init__(self, config: SiglipVisionConfig):
258
+ super().__init__()
259
+ self.embed_dim = config.hidden_size
260
+ self.self_attn = SiglipAttention(config)
261
+ self.layer_norm1 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
262
+ self.mlp = SiglipMLP(config)
263
+ self.layer_norm2 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
264
+
265
+ # Ignore copy
266
+ def forward(
267
+ self,
268
+ hidden_states: torch.Tensor,
269
+ attention_mask: torch.Tensor,
270
+ output_attentions: Optional[bool] = False,
271
+ ) -> Tuple[torch.FloatTensor]:
272
+ """
273
+ Args:
274
+ hidden_states (`torch.FloatTensor`):
275
+ Input to the layer of shape `(batch, seq_len, embed_dim)`.
276
+ attention_mask (`torch.FloatTensor`):
277
+ Attention mask of shape `(batch, 1, q_len, k_v_seq_len)` where padding elements are indicated by very large negative values.
278
+ output_attentions (`bool`, *optional*, defaults to `False`):
279
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
280
+ returned tensors for more detail.
281
+ """
282
+ residual = hidden_states
283
+
284
+ hidden_states = self.layer_norm1(hidden_states)
285
+ hidden_states, attn_weights = self.self_attn(
286
+ hidden_states=hidden_states,
287
+ attention_mask=attention_mask,
288
+ output_attentions=output_attentions,
289
+ )
290
+ hidden_states = residual + hidden_states
291
+
292
+ residual = hidden_states
293
+ hidden_states = self.layer_norm2(hidden_states)
294
+ hidden_states = self.mlp(hidden_states)
295
+ hidden_states = residual + hidden_states
296
+
297
+ outputs = (hidden_states,)
298
+
299
+ if output_attentions:
300
+ outputs += (attn_weights,)
301
+
302
+ return outputs
303
+
304
+
305
+ class SiglipPreTrainedModel(PreTrainedModel):
306
+ """
307
+ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
308
+ models.
309
+ """
310
+
311
+ config_class = SiglipVisionConfig
312
+ base_model_prefix = "siglip"
313
+ supports_gradient_checkpointing = True
314
+
315
+ def _init_weights(self, module):
316
+ """Initialize the weights"""
317
+ pass
318
+
319
+ # Copied from transformers.models.clip.modeling_clip.CLIPEncoder with CLIP->Siglip
320
+ class SiglipEncoder(nn.Module):
321
+ """
322
+ Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
323
+ [`SiglipEncoderLayer`].
324
+
325
+ Args:
326
+ config: SiglipVisionConfig
327
+ """
328
+
329
+ def __init__(self, config: SiglipVisionConfig):
330
+ super().__init__()
331
+ self.config = config
332
+ self.layers = nn.ModuleList([SiglipEncoderLayer(config) for _ in range(config.num_hidden_layers)])
333
+ self.gradient_checkpointing = False
334
+
335
+ # Ignore copy
336
+ def forward(
337
+ self,
338
+ inputs_embeds,
339
+ attention_mask: Optional[torch.Tensor] = None,
340
+ output_attentions: Optional[bool] = None,
341
+ output_hidden_states: Optional[bool] = None,
342
+ return_dict: Optional[bool] = None,
343
+ ) -> Union[Tuple, BaseModelOutput]:
344
+ r"""
345
+ Args:
346
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
347
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
348
+ This is useful if you want more control over how to convert `input_ids` indices into associated vectors
349
+ than the model's internal embedding lookup matrix.
350
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
351
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
352
+
353
+ - 1 for tokens that are **not masked**,
354
+ - 0 for tokens that are **masked**.
355
+
356
+ [What are attention masks?](../glossary#attention-mask)
357
+ output_attentions (`bool`, *optional*):
358
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
359
+ returned tensors for more detail.
360
+ output_hidden_states (`bool`, *optional*):
361
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
362
+ for more detail.
363
+ return_dict (`bool`, *optional*):
364
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
365
+ """
366
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
367
+ output_hidden_states = (
368
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
369
+ )
370
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
371
+
372
+ encoder_states = () if output_hidden_states else None
373
+ all_attentions = () if output_attentions else None
374
+
375
+ hidden_states = inputs_embeds
376
+ for encoder_layer in self.layers:
377
+ if output_hidden_states:
378
+ encoder_states = encoder_states + (hidden_states,)
379
+ if self.gradient_checkpointing and self.training:
380
+ layer_outputs = self._gradient_checkpointing_func(
381
+ encoder_layer.__call__,
382
+ hidden_states,
383
+ attention_mask,
384
+ output_attentions,
385
+ )
386
+ else:
387
+ layer_outputs = encoder_layer(
388
+ hidden_states,
389
+ attention_mask,
390
+ output_attentions=output_attentions,
391
+ )
392
+
393
+ hidden_states = layer_outputs[0]
394
+
395
+ if output_attentions:
396
+ all_attentions = all_attentions + (layer_outputs[1],)
397
+
398
+ if output_hidden_states:
399
+ encoder_states = encoder_states + (hidden_states,)
400
+
401
+ if not return_dict:
402
+ return tuple(v for v in [hidden_states, encoder_states, all_attentions] if v is not None)
403
+ return BaseModelOutput(
404
+ last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions
405
+ )
406
+
407
+
408
+ class SiglipVisionTransformer(nn.Module):
409
+ def __init__(self, config: SiglipVisionConfig):
410
+ super().__init__()
411
+ self.config = config
412
+ embed_dim = config.hidden_size
413
+
414
+ self.embeddings = SiglipVisionEmbeddings(config)
415
+ self.encoder = SiglipEncoder(config)
416
+ self.post_layernorm = nn.LayerNorm(embed_dim, eps=config.layer_norm_eps)
417
+ self.head = SiglipMultiheadAttentionPoolingHead(config)
418
+
419
+ def forward(
420
+ self,
421
+ pixel_values,
422
+ output_attentions: Optional[bool] = None,
423
+ output_hidden_states: Optional[bool] = None,
424
+ return_dict: Optional[bool] = None,
425
+ ) -> Union[Tuple, BaseModelOutputWithPooling]:
426
+ r"""
427
+ Returns:
428
+
429
+ """
430
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
431
+ output_hidden_states = (
432
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
433
+ )
434
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
435
+
436
+ hidden_states = self.embeddings(pixel_values)
437
+
438
+ encoder_outputs = self.encoder(
439
+ inputs_embeds=hidden_states,
440
+ output_attentions=output_attentions,
441
+ output_hidden_states=output_hidden_states,
442
+ return_dict=return_dict,
443
+ )
444
+
445
+ last_hidden_state = encoder_outputs[0]
446
+ last_hidden_state = self.post_layernorm(last_hidden_state)
447
+
448
+ pooled_output = self.head(last_hidden_state)
449
+
450
+ if not return_dict:
451
+ return (last_hidden_state, pooled_output) + encoder_outputs[1:]
452
+
453
+ return BaseModelOutputWithPooling(
454
+ last_hidden_state=last_hidden_state,
455
+ pooler_output=pooled_output,
456
+ hidden_states=encoder_outputs.hidden_states,
457
+ attentions=encoder_outputs.attentions,
458
+ )
459
+
460
+
461
+ class SiglipMultiheadAttentionPoolingHead(nn.Module):
462
+ """Multihead Attention Pooling."""
463
+
464
+ def __init__(self, config: SiglipVisionConfig):
465
+ super().__init__()
466
+
467
+ self.probe = nn.Parameter(torch.randn(1, 1, config.hidden_size))
468
+ self.attention = torch.nn.MultiheadAttention(config.hidden_size, config.num_attention_heads, batch_first=True)
469
+ self.layernorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
470
+ self.mlp = SiglipMLP(config)
471
+
472
+ def forward(self, hidden_state):
473
+ batch_size = hidden_state.shape[0]
474
+ probe = self.probe.repeat(batch_size, 1, 1)
475
+
476
+ hidden_state = self.attention(probe, hidden_state, hidden_state)[0]
477
+
478
+ residual = hidden_state
479
+ hidden_state = self.layernorm(hidden_state)
480
+ hidden_state = residual + self.mlp(hidden_state)
481
+
482
+ return hidden_state[:, 0]
483
+
484
+
485
+ class SiglipVisionModel(SiglipPreTrainedModel):
486
+ config_class = SiglipVisionConfig
487
+ main_input_name = "pixel_values"
488
+ _no_split_modules = ["SiglipEncoderLayer"]
489
+
490
+ def __init__(self, config: SiglipVisionConfig):
491
+ super().__init__(config)
492
+
493
+ self.vision_model = SiglipVisionTransformer(config)
494
+
495
+ # Initialize weights and apply final processing
496
+ self.post_init()
497
+
498
+ def get_input_embeddings(self) -> nn.Module:
499
+ return self.vision_model.embeddings.patch_embedding
500
+
501
+ def forward(
502
+ self,
503
+ pixel_values,
504
+ output_attentions: Optional[bool] = None,
505
+ output_hidden_states: Optional[bool] = None,
506
+ return_dict: Optional[bool] = None,
507
+ ) -> Union[Tuple, BaseModelOutputWithPooling]:
508
+ r"""
509
+ Returns:
510
+
511
+ Examples:
512
+
513
+ ```python
514
+ >>> from PIL import Image
515
+ >>> import requests
516
+ >>> from transformers import AutoProcessor, SiglipVisionModel
517
+
518
+ >>> model = SiglipVisionModel.from_pretrained("google/siglip-base-patch16-224")
519
+ >>> processor = AutoProcessor.from_pretrained("google/siglip-base-patch16-224")
520
+
521
+ >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
522
+ >>> image = Image.open(requests.get(url, stream=True).raw)
523
+
524
+ >>> inputs = processor(images=image, return_tensors="pt")
525
+
526
+ >>> outputs = model(**inputs)
527
+ >>> last_hidden_state = outputs.last_hidden_state
528
+ >>> pooled_output = outputs.pooler_output # pooled features
529
+ ```"""
530
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
531
+
532
+ return self.vision_model(
533
+ pixel_values=pixel_values,
534
+ output_attentions=output_attentions,
535
+ output_hidden_states=output_hidden_states,
536
+ return_dict=return_dict,
537
+ )
538
+
539
+
540
+ # ============================================================================
541
+ # VisionTower module for Imp
542
+ # ============================================================================
543
+
544
+ class VisionTower(nn.Module):
545
+ def __init__(self, vision_tower_cfg, delay_load=False):
546
+ super().__init__()
547
+
548
+ self.is_loaded = False
549
+
550
+ self.config = vision_tower_cfg
551
+ self.vision_tower_name = vision_tower_cfg.mm_vision_tower
552
+ self.select_layer = vision_tower_cfg.mm_vision_select_layer
553
+ # self.select_feature = getattr(vision_tower_cfg, 'mm_vision_select_feature', 'patch')
554
+
555
+ self.image_processor = simple_image_processor
556
+
557
+ if not delay_load:
558
+ self.load_model()
559
+ else:
560
+ raise NotImplementedError("delay load is not implemented yet.")
561
+
562
+ def load_model(self):
563
+ if self.is_loaded:
564
+ return
565
+
566
+ # "google/siglip-so400m-patch14-384"
567
+ # self.vision_tower = SiglipVisionModel.from_pretrained(self.vision_tower_name)
568
+ self.vision_tower = SiglipVisionModel(self.config)
569
+ del self.vision_tower.vision_model.encoder.layers[(self.select_layer + 1):]
570
+ self.vision_tower.vision_model.head = nn.Identity()
571
+ self.vision_tower.vision_model.post_layernorm=nn.Identity()
572
+ self.vision_tower.requires_grad_(False)
573
+ self.vision_tower.eval()
574
+
575
+ self.is_loaded = True
576
+
577
+ @torch.no_grad()
578
+ def forward(self, images):
579
+ if type(images) is list:
580
+ image_features = []
581
+ for image in images:
582
+ image_forward_out = self.vision_tower(image.to(device=self.device, dtype=self.dtype).unsqueeze(0), output_hidden_states=True)
583
+ image_feature = image_forward_out.hidden_states[-1].to(image.dtype)
584
+ assert image_features.shape[-2] == 729
585
+ image_features.append(image_feature)
586
+ else:
587
+ image_forward_outs = self.vision_tower(images.to(device=self.device, dtype=self.dtype), output_hidden_states=True)
588
+ image_features = image_forward_outs.hidden_states[-1].to(images.dtype)
589
+ assert image_features.shape[-2] == 729
590
+
591
+ return image_features
592
+
593
+ @property
594
+ def dummy_feature(self):
595
+ return torch.zeros(1, self.hidden_size, device=self.device, dtype=self.dtype)
596
+
597
+ @property
598
+ def dtype(self):
599
+ for p in self.vision_tower.parameters():
600
+ return p.dtype
601
+
602
+ @property
603
+ def device(self):
604
+ for p in self.vision_tower.parameters():
605
+ return p.device
606
+
607
+ @property
608
+ def hidden_size(self):
609
+ return self.config.hidden_size
610
+
611
+ @property
612
+ def num_patches(self):
613
+ return (self.config.image_size // self.config.patch_size) ** 2
vocab.json ADDED
The diff for this file is too large to render. See raw diff