XiaoduoAILab commited on
Commit
73713d1
1 Parent(s): bc22742

Upload 8 files

Browse files
config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/data1/liuyang/checkpoints/e_line/xl/iter-0400000/",
3
+ "architectures": [
4
+ "XmodelLMForCausalLM"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_xmodel.XModelConfig",
8
+ "AutoModelForCausalLM": "modeling_xmodel.XModelForCausalLM"
9
+ },
10
+ "bos_token_id": 1,
11
+ "eos_token_id": 2,
12
+ "freeze_mm_mlp_adapter": false,
13
+ "hidden_act": "silu",
14
+ "hidden_size": 2048,
15
+ "image_aspect_ratio": "pad",
16
+ "image_grid_pinpoints": null,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 5632,
19
+ "max_position_embeddings": 32768,
20
+ "mm_hidden_size": 1024,
21
+ "mm_projector_lr": null,
22
+ "mm_projector_type": "xdpnetv10_1",
23
+ "mm_use_im_patch_token": false,
24
+ "mm_use_im_start_end": false,
25
+ "mm_vision_select_feature": "patch",
26
+ "mm_vision_select_layer": -2,
27
+ "mm_vision_tower": "/data1/xuwanting/LLaVA/llava/model/clip-vit-large-patch14-336/",
28
+ "model_type": "xmodelvlm",
29
+ "num_attention_heads": 32,
30
+ "num_hidden_layers": 24,
31
+ "num_key_value_heads": 4,
32
+ "pad_token_id": 0,
33
+ "pretraining_tp": 1,
34
+ "rms_norm_eps": 1e-05,
35
+ "tie_word_embeddings": false,
36
+ "torch_dtype": "bfloat16",
37
+ "transformers_version": "4.37.2",
38
+ "tune_mm_mlp_adapter": false,
39
+ "use_cache": true,
40
+ "use_mm_proj": true,
41
+ "vision_tower_type": "clip",
42
+ "vocab_size": 32000
43
+ }
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": 0,
6
+ "transformers_version": "4.37.2"
7
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3029e78e1e252c48d960f3904197d31ebc1be8e00c8b33b2fcdea293eb60ca99
3
+ size 2995971248
special_tokens_map.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": true,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": "<unk>",
17
+ "unk_token": {
18
+ "content": "<unk>",
19
+ "lstrip": false,
20
+ "normalized": true,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenization_xmodel.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+
21
+ import os
22
+ from shutil import copyfile
23
+ from typing import Any, Dict, List, Optional, Tuple
24
+
25
+ import sentencepiece as spm
26
+ from transformers.tokenization_utils import AddedToken, PreTrainedTokenizer
27
+ from transformers.utils import logging
28
+
29
+ logger = logging.get_logger(__name__)
30
+
31
+ VOCAB_FILES_NAMES = {"vocab_file": "xmodel_32000.model"}
32
+
33
+ PRETRAINED_VOCAB_FILES_MAP = {
34
+ "vocab_file": {},
35
+ "tokenizer_file": {},
36
+ }
37
+ PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES = {}
38
+
39
+
40
+ class XModelTokenizer(PreTrainedTokenizer):
41
+ """
42
+ Construct a XModel tokenizer. Based on byte-level Byte-Pair-Encoding.
43
+
44
+ Args:
45
+ vocab_file (`str`):
46
+ Path to the vocabulary file.
47
+ """
48
+
49
+ vocab_files_names = VOCAB_FILES_NAMES
50
+ pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
51
+ max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
52
+ model_input_names = ["input_ids", "attention_mask"]
53
+
54
+ def __init__(
55
+ self,
56
+ vocab_file,
57
+ unk_token="<unk>",
58
+ bos_token="<s>",
59
+ eos_token="</s>",
60
+ pad_token=None,
61
+ sp_model_kwargs: Optional[Dict[str, Any]] = None,
62
+ add_bos_token=True,
63
+ add_eos_token=False,
64
+ clean_up_tokenization_spaces=False,
65
+ **kwargs,
66
+ ):
67
+ self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
68
+ bos_token = AddedToken(bos_token, lstrip=False, rstrip=False) if isinstance(bos_token, str) else bos_token
69
+ eos_token = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_token
70
+ unk_token = AddedToken(unk_token, lstrip=False, rstrip=False) if isinstance(unk_token, str) else unk_token
71
+ pad_token = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_token
72
+ self.vocab_file = vocab_file
73
+ self.add_bos_token = add_bos_token
74
+ self.add_eos_token = add_eos_token
75
+ self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
76
+ self.sp_model.Load(vocab_file)
77
+ super().__init__(
78
+ bos_token=bos_token,
79
+ eos_token=eos_token,
80
+ unk_token=unk_token,
81
+ pad_token=pad_token,
82
+ add_bos_token=add_bos_token,
83
+ add_eos_token=add_eos_token,
84
+ sp_model_kwargs=self.sp_model_kwargs,
85
+ clean_up_tokenization_spaces=clean_up_tokenization_spaces,
86
+ **kwargs,
87
+ )
88
+
89
+ def __getstate__(self):
90
+ state = self.__dict__.copy()
91
+ state["sp_model"] = None
92
+ return state
93
+
94
+ def __setstate__(self, d):
95
+ self.__dict__ = d
96
+ self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
97
+ self.sp_model.Load(self.vocab_file)
98
+
99
+ @property
100
+ def vocab_size(self):
101
+ """Returns vocab size"""
102
+ return self.sp_model.get_piece_size()
103
+
104
+ def get_vocab(self):
105
+ """Returns vocab as a dict"""
106
+ vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
107
+ vocab.update(self.added_tokens_encoder)
108
+ return vocab
109
+
110
+ def _tokenize(self, text):
111
+ """Returns a tokenized string."""
112
+ return self.sp_model.encode(text, out_type=str)
113
+
114
+ def _convert_token_to_id(self, token):
115
+ """Converts a token (str) in an id using the vocab."""
116
+ return self.sp_model.piece_to_id(token)
117
+
118
+ def _convert_id_to_token(self, index):
119
+ """Converts an index (integer) in a token (str) using the vocab."""
120
+ token = self.sp_model.IdToPiece(index)
121
+ return token
122
+
123
+ def convert_tokens_to_string(self, tokens):
124
+ """Converts a sequence of tokens (string) in a single string."""
125
+ current_sub_tokens = []
126
+ out_string = ""
127
+ prev_is_special = False
128
+ for i, token in enumerate(tokens):
129
+ # make sure that special tokens are not decoded using sentencepiece model
130
+ if token in self.all_special_tokens:
131
+ if not prev_is_special and i != 0:
132
+ out_string += " "
133
+ out_string += self.sp_model.decode(current_sub_tokens) + token
134
+ prev_is_special = True
135
+ current_sub_tokens = []
136
+ else:
137
+ current_sub_tokens.append(token)
138
+ prev_is_special = False
139
+ out_string += self.sp_model.decode(current_sub_tokens)
140
+ return out_string
141
+
142
+ def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]:
143
+ """
144
+ Save the vocabulary and special tokens file to a directory.
145
+
146
+ Args:
147
+ save_directory (`str`):
148
+ The directory in which to save the vocabulary.
149
+
150
+ Returns:
151
+ `Tuple(str)`: Paths to the files saved.
152
+ """
153
+ if not os.path.isdir(save_directory):
154
+ logger.error(f"Vocabulary path ({save_directory}) should be a directory")
155
+ return
156
+ out_vocab_file = os.path.join(
157
+ save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
158
+ )
159
+
160
+ if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
161
+ copyfile(self.vocab_file, out_vocab_file)
162
+ elif not os.path.isfile(self.vocab_file):
163
+ with open(out_vocab_file, "wb") as fi:
164
+ content_spiece_model = self.sp_model.serialized_model_proto()
165
+ fi.write(content_spiece_model)
166
+
167
+ return (out_vocab_file,)
168
+
169
+ def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
170
+ bos_token_id = [self.bos_token_id] if self.add_bos_token else []
171
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
172
+
173
+ output = bos_token_id + token_ids_0 + eos_token_id
174
+
175
+ if token_ids_1 is not None:
176
+ output = output + bos_token_id + token_ids_1 + eos_token_id
177
+
178
+ return output
179
+
180
+ def get_special_tokens_mask(
181
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None,
182
+ already_has_special_tokens: bool = False
183
+ ) -> List[int]:
184
+ """
185
+ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
186
+ special tokens using the tokenizer `prepare_for_model` method.
187
+
188
+ Args:
189
+ token_ids_0 (`List[int]`):
190
+ List of IDs.
191
+ token_ids_1 (`List[int]`, *optional*):
192
+ Optional second list of IDs for sequence pairs.
193
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
194
+ Whether or not the token list is already formatted with special tokens for the model.
195
+
196
+ Returns:
197
+ `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
198
+ """
199
+ if already_has_special_tokens:
200
+ return super().get_special_tokens_mask(
201
+ token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
202
+ )
203
+
204
+ bos_token_id = [1] if self.add_bos_token else []
205
+ eos_token_id = [1] if self.add_eos_token else []
206
+
207
+ if token_ids_1 is None:
208
+ return bos_token_id + ([0] * len(token_ids_0)) + eos_token_id
209
+ return (
210
+ bos_token_id
211
+ + ([0] * len(token_ids_0))
212
+ + eos_token_id
213
+ + bos_token_id
214
+ + ([0] * len(token_ids_1))
215
+ + eos_token_id
216
+ )
217
+
218
+ def create_token_type_ids_from_sequences(
219
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
220
+ ) -> List[int]:
221
+ """
222
+ Creates a mask from the two sequences passed to be used in a sequence-pair classification task. An ALBERT
223
+ sequence pair mask has the following format:
224
+
225
+ ```
226
+ 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
227
+ | first sequence | second sequence |
228
+ ```
229
+
230
+ if token_ids_1 is None, only returns the first portion of the mask (0s).
231
+
232
+ Args:
233
+ token_ids_0 (`List[int]`):
234
+ List of ids.
235
+ token_ids_1 (`List[int]`, *optional*):
236
+ Optional second list of IDs for sequence pairs.
237
+
238
+ Returns:
239
+ `List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s).
240
+ """
241
+ bos_token_id = [self.bos_token_id] if self.add_bos_token else []
242
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
243
+
244
+ output = [0] * len(bos_token_id + token_ids_0 + eos_token_id)
245
+
246
+ if token_ids_1 is not None:
247
+ output += [1] * len(bos_token_id + token_ids_1 + eos_token_id)
248
+
249
+ return output
tokenizer_config.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": true,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": true,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": true,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ }
29
+ },
30
+ "auto_map": {
31
+ "AutoTokenizer": [
32
+ "tokenization_xmodel.XModelTokenizer",
33
+ null
34
+ ]
35
+ },
36
+ "bos_token": "<s>",
37
+ "clean_up_tokenization_spaces": false,
38
+ "eos_token": "</s>",
39
+ "model_max_length": 2048,
40
+ "pad_token": "<unk>",
41
+ "padding_side": "right",
42
+ "sp_model_kwargs": {},
43
+ "tokenizer_class": "XModelTokenizer",
44
+ "unk_token": "<unk>"
45
+ }
trainer_state.json ADDED
The diff for this file is too large to render. See raw diff
 
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ce3960e1877f30f599a4d37766be45fedf2233440f0354c0f94aaa2f8513887
3
+ size 6776