Upload EMOVAForConditionalGeneration
Browse files- README.md +199 -0
- config.json +51 -0
- configuration_emova.py +160 -0
- configuration_qwen2vit.py +71 -0
- generation_config.json +6 -0
- model-00001-of-00004.safetensors +3 -0
- model-00002-of-00004.safetensors +3 -0
- model-00003-of-00004.safetensors +3 -0
- model-00004-of-00004.safetensors +3 -0
- model.safetensors.index.json +741 -0
- modeling_emova.py +816 -0
- modeling_qwen2vit.py +335 -0
README.md
ADDED
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers
|
3 |
+
tags: []
|
4 |
+
---
|
5 |
+
|
6 |
+
# Model Card for Model ID
|
7 |
+
|
8 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
## Model Details
|
13 |
+
|
14 |
+
### Model Description
|
15 |
+
|
16 |
+
<!-- Provide a longer summary of what this model is. -->
|
17 |
+
|
18 |
+
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
+
|
20 |
+
- **Developed by:** [More Information Needed]
|
21 |
+
- **Funded by [optional]:** [More Information Needed]
|
22 |
+
- **Shared by [optional]:** [More Information Needed]
|
23 |
+
- **Model type:** [More Information Needed]
|
24 |
+
- **Language(s) (NLP):** [More Information Needed]
|
25 |
+
- **License:** [More Information Needed]
|
26 |
+
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
+
|
28 |
+
### Model Sources [optional]
|
29 |
+
|
30 |
+
<!-- Provide the basic links for the model. -->
|
31 |
+
|
32 |
+
- **Repository:** [More Information Needed]
|
33 |
+
- **Paper [optional]:** [More Information Needed]
|
34 |
+
- **Demo [optional]:** [More Information Needed]
|
35 |
+
|
36 |
+
## Uses
|
37 |
+
|
38 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
+
|
40 |
+
### Direct Use
|
41 |
+
|
42 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
+
|
44 |
+
[More Information Needed]
|
45 |
+
|
46 |
+
### Downstream Use [optional]
|
47 |
+
|
48 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
+
|
50 |
+
[More Information Needed]
|
51 |
+
|
52 |
+
### Out-of-Scope Use
|
53 |
+
|
54 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
+
|
56 |
+
[More Information Needed]
|
57 |
+
|
58 |
+
## Bias, Risks, and Limitations
|
59 |
+
|
60 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
+
|
62 |
+
[More Information Needed]
|
63 |
+
|
64 |
+
### Recommendations
|
65 |
+
|
66 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
+
|
68 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
+
|
70 |
+
## How to Get Started with the Model
|
71 |
+
|
72 |
+
Use the code below to get started with the model.
|
73 |
+
|
74 |
+
[More Information Needed]
|
75 |
+
|
76 |
+
## Training Details
|
77 |
+
|
78 |
+
### Training Data
|
79 |
+
|
80 |
+
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
+
|
82 |
+
[More Information Needed]
|
83 |
+
|
84 |
+
### Training Procedure
|
85 |
+
|
86 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
+
|
88 |
+
#### Preprocessing [optional]
|
89 |
+
|
90 |
+
[More Information Needed]
|
91 |
+
|
92 |
+
|
93 |
+
#### Training Hyperparameters
|
94 |
+
|
95 |
+
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
+
|
97 |
+
#### Speeds, Sizes, Times [optional]
|
98 |
+
|
99 |
+
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
+
|
101 |
+
[More Information Needed]
|
102 |
+
|
103 |
+
## Evaluation
|
104 |
+
|
105 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
+
|
107 |
+
### Testing Data, Factors & Metrics
|
108 |
+
|
109 |
+
#### Testing Data
|
110 |
+
|
111 |
+
<!-- This should link to a Dataset Card if possible. -->
|
112 |
+
|
113 |
+
[More Information Needed]
|
114 |
+
|
115 |
+
#### Factors
|
116 |
+
|
117 |
+
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
+
|
119 |
+
[More Information Needed]
|
120 |
+
|
121 |
+
#### Metrics
|
122 |
+
|
123 |
+
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
+
|
125 |
+
[More Information Needed]
|
126 |
+
|
127 |
+
### Results
|
128 |
+
|
129 |
+
[More Information Needed]
|
130 |
+
|
131 |
+
#### Summary
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
## Model Examination [optional]
|
136 |
+
|
137 |
+
<!-- Relevant interpretability work for the model goes here -->
|
138 |
+
|
139 |
+
[More Information Needed]
|
140 |
+
|
141 |
+
## Environmental Impact
|
142 |
+
|
143 |
+
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
+
|
145 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
+
|
147 |
+
- **Hardware Type:** [More Information Needed]
|
148 |
+
- **Hours used:** [More Information Needed]
|
149 |
+
- **Cloud Provider:** [More Information Needed]
|
150 |
+
- **Compute Region:** [More Information Needed]
|
151 |
+
- **Carbon Emitted:** [More Information Needed]
|
152 |
+
|
153 |
+
## Technical Specifications [optional]
|
154 |
+
|
155 |
+
### Model Architecture and Objective
|
156 |
+
|
157 |
+
[More Information Needed]
|
158 |
+
|
159 |
+
### Compute Infrastructure
|
160 |
+
|
161 |
+
[More Information Needed]
|
162 |
+
|
163 |
+
#### Hardware
|
164 |
+
|
165 |
+
[More Information Needed]
|
166 |
+
|
167 |
+
#### Software
|
168 |
+
|
169 |
+
[More Information Needed]
|
170 |
+
|
171 |
+
## Citation [optional]
|
172 |
+
|
173 |
+
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
+
|
175 |
+
**BibTeX:**
|
176 |
+
|
177 |
+
[More Information Needed]
|
178 |
+
|
179 |
+
**APA:**
|
180 |
+
|
181 |
+
[More Information Needed]
|
182 |
+
|
183 |
+
## Glossary [optional]
|
184 |
+
|
185 |
+
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
+
|
187 |
+
[More Information Needed]
|
188 |
+
|
189 |
+
## More Information [optional]
|
190 |
+
|
191 |
+
[More Information Needed]
|
192 |
+
|
193 |
+
## Model Card Authors [optional]
|
194 |
+
|
195 |
+
[More Information Needed]
|
196 |
+
|
197 |
+
## Model Card Contact
|
198 |
+
|
199 |
+
[More Information Needed]
|
config.json
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/8tssd1/kchenbf/cache/emova-qwen-2-5-7b-hf/",
|
3 |
+
"architectures": [
|
4 |
+
"EMOVAForConditionalGeneration"
|
5 |
+
],
|
6 |
+
"auto_map": {
|
7 |
+
"AutoConfig": "configuration_emova.EMOVAConfig",
|
8 |
+
"AutoModel": "modeling_emova.EMOVAForConditionalGeneration",
|
9 |
+
"AutoModelForCausalLM": "modeling_emova.EMOVAForConditionalGeneration"
|
10 |
+
},
|
11 |
+
"default_system_prompt": "You are a helpful assistant.",
|
12 |
+
"ignore_index": -100,
|
13 |
+
"image_token_index": 155761,
|
14 |
+
"mm_projector_config": {
|
15 |
+
"mlp_depth": 2,
|
16 |
+
"trainable": true,
|
17 |
+
"type": "MLPProjector"
|
18 |
+
},
|
19 |
+
"model_type": "emova",
|
20 |
+
"text_config": {
|
21 |
+
"architectures": [
|
22 |
+
"Qwen2ForCausalLM"
|
23 |
+
],
|
24 |
+
"bos_token_id": 151643,
|
25 |
+
"eos_token_id": 151645,
|
26 |
+
"hidden_size": 3584,
|
27 |
+
"intermediate_size": 18944,
|
28 |
+
"max_position_embeddings": 32768,
|
29 |
+
"max_window_layers": 28,
|
30 |
+
"model_type": "qwen2",
|
31 |
+
"num_attention_heads": 28,
|
32 |
+
"num_hidden_layers": 28,
|
33 |
+
"num_key_value_heads": 4,
|
34 |
+
"rope_theta": 1000000.0,
|
35 |
+
"sliding_window": null,
|
36 |
+
"torch_dtype": "float32",
|
37 |
+
"use_sliding_window": false,
|
38 |
+
"vocab_size": 155776
|
39 |
+
},
|
40 |
+
"tie_word_embeddings": false,
|
41 |
+
"torch_dtype": "bfloat16",
|
42 |
+
"transformers_version": "4.44.2",
|
43 |
+
"vision_config": {
|
44 |
+
"max_pixels": 3211264,
|
45 |
+
"model_type": "qwen2_vl",
|
46 |
+
"pretrained_model_name_or_path": "Emova-ollm/qwen2vit600m",
|
47 |
+
"trainable": true,
|
48 |
+
"type": "Qwen2VisionTower",
|
49 |
+
"unfreeze_mm_vision_tower": true
|
50 |
+
}
|
51 |
+
}
|
configuration_emova.py
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
"""EMOVA model configuration"""
|
15 |
+
from transformers.configuration_utils import PretrainedConfig
|
16 |
+
from transformers.utils import logging
|
17 |
+
from transformers.models.auto import CONFIG_MAPPING
|
18 |
+
|
19 |
+
from .configuration_qwen2vit import Qwen2VLVisionConfig
|
20 |
+
|
21 |
+
logger = logging.get_logger(__name__)
|
22 |
+
|
23 |
+
|
24 |
+
class EMOVAConfig(PretrainedConfig):
|
25 |
+
r"""
|
26 |
+
This is the configuration class to store the configuration of a [`EMOVAForConditionalGeneration`]. It is used to instantiate an
|
27 |
+
EMOVA model according to the specified arguments, defining the model architecture.
|
28 |
+
|
29 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
30 |
+
documentation from [`PretrainedConfig`] for more information.
|
31 |
+
|
32 |
+
Args:
|
33 |
+
vision_config (`Union[AutoConfig, dict]`, *optional*, defaults to `CLIPVisionConfig`):
|
34 |
+
The config object or dictionary of the vision backbone.
|
35 |
+
text_config (`Union[AutoConfig, dict]`, *optional*, defaults to `LlamaConfig`):
|
36 |
+
The config object or dictionary of the text backbone.
|
37 |
+
ignore_index (`int`, *optional*, defaults to -100):
|
38 |
+
The ignore index for the loss function.
|
39 |
+
image_token_index (`int`, *optional*, defaults to 32000):
|
40 |
+
The image token index to encode the image prompt.
|
41 |
+
projector_hidden_act (`str`, *optional*, defaults to `"gelu"`):
|
42 |
+
The activation function used by the multimodal projector.
|
43 |
+
vision_feature_select_strategy (`str`, *optional*, defaults to `"default"`):
|
44 |
+
The feature selection strategy used to select the vision feature from the vision backbone.
|
45 |
+
Can be one of `"default"` or `"full"`. If `"default"`, the CLS token is removed from the vision features.
|
46 |
+
If `"full"`, the full vision features are used.
|
47 |
+
vision_feature_layer (`int`, *optional*, defaults to -2):
|
48 |
+
The index of the layer to select the vision feature.
|
49 |
+
image_grid_pinpoints (`List`, *optional*, defaults to `[[336, 672], [672, 336], [672, 672], [1008, 336], [336, 1008]]`):
|
50 |
+
A list of possible resolutions to use for processing high resolution images. Each item in the list should be a tuple or list
|
51 |
+
of the form `(height, width)`.
|
52 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
53 |
+
Whether the model's input and output word embeddings should be tied.
|
54 |
+
|
55 |
+
Example:
|
56 |
+
|
57 |
+
```python
|
58 |
+
>>> from transformers import EMOVAForConditionalGeneration, EMOVAConfig, CLIPVisionConfig, LlamaConfig
|
59 |
+
|
60 |
+
>>> # Initializing a CLIP-vision config
|
61 |
+
>>> vision_config = CLIPVisionConfig()
|
62 |
+
|
63 |
+
>>> # Initializing a Llama config
|
64 |
+
>>> text_config = LlamaConfig()
|
65 |
+
|
66 |
+
>>> # Initializing a EMOVA style configuration
|
67 |
+
>>> configuration = EMOVAConfig(vision_config, text_config)
|
68 |
+
|
69 |
+
>>> # Initializing a model from the style configuration
|
70 |
+
>>> model = EMOVAForConditionalGeneration(configuration)
|
71 |
+
|
72 |
+
>>> # Accessing the model configuration
|
73 |
+
>>> configuration = model.config
|
74 |
+
```"""
|
75 |
+
|
76 |
+
model_type = "emova"
|
77 |
+
is_composition = False
|
78 |
+
|
79 |
+
def __init__(
|
80 |
+
self,
|
81 |
+
vision_config=None,
|
82 |
+
mm_projector_config=None,
|
83 |
+
text_config=None,
|
84 |
+
ignore_index=-100,
|
85 |
+
image_token_index=32000,
|
86 |
+
vision_feature_select_strategy="default",
|
87 |
+
vision_feature_layer=-2,
|
88 |
+
is_native_resolution=True,
|
89 |
+
image_grid_pinpoints=None,
|
90 |
+
use_image_newline_parameter=False,
|
91 |
+
tie_word_embeddings=False,
|
92 |
+
**kwargs,
|
93 |
+
):
|
94 |
+
self.ignore_index = ignore_index
|
95 |
+
self.image_token_index = image_token_index
|
96 |
+
|
97 |
+
if vision_feature_select_strategy not in ["default", "full"]:
|
98 |
+
raise ValueError(
|
99 |
+
"vision_feature_select_strategy should be one of 'default', 'full'."
|
100 |
+
f"Got: {vision_feature_select_strategy}"
|
101 |
+
)
|
102 |
+
|
103 |
+
# self.vision_feature_select_strategy = vision_feature_select_strategy
|
104 |
+
# self.vision_feature_layer = vision_feature_layer
|
105 |
+
# image_grid_pinpoints = (
|
106 |
+
# image_grid_pinpoints
|
107 |
+
# if image_grid_pinpoints is not None
|
108 |
+
# else [[336, 672], [672, 336], [672, 672], [1008, 336], [336, 1008]]
|
109 |
+
# )
|
110 |
+
# self.is_native_resolution = is_native_resolution
|
111 |
+
# self.image_grid_pinpoints = image_grid_pinpoints if not self.is_native_resolution else None
|
112 |
+
# self.use_image_newline_parameter = use_image_newline_parameter
|
113 |
+
|
114 |
+
if isinstance(vision_config, dict):
|
115 |
+
vision_config = Qwen2VLVisionConfig(**vision_config)
|
116 |
+
elif vision_config is None:
|
117 |
+
vision_config = Qwen2VLVisionConfig(
|
118 |
+
depth=32,
|
119 |
+
embed_dim=1280,
|
120 |
+
hidden_act="quick_gelu",
|
121 |
+
hidden_size=3584,
|
122 |
+
in_channels=3,
|
123 |
+
in_chans=3,
|
124 |
+
mlp_ratio=4,
|
125 |
+
model_type="qwen2_vl",
|
126 |
+
num_heads=16,
|
127 |
+
patch_size=14,
|
128 |
+
spatial_merge_size=2,
|
129 |
+
spatial_patch_size=14,
|
130 |
+
temporal_patch_size=2,
|
131 |
+
initializer_range=0.02,
|
132 |
+
)
|
133 |
+
|
134 |
+
# if isinstance(vision_config, dict):
|
135 |
+
# vision_config["model_type"] = (
|
136 |
+
# vision_config["model_type"] if "model_type" in vision_config else "clip_vision_model"
|
137 |
+
# )
|
138 |
+
# vision_config = CONFIG_MAPPING[vision_config["model_type"]](**vision_config)
|
139 |
+
# elif vision_config is None:
|
140 |
+
# vision_config = CONFIG_MAPPING["clip_vision_model"](
|
141 |
+
# intermediate_size=4096,
|
142 |
+
# hidden_size=1024,
|
143 |
+
# patch_size=14,
|
144 |
+
# image_size=336,
|
145 |
+
# num_hidden_layers=24,
|
146 |
+
# num_attention_heads=16,
|
147 |
+
# vocab_size=32000,
|
148 |
+
# projection_dim=768,
|
149 |
+
# )
|
150 |
+
|
151 |
+
self.vision_config = vision_config
|
152 |
+
self.mm_projector_config = mm_projector_config
|
153 |
+
if isinstance(text_config, dict):
|
154 |
+
text_config["model_type"] = text_config["model_type"] if "model_type" in text_config else "llama"
|
155 |
+
text_config = CONFIG_MAPPING[text_config["model_type"]](**text_config)
|
156 |
+
elif text_config is None:
|
157 |
+
text_config = CONFIG_MAPPING["llama"]()
|
158 |
+
|
159 |
+
self.text_config = text_config
|
160 |
+
super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)
|
configuration_qwen2vit.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""Qwen2VL model configuration"""
|
16 |
+
|
17 |
+
import os
|
18 |
+
from typing import Union
|
19 |
+
|
20 |
+
from transformers.configuration_utils import PretrainedConfig
|
21 |
+
from transformers.utils import logging
|
22 |
+
|
23 |
+
logger = logging.get_logger(__name__)
|
24 |
+
|
25 |
+
|
26 |
+
class Qwen2VLVisionConfig(PretrainedConfig):
|
27 |
+
model_type = "qwen2_vl"
|
28 |
+
|
29 |
+
def __init__(
|
30 |
+
self,
|
31 |
+
depth=32,
|
32 |
+
embed_dim=1280,
|
33 |
+
hidden_size=3584,
|
34 |
+
hidden_act="quick_gelu",
|
35 |
+
mlp_ratio=4,
|
36 |
+
num_heads=16,
|
37 |
+
in_channels=3,
|
38 |
+
patch_size=14,
|
39 |
+
spatial_merge_size=2,
|
40 |
+
temporal_patch_size=2,
|
41 |
+
**kwargs,
|
42 |
+
):
|
43 |
+
super().__init__(**kwargs)
|
44 |
+
|
45 |
+
self.depth = depth
|
46 |
+
self.embed_dim = embed_dim
|
47 |
+
self.hidden_size = hidden_size
|
48 |
+
self.hidden_act = hidden_act
|
49 |
+
self.mlp_ratio = mlp_ratio
|
50 |
+
self.num_heads = num_heads
|
51 |
+
self.in_channels = in_channels
|
52 |
+
self.patch_size = patch_size
|
53 |
+
self.spatial_merge_size = spatial_merge_size
|
54 |
+
self.temporal_patch_size = temporal_patch_size
|
55 |
+
|
56 |
+
@classmethod
|
57 |
+
def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
|
58 |
+
cls._set_token_in_kwargs(kwargs)
|
59 |
+
|
60 |
+
config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
|
61 |
+
|
62 |
+
# if config_dict.get("model_type") == "qwen2_vl":
|
63 |
+
# config_dict = config_dict["vision_config"]
|
64 |
+
|
65 |
+
if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
|
66 |
+
logger.warning(
|
67 |
+
f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
|
68 |
+
f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
|
69 |
+
)
|
70 |
+
|
71 |
+
return cls.from_dict(config_dict, **kwargs)
|
generation_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 151643,
|
4 |
+
"eos_token_id": 151645,
|
5 |
+
"transformers_version": "4.44.2"
|
6 |
+
}
|
model-00001-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bc3a4159d2383c434613cd0273005331a59a33a3188ac70b3660e202285ec8f7
|
3 |
+
size 4908875200
|
model-00002-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e657ab12a61acc374acdbd087ad5b4640f64387bf868184f9124ffbcb77e6a7c
|
3 |
+
size 4932752808
|
model-00003-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b3f05e160738389c89a2c48790d2f1befb39118830957b67930afc8cc4c7dcef
|
3 |
+
size 4991497848
|
model-00004-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:849a82141a4b722c193ca108432d873a7231a9e029081d479e86038b931ac5be
|
3 |
+
size 1854322976
|
model.safetensors.index.json
ADDED
@@ -0,0 +1,741 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 16687361024
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"language_model.lm_head.weight": "model-00004-of-00004.safetensors",
|
7 |
+
"language_model.model.embed_tokens.weight": "model-00001-of-00004.safetensors",
|
8 |
+
"language_model.model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
9 |
+
"language_model.model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
10 |
+
"language_model.model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
11 |
+
"language_model.model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
12 |
+
"language_model.model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
13 |
+
"language_model.model.layers.0.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
14 |
+
"language_model.model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
15 |
+
"language_model.model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
16 |
+
"language_model.model.layers.0.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
17 |
+
"language_model.model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
18 |
+
"language_model.model.layers.0.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
19 |
+
"language_model.model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
20 |
+
"language_model.model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
21 |
+
"language_model.model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
22 |
+
"language_model.model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
23 |
+
"language_model.model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
24 |
+
"language_model.model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
25 |
+
"language_model.model.layers.1.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
26 |
+
"language_model.model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
27 |
+
"language_model.model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
28 |
+
"language_model.model.layers.1.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
29 |
+
"language_model.model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
30 |
+
"language_model.model.layers.1.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
31 |
+
"language_model.model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
32 |
+
"language_model.model.layers.10.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
33 |
+
"language_model.model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
34 |
+
"language_model.model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
35 |
+
"language_model.model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
36 |
+
"language_model.model.layers.10.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
37 |
+
"language_model.model.layers.10.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
38 |
+
"language_model.model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
39 |
+
"language_model.model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
40 |
+
"language_model.model.layers.10.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
41 |
+
"language_model.model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
42 |
+
"language_model.model.layers.10.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
43 |
+
"language_model.model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
44 |
+
"language_model.model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
45 |
+
"language_model.model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
46 |
+
"language_model.model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
47 |
+
"language_model.model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
48 |
+
"language_model.model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
49 |
+
"language_model.model.layers.11.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
50 |
+
"language_model.model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
51 |
+
"language_model.model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
52 |
+
"language_model.model.layers.11.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
53 |
+
"language_model.model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
54 |
+
"language_model.model.layers.11.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
55 |
+
"language_model.model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
56 |
+
"language_model.model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
57 |
+
"language_model.model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
58 |
+
"language_model.model.layers.12.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
59 |
+
"language_model.model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
60 |
+
"language_model.model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
61 |
+
"language_model.model.layers.12.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
62 |
+
"language_model.model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
63 |
+
"language_model.model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
64 |
+
"language_model.model.layers.12.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
65 |
+
"language_model.model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
66 |
+
"language_model.model.layers.12.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
67 |
+
"language_model.model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
68 |
+
"language_model.model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
69 |
+
"language_model.model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
70 |
+
"language_model.model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
71 |
+
"language_model.model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
72 |
+
"language_model.model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
73 |
+
"language_model.model.layers.13.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
74 |
+
"language_model.model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
75 |
+
"language_model.model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
76 |
+
"language_model.model.layers.13.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
77 |
+
"language_model.model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
78 |
+
"language_model.model.layers.13.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
79 |
+
"language_model.model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
80 |
+
"language_model.model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
81 |
+
"language_model.model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
82 |
+
"language_model.model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
83 |
+
"language_model.model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
84 |
+
"language_model.model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
85 |
+
"language_model.model.layers.14.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
86 |
+
"language_model.model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
87 |
+
"language_model.model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
88 |
+
"language_model.model.layers.14.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
89 |
+
"language_model.model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
90 |
+
"language_model.model.layers.14.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
91 |
+
"language_model.model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
92 |
+
"language_model.model.layers.15.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
93 |
+
"language_model.model.layers.15.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
94 |
+
"language_model.model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
95 |
+
"language_model.model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
96 |
+
"language_model.model.layers.15.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
97 |
+
"language_model.model.layers.15.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
98 |
+
"language_model.model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
99 |
+
"language_model.model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
100 |
+
"language_model.model.layers.15.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
101 |
+
"language_model.model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
102 |
+
"language_model.model.layers.15.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
103 |
+
"language_model.model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
104 |
+
"language_model.model.layers.16.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
105 |
+
"language_model.model.layers.16.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
106 |
+
"language_model.model.layers.16.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
107 |
+
"language_model.model.layers.16.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
108 |
+
"language_model.model.layers.16.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
109 |
+
"language_model.model.layers.16.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
110 |
+
"language_model.model.layers.16.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
111 |
+
"language_model.model.layers.16.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
112 |
+
"language_model.model.layers.16.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
113 |
+
"language_model.model.layers.16.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
114 |
+
"language_model.model.layers.16.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
115 |
+
"language_model.model.layers.16.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
116 |
+
"language_model.model.layers.17.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
117 |
+
"language_model.model.layers.17.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
118 |
+
"language_model.model.layers.17.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
119 |
+
"language_model.model.layers.17.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
120 |
+
"language_model.model.layers.17.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
121 |
+
"language_model.model.layers.17.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
122 |
+
"language_model.model.layers.17.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
123 |
+
"language_model.model.layers.17.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
124 |
+
"language_model.model.layers.17.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
125 |
+
"language_model.model.layers.17.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
126 |
+
"language_model.model.layers.17.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
127 |
+
"language_model.model.layers.17.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
128 |
+
"language_model.model.layers.18.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
129 |
+
"language_model.model.layers.18.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
130 |
+
"language_model.model.layers.18.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
131 |
+
"language_model.model.layers.18.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
132 |
+
"language_model.model.layers.18.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
133 |
+
"language_model.model.layers.18.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
134 |
+
"language_model.model.layers.18.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
135 |
+
"language_model.model.layers.18.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
136 |
+
"language_model.model.layers.18.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
137 |
+
"language_model.model.layers.18.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
138 |
+
"language_model.model.layers.18.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
139 |
+
"language_model.model.layers.18.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
140 |
+
"language_model.model.layers.19.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
141 |
+
"language_model.model.layers.19.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
142 |
+
"language_model.model.layers.19.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
143 |
+
"language_model.model.layers.19.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
144 |
+
"language_model.model.layers.19.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
145 |
+
"language_model.model.layers.19.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
146 |
+
"language_model.model.layers.19.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
147 |
+
"language_model.model.layers.19.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
148 |
+
"language_model.model.layers.19.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
149 |
+
"language_model.model.layers.19.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
150 |
+
"language_model.model.layers.19.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
151 |
+
"language_model.model.layers.19.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
152 |
+
"language_model.model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
153 |
+
"language_model.model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
154 |
+
"language_model.model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
155 |
+
"language_model.model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
156 |
+
"language_model.model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
157 |
+
"language_model.model.layers.2.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
158 |
+
"language_model.model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
159 |
+
"language_model.model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
160 |
+
"language_model.model.layers.2.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
161 |
+
"language_model.model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
162 |
+
"language_model.model.layers.2.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
163 |
+
"language_model.model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
164 |
+
"language_model.model.layers.20.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
165 |
+
"language_model.model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
166 |
+
"language_model.model.layers.20.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
167 |
+
"language_model.model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
168 |
+
"language_model.model.layers.20.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
169 |
+
"language_model.model.layers.20.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
170 |
+
"language_model.model.layers.20.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
171 |
+
"language_model.model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
172 |
+
"language_model.model.layers.20.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
173 |
+
"language_model.model.layers.20.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
174 |
+
"language_model.model.layers.20.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
175 |
+
"language_model.model.layers.20.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
176 |
+
"language_model.model.layers.21.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
177 |
+
"language_model.model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
178 |
+
"language_model.model.layers.21.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
179 |
+
"language_model.model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
180 |
+
"language_model.model.layers.21.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
181 |
+
"language_model.model.layers.21.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
182 |
+
"language_model.model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
183 |
+
"language_model.model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
184 |
+
"language_model.model.layers.21.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
185 |
+
"language_model.model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
186 |
+
"language_model.model.layers.21.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
187 |
+
"language_model.model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
188 |
+
"language_model.model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
189 |
+
"language_model.model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
190 |
+
"language_model.model.layers.22.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
191 |
+
"language_model.model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
192 |
+
"language_model.model.layers.22.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
193 |
+
"language_model.model.layers.22.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
194 |
+
"language_model.model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
195 |
+
"language_model.model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
196 |
+
"language_model.model.layers.22.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
197 |
+
"language_model.model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
198 |
+
"language_model.model.layers.22.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
199 |
+
"language_model.model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
200 |
+
"language_model.model.layers.23.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
201 |
+
"language_model.model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
202 |
+
"language_model.model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
203 |
+
"language_model.model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
204 |
+
"language_model.model.layers.23.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
205 |
+
"language_model.model.layers.23.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
206 |
+
"language_model.model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
207 |
+
"language_model.model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
208 |
+
"language_model.model.layers.23.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
209 |
+
"language_model.model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
210 |
+
"language_model.model.layers.23.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
211 |
+
"language_model.model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
212 |
+
"language_model.model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
213 |
+
"language_model.model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
214 |
+
"language_model.model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
215 |
+
"language_model.model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
216 |
+
"language_model.model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
217 |
+
"language_model.model.layers.24.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
218 |
+
"language_model.model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
219 |
+
"language_model.model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
220 |
+
"language_model.model.layers.24.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
221 |
+
"language_model.model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
222 |
+
"language_model.model.layers.24.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
223 |
+
"language_model.model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
224 |
+
"language_model.model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
225 |
+
"language_model.model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
226 |
+
"language_model.model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
227 |
+
"language_model.model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
228 |
+
"language_model.model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
229 |
+
"language_model.model.layers.25.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
230 |
+
"language_model.model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
231 |
+
"language_model.model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
232 |
+
"language_model.model.layers.25.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
233 |
+
"language_model.model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
234 |
+
"language_model.model.layers.25.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
235 |
+
"language_model.model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
236 |
+
"language_model.model.layers.26.input_layernorm.weight": "model-00004-of-00004.safetensors",
|
237 |
+
"language_model.model.layers.26.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
|
238 |
+
"language_model.model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
239 |
+
"language_model.model.layers.26.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
|
240 |
+
"language_model.model.layers.26.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
241 |
+
"language_model.model.layers.26.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
|
242 |
+
"language_model.model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
243 |
+
"language_model.model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
244 |
+
"language_model.model.layers.26.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
|
245 |
+
"language_model.model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
246 |
+
"language_model.model.layers.26.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
|
247 |
+
"language_model.model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
248 |
+
"language_model.model.layers.27.input_layernorm.weight": "model-00004-of-00004.safetensors",
|
249 |
+
"language_model.model.layers.27.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
|
250 |
+
"language_model.model.layers.27.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
251 |
+
"language_model.model.layers.27.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
|
252 |
+
"language_model.model.layers.27.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
253 |
+
"language_model.model.layers.27.self_attn.k_proj.bias": "model-00004-of-00004.safetensors",
|
254 |
+
"language_model.model.layers.27.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
|
255 |
+
"language_model.model.layers.27.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
|
256 |
+
"language_model.model.layers.27.self_attn.q_proj.bias": "model-00004-of-00004.safetensors",
|
257 |
+
"language_model.model.layers.27.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
|
258 |
+
"language_model.model.layers.27.self_attn.v_proj.bias": "model-00004-of-00004.safetensors",
|
259 |
+
"language_model.model.layers.27.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
|
260 |
+
"language_model.model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
261 |
+
"language_model.model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
262 |
+
"language_model.model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
263 |
+
"language_model.model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
264 |
+
"language_model.model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
265 |
+
"language_model.model.layers.3.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
266 |
+
"language_model.model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
267 |
+
"language_model.model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
268 |
+
"language_model.model.layers.3.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
269 |
+
"language_model.model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
270 |
+
"language_model.model.layers.3.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
271 |
+
"language_model.model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
272 |
+
"language_model.model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
273 |
+
"language_model.model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
274 |
+
"language_model.model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
275 |
+
"language_model.model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
276 |
+
"language_model.model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
277 |
+
"language_model.model.layers.4.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
278 |
+
"language_model.model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
279 |
+
"language_model.model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
280 |
+
"language_model.model.layers.4.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
281 |
+
"language_model.model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
282 |
+
"language_model.model.layers.4.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
283 |
+
"language_model.model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
284 |
+
"language_model.model.layers.5.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
285 |
+
"language_model.model.layers.5.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
286 |
+
"language_model.model.layers.5.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
287 |
+
"language_model.model.layers.5.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
288 |
+
"language_model.model.layers.5.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
289 |
+
"language_model.model.layers.5.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
|
290 |
+
"language_model.model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
291 |
+
"language_model.model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
292 |
+
"language_model.model.layers.5.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
|
293 |
+
"language_model.model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
294 |
+
"language_model.model.layers.5.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
|
295 |
+
"language_model.model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
296 |
+
"language_model.model.layers.6.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
297 |
+
"language_model.model.layers.6.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
298 |
+
"language_model.model.layers.6.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
299 |
+
"language_model.model.layers.6.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
300 |
+
"language_model.model.layers.6.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
301 |
+
"language_model.model.layers.6.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
302 |
+
"language_model.model.layers.6.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
303 |
+
"language_model.model.layers.6.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
304 |
+
"language_model.model.layers.6.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
305 |
+
"language_model.model.layers.6.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
306 |
+
"language_model.model.layers.6.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
307 |
+
"language_model.model.layers.6.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
308 |
+
"language_model.model.layers.7.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
309 |
+
"language_model.model.layers.7.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
310 |
+
"language_model.model.layers.7.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
311 |
+
"language_model.model.layers.7.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
312 |
+
"language_model.model.layers.7.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
313 |
+
"language_model.model.layers.7.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
314 |
+
"language_model.model.layers.7.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
315 |
+
"language_model.model.layers.7.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
316 |
+
"language_model.model.layers.7.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
317 |
+
"language_model.model.layers.7.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
318 |
+
"language_model.model.layers.7.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
319 |
+
"language_model.model.layers.7.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
320 |
+
"language_model.model.layers.8.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
321 |
+
"language_model.model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
322 |
+
"language_model.model.layers.8.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
323 |
+
"language_model.model.layers.8.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
324 |
+
"language_model.model.layers.8.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
325 |
+
"language_model.model.layers.8.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
326 |
+
"language_model.model.layers.8.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
327 |
+
"language_model.model.layers.8.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
328 |
+
"language_model.model.layers.8.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
329 |
+
"language_model.model.layers.8.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
330 |
+
"language_model.model.layers.8.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
331 |
+
"language_model.model.layers.8.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
332 |
+
"language_model.model.layers.9.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
333 |
+
"language_model.model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
334 |
+
"language_model.model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
335 |
+
"language_model.model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
336 |
+
"language_model.model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
337 |
+
"language_model.model.layers.9.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
|
338 |
+
"language_model.model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
339 |
+
"language_model.model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
340 |
+
"language_model.model.layers.9.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
|
341 |
+
"language_model.model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
342 |
+
"language_model.model.layers.9.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
|
343 |
+
"language_model.model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
344 |
+
"language_model.model.norm.weight": "model-00004-of-00004.safetensors",
|
345 |
+
"multi_modal_projector.0.bias": "model-00001-of-00004.safetensors",
|
346 |
+
"multi_modal_projector.0.weight": "model-00001-of-00004.safetensors",
|
347 |
+
"multi_modal_projector.2.bias": "model-00001-of-00004.safetensors",
|
348 |
+
"multi_modal_projector.2.weight": "model-00001-of-00004.safetensors",
|
349 |
+
"vision_tower.blocks.0.attn.proj.bias": "model-00001-of-00004.safetensors",
|
350 |
+
"vision_tower.blocks.0.attn.proj.weight": "model-00001-of-00004.safetensors",
|
351 |
+
"vision_tower.blocks.0.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
352 |
+
"vision_tower.blocks.0.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
353 |
+
"vision_tower.blocks.0.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
354 |
+
"vision_tower.blocks.0.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
355 |
+
"vision_tower.blocks.0.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
356 |
+
"vision_tower.blocks.0.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
357 |
+
"vision_tower.blocks.0.norm1.bias": "model-00001-of-00004.safetensors",
|
358 |
+
"vision_tower.blocks.0.norm1.weight": "model-00001-of-00004.safetensors",
|
359 |
+
"vision_tower.blocks.0.norm2.bias": "model-00001-of-00004.safetensors",
|
360 |
+
"vision_tower.blocks.0.norm2.weight": "model-00001-of-00004.safetensors",
|
361 |
+
"vision_tower.blocks.1.attn.proj.bias": "model-00001-of-00004.safetensors",
|
362 |
+
"vision_tower.blocks.1.attn.proj.weight": "model-00001-of-00004.safetensors",
|
363 |
+
"vision_tower.blocks.1.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
364 |
+
"vision_tower.blocks.1.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
365 |
+
"vision_tower.blocks.1.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
366 |
+
"vision_tower.blocks.1.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
367 |
+
"vision_tower.blocks.1.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
368 |
+
"vision_tower.blocks.1.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
369 |
+
"vision_tower.blocks.1.norm1.bias": "model-00001-of-00004.safetensors",
|
370 |
+
"vision_tower.blocks.1.norm1.weight": "model-00001-of-00004.safetensors",
|
371 |
+
"vision_tower.blocks.1.norm2.bias": "model-00001-of-00004.safetensors",
|
372 |
+
"vision_tower.blocks.1.norm2.weight": "model-00001-of-00004.safetensors",
|
373 |
+
"vision_tower.blocks.10.attn.proj.bias": "model-00001-of-00004.safetensors",
|
374 |
+
"vision_tower.blocks.10.attn.proj.weight": "model-00001-of-00004.safetensors",
|
375 |
+
"vision_tower.blocks.10.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
376 |
+
"vision_tower.blocks.10.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
377 |
+
"vision_tower.blocks.10.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
378 |
+
"vision_tower.blocks.10.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
379 |
+
"vision_tower.blocks.10.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
380 |
+
"vision_tower.blocks.10.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
381 |
+
"vision_tower.blocks.10.norm1.bias": "model-00001-of-00004.safetensors",
|
382 |
+
"vision_tower.blocks.10.norm1.weight": "model-00001-of-00004.safetensors",
|
383 |
+
"vision_tower.blocks.10.norm2.bias": "model-00001-of-00004.safetensors",
|
384 |
+
"vision_tower.blocks.10.norm2.weight": "model-00001-of-00004.safetensors",
|
385 |
+
"vision_tower.blocks.11.attn.proj.bias": "model-00001-of-00004.safetensors",
|
386 |
+
"vision_tower.blocks.11.attn.proj.weight": "model-00001-of-00004.safetensors",
|
387 |
+
"vision_tower.blocks.11.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
388 |
+
"vision_tower.blocks.11.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
389 |
+
"vision_tower.blocks.11.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
390 |
+
"vision_tower.blocks.11.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
391 |
+
"vision_tower.blocks.11.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
392 |
+
"vision_tower.blocks.11.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
393 |
+
"vision_tower.blocks.11.norm1.bias": "model-00001-of-00004.safetensors",
|
394 |
+
"vision_tower.blocks.11.norm1.weight": "model-00001-of-00004.safetensors",
|
395 |
+
"vision_tower.blocks.11.norm2.bias": "model-00001-of-00004.safetensors",
|
396 |
+
"vision_tower.blocks.11.norm2.weight": "model-00001-of-00004.safetensors",
|
397 |
+
"vision_tower.blocks.12.attn.proj.bias": "model-00001-of-00004.safetensors",
|
398 |
+
"vision_tower.blocks.12.attn.proj.weight": "model-00001-of-00004.safetensors",
|
399 |
+
"vision_tower.blocks.12.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
400 |
+
"vision_tower.blocks.12.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
401 |
+
"vision_tower.blocks.12.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
402 |
+
"vision_tower.blocks.12.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
403 |
+
"vision_tower.blocks.12.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
404 |
+
"vision_tower.blocks.12.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
405 |
+
"vision_tower.blocks.12.norm1.bias": "model-00001-of-00004.safetensors",
|
406 |
+
"vision_tower.blocks.12.norm1.weight": "model-00001-of-00004.safetensors",
|
407 |
+
"vision_tower.blocks.12.norm2.bias": "model-00001-of-00004.safetensors",
|
408 |
+
"vision_tower.blocks.12.norm2.weight": "model-00001-of-00004.safetensors",
|
409 |
+
"vision_tower.blocks.13.attn.proj.bias": "model-00001-of-00004.safetensors",
|
410 |
+
"vision_tower.blocks.13.attn.proj.weight": "model-00001-of-00004.safetensors",
|
411 |
+
"vision_tower.blocks.13.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
412 |
+
"vision_tower.blocks.13.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
413 |
+
"vision_tower.blocks.13.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
414 |
+
"vision_tower.blocks.13.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
415 |
+
"vision_tower.blocks.13.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
416 |
+
"vision_tower.blocks.13.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
417 |
+
"vision_tower.blocks.13.norm1.bias": "model-00001-of-00004.safetensors",
|
418 |
+
"vision_tower.blocks.13.norm1.weight": "model-00001-of-00004.safetensors",
|
419 |
+
"vision_tower.blocks.13.norm2.bias": "model-00001-of-00004.safetensors",
|
420 |
+
"vision_tower.blocks.13.norm2.weight": "model-00001-of-00004.safetensors",
|
421 |
+
"vision_tower.blocks.14.attn.proj.bias": "model-00001-of-00004.safetensors",
|
422 |
+
"vision_tower.blocks.14.attn.proj.weight": "model-00001-of-00004.safetensors",
|
423 |
+
"vision_tower.blocks.14.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
424 |
+
"vision_tower.blocks.14.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
425 |
+
"vision_tower.blocks.14.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
426 |
+
"vision_tower.blocks.14.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
427 |
+
"vision_tower.blocks.14.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
428 |
+
"vision_tower.blocks.14.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
429 |
+
"vision_tower.blocks.14.norm1.bias": "model-00001-of-00004.safetensors",
|
430 |
+
"vision_tower.blocks.14.norm1.weight": "model-00001-of-00004.safetensors",
|
431 |
+
"vision_tower.blocks.14.norm2.bias": "model-00001-of-00004.safetensors",
|
432 |
+
"vision_tower.blocks.14.norm2.weight": "model-00001-of-00004.safetensors",
|
433 |
+
"vision_tower.blocks.15.attn.proj.bias": "model-00001-of-00004.safetensors",
|
434 |
+
"vision_tower.blocks.15.attn.proj.weight": "model-00001-of-00004.safetensors",
|
435 |
+
"vision_tower.blocks.15.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
436 |
+
"vision_tower.blocks.15.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
437 |
+
"vision_tower.blocks.15.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
438 |
+
"vision_tower.blocks.15.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
439 |
+
"vision_tower.blocks.15.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
440 |
+
"vision_tower.blocks.15.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
441 |
+
"vision_tower.blocks.15.norm1.bias": "model-00001-of-00004.safetensors",
|
442 |
+
"vision_tower.blocks.15.norm1.weight": "model-00001-of-00004.safetensors",
|
443 |
+
"vision_tower.blocks.15.norm2.bias": "model-00001-of-00004.safetensors",
|
444 |
+
"vision_tower.blocks.15.norm2.weight": "model-00001-of-00004.safetensors",
|
445 |
+
"vision_tower.blocks.16.attn.proj.bias": "model-00001-of-00004.safetensors",
|
446 |
+
"vision_tower.blocks.16.attn.proj.weight": "model-00001-of-00004.safetensors",
|
447 |
+
"vision_tower.blocks.16.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
448 |
+
"vision_tower.blocks.16.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
449 |
+
"vision_tower.blocks.16.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
450 |
+
"vision_tower.blocks.16.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
451 |
+
"vision_tower.blocks.16.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
452 |
+
"vision_tower.blocks.16.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
453 |
+
"vision_tower.blocks.16.norm1.bias": "model-00001-of-00004.safetensors",
|
454 |
+
"vision_tower.blocks.16.norm1.weight": "model-00001-of-00004.safetensors",
|
455 |
+
"vision_tower.blocks.16.norm2.bias": "model-00001-of-00004.safetensors",
|
456 |
+
"vision_tower.blocks.16.norm2.weight": "model-00001-of-00004.safetensors",
|
457 |
+
"vision_tower.blocks.17.attn.proj.bias": "model-00001-of-00004.safetensors",
|
458 |
+
"vision_tower.blocks.17.attn.proj.weight": "model-00001-of-00004.safetensors",
|
459 |
+
"vision_tower.blocks.17.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
460 |
+
"vision_tower.blocks.17.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
461 |
+
"vision_tower.blocks.17.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
462 |
+
"vision_tower.blocks.17.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
463 |
+
"vision_tower.blocks.17.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
464 |
+
"vision_tower.blocks.17.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
465 |
+
"vision_tower.blocks.17.norm1.bias": "model-00001-of-00004.safetensors",
|
466 |
+
"vision_tower.blocks.17.norm1.weight": "model-00001-of-00004.safetensors",
|
467 |
+
"vision_tower.blocks.17.norm2.bias": "model-00001-of-00004.safetensors",
|
468 |
+
"vision_tower.blocks.17.norm2.weight": "model-00001-of-00004.safetensors",
|
469 |
+
"vision_tower.blocks.18.attn.proj.bias": "model-00001-of-00004.safetensors",
|
470 |
+
"vision_tower.blocks.18.attn.proj.weight": "model-00001-of-00004.safetensors",
|
471 |
+
"vision_tower.blocks.18.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
472 |
+
"vision_tower.blocks.18.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
473 |
+
"vision_tower.blocks.18.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
474 |
+
"vision_tower.blocks.18.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
475 |
+
"vision_tower.blocks.18.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
476 |
+
"vision_tower.blocks.18.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
477 |
+
"vision_tower.blocks.18.norm1.bias": "model-00001-of-00004.safetensors",
|
478 |
+
"vision_tower.blocks.18.norm1.weight": "model-00001-of-00004.safetensors",
|
479 |
+
"vision_tower.blocks.18.norm2.bias": "model-00001-of-00004.safetensors",
|
480 |
+
"vision_tower.blocks.18.norm2.weight": "model-00001-of-00004.safetensors",
|
481 |
+
"vision_tower.blocks.19.attn.proj.bias": "model-00001-of-00004.safetensors",
|
482 |
+
"vision_tower.blocks.19.attn.proj.weight": "model-00001-of-00004.safetensors",
|
483 |
+
"vision_tower.blocks.19.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
484 |
+
"vision_tower.blocks.19.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
485 |
+
"vision_tower.blocks.19.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
486 |
+
"vision_tower.blocks.19.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
487 |
+
"vision_tower.blocks.19.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
488 |
+
"vision_tower.blocks.19.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
489 |
+
"vision_tower.blocks.19.norm1.bias": "model-00001-of-00004.safetensors",
|
490 |
+
"vision_tower.blocks.19.norm1.weight": "model-00001-of-00004.safetensors",
|
491 |
+
"vision_tower.blocks.19.norm2.bias": "model-00001-of-00004.safetensors",
|
492 |
+
"vision_tower.blocks.19.norm2.weight": "model-00001-of-00004.safetensors",
|
493 |
+
"vision_tower.blocks.2.attn.proj.bias": "model-00001-of-00004.safetensors",
|
494 |
+
"vision_tower.blocks.2.attn.proj.weight": "model-00001-of-00004.safetensors",
|
495 |
+
"vision_tower.blocks.2.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
496 |
+
"vision_tower.blocks.2.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
497 |
+
"vision_tower.blocks.2.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
498 |
+
"vision_tower.blocks.2.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
499 |
+
"vision_tower.blocks.2.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
500 |
+
"vision_tower.blocks.2.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
501 |
+
"vision_tower.blocks.2.norm1.bias": "model-00001-of-00004.safetensors",
|
502 |
+
"vision_tower.blocks.2.norm1.weight": "model-00001-of-00004.safetensors",
|
503 |
+
"vision_tower.blocks.2.norm2.bias": "model-00001-of-00004.safetensors",
|
504 |
+
"vision_tower.blocks.2.norm2.weight": "model-00001-of-00004.safetensors",
|
505 |
+
"vision_tower.blocks.20.attn.proj.bias": "model-00001-of-00004.safetensors",
|
506 |
+
"vision_tower.blocks.20.attn.proj.weight": "model-00001-of-00004.safetensors",
|
507 |
+
"vision_tower.blocks.20.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
508 |
+
"vision_tower.blocks.20.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
509 |
+
"vision_tower.blocks.20.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
510 |
+
"vision_tower.blocks.20.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
511 |
+
"vision_tower.blocks.20.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
512 |
+
"vision_tower.blocks.20.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
513 |
+
"vision_tower.blocks.20.norm1.bias": "model-00001-of-00004.safetensors",
|
514 |
+
"vision_tower.blocks.20.norm1.weight": "model-00001-of-00004.safetensors",
|
515 |
+
"vision_tower.blocks.20.norm2.bias": "model-00001-of-00004.safetensors",
|
516 |
+
"vision_tower.blocks.20.norm2.weight": "model-00001-of-00004.safetensors",
|
517 |
+
"vision_tower.blocks.21.attn.proj.bias": "model-00001-of-00004.safetensors",
|
518 |
+
"vision_tower.blocks.21.attn.proj.weight": "model-00001-of-00004.safetensors",
|
519 |
+
"vision_tower.blocks.21.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
520 |
+
"vision_tower.blocks.21.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
521 |
+
"vision_tower.blocks.21.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
522 |
+
"vision_tower.blocks.21.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
523 |
+
"vision_tower.blocks.21.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
524 |
+
"vision_tower.blocks.21.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
525 |
+
"vision_tower.blocks.21.norm1.bias": "model-00001-of-00004.safetensors",
|
526 |
+
"vision_tower.blocks.21.norm1.weight": "model-00001-of-00004.safetensors",
|
527 |
+
"vision_tower.blocks.21.norm2.bias": "model-00001-of-00004.safetensors",
|
528 |
+
"vision_tower.blocks.21.norm2.weight": "model-00001-of-00004.safetensors",
|
529 |
+
"vision_tower.blocks.22.attn.proj.bias": "model-00001-of-00004.safetensors",
|
530 |
+
"vision_tower.blocks.22.attn.proj.weight": "model-00001-of-00004.safetensors",
|
531 |
+
"vision_tower.blocks.22.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
532 |
+
"vision_tower.blocks.22.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
533 |
+
"vision_tower.blocks.22.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
534 |
+
"vision_tower.blocks.22.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
535 |
+
"vision_tower.blocks.22.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
536 |
+
"vision_tower.blocks.22.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
537 |
+
"vision_tower.blocks.22.norm1.bias": "model-00001-of-00004.safetensors",
|
538 |
+
"vision_tower.blocks.22.norm1.weight": "model-00001-of-00004.safetensors",
|
539 |
+
"vision_tower.blocks.22.norm2.bias": "model-00001-of-00004.safetensors",
|
540 |
+
"vision_tower.blocks.22.norm2.weight": "model-00001-of-00004.safetensors",
|
541 |
+
"vision_tower.blocks.23.attn.proj.bias": "model-00001-of-00004.safetensors",
|
542 |
+
"vision_tower.blocks.23.attn.proj.weight": "model-00001-of-00004.safetensors",
|
543 |
+
"vision_tower.blocks.23.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
544 |
+
"vision_tower.blocks.23.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
545 |
+
"vision_tower.blocks.23.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
546 |
+
"vision_tower.blocks.23.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
547 |
+
"vision_tower.blocks.23.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
548 |
+
"vision_tower.blocks.23.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
549 |
+
"vision_tower.blocks.23.norm1.bias": "model-00001-of-00004.safetensors",
|
550 |
+
"vision_tower.blocks.23.norm1.weight": "model-00001-of-00004.safetensors",
|
551 |
+
"vision_tower.blocks.23.norm2.bias": "model-00001-of-00004.safetensors",
|
552 |
+
"vision_tower.blocks.23.norm2.weight": "model-00001-of-00004.safetensors",
|
553 |
+
"vision_tower.blocks.24.attn.proj.bias": "model-00001-of-00004.safetensors",
|
554 |
+
"vision_tower.blocks.24.attn.proj.weight": "model-00001-of-00004.safetensors",
|
555 |
+
"vision_tower.blocks.24.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
556 |
+
"vision_tower.blocks.24.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
557 |
+
"vision_tower.blocks.24.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
558 |
+
"vision_tower.blocks.24.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
559 |
+
"vision_tower.blocks.24.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
560 |
+
"vision_tower.blocks.24.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
561 |
+
"vision_tower.blocks.24.norm1.bias": "model-00001-of-00004.safetensors",
|
562 |
+
"vision_tower.blocks.24.norm1.weight": "model-00001-of-00004.safetensors",
|
563 |
+
"vision_tower.blocks.24.norm2.bias": "model-00001-of-00004.safetensors",
|
564 |
+
"vision_tower.blocks.24.norm2.weight": "model-00001-of-00004.safetensors",
|
565 |
+
"vision_tower.blocks.25.attn.proj.bias": "model-00001-of-00004.safetensors",
|
566 |
+
"vision_tower.blocks.25.attn.proj.weight": "model-00001-of-00004.safetensors",
|
567 |
+
"vision_tower.blocks.25.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
568 |
+
"vision_tower.blocks.25.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
569 |
+
"vision_tower.blocks.25.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
570 |
+
"vision_tower.blocks.25.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
571 |
+
"vision_tower.blocks.25.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
572 |
+
"vision_tower.blocks.25.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
573 |
+
"vision_tower.blocks.25.norm1.bias": "model-00001-of-00004.safetensors",
|
574 |
+
"vision_tower.blocks.25.norm1.weight": "model-00001-of-00004.safetensors",
|
575 |
+
"vision_tower.blocks.25.norm2.bias": "model-00001-of-00004.safetensors",
|
576 |
+
"vision_tower.blocks.25.norm2.weight": "model-00001-of-00004.safetensors",
|
577 |
+
"vision_tower.blocks.26.attn.proj.bias": "model-00001-of-00004.safetensors",
|
578 |
+
"vision_tower.blocks.26.attn.proj.weight": "model-00001-of-00004.safetensors",
|
579 |
+
"vision_tower.blocks.26.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
580 |
+
"vision_tower.blocks.26.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
581 |
+
"vision_tower.blocks.26.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
582 |
+
"vision_tower.blocks.26.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
583 |
+
"vision_tower.blocks.26.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
584 |
+
"vision_tower.blocks.26.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
585 |
+
"vision_tower.blocks.26.norm1.bias": "model-00001-of-00004.safetensors",
|
586 |
+
"vision_tower.blocks.26.norm1.weight": "model-00001-of-00004.safetensors",
|
587 |
+
"vision_tower.blocks.26.norm2.bias": "model-00001-of-00004.safetensors",
|
588 |
+
"vision_tower.blocks.26.norm2.weight": "model-00001-of-00004.safetensors",
|
589 |
+
"vision_tower.blocks.27.attn.proj.bias": "model-00001-of-00004.safetensors",
|
590 |
+
"vision_tower.blocks.27.attn.proj.weight": "model-00001-of-00004.safetensors",
|
591 |
+
"vision_tower.blocks.27.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
592 |
+
"vision_tower.blocks.27.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
593 |
+
"vision_tower.blocks.27.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
594 |
+
"vision_tower.blocks.27.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
595 |
+
"vision_tower.blocks.27.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
596 |
+
"vision_tower.blocks.27.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
597 |
+
"vision_tower.blocks.27.norm1.bias": "model-00001-of-00004.safetensors",
|
598 |
+
"vision_tower.blocks.27.norm1.weight": "model-00001-of-00004.safetensors",
|
599 |
+
"vision_tower.blocks.27.norm2.bias": "model-00001-of-00004.safetensors",
|
600 |
+
"vision_tower.blocks.27.norm2.weight": "model-00001-of-00004.safetensors",
|
601 |
+
"vision_tower.blocks.28.attn.proj.bias": "model-00001-of-00004.safetensors",
|
602 |
+
"vision_tower.blocks.28.attn.proj.weight": "model-00001-of-00004.safetensors",
|
603 |
+
"vision_tower.blocks.28.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
604 |
+
"vision_tower.blocks.28.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
605 |
+
"vision_tower.blocks.28.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
606 |
+
"vision_tower.blocks.28.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
607 |
+
"vision_tower.blocks.28.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
608 |
+
"vision_tower.blocks.28.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
609 |
+
"vision_tower.blocks.28.norm1.bias": "model-00001-of-00004.safetensors",
|
610 |
+
"vision_tower.blocks.28.norm1.weight": "model-00001-of-00004.safetensors",
|
611 |
+
"vision_tower.blocks.28.norm2.bias": "model-00001-of-00004.safetensors",
|
612 |
+
"vision_tower.blocks.28.norm2.weight": "model-00001-of-00004.safetensors",
|
613 |
+
"vision_tower.blocks.29.attn.proj.bias": "model-00001-of-00004.safetensors",
|
614 |
+
"vision_tower.blocks.29.attn.proj.weight": "model-00001-of-00004.safetensors",
|
615 |
+
"vision_tower.blocks.29.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
616 |
+
"vision_tower.blocks.29.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
617 |
+
"vision_tower.blocks.29.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
618 |
+
"vision_tower.blocks.29.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
619 |
+
"vision_tower.blocks.29.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
620 |
+
"vision_tower.blocks.29.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
621 |
+
"vision_tower.blocks.29.norm1.bias": "model-00001-of-00004.safetensors",
|
622 |
+
"vision_tower.blocks.29.norm1.weight": "model-00001-of-00004.safetensors",
|
623 |
+
"vision_tower.blocks.29.norm2.bias": "model-00001-of-00004.safetensors",
|
624 |
+
"vision_tower.blocks.29.norm2.weight": "model-00001-of-00004.safetensors",
|
625 |
+
"vision_tower.blocks.3.attn.proj.bias": "model-00001-of-00004.safetensors",
|
626 |
+
"vision_tower.blocks.3.attn.proj.weight": "model-00001-of-00004.safetensors",
|
627 |
+
"vision_tower.blocks.3.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
628 |
+
"vision_tower.blocks.3.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
629 |
+
"vision_tower.blocks.3.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
630 |
+
"vision_tower.blocks.3.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
631 |
+
"vision_tower.blocks.3.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
632 |
+
"vision_tower.blocks.3.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
633 |
+
"vision_tower.blocks.3.norm1.bias": "model-00001-of-00004.safetensors",
|
634 |
+
"vision_tower.blocks.3.norm1.weight": "model-00001-of-00004.safetensors",
|
635 |
+
"vision_tower.blocks.3.norm2.bias": "model-00001-of-00004.safetensors",
|
636 |
+
"vision_tower.blocks.3.norm2.weight": "model-00001-of-00004.safetensors",
|
637 |
+
"vision_tower.blocks.30.attn.proj.bias": "model-00001-of-00004.safetensors",
|
638 |
+
"vision_tower.blocks.30.attn.proj.weight": "model-00001-of-00004.safetensors",
|
639 |
+
"vision_tower.blocks.30.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
640 |
+
"vision_tower.blocks.30.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
641 |
+
"vision_tower.blocks.30.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
642 |
+
"vision_tower.blocks.30.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
643 |
+
"vision_tower.blocks.30.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
644 |
+
"vision_tower.blocks.30.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
645 |
+
"vision_tower.blocks.30.norm1.bias": "model-00001-of-00004.safetensors",
|
646 |
+
"vision_tower.blocks.30.norm1.weight": "model-00001-of-00004.safetensors",
|
647 |
+
"vision_tower.blocks.30.norm2.bias": "model-00001-of-00004.safetensors",
|
648 |
+
"vision_tower.blocks.30.norm2.weight": "model-00001-of-00004.safetensors",
|
649 |
+
"vision_tower.blocks.31.attn.proj.bias": "model-00001-of-00004.safetensors",
|
650 |
+
"vision_tower.blocks.31.attn.proj.weight": "model-00001-of-00004.safetensors",
|
651 |
+
"vision_tower.blocks.31.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
652 |
+
"vision_tower.blocks.31.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
653 |
+
"vision_tower.blocks.31.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
654 |
+
"vision_tower.blocks.31.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
655 |
+
"vision_tower.blocks.31.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
656 |
+
"vision_tower.blocks.31.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
657 |
+
"vision_tower.blocks.31.norm1.bias": "model-00001-of-00004.safetensors",
|
658 |
+
"vision_tower.blocks.31.norm1.weight": "model-00001-of-00004.safetensors",
|
659 |
+
"vision_tower.blocks.31.norm2.bias": "model-00001-of-00004.safetensors",
|
660 |
+
"vision_tower.blocks.31.norm2.weight": "model-00001-of-00004.safetensors",
|
661 |
+
"vision_tower.blocks.4.attn.proj.bias": "model-00001-of-00004.safetensors",
|
662 |
+
"vision_tower.blocks.4.attn.proj.weight": "model-00001-of-00004.safetensors",
|
663 |
+
"vision_tower.blocks.4.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
664 |
+
"vision_tower.blocks.4.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
665 |
+
"vision_tower.blocks.4.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
666 |
+
"vision_tower.blocks.4.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
667 |
+
"vision_tower.blocks.4.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
668 |
+
"vision_tower.blocks.4.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
669 |
+
"vision_tower.blocks.4.norm1.bias": "model-00001-of-00004.safetensors",
|
670 |
+
"vision_tower.blocks.4.norm1.weight": "model-00001-of-00004.safetensors",
|
671 |
+
"vision_tower.blocks.4.norm2.bias": "model-00001-of-00004.safetensors",
|
672 |
+
"vision_tower.blocks.4.norm2.weight": "model-00001-of-00004.safetensors",
|
673 |
+
"vision_tower.blocks.5.attn.proj.bias": "model-00001-of-00004.safetensors",
|
674 |
+
"vision_tower.blocks.5.attn.proj.weight": "model-00001-of-00004.safetensors",
|
675 |
+
"vision_tower.blocks.5.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
676 |
+
"vision_tower.blocks.5.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
677 |
+
"vision_tower.blocks.5.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
678 |
+
"vision_tower.blocks.5.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
679 |
+
"vision_tower.blocks.5.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
680 |
+
"vision_tower.blocks.5.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
681 |
+
"vision_tower.blocks.5.norm1.bias": "model-00001-of-00004.safetensors",
|
682 |
+
"vision_tower.blocks.5.norm1.weight": "model-00001-of-00004.safetensors",
|
683 |
+
"vision_tower.blocks.5.norm2.bias": "model-00001-of-00004.safetensors",
|
684 |
+
"vision_tower.blocks.5.norm2.weight": "model-00001-of-00004.safetensors",
|
685 |
+
"vision_tower.blocks.6.attn.proj.bias": "model-00001-of-00004.safetensors",
|
686 |
+
"vision_tower.blocks.6.attn.proj.weight": "model-00001-of-00004.safetensors",
|
687 |
+
"vision_tower.blocks.6.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
688 |
+
"vision_tower.blocks.6.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
689 |
+
"vision_tower.blocks.6.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
690 |
+
"vision_tower.blocks.6.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
691 |
+
"vision_tower.blocks.6.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
692 |
+
"vision_tower.blocks.6.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
693 |
+
"vision_tower.blocks.6.norm1.bias": "model-00001-of-00004.safetensors",
|
694 |
+
"vision_tower.blocks.6.norm1.weight": "model-00001-of-00004.safetensors",
|
695 |
+
"vision_tower.blocks.6.norm2.bias": "model-00001-of-00004.safetensors",
|
696 |
+
"vision_tower.blocks.6.norm2.weight": "model-00001-of-00004.safetensors",
|
697 |
+
"vision_tower.blocks.7.attn.proj.bias": "model-00001-of-00004.safetensors",
|
698 |
+
"vision_tower.blocks.7.attn.proj.weight": "model-00001-of-00004.safetensors",
|
699 |
+
"vision_tower.blocks.7.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
700 |
+
"vision_tower.blocks.7.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
701 |
+
"vision_tower.blocks.7.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
702 |
+
"vision_tower.blocks.7.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
703 |
+
"vision_tower.blocks.7.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
704 |
+
"vision_tower.blocks.7.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
705 |
+
"vision_tower.blocks.7.norm1.bias": "model-00001-of-00004.safetensors",
|
706 |
+
"vision_tower.blocks.7.norm1.weight": "model-00001-of-00004.safetensors",
|
707 |
+
"vision_tower.blocks.7.norm2.bias": "model-00001-of-00004.safetensors",
|
708 |
+
"vision_tower.blocks.7.norm2.weight": "model-00001-of-00004.safetensors",
|
709 |
+
"vision_tower.blocks.8.attn.proj.bias": "model-00001-of-00004.safetensors",
|
710 |
+
"vision_tower.blocks.8.attn.proj.weight": "model-00001-of-00004.safetensors",
|
711 |
+
"vision_tower.blocks.8.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
712 |
+
"vision_tower.blocks.8.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
713 |
+
"vision_tower.blocks.8.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
714 |
+
"vision_tower.blocks.8.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
715 |
+
"vision_tower.blocks.8.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
716 |
+
"vision_tower.blocks.8.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
717 |
+
"vision_tower.blocks.8.norm1.bias": "model-00001-of-00004.safetensors",
|
718 |
+
"vision_tower.blocks.8.norm1.weight": "model-00001-of-00004.safetensors",
|
719 |
+
"vision_tower.blocks.8.norm2.bias": "model-00001-of-00004.safetensors",
|
720 |
+
"vision_tower.blocks.8.norm2.weight": "model-00001-of-00004.safetensors",
|
721 |
+
"vision_tower.blocks.9.attn.proj.bias": "model-00001-of-00004.safetensors",
|
722 |
+
"vision_tower.blocks.9.attn.proj.weight": "model-00001-of-00004.safetensors",
|
723 |
+
"vision_tower.blocks.9.attn.qkv.bias": "model-00001-of-00004.safetensors",
|
724 |
+
"vision_tower.blocks.9.attn.qkv.weight": "model-00001-of-00004.safetensors",
|
725 |
+
"vision_tower.blocks.9.mlp.fc1.bias": "model-00001-of-00004.safetensors",
|
726 |
+
"vision_tower.blocks.9.mlp.fc1.weight": "model-00001-of-00004.safetensors",
|
727 |
+
"vision_tower.blocks.9.mlp.fc2.bias": "model-00001-of-00004.safetensors",
|
728 |
+
"vision_tower.blocks.9.mlp.fc2.weight": "model-00001-of-00004.safetensors",
|
729 |
+
"vision_tower.blocks.9.norm1.bias": "model-00001-of-00004.safetensors",
|
730 |
+
"vision_tower.blocks.9.norm1.weight": "model-00001-of-00004.safetensors",
|
731 |
+
"vision_tower.blocks.9.norm2.bias": "model-00001-of-00004.safetensors",
|
732 |
+
"vision_tower.blocks.9.norm2.weight": "model-00001-of-00004.safetensors",
|
733 |
+
"vision_tower.merger.ln_q.bias": "model-00001-of-00004.safetensors",
|
734 |
+
"vision_tower.merger.ln_q.weight": "model-00001-of-00004.safetensors",
|
735 |
+
"vision_tower.merger.mlp.0.bias": "model-00001-of-00004.safetensors",
|
736 |
+
"vision_tower.merger.mlp.0.weight": "model-00001-of-00004.safetensors",
|
737 |
+
"vision_tower.merger.mlp.2.bias": "model-00001-of-00004.safetensors",
|
738 |
+
"vision_tower.merger.mlp.2.weight": "model-00001-of-00004.safetensors",
|
739 |
+
"vision_tower.patch_embed.proj.weight": "model-00001-of-00004.safetensors"
|
740 |
+
}
|
741 |
+
}
|
modeling_emova.py
ADDED
@@ -0,0 +1,816 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""PyTorch EMOVA model."""
|
16 |
+
|
17 |
+
import math
|
18 |
+
from dataclasses import dataclass
|
19 |
+
from functools import partial
|
20 |
+
from typing import List, Optional, Tuple, Union
|
21 |
+
|
22 |
+
import numpy as np
|
23 |
+
import torch
|
24 |
+
import torch.utils.checkpoint
|
25 |
+
from torch import nn
|
26 |
+
|
27 |
+
from transformers import PreTrainedModel
|
28 |
+
from transformers.activations import ACT2FN
|
29 |
+
from transformers.cache_utils import Cache
|
30 |
+
from transformers.image_processing_utils import select_best_resolution
|
31 |
+
from transformers.modeling_outputs import ModelOutput
|
32 |
+
from transformers.utils import (
|
33 |
+
add_start_docstrings,
|
34 |
+
add_start_docstrings_to_model_forward,
|
35 |
+
logging,
|
36 |
+
replace_return_docstrings,
|
37 |
+
)
|
38 |
+
from transformers.models.auto import AutoModel, AutoModelForCausalLM
|
39 |
+
|
40 |
+
from .configuration_emova import EMOVAConfig
|
41 |
+
from .modeling_qwen2vit import Qwen2VisionTower
|
42 |
+
|
43 |
+
from timm.models.regnet import RegStage
|
44 |
+
|
45 |
+
try:
|
46 |
+
from timm.layers import LayerNorm2d
|
47 |
+
except:
|
48 |
+
from timm.models.layers import LayerNorm2d
|
49 |
+
from einops import rearrange
|
50 |
+
|
51 |
+
logger = logging.get_logger(__name__)
|
52 |
+
|
53 |
+
_CONFIG_FOR_DOC = "EMOVAConfig"
|
54 |
+
|
55 |
+
|
56 |
+
@dataclass
|
57 |
+
class EMOVACausalLMOutputWithPast(ModelOutput):
|
58 |
+
"""
|
59 |
+
Base class for EMOVA causal language model (or autoregressive) outputs.
|
60 |
+
|
61 |
+
Args:
|
62 |
+
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
|
63 |
+
Language modeling loss (for next-token prediction).
|
64 |
+
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
|
65 |
+
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
|
66 |
+
past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
67 |
+
Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
|
68 |
+
`(batch_size, num_heads, sequence_length, embed_size_per_head)`)
|
69 |
+
|
70 |
+
Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
|
71 |
+
`past_key_values` input) to speed up sequential decoding.
|
72 |
+
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
|
73 |
+
Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
|
74 |
+
one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
|
75 |
+
|
76 |
+
Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
|
77 |
+
attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
|
78 |
+
Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
|
79 |
+
sequence_length)`.
|
80 |
+
|
81 |
+
Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
|
82 |
+
heads.
|
83 |
+
image_hidden_states (`tuple(torch.FloatTensor)`, *optional*):
|
84 |
+
Tuple of `torch.FloatTensor` (one for the output of the image embeddings, `(batch_size, num_images,
|
85 |
+
sequence_length, hidden_size)`.
|
86 |
+
|
87 |
+
image_hidden_states of the model produced by the vision encoder, and optionally by the perceiver
|
88 |
+
"""
|
89 |
+
|
90 |
+
loss: Optional[torch.FloatTensor] = None
|
91 |
+
logits: torch.FloatTensor = None
|
92 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None
|
93 |
+
hidden_states: Optional[Tuple[torch.FloatTensor]] = None
|
94 |
+
attentions: Optional[Tuple[torch.FloatTensor]] = None
|
95 |
+
image_hidden_states: Optional[Tuple[torch.FloatTensor]] = None
|
96 |
+
|
97 |
+
|
98 |
+
class EMOVAMultiModalProjector(nn.Sequential):
|
99 |
+
# CAbstractor
|
100 |
+
def __init__(self, config):
|
101 |
+
super(EMOVAMultiModalProjector, self).__init__()
|
102 |
+
hidden_size = config.text_config.hidden_size
|
103 |
+
mm_hidden_size = config.vision_config.hidden_size
|
104 |
+
mlp_depth = config.mm_projector_config['mlp_depth']
|
105 |
+
|
106 |
+
modules = [nn.Linear(mm_hidden_size, hidden_size)]
|
107 |
+
for _ in range(1, mlp_depth):
|
108 |
+
modules.append(nn.GELU())
|
109 |
+
modules.append(nn.Linear(hidden_size, hidden_size))
|
110 |
+
super(EMOVAMultiModalProjector, self).__init__(*modules)
|
111 |
+
|
112 |
+
|
113 |
+
EMOVA_START_DOCSTRING = r"""
|
114 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
115 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
116 |
+
etc.)
|
117 |
+
|
118 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
119 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
120 |
+
and behavior.
|
121 |
+
|
122 |
+
Parameters:
|
123 |
+
config ([`EMOVAConfig`] or [`EMOVAVisionConfig`]):
|
124 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
125 |
+
load the weights associated with the model, only the configuration. Check out the
|
126 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
127 |
+
"""
|
128 |
+
|
129 |
+
|
130 |
+
@add_start_docstrings(
|
131 |
+
"The bare LLaMA Model outputting raw hidden-states without any specific head on top.",
|
132 |
+
EMOVA_START_DOCSTRING,
|
133 |
+
)
|
134 |
+
class EMOVAPreTrainedModel(PreTrainedModel):
|
135 |
+
config_class = EMOVAConfig
|
136 |
+
base_model_prefix = "model"
|
137 |
+
supports_gradient_checkpointing = True
|
138 |
+
_no_split_modules = ["EMOVAVisionAttention"]
|
139 |
+
_skip_keys_device_placement = "past_key_values"
|
140 |
+
_supports_flash_attn_2 = True
|
141 |
+
_supports_cache_class = True
|
142 |
+
|
143 |
+
def _init_weights(self, module):
|
144 |
+
std = (
|
145 |
+
self.config.initializer_range
|
146 |
+
if hasattr(self.config, "initializer_range")
|
147 |
+
else self.config.text_config.initializer_range
|
148 |
+
)
|
149 |
+
|
150 |
+
if hasattr(module, "class_embedding"):
|
151 |
+
module.class_embedding.data.normal_(mean=0.0, std=std)
|
152 |
+
|
153 |
+
if isinstance(module, (nn.Linear, nn.Conv2d)):
|
154 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
155 |
+
if module.bias is not None:
|
156 |
+
module.bias.data.zero_()
|
157 |
+
elif isinstance(module, nn.Embedding):
|
158 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
159 |
+
if module.padding_idx is not None:
|
160 |
+
module.weight.data[module.padding_idx].zero_()
|
161 |
+
|
162 |
+
@property
|
163 |
+
def _supports_sdpa(self):
|
164 |
+
"""
|
165 |
+
Retrieve language_model's attribute to check whether the model supports
|
166 |
+
SDPA or not.
|
167 |
+
"""
|
168 |
+
return self.language_model._supports_sdpa
|
169 |
+
|
170 |
+
|
171 |
+
EMOVA_INPUTS_DOCSTRING = r"""
|
172 |
+
Args:
|
173 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
174 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
175 |
+
it.
|
176 |
+
|
177 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
178 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
179 |
+
|
180 |
+
[What are input IDs?](../glossary#input-ids)
|
181 |
+
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)):
|
182 |
+
The tensors corresponding to the input images. Pixel values can be obtained using
|
183 |
+
[`AutoImageProcessor`]. See [`EMOVAImageProcessor.__call__`] for details. [`EMOVAProcessor`] uses
|
184 |
+
[`EMOVAImageProcessor`] for processing images.
|
185 |
+
image_sizes (`torch.LongTensor` of shape `(batch_size, 2)`, *optional*):
|
186 |
+
The sizes of the images in the batch, being (height, width) for each image.
|
187 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
188 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
189 |
+
|
190 |
+
- 1 for tokens that are **not masked**,
|
191 |
+
- 0 for tokens that are **masked**.
|
192 |
+
|
193 |
+
[What are attention masks?](../glossary#attention-mask)
|
194 |
+
|
195 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
196 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
197 |
+
|
198 |
+
If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
|
199 |
+
`past_key_values`).
|
200 |
+
|
201 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
202 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
203 |
+
information on the default strategy.
|
204 |
+
|
205 |
+
- 1 indicates the head is **not masked**,
|
206 |
+
- 0 indicates the head is **masked**.
|
207 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
208 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
209 |
+
config.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
|
210 |
+
past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
211 |
+
Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
|
212 |
+
`(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of shape
|
213 |
+
`(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.
|
214 |
+
|
215 |
+
Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
216 |
+
blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.
|
217 |
+
|
218 |
+
If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
|
219 |
+
don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
|
220 |
+
`decoder_input_ids` of shape `(batch_size, sequence_length)`.
|
221 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
222 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
223 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
224 |
+
model's internal embedding lookup matrix.
|
225 |
+
vision_feature_layer (`int`, *optional*, defaults to -2):
|
226 |
+
The index of the layer to select the vision feature.
|
227 |
+
vision_feature_select_strategy (`str`, *optional*, defaults to `"default"`):
|
228 |
+
The feature selection strategy used to select the vision feature from the vision backbone.
|
229 |
+
Can be one of `"default"` or `"full"`. If `"default"`, the CLS token is removed from the vision features.
|
230 |
+
If `"full"`, the full vision features are used.
|
231 |
+
use_cache (`bool`, *optional*):
|
232 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
233 |
+
`past_key_values`).
|
234 |
+
output_attentions (`bool`, *optional*):
|
235 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
236 |
+
tensors for more detail.
|
237 |
+
output_hidden_states (`bool`, *optional*):
|
238 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
239 |
+
more detail.
|
240 |
+
return_dict (`bool`, *optional*):
|
241 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
242 |
+
"""
|
243 |
+
|
244 |
+
|
245 |
+
@add_start_docstrings(
|
246 |
+
"""The EMOVA model which consists of a vision backbone and a language model.""",
|
247 |
+
EMOVA_START_DOCSTRING,
|
248 |
+
)
|
249 |
+
class EMOVAForConditionalGeneration(EMOVAPreTrainedModel):
|
250 |
+
def __init__(self, config: EMOVAConfig, **kwargs):
|
251 |
+
super().__init__(config)
|
252 |
+
self.vision_tower = Qwen2VisionTower(config.vision_config)
|
253 |
+
self.multi_modal_projector = EMOVAMultiModalProjector(config)
|
254 |
+
|
255 |
+
self.vocab_size = config.text_config.vocab_size
|
256 |
+
self.language_model = AutoModelForCausalLM.from_config(
|
257 |
+
config.text_config, attn_implementation=config._attn_implementation
|
258 |
+
)
|
259 |
+
self.pad_token_id = self.config.pad_token_id if self.config.pad_token_id is not None else -1
|
260 |
+
self._padding_side = "left" # set it to left by default, user can use setter to change padding_sides
|
261 |
+
self.post_init()
|
262 |
+
|
263 |
+
@property
|
264 |
+
def padding_side(self):
|
265 |
+
return self._padding_side
|
266 |
+
|
267 |
+
@padding_side.setter
|
268 |
+
def padding_side(self, padding_side: str):
|
269 |
+
if padding_side not in ["left", "right"]:
|
270 |
+
raise ValueError(f"{padding_side} is not `left` or `right`.")
|
271 |
+
self._padding_side = padding_side
|
272 |
+
|
273 |
+
def get_input_embeddings(self):
|
274 |
+
return self.language_model.get_input_embeddings()
|
275 |
+
|
276 |
+
def set_input_embeddings(self, value):
|
277 |
+
self.language_model.set_input_embeddings(value)
|
278 |
+
|
279 |
+
def get_output_embeddings(self):
|
280 |
+
return self.language_model.get_output_embeddings()
|
281 |
+
|
282 |
+
def set_output_embeddings(self, new_embeddings):
|
283 |
+
self.language_model.set_output_embeddings(new_embeddings)
|
284 |
+
|
285 |
+
def set_decoder(self, decoder):
|
286 |
+
self.language_model.set_decoder(decoder)
|
287 |
+
|
288 |
+
def get_decoder(self):
|
289 |
+
return self.language_model.get_decoder()
|
290 |
+
|
291 |
+
def tie_weights(self):
|
292 |
+
return self.language_model.tie_weights()
|
293 |
+
|
294 |
+
def resize_token_embeddings(self, new_num_tokens: Optional[int] = None, pad_to_multiple_of=None) -> nn.Embedding:
|
295 |
+
model_embeds = self.language_model.resize_token_embeddings(new_num_tokens, pad_to_multiple_of)
|
296 |
+
# update vocab size
|
297 |
+
self.config.text_config.vocab_size = model_embeds.num_embeddings
|
298 |
+
self.vocab_size = model_embeds.num_embeddings
|
299 |
+
return model_embeds
|
300 |
+
|
301 |
+
def _merge_input_ids_with_image_features(
|
302 |
+
self,
|
303 |
+
image_features,
|
304 |
+
feature_lens,
|
305 |
+
inputs_embeds,
|
306 |
+
input_ids,
|
307 |
+
attention_mask,
|
308 |
+
position_ids=None,
|
309 |
+
labels=None,
|
310 |
+
image_token_index=None,
|
311 |
+
ignore_index=-100,
|
312 |
+
):
|
313 |
+
"""
|
314 |
+
Merge input_ids with with image features into final embeddings
|
315 |
+
|
316 |
+
Args:
|
317 |
+
image_features (`torch.Tensor` of shape `(all_feature_lens, embed_dim)`):
|
318 |
+
All vision vectors of all images in the batch
|
319 |
+
feature_lens (`torch.LongTensor` of shape `(num_images)`):
|
320 |
+
The length of visual embeddings of each image as stacked in `image_features`
|
321 |
+
inputs_embeds (`torch.Tensor` of shape `(batch_size, sequence_length, embed_dim)`):
|
322 |
+
Token embeddings before merging with visual embeddings
|
323 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
324 |
+
Input_ids of tokens, possibly filled with image token
|
325 |
+
attention_mask (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
326 |
+
Mask to avoid performing attention on padding token indices.
|
327 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
328 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
329 |
+
config.n_positions - 1]`.
|
330 |
+
labels (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*)
|
331 |
+
:abels need to be recalculated to support training (if provided)
|
332 |
+
image_token_index (`int`, *optional*)
|
333 |
+
Token id used to indicate the special "image" token. Defaults to `config.image_token_index`
|
334 |
+
ignore_index (`int`, *optional*)
|
335 |
+
Value that is used to pad `labels` and will be ignored when calculated loss. Default: -100.
|
336 |
+
Returns:
|
337 |
+
final_embedding, final_attention_mask, position_ids, final_labels
|
338 |
+
|
339 |
+
Explanation:
|
340 |
+
each image has variable length embeddings, with length specified by feature_lens
|
341 |
+
image_features is concatenation of all visual embed vectors
|
342 |
+
task: fill each <image> with the correct number of visual embeddings
|
343 |
+
Example:
|
344 |
+
X (5 patches), Y (3 patches), Z (8)
|
345 |
+
X, Y are in the same sequence (in-context learning)
|
346 |
+
if right padding
|
347 |
+
input_ids: [
|
348 |
+
a b c d e f X g h i j k Y l m
|
349 |
+
o p q r Z s t u v _ _ _ _ _ _
|
350 |
+
]
|
351 |
+
input_ids should be: [
|
352 |
+
a b c d e f X X X X X g h i j k Y Y Y l m
|
353 |
+
o p q r Z Z Z Z Z Z Z Z s t u v _ _ _ _ _
|
354 |
+
]
|
355 |
+
labels should be: [
|
356 |
+
a b c d e f _ _ _ _ _ g h i j k _ _ _ l m
|
357 |
+
o p q r _ _ _ _ _ _ _ _ s t u v _ _ _ _ _
|
358 |
+
]
|
359 |
+
elif left padding
|
360 |
+
input_ids: [
|
361 |
+
a b c d e f X g h i j k Y l m
|
362 |
+
_ _ _ _ _ _ o p q r Z s t u v
|
363 |
+
]
|
364 |
+
input_ids should be: [
|
365 |
+
a b c d e f X X X X X g h i j k Y Y Y l m
|
366 |
+
_ _ _ _ _ o p q r Z Z Z Z Z Z Z Z s t u v
|
367 |
+
]
|
368 |
+
labels should be: [
|
369 |
+
a b c d e f _ _ _ _ _ g h i j k _ _ _ l m
|
370 |
+
_ _ _ _ _ o p q r _ _ _ _ _ _ _ _ s t u v
|
371 |
+
]
|
372 |
+
Edge cases:
|
373 |
+
* If tokens are same but image token sizes are different, then cannot infer left or right padding
|
374 |
+
```python
|
375 |
+
cat_img = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
|
376 |
+
chart_img = Image.open(requests.get("https://github.com/haotian-liu/LLaVA/blob/1a91fc274d7c35a9b50b3cb29c4247ae5837ce39/images/llava_v1_5_radar.jpg?raw=true", stream=True).raw)
|
377 |
+
prompts = [
|
378 |
+
"[INST] <image>\nWhat is shown in this image? [/INST]",
|
379 |
+
"[INST] <image>\nWhat is shown in this image? [/INST]",
|
380 |
+
]
|
381 |
+
inputs = processor(prompts, [chart_img, cat_img], return_tensors='pt', padding=True).to("cuda")
|
382 |
+
chart_img has 2634 tokens, while cat_img has 2340 tokens
|
383 |
+
```
|
384 |
+
|
385 |
+
input_ids: [
|
386 |
+
a b c d X g h
|
387 |
+
i j Y k l m n
|
388 |
+
]
|
389 |
+
where X is 3 tokens while Y is 5, this mean after merge
|
390 |
+
if left-padding (batched generation)
|
391 |
+
input_ids should be: [
|
392 |
+
_ _ a b c d X X X g h
|
393 |
+
i j Y Y Y Y Y k l m n
|
394 |
+
]
|
395 |
+
elif (right padding) (training)
|
396 |
+
input_ids should be: [
|
397 |
+
a b c d X X X g h _ _
|
398 |
+
i j Y Y Y Y Y k l m n
|
399 |
+
]
|
400 |
+
"""
|
401 |
+
image_token_index = image_token_index if image_token_index is not None else self.config.image_token_index
|
402 |
+
ignore_index = ignore_index if ignore_index is not None else self.config.ignore_index
|
403 |
+
|
404 |
+
with torch.no_grad():
|
405 |
+
num_images = feature_lens.size(0)
|
406 |
+
num_image_features, embed_dim = image_features.shape
|
407 |
+
if feature_lens.sum() != num_image_features:
|
408 |
+
raise ValueError(f"{feature_lens=} / {feature_lens.sum()} != {image_features.shape=}")
|
409 |
+
batch_size = input_ids.shape[0]
|
410 |
+
_left_padding = torch.any(attention_mask[:, 0] == 0)
|
411 |
+
_right_padding = torch.any(attention_mask[:, -1] == 0)
|
412 |
+
|
413 |
+
left_padding = True if not self.training else False
|
414 |
+
if batch_size > 1 and not self.training:
|
415 |
+
if _left_padding and not _right_padding:
|
416 |
+
left_padding = True
|
417 |
+
elif not _left_padding and _right_padding:
|
418 |
+
left_padding = False
|
419 |
+
elif not _left_padding and not _right_padding:
|
420 |
+
# both side is 1, so cannot tell
|
421 |
+
left_padding = self.padding_side == "left"
|
422 |
+
else:
|
423 |
+
# invalid attention_mask
|
424 |
+
raise ValueError(f"both side of attention_mask has zero, invalid. {attention_mask}")
|
425 |
+
|
426 |
+
# Whether to turn off right padding
|
427 |
+
# 1. Create a mask to know where special image tokens are
|
428 |
+
special_image_token_mask = input_ids == image_token_index
|
429 |
+
# special_image_token_mask: [bsz, seqlen]
|
430 |
+
num_special_image_tokens = torch.sum(special_image_token_mask, dim=-1)
|
431 |
+
# num_special_image_tokens: [bsz]
|
432 |
+
# Reserve for padding of num_images
|
433 |
+
total_num_special_image_tokens = torch.sum(special_image_token_mask)
|
434 |
+
if total_num_special_image_tokens != num_images:
|
435 |
+
raise ValueError(
|
436 |
+
f"Number of image tokens in input_ids ({total_num_special_image_tokens}) different from num_images ({num_images})."
|
437 |
+
)
|
438 |
+
# Compute the maximum embed dimension
|
439 |
+
# max_image_feature_lens is max_feature_lens per batch
|
440 |
+
feature_lens = feature_lens.to(input_ids.device)
|
441 |
+
feature_lens_batch = feature_lens.split(num_special_image_tokens.tolist(), dim=0)
|
442 |
+
feature_lens_batch_sum = torch.tensor([x.sum() for x in feature_lens_batch], device=input_ids.device)
|
443 |
+
embed_sequence_lengths = (
|
444 |
+
(attention_mask == 1).long().sum(-1) - num_special_image_tokens + feature_lens_batch_sum
|
445 |
+
)
|
446 |
+
max_embed_dim = embed_sequence_lengths.max()
|
447 |
+
|
448 |
+
batch_indices, non_image_indices = torch.where((input_ids != image_token_index) & (attention_mask == 1))
|
449 |
+
# 2. Compute the positions where text should be written
|
450 |
+
# Calculate new positions for text tokens in merged image-text sequence.
|
451 |
+
# `special_image_token_mask` identifies image tokens. Each image token will be replaced by `nb_text_tokens_per_images` text tokens.
|
452 |
+
# `torch.cumsum` computes how each image token shifts subsequent text token positions.
|
453 |
+
# - 1 to adjust for zero-based indexing, as `cumsum` inherently increases indices by one.
|
454 |
+
# ! instead of special_image_token_mask * (num_image_patches - 1)
|
455 |
+
# special_image_token_mask * (num_feature_len - 1)
|
456 |
+
special_image_token_mask = special_image_token_mask.long()
|
457 |
+
special_image_token_mask[special_image_token_mask == 1] = feature_lens - 1
|
458 |
+
new_token_positions = torch.cumsum((special_image_token_mask + 1), -1) - 1
|
459 |
+
if left_padding:
|
460 |
+
# shift right token positions so that they are ending at the same number
|
461 |
+
# the below here was incorrect? new_token_positions += new_token_positions[:, -1].max() - new_token_positions[:, -1:]
|
462 |
+
new_token_positions += max_embed_dim - 1 - new_token_positions[:, -1:]
|
463 |
+
|
464 |
+
text_to_overwrite = new_token_positions[batch_indices, non_image_indices]
|
465 |
+
|
466 |
+
# 3. Create the full embedding, already padded to the maximum position
|
467 |
+
final_embedding = torch.zeros(
|
468 |
+
batch_size, max_embed_dim, embed_dim, dtype=inputs_embeds.dtype, device=inputs_embeds.device
|
469 |
+
)
|
470 |
+
final_attention_mask = torch.zeros(
|
471 |
+
batch_size, max_embed_dim, dtype=attention_mask.dtype, device=inputs_embeds.device
|
472 |
+
)
|
473 |
+
final_input_ids = torch.full(
|
474 |
+
(batch_size, max_embed_dim), self.pad_token_id, dtype=input_ids.dtype, device=inputs_embeds.device
|
475 |
+
)
|
476 |
+
# In case the Vision model or the Language model has been offloaded to CPU, we need to manually
|
477 |
+
# set the corresponding tensors into their correct target device.
|
478 |
+
target_device = inputs_embeds.device
|
479 |
+
batch_indices, non_image_indices, text_to_overwrite = (
|
480 |
+
batch_indices.to(target_device),
|
481 |
+
non_image_indices.to(target_device),
|
482 |
+
text_to_overwrite.to(target_device),
|
483 |
+
)
|
484 |
+
attention_mask = attention_mask.to(target_device)
|
485 |
+
input_ids = input_ids.to(target_device)
|
486 |
+
|
487 |
+
# 4. Fill the embeddings based on the mask. If we have ["hey" "<image>", "how", "are"]
|
488 |
+
# we need to index copy on [0, 577, 578, 579] for the text and [1:576] for the image features
|
489 |
+
final_embedding[batch_indices, text_to_overwrite] = inputs_embeds[batch_indices, non_image_indices]
|
490 |
+
final_attention_mask[batch_indices, text_to_overwrite] = attention_mask[batch_indices, non_image_indices]
|
491 |
+
final_input_ids[batch_indices, text_to_overwrite] = input_ids[batch_indices, non_image_indices]
|
492 |
+
final_labels = None
|
493 |
+
if labels is not None:
|
494 |
+
labels = labels.to(target_device)
|
495 |
+
final_labels = torch.full_like(final_attention_mask, ignore_index).to(torch.long)
|
496 |
+
final_labels[batch_indices, text_to_overwrite] = labels[batch_indices, non_image_indices]
|
497 |
+
|
498 |
+
# 5. Fill the embeddings corresponding to the images. Anything that is not `text_positions` needs filling (#29835)
|
499 |
+
with torch.no_grad():
|
500 |
+
image_to_overwrite = torch.full(
|
501 |
+
(batch_size, max_embed_dim), True, dtype=torch.bool, device=inputs_embeds.device
|
502 |
+
)
|
503 |
+
image_to_overwrite[batch_indices, text_to_overwrite] = False
|
504 |
+
embed_indices = torch.arange(max_embed_dim).unsqueeze(0).to(target_device)
|
505 |
+
embed_indices = embed_indices.expand(batch_size, max_embed_dim)
|
506 |
+
embed_seq_lens = embed_sequence_lengths[:, None].to(target_device)
|
507 |
+
|
508 |
+
if left_padding:
|
509 |
+
# exclude padding on the left
|
510 |
+
max_embed_dim = max_embed_dim.to(target_device)
|
511 |
+
val = (max_embed_dim - embed_indices) <= embed_seq_lens
|
512 |
+
else:
|
513 |
+
# exclude padding on the right
|
514 |
+
val = embed_indices < embed_seq_lens
|
515 |
+
image_to_overwrite &= val
|
516 |
+
|
517 |
+
if image_to_overwrite.sum() != num_image_features:
|
518 |
+
raise ValueError(
|
519 |
+
f"{image_to_overwrite.sum()=} != {num_image_features=} The input provided to the model are wrong. "
|
520 |
+
f"The number of image tokens is {torch.sum(special_image_token_mask)} while"
|
521 |
+
f" the number of image given to the model is {num_images}. "
|
522 |
+
f"This prevents correct indexing and breaks batch generation."
|
523 |
+
)
|
524 |
+
final_embedding[image_to_overwrite] = image_features.contiguous().reshape(-1, embed_dim).to(target_device)
|
525 |
+
final_attention_mask |= image_to_overwrite
|
526 |
+
position_ids = (final_attention_mask.cumsum(-1) - 1).masked_fill_((final_attention_mask == 0), 1)
|
527 |
+
|
528 |
+
return final_embedding, final_attention_mask, position_ids, final_labels, final_input_ids
|
529 |
+
|
530 |
+
@add_start_docstrings_to_model_forward(EMOVA_INPUTS_DOCSTRING)
|
531 |
+
@replace_return_docstrings(output_type=EMOVACausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
532 |
+
def forward(
|
533 |
+
self,
|
534 |
+
input_ids: torch.LongTensor = None,
|
535 |
+
pixel_values: torch.FloatTensor = None,
|
536 |
+
image_sizes: Optional[torch.LongTensor] = None,
|
537 |
+
attention_mask: Optional[torch.Tensor] = None,
|
538 |
+
position_ids: Optional[torch.LongTensor] = None,
|
539 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
540 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
541 |
+
vision_feature_layer: Optional[int] = None,
|
542 |
+
vision_feature_select_strategy: Optional[str] = None,
|
543 |
+
labels: Optional[torch.LongTensor] = None,
|
544 |
+
use_cache: Optional[bool] = None,
|
545 |
+
output_attentions: Optional[bool] = None,
|
546 |
+
output_hidden_states: Optional[bool] = None,
|
547 |
+
return_dict: Optional[bool] = None,
|
548 |
+
) -> Union[Tuple, EMOVACausalLMOutputWithPast]:
|
549 |
+
r"""
|
550 |
+
Args:
|
551 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
552 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
553 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
554 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
555 |
+
|
556 |
+
Returns:
|
557 |
+
|
558 |
+
Example:
|
559 |
+
|
560 |
+
```python
|
561 |
+
>>> from PIL import Image
|
562 |
+
>>> import requests
|
563 |
+
>>> from transformers import AutoProcessor, EMOVAForConditionalGeneration
|
564 |
+
|
565 |
+
>>> model = EMOVAForConditionalGeneration.from_pretrained("Emova-ollm/emova-qwen-2-5-7b-hf")
|
566 |
+
>>> processor = AutoProcessor.from_pretrained("Emova-ollm/emova-qwen-2-5-7b-hf")
|
567 |
+
|
568 |
+
>>> prompt = "<image>\nWhat is shown in this image?"
|
569 |
+
>>> url = "https://www.ilankelman.org/stopsigns/australia.jpg"
|
570 |
+
>>> image = Image.open(requests.get(url, stream=True).raw)
|
571 |
+
|
572 |
+
>>> inputs = processor(text=prompt, images=image, return_tensors="pt")
|
573 |
+
|
574 |
+
>>> # Generate
|
575 |
+
>>> generate_ids = model.generate(**inputs, max_length=30)
|
576 |
+
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
577 |
+
"\nWhat is shown in this image? The image appears to be a radar chart, which is a type of multi-dimensional plot (...)"
|
578 |
+
```"""
|
579 |
+
|
580 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
581 |
+
output_hidden_states = (
|
582 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
583 |
+
)
|
584 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
585 |
+
|
586 |
+
if inputs_embeds is None:
|
587 |
+
# 1. Extract the input embeddings
|
588 |
+
# In case image_token_index is not in the embeddings (extra token but embedding don't have it)
|
589 |
+
for_inputs_embeds_ids = input_ids.clone()
|
590 |
+
for_inputs_embeds_ids[(input_ids == self.config.image_token_index)] = 0
|
591 |
+
inputs_embeds = self.get_input_embeddings()(for_inputs_embeds_ids)
|
592 |
+
|
593 |
+
# 2. Merge text and images
|
594 |
+
if pixel_values is not None and input_ids.shape[1] != 1 and pixel_values.size(0) > 0:
|
595 |
+
# ! infer image_num_patches from image_sizes
|
596 |
+
|
597 |
+
image_features = self.vision_tower(pixel_values.to(self.dtype), image_sizes)
|
598 |
+
image_features = self.multi_modal_projector(image_features)
|
599 |
+
|
600 |
+
spatial_merge_size = self.vision_tower.spatial_merge_size
|
601 |
+
feature_lens = torch.as_tensor(
|
602 |
+
[t * h * w // (self.vision_tower.spatial_merge_size ** 2) for t, h, w in image_sizes])
|
603 |
+
image_num_patches = sum(feature_lens)
|
604 |
+
|
605 |
+
# NOTE we only support multimodal_patch_merge_type == "spatial_unpad"
|
606 |
+
inputs_embeds = inputs_embeds.to(image_features.dtype)
|
607 |
+
inputs_embeds, attention_mask, position_ids, labels, _ = self._merge_input_ids_with_image_features(
|
608 |
+
image_features,
|
609 |
+
feature_lens,
|
610 |
+
inputs_embeds,
|
611 |
+
input_ids,
|
612 |
+
attention_mask,
|
613 |
+
position_ids,
|
614 |
+
labels=labels,
|
615 |
+
)
|
616 |
+
|
617 |
+
# pixel_values is not None but is empty ---> text only cases
|
618 |
+
elif pixel_values is not None and input_ids.shape[1] != 1 and pixel_values.size(0) == 0:
|
619 |
+
# there are no images
|
620 |
+
pass
|
621 |
+
|
622 |
+
# In case input_ids.shape[1] == 1 & pixel_values==None & past_key_values != None, we are in the case of
|
623 |
+
# generation with cache
|
624 |
+
elif past_key_values is not None and pixel_values is not None and input_ids.shape[1] == 1:
|
625 |
+
# Retrieve the first layer to inspect the logits and mask out the hidden states
|
626 |
+
# that are set to 0
|
627 |
+
first_layer_past_key_value = past_key_values[0][0][:, :, :, 0]
|
628 |
+
|
629 |
+
# Sum all dimensions of head_dim (-2) to avoid random errors such as: https://github.com/huggingface/transformers/pull/28032#issuecomment-1863691941
|
630 |
+
batch_index, non_attended_tokens = torch.where(first_layer_past_key_value.float().sum(-2) == 0)
|
631 |
+
|
632 |
+
# Get the target length
|
633 |
+
target_length = input_ids.shape[1]
|
634 |
+
past_length = first_layer_past_key_value.shape[-1]
|
635 |
+
|
636 |
+
extended_attention_mask = torch.ones(
|
637 |
+
(attention_mask.shape[0], past_length),
|
638 |
+
dtype=attention_mask.dtype,
|
639 |
+
device=attention_mask.device,
|
640 |
+
)
|
641 |
+
|
642 |
+
# Filter out only the tokens that can be un-attended, this can happen
|
643 |
+
# if one uses EMOVA + Fused modules where the cache on the
|
644 |
+
# first iteration is already big enough, or if one passes custom cache
|
645 |
+
valid_indices = non_attended_tokens < extended_attention_mask.size(-1)
|
646 |
+
new_batch_index = batch_index[valid_indices]
|
647 |
+
new_non_attended_tokens = non_attended_tokens[valid_indices]
|
648 |
+
|
649 |
+
# Zero-out the places where we don't need to attend
|
650 |
+
extended_attention_mask[new_batch_index, new_non_attended_tokens] = 0
|
651 |
+
|
652 |
+
attention_mask = torch.cat((extended_attention_mask, attention_mask[:, -target_length:]), dim=1)
|
653 |
+
|
654 |
+
position_ids = torch.sum(attention_mask, dim=1).unsqueeze(-1) - 1
|
655 |
+
|
656 |
+
outputs = self.language_model(
|
657 |
+
attention_mask=attention_mask.to(inputs_embeds.device),
|
658 |
+
position_ids=position_ids,
|
659 |
+
past_key_values=past_key_values,
|
660 |
+
inputs_embeds=inputs_embeds,
|
661 |
+
use_cache=use_cache,
|
662 |
+
output_attentions=output_attentions,
|
663 |
+
output_hidden_states=output_hidden_states,
|
664 |
+
return_dict=return_dict,
|
665 |
+
)
|
666 |
+
|
667 |
+
logits = outputs[0]
|
668 |
+
|
669 |
+
loss = None
|
670 |
+
if labels is not None:
|
671 |
+
# Shift so that tokens < n predict n
|
672 |
+
if attention_mask is not None:
|
673 |
+
shift_attention_mask = attention_mask[..., 1:]
|
674 |
+
shift_logits = logits[..., :-1, :][shift_attention_mask.to(logits.device) != 0].contiguous()
|
675 |
+
shift_labels = labels[..., 1:][shift_attention_mask.to(labels.device) != 0].contiguous()
|
676 |
+
else:
|
677 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
678 |
+
shift_labels = labels[..., 1:].contiguous()
|
679 |
+
# Flatten the tokens
|
680 |
+
loss_fct = nn.CrossEntropyLoss()
|
681 |
+
loss = loss_fct(
|
682 |
+
shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1).to(shift_logits.device)
|
683 |
+
)
|
684 |
+
|
685 |
+
if not return_dict:
|
686 |
+
output = (logits,) + outputs[1:]
|
687 |
+
return (loss,) + output if loss is not None else output
|
688 |
+
|
689 |
+
return EMOVACausalLMOutputWithPast(
|
690 |
+
loss=loss,
|
691 |
+
logits=logits,
|
692 |
+
past_key_values=outputs.past_key_values,
|
693 |
+
hidden_states=outputs.hidden_states,
|
694 |
+
attentions=outputs.attentions,
|
695 |
+
)
|
696 |
+
|
697 |
+
def prepare_inputs_for_generation(
|
698 |
+
self,
|
699 |
+
input_ids,
|
700 |
+
past_key_values=None,
|
701 |
+
inputs_embeds=None,
|
702 |
+
pixel_values=None,
|
703 |
+
image_sizes=None,
|
704 |
+
attention_mask=None,
|
705 |
+
**kwargs,
|
706 |
+
):
|
707 |
+
if past_key_values is not None:
|
708 |
+
if isinstance(past_key_values, Cache):
|
709 |
+
cache_length = past_key_values.get_seq_length()
|
710 |
+
past_length = past_key_values.seen_tokens
|
711 |
+
else:
|
712 |
+
cache_length = past_length = past_key_values[0][0].shape[2]
|
713 |
+
|
714 |
+
# Keep only the unprocessed tokens:
|
715 |
+
# 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
|
716 |
+
# some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
|
717 |
+
# input)
|
718 |
+
if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
|
719 |
+
input_ids = input_ids[:, -(attention_mask.shape[1] - past_length):]
|
720 |
+
# 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
|
721 |
+
# input_ids based on the past_length.
|
722 |
+
elif past_length < input_ids.shape[1]:
|
723 |
+
input_ids = input_ids[:, past_length:]
|
724 |
+
# 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
|
725 |
+
elif self.config.image_token_index in input_ids:
|
726 |
+
input_ids = input_ids[:, input_ids.shape[1] - 1:]
|
727 |
+
# If the cache has seen more tokens than it can hold, then the cache has a size limit. Let's discard the
|
728 |
+
# older attention values, as their corresponding values are not part of the input.
|
729 |
+
if cache_length < past_length and attention_mask is not None:
|
730 |
+
attention_mask = attention_mask[:, -(cache_length + input_ids.shape[1]):]
|
731 |
+
|
732 |
+
position_ids = kwargs.get("position_ids", None)
|
733 |
+
if attention_mask is not None and position_ids is None:
|
734 |
+
# create position_ids on the fly for batch generation
|
735 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
736 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
737 |
+
if past_key_values:
|
738 |
+
position_ids = position_ids[:, -input_ids.shape[1]:]
|
739 |
+
|
740 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
741 |
+
if inputs_embeds is not None and past_key_values is None:
|
742 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
743 |
+
else:
|
744 |
+
model_inputs = {"input_ids": input_ids}
|
745 |
+
|
746 |
+
model_inputs.update(
|
747 |
+
{
|
748 |
+
"position_ids": position_ids,
|
749 |
+
"past_key_values": past_key_values,
|
750 |
+
"use_cache": kwargs.get("use_cache"),
|
751 |
+
"attention_mask": attention_mask,
|
752 |
+
"pixel_values": pixel_values,
|
753 |
+
"image_sizes": image_sizes,
|
754 |
+
}
|
755 |
+
)
|
756 |
+
return model_inputs
|
757 |
+
|
758 |
+
def chat(self, tokenizer, pixel_values, question, generation_config, history=None, return_history=False,
|
759 |
+
num_patches_list=None, IMG_START_TOKEN='<img>', IMG_END_TOKEN='</img>', IMG_CONTEXT_TOKEN='<IMG_CONTEXT>',
|
760 |
+
verbose=False):
|
761 |
+
raise RuntimeError("!!!")
|
762 |
+
|
763 |
+
if history is None and pixel_values is not None and '<image>' not in question:
|
764 |
+
question = '<image>\n' + question
|
765 |
+
|
766 |
+
if num_patches_list is None:
|
767 |
+
num_patches_list = [pixel_values.shape[0]] if pixel_values is not None else []
|
768 |
+
assert pixel_values is None or len(pixel_values) == sum(num_patches_list)
|
769 |
+
|
770 |
+
img_context_token_id = tokenizer.convert_tokens_to_ids(IMG_CONTEXT_TOKEN)
|
771 |
+
self.img_context_token_id = img_context_token_id
|
772 |
+
|
773 |
+
template = get_conv_template(self.template)
|
774 |
+
template.system_message = self.system_message
|
775 |
+
eos_token_id = tokenizer.convert_tokens_to_ids(template.sep)
|
776 |
+
|
777 |
+
history = [] if history is None else history
|
778 |
+
for (old_question, old_answer) in history:
|
779 |
+
template.append_message(template.roles[0], old_question)
|
780 |
+
template.append_message(template.roles[1], old_answer)
|
781 |
+
template.append_message(template.roles[0], question)
|
782 |
+
template.append_message(template.roles[1], None)
|
783 |
+
query = template.get_prompt()
|
784 |
+
|
785 |
+
if verbose and pixel_values is not None:
|
786 |
+
image_bs = pixel_values.shape[0]
|
787 |
+
print(f'dynamic ViT batch size: {image_bs}')
|
788 |
+
|
789 |
+
for num_patches in num_patches_list:
|
790 |
+
image_tokens = IMG_START_TOKEN + IMG_CONTEXT_TOKEN * self.num_image_token * num_patches + IMG_END_TOKEN
|
791 |
+
query = query.replace('<image>', image_tokens, 1)
|
792 |
+
|
793 |
+
model_inputs = tokenizer(query, return_tensors='pt')
|
794 |
+
input_ids = model_inputs['input_ids'].cuda()
|
795 |
+
attention_mask = model_inputs['attention_mask'].cuda()
|
796 |
+
generation_config['eos_token_id'] = eos_token_id
|
797 |
+
generation_output = self.generate(
|
798 |
+
pixel_values=pixel_values,
|
799 |
+
input_ids=input_ids,
|
800 |
+
attention_mask=attention_mask,
|
801 |
+
**generation_config
|
802 |
+
)
|
803 |
+
response = tokenizer.batch_decode(generation_output, skip_special_tokens=True)[0]
|
804 |
+
response = response.split(template.sep)[0].strip()
|
805 |
+
history.append((question, response))
|
806 |
+
if return_history:
|
807 |
+
return response, history
|
808 |
+
else:
|
809 |
+
query_to_print = query.replace(IMG_CONTEXT_TOKEN, '')
|
810 |
+
query_to_print = query_to_print.replace(f'{IMG_START_TOKEN}{IMG_END_TOKEN}', '<image>')
|
811 |
+
if verbose:
|
812 |
+
print(query_to_print, response)
|
813 |
+
return response
|
814 |
+
|
815 |
+
def _reorder_cache(self, *args, **kwargs):
|
816 |
+
return self.language_model._reorder_cache(*args, **kwargs)
|
modeling_qwen2vit.py
ADDED
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
5 |
+
# and OPT implementations in this library. It has been modified from its
|
6 |
+
# original forms to accommodate minor architectural differences compared
|
7 |
+
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
8 |
+
#
|
9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10 |
+
# you may not use this file except in compliance with the License.
|
11 |
+
# You may obtain a copy of the License at
|
12 |
+
#
|
13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14 |
+
#
|
15 |
+
# Unless required by applicable law or agreed to in writing, software
|
16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18 |
+
# See the License for the specific language governing permissions and
|
19 |
+
# limitations under the License.
|
20 |
+
"""PyTorch Qwen2-VL model."""
|
21 |
+
|
22 |
+
import math
|
23 |
+
from dataclasses import dataclass
|
24 |
+
from typing import Any, Dict, List, Optional, Tuple, Union
|
25 |
+
|
26 |
+
import torch
|
27 |
+
import torch.nn as nn
|
28 |
+
import torch.nn.functional as F
|
29 |
+
import torch.utils.checkpoint
|
30 |
+
from torch.nn import CrossEntropyLoss, LayerNorm
|
31 |
+
|
32 |
+
from transformers.activations import ACT2FN
|
33 |
+
from transformers.modeling_utils import PreTrainedModel
|
34 |
+
from transformers.utils import (
|
35 |
+
is_flash_attn_2_available,
|
36 |
+
logging,
|
37 |
+
)
|
38 |
+
from .configuration_qwen2vit import Qwen2VLVisionConfig
|
39 |
+
|
40 |
+
if is_flash_attn_2_available():
|
41 |
+
from flash_attn import flash_attn_varlen_func
|
42 |
+
|
43 |
+
from transformers.modeling_flash_attention_utils import _flash_attention_forward
|
44 |
+
else:
|
45 |
+
flash_attn_varlen_func = None
|
46 |
+
|
47 |
+
logger = logging.get_logger(__name__)
|
48 |
+
|
49 |
+
|
50 |
+
# Copied from transformers.models.llama.modeling_llama.rotate_half
|
51 |
+
def rotate_half(x):
|
52 |
+
"""Rotates half the hidden dims of the input."""
|
53 |
+
x1 = x[..., : x.shape[-1] // 2]
|
54 |
+
x2 = x[..., x.shape[-1] // 2:]
|
55 |
+
return torch.cat((-x2, x1), dim=-1)
|
56 |
+
|
57 |
+
|
58 |
+
def apply_rotary_pos_emb_vision(tensor: torch.Tensor, freqs: torch.Tensor) -> torch.Tensor:
|
59 |
+
orig_dtype = tensor.dtype
|
60 |
+
tensor = tensor.float()
|
61 |
+
cos = freqs.cos()
|
62 |
+
sin = freqs.sin()
|
63 |
+
cos = cos.unsqueeze(1).repeat(1, 1, 2).unsqueeze(0).float()
|
64 |
+
sin = sin.unsqueeze(1).repeat(1, 1, 2).unsqueeze(0).float()
|
65 |
+
output = (tensor * cos) + (rotate_half(tensor) * sin)
|
66 |
+
output = output.to(orig_dtype)
|
67 |
+
return output
|
68 |
+
|
69 |
+
|
70 |
+
class VisionRotaryEmbedding(nn.Module):
|
71 |
+
def __init__(self, dim: int, theta: float = 10000.0) -> None:
|
72 |
+
super().__init__()
|
73 |
+
inv_freq = 1.0 / (theta ** (torch.arange(0, dim, 2, dtype=torch.float) / dim))
|
74 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
75 |
+
|
76 |
+
def forward(self, seqlen: int) -> torch.Tensor:
|
77 |
+
seq = torch.arange(seqlen, device=self.inv_freq.device, dtype=self.inv_freq.dtype)
|
78 |
+
freqs = torch.outer(seq, self.inv_freq)
|
79 |
+
return freqs
|
80 |
+
|
81 |
+
|
82 |
+
class PatchEmbed(nn.Module):
|
83 |
+
def __init__(
|
84 |
+
self,
|
85 |
+
patch_size: int = 14,
|
86 |
+
temporal_patch_size: int = 2,
|
87 |
+
in_channels: int = 3,
|
88 |
+
embed_dim: int = 1152,
|
89 |
+
) -> None:
|
90 |
+
super().__init__()
|
91 |
+
self.patch_size = patch_size
|
92 |
+
self.temporal_patch_size = temporal_patch_size
|
93 |
+
self.in_channels = in_channels
|
94 |
+
self.embed_dim = embed_dim
|
95 |
+
|
96 |
+
kernel_size = [temporal_patch_size, patch_size, patch_size]
|
97 |
+
self.proj = nn.Conv3d(in_channels, embed_dim, kernel_size=kernel_size, stride=kernel_size, bias=False)
|
98 |
+
|
99 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
100 |
+
target_dtype = self.proj.weight.dtype
|
101 |
+
hidden_states = hidden_states.view(
|
102 |
+
-1, self.in_channels, self.temporal_patch_size, self.patch_size, self.patch_size
|
103 |
+
)
|
104 |
+
hidden_states = self.proj(hidden_states.to(dtype=target_dtype)).view(-1, self.embed_dim)
|
105 |
+
return hidden_states
|
106 |
+
|
107 |
+
|
108 |
+
class PatchMerger(nn.Module):
|
109 |
+
def __init__(self, dim: int, context_dim: int, spatial_merge_size: int = 2) -> None:
|
110 |
+
super().__init__()
|
111 |
+
self.hidden_size = context_dim * (spatial_merge_size ** 2)
|
112 |
+
self.ln_q = LayerNorm(context_dim, eps=1e-6)
|
113 |
+
self.mlp = nn.Sequential(
|
114 |
+
nn.Linear(self.hidden_size, self.hidden_size),
|
115 |
+
nn.GELU(),
|
116 |
+
nn.Linear(self.hidden_size, dim),
|
117 |
+
)
|
118 |
+
|
119 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
120 |
+
x = self.mlp(self.ln_q(x).view(-1, self.hidden_size))
|
121 |
+
return x
|
122 |
+
|
123 |
+
|
124 |
+
class VisionMlp(nn.Module):
|
125 |
+
def __init__(self, dim: int, hidden_dim: int, hidden_act: str) -> None:
|
126 |
+
super().__init__()
|
127 |
+
self.fc1 = nn.Linear(dim, hidden_dim)
|
128 |
+
self.act = ACT2FN[hidden_act]
|
129 |
+
self.fc2 = nn.Linear(hidden_dim, dim)
|
130 |
+
|
131 |
+
def forward(self, x) -> torch.Tensor:
|
132 |
+
return self.fc2(self.act(self.fc1(x)))
|
133 |
+
|
134 |
+
|
135 |
+
class VisionAttention(nn.Module):
|
136 |
+
def __init__(self, dim: int, num_heads: int = 16) -> None:
|
137 |
+
super().__init__()
|
138 |
+
self.num_heads = num_heads
|
139 |
+
self.head_dim = dim // num_heads
|
140 |
+
self.qkv = nn.Linear(dim, dim * 3, bias=True)
|
141 |
+
self.proj = nn.Linear(dim, dim)
|
142 |
+
|
143 |
+
def forward(
|
144 |
+
self, hidden_states: torch.Tensor, cu_seqlens: torch.Tensor, rotary_pos_emb: torch.Tensor = None
|
145 |
+
) -> torch.Tensor:
|
146 |
+
seq_length = hidden_states.shape[0]
|
147 |
+
q, k, v = self.qkv(hidden_states).reshape(seq_length, 3, self.num_heads, -1).permute(1, 0, 2, 3).unbind(0)
|
148 |
+
q = apply_rotary_pos_emb_vision(q.unsqueeze(0), rotary_pos_emb).squeeze(0)
|
149 |
+
k = apply_rotary_pos_emb_vision(k.unsqueeze(0), rotary_pos_emb).squeeze(0)
|
150 |
+
|
151 |
+
attention_mask = torch.full(
|
152 |
+
[1, seq_length, seq_length], torch.finfo(q.dtype).min, device=q.device, dtype=q.dtype
|
153 |
+
)
|
154 |
+
for i in range(1, len(cu_seqlens)):
|
155 |
+
attention_mask[..., cu_seqlens[i - 1]: cu_seqlens[i], cu_seqlens[i - 1]: cu_seqlens[i]] = 0
|
156 |
+
|
157 |
+
q = q.transpose(0, 1)
|
158 |
+
k = k.transpose(0, 1)
|
159 |
+
v = v.transpose(0, 1)
|
160 |
+
attn_weights = torch.matmul(q, k.transpose(1, 2)) / math.sqrt(self.head_dim)
|
161 |
+
attn_weights = attn_weights + attention_mask
|
162 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(q.dtype)
|
163 |
+
attn_output = torch.matmul(attn_weights, v)
|
164 |
+
attn_output = attn_output.transpose(0, 1)
|
165 |
+
attn_output = attn_output.reshape(seq_length, -1)
|
166 |
+
attn_output = self.proj(attn_output)
|
167 |
+
return attn_output
|
168 |
+
|
169 |
+
|
170 |
+
class VisionFlashAttention2(nn.Module):
|
171 |
+
def __init__(self, dim: int, num_heads: int = 16) -> None:
|
172 |
+
super().__init__()
|
173 |
+
self.num_heads = num_heads
|
174 |
+
self.qkv = nn.Linear(dim, dim * 3, bias=True)
|
175 |
+
self.proj = nn.Linear(dim, dim)
|
176 |
+
|
177 |
+
def forward(
|
178 |
+
self, hidden_states: torch.Tensor, cu_seqlens: torch.Tensor, rotary_pos_emb: torch.Tensor = None
|
179 |
+
) -> torch.Tensor:
|
180 |
+
seq_length = hidden_states.shape[0]
|
181 |
+
q, k, v = self.qkv(hidden_states).reshape(seq_length, 3, self.num_heads, -1).permute(1, 0, 2, 3).unbind(0)
|
182 |
+
q = apply_rotary_pos_emb_vision(q.unsqueeze(0), rotary_pos_emb).squeeze(0)
|
183 |
+
k = apply_rotary_pos_emb_vision(k.unsqueeze(0), rotary_pos_emb).squeeze(0)
|
184 |
+
|
185 |
+
max_seqlen = (cu_seqlens[1:] - cu_seqlens[:-1]).max().item()
|
186 |
+
attn_output = flash_attn_varlen_func(q, k, v, cu_seqlens, cu_seqlens, max_seqlen, max_seqlen).reshape(
|
187 |
+
seq_length, -1
|
188 |
+
)
|
189 |
+
attn_output = self.proj(attn_output)
|
190 |
+
return attn_output
|
191 |
+
|
192 |
+
|
193 |
+
class VisionSdpaAttention(nn.Module):
|
194 |
+
def __init__(self, dim: int, num_heads: int = 16) -> None:
|
195 |
+
super().__init__()
|
196 |
+
self.num_heads = num_heads
|
197 |
+
self.qkv = nn.Linear(dim, dim * 3, bias=True)
|
198 |
+
self.proj = nn.Linear(dim, dim)
|
199 |
+
|
200 |
+
def forward(
|
201 |
+
self, hidden_states: torch.Tensor, cu_seqlens: torch.Tensor, rotary_pos_emb: torch.Tensor = None
|
202 |
+
) -> torch.Tensor:
|
203 |
+
seq_length = hidden_states.shape[0]
|
204 |
+
q, k, v = self.qkv(hidden_states).reshape(seq_length, 3, self.num_heads, -1).permute(1, 0, 2, 3).unbind(0)
|
205 |
+
q = apply_rotary_pos_emb_vision(q.unsqueeze(0), rotary_pos_emb).squeeze(0)
|
206 |
+
k = apply_rotary_pos_emb_vision(k.unsqueeze(0), rotary_pos_emb).squeeze(0)
|
207 |
+
|
208 |
+
attention_mask = torch.zeros([1, seq_length, seq_length], device=q.device, dtype=torch.bool)
|
209 |
+
for i in range(1, len(cu_seqlens)):
|
210 |
+
attention_mask[..., cu_seqlens[i - 1]: cu_seqlens[i], cu_seqlens[i - 1]: cu_seqlens[i]] = True
|
211 |
+
q = q.transpose(0, 1)
|
212 |
+
k = k.transpose(0, 1)
|
213 |
+
v = v.transpose(0, 1)
|
214 |
+
attn_output = F.scaled_dot_product_attention(q, k, v, attention_mask, dropout_p=0.0)
|
215 |
+
attn_output = attn_output.transpose(0, 1)
|
216 |
+
attn_output = attn_output.reshape(seq_length, -1)
|
217 |
+
attn_output = self.proj(attn_output)
|
218 |
+
return attn_output
|
219 |
+
|
220 |
+
|
221 |
+
QWEN2_VL_VISION_ATTENTION_CLASSES = {
|
222 |
+
"eager": VisionAttention,
|
223 |
+
"flash_attention_2": VisionFlashAttention2,
|
224 |
+
"sdpa": VisionSdpaAttention,
|
225 |
+
}
|
226 |
+
|
227 |
+
|
228 |
+
class Qwen2VLVisionBlock(nn.Module):
|
229 |
+
def __init__(self, config, attn_implementation: str = "sdpa") -> None:
|
230 |
+
super().__init__()
|
231 |
+
self.norm1 = LayerNorm(config.embed_dim, eps=1e-6)
|
232 |
+
self.norm2 = LayerNorm(config.embed_dim, eps=1e-6)
|
233 |
+
mlp_hidden_dim = int(config.embed_dim * config.mlp_ratio)
|
234 |
+
|
235 |
+
self.attn = QWEN2_VL_VISION_ATTENTION_CLASSES[attn_implementation](
|
236 |
+
config.embed_dim, num_heads=config.num_heads
|
237 |
+
)
|
238 |
+
self.mlp = VisionMlp(dim=config.embed_dim, hidden_dim=mlp_hidden_dim, hidden_act=config.hidden_act)
|
239 |
+
|
240 |
+
def forward(self, hidden_states, cu_seqlens, rotary_pos_emb) -> torch.Tensor:
|
241 |
+
hidden_states = hidden_states + self.attn(
|
242 |
+
self.norm1(hidden_states), cu_seqlens=cu_seqlens, rotary_pos_emb=rotary_pos_emb
|
243 |
+
)
|
244 |
+
hidden_states = hidden_states + self.mlp(self.norm2(hidden_states))
|
245 |
+
return hidden_states
|
246 |
+
|
247 |
+
|
248 |
+
class Qwen2VisionTower(PreTrainedModel):
|
249 |
+
config_class = Qwen2VLVisionConfig
|
250 |
+
_no_split_modules = ["Qwen2VLVisionBlock"]
|
251 |
+
base_model_prefix = "model"
|
252 |
+
supports_gradient_checkpointing = True
|
253 |
+
_supports_flash_attn_2 = True
|
254 |
+
_supports_sdpa = True
|
255 |
+
|
256 |
+
def _init_weights(self, module):
|
257 |
+
std = self.config.initializer_range
|
258 |
+
if isinstance(module, (nn.Linear, nn.Conv3d)):
|
259 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
260 |
+
if module.bias is not None:
|
261 |
+
module.bias.data.zero_()
|
262 |
+
elif isinstance(module, nn.Embedding):
|
263 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
264 |
+
if module.padding_idx is not None:
|
265 |
+
module.weight.data[module.padding_idx].zero_()
|
266 |
+
|
267 |
+
def __init__(self, config) -> None:
|
268 |
+
super().__init__(config)
|
269 |
+
self.spatial_merge_size = config.spatial_merge_size
|
270 |
+
|
271 |
+
self.patch_embed = PatchEmbed(
|
272 |
+
patch_size=config.patch_size,
|
273 |
+
temporal_patch_size=config.temporal_patch_size,
|
274 |
+
in_channels=config.in_channels,
|
275 |
+
embed_dim=config.embed_dim,
|
276 |
+
)
|
277 |
+
|
278 |
+
head_dim = config.embed_dim // config.num_heads
|
279 |
+
self.rotary_pos_emb = VisionRotaryEmbedding(head_dim // 2)
|
280 |
+
|
281 |
+
self.blocks = nn.ModuleList(
|
282 |
+
[Qwen2VLVisionBlock(config, "eager") for _ in range(config.depth)]
|
283 |
+
)
|
284 |
+
self.merger = PatchMerger(
|
285 |
+
dim=config.hidden_size, context_dim=config.embed_dim, spatial_merge_size=config.spatial_merge_size
|
286 |
+
)
|
287 |
+
|
288 |
+
def get_dtype(self) -> torch.dtype:
|
289 |
+
return self.blocks[0].mlp.fc2.weight.dtype
|
290 |
+
|
291 |
+
def get_device(self) -> torch.device:
|
292 |
+
return self.blocks[0].mlp.fc2.weight.device
|
293 |
+
|
294 |
+
def rot_pos_emb(self, grid_thw):
|
295 |
+
pos_ids = []
|
296 |
+
for t, h, w in grid_thw:
|
297 |
+
hpos_ids = torch.arange(h).unsqueeze(1).expand(-1, w)
|
298 |
+
hpos_ids = hpos_ids.reshape(
|
299 |
+
h // self.spatial_merge_size,
|
300 |
+
self.spatial_merge_size,
|
301 |
+
w // self.spatial_merge_size,
|
302 |
+
self.spatial_merge_size,
|
303 |
+
)
|
304 |
+
hpos_ids = hpos_ids.permute(0, 2, 1, 3)
|
305 |
+
hpos_ids = hpos_ids.flatten()
|
306 |
+
|
307 |
+
wpos_ids = torch.arange(w).unsqueeze(0).expand(h, -1)
|
308 |
+
wpos_ids = wpos_ids.reshape(
|
309 |
+
h // self.spatial_merge_size,
|
310 |
+
self.spatial_merge_size,
|
311 |
+
w // self.spatial_merge_size,
|
312 |
+
self.spatial_merge_size,
|
313 |
+
)
|
314 |
+
wpos_ids = wpos_ids.permute(0, 2, 1, 3)
|
315 |
+
wpos_ids = wpos_ids.flatten()
|
316 |
+
pos_ids.append(torch.stack([hpos_ids, wpos_ids], dim=-1).repeat(t, 1))
|
317 |
+
pos_ids = torch.cat(pos_ids, dim=0)
|
318 |
+
max_grid_size = grid_thw[:, 1:].max()
|
319 |
+
rotary_pos_emb_full = self.rotary_pos_emb(max_grid_size)
|
320 |
+
rotary_pos_emb = rotary_pos_emb_full[pos_ids].flatten(1)
|
321 |
+
return rotary_pos_emb
|
322 |
+
|
323 |
+
def forward(self, hidden_states: torch.Tensor, grid_thw: torch.Tensor) -> torch.Tensor:
|
324 |
+
hidden_states = self.patch_embed(hidden_states)
|
325 |
+
rotary_pos_emb = self.rot_pos_emb(grid_thw)
|
326 |
+
|
327 |
+
cu_seqlens = torch.repeat_interleave(grid_thw[:, 1] * grid_thw[:, 2], grid_thw[:, 0]).cumsum(
|
328 |
+
dim=0, dtype=torch.int32
|
329 |
+
)
|
330 |
+
cu_seqlens = F.pad(cu_seqlens, (1, 0), value=0)
|
331 |
+
|
332 |
+
for blk in self.blocks:
|
333 |
+
hidden_states = blk(hidden_states, cu_seqlens=cu_seqlens, rotary_pos_emb=rotary_pos_emb)
|
334 |
+
|
335 |
+
return self.merger(hidden_states)
|