finalf0 commited on
Commit
c4a230f
1 Parent(s): 3c72269
README.MD ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## 使用方法
2
+ ```python
3
+ import torch
4
+ from PIL import Image
5
+ from transformers import AutoModel, AutoTokenizer
6
+
7
+ model = AutoModel.from_pretrained('openbmb/MiniCPM-V/', trust_remote_code=True)
8
+ tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V', trust_remote_code=True)
9
+
10
+ model.eval().cuda()
11
+
12
+ image = Image.open('xx.jpg').convert('RGB')
13
+
14
+ question = '请描述一下该图像'
15
+ res, context, _ = model.chat(
16
+ image=image,
17
+ question=question,
18
+ context=None,
19
+ tokenizer=tokenizer,
20
+ sampling=True,
21
+ temperature=0.7
22
+ )
23
+
24
+ print(res)
25
+ ```
config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/home/hf_minicpmv/",
3
+ "architectures": [
4
+ "MiniCPMV"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_minicpm.MiniCPMVConfig",
10
+ "AutoModel": "modeling_minicpmv.MiniCPMV",
11
+ "AutoModelForCausalLM": "modeling_minicpmv.MiniCPMV"
12
+ },
13
+ "bos_token_id": 1,
14
+ "dim_model_base": 256,
15
+ "drop_vision_last_layer": true,
16
+ "eos_token_id": 2,
17
+ "hidden_act": "silu",
18
+ "hidden_size": 2304,
19
+ "image_size": 448,
20
+ "initializer_range": 0.1,
21
+ "intermediate_size": 5760,
22
+ "max_position_embeddings": 2048,
23
+ "model_type": "minicpmv",
24
+ "num_attention_heads": 36,
25
+ "num_hidden_layers": 40,
26
+ "num_key_value_heads": 36,
27
+ "pretraining_tp": 1,
28
+ "query_num": 64,
29
+ "rms_norm_eps": 1e-05,
30
+ "rope_scaling": null,
31
+ "rope_theta": 10000.0,
32
+ "scale_depth": 1.4,
33
+ "scale_emb": 12,
34
+ "tie_word_embeddings": false,
35
+ "torch_dtype": "bfloat16",
36
+ "transformers_version": "4.36.0",
37
+ "use_cache": true,
38
+ "vision_encoder": "vit_so400m_patch14_siglip_384.webli",
39
+ "vocab_size": 122753
40
+ }
configuration_minicpm.py ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ """ MiniCPM model configuration"""
21
+
22
+ from transformers.configuration_utils import PretrainedConfig
23
+ from transformers.utils import logging
24
+
25
+
26
+ logger = logging.get_logger(__name__)
27
+
28
+ MINICPM_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
29
+
30
+
31
+ class MiniCPMConfig(PretrainedConfig):
32
+ r"""
33
+ This is the configuration class to store the configuration of a [`MiniCPMModel`]. It is used to instantiate an MiniCPM
34
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
35
+ defaults will yield a similar configuration to that of the MiniCPM-7B.
36
+
37
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
38
+ documentation from [`PretrainedConfig`] for more information.
39
+
40
+
41
+ Args:
42
+ vocab_size (`int`, *optional*, defaults to 32000):
43
+ Vocabulary size of the MiniCPM model. Defines the number of different tokens that can be represented by the
44
+ `inputs_ids` passed when calling [`MiniCPMModel`]
45
+ hidden_size (`int`, *optional*, defaults to 4096):
46
+ Dimension of the hidden representations.
47
+ intermediate_size (`int`, *optional*, defaults to 11008):
48
+ Dimension of the MLP representations.
49
+ num_hidden_layers (`int`, *optional*, defaults to 32):
50
+ Number of hidden layers in the Transformer decoder.
51
+ num_attention_heads (`int`, *optional*, defaults to 32):
52
+ Number of attention heads for each attention layer in the Transformer decoder.
53
+ num_key_value_heads (`int`, *optional*):
54
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
55
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
56
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
57
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
58
+ by meanpooling all the original heads within that group. For more details checkout [this
59
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
60
+ `num_attention_heads`.
61
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
62
+ The non-linear activation function (function or string) in the decoder.
63
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
64
+ The maximum sequence length that this model might ever be used with. MiniCPM 1 supports up to 2048 tokens,
65
+ MiniCPM 2 up to 4096, CodeMiniCPM up to 16384.
66
+ initializer_range (`float`, *optional*, defaults to 0.02):
67
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
68
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
69
+ The epsilon used by the rms normalization layers.
70
+ use_cache (`bool`, *optional*, defaults to `True`):
71
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
72
+ relevant if `config.is_decoder=True`.
73
+ pad_token_id (`int`, *optional*):
74
+ Padding token id.
75
+ bos_token_id (`int`, *optional*, defaults to 1):
76
+ Beginning of stream token id.
77
+ eos_token_id (`int`, *optional*, defaults to 2):
78
+ End of stream token id.
79
+ pretraining_tp (`int`, *optional*, defaults to 1):
80
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
81
+ document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
82
+ necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
83
+ issue](https://github.com/pytorch/pytorch/issues/76232).
84
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
85
+ Whether to tie weight embeddings
86
+ rope_theta (`float`, *optional*, defaults to 10000.0):
87
+ The base period of the RoPE embeddings.
88
+ rope_scaling (`Dict`, *optional*):
89
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
90
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
91
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
92
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
93
+ these scaling strategies behave:
94
+ https://www.reddit.com/r/LocalMiniCPM/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
95
+ experimental feature, subject to breaking API changes in future versions.
96
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
97
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
98
+ attention_dropout (`float`, *optional*, defaults to 0.0):
99
+ The dropout ratio for the attention probabilities.
100
+
101
+ ```python
102
+ >>> from transformers import MiniCPMModel, MiniCPMConfig
103
+
104
+ >>> # Initializing a MiniCPM minicpm-7b style configuration
105
+ >>> configuration = MiniCPMConfig()
106
+
107
+ >>> # Initializing a model from the minicpm-7b style configuration
108
+ >>> model = MiniCPMModel(configuration)
109
+
110
+ >>> # Accessing the model configuration
111
+ >>> configuration = model.config
112
+ ```"""
113
+
114
+ model_type = "minicpm"
115
+ keys_to_ignore_at_inference = ["past_key_values"]
116
+
117
+ def __init__(
118
+ self,
119
+ vocab_size=32000,
120
+ hidden_size=4096,
121
+ intermediate_size=11008,
122
+ num_hidden_layers=32,
123
+ num_attention_heads=32,
124
+ num_key_value_heads=None,
125
+ hidden_act="silu",
126
+ max_position_embeddings=2048,
127
+ initializer_range=0.02,
128
+ rms_norm_eps=1e-6,
129
+ use_cache=True,
130
+ pad_token_id=None,
131
+ bos_token_id=1,
132
+ eos_token_id=2,
133
+ pretraining_tp=1,
134
+ tie_word_embeddings=False,
135
+ rope_theta=10000.0,
136
+ rope_scaling=None,
137
+ attention_bias=False,
138
+ attention_dropout=0.0,
139
+ scale_emb=1,
140
+ dim_model_base=1,
141
+ scale_depth=1,
142
+ **kwargs,
143
+ ):
144
+ self.vocab_size = vocab_size
145
+ self.max_position_embeddings = max_position_embeddings
146
+ self.hidden_size = hidden_size
147
+ self.intermediate_size = intermediate_size
148
+ self.num_hidden_layers = num_hidden_layers
149
+ self.num_attention_heads = num_attention_heads
150
+
151
+ # for backward compatibility
152
+ if num_key_value_heads is None:
153
+ num_key_value_heads = num_attention_heads
154
+
155
+ self.num_key_value_heads = num_key_value_heads
156
+ self.hidden_act = hidden_act
157
+ self.initializer_range = initializer_range
158
+ self.rms_norm_eps = rms_norm_eps
159
+ self.pretraining_tp = pretraining_tp
160
+ self.use_cache = use_cache
161
+ self.rope_theta = rope_theta
162
+ self.rope_scaling = rope_scaling
163
+ self._rope_scaling_validation()
164
+ self.attention_bias = attention_bias
165
+ self.attention_dropout = attention_dropout
166
+ self.scale_emb = scale_emb
167
+ self.dim_model_base = dim_model_base
168
+ self.scale_depth = scale_depth
169
+
170
+ super().__init__(
171
+ pad_token_id=pad_token_id,
172
+ bos_token_id=bos_token_id,
173
+ eos_token_id=eos_token_id,
174
+ tie_word_embeddings=tie_word_embeddings,
175
+ **kwargs,
176
+ )
177
+
178
+ def _rope_scaling_validation(self):
179
+ """
180
+ Validate the `rope_scaling` configuration.
181
+ """
182
+ if self.rope_scaling is None:
183
+ return
184
+
185
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
186
+ raise ValueError(
187
+ "`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
188
+ f"got {self.rope_scaling}"
189
+ )
190
+ rope_scaling_type = self.rope_scaling.get("type", None)
191
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
192
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
193
+ raise ValueError(
194
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
195
+ )
196
+ if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
197
+ raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
198
+
199
+
200
+
201
+ class MiniCPMVConfig(MiniCPMConfig):
202
+ model_type = "minicpmv"
203
+ keys_to_ignore_at_inference = ["past_key_values"]
204
+ def __init__(
205
+ self,
206
+ vision_encoder="vit_so400m_patch14_siglip_384.webli",
207
+ query_num=64,
208
+ image_size=448,
209
+ drop_vision_last_layer=True,
210
+ **kwargs
211
+ ):
212
+ self.vision_encoder = vision_encoder
213
+ self.query_num = query_num
214
+ self.image_size=image_size
215
+ self.drop_vision_last_layer = drop_vision_last_layer
216
+ super().__init__(**kwargs)
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "transformers_version": "4.36.0"
6
+ }
model.safetensors.index.json ADDED
@@ -0,0 +1,701 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 6869931584
4
+ },
5
+ "weight_map": {
6
+ "llm.lm_head.weight": "model-00002-of-00002.safetensors",
7
+ "llm.model.embed_tokens.weight": "model-00001-of-00002.safetensors",
8
+ "llm.model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
9
+ "llm.model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
10
+ "llm.model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
11
+ "llm.model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
12
+ "llm.model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
13
+ "llm.model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
14
+ "llm.model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
15
+ "llm.model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
16
+ "llm.model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
17
+ "llm.model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
18
+ "llm.model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
19
+ "llm.model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
20
+ "llm.model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
21
+ "llm.model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
22
+ "llm.model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
23
+ "llm.model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
24
+ "llm.model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
25
+ "llm.model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
26
+ "llm.model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
27
+ "llm.model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
28
+ "llm.model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
29
+ "llm.model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
30
+ "llm.model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
31
+ "llm.model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
32
+ "llm.model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
33
+ "llm.model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
34
+ "llm.model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
35
+ "llm.model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
36
+ "llm.model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
37
+ "llm.model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
38
+ "llm.model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
39
+ "llm.model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
40
+ "llm.model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
41
+ "llm.model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
42
+ "llm.model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
43
+ "llm.model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
44
+ "llm.model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
45
+ "llm.model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
46
+ "llm.model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
47
+ "llm.model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
48
+ "llm.model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
49
+ "llm.model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
50
+ "llm.model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
51
+ "llm.model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
52
+ "llm.model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
53
+ "llm.model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
54
+ "llm.model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
55
+ "llm.model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
56
+ "llm.model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
57
+ "llm.model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
58
+ "llm.model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
59
+ "llm.model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
60
+ "llm.model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
61
+ "llm.model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
62
+ "llm.model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
63
+ "llm.model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
64
+ "llm.model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
65
+ "llm.model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
66
+ "llm.model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
67
+ "llm.model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
68
+ "llm.model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
69
+ "llm.model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
70
+ "llm.model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
71
+ "llm.model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
72
+ "llm.model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
73
+ "llm.model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
74
+ "llm.model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
75
+ "llm.model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
76
+ "llm.model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
77
+ "llm.model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
78
+ "llm.model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
79
+ "llm.model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
80
+ "llm.model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
81
+ "llm.model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
82
+ "llm.model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
83
+ "llm.model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
84
+ "llm.model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
85
+ "llm.model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
86
+ "llm.model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
87
+ "llm.model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
88
+ "llm.model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
89
+ "llm.model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
90
+ "llm.model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
91
+ "llm.model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
92
+ "llm.model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
93
+ "llm.model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
94
+ "llm.model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
95
+ "llm.model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
96
+ "llm.model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
97
+ "llm.model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
98
+ "llm.model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
99
+ "llm.model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
100
+ "llm.model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
101
+ "llm.model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
102
+ "llm.model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
103
+ "llm.model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
104
+ "llm.model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
105
+ "llm.model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
106
+ "llm.model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
107
+ "llm.model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
108
+ "llm.model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
109
+ "llm.model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
110
+ "llm.model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
111
+ "llm.model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
112
+ "llm.model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
113
+ "llm.model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
114
+ "llm.model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
115
+ "llm.model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
116
+ "llm.model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
117
+ "llm.model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
118
+ "llm.model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
119
+ "llm.model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
120
+ "llm.model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
121
+ "llm.model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
122
+ "llm.model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
123
+ "llm.model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
124
+ "llm.model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
125
+ "llm.model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
126
+ "llm.model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
127
+ "llm.model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
128
+ "llm.model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
129
+ "llm.model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
130
+ "llm.model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
131
+ "llm.model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
132
+ "llm.model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
133
+ "llm.model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
134
+ "llm.model.layers.21.input_layernorm.weight": "model-00001-of-00002.safetensors",
135
+ "llm.model.layers.21.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
136
+ "llm.model.layers.21.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
137
+ "llm.model.layers.21.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
138
+ "llm.model.layers.21.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
139
+ "llm.model.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
140
+ "llm.model.layers.21.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
141
+ "llm.model.layers.21.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
142
+ "llm.model.layers.21.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
143
+ "llm.model.layers.22.input_layernorm.weight": "model-00001-of-00002.safetensors",
144
+ "llm.model.layers.22.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
145
+ "llm.model.layers.22.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
146
+ "llm.model.layers.22.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
147
+ "llm.model.layers.22.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
148
+ "llm.model.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
149
+ "llm.model.layers.22.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
150
+ "llm.model.layers.22.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
151
+ "llm.model.layers.22.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
152
+ "llm.model.layers.23.input_layernorm.weight": "model-00001-of-00002.safetensors",
153
+ "llm.model.layers.23.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
154
+ "llm.model.layers.23.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
155
+ "llm.model.layers.23.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
156
+ "llm.model.layers.23.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
157
+ "llm.model.layers.23.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
158
+ "llm.model.layers.23.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
159
+ "llm.model.layers.23.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
160
+ "llm.model.layers.23.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
161
+ "llm.model.layers.24.input_layernorm.weight": "model-00001-of-00002.safetensors",
162
+ "llm.model.layers.24.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
163
+ "llm.model.layers.24.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
164
+ "llm.model.layers.24.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
165
+ "llm.model.layers.24.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
166
+ "llm.model.layers.24.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
167
+ "llm.model.layers.24.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
168
+ "llm.model.layers.24.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
169
+ "llm.model.layers.24.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
170
+ "llm.model.layers.25.input_layernorm.weight": "model-00001-of-00002.safetensors",
171
+ "llm.model.layers.25.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
172
+ "llm.model.layers.25.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
173
+ "llm.model.layers.25.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
174
+ "llm.model.layers.25.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
175
+ "llm.model.layers.25.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
176
+ "llm.model.layers.25.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
177
+ "llm.model.layers.25.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
178
+ "llm.model.layers.25.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
179
+ "llm.model.layers.26.input_layernorm.weight": "model-00001-of-00002.safetensors",
180
+ "llm.model.layers.26.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
181
+ "llm.model.layers.26.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
182
+ "llm.model.layers.26.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
183
+ "llm.model.layers.26.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
184
+ "llm.model.layers.26.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
185
+ "llm.model.layers.26.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
186
+ "llm.model.layers.26.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
187
+ "llm.model.layers.26.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
188
+ "llm.model.layers.27.input_layernorm.weight": "model-00001-of-00002.safetensors",
189
+ "llm.model.layers.27.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
190
+ "llm.model.layers.27.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
191
+ "llm.model.layers.27.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
192
+ "llm.model.layers.27.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
193
+ "llm.model.layers.27.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
194
+ "llm.model.layers.27.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
195
+ "llm.model.layers.27.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
196
+ "llm.model.layers.27.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
197
+ "llm.model.layers.28.input_layernorm.weight": "model-00001-of-00002.safetensors",
198
+ "llm.model.layers.28.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
199
+ "llm.model.layers.28.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
200
+ "llm.model.layers.28.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
201
+ "llm.model.layers.28.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
202
+ "llm.model.layers.28.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
203
+ "llm.model.layers.28.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
204
+ "llm.model.layers.28.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
205
+ "llm.model.layers.28.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
206
+ "llm.model.layers.29.input_layernorm.weight": "model-00001-of-00002.safetensors",
207
+ "llm.model.layers.29.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
208
+ "llm.model.layers.29.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
209
+ "llm.model.layers.29.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
210
+ "llm.model.layers.29.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
211
+ "llm.model.layers.29.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
212
+ "llm.model.layers.29.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
213
+ "llm.model.layers.29.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
214
+ "llm.model.layers.29.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
215
+ "llm.model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
216
+ "llm.model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
217
+ "llm.model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
218
+ "llm.model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
219
+ "llm.model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
220
+ "llm.model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
221
+ "llm.model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
222
+ "llm.model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
223
+ "llm.model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
224
+ "llm.model.layers.30.input_layernorm.weight": "model-00001-of-00002.safetensors",
225
+ "llm.model.layers.30.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
226
+ "llm.model.layers.30.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
227
+ "llm.model.layers.30.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
228
+ "llm.model.layers.30.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
229
+ "llm.model.layers.30.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
230
+ "llm.model.layers.30.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
231
+ "llm.model.layers.30.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
232
+ "llm.model.layers.30.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
233
+ "llm.model.layers.31.input_layernorm.weight": "model-00001-of-00002.safetensors",
234
+ "llm.model.layers.31.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
235
+ "llm.model.layers.31.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
236
+ "llm.model.layers.31.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
237
+ "llm.model.layers.31.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
238
+ "llm.model.layers.31.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
239
+ "llm.model.layers.31.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
240
+ "llm.model.layers.31.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
241
+ "llm.model.layers.31.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
242
+ "llm.model.layers.32.input_layernorm.weight": "model-00001-of-00002.safetensors",
243
+ "llm.model.layers.32.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
244
+ "llm.model.layers.32.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
245
+ "llm.model.layers.32.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
246
+ "llm.model.layers.32.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
247
+ "llm.model.layers.32.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
248
+ "llm.model.layers.32.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
249
+ "llm.model.layers.32.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
250
+ "llm.model.layers.32.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
251
+ "llm.model.layers.33.input_layernorm.weight": "model-00001-of-00002.safetensors",
252
+ "llm.model.layers.33.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
253
+ "llm.model.layers.33.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
254
+ "llm.model.layers.33.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
255
+ "llm.model.layers.33.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
256
+ "llm.model.layers.33.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
257
+ "llm.model.layers.33.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
258
+ "llm.model.layers.33.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
259
+ "llm.model.layers.33.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
260
+ "llm.model.layers.34.input_layernorm.weight": "model-00001-of-00002.safetensors",
261
+ "llm.model.layers.34.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
262
+ "llm.model.layers.34.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
263
+ "llm.model.layers.34.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
264
+ "llm.model.layers.34.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
265
+ "llm.model.layers.34.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
266
+ "llm.model.layers.34.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
267
+ "llm.model.layers.34.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
268
+ "llm.model.layers.34.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
269
+ "llm.model.layers.35.input_layernorm.weight": "model-00001-of-00002.safetensors",
270
+ "llm.model.layers.35.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
271
+ "llm.model.layers.35.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
272
+ "llm.model.layers.35.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
273
+ "llm.model.layers.35.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
274
+ "llm.model.layers.35.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
275
+ "llm.model.layers.35.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
276
+ "llm.model.layers.35.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
277
+ "llm.model.layers.35.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
278
+ "llm.model.layers.36.input_layernorm.weight": "model-00002-of-00002.safetensors",
279
+ "llm.model.layers.36.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
280
+ "llm.model.layers.36.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
281
+ "llm.model.layers.36.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
282
+ "llm.model.layers.36.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
283
+ "llm.model.layers.36.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
284
+ "llm.model.layers.36.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
285
+ "llm.model.layers.36.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
286
+ "llm.model.layers.36.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
287
+ "llm.model.layers.37.input_layernorm.weight": "model-00002-of-00002.safetensors",
288
+ "llm.model.layers.37.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
289
+ "llm.model.layers.37.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
290
+ "llm.model.layers.37.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
291
+ "llm.model.layers.37.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
292
+ "llm.model.layers.37.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
293
+ "llm.model.layers.37.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
294
+ "llm.model.layers.37.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
295
+ "llm.model.layers.37.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
296
+ "llm.model.layers.38.input_layernorm.weight": "model-00002-of-00002.safetensors",
297
+ "llm.model.layers.38.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
298
+ "llm.model.layers.38.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
299
+ "llm.model.layers.38.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
300
+ "llm.model.layers.38.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
301
+ "llm.model.layers.38.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
302
+ "llm.model.layers.38.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
303
+ "llm.model.layers.38.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
304
+ "llm.model.layers.38.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
305
+ "llm.model.layers.39.input_layernorm.weight": "model-00002-of-00002.safetensors",
306
+ "llm.model.layers.39.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
307
+ "llm.model.layers.39.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
308
+ "llm.model.layers.39.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
309
+ "llm.model.layers.39.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
310
+ "llm.model.layers.39.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
311
+ "llm.model.layers.39.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
312
+ "llm.model.layers.39.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
313
+ "llm.model.layers.39.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
314
+ "llm.model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
315
+ "llm.model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
316
+ "llm.model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
317
+ "llm.model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
318
+ "llm.model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
319
+ "llm.model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
320
+ "llm.model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
321
+ "llm.model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
322
+ "llm.model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
323
+ "llm.model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
324
+ "llm.model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
325
+ "llm.model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
326
+ "llm.model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
327
+ "llm.model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
328
+ "llm.model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
329
+ "llm.model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
330
+ "llm.model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
331
+ "llm.model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
332
+ "llm.model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
333
+ "llm.model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
334
+ "llm.model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
335
+ "llm.model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
336
+ "llm.model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
337
+ "llm.model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
338
+ "llm.model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
339
+ "llm.model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
340
+ "llm.model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
341
+ "llm.model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
342
+ "llm.model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
343
+ "llm.model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
344
+ "llm.model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
345
+ "llm.model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
346
+ "llm.model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
347
+ "llm.model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
348
+ "llm.model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
349
+ "llm.model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
350
+ "llm.model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
351
+ "llm.model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
352
+ "llm.model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
353
+ "llm.model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
354
+ "llm.model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
355
+ "llm.model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
356
+ "llm.model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
357
+ "llm.model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
358
+ "llm.model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
359
+ "llm.model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
360
+ "llm.model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
361
+ "llm.model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
362
+ "llm.model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
363
+ "llm.model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
364
+ "llm.model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
365
+ "llm.model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
366
+ "llm.model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
367
+ "llm.model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
368
+ "llm.model.norm.weight": "model-00002-of-00002.safetensors",
369
+ "resampler.attn.in_proj_bias": "model-00002-of-00002.safetensors",
370
+ "resampler.attn.in_proj_weight": "model-00002-of-00002.safetensors",
371
+ "resampler.attn.out_proj.bias": "model-00002-of-00002.safetensors",
372
+ "resampler.attn.out_proj.weight": "model-00002-of-00002.safetensors",
373
+ "resampler.kv_proj.weight": "model-00002-of-00002.safetensors",
374
+ "resampler.ln_kv.bias": "model-00002-of-00002.safetensors",
375
+ "resampler.ln_kv.weight": "model-00002-of-00002.safetensors",
376
+ "resampler.ln_post.bias": "model-00002-of-00002.safetensors",
377
+ "resampler.ln_post.weight": "model-00002-of-00002.safetensors",
378
+ "resampler.ln_q.bias": "model-00002-of-00002.safetensors",
379
+ "resampler.ln_q.weight": "model-00002-of-00002.safetensors",
380
+ "resampler.pos_embed": "model-00002-of-00002.safetensors",
381
+ "resampler.proj": "model-00002-of-00002.safetensors",
382
+ "resampler.query": "model-00002-of-00002.safetensors",
383
+ "vpm.blocks.0.attn.proj.bias": "model-00002-of-00002.safetensors",
384
+ "vpm.blocks.0.attn.proj.weight": "model-00002-of-00002.safetensors",
385
+ "vpm.blocks.0.attn.qkv.bias": "model-00002-of-00002.safetensors",
386
+ "vpm.blocks.0.attn.qkv.weight": "model-00002-of-00002.safetensors",
387
+ "vpm.blocks.0.mlp.fc1.bias": "model-00002-of-00002.safetensors",
388
+ "vpm.blocks.0.mlp.fc1.weight": "model-00002-of-00002.safetensors",
389
+ "vpm.blocks.0.mlp.fc2.bias": "model-00002-of-00002.safetensors",
390
+ "vpm.blocks.0.mlp.fc2.weight": "model-00002-of-00002.safetensors",
391
+ "vpm.blocks.0.norm1.bias": "model-00002-of-00002.safetensors",
392
+ "vpm.blocks.0.norm1.weight": "model-00002-of-00002.safetensors",
393
+ "vpm.blocks.0.norm2.bias": "model-00002-of-00002.safetensors",
394
+ "vpm.blocks.0.norm2.weight": "model-00002-of-00002.safetensors",
395
+ "vpm.blocks.1.attn.proj.bias": "model-00002-of-00002.safetensors",
396
+ "vpm.blocks.1.attn.proj.weight": "model-00002-of-00002.safetensors",
397
+ "vpm.blocks.1.attn.qkv.bias": "model-00002-of-00002.safetensors",
398
+ "vpm.blocks.1.attn.qkv.weight": "model-00002-of-00002.safetensors",
399
+ "vpm.blocks.1.mlp.fc1.bias": "model-00002-of-00002.safetensors",
400
+ "vpm.blocks.1.mlp.fc1.weight": "model-00002-of-00002.safetensors",
401
+ "vpm.blocks.1.mlp.fc2.bias": "model-00002-of-00002.safetensors",
402
+ "vpm.blocks.1.mlp.fc2.weight": "model-00002-of-00002.safetensors",
403
+ "vpm.blocks.1.norm1.bias": "model-00002-of-00002.safetensors",
404
+ "vpm.blocks.1.norm1.weight": "model-00002-of-00002.safetensors",
405
+ "vpm.blocks.1.norm2.bias": "model-00002-of-00002.safetensors",
406
+ "vpm.blocks.1.norm2.weight": "model-00002-of-00002.safetensors",
407
+ "vpm.blocks.10.attn.proj.bias": "model-00002-of-00002.safetensors",
408
+ "vpm.blocks.10.attn.proj.weight": "model-00002-of-00002.safetensors",
409
+ "vpm.blocks.10.attn.qkv.bias": "model-00002-of-00002.safetensors",
410
+ "vpm.blocks.10.attn.qkv.weight": "model-00002-of-00002.safetensors",
411
+ "vpm.blocks.10.mlp.fc1.bias": "model-00002-of-00002.safetensors",
412
+ "vpm.blocks.10.mlp.fc1.weight": "model-00002-of-00002.safetensors",
413
+ "vpm.blocks.10.mlp.fc2.bias": "model-00002-of-00002.safetensors",
414
+ "vpm.blocks.10.mlp.fc2.weight": "model-00002-of-00002.safetensors",
415
+ "vpm.blocks.10.norm1.bias": "model-00002-of-00002.safetensors",
416
+ "vpm.blocks.10.norm1.weight": "model-00002-of-00002.safetensors",
417
+ "vpm.blocks.10.norm2.bias": "model-00002-of-00002.safetensors",
418
+ "vpm.blocks.10.norm2.weight": "model-00002-of-00002.safetensors",
419
+ "vpm.blocks.11.attn.proj.bias": "model-00002-of-00002.safetensors",
420
+ "vpm.blocks.11.attn.proj.weight": "model-00002-of-00002.safetensors",
421
+ "vpm.blocks.11.attn.qkv.bias": "model-00002-of-00002.safetensors",
422
+ "vpm.blocks.11.attn.qkv.weight": "model-00002-of-00002.safetensors",
423
+ "vpm.blocks.11.mlp.fc1.bias": "model-00002-of-00002.safetensors",
424
+ "vpm.blocks.11.mlp.fc1.weight": "model-00002-of-00002.safetensors",
425
+ "vpm.blocks.11.mlp.fc2.bias": "model-00002-of-00002.safetensors",
426
+ "vpm.blocks.11.mlp.fc2.weight": "model-00002-of-00002.safetensors",
427
+ "vpm.blocks.11.norm1.bias": "model-00002-of-00002.safetensors",
428
+ "vpm.blocks.11.norm1.weight": "model-00002-of-00002.safetensors",
429
+ "vpm.blocks.11.norm2.bias": "model-00002-of-00002.safetensors",
430
+ "vpm.blocks.11.norm2.weight": "model-00002-of-00002.safetensors",
431
+ "vpm.blocks.12.attn.proj.bias": "model-00002-of-00002.safetensors",
432
+ "vpm.blocks.12.attn.proj.weight": "model-00002-of-00002.safetensors",
433
+ "vpm.blocks.12.attn.qkv.bias": "model-00002-of-00002.safetensors",
434
+ "vpm.blocks.12.attn.qkv.weight": "model-00002-of-00002.safetensors",
435
+ "vpm.blocks.12.mlp.fc1.bias": "model-00002-of-00002.safetensors",
436
+ "vpm.blocks.12.mlp.fc1.weight": "model-00002-of-00002.safetensors",
437
+ "vpm.blocks.12.mlp.fc2.bias": "model-00002-of-00002.safetensors",
438
+ "vpm.blocks.12.mlp.fc2.weight": "model-00002-of-00002.safetensors",
439
+ "vpm.blocks.12.norm1.bias": "model-00002-of-00002.safetensors",
440
+ "vpm.blocks.12.norm1.weight": "model-00002-of-00002.safetensors",
441
+ "vpm.blocks.12.norm2.bias": "model-00002-of-00002.safetensors",
442
+ "vpm.blocks.12.norm2.weight": "model-00002-of-00002.safetensors",
443
+ "vpm.blocks.13.attn.proj.bias": "model-00002-of-00002.safetensors",
444
+ "vpm.blocks.13.attn.proj.weight": "model-00002-of-00002.safetensors",
445
+ "vpm.blocks.13.attn.qkv.bias": "model-00002-of-00002.safetensors",
446
+ "vpm.blocks.13.attn.qkv.weight": "model-00002-of-00002.safetensors",
447
+ "vpm.blocks.13.mlp.fc1.bias": "model-00002-of-00002.safetensors",
448
+ "vpm.blocks.13.mlp.fc1.weight": "model-00002-of-00002.safetensors",
449
+ "vpm.blocks.13.mlp.fc2.bias": "model-00002-of-00002.safetensors",
450
+ "vpm.blocks.13.mlp.fc2.weight": "model-00002-of-00002.safetensors",
451
+ "vpm.blocks.13.norm1.bias": "model-00002-of-00002.safetensors",
452
+ "vpm.blocks.13.norm1.weight": "model-00002-of-00002.safetensors",
453
+ "vpm.blocks.13.norm2.bias": "model-00002-of-00002.safetensors",
454
+ "vpm.blocks.13.norm2.weight": "model-00002-of-00002.safetensors",
455
+ "vpm.blocks.14.attn.proj.bias": "model-00002-of-00002.safetensors",
456
+ "vpm.blocks.14.attn.proj.weight": "model-00002-of-00002.safetensors",
457
+ "vpm.blocks.14.attn.qkv.bias": "model-00002-of-00002.safetensors",
458
+ "vpm.blocks.14.attn.qkv.weight": "model-00002-of-00002.safetensors",
459
+ "vpm.blocks.14.mlp.fc1.bias": "model-00002-of-00002.safetensors",
460
+ "vpm.blocks.14.mlp.fc1.weight": "model-00002-of-00002.safetensors",
461
+ "vpm.blocks.14.mlp.fc2.bias": "model-00002-of-00002.safetensors",
462
+ "vpm.blocks.14.mlp.fc2.weight": "model-00002-of-00002.safetensors",
463
+ "vpm.blocks.14.norm1.bias": "model-00002-of-00002.safetensors",
464
+ "vpm.blocks.14.norm1.weight": "model-00002-of-00002.safetensors",
465
+ "vpm.blocks.14.norm2.bias": "model-00002-of-00002.safetensors",
466
+ "vpm.blocks.14.norm2.weight": "model-00002-of-00002.safetensors",
467
+ "vpm.blocks.15.attn.proj.bias": "model-00002-of-00002.safetensors",
468
+ "vpm.blocks.15.attn.proj.weight": "model-00002-of-00002.safetensors",
469
+ "vpm.blocks.15.attn.qkv.bias": "model-00002-of-00002.safetensors",
470
+ "vpm.blocks.15.attn.qkv.weight": "model-00002-of-00002.safetensors",
471
+ "vpm.blocks.15.mlp.fc1.bias": "model-00002-of-00002.safetensors",
472
+ "vpm.blocks.15.mlp.fc1.weight": "model-00002-of-00002.safetensors",
473
+ "vpm.blocks.15.mlp.fc2.bias": "model-00002-of-00002.safetensors",
474
+ "vpm.blocks.15.mlp.fc2.weight": "model-00002-of-00002.safetensors",
475
+ "vpm.blocks.15.norm1.bias": "model-00002-of-00002.safetensors",
476
+ "vpm.blocks.15.norm1.weight": "model-00002-of-00002.safetensors",
477
+ "vpm.blocks.15.norm2.bias": "model-00002-of-00002.safetensors",
478
+ "vpm.blocks.15.norm2.weight": "model-00002-of-00002.safetensors",
479
+ "vpm.blocks.16.attn.proj.bias": "model-00002-of-00002.safetensors",
480
+ "vpm.blocks.16.attn.proj.weight": "model-00002-of-00002.safetensors",
481
+ "vpm.blocks.16.attn.qkv.bias": "model-00002-of-00002.safetensors",
482
+ "vpm.blocks.16.attn.qkv.weight": "model-00002-of-00002.safetensors",
483
+ "vpm.blocks.16.mlp.fc1.bias": "model-00002-of-00002.safetensors",
484
+ "vpm.blocks.16.mlp.fc1.weight": "model-00002-of-00002.safetensors",
485
+ "vpm.blocks.16.mlp.fc2.bias": "model-00002-of-00002.safetensors",
486
+ "vpm.blocks.16.mlp.fc2.weight": "model-00002-of-00002.safetensors",
487
+ "vpm.blocks.16.norm1.bias": "model-00002-of-00002.safetensors",
488
+ "vpm.blocks.16.norm1.weight": "model-00002-of-00002.safetensors",
489
+ "vpm.blocks.16.norm2.bias": "model-00002-of-00002.safetensors",
490
+ "vpm.blocks.16.norm2.weight": "model-00002-of-00002.safetensors",
491
+ "vpm.blocks.17.attn.proj.bias": "model-00002-of-00002.safetensors",
492
+ "vpm.blocks.17.attn.proj.weight": "model-00002-of-00002.safetensors",
493
+ "vpm.blocks.17.attn.qkv.bias": "model-00002-of-00002.safetensors",
494
+ "vpm.blocks.17.attn.qkv.weight": "model-00002-of-00002.safetensors",
495
+ "vpm.blocks.17.mlp.fc1.bias": "model-00002-of-00002.safetensors",
496
+ "vpm.blocks.17.mlp.fc1.weight": "model-00002-of-00002.safetensors",
497
+ "vpm.blocks.17.mlp.fc2.bias": "model-00002-of-00002.safetensors",
498
+ "vpm.blocks.17.mlp.fc2.weight": "model-00002-of-00002.safetensors",
499
+ "vpm.blocks.17.norm1.bias": "model-00002-of-00002.safetensors",
500
+ "vpm.blocks.17.norm1.weight": "model-00002-of-00002.safetensors",
501
+ "vpm.blocks.17.norm2.bias": "model-00002-of-00002.safetensors",
502
+ "vpm.blocks.17.norm2.weight": "model-00002-of-00002.safetensors",
503
+ "vpm.blocks.18.attn.proj.bias": "model-00002-of-00002.safetensors",
504
+ "vpm.blocks.18.attn.proj.weight": "model-00002-of-00002.safetensors",
505
+ "vpm.blocks.18.attn.qkv.bias": "model-00002-of-00002.safetensors",
506
+ "vpm.blocks.18.attn.qkv.weight": "model-00002-of-00002.safetensors",
507
+ "vpm.blocks.18.mlp.fc1.bias": "model-00002-of-00002.safetensors",
508
+ "vpm.blocks.18.mlp.fc1.weight": "model-00002-of-00002.safetensors",
509
+ "vpm.blocks.18.mlp.fc2.bias": "model-00002-of-00002.safetensors",
510
+ "vpm.blocks.18.mlp.fc2.weight": "model-00002-of-00002.safetensors",
511
+ "vpm.blocks.18.norm1.bias": "model-00002-of-00002.safetensors",
512
+ "vpm.blocks.18.norm1.weight": "model-00002-of-00002.safetensors",
513
+ "vpm.blocks.18.norm2.bias": "model-00002-of-00002.safetensors",
514
+ "vpm.blocks.18.norm2.weight": "model-00002-of-00002.safetensors",
515
+ "vpm.blocks.19.attn.proj.bias": "model-00002-of-00002.safetensors",
516
+ "vpm.blocks.19.attn.proj.weight": "model-00002-of-00002.safetensors",
517
+ "vpm.blocks.19.attn.qkv.bias": "model-00002-of-00002.safetensors",
518
+ "vpm.blocks.19.attn.qkv.weight": "model-00002-of-00002.safetensors",
519
+ "vpm.blocks.19.mlp.fc1.bias": "model-00002-of-00002.safetensors",
520
+ "vpm.blocks.19.mlp.fc1.weight": "model-00002-of-00002.safetensors",
521
+ "vpm.blocks.19.mlp.fc2.bias": "model-00002-of-00002.safetensors",
522
+ "vpm.blocks.19.mlp.fc2.weight": "model-00002-of-00002.safetensors",
523
+ "vpm.blocks.19.norm1.bias": "model-00002-of-00002.safetensors",
524
+ "vpm.blocks.19.norm1.weight": "model-00002-of-00002.safetensors",
525
+ "vpm.blocks.19.norm2.bias": "model-00002-of-00002.safetensors",
526
+ "vpm.blocks.19.norm2.weight": "model-00002-of-00002.safetensors",
527
+ "vpm.blocks.2.attn.proj.bias": "model-00002-of-00002.safetensors",
528
+ "vpm.blocks.2.attn.proj.weight": "model-00002-of-00002.safetensors",
529
+ "vpm.blocks.2.attn.qkv.bias": "model-00002-of-00002.safetensors",
530
+ "vpm.blocks.2.attn.qkv.weight": "model-00002-of-00002.safetensors",
531
+ "vpm.blocks.2.mlp.fc1.bias": "model-00002-of-00002.safetensors",
532
+ "vpm.blocks.2.mlp.fc1.weight": "model-00002-of-00002.safetensors",
533
+ "vpm.blocks.2.mlp.fc2.bias": "model-00002-of-00002.safetensors",
534
+ "vpm.blocks.2.mlp.fc2.weight": "model-00002-of-00002.safetensors",
535
+ "vpm.blocks.2.norm1.bias": "model-00002-of-00002.safetensors",
536
+ "vpm.blocks.2.norm1.weight": "model-00002-of-00002.safetensors",
537
+ "vpm.blocks.2.norm2.bias": "model-00002-of-00002.safetensors",
538
+ "vpm.blocks.2.norm2.weight": "model-00002-of-00002.safetensors",
539
+ "vpm.blocks.20.attn.proj.bias": "model-00002-of-00002.safetensors",
540
+ "vpm.blocks.20.attn.proj.weight": "model-00002-of-00002.safetensors",
541
+ "vpm.blocks.20.attn.qkv.bias": "model-00002-of-00002.safetensors",
542
+ "vpm.blocks.20.attn.qkv.weight": "model-00002-of-00002.safetensors",
543
+ "vpm.blocks.20.mlp.fc1.bias": "model-00002-of-00002.safetensors",
544
+ "vpm.blocks.20.mlp.fc1.weight": "model-00002-of-00002.safetensors",
545
+ "vpm.blocks.20.mlp.fc2.bias": "model-00002-of-00002.safetensors",
546
+ "vpm.blocks.20.mlp.fc2.weight": "model-00002-of-00002.safetensors",
547
+ "vpm.blocks.20.norm1.bias": "model-00002-of-00002.safetensors",
548
+ "vpm.blocks.20.norm1.weight": "model-00002-of-00002.safetensors",
549
+ "vpm.blocks.20.norm2.bias": "model-00002-of-00002.safetensors",
550
+ "vpm.blocks.20.norm2.weight": "model-00002-of-00002.safetensors",
551
+ "vpm.blocks.21.attn.proj.bias": "model-00002-of-00002.safetensors",
552
+ "vpm.blocks.21.attn.proj.weight": "model-00002-of-00002.safetensors",
553
+ "vpm.blocks.21.attn.qkv.bias": "model-00002-of-00002.safetensors",
554
+ "vpm.blocks.21.attn.qkv.weight": "model-00002-of-00002.safetensors",
555
+ "vpm.blocks.21.mlp.fc1.bias": "model-00002-of-00002.safetensors",
556
+ "vpm.blocks.21.mlp.fc1.weight": "model-00002-of-00002.safetensors",
557
+ "vpm.blocks.21.mlp.fc2.bias": "model-00002-of-00002.safetensors",
558
+ "vpm.blocks.21.mlp.fc2.weight": "model-00002-of-00002.safetensors",
559
+ "vpm.blocks.21.norm1.bias": "model-00002-of-00002.safetensors",
560
+ "vpm.blocks.21.norm1.weight": "model-00002-of-00002.safetensors",
561
+ "vpm.blocks.21.norm2.bias": "model-00002-of-00002.safetensors",
562
+ "vpm.blocks.21.norm2.weight": "model-00002-of-00002.safetensors",
563
+ "vpm.blocks.22.attn.proj.bias": "model-00002-of-00002.safetensors",
564
+ "vpm.blocks.22.attn.proj.weight": "model-00002-of-00002.safetensors",
565
+ "vpm.blocks.22.attn.qkv.bias": "model-00002-of-00002.safetensors",
566
+ "vpm.blocks.22.attn.qkv.weight": "model-00002-of-00002.safetensors",
567
+ "vpm.blocks.22.mlp.fc1.bias": "model-00002-of-00002.safetensors",
568
+ "vpm.blocks.22.mlp.fc1.weight": "model-00002-of-00002.safetensors",
569
+ "vpm.blocks.22.mlp.fc2.bias": "model-00002-of-00002.safetensors",
570
+ "vpm.blocks.22.mlp.fc2.weight": "model-00002-of-00002.safetensors",
571
+ "vpm.blocks.22.norm1.bias": "model-00002-of-00002.safetensors",
572
+ "vpm.blocks.22.norm1.weight": "model-00002-of-00002.safetensors",
573
+ "vpm.blocks.22.norm2.bias": "model-00002-of-00002.safetensors",
574
+ "vpm.blocks.22.norm2.weight": "model-00002-of-00002.safetensors",
575
+ "vpm.blocks.23.attn.proj.bias": "model-00002-of-00002.safetensors",
576
+ "vpm.blocks.23.attn.proj.weight": "model-00002-of-00002.safetensors",
577
+ "vpm.blocks.23.attn.qkv.bias": "model-00002-of-00002.safetensors",
578
+ "vpm.blocks.23.attn.qkv.weight": "model-00002-of-00002.safetensors",
579
+ "vpm.blocks.23.mlp.fc1.bias": "model-00002-of-00002.safetensors",
580
+ "vpm.blocks.23.mlp.fc1.weight": "model-00002-of-00002.safetensors",
581
+ "vpm.blocks.23.mlp.fc2.bias": "model-00002-of-00002.safetensors",
582
+ "vpm.blocks.23.mlp.fc2.weight": "model-00002-of-00002.safetensors",
583
+ "vpm.blocks.23.norm1.bias": "model-00002-of-00002.safetensors",
584
+ "vpm.blocks.23.norm1.weight": "model-00002-of-00002.safetensors",
585
+ "vpm.blocks.23.norm2.bias": "model-00002-of-00002.safetensors",
586
+ "vpm.blocks.23.norm2.weight": "model-00002-of-00002.safetensors",
587
+ "vpm.blocks.24.attn.proj.bias": "model-00002-of-00002.safetensors",
588
+ "vpm.blocks.24.attn.proj.weight": "model-00002-of-00002.safetensors",
589
+ "vpm.blocks.24.attn.qkv.bias": "model-00002-of-00002.safetensors",
590
+ "vpm.blocks.24.attn.qkv.weight": "model-00002-of-00002.safetensors",
591
+ "vpm.blocks.24.mlp.fc1.bias": "model-00002-of-00002.safetensors",
592
+ "vpm.blocks.24.mlp.fc1.weight": "model-00002-of-00002.safetensors",
593
+ "vpm.blocks.24.mlp.fc2.bias": "model-00002-of-00002.safetensors",
594
+ "vpm.blocks.24.mlp.fc2.weight": "model-00002-of-00002.safetensors",
595
+ "vpm.blocks.24.norm1.bias": "model-00002-of-00002.safetensors",
596
+ "vpm.blocks.24.norm1.weight": "model-00002-of-00002.safetensors",
597
+ "vpm.blocks.24.norm2.bias": "model-00002-of-00002.safetensors",
598
+ "vpm.blocks.24.norm2.weight": "model-00002-of-00002.safetensors",
599
+ "vpm.blocks.25.attn.proj.bias": "model-00002-of-00002.safetensors",
600
+ "vpm.blocks.25.attn.proj.weight": "model-00002-of-00002.safetensors",
601
+ "vpm.blocks.25.attn.qkv.bias": "model-00002-of-00002.safetensors",
602
+ "vpm.blocks.25.attn.qkv.weight": "model-00002-of-00002.safetensors",
603
+ "vpm.blocks.25.mlp.fc1.bias": "model-00002-of-00002.safetensors",
604
+ "vpm.blocks.25.mlp.fc1.weight": "model-00002-of-00002.safetensors",
605
+ "vpm.blocks.25.mlp.fc2.bias": "model-00002-of-00002.safetensors",
606
+ "vpm.blocks.25.mlp.fc2.weight": "model-00002-of-00002.safetensors",
607
+ "vpm.blocks.25.norm1.bias": "model-00002-of-00002.safetensors",
608
+ "vpm.blocks.25.norm1.weight": "model-00002-of-00002.safetensors",
609
+ "vpm.blocks.25.norm2.bias": "model-00002-of-00002.safetensors",
610
+ "vpm.blocks.25.norm2.weight": "model-00002-of-00002.safetensors",
611
+ "vpm.blocks.3.attn.proj.bias": "model-00002-of-00002.safetensors",
612
+ "vpm.blocks.3.attn.proj.weight": "model-00002-of-00002.safetensors",
613
+ "vpm.blocks.3.attn.qkv.bias": "model-00002-of-00002.safetensors",
614
+ "vpm.blocks.3.attn.qkv.weight": "model-00002-of-00002.safetensors",
615
+ "vpm.blocks.3.mlp.fc1.bias": "model-00002-of-00002.safetensors",
616
+ "vpm.blocks.3.mlp.fc1.weight": "model-00002-of-00002.safetensors",
617
+ "vpm.blocks.3.mlp.fc2.bias": "model-00002-of-00002.safetensors",
618
+ "vpm.blocks.3.mlp.fc2.weight": "model-00002-of-00002.safetensors",
619
+ "vpm.blocks.3.norm1.bias": "model-00002-of-00002.safetensors",
620
+ "vpm.blocks.3.norm1.weight": "model-00002-of-00002.safetensors",
621
+ "vpm.blocks.3.norm2.bias": "model-00002-of-00002.safetensors",
622
+ "vpm.blocks.3.norm2.weight": "model-00002-of-00002.safetensors",
623
+ "vpm.blocks.4.attn.proj.bias": "model-00002-of-00002.safetensors",
624
+ "vpm.blocks.4.attn.proj.weight": "model-00002-of-00002.safetensors",
625
+ "vpm.blocks.4.attn.qkv.bias": "model-00002-of-00002.safetensors",
626
+ "vpm.blocks.4.attn.qkv.weight": "model-00002-of-00002.safetensors",
627
+ "vpm.blocks.4.mlp.fc1.bias": "model-00002-of-00002.safetensors",
628
+ "vpm.blocks.4.mlp.fc1.weight": "model-00002-of-00002.safetensors",
629
+ "vpm.blocks.4.mlp.fc2.bias": "model-00002-of-00002.safetensors",
630
+ "vpm.blocks.4.mlp.fc2.weight": "model-00002-of-00002.safetensors",
631
+ "vpm.blocks.4.norm1.bias": "model-00002-of-00002.safetensors",
632
+ "vpm.blocks.4.norm1.weight": "model-00002-of-00002.safetensors",
633
+ "vpm.blocks.4.norm2.bias": "model-00002-of-00002.safetensors",
634
+ "vpm.blocks.4.norm2.weight": "model-00002-of-00002.safetensors",
635
+ "vpm.blocks.5.attn.proj.bias": "model-00002-of-00002.safetensors",
636
+ "vpm.blocks.5.attn.proj.weight": "model-00002-of-00002.safetensors",
637
+ "vpm.blocks.5.attn.qkv.bias": "model-00002-of-00002.safetensors",
638
+ "vpm.blocks.5.attn.qkv.weight": "model-00002-of-00002.safetensors",
639
+ "vpm.blocks.5.mlp.fc1.bias": "model-00002-of-00002.safetensors",
640
+ "vpm.blocks.5.mlp.fc1.weight": "model-00002-of-00002.safetensors",
641
+ "vpm.blocks.5.mlp.fc2.bias": "model-00002-of-00002.safetensors",
642
+ "vpm.blocks.5.mlp.fc2.weight": "model-00002-of-00002.safetensors",
643
+ "vpm.blocks.5.norm1.bias": "model-00002-of-00002.safetensors",
644
+ "vpm.blocks.5.norm1.weight": "model-00002-of-00002.safetensors",
645
+ "vpm.blocks.5.norm2.bias": "model-00002-of-00002.safetensors",
646
+ "vpm.blocks.5.norm2.weight": "model-00002-of-00002.safetensors",
647
+ "vpm.blocks.6.attn.proj.bias": "model-00002-of-00002.safetensors",
648
+ "vpm.blocks.6.attn.proj.weight": "model-00002-of-00002.safetensors",
649
+ "vpm.blocks.6.attn.qkv.bias": "model-00002-of-00002.safetensors",
650
+ "vpm.blocks.6.attn.qkv.weight": "model-00002-of-00002.safetensors",
651
+ "vpm.blocks.6.mlp.fc1.bias": "model-00002-of-00002.safetensors",
652
+ "vpm.blocks.6.mlp.fc1.weight": "model-00002-of-00002.safetensors",
653
+ "vpm.blocks.6.mlp.fc2.bias": "model-00002-of-00002.safetensors",
654
+ "vpm.blocks.6.mlp.fc2.weight": "model-00002-of-00002.safetensors",
655
+ "vpm.blocks.6.norm1.bias": "model-00002-of-00002.safetensors",
656
+ "vpm.blocks.6.norm1.weight": "model-00002-of-00002.safetensors",
657
+ "vpm.blocks.6.norm2.bias": "model-00002-of-00002.safetensors",
658
+ "vpm.blocks.6.norm2.weight": "model-00002-of-00002.safetensors",
659
+ "vpm.blocks.7.attn.proj.bias": "model-00002-of-00002.safetensors",
660
+ "vpm.blocks.7.attn.proj.weight": "model-00002-of-00002.safetensors",
661
+ "vpm.blocks.7.attn.qkv.bias": "model-00002-of-00002.safetensors",
662
+ "vpm.blocks.7.attn.qkv.weight": "model-00002-of-00002.safetensors",
663
+ "vpm.blocks.7.mlp.fc1.bias": "model-00002-of-00002.safetensors",
664
+ "vpm.blocks.7.mlp.fc1.weight": "model-00002-of-00002.safetensors",
665
+ "vpm.blocks.7.mlp.fc2.bias": "model-00002-of-00002.safetensors",
666
+ "vpm.blocks.7.mlp.fc2.weight": "model-00002-of-00002.safetensors",
667
+ "vpm.blocks.7.norm1.bias": "model-00002-of-00002.safetensors",
668
+ "vpm.blocks.7.norm1.weight": "model-00002-of-00002.safetensors",
669
+ "vpm.blocks.7.norm2.bias": "model-00002-of-00002.safetensors",
670
+ "vpm.blocks.7.norm2.weight": "model-00002-of-00002.safetensors",
671
+ "vpm.blocks.8.attn.proj.bias": "model-00002-of-00002.safetensors",
672
+ "vpm.blocks.8.attn.proj.weight": "model-00002-of-00002.safetensors",
673
+ "vpm.blocks.8.attn.qkv.bias": "model-00002-of-00002.safetensors",
674
+ "vpm.blocks.8.attn.qkv.weight": "model-00002-of-00002.safetensors",
675
+ "vpm.blocks.8.mlp.fc1.bias": "model-00002-of-00002.safetensors",
676
+ "vpm.blocks.8.mlp.fc1.weight": "model-00002-of-00002.safetensors",
677
+ "vpm.blocks.8.mlp.fc2.bias": "model-00002-of-00002.safetensors",
678
+ "vpm.blocks.8.mlp.fc2.weight": "model-00002-of-00002.safetensors",
679
+ "vpm.blocks.8.norm1.bias": "model-00002-of-00002.safetensors",
680
+ "vpm.blocks.8.norm1.weight": "model-00002-of-00002.safetensors",
681
+ "vpm.blocks.8.norm2.bias": "model-00002-of-00002.safetensors",
682
+ "vpm.blocks.8.norm2.weight": "model-00002-of-00002.safetensors",
683
+ "vpm.blocks.9.attn.proj.bias": "model-00002-of-00002.safetensors",
684
+ "vpm.blocks.9.attn.proj.weight": "model-00002-of-00002.safetensors",
685
+ "vpm.blocks.9.attn.qkv.bias": "model-00002-of-00002.safetensors",
686
+ "vpm.blocks.9.attn.qkv.weight": "model-00002-of-00002.safetensors",
687
+ "vpm.blocks.9.mlp.fc1.bias": "model-00002-of-00002.safetensors",
688
+ "vpm.blocks.9.mlp.fc1.weight": "model-00002-of-00002.safetensors",
689
+ "vpm.blocks.9.mlp.fc2.bias": "model-00002-of-00002.safetensors",
690
+ "vpm.blocks.9.mlp.fc2.weight": "model-00002-of-00002.safetensors",
691
+ "vpm.blocks.9.norm1.bias": "model-00002-of-00002.safetensors",
692
+ "vpm.blocks.9.norm1.weight": "model-00002-of-00002.safetensors",
693
+ "vpm.blocks.9.norm2.bias": "model-00002-of-00002.safetensors",
694
+ "vpm.blocks.9.norm2.weight": "model-00002-of-00002.safetensors",
695
+ "vpm.norm.bias": "model-00002-of-00002.safetensors",
696
+ "vpm.norm.weight": "model-00002-of-00002.safetensors",
697
+ "vpm.patch_embed.proj.bias": "model-00002-of-00002.safetensors",
698
+ "vpm.patch_embed.proj.weight": "model-00002-of-00002.safetensors",
699
+ "vpm.pos_embed": "model-00002-of-00002.safetensors"
700
+ }
701
+ }
modeling_minicpm.py ADDED
@@ -0,0 +1,1426 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ """ PyTorch MiniCPM model."""
21
+ import math
22
+ import warnings
23
+ from typing import List, Optional, Tuple, Union
24
+
25
+ import torch
26
+ import torch.nn.functional as F
27
+ import torch.utils.checkpoint
28
+ from torch import nn
29
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
30
+
31
+ from transformers.activations import ACT2FN
32
+ from transformers.cache_utils import Cache, DynamicCache
33
+ from transformers.modeling_attn_mask_utils import (
34
+ AttentionMaskConverter,
35
+ _prepare_4d_attention_mask,
36
+ _prepare_4d_causal_attention_mask,
37
+ _prepare_4d_causal_attention_mask_for_sdpa,
38
+ )
39
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
40
+ from transformers.modeling_utils import PreTrainedModel
41
+ from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS, is_torch_greater_or_equal_than_1_13
42
+ from transformers.utils import (
43
+ add_start_docstrings,
44
+ add_start_docstrings_to_model_forward,
45
+ is_flash_attn_2_available,
46
+ is_flash_attn_greater_or_equal_2_10,
47
+ logging,
48
+ replace_return_docstrings,
49
+ )
50
+ from transformers.utils.import_utils import is_torch_fx_available
51
+ from .configuration_minicpm import MiniCPMConfig
52
+
53
+
54
+ if is_flash_attn_2_available():
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
+
59
+ # This makes `_prepare_4d_causal_attention_mask` a leaf function in the FX graph.
60
+ # It means that the function will not be traced through and simply appear as a node in the graph.
61
+ if is_torch_fx_available():
62
+ if not is_torch_greater_or_equal_than_1_13:
63
+ import torch.fx
64
+
65
+ _prepare_4d_causal_attention_mask = torch.fx.wrap(_prepare_4d_causal_attention_mask)
66
+
67
+
68
+ logger = logging.get_logger(__name__)
69
+
70
+ _CONFIG_FOR_DOC = "MiniCPMConfig"
71
+
72
+
73
+ def _get_unpad_data(attention_mask):
74
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
75
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
76
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
77
+ cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0))
78
+ return (
79
+ indices,
80
+ cu_seqlens,
81
+ max_seqlen_in_batch,
82
+ )
83
+
84
+
85
+ def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
86
+ warnings.warn(
87
+ "Calling `transformers.models.minicpm.modeling_minicpm._prepare_4d_attention_mask` is deprecated and will be removed in v4.37. Use `transformers.modeling_attn_mask_utils._prepare_4d_attention_mask"
88
+ )
89
+ return _prepare_4d_attention_mask(mask=mask, dtype=dtype, tgt_len=tgt_len)
90
+
91
+
92
+ def _make_causal_mask(
93
+ input_ids_shape: torch.Size, dtype: torch.dtype, device: torch.device, past_key_values_length: int = 0
94
+ ):
95
+ warnings.warn(
96
+ "Calling `transformers.models.minicpm.modeling_minicpm._make_causal_mask` is deprecated and will be removed in v4.37. Use `transformers.models.minicpm.modeling_minicpm.AttentionMaskConverter._make_causal_mask"
97
+ )
98
+ return AttentionMaskConverter._make_causal_mask(
99
+ input_ids_shape=input_ids_shape, dtype=dtype, device=device, past_key_values_length=past_key_values_length
100
+ )
101
+
102
+ # @torch.jit.script # type: ignore
103
+ def rms_layernorm(hidden: torch.Tensor, weight: torch.Tensor, eps: float):
104
+ old_dtype = hidden.dtype
105
+ variance = hidden.to(torch.float32).pow(2).mean(dim=-1, keepdim=True)
106
+ hidden = (hidden * torch.rsqrt(variance + eps)).to(old_dtype)
107
+ return hidden * weight
108
+
109
+
110
+ class MiniCPMRMSNorm(nn.Module):
111
+ def __init__(self, hidden_size, eps=1e-6):
112
+ """
113
+ MiniCPMRMSNorm is equivalent to T5LayerNorm
114
+ """
115
+ super().__init__()
116
+ self.weight = nn.Parameter(torch.ones(hidden_size))
117
+ self.variance_epsilon = eps
118
+
119
+ def forward(self, hidden_states):
120
+ return rms_layernorm(hidden_states, self.weight, self.variance_epsilon)
121
+
122
+
123
+ ALL_LAYERNORM_LAYERS.append(MiniCPMRMSNorm)
124
+
125
+
126
+ class MiniCPMRotaryEmbedding(nn.Module):
127
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device="cuda"):
128
+ super().__init__()
129
+
130
+ self.dim = dim
131
+ self.max_position_embeddings = max_position_embeddings
132
+ self.base = base
133
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
134
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
135
+
136
+ # Build here to make `torch.jit.trace` work.
137
+ self._set_cos_sin_cache(
138
+ # seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
139
+ seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.float32
140
+ )
141
+
142
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
143
+ self.max_seq_len_cached = seq_len
144
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
145
+ freqs = torch.outer(t, self.inv_freq)
146
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
147
+ emb = torch.cat((freqs, freqs), dim=-1)
148
+
149
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
150
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
151
+
152
+ def forward(self, x, seq_len=None):
153
+ # x: [bs, num_attention_heads, seq_len, head_size]
154
+ if seq_len > self.max_seq_len_cached:
155
+ self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
156
+
157
+ return (
158
+ self.cos_cached[:seq_len].to(dtype=x.dtype),
159
+ self.sin_cached[:seq_len].to(dtype=x.dtype),
160
+ )
161
+
162
+
163
+ class MiniCPMLinearScalingRotaryEmbedding(MiniCPMRotaryEmbedding):
164
+ """MiniCPMRotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
165
+
166
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
167
+ self.scaling_factor = scaling_factor
168
+ super().__init__(dim, max_position_embeddings, base, device)
169
+
170
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
171
+ self.max_seq_len_cached = seq_len
172
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
173
+ t = t / self.scaling_factor
174
+
175
+ freqs = torch.outer(t, self.inv_freq)
176
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
177
+ emb = torch.cat((freqs, freqs), dim=-1)
178
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
179
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
180
+
181
+
182
+ class MiniCPMDynamicNTKScalingRotaryEmbedding(MiniCPMRotaryEmbedding):
183
+ """MiniCPMRotaryEmbedding extended with Dynamic NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla"""
184
+
185
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
186
+ self.scaling_factor = scaling_factor
187
+ super().__init__(dim, max_position_embeddings, base, device)
188
+
189
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
190
+ self.max_seq_len_cached = seq_len
191
+
192
+ if seq_len > self.max_position_embeddings:
193
+ base = self.base * (
194
+ (self.scaling_factor * seq_len / self.max_position_embeddings) - (self.scaling_factor - 1)
195
+ ) ** (self.dim / (self.dim - 2))
196
+ inv_freq = 1.0 / (base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
197
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
198
+
199
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
200
+
201
+ freqs = torch.outer(t, self.inv_freq)
202
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
203
+ emb = torch.cat((freqs, freqs), dim=-1)
204
+
205
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
206
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
207
+
208
+
209
+ def rotate_half(x):
210
+ """Rotates half the hidden dims of the input."""
211
+ x1 = x[..., : x.shape[-1] // 2]
212
+ x2 = x[..., x.shape[-1] // 2 :]
213
+ return torch.cat((-x2, x1), dim=-1)
214
+
215
+
216
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):
217
+ """Applies Rotary Position Embedding to the query and key tensors.
218
+
219
+ Args:
220
+ q (`torch.Tensor`): The query tensor.
221
+ k (`torch.Tensor`): The key tensor.
222
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
223
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
224
+ position_ids (`torch.Tensor`):
225
+ The position indices of the tokens corresponding to the query and key tensors. For example, this can be
226
+ used to pass offsetted position ids when working with a KV-cache.
227
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
228
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
229
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
230
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
231
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
232
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
233
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
234
+ Returns:
235
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
236
+ """
237
+ # cos = cos[position_ids].unsqueeze(unsqueeze_dim)
238
+ # sin = sin[position_ids].unsqueeze(unsqueeze_dim)
239
+ # q_embed = (q * cos) + (rotate_half(q) * sin)
240
+ # k_embed = (k * cos) + (rotate_half(k) * sin)
241
+ orig_dtype = k.dtype
242
+ cos = cos[position_ids].unsqueeze(unsqueeze_dim) # [bs, 1, seq_len, dim]
243
+ sin = sin[position_ids].unsqueeze(unsqueeze_dim) # [bs, 1, seq_len, dim]
244
+ q_fp32 = q.to(dtype=torch.float32, device=q.device)
245
+ k_fp32 = k.to(dtype=torch.float32, device=k.device)
246
+ q_embed = (q_fp32 * cos) + (rotate_half(q_fp32) * sin)
247
+ k_embed = (k_fp32 * cos) + (rotate_half(k_fp32) * sin)
248
+ return q_embed.to(dtype=orig_dtype), k_embed.to(dtype=orig_dtype)
249
+
250
+ class MiniCPMMLP(nn.Module):
251
+ def __init__(self, config):
252
+ super().__init__()
253
+ self.config = config
254
+ self.hidden_size = config.hidden_size
255
+ self.intermediate_size = config.intermediate_size
256
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
257
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
258
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
259
+ self.act_fn = ACT2FN[config.hidden_act]
260
+
261
+ def forward(self, x):
262
+ if self.config.pretraining_tp > 1:
263
+ slice = self.intermediate_size // self.config.pretraining_tp
264
+ gate_proj_slices = self.gate_proj.weight.split(slice, dim=0)
265
+ up_proj_slices = self.up_proj.weight.split(slice, dim=0)
266
+ down_proj_slices = self.down_proj.weight.split(slice, dim=1)
267
+
268
+ gate_proj = torch.cat(
269
+ [F.linear(x, gate_proj_slices[i]) for i in range(self.config.pretraining_tp)], dim=-1
270
+ )
271
+ up_proj = torch.cat([F.linear(x, up_proj_slices[i]) for i in range(self.config.pretraining_tp)], dim=-1)
272
+
273
+ intermediate_states = (self.act_fn(gate_proj) * up_proj).split(slice, dim=2)
274
+ down_proj = [
275
+ F.linear(intermediate_states[i], down_proj_slices[i]) for i in range(self.config.pretraining_tp)
276
+ ]
277
+ down_proj = sum(down_proj)
278
+ else:
279
+ down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
280
+
281
+ return down_proj
282
+
283
+
284
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
285
+ """
286
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
287
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
288
+ """
289
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
290
+ if n_rep == 1:
291
+ return hidden_states
292
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
293
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
294
+
295
+
296
+
297
+ class MiniCPMAttention(nn.Module):
298
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
299
+
300
+ def __init__(self, config: MiniCPMConfig, layer_idx: Optional[int] = None):
301
+ super().__init__()
302
+ self.config = config
303
+ self.layer_idx = layer_idx
304
+ if layer_idx is None:
305
+ logger.warning_once(
306
+ f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
307
+ "to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
308
+ "when creating this class."
309
+ )
310
+
311
+ self.attention_dropout = config.attention_dropout
312
+ self.hidden_size = config.hidden_size
313
+ self.num_heads = config.num_attention_heads
314
+ self.head_dim = self.hidden_size // self.num_heads
315
+ self.num_key_value_heads = config.num_key_value_heads
316
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
317
+ self.max_position_embeddings = config.max_position_embeddings
318
+ self.rope_theta = config.rope_theta
319
+ self.is_causal = True
320
+
321
+ if (self.head_dim * self.num_heads) != self.hidden_size:
322
+ raise ValueError(
323
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
324
+ f" and `num_heads`: {self.num_heads})."
325
+ )
326
+
327
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=config.attention_bias)
328
+ self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
329
+ self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
330
+ self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=config.attention_bias)
331
+ self._init_rope()
332
+
333
+ def _init_rope(self):
334
+ if self.config.rope_scaling is None:
335
+ self.rotary_emb = MiniCPMRotaryEmbedding(
336
+ self.head_dim,
337
+ max_position_embeddings=self.max_position_embeddings,
338
+ base=self.rope_theta,
339
+ )
340
+ else:
341
+ scaling_type = self.config.rope_scaling["type"]
342
+ scaling_factor = self.config.rope_scaling["factor"]
343
+ if scaling_type == "linear":
344
+ self.rotary_emb = MiniCPMLinearScalingRotaryEmbedding(
345
+ self.head_dim,
346
+ max_position_embeddings=self.max_position_embeddings,
347
+ scaling_factor=scaling_factor,
348
+ base=self.rope_theta,
349
+ )
350
+ elif scaling_type == "dynamic":
351
+ self.rotary_emb = MiniCPMDynamicNTKScalingRotaryEmbedding(
352
+ self.head_dim,
353
+ max_position_embeddings=self.max_position_embeddings,
354
+ scaling_factor=scaling_factor,
355
+ base=self.rope_theta,
356
+ )
357
+ else:
358
+ raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
359
+
360
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
361
+ return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
362
+
363
+ def forward(
364
+ self,
365
+ hidden_states: torch.Tensor,
366
+ attention_mask: Optional[torch.Tensor] = None,
367
+ position_ids: Optional[torch.LongTensor] = None,
368
+ past_key_value: Optional[Cache] = None,
369
+ output_attentions: bool = False,
370
+ use_cache: bool = False,
371
+ **kwargs,
372
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
373
+ if "padding_mask" in kwargs:
374
+ warnings.warn(
375
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
376
+ )
377
+
378
+ bsz, q_len, _ = hidden_states.size()
379
+
380
+ if self.config.pretraining_tp > 1:
381
+ key_value_slicing = (self.num_key_value_heads * self.head_dim) // self.config.pretraining_tp
382
+ query_slices = self.q_proj.weight.split(
383
+ (self.num_heads * self.head_dim) // self.config.pretraining_tp, dim=0
384
+ )
385
+ key_slices = self.k_proj.weight.split(key_value_slicing, dim=0)
386
+ value_slices = self.v_proj.weight.split(key_value_slicing, dim=0)
387
+
388
+ query_states = [F.linear(hidden_states, query_slices[i]) for i in range(self.config.pretraining_tp)]
389
+ query_states = torch.cat(query_states, dim=-1)
390
+
391
+ key_states = [F.linear(hidden_states, key_slices[i]) for i in range(self.config.pretraining_tp)]
392
+ key_states = torch.cat(key_states, dim=-1)
393
+
394
+ value_states = [F.linear(hidden_states, value_slices[i]) for i in range(self.config.pretraining_tp)]
395
+ value_states = torch.cat(value_states, dim=-1)
396
+
397
+ else:
398
+ query_states = self.q_proj(hidden_states)
399
+ key_states = self.k_proj(hidden_states)
400
+ value_states = self.v_proj(hidden_states)
401
+
402
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
403
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
404
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
405
+
406
+ kv_seq_len = key_states.shape[-2]
407
+ if past_key_value is not None:
408
+ if self.layer_idx is None:
409
+ raise ValueError(
410
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
411
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
412
+ "with a layer index."
413
+ )
414
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
415
+ cos, sin = self.rotary_emb(value_states.to(torch.float32), seq_len=kv_seq_len)
416
+
417
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
418
+
419
+ if past_key_value is not None:
420
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
421
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
422
+
423
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
424
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
425
+
426
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
427
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
428
+ raise ValueError(
429
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
430
+ f" {attn_weights.size()}"
431
+ )
432
+
433
+ if attention_mask is not None:
434
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
435
+ raise ValueError(
436
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
437
+ )
438
+ attn_weights = attn_weights + attention_mask
439
+
440
+ # upcast attention to fp32
441
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
442
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
443
+ attn_output = torch.matmul(attn_weights, value_states)
444
+
445
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
446
+ raise ValueError(
447
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
448
+ f" {attn_output.size()}"
449
+ )
450
+
451
+ attn_output = attn_output.transpose(1, 2).contiguous()
452
+
453
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
454
+
455
+ if self.config.pretraining_tp > 1:
456
+ attn_output = attn_output.split(self.hidden_size // self.config.pretraining_tp, dim=2)
457
+ o_proj_slices = self.o_proj.weight.split(self.hidden_size // self.config.pretraining_tp, dim=1)
458
+ attn_output = sum([F.linear(attn_output[i], o_proj_slices[i]) for i in range(self.config.pretraining_tp)])
459
+ else:
460
+ attn_output = self.o_proj(attn_output)
461
+
462
+ if not output_attentions:
463
+ attn_weights = None
464
+
465
+ return attn_output, attn_weights, past_key_value
466
+
467
+
468
+ class MiniCPMFlashAttention2(MiniCPMAttention):
469
+ """
470
+ MiniCPM flash attention module. This module inherits from `MiniCPMAttention` as the weights of the module stays
471
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
472
+ flash attention and deal with padding tokens in case the input contains any of them.
473
+ """
474
+
475
+ def __init__(self, *args, **kwargs):
476
+ super().__init__(*args, **kwargs)
477
+
478
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
479
+ # 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.
480
+ # 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).
481
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
482
+
483
+ def forward(
484
+ self,
485
+ hidden_states: torch.Tensor,
486
+ attention_mask: Optional[torch.LongTensor] = None,
487
+ position_ids: Optional[torch.LongTensor] = None,
488
+ past_key_value: Optional[Cache] = None,
489
+ output_attentions: bool = False,
490
+ use_cache: bool = False,
491
+ **kwargs,
492
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
493
+ # MiniCPMFlashAttention2 attention does not support output_attentions
494
+ if "padding_mask" in kwargs:
495
+ warnings.warn(
496
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
497
+ )
498
+
499
+ # overwrite attention_mask with padding_mask
500
+ attention_mask = kwargs.pop("padding_mask")
501
+
502
+ output_attentions = False
503
+
504
+ bsz, q_len, _ = hidden_states.size()
505
+
506
+ query_states = self.q_proj(hidden_states)
507
+ key_states = self.k_proj(hidden_states)
508
+ value_states = self.v_proj(hidden_states)
509
+
510
+ # Flash attention requires the input to have the shape
511
+ # batch_size x seq_length x head_dim x hidden_dim
512
+ # therefore we just need to keep the original shape
513
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
514
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
515
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
516
+
517
+ kv_seq_len = key_states.shape[-2]
518
+ if past_key_value is not None:
519
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
520
+ cos, sin = self.rotary_emb(value_states.to(torch.float32), seq_len=kv_seq_len)
521
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
522
+
523
+ if past_key_value is not None:
524
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
525
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
526
+
527
+ # TODO: These transpose are quite inefficient but Flash Attention requires the layout [batch_size, sequence_length, num_heads, head_dim]. We would need to refactor the KV cache
528
+ # to be able to avoid many of these transpose/reshape/view.
529
+ query_states = query_states.transpose(1, 2)
530
+ key_states = key_states.transpose(1, 2)
531
+ value_states = value_states.transpose(1, 2)
532
+
533
+ dropout_rate = self.attention_dropout if self.training else 0.0
534
+
535
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
536
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
537
+ # cast them back in the correct dtype just to be sure everything works as expected.
538
+ # This might slowdown training & inference so it is recommended to not cast the LayerNorms
539
+ # in fp32. (MiniCPMRMSNorm handles it correctly)
540
+
541
+ input_dtype = query_states.dtype
542
+ if input_dtype == torch.float32:
543
+ # Handle the case where the model is quantized
544
+ if hasattr(self.config, "_pre_quantization_dtype"):
545
+ target_dtype = self.config._pre_quantization_dtype
546
+ else:
547
+ target_dtype = self.q_proj.weight.dtype
548
+
549
+ logger.warning_once(
550
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
551
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
552
+ f" {target_dtype}."
553
+ )
554
+
555
+ query_states = query_states.to(target_dtype)
556
+ key_states = key_states.to(target_dtype)
557
+ value_states = value_states.to(target_dtype)
558
+
559
+ attn_output = self._flash_attention_forward(
560
+ query_states, key_states, value_states, attention_mask, q_len, dropout=dropout_rate
561
+ )
562
+
563
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
564
+ attn_output = self.o_proj(attn_output)
565
+
566
+ if not output_attentions:
567
+ attn_weights = None
568
+
569
+ return attn_output, attn_weights, past_key_value
570
+
571
+ def _flash_attention_forward(
572
+ self, query_states, key_states, value_states, attention_mask, query_length, dropout=0.0, softmax_scale=None
573
+ ):
574
+ """
575
+ Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
576
+ first unpad the input, then computes the attention scores and pad the final attention scores.
577
+
578
+ Args:
579
+ query_states (`torch.Tensor`):
580
+ Input query states to be passed to Flash Attention API
581
+ key_states (`torch.Tensor`):
582
+ Input key states to be passed to Flash Attention API
583
+ value_states (`torch.Tensor`):
584
+ Input value states to be passed to Flash Attention API
585
+ attention_mask (`torch.Tensor`):
586
+ The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
587
+ position of padding tokens and 1 for the position of non-padding tokens.
588
+ dropout (`int`, *optional*):
589
+ Attention dropout
590
+ softmax_scale (`float`, *optional*):
591
+ The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
592
+ """
593
+ if not self._flash_attn_uses_top_left_mask:
594
+ causal = self.is_causal
595
+ else:
596
+ # TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in MiniCPMFlashAttention2 __init__.
597
+ causal = self.is_causal and query_length != 1
598
+ # Contains at least one padding token in the sequence
599
+ if attention_mask is not None:
600
+ batch_size = query_states.shape[0]
601
+ query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
602
+ query_states, key_states, value_states, attention_mask, query_length
603
+ )
604
+
605
+ cu_seqlens_q, cu_seqlens_k = cu_seq_lens
606
+ max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
607
+ attn_output_unpad = flash_attn_varlen_func(
608
+ query_states,
609
+ key_states,
610
+ value_states,
611
+ cu_seqlens_q=cu_seqlens_q,
612
+ cu_seqlens_k=cu_seqlens_k,
613
+ max_seqlen_q=max_seqlen_in_batch_q,
614
+ max_seqlen_k=max_seqlen_in_batch_k,
615
+ dropout_p=dropout,
616
+ softmax_scale=softmax_scale,
617
+ causal=causal,
618
+ )
619
+
620
+ attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
621
+ else:
622
+ attn_output = flash_attn_func(
623
+ query_states, key_states, value_states, dropout, softmax_scale=softmax_scale, causal=causal
624
+ )
625
+
626
+ return attn_output
627
+
628
+ def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
629
+ indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
630
+ batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
631
+
632
+ key_layer = index_first_axis(
633
+ key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
634
+ )
635
+ value_layer = index_first_axis(
636
+ value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
637
+ )
638
+ if query_length == kv_seq_len:
639
+ query_layer = index_first_axis(
640
+ query_layer.reshape(batch_size * kv_seq_len, self.num_heads, head_dim), indices_k
641
+ )
642
+ cu_seqlens_q = cu_seqlens_k
643
+ max_seqlen_in_batch_q = max_seqlen_in_batch_k
644
+ indices_q = indices_k
645
+ elif query_length == 1:
646
+ max_seqlen_in_batch_q = 1
647
+ cu_seqlens_q = torch.arange(
648
+ batch_size + 1, dtype=torch.int32, device=query_layer.device
649
+ ) # There is a memcpy here, that is very bad.
650
+ indices_q = cu_seqlens_q[:-1]
651
+ query_layer = query_layer.squeeze(1)
652
+ else:
653
+ # The -q_len: slice assumes left padding.
654
+ attention_mask = attention_mask[:, -query_length:]
655
+ query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
656
+
657
+ return (
658
+ query_layer,
659
+ key_layer,
660
+ value_layer,
661
+ indices_q,
662
+ (cu_seqlens_q, cu_seqlens_k),
663
+ (max_seqlen_in_batch_q, max_seqlen_in_batch_k),
664
+ )
665
+
666
+
667
+ class MiniCPMSdpaAttention(MiniCPMAttention):
668
+ """
669
+ MiniCPM attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
670
+ `MiniCPMAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
671
+ SDPA API.
672
+ """
673
+
674
+ # Adapted from MiniCPMAttention.forward
675
+ def forward(
676
+ self,
677
+ hidden_states: torch.Tensor,
678
+ attention_mask: Optional[torch.Tensor] = None,
679
+ position_ids: Optional[torch.LongTensor] = None,
680
+ past_key_value: Optional[Cache] = None,
681
+ output_attentions: bool = False,
682
+ use_cache: bool = False,
683
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
684
+ if output_attentions:
685
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
686
+ logger.warning_once(
687
+ "MiniCPMModel is using MiniCPMSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
688
+ '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.'
689
+ )
690
+ return super().forward(
691
+ hidden_states=hidden_states,
692
+ attention_mask=attention_mask,
693
+ position_ids=position_ids,
694
+ past_key_value=past_key_value,
695
+ output_attentions=output_attentions,
696
+ use_cache=use_cache,
697
+ )
698
+
699
+ bsz, q_len, _ = hidden_states.size()
700
+
701
+ query_states = self.q_proj(hidden_states)
702
+ key_states = self.k_proj(hidden_states)
703
+ value_states = self.v_proj(hidden_states)
704
+
705
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
706
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
707
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
708
+
709
+ kv_seq_len = key_states.shape[-2]
710
+ if past_key_value is not None:
711
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
712
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
713
+
714
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
715
+
716
+ if past_key_value is not None:
717
+ cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
718
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
719
+
720
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
721
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
722
+
723
+ if attention_mask is not None:
724
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
725
+ raise ValueError(
726
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
727
+ )
728
+
729
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
730
+ # Reference: https://github.com/pytorch/pytorch/issues/112577.
731
+ if query_states.device.type == "cuda" and attention_mask is not None:
732
+ query_states = query_states.contiguous()
733
+ key_states = key_states.contiguous()
734
+ value_states = value_states.contiguous()
735
+
736
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
737
+ query_states,
738
+ key_states,
739
+ value_states,
740
+ attn_mask=attention_mask,
741
+ dropout_p=self.attention_dropout if self.training else 0.0,
742
+ # 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.
743
+ is_causal=self.is_causal and attention_mask is None and q_len > 1,
744
+ )
745
+
746
+ attn_output = attn_output.transpose(1, 2).contiguous()
747
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
748
+
749
+ attn_output = self.o_proj(attn_output)
750
+
751
+ return attn_output, None, past_key_value
752
+
753
+
754
+ MINICPM_ATTENTION_CLASSES = {
755
+ "eager": MiniCPMAttention,
756
+ "flash_attention_2": MiniCPMFlashAttention2,
757
+ "sdpa": MiniCPMSdpaAttention,
758
+ }
759
+
760
+
761
+ class MiniCPMDecoderLayer(nn.Module):
762
+ def __init__(self, config: MiniCPMConfig, layer_idx: int):
763
+ super().__init__()
764
+ self.hidden_size = config.hidden_size
765
+
766
+ self.self_attn = MINICPM_ATTENTION_CLASSES[config._attn_implementation](config=config, layer_idx=layer_idx)
767
+
768
+ self.mlp = MiniCPMMLP(config)
769
+ self.input_layernorm = MiniCPMRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
770
+ self.post_attention_layernorm = MiniCPMRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
771
+
772
+ self.scale_depth = config.scale_depth
773
+ self.num_hidden_layers = config.num_hidden_layers
774
+
775
+ def forward(
776
+ self,
777
+ hidden_states: torch.Tensor,
778
+ attention_mask: Optional[torch.Tensor] = None,
779
+ position_ids: Optional[torch.LongTensor] = None,
780
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
781
+ output_attentions: Optional[bool] = False,
782
+ use_cache: Optional[bool] = False,
783
+ **kwargs,
784
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
785
+ """
786
+ Args:
787
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
788
+ attention_mask (`torch.FloatTensor`, *optional*):
789
+ attention mask of size `(batch_size, sequence_length)` if flash attention is used or `(batch_size, 1,
790
+ query_sequence_length, key_sequence_length)` if default attention is used.
791
+ output_attentions (`bool`, *optional*):
792
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
793
+ returned tensors for more detail.
794
+ use_cache (`bool`, *optional*):
795
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
796
+ (see `past_key_values`).
797
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
798
+ """
799
+ if "padding_mask" in kwargs:
800
+ warnings.warn(
801
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
802
+ )
803
+
804
+ residual = hidden_states
805
+ hidden_states = self.input_layernorm(hidden_states)
806
+ # Self Attention
807
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
808
+ hidden_states=hidden_states,
809
+ attention_mask=attention_mask,
810
+ position_ids=position_ids,
811
+ past_key_value=past_key_value,
812
+ output_attentions=output_attentions,
813
+ use_cache=use_cache,
814
+ **kwargs,
815
+ )
816
+
817
+ hidden_states = residual + hidden_states * (self.scale_depth / math.sqrt(self.num_hidden_layers))
818
+
819
+ # Fully Connected
820
+ residual = hidden_states
821
+ hidden_states = self.post_attention_layernorm(hidden_states)
822
+
823
+ hidden_states = self.mlp(hidden_states)
824
+ hidden_states = residual + hidden_states * (self.scale_depth / math.sqrt(self.num_hidden_layers))
825
+
826
+ outputs = (hidden_states,)
827
+
828
+ if output_attentions:
829
+ outputs += (self_attn_weights,)
830
+
831
+ if use_cache:
832
+ outputs += (present_key_value,)
833
+
834
+ return outputs
835
+
836
+
837
+ MINICPM_START_DOCSTRING = r"""
838
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
839
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
840
+ etc.)
841
+
842
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
843
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
844
+ and behavior.
845
+
846
+ Parameters:
847
+ config ([`MiniCPMConfig`]):
848
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
849
+ load the weights associated with the model, only the configuration. Check out the
850
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
851
+ """
852
+
853
+
854
+ @add_start_docstrings(
855
+ "The bare MiniCPM Model outputting raw hidden-states without any specific head on top.",
856
+ MINICPM_START_DOCSTRING,
857
+ )
858
+ class MiniCPMPreTrainedModel(PreTrainedModel):
859
+ config_class = MiniCPMConfig
860
+ base_model_prefix = "model"
861
+ supports_gradient_checkpointing = True
862
+ _no_split_modules = ["MiniCPMDecoderLayer"]
863
+ _skip_keys_device_placement = "past_key_values"
864
+ _supports_flash_attn_2 = True
865
+ _supports_sdpa = True
866
+ _supports_cache_class = True
867
+
868
+ def _init_weights(self, module):
869
+ std = self.config.initializer_range
870
+ if isinstance(module, nn.Linear):
871
+ module.weight.data.normal_(mean=0.0, std=std)
872
+ if module.bias is not None:
873
+ module.bias.data.zero_()
874
+ elif isinstance(module, nn.Embedding):
875
+ module.weight.data.normal_(mean=0.0, std=std)
876
+ if module.padding_idx is not None:
877
+ module.weight.data[module.padding_idx].zero_()
878
+
879
+
880
+ MINICPM_INPUTS_DOCSTRING = r"""
881
+ Args:
882
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
883
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
884
+ it.
885
+
886
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
887
+ [`PreTrainedTokenizer.__call__`] for details.
888
+
889
+ [What are input IDs?](../glossary#input-ids)
890
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
891
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
892
+
893
+ - 1 for tokens that are **not masked**,
894
+ - 0 for tokens that are **masked**.
895
+
896
+ [What are attention masks?](../glossary#attention-mask)
897
+
898
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
899
+ [`PreTrainedTokenizer.__call__`] for details.
900
+
901
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
902
+ `past_key_values`).
903
+
904
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
905
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
906
+ information on the default strategy.
907
+
908
+ - 1 indicates the head is **not masked**,
909
+ - 0 indicates the head is **masked**.
910
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
911
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
912
+ config.n_positions - 1]`.
913
+
914
+ [What are position IDs?](../glossary#position-ids)
915
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
916
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
917
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
918
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
919
+
920
+ Two formats are allowed:
921
+ - a [`~cache_utils.Cache`] instance;
922
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
923
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
924
+ cache format.
925
+
926
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
927
+ legacy cache format will be returned.
928
+
929
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
930
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
931
+ of shape `(batch_size, sequence_length)`.
932
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
933
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
934
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
935
+ model's internal embedding lookup matrix.
936
+ use_cache (`bool`, *optional*):
937
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
938
+ `past_key_values`).
939
+ output_attentions (`bool`, *optional*):
940
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
941
+ tensors for more detail.
942
+ output_hidden_states (`bool`, *optional*):
943
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
944
+ more detail.
945
+ return_dict (`bool`, *optional*):
946
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
947
+ """
948
+
949
+
950
+ @add_start_docstrings(
951
+ "The bare MiniCPM Model outputting raw hidden-states without any specific head on top.",
952
+ MINICPM_START_DOCSTRING,
953
+ )
954
+ class MiniCPMModel(MiniCPMPreTrainedModel):
955
+ """
956
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`MiniCPMDecoderLayer`]
957
+
958
+ Args:
959
+ config: MiniCPMConfig
960
+ """
961
+
962
+ def __init__(self, config: MiniCPMConfig):
963
+ super().__init__(config)
964
+ self.padding_idx = config.pad_token_id
965
+ self.vocab_size = config.vocab_size
966
+
967
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
968
+ self.layers = nn.ModuleList(
969
+ [MiniCPMDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
970
+ )
971
+ self._use_sdpa = config._attn_implementation == "sdpa"
972
+ self._use_flash_attention_2 = config._attn_implementation == "flash_attention_2"
973
+
974
+ self.norm = MiniCPMRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
975
+
976
+ self.gradient_checkpointing = False
977
+ # Initialize weights and apply final processing
978
+ self.post_init()
979
+
980
+ def get_input_embeddings(self):
981
+ return self.embed_tokens
982
+
983
+ def set_input_embeddings(self, value):
984
+ self.embed_tokens = value
985
+
986
+ @add_start_docstrings_to_model_forward(MINICPM_INPUTS_DOCSTRING)
987
+ def forward(
988
+ self,
989
+ input_ids: torch.LongTensor = None,
990
+ attention_mask: Optional[torch.Tensor] = None,
991
+ position_ids: Optional[torch.LongTensor] = None,
992
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
993
+ inputs_embeds: Optional[torch.FloatTensor] = None,
994
+ use_cache: Optional[bool] = None,
995
+ output_attentions: Optional[bool] = None,
996
+ output_hidden_states: Optional[bool] = None,
997
+ return_dict: Optional[bool] = None,
998
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
999
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1000
+ output_hidden_states = (
1001
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1002
+ )
1003
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
1004
+
1005
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1006
+
1007
+ # retrieve input_ids and inputs_embeds
1008
+ if input_ids is not None and inputs_embeds is not None:
1009
+ raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
1010
+ elif input_ids is not None:
1011
+ batch_size, seq_length = input_ids.shape[:2]
1012
+ elif inputs_embeds is not None:
1013
+ batch_size, seq_length = inputs_embeds.shape[:2]
1014
+ else:
1015
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
1016
+
1017
+ if self.gradient_checkpointing and self.training:
1018
+ if use_cache:
1019
+ logger.warning_once(
1020
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
1021
+ )
1022
+ use_cache = False
1023
+
1024
+ past_key_values_length = 0
1025
+ if use_cache:
1026
+ use_legacy_cache = not isinstance(past_key_values, Cache)
1027
+ if use_legacy_cache:
1028
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
1029
+ past_key_values_length = past_key_values.get_usable_length(seq_length)
1030
+
1031
+ if position_ids is None:
1032
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
1033
+ position_ids = torch.arange(
1034
+ past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
1035
+ )
1036
+ position_ids = position_ids.unsqueeze(0)
1037
+
1038
+ if inputs_embeds is None:
1039
+ inputs_embeds = self.embed_tokens(input_ids) * self.config.scale_emb
1040
+
1041
+ if self._use_flash_attention_2:
1042
+ # 2d mask is passed through the layers
1043
+ attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
1044
+ elif self._use_sdpa and not output_attentions:
1045
+ # output_attentions=True can not be supported when using SDPA, and we fall back on
1046
+ # the manual implementation that requires a 4D causal mask in all cases.
1047
+ attention_mask = _prepare_4d_causal_attention_mask_for_sdpa(
1048
+ attention_mask,
1049
+ (batch_size, seq_length),
1050
+ inputs_embeds,
1051
+ past_key_values_length,
1052
+ )
1053
+ else:
1054
+ # 4d mask is passed through the layers
1055
+ attention_mask = _prepare_4d_causal_attention_mask(
1056
+ attention_mask, (batch_size, seq_length), inputs_embeds, past_key_values_length
1057
+ )
1058
+
1059
+ # embed positions
1060
+ hidden_states = inputs_embeds
1061
+
1062
+ # decoder layers
1063
+ all_hidden_states = () if output_hidden_states else None
1064
+ all_self_attns = () if output_attentions else None
1065
+ next_decoder_cache = None
1066
+
1067
+ for decoder_layer in self.layers:
1068
+ if output_hidden_states:
1069
+ all_hidden_states += (hidden_states,)
1070
+
1071
+ if self.gradient_checkpointing and self.training:
1072
+ layer_outputs = self._gradient_checkpointing_func(
1073
+ decoder_layer.__call__,
1074
+ hidden_states,
1075
+ attention_mask,
1076
+ position_ids,
1077
+ past_key_values,
1078
+ output_attentions,
1079
+ use_cache,
1080
+ )
1081
+ else:
1082
+ layer_outputs = decoder_layer(
1083
+ hidden_states,
1084
+ attention_mask=attention_mask,
1085
+ position_ids=position_ids,
1086
+ past_key_value=past_key_values,
1087
+ output_attentions=output_attentions,
1088
+ use_cache=use_cache,
1089
+ )
1090
+
1091
+ hidden_states = layer_outputs[0]
1092
+
1093
+ if use_cache:
1094
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
1095
+
1096
+ if output_attentions:
1097
+ all_self_attns += (layer_outputs[1],)
1098
+
1099
+ hidden_states = self.norm(hidden_states)
1100
+
1101
+ # add hidden states from the last decoder layer
1102
+ if output_hidden_states:
1103
+ all_hidden_states += (hidden_states,)
1104
+
1105
+ next_cache = None
1106
+ if use_cache:
1107
+ next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
1108
+ if not return_dict:
1109
+ return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
1110
+ return BaseModelOutputWithPast(
1111
+ last_hidden_state=hidden_states,
1112
+ past_key_values=next_cache,
1113
+ hidden_states=all_hidden_states,
1114
+ attentions=all_self_attns,
1115
+ )
1116
+
1117
+
1118
+ class MiniCPMForCausalLM(MiniCPMPreTrainedModel):
1119
+ _tied_weights_keys = ["lm_head.weight"]
1120
+
1121
+ def __init__(self, config):
1122
+ super().__init__(config)
1123
+ self.model = MiniCPMModel(config)
1124
+ self.vocab_size = config.vocab_size
1125
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
1126
+
1127
+ # Initialize weights and apply final processing
1128
+ self.post_init()
1129
+
1130
+ def get_input_embeddings(self):
1131
+ return self.model.embed_tokens
1132
+
1133
+ def set_input_embeddings(self, value):
1134
+ self.model.embed_tokens = value
1135
+
1136
+ def get_output_embeddings(self):
1137
+ return self.lm_head
1138
+
1139
+ def set_output_embeddings(self, new_embeddings):
1140
+ self.lm_head = new_embeddings
1141
+
1142
+ def set_decoder(self, decoder):
1143
+ self.model = decoder
1144
+
1145
+ def get_decoder(self):
1146
+ return self.model
1147
+
1148
+ @add_start_docstrings_to_model_forward(MINICPM_INPUTS_DOCSTRING)
1149
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
1150
+ def forward(
1151
+ self,
1152
+ input_ids: torch.LongTensor = None,
1153
+ attention_mask: Optional[torch.Tensor] = None,
1154
+ position_ids: Optional[torch.LongTensor] = None,
1155
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1156
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1157
+ labels: Optional[torch.LongTensor] = None,
1158
+ use_cache: Optional[bool] = None,
1159
+ output_attentions: Optional[bool] = None,
1160
+ output_hidden_states: Optional[bool] = None,
1161
+ return_dict: Optional[bool] = None,
1162
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1163
+ r"""
1164
+ Args:
1165
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1166
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1167
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1168
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1169
+
1170
+ Returns:
1171
+
1172
+ Example:
1173
+
1174
+ ```python
1175
+ >>> from transformers import AutoTokenizer, MiniCPMForCausalLM
1176
+
1177
+ >>> model = MiniCPMForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
1178
+ >>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
1179
+
1180
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
1181
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1182
+
1183
+ >>> # Generate
1184
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1185
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1186
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
1187
+ ```"""
1188
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1189
+ output_hidden_states = (
1190
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1191
+ )
1192
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1193
+
1194
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1195
+ outputs = self.model(
1196
+ input_ids=input_ids,
1197
+ attention_mask=attention_mask,
1198
+ position_ids=position_ids,
1199
+ past_key_values=past_key_values,
1200
+ inputs_embeds=inputs_embeds,
1201
+ use_cache=use_cache,
1202
+ output_attentions=output_attentions,
1203
+ output_hidden_states=output_hidden_states,
1204
+ return_dict=return_dict,
1205
+ )
1206
+
1207
+ hidden_states = outputs[0]
1208
+ if self.config.pretraining_tp > 1:
1209
+ lm_head_slices = self.lm_head.weight.split(self.vocab_size // self.config.pretraining_tp, dim=0)
1210
+ logits = [F.linear(hidden_states, lm_head_slices[i]) for i in range(self.config.pretraining_tp)]
1211
+ logits = torch.cat(logits, dim=-1)
1212
+ else:
1213
+ logits = self.lm_head(hidden_states / (self.config.hidden_size / self.config.dim_model_base))
1214
+ logits = logits.float()
1215
+
1216
+ loss = None
1217
+ if labels is not None:
1218
+ # Shift so that tokens < n predict n
1219
+ shift_logits = logits[..., :-1, :].contiguous()
1220
+ shift_labels = labels[..., 1:].contiguous()
1221
+ # Flatten the tokens
1222
+ loss_fct = CrossEntropyLoss()
1223
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1224
+ shift_labels = shift_labels.view(-1)
1225
+ # Enable model parallelism
1226
+ shift_labels = shift_labels.to(shift_logits.device)
1227
+ loss = loss_fct(shift_logits, shift_labels)
1228
+
1229
+ if not return_dict:
1230
+ output = (logits,) + outputs[1:]
1231
+ return (loss,) + output if loss is not None else output
1232
+
1233
+ return CausalLMOutputWithPast(
1234
+ loss=loss,
1235
+ logits=logits,
1236
+ past_key_values=outputs.past_key_values,
1237
+ hidden_states=outputs.hidden_states,
1238
+ attentions=outputs.attentions,
1239
+ )
1240
+
1241
+ def prepare_inputs_for_generation(
1242
+ self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs
1243
+ ):
1244
+ if past_key_values is not None:
1245
+ if isinstance(past_key_values, Cache):
1246
+ cache_length = past_key_values.get_seq_length()
1247
+ past_length = past_key_values.seen_tokens
1248
+ max_cache_length = past_key_values.get_max_length()
1249
+ else:
1250
+ cache_length = past_length = past_key_values[0][0].shape[2]
1251
+ max_cache_length = None
1252
+
1253
+ # Keep only the unprocessed tokens:
1254
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
1255
+ # some of the inputs are exclusivelly passed as part of the cache (e.g. when passing input_embeds as
1256
+ # input)
1257
+ if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
1258
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
1259
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
1260
+ # input_ids based on the past_length.
1261
+ elif past_length < input_ids.shape[1]:
1262
+ input_ids = input_ids[:, past_length:]
1263
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
1264
+
1265
+ # If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
1266
+ if (
1267
+ max_cache_length is not None
1268
+ and attention_mask is not None
1269
+ and cache_length + input_ids.shape[1] > max_cache_length
1270
+ ):
1271
+ attention_mask = attention_mask[:, -max_cache_length:]
1272
+
1273
+ position_ids = kwargs.get("position_ids", None)
1274
+ if attention_mask is not None and position_ids is None:
1275
+ # create position_ids on the fly for batch generation
1276
+ position_ids = attention_mask.long().cumsum(-1) - 1
1277
+ position_ids.masked_fill_(attention_mask == 0, 1)
1278
+ if past_key_values:
1279
+ position_ids = position_ids[:, -input_ids.shape[1] :]
1280
+
1281
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1282
+ if inputs_embeds is not None and past_key_values is None:
1283
+ model_inputs = {"inputs_embeds": inputs_embeds}
1284
+ else:
1285
+ model_inputs = {"input_ids": input_ids}
1286
+
1287
+ model_inputs.update(
1288
+ {
1289
+ "position_ids": position_ids,
1290
+ "past_key_values": past_key_values,
1291
+ "use_cache": kwargs.get("use_cache"),
1292
+ "attention_mask": attention_mask,
1293
+ }
1294
+ )
1295
+ return model_inputs
1296
+
1297
+ @staticmethod
1298
+ def _reorder_cache(past_key_values, beam_idx):
1299
+ reordered_past = ()
1300
+ for layer_past in past_key_values:
1301
+ reordered_past += (
1302
+ tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
1303
+ )
1304
+ return reordered_past
1305
+
1306
+
1307
+ @add_start_docstrings(
1308
+ """
1309
+ The MiniCPM Model transformer with a sequence classification head on top (linear layer).
1310
+
1311
+ [`MiniCPMForSequenceClassification`] uses the last token in order to do the classification, as other causal models
1312
+ (e.g. GPT-2) do.
1313
+
1314
+ Since it does classification on the last token, it requires to know the position of the last token. If a
1315
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
1316
+ no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
1317
+ padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
1318
+ each row of the batch).
1319
+ """,
1320
+ MINICPM_START_DOCSTRING,
1321
+ )
1322
+ class MiniCPMForSequenceClassification(MiniCPMPreTrainedModel):
1323
+ def __init__(self, config):
1324
+ super().__init__(config)
1325
+ self.num_labels = config.num_labels
1326
+ self.model = MiniCPMModel(config)
1327
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
1328
+
1329
+ # Initialize weights and apply final processing
1330
+ self.post_init()
1331
+
1332
+ def get_input_embeddings(self):
1333
+ return self.model.embed_tokens
1334
+
1335
+ def set_input_embeddings(self, value):
1336
+ self.model.embed_tokens = value
1337
+
1338
+ @add_start_docstrings_to_model_forward(MINICPM_INPUTS_DOCSTRING)
1339
+ def forward(
1340
+ self,
1341
+ input_ids: torch.LongTensor = None,
1342
+ attention_mask: Optional[torch.Tensor] = None,
1343
+ position_ids: Optional[torch.LongTensor] = None,
1344
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1345
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1346
+ labels: Optional[torch.LongTensor] = None,
1347
+ use_cache: Optional[bool] = None,
1348
+ output_attentions: Optional[bool] = None,
1349
+ output_hidden_states: Optional[bool] = None,
1350
+ return_dict: Optional[bool] = None,
1351
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1352
+ r"""
1353
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1354
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1355
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1356
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1357
+ """
1358
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1359
+
1360
+ transformer_outputs = self.model(
1361
+ input_ids,
1362
+ attention_mask=attention_mask,
1363
+ position_ids=position_ids,
1364
+ past_key_values=past_key_values,
1365
+ inputs_embeds=inputs_embeds,
1366
+ use_cache=use_cache,
1367
+ output_attentions=output_attentions,
1368
+ output_hidden_states=output_hidden_states,
1369
+ return_dict=return_dict,
1370
+ )
1371
+ hidden_states = transformer_outputs[0]
1372
+ logits = self.score(hidden_states)
1373
+
1374
+ if input_ids is not None:
1375
+ batch_size = input_ids.shape[0]
1376
+ else:
1377
+ batch_size = inputs_embeds.shape[0]
1378
+
1379
+ if self.config.pad_token_id is None and batch_size != 1:
1380
+ raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
1381
+ if self.config.pad_token_id is None:
1382
+ sequence_lengths = -1
1383
+ else:
1384
+ if input_ids is not None:
1385
+ sequence_lengths = (torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1).to(
1386
+ logits.device
1387
+ )
1388
+ else:
1389
+ sequence_lengths = -1
1390
+
1391
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
1392
+
1393
+ loss = None
1394
+ if labels is not None:
1395
+ labels = labels.to(logits.device)
1396
+ if self.config.problem_type is None:
1397
+ if self.num_labels == 1:
1398
+ self.config.problem_type = "regression"
1399
+ elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
1400
+ self.config.problem_type = "single_label_classification"
1401
+ else:
1402
+ self.config.problem_type = "multi_label_classification"
1403
+
1404
+ if self.config.problem_type == "regression":
1405
+ loss_fct = MSELoss()
1406
+ if self.num_labels == 1:
1407
+ loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
1408
+ else:
1409
+ loss = loss_fct(pooled_logits, labels)
1410
+ elif self.config.problem_type == "single_label_classification":
1411
+ loss_fct = CrossEntropyLoss()
1412
+ loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
1413
+ elif self.config.problem_type == "multi_label_classification":
1414
+ loss_fct = BCEWithLogitsLoss()
1415
+ loss = loss_fct(pooled_logits, labels)
1416
+ if not return_dict:
1417
+ output = (pooled_logits,) + transformer_outputs[1:]
1418
+ return ((loss,) + output) if loss is not None else output
1419
+
1420
+ return SequenceClassifierOutputWithPast(
1421
+ loss=loss,
1422
+ logits=pooled_logits,
1423
+ past_key_values=transformer_outputs.past_key_values,
1424
+ hidden_states=transformer_outputs.hidden_states,
1425
+ attentions=transformer_outputs.attentions,
1426
+ )
modeling_minicpmv.py ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ from typing import List, Optional
3
+
4
+ import timm
5
+ import torch
6
+ import torchvision
7
+ from timm.data import IMAGENET_INCEPTION_MEAN, IMAGENET_INCEPTION_STD
8
+ from torchvision import transforms
9
+ from transformers import LlamaTokenizer
10
+
11
+ from .configuration_minicpm import MiniCPMVConfig
12
+ from .modeling_minicpm import MiniCPMPreTrainedModel, MiniCPMForCausalLM
13
+ from .resampler import Resampler
14
+
15
+
16
+ class MiniCPMVPreTrainedModel(MiniCPMPreTrainedModel):
17
+ config_class = MiniCPMVConfig
18
+
19
+
20
+ class MiniCPMV(MiniCPMVPreTrainedModel):
21
+ def __init__(self, config):
22
+ super().__init__(config)
23
+
24
+ self.llm = MiniCPMForCausalLM(config)
25
+ self.vpm = self.init_vision_module()
26
+ self.vision_dim = self.vpm.embed_dim
27
+ self.embed_dim = self.llm.config.hidden_size
28
+ self.resampler = self.init_resampler(self.embed_dim ,self.vision_dim)
29
+ self.transform = self.init_transform()
30
+
31
+
32
+ def init_vision_module(self):
33
+ model = timm.create_model(
34
+ self.config.vision_encoder,
35
+ pretrained=False,
36
+ num_classes=0,
37
+ dynamic_img_size=True,
38
+ dynamic_img_pad=True
39
+ )
40
+
41
+ if isinstance(model, timm.models.VisionTransformer):
42
+ if model.attn_pool is not None:
43
+ model.attn_pool = torch.nn.Identity()
44
+
45
+ if self.config.drop_vision_last_layer:
46
+ model.blocks = model.blocks[:-1]
47
+
48
+ return model
49
+
50
+ def init_resampler(self, embed_dim, vision_dim):
51
+ return Resampler(
52
+ grid_size=int(math.sqrt(self.config.query_num)),
53
+ embed_dim=embed_dim,
54
+ num_heads=embed_dim // 128,
55
+ kv_dim=vision_dim,
56
+ )
57
+
58
+ def init_transform(self):
59
+ return transforms.Compose([
60
+ transforms.Resize(
61
+ (self.config.image_size, self.config.image_size),
62
+ interpolation=torchvision.transforms.InterpolationMode.BICUBIC
63
+ ),
64
+ transforms.ToTensor(),
65
+ transforms.Normalize(mean=IMAGENET_INCEPTION_MEAN, std=IMAGENET_INCEPTION_STD)
66
+ ])
67
+
68
+
69
+
70
+ def get_vision_embedding(self, pixel_values):
71
+ res = []
72
+ dtype = self.vpm.pos_embed.data.dtype
73
+ for pixel_value in pixel_values:
74
+ vision_embedding = self.vpm.forward_features(pixel_value.unsqueeze(0).type(dtype))
75
+ if hasattr(self.vpm, 'num_prefix_tokens') and self.vpm.num_prefix_tokens > 0:
76
+ vision_embedding = vision_embedding[:, self.vpm.num_prefix_tokens:]
77
+ res.append(self.resampler(vision_embedding))
78
+ return torch.vstack(res)
79
+
80
+ def get_vllm_embedding(self, data):
81
+ if 'vision_hidden_states' not in data:
82
+ pixel_values_list = data['pixel_values']
83
+ vision_hidden_states = []
84
+ for pixel_values in pixel_values_list:
85
+ if len(pixel_values) > 0:
86
+ vision_hidden_states.append(self.get_vision_embedding(pixel_values))
87
+ elif self.training:
88
+ dtype = self.vpm.pos_embed.data.dtype
89
+ device = self.vpm.pos_embed.data.device
90
+ dummy_image = torch.zeros(
91
+ (1, 3, 224, 224),
92
+ device=device, dtype=dtype
93
+ )
94
+ vision_hidden_states.append(self.get_vision_embedding(dummy_image))
95
+ else:
96
+ vision_hidden_states.append([])
97
+
98
+ else:
99
+ vision_hidden_states = data['vision_hidden_states']
100
+
101
+ vllm_embedding = self.llm.model.embed_tokens(data['input_ids']) * self.llm.config.scale_emb
102
+ vision_hidden_states = [i.type(vllm_embedding.dtype) if isinstance(
103
+ i, torch.Tensor) else i for i in vision_hidden_states]
104
+
105
+ bs = len(data['input_ids'])
106
+ for i in range(bs):
107
+ cur_vs_hs = vision_hidden_states[i]
108
+ if len(cur_vs_hs) > 0:
109
+ cur_vllm_emb = vllm_embedding[i]
110
+ cur_image_bound = data['image_bound'][i]
111
+ if len(cur_image_bound) > 0:
112
+ image_indices = torch.stack(
113
+ [torch.arange(r[0], r[1], dtype=torch.long) for r in cur_image_bound]
114
+ ).to(vllm_embedding.device)
115
+
116
+ cur_vllm_emb.scatter_(0, image_indices.view(-1, 1).repeat(1, cur_vllm_emb.shape[-1]),
117
+ cur_vs_hs.view(-1, cur_vs_hs.shape[-1]))
118
+ elif self.training:
119
+ cur_vllm_emb += cur_vs_hs[0].mean() * 0
120
+
121
+ return vllm_embedding, vision_hidden_states
122
+
123
+ def forward(self, data, **kwargs):
124
+ vllm_embedding, vision_hidden_states = self.get_vllm_embedding(data)
125
+ position_ids = data["position_ids"]
126
+ if position_ids.dtype != torch.int64:
127
+ position_ids = position_ids.long()
128
+
129
+ return self.llm(
130
+ input_ids=None,
131
+ position_ids=position_ids,
132
+ inputs_embeds=vllm_embedding,
133
+ **kwargs
134
+ )
135
+
136
+
137
+ def _convert_to_tensors(self, tokenizer, input_str, max_inp_length: Optional[int] = None):
138
+ if tokenizer.add_bos_token:
139
+ input_ids = tokenizer.encode(input_str)
140
+ else:
141
+ input_ids = [tokenizer.bos_id] + tokenizer.encode(input_str)
142
+ if max_inp_length is not None:
143
+ input_ids = input_ids[: max_inp_length]
144
+ input_ids = torch.tensor(input_ids, dtype=torch.int32)
145
+
146
+ image_start_tokens = torch.where(input_ids == tokenizer.im_start_id)[0]
147
+ # 跳过 im_start
148
+ image_start_tokens += 1
149
+ image_end_tokens = torch.where(input_ids == tokenizer.im_end_id)[0]
150
+ valid_image_nums = max(len(image_start_tokens), len(image_end_tokens))
151
+ image_bound = torch.hstack(
152
+ [image_start_tokens[: valid_image_nums].unsqueeze(-1),
153
+ image_end_tokens[:valid_image_nums].unsqueeze(-1)]
154
+ )
155
+
156
+ model_input = {}
157
+ model_input["input_ids"] = input_ids.unsqueeze(0).cuda()
158
+ model_input["image_bound"] = image_bound
159
+
160
+ return model_input
161
+
162
+
163
+ def _process_list(self, tokenizer, data_list: List[str], max_inp_length: Optional[int] = None):
164
+ pad_keys = ['input_ids']
165
+ input_tensors = []
166
+ for data in data_list:
167
+ input_tensors.append(self._convert_to_tensors(tokenizer, data, max_inp_length))
168
+ padded = {}
169
+ for key in pad_keys:
170
+ padded[key] = pad(input_tensors, key, padding_side="left").cuda()
171
+ padded['image_bound'] = [i['image_bound'] for i in input_tensors]
172
+ return padded
173
+
174
+ def _decode(self, inputs_embeds, tokenizer, **kwargs):
175
+ output = self.llm.generate(
176
+ inputs_embeds=inputs_embeds,
177
+ pad_token_id=0,
178
+ eos_token_id=tokenizer.eos_token_id,
179
+ **kwargs
180
+ )
181
+ return self._decode_text(output, tokenizer)
182
+
183
+ def _decode_text(self, result_ids, tokenizer):
184
+ result_text = []
185
+ for result in result_ids:
186
+ result = result[result != 0]
187
+ if result[0] == tokenizer.bos_id:
188
+ result = result[1:]
189
+ if result[-1] == tokenizer.eos_id:
190
+ result = result[:-1]
191
+ result_text.append(tokenizer.decode(result).strip())
192
+ return result_text
193
+
194
+ def generate(
195
+ self,
196
+ data_list=None,
197
+ img_list=None,
198
+ tokenizer=None,
199
+ max_inp_length: Optional[int] = None,
200
+ vision_hidden_states=None,
201
+ return_vision_hidden_states=False,
202
+ **kwargs
203
+ ):
204
+
205
+ assert data_list is not None
206
+ bs = len(data_list)
207
+ if img_list == None:
208
+ img_list = [[] for i in range(bs)]
209
+ assert bs == len(img_list)
210
+
211
+ model_inputs = self._process_list(tokenizer, data_list, max_inp_length)
212
+
213
+ if vision_hidden_states is None:
214
+ pixel_values = []
215
+ for i in range(bs):
216
+ img_inps = []
217
+ for img in img_list[i]:
218
+ img_inps.append(self.transform(img))
219
+ if img_inps:
220
+ pixel_values.append(torch.stack(img_inps).cuda())
221
+ else:
222
+ pixel_values.append([])
223
+ model_inputs['pixel_values'] = pixel_values
224
+ else:
225
+ model_inputs['vision_hidden_states'] = vision_hidden_states
226
+
227
+ with torch.inference_mode():
228
+ model_inputs['inputs_embeds'], vision_hidden_states = self.get_vllm_embedding(model_inputs)
229
+
230
+ result = self._decode(model_inputs['inputs_embeds'], tokenizer, **kwargs)
231
+
232
+ if return_vision_hidden_states:
233
+ return result, vision_hidden_states
234
+
235
+ return result
236
+
237
+
238
+ def chat(self, image, question, context, tokenizer, vision_hidden_states=None, max_new_tokens=2048, sampling=False, **kwargs):
239
+ if not context:
240
+ question = tokenizer.im_start + tokenizer.unk_token * self.config.query_num + tokenizer.im_end + '\n' + question
241
+ final_input = f'<用户>{question}<AI>'
242
+ else:
243
+ final_input = f'{context}<用户>{question}<AI>'
244
+
245
+ if sampling:
246
+ generation_config = {
247
+ 'top_p': 0.8,
248
+ 'top_k': 100,
249
+ 'temperature':0.6,
250
+ 'do_sample': True
251
+ }
252
+ else:
253
+ generation_config = {
254
+ 'num_beams': 3,
255
+ 'repetition_penalty': 1.2,
256
+ }
257
+
258
+ generation_config.update((k, kwargs[k]) for k in generation_config.keys() & kwargs.keys())
259
+
260
+ with torch.inference_mode():
261
+ res, vision_hidden_states = self.generate(
262
+ data_list=[final_input],
263
+ max_inp_length=2048,
264
+ img_list=[[image]],
265
+ tokenizer=tokenizer,
266
+ max_new_tokens=max_new_tokens,
267
+ vision_hidden_states=vision_hidden_states,
268
+ return_vision_hidden_states=True,
269
+ **generation_config
270
+ )
271
+
272
+ context = final_input + res[0]
273
+
274
+ return res[0], context, generation_config
275
+
276
+
277
+ class LlamaTokenizerWrapper(LlamaTokenizer):
278
+ def __init__(self, **kwargs):
279
+ super().__init__(**kwargs)
280
+ self.im_start = "<image>"
281
+ self.im_end = "</image>"
282
+ self.ref_start = "<ref>"
283
+ self.ref_end = "</ref>"
284
+ self.box_start = "<box>"
285
+ self.box_end = "</box>"
286
+ self.quad_start = "<quad>"
287
+ self.quad_end = "</quad>"
288
+
289
+ @property
290
+ def eos_id(self):
291
+ return self.sp_model.eos_id()
292
+
293
+ @property
294
+ def bos_id(self):
295
+ return self.sp_model.bos_id()
296
+
297
+ @property
298
+ def unk_id(self):
299
+ return self.sp_model.unk_id()
300
+
301
+ @property
302
+ def im_start_id(self):
303
+ return self._convert_token_to_id(self.im_start)
304
+
305
+ @property
306
+ def im_end_id(self):
307
+ return self._convert_token_to_id(self.im_end)
308
+
309
+
310
+ def pad(orig_items, key, max_length=None, padding_value=0, padding_side="left"):
311
+ items = []
312
+ if isinstance(orig_items[0][key], list):
313
+ assert isinstance(orig_items[0][key][0], torch.Tensor)
314
+ for it in orig_items:
315
+ for tr in it[key]:
316
+ items.append({key: tr})
317
+ else:
318
+ assert isinstance(orig_items[0][key], torch.Tensor)
319
+ items = orig_items
320
+
321
+ batch_size = len(items)
322
+ shape = items[0][key].shape
323
+ dim = len(shape)
324
+ assert dim <= 3
325
+ if max_length is None:
326
+ max_length = 0
327
+ max_length = max(max_length, max(item[key].shape[-1] for item in items))
328
+ min_length = min(item[key].shape[-1] for item in items)
329
+ dtype = items[0][key].dtype
330
+
331
+ if dim == 1:
332
+ return torch.cat([item[key] for item in items], dim=0)
333
+ elif dim == 2:
334
+ if max_length == min_length:
335
+ return torch.cat([item[key] for item in items], dim=0)
336
+ tensor = torch.zeros((batch_size, max_length), dtype=dtype) + padding_value
337
+ else:
338
+ tensor = torch.zeros((batch_size, max_length, shape[-1]), dtype=dtype) + padding_value
339
+
340
+ for i, item in enumerate(items):
341
+ if dim == 2:
342
+ if padding_side == "left":
343
+ tensor[i, -len(item[key][0]):] = item[key][0].clone()
344
+ else:
345
+ tensor[i, : len(item[key][0])] = item[key][0].clone()
346
+ elif dim == 3:
347
+ if padding_side == "left":
348
+ tensor[i, -len(item[key][0]):, :] = item[key][0].clone()
349
+ else:
350
+ tensor[i, : len(item[key][0]), :] = item[key][0].clone()
351
+
352
+ return tensor
resampler.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ from collections import OrderedDict
7
+ import math
8
+ import requests
9
+ from io import BytesIO
10
+ from functools import partial
11
+ from PIL import Image
12
+ from typing import Callable, Optional, Sequence, Tuple, List, Union
13
+ import numpy as np
14
+
15
+ import torch
16
+ from torch import nn
17
+ from torch.nn import functional as F
18
+ from torch.nn.init import trunc_normal_
19
+ from torchvision import transforms
20
+ from torchvision.transforms import InterpolationMode
21
+
22
+ def get_abs_pos(abs_pos, tgt_size):
23
+ # abs_pos: L, C
24
+ # tgt_size: M
25
+ # return: M, C
26
+ src_size = int(math.sqrt(abs_pos.size(0)))
27
+ tgt_size = int(math.sqrt(tgt_size))
28
+ dtype = abs_pos.dtype
29
+
30
+ if src_size != tgt_size:
31
+ return F.interpolate(
32
+ abs_pos.float().reshape(1, src_size, src_size, -1).permute(0, 3, 1, 2),
33
+ size=(tgt_size, tgt_size),
34
+ mode="bicubic",
35
+ align_corners=False,
36
+ ).permute(0, 2, 3, 1).flatten(0, 2).to(dtype=dtype)
37
+ else:
38
+ return abs_pos
39
+
40
+
41
+ # https://github.com/facebookresearch/mae/blob/efb2a8062c206524e35e47d04501ed4f544c0ae8/util/pos_embed.py#L20
42
+ def get_2d_sincos_pos_embed(embed_dim, grid_size, cls_token=False):
43
+ """
44
+ grid_size: int of the grid height and width
45
+ return:
46
+ pos_embed: [grid_size*grid_size, embed_dim] or [1+grid_size*grid_size, embed_dim] (w/ or w/o cls_token)
47
+ """
48
+ grid_h = np.arange(grid_size, dtype=np.float32)
49
+ grid_w = np.arange(grid_size, dtype=np.float32)
50
+ grid = np.meshgrid(grid_w, grid_h) # here w goes first
51
+ grid = np.stack(grid, axis=0)
52
+
53
+ grid = grid.reshape([2, 1, grid_size, grid_size])
54
+ pos_embed = get_2d_sincos_pos_embed_from_grid(embed_dim, grid)
55
+ if cls_token:
56
+ pos_embed = np.concatenate([np.zeros([1, embed_dim]), pos_embed], axis=0)
57
+ return pos_embed
58
+
59
+
60
+ def get_2d_sincos_pos_embed_from_grid(embed_dim, grid):
61
+ assert embed_dim % 2 == 0
62
+
63
+ # use half of dimensions to encode grid_h
64
+ emb_h = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[0]) # (H*W, D/2)
65
+ emb_w = get_1d_sincos_pos_embed_from_grid(embed_dim // 2, grid[1]) # (H*W, D/2)
66
+
67
+ emb = np.concatenate([emb_h, emb_w], axis=1) # (H*W, D)
68
+ return emb
69
+
70
+
71
+ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
72
+ """
73
+ embed_dim: output dimension for each position
74
+ pos: a list of positions to be encoded: size (M,)
75
+ out: (M, D)
76
+ """
77
+ assert embed_dim % 2 == 0
78
+ omega = np.arange(embed_dim // 2, dtype=np.float32)
79
+ omega /= embed_dim / 2.
80
+ omega = 1. / 10000 ** omega # (D/2,)
81
+
82
+ pos = pos.reshape(-1) # (M,)
83
+ out = np.einsum('m,d->md', pos, omega) # (M, D/2), outer product
84
+
85
+ emb_sin = np.sin(out) # (M, D/2)
86
+ emb_cos = np.cos(out) # (M, D/2)
87
+
88
+ emb = np.concatenate([emb_sin, emb_cos], axis=1) # (M, D)
89
+ return emb
90
+
91
+
92
+ class Resampler(nn.Module):
93
+ """
94
+ A 2D perceiver-resampler network with one cross attention layers by
95
+ (grid_size**2) learnable queries and 2d sincos pos_emb
96
+ Outputs:
97
+ A tensor with the shape of (grid_size**2, embed_dim)
98
+ """
99
+
100
+ def __init__(
101
+ self,
102
+ grid_size,
103
+ embed_dim,
104
+ num_heads,
105
+ kv_dim=None,
106
+ norm_layer=partial(nn.LayerNorm, eps=1e-6)
107
+ ):
108
+ super().__init__()
109
+ self.num_queries = grid_size ** 2
110
+ self.embed_dim = embed_dim
111
+ self.num_heads = num_heads
112
+
113
+ self.pos_embed = nn.Parameter(
114
+ torch.from_numpy(get_2d_sincos_pos_embed(embed_dim, grid_size)).float()
115
+ ).requires_grad_(False)
116
+
117
+ self.query = nn.Parameter(torch.zeros(self.num_queries, embed_dim))
118
+ trunc_normal_(self.query, std=.02)
119
+
120
+ if kv_dim is not None and kv_dim != embed_dim:
121
+ self.kv_proj = nn.Linear(kv_dim, embed_dim, bias=False)
122
+ else:
123
+ self.kv_proj = nn.Identity()
124
+
125
+ self.attn = nn.MultiheadAttention(embed_dim, num_heads)
126
+ self.ln_q = norm_layer(embed_dim)
127
+ self.ln_kv = norm_layer(embed_dim)
128
+
129
+ self.ln_post = norm_layer(embed_dim)
130
+ self.proj = nn.Parameter((embed_dim ** -0.5) * torch.randn(embed_dim, embed_dim))
131
+
132
+ self.apply(self._init_weights)
133
+
134
+ def _init_weights(self, m):
135
+ if isinstance(m, nn.Linear):
136
+ trunc_normal_(m.weight, std=.02)
137
+ if isinstance(m, nn.Linear) and m.bias is not None:
138
+ nn.init.constant_(m.bias, 0)
139
+ elif isinstance(m, nn.LayerNorm):
140
+ nn.init.constant_(m.bias, 0)
141
+ nn.init.constant_(m.weight, 1.0)
142
+
143
+ def forward(self, x, attn_mask=None):
144
+
145
+ pos_embed = get_abs_pos(self.pos_embed, x.size(1))
146
+
147
+ x = self.kv_proj(x)
148
+ x = self.ln_kv(x).permute(1, 0, 2)
149
+
150
+ N = x.shape[1]
151
+ q = self.ln_q(self.query)
152
+ out = self.attn(
153
+ self._repeat(q, N) + self.pos_embed.unsqueeze(1),
154
+ x + pos_embed.unsqueeze(1),
155
+ x,
156
+ attn_mask=attn_mask)[0]
157
+ x = out.permute(1, 0, 2)
158
+
159
+ x = self.ln_post(x)
160
+ x = x @ self.proj
161
+ return x
162
+
163
+ def _repeat(self, query, N: int):
164
+ return query.unsqueeze(1).repeat(1, N, 1)
special_tokens_map.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<ref>",
4
+ "<image>",
5
+ "</quad>",
6
+ "</image>",
7
+ "<quad>",
8
+ "</ref>",
9
+ "<box>",
10
+ "</box>"
11
+ ],
12
+ "bos_token": {
13
+ "content": "<s>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false
18
+ },
19
+ "eos_token": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false
25
+ },
26
+ "unk_token": {
27
+ "content": "<unk>",
28
+ "lstrip": false,
29
+ "normalized": false,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b046f377b2f09a90623a46611bd5d23cb76ac89ca7804a372408f37aff7b96a0
3
+ size 1994817
tokenizer_config.json ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "101": {
30
+ "content": "<image>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "102": {
38
+ "content": "</image>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "103": {
46
+ "content": "<ref>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "104": {
54
+ "content": "</ref>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "105": {
62
+ "content": "<box>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "106": {
70
+ "content": "</box>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "107": {
78
+ "content": "<quad>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "108": {
86
+ "content": "</quad>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ }
93
+ },
94
+ "additional_special_tokens": [
95
+ "<ref>",
96
+ "<image>",
97
+ "</quad>",
98
+ "</image>",
99
+ "<quad>",
100
+ "</ref>",
101
+ "<box>",
102
+ "</box>"
103
+ ],
104
+ "bos_token": "<s>",
105
+ "clean_up_tokenization_spaces": false,
106
+ "eos_token": "</s>",
107
+ "legacy": true,
108
+ "model_max_length": 1000000000000000019884624838656,
109
+ "pad_token": null,
110
+ "sp_model_kwargs": {},
111
+ "spaces_between_special_tokens": false,
112
+ "tokenizer_class": "LlamaTokenizerWrapper",
113
+ "unk_token": "<unk>",
114
+ "use_default_system_prompt": false,
115
+ "auto_map": {
116
+ "AutoTokenizer": [
117
+ "modeling_minicpmv.LlamaTokenizerWrapper",
118
+ null
119
+ ]
120
+ }
121
+ }