LandyGuo
commited on
Commit
·
7a5bca7
1
Parent(s):
4c1ec97
add model file
Browse files- config.json +44 -0
- configuration_bailing_moe.py +78 -0
- generation_config.json +6 -0
- model-00001-of-00004.safetensors +3 -0
- model-00002-of-00004.safetensors +3 -0
- model-00003-of-00004.safetensors +3 -0
- model-00004-of-00004.safetensors +3 -0
- model.safetensors.index.json +0 -0
- modeling_bailing_moe.py +1443 -0
- special_tokens_map.json +38 -0
- tokenization_bailing.py +1068 -0
- tokenizer.json +0 -0
- tokenizer_config.json +2155 -0
config.json
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"BailingMoeForCausalLM"
|
4 |
+
],
|
5 |
+
"attention_dropout": 0.0,
|
6 |
+
"auto_map": {
|
7 |
+
"AutoConfig": "configuration_bailing_moe.BailingMoeConfig",
|
8 |
+
"AutoModel": "modeling_bailing_moe.BailingMoeModel",
|
9 |
+
"AutoModelForCausalLM": "modeling_bailing_moe.BailingMoeForCausalLM"
|
10 |
+
},
|
11 |
+
"eos_token_id": 126081,
|
12 |
+
"pad_token_id": 126081,
|
13 |
+
"first_k_dense_replace": 0,
|
14 |
+
"hidden_act": "silu",
|
15 |
+
"hidden_size": 2048,
|
16 |
+
"initializer_range": 0.006,
|
17 |
+
"intermediate_size": 1408,
|
18 |
+
"max_position_embeddings": 32768,
|
19 |
+
"model_type": "bailing_moe",
|
20 |
+
"moe_intermediate_size": 1408,
|
21 |
+
"num_experts": 64,
|
22 |
+
"num_shared_experts": 2,
|
23 |
+
"norm_topk_prob": true,
|
24 |
+
"num_attention_heads": 16,
|
25 |
+
"num_experts_per_tok": 6,
|
26 |
+
"num_hidden_layers": 28,
|
27 |
+
"num_key_value_heads": 4,
|
28 |
+
"pretraining_tp": 1,
|
29 |
+
"rms_norm_eps": 1e-06,
|
30 |
+
"rope_scaling": null,
|
31 |
+
"rope_theta": 600000,
|
32 |
+
"tie_word_embeddings": false,
|
33 |
+
"torch_dtype": "bfloat16",
|
34 |
+
"transformers_version": "4.40.0",
|
35 |
+
"use_cache": true,
|
36 |
+
"use_bias": false,
|
37 |
+
"use_qkv_bias": false,
|
38 |
+
"vocab_size": 126464,
|
39 |
+
"output_router_logits": false,
|
40 |
+
"embedding_dropout": 0.0,
|
41 |
+
"norm_head": false,
|
42 |
+
"norm_softmax": false,
|
43 |
+
"output_dropout": 0.0
|
44 |
+
}
|
configuration_bailing_moe.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
""" Bailing MoE model configuration """
|
2 |
+
|
3 |
+
from transformers.configuration_utils import PretrainedConfig
|
4 |
+
|
5 |
+
|
6 |
+
class BailingMoeConfig(PretrainedConfig):
|
7 |
+
model_type = "bailing_moe"
|
8 |
+
|
9 |
+
def __init__(
|
10 |
+
self,
|
11 |
+
vocab_size=30592,
|
12 |
+
hidden_size=1024,
|
13 |
+
intermediate_size=None,
|
14 |
+
num_hidden_layers=24,
|
15 |
+
num_attention_heads=16,
|
16 |
+
num_key_value_heads=0,
|
17 |
+
hidden_act="silu",
|
18 |
+
use_qkv_bias=False, # bailing only
|
19 |
+
use_bias=True, # bailing only
|
20 |
+
rms_norm_eps=1e-05,
|
21 |
+
norm_head=False, # bailing only
|
22 |
+
tie_word_embeddings=False, # PretrainedConfig key, here change default value.
|
23 |
+
embedding_dropout=0.1,
|
24 |
+
attention_dropout=0.1,
|
25 |
+
output_dropout=0.1,
|
26 |
+
initializer_range=0.02,
|
27 |
+
max_position_embeddings=16384,
|
28 |
+
rope_theta=10000.0,
|
29 |
+
use_cache=True,
|
30 |
+
use_sliding_window=False,
|
31 |
+
sliding_window=4096,
|
32 |
+
max_window_layers=28,
|
33 |
+
rope_scaling=None,
|
34 |
+
pad_token_id=126081,
|
35 |
+
num_experts=16,
|
36 |
+
num_shared_experts=0,
|
37 |
+
num_experts_per_tok=2,
|
38 |
+
norm_topk_prob=True,
|
39 |
+
moe_intermediate_size=None,
|
40 |
+
first_k_dense_replace=0,
|
41 |
+
head_dim=None,
|
42 |
+
output_router_logits=False,
|
43 |
+
**kwargs,
|
44 |
+
):
|
45 |
+
self.num_hidden_layers = num_hidden_layers
|
46 |
+
self.vocab_size = vocab_size
|
47 |
+
self.hidden_size = hidden_size
|
48 |
+
self.intermediate_size = intermediate_size
|
49 |
+
self.num_attention_heads = num_attention_heads
|
50 |
+
self.num_key_value_heads = num_key_value_heads
|
51 |
+
self.hidden_act = hidden_act
|
52 |
+
self.use_qkv_bias = use_qkv_bias
|
53 |
+
self.use_bias = use_bias
|
54 |
+
self.norm_head = norm_head
|
55 |
+
self.rms_norm_eps = rms_norm_eps
|
56 |
+
self.embedding_dropout = embedding_dropout
|
57 |
+
self.attention_dropout = attention_dropout
|
58 |
+
self.output_dropout = output_dropout
|
59 |
+
self.initializer_range = initializer_range
|
60 |
+
self.max_position_embeddings = max_position_embeddings
|
61 |
+
self.rope_theta = rope_theta
|
62 |
+
self.use_cache = use_cache
|
63 |
+
self.use_sliding_window = use_sliding_window
|
64 |
+
self.sliding_window = sliding_window
|
65 |
+
self.max_window_layers = max_window_layers
|
66 |
+
self.head_dim = head_dim or self.hidden_size // self.num_attention_heads
|
67 |
+
self.rope_scaling = rope_scaling
|
68 |
+
|
69 |
+
# MoE configs
|
70 |
+
self.num_experts = num_experts
|
71 |
+
self.num_shared_experts = num_shared_experts
|
72 |
+
self.num_experts_per_tok = num_experts_per_tok
|
73 |
+
self.norm_topk_prob = norm_topk_prob
|
74 |
+
self.moe_intermediate_size = moe_intermediate_size
|
75 |
+
self.first_k_dense_replace = first_k_dense_replace
|
76 |
+
self.output_router_logits = output_router_logits
|
77 |
+
|
78 |
+
super().__init__(pad_token_id=pad_token_id, tie_word_embeddings=tie_word_embeddings, **kwargs)
|
generation_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"eos_token_id": 126081,
|
4 |
+
"pad_token_id": 126081,
|
5 |
+
"transformers_version": "4.40.0"
|
6 |
+
}
|
model-00001-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b83afd0fe022e3552a74da807869c865b734c88523da27a4510a32f085d9ec33
|
3 |
+
size 10000012352
|
model-00002-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d5ccecf15d89900ba376bff70aac7266a90320205b549337883e0fbd0e7386a6
|
3 |
+
size 9997403496
|
model-00003-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b72c9cb181ce3ce4ba02afa6d78b8ef82f85c8b7da85b7cd472aa58517ef937c
|
3 |
+
size 9995576736
|
model-00004-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f5b3384dc88a60dbc5a20a7fe6617163374b1adbdd5a07c6669192e185a34abc
|
3 |
+
size 3611653272
|
model.safetensors.index.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
modeling_bailing_moe.py
ADDED
@@ -0,0 +1,1443 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2023 Antgroup and The HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
5 |
+
# and OPT implementations in this library. It has been modified from its
|
6 |
+
# original forms to accommodate minor architectural differences compared
|
7 |
+
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
8 |
+
#
|
9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10 |
+
# you may not use this file except in compliance with the License.
|
11 |
+
# You may obtain a copy of the License at
|
12 |
+
#
|
13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14 |
+
#
|
15 |
+
# Unless required by applicable law or agreed to in writing, software
|
16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18 |
+
# See the License for the specific language governing permissions and
|
19 |
+
# limitations under the License.
|
20 |
+
""" PyTorch BailingMoE model."""
|
21 |
+
import math
|
22 |
+
import warnings
|
23 |
+
from typing import List, Optional, Tuple, Union
|
24 |
+
|
25 |
+
import torch
|
26 |
+
import torch.nn.functional as F
|
27 |
+
import torch.utils.checkpoint
|
28 |
+
from torch import nn
|
29 |
+
from torch.nn import CrossEntropyLoss
|
30 |
+
|
31 |
+
from transformers.activations import ACT2FN
|
32 |
+
from transformers.cache_utils import Cache, DynamicCache
|
33 |
+
from transformers.modeling_attn_mask_utils import (
|
34 |
+
AttentionMaskConverter,
|
35 |
+
_prepare_4d_attention_mask,
|
36 |
+
_prepare_4d_causal_attention_mask,
|
37 |
+
_prepare_4d_causal_attention_mask_for_sdpa,
|
38 |
+
)
|
39 |
+
from transformers.modeling_outputs import (
|
40 |
+
MoeModelOutputWithPast,
|
41 |
+
MoeCausalLMOutputWithPast,
|
42 |
+
)
|
43 |
+
from transformers.modeling_utils import PreTrainedModel
|
44 |
+
from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS, is_torch_greater_or_equal_than_1_13
|
45 |
+
from transformers.utils import (
|
46 |
+
add_start_docstrings,
|
47 |
+
add_start_docstrings_to_model_forward,
|
48 |
+
is_flash_attn_2_available,
|
49 |
+
is_flash_attn_greater_or_equal_2_10,
|
50 |
+
logging,
|
51 |
+
replace_return_docstrings,
|
52 |
+
)
|
53 |
+
from transformers.utils.import_utils import is_torch_fx_available
|
54 |
+
from .configuration_bailing_moe import BailingMoeConfig
|
55 |
+
|
56 |
+
|
57 |
+
if is_flash_attn_2_available():
|
58 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
59 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
60 |
+
|
61 |
+
|
62 |
+
# This makes `_prepare_4d_causal_attention_mask` a leaf function in the FX graph.
|
63 |
+
# It means that the function will not be traced through and simply appear as a node in the graph.
|
64 |
+
if is_torch_fx_available():
|
65 |
+
if not is_torch_greater_or_equal_than_1_13:
|
66 |
+
import torch.fx
|
67 |
+
|
68 |
+
_prepare_4d_causal_attention_mask = torch.fx.wrap(_prepare_4d_causal_attention_mask)
|
69 |
+
|
70 |
+
|
71 |
+
logger = logging.get_logger(__name__)
|
72 |
+
|
73 |
+
_CONFIG_FOR_DOC = "BailingMoeConfig"
|
74 |
+
|
75 |
+
|
76 |
+
def _get_unpad_data(attention_mask):
|
77 |
+
seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
|
78 |
+
indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
|
79 |
+
max_seqlen_in_batch = seqlens_in_batch.max().item()
|
80 |
+
cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0))
|
81 |
+
return (
|
82 |
+
indices,
|
83 |
+
cu_seqlens,
|
84 |
+
max_seqlen_in_batch,
|
85 |
+
)
|
86 |
+
|
87 |
+
|
88 |
+
def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
|
89 |
+
warnings.warn(
|
90 |
+
"Calling `transformers.models.BailingMoe.modeling_BailingMoe._prepare_4d_attention_mask` is deprecated and will be removed in v4.37. Use `transformers.modeling_attn_mask_utils._prepare_4d_attention_mask"
|
91 |
+
)
|
92 |
+
return _prepare_4d_attention_mask(mask=mask, dtype=dtype, tgt_len=tgt_len)
|
93 |
+
|
94 |
+
|
95 |
+
def _make_causal_mask(
|
96 |
+
input_ids_shape: torch.Size, dtype: torch.dtype, device: torch.device, past_key_values_length: int = 0
|
97 |
+
):
|
98 |
+
warnings.warn(
|
99 |
+
"Calling `transformers.models.BailingMoe.modeling_BailingMoe._make_causal_mask` is deprecated and will be removed in v4.37. Use `transformers.models.BailingMoe.modeling_BailingMoe.AttentionMaskConverter._make_causal_mask"
|
100 |
+
)
|
101 |
+
return AttentionMaskConverter._make_causal_mask(
|
102 |
+
input_ids_shape=input_ids_shape, dtype=dtype, device=device, past_key_values_length=past_key_values_length
|
103 |
+
)
|
104 |
+
|
105 |
+
|
106 |
+
class BailingMoeRMSNorm(nn.Module):
|
107 |
+
def __init__(self, hidden_size, eps=1e-6):
|
108 |
+
"""
|
109 |
+
BailingMoeRMSNorm is equivalent to T5LayerNorm
|
110 |
+
"""
|
111 |
+
super().__init__()
|
112 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
113 |
+
self.variance_epsilon = eps
|
114 |
+
|
115 |
+
def forward(self, hidden_states):
|
116 |
+
input_dtype = hidden_states.dtype
|
117 |
+
hidden_states = hidden_states.to(torch.float32)
|
118 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
119 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
120 |
+
return self.weight * hidden_states.to(input_dtype)
|
121 |
+
|
122 |
+
|
123 |
+
ALL_LAYERNORM_LAYERS.append(BailingMoeRMSNorm)
|
124 |
+
|
125 |
+
|
126 |
+
class BailingMoeRotaryEmbedding(nn.Module):
|
127 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
|
128 |
+
super().__init__()
|
129 |
+
|
130 |
+
self.dim = dim
|
131 |
+
self.max_position_embeddings = max_position_embeddings
|
132 |
+
self.base = base
|
133 |
+
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
|
134 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
135 |
+
|
136 |
+
# Build here to make `torch.jit.trace` work.
|
137 |
+
self._set_cos_sin_cache(
|
138 |
+
seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
|
139 |
+
)
|
140 |
+
self.max_seq_len_cached = None
|
141 |
+
|
142 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
143 |
+
self.max_seq_len_cached = seq_len
|
144 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
|
145 |
+
|
146 |
+
freqs = torch.outer(t, self.inv_freq.to(t.device))
|
147 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
148 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
149 |
+
self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
|
150 |
+
self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
|
151 |
+
|
152 |
+
def forward(self, x, seq_len=None):
|
153 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
154 |
+
if self.max_seq_len_cached is None or seq_len > self.max_seq_len_cached:
|
155 |
+
self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
|
156 |
+
|
157 |
+
return (
|
158 |
+
self.cos_cached[:seq_len].to(dtype=x.dtype),
|
159 |
+
self.sin_cached[:seq_len].to(dtype=x.dtype),
|
160 |
+
)
|
161 |
+
|
162 |
+
|
163 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaLinearScalingRotaryEmbedding with Llama->BailingMoe
|
164 |
+
class BailingMoeLinearScalingRotaryEmbedding(BailingMoeRotaryEmbedding):
|
165 |
+
"""BailingMoeRotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
|
166 |
+
|
167 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
|
168 |
+
self.scaling_factor = scaling_factor
|
169 |
+
super().__init__(dim, max_position_embeddings, base, device)
|
170 |
+
|
171 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
172 |
+
self.max_seq_len_cached = seq_len
|
173 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
|
174 |
+
t = t / self.scaling_factor
|
175 |
+
|
176 |
+
freqs = torch.outer(t, self.inv_freq)
|
177 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
178 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
179 |
+
self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
|
180 |
+
self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
|
181 |
+
|
182 |
+
|
183 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaDynamicNTKScalingRotaryEmbedding with Llama->BailingMoe
|
184 |
+
class BailingMoeDynamicNTKScalingRotaryEmbedding(BailingMoeRotaryEmbedding):
|
185 |
+
"""BailingMoeRotaryEmbedding extended with Dynamic NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla"""
|
186 |
+
|
187 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
|
188 |
+
self.scaling_factor = scaling_factor
|
189 |
+
super().__init__(dim, max_position_embeddings, base, device)
|
190 |
+
|
191 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
192 |
+
self.max_seq_len_cached = seq_len
|
193 |
+
|
194 |
+
if seq_len > self.max_position_embeddings:
|
195 |
+
base = self.base * (
|
196 |
+
(self.scaling_factor * seq_len / self.max_position_embeddings) - (self.scaling_factor - 1)
|
197 |
+
) ** (self.dim / (self.dim - 2))
|
198 |
+
inv_freq = 1.0 / (base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
|
199 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
200 |
+
|
201 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
|
202 |
+
|
203 |
+
freqs = torch.outer(t, self.inv_freq)
|
204 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
205 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
206 |
+
self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
|
207 |
+
self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
|
208 |
+
|
209 |
+
|
210 |
+
# Copied from transformers.models.llama.modeling_llama.rotate_half
|
211 |
+
def rotate_half(x):
|
212 |
+
"""Rotates half the hidden dims of the input."""
|
213 |
+
x1 = x[..., : x.shape[-1] // 2]
|
214 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
215 |
+
return torch.cat((-x2, x1), dim=-1)
|
216 |
+
|
217 |
+
|
218 |
+
# Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
|
219 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):
|
220 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
221 |
+
|
222 |
+
Args:
|
223 |
+
q (`torch.Tensor`): The query tensor.
|
224 |
+
k (`torch.Tensor`): The key tensor.
|
225 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
226 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
227 |
+
position_ids (`torch.Tensor`):
|
228 |
+
The position indices of the tokens corresponding to the query and key tensors. For example, this can be
|
229 |
+
used to pass offsetted position ids when working with a KV-cache.
|
230 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
231 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
232 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
233 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
234 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
235 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
236 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
237 |
+
Returns:
|
238 |
+
`tuple(torch.Tensor)` comprising the query and key tensors rotated using the Rotary Position Embedding.
|
239 |
+
"""
|
240 |
+
cos = cos[position_ids].unsqueeze(unsqueeze_dim)
|
241 |
+
sin = sin[position_ids].unsqueeze(unsqueeze_dim)
|
242 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
243 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
244 |
+
return q_embed, k_embed
|
245 |
+
|
246 |
+
|
247 |
+
class BailingMoeMLP(nn.Module):
|
248 |
+
def __init__(self, config: BailingMoeConfig, intermediate_size: int):
|
249 |
+
super().__init__()
|
250 |
+
self.config = config
|
251 |
+
self.hidden_size = config.hidden_size
|
252 |
+
self.intermediate_size = intermediate_size
|
253 |
+
|
254 |
+
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
255 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
256 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
|
257 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
258 |
+
|
259 |
+
def forward(self, x):
|
260 |
+
return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
261 |
+
|
262 |
+
|
263 |
+
class BailingMoeGate(nn.Module):
|
264 |
+
def __init__(self, config):
|
265 |
+
super().__init__()
|
266 |
+
self.config = config
|
267 |
+
self.top_k = config.num_experts_per_tok
|
268 |
+
self.num_experts = config.num_experts
|
269 |
+
|
270 |
+
# topk selection algorithm
|
271 |
+
self.norm_topk_prob = config.norm_topk_prob
|
272 |
+
self.gating_dim = config.hidden_size
|
273 |
+
self.weight = nn.Parameter(torch.empty((self.num_experts, self.gating_dim)))
|
274 |
+
self.reset_parameters()
|
275 |
+
|
276 |
+
def reset_parameters(self) -> None:
|
277 |
+
import torch.nn.init as init
|
278 |
+
|
279 |
+
init.kaiming_uniform_(self.weight, a=math.sqrt(5))
|
280 |
+
|
281 |
+
def forward(self, hidden_states):
|
282 |
+
bsz, seq_len, h = hidden_states.shape
|
283 |
+
# compute gating score
|
284 |
+
hidden_states = hidden_states.view(-1, h)
|
285 |
+
logits = F.linear(hidden_states, self.weight, None)
|
286 |
+
scores = logits.softmax(dim=-1, dtype=torch.float32)
|
287 |
+
|
288 |
+
# select top-k experts
|
289 |
+
topk_weight, topk_idx = torch.topk(scores, k=self.top_k, dim=-1, sorted=False)
|
290 |
+
|
291 |
+
# norm gate to sum 1
|
292 |
+
if self.top_k > 1 and self.norm_topk_prob:
|
293 |
+
denominator = topk_weight.sum(dim=-1, keepdim=True)
|
294 |
+
topk_weight = topk_weight / denominator
|
295 |
+
|
296 |
+
return topk_idx, topk_weight, logits
|
297 |
+
|
298 |
+
|
299 |
+
class BailingMoeSparseMoeBlock(nn.Module):
|
300 |
+
"""
|
301 |
+
A mixed expert module containing shared experts.
|
302 |
+
"""
|
303 |
+
|
304 |
+
def __init__(self, config: BailingMoeConfig):
|
305 |
+
super().__init__()
|
306 |
+
self.config = config
|
307 |
+
self.num_experts_per_tok = config.num_experts_per_tok
|
308 |
+
self.experts = self._setup_experts()
|
309 |
+
self.gate = BailingMoeGate(config)
|
310 |
+
if config.num_shared_experts is not None:
|
311 |
+
self.shared_experts = BailingMoeMLP(
|
312 |
+
config=config, intermediate_size=config.moe_intermediate_size * config.num_shared_experts
|
313 |
+
)
|
314 |
+
|
315 |
+
def _setup_experts(self):
|
316 |
+
return nn.ModuleList(
|
317 |
+
[
|
318 |
+
BailingMoeMLP(config=self.config, intermediate_size=self.config.moe_intermediate_size)
|
319 |
+
for _ in range(self.config.num_experts)
|
320 |
+
]
|
321 |
+
)
|
322 |
+
|
323 |
+
def forward(self, hidden_states):
|
324 |
+
identity = hidden_states
|
325 |
+
bsz, seq_len, h = hidden_states.shape
|
326 |
+
topk_idx, topk_weight, router_logits = self.gate(hidden_states)
|
327 |
+
hidden_states = hidden_states.view(-1, hidden_states.shape[-1])
|
328 |
+
flat_topk_idx = topk_idx.view(-1)
|
329 |
+
if self.training:
|
330 |
+
hidden_states = hidden_states.repeat_interleave(self.num_experts_per_tok, dim=0)
|
331 |
+
y = torch.empty_like(hidden_states)
|
332 |
+
for i, expert in enumerate(self.experts):
|
333 |
+
y[flat_topk_idx == i] = expert(hidden_states[flat_topk_idx == i])
|
334 |
+
y = (y.view(*topk_weight.shape, -1) * topk_weight.unsqueeze(-1)).sum(dim=1)
|
335 |
+
y = y.to(hidden_states.dtype).view(bsz, seq_len, h)
|
336 |
+
else:
|
337 |
+
y = self.moe_infer(hidden_states, topk_idx, topk_weight).view(bsz, seq_len, h)
|
338 |
+
if self.config.num_shared_experts is not None:
|
339 |
+
y = y + self.shared_experts(identity)
|
340 |
+
return y, (router_logits.view(bsz, seq_len, -1), topk_idx.view(bsz, seq_len, -1))
|
341 |
+
|
342 |
+
@torch.no_grad()
|
343 |
+
def moe_infer(self, x, topk_ids, topk_weight):
|
344 |
+
cnts = topk_ids.new_zeros((topk_ids.shape[0], len(self.experts)))
|
345 |
+
cnts.scatter_(1, topk_ids, 1)
|
346 |
+
tokens_per_expert = cnts.sum(dim=0)
|
347 |
+
idxs = topk_ids.view(-1).argsort()
|
348 |
+
sorted_tokens = x[idxs // topk_ids.shape[1]]
|
349 |
+
sorted_tokens_shape = sorted_tokens.shape
|
350 |
+
tokens_per_expert = tokens_per_expert.cpu().numpy()
|
351 |
+
outputs = []
|
352 |
+
start_idx = 0
|
353 |
+
for i, num_tokens in enumerate(tokens_per_expert):
|
354 |
+
end_idx = start_idx + num_tokens
|
355 |
+
if num_tokens == 0:
|
356 |
+
continue
|
357 |
+
expert = self.experts[i]
|
358 |
+
tokens_for_this_expert = sorted_tokens[start_idx:end_idx]
|
359 |
+
expert_out = expert(tokens_for_this_expert)
|
360 |
+
outputs.append(expert_out)
|
361 |
+
start_idx = end_idx
|
362 |
+
|
363 |
+
outs = torch.cat(outputs, dim=0) if len(outputs) else sorted_tokens.new_empty(0)
|
364 |
+
new_x = torch.empty_like(outs)
|
365 |
+
new_x[idxs] = outs
|
366 |
+
final_out = (
|
367 |
+
new_x.view(*topk_ids.shape, -1)
|
368 |
+
.type(topk_weight.dtype)
|
369 |
+
.mul_(topk_weight.unsqueeze(dim=-1))
|
370 |
+
.sum(dim=1)
|
371 |
+
.type(new_x.dtype)
|
372 |
+
)
|
373 |
+
return final_out
|
374 |
+
|
375 |
+
|
376 |
+
# Copied from transformers.models.llama.modeling_llama.repeat_kv
|
377 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
378 |
+
"""
|
379 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
380 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
381 |
+
"""
|
382 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
383 |
+
if n_rep == 1:
|
384 |
+
return hidden_states
|
385 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
386 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
387 |
+
|
388 |
+
|
389 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaAttention with Llama->BailingMoe
|
390 |
+
class BailingMoeAttention(nn.Module):
|
391 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
392 |
+
|
393 |
+
def __init__(self, config: BailingMoeConfig, layer_idx: Optional[int] = None):
|
394 |
+
super().__init__()
|
395 |
+
self.config = config
|
396 |
+
self.layer_idx = layer_idx
|
397 |
+
if layer_idx is None:
|
398 |
+
logger.warning_once(
|
399 |
+
f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
|
400 |
+
"to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
|
401 |
+
"when creating this class."
|
402 |
+
)
|
403 |
+
|
404 |
+
self.attention_dropout = config.attention_dropout
|
405 |
+
self.hidden_size = config.hidden_size
|
406 |
+
self.num_heads = config.num_attention_heads
|
407 |
+
self.head_dim = config.head_dim or self.hidden_size // self.num_heads
|
408 |
+
self.num_key_value_heads = config.num_key_value_heads
|
409 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
410 |
+
self.max_position_embeddings = config.max_position_embeddings
|
411 |
+
self.rope_theta = config.rope_theta
|
412 |
+
self.is_causal = True
|
413 |
+
|
414 |
+
self.query_key_value = nn.Linear(
|
415 |
+
self.hidden_size,
|
416 |
+
(self.num_heads + 2 * self.num_key_value_heads) * self.head_dim,
|
417 |
+
bias=config.use_qkv_bias,
|
418 |
+
)
|
419 |
+
self.dense = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=config.use_bias)
|
420 |
+
self._init_rope()
|
421 |
+
|
422 |
+
def _init_rope(self):
|
423 |
+
if self.config.rope_scaling is None:
|
424 |
+
self.rotary_emb = BailingMoeRotaryEmbedding(
|
425 |
+
self.head_dim,
|
426 |
+
max_position_embeddings=self.max_position_embeddings,
|
427 |
+
base=self.rope_theta,
|
428 |
+
)
|
429 |
+
else:
|
430 |
+
scaling_type = self.config.rope_scaling["type"]
|
431 |
+
scaling_factor = self.config.rope_scaling["factor"]
|
432 |
+
if scaling_type == "linear":
|
433 |
+
self.rotary_emb = BailingMoeLinearScalingRotaryEmbedding(
|
434 |
+
self.head_dim,
|
435 |
+
max_position_embeddings=self.max_position_embeddings,
|
436 |
+
scaling_factor=scaling_factor,
|
437 |
+
base=self.rope_theta,
|
438 |
+
)
|
439 |
+
elif scaling_type == "dynamic":
|
440 |
+
self.rotary_emb = BailingMoeDynamicNTKScalingRotaryEmbedding(
|
441 |
+
self.head_dim,
|
442 |
+
max_position_embeddings=self.max_position_embeddings,
|
443 |
+
scaling_factor=scaling_factor,
|
444 |
+
base=self.rope_theta,
|
445 |
+
)
|
446 |
+
else:
|
447 |
+
raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
|
448 |
+
|
449 |
+
def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
|
450 |
+
return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
|
451 |
+
|
452 |
+
def forward(
|
453 |
+
self,
|
454 |
+
hidden_states: torch.Tensor,
|
455 |
+
attention_mask: Optional[torch.Tensor] = None,
|
456 |
+
position_ids: Optional[torch.LongTensor] = None,
|
457 |
+
past_key_value: Optional[Cache] = None,
|
458 |
+
output_attentions: bool = False,
|
459 |
+
use_cache: bool = False,
|
460 |
+
**kwargs,
|
461 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
462 |
+
if "padding_mask" in kwargs:
|
463 |
+
warnings.warn(
|
464 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
465 |
+
)
|
466 |
+
|
467 |
+
bsz, q_len, _ = hidden_states.size()
|
468 |
+
|
469 |
+
qkv = self.query_key_value(hidden_states)
|
470 |
+
qkv = qkv.view(bsz, q_len, self.num_heads + 2 * self.num_key_value_heads, self.head_dim)
|
471 |
+
|
472 |
+
query_states, key_states, value_states = qkv.split(
|
473 |
+
[self.num_heads, self.num_key_value_heads, self.num_key_value_heads], dim=-2
|
474 |
+
)
|
475 |
+
query_states = query_states.transpose(1, 2)
|
476 |
+
key_states = key_states.transpose(1, 2)
|
477 |
+
value_states = value_states.transpose(1, 2)
|
478 |
+
|
479 |
+
kv_seq_len = key_states.shape[-2]
|
480 |
+
if past_key_value is not None:
|
481 |
+
if self.layer_idx is None:
|
482 |
+
raise ValueError(
|
483 |
+
f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
|
484 |
+
"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
|
485 |
+
"with a layer index."
|
486 |
+
)
|
487 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
488 |
+
cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
|
489 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
490 |
+
|
491 |
+
if past_key_value is not None:
|
492 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
493 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
494 |
+
|
495 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
496 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
497 |
+
|
498 |
+
attn_weights = torch.matmul(query_states / math.sqrt(self.head_dim), key_states.transpose(2, 3))
|
499 |
+
|
500 |
+
if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
|
501 |
+
raise ValueError(
|
502 |
+
f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
|
503 |
+
f" {attn_weights.size()}"
|
504 |
+
)
|
505 |
+
|
506 |
+
if attention_mask is not None:
|
507 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
508 |
+
raise ValueError(
|
509 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
510 |
+
)
|
511 |
+
attn_weights = attn_weights + attention_mask
|
512 |
+
|
513 |
+
# upcast attention to fp32
|
514 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
|
515 |
+
attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
|
516 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
517 |
+
|
518 |
+
if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
|
519 |
+
raise ValueError(
|
520 |
+
f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
|
521 |
+
f" {attn_output.size()}"
|
522 |
+
)
|
523 |
+
|
524 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
525 |
+
|
526 |
+
attn_output = attn_output.reshape(bsz, q_len, -1)
|
527 |
+
|
528 |
+
attn_output = self.dense(attn_output)
|
529 |
+
|
530 |
+
if not output_attentions:
|
531 |
+
attn_weights = None
|
532 |
+
|
533 |
+
return attn_output, attn_weights, past_key_value
|
534 |
+
|
535 |
+
|
536 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2 with Llama->BailingMoe
|
537 |
+
class BailingMoeFlashAttention2(BailingMoeAttention):
|
538 |
+
"""
|
539 |
+
BailingMoe flash attention module. This module inherits from `BailingMoeAttention` as the weights of the module stays
|
540 |
+
untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
|
541 |
+
flash attention and deal with padding tokens in case the input contains any of them.
|
542 |
+
"""
|
543 |
+
|
544 |
+
def __init__(self, *args, **kwargs):
|
545 |
+
super().__init__(*args, **kwargs)
|
546 |
+
|
547 |
+
# TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
|
548 |
+
# flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
|
549 |
+
# Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
|
550 |
+
self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
|
551 |
+
|
552 |
+
def forward(
|
553 |
+
self,
|
554 |
+
hidden_states: torch.Tensor,
|
555 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
556 |
+
position_ids: Optional[torch.LongTensor] = None,
|
557 |
+
past_key_value: Optional[Cache] = None,
|
558 |
+
output_attentions: bool = False,
|
559 |
+
use_cache: bool = False,
|
560 |
+
**kwargs,
|
561 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
562 |
+
# BailingMoeFlashAttention2 attention does not support output_attentions
|
563 |
+
if "padding_mask" in kwargs:
|
564 |
+
warnings.warn(
|
565 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
566 |
+
)
|
567 |
+
|
568 |
+
# overwrite attention_mask with padding_mask
|
569 |
+
attention_mask = kwargs.pop("padding_mask")
|
570 |
+
|
571 |
+
output_attentions = False
|
572 |
+
|
573 |
+
bsz, q_len, _ = hidden_states.size()
|
574 |
+
|
575 |
+
# Flash attention requires the input to have the shape
|
576 |
+
# batch_size x seq_length x head_dim x hidden_dim
|
577 |
+
# therefore we just need to keep the original shape
|
578 |
+
|
579 |
+
qkv = self.query_key_value(hidden_states)
|
580 |
+
qkv = qkv.view(bsz, q_len, self.num_heads + 2 * self.num_key_value_heads, self.head_dim)
|
581 |
+
|
582 |
+
query_states, key_states, value_states = qkv.split(
|
583 |
+
[self.num_heads, self.num_key_value_heads, self.num_key_value_heads], dim=-2
|
584 |
+
)
|
585 |
+
query_states = query_states.transpose(1, 2)
|
586 |
+
key_states = key_states.transpose(1, 2)
|
587 |
+
value_states = value_states.transpose(1, 2)
|
588 |
+
|
589 |
+
kv_seq_len = key_states.shape[-2]
|
590 |
+
if past_key_value is not None:
|
591 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
592 |
+
cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
|
593 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
594 |
+
|
595 |
+
if past_key_value is not None:
|
596 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
597 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
598 |
+
|
599 |
+
# TODO: These transpose are quite inefficient but Flash Attention requires the layout [batch_size, sequence_length, num_heads, head_dim]. We would need to refactor the KV cache
|
600 |
+
# to be able to avoid many of these transpose/reshape/view.
|
601 |
+
query_states = query_states.transpose(1, 2)
|
602 |
+
key_states = key_states.transpose(1, 2)
|
603 |
+
value_states = value_states.transpose(1, 2)
|
604 |
+
|
605 |
+
dropout_rate = self.attention_dropout if self.training else 0.0
|
606 |
+
|
607 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
608 |
+
# therefore the input hidden states gets silently cast in float32. Hence, we need
|
609 |
+
# cast them back in the correct dtype just to be sure everything works as expected.
|
610 |
+
# This might slow down training & inference so it is recommended to not cast the LayerNorms
|
611 |
+
# in fp32. (BailingMoeRMSNorm handles it correctly)
|
612 |
+
|
613 |
+
input_dtype = query_states.dtype
|
614 |
+
if input_dtype == torch.float32:
|
615 |
+
# Handle the case where the model is quantized
|
616 |
+
if hasattr(self.config, "_pre_quantization_dtype"):
|
617 |
+
target_dtype = self.config._pre_quantization_dtype
|
618 |
+
elif torch.is_autocast_enabled():
|
619 |
+
target_dtype = torch.get_autocast_gpu_dtype()
|
620 |
+
else:
|
621 |
+
target_dtype = self.q_proj.weight.dtype
|
622 |
+
|
623 |
+
logger.warning_once(
|
624 |
+
f"The input hidden states seems to be silently casted in float32, this might be related to"
|
625 |
+
f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
|
626 |
+
f" {target_dtype}."
|
627 |
+
)
|
628 |
+
|
629 |
+
query_states = query_states.to(target_dtype)
|
630 |
+
key_states = key_states.to(target_dtype)
|
631 |
+
value_states = value_states.to(target_dtype)
|
632 |
+
|
633 |
+
attn_output = self._flash_attention_forward(
|
634 |
+
query_states, key_states, value_states, attention_mask, q_len, dropout=dropout_rate
|
635 |
+
)
|
636 |
+
|
637 |
+
attn_output = attn_output.reshape(bsz, q_len, -1).contiguous()
|
638 |
+
attn_output = self.dense(attn_output)
|
639 |
+
|
640 |
+
if not output_attentions:
|
641 |
+
attn_weights = None
|
642 |
+
|
643 |
+
return attn_output, attn_weights, past_key_value
|
644 |
+
|
645 |
+
def _flash_attention_forward(
|
646 |
+
self, query_states, key_states, value_states, attention_mask, query_length, dropout=0.0, softmax_scale=None
|
647 |
+
):
|
648 |
+
"""
|
649 |
+
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
|
650 |
+
first unpad the input, then computes the attention scores and pad the final attention scores.
|
651 |
+
|
652 |
+
Args:
|
653 |
+
query_states (`torch.Tensor`):
|
654 |
+
Input query states to be passed to Flash Attention API
|
655 |
+
key_states (`torch.Tensor`):
|
656 |
+
Input key states to be passed to Flash Attention API
|
657 |
+
value_states (`torch.Tensor`):
|
658 |
+
Input value states to be passed to Flash Attention API
|
659 |
+
attention_mask (`torch.Tensor`):
|
660 |
+
The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
|
661 |
+
position of padding tokens and 1 for the position of non-padding tokens.
|
662 |
+
dropout (`int`, *optional*):
|
663 |
+
Attention dropout
|
664 |
+
softmax_scale (`float`, *optional*):
|
665 |
+
The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
|
666 |
+
query_length (`int`):
|
667 |
+
The length of the query sequence in terms of tokens. This represents the number of tokens in the
|
668 |
+
`query_states` tensor along the sequence dimension. It is used to determine the effective sequence
|
669 |
+
length for attention computations.
|
670 |
+
"""
|
671 |
+
if not self._flash_attn_uses_top_left_mask:
|
672 |
+
causal = self.is_causal
|
673 |
+
else:
|
674 |
+
# TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in BailingMoeFlashAttention2 __init__.
|
675 |
+
causal = self.is_causal and query_length != 1
|
676 |
+
|
677 |
+
# Contains at least one padding token in the sequence
|
678 |
+
if attention_mask is not None:
|
679 |
+
batch_size = query_states.shape[0]
|
680 |
+
query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
|
681 |
+
query_states, key_states, value_states, attention_mask, query_length
|
682 |
+
)
|
683 |
+
|
684 |
+
cu_seqlens_q, cu_seqlens_k = cu_seq_lens
|
685 |
+
max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
|
686 |
+
|
687 |
+
attn_output_unpad = flash_attn_varlen_func(
|
688 |
+
query_states,
|
689 |
+
key_states,
|
690 |
+
value_states,
|
691 |
+
cu_seqlens_q=cu_seqlens_q,
|
692 |
+
cu_seqlens_k=cu_seqlens_k,
|
693 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
694 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
695 |
+
dropout_p=dropout,
|
696 |
+
softmax_scale=softmax_scale,
|
697 |
+
causal=causal,
|
698 |
+
)
|
699 |
+
|
700 |
+
attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
|
701 |
+
else:
|
702 |
+
attn_output = flash_attn_func(
|
703 |
+
query_states, key_states, value_states, dropout, softmax_scale=softmax_scale, causal=causal
|
704 |
+
)
|
705 |
+
|
706 |
+
return attn_output
|
707 |
+
|
708 |
+
def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
|
709 |
+
indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
|
710 |
+
batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
|
711 |
+
|
712 |
+
key_layer = index_first_axis(
|
713 |
+
key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
|
714 |
+
)
|
715 |
+
value_layer = index_first_axis(
|
716 |
+
value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
|
717 |
+
)
|
718 |
+
if query_length == kv_seq_len:
|
719 |
+
query_layer = index_first_axis(
|
720 |
+
query_layer.reshape(batch_size * kv_seq_len, self.num_heads, head_dim), indices_k
|
721 |
+
)
|
722 |
+
cu_seqlens_q = cu_seqlens_k
|
723 |
+
max_seqlen_in_batch_q = max_seqlen_in_batch_k
|
724 |
+
indices_q = indices_k
|
725 |
+
elif query_length == 1:
|
726 |
+
max_seqlen_in_batch_q = 1
|
727 |
+
cu_seqlens_q = torch.arange(
|
728 |
+
batch_size + 1, dtype=torch.int32, device=query_layer.device
|
729 |
+
) # There is a memcpy here, that is very bad.
|
730 |
+
indices_q = cu_seqlens_q[:-1]
|
731 |
+
query_layer = query_layer.squeeze(1)
|
732 |
+
else:
|
733 |
+
# The -q_len: slice assumes left padding.
|
734 |
+
attention_mask = attention_mask[:, -query_length:]
|
735 |
+
query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
|
736 |
+
|
737 |
+
return (
|
738 |
+
query_layer,
|
739 |
+
key_layer,
|
740 |
+
value_layer,
|
741 |
+
indices_q,
|
742 |
+
(cu_seqlens_q, cu_seqlens_k),
|
743 |
+
(max_seqlen_in_batch_q, max_seqlen_in_batch_k),
|
744 |
+
)
|
745 |
+
|
746 |
+
|
747 |
+
# Copied from transformers.models.llama.modeling_llama.LlamaSdpaAttention with Llama->BailingMoe
|
748 |
+
class BailingMoeSdpaAttention(BailingMoeAttention):
|
749 |
+
"""
|
750 |
+
BailingMoe attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
|
751 |
+
`BailingMoeAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
|
752 |
+
SDPA API.
|
753 |
+
"""
|
754 |
+
|
755 |
+
# Adapted from BailingMoeAttention.forward
|
756 |
+
def forward(
|
757 |
+
self,
|
758 |
+
hidden_states: torch.Tensor,
|
759 |
+
attention_mask: Optional[torch.Tensor] = None,
|
760 |
+
position_ids: Optional[torch.LongTensor] = None,
|
761 |
+
past_key_value: Optional[Cache] = None,
|
762 |
+
output_attentions: bool = False,
|
763 |
+
use_cache: bool = False,
|
764 |
+
**kwargs,
|
765 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
766 |
+
if output_attentions:
|
767 |
+
# TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
|
768 |
+
logger.warning_once(
|
769 |
+
"BailingMoeModel is using BailingMoeSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
|
770 |
+
'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
|
771 |
+
)
|
772 |
+
return super().forward(
|
773 |
+
hidden_states=hidden_states,
|
774 |
+
attention_mask=attention_mask,
|
775 |
+
position_ids=position_ids,
|
776 |
+
past_key_value=past_key_value,
|
777 |
+
output_attentions=output_attentions,
|
778 |
+
use_cache=use_cache,
|
779 |
+
)
|
780 |
+
|
781 |
+
bsz, q_len, _ = hidden_states.size()
|
782 |
+
|
783 |
+
qkv = self.query_key_value(hidden_states)
|
784 |
+
qkv = qkv.view(bsz, q_len, self.num_heads + 2 * self.num_key_value_heads, self.head_dim)
|
785 |
+
|
786 |
+
query_states, key_states, value_states = qkv.split(
|
787 |
+
[self.num_heads, self.num_key_value_heads, self.num_key_value_heads], dim=-2
|
788 |
+
)
|
789 |
+
query_states = query_states.transpose(1, 2)
|
790 |
+
key_states = key_states.transpose(1, 2)
|
791 |
+
value_states = value_states.transpose(1, 2)
|
792 |
+
|
793 |
+
kv_seq_len = key_states.shape[-2]
|
794 |
+
if past_key_value is not None:
|
795 |
+
kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
|
796 |
+
cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
|
797 |
+
|
798 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
799 |
+
|
800 |
+
if past_key_value is not None:
|
801 |
+
cache_kwargs = {"sin": sin, "cos": cos} # Specific to RoPE models
|
802 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
803 |
+
|
804 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
805 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
806 |
+
|
807 |
+
if attention_mask is not None:
|
808 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
809 |
+
raise ValueError(
|
810 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
811 |
+
)
|
812 |
+
|
813 |
+
# SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
|
814 |
+
# Reference: https://github.com/pytorch/pytorch/issues/112577.
|
815 |
+
if query_states.device.type == "cuda" and attention_mask is not None:
|
816 |
+
query_states = query_states.contiguous()
|
817 |
+
key_states = key_states.contiguous()
|
818 |
+
value_states = value_states.contiguous()
|
819 |
+
|
820 |
+
attn_output = torch.nn.functional.scaled_dot_product_attention(
|
821 |
+
query_states,
|
822 |
+
key_states,
|
823 |
+
value_states,
|
824 |
+
attn_mask=attention_mask,
|
825 |
+
dropout_p=self.attention_dropout if self.training else 0.0,
|
826 |
+
# The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
|
827 |
+
is_causal=self.is_causal and attention_mask is None and q_len > 1,
|
828 |
+
)
|
829 |
+
|
830 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
831 |
+
attn_output = attn_output.reshape(bsz, q_len, -1)
|
832 |
+
|
833 |
+
attn_output = self.dense(attn_output)
|
834 |
+
|
835 |
+
return attn_output, None, past_key_value
|
836 |
+
|
837 |
+
|
838 |
+
BAILING_MOE_ATTENTION_CLASSES = {
|
839 |
+
"eager": BailingMoeAttention,
|
840 |
+
"flash_attention_2": BailingMoeFlashAttention2,
|
841 |
+
"sdpa": BailingMoeSdpaAttention,
|
842 |
+
}
|
843 |
+
|
844 |
+
|
845 |
+
class BailingMoeDecoderLayer(nn.Module):
|
846 |
+
def __init__(self, config: BailingMoeConfig, layer_idx: int):
|
847 |
+
super().__init__()
|
848 |
+
self.hidden_size = config.hidden_size
|
849 |
+
|
850 |
+
self.attention = BAILING_MOE_ATTENTION_CLASSES[config._attn_implementation](config=config, layer_idx=layer_idx)
|
851 |
+
|
852 |
+
self.mlp = (
|
853 |
+
BailingMoeSparseMoeBlock(config)
|
854 |
+
if (config.num_experts is not None and layer_idx >= config.first_k_dense_replace)
|
855 |
+
else BailingMoeMLP(config=config, intermediate_size=config.intermediate_size)
|
856 |
+
)
|
857 |
+
self.input_layernorm = BailingMoeRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
858 |
+
self.post_attention_layernorm = BailingMoeRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
859 |
+
|
860 |
+
def forward(
|
861 |
+
self,
|
862 |
+
hidden_states: torch.Tensor,
|
863 |
+
attention_mask: Optional[torch.Tensor] = None,
|
864 |
+
position_ids: Optional[torch.LongTensor] = None,
|
865 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
866 |
+
output_attentions: Optional[bool] = False,
|
867 |
+
output_router_logits: Optional[bool] = False,
|
868 |
+
use_cache: Optional[bool] = False,
|
869 |
+
**kwargs,
|
870 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
871 |
+
"""
|
872 |
+
Args:
|
873 |
+
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
|
874 |
+
attention_mask (`torch.FloatTensor`, *optional*):
|
875 |
+
attention mask of size `(batch_size, sequence_length)` if flash attention is used or `(batch_size, 1,
|
876 |
+
query_sequence_length, key_sequence_length)` if default attention is used.
|
877 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
878 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
879 |
+
config.n_positions - 1]`.
|
880 |
+
past_key_value (`Tuple(torch.FloatTensor)`, *optional*):
|
881 |
+
cached past key and value projection states
|
882 |
+
output_attentions (`bool`, *optional*):
|
883 |
+
Whether to return the attentions tensors of all attention layers. See `attentions` under
|
884 |
+
returned tensors for more detail.
|
885 |
+
output_router_logits (`bool`, *optional*):
|
886 |
+
Whether or not to return the logits of all the routers. They are useful for computing the router loss,
|
887 |
+
and should not be returned during inference.
|
888 |
+
use_cache (`bool`, *optional*):
|
889 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
890 |
+
(see `past_key_values`).
|
891 |
+
"""
|
892 |
+
if "padding_mask" in kwargs:
|
893 |
+
warnings.warn(
|
894 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
895 |
+
)
|
896 |
+
residual = hidden_states
|
897 |
+
|
898 |
+
hidden_states = self.input_layernorm(hidden_states)
|
899 |
+
|
900 |
+
# Self Attention
|
901 |
+
hidden_states, self_attn_weights, present_key_value = self.attention(
|
902 |
+
hidden_states=hidden_states,
|
903 |
+
attention_mask=attention_mask,
|
904 |
+
position_ids=position_ids,
|
905 |
+
past_key_value=past_key_value,
|
906 |
+
output_attentions=output_attentions,
|
907 |
+
use_cache=use_cache,
|
908 |
+
)
|
909 |
+
hidden_states = residual + hidden_states
|
910 |
+
|
911 |
+
# Fully Connected
|
912 |
+
residual = hidden_states
|
913 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
914 |
+
hidden_states = self.mlp(hidden_states)
|
915 |
+
if isinstance(hidden_states, tuple):
|
916 |
+
hidden_states, router_logits = hidden_states
|
917 |
+
else:
|
918 |
+
router_logits = None
|
919 |
+
hidden_states = residual + hidden_states
|
920 |
+
|
921 |
+
outputs = (hidden_states,)
|
922 |
+
|
923 |
+
if output_attentions:
|
924 |
+
outputs += (self_attn_weights,)
|
925 |
+
|
926 |
+
if use_cache:
|
927 |
+
outputs += (present_key_value,)
|
928 |
+
|
929 |
+
if output_router_logits:
|
930 |
+
outputs += (router_logits,)
|
931 |
+
|
932 |
+
return outputs
|
933 |
+
|
934 |
+
|
935 |
+
BAILINGMOE_START_DOCSTRING = r"""
|
936 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
937 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
938 |
+
etc.)
|
939 |
+
|
940 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
941 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
942 |
+
and behavior.
|
943 |
+
|
944 |
+
Parameters:
|
945 |
+
config ([`BailingMoeConfig`]):
|
946 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
947 |
+
load the weights associated with the model, only the configuration. Check out the
|
948 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
949 |
+
"""
|
950 |
+
|
951 |
+
|
952 |
+
@add_start_docstrings(
|
953 |
+
"The bare BailingMoe Model outputting raw hidden-states without any specific head on top.",
|
954 |
+
BAILINGMOE_START_DOCSTRING,
|
955 |
+
)
|
956 |
+
class BailingMoePreTrainedModel(PreTrainedModel):
|
957 |
+
config_class = BailingMoeConfig
|
958 |
+
base_model_prefix = "model"
|
959 |
+
supports_gradient_checkpointing = True
|
960 |
+
_no_split_modules = ["BailingMoeDecoderLayer"]
|
961 |
+
_skip_keys_device_placement = "past_key_values"
|
962 |
+
_supports_flash_attn_2 = True
|
963 |
+
_supports_sdpa = True
|
964 |
+
_supports_cache_class = True
|
965 |
+
|
966 |
+
def _init_weights(self, module):
|
967 |
+
std = self.config.initializer_range
|
968 |
+
if isinstance(module, nn.Linear):
|
969 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
970 |
+
if module.bias is not None:
|
971 |
+
module.bias.data.zero_()
|
972 |
+
elif isinstance(module, nn.Embedding):
|
973 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
974 |
+
if module.padding_idx is not None:
|
975 |
+
module.weight.data[module.padding_idx].zero_()
|
976 |
+
|
977 |
+
|
978 |
+
BAILINGMOE_INPUTS_DOCSTRING = r"""
|
979 |
+
Args:
|
980 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
981 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
982 |
+
it.
|
983 |
+
|
984 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
985 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
986 |
+
|
987 |
+
[What are input IDs?](../glossary#input-ids)
|
988 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
989 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
990 |
+
|
991 |
+
- 1 for tokens that are **not masked**,
|
992 |
+
- 0 for tokens that are **masked**.
|
993 |
+
|
994 |
+
[What are attention masks?](../glossary#attention-mask)
|
995 |
+
|
996 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
997 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
998 |
+
|
999 |
+
If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
|
1000 |
+
`past_key_values`).
|
1001 |
+
|
1002 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
1003 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
1004 |
+
information on the default strategy.
|
1005 |
+
|
1006 |
+
- 1 indicates the head is **not masked**,
|
1007 |
+
- 0 indicates the head is **masked**.
|
1008 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
1009 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
1010 |
+
config.n_positions - 1]`.
|
1011 |
+
|
1012 |
+
[What are position IDs?](../glossary#position-ids)
|
1013 |
+
past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
1014 |
+
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
1015 |
+
blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
|
1016 |
+
returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
|
1017 |
+
|
1018 |
+
Two formats are allowed:
|
1019 |
+
- a [`~cache_utils.Cache`] instance;
|
1020 |
+
- Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
1021 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
|
1022 |
+
cache format.
|
1023 |
+
|
1024 |
+
The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
|
1025 |
+
legacy cache format will be returned.
|
1026 |
+
|
1027 |
+
If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
|
1028 |
+
have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
|
1029 |
+
of shape `(batch_size, sequence_length)`.
|
1030 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
1031 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
1032 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
1033 |
+
model's internal embedding lookup matrix.
|
1034 |
+
use_cache (`bool`, *optional*):
|
1035 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
1036 |
+
`past_key_values`).
|
1037 |
+
output_attentions (`bool`, *optional*):
|
1038 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
1039 |
+
tensors for more detail.
|
1040 |
+
output_hidden_states (`bool`, *optional*):
|
1041 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
1042 |
+
more detail.
|
1043 |
+
return_dict (`bool`, *optional*):
|
1044 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
1045 |
+
"""
|
1046 |
+
|
1047 |
+
|
1048 |
+
@add_start_docstrings(
|
1049 |
+
"The bare BailingMoe Model outputting raw hidden-states without any specific head on top.",
|
1050 |
+
BAILINGMOE_START_DOCSTRING,
|
1051 |
+
)
|
1052 |
+
class BailingMoeModel(BailingMoePreTrainedModel):
|
1053 |
+
"""
|
1054 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`BailingMoeDecoderLayer`]
|
1055 |
+
|
1056 |
+
Args:
|
1057 |
+
config: BailingMoeConfig
|
1058 |
+
"""
|
1059 |
+
|
1060 |
+
def __init__(self, config: BailingMoeConfig):
|
1061 |
+
super().__init__(config)
|
1062 |
+
self.padding_idx = config.pad_token_id
|
1063 |
+
self.vocab_size = config.vocab_size
|
1064 |
+
|
1065 |
+
self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
1066 |
+
self.layers = nn.ModuleList(
|
1067 |
+
[BailingMoeDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
1068 |
+
)
|
1069 |
+
self._use_sdpa = config._attn_implementation == "sdpa"
|
1070 |
+
self._use_flash_attention_2 = config._attn_implementation == "flash_attention_2"
|
1071 |
+
self.norm = BailingMoeRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
1072 |
+
|
1073 |
+
self.gradient_checkpointing = False
|
1074 |
+
# Initialize weights and apply final processing
|
1075 |
+
self.post_init()
|
1076 |
+
|
1077 |
+
def get_input_embeddings(self):
|
1078 |
+
return self.word_embeddings
|
1079 |
+
|
1080 |
+
def set_input_embeddings(self, value):
|
1081 |
+
self.word_embeddings = value
|
1082 |
+
|
1083 |
+
@add_start_docstrings_to_model_forward(BAILINGMOE_INPUTS_DOCSTRING)
|
1084 |
+
def forward(
|
1085 |
+
self,
|
1086 |
+
input_ids: torch.LongTensor = None,
|
1087 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1088 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1089 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
1090 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1091 |
+
use_cache: Optional[bool] = None,
|
1092 |
+
output_attentions: Optional[bool] = None,
|
1093 |
+
output_hidden_states: Optional[bool] = None,
|
1094 |
+
output_router_logits: Optional[bool] = None,
|
1095 |
+
return_dict: Optional[bool] = None,
|
1096 |
+
**kwargs,
|
1097 |
+
) -> Union[Tuple, MoeModelOutputWithPast]:
|
1098 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
1099 |
+
output_hidden_states = (
|
1100 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
1101 |
+
)
|
1102 |
+
output_router_logits = (
|
1103 |
+
output_router_logits if output_router_logits is not None else self.config.output_router_logits
|
1104 |
+
)
|
1105 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
1106 |
+
|
1107 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1108 |
+
|
1109 |
+
# retrieve input_ids and inputs_embeds
|
1110 |
+
if input_ids is not None and inputs_embeds is not None:
|
1111 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
1112 |
+
elif input_ids is not None:
|
1113 |
+
batch_size, seq_length = input_ids.shape[:2]
|
1114 |
+
elif inputs_embeds is not None:
|
1115 |
+
batch_size, seq_length = inputs_embeds.shape[:2]
|
1116 |
+
else:
|
1117 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
1118 |
+
|
1119 |
+
if self.gradient_checkpointing and self.training:
|
1120 |
+
if use_cache:
|
1121 |
+
logger.warning_once(
|
1122 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`transformers."
|
1123 |
+
)
|
1124 |
+
use_cache = False
|
1125 |
+
|
1126 |
+
past_key_values_length = 0
|
1127 |
+
if use_cache:
|
1128 |
+
use_legacy_cache = not isinstance(past_key_values, Cache)
|
1129 |
+
if use_legacy_cache:
|
1130 |
+
past_key_values = DynamicCache.from_legacy_cache(past_key_values)
|
1131 |
+
past_key_values_length = past_key_values.get_usable_length(seq_length)
|
1132 |
+
|
1133 |
+
if position_ids is None:
|
1134 |
+
device = input_ids.device if input_ids is not None else inputs_embeds.device
|
1135 |
+
position_ids = torch.arange(
|
1136 |
+
past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
|
1137 |
+
)
|
1138 |
+
position_ids = position_ids.unsqueeze(0)
|
1139 |
+
|
1140 |
+
if inputs_embeds is None:
|
1141 |
+
inputs_embeds = self.word_embeddings(input_ids)
|
1142 |
+
|
1143 |
+
if self._use_flash_attention_2:
|
1144 |
+
# 2d mask is passed through the layers
|
1145 |
+
attention_mask = attention_mask if (attention_mask is not None and 0 in attention_mask) else None
|
1146 |
+
elif self._use_sdpa and not output_attentions:
|
1147 |
+
# output_attentions=True can not be supported when using SDPA, and we fall back on
|
1148 |
+
# the manual implementation that requires a 4D causal mask in all cases.
|
1149 |
+
attention_mask = _prepare_4d_causal_attention_mask_for_sdpa(
|
1150 |
+
attention_mask,
|
1151 |
+
(batch_size, seq_length),
|
1152 |
+
inputs_embeds,
|
1153 |
+
past_key_values_length,
|
1154 |
+
)
|
1155 |
+
else:
|
1156 |
+
# 4d mask is passed through the layers
|
1157 |
+
attention_mask = _prepare_4d_causal_attention_mask(
|
1158 |
+
attention_mask, (batch_size, seq_length), inputs_embeds, past_key_values_length
|
1159 |
+
)
|
1160 |
+
|
1161 |
+
# embed positions
|
1162 |
+
hidden_states = inputs_embeds
|
1163 |
+
|
1164 |
+
# decoder layers
|
1165 |
+
all_hidden_states = () if output_hidden_states else None
|
1166 |
+
all_self_attns = () if output_attentions else None
|
1167 |
+
all_router_logits = () if output_router_logits else None
|
1168 |
+
next_decoder_cache = None
|
1169 |
+
|
1170 |
+
for decoder_layer in self.layers:
|
1171 |
+
if output_hidden_states:
|
1172 |
+
all_hidden_states += (hidden_states,)
|
1173 |
+
|
1174 |
+
if self.gradient_checkpointing and self.training:
|
1175 |
+
layer_outputs = self._gradient_checkpointing_func(
|
1176 |
+
decoder_layer.__call__,
|
1177 |
+
hidden_states,
|
1178 |
+
attention_mask,
|
1179 |
+
position_ids,
|
1180 |
+
past_key_values,
|
1181 |
+
output_attentions,
|
1182 |
+
output_router_logits,
|
1183 |
+
use_cache,
|
1184 |
+
)
|
1185 |
+
else:
|
1186 |
+
layer_outputs = decoder_layer(
|
1187 |
+
hidden_states,
|
1188 |
+
attention_mask=attention_mask,
|
1189 |
+
position_ids=position_ids,
|
1190 |
+
past_key_value=past_key_values,
|
1191 |
+
output_attentions=output_attentions,
|
1192 |
+
output_router_logits=output_router_logits,
|
1193 |
+
use_cache=use_cache,
|
1194 |
+
)
|
1195 |
+
hidden_states = layer_outputs[0]
|
1196 |
+
|
1197 |
+
if use_cache:
|
1198 |
+
next_decoder_cache = layer_outputs[2 if output_attentions else 1]
|
1199 |
+
|
1200 |
+
if output_attentions:
|
1201 |
+
all_self_attns += (layer_outputs[1],)
|
1202 |
+
|
1203 |
+
if output_router_logits and layer_outputs[-1] is not None:
|
1204 |
+
all_router_logits += (layer_outputs[-1],)
|
1205 |
+
|
1206 |
+
hidden_states = self.norm(hidden_states)
|
1207 |
+
|
1208 |
+
# add hidden states from the last decoder layer
|
1209 |
+
if output_hidden_states:
|
1210 |
+
all_hidden_states += (hidden_states,)
|
1211 |
+
|
1212 |
+
next_cache = None
|
1213 |
+
if use_cache:
|
1214 |
+
next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
|
1215 |
+
if not return_dict:
|
1216 |
+
return tuple(
|
1217 |
+
v
|
1218 |
+
for v in [hidden_states, next_cache, all_hidden_states, all_self_attns, all_router_logits]
|
1219 |
+
if v is not None
|
1220 |
+
)
|
1221 |
+
return MoeModelOutputWithPast(
|
1222 |
+
last_hidden_state=hidden_states,
|
1223 |
+
past_key_values=next_cache,
|
1224 |
+
hidden_states=all_hidden_states,
|
1225 |
+
attentions=all_self_attns,
|
1226 |
+
router_logits=all_router_logits,
|
1227 |
+
)
|
1228 |
+
|
1229 |
+
|
1230 |
+
class BailingMoeForCausalLM(BailingMoePreTrainedModel):
|
1231 |
+
_tied_weights_keys = ["lm_head.weight"]
|
1232 |
+
|
1233 |
+
def __init__(self, config: BailingMoeConfig):
|
1234 |
+
super().__init__(config)
|
1235 |
+
self.model = BailingMoeModel(config)
|
1236 |
+
self.vocab_size = config.vocab_size
|
1237 |
+
self.norm_head = config.norm_head
|
1238 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
1239 |
+
|
1240 |
+
# Initialize weights and apply final processing
|
1241 |
+
self.post_init()
|
1242 |
+
|
1243 |
+
def get_input_embeddings(self):
|
1244 |
+
return self.model.word_embeddings
|
1245 |
+
|
1246 |
+
def set_input_embeddings(self, value):
|
1247 |
+
self.model.word_embeddings = value
|
1248 |
+
|
1249 |
+
def get_output_embeddings(self):
|
1250 |
+
return self.lm_head
|
1251 |
+
|
1252 |
+
def set_output_embeddings(self, new_embeddings):
|
1253 |
+
self.lm_head = new_embeddings
|
1254 |
+
|
1255 |
+
def set_decoder(self, decoder):
|
1256 |
+
self.model = decoder
|
1257 |
+
|
1258 |
+
def get_decoder(self):
|
1259 |
+
return self.model
|
1260 |
+
|
1261 |
+
@add_start_docstrings_to_model_forward(BAILINGMOE_INPUTS_DOCSTRING)
|
1262 |
+
@replace_return_docstrings(output_type=MoeCausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
1263 |
+
def forward(
|
1264 |
+
self,
|
1265 |
+
input_ids: torch.LongTensor = None,
|
1266 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1267 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1268 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
1269 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1270 |
+
labels: Optional[torch.LongTensor] = None,
|
1271 |
+
use_cache: Optional[bool] = None,
|
1272 |
+
output_attentions: Optional[bool] = None,
|
1273 |
+
output_hidden_states: Optional[bool] = None,
|
1274 |
+
output_router_logits: Optional[bool] = None,
|
1275 |
+
return_dict: Optional[bool] = None,
|
1276 |
+
**kwargs,
|
1277 |
+
) -> Union[Tuple, MoeCausalLMOutputWithPast]:
|
1278 |
+
r"""
|
1279 |
+
Args:
|
1280 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
1281 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
1282 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
1283 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
1284 |
+
|
1285 |
+
Returns:
|
1286 |
+
|
1287 |
+
Example:
|
1288 |
+
|
1289 |
+
```python
|
1290 |
+
>>> from transformers import AutoTokenizer
|
1291 |
+
|
1292 |
+
>>> model = BailingMoeForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
|
1293 |
+
>>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
|
1294 |
+
|
1295 |
+
>>> prompt = "Hey, are you conscious? Can you talk to me?"
|
1296 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
1297 |
+
|
1298 |
+
>>> # Generate
|
1299 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
1300 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
1301 |
+
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
|
1302 |
+
```"""
|
1303 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
1304 |
+
output_hidden_states = (
|
1305 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
1306 |
+
)
|
1307 |
+
output_router_logits = (
|
1308 |
+
output_router_logits if output_router_logits is not None else self.config.output_router_logits
|
1309 |
+
)
|
1310 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1311 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
1312 |
+
outputs = self.model(
|
1313 |
+
input_ids=input_ids,
|
1314 |
+
attention_mask=attention_mask,
|
1315 |
+
position_ids=position_ids,
|
1316 |
+
past_key_values=past_key_values,
|
1317 |
+
inputs_embeds=inputs_embeds,
|
1318 |
+
use_cache=use_cache,
|
1319 |
+
output_attentions=output_attentions,
|
1320 |
+
output_hidden_states=output_hidden_states,
|
1321 |
+
output_router_logits=output_router_logits,
|
1322 |
+
return_dict=return_dict,
|
1323 |
+
**kwargs,
|
1324 |
+
)
|
1325 |
+
|
1326 |
+
hidden_states = outputs[0]
|
1327 |
+
|
1328 |
+
if self.norm_head:
|
1329 |
+
if self.training:
|
1330 |
+
norm_weight = (
|
1331 |
+
self.lm_head.weight / (torch.norm(self.lm_head.weight, p=2, dim=0, keepdim=True) + 1e-7).detach()
|
1332 |
+
)
|
1333 |
+
logits = F.linear(hidden_states, norm_weight, None)
|
1334 |
+
else:
|
1335 |
+
self.lm_head.weight.data = (
|
1336 |
+
self.lm_head.weight.data.float()
|
1337 |
+
/ (torch.norm(self.lm_head.weight.data.float(), p=2, dim=0, keepdim=True) + 1e-7)
|
1338 |
+
).to(hidden_states.dtype)
|
1339 |
+
logits = F.linear(hidden_states, self.lm_head.weight.data, None)
|
1340 |
+
self.norm_head = False
|
1341 |
+
else:
|
1342 |
+
logits = self.lm_head(hidden_states)
|
1343 |
+
|
1344 |
+
logits = logits.float()
|
1345 |
+
|
1346 |
+
loss = None
|
1347 |
+
aux_loss = None
|
1348 |
+
|
1349 |
+
if labels is not None:
|
1350 |
+
# Shift so that tokens < n predict n
|
1351 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
1352 |
+
shift_labels = labels[..., 1:].contiguous()
|
1353 |
+
# Flatten the tokens
|
1354 |
+
loss_fct = CrossEntropyLoss()
|
1355 |
+
shift_logits = shift_logits.view(-1, self.config.vocab_size)
|
1356 |
+
shift_labels = shift_labels.view(-1)
|
1357 |
+
# Enable model parallelism
|
1358 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
1359 |
+
loss = loss_fct(shift_logits, shift_labels)
|
1360 |
+
|
1361 |
+
if not return_dict:
|
1362 |
+
output = (logits,) + outputs[1:]
|
1363 |
+
if output_router_logits:
|
1364 |
+
output = (aux_loss,) + output
|
1365 |
+
return (loss,) + output if loss is not None else output
|
1366 |
+
|
1367 |
+
return MoeCausalLMOutputWithPast(
|
1368 |
+
loss=loss,
|
1369 |
+
aux_loss=aux_loss,
|
1370 |
+
logits=logits,
|
1371 |
+
past_key_values=outputs.past_key_values,
|
1372 |
+
hidden_states=outputs.hidden_states,
|
1373 |
+
attentions=outputs.attentions,
|
1374 |
+
router_logits=outputs.router_logits,
|
1375 |
+
)
|
1376 |
+
|
1377 |
+
def prepare_inputs_for_generation(
|
1378 |
+
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, token_type_ids=None, **kwargs
|
1379 |
+
):
|
1380 |
+
if past_key_values is not None:
|
1381 |
+
if isinstance(past_key_values, Cache):
|
1382 |
+
cache_length = past_key_values.get_seq_length()
|
1383 |
+
past_length = past_key_values.seen_tokens
|
1384 |
+
max_cache_length = (
|
1385 |
+
past_key_values.get_max_length()
|
1386 |
+
if hasattr(past_key_values, "get_max_length")
|
1387 |
+
else past_key_values.get_max_cache_shape()
|
1388 |
+
)
|
1389 |
+
else:
|
1390 |
+
cache_length = past_length = past_key_values[0][0].shape[2]
|
1391 |
+
max_cache_length = None
|
1392 |
+
|
1393 |
+
# Keep only the unprocessed tokens:
|
1394 |
+
# 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
|
1395 |
+
# some of the inputs are exclusivelly passed as part of the cache (e.g. when passing input_embeds as input)
|
1396 |
+
if attention_mask is not None and attention_mask.shape[1] > input_ids.shape[1]:
|
1397 |
+
input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
|
1398 |
+
# 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
|
1399 |
+
# input_ids based on the past_length.
|
1400 |
+
elif past_length < input_ids.shape[1]:
|
1401 |
+
input_ids = input_ids[:, past_length:]
|
1402 |
+
# 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
|
1403 |
+
|
1404 |
+
# If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
|
1405 |
+
if (
|
1406 |
+
max_cache_length is not None
|
1407 |
+
and attention_mask is not None
|
1408 |
+
and cache_length + input_ids.shape[1] > max_cache_length
|
1409 |
+
):
|
1410 |
+
attention_mask = attention_mask[:, -max_cache_length:]
|
1411 |
+
|
1412 |
+
position_ids = kwargs.get("position_ids", None)
|
1413 |
+
if attention_mask is not None and position_ids is None:
|
1414 |
+
# create position_ids on the fly for batch generation
|
1415 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
1416 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
1417 |
+
if past_key_values:
|
1418 |
+
position_ids = position_ids[:, -input_ids.shape[1] :]
|
1419 |
+
|
1420 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
1421 |
+
if inputs_embeds is not None and past_key_values is None:
|
1422 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
1423 |
+
else:
|
1424 |
+
model_inputs = {"input_ids": input_ids}
|
1425 |
+
|
1426 |
+
model_inputs.update(
|
1427 |
+
{
|
1428 |
+
"position_ids": position_ids,
|
1429 |
+
"past_key_values": past_key_values,
|
1430 |
+
"use_cache": kwargs.get("use_cache"),
|
1431 |
+
"attention_mask": attention_mask,
|
1432 |
+
}
|
1433 |
+
)
|
1434 |
+
return model_inputs
|
1435 |
+
|
1436 |
+
@staticmethod
|
1437 |
+
def _reorder_cache(past_key_values, beam_idx):
|
1438 |
+
reordered_past = ()
|
1439 |
+
for layer_past in past_key_values:
|
1440 |
+
reordered_past += (
|
1441 |
+
tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
|
1442 |
+
)
|
1443 |
+
return reordered_past
|
special_tokens_map.json
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<role>",
|
4 |
+
"</role>",
|
5 |
+
"<|arithmetic_start|>",
|
6 |
+
"<|arithmetic_end|>",
|
7 |
+
"<|number_start|>",
|
8 |
+
"<|number_end|>"
|
9 |
+
],
|
10 |
+
"bos_token": {
|
11 |
+
"content": "<|startoftext|>",
|
12 |
+
"lstrip": false,
|
13 |
+
"normalized": false,
|
14 |
+
"rstrip": false,
|
15 |
+
"single_word": false
|
16 |
+
},
|
17 |
+
"cls_token": {
|
18 |
+
"content": "[CLS]",
|
19 |
+
"lstrip": false,
|
20 |
+
"normalized": false,
|
21 |
+
"rstrip": false,
|
22 |
+
"single_word": false
|
23 |
+
},
|
24 |
+
"eos_token": {
|
25 |
+
"content": "<|endoftext|>",
|
26 |
+
"lstrip": false,
|
27 |
+
"normalized": false,
|
28 |
+
"rstrip": false,
|
29 |
+
"single_word": false
|
30 |
+
},
|
31 |
+
"pad_token": {
|
32 |
+
"content": "<|endoftext|>",
|
33 |
+
"lstrip": false,
|
34 |
+
"normalized": false,
|
35 |
+
"rstrip": false,
|
36 |
+
"single_word": false
|
37 |
+
}
|
38 |
+
}
|
tokenization_bailing.py
ADDED
@@ -0,0 +1,1068 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# coding=utf-8
|
3 |
+
# Copyright (c) Ant Group. All rights reserved.
|
4 |
+
|
5 |
+
import itertools
|
6 |
+
from typing import Any, Dict, List, Optional, Union
|
7 |
+
|
8 |
+
import torch
|
9 |
+
from transformers import PreTrainedTokenizerFast
|
10 |
+
from transformers.tokenization_utils_base import AddedToken, BatchEncoding
|
11 |
+
from transformers.utils import TensorType, logging
|
12 |
+
|
13 |
+
logger = logging.get_logger(__name__)
|
14 |
+
|
15 |
+
|
16 |
+
def is_system(msg):
|
17 |
+
return msg['role'].lower() == 'system'
|
18 |
+
|
19 |
+
|
20 |
+
def is_user(msg):
|
21 |
+
return msg['role'].lower() in ['human', 'user']
|
22 |
+
|
23 |
+
|
24 |
+
def is_assistant(msg):
|
25 |
+
return msg['role'].lower() == 'assistant'
|
26 |
+
|
27 |
+
|
28 |
+
def _convert_to_conversation(query, system=None):
|
29 |
+
conversation = []
|
30 |
+
if system:
|
31 |
+
conversation.append({"role": "SYSTEM", "content": system})
|
32 |
+
if isinstance(query, str):
|
33 |
+
conversation.append({"role": "HUMAN", "content": query})
|
34 |
+
elif isinstance(query, List):
|
35 |
+
conversation.extend(query)
|
36 |
+
elif isinstance(query, Dict):
|
37 |
+
if "messages" in query:
|
38 |
+
conversation.extend(query["messages"])
|
39 |
+
if "system_message" in query and len(conversation) > 0 and not is_system(conversation[0]):
|
40 |
+
conversation.insert(0, {"role": "SYSTEM", "content": query["system_message"]})
|
41 |
+
else:
|
42 |
+
conversation.append(query)
|
43 |
+
return conversation
|
44 |
+
|
45 |
+
|
46 |
+
class BailingTokenizer(PreTrainedTokenizerFast):
|
47 |
+
is_bailing_tokenizer = True
|
48 |
+
model_input_names = ["input_ids", "attention_mask"]
|
49 |
+
slow_tokenizer_class = None
|
50 |
+
|
51 |
+
# add gmask_token
|
52 |
+
SPECIAL_TOKENS_ATTRIBUTES = [
|
53 |
+
"bos_token",
|
54 |
+
"eos_token",
|
55 |
+
"unk_token",
|
56 |
+
"sep_token",
|
57 |
+
"pad_token",
|
58 |
+
"cls_token",
|
59 |
+
"mask_token",
|
60 |
+
"gmask_token",
|
61 |
+
"additional_special_tokens",
|
62 |
+
]
|
63 |
+
|
64 |
+
def __init__(
|
65 |
+
self,
|
66 |
+
vocab_file=None,
|
67 |
+
merges_file=None,
|
68 |
+
tokenizer_file=None,
|
69 |
+
clean_up_tokenization_spaces=False,
|
70 |
+
bos_token="<|startoftext|>",
|
71 |
+
eos_token="<|endoftext|>",
|
72 |
+
cls_token="[CLS]",
|
73 |
+
pad_token="<|endoftext|>",
|
74 |
+
gmask_token="[gMASK]",
|
75 |
+
add_bos_token=False,
|
76 |
+
add_eos_token=False,
|
77 |
+
**kwargs,
|
78 |
+
):
|
79 |
+
self.add_bos_token = add_bos_token
|
80 |
+
|
81 |
+
self._gmask_token = (
|
82 |
+
AddedToken(gmask_token, lstrip=False, rstrip=False, normalized=False)
|
83 |
+
if isinstance(gmask_token, str)
|
84 |
+
else gmask_token
|
85 |
+
)
|
86 |
+
|
87 |
+
self._sop_token = (
|
88 |
+
AddedToken(bos_token, lstrip=False, rstrip=False, normalized=False)
|
89 |
+
if isinstance(bos_token, str)
|
90 |
+
else bos_token
|
91 |
+
)
|
92 |
+
|
93 |
+
self._eop_token = (
|
94 |
+
AddedToken(eos_token, lstrip=False, rstrip=False, normalized=False)
|
95 |
+
if isinstance(eos_token, str)
|
96 |
+
else eos_token
|
97 |
+
)
|
98 |
+
|
99 |
+
super().__init__(
|
100 |
+
vocab_file=vocab_file,
|
101 |
+
merges_file=merges_file,
|
102 |
+
tokenizer_file=tokenizer_file,
|
103 |
+
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
|
104 |
+
bos_token=bos_token,
|
105 |
+
eos_token=eos_token,
|
106 |
+
cls_token=cls_token,
|
107 |
+
pad_token=pad_token,
|
108 |
+
gmask_token=gmask_token,
|
109 |
+
add_bos_token=add_bos_token,
|
110 |
+
add_eos_token=add_eos_token,
|
111 |
+
**kwargs,
|
112 |
+
)
|
113 |
+
|
114 |
+
self.check_special_tokens()
|
115 |
+
|
116 |
+
def check_special_tokens(self):
|
117 |
+
'''
|
118 |
+
eos_token, cls_token, mask_token
|
119 |
+
special tokens should init, check special token is not None
|
120 |
+
'''
|
121 |
+
for name, special_token in zip(
|
122 |
+
['eos', 'bos', 'cls', 'gmask'],
|
123 |
+
[self.eos_token, self.bos_token, self.cls_token, self.gmask_token],
|
124 |
+
):
|
125 |
+
assert special_token is not None, f'should init special token [{name}] in tokenizer_config.json'
|
126 |
+
|
127 |
+
@property
|
128 |
+
def gmask_token(self) -> Optional[str]:
|
129 |
+
if self._gmask_token is None:
|
130 |
+
if self.verbose:
|
131 |
+
logger.error("Using gmask_token, but it is not set yet.")
|
132 |
+
return None
|
133 |
+
return str(self._gmask_token)
|
134 |
+
|
135 |
+
@gmask_token.setter
|
136 |
+
def gmask_token(self, value):
|
137 |
+
if not isinstance(value, (str, AddedToken)) and value is not None:
|
138 |
+
raise ValueError("Cannot set a non-string value as the gmask token")
|
139 |
+
self._gmask_token = value
|
140 |
+
|
141 |
+
@property
|
142 |
+
def gmask_token_id(self) -> Optional[int]:
|
143 |
+
if self._gmask_token is None:
|
144 |
+
return None
|
145 |
+
return self.convert_tokens_to_ids(self.gmask_token)
|
146 |
+
|
147 |
+
@property
|
148 |
+
def sop_token(self) -> Optional[str]:
|
149 |
+
if self._sop_token is None:
|
150 |
+
if self.verbose:
|
151 |
+
logger.error("Using sop_token, but it is not set yet.")
|
152 |
+
return None
|
153 |
+
return str(self._sop_token)
|
154 |
+
|
155 |
+
@sop_token.setter
|
156 |
+
def sop_token(self, value):
|
157 |
+
if not isinstance(value, (str, AddedToken)) and value is not None:
|
158 |
+
raise ValueError("Cannot set a non-string value as the sop token")
|
159 |
+
self._sop_token = value
|
160 |
+
|
161 |
+
@property
|
162 |
+
def sop_token_id(self) -> Optional[int]:
|
163 |
+
if self._sop_token is None:
|
164 |
+
return None
|
165 |
+
return self.convert_tokens_to_ids(self.sop_token)
|
166 |
+
|
167 |
+
@property
|
168 |
+
def eop_token(self) -> Optional[str]:
|
169 |
+
if self._eop_token is None:
|
170 |
+
if self.verbose:
|
171 |
+
logger.error("Using eop_token, but it is not set yet.")
|
172 |
+
return None
|
173 |
+
return str(self._eop_token)
|
174 |
+
|
175 |
+
@eop_token.setter
|
176 |
+
def eop_token(self, value):
|
177 |
+
if not isinstance(value, (str, AddedToken)) and value is not None:
|
178 |
+
raise ValueError("Cannot set a non-string value as the eop token")
|
179 |
+
self._eop_token = value
|
180 |
+
|
181 |
+
@property
|
182 |
+
def eop_token_id(self) -> Optional[int]:
|
183 |
+
if self._eop_token is None:
|
184 |
+
return None
|
185 |
+
return self.convert_tokens_to_ids(self.eop_token)
|
186 |
+
|
187 |
+
@property
|
188 |
+
def vocab_size(self):
|
189 |
+
return len(self.get_vocab())
|
190 |
+
|
191 |
+
def _chat_from_json(self, chat, chat_format="antglm_chat", system=None):
|
192 |
+
msgs = chat if "messages" not in chat else chat["messages"]
|
193 |
+
_msgs = []
|
194 |
+
sys_msg = None
|
195 |
+
for msg in msgs:
|
196 |
+
if is_system(msg):
|
197 |
+
sys_msg = msg['content']
|
198 |
+
else:
|
199 |
+
_msgs.append(msg)
|
200 |
+
chat = {"messages": _msgs}
|
201 |
+
system = system or sys_msg
|
202 |
+
if system:
|
203 |
+
chat['system_message'] = system
|
204 |
+
from .chat_format import Chat
|
205 |
+
|
206 |
+
return Chat.from_json(chat, name=chat_format)
|
207 |
+
|
208 |
+
def apply_chat_template(
|
209 |
+
self,
|
210 |
+
conversation: Union[List[Dict[str, str]], List[List[Dict[str, str]]]],
|
211 |
+
tools: Optional[List[Dict]] = None,
|
212 |
+
documents: Optional[List[Dict[str, str]]] = None,
|
213 |
+
chat_template: Optional[str] = None,
|
214 |
+
add_generation_prompt: bool = False,
|
215 |
+
system: str = None, # only used for legacy chatml
|
216 |
+
tokenize=False,
|
217 |
+
padding: bool = False,
|
218 |
+
truncation: bool = False,
|
219 |
+
max_length: Optional[int] = None,
|
220 |
+
return_tensors: Optional[Union[str, TensorType]] = None,
|
221 |
+
return_dict: bool = False,
|
222 |
+
return_assistant_tokens_mask: bool = False,
|
223 |
+
tokenizer_kwargs: Optional[Dict[str, Any]] = None,
|
224 |
+
**kwargs,
|
225 |
+
):
|
226 |
+
if hasattr(self, "chat_template") and self.chat_template:
|
227 |
+
if isinstance(conversation, Dict) and "messages" in conversation:
|
228 |
+
conversation = conversation["messages"]
|
229 |
+
# use transformers built-in method
|
230 |
+
return super().apply_chat_template(
|
231 |
+
conversation=conversation,
|
232 |
+
tools=tools,
|
233 |
+
documents=documents,
|
234 |
+
chat_template=chat_template,
|
235 |
+
add_generation_prompt=add_generation_prompt,
|
236 |
+
tokenize=tokenize,
|
237 |
+
padding=padding,
|
238 |
+
truncation=truncation,
|
239 |
+
return_tensors=return_tensors,
|
240 |
+
return_dict=return_dict,
|
241 |
+
return_assistant_tokens_mask=return_assistant_tokens_mask,
|
242 |
+
tokenizer_kwargs=tokenizer_kwargs,
|
243 |
+
)
|
244 |
+
|
245 |
+
# 非chat_template方式后续将不再支持。
|
246 |
+
logger.warning("Please set chat_template in tokenizer_config.json!")
|
247 |
+
|
248 |
+
chat_format = kwargs.get('chat_format', 'antglm_chat')
|
249 |
+
|
250 |
+
is_batched = False
|
251 |
+
|
252 |
+
if isinstance(conversation, List) and (
|
253 |
+
isinstance(conversation[0], (list, tuple)) or "messages" in conversation[0]
|
254 |
+
):
|
255 |
+
conversations = conversation
|
256 |
+
is_batched = True
|
257 |
+
|
258 |
+
if not is_batched:
|
259 |
+
conversations = [conversation]
|
260 |
+
|
261 |
+
rendered = []
|
262 |
+
for chat in conversations:
|
263 |
+
rendered_chat = self._chat_from_json(chat, chat_format=chat_format, system=system).prompt_str
|
264 |
+
rendered.append(rendered_chat)
|
265 |
+
|
266 |
+
if not is_batched:
|
267 |
+
rendered = rendered[0]
|
268 |
+
|
269 |
+
if tokenize:
|
270 |
+
out = self(
|
271 |
+
rendered,
|
272 |
+
padding=padding,
|
273 |
+
truncation=truncation,
|
274 |
+
max_length=max_length,
|
275 |
+
add_special_tokens=False,
|
276 |
+
return_tensors=return_tensors,
|
277 |
+
)
|
278 |
+
if return_dict:
|
279 |
+
return out
|
280 |
+
else:
|
281 |
+
return out["input_ids"]
|
282 |
+
else:
|
283 |
+
return rendered
|
284 |
+
|
285 |
+
def _build_position_ids(
|
286 |
+
self,
|
287 |
+
mask_pos: int,
|
288 |
+
bos_pos: int,
|
289 |
+
max_output_length: int,
|
290 |
+
rotary_type: Optional[str] = "none",
|
291 |
+
**kwargs,
|
292 |
+
) -> List[List[int]]:
|
293 |
+
window_size = kwargs.get("window_size", 1024) - 1
|
294 |
+
block_position_ids = [0] * bos_pos
|
295 |
+
|
296 |
+
# 获得mask所在的位置,用于后面output positionid的构造
|
297 |
+
if "1d" in rotary_type:
|
298 |
+
position_ids = list(range(bos_pos)) + list(range(mask_pos + 1, mask_pos + max_output_length + 2))
|
299 |
+
block_position_ids = block_position_ids + list(range(1, max_output_length + 2))
|
300 |
+
elif "2d" in rotary_type:
|
301 |
+
# 后面input_ids要加一个bos_id
|
302 |
+
position_ids = list(range(bos_pos))
|
303 |
+
position_ids = position_ids + [mask_pos] * (1 + max_output_length)
|
304 |
+
block_position_ids = block_position_ids + list(range(1, max_output_length + 2))
|
305 |
+
else:
|
306 |
+
# build position ids
|
307 |
+
position_ids = []
|
308 |
+
repeat_times = bos_pos // window_size
|
309 |
+
for _ in range(repeat_times):
|
310 |
+
position_ids += list(range(window_size))
|
311 |
+
position_ids += list(range(bos_pos - window_size * repeat_times))
|
312 |
+
# need consider additional bos_id after input_ids
|
313 |
+
mask_pos = position_ids[-1]
|
314 |
+
position_ids += [mask_pos] * (max_output_length + 1)
|
315 |
+
|
316 |
+
block_repeat_times = max_output_length // (window_size - 1)
|
317 |
+
additional_block_position_ids = []
|
318 |
+
for _ in range(block_repeat_times):
|
319 |
+
additional_block_position_ids += list(range(1, window_size))
|
320 |
+
additional_block_position_ids += list(
|
321 |
+
range(1, max_output_length + 2 - (window_size - 1) * block_repeat_times)
|
322 |
+
)
|
323 |
+
block_position_ids = block_position_ids + additional_block_position_ids
|
324 |
+
|
325 |
+
position_ids = [position_ids, block_position_ids]
|
326 |
+
return position_ids
|
327 |
+
|
328 |
+
def _build_inputs_for_generation(
|
329 |
+
self,
|
330 |
+
input_ids: List[int],
|
331 |
+
max_input_length=None,
|
332 |
+
left_truncate=True,
|
333 |
+
max_output_length=1024,
|
334 |
+
rotary_type="none",
|
335 |
+
unidirectional_attention: bool = True,
|
336 |
+
attention_dtype=None,
|
337 |
+
**kwargs,
|
338 |
+
):
|
339 |
+
if max_input_length and len(input_ids) > max_input_length:
|
340 |
+
if left_truncate:
|
341 |
+
input_ids = input_ids[-max_input_length:]
|
342 |
+
else:
|
343 |
+
input_ids = input_ids[:max_input_length]
|
344 |
+
|
345 |
+
is_left_padding = input_ids[0] == self.eos_token_id
|
346 |
+
if not unidirectional_attention:
|
347 |
+
if input_ids[0] != self.cls_token_id:
|
348 |
+
input_ids = [self.cls_token_id] + input_ids
|
349 |
+
|
350 |
+
if self.gmask_token_id not in set(input_ids):
|
351 |
+
input_ids = input_ids + [self.gmask_token_id]
|
352 |
+
|
353 |
+
mask_pos = input_ids.index(self.gmask_token_id)
|
354 |
+
sep = len(input_ids)
|
355 |
+
else:
|
356 |
+
if self.add_bos_token:
|
357 |
+
input_ids = input_ids + [self.bos_token_id]
|
358 |
+
if self.eos_token_id in input_ids:
|
359 |
+
mask_pos = input_ids.index(self.eos_token_id) - 1
|
360 |
+
else:
|
361 |
+
mask_pos = len(input_ids) - 1
|
362 |
+
sep = len(input_ids) - 1
|
363 |
+
else:
|
364 |
+
sep = len(input_ids)
|
365 |
+
if self.eos_token_id in input_ids:
|
366 |
+
if is_left_padding:
|
367 |
+
ori_input_ids = input_ids
|
368 |
+
input_ids = input_ids[::-1]
|
369 |
+
mask_pos = input_ids.index(self.eos_token_id) - 1
|
370 |
+
mask_pos = max(0, mask_pos) # for empty sequence
|
371 |
+
if is_left_padding:
|
372 |
+
input_ids = ori_input_ids
|
373 |
+
mask_pos = sep - 1 - mask_pos # the first non-eos token
|
374 |
+
|
375 |
+
else:
|
376 |
+
mask_pos = len(input_ids) - 1
|
377 |
+
|
378 |
+
position_ids = self._build_position_ids(mask_pos, sep, max_output_length, rotary_type, **kwargs)
|
379 |
+
|
380 |
+
if is_left_padding:
|
381 |
+
position_ids[0] = [max(0, i - mask_pos) for i in range(len(position_ids[0]))]
|
382 |
+
|
383 |
+
# 后面input_ids要加一个bos_id
|
384 |
+
total_length = sep + max_output_length
|
385 |
+
if self.add_bos_token:
|
386 |
+
total_length += 1
|
387 |
+
|
388 |
+
def build_mask_matrix(seq_length, sep, mask_pos, unidirectional_attention):
|
389 |
+
# 长序列使用bool类型节省显存
|
390 |
+
if unidirectional_attention:
|
391 |
+
attention_mask = torch.ones([seq_length, seq_length], dtype=attention_dtype)
|
392 |
+
attention_mask = torch.tril(attention_mask)
|
393 |
+
if is_left_padding:
|
394 |
+
attention_mask[:, :mask_pos] = 0
|
395 |
+
else:
|
396 |
+
attention_mask[:, mask_pos + 1 : sep] = 0
|
397 |
+
else:
|
398 |
+
attention_mask = torch.zeros([seq_length, seq_length], dtype=attention_dtype)
|
399 |
+
attention_mask[:, : mask_pos + 1] = 1
|
400 |
+
for i in range(sep, total_length):
|
401 |
+
attention_mask[i, sep : i + 1] = 1
|
402 |
+
return attention_mask
|
403 |
+
|
404 |
+
if self.add_bos_token:
|
405 |
+
attention_mask = build_mask_matrix(total_length, sep + 1, mask_pos, unidirectional_attention)
|
406 |
+
else:
|
407 |
+
attention_mask = build_mask_matrix(total_length, sep, mask_pos, unidirectional_attention)
|
408 |
+
attention_mask = torch.unsqueeze(attention_mask, dim=0)
|
409 |
+
attention_mask = torch.unsqueeze(attention_mask, dim=1)
|
410 |
+
if attention_dtype is None:
|
411 |
+
attention_mask = attention_mask.long()
|
412 |
+
inputs = {
|
413 |
+
"input_ids": torch.Tensor([input_ids]).long(),
|
414 |
+
"position_ids": torch.Tensor([position_ids]).long(),
|
415 |
+
"attention_mask": attention_mask,
|
416 |
+
}
|
417 |
+
return BatchEncoding(inputs)
|
418 |
+
|
419 |
+
def build_inputs_for_generation(
|
420 |
+
self,
|
421 |
+
input_ids: Union[List[int], List[List[int]], torch.Tensor],
|
422 |
+
max_input_length=None,
|
423 |
+
left_truncate=True,
|
424 |
+
max_output_length=1024,
|
425 |
+
rotary_type="1d",
|
426 |
+
unidirectional_attention=True,
|
427 |
+
attention_dtype=None,
|
428 |
+
**kwargs,
|
429 |
+
):
|
430 |
+
if isinstance(input_ids, torch.Tensor):
|
431 |
+
input_ids = input_ids.tolist()
|
432 |
+
|
433 |
+
if isinstance(input_ids[0], list):
|
434 |
+
input_ids_list = []
|
435 |
+
position_ids_list = []
|
436 |
+
attention_mask_list = []
|
437 |
+
for _input_ids in input_ids:
|
438 |
+
inputs = self._build_inputs_for_generation(
|
439 |
+
_input_ids,
|
440 |
+
max_input_length=max_input_length,
|
441 |
+
left_truncate=left_truncate,
|
442 |
+
max_output_length=max_output_length,
|
443 |
+
rotary_type=rotary_type,
|
444 |
+
unidirectional_attention=unidirectional_attention,
|
445 |
+
attention_dtype=attention_dtype,
|
446 |
+
**kwargs,
|
447 |
+
)
|
448 |
+
input_ids_list.append(inputs['input_ids'])
|
449 |
+
position_ids_list.append(inputs['position_ids'])
|
450 |
+
attention_mask_list.append(inputs["attention_mask"])
|
451 |
+
|
452 |
+
max_ids_length = max([input.size(1) for input in input_ids_list])
|
453 |
+
|
454 |
+
for i in range(len(input_ids)):
|
455 |
+
cur_ids_length = input_ids_list[i].size(1)
|
456 |
+
if cur_ids_length < max_ids_length:
|
457 |
+
# pad input ids
|
458 |
+
pad_input_ids = input_ids_list[i].new_zeros((1, max_ids_length - cur_ids_length))
|
459 |
+
input_ids_list[i] = torch.cat([pad_input_ids, input_ids_list[i]], dim=-1)
|
460 |
+
|
461 |
+
# pad postition ids with left pad
|
462 |
+
# 0, 1, 2, 3, 4 ... -> 0, ..., 0, 1, 2, 3, 4, ...
|
463 |
+
pad_position_ids = input_ids_list[i].new_zeros((1, 2, max_ids_length - cur_ids_length))
|
464 |
+
position_ids_list[i] = torch.cat([pad_position_ids, position_ids_list[i]], dim=-1)
|
465 |
+
|
466 |
+
# pad generation attention mask with left and bottom pad
|
467 |
+
new_attention_mask = input_ids_list[i].new_zeros(
|
468 |
+
1,
|
469 |
+
1,
|
470 |
+
max_ids_length + max_output_length,
|
471 |
+
max_ids_length + max_output_length,
|
472 |
+
)
|
473 |
+
new_attention_mask[
|
474 |
+
:,
|
475 |
+
:,
|
476 |
+
max_ids_length - cur_ids_length :,
|
477 |
+
max_ids_length - cur_ids_length :,
|
478 |
+
] = attention_mask_list[i]
|
479 |
+
attention_mask_list[i] = new_attention_mask.contiguous()
|
480 |
+
|
481 |
+
input_ids_list = torch.cat(input_ids_list, dim=0)
|
482 |
+
position_ids_list = torch.cat(position_ids_list, dim=0)
|
483 |
+
attention_mask_list = torch.cat(attention_mask_list, dim=0)
|
484 |
+
|
485 |
+
inputs = {
|
486 |
+
"input_ids": input_ids_list,
|
487 |
+
"position_ids": position_ids_list,
|
488 |
+
"attention_mask": attention_mask_list,
|
489 |
+
}
|
490 |
+
|
491 |
+
return BatchEncoding(inputs)
|
492 |
+
else:
|
493 |
+
return self._build_inputs_for_generation(
|
494 |
+
input_ids,
|
495 |
+
max_input_length=max_input_length,
|
496 |
+
left_truncate=left_truncate,
|
497 |
+
max_output_length=max_output_length,
|
498 |
+
rotary_type=rotary_type,
|
499 |
+
unidirectional_attention=unidirectional_attention,
|
500 |
+
**kwargs,
|
501 |
+
)
|
502 |
+
|
503 |
+
def _build_inputs_for_train(
|
504 |
+
self,
|
505 |
+
inputs: Union[str, List[str]],
|
506 |
+
outputs: Union[str, List[str]],
|
507 |
+
new_conversation_offset: List[int] = None,
|
508 |
+
max_length: int = 2048,
|
509 |
+
rotary_type: str = "1d",
|
510 |
+
left_truncate: bool = True,
|
511 |
+
unidirectional_attention: bool = True,
|
512 |
+
isolation_position_ids: bool = False,
|
513 |
+
padding: bool = True,
|
514 |
+
use_fa2: bool = True,
|
515 |
+
use_packed: bool = True,
|
516 |
+
use_baichuan_packed: bool = False,
|
517 |
+
skip_truncated_turn: bool = False,
|
518 |
+
return_attention_mask: bool = True,
|
519 |
+
):
|
520 |
+
r"""
|
521 |
+
Build tensor input for model training. If inputs and outputs are list, will pack them.
|
522 |
+
|
523 |
+
Args:
|
524 |
+
inputs (str, List[str], List[Dict], List[List[Dict]]): the input prompts.
|
525 |
+
outputs (str, List[str]): the output responses.
|
526 |
+
max_length (int, Optional): the maximum length of the final input ids for training. Default: 2048
|
527 |
+
rotary_type (str, Optional): the rotary type of position embedding. Default: 1d
|
528 |
+
left_truncate (bool, Optional): whether truncate the inputs from left. Default: True
|
529 |
+
use_fa2 (bool, Optional): whether to build attention mask under flash attention 2.
|
530 |
+
new_conversation_offset (List[int], Optional): 第idx条样本是全新的对话,[0, 1]代表:inputs[0]和outputs[0]是一个对话,inputs[1]和outputs[1]是一个对话.
|
531 |
+
"""
|
532 |
+
if use_packed and use_baichuan_packed and unidirectional_attention:
|
533 |
+
return self._build_baichuan_inputs_for_train(
|
534 |
+
inputs,
|
535 |
+
outputs,
|
536 |
+
new_conversation_offset,
|
537 |
+
max_length,
|
538 |
+
rotary_type,
|
539 |
+
left_truncate,
|
540 |
+
skip_truncated_turn,
|
541 |
+
use_fa2,
|
542 |
+
padding,
|
543 |
+
)
|
544 |
+
if isinstance(inputs, str):
|
545 |
+
inputs = [inputs]
|
546 |
+
if isinstance(outputs, str):
|
547 |
+
outputs = [outputs]
|
548 |
+
|
549 |
+
assert len(inputs) == len(outputs)
|
550 |
+
|
551 |
+
input_ids = [self(item)['input_ids'] for item in inputs]
|
552 |
+
output_ids = [self(item)['input_ids'] for item in outputs]
|
553 |
+
|
554 |
+
packed_input_ids = []
|
555 |
+
packed_output_ids = []
|
556 |
+
if new_conversation_offset is None:
|
557 |
+
new_conversation_offset = list(range(0, len(inputs)))
|
558 |
+
assert 0 in new_conversation_offset, f"没有0,请检查new_conversation_offset: {new_conversation_offset}"
|
559 |
+
current_len = 0
|
560 |
+
|
561 |
+
for idx, (input, output) in enumerate(zip(input_ids, output_ids)):
|
562 |
+
num_special_tokens = 0
|
563 |
+
if not unidirectional_attention:
|
564 |
+
if idx in new_conversation_offset:
|
565 |
+
# cls and gmask
|
566 |
+
num_special_tokens += 2
|
567 |
+
else:
|
568 |
+
# only gmask
|
569 |
+
num_special_tokens += 1
|
570 |
+
else:
|
571 |
+
# sop and eos
|
572 |
+
if self.add_bos_token:
|
573 |
+
num_special_tokens += 2
|
574 |
+
else:
|
575 |
+
num_special_tokens += 1
|
576 |
+
|
577 |
+
# truncate
|
578 |
+
if len(input) + len(output) + current_len > max_length - num_special_tokens:
|
579 |
+
if not use_packed or use_fa2 and unidirectional_attention:
|
580 |
+
attention_mask = torch.tensor(0)
|
581 |
+
elif use_fa2:
|
582 |
+
attention_mask = -1 * torch.ones([2, max_length])
|
583 |
+
else:
|
584 |
+
attention_mask = torch.tril(torch.ones([max_length, max_length]))
|
585 |
+
# 返回一个空的样本,该样本不参与训练
|
586 |
+
default_return = {
|
587 |
+
'input_ids': (torch.ones(max_length) * self.eos_token_id).long(),
|
588 |
+
'position_ids': torch.zeros(2, max_length).long(),
|
589 |
+
'attention_mask': (attention_mask.long()),
|
590 |
+
'labels': (torch.ones(max_length) * -100).long(),
|
591 |
+
}
|
592 |
+
# 如果不截断,直接返回
|
593 |
+
if skip_truncated_turn:
|
594 |
+
if current_len == 0:
|
595 |
+
return default_return
|
596 |
+
else:
|
597 |
+
break
|
598 |
+
left_len = max_length - num_special_tokens - current_len
|
599 |
+
# 如果截断,只截断prompt
|
600 |
+
if left_len - len(output) > 0:
|
601 |
+
if left_truncate:
|
602 |
+
input = input[-(left_len - len(output)) :]
|
603 |
+
else:
|
604 |
+
input = input[: left_len - len(output)]
|
605 |
+
else:
|
606 |
+
# response超过left_len,直接返回
|
607 |
+
if current_len == 0:
|
608 |
+
return default_return
|
609 |
+
else:
|
610 |
+
break
|
611 |
+
if unidirectional_attention:
|
612 |
+
packed_input_ids.append(list(input))
|
613 |
+
else:
|
614 |
+
if num_special_tokens == 4:
|
615 |
+
packed_input_ids.append([self.cls_token_id] + list(input) + [self.gmask_token_id])
|
616 |
+
else:
|
617 |
+
packed_input_ids.append(list(input) + [self.gmask_token_id])
|
618 |
+
|
619 |
+
packed_output_ids.append(list(output) + [self.eos_token_id])
|
620 |
+
current_len += len(input) + len(output) + num_special_tokens
|
621 |
+
|
622 |
+
assert current_len <= max_length
|
623 |
+
|
624 |
+
if use_packed:
|
625 |
+
# pack模式
|
626 |
+
def build_mask_matrix(seq_length, sep):
|
627 |
+
# https://github.com/pytorch/pytorch/issues/101932, fix triu/tril bf16 support
|
628 |
+
m = torch.ones((1, seq_length, seq_length))
|
629 |
+
mask = torch.arange(1, m.shape[-1] + 1).reshape(1, -1, 1).to(m.device)
|
630 |
+
ids = torch.arange(1, m.shape[-1] + 1).reshape(1, 1, -1).expand(1, m.shape[-1], -1).to(m.device)
|
631 |
+
m = (ids <= mask).type_as(m)
|
632 |
+
|
633 |
+
m[0, :, : int(sep)] = 1
|
634 |
+
m = m.squeeze(0)
|
635 |
+
return m
|
636 |
+
|
637 |
+
tokens = []
|
638 |
+
attention_mask_list = []
|
639 |
+
input_length_list = []
|
640 |
+
position_id_list = []
|
641 |
+
block_position_id_list = []
|
642 |
+
for input, output in zip(packed_input_ids, packed_output_ids):
|
643 |
+
if self.add_bos_token:
|
644 |
+
data = input + [self.sop_token_id] + output
|
645 |
+
mask_pos = len(input) - 1
|
646 |
+
else:
|
647 |
+
data = input + output
|
648 |
+
mask_pos = len(input) - 2
|
649 |
+
if return_attention_mask:
|
650 |
+
if unidirectional_attention:
|
651 |
+
attention_mask = build_mask_matrix(len(data), 0)
|
652 |
+
else:
|
653 |
+
attention_mask = build_mask_matrix(len(data), len(input))
|
654 |
+
attention_mask = attention_mask.squeeze((0, 1))
|
655 |
+
|
656 |
+
attention_mask_list.append(attention_mask)
|
657 |
+
input_length_list.append(len(input))
|
658 |
+
tokens += data
|
659 |
+
|
660 |
+
sop_pos = mask_pos + 1
|
661 |
+
position_ids, block_position_ids = self._build_position_ids(
|
662 |
+
mask_pos=mask_pos, bos_pos=sop_pos, max_output_length=len(output), rotary_type=rotary_type
|
663 |
+
)
|
664 |
+
|
665 |
+
position_id_list.append(position_ids)
|
666 |
+
block_position_id_list.append(block_position_ids)
|
667 |
+
|
668 |
+
labels = []
|
669 |
+
for i in range(len(packed_input_ids)):
|
670 |
+
if self.add_bos_token:
|
671 |
+
labels += [-100] * len(packed_input_ids[i]) + packed_output_ids[i] + [-100]
|
672 |
+
else:
|
673 |
+
labels += [-100] * (len(packed_input_ids[i]) - 1) + packed_output_ids[i] + [-100]
|
674 |
+
|
675 |
+
total_len = 0
|
676 |
+
if use_fa2:
|
677 |
+
pack_attention_mask = -1 * torch.ones([2, current_len])
|
678 |
+
else:
|
679 |
+
pack_attention_mask = torch.tril(torch.ones([current_len, current_len]))
|
680 |
+
|
681 |
+
pack_position_ids = []
|
682 |
+
pack_block_position_ids = []
|
683 |
+
total_len = 0
|
684 |
+
max_index = 0
|
685 |
+
for i in range(len(position_id_list)):
|
686 |
+
|
687 |
+
if use_fa2:
|
688 |
+
pack_attention_mask[0][i] = total_len
|
689 |
+
pack_attention_mask[1][i] = total_len + input_length_list[i]
|
690 |
+
else:
|
691 |
+
pack_attention_mask[
|
692 |
+
total_len : total_len + attention_mask.shape[0],
|
693 |
+
total_len : total_len + attention_mask.shape[0],
|
694 |
+
] = attention_mask
|
695 |
+
position_ids = [pid + max_index for pid in position_id_list[i]]
|
696 |
+
block_position_ids = block_position_id_list[i]
|
697 |
+
pack_position_ids.extend(position_ids)
|
698 |
+
pack_block_position_ids.extend(block_position_ids)
|
699 |
+
if not isolation_position_ids:
|
700 |
+
max_index = pack_position_ids[-1] + 1
|
701 |
+
total_len += len(position_id_list[i])
|
702 |
+
position_ids = [pack_position_ids, pack_block_position_ids]
|
703 |
+
else:
|
704 |
+
# 单输入模式
|
705 |
+
# 真多轮下,一条样本可能会有好几轮对话,此时需要获取第一条样本的结束位置
|
706 |
+
if len(new_conversation_offset) > 1:
|
707 |
+
end_idx = new_conversation_offset[1]
|
708 |
+
else:
|
709 |
+
end_idx = 1
|
710 |
+
input, output = list(itertools.chain(*packed_input_ids[:end_idx])), list(
|
711 |
+
itertools.chain(*packed_output_ids[:end_idx])
|
712 |
+
)
|
713 |
+
if self.add_bos_token:
|
714 |
+
tokens = input + [self.sop_token_id] + output
|
715 |
+
else:
|
716 |
+
tokens = input + output
|
717 |
+
|
718 |
+
if self.add_bos_token:
|
719 |
+
labels = [-100] * len(input) + output + [-100]
|
720 |
+
position_ids = self._build_position_ids(
|
721 |
+
mask_pos=len(input) - 1, bos_pos=len(input), max_output_length=len(output), rotary_type=rotary_type
|
722 |
+
)
|
723 |
+
else:
|
724 |
+
labels = [-100] * (len(input) - 1) + output + [-100]
|
725 |
+
position_ids = self._build_position_ids(
|
726 |
+
mask_pos=len(input) - 2,
|
727 |
+
bos_pos=len(input) - 1,
|
728 |
+
max_output_length=len(output),
|
729 |
+
rotary_type=rotary_type,
|
730 |
+
)
|
731 |
+
attention_mask = len(input)
|
732 |
+
assert current_len == len(tokens)
|
733 |
+
|
734 |
+
# 最大长度补全
|
735 |
+
if max_length > 0 and len(tokens) < max_length and padding:
|
736 |
+
pad_length = max_length - len(tokens)
|
737 |
+
tokens += [self.pad_token_id] * pad_length
|
738 |
+
labels.extend([-100] * pad_length)
|
739 |
+
position_ids[0] += [0] * pad_length
|
740 |
+
position_ids[1] += [0] * pad_length
|
741 |
+
|
742 |
+
if use_packed:
|
743 |
+
if use_fa2:
|
744 |
+
new_attention_mask = -1 * torch.ones([2, max_length])
|
745 |
+
new_attention_mask[:, :current_len] = pack_attention_mask
|
746 |
+
else:
|
747 |
+
new_attention_mask = torch.tril(torch.ones([max_length, max_length]))
|
748 |
+
new_attention_mask[:current_len, :current_len] = pack_attention_mask
|
749 |
+
pack_attention_mask = new_attention_mask.contiguous()
|
750 |
+
|
751 |
+
assert len(tokens) == len(labels)
|
752 |
+
|
753 |
+
if max_length > 0 and padding:
|
754 |
+
assert len(tokens) == max_length
|
755 |
+
|
756 |
+
if use_fa2 and unidirectional_attention:
|
757 |
+
# pack_attention_mask = torch.zeros([1], dtype=torch.long)
|
758 |
+
pack_attention_mask = torch.tensor(0)
|
759 |
+
|
760 |
+
if use_packed:
|
761 |
+
if not use_fa2:
|
762 |
+
attention_mask = pack_attention_mask.unsqueeze(0).long()
|
763 |
+
else:
|
764 |
+
attention_mask = pack_attention_mask
|
765 |
+
else:
|
766 |
+
attention_mask = torch.tensor(attention_mask).long()
|
767 |
+
return {
|
768 |
+
'input_ids': torch.tensor(tokens).long(),
|
769 |
+
'position_ids': torch.tensor(position_ids).long(),
|
770 |
+
'attention_mask': attention_mask,
|
771 |
+
'labels': torch.tensor(labels).long(),
|
772 |
+
}
|
773 |
+
|
774 |
+
def _build_baichuan_inputs_for_train(
|
775 |
+
self,
|
776 |
+
inputs: Union[str, List[str]],
|
777 |
+
outputs: Union[str, List[str]],
|
778 |
+
new_conversation_offset: List[int] = None,
|
779 |
+
max_length: int = 2048,
|
780 |
+
rotary_type: str = "1d",
|
781 |
+
left_truncate: bool = True,
|
782 |
+
skip_truncated_turn: bool = True,
|
783 |
+
use_fa2: bool = True,
|
784 |
+
padding: bool = True,
|
785 |
+
):
|
786 |
+
'''
|
787 |
+
input: <role> HUMAN </role> u1 <role> ASSISTANT </role> a11 a12 <role> HUMAN </role> u2 <role> ASSISTANT </role> a21 a22 <|endoftext|> <role> HUMAN </role> u1 <role> ASSISTANT </role> a11 a12 <role> HUMAN </role> u2 <role> ASSISTANT </role> a21 a22 <|endoftext|>
|
788 |
+
output: x x x x x x a11 a12 <|endoftext|> x x x x x x a21 a22 <|endoftext|> x x x x x x x a11 a12 <|endoftext|> x x x x x x a21 a22 <|endoftext|> x
|
789 |
+
只适用真多轮+pack数据训练单向模型,需要打开use_true_multiturn
|
790 |
+
'''
|
791 |
+
if isinstance(inputs, str):
|
792 |
+
inputs = [inputs]
|
793 |
+
if isinstance(outputs, str):
|
794 |
+
outputs = [outputs]
|
795 |
+
assert len(inputs) == len(outputs)
|
796 |
+
|
797 |
+
input_ids = [self(item)['input_ids'] for item in inputs]
|
798 |
+
output_ids = [self(item)['input_ids'] for item in outputs]
|
799 |
+
|
800 |
+
packed_input_ids = []
|
801 |
+
packed_output_ids = []
|
802 |
+
|
803 |
+
if new_conversation_offset is None:
|
804 |
+
new_conversation_offset = list(range(0, len(inputs)))
|
805 |
+
assert 0 in new_conversation_offset, f"没有0,请检查new_conversation_offset: {new_conversation_offset}"
|
806 |
+
current_len = 0
|
807 |
+
|
808 |
+
for idx, (input, output) in enumerate(zip(input_ids, output_ids)):
|
809 |
+
num_special_tokens = 0
|
810 |
+
if idx != 0 and idx in new_conversation_offset:
|
811 |
+
# 在input_ids加入eos,只有第0条样本不加
|
812 |
+
num_special_tokens += 1
|
813 |
+
|
814 |
+
# truncate
|
815 |
+
if len(input) + len(output) + current_len > max_length - num_special_tokens:
|
816 |
+
if use_fa2:
|
817 |
+
attention_mask = torch.tensor(0)
|
818 |
+
else:
|
819 |
+
attention_mask = torch.tril(torch.ones([max_length, max_length]))
|
820 |
+
# 返回一个空的样本,该样本不参与训练
|
821 |
+
default_return = {
|
822 |
+
'input_ids': (torch.ones(max_length) * self.eos_token_id).long(),
|
823 |
+
'position_ids': torch.zeros(2, max_length).long(),
|
824 |
+
'attention_mask': (attention_mask.long()),
|
825 |
+
'labels': (torch.ones(max_length) * -100).long(),
|
826 |
+
}
|
827 |
+
|
828 |
+
# 如果不截断,直接返回
|
829 |
+
if skip_truncated_turn:
|
830 |
+
if current_len == 0:
|
831 |
+
return default_return
|
832 |
+
else:
|
833 |
+
break
|
834 |
+
left_len = max_length - num_special_tokens - current_len
|
835 |
+
# 如果截断,只截断prompt
|
836 |
+
if left_len - len(output) > 0:
|
837 |
+
if left_truncate:
|
838 |
+
input = input[-(left_len - len(output)) :]
|
839 |
+
else:
|
840 |
+
input = input[: left_len - len(output)]
|
841 |
+
else:
|
842 |
+
# response超过left_len,直接返回
|
843 |
+
if current_len == 0:
|
844 |
+
return default_return
|
845 |
+
else:
|
846 |
+
break
|
847 |
+
# 这里拼的是input_ids
|
848 |
+
if num_special_tokens == 1:
|
849 |
+
packed_input_ids.append([self.eos_token_id] + list(input))
|
850 |
+
else:
|
851 |
+
packed_input_ids.append(list(input))
|
852 |
+
packed_output_ids.append(list(output))
|
853 |
+
current_len += len(input) + len(output) + num_special_tokens
|
854 |
+
assert current_len <= max_length
|
855 |
+
|
856 |
+
def build_mask_matrix(seq_length, sep):
|
857 |
+
# https://github.com/pytorch/pytorch/issues/101932, fix triu/tril bf16 support
|
858 |
+
m = torch.ones((1, seq_length, seq_length))
|
859 |
+
mask = torch.arange(1, m.shape[-1] + 1).reshape(1, -1, 1).to(m.device)
|
860 |
+
ids = torch.arange(1, m.shape[-1] + 1).reshape(1, 1, -1).expand(1, m.shape[-1], -1).to(m.device)
|
861 |
+
m = (ids <= mask).type_as(m)
|
862 |
+
|
863 |
+
m[0, :, : int(sep)] = 1
|
864 |
+
m = m.squeeze(0)
|
865 |
+
return m
|
866 |
+
|
867 |
+
tokens = []
|
868 |
+
attention_mask_list = []
|
869 |
+
position_id_list = []
|
870 |
+
block_position_id_list = []
|
871 |
+
token_lens = []
|
872 |
+
for input, output in zip(packed_input_ids, packed_output_ids):
|
873 |
+
data = input + output
|
874 |
+
if not use_fa2:
|
875 |
+
attention_mask = build_mask_matrix(len(data), 0)
|
876 |
+
attention_mask_list.append(attention_mask)
|
877 |
+
tokens += data
|
878 |
+
token_lens.append(len(data))
|
879 |
+
|
880 |
+
position_ids, block_position_ids = self._build_position_ids(
|
881 |
+
mask_pos=len(input) - 2, bos_pos=len(input) - 1, max_output_length=len(output), rotary_type=rotary_type
|
882 |
+
)
|
883 |
+
|
884 |
+
position_id_list.append(position_ids)
|
885 |
+
block_position_id_list.append(block_position_ids)
|
886 |
+
|
887 |
+
labels = []
|
888 |
+
for i in range(len(packed_input_ids)):
|
889 |
+
labels += [-100] * (len(packed_input_ids[i]) - 1) + packed_output_ids[i] + [self.eos_token_id]
|
890 |
+
|
891 |
+
total_len = 0
|
892 |
+
if use_fa2:
|
893 |
+
pack_attention_mask = torch.Tensor([[0], [1]])
|
894 |
+
else:
|
895 |
+
pack_attention_mask = torch.tril(torch.ones([max_length, max_length]))
|
896 |
+
|
897 |
+
pack_position_ids = []
|
898 |
+
pack_block_position_ids = []
|
899 |
+
total_len = 0
|
900 |
+
max_index = 0
|
901 |
+
for i in range(len(token_lens)):
|
902 |
+
if not use_fa2:
|
903 |
+
attention_mask = attention_mask_list[i]
|
904 |
+
pack_attention_mask[
|
905 |
+
total_len : total_len + attention_mask.shape[0], total_len : total_len + attention_mask.shape[0]
|
906 |
+
] = attention_mask
|
907 |
+
position_ids = [pid + max_index for pid in position_id_list[i]]
|
908 |
+
block_position_ids = block_position_id_list[i]
|
909 |
+
pack_position_ids.extend(position_ids)
|
910 |
+
pack_block_position_ids.extend(block_position_ids)
|
911 |
+
max_index = pack_position_ids[-1] + 1
|
912 |
+
total_len += token_lens[i]
|
913 |
+
position_ids = [pack_position_ids, pack_block_position_ids]
|
914 |
+
|
915 |
+
if max_length > 0 and len(tokens) < max_length and padding:
|
916 |
+
pad_length = max_length - len(tokens)
|
917 |
+
tokens += [self.pad_token_id] * pad_length
|
918 |
+
labels.extend([-100] * pad_length)
|
919 |
+
position_ids[0] += [0] * pad_length
|
920 |
+
position_ids[1] += [0] * pad_length
|
921 |
+
|
922 |
+
assert len(tokens) == len(labels)
|
923 |
+
|
924 |
+
if not use_fa2:
|
925 |
+
attention_mask = pack_attention_mask.unsqueeze(0).long()
|
926 |
+
else:
|
927 |
+
attention_mask = torch.tensor(0)
|
928 |
+
return {
|
929 |
+
'input_ids': torch.tensor(tokens).long(),
|
930 |
+
'position_ids': torch.tensor(position_ids).long(),
|
931 |
+
'attention_mask': attention_mask,
|
932 |
+
'labels': torch.tensor(labels).long(),
|
933 |
+
}
|
934 |
+
|
935 |
+
def build_inputs_for_train(
|
936 |
+
self,
|
937 |
+
data: Union[Dict, List[Dict]],
|
938 |
+
new_conversation_offset: List[int] = None,
|
939 |
+
chat_format="antglm_chat",
|
940 |
+
is_chat_format=True, # 如果传入的是字符串,用于说明是否已经是
|
941 |
+
use_true_multiturn=False,
|
942 |
+
max_length: int = 2048,
|
943 |
+
rotary_type: str = "1d",
|
944 |
+
left_truncate: bool = True,
|
945 |
+
unidirectional_attention: bool = True,
|
946 |
+
isolation_position_ids: bool = False,
|
947 |
+
padding: bool = True,
|
948 |
+
use_fa2: bool = True,
|
949 |
+
use_packed: bool = True,
|
950 |
+
use_baichuan_packed: bool = False,
|
951 |
+
skip_truncated_turn: bool = False,
|
952 |
+
return_attention_mask: bool = True,
|
953 |
+
):
|
954 |
+
r"""
|
955 |
+
Build tensor input for model training. If inputs and outputs are list, will pack them.
|
956 |
+
|
957 |
+
Args:
|
958 |
+
inputs (str, List[str], List[Dict], List[List[Dict]]): the input prompts.
|
959 |
+
outputs (str, List[str]): the output responses.
|
960 |
+
new_conversation_offset (List[int]): the offset index of the new conversation turn.
|
961 |
+
is_chat_format (bool): whether the input is already chatml format
|
962 |
+
max_length (int, Optional): the maximum length of the final input ids for training. Default: 2048
|
963 |
+
rotary_type (str, Optional): the rotary type of position embedding. Default: 1d
|
964 |
+
left_truncate (bool, Optional): whether truncate the inputs from left. Default: True
|
965 |
+
use_fa2 (bool, Optional): whether to build attention mask under flash attention 2.
|
966 |
+
"""
|
967 |
+
if isinstance(data, List):
|
968 |
+
# chatml list
|
969 |
+
_inputs = []
|
970 |
+
_outputs = []
|
971 |
+
new_conversation_offset = []
|
972 |
+
for _input in data:
|
973 |
+
if use_true_multiturn:
|
974 |
+
chat = self._chat_from_json(_input, chat_format=chat_format)
|
975 |
+
chat_data = chat.prompt_pack
|
976 |
+
new_conversation_offset.append(len(_inputs))
|
977 |
+
_inputs.extend(chat_data['input'])
|
978 |
+
_outputs.extend(chat_data['output'])
|
979 |
+
else:
|
980 |
+
_conversation = _convert_to_conversation(_input)
|
981 |
+
assert is_assistant(_conversation[-1])
|
982 |
+
|
983 |
+
_inputs.append(
|
984 |
+
self.apply_chat_template(_conversation[:-1], tokenize=False, add_generation_prompt=True)
|
985 |
+
)
|
986 |
+
_outputs.append(_conversation[-1]['content'])
|
987 |
+
|
988 |
+
return self._build_inputs_for_train(
|
989 |
+
inputs=_inputs,
|
990 |
+
outputs=_outputs,
|
991 |
+
new_conversation_offset=new_conversation_offset,
|
992 |
+
max_length=max_length,
|
993 |
+
rotary_type=rotary_type,
|
994 |
+
left_truncate=left_truncate,
|
995 |
+
unidirectional_attention=unidirectional_attention,
|
996 |
+
isolation_position_ids=isolation_position_ids,
|
997 |
+
padding=padding,
|
998 |
+
use_fa2=use_fa2,
|
999 |
+
use_packed=use_packed,
|
1000 |
+
use_baichuan_packed=use_baichuan_packed,
|
1001 |
+
skip_truncated_turn=skip_truncated_turn,
|
1002 |
+
return_attention_mask=return_attention_mask,
|
1003 |
+
)
|
1004 |
+
elif isinstance(data, Dict):
|
1005 |
+
if 'messages' in data:
|
1006 |
+
# chatml format
|
1007 |
+
if use_true_multiturn:
|
1008 |
+
chat = self._chat_from_json(data, chat_format=chat_format)
|
1009 |
+
chat_data = chat.prompt_pack
|
1010 |
+
else:
|
1011 |
+
_conversation = _convert_to_conversation(data)
|
1012 |
+
assert is_assistant(_conversation[-1])
|
1013 |
+
|
1014 |
+
chat_data = {
|
1015 |
+
"input": self.apply_chat_template(
|
1016 |
+
_conversation[:-1], tokenize=False, add_generation_prompt=True
|
1017 |
+
),
|
1018 |
+
"output": _conversation[-1]['content'],
|
1019 |
+
}
|
1020 |
+
|
1021 |
+
return self._build_inputs_for_train(
|
1022 |
+
inputs=chat_data['input'],
|
1023 |
+
outputs=chat_data['output'],
|
1024 |
+
max_length=max_length,
|
1025 |
+
rotary_type=rotary_type,
|
1026 |
+
left_truncate=left_truncate,
|
1027 |
+
unidirectional_attention=unidirectional_attention,
|
1028 |
+
isolation_position_ids=isolation_position_ids,
|
1029 |
+
padding=padding,
|
1030 |
+
use_fa2=use_fa2,
|
1031 |
+
use_packed=use_packed,
|
1032 |
+
use_baichuan_packed=use_baichuan_packed,
|
1033 |
+
skip_truncated_turn=skip_truncated_turn,
|
1034 |
+
return_attention_mask=return_attention_mask,
|
1035 |
+
)
|
1036 |
+
else:
|
1037 |
+
inputs = data['input']
|
1038 |
+
outputs = data['output']
|
1039 |
+
|
1040 |
+
if isinstance(inputs, str):
|
1041 |
+
inputs = [inputs]
|
1042 |
+
if isinstance(outputs, str):
|
1043 |
+
outputs = [outputs]
|
1044 |
+
|
1045 |
+
if not is_chat_format and chat_format:
|
1046 |
+
inputs = [
|
1047 |
+
self.apply_chat_template(
|
1048 |
+
[{"role": "HUMAN", "content": item}], tokenize=False, chat_format=chat_format
|
1049 |
+
)
|
1050 |
+
for item in inputs
|
1051 |
+
]
|
1052 |
+
|
1053 |
+
return self._build_inputs_for_train(
|
1054 |
+
inputs=inputs,
|
1055 |
+
outputs=outputs,
|
1056 |
+
new_conversation_offset=new_conversation_offset,
|
1057 |
+
max_length=max_length,
|
1058 |
+
rotary_type=rotary_type,
|
1059 |
+
left_truncate=left_truncate,
|
1060 |
+
unidirectional_attention=unidirectional_attention,
|
1061 |
+
isolation_position_ids=isolation_position_ids,
|
1062 |
+
padding=padding,
|
1063 |
+
use_fa2=use_fa2,
|
1064 |
+
use_packed=use_packed,
|
1065 |
+
use_baichuan_packed=use_baichuan_packed,
|
1066 |
+
skip_truncated_turn=skip_truncated_turn,
|
1067 |
+
return_attention_mask=return_attention_mask,
|
1068 |
+
)
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,2155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": false,
|
3 |
+
"add_eos_token": false,
|
4 |
+
"added_tokens_decoder": {
|
5 |
+
"126080": {
|
6 |
+
"content": "<|startoftext|>",
|
7 |
+
"lstrip": false,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false,
|
11 |
+
"special": true
|
12 |
+
},
|
13 |
+
"126081": {
|
14 |
+
"content": "<|endoftext|>",
|
15 |
+
"lstrip": false,
|
16 |
+
"normalized": false,
|
17 |
+
"rstrip": false,
|
18 |
+
"single_word": false,
|
19 |
+
"special": true
|
20 |
+
},
|
21 |
+
"126082": {
|
22 |
+
"content": "[CLS]",
|
23 |
+
"lstrip": false,
|
24 |
+
"normalized": false,
|
25 |
+
"rstrip": false,
|
26 |
+
"single_word": false,
|
27 |
+
"special": true
|
28 |
+
},
|
29 |
+
"126083": {
|
30 |
+
"content": "[gMASK]",
|
31 |
+
"lstrip": false,
|
32 |
+
"normalized": false,
|
33 |
+
"rstrip": false,
|
34 |
+
"single_word": false,
|
35 |
+
"special": true
|
36 |
+
},
|
37 |
+
"126084": {
|
38 |
+
"content": "<|reserved_token_0|>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": false,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false,
|
43 |
+
"special": true
|
44 |
+
},
|
45 |
+
"126085": {
|
46 |
+
"content": "<|reserved_token_1|>",
|
47 |
+
"lstrip": false,
|
48 |
+
"normalized": false,
|
49 |
+
"rstrip": false,
|
50 |
+
"single_word": false,
|
51 |
+
"special": true
|
52 |
+
},
|
53 |
+
"126086": {
|
54 |
+
"content": "<|reserved_token_2|>",
|
55 |
+
"lstrip": false,
|
56 |
+
"normalized": false,
|
57 |
+
"rstrip": false,
|
58 |
+
"single_word": false,
|
59 |
+
"special": true
|
60 |
+
},
|
61 |
+
"126087": {
|
62 |
+
"content": "<|reserved_token_3|>",
|
63 |
+
"lstrip": false,
|
64 |
+
"normalized": false,
|
65 |
+
"rstrip": false,
|
66 |
+
"single_word": false,
|
67 |
+
"special": true
|
68 |
+
},
|
69 |
+
"126088": {
|
70 |
+
"content": "<|reserved_token_4|>",
|
71 |
+
"lstrip": false,
|
72 |
+
"normalized": false,
|
73 |
+
"rstrip": false,
|
74 |
+
"single_word": false,
|
75 |
+
"special": true
|
76 |
+
},
|
77 |
+
"126089": {
|
78 |
+
"content": "<|reserved_token_5|>",
|
79 |
+
"lstrip": false,
|
80 |
+
"normalized": false,
|
81 |
+
"rstrip": false,
|
82 |
+
"single_word": false,
|
83 |
+
"special": true
|
84 |
+
},
|
85 |
+
"126090": {
|
86 |
+
"content": "<|reserved_token_6|>",
|
87 |
+
"lstrip": false,
|
88 |
+
"normalized": false,
|
89 |
+
"rstrip": false,
|
90 |
+
"single_word": false,
|
91 |
+
"special": true
|
92 |
+
},
|
93 |
+
"126091": {
|
94 |
+
"content": "<|reserved_token_7|>",
|
95 |
+
"lstrip": false,
|
96 |
+
"normalized": false,
|
97 |
+
"rstrip": false,
|
98 |
+
"single_word": false,
|
99 |
+
"special": true
|
100 |
+
},
|
101 |
+
"126092": {
|
102 |
+
"content": "<|reserved_token_8|>",
|
103 |
+
"lstrip": false,
|
104 |
+
"normalized": false,
|
105 |
+
"rstrip": false,
|
106 |
+
"single_word": false,
|
107 |
+
"special": true
|
108 |
+
},
|
109 |
+
"126093": {
|
110 |
+
"content": "<|reserved_token_9|>",
|
111 |
+
"lstrip": false,
|
112 |
+
"normalized": false,
|
113 |
+
"rstrip": false,
|
114 |
+
"single_word": false,
|
115 |
+
"special": true
|
116 |
+
},
|
117 |
+
"126094": {
|
118 |
+
"content": "<|reserved_token_10|>",
|
119 |
+
"lstrip": false,
|
120 |
+
"normalized": false,
|
121 |
+
"rstrip": false,
|
122 |
+
"single_word": false,
|
123 |
+
"special": true
|
124 |
+
},
|
125 |
+
"126095": {
|
126 |
+
"content": "<|reserved_token_11|>",
|
127 |
+
"lstrip": false,
|
128 |
+
"normalized": false,
|
129 |
+
"rstrip": false,
|
130 |
+
"single_word": false,
|
131 |
+
"special": true
|
132 |
+
},
|
133 |
+
"126096": {
|
134 |
+
"content": "<|reserved_token_12|>",
|
135 |
+
"lstrip": false,
|
136 |
+
"normalized": false,
|
137 |
+
"rstrip": false,
|
138 |
+
"single_word": false,
|
139 |
+
"special": true
|
140 |
+
},
|
141 |
+
"126097": {
|
142 |
+
"content": "<|reserved_token_13|>",
|
143 |
+
"lstrip": false,
|
144 |
+
"normalized": false,
|
145 |
+
"rstrip": false,
|
146 |
+
"single_word": false,
|
147 |
+
"special": true
|
148 |
+
},
|
149 |
+
"126098": {
|
150 |
+
"content": "<|reserved_token_14|>",
|
151 |
+
"lstrip": false,
|
152 |
+
"normalized": false,
|
153 |
+
"rstrip": false,
|
154 |
+
"single_word": false,
|
155 |
+
"special": true
|
156 |
+
},
|
157 |
+
"126099": {
|
158 |
+
"content": "<|reserved_token_15|>",
|
159 |
+
"lstrip": false,
|
160 |
+
"normalized": false,
|
161 |
+
"rstrip": false,
|
162 |
+
"single_word": false,
|
163 |
+
"special": true
|
164 |
+
},
|
165 |
+
"126100": {
|
166 |
+
"content": "<|reserved_token_16|>",
|
167 |
+
"lstrip": false,
|
168 |
+
"normalized": false,
|
169 |
+
"rstrip": false,
|
170 |
+
"single_word": false,
|
171 |
+
"special": true
|
172 |
+
},
|
173 |
+
"126101": {
|
174 |
+
"content": "<|reserved_token_17|>",
|
175 |
+
"lstrip": false,
|
176 |
+
"normalized": false,
|
177 |
+
"rstrip": false,
|
178 |
+
"single_word": false,
|
179 |
+
"special": true
|
180 |
+
},
|
181 |
+
"126102": {
|
182 |
+
"content": "<|reserved_token_18|>",
|
183 |
+
"lstrip": false,
|
184 |
+
"normalized": false,
|
185 |
+
"rstrip": false,
|
186 |
+
"single_word": false,
|
187 |
+
"special": true
|
188 |
+
},
|
189 |
+
"126103": {
|
190 |
+
"content": "<|reserved_token_19|>",
|
191 |
+
"lstrip": false,
|
192 |
+
"normalized": false,
|
193 |
+
"rstrip": false,
|
194 |
+
"single_word": false,
|
195 |
+
"special": true
|
196 |
+
},
|
197 |
+
"126104": {
|
198 |
+
"content": "<|reserved_token_20|>",
|
199 |
+
"lstrip": false,
|
200 |
+
"normalized": false,
|
201 |
+
"rstrip": false,
|
202 |
+
"single_word": false,
|
203 |
+
"special": true
|
204 |
+
},
|
205 |
+
"126105": {
|
206 |
+
"content": "<|reserved_token_21|>",
|
207 |
+
"lstrip": false,
|
208 |
+
"normalized": false,
|
209 |
+
"rstrip": false,
|
210 |
+
"single_word": false,
|
211 |
+
"special": true
|
212 |
+
},
|
213 |
+
"126106": {
|
214 |
+
"content": "<|reserved_token_22|>",
|
215 |
+
"lstrip": false,
|
216 |
+
"normalized": false,
|
217 |
+
"rstrip": false,
|
218 |
+
"single_word": false,
|
219 |
+
"special": true
|
220 |
+
},
|
221 |
+
"126107": {
|
222 |
+
"content": "<|reserved_token_23|>",
|
223 |
+
"lstrip": false,
|
224 |
+
"normalized": false,
|
225 |
+
"rstrip": false,
|
226 |
+
"single_word": false,
|
227 |
+
"special": true
|
228 |
+
},
|
229 |
+
"126108": {
|
230 |
+
"content": "<|reserved_token_24|>",
|
231 |
+
"lstrip": false,
|
232 |
+
"normalized": false,
|
233 |
+
"rstrip": false,
|
234 |
+
"single_word": false,
|
235 |
+
"special": true
|
236 |
+
},
|
237 |
+
"126109": {
|
238 |
+
"content": "<|reserved_token_25|>",
|
239 |
+
"lstrip": false,
|
240 |
+
"normalized": false,
|
241 |
+
"rstrip": false,
|
242 |
+
"single_word": false,
|
243 |
+
"special": true
|
244 |
+
},
|
245 |
+
"126110": {
|
246 |
+
"content": "<|reserved_token_26|>",
|
247 |
+
"lstrip": false,
|
248 |
+
"normalized": false,
|
249 |
+
"rstrip": false,
|
250 |
+
"single_word": false,
|
251 |
+
"special": true
|
252 |
+
},
|
253 |
+
"126111": {
|
254 |
+
"content": "<|reserved_token_27|>",
|
255 |
+
"lstrip": false,
|
256 |
+
"normalized": false,
|
257 |
+
"rstrip": false,
|
258 |
+
"single_word": false,
|
259 |
+
"special": true
|
260 |
+
},
|
261 |
+
"126112": {
|
262 |
+
"content": "<|reserved_token_28|>",
|
263 |
+
"lstrip": false,
|
264 |
+
"normalized": false,
|
265 |
+
"rstrip": false,
|
266 |
+
"single_word": false,
|
267 |
+
"special": true
|
268 |
+
},
|
269 |
+
"126113": {
|
270 |
+
"content": "<|reserved_token_29|>",
|
271 |
+
"lstrip": false,
|
272 |
+
"normalized": false,
|
273 |
+
"rstrip": false,
|
274 |
+
"single_word": false,
|
275 |
+
"special": true
|
276 |
+
},
|
277 |
+
"126114": {
|
278 |
+
"content": "<|reserved_token_30|>",
|
279 |
+
"lstrip": false,
|
280 |
+
"normalized": false,
|
281 |
+
"rstrip": false,
|
282 |
+
"single_word": false,
|
283 |
+
"special": true
|
284 |
+
},
|
285 |
+
"126115": {
|
286 |
+
"content": "<|reserved_token_31|>",
|
287 |
+
"lstrip": false,
|
288 |
+
"normalized": false,
|
289 |
+
"rstrip": false,
|
290 |
+
"single_word": false,
|
291 |
+
"special": true
|
292 |
+
},
|
293 |
+
"126116": {
|
294 |
+
"content": "<|reserved_token_32|>",
|
295 |
+
"lstrip": false,
|
296 |
+
"normalized": false,
|
297 |
+
"rstrip": false,
|
298 |
+
"single_word": false,
|
299 |
+
"special": true
|
300 |
+
},
|
301 |
+
"126117": {
|
302 |
+
"content": "<|reserved_token_33|>",
|
303 |
+
"lstrip": false,
|
304 |
+
"normalized": false,
|
305 |
+
"rstrip": false,
|
306 |
+
"single_word": false,
|
307 |
+
"special": true
|
308 |
+
},
|
309 |
+
"126118": {
|
310 |
+
"content": "<|reserved_token_34|>",
|
311 |
+
"lstrip": false,
|
312 |
+
"normalized": false,
|
313 |
+
"rstrip": false,
|
314 |
+
"single_word": false,
|
315 |
+
"special": true
|
316 |
+
},
|
317 |
+
"126119": {
|
318 |
+
"content": "<|reserved_token_35|>",
|
319 |
+
"lstrip": false,
|
320 |
+
"normalized": false,
|
321 |
+
"rstrip": false,
|
322 |
+
"single_word": false,
|
323 |
+
"special": true
|
324 |
+
},
|
325 |
+
"126120": {
|
326 |
+
"content": "<|reserved_token_36|>",
|
327 |
+
"lstrip": false,
|
328 |
+
"normalized": false,
|
329 |
+
"rstrip": false,
|
330 |
+
"single_word": false,
|
331 |
+
"special": true
|
332 |
+
},
|
333 |
+
"126121": {
|
334 |
+
"content": "<|reserved_token_37|>",
|
335 |
+
"lstrip": false,
|
336 |
+
"normalized": false,
|
337 |
+
"rstrip": false,
|
338 |
+
"single_word": false,
|
339 |
+
"special": true
|
340 |
+
},
|
341 |
+
"126122": {
|
342 |
+
"content": "<|reserved_token_38|>",
|
343 |
+
"lstrip": false,
|
344 |
+
"normalized": false,
|
345 |
+
"rstrip": false,
|
346 |
+
"single_word": false,
|
347 |
+
"special": true
|
348 |
+
},
|
349 |
+
"126123": {
|
350 |
+
"content": "<|reserved_token_39|>",
|
351 |
+
"lstrip": false,
|
352 |
+
"normalized": false,
|
353 |
+
"rstrip": false,
|
354 |
+
"single_word": false,
|
355 |
+
"special": true
|
356 |
+
},
|
357 |
+
"126124": {
|
358 |
+
"content": "<|reserved_token_40|>",
|
359 |
+
"lstrip": false,
|
360 |
+
"normalized": false,
|
361 |
+
"rstrip": false,
|
362 |
+
"single_word": false,
|
363 |
+
"special": true
|
364 |
+
},
|
365 |
+
"126125": {
|
366 |
+
"content": "<|reserved_token_41|>",
|
367 |
+
"lstrip": false,
|
368 |
+
"normalized": false,
|
369 |
+
"rstrip": false,
|
370 |
+
"single_word": false,
|
371 |
+
"special": true
|
372 |
+
},
|
373 |
+
"126126": {
|
374 |
+
"content": "<|reserved_token_42|>",
|
375 |
+
"lstrip": false,
|
376 |
+
"normalized": false,
|
377 |
+
"rstrip": false,
|
378 |
+
"single_word": false,
|
379 |
+
"special": true
|
380 |
+
},
|
381 |
+
"126127": {
|
382 |
+
"content": "<|reserved_token_43|>",
|
383 |
+
"lstrip": false,
|
384 |
+
"normalized": false,
|
385 |
+
"rstrip": false,
|
386 |
+
"single_word": false,
|
387 |
+
"special": true
|
388 |
+
},
|
389 |
+
"126128": {
|
390 |
+
"content": "<|reserved_token_44|>",
|
391 |
+
"lstrip": false,
|
392 |
+
"normalized": false,
|
393 |
+
"rstrip": false,
|
394 |
+
"single_word": false,
|
395 |
+
"special": true
|
396 |
+
},
|
397 |
+
"126129": {
|
398 |
+
"content": "<|reserved_token_45|>",
|
399 |
+
"lstrip": false,
|
400 |
+
"normalized": false,
|
401 |
+
"rstrip": false,
|
402 |
+
"single_word": false,
|
403 |
+
"special": true
|
404 |
+
},
|
405 |
+
"126130": {
|
406 |
+
"content": "<|reserved_token_46|>",
|
407 |
+
"lstrip": false,
|
408 |
+
"normalized": false,
|
409 |
+
"rstrip": false,
|
410 |
+
"single_word": false,
|
411 |
+
"special": true
|
412 |
+
},
|
413 |
+
"126131": {
|
414 |
+
"content": "<|reserved_token_47|>",
|
415 |
+
"lstrip": false,
|
416 |
+
"normalized": false,
|
417 |
+
"rstrip": false,
|
418 |
+
"single_word": false,
|
419 |
+
"special": true
|
420 |
+
},
|
421 |
+
"126132": {
|
422 |
+
"content": "<|reserved_token_48|>",
|
423 |
+
"lstrip": false,
|
424 |
+
"normalized": false,
|
425 |
+
"rstrip": false,
|
426 |
+
"single_word": false,
|
427 |
+
"special": true
|
428 |
+
},
|
429 |
+
"126133": {
|
430 |
+
"content": "<|reserved_token_49|>",
|
431 |
+
"lstrip": false,
|
432 |
+
"normalized": false,
|
433 |
+
"rstrip": false,
|
434 |
+
"single_word": false,
|
435 |
+
"special": true
|
436 |
+
},
|
437 |
+
"126134": {
|
438 |
+
"content": "<|reserved_token_50|>",
|
439 |
+
"lstrip": false,
|
440 |
+
"normalized": false,
|
441 |
+
"rstrip": false,
|
442 |
+
"single_word": false,
|
443 |
+
"special": true
|
444 |
+
},
|
445 |
+
"126135": {
|
446 |
+
"content": "<|reserved_token_51|>",
|
447 |
+
"lstrip": false,
|
448 |
+
"normalized": false,
|
449 |
+
"rstrip": false,
|
450 |
+
"single_word": false,
|
451 |
+
"special": true
|
452 |
+
},
|
453 |
+
"126136": {
|
454 |
+
"content": "<|reserved_token_52|>",
|
455 |
+
"lstrip": false,
|
456 |
+
"normalized": false,
|
457 |
+
"rstrip": false,
|
458 |
+
"single_word": false,
|
459 |
+
"special": true
|
460 |
+
},
|
461 |
+
"126137": {
|
462 |
+
"content": "<|reserved_token_53|>",
|
463 |
+
"lstrip": false,
|
464 |
+
"normalized": false,
|
465 |
+
"rstrip": false,
|
466 |
+
"single_word": false,
|
467 |
+
"special": true
|
468 |
+
},
|
469 |
+
"126138": {
|
470 |
+
"content": "<|reserved_token_54|>",
|
471 |
+
"lstrip": false,
|
472 |
+
"normalized": false,
|
473 |
+
"rstrip": false,
|
474 |
+
"single_word": false,
|
475 |
+
"special": true
|
476 |
+
},
|
477 |
+
"126139": {
|
478 |
+
"content": "<|reserved_token_55|>",
|
479 |
+
"lstrip": false,
|
480 |
+
"normalized": false,
|
481 |
+
"rstrip": false,
|
482 |
+
"single_word": false,
|
483 |
+
"special": true
|
484 |
+
},
|
485 |
+
"126140": {
|
486 |
+
"content": "<|reserved_token_56|>",
|
487 |
+
"lstrip": false,
|
488 |
+
"normalized": false,
|
489 |
+
"rstrip": false,
|
490 |
+
"single_word": false,
|
491 |
+
"special": true
|
492 |
+
},
|
493 |
+
"126141": {
|
494 |
+
"content": "<|reserved_token_57|>",
|
495 |
+
"lstrip": false,
|
496 |
+
"normalized": false,
|
497 |
+
"rstrip": false,
|
498 |
+
"single_word": false,
|
499 |
+
"special": true
|
500 |
+
},
|
501 |
+
"126142": {
|
502 |
+
"content": "<|reserved_token_58|>",
|
503 |
+
"lstrip": false,
|
504 |
+
"normalized": false,
|
505 |
+
"rstrip": false,
|
506 |
+
"single_word": false,
|
507 |
+
"special": true
|
508 |
+
},
|
509 |
+
"126143": {
|
510 |
+
"content": "<|reserved_token_59|>",
|
511 |
+
"lstrip": false,
|
512 |
+
"normalized": false,
|
513 |
+
"rstrip": false,
|
514 |
+
"single_word": false,
|
515 |
+
"special": true
|
516 |
+
},
|
517 |
+
"126144": {
|
518 |
+
"content": "<|reserved_token_60|>",
|
519 |
+
"lstrip": false,
|
520 |
+
"normalized": false,
|
521 |
+
"rstrip": false,
|
522 |
+
"single_word": false,
|
523 |
+
"special": true
|
524 |
+
},
|
525 |
+
"126145": {
|
526 |
+
"content": "<|reserved_token_61|>",
|
527 |
+
"lstrip": false,
|
528 |
+
"normalized": false,
|
529 |
+
"rstrip": false,
|
530 |
+
"single_word": false,
|
531 |
+
"special": true
|
532 |
+
},
|
533 |
+
"126146": {
|
534 |
+
"content": "<|reserved_token_62|>",
|
535 |
+
"lstrip": false,
|
536 |
+
"normalized": false,
|
537 |
+
"rstrip": false,
|
538 |
+
"single_word": false,
|
539 |
+
"special": true
|
540 |
+
},
|
541 |
+
"126147": {
|
542 |
+
"content": "<|reserved_token_63|>",
|
543 |
+
"lstrip": false,
|
544 |
+
"normalized": false,
|
545 |
+
"rstrip": false,
|
546 |
+
"single_word": false,
|
547 |
+
"special": true
|
548 |
+
},
|
549 |
+
"126148": {
|
550 |
+
"content": "<|reserved_token_64|>",
|
551 |
+
"lstrip": false,
|
552 |
+
"normalized": false,
|
553 |
+
"rstrip": false,
|
554 |
+
"single_word": false,
|
555 |
+
"special": true
|
556 |
+
},
|
557 |
+
"126149": {
|
558 |
+
"content": "<|reserved_token_65|>",
|
559 |
+
"lstrip": false,
|
560 |
+
"normalized": false,
|
561 |
+
"rstrip": false,
|
562 |
+
"single_word": false,
|
563 |
+
"special": true
|
564 |
+
},
|
565 |
+
"126150": {
|
566 |
+
"content": "<|reserved_token_66|>",
|
567 |
+
"lstrip": false,
|
568 |
+
"normalized": false,
|
569 |
+
"rstrip": false,
|
570 |
+
"single_word": false,
|
571 |
+
"special": true
|
572 |
+
},
|
573 |
+
"126151": {
|
574 |
+
"content": "<|reserved_token_67|>",
|
575 |
+
"lstrip": false,
|
576 |
+
"normalized": false,
|
577 |
+
"rstrip": false,
|
578 |
+
"single_word": false,
|
579 |
+
"special": true
|
580 |
+
},
|
581 |
+
"126152": {
|
582 |
+
"content": "<|reserved_token_68|>",
|
583 |
+
"lstrip": false,
|
584 |
+
"normalized": false,
|
585 |
+
"rstrip": false,
|
586 |
+
"single_word": false,
|
587 |
+
"special": true
|
588 |
+
},
|
589 |
+
"126153": {
|
590 |
+
"content": "<|reserved_token_69|>",
|
591 |
+
"lstrip": false,
|
592 |
+
"normalized": false,
|
593 |
+
"rstrip": false,
|
594 |
+
"single_word": false,
|
595 |
+
"special": true
|
596 |
+
},
|
597 |
+
"126154": {
|
598 |
+
"content": "<|reserved_token_70|>",
|
599 |
+
"lstrip": false,
|
600 |
+
"normalized": false,
|
601 |
+
"rstrip": false,
|
602 |
+
"single_word": false,
|
603 |
+
"special": true
|
604 |
+
},
|
605 |
+
"126155": {
|
606 |
+
"content": "<|reserved_token_71|>",
|
607 |
+
"lstrip": false,
|
608 |
+
"normalized": false,
|
609 |
+
"rstrip": false,
|
610 |
+
"single_word": false,
|
611 |
+
"special": true
|
612 |
+
},
|
613 |
+
"126156": {
|
614 |
+
"content": "<|reserved_token_72|>",
|
615 |
+
"lstrip": false,
|
616 |
+
"normalized": false,
|
617 |
+
"rstrip": false,
|
618 |
+
"single_word": false,
|
619 |
+
"special": true
|
620 |
+
},
|
621 |
+
"126157": {
|
622 |
+
"content": "<|reserved_token_73|>",
|
623 |
+
"lstrip": false,
|
624 |
+
"normalized": false,
|
625 |
+
"rstrip": false,
|
626 |
+
"single_word": false,
|
627 |
+
"special": true
|
628 |
+
},
|
629 |
+
"126158": {
|
630 |
+
"content": "<|reserved_token_74|>",
|
631 |
+
"lstrip": false,
|
632 |
+
"normalized": false,
|
633 |
+
"rstrip": false,
|
634 |
+
"single_word": false,
|
635 |
+
"special": true
|
636 |
+
},
|
637 |
+
"126159": {
|
638 |
+
"content": "<|reserved_token_75|>",
|
639 |
+
"lstrip": false,
|
640 |
+
"normalized": false,
|
641 |
+
"rstrip": false,
|
642 |
+
"single_word": false,
|
643 |
+
"special": true
|
644 |
+
},
|
645 |
+
"126160": {
|
646 |
+
"content": "<|reserved_token_76|>",
|
647 |
+
"lstrip": false,
|
648 |
+
"normalized": false,
|
649 |
+
"rstrip": false,
|
650 |
+
"single_word": false,
|
651 |
+
"special": true
|
652 |
+
},
|
653 |
+
"126161": {
|
654 |
+
"content": "<|reserved_token_77|>",
|
655 |
+
"lstrip": false,
|
656 |
+
"normalized": false,
|
657 |
+
"rstrip": false,
|
658 |
+
"single_word": false,
|
659 |
+
"special": true
|
660 |
+
},
|
661 |
+
"126162": {
|
662 |
+
"content": "<|reserved_token_78|>",
|
663 |
+
"lstrip": false,
|
664 |
+
"normalized": false,
|
665 |
+
"rstrip": false,
|
666 |
+
"single_word": false,
|
667 |
+
"special": true
|
668 |
+
},
|
669 |
+
"126163": {
|
670 |
+
"content": "<|reserved_token_79|>",
|
671 |
+
"lstrip": false,
|
672 |
+
"normalized": false,
|
673 |
+
"rstrip": false,
|
674 |
+
"single_word": false,
|
675 |
+
"special": true
|
676 |
+
},
|
677 |
+
"126164": {
|
678 |
+
"content": "<|reserved_token_80|>",
|
679 |
+
"lstrip": false,
|
680 |
+
"normalized": false,
|
681 |
+
"rstrip": false,
|
682 |
+
"single_word": false,
|
683 |
+
"special": true
|
684 |
+
},
|
685 |
+
"126165": {
|
686 |
+
"content": "<|reserved_token_81|>",
|
687 |
+
"lstrip": false,
|
688 |
+
"normalized": false,
|
689 |
+
"rstrip": false,
|
690 |
+
"single_word": false,
|
691 |
+
"special": true
|
692 |
+
},
|
693 |
+
"126166": {
|
694 |
+
"content": "<|reserved_token_82|>",
|
695 |
+
"lstrip": false,
|
696 |
+
"normalized": false,
|
697 |
+
"rstrip": false,
|
698 |
+
"single_word": false,
|
699 |
+
"special": true
|
700 |
+
},
|
701 |
+
"126167": {
|
702 |
+
"content": "<|reserved_token_83|>",
|
703 |
+
"lstrip": false,
|
704 |
+
"normalized": false,
|
705 |
+
"rstrip": false,
|
706 |
+
"single_word": false,
|
707 |
+
"special": true
|
708 |
+
},
|
709 |
+
"126168": {
|
710 |
+
"content": "<|reserved_token_84|>",
|
711 |
+
"lstrip": false,
|
712 |
+
"normalized": false,
|
713 |
+
"rstrip": false,
|
714 |
+
"single_word": false,
|
715 |
+
"special": true
|
716 |
+
},
|
717 |
+
"126169": {
|
718 |
+
"content": "<|reserved_token_85|>",
|
719 |
+
"lstrip": false,
|
720 |
+
"normalized": false,
|
721 |
+
"rstrip": false,
|
722 |
+
"single_word": false,
|
723 |
+
"special": true
|
724 |
+
},
|
725 |
+
"126170": {
|
726 |
+
"content": "<|reserved_token_86|>",
|
727 |
+
"lstrip": false,
|
728 |
+
"normalized": false,
|
729 |
+
"rstrip": false,
|
730 |
+
"single_word": false,
|
731 |
+
"special": true
|
732 |
+
},
|
733 |
+
"126171": {
|
734 |
+
"content": "<|reserved_token_87|>",
|
735 |
+
"lstrip": false,
|
736 |
+
"normalized": false,
|
737 |
+
"rstrip": false,
|
738 |
+
"single_word": false,
|
739 |
+
"special": true
|
740 |
+
},
|
741 |
+
"126172": {
|
742 |
+
"content": "<|reserved_token_88|>",
|
743 |
+
"lstrip": false,
|
744 |
+
"normalized": false,
|
745 |
+
"rstrip": false,
|
746 |
+
"single_word": false,
|
747 |
+
"special": true
|
748 |
+
},
|
749 |
+
"126173": {
|
750 |
+
"content": "<|reserved_token_89|>",
|
751 |
+
"lstrip": false,
|
752 |
+
"normalized": false,
|
753 |
+
"rstrip": false,
|
754 |
+
"single_word": false,
|
755 |
+
"special": true
|
756 |
+
},
|
757 |
+
"126174": {
|
758 |
+
"content": "<|reserved_token_90|>",
|
759 |
+
"lstrip": false,
|
760 |
+
"normalized": false,
|
761 |
+
"rstrip": false,
|
762 |
+
"single_word": false,
|
763 |
+
"special": true
|
764 |
+
},
|
765 |
+
"126175": {
|
766 |
+
"content": "<|reserved_token_91|>",
|
767 |
+
"lstrip": false,
|
768 |
+
"normalized": false,
|
769 |
+
"rstrip": false,
|
770 |
+
"single_word": false,
|
771 |
+
"special": true
|
772 |
+
},
|
773 |
+
"126176": {
|
774 |
+
"content": "<|reserved_token_92|>",
|
775 |
+
"lstrip": false,
|
776 |
+
"normalized": false,
|
777 |
+
"rstrip": false,
|
778 |
+
"single_word": false,
|
779 |
+
"special": true
|
780 |
+
},
|
781 |
+
"126177": {
|
782 |
+
"content": "<|reserved_token_93|>",
|
783 |
+
"lstrip": false,
|
784 |
+
"normalized": false,
|
785 |
+
"rstrip": false,
|
786 |
+
"single_word": false,
|
787 |
+
"special": true
|
788 |
+
},
|
789 |
+
"126178": {
|
790 |
+
"content": "<|reserved_token_94|>",
|
791 |
+
"lstrip": false,
|
792 |
+
"normalized": false,
|
793 |
+
"rstrip": false,
|
794 |
+
"single_word": false,
|
795 |
+
"special": true
|
796 |
+
},
|
797 |
+
"126179": {
|
798 |
+
"content": "<|reserved_token_95|>",
|
799 |
+
"lstrip": false,
|
800 |
+
"normalized": false,
|
801 |
+
"rstrip": false,
|
802 |
+
"single_word": false,
|
803 |
+
"special": true
|
804 |
+
},
|
805 |
+
"126180": {
|
806 |
+
"content": "<|reserved_token_96|>",
|
807 |
+
"lstrip": false,
|
808 |
+
"normalized": false,
|
809 |
+
"rstrip": false,
|
810 |
+
"single_word": false,
|
811 |
+
"special": true
|
812 |
+
},
|
813 |
+
"126181": {
|
814 |
+
"content": "<|reserved_token_97|>",
|
815 |
+
"lstrip": false,
|
816 |
+
"normalized": false,
|
817 |
+
"rstrip": false,
|
818 |
+
"single_word": false,
|
819 |
+
"special": true
|
820 |
+
},
|
821 |
+
"126182": {
|
822 |
+
"content": "<|reserved_token_98|>",
|
823 |
+
"lstrip": false,
|
824 |
+
"normalized": false,
|
825 |
+
"rstrip": false,
|
826 |
+
"single_word": false,
|
827 |
+
"special": true
|
828 |
+
},
|
829 |
+
"126183": {
|
830 |
+
"content": "<|reserved_token_99|>",
|
831 |
+
"lstrip": false,
|
832 |
+
"normalized": false,
|
833 |
+
"rstrip": false,
|
834 |
+
"single_word": false,
|
835 |
+
"special": true
|
836 |
+
},
|
837 |
+
"126184": {
|
838 |
+
"content": "<|reserved_token_100|>",
|
839 |
+
"lstrip": false,
|
840 |
+
"normalized": false,
|
841 |
+
"rstrip": false,
|
842 |
+
"single_word": false,
|
843 |
+
"special": true
|
844 |
+
},
|
845 |
+
"126185": {
|
846 |
+
"content": "<|reserved_token_101|>",
|
847 |
+
"lstrip": false,
|
848 |
+
"normalized": false,
|
849 |
+
"rstrip": false,
|
850 |
+
"single_word": false,
|
851 |
+
"special": true
|
852 |
+
},
|
853 |
+
"126186": {
|
854 |
+
"content": "<|reserved_token_102|>",
|
855 |
+
"lstrip": false,
|
856 |
+
"normalized": false,
|
857 |
+
"rstrip": false,
|
858 |
+
"single_word": false,
|
859 |
+
"special": true
|
860 |
+
},
|
861 |
+
"126187": {
|
862 |
+
"content": "<|reserved_token_103|>",
|
863 |
+
"lstrip": false,
|
864 |
+
"normalized": false,
|
865 |
+
"rstrip": false,
|
866 |
+
"single_word": false,
|
867 |
+
"special": true
|
868 |
+
},
|
869 |
+
"126188": {
|
870 |
+
"content": "<|reserved_token_104|>",
|
871 |
+
"lstrip": false,
|
872 |
+
"normalized": false,
|
873 |
+
"rstrip": false,
|
874 |
+
"single_word": false,
|
875 |
+
"special": true
|
876 |
+
},
|
877 |
+
"126189": {
|
878 |
+
"content": "<|reserved_token_105|>",
|
879 |
+
"lstrip": false,
|
880 |
+
"normalized": false,
|
881 |
+
"rstrip": false,
|
882 |
+
"single_word": false,
|
883 |
+
"special": true
|
884 |
+
},
|
885 |
+
"126190": {
|
886 |
+
"content": "<|reserved_token_106|>",
|
887 |
+
"lstrip": false,
|
888 |
+
"normalized": false,
|
889 |
+
"rstrip": false,
|
890 |
+
"single_word": false,
|
891 |
+
"special": true
|
892 |
+
},
|
893 |
+
"126191": {
|
894 |
+
"content": "<|reserved_token_107|>",
|
895 |
+
"lstrip": false,
|
896 |
+
"normalized": false,
|
897 |
+
"rstrip": false,
|
898 |
+
"single_word": false,
|
899 |
+
"special": true
|
900 |
+
},
|
901 |
+
"126192": {
|
902 |
+
"content": "<|reserved_token_108|>",
|
903 |
+
"lstrip": false,
|
904 |
+
"normalized": false,
|
905 |
+
"rstrip": false,
|
906 |
+
"single_word": false,
|
907 |
+
"special": true
|
908 |
+
},
|
909 |
+
"126193": {
|
910 |
+
"content": "<|reserved_token_109|>",
|
911 |
+
"lstrip": false,
|
912 |
+
"normalized": false,
|
913 |
+
"rstrip": false,
|
914 |
+
"single_word": false,
|
915 |
+
"special": true
|
916 |
+
},
|
917 |
+
"126194": {
|
918 |
+
"content": "<|reserved_token_110|>",
|
919 |
+
"lstrip": false,
|
920 |
+
"normalized": false,
|
921 |
+
"rstrip": false,
|
922 |
+
"single_word": false,
|
923 |
+
"special": true
|
924 |
+
},
|
925 |
+
"126195": {
|
926 |
+
"content": "<|reserved_token_111|>",
|
927 |
+
"lstrip": false,
|
928 |
+
"normalized": false,
|
929 |
+
"rstrip": false,
|
930 |
+
"single_word": false,
|
931 |
+
"special": true
|
932 |
+
},
|
933 |
+
"126196": {
|
934 |
+
"content": "<|reserved_token_112|>",
|
935 |
+
"lstrip": false,
|
936 |
+
"normalized": false,
|
937 |
+
"rstrip": false,
|
938 |
+
"single_word": false,
|
939 |
+
"special": true
|
940 |
+
},
|
941 |
+
"126197": {
|
942 |
+
"content": "<|reserved_token_113|>",
|
943 |
+
"lstrip": false,
|
944 |
+
"normalized": false,
|
945 |
+
"rstrip": false,
|
946 |
+
"single_word": false,
|
947 |
+
"special": true
|
948 |
+
},
|
949 |
+
"126198": {
|
950 |
+
"content": "<|reserved_token_114|>",
|
951 |
+
"lstrip": false,
|
952 |
+
"normalized": false,
|
953 |
+
"rstrip": false,
|
954 |
+
"single_word": false,
|
955 |
+
"special": true
|
956 |
+
},
|
957 |
+
"126199": {
|
958 |
+
"content": "<|reserved_token_115|>",
|
959 |
+
"lstrip": false,
|
960 |
+
"normalized": false,
|
961 |
+
"rstrip": false,
|
962 |
+
"single_word": false,
|
963 |
+
"special": true
|
964 |
+
},
|
965 |
+
"126200": {
|
966 |
+
"content": "<|reserved_token_116|>",
|
967 |
+
"lstrip": false,
|
968 |
+
"normalized": false,
|
969 |
+
"rstrip": false,
|
970 |
+
"single_word": false,
|
971 |
+
"special": true
|
972 |
+
},
|
973 |
+
"126201": {
|
974 |
+
"content": "<|reserved_token_117|>",
|
975 |
+
"lstrip": false,
|
976 |
+
"normalized": false,
|
977 |
+
"rstrip": false,
|
978 |
+
"single_word": false,
|
979 |
+
"special": true
|
980 |
+
},
|
981 |
+
"126202": {
|
982 |
+
"content": "<|reserved_token_118|>",
|
983 |
+
"lstrip": false,
|
984 |
+
"normalized": false,
|
985 |
+
"rstrip": false,
|
986 |
+
"single_word": false,
|
987 |
+
"special": true
|
988 |
+
},
|
989 |
+
"126203": {
|
990 |
+
"content": "<|reserved_token_119|>",
|
991 |
+
"lstrip": false,
|
992 |
+
"normalized": false,
|
993 |
+
"rstrip": false,
|
994 |
+
"single_word": false,
|
995 |
+
"special": true
|
996 |
+
},
|
997 |
+
"126204": {
|
998 |
+
"content": "<|reserved_token_120|>",
|
999 |
+
"lstrip": false,
|
1000 |
+
"normalized": false,
|
1001 |
+
"rstrip": false,
|
1002 |
+
"single_word": false,
|
1003 |
+
"special": true
|
1004 |
+
},
|
1005 |
+
"126205": {
|
1006 |
+
"content": "<|reserved_token_121|>",
|
1007 |
+
"lstrip": false,
|
1008 |
+
"normalized": false,
|
1009 |
+
"rstrip": false,
|
1010 |
+
"single_word": false,
|
1011 |
+
"special": true
|
1012 |
+
},
|
1013 |
+
"126206": {
|
1014 |
+
"content": "<|reserved_token_122|>",
|
1015 |
+
"lstrip": false,
|
1016 |
+
"normalized": false,
|
1017 |
+
"rstrip": false,
|
1018 |
+
"single_word": false,
|
1019 |
+
"special": true
|
1020 |
+
},
|
1021 |
+
"126207": {
|
1022 |
+
"content": "<|reserved_token_123|>",
|
1023 |
+
"lstrip": false,
|
1024 |
+
"normalized": false,
|
1025 |
+
"rstrip": false,
|
1026 |
+
"single_word": false,
|
1027 |
+
"special": true
|
1028 |
+
},
|
1029 |
+
"126208": {
|
1030 |
+
"content": "<|reserved_token_124|>",
|
1031 |
+
"lstrip": false,
|
1032 |
+
"normalized": false,
|
1033 |
+
"rstrip": false,
|
1034 |
+
"single_word": false,
|
1035 |
+
"special": true
|
1036 |
+
},
|
1037 |
+
"126209": {
|
1038 |
+
"content": "<|reserved_token_125|>",
|
1039 |
+
"lstrip": false,
|
1040 |
+
"normalized": false,
|
1041 |
+
"rstrip": false,
|
1042 |
+
"single_word": false,
|
1043 |
+
"special": true
|
1044 |
+
},
|
1045 |
+
"126210": {
|
1046 |
+
"content": "<|reserved_token_126|>",
|
1047 |
+
"lstrip": false,
|
1048 |
+
"normalized": false,
|
1049 |
+
"rstrip": false,
|
1050 |
+
"single_word": false,
|
1051 |
+
"special": true
|
1052 |
+
},
|
1053 |
+
"126211": {
|
1054 |
+
"content": "<|reserved_token_127|>",
|
1055 |
+
"lstrip": false,
|
1056 |
+
"normalized": false,
|
1057 |
+
"rstrip": false,
|
1058 |
+
"single_word": false,
|
1059 |
+
"special": true
|
1060 |
+
},
|
1061 |
+
"126212": {
|
1062 |
+
"content": "<|reserved_token_128|>",
|
1063 |
+
"lstrip": false,
|
1064 |
+
"normalized": false,
|
1065 |
+
"rstrip": false,
|
1066 |
+
"single_word": false,
|
1067 |
+
"special": true
|
1068 |
+
},
|
1069 |
+
"126213": {
|
1070 |
+
"content": "<|reserved_token_129|>",
|
1071 |
+
"lstrip": false,
|
1072 |
+
"normalized": false,
|
1073 |
+
"rstrip": false,
|
1074 |
+
"single_word": false,
|
1075 |
+
"special": true
|
1076 |
+
},
|
1077 |
+
"126214": {
|
1078 |
+
"content": "<|reserved_token_130|>",
|
1079 |
+
"lstrip": false,
|
1080 |
+
"normalized": false,
|
1081 |
+
"rstrip": false,
|
1082 |
+
"single_word": false,
|
1083 |
+
"special": true
|
1084 |
+
},
|
1085 |
+
"126215": {
|
1086 |
+
"content": "<|reserved_token_131|>",
|
1087 |
+
"lstrip": false,
|
1088 |
+
"normalized": false,
|
1089 |
+
"rstrip": false,
|
1090 |
+
"single_word": false,
|
1091 |
+
"special": true
|
1092 |
+
},
|
1093 |
+
"126216": {
|
1094 |
+
"content": "<|reserved_token_132|>",
|
1095 |
+
"lstrip": false,
|
1096 |
+
"normalized": false,
|
1097 |
+
"rstrip": false,
|
1098 |
+
"single_word": false,
|
1099 |
+
"special": true
|
1100 |
+
},
|
1101 |
+
"126217": {
|
1102 |
+
"content": "<|reserved_token_133|>",
|
1103 |
+
"lstrip": false,
|
1104 |
+
"normalized": false,
|
1105 |
+
"rstrip": false,
|
1106 |
+
"single_word": false,
|
1107 |
+
"special": true
|
1108 |
+
},
|
1109 |
+
"126218": {
|
1110 |
+
"content": "<|reserved_token_134|>",
|
1111 |
+
"lstrip": false,
|
1112 |
+
"normalized": false,
|
1113 |
+
"rstrip": false,
|
1114 |
+
"single_word": false,
|
1115 |
+
"special": true
|
1116 |
+
},
|
1117 |
+
"126219": {
|
1118 |
+
"content": "<|reserved_token_135|>",
|
1119 |
+
"lstrip": false,
|
1120 |
+
"normalized": false,
|
1121 |
+
"rstrip": false,
|
1122 |
+
"single_word": false,
|
1123 |
+
"special": true
|
1124 |
+
},
|
1125 |
+
"126220": {
|
1126 |
+
"content": "<|reserved_token_136|>",
|
1127 |
+
"lstrip": false,
|
1128 |
+
"normalized": false,
|
1129 |
+
"rstrip": false,
|
1130 |
+
"single_word": false,
|
1131 |
+
"special": true
|
1132 |
+
},
|
1133 |
+
"126221": {
|
1134 |
+
"content": "<|reserved_token_137|>",
|
1135 |
+
"lstrip": false,
|
1136 |
+
"normalized": false,
|
1137 |
+
"rstrip": false,
|
1138 |
+
"single_word": false,
|
1139 |
+
"special": true
|
1140 |
+
},
|
1141 |
+
"126222": {
|
1142 |
+
"content": "<|reserved_token_138|>",
|
1143 |
+
"lstrip": false,
|
1144 |
+
"normalized": false,
|
1145 |
+
"rstrip": false,
|
1146 |
+
"single_word": false,
|
1147 |
+
"special": true
|
1148 |
+
},
|
1149 |
+
"126223": {
|
1150 |
+
"content": "<|reserved_token_139|>",
|
1151 |
+
"lstrip": false,
|
1152 |
+
"normalized": false,
|
1153 |
+
"rstrip": false,
|
1154 |
+
"single_word": false,
|
1155 |
+
"special": true
|
1156 |
+
},
|
1157 |
+
"126224": {
|
1158 |
+
"content": "<|reserved_token_140|>",
|
1159 |
+
"lstrip": false,
|
1160 |
+
"normalized": false,
|
1161 |
+
"rstrip": false,
|
1162 |
+
"single_word": false,
|
1163 |
+
"special": true
|
1164 |
+
},
|
1165 |
+
"126225": {
|
1166 |
+
"content": "<|reserved_token_141|>",
|
1167 |
+
"lstrip": false,
|
1168 |
+
"normalized": false,
|
1169 |
+
"rstrip": false,
|
1170 |
+
"single_word": false,
|
1171 |
+
"special": true
|
1172 |
+
},
|
1173 |
+
"126226": {
|
1174 |
+
"content": "<|reserved_token_142|>",
|
1175 |
+
"lstrip": false,
|
1176 |
+
"normalized": false,
|
1177 |
+
"rstrip": false,
|
1178 |
+
"single_word": false,
|
1179 |
+
"special": true
|
1180 |
+
},
|
1181 |
+
"126227": {
|
1182 |
+
"content": "<|reserved_token_143|>",
|
1183 |
+
"lstrip": false,
|
1184 |
+
"normalized": false,
|
1185 |
+
"rstrip": false,
|
1186 |
+
"single_word": false,
|
1187 |
+
"special": true
|
1188 |
+
},
|
1189 |
+
"126228": {
|
1190 |
+
"content": "<|reserved_token_144|>",
|
1191 |
+
"lstrip": false,
|
1192 |
+
"normalized": false,
|
1193 |
+
"rstrip": false,
|
1194 |
+
"single_word": false,
|
1195 |
+
"special": true
|
1196 |
+
},
|
1197 |
+
"126229": {
|
1198 |
+
"content": "<|reserved_token_145|>",
|
1199 |
+
"lstrip": false,
|
1200 |
+
"normalized": false,
|
1201 |
+
"rstrip": false,
|
1202 |
+
"single_word": false,
|
1203 |
+
"special": true
|
1204 |
+
},
|
1205 |
+
"126230": {
|
1206 |
+
"content": "<|reserved_token_146|>",
|
1207 |
+
"lstrip": false,
|
1208 |
+
"normalized": false,
|
1209 |
+
"rstrip": false,
|
1210 |
+
"single_word": false,
|
1211 |
+
"special": true
|
1212 |
+
},
|
1213 |
+
"126231": {
|
1214 |
+
"content": "<|reserved_token_147|>",
|
1215 |
+
"lstrip": false,
|
1216 |
+
"normalized": false,
|
1217 |
+
"rstrip": false,
|
1218 |
+
"single_word": false,
|
1219 |
+
"special": true
|
1220 |
+
},
|
1221 |
+
"126232": {
|
1222 |
+
"content": "<|reserved_token_148|>",
|
1223 |
+
"lstrip": false,
|
1224 |
+
"normalized": false,
|
1225 |
+
"rstrip": false,
|
1226 |
+
"single_word": false,
|
1227 |
+
"special": true
|
1228 |
+
},
|
1229 |
+
"126233": {
|
1230 |
+
"content": "<|reserved_token_149|>",
|
1231 |
+
"lstrip": false,
|
1232 |
+
"normalized": false,
|
1233 |
+
"rstrip": false,
|
1234 |
+
"single_word": false,
|
1235 |
+
"special": true
|
1236 |
+
},
|
1237 |
+
"126234": {
|
1238 |
+
"content": "<|reserved_token_150|>",
|
1239 |
+
"lstrip": false,
|
1240 |
+
"normalized": false,
|
1241 |
+
"rstrip": false,
|
1242 |
+
"single_word": false,
|
1243 |
+
"special": true
|
1244 |
+
},
|
1245 |
+
"126235": {
|
1246 |
+
"content": "<|reserved_token_151|>",
|
1247 |
+
"lstrip": false,
|
1248 |
+
"normalized": false,
|
1249 |
+
"rstrip": false,
|
1250 |
+
"single_word": false,
|
1251 |
+
"special": true
|
1252 |
+
},
|
1253 |
+
"126236": {
|
1254 |
+
"content": "<|reserved_token_152|>",
|
1255 |
+
"lstrip": false,
|
1256 |
+
"normalized": false,
|
1257 |
+
"rstrip": false,
|
1258 |
+
"single_word": false,
|
1259 |
+
"special": true
|
1260 |
+
},
|
1261 |
+
"126237": {
|
1262 |
+
"content": "<|reserved_token_153|>",
|
1263 |
+
"lstrip": false,
|
1264 |
+
"normalized": false,
|
1265 |
+
"rstrip": false,
|
1266 |
+
"single_word": false,
|
1267 |
+
"special": true
|
1268 |
+
},
|
1269 |
+
"126238": {
|
1270 |
+
"content": "<|reserved_token_154|>",
|
1271 |
+
"lstrip": false,
|
1272 |
+
"normalized": false,
|
1273 |
+
"rstrip": false,
|
1274 |
+
"single_word": false,
|
1275 |
+
"special": true
|
1276 |
+
},
|
1277 |
+
"126239": {
|
1278 |
+
"content": "<|reserved_token_155|>",
|
1279 |
+
"lstrip": false,
|
1280 |
+
"normalized": false,
|
1281 |
+
"rstrip": false,
|
1282 |
+
"single_word": false,
|
1283 |
+
"special": true
|
1284 |
+
},
|
1285 |
+
"126240": {
|
1286 |
+
"content": "<|reserved_token_156|>",
|
1287 |
+
"lstrip": false,
|
1288 |
+
"normalized": false,
|
1289 |
+
"rstrip": false,
|
1290 |
+
"single_word": false,
|
1291 |
+
"special": true
|
1292 |
+
},
|
1293 |
+
"126241": {
|
1294 |
+
"content": "<|reserved_token_157|>",
|
1295 |
+
"lstrip": false,
|
1296 |
+
"normalized": false,
|
1297 |
+
"rstrip": false,
|
1298 |
+
"single_word": false,
|
1299 |
+
"special": true
|
1300 |
+
},
|
1301 |
+
"126242": {
|
1302 |
+
"content": "<|reserved_token_158|>",
|
1303 |
+
"lstrip": false,
|
1304 |
+
"normalized": false,
|
1305 |
+
"rstrip": false,
|
1306 |
+
"single_word": false,
|
1307 |
+
"special": true
|
1308 |
+
},
|
1309 |
+
"126243": {
|
1310 |
+
"content": "<|reserved_token_159|>",
|
1311 |
+
"lstrip": false,
|
1312 |
+
"normalized": false,
|
1313 |
+
"rstrip": false,
|
1314 |
+
"single_word": false,
|
1315 |
+
"special": true
|
1316 |
+
},
|
1317 |
+
"126244": {
|
1318 |
+
"content": "<|reserved_token_160|>",
|
1319 |
+
"lstrip": false,
|
1320 |
+
"normalized": false,
|
1321 |
+
"rstrip": false,
|
1322 |
+
"single_word": false,
|
1323 |
+
"special": true
|
1324 |
+
},
|
1325 |
+
"126245": {
|
1326 |
+
"content": "<|reserved_token_161|>",
|
1327 |
+
"lstrip": false,
|
1328 |
+
"normalized": false,
|
1329 |
+
"rstrip": false,
|
1330 |
+
"single_word": false,
|
1331 |
+
"special": true
|
1332 |
+
},
|
1333 |
+
"126246": {
|
1334 |
+
"content": "<|reserved_token_162|>",
|
1335 |
+
"lstrip": false,
|
1336 |
+
"normalized": false,
|
1337 |
+
"rstrip": false,
|
1338 |
+
"single_word": false,
|
1339 |
+
"special": true
|
1340 |
+
},
|
1341 |
+
"126247": {
|
1342 |
+
"content": "<|reserved_token_163|>",
|
1343 |
+
"lstrip": false,
|
1344 |
+
"normalized": false,
|
1345 |
+
"rstrip": false,
|
1346 |
+
"single_word": false,
|
1347 |
+
"special": true
|
1348 |
+
},
|
1349 |
+
"126248": {
|
1350 |
+
"content": "<|reserved_token_164|>",
|
1351 |
+
"lstrip": false,
|
1352 |
+
"normalized": false,
|
1353 |
+
"rstrip": false,
|
1354 |
+
"single_word": false,
|
1355 |
+
"special": true
|
1356 |
+
},
|
1357 |
+
"126249": {
|
1358 |
+
"content": "<|reserved_token_165|>",
|
1359 |
+
"lstrip": false,
|
1360 |
+
"normalized": false,
|
1361 |
+
"rstrip": false,
|
1362 |
+
"single_word": false,
|
1363 |
+
"special": true
|
1364 |
+
},
|
1365 |
+
"126250": {
|
1366 |
+
"content": "<|reserved_token_166|>",
|
1367 |
+
"lstrip": false,
|
1368 |
+
"normalized": false,
|
1369 |
+
"rstrip": false,
|
1370 |
+
"single_word": false,
|
1371 |
+
"special": true
|
1372 |
+
},
|
1373 |
+
"126251": {
|
1374 |
+
"content": "<|reserved_token_167|>",
|
1375 |
+
"lstrip": false,
|
1376 |
+
"normalized": false,
|
1377 |
+
"rstrip": false,
|
1378 |
+
"single_word": false,
|
1379 |
+
"special": true
|
1380 |
+
},
|
1381 |
+
"126252": {
|
1382 |
+
"content": "<|reserved_token_168|>",
|
1383 |
+
"lstrip": false,
|
1384 |
+
"normalized": false,
|
1385 |
+
"rstrip": false,
|
1386 |
+
"single_word": false,
|
1387 |
+
"special": true
|
1388 |
+
},
|
1389 |
+
"126253": {
|
1390 |
+
"content": "<|reserved_token_169|>",
|
1391 |
+
"lstrip": false,
|
1392 |
+
"normalized": false,
|
1393 |
+
"rstrip": false,
|
1394 |
+
"single_word": false,
|
1395 |
+
"special": true
|
1396 |
+
},
|
1397 |
+
"126254": {
|
1398 |
+
"content": "<|reserved_token_170|>",
|
1399 |
+
"lstrip": false,
|
1400 |
+
"normalized": false,
|
1401 |
+
"rstrip": false,
|
1402 |
+
"single_word": false,
|
1403 |
+
"special": true
|
1404 |
+
},
|
1405 |
+
"126255": {
|
1406 |
+
"content": "<|reserved_token_171|>",
|
1407 |
+
"lstrip": false,
|
1408 |
+
"normalized": false,
|
1409 |
+
"rstrip": false,
|
1410 |
+
"single_word": false,
|
1411 |
+
"special": true
|
1412 |
+
},
|
1413 |
+
"126256": {
|
1414 |
+
"content": "<|reserved_token_172|>",
|
1415 |
+
"lstrip": false,
|
1416 |
+
"normalized": false,
|
1417 |
+
"rstrip": false,
|
1418 |
+
"single_word": false,
|
1419 |
+
"special": true
|
1420 |
+
},
|
1421 |
+
"126257": {
|
1422 |
+
"content": "<|reserved_token_173|>",
|
1423 |
+
"lstrip": false,
|
1424 |
+
"normalized": false,
|
1425 |
+
"rstrip": false,
|
1426 |
+
"single_word": false,
|
1427 |
+
"special": true
|
1428 |
+
},
|
1429 |
+
"126258": {
|
1430 |
+
"content": "<|reserved_token_174|>",
|
1431 |
+
"lstrip": false,
|
1432 |
+
"normalized": false,
|
1433 |
+
"rstrip": false,
|
1434 |
+
"single_word": false,
|
1435 |
+
"special": true
|
1436 |
+
},
|
1437 |
+
"126259": {
|
1438 |
+
"content": "<|reserved_token_175|>",
|
1439 |
+
"lstrip": false,
|
1440 |
+
"normalized": false,
|
1441 |
+
"rstrip": false,
|
1442 |
+
"single_word": false,
|
1443 |
+
"special": true
|
1444 |
+
},
|
1445 |
+
"126260": {
|
1446 |
+
"content": "<|reserved_token_176|>",
|
1447 |
+
"lstrip": false,
|
1448 |
+
"normalized": false,
|
1449 |
+
"rstrip": false,
|
1450 |
+
"single_word": false,
|
1451 |
+
"special": true
|
1452 |
+
},
|
1453 |
+
"126261": {
|
1454 |
+
"content": "<|reserved_token_177|>",
|
1455 |
+
"lstrip": false,
|
1456 |
+
"normalized": false,
|
1457 |
+
"rstrip": false,
|
1458 |
+
"single_word": false,
|
1459 |
+
"special": true
|
1460 |
+
},
|
1461 |
+
"126262": {
|
1462 |
+
"content": "<|reserved_token_178|>",
|
1463 |
+
"lstrip": false,
|
1464 |
+
"normalized": false,
|
1465 |
+
"rstrip": false,
|
1466 |
+
"single_word": false,
|
1467 |
+
"special": true
|
1468 |
+
},
|
1469 |
+
"126263": {
|
1470 |
+
"content": "<|reserved_token_179|>",
|
1471 |
+
"lstrip": false,
|
1472 |
+
"normalized": false,
|
1473 |
+
"rstrip": false,
|
1474 |
+
"single_word": false,
|
1475 |
+
"special": true
|
1476 |
+
},
|
1477 |
+
"126264": {
|
1478 |
+
"content": "<|reserved_token_180|>",
|
1479 |
+
"lstrip": false,
|
1480 |
+
"normalized": false,
|
1481 |
+
"rstrip": false,
|
1482 |
+
"single_word": false,
|
1483 |
+
"special": true
|
1484 |
+
},
|
1485 |
+
"126265": {
|
1486 |
+
"content": "<|reserved_token_181|>",
|
1487 |
+
"lstrip": false,
|
1488 |
+
"normalized": false,
|
1489 |
+
"rstrip": false,
|
1490 |
+
"single_word": false,
|
1491 |
+
"special": true
|
1492 |
+
},
|
1493 |
+
"126266": {
|
1494 |
+
"content": "<|reserved_token_182|>",
|
1495 |
+
"lstrip": false,
|
1496 |
+
"normalized": false,
|
1497 |
+
"rstrip": false,
|
1498 |
+
"single_word": false,
|
1499 |
+
"special": true
|
1500 |
+
},
|
1501 |
+
"126267": {
|
1502 |
+
"content": "<|reserved_token_183|>",
|
1503 |
+
"lstrip": false,
|
1504 |
+
"normalized": false,
|
1505 |
+
"rstrip": false,
|
1506 |
+
"single_word": false,
|
1507 |
+
"special": true
|
1508 |
+
},
|
1509 |
+
"126268": {
|
1510 |
+
"content": "<|reserved_token_184|>",
|
1511 |
+
"lstrip": false,
|
1512 |
+
"normalized": false,
|
1513 |
+
"rstrip": false,
|
1514 |
+
"single_word": false,
|
1515 |
+
"special": true
|
1516 |
+
},
|
1517 |
+
"126269": {
|
1518 |
+
"content": "<|reserved_token_185|>",
|
1519 |
+
"lstrip": false,
|
1520 |
+
"normalized": false,
|
1521 |
+
"rstrip": false,
|
1522 |
+
"single_word": false,
|
1523 |
+
"special": true
|
1524 |
+
},
|
1525 |
+
"126270": {
|
1526 |
+
"content": "<|reserved_token_186|>",
|
1527 |
+
"lstrip": false,
|
1528 |
+
"normalized": false,
|
1529 |
+
"rstrip": false,
|
1530 |
+
"single_word": false,
|
1531 |
+
"special": true
|
1532 |
+
},
|
1533 |
+
"126271": {
|
1534 |
+
"content": "<|reserved_token_187|>",
|
1535 |
+
"lstrip": false,
|
1536 |
+
"normalized": false,
|
1537 |
+
"rstrip": false,
|
1538 |
+
"single_word": false,
|
1539 |
+
"special": true
|
1540 |
+
},
|
1541 |
+
"126272": {
|
1542 |
+
"content": "<|reserved_token_188|>",
|
1543 |
+
"lstrip": false,
|
1544 |
+
"normalized": false,
|
1545 |
+
"rstrip": false,
|
1546 |
+
"single_word": false,
|
1547 |
+
"special": true
|
1548 |
+
},
|
1549 |
+
"126273": {
|
1550 |
+
"content": "<|reserved_token_189|>",
|
1551 |
+
"lstrip": false,
|
1552 |
+
"normalized": false,
|
1553 |
+
"rstrip": false,
|
1554 |
+
"single_word": false,
|
1555 |
+
"special": true
|
1556 |
+
},
|
1557 |
+
"126274": {
|
1558 |
+
"content": "<|reserved_token_190|>",
|
1559 |
+
"lstrip": false,
|
1560 |
+
"normalized": false,
|
1561 |
+
"rstrip": false,
|
1562 |
+
"single_word": false,
|
1563 |
+
"special": true
|
1564 |
+
},
|
1565 |
+
"126275": {
|
1566 |
+
"content": "<|reserved_token_191|>",
|
1567 |
+
"lstrip": false,
|
1568 |
+
"normalized": false,
|
1569 |
+
"rstrip": false,
|
1570 |
+
"single_word": false,
|
1571 |
+
"special": true
|
1572 |
+
},
|
1573 |
+
"126276": {
|
1574 |
+
"content": "<|reserved_token_192|>",
|
1575 |
+
"lstrip": false,
|
1576 |
+
"normalized": false,
|
1577 |
+
"rstrip": false,
|
1578 |
+
"single_word": false,
|
1579 |
+
"special": true
|
1580 |
+
},
|
1581 |
+
"126277": {
|
1582 |
+
"content": "<|reserved_token_193|>",
|
1583 |
+
"lstrip": false,
|
1584 |
+
"normalized": false,
|
1585 |
+
"rstrip": false,
|
1586 |
+
"single_word": false,
|
1587 |
+
"special": true
|
1588 |
+
},
|
1589 |
+
"126278": {
|
1590 |
+
"content": "<|reserved_token_194|>",
|
1591 |
+
"lstrip": false,
|
1592 |
+
"normalized": false,
|
1593 |
+
"rstrip": false,
|
1594 |
+
"single_word": false,
|
1595 |
+
"special": true
|
1596 |
+
},
|
1597 |
+
"126279": {
|
1598 |
+
"content": "<|reserved_token_195|>",
|
1599 |
+
"lstrip": false,
|
1600 |
+
"normalized": false,
|
1601 |
+
"rstrip": false,
|
1602 |
+
"single_word": false,
|
1603 |
+
"special": true
|
1604 |
+
},
|
1605 |
+
"126280": {
|
1606 |
+
"content": "<|reserved_token_196|>",
|
1607 |
+
"lstrip": false,
|
1608 |
+
"normalized": false,
|
1609 |
+
"rstrip": false,
|
1610 |
+
"single_word": false,
|
1611 |
+
"special": true
|
1612 |
+
},
|
1613 |
+
"126281": {
|
1614 |
+
"content": "<|reserved_token_197|>",
|
1615 |
+
"lstrip": false,
|
1616 |
+
"normalized": false,
|
1617 |
+
"rstrip": false,
|
1618 |
+
"single_word": false,
|
1619 |
+
"special": true
|
1620 |
+
},
|
1621 |
+
"126282": {
|
1622 |
+
"content": "<|reserved_token_198|>",
|
1623 |
+
"lstrip": false,
|
1624 |
+
"normalized": false,
|
1625 |
+
"rstrip": false,
|
1626 |
+
"single_word": false,
|
1627 |
+
"special": true
|
1628 |
+
},
|
1629 |
+
"126283": {
|
1630 |
+
"content": "<|reserved_token_199|>",
|
1631 |
+
"lstrip": false,
|
1632 |
+
"normalized": false,
|
1633 |
+
"rstrip": false,
|
1634 |
+
"single_word": false,
|
1635 |
+
"special": true
|
1636 |
+
},
|
1637 |
+
"126284": {
|
1638 |
+
"content": "<|reserved_token_200|>",
|
1639 |
+
"lstrip": false,
|
1640 |
+
"normalized": false,
|
1641 |
+
"rstrip": false,
|
1642 |
+
"single_word": false,
|
1643 |
+
"special": true
|
1644 |
+
},
|
1645 |
+
"126285": {
|
1646 |
+
"content": "<|reserved_token_201|>",
|
1647 |
+
"lstrip": false,
|
1648 |
+
"normalized": false,
|
1649 |
+
"rstrip": false,
|
1650 |
+
"single_word": false,
|
1651 |
+
"special": true
|
1652 |
+
},
|
1653 |
+
"126286": {
|
1654 |
+
"content": "<|reserved_token_202|>",
|
1655 |
+
"lstrip": false,
|
1656 |
+
"normalized": false,
|
1657 |
+
"rstrip": false,
|
1658 |
+
"single_word": false,
|
1659 |
+
"special": true
|
1660 |
+
},
|
1661 |
+
"126287": {
|
1662 |
+
"content": "<|reserved_token_203|>",
|
1663 |
+
"lstrip": false,
|
1664 |
+
"normalized": false,
|
1665 |
+
"rstrip": false,
|
1666 |
+
"single_word": false,
|
1667 |
+
"special": true
|
1668 |
+
},
|
1669 |
+
"126288": {
|
1670 |
+
"content": "<|reserved_token_204|>",
|
1671 |
+
"lstrip": false,
|
1672 |
+
"normalized": false,
|
1673 |
+
"rstrip": false,
|
1674 |
+
"single_word": false,
|
1675 |
+
"special": true
|
1676 |
+
},
|
1677 |
+
"126289": {
|
1678 |
+
"content": "<|reserved_token_205|>",
|
1679 |
+
"lstrip": false,
|
1680 |
+
"normalized": false,
|
1681 |
+
"rstrip": false,
|
1682 |
+
"single_word": false,
|
1683 |
+
"special": true
|
1684 |
+
},
|
1685 |
+
"126290": {
|
1686 |
+
"content": "<|reserved_token_206|>",
|
1687 |
+
"lstrip": false,
|
1688 |
+
"normalized": false,
|
1689 |
+
"rstrip": false,
|
1690 |
+
"single_word": false,
|
1691 |
+
"special": true
|
1692 |
+
},
|
1693 |
+
"126291": {
|
1694 |
+
"content": "<|reserved_token_207|>",
|
1695 |
+
"lstrip": false,
|
1696 |
+
"normalized": false,
|
1697 |
+
"rstrip": false,
|
1698 |
+
"single_word": false,
|
1699 |
+
"special": true
|
1700 |
+
},
|
1701 |
+
"126292": {
|
1702 |
+
"content": "<|reserved_token_208|>",
|
1703 |
+
"lstrip": false,
|
1704 |
+
"normalized": false,
|
1705 |
+
"rstrip": false,
|
1706 |
+
"single_word": false,
|
1707 |
+
"special": true
|
1708 |
+
},
|
1709 |
+
"126293": {
|
1710 |
+
"content": "<|reserved_token_209|>",
|
1711 |
+
"lstrip": false,
|
1712 |
+
"normalized": false,
|
1713 |
+
"rstrip": false,
|
1714 |
+
"single_word": false,
|
1715 |
+
"special": true
|
1716 |
+
},
|
1717 |
+
"126294": {
|
1718 |
+
"content": "<|reserved_token_210|>",
|
1719 |
+
"lstrip": false,
|
1720 |
+
"normalized": false,
|
1721 |
+
"rstrip": false,
|
1722 |
+
"single_word": false,
|
1723 |
+
"special": true
|
1724 |
+
},
|
1725 |
+
"126295": {
|
1726 |
+
"content": "<|reserved_token_211|>",
|
1727 |
+
"lstrip": false,
|
1728 |
+
"normalized": false,
|
1729 |
+
"rstrip": false,
|
1730 |
+
"single_word": false,
|
1731 |
+
"special": true
|
1732 |
+
},
|
1733 |
+
"126296": {
|
1734 |
+
"content": "<|reserved_token_212|>",
|
1735 |
+
"lstrip": false,
|
1736 |
+
"normalized": false,
|
1737 |
+
"rstrip": false,
|
1738 |
+
"single_word": false,
|
1739 |
+
"special": true
|
1740 |
+
},
|
1741 |
+
"126297": {
|
1742 |
+
"content": "<|reserved_token_213|>",
|
1743 |
+
"lstrip": false,
|
1744 |
+
"normalized": false,
|
1745 |
+
"rstrip": false,
|
1746 |
+
"single_word": false,
|
1747 |
+
"special": true
|
1748 |
+
},
|
1749 |
+
"126298": {
|
1750 |
+
"content": "<|reserved_token_214|>",
|
1751 |
+
"lstrip": false,
|
1752 |
+
"normalized": false,
|
1753 |
+
"rstrip": false,
|
1754 |
+
"single_word": false,
|
1755 |
+
"special": true
|
1756 |
+
},
|
1757 |
+
"126299": {
|
1758 |
+
"content": "<|reserved_token_215|>",
|
1759 |
+
"lstrip": false,
|
1760 |
+
"normalized": false,
|
1761 |
+
"rstrip": false,
|
1762 |
+
"single_word": false,
|
1763 |
+
"special": true
|
1764 |
+
},
|
1765 |
+
"126300": {
|
1766 |
+
"content": "<|reserved_token_216|>",
|
1767 |
+
"lstrip": false,
|
1768 |
+
"normalized": false,
|
1769 |
+
"rstrip": false,
|
1770 |
+
"single_word": false,
|
1771 |
+
"special": true
|
1772 |
+
},
|
1773 |
+
"126301": {
|
1774 |
+
"content": "<|reserved_token_217|>",
|
1775 |
+
"lstrip": false,
|
1776 |
+
"normalized": false,
|
1777 |
+
"rstrip": false,
|
1778 |
+
"single_word": false,
|
1779 |
+
"special": true
|
1780 |
+
},
|
1781 |
+
"126302": {
|
1782 |
+
"content": "<|reserved_token_218|>",
|
1783 |
+
"lstrip": false,
|
1784 |
+
"normalized": false,
|
1785 |
+
"rstrip": false,
|
1786 |
+
"single_word": false,
|
1787 |
+
"special": true
|
1788 |
+
},
|
1789 |
+
"126303": {
|
1790 |
+
"content": "<|reserved_token_219|>",
|
1791 |
+
"lstrip": false,
|
1792 |
+
"normalized": false,
|
1793 |
+
"rstrip": false,
|
1794 |
+
"single_word": false,
|
1795 |
+
"special": true
|
1796 |
+
},
|
1797 |
+
"126304": {
|
1798 |
+
"content": "<|reserved_token_220|>",
|
1799 |
+
"lstrip": false,
|
1800 |
+
"normalized": false,
|
1801 |
+
"rstrip": false,
|
1802 |
+
"single_word": false,
|
1803 |
+
"special": true
|
1804 |
+
},
|
1805 |
+
"126305": {
|
1806 |
+
"content": "<|reserved_token_221|>",
|
1807 |
+
"lstrip": false,
|
1808 |
+
"normalized": false,
|
1809 |
+
"rstrip": false,
|
1810 |
+
"single_word": false,
|
1811 |
+
"special": true
|
1812 |
+
},
|
1813 |
+
"126306": {
|
1814 |
+
"content": "<|reserved_token_222|>",
|
1815 |
+
"lstrip": false,
|
1816 |
+
"normalized": false,
|
1817 |
+
"rstrip": false,
|
1818 |
+
"single_word": false,
|
1819 |
+
"special": true
|
1820 |
+
},
|
1821 |
+
"126307": {
|
1822 |
+
"content": "<|reserved_token_223|>",
|
1823 |
+
"lstrip": false,
|
1824 |
+
"normalized": false,
|
1825 |
+
"rstrip": false,
|
1826 |
+
"single_word": false,
|
1827 |
+
"special": true
|
1828 |
+
},
|
1829 |
+
"126308": {
|
1830 |
+
"content": "<|reserved_token_224|>",
|
1831 |
+
"lstrip": false,
|
1832 |
+
"normalized": false,
|
1833 |
+
"rstrip": false,
|
1834 |
+
"single_word": false,
|
1835 |
+
"special": true
|
1836 |
+
},
|
1837 |
+
"126309": {
|
1838 |
+
"content": "<|reserved_token_225|>",
|
1839 |
+
"lstrip": false,
|
1840 |
+
"normalized": false,
|
1841 |
+
"rstrip": false,
|
1842 |
+
"single_word": false,
|
1843 |
+
"special": true
|
1844 |
+
},
|
1845 |
+
"126310": {
|
1846 |
+
"content": "<|reserved_token_226|>",
|
1847 |
+
"lstrip": false,
|
1848 |
+
"normalized": false,
|
1849 |
+
"rstrip": false,
|
1850 |
+
"single_word": false,
|
1851 |
+
"special": true
|
1852 |
+
},
|
1853 |
+
"126311": {
|
1854 |
+
"content": "<|reserved_token_227|>",
|
1855 |
+
"lstrip": false,
|
1856 |
+
"normalized": false,
|
1857 |
+
"rstrip": false,
|
1858 |
+
"single_word": false,
|
1859 |
+
"special": true
|
1860 |
+
},
|
1861 |
+
"126312": {
|
1862 |
+
"content": "<|reserved_token_228|>",
|
1863 |
+
"lstrip": false,
|
1864 |
+
"normalized": false,
|
1865 |
+
"rstrip": false,
|
1866 |
+
"single_word": false,
|
1867 |
+
"special": true
|
1868 |
+
},
|
1869 |
+
"126313": {
|
1870 |
+
"content": "<|reserved_token_229|>",
|
1871 |
+
"lstrip": false,
|
1872 |
+
"normalized": false,
|
1873 |
+
"rstrip": false,
|
1874 |
+
"single_word": false,
|
1875 |
+
"special": true
|
1876 |
+
},
|
1877 |
+
"126314": {
|
1878 |
+
"content": "<|reserved_token_230|>",
|
1879 |
+
"lstrip": false,
|
1880 |
+
"normalized": false,
|
1881 |
+
"rstrip": false,
|
1882 |
+
"single_word": false,
|
1883 |
+
"special": true
|
1884 |
+
},
|
1885 |
+
"126315": {
|
1886 |
+
"content": "<|reserved_token_231|>",
|
1887 |
+
"lstrip": false,
|
1888 |
+
"normalized": false,
|
1889 |
+
"rstrip": false,
|
1890 |
+
"single_word": false,
|
1891 |
+
"special": true
|
1892 |
+
},
|
1893 |
+
"126316": {
|
1894 |
+
"content": "<|reserved_token_232|>",
|
1895 |
+
"lstrip": false,
|
1896 |
+
"normalized": false,
|
1897 |
+
"rstrip": false,
|
1898 |
+
"single_word": false,
|
1899 |
+
"special": true
|
1900 |
+
},
|
1901 |
+
"126317": {
|
1902 |
+
"content": "<|reserved_token_233|>",
|
1903 |
+
"lstrip": false,
|
1904 |
+
"normalized": false,
|
1905 |
+
"rstrip": false,
|
1906 |
+
"single_word": false,
|
1907 |
+
"special": true
|
1908 |
+
},
|
1909 |
+
"126318": {
|
1910 |
+
"content": "<|reserved_token_234|>",
|
1911 |
+
"lstrip": false,
|
1912 |
+
"normalized": false,
|
1913 |
+
"rstrip": false,
|
1914 |
+
"single_word": false,
|
1915 |
+
"special": true
|
1916 |
+
},
|
1917 |
+
"126319": {
|
1918 |
+
"content": "<|reserved_token_235|>",
|
1919 |
+
"lstrip": false,
|
1920 |
+
"normalized": false,
|
1921 |
+
"rstrip": false,
|
1922 |
+
"single_word": false,
|
1923 |
+
"special": true
|
1924 |
+
},
|
1925 |
+
"126320": {
|
1926 |
+
"content": "<|reserved_token_236|>",
|
1927 |
+
"lstrip": false,
|
1928 |
+
"normalized": false,
|
1929 |
+
"rstrip": false,
|
1930 |
+
"single_word": false,
|
1931 |
+
"special": true
|
1932 |
+
},
|
1933 |
+
"126321": {
|
1934 |
+
"content": "<|reserved_token_237|>",
|
1935 |
+
"lstrip": false,
|
1936 |
+
"normalized": false,
|
1937 |
+
"rstrip": false,
|
1938 |
+
"single_word": false,
|
1939 |
+
"special": true
|
1940 |
+
},
|
1941 |
+
"126322": {
|
1942 |
+
"content": "<|reserved_token_238|>",
|
1943 |
+
"lstrip": false,
|
1944 |
+
"normalized": false,
|
1945 |
+
"rstrip": false,
|
1946 |
+
"single_word": false,
|
1947 |
+
"special": true
|
1948 |
+
},
|
1949 |
+
"126323": {
|
1950 |
+
"content": "<|reserved_token_239|>",
|
1951 |
+
"lstrip": false,
|
1952 |
+
"normalized": false,
|
1953 |
+
"rstrip": false,
|
1954 |
+
"single_word": false,
|
1955 |
+
"special": true
|
1956 |
+
},
|
1957 |
+
"126324": {
|
1958 |
+
"content": "<|reserved_token_240|>",
|
1959 |
+
"lstrip": false,
|
1960 |
+
"normalized": false,
|
1961 |
+
"rstrip": false,
|
1962 |
+
"single_word": false,
|
1963 |
+
"special": true
|
1964 |
+
},
|
1965 |
+
"126325": {
|
1966 |
+
"content": "<|reserved_token_241|>",
|
1967 |
+
"lstrip": false,
|
1968 |
+
"normalized": false,
|
1969 |
+
"rstrip": false,
|
1970 |
+
"single_word": false,
|
1971 |
+
"special": true
|
1972 |
+
},
|
1973 |
+
"126326": {
|
1974 |
+
"content": "<|reserved_token_242|>",
|
1975 |
+
"lstrip": false,
|
1976 |
+
"normalized": false,
|
1977 |
+
"rstrip": false,
|
1978 |
+
"single_word": false,
|
1979 |
+
"special": true
|
1980 |
+
},
|
1981 |
+
"126327": {
|
1982 |
+
"content": "<|reserved_token_243|>",
|
1983 |
+
"lstrip": false,
|
1984 |
+
"normalized": false,
|
1985 |
+
"rstrip": false,
|
1986 |
+
"single_word": false,
|
1987 |
+
"special": true
|
1988 |
+
},
|
1989 |
+
"126328": {
|
1990 |
+
"content": "<|reserved_token_244|>",
|
1991 |
+
"lstrip": false,
|
1992 |
+
"normalized": false,
|
1993 |
+
"rstrip": false,
|
1994 |
+
"single_word": false,
|
1995 |
+
"special": true
|
1996 |
+
},
|
1997 |
+
"126329": {
|
1998 |
+
"content": "<|reserved_token_245|>",
|
1999 |
+
"lstrip": false,
|
2000 |
+
"normalized": false,
|
2001 |
+
"rstrip": false,
|
2002 |
+
"single_word": false,
|
2003 |
+
"special": true
|
2004 |
+
},
|
2005 |
+
"126330": {
|
2006 |
+
"content": "<|reserved_token_246|>",
|
2007 |
+
"lstrip": false,
|
2008 |
+
"normalized": false,
|
2009 |
+
"rstrip": false,
|
2010 |
+
"single_word": false,
|
2011 |
+
"special": true
|
2012 |
+
},
|
2013 |
+
"126331": {
|
2014 |
+
"content": "<|reserved_token_247|>",
|
2015 |
+
"lstrip": false,
|
2016 |
+
"normalized": false,
|
2017 |
+
"rstrip": false,
|
2018 |
+
"single_word": false,
|
2019 |
+
"special": true
|
2020 |
+
},
|
2021 |
+
"126332": {
|
2022 |
+
"content": "<|reserved_token_248|>",
|
2023 |
+
"lstrip": false,
|
2024 |
+
"normalized": false,
|
2025 |
+
"rstrip": false,
|
2026 |
+
"single_word": false,
|
2027 |
+
"special": true
|
2028 |
+
},
|
2029 |
+
"126333": {
|
2030 |
+
"content": "<|reserved_token_249|>",
|
2031 |
+
"lstrip": false,
|
2032 |
+
"normalized": false,
|
2033 |
+
"rstrip": false,
|
2034 |
+
"single_word": false,
|
2035 |
+
"special": true
|
2036 |
+
},
|
2037 |
+
"126334": {
|
2038 |
+
"content": "<|reserved_token_250|>",
|
2039 |
+
"lstrip": false,
|
2040 |
+
"normalized": false,
|
2041 |
+
"rstrip": false,
|
2042 |
+
"single_word": false,
|
2043 |
+
"special": true
|
2044 |
+
},
|
2045 |
+
"126335": {
|
2046 |
+
"content": "<|reserved_token_251|>",
|
2047 |
+
"lstrip": false,
|
2048 |
+
"normalized": false,
|
2049 |
+
"rstrip": false,
|
2050 |
+
"single_word": false,
|
2051 |
+
"special": true
|
2052 |
+
},
|
2053 |
+
"126336": {
|
2054 |
+
"content": "<|reserved_token_252|>",
|
2055 |
+
"lstrip": false,
|
2056 |
+
"normalized": false,
|
2057 |
+
"rstrip": false,
|
2058 |
+
"single_word": false,
|
2059 |
+
"special": true
|
2060 |
+
},
|
2061 |
+
"126337": {
|
2062 |
+
"content": "<|reserved_token_253|>",
|
2063 |
+
"lstrip": false,
|
2064 |
+
"normalized": false,
|
2065 |
+
"rstrip": false,
|
2066 |
+
"single_word": false,
|
2067 |
+
"special": true
|
2068 |
+
},
|
2069 |
+
"126338": {
|
2070 |
+
"content": "<|reserved_token_254|>",
|
2071 |
+
"lstrip": false,
|
2072 |
+
"normalized": false,
|
2073 |
+
"rstrip": false,
|
2074 |
+
"single_word": false,
|
2075 |
+
"special": true
|
2076 |
+
},
|
2077 |
+
"126339": {
|
2078 |
+
"content": "<|reserved_token_255|>",
|
2079 |
+
"lstrip": false,
|
2080 |
+
"normalized": false,
|
2081 |
+
"rstrip": false,
|
2082 |
+
"single_word": false,
|
2083 |
+
"special": true
|
2084 |
+
},
|
2085 |
+
"126340": {
|
2086 |
+
"content": "<role>",
|
2087 |
+
"lstrip": false,
|
2088 |
+
"normalized": false,
|
2089 |
+
"rstrip": false,
|
2090 |
+
"single_word": false,
|
2091 |
+
"special": true
|
2092 |
+
},
|
2093 |
+
"126341": {
|
2094 |
+
"content": "</role>",
|
2095 |
+
"lstrip": false,
|
2096 |
+
"normalized": false,
|
2097 |
+
"rstrip": false,
|
2098 |
+
"single_word": false,
|
2099 |
+
"special": true
|
2100 |
+
},
|
2101 |
+
"126342": {
|
2102 |
+
"content": "<|arithmetic_start|>",
|
2103 |
+
"lstrip": false,
|
2104 |
+
"normalized": false,
|
2105 |
+
"rstrip": false,
|
2106 |
+
"single_word": false,
|
2107 |
+
"special": true
|
2108 |
+
},
|
2109 |
+
"126343": {
|
2110 |
+
"content": "<|arithmetic_end|>",
|
2111 |
+
"lstrip": false,
|
2112 |
+
"normalized": false,
|
2113 |
+
"rstrip": false,
|
2114 |
+
"single_word": false,
|
2115 |
+
"special": true
|
2116 |
+
},
|
2117 |
+
"126344": {
|
2118 |
+
"content": "<|number_start|>",
|
2119 |
+
"lstrip": false,
|
2120 |
+
"normalized": false,
|
2121 |
+
"rstrip": false,
|
2122 |
+
"single_word": false,
|
2123 |
+
"special": true
|
2124 |
+
},
|
2125 |
+
"126345": {
|
2126 |
+
"content": "<|number_end|>",
|
2127 |
+
"lstrip": false,
|
2128 |
+
"normalized": false,
|
2129 |
+
"rstrip": false,
|
2130 |
+
"single_word": false,
|
2131 |
+
"special": true
|
2132 |
+
}
|
2133 |
+
},
|
2134 |
+
"additional_special_tokens": [
|
2135 |
+
"<role>",
|
2136 |
+
"</role>",
|
2137 |
+
"<|arithmetic_start|>",
|
2138 |
+
"<|arithmetic_end|>",
|
2139 |
+
"<|number_start|>",
|
2140 |
+
"<|number_end|>"
|
2141 |
+
],
|
2142 |
+
"bos_token": "<|startoftext|>",
|
2143 |
+
"chat_template": "{% for message in messages %}{% set role = message['role'] | lower %}{% if role == 'user' %}{% set role = 'HUMAN' %}{% endif %}{% set role = role | upper %}{{ '<role>' + role + '</role>' + message['content'] }}{% endfor %}{% if add_generation_prompt %}{{ '<role>ASSISTANT</role>' }}{% endif %}",
|
2144 |
+
"clean_up_tokenization_spaces": false,
|
2145 |
+
"cls_token": "[CLS]",
|
2146 |
+
"eos_token": "<|endoftext|>",
|
2147 |
+
"fast_tokenizer": true,
|
2148 |
+
"gmask_token": "[gMASK]",
|
2149 |
+
"merges_file": null,
|
2150 |
+
"model_max_length": 1000000000000000019884624838656,
|
2151 |
+
"pad_token": "<|endoftext|>",
|
2152 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
2153 |
+
"trust_remote_code": true,
|
2154 |
+
"vocab_file": null
|
2155 |
+
}
|