mapo80 commited on
Commit
07fdac1
·
verified ·
1 Parent(s): 1a88b04

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ tags:
6
+ - image-quality-assessment
7
+ - document-quality
8
+ - mplug-owl2
9
+ - vision-language
10
+ - document-analysis
11
+ - sharpness
12
+ - blur-detection
13
+ - IQA
14
+ pipeline_tag: image-to-text
15
+ library_name: transformers
16
+ ---
17
+
18
+ # DeQA-Doc-Sharpness: Document Image Sharpness Assessment
19
+
20
+ **DeQA-Doc-Sharpness** is a vision-language model specialized in assessing the **sharpness and clarity** of document images. It evaluates focus quality, blur levels, and text legibility in scanned or photographed documents.
21
+
22
+ ## Model Family
23
+
24
+ This model is part of the **DeQA-Doc** family, which includes three specialized models:
25
+
26
+ | Model | Description | HuggingFace |
27
+ |-------|-------------|-------------|
28
+ | **DeQA-Doc-Overall** | Overall document quality | [mapo80/DeQA-Doc-Overall](https://huggingface.co/mapo80/DeQA-Doc-Overall) |
29
+ | **DeQA-Doc-Color** | Color quality assessment | [mapo80/DeQA-Doc-Color](https://huggingface.co/mapo80/DeQA-Doc-Color) |
30
+ | **DeQA-Doc-Sharpness** | Sharpness/clarity assessment (this model) | [mapo80/DeQA-Doc-Sharpness](https://huggingface.co/mapo80/DeQA-Doc-Sharpness) |
31
+
32
+ ## Quick Start
33
+
34
+ ```python
35
+ import torch
36
+ from transformers import AutoModelForCausalLM
37
+ from PIL import Image
38
+
39
+ # Load the model
40
+ model = AutoModelForCausalLM.from_pretrained(
41
+ "mapo80/DeQA-Doc-Sharpness",
42
+ trust_remote_code=True,
43
+ torch_dtype=torch.float16,
44
+ device_map="auto",
45
+ )
46
+
47
+ # Score an image
48
+ image = Image.open("document.jpg").convert("RGB")
49
+ score = model.score([image])
50
+ print(f"Sharpness Score: {score.item():.2f} / 5.0")
51
+ ```
52
+
53
+ ## What Does Sharpness Quality Measure?
54
+
55
+ The sharpness score evaluates:
56
+
57
+ - **Focus Quality**: How well the document is in focus
58
+ - **Motion Blur**: Absence of blur from camera/scanner movement
59
+ - **Text Clarity**: Sharpness of text edges and characters
60
+ - **Detail Preservation**: Fine details are visible and crisp
61
+ - **Resolution Quality**: Adequate resolution for the content
62
+
63
+ ## Score Interpretation
64
+
65
+ | Score Range | Quality Level | Typical Issues |
66
+ |-------------|---------------|----------------|
67
+ | 4.5 - 5.0 | **Excellent** | Perfectly sharp, crisp text |
68
+ | 3.5 - 4.5 | **Good** | Slight softness, still very readable |
69
+ | 2.5 - 3.5 | **Fair** | Noticeable blur, readable with effort |
70
+ | 1.5 - 2.5 | **Poor** | Significant blur, hard to read |
71
+ | 1.0 - 1.5 | **Bad** | Severe blur, text illegible |
72
+
73
+ ## Batch Processing
74
+
75
+ ```python
76
+ images = [
77
+ Image.open("doc1.jpg").convert("RGB"),
78
+ Image.open("doc2.jpg").convert("RGB"),
79
+ Image.open("doc3.jpg").convert("RGB"),
80
+ ]
81
+
82
+ scores = model.score(images)
83
+ for i, score in enumerate(scores):
84
+ print(f"Document {i+1} Sharpness: {score.item():.2f} / 5.0")
85
+ ```
86
+
87
+ ## Use Cases
88
+
89
+ - **OCR Preprocessing**: Filter blurry images before OCR to improve accuracy
90
+ - **Document Capture QA**: Real-time feedback for mobile document scanning
91
+ - **Archive Quality Control**: Identify documents needing re-scanning
92
+ - **Blur Detection**: Automatic detection of out-of-focus captures
93
+ - **Scanner Maintenance**: Detect scanner focus issues
94
+
95
+ ## Example: OCR Quality Gate
96
+
97
+ ```python
98
+ import torch
99
+ from transformers import AutoModelForCausalLM
100
+ from PIL import Image
101
+
102
+ model = AutoModelForCausalLM.from_pretrained(
103
+ "mapo80/DeQA-Doc-Sharpness",
104
+ trust_remote_code=True,
105
+ torch_dtype=torch.float16,
106
+ device_map="auto",
107
+ )
108
+
109
+ def check_ocr_readiness(image_path, min_sharpness=3.5):
110
+ """Check if document is sharp enough for reliable OCR."""
111
+ img = Image.open(image_path).convert("RGB")
112
+ score = model.score([img]).item()
113
+
114
+ if score >= min_sharpness:
115
+ return True, score, "Ready for OCR"
116
+ elif score >= 2.5:
117
+ return False, score, "May produce OCR errors - consider rescanning"
118
+ else:
119
+ return False, score, "Too blurry for OCR - rescan required"
120
+
121
+ ready, score, message = check_ocr_readiness("scan.jpg")
122
+ print(f"Sharpness: {score:.2f}/5.0 - {message}")
123
+
124
+ if ready:
125
+ # Proceed with OCR
126
+ pass
127
+ else:
128
+ # Request rescan
129
+ pass
130
+ ```
131
+
132
+ ## Example: Batch Quality Sorting
133
+
134
+ ```python
135
+ import torch
136
+ from transformers import AutoModelForCausalLM
137
+ from PIL import Image
138
+ from pathlib import Path
139
+
140
+ model = AutoModelForCausalLM.from_pretrained(
141
+ "mapo80/DeQA-Doc-Sharpness",
142
+ trust_remote_code=True,
143
+ torch_dtype=torch.float16,
144
+ device_map="auto",
145
+ )
146
+
147
+ def sort_by_sharpness(image_folder):
148
+ """Sort documents into quality buckets based on sharpness."""
149
+ results = {"excellent": [], "good": [], "fair": [], "poor": [], "bad": []}
150
+
151
+ for img_path in Path(image_folder).glob("*.jpg"):
152
+ img = Image.open(img_path).convert("RGB")
153
+ score = model.score([img]).item()
154
+
155
+ if score >= 4.5:
156
+ results["excellent"].append((img_path, score))
157
+ elif score >= 3.5:
158
+ results["good"].append((img_path, score))
159
+ elif score >= 2.5:
160
+ results["fair"].append((img_path, score))
161
+ elif score >= 1.5:
162
+ results["poor"].append((img_path, score))
163
+ else:
164
+ results["bad"].append((img_path, score))
165
+
166
+ return results
167
+
168
+ # Usage
169
+ quality_report = sort_by_sharpness("scanned_docs/")
170
+ print(f"Excellent: {len(quality_report['excellent'])} documents")
171
+ print(f"Need rescan: {len(quality_report['poor']) + len(quality_report['bad'])} documents")
172
+ ```
173
+
174
+ ## Multi-Dimensional Quality Assessment
175
+
176
+ Combine with other DeQA-Doc models for comprehensive assessment:
177
+
178
+ ```python
179
+ import torch
180
+ from transformers import AutoModelForCausalLM
181
+ from PIL import Image
182
+
183
+ # Load all three models
184
+ models = {
185
+ "overall": AutoModelForCausalLM.from_pretrained(
186
+ "mapo80/DeQA-Doc-Overall", trust_remote_code=True,
187
+ torch_dtype=torch.float16, device_map="auto"
188
+ ),
189
+ "color": AutoModelForCausalLM.from_pretrained(
190
+ "mapo80/DeQA-Doc-Color", trust_remote_code=True,
191
+ torch_dtype=torch.float16, device_map="auto"
192
+ ),
193
+ "sharpness": AutoModelForCausalLM.from_pretrained(
194
+ "mapo80/DeQA-Doc-Sharpness", trust_remote_code=True,
195
+ torch_dtype=torch.float16, device_map="auto"
196
+ ),
197
+ }
198
+
199
+ def full_quality_report(image_path):
200
+ img = Image.open(image_path).convert("RGB")
201
+
202
+ scores = {}
203
+ for name, model in models.items():
204
+ scores[name] = model.score([img]).item()
205
+
206
+ return scores
207
+
208
+ report = full_quality_report("document.jpg")
209
+ print(f"Overall: {report['overall']:.2f}/5.0")
210
+ print(f"Color: {report['color']:.2f}/5.0")
211
+ print(f"Sharpness: {report['sharpness']:.2f}/5.0")
212
+ ```
213
+
214
+ ## Model Architecture
215
+
216
+ - **Base Model**: mPLUG-Owl2 (LLaMA2-7B + ViT-L Vision Encoder)
217
+ - **Vision Encoder**: CLIP ViT-L/14 (1024 visual tokens via Visual Abstractor)
218
+ - **Language Model**: LLaMA2-7B
219
+ - **Training**: Full fine-tuning on document sharpness quality datasets
220
+ - **Input Resolution**: Images are resized to 448x448 (with aspect ratio preservation)
221
+
222
+ ## Technical Details
223
+
224
+ | Property | Value |
225
+ |----------|-------|
226
+ | Model Size | ~16 GB (float16) |
227
+ | Parameters | ~7.2B |
228
+ | Input | RGB images (any resolution) |
229
+ | Output | Sharpness quality score (1.0 - 5.0) |
230
+ | Inference | ~2-3 seconds per image on A100 |
231
+
232
+ ## Hardware Requirements
233
+
234
+ | Setup | VRAM Required | Recommended |
235
+ |-------|---------------|-------------|
236
+ | Full precision (fp32) | ~32 GB | A100, H100 |
237
+ | Half precision (fp16) | ~16 GB | A100, A40, RTX 4090 |
238
+ | With CPU offload | ~8 GB GPU + RAM | RTX 3090, RTX 4080 |
239
+
240
+ ## Installation
241
+
242
+ ```bash
243
+ pip install torch transformers accelerate pillow sentencepiece protobuf
244
+ ```
245
+
246
+ **Note**: Use `transformers>=4.36.0` for best compatibility.
247
+
248
+ ## Comparison with Traditional Methods
249
+
250
+ | Method | Pros | Cons |
251
+ |--------|------|------|
252
+ | **Laplacian Variance** | Fast, simple | Only measures edge intensity |
253
+ | **FFT-based** | Frequency analysis | Sensitive to image content |
254
+ | **Gradient-based** | Good for text | Requires tuning |
255
+ | **DeQA-Doc-Sharpness** | Content-aware, trained on documents | Requires GPU |
256
+
257
+ DeQA-Doc-Sharpness understands document context and can differentiate between intentionally smooth backgrounds and unintentional blur.
258
+
259
+ ## Limitations
260
+
261
+ - Optimized for document images (text, forms, letters)
262
+ - May not generalize well to natural photos
263
+ - Requires GPU with sufficient VRAM for efficient inference
264
+ - Sharpness assessment is relative to training data distribution
265
+
266
+ ## Citation
267
+
268
+ ```bibtex
269
+ @misc{deqa-doc-sharpness-2024,
270
+ title={DeQA-Doc-Sharpness: Document Image Sharpness Assessment},
271
+ author={mapo80},
272
+ year={2024},
273
+ publisher={HuggingFace},
274
+ url={https://huggingface.co/mapo80/DeQA-Doc-Sharpness}
275
+ }
276
+ ```
277
+
278
+ ## License
279
+
280
+ Apache 2.0
281
+
282
+ ## Related Models
283
+
284
+ - [DeQA-Doc-Overall](https://huggingface.co/mapo80/DeQA-Doc-Overall) - Overall quality assessment
285
+ - [DeQA-Doc-Color](https://huggingface.co/mapo80/DeQA-Doc-Color) - Color quality assessment
__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from .configuration_mplug_owl2 import MPLUGOwl2Config
2
+ from .modeling_attn_mask_utils import _prepare_4d_causal_attention_mask
3
+ from .modeling_mplug_owl2_huggingface import MPLUGOwl2LlamaForCausalLM
4
+
5
+ __all__ = ["MPLUGOwl2Config", "MPLUGOwl2LlamaForCausalLM"]
config.json ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "./",
3
+ "architectures": [
4
+ "MPLUGOwl2LlamaForCausalLM"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_mplug_owl2.MPLUGOwl2Config",
8
+ "AutoModel": "modeling_mplug_owl2_huggingface.MPLUGOwl2LlamaForCausalLM",
9
+ "AutoModelForCausalLM": "modeling_mplug_owl2_huggingface.MPLUGOwl2LlamaForCausalLM"
10
+ },
11
+ "attention_bias": false,
12
+ "attention_dropout": 0.0,
13
+ "binary_rating_loss": "fidelity",
14
+ "bos_token_id": 1,
15
+ "closeset_rating_loss": true,
16
+ "continuous_rating_loss": true,
17
+ "detach_pred_std": true,
18
+ "eos_token_id": 2,
19
+ "freeze_vision_model": false,
20
+ "hidden_act": "silu",
21
+ "hidden_size": 4096,
22
+ "image_aspect_ratio": "pad",
23
+ "image_grid_pinpoints": null,
24
+ "initializer_range": 0.02,
25
+ "intermediate_size": 11008,
26
+ "level_ids": [
27
+ 15129,
28
+ 1781,
29
+ 6534,
30
+ 6460,
31
+ 4319
32
+ ],
33
+ "level_prefix": [
34
+ 11029,
35
+ 310,
36
+ 278,
37
+ 1967,
38
+ 338
39
+ ],
40
+ "max_position_embeddings": 2048,
41
+ "model_type": "mplug_owl2",
42
+ "num_attention_heads": 32,
43
+ "num_hidden_layers": 32,
44
+ "num_key_value_heads": 32,
45
+ "pretraining_tp": 1,
46
+ "rms_norm_eps": 1e-06,
47
+ "rope_scaling": null,
48
+ "rope_theta": 10000.0,
49
+ "softkl_loss": true,
50
+ "tie_word_embeddings": false,
51
+ "torch_dtype": "bfloat16",
52
+ "transformers_version": "4.36.1",
53
+ "tune_visual_abstractor": true,
54
+ "use_cache": true,
55
+ "use_fix_std": true,
56
+ "visual_abstractor_lr": null,
57
+ "visual_config": {
58
+ "visual_abstractor": {
59
+ "_name_or_path": "",
60
+ "add_cross_attention": false,
61
+ "architectures": null,
62
+ "attention_probs_dropout_prob": 0.0,
63
+ "bad_words_ids": null,
64
+ "begin_suppress_tokens": null,
65
+ "bos_token_id": null,
66
+ "chunk_size_feed_forward": 0,
67
+ "cross_attention_hidden_size": null,
68
+ "decoder_start_token_id": null,
69
+ "diversity_penalty": 0.0,
70
+ "do_sample": false,
71
+ "early_stopping": false,
72
+ "encoder_hidden_size": 1024,
73
+ "encoder_no_repeat_ngram_size": 0,
74
+ "eos_token_id": null,
75
+ "exponential_decay_length_penalty": null,
76
+ "finetuning_task": null,
77
+ "forced_bos_token_id": null,
78
+ "forced_eos_token_id": null,
79
+ "grid_size": 32,
80
+ "hidden_size": 1024,
81
+ "id2label": {
82
+ "0": "LABEL_0",
83
+ "1": "LABEL_1"
84
+ },
85
+ "initializer_range": 0.02,
86
+ "intermediate_size": 2816,
87
+ "is_decoder": false,
88
+ "is_encoder_decoder": false,
89
+ "label2id": {
90
+ "LABEL_0": 0,
91
+ "LABEL_1": 1
92
+ },
93
+ "layer_norm_eps": 1e-06,
94
+ "length_penalty": 1.0,
95
+ "max_length": 20,
96
+ "min_length": 0,
97
+ "model_type": "mplug_owl_visual_abstract",
98
+ "no_repeat_ngram_size": 0,
99
+ "num_attention_heads": 16,
100
+ "num_beam_groups": 1,
101
+ "num_beams": 1,
102
+ "num_hidden_layers": 6,
103
+ "num_learnable_queries": 64,
104
+ "num_return_sequences": 1,
105
+ "output_attentions": false,
106
+ "output_hidden_states": false,
107
+ "output_scores": false,
108
+ "pad_token_id": null,
109
+ "prefix": null,
110
+ "problem_type": null,
111
+ "pruned_heads": {},
112
+ "remove_invalid_values": false,
113
+ "repetition_penalty": 1.0,
114
+ "return_dict": true,
115
+ "return_dict_in_generate": false,
116
+ "sep_token_id": null,
117
+ "suppress_tokens": null,
118
+ "task_specific_params": null,
119
+ "temperature": 1.0,
120
+ "tf_legacy_loss": false,
121
+ "tie_encoder_decoder": false,
122
+ "tie_word_embeddings": true,
123
+ "tokenizer_class": null,
124
+ "top_k": 50,
125
+ "top_p": 1.0,
126
+ "torch_dtype": null,
127
+ "torchscript": false,
128
+ "transformers_version": "4.28.1",
129
+ "typical_p": 1.0,
130
+ "use_bfloat16": false
131
+ },
132
+ "visual_model": {
133
+ "_name_or_path": "",
134
+ "add_cross_attention": false,
135
+ "architectures": null,
136
+ "attention_dropout": 0.0,
137
+ "bad_words_ids": null,
138
+ "begin_suppress_tokens": null,
139
+ "bos_token_id": null,
140
+ "chunk_size_feed_forward": 0,
141
+ "cross_attention_hidden_size": null,
142
+ "decoder_start_token_id": null,
143
+ "diversity_penalty": 0.0,
144
+ "do_sample": false,
145
+ "early_stopping": false,
146
+ "encoder_no_repeat_ngram_size": 0,
147
+ "eos_token_id": null,
148
+ "exponential_decay_length_penalty": null,
149
+ "finetuning_task": null,
150
+ "forced_bos_token_id": null,
151
+ "forced_eos_token_id": null,
152
+ "hidden_act": "quick_gelu",
153
+ "hidden_size": 1024,
154
+ "id2label": {
155
+ "0": "LABEL_0",
156
+ "1": "LABEL_1"
157
+ },
158
+ "image_size": 448,
159
+ "initializer_factor": 1.0,
160
+ "initializer_range": 0.02,
161
+ "intermediate_size": 4096,
162
+ "is_decoder": false,
163
+ "is_encoder_decoder": false,
164
+ "label2id": {
165
+ "LABEL_0": 0,
166
+ "LABEL_1": 1
167
+ },
168
+ "layer_norm_eps": 1e-06,
169
+ "length_penalty": 1.0,
170
+ "max_length": 20,
171
+ "min_length": 0,
172
+ "model_type": "mplug_owl_vision_model",
173
+ "no_repeat_ngram_size": 0,
174
+ "num_attention_heads": 16,
175
+ "num_beam_groups": 1,
176
+ "num_beams": 1,
177
+ "num_channels": 3,
178
+ "num_hidden_layers": 24,
179
+ "num_return_sequences": 1,
180
+ "output_attentions": false,
181
+ "output_hidden_states": false,
182
+ "output_scores": false,
183
+ "pad_token_id": null,
184
+ "patch_size": 14,
185
+ "prefix": null,
186
+ "problem_type": null,
187
+ "projection_dim": 768,
188
+ "pruned_heads": {},
189
+ "remove_invalid_values": false,
190
+ "repetition_penalty": 1.0,
191
+ "return_dict": true,
192
+ "return_dict_in_generate": false,
193
+ "sep_token_id": null,
194
+ "suppress_tokens": null,
195
+ "task_specific_params": null,
196
+ "temperature": 1.0,
197
+ "tf_legacy_loss": false,
198
+ "tie_encoder_decoder": false,
199
+ "tie_word_embeddings": true,
200
+ "tokenizer_class": null,
201
+ "top_k": 50,
202
+ "top_p": 1.0,
203
+ "torch_dtype": null,
204
+ "torchscript": false,
205
+ "transformers_version": "4.28.1",
206
+ "typical_p": 1.0,
207
+ "use_bfloat16": false,
208
+ "use_flash_attn": false
209
+ }
210
+ },
211
+ "vocab_size": 32000,
212
+ "weight_desp": 1.0,
213
+ "weight_in_level": null,
214
+ "weight_next_token": 0.01,
215
+ "weight_rank": 1.0,
216
+ "weight_softkl": 1.0
217
+ }
configuration_mplug_owl2.py ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+ import copy
6
+ import os
7
+ from typing import Union
8
+
9
+ from transformers.configuration_utils import PretrainedConfig
10
+ from transformers.models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
11
+ from transformers.utils import logging
12
+ from transformers.models.auto import CONFIG_MAPPING
13
+
14
+
15
+ class LlamaConfig(PretrainedConfig):
16
+ r"""
17
+ This is the configuration class to store the configuration of a [`LlamaModel`]. It is used to instantiate an LLaMA
18
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
19
+ defaults will yield a similar configuration to that of the LLaMA-7B.
20
+
21
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
22
+ documentation from [`PretrainedConfig`] for more information.
23
+
24
+
25
+ Args:
26
+ vocab_size (`int`, *optional*, defaults to 32000):
27
+ Vocabulary size of the LLaMA model. Defines the number of different tokens that can be represented by the
28
+ `inputs_ids` passed when calling [`LlamaModel`]
29
+ hidden_size (`int`, *optional*, defaults to 4096):
30
+ Dimension of the hidden representations.
31
+ intermediate_size (`int`, *optional*, defaults to 11008):
32
+ Dimension of the MLP representations.
33
+ num_hidden_layers (`int`, *optional*, defaults to 32):
34
+ Number of hidden layers in the Transformer decoder.
35
+ num_attention_heads (`int`, *optional*, defaults to 32):
36
+ Number of attention heads for each attention layer in the Transformer decoder.
37
+ num_key_value_heads (`int`, *optional*):
38
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
39
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
40
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
41
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
42
+ by meanpooling all the original heads within that group. For more details checkout [this
43
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
44
+ `num_attention_heads`.
45
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
46
+ The non-linear activation function (function or string) in the decoder.
47
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
48
+ The maximum sequence length that this model might ever be used with. Llama 1 supports up to 2048 tokens,
49
+ Llama 2 up to 4096, CodeLlama up to 16384.
50
+ initializer_range (`float`, *optional*, defaults to 0.02):
51
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
52
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
53
+ The epsilon used by the rms normalization layers.
54
+ use_cache (`bool`, *optional*, defaults to `True`):
55
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
56
+ relevant if `config.is_decoder=True`.
57
+ pad_token_id (`int`, *optional*):
58
+ Padding token id.
59
+ bos_token_id (`int`, *optional*, defaults to 1):
60
+ Beginning of stream token id.
61
+ eos_token_id (`int`, *optional*, defaults to 2):
62
+ End of stream token id.
63
+ pretraining_tp (`int`, *optional*, defaults to 1):
64
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
65
+ document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
66
+ necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
67
+ issue](https://github.com/pytorch/pytorch/issues/76232).
68
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
69
+ Whether to tie weight embeddings
70
+ rope_theta (`float`, *optional*, defaults to 10000.0):
71
+ The base period of the RoPE embeddings.
72
+ rope_scaling (`Dict`, *optional*):
73
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
74
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
75
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
76
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
77
+ these scaling strategies behave:
78
+ https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
79
+ experimental feature, subject to breaking API changes in future versions.
80
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
81
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
82
+
83
+
84
+ ```python
85
+ >>> from transformers import LlamaModel, LlamaConfig
86
+
87
+ >>> # Initializing a LLaMA llama-7b style configuration
88
+ >>> configuration = LlamaConfig()
89
+
90
+ >>> # Initializing a model from the llama-7b style configuration
91
+ >>> model = LlamaModel(configuration)
92
+
93
+ >>> # Accessing the model configuration
94
+ >>> configuration = model.config
95
+ ```"""
96
+ model_type = "llama"
97
+ keys_to_ignore_at_inference = ["past_key_values"]
98
+
99
+ def __init__(
100
+ self,
101
+ vocab_size=32000,
102
+ hidden_size=4096,
103
+ intermediate_size=11008,
104
+ num_hidden_layers=32,
105
+ num_attention_heads=32,
106
+ num_key_value_heads=None,
107
+ hidden_act="silu",
108
+ max_position_embeddings=2048,
109
+ initializer_range=0.02,
110
+ rms_norm_eps=1e-6,
111
+ use_cache=True,
112
+ pad_token_id=None,
113
+ bos_token_id=1,
114
+ eos_token_id=2,
115
+ pretraining_tp=1,
116
+ tie_word_embeddings=False,
117
+ rope_theta=10000.0,
118
+ rope_scaling=None,
119
+ attention_bias=False,
120
+ attention_dropout=0.0,
121
+ **kwargs,
122
+ ):
123
+ self.vocab_size = vocab_size
124
+ self.max_position_embeddings = max_position_embeddings
125
+ self.hidden_size = hidden_size
126
+ self.intermediate_size = intermediate_size
127
+ self.num_hidden_layers = num_hidden_layers
128
+ self.num_attention_heads = num_attention_heads
129
+
130
+ # for backward compatibility
131
+ if num_key_value_heads is None:
132
+ num_key_value_heads = num_attention_heads
133
+
134
+ self.num_key_value_heads = num_key_value_heads
135
+ self.hidden_act = hidden_act
136
+ self.initializer_range = initializer_range
137
+ self.rms_norm_eps = rms_norm_eps
138
+ self.pretraining_tp = pretraining_tp
139
+ self.use_cache = use_cache
140
+ self.rope_theta = rope_theta
141
+ self.rope_scaling = rope_scaling
142
+ self._rope_scaling_validation()
143
+ self.attention_bias = attention_bias
144
+ self.attention_dropout = attention_dropout
145
+
146
+ super().__init__(
147
+ pad_token_id=pad_token_id,
148
+ bos_token_id=bos_token_id,
149
+ eos_token_id=eos_token_id,
150
+ tie_word_embeddings=tie_word_embeddings,
151
+ **kwargs,
152
+ )
153
+
154
+ def _rope_scaling_validation(self):
155
+ """
156
+ Validate the `rope_scaling` configuration.
157
+ """
158
+ if self.rope_scaling is None:
159
+ return
160
+
161
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
162
+ raise ValueError(
163
+ "`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
164
+ f"got {self.rope_scaling}"
165
+ )
166
+ rope_scaling_type = self.rope_scaling.get("type", None)
167
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
168
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
169
+ raise ValueError(
170
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
171
+ )
172
+ if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
173
+ raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
174
+
175
+
176
+ class MplugOwlVisionConfig(PretrainedConfig):
177
+ r"""
178
+ This is the configuration class to store the configuration of a [`MplugOwlVisionModel`]. It is used to instantiate
179
+ a
180
+ mPLUG-Owl vision encoder according to the specified arguments, defining the model architecture. Instantiating a
181
+ configuration defaults will yield a similar configuration to that of the mPLUG-Owl
182
+ [x-plug/x_plug-llama-7b](https://huggingface.co/x-plug/x_plug-llama-7b) architecture.
183
+
184
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
185
+ documentation from [`PretrainedConfig`] for more information.
186
+
187
+ Args:
188
+ hidden_size (`int`, *optional*, defaults to 768):
189
+ Dimensionality of the encoder layers and the pooler layer.
190
+ intermediate_size (`int`, *optional*, defaults to 3072):
191
+ Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
192
+ num_hidden_layers (`int`, *optional*, defaults to 12):
193
+ Number of hidden layers in the Transformer encoder.
194
+ num_attention_heads (`int`, *optional*, defaults to 12):
195
+ Number of attention heads for each attention layer in the Transformer encoder.
196
+ image_size (`int`, *optional*, defaults to 224):
197
+ The size (resolution) of each image.
198
+ patch_size (`int`, *optional*, defaults to 32):
199
+ The size (resolution) of each patch.
200
+ hidden_act (`str` or `function`, *optional*, defaults to `"quick_gelu"`):
201
+ The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
202
+ `"relu"`, `"selu"` and `"gelu_new"` ``"quick_gelu"` are supported.
203
+ layer_norm_eps (`float`, *optional*, defaults to 1e-5):
204
+ The epsilon used by the layer normalization layers.
205
+ attention_dropout (`float`, *optional*, defaults to 0.0):
206
+ The dropout ratio for the attention probabilities.
207
+ initializer_range (`float`, *optional*, defaults to 0.02):
208
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
209
+ initializer_factor (`float`, *optional*, defaults to 1):
210
+ A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
211
+ testing).
212
+
213
+
214
+ ```"""
215
+
216
+ model_type = "mplug_owl_vision_model"
217
+
218
+ def __init__(
219
+ self,
220
+ hidden_size=1024,
221
+ intermediate_size=4096,
222
+ projection_dim=768,
223
+ num_hidden_layers=24,
224
+ num_attention_heads=16,
225
+ num_channels=3,
226
+ image_size=1024,
227
+ patch_size=14,
228
+ hidden_act="quick_gelu",
229
+ layer_norm_eps=1e-6,
230
+ attention_dropout=0.0,
231
+ initializer_range=0.02,
232
+ initializer_factor=1.0,
233
+ use_flash_attn=False,
234
+ **kwargs,
235
+ ):
236
+ super().__init__(**kwargs)
237
+ self.hidden_size = hidden_size
238
+ self.intermediate_size = intermediate_size
239
+ self.projection_dim = projection_dim
240
+ self.num_hidden_layers = num_hidden_layers
241
+ self.num_attention_heads = num_attention_heads
242
+ self.num_channels = num_channels
243
+ self.patch_size = patch_size
244
+ self.image_size = image_size
245
+ self.initializer_range = initializer_range
246
+ self.initializer_factor = initializer_factor
247
+ self.attention_dropout = attention_dropout
248
+ self.layer_norm_eps = layer_norm_eps
249
+ self.hidden_act = hidden_act
250
+ self.use_flash_attn = use_flash_attn
251
+
252
+ @classmethod
253
+ def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
254
+ config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
255
+
256
+ # get the vision config dict if we are loading from MplugOwlConfig
257
+ if config_dict.get("model_type") == "mplug-owl":
258
+ config_dict = config_dict["vision_config"]
259
+
260
+ if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
261
+ logger.warning(
262
+ f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
263
+ f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
264
+ )
265
+
266
+ return cls.from_dict(config_dict, **kwargs)
267
+
268
+
269
+ class MplugOwlVisualAbstractorConfig(PretrainedConfig):
270
+ model_type = "mplug_owl_visual_abstract"
271
+
272
+ def __init__(
273
+ self,
274
+ num_learnable_queries=64,
275
+ hidden_size=1024,
276
+ num_hidden_layers=6,
277
+ num_attention_heads=16,
278
+ intermediate_size=2816,
279
+ attention_probs_dropout_prob=0.,
280
+ initializer_range=0.02,
281
+ layer_norm_eps=1e-6,
282
+ encoder_hidden_size=1024,
283
+ grid_size=None,
284
+ **kwargs,
285
+ ):
286
+ super().__init__(**kwargs)
287
+ self.hidden_size = hidden_size
288
+ self.num_learnable_queries = num_learnable_queries
289
+ self.num_hidden_layers = num_hidden_layers
290
+ self.num_attention_heads = num_attention_heads
291
+ self.intermediate_size = intermediate_size
292
+ self.attention_probs_dropout_prob = attention_probs_dropout_prob
293
+ self.initializer_range = initializer_range
294
+ self.layer_norm_eps = layer_norm_eps
295
+ self.encoder_hidden_size = encoder_hidden_size
296
+ self.grid_size = grid_size if grid_size else 73
297
+
298
+ @classmethod
299
+ def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
300
+ config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
301
+
302
+ # get the visual_abstractor config dict if we are loading from MplugOwlConfig
303
+ if config_dict.get("model_type") == "mplug-owl":
304
+ config_dict = config_dict["abstractor_config"]
305
+
306
+ if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
307
+ logger.warning(
308
+ f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
309
+ f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
310
+ )
311
+
312
+ return cls.from_dict(config_dict, **kwargs)
313
+
314
+
315
+
316
+ DEFAULT_VISUAL_CONFIG = {
317
+ "visual_model": MplugOwlVisionConfig().to_dict(),
318
+ "visual_abstractor": MplugOwlVisualAbstractorConfig().to_dict()
319
+ }
320
+
321
+ class MPLUGOwl2Config(LlamaConfig):
322
+ model_type = "mplug_owl2"
323
+ def __init__(self, visual_config=None, **kwargs):
324
+ if visual_config is None:
325
+ self.visual_config = DEFAULT_VISUAL_CONFIG
326
+ else:
327
+ self.visual_config = visual_config
328
+
329
+ super().__init__(
330
+ **kwargs,
331
+ )
332
+
333
+ if __name__ == "__main__":
334
+ print(MplugOwlVisionConfig().to_dict())
modeling_attn_mask_utils.py ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2023 The HuggingFace Team. All rights reserved.
2
+ #
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
+ from typing import List, Optional, Tuple, Union
15
+
16
+ import torch
17
+
18
+
19
+ class AttentionMaskConverter:
20
+ """
21
+ A utility attention mask class that allows one to:
22
+ - Create a causal 4d mask
23
+ - Create a causal 4d mask with slided window
24
+ - Convert a 2d attention mask (batch_size, query_length) to a 4d attention mask (batch_size, 1, query_length,
25
+ key_value_length) that can be multiplied with attention scores
26
+
27
+ Parameters:
28
+ is_causal (`bool`):
29
+ Whether the attention mask should be a uni-directional (causal) or bi-directional mask.
30
+
31
+ sliding_window (`int`, *optional*):
32
+ Optionally, the sliding window masks can be created if `sliding_window` is defined to a positive integer.
33
+ """
34
+
35
+ def __init__(self, is_causal: bool, sliding_window: Optional[int] = None):
36
+ self.is_causal = is_causal
37
+ self.sliding_window = sliding_window
38
+
39
+ if self.sliding_window is not None and self.sliding_window <= 0:
40
+ raise ValueError(
41
+ f"Make sure that when passing `sliding_window` that its value is a strictly positive integer, not `{self.sliding_window}`"
42
+ )
43
+
44
+ def to_causal_4d(
45
+ self,
46
+ batch_size: int,
47
+ query_length: int,
48
+ key_value_length: int,
49
+ dtype: torch.dtype = torch.float32,
50
+ device: Union[torch.device, "str"] = "cpu",
51
+ ) -> torch.Tensor:
52
+ """
53
+ Creates a causal 4D mask of (bsz, head_dim=1, query_length, key_value_length) shape and adds large negative
54
+ bias to upper right hand triangular matrix (causal mask).
55
+ """
56
+ if not self.is_causal:
57
+ raise ValueError(f"Please use `to_causal_4d` only if {self.__class__} has `is_causal` set to True.")
58
+
59
+ # If shape is not cached, create a new causal mask and cache it
60
+ input_shape = (batch_size, query_length)
61
+ past_key_values_length = key_value_length - query_length
62
+
63
+ # create causal mask
64
+ # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
65
+ causal_4d_mask = None
66
+ if input_shape[-1] > 1 or self.sliding_window is not None:
67
+ causal_4d_mask = self._make_causal_mask(
68
+ input_shape,
69
+ dtype,
70
+ device=device,
71
+ past_key_values_length=past_key_values_length,
72
+ sliding_window=self.sliding_window,
73
+ )
74
+
75
+ return causal_4d_mask
76
+
77
+ def to_4d(
78
+ self,
79
+ attention_mask_2d: torch.Tensor,
80
+ query_length: int,
81
+ key_value_length: Optional[int] = None,
82
+ dtype: torch.dtype = torch.float32,
83
+ ) -> torch.Tensor:
84
+ """
85
+ Converts 2D attention mask to 4D attention mask by expanding mask to (bsz, head_dim=1, query_length,
86
+ key_value_length) shape and by adding a large negative bias to not-attended positions. If attention_mask is
87
+ causal, a causal mask will be added.
88
+ """
89
+ input_shape = (attention_mask_2d.shape[0], query_length)
90
+
91
+ # create causal mask
92
+ # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
93
+ causal_4d_mask = None
94
+ if (input_shape[-1] > 1 or self.sliding_window is not None) and self.is_causal:
95
+ if key_value_length is None:
96
+ raise ValueError(
97
+ "This attention mask converter is causal. Make sure to pass `key_value_length` to correctly create a causal mask."
98
+ )
99
+
100
+ past_key_values_length = key_value_length - query_length
101
+ causal_4d_mask = self._make_causal_mask(
102
+ input_shape,
103
+ dtype,
104
+ device=attention_mask_2d.device,
105
+ past_key_values_length=past_key_values_length,
106
+ sliding_window=self.sliding_window,
107
+ )
108
+ elif self.sliding_window is not None:
109
+ raise NotImplementedError("Sliding window is currently only implemented for causal masking")
110
+
111
+ # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
112
+ expanded_attn_mask = self._expand_mask(attention_mask_2d, dtype, tgt_len=input_shape[-1]).to(
113
+ attention_mask_2d.device
114
+ )
115
+ expanded_4d_mask = expanded_attn_mask if causal_4d_mask is None else expanded_attn_mask + causal_4d_mask
116
+
117
+ return expanded_4d_mask
118
+
119
+ @staticmethod
120
+ def _make_causal_mask(
121
+ input_ids_shape: torch.Size,
122
+ dtype: torch.dtype,
123
+ device: torch.device,
124
+ past_key_values_length: int = 0,
125
+ sliding_window: Optional[int] = None,
126
+ ):
127
+ """
128
+ Make causal mask used for bi-directional self-attention.
129
+ """
130
+ bsz, tgt_len = input_ids_shape
131
+ mask = torch.full((tgt_len, tgt_len), torch.finfo(dtype).min, device=device)
132
+ mask_cond = torch.arange(mask.size(-1), device=device)
133
+ mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)
134
+
135
+ mask = mask.to(dtype)
136
+
137
+ if past_key_values_length > 0:
138
+ mask = torch.cat([torch.zeros(tgt_len, past_key_values_length, dtype=dtype, device=device), mask], dim=-1)
139
+
140
+ # add lower triangular sliding window mask if necessary
141
+ if sliding_window is not None:
142
+ diagonal = past_key_values_length - sliding_window + 1
143
+
144
+ context_mask = 1 - torch.triu(torch.ones_like(mask, dtype=torch.int), diagonal=diagonal)
145
+ mask.masked_fill_(context_mask.bool(), torch.finfo(dtype).min)
146
+
147
+ return mask[None, None, :, :].expand(bsz, 1, tgt_len, tgt_len + past_key_values_length)
148
+
149
+ @staticmethod
150
+ def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
151
+ """
152
+ Expands attention_mask from `[bsz, seq_len]` to `[bsz, 1, tgt_seq_len, src_seq_len]`.
153
+ """
154
+ bsz, src_len = mask.size()
155
+ tgt_len = tgt_len if tgt_len is not None else src_len
156
+
157
+ expanded_mask = mask[:, None, None, :].expand(bsz, 1, tgt_len, src_len).to(dtype)
158
+
159
+ inverted_mask = 1.0 - expanded_mask
160
+
161
+ return inverted_mask.masked_fill(inverted_mask.to(torch.bool), torch.finfo(dtype).min)
162
+
163
+
164
+ def _prepare_4d_causal_attention_mask(
165
+ attention_mask: Optional[torch.Tensor],
166
+ input_shape: Union[torch.Size, Tuple, List],
167
+ inputs_embeds: torch.Tensor,
168
+ past_key_values_length: int,
169
+ sliding_window: Optional[int] = None,
170
+ ):
171
+ """
172
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
173
+ `(batch_size, key_value_length)`
174
+
175
+ Args:
176
+ attention_mask (`torch.Tensor` or `None`):
177
+ A 2D attention mask of shape `(batch_size, key_value_length)`
178
+ input_shape (`tuple(int)` or `list(int)` or `torch.Size`):
179
+ The input shape should be a tuple that defines `(batch_size, query_length)`.
180
+ inputs_embeds (`torch.Tensor`):
181
+ The embedded inputs as a torch Tensor.
182
+ past_key_values_length (`int`):
183
+ The length of the key value cache.
184
+ sliding_window (`int`, *optional*):
185
+ If the model uses windowed attention, a sliding window should be passed.
186
+ """
187
+ attn_mask_converter = AttentionMaskConverter(is_causal=True, sliding_window=sliding_window)
188
+
189
+ key_value_length = input_shape[-1] + past_key_values_length
190
+
191
+ # 4d mask is passed through the layers
192
+ if attention_mask is not None:
193
+ attention_mask = attn_mask_converter.to_4d(
194
+ attention_mask, input_shape[-1], key_value_length, dtype=inputs_embeds.dtype
195
+ )
196
+ else:
197
+ attention_mask = attn_mask_converter.to_causal_4d(
198
+ input_shape[0], input_shape[-1], key_value_length, dtype=inputs_embeds.dtype, device=inputs_embeds.device
199
+ )
200
+
201
+ return attention_mask
202
+
203
+
204
+ def _prepare_4d_attention_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
205
+ """
206
+ Creates a non-causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
207
+ `(batch_size, key_value_length)`
208
+
209
+ Args:
210
+ mask (`torch.Tensor` or `None`):
211
+ A 2D attention mask of shape `(batch_size, key_value_length)`
212
+ dtype (`torch.dtype`):
213
+ The torch dtype the created mask shall have.
214
+ tgt_len (`int`):
215
+ The target length or query length the created mask shall have.
216
+ """
217
+ return AttentionMaskConverter._expand_mask(mask=mask, dtype=dtype, tgt_len=tgt_len)
218
+
219
+
220
+ def _create_4d_causal_attention_mask(
221
+ input_shape: Union[torch.Size, Tuple, List],
222
+ dtype: torch.dtype,
223
+ device: torch.device,
224
+ past_key_values_length: int = 0,
225
+ sliding_window: Optional[int] = None,
226
+ ):
227
+ """
228
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)`
229
+
230
+ Args:
231
+ input_shape (`tuple(int)` or `list(int)` or `torch.Size`):
232
+ The input shape should be a tuple that defines `(batch_size, query_length)`.
233
+ dtype (`torch.dtype`):
234
+ The torch dtype the created mask shall have.
235
+ device (`int`):
236
+ The torch device the created mask shall have.
237
+ sliding_window (`int`, *optional*):
238
+ If the model uses windowed attention, a sliding window should be passed.
239
+ """
240
+ attn_mask_converter = AttentionMaskConverter(is_causal=True, sliding_window=sliding_window)
241
+
242
+ key_value_length = past_key_values_length + input_shape[-1]
243
+ attention_mask = attn_mask_converter.to_causal_4d(
244
+ input_shape[0], input_shape[-1], key_value_length, dtype=dtype, device=device
245
+ )
246
+
247
+ return attention_mask
248
+
249
+ def _prepare_4d_causal_attention_mask_for_sdpa(
250
+ attention_mask: Optional[torch.Tensor],
251
+ input_shape: Union[torch.Size, Tuple, List],
252
+ inputs_embeds: torch.Tensor,
253
+ past_key_values_length: int,
254
+ sliding_window: Optional[int] = None,
255
+ ):
256
+ """
257
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
258
+ `(batch_size, key_value_length)` for SDPA (Scaled Dot Product Attention).
259
+
260
+ Args:
261
+ attention_mask (`torch.Tensor` or `None`):
262
+ A 2D attention mask of shape `(batch_size, key_value_length)`
263
+ input_shape (`tuple(int)` or `list(int)` or `torch.Size`):
264
+ The input shape should be a tuple that defines `(batch_size, query_length)`.
265
+ inputs_embeds (`torch.Tensor`):
266
+ The embedded inputs as a torch Tensor.
267
+ past_key_values_length (`int`):
268
+ The length of the key value cache.
269
+ sliding_window (`int`, *optional*):
270
+ If the model uses windowed attention, a sliding window should be passed.
271
+ """
272
+ # For SDPA, we use the same implementation as the regular causal attention mask
273
+ return _prepare_4d_causal_attention_mask(
274
+ attention_mask, input_shape, inputs_embeds, past_key_values_length, sliding_window
275
+ )
modeling_llama2.py ADDED
@@ -0,0 +1,861 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import warnings
3
+ from functools import partial
4
+ from typing import List, Optional, Tuple, Union
5
+
6
+ import torch
7
+ import torch.nn.functional as F
8
+ import torch.utils.checkpoint
9
+ from torch import nn
10
+ from torch.nn import CrossEntropyLoss
11
+ from transformers.cache_utils import Cache
12
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
13
+ from transformers.utils import logging
14
+ from transformers.models.llama.modeling_llama import (
15
+ LlamaRotaryEmbedding,
16
+ LlamaLinearScalingRotaryEmbedding,
17
+ LlamaDynamicNTKScalingRotaryEmbedding,
18
+ apply_rotary_pos_emb,
19
+ repeat_kv,
20
+ LlamaMLP,
21
+ LlamaRMSNorm,
22
+ is_flash_attn_greater_or_equal_2_10,
23
+ )
24
+
25
+ logger = logging.get_logger(__name__)
26
+
27
+ import copy
28
+ import os
29
+ import sys
30
+
31
+ dir_path = os.path.dirname(os.path.realpath(__file__))
32
+ sys.path.insert(0, dir_path)
33
+
34
+ import transformers
35
+ from transformers.models.llama.modeling_llama import *
36
+
37
+ from transformers.configuration_utils import PretrainedConfig
38
+ from transformers.utils import logging
39
+
40
+ from .modeling_attn_mask_utils import _prepare_4d_causal_attention_mask, _prepare_4d_causal_attention_mask_for_sdpa
41
+ from .configuration_mplug_owl2 import LlamaConfig
42
+
43
+ def _get_unpad_data(attention_mask):
44
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
45
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
46
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
47
+ cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0))
48
+ return (
49
+ indices,
50
+ cu_seqlens,
51
+ max_seqlen_in_batch,
52
+ )
53
+
54
+
55
+ class MultiwayNetwork(nn.Module):
56
+
57
+ def __init__(self, module_provider, num_multiway=2):
58
+ super(MultiwayNetwork, self).__init__()
59
+
60
+ self.multiway = torch.nn.ModuleList([module_provider() for _ in range(num_multiway)])
61
+
62
+ def forward(self, hidden_states, multiway_indices):
63
+
64
+ if len(self.multiway) == 1:
65
+ return self.multiway[0](hidden_states)
66
+
67
+ output_hidden_states = torch.empty_like(hidden_states)
68
+
69
+ for idx, subway in enumerate(self.multiway):
70
+ local_indices = multiway_indices.eq(idx).nonzero(as_tuple=True)
71
+ hidden = hidden_states[local_indices].unsqueeze(1).contiguous()
72
+ if hidden.numel():
73
+ output = subway(hidden)
74
+ if isinstance(output, tuple):
75
+ output = output[0]
76
+ output = output.squeeze(1)
77
+ output_hidden_states[local_indices] = output
78
+
79
+ return output_hidden_states.contiguous()
80
+
81
+
82
+ class LlamaAttention(nn.Module):
83
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
84
+
85
+ def __init__(self, config: LlamaConfig, layer_idx: Optional[int] = None):
86
+ super().__init__()
87
+ self.config = config
88
+ self.layer_idx = layer_idx
89
+ if layer_idx is None:
90
+ logger.warning_once(
91
+ f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
92
+ "to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
93
+ "when creating this class."
94
+ )
95
+
96
+ self.attention_dropout = config.attention_dropout
97
+ self.hidden_size = config.hidden_size
98
+ self.num_heads = config.num_attention_heads
99
+ self.head_dim = self.hidden_size // self.num_heads
100
+ self.num_key_value_heads = config.num_key_value_heads
101
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
102
+ self.max_position_embeddings = config.max_position_embeddings
103
+ self.rope_theta = config.rope_theta
104
+ self.is_causal = True
105
+
106
+ if (self.head_dim * self.num_heads) != self.hidden_size:
107
+ raise ValueError(
108
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
109
+ f" and `num_heads`: {self.num_heads})."
110
+ )
111
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=config.attention_bias)
112
+ self.k_proj = MultiwayNetwork(module_provider=partial(
113
+ nn.Linear, in_features=self.hidden_size, out_features=self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
114
+ )
115
+ self.v_proj = MultiwayNetwork(module_provider=partial(
116
+ nn.Linear, in_features=self.hidden_size, out_features=self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
117
+ )
118
+ self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=config.attention_bias)
119
+ self._init_rope()
120
+
121
+ def _init_rope(self):
122
+ if self.config.rope_scaling is None:
123
+ self.rotary_emb = LlamaRotaryEmbedding(
124
+ self.head_dim,
125
+ max_position_embeddings=self.max_position_embeddings,
126
+ base=self.rope_theta,
127
+ )
128
+ else:
129
+ scaling_type = self.config.rope_scaling["type"]
130
+ scaling_factor = self.config.rope_scaling["factor"]
131
+ if scaling_type == "linear":
132
+ self.rotary_emb = LlamaLinearScalingRotaryEmbedding(
133
+ self.head_dim,
134
+ max_position_embeddings=self.max_position_embeddings,
135
+ scaling_factor=scaling_factor,
136
+ base=self.rope_theta,
137
+ )
138
+ elif scaling_type == "dynamic":
139
+ self.rotary_emb = LlamaDynamicNTKScalingRotaryEmbedding(
140
+ self.head_dim,
141
+ max_position_embeddings=self.max_position_embeddings,
142
+ scaling_factor=scaling_factor,
143
+ base=self.rope_theta,
144
+ )
145
+ else:
146
+ raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
147
+
148
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
149
+ return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
150
+
151
+ def forward(
152
+ self,
153
+ hidden_states: torch.Tensor,
154
+ modality_indicators: torch.Tensor,
155
+ attention_mask: Optional[torch.Tensor] = None,
156
+ position_ids: Optional[torch.LongTensor] = None,
157
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
158
+ output_attentions: bool = False,
159
+ use_cache: bool = False,
160
+ padding_mask: Optional[torch.LongTensor] = None,
161
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
162
+ bsz, q_len, _ = hidden_states.size()
163
+
164
+ query_states = self.q_proj(hidden_states, )
165
+ key_states = self.k_proj(hidden_states, modality_indicators)
166
+ value_states = self.v_proj(hidden_states, modality_indicators)
167
+
168
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
169
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
170
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
171
+
172
+ kv_seq_len = key_states.shape[-2]
173
+ if past_key_value is not None:
174
+ kv_seq_len += past_key_value[0].shape[-2]
175
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
176
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
177
+
178
+ if past_key_value is not None:
179
+ # reuse k, v, self_attention
180
+ key_states = torch.cat([past_key_value[0], key_states], dim=2)
181
+ value_states = torch.cat([past_key_value[1], value_states], dim=2)
182
+
183
+ past_key_value = (key_states, value_states) if use_cache else None
184
+
185
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
186
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
187
+
188
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
189
+
190
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
191
+ raise ValueError(
192
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
193
+ f" {attn_weights.size()}"
194
+ )
195
+
196
+ if attention_mask is not None:
197
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
198
+ raise ValueError(
199
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
200
+ )
201
+ attn_weights = attn_weights + attention_mask
202
+
203
+ # upcast attention to fp32
204
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
205
+ attn_output = torch.matmul(attn_weights, value_states)
206
+
207
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
208
+ raise ValueError(
209
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
210
+ f" {attn_output.size()}"
211
+ )
212
+
213
+ attn_output = attn_output.transpose(1, 2).contiguous()
214
+
215
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
216
+
217
+ attn_output = self.o_proj(attn_output)
218
+
219
+ if not output_attentions:
220
+ attn_weights = None
221
+
222
+ return attn_output, attn_weights, past_key_value
223
+
224
+
225
+ class LlamaFlashAttention2(LlamaAttention):
226
+ """
227
+ Llama flash attention module. This module inherits from `LlamaAttention` as the weights of the module stays
228
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
229
+ flash attention and deal with padding tokens in case the input contains any of them.
230
+ """
231
+
232
+ def __init__(self, *args, **kwargs):
233
+ super().__init__(*args, **kwargs)
234
+
235
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
236
+ # flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
237
+ # Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
238
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
239
+
240
+ def forward(
241
+ self,
242
+ hidden_states: torch.Tensor,
243
+ modality_indicators: torch.Tensor,
244
+ attention_mask: Optional[torch.LongTensor] = None,
245
+ position_ids: Optional[torch.LongTensor] = None,
246
+ past_key_value: Optional[Cache] = None,
247
+ output_attentions: bool = False,
248
+ use_cache: bool = False,
249
+ **kwargs,
250
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
251
+ # LlamaFlashAttention2 attention does not support output_attentions
252
+ if "padding_mask" in kwargs:
253
+ warnings.warn(
254
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
255
+ )
256
+
257
+ # overwrite attention_mask with padding_mask
258
+ attention_mask = kwargs.pop("padding_mask")
259
+
260
+ output_attentions = False
261
+
262
+ bsz, q_len, _ = hidden_states.size()
263
+
264
+ query_states = self.q_proj(hidden_states)
265
+ key_states = self.k_proj(hidden_states, modality_indicators)
266
+ value_states = self.v_proj(hidden_states, modality_indicators)
267
+
268
+ # Flash attention requires the input to have the shape
269
+ # batch_size x seq_length x head_dim x hidden_dim
270
+ # therefore we just need to keep the original shape
271
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
272
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
273
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
274
+
275
+ kv_seq_len = key_states.shape[-2]
276
+ if past_key_value is not None:
277
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
278
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
279
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
280
+
281
+ if past_key_value is not None:
282
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
283
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
284
+
285
+ # TODO: These transpose are quite inefficient but Flash Attention requires the layout [batch_size, sequence_length, num_heads, head_dim]. We would need to refactor the KV cache
286
+ # to be able to avoid many of these transpose/reshape/view.
287
+ query_states = query_states.transpose(1, 2)
288
+ key_states = key_states.transpose(1, 2)
289
+ value_states = value_states.transpose(1, 2)
290
+
291
+ dropout_rate = self.attention_dropout if self.training else 0.0
292
+
293
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
294
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
295
+ # cast them back in the correct dtype just to be sure everything works as expected.
296
+ # This might slowdown training & inference so it is recommended to not cast the LayerNorms
297
+ # in fp32. (LlamaRMSNorm handles it correctly)
298
+
299
+ input_dtype = query_states.dtype
300
+ if input_dtype == torch.float32:
301
+ if torch.is_autocast_enabled():
302
+ target_dtype = torch.get_autocast_gpu_dtype()
303
+ # Handle the case where the model is quantized
304
+ elif hasattr(self.config, "_pre_quantization_dtype"):
305
+ target_dtype = self.config._pre_quantization_dtype
306
+ else:
307
+ target_dtype = self.q_proj.weight.dtype
308
+
309
+ logger.warning_once(
310
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
311
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
312
+ f" {target_dtype}."
313
+ )
314
+
315
+ query_states = query_states.to(target_dtype)
316
+ key_states = key_states.to(target_dtype)
317
+ value_states = value_states.to(target_dtype)
318
+
319
+ attn_output = self._flash_attention_forward(
320
+ query_states, key_states, value_states, attention_mask, q_len, dropout=dropout_rate
321
+ )
322
+
323
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
324
+ attn_output = self.o_proj(attn_output)
325
+
326
+ if not output_attentions:
327
+ attn_weights = None
328
+
329
+ return attn_output, attn_weights, past_key_value
330
+
331
+ def _flash_attention_forward(
332
+ self, query_states, key_states, value_states, attention_mask, query_length, dropout=0.0, softmax_scale=None
333
+ ):
334
+ """
335
+ Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
336
+ first unpad the input, then computes the attention scores and pad the final attention scores.
337
+
338
+ Args:
339
+ query_states (`torch.Tensor`):
340
+ Input query states to be passed to Flash Attention API
341
+ key_states (`torch.Tensor`):
342
+ Input key states to be passed to Flash Attention API
343
+ value_states (`torch.Tensor`):
344
+ Input value states to be passed to Flash Attention API
345
+ attention_mask (`torch.Tensor`):
346
+ The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
347
+ position of padding tokens and 1 for the position of non-padding tokens.
348
+ dropout (`int`, *optional*):
349
+ Attention dropout
350
+ softmax_scale (`float`, *optional*):
351
+ The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
352
+ """
353
+ if not self._flash_attn_uses_top_left_mask:
354
+ causal = self.is_causal
355
+ else:
356
+ # TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in LlamaFlashAttention2 __init__.
357
+ causal = self.is_causal and query_length != 1
358
+
359
+ # Contains at least one padding token in the sequence
360
+ if attention_mask is not None:
361
+ batch_size = query_states.shape[0]
362
+ query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
363
+ query_states, key_states, value_states, attention_mask, query_length
364
+ )
365
+
366
+ cu_seqlens_q, cu_seqlens_k = cu_seq_lens
367
+ max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
368
+
369
+ attn_output_unpad = flash_attn_varlen_func(
370
+ query_states,
371
+ key_states,
372
+ value_states,
373
+ cu_seqlens_q=cu_seqlens_q,
374
+ cu_seqlens_k=cu_seqlens_k,
375
+ max_seqlen_q=max_seqlen_in_batch_q,
376
+ max_seqlen_k=max_seqlen_in_batch_k,
377
+ dropout_p=dropout,
378
+ softmax_scale=softmax_scale,
379
+ causal=causal,
380
+ )
381
+
382
+ attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
383
+ else:
384
+ attn_output = flash_attn_func(
385
+ query_states, key_states, value_states, dropout, softmax_scale=softmax_scale, causal=causal
386
+ )
387
+
388
+ return attn_output
389
+
390
+ def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
391
+ indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
392
+ batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
393
+
394
+ key_layer = index_first_axis(
395
+ key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
396
+ )
397
+ value_layer = index_first_axis(
398
+ value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
399
+ )
400
+ if query_length == kv_seq_len:
401
+ query_layer = index_first_axis(
402
+ query_layer.reshape(batch_size * kv_seq_len, self.num_heads, head_dim), indices_k
403
+ )
404
+ cu_seqlens_q = cu_seqlens_k
405
+ max_seqlen_in_batch_q = max_seqlen_in_batch_k
406
+ indices_q = indices_k
407
+ elif query_length == 1:
408
+ max_seqlen_in_batch_q = 1
409
+ cu_seqlens_q = torch.arange(
410
+ batch_size + 1, dtype=torch.int32, device=query_layer.device
411
+ ) # There is a memcpy here, that is very bad.
412
+ indices_q = cu_seqlens_q[:-1]
413
+ query_layer = query_layer.squeeze(1)
414
+ else:
415
+ # The -q_len: slice assumes left padding.
416
+ attention_mask = attention_mask[:, -query_length:]
417
+ query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
418
+
419
+ return (
420
+ query_layer,
421
+ key_layer,
422
+ value_layer,
423
+ indices_q,
424
+ (cu_seqlens_q, cu_seqlens_k),
425
+ (max_seqlen_in_batch_q, max_seqlen_in_batch_k),
426
+ )
427
+
428
+
429
+ class LlamaSdpaAttention(LlamaAttention):
430
+ """
431
+ Llama attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
432
+ `LlamaAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
433
+ SDPA API.
434
+ """
435
+
436
+ # Adapted from LlamaAttention.forward
437
+ def forward(
438
+ self,
439
+ hidden_states: torch.Tensor,
440
+ modality_indicators: torch.Tensor,
441
+ attention_mask: Optional[torch.Tensor] = None,
442
+ position_ids: Optional[torch.LongTensor] = None,
443
+ past_key_value: Optional[Cache] = None,
444
+ output_attentions: bool = False,
445
+ use_cache: bool = False,
446
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
447
+ if output_attentions:
448
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
449
+ logger.warning_once(
450
+ "LlamaModel is using LlamaSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
451
+ 'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
452
+ )
453
+ return super().forward(
454
+ hidden_states=hidden_states,
455
+ modality_indicators=modality_indicators,
456
+ attention_mask=attention_mask,
457
+ position_ids=position_ids,
458
+ past_key_value=past_key_value,
459
+ output_attentions=output_attentions,
460
+ use_cache=use_cache,
461
+ )
462
+
463
+ bsz, q_len, _ = hidden_states.size()
464
+
465
+ query_states = self.q_proj(hidden_states)
466
+ key_states = self.k_proj(hidden_states, modality_indicators)
467
+ value_states = self.v_proj(hidden_states, modality_indicators)
468
+
469
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
470
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
471
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
472
+
473
+ kv_seq_len = key_states.shape[-2]
474
+ if past_key_value is not None:
475
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
476
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
477
+
478
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
479
+
480
+ if past_key_value is not None:
481
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
482
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
483
+
484
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
485
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
486
+
487
+ if attention_mask is not None:
488
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
489
+ raise ValueError(
490
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
491
+ )
492
+
493
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
494
+ # Reference: https://github.com/pytorch/pytorch/issues/112577.
495
+ if query_states.device.type == "cuda" and attention_mask is not None:
496
+ query_states = query_states.contiguous()
497
+ key_states = key_states.contiguous()
498
+ value_states = value_states.contiguous()
499
+
500
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
501
+ query_states,
502
+ key_states,
503
+ value_states,
504
+ attn_mask=attention_mask,
505
+ dropout_p=self.attention_dropout if self.training else 0.0,
506
+ # The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
507
+ is_causal=self.is_causal and attention_mask is None and q_len > 1,
508
+ )
509
+
510
+ attn_output = attn_output.transpose(1, 2).contiguous()
511
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
512
+
513
+ attn_output = self.o_proj(attn_output)
514
+
515
+ return attn_output, None, past_key_value
516
+
517
+
518
+
519
+ LLAMA_ATTENTION_CLASSES = {
520
+ "eager": LlamaAttention,
521
+ "flash_attention_2": LlamaFlashAttention2,
522
+ "sdpa": LlamaSdpaAttention,
523
+ }
524
+
525
+ class LlamaDecoderLayer(nn.Module):
526
+ def __init__(self, config: LlamaConfig, layer_idx):
527
+ super().__init__()
528
+ self.hidden_size = config.hidden_size
529
+ self.self_attn = LlamaAttention(config=config)
530
+ # Get attention implementation with fallback to 'eager'
531
+ attn_implementation = getattr(config, '_attn_implementation', 'eager')
532
+ if attn_implementation in LLAMA_ATTENTION_CLASSES:
533
+ self.self_attn = LLAMA_ATTENTION_CLASSES[attn_implementation](config=config, layer_idx=layer_idx)
534
+ else:
535
+ # Fallback to eager implementation
536
+ self.self_attn = LLAMA_ATTENTION_CLASSES['eager'](config=config, layer_idx=layer_idx)
537
+ self.mlp = LlamaMLP(config)
538
+ self.input_layernorm = MultiwayNetwork(module_provider=partial(
539
+ LlamaRMSNorm, hidden_size=config.hidden_size, eps=config.rms_norm_eps
540
+ ))
541
+ self.post_attention_layernorm = MultiwayNetwork(module_provider=partial(
542
+ LlamaRMSNorm, hidden_size=config.hidden_size, eps=config.rms_norm_eps
543
+ ))
544
+
545
+ def forward(
546
+ self,
547
+ hidden_states: torch.Tensor,
548
+ modality_indicators: torch.Tensor = None,
549
+ attention_mask: Optional[torch.Tensor] = None,
550
+ position_ids: Optional[torch.LongTensor] = None,
551
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
552
+ output_attentions: Optional[bool] = False,
553
+ use_cache: Optional[bool] = False,
554
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
555
+ """
556
+ Args:
557
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
558
+ attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
559
+ `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
560
+ output_attentions (`bool`, *optional*):
561
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
562
+ returned tensors for more detail.
563
+ use_cache (`bool`, *optional*):
564
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
565
+ (see `past_key_values`).
566
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
567
+ """
568
+
569
+ residual = hidden_states
570
+
571
+ hidden_states = self.input_layernorm(hidden_states, modality_indicators)
572
+
573
+ # Self Attention
574
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
575
+ hidden_states=hidden_states,
576
+ modality_indicators=modality_indicators,
577
+ attention_mask=attention_mask,
578
+ position_ids=position_ids,
579
+ past_key_value=past_key_value,
580
+ output_attentions=output_attentions,
581
+ use_cache=use_cache,
582
+ )
583
+ hidden_states = residual + hidden_states
584
+
585
+ # Fully Connected
586
+ residual = hidden_states
587
+ hidden_states = self.post_attention_layernorm(hidden_states, modality_indicators)
588
+ hidden_states = self.mlp(hidden_states)
589
+ hidden_states = residual + hidden_states
590
+
591
+ outputs = (hidden_states,)
592
+
593
+ if output_attentions:
594
+ outputs += (self_attn_weights,)
595
+
596
+ if use_cache:
597
+ outputs += (present_key_value,)
598
+
599
+ return outputs
600
+
601
+
602
+ def model_forward(
603
+ self,
604
+ input_ids: torch.LongTensor = None,
605
+ modality_indicators: torch.Tensor = None,
606
+ attention_mask: Optional[torch.Tensor] = None,
607
+ position_ids: Optional[torch.LongTensor] = None,
608
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
609
+ inputs_embeds: Optional[torch.FloatTensor] = None,
610
+ use_cache: Optional[bool] = None,
611
+ output_attentions: Optional[bool] = None,
612
+ output_hidden_states: Optional[bool] = None,
613
+ return_dict: Optional[bool] = None,
614
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
615
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
616
+ output_hidden_states = (
617
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
618
+ )
619
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
620
+
621
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
622
+
623
+ # Set attention implementation attributes if not already set
624
+ if not hasattr(self, '_use_flash_attention_2'):
625
+ self._use_flash_attention_2 = getattr(self.config, '_attn_implementation', 'eager') == 'flash_attention_2'
626
+ if not hasattr(self, '_use_sdpa'):
627
+ self._use_sdpa = getattr(self.config, '_attn_implementation', 'eager') == 'sdpa'
628
+
629
+ # retrieve input_ids and inputs_embeds
630
+ if input_ids is not None and inputs_embeds is not None:
631
+ raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time")
632
+ elif input_ids is not None:
633
+ batch_size, seq_length = input_ids.shape
634
+ elif inputs_embeds is not None:
635
+ batch_size, seq_length, _ = inputs_embeds.shape
636
+ else:
637
+ raise ValueError("You have to specify either decoder_input_ids or decoder_inputs_embeds")
638
+
639
+ seq_length_with_past = seq_length
640
+ past_key_values_length = 0
641
+
642
+ if past_key_values is not None:
643
+ past_key_values_length = past_key_values[0][0].shape[2]
644
+ seq_length_with_past = seq_length_with_past + past_key_values_length
645
+
646
+ if position_ids is None:
647
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
648
+ position_ids = torch.arange(
649
+ past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
650
+ )
651
+ position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
652
+ else:
653
+ position_ids = position_ids.view(-1, seq_length).long()
654
+
655
+ if inputs_embeds is None:
656
+ inputs_embeds = self.embed_tokens(input_ids)
657
+ # embed positions
658
+ if attention_mask is None:
659
+ attention_mask = torch.ones(
660
+ (batch_size, seq_length_with_past), dtype=torch.bool, device=inputs_embeds.device
661
+ )
662
+
663
+ if self._use_flash_attention_2:
664
+ # 2d mask is passed through the layers
665
+ attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
666
+ elif self._use_sdpa and not output_attentions:
667
+ # output_attentions=True can not be supported when using SDPA, and we fall back on
668
+ # the manual implementation that requires a 4D causal mask in all cases.
669
+ attention_mask = _prepare_4d_causal_attention_mask_for_sdpa(
670
+ attention_mask,
671
+ (batch_size, seq_length),
672
+ inputs_embeds,
673
+ past_key_values_length,
674
+ )
675
+ else:
676
+ # 4d mask is passed through the layers
677
+ attention_mask = _prepare_4d_causal_attention_mask(
678
+ attention_mask, (batch_size, seq_length), inputs_embeds, past_key_values_length
679
+ )
680
+
681
+ hidden_states = inputs_embeds
682
+
683
+ if self.gradient_checkpointing and self.training:
684
+ if use_cache:
685
+ logger.warning_once(
686
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
687
+ )
688
+ use_cache = False
689
+
690
+ # decoder layers
691
+ all_hidden_states = () if output_hidden_states else None
692
+ all_self_attns = () if output_attentions else None
693
+ next_decoder_cache = () if use_cache else None
694
+
695
+ for idx, decoder_layer in enumerate(self.layers):
696
+ if output_hidden_states:
697
+ all_hidden_states += (hidden_states,)
698
+
699
+ past_key_value = past_key_values[idx] if past_key_values is not None else None
700
+
701
+ if self.gradient_checkpointing and self.training:
702
+
703
+ def create_custom_forward(module):
704
+ def custom_forward(*inputs):
705
+ # None for past_key_value
706
+ return module(*inputs, past_key_value, output_attentions)
707
+
708
+ return custom_forward
709
+
710
+ layer_outputs = torch.utils.checkpoint.checkpoint(
711
+ create_custom_forward(decoder_layer),
712
+ hidden_states,
713
+ modality_indicators,
714
+ attention_mask,
715
+ position_ids,
716
+ )
717
+ else:
718
+ layer_outputs = decoder_layer(
719
+ hidden_states,
720
+ modality_indicators=modality_indicators,
721
+ attention_mask=attention_mask,
722
+ position_ids=position_ids,
723
+ past_key_value=past_key_value,
724
+ output_attentions=output_attentions,
725
+ use_cache=use_cache,
726
+ )
727
+
728
+ hidden_states = layer_outputs[0]
729
+
730
+ if use_cache:
731
+ next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
732
+
733
+ if output_attentions:
734
+ all_self_attns += (layer_outputs[1],)
735
+
736
+ hidden_states = self.norm(hidden_states)
737
+
738
+ # add hidden states from the last decoder layer
739
+ if output_hidden_states:
740
+ all_hidden_states += (hidden_states,)
741
+
742
+ next_cache = next_decoder_cache if use_cache else None
743
+ if not return_dict:
744
+ return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
745
+ return BaseModelOutputWithPast(
746
+ last_hidden_state=hidden_states,
747
+ past_key_values=next_cache,
748
+ hidden_states=all_hidden_states,
749
+ attentions=all_self_attns,
750
+ )
751
+
752
+
753
+ def causal_model_forward(
754
+ self,
755
+ input_ids: torch.LongTensor = None,
756
+ modality_indicators: torch.Tensor = None,
757
+ attention_mask: Optional[torch.Tensor] = None,
758
+ position_ids: Optional[torch.LongTensor] = None,
759
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
760
+ inputs_embeds: Optional[torch.FloatTensor] = None,
761
+ labels: Optional[torch.LongTensor] = None,
762
+ use_cache: Optional[bool] = None,
763
+ output_attentions: Optional[bool] = None,
764
+ output_hidden_states: Optional[bool] = None,
765
+ return_dict: Optional[bool] = None,
766
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
767
+ r"""
768
+ Args:
769
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
770
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
771
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
772
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
773
+
774
+ Returns:
775
+
776
+ Example:
777
+
778
+ ```python
779
+ >>> from transformers import AutoTokenizer, LlamaForCausalLM
780
+
781
+ >>> model = LlamaForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
782
+ >>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
783
+
784
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
785
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
786
+
787
+ >>> # Generate
788
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
789
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
790
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
791
+ ```"""
792
+
793
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
794
+ output_hidden_states = (
795
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
796
+ )
797
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
798
+
799
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
800
+ outputs = self.model(
801
+ input_ids=input_ids,
802
+ modality_indicators=modality_indicators,
803
+ attention_mask=attention_mask,
804
+ position_ids=position_ids,
805
+ past_key_values=past_key_values,
806
+ inputs_embeds=inputs_embeds,
807
+ use_cache=use_cache,
808
+ output_attentions=output_attentions,
809
+ output_hidden_states=output_hidden_states,
810
+ return_dict=return_dict,
811
+ )
812
+
813
+ hidden_states = outputs[0]
814
+ if self.config.pretraining_tp > 1:
815
+ lm_head_slices = self.lm_head.weight.split(self.vocab_size // self.config.pretraining_tp, dim=0)
816
+ logits = [F.linear(hidden_states, lm_head_slices[i]) for i in range(self.config.pretraining_tp)]
817
+ logits = torch.cat(logits, dim=-1)
818
+ else:
819
+ logits = self.lm_head(hidden_states)
820
+ logits = logits.float()
821
+
822
+ loss = None
823
+ if labels is not None:
824
+ # Shift so that tokens < n predict n
825
+ shift_logits = logits[..., :-1, :].contiguous()
826
+ shift_labels = labels[..., 1:].contiguous()
827
+ # Flatten the tokens
828
+ loss_fct = CrossEntropyLoss()
829
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
830
+ shift_labels = shift_labels.view(-1)
831
+ # Enable model parallelism
832
+ shift_labels = shift_labels.to(shift_logits.device)
833
+ loss = loss_fct(shift_logits, shift_labels)
834
+
835
+ if not return_dict:
836
+ output = (logits,) + outputs[1:]
837
+ return (loss,) + output if loss is not None else output
838
+
839
+ return CausalLMOutputWithPast(
840
+ loss=loss,
841
+ logits=logits,
842
+ past_key_values=outputs.past_key_values,
843
+ hidden_states=outputs.hidden_states,
844
+ attentions=outputs.attentions,
845
+ )
846
+
847
+ def replace_llama_modality_adaptive():
848
+ transformers.models.llama.configuration_llama.LlamaConfig = LlamaConfig
849
+ transformers.models.llama.modeling_llama.LlamaAttention = LlamaAttention
850
+ transformers.models.llama.modeling_llama.LlamaFlashAttention2 = LlamaFlashAttention2
851
+ transformers.models.llama.modeling_llama.LlamaSdpaAttention = LlamaSdpaAttention
852
+ transformers.models.llama.modeling_llama.LlamaDecoderLayer = LlamaDecoderLayer
853
+ transformers.models.llama.modeling_llama.LlamaModel.forward = model_forward
854
+ transformers.models.llama.modeling_llama.LlamaForCausalLM.forward = causal_model_forward
855
+
856
+
857
+ if __name__ == "__main__":
858
+ replace_llama_modality_adaptive()
859
+ config = transformers.LlamaConfig.from_pretrained('/cpfs01/shared/public/test/vicuna-7b-v1.5/')
860
+ model = transformers.LlamaForCausalLM(config)
861
+ print(model)
modeling_mplug_owl2_huggingface.py ADDED
@@ -0,0 +1,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2023 Haotian Liu & Qinghao Ye (Modified from LLaVA)
2
+ #
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
+
15
+ import os
16
+ import sys
17
+ from abc import ABC, abstractmethod
18
+ from typing import List, Optional, Tuple, Union
19
+
20
+ import torch
21
+ import torch.nn as nn
22
+ import torch.nn.functional as F
23
+ from torch.nn import CrossEntropyLoss
24
+ from PIL import Image
25
+
26
+ dir_path = os.path.dirname(os.path.realpath(__file__))
27
+ sys.path.insert(0, dir_path)
28
+
29
+ from transformers import (
30
+ AutoConfig,
31
+ AutoModelForCausalLM,
32
+ AutoTokenizer,
33
+ LlamaForCausalLM,
34
+ LlamaModel,
35
+ )
36
+ from transformers.modeling_outputs import CausalLMOutputWithPast
37
+ from transformers.models.clip.image_processing_clip import CLIPImageProcessor
38
+
39
+ from .configuration_mplug_owl2 import (
40
+ MPLUGOwl2Config,
41
+ MplugOwlVisionConfig,
42
+ MplugOwlVisualAbstractorConfig
43
+ )
44
+ from .modeling_attn_mask_utils import _prepare_4d_causal_attention_mask # Force copy
45
+ from .modeling_llama2 import replace_llama_modality_adaptive
46
+ from .visual_encoder import MplugOwlVisionModel, MplugOwlVisualAbstractorModel
47
+
48
+ IGNORE_INDEX = -100
49
+ IMAGE_TOKEN_INDEX = -200
50
+ DEFAULT_IMAGE_TOKEN = "<|image|>"
51
+
52
+
53
+ def tokenizer_image_token(prompt, tokenizer, image_token_index=IMAGE_TOKEN_INDEX, return_tensors=None):
54
+ prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split(DEFAULT_IMAGE_TOKEN)]
55
+
56
+ def insert_separator(X, sep):
57
+ return [ele for sublist in zip(X, [sep]*len(X)) for ele in sublist][:-1]
58
+
59
+ input_ids = []
60
+ offset = 0
61
+ if len(prompt_chunks) > 0 and len(prompt_chunks[0]) > 0 and prompt_chunks[0][0] == tokenizer.bos_token_id:
62
+ offset = 1
63
+ input_ids.append(prompt_chunks[0][0])
64
+
65
+ for x in insert_separator(prompt_chunks, [image_token_index] * (offset + 1)):
66
+ input_ids.extend(x[offset:])
67
+
68
+ if return_tensors is not None:
69
+ if return_tensors == 'pt':
70
+ return torch.tensor(input_ids, dtype=torch.long)
71
+ raise ValueError(f'Unsupported tensor type: {return_tensors}')
72
+ return input_ids
73
+
74
+
75
+ def expand2square(pil_img, background_color):
76
+ width, height = pil_img.size
77
+ if width == height:
78
+ return pil_img
79
+ elif width > height:
80
+ result = Image.new(pil_img.mode, (width, width), background_color)
81
+ result.paste(pil_img, (0, (width - height) // 2))
82
+ return result
83
+ else:
84
+ result = Image.new(pil_img.mode, (height, height), background_color)
85
+ result.paste(pil_img, ((height - width) // 2, 0))
86
+ return result
87
+
88
+
89
+ class MPLUGOwl2MetaModel:
90
+ def __init__(self, config):
91
+ super(MPLUGOwl2MetaModel, self).__init__(config)
92
+ self.vision_model = MplugOwlVisionModel(
93
+ MplugOwlVisionConfig(**config.visual_config["visual_model"])
94
+ )
95
+ self.visual_abstractor = MplugOwlVisualAbstractorModel(
96
+ MplugOwlVisualAbstractorConfig(**config.visual_config["visual_abstractor"]),
97
+ config.hidden_size,
98
+ )
99
+
100
+ def get_vision_tower(self):
101
+ vision_model = getattr(self, "vision_model", None)
102
+ if type(vision_model) is list:
103
+ vision_model = vision_model[0]
104
+ return vision_model
105
+
106
+ def get_visual_abstractor(self):
107
+ visual_abstractor = getattr(self, "visual_abstractor", None)
108
+ if type(visual_abstractor) is list:
109
+ visual_abstractor = visual_abstractor[0]
110
+ return visual_abstractor
111
+
112
+
113
+ class MPLUGOwl2MetaForCausalLM(ABC):
114
+ @abstractmethod
115
+ def get_model(self):
116
+ pass
117
+
118
+ def encode_images(self, images):
119
+ image_features = self.get_model().vision_model(images).last_hidden_state
120
+ image_features = (
121
+ self.get_model()
122
+ .visual_abstractor(encoder_hidden_states=image_features)
123
+ .last_hidden_state
124
+ )
125
+ return image_features
126
+
127
+ def prepare_inputs_labels_for_multimodal(
128
+ self, input_ids, attention_mask, past_key_values, labels, images
129
+ ):
130
+ if images is None or input_ids.shape[1] == 1:
131
+ if (
132
+ past_key_values is not None
133
+ and images is not None
134
+ and input_ids.shape[1] == 1
135
+ ):
136
+ attention_mask = torch.ones(
137
+ (attention_mask.shape[0], past_key_values[-1][-1].shape[-2] + 1),
138
+ dtype=attention_mask.dtype,
139
+ device=attention_mask.device,
140
+ )
141
+ multiway_indices = torch.zeros_like(input_ids).long().to(self.device)
142
+ return (
143
+ input_ids,
144
+ multiway_indices,
145
+ attention_mask,
146
+ past_key_values,
147
+ None,
148
+ labels,
149
+ )
150
+
151
+ if type(images) is list or images.ndim == 5:
152
+ concat_images = torch.cat([image for image in images], dim=0)
153
+ image_features = self.encode_images(concat_images)
154
+ split_sizes = [image.shape[0] for image in images]
155
+ image_features = torch.split(image_features, split_sizes, dim=0)
156
+ image_features = [x.flatten(0, 1) for x in image_features]
157
+ else:
158
+ image_features = self.encode_images(images)
159
+
160
+ new_input_embeds = []
161
+ new_modality_indicators = []
162
+ new_labels = [] if labels is not None else None
163
+ cur_image_idx = 0
164
+ for batch_idx, cur_input_ids in enumerate(input_ids):
165
+ if (cur_input_ids == IMAGE_TOKEN_INDEX).sum() == 0:
166
+ half_len = cur_input_ids.shape[0] // 2
167
+ cur_image_features = image_features[cur_image_idx]
168
+ cur_input_embeds_1 = self.get_model().embed_tokens(
169
+ cur_input_ids[:half_len]
170
+ )
171
+ cur_input_embeds_2 = self.get_model().embed_tokens(
172
+ cur_input_ids[half_len:]
173
+ )
174
+ cur_input_embeds = torch.cat(
175
+ [cur_input_embeds_1, cur_image_features[0:0], cur_input_embeds_2],
176
+ dim=0,
177
+ )
178
+ new_input_embeds.append(cur_input_embeds)
179
+
180
+ cur_modality_indicators = (
181
+ torch.zeros(len(cur_input_embeds)).long().to(self.device)
182
+ )
183
+ new_modality_indicators.append(cur_modality_indicators)
184
+ if labels is not None:
185
+ new_labels.append(labels[batch_idx])
186
+ cur_image_idx += 1
187
+ continue
188
+ image_token_indices = torch.where(cur_input_ids == IMAGE_TOKEN_INDEX)[0]
189
+ cur_new_input_embeds = []
190
+ cur_modality_indicators = []
191
+ if labels is not None:
192
+ cur_labels = labels[batch_idx]
193
+ cur_new_labels = []
194
+ assert cur_labels.shape == cur_input_ids.shape
195
+ while image_token_indices.numel() > 0:
196
+ cur_image_features = image_features[cur_image_idx]
197
+ image_token_start = image_token_indices[0]
198
+ cur_new_input_embeds.append(
199
+ self.get_model().embed_tokens(cur_input_ids[:image_token_start])
200
+ )
201
+ cur_new_input_embeds.append(cur_image_features)
202
+
203
+ cur_modality_indicators.append(
204
+ torch.zeros(len(cur_input_ids[:image_token_start])).long()
205
+ )
206
+ cur_modality_indicators.append(
207
+ torch.ones(len(cur_image_features)).long()
208
+ )
209
+
210
+ if labels is not None:
211
+ cur_new_labels.append(cur_labels[:image_token_start])
212
+ cur_new_labels.append(
213
+ torch.full(
214
+ (cur_image_features.shape[0],),
215
+ IGNORE_INDEX,
216
+ device=labels.device,
217
+ dtype=labels.dtype,
218
+ )
219
+ )
220
+ cur_labels = cur_labels[image_token_start + 1 :]
221
+ cur_image_idx += 1
222
+ cur_input_ids = cur_input_ids[image_token_start + 1 :]
223
+ image_token_indices = torch.where(cur_input_ids == IMAGE_TOKEN_INDEX)[0]
224
+ if cur_input_ids.numel() > 0:
225
+ cur_new_input_embeds.append(
226
+ self.get_model().embed_tokens(cur_input_ids)
227
+ )
228
+ cur_modality_indicators.append(torch.zeros(len(cur_input_ids)).long())
229
+ if labels is not None:
230
+ cur_new_labels.append(cur_labels)
231
+ cur_new_input_embeds = [
232
+ x.to(device=self.device) for x in cur_new_input_embeds
233
+ ]
234
+ cur_new_input_embeds = torch.cat(cur_new_input_embeds, dim=0)
235
+ new_input_embeds.append(cur_new_input_embeds)
236
+
237
+ cur_modality_indicators = [
238
+ x.to(device=self.device) for x in cur_modality_indicators
239
+ ]
240
+ cur_modality_indicators = torch.cat(cur_modality_indicators, dim=0)
241
+ new_modality_indicators.append(cur_modality_indicators)
242
+
243
+ if labels is not None:
244
+ cur_new_labels = torch.cat(cur_new_labels, dim=0)
245
+ new_labels.append(cur_new_labels)
246
+
247
+ if any(x.shape != new_input_embeds[0].shape for x in new_input_embeds):
248
+ max_len = max(x.shape[0] for x in new_input_embeds)
249
+
250
+ new_input_embeds_align = []
251
+ for cur_new_embed in new_input_embeds:
252
+ cur_new_embed = torch.cat(
253
+ (
254
+ cur_new_embed,
255
+ torch.zeros(
256
+ (max_len - cur_new_embed.shape[0], cur_new_embed.shape[1]),
257
+ dtype=cur_new_embed.dtype,
258
+ device=cur_new_embed.device,
259
+ ),
260
+ ),
261
+ dim=0,
262
+ )
263
+ new_input_embeds_align.append(cur_new_embed)
264
+ new_input_embeds = torch.stack(new_input_embeds_align, dim=0)
265
+
266
+ new_modality_indicators_align = []
267
+ for cur_modality_indicator in new_modality_indicators:
268
+ cur_new_embed = torch.cat(
269
+ (
270
+ cur_modality_indicator,
271
+ torch.zeros(
272
+ max_len - cur_modality_indicator.shape[0],
273
+ dtype=cur_modality_indicator.dtype,
274
+ device=cur_modality_indicator.device,
275
+ ),
276
+ ),
277
+ dim=0,
278
+ )
279
+ new_modality_indicators_align.append(cur_new_embed)
280
+ new_modality_indicators = torch.stack(new_modality_indicators_align, dim=0)
281
+
282
+ if labels is not None:
283
+ new_labels_align = []
284
+ _new_labels = new_labels
285
+ for cur_new_label in new_labels:
286
+ cur_new_label = torch.cat(
287
+ (
288
+ cur_new_label,
289
+ torch.full(
290
+ (max_len - cur_new_label.shape[0],),
291
+ IGNORE_INDEX,
292
+ dtype=cur_new_label.dtype,
293
+ device=cur_new_label.device,
294
+ ),
295
+ ),
296
+ dim=0,
297
+ )
298
+ new_labels_align.append(cur_new_label)
299
+ new_labels = torch.stack(new_labels_align, dim=0)
300
+
301
+ if attention_mask is not None:
302
+ new_attention_mask = []
303
+ for cur_attention_mask, cur_new_labels, cur_new_labels_align in zip(
304
+ attention_mask, _new_labels, new_labels
305
+ ):
306
+ new_attn_mask_pad_left = torch.full(
307
+ (cur_new_labels.shape[0] - labels.shape[1],),
308
+ True,
309
+ dtype=attention_mask.dtype,
310
+ device=attention_mask.device,
311
+ )
312
+ new_attn_mask_pad_right = torch.full(
313
+ (cur_new_labels_align.shape[0] - cur_new_labels.shape[0],),
314
+ False,
315
+ dtype=attention_mask.dtype,
316
+ device=attention_mask.device,
317
+ )
318
+ cur_new_attention_mask = torch.cat(
319
+ (
320
+ new_attn_mask_pad_left,
321
+ cur_attention_mask,
322
+ new_attn_mask_pad_right,
323
+ ),
324
+ dim=0,
325
+ )
326
+ new_attention_mask.append(cur_new_attention_mask)
327
+ attention_mask = torch.stack(new_attention_mask, dim=0)
328
+ assert attention_mask.shape == new_labels.shape
329
+ else:
330
+ new_input_embeds = torch.stack(new_input_embeds, dim=0)
331
+ new_modality_indicators = torch.stack(new_modality_indicators, dim=0)
332
+ if labels is not None:
333
+ new_labels = torch.stack(new_labels, dim=0)
334
+
335
+ if attention_mask is not None:
336
+ new_attn_mask_pad_left = torch.full(
337
+ (
338
+ attention_mask.shape[0],
339
+ new_input_embeds.shape[1] - input_ids.shape[1],
340
+ ),
341
+ True,
342
+ dtype=attention_mask.dtype,
343
+ device=attention_mask.device,
344
+ )
345
+ attention_mask = torch.cat(
346
+ (new_attn_mask_pad_left, attention_mask), dim=1
347
+ )
348
+ assert attention_mask.shape == new_input_embeds.shape[:2]
349
+ return (
350
+ None,
351
+ new_modality_indicators,
352
+ attention_mask,
353
+ past_key_values,
354
+ new_input_embeds,
355
+ new_labels,
356
+ )
357
+
358
+
359
+ class MPLUGOwl2LlamaModel(MPLUGOwl2MetaModel, LlamaModel):
360
+ config_class = MPLUGOwl2Config
361
+
362
+ def __init__(self, config: MPLUGOwl2Config):
363
+ super(MPLUGOwl2LlamaModel, self).__init__(config)
364
+
365
+
366
+ class MPLUGOwl2LlamaForCausalLM(LlamaForCausalLM, MPLUGOwl2MetaForCausalLM):
367
+ config_class = MPLUGOwl2Config
368
+
369
+ def __init__(self, config):
370
+ super(LlamaForCausalLM, self).__init__(config)
371
+ self.model = MPLUGOwl2LlamaModel(config)
372
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
373
+
374
+ # Tokenizer and image processor will be initialized lazily in score()
375
+ self._tokenizer = None
376
+ self._image_processor = None
377
+ self._preferential_ids = None
378
+
379
+ self.post_init()
380
+
381
+ def _init_processors(self):
382
+ """Lazily initialize tokenizer and image processor from the model's directory."""
383
+ if self._tokenizer is None:
384
+ # Use the model's name_or_path from config, fallback to HF repo name
385
+ model_path = getattr(self.config, '_name_or_path', None)
386
+ if model_path is None or model_path == './' or not model_path.startswith(('/', 'http', 'mapo80')):
387
+ model_path = "mapo80/DeQA-Doc-Sharpness"
388
+ self._tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
389
+ self._image_processor = CLIPImageProcessor.from_pretrained(model_path)
390
+ self._preferential_ids = [id_[1] for id_ in self._tokenizer(
391
+ ["excellent", "good", "fair", "poor", "bad"]
392
+ )["input_ids"]]
393
+
394
+ @property
395
+ def tokenizer(self):
396
+ self._init_processors()
397
+ return self._tokenizer
398
+
399
+ @property
400
+ def image_processor(self):
401
+ self._init_processors()
402
+ return self._image_processor
403
+
404
+ @property
405
+ def preferential_ids_(self):
406
+ self._init_processors()
407
+ return self._preferential_ids
408
+
409
+ def get_model(self):
410
+ return self.model
411
+
412
+ def forward(
413
+ self,
414
+ input_ids: torch.LongTensor = None,
415
+ attention_mask: Optional[torch.Tensor] = None,
416
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
417
+ inputs_embeds: Optional[torch.FloatTensor] = None,
418
+ labels: Optional[torch.LongTensor] = None,
419
+ use_cache: Optional[bool] = None,
420
+ output_attentions: Optional[bool] = None,
421
+ output_hidden_states: Optional[bool] = None,
422
+ images: Optional[torch.FloatTensor] = None,
423
+ return_dict: Optional[bool] = None,
424
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
425
+ output_attentions = (
426
+ output_attentions
427
+ if output_attentions is not None
428
+ else self.config.output_attentions
429
+ )
430
+ output_hidden_states = (
431
+ output_hidden_states
432
+ if output_hidden_states is not None
433
+ else self.config.output_hidden_states
434
+ )
435
+ return_dict = (
436
+ return_dict if return_dict is not None else self.config.use_return_dict
437
+ )
438
+ (
439
+ input_ids,
440
+ modality_indicators,
441
+ attention_mask,
442
+ past_key_values,
443
+ inputs_embeds,
444
+ labels,
445
+ ) = self.prepare_inputs_labels_for_multimodal(
446
+ input_ids, attention_mask, past_key_values, labels, images
447
+ )
448
+
449
+ outputs = self.model(
450
+ input_ids=input_ids,
451
+ modality_indicators=modality_indicators,
452
+ attention_mask=attention_mask,
453
+ past_key_values=past_key_values,
454
+ inputs_embeds=inputs_embeds,
455
+ use_cache=use_cache,
456
+ output_attentions=output_attentions,
457
+ output_hidden_states=output_hidden_states,
458
+ return_dict=return_dict,
459
+ )
460
+
461
+ hidden_states = outputs[0]
462
+ logits = self.lm_head(hidden_states)
463
+
464
+ loss = None
465
+ if labels is not None:
466
+ shift_logits = logits[..., :-1, :].contiguous()
467
+ shift_labels = labels[..., 1:].contiguous()
468
+ loss_fct = CrossEntropyLoss()
469
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
470
+ shift_labels = shift_labels.view(-1)
471
+ shift_labels = shift_labels.to(shift_logits.device)
472
+ loss = loss_fct(shift_logits, shift_labels)
473
+
474
+ if not return_dict:
475
+ output = (logits,) + outputs[1:]
476
+ return (loss,) + output if loss is not None else output
477
+
478
+ return CausalLMOutputWithPast(
479
+ loss=loss,
480
+ logits=logits,
481
+ past_key_values=outputs.past_key_values,
482
+ hidden_states=outputs.hidden_states,
483
+ attentions=outputs.attentions,
484
+ )
485
+
486
+ def score(
487
+ self,
488
+ images: List[Image.Image],
489
+ task_: str = "quality",
490
+ input_: str = "image",
491
+ ) -> torch.Tensor:
492
+ """
493
+ Score images based on quality assessment.
494
+
495
+ Args:
496
+ images: List of PIL Images to score
497
+ task_: Type of assessment (default: "quality")
498
+ input_: Input type - "image" or "video" (default: "image")
499
+
500
+ Returns:
501
+ torch.Tensor: Quality scores (1-5 scale)
502
+ """
503
+ if not hasattr(self, "weight_tensor"):
504
+ self.weight_tensor = torch.Tensor([5., 4., 3., 2., 1.]).half().to(self.device)
505
+
506
+ prompt = "USER: How would you rate the {} of this {}?\n<|image|>\nASSISTANT: The {} of the {} is".format(
507
+ task_, input_, task_, input_
508
+ )
509
+
510
+ if input_ == "image":
511
+ # Process single images
512
+ images = [expand2square(img, tuple(int(x*255) for x in self.image_processor.image_mean)) for img in images]
513
+ input_ids = tokenizer_image_token(prompt, self.tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).to(self.device)
514
+
515
+ with torch.inference_mode():
516
+ image_tensor = self.image_processor.preprocess(images, return_tensors="pt")["pixel_values"].half().to(self.device)
517
+ output_logits = self(
518
+ input_ids=input_ids.repeat(image_tensor.shape[0], 1),
519
+ images=image_tensor
520
+ )["logits"][:, -1, self.preferential_ids_]
521
+
522
+ return torch.softmax(output_logits, -1) @ self.weight_tensor
523
+ else:
524
+ # Process videos (list of frame sequences)
525
+ video = [[expand2square(frame, tuple(int(x*255) for x in self.image_processor.image_mean)) for frame in vid] for vid in images]
526
+ input_ids = tokenizer_image_token(prompt, self.tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).to(self.device)
527
+
528
+ with torch.inference_mode():
529
+ video_tensors = [
530
+ self.image_processor.preprocess(vid, return_tensors="pt")["pixel_values"].half().to(self.device)
531
+ for vid in video
532
+ ]
533
+ output_logits = self(
534
+ input_ids=input_ids.repeat(len(video_tensors), 1),
535
+ images=video_tensors
536
+ )["logits"][:, -1, self.preferential_ids_]
537
+
538
+ return torch.softmax(output_logits, -1) @ self.weight_tensor
539
+
540
+ def prepare_inputs_for_generation(
541
+ self,
542
+ input_ids,
543
+ past_key_values=None,
544
+ attention_mask=None,
545
+ inputs_embeds=None,
546
+ images=None,
547
+ **kwargs,
548
+ ):
549
+ if past_key_values:
550
+ input_ids = input_ids[:, -1:]
551
+
552
+ if inputs_embeds is not None and past_key_values is None:
553
+ model_inputs = {"inputs_embeds": inputs_embeds}
554
+ else:
555
+ model_inputs = {"input_ids": input_ids}
556
+
557
+ model_inputs.update(
558
+ {
559
+ "past_key_values": past_key_values,
560
+ "use_cache": kwargs.get("use_cache"),
561
+ "attention_mask": attention_mask,
562
+ "images": images,
563
+ }
564
+ )
565
+ return model_inputs
566
+
567
+
568
+ AutoConfig.register("mplug_owl2", MPLUGOwl2Config)
569
+ AutoModelForCausalLM.register(MPLUGOwl2Config, MPLUGOwl2LlamaForCausalLM)
570
+
571
+ replace_llama_modality_adaptive()
preprocessor_config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": {
3
+ "height": 448,
4
+ "width": 448
5
+ },
6
+ "do_center_crop": true,
7
+ "do_normalize": true,
8
+ "do_rescale": true,
9
+ "do_resize": true,
10
+ "image_mean": [0.48145466, 0.4578275, 0.40821073],
11
+ "image_processor_type": "CLIPImageProcessor",
12
+ "image_std": [0.26862954, 0.26130258, 0.27577711],
13
+ "resample": 3,
14
+ "rescale_factor": 0.00392156862745098,
15
+ "size": {
16
+ "shortest_edge": 448
17
+ }
18
+ }
pytorch_model-00001-of-00004.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:721e2348e05ef81b5cc9534a94b9caba3699586a37cd643aad6dd6c14a9b7041
3
+ size 4981108780
pytorch_model-00002-of-00004.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:94954006aba2f33919e4082bc65fc5b5091f73998e9915f85cb71e832d6ee96d
3
+ size 4920293259
pytorch_model-00003-of-00004.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:639b15209838cf92a603a4f8667cdec11582c01e4fa7aba87ed916dce074ab76
3
+ size 4989532454
pytorch_model-00004-of-00004.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c358f2e9c72bf180194543d9c167d23bd22ca3aa0c9d689afa21d505ca8ab8c
3
+ size 1518469929
pytorch_model.bin.index.json ADDED
@@ -0,0 +1,869 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 16409100288
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "pytorch_model-00004-of-00004.bin",
7
+ "model.embed_tokens.weight": "pytorch_model-00001-of-00004.bin",
8
+ "model.layers.0.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
9
+ "model.layers.0.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
10
+ "model.layers.0.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
11
+ "model.layers.0.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
12
+ "model.layers.0.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
13
+ "model.layers.0.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
14
+ "model.layers.0.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
15
+ "model.layers.0.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
16
+ "model.layers.0.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
17
+ "model.layers.0.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
18
+ "model.layers.0.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
19
+ "model.layers.0.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
20
+ "model.layers.0.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
21
+ "model.layers.1.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
22
+ "model.layers.1.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
23
+ "model.layers.1.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
24
+ "model.layers.1.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
25
+ "model.layers.1.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
26
+ "model.layers.1.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
27
+ "model.layers.1.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
28
+ "model.layers.1.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
29
+ "model.layers.1.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
30
+ "model.layers.1.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
31
+ "model.layers.1.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
32
+ "model.layers.1.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
33
+ "model.layers.1.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
34
+ "model.layers.10.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
35
+ "model.layers.10.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
36
+ "model.layers.10.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
37
+ "model.layers.10.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
38
+ "model.layers.10.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
39
+ "model.layers.10.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
40
+ "model.layers.10.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
41
+ "model.layers.10.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
42
+ "model.layers.10.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
43
+ "model.layers.10.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
44
+ "model.layers.10.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
45
+ "model.layers.10.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
46
+ "model.layers.10.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
47
+ "model.layers.11.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
48
+ "model.layers.11.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
49
+ "model.layers.11.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
50
+ "model.layers.11.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
51
+ "model.layers.11.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
52
+ "model.layers.11.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
53
+ "model.layers.11.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
54
+ "model.layers.11.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
55
+ "model.layers.11.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
56
+ "model.layers.11.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
57
+ "model.layers.11.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
58
+ "model.layers.11.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
59
+ "model.layers.11.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
60
+ "model.layers.12.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
61
+ "model.layers.12.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
62
+ "model.layers.12.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
63
+ "model.layers.12.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
64
+ "model.layers.12.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
65
+ "model.layers.12.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
66
+ "model.layers.12.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
67
+ "model.layers.12.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
68
+ "model.layers.12.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
69
+ "model.layers.12.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
70
+ "model.layers.12.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
71
+ "model.layers.12.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
72
+ "model.layers.12.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
73
+ "model.layers.13.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
74
+ "model.layers.13.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
75
+ "model.layers.13.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
76
+ "model.layers.13.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
77
+ "model.layers.13.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
78
+ "model.layers.13.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
79
+ "model.layers.13.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
80
+ "model.layers.13.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
81
+ "model.layers.13.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
82
+ "model.layers.13.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
83
+ "model.layers.13.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
84
+ "model.layers.13.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
85
+ "model.layers.13.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
86
+ "model.layers.14.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
87
+ "model.layers.14.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
88
+ "model.layers.14.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
89
+ "model.layers.14.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
90
+ "model.layers.14.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
91
+ "model.layers.14.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
92
+ "model.layers.14.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
93
+ "model.layers.14.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
94
+ "model.layers.14.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
95
+ "model.layers.14.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
96
+ "model.layers.14.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
97
+ "model.layers.14.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
98
+ "model.layers.14.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
99
+ "model.layers.15.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
100
+ "model.layers.15.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
101
+ "model.layers.15.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
102
+ "model.layers.15.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
103
+ "model.layers.15.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
104
+ "model.layers.15.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
105
+ "model.layers.15.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
106
+ "model.layers.15.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
107
+ "model.layers.15.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
108
+ "model.layers.15.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
109
+ "model.layers.15.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
110
+ "model.layers.15.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
111
+ "model.layers.15.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
112
+ "model.layers.16.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
113
+ "model.layers.16.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
114
+ "model.layers.16.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
115
+ "model.layers.16.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
116
+ "model.layers.16.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
117
+ "model.layers.16.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
118
+ "model.layers.16.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
119
+ "model.layers.16.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
120
+ "model.layers.16.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
121
+ "model.layers.16.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
122
+ "model.layers.16.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
123
+ "model.layers.16.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
124
+ "model.layers.16.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
125
+ "model.layers.17.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
126
+ "model.layers.17.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
127
+ "model.layers.17.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
128
+ "model.layers.17.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
129
+ "model.layers.17.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
130
+ "model.layers.17.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
131
+ "model.layers.17.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
132
+ "model.layers.17.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
133
+ "model.layers.17.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
134
+ "model.layers.17.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
135
+ "model.layers.17.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
136
+ "model.layers.17.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
137
+ "model.layers.17.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
138
+ "model.layers.18.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
139
+ "model.layers.18.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
140
+ "model.layers.18.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
141
+ "model.layers.18.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
142
+ "model.layers.18.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
143
+ "model.layers.18.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
144
+ "model.layers.18.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
145
+ "model.layers.18.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
146
+ "model.layers.18.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
147
+ "model.layers.18.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
148
+ "model.layers.18.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
149
+ "model.layers.18.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
150
+ "model.layers.18.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
151
+ "model.layers.19.input_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
152
+ "model.layers.19.input_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
153
+ "model.layers.19.mlp.down_proj.weight": "pytorch_model-00002-of-00004.bin",
154
+ "model.layers.19.mlp.gate_proj.weight": "pytorch_model-00002-of-00004.bin",
155
+ "model.layers.19.mlp.up_proj.weight": "pytorch_model-00002-of-00004.bin",
156
+ "model.layers.19.post_attention_layernorm.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
157
+ "model.layers.19.post_attention_layernorm.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
158
+ "model.layers.19.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
159
+ "model.layers.19.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
160
+ "model.layers.19.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
161
+ "model.layers.19.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
162
+ "model.layers.19.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
163
+ "model.layers.19.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
164
+ "model.layers.2.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
165
+ "model.layers.2.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
166
+ "model.layers.2.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
167
+ "model.layers.2.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
168
+ "model.layers.2.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
169
+ "model.layers.2.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
170
+ "model.layers.2.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
171
+ "model.layers.2.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
172
+ "model.layers.2.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
173
+ "model.layers.2.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
174
+ "model.layers.2.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
175
+ "model.layers.2.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
176
+ "model.layers.2.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
177
+ "model.layers.20.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
178
+ "model.layers.20.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
179
+ "model.layers.20.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
180
+ "model.layers.20.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
181
+ "model.layers.20.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
182
+ "model.layers.20.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
183
+ "model.layers.20.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
184
+ "model.layers.20.self_attn.k_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
185
+ "model.layers.20.self_attn.k_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
186
+ "model.layers.20.self_attn.o_proj.weight": "pytorch_model-00002-of-00004.bin",
187
+ "model.layers.20.self_attn.q_proj.weight": "pytorch_model-00002-of-00004.bin",
188
+ "model.layers.20.self_attn.v_proj.multiway.0.weight": "pytorch_model-00002-of-00004.bin",
189
+ "model.layers.20.self_attn.v_proj.multiway.1.weight": "pytorch_model-00002-of-00004.bin",
190
+ "model.layers.21.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
191
+ "model.layers.21.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
192
+ "model.layers.21.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
193
+ "model.layers.21.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
194
+ "model.layers.21.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
195
+ "model.layers.21.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
196
+ "model.layers.21.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
197
+ "model.layers.21.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
198
+ "model.layers.21.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
199
+ "model.layers.21.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
200
+ "model.layers.21.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
201
+ "model.layers.21.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
202
+ "model.layers.21.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
203
+ "model.layers.22.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
204
+ "model.layers.22.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
205
+ "model.layers.22.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
206
+ "model.layers.22.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
207
+ "model.layers.22.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
208
+ "model.layers.22.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
209
+ "model.layers.22.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
210
+ "model.layers.22.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
211
+ "model.layers.22.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
212
+ "model.layers.22.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
213
+ "model.layers.22.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
214
+ "model.layers.22.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
215
+ "model.layers.22.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
216
+ "model.layers.23.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
217
+ "model.layers.23.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
218
+ "model.layers.23.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
219
+ "model.layers.23.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
220
+ "model.layers.23.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
221
+ "model.layers.23.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
222
+ "model.layers.23.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
223
+ "model.layers.23.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
224
+ "model.layers.23.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
225
+ "model.layers.23.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
226
+ "model.layers.23.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
227
+ "model.layers.23.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
228
+ "model.layers.23.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
229
+ "model.layers.24.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
230
+ "model.layers.24.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
231
+ "model.layers.24.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
232
+ "model.layers.24.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
233
+ "model.layers.24.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
234
+ "model.layers.24.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
235
+ "model.layers.24.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
236
+ "model.layers.24.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
237
+ "model.layers.24.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
238
+ "model.layers.24.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
239
+ "model.layers.24.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
240
+ "model.layers.24.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
241
+ "model.layers.24.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
242
+ "model.layers.25.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
243
+ "model.layers.25.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
244
+ "model.layers.25.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
245
+ "model.layers.25.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
246
+ "model.layers.25.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
247
+ "model.layers.25.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
248
+ "model.layers.25.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
249
+ "model.layers.25.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
250
+ "model.layers.25.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
251
+ "model.layers.25.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
252
+ "model.layers.25.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
253
+ "model.layers.25.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
254
+ "model.layers.25.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
255
+ "model.layers.26.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
256
+ "model.layers.26.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
257
+ "model.layers.26.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
258
+ "model.layers.26.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
259
+ "model.layers.26.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
260
+ "model.layers.26.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
261
+ "model.layers.26.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
262
+ "model.layers.26.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
263
+ "model.layers.26.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
264
+ "model.layers.26.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
265
+ "model.layers.26.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
266
+ "model.layers.26.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
267
+ "model.layers.26.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
268
+ "model.layers.27.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
269
+ "model.layers.27.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
270
+ "model.layers.27.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
271
+ "model.layers.27.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
272
+ "model.layers.27.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
273
+ "model.layers.27.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
274
+ "model.layers.27.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
275
+ "model.layers.27.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
276
+ "model.layers.27.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
277
+ "model.layers.27.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
278
+ "model.layers.27.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
279
+ "model.layers.27.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
280
+ "model.layers.27.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
281
+ "model.layers.28.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
282
+ "model.layers.28.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
283
+ "model.layers.28.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
284
+ "model.layers.28.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
285
+ "model.layers.28.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
286
+ "model.layers.28.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
287
+ "model.layers.28.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
288
+ "model.layers.28.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
289
+ "model.layers.28.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
290
+ "model.layers.28.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
291
+ "model.layers.28.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
292
+ "model.layers.28.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
293
+ "model.layers.28.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
294
+ "model.layers.29.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
295
+ "model.layers.29.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
296
+ "model.layers.29.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
297
+ "model.layers.29.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
298
+ "model.layers.29.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
299
+ "model.layers.29.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
300
+ "model.layers.29.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
301
+ "model.layers.29.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
302
+ "model.layers.29.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
303
+ "model.layers.29.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
304
+ "model.layers.29.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
305
+ "model.layers.29.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
306
+ "model.layers.29.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
307
+ "model.layers.3.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
308
+ "model.layers.3.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
309
+ "model.layers.3.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
310
+ "model.layers.3.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
311
+ "model.layers.3.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
312
+ "model.layers.3.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
313
+ "model.layers.3.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
314
+ "model.layers.3.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
315
+ "model.layers.3.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
316
+ "model.layers.3.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
317
+ "model.layers.3.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
318
+ "model.layers.3.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
319
+ "model.layers.3.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
320
+ "model.layers.30.input_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
321
+ "model.layers.30.input_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
322
+ "model.layers.30.mlp.down_proj.weight": "pytorch_model-00003-of-00004.bin",
323
+ "model.layers.30.mlp.gate_proj.weight": "pytorch_model-00003-of-00004.bin",
324
+ "model.layers.30.mlp.up_proj.weight": "pytorch_model-00003-of-00004.bin",
325
+ "model.layers.30.post_attention_layernorm.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
326
+ "model.layers.30.post_attention_layernorm.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
327
+ "model.layers.30.self_attn.k_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
328
+ "model.layers.30.self_attn.k_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
329
+ "model.layers.30.self_attn.o_proj.weight": "pytorch_model-00003-of-00004.bin",
330
+ "model.layers.30.self_attn.q_proj.weight": "pytorch_model-00003-of-00004.bin",
331
+ "model.layers.30.self_attn.v_proj.multiway.0.weight": "pytorch_model-00003-of-00004.bin",
332
+ "model.layers.30.self_attn.v_proj.multiway.1.weight": "pytorch_model-00003-of-00004.bin",
333
+ "model.layers.31.input_layernorm.multiway.0.weight": "pytorch_model-00004-of-00004.bin",
334
+ "model.layers.31.input_layernorm.multiway.1.weight": "pytorch_model-00004-of-00004.bin",
335
+ "model.layers.31.mlp.down_proj.weight": "pytorch_model-00004-of-00004.bin",
336
+ "model.layers.31.mlp.gate_proj.weight": "pytorch_model-00004-of-00004.bin",
337
+ "model.layers.31.mlp.up_proj.weight": "pytorch_model-00004-of-00004.bin",
338
+ "model.layers.31.post_attention_layernorm.multiway.0.weight": "pytorch_model-00004-of-00004.bin",
339
+ "model.layers.31.post_attention_layernorm.multiway.1.weight": "pytorch_model-00004-of-00004.bin",
340
+ "model.layers.31.self_attn.k_proj.multiway.0.weight": "pytorch_model-00004-of-00004.bin",
341
+ "model.layers.31.self_attn.k_proj.multiway.1.weight": "pytorch_model-00004-of-00004.bin",
342
+ "model.layers.31.self_attn.o_proj.weight": "pytorch_model-00004-of-00004.bin",
343
+ "model.layers.31.self_attn.q_proj.weight": "pytorch_model-00004-of-00004.bin",
344
+ "model.layers.31.self_attn.v_proj.multiway.0.weight": "pytorch_model-00004-of-00004.bin",
345
+ "model.layers.31.self_attn.v_proj.multiway.1.weight": "pytorch_model-00004-of-00004.bin",
346
+ "model.layers.4.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
347
+ "model.layers.4.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
348
+ "model.layers.4.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
349
+ "model.layers.4.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
350
+ "model.layers.4.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
351
+ "model.layers.4.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
352
+ "model.layers.4.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
353
+ "model.layers.4.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
354
+ "model.layers.4.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
355
+ "model.layers.4.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
356
+ "model.layers.4.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
357
+ "model.layers.4.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
358
+ "model.layers.4.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
359
+ "model.layers.5.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
360
+ "model.layers.5.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
361
+ "model.layers.5.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
362
+ "model.layers.5.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
363
+ "model.layers.5.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
364
+ "model.layers.5.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
365
+ "model.layers.5.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
366
+ "model.layers.5.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
367
+ "model.layers.5.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
368
+ "model.layers.5.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
369
+ "model.layers.5.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
370
+ "model.layers.5.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
371
+ "model.layers.5.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
372
+ "model.layers.6.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
373
+ "model.layers.6.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
374
+ "model.layers.6.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
375
+ "model.layers.6.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
376
+ "model.layers.6.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
377
+ "model.layers.6.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
378
+ "model.layers.6.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
379
+ "model.layers.6.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
380
+ "model.layers.6.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
381
+ "model.layers.6.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
382
+ "model.layers.6.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
383
+ "model.layers.6.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
384
+ "model.layers.6.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
385
+ "model.layers.7.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
386
+ "model.layers.7.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
387
+ "model.layers.7.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
388
+ "model.layers.7.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
389
+ "model.layers.7.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
390
+ "model.layers.7.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
391
+ "model.layers.7.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
392
+ "model.layers.7.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
393
+ "model.layers.7.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
394
+ "model.layers.7.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
395
+ "model.layers.7.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
396
+ "model.layers.7.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
397
+ "model.layers.7.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
398
+ "model.layers.8.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
399
+ "model.layers.8.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
400
+ "model.layers.8.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
401
+ "model.layers.8.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
402
+ "model.layers.8.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
403
+ "model.layers.8.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
404
+ "model.layers.8.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
405
+ "model.layers.8.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
406
+ "model.layers.8.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
407
+ "model.layers.8.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
408
+ "model.layers.8.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
409
+ "model.layers.8.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
410
+ "model.layers.8.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
411
+ "model.layers.9.input_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
412
+ "model.layers.9.input_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
413
+ "model.layers.9.mlp.down_proj.weight": "pytorch_model-00001-of-00004.bin",
414
+ "model.layers.9.mlp.gate_proj.weight": "pytorch_model-00001-of-00004.bin",
415
+ "model.layers.9.mlp.up_proj.weight": "pytorch_model-00001-of-00004.bin",
416
+ "model.layers.9.post_attention_layernorm.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
417
+ "model.layers.9.post_attention_layernorm.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
418
+ "model.layers.9.self_attn.k_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
419
+ "model.layers.9.self_attn.k_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
420
+ "model.layers.9.self_attn.o_proj.weight": "pytorch_model-00001-of-00004.bin",
421
+ "model.layers.9.self_attn.q_proj.weight": "pytorch_model-00001-of-00004.bin",
422
+ "model.layers.9.self_attn.v_proj.multiway.0.weight": "pytorch_model-00001-of-00004.bin",
423
+ "model.layers.9.self_attn.v_proj.multiway.1.weight": "pytorch_model-00001-of-00004.bin",
424
+ "model.norm.weight": "pytorch_model-00004-of-00004.bin",
425
+ "model.vision_model.embeddings.cls_token": "pytorch_model-00004-of-00004.bin",
426
+ "model.vision_model.embeddings.patch_embed.weight": "pytorch_model-00004-of-00004.bin",
427
+ "model.vision_model.embeddings.position_embedding": "pytorch_model-00004-of-00004.bin",
428
+ "model.vision_model.embeddings.pre_layernorm.bias": "pytorch_model-00004-of-00004.bin",
429
+ "model.vision_model.embeddings.pre_layernorm.weight": "pytorch_model-00004-of-00004.bin",
430
+ "model.vision_model.encoder.layers.0.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
431
+ "model.vision_model.encoder.layers.0.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
432
+ "model.vision_model.encoder.layers.0.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
433
+ "model.vision_model.encoder.layers.0.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
434
+ "model.vision_model.encoder.layers.0.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
435
+ "model.vision_model.encoder.layers.0.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
436
+ "model.vision_model.encoder.layers.0.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
437
+ "model.vision_model.encoder.layers.0.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
438
+ "model.vision_model.encoder.layers.0.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
439
+ "model.vision_model.encoder.layers.0.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
440
+ "model.vision_model.encoder.layers.0.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
441
+ "model.vision_model.encoder.layers.0.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
442
+ "model.vision_model.encoder.layers.1.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
443
+ "model.vision_model.encoder.layers.1.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
444
+ "model.vision_model.encoder.layers.1.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
445
+ "model.vision_model.encoder.layers.1.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
446
+ "model.vision_model.encoder.layers.1.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
447
+ "model.vision_model.encoder.layers.1.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
448
+ "model.vision_model.encoder.layers.1.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
449
+ "model.vision_model.encoder.layers.1.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
450
+ "model.vision_model.encoder.layers.1.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
451
+ "model.vision_model.encoder.layers.1.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
452
+ "model.vision_model.encoder.layers.1.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
453
+ "model.vision_model.encoder.layers.1.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
454
+ "model.vision_model.encoder.layers.10.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
455
+ "model.vision_model.encoder.layers.10.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
456
+ "model.vision_model.encoder.layers.10.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
457
+ "model.vision_model.encoder.layers.10.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
458
+ "model.vision_model.encoder.layers.10.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
459
+ "model.vision_model.encoder.layers.10.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
460
+ "model.vision_model.encoder.layers.10.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
461
+ "model.vision_model.encoder.layers.10.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
462
+ "model.vision_model.encoder.layers.10.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
463
+ "model.vision_model.encoder.layers.10.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
464
+ "model.vision_model.encoder.layers.10.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
465
+ "model.vision_model.encoder.layers.10.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
466
+ "model.vision_model.encoder.layers.11.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
467
+ "model.vision_model.encoder.layers.11.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
468
+ "model.vision_model.encoder.layers.11.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
469
+ "model.vision_model.encoder.layers.11.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
470
+ "model.vision_model.encoder.layers.11.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
471
+ "model.vision_model.encoder.layers.11.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
472
+ "model.vision_model.encoder.layers.11.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
473
+ "model.vision_model.encoder.layers.11.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
474
+ "model.vision_model.encoder.layers.11.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
475
+ "model.vision_model.encoder.layers.11.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
476
+ "model.vision_model.encoder.layers.11.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
477
+ "model.vision_model.encoder.layers.11.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
478
+ "model.vision_model.encoder.layers.12.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
479
+ "model.vision_model.encoder.layers.12.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
480
+ "model.vision_model.encoder.layers.12.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
481
+ "model.vision_model.encoder.layers.12.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
482
+ "model.vision_model.encoder.layers.12.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
483
+ "model.vision_model.encoder.layers.12.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
484
+ "model.vision_model.encoder.layers.12.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
485
+ "model.vision_model.encoder.layers.12.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
486
+ "model.vision_model.encoder.layers.12.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
487
+ "model.vision_model.encoder.layers.12.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
488
+ "model.vision_model.encoder.layers.12.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
489
+ "model.vision_model.encoder.layers.12.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
490
+ "model.vision_model.encoder.layers.13.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
491
+ "model.vision_model.encoder.layers.13.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
492
+ "model.vision_model.encoder.layers.13.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
493
+ "model.vision_model.encoder.layers.13.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
494
+ "model.vision_model.encoder.layers.13.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
495
+ "model.vision_model.encoder.layers.13.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
496
+ "model.vision_model.encoder.layers.13.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
497
+ "model.vision_model.encoder.layers.13.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
498
+ "model.vision_model.encoder.layers.13.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
499
+ "model.vision_model.encoder.layers.13.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
500
+ "model.vision_model.encoder.layers.13.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
501
+ "model.vision_model.encoder.layers.13.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
502
+ "model.vision_model.encoder.layers.14.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
503
+ "model.vision_model.encoder.layers.14.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
504
+ "model.vision_model.encoder.layers.14.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
505
+ "model.vision_model.encoder.layers.14.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
506
+ "model.vision_model.encoder.layers.14.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
507
+ "model.vision_model.encoder.layers.14.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
508
+ "model.vision_model.encoder.layers.14.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
509
+ "model.vision_model.encoder.layers.14.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
510
+ "model.vision_model.encoder.layers.14.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
511
+ "model.vision_model.encoder.layers.14.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
512
+ "model.vision_model.encoder.layers.14.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
513
+ "model.vision_model.encoder.layers.14.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
514
+ "model.vision_model.encoder.layers.15.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
515
+ "model.vision_model.encoder.layers.15.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
516
+ "model.vision_model.encoder.layers.15.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
517
+ "model.vision_model.encoder.layers.15.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
518
+ "model.vision_model.encoder.layers.15.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
519
+ "model.vision_model.encoder.layers.15.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
520
+ "model.vision_model.encoder.layers.15.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
521
+ "model.vision_model.encoder.layers.15.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
522
+ "model.vision_model.encoder.layers.15.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
523
+ "model.vision_model.encoder.layers.15.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
524
+ "model.vision_model.encoder.layers.15.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
525
+ "model.vision_model.encoder.layers.15.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
526
+ "model.vision_model.encoder.layers.16.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
527
+ "model.vision_model.encoder.layers.16.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
528
+ "model.vision_model.encoder.layers.16.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
529
+ "model.vision_model.encoder.layers.16.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
530
+ "model.vision_model.encoder.layers.16.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
531
+ "model.vision_model.encoder.layers.16.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
532
+ "model.vision_model.encoder.layers.16.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
533
+ "model.vision_model.encoder.layers.16.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
534
+ "model.vision_model.encoder.layers.16.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
535
+ "model.vision_model.encoder.layers.16.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
536
+ "model.vision_model.encoder.layers.16.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
537
+ "model.vision_model.encoder.layers.16.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
538
+ "model.vision_model.encoder.layers.17.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
539
+ "model.vision_model.encoder.layers.17.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
540
+ "model.vision_model.encoder.layers.17.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
541
+ "model.vision_model.encoder.layers.17.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
542
+ "model.vision_model.encoder.layers.17.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
543
+ "model.vision_model.encoder.layers.17.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
544
+ "model.vision_model.encoder.layers.17.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
545
+ "model.vision_model.encoder.layers.17.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
546
+ "model.vision_model.encoder.layers.17.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
547
+ "model.vision_model.encoder.layers.17.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
548
+ "model.vision_model.encoder.layers.17.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
549
+ "model.vision_model.encoder.layers.17.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
550
+ "model.vision_model.encoder.layers.18.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
551
+ "model.vision_model.encoder.layers.18.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
552
+ "model.vision_model.encoder.layers.18.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
553
+ "model.vision_model.encoder.layers.18.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
554
+ "model.vision_model.encoder.layers.18.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
555
+ "model.vision_model.encoder.layers.18.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
556
+ "model.vision_model.encoder.layers.18.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
557
+ "model.vision_model.encoder.layers.18.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
558
+ "model.vision_model.encoder.layers.18.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
559
+ "model.vision_model.encoder.layers.18.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
560
+ "model.vision_model.encoder.layers.18.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
561
+ "model.vision_model.encoder.layers.18.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
562
+ "model.vision_model.encoder.layers.19.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
563
+ "model.vision_model.encoder.layers.19.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
564
+ "model.vision_model.encoder.layers.19.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
565
+ "model.vision_model.encoder.layers.19.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
566
+ "model.vision_model.encoder.layers.19.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
567
+ "model.vision_model.encoder.layers.19.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
568
+ "model.vision_model.encoder.layers.19.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
569
+ "model.vision_model.encoder.layers.19.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
570
+ "model.vision_model.encoder.layers.19.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
571
+ "model.vision_model.encoder.layers.19.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
572
+ "model.vision_model.encoder.layers.19.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
573
+ "model.vision_model.encoder.layers.19.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
574
+ "model.vision_model.encoder.layers.2.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
575
+ "model.vision_model.encoder.layers.2.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
576
+ "model.vision_model.encoder.layers.2.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
577
+ "model.vision_model.encoder.layers.2.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
578
+ "model.vision_model.encoder.layers.2.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
579
+ "model.vision_model.encoder.layers.2.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
580
+ "model.vision_model.encoder.layers.2.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
581
+ "model.vision_model.encoder.layers.2.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
582
+ "model.vision_model.encoder.layers.2.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
583
+ "model.vision_model.encoder.layers.2.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
584
+ "model.vision_model.encoder.layers.2.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
585
+ "model.vision_model.encoder.layers.2.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
586
+ "model.vision_model.encoder.layers.20.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
587
+ "model.vision_model.encoder.layers.20.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
588
+ "model.vision_model.encoder.layers.20.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
589
+ "model.vision_model.encoder.layers.20.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
590
+ "model.vision_model.encoder.layers.20.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
591
+ "model.vision_model.encoder.layers.20.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
592
+ "model.vision_model.encoder.layers.20.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
593
+ "model.vision_model.encoder.layers.20.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
594
+ "model.vision_model.encoder.layers.20.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
595
+ "model.vision_model.encoder.layers.20.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
596
+ "model.vision_model.encoder.layers.20.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
597
+ "model.vision_model.encoder.layers.20.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
598
+ "model.vision_model.encoder.layers.21.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
599
+ "model.vision_model.encoder.layers.21.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
600
+ "model.vision_model.encoder.layers.21.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
601
+ "model.vision_model.encoder.layers.21.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
602
+ "model.vision_model.encoder.layers.21.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
603
+ "model.vision_model.encoder.layers.21.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
604
+ "model.vision_model.encoder.layers.21.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
605
+ "model.vision_model.encoder.layers.21.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
606
+ "model.vision_model.encoder.layers.21.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
607
+ "model.vision_model.encoder.layers.21.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
608
+ "model.vision_model.encoder.layers.21.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
609
+ "model.vision_model.encoder.layers.21.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
610
+ "model.vision_model.encoder.layers.22.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
611
+ "model.vision_model.encoder.layers.22.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
612
+ "model.vision_model.encoder.layers.22.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
613
+ "model.vision_model.encoder.layers.22.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
614
+ "model.vision_model.encoder.layers.22.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
615
+ "model.vision_model.encoder.layers.22.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
616
+ "model.vision_model.encoder.layers.22.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
617
+ "model.vision_model.encoder.layers.22.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
618
+ "model.vision_model.encoder.layers.22.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
619
+ "model.vision_model.encoder.layers.22.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
620
+ "model.vision_model.encoder.layers.22.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
621
+ "model.vision_model.encoder.layers.22.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
622
+ "model.vision_model.encoder.layers.23.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
623
+ "model.vision_model.encoder.layers.23.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
624
+ "model.vision_model.encoder.layers.23.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
625
+ "model.vision_model.encoder.layers.23.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
626
+ "model.vision_model.encoder.layers.23.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
627
+ "model.vision_model.encoder.layers.23.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
628
+ "model.vision_model.encoder.layers.23.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
629
+ "model.vision_model.encoder.layers.23.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
630
+ "model.vision_model.encoder.layers.23.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
631
+ "model.vision_model.encoder.layers.23.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
632
+ "model.vision_model.encoder.layers.23.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
633
+ "model.vision_model.encoder.layers.23.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
634
+ "model.vision_model.encoder.layers.3.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
635
+ "model.vision_model.encoder.layers.3.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
636
+ "model.vision_model.encoder.layers.3.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
637
+ "model.vision_model.encoder.layers.3.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
638
+ "model.vision_model.encoder.layers.3.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
639
+ "model.vision_model.encoder.layers.3.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
640
+ "model.vision_model.encoder.layers.3.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
641
+ "model.vision_model.encoder.layers.3.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
642
+ "model.vision_model.encoder.layers.3.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
643
+ "model.vision_model.encoder.layers.3.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
644
+ "model.vision_model.encoder.layers.3.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
645
+ "model.vision_model.encoder.layers.3.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
646
+ "model.vision_model.encoder.layers.4.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
647
+ "model.vision_model.encoder.layers.4.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
648
+ "model.vision_model.encoder.layers.4.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
649
+ "model.vision_model.encoder.layers.4.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
650
+ "model.vision_model.encoder.layers.4.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
651
+ "model.vision_model.encoder.layers.4.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
652
+ "model.vision_model.encoder.layers.4.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
653
+ "model.vision_model.encoder.layers.4.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
654
+ "model.vision_model.encoder.layers.4.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
655
+ "model.vision_model.encoder.layers.4.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
656
+ "model.vision_model.encoder.layers.4.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
657
+ "model.vision_model.encoder.layers.4.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
658
+ "model.vision_model.encoder.layers.5.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
659
+ "model.vision_model.encoder.layers.5.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
660
+ "model.vision_model.encoder.layers.5.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
661
+ "model.vision_model.encoder.layers.5.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
662
+ "model.vision_model.encoder.layers.5.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
663
+ "model.vision_model.encoder.layers.5.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
664
+ "model.vision_model.encoder.layers.5.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
665
+ "model.vision_model.encoder.layers.5.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
666
+ "model.vision_model.encoder.layers.5.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
667
+ "model.vision_model.encoder.layers.5.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
668
+ "model.vision_model.encoder.layers.5.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
669
+ "model.vision_model.encoder.layers.5.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
670
+ "model.vision_model.encoder.layers.6.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
671
+ "model.vision_model.encoder.layers.6.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
672
+ "model.vision_model.encoder.layers.6.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
673
+ "model.vision_model.encoder.layers.6.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
674
+ "model.vision_model.encoder.layers.6.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
675
+ "model.vision_model.encoder.layers.6.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
676
+ "model.vision_model.encoder.layers.6.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
677
+ "model.vision_model.encoder.layers.6.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
678
+ "model.vision_model.encoder.layers.6.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
679
+ "model.vision_model.encoder.layers.6.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
680
+ "model.vision_model.encoder.layers.6.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
681
+ "model.vision_model.encoder.layers.6.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
682
+ "model.vision_model.encoder.layers.7.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
683
+ "model.vision_model.encoder.layers.7.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
684
+ "model.vision_model.encoder.layers.7.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
685
+ "model.vision_model.encoder.layers.7.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
686
+ "model.vision_model.encoder.layers.7.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
687
+ "model.vision_model.encoder.layers.7.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
688
+ "model.vision_model.encoder.layers.7.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
689
+ "model.vision_model.encoder.layers.7.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
690
+ "model.vision_model.encoder.layers.7.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
691
+ "model.vision_model.encoder.layers.7.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
692
+ "model.vision_model.encoder.layers.7.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
693
+ "model.vision_model.encoder.layers.7.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
694
+ "model.vision_model.encoder.layers.8.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
695
+ "model.vision_model.encoder.layers.8.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
696
+ "model.vision_model.encoder.layers.8.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
697
+ "model.vision_model.encoder.layers.8.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
698
+ "model.vision_model.encoder.layers.8.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
699
+ "model.vision_model.encoder.layers.8.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
700
+ "model.vision_model.encoder.layers.8.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
701
+ "model.vision_model.encoder.layers.8.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
702
+ "model.vision_model.encoder.layers.8.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
703
+ "model.vision_model.encoder.layers.8.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
704
+ "model.vision_model.encoder.layers.8.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
705
+ "model.vision_model.encoder.layers.8.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
706
+ "model.vision_model.encoder.layers.9.input_layernorm.bias": "pytorch_model-00004-of-00004.bin",
707
+ "model.vision_model.encoder.layers.9.input_layernorm.weight": "pytorch_model-00004-of-00004.bin",
708
+ "model.vision_model.encoder.layers.9.mlp.fc1.bias": "pytorch_model-00004-of-00004.bin",
709
+ "model.vision_model.encoder.layers.9.mlp.fc1.weight": "pytorch_model-00004-of-00004.bin",
710
+ "model.vision_model.encoder.layers.9.mlp.fc2.bias": "pytorch_model-00004-of-00004.bin",
711
+ "model.vision_model.encoder.layers.9.mlp.fc2.weight": "pytorch_model-00004-of-00004.bin",
712
+ "model.vision_model.encoder.layers.9.post_attention_layernorm.bias": "pytorch_model-00004-of-00004.bin",
713
+ "model.vision_model.encoder.layers.9.post_attention_layernorm.weight": "pytorch_model-00004-of-00004.bin",
714
+ "model.vision_model.encoder.layers.9.self_attn.dense.bias": "pytorch_model-00004-of-00004.bin",
715
+ "model.vision_model.encoder.layers.9.self_attn.dense.weight": "pytorch_model-00004-of-00004.bin",
716
+ "model.vision_model.encoder.layers.9.self_attn.query_key_value.bias": "pytorch_model-00004-of-00004.bin",
717
+ "model.vision_model.encoder.layers.9.self_attn.query_key_value.weight": "pytorch_model-00004-of-00004.bin",
718
+ "model.vision_model.post_layernorm.bias": "pytorch_model-00004-of-00004.bin",
719
+ "model.vision_model.post_layernorm.weight": "pytorch_model-00004-of-00004.bin",
720
+ "model.visual_abstractor.encoder.layers.0.crossattention.attention.k_pos_embed": "pytorch_model-00004-of-00004.bin",
721
+ "model.visual_abstractor.encoder.layers.0.crossattention.attention.key.bias": "pytorch_model-00004-of-00004.bin",
722
+ "model.visual_abstractor.encoder.layers.0.crossattention.attention.key.weight": "pytorch_model-00004-of-00004.bin",
723
+ "model.visual_abstractor.encoder.layers.0.crossattention.attention.q_pos_embed": "pytorch_model-00004-of-00004.bin",
724
+ "model.visual_abstractor.encoder.layers.0.crossattention.attention.query.bias": "pytorch_model-00004-of-00004.bin",
725
+ "model.visual_abstractor.encoder.layers.0.crossattention.attention.query.weight": "pytorch_model-00004-of-00004.bin",
726
+ "model.visual_abstractor.encoder.layers.0.crossattention.attention.value.bias": "pytorch_model-00004-of-00004.bin",
727
+ "model.visual_abstractor.encoder.layers.0.crossattention.attention.value.weight": "pytorch_model-00004-of-00004.bin",
728
+ "model.visual_abstractor.encoder.layers.0.crossattention.norm1.bias": "pytorch_model-00004-of-00004.bin",
729
+ "model.visual_abstractor.encoder.layers.0.crossattention.norm1.weight": "pytorch_model-00004-of-00004.bin",
730
+ "model.visual_abstractor.encoder.layers.0.crossattention.normk.bias": "pytorch_model-00004-of-00004.bin",
731
+ "model.visual_abstractor.encoder.layers.0.crossattention.normk.weight": "pytorch_model-00004-of-00004.bin",
732
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.mlp.ffn_ln.bias": "pytorch_model-00004-of-00004.bin",
733
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.mlp.ffn_ln.weight": "pytorch_model-00004-of-00004.bin",
734
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.mlp.w1.bias": "pytorch_model-00004-of-00004.bin",
735
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.mlp.w1.weight": "pytorch_model-00004-of-00004.bin",
736
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.mlp.w2.bias": "pytorch_model-00004-of-00004.bin",
737
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.mlp.w2.weight": "pytorch_model-00004-of-00004.bin",
738
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.mlp.w3.bias": "pytorch_model-00004-of-00004.bin",
739
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.mlp.w3.weight": "pytorch_model-00004-of-00004.bin",
740
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.norm2.bias": "pytorch_model-00004-of-00004.bin",
741
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.norm2.weight": "pytorch_model-00004-of-00004.bin",
742
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.out_proj.bias": "pytorch_model-00004-of-00004.bin",
743
+ "model.visual_abstractor.encoder.layers.0.crossattention.output.out_proj.weight": "pytorch_model-00004-of-00004.bin",
744
+ "model.visual_abstractor.encoder.layers.1.crossattention.attention.k_pos_embed": "pytorch_model-00004-of-00004.bin",
745
+ "model.visual_abstractor.encoder.layers.1.crossattention.attention.key.bias": "pytorch_model-00004-of-00004.bin",
746
+ "model.visual_abstractor.encoder.layers.1.crossattention.attention.key.weight": "pytorch_model-00004-of-00004.bin",
747
+ "model.visual_abstractor.encoder.layers.1.crossattention.attention.q_pos_embed": "pytorch_model-00004-of-00004.bin",
748
+ "model.visual_abstractor.encoder.layers.1.crossattention.attention.query.bias": "pytorch_model-00004-of-00004.bin",
749
+ "model.visual_abstractor.encoder.layers.1.crossattention.attention.query.weight": "pytorch_model-00004-of-00004.bin",
750
+ "model.visual_abstractor.encoder.layers.1.crossattention.attention.value.bias": "pytorch_model-00004-of-00004.bin",
751
+ "model.visual_abstractor.encoder.layers.1.crossattention.attention.value.weight": "pytorch_model-00004-of-00004.bin",
752
+ "model.visual_abstractor.encoder.layers.1.crossattention.norm1.bias": "pytorch_model-00004-of-00004.bin",
753
+ "model.visual_abstractor.encoder.layers.1.crossattention.norm1.weight": "pytorch_model-00004-of-00004.bin",
754
+ "model.visual_abstractor.encoder.layers.1.crossattention.normk.bias": "pytorch_model-00004-of-00004.bin",
755
+ "model.visual_abstractor.encoder.layers.1.crossattention.normk.weight": "pytorch_model-00004-of-00004.bin",
756
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.mlp.ffn_ln.bias": "pytorch_model-00004-of-00004.bin",
757
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.mlp.ffn_ln.weight": "pytorch_model-00004-of-00004.bin",
758
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.mlp.w1.bias": "pytorch_model-00004-of-00004.bin",
759
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.mlp.w1.weight": "pytorch_model-00004-of-00004.bin",
760
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.mlp.w2.bias": "pytorch_model-00004-of-00004.bin",
761
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.mlp.w2.weight": "pytorch_model-00004-of-00004.bin",
762
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.mlp.w3.bias": "pytorch_model-00004-of-00004.bin",
763
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.mlp.w3.weight": "pytorch_model-00004-of-00004.bin",
764
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.norm2.bias": "pytorch_model-00004-of-00004.bin",
765
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.norm2.weight": "pytorch_model-00004-of-00004.bin",
766
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.out_proj.bias": "pytorch_model-00004-of-00004.bin",
767
+ "model.visual_abstractor.encoder.layers.1.crossattention.output.out_proj.weight": "pytorch_model-00004-of-00004.bin",
768
+ "model.visual_abstractor.encoder.layers.2.crossattention.attention.k_pos_embed": "pytorch_model-00004-of-00004.bin",
769
+ "model.visual_abstractor.encoder.layers.2.crossattention.attention.key.bias": "pytorch_model-00004-of-00004.bin",
770
+ "model.visual_abstractor.encoder.layers.2.crossattention.attention.key.weight": "pytorch_model-00004-of-00004.bin",
771
+ "model.visual_abstractor.encoder.layers.2.crossattention.attention.q_pos_embed": "pytorch_model-00004-of-00004.bin",
772
+ "model.visual_abstractor.encoder.layers.2.crossattention.attention.query.bias": "pytorch_model-00004-of-00004.bin",
773
+ "model.visual_abstractor.encoder.layers.2.crossattention.attention.query.weight": "pytorch_model-00004-of-00004.bin",
774
+ "model.visual_abstractor.encoder.layers.2.crossattention.attention.value.bias": "pytorch_model-00004-of-00004.bin",
775
+ "model.visual_abstractor.encoder.layers.2.crossattention.attention.value.weight": "pytorch_model-00004-of-00004.bin",
776
+ "model.visual_abstractor.encoder.layers.2.crossattention.norm1.bias": "pytorch_model-00004-of-00004.bin",
777
+ "model.visual_abstractor.encoder.layers.2.crossattention.norm1.weight": "pytorch_model-00004-of-00004.bin",
778
+ "model.visual_abstractor.encoder.layers.2.crossattention.normk.bias": "pytorch_model-00004-of-00004.bin",
779
+ "model.visual_abstractor.encoder.layers.2.crossattention.normk.weight": "pytorch_model-00004-of-00004.bin",
780
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.mlp.ffn_ln.bias": "pytorch_model-00004-of-00004.bin",
781
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.mlp.ffn_ln.weight": "pytorch_model-00004-of-00004.bin",
782
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.mlp.w1.bias": "pytorch_model-00004-of-00004.bin",
783
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.mlp.w1.weight": "pytorch_model-00004-of-00004.bin",
784
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.mlp.w2.bias": "pytorch_model-00004-of-00004.bin",
785
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.mlp.w2.weight": "pytorch_model-00004-of-00004.bin",
786
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.mlp.w3.bias": "pytorch_model-00004-of-00004.bin",
787
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.mlp.w3.weight": "pytorch_model-00004-of-00004.bin",
788
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.norm2.bias": "pytorch_model-00004-of-00004.bin",
789
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.norm2.weight": "pytorch_model-00004-of-00004.bin",
790
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.out_proj.bias": "pytorch_model-00004-of-00004.bin",
791
+ "model.visual_abstractor.encoder.layers.2.crossattention.output.out_proj.weight": "pytorch_model-00004-of-00004.bin",
792
+ "model.visual_abstractor.encoder.layers.3.crossattention.attention.k_pos_embed": "pytorch_model-00004-of-00004.bin",
793
+ "model.visual_abstractor.encoder.layers.3.crossattention.attention.key.bias": "pytorch_model-00004-of-00004.bin",
794
+ "model.visual_abstractor.encoder.layers.3.crossattention.attention.key.weight": "pytorch_model-00004-of-00004.bin",
795
+ "model.visual_abstractor.encoder.layers.3.crossattention.attention.q_pos_embed": "pytorch_model-00004-of-00004.bin",
796
+ "model.visual_abstractor.encoder.layers.3.crossattention.attention.query.bias": "pytorch_model-00004-of-00004.bin",
797
+ "model.visual_abstractor.encoder.layers.3.crossattention.attention.query.weight": "pytorch_model-00004-of-00004.bin",
798
+ "model.visual_abstractor.encoder.layers.3.crossattention.attention.value.bias": "pytorch_model-00004-of-00004.bin",
799
+ "model.visual_abstractor.encoder.layers.3.crossattention.attention.value.weight": "pytorch_model-00004-of-00004.bin",
800
+ "model.visual_abstractor.encoder.layers.3.crossattention.norm1.bias": "pytorch_model-00004-of-00004.bin",
801
+ "model.visual_abstractor.encoder.layers.3.crossattention.norm1.weight": "pytorch_model-00004-of-00004.bin",
802
+ "model.visual_abstractor.encoder.layers.3.crossattention.normk.bias": "pytorch_model-00004-of-00004.bin",
803
+ "model.visual_abstractor.encoder.layers.3.crossattention.normk.weight": "pytorch_model-00004-of-00004.bin",
804
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.mlp.ffn_ln.bias": "pytorch_model-00004-of-00004.bin",
805
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.mlp.ffn_ln.weight": "pytorch_model-00004-of-00004.bin",
806
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.mlp.w1.bias": "pytorch_model-00004-of-00004.bin",
807
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.mlp.w1.weight": "pytorch_model-00004-of-00004.bin",
808
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.mlp.w2.bias": "pytorch_model-00004-of-00004.bin",
809
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.mlp.w2.weight": "pytorch_model-00004-of-00004.bin",
810
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.mlp.w3.bias": "pytorch_model-00004-of-00004.bin",
811
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.mlp.w3.weight": "pytorch_model-00004-of-00004.bin",
812
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.norm2.bias": "pytorch_model-00004-of-00004.bin",
813
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.norm2.weight": "pytorch_model-00004-of-00004.bin",
814
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.out_proj.bias": "pytorch_model-00004-of-00004.bin",
815
+ "model.visual_abstractor.encoder.layers.3.crossattention.output.out_proj.weight": "pytorch_model-00004-of-00004.bin",
816
+ "model.visual_abstractor.encoder.layers.4.crossattention.attention.k_pos_embed": "pytorch_model-00004-of-00004.bin",
817
+ "model.visual_abstractor.encoder.layers.4.crossattention.attention.key.bias": "pytorch_model-00004-of-00004.bin",
818
+ "model.visual_abstractor.encoder.layers.4.crossattention.attention.key.weight": "pytorch_model-00004-of-00004.bin",
819
+ "model.visual_abstractor.encoder.layers.4.crossattention.attention.q_pos_embed": "pytorch_model-00004-of-00004.bin",
820
+ "model.visual_abstractor.encoder.layers.4.crossattention.attention.query.bias": "pytorch_model-00004-of-00004.bin",
821
+ "model.visual_abstractor.encoder.layers.4.crossattention.attention.query.weight": "pytorch_model-00004-of-00004.bin",
822
+ "model.visual_abstractor.encoder.layers.4.crossattention.attention.value.bias": "pytorch_model-00004-of-00004.bin",
823
+ "model.visual_abstractor.encoder.layers.4.crossattention.attention.value.weight": "pytorch_model-00004-of-00004.bin",
824
+ "model.visual_abstractor.encoder.layers.4.crossattention.norm1.bias": "pytorch_model-00004-of-00004.bin",
825
+ "model.visual_abstractor.encoder.layers.4.crossattention.norm1.weight": "pytorch_model-00004-of-00004.bin",
826
+ "model.visual_abstractor.encoder.layers.4.crossattention.normk.bias": "pytorch_model-00004-of-00004.bin",
827
+ "model.visual_abstractor.encoder.layers.4.crossattention.normk.weight": "pytorch_model-00004-of-00004.bin",
828
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.mlp.ffn_ln.bias": "pytorch_model-00004-of-00004.bin",
829
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.mlp.ffn_ln.weight": "pytorch_model-00004-of-00004.bin",
830
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.mlp.w1.bias": "pytorch_model-00004-of-00004.bin",
831
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.mlp.w1.weight": "pytorch_model-00004-of-00004.bin",
832
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.mlp.w2.bias": "pytorch_model-00004-of-00004.bin",
833
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.mlp.w2.weight": "pytorch_model-00004-of-00004.bin",
834
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.mlp.w3.bias": "pytorch_model-00004-of-00004.bin",
835
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.mlp.w3.weight": "pytorch_model-00004-of-00004.bin",
836
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.norm2.bias": "pytorch_model-00004-of-00004.bin",
837
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.norm2.weight": "pytorch_model-00004-of-00004.bin",
838
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.out_proj.bias": "pytorch_model-00004-of-00004.bin",
839
+ "model.visual_abstractor.encoder.layers.4.crossattention.output.out_proj.weight": "pytorch_model-00004-of-00004.bin",
840
+ "model.visual_abstractor.encoder.layers.5.crossattention.attention.k_pos_embed": "pytorch_model-00004-of-00004.bin",
841
+ "model.visual_abstractor.encoder.layers.5.crossattention.attention.key.bias": "pytorch_model-00004-of-00004.bin",
842
+ "model.visual_abstractor.encoder.layers.5.crossattention.attention.key.weight": "pytorch_model-00004-of-00004.bin",
843
+ "model.visual_abstractor.encoder.layers.5.crossattention.attention.q_pos_embed": "pytorch_model-00004-of-00004.bin",
844
+ "model.visual_abstractor.encoder.layers.5.crossattention.attention.query.bias": "pytorch_model-00004-of-00004.bin",
845
+ "model.visual_abstractor.encoder.layers.5.crossattention.attention.query.weight": "pytorch_model-00004-of-00004.bin",
846
+ "model.visual_abstractor.encoder.layers.5.crossattention.attention.value.bias": "pytorch_model-00004-of-00004.bin",
847
+ "model.visual_abstractor.encoder.layers.5.crossattention.attention.value.weight": "pytorch_model-00004-of-00004.bin",
848
+ "model.visual_abstractor.encoder.layers.5.crossattention.norm1.bias": "pytorch_model-00004-of-00004.bin",
849
+ "model.visual_abstractor.encoder.layers.5.crossattention.norm1.weight": "pytorch_model-00004-of-00004.bin",
850
+ "model.visual_abstractor.encoder.layers.5.crossattention.normk.bias": "pytorch_model-00004-of-00004.bin",
851
+ "model.visual_abstractor.encoder.layers.5.crossattention.normk.weight": "pytorch_model-00004-of-00004.bin",
852
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.mlp.ffn_ln.bias": "pytorch_model-00004-of-00004.bin",
853
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.mlp.ffn_ln.weight": "pytorch_model-00004-of-00004.bin",
854
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.mlp.w1.bias": "pytorch_model-00004-of-00004.bin",
855
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.mlp.w1.weight": "pytorch_model-00004-of-00004.bin",
856
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.mlp.w2.bias": "pytorch_model-00004-of-00004.bin",
857
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.mlp.w2.weight": "pytorch_model-00004-of-00004.bin",
858
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.mlp.w3.bias": "pytorch_model-00004-of-00004.bin",
859
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.mlp.w3.weight": "pytorch_model-00004-of-00004.bin",
860
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.norm2.bias": "pytorch_model-00004-of-00004.bin",
861
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.norm2.weight": "pytorch_model-00004-of-00004.bin",
862
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.out_proj.bias": "pytorch_model-00004-of-00004.bin",
863
+ "model.visual_abstractor.encoder.layers.5.crossattention.output.out_proj.weight": "pytorch_model-00004-of-00004.bin",
864
+ "model.visual_abstractor.query_embeds": "pytorch_model-00004-of-00004.bin",
865
+ "model.visual_abstractor.visual_fc.bias": "pytorch_model-00004-of-00004.bin",
866
+ "model.visual_abstractor.visual_fc.weight": "pytorch_model-00004-of-00004.bin",
867
+ "model.visual_abstractor.vit_eos": "pytorch_model-00004-of-00004.bin"
868
+ }
869
+ }
runs/Jun19_10-38-29_antfcutrn-kmaker-033145119198/events.out.tfevents.1750300731.antfcutrn-kmaker-033145119198.18341.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:139a2814d9a266e78a1f3e035a1ac2b48cd2966a690ac7b1a7427fd63911a891
3
+ size 62257
special_tokens_map.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": "<unk>",
17
+ "unk_token": {
18
+ "content": "<unk>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
3
+ size 499723
tokenizer_config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ }
29
+ },
30
+ "bos_token": "<s>",
31
+ "clean_up_tokenization_spaces": false,
32
+ "eos_token": "</s>",
33
+ "legacy": false,
34
+ "model_max_length": 2048,
35
+ "pad_token": "<unk>",
36
+ "padding_side": "right",
37
+ "sp_model_kwargs": {},
38
+ "spaces_between_special_tokens": false,
39
+ "tokenizer_class": "LlamaTokenizer",
40
+ "unk_token": "<unk>",
41
+ "use_default_system_prompt": false
42
+ }
trainer_state.json ADDED
@@ -0,0 +1,2010 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 3.0,
5
+ "eval_steps": 500,
6
+ "global_step": 330,
7
+ "is_hyper_param_search": false,
8
+ "is_local_process_zero": true,
9
+ "is_world_process_zero": true,
10
+ "log_history": [
11
+ {
12
+ "epoch": 0.01,
13
+ "learning_rate": 2.0000000000000003e-06,
14
+ "loss": 0.1273,
15
+ "step": 1
16
+ },
17
+ {
18
+ "epoch": 0.02,
19
+ "learning_rate": 4.000000000000001e-06,
20
+ "loss": 0.1438,
21
+ "step": 2
22
+ },
23
+ {
24
+ "epoch": 0.03,
25
+ "learning_rate": 6e-06,
26
+ "loss": 0.1274,
27
+ "step": 3
28
+ },
29
+ {
30
+ "epoch": 0.04,
31
+ "learning_rate": 8.000000000000001e-06,
32
+ "loss": 0.0856,
33
+ "step": 4
34
+ },
35
+ {
36
+ "epoch": 0.05,
37
+ "learning_rate": 1e-05,
38
+ "loss": 0.0508,
39
+ "step": 5
40
+ },
41
+ {
42
+ "epoch": 0.05,
43
+ "learning_rate": 1.2e-05,
44
+ "loss": 0.066,
45
+ "step": 6
46
+ },
47
+ {
48
+ "epoch": 0.06,
49
+ "learning_rate": 1.4e-05,
50
+ "loss": 0.0804,
51
+ "step": 7
52
+ },
53
+ {
54
+ "epoch": 0.07,
55
+ "learning_rate": 1.6000000000000003e-05,
56
+ "loss": 0.0526,
57
+ "step": 8
58
+ },
59
+ {
60
+ "epoch": 0.08,
61
+ "learning_rate": 1.8e-05,
62
+ "loss": 0.0692,
63
+ "step": 9
64
+ },
65
+ {
66
+ "epoch": 0.09,
67
+ "learning_rate": 2e-05,
68
+ "loss": 0.0485,
69
+ "step": 10
70
+ },
71
+ {
72
+ "epoch": 0.1,
73
+ "learning_rate": 1.999951808959328e-05,
74
+ "loss": 0.0363,
75
+ "step": 11
76
+ },
77
+ {
78
+ "epoch": 0.11,
79
+ "learning_rate": 1.9998072404820648e-05,
80
+ "loss": 0.0303,
81
+ "step": 12
82
+ },
83
+ {
84
+ "epoch": 0.12,
85
+ "learning_rate": 1.9995663085020215e-05,
86
+ "loss": 0.0527,
87
+ "step": 13
88
+ },
89
+ {
90
+ "epoch": 0.13,
91
+ "learning_rate": 1.9992290362407232e-05,
92
+ "loss": 0.0485,
93
+ "step": 14
94
+ },
95
+ {
96
+ "epoch": 0.14,
97
+ "learning_rate": 1.9987954562051724e-05,
98
+ "loss": 0.0726,
99
+ "step": 15
100
+ },
101
+ {
102
+ "epoch": 0.15,
103
+ "learning_rate": 1.998265610184716e-05,
104
+ "loss": 0.0379,
105
+ "step": 16
106
+ },
107
+ {
108
+ "epoch": 0.15,
109
+ "learning_rate": 1.997639549247016e-05,
110
+ "loss": 0.0427,
111
+ "step": 17
112
+ },
113
+ {
114
+ "epoch": 0.16,
115
+ "learning_rate": 1.9969173337331283e-05,
116
+ "loss": 0.0405,
117
+ "step": 18
118
+ },
119
+ {
120
+ "epoch": 0.17,
121
+ "learning_rate": 1.9960990332516875e-05,
122
+ "loss": 0.0359,
123
+ "step": 19
124
+ },
125
+ {
126
+ "epoch": 0.18,
127
+ "learning_rate": 1.995184726672197e-05,
128
+ "loss": 0.0284,
129
+ "step": 20
130
+ },
131
+ {
132
+ "epoch": 0.19,
133
+ "learning_rate": 1.9941745021174284e-05,
134
+ "loss": 0.033,
135
+ "step": 21
136
+ },
137
+ {
138
+ "epoch": 0.2,
139
+ "learning_rate": 1.9930684569549265e-05,
140
+ "loss": 0.0328,
141
+ "step": 22
142
+ },
143
+ {
144
+ "epoch": 0.21,
145
+ "learning_rate": 1.991866697787626e-05,
146
+ "loss": 0.022,
147
+ "step": 23
148
+ },
149
+ {
150
+ "epoch": 0.22,
151
+ "learning_rate": 1.990569340443577e-05,
152
+ "loss": 0.0374,
153
+ "step": 24
154
+ },
155
+ {
156
+ "epoch": 0.23,
157
+ "learning_rate": 1.989176509964781e-05,
158
+ "loss": 0.0214,
159
+ "step": 25
160
+ },
161
+ {
162
+ "epoch": 0.24,
163
+ "learning_rate": 1.9876883405951378e-05,
164
+ "loss": 0.0329,
165
+ "step": 26
166
+ },
167
+ {
168
+ "epoch": 0.25,
169
+ "learning_rate": 1.9861049757675087e-05,
170
+ "loss": 0.0114,
171
+ "step": 27
172
+ },
173
+ {
174
+ "epoch": 0.25,
175
+ "learning_rate": 1.9844265680898917e-05,
176
+ "loss": 0.0174,
177
+ "step": 28
178
+ },
179
+ {
180
+ "epoch": 0.26,
181
+ "learning_rate": 1.982653279330712e-05,
182
+ "loss": 0.0339,
183
+ "step": 29
184
+ },
185
+ {
186
+ "epoch": 0.27,
187
+ "learning_rate": 1.9807852804032306e-05,
188
+ "loss": 0.0477,
189
+ "step": 30
190
+ },
191
+ {
192
+ "epoch": 0.28,
193
+ "learning_rate": 1.9788227513490724e-05,
194
+ "loss": 0.0377,
195
+ "step": 31
196
+ },
197
+ {
198
+ "epoch": 0.29,
199
+ "learning_rate": 1.9767658813208725e-05,
200
+ "loss": 0.0261,
201
+ "step": 32
202
+ },
203
+ {
204
+ "epoch": 0.3,
205
+ "learning_rate": 1.974614868564045e-05,
206
+ "loss": 0.0397,
207
+ "step": 33
208
+ },
209
+ {
210
+ "epoch": 0.31,
211
+ "learning_rate": 1.9723699203976768e-05,
212
+ "loss": 0.0316,
213
+ "step": 34
214
+ },
215
+ {
216
+ "epoch": 0.32,
217
+ "learning_rate": 1.9700312531945444e-05,
218
+ "loss": 0.0323,
219
+ "step": 35
220
+ },
221
+ {
222
+ "epoch": 0.33,
223
+ "learning_rate": 1.96759909236026e-05,
224
+ "loss": 0.0264,
225
+ "step": 36
226
+ },
227
+ {
228
+ "epoch": 0.34,
229
+ "learning_rate": 1.9650736723115476e-05,
230
+ "loss": 0.0204,
231
+ "step": 37
232
+ },
233
+ {
234
+ "epoch": 0.35,
235
+ "learning_rate": 1.9624552364536472e-05,
236
+ "loss": 0.02,
237
+ "step": 38
238
+ },
239
+ {
240
+ "epoch": 0.35,
241
+ "learning_rate": 1.9597440371568576e-05,
242
+ "loss": 0.0189,
243
+ "step": 39
244
+ },
245
+ {
246
+ "epoch": 0.36,
247
+ "learning_rate": 1.956940335732209e-05,
248
+ "loss": 0.0277,
249
+ "step": 40
250
+ },
251
+ {
252
+ "epoch": 0.37,
253
+ "learning_rate": 1.9540444024062807e-05,
254
+ "loss": 0.0321,
255
+ "step": 41
256
+ },
257
+ {
258
+ "epoch": 0.38,
259
+ "learning_rate": 1.9510565162951538e-05,
260
+ "loss": 0.04,
261
+ "step": 42
262
+ },
263
+ {
264
+ "epoch": 0.39,
265
+ "learning_rate": 1.9479769653775107e-05,
266
+ "loss": 0.0308,
267
+ "step": 43
268
+ },
269
+ {
270
+ "epoch": 0.4,
271
+ "learning_rate": 1.944806046466878e-05,
272
+ "loss": 0.0235,
273
+ "step": 44
274
+ },
275
+ {
276
+ "epoch": 0.41,
277
+ "learning_rate": 1.941544065183021e-05,
278
+ "loss": 0.0185,
279
+ "step": 45
280
+ },
281
+ {
282
+ "epoch": 0.42,
283
+ "learning_rate": 1.9381913359224844e-05,
284
+ "loss": 0.0477,
285
+ "step": 46
286
+ },
287
+ {
288
+ "epoch": 0.43,
289
+ "learning_rate": 1.9347481818282927e-05,
290
+ "loss": 0.0353,
291
+ "step": 47
292
+ },
293
+ {
294
+ "epoch": 0.44,
295
+ "learning_rate": 1.9312149347588035e-05,
296
+ "loss": 0.0347,
297
+ "step": 48
298
+ },
299
+ {
300
+ "epoch": 0.45,
301
+ "learning_rate": 1.9275919352557242e-05,
302
+ "loss": 0.023,
303
+ "step": 49
304
+ },
305
+ {
306
+ "epoch": 0.45,
307
+ "learning_rate": 1.9238795325112867e-05,
308
+ "loss": 0.0752,
309
+ "step": 50
310
+ },
311
+ {
312
+ "epoch": 0.46,
313
+ "learning_rate": 1.920078084334595e-05,
314
+ "loss": 0.0305,
315
+ "step": 51
316
+ },
317
+ {
318
+ "epoch": 0.47,
319
+ "learning_rate": 1.916187957117136e-05,
320
+ "loss": 0.0216,
321
+ "step": 52
322
+ },
323
+ {
324
+ "epoch": 0.48,
325
+ "learning_rate": 1.9122095257974676e-05,
326
+ "loss": 0.0129,
327
+ "step": 53
328
+ },
329
+ {
330
+ "epoch": 0.49,
331
+ "learning_rate": 1.9081431738250815e-05,
332
+ "loss": 0.0225,
333
+ "step": 54
334
+ },
335
+ {
336
+ "epoch": 0.5,
337
+ "learning_rate": 1.9039892931234434e-05,
338
+ "loss": 0.022,
339
+ "step": 55
340
+ },
341
+ {
342
+ "epoch": 0.51,
343
+ "learning_rate": 1.8997482840522218e-05,
344
+ "loss": 0.0419,
345
+ "step": 56
346
+ },
347
+ {
348
+ "epoch": 0.52,
349
+ "learning_rate": 1.895420555368697e-05,
350
+ "loss": 0.0308,
351
+ "step": 57
352
+ },
353
+ {
354
+ "epoch": 0.53,
355
+ "learning_rate": 1.891006524188368e-05,
356
+ "loss": 0.0246,
357
+ "step": 58
358
+ },
359
+ {
360
+ "epoch": 0.54,
361
+ "learning_rate": 1.8865066159447468e-05,
362
+ "loss": 0.0446,
363
+ "step": 59
364
+ },
365
+ {
366
+ "epoch": 0.55,
367
+ "learning_rate": 1.881921264348355e-05,
368
+ "loss": 0.0255,
369
+ "step": 60
370
+ },
371
+ {
372
+ "epoch": 0.55,
373
+ "learning_rate": 1.8772509113449243e-05,
374
+ "loss": 0.0247,
375
+ "step": 61
376
+ },
377
+ {
378
+ "epoch": 0.56,
379
+ "learning_rate": 1.8724960070727974e-05,
380
+ "loss": 0.0189,
381
+ "step": 62
382
+ },
383
+ {
384
+ "epoch": 0.57,
385
+ "learning_rate": 1.8676570098195443e-05,
386
+ "loss": 0.0241,
387
+ "step": 63
388
+ },
389
+ {
390
+ "epoch": 0.58,
391
+ "learning_rate": 1.862734385977792e-05,
392
+ "loss": 0.0285,
393
+ "step": 64
394
+ },
395
+ {
396
+ "epoch": 0.59,
397
+ "learning_rate": 1.8577286100002723e-05,
398
+ "loss": 0.0266,
399
+ "step": 65
400
+ },
401
+ {
402
+ "epoch": 0.6,
403
+ "learning_rate": 1.8526401643540924e-05,
404
+ "loss": 0.0156,
405
+ "step": 66
406
+ },
407
+ {
408
+ "epoch": 0.61,
409
+ "learning_rate": 1.8474695394742345e-05,
410
+ "loss": 0.0188,
411
+ "step": 67
412
+ },
413
+ {
414
+ "epoch": 0.62,
415
+ "learning_rate": 1.8422172337162865e-05,
416
+ "loss": 0.0172,
417
+ "step": 68
418
+ },
419
+ {
420
+ "epoch": 0.63,
421
+ "learning_rate": 1.8368837533084092e-05,
422
+ "loss": 0.019,
423
+ "step": 69
424
+ },
425
+ {
426
+ "epoch": 0.64,
427
+ "learning_rate": 1.8314696123025456e-05,
428
+ "loss": 0.0165,
429
+ "step": 70
430
+ },
431
+ {
432
+ "epoch": 0.65,
433
+ "learning_rate": 1.825975332524873e-05,
434
+ "loss": 0.0179,
435
+ "step": 71
436
+ },
437
+ {
438
+ "epoch": 0.65,
439
+ "learning_rate": 1.8204014435255136e-05,
440
+ "loss": 0.0199,
441
+ "step": 72
442
+ },
443
+ {
444
+ "epoch": 0.66,
445
+ "learning_rate": 1.8147484825274895e-05,
446
+ "loss": 0.0377,
447
+ "step": 73
448
+ },
449
+ {
450
+ "epoch": 0.67,
451
+ "learning_rate": 1.8090169943749477e-05,
452
+ "loss": 0.0196,
453
+ "step": 74
454
+ },
455
+ {
456
+ "epoch": 0.68,
457
+ "learning_rate": 1.803207531480645e-05,
458
+ "loss": 0.0103,
459
+ "step": 75
460
+ },
461
+ {
462
+ "epoch": 0.69,
463
+ "learning_rate": 1.797320653772707e-05,
464
+ "loss": 0.0237,
465
+ "step": 76
466
+ },
467
+ {
468
+ "epoch": 0.7,
469
+ "learning_rate": 1.7913569286406606e-05,
470
+ "loss": 0.0238,
471
+ "step": 77
472
+ },
473
+ {
474
+ "epoch": 0.71,
475
+ "learning_rate": 1.785316930880745e-05,
476
+ "loss": 0.0182,
477
+ "step": 78
478
+ },
479
+ {
480
+ "epoch": 0.72,
481
+ "learning_rate": 1.779201242640517e-05,
482
+ "loss": 0.0171,
483
+ "step": 79
484
+ },
485
+ {
486
+ "epoch": 0.73,
487
+ "learning_rate": 1.773010453362737e-05,
488
+ "loss": 0.0256,
489
+ "step": 80
490
+ },
491
+ {
492
+ "epoch": 0.74,
493
+ "learning_rate": 1.7667451597285617e-05,
494
+ "loss": 0.0196,
495
+ "step": 81
496
+ },
497
+ {
498
+ "epoch": 0.75,
499
+ "learning_rate": 1.7604059656000313e-05,
500
+ "loss": 0.0221,
501
+ "step": 82
502
+ },
503
+ {
504
+ "epoch": 0.75,
505
+ "learning_rate": 1.7539934819618696e-05,
506
+ "loss": 0.0172,
507
+ "step": 83
508
+ },
509
+ {
510
+ "epoch": 0.76,
511
+ "learning_rate": 1.747508326862597e-05,
512
+ "loss": 0.0192,
513
+ "step": 84
514
+ },
515
+ {
516
+ "epoch": 0.77,
517
+ "learning_rate": 1.7409511253549592e-05,
518
+ "loss": 0.0141,
519
+ "step": 85
520
+ },
521
+ {
522
+ "epoch": 0.78,
523
+ "learning_rate": 1.7343225094356857e-05,
524
+ "loss": 0.0226,
525
+ "step": 86
526
+ },
527
+ {
528
+ "epoch": 0.79,
529
+ "learning_rate": 1.727623117984575e-05,
530
+ "loss": 0.0158,
531
+ "step": 87
532
+ },
533
+ {
534
+ "epoch": 0.8,
535
+ "learning_rate": 1.720853596702919e-05,
536
+ "loss": 0.0158,
537
+ "step": 88
538
+ },
539
+ {
540
+ "epoch": 0.81,
541
+ "learning_rate": 1.7140145980512684e-05,
542
+ "loss": 0.0186,
543
+ "step": 89
544
+ },
545
+ {
546
+ "epoch": 0.82,
547
+ "learning_rate": 1.7071067811865477e-05,
548
+ "loss": 0.0099,
549
+ "step": 90
550
+ },
551
+ {
552
+ "epoch": 0.83,
553
+ "learning_rate": 1.7001308118985237e-05,
554
+ "loss": 0.0174,
555
+ "step": 91
556
+ },
557
+ {
558
+ "epoch": 0.84,
559
+ "learning_rate": 1.6930873625456362e-05,
560
+ "loss": 0.0254,
561
+ "step": 92
562
+ },
563
+ {
564
+ "epoch": 0.85,
565
+ "learning_rate": 1.685977111990193e-05,
566
+ "loss": 0.0173,
567
+ "step": 93
568
+ },
569
+ {
570
+ "epoch": 0.85,
571
+ "learning_rate": 1.678800745532942e-05,
572
+ "loss": 0.0132,
573
+ "step": 94
574
+ },
575
+ {
576
+ "epoch": 0.86,
577
+ "learning_rate": 1.6715589548470187e-05,
578
+ "loss": 0.0118,
579
+ "step": 95
580
+ },
581
+ {
582
+ "epoch": 0.87,
583
+ "learning_rate": 1.664252437911282e-05,
584
+ "loss": 0.0159,
585
+ "step": 96
586
+ },
587
+ {
588
+ "epoch": 0.88,
589
+ "learning_rate": 1.6568818989430416e-05,
590
+ "loss": 0.0165,
591
+ "step": 97
592
+ },
593
+ {
594
+ "epoch": 0.89,
595
+ "learning_rate": 1.6494480483301836e-05,
596
+ "loss": 0.0167,
597
+ "step": 98
598
+ },
599
+ {
600
+ "epoch": 0.9,
601
+ "learning_rate": 1.641951602562703e-05,
602
+ "loss": 0.0083,
603
+ "step": 99
604
+ },
605
+ {
606
+ "epoch": 0.91,
607
+ "learning_rate": 1.6343932841636455e-05,
608
+ "loss": 0.0229,
609
+ "step": 100
610
+ },
611
+ {
612
+ "epoch": 0.92,
613
+ "learning_rate": 1.6267738216194698e-05,
614
+ "loss": 0.0202,
615
+ "step": 101
616
+ },
617
+ {
618
+ "epoch": 0.93,
619
+ "learning_rate": 1.6190939493098344e-05,
620
+ "loss": 0.0273,
621
+ "step": 102
622
+ },
623
+ {
624
+ "epoch": 0.94,
625
+ "learning_rate": 1.6113544074368166e-05,
626
+ "loss": 0.0117,
627
+ "step": 103
628
+ },
629
+ {
630
+ "epoch": 0.95,
631
+ "learning_rate": 1.6035559419535714e-05,
632
+ "loss": 0.0133,
633
+ "step": 104
634
+ },
635
+ {
636
+ "epoch": 0.95,
637
+ "learning_rate": 1.5956993044924334e-05,
638
+ "loss": 0.018,
639
+ "step": 105
640
+ },
641
+ {
642
+ "epoch": 0.96,
643
+ "learning_rate": 1.5877852522924733e-05,
644
+ "loss": 0.0175,
645
+ "step": 106
646
+ },
647
+ {
648
+ "epoch": 0.97,
649
+ "learning_rate": 1.579814548126514e-05,
650
+ "loss": 0.0255,
651
+ "step": 107
652
+ },
653
+ {
654
+ "epoch": 0.98,
655
+ "learning_rate": 1.5717879602276123e-05,
656
+ "loss": 0.0223,
657
+ "step": 108
658
+ },
659
+ {
660
+ "epoch": 0.99,
661
+ "learning_rate": 1.5637062622150168e-05,
662
+ "loss": 0.0218,
663
+ "step": 109
664
+ },
665
+ {
666
+ "epoch": 1.0,
667
+ "learning_rate": 1.5555702330196024e-05,
668
+ "loss": 0.0102,
669
+ "step": 110
670
+ },
671
+ {
672
+ "epoch": 1.01,
673
+ "learning_rate": 1.547380656808797e-05,
674
+ "loss": 0.0127,
675
+ "step": 111
676
+ },
677
+ {
678
+ "epoch": 1.02,
679
+ "learning_rate": 1.5391383229110005e-05,
680
+ "loss": 0.017,
681
+ "step": 112
682
+ },
683
+ {
684
+ "epoch": 1.03,
685
+ "learning_rate": 1.5308440257395095e-05,
686
+ "loss": 0.0184,
687
+ "step": 113
688
+ },
689
+ {
690
+ "epoch": 1.04,
691
+ "learning_rate": 1.5224985647159489e-05,
692
+ "loss": 0.0077,
693
+ "step": 114
694
+ },
695
+ {
696
+ "epoch": 1.05,
697
+ "learning_rate": 1.5141027441932217e-05,
698
+ "loss": 0.0139,
699
+ "step": 115
700
+ },
701
+ {
702
+ "epoch": 1.05,
703
+ "learning_rate": 1.5056573733779848e-05,
704
+ "loss": 0.0109,
705
+ "step": 116
706
+ },
707
+ {
708
+ "epoch": 1.06,
709
+ "learning_rate": 1.4971632662526545e-05,
710
+ "loss": 0.0146,
711
+ "step": 117
712
+ },
713
+ {
714
+ "epoch": 1.07,
715
+ "learning_rate": 1.4886212414969551e-05,
716
+ "loss": 0.0187,
717
+ "step": 118
718
+ },
719
+ {
720
+ "epoch": 1.08,
721
+ "learning_rate": 1.4800321224090114e-05,
722
+ "loss": 0.019,
723
+ "step": 119
724
+ },
725
+ {
726
+ "epoch": 1.09,
727
+ "learning_rate": 1.4713967368259981e-05,
728
+ "loss": 0.0103,
729
+ "step": 120
730
+ },
731
+ {
732
+ "epoch": 1.1,
733
+ "learning_rate": 1.4627159170443504e-05,
734
+ "loss": 0.0164,
735
+ "step": 121
736
+ },
737
+ {
738
+ "epoch": 1.11,
739
+ "learning_rate": 1.4539904997395468e-05,
740
+ "loss": 0.0131,
741
+ "step": 122
742
+ },
743
+ {
744
+ "epoch": 1.12,
745
+ "learning_rate": 1.4452213258854684e-05,
746
+ "loss": 0.0172,
747
+ "step": 123
748
+ },
749
+ {
750
+ "epoch": 1.13,
751
+ "learning_rate": 1.436409240673342e-05,
752
+ "loss": 0.0125,
753
+ "step": 124
754
+ },
755
+ {
756
+ "epoch": 1.14,
757
+ "learning_rate": 1.4275550934302822e-05,
758
+ "loss": 0.0102,
759
+ "step": 125
760
+ },
761
+ {
762
+ "epoch": 1.15,
763
+ "learning_rate": 1.4186597375374283e-05,
764
+ "loss": 0.0134,
765
+ "step": 126
766
+ },
767
+ {
768
+ "epoch": 1.15,
769
+ "learning_rate": 1.4097240303476955e-05,
770
+ "loss": 0.0067,
771
+ "step": 127
772
+ },
773
+ {
774
+ "epoch": 1.16,
775
+ "learning_rate": 1.4007488331031409e-05,
776
+ "loss": 0.0096,
777
+ "step": 128
778
+ },
779
+ {
780
+ "epoch": 1.17,
781
+ "learning_rate": 1.391735010851956e-05,
782
+ "loss": 0.0154,
783
+ "step": 129
784
+ },
785
+ {
786
+ "epoch": 1.18,
787
+ "learning_rate": 1.3826834323650899e-05,
788
+ "loss": 0.0188,
789
+ "step": 130
790
+ },
791
+ {
792
+ "epoch": 1.19,
793
+ "learning_rate": 1.3735949700525164e-05,
794
+ "loss": 0.008,
795
+ "step": 131
796
+ },
797
+ {
798
+ "epoch": 1.2,
799
+ "learning_rate": 1.3644704998791501e-05,
800
+ "loss": 0.0139,
801
+ "step": 132
802
+ },
803
+ {
804
+ "epoch": 1.21,
805
+ "learning_rate": 1.3553109012804162e-05,
806
+ "loss": 0.0111,
807
+ "step": 133
808
+ },
809
+ {
810
+ "epoch": 1.22,
811
+ "learning_rate": 1.346117057077493e-05,
812
+ "loss": 0.0136,
813
+ "step": 134
814
+ },
815
+ {
816
+ "epoch": 1.23,
817
+ "learning_rate": 1.3368898533922202e-05,
818
+ "loss": 0.012,
819
+ "step": 135
820
+ },
821
+ {
822
+ "epoch": 1.24,
823
+ "learning_rate": 1.3276301795616937e-05,
824
+ "loss": 0.0181,
825
+ "step": 136
826
+ },
827
+ {
828
+ "epoch": 1.25,
829
+ "learning_rate": 1.3183389280525497e-05,
830
+ "loss": 0.012,
831
+ "step": 137
832
+ },
833
+ {
834
+ "epoch": 1.25,
835
+ "learning_rate": 1.3090169943749475e-05,
836
+ "loss": 0.0085,
837
+ "step": 138
838
+ },
839
+ {
840
+ "epoch": 1.26,
841
+ "learning_rate": 1.2996652769962567e-05,
842
+ "loss": 0.0107,
843
+ "step": 139
844
+ },
845
+ {
846
+ "epoch": 1.27,
847
+ "learning_rate": 1.2902846772544625e-05,
848
+ "loss": 0.015,
849
+ "step": 140
850
+ },
851
+ {
852
+ "epoch": 1.28,
853
+ "learning_rate": 1.2808760992712923e-05,
854
+ "loss": 0.0152,
855
+ "step": 141
856
+ },
857
+ {
858
+ "epoch": 1.29,
859
+ "learning_rate": 1.2714404498650743e-05,
860
+ "loss": 0.0126,
861
+ "step": 142
862
+ },
863
+ {
864
+ "epoch": 1.3,
865
+ "learning_rate": 1.2619786384633374e-05,
866
+ "loss": 0.0086,
867
+ "step": 143
868
+ },
869
+ {
870
+ "epoch": 1.31,
871
+ "learning_rate": 1.252491577015158e-05,
872
+ "loss": 0.0121,
873
+ "step": 144
874
+ },
875
+ {
876
+ "epoch": 1.32,
877
+ "learning_rate": 1.242980179903264e-05,
878
+ "loss": 0.0146,
879
+ "step": 145
880
+ },
881
+ {
882
+ "epoch": 1.33,
883
+ "learning_rate": 1.2334453638559057e-05,
884
+ "loss": 0.0146,
885
+ "step": 146
886
+ },
887
+ {
888
+ "epoch": 1.34,
889
+ "learning_rate": 1.2238880478584987e-05,
890
+ "loss": 0.014,
891
+ "step": 147
892
+ },
893
+ {
894
+ "epoch": 1.35,
895
+ "learning_rate": 1.2143091530650508e-05,
896
+ "loss": 0.0207,
897
+ "step": 148
898
+ },
899
+ {
900
+ "epoch": 1.35,
901
+ "learning_rate": 1.2047096027093798e-05,
902
+ "loss": 0.0166,
903
+ "step": 149
904
+ },
905
+ {
906
+ "epoch": 1.36,
907
+ "learning_rate": 1.1950903220161286e-05,
908
+ "loss": 0.015,
909
+ "step": 150
910
+ },
911
+ {
912
+ "epoch": 1.37,
913
+ "learning_rate": 1.185452238111591e-05,
914
+ "loss": 0.0115,
915
+ "step": 151
916
+ },
917
+ {
918
+ "epoch": 1.38,
919
+ "learning_rate": 1.1757962799343548e-05,
920
+ "loss": 0.0081,
921
+ "step": 152
922
+ },
923
+ {
924
+ "epoch": 1.39,
925
+ "learning_rate": 1.1661233781457655e-05,
926
+ "loss": 0.0164,
927
+ "step": 153
928
+ },
929
+ {
930
+ "epoch": 1.4,
931
+ "learning_rate": 1.156434465040231e-05,
932
+ "loss": 0.0108,
933
+ "step": 154
934
+ },
935
+ {
936
+ "epoch": 1.41,
937
+ "learning_rate": 1.1467304744553618e-05,
938
+ "loss": 0.021,
939
+ "step": 155
940
+ },
941
+ {
942
+ "epoch": 1.42,
943
+ "learning_rate": 1.1370123416819683e-05,
944
+ "loss": 0.0187,
945
+ "step": 156
946
+ },
947
+ {
948
+ "epoch": 1.43,
949
+ "learning_rate": 1.1272810033739134e-05,
950
+ "loss": 0.0178,
951
+ "step": 157
952
+ },
953
+ {
954
+ "epoch": 1.44,
955
+ "learning_rate": 1.1175373974578378e-05,
956
+ "loss": 0.0195,
957
+ "step": 158
958
+ },
959
+ {
960
+ "epoch": 1.45,
961
+ "learning_rate": 1.1077824630427593e-05,
962
+ "loss": 0.016,
963
+ "step": 159
964
+ },
965
+ {
966
+ "epoch": 1.45,
967
+ "learning_rate": 1.098017140329561e-05,
968
+ "loss": 0.0226,
969
+ "step": 160
970
+ },
971
+ {
972
+ "epoch": 1.46,
973
+ "learning_rate": 1.0882423705203698e-05,
974
+ "loss": 0.0187,
975
+ "step": 161
976
+ },
977
+ {
978
+ "epoch": 1.47,
979
+ "learning_rate": 1.0784590957278452e-05,
980
+ "loss": 0.0122,
981
+ "step": 162
982
+ },
983
+ {
984
+ "epoch": 1.48,
985
+ "learning_rate": 1.0686682588843737e-05,
986
+ "loss": 0.0073,
987
+ "step": 163
988
+ },
989
+ {
990
+ "epoch": 1.49,
991
+ "learning_rate": 1.058870803651189e-05,
992
+ "loss": 0.0102,
993
+ "step": 164
994
+ },
995
+ {
996
+ "epoch": 1.5,
997
+ "learning_rate": 1.0490676743274181e-05,
998
+ "loss": 0.0076,
999
+ "step": 165
1000
+ },
1001
+ {
1002
+ "epoch": 1.51,
1003
+ "learning_rate": 1.0392598157590687e-05,
1004
+ "loss": 0.011,
1005
+ "step": 166
1006
+ },
1007
+ {
1008
+ "epoch": 1.52,
1009
+ "learning_rate": 1.0294481732479635e-05,
1010
+ "loss": 0.02,
1011
+ "step": 167
1012
+ },
1013
+ {
1014
+ "epoch": 1.53,
1015
+ "learning_rate": 1.0196336924606282e-05,
1016
+ "loss": 0.0186,
1017
+ "step": 168
1018
+ },
1019
+ {
1020
+ "epoch": 1.54,
1021
+ "learning_rate": 1.0098173193371498e-05,
1022
+ "loss": 0.0133,
1023
+ "step": 169
1024
+ },
1025
+ {
1026
+ "epoch": 1.55,
1027
+ "learning_rate": 1e-05,
1028
+ "loss": 0.0128,
1029
+ "step": 170
1030
+ },
1031
+ {
1032
+ "epoch": 1.55,
1033
+ "learning_rate": 9.901826806628505e-06,
1034
+ "loss": 0.0067,
1035
+ "step": 171
1036
+ },
1037
+ {
1038
+ "epoch": 1.56,
1039
+ "learning_rate": 9.80366307539372e-06,
1040
+ "loss": 0.0052,
1041
+ "step": 172
1042
+ },
1043
+ {
1044
+ "epoch": 1.57,
1045
+ "learning_rate": 9.705518267520369e-06,
1046
+ "loss": 0.0105,
1047
+ "step": 173
1048
+ },
1049
+ {
1050
+ "epoch": 1.58,
1051
+ "learning_rate": 9.607401842409318e-06,
1052
+ "loss": 0.0089,
1053
+ "step": 174
1054
+ },
1055
+ {
1056
+ "epoch": 1.59,
1057
+ "learning_rate": 9.50932325672582e-06,
1058
+ "loss": 0.0071,
1059
+ "step": 175
1060
+ },
1061
+ {
1062
+ "epoch": 1.6,
1063
+ "learning_rate": 9.41129196348811e-06,
1064
+ "loss": 0.0082,
1065
+ "step": 176
1066
+ },
1067
+ {
1068
+ "epoch": 1.61,
1069
+ "learning_rate": 9.313317411156265e-06,
1070
+ "loss": 0.0122,
1071
+ "step": 177
1072
+ },
1073
+ {
1074
+ "epoch": 1.62,
1075
+ "learning_rate": 9.215409042721553e-06,
1076
+ "loss": 0.0077,
1077
+ "step": 178
1078
+ },
1079
+ {
1080
+ "epoch": 1.63,
1081
+ "learning_rate": 9.117576294796307e-06,
1082
+ "loss": 0.0084,
1083
+ "step": 179
1084
+ },
1085
+ {
1086
+ "epoch": 1.64,
1087
+ "learning_rate": 9.019828596704394e-06,
1088
+ "loss": 0.0099,
1089
+ "step": 180
1090
+ },
1091
+ {
1092
+ "epoch": 1.65,
1093
+ "learning_rate": 8.922175369572407e-06,
1094
+ "loss": 0.0085,
1095
+ "step": 181
1096
+ },
1097
+ {
1098
+ "epoch": 1.65,
1099
+ "learning_rate": 8.824626025421625e-06,
1100
+ "loss": 0.005,
1101
+ "step": 182
1102
+ },
1103
+ {
1104
+ "epoch": 1.66,
1105
+ "learning_rate": 8.72718996626087e-06,
1106
+ "loss": 0.0068,
1107
+ "step": 183
1108
+ },
1109
+ {
1110
+ "epoch": 1.67,
1111
+ "learning_rate": 8.629876583180322e-06,
1112
+ "loss": 0.0124,
1113
+ "step": 184
1114
+ },
1115
+ {
1116
+ "epoch": 1.68,
1117
+ "learning_rate": 8.532695255446384e-06,
1118
+ "loss": 0.0093,
1119
+ "step": 185
1120
+ },
1121
+ {
1122
+ "epoch": 1.69,
1123
+ "learning_rate": 8.43565534959769e-06,
1124
+ "loss": 0.0175,
1125
+ "step": 186
1126
+ },
1127
+ {
1128
+ "epoch": 1.7,
1129
+ "learning_rate": 8.338766218542348e-06,
1130
+ "loss": 0.0053,
1131
+ "step": 187
1132
+ },
1133
+ {
1134
+ "epoch": 1.71,
1135
+ "learning_rate": 8.242037200656455e-06,
1136
+ "loss": 0.0145,
1137
+ "step": 188
1138
+ },
1139
+ {
1140
+ "epoch": 1.72,
1141
+ "learning_rate": 8.145477618884092e-06,
1142
+ "loss": 0.0096,
1143
+ "step": 189
1144
+ },
1145
+ {
1146
+ "epoch": 1.73,
1147
+ "learning_rate": 8.04909677983872e-06,
1148
+ "loss": 0.0076,
1149
+ "step": 190
1150
+ },
1151
+ {
1152
+ "epoch": 1.74,
1153
+ "learning_rate": 7.952903972906205e-06,
1154
+ "loss": 0.0092,
1155
+ "step": 191
1156
+ },
1157
+ {
1158
+ "epoch": 1.75,
1159
+ "learning_rate": 7.856908469349495e-06,
1160
+ "loss": 0.0113,
1161
+ "step": 192
1162
+ },
1163
+ {
1164
+ "epoch": 1.75,
1165
+ "learning_rate": 7.761119521415017e-06,
1166
+ "loss": 0.007,
1167
+ "step": 193
1168
+ },
1169
+ {
1170
+ "epoch": 1.76,
1171
+ "learning_rate": 7.66554636144095e-06,
1172
+ "loss": 0.0144,
1173
+ "step": 194
1174
+ },
1175
+ {
1176
+ "epoch": 1.77,
1177
+ "learning_rate": 7.570198200967363e-06,
1178
+ "loss": 0.0088,
1179
+ "step": 195
1180
+ },
1181
+ {
1182
+ "epoch": 1.78,
1183
+ "learning_rate": 7.4750842298484205e-06,
1184
+ "loss": 0.0063,
1185
+ "step": 196
1186
+ },
1187
+ {
1188
+ "epoch": 1.79,
1189
+ "learning_rate": 7.380213615366627e-06,
1190
+ "loss": 0.0083,
1191
+ "step": 197
1192
+ },
1193
+ {
1194
+ "epoch": 1.8,
1195
+ "learning_rate": 7.285595501349259e-06,
1196
+ "loss": 0.0095,
1197
+ "step": 198
1198
+ },
1199
+ {
1200
+ "epoch": 1.81,
1201
+ "learning_rate": 7.191239007287082e-06,
1202
+ "loss": 0.0042,
1203
+ "step": 199
1204
+ },
1205
+ {
1206
+ "epoch": 1.82,
1207
+ "learning_rate": 7.097153227455379e-06,
1208
+ "loss": 0.0081,
1209
+ "step": 200
1210
+ },
1211
+ {
1212
+ "epoch": 1.83,
1213
+ "learning_rate": 7.003347230037434e-06,
1214
+ "loss": 0.0102,
1215
+ "step": 201
1216
+ },
1217
+ {
1218
+ "epoch": 1.84,
1219
+ "learning_rate": 6.909830056250527e-06,
1220
+ "loss": 0.0049,
1221
+ "step": 202
1222
+ },
1223
+ {
1224
+ "epoch": 1.85,
1225
+ "learning_rate": 6.816610719474503e-06,
1226
+ "loss": 0.0084,
1227
+ "step": 203
1228
+ },
1229
+ {
1230
+ "epoch": 1.85,
1231
+ "learning_rate": 6.723698204383067e-06,
1232
+ "loss": 0.0091,
1233
+ "step": 204
1234
+ },
1235
+ {
1236
+ "epoch": 1.86,
1237
+ "learning_rate": 6.631101466077801e-06,
1238
+ "loss": 0.0084,
1239
+ "step": 205
1240
+ },
1241
+ {
1242
+ "epoch": 1.87,
1243
+ "learning_rate": 6.538829429225068e-06,
1244
+ "loss": 0.0124,
1245
+ "step": 206
1246
+ },
1247
+ {
1248
+ "epoch": 1.88,
1249
+ "learning_rate": 6.446890987195842e-06,
1250
+ "loss": 0.0051,
1251
+ "step": 207
1252
+ },
1253
+ {
1254
+ "epoch": 1.89,
1255
+ "learning_rate": 6.355295001208504e-06,
1256
+ "loss": 0.0047,
1257
+ "step": 208
1258
+ },
1259
+ {
1260
+ "epoch": 1.9,
1261
+ "learning_rate": 6.2640502994748375e-06,
1262
+ "loss": 0.0135,
1263
+ "step": 209
1264
+ },
1265
+ {
1266
+ "epoch": 1.91,
1267
+ "learning_rate": 6.173165676349103e-06,
1268
+ "loss": 0.0095,
1269
+ "step": 210
1270
+ },
1271
+ {
1272
+ "epoch": 1.92,
1273
+ "learning_rate": 6.082649891480441e-06,
1274
+ "loss": 0.0051,
1275
+ "step": 211
1276
+ },
1277
+ {
1278
+ "epoch": 1.93,
1279
+ "learning_rate": 5.9925116689685925e-06,
1280
+ "loss": 0.0076,
1281
+ "step": 212
1282
+ },
1283
+ {
1284
+ "epoch": 1.94,
1285
+ "learning_rate": 5.902759696523046e-06,
1286
+ "loss": 0.0051,
1287
+ "step": 213
1288
+ },
1289
+ {
1290
+ "epoch": 1.95,
1291
+ "learning_rate": 5.813402624625722e-06,
1292
+ "loss": 0.0066,
1293
+ "step": 214
1294
+ },
1295
+ {
1296
+ "epoch": 1.95,
1297
+ "learning_rate": 5.724449065697182e-06,
1298
+ "loss": 0.0097,
1299
+ "step": 215
1300
+ },
1301
+ {
1302
+ "epoch": 1.96,
1303
+ "learning_rate": 5.635907593266578e-06,
1304
+ "loss": 0.0094,
1305
+ "step": 216
1306
+ },
1307
+ {
1308
+ "epoch": 1.97,
1309
+ "learning_rate": 5.54778674114532e-06,
1310
+ "loss": 0.0093,
1311
+ "step": 217
1312
+ },
1313
+ {
1314
+ "epoch": 1.98,
1315
+ "learning_rate": 5.460095002604533e-06,
1316
+ "loss": 0.0089,
1317
+ "step": 218
1318
+ },
1319
+ {
1320
+ "epoch": 1.99,
1321
+ "learning_rate": 5.3728408295565e-06,
1322
+ "loss": 0.0063,
1323
+ "step": 219
1324
+ },
1325
+ {
1326
+ "epoch": 2.0,
1327
+ "learning_rate": 5.286032631740023e-06,
1328
+ "loss": 0.0063,
1329
+ "step": 220
1330
+ },
1331
+ {
1332
+ "epoch": 2.01,
1333
+ "learning_rate": 5.199678775909889e-06,
1334
+ "loss": 0.0052,
1335
+ "step": 221
1336
+ },
1337
+ {
1338
+ "epoch": 2.02,
1339
+ "learning_rate": 5.1137875850304545e-06,
1340
+ "loss": 0.007,
1341
+ "step": 222
1342
+ },
1343
+ {
1344
+ "epoch": 2.03,
1345
+ "learning_rate": 5.0283673374734546e-06,
1346
+ "loss": 0.0058,
1347
+ "step": 223
1348
+ },
1349
+ {
1350
+ "epoch": 2.04,
1351
+ "learning_rate": 4.943426266220156e-06,
1352
+ "loss": 0.0046,
1353
+ "step": 224
1354
+ },
1355
+ {
1356
+ "epoch": 2.05,
1357
+ "learning_rate": 4.858972558067784e-06,
1358
+ "loss": 0.0056,
1359
+ "step": 225
1360
+ },
1361
+ {
1362
+ "epoch": 2.05,
1363
+ "learning_rate": 4.775014352840512e-06,
1364
+ "loss": 0.0092,
1365
+ "step": 226
1366
+ },
1367
+ {
1368
+ "epoch": 2.06,
1369
+ "learning_rate": 4.691559742604906e-06,
1370
+ "loss": 0.0068,
1371
+ "step": 227
1372
+ },
1373
+ {
1374
+ "epoch": 2.07,
1375
+ "learning_rate": 4.608616770889998e-06,
1376
+ "loss": 0.0071,
1377
+ "step": 228
1378
+ },
1379
+ {
1380
+ "epoch": 2.08,
1381
+ "learning_rate": 4.526193431912038e-06,
1382
+ "loss": 0.0052,
1383
+ "step": 229
1384
+ },
1385
+ {
1386
+ "epoch": 2.09,
1387
+ "learning_rate": 4.444297669803981e-06,
1388
+ "loss": 0.0092,
1389
+ "step": 230
1390
+ },
1391
+ {
1392
+ "epoch": 2.1,
1393
+ "learning_rate": 4.362937377849832e-06,
1394
+ "loss": 0.0091,
1395
+ "step": 231
1396
+ },
1397
+ {
1398
+ "epoch": 2.11,
1399
+ "learning_rate": 4.282120397723879e-06,
1400
+ "loss": 0.0053,
1401
+ "step": 232
1402
+ },
1403
+ {
1404
+ "epoch": 2.12,
1405
+ "learning_rate": 4.2018545187348645e-06,
1406
+ "loss": 0.0068,
1407
+ "step": 233
1408
+ },
1409
+ {
1410
+ "epoch": 2.13,
1411
+ "learning_rate": 4.12214747707527e-06,
1412
+ "loss": 0.0049,
1413
+ "step": 234
1414
+ },
1415
+ {
1416
+ "epoch": 2.14,
1417
+ "learning_rate": 4.043006955075667e-06,
1418
+ "loss": 0.0046,
1419
+ "step": 235
1420
+ },
1421
+ {
1422
+ "epoch": 2.15,
1423
+ "learning_rate": 3.964440580464286e-06,
1424
+ "loss": 0.0084,
1425
+ "step": 236
1426
+ },
1427
+ {
1428
+ "epoch": 2.15,
1429
+ "learning_rate": 3.8864559256318375e-06,
1430
+ "loss": 0.0073,
1431
+ "step": 237
1432
+ },
1433
+ {
1434
+ "epoch": 2.16,
1435
+ "learning_rate": 3.8090605069016596e-06,
1436
+ "loss": 0.0057,
1437
+ "step": 238
1438
+ },
1439
+ {
1440
+ "epoch": 2.17,
1441
+ "learning_rate": 3.7322617838053066e-06,
1442
+ "loss": 0.0069,
1443
+ "step": 239
1444
+ },
1445
+ {
1446
+ "epoch": 2.18,
1447
+ "learning_rate": 3.6560671583635467e-06,
1448
+ "loss": 0.0039,
1449
+ "step": 240
1450
+ },
1451
+ {
1452
+ "epoch": 2.19,
1453
+ "learning_rate": 3.58048397437297e-06,
1454
+ "loss": 0.0044,
1455
+ "step": 241
1456
+ },
1457
+ {
1458
+ "epoch": 2.2,
1459
+ "learning_rate": 3.505519516698165e-06,
1460
+ "loss": 0.0095,
1461
+ "step": 242
1462
+ },
1463
+ {
1464
+ "epoch": 2.21,
1465
+ "learning_rate": 3.4311810105695875e-06,
1466
+ "loss": 0.0046,
1467
+ "step": 243
1468
+ },
1469
+ {
1470
+ "epoch": 2.22,
1471
+ "learning_rate": 3.3574756208871862e-06,
1472
+ "loss": 0.0061,
1473
+ "step": 244
1474
+ },
1475
+ {
1476
+ "epoch": 2.23,
1477
+ "learning_rate": 3.284410451529816e-06,
1478
+ "loss": 0.0041,
1479
+ "step": 245
1480
+ },
1481
+ {
1482
+ "epoch": 2.24,
1483
+ "learning_rate": 3.2119925446705824e-06,
1484
+ "loss": 0.0065,
1485
+ "step": 246
1486
+ },
1487
+ {
1488
+ "epoch": 2.25,
1489
+ "learning_rate": 3.140228880098074e-06,
1490
+ "loss": 0.0044,
1491
+ "step": 247
1492
+ },
1493
+ {
1494
+ "epoch": 2.25,
1495
+ "learning_rate": 3.069126374543643e-06,
1496
+ "loss": 0.0046,
1497
+ "step": 248
1498
+ },
1499
+ {
1500
+ "epoch": 2.26,
1501
+ "learning_rate": 2.998691881014765e-06,
1502
+ "loss": 0.0072,
1503
+ "step": 249
1504
+ },
1505
+ {
1506
+ "epoch": 2.27,
1507
+ "learning_rate": 2.9289321881345257e-06,
1508
+ "loss": 0.0054,
1509
+ "step": 250
1510
+ },
1511
+ {
1512
+ "epoch": 2.28,
1513
+ "learning_rate": 2.859854019487318e-06,
1514
+ "loss": 0.0087,
1515
+ "step": 251
1516
+ },
1517
+ {
1518
+ "epoch": 2.29,
1519
+ "learning_rate": 2.791464032970812e-06,
1520
+ "loss": 0.0049,
1521
+ "step": 252
1522
+ },
1523
+ {
1524
+ "epoch": 2.3,
1525
+ "learning_rate": 2.723768820154251e-06,
1526
+ "loss": 0.0065,
1527
+ "step": 253
1528
+ },
1529
+ {
1530
+ "epoch": 2.31,
1531
+ "learning_rate": 2.656774905643147e-06,
1532
+ "loss": 0.0061,
1533
+ "step": 254
1534
+ },
1535
+ {
1536
+ "epoch": 2.32,
1537
+ "learning_rate": 2.5904887464504115e-06,
1538
+ "loss": 0.0047,
1539
+ "step": 255
1540
+ },
1541
+ {
1542
+ "epoch": 2.33,
1543
+ "learning_rate": 2.5249167313740307e-06,
1544
+ "loss": 0.0048,
1545
+ "step": 256
1546
+ },
1547
+ {
1548
+ "epoch": 2.34,
1549
+ "learning_rate": 2.4600651803813057e-06,
1550
+ "loss": 0.0046,
1551
+ "step": 257
1552
+ },
1553
+ {
1554
+ "epoch": 2.35,
1555
+ "learning_rate": 2.395940343999691e-06,
1556
+ "loss": 0.0057,
1557
+ "step": 258
1558
+ },
1559
+ {
1560
+ "epoch": 2.35,
1561
+ "learning_rate": 2.332548402714385e-06,
1562
+ "loss": 0.0056,
1563
+ "step": 259
1564
+ },
1565
+ {
1566
+ "epoch": 2.36,
1567
+ "learning_rate": 2.26989546637263e-06,
1568
+ "loss": 0.0124,
1569
+ "step": 260
1570
+ },
1571
+ {
1572
+ "epoch": 2.37,
1573
+ "learning_rate": 2.207987573594833e-06,
1574
+ "loss": 0.0026,
1575
+ "step": 261
1576
+ },
1577
+ {
1578
+ "epoch": 2.38,
1579
+ "learning_rate": 2.146830691192553e-06,
1580
+ "loss": 0.0098,
1581
+ "step": 262
1582
+ },
1583
+ {
1584
+ "epoch": 2.39,
1585
+ "learning_rate": 2.086430713593397e-06,
1586
+ "loss": 0.0052,
1587
+ "step": 263
1588
+ },
1589
+ {
1590
+ "epoch": 2.4,
1591
+ "learning_rate": 2.02679346227293e-06,
1592
+ "loss": 0.0053,
1593
+ "step": 264
1594
+ },
1595
+ {
1596
+ "epoch": 2.41,
1597
+ "learning_rate": 1.967924685193552e-06,
1598
+ "loss": 0.0072,
1599
+ "step": 265
1600
+ },
1601
+ {
1602
+ "epoch": 2.42,
1603
+ "learning_rate": 1.9098300562505266e-06,
1604
+ "loss": 0.0063,
1605
+ "step": 266
1606
+ },
1607
+ {
1608
+ "epoch": 2.43,
1609
+ "learning_rate": 1.8525151747251058e-06,
1610
+ "loss": 0.0068,
1611
+ "step": 267
1612
+ },
1613
+ {
1614
+ "epoch": 2.44,
1615
+ "learning_rate": 1.7959855647448642e-06,
1616
+ "loss": 0.0064,
1617
+ "step": 268
1618
+ },
1619
+ {
1620
+ "epoch": 2.45,
1621
+ "learning_rate": 1.7402466747512704e-06,
1622
+ "loss": 0.006,
1623
+ "step": 269
1624
+ },
1625
+ {
1626
+ "epoch": 2.45,
1627
+ "learning_rate": 1.6853038769745466e-06,
1628
+ "loss": 0.0048,
1629
+ "step": 270
1630
+ },
1631
+ {
1632
+ "epoch": 2.46,
1633
+ "learning_rate": 1.6311624669159064e-06,
1634
+ "loss": 0.007,
1635
+ "step": 271
1636
+ },
1637
+ {
1638
+ "epoch": 2.47,
1639
+ "learning_rate": 1.577827662837136e-06,
1640
+ "loss": 0.0042,
1641
+ "step": 272
1642
+ },
1643
+ {
1644
+ "epoch": 2.48,
1645
+ "learning_rate": 1.5253046052576559e-06,
1646
+ "loss": 0.0044,
1647
+ "step": 273
1648
+ },
1649
+ {
1650
+ "epoch": 2.49,
1651
+ "learning_rate": 1.4735983564590784e-06,
1652
+ "loss": 0.0049,
1653
+ "step": 274
1654
+ },
1655
+ {
1656
+ "epoch": 2.5,
1657
+ "learning_rate": 1.4227138999972801e-06,
1658
+ "loss": 0.0058,
1659
+ "step": 275
1660
+ },
1661
+ {
1662
+ "epoch": 2.51,
1663
+ "learning_rate": 1.3726561402220818e-06,
1664
+ "loss": 0.0062,
1665
+ "step": 276
1666
+ },
1667
+ {
1668
+ "epoch": 2.52,
1669
+ "learning_rate": 1.3234299018045615e-06,
1670
+ "loss": 0.0066,
1671
+ "step": 277
1672
+ },
1673
+ {
1674
+ "epoch": 2.53,
1675
+ "learning_rate": 1.2750399292720284e-06,
1676
+ "loss": 0.0064,
1677
+ "step": 278
1678
+ },
1679
+ {
1680
+ "epoch": 2.54,
1681
+ "learning_rate": 1.2274908865507595e-06,
1682
+ "loss": 0.0052,
1683
+ "step": 279
1684
+ },
1685
+ {
1686
+ "epoch": 2.55,
1687
+ "learning_rate": 1.1807873565164507e-06,
1688
+ "loss": 0.0077,
1689
+ "step": 280
1690
+ },
1691
+ {
1692
+ "epoch": 2.55,
1693
+ "learning_rate": 1.1349338405525368e-06,
1694
+ "loss": 0.0036,
1695
+ "step": 281
1696
+ },
1697
+ {
1698
+ "epoch": 2.56,
1699
+ "learning_rate": 1.0899347581163222e-06,
1700
+ "loss": 0.0076,
1701
+ "step": 282
1702
+ },
1703
+ {
1704
+ "epoch": 2.57,
1705
+ "learning_rate": 1.045794446313031e-06,
1706
+ "loss": 0.0047,
1707
+ "step": 283
1708
+ },
1709
+ {
1710
+ "epoch": 2.58,
1711
+ "learning_rate": 1.0025171594777872e-06,
1712
+ "loss": 0.0053,
1713
+ "step": 284
1714
+ },
1715
+ {
1716
+ "epoch": 2.59,
1717
+ "learning_rate": 9.601070687655667e-07,
1718
+ "loss": 0.0049,
1719
+ "step": 285
1720
+ },
1721
+ {
1722
+ "epoch": 2.6,
1723
+ "learning_rate": 9.185682617491865e-07,
1724
+ "loss": 0.0073,
1725
+ "step": 286
1726
+ },
1727
+ {
1728
+ "epoch": 2.61,
1729
+ "learning_rate": 8.779047420253239e-07,
1730
+ "loss": 0.0056,
1731
+ "step": 287
1732
+ },
1733
+ {
1734
+ "epoch": 2.62,
1735
+ "learning_rate": 8.381204288286415e-07,
1736
+ "loss": 0.0087,
1737
+ "step": 288
1738
+ },
1739
+ {
1740
+ "epoch": 2.63,
1741
+ "learning_rate": 7.992191566540519e-07,
1742
+ "loss": 0.0041,
1743
+ "step": 289
1744
+ },
1745
+ {
1746
+ "epoch": 2.64,
1747
+ "learning_rate": 7.612046748871327e-07,
1748
+ "loss": 0.0062,
1749
+ "step": 290
1750
+ },
1751
+ {
1752
+ "epoch": 2.65,
1753
+ "learning_rate": 7.240806474427598e-07,
1754
+ "loss": 0.0035,
1755
+ "step": 291
1756
+ },
1757
+ {
1758
+ "epoch": 2.65,
1759
+ "learning_rate": 6.878506524119644e-07,
1760
+ "loss": 0.0042,
1761
+ "step": 292
1762
+ },
1763
+ {
1764
+ "epoch": 2.66,
1765
+ "learning_rate": 6.525181817170756e-07,
1766
+ "loss": 0.0063,
1767
+ "step": 293
1768
+ },
1769
+ {
1770
+ "epoch": 2.67,
1771
+ "learning_rate": 6.180866407751595e-07,
1772
+ "loss": 0.0054,
1773
+ "step": 294
1774
+ },
1775
+ {
1776
+ "epoch": 2.68,
1777
+ "learning_rate": 5.845593481697931e-07,
1778
+ "loss": 0.0053,
1779
+ "step": 295
1780
+ },
1781
+ {
1782
+ "epoch": 2.69,
1783
+ "learning_rate": 5.519395353312195e-07,
1784
+ "loss": 0.008,
1785
+ "step": 296
1786
+ },
1787
+ {
1788
+ "epoch": 2.7,
1789
+ "learning_rate": 5.20230346224897e-07,
1790
+ "loss": 0.0039,
1791
+ "step": 297
1792
+ },
1793
+ {
1794
+ "epoch": 2.71,
1795
+ "learning_rate": 4.894348370484648e-07,
1796
+ "loss": 0.0037,
1797
+ "step": 298
1798
+ },
1799
+ {
1800
+ "epoch": 2.72,
1801
+ "learning_rate": 4.5955597593719593e-07,
1802
+ "loss": 0.0061,
1803
+ "step": 299
1804
+ },
1805
+ {
1806
+ "epoch": 2.73,
1807
+ "learning_rate": 4.305966426779118e-07,
1808
+ "loss": 0.0059,
1809
+ "step": 300
1810
+ },
1811
+ {
1812
+ "epoch": 2.74,
1813
+ "learning_rate": 4.025596284314259e-07,
1814
+ "loss": 0.0067,
1815
+ "step": 301
1816
+ },
1817
+ {
1818
+ "epoch": 2.75,
1819
+ "learning_rate": 3.7544763546352834e-07,
1820
+ "loss": 0.0064,
1821
+ "step": 302
1822
+ },
1823
+ {
1824
+ "epoch": 2.75,
1825
+ "learning_rate": 3.492632768845261e-07,
1826
+ "loss": 0.0047,
1827
+ "step": 303
1828
+ },
1829
+ {
1830
+ "epoch": 2.76,
1831
+ "learning_rate": 3.2400907639740243e-07,
1832
+ "loss": 0.0033,
1833
+ "step": 304
1834
+ },
1835
+ {
1836
+ "epoch": 2.77,
1837
+ "learning_rate": 2.996874680545603e-07,
1838
+ "loss": 0.0081,
1839
+ "step": 305
1840
+ },
1841
+ {
1842
+ "epoch": 2.78,
1843
+ "learning_rate": 2.7630079602323447e-07,
1844
+ "loss": 0.0065,
1845
+ "step": 306
1846
+ },
1847
+ {
1848
+ "epoch": 2.79,
1849
+ "learning_rate": 2.5385131435955e-07,
1850
+ "loss": 0.005,
1851
+ "step": 307
1852
+ },
1853
+ {
1854
+ "epoch": 2.8,
1855
+ "learning_rate": 2.3234118679127615e-07,
1856
+ "loss": 0.0051,
1857
+ "step": 308
1858
+ },
1859
+ {
1860
+ "epoch": 2.81,
1861
+ "learning_rate": 2.117724865092774e-07,
1862
+ "loss": 0.0061,
1863
+ "step": 309
1864
+ },
1865
+ {
1866
+ "epoch": 2.82,
1867
+ "learning_rate": 1.921471959676957e-07,
1868
+ "loss": 0.0076,
1869
+ "step": 310
1870
+ },
1871
+ {
1872
+ "epoch": 2.83,
1873
+ "learning_rate": 1.734672066928822e-07,
1874
+ "loss": 0.0063,
1875
+ "step": 311
1876
+ },
1877
+ {
1878
+ "epoch": 2.84,
1879
+ "learning_rate": 1.5573431910108404e-07,
1880
+ "loss": 0.0031,
1881
+ "step": 312
1882
+ },
1883
+ {
1884
+ "epoch": 2.85,
1885
+ "learning_rate": 1.3895024232491338e-07,
1886
+ "loss": 0.0039,
1887
+ "step": 313
1888
+ },
1889
+ {
1890
+ "epoch": 2.85,
1891
+ "learning_rate": 1.231165940486234e-07,
1892
+ "loss": 0.0053,
1893
+ "step": 314
1894
+ },
1895
+ {
1896
+ "epoch": 2.86,
1897
+ "learning_rate": 1.0823490035218986e-07,
1898
+ "loss": 0.0078,
1899
+ "step": 315
1900
+ },
1901
+ {
1902
+ "epoch": 2.87,
1903
+ "learning_rate": 9.43065955642275e-08,
1904
+ "loss": 0.0098,
1905
+ "step": 316
1906
+ },
1907
+ {
1908
+ "epoch": 2.88,
1909
+ "learning_rate": 8.133302212373961e-08,
1910
+ "loss": 0.0054,
1911
+ "step": 317
1912
+ },
1913
+ {
1914
+ "epoch": 2.89,
1915
+ "learning_rate": 6.931543045073708e-08,
1916
+ "loss": 0.0054,
1917
+ "step": 318
1918
+ },
1919
+ {
1920
+ "epoch": 2.9,
1921
+ "learning_rate": 5.8254978825718065e-08,
1922
+ "loss": 0.0046,
1923
+ "step": 319
1924
+ },
1925
+ {
1926
+ "epoch": 2.91,
1927
+ "learning_rate": 4.815273327803183e-08,
1928
+ "loss": 0.0086,
1929
+ "step": 320
1930
+ },
1931
+ {
1932
+ "epoch": 2.92,
1933
+ "learning_rate": 3.900966748312862e-08,
1934
+ "loss": 0.0057,
1935
+ "step": 321
1936
+ },
1937
+ {
1938
+ "epoch": 2.93,
1939
+ "learning_rate": 3.082666266872036e-08,
1940
+ "loss": 0.0055,
1941
+ "step": 322
1942
+ },
1943
+ {
1944
+ "epoch": 2.94,
1945
+ "learning_rate": 2.3604507529843e-08,
1946
+ "loss": 0.0054,
1947
+ "step": 323
1948
+ },
1949
+ {
1950
+ "epoch": 2.95,
1951
+ "learning_rate": 1.7343898152841765e-08,
1952
+ "loss": 0.004,
1953
+ "step": 324
1954
+ },
1955
+ {
1956
+ "epoch": 2.95,
1957
+ "learning_rate": 1.2045437948275952e-08,
1958
+ "loss": 0.0031,
1959
+ "step": 325
1960
+ },
1961
+ {
1962
+ "epoch": 2.96,
1963
+ "learning_rate": 7.70963759277099e-09,
1964
+ "loss": 0.0075,
1965
+ "step": 326
1966
+ },
1967
+ {
1968
+ "epoch": 2.97,
1969
+ "learning_rate": 4.336914979787832e-09,
1970
+ "loss": 0.0055,
1971
+ "step": 327
1972
+ },
1973
+ {
1974
+ "epoch": 2.98,
1975
+ "learning_rate": 1.9275951793518154e-09,
1976
+ "loss": 0.0054,
1977
+ "step": 328
1978
+ },
1979
+ {
1980
+ "epoch": 2.99,
1981
+ "learning_rate": 4.819104067199653e-10,
1982
+ "loss": 0.0052,
1983
+ "step": 329
1984
+ },
1985
+ {
1986
+ "epoch": 3.0,
1987
+ "learning_rate": 0.0,
1988
+ "loss": 0.0021,
1989
+ "step": 330
1990
+ },
1991
+ {
1992
+ "epoch": 3.0,
1993
+ "step": 330,
1994
+ "total_flos": 0.0,
1995
+ "train_loss": 0.016219358733206086,
1996
+ "train_runtime": 8423.2988,
1997
+ "train_samples_per_second": 1.247,
1998
+ "train_steps_per_second": 0.039
1999
+ }
2000
+ ],
2001
+ "logging_steps": 1.0,
2002
+ "max_steps": 330,
2003
+ "num_input_tokens_seen": 0,
2004
+ "num_train_epochs": 3,
2005
+ "save_steps": 500,
2006
+ "total_flos": 0.0,
2007
+ "train_batch_size": 8,
2008
+ "trial_name": null,
2009
+ "trial_params": null
2010
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:94099be84e09b0bf6180c33929e84583fce28f561bfc0c9e87ec3a0bfb39ad28
3
+ size 6779
visual_encoder.py ADDED
@@ -0,0 +1,1019 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ from typing import Any, Optional, Tuple, Union
3
+
4
+ from transformers.modeling_outputs import BaseModelOutput, BaseModelOutputWithPooling, BaseModelOutputWithPastAndCrossAttentions
5
+ from transformers.modeling_utils import PreTrainedModel
6
+ from transformers.pytorch_utils import find_pruneable_heads_and_indices, prune_linear_layer
7
+
8
+ import numpy as np
9
+ import torch
10
+ import torch.nn as nn
11
+ import torch.utils.checkpoint
12
+ # icecream removed for inference
13
+
14
+ def get_abs_pos(abs_pos, tgt_size):
15
+ # abs_pos: L, C
16
+ # tgt_size: M
17
+ # return: M, C
18
+ src_size = int(math.sqrt(abs_pos.size(0)))
19
+ tgt_size = int(math.sqrt(tgt_size))
20
+ dtype = abs_pos.dtype
21
+
22
+ if src_size != tgt_size:
23
+ return F.interpolate(
24
+ abs_pos.float().reshape(1, src_size, src_size, -1).permute(0, 3, 1, 2),
25
+ size=(tgt_size, tgt_size),
26
+ mode="bicubic",
27
+ align_corners=False,
28
+ ).permute(0, 2, 3, 1).flatten(0, 2).to(dtype=dtype)
29
+ else:
30
+ return abs_pos
31
+
32
+ # https://github.com/facebookresearch/mae/blob/efb2a8062c206524e35e47d04501ed4f544c0ae8/util/pos_embed.py#L20
33
+ def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False):
34
+ """
35
+ grid_size: int of the grid height and width
36
+ return:
37
+ pos_embed: [grid_size*grid_size, embed_dim] or [1+grid_size*grid_size, embed_dim] (w/ or w/o cls_token)
38
+ """
39
+ grid_h = np.arange(grid_size, dtype=np.float32)
40
+ grid_w = np.arange(grid_size, dtype=np.float32)
41
+ grid = np.meshgrid(grid_w, grid_h) # here w goes first
42
+ grid = np.stack(grid, axis=0)
43
+
44
+ grid = grid.reshape([2, 1, grid_size, grid_size])
45
+ pos_embed = get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
46
+ if cls_token:
47
+ pos_embed = np.concatenate([np.zeros([1, embed_dim]), pos_embed], axis=0)
48
+ return pos_embed
49
+
50
+
51
+ def get_2d_sincos_pos_embed_from_grid(embed_dim, grid):
52
+ assert embed_dim % 2 == 0
53
+
54
+ # use half of dimensions to encode grid_h
55
+ emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0]) # (H*W, D/2)
56
+ emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1]) # (H*W, D/2)
57
+
58
+ emb = np.concatenate([emb_h, emb_w], axis=1) # (H*W, D)
59
+ return emb
60
+
61
+
62
+ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
63
+ """
64
+ embed_dim: output dimension for each position
65
+ pos: a list of positions to be encoded: size (M,)
66
+ out: (M, D)
67
+ """
68
+ assert embed_dim % 2 == 0
69
+ omega = np.arange(embed_dim // 2, dtype=np.float32)
70
+ omega /= embed_dim / 2.
71
+ omega = 1. / 10000**omega # (D/2,)
72
+
73
+ pos = pos.reshape(-1) # (M,)
74
+ out = np.einsum('m,d->md', pos, omega) # (M, D/2), outer product
75
+
76
+ emb_sin = np.sin(out) # (M, D/2)
77
+ emb_cos = np.cos(out) # (M, D/2)
78
+
79
+ emb = np.concatenate([emb_sin, emb_cos], axis=1) # (M, D)
80
+ return emb
81
+
82
+
83
+
84
+ import torch
85
+ import torch.nn as nn
86
+ import torch.nn.functional as F
87
+
88
+ class MplugOwlVisionEmbeddings(nn.Module):
89
+ def __init__(self, config):
90
+ super().__init__()
91
+ self.config = config
92
+ self.hidden_size = config.hidden_size
93
+ self.image_size = config.image_size
94
+ self.patch_size = config.patch_size
95
+
96
+ self.cls_token = nn.Parameter(torch.randn(1, 1, self.hidden_size))
97
+
98
+ self.patch_embed = nn.Conv2d(
99
+ in_channels=3,
100
+ out_channels=self.hidden_size,
101
+ kernel_size=self.patch_size,
102
+ stride=self.patch_size,
103
+ bias=False,
104
+ )
105
+
106
+ # Initialize position embedding for default size (can be resized later)
107
+ self.num_patches = (self.image_size // self.patch_size) ** 2
108
+ self.position_embedding = nn.Parameter(torch.randn(1, self.num_patches + 1, self.hidden_size))
109
+ self.pre_layernorm = nn.LayerNorm(self.hidden_size, eps=config.layer_norm_eps)
110
+
111
+ def interpolate_pos_encoding(self, embeddings, h, w):
112
+ """
113
+ Interpolate position embeddings for different image sizes
114
+ """
115
+ npatch = embeddings.shape[1] - 1 # subtract 1 for cls token
116
+ N = self.position_embedding.shape[1] - 1 # original number of patches
117
+
118
+ if npatch == N:
119
+ return self.position_embedding
120
+
121
+ # Separate class token and patch embeddings
122
+ class_pos_embed = self.position_embedding[:, 0:1] # [1, 1, hidden_size]
123
+ patch_pos_embed = self.position_embedding[:, 1:] # [1, N, hidden_size]
124
+
125
+ dim = embeddings.shape[-1]
126
+
127
+ # Calculate original grid size
128
+ w0 = h0 = int(N ** 0.5)
129
+
130
+ # Reshape patch embeddings to 2D grid
131
+ patch_pos_embed = patch_pos_embed.reshape(1, w0, h0, dim).permute(0, 3, 1, 2)
132
+
133
+ # Convert to float32 for interpolation
134
+ patch_pos_embed = patch_pos_embed.float()
135
+
136
+ # Interpolate to new size
137
+ patch_pos_embed = F.interpolate(
138
+ patch_pos_embed,
139
+ size=(h, w),
140
+ mode='bicubic',
141
+ align_corners=False,
142
+ )
143
+
144
+ # Convert back to original dtype
145
+ patch_pos_embed = patch_pos_embed.to(dtype=embeddings.dtype)
146
+
147
+ # Reshape back to sequence
148
+ patch_pos_embed = patch_pos_embed.permute(0, 2, 3, 1).reshape(1, -1, dim)
149
+
150
+ # Concatenate class token and patch embeddings
151
+ return torch.cat((class_pos_embed, patch_pos_embed), dim=1)
152
+
153
+ def forward(self, pixel_values: torch.FloatTensor) -> torch.Tensor:
154
+ batch_size = pixel_values.size(0)
155
+ #print(f"[DEBUG] Input image shape: {pixel_values.shape}")
156
+
157
+ image_embeds = self.patch_embed(pixel_values)
158
+ #print(f"[DEBUG] After patch_embed shape: {image_embeds.shape}")
159
+
160
+ # Get patch grid dimensions
161
+ _, _, h, w = image_embeds.shape
162
+
163
+ image_embeds = image_embeds.flatten(2).transpose(1, 2)
164
+ #print(f"[DEBUG] After flatten and transpose shape: {image_embeds.shape}")
165
+
166
+ class_embeds = self.cls_token.expand(batch_size, 1, -1).to(image_embeds.dtype)
167
+ embeddings = torch.cat([class_embeds, image_embeds], dim=1)
168
+
169
+ # Interpolate position embeddings to match current image size
170
+ pos_embed = self.interpolate_pos_encoding(embeddings, h, w).to(image_embeds.dtype)
171
+ #print(f"[DEBUG] Position embedding shape after interpolation: {pos_embed.shape}")
172
+
173
+ embeddings = embeddings + pos_embed
174
+ embeddings = self.pre_layernorm(embeddings)
175
+ return embeddings
176
+
177
+
178
+
179
+ class MplugOwlVisionAttention(nn.Module):
180
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
181
+
182
+ def __init__(self, config):
183
+ super().__init__()
184
+ self.config = config
185
+ self.hidden_size = config.hidden_size
186
+ self.num_heads = config.num_attention_heads
187
+ self.head_dim = self.hidden_size // self.num_heads
188
+ if self.head_dim * self.num_heads != self.hidden_size:
189
+ raise ValueError(
190
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size} and `num_heads`:"
191
+ f" {self.num_heads})."
192
+ )
193
+ self.scale = self.head_dim**-0.5
194
+ self.dropout = nn.Dropout(config.attention_dropout)
195
+
196
+ self.query_key_value = nn.Linear(self.hidden_size, 3 * self.hidden_size)
197
+ self.dense = nn.Linear(self.hidden_size, self.hidden_size)
198
+
199
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
200
+ return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
201
+
202
+ def forward(
203
+ self,
204
+ hidden_states: torch.Tensor,
205
+ head_mask: Optional[torch.Tensor] = None,
206
+ output_attentions: Optional[bool] = False,
207
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
208
+ """Input shape: Batch x Time x Channel"""
209
+
210
+ bsz, seq_len, embed_dim = hidden_states.size()
211
+
212
+ mixed_qkv = self.query_key_value(hidden_states)
213
+
214
+ mixed_qkv = mixed_qkv.reshape(bsz, seq_len, self.num_heads, 3, embed_dim // self.num_heads).permute(
215
+ 3, 0, 2, 1, 4
216
+ ) # [3, b, np, sq, hn]
217
+ query_states, key_states, value_states = (
218
+ mixed_qkv[0],
219
+ mixed_qkv[1],
220
+ mixed_qkv[2],
221
+ )
222
+ # if self.config.use_flash_attn and flash_attn_func is not None:
223
+ if False:
224
+ # [b*sq, np, hn]
225
+ query_states = query_states.permute(0, 2, 1, 3).contiguous()
226
+ query_states = query_states.view(query_states.size(0) * query_states.size(1), query_states.size(2), -1)
227
+
228
+ key_states = key_states.permute(0, 2, 1, 3).contiguous()
229
+ key_states = key_states.view(key_states.size(0) * key_states.size(1), key_states.size(2), -1)
230
+
231
+ value_states = value_states.permute(0, 2, 1, 3).contiguous()
232
+ value_states = value_states.view(value_states.size(0) * value_states.size(1), value_states.size(2), -1)
233
+
234
+ cu_seqlens = torch.arange(
235
+ 0, (bsz + 1) * seq_len, step=seq_len, dtype=torch.int32, device=query_states.device
236
+ )
237
+
238
+ context_layer = flash_attn_func(
239
+ query_states,
240
+ key_states,
241
+ value_states,
242
+ cu_seqlens,
243
+ cu_seqlens,
244
+ seq_len,
245
+ seq_len,
246
+ self.dropout if self.training else 0.0,
247
+ softmax_scale=self.scale,
248
+ causal=False,
249
+ return_attn_probs=False,
250
+ )
251
+ # [b*sq, np, hn] => [b, sq, np, hn]
252
+ context_layer = context_layer.view(bsz, seq_len, context_layer.size(1), context_layer.size(2))
253
+ else:
254
+ # Take the dot product between "query" and "key" to get the raw attention scores.
255
+ attention_scores = torch.matmul(query_states, key_states.transpose(-1, -2))
256
+
257
+ attention_scores = attention_scores * self.scale
258
+
259
+ # Normalize the attention scores to probabilities.
260
+ attention_probs = torch.softmax(attention_scores, dim=-1)
261
+
262
+ # This is actually dropping out entire tokens to attend to, which might
263
+ # seem a bit unusual, but is taken from the original Transformer paper.
264
+ attention_probs = self.dropout(attention_probs)
265
+
266
+ # Mask heads if we want to
267
+ if head_mask is not None:
268
+ attention_probs = attention_probs * head_mask
269
+
270
+ context_layer = torch.matmul(attention_probs, value_states).permute(0, 2, 1, 3)
271
+
272
+ new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size,)
273
+ context_layer = context_layer.reshape(new_context_layer_shape)
274
+
275
+ output = self.dense(context_layer)
276
+
277
+ outputs = (output, attention_probs) if output_attentions else (output, None)
278
+
279
+ return outputs
280
+
281
+
282
+ class QuickGELU(nn.Module):
283
+ def forward(self, x: torch.Tensor):
284
+ return x * torch.sigmoid(1.702 * x)
285
+
286
+
287
+ class MplugOwlMLP(nn.Module):
288
+ def __init__(self, config):
289
+ super().__init__()
290
+ self.config = config
291
+ self.activation_fn = QuickGELU()
292
+ self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
293
+ self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)
294
+
295
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
296
+ hidden_states = self.fc1(hidden_states)
297
+ hidden_states = self.activation_fn(hidden_states)
298
+ hidden_states = self.fc2(hidden_states)
299
+ return hidden_states
300
+
301
+
302
+ class MplugOwlVisionEncoderLayer(nn.Module):
303
+ def __init__(self, config):
304
+ super().__init__()
305
+ self.hidden_size = config.hidden_size
306
+ self.self_attn = MplugOwlVisionAttention(config)
307
+ self.input_layernorm = nn.LayerNorm(self.hidden_size, eps=config.layer_norm_eps)
308
+ self.mlp = MplugOwlMLP(config)
309
+ self.post_attention_layernorm = nn.LayerNorm(self.hidden_size, eps=config.layer_norm_eps)
310
+
311
+ def forward(
312
+ self,
313
+ hidden_states: torch.Tensor,
314
+ attention_mask: torch.Tensor,
315
+ output_attentions: Optional[bool] = False,
316
+ ) -> Tuple[torch.FloatTensor]:
317
+ """
318
+ Args:
319
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
320
+ attention_mask (`torch.FloatTensor`): attention mask of size
321
+ `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
322
+ `(config.encoder_attention_heads,)`.
323
+ output_attentions (`bool`, *optional*):
324
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
325
+ returned tensors for more detail.
326
+ """
327
+ residual = hidden_states
328
+
329
+ hidden_states = self.input_layernorm(hidden_states)
330
+ hidden_states, attn_weights = self.self_attn(
331
+ hidden_states=hidden_states,
332
+ head_mask=attention_mask,
333
+ output_attentions=output_attentions,
334
+ )
335
+ hidden_states = hidden_states + residual
336
+ residual = hidden_states
337
+ hidden_states = self.post_attention_layernorm(hidden_states)
338
+ hidden_states = self.mlp(hidden_states)
339
+
340
+ hidden_states = hidden_states + residual
341
+
342
+ outputs = (hidden_states,)
343
+
344
+ if output_attentions:
345
+ outputs += (attn_weights,)
346
+
347
+ return outputs
348
+
349
+
350
+ class MplugOwlVisionEncoder(nn.Module):
351
+ """
352
+ Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
353
+ [`MplugOwlVisionEncoderLayer`].
354
+
355
+ Args:
356
+ config (`MplugOwlVisionConfig`):
357
+ The corresponding vision configuration for the `MplugOwlEncoder`.
358
+ """
359
+
360
+ def __init__(self, config):
361
+ super().__init__()
362
+ self.config = config
363
+ self.layers = nn.ModuleList([MplugOwlVisionEncoderLayer(config) for _ in range(config.num_hidden_layers)])
364
+ self.gradient_checkpointing = True
365
+
366
+ def forward(
367
+ self,
368
+ inputs_embeds,
369
+ attention_mask: Optional[torch.Tensor] = None,
370
+ output_attentions: Optional[bool] = None,
371
+ output_hidden_states: Optional[bool] = None,
372
+ return_dict: Optional[bool] = None,
373
+ ) -> Union[Tuple, BaseModelOutput]:
374
+ r"""
375
+ Args:
376
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
377
+ Embedded representation of the inputs. Should be float, not int tokens.
378
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
379
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
380
+
381
+ - 1 for tokens that are **not masked**,
382
+ - 0 for tokens that are **masked**.
383
+
384
+ [What are attention masks?](../glossary#attention-mask)
385
+ output_attentions (`bool`, *optional*):
386
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
387
+ returned tensors for more detail.
388
+ output_hidden_states (`bool`, *optional*):
389
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
390
+ for more detail.
391
+ return_dict (`bool`, *optional*):
392
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
393
+ """
394
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
395
+ output_hidden_states = (
396
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
397
+ )
398
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
399
+
400
+ encoder_states = () if output_hidden_states else None
401
+ all_attentions = () if output_attentions else None
402
+
403
+ hidden_states = inputs_embeds
404
+ for idx, encoder_layer in enumerate(self.layers):
405
+ if output_hidden_states:
406
+ encoder_states = encoder_states + (hidden_states,)
407
+ if self.gradient_checkpointing and self.training:
408
+
409
+ def create_custom_forward(module):
410
+ def custom_forward(*inputs):
411
+ return module(*inputs, output_attentions)
412
+
413
+ return custom_forward
414
+
415
+ layer_outputs = torch.utils.checkpoint.checkpoint(
416
+ create_custom_forward(encoder_layer),
417
+ hidden_states,
418
+ attention_mask,
419
+ )
420
+ else:
421
+ layer_outputs = encoder_layer(
422
+ hidden_states,
423
+ attention_mask,
424
+ output_attentions=output_attentions,
425
+ )
426
+
427
+ hidden_states = layer_outputs[0]
428
+
429
+ if output_attentions:
430
+ all_attentions = all_attentions + (layer_outputs[1],)
431
+
432
+ if output_hidden_states:
433
+ encoder_states = encoder_states + (hidden_states,)
434
+
435
+ if not return_dict:
436
+ return tuple(v for v in [hidden_states, encoder_states, all_attentions] if v is not None)
437
+ return BaseModelOutput(
438
+ last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions
439
+ )
440
+
441
+
442
+ class MplugOwlVisionModel(PreTrainedModel):
443
+ main_input_name = "pixel_values"
444
+ _no_split_modules = ["MplugOwlVisionEncoderLayer"]
445
+
446
+ def __init__(self, config):
447
+ super().__init__(config)
448
+ self.config = config
449
+ self.hidden_size = config.hidden_size
450
+
451
+ self.embeddings = MplugOwlVisionEmbeddings(config)
452
+ self.encoder = MplugOwlVisionEncoder(config)
453
+ self.post_layernorm = nn.LayerNorm(self.hidden_size, eps=config.layer_norm_eps)
454
+
455
+ self.post_init()
456
+
457
+
458
+ def forward(
459
+ self,
460
+ pixel_values: Optional[torch.FloatTensor] = None,
461
+ output_attentions: Optional[bool] = None,
462
+ output_hidden_states: Optional[bool] = None,
463
+ return_dict: Optional[bool] = None,
464
+ ) -> Union[Tuple, BaseModelOutputWithPooling]:
465
+ r"""
466
+ Returns:
467
+
468
+ """
469
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
470
+ output_hidden_states = (
471
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
472
+ )
473
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
474
+
475
+ if pixel_values is None:
476
+ raise ValueError("You have to specify pixel_values")
477
+
478
+ hidden_states = self.embeddings(pixel_values)
479
+
480
+ encoder_outputs = self.encoder(
481
+ inputs_embeds=hidden_states,
482
+ output_attentions=output_attentions,
483
+ output_hidden_states=output_hidden_states,
484
+ return_dict=return_dict,
485
+ )
486
+
487
+ last_hidden_state = encoder_outputs[0]
488
+ last_hidden_state = self.post_layernorm(last_hidden_state)
489
+
490
+ pooled_output = last_hidden_state[:, 0, :]
491
+ pooled_output = self.post_layernorm(pooled_output)
492
+
493
+ if not return_dict:
494
+ return (last_hidden_state, pooled_output) + encoder_outputs[1:]
495
+
496
+ return BaseModelOutputWithPooling(
497
+ last_hidden_state=last_hidden_state,
498
+ pooler_output=pooled_output,
499
+ hidden_states=encoder_outputs.hidden_states,
500
+ attentions=encoder_outputs.attentions,
501
+ )
502
+
503
+ def get_input_embeddings(self):
504
+ return self.embeddings
505
+
506
+
507
+ class MplugOwlVisualAbstractorMLP(nn.Module):
508
+ def __init__(self, config):
509
+ super().__init__()
510
+ self.config = config
511
+ in_features = config.hidden_size
512
+ self.act = nn.SiLU()
513
+
514
+ self.w1 = nn.Linear(in_features, config.intermediate_size)
515
+ self.w2 = nn.Linear(config.intermediate_size, in_features)
516
+ self.w3 = nn.Linear(in_features, config.intermediate_size)
517
+ self.ffn_ln = nn.LayerNorm(config.intermediate_size, eps=config.layer_norm_eps)
518
+
519
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
520
+ hidden_states = self.act(self.w1(hidden_states)) * self.w3(hidden_states)
521
+ hidden_states = self.ffn_ln(hidden_states)
522
+ hidden_states = self.w2(hidden_states)
523
+ return hidden_states
524
+
525
+
526
+ class MplugOwlVisualAbstractorMultiHeadAttention(nn.Module):
527
+ def __init__(self, config):
528
+ super().__init__()
529
+ self.config = config
530
+ if config.hidden_size % config.num_attention_heads != 0:
531
+ raise ValueError(
532
+ "The hidden size (%d) is not a multiple of the number of attention heads (%d)"
533
+ % (config.hidden_size, config.num_attention_heads)
534
+ )
535
+
536
+ self.num_attention_heads = config.num_attention_heads
537
+ self.attention_head_size = int(config.hidden_size / config.num_attention_heads)
538
+ self.all_head_size = self.num_attention_heads * self.attention_head_size
539
+
540
+ self.query = nn.Linear(config.hidden_size, self.all_head_size)
541
+ self.key = nn.Linear(config.encoder_hidden_size, self.all_head_size)
542
+ self.value = nn.Linear(config.encoder_hidden_size, self.all_head_size)
543
+
544
+ self.dropout = nn.Dropout(config.attention_probs_dropout_prob)
545
+ self.save_attention = False
546
+
547
+ # self.q_pos_embed = nn.Parameter(
548
+ # torch.from_numpy(get_1d_sincos_pos_embed_from_grid(config.hidden_size, np.arange(config.num_learnable_queries, dtype=np.float32))).float()
549
+ # ).requires_grad_(False)
550
+ # grids = config.grid_size
551
+ # self.k_pos_embed = nn.Parameter(
552
+ # torch.from_numpy(get_2d_sincos_pos_embed(config.hidden_size, grids, cls_token=True)).float()
553
+ # ).requires_grad_(False)
554
+ grids = config.grid_size
555
+ self.register_buffer(
556
+ 'q_pos_embed',
557
+ torch.from_numpy(get_1d_sincos_pos_embed_from_grid(config.hidden_size, np.arange(config.num_learnable_queries, dtype=np.float32))).float()
558
+ )
559
+ self.register_buffer(
560
+ 'k_pos_embed',
561
+ torch.from_numpy(get_2d_sincos_pos_embed(config.hidden_size, grids, cls_token=True)).float()
562
+ )
563
+
564
+
565
+ def save_attn_gradients(self, attn_gradients):
566
+ self.attn_gradients = attn_gradients
567
+
568
+ def get_attn_gradients(self):
569
+ return self.attn_gradients
570
+
571
+ def save_attention_map(self, attention_map):
572
+ self.attention_map = attention_map
573
+
574
+ def get_attention_map(self):
575
+ return self.attention_map
576
+
577
+ def transpose_for_scores(self, x):
578
+ new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size)
579
+ x = x.view(*new_x_shape)
580
+ return x.permute(0, 2, 1, 3)
581
+
582
+ def forward(
583
+ self,
584
+ hidden_states,
585
+ attention_mask=None,
586
+ head_mask=None,
587
+ encoder_hidden_states=None,
588
+ encoder_attention_mask=None,
589
+ past_key_value=None,
590
+ output_attentions=False,
591
+ ):
592
+ # If this is instantiated as a cross-attention module, the keys
593
+ # and values come from an encoder; the attention mask needs to be
594
+ # such that the encoder's padding tokens are not attended to.
595
+
596
+ # 确保位置编码的维度与输入匹配
597
+ if encoder_hidden_states is not None:
598
+ seq_len = encoder_hidden_states.size(1)
599
+ if seq_len != self.k_pos_embed.size(0):
600
+ # 如果序列长度不匹配,需要调整位置编码
601
+ # 使用更高效的方式调整位置编码
602
+ k_pos_embed = self.k_pos_embed
603
+ if seq_len > k_pos_embed.size(0):
604
+ # 如果目标序列更长,使用重复
605
+ repeat_times = (seq_len + k_pos_embed.size(0) - 1) // k_pos_embed.size(0)
606
+ k_pos_embed = k_pos_embed.repeat(repeat_times, 1)[:seq_len]
607
+ else:
608
+ # 如果目标序列更短,使用切片
609
+ k_pos_embed = k_pos_embed[:seq_len]
610
+ else:
611
+ k_pos_embed = self.k_pos_embed
612
+
613
+ # 确保 q_pos_embed 和 k_pos_embed 的维度正确
614
+ q_pos_embed = self.q_pos_embed.to(dtype=hidden_states.dtype)
615
+ k_pos_embed = k_pos_embed.to(dtype=encoder_hidden_states.dtype)
616
+
617
+ # 确保维度匹配
618
+ if q_pos_embed.size(0) + k_pos_embed.size(0) != encoder_hidden_states.size(1):
619
+ # 如果维度不匹配,调整 k_pos_embed 的大小
620
+ target_size = encoder_hidden_states.size(1) - q_pos_embed.size(0)
621
+ if target_size > k_pos_embed.size(0):
622
+ # 如果目标大小更大,使用重复
623
+ repeat_times = (target_size + k_pos_embed.size(0) - 1) // k_pos_embed.size(0)
624
+ k_pos_embed = k_pos_embed.repeat(repeat_times, 1)[:target_size]
625
+ else:
626
+ # 如果目标大小更小,使用切片
627
+ k_pos_embed = k_pos_embed[:target_size]
628
+
629
+ qk_pos_embed = torch.cat([q_pos_embed, k_pos_embed], dim=0).unsqueeze(0)
630
+ else:
631
+ qk_pos_embed = self.q_pos_embed.unsqueeze(0).to(dtype=hidden_states.dtype)
632
+
633
+ # 确保最终维度匹配
634
+ assert qk_pos_embed.size(1) == encoder_hidden_states.size(1), \
635
+ f"Position embedding size {qk_pos_embed.size(1)} does not match encoder hidden states size {encoder_hidden_states.size(1)}"
636
+
637
+ key_layer = self.transpose_for_scores(self.key(encoder_hidden_states + qk_pos_embed))
638
+ value_layer = self.transpose_for_scores(self.value(encoder_hidden_states))
639
+ attention_mask = encoder_attention_mask
640
+
641
+ mixed_query_layer = self.query(hidden_states + self.q_pos_embed.unsqueeze(0).to(dtype=hidden_states.dtype))
642
+
643
+ query_layer = self.transpose_for_scores(mixed_query_layer)
644
+
645
+ past_key_value = (key_layer, value_layer)
646
+
647
+ # Take the dot product between "query" and "key" to get the raw attention scores.
648
+ attention_scores = torch.matmul(query_layer, key_layer.transpose(-1, -2))
649
+
650
+ attention_scores = attention_scores / math.sqrt(self.attention_head_size)
651
+
652
+ if attention_mask is not None:
653
+ # Apply the attention mask is (precomputed for all layers in BertModel forward() function)
654
+ attention_scores = attention_scores + attention_mask
655
+
656
+ # Normalize the attention scores to probabilities.
657
+ attention_probs = nn.Softmax(dim=-1)(attention_scores)
658
+
659
+ if self.save_attention:
660
+ self.save_attention_map(attention_probs)
661
+ attention_probs.register_hook(self.save_attn_gradients)
662
+
663
+ # This is actually dropping out entire tokens to attend to, which might
664
+ # seem a bit unusual, but is taken from the original Transformer paper.
665
+ attention_probs_dropped = self.dropout(attention_probs)
666
+
667
+ # Mask heads if we want to
668
+ if head_mask is not None:
669
+ attention_probs_dropped = attention_probs_dropped * head_mask
670
+
671
+ context_layer = torch.matmul(attention_probs_dropped, value_layer)
672
+
673
+ context_layer = context_layer.permute(0, 2, 1, 3).contiguous()
674
+ new_context_layer_shape = context_layer.size()[:-2] + (self.all_head_size,)
675
+ context_layer = context_layer.view(*new_context_layer_shape)
676
+
677
+ outputs = (context_layer, attention_probs) if output_attentions else (context_layer,)
678
+
679
+ outputs = outputs + (past_key_value,)
680
+ return outputs
681
+
682
+
683
+ class MplugOwlVisualAbstractorCrossOutput(nn.Module):
684
+ def __init__(self, config):
685
+ super().__init__()
686
+ dim = config.hidden_size
687
+ self.out_proj = nn.Linear(dim, dim, bias=True)
688
+ self.norm2 = nn.LayerNorm(dim)
689
+ self.mlp = MplugOwlVisualAbstractorMLP(config)
690
+
691
+ def forward(self, hidden_states: torch.Tensor, input_tensor: torch.Tensor) -> torch.Tensor:
692
+ input_tensor = input_tensor + self.out_proj(hidden_states)
693
+ input_tensor = input_tensor + self.mlp(self.norm2(input_tensor))
694
+ return input_tensor
695
+
696
+
697
+ class MplugOwlVisualAbstractorAttention(nn.Module):
698
+ def __init__(self, config):
699
+ super().__init__()
700
+ self.attention = MplugOwlVisualAbstractorMultiHeadAttention(config)
701
+ self.output = MplugOwlVisualAbstractorCrossOutput(config)
702
+ self.pruned_heads = set()
703
+ self.norm1 = nn.LayerNorm(config.hidden_size)
704
+ self.normk = nn.LayerNorm(config.hidden_size)
705
+
706
+ def prune_heads(self, heads):
707
+ if len(heads) == 0:
708
+ return
709
+ heads, index = find_pruneable_heads_and_indices(
710
+ heads, self.attention.num_attention_heads, self.attention.attention_head_size, self.pruned_heads
711
+ )
712
+
713
+ # Prune linear layers
714
+ self.attention.query = prune_linear_layer(self.attention.query, index)
715
+ self.attention.key = prune_linear_layer(self.attention.key, index)
716
+ self.attention.value = prune_linear_layer(self.attention.value, index)
717
+ self.output.dense = prune_linear_layer(self.output.out_proj, index, dim=1)
718
+
719
+ # Update hyper params and store pruned heads
720
+ self.attention.num_attention_heads = self.attention.num_attention_heads - len(heads)
721
+ self.attention.all_head_size = self.attention.attention_head_size * self.attention.num_attention_heads
722
+ self.pruned_heads = self.pruned_heads.union(heads)
723
+
724
+ def forward(
725
+ self,
726
+ hidden_states: torch.Tensor,
727
+ attention_mask: Optional[torch.FloatTensor] = None,
728
+ head_mask: Optional[torch.FloatTensor] = None,
729
+ encoder_hidden_states: Optional[torch.FloatTensor] = None,
730
+ encoder_attention_mask: Optional[torch.FloatTensor] = None,
731
+ past_key_value: Optional[Tuple[Tuple[torch.FloatTensor]]] = None,
732
+ output_attentions: Optional[bool] = False,
733
+ ) -> Tuple[torch.Tensor]:
734
+ # HACK we apply norm on q and k
735
+ hidden_states = self.norm1(hidden_states)
736
+ encoder_hidden_states = self.normk(encoder_hidden_states)
737
+ encoder_hidden_states = torch.cat([hidden_states, encoder_hidden_states], dim=1)
738
+ encoder_attention_mask = torch.cat([attention_mask, encoder_attention_mask], dim=-1)
739
+ self_outputs = self.attention(
740
+ hidden_states,
741
+ attention_mask,
742
+ head_mask,
743
+ encoder_hidden_states,
744
+ encoder_attention_mask,
745
+ past_key_value,
746
+ output_attentions,
747
+ )
748
+ attention_output = self.output(self_outputs[0], hidden_states)
749
+ # add attentions if we output them
750
+ outputs = (attention_output,) + self_outputs[1:]
751
+ return outputs
752
+
753
+
754
+ class MplugOwlVisualAbstractorLayer(nn.Module):
755
+ def __init__(self, config, layer_idx):
756
+ super().__init__()
757
+ self.chunk_size_feed_forward = config.chunk_size_feed_forward
758
+ self.seq_len_dim = 1
759
+
760
+ self.layer_idx = layer_idx
761
+
762
+ self.crossattention = MplugOwlVisualAbstractorAttention(config)
763
+ self.has_cross_attention = True
764
+
765
+ def forward(
766
+ self,
767
+ hidden_states,
768
+ attention_mask=None,
769
+ head_mask=None,
770
+ encoder_hidden_states=None,
771
+ encoder_attention_mask=None,
772
+ output_attentions=False,
773
+ ):
774
+ if encoder_hidden_states is None:
775
+ raise ValueError("encoder_hidden_states must be given for cross-attention layers")
776
+ cross_attention_outputs = self.crossattention(
777
+ hidden_states,
778
+ attention_mask,
779
+ head_mask,
780
+ encoder_hidden_states,
781
+ encoder_attention_mask,
782
+ output_attentions=output_attentions,
783
+ )
784
+ query_attention_output = cross_attention_outputs[0]
785
+
786
+ outputs = (query_attention_output,)
787
+ return outputs
788
+
789
+
790
+ class MplugOwlVisualAbstractorEncoder(nn.Module):
791
+ def __init__(self, config):
792
+ super().__init__()
793
+ self.config = config
794
+ self.layers = nn.ModuleList(
795
+ [MplugOwlVisualAbstractorLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
796
+ )
797
+ self.gradient_checkpointing = True
798
+
799
+ def forward(
800
+ self,
801
+ hidden_states,
802
+ attention_mask=None,
803
+ head_mask=None,
804
+ encoder_hidden_states=None,
805
+ encoder_attention_mask=None,
806
+ past_key_values=None,
807
+ output_attentions=False,
808
+ output_hidden_states=False,
809
+ return_dict=True,
810
+ ):
811
+ all_hidden_states = () if output_hidden_states else None
812
+
813
+ for i in range(self.config.num_hidden_layers):
814
+ layer_module = self.layers[i]
815
+ if output_hidden_states:
816
+ all_hidden_states = all_hidden_states + (hidden_states,)
817
+
818
+ layer_head_mask = head_mask[i] if head_mask is not None else None
819
+ past_key_value = past_key_values[i] if past_key_values is not None else None
820
+
821
+ if getattr(self.config, "gradient_checkpointing", False) and self.training:
822
+
823
+ def create_custom_forward(module):
824
+ def custom_forward(*inputs):
825
+ return module(*inputs, past_key_value, output_attentions)
826
+
827
+ return custom_forward
828
+
829
+ layer_outputs = torch.utils.checkpoint.checkpoint(
830
+ create_custom_forward(layer_module),
831
+ hidden_states,
832
+ attention_mask,
833
+ layer_head_mask,
834
+ encoder_hidden_states,
835
+ encoder_attention_mask,
836
+ )
837
+ else:
838
+ layer_outputs = layer_module(
839
+ hidden_states,
840
+ attention_mask,
841
+ layer_head_mask,
842
+ encoder_hidden_states,
843
+ encoder_attention_mask,
844
+ output_attentions,
845
+ )
846
+
847
+ hidden_states = layer_outputs[0]
848
+
849
+ return BaseModelOutput(
850
+ last_hidden_state=hidden_states,
851
+ )
852
+
853
+
854
+ class MplugOwlVisualAbstractorModel(PreTrainedModel):
855
+ _no_split_modules = ["MplugOwlVisualAbstractorLayer"]
856
+ def __init__(self, config, language_hidden_size):
857
+ super().__init__(config)
858
+ self.config = config
859
+
860
+ self.encoder = MplugOwlVisualAbstractorEncoder(config)
861
+ self.visual_fc = torch.nn.Linear(config.hidden_size, language_hidden_size)
862
+ self.query_embeds = torch.nn.Parameter(torch.randn(1, config.num_learnable_queries, config.hidden_size))
863
+ self.vit_eos = torch.nn.Parameter(torch.randn(1, 1, language_hidden_size))
864
+
865
+ self.post_init()
866
+
867
+ def _prune_heads(self, heads_to_prune):
868
+ """
869
+ Prunes heads of the model. heads_to_prune: dict of {layer_num: list of heads to prune in this layer} See base
870
+ class PreTrainedModel
871
+ """
872
+ for layer, heads in heads_to_prune.items():
873
+ self.encoder.layer[layer].attention.prune_heads(heads)
874
+
875
+ def get_extended_attention_mask(
876
+ self,
877
+ attention_mask: torch.Tensor,
878
+ input_shape: Tuple[int],
879
+ device: torch.device,
880
+ ) -> torch.Tensor:
881
+ """
882
+ Makes broadcastable attention and causal masks so that future and masked tokens are ignored.
883
+
884
+ Arguments:
885
+ attention_mask (`torch.Tensor`):
886
+ Mask with ones indicating tokens to attend to, zeros for tokens to ignore.
887
+ input_shape (`Tuple[int]`):
888
+ The shape of the input to the model.
889
+ device: (`torch.device`):
890
+ The device of the input to the model.
891
+
892
+ Returns:
893
+ `torch.Tensor` The extended attention mask, with a the same dtype as `attention_mask.dtype`.
894
+ """
895
+ # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
896
+ # ourselves in which case we just need to make it broadcastable to all heads.
897
+ if attention_mask.dim() == 3:
898
+ extended_attention_mask = attention_mask[:, None, :, :]
899
+ elif attention_mask.dim() == 2:
900
+ # Provided a padding mask of dimensions [batch_size, seq_length]
901
+ # - the model is an encoder, so make the mask broadcastable to [batch_size, num_heads, seq_length, seq_length]
902
+ extended_attention_mask = attention_mask[:, None, None, :]
903
+ else:
904
+ raise ValueError(
905
+ "Wrong shape for input_ids (shape {}) or attention_mask (shape {})".format(
906
+ input_shape, attention_mask.shape
907
+ )
908
+ )
909
+
910
+ # Since attention_mask is 1.0 for positions we want to attend and 0.0 for
911
+ # masked positions, this operation will create a tensor which is 0.0 for
912
+ # positions we want to attend and -10000.0 for masked positions.
913
+ # Since we are adding it to the raw scores before the softmax, this is
914
+ # effectively the same as removing these entirely.
915
+ extended_attention_mask = extended_attention_mask.to(dtype=self.dtype) # fp16 compatibility
916
+ extended_attention_mask = (1.0 - extended_attention_mask) * -10000.0
917
+ return extended_attention_mask
918
+
919
+ def forward(
920
+ self,
921
+ attention_mask=None,
922
+ head_mask=None,
923
+ encoder_hidden_states=None,
924
+ encoder_attention_mask=None,
925
+ past_key_values=None,
926
+ output_attentions=None,
927
+ output_hidden_states=None,
928
+ return_dict=None,
929
+ ):
930
+ r"""
931
+ encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, `optional`):
932
+ Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
933
+ the model is configured as a decoder.
934
+ encoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, `optional`):
935
+ Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
936
+ the cross-attention if the model is configured as a decoder. Mask values selected in `[0, 1]`:
937
+ - 1 for tokens that are **not masked**,
938
+ - 0 for tokens that are **masked**.
939
+ past_key_values (`tuple(tuple(torch.FloatTensor))` of length `config.n_layers` with each tuple having 4 tensors of:
940
+ shape `(batch_size, num_heads, sequence_length - 1, embed_size_per_head)`): Contains precomputed key and
941
+ value hidden states of the attention blocks. Can be used to speed up decoding. If `past_key_values` are
942
+ used, the user can optionally input only the last `decoder_input_ids` (those that don't have their past key
943
+ value states given to this model) of shape `(batch_size, 1)` instead of all `decoder_input_ids` of shape
944
+ `(batch_size, sequence_length)`.
945
+ """
946
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
947
+ output_hidden_states = (
948
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
949
+ )
950
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
951
+
952
+ query_embeds = self.query_embeds.repeat(encoder_hidden_states.shape[0], 1, 1)
953
+ embedding_output = query_embeds
954
+ input_shape = embedding_output.size()[:-1]
955
+ batch_size, seq_length = input_shape
956
+ device = embedding_output.device
957
+
958
+ # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
959
+ # ourselves in which case we just need to make it broadcastable to all heads.
960
+ if attention_mask is None:
961
+ attention_mask = torch.ones(
962
+ (query_embeds.shape[0], query_embeds.shape[1]), dtype=torch.long, device=query_embeds.device
963
+ )
964
+ extended_attention_mask = self.get_extended_attention_mask(attention_mask, input_shape, device)
965
+
966
+ # If a 2D or 3D attention mask is provided for the cross-attention
967
+ # we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length]
968
+ if encoder_hidden_states is not None:
969
+ if type(encoder_hidden_states) == list:
970
+ encoder_batch_size, encoder_sequence_length, _ = encoder_hidden_states[0].size()
971
+ else:
972
+ (
973
+ encoder_batch_size,
974
+ encoder_sequence_length,
975
+ _,
976
+ ) = encoder_hidden_states.size()
977
+ encoder_hidden_shape = (encoder_batch_size, encoder_sequence_length)
978
+
979
+ if type(encoder_attention_mask) == list:
980
+ encoder_extended_attention_mask = [self.invert_attention_mask(mask) for mask in encoder_attention_mask]
981
+ elif encoder_attention_mask is None:
982
+ encoder_attention_mask = torch.ones(encoder_hidden_shape, device=device)
983
+ encoder_extended_attention_mask = self.invert_attention_mask(encoder_attention_mask)
984
+ else:
985
+ encoder_extended_attention_mask = self.invert_attention_mask(encoder_attention_mask)
986
+ else:
987
+ encoder_extended_attention_mask = None
988
+
989
+ # Prepare head mask if needed
990
+ # 1.0 in head_mask indicate we keep the head
991
+ # attention_probs has shape bsz x n_heads x N x N
992
+ # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads]
993
+ # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length]
994
+ head_mask = self.get_head_mask(head_mask, self.config.num_hidden_layers)
995
+
996
+ encoder_outputs = self.encoder(
997
+ embedding_output,
998
+ attention_mask=extended_attention_mask,
999
+ head_mask=head_mask,
1000
+ encoder_hidden_states=encoder_hidden_states,
1001
+ encoder_attention_mask=encoder_extended_attention_mask,
1002
+ past_key_values=past_key_values,
1003
+ output_attentions=output_attentions,
1004
+ output_hidden_states=output_hidden_states,
1005
+ return_dict=return_dict,
1006
+ )
1007
+ sequence_output = encoder_outputs[0]
1008
+ pooled_output = sequence_output[:, 0, :]
1009
+
1010
+ sequence_output = self.visual_fc(sequence_output)
1011
+ sequence_output = torch.cat([sequence_output, self.vit_eos.repeat(sequence_output.shape[0], 1, 1)], dim=1)
1012
+
1013
+ return BaseModelOutputWithPooling(
1014
+ last_hidden_state=sequence_output,
1015
+ pooler_output=pooled_output,
1016
+ hidden_states=encoder_outputs.hidden_states,
1017
+ )
1018
+
1019
+