liang.zhao
commited on
Commit
•
9952cfb
1
Parent(s):
5e9642a
update model and config
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +53 -0
- config.json +27 -0
- configuration_skywork.py +76 -0
- generation_config.json +10 -0
- modeling_skywork.py +1111 -0
- pytorch_model-00001-of-00053.bin +3 -0
- pytorch_model-00002-of-00053.bin +3 -0
- pytorch_model-00003-of-00053.bin +3 -0
- pytorch_model-00004-of-00053.bin +3 -0
- pytorch_model-00005-of-00053.bin +3 -0
- pytorch_model-00006-of-00053.bin +3 -0
- pytorch_model-00007-of-00053.bin +3 -0
- pytorch_model-00008-of-00053.bin +3 -0
- pytorch_model-00009-of-00053.bin +3 -0
- pytorch_model-00010-of-00053.bin +3 -0
- pytorch_model-00011-of-00053.bin +3 -0
- pytorch_model-00012-of-00053.bin +3 -0
- pytorch_model-00013-of-00053.bin +3 -0
- pytorch_model-00014-of-00053.bin +3 -0
- pytorch_model-00015-of-00053.bin +3 -0
- pytorch_model-00016-of-00053.bin +3 -0
- pytorch_model-00017-of-00053.bin +3 -0
- pytorch_model-00018-of-00053.bin +3 -0
- pytorch_model-00019-of-00053.bin +3 -0
- pytorch_model-00020-of-00053.bin +3 -0
- pytorch_model-00021-of-00053.bin +3 -0
- pytorch_model-00022-of-00053.bin +3 -0
- pytorch_model-00023-of-00053.bin +3 -0
- pytorch_model-00024-of-00053.bin +3 -0
- pytorch_model-00025-of-00053.bin +3 -0
- pytorch_model-00026-of-00053.bin +3 -0
- pytorch_model-00027-of-00053.bin +3 -0
- pytorch_model-00028-of-00053.bin +3 -0
- pytorch_model-00029-of-00053.bin +3 -0
- pytorch_model-00030-of-00053.bin +3 -0
- pytorch_model-00031-of-00053.bin +3 -0
- pytorch_model-00032-of-00053.bin +3 -0
- pytorch_model-00033-of-00053.bin +3 -0
- pytorch_model-00034-of-00053.bin +3 -0
- pytorch_model-00035-of-00053.bin +3 -0
- pytorch_model-00036-of-00053.bin +3 -0
- pytorch_model-00037-of-00053.bin +3 -0
- pytorch_model-00038-of-00053.bin +3 -0
- pytorch_model-00039-of-00053.bin +3 -0
- pytorch_model-00040-of-00053.bin +3 -0
- pytorch_model-00041-of-00053.bin +3 -0
- pytorch_model-00042-of-00053.bin +3 -0
- pytorch_model-00043-of-00053.bin +3 -0
- pytorch_model-00044-of-00053.bin +3 -0
- pytorch_model-00045-of-00053.bin +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,56 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
pytorch_model-00052-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
37 |
+
pytorch_model-00030-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
38 |
+
pytorch_model-00041-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
39 |
+
pytorch_model-00045-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
40 |
+
pytorch_model-00003-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
41 |
+
pytorch_model-00008-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
42 |
+
pytorch_model-00032-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
43 |
+
pytorch_model-00046-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
44 |
+
pytorch_model-00048-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
45 |
+
pytorch_model-00012-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
46 |
+
pytorch_model-00049-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
47 |
+
pytorch_model-00050-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
48 |
+
pytorch_model-00013-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
49 |
+
pytorch_model-00027-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
50 |
+
pytorch_model-00006-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
51 |
+
pytorch_model-00022-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
52 |
+
pytorch_model-00023-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
53 |
+
pytorch_model-00036-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
54 |
+
pytorch_model-00010-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
55 |
+
pytorch_model-00011-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
56 |
+
pytorch_model-00016-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
57 |
+
pytorch_model-00040-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
58 |
+
pytorch_model-00014-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
59 |
+
pytorch_model-00029-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
60 |
+
pytorch_model-00037-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
61 |
+
pytorch_model-00044-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
62 |
+
pytorch_model-00005-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
63 |
+
pytorch_model-00028-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
64 |
+
pytorch_model-00035-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
65 |
+
pytorch_model-00009-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
66 |
+
pytorch_model-00021-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
67 |
+
pytorch_model-00039-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
68 |
+
pytorch_model-00047-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
69 |
+
pytorch_model-00017-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
70 |
+
pytorch_model-00019-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
71 |
+
pytorch_model-00020-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
72 |
+
pytorch_model-00004-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
73 |
+
pytorch_model-00034-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
74 |
+
pytorch_model-00002-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
75 |
+
pytorch_model-00033-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
76 |
+
pytorch_model-00038-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
77 |
+
pytorch_model-00043-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
78 |
+
pytorch_model-00053-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
79 |
+
pytorch_model-00024-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
80 |
+
pytorch_model-00031-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
81 |
+
pytorch_model-00025-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
82 |
+
pytorch_model-00026-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
83 |
+
pytorch_model-00051-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
84 |
+
pytorch_model-00001-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
85 |
+
pytorch_model-00042-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
86 |
+
pytorch_model-00015-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
87 |
+
pytorch_model-00007-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
88 |
+
pytorch_model-00018-of-00053.bin filter=lfs diff=lfs merge=lfs -text
|
config.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"SkyworkForCausalLM"
|
4 |
+
],
|
5 |
+
"auto_map": {
|
6 |
+
"AutoConfig": "configuration_skywork.SkyworkConfig",
|
7 |
+
"AutoModelForCausalLM": "modeling_skywork.SkyworkForCausalLM"
|
8 |
+
},
|
9 |
+
"bos_token_id": 1,
|
10 |
+
"eos_token_id": 2,
|
11 |
+
"pad_token_id": 0,
|
12 |
+
"hidden_act": "silu",
|
13 |
+
"hidden_size": 4608,
|
14 |
+
"initializer_range": 0.01,
|
15 |
+
"intermediate_size": 12288,
|
16 |
+
"max_position_embeddings": 4096,
|
17 |
+
"model_type": "skywork",
|
18 |
+
"num_attention_heads": 36,
|
19 |
+
"num_hidden_layers": 52,
|
20 |
+
"num_key_value_heads": 36,
|
21 |
+
"rms_norm_eps": 1e-06,
|
22 |
+
"tie_word_embeddings": false,
|
23 |
+
"torch_dtype": "bfloat16",
|
24 |
+
"transformers_version": "4.33.1",
|
25 |
+
"use_cache": true,
|
26 |
+
"vocab_size": 65519
|
27 |
+
}
|
configuration_skywork.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) SkyworkAI and the HuggingFace Inc. team. All rights reserved.
|
2 |
+
# This code is built upon Huggingface's transformers repository.
|
3 |
+
|
4 |
+
from transformers.configuration_utils import PretrainedConfig
|
5 |
+
from transformers.utils import logging
|
6 |
+
|
7 |
+
|
8 |
+
logger = logging.get_logger(__name__)
|
9 |
+
|
10 |
+
Skywork_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
|
11 |
+
|
12 |
+
|
13 |
+
class SkyworkConfig(PretrainedConfig):
|
14 |
+
|
15 |
+
model_type = "skywork"
|
16 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
17 |
+
|
18 |
+
def __init__(
|
19 |
+
self,
|
20 |
+
vocab_size=32000,
|
21 |
+
hidden_size=4096,
|
22 |
+
intermediate_size=11008,
|
23 |
+
num_hidden_layers=32,
|
24 |
+
num_attention_heads=32,
|
25 |
+
num_key_value_heads=None,
|
26 |
+
hidden_act="silu",
|
27 |
+
max_position_embeddings=2048,
|
28 |
+
initializer_range=0.02,
|
29 |
+
rms_norm_eps=1e-6,
|
30 |
+
use_cache=True,
|
31 |
+
pad_token_id=0,
|
32 |
+
bos_token_id=1,
|
33 |
+
eos_token_id=2,
|
34 |
+
pretraining_tp=1,
|
35 |
+
tie_word_embeddings=False,
|
36 |
+
rope_scaling=None,
|
37 |
+
rope_theta=10000.0,
|
38 |
+
attention_bias=False,
|
39 |
+
use_flash_attention=False,
|
40 |
+
**kwargs,
|
41 |
+
):
|
42 |
+
self.vocab_size = vocab_size
|
43 |
+
self.max_position_embeddings = max_position_embeddings
|
44 |
+
self.hidden_size = hidden_size
|
45 |
+
self.intermediate_size = intermediate_size
|
46 |
+
self.num_hidden_layers = num_hidden_layers
|
47 |
+
self.num_attention_heads = num_attention_heads
|
48 |
+
|
49 |
+
# for backward compatibility
|
50 |
+
if num_key_value_heads is None:
|
51 |
+
num_key_value_heads = num_attention_heads
|
52 |
+
|
53 |
+
self.num_key_value_heads = num_key_value_heads
|
54 |
+
self.hidden_act = hidden_act
|
55 |
+
self.initializer_range = initializer_range
|
56 |
+
self.rms_norm_eps = rms_norm_eps
|
57 |
+
self.pretraining_tp = pretraining_tp
|
58 |
+
self.use_cache = use_cache
|
59 |
+
self.rope_scaling = rope_scaling
|
60 |
+
self.rope_theta = rope_theta
|
61 |
+
self.attention_bias = attention_bias
|
62 |
+
self.use_flash_attention = use_flash_attention
|
63 |
+
if self.use_flash_attention:
|
64 |
+
try:
|
65 |
+
from flash_attn.flash_attn_interface import flash_attn_varlen_func
|
66 |
+
from einops import rearrange
|
67 |
+
except:
|
68 |
+
raise ValueError("`use_flash_attention` requires Flash Attention 2+ and einops.\nTry `pip install einops` and installing Flash Attention from from https://github.com/Dao-AILab/flash-attention")
|
69 |
+
|
70 |
+
super().__init__(
|
71 |
+
pad_token_id=pad_token_id,
|
72 |
+
bos_token_id=bos_token_id,
|
73 |
+
eos_token_id=eos_token_id,
|
74 |
+
tie_word_embeddings=tie_word_embeddings,
|
75 |
+
**kwargs,
|
76 |
+
)
|
generation_config.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token_id": 1,
|
3 |
+
"do_sample": true,
|
4 |
+
"eos_token_id": 2,
|
5 |
+
"max_length": 4096,
|
6 |
+
"pad_token_id": 0,
|
7 |
+
"temperature": 0.6,
|
8 |
+
"top_p": 0.9,
|
9 |
+
"transformers_version": "4.34.0"
|
10 |
+
}
|
modeling_skywork.py
ADDED
@@ -0,0 +1,1111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) SkyworkAI and the HuggingFace Inc. team. All rights reserved.
|
2 |
+
# This code is built upon Huggingface's transformers repository.
|
3 |
+
import math
|
4 |
+
from typing import List, Optional, Tuple, Union
|
5 |
+
|
6 |
+
import torch
|
7 |
+
import torch.nn.functional as F
|
8 |
+
import torch.utils.checkpoint
|
9 |
+
from torch import nn
|
10 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
11 |
+
|
12 |
+
from transformers.activations import ACT2FN
|
13 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
|
14 |
+
from transformers.modeling_utils import PreTrainedModel
|
15 |
+
from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS
|
16 |
+
from transformers.utils import (
|
17 |
+
add_start_docstrings,
|
18 |
+
add_start_docstrings_to_model_forward,
|
19 |
+
is_flash_attn_available,
|
20 |
+
logging,
|
21 |
+
replace_return_docstrings,
|
22 |
+
)
|
23 |
+
from .configuration_skywork import SkyworkConfig
|
24 |
+
|
25 |
+
|
26 |
+
if is_flash_attn_available():
|
27 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
28 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
29 |
+
|
30 |
+
|
31 |
+
logger = logging.get_logger(__name__)
|
32 |
+
|
33 |
+
_CONFIG_FOR_DOC = "SkyworkConfig"
|
34 |
+
|
35 |
+
|
36 |
+
def _get_unpad_data(padding_mask):
|
37 |
+
seqlens_in_batch = padding_mask.sum(dim=-1, dtype=torch.int32)
|
38 |
+
indices = torch.nonzero(padding_mask.flatten(), as_tuple=False).flatten()
|
39 |
+
max_seqlen_in_batch = seqlens_in_batch.max().item()
|
40 |
+
cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0))
|
41 |
+
return (
|
42 |
+
indices,
|
43 |
+
cu_seqlens,
|
44 |
+
max_seqlen_in_batch,
|
45 |
+
)
|
46 |
+
|
47 |
+
|
48 |
+
# Copied from transformers.models.bart.modeling_bart._make_causal_mask
|
49 |
+
def _make_causal_mask(
|
50 |
+
input_ids_shape: torch.Size, dtype: torch.dtype, device: torch.device, past_key_values_length: int = 0
|
51 |
+
):
|
52 |
+
"""
|
53 |
+
Make causal mask used for bi-directional self-attention.
|
54 |
+
"""
|
55 |
+
bsz, tgt_len = input_ids_shape
|
56 |
+
mask = torch.full((tgt_len, tgt_len), torch.finfo(dtype).min, device=device)
|
57 |
+
mask_cond = torch.arange(mask.size(-1), device=device)
|
58 |
+
mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)
|
59 |
+
mask = mask.to(dtype)
|
60 |
+
|
61 |
+
if past_key_values_length > 0:
|
62 |
+
mask = torch.cat([torch.zeros(tgt_len, past_key_values_length, dtype=dtype, device=device), mask], dim=-1)
|
63 |
+
return mask[None, None, :, :].expand(bsz, 1, tgt_len, tgt_len + past_key_values_length)
|
64 |
+
|
65 |
+
|
66 |
+
# Copied from transformers.models.bart.modeling_bart._expand_mask
|
67 |
+
def _expand_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):
|
68 |
+
"""
|
69 |
+
Expands attention_mask from `[bsz, seq_len]` to `[bsz, 1, tgt_seq_len, src_seq_len]`.
|
70 |
+
"""
|
71 |
+
bsz, src_len = mask.size()
|
72 |
+
tgt_len = tgt_len if tgt_len is not None else src_len
|
73 |
+
|
74 |
+
expanded_mask = mask[:, None, None, :].expand(bsz, 1, tgt_len, src_len).to(dtype)
|
75 |
+
|
76 |
+
inverted_mask = 1.0 - expanded_mask
|
77 |
+
|
78 |
+
return inverted_mask.masked_fill(inverted_mask.to(torch.bool), torch.finfo(dtype).min)
|
79 |
+
|
80 |
+
|
81 |
+
class SkyworkRMSNorm(nn.Module):
|
82 |
+
def __init__(self, hidden_size, eps=1e-6):
|
83 |
+
"""
|
84 |
+
SkyworkRMSNorm is equivalent to T5LayerNorm
|
85 |
+
"""
|
86 |
+
super().__init__()
|
87 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
88 |
+
self.variance_epsilon = eps
|
89 |
+
|
90 |
+
def forward(self, hidden_states):
|
91 |
+
input_dtype = hidden_states.dtype
|
92 |
+
hidden_states = hidden_states.to(torch.float32)
|
93 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
94 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
95 |
+
return self.weight * hidden_states.to(input_dtype)
|
96 |
+
|
97 |
+
|
98 |
+
ALL_LAYERNORM_LAYERS.append(SkyworkRMSNorm)
|
99 |
+
|
100 |
+
|
101 |
+
class SkyworkRotaryEmbedding(nn.Module):
|
102 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
|
103 |
+
super().__init__()
|
104 |
+
|
105 |
+
self.dim = dim
|
106 |
+
self.max_position_embeddings = max_position_embeddings
|
107 |
+
self.base = base
|
108 |
+
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
|
109 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
110 |
+
|
111 |
+
# Build here to make `torch.jit.trace` work.
|
112 |
+
self._set_cos_sin_cache(
|
113 |
+
seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
|
114 |
+
)
|
115 |
+
|
116 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
117 |
+
self.max_seq_len_cached = seq_len
|
118 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
|
119 |
+
|
120 |
+
freqs = torch.einsum("i,j->ij", t, self.inv_freq)
|
121 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
122 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
123 |
+
self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
|
124 |
+
self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
|
125 |
+
|
126 |
+
def forward(self, x, seq_len=None):
|
127 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
128 |
+
if seq_len > self.max_seq_len_cached:
|
129 |
+
self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
|
130 |
+
|
131 |
+
return (
|
132 |
+
self.cos_cached[:seq_len].to(dtype=x.dtype),
|
133 |
+
self.sin_cached[:seq_len].to(dtype=x.dtype),
|
134 |
+
)
|
135 |
+
|
136 |
+
|
137 |
+
class SkyworkLinearScalingRotaryEmbedding(SkyworkRotaryEmbedding):
|
138 |
+
"""SkyworkRotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
|
139 |
+
|
140 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
|
141 |
+
self.scaling_factor = scaling_factor
|
142 |
+
super().__init__(dim, max_position_embeddings, base, device)
|
143 |
+
|
144 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
145 |
+
self.max_seq_len_cached = seq_len
|
146 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
|
147 |
+
t = t / self.scaling_factor
|
148 |
+
|
149 |
+
freqs = torch.einsum("i,j->ij", t, self.inv_freq)
|
150 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
151 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
152 |
+
self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
|
153 |
+
self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
|
154 |
+
|
155 |
+
|
156 |
+
class SkyworkDynamicNTKScalingRotaryEmbedding(SkyworkRotaryEmbedding):
|
157 |
+
"""SkyworkRotaryEmbedding extended with Dynamic NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla"""
|
158 |
+
|
159 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
|
160 |
+
self.scaling_factor = scaling_factor
|
161 |
+
super().__init__(dim, max_position_embeddings, base, device)
|
162 |
+
|
163 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
164 |
+
self.max_seq_len_cached = seq_len
|
165 |
+
|
166 |
+
if seq_len > self.max_position_embeddings:
|
167 |
+
base = self.base * (
|
168 |
+
(self.scaling_factor * seq_len / self.max_position_embeddings) - (self.scaling_factor - 1)
|
169 |
+
) ** (self.dim / (self.dim - 2))
|
170 |
+
inv_freq = 1.0 / (base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim))
|
171 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
172 |
+
|
173 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
|
174 |
+
|
175 |
+
freqs = torch.einsum("i,j->ij", t, self.inv_freq)
|
176 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
177 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
178 |
+
self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
|
179 |
+
self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
|
180 |
+
|
181 |
+
|
182 |
+
def rotate_half(x):
|
183 |
+
"""Rotates half the hidden dims of the input."""
|
184 |
+
x1 = x[..., : x.shape[-1] // 2]
|
185 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
186 |
+
return torch.cat((-x2, x1), dim=-1)
|
187 |
+
|
188 |
+
|
189 |
+
# Copied from transformers.models.gpt_neox.modeling_gpt_neox.apply_rotary_pos_emb
|
190 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids):
|
191 |
+
cos = cos[position_ids].unsqueeze(1) # [seq_len, dim] -> [batch_size, 1, seq_len, head_dim]
|
192 |
+
sin = sin[position_ids].unsqueeze(1)
|
193 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
194 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
195 |
+
return q_embed, k_embed
|
196 |
+
|
197 |
+
|
198 |
+
class SkyworkMLP(nn.Module):
|
199 |
+
def __init__(self, config):
|
200 |
+
super().__init__()
|
201 |
+
self.config = config
|
202 |
+
self.hidden_size = config.hidden_size
|
203 |
+
self.intermediate_size = config.intermediate_size
|
204 |
+
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
205 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
206 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
|
207 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
208 |
+
|
209 |
+
def forward(self, x):
|
210 |
+
if self.config.pretraining_tp > 1:
|
211 |
+
slice = self.intermediate_size // self.config.pretraining_tp
|
212 |
+
gate_proj_slices = self.gate_proj.weight.split(slice, dim=0)
|
213 |
+
up_proj_slices = self.up_proj.weight.split(slice, dim=0)
|
214 |
+
down_proj_slices = self.down_proj.weight.split(slice, dim=1)
|
215 |
+
|
216 |
+
gate_proj = torch.cat(
|
217 |
+
[F.linear(x, gate_proj_slices[i]) for i in range(self.config.pretraining_tp)], dim=-1
|
218 |
+
)
|
219 |
+
up_proj = torch.cat([F.linear(x, up_proj_slices[i]) for i in range(self.config.pretraining_tp)], dim=-1)
|
220 |
+
|
221 |
+
intermediate_states = (self.act_fn(gate_proj) * up_proj).split(slice, dim=2)
|
222 |
+
down_proj = [
|
223 |
+
F.linear(intermediate_states[i], down_proj_slices[i]) for i in range(self.config.pretraining_tp)
|
224 |
+
]
|
225 |
+
down_proj = sum(down_proj)
|
226 |
+
else:
|
227 |
+
down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
228 |
+
|
229 |
+
return down_proj
|
230 |
+
|
231 |
+
|
232 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
233 |
+
"""
|
234 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
235 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
236 |
+
"""
|
237 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
238 |
+
if n_rep == 1:
|
239 |
+
return hidden_states
|
240 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
241 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
242 |
+
|
243 |
+
|
244 |
+
class SkyworkAttention(nn.Module):
|
245 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
246 |
+
|
247 |
+
def __init__(self, config: SkyworkConfig):
|
248 |
+
super().__init__()
|
249 |
+
self.config = config
|
250 |
+
self.hidden_size = config.hidden_size
|
251 |
+
self.num_heads = config.num_attention_heads
|
252 |
+
self.head_dim = self.hidden_size // self.num_heads
|
253 |
+
self.num_key_value_heads = config.num_key_value_heads
|
254 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
255 |
+
self.max_position_embeddings = config.max_position_embeddings
|
256 |
+
self.rope_theta = config.rope_theta
|
257 |
+
|
258 |
+
if (self.head_dim * self.num_heads) != self.hidden_size:
|
259 |
+
raise ValueError(
|
260 |
+
f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
|
261 |
+
f" and `num_heads`: {self.num_heads})."
|
262 |
+
)
|
263 |
+
self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=config.attention_bias)
|
264 |
+
self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
|
265 |
+
self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
|
266 |
+
self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=config.attention_bias)
|
267 |
+
self._init_rope()
|
268 |
+
|
269 |
+
def _init_rope(self):
|
270 |
+
if self.config.rope_scaling is None:
|
271 |
+
self.rotary_emb = SkyworkRotaryEmbedding(
|
272 |
+
self.head_dim,
|
273 |
+
max_position_embeddings=self.max_position_embeddings,
|
274 |
+
base=self.rope_theta,
|
275 |
+
)
|
276 |
+
else:
|
277 |
+
scaling_type = self.config.rope_scaling["type"]
|
278 |
+
scaling_factor = self.config.rope_scaling["factor"]
|
279 |
+
if scaling_type == "linear":
|
280 |
+
self.rotary_emb = SkyworkLinearScalingRotaryEmbedding(
|
281 |
+
self.head_dim,
|
282 |
+
max_position_embeddings=self.max_position_embeddings,
|
283 |
+
scaling_factor=scaling_factor,
|
284 |
+
base=self.rope_theta,
|
285 |
+
)
|
286 |
+
elif scaling_type == "dynamic":
|
287 |
+
self.rotary_emb = SkyworkDynamicNTKScalingRotaryEmbedding(
|
288 |
+
self.head_dim,
|
289 |
+
max_position_embeddings=self.max_position_embeddings,
|
290 |
+
scaling_factor=scaling_factor,
|
291 |
+
base=self.rope_theta,
|
292 |
+
)
|
293 |
+
else:
|
294 |
+
raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
|
295 |
+
|
296 |
+
def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
|
297 |
+
return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
|
298 |
+
|
299 |
+
def forward(
|
300 |
+
self,
|
301 |
+
hidden_states: torch.Tensor,
|
302 |
+
attention_mask: Optional[torch.Tensor] = None,
|
303 |
+
position_ids: Optional[torch.LongTensor] = None,
|
304 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
305 |
+
output_attentions: bool = False,
|
306 |
+
use_cache: bool = False,
|
307 |
+
padding_mask: Optional[torch.LongTensor] = None,
|
308 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
309 |
+
bsz, q_len, _ = hidden_states.size()
|
310 |
+
|
311 |
+
if self.config.pretraining_tp > 1:
|
312 |
+
key_value_slicing = (self.num_key_value_heads * self.head_dim) // self.config.pretraining_tp
|
313 |
+
query_slices = self.q_proj.weight.split(
|
314 |
+
(self.num_heads * self.head_dim) // self.config.pretraining_tp, dim=0
|
315 |
+
)
|
316 |
+
key_slices = self.k_proj.weight.split(key_value_slicing, dim=0)
|
317 |
+
value_slices = self.v_proj.weight.split(key_value_slicing, dim=0)
|
318 |
+
|
319 |
+
query_states = [F.linear(hidden_states, query_slices[i]) for i in range(self.config.pretraining_tp)]
|
320 |
+
query_states = torch.cat(query_states, dim=-1)
|
321 |
+
|
322 |
+
key_states = [F.linear(hidden_states, key_slices[i]) for i in range(self.config.pretraining_tp)]
|
323 |
+
key_states = torch.cat(key_states, dim=-1)
|
324 |
+
|
325 |
+
value_states = [F.linear(hidden_states, value_slices[i]) for i in range(self.config.pretraining_tp)]
|
326 |
+
value_states = torch.cat(value_states, dim=-1)
|
327 |
+
|
328 |
+
else:
|
329 |
+
query_states = self.q_proj(hidden_states)
|
330 |
+
key_states = self.k_proj(hidden_states)
|
331 |
+
value_states = self.v_proj(hidden_states)
|
332 |
+
|
333 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
334 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
335 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
336 |
+
|
337 |
+
kv_seq_len = key_states.shape[-2]
|
338 |
+
if past_key_value is not None:
|
339 |
+
kv_seq_len += past_key_value[0].shape[-2]
|
340 |
+
cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
|
341 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
342 |
+
|
343 |
+
if past_key_value is not None:
|
344 |
+
# reuse k, v, self_attention
|
345 |
+
key_states = torch.cat([past_key_value[0], key_states], dim=2)
|
346 |
+
value_states = torch.cat([past_key_value[1], value_states], dim=2)
|
347 |
+
|
348 |
+
past_key_value = (key_states, value_states) if use_cache else None
|
349 |
+
|
350 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
351 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
352 |
+
|
353 |
+
attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
|
354 |
+
|
355 |
+
if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
|
356 |
+
raise ValueError(
|
357 |
+
f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
|
358 |
+
f" {attn_weights.size()}"
|
359 |
+
)
|
360 |
+
|
361 |
+
if attention_mask is not None:
|
362 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
363 |
+
raise ValueError(
|
364 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
365 |
+
)
|
366 |
+
attn_weights = attn_weights + attention_mask
|
367 |
+
|
368 |
+
# upcast attention to fp32
|
369 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
|
370 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
371 |
+
|
372 |
+
if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
|
373 |
+
raise ValueError(
|
374 |
+
f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
|
375 |
+
f" {attn_output.size()}"
|
376 |
+
)
|
377 |
+
|
378 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
379 |
+
|
380 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
381 |
+
|
382 |
+
if self.config.pretraining_tp > 1:
|
383 |
+
attn_output = attn_output.split(self.hidden_size // self.config.pretraining_tp, dim=2)
|
384 |
+
o_proj_slices = self.o_proj.weight.split(self.hidden_size // self.config.pretraining_tp, dim=1)
|
385 |
+
attn_output = sum([F.linear(attn_output[i], o_proj_slices[i]) for i in range(self.config.pretraining_tp)])
|
386 |
+
else:
|
387 |
+
attn_output = self.o_proj(attn_output)
|
388 |
+
|
389 |
+
if not output_attentions:
|
390 |
+
attn_weights = None
|
391 |
+
|
392 |
+
return attn_output, attn_weights, past_key_value
|
393 |
+
|
394 |
+
|
395 |
+
class SkyworkFlashAttention2(SkyworkAttention):
|
396 |
+
"""
|
397 |
+
Skywork flash attention module. This module inherits from `SkyworkAttention` as the weights of the module stays
|
398 |
+
untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
|
399 |
+
flash attention and deal with padding tokens in case the input contains any of them.
|
400 |
+
"""
|
401 |
+
|
402 |
+
def forward(
|
403 |
+
self,
|
404 |
+
hidden_states: torch.Tensor,
|
405 |
+
attention_mask: Optional[torch.Tensor] = None,
|
406 |
+
position_ids: Optional[torch.LongTensor] = None,
|
407 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
408 |
+
output_attentions: bool = False,
|
409 |
+
use_cache: bool = False,
|
410 |
+
padding_mask: Optional[torch.LongTensor] = None,
|
411 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
412 |
+
# SkyworkFlashAttention2 attention does not support output_attentions
|
413 |
+
output_attentions = False
|
414 |
+
|
415 |
+
bsz, q_len, _ = hidden_states.size()
|
416 |
+
|
417 |
+
query_states = self.q_proj(hidden_states)
|
418 |
+
key_states = self.k_proj(hidden_states)
|
419 |
+
value_states = self.v_proj(hidden_states)
|
420 |
+
|
421 |
+
# Flash attention requires the input to have the shape
|
422 |
+
# batch_size x seq_length x head_dime x hidden_dim
|
423 |
+
# therefore we just need to keep the original shape
|
424 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
425 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
426 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
427 |
+
|
428 |
+
kv_seq_len = key_states.shape[-2]
|
429 |
+
if past_key_value is not None:
|
430 |
+
kv_seq_len += past_key_value[0].shape[-2]
|
431 |
+
|
432 |
+
cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
|
433 |
+
|
434 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
435 |
+
|
436 |
+
if past_key_value is not None:
|
437 |
+
# reuse k, v, self_attention
|
438 |
+
key_states = torch.cat([past_key_value[0], key_states], dim=2)
|
439 |
+
value_states = torch.cat([past_key_value[1], value_states], dim=2)
|
440 |
+
|
441 |
+
past_key_value = (key_states, value_states) if use_cache else None
|
442 |
+
|
443 |
+
query_states = query_states.transpose(1, 2)
|
444 |
+
key_states = key_states.transpose(1, 2)
|
445 |
+
value_states = value_states.transpose(1, 2)
|
446 |
+
|
447 |
+
# TODO: skywork does not have dropout in the config??
|
448 |
+
# It is recommended to use dropout with FA according to the docs
|
449 |
+
# when training.
|
450 |
+
dropout_rate = 0.0 # if not self.training else self.attn_dropout
|
451 |
+
|
452 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
453 |
+
# therefore the input hidden states gets silently casted in float32. Hence, we need
|
454 |
+
# cast them back in float16 just to be sure everything works as expected.
|
455 |
+
# This might slowdown training & inference so it is recommended to not cast the LayerNorms
|
456 |
+
# in fp32. (SkyworkRMSNorm handles it correctly)
|
457 |
+
input_dtype = query_states.dtype
|
458 |
+
if input_dtype == torch.float32:
|
459 |
+
logger.warning_once(
|
460 |
+
"The input hidden states seems to be silently casted in float32, this might be related to"
|
461 |
+
" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
|
462 |
+
" float16."
|
463 |
+
)
|
464 |
+
|
465 |
+
query_states = query_states.to(torch.float16)
|
466 |
+
key_states = key_states.to(torch.float16)
|
467 |
+
value_states = value_states.to(torch.float16)
|
468 |
+
|
469 |
+
attn_output = self._flash_attention_forward(
|
470 |
+
query_states, key_states, value_states, padding_mask, q_len, dropout=dropout_rate
|
471 |
+
)
|
472 |
+
|
473 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
|
474 |
+
attn_output = self.o_proj(attn_output)
|
475 |
+
|
476 |
+
if not output_attentions:
|
477 |
+
attn_weights = None
|
478 |
+
|
479 |
+
return attn_output, attn_weights, past_key_value
|
480 |
+
|
481 |
+
def _flash_attention_forward(
|
482 |
+
self, query_states, key_states, value_states, padding_mask, query_length, dropout=0.0, softmax_scale=None
|
483 |
+
):
|
484 |
+
"""
|
485 |
+
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
|
486 |
+
first unpad the input, then computes the attention scores and pad the final attention scores.
|
487 |
+
|
488 |
+
Args:
|
489 |
+
query_states (`torch.Tensor`):
|
490 |
+
Input query states to be passed to Flash Attention API
|
491 |
+
key_states (`torch.Tensor`):
|
492 |
+
Input key states to be passed to Flash Attention API
|
493 |
+
value_states (`torch.Tensor`):
|
494 |
+
Input value states to be passed to Flash Attention API
|
495 |
+
padding_mask (`torch.Tensor`):
|
496 |
+
The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
|
497 |
+
position of padding tokens and 1 for the position of non-padding tokens.
|
498 |
+
dropout (`int`, *optional*):
|
499 |
+
Attention dropout
|
500 |
+
softmax_scale (`float`, *optional*):
|
501 |
+
The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
|
502 |
+
"""
|
503 |
+
# Contains at least one padding token in the sequence
|
504 |
+
if padding_mask is not None:
|
505 |
+
batch_size = query_states.shape[0]
|
506 |
+
query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
|
507 |
+
query_states, key_states, value_states, padding_mask, query_length
|
508 |
+
)
|
509 |
+
|
510 |
+
cu_seqlens_q, cu_seqlens_k = cu_seq_lens
|
511 |
+
max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
|
512 |
+
|
513 |
+
attn_output_unpad = flash_attn_varlen_func(
|
514 |
+
query_states,
|
515 |
+
key_states,
|
516 |
+
value_states,
|
517 |
+
cu_seqlens_q=cu_seqlens_q,
|
518 |
+
cu_seqlens_k=cu_seqlens_k,
|
519 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
520 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
521 |
+
dropout_p=dropout,
|
522 |
+
softmax_scale=softmax_scale,
|
523 |
+
causal=True,
|
524 |
+
)
|
525 |
+
|
526 |
+
attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
|
527 |
+
else:
|
528 |
+
attn_output = flash_attn_func(
|
529 |
+
query_states, key_states, value_states, dropout, softmax_scale=softmax_scale, causal=True
|
530 |
+
)
|
531 |
+
|
532 |
+
return attn_output
|
533 |
+
|
534 |
+
def _upad_input(self, query_layer, key_layer, value_layer, padding_mask, query_length):
|
535 |
+
indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(padding_mask)
|
536 |
+
batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
|
537 |
+
|
538 |
+
key_layer = index_first_axis(
|
539 |
+
key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
|
540 |
+
)
|
541 |
+
value_layer = index_first_axis(
|
542 |
+
value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
|
543 |
+
)
|
544 |
+
if query_length == kv_seq_len:
|
545 |
+
query_layer = index_first_axis(
|
546 |
+
query_layer.reshape(batch_size * kv_seq_len, self.num_heads, head_dim), indices_k
|
547 |
+
)
|
548 |
+
cu_seqlens_q = cu_seqlens_k
|
549 |
+
max_seqlen_in_batch_q = max_seqlen_in_batch_k
|
550 |
+
indices_q = indices_k
|
551 |
+
elif query_length == 1:
|
552 |
+
max_seqlen_in_batch_q = 1
|
553 |
+
cu_seqlens_q = torch.arange(
|
554 |
+
batch_size + 1, dtype=torch.int32, device=query_layer.device
|
555 |
+
) # There is a memcpy here, that is very bad.
|
556 |
+
indices_q = cu_seqlens_q[:-1]
|
557 |
+
query_layer = query_layer.squeeze(1)
|
558 |
+
else:
|
559 |
+
# The -q_len: slice assumes left padding.
|
560 |
+
padding_mask = padding_mask[:, -query_length:]
|
561 |
+
query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, padding_mask)
|
562 |
+
|
563 |
+
return (
|
564 |
+
query_layer,
|
565 |
+
key_layer,
|
566 |
+
value_layer,
|
567 |
+
indices_q,
|
568 |
+
(cu_seqlens_q, cu_seqlens_k),
|
569 |
+
(max_seqlen_in_batch_q, max_seqlen_in_batch_k),
|
570 |
+
)
|
571 |
+
|
572 |
+
|
573 |
+
class SkyworkDecoderLayer(nn.Module):
|
574 |
+
def __init__(self, config: SkyworkConfig):
|
575 |
+
super().__init__()
|
576 |
+
self.hidden_size = config.hidden_size
|
577 |
+
self.self_attn = (
|
578 |
+
SkyworkAttention(config=config)
|
579 |
+
if not getattr(config, "_flash_attn_2_enabled", False)
|
580 |
+
else SkyworkFlashAttention2(config=config)
|
581 |
+
)
|
582 |
+
self.mlp = SkyworkMLP(config)
|
583 |
+
self.input_layernorm = SkyworkRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
584 |
+
self.post_attention_layernorm = SkyworkRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
585 |
+
|
586 |
+
def forward(
|
587 |
+
self,
|
588 |
+
hidden_states: torch.Tensor,
|
589 |
+
attention_mask: Optional[torch.Tensor] = None,
|
590 |
+
position_ids: Optional[torch.LongTensor] = None,
|
591 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
592 |
+
output_attentions: Optional[bool] = False,
|
593 |
+
use_cache: Optional[bool] = False,
|
594 |
+
padding_mask: Optional[torch.LongTensor] = None,
|
595 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
596 |
+
"""
|
597 |
+
Args:
|
598 |
+
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
|
599 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
600 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
601 |
+
output_attentions (`bool`, *optional*):
|
602 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
603 |
+
returned tensors for more detail.
|
604 |
+
use_cache (`bool`, *optional*):
|
605 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
606 |
+
(see `past_key_values`).
|
607 |
+
past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
|
608 |
+
"""
|
609 |
+
|
610 |
+
residual = hidden_states
|
611 |
+
|
612 |
+
hidden_states = self.input_layernorm(hidden_states)
|
613 |
+
|
614 |
+
# Self Attention
|
615 |
+
hidden_states, self_attn_weights, present_key_value = self.self_attn(
|
616 |
+
hidden_states=hidden_states,
|
617 |
+
attention_mask=attention_mask,
|
618 |
+
position_ids=position_ids,
|
619 |
+
past_key_value=past_key_value,
|
620 |
+
output_attentions=output_attentions,
|
621 |
+
use_cache=use_cache,
|
622 |
+
padding_mask=padding_mask,
|
623 |
+
)
|
624 |
+
hidden_states = residual + hidden_states
|
625 |
+
|
626 |
+
# Fully Connected
|
627 |
+
residual = hidden_states
|
628 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
629 |
+
hidden_states = self.mlp(hidden_states)
|
630 |
+
hidden_states = residual + hidden_states
|
631 |
+
|
632 |
+
outputs = (hidden_states,)
|
633 |
+
|
634 |
+
if output_attentions:
|
635 |
+
outputs += (self_attn_weights,)
|
636 |
+
|
637 |
+
if use_cache:
|
638 |
+
outputs += (present_key_value,)
|
639 |
+
|
640 |
+
return outputs
|
641 |
+
|
642 |
+
class SkyworkPreTrainedModel(PreTrainedModel):
|
643 |
+
config_class = SkyworkConfig
|
644 |
+
base_model_prefix = "model"
|
645 |
+
supports_gradient_checkpointing = True
|
646 |
+
_no_split_modules = ["SkyworkDecoderLayer"]
|
647 |
+
_skip_keys_device_placement = "past_key_values"
|
648 |
+
_supports_flash_attn_2 = True
|
649 |
+
|
650 |
+
def _init_weights(self, module):
|
651 |
+
std = self.config.initializer_range
|
652 |
+
if isinstance(module, nn.Linear):
|
653 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
654 |
+
if module.bias is not None:
|
655 |
+
module.bias.data.zero_()
|
656 |
+
elif isinstance(module, nn.Embedding):
|
657 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
658 |
+
if module.padding_idx is not None:
|
659 |
+
module.weight.data[module.padding_idx].zero_()
|
660 |
+
|
661 |
+
def _set_gradient_checkpointing(self, module, value=False):
|
662 |
+
if isinstance(module, SkyworkModel):
|
663 |
+
module.gradient_checkpointing = value
|
664 |
+
|
665 |
+
class SkyworkModel(SkyworkPreTrainedModel):
|
666 |
+
"""
|
667 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`SkyworkDecoderLayer`]
|
668 |
+
|
669 |
+
Args:
|
670 |
+
config: SkyworkConfig
|
671 |
+
"""
|
672 |
+
|
673 |
+
def __init__(self, config: SkyworkConfig):
|
674 |
+
super().__init__(config)
|
675 |
+
self.padding_idx = config.pad_token_id
|
676 |
+
self.vocab_size = config.vocab_size
|
677 |
+
|
678 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
679 |
+
self.layers = nn.ModuleList([SkyworkDecoderLayer(config) for _ in range(config.num_hidden_layers)])
|
680 |
+
self.norm = SkyworkRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
681 |
+
|
682 |
+
self.gradient_checkpointing = False
|
683 |
+
# Initialize weights and apply final processing
|
684 |
+
self.post_init()
|
685 |
+
|
686 |
+
def get_input_embeddings(self):
|
687 |
+
return self.embed_tokens
|
688 |
+
|
689 |
+
def set_input_embeddings(self, value):
|
690 |
+
self.embed_tokens = value
|
691 |
+
|
692 |
+
# Copied from transformers.models.bart.modeling_bart.BartDecoder._prepare_decoder_attention_mask
|
693 |
+
def _prepare_decoder_attention_mask(self, attention_mask, input_shape, inputs_embeds, past_key_values_length):
|
694 |
+
# create causal mask
|
695 |
+
# [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
|
696 |
+
combined_attention_mask = None
|
697 |
+
if input_shape[-1] > 1:
|
698 |
+
combined_attention_mask = _make_causal_mask(
|
699 |
+
input_shape,
|
700 |
+
inputs_embeds.dtype,
|
701 |
+
device=inputs_embeds.device,
|
702 |
+
past_key_values_length=past_key_values_length,
|
703 |
+
)
|
704 |
+
|
705 |
+
if attention_mask is not None:
|
706 |
+
# [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
|
707 |
+
expanded_attn_mask = _expand_mask(attention_mask, inputs_embeds.dtype, tgt_len=input_shape[-1]).to(
|
708 |
+
inputs_embeds.device
|
709 |
+
)
|
710 |
+
combined_attention_mask = (
|
711 |
+
expanded_attn_mask if combined_attention_mask is None else expanded_attn_mask + combined_attention_mask
|
712 |
+
)
|
713 |
+
|
714 |
+
return combined_attention_mask
|
715 |
+
|
716 |
+
def forward(
|
717 |
+
self,
|
718 |
+
input_ids: torch.LongTensor = None,
|
719 |
+
attention_mask: Optional[torch.Tensor] = None,
|
720 |
+
position_ids: Optional[torch.LongTensor] = None,
|
721 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
722 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
723 |
+
use_cache: Optional[bool] = None,
|
724 |
+
output_attentions: Optional[bool] = None,
|
725 |
+
output_hidden_states: Optional[bool] = None,
|
726 |
+
return_dict: Optional[bool] = None,
|
727 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
728 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
729 |
+
output_hidden_states = (
|
730 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
731 |
+
)
|
732 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
733 |
+
|
734 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
735 |
+
|
736 |
+
# retrieve input_ids and inputs_embeds
|
737 |
+
if input_ids is not None and inputs_embeds is not None:
|
738 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
739 |
+
elif input_ids is not None:
|
740 |
+
batch_size, seq_length = input_ids.shape
|
741 |
+
elif inputs_embeds is not None:
|
742 |
+
batch_size, seq_length, _ = inputs_embeds.shape
|
743 |
+
else:
|
744 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
745 |
+
|
746 |
+
seq_length_with_past = seq_length
|
747 |
+
past_key_values_length = 0
|
748 |
+
|
749 |
+
if past_key_values is not None:
|
750 |
+
past_key_values_length = past_key_values[0][0].shape[2]
|
751 |
+
seq_length_with_past = seq_length_with_past + past_key_values_length
|
752 |
+
|
753 |
+
if position_ids is None:
|
754 |
+
device = input_ids.device if input_ids is not None else inputs_embeds.device
|
755 |
+
position_ids = torch.arange(
|
756 |
+
past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=device
|
757 |
+
)
|
758 |
+
position_ids = position_ids.unsqueeze(0)
|
759 |
+
|
760 |
+
if inputs_embeds is None:
|
761 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
762 |
+
# embed positions
|
763 |
+
if attention_mask is None:
|
764 |
+
attention_mask = torch.ones(
|
765 |
+
(batch_size, seq_length_with_past), dtype=torch.bool, device=inputs_embeds.device
|
766 |
+
)
|
767 |
+
padding_mask = None
|
768 |
+
else:
|
769 |
+
if 0 in attention_mask:
|
770 |
+
padding_mask = attention_mask
|
771 |
+
else:
|
772 |
+
padding_mask = None
|
773 |
+
|
774 |
+
attention_mask = self._prepare_decoder_attention_mask(
|
775 |
+
attention_mask, (batch_size, seq_length), inputs_embeds, past_key_values_length
|
776 |
+
)
|
777 |
+
|
778 |
+
hidden_states = inputs_embeds
|
779 |
+
|
780 |
+
if self.gradient_checkpointing and self.training:
|
781 |
+
if use_cache:
|
782 |
+
logger.warning_once(
|
783 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
784 |
+
)
|
785 |
+
use_cache = False
|
786 |
+
|
787 |
+
# decoder layers
|
788 |
+
all_hidden_states = () if output_hidden_states else None
|
789 |
+
all_self_attns = () if output_attentions else None
|
790 |
+
next_decoder_cache = () if use_cache else None
|
791 |
+
|
792 |
+
for idx, decoder_layer in enumerate(self.layers):
|
793 |
+
if output_hidden_states:
|
794 |
+
all_hidden_states += (hidden_states,)
|
795 |
+
|
796 |
+
past_key_value = past_key_values[idx] if past_key_values is not None else None
|
797 |
+
|
798 |
+
if self.gradient_checkpointing and self.training:
|
799 |
+
|
800 |
+
def create_custom_forward(module):
|
801 |
+
def custom_forward(*inputs):
|
802 |
+
# None for past_key_value
|
803 |
+
return module(*inputs, past_key_value, output_attentions, padding_mask=padding_mask)
|
804 |
+
|
805 |
+
return custom_forward
|
806 |
+
|
807 |
+
layer_outputs = torch.utils.checkpoint.checkpoint(
|
808 |
+
create_custom_forward(decoder_layer), hidden_states, attention_mask, position_ids
|
809 |
+
)
|
810 |
+
else:
|
811 |
+
layer_outputs = decoder_layer(
|
812 |
+
hidden_states,
|
813 |
+
attention_mask=attention_mask,
|
814 |
+
position_ids=position_ids,
|
815 |
+
past_key_value=past_key_value,
|
816 |
+
output_attentions=output_attentions,
|
817 |
+
use_cache=use_cache,
|
818 |
+
padding_mask=padding_mask,
|
819 |
+
)
|
820 |
+
|
821 |
+
hidden_states = layer_outputs[0]
|
822 |
+
|
823 |
+
if use_cache:
|
824 |
+
next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
|
825 |
+
|
826 |
+
if output_attentions:
|
827 |
+
all_self_attns += (layer_outputs[1],)
|
828 |
+
|
829 |
+
hidden_states = self.norm(hidden_states)
|
830 |
+
|
831 |
+
# add hidden states from the last decoder layer
|
832 |
+
if output_hidden_states:
|
833 |
+
all_hidden_states += (hidden_states,)
|
834 |
+
|
835 |
+
next_cache = next_decoder_cache if use_cache else None
|
836 |
+
if not return_dict:
|
837 |
+
return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
|
838 |
+
return BaseModelOutputWithPast(
|
839 |
+
last_hidden_state=hidden_states,
|
840 |
+
past_key_values=next_cache,
|
841 |
+
hidden_states=all_hidden_states,
|
842 |
+
attentions=all_self_attns,
|
843 |
+
)
|
844 |
+
|
845 |
+
|
846 |
+
class SkyworkForCausalLM(SkyworkPreTrainedModel):
|
847 |
+
_tied_weights_keys = ["lm_head.weight"]
|
848 |
+
|
849 |
+
def __init__(self, config):
|
850 |
+
super().__init__(config)
|
851 |
+
self.model = SkyworkModel(config)
|
852 |
+
self.vocab_size = config.vocab_size
|
853 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
854 |
+
|
855 |
+
# Initialize weights and apply final processing
|
856 |
+
self.post_init()
|
857 |
+
|
858 |
+
def get_input_embeddings(self):
|
859 |
+
return self.model.embed_tokens
|
860 |
+
|
861 |
+
def set_input_embeddings(self, value):
|
862 |
+
self.model.embed_tokens = value
|
863 |
+
|
864 |
+
def get_output_embeddings(self):
|
865 |
+
return self.lm_head
|
866 |
+
|
867 |
+
def set_output_embeddings(self, new_embeddings):
|
868 |
+
self.lm_head = new_embeddings
|
869 |
+
|
870 |
+
def set_decoder(self, decoder):
|
871 |
+
self.model = decoder
|
872 |
+
|
873 |
+
def get_decoder(self):
|
874 |
+
return self.model
|
875 |
+
|
876 |
+
@replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
|
877 |
+
def forward(
|
878 |
+
self,
|
879 |
+
input_ids: torch.LongTensor = None,
|
880 |
+
attention_mask: Optional[torch.Tensor] = None,
|
881 |
+
position_ids: Optional[torch.LongTensor] = None,
|
882 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
883 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
884 |
+
labels: Optional[torch.LongTensor] = None,
|
885 |
+
use_cache: Optional[bool] = None,
|
886 |
+
output_attentions: Optional[bool] = None,
|
887 |
+
output_hidden_states: Optional[bool] = None,
|
888 |
+
return_dict: Optional[bool] = None,
|
889 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
890 |
+
r"""
|
891 |
+
Args:
|
892 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
893 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
894 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
895 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
896 |
+
|
897 |
+
Returns:
|
898 |
+
|
899 |
+
Example:
|
900 |
+
|
901 |
+
```python
|
902 |
+
>>> from transformers import AutoTokenizer, SkyworkForCausalLM
|
903 |
+
|
904 |
+
>>> model = SkyworkForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
|
905 |
+
>>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
|
906 |
+
|
907 |
+
>>> prompt = "Hey, are you conscious? Can you talk to me?"
|
908 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
909 |
+
|
910 |
+
>>> # Generate
|
911 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
912 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
913 |
+
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
|
914 |
+
```"""
|
915 |
+
|
916 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
917 |
+
output_hidden_states = (
|
918 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
919 |
+
)
|
920 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
921 |
+
|
922 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
923 |
+
outputs = self.model(
|
924 |
+
input_ids=input_ids,
|
925 |
+
attention_mask=attention_mask,
|
926 |
+
position_ids=position_ids,
|
927 |
+
past_key_values=past_key_values,
|
928 |
+
inputs_embeds=inputs_embeds,
|
929 |
+
use_cache=use_cache,
|
930 |
+
output_attentions=output_attentions,
|
931 |
+
output_hidden_states=output_hidden_states,
|
932 |
+
return_dict=return_dict,
|
933 |
+
)
|
934 |
+
|
935 |
+
hidden_states = outputs[0]
|
936 |
+
if self.config.pretraining_tp > 1:
|
937 |
+
lm_head_slices = self.lm_head.weight.split(self.vocab_size // self.config.pretraining_tp, dim=0)
|
938 |
+
logits = [F.linear(hidden_states, lm_head_slices[i]) for i in range(self.config.pretraining_tp)]
|
939 |
+
logits = torch.cat(logits, dim=-1)
|
940 |
+
else:
|
941 |
+
logits = self.lm_head(hidden_states)
|
942 |
+
logits = logits.float()
|
943 |
+
|
944 |
+
loss = None
|
945 |
+
if labels is not None:
|
946 |
+
# Shift so that tokens < n predict n
|
947 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
948 |
+
shift_labels = labels[..., 1:].contiguous()
|
949 |
+
# Flatten the tokens
|
950 |
+
loss_fct = CrossEntropyLoss()
|
951 |
+
shift_logits = shift_logits.view(-1, self.config.vocab_size)
|
952 |
+
shift_labels = shift_labels.view(-1)
|
953 |
+
# Enable model parallelism
|
954 |
+
shift_labels = shift_labels.to(shift_logits.device)
|
955 |
+
loss = loss_fct(shift_logits, shift_labels)
|
956 |
+
|
957 |
+
if not return_dict:
|
958 |
+
output = (logits,) + outputs[1:]
|
959 |
+
return (loss,) + output if loss is not None else output
|
960 |
+
|
961 |
+
return CausalLMOutputWithPast(
|
962 |
+
loss=loss,
|
963 |
+
logits=logits,
|
964 |
+
past_key_values=outputs.past_key_values,
|
965 |
+
hidden_states=outputs.hidden_states,
|
966 |
+
attentions=outputs.attentions,
|
967 |
+
)
|
968 |
+
|
969 |
+
def prepare_inputs_for_generation(
|
970 |
+
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs
|
971 |
+
):
|
972 |
+
if past_key_values:
|
973 |
+
input_ids = input_ids[:, -1:]
|
974 |
+
|
975 |
+
position_ids = kwargs.get("position_ids", None)
|
976 |
+
if attention_mask is not None and position_ids is None:
|
977 |
+
# create position_ids on the fly for batch generation
|
978 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
979 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
980 |
+
if past_key_values:
|
981 |
+
position_ids = position_ids[:, -1].unsqueeze(-1)
|
982 |
+
|
983 |
+
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
|
984 |
+
if inputs_embeds is not None and past_key_values is None:
|
985 |
+
model_inputs = {"inputs_embeds": inputs_embeds}
|
986 |
+
else:
|
987 |
+
model_inputs = {"input_ids": input_ids}
|
988 |
+
|
989 |
+
model_inputs.update(
|
990 |
+
{
|
991 |
+
"position_ids": position_ids,
|
992 |
+
"past_key_values": past_key_values,
|
993 |
+
"use_cache": kwargs.get("use_cache"),
|
994 |
+
"attention_mask": attention_mask,
|
995 |
+
}
|
996 |
+
)
|
997 |
+
return model_inputs
|
998 |
+
|
999 |
+
@staticmethod
|
1000 |
+
def _reorder_cache(past_key_values, beam_idx):
|
1001 |
+
reordered_past = ()
|
1002 |
+
for layer_past in past_key_values:
|
1003 |
+
reordered_past += (
|
1004 |
+
tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
|
1005 |
+
)
|
1006 |
+
return reordered_past
|
1007 |
+
|
1008 |
+
class SkyworkForSequenceClassification(SkyworkPreTrainedModel):
|
1009 |
+
def __init__(self, config):
|
1010 |
+
super().__init__(config)
|
1011 |
+
self.num_labels = config.num_labels
|
1012 |
+
self.model = SkyworkModel(config)
|
1013 |
+
self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
|
1014 |
+
|
1015 |
+
# Initialize weights and apply final processing
|
1016 |
+
self.post_init()
|
1017 |
+
|
1018 |
+
def get_input_embeddings(self):
|
1019 |
+
return self.model.embed_tokens
|
1020 |
+
|
1021 |
+
def set_input_embeddings(self, value):
|
1022 |
+
self.model.embed_tokens = value
|
1023 |
+
|
1024 |
+
def forward(
|
1025 |
+
self,
|
1026 |
+
input_ids: torch.LongTensor = None,
|
1027 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1028 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1029 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
1030 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1031 |
+
labels: Optional[torch.LongTensor] = None,
|
1032 |
+
use_cache: Optional[bool] = None,
|
1033 |
+
output_attentions: Optional[bool] = None,
|
1034 |
+
output_hidden_states: Optional[bool] = None,
|
1035 |
+
return_dict: Optional[bool] = None,
|
1036 |
+
) -> Union[Tuple, SequenceClassifierOutputWithPast]:
|
1037 |
+
r"""
|
1038 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
1039 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
1040 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
1041 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
1042 |
+
"""
|
1043 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1044 |
+
|
1045 |
+
transformer_outputs = self.model(
|
1046 |
+
input_ids,
|
1047 |
+
attention_mask=attention_mask,
|
1048 |
+
position_ids=position_ids,
|
1049 |
+
past_key_values=past_key_values,
|
1050 |
+
inputs_embeds=inputs_embeds,
|
1051 |
+
use_cache=use_cache,
|
1052 |
+
output_attentions=output_attentions,
|
1053 |
+
output_hidden_states=output_hidden_states,
|
1054 |
+
return_dict=return_dict,
|
1055 |
+
)
|
1056 |
+
hidden_states = transformer_outputs[0]
|
1057 |
+
logits = self.score(hidden_states)
|
1058 |
+
|
1059 |
+
if input_ids is not None:
|
1060 |
+
batch_size = input_ids.shape[0]
|
1061 |
+
else:
|
1062 |
+
batch_size = inputs_embeds.shape[0]
|
1063 |
+
|
1064 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
1065 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
1066 |
+
if self.config.pad_token_id is None:
|
1067 |
+
sequence_lengths = -1
|
1068 |
+
else:
|
1069 |
+
if input_ids is not None:
|
1070 |
+
sequence_lengths = (torch.eq(input_ids, self.config.pad_token_id).long().argmax(-1) - 1).to(
|
1071 |
+
logits.device
|
1072 |
+
)
|
1073 |
+
else:
|
1074 |
+
sequence_lengths = -1
|
1075 |
+
|
1076 |
+
pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
|
1077 |
+
|
1078 |
+
loss = None
|
1079 |
+
if labels is not None:
|
1080 |
+
labels = labels.to(logits.device)
|
1081 |
+
if self.config.problem_type is None:
|
1082 |
+
if self.num_labels == 1:
|
1083 |
+
self.config.problem_type = "regression"
|
1084 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
1085 |
+
self.config.problem_type = "single_label_classification"
|
1086 |
+
else:
|
1087 |
+
self.config.problem_type = "multi_label_classification"
|
1088 |
+
|
1089 |
+
if self.config.problem_type == "regression":
|
1090 |
+
loss_fct = MSELoss()
|
1091 |
+
if self.num_labels == 1:
|
1092 |
+
loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
|
1093 |
+
else:
|
1094 |
+
loss = loss_fct(pooled_logits, labels)
|
1095 |
+
elif self.config.problem_type == "single_label_classification":
|
1096 |
+
loss_fct = CrossEntropyLoss()
|
1097 |
+
loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
|
1098 |
+
elif self.config.problem_type == "multi_label_classification":
|
1099 |
+
loss_fct = BCEWithLogitsLoss()
|
1100 |
+
loss = loss_fct(pooled_logits, labels)
|
1101 |
+
if not return_dict:
|
1102 |
+
output = (pooled_logits,) + transformer_outputs[1:]
|
1103 |
+
return ((loss,) + output) if loss is not None else output
|
1104 |
+
|
1105 |
+
return SequenceClassifierOutputWithPast(
|
1106 |
+
loss=loss,
|
1107 |
+
logits=pooled_logits,
|
1108 |
+
past_key_values=transformer_outputs.past_key_values,
|
1109 |
+
hidden_states=transformer_outputs.hidden_states,
|
1110 |
+
attentions=transformer_outputs.attentions,
|
1111 |
+
)
|
pytorch_model-00001-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:68940720301857dba24c7f68a2560e165076a577622da9c3ecef68f7963f5cff
|
3 |
+
size 509629447
|
pytorch_model-00002-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e205c6182bb23ed7e38bc67a371a7fd73550720f04812a6d2d40f935dd0e23a1
|
3 |
+
size 509629447
|
pytorch_model-00003-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d28f1778e9d1c25129ce2c1efa57bb9a4f0481f20ea599e838ead0b0503fe51b
|
3 |
+
size 509629447
|
pytorch_model-00004-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:492050395a7cb564ef08be3ae8d1c41b045a0946e5b3963f9eccf2d7a83c756e
|
3 |
+
size 509629447
|
pytorch_model-00005-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9754fc15b494d09fb7e69061945e99f3581c04b92155615eaac613f795f90af2
|
3 |
+
size 509629447
|
pytorch_model-00006-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:289188fd00cb91892ff5892c318a1c95ca7f116b26f61f1333da002591b8aa4e
|
3 |
+
size 509629447
|
pytorch_model-00007-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6df94cae029ebf292724c215cc98278a6f5094dd389ee737010aae267b4615f0
|
3 |
+
size 509629447
|
pytorch_model-00008-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2f1fbf1ecdea5d2e884a9f5b4f490cd25190ca6e136e21b6a5742502a7314ce1
|
3 |
+
size 509629447
|
pytorch_model-00009-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:662acb1bbf08baa2339cbb5a1b6751d9f666a5b4bdc5b3e2bae0dd3e9a978816
|
3 |
+
size 509629447
|
pytorch_model-00010-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:38147ea6887d0daeb9ffb680e50fdda895aaa00fbd7abb3831da45443f335bce
|
3 |
+
size 509629447
|
pytorch_model-00011-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:302cf0a909d5da00e667f58c982d59d3fc69afb8e51082e568f015da170cdf17
|
3 |
+
size 509629511
|
pytorch_model-00012-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ceff426fbfaf9a6911d36fdaf5d7bc098506fe0bae5cd006f1a7a76f738a0f09
|
3 |
+
size 509629511
|
pytorch_model-00013-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:63fa9883b515fafbd78d935e9570710b1bdd244c81a4743337b66dd402a2e288
|
3 |
+
size 509629511
|
pytorch_model-00014-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:29a39a5d252dc31a4b60a20cc4d3651931062e0bdd97391005c761877e00f84e
|
3 |
+
size 509629511
|
pytorch_model-00015-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fbbdd55cb635c442b06906a76a36500ebfa8ec5a6fd8d33a99123f2761aa0598
|
3 |
+
size 509629511
|
pytorch_model-00016-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4afa21eaf0a5ca8341d7dcec5b76dba960f797de9ac2fca96b6076a0cb137826
|
3 |
+
size 509629511
|
pytorch_model-00017-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9862fb9399bf64c00f5d7956d7c47e390a8fe58a2a9fe20b1dec66ffaa77e486
|
3 |
+
size 509629511
|
pytorch_model-00018-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b1e97e33b7d6de423a52c2cbfcfb6ab1ec64a47b73c5680fe1acb6664b613af7
|
3 |
+
size 509629511
|
pytorch_model-00019-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0bc3079f15219c1f453a21aaa410a14cdd8aa3416e0c37ec8c5ddb1c708eccbb
|
3 |
+
size 509629511
|
pytorch_model-00020-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b3b0b92ea03f7e8e457b3362b6b72aa814294b562a173613c3763103973be8f2
|
3 |
+
size 509629511
|
pytorch_model-00021-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:410de3915493f0c984db3636d195b79e29c36a8a04070a6f84499e7ba30228b9
|
3 |
+
size 509629511
|
pytorch_model-00022-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:faf930f0ee2069fd60baff35cb8015274abe05f83878407fc405287ebbf1ff0d
|
3 |
+
size 509629511
|
pytorch_model-00023-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:23feb32029849bbacc1ad52089ca50cdc0ccbd1847db5bcd740c6070c89ed8fe
|
3 |
+
size 509629511
|
pytorch_model-00024-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:57a66e21dbdbd69f0bdc0531c334d2e1d718d8a5f2f1c81fe4c7d8e328978f7c
|
3 |
+
size 509629511
|
pytorch_model-00025-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e225e949dc5185b44f1c210cf027306991f1299080f06289013644dd426c905c
|
3 |
+
size 509629511
|
pytorch_model-00026-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1f21ed93e2c3b7d5ce4f35b018dd9662e2ff9aca328939715c8e538f9dae6a51
|
3 |
+
size 509629511
|
pytorch_model-00027-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:959c22c54dc5e35033e061c95a2cf6579d72c64263ef969337df463ed240023e
|
3 |
+
size 509629511
|
pytorch_model-00028-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eb537adaac04127fb050014845363a3b929b9d0d1b9a15c9f853ebe8479c0b00
|
3 |
+
size 509629511
|
pytorch_model-00029-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:796cd3b42ce08e128f8f84bf5e9f9ea174f63a13711349cbfe8b9d4eb08d4814
|
3 |
+
size 509629511
|
pytorch_model-00030-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1a2713d082266c6f286d093399910ef7542bf25b5d41680ecf2e92918b2ffde3
|
3 |
+
size 509629511
|
pytorch_model-00031-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:85fae9975fa5af1d748200bae1a47e09a8ebd942c8b37a312044cbd0d8654345
|
3 |
+
size 509629511
|
pytorch_model-00032-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6eb5b97e5cf86189304dfa7d163a266827ed4a50b8ea9bc14c7ff8cc117800e3
|
3 |
+
size 509629511
|
pytorch_model-00033-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0a91cc0c084b84e4a7d18946f153ce4ae79723df5e7537b35612f6a2d0d78350
|
3 |
+
size 509629511
|
pytorch_model-00034-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e06e3c2c0c61e96d282c46e858c681080c03fa8f501d7a5e5961c2e797560fb0
|
3 |
+
size 509629511
|
pytorch_model-00035-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:01617a64df649449201a8284bab3044fa8e61ce8ce4bb63d975bf5f580f79bff
|
3 |
+
size 509629511
|
pytorch_model-00036-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:45b2ca00bdb605af8bd785ba122268cbd491d8ec7bdaa597774edb489fcd0298
|
3 |
+
size 509629511
|
pytorch_model-00037-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:139dbbcbb259f4dda361d015b87ea7f12ec19b6b8e0897fedd0e2a3614c3b37e
|
3 |
+
size 509629511
|
pytorch_model-00038-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:10ac7a95b8bde058ea0d5c7a8a55af1d4aed65d9ae12e286fec88b3a9256f636
|
3 |
+
size 509629511
|
pytorch_model-00039-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9dece182f9bfb4f56d689437396ce2a65318d08aff9de5ede050eb4240e70a09
|
3 |
+
size 509629511
|
pytorch_model-00040-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6cbd32d4ec97b7c2438be4fb3863251c09cf40a8ab6d5918935a5c7f4c620f20
|
3 |
+
size 509629511
|
pytorch_model-00041-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8681905b13bbfe3384af79f9da47d7a05c79f8cb5e0c36f5e0626b20f9655e08
|
3 |
+
size 509629511
|
pytorch_model-00042-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1e3c7df5786804b1f93dc1488847e0aecd23aa2b4c133ccd2476a26ad8a25dde
|
3 |
+
size 509629511
|
pytorch_model-00043-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c9ecdfb82b40f8b0185eb3f63271cd351d08a028d250e327f5c287ec726cf3c
|
3 |
+
size 509629511
|
pytorch_model-00044-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:38c0296e8c1aff535c03b641d527142c54af30339261a11555ff949caf84f338
|
3 |
+
size 509629511
|
pytorch_model-00045-of-00053.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a628a44063a617d465cc8bc44deea8bbc0808042f8232b0f5ffb0b3a73feddea
|
3 |
+
size 509629511
|