huseinzol05 commited on
Commit
595c258
1 Parent(s): 89b02a3

Upload MM_LLMs

Browse files
Files changed (5) hide show
  1. README.md +201 -0
  2. config.json +508 -0
  3. generation_config.json +4 -0
  4. model.safetensors +3 -0
  5. 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,508 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "multimodal-tinyllama/checkpoint-2000",
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
+ "hidden_size": 2048,
212
+ "image_config": {
213
+ "_name_or_path": "google/siglip-base-patch16-384",
214
+ "add_cross_attention": false,
215
+ "architectures": [
216
+ "SiglipModel"
217
+ ],
218
+ "bad_words_ids": null,
219
+ "begin_suppress_tokens": null,
220
+ "bos_token_id": null,
221
+ "chunk_size_feed_forward": 0,
222
+ "cross_attention_hidden_size": null,
223
+ "decoder_start_token_id": null,
224
+ "diversity_penalty": 0.0,
225
+ "do_sample": false,
226
+ "early_stopping": false,
227
+ "encoder_no_repeat_ngram_size": 0,
228
+ "eos_token_id": null,
229
+ "exponential_decay_length_penalty": null,
230
+ "finetuning_task": null,
231
+ "forced_bos_token_id": null,
232
+ "forced_eos_token_id": null,
233
+ "id2label": {
234
+ "0": "LABEL_0",
235
+ "1": "LABEL_1"
236
+ },
237
+ "initializer_factor": 1.0,
238
+ "is_decoder": false,
239
+ "is_encoder_decoder": false,
240
+ "label2id": {
241
+ "LABEL_0": 0,
242
+ "LABEL_1": 1
243
+ },
244
+ "length_penalty": 1.0,
245
+ "max_length": 20,
246
+ "min_length": 0,
247
+ "model_type": "siglip",
248
+ "no_repeat_ngram_size": 0,
249
+ "num_beam_groups": 1,
250
+ "num_beams": 1,
251
+ "num_return_sequences": 1,
252
+ "output_attentions": false,
253
+ "output_hidden_states": false,
254
+ "output_scores": false,
255
+ "pad_token_id": null,
256
+ "prefix": null,
257
+ "problem_type": null,
258
+ "pruned_heads": {},
259
+ "remove_invalid_values": false,
260
+ "repetition_penalty": 1.0,
261
+ "return_dict": true,
262
+ "return_dict_in_generate": false,
263
+ "sep_token_id": null,
264
+ "suppress_tokens": null,
265
+ "task_specific_params": null,
266
+ "temperature": 1.0,
267
+ "text_config": {
268
+ "_name_or_path": "",
269
+ "add_cross_attention": false,
270
+ "architectures": null,
271
+ "attention_dropout": 0.0,
272
+ "bad_words_ids": null,
273
+ "begin_suppress_tokens": null,
274
+ "bos_token_id": 49406,
275
+ "chunk_size_feed_forward": 0,
276
+ "cross_attention_hidden_size": null,
277
+ "decoder_start_token_id": null,
278
+ "diversity_penalty": 0.0,
279
+ "do_sample": false,
280
+ "early_stopping": false,
281
+ "encoder_no_repeat_ngram_size": 0,
282
+ "eos_token_id": 49407,
283
+ "exponential_decay_length_penalty": null,
284
+ "finetuning_task": null,
285
+ "forced_bos_token_id": null,
286
+ "forced_eos_token_id": null,
287
+ "hidden_act": "gelu_pytorch_tanh",
288
+ "hidden_size": 768,
289
+ "id2label": {
290
+ "0": "LABEL_0",
291
+ "1": "LABEL_1"
292
+ },
293
+ "intermediate_size": 3072,
294
+ "is_decoder": false,
295
+ "is_encoder_decoder": false,
296
+ "label2id": {
297
+ "LABEL_0": 0,
298
+ "LABEL_1": 1
299
+ },
300
+ "layer_norm_eps": 1e-06,
301
+ "length_penalty": 1.0,
302
+ "max_length": 20,
303
+ "max_position_embeddings": 64,
304
+ "min_length": 0,
305
+ "model_type": "siglip_text_model",
306
+ "no_repeat_ngram_size": 0,
307
+ "num_attention_heads": 12,
308
+ "num_beam_groups": 1,
309
+ "num_beams": 1,
310
+ "num_hidden_layers": 12,
311
+ "num_return_sequences": 1,
312
+ "output_attentions": false,
313
+ "output_hidden_states": false,
314
+ "output_scores": false,
315
+ "pad_token_id": 1,
316
+ "prefix": null,
317
+ "problem_type": null,
318
+ "pruned_heads": {},
319
+ "remove_invalid_values": false,
320
+ "repetition_penalty": 1.0,
321
+ "return_dict": true,
322
+ "return_dict_in_generate": false,
323
+ "sep_token_id": null,
324
+ "suppress_tokens": null,
325
+ "task_specific_params": null,
326
+ "temperature": 1.0,
327
+ "tf_legacy_loss": false,
328
+ "tie_encoder_decoder": false,
329
+ "tie_word_embeddings": true,
330
+ "tokenizer_class": null,
331
+ "top_k": 50,
332
+ "top_p": 1.0,
333
+ "torch_dtype": null,
334
+ "torchscript": false,
335
+ "typical_p": 1.0,
336
+ "use_bfloat16": false,
337
+ "vocab_size": 32000
338
+ },
339
+ "tf_legacy_loss": false,
340
+ "tie_encoder_decoder": false,
341
+ "tie_word_embeddings": true,
342
+ "tokenizer_class": null,
343
+ "top_k": 50,
344
+ "top_p": 1.0,
345
+ "torch_dtype": "float32",
346
+ "torchscript": false,
347
+ "typical_p": 1.0,
348
+ "use_bfloat16": false,
349
+ "vision_config": {
350
+ "_name_or_path": "",
351
+ "add_cross_attention": false,
352
+ "architectures": null,
353
+ "attention_dropout": 0.0,
354
+ "bad_words_ids": null,
355
+ "begin_suppress_tokens": null,
356
+ "bos_token_id": null,
357
+ "chunk_size_feed_forward": 0,
358
+ "cross_attention_hidden_size": null,
359
+ "decoder_start_token_id": null,
360
+ "diversity_penalty": 0.0,
361
+ "do_sample": false,
362
+ "early_stopping": false,
363
+ "encoder_no_repeat_ngram_size": 0,
364
+ "eos_token_id": null,
365
+ "exponential_decay_length_penalty": null,
366
+ "finetuning_task": null,
367
+ "forced_bos_token_id": null,
368
+ "forced_eos_token_id": null,
369
+ "hidden_act": "gelu_pytorch_tanh",
370
+ "hidden_size": 768,
371
+ "id2label": {
372
+ "0": "LABEL_0",
373
+ "1": "LABEL_1"
374
+ },
375
+ "image_size": 384,
376
+ "intermediate_size": 3072,
377
+ "is_decoder": false,
378
+ "is_encoder_decoder": false,
379
+ "label2id": {
380
+ "LABEL_0": 0,
381
+ "LABEL_1": 1
382
+ },
383
+ "layer_norm_eps": 1e-06,
384
+ "length_penalty": 1.0,
385
+ "max_length": 20,
386
+ "min_length": 0,
387
+ "model_type": "siglip_vision_model",
388
+ "no_repeat_ngram_size": 0,
389
+ "num_attention_heads": 12,
390
+ "num_beam_groups": 1,
391
+ "num_beams": 1,
392
+ "num_channels": 3,
393
+ "num_hidden_layers": 12,
394
+ "num_return_sequences": 1,
395
+ "output_attentions": false,
396
+ "output_hidden_states": false,
397
+ "output_scores": false,
398
+ "pad_token_id": null,
399
+ "patch_size": 16,
400
+ "prefix": null,
401
+ "problem_type": null,
402
+ "pruned_heads": {},
403
+ "remove_invalid_values": false,
404
+ "repetition_penalty": 1.0,
405
+ "return_dict": true,
406
+ "return_dict_in_generate": false,
407
+ "sep_token_id": null,
408
+ "suppress_tokens": null,
409
+ "task_specific_params": null,
410
+ "temperature": 1.0,
411
+ "tf_legacy_loss": false,
412
+ "tie_encoder_decoder": false,
413
+ "tie_word_embeddings": true,
414
+ "tokenizer_class": null,
415
+ "top_k": 50,
416
+ "top_p": 1.0,
417
+ "torch_dtype": null,
418
+ "torchscript": false,
419
+ "typical_p": 1.0,
420
+ "use_bfloat16": false
421
+ }
422
+ },
423
+ "llm_config": {
424
+ "_name_or_path": "mesolitica/malaysian-tinyllama-1.1b-16k-instructions-v3",
425
+ "add_cross_attention": false,
426
+ "architectures": [
427
+ "LlamaForCausalLM"
428
+ ],
429
+ "attention_bias": false,
430
+ "attention_dropout": 0.0,
431
+ "bad_words_ids": null,
432
+ "begin_suppress_tokens": null,
433
+ "bos_token_id": 1,
434
+ "chunk_size_feed_forward": 0,
435
+ "cross_attention_hidden_size": null,
436
+ "decoder_start_token_id": null,
437
+ "diversity_penalty": 0.0,
438
+ "do_sample": false,
439
+ "early_stopping": false,
440
+ "encoder_no_repeat_ngram_size": 0,
441
+ "eos_token_id": 2,
442
+ "exponential_decay_length_penalty": null,
443
+ "finetuning_task": null,
444
+ "forced_bos_token_id": null,
445
+ "forced_eos_token_id": null,
446
+ "hidden_act": "silu",
447
+ "hidden_size": 2048,
448
+ "id2label": {
449
+ "0": "LABEL_0",
450
+ "1": "LABEL_1"
451
+ },
452
+ "initializer_range": 0.02,
453
+ "intermediate_size": 5632,
454
+ "is_decoder": false,
455
+ "is_encoder_decoder": false,
456
+ "label2id": {
457
+ "LABEL_0": 0,
458
+ "LABEL_1": 1
459
+ },
460
+ "length_penalty": 1.0,
461
+ "max_length": 20,
462
+ "max_position_embeddings": 32768,
463
+ "min_length": 0,
464
+ "model_type": "llama",
465
+ "no_repeat_ngram_size": 0,
466
+ "num_attention_heads": 32,
467
+ "num_beam_groups": 1,
468
+ "num_beams": 1,
469
+ "num_hidden_layers": 22,
470
+ "num_key_value_heads": 4,
471
+ "num_return_sequences": 1,
472
+ "output_attentions": false,
473
+ "output_hidden_states": false,
474
+ "output_scores": false,
475
+ "pad_token_id": null,
476
+ "prefix": null,
477
+ "pretraining_tp": 1,
478
+ "problem_type": null,
479
+ "pruned_heads": {},
480
+ "remove_invalid_values": false,
481
+ "repetition_penalty": 1.0,
482
+ "return_dict": true,
483
+ "return_dict_in_generate": false,
484
+ "rms_norm_eps": 1e-05,
485
+ "rope_scaling": null,
486
+ "rope_theta": 10000.0,
487
+ "sep_token_id": null,
488
+ "suppress_tokens": null,
489
+ "task_specific_params": null,
490
+ "temperature": 1.0,
491
+ "tf_legacy_loss": false,
492
+ "tie_encoder_decoder": false,
493
+ "tie_word_embeddings": false,
494
+ "tokenizer_class": null,
495
+ "top_k": 50,
496
+ "top_p": 1.0,
497
+ "torch_dtype": "bfloat16",
498
+ "torchscript": false,
499
+ "typical_p": 1.0,
500
+ "use_bfloat16": false,
501
+ "use_cache": true,
502
+ "vocab_size": 32004
503
+ },
504
+ "model_type": "mm_llms",
505
+ "torch_dtype": "bfloat16",
506
+ "transformers_version": "4.37.2",
507
+ "vision_select_layer": -2
508
+ }
generation_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "transformers_version": "4.37.2"
4
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:841442e5abb85570f303de4bf4285f3c488affaf58144eff1895a688bc2668a6
3
+ size 3236402604
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