huseinzol05
commited on
Commit
•
8235038
1
Parent(s):
68eebdf
Upload MM_LLMs
Browse files- README.md +201 -0
- config.json +505 -0
- generation_config.json +4 -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 +0 -0
- modeling_combine.py +334 -0
README.md
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
200 |
+
|
201 |
+
|
config.json
ADDED
@@ -0,0 +1,505 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "multimodal-mistral/checkpoint-1000",
|
3 |
+
"architectures": [
|
4 |
+
"MM_LLMs"
|
5 |
+
],
|
6 |
+
"audio_config": {
|
7 |
+
"_name_or_path": "mesolitica/malaysian-whisper-small",
|
8 |
+
"activation_dropout": 0.0,
|
9 |
+
"activation_function": "gelu",
|
10 |
+
"add_cross_attention": false,
|
11 |
+
"apply_spec_augment": false,
|
12 |
+
"architectures": [
|
13 |
+
"WhisperForConditionalGeneration"
|
14 |
+
],
|
15 |
+
"attention_dropout": 0.0,
|
16 |
+
"bad_words_ids": null,
|
17 |
+
"begin_suppress_tokens": [
|
18 |
+
220,
|
19 |
+
50257
|
20 |
+
],
|
21 |
+
"bos_token_id": 50257,
|
22 |
+
"chunk_size_feed_forward": 0,
|
23 |
+
"classifier_proj_size": 256,
|
24 |
+
"cross_attention_hidden_size": null,
|
25 |
+
"d_model": 768,
|
26 |
+
"decoder_attention_heads": 12,
|
27 |
+
"decoder_ffn_dim": 3072,
|
28 |
+
"decoder_layerdrop": 0.0,
|
29 |
+
"decoder_layers": 12,
|
30 |
+
"decoder_start_token_id": 50258,
|
31 |
+
"diversity_penalty": 0.0,
|
32 |
+
"do_sample": false,
|
33 |
+
"dropout": 0.0,
|
34 |
+
"early_stopping": false,
|
35 |
+
"encoder_attention_heads": 12,
|
36 |
+
"encoder_ffn_dim": 3072,
|
37 |
+
"encoder_layerdrop": 0.0,
|
38 |
+
"encoder_layers": 12,
|
39 |
+
"encoder_no_repeat_ngram_size": 0,
|
40 |
+
"eos_token_id": 50257,
|
41 |
+
"exponential_decay_length_penalty": null,
|
42 |
+
"finetuning_task": null,
|
43 |
+
"forced_bos_token_id": null,
|
44 |
+
"forced_decoder_ids": [
|
45 |
+
[
|
46 |
+
1,
|
47 |
+
50259
|
48 |
+
],
|
49 |
+
[
|
50 |
+
2,
|
51 |
+
50359
|
52 |
+
],
|
53 |
+
[
|
54 |
+
3,
|
55 |
+
50363
|
56 |
+
]
|
57 |
+
],
|
58 |
+
"forced_eos_token_id": null,
|
59 |
+
"id2label": {
|
60 |
+
"0": "LABEL_0",
|
61 |
+
"1": "LABEL_1"
|
62 |
+
},
|
63 |
+
"init_std": 0.02,
|
64 |
+
"is_decoder": false,
|
65 |
+
"is_encoder_decoder": true,
|
66 |
+
"label2id": {
|
67 |
+
"LABEL_0": 0,
|
68 |
+
"LABEL_1": 1
|
69 |
+
},
|
70 |
+
"length_penalty": 1.0,
|
71 |
+
"mask_feature_length": 10,
|
72 |
+
"mask_feature_min_masks": 0,
|
73 |
+
"mask_feature_prob": 0.0,
|
74 |
+
"mask_time_length": 10,
|
75 |
+
"mask_time_min_masks": 2,
|
76 |
+
"mask_time_prob": 0.05,
|
77 |
+
"max_length": 448,
|
78 |
+
"max_source_positions": 1500,
|
79 |
+
"max_target_positions": 448,
|
80 |
+
"median_filter_width": 7,
|
81 |
+
"min_length": 0,
|
82 |
+
"model_type": "whisper",
|
83 |
+
"no_repeat_ngram_size": 0,
|
84 |
+
"num_beam_groups": 1,
|
85 |
+
"num_beams": 1,
|
86 |
+
"num_hidden_layers": 12,
|
87 |
+
"num_mel_bins": 80,
|
88 |
+
"num_return_sequences": 1,
|
89 |
+
"output_attentions": false,
|
90 |
+
"output_hidden_states": false,
|
91 |
+
"output_scores": false,
|
92 |
+
"pad_token_id": 50257,
|
93 |
+
"prefix": null,
|
94 |
+
"problem_type": null,
|
95 |
+
"pruned_heads": {},
|
96 |
+
"remove_invalid_values": false,
|
97 |
+
"repetition_penalty": 1.0,
|
98 |
+
"return_dict": true,
|
99 |
+
"return_dict_in_generate": false,
|
100 |
+
"scale_embedding": false,
|
101 |
+
"sep_token_id": null,
|
102 |
+
"suppress_tokens": [
|
103 |
+
1,
|
104 |
+
2,
|
105 |
+
7,
|
106 |
+
8,
|
107 |
+
9,
|
108 |
+
10,
|
109 |
+
14,
|
110 |
+
25,
|
111 |
+
26,
|
112 |
+
27,
|
113 |
+
28,
|
114 |
+
29,
|
115 |
+
31,
|
116 |
+
58,
|
117 |
+
59,
|
118 |
+
60,
|
119 |
+
61,
|
120 |
+
62,
|
121 |
+
63,
|
122 |
+
90,
|
123 |
+
91,
|
124 |
+
92,
|
125 |
+
93,
|
126 |
+
359,
|
127 |
+
503,
|
128 |
+
522,
|
129 |
+
542,
|
130 |
+
873,
|
131 |
+
893,
|
132 |
+
902,
|
133 |
+
918,
|
134 |
+
922,
|
135 |
+
931,
|
136 |
+
1350,
|
137 |
+
1853,
|
138 |
+
1982,
|
139 |
+
2460,
|
140 |
+
2627,
|
141 |
+
3246,
|
142 |
+
3253,
|
143 |
+
3268,
|
144 |
+
3536,
|
145 |
+
3846,
|
146 |
+
3961,
|
147 |
+
4183,
|
148 |
+
4667,
|
149 |
+
6585,
|
150 |
+
6647,
|
151 |
+
7273,
|
152 |
+
9061,
|
153 |
+
9383,
|
154 |
+
10428,
|
155 |
+
10929,
|
156 |
+
11938,
|
157 |
+
12033,
|
158 |
+
12331,
|
159 |
+
12562,
|
160 |
+
13793,
|
161 |
+
14157,
|
162 |
+
14635,
|
163 |
+
15265,
|
164 |
+
15618,
|
165 |
+
16553,
|
166 |
+
16604,
|
167 |
+
18362,
|
168 |
+
18956,
|
169 |
+
20075,
|
170 |
+
21675,
|
171 |
+
22520,
|
172 |
+
26130,
|
173 |
+
26161,
|
174 |
+
26435,
|
175 |
+
28279,
|
176 |
+
29464,
|
177 |
+
31650,
|
178 |
+
32302,
|
179 |
+
32470,
|
180 |
+
36865,
|
181 |
+
42863,
|
182 |
+
47425,
|
183 |
+
49870,
|
184 |
+
50254,
|
185 |
+
50258,
|
186 |
+
50360,
|
187 |
+
50361,
|
188 |
+
50362
|
189 |
+
],
|
190 |
+
"task_specific_params": null,
|
191 |
+
"temperature": 1.0,
|
192 |
+
"tf_legacy_loss": false,
|
193 |
+
"tie_encoder_decoder": false,
|
194 |
+
"tie_word_embeddings": true,
|
195 |
+
"tokenizer_class": null,
|
196 |
+
"top_k": 50,
|
197 |
+
"top_p": 1.0,
|
198 |
+
"torch_dtype": "bfloat16",
|
199 |
+
"torchscript": false,
|
200 |
+
"typical_p": 1.0,
|
201 |
+
"use_bfloat16": false,
|
202 |
+
"use_cache": true,
|
203 |
+
"use_weighted_layer_sum": false,
|
204 |
+
"vocab_size": 51865
|
205 |
+
},
|
206 |
+
"audio_select_layer": -2,
|
207 |
+
"auto_map": {
|
208 |
+
"AutoConfig": "modeling_combine.MM_LLMs_Config",
|
209 |
+
"AutoModel": "modeling_combine.MM_LLMs"
|
210 |
+
},
|
211 |
+
"image_config": {
|
212 |
+
"_name_or_path": "google/siglip-base-patch16-384",
|
213 |
+
"add_cross_attention": false,
|
214 |
+
"architectures": [
|
215 |
+
"SiglipModel"
|
216 |
+
],
|
217 |
+
"bad_words_ids": null,
|
218 |
+
"begin_suppress_tokens": null,
|
219 |
+
"bos_token_id": null,
|
220 |
+
"chunk_size_feed_forward": 0,
|
221 |
+
"cross_attention_hidden_size": null,
|
222 |
+
"decoder_start_token_id": null,
|
223 |
+
"diversity_penalty": 0.0,
|
224 |
+
"do_sample": false,
|
225 |
+
"early_stopping": false,
|
226 |
+
"encoder_no_repeat_ngram_size": 0,
|
227 |
+
"eos_token_id": null,
|
228 |
+
"exponential_decay_length_penalty": null,
|
229 |
+
"finetuning_task": null,
|
230 |
+
"forced_bos_token_id": null,
|
231 |
+
"forced_eos_token_id": null,
|
232 |
+
"id2label": {
|
233 |
+
"0": "LABEL_0",
|
234 |
+
"1": "LABEL_1"
|
235 |
+
},
|
236 |
+
"initializer_factor": 1.0,
|
237 |
+
"is_decoder": false,
|
238 |
+
"is_encoder_decoder": false,
|
239 |
+
"label2id": {
|
240 |
+
"LABEL_0": 0,
|
241 |
+
"LABEL_1": 1
|
242 |
+
},
|
243 |
+
"length_penalty": 1.0,
|
244 |
+
"max_length": 20,
|
245 |
+
"min_length": 0,
|
246 |
+
"model_type": "siglip",
|
247 |
+
"no_repeat_ngram_size": 0,
|
248 |
+
"num_beam_groups": 1,
|
249 |
+
"num_beams": 1,
|
250 |
+
"num_return_sequences": 1,
|
251 |
+
"output_attentions": false,
|
252 |
+
"output_hidden_states": false,
|
253 |
+
"output_scores": false,
|
254 |
+
"pad_token_id": null,
|
255 |
+
"prefix": null,
|
256 |
+
"problem_type": null,
|
257 |
+
"pruned_heads": {},
|
258 |
+
"remove_invalid_values": false,
|
259 |
+
"repetition_penalty": 1.0,
|
260 |
+
"return_dict": true,
|
261 |
+
"return_dict_in_generate": false,
|
262 |
+
"sep_token_id": null,
|
263 |
+
"suppress_tokens": null,
|
264 |
+
"task_specific_params": null,
|
265 |
+
"temperature": 1.0,
|
266 |
+
"text_config": {
|
267 |
+
"_name_or_path": "",
|
268 |
+
"add_cross_attention": false,
|
269 |
+
"architectures": null,
|
270 |
+
"attention_dropout": 0.0,
|
271 |
+
"bad_words_ids": null,
|
272 |
+
"begin_suppress_tokens": null,
|
273 |
+
"bos_token_id": 49406,
|
274 |
+
"chunk_size_feed_forward": 0,
|
275 |
+
"cross_attention_hidden_size": null,
|
276 |
+
"decoder_start_token_id": null,
|
277 |
+
"diversity_penalty": 0.0,
|
278 |
+
"do_sample": false,
|
279 |
+
"early_stopping": false,
|
280 |
+
"encoder_no_repeat_ngram_size": 0,
|
281 |
+
"eos_token_id": 49407,
|
282 |
+
"exponential_decay_length_penalty": null,
|
283 |
+
"finetuning_task": null,
|
284 |
+
"forced_bos_token_id": null,
|
285 |
+
"forced_eos_token_id": null,
|
286 |
+
"hidden_act": "gelu_pytorch_tanh",
|
287 |
+
"hidden_size": 768,
|
288 |
+
"id2label": {
|
289 |
+
"0": "LABEL_0",
|
290 |
+
"1": "LABEL_1"
|
291 |
+
},
|
292 |
+
"intermediate_size": 3072,
|
293 |
+
"is_decoder": false,
|
294 |
+
"is_encoder_decoder": false,
|
295 |
+
"label2id": {
|
296 |
+
"LABEL_0": 0,
|
297 |
+
"LABEL_1": 1
|
298 |
+
},
|
299 |
+
"layer_norm_eps": 1e-06,
|
300 |
+
"length_penalty": 1.0,
|
301 |
+
"max_length": 20,
|
302 |
+
"max_position_embeddings": 64,
|
303 |
+
"min_length": 0,
|
304 |
+
"model_type": "siglip_text_model",
|
305 |
+
"no_repeat_ngram_size": 0,
|
306 |
+
"num_attention_heads": 12,
|
307 |
+
"num_beam_groups": 1,
|
308 |
+
"num_beams": 1,
|
309 |
+
"num_hidden_layers": 12,
|
310 |
+
"num_return_sequences": 1,
|
311 |
+
"output_attentions": false,
|
312 |
+
"output_hidden_states": false,
|
313 |
+
"output_scores": false,
|
314 |
+
"pad_token_id": 1,
|
315 |
+
"prefix": null,
|
316 |
+
"problem_type": null,
|
317 |
+
"pruned_heads": {},
|
318 |
+
"remove_invalid_values": false,
|
319 |
+
"repetition_penalty": 1.0,
|
320 |
+
"return_dict": true,
|
321 |
+
"return_dict_in_generate": false,
|
322 |
+
"sep_token_id": null,
|
323 |
+
"suppress_tokens": null,
|
324 |
+
"task_specific_params": null,
|
325 |
+
"temperature": 1.0,
|
326 |
+
"tf_legacy_loss": false,
|
327 |
+
"tie_encoder_decoder": false,
|
328 |
+
"tie_word_embeddings": true,
|
329 |
+
"tokenizer_class": null,
|
330 |
+
"top_k": 50,
|
331 |
+
"top_p": 1.0,
|
332 |
+
"torch_dtype": null,
|
333 |
+
"torchscript": false,
|
334 |
+
"typical_p": 1.0,
|
335 |
+
"use_bfloat16": false,
|
336 |
+
"vocab_size": 32000
|
337 |
+
},
|
338 |
+
"tf_legacy_loss": false,
|
339 |
+
"tie_encoder_decoder": false,
|
340 |
+
"tie_word_embeddings": true,
|
341 |
+
"tokenizer_class": null,
|
342 |
+
"top_k": 50,
|
343 |
+
"top_p": 1.0,
|
344 |
+
"torch_dtype": "float32",
|
345 |
+
"torchscript": false,
|
346 |
+
"typical_p": 1.0,
|
347 |
+
"use_bfloat16": false,
|
348 |
+
"vision_config": {
|
349 |
+
"_name_or_path": "",
|
350 |
+
"add_cross_attention": false,
|
351 |
+
"architectures": null,
|
352 |
+
"attention_dropout": 0.0,
|
353 |
+
"bad_words_ids": null,
|
354 |
+
"begin_suppress_tokens": null,
|
355 |
+
"bos_token_id": null,
|
356 |
+
"chunk_size_feed_forward": 0,
|
357 |
+
"cross_attention_hidden_size": null,
|
358 |
+
"decoder_start_token_id": null,
|
359 |
+
"diversity_penalty": 0.0,
|
360 |
+
"do_sample": false,
|
361 |
+
"early_stopping": false,
|
362 |
+
"encoder_no_repeat_ngram_size": 0,
|
363 |
+
"eos_token_id": null,
|
364 |
+
"exponential_decay_length_penalty": null,
|
365 |
+
"finetuning_task": null,
|
366 |
+
"forced_bos_token_id": null,
|
367 |
+
"forced_eos_token_id": null,
|
368 |
+
"hidden_act": "gelu_pytorch_tanh",
|
369 |
+
"hidden_size": 768,
|
370 |
+
"id2label": {
|
371 |
+
"0": "LABEL_0",
|
372 |
+
"1": "LABEL_1"
|
373 |
+
},
|
374 |
+
"image_size": 384,
|
375 |
+
"intermediate_size": 3072,
|
376 |
+
"is_decoder": false,
|
377 |
+
"is_encoder_decoder": false,
|
378 |
+
"label2id": {
|
379 |
+
"LABEL_0": 0,
|
380 |
+
"LABEL_1": 1
|
381 |
+
},
|
382 |
+
"layer_norm_eps": 1e-06,
|
383 |
+
"length_penalty": 1.0,
|
384 |
+
"max_length": 20,
|
385 |
+
"min_length": 0,
|
386 |
+
"model_type": "siglip_vision_model",
|
387 |
+
"no_repeat_ngram_size": 0,
|
388 |
+
"num_attention_heads": 12,
|
389 |
+
"num_beam_groups": 1,
|
390 |
+
"num_beams": 1,
|
391 |
+
"num_channels": 3,
|
392 |
+
"num_hidden_layers": 12,
|
393 |
+
"num_return_sequences": 1,
|
394 |
+
"output_attentions": false,
|
395 |
+
"output_hidden_states": false,
|
396 |
+
"output_scores": false,
|
397 |
+
"pad_token_id": null,
|
398 |
+
"patch_size": 16,
|
399 |
+
"prefix": null,
|
400 |
+
"problem_type": null,
|
401 |
+
"pruned_heads": {},
|
402 |
+
"remove_invalid_values": false,
|
403 |
+
"repetition_penalty": 1.0,
|
404 |
+
"return_dict": true,
|
405 |
+
"return_dict_in_generate": false,
|
406 |
+
"sep_token_id": null,
|
407 |
+
"suppress_tokens": null,
|
408 |
+
"task_specific_params": null,
|
409 |
+
"temperature": 1.0,
|
410 |
+
"tf_legacy_loss": false,
|
411 |
+
"tie_encoder_decoder": false,
|
412 |
+
"tie_word_embeddings": true,
|
413 |
+
"tokenizer_class": null,
|
414 |
+
"top_k": 50,
|
415 |
+
"top_p": 1.0,
|
416 |
+
"torch_dtype": null,
|
417 |
+
"torchscript": false,
|
418 |
+
"typical_p": 1.0,
|
419 |
+
"use_bfloat16": false
|
420 |
+
}
|
421 |
+
},
|
422 |
+
"llm_config": {
|
423 |
+
"_name_or_path": "mesolitica/malaysian-mistral-7b-32k-instructions-v4",
|
424 |
+
"add_cross_attention": false,
|
425 |
+
"architectures": [
|
426 |
+
"MistralForCausalLM"
|
427 |
+
],
|
428 |
+
"attention_dropout": 0.0,
|
429 |
+
"bad_words_ids": null,
|
430 |
+
"begin_suppress_tokens": null,
|
431 |
+
"bos_token_id": 1,
|
432 |
+
"chunk_size_feed_forward": 0,
|
433 |
+
"cross_attention_hidden_size": null,
|
434 |
+
"decoder_start_token_id": null,
|
435 |
+
"diversity_penalty": 0.0,
|
436 |
+
"do_sample": false,
|
437 |
+
"early_stopping": false,
|
438 |
+
"encoder_no_repeat_ngram_size": 0,
|
439 |
+
"eos_token_id": 2,
|
440 |
+
"exponential_decay_length_penalty": null,
|
441 |
+
"finetuning_task": null,
|
442 |
+
"forced_bos_token_id": null,
|
443 |
+
"forced_eos_token_id": null,
|
444 |
+
"hidden_act": "silu",
|
445 |
+
"hidden_size": 4096,
|
446 |
+
"id2label": {
|
447 |
+
"0": "LABEL_0",
|
448 |
+
"1": "LABEL_1"
|
449 |
+
},
|
450 |
+
"initializer_range": 0.02,
|
451 |
+
"intermediate_size": 14336,
|
452 |
+
"is_decoder": false,
|
453 |
+
"is_encoder_decoder": false,
|
454 |
+
"label2id": {
|
455 |
+
"LABEL_0": 0,
|
456 |
+
"LABEL_1": 1
|
457 |
+
},
|
458 |
+
"length_penalty": 1.0,
|
459 |
+
"max_length": 20,
|
460 |
+
"max_position_embeddings": 32768,
|
461 |
+
"min_length": 0,
|
462 |
+
"model_type": "mistral",
|
463 |
+
"no_repeat_ngram_size": 0,
|
464 |
+
"num_attention_heads": 32,
|
465 |
+
"num_beam_groups": 1,
|
466 |
+
"num_beams": 1,
|
467 |
+
"num_hidden_layers": 32,
|
468 |
+
"num_key_value_heads": 8,
|
469 |
+
"num_return_sequences": 1,
|
470 |
+
"output_attentions": false,
|
471 |
+
"output_hidden_states": false,
|
472 |
+
"output_scores": false,
|
473 |
+
"pad_token_id": null,
|
474 |
+
"prefix": null,
|
475 |
+
"problem_type": null,
|
476 |
+
"pruned_heads": {},
|
477 |
+
"remove_invalid_values": false,
|
478 |
+
"repetition_penalty": 1.0,
|
479 |
+
"return_dict": true,
|
480 |
+
"return_dict_in_generate": false,
|
481 |
+
"rms_norm_eps": 1e-05,
|
482 |
+
"rope_theta": 10000.0,
|
483 |
+
"sep_token_id": null,
|
484 |
+
"sliding_window": 4096,
|
485 |
+
"suppress_tokens": null,
|
486 |
+
"task_specific_params": null,
|
487 |
+
"temperature": 1.0,
|
488 |
+
"tf_legacy_loss": false,
|
489 |
+
"tie_encoder_decoder": false,
|
490 |
+
"tie_word_embeddings": false,
|
491 |
+
"tokenizer_class": null,
|
492 |
+
"top_k": 50,
|
493 |
+
"top_p": 1.0,
|
494 |
+
"torch_dtype": "bfloat16",
|
495 |
+
"torchscript": false,
|
496 |
+
"typical_p": 1.0,
|
497 |
+
"use_bfloat16": false,
|
498 |
+
"use_cache": true,
|
499 |
+
"vocab_size": 32004
|
500 |
+
},
|
501 |
+
"model_type": "mm_llms",
|
502 |
+
"torch_dtype": "bfloat16",
|
503 |
+
"transformers_version": "4.37.2",
|
504 |
+
"vision_select_layer": -2
|
505 |
+
}
|
generation_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"transformers_version": "4.37.2"
|
4 |
+
}
|
model-00001-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5161806048dd44f72c03b60315714b36fe294154deb1ccac549abb7f1e5bb5c6
|
3 |
+
size 4961225036
|
model-00002-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:22477ce687ca06bd01af0fe71049127e6ffb41331cec89d02bba68d288f8ca9d
|
3 |
+
size 4999819752
|
model-00003-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:93bda8dcfa1ec04e912d9378243dec58b8dc9985e04a60631bca7ba3d290c83c
|
3 |
+
size 4915916584
|
model-00004-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a435eaeed33c8d8f53e8104d759442ad6c36dab681955bd2ade80071f45096fe
|
3 |
+
size 822175216
|
model.safetensors.index.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
modeling_combine.py
ADDED
@@ -0,0 +1,334 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from collections import Counter, defaultdict
|
2 |
+
import numpy as np
|
3 |
+
import torch
|
4 |
+
import torch.nn.functional as F
|
5 |
+
from torch import Tensor
|
6 |
+
from torch import nn
|
7 |
+
from torch.nn import CrossEntropyLoss
|
8 |
+
import copy
|
9 |
+
import math
|
10 |
+
from transformers.activations import gelu
|
11 |
+
from typing import List, Optional, Tuple, Union
|
12 |
+
from transformers.modeling_utils import PreTrainedModel, PretrainedConfig
|
13 |
+
from transformers import CONFIG_MAPPING
|
14 |
+
from transformers.modeling_outputs import BaseModelOutput
|
15 |
+
from transformers import GenerationConfig
|
16 |
+
from transformers import CLIPConfig, CLIPProcessor, CLIPModel, AutoModel
|
17 |
+
from transformers import WhisperConfig, WhisperPreTrainedModel, WhisperModel
|
18 |
+
from transformers import AutoConfig, AutoModelForCausalLM, LlamaConfig
|
19 |
+
|
20 |
+
|
21 |
+
def most_frequent_element(tensor):
|
22 |
+
flattened_list = tensor.flatten().tolist()
|
23 |
+
counter = Counter(flattened_list)
|
24 |
+
most_common_element = counter.most_common(1)[0][1]
|
25 |
+
|
26 |
+
return most_common_element
|
27 |
+
|
28 |
+
|
29 |
+
class MM_LLMs_Config(PretrainedConfig):
|
30 |
+
model_type = 'mm_llms'
|
31 |
+
is_composition = True
|
32 |
+
|
33 |
+
def __init__(
|
34 |
+
self,
|
35 |
+
image_config=None,
|
36 |
+
audio_config=None,
|
37 |
+
llm_config=None,
|
38 |
+
audio_select_layer=-2,
|
39 |
+
vision_select_layer=-2,
|
40 |
+
**kwargs
|
41 |
+
):
|
42 |
+
|
43 |
+
self.image_config = image_config
|
44 |
+
self.audio_config = audio_config
|
45 |
+
self.llm_config = llm_config
|
46 |
+
self.audio_select_layer = audio_select_layer
|
47 |
+
self.vision_select_layer = vision_select_layer
|
48 |
+
|
49 |
+
if isinstance(self.image_config, dict):
|
50 |
+
image_config["model_type"] = (
|
51 |
+
image_config["model_type"] if "model_type" in image_config else "clip"
|
52 |
+
)
|
53 |
+
self.image_config = CONFIG_MAPPING[image_config["model_type"]](**image_config)
|
54 |
+
if isinstance(self.audio_config, dict):
|
55 |
+
audio_config["model_type"] = (
|
56 |
+
audio_config["model_type"] if "model_type" in audio_config else "whisper"
|
57 |
+
)
|
58 |
+
self.audio_config = CONFIG_MAPPING[audio_config["model_type"]](**audio_config)
|
59 |
+
if isinstance(self.llm_config, dict):
|
60 |
+
llm_config["model_type"] = llm_config["model_type"] if "model_type" in llm_config else "llama"
|
61 |
+
self.llm_config = CONFIG_MAPPING[llm_config["model_type"]](**llm_config)
|
62 |
+
|
63 |
+
super().__init__(**kwargs)
|
64 |
+
|
65 |
+
|
66 |
+
class LlavaMultiModalProjector(nn.Module):
|
67 |
+
def __init__(self, in_hidden_size, out_hidden_size, conv_kernel=None, conv_stride=3):
|
68 |
+
super().__init__()
|
69 |
+
|
70 |
+
self.conv_kernel = conv_kernel
|
71 |
+
|
72 |
+
if conv_kernel:
|
73 |
+
self.linear_1 = nn.Conv1d(
|
74 |
+
in_hidden_size,
|
75 |
+
out_hidden_size,
|
76 |
+
kernel_size=conv_kernel,
|
77 |
+
stride=conv_stride)
|
78 |
+
else:
|
79 |
+
self.linear_1 = nn.Linear(
|
80 |
+
in_hidden_size,
|
81 |
+
out_hidden_size,
|
82 |
+
bias=True,
|
83 |
+
)
|
84 |
+
self.act = gelu
|
85 |
+
self.linear_2 = nn.Linear(
|
86 |
+
out_hidden_size,
|
87 |
+
out_hidden_size,
|
88 |
+
bias=True)
|
89 |
+
|
90 |
+
def forward(self, image_features):
|
91 |
+
hidden_states = self.linear_1(image_features)
|
92 |
+
if self.conv_kernel:
|
93 |
+
hidden_states = hidden_states.transpose(1, 2).contiguous()
|
94 |
+
hidden_states = self.act(hidden_states)
|
95 |
+
hidden_states = self.linear_2(hidden_states)
|
96 |
+
return hidden_states
|
97 |
+
|
98 |
+
|
99 |
+
class MM_LLMs(PreTrainedModel):
|
100 |
+
config_class = MM_LLMs_Config
|
101 |
+
supports_gradient_checkpointing = True
|
102 |
+
_supports_flash_attn_2 = True
|
103 |
+
|
104 |
+
def __init__(self, config, flash_attention=False, dtype=torch.float32):
|
105 |
+
super().__init__(config)
|
106 |
+
self.config = config
|
107 |
+
|
108 |
+
self.image_encoder = AutoModel.from_config(config.image_config)
|
109 |
+
|
110 |
+
self.audio_encoder = AutoModel.from_config(
|
111 |
+
config.audio_config,
|
112 |
+
use_flash_attention_2=flash_attention,
|
113 |
+
torch_dtype=dtype,
|
114 |
+
)
|
115 |
+
|
116 |
+
self.llm = AutoModelForCausalLM.from_config(
|
117 |
+
config.llm_config,
|
118 |
+
use_flash_attention_2=flash_attention,
|
119 |
+
torch_dtype=dtype,
|
120 |
+
)
|
121 |
+
|
122 |
+
self.image_projector = LlavaMultiModalProjector(
|
123 |
+
config.image_config.vision_config.hidden_size,
|
124 |
+
config.llm_config.hidden_size
|
125 |
+
)
|
126 |
+
self.audio_projector = LlavaMultiModalProjector(
|
127 |
+
config.audio_config.d_model,
|
128 |
+
config.llm_config.hidden_size,
|
129 |
+
conv_kernel=40,
|
130 |
+
conv_stride=3,
|
131 |
+
)
|
132 |
+
|
133 |
+
def forward(self,
|
134 |
+
input_ids: torch.LongTensor = None,
|
135 |
+
image_index: torch.LongTensor = None,
|
136 |
+
audio_index: torch.LongTensor = None,
|
137 |
+
image_starts: torch.int = None,
|
138 |
+
image_ends: torch.int = None,
|
139 |
+
audio_starts: torch.int = None,
|
140 |
+
audio_ends: torch.int = None,
|
141 |
+
images: torch.FloatTensor = None,
|
142 |
+
audios: torch.FloatTensor = None,
|
143 |
+
attention_mask: Optional[torch.Tensor] = None,
|
144 |
+
position_ids: Optional[torch.LongTensor] = None,
|
145 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
146 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
147 |
+
labels: Optional[torch.LongTensor] = None,
|
148 |
+
output_attentions: Optional[bool] = None,
|
149 |
+
output_hidden_states: Optional[bool] = None,
|
150 |
+
use_cache: Optional[bool] = None,
|
151 |
+
return_dict: Optional[bool] = None,
|
152 |
+
where_is_b=None,
|
153 |
+
where_is_k=None,
|
154 |
+
ls=None,
|
155 |
+
**kwargs):
|
156 |
+
|
157 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
158 |
+
|
159 |
+
images = images.type(self.image_encoder.dtype) if images is not None else None
|
160 |
+
audios = audios.type(self.audio_encoder.dtype) if audios is not None else None
|
161 |
+
|
162 |
+
print(
|
163 |
+
where_is_b,
|
164 |
+
where_is_k,
|
165 |
+
ls,
|
166 |
+
image_index,
|
167 |
+
audio_index,
|
168 |
+
input_ids.shape,
|
169 |
+
images.shape,
|
170 |
+
audios.shape,
|
171 |
+
)
|
172 |
+
|
173 |
+
model_inputs = self.prepare_inputs_for_generation(
|
174 |
+
input_ids=input_ids,
|
175 |
+
image_index=image_index,
|
176 |
+
audio_index=audio_index,
|
177 |
+
image_starts=image_starts,
|
178 |
+
image_ends=image_ends,
|
179 |
+
audio_starts=audio_starts,
|
180 |
+
audio_ends=audio_ends,
|
181 |
+
images=images,
|
182 |
+
audios=audios,
|
183 |
+
attention_mask=attention_mask,
|
184 |
+
labels=labels,
|
185 |
+
where_is_b=where_is_b,
|
186 |
+
where_is_k=where_is_k,
|
187 |
+
ls=ls)
|
188 |
+
|
189 |
+
outputs = self.llm(
|
190 |
+
inputs_embeds=model_inputs['inputs_embeds'],
|
191 |
+
attention_mask=model_inputs['attention_mask'],
|
192 |
+
labels=model_inputs['labels'],
|
193 |
+
return_dict=return_dict)
|
194 |
+
|
195 |
+
return outputs
|
196 |
+
|
197 |
+
def prepare_inputs_for_generation(
|
198 |
+
self,
|
199 |
+
input_ids,
|
200 |
+
past_key_values=None,
|
201 |
+
inputs_embeds=None,
|
202 |
+
images=None,
|
203 |
+
audios=None,
|
204 |
+
audio_starts=None,
|
205 |
+
audio_ends=None,
|
206 |
+
image_starts=None,
|
207 |
+
image_ends=None,
|
208 |
+
attention_mask=None,
|
209 |
+
labels=None,
|
210 |
+
audio_index=None,
|
211 |
+
image_index=None,
|
212 |
+
where_is_b=None,
|
213 |
+
where_is_k=None,
|
214 |
+
ls=None,
|
215 |
+
inference=False,
|
216 |
+
**kwargs):
|
217 |
+
|
218 |
+
image_features = self.encode_image(
|
219 |
+
images) if images is not None else None
|
220 |
+
audio_features = self.encode_audio(
|
221 |
+
audios) if audios is not None else None
|
222 |
+
embed_tokens = self.llm.model.embed_tokens
|
223 |
+
text_embeddings = embed_tokens(input_ids)
|
224 |
+
batch_size = text_embeddings.shape[0]
|
225 |
+
seq_len = text_embeddings.shape[1]
|
226 |
+
embed_dim = text_embeddings.shape[2]
|
227 |
+
|
228 |
+
if len(audio_index):
|
229 |
+
max_count_audio = most_frequent_element(audio_index)
|
230 |
+
else:
|
231 |
+
max_count_audio = 0
|
232 |
+
if len(image_index):
|
233 |
+
max_count_image = most_frequent_element(image_index)
|
234 |
+
else:
|
235 |
+
max_count_image = 0
|
236 |
+
|
237 |
+
if audio_features is not None:
|
238 |
+
seq_audio = audio_features.shape[1]
|
239 |
+
else:
|
240 |
+
seq_audio = 0
|
241 |
+
|
242 |
+
if image_features is not None:
|
243 |
+
seq_image = image_features.shape[1]
|
244 |
+
else:
|
245 |
+
seq_image = 0
|
246 |
+
|
247 |
+
audio_len = seq_audio * max_count_audio
|
248 |
+
image_len = seq_image * max_count_image
|
249 |
+
|
250 |
+
new_len = text_embeddings.shape[1] + audio_len + image_len
|
251 |
+
final_embedding = torch.zeros(
|
252 |
+
batch_size, new_len, embed_dim,
|
253 |
+
device=text_embeddings.device,
|
254 |
+
dtype=text_embeddings.dtype
|
255 |
+
)
|
256 |
+
final_embedding[:, :seq_len] = text_embeddings
|
257 |
+
final_attention_mask = torch.zeros(
|
258 |
+
batch_size, new_len,
|
259 |
+
device=attention_mask.device,
|
260 |
+
dtype=attention_mask.dtype
|
261 |
+
)
|
262 |
+
final_attention_mask[:, :seq_len] = attention_mask
|
263 |
+
if labels is not None:
|
264 |
+
final_labels = torch.full(
|
265 |
+
(batch_size, new_len),
|
266 |
+
-100,
|
267 |
+
device=labels.device,
|
268 |
+
dtype=labels.dtype
|
269 |
+
)
|
270 |
+
final_labels[:, :seq_len] = labels
|
271 |
+
else:
|
272 |
+
final_labels = None
|
273 |
+
|
274 |
+
image_id = int(image_starts[0])
|
275 |
+
audio_id = int(audio_starts[0])
|
276 |
+
|
277 |
+
positions = defaultdict(int)
|
278 |
+
b_image = 0
|
279 |
+
b_audio = 0
|
280 |
+
|
281 |
+
for i in range(len(where_is_b)):
|
282 |
+
b, k = where_is_b[i], where_is_k[i]
|
283 |
+
int_b = int(b)
|
284 |
+
int_k = int(k)
|
285 |
+
l = int(ls[i])
|
286 |
+
if l == image_id:
|
287 |
+
f = image_features[b_image]
|
288 |
+
b_image += 1
|
289 |
+
if l == audio_id:
|
290 |
+
f = audio_features[b_audio]
|
291 |
+
b_audio += 1
|
292 |
+
|
293 |
+
c = torch.cat([final_embedding[b, :int_k + 1 + positions[int_b]],
|
294 |
+
f, text_embeddings[b, k + 1:]])
|
295 |
+
final_embedding[b, :len(c)] = c
|
296 |
+
final_attention_mask[b, :len(c)] = 1.0
|
297 |
+
|
298 |
+
if labels is not None:
|
299 |
+
ignore = torch.tensor([-100] * len(f), device=labels.device)
|
300 |
+
c_label = torch.cat(
|
301 |
+
[final_labels[b, :int_k + 1 + positions[int_b]], ignore, labels[b, k + 1:]])
|
302 |
+
final_labels[b, :len(c)] = c_label
|
303 |
+
|
304 |
+
positions[int_b] += len(f)
|
305 |
+
|
306 |
+
if not inference:
|
307 |
+
final_attention_mask[:, :seq_audio + seq_image + 2] = 0.0
|
308 |
+
|
309 |
+
if labels is not None:
|
310 |
+
final_labels[:, :seq_audio + seq_image + 2] = -100
|
311 |
+
|
312 |
+
model_inputs = {
|
313 |
+
"input_ids": input_ids,
|
314 |
+
"inputs_embeds": final_embedding,
|
315 |
+
"use_cache": kwargs.get("use_cache"),
|
316 |
+
"attention_mask": final_attention_mask,
|
317 |
+
"labels": final_labels,
|
318 |
+
}
|
319 |
+
return model_inputs
|
320 |
+
|
321 |
+
def encode_audio(self, audios):
|
322 |
+
encoded = self.audio_encoder.encoder(audios, output_hidden_states=True)
|
323 |
+
encoded = encoded.hidden_states[self.config.audio_select_layer]
|
324 |
+
audio_features = self.audio_projector(encoded.transpose(1, 2).contiguous())
|
325 |
+
return audio_features
|
326 |
+
|
327 |
+
def encode_image(self, images):
|
328 |
+
if self.config.vision_select_layer is not None:
|
329 |
+
encoded = self.image_encoder.vision_model(images, output_hidden_states=True)
|
330 |
+
encoded = encoded.hidden_states[self.config.vision_select_layer]
|
331 |
+
else:
|
332 |
+
encoded = self.image_encoder.vision_model(images)[0]
|
333 |
+
image_features = self.image_projector(encoded)
|
334 |
+
return image_features
|