11104491
commited on
Commit
•
55c0361
1
Parent(s):
05cc858
First model version
Browse files- added_tokens.json +6 -0
- config.json +31 -0
- configuration_bluelm.py +163 -0
- generation_config.json +7 -0
- modeling_bluelm.py +1002 -0
- pytorch_model-00001-of-00008.bin +3 -0
- pytorch_model-00002-of-00008.bin +3 -0
- pytorch_model-00003-of-00008.bin +3 -0
- pytorch_model-00004-of-00008.bin +3 -0
- pytorch_model-00005-of-00008.bin +3 -0
- pytorch_model-00006-of-00008.bin +3 -0
- pytorch_model-00007-of-00008.bin +3 -0
- pytorch_model-00008-of-00008.bin +3 -0
- pytorch_model.bin.index.json +300 -0
- special_tokens_map.json +36 -0
- tokenization_bluelm.py +251 -0
- tokenizer.model +3 -0
- tokenizer_config.json +43 -0
added_tokens.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"[SEA]": 100003,
|
3 |
+
"[SEH]": 100002,
|
4 |
+
"[|AI|]:": 100001,
|
5 |
+
"[|Human|]:": 100000
|
6 |
+
}
|
config.json
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"BlueLMForCausalLM"
|
4 |
+
],
|
5 |
+
"auto_map": {
|
6 |
+
"AutoConfig": "configuration_bluelm.BlueLMConfig",
|
7 |
+
"AutoModelForCausalLM": "modeling_bluelm.BlueLMForCausalLM"
|
8 |
+
},
|
9 |
+
"bos_token_id": 1,
|
10 |
+
"eos_token_id": 2,
|
11 |
+
"hidden_act": "silu",
|
12 |
+
"hidden_size": 4096,
|
13 |
+
"initializer_range": 0.02,
|
14 |
+
"intermediate_size": 11008,
|
15 |
+
"max_position_embeddings": 2048,
|
16 |
+
"model_type": "BlueLM",
|
17 |
+
"num_attention_heads": 32,
|
18 |
+
"num_hidden_layers": 32,
|
19 |
+
"num_key_value_heads": 32,
|
20 |
+
"pad_token_id": 3,
|
21 |
+
"pretraining_tp": 1,
|
22 |
+
"rms_norm_eps": 1e-06,
|
23 |
+
"rope_scaling": null,
|
24 |
+
"rope_theta": 10000.0,
|
25 |
+
"tie_word_embeddings": false,
|
26 |
+
"torch_dtype": "bfloat16",
|
27 |
+
"transformers_version": "4.30.1",
|
28 |
+
"use_cache": true,
|
29 |
+
"use_stable_embedding": true,
|
30 |
+
"vocab_size": 100004
|
31 |
+
}
|
configuration_bluelm.py
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
5 |
+
# and OPT implementations in this library. It has been modified from its
|
6 |
+
# original forms to accommodate minor architectural differences compared
|
7 |
+
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
8 |
+
#
|
9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10 |
+
# you may not use this file except in compliance with the License.
|
11 |
+
# You may obtain a copy of the License at
|
12 |
+
#
|
13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14 |
+
#
|
15 |
+
# Unless required by applicable law or agreed to in writing, software
|
16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18 |
+
# See the License for the specific language governing permissions and
|
19 |
+
# limitations under the License.
|
20 |
+
|
21 |
+
""" BlueLM model configuration"""
|
22 |
+
|
23 |
+
from transformers.configuration_utils import PretrainedConfig
|
24 |
+
|
25 |
+
BlueLM_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
|
26 |
+
|
27 |
+
|
28 |
+
class BlueLMConfig(PretrainedConfig):
|
29 |
+
r"""
|
30 |
+
This is the configuration class to store the configuration of a [`BlueLMModel`]. It is used to instantiate an BlueLM
|
31 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
32 |
+
defaults will yield a similar configuration to that of the BlueLM-7B.
|
33 |
+
|
34 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
35 |
+
documentation from [`PretrainedConfig`] for more information.
|
36 |
+
|
37 |
+
|
38 |
+
Args:
|
39 |
+
vocab_size (`int`, *optional*, defaults to 32000):
|
40 |
+
Vocabulary size of the BlueLM model. Defines the number of different tokens that can be represented by the
|
41 |
+
`inputs_ids` passed when calling [`BlueLMModel`]
|
42 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
43 |
+
Dimension of the hidden representations.
|
44 |
+
intermediate_size (`int`, *optional*, defaults to 11008):
|
45 |
+
Dimension of the MLP representations.
|
46 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
47 |
+
Number of hidden layers in the Transformer encoder.
|
48 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
49 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
50 |
+
num_key_value_heads (`int`, *optional*):
|
51 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
52 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
53 |
+
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
54 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
55 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
56 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
57 |
+
`num_attention_heads`.
|
58 |
+
pretraining_tp (`int`, *optional*, defaults to `1`):
|
59 |
+
Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
|
60 |
+
document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
|
61 |
+
necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
|
62 |
+
issue](https://github.com/pytorch/pytorch/issues/76232).
|
63 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
64 |
+
The non-linear activation function (function or string) in the decoder.
|
65 |
+
max_position_embeddings (`int`, *optional*, defaults to 2048):
|
66 |
+
The maximum sequence length that this model might ever be used with.
|
67 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
68 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
69 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-12):
|
70 |
+
The epsilon used by the rms normalization layers.
|
71 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
72 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
73 |
+
relevant if `config.is_decoder=True`.
|
74 |
+
tie_word_embeddings(`bool`, *optional*, defaults to `False`):
|
75 |
+
Whether to tie weight embeddings
|
76 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
77 |
+
The base period of the RoPE embeddings.
|
78 |
+
rope_scaling (`Dict`, *optional*):
|
79 |
+
Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
|
80 |
+
strategies: linear and dynamic. Their scaling factor must be an float greater than 1. The expected format
|
81 |
+
is `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
|
82 |
+
`max_position_embeddings` to the expected new maximum. See the following thread for more information on how
|
83 |
+
these scaling strategies behave:
|
84 |
+
https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
|
85 |
+
experimental feature, subject to breaking API changes in future versions.
|
86 |
+
|
87 |
+
"""
|
88 |
+
|
89 |
+
model_type = "BlueLM"
|
90 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
91 |
+
|
92 |
+
def __init__(
|
93 |
+
self,
|
94 |
+
vocab_size=100096,
|
95 |
+
hidden_size=4096,
|
96 |
+
intermediate_size=11008,
|
97 |
+
num_hidden_layers=32,
|
98 |
+
num_attention_heads=32,
|
99 |
+
num_key_value_heads=None,
|
100 |
+
hidden_act="silu",
|
101 |
+
max_position_embeddings=2048,
|
102 |
+
initializer_range=0.02,
|
103 |
+
rms_norm_eps=1e-6,
|
104 |
+
use_cache=True,
|
105 |
+
pad_token_id=None,
|
106 |
+
bos_token_id=1,
|
107 |
+
eos_token_id=2,
|
108 |
+
pretraining_tp=1,
|
109 |
+
tie_word_embeddings=False,
|
110 |
+
rope_theta=10000.0,
|
111 |
+
rope_scaling=None,
|
112 |
+
use_stable_embedding=True,
|
113 |
+
**kwargs,
|
114 |
+
):
|
115 |
+
self.vocab_size = vocab_size
|
116 |
+
self.max_position_embeddings = max_position_embeddings
|
117 |
+
self.hidden_size = hidden_size
|
118 |
+
self.intermediate_size = intermediate_size
|
119 |
+
self.num_hidden_layers = num_hidden_layers
|
120 |
+
self.num_attention_heads = num_attention_heads
|
121 |
+
self.use_stable_embedding = use_stable_embedding
|
122 |
+
# for backward compatibility
|
123 |
+
if num_key_value_heads is None:
|
124 |
+
num_key_value_heads = num_attention_heads
|
125 |
+
|
126 |
+
self.num_key_value_heads = num_key_value_heads
|
127 |
+
self.hidden_act = hidden_act
|
128 |
+
self.initializer_range = initializer_range
|
129 |
+
self.rms_norm_eps = rms_norm_eps
|
130 |
+
self.pretraining_tp = pretraining_tp
|
131 |
+
self.use_cache = use_cache
|
132 |
+
self.rope_theta = rope_theta
|
133 |
+
self.rope_scaling = rope_scaling
|
134 |
+
self._rope_scaling_validation()
|
135 |
+
|
136 |
+
super().__init__(
|
137 |
+
pad_token_id=pad_token_id,
|
138 |
+
bos_token_id=bos_token_id,
|
139 |
+
eos_token_id=eos_token_id,
|
140 |
+
tie_word_embeddings=tie_word_embeddings,
|
141 |
+
**kwargs,
|
142 |
+
)
|
143 |
+
|
144 |
+
def _rope_scaling_validation(self):
|
145 |
+
"""
|
146 |
+
Validate the `rope_scaling` configuration.
|
147 |
+
"""
|
148 |
+
if self.rope_scaling is None:
|
149 |
+
return
|
150 |
+
|
151 |
+
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
|
152 |
+
raise ValueError(
|
153 |
+
"`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
|
154 |
+
f"got {self.rope_scaling}"
|
155 |
+
)
|
156 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
157 |
+
rope_scaling_factor = self.rope_scaling.get("factor", None)
|
158 |
+
if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
|
159 |
+
raise ValueError(
|
160 |
+
f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
|
161 |
+
)
|
162 |
+
if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
|
163 |
+
raise ValueError(f"`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}")
|
generation_config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 1,
|
4 |
+
"eos_token_id": 2,
|
5 |
+
"pad_token_id": 3,
|
6 |
+
"transformers_version": "4.30.1"
|
7 |
+
}
|
modeling_bluelm.py
ADDED
@@ -0,0 +1,1002 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
5 |
+
# and OPT implementations in this library. It has been modified from its
|
6 |
+
# original forms to accommodate minor architectural differences compared
|
7 |
+
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
8 |
+
#
|
9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10 |
+
# you may not use this file except in compliance with the License.
|
11 |
+
# You may obtain a copy of the License at
|
12 |
+
#
|
13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14 |
+
#
|
15 |
+
# Unless required by applicable law or agreed to in writing, software
|
16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18 |
+
# See the License for the specific language governing permissions and
|
19 |
+
# limitations under the License.
|
20 |
+
""" PyTorch BlueLM model."""
|
21 |
+
import math
|
22 |
+
from typing import List, Optional, Tuple, Union
|
23 |
+
|
24 |
+
import torch
|
25 |
+
import torch.utils.checkpoint
|
26 |
+
from torch import nn
|
27 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
28 |
+
|
29 |
+
from transformers.activations import ACT2FN
|
30 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
|
31 |
+
from transformers.modeling_utils import PreTrainedModel
|
32 |
+
from transformers.utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
|
33 |
+
from .configuration_bluelm import BlueLMConfig
|
34 |
+
|
35 |
+
|
36 |
+
try:
|
37 |
+
from xformers import ops as xops
|
38 |
+
except ImportError:
|
39 |
+
xops = None
|
40 |
+
# print("xformers is not installed correctly.")
|
41 |
+
|
42 |
+
try:
|
43 |
+
from apex.normalization import MixedFusedRMSNorm
|
44 |
+
except ImportError:
|
45 |
+
MixedFusedRMSNorm = None
|
46 |
+
# print("Please install nvidia apex from source (https://github.com/NVIDIA/apex#linux) or use ngc container.")
|
47 |
+
|
48 |
+
|
49 |
+
logger = logging.get_logger(__name__)
|
50 |
+
|
51 |
+
_CONFIG_FOR_DOC = "BlueLmConfig"
|
52 |
+
|
53 |
+
|
54 |
+
def _make_causal_mask(input_ids_shape: torch.Size, dtype: torch.dtype, past_key_values_length: int = 0):
|
55 |
+
"""
|
56 |
+
Make causal mask used for bi-directional self-attention.
|
57 |
+
"""
|
58 |
+
bsz, tgt_len = input_ids_shape
|
59 |
+
mask = torch.full((tgt_len, tgt_len), torch.tensor(torch.finfo(dtype).min))
|
60 |
+
mask_cond = torch.arange(mask.size(-1))
|
61 |
+
mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)
|
62 |
+
mask = mask.to(dtype)
|
63 |
+
|
64 |
+
if past_key_values_length > 0:
|
65 |
+
mask = torch.cat([torch.zeros(tgt_len, past_key_values_length, dtype=dtype), mask], dim=-1)
|
66 |
+
return mask[None, None, :, :].expand(bsz, 1, tgt_len, tgt_len + past_key_values_length)
|
67 |
+
|
68 |
+
|
69 |
+
def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
|
70 |
+
"""
|
71 |
+
Expands attention_mask from `[bsz, seq_len]` to `[bsz, 1, tgt_seq_len, src_seq_len]`.
|
72 |
+
"""
|
73 |
+
bsz, src_len = mask.size()
|
74 |
+
tgt_len = tgt_len if tgt_len is not None else src_len
|
75 |
+
|
76 |
+
expanded_mask = mask[:, None, None, :].expand(bsz, 1, tgt_len, src_len).to(dtype)
|
77 |
+
|
78 |
+
inverted_mask = 1.0 - expanded_mask
|
79 |
+
|
80 |
+
return inverted_mask.masked_fill(inverted_mask.to(torch.bool), torch.finfo(dtype).min)
|
81 |
+
|
82 |
+
|
83 |
+
class BlueLMRMSNorm(nn.Module):
|
84 |
+
def __init__(self, hidden_size, eps=1e-6):
|
85 |
+
"""
|
86 |
+
BlueLMRMSNorm is equivalent to T5LayerNorm
|
87 |
+
"""
|
88 |
+
super().__init__()
|
89 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
90 |
+
self.variance_epsilon = eps
|
91 |
+
|
92 |
+
def forward(self, hidden_states):
|
93 |
+
variance = hidden_states.to(torch.float32).pow(2).mean(-1, keepdim=True)
|
94 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
95 |
+
|
96 |
+
# convert into half-precision if necessary
|
97 |
+
if self.weight.dtype in [torch.float16, torch.bfloat16]:
|
98 |
+
hidden_states = hidden_states.to(self.weight.dtype)
|
99 |
+
|
100 |
+
return self.weight * hidden_states
|
101 |
+
|
102 |
+
|
103 |
+
class BlueLMRotaryEmbedding(torch.nn.Module):
|
104 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, k=16, b=0.3):
|
105 |
+
super().__init__()
|
106 |
+
# hard code bluedLM-long support 32k window size only
|
107 |
+
max_position_embeddings = 2048 * k
|
108 |
+
a = math.log(k) / ((dim / 2) ** b)
|
109 |
+
inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2).float().to(device) / dim)) \
|
110 |
+
/ torch.exp(a * torch.arange(1, dim / 2 + 1).float() ** b)
|
111 |
+
|
112 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
113 |
+
assert self.inv_freq.dtype == torch.float32 # inv_freq must be float32 for ensuring numeric precision
|
114 |
+
|
115 |
+
# Build here to make `torch.jit.trace` work.
|
116 |
+
self.max_seq_len_cached = max_position_embeddings
|
117 |
+
t = torch.arange(self.max_seq_len_cached, device=self.inv_freq.device, dtype=self.inv_freq.dtype)
|
118 |
+
freqs = torch.einsum("i,j->ij", t, self.inv_freq)
|
119 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
120 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
121 |
+
self.register_buffer("cos_cached", emb.cos()[None, :, None, :], persistent=False)
|
122 |
+
self.register_buffer("sin_cached", emb.sin()[None, :, None, :], persistent=False)
|
123 |
+
|
124 |
+
def forward(self, x, seq_len=None):
|
125 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
126 |
+
# This `if` block is unlikely to be run after we build sin/cos in `__init__`. Keep the logic here just in case.
|
127 |
+
if seq_len > self.max_seq_len_cached:
|
128 |
+
self.max_seq_len_cached = seq_len
|
129 |
+
t = torch.arange(self.max_seq_len_cached, device=x.device, dtype=self.inv_freq.dtype)
|
130 |
+
freqs = torch.einsum("i,j->ij", t, self.inv_freq)
|
131 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
132 |
+
emb = torch.cat((freqs, freqs), dim=-1).to(x.device)
|
133 |
+
self.register_buffer("cos_cached", emb.cos()[None, :, None, :], persistent=False)
|
134 |
+
self.register_buffer("sin_cached", emb.sin()[None, :, None, :], persistent=False)
|
135 |
+
return (
|
136 |
+
self.cos_cached[:, :seq_len, ...].to(dtype=x.dtype),
|
137 |
+
self.sin_cached[:, :seq_len, ...].to(dtype=x.dtype),
|
138 |
+
)
|
139 |
+
|
140 |
+
|
141 |
+
def rotate_half(x):
|
142 |
+
"""Rotates half the hidden dims of the input."""
|
143 |
+
x1 = x[..., : x.shape[-1] // 2]
|
144 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
145 |
+
return torch.cat((-x2, x1), dim=-1)
|
146 |
+
|
147 |
+
|
148 |
+
def apply_rotary_pos_emb(q, k, cos, sin, offset: int = 0):
|
149 |
+
cos = cos[:, offset : q.shape[1] + offset, ...]
|
150 |
+
sin = sin[:, offset : q.shape[1] + offset, ...]
|
151 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
152 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
153 |
+
return q_embed, k_embed
|
154 |
+
|
155 |
+
|
156 |
+
class BlueLMMLP(nn.Module):
|
157 |
+
def __init__(
|
158 |
+
self,
|
159 |
+
hidden_size: int,
|
160 |
+
intermediate_size: int,
|
161 |
+
hidden_act: str,
|
162 |
+
dropout_prob: float,
|
163 |
+
):
|
164 |
+
super().__init__()
|
165 |
+
self.gate_proj = nn.Linear(hidden_size, intermediate_size, bias=False)
|
166 |
+
self.down_proj = nn.Linear(intermediate_size, hidden_size, bias=False)
|
167 |
+
self.up_proj = nn.Linear(hidden_size, intermediate_size, bias=False)
|
168 |
+
self.act_fn = ACT2FN[hidden_act]
|
169 |
+
self.dropout = nn.Dropout(dropout_prob)
|
170 |
+
|
171 |
+
def forward(self, x):
|
172 |
+
return self.dropout(self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x)))
|
173 |
+
|
174 |
+
|
175 |
+
class BlueLMAttention(nn.Module):
|
176 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
177 |
+
|
178 |
+
def __init__(
|
179 |
+
self,
|
180 |
+
hidden_size: int,
|
181 |
+
num_heads: int,
|
182 |
+
dropout_prob: float,
|
183 |
+
):
|
184 |
+
super().__init__()
|
185 |
+
self.hidden_size = hidden_size
|
186 |
+
self.num_heads = num_heads
|
187 |
+
self.head_dim = hidden_size // num_heads
|
188 |
+
self.dropout_prob = dropout_prob
|
189 |
+
|
190 |
+
if (self.head_dim * num_heads) != self.hidden_size:
|
191 |
+
raise ValueError(
|
192 |
+
f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
|
193 |
+
f" and `num_heads`: {num_heads})."
|
194 |
+
)
|
195 |
+
self.q_proj = nn.Linear(
|
196 |
+
hidden_size,
|
197 |
+
num_heads * self.head_dim,
|
198 |
+
bias=False,
|
199 |
+
)
|
200 |
+
self.k_proj = nn.Linear(
|
201 |
+
hidden_size,
|
202 |
+
num_heads * self.head_dim,
|
203 |
+
bias=False,
|
204 |
+
)
|
205 |
+
self.v_proj = nn.Linear(
|
206 |
+
hidden_size,
|
207 |
+
num_heads * self.head_dim,
|
208 |
+
bias=False,
|
209 |
+
)
|
210 |
+
self.o_proj = nn.Linear(
|
211 |
+
num_heads * self.head_dim,
|
212 |
+
hidden_size,
|
213 |
+
bias=False,
|
214 |
+
)
|
215 |
+
self.rotary_emb = BlueLMRotaryEmbedding(self.head_dim)
|
216 |
+
if xops is not None:
|
217 |
+
self.causal_mask = xops.LowerTriangularMask()
|
218 |
+
|
219 |
+
def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
|
220 |
+
return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).contiguous()
|
221 |
+
|
222 |
+
def forward(
|
223 |
+
self,
|
224 |
+
hidden_states: torch.Tensor,
|
225 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
226 |
+
attention_mask: Optional[torch.Tensor] = None,
|
227 |
+
output_attentions: bool = False,
|
228 |
+
use_cache: bool = False,
|
229 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
230 |
+
"""Input shape: Batch x Time x Channel"""
|
231 |
+
|
232 |
+
bsz, q_len, _ = hidden_states.size()
|
233 |
+
|
234 |
+
query_states = self.q_proj(hidden_states).view(bsz, q_len, self.num_heads, self.head_dim)
|
235 |
+
key_states = self.k_proj(hidden_states).view(bsz, q_len, self.num_heads, self.head_dim)
|
236 |
+
value_states = self.v_proj(hidden_states).view(bsz, q_len, self.num_heads, self.head_dim)
|
237 |
+
|
238 |
+
kv_seq_len = key_states.shape[1]
|
239 |
+
offset = 0
|
240 |
+
if past_key_value is not None:
|
241 |
+
offset = past_key_value[0].shape[1]
|
242 |
+
kv_seq_len += offset
|
243 |
+
cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
|
244 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, offset=offset)
|
245 |
+
# [bsz, t, nh, hd]
|
246 |
+
|
247 |
+
if past_key_value is not None:
|
248 |
+
# reuse k, v, self_attention
|
249 |
+
key_states = torch.cat([past_key_value[0], key_states], dim=1)
|
250 |
+
value_states = torch.cat([past_key_value[1], value_states], dim=1)
|
251 |
+
|
252 |
+
past_key_value = (key_states, value_states) if use_cache else None
|
253 |
+
|
254 |
+
if xops is not None and self.training:
|
255 |
+
attn_weights = None
|
256 |
+
attn_output = xops.memory_efficient_attention(
|
257 |
+
query_states, key_states, value_states, attn_bias=self.causal_mask, p=self.dropout_prob,
|
258 |
+
op=xops.fmha.MemoryEfficientAttentionFlashAttentionOp
|
259 |
+
)
|
260 |
+
else:
|
261 |
+
# [bsz, t, nh, hd]
|
262 |
+
attn_weights = torch.einsum("bqnh,bknh->bnqk", query_states, key_states) / math.sqrt(self.head_dim)
|
263 |
+
|
264 |
+
if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
|
265 |
+
raise ValueError(
|
266 |
+
f"Attention weights should be of size {(bsz * self.num_heads, q_len, kv_seq_len)}, but is"
|
267 |
+
f" {attn_weights.size()}"
|
268 |
+
)
|
269 |
+
|
270 |
+
if attention_mask is not None:
|
271 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
272 |
+
raise ValueError(
|
273 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
274 |
+
)
|
275 |
+
attn_weights = attn_weights + attention_mask
|
276 |
+
attn_weights = torch.max(attn_weights, torch.tensor(torch.finfo(attn_weights.dtype).min))
|
277 |
+
|
278 |
+
# upcast attention to fp32
|
279 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
|
280 |
+
attn_output = torch.einsum("bnqk,bknh->bqnh", attn_weights, value_states)
|
281 |
+
|
282 |
+
if attn_output.size() != (bsz, q_len, self.num_heads, self.head_dim):
|
283 |
+
raise ValueError(
|
284 |
+
f"`attn_output` should be of size {(bsz, q_len, self.num_heads, self.head_dim)}, but is"
|
285 |
+
f" {attn_output.size()}"
|
286 |
+
)
|
287 |
+
|
288 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
289 |
+
|
290 |
+
attn_output = self.o_proj(attn_output)
|
291 |
+
|
292 |
+
if not output_attentions:
|
293 |
+
attn_weights = None
|
294 |
+
|
295 |
+
return attn_output, attn_weights, past_key_value
|
296 |
+
|
297 |
+
|
298 |
+
class BlueLMDecoderLayer(nn.Module):
|
299 |
+
def __init__(self, config: BlueLMConfig):
|
300 |
+
super().__init__()
|
301 |
+
self.hidden_size = config.hidden_size
|
302 |
+
self.self_attn = BlueLMAttention(
|
303 |
+
hidden_size=self.hidden_size,
|
304 |
+
num_heads=config.num_attention_heads,
|
305 |
+
dropout_prob=0,
|
306 |
+
)
|
307 |
+
self.mlp = BlueLMMLP(
|
308 |
+
hidden_size=self.hidden_size,
|
309 |
+
intermediate_size=config.intermediate_size,
|
310 |
+
hidden_act=config.hidden_act,
|
311 |
+
dropout_prob=0,
|
312 |
+
)
|
313 |
+
if MixedFusedRMSNorm is None:
|
314 |
+
self.input_layernorm = BlueLMRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
315 |
+
self.post_attention_layernorm = BlueLMRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
316 |
+
else:
|
317 |
+
self.input_layernorm = MixedFusedRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
318 |
+
self.post_attention_layernorm = MixedFusedRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
319 |
+
|
320 |
+
def forward(
|
321 |
+
self,
|
322 |
+
hidden_states: torch.Tensor,
|
323 |
+
attention_mask: Optional[torch.Tensor] = None,
|
324 |
+
output_attentions: Optional[bool] = False,
|
325 |
+
use_cache: Optional[bool] = False,
|
326 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
327 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
328 |
+
"""
|
329 |
+
Args:
|
330 |
+
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
|
331 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
332 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
333 |
+
output_attentions (`bool`, *optional*):
|
334 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
335 |
+
returned tensors for more detail.
|
336 |
+
use_cache (`bool`, *optional*):
|
337 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
338 |
+
(see `past_key_values`).
|
339 |
+
past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
|
340 |
+
"""
|
341 |
+
|
342 |
+
residual = hidden_states
|
343 |
+
|
344 |
+
hidden_states = self.input_layernorm(hidden_states)
|
345 |
+
|
346 |
+
# Self Attention
|
347 |
+
hidden_states, self_attn_weights, present_key_value = self.self_attn(
|
348 |
+
hidden_states=hidden_states,
|
349 |
+
past_key_value=past_key_value,
|
350 |
+
attention_mask=attention_mask,
|
351 |
+
output_attentions=output_attentions,
|
352 |
+
use_cache=use_cache,
|
353 |
+
)
|
354 |
+
hidden_states = residual + hidden_states
|
355 |
+
|
356 |
+
# Fully Connected
|
357 |
+
residual = hidden_states
|
358 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
359 |
+
hidden_states = self.mlp(hidden_states)
|
360 |
+
hidden_states = residual + hidden_states
|
361 |
+
|
362 |
+
outputs = (hidden_states,)
|
363 |
+
|
364 |
+
if output_attentions:
|
365 |
+
outputs += (self_attn_weights,)
|
366 |
+
|
367 |
+
if use_cache:
|
368 |
+
outputs += (present_key_value,)
|
369 |
+
|
370 |
+
return outputs
|
371 |
+
|
372 |
+
|
373 |
+
BlueLM_START_DOCSTRING = r"""
|
374 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
375 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
376 |
+
etc.)
|
377 |
+
|
378 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
379 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
380 |
+
and behavior.
|
381 |
+
|
382 |
+
Parameters:
|
383 |
+
config ([`BlueLMConfig`]):
|
384 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
385 |
+
load the weights associated with the model, only the configuration. Check out the
|
386 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
387 |
+
"""
|
388 |
+
|
389 |
+
|
390 |
+
@add_start_docstrings(
|
391 |
+
"The bare BlueLM Model outputting raw hidden-states without any specific head on top.",
|
392 |
+
BlueLM_START_DOCSTRING,
|
393 |
+
)
|
394 |
+
class BlueLMPreTrainedModel(PreTrainedModel):
|
395 |
+
config_class = BlueLMConfig
|
396 |
+
base_model_prefix = "model"
|
397 |
+
supports_gradient_checkpointing = True
|
398 |
+
_no_split_modules = ["BlueLMDecoderLayer"]
|
399 |
+
_keys_to_ignore_on_load_unexpected = [r"decoder\.version"]
|
400 |
+
|
401 |
+
def _init_weights(self, module):
|
402 |
+
std = self.config.initializer_range
|
403 |
+
if isinstance(module, nn.Linear):
|
404 |
+
# module.weight.data.normal_(mean=0.0, std=std)
|
405 |
+
torch.nn.init.xavier_normal_(module.weight.data)
|
406 |
+
if module.bias is not None:
|
407 |
+
module.bias.data.zero_()
|
408 |
+
elif isinstance(module, nn.Embedding):
|
409 |
+
if self.config.use_stable_embedding:
|
410 |
+
torch.nn.init.xavier_normal_(module.weight.data)
|
411 |
+
else:
|
412 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
413 |
+
if module.padding_idx is not None:
|
414 |
+
module.weight.data[module.padding_idx].zero_()
|
415 |
+
|
416 |
+
def _set_gradient_checkpointing(self, module, value=False):
|
417 |
+
if isinstance(module, BlueLMModel):
|
418 |
+
module.gradient_checkpointing = value
|
419 |
+
|
420 |
+
|
421 |
+
BlueLM_INPUTS_DOCSTRING = r"""
|
422 |
+
Args:
|
423 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
424 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
425 |
+
it.
|
426 |
+
|
427 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
428 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
429 |
+
|
430 |
+
[What are input IDs?](../glossary#input-ids)
|
431 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
432 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
433 |
+
|
434 |
+
- 1 for tokens that are **not masked**,
|
435 |
+
- 0 for tokens that are **masked**.
|
436 |
+
|
437 |
+
[What are attention masks?](../glossary#attention-mask)
|
438 |
+
|
439 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
440 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
441 |
+
|
442 |
+
If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
|
443 |
+
`past_key_values`).
|
444 |
+
|
445 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
446 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
447 |
+
information on the default strategy.
|
448 |
+
|
449 |
+
- 1 indicates the head is **not masked**,
|
450 |
+
- 0 indicates the head is **masked**.
|
451 |
+
|
452 |
+
past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
453 |
+
Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
|
454 |
+
`(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of shape
|
455 |
+
`(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.
|
456 |
+
|
457 |
+
Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
458 |
+
blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.
|
459 |
+
|
460 |
+
If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
|
461 |
+
don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
|
462 |
+
`decoder_input_ids` of shape `(batch_size, sequence_length)`.
|
463 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
464 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
465 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
466 |
+
model's internal embedding lookup matrix.
|
467 |
+
use_cache (`bool`, *optional*):
|
468 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
469 |
+
`past_key_values`).
|
470 |
+
output_attentions (`bool`, *optional*):
|
471 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
472 |
+
tensors for more detail.
|
473 |
+
output_hidden_states (`bool`, *optional*):
|
474 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
475 |
+
more detail.
|
476 |
+
return_dict (`bool`, *optional*):
|
477 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
478 |
+
"""
|
479 |
+
|
480 |
+
|
481 |
+
@add_start_docstrings(
|
482 |
+
"The bare BlueLM Model outputting raw hidden-states without any specific head on top.",
|
483 |
+
BlueLM_START_DOCSTRING,
|
484 |
+
)
|
485 |
+
class BlueLMModel(BlueLMPreTrainedModel):
|
486 |
+
"""
|
487 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`BlueLMDecoderLayer`]
|
488 |
+
|
489 |
+
Args:
|
490 |
+
config: BlueLMConfig
|
491 |
+
"""
|
492 |
+
|
493 |
+
def __init__(self, config: BlueLMConfig):
|
494 |
+
super().__init__(config)
|
495 |
+
self.padding_idx = config.pad_token_id
|
496 |
+
self.vocab_size = config.vocab_size
|
497 |
+
|
498 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
499 |
+
if config.use_stable_embedding:
|
500 |
+
self.embed_layer_norm = nn.LayerNorm(config.hidden_size,eps=1e-06)
|
501 |
+
else:
|
502 |
+
self.embed_layer_norm = None
|
503 |
+
self.layers = nn.ModuleList([BlueLMDecoderLayer(config) for _ in range(config.num_hidden_layers)])
|
504 |
+
if MixedFusedRMSNorm is None:
|
505 |
+
self.norm = BlueLMRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
506 |
+
else:
|
507 |
+
self.norm = MixedFusedRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
508 |
+
|
509 |
+
self.gradient_checkpointing = False
|
510 |
+
# Initialize weights and apply final processing
|
511 |
+
self.post_init()
|
512 |
+
|
513 |
+
def get_input_embeddings(self):
|
514 |
+
return self.embed_tokens
|
515 |
+
|
516 |
+
def set_input_embeddings(self, value):
|
517 |
+
self.embed_tokens = value
|
518 |
+
|
519 |
+
# Copied from transformers.models.bart.modeling_bart.BartDecoder._prepare_decoder_attention_mask
|
520 |
+
def _prepare_decoder_attention_mask(self, attention_mask, input_shape, inputs_embeds, past_key_values_length):
|
521 |
+
# create causal mask
|
522 |
+
# [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
|
523 |
+
combined_attention_mask = None
|
524 |
+
if input_shape[-1] > 1:
|
525 |
+
combined_attention_mask = _make_causal_mask(
|
526 |
+
input_shape, inputs_embeds.dtype, past_key_values_length=past_key_values_length
|
527 |
+
).to(inputs_embeds.device)
|
528 |
+
|
529 |
+
if attention_mask is not None:
|
530 |
+
# [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
|
531 |
+
expanded_attn_mask = _expand_mask(attention_mask, inputs_embeds.dtype, tgt_len=input_shape[-1]).to(
|
532 |
+
inputs_embeds.device
|
533 |
+
)
|
534 |
+
combined_attention_mask = (
|
535 |
+
expanded_attn_mask if combined_attention_mask is None else expanded_attn_mask + combined_attention_mask
|
536 |
+
)
|
537 |
+
|
538 |
+
return combined_attention_mask
|
539 |
+
|
540 |
+
def forward(
|
541 |
+
self,
|
542 |
+
input_ids: torch.LongTensor = None,
|
543 |
+
attention_mask: Optional[torch.Tensor] = None,
|
544 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
545 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
546 |
+
use_cache: Optional[bool] = None,
|
547 |
+
output_attentions: Optional[bool] = None,
|
548 |
+
output_hidden_states: Optional[bool] = None,
|
549 |
+
return_dict: Optional[bool] = None,
|
550 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
551 |
+
r"""
|
552 |
+
Args:
|
553 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
554 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
|
555 |
+
provide it.
|
556 |
+
|
557 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
558 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
559 |
+
|
560 |
+
[What are input IDs?](../glossary#input-ids)
|
561 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
562 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
563 |
+
|
564 |
+
- 1 for tokens that are **not masked**,
|
565 |
+
- 0 for tokens that are **masked**.
|
566 |
+
|
567 |
+
[What are attention masks?](../glossary#attention-mask)
|
568 |
+
past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
569 |
+
Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
570 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of
|
571 |
+
|
572 |
+
Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
|
573 |
+
cross-attention blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.
|
574 |
+
|
575 |
+
If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those
|
576 |
+
that don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of
|
577 |
+
all `decoder_input_ids` of shape `(batch_size, sequence_length)`.
|
578 |
+
use_cache (`bool`, *optional*):
|
579 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
580 |
+
(see `past_key_values`).
|
581 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
582 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
|
583 |
+
This is useful if you want more control over how to convert `input_ids` indices into associated vectors
|
584 |
+
than the model's internal embedding lookup matrix.
|
585 |
+
output_attentions (`bool`, *optional*):
|
586 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
587 |
+
returned tensors for more detail.
|
588 |
+
output_hidden_states (`bool`, *optional*):
|
589 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
|
590 |
+
for more detail.
|
591 |
+
return_dict (`bool`, *optional*):
|
592 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
593 |
+
"""
|
594 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
595 |
+
output_hidden_states = (
|
596 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
597 |
+
)
|
598 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
599 |
+
|
600 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
601 |
+
|
602 |
+
# retrieve input_ids and inputs_embeds
|
603 |
+
if input_ids is not None and inputs_embeds is not None:
|
604 |
+
raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time")
|
605 |
+
elif input_ids is not None:
|
606 |
+
batch_size, seq_length = input_ids.shape
|
607 |
+
elif inputs_embeds is not None:
|
608 |
+
batch_size, seq_length, _ = inputs_embeds.shape
|
609 |
+
else:
|
610 |
+
raise ValueError("You have to specify either decoder_input_ids or decoder_inputs_embeds")
|
611 |
+
seq_length_with_past = seq_length
|
612 |
+
past_key_values_length = 0
|
613 |
+
if past_key_values is not None:
|
614 |
+
past_key_values_length = past_key_values[0][0].shape[2]
|
615 |
+
seq_length_with_past = seq_length_with_past + past_key_values_length
|
616 |
+
if inputs_embeds is None:
|
617 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
618 |
+
if self.embed_layer_norm:
|
619 |
+
inputs_embeds = self.embed_layer_norm(inputs_embeds)
|
620 |
+
# embed positions
|
621 |
+
if xops is not None and self.training:
|
622 |
+
attention_mask = None
|
623 |
+
else:
|
624 |
+
if attention_mask is None:
|
625 |
+
attention_mask = torch.ones(
|
626 |
+
(batch_size, seq_length_with_past), dtype=torch.bool, device=inputs_embeds.device
|
627 |
+
)
|
628 |
+
attention_mask = self._prepare_decoder_attention_mask(
|
629 |
+
attention_mask, (batch_size, seq_length), inputs_embeds, past_key_values_length
|
630 |
+
)
|
631 |
+
|
632 |
+
hidden_states = inputs_embeds
|
633 |
+
|
634 |
+
if self.gradient_checkpointing and self.training:
|
635 |
+
if use_cache:
|
636 |
+
logger.warning_once(
|
637 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
638 |
+
)
|
639 |
+
use_cache = False
|
640 |
+
|
641 |
+
# decoder layers
|
642 |
+
all_hidden_states = () if output_hidden_states else None
|
643 |
+
all_self_attns = () if output_attentions else None
|
644 |
+
next_decoder_cache = () if use_cache else None
|
645 |
+
|
646 |
+
for idx, decoder_layer in enumerate(self.layers):
|
647 |
+
if output_hidden_states:
|
648 |
+
all_hidden_states += (hidden_states,)
|
649 |
+
|
650 |
+
past_key_value = past_key_values[idx] if past_key_values is not None else None
|
651 |
+
|
652 |
+
if self.gradient_checkpointing and self.training:
|
653 |
+
|
654 |
+
def create_custom_forward(module):
|
655 |
+
def custom_forward(*inputs):
|
656 |
+
# None for past_key_value
|
657 |
+
return module(*inputs, output_attentions, None)
|
658 |
+
|
659 |
+
return custom_forward
|
660 |
+
|
661 |
+
layer_outputs = torch.utils.checkpoint.checkpoint(
|
662 |
+
create_custom_forward(decoder_layer),
|
663 |
+
hidden_states,
|
664 |
+
attention_mask,
|
665 |
+
None,
|
666 |
+
)
|
667 |
+
else:
|
668 |
+
layer_outputs = decoder_layer(
|
669 |
+
hidden_states,
|
670 |
+
attention_mask=attention_mask,
|
671 |
+
past_key_value=past_key_value,
|
672 |
+
output_attentions=output_attentions,
|
673 |
+
use_cache=use_cache,
|
674 |
+
)
|
675 |
+
|
676 |
+
hidden_states = layer_outputs[0]
|
677 |
+
|
678 |
+
if use_cache:
|
679 |
+
next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
|
680 |
+
|
681 |
+
if output_attentions:
|
682 |
+
all_self_attns += (layer_outputs[1],)
|
683 |
+
|
684 |
+
hidden_states = self.norm(hidden_states)
|
685 |
+
|
686 |
+
# add hidden states from the last decoder layer
|
687 |
+
if output_hidden_states:
|
688 |
+
all_hidden_states += (hidden_states,)
|
689 |
+
|
690 |
+
next_cache = next_decoder_cache if use_cache else None
|
691 |
+
if not return_dict:
|
692 |
+
return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
|
693 |
+
return BaseModelOutputWithPast(
|
694 |
+
last_hidden_state=hidden_states,
|
695 |
+
past_key_values=next_cache,
|
696 |
+
hidden_states=all_hidden_states,
|
697 |
+
attentions=all_self_attns,
|
698 |
+
)
|
699 |
+
|
700 |
+
|
701 |
+
class BlueLMForCausalLM(BlueLMPreTrainedModel):
|
702 |
+
_keys_to_ignore_on_load_missing = [r"lm_head.weight"]
|
703 |
+
|
704 |
+
def __init__(self, config):
|
705 |
+
super().__init__(config)
|
706 |
+
self.model = BlueLMModel(config)
|
707 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
708 |
+
|
709 |
+
# Initialize weights and apply final processing
|
710 |
+
self.post_init()
|
711 |
+
|
712 |
+
def get_input_embeddings(self):
|
713 |
+
return self.model.embed_tokens
|
714 |
+
|
715 |
+
def set_input_embeddings(self, value):
|
716 |
+
self.model.embed_tokens = value
|
717 |
+
|
718 |
+
def get_output_embeddings(self):
|
719 |
+
return self.lm_head
|
720 |
+
|
721 |
+
def set_output_embeddings(self, new_embeddings):
|
722 |
+
self.lm_head = new_embeddings
|
723 |
+
|
724 |
+
def set_decoder(self, decoder):
|
725 |
+
self.model = decoder
|
726 |
+
|
727 |
+
def get_decoder(self):
|
728 |
+
return self.model
|
729 |
+
|
730 |
+
@replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
731 |
+
def forward(
|
732 |
+
self,
|
733 |
+
input_ids: torch.LongTensor = None,
|
734 |
+
attention_mask: Optional[torch.Tensor] = None,
|
735 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
736 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
737 |
+
labels: Optional[torch.LongTensor] = None,
|
738 |
+
use_cache: Optional[bool] = None,
|
739 |
+
output_attentions: Optional[bool] = None,
|
740 |
+
output_hidden_states: Optional[bool] = None,
|
741 |
+
return_dict: Optional[bool] = None,
|
742 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
743 |
+
r"""
|
744 |
+
Args:
|
745 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
746 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
|
747 |
+
provide it.
|
748 |
+
|
749 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
750 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
751 |
+
|
752 |
+
[What are input IDs?](../glossary#input-ids)
|
753 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
754 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
755 |
+
|
756 |
+
- 1 for tokens that are **not masked**,
|
757 |
+
- 0 for tokens that are **masked**.
|
758 |
+
|
759 |
+
[What are attention masks?](../glossary#attention-mask)
|
760 |
+
past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
761 |
+
Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
762 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of
|
763 |
+
shape `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`. The two additional
|
764 |
+
tensors are only required when the model is used as a decoder in a Sequence to Sequence model.
|
765 |
+
|
766 |
+
Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
|
767 |
+
cross-attention blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.
|
768 |
+
|
769 |
+
If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those
|
770 |
+
that don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of
|
771 |
+
all `decoder_input_ids` of shape `(batch_size, sequence_length)`.
|
772 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
773 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
|
774 |
+
This is useful if you want more control over how to convert `input_ids` indices into associated vectors
|
775 |
+
than the model's internal embedding lookup matrix.
|
776 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
777 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
778 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
779 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
780 |
+
use_cache (`bool`, *optional*):
|
781 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
782 |
+
(see `past_key_values`).
|
783 |
+
output_attentions (`bool`, *optional*):
|
784 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
785 |
+
returned tensors for more detail.
|
786 |
+
output_hidden_states (`bool`, *optional*):
|
787 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
|
788 |
+
for more detail.
|
789 |
+
return_dict (`bool`, *optional*):
|
790 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
791 |
+
|
792 |
+
Returns:
|
793 |
+
|
794 |
+
Example:
|
795 |
+
|
796 |
+
```python
|
797 |
+
>>> from transformers import AutoTokenizer, BlueLMForCausalLM
|
798 |
+
|
799 |
+
>>> model = BlueLMForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
|
800 |
+
>>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
|
801 |
+
|
802 |
+
>>> prompt = "Hey, are you consciours? Can you talk to me?"
|
803 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
804 |
+
|
805 |
+
>>> # Generate
|
806 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
807 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
808 |
+
"Hey, are you consciours? Can you talk to me?\nI'm not consciours, but I can talk to you."
|
809 |
+
```"""
|
810 |
+
|
811 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
812 |
+
output_hidden_states = (
|
813 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
814 |
+
)
|
815 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
816 |
+
|
817 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
818 |
+
outputs = self.model(
|
819 |
+
input_ids=input_ids,
|
820 |
+
attention_mask=attention_mask,
|
821 |
+
past_key_values=past_key_values,
|
822 |
+
inputs_embeds=inputs_embeds,
|
823 |
+
use_cache=use_cache,
|
824 |
+
output_attentions=output_attentions,
|
825 |
+
output_hidden_states=output_hidden_states,
|
826 |
+
return_dict=return_dict,
|
827 |
+
)
|
828 |
+
|
829 |
+
hidden_states = outputs[0]
|
830 |
+
logits = self.lm_head(hidden_states)
|
831 |
+
|
832 |
+
loss = None
|
833 |
+
if labels is not None:
|
834 |
+
# Shift so that tokens < n predict n
|
835 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
836 |
+
shift_labels = labels[..., 1:].contiguous()
|
837 |
+
# Flatten the tokens
|
838 |
+
loss_fct = CrossEntropyLoss()
|
839 |
+
shift_logits = shift_logits.view(-1, self.config.vocab_size)
|
840 |
+
shift_labels = shift_labels.view(-1)
|
841 |
+
# Enable model/pipeline parallelism
|
842 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
843 |
+
loss = loss_fct(shift_logits, shift_labels)
|
844 |
+
|
845 |
+
if not return_dict:
|
846 |
+
output = (logits,) + outputs[1:]
|
847 |
+
return (loss,) + output if loss is not None else output
|
848 |
+
|
849 |
+
return CausalLMOutputWithPast(
|
850 |
+
loss=loss,
|
851 |
+
logits=logits,
|
852 |
+
past_key_values=outputs.past_key_values,
|
853 |
+
hidden_states=outputs.hidden_states,
|
854 |
+
attentions=outputs.attentions,
|
855 |
+
)
|
856 |
+
|
857 |
+
def prepare_inputs_for_generation(
|
858 |
+
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs
|
859 |
+
):
|
860 |
+
if past_key_values:
|
861 |
+
input_ids = input_ids[:, -1:]
|
862 |
+
|
863 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
864 |
+
if inputs_embeds is not None and past_key_values is None:
|
865 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
866 |
+
else:
|
867 |
+
model_inputs = {"input_ids": input_ids}
|
868 |
+
|
869 |
+
model_inputs.update(
|
870 |
+
{
|
871 |
+
"past_key_values": past_key_values,
|
872 |
+
"use_cache": kwargs.get("use_cache"),
|
873 |
+
"attention_mask": attention_mask,
|
874 |
+
}
|
875 |
+
)
|
876 |
+
return model_inputs
|
877 |
+
|
878 |
+
@staticmethod
|
879 |
+
def _reorder_cache(past_key_values, beam_idx):
|
880 |
+
reordered_past = ()
|
881 |
+
for layer_past in past_key_values:
|
882 |
+
reordered_past += (tuple(past_state.index_select(0, beam_idx) for past_state in layer_past),)
|
883 |
+
return reordered_past
|
884 |
+
|
885 |
+
|
886 |
+
@add_start_docstrings(
|
887 |
+
"""
|
888 |
+
The BlueLM Model transformer with a sequence classification head on top (linear layer).
|
889 |
+
|
890 |
+
[`BlueLMForSequenceClassification`] uses the last token in order to do the classification, as other causal models
|
891 |
+
(e.g. GPT-2) do.
|
892 |
+
|
893 |
+
Since it does classification on the last token, it requires to know the position of the last token. If a
|
894 |
+
`pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
|
895 |
+
no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
|
896 |
+
padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
|
897 |
+
each row of the batch).
|
898 |
+
""",
|
899 |
+
BlueLM_START_DOCSTRING,
|
900 |
+
)
|
901 |
+
class BlueLMForSequenceClassification(BlueLMPreTrainedModel):
|
902 |
+
_keys_to_ignore_on_load_missing = [r"lm_head.weight"]
|
903 |
+
|
904 |
+
def __init__(self, config):
|
905 |
+
super().__init__(config)
|
906 |
+
self.num_labels = config.num_labels
|
907 |
+
self.model = BlueLMModel(config)
|
908 |
+
self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
|
909 |
+
|
910 |
+
# Initialize weights and apply final processing
|
911 |
+
self.post_init()
|
912 |
+
|
913 |
+
def get_input_embeddings(self):
|
914 |
+
return self.model.embed_tokens
|
915 |
+
|
916 |
+
def set_input_embeddings(self, value):
|
917 |
+
self.model.embed_tokens = value
|
918 |
+
|
919 |
+
@add_start_docstrings_to_model_forward(BlueLM_INPUTS_DOCSTRING)
|
920 |
+
def forward(
|
921 |
+
self,
|
922 |
+
input_ids: torch.LongTensor = None,
|
923 |
+
attention_mask: Optional[torch.Tensor] = None,
|
924 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
925 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
926 |
+
labels: Optional[torch.LongTensor] = None,
|
927 |
+
use_cache: Optional[bool] = None,
|
928 |
+
output_attentions: Optional[bool] = None,
|
929 |
+
output_hidden_states: Optional[bool] = None,
|
930 |
+
return_dict: Optional[bool] = None,
|
931 |
+
) -> Union[Tuple, SequenceClassifierOutputWithPast]:
|
932 |
+
r"""
|
933 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
934 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
935 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
936 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
937 |
+
"""
|
938 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
939 |
+
|
940 |
+
transformer_outputs = self.model(
|
941 |
+
input_ids,
|
942 |
+
past_key_values=past_key_values,
|
943 |
+
attention_mask=attention_mask,
|
944 |
+
inputs_embeds=inputs_embeds,
|
945 |
+
use_cache=use_cache,
|
946 |
+
output_attentions=output_attentions,
|
947 |
+
output_hidden_states=output_hidden_states,
|
948 |
+
return_dict=return_dict,
|
949 |
+
)
|
950 |
+
hidden_states = transformer_outputs[0]
|
951 |
+
logits = self.score(hidden_states)
|
952 |
+
|
953 |
+
if input_ids is not None:
|
954 |
+
batch_size = input_ids.shape[0]
|
955 |
+
else:
|
956 |
+
batch_size = inputs_embeds.shape[0]
|
957 |
+
|
958 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
959 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
960 |
+
if self.config.pad_token_id is None:
|
961 |
+
sequence_lengths = -1
|
962 |
+
else:
|
963 |
+
if input_ids is not None:
|
964 |
+
sequence_lengths = (torch.ne(input_ids, self.config.pad_token_id).sum(-1) - 1).to(logits.device)
|
965 |
+
else:
|
966 |
+
sequence_lengths = -1
|
967 |
+
|
968 |
+
pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
|
969 |
+
|
970 |
+
loss = None
|
971 |
+
if labels is not None:
|
972 |
+
if self.config.problem_type is None:
|
973 |
+
if self.num_labels == 1:
|
974 |
+
self.config.problem_type = "regression"
|
975 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
976 |
+
self.config.problem_type = "single_label_classification"
|
977 |
+
else:
|
978 |
+
self.config.problem_type = "multi_label_classification"
|
979 |
+
|
980 |
+
if self.config.problem_type == "regression":
|
981 |
+
loss_fct = MSELoss()
|
982 |
+
if self.num_labels == 1:
|
983 |
+
loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
|
984 |
+
else:
|
985 |
+
loss = loss_fct(pooled_logits, labels)
|
986 |
+
elif self.config.problem_type == "single_label_classification":
|
987 |
+
loss_fct = CrossEntropyLoss()
|
988 |
+
loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
|
989 |
+
elif self.config.problem_type == "multi_label_classification":
|
990 |
+
loss_fct = BCEWithLogitsLoss()
|
991 |
+
loss = loss_fct(pooled_logits, labels)
|
992 |
+
if not return_dict:
|
993 |
+
output = (pooled_logits,) + transformer_outputs[1:]
|
994 |
+
return ((loss,) + output) if loss is not None else output
|
995 |
+
|
996 |
+
return SequenceClassifierOutputWithPast(
|
997 |
+
loss=loss,
|
998 |
+
logits=pooled_logits,
|
999 |
+
past_key_values=transformer_outputs.past_key_values,
|
1000 |
+
hidden_states=transformer_outputs.hidden_states,
|
1001 |
+
attentions=transformer_outputs.attentions,
|
1002 |
+
)
|
pytorch_model-00001-of-00008.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ef933e6a25091ecbe9e52b8627dda601e498875de74d30597d0a816c94af617c
|
3 |
+
size 1944118389
|
pytorch_model-00002-of-00008.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:541ff0b1d4ab4a76e1538bc6204b12d1553fff863c1f9676dac850d315ccb2af
|
3 |
+
size 1933671335
|
pytorch_model-00003-of-00008.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eb0add2168a6447bdc7f421afbfa65aa12fad4326ed483538d24efb8f9189cf6
|
3 |
+
size 1933671399
|
pytorch_model-00004-of-00008.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6bb485fd726e6960e0f4b2de2b947bc8684ed62aaecc630f4d21f05043ed2d74
|
3 |
+
size 1990294503
|
pytorch_model-00005-of-00008.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ba57a5a44b518a37e04f137afb3b0597fe00407b3356ee82516dd00726b07acd
|
3 |
+
size 1990294503
|
pytorch_model-00006-of-00008.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5504192816de89b069f3bee39100efc03475cf8cbd3b9e445be467bc0ed069ef
|
3 |
+
size 1990294503
|
pytorch_model-00007-of-00008.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:489e4d2657b77e01bddfaa8526ccf0c2d9d08404b75c3195dd598b408dae81da
|
3 |
+
size 1990303033
|
pytorch_model-00008-of-00008.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:85639818ea2ab05784a382a04a97f1333a29ba7761e700ca762170fb1fe50deb
|
3 |
+
size 819987370
|
pytorch_model.bin.index.json
ADDED
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 14592532480
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"lm_head.weight": "pytorch_model-00008-of-00008.bin",
|
7 |
+
"model.embed_layer_norm.bias": "pytorch_model-00001-of-00008.bin",
|
8 |
+
"model.embed_layer_norm.weight": "pytorch_model-00001-of-00008.bin",
|
9 |
+
"model.embed_tokens.weight": "pytorch_model-00001-of-00008.bin",
|
10 |
+
"model.layers.0.input_layernorm.weight": "pytorch_model-00001-of-00008.bin",
|
11 |
+
"model.layers.0.mlp.down_proj.weight": "pytorch_model-00001-of-00008.bin",
|
12 |
+
"model.layers.0.mlp.gate_proj.weight": "pytorch_model-00001-of-00008.bin",
|
13 |
+
"model.layers.0.mlp.up_proj.weight": "pytorch_model-00001-of-00008.bin",
|
14 |
+
"model.layers.0.post_attention_layernorm.weight": "pytorch_model-00001-of-00008.bin",
|
15 |
+
"model.layers.0.self_attn.k_proj.weight": "pytorch_model-00001-of-00008.bin",
|
16 |
+
"model.layers.0.self_attn.o_proj.weight": "pytorch_model-00001-of-00008.bin",
|
17 |
+
"model.layers.0.self_attn.q_proj.weight": "pytorch_model-00001-of-00008.bin",
|
18 |
+
"model.layers.0.self_attn.v_proj.weight": "pytorch_model-00001-of-00008.bin",
|
19 |
+
"model.layers.1.input_layernorm.weight": "pytorch_model-00001-of-00008.bin",
|
20 |
+
"model.layers.1.mlp.down_proj.weight": "pytorch_model-00001-of-00008.bin",
|
21 |
+
"model.layers.1.mlp.gate_proj.weight": "pytorch_model-00001-of-00008.bin",
|
22 |
+
"model.layers.1.mlp.up_proj.weight": "pytorch_model-00001-of-00008.bin",
|
23 |
+
"model.layers.1.post_attention_layernorm.weight": "pytorch_model-00001-of-00008.bin",
|
24 |
+
"model.layers.1.self_attn.k_proj.weight": "pytorch_model-00001-of-00008.bin",
|
25 |
+
"model.layers.1.self_attn.o_proj.weight": "pytorch_model-00001-of-00008.bin",
|
26 |
+
"model.layers.1.self_attn.q_proj.weight": "pytorch_model-00001-of-00008.bin",
|
27 |
+
"model.layers.1.self_attn.v_proj.weight": "pytorch_model-00001-of-00008.bin",
|
28 |
+
"model.layers.10.input_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
29 |
+
"model.layers.10.mlp.down_proj.weight": "pytorch_model-00003-of-00008.bin",
|
30 |
+
"model.layers.10.mlp.gate_proj.weight": "pytorch_model-00003-of-00008.bin",
|
31 |
+
"model.layers.10.mlp.up_proj.weight": "pytorch_model-00003-of-00008.bin",
|
32 |
+
"model.layers.10.post_attention_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
33 |
+
"model.layers.10.self_attn.k_proj.weight": "pytorch_model-00003-of-00008.bin",
|
34 |
+
"model.layers.10.self_attn.o_proj.weight": "pytorch_model-00003-of-00008.bin",
|
35 |
+
"model.layers.10.self_attn.q_proj.weight": "pytorch_model-00003-of-00008.bin",
|
36 |
+
"model.layers.10.self_attn.v_proj.weight": "pytorch_model-00003-of-00008.bin",
|
37 |
+
"model.layers.11.input_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
38 |
+
"model.layers.11.mlp.down_proj.weight": "pytorch_model-00003-of-00008.bin",
|
39 |
+
"model.layers.11.mlp.gate_proj.weight": "pytorch_model-00003-of-00008.bin",
|
40 |
+
"model.layers.11.mlp.up_proj.weight": "pytorch_model-00003-of-00008.bin",
|
41 |
+
"model.layers.11.post_attention_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
42 |
+
"model.layers.11.self_attn.k_proj.weight": "pytorch_model-00003-of-00008.bin",
|
43 |
+
"model.layers.11.self_attn.o_proj.weight": "pytorch_model-00003-of-00008.bin",
|
44 |
+
"model.layers.11.self_attn.q_proj.weight": "pytorch_model-00003-of-00008.bin",
|
45 |
+
"model.layers.11.self_attn.v_proj.weight": "pytorch_model-00003-of-00008.bin",
|
46 |
+
"model.layers.12.input_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
47 |
+
"model.layers.12.mlp.down_proj.weight": "pytorch_model-00004-of-00008.bin",
|
48 |
+
"model.layers.12.mlp.gate_proj.weight": "pytorch_model-00004-of-00008.bin",
|
49 |
+
"model.layers.12.mlp.up_proj.weight": "pytorch_model-00004-of-00008.bin",
|
50 |
+
"model.layers.12.post_attention_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
51 |
+
"model.layers.12.self_attn.k_proj.weight": "pytorch_model-00003-of-00008.bin",
|
52 |
+
"model.layers.12.self_attn.o_proj.weight": "pytorch_model-00003-of-00008.bin",
|
53 |
+
"model.layers.12.self_attn.q_proj.weight": "pytorch_model-00003-of-00008.bin",
|
54 |
+
"model.layers.12.self_attn.v_proj.weight": "pytorch_model-00003-of-00008.bin",
|
55 |
+
"model.layers.13.input_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
56 |
+
"model.layers.13.mlp.down_proj.weight": "pytorch_model-00004-of-00008.bin",
|
57 |
+
"model.layers.13.mlp.gate_proj.weight": "pytorch_model-00004-of-00008.bin",
|
58 |
+
"model.layers.13.mlp.up_proj.weight": "pytorch_model-00004-of-00008.bin",
|
59 |
+
"model.layers.13.post_attention_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
60 |
+
"model.layers.13.self_attn.k_proj.weight": "pytorch_model-00004-of-00008.bin",
|
61 |
+
"model.layers.13.self_attn.o_proj.weight": "pytorch_model-00004-of-00008.bin",
|
62 |
+
"model.layers.13.self_attn.q_proj.weight": "pytorch_model-00004-of-00008.bin",
|
63 |
+
"model.layers.13.self_attn.v_proj.weight": "pytorch_model-00004-of-00008.bin",
|
64 |
+
"model.layers.14.input_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
65 |
+
"model.layers.14.mlp.down_proj.weight": "pytorch_model-00004-of-00008.bin",
|
66 |
+
"model.layers.14.mlp.gate_proj.weight": "pytorch_model-00004-of-00008.bin",
|
67 |
+
"model.layers.14.mlp.up_proj.weight": "pytorch_model-00004-of-00008.bin",
|
68 |
+
"model.layers.14.post_attention_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
69 |
+
"model.layers.14.self_attn.k_proj.weight": "pytorch_model-00004-of-00008.bin",
|
70 |
+
"model.layers.14.self_attn.o_proj.weight": "pytorch_model-00004-of-00008.bin",
|
71 |
+
"model.layers.14.self_attn.q_proj.weight": "pytorch_model-00004-of-00008.bin",
|
72 |
+
"model.layers.14.self_attn.v_proj.weight": "pytorch_model-00004-of-00008.bin",
|
73 |
+
"model.layers.15.input_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
74 |
+
"model.layers.15.mlp.down_proj.weight": "pytorch_model-00004-of-00008.bin",
|
75 |
+
"model.layers.15.mlp.gate_proj.weight": "pytorch_model-00004-of-00008.bin",
|
76 |
+
"model.layers.15.mlp.up_proj.weight": "pytorch_model-00004-of-00008.bin",
|
77 |
+
"model.layers.15.post_attention_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
78 |
+
"model.layers.15.self_attn.k_proj.weight": "pytorch_model-00004-of-00008.bin",
|
79 |
+
"model.layers.15.self_attn.o_proj.weight": "pytorch_model-00004-of-00008.bin",
|
80 |
+
"model.layers.15.self_attn.q_proj.weight": "pytorch_model-00004-of-00008.bin",
|
81 |
+
"model.layers.15.self_attn.v_proj.weight": "pytorch_model-00004-of-00008.bin",
|
82 |
+
"model.layers.16.input_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
83 |
+
"model.layers.16.mlp.down_proj.weight": "pytorch_model-00004-of-00008.bin",
|
84 |
+
"model.layers.16.mlp.gate_proj.weight": "pytorch_model-00004-of-00008.bin",
|
85 |
+
"model.layers.16.mlp.up_proj.weight": "pytorch_model-00004-of-00008.bin",
|
86 |
+
"model.layers.16.post_attention_layernorm.weight": "pytorch_model-00004-of-00008.bin",
|
87 |
+
"model.layers.16.self_attn.k_proj.weight": "pytorch_model-00004-of-00008.bin",
|
88 |
+
"model.layers.16.self_attn.o_proj.weight": "pytorch_model-00004-of-00008.bin",
|
89 |
+
"model.layers.16.self_attn.q_proj.weight": "pytorch_model-00004-of-00008.bin",
|
90 |
+
"model.layers.16.self_attn.v_proj.weight": "pytorch_model-00004-of-00008.bin",
|
91 |
+
"model.layers.17.input_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
92 |
+
"model.layers.17.mlp.down_proj.weight": "pytorch_model-00005-of-00008.bin",
|
93 |
+
"model.layers.17.mlp.gate_proj.weight": "pytorch_model-00005-of-00008.bin",
|
94 |
+
"model.layers.17.mlp.up_proj.weight": "pytorch_model-00005-of-00008.bin",
|
95 |
+
"model.layers.17.post_attention_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
96 |
+
"model.layers.17.self_attn.k_proj.weight": "pytorch_model-00004-of-00008.bin",
|
97 |
+
"model.layers.17.self_attn.o_proj.weight": "pytorch_model-00005-of-00008.bin",
|
98 |
+
"model.layers.17.self_attn.q_proj.weight": "pytorch_model-00004-of-00008.bin",
|
99 |
+
"model.layers.17.self_attn.v_proj.weight": "pytorch_model-00004-of-00008.bin",
|
100 |
+
"model.layers.18.input_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
101 |
+
"model.layers.18.mlp.down_proj.weight": "pytorch_model-00005-of-00008.bin",
|
102 |
+
"model.layers.18.mlp.gate_proj.weight": "pytorch_model-00005-of-00008.bin",
|
103 |
+
"model.layers.18.mlp.up_proj.weight": "pytorch_model-00005-of-00008.bin",
|
104 |
+
"model.layers.18.post_attention_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
105 |
+
"model.layers.18.self_attn.k_proj.weight": "pytorch_model-00005-of-00008.bin",
|
106 |
+
"model.layers.18.self_attn.o_proj.weight": "pytorch_model-00005-of-00008.bin",
|
107 |
+
"model.layers.18.self_attn.q_proj.weight": "pytorch_model-00005-of-00008.bin",
|
108 |
+
"model.layers.18.self_attn.v_proj.weight": "pytorch_model-00005-of-00008.bin",
|
109 |
+
"model.layers.19.input_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
110 |
+
"model.layers.19.mlp.down_proj.weight": "pytorch_model-00005-of-00008.bin",
|
111 |
+
"model.layers.19.mlp.gate_proj.weight": "pytorch_model-00005-of-00008.bin",
|
112 |
+
"model.layers.19.mlp.up_proj.weight": "pytorch_model-00005-of-00008.bin",
|
113 |
+
"model.layers.19.post_attention_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
114 |
+
"model.layers.19.self_attn.k_proj.weight": "pytorch_model-00005-of-00008.bin",
|
115 |
+
"model.layers.19.self_attn.o_proj.weight": "pytorch_model-00005-of-00008.bin",
|
116 |
+
"model.layers.19.self_attn.q_proj.weight": "pytorch_model-00005-of-00008.bin",
|
117 |
+
"model.layers.19.self_attn.v_proj.weight": "pytorch_model-00005-of-00008.bin",
|
118 |
+
"model.layers.2.input_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
119 |
+
"model.layers.2.mlp.down_proj.weight": "pytorch_model-00001-of-00008.bin",
|
120 |
+
"model.layers.2.mlp.gate_proj.weight": "pytorch_model-00001-of-00008.bin",
|
121 |
+
"model.layers.2.mlp.up_proj.weight": "pytorch_model-00002-of-00008.bin",
|
122 |
+
"model.layers.2.post_attention_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
123 |
+
"model.layers.2.self_attn.k_proj.weight": "pytorch_model-00001-of-00008.bin",
|
124 |
+
"model.layers.2.self_attn.o_proj.weight": "pytorch_model-00001-of-00008.bin",
|
125 |
+
"model.layers.2.self_attn.q_proj.weight": "pytorch_model-00001-of-00008.bin",
|
126 |
+
"model.layers.2.self_attn.v_proj.weight": "pytorch_model-00001-of-00008.bin",
|
127 |
+
"model.layers.20.input_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
128 |
+
"model.layers.20.mlp.down_proj.weight": "pytorch_model-00005-of-00008.bin",
|
129 |
+
"model.layers.20.mlp.gate_proj.weight": "pytorch_model-00005-of-00008.bin",
|
130 |
+
"model.layers.20.mlp.up_proj.weight": "pytorch_model-00005-of-00008.bin",
|
131 |
+
"model.layers.20.post_attention_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
132 |
+
"model.layers.20.self_attn.k_proj.weight": "pytorch_model-00005-of-00008.bin",
|
133 |
+
"model.layers.20.self_attn.o_proj.weight": "pytorch_model-00005-of-00008.bin",
|
134 |
+
"model.layers.20.self_attn.q_proj.weight": "pytorch_model-00005-of-00008.bin",
|
135 |
+
"model.layers.20.self_attn.v_proj.weight": "pytorch_model-00005-of-00008.bin",
|
136 |
+
"model.layers.21.input_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
137 |
+
"model.layers.21.mlp.down_proj.weight": "pytorch_model-00005-of-00008.bin",
|
138 |
+
"model.layers.21.mlp.gate_proj.weight": "pytorch_model-00005-of-00008.bin",
|
139 |
+
"model.layers.21.mlp.up_proj.weight": "pytorch_model-00005-of-00008.bin",
|
140 |
+
"model.layers.21.post_attention_layernorm.weight": "pytorch_model-00005-of-00008.bin",
|
141 |
+
"model.layers.21.self_attn.k_proj.weight": "pytorch_model-00005-of-00008.bin",
|
142 |
+
"model.layers.21.self_attn.o_proj.weight": "pytorch_model-00005-of-00008.bin",
|
143 |
+
"model.layers.21.self_attn.q_proj.weight": "pytorch_model-00005-of-00008.bin",
|
144 |
+
"model.layers.21.self_attn.v_proj.weight": "pytorch_model-00005-of-00008.bin",
|
145 |
+
"model.layers.22.input_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
146 |
+
"model.layers.22.mlp.down_proj.weight": "pytorch_model-00006-of-00008.bin",
|
147 |
+
"model.layers.22.mlp.gate_proj.weight": "pytorch_model-00006-of-00008.bin",
|
148 |
+
"model.layers.22.mlp.up_proj.weight": "pytorch_model-00006-of-00008.bin",
|
149 |
+
"model.layers.22.post_attention_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
150 |
+
"model.layers.22.self_attn.k_proj.weight": "pytorch_model-00005-of-00008.bin",
|
151 |
+
"model.layers.22.self_attn.o_proj.weight": "pytorch_model-00006-of-00008.bin",
|
152 |
+
"model.layers.22.self_attn.q_proj.weight": "pytorch_model-00005-of-00008.bin",
|
153 |
+
"model.layers.22.self_attn.v_proj.weight": "pytorch_model-00006-of-00008.bin",
|
154 |
+
"model.layers.23.input_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
155 |
+
"model.layers.23.mlp.down_proj.weight": "pytorch_model-00006-of-00008.bin",
|
156 |
+
"model.layers.23.mlp.gate_proj.weight": "pytorch_model-00006-of-00008.bin",
|
157 |
+
"model.layers.23.mlp.up_proj.weight": "pytorch_model-00006-of-00008.bin",
|
158 |
+
"model.layers.23.post_attention_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
159 |
+
"model.layers.23.self_attn.k_proj.weight": "pytorch_model-00006-of-00008.bin",
|
160 |
+
"model.layers.23.self_attn.o_proj.weight": "pytorch_model-00006-of-00008.bin",
|
161 |
+
"model.layers.23.self_attn.q_proj.weight": "pytorch_model-00006-of-00008.bin",
|
162 |
+
"model.layers.23.self_attn.v_proj.weight": "pytorch_model-00006-of-00008.bin",
|
163 |
+
"model.layers.24.input_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
164 |
+
"model.layers.24.mlp.down_proj.weight": "pytorch_model-00006-of-00008.bin",
|
165 |
+
"model.layers.24.mlp.gate_proj.weight": "pytorch_model-00006-of-00008.bin",
|
166 |
+
"model.layers.24.mlp.up_proj.weight": "pytorch_model-00006-of-00008.bin",
|
167 |
+
"model.layers.24.post_attention_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
168 |
+
"model.layers.24.self_attn.k_proj.weight": "pytorch_model-00006-of-00008.bin",
|
169 |
+
"model.layers.24.self_attn.o_proj.weight": "pytorch_model-00006-of-00008.bin",
|
170 |
+
"model.layers.24.self_attn.q_proj.weight": "pytorch_model-00006-of-00008.bin",
|
171 |
+
"model.layers.24.self_attn.v_proj.weight": "pytorch_model-00006-of-00008.bin",
|
172 |
+
"model.layers.25.input_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
173 |
+
"model.layers.25.mlp.down_proj.weight": "pytorch_model-00006-of-00008.bin",
|
174 |
+
"model.layers.25.mlp.gate_proj.weight": "pytorch_model-00006-of-00008.bin",
|
175 |
+
"model.layers.25.mlp.up_proj.weight": "pytorch_model-00006-of-00008.bin",
|
176 |
+
"model.layers.25.post_attention_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
177 |
+
"model.layers.25.self_attn.k_proj.weight": "pytorch_model-00006-of-00008.bin",
|
178 |
+
"model.layers.25.self_attn.o_proj.weight": "pytorch_model-00006-of-00008.bin",
|
179 |
+
"model.layers.25.self_attn.q_proj.weight": "pytorch_model-00006-of-00008.bin",
|
180 |
+
"model.layers.25.self_attn.v_proj.weight": "pytorch_model-00006-of-00008.bin",
|
181 |
+
"model.layers.26.input_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
182 |
+
"model.layers.26.mlp.down_proj.weight": "pytorch_model-00006-of-00008.bin",
|
183 |
+
"model.layers.26.mlp.gate_proj.weight": "pytorch_model-00006-of-00008.bin",
|
184 |
+
"model.layers.26.mlp.up_proj.weight": "pytorch_model-00006-of-00008.bin",
|
185 |
+
"model.layers.26.post_attention_layernorm.weight": "pytorch_model-00006-of-00008.bin",
|
186 |
+
"model.layers.26.self_attn.k_proj.weight": "pytorch_model-00006-of-00008.bin",
|
187 |
+
"model.layers.26.self_attn.o_proj.weight": "pytorch_model-00006-of-00008.bin",
|
188 |
+
"model.layers.26.self_attn.q_proj.weight": "pytorch_model-00006-of-00008.bin",
|
189 |
+
"model.layers.26.self_attn.v_proj.weight": "pytorch_model-00006-of-00008.bin",
|
190 |
+
"model.layers.27.input_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
191 |
+
"model.layers.27.mlp.down_proj.weight": "pytorch_model-00007-of-00008.bin",
|
192 |
+
"model.layers.27.mlp.gate_proj.weight": "pytorch_model-00007-of-00008.bin",
|
193 |
+
"model.layers.27.mlp.up_proj.weight": "pytorch_model-00007-of-00008.bin",
|
194 |
+
"model.layers.27.post_attention_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
195 |
+
"model.layers.27.self_attn.k_proj.weight": "pytorch_model-00007-of-00008.bin",
|
196 |
+
"model.layers.27.self_attn.o_proj.weight": "pytorch_model-00007-of-00008.bin",
|
197 |
+
"model.layers.27.self_attn.q_proj.weight": "pytorch_model-00006-of-00008.bin",
|
198 |
+
"model.layers.27.self_attn.v_proj.weight": "pytorch_model-00007-of-00008.bin",
|
199 |
+
"model.layers.28.input_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
200 |
+
"model.layers.28.mlp.down_proj.weight": "pytorch_model-00007-of-00008.bin",
|
201 |
+
"model.layers.28.mlp.gate_proj.weight": "pytorch_model-00007-of-00008.bin",
|
202 |
+
"model.layers.28.mlp.up_proj.weight": "pytorch_model-00007-of-00008.bin",
|
203 |
+
"model.layers.28.post_attention_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
204 |
+
"model.layers.28.self_attn.k_proj.weight": "pytorch_model-00007-of-00008.bin",
|
205 |
+
"model.layers.28.self_attn.o_proj.weight": "pytorch_model-00007-of-00008.bin",
|
206 |
+
"model.layers.28.self_attn.q_proj.weight": "pytorch_model-00007-of-00008.bin",
|
207 |
+
"model.layers.28.self_attn.v_proj.weight": "pytorch_model-00007-of-00008.bin",
|
208 |
+
"model.layers.29.input_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
209 |
+
"model.layers.29.mlp.down_proj.weight": "pytorch_model-00007-of-00008.bin",
|
210 |
+
"model.layers.29.mlp.gate_proj.weight": "pytorch_model-00007-of-00008.bin",
|
211 |
+
"model.layers.29.mlp.up_proj.weight": "pytorch_model-00007-of-00008.bin",
|
212 |
+
"model.layers.29.post_attention_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
213 |
+
"model.layers.29.self_attn.k_proj.weight": "pytorch_model-00007-of-00008.bin",
|
214 |
+
"model.layers.29.self_attn.o_proj.weight": "pytorch_model-00007-of-00008.bin",
|
215 |
+
"model.layers.29.self_attn.q_proj.weight": "pytorch_model-00007-of-00008.bin",
|
216 |
+
"model.layers.29.self_attn.v_proj.weight": "pytorch_model-00007-of-00008.bin",
|
217 |
+
"model.layers.3.input_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
218 |
+
"model.layers.3.mlp.down_proj.weight": "pytorch_model-00002-of-00008.bin",
|
219 |
+
"model.layers.3.mlp.gate_proj.weight": "pytorch_model-00002-of-00008.bin",
|
220 |
+
"model.layers.3.mlp.up_proj.weight": "pytorch_model-00002-of-00008.bin",
|
221 |
+
"model.layers.3.post_attention_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
222 |
+
"model.layers.3.self_attn.k_proj.weight": "pytorch_model-00002-of-00008.bin",
|
223 |
+
"model.layers.3.self_attn.o_proj.weight": "pytorch_model-00002-of-00008.bin",
|
224 |
+
"model.layers.3.self_attn.q_proj.weight": "pytorch_model-00002-of-00008.bin",
|
225 |
+
"model.layers.3.self_attn.v_proj.weight": "pytorch_model-00002-of-00008.bin",
|
226 |
+
"model.layers.30.input_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
227 |
+
"model.layers.30.mlp.down_proj.weight": "pytorch_model-00007-of-00008.bin",
|
228 |
+
"model.layers.30.mlp.gate_proj.weight": "pytorch_model-00007-of-00008.bin",
|
229 |
+
"model.layers.30.mlp.up_proj.weight": "pytorch_model-00007-of-00008.bin",
|
230 |
+
"model.layers.30.post_attention_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
231 |
+
"model.layers.30.self_attn.k_proj.weight": "pytorch_model-00007-of-00008.bin",
|
232 |
+
"model.layers.30.self_attn.o_proj.weight": "pytorch_model-00007-of-00008.bin",
|
233 |
+
"model.layers.30.self_attn.q_proj.weight": "pytorch_model-00007-of-00008.bin",
|
234 |
+
"model.layers.30.self_attn.v_proj.weight": "pytorch_model-00007-of-00008.bin",
|
235 |
+
"model.layers.31.input_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
236 |
+
"model.layers.31.mlp.down_proj.weight": "pytorch_model-00007-of-00008.bin",
|
237 |
+
"model.layers.31.mlp.gate_proj.weight": "pytorch_model-00007-of-00008.bin",
|
238 |
+
"model.layers.31.mlp.up_proj.weight": "pytorch_model-00007-of-00008.bin",
|
239 |
+
"model.layers.31.post_attention_layernorm.weight": "pytorch_model-00007-of-00008.bin",
|
240 |
+
"model.layers.31.self_attn.k_proj.weight": "pytorch_model-00007-of-00008.bin",
|
241 |
+
"model.layers.31.self_attn.o_proj.weight": "pytorch_model-00007-of-00008.bin",
|
242 |
+
"model.layers.31.self_attn.q_proj.weight": "pytorch_model-00007-of-00008.bin",
|
243 |
+
"model.layers.31.self_attn.v_proj.weight": "pytorch_model-00007-of-00008.bin",
|
244 |
+
"model.layers.4.input_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
245 |
+
"model.layers.4.mlp.down_proj.weight": "pytorch_model-00002-of-00008.bin",
|
246 |
+
"model.layers.4.mlp.gate_proj.weight": "pytorch_model-00002-of-00008.bin",
|
247 |
+
"model.layers.4.mlp.up_proj.weight": "pytorch_model-00002-of-00008.bin",
|
248 |
+
"model.layers.4.post_attention_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
249 |
+
"model.layers.4.self_attn.k_proj.weight": "pytorch_model-00002-of-00008.bin",
|
250 |
+
"model.layers.4.self_attn.o_proj.weight": "pytorch_model-00002-of-00008.bin",
|
251 |
+
"model.layers.4.self_attn.q_proj.weight": "pytorch_model-00002-of-00008.bin",
|
252 |
+
"model.layers.4.self_attn.v_proj.weight": "pytorch_model-00002-of-00008.bin",
|
253 |
+
"model.layers.5.input_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
254 |
+
"model.layers.5.mlp.down_proj.weight": "pytorch_model-00002-of-00008.bin",
|
255 |
+
"model.layers.5.mlp.gate_proj.weight": "pytorch_model-00002-of-00008.bin",
|
256 |
+
"model.layers.5.mlp.up_proj.weight": "pytorch_model-00002-of-00008.bin",
|
257 |
+
"model.layers.5.post_attention_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
258 |
+
"model.layers.5.self_attn.k_proj.weight": "pytorch_model-00002-of-00008.bin",
|
259 |
+
"model.layers.5.self_attn.o_proj.weight": "pytorch_model-00002-of-00008.bin",
|
260 |
+
"model.layers.5.self_attn.q_proj.weight": "pytorch_model-00002-of-00008.bin",
|
261 |
+
"model.layers.5.self_attn.v_proj.weight": "pytorch_model-00002-of-00008.bin",
|
262 |
+
"model.layers.6.input_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
263 |
+
"model.layers.6.mlp.down_proj.weight": "pytorch_model-00002-of-00008.bin",
|
264 |
+
"model.layers.6.mlp.gate_proj.weight": "pytorch_model-00002-of-00008.bin",
|
265 |
+
"model.layers.6.mlp.up_proj.weight": "pytorch_model-00002-of-00008.bin",
|
266 |
+
"model.layers.6.post_attention_layernorm.weight": "pytorch_model-00002-of-00008.bin",
|
267 |
+
"model.layers.6.self_attn.k_proj.weight": "pytorch_model-00002-of-00008.bin",
|
268 |
+
"model.layers.6.self_attn.o_proj.weight": "pytorch_model-00002-of-00008.bin",
|
269 |
+
"model.layers.6.self_attn.q_proj.weight": "pytorch_model-00002-of-00008.bin",
|
270 |
+
"model.layers.6.self_attn.v_proj.weight": "pytorch_model-00002-of-00008.bin",
|
271 |
+
"model.layers.7.input_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
272 |
+
"model.layers.7.mlp.down_proj.weight": "pytorch_model-00003-of-00008.bin",
|
273 |
+
"model.layers.7.mlp.gate_proj.weight": "pytorch_model-00002-of-00008.bin",
|
274 |
+
"model.layers.7.mlp.up_proj.weight": "pytorch_model-00003-of-00008.bin",
|
275 |
+
"model.layers.7.post_attention_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
276 |
+
"model.layers.7.self_attn.k_proj.weight": "pytorch_model-00002-of-00008.bin",
|
277 |
+
"model.layers.7.self_attn.o_proj.weight": "pytorch_model-00002-of-00008.bin",
|
278 |
+
"model.layers.7.self_attn.q_proj.weight": "pytorch_model-00002-of-00008.bin",
|
279 |
+
"model.layers.7.self_attn.v_proj.weight": "pytorch_model-00002-of-00008.bin",
|
280 |
+
"model.layers.8.input_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
281 |
+
"model.layers.8.mlp.down_proj.weight": "pytorch_model-00003-of-00008.bin",
|
282 |
+
"model.layers.8.mlp.gate_proj.weight": "pytorch_model-00003-of-00008.bin",
|
283 |
+
"model.layers.8.mlp.up_proj.weight": "pytorch_model-00003-of-00008.bin",
|
284 |
+
"model.layers.8.post_attention_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
285 |
+
"model.layers.8.self_attn.k_proj.weight": "pytorch_model-00003-of-00008.bin",
|
286 |
+
"model.layers.8.self_attn.o_proj.weight": "pytorch_model-00003-of-00008.bin",
|
287 |
+
"model.layers.8.self_attn.q_proj.weight": "pytorch_model-00003-of-00008.bin",
|
288 |
+
"model.layers.8.self_attn.v_proj.weight": "pytorch_model-00003-of-00008.bin",
|
289 |
+
"model.layers.9.input_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
290 |
+
"model.layers.9.mlp.down_proj.weight": "pytorch_model-00003-of-00008.bin",
|
291 |
+
"model.layers.9.mlp.gate_proj.weight": "pytorch_model-00003-of-00008.bin",
|
292 |
+
"model.layers.9.mlp.up_proj.weight": "pytorch_model-00003-of-00008.bin",
|
293 |
+
"model.layers.9.post_attention_layernorm.weight": "pytorch_model-00003-of-00008.bin",
|
294 |
+
"model.layers.9.self_attn.k_proj.weight": "pytorch_model-00003-of-00008.bin",
|
295 |
+
"model.layers.9.self_attn.o_proj.weight": "pytorch_model-00003-of-00008.bin",
|
296 |
+
"model.layers.9.self_attn.q_proj.weight": "pytorch_model-00003-of-00008.bin",
|
297 |
+
"model.layers.9.self_attn.v_proj.weight": "pytorch_model-00003-of-00008.bin",
|
298 |
+
"model.norm.weight": "pytorch_model-00007-of-00008.bin"
|
299 |
+
}
|
300 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"[|Human|]:",
|
4 |
+
"[|AI|]:",
|
5 |
+
"[SEH]",
|
6 |
+
"[SEA]"
|
7 |
+
],
|
8 |
+
"bos_token": {
|
9 |
+
"content": "<s>",
|
10 |
+
"lstrip": false,
|
11 |
+
"normalized": true,
|
12 |
+
"rstrip": false,
|
13 |
+
"single_word": false
|
14 |
+
},
|
15 |
+
"eos_token": {
|
16 |
+
"content": "</s>",
|
17 |
+
"lstrip": false,
|
18 |
+
"normalized": true,
|
19 |
+
"rstrip": false,
|
20 |
+
"single_word": false
|
21 |
+
},
|
22 |
+
"pad_token": {
|
23 |
+
"content": "<pad>",
|
24 |
+
"lstrip": false,
|
25 |
+
"normalized": true,
|
26 |
+
"rstrip": false,
|
27 |
+
"single_word": false
|
28 |
+
},
|
29 |
+
"unk_token": {
|
30 |
+
"content": "<unk>",
|
31 |
+
"lstrip": false,
|
32 |
+
"normalized": true,
|
33 |
+
"rstrip": false,
|
34 |
+
"single_word": false
|
35 |
+
}
|
36 |
+
}
|
tokenization_bluelm.py
ADDED
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
5 |
+
# and OPT implementations in this library. It has been modified from its
|
6 |
+
# original forms to accommodate minor architectural differences compared
|
7 |
+
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
8 |
+
#
|
9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10 |
+
# you may not use this file except in compliance with the License.
|
11 |
+
# You may obtain a copy of the License at
|
12 |
+
#
|
13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14 |
+
#
|
15 |
+
# Unless required by applicable law or agreed to in writing, software
|
16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18 |
+
# See the License for the specific language governing permissions and
|
19 |
+
# limitations under the License.
|
20 |
+
|
21 |
+
"""Tokenization classes for BlueLM."""
|
22 |
+
import os
|
23 |
+
from shutil import copyfile
|
24 |
+
from typing import Any, Dict, List, Optional, Tuple
|
25 |
+
|
26 |
+
import sentencepiece as spm
|
27 |
+
|
28 |
+
from transformers.tokenization_utils import AddedToken, PreTrainedTokenizer
|
29 |
+
from transformers.utils import logging
|
30 |
+
|
31 |
+
|
32 |
+
logger = logging.get_logger(__name__)
|
33 |
+
|
34 |
+
VOCAB_FILES_NAMES = {"vocab_file": "tokenizer.model"}
|
35 |
+
|
36 |
+
PRETRAINED_VOCAB_FILES_MAP = {
|
37 |
+
"vocab_file": {},
|
38 |
+
"tokenizer_file": {},
|
39 |
+
}
|
40 |
+
PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES = {}
|
41 |
+
|
42 |
+
|
43 |
+
class BlueLMTokenizer(PreTrainedTokenizer):
|
44 |
+
"""
|
45 |
+
Construct a BlueLM tokenizer. Based on byte-level Byte-Pair-Encoding.
|
46 |
+
|
47 |
+
Args:
|
48 |
+
vocab_file (`str`):
|
49 |
+
Path to the vocabulary file.
|
50 |
+
"""
|
51 |
+
|
52 |
+
vocab_files_names = VOCAB_FILES_NAMES
|
53 |
+
pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
|
54 |
+
max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
|
55 |
+
model_input_names = ["input_ids", "attention_mask"]
|
56 |
+
|
57 |
+
def __init__(
|
58 |
+
self,
|
59 |
+
vocab_file,
|
60 |
+
unk_token="<unk>",
|
61 |
+
bos_token="<s>",
|
62 |
+
eos_token="</s>",
|
63 |
+
pad_token=None,
|
64 |
+
sp_model_kwargs: Optional[Dict[str, Any]] = None,
|
65 |
+
add_bos_token=True,
|
66 |
+
add_eos_token=False,
|
67 |
+
clean_up_tokenization_spaces=False,
|
68 |
+
**kwargs,
|
69 |
+
):
|
70 |
+
self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
|
71 |
+
bos_token = AddedToken(bos_token, lstrip=False, rstrip=False) if isinstance(bos_token, str) else bos_token
|
72 |
+
eos_token = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_token
|
73 |
+
unk_token = AddedToken(unk_token, lstrip=False, rstrip=False) if isinstance(unk_token, str) else unk_token
|
74 |
+
pad_token = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_token
|
75 |
+
super().__init__(
|
76 |
+
bos_token=bos_token,
|
77 |
+
eos_token=eos_token,
|
78 |
+
unk_token=unk_token,
|
79 |
+
pad_token=pad_token,
|
80 |
+
add_bos_token=add_bos_token,
|
81 |
+
add_eos_token=add_eos_token,
|
82 |
+
sp_model_kwargs=self.sp_model_kwargs,
|
83 |
+
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
|
84 |
+
**kwargs,
|
85 |
+
)
|
86 |
+
self.vocab_file = vocab_file
|
87 |
+
self.add_bos_token = add_bos_token
|
88 |
+
self.add_eos_token = add_eos_token
|
89 |
+
self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
|
90 |
+
self.sp_model.Load(vocab_file)
|
91 |
+
|
92 |
+
def __getstate__(self):
|
93 |
+
state = self.__dict__.copy()
|
94 |
+
state["sp_model"] = None
|
95 |
+
return state
|
96 |
+
|
97 |
+
def __setstate__(self, d):
|
98 |
+
self.__dict__ = d
|
99 |
+
self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
|
100 |
+
self.sp_model.Load(self.vocab_file)
|
101 |
+
|
102 |
+
@property
|
103 |
+
def vocab_size(self):
|
104 |
+
"""Returns vocab size"""
|
105 |
+
return self.sp_model.get_piece_size()
|
106 |
+
|
107 |
+
def get_vocab(self):
|
108 |
+
"""Returns vocab as a dict"""
|
109 |
+
vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
|
110 |
+
vocab.update(self.added_tokens_encoder)
|
111 |
+
return vocab
|
112 |
+
|
113 |
+
def _tokenize(self, text):
|
114 |
+
"""Returns a tokenized string."""
|
115 |
+
return self.sp_model.encode(text, out_type=str)
|
116 |
+
|
117 |
+
def _convert_token_to_id(self, token):
|
118 |
+
"""Converts a token (str) in an id using the vocab."""
|
119 |
+
return self.sp_model.piece_to_id(token)
|
120 |
+
|
121 |
+
def _convert_id_to_token(self, index):
|
122 |
+
"""Converts an index (integer) in a token (str) using the vocab."""
|
123 |
+
token = self.sp_model.IdToPiece(index)
|
124 |
+
return token
|
125 |
+
|
126 |
+
def convert_tokens_to_string(self, tokens):
|
127 |
+
"""Converts a sequence of tokens (string) in a single string."""
|
128 |
+
current_sub_tokens = []
|
129 |
+
out_string = ""
|
130 |
+
prev_is_special = False
|
131 |
+
for i, token in enumerate(tokens):
|
132 |
+
# make sure that special tokens are not decoded using sentencepiece model
|
133 |
+
if token in self.all_special_tokens:
|
134 |
+
if not prev_is_special and i != 0:
|
135 |
+
out_string += " "
|
136 |
+
out_string += self.sp_model.decode(current_sub_tokens) + token
|
137 |
+
prev_is_special = True
|
138 |
+
current_sub_tokens = []
|
139 |
+
else:
|
140 |
+
current_sub_tokens.append(token)
|
141 |
+
prev_is_special = False
|
142 |
+
out_string += self.sp_model.decode(current_sub_tokens)
|
143 |
+
return out_string
|
144 |
+
|
145 |
+
def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]:
|
146 |
+
"""
|
147 |
+
Save the vocabulary and special tokens file to a directory.
|
148 |
+
|
149 |
+
Args:
|
150 |
+
save_directory (`str`):
|
151 |
+
The directory in which to save the vocabulary.
|
152 |
+
|
153 |
+
Returns:
|
154 |
+
`Tuple(str)`: Paths to the files saved.
|
155 |
+
"""
|
156 |
+
if not os.path.isdir(save_directory):
|
157 |
+
logger.error(f"Vocabulary path ({save_directory}) should be a directory")
|
158 |
+
return
|
159 |
+
out_vocab_file = os.path.join(
|
160 |
+
save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
|
161 |
+
)
|
162 |
+
|
163 |
+
if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
|
164 |
+
copyfile(self.vocab_file, out_vocab_file)
|
165 |
+
elif not os.path.isfile(self.vocab_file):
|
166 |
+
with open(out_vocab_file, "wb") as fi:
|
167 |
+
content_spiece_model = self.sp_model.serialized_model_proto()
|
168 |
+
fi.write(content_spiece_model)
|
169 |
+
|
170 |
+
return (out_vocab_file,)
|
171 |
+
|
172 |
+
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
|
173 |
+
bos_token_id = [self.bos_token_id] if self.add_bos_token else []
|
174 |
+
eos_token_id = [self.eos_token_id] if self.add_eos_token else []
|
175 |
+
|
176 |
+
output = bos_token_id + token_ids_0 + eos_token_id
|
177 |
+
|
178 |
+
if token_ids_1 is not None:
|
179 |
+
output = output + bos_token_id + token_ids_1 + eos_token_id
|
180 |
+
|
181 |
+
return output
|
182 |
+
|
183 |
+
def get_special_tokens_mask(
|
184 |
+
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
|
185 |
+
) -> List[int]:
|
186 |
+
"""
|
187 |
+
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
|
188 |
+
special tokens using the tokenizer `prepare_for_model` method.
|
189 |
+
|
190 |
+
Args:
|
191 |
+
token_ids_0 (`List[int]`):
|
192 |
+
List of IDs.
|
193 |
+
token_ids_1 (`List[int]`, *optional*):
|
194 |
+
Optional second list of IDs for sequence pairs.
|
195 |
+
already_has_special_tokens (`bool`, *optional*, defaults to `False`):
|
196 |
+
Whether or not the token list is already formatted with special tokens for the model.
|
197 |
+
|
198 |
+
Returns:
|
199 |
+
`List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
|
200 |
+
"""
|
201 |
+
if already_has_special_tokens:
|
202 |
+
return super().get_special_tokens_mask(
|
203 |
+
token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
|
204 |
+
)
|
205 |
+
|
206 |
+
bos_token_id = [1] if self.add_bos_token else []
|
207 |
+
eos_token_id = [1] if self.add_eos_token else []
|
208 |
+
|
209 |
+
if token_ids_1 is None:
|
210 |
+
return bos_token_id + ([0] * len(token_ids_0)) + eos_token_id
|
211 |
+
return (
|
212 |
+
bos_token_id
|
213 |
+
+ ([0] * len(token_ids_0))
|
214 |
+
+ eos_token_id
|
215 |
+
+ bos_token_id
|
216 |
+
+ ([0] * len(token_ids_1))
|
217 |
+
+ eos_token_id
|
218 |
+
)
|
219 |
+
|
220 |
+
def create_token_type_ids_from_sequences(
|
221 |
+
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
|
222 |
+
) -> List[int]:
|
223 |
+
"""
|
224 |
+
Creates a mask from the two sequences passed to be used in a sequence-pair classification task. An ALBERT
|
225 |
+
sequence pair mask has the following format:
|
226 |
+
|
227 |
+
```
|
228 |
+
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
|
229 |
+
| first sequence | second sequence |
|
230 |
+
```
|
231 |
+
|
232 |
+
if token_ids_1 is None, only returns the first portion of the mask (0s).
|
233 |
+
|
234 |
+
Args:
|
235 |
+
token_ids_0 (`List[int]`):
|
236 |
+
List of ids.
|
237 |
+
token_ids_1 (`List[int]`, *optional*):
|
238 |
+
Optional second list of IDs for sequence pairs.
|
239 |
+
|
240 |
+
Returns:
|
241 |
+
`List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s).
|
242 |
+
"""
|
243 |
+
bos_token_id = [self.bos_token_id] if self.add_bos_token else []
|
244 |
+
eos_token_id = [self.eos_token_id] if self.add_eos_token else []
|
245 |
+
|
246 |
+
output = [0] * len(bos_token_id + token_ids_0 + eos_token_id)
|
247 |
+
|
248 |
+
if token_ids_1 is not None:
|
249 |
+
output += [1] * len(bos_token_id + token_ids_1 + eos_token_id)
|
250 |
+
|
251 |
+
return output
|
tokenizer.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f5ed07a4a6a74d6a69f56478892da8a06fbaa29dc27ff4d957fda6237643150b
|
3 |
+
size 1609668
|
tokenizer_config.json
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"auto_map": {
|
3 |
+
"AutoTokenizer": ["tokenization_bluelm.BlueLMTokenizer", null]
|
4 |
+
},
|
5 |
+
"add_bos_token": true,
|
6 |
+
"add_eos_token": false,
|
7 |
+
"bos_token": {
|
8 |
+
"__type": "AddedToken",
|
9 |
+
"content": "<s>",
|
10 |
+
"lstrip": false,
|
11 |
+
"normalized": true,
|
12 |
+
"rstrip": false,
|
13 |
+
"single_word": false
|
14 |
+
},
|
15 |
+
"clean_up_tokenization_spaces": false,
|
16 |
+
"eos_token": {
|
17 |
+
"__type": "AddedToken",
|
18 |
+
"content": "</s>",
|
19 |
+
"lstrip": false,
|
20 |
+
"normalized": true,
|
21 |
+
"rstrip": false,
|
22 |
+
"single_word": false
|
23 |
+
},
|
24 |
+
"model_max_length": 1000000000000000019884624838656,
|
25 |
+
"pad_token": {
|
26 |
+
"__type": "AddedToken",
|
27 |
+
"content": "<pad>",
|
28 |
+
"lstrip": false,
|
29 |
+
"normalized": true,
|
30 |
+
"rstrip": false,
|
31 |
+
"single_word": false
|
32 |
+
},
|
33 |
+
"sp_model_kwargs": {},
|
34 |
+
"tokenizer_class": "BlueLMTokenizer",
|
35 |
+
"unk_token": {
|
36 |
+
"__type": "AddedToken",
|
37 |
+
"content": "<unk>",
|
38 |
+
"lstrip": false,
|
39 |
+
"normalized": true,
|
40 |
+
"rstrip": false,
|
41 |
+
"single_word": false
|
42 |
+
}
|
43 |
+
}
|