phara0n commited on
Commit
fbd7a82
·
verified ·
1 Parent(s): 692091c

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - multilingual
4
+ pipeline_tag: image-text-to-text
5
+ tags:
6
+ - vision
7
+ widget:
8
+ - messages:
9
+ - role: user
10
+ content: <|image_1|>\nDescribe bones on this chest X-ray?
11
+ library_name: transformers
12
+ ---
13
+ # ChexFract: Specialized Vision-Language Models for Fracture Detection in Chest X-rays
14
+
15
+ This repository contains the pre-trained models from our paper "ChexFract: From General to Specialized - Enhancing Fracture Description Generation in Medical AI".
16
+
17
+ ## 📋 Overview
18
+
19
+ ChexFract models are specialized vision-language models fine-tuned for accurate fracture detection and description in chest X-ray images. These models significantly outperform general-purpose radiology report generation systems on fracture-specific tasks.
20
+
21
+ ## 🏆 Model Performance
22
+
23
+ ### Released Models
24
+
25
+ We release two best-performing models, each optimized for their respective encoder architecture:
26
+
27
+ 1. **ChexFract-MAIRA-2** (Best F1-Score with MAIRA-2 encoder)
28
+ - **Configuration:** Templated text + Fine-tuned encoder (unfrozen)
29
+ - **ROC-AUC:** 0.713
30
+ - **F1-Score:** 0.629
31
+ - **Accuracy:** 0.748
32
+ - **Precision:** 0.682
33
+ - **Recall:** 0.584
34
+
35
+ 2. **ChexFract-CheXagent** (Best F1-Score with CheXagent encoder)
36
+ - **Configuration:** Templated text + Fine-tuned encoder (unfrozen)
37
+ - **ROC-AUC:** 0.697
38
+ - **F1-Score:** 0.591
39
+ - **Accuracy:** 0.752
40
+ - **Precision:** 0.750
41
+ - **Recall:** 0.487
42
+
43
+ ## 🚀 Quick Start
44
+
45
+ ### Installation
46
+
47
+ ```bash
48
+ pip install torch torchvision transformers pillow
49
+ ```
50
+
51
+ ### Basic Usage
52
+
53
+ **Using CheXagent encoder model:**
54
+ ```python
55
+ from transformers import AutoModelForCausalLM, AutoProcessor
56
+ from PIL import Image
57
+
58
+ # Load model and processor
59
+ model = AutoModelForCausalLM.from_pretrained("AIRI-Institute/chexfract-chexagent", trust_remote_code=True)
60
+ processor = AutoProcessor.from_pretrained("AIRI-Institute/chexfract-chexagent", trust_remote_code=True)
61
+
62
+ messages = [{"role": "user", "content": "<|image_1|>\nDescribe bones on this chest X-ray"}]
63
+
64
+ # Load chest X-ray image
65
+ image = Image.open("chest_xray.png")
66
+ prompt = processor.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
67
+
68
+ # Generate fracture description
69
+ inputs = processor(prompt, image, return_tensors="pt")
70
+ outputs = model.generate(**inputs, eos_token_id=processor.tokenizer.eos_token_id, max_new_tokens=1024)
71
+ description = processor.decode(outputs[0, inputs['input_ids'].shape[1]:], skip_special_tokens=True)
72
+
73
+ print(f"Fracture description: {description}")
74
+ ```
75
+
76
+ ## 📈 Performance Comparison
77
+
78
+ | Model | ROC-AUC | F1-Score | Accuracy | Precision | Recall |
79
+ |-------|---------|----------|----------|-----------|--------|
80
+ | General MAIRA-2 (baseline) | 0.518 | 0.085 | 0.645 | 0.777 | 0.045 |
81
+ | **ChexFract-MAIRA-2** | **0.713** | **0.629** | **0.748** | **0.682** | **0.584** |
82
+ | General CheXagent (baseline) | 0.604 | 0.376 | 0.700 | 0.791 | 0.246 |
83
+ | **ChexFract-CheXagent** | **0.697** | **0.591** | **0.752** | **0.750** | **0.487** |
84
+
85
+ ## 🔬 Model Architecture
86
+
87
+ Both models share the same architecture but use different visual encoders:
88
+
89
+ - **ChexFract-MAIRA-2:**
90
+ - **Visual Encoder:** [Rad-DINO (from MAIRA-2)](https://huggingface.co/microsoft/rad-dino-maira-2)
91
+ - **Language Model:** [Phi-3.5 Vision Instruct](https://huggingface.co/microsoft/Phi-3.5-vision-instruct) (3.8B parameters)
92
+ - **Training:** Fine-tuned encoder (unfrozen) + templated text on ChexFract dataset
93
+
94
+ - **ChexFract-CheXagent:**
95
+ - **Visual Encoder:** [CheXagent-2-3b encoder](https://huggingface.co/StanfordAIMI/CheXagent-2-3b)
96
+ - **Language Model:** [Phi-3.5 Vision Instruct](https://huggingface.co/microsoft/Phi-3.5-vision-instruct) (3.8B parameters)
97
+ - **Training:** Fine-tuned encoder (unfrozen) + templated text on ChexFract dataset
98
+
99
+ ## ⚠️ Limitations and Clinical Use
100
+
101
+ **Important:** These models are designed for **research purposes**. They are **NOT intended for standalone diagnostic use**.
102
+
103
+ ## 📝 Citation
104
+
105
+ If you use these models in your research, please cite:
106
+
107
+ ```bibtex
108
+ @article{chexfract2025,
109
+ title={ChexFract: From General to Specialized - Enhancing Fracture Description Generation in Medical AI},
110
+ author={Nechaev, Nikolay and Przhezdzetskaia, Evgeniia and Umerenkov, Dmitry and Dylov, Dmitry V.},
111
+ journal={arXiv preprint arXiv:XXXX.XXXXX},
112
+ year={2025},
113
+ institution={Artificial Intelligence Research Institute (AIRI)}
114
+ }
115
+ ```
116
+
117
+ ## 📄 License
118
+
119
+ ### Model License
120
+
121
+ **Important:** These models are derivative works based on multiple pre-trained models. The license for these models is subject to the most restrictive terms among the base model licenses.
122
+
123
+ **Effective License:** These models are provided under terms compatible with the most restrictive license among the base model licenses. Users must comply with ALL applicable base model licenses.
124
+
125
+ **Base Model Licenses:**
126
+ - **Rad-DINO encoder (from MAIRA-2):** Microsoft Research License Agreement (MSRLA) - see [microsoft/rad-dino-maira-2](https://huggingface.co/microsoft/rad-dino-maira-2) for full terms
127
+ - **CheXagent-2-3b encoder:** Creative Commons Attribution Non Commercial 4.0 (CC-BY-NC-4.0) - see [StanfordAIMI/CheXagent-2-3b](https://huggingface.co/StanfordAIMI/CheXagent-2-3b) for full terms
128
+ - **Phi-3.5 Vision Instruct:** MIT License - see [microsoft/Phi-3.5-vision-instruct](https://huggingface.co/microsoft/Phi-3.5-vision-instruct) for full license terms
129
+
130
+ **⚠️ IMPORTANT - Commercial Use Restrictions:**
131
+ - **CheXagent-2-3b** uses CC-BY-NC-4.0, which **PROHIBITS commercial use** without explicit permission
132
+ - **Rad-DINO (MAIRA-2)** uses MSRLA, which typically has **restrictions on commercial use** without permission
133
+ - **Phi-3.5** uses MIT License, which allows commercial use
134
+
135
+ **The most restrictive license applies:** These models are **NOT licensed for commercial use** due to CC-BY-NC-4.0 and MSRLA restrictions. For commercial use, you must obtain appropriate licenses from the original model owners.
136
+
137
+ **Before using these models, you must:**
138
+ 1. Review the license terms of all base models in their original repositories
139
+ 2. Ensure your use case complies with all applicable licenses (especially for commercial purposes)
140
+ 3. Include appropriate attribution and copyright notices as required by each license
141
+ 4. Obtain commercial licenses if needed from model owners (Microsoft for MAIRA-2, Stanford for CheXagent)
142
+
143
+ ### Additional License Information
144
+
145
+ The fine-tuning code and modifications specific to this work may be subject to additional licensing terms. Please review all applicable licenses before commercial use.
146
+
147
+ ## 👥 Authors
148
+
149
+ - **Nikolay Nechaev** - Artificial Intelligence Research Institute (AIRI)
150
+ - **Evgeniia Przhezdzetskaia** - Artificial Intelligence Research Institute (AIRI)
151
+ - **Dmitry Umerenkov** - Artificial Intelligence Research Institute (AIRI)
152
+ - **Dmitry V. Dylov** - Artificial Intelligence Research Institute (AIRI)
153
+
154
+ ## 🔗 Related Resources
155
+
156
+ - **Paper:** [arXiv link]
157
+
158
+ ## 🙏 Acknowledgments
159
+
160
+ We thank the contributors to the MIMIC-CXR, PadChest, BIMCV-COVID19, CheXpert, and OpenI datasets for making their data publicly available. We also acknowledge the computational resources provided for this research.
161
+
162
+ ## 📧 Contact
163
+
164
+ For questions or issues, please contact:
165
+ - **Email:** nechaev@airi.net
166
+ - **Institution:** Artificial Intelligence Research Institute (AIRI), Moscow, Russia
167
+
168
+ ---
169
+
170
+ **Disclaimer:** These models are provided for research purposes only. They are not intended for clinical use without proper validation and regulatory approval.
171
+
config.json ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Data/models/phi-chex-ft",
3
+ "architectures": [
4
+ "ChexBonesForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_chexbones.ChexBonesConfig",
9
+ "AutoModelForCausalLM": "modeling_chexbones.ChexBonesForCausalLM"
10
+ },
11
+ "bos_token_id": 1,
12
+ "embd_layer": {
13
+ "embedding_cls": "image",
14
+ "projection_cls": "mlp",
15
+ "use_hd_transform": true,
16
+ "with_learnable_separator": true
17
+ },
18
+ "embd_pdrop": 0.0,
19
+ "eos_token_id": 2,
20
+ "hidden_act": "silu",
21
+ "hidden_size": 3072,
22
+ "img_processor": {
23
+ "image_dim_out": 1408,
24
+ "image_size": 448,
25
+ "model_type": "chexagent_vision_model",
26
+ "num_hidden_layers": 40
27
+ },
28
+ "initializer_range": 0.02,
29
+ "intermediate_size": 8192,
30
+ "max_position_embeddings": 131072,
31
+ "model_type": "phi3_chex",
32
+ "num_attention_heads": 32,
33
+ "num_hidden_layers": 32,
34
+ "num_key_value_heads": 32,
35
+ "original_max_position_embeddings": 4096,
36
+ "pad_token_id": 32000,
37
+ "projector_lr": 0.001,
38
+ "resid_pdrop": 0.0,
39
+ "rms_norm_eps": 1e-05,
40
+ "rope_scaling": {
41
+ "long_factor": [
42
+ 1.0800000429153442,
43
+ 1.1100000143051147,
44
+ 1.1399999856948853,
45
+ 1.340000033378601,
46
+ 1.5899999141693115,
47
+ 1.600000023841858,
48
+ 1.6200000047683716,
49
+ 2.620000123977661,
50
+ 3.2300000190734863,
51
+ 3.2300000190734863,
52
+ 4.789999961853027,
53
+ 7.400000095367432,
54
+ 7.700000286102295,
55
+ 9.09000015258789,
56
+ 12.199999809265137,
57
+ 17.670000076293945,
58
+ 24.46000099182129,
59
+ 28.57000160217285,
60
+ 30.420001983642578,
61
+ 30.840002059936523,
62
+ 32.590003967285156,
63
+ 32.93000411987305,
64
+ 42.320003509521484,
65
+ 44.96000289916992,
66
+ 50.340003967285156,
67
+ 50.45000457763672,
68
+ 57.55000305175781,
69
+ 57.93000411987305,
70
+ 58.21000289916992,
71
+ 60.1400032043457,
72
+ 62.61000442504883,
73
+ 62.62000274658203,
74
+ 62.71000289916992,
75
+ 63.1400032043457,
76
+ 63.1400032043457,
77
+ 63.77000427246094,
78
+ 63.93000411987305,
79
+ 63.96000289916992,
80
+ 63.970001220703125,
81
+ 64.02999877929688,
82
+ 64.06999969482422,
83
+ 64.08000183105469,
84
+ 64.12000274658203,
85
+ 64.41000366210938,
86
+ 64.4800033569336,
87
+ 64.51000213623047,
88
+ 64.52999877929688,
89
+ 64.83999633789062
90
+ ],
91
+ "short_factor": [
92
+ 1.08,
93
+ 1.1,
94
+ 1.1300000000000001,
95
+ 1.2800000000000002,
96
+ 1.3100000000000003,
97
+ 1.4500000000000004,
98
+ 1.4500000000000004,
99
+ 1.9500000000000008,
100
+ 2.030000000000001,
101
+ 2.4299999999999926,
102
+ 2.5699999999999896,
103
+ 2.9499999999999815,
104
+ 3.729999999999965,
105
+ 3.869999999999962,
106
+ 4.189999999999955,
107
+ 4.43999999999995,
108
+ 4.6399999999999455,
109
+ 4.979999999999938,
110
+ 5.159999999999934,
111
+ 5.279999999999932,
112
+ 5.759999999999922,
113
+ 5.889999999999919,
114
+ 5.889999999999919,
115
+ 5.969999999999917,
116
+ 6.089999999999915,
117
+ 6.2799999999999105,
118
+ 6.7699999999999,
119
+ 6.8899999999998975,
120
+ 7.109999999999893,
121
+ 7.129999999999892,
122
+ 7.179999999999891,
123
+ 7.289999999999889,
124
+ 7.339999999999888,
125
+ 7.559999999999883,
126
+ 7.619999999999882,
127
+ 7.69999999999988,
128
+ 7.879999999999876,
129
+ 7.879999999999876,
130
+ 7.879999999999876,
131
+ 7.939999999999875,
132
+ 7.949999999999875,
133
+ 7.979999999999874,
134
+ 8.19999999999987,
135
+ 8.439999999999864,
136
+ 8.469999999999864,
137
+ 8.589999999999861,
138
+ 8.809999999999857,
139
+ 8.999999999999853
140
+ ],
141
+ "type": "su"
142
+ },
143
+ "rope_theta": 10000.0,
144
+ "sliding_window": 262144,
145
+ "tie_word_embeddings": false,
146
+ "tokenizer_model_max_length": 131072,
147
+ "tokenizer_padding_side": "right",
148
+ "torch_dtype": "bfloat16",
149
+ "transformers_version": "4.45.2",
150
+ "use_cache": true,
151
+ "vision_config": {
152
+ "image_dim_out": 1408,
153
+ "image_size": 448,
154
+ "model_type": "chexagent_vision_model",
155
+ "num_hidden_layers": 40
156
+ },
157
+ "vision_lr": 2e-06,
158
+ "vocab_size": 32064
159
+ }
configuration_chexbones.py ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 Microsoft and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ from transformers.configuration_utils import PretrainedConfig
18
+ from transformers.utils import logging
19
+ from typing import Union
20
+ import os
21
+
22
+
23
+ logger = logging.get_logger(__name__)
24
+
25
+ CHEXBONES_PRETRAINED_CONFIG_ARCHIVE_MAP = {
26
+ "AIRI/chexfract-chexagent": "./config.json",
27
+ }
28
+
29
+ #from https://huggingface.co/StanfordAIMI/CheXagent-8b/blob/main/configuration_chexagent.py
30
+ class CheXagentVisionConfig(PretrainedConfig):
31
+ model_type = "chexagent_vision_model"
32
+
33
+ def __init__(
34
+ self,
35
+ hidden_size=1408,
36
+ intermediate_size=6144,
37
+ num_hidden_layers=39,
38
+ num_attention_heads=16,
39
+ image_size=224,
40
+ patch_size=14,
41
+ hidden_act="gelu",
42
+ layer_norm_eps=1e-6,
43
+ attention_dropout=0.0,
44
+ initializer_range=1e-10,
45
+ qkv_bias=True,
46
+ **kwargs,
47
+ ):
48
+ super().__init__(**kwargs)
49
+
50
+ self.hidden_size = hidden_size
51
+ self.intermediate_size = intermediate_size
52
+ self.num_hidden_layers = num_hidden_layers
53
+ self.num_attention_heads = num_attention_heads
54
+ self.patch_size = patch_size
55
+ self.image_size = image_size
56
+ self.initializer_range = initializer_range
57
+ self.attention_dropout = attention_dropout
58
+ self.layer_norm_eps = layer_norm_eps
59
+ self.hidden_act = hidden_act
60
+ self.qkv_bias = qkv_bias
61
+
62
+ @classmethod
63
+ def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
64
+ cls._set_token_in_kwargs(kwargs)
65
+
66
+ config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
67
+
68
+ if config_dict.get("model_type") == "chexagent":
69
+ config_dict = config_dict["vision_config"]
70
+
71
+ if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
72
+ logger.warning(
73
+ f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
74
+ f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
75
+ )
76
+
77
+ return cls.from_dict(config_dict, **kwargs)
78
+
79
+
80
+ class ChexBonesConfig(PretrainedConfig):
81
+ r"""
82
+ This is the configuration class to store the configuration of a [`ChexBonesModel`]. It is used to instantiate a ChexBones
83
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
84
+ defaults will yield a similar configuration to that of the
85
+ [microsoft/Phi-3-vision-128k-instruct](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct).
86
+
87
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
88
+ documentation from [`PretrainedConfig`] for more information.
89
+
90
+ Args:
91
+ vocab_size (`int`, *optional*, defaults to 32064):
92
+ Vocabulary size of the Phi-3-V model. Defines the number of different tokens that can be represented by the
93
+ `inputs_ids` passed when calling [`ChexBonesModel`].
94
+ hidden_size (`int`, *optional*, defaults to 3072):
95
+ Dimension of the hidden representations.
96
+ intermediate_size (`int`, *optional*, defaults to 8192):
97
+ Dimension of the MLP representations.
98
+ num_hidden_layers (`int`, *optional*, defaults to 32):
99
+ Number of hidden layers in the Transformer decoder.
100
+ num_attention_heads (`int`, *optional*, defaults to 32):
101
+ Number of attention heads for each attention layer in the Transformer decoder.
102
+ num_key_value_heads (`int`, *optional*):
103
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
104
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
105
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
106
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
107
+ by meanpooling all the original heads within that group. For more details checkout [this
108
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
109
+ `num_attention_heads`.
110
+ resid_pdrop (`float`, *optional*, defaults to 0.0):
111
+ Dropout probability for mlp outputs.
112
+ embd_pdrop (`int`, *optional*, defaults to 0.0):
113
+ The dropout ratio for the embeddings.
114
+ attention_dropout (`float`, *optional*, defaults to 0.0):
115
+ The dropout ratio after computing the attention scores.
116
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
117
+ The non-linear activation function (function or string) in the decoder.
118
+ max_position_embeddings (`int`, *optional*, defaults to 4096):
119
+ The maximum sequence length that this model might ever be used with.
120
+ original_max_position_embeddings (`int`, *optional*, defaults to 4096):
121
+ The maximum sequence length that this model was trained with. This is used to determine the size of the
122
+ original RoPE embeddings when using long scaling.
123
+ initializer_range (`float`, *optional*, defaults to 0.02):
124
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
125
+ rms_norm_eps (`float`, *optional*, defaults to 1e-05):
126
+ The epsilon value used for the RMSNorm.
127
+ use_cache (`bool`, *optional*, defaults to `True`):
128
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
129
+ relevant if `config.is_decoder=True`. Whether to tie weight embeddings or not.
130
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
131
+ Whether to tie weight embeddings
132
+ rope_theta (`float`, *optional*, defaults to 10000.0):
133
+ The base period of the RoPE embeddings.
134
+ rope_scaling (`dict`, *optional*):
135
+ The scaling strategy for the RoPE embeddings. If `None`, no scaling is applied. If a dictionary, it must
136
+ contain the following keys: `type`, `short_factor` and `long_factor`. The `type` must be either `su` or `yarn` and
137
+ the `short_factor` and `long_factor` must be lists of numbers with the same length as the hidden size
138
+ divided by the number of attention heads divided by 2.
139
+ bos_token_id (`int`, *optional*, defaults to 1):
140
+ The id of the "beginning-of-sequence" token.
141
+ eos_token_id (`int`, *optional*, defaults to 32000):
142
+ The id of the "end-of-sequence" token.
143
+ pad_token_id (`int`, *optional*, defaults to 32000):
144
+ The id of the padding token.
145
+ sliding_window (`int`, *optional*):
146
+ Sliding window attention window size. If `None`, no sliding window is applied.
147
+ embd_layer (`str`, *optional*, defaults to `"default"`):
148
+ The embedding layer to use. Can be either `"default"` or `"image"`. "default" uses the standard embedding for text.
149
+
150
+
151
+ ```"""
152
+
153
+ model_type = "ChexBonesModel"
154
+ keys_to_ignore_at_inference = ["past_key_values"]
155
+
156
+ def __init__(
157
+ self,
158
+ vocab_size=32064,
159
+ hidden_size=3072,
160
+ intermediate_size=8192,
161
+ num_hidden_layers=32,
162
+ num_attention_heads=32,
163
+ num_key_value_heads=None,
164
+ resid_pdrop=0.0,
165
+ embd_pdrop=0.0,
166
+ attention_dropout=0.0,
167
+ hidden_act="silu",
168
+ max_position_embeddings=4096,
169
+ original_max_position_embeddings=4096,
170
+ initializer_range=0.02,
171
+ rms_norm_eps=1e-5,
172
+ use_cache=True,
173
+ tie_word_embeddings=False,
174
+ rope_theta=10000.0,
175
+ rope_scaling=None,
176
+ bos_token_id=1,
177
+ eos_token_id=32000,
178
+ pad_token_id=32000,
179
+ sliding_window=None,
180
+ embd_layer: str = "default",
181
+ **kwargs,
182
+ ):
183
+ self.vocab_size = vocab_size
184
+ self.hidden_size = hidden_size
185
+ self.intermediate_size = intermediate_size
186
+ self.num_hidden_layers = num_hidden_layers
187
+ self.num_attention_heads = num_attention_heads
188
+
189
+ if num_key_value_heads is None:
190
+ num_key_value_heads = num_attention_heads
191
+
192
+ self.num_key_value_heads = num_key_value_heads
193
+ self.resid_pdrop = resid_pdrop
194
+ self.embd_pdrop = embd_pdrop
195
+ self.attention_dropout = attention_dropout
196
+ self.hidden_act = hidden_act
197
+ self.max_position_embeddings = max_position_embeddings
198
+ self.original_max_position_embeddings = original_max_position_embeddings
199
+ self.initializer_range = initializer_range
200
+ self.rms_norm_eps = rms_norm_eps
201
+ self.use_cache = use_cache
202
+ self.rope_theta = rope_theta
203
+ self.rope_scaling = rope_scaling
204
+ self._rope_scaling_validation()
205
+ self.sliding_window = sliding_window
206
+ self.embd_layer = embd_layer
207
+
208
+
209
+
210
+ super().__init__(
211
+ bos_token_id=bos_token_id,
212
+ eos_token_id=eos_token_id,
213
+ pad_token_id=pad_token_id,
214
+ tie_word_embeddings=tie_word_embeddings,
215
+ **kwargs,
216
+ )
217
+
218
+ def _rope_scaling_validation(self):
219
+ """
220
+ Validate the `rope_scaling` configuration.
221
+ """
222
+ if self.rope_scaling is None:
223
+ return
224
+
225
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 3:
226
+ raise ValueError(
227
+ "`rope_scaling` must be a dictionary with three fields, `type`, `short_factor` and `long_factor`, "
228
+ f"got {self.rope_scaling}"
229
+ )
230
+ rope_scaling_type = self.rope_scaling.get("type", None)
231
+ rope_scaling_short_factor = self.rope_scaling.get("short_factor", None)
232
+ rope_scaling_long_factor = self.rope_scaling.get("long_factor", None)
233
+ if rope_scaling_type is None or rope_scaling_type not in ["su", "yarn"]:
234
+ raise ValueError(f"`rope_scaling`'s type field must be one of ['su', 'yarn'], got {rope_scaling_type}")
235
+ if not (
236
+ isinstance(rope_scaling_short_factor, list)
237
+ and all(isinstance(x, (int, float)) for x in rope_scaling_short_factor)
238
+ ):
239
+ raise ValueError(
240
+ f"`rope_scaling`'s short_factor field must be a list of numbers, got {rope_scaling_short_factor}"
241
+ )
242
+ if not len(rope_scaling_short_factor) == self.hidden_size // self.num_attention_heads // 2:
243
+ raise ValueError(
244
+ f"`rope_scaling`'s short_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_short_factor)}"
245
+ )
246
+ if not (
247
+ isinstance(rope_scaling_long_factor, list)
248
+ and all(isinstance(x, (int, float)) for x in rope_scaling_long_factor)
249
+ ):
250
+ raise ValueError(
251
+ f"`rope_scaling`'s long_factor field must be a list of numbers, got {rope_scaling_long_factor}"
252
+ )
253
+ if not len(rope_scaling_long_factor) == self.hidden_size // self.num_attention_heads // 2:
254
+ raise ValueError(
255
+ f"`rope_scaling`'s long_factor field must have length {self.hidden_size // self.num_attention_heads // 2}, got {len(rope_scaling_long_factor)}"
256
+ )
257
+
258
+
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "pad_token_id": 32000,
6
+ "transformers_version": "4.45.2"
7
+ }
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba0630022adc950718b911810b669e270ebc349e4f1629e6bfc3f2f7ab718c97
3
+ size 4986119408
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:265cf10ffe36ab5f0cef5cef718e27b7ac3db7694553cb96380ea34cd3a8e400
3
+ size 4708241232
model.safetensors.index.json ADDED
@@ -0,0 +1,692 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 9694264064
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00002-of-00002.safetensors",
7
+ "model.embed_tokens.weight": "model-00001-of-00002.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
14
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
15
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
16
+ "model.layers.1.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
17
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
18
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
19
+ "model.layers.1.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
20
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
21
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.10.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
24
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
25
+ "model.layers.10.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
26
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
27
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
28
+ "model.layers.11.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
29
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
30
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
31
+ "model.layers.11.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.12.input_layernorm.weight": "model-00002-of-00002.safetensors",
33
+ "model.layers.12.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
34
+ "model.layers.12.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
35
+ "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
36
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
37
+ "model.layers.12.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
38
+ "model.layers.13.input_layernorm.weight": "model-00002-of-00002.safetensors",
39
+ "model.layers.13.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
40
+ "model.layers.13.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
41
+ "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
42
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
43
+ "model.layers.13.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
44
+ "model.layers.14.input_layernorm.weight": "model-00002-of-00002.safetensors",
45
+ "model.layers.14.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
46
+ "model.layers.14.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
47
+ "model.layers.14.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
48
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
49
+ "model.layers.14.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
50
+ "model.layers.15.input_layernorm.weight": "model-00002-of-00002.safetensors",
51
+ "model.layers.15.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
52
+ "model.layers.15.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
53
+ "model.layers.15.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
54
+ "model.layers.15.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
55
+ "model.layers.15.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
56
+ "model.layers.16.input_layernorm.weight": "model-00002-of-00002.safetensors",
57
+ "model.layers.16.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
58
+ "model.layers.16.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
59
+ "model.layers.16.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
60
+ "model.layers.16.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
61
+ "model.layers.16.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
62
+ "model.layers.17.input_layernorm.weight": "model-00002-of-00002.safetensors",
63
+ "model.layers.17.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
64
+ "model.layers.17.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
65
+ "model.layers.17.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
66
+ "model.layers.17.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
67
+ "model.layers.17.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
68
+ "model.layers.18.input_layernorm.weight": "model-00002-of-00002.safetensors",
69
+ "model.layers.18.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
70
+ "model.layers.18.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
71
+ "model.layers.18.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
72
+ "model.layers.18.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
73
+ "model.layers.18.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
74
+ "model.layers.19.input_layernorm.weight": "model-00002-of-00002.safetensors",
75
+ "model.layers.19.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
76
+ "model.layers.19.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
77
+ "model.layers.19.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
78
+ "model.layers.19.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
79
+ "model.layers.19.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
80
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
81
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
82
+ "model.layers.2.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
83
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
84
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
85
+ "model.layers.2.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
86
+ "model.layers.20.input_layernorm.weight": "model-00002-of-00002.safetensors",
87
+ "model.layers.20.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
88
+ "model.layers.20.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
89
+ "model.layers.20.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
90
+ "model.layers.20.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
91
+ "model.layers.20.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
92
+ "model.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
93
+ "model.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
94
+ "model.layers.21.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
95
+ "model.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
96
+ "model.layers.21.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
97
+ "model.layers.21.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
98
+ "model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
99
+ "model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
100
+ "model.layers.22.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
101
+ "model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
102
+ "model.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
103
+ "model.layers.22.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
104
+ "model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
105
+ "model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
106
+ "model.layers.23.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
107
+ "model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
108
+ "model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
109
+ "model.layers.23.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
110
+ "model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
111
+ "model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
112
+ "model.layers.24.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
113
+ "model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
114
+ "model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
115
+ "model.layers.24.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
116
+ "model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
117
+ "model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
118
+ "model.layers.25.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
119
+ "model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
120
+ "model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
121
+ "model.layers.25.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
122
+ "model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
123
+ "model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
124
+ "model.layers.26.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
125
+ "model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
126
+ "model.layers.26.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
127
+ "model.layers.26.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
128
+ "model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
129
+ "model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
130
+ "model.layers.27.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
131
+ "model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
132
+ "model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
133
+ "model.layers.27.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
134
+ "model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
135
+ "model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
136
+ "model.layers.28.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
137
+ "model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
138
+ "model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
139
+ "model.layers.28.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
140
+ "model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
141
+ "model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
142
+ "model.layers.29.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
143
+ "model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
144
+ "model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
145
+ "model.layers.29.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
146
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
147
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
148
+ "model.layers.3.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
149
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
150
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
151
+ "model.layers.3.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
152
+ "model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
153
+ "model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
154
+ "model.layers.30.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
155
+ "model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
156
+ "model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
157
+ "model.layers.30.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
158
+ "model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
159
+ "model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
160
+ "model.layers.31.mlp.gate_up_proj.weight": "model-00002-of-00002.safetensors",
161
+ "model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
162
+ "model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
163
+ "model.layers.31.self_attn.qkv_proj.weight": "model-00002-of-00002.safetensors",
164
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
165
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
166
+ "model.layers.4.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
167
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
168
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
169
+ "model.layers.4.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
170
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
171
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
172
+ "model.layers.5.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
173
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
174
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
175
+ "model.layers.5.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
176
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
177
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
178
+ "model.layers.6.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
179
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
180
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
181
+ "model.layers.6.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
182
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
183
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
184
+ "model.layers.7.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
185
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
186
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
187
+ "model.layers.7.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
188
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
189
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
190
+ "model.layers.8.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
191
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
192
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
193
+ "model.layers.8.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
194
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
195
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
196
+ "model.layers.9.mlp.gate_up_proj.weight": "model-00001-of-00002.safetensors",
197
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
198
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
199
+ "model.layers.9.self_attn.qkv_proj.weight": "model-00001-of-00002.safetensors",
200
+ "model.norm.weight": "model-00002-of-00002.safetensors",
201
+ "model.vision_embed_tokens.img_processor.embeddings.class_embedding": "model-00001-of-00002.safetensors",
202
+ "model.vision_embed_tokens.img_processor.embeddings.patch_embedding.bias": "model-00001-of-00002.safetensors",
203
+ "model.vision_embed_tokens.img_processor.embeddings.patch_embedding.weight": "model-00001-of-00002.safetensors",
204
+ "model.vision_embed_tokens.img_processor.embeddings.position_embedding": "model-00001-of-00002.safetensors",
205
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.layer_norm1.bias": "model-00001-of-00002.safetensors",
206
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.layer_norm1.weight": "model-00001-of-00002.safetensors",
207
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.layer_norm2.bias": "model-00001-of-00002.safetensors",
208
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.layer_norm2.weight": "model-00001-of-00002.safetensors",
209
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.mlp.fc1.bias": "model-00001-of-00002.safetensors",
210
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.mlp.fc1.weight": "model-00001-of-00002.safetensors",
211
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.mlp.fc2.bias": "model-00001-of-00002.safetensors",
212
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.mlp.fc2.weight": "model-00001-of-00002.safetensors",
213
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.self_attn.projection.bias": "model-00001-of-00002.safetensors",
214
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.self_attn.projection.weight": "model-00001-of-00002.safetensors",
215
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
216
+ "model.vision_embed_tokens.img_processor.encoder.layers.0.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
217
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.layer_norm1.bias": "model-00001-of-00002.safetensors",
218
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.layer_norm1.weight": "model-00001-of-00002.safetensors",
219
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.layer_norm2.bias": "model-00001-of-00002.safetensors",
220
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.layer_norm2.weight": "model-00001-of-00002.safetensors",
221
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.mlp.fc1.bias": "model-00001-of-00002.safetensors",
222
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.mlp.fc1.weight": "model-00001-of-00002.safetensors",
223
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.mlp.fc2.bias": "model-00001-of-00002.safetensors",
224
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.mlp.fc2.weight": "model-00001-of-00002.safetensors",
225
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.self_attn.projection.bias": "model-00001-of-00002.safetensors",
226
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.self_attn.projection.weight": "model-00001-of-00002.safetensors",
227
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
228
+ "model.vision_embed_tokens.img_processor.encoder.layers.1.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
229
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.layer_norm1.bias": "model-00001-of-00002.safetensors",
230
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.layer_norm1.weight": "model-00001-of-00002.safetensors",
231
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.layer_norm2.bias": "model-00001-of-00002.safetensors",
232
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.layer_norm2.weight": "model-00001-of-00002.safetensors",
233
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.mlp.fc1.bias": "model-00001-of-00002.safetensors",
234
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.mlp.fc1.weight": "model-00001-of-00002.safetensors",
235
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.mlp.fc2.bias": "model-00001-of-00002.safetensors",
236
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.mlp.fc2.weight": "model-00001-of-00002.safetensors",
237
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.self_attn.projection.bias": "model-00001-of-00002.safetensors",
238
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.self_attn.projection.weight": "model-00001-of-00002.safetensors",
239
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
240
+ "model.vision_embed_tokens.img_processor.encoder.layers.10.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
241
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.layer_norm1.bias": "model-00001-of-00002.safetensors",
242
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.layer_norm1.weight": "model-00001-of-00002.safetensors",
243
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.layer_norm2.bias": "model-00001-of-00002.safetensors",
244
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.layer_norm2.weight": "model-00001-of-00002.safetensors",
245
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.mlp.fc1.bias": "model-00001-of-00002.safetensors",
246
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.mlp.fc1.weight": "model-00001-of-00002.safetensors",
247
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.mlp.fc2.bias": "model-00001-of-00002.safetensors",
248
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.mlp.fc2.weight": "model-00001-of-00002.safetensors",
249
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.self_attn.projection.bias": "model-00001-of-00002.safetensors",
250
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.self_attn.projection.weight": "model-00001-of-00002.safetensors",
251
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
252
+ "model.vision_embed_tokens.img_processor.encoder.layers.11.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
253
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.layer_norm1.bias": "model-00001-of-00002.safetensors",
254
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.layer_norm1.weight": "model-00001-of-00002.safetensors",
255
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.layer_norm2.bias": "model-00001-of-00002.safetensors",
256
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.layer_norm2.weight": "model-00001-of-00002.safetensors",
257
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.mlp.fc1.bias": "model-00001-of-00002.safetensors",
258
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.mlp.fc1.weight": "model-00001-of-00002.safetensors",
259
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.mlp.fc2.bias": "model-00001-of-00002.safetensors",
260
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.mlp.fc2.weight": "model-00001-of-00002.safetensors",
261
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.self_attn.projection.bias": "model-00001-of-00002.safetensors",
262
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.self_attn.projection.weight": "model-00001-of-00002.safetensors",
263
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
264
+ "model.vision_embed_tokens.img_processor.encoder.layers.12.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
265
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.layer_norm1.bias": "model-00001-of-00002.safetensors",
266
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.layer_norm1.weight": "model-00001-of-00002.safetensors",
267
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.layer_norm2.bias": "model-00001-of-00002.safetensors",
268
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.layer_norm2.weight": "model-00001-of-00002.safetensors",
269
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.mlp.fc1.bias": "model-00001-of-00002.safetensors",
270
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.mlp.fc1.weight": "model-00001-of-00002.safetensors",
271
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.mlp.fc2.bias": "model-00001-of-00002.safetensors",
272
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.mlp.fc2.weight": "model-00001-of-00002.safetensors",
273
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.self_attn.projection.bias": "model-00001-of-00002.safetensors",
274
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.self_attn.projection.weight": "model-00001-of-00002.safetensors",
275
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
276
+ "model.vision_embed_tokens.img_processor.encoder.layers.13.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
277
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.layer_norm1.bias": "model-00001-of-00002.safetensors",
278
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.layer_norm1.weight": "model-00001-of-00002.safetensors",
279
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.layer_norm2.bias": "model-00001-of-00002.safetensors",
280
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.layer_norm2.weight": "model-00001-of-00002.safetensors",
281
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.mlp.fc1.bias": "model-00001-of-00002.safetensors",
282
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.mlp.fc1.weight": "model-00001-of-00002.safetensors",
283
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.mlp.fc2.bias": "model-00001-of-00002.safetensors",
284
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.mlp.fc2.weight": "model-00001-of-00002.safetensors",
285
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.self_attn.projection.bias": "model-00001-of-00002.safetensors",
286
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.self_attn.projection.weight": "model-00001-of-00002.safetensors",
287
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
288
+ "model.vision_embed_tokens.img_processor.encoder.layers.14.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
289
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.layer_norm1.bias": "model-00001-of-00002.safetensors",
290
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.layer_norm1.weight": "model-00001-of-00002.safetensors",
291
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.layer_norm2.bias": "model-00001-of-00002.safetensors",
292
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.layer_norm2.weight": "model-00001-of-00002.safetensors",
293
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.mlp.fc1.bias": "model-00001-of-00002.safetensors",
294
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.mlp.fc1.weight": "model-00001-of-00002.safetensors",
295
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.mlp.fc2.bias": "model-00001-of-00002.safetensors",
296
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.mlp.fc2.weight": "model-00001-of-00002.safetensors",
297
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.self_attn.projection.bias": "model-00001-of-00002.safetensors",
298
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.self_attn.projection.weight": "model-00001-of-00002.safetensors",
299
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
300
+ "model.vision_embed_tokens.img_processor.encoder.layers.15.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
301
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.layer_norm1.bias": "model-00001-of-00002.safetensors",
302
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.layer_norm1.weight": "model-00001-of-00002.safetensors",
303
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.layer_norm2.bias": "model-00001-of-00002.safetensors",
304
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.layer_norm2.weight": "model-00001-of-00002.safetensors",
305
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.mlp.fc1.bias": "model-00001-of-00002.safetensors",
306
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.mlp.fc1.weight": "model-00001-of-00002.safetensors",
307
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.mlp.fc2.bias": "model-00001-of-00002.safetensors",
308
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.mlp.fc2.weight": "model-00001-of-00002.safetensors",
309
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.self_attn.projection.bias": "model-00001-of-00002.safetensors",
310
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.self_attn.projection.weight": "model-00001-of-00002.safetensors",
311
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
312
+ "model.vision_embed_tokens.img_processor.encoder.layers.16.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
313
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.layer_norm1.bias": "model-00001-of-00002.safetensors",
314
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.layer_norm1.weight": "model-00001-of-00002.safetensors",
315
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.layer_norm2.bias": "model-00001-of-00002.safetensors",
316
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.layer_norm2.weight": "model-00001-of-00002.safetensors",
317
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.mlp.fc1.bias": "model-00001-of-00002.safetensors",
318
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.mlp.fc1.weight": "model-00001-of-00002.safetensors",
319
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.mlp.fc2.bias": "model-00001-of-00002.safetensors",
320
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.mlp.fc2.weight": "model-00001-of-00002.safetensors",
321
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.self_attn.projection.bias": "model-00001-of-00002.safetensors",
322
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.self_attn.projection.weight": "model-00001-of-00002.safetensors",
323
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
324
+ "model.vision_embed_tokens.img_processor.encoder.layers.17.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
325
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.layer_norm1.bias": "model-00001-of-00002.safetensors",
326
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.layer_norm1.weight": "model-00001-of-00002.safetensors",
327
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.layer_norm2.bias": "model-00001-of-00002.safetensors",
328
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.layer_norm2.weight": "model-00001-of-00002.safetensors",
329
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.mlp.fc1.bias": "model-00001-of-00002.safetensors",
330
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.mlp.fc1.weight": "model-00001-of-00002.safetensors",
331
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.mlp.fc2.bias": "model-00001-of-00002.safetensors",
332
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.mlp.fc2.weight": "model-00001-of-00002.safetensors",
333
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.self_attn.projection.bias": "model-00001-of-00002.safetensors",
334
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.self_attn.projection.weight": "model-00001-of-00002.safetensors",
335
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
336
+ "model.vision_embed_tokens.img_processor.encoder.layers.18.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
337
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.layer_norm1.bias": "model-00001-of-00002.safetensors",
338
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.layer_norm1.weight": "model-00001-of-00002.safetensors",
339
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.layer_norm2.bias": "model-00001-of-00002.safetensors",
340
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.layer_norm2.weight": "model-00001-of-00002.safetensors",
341
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.mlp.fc1.bias": "model-00001-of-00002.safetensors",
342
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.mlp.fc1.weight": "model-00001-of-00002.safetensors",
343
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.mlp.fc2.bias": "model-00001-of-00002.safetensors",
344
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.mlp.fc2.weight": "model-00001-of-00002.safetensors",
345
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.self_attn.projection.bias": "model-00001-of-00002.safetensors",
346
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.self_attn.projection.weight": "model-00001-of-00002.safetensors",
347
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
348
+ "model.vision_embed_tokens.img_processor.encoder.layers.19.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
349
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.layer_norm1.bias": "model-00001-of-00002.safetensors",
350
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.layer_norm1.weight": "model-00001-of-00002.safetensors",
351
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.layer_norm2.bias": "model-00001-of-00002.safetensors",
352
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.layer_norm2.weight": "model-00001-of-00002.safetensors",
353
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.mlp.fc1.bias": "model-00001-of-00002.safetensors",
354
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.mlp.fc1.weight": "model-00001-of-00002.safetensors",
355
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.mlp.fc2.bias": "model-00001-of-00002.safetensors",
356
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.mlp.fc2.weight": "model-00001-of-00002.safetensors",
357
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.self_attn.projection.bias": "model-00001-of-00002.safetensors",
358
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.self_attn.projection.weight": "model-00001-of-00002.safetensors",
359
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
360
+ "model.vision_embed_tokens.img_processor.encoder.layers.2.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
361
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.layer_norm1.bias": "model-00001-of-00002.safetensors",
362
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.layer_norm1.weight": "model-00001-of-00002.safetensors",
363
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.layer_norm2.bias": "model-00001-of-00002.safetensors",
364
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.layer_norm2.weight": "model-00001-of-00002.safetensors",
365
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.mlp.fc1.bias": "model-00001-of-00002.safetensors",
366
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.mlp.fc1.weight": "model-00001-of-00002.safetensors",
367
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.mlp.fc2.bias": "model-00001-of-00002.safetensors",
368
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.mlp.fc2.weight": "model-00001-of-00002.safetensors",
369
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.self_attn.projection.bias": "model-00001-of-00002.safetensors",
370
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.self_attn.projection.weight": "model-00001-of-00002.safetensors",
371
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
372
+ "model.vision_embed_tokens.img_processor.encoder.layers.20.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
373
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.layer_norm1.bias": "model-00001-of-00002.safetensors",
374
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.layer_norm1.weight": "model-00001-of-00002.safetensors",
375
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.layer_norm2.bias": "model-00001-of-00002.safetensors",
376
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.layer_norm2.weight": "model-00001-of-00002.safetensors",
377
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.mlp.fc1.bias": "model-00001-of-00002.safetensors",
378
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.mlp.fc1.weight": "model-00001-of-00002.safetensors",
379
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.mlp.fc2.bias": "model-00001-of-00002.safetensors",
380
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.mlp.fc2.weight": "model-00001-of-00002.safetensors",
381
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.self_attn.projection.bias": "model-00001-of-00002.safetensors",
382
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.self_attn.projection.weight": "model-00001-of-00002.safetensors",
383
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
384
+ "model.vision_embed_tokens.img_processor.encoder.layers.21.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
385
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.layer_norm1.bias": "model-00001-of-00002.safetensors",
386
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.layer_norm1.weight": "model-00001-of-00002.safetensors",
387
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.layer_norm2.bias": "model-00001-of-00002.safetensors",
388
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.layer_norm2.weight": "model-00001-of-00002.safetensors",
389
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.mlp.fc1.bias": "model-00001-of-00002.safetensors",
390
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.mlp.fc1.weight": "model-00001-of-00002.safetensors",
391
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.mlp.fc2.bias": "model-00001-of-00002.safetensors",
392
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.mlp.fc2.weight": "model-00001-of-00002.safetensors",
393
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.self_attn.projection.bias": "model-00001-of-00002.safetensors",
394
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.self_attn.projection.weight": "model-00001-of-00002.safetensors",
395
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
396
+ "model.vision_embed_tokens.img_processor.encoder.layers.22.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
397
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.layer_norm1.bias": "model-00001-of-00002.safetensors",
398
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.layer_norm1.weight": "model-00001-of-00002.safetensors",
399
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.layer_norm2.bias": "model-00001-of-00002.safetensors",
400
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.layer_norm2.weight": "model-00001-of-00002.safetensors",
401
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.mlp.fc1.bias": "model-00001-of-00002.safetensors",
402
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.mlp.fc1.weight": "model-00001-of-00002.safetensors",
403
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.mlp.fc2.bias": "model-00001-of-00002.safetensors",
404
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.mlp.fc2.weight": "model-00001-of-00002.safetensors",
405
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.self_attn.projection.bias": "model-00001-of-00002.safetensors",
406
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.self_attn.projection.weight": "model-00001-of-00002.safetensors",
407
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
408
+ "model.vision_embed_tokens.img_processor.encoder.layers.23.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
409
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.layer_norm1.bias": "model-00001-of-00002.safetensors",
410
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.layer_norm1.weight": "model-00001-of-00002.safetensors",
411
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.layer_norm2.bias": "model-00001-of-00002.safetensors",
412
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.layer_norm2.weight": "model-00001-of-00002.safetensors",
413
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.mlp.fc1.bias": "model-00001-of-00002.safetensors",
414
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.mlp.fc1.weight": "model-00001-of-00002.safetensors",
415
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.mlp.fc2.bias": "model-00001-of-00002.safetensors",
416
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.mlp.fc2.weight": "model-00001-of-00002.safetensors",
417
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.self_attn.projection.bias": "model-00001-of-00002.safetensors",
418
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.self_attn.projection.weight": "model-00001-of-00002.safetensors",
419
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
420
+ "model.vision_embed_tokens.img_processor.encoder.layers.24.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
421
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.layer_norm1.bias": "model-00001-of-00002.safetensors",
422
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.layer_norm1.weight": "model-00001-of-00002.safetensors",
423
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.layer_norm2.bias": "model-00001-of-00002.safetensors",
424
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.layer_norm2.weight": "model-00001-of-00002.safetensors",
425
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.mlp.fc1.bias": "model-00001-of-00002.safetensors",
426
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.mlp.fc1.weight": "model-00001-of-00002.safetensors",
427
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.mlp.fc2.bias": "model-00001-of-00002.safetensors",
428
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.mlp.fc2.weight": "model-00001-of-00002.safetensors",
429
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.self_attn.projection.bias": "model-00001-of-00002.safetensors",
430
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.self_attn.projection.weight": "model-00001-of-00002.safetensors",
431
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
432
+ "model.vision_embed_tokens.img_processor.encoder.layers.25.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
433
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.layer_norm1.bias": "model-00001-of-00002.safetensors",
434
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.layer_norm1.weight": "model-00001-of-00002.safetensors",
435
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.layer_norm2.bias": "model-00001-of-00002.safetensors",
436
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.layer_norm2.weight": "model-00001-of-00002.safetensors",
437
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.mlp.fc1.bias": "model-00001-of-00002.safetensors",
438
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.mlp.fc1.weight": "model-00001-of-00002.safetensors",
439
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.mlp.fc2.bias": "model-00001-of-00002.safetensors",
440
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.mlp.fc2.weight": "model-00001-of-00002.safetensors",
441
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.self_attn.projection.bias": "model-00001-of-00002.safetensors",
442
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.self_attn.projection.weight": "model-00001-of-00002.safetensors",
443
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
444
+ "model.vision_embed_tokens.img_processor.encoder.layers.26.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
445
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.layer_norm1.bias": "model-00001-of-00002.safetensors",
446
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.layer_norm1.weight": "model-00001-of-00002.safetensors",
447
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.layer_norm2.bias": "model-00001-of-00002.safetensors",
448
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.layer_norm2.weight": "model-00001-of-00002.safetensors",
449
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.mlp.fc1.bias": "model-00001-of-00002.safetensors",
450
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.mlp.fc1.weight": "model-00001-of-00002.safetensors",
451
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.mlp.fc2.bias": "model-00001-of-00002.safetensors",
452
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.mlp.fc2.weight": "model-00001-of-00002.safetensors",
453
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.self_attn.projection.bias": "model-00001-of-00002.safetensors",
454
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.self_attn.projection.weight": "model-00001-of-00002.safetensors",
455
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
456
+ "model.vision_embed_tokens.img_processor.encoder.layers.27.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
457
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.layer_norm1.bias": "model-00001-of-00002.safetensors",
458
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.layer_norm1.weight": "model-00001-of-00002.safetensors",
459
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.layer_norm2.bias": "model-00001-of-00002.safetensors",
460
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.layer_norm2.weight": "model-00001-of-00002.safetensors",
461
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.mlp.fc1.bias": "model-00001-of-00002.safetensors",
462
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.mlp.fc1.weight": "model-00001-of-00002.safetensors",
463
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.mlp.fc2.bias": "model-00001-of-00002.safetensors",
464
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.mlp.fc2.weight": "model-00001-of-00002.safetensors",
465
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.self_attn.projection.bias": "model-00001-of-00002.safetensors",
466
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.self_attn.projection.weight": "model-00001-of-00002.safetensors",
467
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
468
+ "model.vision_embed_tokens.img_processor.encoder.layers.28.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
469
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.layer_norm1.bias": "model-00001-of-00002.safetensors",
470
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.layer_norm1.weight": "model-00001-of-00002.safetensors",
471
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.layer_norm2.bias": "model-00001-of-00002.safetensors",
472
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.layer_norm2.weight": "model-00001-of-00002.safetensors",
473
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.mlp.fc1.bias": "model-00001-of-00002.safetensors",
474
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.mlp.fc1.weight": "model-00001-of-00002.safetensors",
475
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.mlp.fc2.bias": "model-00001-of-00002.safetensors",
476
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.mlp.fc2.weight": "model-00001-of-00002.safetensors",
477
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.self_attn.projection.bias": "model-00001-of-00002.safetensors",
478
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.self_attn.projection.weight": "model-00001-of-00002.safetensors",
479
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
480
+ "model.vision_embed_tokens.img_processor.encoder.layers.29.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
481
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.layer_norm1.bias": "model-00001-of-00002.safetensors",
482
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.layer_norm1.weight": "model-00001-of-00002.safetensors",
483
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.layer_norm2.bias": "model-00001-of-00002.safetensors",
484
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.layer_norm2.weight": "model-00001-of-00002.safetensors",
485
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.mlp.fc1.bias": "model-00001-of-00002.safetensors",
486
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.mlp.fc1.weight": "model-00001-of-00002.safetensors",
487
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.mlp.fc2.bias": "model-00001-of-00002.safetensors",
488
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.mlp.fc2.weight": "model-00001-of-00002.safetensors",
489
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.self_attn.projection.bias": "model-00001-of-00002.safetensors",
490
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.self_attn.projection.weight": "model-00001-of-00002.safetensors",
491
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
492
+ "model.vision_embed_tokens.img_processor.encoder.layers.3.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
493
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.layer_norm1.bias": "model-00001-of-00002.safetensors",
494
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.layer_norm1.weight": "model-00001-of-00002.safetensors",
495
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.layer_norm2.bias": "model-00001-of-00002.safetensors",
496
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.layer_norm2.weight": "model-00001-of-00002.safetensors",
497
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.mlp.fc1.bias": "model-00001-of-00002.safetensors",
498
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.mlp.fc1.weight": "model-00001-of-00002.safetensors",
499
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.mlp.fc2.bias": "model-00001-of-00002.safetensors",
500
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.mlp.fc2.weight": "model-00001-of-00002.safetensors",
501
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.self_attn.projection.bias": "model-00001-of-00002.safetensors",
502
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.self_attn.projection.weight": "model-00001-of-00002.safetensors",
503
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
504
+ "model.vision_embed_tokens.img_processor.encoder.layers.30.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
505
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.layer_norm1.bias": "model-00001-of-00002.safetensors",
506
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.layer_norm1.weight": "model-00001-of-00002.safetensors",
507
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.layer_norm2.bias": "model-00001-of-00002.safetensors",
508
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.layer_norm2.weight": "model-00001-of-00002.safetensors",
509
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.mlp.fc1.bias": "model-00001-of-00002.safetensors",
510
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.mlp.fc1.weight": "model-00001-of-00002.safetensors",
511
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.mlp.fc2.bias": "model-00001-of-00002.safetensors",
512
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.mlp.fc2.weight": "model-00001-of-00002.safetensors",
513
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.self_attn.projection.bias": "model-00001-of-00002.safetensors",
514
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.self_attn.projection.weight": "model-00001-of-00002.safetensors",
515
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
516
+ "model.vision_embed_tokens.img_processor.encoder.layers.31.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
517
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.layer_norm1.bias": "model-00001-of-00002.safetensors",
518
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.layer_norm1.weight": "model-00001-of-00002.safetensors",
519
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.layer_norm2.bias": "model-00001-of-00002.safetensors",
520
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.layer_norm2.weight": "model-00001-of-00002.safetensors",
521
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.mlp.fc1.bias": "model-00001-of-00002.safetensors",
522
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.mlp.fc1.weight": "model-00001-of-00002.safetensors",
523
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.mlp.fc2.bias": "model-00001-of-00002.safetensors",
524
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.mlp.fc2.weight": "model-00001-of-00002.safetensors",
525
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.self_attn.projection.bias": "model-00001-of-00002.safetensors",
526
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.self_attn.projection.weight": "model-00001-of-00002.safetensors",
527
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
528
+ "model.vision_embed_tokens.img_processor.encoder.layers.32.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
529
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.layer_norm1.bias": "model-00001-of-00002.safetensors",
530
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.layer_norm1.weight": "model-00001-of-00002.safetensors",
531
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.layer_norm2.bias": "model-00001-of-00002.safetensors",
532
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.layer_norm2.weight": "model-00001-of-00002.safetensors",
533
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.mlp.fc1.bias": "model-00001-of-00002.safetensors",
534
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.mlp.fc1.weight": "model-00001-of-00002.safetensors",
535
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.mlp.fc2.bias": "model-00001-of-00002.safetensors",
536
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.mlp.fc2.weight": "model-00001-of-00002.safetensors",
537
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.self_attn.projection.bias": "model-00001-of-00002.safetensors",
538
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.self_attn.projection.weight": "model-00001-of-00002.safetensors",
539
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
540
+ "model.vision_embed_tokens.img_processor.encoder.layers.33.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
541
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.layer_norm1.bias": "model-00001-of-00002.safetensors",
542
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.layer_norm1.weight": "model-00001-of-00002.safetensors",
543
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.layer_norm2.bias": "model-00001-of-00002.safetensors",
544
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.layer_norm2.weight": "model-00001-of-00002.safetensors",
545
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.mlp.fc1.bias": "model-00001-of-00002.safetensors",
546
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.mlp.fc1.weight": "model-00001-of-00002.safetensors",
547
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.mlp.fc2.bias": "model-00001-of-00002.safetensors",
548
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.mlp.fc2.weight": "model-00001-of-00002.safetensors",
549
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.self_attn.projection.bias": "model-00001-of-00002.safetensors",
550
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.self_attn.projection.weight": "model-00001-of-00002.safetensors",
551
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
552
+ "model.vision_embed_tokens.img_processor.encoder.layers.34.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
553
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.layer_norm1.bias": "model-00001-of-00002.safetensors",
554
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.layer_norm1.weight": "model-00001-of-00002.safetensors",
555
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.layer_norm2.bias": "model-00001-of-00002.safetensors",
556
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.layer_norm2.weight": "model-00001-of-00002.safetensors",
557
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.mlp.fc1.bias": "model-00001-of-00002.safetensors",
558
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.mlp.fc1.weight": "model-00001-of-00002.safetensors",
559
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.mlp.fc2.bias": "model-00001-of-00002.safetensors",
560
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.mlp.fc2.weight": "model-00001-of-00002.safetensors",
561
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.self_attn.projection.bias": "model-00001-of-00002.safetensors",
562
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.self_attn.projection.weight": "model-00001-of-00002.safetensors",
563
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
564
+ "model.vision_embed_tokens.img_processor.encoder.layers.35.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
565
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.layer_norm1.bias": "model-00001-of-00002.safetensors",
566
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.layer_norm1.weight": "model-00001-of-00002.safetensors",
567
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.layer_norm2.bias": "model-00001-of-00002.safetensors",
568
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.layer_norm2.weight": "model-00001-of-00002.safetensors",
569
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.mlp.fc1.bias": "model-00001-of-00002.safetensors",
570
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.mlp.fc1.weight": "model-00001-of-00002.safetensors",
571
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.mlp.fc2.bias": "model-00001-of-00002.safetensors",
572
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.mlp.fc2.weight": "model-00001-of-00002.safetensors",
573
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.self_attn.projection.bias": "model-00001-of-00002.safetensors",
574
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.self_attn.projection.weight": "model-00001-of-00002.safetensors",
575
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
576
+ "model.vision_embed_tokens.img_processor.encoder.layers.36.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
577
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.layer_norm1.bias": "model-00001-of-00002.safetensors",
578
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.layer_norm1.weight": "model-00001-of-00002.safetensors",
579
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.layer_norm2.bias": "model-00001-of-00002.safetensors",
580
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.layer_norm2.weight": "model-00001-of-00002.safetensors",
581
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.mlp.fc1.bias": "model-00001-of-00002.safetensors",
582
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.mlp.fc1.weight": "model-00001-of-00002.safetensors",
583
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.mlp.fc2.bias": "model-00001-of-00002.safetensors",
584
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.mlp.fc2.weight": "model-00001-of-00002.safetensors",
585
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.self_attn.projection.bias": "model-00001-of-00002.safetensors",
586
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.self_attn.projection.weight": "model-00001-of-00002.safetensors",
587
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
588
+ "model.vision_embed_tokens.img_processor.encoder.layers.37.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
589
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.layer_norm1.bias": "model-00001-of-00002.safetensors",
590
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.layer_norm1.weight": "model-00001-of-00002.safetensors",
591
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.layer_norm2.bias": "model-00001-of-00002.safetensors",
592
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.layer_norm2.weight": "model-00001-of-00002.safetensors",
593
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.mlp.fc1.bias": "model-00001-of-00002.safetensors",
594
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.mlp.fc1.weight": "model-00001-of-00002.safetensors",
595
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.mlp.fc2.bias": "model-00001-of-00002.safetensors",
596
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.mlp.fc2.weight": "model-00001-of-00002.safetensors",
597
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.self_attn.projection.bias": "model-00001-of-00002.safetensors",
598
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.self_attn.projection.weight": "model-00001-of-00002.safetensors",
599
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
600
+ "model.vision_embed_tokens.img_processor.encoder.layers.38.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
601
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.layer_norm1.bias": "model-00001-of-00002.safetensors",
602
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.layer_norm1.weight": "model-00001-of-00002.safetensors",
603
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.layer_norm2.bias": "model-00001-of-00002.safetensors",
604
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.layer_norm2.weight": "model-00001-of-00002.safetensors",
605
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.mlp.fc1.bias": "model-00001-of-00002.safetensors",
606
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.mlp.fc1.weight": "model-00001-of-00002.safetensors",
607
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.mlp.fc2.bias": "model-00001-of-00002.safetensors",
608
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.mlp.fc2.weight": "model-00001-of-00002.safetensors",
609
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.self_attn.projection.bias": "model-00001-of-00002.safetensors",
610
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.self_attn.projection.weight": "model-00001-of-00002.safetensors",
611
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
612
+ "model.vision_embed_tokens.img_processor.encoder.layers.39.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
613
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.layer_norm1.bias": "model-00001-of-00002.safetensors",
614
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.layer_norm1.weight": "model-00001-of-00002.safetensors",
615
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.layer_norm2.bias": "model-00001-of-00002.safetensors",
616
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.layer_norm2.weight": "model-00001-of-00002.safetensors",
617
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.mlp.fc1.bias": "model-00001-of-00002.safetensors",
618
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.mlp.fc1.weight": "model-00001-of-00002.safetensors",
619
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.mlp.fc2.bias": "model-00001-of-00002.safetensors",
620
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.mlp.fc2.weight": "model-00001-of-00002.safetensors",
621
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.self_attn.projection.bias": "model-00001-of-00002.safetensors",
622
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.self_attn.projection.weight": "model-00001-of-00002.safetensors",
623
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
624
+ "model.vision_embed_tokens.img_processor.encoder.layers.4.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
625
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.layer_norm1.bias": "model-00001-of-00002.safetensors",
626
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.layer_norm1.weight": "model-00001-of-00002.safetensors",
627
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.layer_norm2.bias": "model-00001-of-00002.safetensors",
628
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.layer_norm2.weight": "model-00001-of-00002.safetensors",
629
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.mlp.fc1.bias": "model-00001-of-00002.safetensors",
630
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.mlp.fc1.weight": "model-00001-of-00002.safetensors",
631
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.mlp.fc2.bias": "model-00001-of-00002.safetensors",
632
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.mlp.fc2.weight": "model-00001-of-00002.safetensors",
633
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.self_attn.projection.bias": "model-00001-of-00002.safetensors",
634
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.self_attn.projection.weight": "model-00001-of-00002.safetensors",
635
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
636
+ "model.vision_embed_tokens.img_processor.encoder.layers.5.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
637
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.layer_norm1.bias": "model-00001-of-00002.safetensors",
638
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.layer_norm1.weight": "model-00001-of-00002.safetensors",
639
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.layer_norm2.bias": "model-00001-of-00002.safetensors",
640
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.layer_norm2.weight": "model-00001-of-00002.safetensors",
641
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.mlp.fc1.bias": "model-00001-of-00002.safetensors",
642
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.mlp.fc1.weight": "model-00001-of-00002.safetensors",
643
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.mlp.fc2.bias": "model-00001-of-00002.safetensors",
644
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.mlp.fc2.weight": "model-00001-of-00002.safetensors",
645
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.self_attn.projection.bias": "model-00001-of-00002.safetensors",
646
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.self_attn.projection.weight": "model-00001-of-00002.safetensors",
647
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
648
+ "model.vision_embed_tokens.img_processor.encoder.layers.6.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
649
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.layer_norm1.bias": "model-00001-of-00002.safetensors",
650
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.layer_norm1.weight": "model-00001-of-00002.safetensors",
651
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.layer_norm2.bias": "model-00001-of-00002.safetensors",
652
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.layer_norm2.weight": "model-00001-of-00002.safetensors",
653
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.mlp.fc1.bias": "model-00001-of-00002.safetensors",
654
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.mlp.fc1.weight": "model-00001-of-00002.safetensors",
655
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.mlp.fc2.bias": "model-00001-of-00002.safetensors",
656
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.mlp.fc2.weight": "model-00001-of-00002.safetensors",
657
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.self_attn.projection.bias": "model-00001-of-00002.safetensors",
658
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.self_attn.projection.weight": "model-00001-of-00002.safetensors",
659
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
660
+ "model.vision_embed_tokens.img_processor.encoder.layers.7.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
661
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.layer_norm1.bias": "model-00001-of-00002.safetensors",
662
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.layer_norm1.weight": "model-00001-of-00002.safetensors",
663
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.layer_norm2.bias": "model-00001-of-00002.safetensors",
664
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.layer_norm2.weight": "model-00001-of-00002.safetensors",
665
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.mlp.fc1.bias": "model-00001-of-00002.safetensors",
666
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.mlp.fc1.weight": "model-00001-of-00002.safetensors",
667
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.mlp.fc2.bias": "model-00001-of-00002.safetensors",
668
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.mlp.fc2.weight": "model-00001-of-00002.safetensors",
669
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.self_attn.projection.bias": "model-00001-of-00002.safetensors",
670
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.self_attn.projection.weight": "model-00001-of-00002.safetensors",
671
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
672
+ "model.vision_embed_tokens.img_processor.encoder.layers.8.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
673
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.layer_norm1.bias": "model-00001-of-00002.safetensors",
674
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.layer_norm1.weight": "model-00001-of-00002.safetensors",
675
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.layer_norm2.bias": "model-00001-of-00002.safetensors",
676
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.layer_norm2.weight": "model-00001-of-00002.safetensors",
677
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.mlp.fc1.bias": "model-00001-of-00002.safetensors",
678
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.mlp.fc1.weight": "model-00001-of-00002.safetensors",
679
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.mlp.fc2.bias": "model-00001-of-00002.safetensors",
680
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.mlp.fc2.weight": "model-00001-of-00002.safetensors",
681
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.self_attn.projection.bias": "model-00001-of-00002.safetensors",
682
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.self_attn.projection.weight": "model-00001-of-00002.safetensors",
683
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.self_attn.qkv.bias": "model-00001-of-00002.safetensors",
684
+ "model.vision_embed_tokens.img_processor.encoder.layers.9.self_attn.qkv.weight": "model-00001-of-00002.safetensors",
685
+ "model.vision_embed_tokens.img_processor.post_layernorm.bias": "model-00001-of-00002.safetensors",
686
+ "model.vision_embed_tokens.img_processor.post_layernorm.weight": "model-00001-of-00002.safetensors",
687
+ "model.vision_embed_tokens.img_projection.0.bias": "model-00001-of-00002.safetensors",
688
+ "model.vision_embed_tokens.img_projection.0.weight": "model-00001-of-00002.safetensors",
689
+ "model.vision_embed_tokens.img_projection.2.bias": "model-00001-of-00002.safetensors",
690
+ "model.vision_embed_tokens.img_projection.2.weight": "model-00001-of-00002.safetensors"
691
+ }
692
+ }
modeling_chexbones.py ADDED
@@ -0,0 +1,1825 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2025 AIRI
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ import inspect
18
+ import math
19
+ import warnings
20
+ from typing import List, Optional, Tuple, Union
21
+
22
+ import torch
23
+ import torch.nn.functional as F
24
+ from torch import nn
25
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
26
+
27
+ from transformers.activations import ACT2FN
28
+ from transformers.cache_utils import Cache, DynamicCache
29
+ from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask
30
+ from transformers.modeling_outputs import (
31
+ BaseModelOutputWithPast,
32
+ CausalLMOutputWithPast,
33
+ SequenceClassifierOutputWithPast,
34
+ TokenClassifierOutput,
35
+ )
36
+ from transformers import AutoModel
37
+ from transformers.modeling_utils import PreTrainedModel
38
+ from transformers.utils import (
39
+ add_code_sample_docstrings,
40
+ add_start_docstrings,
41
+ add_start_docstrings_to_model_forward,
42
+ is_flash_attn_greater_or_equal_2_10,
43
+ logging,
44
+ replace_return_docstrings,
45
+ )
46
+ from .configuration_chexbones import ChexBonesConfig, CheXagentVisionConfig
47
+
48
+ from transformers.modeling_outputs import (
49
+ BaseModelOutput,
50
+
51
+ BaseModelOutputWithPooling
52
+ )
53
+
54
+ try:
55
+ from flash_attn import flash_attn_func, flash_attn_varlen_func
56
+ from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
57
+
58
+ _flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
59
+ except ImportError:
60
+ pass
61
+
62
+ import torch
63
+ from torch import nn
64
+ from transformers import PretrainedConfig
65
+ from transformers.utils import logging
66
+
67
+ logger = logging.get_logger(__name__)
68
+
69
+ _CONFIG_FOR_DOC = "ChexBonesConfig"
70
+
71
+
72
+ MAX_INPUT_ID = int(1e9)
73
+
74
+
75
+ #from ChexAgent https://huggingface.co/StanfordAIMI/CheXagent-8b/blob/main/modeling_chexagent.py
76
+
77
+ class CheXagentVisionEmbeddings(nn.Module):
78
+ def __init__(self, config: CheXagentVisionConfig):
79
+ super().__init__()
80
+ self.config = config
81
+ self.embed_dim = config.hidden_size
82
+ self.image_size = config.image_size
83
+ self.patch_size = config.patch_size
84
+
85
+ self.class_embedding = nn.Parameter(torch.randn(1, 1, self.embed_dim))
86
+
87
+ self.patch_embedding = nn.Conv2d(
88
+ in_channels=3, out_channels=self.embed_dim, kernel_size=self.patch_size, stride=self.patch_size
89
+ )
90
+
91
+ self.num_patches = (self.image_size // self.patch_size) ** 2
92
+ self.num_positions = self.num_patches + 1
93
+
94
+ self.position_embedding = nn.Parameter(torch.randn(1, self.num_positions, self.embed_dim))
95
+
96
+ def forward(self, pixel_values: torch.FloatTensor) -> torch.Tensor:
97
+ batch_size = pixel_values.shape[0]
98
+ target_dtype = self.patch_embedding.weight.dtype
99
+ patch_embeds = self.patch_embedding(pixel_values.to(dtype=target_dtype)) # shape = [*, width, grid, grid]
100
+ patch_embeds = patch_embeds.flatten(2).transpose(1, 2)
101
+
102
+ class_embeds = self.class_embedding.expand(batch_size, 1, -1).to(target_dtype)
103
+ embeddings = torch.cat([class_embeds, patch_embeds], dim=1)
104
+ embeddings = embeddings + self.position_embedding[:, : embeddings.size(1), :].to(target_dtype)
105
+ return embeddings
106
+
107
+
108
+ class CheXagentAttention(nn.Module):
109
+ def __init__(self, config):
110
+ super().__init__()
111
+ self.config = config
112
+ self.embed_dim = config.hidden_size
113
+ self.num_heads = config.num_attention_heads
114
+ self.head_dim = self.embed_dim // self.num_heads
115
+ if self.head_dim * self.num_heads != self.embed_dim:
116
+ raise ValueError(
117
+ f"embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim} and `num_heads`:"
118
+ f" {self.num_heads})."
119
+ )
120
+ self.scale = self.head_dim ** -0.5
121
+ self.dropout = nn.Dropout(config.attention_dropout)
122
+
123
+ # small tweak here compared to CLIP, no bias here
124
+ self.qkv = nn.Linear(self.embed_dim, 3 * self.embed_dim, bias=False)
125
+
126
+ if config.qkv_bias:
127
+ q_bias = nn.Parameter(torch.zeros(self.embed_dim))
128
+ v_bias = nn.Parameter(torch.zeros(self.embed_dim))
129
+ else:
130
+ q_bias = None
131
+ v_bias = None
132
+
133
+ if q_bias is not None:
134
+ qkv_bias = torch.cat((q_bias, torch.zeros_like(v_bias, requires_grad=False), v_bias))
135
+ self.qkv.bias = nn.Parameter(qkv_bias)
136
+
137
+ self.projection = nn.Linear(self.embed_dim, self.embed_dim)
138
+
139
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
140
+ return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
141
+
142
+ def forward(
143
+ self,
144
+ hidden_states: torch.Tensor,
145
+ head_mask: Optional[torch.Tensor] = None,
146
+ output_attentions: Optional[bool] = False,
147
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
148
+ bsz, tgt_len, embed_dim = hidden_states.size()
149
+
150
+ mixed_qkv = self.qkv(hidden_states)
151
+
152
+ mixed_qkv = mixed_qkv.reshape(bsz, tgt_len, 3, self.num_heads, embed_dim // self.num_heads).permute(
153
+ 2, 0, 3, 1, 4
154
+ )
155
+ query_states, key_states, value_states = mixed_qkv[0], mixed_qkv[1], mixed_qkv[2]
156
+
157
+ # Take the dot product between "query" and "key" to get the raw attention scores.
158
+ attention_scores = torch.matmul(query_states, key_states.transpose(-1, -2))
159
+
160
+ attention_scores = attention_scores * self.scale
161
+
162
+ # Normalize the attention scores to probabilities.
163
+ attention_probs = nn.functional.softmax(attention_scores, dim=-1)
164
+
165
+ # This is actually dropping out entire tokens to attend to, which might
166
+ # seem a bit unusual, but is taken from the original Transformer paper.
167
+ attention_probs = self.dropout(attention_probs)
168
+
169
+ # Mask heads if we want to
170
+ if head_mask is not None:
171
+ attention_probs = attention_probs * head_mask
172
+
173
+ context_layer = torch.matmul(attention_probs, value_states).permute(0, 2, 1, 3)
174
+
175
+ new_context_layer_shape = context_layer.size()[:-2] + (self.embed_dim,)
176
+ context_layer = context_layer.reshape(new_context_layer_shape)
177
+
178
+ output = self.projection(context_layer)
179
+
180
+ outputs = (output, attention_probs) if output_attentions else (output, None)
181
+
182
+ return outputs
183
+
184
+
185
+ class CheXagentMLP(nn.Module):
186
+ def __init__(self, config):
187
+ super().__init__()
188
+ self.config = config
189
+ self.activation_fn = ACT2FN[config.hidden_act]
190
+ self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
191
+ self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)
192
+
193
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
194
+ hidden_states = self.fc1(hidden_states)
195
+ hidden_states = self.activation_fn(hidden_states)
196
+ hidden_states = self.fc2(hidden_states)
197
+ return hidden_states
198
+
199
+
200
+ class CheXagentEncoderLayer(nn.Module):
201
+ def __init__(self, config: CheXagentVisionConfig):
202
+ super().__init__()
203
+ self.embed_dim = config.hidden_size
204
+ self.self_attn = CheXagentAttention(config)
205
+ self.layer_norm1 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
206
+ self.mlp = CheXagentMLP(config)
207
+ self.layer_norm2 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
208
+
209
+ def forward(
210
+ self,
211
+ hidden_states: torch.Tensor,
212
+ attention_mask: torch.Tensor,
213
+ output_attentions: Optional[bool] = False,
214
+ ) -> Tuple[torch.FloatTensor]:
215
+ residual = hidden_states
216
+ hidden_states = self.layer_norm1(hidden_states)
217
+ hidden_states, attn_weights = self.self_attn(
218
+ hidden_states=hidden_states,
219
+ head_mask=attention_mask,
220
+ output_attentions=output_attentions,
221
+ )
222
+ hidden_states = hidden_states + residual
223
+ residual = hidden_states
224
+ hidden_states = self.layer_norm2(hidden_states)
225
+ hidden_states = self.mlp(hidden_states)
226
+
227
+ hidden_states = hidden_states + residual
228
+
229
+ outputs = (hidden_states,)
230
+
231
+ if output_attentions:
232
+ outputs += (attn_weights,)
233
+
234
+ return outputs
235
+
236
+
237
+ class CheXagentPreTrainedModel(PreTrainedModel):
238
+ config_class = CheXagentVisionConfig
239
+ base_model_prefix = "chexagent"
240
+ supports_gradient_checkpointing = True
241
+ _no_split_modules = [
242
+ "CheXagentQFormerEmbeddings",
243
+ "CheXagentAttention",
244
+ "CheXagentQFormerMultiHeadAttention",
245
+ "CheXagentQFormerSelfOutput",
246
+ ]
247
+ _keep_in_fp32_modules = []
248
+
249
+ def _init_weights(self, module):
250
+ """Initialize the weights"""
251
+ factor = self.config.initializer_range
252
+ if isinstance(module, nn.Conv2d) or isinstance(module, nn.Embedding) or isinstance(module, nn.Linear):
253
+ module.weight.data.normal_(mean=0.0, std=factor)
254
+ if hasattr(module, "bias") and module.bias is not None:
255
+ module.bias.data.zero_()
256
+
257
+ if isinstance(module, CheXagentVisionEmbeddings):
258
+ if hasattr(self.config, "vision_config"):
259
+ factor = self.config.vision_config.initializer_range
260
+ nn.init.trunc_normal_(module.position_embedding, mean=0.0, std=factor)
261
+ nn.init.trunc_normal_(module.class_embedding, mean=0.0, std=factor)
262
+
263
+ elif isinstance(module, nn.LayerNorm):
264
+ module.bias.data.zero_()
265
+ module.weight.data.fill_(1.0)
266
+ elif isinstance(module, nn.Linear) and module.bias is not None:
267
+ module.bias.data.zero_()
268
+
269
+
270
+ class CheXagentEncoder(nn.Module):
271
+ def __init__(self, config: CheXagentVisionConfig):
272
+ super().__init__()
273
+ self.config = config
274
+ self.layers = nn.ModuleList([CheXagentEncoderLayer(config) for _ in range(config.num_hidden_layers)])
275
+ self.gradient_checkpointing = False
276
+
277
+ def forward(
278
+ self,
279
+ inputs_embeds,
280
+ attention_mask: Optional[torch.Tensor] = None,
281
+ output_attentions: Optional[bool] = None,
282
+ output_hidden_states: Optional[bool] = None,
283
+ return_dict: Optional[bool] = None,
284
+ ) -> Union[Tuple, BaseModelOutput]:
285
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
286
+ output_hidden_states = (
287
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
288
+ )
289
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
290
+
291
+ encoder_states = () if output_hidden_states else None
292
+ all_attentions = () if output_attentions else None
293
+ hidden_states = inputs_embeds
294
+ for idx, encoder_layer in enumerate(self.layers):
295
+ if output_hidden_states:
296
+ encoder_states = encoder_states + (hidden_states,)
297
+ if self.gradient_checkpointing and self.training:
298
+ layer_outputs = self._gradient_checkpointing_func(
299
+ encoder_layer.__call__,
300
+ hidden_states,
301
+ attention_mask,
302
+ output_attentions,
303
+ )
304
+ else:
305
+ layer_outputs = encoder_layer(hidden_states, attention_mask, output_attentions=output_attentions, )
306
+
307
+ hidden_states = layer_outputs[0]
308
+
309
+ if output_attentions:
310
+ all_attentions = all_attentions + (layer_outputs[1],)
311
+
312
+ if output_hidden_states:
313
+ encoder_states = encoder_states + (hidden_states,)
314
+
315
+ if not return_dict:
316
+ return tuple(v for v in [hidden_states, encoder_states, all_attentions] if v is not None)
317
+ return BaseModelOutput(
318
+ last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions
319
+ )
320
+
321
+
322
+ class CheXagentVisionModel(CheXagentPreTrainedModel):
323
+ main_input_name = "pixel_values"
324
+ config_class = CheXagentVisionConfig
325
+
326
+ def __init__(self, config: CheXagentVisionConfig):
327
+ super().__init__(config)
328
+ self.config = config
329
+ embed_dim = config.hidden_size
330
+
331
+ self.embeddings = CheXagentVisionEmbeddings(config)
332
+ self.encoder = CheXagentEncoder(config)
333
+ self.post_layernorm = nn.LayerNorm(embed_dim, eps=config.layer_norm_eps)
334
+
335
+ self.post_init()
336
+
337
+ def forward(
338
+ self,
339
+ pixel_values: Optional[torch.FloatTensor] = None,
340
+ output_attentions: Optional[bool] = None,
341
+ output_hidden_states: Optional[bool] = None,
342
+ return_dict: Optional[bool] = None,
343
+ ) -> Union[Tuple, BaseModelOutputWithPooling]:
344
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
345
+ output_hidden_states = (
346
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
347
+ )
348
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
349
+
350
+ if pixel_values is None:
351
+ raise ValueError("You have to specify pixel_values")
352
+ hidden_states = self.embeddings(pixel_values)
353
+
354
+ encoder_outputs = self.encoder(
355
+ inputs_embeds=hidden_states,
356
+ output_attentions=output_attentions,
357
+ output_hidden_states=output_hidden_states,
358
+ return_dict=return_dict,
359
+ )
360
+
361
+ last_hidden_state = encoder_outputs[0]
362
+ last_hidden_state = self.post_layernorm(last_hidden_state)
363
+
364
+ pooled_output = last_hidden_state[:, 0, :]
365
+ pooled_output = self.post_layernorm(pooled_output)
366
+
367
+ if not return_dict:
368
+ return (last_hidden_state, pooled_output) + encoder_outputs[1:]
369
+
370
+ return BaseModelOutputWithPooling(
371
+ last_hidden_state=last_hidden_state,
372
+ pooler_output=pooled_output,
373
+ hidden_states=encoder_outputs.hidden_states,
374
+ attentions=encoder_outputs.attentions,
375
+ )
376
+
377
+ def get_input_embeddings(self):
378
+ return self.embeddings
379
+
380
+
381
+
382
+ #from https://huggingface.co/microsoft/Phi-3.5-vision-instruct/blob/main/modeling_phi3_v.py
383
+ class Phi3ImageEmbedding(nn.Module):
384
+ """Phi3 Image embedding."""
385
+
386
+ def __init__(self, config: PretrainedConfig, wte=None, **kwargs) -> None:
387
+ super().__init__()
388
+
389
+ # n_embed or hidden_size
390
+ hidden_size = config.n_embd if hasattr(config, 'n_embd') else config.hidden_size
391
+ if hasattr(config, 'embd_pdrop') or hasattr(config, 'embed_pdrop'):
392
+ embd_drop = config.embd_pdrop if hasattr(config, 'embd_pdrop') else config.embed_pdrop
393
+ self.drop = nn.Dropout(embd_drop)
394
+ else:
395
+ self.drop = None
396
+
397
+ self.wte = wte
398
+
399
+ if isinstance(config.img_processor, dict) and config.img_processor.get('model_type', None) == 'chexagent_vision_model':
400
+ assert 'image_dim_out' in config.img_processor, 'image_dim_out must be provided for CLIPVisionModel'
401
+
402
+
403
+ self.img_processor = CheXagentVisionModel(config=CheXagentVisionConfig(**config.img_processor))
404
+ image_dim_out = self.img_processor.config.hidden_size
405
+ else:
406
+ raise NotImplementedError(f'img_processor = {config.img_processor}, not implemented')
407
+
408
+ if isinstance(config.img_processor, dict):
409
+ self.layer_idx = config.img_processor.get('layer_idx', -2)
410
+ self.type_feature = config.img_processor.get('type_feature', 'patch')
411
+ else:
412
+ self.layer_idx = -2
413
+ self.type_feature = 'patch'
414
+
415
+ self.image_dim_out = image_dim_out
416
+ self.img_sizes = None
417
+
418
+ projection_cls = kwargs.get('projection_cls', 'linear')
419
+ if projection_cls == 'linear':
420
+ self.img_projection = nn.Linear(image_dim_out, hidden_size)
421
+ elif projection_cls == 'mlp':
422
+ dim_projection = hidden_size
423
+ depth = 2
424
+ scale = 1
425
+ activation = nn.GELU()
426
+ layers = [nn.Linear(image_dim_out, dim_projection)]
427
+ for _ in range(1, depth):
428
+ layers.extend([activation,
429
+ nn.Linear(int(dim_projection*scale), dim_projection)])
430
+ self.img_projection = nn.Sequential(*layers)
431
+ else:
432
+ raise NotImplementedError(f'projection_cls = {projection_cls}, not implemented')
433
+
434
+ self.vocab_size = config.vocab_size
435
+ self.img_features = None
436
+
437
+
438
+ def set_img_features(self, img_features: torch.FloatTensor) -> None:
439
+ self.img_features = img_features
440
+
441
+ def set_img_sizes(self, img_sizes: torch.LongTensor) -> None:
442
+ self.img_sizes = img_sizes
443
+
444
+ def get_img_features(self, img_embeds: torch.FloatTensor) -> torch.FloatTensor:
445
+ LAYER_IDX = self.layer_idx
446
+ TYPE_FEATURE = self.type_feature
447
+
448
+ img_processor_output = self.img_processor(img_embeds, output_hidden_states=True)
449
+ img_feature = img_processor_output.hidden_states[LAYER_IDX]
450
+
451
+ if TYPE_FEATURE == "patch":
452
+ patch_feature = img_feature[:, 1:]
453
+ return patch_feature
454
+
455
+ raise NotImplementedError
456
+
457
+ def forward(
458
+ self, input_ids: torch.LongTensor, pixel_values: torch.FloatTensor, image_sizes=None
459
+ ) -> torch.FloatTensor:
460
+ input_shape = input_ids.size()
461
+ input_ids = input_ids.view(-1, input_shape[-1])
462
+
463
+ # positions for image tokens
464
+ positions = torch.nonzero((input_ids < 0) & (input_ids > -MAX_INPUT_ID), as_tuple=True)
465
+ has_image = len(positions[0].tolist()) > 0
466
+ input_ids = input_ids.clamp_min(0).clamp_max(self.vocab_size).detach()
467
+ hidden_states = self.wte(input_ids)
468
+
469
+ if has_image:
470
+ num_images, num_crops, c, h, w = pixel_values.shape
471
+ assert c == 3 #and h == w == 336
472
+ img_features = self.get_img_features(pixel_values.flatten(0, 1))
473
+ image_features_proj = self.hd_feature_transform(img_features, image_sizes)
474
+ hidden_states = hidden_states.index_put(
475
+ positions, image_features_proj, accumulate=False
476
+ )
477
+
478
+ if self.drop is not None:
479
+ hidden_states = self.drop(hidden_states)
480
+
481
+ return hidden_states
482
+
483
+ def hd_feature_transform(self, image_features, image_sizes):
484
+ """
485
+ Remake
486
+ """
487
+ if isinstance(self.img_projection, nn.Sequential):
488
+ target_device = self.img_projection[0].bias.device
489
+ target_dtype = self.img_projection[0].bias.dtype
490
+ else: # It's a single nn.Linear layer
491
+ target_device = self.img_projection.bias.device
492
+ target_dtype = self.img_projection.bias.dtype
493
+
494
+ #all_image_embeddings = image_features.flatten(0,1)
495
+
496
+ image_features_proj = self.img_projection(
497
+ image_features.flatten(0,1).to(target_device).to(target_dtype)
498
+ )
499
+
500
+ return image_features_proj
501
+
502
+
503
+
504
+ logger = logging.get_logger(__name__)
505
+
506
+
507
+ # Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->Phi3
508
+ class Phi3RMSNorm(nn.Module):
509
+ def __init__(self, hidden_size, eps=1e-6):
510
+ """
511
+ Phi3RMSNorm is equivalent to T5LayerNorm
512
+ """
513
+ super().__init__()
514
+ self.weight = nn.Parameter(torch.ones(hidden_size))
515
+ self.variance_epsilon = eps
516
+
517
+ def forward(self, hidden_states):
518
+ input_dtype = hidden_states.dtype
519
+ hidden_states = hidden_states.to(torch.float32)
520
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
521
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
522
+ return self.weight * hidden_states.to(input_dtype)
523
+
524
+
525
+ # Copied from transformers.models.llama.modeling_llama._get_unpad_data
526
+ def _get_unpad_data(attention_mask):
527
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
528
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
529
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
530
+ cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0))
531
+ return (
532
+ indices,
533
+ cu_seqlens,
534
+ max_seqlen_in_batch,
535
+ )
536
+
537
+
538
+ # Copied from transformers.models.gemma.modeling_gemma.GemmaRotaryEmbedding with gemma->phi3, Gemma->Phi3
539
+ class Phi3RotaryEmbedding(nn.Module):
540
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
541
+ super().__init__()
542
+
543
+ self.dim = dim
544
+ self.max_position_embeddings = max_position_embeddings
545
+ self.base = base
546
+ self.register_buffer("inv_freq", None, persistent=False)
547
+
548
+ @torch.no_grad()
549
+ def forward(self, x, position_ids, seq_len=None):
550
+ # x: [bs, num_attention_heads, seq_len, head_size]
551
+ if self.inv_freq is None:
552
+ self.inv_freq = 1.0 / (
553
+ self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim)
554
+ )
555
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
556
+ position_ids_expanded = position_ids[:, None, :].float()
557
+ # Force float32 since bfloat16 loses precision on long contexts
558
+ # See https://github.com/huggingface/transformers/pull/29285
559
+ device_type = x.device.type
560
+ device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
561
+ with torch.autocast(device_type=device_type, enabled=False):
562
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
563
+ emb = torch.cat((freqs, freqs), dim=-1)
564
+ cos = emb.cos()
565
+ sin = emb.sin()
566
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
567
+
568
+
569
+ class Phi3SuScaledRotaryEmbedding(Phi3RotaryEmbedding):
570
+ def __init__(self, dim, config, device=None):
571
+ super().__init__(dim, config.max_position_embeddings, config.rope_theta, device)
572
+
573
+ self.short_factor = config.rope_scaling["short_factor"]
574
+ self.long_factor = config.rope_scaling["long_factor"]
575
+ self.original_max_position_embeddings = config.original_max_position_embeddings
576
+
577
+ @torch.no_grad()
578
+ def forward(self, x, position_ids, seq_len=None):
579
+ seq_len = seq_len or torch.max(position_ids) + 1
580
+ if seq_len > self.original_max_position_embeddings:
581
+ ext_factors = torch.tensor(self.long_factor, dtype=torch.float32, device=x.device)
582
+ else:
583
+ ext_factors = torch.tensor(self.short_factor, dtype=torch.float32, device=x.device)
584
+
585
+ inv_freq_shape = torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim
586
+ self.inv_freq = 1.0 / (ext_factors * self.base**inv_freq_shape)
587
+
588
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
589
+ position_ids_expanded = position_ids[:, None, :].float()
590
+
591
+ # Force float32 since bfloat16 loses precision on long contexts
592
+ # See https://github.com/huggingface/transformers/pull/29285
593
+ device_type = x.device.type
594
+ device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
595
+ with torch.autocast(device_type=device_type, enabled=False):
596
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
597
+ emb = torch.cat((freqs, freqs), dim=-1)
598
+
599
+ scale = self.max_position_embeddings / self.original_max_position_embeddings
600
+ if scale <= 1.0:
601
+ scaling_factor = 1.0
602
+ else:
603
+ scaling_factor = math.sqrt(1 + math.log(scale) / math.log(self.original_max_position_embeddings))
604
+
605
+ cos = emb.cos() * scaling_factor
606
+ sin = emb.sin() * scaling_factor
607
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
608
+
609
+
610
+ class Phi3YarnScaledRotaryEmbedding(Phi3RotaryEmbedding):
611
+ def __init__(self, dim, config, device=None):
612
+ super().__init__(dim, config.max_position_embeddings, config.rope_theta, device)
613
+
614
+ self.short_factor = config.rope_scaling["short_factor"]
615
+ self.long_factor = config.rope_scaling["long_factor"]
616
+ self.original_max_position_embeddings = config.original_max_position_embeddings
617
+
618
+ @torch.no_grad()
619
+ def forward(self, x, position_ids, seq_len=None):
620
+ seq_len = torch.max(position_ids) + 1
621
+ if seq_len > self.original_max_position_embeddings:
622
+ ext_factors = torch.tensor(self.long_factor, dtype=torch.float32, device=x.device)
623
+ else:
624
+ ext_factors = torch.tensor(self.short_factor, dtype=torch.float32, device=x.device)
625
+
626
+ inv_freq_shape = torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim
627
+ self.inv_freq = 1.0 / (ext_factors * self.base**inv_freq_shape)
628
+
629
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
630
+ position_ids_expanded = position_ids[:, None, :].float()
631
+
632
+ # Force float32 since bfloat16 loses precision on long contexts
633
+ # See https://github.com/huggingface/transformers/pull/29285
634
+ device_type = x.device.type
635
+ device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
636
+ with torch.autocast(device_type=device_type, enabled=False):
637
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
638
+ emb = torch.cat((freqs, freqs), dim=-1)
639
+
640
+ scale = self.max_position_embeddings / self.original_max_position_embeddings
641
+ if scale <= 1.0:
642
+ scaling_factor = 1.0
643
+ else:
644
+ scaling_factor = 0.1 * math.log(scale) + 1.0
645
+
646
+ cos = emb.cos() * scaling_factor
647
+ sin = emb.sin() * scaling_factor
648
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
649
+
650
+
651
+ # Copied from transformers.models.llama.modeling_llama.rotate_half
652
+ def rotate_half(x):
653
+ """Rotates half the hidden dims of the input."""
654
+ x1 = x[..., : x.shape[-1] // 2]
655
+ x2 = x[..., x.shape[-1] // 2 :]
656
+ return torch.cat((-x2, x1), dim=-1)
657
+
658
+
659
+ # Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
660
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
661
+ """Applies Rotary Position Embedding to the query and key tensors.
662
+
663
+ Args:
664
+ q (`torch.Tensor`): The query tensor.
665
+ k (`torch.Tensor`): The key tensor.
666
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
667
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
668
+ position_ids (`torch.Tensor`, *optional*):
669
+ Deprecated and unused.
670
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
671
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
672
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
673
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
674
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
675
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
676
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
677
+ Returns:
678
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
679
+ """
680
+ cos = cos.unsqueeze(unsqueeze_dim)
681
+ sin = sin.unsqueeze(unsqueeze_dim)
682
+ q_embed = (q * cos) + (rotate_half(q) * sin)
683
+ k_embed = (k * cos) + (rotate_half(k) * sin)
684
+ return q_embed, k_embed
685
+
686
+
687
+ class Phi3MLP(nn.Module):
688
+ def __init__(self, config):
689
+ super().__init__()
690
+
691
+ self.config = config
692
+ self.gate_up_proj = nn.Linear(config.hidden_size, 2 * config.intermediate_size, bias=False)
693
+ self.down_proj = nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
694
+
695
+ self.activation_fn = ACT2FN[config.hidden_act]
696
+
697
+ def forward(self, hidden_states: torch.FloatTensor) -> torch.FloatTensor:
698
+ up_states = self.gate_up_proj(hidden_states)
699
+
700
+ gate, up_states = up_states.chunk(2, dim=-1)
701
+ up_states = up_states * self.activation_fn(gate)
702
+
703
+ return self.down_proj(up_states)
704
+
705
+
706
+ # Copied from transformers.models.llama.modeling_llama.repeat_kv with llama->phi
707
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
708
+ """
709
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
710
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
711
+ """
712
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
713
+ if n_rep == 1:
714
+ return hidden_states
715
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
716
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
717
+
718
+
719
+ class Phi3Attention(nn.Module):
720
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
721
+
722
+ def __init__(self, config: ChexBonesConfig, layer_idx: Optional[int] = None):
723
+ super().__init__()
724
+ self.config = config
725
+ self.layer_idx = layer_idx
726
+ if layer_idx is None:
727
+ logger.warning_once(
728
+ f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
729
+ "lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
730
+ "when creating this class."
731
+ )
732
+
733
+ self.attention_dropout = config.attention_dropout
734
+ self.hidden_size = config.hidden_size
735
+ self.num_heads = config.num_attention_heads
736
+ self.head_dim = self.hidden_size // self.num_heads
737
+ self.num_key_value_heads = config.num_key_value_heads
738
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
739
+ self.max_position_embeddings = config.max_position_embeddings
740
+ self.original_max_position_embeddings = config.original_max_position_embeddings
741
+ self.rope_theta = config.rope_theta
742
+ self.rope_scaling = config.rope_scaling
743
+ self.is_causal = True
744
+
745
+ if (self.head_dim * self.num_heads) != self.hidden_size:
746
+ raise ValueError(
747
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
748
+ f" and `num_heads`: {self.num_heads})."
749
+ )
750
+
751
+ op_size = self.num_heads * self.head_dim + 2 * (self.num_key_value_heads * self.head_dim)
752
+ self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
753
+ self.qkv_proj = nn.Linear(self.hidden_size, op_size, bias=False)
754
+ self._init_rope()
755
+
756
+ def _init_rope(self):
757
+ if self.rope_scaling is None:
758
+ self.rotary_emb = Phi3RotaryEmbedding(
759
+ self.head_dim,
760
+ max_position_embeddings=self.max_position_embeddings,
761
+ base=self.rope_theta,
762
+ )
763
+ else:
764
+ scaling_type = self.config.rope_scaling["type"]
765
+ if scaling_type == "su":
766
+ self.rotary_emb = Phi3SuScaledRotaryEmbedding(self.head_dim, self.config)
767
+ elif scaling_type == "yarn":
768
+ self.rotary_emb = Phi3YarnScaledRotaryEmbedding(self.head_dim, self.config)
769
+ else:
770
+ raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
771
+
772
+ def forward(
773
+ self,
774
+ hidden_states: torch.Tensor,
775
+ attention_mask: Optional[torch.Tensor] = None,
776
+ position_ids: Optional[torch.LongTensor] = None,
777
+ past_key_value: Optional[Cache] = None,
778
+ output_attentions: bool = False,
779
+ use_cache: bool = False,
780
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
781
+ logger.warning_once("You are not running the flash-attention implementation, expect numerical differences.")
782
+
783
+ bsz, q_len, _ = hidden_states.size()
784
+
785
+ qkv = self.qkv_proj(hidden_states)
786
+ query_pos = self.num_heads * self.head_dim
787
+ query_states = qkv[..., :query_pos]
788
+ key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
789
+ value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
790
+
791
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
792
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
793
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
794
+
795
+ kv_seq_len = key_states.shape[-2]
796
+ if past_key_value is not None:
797
+ if self.layer_idx is None:
798
+ raise ValueError(
799
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
800
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
801
+ "with a layer index."
802
+ )
803
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
804
+ cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
805
+
806
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
807
+
808
+ if past_key_value is not None:
809
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
810
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
811
+
812
+ # repeat k/v heads if n_kv_heads < n_heads
813
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
814
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
815
+
816
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
817
+
818
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
819
+ raise ValueError(
820
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
821
+ f" {attn_weights.size()}"
822
+ )
823
+
824
+ if attention_mask is not None:
825
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
826
+ raise ValueError(
827
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
828
+ )
829
+ attn_weights = attn_weights + attention_mask
830
+
831
+ # upcast attention to fp32
832
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(value_states.dtype)
833
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
834
+
835
+ attn_output = torch.matmul(attn_weights, value_states)
836
+
837
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
838
+ raise ValueError(
839
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
840
+ f" {attn_output.size()}"
841
+ )
842
+
843
+ attn_output = attn_output.transpose(1, 2).contiguous()
844
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
845
+
846
+ attn_output = self.o_proj(attn_output)
847
+
848
+ if not output_attentions:
849
+ attn_weights = None
850
+
851
+ return attn_output, attn_weights, past_key_value
852
+
853
+
854
+ class Phi3FlashAttention2(Phi3Attention):
855
+ """
856
+ Phi-3 flash attention module. This module inherits from `Phi3Attention` as the weights of the module stays
857
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
858
+ flash attention and deal with padding tokens in case the input contains any of them.
859
+ """
860
+
861
+ # Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
862
+ def __init__(self, *args, **kwargs):
863
+ super().__init__(*args, **kwargs)
864
+
865
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
866
+ # 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.
867
+ # 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).
868
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
869
+
870
+ def forward(
871
+ self,
872
+ hidden_states: torch.Tensor,
873
+ attention_mask: Optional[torch.LongTensor] = None,
874
+ position_ids: Optional[torch.LongTensor] = None,
875
+ past_key_value: Optional[Cache] = None,
876
+ output_attentions: bool = False,
877
+ use_cache: bool = False,
878
+ **kwargs,
879
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
880
+ # Phi3FlashAttention2 attention does not support output_attentions
881
+
882
+ if not _flash_supports_window_size:
883
+ logger.warning_once(
884
+ "The current flash attention version does not support sliding window attention. Please use `attn_implementation='eager'` or upgrade flash-attn library."
885
+ )
886
+ raise ValueError("The current flash attention version does not support sliding window attention.")
887
+
888
+ output_attentions = False
889
+
890
+ if "padding_mask" in kwargs:
891
+ warnings.warn(
892
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
893
+ )
894
+
895
+ # overwrite attention_mask with padding_mask
896
+ attention_mask = kwargs.pop("padding_mask")
897
+
898
+ bsz, q_len, _ = hidden_states.size()
899
+
900
+ qkv = self.qkv_proj(hidden_states)
901
+ query_pos = self.num_heads * self.head_dim
902
+ query_states = qkv[..., :query_pos]
903
+ key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
904
+ value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
905
+
906
+ # Flash attention requires the input to have the shape
907
+ # batch_size x seq_length x head_dim x hidden_dim
908
+ # therefore we just need to keep the original shape
909
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
910
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
911
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
912
+
913
+ kv_seq_len = key_states.shape[-2]
914
+ if past_key_value is not None:
915
+ if self.layer_idx is None:
916
+ raise ValueError(
917
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
918
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
919
+ "with a layer index."
920
+ )
921
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
922
+
923
+ # Because the input can be padded, the absolute sequence length depends on the max position id.
924
+ rotary_seq_len = max(kv_seq_len, position_ids[:, -1].max().item()) + 1
925
+ cos, sin = self.rotary_emb(value_states, position_ids, seq_len=rotary_seq_len)
926
+
927
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
928
+
929
+ use_sliding_windows = (
930
+ _flash_supports_window_size
931
+ and getattr(self.config, "sliding_window", None) is not None
932
+ and kv_seq_len > self.config.sliding_window
933
+ )
934
+
935
+ if past_key_value is not None:
936
+ # Activate slicing cache only if the config has a value `sliding_windows` attribute
937
+ cache_has_contents = past_key_value.get_seq_length(self.layer_idx) > 0
938
+ if (
939
+ getattr(self.config, "sliding_window", None) is not None
940
+ and kv_seq_len > self.config.sliding_window
941
+ and cache_has_contents
942
+ ):
943
+ slicing_tokens = 1 - self.config.sliding_window
944
+
945
+ past_key = past_key_value[self.layer_idx][0]
946
+ past_value = past_key_value[self.layer_idx][1]
947
+
948
+ past_key = past_key[:, :, slicing_tokens:, :].contiguous()
949
+ past_value = past_value[:, :, slicing_tokens:, :].contiguous()
950
+
951
+ if past_key.shape[-2] != self.config.sliding_window - 1:
952
+ raise ValueError(
953
+ f"past key must have a shape of (`batch_size, num_heads, self.config.sliding_window-1, head_dim`), got"
954
+ f" {past_key.shape}"
955
+ )
956
+
957
+ if attention_mask is not None:
958
+ attention_mask = attention_mask[:, slicing_tokens:]
959
+ attention_mask = torch.cat([attention_mask, torch.ones_like(attention_mask[:, -1:])], dim=-1)
960
+
961
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
962
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
963
+
964
+ # repeat k/v heads if n_kv_heads < n_heads
965
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
966
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
967
+
968
+ attn_dropout = self.attention_dropout if self.training else 0.0
969
+
970
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
971
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
972
+ # cast them back in the correct dtype just to be sure everything works as expected.
973
+ # This might slowdown training & inference so it is recommended to not cast the LayerNorms
974
+ # in fp32.
975
+
976
+ if query_states.dtype == torch.float32:
977
+ if torch.is_autocast_enabled():
978
+ target_dtype = torch.get_autocast_gpu_dtype()
979
+ # Handle the case where the model is quantized
980
+ elif hasattr(self.config, "_pre_quantization_dtype"):
981
+ target_dtype = self.config._pre_quantization_dtype
982
+ else:
983
+ target_dtype = self.qkv_proj.weight.dtype
984
+
985
+ logger.warning_once(
986
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
987
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
988
+ f" {target_dtype}."
989
+ )
990
+
991
+ query_states = query_states.to(target_dtype)
992
+ key_states = key_states.to(target_dtype)
993
+ value_states = value_states.to(target_dtype)
994
+
995
+ # Reashape to the expected shape for Flash Attention
996
+ query_states = query_states.transpose(1, 2)
997
+ key_states = key_states.transpose(1, 2)
998
+ value_states = value_states.transpose(1, 2)
999
+
1000
+ attn_output = self._flash_attention_forward(
1001
+ query_states,
1002
+ key_states,
1003
+ value_states,
1004
+ attention_mask,
1005
+ q_len,
1006
+ dropout=attn_dropout,
1007
+ use_sliding_windows=use_sliding_windows,
1008
+ )
1009
+
1010
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
1011
+ attn_output = self.o_proj(attn_output)
1012
+
1013
+ if not output_attentions:
1014
+ attn_weights = None
1015
+
1016
+ return attn_output, attn_weights, past_key_value
1017
+
1018
+ # Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._flash_attention_forward
1019
+ def _flash_attention_forward(
1020
+ self,
1021
+ query_states,
1022
+ key_states,
1023
+ value_states,
1024
+ attention_mask,
1025
+ query_length,
1026
+ dropout=0.0,
1027
+ softmax_scale=None,
1028
+ use_sliding_windows=False,
1029
+ ):
1030
+ """
1031
+ Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
1032
+ first unpad the input, then computes the attention scores and pad the final attention scores.
1033
+
1034
+ Args:
1035
+ query_states (`torch.Tensor`):
1036
+ Input query states to be passed to Flash Attention API
1037
+ key_states (`torch.Tensor`):
1038
+ Input key states to be passed to Flash Attention API
1039
+ value_states (`torch.Tensor`):
1040
+ Input value states to be passed to Flash Attention API
1041
+ attention_mask (`torch.Tensor`):
1042
+ The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
1043
+ position of padding tokens and 1 for the position of non-padding tokens.
1044
+ dropout (`float`):
1045
+ Attention dropout
1046
+ softmax_scale (`float`, *optional*):
1047
+ The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
1048
+ use_sliding_windows (`bool`, *optional*):
1049
+ Whether to activate sliding window attention.
1050
+ """
1051
+ if not self._flash_attn_uses_top_left_mask:
1052
+ causal = self.is_causal
1053
+ else:
1054
+ # 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__.
1055
+ causal = self.is_causal and query_length != 1
1056
+
1057
+ # Contains at least one padding token in the sequence
1058
+ if attention_mask is not None:
1059
+ batch_size = query_states.shape[0]
1060
+ query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
1061
+ query_states, key_states, value_states, attention_mask, query_length
1062
+ )
1063
+
1064
+ cu_seqlens_q, cu_seqlens_k = cu_seq_lens
1065
+ max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
1066
+
1067
+ if not use_sliding_windows:
1068
+ attn_output_unpad = flash_attn_varlen_func(
1069
+ query_states,
1070
+ key_states,
1071
+ value_states,
1072
+ cu_seqlens_q=cu_seqlens_q,
1073
+ cu_seqlens_k=cu_seqlens_k,
1074
+ max_seqlen_q=max_seqlen_in_batch_q,
1075
+ max_seqlen_k=max_seqlen_in_batch_k,
1076
+ dropout_p=dropout,
1077
+ softmax_scale=softmax_scale,
1078
+ causal=causal,
1079
+ )
1080
+ else:
1081
+ attn_output_unpad = flash_attn_varlen_func(
1082
+ query_states,
1083
+ key_states,
1084
+ value_states,
1085
+ cu_seqlens_q=cu_seqlens_q,
1086
+ cu_seqlens_k=cu_seqlens_k,
1087
+ max_seqlen_q=max_seqlen_in_batch_q,
1088
+ max_seqlen_k=max_seqlen_in_batch_k,
1089
+ dropout_p=dropout,
1090
+ softmax_scale=softmax_scale,
1091
+ causal=causal,
1092
+ window_size=(self.config.sliding_window, self.config.sliding_window),
1093
+ )
1094
+
1095
+ attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
1096
+ else:
1097
+ if not use_sliding_windows:
1098
+ attn_output = flash_attn_func(
1099
+ query_states,
1100
+ key_states,
1101
+ value_states,
1102
+ dropout,
1103
+ softmax_scale=softmax_scale,
1104
+ causal=causal,
1105
+ )
1106
+ else:
1107
+ attn_output = flash_attn_func(
1108
+ query_states,
1109
+ key_states,
1110
+ value_states,
1111
+ dropout,
1112
+ softmax_scale=softmax_scale,
1113
+ causal=causal,
1114
+ window_size=(self.config.sliding_window, self.config.sliding_window),
1115
+ )
1116
+
1117
+ return attn_output
1118
+
1119
+ # Copied from transformers.models.mistral.modeling_mistral.MistralFlashAttention2._upad_input
1120
+ def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
1121
+ batch_size, kv_seq_len, num_heads, head_dim = key_layer.shape
1122
+
1123
+ # On the first iteration we need to properly re-create the padding mask
1124
+ # by slicing it on the proper place
1125
+ if kv_seq_len != attention_mask.shape[-1]:
1126
+ attention_mask_num_tokens = attention_mask.shape[-1]
1127
+ attention_mask = attention_mask[:, attention_mask_num_tokens - kv_seq_len :]
1128
+
1129
+ indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
1130
+
1131
+ key_layer = index_first_axis(key_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
1132
+ value_layer = index_first_axis(value_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k)
1133
+
1134
+ if query_length == kv_seq_len:
1135
+ query_layer = index_first_axis(
1136
+ query_layer.reshape(batch_size * kv_seq_len, num_heads, head_dim), indices_k
1137
+ )
1138
+ cu_seqlens_q = cu_seqlens_k
1139
+ max_seqlen_in_batch_q = max_seqlen_in_batch_k
1140
+ indices_q = indices_k
1141
+ elif query_length == 1:
1142
+ max_seqlen_in_batch_q = 1
1143
+ cu_seqlens_q = torch.arange(
1144
+ batch_size + 1, dtype=torch.int32, device=query_layer.device
1145
+ ) # There is a memcpy here, that is very bad.
1146
+ indices_q = cu_seqlens_q[:-1]
1147
+ query_layer = query_layer.squeeze(1)
1148
+ else:
1149
+ # The -q_len: slice assumes left padding.
1150
+ attention_mask = attention_mask[:, -query_length:]
1151
+ query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
1152
+
1153
+ return (
1154
+ query_layer,
1155
+ key_layer,
1156
+ value_layer,
1157
+ indices_q,
1158
+ (cu_seqlens_q, cu_seqlens_k),
1159
+ (max_seqlen_in_batch_q, max_seqlen_in_batch_k),
1160
+ )
1161
+
1162
+
1163
+ # copied from transformers.models.llama.modeling_llama.LlamaSdpaAttention with Llama->Phi3
1164
+ # TODO @Arthur no longer copied from LLama after static cache
1165
+ class Phi3SdpaAttention(Phi3Attention):
1166
+ """
1167
+ Phi3 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
1168
+ `Phi3Attention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
1169
+ SDPA API.
1170
+ """
1171
+
1172
+ # Adapted from Phi3Attention.forward
1173
+ def forward(
1174
+ self,
1175
+ hidden_states: torch.Tensor,
1176
+ attention_mask: Optional[torch.Tensor] = None,
1177
+ position_ids: Optional[torch.LongTensor] = None,
1178
+ past_key_value: Optional[Cache] = None,
1179
+ output_attentions: bool = False,
1180
+ use_cache: bool = False,
1181
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
1182
+ if output_attentions:
1183
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
1184
+ logger.warning_once(
1185
+ "ChexBonesModel is using Phi3SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
1186
+ '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.'
1187
+ )
1188
+ return super().forward(
1189
+ hidden_states=hidden_states,
1190
+ attention_mask=attention_mask,
1191
+ position_ids=position_ids,
1192
+ past_key_value=past_key_value,
1193
+ output_attentions=output_attentions,
1194
+ use_cache=use_cache,
1195
+ )
1196
+
1197
+ bsz, q_len, _ = hidden_states.size()
1198
+
1199
+ qkv = self.qkv_proj(hidden_states)
1200
+ query_pos = self.num_heads * self.head_dim
1201
+ query_states = qkv[..., :query_pos]
1202
+ key_states = qkv[..., query_pos : query_pos + self.num_key_value_heads * self.head_dim]
1203
+ value_states = qkv[..., query_pos + self.num_key_value_heads * self.head_dim :]
1204
+
1205
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
1206
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
1207
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
1208
+
1209
+ kv_seq_len = key_states.shape[-2]
1210
+ if past_key_value is not None:
1211
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
1212
+ cos, sin = self.rotary_emb(value_states, position_ids, seq_len=kv_seq_len)
1213
+
1214
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
1215
+
1216
+ if past_key_value is not None:
1217
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
1218
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
1219
+
1220
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
1221
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
1222
+
1223
+ if attention_mask is not None:
1224
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
1225
+ raise ValueError(
1226
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
1227
+ )
1228
+
1229
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
1230
+ # Reference: https://github.com/pytorch/pytorch/issues/112577.
1231
+ if query_states.device.type == "cuda" and attention_mask is not None:
1232
+ query_states = query_states.contiguous()
1233
+ key_states = key_states.contiguous()
1234
+ value_states = value_states.contiguous()
1235
+
1236
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
1237
+ query_states,
1238
+ key_states,
1239
+ value_states,
1240
+ attn_mask=attention_mask,
1241
+ dropout_p=self.attention_dropout if self.training else 0.0,
1242
+ # 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.
1243
+ is_causal=self.is_causal and attention_mask is None and q_len > 1,
1244
+ )
1245
+
1246
+ attn_output = attn_output.transpose(1, 2).contiguous()
1247
+ attn_output = attn_output.view(bsz, q_len, self.hidden_size)
1248
+
1249
+ attn_output = self.o_proj(attn_output)
1250
+
1251
+ return attn_output, None, past_key_value
1252
+
1253
+
1254
+ PHI3_ATTENTION_CLASSES = {
1255
+ "eager": Phi3Attention,
1256
+ "flash_attention_2": Phi3FlashAttention2,
1257
+ "sdpa": Phi3SdpaAttention,
1258
+ }
1259
+
1260
+
1261
+ class Phi3DecoderLayer(nn.Module):
1262
+ def __init__(self, config: ChexBonesConfig, layer_idx: int):
1263
+ super().__init__()
1264
+
1265
+ self.config = config
1266
+ self.self_attn = PHI3_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx=layer_idx)
1267
+
1268
+ self.mlp = Phi3MLP(config)
1269
+ self.input_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
1270
+
1271
+ self.resid_attn_dropout = nn.Dropout(config.resid_pdrop)
1272
+ self.resid_mlp_dropout = nn.Dropout(config.resid_pdrop)
1273
+ self.post_attention_layernorm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
1274
+
1275
+ def forward(
1276
+ self,
1277
+ hidden_states: torch.Tensor,
1278
+ attention_mask: Optional[torch.Tensor] = None,
1279
+ position_ids: Optional[torch.LongTensor] = None,
1280
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
1281
+ output_attentions: Optional[bool] = False,
1282
+ use_cache: Optional[bool] = False,
1283
+ **kwargs,
1284
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
1285
+ if "padding_mask" in kwargs:
1286
+ warnings.warn(
1287
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
1288
+ )
1289
+ """
1290
+ Args:
1291
+ hidden_states (`torch.FloatTensor`):
1292
+ input to the layer of shape `(batch, seq_len, embed_dim)`
1293
+ attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
1294
+ `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
1295
+ position_ids (`torch.LongTensor` of shape `({0})`, *optional*):
1296
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range
1297
+ `[0, config.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
1298
+ output_attentions (`bool`, *optional*):
1299
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
1300
+ returned tensors for more detail.
1301
+ use_cache (`bool`, *optional*):
1302
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
1303
+ (see `past_key_values`).
1304
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
1305
+ """
1306
+
1307
+ residual = hidden_states
1308
+
1309
+ hidden_states = self.input_layernorm(hidden_states)
1310
+
1311
+ # Self Attention
1312
+ attn_outputs, self_attn_weights, present_key_value = self.self_attn(
1313
+ hidden_states=hidden_states,
1314
+ attention_mask=attention_mask,
1315
+ position_ids=position_ids,
1316
+ past_key_value=past_key_value,
1317
+ output_attentions=output_attentions,
1318
+ use_cache=use_cache,
1319
+ )
1320
+
1321
+ hidden_states = residual + self.resid_attn_dropout(attn_outputs)
1322
+
1323
+ residual = hidden_states
1324
+ hidden_states = self.post_attention_layernorm(hidden_states)
1325
+ hidden_states = self.mlp(hidden_states)
1326
+ hidden_states = residual + self.resid_mlp_dropout(hidden_states)
1327
+
1328
+ outputs = (hidden_states,)
1329
+
1330
+ if output_attentions:
1331
+ outputs += (self_attn_weights,)
1332
+
1333
+ if use_cache:
1334
+ outputs += (present_key_value,)
1335
+
1336
+ return outputs
1337
+
1338
+
1339
+ CHEXBONES_START_DOCSTRING = r"""
1340
+
1341
+ """
1342
+
1343
+
1344
+ @add_start_docstrings(
1345
+ "Chex Bones Model.",
1346
+ CHEXBONES_START_DOCSTRING,
1347
+ )
1348
+ class ChexBonesPreTrainedModel(PreTrainedModel):
1349
+ config_class = ChexBonesConfig
1350
+ base_model_prefix = "model"
1351
+ supports_gradient_checkpointing = True
1352
+ _no_split_modules = ["Phi3DecoderLayer"]
1353
+ _skip_keys_device_placement = "past_key_values"
1354
+ _supports_flash_attn_2 = True
1355
+ _supports_sdpa = False
1356
+ _supports_cache_class = True
1357
+
1358
+ _version = "0.0.5"
1359
+
1360
+ def _init_weights(self, module):
1361
+ std = self.config.initializer_range
1362
+ if isinstance(module, nn.Linear):
1363
+ module.weight.data.normal_(mean=0.0, std=std)
1364
+ if module.bias is not None:
1365
+ module.bias.data.zero_()
1366
+ elif isinstance(module, nn.Embedding):
1367
+ module.weight.data.normal_(mean=0.0, std=std)
1368
+ if module.padding_idx is not None:
1369
+ module.weight.data[module.padding_idx].zero_()
1370
+
1371
+
1372
+ CHEXBONES_INPUTS_DOCSTRING = r"""
1373
+ Args:
1374
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
1375
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
1376
+ it.
1377
+
1378
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
1379
+ [`PreTrainedTokenizer.__call__`] for details.
1380
+
1381
+ [What are input IDs?](../glossary#input-ids)
1382
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
1383
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
1384
+
1385
+ - 1 for tokens that are **not masked**,
1386
+ - 0 for tokens that are **masked**.
1387
+
1388
+ [What are attention masks?](../glossary#attention-mask)
1389
+
1390
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
1391
+ [`PreTrainedTokenizer.__call__`] for details.
1392
+
1393
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
1394
+ `past_key_values`).
1395
+
1396
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
1397
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
1398
+ information on the default strategy.
1399
+
1400
+ - 1 indicates the head is **not masked**,
1401
+ - 0 indicates the head is **masked**.
1402
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1403
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
1404
+ config.n_positions - 1]`.
1405
+
1406
+ [What are position IDs?](../glossary#position-ids)
1407
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
1408
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
1409
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
1410
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
1411
+
1412
+ Two formats are allowed:
1413
+ - a [`~cache_utils.Cache`] instance;
1414
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
1415
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
1416
+ cache format.
1417
+
1418
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
1419
+ legacy cache format will be returned.
1420
+
1421
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
1422
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
1423
+ of shape `(batch_size, sequence_length)`.
1424
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
1425
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
1426
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
1427
+ model's internal embedding lookup matrix.
1428
+ pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)):
1429
+ The tensors corresponding to the input images. Pixel values can be obtained using [`AutoImageProcessor`].
1430
+ See [`ChexBonesImageProcessor.__call__`] for details.
1431
+ image_sizes (`torch.LongTensor` of shape `(batch_size, 2)`, *optional*):
1432
+ The sizes of the images in the batch, being (height, width) for each image.
1433
+ use_cache (`bool`, *optional*):
1434
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
1435
+ `past_key_values`).
1436
+ output_attentions (`bool`, *optional*):
1437
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
1438
+ tensors for more detail.
1439
+ output_hidden_states (`bool`, *optional*):
1440
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
1441
+ more detail.
1442
+ return_dict (`bool`, *optional*):
1443
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
1444
+ """
1445
+
1446
+
1447
+ #copied from transformers.models.phi-3.5-vision-instruct.modeling_phi3_v.Phi3VModel with Phi3->ChexBones
1448
+ @add_start_docstrings(
1449
+ "Chex Bones - CheXAgent",
1450
+ CHEXBONES_START_DOCSTRING,
1451
+ )
1452
+ class ChexBonesModel(ChexBonesPreTrainedModel):
1453
+ """
1454
+ """
1455
+
1456
+ def __init__(self, config: ChexBonesConfig):
1457
+ super().__init__(config)
1458
+ self.padding_idx = config.pad_token_id
1459
+ self.vocab_size = config.vocab_size
1460
+
1461
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
1462
+ self.embed_dropout = nn.Dropout(config.embd_pdrop)
1463
+
1464
+ self.vision_embed_tokens = None
1465
+ if isinstance(config.embd_layer, dict):
1466
+ # vision embedding layer
1467
+ embedding_config = {
1468
+ 'embedding_cls': config.embd_layer['embedding_cls'],
1469
+ **config.embd_layer
1470
+ }
1471
+ self.vision_embed_tokens = Phi3ImageEmbedding(config, wte=self.embed_tokens, **embedding_config)
1472
+ # # set wte the same for vision embedding
1473
+ # self.vision_embed_tokens.wte.weight = self.embed_tokens.weight
1474
+
1475
+ self.layers = nn.ModuleList(
1476
+ [Phi3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
1477
+ )
1478
+ self._attn_implementation = config._attn_implementation
1479
+ self.norm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
1480
+
1481
+ self.gradient_checkpointing = False
1482
+ # Initialize weights and apply final processing
1483
+ self.post_init()
1484
+
1485
+ def get_input_embeddings(self):
1486
+ return self.embed_tokens
1487
+
1488
+ def set_input_embeddings(self, value):
1489
+ self.embed_tokens = value
1490
+
1491
+ @add_start_docstrings_to_model_forward(CHEXBONES_INPUTS_DOCSTRING)
1492
+ def forward(
1493
+ self,
1494
+ input_ids: torch.LongTensor = None,
1495
+ attention_mask: Optional[torch.Tensor] = None,
1496
+ position_ids: Optional[torch.LongTensor] = None,
1497
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1498
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1499
+ pixel_values: Optional[torch.FloatTensor] = None,
1500
+ image_sizes: Optional[torch.LongTensor] = None,
1501
+ use_cache: Optional[bool] = None,
1502
+ output_attentions: Optional[bool] = None,
1503
+ output_hidden_states: Optional[bool] = None,
1504
+ return_dict: Optional[bool] = None,
1505
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
1506
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1507
+ output_hidden_states = (
1508
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1509
+ )
1510
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
1511
+
1512
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1513
+
1514
+ # retrieve input_ids and inputs_embeds
1515
+ if input_ids is not None and inputs_embeds is not None:
1516
+ raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
1517
+ elif input_ids is not None:
1518
+ batch_size, seq_length = input_ids.shape[:2]
1519
+ elif inputs_embeds is not None:
1520
+ batch_size, seq_length = inputs_embeds.shape[:2]
1521
+ else:
1522
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
1523
+
1524
+ past_key_values_length = 0
1525
+
1526
+ if self.gradient_checkpointing and self.training:
1527
+ if use_cache:
1528
+ logger.warning_once(
1529
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
1530
+ )
1531
+ use_cache = False
1532
+
1533
+ if use_cache:
1534
+ use_legacy_cache = not isinstance(past_key_values, Cache)
1535
+ if use_legacy_cache:
1536
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
1537
+ past_key_values_length = past_key_values.get_usable_length(seq_length)
1538
+
1539
+ if position_ids is None:
1540
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
1541
+ position_ids = torch.arange(
1542
+ past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
1543
+ )
1544
+ position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
1545
+ else:
1546
+ position_ids = position_ids.view(-1, seq_length).long()
1547
+
1548
+ if inputs_embeds is None:
1549
+ if pixel_values is not None and image_sizes is not None:
1550
+ assert self.vision_embed_tokens is not None, "Vision embedding layer is not defined"
1551
+ inputs_embeds = self.vision_embed_tokens(input_ids, pixel_values=pixel_values, image_sizes=image_sizes)
1552
+ else:
1553
+ inputs_embeds = self.embed_tokens(input_ids)
1554
+
1555
+ if attention_mask is not None and self._attn_implementation == "flash_attention_2" and use_cache:
1556
+ is_padding_right = attention_mask[:, -1].sum().item() != batch_size
1557
+ if is_padding_right:
1558
+ raise ValueError(
1559
+ "You are attempting to perform batched generation with padding_side='right'"
1560
+ " this may lead to unexpected behaviour for Flash Attention version of ChexBones. Make sure to "
1561
+ " call `tokenizer.padding_side = 'left'` before tokenizing the input. "
1562
+ )
1563
+
1564
+ if self._attn_implementation == "flash_attention_2":
1565
+ # 2d mask is passed through the layers
1566
+ attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
1567
+ else:
1568
+ # 4d mask is passed through the layers
1569
+ attention_mask = _prepare_4d_causal_attention_mask(
1570
+ attention_mask,
1571
+ (batch_size, seq_length),
1572
+ inputs_embeds,
1573
+ past_key_values_length,
1574
+ sliding_window=self.config.sliding_window,
1575
+ )
1576
+
1577
+ hidden_states = inputs_embeds
1578
+
1579
+ # decoder layers
1580
+ all_hidden_states = () if output_hidden_states else None
1581
+ all_self_attns = () if output_attentions else None
1582
+ next_decoder_cache = None
1583
+
1584
+ for decoder_layer in self.layers:
1585
+ if output_hidden_states:
1586
+ all_hidden_states += (hidden_states,)
1587
+
1588
+ if self.gradient_checkpointing and self.training:
1589
+ layer_outputs = self._gradient_checkpointing_func(
1590
+ decoder_layer.__call__,
1591
+ hidden_states,
1592
+ attention_mask,
1593
+ position_ids,
1594
+ past_key_values,
1595
+ output_attentions,
1596
+ use_cache,
1597
+ )
1598
+ else:
1599
+ layer_outputs = decoder_layer(
1600
+ hidden_states,
1601
+ attention_mask=attention_mask,
1602
+ position_ids=position_ids,
1603
+ past_key_value=past_key_values,
1604
+ output_attentions=output_attentions,
1605
+ use_cache=use_cache,
1606
+ )
1607
+
1608
+ hidden_states = layer_outputs[0]
1609
+
1610
+ if use_cache:
1611
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
1612
+
1613
+ if output_attentions:
1614
+ all_self_attns += (layer_outputs[1],)
1615
+
1616
+ hidden_states = self.norm(hidden_states)
1617
+
1618
+ # add hidden states from the last decoder layer
1619
+ if output_hidden_states:
1620
+ all_hidden_states += (hidden_states,)
1621
+
1622
+ next_cache = None
1623
+ if use_cache:
1624
+ next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
1625
+ if not return_dict:
1626
+ return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
1627
+ return BaseModelOutputWithPast(
1628
+ last_hidden_state=hidden_states,
1629
+ past_key_values=next_cache,
1630
+ hidden_states=all_hidden_states,
1631
+ attentions=all_self_attns,
1632
+ )
1633
+
1634
+ #copied from transformers.models.phi-3.5-vision-instruct.modeling_phi3_v.Phi3VForCausalLM with Phi3->ChexBones
1635
+ class ChexBonesForCausalLM(ChexBonesPreTrainedModel):
1636
+ _tied_weights_keys = ["lm_head.weight", 'model.embed_tokens.weight', 'model.vision_embed_tokens.wte.weight']
1637
+
1638
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.__init__ with Llama->Phi3
1639
+ def __init__(self, config):
1640
+ super().__init__(config)
1641
+ self.model = ChexBonesModel(config)
1642
+ self.vocab_size = config.vocab_size
1643
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
1644
+
1645
+ # Initialize weights and apply final processing
1646
+ self.post_init()
1647
+
1648
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_input_embeddings
1649
+ def get_input_embeddings(self):
1650
+ return self.model.embed_tokens
1651
+
1652
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_input_embeddings
1653
+ def set_input_embeddings(self, value):
1654
+ self.model.embed_tokens = value
1655
+
1656
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_output_embeddings
1657
+ def get_output_embeddings(self):
1658
+ return self.lm_head
1659
+
1660
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_output_embeddings
1661
+ def set_output_embeddings(self, new_embeddings):
1662
+ self.lm_head = new_embeddings
1663
+
1664
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.set_decoder
1665
+ def set_decoder(self, decoder):
1666
+ self.model = decoder
1667
+
1668
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.get_decoder
1669
+ def get_decoder(self):
1670
+ return self.model
1671
+
1672
+ # Ignore copy
1673
+ @add_start_docstrings_to_model_forward(CHEXBONES_INPUTS_DOCSTRING)
1674
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
1675
+ def forward(
1676
+ self,
1677
+ input_ids: torch.LongTensor = None,
1678
+ attention_mask: Optional[torch.Tensor] = None,
1679
+ position_ids: Optional[torch.LongTensor] = None,
1680
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1681
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1682
+ pixel_values: Optional[torch.FloatTensor] = None,
1683
+ image_sizes: Optional[torch.LongTensor] = None,
1684
+ labels: Optional[torch.LongTensor] = None,
1685
+ use_cache: Optional[bool] = None,
1686
+ output_attentions: Optional[bool] = None,
1687
+ output_hidden_states: Optional[bool] = None,
1688
+ return_dict: Optional[bool] = None,
1689
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1690
+ r"""
1691
+ Args:
1692
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1693
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1694
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1695
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1696
+
1697
+ Returns:
1698
+ ```"""
1699
+
1700
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1701
+ output_hidden_states = (
1702
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1703
+ )
1704
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1705
+
1706
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1707
+ outputs = self.model(
1708
+ input_ids=input_ids,
1709
+ attention_mask=attention_mask,
1710
+ position_ids=position_ids,
1711
+ past_key_values=past_key_values,
1712
+ inputs_embeds=inputs_embeds,
1713
+ pixel_values=pixel_values,
1714
+ image_sizes=image_sizes,
1715
+ use_cache=use_cache,
1716
+ output_attentions=output_attentions,
1717
+ output_hidden_states=output_hidden_states,
1718
+ return_dict=return_dict,
1719
+ )
1720
+
1721
+ hidden_states = outputs[0]
1722
+ logits = self.lm_head(hidden_states)
1723
+ logits = logits.float()
1724
+
1725
+ loss = None
1726
+ if labels is not None:
1727
+ # Shift so that tokens < n predict n
1728
+ shift_logits = logits[..., :-1, :].contiguous()
1729
+ shift_labels = labels[..., 1:].contiguous()
1730
+ # Flatten the tokens
1731
+ loss_fct = CrossEntropyLoss()
1732
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1733
+ shift_labels = shift_labels.view(-1)
1734
+ # Enable model parallelism
1735
+ shift_labels = shift_labels.to(shift_logits.device)
1736
+ loss = loss_fct(shift_logits, shift_labels)
1737
+
1738
+ if not return_dict:
1739
+ output = (logits,) + outputs[1:]
1740
+ return (loss,) + output if loss is not None else output
1741
+
1742
+ return CausalLMOutputWithPast(
1743
+ loss=loss,
1744
+ logits=logits,
1745
+ past_key_values=outputs.past_key_values,
1746
+ hidden_states=outputs.hidden_states,
1747
+ attentions=outputs.attentions,
1748
+ )
1749
+
1750
+ # Copied from transformers.models.persimmon.modeling_persimmon.PersimmonForCausalLM.prepare_inputs_for_generation
1751
+ def prepare_inputs_for_generation(
1752
+ self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, pixel_values=None, image_sizes=None, **kwargs
1753
+ ):
1754
+ # When the first time input length reached long and short factor switching point, enforce re-compute cache
1755
+ # It will cause downside of slower at this single token position, however, better than current failure.
1756
+ if past_key_values and self.config.rope_scaling and input_ids.shape[1] >= self.config.original_max_position_embeddings + 1:
1757
+ past_length = past_key_values.seen_tokens if isinstance(past_key_values, Cache) else past_key_values[0][0].shape[2]
1758
+ if past_length <= self.config.original_max_position_embeddings:
1759
+ past_key_values = None
1760
+
1761
+ if past_key_values is not None:
1762
+ if isinstance(past_key_values, Cache):
1763
+ cache_length = past_key_values.get_seq_length()
1764
+ past_length = past_key_values.seen_tokens
1765
+ max_cache_length = past_key_values.get_max_length()
1766
+ else:
1767
+ cache_length = past_length = past_key_values[0][0].shape[2]
1768
+ max_cache_length = None
1769
+
1770
+ # Keep only the unprocessed tokens:
1771
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
1772
+ # some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
1773
+ # input)
1774
+ if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
1775
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
1776
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
1777
+ # input_ids based on the past_length.
1778
+ elif past_length < input_ids.shape[1]:
1779
+ input_ids = input_ids[:, past_length:]
1780
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
1781
+
1782
+ # If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
1783
+ if (
1784
+ max_cache_length is not None
1785
+ and attention_mask is not None
1786
+ and cache_length + input_ids.shape[1] > max_cache_length
1787
+ ):
1788
+ attention_mask = attention_mask[:, -max_cache_length:]
1789
+
1790
+ position_ids = kwargs.get("position_ids", None)
1791
+ if attention_mask is not None and position_ids is None:
1792
+ # create position_ids on the fly for batch generation
1793
+ position_ids = attention_mask.long().cumsum(-1) - 1
1794
+ position_ids.masked_fill_(attention_mask == 0, 1)
1795
+ if past_key_values:
1796
+ position_ids = position_ids[:, -input_ids.shape[1] :]
1797
+
1798
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1799
+ if inputs_embeds is not None and past_key_values is None:
1800
+ model_inputs = {"inputs_embeds": inputs_embeds}
1801
+ else:
1802
+ model_inputs = {"input_ids": input_ids}
1803
+
1804
+ model_inputs.update(
1805
+ {
1806
+ "position_ids": position_ids,
1807
+ "past_key_values": past_key_values,
1808
+ "use_cache": kwargs.get("use_cache"),
1809
+ "attention_mask": attention_mask,
1810
+ "pixel_values": pixel_values,
1811
+ "image_sizes": image_sizes,
1812
+ }
1813
+ )
1814
+ return model_inputs
1815
+
1816
+ @staticmethod
1817
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM._reorder_cache
1818
+ def _reorder_cache(past_key_values, beam_idx):
1819
+ reordered_past = ()
1820
+ for layer_past in past_key_values:
1821
+ reordered_past += (
1822
+ tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
1823
+ )
1824
+ return reordered_past
1825
+
preprocessor_config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoProcessor": "processing_chexbones.ChexBonesProcessor"
4
+ },
5
+ "crop_size": {
6
+ "height": 448,
7
+ "width": 448
8
+ },
9
+ "do_convert_rgb": true,
10
+ "do_normalize": true,
11
+ "do_rescale": true,
12
+ "do_resize": true,
13
+ "image_mean": [
14
+ 0.48145466,
15
+ 0.4578275,
16
+ 0.40821073
17
+ ],
18
+ "image_processor_type": "BlipImageProcessor",
19
+ "image_std": [
20
+ 0.26862954,
21
+ 0.26130258,
22
+ 0.27577711
23
+ ],
24
+ "processor_class": "ChexBonesProcessor",
25
+ "resample": 3,
26
+ "rescale_factor": 0.00392156862745098,
27
+ "size": {
28
+ "height": 448,
29
+ "width": 448
30
+ }
31
+ }
processing_chexbones.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 Microsoft and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import re
17
+ from typing import List, Optional, Union
18
+
19
+ import torch
20
+
21
+ from transformers.feature_extraction_utils import BatchFeature
22
+ from transformers.image_utils import ImageInput
23
+ from transformers.processing_utils import ProcessorMixin
24
+ from transformers.tokenization_utils_base import PaddingStrategy, TextInput, TruncationStrategy
25
+ from transformers.utils import TensorType
26
+
27
+
28
+ from typing import List, Optional, Union
29
+
30
+ import numpy as np
31
+
32
+ from transformers.image_processing_utils import BatchFeature
33
+ from transformers.image_utils import (
34
+ ImageInput,
35
+ )
36
+ from transformers.utils import TensorType, is_vision_available, logging
37
+
38
+
39
+ logger = logging.get_logger(__name__)
40
+
41
+
42
+ if is_vision_available():
43
+ from PIL import Image
44
+
45
+ import torch
46
+
47
+
48
+
49
+ def pad_to_max_num_crops_tensor(images, max_crops=5):
50
+ """
51
+ images: B x 3 x H x W, B<=max_crops
52
+ """
53
+ B, _, H, W = images.shape
54
+ if B < max_crops:
55
+ pad = torch.zeros(max_crops - B, 3, H, W, dtype=images.dtype, device=images.device)
56
+ images = torch.cat([images, pad], dim=0)
57
+ return images
58
+
59
+ DINO_NUM_TOKENS = 1024
60
+
61
+
62
+ #copied from transformers.models.phi-3.5-vision-instruct.processing_phi3.Phi3Processor with Phi3->ChexBones
63
+ class ChexBonesProcessor(ProcessorMixin):
64
+ r"""
65
+
66
+ """
67
+
68
+ attributes = [ "tokenizer", "image_processor"]
69
+ image_processor_class = "BlipImageProcessor"
70
+ tokenizer_class = ("LlamaTokenizer", "LlamaTokenizerFast")
71
+ special_image_token = "<|image|>"
72
+ # valid_kwargs = ['dino_config'] #stay it here
73
+
74
+
75
+ def __init__(self, tokenizer, image_processor):
76
+ #self.image_processor = AutoImageProcessor.from_pretrained(dino_checkpoint)
77
+ self.image_processor = image_processor # BitImageProcessor(**dino_config)
78
+ self.tokenizer = tokenizer
79
+ self.num_img_tokens = DINO_NUM_TOKENS
80
+ self.img_tokens = [f"<|image_{i+1}|>" for i in range(1000000)]
81
+ self.chat_template = None
82
+
83
+ def __call__(
84
+ self,
85
+ text: Union[TextInput, List[TextInput]],
86
+ images: ImageInput = None,
87
+ padding: Union[bool, str, PaddingStrategy] = False,
88
+ truncation: Union[bool, str, TruncationStrategy] = None,
89
+ max_length=None,
90
+ return_tensors: Optional[Union[str, TensorType]] = TensorType.PYTORCH,
91
+ ) -> BatchFeature:
92
+ """
93
+ Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
94
+ and `kwargs` arguments to LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to encode
95
+ the text. To prepare the image(s), this method forwards the `images` and `kwrags` arguments to
96
+ ChexBonesImageProcessor's if `images` is not `None`. Please refer to the doctsring
97
+ of the above two methods for more information.
98
+
99
+ Args:
100
+ text (`str`, `List[str]`, `List[List[str]]`):
101
+ The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
102
+ (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
103
+ `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
104
+ images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
105
+ The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
106
+ tensor. Both channels-first and channels-last formats are supported.
107
+ padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `False`):
108
+ Select a strategy to pad the returned sequences (according to the model's padding side and padding
109
+ index) among:
110
+ - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
111
+ sequence if provided).
112
+ - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
113
+ acceptable input length for the model if that argument is not provided.
114
+ - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
115
+ lengths).
116
+ max_length (`int`, *optional*):
117
+ Maximum length of the returned list and optionally padding length (see above).
118
+ truncation (`bool`, *optional*):
119
+ Activates truncation to cut input sequences longer than `max_length` to `max_length`.
120
+ return_tensors (`str` or [`~utils.TensorType`], *optional*):
121
+ If set, will return tensors of a particular framework. Acceptable values are:
122
+
123
+ - `'tf'`: Return TensorFlow `tf.constant` objects.
124
+ - `'pt'`: Return PyTorch `torch.Tensor` objects.
125
+ - `'np'`: Return NumPy `np.ndarray` objects.
126
+ - `'jax'`: Return JAX `jnp.ndarray` objects.
127
+
128
+ Returns:
129
+ [`BatchFeature`]: A [`BatchFeature`] with the following fields:
130
+
131
+ - **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
132
+ - **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
133
+ `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
134
+ `None`).
135
+ - **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
136
+ """
137
+ if images is not None:
138
+ image_inputs = self.image_processor(images, return_tensors=return_tensors)
139
+ batch_size = image_inputs['pixel_values'].shape[0]
140
+ image_inputs = {"pixel_values": image_inputs['pixel_values'][:,None,...],
141
+ "image_sizes": torch.Tensor([448,448])[None,...].repeat(batch_size,1),
142
+ "num_img_tokens": torch.Tensor([DINO_NUM_TOKENS]).to( dtype=torch.uint16)[None,...].repeat(batch_size,1)
143
+ }
144
+ else:
145
+ image_inputs = {}
146
+ inputs = self._convert_images_texts_to_inputs(image_inputs, text, padding=padding, truncation=truncation, max_length=max_length, return_tensors=return_tensors)
147
+ return inputs
148
+
149
+ def calc_num_image_tokens(self, images: ImageInput):
150
+ """ Calculate the number of image tokens for each image.
151
+ Args:
152
+ images (`ImageInput`):
153
+ Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
154
+ passing in images with pixel values between 0 and 1, set `do_rescale=False`.
155
+ """
156
+ return DINO_NUM_TOKENS
157
+ #return self.image_processor.calc_num_image_tokens(images)
158
+
159
+ def calc_num_image_tokens_from_image_size(self, width, height):
160
+ """ Calculate the number of image token for an image with given width and height.
161
+ Args:
162
+ width (`int`):
163
+ Width of the image.
164
+ height (`int`):
165
+ Height of the image.
166
+ """
167
+ return DINO_NUM_TOKENS
168
+ #return self.image_processor.calc_num_image_tokens_from_image_size(width, height)
169
+
170
+
171
+ @property
172
+ def special_image_token_id(self):
173
+ return self.tokenizer.convert_tokens_to_ids(self.special_image_token)
174
+
175
+ def get_special_image_token_id(self):
176
+ return self.tokenizer.convert_tokens_to_ids(self.special_image_token)
177
+
178
+ def _convert_images_texts_to_inputs(self, images, texts, padding=False, truncation=None, max_length=None, return_tensors=None):
179
+
180
+ if not len(images):
181
+ model_inputs = self.tokenizer(texts, return_tensors=return_tensors, padding=padding, truncation=truncation, max_length=max_length)
182
+ return BatchFeature(data={**model_inputs})
183
+
184
+ pattern = r"<\|image_\d+\|>"
185
+ prompt_chunks = [self.tokenizer(chunk).input_ids for chunk in re.split(pattern, texts)]
186
+
187
+ if 'num_img_tokens' in images:
188
+ num_img_tokens = images['num_img_tokens']
189
+ else:
190
+ assert 'num_crops' in images, 'num_crops must be provided in images if num_img_tokens is not provided'
191
+ num_crops = images['num_crops']
192
+ num_img_tokens = [_num_crops * self.num_img_tokens for _num_crops in num_crops]
193
+
194
+ images, image_sizes = images['pixel_values'], images['image_sizes']
195
+
196
+ # image_tags needs to start from 1 to n
197
+ image_tags = re.findall(pattern, texts)
198
+ # image_ids = [int(s.split("|")[1].split("_")[-1]) * -1 for s in image_tags]
199
+ # image_ids_pad = [[iid]*num_img_tokens[i] for i, iid in enumerate(image_ids)]
200
+ image_ids = [int(s.split("|")[1].split("_")[-1]) for s in image_tags]
201
+ unique_image_ids = sorted(list(set(image_ids)))
202
+ # image_ids must start from 1, and must be continuous int, e.g. [1, 2, 3], cannot be [1, 4, 5]
203
+ # check the condition
204
+ assert unique_image_ids == list(range(1, len(unique_image_ids)+1)), f"image_ids must start from 1, and must be continuous int, e.g. [1, 2, 3], cannot be {unique_image_ids}"
205
+ # total images must be the same as the number of image tags
206
+ assert len(unique_image_ids) == len(images), f"total images must be the same as the number of image tags, got {len(unique_image_ids)} image tags and {len(images)} images"
207
+
208
+ image_ids_pad = [[-iid]*num_img_tokens[iid-1] for iid in image_ids]
209
+
210
+ def insert_separator(X, sep_list):
211
+ if len(X) > len(sep_list):
212
+ sep_list.append([])
213
+ return [ele for sublist in zip(X, sep_list) for ele in sublist]
214
+ input_ids = []
215
+ offset = 0
216
+ for x in insert_separator(prompt_chunks, image_ids_pad):
217
+ input_ids.extend(x[offset:])
218
+
219
+ input_ids = torch.tensor(input_ids, dtype=torch.long).unsqueeze(0)
220
+ attention_mask = (input_ids > -1000000).to(torch.long)
221
+
222
+ return BatchFeature(data={"input_ids": input_ids,
223
+ "attention_mask": attention_mask,
224
+ "pixel_values": images,
225
+ "image_sizes": image_sizes})
226
+
227
+
228
+ # Copied from transformers.models.clip.processing_clip.CLIPProcessor.batch_decode with CLIP->Llama
229
+ def batch_decode(self, *args, **kwargs):
230
+ """
231
+ This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
232
+ refer to the docstring of this method for more information.
233
+ """
234
+ return self.tokenizer.batch_decode(*args, **kwargs)
235
+
236
+ # Copied from transformers.models.clip.processing_clip.CLIPProcessor.decode with CLIP->Llama
237
+ def decode(self, *args, **kwargs):
238
+ """
239
+ This method forwards all its arguments to LlamaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
240
+ the docstring of this method for more information.
241
+ """
242
+ return self.tokenizer.decode(*args, **kwargs)
243
+
244
+ @property
245
+ # Copied from transformers.models.clip.processing_clip.CLIPProcessor.model_input_names
246
+ def model_input_names(self):
247
+ tokenizer_input_names = self.tokenizer.model_input_names
248
+ image_processor_input_names = self.image_processor.model_input_names
249
+ return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))
processor_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoProcessor": "processing_chexbones.ChexBonesProcessor"
4
+ },
5
+ "processor_class": "ChexBonesProcessor"
6
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|system|>",
4
+ "<|end|>",
5
+ "<|user|>",
6
+ "<|end|>"
7
+ ],
8
+ "bos_token": {
9
+ "content": "<s>",
10
+ "lstrip": false,
11
+ "normalized": false,
12
+ "rstrip": false,
13
+ "single_word": false
14
+ },
15
+ "eos_token": {
16
+ "content": "<|endoftext|>",
17
+ "lstrip": false,
18
+ "normalized": false,
19
+ "rstrip": false,
20
+ "single_word": false
21
+ },
22
+ "pad_token": "<unk>",
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": null,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": true,
27
+ "single_word": false,
28
+ "special": false
29
+ },
30
+ "32000": {
31
+ "content": "<|endoftext|>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ },
38
+ "32001": {
39
+ "content": "<|assistant|>",
40
+ "lstrip": false,
41
+ "normalized": false,
42
+ "rstrip": true,
43
+ "single_word": false,
44
+ "special": true
45
+ },
46
+ "32002": {
47
+ "content": "<|placeholder1|>",
48
+ "lstrip": false,
49
+ "normalized": false,
50
+ "rstrip": true,
51
+ "single_word": false,
52
+ "special": true
53
+ },
54
+ "32003": {
55
+ "content": "<|placeholder2|>",
56
+ "lstrip": false,
57
+ "normalized": false,
58
+ "rstrip": true,
59
+ "single_word": false,
60
+ "special": true
61
+ },
62
+ "32004": {
63
+ "content": "<|placeholder3|>",
64
+ "lstrip": false,
65
+ "normalized": false,
66
+ "rstrip": true,
67
+ "single_word": false,
68
+ "special": true
69
+ },
70
+ "32005": {
71
+ "content": "<|placeholder4|>",
72
+ "lstrip": false,
73
+ "normalized": false,
74
+ "rstrip": true,
75
+ "single_word": false,
76
+ "special": true
77
+ },
78
+ "32006": {
79
+ "content": "<|system|>",
80
+ "lstrip": false,
81
+ "normalized": false,
82
+ "rstrip": false,
83
+ "single_word": false,
84
+ "special": true
85
+ },
86
+ "32007": {
87
+ "content": "<|end|>",
88
+ "lstrip": false,
89
+ "normalized": false,
90
+ "rstrip": false,
91
+ "single_word": false,
92
+ "special": true
93
+ },
94
+ "32008": {
95
+ "content": "<|placeholder5|>",
96
+ "lstrip": false,
97
+ "normalized": false,
98
+ "rstrip": true,
99
+ "single_word": false,
100
+ "special": true
101
+ },
102
+ "32009": {
103
+ "content": "<|placeholder6|>",
104
+ "lstrip": false,
105
+ "normalized": false,
106
+ "rstrip": true,
107
+ "single_word": false,
108
+ "special": true
109
+ },
110
+ "32010": {
111
+ "content": "<|user|>",
112
+ "lstrip": false,
113
+ "normalized": false,
114
+ "rstrip": false,
115
+ "single_word": false,
116
+ "special": true
117
+ },
118
+ "32011": {
119
+ "content": "<|placeholder7|>",
120
+ "lstrip": false,
121
+ "normalized": false,
122
+ "rstrip": true,
123
+ "single_word": false,
124
+ "special": true
125
+ },
126
+ "32012": {
127
+ "content": "<|placeholder8|>",
128
+ "lstrip": false,
129
+ "normalized": false,
130
+ "rstrip": true,
131
+ "single_word": false,
132
+ "special": true
133
+ },
134
+ "32013": {
135
+ "content": "<|placeholder9|>",
136
+ "lstrip": false,
137
+ "normalized": false,
138
+ "rstrip": true,
139
+ "single_word": false,
140
+ "special": true
141
+ },
142
+ "32014": {
143
+ "content": "<|placeholder10|>",
144
+ "lstrip": false,
145
+ "normalized": false,
146
+ "rstrip": true,
147
+ "single_word": false,
148
+ "special": true
149
+ },
150
+ "32015": {
151
+ "content": "<|placeholder11|>",
152
+ "lstrip": false,
153
+ "normalized": false,
154
+ "rstrip": true,
155
+ "single_word": false,
156
+ "special": true
157
+ },
158
+ "32016": {
159
+ "content": "<|placeholder12|>",
160
+ "lstrip": false,
161
+ "normalized": false,
162
+ "rstrip": true,
163
+ "single_word": false,
164
+ "special": true
165
+ },
166
+ "32017": {
167
+ "content": "<|placeholder13|>",
168
+ "lstrip": false,
169
+ "normalized": false,
170
+ "rstrip": true,
171
+ "single_word": false,
172
+ "special": true
173
+ },
174
+ "32018": {
175
+ "content": "<|placeholder14|>",
176
+ "lstrip": false,
177
+ "normalized": false,
178
+ "rstrip": true,
179
+ "single_word": false,
180
+ "special": true
181
+ },
182
+ "32019": {
183
+ "content": "<|placeholder15|>",
184
+ "lstrip": false,
185
+ "normalized": false,
186
+ "rstrip": true,
187
+ "single_word": false,
188
+ "special": true
189
+ },
190
+ "32020": {
191
+ "content": "<|placeholder16|>",
192
+ "lstrip": false,
193
+ "normalized": false,
194
+ "rstrip": true,
195
+ "single_word": false,
196
+ "special": true
197
+ },
198
+ "32021": {
199
+ "content": "<|placeholder17|>",
200
+ "lstrip": false,
201
+ "normalized": false,
202
+ "rstrip": true,
203
+ "single_word": false,
204
+ "special": true
205
+ },
206
+ "32022": {
207
+ "content": "<|placeholder18|>",
208
+ "lstrip": false,
209
+ "normalized": false,
210
+ "rstrip": true,
211
+ "single_word": false,
212
+ "special": true
213
+ },
214
+ "32023": {
215
+ "content": "<|placeholder19|>",
216
+ "lstrip": false,
217
+ "normalized": false,
218
+ "rstrip": true,
219
+ "single_word": false,
220
+ "special": true
221
+ },
222
+ "32024": {
223
+ "content": "<|placeholder20|>",
224
+ "lstrip": false,
225
+ "normalized": false,
226
+ "rstrip": true,
227
+ "single_word": false,
228
+ "special": true
229
+ },
230
+ "32025": {
231
+ "content": "<|placeholder21|>",
232
+ "lstrip": false,
233
+ "normalized": false,
234
+ "rstrip": true,
235
+ "single_word": false,
236
+ "special": true
237
+ },
238
+ "32026": {
239
+ "content": "<|placeholder22|>",
240
+ "lstrip": false,
241
+ "normalized": false,
242
+ "rstrip": true,
243
+ "single_word": false,
244
+ "special": true
245
+ },
246
+ "32027": {
247
+ "content": "<|placeholder23|>",
248
+ "lstrip": false,
249
+ "normalized": false,
250
+ "rstrip": true,
251
+ "single_word": false,
252
+ "special": true
253
+ },
254
+ "32028": {
255
+ "content": "<|placeholder24|>",
256
+ "lstrip": false,
257
+ "normalized": false,
258
+ "rstrip": true,
259
+ "single_word": false,
260
+ "special": true
261
+ },
262
+ "32029": {
263
+ "content": "<|placeholder25|>",
264
+ "lstrip": false,
265
+ "normalized": false,
266
+ "rstrip": true,
267
+ "single_word": false,
268
+ "special": true
269
+ },
270
+ "32030": {
271
+ "content": "<|placeholder26|>",
272
+ "lstrip": false,
273
+ "normalized": false,
274
+ "rstrip": true,
275
+ "single_word": false,
276
+ "special": true
277
+ },
278
+ "32031": {
279
+ "content": "<|placeholder27|>",
280
+ "lstrip": false,
281
+ "normalized": false,
282
+ "rstrip": true,
283
+ "single_word": false,
284
+ "special": true
285
+ },
286
+ "32032": {
287
+ "content": "<|placeholder28|>",
288
+ "lstrip": false,
289
+ "normalized": false,
290
+ "rstrip": true,
291
+ "single_word": false,
292
+ "special": true
293
+ },
294
+ "32033": {
295
+ "content": "<|placeholder29|>",
296
+ "lstrip": false,
297
+ "normalized": false,
298
+ "rstrip": true,
299
+ "single_word": false,
300
+ "special": true
301
+ },
302
+ "32034": {
303
+ "content": "<|placeholder30|>",
304
+ "lstrip": false,
305
+ "normalized": false,
306
+ "rstrip": true,
307
+ "single_word": false,
308
+ "special": true
309
+ },
310
+ "32035": {
311
+ "content": "<|placeholder31|>",
312
+ "lstrip": false,
313
+ "normalized": false,
314
+ "rstrip": true,
315
+ "single_word": false,
316
+ "special": true
317
+ },
318
+ "32036": {
319
+ "content": "<|placeholder32|>",
320
+ "lstrip": false,
321
+ "normalized": false,
322
+ "rstrip": true,
323
+ "single_word": false,
324
+ "special": true
325
+ },
326
+ "32037": {
327
+ "content": "<|placeholder33|>",
328
+ "lstrip": false,
329
+ "normalized": false,
330
+ "rstrip": true,
331
+ "single_word": false,
332
+ "special": true
333
+ },
334
+ "32038": {
335
+ "content": "<|placeholder34|>",
336
+ "lstrip": false,
337
+ "normalized": false,
338
+ "rstrip": true,
339
+ "single_word": false,
340
+ "special": true
341
+ },
342
+ "32039": {
343
+ "content": "<|placeholder35|>",
344
+ "lstrip": false,
345
+ "normalized": false,
346
+ "rstrip": true,
347
+ "single_word": false,
348
+ "special": true
349
+ },
350
+ "32040": {
351
+ "content": "<|placeholder36|>",
352
+ "lstrip": false,
353
+ "normalized": false,
354
+ "rstrip": true,
355
+ "single_word": false,
356
+ "special": true
357
+ },
358
+ "32041": {
359
+ "content": "<|placeholder37|>",
360
+ "lstrip": false,
361
+ "normalized": false,
362
+ "rstrip": true,
363
+ "single_word": false,
364
+ "special": true
365
+ },
366
+ "32042": {
367
+ "content": "<|placeholder38|>",
368
+ "lstrip": false,
369
+ "normalized": false,
370
+ "rstrip": true,
371
+ "single_word": false,
372
+ "special": true
373
+ },
374
+ "32043": {
375
+ "content": "<|placeholder39|>",
376
+ "lstrip": false,
377
+ "normalized": false,
378
+ "rstrip": true,
379
+ "single_word": false,
380
+ "special": true
381
+ },
382
+ "32044": {
383
+ "content": "<|image|>",
384
+ "lstrip": false,
385
+ "normalized": false,
386
+ "rstrip": true,
387
+ "single_word": false,
388
+ "special": true
389
+ }
390
+ },
391
+ "additional_special_tokens": [
392
+ "<|system|>",
393
+ "<|end|>",
394
+ "<|user|>",
395
+ "<|end|>"
396
+ ],
397
+ "auto_map": {
398
+ "AutoProcessor": "processing_phi3_dino.Phi3DinoProcessor"
399
+ },
400
+ "bos_token": "<s>",
401
+ "chat_template": "{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}{{- '<|assistant|>\n' -}}{% endif %}",
402
+ "clean_up_tokenization_spaces": false,
403
+ "eos_token": "<|endoftext|>",
404
+ "legacy": false,
405
+ "model_max_length": 131072,
406
+ "num_crops": 16,
407
+ "pad_token": "<unk>",
408
+ "padding_side": "right",
409
+ "processor_class": "Phi3DinoProcessor",
410
+ "sp_model_kwargs": {},
411
+ "tokenizer_class": "LlamaTokenizer",
412
+ "unk_token": "<unk>",
413
+ "use_default_system_prompt": false
414
+ }