Anony-mous commited on
Commit
1741e45
·
1 Parent(s): a1b049d

update model weight

Browse files
model_weight/added_tokens.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "<image>": 92550,
3
+ "[UNUSED_TOKEN_141]": 92544,
4
+ "[UNUSED_TOKEN_142]": 92545,
5
+ "[UNUSED_TOKEN_143]": 92546,
6
+ "[UNUSED_TOKEN_144]": 92547,
7
+ "[UNUSED_TOKEN_145]": 92548,
8
+ "[UNUSED_TOKEN_146]": 92549
9
+ }
model_weight/config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/cpfs01/shared/gmai/xtuner_lite_workspace/xtuner/work_dir/internlm2_5-llava_caption_pretrain_image-encoder+projector/20240909213053/hf-13490-of-13490/",
3
+ "architectures": [
4
+ "LlavaForConditionalGeneration"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_llava.EnhancedLlavaConfig",
8
+ "AutoModel": "modeling_llava.LlavaForConditionalGeneration"
9
+ },
10
+ "ignore_index": -100,
11
+ "image_token_index": 92550,
12
+ "model_type": "enhanced_llava",
13
+ "projector_hidden_act": "gelu",
14
+ "text_config": {
15
+ "_name_or_path": "internlm/internlm2_5-7b-chat",
16
+ "architectures": [
17
+ "InternLM2ForCausalLM"
18
+ ],
19
+ "attn_implementation": "flash_attention_2",
20
+ "auto_map": {
21
+ "AutoConfig": "configuration_internlm2.InternLM2Config",
22
+ "AutoModel": "modeling_internlm2.InternLM2ForCausalLM",
23
+ "AutoModelForCausalLM": "modeling_internlm2.InternLM2ForCausalLM"
24
+ },
25
+ "bias": false,
26
+ "intermediate_size": 14336,
27
+ "max_position_embeddings": 32768,
28
+ "model_type": "internlm2",
29
+ "num_key_value_heads": 8,
30
+ "pad_token_id": 2,
31
+ "rms_norm_eps": 1e-05,
32
+ "rope_scaling": {
33
+ "factor": 2.0,
34
+ "type": "dynamic"
35
+ },
36
+ "rope_theta": 1000000,
37
+ "torch_dtype": "bfloat16",
38
+ "use_cache": false,
39
+ "vocab_size": 92551
40
+ },
41
+ "tie_word_embeddings": false,
42
+ "torch_dtype": "bfloat16",
43
+ "transformers_version": "4.44.0",
44
+ "vision_config": {
45
+ "_name_or_path": "/cpfs01/shared/gmai/xtuner_workspace/openai/clip-vit-large-patch14-336",
46
+ "dropout": 0.0,
47
+ "hidden_size": 1024,
48
+ "image_size": 336,
49
+ "intermediate_size": 4096,
50
+ "model_type": "clip_vision_model",
51
+ "num_attention_heads": 16,
52
+ "num_hidden_layers": 24,
53
+ "patch_size": 14,
54
+ "projection_dim": 768
55
+ },
56
+ "vision_feature_layer": -2,
57
+ "vision_feature_select_strategy": "default"
58
+ }
model_weight/configuration_internlm2.py ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
2
+ #
3
+ # This code is based on transformers/src/transformers/models/llama/configuration_llama.py
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ """ InternLM2 model configuration"""
17
+
18
+ from transformers.configuration_utils import PretrainedConfig
19
+ from transformers.utils import logging
20
+
21
+ logger = logging.get_logger(__name__)
22
+
23
+ INTERNLM2_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
24
+
25
+
26
+ # Modified from transformers.model.llama.configuration_llama.LlamaConfig
27
+ class InternLM2Config(PretrainedConfig):
28
+ r"""
29
+ This is the configuration class to store the configuration of a [`InternLM2Model`]. It is used to instantiate
30
+ an InternLM2 model according to the specified arguments, defining the model architecture. Instantiating a
31
+ configuration with the defaults will yield a similar configuration to that of the InternLM2-7B.
32
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
33
+ documentation from [`PretrainedConfig`] for more information.
34
+ Args:
35
+ vocab_size (`int`, *optional*, defaults to 32000):
36
+ Vocabulary size of the InternLM2 model. Defines the number of different tokens that can be represented by the
37
+ `inputs_ids` passed when calling [`InternLM2Model`]
38
+ hidden_size (`int`, *optional*, defaults to 4096):
39
+ Dimension of the hidden representations.
40
+ intermediate_size (`int`, *optional*, defaults to 11008):
41
+ Dimension of the MLP representations.
42
+ num_hidden_layers (`int`, *optional*, defaults to 32):
43
+ Number of hidden layers in the Transformer decoder.
44
+ num_attention_heads (`int`, *optional*, defaults to 32):
45
+ Number of attention heads for each attention layer in the Transformer decoder.
46
+ num_key_value_heads (`int`, *optional*):
47
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
48
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
49
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
50
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
51
+ by meanpooling all the original heads within that group. For more details checkout [this
52
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
53
+ `num_attention_heads`.
54
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
55
+ The non-linear activation function (function or string) in the decoder.
56
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
57
+ The maximum sequence length that this model might ever be used with. InternLM2 supports up to 32768 tokens.
58
+ initializer_range (`float`, *optional*, defaults to 0.02):
59
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
60
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
61
+ The epsilon used by the rms normalization layers.
62
+ use_cache (`bool`, *optional*, defaults to `True`):
63
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
64
+ relevant if `config.is_decoder=True`.
65
+ pad_token_id (`int`, *optional*):
66
+ Padding token id.
67
+ bos_token_id (`int`, *optional*, defaults to 1):
68
+ Beginning of stream token id.
69
+ eos_token_id (`int`, *optional*, defaults to 2):
70
+ End of stream token id.
71
+ pretraining_tp (`int`, *optional*, defaults to 1):
72
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
73
+ document](https://huggingface.co/docs/transformers/main/perf_train_gpu_many#tensor-parallelism)
74
+ to understand more about it. This value is necessary to ensure exact reproducibility
75
+ of the pretraining results. Please refer to [this
76
+ issue](https://github.com/pytorch/pytorch/issues/76232).
77
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
78
+ Whether to tie weight embeddings
79
+ rope_theta (`float`, *optional*, defaults to 10000.0):
80
+ The base period of the RoPE embeddings.
81
+ rope_scaling (`Dict`, *optional*):
82
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
83
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
84
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
85
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
86
+ these scaling strategies behave:
87
+ https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
88
+ experimental feature, subject to breaking API changes in future versions.
89
+ """
90
+ _auto_class = 'AutoConfig'
91
+ model_type = 'internlm2'
92
+ keys_to_ignore_at_inference = ['past_key_values']
93
+
94
+ def __init__( # pylint: disable=W0102
95
+ self,
96
+ vocab_size=103168,
97
+ hidden_size=4096,
98
+ intermediate_size=11008,
99
+ num_hidden_layers=32,
100
+ num_attention_heads=32,
101
+ num_key_value_heads=None,
102
+ hidden_act='silu',
103
+ max_position_embeddings=2048,
104
+ initializer_range=0.02,
105
+ rms_norm_eps=1e-6,
106
+ use_cache=True,
107
+ pad_token_id=0,
108
+ bos_token_id=1,
109
+ eos_token_id=2,
110
+ pretraining_tp=1,
111
+ tie_word_embeddings=False,
112
+ bias=True,
113
+ rope_theta=10000,
114
+ rope_scaling=None,
115
+ attn_implementation=None,
116
+ **kwargs,
117
+ ):
118
+ self.vocab_size = vocab_size
119
+ self.max_position_embeddings = max_position_embeddings
120
+ self.hidden_size = hidden_size
121
+ self.intermediate_size = intermediate_size
122
+ self.num_hidden_layers = num_hidden_layers
123
+ self.num_attention_heads = num_attention_heads
124
+ self.bias = bias
125
+
126
+ if num_key_value_heads is None:
127
+ num_key_value_heads = num_attention_heads
128
+ self.num_key_value_heads = num_key_value_heads
129
+
130
+ self.hidden_act = hidden_act
131
+ self.initializer_range = initializer_range
132
+ self.rms_norm_eps = rms_norm_eps
133
+ self.pretraining_tp = pretraining_tp
134
+ self.use_cache = use_cache
135
+ self.rope_theta = rope_theta
136
+ self.rope_scaling = rope_scaling
137
+ self._rope_scaling_validation()
138
+ self.attn_implementation = attn_implementation
139
+ if self.attn_implementation is None:
140
+ self.attn_implementation = 'eager'
141
+
142
+ super().__init__(
143
+ pad_token_id=pad_token_id,
144
+ bos_token_id=bos_token_id,
145
+ eos_token_id=eos_token_id,
146
+ tie_word_embeddings=tie_word_embeddings,
147
+ **kwargs,
148
+ )
149
+
150
+ def _rope_scaling_validation(self):
151
+ """
152
+ Validate the `rope_scaling` configuration.
153
+ """
154
+ if self.rope_scaling is None:
155
+ return
156
+
157
+ if not isinstance(self.rope_scaling,
158
+ dict) or len(self.rope_scaling) != 2:
159
+ raise ValueError(
160
+ '`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, '
161
+ f'got {self.rope_scaling}')
162
+ rope_scaling_type = self.rope_scaling.get('type', None)
163
+ rope_scaling_factor = self.rope_scaling.get('factor', None)
164
+ if rope_scaling_type is None or rope_scaling_type not in [
165
+ 'linear', 'dynamic'
166
+ ]:
167
+ raise ValueError(
168
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
169
+ )
170
+ if (rope_scaling_factor is None
171
+ or not isinstance(rope_scaling_factor,
172
+ (float, int)) or rope_scaling_factor < 1.0):
173
+ raise ValueError(
174
+ f"`rope_scaling`'s factor field must be a number >= 1, got {rope_scaling_factor} "
175
+ f'of type {type(rope_scaling_factor)}')
model_weight/configuration_llava.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2023 Microsoft Research & University of Wisconsin-Madison and the HuggingFace Inc. team. All rights reserved.
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Llava model configuration"""
15
+ import os
16
+ from typing import Union
17
+ from transformers.configuration_utils import PretrainedConfig, custom_object_save
18
+ from transformers.utils import logging
19
+ from transformers import CONFIG_MAPPING, AutoModelForCausalLM, AutoConfig
20
+
21
+ logger = logging.get_logger(__name__)
22
+
23
+ class EnhancedLlavaConfig(PretrainedConfig):
24
+ r"""
25
+ This is the configuration class to store the configuration of a [`LlavaForConditionalGeneration`]. It is used to instantiate an
26
+ Llava model according to the specified arguments, defining the model architecture. Instantiating a configuration
27
+ with the defaults will yield a similar configuration to that of the Llava-9B.
28
+
29
+ e.g. [llava-hf/llava-9b](https://huggingface.co/llava-hf/llava-9b)
30
+
31
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
32
+ documentation from [`PretrainedConfig`] for more information.
33
+
34
+ Args:
35
+ vision_config (`Union[AutoConfig, dict]`, *optional*, defaults to `CLIPVisionConfig`):
36
+ The config object or dictionary of the vision backbone.
37
+ text_config (`Union[AutoConfig, dict]`, *optional*, defaults to `LlamaConfig`):
38
+ The config object or dictionary of the text backbone.
39
+ ignore_index (`int`, *optional*, defaults to -100):
40
+ The ignore index for the loss function.
41
+ image_token_index (`int`, *optional*, defaults to 32000):
42
+ The image token index to encode the image prompt.
43
+ projector_hidden_act (`str`, *optional*, defaults to `"gelu"`):
44
+ The activation function used by the multimodal projector.
45
+ vision_feature_select_strategy (`str`, *optional*, defaults to `"default"`):
46
+ The feature selection strategy used to select the vision feature from the vision backbone.
47
+ Can be one of `"default"` or `"full"`.
48
+ vision_feature_layer (`int`, *optional*, defaults to -2):
49
+ The index of the layer to select the vision feature.
50
+
51
+ Example:
52
+
53
+ ```python
54
+ >>> from transformers import LlavaForConditionalGeneration, LlavaConfig, CLIPVisionConfig, LlamaConfig
55
+
56
+ >>> # Initializing a CLIP-vision config
57
+ >>> vision_config = CLIPVisionConfig()
58
+
59
+ >>> # Initializing a Llama config
60
+ >>> text_config = LlamaConfig()
61
+
62
+ >>> # Initializing a Llava llava-1.5-7b style configuration
63
+ >>> configuration = LlavaConfig(vision_config, text_config)
64
+
65
+ >>> # Initializing a model from the llava-1.5-7b style configuration
66
+ >>> model = LlavaForConditionalGeneration(configuration)
67
+
68
+ >>> # Accessing the model configuration
69
+ >>> configuration = model.config
70
+ ```"""
71
+
72
+ _auto_class = 'AutoConfig'
73
+ model_type = "enhanced_llava"
74
+ is_composition = False
75
+
76
+ def __init__(
77
+ self,
78
+ vision_config=None,
79
+ text_config=None,
80
+ ignore_index=-100,
81
+ image_token_index=32000,
82
+ projector_hidden_act="gelu",
83
+ vision_feature_select_strategy="default",
84
+ vision_feature_layer=-2,
85
+ **kwargs,
86
+ ):
87
+ self.ignore_index = ignore_index
88
+ self.image_token_index = image_token_index
89
+ self.projector_hidden_act = projector_hidden_act
90
+
91
+ if vision_feature_select_strategy not in ["default", "full"]:
92
+ raise ValueError(
93
+ "vision_feature_select_strategy should be one of 'default', 'full'."
94
+ f"Got: {vision_feature_select_strategy}"
95
+ )
96
+
97
+ self.vision_feature_select_strategy = vision_feature_select_strategy
98
+ self.vision_feature_layer = vision_feature_layer
99
+
100
+ if isinstance(vision_config, dict):
101
+ vision_config["model_type"] = (
102
+ vision_config["model_type"] if "model_type" in vision_config else "clip_vision_model"
103
+ )
104
+ vision_config = CONFIG_MAPPING[vision_config["model_type"]](**vision_config)
105
+ elif vision_config is None:
106
+ vision_config = CONFIG_MAPPING["clip_vision_model"](
107
+ intermediate_size=4096,
108
+ hidden_size=1024,
109
+ patch_size=14,
110
+ image_size=336,
111
+ num_hidden_layers=24,
112
+ num_attention_heads=16,
113
+ vocab_size=32000,
114
+ projection_dim=768,
115
+ )
116
+
117
+ self.vision_config = vision_config
118
+
119
+ if isinstance(text_config, dict):
120
+ text_config["model_type"] = text_config["model_type"] if "model_type" in text_config else "llama"
121
+
122
+ if text_config["model_type"] == 'internlm2':
123
+ from .configuration_internlm2 import InternLM2Config
124
+ from .modeling_internlm2 import InternLM2ForCausalLM
125
+ AutoConfig.register('internlm2', InternLM2Config)
126
+ AutoModelForCausalLM.register(
127
+ InternLM2Config, InternLM2ForCausalLM)
128
+ if 'auto_map' not in text_config:
129
+ text_config['auto_map'] = {}
130
+ text_config['auto_map']['AutoConfig'] = 'configuration_internlm2.InternLM2Config'
131
+ text_config['auto_map']['AutoModel'] = 'modeling_internlm2.InternLM2ForCausalLM'
132
+ text_config['auto_map']['AutoModelForCausalLM'] = 'modeling_internlm2.InternLM2ForCausalLM'
133
+ text_config = InternLM2Config(**text_config)
134
+ else:
135
+ text_config = CONFIG_MAPPING[text_config["model_type"]](**text_config)
136
+
137
+ elif text_config is None:
138
+ text_config = CONFIG_MAPPING["llama"]()
139
+
140
+ self.text_config = text_config
141
+
142
+ super().__init__(**kwargs)
143
+
144
+
145
+ def save_pretrained(self, save_directory: Union[str, os.PathLike], push_to_hub: bool = False, **kwargs):
146
+ """
147
+ Save a configuration object to the directory `save_directory`, so that it can be re-loaded using the
148
+ [`~PretrainedConfig.from_pretrained`] class method.
149
+
150
+ Args:
151
+ save_directory (`str` or `os.PathLike`):
152
+ Directory where the configuration JSON file will be saved (will be created if it does not exist).
153
+ push_to_hub (`bool`, *optional*, defaults to `False`):
154
+ Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the
155
+ repository you want to push to with `repo_id` (will default to the name of `save_directory` in your
156
+ namespace).
157
+ kwargs (`Dict[str, Any]`, *optional*):
158
+ Additional key word arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.
159
+ """
160
+ super().save_pretrained(save_directory, push_to_hub, **kwargs)
161
+
162
+ if self.text_config._auto_class is not None:
163
+ custom_object_save(self.text_config, save_directory, config=self.text_config)
164
+
165
+ AutoConfig.register('enhanced_llava', EnhancedLlavaConfig, exist_ok=True)
model_weight/generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "pad_token_id": 2,
6
+ "transformers_version": "4.44.0"
7
+ }
model_weight/model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b0d083bda1abc9721dc0b6374cb348cd11c8d9b964837272cc0256b275a2f6b0
3
+ size 4980892168
model_weight/model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc5ea1a242e519c0fb5873e9bbc8a5dbee9afcea4fdcada468be8c057e77d563
3
+ size 4915914584
model_weight/model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:52d683b2d10fc35f0d3109594cb10f7de337e804b344613ffe351e2b142dcfea
3
+ size 4915914592
model_weight/model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:817db982875d781ae29db0d8754083c3bd228f22bc6f130798d56f145d304181
3
+ size 1311868384
model_weight/model.safetensors.index.json ADDED
@@ -0,0 +1,629 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 16124506112
4
+ },
5
+ "weight_map": {
6
+ "language_model.model.layers.0.attention.wo.weight": "model-00001-of-00004.safetensors",
7
+ "language_model.model.layers.0.attention.wqkv.weight": "model-00001-of-00004.safetensors",
8
+ "language_model.model.layers.0.attention_norm.weight": "model-00001-of-00004.safetensors",
9
+ "language_model.model.layers.0.feed_forward.w1.weight": "model-00001-of-00004.safetensors",
10
+ "language_model.model.layers.0.feed_forward.w2.weight": "model-00001-of-00004.safetensors",
11
+ "language_model.model.layers.0.feed_forward.w3.weight": "model-00001-of-00004.safetensors",
12
+ "language_model.model.layers.0.ffn_norm.weight": "model-00001-of-00004.safetensors",
13
+ "language_model.model.layers.1.attention.wo.weight": "model-00001-of-00004.safetensors",
14
+ "language_model.model.layers.1.attention.wqkv.weight": "model-00001-of-00004.safetensors",
15
+ "language_model.model.layers.1.attention_norm.weight": "model-00001-of-00004.safetensors",
16
+ "language_model.model.layers.1.feed_forward.w1.weight": "model-00001-of-00004.safetensors",
17
+ "language_model.model.layers.1.feed_forward.w2.weight": "model-00001-of-00004.safetensors",
18
+ "language_model.model.layers.1.feed_forward.w3.weight": "model-00001-of-00004.safetensors",
19
+ "language_model.model.layers.1.ffn_norm.weight": "model-00001-of-00004.safetensors",
20
+ "language_model.model.layers.10.attention.wo.weight": "model-00002-of-00004.safetensors",
21
+ "language_model.model.layers.10.attention.wqkv.weight": "model-00002-of-00004.safetensors",
22
+ "language_model.model.layers.10.attention_norm.weight": "model-00002-of-00004.safetensors",
23
+ "language_model.model.layers.10.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
24
+ "language_model.model.layers.10.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
25
+ "language_model.model.layers.10.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
26
+ "language_model.model.layers.10.ffn_norm.weight": "model-00002-of-00004.safetensors",
27
+ "language_model.model.layers.11.attention.wo.weight": "model-00002-of-00004.safetensors",
28
+ "language_model.model.layers.11.attention.wqkv.weight": "model-00002-of-00004.safetensors",
29
+ "language_model.model.layers.11.attention_norm.weight": "model-00002-of-00004.safetensors",
30
+ "language_model.model.layers.11.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
31
+ "language_model.model.layers.11.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
32
+ "language_model.model.layers.11.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
33
+ "language_model.model.layers.11.ffn_norm.weight": "model-00002-of-00004.safetensors",
34
+ "language_model.model.layers.12.attention.wo.weight": "model-00002-of-00004.safetensors",
35
+ "language_model.model.layers.12.attention.wqkv.weight": "model-00002-of-00004.safetensors",
36
+ "language_model.model.layers.12.attention_norm.weight": "model-00002-of-00004.safetensors",
37
+ "language_model.model.layers.12.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
38
+ "language_model.model.layers.12.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
39
+ "language_model.model.layers.12.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
40
+ "language_model.model.layers.12.ffn_norm.weight": "model-00002-of-00004.safetensors",
41
+ "language_model.model.layers.13.attention.wo.weight": "model-00002-of-00004.safetensors",
42
+ "language_model.model.layers.13.attention.wqkv.weight": "model-00002-of-00004.safetensors",
43
+ "language_model.model.layers.13.attention_norm.weight": "model-00002-of-00004.safetensors",
44
+ "language_model.model.layers.13.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
45
+ "language_model.model.layers.13.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
46
+ "language_model.model.layers.13.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
47
+ "language_model.model.layers.13.ffn_norm.weight": "model-00002-of-00004.safetensors",
48
+ "language_model.model.layers.14.attention.wo.weight": "model-00002-of-00004.safetensors",
49
+ "language_model.model.layers.14.attention.wqkv.weight": "model-00002-of-00004.safetensors",
50
+ "language_model.model.layers.14.attention_norm.weight": "model-00002-of-00004.safetensors",
51
+ "language_model.model.layers.14.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
52
+ "language_model.model.layers.14.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
53
+ "language_model.model.layers.14.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
54
+ "language_model.model.layers.14.ffn_norm.weight": "model-00002-of-00004.safetensors",
55
+ "language_model.model.layers.15.attention.wo.weight": "model-00002-of-00004.safetensors",
56
+ "language_model.model.layers.15.attention.wqkv.weight": "model-00002-of-00004.safetensors",
57
+ "language_model.model.layers.15.attention_norm.weight": "model-00002-of-00004.safetensors",
58
+ "language_model.model.layers.15.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
59
+ "language_model.model.layers.15.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
60
+ "language_model.model.layers.15.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
61
+ "language_model.model.layers.15.ffn_norm.weight": "model-00002-of-00004.safetensors",
62
+ "language_model.model.layers.16.attention.wo.weight": "model-00002-of-00004.safetensors",
63
+ "language_model.model.layers.16.attention.wqkv.weight": "model-00002-of-00004.safetensors",
64
+ "language_model.model.layers.16.attention_norm.weight": "model-00002-of-00004.safetensors",
65
+ "language_model.model.layers.16.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
66
+ "language_model.model.layers.16.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
67
+ "language_model.model.layers.16.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
68
+ "language_model.model.layers.16.ffn_norm.weight": "model-00002-of-00004.safetensors",
69
+ "language_model.model.layers.17.attention.wo.weight": "model-00002-of-00004.safetensors",
70
+ "language_model.model.layers.17.attention.wqkv.weight": "model-00002-of-00004.safetensors",
71
+ "language_model.model.layers.17.attention_norm.weight": "model-00002-of-00004.safetensors",
72
+ "language_model.model.layers.17.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
73
+ "language_model.model.layers.17.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
74
+ "language_model.model.layers.17.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
75
+ "language_model.model.layers.17.ffn_norm.weight": "model-00002-of-00004.safetensors",
76
+ "language_model.model.layers.18.attention.wo.weight": "model-00002-of-00004.safetensors",
77
+ "language_model.model.layers.18.attention.wqkv.weight": "model-00002-of-00004.safetensors",
78
+ "language_model.model.layers.18.attention_norm.weight": "model-00002-of-00004.safetensors",
79
+ "language_model.model.layers.18.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
80
+ "language_model.model.layers.18.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
81
+ "language_model.model.layers.18.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
82
+ "language_model.model.layers.18.ffn_norm.weight": "model-00002-of-00004.safetensors",
83
+ "language_model.model.layers.19.attention.wo.weight": "model-00002-of-00004.safetensors",
84
+ "language_model.model.layers.19.attention.wqkv.weight": "model-00002-of-00004.safetensors",
85
+ "language_model.model.layers.19.attention_norm.weight": "model-00003-of-00004.safetensors",
86
+ "language_model.model.layers.19.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
87
+ "language_model.model.layers.19.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
88
+ "language_model.model.layers.19.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
89
+ "language_model.model.layers.19.ffn_norm.weight": "model-00003-of-00004.safetensors",
90
+ "language_model.model.layers.2.attention.wo.weight": "model-00001-of-00004.safetensors",
91
+ "language_model.model.layers.2.attention.wqkv.weight": "model-00001-of-00004.safetensors",
92
+ "language_model.model.layers.2.attention_norm.weight": "model-00001-of-00004.safetensors",
93
+ "language_model.model.layers.2.feed_forward.w1.weight": "model-00001-of-00004.safetensors",
94
+ "language_model.model.layers.2.feed_forward.w2.weight": "model-00001-of-00004.safetensors",
95
+ "language_model.model.layers.2.feed_forward.w3.weight": "model-00001-of-00004.safetensors",
96
+ "language_model.model.layers.2.ffn_norm.weight": "model-00001-of-00004.safetensors",
97
+ "language_model.model.layers.20.attention.wo.weight": "model-00003-of-00004.safetensors",
98
+ "language_model.model.layers.20.attention.wqkv.weight": "model-00003-of-00004.safetensors",
99
+ "language_model.model.layers.20.attention_norm.weight": "model-00003-of-00004.safetensors",
100
+ "language_model.model.layers.20.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
101
+ "language_model.model.layers.20.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
102
+ "language_model.model.layers.20.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
103
+ "language_model.model.layers.20.ffn_norm.weight": "model-00003-of-00004.safetensors",
104
+ "language_model.model.layers.21.attention.wo.weight": "model-00003-of-00004.safetensors",
105
+ "language_model.model.layers.21.attention.wqkv.weight": "model-00003-of-00004.safetensors",
106
+ "language_model.model.layers.21.attention_norm.weight": "model-00003-of-00004.safetensors",
107
+ "language_model.model.layers.21.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
108
+ "language_model.model.layers.21.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
109
+ "language_model.model.layers.21.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
110
+ "language_model.model.layers.21.ffn_norm.weight": "model-00003-of-00004.safetensors",
111
+ "language_model.model.layers.22.attention.wo.weight": "model-00003-of-00004.safetensors",
112
+ "language_model.model.layers.22.attention.wqkv.weight": "model-00003-of-00004.safetensors",
113
+ "language_model.model.layers.22.attention_norm.weight": "model-00003-of-00004.safetensors",
114
+ "language_model.model.layers.22.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
115
+ "language_model.model.layers.22.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
116
+ "language_model.model.layers.22.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
117
+ "language_model.model.layers.22.ffn_norm.weight": "model-00003-of-00004.safetensors",
118
+ "language_model.model.layers.23.attention.wo.weight": "model-00003-of-00004.safetensors",
119
+ "language_model.model.layers.23.attention.wqkv.weight": "model-00003-of-00004.safetensors",
120
+ "language_model.model.layers.23.attention_norm.weight": "model-00003-of-00004.safetensors",
121
+ "language_model.model.layers.23.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
122
+ "language_model.model.layers.23.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
123
+ "language_model.model.layers.23.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
124
+ "language_model.model.layers.23.ffn_norm.weight": "model-00003-of-00004.safetensors",
125
+ "language_model.model.layers.24.attention.wo.weight": "model-00003-of-00004.safetensors",
126
+ "language_model.model.layers.24.attention.wqkv.weight": "model-00003-of-00004.safetensors",
127
+ "language_model.model.layers.24.attention_norm.weight": "model-00003-of-00004.safetensors",
128
+ "language_model.model.layers.24.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
129
+ "language_model.model.layers.24.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
130
+ "language_model.model.layers.24.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
131
+ "language_model.model.layers.24.ffn_norm.weight": "model-00003-of-00004.safetensors",
132
+ "language_model.model.layers.25.attention.wo.weight": "model-00003-of-00004.safetensors",
133
+ "language_model.model.layers.25.attention.wqkv.weight": "model-00003-of-00004.safetensors",
134
+ "language_model.model.layers.25.attention_norm.weight": "model-00003-of-00004.safetensors",
135
+ "language_model.model.layers.25.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
136
+ "language_model.model.layers.25.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
137
+ "language_model.model.layers.25.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
138
+ "language_model.model.layers.25.ffn_norm.weight": "model-00003-of-00004.safetensors",
139
+ "language_model.model.layers.26.attention.wo.weight": "model-00003-of-00004.safetensors",
140
+ "language_model.model.layers.26.attention.wqkv.weight": "model-00003-of-00004.safetensors",
141
+ "language_model.model.layers.26.attention_norm.weight": "model-00003-of-00004.safetensors",
142
+ "language_model.model.layers.26.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
143
+ "language_model.model.layers.26.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
144
+ "language_model.model.layers.26.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
145
+ "language_model.model.layers.26.ffn_norm.weight": "model-00003-of-00004.safetensors",
146
+ "language_model.model.layers.27.attention.wo.weight": "model-00003-of-00004.safetensors",
147
+ "language_model.model.layers.27.attention.wqkv.weight": "model-00003-of-00004.safetensors",
148
+ "language_model.model.layers.27.attention_norm.weight": "model-00003-of-00004.safetensors",
149
+ "language_model.model.layers.27.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
150
+ "language_model.model.layers.27.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
151
+ "language_model.model.layers.27.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
152
+ "language_model.model.layers.27.ffn_norm.weight": "model-00003-of-00004.safetensors",
153
+ "language_model.model.layers.28.attention.wo.weight": "model-00003-of-00004.safetensors",
154
+ "language_model.model.layers.28.attention.wqkv.weight": "model-00003-of-00004.safetensors",
155
+ "language_model.model.layers.28.attention_norm.weight": "model-00003-of-00004.safetensors",
156
+ "language_model.model.layers.28.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
157
+ "language_model.model.layers.28.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
158
+ "language_model.model.layers.28.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
159
+ "language_model.model.layers.28.ffn_norm.weight": "model-00003-of-00004.safetensors",
160
+ "language_model.model.layers.29.attention.wo.weight": "model-00003-of-00004.safetensors",
161
+ "language_model.model.layers.29.attention.wqkv.weight": "model-00003-of-00004.safetensors",
162
+ "language_model.model.layers.29.attention_norm.weight": "model-00003-of-00004.safetensors",
163
+ "language_model.model.layers.29.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
164
+ "language_model.model.layers.29.feed_forward.w2.weight": "model-00003-of-00004.safetensors",
165
+ "language_model.model.layers.29.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
166
+ "language_model.model.layers.29.ffn_norm.weight": "model-00003-of-00004.safetensors",
167
+ "language_model.model.layers.3.attention.wo.weight": "model-00001-of-00004.safetensors",
168
+ "language_model.model.layers.3.attention.wqkv.weight": "model-00001-of-00004.safetensors",
169
+ "language_model.model.layers.3.attention_norm.weight": "model-00001-of-00004.safetensors",
170
+ "language_model.model.layers.3.feed_forward.w1.weight": "model-00001-of-00004.safetensors",
171
+ "language_model.model.layers.3.feed_forward.w2.weight": "model-00001-of-00004.safetensors",
172
+ "language_model.model.layers.3.feed_forward.w3.weight": "model-00001-of-00004.safetensors",
173
+ "language_model.model.layers.3.ffn_norm.weight": "model-00001-of-00004.safetensors",
174
+ "language_model.model.layers.30.attention.wo.weight": "model-00003-of-00004.safetensors",
175
+ "language_model.model.layers.30.attention.wqkv.weight": "model-00003-of-00004.safetensors",
176
+ "language_model.model.layers.30.attention_norm.weight": "model-00004-of-00004.safetensors",
177
+ "language_model.model.layers.30.feed_forward.w1.weight": "model-00003-of-00004.safetensors",
178
+ "language_model.model.layers.30.feed_forward.w2.weight": "model-00004-of-00004.safetensors",
179
+ "language_model.model.layers.30.feed_forward.w3.weight": "model-00003-of-00004.safetensors",
180
+ "language_model.model.layers.30.ffn_norm.weight": "model-00004-of-00004.safetensors",
181
+ "language_model.model.layers.31.attention.wo.weight": "model-00004-of-00004.safetensors",
182
+ "language_model.model.layers.31.attention.wqkv.weight": "model-00004-of-00004.safetensors",
183
+ "language_model.model.layers.31.attention_norm.weight": "model-00004-of-00004.safetensors",
184
+ "language_model.model.layers.31.feed_forward.w1.weight": "model-00004-of-00004.safetensors",
185
+ "language_model.model.layers.31.feed_forward.w2.weight": "model-00004-of-00004.safetensors",
186
+ "language_model.model.layers.31.feed_forward.w3.weight": "model-00004-of-00004.safetensors",
187
+ "language_model.model.layers.31.ffn_norm.weight": "model-00004-of-00004.safetensors",
188
+ "language_model.model.layers.4.attention.wo.weight": "model-00001-of-00004.safetensors",
189
+ "language_model.model.layers.4.attention.wqkv.weight": "model-00001-of-00004.safetensors",
190
+ "language_model.model.layers.4.attention_norm.weight": "model-00001-of-00004.safetensors",
191
+ "language_model.model.layers.4.feed_forward.w1.weight": "model-00001-of-00004.safetensors",
192
+ "language_model.model.layers.4.feed_forward.w2.weight": "model-00001-of-00004.safetensors",
193
+ "language_model.model.layers.4.feed_forward.w3.weight": "model-00001-of-00004.safetensors",
194
+ "language_model.model.layers.4.ffn_norm.weight": "model-00001-of-00004.safetensors",
195
+ "language_model.model.layers.5.attention.wo.weight": "model-00001-of-00004.safetensors",
196
+ "language_model.model.layers.5.attention.wqkv.weight": "model-00001-of-00004.safetensors",
197
+ "language_model.model.layers.5.attention_norm.weight": "model-00001-of-00004.safetensors",
198
+ "language_model.model.layers.5.feed_forward.w1.weight": "model-00001-of-00004.safetensors",
199
+ "language_model.model.layers.5.feed_forward.w2.weight": "model-00001-of-00004.safetensors",
200
+ "language_model.model.layers.5.feed_forward.w3.weight": "model-00001-of-00004.safetensors",
201
+ "language_model.model.layers.5.ffn_norm.weight": "model-00001-of-00004.safetensors",
202
+ "language_model.model.layers.6.attention.wo.weight": "model-00001-of-00004.safetensors",
203
+ "language_model.model.layers.6.attention.wqkv.weight": "model-00001-of-00004.safetensors",
204
+ "language_model.model.layers.6.attention_norm.weight": "model-00001-of-00004.safetensors",
205
+ "language_model.model.layers.6.feed_forward.w1.weight": "model-00001-of-00004.safetensors",
206
+ "language_model.model.layers.6.feed_forward.w2.weight": "model-00001-of-00004.safetensors",
207
+ "language_model.model.layers.6.feed_forward.w3.weight": "model-00001-of-00004.safetensors",
208
+ "language_model.model.layers.6.ffn_norm.weight": "model-00001-of-00004.safetensors",
209
+ "language_model.model.layers.7.attention.wo.weight": "model-00001-of-00004.safetensors",
210
+ "language_model.model.layers.7.attention.wqkv.weight": "model-00001-of-00004.safetensors",
211
+ "language_model.model.layers.7.attention_norm.weight": "model-00001-of-00004.safetensors",
212
+ "language_model.model.layers.7.feed_forward.w1.weight": "model-00001-of-00004.safetensors",
213
+ "language_model.model.layers.7.feed_forward.w2.weight": "model-00001-of-00004.safetensors",
214
+ "language_model.model.layers.7.feed_forward.w3.weight": "model-00001-of-00004.safetensors",
215
+ "language_model.model.layers.7.ffn_norm.weight": "model-00001-of-00004.safetensors",
216
+ "language_model.model.layers.8.attention.wo.weight": "model-00001-of-00004.safetensors",
217
+ "language_model.model.layers.8.attention.wqkv.weight": "model-00001-of-00004.safetensors",
218
+ "language_model.model.layers.8.attention_norm.weight": "model-00002-of-00004.safetensors",
219
+ "language_model.model.layers.8.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
220
+ "language_model.model.layers.8.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
221
+ "language_model.model.layers.8.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
222
+ "language_model.model.layers.8.ffn_norm.weight": "model-00002-of-00004.safetensors",
223
+ "language_model.model.layers.9.attention.wo.weight": "model-00002-of-00004.safetensors",
224
+ "language_model.model.layers.9.attention.wqkv.weight": "model-00002-of-00004.safetensors",
225
+ "language_model.model.layers.9.attention_norm.weight": "model-00002-of-00004.safetensors",
226
+ "language_model.model.layers.9.feed_forward.w1.weight": "model-00002-of-00004.safetensors",
227
+ "language_model.model.layers.9.feed_forward.w2.weight": "model-00002-of-00004.safetensors",
228
+ "language_model.model.layers.9.feed_forward.w3.weight": "model-00002-of-00004.safetensors",
229
+ "language_model.model.layers.9.ffn_norm.weight": "model-00002-of-00004.safetensors",
230
+ "language_model.model.norm.weight": "model-00004-of-00004.safetensors",
231
+ "language_model.model.tok_embeddings.weight": "model-00001-of-00004.safetensors",
232
+ "language_model.output.weight": "model-00004-of-00004.safetensors",
233
+ "multi_modal_projector.linear_1.bias": "model-00001-of-00004.safetensors",
234
+ "multi_modal_projector.linear_1.weight": "model-00001-of-00004.safetensors",
235
+ "multi_modal_projector.linear_2.bias": "model-00001-of-00004.safetensors",
236
+ "multi_modal_projector.linear_2.weight": "model-00001-of-00004.safetensors",
237
+ "vision_tower.vision_model.embeddings.class_embedding": "model-00001-of-00004.safetensors",
238
+ "vision_tower.vision_model.embeddings.patch_embedding.weight": "model-00001-of-00004.safetensors",
239
+ "vision_tower.vision_model.embeddings.position_embedding.weight": "model-00001-of-00004.safetensors",
240
+ "vision_tower.vision_model.encoder.layers.0.layer_norm1.bias": "model-00001-of-00004.safetensors",
241
+ "vision_tower.vision_model.encoder.layers.0.layer_norm1.weight": "model-00001-of-00004.safetensors",
242
+ "vision_tower.vision_model.encoder.layers.0.layer_norm2.bias": "model-00001-of-00004.safetensors",
243
+ "vision_tower.vision_model.encoder.layers.0.layer_norm2.weight": "model-00001-of-00004.safetensors",
244
+ "vision_tower.vision_model.encoder.layers.0.mlp.fc1.bias": "model-00001-of-00004.safetensors",
245
+ "vision_tower.vision_model.encoder.layers.0.mlp.fc1.weight": "model-00001-of-00004.safetensors",
246
+ "vision_tower.vision_model.encoder.layers.0.mlp.fc2.bias": "model-00001-of-00004.safetensors",
247
+ "vision_tower.vision_model.encoder.layers.0.mlp.fc2.weight": "model-00001-of-00004.safetensors",
248
+ "vision_tower.vision_model.encoder.layers.0.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
249
+ "vision_tower.vision_model.encoder.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
250
+ "vision_tower.vision_model.encoder.layers.0.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
251
+ "vision_tower.vision_model.encoder.layers.0.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
252
+ "vision_tower.vision_model.encoder.layers.0.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
253
+ "vision_tower.vision_model.encoder.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
254
+ "vision_tower.vision_model.encoder.layers.0.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
255
+ "vision_tower.vision_model.encoder.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
256
+ "vision_tower.vision_model.encoder.layers.1.layer_norm1.bias": "model-00001-of-00004.safetensors",
257
+ "vision_tower.vision_model.encoder.layers.1.layer_norm1.weight": "model-00001-of-00004.safetensors",
258
+ "vision_tower.vision_model.encoder.layers.1.layer_norm2.bias": "model-00001-of-00004.safetensors",
259
+ "vision_tower.vision_model.encoder.layers.1.layer_norm2.weight": "model-00001-of-00004.safetensors",
260
+ "vision_tower.vision_model.encoder.layers.1.mlp.fc1.bias": "model-00001-of-00004.safetensors",
261
+ "vision_tower.vision_model.encoder.layers.1.mlp.fc1.weight": "model-00001-of-00004.safetensors",
262
+ "vision_tower.vision_model.encoder.layers.1.mlp.fc2.bias": "model-00001-of-00004.safetensors",
263
+ "vision_tower.vision_model.encoder.layers.1.mlp.fc2.weight": "model-00001-of-00004.safetensors",
264
+ "vision_tower.vision_model.encoder.layers.1.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
265
+ "vision_tower.vision_model.encoder.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
266
+ "vision_tower.vision_model.encoder.layers.1.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
267
+ "vision_tower.vision_model.encoder.layers.1.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
268
+ "vision_tower.vision_model.encoder.layers.1.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
269
+ "vision_tower.vision_model.encoder.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
270
+ "vision_tower.vision_model.encoder.layers.1.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
271
+ "vision_tower.vision_model.encoder.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
272
+ "vision_tower.vision_model.encoder.layers.10.layer_norm1.bias": "model-00001-of-00004.safetensors",
273
+ "vision_tower.vision_model.encoder.layers.10.layer_norm1.weight": "model-00001-of-00004.safetensors",
274
+ "vision_tower.vision_model.encoder.layers.10.layer_norm2.bias": "model-00001-of-00004.safetensors",
275
+ "vision_tower.vision_model.encoder.layers.10.layer_norm2.weight": "model-00001-of-00004.safetensors",
276
+ "vision_tower.vision_model.encoder.layers.10.mlp.fc1.bias": "model-00001-of-00004.safetensors",
277
+ "vision_tower.vision_model.encoder.layers.10.mlp.fc1.weight": "model-00001-of-00004.safetensors",
278
+ "vision_tower.vision_model.encoder.layers.10.mlp.fc2.bias": "model-00001-of-00004.safetensors",
279
+ "vision_tower.vision_model.encoder.layers.10.mlp.fc2.weight": "model-00001-of-00004.safetensors",
280
+ "vision_tower.vision_model.encoder.layers.10.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
281
+ "vision_tower.vision_model.encoder.layers.10.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
282
+ "vision_tower.vision_model.encoder.layers.10.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
283
+ "vision_tower.vision_model.encoder.layers.10.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
284
+ "vision_tower.vision_model.encoder.layers.10.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
285
+ "vision_tower.vision_model.encoder.layers.10.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
286
+ "vision_tower.vision_model.encoder.layers.10.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
287
+ "vision_tower.vision_model.encoder.layers.10.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
288
+ "vision_tower.vision_model.encoder.layers.11.layer_norm1.bias": "model-00001-of-00004.safetensors",
289
+ "vision_tower.vision_model.encoder.layers.11.layer_norm1.weight": "model-00001-of-00004.safetensors",
290
+ "vision_tower.vision_model.encoder.layers.11.layer_norm2.bias": "model-00001-of-00004.safetensors",
291
+ "vision_tower.vision_model.encoder.layers.11.layer_norm2.weight": "model-00001-of-00004.safetensors",
292
+ "vision_tower.vision_model.encoder.layers.11.mlp.fc1.bias": "model-00001-of-00004.safetensors",
293
+ "vision_tower.vision_model.encoder.layers.11.mlp.fc1.weight": "model-00001-of-00004.safetensors",
294
+ "vision_tower.vision_model.encoder.layers.11.mlp.fc2.bias": "model-00001-of-00004.safetensors",
295
+ "vision_tower.vision_model.encoder.layers.11.mlp.fc2.weight": "model-00001-of-00004.safetensors",
296
+ "vision_tower.vision_model.encoder.layers.11.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
297
+ "vision_tower.vision_model.encoder.layers.11.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
298
+ "vision_tower.vision_model.encoder.layers.11.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
299
+ "vision_tower.vision_model.encoder.layers.11.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
300
+ "vision_tower.vision_model.encoder.layers.11.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
301
+ "vision_tower.vision_model.encoder.layers.11.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
302
+ "vision_tower.vision_model.encoder.layers.11.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
303
+ "vision_tower.vision_model.encoder.layers.11.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
304
+ "vision_tower.vision_model.encoder.layers.12.layer_norm1.bias": "model-00001-of-00004.safetensors",
305
+ "vision_tower.vision_model.encoder.layers.12.layer_norm1.weight": "model-00001-of-00004.safetensors",
306
+ "vision_tower.vision_model.encoder.layers.12.layer_norm2.bias": "model-00001-of-00004.safetensors",
307
+ "vision_tower.vision_model.encoder.layers.12.layer_norm2.weight": "model-00001-of-00004.safetensors",
308
+ "vision_tower.vision_model.encoder.layers.12.mlp.fc1.bias": "model-00001-of-00004.safetensors",
309
+ "vision_tower.vision_model.encoder.layers.12.mlp.fc1.weight": "model-00001-of-00004.safetensors",
310
+ "vision_tower.vision_model.encoder.layers.12.mlp.fc2.bias": "model-00001-of-00004.safetensors",
311
+ "vision_tower.vision_model.encoder.layers.12.mlp.fc2.weight": "model-00001-of-00004.safetensors",
312
+ "vision_tower.vision_model.encoder.layers.12.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
313
+ "vision_tower.vision_model.encoder.layers.12.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
314
+ "vision_tower.vision_model.encoder.layers.12.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
315
+ "vision_tower.vision_model.encoder.layers.12.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
316
+ "vision_tower.vision_model.encoder.layers.12.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
317
+ "vision_tower.vision_model.encoder.layers.12.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
318
+ "vision_tower.vision_model.encoder.layers.12.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
319
+ "vision_tower.vision_model.encoder.layers.12.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
320
+ "vision_tower.vision_model.encoder.layers.13.layer_norm1.bias": "model-00001-of-00004.safetensors",
321
+ "vision_tower.vision_model.encoder.layers.13.layer_norm1.weight": "model-00001-of-00004.safetensors",
322
+ "vision_tower.vision_model.encoder.layers.13.layer_norm2.bias": "model-00001-of-00004.safetensors",
323
+ "vision_tower.vision_model.encoder.layers.13.layer_norm2.weight": "model-00001-of-00004.safetensors",
324
+ "vision_tower.vision_model.encoder.layers.13.mlp.fc1.bias": "model-00001-of-00004.safetensors",
325
+ "vision_tower.vision_model.encoder.layers.13.mlp.fc1.weight": "model-00001-of-00004.safetensors",
326
+ "vision_tower.vision_model.encoder.layers.13.mlp.fc2.bias": "model-00001-of-00004.safetensors",
327
+ "vision_tower.vision_model.encoder.layers.13.mlp.fc2.weight": "model-00001-of-00004.safetensors",
328
+ "vision_tower.vision_model.encoder.layers.13.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
329
+ "vision_tower.vision_model.encoder.layers.13.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
330
+ "vision_tower.vision_model.encoder.layers.13.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
331
+ "vision_tower.vision_model.encoder.layers.13.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
332
+ "vision_tower.vision_model.encoder.layers.13.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
333
+ "vision_tower.vision_model.encoder.layers.13.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
334
+ "vision_tower.vision_model.encoder.layers.13.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
335
+ "vision_tower.vision_model.encoder.layers.13.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
336
+ "vision_tower.vision_model.encoder.layers.14.layer_norm1.bias": "model-00001-of-00004.safetensors",
337
+ "vision_tower.vision_model.encoder.layers.14.layer_norm1.weight": "model-00001-of-00004.safetensors",
338
+ "vision_tower.vision_model.encoder.layers.14.layer_norm2.bias": "model-00001-of-00004.safetensors",
339
+ "vision_tower.vision_model.encoder.layers.14.layer_norm2.weight": "model-00001-of-00004.safetensors",
340
+ "vision_tower.vision_model.encoder.layers.14.mlp.fc1.bias": "model-00001-of-00004.safetensors",
341
+ "vision_tower.vision_model.encoder.layers.14.mlp.fc1.weight": "model-00001-of-00004.safetensors",
342
+ "vision_tower.vision_model.encoder.layers.14.mlp.fc2.bias": "model-00001-of-00004.safetensors",
343
+ "vision_tower.vision_model.encoder.layers.14.mlp.fc2.weight": "model-00001-of-00004.safetensors",
344
+ "vision_tower.vision_model.encoder.layers.14.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
345
+ "vision_tower.vision_model.encoder.layers.14.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
346
+ "vision_tower.vision_model.encoder.layers.14.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
347
+ "vision_tower.vision_model.encoder.layers.14.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
348
+ "vision_tower.vision_model.encoder.layers.14.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
349
+ "vision_tower.vision_model.encoder.layers.14.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
350
+ "vision_tower.vision_model.encoder.layers.14.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
351
+ "vision_tower.vision_model.encoder.layers.14.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
352
+ "vision_tower.vision_model.encoder.layers.15.layer_norm1.bias": "model-00001-of-00004.safetensors",
353
+ "vision_tower.vision_model.encoder.layers.15.layer_norm1.weight": "model-00001-of-00004.safetensors",
354
+ "vision_tower.vision_model.encoder.layers.15.layer_norm2.bias": "model-00001-of-00004.safetensors",
355
+ "vision_tower.vision_model.encoder.layers.15.layer_norm2.weight": "model-00001-of-00004.safetensors",
356
+ "vision_tower.vision_model.encoder.layers.15.mlp.fc1.bias": "model-00001-of-00004.safetensors",
357
+ "vision_tower.vision_model.encoder.layers.15.mlp.fc1.weight": "model-00001-of-00004.safetensors",
358
+ "vision_tower.vision_model.encoder.layers.15.mlp.fc2.bias": "model-00001-of-00004.safetensors",
359
+ "vision_tower.vision_model.encoder.layers.15.mlp.fc2.weight": "model-00001-of-00004.safetensors",
360
+ "vision_tower.vision_model.encoder.layers.15.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
361
+ "vision_tower.vision_model.encoder.layers.15.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
362
+ "vision_tower.vision_model.encoder.layers.15.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
363
+ "vision_tower.vision_model.encoder.layers.15.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
364
+ "vision_tower.vision_model.encoder.layers.15.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
365
+ "vision_tower.vision_model.encoder.layers.15.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
366
+ "vision_tower.vision_model.encoder.layers.15.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
367
+ "vision_tower.vision_model.encoder.layers.15.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
368
+ "vision_tower.vision_model.encoder.layers.16.layer_norm1.bias": "model-00001-of-00004.safetensors",
369
+ "vision_tower.vision_model.encoder.layers.16.layer_norm1.weight": "model-00001-of-00004.safetensors",
370
+ "vision_tower.vision_model.encoder.layers.16.layer_norm2.bias": "model-00001-of-00004.safetensors",
371
+ "vision_tower.vision_model.encoder.layers.16.layer_norm2.weight": "model-00001-of-00004.safetensors",
372
+ "vision_tower.vision_model.encoder.layers.16.mlp.fc1.bias": "model-00001-of-00004.safetensors",
373
+ "vision_tower.vision_model.encoder.layers.16.mlp.fc1.weight": "model-00001-of-00004.safetensors",
374
+ "vision_tower.vision_model.encoder.layers.16.mlp.fc2.bias": "model-00001-of-00004.safetensors",
375
+ "vision_tower.vision_model.encoder.layers.16.mlp.fc2.weight": "model-00001-of-00004.safetensors",
376
+ "vision_tower.vision_model.encoder.layers.16.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
377
+ "vision_tower.vision_model.encoder.layers.16.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
378
+ "vision_tower.vision_model.encoder.layers.16.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
379
+ "vision_tower.vision_model.encoder.layers.16.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
380
+ "vision_tower.vision_model.encoder.layers.16.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
381
+ "vision_tower.vision_model.encoder.layers.16.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
382
+ "vision_tower.vision_model.encoder.layers.16.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
383
+ "vision_tower.vision_model.encoder.layers.16.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
384
+ "vision_tower.vision_model.encoder.layers.17.layer_norm1.bias": "model-00001-of-00004.safetensors",
385
+ "vision_tower.vision_model.encoder.layers.17.layer_norm1.weight": "model-00001-of-00004.safetensors",
386
+ "vision_tower.vision_model.encoder.layers.17.layer_norm2.bias": "model-00001-of-00004.safetensors",
387
+ "vision_tower.vision_model.encoder.layers.17.layer_norm2.weight": "model-00001-of-00004.safetensors",
388
+ "vision_tower.vision_model.encoder.layers.17.mlp.fc1.bias": "model-00001-of-00004.safetensors",
389
+ "vision_tower.vision_model.encoder.layers.17.mlp.fc1.weight": "model-00001-of-00004.safetensors",
390
+ "vision_tower.vision_model.encoder.layers.17.mlp.fc2.bias": "model-00001-of-00004.safetensors",
391
+ "vision_tower.vision_model.encoder.layers.17.mlp.fc2.weight": "model-00001-of-00004.safetensors",
392
+ "vision_tower.vision_model.encoder.layers.17.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
393
+ "vision_tower.vision_model.encoder.layers.17.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
394
+ "vision_tower.vision_model.encoder.layers.17.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
395
+ "vision_tower.vision_model.encoder.layers.17.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
396
+ "vision_tower.vision_model.encoder.layers.17.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
397
+ "vision_tower.vision_model.encoder.layers.17.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
398
+ "vision_tower.vision_model.encoder.layers.17.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
399
+ "vision_tower.vision_model.encoder.layers.17.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
400
+ "vision_tower.vision_model.encoder.layers.18.layer_norm1.bias": "model-00001-of-00004.safetensors",
401
+ "vision_tower.vision_model.encoder.layers.18.layer_norm1.weight": "model-00001-of-00004.safetensors",
402
+ "vision_tower.vision_model.encoder.layers.18.layer_norm2.bias": "model-00001-of-00004.safetensors",
403
+ "vision_tower.vision_model.encoder.layers.18.layer_norm2.weight": "model-00001-of-00004.safetensors",
404
+ "vision_tower.vision_model.encoder.layers.18.mlp.fc1.bias": "model-00001-of-00004.safetensors",
405
+ "vision_tower.vision_model.encoder.layers.18.mlp.fc1.weight": "model-00001-of-00004.safetensors",
406
+ "vision_tower.vision_model.encoder.layers.18.mlp.fc2.bias": "model-00001-of-00004.safetensors",
407
+ "vision_tower.vision_model.encoder.layers.18.mlp.fc2.weight": "model-00001-of-00004.safetensors",
408
+ "vision_tower.vision_model.encoder.layers.18.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
409
+ "vision_tower.vision_model.encoder.layers.18.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
410
+ "vision_tower.vision_model.encoder.layers.18.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
411
+ "vision_tower.vision_model.encoder.layers.18.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
412
+ "vision_tower.vision_model.encoder.layers.18.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
413
+ "vision_tower.vision_model.encoder.layers.18.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
414
+ "vision_tower.vision_model.encoder.layers.18.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
415
+ "vision_tower.vision_model.encoder.layers.18.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
416
+ "vision_tower.vision_model.encoder.layers.19.layer_norm1.bias": "model-00001-of-00004.safetensors",
417
+ "vision_tower.vision_model.encoder.layers.19.layer_norm1.weight": "model-00001-of-00004.safetensors",
418
+ "vision_tower.vision_model.encoder.layers.19.layer_norm2.bias": "model-00001-of-00004.safetensors",
419
+ "vision_tower.vision_model.encoder.layers.19.layer_norm2.weight": "model-00001-of-00004.safetensors",
420
+ "vision_tower.vision_model.encoder.layers.19.mlp.fc1.bias": "model-00001-of-00004.safetensors",
421
+ "vision_tower.vision_model.encoder.layers.19.mlp.fc1.weight": "model-00001-of-00004.safetensors",
422
+ "vision_tower.vision_model.encoder.layers.19.mlp.fc2.bias": "model-00001-of-00004.safetensors",
423
+ "vision_tower.vision_model.encoder.layers.19.mlp.fc2.weight": "model-00001-of-00004.safetensors",
424
+ "vision_tower.vision_model.encoder.layers.19.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
425
+ "vision_tower.vision_model.encoder.layers.19.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
426
+ "vision_tower.vision_model.encoder.layers.19.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
427
+ "vision_tower.vision_model.encoder.layers.19.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
428
+ "vision_tower.vision_model.encoder.layers.19.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
429
+ "vision_tower.vision_model.encoder.layers.19.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
430
+ "vision_tower.vision_model.encoder.layers.19.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
431
+ "vision_tower.vision_model.encoder.layers.19.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
432
+ "vision_tower.vision_model.encoder.layers.2.layer_norm1.bias": "model-00001-of-00004.safetensors",
433
+ "vision_tower.vision_model.encoder.layers.2.layer_norm1.weight": "model-00001-of-00004.safetensors",
434
+ "vision_tower.vision_model.encoder.layers.2.layer_norm2.bias": "model-00001-of-00004.safetensors",
435
+ "vision_tower.vision_model.encoder.layers.2.layer_norm2.weight": "model-00001-of-00004.safetensors",
436
+ "vision_tower.vision_model.encoder.layers.2.mlp.fc1.bias": "model-00001-of-00004.safetensors",
437
+ "vision_tower.vision_model.encoder.layers.2.mlp.fc1.weight": "model-00001-of-00004.safetensors",
438
+ "vision_tower.vision_model.encoder.layers.2.mlp.fc2.bias": "model-00001-of-00004.safetensors",
439
+ "vision_tower.vision_model.encoder.layers.2.mlp.fc2.weight": "model-00001-of-00004.safetensors",
440
+ "vision_tower.vision_model.encoder.layers.2.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
441
+ "vision_tower.vision_model.encoder.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
442
+ "vision_tower.vision_model.encoder.layers.2.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
443
+ "vision_tower.vision_model.encoder.layers.2.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
444
+ "vision_tower.vision_model.encoder.layers.2.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
445
+ "vision_tower.vision_model.encoder.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
446
+ "vision_tower.vision_model.encoder.layers.2.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
447
+ "vision_tower.vision_model.encoder.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
448
+ "vision_tower.vision_model.encoder.layers.20.layer_norm1.bias": "model-00001-of-00004.safetensors",
449
+ "vision_tower.vision_model.encoder.layers.20.layer_norm1.weight": "model-00001-of-00004.safetensors",
450
+ "vision_tower.vision_model.encoder.layers.20.layer_norm2.bias": "model-00001-of-00004.safetensors",
451
+ "vision_tower.vision_model.encoder.layers.20.layer_norm2.weight": "model-00001-of-00004.safetensors",
452
+ "vision_tower.vision_model.encoder.layers.20.mlp.fc1.bias": "model-00001-of-00004.safetensors",
453
+ "vision_tower.vision_model.encoder.layers.20.mlp.fc1.weight": "model-00001-of-00004.safetensors",
454
+ "vision_tower.vision_model.encoder.layers.20.mlp.fc2.bias": "model-00001-of-00004.safetensors",
455
+ "vision_tower.vision_model.encoder.layers.20.mlp.fc2.weight": "model-00001-of-00004.safetensors",
456
+ "vision_tower.vision_model.encoder.layers.20.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
457
+ "vision_tower.vision_model.encoder.layers.20.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
458
+ "vision_tower.vision_model.encoder.layers.20.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
459
+ "vision_tower.vision_model.encoder.layers.20.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
460
+ "vision_tower.vision_model.encoder.layers.20.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
461
+ "vision_tower.vision_model.encoder.layers.20.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
462
+ "vision_tower.vision_model.encoder.layers.20.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
463
+ "vision_tower.vision_model.encoder.layers.20.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
464
+ "vision_tower.vision_model.encoder.layers.21.layer_norm1.bias": "model-00001-of-00004.safetensors",
465
+ "vision_tower.vision_model.encoder.layers.21.layer_norm1.weight": "model-00001-of-00004.safetensors",
466
+ "vision_tower.vision_model.encoder.layers.21.layer_norm2.bias": "model-00001-of-00004.safetensors",
467
+ "vision_tower.vision_model.encoder.layers.21.layer_norm2.weight": "model-00001-of-00004.safetensors",
468
+ "vision_tower.vision_model.encoder.layers.21.mlp.fc1.bias": "model-00001-of-00004.safetensors",
469
+ "vision_tower.vision_model.encoder.layers.21.mlp.fc1.weight": "model-00001-of-00004.safetensors",
470
+ "vision_tower.vision_model.encoder.layers.21.mlp.fc2.bias": "model-00001-of-00004.safetensors",
471
+ "vision_tower.vision_model.encoder.layers.21.mlp.fc2.weight": "model-00001-of-00004.safetensors",
472
+ "vision_tower.vision_model.encoder.layers.21.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
473
+ "vision_tower.vision_model.encoder.layers.21.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
474
+ "vision_tower.vision_model.encoder.layers.21.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
475
+ "vision_tower.vision_model.encoder.layers.21.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
476
+ "vision_tower.vision_model.encoder.layers.21.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
477
+ "vision_tower.vision_model.encoder.layers.21.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
478
+ "vision_tower.vision_model.encoder.layers.21.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
479
+ "vision_tower.vision_model.encoder.layers.21.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
480
+ "vision_tower.vision_model.encoder.layers.22.layer_norm1.bias": "model-00001-of-00004.safetensors",
481
+ "vision_tower.vision_model.encoder.layers.22.layer_norm1.weight": "model-00001-of-00004.safetensors",
482
+ "vision_tower.vision_model.encoder.layers.22.layer_norm2.bias": "model-00001-of-00004.safetensors",
483
+ "vision_tower.vision_model.encoder.layers.22.layer_norm2.weight": "model-00001-of-00004.safetensors",
484
+ "vision_tower.vision_model.encoder.layers.22.mlp.fc1.bias": "model-00001-of-00004.safetensors",
485
+ "vision_tower.vision_model.encoder.layers.22.mlp.fc1.weight": "model-00001-of-00004.safetensors",
486
+ "vision_tower.vision_model.encoder.layers.22.mlp.fc2.bias": "model-00001-of-00004.safetensors",
487
+ "vision_tower.vision_model.encoder.layers.22.mlp.fc2.weight": "model-00001-of-00004.safetensors",
488
+ "vision_tower.vision_model.encoder.layers.22.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
489
+ "vision_tower.vision_model.encoder.layers.22.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
490
+ "vision_tower.vision_model.encoder.layers.22.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
491
+ "vision_tower.vision_model.encoder.layers.22.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
492
+ "vision_tower.vision_model.encoder.layers.22.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
493
+ "vision_tower.vision_model.encoder.layers.22.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
494
+ "vision_tower.vision_model.encoder.layers.22.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
495
+ "vision_tower.vision_model.encoder.layers.22.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
496
+ "vision_tower.vision_model.encoder.layers.23.layer_norm1.bias": "model-00001-of-00004.safetensors",
497
+ "vision_tower.vision_model.encoder.layers.23.layer_norm1.weight": "model-00001-of-00004.safetensors",
498
+ "vision_tower.vision_model.encoder.layers.23.layer_norm2.bias": "model-00001-of-00004.safetensors",
499
+ "vision_tower.vision_model.encoder.layers.23.layer_norm2.weight": "model-00001-of-00004.safetensors",
500
+ "vision_tower.vision_model.encoder.layers.23.mlp.fc1.bias": "model-00001-of-00004.safetensors",
501
+ "vision_tower.vision_model.encoder.layers.23.mlp.fc1.weight": "model-00001-of-00004.safetensors",
502
+ "vision_tower.vision_model.encoder.layers.23.mlp.fc2.bias": "model-00001-of-00004.safetensors",
503
+ "vision_tower.vision_model.encoder.layers.23.mlp.fc2.weight": "model-00001-of-00004.safetensors",
504
+ "vision_tower.vision_model.encoder.layers.23.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
505
+ "vision_tower.vision_model.encoder.layers.23.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
506
+ "vision_tower.vision_model.encoder.layers.23.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
507
+ "vision_tower.vision_model.encoder.layers.23.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
508
+ "vision_tower.vision_model.encoder.layers.23.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
509
+ "vision_tower.vision_model.encoder.layers.23.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
510
+ "vision_tower.vision_model.encoder.layers.23.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
511
+ "vision_tower.vision_model.encoder.layers.23.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
512
+ "vision_tower.vision_model.encoder.layers.3.layer_norm1.bias": "model-00001-of-00004.safetensors",
513
+ "vision_tower.vision_model.encoder.layers.3.layer_norm1.weight": "model-00001-of-00004.safetensors",
514
+ "vision_tower.vision_model.encoder.layers.3.layer_norm2.bias": "model-00001-of-00004.safetensors",
515
+ "vision_tower.vision_model.encoder.layers.3.layer_norm2.weight": "model-00001-of-00004.safetensors",
516
+ "vision_tower.vision_model.encoder.layers.3.mlp.fc1.bias": "model-00001-of-00004.safetensors",
517
+ "vision_tower.vision_model.encoder.layers.3.mlp.fc1.weight": "model-00001-of-00004.safetensors",
518
+ "vision_tower.vision_model.encoder.layers.3.mlp.fc2.bias": "model-00001-of-00004.safetensors",
519
+ "vision_tower.vision_model.encoder.layers.3.mlp.fc2.weight": "model-00001-of-00004.safetensors",
520
+ "vision_tower.vision_model.encoder.layers.3.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
521
+ "vision_tower.vision_model.encoder.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
522
+ "vision_tower.vision_model.encoder.layers.3.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
523
+ "vision_tower.vision_model.encoder.layers.3.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
524
+ "vision_tower.vision_model.encoder.layers.3.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
525
+ "vision_tower.vision_model.encoder.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
526
+ "vision_tower.vision_model.encoder.layers.3.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
527
+ "vision_tower.vision_model.encoder.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
528
+ "vision_tower.vision_model.encoder.layers.4.layer_norm1.bias": "model-00001-of-00004.safetensors",
529
+ "vision_tower.vision_model.encoder.layers.4.layer_norm1.weight": "model-00001-of-00004.safetensors",
530
+ "vision_tower.vision_model.encoder.layers.4.layer_norm2.bias": "model-00001-of-00004.safetensors",
531
+ "vision_tower.vision_model.encoder.layers.4.layer_norm2.weight": "model-00001-of-00004.safetensors",
532
+ "vision_tower.vision_model.encoder.layers.4.mlp.fc1.bias": "model-00001-of-00004.safetensors",
533
+ "vision_tower.vision_model.encoder.layers.4.mlp.fc1.weight": "model-00001-of-00004.safetensors",
534
+ "vision_tower.vision_model.encoder.layers.4.mlp.fc2.bias": "model-00001-of-00004.safetensors",
535
+ "vision_tower.vision_model.encoder.layers.4.mlp.fc2.weight": "model-00001-of-00004.safetensors",
536
+ "vision_tower.vision_model.encoder.layers.4.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
537
+ "vision_tower.vision_model.encoder.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
538
+ "vision_tower.vision_model.encoder.layers.4.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
539
+ "vision_tower.vision_model.encoder.layers.4.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
540
+ "vision_tower.vision_model.encoder.layers.4.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
541
+ "vision_tower.vision_model.encoder.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
542
+ "vision_tower.vision_model.encoder.layers.4.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
543
+ "vision_tower.vision_model.encoder.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
544
+ "vision_tower.vision_model.encoder.layers.5.layer_norm1.bias": "model-00001-of-00004.safetensors",
545
+ "vision_tower.vision_model.encoder.layers.5.layer_norm1.weight": "model-00001-of-00004.safetensors",
546
+ "vision_tower.vision_model.encoder.layers.5.layer_norm2.bias": "model-00001-of-00004.safetensors",
547
+ "vision_tower.vision_model.encoder.layers.5.layer_norm2.weight": "model-00001-of-00004.safetensors",
548
+ "vision_tower.vision_model.encoder.layers.5.mlp.fc1.bias": "model-00001-of-00004.safetensors",
549
+ "vision_tower.vision_model.encoder.layers.5.mlp.fc1.weight": "model-00001-of-00004.safetensors",
550
+ "vision_tower.vision_model.encoder.layers.5.mlp.fc2.bias": "model-00001-of-00004.safetensors",
551
+ "vision_tower.vision_model.encoder.layers.5.mlp.fc2.weight": "model-00001-of-00004.safetensors",
552
+ "vision_tower.vision_model.encoder.layers.5.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
553
+ "vision_tower.vision_model.encoder.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
554
+ "vision_tower.vision_model.encoder.layers.5.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
555
+ "vision_tower.vision_model.encoder.layers.5.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
556
+ "vision_tower.vision_model.encoder.layers.5.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
557
+ "vision_tower.vision_model.encoder.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
558
+ "vision_tower.vision_model.encoder.layers.5.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
559
+ "vision_tower.vision_model.encoder.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
560
+ "vision_tower.vision_model.encoder.layers.6.layer_norm1.bias": "model-00001-of-00004.safetensors",
561
+ "vision_tower.vision_model.encoder.layers.6.layer_norm1.weight": "model-00001-of-00004.safetensors",
562
+ "vision_tower.vision_model.encoder.layers.6.layer_norm2.bias": "model-00001-of-00004.safetensors",
563
+ "vision_tower.vision_model.encoder.layers.6.layer_norm2.weight": "model-00001-of-00004.safetensors",
564
+ "vision_tower.vision_model.encoder.layers.6.mlp.fc1.bias": "model-00001-of-00004.safetensors",
565
+ "vision_tower.vision_model.encoder.layers.6.mlp.fc1.weight": "model-00001-of-00004.safetensors",
566
+ "vision_tower.vision_model.encoder.layers.6.mlp.fc2.bias": "model-00001-of-00004.safetensors",
567
+ "vision_tower.vision_model.encoder.layers.6.mlp.fc2.weight": "model-00001-of-00004.safetensors",
568
+ "vision_tower.vision_model.encoder.layers.6.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
569
+ "vision_tower.vision_model.encoder.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
570
+ "vision_tower.vision_model.encoder.layers.6.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
571
+ "vision_tower.vision_model.encoder.layers.6.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
572
+ "vision_tower.vision_model.encoder.layers.6.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
573
+ "vision_tower.vision_model.encoder.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
574
+ "vision_tower.vision_model.encoder.layers.6.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
575
+ "vision_tower.vision_model.encoder.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
576
+ "vision_tower.vision_model.encoder.layers.7.layer_norm1.bias": "model-00001-of-00004.safetensors",
577
+ "vision_tower.vision_model.encoder.layers.7.layer_norm1.weight": "model-00001-of-00004.safetensors",
578
+ "vision_tower.vision_model.encoder.layers.7.layer_norm2.bias": "model-00001-of-00004.safetensors",
579
+ "vision_tower.vision_model.encoder.layers.7.layer_norm2.weight": "model-00001-of-00004.safetensors",
580
+ "vision_tower.vision_model.encoder.layers.7.mlp.fc1.bias": "model-00001-of-00004.safetensors",
581
+ "vision_tower.vision_model.encoder.layers.7.mlp.fc1.weight": "model-00001-of-00004.safetensors",
582
+ "vision_tower.vision_model.encoder.layers.7.mlp.fc2.bias": "model-00001-of-00004.safetensors",
583
+ "vision_tower.vision_model.encoder.layers.7.mlp.fc2.weight": "model-00001-of-00004.safetensors",
584
+ "vision_tower.vision_model.encoder.layers.7.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
585
+ "vision_tower.vision_model.encoder.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
586
+ "vision_tower.vision_model.encoder.layers.7.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
587
+ "vision_tower.vision_model.encoder.layers.7.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
588
+ "vision_tower.vision_model.encoder.layers.7.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
589
+ "vision_tower.vision_model.encoder.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
590
+ "vision_tower.vision_model.encoder.layers.7.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
591
+ "vision_tower.vision_model.encoder.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
592
+ "vision_tower.vision_model.encoder.layers.8.layer_norm1.bias": "model-00001-of-00004.safetensors",
593
+ "vision_tower.vision_model.encoder.layers.8.layer_norm1.weight": "model-00001-of-00004.safetensors",
594
+ "vision_tower.vision_model.encoder.layers.8.layer_norm2.bias": "model-00001-of-00004.safetensors",
595
+ "vision_tower.vision_model.encoder.layers.8.layer_norm2.weight": "model-00001-of-00004.safetensors",
596
+ "vision_tower.vision_model.encoder.layers.8.mlp.fc1.bias": "model-00001-of-00004.safetensors",
597
+ "vision_tower.vision_model.encoder.layers.8.mlp.fc1.weight": "model-00001-of-00004.safetensors",
598
+ "vision_tower.vision_model.encoder.layers.8.mlp.fc2.bias": "model-00001-of-00004.safetensors",
599
+ "vision_tower.vision_model.encoder.layers.8.mlp.fc2.weight": "model-00001-of-00004.safetensors",
600
+ "vision_tower.vision_model.encoder.layers.8.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
601
+ "vision_tower.vision_model.encoder.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
602
+ "vision_tower.vision_model.encoder.layers.8.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
603
+ "vision_tower.vision_model.encoder.layers.8.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
604
+ "vision_tower.vision_model.encoder.layers.8.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
605
+ "vision_tower.vision_model.encoder.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
606
+ "vision_tower.vision_model.encoder.layers.8.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
607
+ "vision_tower.vision_model.encoder.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
608
+ "vision_tower.vision_model.encoder.layers.9.layer_norm1.bias": "model-00001-of-00004.safetensors",
609
+ "vision_tower.vision_model.encoder.layers.9.layer_norm1.weight": "model-00001-of-00004.safetensors",
610
+ "vision_tower.vision_model.encoder.layers.9.layer_norm2.bias": "model-00001-of-00004.safetensors",
611
+ "vision_tower.vision_model.encoder.layers.9.layer_norm2.weight": "model-00001-of-00004.safetensors",
612
+ "vision_tower.vision_model.encoder.layers.9.mlp.fc1.bias": "model-00001-of-00004.safetensors",
613
+ "vision_tower.vision_model.encoder.layers.9.mlp.fc1.weight": "model-00001-of-00004.safetensors",
614
+ "vision_tower.vision_model.encoder.layers.9.mlp.fc2.bias": "model-00001-of-00004.safetensors",
615
+ "vision_tower.vision_model.encoder.layers.9.mlp.fc2.weight": "model-00001-of-00004.safetensors",
616
+ "vision_tower.vision_model.encoder.layers.9.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
617
+ "vision_tower.vision_model.encoder.layers.9.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
618
+ "vision_tower.vision_model.encoder.layers.9.self_attn.out_proj.bias": "model-00001-of-00004.safetensors",
619
+ "vision_tower.vision_model.encoder.layers.9.self_attn.out_proj.weight": "model-00001-of-00004.safetensors",
620
+ "vision_tower.vision_model.encoder.layers.9.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
621
+ "vision_tower.vision_model.encoder.layers.9.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
622
+ "vision_tower.vision_model.encoder.layers.9.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
623
+ "vision_tower.vision_model.encoder.layers.9.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
624
+ "vision_tower.vision_model.post_layernorm.bias": "model-00001-of-00004.safetensors",
625
+ "vision_tower.vision_model.post_layernorm.weight": "model-00001-of-00004.safetensors",
626
+ "vision_tower.vision_model.pre_layrnorm.bias": "model-00001-of-00004.safetensors",
627
+ "vision_tower.vision_model.pre_layrnorm.weight": "model-00001-of-00004.safetensors"
628
+ }
629
+ }
model_weight/modeling_internlm2.py ADDED
@@ -0,0 +1,1899 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
2
+ #
3
+ # This code is based on transformers/src/transformers/models/llama/modeling_llama.py
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ """PyTorch InternLM2.5 model."""
17
+ import math
18
+ import queue
19
+ import threading
20
+ from typing import List, Optional, Tuple, Union
21
+
22
+ import torch
23
+ import torch.nn.functional as F
24
+ import torch.utils.checkpoint
25
+ from einops import rearrange
26
+ from torch import nn
27
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
28
+ from transformers.activations import ACT2FN
29
+ from transformers.cache_utils import Cache, DynamicCache, StaticCache
30
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
31
+ from transformers.modeling_outputs import (BaseModelOutputWithPast,
32
+ CausalLMOutputWithPast,
33
+ QuestionAnsweringModelOutput,
34
+ SequenceClassifierOutputWithPast,
35
+ TokenClassifierOutput)
36
+ from transformers.modeling_utils import PreTrainedModel
37
+ from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS
38
+ from transformers.utils import (add_start_docstrings,
39
+ add_start_docstrings_to_model_forward,
40
+ is_flash_attn_greater_or_equal_2_10, logging,
41
+ replace_return_docstrings)
42
+
43
+ try:
44
+ from transformers.generation.streamers import BaseStreamer
45
+ except Exception:
46
+ BaseStreamer = None
47
+
48
+ from .configuration_internlm2 import InternLM2Config
49
+
50
+ try:
51
+ from flash_attn import flash_attn_func, flash_attn_varlen_func
52
+ from flash_attn.bert_padding import (index_first_axis, pad_input,
53
+ unpad_input)
54
+ except:
55
+ pass
56
+
57
+ logger = logging.get_logger(__name__)
58
+
59
+ _CONFIG_FOR_DOC = 'InternLM2Config'
60
+
61
+
62
+ def _get_unpad_data(attention_mask):
63
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
64
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
65
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
66
+ cu_seqlens = F.pad(
67
+ torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0)) # pylint: disable=E1102
68
+ return (
69
+ indices,
70
+ cu_seqlens,
71
+ max_seqlen_in_batch,
72
+ )
73
+
74
+
75
+ class InternLM2RMSNorm(nn.Module):
76
+ """InternLM2RMSNorm is equivalent to T5LayerNorm."""
77
+
78
+ def __init__(self, hidden_size, eps=1e-6):
79
+ super().__init__()
80
+ self.weight = nn.Parameter(torch.ones(hidden_size))
81
+ self.variance_epsilon = eps
82
+
83
+ def forward(self, hidden_states):
84
+ input_dtype = hidden_states.dtype
85
+ hidden_states = hidden_states.to(torch.float32)
86
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
87
+ hidden_states = hidden_states * torch.rsqrt(variance +
88
+ self.variance_epsilon)
89
+ return self.weight * hidden_states.to(input_dtype)
90
+
91
+
92
+ ALL_LAYERNORM_LAYERS.append(InternLM2RMSNorm)
93
+
94
+
95
+ class InternLM2RotaryEmbedding(nn.Module):
96
+ """Rotary Position Embedding for the InternLM2 model. Credits to the Reddit user /u/lucidrains."""
97
+
98
+ def __init__(self,
99
+ dim,
100
+ max_position_embeddings=2048,
101
+ base=10000,
102
+ device=None,
103
+ scaling_factor=1.0):
104
+ super().__init__()
105
+ self.scaling_factor = scaling_factor
106
+ self.dim = dim
107
+ self.max_position_embeddings = max_position_embeddings
108
+ self.base = base
109
+ inv_freq = 1.0 / (
110
+ self.base
111
+ **(torch.arange(0, self.dim, 2,
112
+ dtype=torch.int64).float().to(device) / self.dim))
113
+ self.register_buffer('inv_freq', inv_freq, persistent=False)
114
+ # For BC we register cos and sin cached
115
+ self.max_seq_len_cached = max_position_embeddings
116
+
117
+ @torch.no_grad()
118
+ def forward(self, x, position_ids):
119
+ # x: [bs, num_attention_heads, seq_len, head_size]
120
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(
121
+ position_ids.shape[0], -1, 1)
122
+ position_ids_expanded = position_ids[:, None, :].float()
123
+ # Force float32 since bfloat16 loses precision on long contexts
124
+ # See https://github.com/huggingface/transformers/pull/29285
125
+ device_type = x.device.type
126
+ device_type = device_type if isinstance(
127
+ device_type, str) and device_type != 'mps' else 'cpu'
128
+ with torch.autocast(device_type=device_type, enabled=False):
129
+ freqs = (inv_freq_expanded.float()
130
+ @ position_ids_expanded.float()).transpose(1, 2)
131
+ emb = torch.cat((freqs, freqs), dim=-1)
132
+ cos = emb.cos()
133
+ sin = emb.sin()
134
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
135
+
136
+
137
+ class InternLM2LinearScalingRotaryEmbedding(InternLM2RotaryEmbedding):
138
+ """InternLM2RotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
139
+
140
+ def forward(self, x, position_ids):
141
+ # difference to the original RoPE: a scaling factor is aplied to the position ids
142
+ position_ids = position_ids.float() / self.scaling_factor
143
+ cos, sin = super().forward(x, position_ids)
144
+ return cos, sin
145
+
146
+
147
+ class InternLM2DynamicNTKScalingRotaryEmbedding(InternLM2RotaryEmbedding):
148
+ """InternLM2RotaryEmbedding extended with Dynamic NTK scaling.
149
+ Credits to the Reddit users /u/bloc97 and /u/emozilla"""
150
+
151
+ def forward(self, x, position_ids):
152
+ # difference to the original RoPE: inv_freq is recomputed when the sequence length > original length
153
+ seq_len = torch.max(position_ids) + 1
154
+ if seq_len > self.max_position_embeddings:
155
+ base = self.base * ((self.scaling_factor * seq_len /
156
+ self.max_position_embeddings) -
157
+ (self.scaling_factor - 1))**(
158
+ self.dim / (self.dim - 2))
159
+ inv_freq = 1.0 / (
160
+ base
161
+ **(torch.arange(0, self.dim, 2, dtype=torch.int64).float().to(
162
+ x.device) / self.dim))
163
+ self.register_buffer(
164
+ 'inv_freq', inv_freq,
165
+ persistent=False) # TODO joao: this may break with compilation
166
+
167
+ cos, sin = super().forward(x, position_ids)
168
+ return cos, sin
169
+
170
+
171
+ def rotate_half(x):
172
+ """Rotates half the hidden dims of the input."""
173
+ x1 = x[..., :x.shape[-1] // 2]
174
+ x2 = x[..., x.shape[-1] // 2:]
175
+ return torch.cat((-x2, x1), dim=-1)
176
+
177
+
178
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1): # pylint: disable=unused-argument
179
+ """Applies Rotary Position Embedding to the query and key tensors.
180
+ Args:
181
+ q (`torch.Tensor`): The query tensor.
182
+ k (`torch.Tensor`): The key tensor.
183
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
184
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
185
+ position_ids (`torch.Tensor`, *optional*):
186
+ Deprecated and unused.
187
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
188
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
189
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
190
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
191
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
192
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
193
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
194
+ Returns:
195
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
196
+ """
197
+ cos = cos.unsqueeze(unsqueeze_dim)
198
+ sin = sin.unsqueeze(unsqueeze_dim)
199
+ q_embed = (q * cos) + (rotate_half(q) * sin)
200
+ k_embed = (k * cos) + (rotate_half(k) * sin)
201
+ return q_embed, k_embed
202
+
203
+
204
+ class InternLM2MLP(nn.Module):
205
+ """MLP for InternLM2 model."""
206
+
207
+ def __init__(self, config):
208
+ super().__init__()
209
+ self.config = config
210
+ self.hidden_size = config.hidden_size
211
+ self.intermediate_size = config.intermediate_size
212
+ self.w1 = nn.Linear(
213
+ self.hidden_size, self.intermediate_size, bias=False)
214
+ self.w3 = nn.Linear(
215
+ self.hidden_size, self.intermediate_size, bias=False)
216
+ self.w2 = nn.Linear(
217
+ self.intermediate_size, self.hidden_size, bias=False)
218
+ self.act_fn = ACT2FN[config.hidden_act]
219
+
220
+ def forward(self, x):
221
+ down_proj = self.w2(self.act_fn(self.w1(x)) * self.w3(x))
222
+
223
+ return down_proj
224
+
225
+
226
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
227
+ """
228
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
229
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
230
+ """
231
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
232
+ if n_rep == 1:
233
+ return hidden_states
234
+ hidden_states = hidden_states[:, :,
235
+ None, :, :].expand(batch,
236
+ num_key_value_heads,
237
+ n_rep, slen, head_dim)
238
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen,
239
+ head_dim)
240
+
241
+
242
+ class InternLM2Attention(nn.Module):
243
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
244
+
245
+ def __init__(self,
246
+ config: InternLM2Config,
247
+ layer_idx: Optional[int] = None):
248
+ super().__init__()
249
+ self.config = config
250
+ self.layer_idx = layer_idx
251
+ if layer_idx is None:
252
+ logger.warning_once(
253
+ f'Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will '
254
+ 'lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` '
255
+ 'when creating this class.')
256
+
257
+ self.hidden_size = config.hidden_size
258
+ self.num_heads = config.num_attention_heads
259
+ self.head_dim = self.hidden_size // self.num_heads
260
+ self.num_key_value_heads = config.num_key_value_heads
261
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
262
+ self.max_position_embeddings = config.max_position_embeddings
263
+ self.rope_theta = config.rope_theta
264
+ self.is_causal = True
265
+
266
+ if (self.head_dim * self.num_heads) != self.hidden_size:
267
+ raise ValueError(
268
+ f'hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}'
269
+ f' and `num_heads`: {self.num_heads}).')
270
+
271
+ self.wqkv = nn.Linear(
272
+ self.hidden_size,
273
+ (self.num_heads + 2 * self.num_key_value_heads) * self.head_dim,
274
+ bias=config.bias,
275
+ )
276
+ self.wo = nn.Linear(
277
+ self.num_heads * self.head_dim, self.hidden_size, bias=config.bias)
278
+
279
+ self._init_rope()
280
+
281
+ def _init_rope(self):
282
+ if self.config.rope_scaling is None:
283
+ self.rotary_emb = InternLM2RotaryEmbedding(
284
+ self.head_dim,
285
+ max_position_embeddings=self.max_position_embeddings,
286
+ base=self.rope_theta,
287
+ )
288
+ else:
289
+ scaling_type = self.config.rope_scaling['type']
290
+ scaling_factor = self.config.rope_scaling['factor']
291
+ if scaling_type == 'linear':
292
+ self.rotary_emb = InternLM2LinearScalingRotaryEmbedding(
293
+ self.head_dim,
294
+ max_position_embeddings=self.max_position_embeddings,
295
+ scaling_factor=scaling_factor,
296
+ base=self.rope_theta,
297
+ )
298
+ elif scaling_type == 'dynamic':
299
+ self.rotary_emb = InternLM2DynamicNTKScalingRotaryEmbedding(
300
+ self.head_dim,
301
+ max_position_embeddings=self.max_position_embeddings,
302
+ scaling_factor=scaling_factor,
303
+ base=self.rope_theta,
304
+ )
305
+ else:
306
+ raise ValueError(f'Unknown RoPE scaling type {scaling_type}')
307
+
308
+ def forward(
309
+ self,
310
+ hidden_states: torch.Tensor,
311
+ attention_mask: Optional[torch.Tensor] = None,
312
+ position_ids: Optional[torch.LongTensor] = None,
313
+ past_key_value: Optional[Cache] = None,
314
+ output_attentions: bool = False,
315
+ use_cache: bool = False, # pylint: disable=unused-argument
316
+ cache_position: Optional[torch.LongTensor] = None,
317
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor],
318
+ Optional[Tuple[torch.Tensor]]]:
319
+ bsz, q_len, _ = hidden_states.size()
320
+
321
+ if self.config.pretraining_tp > 1:
322
+ # split qkv_states by tp size
323
+ key_value_slicing = (self.num_key_value_heads *
324
+ self.head_dim) // self.config.pretraining_tp
325
+ qkv_slices = self.wqkv.weight.split(key_value_slicing, dim=0)
326
+ qkv_states = torch.cat(
327
+ [
328
+ F.linear(hidden_states, qkv_slice)
329
+ for qkv_slice in qkv_slices
330
+ ],
331
+ dim=-1 # pylint: disable=E1102
332
+ )
333
+ else:
334
+ qkv_states = self.wqkv(hidden_states)
335
+
336
+ qkv_states = rearrange(
337
+ qkv_states,
338
+ 'b q (h gs d) -> b q h gs d',
339
+ gs=2 + self.num_key_value_groups,
340
+ d=self.head_dim,
341
+ )
342
+
343
+ query_states = qkv_states[..., :self.num_key_value_groups, :]
344
+ query_states = rearrange(query_states,
345
+ 'b q h gs d -> b q (h gs) d').transpose(1, 2)
346
+ key_states = qkv_states[..., -2, :].transpose(1, 2)
347
+ value_states = qkv_states[..., -1, :].transpose(1, 2)
348
+
349
+ cos, sin = self.rotary_emb(value_states, position_ids)
350
+ query_states, key_states = apply_rotary_pos_emb(
351
+ query_states, key_states, cos, sin, position_ids)
352
+
353
+ if past_key_value is not None:
354
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
355
+ cache_kwargs = {
356
+ 'sin': sin,
357
+ 'cos': cos,
358
+ 'cache_position': cache_position
359
+ }
360
+ key_states, value_states = past_key_value.update(
361
+ key_states, value_states, self.layer_idx, cache_kwargs)
362
+
363
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
364
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
365
+
366
+ attn_weights = torch.matmul(query_states, key_states.transpose(
367
+ 2, 3)) / math.sqrt(self.head_dim)
368
+
369
+ if attention_mask is not None: # no matter the length, we just slice it
370
+ causal_mask = attention_mask[:, :, :, :key_states.shape[-2]]
371
+ attn_weights = attn_weights + causal_mask
372
+
373
+ # upcast attention to fp32
374
+ attn_weights = nn.functional.softmax(
375
+ attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
376
+ attn_output = torch.matmul(attn_weights, value_states)
377
+
378
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
379
+ raise ValueError(
380
+ f'`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is'
381
+ f' {attn_output.size()}')
382
+
383
+ attn_output = attn_output.transpose(1, 2).contiguous()
384
+
385
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
386
+
387
+ if self.config.pretraining_tp > 1:
388
+ attn_output = attn_output.split(
389
+ self.hidden_size // self.config.pretraining_tp, dim=2)
390
+ o_proj_slices = self.wo.weight.split(
391
+ self.hidden_size // self.config.pretraining_tp, dim=1)
392
+ attn_output = sum([
393
+ F.linear(attn_output[i], o_proj_slices[i]) # pylint: disable=E1102
394
+ for i in range(self.config.pretraining_tp)
395
+ ])
396
+ else:
397
+ attn_output = self.wo(attn_output)
398
+
399
+ if not output_attentions:
400
+ attn_weights = None
401
+
402
+ return attn_output, attn_weights, past_key_value
403
+
404
+
405
+ class InternLM2FlashAttention2(InternLM2Attention):
406
+ """
407
+ InternLM2 flash attention module. This module inherits from `InternLM2Attention` as the weights of the module stays
408
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
409
+ flash attention and deal with padding tokens in case the input contains any of them.
410
+ """
411
+
412
+ def __init__(self, *args, **kwargs):
413
+ super().__init__(*args, **kwargs)
414
+
415
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
416
+ # flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement,
417
+ # that was made default for flash_attn>=2.1. This attribute is used to handle this difference.
418
+ # Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
419
+ # Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1)
420
+ # produces a wrong mask (top-left).
421
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10(
422
+ )
423
+
424
+ def forward(
425
+ self,
426
+ hidden_states: torch.Tensor,
427
+ attention_mask: Optional[torch.LongTensor] = None,
428
+ position_ids: Optional[torch.LongTensor] = None,
429
+ past_key_value: Optional[Cache] = None,
430
+ output_attentions: bool = False,
431
+ use_cache: bool = False,
432
+ cache_position: Optional[torch.LongTensor] = None,
433
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor],
434
+ Optional[Tuple[torch.Tensor]]]:
435
+ if isinstance(past_key_value, StaticCache):
436
+ raise ValueError(
437
+ '`static` cache implementation is not compatible with `attn_implementation==flash_attention_2` '
438
+ 'make sure to use `sdpa` in the mean time, and open an issue at '
439
+ 'https://github.com/huggingface/transformers')
440
+
441
+ output_attentions = False
442
+
443
+ bsz, q_len, _ = hidden_states.size()
444
+
445
+ qkv_states = self.wqkv(hidden_states)
446
+
447
+ qkv_states = rearrange(
448
+ qkv_states,
449
+ 'b q (h gs d) -> b q h gs d',
450
+ gs=2 + self.num_key_value_groups,
451
+ d=self.head_dim,
452
+ )
453
+
454
+ query_states = qkv_states[..., :self.num_key_value_groups, :]
455
+ query_states = rearrange(query_states, 'b q h gs d -> b q (h gs) d')
456
+ key_states = qkv_states[..., -2, :]
457
+ value_states = qkv_states[..., -1, :]
458
+
459
+ query_states = query_states.transpose(1, 2)
460
+ key_states = key_states.transpose(1, 2)
461
+ value_states = value_states.transpose(1, 2)
462
+
463
+ cos, sin = self.rotary_emb(value_states, position_ids)
464
+ query_states, key_states = apply_rotary_pos_emb(
465
+ query_states, key_states, cos, sin)
466
+
467
+ if past_key_value is not None:
468
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
469
+ cache_kwargs = {
470
+ 'sin': sin,
471
+ 'cos': cos,
472
+ 'cache_position': cache_position
473
+ }
474
+ key_states, value_states = past_key_value.update(
475
+ key_states, value_states, self.layer_idx, cache_kwargs)
476
+
477
+ # TODO: These transpose are quite inefficient but Flash Attention requires the layout
478
+ # [batch_size, sequence_length, num_heads, head_dim]. We would need to refactor the KV cache
479
+ # to be able to avoid many of these transpose/reshape/view.
480
+ query_states = query_states.transpose(1, 2)
481
+ key_states = key_states.transpose(1, 2)
482
+ value_states = value_states.transpose(1, 2)
483
+
484
+ # dropout_rate = self.attention_dropout if self.training else 0.0
485
+ dropout_rate = 0.0
486
+
487
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
488
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
489
+ # cast them back in the correct dtype just to be sure everything works as expected.
490
+ # This might slowdown training & inference so it is recommended to not cast the LayerNorms
491
+ # in fp32. (InternLM2RMSNorm handles it correctly)
492
+
493
+ input_dtype = query_states.dtype
494
+ if input_dtype == torch.float32:
495
+ if torch.is_autocast_enabled():
496
+ target_dtype = torch.get_autocast_gpu_dtype()
497
+ # Handle the case where the model is quantized
498
+ elif hasattr(self.config, '_pre_quantization_dtype'):
499
+ target_dtype = self.config._pre_quantization_dtype
500
+ else:
501
+ target_dtype = self.wqkv.weight.dtype
502
+
503
+ logger.warning_once(
504
+ f'The input hidden states seems to be silently casted in float32, this might be related to'
505
+ f' the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in'
506
+ f' {target_dtype}.')
507
+
508
+ query_states = query_states.to(target_dtype)
509
+ key_states = key_states.to(target_dtype)
510
+ value_states = value_states.to(target_dtype)
511
+
512
+ attn_output = self._flash_attention_forward(
513
+ query_states,
514
+ key_states,
515
+ value_states,
516
+ attention_mask,
517
+ q_len,
518
+ dropout=dropout_rate)
519
+
520
+ attn_output = attn_output.reshape(bsz, q_len,
521
+ self.hidden_size).contiguous()
522
+ attn_output = self.wo(attn_output)
523
+
524
+ if not output_attentions:
525
+ attn_weights = None
526
+
527
+ return attn_output, attn_weights, past_key_value # pylint: disable=E0606
528
+
529
+ def _flash_attention_forward(self,
530
+ query_states,
531
+ key_states,
532
+ value_states,
533
+ attention_mask,
534
+ query_length,
535
+ dropout=0.0,
536
+ softmax_scale=None):
537
+ """
538
+ Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
539
+ first unpad the input, then computes the attention scores and pad the final attention scores.
540
+ Args:
541
+ query_states (`torch.Tensor`):
542
+ Input query states to be passed to Flash Attention API
543
+ key_states (`torch.Tensor`):
544
+ Input key states to be passed to Flash Attention API
545
+ value_states (`torch.Tensor`):
546
+ Input value states to be passed to Flash Attention API
547
+ attention_mask (`torch.Tensor`):
548
+ The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
549
+ position of padding tokens and 1 for the position of non-padding tokens.
550
+ dropout (`float`):
551
+ Attention dropout
552
+ softmax_scale (`float`, *optional*):
553
+ The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
554
+ """
555
+ if not self._flash_attn_uses_top_left_mask:
556
+ causal = self.is_causal
557
+ else:
558
+ # TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1.
559
+ # For details, please see the comment in InternLM2FlashAttention2 __init__.
560
+ causal = self.is_causal and query_length != 1
561
+
562
+ # Contains at least one padding token in the sequence
563
+ if attention_mask is not None:
564
+ batch_size = query_states.shape[0]
565
+ query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
566
+ query_states, key_states, value_states, attention_mask,
567
+ query_length)
568
+
569
+ cu_seqlens_q, cu_seqlens_k = cu_seq_lens
570
+ max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
571
+
572
+ attn_output_unpad = flash_attn_varlen_func( # pylint: disable=E0606
573
+ query_states,
574
+ key_states,
575
+ value_states,
576
+ cu_seqlens_q=cu_seqlens_q,
577
+ cu_seqlens_k=cu_seqlens_k,
578
+ max_seqlen_q=max_seqlen_in_batch_q,
579
+ max_seqlen_k=max_seqlen_in_batch_k,
580
+ dropout_p=dropout,
581
+ softmax_scale=softmax_scale,
582
+ causal=causal,
583
+ )
584
+
585
+ attn_output = pad_input(attn_output_unpad, indices_q, batch_size,
586
+ query_length) # pylint: disable=E0606
587
+ else:
588
+ attn_output = flash_attn_func( # pylint: disable=E0606
589
+ query_states,
590
+ key_states,
591
+ value_states,
592
+ dropout,
593
+ softmax_scale=softmax_scale,
594
+ causal=causal)
595
+
596
+ return attn_output
597
+
598
+ def _upad_input(self, query_layer, key_layer, value_layer, attention_mask,
599
+ query_length):
600
+ indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(
601
+ attention_mask)
602
+ batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
603
+
604
+ key_layer = index_first_axis( # pylint: disable=E0606
605
+ key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads,
606
+ head_dim), indices_k)
607
+ value_layer = index_first_axis( # pylint: disable=E0606
608
+ value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads,
609
+ head_dim), indices_k)
610
+ if query_length == kv_seq_len:
611
+ query_layer = index_first_axis( # pylint: disable=E0606
612
+ query_layer.reshape(batch_size * kv_seq_len, self.num_heads,
613
+ head_dim), indices_k)
614
+ cu_seqlens_q = cu_seqlens_k
615
+ max_seqlen_in_batch_q = max_seqlen_in_batch_k
616
+ indices_q = indices_k
617
+ elif query_length == 1:
618
+ max_seqlen_in_batch_q = 1
619
+ cu_seqlens_q = torch.arange(
620
+ batch_size + 1, dtype=torch.int32, device=query_layer.device
621
+ ) # There is a memcpy here, that is very bad.
622
+ indices_q = cu_seqlens_q[:-1]
623
+ query_layer = query_layer.squeeze(1)
624
+ else:
625
+ # The -q_len: slice assumes left padding.
626
+ attention_mask = attention_mask[:, -query_length:]
627
+ query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input( # pylint: disable=E0606
628
+ query_layer, attention_mask)
629
+
630
+ return (
631
+ query_layer,
632
+ key_layer,
633
+ value_layer,
634
+ indices_q,
635
+ (cu_seqlens_q, cu_seqlens_k),
636
+ (max_seqlen_in_batch_q, max_seqlen_in_batch_k),
637
+ )
638
+
639
+
640
+ # Copied from transformers.models.llama.modeling_llama.LllamaSdpaAttention with Llama->InternLM2
641
+ class InternLM2SdpaAttention(InternLM2Attention):
642
+ """
643
+ InternLM2 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
644
+ `InternLM2Attention` as the weights of the module stays untouched. The only changes are on the forward pass
645
+ to adapt to SDPA API.
646
+ """
647
+
648
+ # Adapted from InternLM2Attention.forward
649
+ def forward(
650
+ self,
651
+ hidden_states: torch.Tensor,
652
+ attention_mask: Optional[torch.Tensor] = None,
653
+ position_ids: Optional[torch.LongTensor] = None,
654
+ past_key_value: Optional[Cache] = None,
655
+ output_attentions: bool = False,
656
+ use_cache: bool = False,
657
+ cache_position: Optional[torch.LongTensor] = None,
658
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor],
659
+ Optional[Tuple[torch.Tensor]]]:
660
+ if output_attentions:
661
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"`
662
+ # once this is implemented.
663
+ logger.warning_once(
664
+ 'InternLM2Model uses InternLM2SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` '
665
+ 'does not support `output_attentions=True`. Falling back to the manual attention implementation, '
666
+ 'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. '
667
+ 'This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
668
+ )
669
+ return super().forward(
670
+ hidden_states=hidden_states,
671
+ attention_mask=attention_mask,
672
+ position_ids=position_ids,
673
+ past_key_value=past_key_value,
674
+ output_attentions=output_attentions,
675
+ use_cache=use_cache,
676
+ cache_position=cache_position,
677
+ )
678
+
679
+ bsz, q_len, _ = hidden_states.size()
680
+
681
+ qkv_states = self.wqkv(hidden_states)
682
+
683
+ qkv_states = rearrange(
684
+ qkv_states,
685
+ 'b q (h gs d) -> b q h gs d',
686
+ gs=2 + self.num_key_value_groups,
687
+ d=self.head_dim,
688
+ )
689
+
690
+ query_states = qkv_states[..., :self.num_key_value_groups, :]
691
+ query_states = rearrange(query_states, 'b q h gs d -> b q (h gs) d')
692
+ key_states = qkv_states[..., -2, :]
693
+ value_states = qkv_states[..., -1, :]
694
+
695
+ query_states = query_states.transpose(1, 2)
696
+ key_states = key_states.transpose(1, 2)
697
+ value_states = value_states.transpose(1, 2)
698
+
699
+ cos, sin = self.rotary_emb(value_states, position_ids)
700
+ query_states, key_states = apply_rotary_pos_emb(
701
+ query_states, key_states, cos, sin)
702
+
703
+ if past_key_value is not None:
704
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
705
+ cache_kwargs = {
706
+ 'sin': sin,
707
+ 'cos': cos,
708
+ 'cache_position': cache_position
709
+ }
710
+ key_states, value_states = past_key_value.update(
711
+ key_states, value_states, self.layer_idx, cache_kwargs)
712
+
713
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
714
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
715
+
716
+ causal_mask = attention_mask
717
+ if attention_mask is not None:
718
+ causal_mask = causal_mask[:, :, :, :key_states.shape[-2]]
719
+
720
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with
721
+ # custom attn_mask, Reference: https://github.com/pytorch/pytorch/issues/112577.
722
+ if query_states.device.type == 'cuda' and causal_mask is not None:
723
+ query_states = query_states.contiguous()
724
+ key_states = key_states.contiguous()
725
+ value_states = value_states.contiguous()
726
+
727
+ # We dispatch to SDPA's Flash Attention or Efficient kernels via this `is_causal` if statement instead of
728
+ # an inline conditional assignment in SDPA to support both torch.compile's dynamic shapes and full graph
729
+ # options. An inline conditional prevents dynamic shapes from compiling.
730
+ is_causal = bool(causal_mask is None and q_len > 1)
731
+
732
+ attn_output = torch.nn.functional.scaled_dot_product_attention( # pylint: disable=E1102
733
+ query_states,
734
+ key_states,
735
+ value_states,
736
+ attn_mask=causal_mask,
737
+ dropout_p=0.0,
738
+ is_causal=is_causal,
739
+ )
740
+
741
+ attn_output = attn_output.transpose(1, 2).contiguous()
742
+ attn_output = attn_output.view(bsz, q_len, self.hidden_size)
743
+
744
+ attn_output = self.wo(attn_output)
745
+
746
+ return attn_output, None, past_key_value
747
+
748
+
749
+ INTERNLM2_ATTENTION_CLASSES = {
750
+ 'eager': InternLM2Attention,
751
+ 'flash_attention_2': InternLM2FlashAttention2,
752
+ 'sdpa': InternLM2SdpaAttention,
753
+ }
754
+
755
+
756
+ # Modified from transformers.models.llama.modeling_llama.LlamaDecoderLayer with Llama->InternLM2
757
+ class InternLM2DecoderLayer(nn.Module):
758
+ """InternLM2 Decoder Layer. This module is a single layer of the InternLM2 model."""
759
+
760
+ def __init__(self, config: InternLM2Config, layer_idx: int):
761
+ super().__init__()
762
+ self.hidden_size = config.hidden_size
763
+ self.layer_idx = layer_idx
764
+
765
+ self.attention = INTERNLM2_ATTENTION_CLASSES[
766
+ config.attn_implementation](
767
+ config=config, layer_idx=layer_idx)
768
+
769
+ self.feed_forward = InternLM2MLP(config)
770
+ self.attention_norm = InternLM2RMSNorm(
771
+ config.hidden_size, eps=config.rms_norm_eps)
772
+ self.ffn_norm = InternLM2RMSNorm(
773
+ config.hidden_size, eps=config.rms_norm_eps)
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[Cache] = None,
781
+ output_attentions: Optional[bool] = False,
782
+ use_cache: Optional[bool] = False,
783
+ cache_position: Optional[torch.LongTensor] = None,
784
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor,
785
+ torch.FloatTensor]]]:
786
+ """
787
+ Args:
788
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
789
+ attention_mask (`torch.FloatTensor`, *optional*):
790
+ attention mask of size `(batch_size, sequence_length)` if flash attention is used or `(batch_size, 1,
791
+ query_sequence_length, key_sequence_length)` if default attention is used.
792
+ output_attentions (`bool`, *optional*):
793
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
794
+ returned tensors for more detail.
795
+ use_cache (`bool`, *optional*):
796
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
797
+ (see `past_key_values`).
798
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
799
+ """
800
+ residual = hidden_states
801
+
802
+ hidden_states = self.attention_norm(hidden_states)
803
+
804
+ # Self Attention
805
+ hidden_states, self_attn_weights, present_key_value = self.attention(
806
+ hidden_states=hidden_states,
807
+ attention_mask=attention_mask,
808
+ position_ids=position_ids,
809
+ past_key_value=past_key_value,
810
+ output_attentions=output_attentions,
811
+ use_cache=use_cache,
812
+ cache_position=cache_position,
813
+ )
814
+ hidden_states = residual + hidden_states
815
+
816
+ # Fully Connected
817
+ residual = hidden_states
818
+ hidden_states = self.ffn_norm(hidden_states)
819
+ hidden_states = self.feed_forward(hidden_states)
820
+ hidden_states = residual + hidden_states
821
+
822
+ outputs = (hidden_states, )
823
+
824
+ if output_attentions:
825
+ outputs += (self_attn_weights, )
826
+
827
+ if use_cache:
828
+ outputs += (present_key_value, )
829
+
830
+ return outputs
831
+
832
+
833
+ InternLM2_START_DOCSTRING = r"""
834
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
835
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
836
+ etc.)
837
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
838
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
839
+ and behavior.
840
+ Parameters:
841
+ config ([`InternLM2Config`]):
842
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
843
+ load the weights associated with the model, only the configuration. Check out the
844
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
845
+ """
846
+
847
+
848
+ # Copied from transformers.models.llama.modeling_llama.LlamaPreTrainedModel with Llama->InternLM2
849
+ @add_start_docstrings(
850
+ 'The bare InternLM2 Model outputting raw hidden-states without any specific head on top.',
851
+ InternLM2_START_DOCSTRING,
852
+ )
853
+ class InternLM2PreTrainedModel(PreTrainedModel):
854
+ """
855
+ InternLM2 pretraiend model's base class.
856
+ """
857
+
858
+ config_class = InternLM2Config
859
+ base_model_prefix = 'model'
860
+ supports_gradient_checkpointing = True
861
+ _no_split_modules = ['InternLM2DecoderLayer']
862
+ _skip_keys_device_placement = ['past_key_values']
863
+ _supports_flash_attn_2 = True
864
+ _supports_sdpa = True
865
+ _supports_cache_class = True
866
+ _supports_quantized_cache = True
867
+ _supports_static_cache = True
868
+
869
+ def _init_weights(self, module):
870
+ std = self.config.initializer_range
871
+ if isinstance(module, nn.Linear):
872
+ module.weight.data.normal_(mean=0.0, std=std)
873
+ if module.bias is not None:
874
+ module.bias.data.zero_()
875
+ elif isinstance(module, nn.Embedding):
876
+ module.weight.data.normal_(mean=0.0, std=std)
877
+ if module.padding_idx is not None:
878
+ module.weight.data[module.padding_idx].zero_()
879
+
880
+
881
+ InternLM2_INPUTS_DOCSTRING = r"""
882
+ Args:
883
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
884
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
885
+ it.
886
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
887
+ [`PreTrainedTokenizer.__call__`] for details.
888
+ [What are input IDs?](../glossary#input-ids)
889
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
890
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
891
+ - 1 for tokens that are **not masked**,
892
+ - 0 for tokens that are **masked**.
893
+ [What are attention masks?](../glossary#attention-mask)
894
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
895
+ [`PreTrainedTokenizer.__call__`] for details.
896
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
897
+ `past_key_values`).
898
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
899
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
900
+ information on the default strategy.
901
+ - 1 indicates the head is **not masked**,
902
+ - 0 indicates the head is **masked**.
903
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
904
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
905
+ config.n_positions - 1]`.
906
+ [What are position IDs?](../glossary#position-ids)
907
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
908
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
909
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
910
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
911
+ Two formats are allowed:
912
+ - a [`~cache_utils.Cache`] instance;
913
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
914
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
915
+ cache format.
916
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
917
+ legacy cache format will be returned.
918
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
919
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
920
+ of shape `(batch_size, sequence_length)`.
921
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
922
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
923
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
924
+ model's internal embedding lookup matrix.
925
+ use_cache (`bool`, *optional*):
926
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
927
+ `past_key_values`).
928
+ output_attentions (`bool`, *optional*):
929
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
930
+ tensors for more detail.
931
+ output_hidden_states (`bool`, *optional*):
932
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
933
+ more detail.
934
+ return_dict (`bool`, *optional*):
935
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
936
+ cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
937
+ Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
938
+ this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
939
+ the complete sequence length.
940
+ """
941
+
942
+
943
+ # Modified from transformers.models.llama.modeling_llama.LlamaModel with Llama->InternLM2
944
+ @add_start_docstrings(
945
+ 'The bare InternLM2 Model outputting raw hidden-states without any specific head on top.',
946
+ InternLM2_START_DOCSTRING,
947
+ )
948
+ class InternLM2Model(InternLM2PreTrainedModel):
949
+ """
950
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`InternLM2DecoderLayer`]
951
+ Args:
952
+ config: InternLM2Config
953
+ """
954
+
955
+ _auto_class = 'AutoModel'
956
+
957
+ def __init__(self, config: InternLM2Config):
958
+ super().__init__(config)
959
+ self.padding_idx = config.pad_token_id
960
+ self.vocab_size = config.vocab_size
961
+ self.config = config
962
+
963
+ self.tok_embeddings = nn.Embedding(config.vocab_size,
964
+ config.hidden_size,
965
+ self.padding_idx)
966
+
967
+ self.layers = nn.ModuleList([
968
+ InternLM2DecoderLayer(config, layer_idx)
969
+ for layer_idx in range(config.num_hidden_layers)
970
+ ])
971
+ self.norm = InternLM2RMSNorm(
972
+ config.hidden_size, eps=config.rms_norm_eps)
973
+
974
+ self.gradient_checkpointing = False
975
+ # Initialize weights and apply final processing
976
+ self.post_init()
977
+
978
+ def get_input_embeddings(self):
979
+ return self.tok_embeddings
980
+
981
+ def set_input_embeddings(self, value):
982
+ self.tok_embeddings = value
983
+
984
+ @add_start_docstrings_to_model_forward(InternLM2_INPUTS_DOCSTRING)
985
+ def forward(
986
+ self,
987
+ input_ids: torch.LongTensor = None,
988
+ attention_mask: Optional[torch.Tensor] = None,
989
+ position_ids: Optional[torch.LongTensor] = None,
990
+ past_key_values: Optional[Union[Cache,
991
+ List[torch.FloatTensor]]] = None,
992
+ inputs_embeds: Optional[torch.FloatTensor] = None,
993
+ use_cache: Optional[bool] = None,
994
+ output_attentions: Optional[bool] = None,
995
+ output_hidden_states: Optional[bool] = None,
996
+ return_dict: Optional[bool] = None,
997
+ cache_position: Optional[torch.LongTensor] = 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
1002
+ self.config.output_hidden_states)
1003
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
1004
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1005
+
1006
+ if (input_ids is None) ^ (inputs_embeds is not None):
1007
+ raise ValueError(
1008
+ 'You cannot specify both input_ids and inputs_embeds at the same time, and must specify either one'
1009
+ )
1010
+
1011
+ if self.gradient_checkpointing and self.training and use_cache:
1012
+ logger.warning_once(
1013
+ '`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`.'
1014
+ )
1015
+ use_cache = False
1016
+
1017
+ if inputs_embeds is None:
1018
+ inputs_embeds = self.tok_embeddings(input_ids)
1019
+
1020
+ return_legacy_cache = False
1021
+ if use_cache and not isinstance(
1022
+ past_key_values,
1023
+ Cache): # kept for BC (non `Cache` `past_key_values` inputs)
1024
+ return_legacy_cache = True
1025
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
1026
+
1027
+ if cache_position is None:
1028
+ past_seen_tokens = past_key_values.get_seq_length(
1029
+ ) if past_key_values is not None else 0
1030
+ cache_position = torch.arange(
1031
+ past_seen_tokens,
1032
+ past_seen_tokens + inputs_embeds.shape[1],
1033
+ device=inputs_embeds.device)
1034
+ if position_ids is None:
1035
+ position_ids = cache_position.unsqueeze(0)
1036
+
1037
+ causal_mask = self._update_causal_mask(attention_mask, inputs_embeds,
1038
+ cache_position, past_key_values,
1039
+ output_attentions)
1040
+
1041
+ # embed positions
1042
+ hidden_states = inputs_embeds
1043
+
1044
+ # decoder layers
1045
+ all_hidden_states = () if output_hidden_states else None
1046
+ all_self_attns = () if output_attentions else None
1047
+ next_decoder_cache = None
1048
+
1049
+ for decoder_layer in self.layers:
1050
+ if output_hidden_states:
1051
+ all_hidden_states += (hidden_states, )
1052
+
1053
+ if self.gradient_checkpointing and self.training:
1054
+ layer_outputs = self._gradient_checkpointing_func(
1055
+ decoder_layer.__call__,
1056
+ hidden_states,
1057
+ causal_mask,
1058
+ position_ids,
1059
+ past_key_values,
1060
+ output_attentions,
1061
+ use_cache,
1062
+ cache_position,
1063
+ )
1064
+ else:
1065
+ layer_outputs = decoder_layer(
1066
+ hidden_states,
1067
+ attention_mask=causal_mask,
1068
+ position_ids=position_ids,
1069
+ past_key_value=past_key_values,
1070
+ output_attentions=output_attentions,
1071
+ use_cache=use_cache,
1072
+ cache_position=cache_position,
1073
+ )
1074
+
1075
+ hidden_states = layer_outputs[0]
1076
+
1077
+ if use_cache:
1078
+ next_decoder_cache = layer_outputs[
1079
+ 2 if output_attentions else 1]
1080
+
1081
+ if output_attentions:
1082
+ all_self_attns += (layer_outputs[1], )
1083
+
1084
+ hidden_states = self.norm(hidden_states)
1085
+
1086
+ # add hidden states from the last decoder layer
1087
+ if output_hidden_states:
1088
+ all_hidden_states += (hidden_states, )
1089
+
1090
+ next_cache = next_decoder_cache if use_cache else None
1091
+ if return_legacy_cache:
1092
+ next_cache = next_cache.to_legacy_cache()
1093
+
1094
+ if not return_dict:
1095
+ return tuple(
1096
+ v for v in
1097
+ [hidden_states, next_cache, all_hidden_states, all_self_attns]
1098
+ if v is not None)
1099
+ return BaseModelOutputWithPast(
1100
+ last_hidden_state=hidden_states,
1101
+ past_key_values=next_cache,
1102
+ hidden_states=all_hidden_states,
1103
+ attentions=all_self_attns,
1104
+ )
1105
+
1106
+ def _update_causal_mask(
1107
+ self,
1108
+ attention_mask: torch.Tensor,
1109
+ input_tensor: torch.Tensor,
1110
+ cache_position: torch.Tensor,
1111
+ past_key_values: Cache,
1112
+ output_attentions: bool,
1113
+ ):
1114
+ # TODO: As of torch==2.2.0, the `attention_mask` passed to the model in `generate` is 2D and of dynamic length
1115
+ # even when the static KV cache is used. This is an issue for torch.compile which then recaptures cudagraphs at
1116
+ # each decode steps due to the dynamic shapes. (`recording cudagraph tree for symint key 13`, etc.), which is
1117
+ # VERY slow. A workaround is `@torch.compiler.disable`, but this prevents using `fullgraph=True`.
1118
+ # See more context in https://github.com/huggingface/transformers/pull/29114
1119
+
1120
+ if self.config.attn_implementation == 'flash_attention_2':
1121
+ if attention_mask is not None and 0.0 in attention_mask:
1122
+ return attention_mask
1123
+ return None
1124
+
1125
+ # For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
1126
+ # order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
1127
+ # to infer the attention mask.
1128
+ past_seen_tokens = past_key_values.get_seq_length(
1129
+ ) if past_key_values is not None else 0
1130
+ using_static_cache = isinstance(past_key_values, StaticCache)
1131
+
1132
+ # When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
1133
+ if self.config.attn_implementation == 'sdpa' and not using_static_cache and not output_attentions:
1134
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
1135
+ attention_mask,
1136
+ inputs_embeds=input_tensor,
1137
+ past_key_values_length=past_seen_tokens,
1138
+ is_training=self.training,
1139
+ ):
1140
+ return None
1141
+
1142
+ dtype, device = input_tensor.dtype, input_tensor.device
1143
+ min_dtype = torch.finfo(dtype).min
1144
+ sequence_length = input_tensor.shape[1]
1145
+ if using_static_cache:
1146
+ target_length = past_key_values.get_max_length()
1147
+ else:
1148
+ target_length = (
1149
+ attention_mask.shape[-1] if isinstance(
1150
+ attention_mask, torch.Tensor) else past_seen_tokens +
1151
+ sequence_length + 1)
1152
+
1153
+ if attention_mask is not None and attention_mask.dim() == 4:
1154
+ # in this case we assume that the mask comes already in inverted form and requires no inversion or slicing
1155
+ if attention_mask.max() != 0:
1156
+ raise ValueError(
1157
+ 'Custom 4D attention mask should be passed in inverted form with max==0`'
1158
+ )
1159
+ causal_mask = attention_mask
1160
+ else:
1161
+ causal_mask = torch.full((sequence_length, target_length),
1162
+ fill_value=min_dtype,
1163
+ dtype=dtype,
1164
+ device=device)
1165
+ if sequence_length != 1:
1166
+ causal_mask = torch.triu(causal_mask, diagonal=1)
1167
+ causal_mask *= torch.arange(
1168
+ target_length, device=device) > cache_position.reshape(-1, 1)
1169
+ causal_mask = causal_mask[None, None, :, :].expand(
1170
+ input_tensor.shape[0], 1, -1, -1)
1171
+ if attention_mask is not None:
1172
+ causal_mask = causal_mask.clone(
1173
+ ) # copy to contiguous memory for in-place edit
1174
+ mask_length = attention_mask.shape[-1]
1175
+ padding_mask = causal_mask[:, :, :, :
1176
+ mask_length] + attention_mask[:,
1177
+ None,
1178
+ None, :]
1179
+ padding_mask = padding_mask == 0
1180
+ causal_mask[:, :, :, :
1181
+ mask_length] = causal_mask[:, :, :, :
1182
+ mask_length].masked_fill(
1183
+ padding_mask,
1184
+ min_dtype)
1185
+ if (self.config.attn_implementation == 'sdpa'
1186
+ and attention_mask is not None
1187
+ and attention_mask.device.type == 'cuda'
1188
+ and not output_attentions):
1189
+ # Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
1190
+ # using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
1191
+ # Details: https://github.com/pytorch/pytorch/issues/110213
1192
+ causal_mask = AttentionMaskConverter._unmask_unattended(
1193
+ causal_mask, min_dtype) # pylint: disable=E1120
1194
+
1195
+ return causal_mask
1196
+
1197
+
1198
+ # Modified from transformers.models.llama.modeling_llama.LlamaForCausalLM
1199
+ class InternLM2ForCausalLM(InternLM2PreTrainedModel):
1200
+ """Causal language model (CLM) for InternLM2."""
1201
+
1202
+ _auto_class = 'AutoModelForCausalLM'
1203
+ _tied_weights_keys = ['output.weight']
1204
+
1205
+ def __init__(self, config):
1206
+ super().__init__(config)
1207
+ self.model = InternLM2Model(config)
1208
+ self.vocab_size = config.vocab_size
1209
+ self.output = nn.Linear(
1210
+ config.hidden_size, config.vocab_size, bias=False)
1211
+
1212
+ # Initialize weights and apply final processing
1213
+ self.post_init()
1214
+
1215
+ def get_input_embeddings(self):
1216
+ return self.model.tok_embeddings
1217
+
1218
+ def set_input_embeddings(self, value):
1219
+ self.model.tok_embeddings = value
1220
+
1221
+ def get_output_embeddings(self):
1222
+ return self.output
1223
+
1224
+ def set_output_embeddings(self, new_embeddings):
1225
+ self.output = new_embeddings
1226
+
1227
+ def set_decoder(self, decoder):
1228
+ self.model = decoder
1229
+
1230
+ def get_decoder(self):
1231
+ return self.model
1232
+
1233
+ @add_start_docstrings_to_model_forward(InternLM2_INPUTS_DOCSTRING)
1234
+ @replace_return_docstrings(
1235
+ output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
1236
+ def forward(
1237
+ self,
1238
+ input_ids: torch.LongTensor = None,
1239
+ attention_mask: Optional[torch.Tensor] = None,
1240
+ position_ids: Optional[torch.LongTensor] = None,
1241
+ past_key_values: Optional[Union[Cache,
1242
+ List[torch.FloatTensor]]] = None,
1243
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1244
+ labels: Optional[torch.LongTensor] = None,
1245
+ use_cache: Optional[bool] = None,
1246
+ output_attentions: Optional[bool] = None,
1247
+ output_hidden_states: Optional[bool] = None,
1248
+ return_dict: Optional[bool] = None,
1249
+ cache_position: Optional[torch.LongTensor] = None,
1250
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1251
+ r"""
1252
+ Args:
1253
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1254
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1255
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1256
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1257
+ Returns:
1258
+ Example:
1259
+ ```python
1260
+ >>> from transformers import AutoTokenizer, InternLM2ForCausalLM
1261
+ >>> model = InternLM2ForCausalLM.from_pretrained("meta-InternLM2/InternLM2-2-7b-hf")
1262
+ >>> tokenizer = AutoTokenizer.from_pretrained("meta-InternLM2/InternLM2-2-7b-hf")
1263
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
1264
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1265
+ >>> # Generate
1266
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1267
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1268
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
1269
+ ```"""
1270
+
1271
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1272
+ output_hidden_states = (
1273
+ output_hidden_states if output_hidden_states is not None else
1274
+ self.config.output_hidden_states)
1275
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1276
+
1277
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1278
+ outputs = self.model(
1279
+ input_ids=input_ids,
1280
+ attention_mask=attention_mask,
1281
+ position_ids=position_ids,
1282
+ past_key_values=past_key_values,
1283
+ inputs_embeds=inputs_embeds,
1284
+ use_cache=use_cache,
1285
+ output_attentions=output_attentions,
1286
+ output_hidden_states=output_hidden_states,
1287
+ return_dict=return_dict,
1288
+ cache_position=cache_position,
1289
+ )
1290
+
1291
+ hidden_states = outputs[0]
1292
+ if self.config.pretraining_tp > 1:
1293
+ output_slices = self.output.weight.split(
1294
+ self.vocab_size // self.config.pretraining_tp, dim=0)
1295
+ logits = [
1296
+ F.linear(hidden_states, output_slices[i]) # pylint: disable=not-callable
1297
+ for i in range(self.config.pretraining_tp)
1298
+ ]
1299
+ logits = torch.cat(logits, dim=-1)
1300
+ else:
1301
+ logits = self.output(hidden_states)
1302
+ logits = logits.float()
1303
+
1304
+ loss = None
1305
+ if labels is not None:
1306
+ # Shift so that tokens < n predict n
1307
+ shift_logits = logits[..., :-1, :].contiguous()
1308
+ shift_labels = labels[..., 1:].contiguous()
1309
+ # Flatten the tokens
1310
+ loss_fct = CrossEntropyLoss()
1311
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1312
+ shift_labels = shift_labels.view(-1)
1313
+ # Enable model parallelism
1314
+ shift_labels = shift_labels.to(shift_logits.device)
1315
+ loss = loss_fct(shift_logits, shift_labels)
1316
+
1317
+ if not return_dict:
1318
+ output = (logits, ) + outputs[1:]
1319
+ return (loss, ) + output if loss is not None else output
1320
+
1321
+ return CausalLMOutputWithPast(
1322
+ loss=loss,
1323
+ logits=logits,
1324
+ past_key_values=outputs.past_key_values,
1325
+ hidden_states=outputs.hidden_states,
1326
+ attentions=outputs.attentions,
1327
+ )
1328
+
1329
+ def prepare_inputs_for_generation(
1330
+ self,
1331
+ input_ids,
1332
+ past_key_values=None,
1333
+ attention_mask=None,
1334
+ inputs_embeds=None,
1335
+ cache_position=None,
1336
+ use_cache=True,
1337
+ **kwargs,
1338
+ ):
1339
+ past_length = 0
1340
+ if past_key_values is not None:
1341
+ if isinstance(past_key_values, Cache):
1342
+ past_length = cache_position[
1343
+ 0] if cache_position is not None else past_key_values.get_seq_length(
1344
+ )
1345
+ max_cache_length = (
1346
+ torch.tensor(
1347
+ past_key_values.get_max_length(),
1348
+ device=input_ids.device)
1349
+ if past_key_values.get_max_length() is not None else None)
1350
+ cache_length = past_length if max_cache_length is None else torch.min(
1351
+ max_cache_length, past_length)
1352
+ # TODO joao: remove this `else` after `generate` prioritizes `Cache` objects
1353
+ else:
1354
+ cache_length = past_length = past_key_values[0][0].shape[2]
1355
+ max_cache_length = None
1356
+
1357
+ # Keep only the unprocessed tokens:
1358
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
1359
+ # some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as input)
1360
+ if attention_mask is not None and attention_mask.shape[
1361
+ 1] > input_ids.shape[1]:
1362
+ input_ids = input_ids[:, -(attention_mask.shape[1] -
1363
+ past_length):]
1364
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
1365
+ # input_ids based on the past_length.
1366
+ elif past_length < input_ids.shape[1]:
1367
+ input_ids = input_ids[:, past_length:]
1368
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
1369
+
1370
+ # If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
1371
+ if (max_cache_length is not None and attention_mask is not None
1372
+ and cache_length + input_ids.shape[1] > max_cache_length):
1373
+ attention_mask = attention_mask[:, -max_cache_length:] # pylint: disable=E1130
1374
+
1375
+ position_ids = kwargs.get('position_ids', None)
1376
+ if attention_mask is not None and position_ids is None:
1377
+ # create position_ids on the fly for batch generation
1378
+ position_ids = attention_mask.long().cumsum(-1) - 1
1379
+ position_ids.masked_fill_(attention_mask == 0, 1)
1380
+ if past_key_values:
1381
+ position_ids = position_ids[:, -input_ids.shape[1]:]
1382
+
1383
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1384
+ if inputs_embeds is not None and past_key_values is None:
1385
+ model_inputs = {'inputs_embeds': inputs_embeds}
1386
+ else:
1387
+ # The `contiguous()` here is necessary to have a static stride during decoding. torchdynamo otherwise
1388
+ # recompiles graphs as the stride of the inputs is a guard.
1389
+ # Ref: https://github.com/huggingface/transformers/pull/29114
1390
+ # TODO: use `next_tokens` directly instead.
1391
+ model_inputs = {'input_ids': input_ids.contiguous()}
1392
+
1393
+ input_length = position_ids.shape[
1394
+ -1] if position_ids is not None else input_ids.shape[-1]
1395
+ if cache_position is None:
1396
+ cache_position = torch.arange(
1397
+ past_length,
1398
+ past_length + input_length,
1399
+ device=input_ids.device)
1400
+ elif use_cache:
1401
+ cache_position = cache_position[-input_length:]
1402
+
1403
+ model_inputs.update({
1404
+ 'position_ids': position_ids,
1405
+ 'cache_position': cache_position,
1406
+ 'past_key_values': past_key_values,
1407
+ 'use_cache': use_cache,
1408
+ 'attention_mask': attention_mask,
1409
+ })
1410
+ return model_inputs
1411
+
1412
+ @staticmethod
1413
+ def _reorder_cache(past_key_values, beam_idx):
1414
+ reordered_past = ()
1415
+ for layer_past in past_key_values:
1416
+ reordered_past += (tuple(
1417
+ past_state.index_select(0, beam_idx.to(past_state.device))
1418
+ for past_state in layer_past), )
1419
+ return reordered_past
1420
+
1421
+ def build_inputs(self,
1422
+ tokenizer,
1423
+ query: str,
1424
+ history: List[Tuple[str, str]] = None,
1425
+ meta_instruction=''):
1426
+ if history is None:
1427
+ history = []
1428
+ if tokenizer.add_bos_token:
1429
+ prompt = ''
1430
+ else:
1431
+ prompt = tokenizer.bos_token
1432
+ if meta_instruction:
1433
+ prompt += f"""<|im_start|>system\n{meta_instruction}<|im_end|>\n"""
1434
+ for record in history:
1435
+ prompt += f"""<|im_start|>user\n{record[0]}<|im_end|>\n<|im_start|>assistant\n{record[1]}<|im_end|>\n"""
1436
+ prompt += f"""<|im_start|>user\n{query}<|im_end|>\n<|im_start|>assistant\n"""
1437
+ return tokenizer([prompt], return_tensors='pt')
1438
+
1439
+ @torch.no_grad()
1440
+ def chat(
1441
+ self,
1442
+ tokenizer,
1443
+ query: str,
1444
+ history: Optional[List[Tuple[str, str]]] = None,
1445
+ streamer: Optional[BaseStreamer] = None,
1446
+ max_new_tokens: int = 1024,
1447
+ do_sample: bool = True,
1448
+ temperature: float = 0.8,
1449
+ top_p: float = 0.8,
1450
+ meta_instruction:
1451
+ str = 'You are an AI assistant whose name is InternLM (书生·浦语).\n'
1452
+ '- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory '
1453
+ '(上海人工智能实验室). It is designed to be helpful, honest, and harmless.\n'
1454
+ '- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such '
1455
+ 'as English and 中文.',
1456
+ **kwargs,
1457
+ ):
1458
+ if history is None:
1459
+ history = []
1460
+ inputs = self.build_inputs(tokenizer, query, history, meta_instruction)
1461
+ inputs = {
1462
+ k: v.to(self.device)
1463
+ for k, v in inputs.items() if torch.is_tensor(v)
1464
+ }
1465
+ # also add end-of-assistant token in eos token id to avoid unnecessary generation
1466
+ eos_token_id = [
1467
+ tokenizer.eos_token_id,
1468
+ tokenizer.convert_tokens_to_ids(['<|im_end|>'])[0]
1469
+ ]
1470
+ outputs = self.generate(
1471
+ **inputs,
1472
+ streamer=streamer,
1473
+ max_new_tokens=max_new_tokens,
1474
+ do_sample=do_sample,
1475
+ temperature=temperature,
1476
+ top_p=top_p,
1477
+ eos_token_id=eos_token_id,
1478
+ **kwargs,
1479
+ )
1480
+ outputs = outputs[0].cpu().tolist()[len(inputs['input_ids'][0]):]
1481
+ response = tokenizer.decode(outputs, skip_special_tokens=True)
1482
+ response = response.split('<|im_end|>')[0]
1483
+ history = history + [(query, response)]
1484
+ return response, history
1485
+
1486
+ @torch.no_grad()
1487
+ def stream_chat(
1488
+ self,
1489
+ tokenizer,
1490
+ query: str,
1491
+ history: List[Tuple[str, str]] = None,
1492
+ max_new_tokens: int = 1024,
1493
+ do_sample: bool = True,
1494
+ temperature: float = 0.8,
1495
+ top_p: float = 0.8,
1496
+ **kwargs,
1497
+ ):
1498
+ if history is None:
1499
+ history = []
1500
+ """
1501
+ Return a generator in format: (response, history)
1502
+ Eg.
1503
+ ('你好,有什么可以帮助您的吗', [('你好', '你好,有什么可以帮助您的吗')])
1504
+ ('你好,有什么可以帮助您的吗?', [('你好', '你好,有什么可以帮助您的吗?')])
1505
+ """
1506
+ if BaseStreamer is None:
1507
+ raise ModuleNotFoundError(
1508
+ 'The version of `transformers` is too low. Please make sure '
1509
+ 'that you have installed `transformers>=4.28.0`.')
1510
+
1511
+ response_queue = queue.Queue(maxsize=20)
1512
+
1513
+ class ChatStreamer(BaseStreamer):
1514
+ """
1515
+ Streamer used in generate to print words one by one.
1516
+ """
1517
+
1518
+ def __init__(self, tokenizer) -> None:
1519
+ super().__init__()
1520
+ self.tokenizer = tokenizer
1521
+ self.queue = response_queue
1522
+ self.query = query
1523
+ self.history = history
1524
+ self.response = ''
1525
+ self.cache = []
1526
+ self.received_inputs = False
1527
+ self.queue.put(
1528
+ (self.response, history + [(self.query, self.response)]))
1529
+
1530
+ def put(self, value):
1531
+ if len(value.shape) > 1 and value.shape[0] > 1:
1532
+ raise ValueError('ChatStreamer only supports batch size 1')
1533
+ elif len(value.shape) > 1:
1534
+ value = value[0]
1535
+
1536
+ if not self.received_inputs:
1537
+ # The first received value is input_ids, ignore here
1538
+ self.received_inputs = True
1539
+ return
1540
+
1541
+ self.cache.extend(value.tolist())
1542
+ token = self.tokenizer.decode(
1543
+ self.cache, skip_special_tokens=True)
1544
+ if token.strip() != '<|im_end|>':
1545
+ self.response = self.response + token
1546
+ history = self.history + [(self.query, self.response)]
1547
+ self.queue.put((self.response, history))
1548
+ self.cache = []
1549
+ else:
1550
+ self.end()
1551
+
1552
+ def end(self):
1553
+ self.queue.put(None)
1554
+
1555
+ def stream_producer():
1556
+ return self.chat(
1557
+ tokenizer=tokenizer,
1558
+ query=query,
1559
+ streamer=ChatStreamer(tokenizer=tokenizer),
1560
+ history=history,
1561
+ max_new_tokens=max_new_tokens,
1562
+ do_sample=do_sample,
1563
+ temperature=temperature,
1564
+ top_p=top_p,
1565
+ **kwargs,
1566
+ )
1567
+
1568
+ def consumer():
1569
+ producer = threading.Thread(target=stream_producer)
1570
+ producer.start()
1571
+ while True:
1572
+ res = response_queue.get()
1573
+ if res is None:
1574
+ return
1575
+ yield res
1576
+
1577
+ return consumer()
1578
+
1579
+
1580
+ # Copied from transformers.models.llama.modeling_llama.LlamaForSequenceClassification with Llama->InternLM2
1581
+ @add_start_docstrings(
1582
+ """
1583
+ The InternLM2 Model transformer with a sequence classification head on top (linear layer).
1584
+ [`InternLM2ForSequenceClassification`] uses the last token in order to do the classification, as other causal models
1585
+ (e.g. GPT-2) do.
1586
+ Since it does classification on the last token, it requires to know the position of the last token. If a
1587
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
1588
+ no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
1589
+ padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
1590
+ each row of the batch).
1591
+ """,
1592
+ InternLM2_START_DOCSTRING,
1593
+ )
1594
+ class InternLM2ForSequenceClassification(InternLM2PreTrainedModel):
1595
+ """Sequence Classification Head for InternLM2 Model."""
1596
+
1597
+ def __init__(self, config):
1598
+ super().__init__(config)
1599
+ self.num_labels = config.num_labels
1600
+ self.model = InternLM2Model(config)
1601
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
1602
+
1603
+ # Initialize weights and apply final processing
1604
+ self.post_init()
1605
+
1606
+ def get_input_embeddings(self):
1607
+ return self.model.tok_embeddings
1608
+
1609
+ def set_input_embeddings(self, value):
1610
+ self.model.tok_embeddings = value
1611
+
1612
+ @add_start_docstrings_to_model_forward(InternLM2_INPUTS_DOCSTRING)
1613
+ def forward(
1614
+ self,
1615
+ input_ids: torch.LongTensor = None,
1616
+ attention_mask: Optional[torch.Tensor] = None,
1617
+ position_ids: Optional[torch.LongTensor] = None,
1618
+ past_key_values: Optional[Union[Cache,
1619
+ List[torch.FloatTensor]]] = None,
1620
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1621
+ labels: Optional[torch.LongTensor] = None,
1622
+ use_cache: Optional[bool] = None,
1623
+ output_attentions: Optional[bool] = None,
1624
+ output_hidden_states: Optional[bool] = None,
1625
+ return_dict: Optional[bool] = None,
1626
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1627
+ r"""
1628
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1629
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1630
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1631
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1632
+ """
1633
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1634
+
1635
+ transformer_outputs = self.model(
1636
+ input_ids,
1637
+ attention_mask=attention_mask,
1638
+ position_ids=position_ids,
1639
+ past_key_values=past_key_values,
1640
+ inputs_embeds=inputs_embeds,
1641
+ use_cache=use_cache,
1642
+ output_attentions=output_attentions,
1643
+ output_hidden_states=output_hidden_states,
1644
+ return_dict=return_dict,
1645
+ )
1646
+ hidden_states = transformer_outputs[0]
1647
+ logits = self.score(hidden_states)
1648
+
1649
+ if input_ids is not None:
1650
+ batch_size = input_ids.shape[0]
1651
+ else:
1652
+ batch_size = inputs_embeds.shape[0]
1653
+
1654
+ if self.config.pad_token_id is None and batch_size != 1:
1655
+ raise ValueError(
1656
+ 'Cannot handle batch sizes > 1 if no padding token is defined.'
1657
+ )
1658
+ if self.config.pad_token_id is None:
1659
+ sequence_lengths = -1
1660
+ else:
1661
+ if input_ids is not None:
1662
+ # if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
1663
+ sequence_lengths = torch.eq(
1664
+ input_ids, self.config.pad_token_id).int().argmax(-1) - 1
1665
+ sequence_lengths = sequence_lengths % input_ids.shape[-1]
1666
+ sequence_lengths = sequence_lengths.to(logits.device)
1667
+ else:
1668
+ sequence_lengths = -1
1669
+
1670
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device),
1671
+ sequence_lengths]
1672
+
1673
+ loss = None
1674
+ if labels is not None:
1675
+ labels = labels.to(logits.device)
1676
+ if self.config.problem_type is None:
1677
+ if self.num_labels == 1:
1678
+ self.config.problem_type = 'regression'
1679
+ elif self.num_labels > 1 and (labels.dtype
1680
+ in (torch.long, torch.int)):
1681
+ self.config.problem_type = 'single_label_classification'
1682
+ else:
1683
+ self.config.problem_type = 'multi_label_classification'
1684
+
1685
+ if self.config.problem_type == 'regression':
1686
+ loss_fct = MSELoss()
1687
+ if self.num_labels == 1:
1688
+ loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
1689
+ else:
1690
+ loss = loss_fct(pooled_logits, labels)
1691
+ elif self.config.problem_type == 'single_label_classification':
1692
+ loss_fct = CrossEntropyLoss()
1693
+ loss = loss_fct(
1694
+ pooled_logits.view(-1, self.num_labels), labels.view(-1))
1695
+ elif self.config.problem_type == 'multi_label_classification':
1696
+ loss_fct = BCEWithLogitsLoss()
1697
+ loss = loss_fct(pooled_logits, labels)
1698
+ if not return_dict:
1699
+ output = (pooled_logits, ) + transformer_outputs[1:]
1700
+ return ((loss, ) + output) if loss is not None else output
1701
+
1702
+ return SequenceClassifierOutputWithPast(
1703
+ loss=loss,
1704
+ logits=pooled_logits,
1705
+ past_key_values=transformer_outputs.past_key_values,
1706
+ hidden_states=transformer_outputs.hidden_states,
1707
+ attentions=transformer_outputs.attentions,
1708
+ )
1709
+
1710
+
1711
+ # Copied from transformers.models.llama.modeling_llama.LlamaForQuestionAnswering with Llama->InternLM2
1712
+ @add_start_docstrings(
1713
+ """
1714
+ The InternLM2 Model transformer with a span classification head on top for extractive question-answering tasks like
1715
+ SQuAD (a linear layer on top of the hidden-states output to compute `span start logits` and `span end logits`).
1716
+ """,
1717
+ InternLM2_START_DOCSTRING,
1718
+ )
1719
+ class InternLM2ForQuestionAnswering(InternLM2PreTrainedModel):
1720
+ """Question Answering model for InternLM2."""
1721
+
1722
+ base_model_prefix = 'transformer'
1723
+
1724
+ def __init__(self, config):
1725
+ super().__init__(config)
1726
+ self.transformer = InternLM2Model(config)
1727
+ self.qa_outputs = nn.Linear(config.hidden_size, 2)
1728
+
1729
+ # Initialize weights and apply final processing
1730
+ self.post_init()
1731
+
1732
+ def get_input_embeddings(self):
1733
+ return self.transformer.tok_embeddings
1734
+
1735
+ def set_input_embeddings(self, value):
1736
+ self.transformer.tok_embeddings = value
1737
+
1738
+ @add_start_docstrings_to_model_forward(InternLM2_INPUTS_DOCSTRING)
1739
+ def forward(
1740
+ self,
1741
+ input_ids: Optional[torch.LongTensor] = None,
1742
+ attention_mask: Optional[torch.FloatTensor] = None,
1743
+ position_ids: Optional[torch.LongTensor] = None,
1744
+ past_key_values: Optional[Union[Cache,
1745
+ List[torch.FloatTensor]]] = None,
1746
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1747
+ start_positions: Optional[torch.LongTensor] = None,
1748
+ end_positions: Optional[torch.LongTensor] = None,
1749
+ output_attentions: Optional[bool] = None,
1750
+ output_hidden_states: Optional[bool] = None,
1751
+ return_dict: Optional[bool] = None,
1752
+ ) -> Union[Tuple, QuestionAnsweringModelOutput]:
1753
+ r"""
1754
+ start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1755
+ Labels for position (index) of the start of the labelled span for computing the token classification loss.
1756
+ Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
1757
+ are not taken into account for computing the loss.
1758
+ end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1759
+ Labels for position (index) of the end of the labelled span for computing the token classification loss.
1760
+ Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
1761
+ are not taken into account for computing the loss.
1762
+ """
1763
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1764
+
1765
+ outputs = self.transformer(
1766
+ input_ids,
1767
+ attention_mask=attention_mask,
1768
+ position_ids=position_ids,
1769
+ past_key_values=past_key_values,
1770
+ inputs_embeds=inputs_embeds,
1771
+ output_attentions=output_attentions,
1772
+ output_hidden_states=output_hidden_states,
1773
+ return_dict=return_dict,
1774
+ )
1775
+
1776
+ sequence_output = outputs[0]
1777
+
1778
+ logits = self.qa_outputs(sequence_output)
1779
+ start_logits, end_logits = logits.split(1, dim=-1)
1780
+ start_logits = start_logits.squeeze(-1).contiguous()
1781
+ end_logits = end_logits.squeeze(-1).contiguous()
1782
+
1783
+ total_loss = None
1784
+ if start_positions is not None and end_positions is not None:
1785
+ # If we are on multi-GPU, split add a dimension
1786
+ if len(start_positions.size()) > 1:
1787
+ start_positions = start_positions.squeeze(-1).to(
1788
+ start_logits.device)
1789
+ if len(end_positions.size()) > 1:
1790
+ end_positions = end_positions.squeeze(-1).to(end_logits.device)
1791
+ # sometimes the start/end positions are outside our model inputs, we ignore these terms
1792
+ ignored_index = start_logits.size(1)
1793
+ start_positions = start_positions.clamp(0, ignored_index)
1794
+ end_positions = end_positions.clamp(0, ignored_index)
1795
+
1796
+ loss_fct = CrossEntropyLoss(ignore_index=ignored_index)
1797
+ start_loss = loss_fct(start_logits, start_positions)
1798
+ end_loss = loss_fct(end_logits, end_positions)
1799
+ total_loss = (start_loss + end_loss) / 2
1800
+
1801
+ if not return_dict:
1802
+ output = (start_logits, end_logits) + outputs[2:]
1803
+ return ((total_loss, ) +
1804
+ output) if total_loss is not None else output
1805
+
1806
+ return QuestionAnsweringModelOutput(
1807
+ loss=total_loss,
1808
+ start_logits=start_logits,
1809
+ end_logits=end_logits,
1810
+ hidden_states=outputs.hidden_states,
1811
+ attentions=outputs.attentions,
1812
+ )
1813
+
1814
+
1815
+ # Copied from transformers.models.llama.modeling_llama.LlamaForTokenClassification with Llama->InternLM2
1816
+ @add_start_docstrings(
1817
+ """
1818
+ The InternLM2 Model transformer with a token classification head on top (a linear layer on top of the hidden-states
1819
+ output) e.g. for Named-Entity-Recognition (NER) tasks.
1820
+ """,
1821
+ InternLM2_START_DOCSTRING,
1822
+ )
1823
+ class InternLM2ForTokenClassification(InternLM2PreTrainedModel):
1824
+ """Token classification model for InternLM2."""
1825
+
1826
+ def __init__(self, config):
1827
+ super().__init__(config)
1828
+ self.num_labels = config.num_labels
1829
+ self.model = InternLM2Model(config)
1830
+ if getattr(config, 'classifier_dropout', None) is not None:
1831
+ classifier_dropout = config.classifier_dropout
1832
+ elif getattr(config, 'hidden_dropout', None) is not None:
1833
+ classifier_dropout = config.hidden_dropout
1834
+ else:
1835
+ classifier_dropout = 0.1
1836
+ self.dropout = nn.Dropout(classifier_dropout)
1837
+ self.score = nn.Linear(config.hidden_size, config.num_labels)
1838
+
1839
+ # Initialize weights and apply final processing
1840
+ self.post_init()
1841
+
1842
+ def get_input_embeddings(self):
1843
+ return self.model.tok_embeddings
1844
+
1845
+ def set_input_embeddings(self, value):
1846
+ self.model.tok_embeddings = value
1847
+
1848
+ @add_start_docstrings_to_model_forward(InternLM2_INPUTS_DOCSTRING)
1849
+ def forward(
1850
+ self,
1851
+ input_ids: torch.LongTensor = None,
1852
+ attention_mask: Optional[torch.Tensor] = None,
1853
+ position_ids: Optional[torch.LongTensor] = None,
1854
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1855
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1856
+ labels: Optional[torch.LongTensor] = None,
1857
+ use_cache: Optional[bool] = None,
1858
+ output_attentions: Optional[bool] = None,
1859
+ output_hidden_states: Optional[bool] = None,
1860
+ return_dict: Optional[bool] = None,
1861
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1862
+ r"""
1863
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1864
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1865
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1866
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1867
+ """
1868
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1869
+
1870
+ outputs = self.model(
1871
+ input_ids,
1872
+ attention_mask=attention_mask,
1873
+ position_ids=position_ids,
1874
+ past_key_values=past_key_values,
1875
+ inputs_embeds=inputs_embeds,
1876
+ use_cache=use_cache,
1877
+ output_attentions=output_attentions,
1878
+ output_hidden_states=output_hidden_states,
1879
+ return_dict=return_dict,
1880
+ )
1881
+ sequence_output = outputs[0]
1882
+ sequence_output = self.dropout(sequence_output)
1883
+ logits = self.score(sequence_output)
1884
+
1885
+ loss = None
1886
+ if labels is not None:
1887
+ loss_fct = CrossEntropyLoss()
1888
+ loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
1889
+
1890
+ if not return_dict:
1891
+ output = (logits, ) + outputs[2:]
1892
+ return ((loss, ) + output) if loss is not None else output
1893
+
1894
+ return TokenClassifierOutput(
1895
+ loss=loss,
1896
+ logits=logits,
1897
+ hidden_states=outputs.hidden_states,
1898
+ attentions=outputs.attentions,
1899
+ )
model_weight/modeling_llava.py ADDED
@@ -0,0 +1,575 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2023 the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """PyTorch Llava model."""
16
+
17
+ from dataclasses import dataclass
18
+ from typing import List, Optional, Tuple, Union
19
+
20
+ import torch
21
+ import torch.utils.checkpoint
22
+ from torch import nn
23
+
24
+ from transformers import PreTrainedModel
25
+ from transformers.activations import ACT2FN
26
+ from transformers.cache_utils import Cache
27
+ from transformers.modeling_outputs import ModelOutput
28
+ from transformers.utils import (
29
+ add_start_docstrings,
30
+ add_start_docstrings_to_model_forward,
31
+ logging,
32
+ replace_return_docstrings,
33
+ )
34
+ from transformers import AutoModel, AutoModelForCausalLM
35
+ from .configuration_llava import EnhancedLlavaConfig
36
+
37
+
38
+ logger = logging.get_logger(__name__)
39
+
40
+ _CONFIG_FOR_DOC = "LlavaConfig"
41
+
42
+
43
+
44
+ @dataclass
45
+ # Copied from transformers.models.idefics.modeling_idefics.IdeficsCausalLMOutputWithPast with Idefics->Llava
46
+ class LlavaCausalLMOutputWithPast(ModelOutput):
47
+ """
48
+ Base class for Llava causal language model (or autoregressive) outputs.
49
+
50
+ Args:
51
+ loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
52
+ Language modeling loss (for next-token prediction).
53
+ logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
54
+ Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
55
+ past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
56
+ Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
57
+ `(batch_size, num_heads, sequence_length, embed_size_per_head)`)
58
+
59
+ Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
60
+ `past_key_values` input) to speed up sequential decoding.
61
+ hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
62
+ Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
63
+ one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
64
+
65
+ Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
66
+ attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
67
+ Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
68
+ sequence_length)`.
69
+
70
+ Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
71
+ heads.
72
+ image_hidden_states (`tuple(torch.FloatTensor)`, *optional*):
73
+ Tuple of `torch.FloatTensor` (one for the output of the image embeddings, `(batch_size, num_images,
74
+ sequence_length, hidden_size)`.
75
+
76
+ image_hidden_states of the model produced by the vision encoder, and optionally by the perceiver
77
+ """
78
+
79
+ loss: Optional[torch.FloatTensor] = None
80
+ logits: torch.FloatTensor = None
81
+ past_key_values: Optional[List[torch.FloatTensor]] = None
82
+ hidden_states: Optional[Tuple[torch.FloatTensor]] = None
83
+ attentions: Optional[Tuple[torch.FloatTensor]] = None
84
+ image_hidden_states: Optional[Tuple[torch.FloatTensor]] = None
85
+
86
+
87
+ class LlavaMultiModalProjector(nn.Module):
88
+ def __init__(self, config: EnhancedLlavaConfig):
89
+ super().__init__()
90
+
91
+ self.linear_1 = nn.Linear(config.vision_config.hidden_size, config.text_config.hidden_size, bias=True)
92
+ self.act = ACT2FN[config.projector_hidden_act]
93
+ self.linear_2 = nn.Linear(config.text_config.hidden_size, config.text_config.hidden_size, bias=True)
94
+
95
+ def forward(self, image_features):
96
+ hidden_states = self.linear_1(image_features)
97
+ hidden_states = self.act(hidden_states)
98
+ hidden_states = self.linear_2(hidden_states)
99
+ return hidden_states
100
+
101
+
102
+ LLAVA_START_DOCSTRING = r"""
103
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
104
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
105
+ etc.)
106
+
107
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
108
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
109
+ and behavior.
110
+
111
+ Parameters:
112
+ config ([`LlavaConfig`] or [`LlavaVisionConfig`]):
113
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
114
+ load the weights associated with the model, only the configuration. Check out the
115
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
116
+ """
117
+
118
+
119
+ @add_start_docstrings(
120
+ "The bare LLaMA Model outputting raw hidden-states without any specific head on top.",
121
+ LLAVA_START_DOCSTRING,
122
+ )
123
+ class LlavaPreTrainedModel(PreTrainedModel):
124
+ config_class = EnhancedLlavaConfig
125
+ base_model_prefix = "model"
126
+ supports_gradient_checkpointing = True
127
+ _no_split_modules = ["LlavaVisionAttention"]
128
+ _skip_keys_device_placement = "past_key_values"
129
+ _supports_flash_attn_2 = True
130
+
131
+ def _init_weights(self, module):
132
+ # important: this ported version of Llava isn't meant for training from scratch - only
133
+ # inference and fine-tuning - so the proper init weights code has been removed - the original codebase
134
+ # https://github.com/haotian-liu/LLaVA/tree/main/llava should serve for that purpose
135
+ std = (
136
+ self.config.initializer_range
137
+ if hasattr(self.config, "initializer_range")
138
+ else self.config.text_config.initializer_range
139
+ )
140
+
141
+ if hasattr(module, "class_embedding"):
142
+ module.class_embedding.data.normal_(mean=0.0, std=std)
143
+
144
+ if isinstance(module, (nn.Linear, nn.Conv2d)):
145
+ module.weight.data.normal_(mean=0.0, std=std)
146
+ if module.bias is not None:
147
+ module.bias.data.zero_()
148
+ elif isinstance(module, nn.Embedding):
149
+ module.weight.data.normal_(mean=0.0, std=std)
150
+ if module.padding_idx is not None:
151
+ module.weight.data[module.padding_idx].zero_()
152
+
153
+ @property
154
+ def _supports_sdpa(self):
155
+ """
156
+ Retrieve language_model's attribute to check whether the model supports
157
+ SDPA or not.
158
+ """
159
+ return self.language_model._supports_sdpa
160
+
161
+
162
+ LLAVA_INPUTS_DOCSTRING = r"""
163
+ Args:
164
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
165
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
166
+ it.
167
+
168
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
169
+ [`PreTrainedTokenizer.__call__`] for details.
170
+
171
+ [What are input IDs?](../glossary#input-ids)
172
+ pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)):
173
+ The tensors corresponding to the input images. Pixel values can be obtained using
174
+ [`AutoImageProcessor`]. See [`CLIPImageProcessor.__call__`] for details ([]`LlavaProcessor`] uses
175
+ [`CLIPImageProcessor`] for processing images).
176
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
177
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
178
+
179
+ - 1 for tokens that are **not masked**,
180
+ - 0 for tokens that are **masked**.
181
+
182
+ [What are attention masks?](../glossary#attention-mask)
183
+
184
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
185
+ [`PreTrainedTokenizer.__call__`] for details.
186
+
187
+ If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
188
+ `past_key_values`).
189
+
190
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
191
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
192
+ information on the default strategy.
193
+
194
+ - 1 indicates the head is **not masked**,
195
+ - 0 indicates the head is **masked**.
196
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
197
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
198
+ config.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
199
+ past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
200
+ Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
201
+ `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of shape
202
+ `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.
203
+
204
+ Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
205
+ blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.
206
+
207
+ If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
208
+ don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
209
+ `decoder_input_ids` of shape `(batch_size, sequence_length)`.
210
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
211
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
212
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
213
+ model's internal embedding lookup matrix.
214
+ vision_feature_layer (`int`, *optional*, defaults to -2):
215
+ The index of the layer to select the vision feature.
216
+ vision_feature_select_strategy (`str`, *optional*, defaults to `"default"`):
217
+ The feature selection strategy used to select the vision feature from the vision backbone.
218
+ Can be one of `"default"` or `"full"`.
219
+ use_cache (`bool`, *optional*):
220
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
221
+ `past_key_values`).
222
+ output_attentions (`bool`, *optional*):
223
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
224
+ tensors for more detail.
225
+ output_hidden_states (`bool`, *optional*):
226
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
227
+ more detail.
228
+ return_dict (`bool`, *optional*):
229
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
230
+ """
231
+
232
+
233
+ @add_start_docstrings(
234
+ """The LLAVA model which consists of a vision backbone and a language model.""",
235
+ LLAVA_START_DOCSTRING,
236
+ )
237
+ class LlavaForConditionalGeneration(LlavaPreTrainedModel):
238
+
239
+ _auto_class = 'AutoModel'
240
+
241
+ def __init__(self, config: EnhancedLlavaConfig):
242
+ super().__init__(config)
243
+ self.vision_tower = AutoModel.from_config(config.vision_config)
244
+
245
+ self.multi_modal_projector = LlavaMultiModalProjector(config)
246
+ self.vocab_size = config.text_config.vocab_size
247
+ print(config.text_config)
248
+ self.language_model = AutoModelForCausalLM.from_config(
249
+ config.text_config,
250
+ attn_implementation=config._attn_implementation
251
+ )
252
+ self.pad_token_id = self.config.pad_token_id if self.config.pad_token_id is not None else -1
253
+ self.post_init()
254
+
255
+ def get_input_embeddings(self):
256
+ return self.language_model.get_input_embeddings()
257
+
258
+ def set_input_embeddings(self, value):
259
+ self.language_model.set_input_embeddings(value)
260
+
261
+ def get_output_embeddings(self):
262
+ return self.language_model.get_output_embeddings()
263
+
264
+ def set_output_embeddings(self, new_embeddings):
265
+ self.language_model.set_output_embeddings(new_embeddings)
266
+
267
+ def set_decoder(self, decoder):
268
+ self.language_model.set_decoder(decoder)
269
+
270
+ def get_decoder(self):
271
+ return self.language_model.get_decoder()
272
+
273
+ def tie_weights(self):
274
+ return self.language_model.tie_weights()
275
+
276
+ def resize_token_embeddings(self, new_num_tokens: Optional[int] = None, pad_to_multiple_of=None) -> nn.Embedding:
277
+ model_embeds = self.language_model.resize_token_embeddings(new_num_tokens, pad_to_multiple_of)
278
+ # update vocab size
279
+ self.config.text_config.vocab_size = model_embeds.num_embeddings
280
+ self.vocab_size = model_embeds.num_embeddings
281
+ return model_embeds
282
+
283
+ def _merge_input_ids_with_image_features(self, image_features, inputs_embeds, input_ids, attention_mask, labels):
284
+ num_images, num_image_patches, embed_dim = image_features.shape
285
+ batch_size, sequence_length = input_ids.shape
286
+ left_padding = not torch.sum(input_ids[:, -1] == torch.tensor(self.pad_token_id))
287
+ # 1. Create a mask to know where special image tokens are
288
+ special_image_token_mask = input_ids == self.config.image_token_index
289
+ num_special_image_tokens = torch.sum(special_image_token_mask, dim=-1)
290
+ # Compute the maximum embed dimension
291
+ max_embed_dim = (num_special_image_tokens.max() * (num_image_patches - 1)) + sequence_length
292
+ batch_indices, non_image_indices = torch.where(input_ids != self.config.image_token_index)
293
+
294
+ # 2. Compute the positions where text should be written
295
+ # Calculate new positions for text tokens in merged image-text sequence.
296
+ # `special_image_token_mask` identifies image tokens. Each image token will be replaced by `nb_text_tokens_per_images - 1` text tokens.
297
+ # `torch.cumsum` computes how each image token shifts subsequent text token positions.
298
+ # - 1 to adjust for zero-based indexing, as `cumsum` inherently increases indices by one.
299
+ new_token_positions = torch.cumsum((special_image_token_mask * (num_image_patches - 1) + 1), -1) - 1
300
+ nb_image_pad = max_embed_dim - 1 - new_token_positions[:, -1]
301
+ if left_padding:
302
+ new_token_positions += nb_image_pad[:, None] # offset for left padding
303
+ text_to_overwrite = new_token_positions[batch_indices, non_image_indices]
304
+
305
+ # 3. Create the full embedding, already padded to the maximum position
306
+ final_embedding = torch.zeros(
307
+ batch_size, max_embed_dim, embed_dim, dtype=inputs_embeds.dtype, device=inputs_embeds.device
308
+ )
309
+ final_attention_mask = torch.zeros(
310
+ batch_size, max_embed_dim, dtype=attention_mask.dtype, device=inputs_embeds.device
311
+ )
312
+ if labels is not None:
313
+ final_labels = torch.full(
314
+ (batch_size, max_embed_dim), self.config.ignore_index, dtype=input_ids.dtype, device=input_ids.device
315
+ )
316
+ # In case the Vision model or the Language model has been offloaded to CPU, we need to manually
317
+ # set the corresponding tensors into their correct target device.
318
+ target_device = inputs_embeds.device
319
+ batch_indices, non_image_indices, text_to_overwrite = (
320
+ batch_indices.to(target_device),
321
+ non_image_indices.to(target_device),
322
+ text_to_overwrite.to(target_device),
323
+ )
324
+ attention_mask = attention_mask.to(target_device)
325
+
326
+ # 4. Fill the embeddings based on the mask. If we have ["hey" "<image>", "how", "are"]
327
+ # we need to index copy on [0, 577, 578, 579] for the text and [1:576] for the image features
328
+ final_embedding[batch_indices, text_to_overwrite] = inputs_embeds[batch_indices, non_image_indices]
329
+ final_attention_mask[batch_indices, text_to_overwrite] = attention_mask[batch_indices, non_image_indices]
330
+ if labels is not None:
331
+ final_labels[batch_indices, text_to_overwrite] = labels[batch_indices, non_image_indices]
332
+
333
+ # 5. Fill the embeddings corresponding to the images. Anything that is not `text_positions` needs filling (#29835)
334
+ image_to_overwrite = torch.full(
335
+ (batch_size, max_embed_dim), True, dtype=torch.bool, device=inputs_embeds.device
336
+ )
337
+ image_to_overwrite[batch_indices, text_to_overwrite] = False
338
+ image_to_overwrite &= image_to_overwrite.cumsum(-1) - 1 >= nb_image_pad[:, None].to(target_device)
339
+
340
+ if image_to_overwrite.sum() != image_features.shape[:-1].numel():
341
+ raise ValueError(
342
+ f"The input provided to the model are wrong. The number of image tokens is {torch.sum(special_image_token_mask)} while"
343
+ f" the number of image given to the model is {num_images}. This prevents correct indexing and breaks batch generation."
344
+ )
345
+
346
+ final_embedding[image_to_overwrite] = image_features.contiguous().reshape(-1, embed_dim).to(target_device)
347
+ final_attention_mask |= image_to_overwrite
348
+ position_ids = (final_attention_mask.cumsum(-1) - 1).masked_fill_((final_attention_mask == 0), 1)
349
+
350
+ # 6. Mask out the embedding at padding positions, as we later use the past_key_value value to determine the non-attended tokens.
351
+ batch_indices, pad_indices = torch.where(input_ids == self.pad_token_id)
352
+ indices_to_mask = new_token_positions[batch_indices, pad_indices]
353
+
354
+ final_embedding[batch_indices, indices_to_mask] = 0
355
+
356
+ if labels is None:
357
+ final_labels = None
358
+
359
+ return final_embedding, final_attention_mask, final_labels, position_ids
360
+
361
+
362
+ def forward(
363
+ self,
364
+ input_ids: torch.LongTensor = None,
365
+ pixel_values: torch.FloatTensor = None,
366
+ attention_mask: Optional[torch.Tensor] = None,
367
+ position_ids: Optional[torch.LongTensor] = None,
368
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
369
+ inputs_embeds: Optional[torch.FloatTensor] = None,
370
+ vision_feature_layer: Optional[int] = None,
371
+ vision_feature_select_strategy: Optional[str] = None,
372
+ labels: Optional[torch.LongTensor] = None,
373
+ use_cache: Optional[bool] = None,
374
+ output_attentions: Optional[bool] = None,
375
+ output_hidden_states: Optional[bool] = None,
376
+ return_dict: Optional[bool] = None,
377
+ ) -> Union[Tuple, LlavaCausalLMOutputWithPast]:
378
+
379
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
380
+ output_hidden_states = (
381
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
382
+ )
383
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
384
+ vision_feature_layer = (
385
+ vision_feature_layer if vision_feature_layer is not None else self.config.vision_feature_layer
386
+ )
387
+ vision_feature_select_strategy = (
388
+ vision_feature_select_strategy
389
+ if vision_feature_select_strategy is not None
390
+ else self.config.vision_feature_select_strategy
391
+ )
392
+
393
+ if inputs_embeds is None:
394
+ # 1. Extra the input embeddings
395
+ inputs_embeds = self.get_input_embeddings()(input_ids)
396
+
397
+ # ------------- start add this ----------------
398
+ if pixel_values is None and self.training:
399
+ # all of the input is text
400
+ # If not handled properly, deadlock can occur.
401
+ # print('===================all of the input is text==============')
402
+ image_size = self.config.vision_config.image_size
403
+ pixel_values = torch.zeros(input_ids.shape[0], 3, image_size, image_size,
404
+ dtype=torch.float32,
405
+ device=input_ids.device)
406
+ image_outputs = self.vision_tower(pixel_values, output_hidden_states=True)
407
+ # this is not memory efficient at all (output_hidden_states=True) will save all the hidden stated.
408
+ selected_image_feature = image_outputs.hidden_states[vision_feature_layer]
409
+ if vision_feature_select_strategy == "default":
410
+ selected_image_feature = selected_image_feature[:, 1:]
411
+ elif vision_feature_select_strategy == "full":
412
+ selected_image_feature = selected_image_feature
413
+ else:
414
+ raise ValueError(
415
+ f"Unexpected select feature strategy: {self.config.vision_feature_select_strategy}"
416
+ )
417
+ image_features = self.multi_modal_projector(selected_image_feature)
418
+ inputs_embeds = inputs_embeds.to(image_features.dtype)
419
+ inputs_embeds, attention_mask, labels, position_ids = self._merge_input_ids_with_image_features(
420
+ image_features[0:0], inputs_embeds, input_ids, attention_mask, labels
421
+ )
422
+ # ------------- end add this ----------------
423
+ # 2. Merge text and images
424
+ elif pixel_values is not None and input_ids.shape[1] != 1:
425
+ image_outputs = self.vision_tower(pixel_values, output_hidden_states=True)
426
+ # this is not memory efficient at all (output_hidden_states=True) will save all the hidden stated.
427
+ selected_image_feature = image_outputs.hidden_states[vision_feature_layer]
428
+
429
+ if vision_feature_select_strategy == "default":
430
+ selected_image_feature = selected_image_feature[:, 1:]
431
+ elif vision_feature_select_strategy == "full":
432
+ selected_image_feature = selected_image_feature
433
+ else:
434
+ raise ValueError(
435
+ f"Unexpected select feature strategy: {self.config.vision_feature_select_strategy}"
436
+ )
437
+
438
+ image_features = self.multi_modal_projector(selected_image_feature)
439
+ inputs_embeds = inputs_embeds.to(image_features.dtype)
440
+ inputs_embeds, attention_mask, labels, position_ids = self._merge_input_ids_with_image_features(
441
+ image_features, inputs_embeds, input_ids, attention_mask, labels
442
+ )
443
+
444
+ # In case input_ids.shape[1] == 1 & pixel_values==None & past_key_values != None, we are in the case of
445
+ # generation with cache
446
+ elif past_key_values is not None and pixel_values is not None and input_ids.shape[1] == 1:
447
+ # Retrieve the first layer to inspect the logits and mask out the hidden states
448
+ # that are set to 0
449
+ first_layer_past_key_value = past_key_values[0][0][:, :, :, 0]
450
+
451
+ # Sum all dimensions of head_dim (-2) to avoid random errors such as: https://github.com/huggingface/transformers/pull/28032#issuecomment-1863691941
452
+ batch_index, non_attended_tokens = torch.where(first_layer_past_key_value.float().sum(-2) == 0)
453
+
454
+ # Get the target length
455
+ target_length = input_ids.shape[1]
456
+ past_length = first_layer_past_key_value.shape[-1]
457
+
458
+ extended_attention_mask = torch.ones(
459
+ (attention_mask.shape[0], past_length),
460
+ dtype=attention_mask.dtype,
461
+ device=attention_mask.device,
462
+ )
463
+
464
+ # Filter out only the tokens that can be un-attended, this can happen
465
+ # if one uses Llava + Fused modules where the cache on the
466
+ # first iteration is already big enough, or if one passes custom cache
467
+ valid_indices = non_attended_tokens < extended_attention_mask.size(-1)
468
+ new_batch_index = batch_index[valid_indices]
469
+ new_non_attended_tokens = non_attended_tokens[valid_indices]
470
+
471
+ # Zero-out the places where we don't need to attend
472
+ extended_attention_mask[new_batch_index, new_non_attended_tokens] = 0
473
+
474
+ attention_mask = torch.cat((extended_attention_mask, attention_mask[:, -target_length:]), dim=1)
475
+ position_ids = torch.sum(attention_mask, dim=1).unsqueeze(-1) - 1
476
+
477
+ outputs = self.language_model(
478
+ attention_mask=attention_mask,
479
+ position_ids=position_ids,
480
+ past_key_values=past_key_values,
481
+ inputs_embeds=inputs_embeds,
482
+ use_cache=use_cache,
483
+ output_attentions=output_attentions,
484
+ output_hidden_states=output_hidden_states,
485
+ return_dict=return_dict,
486
+ )
487
+
488
+ logits = outputs[0]
489
+
490
+ loss = None
491
+ if labels is not None:
492
+ # Shift so that tokens < n predict n
493
+ if attention_mask is not None:
494
+ shift_attention_mask = attention_mask[..., 1:]
495
+ shift_logits = logits[..., :-1, :][shift_attention_mask.to(logits.device) != 0].contiguous()
496
+ shift_labels = labels[..., 1:][shift_attention_mask.to(labels.device) != 0].contiguous()
497
+ else:
498
+ shift_logits = logits[..., :-1, :].contiguous()
499
+ shift_labels = labels[..., 1:].contiguous()
500
+ # Flatten the tokens
501
+ loss_fct = nn.CrossEntropyLoss()
502
+ loss = loss_fct(
503
+ shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1).to(shift_logits.device)
504
+ )
505
+
506
+ if not return_dict:
507
+ output = (logits,) + outputs[1:]
508
+ return (loss,) + output if loss is not None else output
509
+
510
+ return LlavaCausalLMOutputWithPast(
511
+ loss=loss,
512
+ logits=logits,
513
+ past_key_values=outputs.past_key_values,
514
+ hidden_states=outputs.hidden_states,
515
+ attentions=outputs.attentions,
516
+ )
517
+
518
+ def prepare_inputs_for_generation(
519
+ self, input_ids, past_key_values=None, inputs_embeds=None, pixel_values=None, attention_mask=None, **kwargs
520
+ ):
521
+ if past_key_values is not None:
522
+ if isinstance(past_key_values, Cache):
523
+ cache_length = past_key_values.get_seq_length()
524
+ past_length = past_key_values.seen_tokens
525
+ else:
526
+ cache_length = past_length = past_key_values[0][0].shape[2]
527
+
528
+ # Keep only the unprocessed tokens:
529
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
530
+ # some of the inputs are exclusively passed as part of the cache (e.g. when passing input_embeds as
531
+ # input)
532
+ if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
533
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
534
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
535
+ # input_ids based on the past_length.
536
+ elif past_length < input_ids.shape[1]:
537
+ input_ids = input_ids[:, past_length:]
538
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
539
+ elif self.config.image_token_index in input_ids:
540
+ input_ids = input_ids[:, input_ids.shape[1] - 1 :]
541
+ # If the cache has seen more tokens than it can hold, then the cache has a size limit. Let's discard the
542
+ # older attention values, as their corresponding values are not part of the input.
543
+ if cache_length < past_length and attention_mask is not None:
544
+ attention_mask = attention_mask[:, -(cache_length + input_ids.shape[1]) :]
545
+
546
+ position_ids = kwargs.get("position_ids", None)
547
+ if attention_mask is not None and position_ids is None:
548
+ # create position_ids on the fly for batch generation
549
+ position_ids = attention_mask.long().cumsum(-1) - 1
550
+ position_ids.masked_fill_(attention_mask == 0, 1)
551
+ if past_key_values:
552
+ position_ids = position_ids[:, -input_ids.shape[1] :]
553
+
554
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
555
+ if inputs_embeds is not None and past_key_values is None:
556
+ model_inputs = {"inputs_embeds": inputs_embeds}
557
+ else:
558
+ model_inputs = {"input_ids": input_ids}
559
+
560
+ model_inputs.update(
561
+ {
562
+ "position_ids": position_ids,
563
+ "past_key_values": past_key_values,
564
+ "use_cache": kwargs.get("use_cache"),
565
+ "attention_mask": attention_mask,
566
+ "pixel_values": pixel_values,
567
+ }
568
+ )
569
+ return model_inputs
570
+
571
+ def _reorder_cache(self, *args, **kwargs):
572
+ return self.language_model._reorder_cache(*args, **kwargs)
573
+
574
+ AutoModel.register(EnhancedLlavaConfig, LlavaForConditionalGeneration, exist_ok=True)
575
+ AutoModelForCausalLM.register(EnhancedLlavaConfig, LlavaForConditionalGeneration, exist_ok=True)
model_weight/preprocessor_config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": {
3
+ "height": 336,
4
+ "width": 336
5
+ },
6
+ "do_center_crop": true,
7
+ "do_convert_rgb": true,
8
+ "do_normalize": true,
9
+ "do_rescale": true,
10
+ "do_resize": true,
11
+ "image_mean": [
12
+ 0.48145466,
13
+ 0.4578275,
14
+ 0.40821073
15
+ ],
16
+ "image_processor_type": "CLIPImageProcessor",
17
+ "image_std": [
18
+ 0.26862954,
19
+ 0.26130258,
20
+ 0.27577711
21
+ ],
22
+ "processor_class": "LlavaProcessor",
23
+ "resample": 3,
24
+ "rescale_factor": 0.00392156862745098,
25
+ "size": {
26
+ "shortest_edge": 336
27
+ }
28
+ }
model_weight/special_tokens_map.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|action_start|>",
6
+ "<|action_end|>",
7
+ "<|interpreter|>",
8
+ "<|plugin|>"
9
+ ],
10
+ "bos_token": {
11
+ "content": "<s>",
12
+ "lstrip": false,
13
+ "normalized": false,
14
+ "rstrip": false,
15
+ "single_word": false
16
+ },
17
+ "eos_token": {
18
+ "content": "</s>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "</s>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ },
31
+ "unk_token": {
32
+ "content": "<unk>",
33
+ "lstrip": false,
34
+ "normalized": false,
35
+ "rstrip": false,
36
+ "single_word": false
37
+ }
38
+ }
model_weight/tokenization_internlm2.py ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on transformers/src/transformers/models/llama/tokenization_llama.py
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ """Tokenization classes for InternLM."""
19
+ import os
20
+ from shutil import copyfile
21
+ from typing import Any, Dict, List, Optional, Tuple
22
+
23
+ import sentencepiece as spm
24
+ from transformers.tokenization_utils import PreTrainedTokenizer
25
+ from transformers.utils import logging
26
+
27
+ logger = logging.get_logger(__name__)
28
+
29
+ VOCAB_FILES_NAMES = {"vocab_file": "./tokenizer.model"}
30
+
31
+ PRETRAINED_VOCAB_FILES_MAP = {}
32
+
33
+
34
+ # Modified from transformers.model.llama.tokenization_llama.LlamaTokenizer
35
+ class InternLM2Tokenizer(PreTrainedTokenizer):
36
+ """
37
+ Construct a InternLM2 tokenizer. Based on byte-level Byte-Pair-Encoding.
38
+
39
+ Args:
40
+ vocab_file (`str`):
41
+ Path to the vocabulary file.
42
+ """
43
+
44
+ vocab_files_names = VOCAB_FILES_NAMES
45
+ pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
46
+ model_input_names = ["input_ids", "attention_mask"]
47
+ _auto_class = "AutoTokenizer"
48
+
49
+ def __init__(
50
+ self,
51
+ vocab_file,
52
+ unk_token="<unk>",
53
+ bos_token="<s>",
54
+ eos_token="</s>",
55
+ pad_token="</s>",
56
+ sp_model_kwargs: Optional[Dict[str, Any]] = None,
57
+ add_bos_token=True,
58
+ add_eos_token=False,
59
+ decode_with_prefix_space=False,
60
+ clean_up_tokenization_spaces=False,
61
+ **kwargs,
62
+ ):
63
+ self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
64
+ self.vocab_file = vocab_file
65
+ self.add_bos_token = add_bos_token
66
+ self.add_eos_token = add_eos_token
67
+ self.decode_with_prefix_space = decode_with_prefix_space
68
+ self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
69
+ self.sp_model.Load(vocab_file)
70
+ self._no_prefix_space_tokens = None
71
+ super().__init__(
72
+ bos_token=bos_token,
73
+ eos_token=eos_token,
74
+ unk_token=unk_token,
75
+ pad_token=pad_token,
76
+ clean_up_tokenization_spaces=clean_up_tokenization_spaces,
77
+ **kwargs,
78
+ )
79
+
80
+ @property
81
+ def no_prefix_space_tokens(self):
82
+ if self._no_prefix_space_tokens is None:
83
+ vocab = self.convert_ids_to_tokens(list(range(self.vocab_size)))
84
+ self._no_prefix_space_tokens = {i for i, tok in enumerate(vocab) if not tok.startswith("▁")}
85
+ return self._no_prefix_space_tokens
86
+
87
+ @property
88
+ def vocab_size(self):
89
+ """Returns vocab size"""
90
+ return self.sp_model.get_piece_size()
91
+
92
+ @property
93
+ def bos_token_id(self) -> Optional[int]:
94
+ return self.sp_model.bos_id()
95
+
96
+ @property
97
+ def eos_token_id(self) -> Optional[int]:
98
+ return self.sp_model.eos_id()
99
+
100
+ def get_vocab(self):
101
+ """Returns vocab as a dict"""
102
+ vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
103
+ vocab.update(self.added_tokens_encoder)
104
+ return vocab
105
+
106
+ def _tokenize(self, text):
107
+ """Returns a tokenized string."""
108
+ return self.sp_model.encode(text, out_type=str)
109
+
110
+ def _convert_token_to_id(self, token):
111
+ """Converts a token (str) in an id using the vocab."""
112
+ return self.sp_model.piece_to_id(token)
113
+
114
+ def _convert_id_to_token(self, index):
115
+ """Converts an index (integer) in a token (str) using the vocab."""
116
+ token = self.sp_model.IdToPiece(index)
117
+ return token
118
+
119
+ def _maybe_add_prefix_space(self, tokens, decoded):
120
+ if tokens and tokens[0] not in self.no_prefix_space_tokens:
121
+ return " " + decoded
122
+ else:
123
+ return decoded
124
+
125
+ def convert_tokens_to_string(self, tokens):
126
+ """Converts a sequence of tokens (string) in a single string."""
127
+ current_sub_tokens = []
128
+ out_string = ""
129
+ prev_is_special = False
130
+ for token in tokens:
131
+ # make sure that special tokens are not decoded using sentencepiece model
132
+ if token in self.all_special_tokens:
133
+ if not prev_is_special:
134
+ out_string += " "
135
+ out_string += self.sp_model.decode(current_sub_tokens) + token
136
+ prev_is_special = True
137
+ current_sub_tokens = []
138
+ else:
139
+ current_sub_tokens.append(token)
140
+ prev_is_special = False
141
+ out_string += self.sp_model.decode(current_sub_tokens)
142
+ out_string = self.clean_up_tokenization(out_string)
143
+ out_string = self._maybe_add_prefix_space(tokens=tokens, decoded=out_string)
144
+ return out_string[1:]
145
+
146
+ def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]:
147
+ """
148
+ Save the vocabulary and special tokens file to a directory.
149
+
150
+ Args:
151
+ save_directory (`str`):
152
+ The directory in which to save the vocabulary.
153
+
154
+ Returns:
155
+ `Tuple(str)`: Paths to the files saved.
156
+ """
157
+ if not os.path.isdir(save_directory):
158
+ logger.error(f"Vocabulary path ({save_directory}) should be a directory")
159
+ return
160
+ out_vocab_file = os.path.join(
161
+ save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
162
+ )
163
+
164
+ if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
165
+ copyfile(self.vocab_file, out_vocab_file)
166
+ elif not os.path.isfile(self.vocab_file):
167
+ with open(out_vocab_file, "wb") as fi:
168
+ content_spiece_model = self.sp_model.serialized_model_proto()
169
+ fi.write(content_spiece_model)
170
+
171
+ return (out_vocab_file,)
172
+
173
+ def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
174
+ if self.add_bos_token:
175
+ bos_token_ids = [self.bos_token_id]
176
+ else:
177
+ bos_token_ids = []
178
+
179
+ output = bos_token_ids + token_ids_0
180
+
181
+ if token_ids_1 is not None:
182
+ output = output + token_ids_1
183
+
184
+ if self.add_eos_token:
185
+ output = output + [self.eos_token_id]
186
+
187
+ return output
188
+
189
+ def get_special_tokens_mask(
190
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
191
+ ) -> List[int]:
192
+ """
193
+ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
194
+ special tokens using the tokenizer `prepare_for_model` method.
195
+
196
+ Args:
197
+ token_ids_0 (`List[int]`):
198
+ List of IDs.
199
+ token_ids_1 (`List[int]`, *optional*):
200
+ Optional second list of IDs for sequence pairs.
201
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
202
+ Whether or not the token list is already formatted with special tokens for the model.
203
+
204
+ Returns:
205
+ `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
206
+ """
207
+ if already_has_special_tokens:
208
+ return super().get_special_tokens_mask(
209
+ token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
210
+ )
211
+
212
+ if token_ids_1 is None:
213
+ return [1] + ([0] * len(token_ids_0)) + [1]
214
+ return [1] + ([0] * len(token_ids_0)) + [1, 1] + ([0] * len(token_ids_1)) + [1]
215
+
216
+ def create_token_type_ids_from_sequences(
217
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
218
+ ) -> List[int]:
219
+ """
220
+ Create a mask from the two sequences passed to be used in a sequence-pair classification task. T5 does not make
221
+ use of token type ids, therefore a list of zeros is returned.
222
+
223
+ Args:
224
+ token_ids_0 (`List[int]`):
225
+ List of IDs.
226
+ token_ids_1 (`List[int]`, *optional*):
227
+ Optional second list of IDs for sequence pairs.
228
+
229
+ Returns:
230
+ `List[int]`: List of zeros.
231
+ """
232
+ eos = [self.eos_token_id]
233
+
234
+ if token_ids_1 is None:
235
+ return len(token_ids_0 + eos) * [0]
236
+ return len(token_ids_0 + eos + token_ids_1 + eos) * [0]
model_weight/tokenization_internlm2_fast.py ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on transformers/src/transformers/models/llama/tokenization_llama_fast.py
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ """Tokenization Fast class for InternLM."""
19
+ import os
20
+ from shutil import copyfile
21
+ from typing import Any, Dict, Optional, Tuple
22
+
23
+ from tokenizers import processors, decoders, Tokenizer, normalizers
24
+ from tokenizers.models import BPE
25
+
26
+ from transformers.tokenization_utils_fast import PreTrainedTokenizerFast
27
+ from transformers.utils import logging
28
+
29
+ from transformers.convert_slow_tokenizer import (
30
+ SLOW_TO_FAST_CONVERTERS,
31
+ SpmConverter,
32
+ SentencePieceExtractor,
33
+ )
34
+
35
+ from .tokenization_internlm2 import InternLM2Tokenizer
36
+
37
+ logger = logging.get_logger(__name__)
38
+
39
+ VOCAB_FILES_NAMES = {"vocab_file": "./tokenizer.model"}
40
+
41
+ # Modified from transformers.convert_slow_tokenizer.LlamaConverter
42
+ class InternLM2Converter(SpmConverter):
43
+ handle_byte_fallback = True
44
+
45
+ def vocab(self, proto):
46
+ vocab = [
47
+ ("<unk>", 0.0),
48
+ ("<s>", 0.0),
49
+ ("</s>", 0.0),
50
+ ]
51
+ vocab += [(piece.piece, piece.score) for piece in proto.pieces[3:]]
52
+ return vocab
53
+
54
+ def unk_id(self, proto):
55
+ unk_id = 0
56
+ return unk_id
57
+
58
+ def decoder(self, replacement, add_prefix_space):
59
+ return decoders.Sequence(
60
+ [
61
+ decoders.Replace("▁", " "),
62
+ decoders.ByteFallback(),
63
+ decoders.Fuse(),
64
+ decoders.Strip(content=" ", left=1),
65
+ ]
66
+ )
67
+
68
+ def tokenizer(self, proto):
69
+ model_type = proto.trainer_spec.model_type
70
+ vocab_scores = self.vocab(proto)
71
+ # special tokens
72
+ added_tokens = self.original_tokenizer.added_tokens_decoder
73
+ for i in range(len(vocab_scores)):
74
+ piece, score = vocab_scores[i]
75
+ if i in added_tokens:
76
+ vocab_scores[i] = (added_tokens[i].content, score)
77
+ if model_type == 1:
78
+ raise RuntimeError("InternLM2 is supposed to be a BPE model!")
79
+
80
+ elif model_type == 2:
81
+ _, merges = SentencePieceExtractor(self.original_tokenizer.vocab_file).extract(vocab_scores)
82
+ bpe_vocab = {word: i for i, (word, _score) in enumerate(vocab_scores)}
83
+ tokenizer = Tokenizer(
84
+ BPE(bpe_vocab, merges, unk_token=proto.trainer_spec.unk_piece, fuse_unk=True, byte_fallback=True)
85
+ )
86
+ tokenizer.add_special_tokens(
87
+ [ added_token for index, added_token in added_tokens.items()]
88
+ )
89
+ else:
90
+ raise Exception(
91
+ "You're trying to run a `Unigram` model but you're file was trained with a different algorithm"
92
+ )
93
+
94
+ return tokenizer
95
+
96
+ def normalizer(self, proto):
97
+ normalizers_list = []
98
+ if proto.normalizer_spec.add_dummy_prefix:
99
+ normalizers_list.append(normalizers.Prepend(prepend="▁"))
100
+ normalizers_list.append(normalizers.Replace(pattern=" ", content="▁"))
101
+ return normalizers.Sequence(normalizers_list)
102
+
103
+ def pre_tokenizer(self, replacement, add_prefix_space):
104
+ return None
105
+
106
+ SLOW_TO_FAST_CONVERTERS["InternLM2Tokenizer"] = InternLM2Converter
107
+
108
+
109
+ # Modified from transformers.model.llama.tokenization_llama_fast.LlamaTokenizerFast -> InternLM2TokenizerFast
110
+ class InternLM2TokenizerFast(PreTrainedTokenizerFast):
111
+ vocab_files_names = VOCAB_FILES_NAMES
112
+ slow_tokenizer_class = InternLM2Tokenizer
113
+ padding_side = "left"
114
+ model_input_names = ["input_ids", "attention_mask"]
115
+ _auto_class = "AutoTokenizer"
116
+
117
+ def __init__(
118
+ self,
119
+ vocab_file,
120
+ unk_token="<unk>",
121
+ bos_token="<s>",
122
+ eos_token="</s>",
123
+ pad_token="</s>",
124
+ sp_model_kwargs: Optional[Dict[str, Any]] = None,
125
+ add_bos_token=True,
126
+ add_eos_token=False,
127
+ decode_with_prefix_space=False,
128
+ clean_up_tokenization_spaces=False,
129
+ **kwargs,
130
+ ):
131
+ super().__init__(
132
+ vocab_file=vocab_file,
133
+ unk_token=unk_token,
134
+ bos_token=bos_token,
135
+ eos_token=eos_token,
136
+ pad_token=pad_token,
137
+ sp_model_kwargs=sp_model_kwargs,
138
+ add_bos_token=add_bos_token,
139
+ add_eos_token=add_eos_token,
140
+ decode_with_prefix_space=decode_with_prefix_space,
141
+ clean_up_tokenization_spaces=clean_up_tokenization_spaces,
142
+ **kwargs,
143
+ )
144
+ self._add_bos_token = add_bos_token
145
+ self._add_eos_token = add_eos_token
146
+ self.update_post_processor()
147
+ self.vocab_file = vocab_file
148
+
149
+ @property
150
+ def can_save_slow_tokenizer(self) -> bool:
151
+ return os.path.isfile(self.vocab_file) if self.vocab_file else False
152
+
153
+ def update_post_processor(self):
154
+ """
155
+ Updates the underlying post processor with the current `bos_token` and `eos_token`.
156
+ """
157
+ bos = self.bos_token
158
+ bos_token_id = self.bos_token_id
159
+ if bos is None and self.add_bos_token:
160
+ raise ValueError("add_bos_token = True but bos_token = None")
161
+
162
+ eos = self.eos_token
163
+ eos_token_id = self.eos_token_id
164
+ if eos is None and self.add_eos_token:
165
+ raise ValueError("add_eos_token = True but eos_token = None")
166
+
167
+ single = f"{(bos+':0 ') if self.add_bos_token else ''}$A:0{(' '+eos+':0') if self.add_eos_token else ''}"
168
+ pair = f"{single}{(' '+bos+':1') if self.add_bos_token else ''} $B:1{(' '+eos+':1') if self.add_eos_token else ''}"
169
+
170
+ special_tokens = []
171
+ if self.add_bos_token:
172
+ special_tokens.append((bos, bos_token_id))
173
+ if self.add_eos_token:
174
+ special_tokens.append((eos, eos_token_id))
175
+ self._tokenizer.post_processor = processors.TemplateProcessing(
176
+ single=single, pair=pair, special_tokens=special_tokens
177
+ )
178
+
179
+ @property
180
+ def add_eos_token(self):
181
+ return self._add_eos_token
182
+
183
+ @property
184
+ def add_bos_token(self):
185
+ return self._add_bos_token
186
+
187
+ @add_eos_token.setter
188
+ def add_eos_token(self, value):
189
+ self._add_eos_token = value
190
+ self.update_post_processor()
191
+
192
+ @add_bos_token.setter
193
+ def add_bos_token(self, value):
194
+ self._add_bos_token = value
195
+ self.update_post_processor()
196
+
197
+ def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]:
198
+ if not self.can_save_slow_tokenizer:
199
+ raise ValueError(
200
+ "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
201
+ "tokenizer."
202
+ )
203
+
204
+ if not os.path.isdir(save_directory):
205
+ logger.error(f"Vocabulary path ({save_directory}) should be a directory")
206
+ return
207
+ out_vocab_file = os.path.join(
208
+ save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
209
+ )
210
+
211
+ if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file):
212
+ copyfile(self.vocab_file, out_vocab_file)
213
+
214
+ return (out_vocab_file,)
model_weight/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
model_weight/tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f868398fc4e05ee1e8aeba95ddf18ddcc45b8bce55d5093bead5bbf80429b48b
3
+ size 1477754
model_weight/tokenizer_config.json ADDED
@@ -0,0 +1,1648 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "92352": {
30
+ "content": "E",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": false
36
+ },
37
+ "92353": {
38
+ "content": "F",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": false
44
+ },
45
+ "92354": {
46
+ "content": "G",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": false
52
+ },
53
+ "92355": {
54
+ "content": "H",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": false
60
+ },
61
+ "92356": {
62
+ "content": "I",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": false
68
+ },
69
+ "92357": {
70
+ "content": "J",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": false
76
+ },
77
+ "92358": {
78
+ "content": "K",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": false
84
+ },
85
+ "92359": {
86
+ "content": "L",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": false
92
+ },
93
+ "92360": {
94
+ "content": "M",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": false
100
+ },
101
+ "92361": {
102
+ "content": "N",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": false
108
+ },
109
+ "92362": {
110
+ "content": "R",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": false
116
+ },
117
+ "92363": {
118
+ "content": "U",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "92364": {
126
+ "content": "V",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "92365": {
134
+ "content": "W",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "92366": {
142
+ "content": "X",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "92367": {
150
+ "content": "Y",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "92368": {
158
+ "content": "Z",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "92369": {
166
+ "content": "a",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "92370": {
174
+ "content": "b",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "92371": {
182
+ "content": "c",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "92372": {
190
+ "content": "d",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "92373": {
198
+ "content": "e",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "92374": {
206
+ "content": "f",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ },
213
+ "92375": {
214
+ "content": "g",
215
+ "lstrip": false,
216
+ "normalized": false,
217
+ "rstrip": false,
218
+ "single_word": false,
219
+ "special": false
220
+ },
221
+ "92376": {
222
+ "content": "h",
223
+ "lstrip": false,
224
+ "normalized": false,
225
+ "rstrip": false,
226
+ "single_word": false,
227
+ "special": false
228
+ },
229
+ "92377": {
230
+ "content": "i",
231
+ "lstrip": false,
232
+ "normalized": false,
233
+ "rstrip": false,
234
+ "single_word": false,
235
+ "special": false
236
+ },
237
+ "92378": {
238
+ "content": "j",
239
+ "lstrip": false,
240
+ "normalized": false,
241
+ "rstrip": false,
242
+ "single_word": false,
243
+ "special": false
244
+ },
245
+ "92379": {
246
+ "content": "k",
247
+ "lstrip": false,
248
+ "normalized": false,
249
+ "rstrip": false,
250
+ "single_word": false,
251
+ "special": false
252
+ },
253
+ "92380": {
254
+ "content": "l",
255
+ "lstrip": false,
256
+ "normalized": false,
257
+ "rstrip": false,
258
+ "single_word": false,
259
+ "special": false
260
+ },
261
+ "92381": {
262
+ "content": "m",
263
+ "lstrip": false,
264
+ "normalized": false,
265
+ "rstrip": false,
266
+ "single_word": false,
267
+ "special": false
268
+ },
269
+ "92382": {
270
+ "content": "n",
271
+ "lstrip": false,
272
+ "normalized": false,
273
+ "rstrip": false,
274
+ "single_word": false,
275
+ "special": false
276
+ },
277
+ "92383": {
278
+ "content": "o",
279
+ "lstrip": false,
280
+ "normalized": false,
281
+ "rstrip": false,
282
+ "single_word": false,
283
+ "special": false
284
+ },
285
+ "92384": {
286
+ "content": "p",
287
+ "lstrip": false,
288
+ "normalized": false,
289
+ "rstrip": false,
290
+ "single_word": false,
291
+ "special": false
292
+ },
293
+ "92385": {
294
+ "content": "q",
295
+ "lstrip": false,
296
+ "normalized": false,
297
+ "rstrip": false,
298
+ "single_word": false,
299
+ "special": false
300
+ },
301
+ "92386": {
302
+ "content": "r",
303
+ "lstrip": false,
304
+ "normalized": false,
305
+ "rstrip": false,
306
+ "single_word": false,
307
+ "special": false
308
+ },
309
+ "92387": {
310
+ "content": "s",
311
+ "lstrip": false,
312
+ "normalized": false,
313
+ "rstrip": false,
314
+ "single_word": false,
315
+ "special": false
316
+ },
317
+ "92388": {
318
+ "content": "t",
319
+ "lstrip": false,
320
+ "normalized": false,
321
+ "rstrip": false,
322
+ "single_word": false,
323
+ "special": false
324
+ },
325
+ "92389": {
326
+ "content": "u",
327
+ "lstrip": false,
328
+ "normalized": false,
329
+ "rstrip": false,
330
+ "single_word": false,
331
+ "special": false
332
+ },
333
+ "92390": {
334
+ "content": "v",
335
+ "lstrip": false,
336
+ "normalized": false,
337
+ "rstrip": false,
338
+ "single_word": false,
339
+ "special": false
340
+ },
341
+ "92391": {
342
+ "content": "w",
343
+ "lstrip": false,
344
+ "normalized": false,
345
+ "rstrip": false,
346
+ "single_word": false,
347
+ "special": false
348
+ },
349
+ "92392": {
350
+ "content": "x",
351
+ "lstrip": false,
352
+ "normalized": false,
353
+ "rstrip": false,
354
+ "single_word": false,
355
+ "special": false
356
+ },
357
+ "92393": {
358
+ "content": "y",
359
+ "lstrip": false,
360
+ "normalized": false,
361
+ "rstrip": false,
362
+ "single_word": false,
363
+ "special": false
364
+ },
365
+ "92394": {
366
+ "content": "z",
367
+ "lstrip": false,
368
+ "normalized": false,
369
+ "rstrip": false,
370
+ "single_word": false,
371
+ "special": false
372
+ },
373
+ "92395": {
374
+ "content": "——",
375
+ "lstrip": false,
376
+ "normalized": false,
377
+ "rstrip": false,
378
+ "single_word": false,
379
+ "special": false
380
+ },
381
+ "92396": {
382
+ "content": "……",
383
+ "lstrip": false,
384
+ "normalized": false,
385
+ "rstrip": false,
386
+ "single_word": false,
387
+ "special": false
388
+ },
389
+ "92397": {
390
+ "content": "[UNUSED_TOKEN_0]",
391
+ "lstrip": false,
392
+ "normalized": false,
393
+ "rstrip": false,
394
+ "single_word": false,
395
+ "special": false
396
+ },
397
+ "92398": {
398
+ "content": "[UNUSED_TOKEN_1]",
399
+ "lstrip": false,
400
+ "normalized": false,
401
+ "rstrip": false,
402
+ "single_word": false,
403
+ "special": false
404
+ },
405
+ "92399": {
406
+ "content": "[UNUSED_TOKEN_2]",
407
+ "lstrip": false,
408
+ "normalized": false,
409
+ "rstrip": false,
410
+ "single_word": false,
411
+ "special": false
412
+ },
413
+ "92400": {
414
+ "content": "[UNUSED_TOKEN_3]",
415
+ "lstrip": false,
416
+ "normalized": false,
417
+ "rstrip": false,
418
+ "single_word": false,
419
+ "special": false
420
+ },
421
+ "92401": {
422
+ "content": "[UNUSED_TOKEN_4]",
423
+ "lstrip": false,
424
+ "normalized": false,
425
+ "rstrip": false,
426
+ "single_word": false,
427
+ "special": false
428
+ },
429
+ "92402": {
430
+ "content": "[UNUSED_TOKEN_5]",
431
+ "lstrip": false,
432
+ "normalized": false,
433
+ "rstrip": false,
434
+ "single_word": false,
435
+ "special": false
436
+ },
437
+ "92403": {
438
+ "content": "[UNUSED_TOKEN_6]",
439
+ "lstrip": false,
440
+ "normalized": false,
441
+ "rstrip": false,
442
+ "single_word": false,
443
+ "special": false
444
+ },
445
+ "92404": {
446
+ "content": "[UNUSED_TOKEN_7]",
447
+ "lstrip": false,
448
+ "normalized": false,
449
+ "rstrip": false,
450
+ "single_word": false,
451
+ "special": false
452
+ },
453
+ "92405": {
454
+ "content": "[UNUSED_TOKEN_8]",
455
+ "lstrip": false,
456
+ "normalized": false,
457
+ "rstrip": false,
458
+ "single_word": false,
459
+ "special": false
460
+ },
461
+ "92406": {
462
+ "content": "[UNUSED_TOKEN_9]",
463
+ "lstrip": false,
464
+ "normalized": false,
465
+ "rstrip": false,
466
+ "single_word": false,
467
+ "special": false
468
+ },
469
+ "92407": {
470
+ "content": "[UNUSED_TOKEN_10]",
471
+ "lstrip": false,
472
+ "normalized": false,
473
+ "rstrip": false,
474
+ "single_word": false,
475
+ "special": false
476
+ },
477
+ "92408": {
478
+ "content": "[UNUSED_TOKEN_11]",
479
+ "lstrip": false,
480
+ "normalized": false,
481
+ "rstrip": false,
482
+ "single_word": false,
483
+ "special": false
484
+ },
485
+ "92409": {
486
+ "content": "[UNUSED_TOKEN_12]",
487
+ "lstrip": false,
488
+ "normalized": false,
489
+ "rstrip": false,
490
+ "single_word": false,
491
+ "special": false
492
+ },
493
+ "92410": {
494
+ "content": "[UNUSED_TOKEN_13]",
495
+ "lstrip": false,
496
+ "normalized": false,
497
+ "rstrip": false,
498
+ "single_word": false,
499
+ "special": false
500
+ },
501
+ "92411": {
502
+ "content": "[UNUSED_TOKEN_14]",
503
+ "lstrip": false,
504
+ "normalized": false,
505
+ "rstrip": false,
506
+ "single_word": false,
507
+ "special": false
508
+ },
509
+ "92412": {
510
+ "content": "[UNUSED_TOKEN_15]",
511
+ "lstrip": false,
512
+ "normalized": false,
513
+ "rstrip": false,
514
+ "single_word": false,
515
+ "special": false
516
+ },
517
+ "92413": {
518
+ "content": "[UNUSED_TOKEN_16]",
519
+ "lstrip": false,
520
+ "normalized": false,
521
+ "rstrip": false,
522
+ "single_word": false,
523
+ "special": false
524
+ },
525
+ "92414": {
526
+ "content": "[UNUSED_TOKEN_17]",
527
+ "lstrip": false,
528
+ "normalized": false,
529
+ "rstrip": false,
530
+ "single_word": false,
531
+ "special": false
532
+ },
533
+ "92415": {
534
+ "content": "[UNUSED_TOKEN_18]",
535
+ "lstrip": false,
536
+ "normalized": false,
537
+ "rstrip": false,
538
+ "single_word": false,
539
+ "special": false
540
+ },
541
+ "92416": {
542
+ "content": "[UNUSED_TOKEN_19]",
543
+ "lstrip": false,
544
+ "normalized": false,
545
+ "rstrip": false,
546
+ "single_word": false,
547
+ "special": false
548
+ },
549
+ "92417": {
550
+ "content": "[UNUSED_TOKEN_20]",
551
+ "lstrip": false,
552
+ "normalized": false,
553
+ "rstrip": false,
554
+ "single_word": false,
555
+ "special": false
556
+ },
557
+ "92418": {
558
+ "content": "[UNUSED_TOKEN_21]",
559
+ "lstrip": false,
560
+ "normalized": false,
561
+ "rstrip": false,
562
+ "single_word": false,
563
+ "special": false
564
+ },
565
+ "92419": {
566
+ "content": "[UNUSED_TOKEN_22]",
567
+ "lstrip": false,
568
+ "normalized": false,
569
+ "rstrip": false,
570
+ "single_word": false,
571
+ "special": false
572
+ },
573
+ "92420": {
574
+ "content": "[UNUSED_TOKEN_23]",
575
+ "lstrip": false,
576
+ "normalized": false,
577
+ "rstrip": false,
578
+ "single_word": false,
579
+ "special": false
580
+ },
581
+ "92421": {
582
+ "content": "[UNUSED_TOKEN_24]",
583
+ "lstrip": false,
584
+ "normalized": false,
585
+ "rstrip": false,
586
+ "single_word": false,
587
+ "special": false
588
+ },
589
+ "92422": {
590
+ "content": "[UNUSED_TOKEN_25]",
591
+ "lstrip": false,
592
+ "normalized": false,
593
+ "rstrip": false,
594
+ "single_word": false,
595
+ "special": false
596
+ },
597
+ "92423": {
598
+ "content": "[UNUSED_TOKEN_26]",
599
+ "lstrip": false,
600
+ "normalized": false,
601
+ "rstrip": false,
602
+ "single_word": false,
603
+ "special": false
604
+ },
605
+ "92424": {
606
+ "content": "[UNUSED_TOKEN_27]",
607
+ "lstrip": false,
608
+ "normalized": false,
609
+ "rstrip": false,
610
+ "single_word": false,
611
+ "special": false
612
+ },
613
+ "92425": {
614
+ "content": "[UNUSED_TOKEN_28]",
615
+ "lstrip": false,
616
+ "normalized": false,
617
+ "rstrip": false,
618
+ "single_word": false,
619
+ "special": false
620
+ },
621
+ "92426": {
622
+ "content": "[UNUSED_TOKEN_29]",
623
+ "lstrip": false,
624
+ "normalized": false,
625
+ "rstrip": false,
626
+ "single_word": false,
627
+ "special": false
628
+ },
629
+ "92427": {
630
+ "content": "[UNUSED_TOKEN_30]",
631
+ "lstrip": false,
632
+ "normalized": false,
633
+ "rstrip": false,
634
+ "single_word": false,
635
+ "special": false
636
+ },
637
+ "92428": {
638
+ "content": "[UNUSED_TOKEN_31]",
639
+ "lstrip": false,
640
+ "normalized": false,
641
+ "rstrip": false,
642
+ "single_word": false,
643
+ "special": false
644
+ },
645
+ "92429": {
646
+ "content": "[UNUSED_TOKEN_32]",
647
+ "lstrip": false,
648
+ "normalized": false,
649
+ "rstrip": false,
650
+ "single_word": false,
651
+ "special": false
652
+ },
653
+ "92430": {
654
+ "content": "[UNUSED_TOKEN_33]",
655
+ "lstrip": false,
656
+ "normalized": false,
657
+ "rstrip": false,
658
+ "single_word": false,
659
+ "special": false
660
+ },
661
+ "92431": {
662
+ "content": "[UNUSED_TOKEN_34]",
663
+ "lstrip": false,
664
+ "normalized": false,
665
+ "rstrip": false,
666
+ "single_word": false,
667
+ "special": false
668
+ },
669
+ "92432": {
670
+ "content": "[UNUSED_TOKEN_35]",
671
+ "lstrip": false,
672
+ "normalized": false,
673
+ "rstrip": false,
674
+ "single_word": false,
675
+ "special": false
676
+ },
677
+ "92433": {
678
+ "content": "[UNUSED_TOKEN_36]",
679
+ "lstrip": false,
680
+ "normalized": false,
681
+ "rstrip": false,
682
+ "single_word": false,
683
+ "special": false
684
+ },
685
+ "92434": {
686
+ "content": "[UNUSED_TOKEN_37]",
687
+ "lstrip": false,
688
+ "normalized": false,
689
+ "rstrip": false,
690
+ "single_word": false,
691
+ "special": false
692
+ },
693
+ "92435": {
694
+ "content": "[UNUSED_TOKEN_38]",
695
+ "lstrip": false,
696
+ "normalized": false,
697
+ "rstrip": false,
698
+ "single_word": false,
699
+ "special": false
700
+ },
701
+ "92436": {
702
+ "content": "[UNUSED_TOKEN_39]",
703
+ "lstrip": false,
704
+ "normalized": false,
705
+ "rstrip": false,
706
+ "single_word": false,
707
+ "special": false
708
+ },
709
+ "92437": {
710
+ "content": "[UNUSED_TOKEN_40]",
711
+ "lstrip": false,
712
+ "normalized": false,
713
+ "rstrip": false,
714
+ "single_word": false,
715
+ "special": false
716
+ },
717
+ "92438": {
718
+ "content": "[UNUSED_TOKEN_41]",
719
+ "lstrip": false,
720
+ "normalized": false,
721
+ "rstrip": false,
722
+ "single_word": false,
723
+ "special": false
724
+ },
725
+ "92439": {
726
+ "content": "[UNUSED_TOKEN_42]",
727
+ "lstrip": false,
728
+ "normalized": false,
729
+ "rstrip": false,
730
+ "single_word": false,
731
+ "special": false
732
+ },
733
+ "92440": {
734
+ "content": "[UNUSED_TOKEN_43]",
735
+ "lstrip": false,
736
+ "normalized": false,
737
+ "rstrip": false,
738
+ "single_word": false,
739
+ "special": false
740
+ },
741
+ "92441": {
742
+ "content": "[UNUSED_TOKEN_44]",
743
+ "lstrip": false,
744
+ "normalized": false,
745
+ "rstrip": false,
746
+ "single_word": false,
747
+ "special": false
748
+ },
749
+ "92442": {
750
+ "content": "[UNUSED_TOKEN_45]",
751
+ "lstrip": false,
752
+ "normalized": false,
753
+ "rstrip": false,
754
+ "single_word": false,
755
+ "special": false
756
+ },
757
+ "92443": {
758
+ "content": "[UNUSED_TOKEN_46]",
759
+ "lstrip": false,
760
+ "normalized": false,
761
+ "rstrip": false,
762
+ "single_word": false,
763
+ "special": false
764
+ },
765
+ "92444": {
766
+ "content": "[UNUSED_TOKEN_47]",
767
+ "lstrip": false,
768
+ "normalized": false,
769
+ "rstrip": false,
770
+ "single_word": false,
771
+ "special": false
772
+ },
773
+ "92445": {
774
+ "content": "[UNUSED_TOKEN_48]",
775
+ "lstrip": false,
776
+ "normalized": false,
777
+ "rstrip": false,
778
+ "single_word": false,
779
+ "special": false
780
+ },
781
+ "92446": {
782
+ "content": "[UNUSED_TOKEN_49]",
783
+ "lstrip": false,
784
+ "normalized": false,
785
+ "rstrip": false,
786
+ "single_word": false,
787
+ "special": false
788
+ },
789
+ "92447": {
790
+ "content": "[UNUSED_TOKEN_50]",
791
+ "lstrip": false,
792
+ "normalized": false,
793
+ "rstrip": false,
794
+ "single_word": false,
795
+ "special": false
796
+ },
797
+ "92448": {
798
+ "content": "[UNUSED_TOKEN_51]",
799
+ "lstrip": false,
800
+ "normalized": false,
801
+ "rstrip": false,
802
+ "single_word": false,
803
+ "special": false
804
+ },
805
+ "92449": {
806
+ "content": "[UNUSED_TOKEN_52]",
807
+ "lstrip": false,
808
+ "normalized": false,
809
+ "rstrip": false,
810
+ "single_word": false,
811
+ "special": false
812
+ },
813
+ "92450": {
814
+ "content": "[UNUSED_TOKEN_53]",
815
+ "lstrip": false,
816
+ "normalized": false,
817
+ "rstrip": false,
818
+ "single_word": false,
819
+ "special": false
820
+ },
821
+ "92451": {
822
+ "content": "[UNUSED_TOKEN_54]",
823
+ "lstrip": false,
824
+ "normalized": false,
825
+ "rstrip": false,
826
+ "single_word": false,
827
+ "special": false
828
+ },
829
+ "92452": {
830
+ "content": "[UNUSED_TOKEN_55]",
831
+ "lstrip": false,
832
+ "normalized": false,
833
+ "rstrip": false,
834
+ "single_word": false,
835
+ "special": false
836
+ },
837
+ "92453": {
838
+ "content": "[UNUSED_TOKEN_56]",
839
+ "lstrip": false,
840
+ "normalized": false,
841
+ "rstrip": false,
842
+ "single_word": false,
843
+ "special": false
844
+ },
845
+ "92454": {
846
+ "content": "[UNUSED_TOKEN_57]",
847
+ "lstrip": false,
848
+ "normalized": false,
849
+ "rstrip": false,
850
+ "single_word": false,
851
+ "special": false
852
+ },
853
+ "92455": {
854
+ "content": "[UNUSED_TOKEN_58]",
855
+ "lstrip": false,
856
+ "normalized": false,
857
+ "rstrip": false,
858
+ "single_word": false,
859
+ "special": false
860
+ },
861
+ "92456": {
862
+ "content": "[UNUSED_TOKEN_59]",
863
+ "lstrip": false,
864
+ "normalized": false,
865
+ "rstrip": false,
866
+ "single_word": false,
867
+ "special": false
868
+ },
869
+ "92457": {
870
+ "content": "[UNUSED_TOKEN_60]",
871
+ "lstrip": false,
872
+ "normalized": false,
873
+ "rstrip": false,
874
+ "single_word": false,
875
+ "special": false
876
+ },
877
+ "92458": {
878
+ "content": "[UNUSED_TOKEN_61]",
879
+ "lstrip": false,
880
+ "normalized": false,
881
+ "rstrip": false,
882
+ "single_word": false,
883
+ "special": false
884
+ },
885
+ "92459": {
886
+ "content": "[UNUSED_TOKEN_62]",
887
+ "lstrip": false,
888
+ "normalized": false,
889
+ "rstrip": false,
890
+ "single_word": false,
891
+ "special": false
892
+ },
893
+ "92460": {
894
+ "content": "[UNUSED_TOKEN_63]",
895
+ "lstrip": false,
896
+ "normalized": false,
897
+ "rstrip": false,
898
+ "single_word": false,
899
+ "special": false
900
+ },
901
+ "92461": {
902
+ "content": "[UNUSED_TOKEN_64]",
903
+ "lstrip": false,
904
+ "normalized": false,
905
+ "rstrip": false,
906
+ "single_word": false,
907
+ "special": false
908
+ },
909
+ "92462": {
910
+ "content": "[UNUSED_TOKEN_65]",
911
+ "lstrip": false,
912
+ "normalized": false,
913
+ "rstrip": false,
914
+ "single_word": false,
915
+ "special": false
916
+ },
917
+ "92463": {
918
+ "content": "[UNUSED_TOKEN_66]",
919
+ "lstrip": false,
920
+ "normalized": false,
921
+ "rstrip": false,
922
+ "single_word": false,
923
+ "special": false
924
+ },
925
+ "92464": {
926
+ "content": "[UNUSED_TOKEN_67]",
927
+ "lstrip": false,
928
+ "normalized": false,
929
+ "rstrip": false,
930
+ "single_word": false,
931
+ "special": false
932
+ },
933
+ "92465": {
934
+ "content": "[UNUSED_TOKEN_68]",
935
+ "lstrip": false,
936
+ "normalized": false,
937
+ "rstrip": false,
938
+ "single_word": false,
939
+ "special": false
940
+ },
941
+ "92466": {
942
+ "content": "[UNUSED_TOKEN_69]",
943
+ "lstrip": false,
944
+ "normalized": false,
945
+ "rstrip": false,
946
+ "single_word": false,
947
+ "special": false
948
+ },
949
+ "92467": {
950
+ "content": "[UNUSED_TOKEN_70]",
951
+ "lstrip": false,
952
+ "normalized": false,
953
+ "rstrip": false,
954
+ "single_word": false,
955
+ "special": false
956
+ },
957
+ "92468": {
958
+ "content": "[UNUSED_TOKEN_71]",
959
+ "lstrip": false,
960
+ "normalized": false,
961
+ "rstrip": false,
962
+ "single_word": false,
963
+ "special": false
964
+ },
965
+ "92469": {
966
+ "content": "[UNUSED_TOKEN_72]",
967
+ "lstrip": false,
968
+ "normalized": false,
969
+ "rstrip": false,
970
+ "single_word": false,
971
+ "special": false
972
+ },
973
+ "92470": {
974
+ "content": "[UNUSED_TOKEN_73]",
975
+ "lstrip": false,
976
+ "normalized": false,
977
+ "rstrip": false,
978
+ "single_word": false,
979
+ "special": false
980
+ },
981
+ "92471": {
982
+ "content": "[UNUSED_TOKEN_74]",
983
+ "lstrip": false,
984
+ "normalized": false,
985
+ "rstrip": false,
986
+ "single_word": false,
987
+ "special": false
988
+ },
989
+ "92472": {
990
+ "content": "[UNUSED_TOKEN_75]",
991
+ "lstrip": false,
992
+ "normalized": false,
993
+ "rstrip": false,
994
+ "single_word": false,
995
+ "special": false
996
+ },
997
+ "92473": {
998
+ "content": "[UNUSED_TOKEN_76]",
999
+ "lstrip": false,
1000
+ "normalized": false,
1001
+ "rstrip": false,
1002
+ "single_word": false,
1003
+ "special": false
1004
+ },
1005
+ "92474": {
1006
+ "content": "[UNUSED_TOKEN_77]",
1007
+ "lstrip": false,
1008
+ "normalized": false,
1009
+ "rstrip": false,
1010
+ "single_word": false,
1011
+ "special": false
1012
+ },
1013
+ "92475": {
1014
+ "content": "[UNUSED_TOKEN_78]",
1015
+ "lstrip": false,
1016
+ "normalized": false,
1017
+ "rstrip": false,
1018
+ "single_word": false,
1019
+ "special": false
1020
+ },
1021
+ "92476": {
1022
+ "content": "[UNUSED_TOKEN_79]",
1023
+ "lstrip": false,
1024
+ "normalized": false,
1025
+ "rstrip": false,
1026
+ "single_word": false,
1027
+ "special": false
1028
+ },
1029
+ "92477": {
1030
+ "content": "[UNUSED_TOKEN_80]",
1031
+ "lstrip": false,
1032
+ "normalized": false,
1033
+ "rstrip": false,
1034
+ "single_word": false,
1035
+ "special": false
1036
+ },
1037
+ "92478": {
1038
+ "content": "[UNUSED_TOKEN_81]",
1039
+ "lstrip": false,
1040
+ "normalized": false,
1041
+ "rstrip": false,
1042
+ "single_word": false,
1043
+ "special": false
1044
+ },
1045
+ "92479": {
1046
+ "content": "[UNUSED_TOKEN_82]",
1047
+ "lstrip": false,
1048
+ "normalized": false,
1049
+ "rstrip": false,
1050
+ "single_word": false,
1051
+ "special": false
1052
+ },
1053
+ "92480": {
1054
+ "content": "[UNUSED_TOKEN_83]",
1055
+ "lstrip": false,
1056
+ "normalized": false,
1057
+ "rstrip": false,
1058
+ "single_word": false,
1059
+ "special": false
1060
+ },
1061
+ "92481": {
1062
+ "content": "[UNUSED_TOKEN_84]",
1063
+ "lstrip": false,
1064
+ "normalized": false,
1065
+ "rstrip": false,
1066
+ "single_word": false,
1067
+ "special": false
1068
+ },
1069
+ "92482": {
1070
+ "content": "[UNUSED_TOKEN_85]",
1071
+ "lstrip": false,
1072
+ "normalized": false,
1073
+ "rstrip": false,
1074
+ "single_word": false,
1075
+ "special": false
1076
+ },
1077
+ "92483": {
1078
+ "content": "[UNUSED_TOKEN_86]",
1079
+ "lstrip": false,
1080
+ "normalized": false,
1081
+ "rstrip": false,
1082
+ "single_word": false,
1083
+ "special": false
1084
+ },
1085
+ "92484": {
1086
+ "content": "[UNUSED_TOKEN_87]",
1087
+ "lstrip": false,
1088
+ "normalized": false,
1089
+ "rstrip": false,
1090
+ "single_word": false,
1091
+ "special": false
1092
+ },
1093
+ "92485": {
1094
+ "content": "[UNUSED_TOKEN_88]",
1095
+ "lstrip": false,
1096
+ "normalized": false,
1097
+ "rstrip": false,
1098
+ "single_word": false,
1099
+ "special": false
1100
+ },
1101
+ "92486": {
1102
+ "content": "[UNUSED_TOKEN_89]",
1103
+ "lstrip": false,
1104
+ "normalized": false,
1105
+ "rstrip": false,
1106
+ "single_word": false,
1107
+ "special": false
1108
+ },
1109
+ "92487": {
1110
+ "content": "[UNUSED_TOKEN_90]",
1111
+ "lstrip": false,
1112
+ "normalized": false,
1113
+ "rstrip": false,
1114
+ "single_word": false,
1115
+ "special": false
1116
+ },
1117
+ "92488": {
1118
+ "content": "[UNUSED_TOKEN_91]",
1119
+ "lstrip": false,
1120
+ "normalized": false,
1121
+ "rstrip": false,
1122
+ "single_word": false,
1123
+ "special": false
1124
+ },
1125
+ "92489": {
1126
+ "content": "[UNUSED_TOKEN_92]",
1127
+ "lstrip": false,
1128
+ "normalized": false,
1129
+ "rstrip": false,
1130
+ "single_word": false,
1131
+ "special": false
1132
+ },
1133
+ "92490": {
1134
+ "content": "[UNUSED_TOKEN_93]",
1135
+ "lstrip": false,
1136
+ "normalized": false,
1137
+ "rstrip": false,
1138
+ "single_word": false,
1139
+ "special": false
1140
+ },
1141
+ "92491": {
1142
+ "content": "[UNUSED_TOKEN_94]",
1143
+ "lstrip": false,
1144
+ "normalized": false,
1145
+ "rstrip": false,
1146
+ "single_word": false,
1147
+ "special": false
1148
+ },
1149
+ "92492": {
1150
+ "content": "[UNUSED_TOKEN_95]",
1151
+ "lstrip": false,
1152
+ "normalized": false,
1153
+ "rstrip": false,
1154
+ "single_word": false,
1155
+ "special": false
1156
+ },
1157
+ "92493": {
1158
+ "content": "[UNUSED_TOKEN_96]",
1159
+ "lstrip": false,
1160
+ "normalized": false,
1161
+ "rstrip": false,
1162
+ "single_word": false,
1163
+ "special": false
1164
+ },
1165
+ "92494": {
1166
+ "content": "[UNUSED_TOKEN_97]",
1167
+ "lstrip": false,
1168
+ "normalized": false,
1169
+ "rstrip": false,
1170
+ "single_word": false,
1171
+ "special": false
1172
+ },
1173
+ "92495": {
1174
+ "content": "[UNUSED_TOKEN_98]",
1175
+ "lstrip": false,
1176
+ "normalized": false,
1177
+ "rstrip": false,
1178
+ "single_word": false,
1179
+ "special": false
1180
+ },
1181
+ "92496": {
1182
+ "content": "[UNUSED_TOKEN_99]",
1183
+ "lstrip": false,
1184
+ "normalized": false,
1185
+ "rstrip": false,
1186
+ "single_word": false,
1187
+ "special": false
1188
+ },
1189
+ "92497": {
1190
+ "content": "[UNUSED_TOKEN_100]",
1191
+ "lstrip": false,
1192
+ "normalized": false,
1193
+ "rstrip": false,
1194
+ "single_word": false,
1195
+ "special": false
1196
+ },
1197
+ "92498": {
1198
+ "content": "[UNUSED_TOKEN_101]",
1199
+ "lstrip": false,
1200
+ "normalized": false,
1201
+ "rstrip": false,
1202
+ "single_word": false,
1203
+ "special": false
1204
+ },
1205
+ "92499": {
1206
+ "content": "[UNUSED_TOKEN_102]",
1207
+ "lstrip": false,
1208
+ "normalized": false,
1209
+ "rstrip": false,
1210
+ "single_word": false,
1211
+ "special": false
1212
+ },
1213
+ "92500": {
1214
+ "content": "[UNUSED_TOKEN_103]",
1215
+ "lstrip": false,
1216
+ "normalized": false,
1217
+ "rstrip": false,
1218
+ "single_word": false,
1219
+ "special": false
1220
+ },
1221
+ "92501": {
1222
+ "content": "[UNUSED_TOKEN_104]",
1223
+ "lstrip": false,
1224
+ "normalized": false,
1225
+ "rstrip": false,
1226
+ "single_word": false,
1227
+ "special": false
1228
+ },
1229
+ "92502": {
1230
+ "content": "[UNUSED_TOKEN_105]",
1231
+ "lstrip": false,
1232
+ "normalized": false,
1233
+ "rstrip": false,
1234
+ "single_word": false,
1235
+ "special": false
1236
+ },
1237
+ "92503": {
1238
+ "content": "[UNUSED_TOKEN_106]",
1239
+ "lstrip": false,
1240
+ "normalized": false,
1241
+ "rstrip": false,
1242
+ "single_word": false,
1243
+ "special": false
1244
+ },
1245
+ "92504": {
1246
+ "content": "[UNUSED_TOKEN_107]",
1247
+ "lstrip": false,
1248
+ "normalized": false,
1249
+ "rstrip": false,
1250
+ "single_word": false,
1251
+ "special": false
1252
+ },
1253
+ "92505": {
1254
+ "content": "[UNUSED_TOKEN_108]",
1255
+ "lstrip": false,
1256
+ "normalized": false,
1257
+ "rstrip": false,
1258
+ "single_word": false,
1259
+ "special": false
1260
+ },
1261
+ "92506": {
1262
+ "content": "[UNUSED_TOKEN_109]",
1263
+ "lstrip": false,
1264
+ "normalized": false,
1265
+ "rstrip": false,
1266
+ "single_word": false,
1267
+ "special": false
1268
+ },
1269
+ "92507": {
1270
+ "content": "[UNUSED_TOKEN_110]",
1271
+ "lstrip": false,
1272
+ "normalized": false,
1273
+ "rstrip": false,
1274
+ "single_word": false,
1275
+ "special": false
1276
+ },
1277
+ "92508": {
1278
+ "content": "[UNUSED_TOKEN_111]",
1279
+ "lstrip": false,
1280
+ "normalized": false,
1281
+ "rstrip": false,
1282
+ "single_word": false,
1283
+ "special": false
1284
+ },
1285
+ "92509": {
1286
+ "content": "[UNUSED_TOKEN_112]",
1287
+ "lstrip": false,
1288
+ "normalized": false,
1289
+ "rstrip": false,
1290
+ "single_word": false,
1291
+ "special": false
1292
+ },
1293
+ "92510": {
1294
+ "content": "[UNUSED_TOKEN_113]",
1295
+ "lstrip": false,
1296
+ "normalized": false,
1297
+ "rstrip": false,
1298
+ "single_word": false,
1299
+ "special": false
1300
+ },
1301
+ "92511": {
1302
+ "content": "[UNUSED_TOKEN_114]",
1303
+ "lstrip": false,
1304
+ "normalized": false,
1305
+ "rstrip": false,
1306
+ "single_word": false,
1307
+ "special": false
1308
+ },
1309
+ "92512": {
1310
+ "content": "[UNUSED_TOKEN_115]",
1311
+ "lstrip": false,
1312
+ "normalized": false,
1313
+ "rstrip": false,
1314
+ "single_word": false,
1315
+ "special": false
1316
+ },
1317
+ "92513": {
1318
+ "content": "[UNUSED_TOKEN_116]",
1319
+ "lstrip": false,
1320
+ "normalized": false,
1321
+ "rstrip": false,
1322
+ "single_word": false,
1323
+ "special": false
1324
+ },
1325
+ "92514": {
1326
+ "content": "[UNUSED_TOKEN_117]",
1327
+ "lstrip": false,
1328
+ "normalized": false,
1329
+ "rstrip": false,
1330
+ "single_word": false,
1331
+ "special": false
1332
+ },
1333
+ "92515": {
1334
+ "content": "[UNUSED_TOKEN_118]",
1335
+ "lstrip": false,
1336
+ "normalized": false,
1337
+ "rstrip": false,
1338
+ "single_word": false,
1339
+ "special": false
1340
+ },
1341
+ "92516": {
1342
+ "content": "[UNUSED_TOKEN_119]",
1343
+ "lstrip": false,
1344
+ "normalized": false,
1345
+ "rstrip": false,
1346
+ "single_word": false,
1347
+ "special": false
1348
+ },
1349
+ "92517": {
1350
+ "content": "[UNUSED_TOKEN_120]",
1351
+ "lstrip": false,
1352
+ "normalized": false,
1353
+ "rstrip": false,
1354
+ "single_word": false,
1355
+ "special": false
1356
+ },
1357
+ "92518": {
1358
+ "content": "[UNUSED_TOKEN_121]",
1359
+ "lstrip": false,
1360
+ "normalized": false,
1361
+ "rstrip": false,
1362
+ "single_word": false,
1363
+ "special": false
1364
+ },
1365
+ "92519": {
1366
+ "content": "[UNUSED_TOKEN_122]",
1367
+ "lstrip": false,
1368
+ "normalized": false,
1369
+ "rstrip": false,
1370
+ "single_word": false,
1371
+ "special": false
1372
+ },
1373
+ "92520": {
1374
+ "content": "[UNUSED_TOKEN_123]",
1375
+ "lstrip": false,
1376
+ "normalized": false,
1377
+ "rstrip": false,
1378
+ "single_word": false,
1379
+ "special": false
1380
+ },
1381
+ "92521": {
1382
+ "content": "[UNUSED_TOKEN_124]",
1383
+ "lstrip": false,
1384
+ "normalized": false,
1385
+ "rstrip": false,
1386
+ "single_word": false,
1387
+ "special": false
1388
+ },
1389
+ "92522": {
1390
+ "content": "[UNUSED_TOKEN_125]",
1391
+ "lstrip": false,
1392
+ "normalized": false,
1393
+ "rstrip": false,
1394
+ "single_word": false,
1395
+ "special": false
1396
+ },
1397
+ "92523": {
1398
+ "content": "[UNUSED_TOKEN_126]",
1399
+ "lstrip": false,
1400
+ "normalized": false,
1401
+ "rstrip": false,
1402
+ "single_word": false,
1403
+ "special": false
1404
+ },
1405
+ "92524": {
1406
+ "content": "[UNUSED_TOKEN_127]",
1407
+ "lstrip": false,
1408
+ "normalized": false,
1409
+ "rstrip": false,
1410
+ "single_word": false,
1411
+ "special": false
1412
+ },
1413
+ "92525": {
1414
+ "content": "[UNUSED_TOKEN_128]",
1415
+ "lstrip": false,
1416
+ "normalized": false,
1417
+ "rstrip": false,
1418
+ "single_word": false,
1419
+ "special": false
1420
+ },
1421
+ "92526": {
1422
+ "content": "[UNUSED_TOKEN_129]",
1423
+ "lstrip": false,
1424
+ "normalized": false,
1425
+ "rstrip": false,
1426
+ "single_word": false,
1427
+ "special": false
1428
+ },
1429
+ "92527": {
1430
+ "content": "[UNUSED_TOKEN_130]",
1431
+ "lstrip": false,
1432
+ "normalized": false,
1433
+ "rstrip": false,
1434
+ "single_word": false,
1435
+ "special": false
1436
+ },
1437
+ "92528": {
1438
+ "content": "[UNUSED_TOKEN_131]",
1439
+ "lstrip": false,
1440
+ "normalized": false,
1441
+ "rstrip": false,
1442
+ "single_word": false,
1443
+ "special": false
1444
+ },
1445
+ "92529": {
1446
+ "content": "[UNUSED_TOKEN_132]",
1447
+ "lstrip": false,
1448
+ "normalized": false,
1449
+ "rstrip": false,
1450
+ "single_word": false,
1451
+ "special": false
1452
+ },
1453
+ "92530": {
1454
+ "content": "[UNUSED_TOKEN_133]",
1455
+ "lstrip": false,
1456
+ "normalized": false,
1457
+ "rstrip": false,
1458
+ "single_word": false,
1459
+ "special": false
1460
+ },
1461
+ "92531": {
1462
+ "content": "[UNUSED_TOKEN_134]",
1463
+ "lstrip": false,
1464
+ "normalized": false,
1465
+ "rstrip": false,
1466
+ "single_word": false,
1467
+ "special": false
1468
+ },
1469
+ "92532": {
1470
+ "content": "[UNUSED_TOKEN_135]",
1471
+ "lstrip": false,
1472
+ "normalized": false,
1473
+ "rstrip": false,
1474
+ "single_word": false,
1475
+ "special": false
1476
+ },
1477
+ "92533": {
1478
+ "content": "[UNUSED_TOKEN_136]",
1479
+ "lstrip": false,
1480
+ "normalized": false,
1481
+ "rstrip": false,
1482
+ "single_word": false,
1483
+ "special": false
1484
+ },
1485
+ "92534": {
1486
+ "content": "[UNUSED_TOKEN_137]",
1487
+ "lstrip": false,
1488
+ "normalized": false,
1489
+ "rstrip": false,
1490
+ "single_word": false,
1491
+ "special": false
1492
+ },
1493
+ "92535": {
1494
+ "content": "[UNUSED_TOKEN_138]",
1495
+ "lstrip": false,
1496
+ "normalized": false,
1497
+ "rstrip": false,
1498
+ "single_word": false,
1499
+ "special": false
1500
+ },
1501
+ "92536": {
1502
+ "content": "[UNUSED_TOKEN_139]",
1503
+ "lstrip": false,
1504
+ "normalized": false,
1505
+ "rstrip": false,
1506
+ "single_word": false,
1507
+ "special": false
1508
+ },
1509
+ "92537": {
1510
+ "content": "[UNUSED_TOKEN_140]",
1511
+ "lstrip": false,
1512
+ "normalized": false,
1513
+ "rstrip": false,
1514
+ "single_word": false,
1515
+ "special": false
1516
+ },
1517
+ "92538": {
1518
+ "content": "<|plugin|>",
1519
+ "lstrip": false,
1520
+ "normalized": false,
1521
+ "rstrip": false,
1522
+ "single_word": false,
1523
+ "special": true
1524
+ },
1525
+ "92539": {
1526
+ "content": "<|interpreter|>",
1527
+ "lstrip": false,
1528
+ "normalized": false,
1529
+ "rstrip": false,
1530
+ "single_word": false,
1531
+ "special": true
1532
+ },
1533
+ "92540": {
1534
+ "content": "<|action_end|>",
1535
+ "lstrip": false,
1536
+ "normalized": false,
1537
+ "rstrip": false,
1538
+ "single_word": false,
1539
+ "special": true
1540
+ },
1541
+ "92541": {
1542
+ "content": "<|action_start|>",
1543
+ "lstrip": false,
1544
+ "normalized": false,
1545
+ "rstrip": false,
1546
+ "single_word": false,
1547
+ "special": true
1548
+ },
1549
+ "92542": {
1550
+ "content": "<|im_end|>",
1551
+ "lstrip": false,
1552
+ "normalized": false,
1553
+ "rstrip": false,
1554
+ "single_word": false,
1555
+ "special": true
1556
+ },
1557
+ "92543": {
1558
+ "content": "<|im_start|>",
1559
+ "lstrip": false,
1560
+ "normalized": false,
1561
+ "rstrip": false,
1562
+ "single_word": false,
1563
+ "special": true
1564
+ },
1565
+ "92544": {
1566
+ "content": "[UNUSED_TOKEN_141]",
1567
+ "lstrip": false,
1568
+ "normalized": false,
1569
+ "rstrip": false,
1570
+ "single_word": false,
1571
+ "special": false
1572
+ },
1573
+ "92545": {
1574
+ "content": "[UNUSED_TOKEN_142]",
1575
+ "lstrip": false,
1576
+ "normalized": false,
1577
+ "rstrip": false,
1578
+ "single_word": false,
1579
+ "special": false
1580
+ },
1581
+ "92546": {
1582
+ "content": "[UNUSED_TOKEN_143]",
1583
+ "lstrip": false,
1584
+ "normalized": false,
1585
+ "rstrip": false,
1586
+ "single_word": false,
1587
+ "special": false
1588
+ },
1589
+ "92547": {
1590
+ "content": "[UNUSED_TOKEN_144]",
1591
+ "lstrip": false,
1592
+ "normalized": false,
1593
+ "rstrip": false,
1594
+ "single_word": false,
1595
+ "special": false
1596
+ },
1597
+ "92548": {
1598
+ "content": "[UNUSED_TOKEN_145]",
1599
+ "lstrip": false,
1600
+ "normalized": false,
1601
+ "rstrip": false,
1602
+ "single_word": false,
1603
+ "special": false
1604
+ },
1605
+ "92549": {
1606
+ "content": "[UNUSED_TOKEN_146]",
1607
+ "lstrip": false,
1608
+ "normalized": false,
1609
+ "rstrip": false,
1610
+ "single_word": false,
1611
+ "special": false
1612
+ },
1613
+ "92550": {
1614
+ "content": "<image>",
1615
+ "lstrip": false,
1616
+ "normalized": false,
1617
+ "rstrip": false,
1618
+ "single_word": false,
1619
+ "special": true
1620
+ }
1621
+ },
1622
+ "additional_special_tokens": [
1623
+ "<|im_start|>",
1624
+ "<|im_end|>",
1625
+ "<|action_start|>",
1626
+ "<|action_end|>",
1627
+ "<|interpreter|>",
1628
+ "<|plugin|>"
1629
+ ],
1630
+ "auto_map": {
1631
+ "AutoTokenizer": [
1632
+ "tokenization_internlm2.InternLM2Tokenizer",
1633
+ "tokenization_internlm2_fast.InternLM2TokenizerFast"
1634
+ ]
1635
+ },
1636
+ "bos_token": "<s>",
1637
+ "chat_template": "{{ bos_token }}{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",
1638
+ "clean_up_tokenization_spaces": false,
1639
+ "decode_with_prefix_space": false,
1640
+ "eos_token": "</s>",
1641
+ "model_max_length": 1000000000000000019884624838656,
1642
+ "pad_token": "</s>",
1643
+ "padding_side": "right",
1644
+ "processor_class": "LlavaProcessor",
1645
+ "sp_model_kwargs": null,
1646
+ "tokenizer_class": "InternLM2Tokenizer",
1647
+ "unk_token": "<unk>"
1648
+ }