upload model
Browse files- config.json +37 -0
- configuration_qwen.py +65 -0
- generation_config.json +11 -0
- model-00001-of-00015.safetensors +3 -0
- model-00002-of-00015.safetensors +3 -0
- model-00003-of-00015.safetensors +3 -0
- model-00004-of-00015.safetensors +3 -0
- model-00005-of-00015.safetensors +3 -0
- model-00006-of-00015.safetensors +3 -0
- model-00007-of-00015.safetensors +3 -0
- model-00008-of-00015.safetensors +3 -0
- model-00009-of-00015.safetensors +3 -0
- model-00010-of-00015.safetensors +3 -0
- model-00011-of-00015.safetensors +3 -0
- model-00012-of-00015.safetensors +3 -0
- model-00013-of-00015.safetensors +3 -0
- model-00014-of-00015.safetensors +3 -0
- model-00015-of-00015.safetensors +3 -0
- model.safetensors.index.json +330 -0
- modeling_qwen.py +1232 -0
- qwen.tiktoken +0 -0
- qwen_generation_utils.py +416 -0
- tokenization_qwen.py +246 -0
- tokenizer_config.json +11 -0
config.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"QWenLMHeadModel"
|
4 |
+
],
|
5 |
+
"auto_map": {
|
6 |
+
"AutoConfig": "configuration_qwen.QWenConfig",
|
7 |
+
"AutoModelForCausalLM": "modeling_qwen.QWenLMHeadModel"
|
8 |
+
},
|
9 |
+
"attn_dropout_prob": 0.0,
|
10 |
+
"bf16": false,
|
11 |
+
"emb_dropout_prob": 0.0,
|
12 |
+
"fp16": false,
|
13 |
+
"fp32": false,
|
14 |
+
"hidden_size": 5120,
|
15 |
+
"intermediate_size": 27392,
|
16 |
+
"initializer_range": 0.02,
|
17 |
+
"kv_channels": 128,
|
18 |
+
"layer_norm_epsilon": 1e-06,
|
19 |
+
"max_position_embeddings": 8192,
|
20 |
+
"model_type": "qwen",
|
21 |
+
"no_bias": true,
|
22 |
+
"num_attention_heads": 40,
|
23 |
+
"num_hidden_layers": 40,
|
24 |
+
"onnx_safe": null,
|
25 |
+
"rotary_emb_base": 10000,
|
26 |
+
"rotary_pct": 1.0,
|
27 |
+
"scale_attn_weights": true,
|
28 |
+
"seq_length": 2048,
|
29 |
+
"tie_word_embeddings": false,
|
30 |
+
"tokenizer_class": "QWenTokenizer",
|
31 |
+
"transformers_version": "4.32.0",
|
32 |
+
"use_cache": true,
|
33 |
+
"use_dynamic_ntk": true,
|
34 |
+
"use_flash_attn": "auto",
|
35 |
+
"use_logn_attn": true,
|
36 |
+
"vocab_size": 152064
|
37 |
+
}
|
configuration_qwen.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) Alibaba Cloud.
|
2 |
+
#
|
3 |
+
# This source code is licensed under the license found in the
|
4 |
+
# LICENSE file in the root directory of this source tree.
|
5 |
+
|
6 |
+
from transformers import PretrainedConfig
|
7 |
+
|
8 |
+
|
9 |
+
class QWenConfig(PretrainedConfig):
|
10 |
+
model_type = "qwen"
|
11 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
12 |
+
|
13 |
+
def __init__(
|
14 |
+
self,
|
15 |
+
vocab_size=151936,
|
16 |
+
hidden_size=4096,
|
17 |
+
num_hidden_layers=32,
|
18 |
+
num_attention_heads=32,
|
19 |
+
emb_dropout_prob=0.0,
|
20 |
+
attn_dropout_prob=0.0,
|
21 |
+
layer_norm_epsilon=1e-6,
|
22 |
+
initializer_range=0.02,
|
23 |
+
max_position_embeddings=8192,
|
24 |
+
scale_attn_weights=True,
|
25 |
+
use_cache=True,
|
26 |
+
bf16=False,
|
27 |
+
fp16=False,
|
28 |
+
fp32=False,
|
29 |
+
kv_channels=128,
|
30 |
+
rotary_pct=1.0,
|
31 |
+
rotary_emb_base=10000,
|
32 |
+
use_dynamic_ntk=True,
|
33 |
+
use_logn_attn=True,
|
34 |
+
use_flash_attn="auto",
|
35 |
+
intermediate_size=22016,
|
36 |
+
no_bias=True,
|
37 |
+
tie_word_embeddings=False,
|
38 |
+
**kwargs,
|
39 |
+
):
|
40 |
+
self.vocab_size = vocab_size
|
41 |
+
self.hidden_size = hidden_size
|
42 |
+
self.intermediate_size = intermediate_size
|
43 |
+
self.num_hidden_layers = num_hidden_layers
|
44 |
+
self.num_attention_heads = num_attention_heads
|
45 |
+
self.emb_dropout_prob = emb_dropout_prob
|
46 |
+
self.attn_dropout_prob = attn_dropout_prob
|
47 |
+
self.layer_norm_epsilon = layer_norm_epsilon
|
48 |
+
self.initializer_range = initializer_range
|
49 |
+
self.scale_attn_weights = scale_attn_weights
|
50 |
+
self.use_cache = use_cache
|
51 |
+
self.max_position_embeddings = max_position_embeddings
|
52 |
+
self.bf16 = bf16
|
53 |
+
self.fp16 = fp16
|
54 |
+
self.fp32 = fp32
|
55 |
+
self.kv_channels = kv_channels
|
56 |
+
self.rotary_pct = rotary_pct
|
57 |
+
self.rotary_emb_base = rotary_emb_base
|
58 |
+
self.use_dynamic_ntk = use_dynamic_ntk
|
59 |
+
self.use_logn_attn = use_logn_attn
|
60 |
+
self.use_flash_attn = use_flash_attn
|
61 |
+
self.no_bias = no_bias
|
62 |
+
super().__init__(
|
63 |
+
tie_word_embeddings=tie_word_embeddings,
|
64 |
+
**kwargs
|
65 |
+
)
|
generation_config.json
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"chat_format": "chatml",
|
3 |
+
"eos_token_id": 151643,
|
4 |
+
"pad_token_id": 151643,
|
5 |
+
"max_window_size": 6144,
|
6 |
+
"max_new_tokens": 512,
|
7 |
+
"do_sample": true,
|
8 |
+
"top_k": 0,
|
9 |
+
"top_p": 0.5,
|
10 |
+
"transformers_version": "4.31.0"
|
11 |
+
}
|
model-00001-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9de1c7c7cdc23b6c538c35e128c0e6607b4f1deebc61b3ef4ad131f6888f13d2
|
3 |
+
size 2047396712
|
model-00002-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e67dd4ceb8b16fed9cc5447f55427064d3ef8abc8d8a931c333750e65bc78a1f
|
3 |
+
size 2031782664
|
model-00003-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:27017a0cd4d7894774dfebe220000182c37582a6c07d2d3f53e45bc1708b04d7
|
3 |
+
size 1891525160
|
model-00004-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:022d0e4fbbf7539bddd2e0511512e292f393065fbbb9f93f821a535b74fd53b6
|
3 |
+
size 1891525152
|
model-00005-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:745d337e322f07d5c56ee6da4c2f0afc693d23a4f2d5d3925a63e2beb6bb654d
|
3 |
+
size 1891525184
|
model-00006-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3b3d91f71bdd8689624634b682e39b81036d0fb5a0347fb87e5c78affb736875
|
3 |
+
size 1891525184
|
model-00007-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d04cfa796ccb716a90563eb009953491b1878432bed213ddd6baf2dcaafd1483
|
3 |
+
size 1891525184
|
model-00008-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fd74b77c958199e43507faa55819e6b063b8a1d38c2f963440f9faeb4babb0ce
|
3 |
+
size 1891525184
|
model-00009-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a4b2c46c3f807c978e9f39bb53855f10e22bc90a59a8db8f074da7c7406fbbef
|
3 |
+
size 1891525184
|
model-00010-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1da374b19c029ca4de4d5c1d1a7ea77ab3a227f85a2a3f1f79b91da18be1ee37
|
3 |
+
size 1891525184
|
model-00011-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c2c0c462092baee9b56cdb7818bb15de3f760f648efc4b3e35d2f25c55048f96
|
3 |
+
size 1891525184
|
model-00012-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:00333a21e8e29736155eb8de154a45f02a2ff3c9116494f2b9df0c3a700650e1
|
3 |
+
size 1891525184
|
model-00013-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c0c355a4a91af4b4d72bc6311e59cea7007d7cb988edfa38e62cfdbdbec3ff19
|
3 |
+
size 1891525184
|
model-00014-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8483262f316fbf2342f2b36c88f42e2295586af0a21183107d5778c238e1d071
|
3 |
+
size 1891525184
|
model-00015-of-00015.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:46bbd76bfc2957640818bebe7d3f7b3e6eb53f769ebe521d717c7cc778e4b92a
|
3 |
+
size 1557135488
|
model.safetensors.index.json
ADDED
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 28334581760
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"lm_head.weight": "model-00015-of-00015.safetensors",
|
7 |
+
"transformer.h.0.attn.c_attn.bias": "model-00001-of-00015.safetensors",
|
8 |
+
"transformer.h.0.attn.c_attn.weight": "model-00001-of-00015.safetensors",
|
9 |
+
"transformer.h.0.attn.c_proj.weight": "model-00001-of-00015.safetensors",
|
10 |
+
"transformer.h.0.ln_1.weight": "model-00001-of-00015.safetensors",
|
11 |
+
"transformer.h.0.ln_2.weight": "model-00001-of-00015.safetensors",
|
12 |
+
"transformer.h.0.mlp.c_proj.weight": "model-00002-of-00015.safetensors",
|
13 |
+
"transformer.h.0.mlp.w1.weight": "model-00001-of-00015.safetensors",
|
14 |
+
"transformer.h.0.mlp.w2.weight": "model-00001-of-00015.safetensors",
|
15 |
+
"transformer.h.1.attn.c_attn.bias": "model-00002-of-00015.safetensors",
|
16 |
+
"transformer.h.1.attn.c_attn.weight": "model-00002-of-00015.safetensors",
|
17 |
+
"transformer.h.1.attn.c_proj.weight": "model-00002-of-00015.safetensors",
|
18 |
+
"transformer.h.1.ln_1.weight": "model-00002-of-00015.safetensors",
|
19 |
+
"transformer.h.1.ln_2.weight": "model-00002-of-00015.safetensors",
|
20 |
+
"transformer.h.1.mlp.c_proj.weight": "model-00002-of-00015.safetensors",
|
21 |
+
"transformer.h.1.mlp.w1.weight": "model-00002-of-00015.safetensors",
|
22 |
+
"transformer.h.1.mlp.w2.weight": "model-00002-of-00015.safetensors",
|
23 |
+
"transformer.h.10.attn.c_attn.bias": "model-00005-of-00015.safetensors",
|
24 |
+
"transformer.h.10.attn.c_attn.weight": "model-00005-of-00015.safetensors",
|
25 |
+
"transformer.h.10.attn.c_proj.weight": "model-00005-of-00015.safetensors",
|
26 |
+
"transformer.h.10.ln_1.weight": "model-00004-of-00015.safetensors",
|
27 |
+
"transformer.h.10.ln_2.weight": "model-00005-of-00015.safetensors",
|
28 |
+
"transformer.h.10.mlp.c_proj.weight": "model-00005-of-00015.safetensors",
|
29 |
+
"transformer.h.10.mlp.w1.weight": "model-00005-of-00015.safetensors",
|
30 |
+
"transformer.h.10.mlp.w2.weight": "model-00005-of-00015.safetensors",
|
31 |
+
"transformer.h.11.attn.c_attn.bias": "model-00005-of-00015.safetensors",
|
32 |
+
"transformer.h.11.attn.c_attn.weight": "model-00005-of-00015.safetensors",
|
33 |
+
"transformer.h.11.attn.c_proj.weight": "model-00005-of-00015.safetensors",
|
34 |
+
"transformer.h.11.ln_1.weight": "model-00005-of-00015.safetensors",
|
35 |
+
"transformer.h.11.ln_2.weight": "model-00005-of-00015.safetensors",
|
36 |
+
"transformer.h.11.mlp.c_proj.weight": "model-00005-of-00015.safetensors",
|
37 |
+
"transformer.h.11.mlp.w1.weight": "model-00005-of-00015.safetensors",
|
38 |
+
"transformer.h.11.mlp.w2.weight": "model-00005-of-00015.safetensors",
|
39 |
+
"transformer.h.12.attn.c_attn.bias": "model-00005-of-00015.safetensors",
|
40 |
+
"transformer.h.12.attn.c_attn.weight": "model-00005-of-00015.safetensors",
|
41 |
+
"transformer.h.12.attn.c_proj.weight": "model-00005-of-00015.safetensors",
|
42 |
+
"transformer.h.12.ln_1.weight": "model-00005-of-00015.safetensors",
|
43 |
+
"transformer.h.12.ln_2.weight": "model-00005-of-00015.safetensors",
|
44 |
+
"transformer.h.12.mlp.c_proj.weight": "model-00005-of-00015.safetensors",
|
45 |
+
"transformer.h.12.mlp.w1.weight": "model-00005-of-00015.safetensors",
|
46 |
+
"transformer.h.12.mlp.w2.weight": "model-00005-of-00015.safetensors",
|
47 |
+
"transformer.h.13.attn.c_attn.bias": "model-00006-of-00015.safetensors",
|
48 |
+
"transformer.h.13.attn.c_attn.weight": "model-00006-of-00015.safetensors",
|
49 |
+
"transformer.h.13.attn.c_proj.weight": "model-00006-of-00015.safetensors",
|
50 |
+
"transformer.h.13.ln_1.weight": "model-00005-of-00015.safetensors",
|
51 |
+
"transformer.h.13.ln_2.weight": "model-00006-of-00015.safetensors",
|
52 |
+
"transformer.h.13.mlp.c_proj.weight": "model-00006-of-00015.safetensors",
|
53 |
+
"transformer.h.13.mlp.w1.weight": "model-00006-of-00015.safetensors",
|
54 |
+
"transformer.h.13.mlp.w2.weight": "model-00006-of-00015.safetensors",
|
55 |
+
"transformer.h.14.attn.c_attn.bias": "model-00006-of-00015.safetensors",
|
56 |
+
"transformer.h.14.attn.c_attn.weight": "model-00006-of-00015.safetensors",
|
57 |
+
"transformer.h.14.attn.c_proj.weight": "model-00006-of-00015.safetensors",
|
58 |
+
"transformer.h.14.ln_1.weight": "model-00006-of-00015.safetensors",
|
59 |
+
"transformer.h.14.ln_2.weight": "model-00006-of-00015.safetensors",
|
60 |
+
"transformer.h.14.mlp.c_proj.weight": "model-00006-of-00015.safetensors",
|
61 |
+
"transformer.h.14.mlp.w1.weight": "model-00006-of-00015.safetensors",
|
62 |
+
"transformer.h.14.mlp.w2.weight": "model-00006-of-00015.safetensors",
|
63 |
+
"transformer.h.15.attn.c_attn.bias": "model-00006-of-00015.safetensors",
|
64 |
+
"transformer.h.15.attn.c_attn.weight": "model-00006-of-00015.safetensors",
|
65 |
+
"transformer.h.15.attn.c_proj.weight": "model-00006-of-00015.safetensors",
|
66 |
+
"transformer.h.15.ln_1.weight": "model-00006-of-00015.safetensors",
|
67 |
+
"transformer.h.15.ln_2.weight": "model-00006-of-00015.safetensors",
|
68 |
+
"transformer.h.15.mlp.c_proj.weight": "model-00006-of-00015.safetensors",
|
69 |
+
"transformer.h.15.mlp.w1.weight": "model-00006-of-00015.safetensors",
|
70 |
+
"transformer.h.15.mlp.w2.weight": "model-00006-of-00015.safetensors",
|
71 |
+
"transformer.h.16.attn.c_attn.bias": "model-00007-of-00015.safetensors",
|
72 |
+
"transformer.h.16.attn.c_attn.weight": "model-00007-of-00015.safetensors",
|
73 |
+
"transformer.h.16.attn.c_proj.weight": "model-00007-of-00015.safetensors",
|
74 |
+
"transformer.h.16.ln_1.weight": "model-00006-of-00015.safetensors",
|
75 |
+
"transformer.h.16.ln_2.weight": "model-00007-of-00015.safetensors",
|
76 |
+
"transformer.h.16.mlp.c_proj.weight": "model-00007-of-00015.safetensors",
|
77 |
+
"transformer.h.16.mlp.w1.weight": "model-00007-of-00015.safetensors",
|
78 |
+
"transformer.h.16.mlp.w2.weight": "model-00007-of-00015.safetensors",
|
79 |
+
"transformer.h.17.attn.c_attn.bias": "model-00007-of-00015.safetensors",
|
80 |
+
"transformer.h.17.attn.c_attn.weight": "model-00007-of-00015.safetensors",
|
81 |
+
"transformer.h.17.attn.c_proj.weight": "model-00007-of-00015.safetensors",
|
82 |
+
"transformer.h.17.ln_1.weight": "model-00007-of-00015.safetensors",
|
83 |
+
"transformer.h.17.ln_2.weight": "model-00007-of-00015.safetensors",
|
84 |
+
"transformer.h.17.mlp.c_proj.weight": "model-00007-of-00015.safetensors",
|
85 |
+
"transformer.h.17.mlp.w1.weight": "model-00007-of-00015.safetensors",
|
86 |
+
"transformer.h.17.mlp.w2.weight": "model-00007-of-00015.safetensors",
|
87 |
+
"transformer.h.18.attn.c_attn.bias": "model-00007-of-00015.safetensors",
|
88 |
+
"transformer.h.18.attn.c_attn.weight": "model-00007-of-00015.safetensors",
|
89 |
+
"transformer.h.18.attn.c_proj.weight": "model-00007-of-00015.safetensors",
|
90 |
+
"transformer.h.18.ln_1.weight": "model-00007-of-00015.safetensors",
|
91 |
+
"transformer.h.18.ln_2.weight": "model-00007-of-00015.safetensors",
|
92 |
+
"transformer.h.18.mlp.c_proj.weight": "model-00007-of-00015.safetensors",
|
93 |
+
"transformer.h.18.mlp.w1.weight": "model-00007-of-00015.safetensors",
|
94 |
+
"transformer.h.18.mlp.w2.weight": "model-00007-of-00015.safetensors",
|
95 |
+
"transformer.h.19.attn.c_attn.bias": "model-00008-of-00015.safetensors",
|
96 |
+
"transformer.h.19.attn.c_attn.weight": "model-00008-of-00015.safetensors",
|
97 |
+
"transformer.h.19.attn.c_proj.weight": "model-00008-of-00015.safetensors",
|
98 |
+
"transformer.h.19.ln_1.weight": "model-00007-of-00015.safetensors",
|
99 |
+
"transformer.h.19.ln_2.weight": "model-00008-of-00015.safetensors",
|
100 |
+
"transformer.h.19.mlp.c_proj.weight": "model-00008-of-00015.safetensors",
|
101 |
+
"transformer.h.19.mlp.w1.weight": "model-00008-of-00015.safetensors",
|
102 |
+
"transformer.h.19.mlp.w2.weight": "model-00008-of-00015.safetensors",
|
103 |
+
"transformer.h.2.attn.c_attn.bias": "model-00002-of-00015.safetensors",
|
104 |
+
"transformer.h.2.attn.c_attn.weight": "model-00002-of-00015.safetensors",
|
105 |
+
"transformer.h.2.attn.c_proj.weight": "model-00002-of-00015.safetensors",
|
106 |
+
"transformer.h.2.ln_1.weight": "model-00002-of-00015.safetensors",
|
107 |
+
"transformer.h.2.ln_2.weight": "model-00002-of-00015.safetensors",
|
108 |
+
"transformer.h.2.mlp.c_proj.weight": "model-00002-of-00015.safetensors",
|
109 |
+
"transformer.h.2.mlp.w1.weight": "model-00002-of-00015.safetensors",
|
110 |
+
"transformer.h.2.mlp.w2.weight": "model-00002-of-00015.safetensors",
|
111 |
+
"transformer.h.20.attn.c_attn.bias": "model-00008-of-00015.safetensors",
|
112 |
+
"transformer.h.20.attn.c_attn.weight": "model-00008-of-00015.safetensors",
|
113 |
+
"transformer.h.20.attn.c_proj.weight": "model-00008-of-00015.safetensors",
|
114 |
+
"transformer.h.20.ln_1.weight": "model-00008-of-00015.safetensors",
|
115 |
+
"transformer.h.20.ln_2.weight": "model-00008-of-00015.safetensors",
|
116 |
+
"transformer.h.20.mlp.c_proj.weight": "model-00008-of-00015.safetensors",
|
117 |
+
"transformer.h.20.mlp.w1.weight": "model-00008-of-00015.safetensors",
|
118 |
+
"transformer.h.20.mlp.w2.weight": "model-00008-of-00015.safetensors",
|
119 |
+
"transformer.h.21.attn.c_attn.bias": "model-00008-of-00015.safetensors",
|
120 |
+
"transformer.h.21.attn.c_attn.weight": "model-00008-of-00015.safetensors",
|
121 |
+
"transformer.h.21.attn.c_proj.weight": "model-00008-of-00015.safetensors",
|
122 |
+
"transformer.h.21.ln_1.weight": "model-00008-of-00015.safetensors",
|
123 |
+
"transformer.h.21.ln_2.weight": "model-00008-of-00015.safetensors",
|
124 |
+
"transformer.h.21.mlp.c_proj.weight": "model-00008-of-00015.safetensors",
|
125 |
+
"transformer.h.21.mlp.w1.weight": "model-00008-of-00015.safetensors",
|
126 |
+
"transformer.h.21.mlp.w2.weight": "model-00008-of-00015.safetensors",
|
127 |
+
"transformer.h.22.attn.c_attn.bias": "model-00009-of-00015.safetensors",
|
128 |
+
"transformer.h.22.attn.c_attn.weight": "model-00009-of-00015.safetensors",
|
129 |
+
"transformer.h.22.attn.c_proj.weight": "model-00009-of-00015.safetensors",
|
130 |
+
"transformer.h.22.ln_1.weight": "model-00008-of-00015.safetensors",
|
131 |
+
"transformer.h.22.ln_2.weight": "model-00009-of-00015.safetensors",
|
132 |
+
"transformer.h.22.mlp.c_proj.weight": "model-00009-of-00015.safetensors",
|
133 |
+
"transformer.h.22.mlp.w1.weight": "model-00009-of-00015.safetensors",
|
134 |
+
"transformer.h.22.mlp.w2.weight": "model-00009-of-00015.safetensors",
|
135 |
+
"transformer.h.23.attn.c_attn.bias": "model-00009-of-00015.safetensors",
|
136 |
+
"transformer.h.23.attn.c_attn.weight": "model-00009-of-00015.safetensors",
|
137 |
+
"transformer.h.23.attn.c_proj.weight": "model-00009-of-00015.safetensors",
|
138 |
+
"transformer.h.23.ln_1.weight": "model-00009-of-00015.safetensors",
|
139 |
+
"transformer.h.23.ln_2.weight": "model-00009-of-00015.safetensors",
|
140 |
+
"transformer.h.23.mlp.c_proj.weight": "model-00009-of-00015.safetensors",
|
141 |
+
"transformer.h.23.mlp.w1.weight": "model-00009-of-00015.safetensors",
|
142 |
+
"transformer.h.23.mlp.w2.weight": "model-00009-of-00015.safetensors",
|
143 |
+
"transformer.h.24.attn.c_attn.bias": "model-00009-of-00015.safetensors",
|
144 |
+
"transformer.h.24.attn.c_attn.weight": "model-00009-of-00015.safetensors",
|
145 |
+
"transformer.h.24.attn.c_proj.weight": "model-00009-of-00015.safetensors",
|
146 |
+
"transformer.h.24.ln_1.weight": "model-00009-of-00015.safetensors",
|
147 |
+
"transformer.h.24.ln_2.weight": "model-00009-of-00015.safetensors",
|
148 |
+
"transformer.h.24.mlp.c_proj.weight": "model-00009-of-00015.safetensors",
|
149 |
+
"transformer.h.24.mlp.w1.weight": "model-00009-of-00015.safetensors",
|
150 |
+
"transformer.h.24.mlp.w2.weight": "model-00009-of-00015.safetensors",
|
151 |
+
"transformer.h.25.attn.c_attn.bias": "model-00010-of-00015.safetensors",
|
152 |
+
"transformer.h.25.attn.c_attn.weight": "model-00010-of-00015.safetensors",
|
153 |
+
"transformer.h.25.attn.c_proj.weight": "model-00010-of-00015.safetensors",
|
154 |
+
"transformer.h.25.ln_1.weight": "model-00009-of-00015.safetensors",
|
155 |
+
"transformer.h.25.ln_2.weight": "model-00010-of-00015.safetensors",
|
156 |
+
"transformer.h.25.mlp.c_proj.weight": "model-00010-of-00015.safetensors",
|
157 |
+
"transformer.h.25.mlp.w1.weight": "model-00010-of-00015.safetensors",
|
158 |
+
"transformer.h.25.mlp.w2.weight": "model-00010-of-00015.safetensors",
|
159 |
+
"transformer.h.26.attn.c_attn.bias": "model-00010-of-00015.safetensors",
|
160 |
+
"transformer.h.26.attn.c_attn.weight": "model-00010-of-00015.safetensors",
|
161 |
+
"transformer.h.26.attn.c_proj.weight": "model-00010-of-00015.safetensors",
|
162 |
+
"transformer.h.26.ln_1.weight": "model-00010-of-00015.safetensors",
|
163 |
+
"transformer.h.26.ln_2.weight": "model-00010-of-00015.safetensors",
|
164 |
+
"transformer.h.26.mlp.c_proj.weight": "model-00010-of-00015.safetensors",
|
165 |
+
"transformer.h.26.mlp.w1.weight": "model-00010-of-00015.safetensors",
|
166 |
+
"transformer.h.26.mlp.w2.weight": "model-00010-of-00015.safetensors",
|
167 |
+
"transformer.h.27.attn.c_attn.bias": "model-00010-of-00015.safetensors",
|
168 |
+
"transformer.h.27.attn.c_attn.weight": "model-00010-of-00015.safetensors",
|
169 |
+
"transformer.h.27.attn.c_proj.weight": "model-00010-of-00015.safetensors",
|
170 |
+
"transformer.h.27.ln_1.weight": "model-00010-of-00015.safetensors",
|
171 |
+
"transformer.h.27.ln_2.weight": "model-00010-of-00015.safetensors",
|
172 |
+
"transformer.h.27.mlp.c_proj.weight": "model-00010-of-00015.safetensors",
|
173 |
+
"transformer.h.27.mlp.w1.weight": "model-00010-of-00015.safetensors",
|
174 |
+
"transformer.h.27.mlp.w2.weight": "model-00010-of-00015.safetensors",
|
175 |
+
"transformer.h.28.attn.c_attn.bias": "model-00011-of-00015.safetensors",
|
176 |
+
"transformer.h.28.attn.c_attn.weight": "model-00011-of-00015.safetensors",
|
177 |
+
"transformer.h.28.attn.c_proj.weight": "model-00011-of-00015.safetensors",
|
178 |
+
"transformer.h.28.ln_1.weight": "model-00010-of-00015.safetensors",
|
179 |
+
"transformer.h.28.ln_2.weight": "model-00011-of-00015.safetensors",
|
180 |
+
"transformer.h.28.mlp.c_proj.weight": "model-00011-of-00015.safetensors",
|
181 |
+
"transformer.h.28.mlp.w1.weight": "model-00011-of-00015.safetensors",
|
182 |
+
"transformer.h.28.mlp.w2.weight": "model-00011-of-00015.safetensors",
|
183 |
+
"transformer.h.29.attn.c_attn.bias": "model-00011-of-00015.safetensors",
|
184 |
+
"transformer.h.29.attn.c_attn.weight": "model-00011-of-00015.safetensors",
|
185 |
+
"transformer.h.29.attn.c_proj.weight": "model-00011-of-00015.safetensors",
|
186 |
+
"transformer.h.29.ln_1.weight": "model-00011-of-00015.safetensors",
|
187 |
+
"transformer.h.29.ln_2.weight": "model-00011-of-00015.safetensors",
|
188 |
+
"transformer.h.29.mlp.c_proj.weight": "model-00011-of-00015.safetensors",
|
189 |
+
"transformer.h.29.mlp.w1.weight": "model-00011-of-00015.safetensors",
|
190 |
+
"transformer.h.29.mlp.w2.weight": "model-00011-of-00015.safetensors",
|
191 |
+
"transformer.h.3.attn.c_attn.bias": "model-00002-of-00015.safetensors",
|
192 |
+
"transformer.h.3.attn.c_attn.weight": "model-00002-of-00015.safetensors",
|
193 |
+
"transformer.h.3.attn.c_proj.weight": "model-00002-of-00015.safetensors",
|
194 |
+
"transformer.h.3.ln_1.weight": "model-00002-of-00015.safetensors",
|
195 |
+
"transformer.h.3.ln_2.weight": "model-00002-of-00015.safetensors",
|
196 |
+
"transformer.h.3.mlp.c_proj.weight": "model-00002-of-00015.safetensors",
|
197 |
+
"transformer.h.3.mlp.w1.weight": "model-00002-of-00015.safetensors",
|
198 |
+
"transformer.h.3.mlp.w2.weight": "model-00002-of-00015.safetensors",
|
199 |
+
"transformer.h.30.attn.c_attn.bias": "model-00011-of-00015.safetensors",
|
200 |
+
"transformer.h.30.attn.c_attn.weight": "model-00011-of-00015.safetensors",
|
201 |
+
"transformer.h.30.attn.c_proj.weight": "model-00011-of-00015.safetensors",
|
202 |
+
"transformer.h.30.ln_1.weight": "model-00011-of-00015.safetensors",
|
203 |
+
"transformer.h.30.ln_2.weight": "model-00011-of-00015.safetensors",
|
204 |
+
"transformer.h.30.mlp.c_proj.weight": "model-00011-of-00015.safetensors",
|
205 |
+
"transformer.h.30.mlp.w1.weight": "model-00011-of-00015.safetensors",
|
206 |
+
"transformer.h.30.mlp.w2.weight": "model-00011-of-00015.safetensors",
|
207 |
+
"transformer.h.31.attn.c_attn.bias": "model-00012-of-00015.safetensors",
|
208 |
+
"transformer.h.31.attn.c_attn.weight": "model-00012-of-00015.safetensors",
|
209 |
+
"transformer.h.31.attn.c_proj.weight": "model-00012-of-00015.safetensors",
|
210 |
+
"transformer.h.31.ln_1.weight": "model-00011-of-00015.safetensors",
|
211 |
+
"transformer.h.31.ln_2.weight": "model-00012-of-00015.safetensors",
|
212 |
+
"transformer.h.31.mlp.c_proj.weight": "model-00012-of-00015.safetensors",
|
213 |
+
"transformer.h.31.mlp.w1.weight": "model-00012-of-00015.safetensors",
|
214 |
+
"transformer.h.31.mlp.w2.weight": "model-00012-of-00015.safetensors",
|
215 |
+
"transformer.h.32.attn.c_attn.bias": "model-00012-of-00015.safetensors",
|
216 |
+
"transformer.h.32.attn.c_attn.weight": "model-00012-of-00015.safetensors",
|
217 |
+
"transformer.h.32.attn.c_proj.weight": "model-00012-of-00015.safetensors",
|
218 |
+
"transformer.h.32.ln_1.weight": "model-00012-of-00015.safetensors",
|
219 |
+
"transformer.h.32.ln_2.weight": "model-00012-of-00015.safetensors",
|
220 |
+
"transformer.h.32.mlp.c_proj.weight": "model-00012-of-00015.safetensors",
|
221 |
+
"transformer.h.32.mlp.w1.weight": "model-00012-of-00015.safetensors",
|
222 |
+
"transformer.h.32.mlp.w2.weight": "model-00012-of-00015.safetensors",
|
223 |
+
"transformer.h.33.attn.c_attn.bias": "model-00012-of-00015.safetensors",
|
224 |
+
"transformer.h.33.attn.c_attn.weight": "model-00012-of-00015.safetensors",
|
225 |
+
"transformer.h.33.attn.c_proj.weight": "model-00012-of-00015.safetensors",
|
226 |
+
"transformer.h.33.ln_1.weight": "model-00012-of-00015.safetensors",
|
227 |
+
"transformer.h.33.ln_2.weight": "model-00012-of-00015.safetensors",
|
228 |
+
"transformer.h.33.mlp.c_proj.weight": "model-00012-of-00015.safetensors",
|
229 |
+
"transformer.h.33.mlp.w1.weight": "model-00012-of-00015.safetensors",
|
230 |
+
"transformer.h.33.mlp.w2.weight": "model-00012-of-00015.safetensors",
|
231 |
+
"transformer.h.34.attn.c_attn.bias": "model-00013-of-00015.safetensors",
|
232 |
+
"transformer.h.34.attn.c_attn.weight": "model-00013-of-00015.safetensors",
|
233 |
+
"transformer.h.34.attn.c_proj.weight": "model-00013-of-00015.safetensors",
|
234 |
+
"transformer.h.34.ln_1.weight": "model-00012-of-00015.safetensors",
|
235 |
+
"transformer.h.34.ln_2.weight": "model-00013-of-00015.safetensors",
|
236 |
+
"transformer.h.34.mlp.c_proj.weight": "model-00013-of-00015.safetensors",
|
237 |
+
"transformer.h.34.mlp.w1.weight": "model-00013-of-00015.safetensors",
|
238 |
+
"transformer.h.34.mlp.w2.weight": "model-00013-of-00015.safetensors",
|
239 |
+
"transformer.h.35.attn.c_attn.bias": "model-00013-of-00015.safetensors",
|
240 |
+
"transformer.h.35.attn.c_attn.weight": "model-00013-of-00015.safetensors",
|
241 |
+
"transformer.h.35.attn.c_proj.weight": "model-00013-of-00015.safetensors",
|
242 |
+
"transformer.h.35.ln_1.weight": "model-00013-of-00015.safetensors",
|
243 |
+
"transformer.h.35.ln_2.weight": "model-00013-of-00015.safetensors",
|
244 |
+
"transformer.h.35.mlp.c_proj.weight": "model-00013-of-00015.safetensors",
|
245 |
+
"transformer.h.35.mlp.w1.weight": "model-00013-of-00015.safetensors",
|
246 |
+
"transformer.h.35.mlp.w2.weight": "model-00013-of-00015.safetensors",
|
247 |
+
"transformer.h.36.attn.c_attn.bias": "model-00013-of-00015.safetensors",
|
248 |
+
"transformer.h.36.attn.c_attn.weight": "model-00013-of-00015.safetensors",
|
249 |
+
"transformer.h.36.attn.c_proj.weight": "model-00013-of-00015.safetensors",
|
250 |
+
"transformer.h.36.ln_1.weight": "model-00013-of-00015.safetensors",
|
251 |
+
"transformer.h.36.ln_2.weight": "model-00013-of-00015.safetensors",
|
252 |
+
"transformer.h.36.mlp.c_proj.weight": "model-00013-of-00015.safetensors",
|
253 |
+
"transformer.h.36.mlp.w1.weight": "model-00013-of-00015.safetensors",
|
254 |
+
"transformer.h.36.mlp.w2.weight": "model-00013-of-00015.safetensors",
|
255 |
+
"transformer.h.37.attn.c_attn.bias": "model-00014-of-00015.safetensors",
|
256 |
+
"transformer.h.37.attn.c_attn.weight": "model-00014-of-00015.safetensors",
|
257 |
+
"transformer.h.37.attn.c_proj.weight": "model-00014-of-00015.safetensors",
|
258 |
+
"transformer.h.37.ln_1.weight": "model-00013-of-00015.safetensors",
|
259 |
+
"transformer.h.37.ln_2.weight": "model-00014-of-00015.safetensors",
|
260 |
+
"transformer.h.37.mlp.c_proj.weight": "model-00014-of-00015.safetensors",
|
261 |
+
"transformer.h.37.mlp.w1.weight": "model-00014-of-00015.safetensors",
|
262 |
+
"transformer.h.37.mlp.w2.weight": "model-00014-of-00015.safetensors",
|
263 |
+
"transformer.h.38.attn.c_attn.bias": "model-00014-of-00015.safetensors",
|
264 |
+
"transformer.h.38.attn.c_attn.weight": "model-00014-of-00015.safetensors",
|
265 |
+
"transformer.h.38.attn.c_proj.weight": "model-00014-of-00015.safetensors",
|
266 |
+
"transformer.h.38.ln_1.weight": "model-00014-of-00015.safetensors",
|
267 |
+
"transformer.h.38.ln_2.weight": "model-00014-of-00015.safetensors",
|
268 |
+
"transformer.h.38.mlp.c_proj.weight": "model-00014-of-00015.safetensors",
|
269 |
+
"transformer.h.38.mlp.w1.weight": "model-00014-of-00015.safetensors",
|
270 |
+
"transformer.h.38.mlp.w2.weight": "model-00014-of-00015.safetensors",
|
271 |
+
"transformer.h.39.attn.c_attn.bias": "model-00014-of-00015.safetensors",
|
272 |
+
"transformer.h.39.attn.c_attn.weight": "model-00014-of-00015.safetensors",
|
273 |
+
"transformer.h.39.attn.c_proj.weight": "model-00014-of-00015.safetensors",
|
274 |
+
"transformer.h.39.ln_1.weight": "model-00014-of-00015.safetensors",
|
275 |
+
"transformer.h.39.ln_2.weight": "model-00014-of-00015.safetensors",
|
276 |
+
"transformer.h.39.mlp.c_proj.weight": "model-00014-of-00015.safetensors",
|
277 |
+
"transformer.h.39.mlp.w1.weight": "model-00014-of-00015.safetensors",
|
278 |
+
"transformer.h.39.mlp.w2.weight": "model-00014-of-00015.safetensors",
|
279 |
+
"transformer.h.4.attn.c_attn.bias": "model-00003-of-00015.safetensors",
|
280 |
+
"transformer.h.4.attn.c_attn.weight": "model-00003-of-00015.safetensors",
|
281 |
+
"transformer.h.4.attn.c_proj.weight": "model-00003-of-00015.safetensors",
|
282 |
+
"transformer.h.4.ln_1.weight": "model-00002-of-00015.safetensors",
|
283 |
+
"transformer.h.4.ln_2.weight": "model-00003-of-00015.safetensors",
|
284 |
+
"transformer.h.4.mlp.c_proj.weight": "model-00003-of-00015.safetensors",
|
285 |
+
"transformer.h.4.mlp.w1.weight": "model-00003-of-00015.safetensors",
|
286 |
+
"transformer.h.4.mlp.w2.weight": "model-00003-of-00015.safetensors",
|
287 |
+
"transformer.h.5.attn.c_attn.bias": "model-00003-of-00015.safetensors",
|
288 |
+
"transformer.h.5.attn.c_attn.weight": "model-00003-of-00015.safetensors",
|
289 |
+
"transformer.h.5.attn.c_proj.weight": "model-00003-of-00015.safetensors",
|
290 |
+
"transformer.h.5.ln_1.weight": "model-00003-of-00015.safetensors",
|
291 |
+
"transformer.h.5.ln_2.weight": "model-00003-of-00015.safetensors",
|
292 |
+
"transformer.h.5.mlp.c_proj.weight": "model-00003-of-00015.safetensors",
|
293 |
+
"transformer.h.5.mlp.w1.weight": "model-00003-of-00015.safetensors",
|
294 |
+
"transformer.h.5.mlp.w2.weight": "model-00003-of-00015.safetensors",
|
295 |
+
"transformer.h.6.attn.c_attn.bias": "model-00003-of-00015.safetensors",
|
296 |
+
"transformer.h.6.attn.c_attn.weight": "model-00003-of-00015.safetensors",
|
297 |
+
"transformer.h.6.attn.c_proj.weight": "model-00003-of-00015.safetensors",
|
298 |
+
"transformer.h.6.ln_1.weight": "model-00003-of-00015.safetensors",
|
299 |
+
"transformer.h.6.ln_2.weight": "model-00003-of-00015.safetensors",
|
300 |
+
"transformer.h.6.mlp.c_proj.weight": "model-00003-of-00015.safetensors",
|
301 |
+
"transformer.h.6.mlp.w1.weight": "model-00003-of-00015.safetensors",
|
302 |
+
"transformer.h.6.mlp.w2.weight": "model-00003-of-00015.safetensors",
|
303 |
+
"transformer.h.7.attn.c_attn.bias": "model-00004-of-00015.safetensors",
|
304 |
+
"transformer.h.7.attn.c_attn.weight": "model-00004-of-00015.safetensors",
|
305 |
+
"transformer.h.7.attn.c_proj.weight": "model-00004-of-00015.safetensors",
|
306 |
+
"transformer.h.7.ln_1.weight": "model-00003-of-00015.safetensors",
|
307 |
+
"transformer.h.7.ln_2.weight": "model-00004-of-00015.safetensors",
|
308 |
+
"transformer.h.7.mlp.c_proj.weight": "model-00004-of-00015.safetensors",
|
309 |
+
"transformer.h.7.mlp.w1.weight": "model-00004-of-00015.safetensors",
|
310 |
+
"transformer.h.7.mlp.w2.weight": "model-00004-of-00015.safetensors",
|
311 |
+
"transformer.h.8.attn.c_attn.bias": "model-00004-of-00015.safetensors",
|
312 |
+
"transformer.h.8.attn.c_attn.weight": "model-00004-of-00015.safetensors",
|
313 |
+
"transformer.h.8.attn.c_proj.weight": "model-00004-of-00015.safetensors",
|
314 |
+
"transformer.h.8.ln_1.weight": "model-00004-of-00015.safetensors",
|
315 |
+
"transformer.h.8.ln_2.weight": "model-00004-of-00015.safetensors",
|
316 |
+
"transformer.h.8.mlp.c_proj.weight": "model-00004-of-00015.safetensors",
|
317 |
+
"transformer.h.8.mlp.w1.weight": "model-00004-of-00015.safetensors",
|
318 |
+
"transformer.h.8.mlp.w2.weight": "model-00004-of-00015.safetensors",
|
319 |
+
"transformer.h.9.attn.c_attn.bias": "model-00004-of-00015.safetensors",
|
320 |
+
"transformer.h.9.attn.c_attn.weight": "model-00004-of-00015.safetensors",
|
321 |
+
"transformer.h.9.attn.c_proj.weight": "model-00004-of-00015.safetensors",
|
322 |
+
"transformer.h.9.ln_1.weight": "model-00004-of-00015.safetensors",
|
323 |
+
"transformer.h.9.ln_2.weight": "model-00004-of-00015.safetensors",
|
324 |
+
"transformer.h.9.mlp.c_proj.weight": "model-00004-of-00015.safetensors",
|
325 |
+
"transformer.h.9.mlp.w1.weight": "model-00004-of-00015.safetensors",
|
326 |
+
"transformer.h.9.mlp.w2.weight": "model-00004-of-00015.safetensors",
|
327 |
+
"transformer.ln_f.weight": "model-00014-of-00015.safetensors",
|
328 |
+
"transformer.wte.weight": "model-00001-of-00015.safetensors"
|
329 |
+
}
|
330 |
+
}
|
modeling_qwen.py
ADDED
@@ -0,0 +1,1232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) Alibaba Cloud.
|
2 |
+
#
|
3 |
+
# This source code is licensed under the license found in the
|
4 |
+
# LICENSE file in the root directory of this source tree.
|
5 |
+
|
6 |
+
import importlib
|
7 |
+
import math
|
8 |
+
from typing import TYPE_CHECKING, Optional, Tuple, Union, Callable, List, Any, Generator
|
9 |
+
|
10 |
+
import torch
|
11 |
+
import torch.nn.functional as F
|
12 |
+
import torch.utils.checkpoint
|
13 |
+
from torch.cuda.amp import autocast
|
14 |
+
|
15 |
+
from torch.nn import CrossEntropyLoss
|
16 |
+
from transformers import PreTrainedTokenizer, GenerationConfig, StoppingCriteriaList
|
17 |
+
from transformers.generation.logits_process import LogitsProcessorList
|
18 |
+
|
19 |
+
if TYPE_CHECKING:
|
20 |
+
from transformers.generation.streamers import BaseStreamer
|
21 |
+
from transformers.generation.utils import GenerateOutput
|
22 |
+
from transformers.modeling_outputs import (
|
23 |
+
BaseModelOutputWithPast,
|
24 |
+
CausalLMOutputWithPast,
|
25 |
+
)
|
26 |
+
from transformers.modeling_utils import PreTrainedModel
|
27 |
+
from transformers.utils import logging
|
28 |
+
|
29 |
+
try:
|
30 |
+
from einops import rearrange
|
31 |
+
except ImportError:
|
32 |
+
rearrange = None
|
33 |
+
from torch import nn
|
34 |
+
|
35 |
+
SUPPORT_CUDA = torch.cuda.is_available()
|
36 |
+
SUPPORT_BF16 = SUPPORT_CUDA and torch.cuda.is_bf16_supported()
|
37 |
+
SUPPORT_FP16 = SUPPORT_CUDA and torch.cuda.get_device_capability(0)[0] >= 7
|
38 |
+
|
39 |
+
from .configuration_qwen import QWenConfig
|
40 |
+
from .qwen_generation_utils import (
|
41 |
+
HistoryType,
|
42 |
+
make_context,
|
43 |
+
decode_tokens,
|
44 |
+
get_stop_words_ids,
|
45 |
+
StopWordsLogitsProcessor,
|
46 |
+
)
|
47 |
+
|
48 |
+
|
49 |
+
logger = logging.get_logger(__name__)
|
50 |
+
|
51 |
+
_CHECKPOINT_FOR_DOC = "qwen"
|
52 |
+
_CONFIG_FOR_DOC = "QWenConfig"
|
53 |
+
|
54 |
+
QWen_PRETRAINED_MODEL_ARCHIVE_LIST = ["qwen-7b"]
|
55 |
+
|
56 |
+
_ERROR_BAD_CHAT_FORMAT = """\
|
57 |
+
We detect you are probably using the pretrained model (rather than chat model) for chatting, since the chat_format in generation_config is not "chatml".
|
58 |
+
If you are directly using the model downloaded from Huggingface, please make sure you are using our "Qwen/Qwen-7B-Chat" Huggingface model (rather than "Qwen/Qwen-7B") when you call model.chat().
|
59 |
+
我们检测到您可能在使用预训练模型(而非chat模型)进行多轮chat,因为您当前在generation_config指定的chat_format,并未设置为我们在对话中所支持的"chatml"格式。
|
60 |
+
如果您在直接使用我们从Huggingface提供的模型,请确保您在调用model.chat()时,使用的是"Qwen/Qwen-7B-Chat"模型(而非"Qwen/Qwen-7B"预训练模型)。
|
61 |
+
"""
|
62 |
+
|
63 |
+
_SENTINEL = object()
|
64 |
+
_ERROR_STREAM_IN_CHAT = """\
|
65 |
+
Pass argument `stream` to model.chat() is buggy, deprecated, and marked for removal. Please use model.chat_stream(...) instead of model.chat(..., stream=True).
|
66 |
+
向model.chat()传入参数stream的用法可能存在Bug,该用法已被废弃,将在未来被移除。请使用model.chat_stream(...)代替model.chat(..., stream=True)。
|
67 |
+
"""
|
68 |
+
|
69 |
+
_ERROR_INPUT_CPU_QUERY_WITH_FLASH_ATTN_ACTIVATED = """\
|
70 |
+
We detect you have activated flash attention support, but running model computation on CPU. Please make sure that your input data has been placed on GPU. If you actually want to run CPU computation, please following the readme and set device_map="cpu" to disable flash attention when loading the model (calling AutoModelForCausalLM.from_pretrained).
|
71 |
+
检测到您的模型已激活了flash attention支持,但正在执行CPU运算任务。如使用flash attention,请您确认模型输入已经传到GPU上。如果您确认要执行CPU运算,请您在载入模型(调用AutoModelForCausalLM.from_pretrained)时,按照readme说法,指定device_map="cpu"以禁用flash attention。
|
72 |
+
"""
|
73 |
+
|
74 |
+
apply_rotary_emb_func = None
|
75 |
+
rms_norm = None
|
76 |
+
flash_attn_unpadded_func = None
|
77 |
+
|
78 |
+
|
79 |
+
def _import_flash_attn():
|
80 |
+
global apply_rotary_emb_func, rms_norm, flash_attn_unpadded_func
|
81 |
+
try:
|
82 |
+
from flash_attn.layers.rotary import apply_rotary_emb_func as __apply_rotary_emb_func
|
83 |
+
apply_rotary_emb_func = __apply_rotary_emb_func
|
84 |
+
except ImportError:
|
85 |
+
logger.warn(
|
86 |
+
"Warning: import flash_attn rotary fail, please install FlashAttention rotary to get higher efficiency "
|
87 |
+
"https://github.com/Dao-AILab/flash-attention/tree/main/csrc/rotary"
|
88 |
+
)
|
89 |
+
|
90 |
+
try:
|
91 |
+
from flash_attn.ops.rms_norm import rms_norm as __rms_norm
|
92 |
+
rms_norm = __rms_norm
|
93 |
+
except ImportError:
|
94 |
+
logger.warn(
|
95 |
+
"Warning: import flash_attn rms_norm fail, please install FlashAttention layer_norm to get higher efficiency "
|
96 |
+
"https://github.com/Dao-AILab/flash-attention/tree/main/csrc/layer_norm"
|
97 |
+
)
|
98 |
+
|
99 |
+
try:
|
100 |
+
import flash_attn
|
101 |
+
if not hasattr(flash_attn, '__version__'):
|
102 |
+
from flash_attn.flash_attn_interface import flash_attn_unpadded_func as __flash_attn_unpadded_func
|
103 |
+
else:
|
104 |
+
if int(flash_attn.__version__.split(".")[0]) >= 2:
|
105 |
+
from flash_attn.flash_attn_interface import flash_attn_varlen_func as __flash_attn_unpadded_func
|
106 |
+
else:
|
107 |
+
from flash_attn.flash_attn_interface import flash_attn_unpadded_func as __flash_attn_unpadded_func
|
108 |
+
flash_attn_unpadded_func = __flash_attn_unpadded_func
|
109 |
+
except ImportError:
|
110 |
+
logger.warn(
|
111 |
+
"Warning: import flash_attn fail, please install FlashAttention to get higher efficiency "
|
112 |
+
"https://github.com/Dao-AILab/flash-attention"
|
113 |
+
)
|
114 |
+
|
115 |
+
|
116 |
+
class FlashSelfAttention(torch.nn.Module):
|
117 |
+
def __init__(
|
118 |
+
self,
|
119 |
+
causal=False,
|
120 |
+
softmax_scale=None,
|
121 |
+
attention_dropout=0.0,
|
122 |
+
):
|
123 |
+
super().__init__()
|
124 |
+
assert flash_attn_unpadded_func is not None, (
|
125 |
+
"Please install FlashAttention first, " "e.g., with pip install flash-attn"
|
126 |
+
)
|
127 |
+
assert (
|
128 |
+
rearrange is not None
|
129 |
+
), "Please install einops first, e.g., with pip install einops"
|
130 |
+
self.causal = causal
|
131 |
+
self.softmax_scale = softmax_scale
|
132 |
+
self.dropout_p = attention_dropout
|
133 |
+
|
134 |
+
def forward(self, q, k, v):
|
135 |
+
assert all((i.dtype in [torch.float16, torch.bfloat16] for i in (q, k, v)))
|
136 |
+
assert all((i.is_cuda for i in (q, k, v)))
|
137 |
+
batch_size, seqlen_q = q.shape[0], q.shape[1]
|
138 |
+
seqlen_k = k.shape[1]
|
139 |
+
|
140 |
+
q, k, v = [rearrange(x, "b s ... -> (b s) ...") for x in [q, k, v]]
|
141 |
+
cu_seqlens_q = torch.arange(
|
142 |
+
0,
|
143 |
+
(batch_size + 1) * seqlen_q,
|
144 |
+
step=seqlen_q,
|
145 |
+
dtype=torch.int32,
|
146 |
+
device=q.device,
|
147 |
+
)
|
148 |
+
|
149 |
+
if self.training:
|
150 |
+
assert seqlen_k == seqlen_q
|
151 |
+
|
152 |
+
is_causal = self.causal
|
153 |
+
cu_seqlens_k = cu_seqlens_q
|
154 |
+
else:
|
155 |
+
is_causal = seqlen_q == seqlen_k
|
156 |
+
cu_seqlens_k = torch.arange(
|
157 |
+
0,
|
158 |
+
(batch_size + 1) * seqlen_k,
|
159 |
+
step=seqlen_k,
|
160 |
+
dtype=torch.int32,
|
161 |
+
device=q.device,
|
162 |
+
)
|
163 |
+
self.dropout_p = 0
|
164 |
+
|
165 |
+
output = flash_attn_unpadded_func(
|
166 |
+
q,
|
167 |
+
k,
|
168 |
+
v,
|
169 |
+
cu_seqlens_q,
|
170 |
+
cu_seqlens_k,
|
171 |
+
seqlen_q,
|
172 |
+
seqlen_k,
|
173 |
+
self.dropout_p,
|
174 |
+
softmax_scale=self.softmax_scale,
|
175 |
+
causal=is_causal,
|
176 |
+
)
|
177 |
+
|
178 |
+
new_shape = (batch_size, output.shape[0] // batch_size) + output.shape[1:]
|
179 |
+
output = output.view(new_shape)
|
180 |
+
return output
|
181 |
+
|
182 |
+
|
183 |
+
class QWenAttention(nn.Module):
|
184 |
+
def __init__(self, config):
|
185 |
+
super().__init__()
|
186 |
+
|
187 |
+
self.register_buffer("masked_bias", torch.tensor(-1e4), persistent=False)
|
188 |
+
self.seq_length = config.seq_length
|
189 |
+
|
190 |
+
self.hidden_size = config.hidden_size
|
191 |
+
self.split_size = config.hidden_size
|
192 |
+
self.num_heads = config.num_attention_heads
|
193 |
+
self.head_dim = self.hidden_size // self.num_heads
|
194 |
+
|
195 |
+
self.use_flash_attn = config.use_flash_attn
|
196 |
+
self.scale_attn_weights = True
|
197 |
+
|
198 |
+
self.projection_size = config.kv_channels * config.num_attention_heads
|
199 |
+
|
200 |
+
assert self.projection_size % config.num_attention_heads == 0
|
201 |
+
self.hidden_size_per_attention_head = (
|
202 |
+
self.projection_size // config.num_attention_heads
|
203 |
+
)
|
204 |
+
|
205 |
+
self.c_attn = nn.Linear(config.hidden_size, 3 * self.projection_size)
|
206 |
+
|
207 |
+
self.c_proj = nn.Linear(
|
208 |
+
config.hidden_size, self.projection_size, bias=not config.no_bias
|
209 |
+
)
|
210 |
+
|
211 |
+
self.is_fp32 = not (config.bf16 or config.fp16)
|
212 |
+
if (
|
213 |
+
self.use_flash_attn
|
214 |
+
and flash_attn_unpadded_func is not None
|
215 |
+
and not self.is_fp32
|
216 |
+
):
|
217 |
+
self.core_attention_flash = FlashSelfAttention(
|
218 |
+
causal=True, attention_dropout=config.attn_dropout_prob
|
219 |
+
)
|
220 |
+
self.bf16 = config.bf16
|
221 |
+
|
222 |
+
self.use_dynamic_ntk = config.use_dynamic_ntk
|
223 |
+
self.use_logn_attn = config.use_logn_attn
|
224 |
+
|
225 |
+
logn_list = [
|
226 |
+
math.log(i, self.seq_length) if i > self.seq_length else 1
|
227 |
+
for i in range(1, 32768)
|
228 |
+
]
|
229 |
+
self.logn_tensor = torch.tensor(logn_list)[None, :, None, None]
|
230 |
+
|
231 |
+
self.attn_dropout = nn.Dropout(config.attn_dropout_prob)
|
232 |
+
|
233 |
+
def _attn(self, query, key, value, registered_causal_mask, attention_mask=None, head_mask=None):
|
234 |
+
attn_weights = torch.matmul(query, key.transpose(-1, -2))
|
235 |
+
|
236 |
+
if self.scale_attn_weights:
|
237 |
+
attn_weights = attn_weights / torch.full(
|
238 |
+
[],
|
239 |
+
value.size(-1) ** 0.5,
|
240 |
+
dtype=attn_weights.dtype,
|
241 |
+
device=attn_weights.device,
|
242 |
+
)
|
243 |
+
|
244 |
+
query_length, key_length = query.size(-2), key.size(-2)
|
245 |
+
causal_mask = registered_causal_mask[
|
246 |
+
:, :, key_length - query_length : key_length, :key_length
|
247 |
+
]
|
248 |
+
mask_value = torch.finfo(attn_weights.dtype).min
|
249 |
+
mask_value = torch.full([], mask_value, dtype=attn_weights.dtype).to(
|
250 |
+
attn_weights.device
|
251 |
+
)
|
252 |
+
attn_weights = torch.where(
|
253 |
+
causal_mask, attn_weights.to(attn_weights.dtype), mask_value
|
254 |
+
)
|
255 |
+
|
256 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1)
|
257 |
+
|
258 |
+
attn_weights = attn_weights.type(value.dtype)
|
259 |
+
attn_weights = self.attn_dropout(attn_weights)
|
260 |
+
|
261 |
+
if head_mask is not None:
|
262 |
+
attn_weights = attn_weights * head_mask
|
263 |
+
|
264 |
+
attn_output = torch.matmul(attn_weights, value)
|
265 |
+
attn_output = attn_output.transpose(1, 2)
|
266 |
+
|
267 |
+
return attn_output, attn_weights
|
268 |
+
|
269 |
+
def _upcast_and_reordered_attn(
|
270 |
+
self, query, key, value, registered_causal_mask, attention_mask=None, head_mask=None
|
271 |
+
):
|
272 |
+
bsz, num_heads, q_seq_len, dk = query.size()
|
273 |
+
_, _, k_seq_len, _ = key.size()
|
274 |
+
|
275 |
+
attn_weights = torch.empty(
|
276 |
+
bsz * num_heads,
|
277 |
+
q_seq_len,
|
278 |
+
k_seq_len,
|
279 |
+
dtype=torch.float32,
|
280 |
+
device=query.device,
|
281 |
+
)
|
282 |
+
|
283 |
+
scale_factor = 1.0
|
284 |
+
if self.scale_attn_weights:
|
285 |
+
scale_factor /= float(value.size(-1)) ** 0.5
|
286 |
+
|
287 |
+
with autocast(enabled=False):
|
288 |
+
q, k = query.reshape(-1, q_seq_len, dk), key.transpose(-1, -2).reshape(
|
289 |
+
-1, dk, k_seq_len
|
290 |
+
)
|
291 |
+
attn_weights = torch.baddbmm(
|
292 |
+
attn_weights, q.float(), k.float(), beta=0, alpha=scale_factor
|
293 |
+
)
|
294 |
+
attn_weights = attn_weights.reshape(bsz, num_heads, q_seq_len, k_seq_len)
|
295 |
+
|
296 |
+
query_length, key_length = query.size(-2), key.size(-2)
|
297 |
+
causal_mask = registered_causal_mask[
|
298 |
+
:, :, key_length - query_length : key_length, :key_length
|
299 |
+
]
|
300 |
+
mask_value = torch.finfo(attn_weights.dtype).min
|
301 |
+
mask_value = torch.tensor(mask_value, dtype=attn_weights.dtype).to(
|
302 |
+
attn_weights.device
|
303 |
+
)
|
304 |
+
attn_weights = torch.where(causal_mask, attn_weights, mask_value)
|
305 |
+
|
306 |
+
if attention_mask is not None:
|
307 |
+
attn_weights = attn_weights + attention_mask
|
308 |
+
|
309 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1)
|
310 |
+
|
311 |
+
if attn_weights.dtype != torch.float32:
|
312 |
+
raise RuntimeError(
|
313 |
+
"Error with upcasting, attn_weights does not have dtype torch.float32"
|
314 |
+
)
|
315 |
+
attn_weights = attn_weights.type(value.dtype)
|
316 |
+
attn_weights = self.attn_dropout(attn_weights)
|
317 |
+
|
318 |
+
if head_mask is not None:
|
319 |