thomas-yanxin
commited on
Commit
•
e63168c
1
Parent(s):
ccde946
'init'
Browse files- config.json +28 -0
- configuration.json +11 -0
- configuration_baichuan.py +46 -0
- generation_config.json +14 -0
- logo-github.png +0 -0
- modeling_baichuan.py +609 -0
- pytorch_model-00001-of-00003.bin +3 -0
- pytorch_model-00002-of-00003.bin +3 -0
- pytorch_model-00003-of-00003.bin +3 -0
- pytorch_model.bin.index.json +290 -0
- quantizer.py +126 -0
- special_tokens_map.json +30 -0
- tokenization_baichuan.py +232 -0
- tokenizer.model +3 -0
- tokenizer_config.json +46 -0
config.json
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"_name_or_path": "/tmp/code/baichuan",
|
4 |
+
"architectures": [
|
5 |
+
"BaichuanForCausalLM"
|
6 |
+
],
|
7 |
+
"auto_map": {
|
8 |
+
"AutoConfig": "configuration_baichuan.BaichuanConfig",
|
9 |
+
"AutoModelForCausalLM": "modeling_baichuan.BaichuanForCausalLM"
|
10 |
+
},
|
11 |
+
"bos_token_id": 1,
|
12 |
+
"eos_token_id": 2,
|
13 |
+
"hidden_act": "silu",
|
14 |
+
"hidden_size": 5120,
|
15 |
+
"initializer_range": 0.02,
|
16 |
+
"intermediate_size": 13696,
|
17 |
+
"model_max_length": 4096,
|
18 |
+
"model_type": "baichuan",
|
19 |
+
"num_attention_heads": 40,
|
20 |
+
"num_hidden_layers": 40,
|
21 |
+
"pad_token_id": 0,
|
22 |
+
"rms_norm_eps": 1e-06,
|
23 |
+
"tie_word_embeddings": false,
|
24 |
+
"torch_dtype": "float16",
|
25 |
+
"transformers_version": "4.32.0.dev0",
|
26 |
+
"use_cache": true,
|
27 |
+
"vocab_size": 64000
|
28 |
+
}
|
configuration.json
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"framework": "pytorch",
|
3 |
+
"task": "text-generation",
|
4 |
+
"model": {
|
5 |
+
"type": "MindChat-Baichuan-13B"
|
6 |
+
},
|
7 |
+
"pipeline": {
|
8 |
+
"type": "MindChat-Baichuan-13B-text-generation-pipe"
|
9 |
+
},
|
10 |
+
"allow_remote": true
|
11 |
+
}
|
configuration_baichuan.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) 2023, Baichuan Intelligent Technology. All rights reserved.
|
2 |
+
|
3 |
+
from transformers.configuration_utils import PretrainedConfig
|
4 |
+
|
5 |
+
class BaichuanConfig(PretrainedConfig):
|
6 |
+
model_type = "baichuan"
|
7 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
8 |
+
|
9 |
+
def __init__(
|
10 |
+
self,
|
11 |
+
vocab_size=64000,
|
12 |
+
hidden_size=5120,
|
13 |
+
intermediate_size=13696,
|
14 |
+
num_hidden_layers=40,
|
15 |
+
num_attention_heads=40,
|
16 |
+
hidden_act="silu",
|
17 |
+
model_max_length=4096,
|
18 |
+
initializer_range=0.02,
|
19 |
+
rms_norm_eps=1e-6,
|
20 |
+
use_cache=True,
|
21 |
+
pad_token_id=0,
|
22 |
+
bos_token_id=1,
|
23 |
+
eos_token_id=2,
|
24 |
+
tie_word_embeddings=False,
|
25 |
+
gradient_checkpointing=False,
|
26 |
+
**kwargs,
|
27 |
+
):
|
28 |
+
self.vocab_size = vocab_size
|
29 |
+
self.model_max_length = model_max_length
|
30 |
+
self.hidden_size = hidden_size
|
31 |
+
self.intermediate_size = intermediate_size
|
32 |
+
self.num_hidden_layers = num_hidden_layers
|
33 |
+
self.num_attention_heads = num_attention_heads
|
34 |
+
self.hidden_act = hidden_act
|
35 |
+
self.initializer_range = initializer_range
|
36 |
+
self.rms_norm_eps = rms_norm_eps
|
37 |
+
self.use_cache = use_cache
|
38 |
+
self.gradient_checkpointing = gradient_checkpointing,
|
39 |
+
super().__init__(
|
40 |
+
pad_token_id=pad_token_id,
|
41 |
+
bos_token_id=bos_token_id,
|
42 |
+
eos_token_id=eos_token_id,
|
43 |
+
tie_word_embeddings=tie_word_embeddings,
|
44 |
+
**kwargs,
|
45 |
+
)
|
46 |
+
|
generation_config.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"pad_token_id": 0,
|
3 |
+
"bos_token_id": 1,
|
4 |
+
"eos_token_id": 2,
|
5 |
+
"user_token_id": 195,
|
6 |
+
"assistant_token_id": 196,
|
7 |
+
"max_new_tokens": 2048,
|
8 |
+
"temperature": 0.3,
|
9 |
+
"top_k": 5,
|
10 |
+
"top_p": 0.85,
|
11 |
+
"repetition_penalty": 1.1,
|
12 |
+
"do_sample": true,
|
13 |
+
"transformers_version": "4.29.2"
|
14 |
+
}
|
logo-github.png
ADDED
modeling_baichuan.py
ADDED
@@ -0,0 +1,609 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) 2023, Baichuan Intelligent Technology. All rights reserved.
|
2 |
+
|
3 |
+
import math
|
4 |
+
from typing import List, Optional, Tuple, Union
|
5 |
+
|
6 |
+
import torch
|
7 |
+
import torch.utils.checkpoint
|
8 |
+
from torch.nn import CrossEntropyLoss
|
9 |
+
from transformers import PreTrainedModel
|
10 |
+
from transformers.activations import ACT2FN
|
11 |
+
from transformers.generation.utils import GenerationConfig
|
12 |
+
from transformers.modeling_outputs import (BaseModelOutputWithPast,
|
13 |
+
CausalLMOutputWithPast)
|
14 |
+
from transformers.utils import logging
|
15 |
+
|
16 |
+
from .configuration_baichuan import BaichuanConfig
|
17 |
+
|
18 |
+
logger = logging.get_logger(__name__)
|
19 |
+
|
20 |
+
|
21 |
+
def _get_interleave(n):
|
22 |
+
def _get_interleave_power_of_2(n):
|
23 |
+
start = (2 ** (-2 ** -(math.log2(n) - 3)))
|
24 |
+
ratio = start
|
25 |
+
return [start * ratio ** i for i in range(n)]
|
26 |
+
|
27 |
+
if math.log2(n).is_integer():
|
28 |
+
return _get_interleave_power_of_2(n)
|
29 |
+
else:
|
30 |
+
closest_power_of_2 = 2 ** math.floor(math.log2(n))
|
31 |
+
return _get_interleave_power_of_2(closest_power_of_2) + \
|
32 |
+
_get_interleave(2 * closest_power_of_2)[0::2][:n - closest_power_of_2]
|
33 |
+
|
34 |
+
def _fill_with_neg_inf(t):
|
35 |
+
"""FP16-compatible function that fills a tensor with -inf."""
|
36 |
+
return t.float().fill_(float("-inf")).type_as(t)
|
37 |
+
|
38 |
+
def _gen_alibi_mask(n_head, max_pos):
|
39 |
+
"""used in inference only"""
|
40 |
+
slopes = torch.Tensor(_get_interleave(n_head))
|
41 |
+
alibi = slopes.unsqueeze(1).unsqueeze(1) * torch.arange(max_pos).unsqueeze(0).unsqueeze(0).expand(
|
42 |
+
n_head, -1, -1)
|
43 |
+
alibi = alibi.view(n_head, 1, max_pos)
|
44 |
+
alibi_mask = torch.triu(
|
45 |
+
_fill_with_neg_inf(torch.zeros([max_pos, max_pos])), 1
|
46 |
+
)
|
47 |
+
alibi_mask = alibi_mask.unsqueeze(0) + alibi
|
48 |
+
return alibi_mask
|
49 |
+
|
50 |
+
def _buffered_future_mask(tensor, maxpos, alibi, attn_heads):
|
51 |
+
"""used in training only"""
|
52 |
+
dim = tensor.size(1)
|
53 |
+
_future_mask = torch.triu(
|
54 |
+
_fill_with_neg_inf(torch.zeros([maxpos, maxpos])), 1
|
55 |
+
)
|
56 |
+
_future_mask = _future_mask.unsqueeze(0) + alibi
|
57 |
+
_future_mask = _future_mask.to(tensor)
|
58 |
+
return _future_mask[:tensor.shape[0] * attn_heads, :maxpos, :maxpos]
|
59 |
+
|
60 |
+
|
61 |
+
class RMSNorm(torch.nn.Module):
|
62 |
+
def __init__(self, hidden_size, epsilon=1e-6):
|
63 |
+
super().__init__()
|
64 |
+
self.weight = torch.nn.Parameter(torch.empty(hidden_size))
|
65 |
+
self.epsilon = epsilon
|
66 |
+
|
67 |
+
def forward(self, hidden_states):
|
68 |
+
variance = hidden_states.to(torch.float32).pow(2).mean(-1, keepdim=True)
|
69 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.epsilon)
|
70 |
+
|
71 |
+
# convert into half-precision
|
72 |
+
if self.weight.dtype in [torch.float16, torch.bfloat16]:
|
73 |
+
hidden_states = hidden_states.to(self.weight.dtype)
|
74 |
+
|
75 |
+
return self.weight * hidden_states
|
76 |
+
|
77 |
+
|
78 |
+
class MLP(torch.nn.Module):
|
79 |
+
def __init__(
|
80 |
+
self,
|
81 |
+
hidden_size: int,
|
82 |
+
intermediate_size: int,
|
83 |
+
hidden_act: str,
|
84 |
+
):
|
85 |
+
super().__init__()
|
86 |
+
self.gate_proj = torch.nn.Linear(hidden_size, intermediate_size, bias=False)
|
87 |
+
self.down_proj = torch.nn.Linear(intermediate_size, hidden_size, bias=False)
|
88 |
+
self.up_proj = torch.nn.Linear(hidden_size, intermediate_size, bias=False)
|
89 |
+
self.act_fn = ACT2FN[hidden_act]
|
90 |
+
|
91 |
+
def forward(self, x):
|
92 |
+
return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
93 |
+
|
94 |
+
|
95 |
+
class BaichuanAttention(torch.nn.Module):
|
96 |
+
def __init__(self, config: BaichuanConfig):
|
97 |
+
super().__init__()
|
98 |
+
self.config = config
|
99 |
+
self.hidden_size = config.hidden_size
|
100 |
+
self.num_heads = config.num_attention_heads
|
101 |
+
self.head_dim = self.hidden_size // self.num_heads
|
102 |
+
self.max_position_embeddings = config.model_max_length
|
103 |
+
|
104 |
+
if (self.head_dim * self.num_heads) != self.hidden_size:
|
105 |
+
raise ValueError(
|
106 |
+
f"hidden_size {self.hidden_size} is not divisible by num_heads {self.num_heads}"
|
107 |
+
)
|
108 |
+
self.W_pack = torch.nn.Linear(self.hidden_size, 3 * self.hidden_size, bias=False)
|
109 |
+
self.o_proj = torch.nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
|
110 |
+
|
111 |
+
def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
|
112 |
+
return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
|
113 |
+
|
114 |
+
def forward(
|
115 |
+
self,
|
116 |
+
hidden_states: torch.Tensor,
|
117 |
+
attention_mask: Optional[torch.Tensor] = None,
|
118 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
119 |
+
output_attentions: bool = False,
|
120 |
+
use_cache: bool = False,
|
121 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
122 |
+
|
123 |
+
bsz, q_len, _ = hidden_states.size()
|
124 |
+
|
125 |
+
proj = self.W_pack(hidden_states)
|
126 |
+
proj = proj.unflatten(-1, (3, self.hidden_size)).unsqueeze(0).transpose(0, -2).squeeze(-2)
|
127 |
+
query_states = proj[0].view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
128 |
+
key_states = proj[1].view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
129 |
+
value_states = proj[2].view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
130 |
+
|
131 |
+
kv_seq_len = key_states.shape[-2]
|
132 |
+
if past_key_value is not None:
|
133 |
+
kv_seq_len += past_key_value[0].shape[-2]
|
134 |
+
|
135 |
+
if past_key_value is not None:
|
136 |
+
# reuse k, v, self_attention
|
137 |
+
key_states = torch.cat([past_key_value[0], key_states], dim=2)
|
138 |
+
value_states = torch.cat([past_key_value[1], value_states], dim=2)
|
139 |
+
|
140 |
+
past_key_value = (key_states, value_states) if use_cache else None
|
141 |
+
|
142 |
+
attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
|
143 |
+
|
144 |
+
if attention_mask is not None:
|
145 |
+
if q_len == 1: # inference with cache
|
146 |
+
if len(attention_mask.size()) == 4:
|
147 |
+
attention_mask = attention_mask[:, :, -1:, :]
|
148 |
+
else:
|
149 |
+
attention_mask = attention_mask[:, -1:, :]
|
150 |
+
attn_weights = attn_weights + attention_mask
|
151 |
+
attn_weights = torch.max(attn_weights, torch.tensor(torch.finfo(attn_weights.dtype).min))
|
152 |
+
|
153 |
+
attn_weights = torch.nn.functional.softmax(attn_weights, dim=-1)
|
154 |
+
|
155 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
156 |
+
|
157 |
+
attn_output = attn_output.transpose(1, 2)
|
158 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
159 |
+
attn_output = self.o_proj(attn_output)
|
160 |
+
|
161 |
+
if not output_attentions:
|
162 |
+
attn_weights = None
|
163 |
+
|
164 |
+
return attn_output, attn_weights, past_key_value
|
165 |
+
|
166 |
+
|
167 |
+
class BaichuanLayer(torch.nn.Module):
|
168 |
+
def __init__(self, config: BaichuanConfig):
|
169 |
+
super().__init__()
|
170 |
+
self.hidden_size = config.hidden_size
|
171 |
+
self.self_attn = BaichuanAttention(config=config)
|
172 |
+
self.mlp = MLP(
|
173 |
+
hidden_size=self.hidden_size,
|
174 |
+
intermediate_size=config.intermediate_size,
|
175 |
+
hidden_act=config.hidden_act,
|
176 |
+
)
|
177 |
+
self.input_layernorm = RMSNorm(config.hidden_size, epsilon=config.rms_norm_eps)
|
178 |
+
self.post_attention_layernorm = RMSNorm(config.hidden_size, epsilon=config.rms_norm_eps)
|
179 |
+
|
180 |
+
def forward(
|
181 |
+
self,
|
182 |
+
hidden_states: torch.Tensor,
|
183 |
+
attention_mask: Optional[torch.Tensor] = None,
|
184 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
185 |
+
output_attentions: Optional[bool] = False,
|
186 |
+
use_cache: Optional[bool] = False,
|
187 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
188 |
+
|
189 |
+
residual = hidden_states
|
190 |
+
|
191 |
+
hidden_states = self.input_layernorm(hidden_states)
|
192 |
+
|
193 |
+
# Self Attention
|
194 |
+
hidden_states, self_attn_weights, present_key_value = self.self_attn(
|
195 |
+
hidden_states=hidden_states,
|
196 |
+
attention_mask=attention_mask,
|
197 |
+
past_key_value=past_key_value,
|
198 |
+
output_attentions=output_attentions,
|
199 |
+
use_cache=use_cache,
|
200 |
+
)
|
201 |
+
hidden_states = residual + hidden_states
|
202 |
+
|
203 |
+
# Fully Connected
|
204 |
+
residual = hidden_states
|
205 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
206 |
+
hidden_states = self.mlp(hidden_states)
|
207 |
+
hidden_states = residual + hidden_states
|
208 |
+
|
209 |
+
outputs = (hidden_states,)
|
210 |
+
|
211 |
+
if use_cache:
|
212 |
+
outputs += (present_key_value,)
|
213 |
+
|
214 |
+
return outputs
|
215 |
+
|
216 |
+
|
217 |
+
class BaichuanPreTrainedModel(PreTrainedModel):
|
218 |
+
config_class = BaichuanConfig
|
219 |
+
base_model_prefix = "model"
|
220 |
+
supports_gradient_checkpointing = True
|
221 |
+
_no_split_modules = ["BaichuanLayer"]
|
222 |
+
_keys_to_ignore_on_load_unexpected = [r"decoder\.version"]
|
223 |
+
|
224 |
+
def _init_weights(self, module):
|
225 |
+
std = self.config.initializer_range
|
226 |
+
if isinstance(module, torch.nn.Linear):
|
227 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
228 |
+
if module.bias is not None:
|
229 |
+
module.bias.data.zero_()
|
230 |
+
elif isinstance(module, torch.nn.Embedding):
|
231 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
232 |
+
if module.padding_idx is not None:
|
233 |
+
module.weight.data[module.padding_idx].zero_()
|
234 |
+
|
235 |
+
def _set_gradient_checkpointing(self, module, value=False):
|
236 |
+
if isinstance(module, BaichuanModel):
|
237 |
+
module.gradient_checkpointing = value
|
238 |
+
|
239 |
+
|
240 |
+
class BaichuanModel(BaichuanPreTrainedModel):
|
241 |
+
def __init__(self, config: BaichuanConfig):
|
242 |
+
super().__init__(config)
|
243 |
+
self.padding_idx = config.pad_token_id
|
244 |
+
self.vocab_size = config.vocab_size
|
245 |
+
self.n_head = config.num_attention_heads
|
246 |
+
self.embed_tokens = torch.nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
247 |
+
self.layers = torch.nn.ModuleList([BaichuanLayer(config) for _ in range(config.num_hidden_layers)])
|
248 |
+
self.norm = RMSNorm(config.hidden_size, epsilon=config.rms_norm_eps)
|
249 |
+
|
250 |
+
self.gradient_checkpointing = config.gradient_checkpointing
|
251 |
+
self.post_init()
|
252 |
+
self.max_cache_pos = config.model_max_length
|
253 |
+
self.first_run = True
|
254 |
+
self.alibi_mask = None
|
255 |
+
|
256 |
+
def get_input_embeddings(self):
|
257 |
+
return self.embed_tokens
|
258 |
+
|
259 |
+
def set_input_embeddings(self, value):
|
260 |
+
self.embed_tokens = value
|
261 |
+
|
262 |
+
def get_alibi_mask(self, tensor, seq_length_with_past):
|
263 |
+
if self.training:
|
264 |
+
slopes = torch.Tensor(_get_interleave(self.n_head))
|
265 |
+
alibi = slopes.unsqueeze(1).unsqueeze(1) * torch.arange(seq_length_with_past).unsqueeze(0).unsqueeze(0).expand(
|
266 |
+
self.n_head,
|
267 |
+
-1, -1)
|
268 |
+
alibi = alibi.view(self.n_head, 1, seq_length_with_past)
|
269 |
+
mask = _buffered_future_mask(tensor, seq_length_with_past, alibi, self.n_head)
|
270 |
+
else:
|
271 |
+
if self.first_run:
|
272 |
+
self.first_run = False
|
273 |
+
self.register_buffer("future_mask", _gen_alibi_mask(self.n_head, self.max_cache_pos).to(tensor), persistent=False)
|
274 |
+
if seq_length_with_past > self.max_cache_pos:
|
275 |
+
self.max_cache_pos = seq_length_with_past
|
276 |
+
self.register_buffer("future_mask", _gen_alibi_mask(self.n_head, self.max_cache_pos).to(tensor), persistent=False)
|
277 |
+
mask = self.future_mask[:self.n_head, :seq_length_with_past, :seq_length_with_past]
|
278 |
+
return mask
|
279 |
+
|
280 |
+
def forward(
|
281 |
+
self,
|
282 |
+
input_ids: torch.LongTensor = None,
|
283 |
+
attention_mask: Optional[torch.Tensor] = None,
|
284 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
285 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
286 |
+
use_cache: Optional[bool] = False,
|
287 |
+
output_attentions: Optional[bool] = False,
|
288 |
+
output_hidden_states: Optional[bool] = False,
|
289 |
+
return_dict: Optional[bool] = True,
|
290 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
291 |
+
|
292 |
+
if input_ids is not None and inputs_embeds is not None:
|
293 |
+
raise ValueError("You cannot provide both input_ids and inputs_embeds simultaneously")
|
294 |
+
elif input_ids is not None:
|
295 |
+
batch_size, seq_length = input_ids.shape
|
296 |
+
elif inputs_embeds is not None:
|
297 |
+
batch_size, seq_length, _ = inputs_embeds.shape
|
298 |
+
else:
|
299 |
+
raise ValueError("You need to provide input_ids or inputs_embeds")
|
300 |
+
|
301 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
302 |
+
|
303 |
+
seq_length_with_past = seq_length
|
304 |
+
|
305 |
+
if past_key_values is not None:
|
306 |
+
past_key_values_length = past_key_values[0][0].shape[2]
|
307 |
+
seq_length_with_past = seq_length_with_past + past_key_values_length
|
308 |
+
|
309 |
+
if inputs_embeds is None:
|
310 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
311 |
+
|
312 |
+
if self.training:
|
313 |
+
if self.alibi_mask is None or self.alibi_mask.shape[-1] != seq_length_with_past:
|
314 |
+
self.alibi_mask = self.get_alibi_mask(inputs_embeds, seq_length_with_past)
|
315 |
+
alibi_mask = self.alibi_mask
|
316 |
+
else:
|
317 |
+
alibi_mask = self.get_alibi_mask(inputs_embeds, seq_length_with_past)
|
318 |
+
|
319 |
+
if attention_mask is not None:
|
320 |
+
if len(attention_mask.shape) == 2:
|
321 |
+
expanded_mask = attention_mask.to(alibi_mask.dtype)
|
322 |
+
expanded_mask = torch.tril(torch.gt(expanded_mask[:, :, None] * expanded_mask[:, None, :], 0)
|
323 |
+
) * torch.eq(expanded_mask[:, :, None] - expanded_mask[:, None, :], 0)
|
324 |
+
else:
|
325 |
+
expanded_mask = attention_mask
|
326 |
+
bsz = inputs_embeds.size(0)
|
327 |
+
src_len, tgt_len = alibi_mask.size()[-2:]
|
328 |
+
expanded_mask = expanded_mask.unsqueeze(1).expand(bsz, 1, src_len, tgt_len).to(alibi_mask.dtype)
|
329 |
+
inverted_mask = 1.0 - expanded_mask
|
330 |
+
inverted_mask = inverted_mask.masked_fill(inverted_mask.to(torch.bool), torch.finfo(alibi_mask.dtype).min)
|
331 |
+
attention_mask = inverted_mask + alibi_mask.unsqueeze(0)
|
332 |
+
else:
|
333 |
+
attention_mask = alibi_mask
|
334 |
+
|
335 |
+
hidden_states = inputs_embeds
|
336 |
+
|
337 |
+
if self.gradient_checkpointing and self.training:
|
338 |
+
if use_cache:
|
339 |
+
logger.warning_once(
|
340 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
341 |
+
)
|
342 |
+
use_cache = False
|
343 |
+
|
344 |
+
# decoder layers
|
345 |
+
all_hidden_states = () if output_hidden_states else None
|
346 |
+
all_self_attns = () if output_attentions else None
|
347 |
+
next_decoder_cache = () if use_cache else None
|
348 |
+
|
349 |
+
for idx, decoder_layer in enumerate(self.layers):
|
350 |
+
if output_hidden_states:
|
351 |
+
all_hidden_states += (hidden_states,)
|
352 |
+
|
353 |
+
past_key_value = past_key_values[idx] if past_key_values is not None else None
|
354 |
+
|
355 |
+
if self.gradient_checkpointing and self.training:
|
356 |
+
|
357 |
+
def create_custom_forward(module):
|
358 |
+
def custom_forward(*inputs):
|
359 |
+
# None for past_key_value
|
360 |
+
return module(*inputs, output_attentions, None)
|
361 |
+
|
362 |
+
return custom_forward
|
363 |
+
|
364 |
+
layer_outputs = torch.utils.checkpoint.checkpoint(
|
365 |
+
create_custom_forward(decoder_layer),
|
366 |
+
hidden_states,
|
367 |
+
attention_mask,
|
368 |
+
None,
|
369 |
+
)
|
370 |
+
else:
|
371 |
+
layer_outputs = decoder_layer(
|
372 |
+
hidden_states,
|
373 |
+
attention_mask=attention_mask,
|
374 |
+
past_key_value=past_key_value,
|
375 |
+
output_attentions=output_attentions,
|
376 |
+
use_cache=use_cache,
|
377 |
+
)
|
378 |
+
|
379 |
+
hidden_states = layer_outputs[0]
|
380 |
+
|
381 |
+
if use_cache:
|
382 |
+
next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
|
383 |
+
|
384 |
+
if output_attentions:
|
385 |
+
all_self_attns += (layer_outputs[1],)
|
386 |
+
|
387 |
+
hidden_states = self.norm(hidden_states)
|
388 |
+
|
389 |
+
# add hidden states from the last decoder layer
|
390 |
+
if output_hidden_states:
|
391 |
+
all_hidden_states += (hidden_states,)
|
392 |
+
|
393 |
+
next_cache = next_decoder_cache if use_cache else None
|
394 |
+
if not return_dict:
|
395 |
+
return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
|
396 |
+
return BaseModelOutputWithPast(
|
397 |
+
last_hidden_state=hidden_states,
|
398 |
+
past_key_values=next_cache,
|
399 |
+
hidden_states=all_hidden_states,
|
400 |
+
attentions=all_self_attns,
|
401 |
+
)
|
402 |
+
|
403 |
+
|
404 |
+
class BaichuanForCausalLM(BaichuanPreTrainedModel):
|
405 |
+
def __init__(self, config):
|
406 |
+
super().__init__(config)
|
407 |
+
self.model = BaichuanModel(config)
|
408 |
+
self.lm_head = torch.nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
409 |
+
|
410 |
+
# Initialize weights and apply final processing
|
411 |
+
self.post_init()
|
412 |
+
|
413 |
+
def get_input_embeddings(self):
|
414 |
+
return self.model.embed_tokens
|
415 |
+
|
416 |
+
def set_input_embeddings(self, value):
|
417 |
+
self.model.embed_tokens = value
|
418 |
+
|
419 |
+
def get_output_embeddings(self):
|
420 |
+
return self.lm_head
|
421 |
+
|
422 |
+
def set_output_embeddings(self, new_embeddings):
|
423 |
+
self.lm_head = new_embeddings
|
424 |
+
|
425 |
+
def set_decoder(self, decoder):
|
426 |
+
self.model = decoder
|
427 |
+
|
428 |
+
def get_decoder(self):
|
429 |
+
return self.model
|
430 |
+
|
431 |
+
def forward(
|
432 |
+
self,
|
433 |
+
input_ids: torch.LongTensor = None,
|
434 |
+
attention_mask: Optional[torch.Tensor] = None,
|
435 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
436 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
437 |
+
labels: Optional[torch.LongTensor] = None,
|
438 |
+
use_cache: Optional[bool] = None,
|
439 |
+
output_attentions: Optional[bool] = False,
|
440 |
+
output_hidden_states: Optional[bool] = False,
|
441 |
+
return_dict: Optional[bool] = True,
|
442 |
+
**kwargs
|
443 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
444 |
+
|
445 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
446 |
+
|
447 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
448 |
+
outputs = self.model(
|
449 |
+
input_ids=input_ids,
|
450 |
+
attention_mask=attention_mask,
|
451 |
+
past_key_values=past_key_values,
|
452 |
+
inputs_embeds=inputs_embeds,
|
453 |
+
use_cache=use_cache,
|
454 |
+
output_attentions=output_attentions,
|
455 |
+
output_hidden_states=output_hidden_states,
|
456 |
+
return_dict=return_dict,
|
457 |
+
)
|
458 |
+
|
459 |
+
hidden_states = outputs[0]
|
460 |
+
logits = self.lm_head(hidden_states)
|
461 |
+
|
462 |
+
loss = None
|
463 |
+
if labels is not None:
|
464 |
+
# Shift so that tokens < n predict n
|
465 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
466 |
+
shift_labels = labels[..., 1:].contiguous()
|
467 |
+
# Flatten the tokens
|
468 |
+
loss_fct = CrossEntropyLoss()
|
469 |
+
shift_logits = shift_logits.view(-1, self.config.vocab_size)
|
470 |
+
shift_labels = shift_labels.view(-1)
|
471 |
+
# Enable model parallelism
|
472 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
473 |
+
loss = loss_fct(shift_logits, shift_labels)
|
474 |
+
|
475 |
+
if not return_dict:
|
476 |
+
output = (logits,) + outputs[1:]
|
477 |
+
return (loss,) + output if loss is not None else output
|
478 |
+
|
479 |
+
return CausalLMOutputWithPast(
|
480 |
+
loss=loss,
|
481 |
+
logits=logits,
|
482 |
+
past_key_values=outputs.past_key_values,
|
483 |
+
hidden_states=outputs.hidden_states,
|
484 |
+
attentions=outputs.attentions,
|
485 |
+
)
|
486 |
+
|
487 |
+
def prepare_inputs_for_generation(
|
488 |
+
self,
|
489 |
+
input_ids: torch.LongTensor,
|
490 |
+
past_key_values: Optional[torch.Tensor] = None,
|
491 |
+
attention_mask: Optional[torch.Tensor] = None,
|
492 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
493 |
+
**kwargs
|
494 |
+
):
|
495 |
+
if past_key_values:
|
496 |
+
input_ids = input_ids[:, -1:]
|
497 |
+
|
498 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
499 |
+
if inputs_embeds is not None and past_key_values is None:
|
500 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
501 |
+
else:
|
502 |
+
model_inputs = {"input_ids": input_ids}
|
503 |
+
|
504 |
+
model_inputs.update(
|
505 |
+
{
|
506 |
+
"past_key_values": past_key_values,
|
507 |
+
"use_cache": kwargs.get("use_cache"),
|
508 |
+
"attention_mask": attention_mask
|
509 |
+
}
|
510 |
+
)
|
511 |
+
return model_inputs
|
512 |
+
|
513 |
+
@staticmethod
|
514 |
+
def _reorder_cache(past_key_values, beam_idx):
|
515 |
+
return tuple(
|
516 |
+
tuple(past_state.index_select(0, beam_idx) for past_state in layer_past)
|
517 |
+
for layer_past in past_key_values
|
518 |
+
)
|
519 |
+
|
520 |
+
def quantize(self, bits: int):
|
521 |
+
try:
|
522 |
+
from .quantizer import QLinear
|
523 |
+
except ImportError:
|
524 |
+
raise ImportError(
|
525 |
+
f"Needs QLinear to run quantize."
|
526 |
+
)
|
527 |
+
|
528 |
+
for layer in self.model.layers:
|
529 |
+
layer.self_attn.W_pack = QLinear(
|
530 |
+
bits=bits,
|
531 |
+
weight=layer.self_attn.W_pack.weight,
|
532 |
+
bias = None,
|
533 |
+
)
|
534 |
+
layer.self_attn.o_proj = QLinear(
|
535 |
+
bits=bits,
|
536 |
+
weight=layer.self_attn.o_proj.weight,
|
537 |
+
bias = None,
|
538 |
+
)
|
539 |
+
layer.mlp.gate_proj = QLinear(
|
540 |
+
bits=bits,
|
541 |
+
weight=layer.mlp.gate_proj.weight,
|
542 |
+
bias = None,
|
543 |
+
)
|
544 |
+
layer.mlp.down_proj = QLinear(
|
545 |
+
bits=bits,
|
546 |
+
weight=layer.mlp.down_proj.weight,
|
547 |
+
bias = None,
|
548 |
+
)
|
549 |
+
layer.mlp.up_proj = QLinear(
|
550 |
+
bits=bits,
|
551 |
+
weight=layer.mlp.up_proj.weight,
|
552 |
+
bias = None,
|
553 |
+
)
|
554 |
+
return self
|
555 |
+
|
556 |
+
def _build_chat_input(self, tokenizer, messages: List[dict], max_new_tokens: int=0):
|
557 |
+
max_new_tokens = max_new_tokens or self.generation_config.max_new_tokens
|
558 |
+
max_input_tokens = self.config.model_max_length - max_new_tokens
|
559 |
+
max_input_tokens = max(self.config.model_max_length // 2, max_input_tokens)
|
560 |
+
total_input, round_input = [], []
|
561 |
+
for i, message in enumerate(messages[::-1]):
|
562 |
+
content_tokens = tokenizer.encode(message['content'])
|
563 |
+
if message['role'] == 'user':
|
564 |
+
round_input = [self.generation_config.user_token_id] + content_tokens + round_input
|
565 |
+
if total_input and len(total_input) + len(round_input) > max_input_tokens:
|
566 |
+
break
|
567 |
+
else:
|
568 |
+
total_input = round_input + total_input
|
569 |
+
if len(total_input) >= max_input_tokens:
|
570 |
+
break
|
571 |
+
else:
|
572 |
+
round_input = []
|
573 |
+
elif message['role'] == 'assistant':
|
574 |
+
round_input = [
|
575 |
+
self.generation_config.assistant_token_id
|
576 |
+
] + content_tokens + [
|
577 |
+
self.generation_config.eos_token_id
|
578 |
+
] + round_input
|
579 |
+
else:
|
580 |
+
raise ValueError(f"message role not supported yet: {message['role']}")
|
581 |
+
total_input = total_input[-max_input_tokens:] # truncate left
|
582 |
+
total_input.append(self.generation_config.assistant_token_id)
|
583 |
+
total_input = torch.LongTensor([total_input]).to(self.device)
|
584 |
+
return total_input
|
585 |
+
|
586 |
+
@torch.no_grad()
|
587 |
+
def chat(self, tokenizer, messages: List[dict], stream=False,
|
588 |
+
generation_config: Optional[GenerationConfig]=None):
|
589 |
+
generation_config = generation_config or self.generation_config
|
590 |
+
input_ids = self._build_chat_input(tokenizer, messages, generation_config.max_new_tokens)
|
591 |
+
if stream:
|
592 |
+
from transformers_stream_generator.main import (
|
593 |
+
NewGenerationMixin, StreamGenerationConfig)
|
594 |
+
self.__class__.generate = NewGenerationMixin.generate
|
595 |
+
self.__class__.sample_stream = NewGenerationMixin.sample_stream
|
596 |
+
stream_config = StreamGenerationConfig(**generation_config.to_dict(), do_stream=True)
|
597 |
+
|
598 |
+
def stream_generator():
|
599 |
+
outputs = []
|
600 |
+
for token in self.generate(input_ids, generation_config=stream_config):
|
601 |
+
outputs.append(token.item())
|
602 |
+
yield tokenizer.decode(outputs, skip_special_tokens=True)
|
603 |
+
|
604 |
+
return stream_generator()
|
605 |
+
else:
|
606 |
+
self.__class__.generate = PreTrainedModel.generate # disable stream
|
607 |
+
outputs = self.generate(input_ids, generation_config=generation_config)
|
608 |
+
response = tokenizer.decode(outputs[0][len(input_ids[0]):], skip_special_tokens=True)
|
609 |
+
return response
|
pytorch_model-00001-of-00003.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:01664b5377d9174ebfbfc466a6bf639ffe97a2bc8a49e7007b51c8094f952651
|
3 |
+
size 9972281188
|
pytorch_model-00002-of-00003.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d7b5e87c883170cd73ac17044d78c5042b619788a8b60404a71ebf6c79f5a0fe
|
3 |
+
size 9947421360
|
pytorch_model-00003-of-00003.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2fe7542e910746e85d1ab45af3a036f644711417e62e16592d8cfc146902dd7c
|
3 |
+
size 6610200289
|
pytorch_model.bin.index.json
ADDED
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 26529802240
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"lm_head.weight": "pytorch_model-00003-of-00003.bin",
|
7 |
+
"model.embed_tokens.weight": "pytorch_model-00001-of-00003.bin",
|
8 |
+
"model.layers.0.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
9 |
+
"model.layers.0.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
10 |
+
"model.layers.0.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
11 |
+
"model.layers.0.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
12 |
+
"model.layers.0.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
13 |
+
"model.layers.0.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
14 |
+
"model.layers.0.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
15 |
+
"model.layers.1.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
16 |
+
"model.layers.1.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
17 |
+
"model.layers.1.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
18 |
+
"model.layers.1.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
19 |
+
"model.layers.1.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
20 |
+
"model.layers.1.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
21 |
+
"model.layers.1.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
22 |
+
"model.layers.10.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
23 |
+
"model.layers.10.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
24 |
+
"model.layers.10.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
25 |
+
"model.layers.10.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
26 |
+
"model.layers.10.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
27 |
+
"model.layers.10.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
28 |
+
"model.layers.10.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
29 |
+
"model.layers.11.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
30 |
+
"model.layers.11.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
31 |
+
"model.layers.11.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
32 |
+
"model.layers.11.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
33 |
+
"model.layers.11.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
34 |
+
"model.layers.11.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
35 |
+
"model.layers.11.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
36 |
+
"model.layers.12.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
37 |
+
"model.layers.12.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
38 |
+
"model.layers.12.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
39 |
+
"model.layers.12.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
40 |
+
"model.layers.12.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
41 |
+
"model.layers.12.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
42 |
+
"model.layers.12.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
43 |
+
"model.layers.13.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
44 |
+
"model.layers.13.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
45 |
+
"model.layers.13.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
46 |
+
"model.layers.13.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
47 |
+
"model.layers.13.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
48 |
+
"model.layers.13.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
49 |
+
"model.layers.13.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
50 |
+
"model.layers.14.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
51 |
+
"model.layers.14.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
52 |
+
"model.layers.14.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
53 |
+
"model.layers.14.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
54 |
+
"model.layers.14.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
55 |
+
"model.layers.14.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
56 |
+
"model.layers.14.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
57 |
+
"model.layers.15.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
58 |
+
"model.layers.15.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
59 |
+
"model.layers.15.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
60 |
+
"model.layers.15.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
61 |
+
"model.layers.15.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
62 |
+
"model.layers.15.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
63 |
+
"model.layers.15.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
64 |
+
"model.layers.16.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
65 |
+
"model.layers.16.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
66 |
+
"model.layers.16.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
67 |
+
"model.layers.16.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
68 |
+
"model.layers.16.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
69 |
+
"model.layers.16.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
70 |
+
"model.layers.16.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
71 |
+
"model.layers.17.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
72 |
+
"model.layers.17.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
73 |
+
"model.layers.17.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
74 |
+
"model.layers.17.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
75 |
+
"model.layers.17.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
76 |
+
"model.layers.17.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
77 |
+
"model.layers.17.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
78 |
+
"model.layers.18.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
79 |
+
"model.layers.18.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
80 |
+
"model.layers.18.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
81 |
+
"model.layers.18.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
82 |
+
"model.layers.18.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
83 |
+
"model.layers.18.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
84 |
+
"model.layers.18.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
85 |
+
"model.layers.19.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
86 |
+
"model.layers.19.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
87 |
+
"model.layers.19.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
88 |
+
"model.layers.19.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
89 |
+
"model.layers.19.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
90 |
+
"model.layers.19.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
91 |
+
"model.layers.19.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
92 |
+
"model.layers.2.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
93 |
+
"model.layers.2.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
94 |
+
"model.layers.2.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
95 |
+
"model.layers.2.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
96 |
+
"model.layers.2.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
97 |
+
"model.layers.2.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
98 |
+
"model.layers.2.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
99 |
+
"model.layers.20.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
100 |
+
"model.layers.20.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
101 |
+
"model.layers.20.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
102 |
+
"model.layers.20.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
103 |
+
"model.layers.20.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
104 |
+
"model.layers.20.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
105 |
+
"model.layers.20.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
106 |
+
"model.layers.21.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
107 |
+
"model.layers.21.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
108 |
+
"model.layers.21.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
109 |
+
"model.layers.21.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
110 |
+
"model.layers.21.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
111 |
+
"model.layers.21.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
112 |
+
"model.layers.21.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
113 |
+
"model.layers.22.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
114 |
+
"model.layers.22.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
115 |
+
"model.layers.22.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
116 |
+
"model.layers.22.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
117 |
+
"model.layers.22.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
118 |
+
"model.layers.22.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
119 |
+
"model.layers.22.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
120 |
+
"model.layers.23.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
121 |
+
"model.layers.23.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
122 |
+
"model.layers.23.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
123 |
+
"model.layers.23.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
124 |
+
"model.layers.23.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
125 |
+
"model.layers.23.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
126 |
+
"model.layers.23.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
127 |
+
"model.layers.24.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
128 |
+
"model.layers.24.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
129 |
+
"model.layers.24.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
130 |
+
"model.layers.24.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
131 |
+
"model.layers.24.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
132 |
+
"model.layers.24.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
133 |
+
"model.layers.24.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
134 |
+
"model.layers.25.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
135 |
+
"model.layers.25.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
136 |
+
"model.layers.25.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
137 |
+
"model.layers.25.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
138 |
+
"model.layers.25.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
139 |
+
"model.layers.25.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
140 |
+
"model.layers.25.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
141 |
+
"model.layers.26.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
142 |
+
"model.layers.26.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
143 |
+
"model.layers.26.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
144 |
+
"model.layers.26.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
145 |
+
"model.layers.26.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
146 |
+
"model.layers.26.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
147 |
+
"model.layers.26.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
148 |
+
"model.layers.27.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
149 |
+
"model.layers.27.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
150 |
+
"model.layers.27.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
151 |
+
"model.layers.27.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
152 |
+
"model.layers.27.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
153 |
+
"model.layers.27.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
154 |
+
"model.layers.27.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
155 |
+
"model.layers.28.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
156 |
+
"model.layers.28.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
157 |
+
"model.layers.28.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
158 |
+
"model.layers.28.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
159 |
+
"model.layers.28.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
160 |
+
"model.layers.28.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
161 |
+
"model.layers.28.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
162 |
+
"model.layers.29.input_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
163 |
+
"model.layers.29.mlp.down_proj.weight": "pytorch_model-00002-of-00003.bin",
|
164 |
+
"model.layers.29.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
165 |
+
"model.layers.29.mlp.up_proj.weight": "pytorch_model-00002-of-00003.bin",
|
166 |
+
"model.layers.29.post_attention_layernorm.weight": "pytorch_model-00002-of-00003.bin",
|
167 |
+
"model.layers.29.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
168 |
+
"model.layers.29.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
169 |
+
"model.layers.3.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
170 |
+
"model.layers.3.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
171 |
+
"model.layers.3.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
172 |
+
"model.layers.3.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
173 |
+
"model.layers.3.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
174 |
+
"model.layers.3.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
175 |
+
"model.layers.3.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
176 |
+
"model.layers.30.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
177 |
+
"model.layers.30.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
178 |
+
"model.layers.30.mlp.gate_proj.weight": "pytorch_model-00002-of-00003.bin",
|
179 |
+
"model.layers.30.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
180 |
+
"model.layers.30.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
181 |
+
"model.layers.30.self_attn.W_pack.weight": "pytorch_model-00002-of-00003.bin",
|
182 |
+
"model.layers.30.self_attn.o_proj.weight": "pytorch_model-00002-of-00003.bin",
|
183 |
+
"model.layers.31.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
184 |
+
"model.layers.31.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
185 |
+
"model.layers.31.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
186 |
+
"model.layers.31.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
187 |
+
"model.layers.31.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
188 |
+
"model.layers.31.self_attn.W_pack.weight": "pytorch_model-00003-of-00003.bin",
|
189 |
+
"model.layers.31.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
190 |
+
"model.layers.32.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
191 |
+
"model.layers.32.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
192 |
+
"model.layers.32.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
193 |
+
"model.layers.32.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
194 |
+
"model.layers.32.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
195 |
+
"model.layers.32.self_attn.W_pack.weight": "pytorch_model-00003-of-00003.bin",
|
196 |
+
"model.layers.32.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
197 |
+
"model.layers.33.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
198 |
+
"model.layers.33.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
199 |
+
"model.layers.33.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
200 |
+
"model.layers.33.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
201 |
+
"model.layers.33.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
202 |
+
"model.layers.33.self_attn.W_pack.weight": "pytorch_model-00003-of-00003.bin",
|
203 |
+
"model.layers.33.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
204 |
+
"model.layers.34.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
205 |
+
"model.layers.34.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
206 |
+
"model.layers.34.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
207 |
+
"model.layers.34.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
208 |
+
"model.layers.34.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
209 |
+
"model.layers.34.self_attn.W_pack.weight": "pytorch_model-00003-of-00003.bin",
|
210 |
+
"model.layers.34.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
211 |
+
"model.layers.35.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
212 |
+
"model.layers.35.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
213 |
+
"model.layers.35.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
214 |
+
"model.layers.35.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
215 |
+
"model.layers.35.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
216 |
+
"model.layers.35.self_attn.W_pack.weight": "pytorch_model-00003-of-00003.bin",
|
217 |
+
"model.layers.35.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
218 |
+
"model.layers.36.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
219 |
+
"model.layers.36.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
220 |
+
"model.layers.36.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
221 |
+
"model.layers.36.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
222 |
+
"model.layers.36.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
223 |
+
"model.layers.36.self_attn.W_pack.weight": "pytorch_model-00003-of-00003.bin",
|
224 |
+
"model.layers.36.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
225 |
+
"model.layers.37.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
226 |
+
"model.layers.37.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
227 |
+
"model.layers.37.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
228 |
+
"model.layers.37.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
229 |
+
"model.layers.37.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
230 |
+
"model.layers.37.self_attn.W_pack.weight": "pytorch_model-00003-of-00003.bin",
|
231 |
+
"model.layers.37.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
232 |
+
"model.layers.38.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
233 |
+
"model.layers.38.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
234 |
+
"model.layers.38.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
235 |
+
"model.layers.38.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
236 |
+
"model.layers.38.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
237 |
+
"model.layers.38.self_attn.W_pack.weight": "pytorch_model-00003-of-00003.bin",
|
238 |
+
"model.layers.38.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
239 |
+
"model.layers.39.input_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
240 |
+
"model.layers.39.mlp.down_proj.weight": "pytorch_model-00003-of-00003.bin",
|
241 |
+
"model.layers.39.mlp.gate_proj.weight": "pytorch_model-00003-of-00003.bin",
|
242 |
+
"model.layers.39.mlp.up_proj.weight": "pytorch_model-00003-of-00003.bin",
|
243 |
+
"model.layers.39.post_attention_layernorm.weight": "pytorch_model-00003-of-00003.bin",
|
244 |
+
"model.layers.39.self_attn.W_pack.weight": "pytorch_model-00003-of-00003.bin",
|
245 |
+
"model.layers.39.self_attn.o_proj.weight": "pytorch_model-00003-of-00003.bin",
|
246 |
+
"model.layers.4.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
247 |
+
"model.layers.4.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
248 |
+
"model.layers.4.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
249 |
+
"model.layers.4.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
250 |
+
"model.layers.4.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
251 |
+
"model.layers.4.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
252 |
+
"model.layers.4.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
253 |
+
"model.layers.5.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
254 |
+
"model.layers.5.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
255 |
+
"model.layers.5.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
256 |
+
"model.layers.5.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
257 |
+
"model.layers.5.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
258 |
+
"model.layers.5.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
259 |
+
"model.layers.5.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
260 |
+
"model.layers.6.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
261 |
+
"model.layers.6.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
262 |
+
"model.layers.6.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
263 |
+
"model.layers.6.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
264 |
+
"model.layers.6.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
265 |
+
"model.layers.6.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
266 |
+
"model.layers.6.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
267 |
+
"model.layers.7.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
268 |
+
"model.layers.7.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
269 |
+
"model.layers.7.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
270 |
+
"model.layers.7.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
271 |
+
"model.layers.7.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
272 |
+
"model.layers.7.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
273 |
+
"model.layers.7.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
274 |
+
"model.layers.8.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
275 |
+
"model.layers.8.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
276 |
+
"model.layers.8.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
277 |
+
"model.layers.8.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
278 |
+
"model.layers.8.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
279 |
+
"model.layers.8.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
280 |
+
"model.layers.8.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
281 |
+
"model.layers.9.input_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
282 |
+
"model.layers.9.mlp.down_proj.weight": "pytorch_model-00001-of-00003.bin",
|
283 |
+
"model.layers.9.mlp.gate_proj.weight": "pytorch_model-00001-of-00003.bin",
|
284 |
+
"model.layers.9.mlp.up_proj.weight": "pytorch_model-00001-of-00003.bin",
|
285 |
+
"model.layers.9.post_attention_layernorm.weight": "pytorch_model-00001-of-00003.bin",
|
286 |
+
"model.layers.9.self_attn.W_pack.weight": "pytorch_model-00001-of-00003.bin",
|
287 |
+
"model.layers.9.self_attn.o_proj.weight": "pytorch_model-00001-of-00003.bin",
|
288 |
+
"model.norm.weight": "pytorch_model-00003-of-00003.bin"
|
289 |
+
}
|
290 |
+
}
|
quantizer.py
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) 2023, Baichuan Intelligent Technology. All rights reserved.
|
2 |
+
|
3 |
+
import base64
|
4 |
+
import bz2
|
5 |
+
import ctypes
|
6 |
+
from typing import List
|
7 |
+
|
8 |
+
import torch
|
9 |
+
from transformers.utils import logging
|
10 |
+
|
11 |
+
logger = logging.get_logger(__name__)
|
12 |
+
|
13 |
+
try:
|
14 |
+
from cpm_kernels.kernels.base import (KernelFunction, LazyKernelCModule,
|
15 |
+
round_up)
|
16 |
+
|
17 |
+
class Kernel:
|
18 |
+
def __init__(self, code: bytes, function_names: List[str]):
|
19 |
+
self.code = code
|
20 |
+
self._function_names = function_names
|
21 |
+
self._cmodule = LazyKernelCModule(self.code)
|
22 |
+
|
23 |
+
for name in self._function_names:
|
24 |
+
setattr(self, name, KernelFunction(self._cmodule, name))
|
25 |
+
quantization_code = "QlpoOTFBWSZTWX/mUzwAK6f///////////////////////////////7f////////////4C5duvi2D0Oj1ppVCJ2zQFYbnbsxmq20pAC7kEDb3Z3nWrextY9NZbavON7nveSRqszudmzAGGgkeh0Pewk881e3Tz13kW9YO7uA9AUUiAWLNW2HHWCE005Mdz3jHs1Ic7QNCQBNGgmE000DRNoGjUYmA0mEmJjIaI9JtT0JoaaMTaQ0aMjTTI1TzKMmETwyaJ6k8p4Ke1T0wk2aE0anpPSHppqNM1HqYzVGj0MpsTTUGpoCAAEyAAAmhpPSYowMk9U8mqb0mJtU8ETwCZT1DQ9R5R6htE9TTyRptQeoyHqA0B6g9T1AD1HpGQGgD1A0NPUAAAA0A1Mg00gmhKPU9E2SekHoJ5QHlNDEPUeoDEaBkAHqBoABoNABoAaGgBoAAAAAAA0AAAAAAAAEmoiIgmiD0maRip+qfpR+k9U/QKaZPUepiGeST1HqeU9TQ9JoANAMhoZPU0AAYnqaBoAANABoAAAADQGgAAADTQ0IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASJEE0AJo0GkxGJoZNKeBoTCnpNNpU9knqn+ppmUnom1PKZqTaaTTwTTFPNJ6pj1BG0eo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xpWCMkDUZIBUQoKpooWCkAnBzOK5na/LqSSLTATYIaabQCteZkFlqs0bDPpuWAcNiRn6GWSnwrsatNVFIK0+WUGVX3p1UghXmamW9amFzoPHfP2Z3WLhW9ZEaq0DQiqOJyRC17MYwQA84eUDjyR/GOBNpNoO1pV6NwwsBZoAgBWz+M+YS5GC+Su1IEB0A5in0LwPQxXq7joeDPBdd3DzF6z96RTojxR29u8vE3GnO6jAa0MBmCuoxyYl/SDsbSpYIlMINttOUZndGWJ2JgBs8s7bw1GhnALOxFBnZayRRjt4bSvH+Ma9WNZSaKBoUDtDEQNIMt5XAZJIvEFZSahWUgL7ADIBAjZYJVAK8NHljSCRbLZdxbuCkFfrZVirL+GkBWYaJFCoglTaEWtiguhCVZNjj+c9eMUMbOVJQmcHOmKmRIKboAMkAbohUflNANgubKuhTXDGSlSKY0PetmdL+7bQoIJCVRY+osfasgH1NADQYBBoYd+dccoSIhapDyYkRkhkYGAZDWCMlJReDHnRJZKAxUYiJmPGYriVoGAkdW2QI785BQQakRBFiFEknMOMGpw8jj8a7sLaWrGrZ5gDnB2Ys6AFHfczh5BvVw8R6n1P4QHEbDeIf/i7kinChIP/Mpng="
|
26 |
+
kernels = Kernel(
|
27 |
+
bz2.decompress(base64.b64decode(quantization_code)),
|
28 |
+
[
|
29 |
+
"int4_to_fp16",
|
30 |
+
"fp16_to_int4",
|
31 |
+
"int8_to_fp16",
|
32 |
+
"fp16_to_int8",
|
33 |
+
"int4_to_bf16",
|
34 |
+
"bf16_to_int4",
|
35 |
+
"int8_to_bf16",
|
36 |
+
"bf16_to_int8",
|
37 |
+
],
|
38 |
+
)
|
39 |
+
except Exception as exception:
|
40 |
+
kernels = None
|
41 |
+
logger.warning("Failed to load kernels:" + str(exception))
|
42 |
+
|
43 |
+
def quant4(weight: torch.Tensor, scale: torch.Tensor):
|
44 |
+
stream = torch.cuda.current_stream()
|
45 |
+
num_row = weight.size(0)
|
46 |
+
num_chan_fp16 = weight.size(1)
|
47 |
+
# 4bit
|
48 |
+
num_chan_int = num_chan_fp16 // 8
|
49 |
+
qweight = torch.zeros((num_row, num_chan_int), dtype=torch.int32, device=weight.device)
|
50 |
+
intweight = torch.empty(num_row, num_chan_fp16, dtype = torch.int32)
|
51 |
+
intweight = torch.clip(torch.round(weight.to(scale.dtype) / scale[:, None]),-16, 15).to(dtype=torch.int32)
|
52 |
+
|
53 |
+
for j in range(num_chan_int):
|
54 |
+
qweight[:, j] = ((intweight[:, j*8+7] & 0x0f) << 28) \
|
55 |
+
| ((intweight[:, j*8+6] & 0x0f) << 24) \
|
56 |
+
| ((intweight[:, j*8+5] & 0x0f) << 20) \
|
57 |
+
| ((intweight[:, j*8+4] & 0x0f) << 16) \
|
58 |
+
| ((intweight[:, j*8+3] & 0x0f) << 12) \
|
59 |
+
| ((intweight[:, j*8+2] & 0x0f) << 8) \
|
60 |
+
| ((intweight[:, j*8+1] & 0x0f) << 4) \
|
61 |
+
| ((intweight[:, j*8] & 0x0f))
|
62 |
+
return qweight
|
63 |
+
|
64 |
+
def dequant4(qweight: torch.Tensor, scale: torch.Tensor, input: torch.Tensor):
|
65 |
+
stream = torch.cuda.current_stream()
|
66 |
+
num_row = qweight.size(0)
|
67 |
+
num_chan_int = qweight.size(1)
|
68 |
+
# 4bit
|
69 |
+
num_chan_fp16 = num_chan_int * 8
|
70 |
+
|
71 |
+
out = torch.empty((num_row, num_chan_fp16), dtype=input.dtype, device=qweight.device)
|
72 |
+
|
73 |
+
blockDim = (128, 1, 1)
|
74 |
+
gridDim = ((num_chan_int + blockDim[0] - 1) // blockDim[0], num_row, 1)
|
75 |
+
if input.dtype == torch.bfloat16:
|
76 |
+
kernels.int4_to_bf16(
|
77 |
+
gridDim,
|
78 |
+
blockDim,
|
79 |
+
0,
|
80 |
+
stream,
|
81 |
+
[ctypes.c_void_p(out.data_ptr()), ctypes.c_void_p(qweight.data_ptr()),
|
82 |
+
ctypes.c_void_p(scale.data_ptr()), ctypes.c_int32(num_row), ctypes.c_int32(num_chan_int), ctypes.c_int32(num_chan_fp16)],
|
83 |
+
)
|
84 |
+
elif input.dtype == torch.float16:
|
85 |
+
kernels.int4_to_fp16(
|
86 |
+
gridDim,
|
87 |
+
blockDim,
|
88 |
+
0,
|
89 |
+
stream,
|
90 |
+
[ctypes.c_void_p(out.data_ptr()), ctypes.c_void_p(qweight.data_ptr()),
|
91 |
+
ctypes.c_void_p(scale.data_ptr()), ctypes.c_int32(num_row), ctypes.c_int32(num_chan_int), ctypes.c_int32(num_chan_fp16)],
|
92 |
+
)
|
93 |
+
return out
|
94 |
+
|
95 |
+
class QLinear(torch.nn.Module):
|
96 |
+
def __init__(self, bits: int, weight: torch.Tensor, bias=None):
|
97 |
+
super().__init__()
|
98 |
+
self.quant_bits = bits
|
99 |
+
self.scale = weight.abs().max(dim=-1).values / ((2 ** (bits - 1)) - 1)
|
100 |
+
self.scale = self.scale.to(torch.float32)
|
101 |
+
if self.quant_bits == 4:
|
102 |
+
self.weight = quant4(weight, self.scale)
|
103 |
+
elif self.quant_bits == 8:
|
104 |
+
self.weight = torch.round(weight.to(self.scale.dtype) / self.scale[:, None]).to(torch.int8)
|
105 |
+
if self.quant_bits == 8:
|
106 |
+
self.weight = self.weight.T
|
107 |
+
self.bias = None
|
108 |
+
|
109 |
+
def forward(self, input):
|
110 |
+
if self.quant_bits == 4:
|
111 |
+
assert(input.dtype == torch.bfloat16 or input.dtype == torch.float16)
|
112 |
+
|
113 |
+
if self.weight.device != input.device:
|
114 |
+
self.weight = self.weight.to(input.device)
|
115 |
+
self.scale = self.scale.to(input.device)
|
116 |
+
|
117 |
+
if self.quant_bits == 4:
|
118 |
+
self.scale = self.scale.to(input.dtype)
|
119 |
+
rweight = dequant4(self.weight, self.scale, input).T
|
120 |
+
output = torch.matmul(input, rweight)
|
121 |
+
elif self.quant_bits == 8:
|
122 |
+
rweight = self.weight.to(input.dtype) * self.scale.to(input.dtype)
|
123 |
+
output = torch.matmul(input, rweight)
|
124 |
+
if self.bias is not None:
|
125 |
+
output = output + self.bias
|
126 |
+
return output
|
special_tokens_map.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": true,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": true
|
8 |
+
},
|
9 |
+
"eos_token": {
|
10 |
+
"content": "</s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": true,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": true
|
15 |
+
},
|
16 |
+
"pad_token": {
|
17 |
+
"content": "<unk>",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": true,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": true
|
22 |
+
},
|
23 |
+
"unk_token": {
|
24 |
+
"content": "<unk>",
|
25 |
+
"lstrip": false,
|
26 |
+
"normalized": true,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": true
|
29 |
+
}
|
30 |
+
}
|
tokenization_baichuan.py
ADDED
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) 2023, Baichuan Intelligent Technology. All rights reserved.
|
2 |
+
|
3 |
+
import os
|
4 |
+
from shutil import copyfile
|
5 |
+
from typing import Any, Dict, List, Optional, Tuple
|
6 |
+
|
7 |
+
import sentencepiece as spm
|
8 |
+
from transformers.tokenization_utils import AddedToken, PreTrainedTokenizer
|
9 |
+
from transformers.utils import logging
|
10 |
+
|
11 |
+
|
12 |
+
logger = logging.get_logger(__name__)
|
13 |
+
|
14 |
+
VOCAB_FILES_NAMES = {"vocab_file": "tokenizer.model"}
|
15 |
+
|
16 |
+
PRETRAINED_VOCAB_FILES_MAP = {
|
17 |
+
"vocab_file": {},
|
18 |
+
"tokenizer_file": {},
|
19 |
+
}
|
20 |
+
PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES = {}
|
21 |
+
|
22 |
+
|
23 |
+
class BaichuanTokenizer(PreTrainedTokenizer):
|
24 |
+
"""
|
25 |
+
Construct a Baichuan tokenizer. Based on byte-level Byte-Pair-Encoding.
|
26 |
+
|
27 |
+
Args:
|
28 |
+
vocab_file (`str`):
|
29 |
+
Path to the vocabulary file.
|
30 |
+
"""
|
31 |
+
|
32 |
+
vocab_files_names = VOCAB_FILES_NAMES
|
33 |
+
pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
|
34 |
+
max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
|
35 |
+
model_input_names = ["input_ids", "attention_mask"]
|
36 |
+
|
37 |
+
def __init__(
|
38 |
+
self,
|
39 |
+
vocab_file,
|
40 |
+
unk_token="<unk>",
|
41 |
+
bos_token="<s>",
|
42 |
+
eos_token="</s>",
|
43 |
+
pad_token=None,
|
44 |
+
sp_model_kwargs: Optional[Dict[str, Any]] = None,
|
45 |
+
add_bos_token=True,
|
46 |
+
add_eos_token=False,
|
47 |
+
clean_up_tokenization_spaces=False,
|
48 |
+
**kwargs,
|
49 |
+
):
|
50 |
+
self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
|
51 |
+
bos_token = AddedToken(bos_token, lstrip=False, rstrip=False) if isinstance(bos_token, str) else bos_token
|
52 |
+
eos_token = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_token
|
53 |
+
unk_token = AddedToken(unk_token, lstrip=False, rstrip=False) if isinstance(unk_token, str) else unk_token
|
54 |
+
pad_token = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_token
|
55 |
+
super().__init__(
|
56 |
+
bos_token=bos_token,
|
57 |
+
eos_token=eos_token,
|
58 |
+
unk_token=unk_token,
|
59 |
+
pad_token=pad_token,
|
60 |
+
add_bos_token=add_bos_token,
|
61 |
+
add_eos_token=add_eos_token,
|
62 |
+
sp_model_kwargs=self.sp_model_kwargs,
|
63 |
+
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
|
64 |
+
**kwargs,
|
65 |
+
)
|
66 |
+
self.vocab_file = vocab_file
|
67 |
+
self.add_bos_token = add_bos_token
|
68 |
+
self.add_eos_token = add_eos_token
|
69 |
+
self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
|
70 |
+
self.sp_model.Load(vocab_file)
|
71 |
+
|
72 |
+
def __getstate__(self):
|
73 |
+
state = self.__dict__.copy()
|
74 |
+
state["sp_model"] = None
|
75 |
+
return state
|
76 |
+
|
77 |
+
def __setstate__(self, d):
|
78 |
+
self.__dict__ = d
|
79 |
+
self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
|
80 |
+
self.sp_model.Load(self.vocab_file)
|
81 |
+
|
82 |
+
@property
|
83 |
+
def vocab_size(self):
|
84 |
+
"""Returns vocab size"""
|
85 |
+
return self.sp_model.get_piece_size()
|
86 |
+
|
87 |
+
def get_vocab(self):
|
88 |
+
"""Returns vocab as a dict"""
|
89 |
+
vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
|
90 |
+
vocab.update(self.added_tokens_encoder)
|
91 |
+
return vocab
|
92 |
+
|
93 |
+
def _tokenize(self, text):
|
94 |
+
"""Returns a tokenized string."""
|
95 |
+
return self.sp_model.encode(text, out_type=str)
|
96 |
+
|
97 |
+
def _convert_token_to_id(self, token):
|
98 |
+
"""Converts a token (str) in an id using the vocab."""
|
99 |
+
return self.sp_model.piece_to_id(token)
|
100 |
+
|
101 |
+
def _convert_id_to_token(self, index):
|
102 |
+
"""Converts an index (integer) in a token (str) using the vocab."""
|
103 |
+
token = self.sp_model.IdToPiece(index)
|
104 |
+
return token
|
105 |
+
|
106 |
+
def convert_tokens_to_string(self, tokens):
|
107 |
+
"""Converts a sequence of tokens (string) in a single string."""
|
108 |
+
current_sub_tokens = []
|
109 |
+
out_string = ""
|
110 |
+
prev_is_special = False
|
111 |
+
for i, token in enumerate(tokens):
|
112 |
+
# make sure that special tokens are not decoded using sentencepiece model
|
113 |
+
if token in self.all_special_tokens:
|
114 |
+
if not prev_is_special and i != 0:
|
115 |
+
out_string += " "
|
116 |
+
out_string += self.sp_model.decode(current_sub_tokens) + token
|
117 |
+
prev_is_special = True
|
118 |
+
current_sub_tokens = []
|
119 |
+
else:
|
120 |
+
current_sub_tokens.append(token)
|
121 |
+
prev_is_special = False
|
122 |
+
out_string += self.sp_model.decode(current_sub_tokens)
|
123 |
+
return out_string
|
124 |
+
|
125 |
+
def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]:
|
126 |
+
"""
|
127 |
+
Save the vocabulary and special tokens file to a directory.
|
128 |
+
|
129 |
+
Args:
|
130 |
+
save_directory (`str`):
|
131 |
+
The directory in which to save the vocabulary.
|
132 |
+
|
133 |
+
Returns:
|
134 |
+
`Tuple(str)`: Paths to the files saved.
|
135 |
+
"""
|
136 |
+
if not os.path.isdir(save_directory):
|
137 |
+
logger.error(f"Vocabulary path ({save_directory}) should be a directory")
|
138 |
+
return
|
139 |
+
out_vocab_file = os.path.join(
|
140 |
+
save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
|
141 |
+
)
|
142 |
+
|
143 |
+
if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
|
144 |
+
copyfile(self.vocab_file, out_vocab_file)
|
145 |
+
elif not os.path.isfile(self.vocab_file):
|
146 |
+
with open(out_vocab_file, "wb") as fi:
|
147 |
+
content_spiece_model = self.sp_model.serialized_model_proto()
|
148 |
+
fi.write(content_spiece_model)
|
149 |
+
|
150 |
+
return (out_vocab_file,)
|
151 |
+
|
152 |
+
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
|
153 |
+
bos_token_id = [self.bos_token_id] if self.add_bos_token else []
|
154 |
+
eos_token_id = [self.eos_token_id] if self.add_eos_token else []
|
155 |
+
|
156 |
+
output = bos_token_id + token_ids_0 + eos_token_id
|
157 |
+
|
158 |
+
if token_ids_1 is not None:
|
159 |
+
output = output + bos_token_id + token_ids_1 + eos_token_id
|
160 |
+
|
161 |
+
return output
|
162 |
+
|
163 |
+
def get_special_tokens_mask(
|
164 |
+
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
|
165 |
+
) -> List[int]:
|
166 |
+
"""
|
167 |
+
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
|
168 |
+
special tokens using the tokenizer `prepare_for_model` method.
|
169 |
+
|
170 |
+
Args:
|
171 |
+
token_ids_0 (`List[int]`):
|
172 |
+
List of IDs.
|
173 |
+
token_ids_1 (`List[int]`, *optional*):
|
174 |
+
Optional second list of IDs for sequence pairs.
|
175 |
+
already_has_special_tokens (`bool`, *optional*, defaults to `False`):
|
176 |
+
Whether or not the token list is already formatted with special tokens for the model.
|
177 |
+
|
178 |
+
Returns:
|
179 |
+
`List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
|
180 |
+
"""
|
181 |
+
if already_has_special_tokens:
|
182 |
+
return super().get_special_tokens_mask(
|
183 |
+
token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
|
184 |
+
)
|
185 |
+
|
186 |
+
bos_token_id = [1] if self.add_bos_token else []
|
187 |
+
eos_token_id = [1] if self.add_eos_token else []
|
188 |
+
|
189 |
+
if token_ids_1 is None:
|
190 |
+
return bos_token_id + ([0] * len(token_ids_0)) + eos_token_id
|
191 |
+
return (
|
192 |
+
bos_token_id
|
193 |
+
+ ([0] * len(token_ids_0))
|
194 |
+
+ eos_token_id
|
195 |
+
+ bos_token_id
|
196 |
+
+ ([0] * len(token_ids_1))
|
197 |
+
+ eos_token_id
|
198 |
+
)
|
199 |
+
|
200 |
+
def create_token_type_ids_from_sequences(
|
201 |
+
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
|
202 |
+
) -> List[int]:
|
203 |
+
"""
|
204 |
+
Creates a mask from the two sequences passed to be used in a sequence-pair classification task. An ALBERT
|
205 |
+
sequence pair mask has the following format:
|
206 |
+
|
207 |
+
```
|
208 |
+
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
|
209 |
+
| first sequence | second sequence |
|
210 |
+
```
|
211 |
+
|
212 |
+
if token_ids_1 is None, only returns the first portion of the mask (0s).
|
213 |
+
|
214 |
+
Args:
|
215 |
+
token_ids_0 (`List[int]`):
|
216 |
+
List of ids.
|
217 |
+
token_ids_1 (`List[int]`, *optional*):
|
218 |
+
Optional second list of IDs for sequence pairs.
|
219 |
+
|
220 |
+
Returns:
|
221 |
+
`List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s).
|
222 |
+
"""
|
223 |
+
bos_token_id = [self.bos_token_id] if self.add_bos_token else []
|
224 |
+
eos_token_id = [self.eos_token_id] if self.add_eos_token else []
|
225 |
+
|
226 |
+
output = [0] * len(bos_token_id + token_ids_0 + eos_token_id)
|
227 |
+
|
228 |
+
if token_ids_1 is not None:
|
229 |
+
output += [1] * len(bos_token_id + token_ids_1 + eos_token_id)
|
230 |
+
|
231 |
+
return output
|
232 |
+
|
tokenizer.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f7d1ab69d25c74644af5c5e4dcd1cc6e96d33783dbd257b6bdea55b643c72813
|
3 |
+
size 1136765
|
tokenizer_config.json
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": false,
|
3 |
+
"add_eos_token": false,
|
4 |
+
"auto_map": {
|
5 |
+
"AutoTokenizer": [
|
6 |
+
"tokenization_baichuan.BaichuanTokenizer",
|
7 |
+
null
|
8 |
+
]
|
9 |
+
},
|
10 |
+
"bos_token": {
|
11 |
+
"__type": "AddedToken",
|
12 |
+
"content": "<s>",
|
13 |
+
"lstrip": false,
|
14 |
+
"normalized": true,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": true
|
17 |
+
},
|
18 |
+
"clean_up_tokenization_spaces": false,
|
19 |
+
"eos_token": {
|
20 |
+
"__type": "AddedToken",
|
21 |
+
"content": "</s>",
|
22 |
+
"lstrip": false,
|
23 |
+
"normalized": true,
|
24 |
+
"rstrip": false,
|
25 |
+
"single_word": true
|
26 |
+
},
|
27 |
+
"model_max_length": 4096,
|
28 |
+
"pad_token": {
|
29 |
+
"__type": "AddedToken",
|
30 |
+
"content": "<unk>",
|
31 |
+
"lstrip": false,
|
32 |
+
"normalized": true,
|
33 |
+
"rstrip": false,
|
34 |
+
"single_word": true
|
35 |
+
},
|
36 |
+
"sp_model_kwargs": {},
|
37 |
+
"tokenizer_class": "BaichuanTokenizer",
|
38 |
+
"unk_token": {
|
39 |
+
"__type": "AddedToken",
|
40 |
+
"content": "<unk>",
|
41 |
+
"lstrip": false,
|
42 |
+
"normalized": true,
|
43 |
+
"rstrip": false,
|
44 |
+
"single_word": true
|
45 |
+
}
|
46 |
+
}
|