openvino-ci commited on
Commit
ac627e2
·
verified ·
1 Parent(s): 12f3fe4

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ license_link: https://choosealicense.com/licenses/apache-2.0/
4
+ ---
5
+ # codegen25-7b-multi-int4-ov
6
+ * Model creator: [Salesforce](https://huggingface.co/Salesforce)
7
+ * Original model: [codegen25-7b-multi](https://huggingface.co/Salesforce/codegen25-7b-multi)
8
+
9
+ ## Description
10
+ This is [codegen25-7b-multi](https://huggingface.co/Salesforce/codegen25-7b-multi) model converted to the [OpenVINO™ IR](https://docs.openvino.ai/2024/documentation/openvino-ir-format.html) (Intermediate Representation) format with weights compressed to INT4 by [NNCF](https://github.com/openvinotoolkit/nncf).
11
+
12
+ ## Quantization Parameters
13
+
14
+ Weight compression was performed using `nncf.compress_weights` with the following parameters:
15
+
16
+ * mode: **int4_sym**
17
+ * ratio: **1**
18
+ * group_size: **128**
19
+
20
+ For more information on quantization, check the [OpenVINO model optimization guide](https://docs.openvino.ai/2024/openvino-workflow/model-optimization-guide/weight-compression.html).
21
+
22
+
23
+ ## Compatibility
24
+
25
+ The provided OpenVINO™ IR model is compatible with:
26
+
27
+ * OpenVINO version 2024.1.0 and higher
28
+ * Optimum Intel 1.16.0 and higher
29
+
30
+ ## Running Model Inference
31
+
32
+ 1. Install packages required for using [Optimum Intel](https://huggingface.co/docs/optimum/intel/index) integration with the OpenVINO backend:
33
+
34
+ ```
35
+ pip install optimum[openvino]
36
+ ```
37
+
38
+ 2. Run model inference:
39
+
40
+ ```
41
+ from transformers import AutoTokenizer
42
+ from optimum.intel.openvino import OVModelForCausalLM
43
+
44
+ model_id = "OpenVINO/codegen25-7b-multi-int4-ov"
45
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
46
+ model = OVModelForCausalLM.from_pretrained(model_id)
47
+
48
+ inputs = tokenizer("What is OpenVINO?", return_tensors="pt")
49
+
50
+ outputs = model.generate(**inputs, max_length=200)
51
+ text = tokenizer.batch_decode(outputs)[0]
52
+ print(text)
53
+ ```
54
+
55
+ For more examples and possible optimizations, refer to the [OpenVINO Large Language Model Inference Guide](https://docs.openvino.ai/2024/learn-openvino/llm_inference_guide.html).
56
+
57
+ ## Limitations
58
+
59
+ Check the original model card for [limitations]().
60
+
61
+ ## Legal information
62
+
63
+ The original model is distributed under [apache-2.0](https://choosealicense.com/licenses/apache-2.0/) license. More details can be found in [original model card](https://huggingface.co/Salesforce/codegen25-7b-multi).
64
+
65
+ ## Disclaimer
66
+
67
+ Intel is committed to respecting human rights and avoiding causing or contributing to adverse impacts on human rights. See [Intel’s Global Human Rights Principles](https://www.intel.com/content/dam/www/central-libraries/us/en/documents/policy-human-rights.pdf). Intel’s products and software are intended only to be used in applications that do not cause or contribute to adverse impacts on human rights.
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Salesforce/codegen25-7b-multi",
3
+ "architectures": [
4
+ "LlamaForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "bos_token_id": 50256,
9
+ "eos_token_id": 50256,
10
+ "hidden_act": "silu",
11
+ "hidden_size": 4096,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 11008,
14
+ "max_position_embeddings": 2048,
15
+ "model_type": "llama",
16
+ "num_attention_heads": 32,
17
+ "num_hidden_layers": 32,
18
+ "num_key_value_heads": 32,
19
+ "pad_token_id": 0,
20
+ "pretraining_tp": 1,
21
+ "rms_norm_eps": 1e-06,
22
+ "rope_scaling": null,
23
+ "rope_theta": 10000.0,
24
+ "tie_word_embeddings": false,
25
+ "torch_dtype": "float32",
26
+ "transformers_version": "4.40.1",
27
+ "use_cache": true,
28
+ "vocab_size": 51200
29
+ }
openvino_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a2c0cf67087123f381306eb3a228ec315467752925a7f076d18adeb3beb5cc8
3
+ size 3759460808
openvino_model.xml ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "eos_token": {
3
+ "content": "<|endoftext|>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ }
9
+ }
tokenization_codegen25.py ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2023, salesforce.com, inc.
2
+ # All rights reserved.
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ # For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/Apache-2.0
5
+ """Tokenization classes for CodeGen2.5."""
6
+
7
+ from typing import List, Optional
8
+
9
+ from transformers.tokenization_utils import AddedToken, PreTrainedTokenizer
10
+ from transformers.utils import logging
11
+
12
+ try:
13
+ import tiktoken
14
+ except ModuleNotFoundError as e:
15
+ raise ModuleNotFoundError("CodeGen2.5 requires the installation of tiktoken. Please install it via `pip install tiktoken`.") from e
16
+
17
+
18
+ logger = logging.get_logger(__name__)
19
+
20
+ MAX_MODEL_INPUT_SIZES = {
21
+ "Salesforce/codegen25-7b-multi": 2048,
22
+ "Salesforce/codegen25-7b-mono": 2048,
23
+ "Salesforce/codegen25-7b-instruct": 2048,
24
+ }
25
+
26
+
27
+ def tiktoken_tokenizer(base="gpt2", pad_token=None, add_special=True):
28
+ if not add_special:
29
+ return tiktoken.get_encoding(base)
30
+
31
+ def include_whitespace(n_min=2, n_max=20):
32
+ whitespaces = [" " * n for n in reversed(range(n_min, n_max))]
33
+ return whitespaces
34
+
35
+ def include_tabs(n_min=2, n_max=20):
36
+ tabs = ["\t" * n for n in reversed(range(n_min, n_max))]
37
+ return tabs
38
+
39
+ def include_fim_tokens():
40
+ fim_tokens = [
41
+ "<fim_prefix>",
42
+ "<fim_middle>",
43
+ "<fim_suffix>",
44
+ "<fim_pad>",
45
+ "<filename>",
46
+ "<gh_stars>",
47
+ "<issue_start>",
48
+ "<issue_comment>",
49
+ "<issue_closed>",
50
+ "<jupyter_start>",
51
+ "<jupyter_text>",
52
+ "<jupyter_code>",
53
+ "<jupyter_output>",
54
+ "<empty_output>",
55
+ "<commit_before>",
56
+ "<commit_msg>",
57
+ "<commit_after>",
58
+ "<reponame>"
59
+ ]
60
+ return fim_tokens
61
+
62
+ def include_codegen2_tokens():
63
+ tokens = []
64
+ tokens += [f"<dummy_{i}>" for i in range(4)]
65
+ tokens.append("<sep>") # 50317
66
+ tokens.append("<eom>") # 50318
67
+ tokens += [f"<mask_{i}>" for i in reversed(range(1, 51199-50318+1))]
68
+ return tokens
69
+
70
+ add_whitespaces = include_whitespace(n_min=2, n_max=32)
71
+ add_tabs = include_tabs(n_min=2, n_max=10)
72
+ fim_tokens = include_fim_tokens()
73
+ codegen2_tokens = include_codegen2_tokens()
74
+
75
+ tokenizer = tiktoken.get_encoding(base)
76
+
77
+ idx = tokenizer.n_vocab
78
+
79
+ bpe_ranks = tokenizer._mergeable_ranks
80
+
81
+ for wsp in add_whitespaces:
82
+ bpe_ranks[bytes(wsp, 'ascii')] = idx
83
+ idx += 1
84
+ for t in add_tabs:
85
+ bpe_ranks[bytes(t, 'ascii')] = idx
86
+ idx += 1
87
+
88
+ special_tokens = dict()
89
+
90
+ for sp in fim_tokens:
91
+ special_tokens[sp] = idx
92
+ idx += 1
93
+ for sp in codegen2_tokens:
94
+ special_tokens[sp] = idx
95
+ idx += 1
96
+
97
+ if pad_token and pad_token not in tokenizer._special_tokens and pad_token not in special_tokens:
98
+ special_tokens[pad_token] = idx
99
+ idx += 1
100
+ # In production, load the arguments directly instead of accessing private attributes
101
+ # See openai_public.py for examples of arguments for specific encodings
102
+ enc = tiktoken.Encoding(
103
+ # If you're changing the set of special tokens, make sure to use a different name
104
+ # It should be clear from the name what behaviour to expect.
105
+ name=base.replace("base", "im"),
106
+ pat_str=tokenizer._pat_str,
107
+ mergeable_ranks=bpe_ranks,
108
+ special_tokens={
109
+ **tokenizer._special_tokens,
110
+ **special_tokens
111
+ }
112
+ )
113
+ return enc
114
+
115
+
116
+ class CodeGen25Tokenizer(PreTrainedTokenizer):
117
+ """
118
+ Construct a CodeGen2.5 tokenizer. Based on byte-level Byte-Pair-Encoding.
119
+ Args:
120
+ vocab_file (`str`):
121
+ Path to the vocabulary file.
122
+ """
123
+ max_model_input_sizes = MAX_MODEL_INPUT_SIZES
124
+ model_input_names = ["input_ids", "attention_mask"]
125
+
126
+ def __init__(
127
+ self,
128
+ pad_token=None,
129
+ eos_token="<|endoftext|>",
130
+ add_eos_token=False,
131
+ add_special_tokens=True,
132
+ **kwargs,
133
+ ):
134
+ pad_token_added = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_token
135
+ eos_token_added = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_token
136
+ self.encoder = tiktoken_tokenizer(base="gpt2", pad_token=pad_token, add_special=add_special_tokens)
137
+ super().__init__(
138
+ pad_token=pad_token_added,
139
+ eos_token=eos_token_added,
140
+ add_eos_token=add_eos_token,
141
+ **kwargs,
142
+ )
143
+ self.add_eos_token = add_eos_token
144
+
145
+ @property
146
+ def vocab_size(self):
147
+ """Returns vocab size"""
148
+ return self.encoder.n_vocab
149
+
150
+ def get_vocab(self):
151
+ """Returns vocab as a dict"""
152
+ vocab = {self._convert_id_to_token(i): i for i in range(self.vocab_size)}
153
+ return vocab
154
+
155
+ def _tokenize(self, text, **kwargs):
156
+ """Returns a tokenized string."""
157
+ return self.encoder.encode(text, allowed_special="all")
158
+
159
+ def _convert_token_to_id(self, token):
160
+ """Converts a token (str) in an id using the vocab."""
161
+ if isinstance(token, str):
162
+ return self.encoder.encode_single_token(token)
163
+ else:
164
+ return token
165
+
166
+ def _convert_id_to_token(self, index):
167
+ """Converts an index (integer) in a token (str) using the vocab."""
168
+ try:
169
+ token = self.encoder.decode_single_token_bytes(index).decode("utf-8")
170
+ except Exception:
171
+ token = ""
172
+ return token
173
+
174
+ def _decode(self, token_ids: List[int], skip_special_tokens: bool = False, **kwargs):
175
+ if skip_special_tokens:
176
+ token_ids = [t for t in token_ids if t not in self.all_special_ids]
177
+ return self.encoder.decode(token_ids)
178
+
179
+ def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None) -> List[int]:
180
+ """Build model inputs from a sequence by appending eos_token_id."""
181
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
182
+
183
+ output = token_ids_0 + eos_token_id
184
+
185
+ if token_ids_1 is not None:
186
+ output = output + token_ids_1 + eos_token_id
187
+
188
+ return output
189
+
190
+ def get_special_tokens_mask(
191
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None,
192
+ already_has_special_tokens: bool = False
193
+ ) -> List[int]:
194
+ """
195
+ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
196
+ special tokens using the tokenizer `prepare_for_model` method.
197
+ Args:
198
+ token_ids_0 (`List[int]`):
199
+ List of IDs.
200
+ token_ids_1 (`List[int]`, *optional*):
201
+ Optional second list of IDs for sequence pairs.
202
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
203
+ Whether the token list is already formatted with special tokens for the model.
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
+ eos_token_id = [1] if self.add_eos_token else []
213
+
214
+ if token_ids_1 is None:
215
+ return ([0] * len(token_ids_0)) + eos_token_id
216
+ return ([0] * len(token_ids_0)) + eos_token_id + ([0] * len(token_ids_1)) + eos_token_id
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
+ 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
226
+ | first sequence | second sequence |
227
+ ```
228
+ if token_ids_1 is None, only returns the first portion of the mask (0s).
229
+ Args:
230
+ token_ids_0 (`List[int]`):
231
+ List of ids.
232
+ token_ids_1 (`List[int]`, *optional*):
233
+ Optional second list of IDs for sequence pairs.
234
+ Returns:
235
+ `List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s).
236
+ """
237
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
238
+
239
+ output = [0] * len(token_ids_0 + eos_token_id)
240
+
241
+ if token_ids_1 is not None:
242
+ output += [1] * len(token_ids_1 + eos_token_id)
243
+
244
+ return output
245
+
246
+ # has no vocab file
247
+ def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None):
248
+ return ()
tokenizer_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_eos_token": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ }
12
+ },
13
+ "auto_map": {
14
+ "AutoTokenizer": [
15
+ "tokenization_codegen25.CodeGen25Tokenizer",
16
+ null
17
+ ]
18
+ },
19
+ "clean_up_tokenization_spaces": true,
20
+ "eos_token": "<|endoftext|>",
21
+ "model_max_length": 2048,
22
+ "pad_token": null,
23
+ "tokenizer_class": "CodeGen25Tokenizer"
24
+ }