Upload folder using huggingface_hub
Browse files- config.json +29 -0
- configuration_RW.py +75 -0
- generation_config.json +6 -0
- latest +1 -0
- modelling_RW.py +1106 -0
- pytorch_model-00001-of-00018.bin +3 -0
- pytorch_model-00002-of-00018.bin +3 -0
- pytorch_model-00003-of-00018.bin +3 -0
- pytorch_model-00004-of-00018.bin +3 -0
- pytorch_model-00005-of-00018.bin +3 -0
- pytorch_model-00006-of-00018.bin +3 -0
- pytorch_model-00007-of-00018.bin +3 -0
- pytorch_model-00008-of-00018.bin +3 -0
- pytorch_model-00009-of-00018.bin +3 -0
- pytorch_model-00010-of-00018.bin +3 -0
- pytorch_model-00011-of-00018.bin +3 -0
- pytorch_model-00012-of-00018.bin +3 -0
- pytorch_model-00013-of-00018.bin +3 -0
- pytorch_model-00014-of-00018.bin +3 -0
- pytorch_model-00015-of-00018.bin +3 -0
- pytorch_model-00016-of-00018.bin +3 -0
- pytorch_model-00017-of-00018.bin +3 -0
- pytorch_model-00018-of-00018.bin +3 -0
- pytorch_model.bin.index.json +491 -0
- special_tokens_map.json +17 -0
- tokenizer.json +0 -0
- tokenizer_config.json +8 -0
- trainer_state.json +658 -0
- training_args.bin +3 -0
- zero_to_fp32.py +584 -0
config.json
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/workspace/WizardLM-Uncensored-falcon-40b",
|
3 |
+
"alibi": false,
|
4 |
+
"apply_residual_connection_post_layernorm": false,
|
5 |
+
"architectures": [
|
6 |
+
"RWForCausalLM"
|
7 |
+
],
|
8 |
+
"attention_dropout": 0.0,
|
9 |
+
"auto_map": {
|
10 |
+
"AutoConfig": "configuration_RW.RWConfig",
|
11 |
+
"AutoModelForCausalLM": "modelling_RW.RWForCausalLM"
|
12 |
+
},
|
13 |
+
"bias": false,
|
14 |
+
"bos_token_id": 1,
|
15 |
+
"eos_token_id": 2,
|
16 |
+
"hidden_dropout": 0.0,
|
17 |
+
"hidden_size": 8192,
|
18 |
+
"initializer_range": 0.02,
|
19 |
+
"layer_norm_epsilon": 1e-05,
|
20 |
+
"model_type": "RefinedWeb",
|
21 |
+
"n_head": 128,
|
22 |
+
"n_head_kv": 8,
|
23 |
+
"n_layer": 60,
|
24 |
+
"parallel_attn": true,
|
25 |
+
"torch_dtype": "float32",
|
26 |
+
"transformers_version": "4.30.0.dev0",
|
27 |
+
"use_cache": true,
|
28 |
+
"vocab_size": 65025
|
29 |
+
}
|
configuration_RW.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 the Big Science Workshop and HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
""" Bloom configuration"""
|
16 |
+
from transformers.configuration_utils import PretrainedConfig
|
17 |
+
from transformers.utils import logging
|
18 |
+
|
19 |
+
|
20 |
+
logger = logging.get_logger(__name__)
|
21 |
+
|
22 |
+
|
23 |
+
class RWConfig(PretrainedConfig):
|
24 |
+
model_type = "RefinedWeb"
|
25 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
26 |
+
attribute_map = {
|
27 |
+
"num_hidden_layers": "n_layer",
|
28 |
+
"num_attention_heads": "n_head",
|
29 |
+
}
|
30 |
+
|
31 |
+
def __init__(
|
32 |
+
self,
|
33 |
+
vocab_size=250880,
|
34 |
+
hidden_size=64,
|
35 |
+
n_layer=2,
|
36 |
+
n_head=8,
|
37 |
+
layer_norm_epsilon=1e-5,
|
38 |
+
initializer_range=0.02,
|
39 |
+
use_cache=True,
|
40 |
+
bos_token_id=1,
|
41 |
+
eos_token_id=2,
|
42 |
+
apply_residual_connection_post_layernorm=False,
|
43 |
+
hidden_dropout=0.0,
|
44 |
+
attention_dropout=0.0,
|
45 |
+
n_head_kv=None,
|
46 |
+
alibi=False,
|
47 |
+
**kwargs,
|
48 |
+
):
|
49 |
+
self.vocab_size = vocab_size
|
50 |
+
# Backward compatibility with n_embed kwarg
|
51 |
+
n_embed = kwargs.pop("n_embed", None)
|
52 |
+
self.hidden_size = hidden_size if n_embed is None else n_embed
|
53 |
+
self.n_layer = n_layer
|
54 |
+
self.n_head = n_head
|
55 |
+
self.layer_norm_epsilon = layer_norm_epsilon
|
56 |
+
self.initializer_range = initializer_range
|
57 |
+
self.use_cache = use_cache
|
58 |
+
self.apply_residual_connection_post_layernorm = apply_residual_connection_post_layernorm
|
59 |
+
self.hidden_dropout = hidden_dropout
|
60 |
+
self.attention_dropout = attention_dropout
|
61 |
+
|
62 |
+
self.bos_token_id = bos_token_id
|
63 |
+
self.eos_token_id = eos_token_id
|
64 |
+
self.n_head_kv = n_head if n_head_kv is None else n_head_kv
|
65 |
+
self.alibi = alibi
|
66 |
+
|
67 |
+
super().__init__(bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)
|
68 |
+
|
69 |
+
@property
|
70 |
+
def head_dim(self):
|
71 |
+
return self.hidden_size // self.n_head
|
72 |
+
|
73 |
+
@property
|
74 |
+
def rotary(self):
|
75 |
+
return not self.alibi
|
generation_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 1,
|
4 |
+
"eos_token_id": 2,
|
5 |
+
"transformers_version": "4.30.0.dev0"
|
6 |
+
}
|
latest
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
global_step214
|
modelling_RW.py
ADDED
@@ -0,0 +1,1106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# port of models described in RW
|
2 |
+
# We use the bloom model as a starting point for these model.
|
3 |
+
# Please refer to the bloom models for usage instructions.
|
4 |
+
|
5 |
+
import math
|
6 |
+
import warnings
|
7 |
+
from typing import Optional, Tuple, Union
|
8 |
+
|
9 |
+
import torch
|
10 |
+
import torch.utils.checkpoint
|
11 |
+
from torch import nn
|
12 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, LayerNorm, MSELoss
|
13 |
+
from torch.nn import functional as F
|
14 |
+
|
15 |
+
from transformers.modeling_outputs import (
|
16 |
+
BaseModelOutputWithPastAndCrossAttentions,
|
17 |
+
CausalLMOutputWithCrossAttentions,
|
18 |
+
QuestionAnsweringModelOutput,
|
19 |
+
SequenceClassifierOutputWithPast,
|
20 |
+
TokenClassifierOutput,
|
21 |
+
)
|
22 |
+
from transformers.modeling_utils import PreTrainedModel
|
23 |
+
from transformers.utils import logging
|
24 |
+
from .configuration_RW import RWConfig
|
25 |
+
|
26 |
+
logger = logging.get_logger(__name__)
|
27 |
+
|
28 |
+
# NOTE(Hesslow): Unfortunately we did not fuse matmul and bias during training, this means that there's one additional quantization to bfloat16 between the operations.
|
29 |
+
# In order not to degrade the quality of our HF-port, we keep these characteristics in the final model.
|
30 |
+
class Linear(nn.Linear):
|
31 |
+
def forward(self, input: torch.Tensor) -> torch.Tensor:
|
32 |
+
ret = input @ self.weight.T
|
33 |
+
if self.bias is None:
|
34 |
+
return ret
|
35 |
+
else:
|
36 |
+
return ret + self.bias
|
37 |
+
|
38 |
+
|
39 |
+
from einops import rearrange
|
40 |
+
|
41 |
+
# rotary pos emb helpers (torch.jit.script does not seem to support staticmethod...)
|
42 |
+
def rotate_half(x):
|
43 |
+
x1, x2 = x[..., : x.shape[-1] // 2], x[..., x.shape[-1] // 2 :]
|
44 |
+
return torch.cat((-x2, x1), dim=x1.ndim - 1) # dim=-1 triggers a bug in torch < 1.8.0
|
45 |
+
|
46 |
+
|
47 |
+
class RotaryEmbedding(torch.nn.Module):
|
48 |
+
"""Implementation of RotaryEmbedding from GPT-NeoX.
|
49 |
+
This implementation is design to operate on queries and keys that are compatible with
|
50 |
+
[batch_size, n_heads_per_partition, seq_len, head_dim] (e.g. MinGPTAttention format).
|
51 |
+
"""
|
52 |
+
|
53 |
+
def __init__(
|
54 |
+
self,
|
55 |
+
head_dim: int,
|
56 |
+
base=10000,
|
57 |
+
):
|
58 |
+
super().__init__()
|
59 |
+
inv_freq = 1.0 / (base ** (torch.arange(0, head_dim, 2).float() / head_dim))
|
60 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
61 |
+
self.head_dim = head_dim
|
62 |
+
self.seq_len_cached = None
|
63 |
+
self.batch_size_cached = None
|
64 |
+
self.cos_cached: torch.Tensor | None = None
|
65 |
+
self.sin_cached: torch.Tensor | None = None
|
66 |
+
|
67 |
+
def cos_sin(
|
68 |
+
self,
|
69 |
+
seq_len: int,
|
70 |
+
device="cuda",
|
71 |
+
dtype=torch.bfloat16,
|
72 |
+
) -> torch.Tensor:
|
73 |
+
if seq_len != self.seq_len_cached:
|
74 |
+
self.seq_len_cached = seq_len
|
75 |
+
t = torch.arange(seq_len, device=device).type_as(self.inv_freq)
|
76 |
+
freqs = torch.einsum("i,j->ij", t, self.inv_freq)
|
77 |
+
emb = torch.cat((freqs, freqs), dim=-1).to(device)
|
78 |
+
|
79 |
+
if dtype in [torch.float16, torch.bfloat16]:
|
80 |
+
emb = emb.float()
|
81 |
+
|
82 |
+
self.cos_cached = emb.cos()[None, :, :]
|
83 |
+
self.sin_cached = emb.sin()[None, :, :]
|
84 |
+
|
85 |
+
self.cos_cached = self.cos_cached.type(dtype)
|
86 |
+
self.sin_cached = self.sin_cached.type(dtype)
|
87 |
+
|
88 |
+
return self.cos_cached, self.sin_cached
|
89 |
+
|
90 |
+
def forward(self, q, k):
|
91 |
+
batch, seq_len, head_dim = q.shape
|
92 |
+
cos, sin = self.cos_sin(seq_len, q.device, q.dtype)
|
93 |
+
return (q * cos) + (rotate_half(q) * sin), (k * cos) + (rotate_half(k) * sin)
|
94 |
+
|
95 |
+
|
96 |
+
def _make_causal_mask(
|
97 |
+
input_ids_shape: torch.Size, device: torch.device, past_key_values_length: int
|
98 |
+
) -> torch.BoolTensor:
|
99 |
+
batch_size, target_length = input_ids_shape
|
100 |
+
mask = torch.empty((target_length, target_length + past_key_values_length), dtype=torch.bool, device=device)
|
101 |
+
# ONNX doesn't support `torch.Tensor.triu` properly, thus we use this workaround
|
102 |
+
seq_ids = torch.arange(target_length, device=device)
|
103 |
+
mask[:, past_key_values_length:] = seq_ids[:, None] < seq_ids[None, :]
|
104 |
+
|
105 |
+
if past_key_values_length > 0:
|
106 |
+
mask[:, :past_key_values_length] = False
|
107 |
+
|
108 |
+
expanded_mask = mask[None, None, :, :].expand(batch_size, 1, target_length, target_length + past_key_values_length)
|
109 |
+
return expanded_mask
|
110 |
+
|
111 |
+
|
112 |
+
def _expand_mask(mask: torch.Tensor, tgt_length: int) -> torch.BoolTensor:
|
113 |
+
batch_size, src_length = mask.shape
|
114 |
+
tgt_length = tgt_length if tgt_length is not None else src_length
|
115 |
+
|
116 |
+
expanded_mask = ~(mask[:, None, None, :].to(torch.bool))
|
117 |
+
return expanded_mask.expand(batch_size, 1, tgt_length, src_length)
|
118 |
+
|
119 |
+
|
120 |
+
def build_alibi_tensor(attention_mask: torch.Tensor, num_heads: int, dtype: torch.dtype) -> torch.Tensor:
|
121 |
+
batch_size, seq_length = attention_mask.shape
|
122 |
+
closest_power_of_2 = 2 ** math.floor(math.log2(num_heads))
|
123 |
+
base = torch.tensor(
|
124 |
+
2 ** (-(2 ** -(math.log2(closest_power_of_2) - 3))), device=attention_mask.device, dtype=torch.float32
|
125 |
+
)
|
126 |
+
powers = torch.arange(1, 1 + closest_power_of_2, device=attention_mask.device, dtype=torch.int32)
|
127 |
+
slopes = torch.pow(base, powers)
|
128 |
+
|
129 |
+
if closest_power_of_2 != num_heads:
|
130 |
+
extra_base = torch.tensor(
|
131 |
+
2 ** (-(2 ** -(math.log2(2 * closest_power_of_2) - 3))), device=attention_mask.device, dtype=torch.float32
|
132 |
+
)
|
133 |
+
num_remaining_heads = min(closest_power_of_2, num_heads - closest_power_of_2)
|
134 |
+
extra_powers = torch.arange(1, 1 + 2 * num_remaining_heads, 2, device=attention_mask.device, dtype=torch.int32)
|
135 |
+
slopes = torch.cat([slopes, torch.pow(extra_base, extra_powers)], dim=0)
|
136 |
+
|
137 |
+
# Note: alibi will added to the attention bias that will be applied to the query, key product of attention
|
138 |
+
# => therefore alibi will have to be of shape (batch_size, num_heads, query_length, key_length)
|
139 |
+
# => here we set (batch_size=1, num_heads=num_heads, query_length=1, key_length=max_length)
|
140 |
+
# => the query_length dimension will then be broadcasted correctly
|
141 |
+
# This is more or less identical to T5's relative position bias:
|
142 |
+
# https://github.com/huggingface/transformers/blob/f681437203baa7671de3174b0fa583c349d9d5e1/src/transformers/models/t5/modeling_t5.py#L527
|
143 |
+
arange_tensor = ((attention_mask.cumsum(dim=-1) - 1) * attention_mask)[:, None, :]
|
144 |
+
alibi = slopes[..., None].bfloat16() * arange_tensor
|
145 |
+
return alibi.reshape(batch_size * num_heads, 1, seq_length).to(dtype)
|
146 |
+
|
147 |
+
|
148 |
+
def dropout_add(x: torch.Tensor, residual: torch.Tensor, prob: float, training: bool) -> torch.Tensor:
|
149 |
+
out = F.dropout(x, p=prob, training=training)
|
150 |
+
out = residual + out
|
151 |
+
return out
|
152 |
+
|
153 |
+
|
154 |
+
class Attention(nn.Module):
|
155 |
+
def __init__(self, config: RWConfig):
|
156 |
+
super().__init__()
|
157 |
+
|
158 |
+
self.hidden_size = config.hidden_size
|
159 |
+
self.num_heads = config.n_head
|
160 |
+
self.head_dim = self.hidden_size // self.num_heads
|
161 |
+
self.split_size = self.hidden_size
|
162 |
+
self.hidden_dropout = config.hidden_dropout
|
163 |
+
|
164 |
+
if self.head_dim * self.num_heads != self.hidden_size:
|
165 |
+
raise ValueError(
|
166 |
+
f"`hidden_size` must be divisible by num_heads (got `hidden_size`: {self.hidden_size} and `num_heads`:"
|
167 |
+
f" {self.num_heads})."
|
168 |
+
)
|
169 |
+
|
170 |
+
self.maybe_rotary = RotaryEmbedding(config.head_dim) if config.rotary else lambda q, k: (q, k)
|
171 |
+
|
172 |
+
# Layer-wise attention scaling
|
173 |
+
self.inv_norm_factor = 1.0 / math.sqrt(self.head_dim)
|
174 |
+
self.beta = self.inv_norm_factor
|
175 |
+
|
176 |
+
self.query_key_value = Linear(
|
177 |
+
self.hidden_size,
|
178 |
+
(config.n_head_kv * 2 + config.n_head) * self.head_dim,
|
179 |
+
bias=config.bias,
|
180 |
+
)
|
181 |
+
self.dense = Linear(self.hidden_size, self.hidden_size, bias=config.bias)
|
182 |
+
self.attention_dropout = nn.Dropout(config.attention_dropout)
|
183 |
+
self.num_kv = config.n_head_kv
|
184 |
+
|
185 |
+
def _split_heads(self, fused_qkv: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
186 |
+
"""
|
187 |
+
Split the last dimension into (num_heads, head_dim), results share same memory
|
188 |
+
storage as `fused_qkv`
|
189 |
+
|
190 |
+
Args:
|
191 |
+
fused_qkv (`torch.tensor`, *required*): [batch_size, seq_length, num_heads * 3 * head_dim]
|
192 |
+
|
193 |
+
Returns:
|
194 |
+
query: [batch_size, seq_length, num_heads, head_dim]
|
195 |
+
key: [batch_size, seq_length, num_heads, head_dim]
|
196 |
+
value: [batch_size, seq_length, num_heads, head_dim]
|
197 |
+
"""
|
198 |
+
batch, seq_len, _ = fused_qkv.shape
|
199 |
+
qkv = fused_qkv.view(batch, seq_len, -1, self.num_heads // self.num_kv + 2, 64)
|
200 |
+
q = qkv[:, :, :, :-2]
|
201 |
+
k = qkv[:, :, :, [-2]]
|
202 |
+
v = qkv[:, :, :, [-1]]
|
203 |
+
k = torch.broadcast_to(k, q.shape)
|
204 |
+
v = torch.broadcast_to(v, q.shape)
|
205 |
+
|
206 |
+
q, k, v = [
|
207 |
+
rearrange(
|
208 |
+
x,
|
209 |
+
"batch seq_len group num_heads head_dim ->\
|
210 |
+
batch seq_len (group num_heads) head_dim",
|
211 |
+
head_dim=self.head_dim,
|
212 |
+
)
|
213 |
+
for x in [q, k, v]
|
214 |
+
]
|
215 |
+
return q, k, v
|
216 |
+
|
217 |
+
def _merge_heads(self, x: torch.Tensor) -> torch.Tensor:
|
218 |
+
"""
|
219 |
+
Merge heads together over the last dimenstion
|
220 |
+
|
221 |
+
Args:
|
222 |
+
x: (`torch.tensor`, *required*): [batch_size * num_heads, seq_length, head_dim]
|
223 |
+
|
224 |
+
Returns:
|
225 |
+
torch.tensor: [batch_size, seq_length, num_heads * head_dim]
|
226 |
+
"""
|
227 |
+
# What we want to achieve is:
|
228 |
+
# batch_size * num_heads, seq_length, head_dim -> batch_size, seq_length, num_heads * head_dim
|
229 |
+
batch_size_and_num_heads, seq_length, _ = x.shape
|
230 |
+
batch_size = batch_size_and_num_heads // self.num_heads
|
231 |
+
|
232 |
+
# First view to decompose the batch size
|
233 |
+
# batch_size * num_heads, seq_length, head_dim -> batch_size, num_heads, seq_length, head_dim
|
234 |
+
x = x.view(batch_size, self.num_heads, seq_length, self.head_dim)
|
235 |
+
|
236 |
+
# batch_size, num_heads, seq_length, head_dim -> batch_size, seq_length, num_heads, head_dim
|
237 |
+
x = x.permute(0, 2, 1, 3)
|
238 |
+
|
239 |
+
# batch_size, seq_length, num_heads, head_dim -> batch_size, seq_length, num_heads * head_dim
|
240 |
+
return x.reshape(batch_size, seq_length, self.num_heads * self.head_dim)
|
241 |
+
|
242 |
+
def forward(
|
243 |
+
self,
|
244 |
+
hidden_states: torch.Tensor,
|
245 |
+
alibi: torch.Tensor,
|
246 |
+
attention_mask: torch.Tensor,
|
247 |
+
layer_past: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
|
248 |
+
head_mask: Optional[torch.Tensor] = None,
|
249 |
+
use_cache: bool = False,
|
250 |
+
output_attentions: bool = False,
|
251 |
+
):
|
252 |
+
fused_qkv = self.query_key_value(hidden_states) # [batch_size, seq_length, 3 x hidden_size]
|
253 |
+
|
254 |
+
# 3 x [batch_size, seq_length, num_heads, head_dim]
|
255 |
+
(query_layer, key_layer, value_layer) = self._split_heads(fused_qkv)
|
256 |
+
|
257 |
+
batch_size, q_length, _, _ = query_layer.shape
|
258 |
+
|
259 |
+
query_layer = query_layer.transpose(1, 2).reshape(batch_size * self.num_heads, q_length, self.head_dim)
|
260 |
+
key_layer = key_layer.transpose(1, 2).reshape(
|
261 |
+
batch_size * self.num_heads,
|
262 |
+
q_length,
|
263 |
+
self.head_dim,
|
264 |
+
)
|
265 |
+
value_layer = value_layer.transpose(1, 2).reshape(batch_size * self.num_heads, q_length, self.head_dim)
|
266 |
+
|
267 |
+
query_layer, key_layer = self.maybe_rotary(query_layer, key_layer)
|
268 |
+
|
269 |
+
if layer_past is not None:
|
270 |
+
past_key, past_value = layer_past
|
271 |
+
# concatenate along seq_length dimension:
|
272 |
+
# - key: [batch_size * self.num_heads, head_dim, kv_length]
|
273 |
+
# - value: [batch_size * self.num_heads, kv_length, head_dim]
|
274 |
+
key_layer = torch.cat((past_key, key_layer), dim=1)
|
275 |
+
value_layer = torch.cat((past_value, value_layer), dim=1)
|
276 |
+
|
277 |
+
_, kv_length, _ = key_layer.shape
|
278 |
+
|
279 |
+
if use_cache is True:
|
280 |
+
present = (key_layer, value_layer)
|
281 |
+
else:
|
282 |
+
present = None
|
283 |
+
|
284 |
+
if alibi is None:
|
285 |
+
query_layer_ = query_layer.reshape(batch_size, self.num_heads, -1, self.head_dim)
|
286 |
+
key_layer_ = key_layer.reshape(batch_size, self.num_heads, -1, self.head_dim)
|
287 |
+
value_layer_ = value_layer.reshape(batch_size, self.num_heads, -1, self.head_dim)
|
288 |
+
|
289 |
+
attn_output = F.scaled_dot_product_attention(
|
290 |
+
query_layer_, key_layer_, value_layer_, None, 0.0, is_causal=True
|
291 |
+
)
|
292 |
+
|
293 |
+
x = attn_output.view(batch_size, self.num_heads, q_length, self.head_dim)
|
294 |
+
x = x.permute(0, 2, 1, 3)
|
295 |
+
attn_output = x.reshape(batch_size, q_length, self.num_heads * self.head_dim)
|
296 |
+
|
297 |
+
output_tensor = self.dense(attn_output)
|
298 |
+
|
299 |
+
outputs = (output_tensor, present)
|
300 |
+
assert not output_attentions # not supported.
|
301 |
+
return outputs
|
302 |
+
else:
|
303 |
+
attention_mask_float = (attention_mask * 1.0).masked_fill(attention_mask, -1e9).to(torch.bfloat16)
|
304 |
+
matmul_result = query_layer @ key_layer.transpose(-1, -2)
|
305 |
+
|
306 |
+
# change view to [batch_size, num_heads, q_length, kv_length]
|
307 |
+
attention_scores = matmul_result.view(batch_size, self.num_heads, q_length, kv_length)
|
308 |
+
|
309 |
+
# cast attention scores to fp32, compute scaled softmax and cast back to initial dtype - [batch_size, num_heads, q_length, kv_length]
|
310 |
+
input_dtype = attention_scores.dtype
|
311 |
+
# `float16` has a minimum value of -65504.0, whereas `bfloat16` and `float32` have a minimum value of `-3.4e+38`
|
312 |
+
if input_dtype == torch.float16 or input_dtype == torch.bfloat16:
|
313 |
+
attention_scores = attention_scores.to(torch.float32)
|
314 |
+
# attn_weights = torch.masked_fill(attention_scores, attention_mask, torch.finfo(attention_scores.dtype).min)
|
315 |
+
attention_probs = F.softmax(
|
316 |
+
(attention_scores + alibi.view(batch_size, self.num_heads, 1, -1)) * self.inv_norm_factor
|
317 |
+
+ attention_mask_float,
|
318 |
+
dim=-1,
|
319 |
+
dtype=hidden_states.dtype,
|
320 |
+
)
|
321 |
+
# [batch_size, num_heads, q_length, kv_length]
|
322 |
+
attention_probs = self.attention_dropout(attention_probs)
|
323 |
+
|
324 |
+
if head_mask is not None:
|
325 |
+
attention_probs = attention_probs * head_mask
|
326 |
+
|
327 |
+
# change view [batch_size x num_heads, q_length, kv_length]
|
328 |
+
attention_probs_reshaped = attention_probs.view(batch_size * self.num_heads, q_length, kv_length)
|
329 |
+
|
330 |
+
# matmul: [batch_size * num_heads, q_length, head_dim]
|
331 |
+
context_layer = attention_probs_reshaped @ value_layer
|
332 |
+
|
333 |
+
# change view [batch_size, num_heads, q_length, head_dim]
|
334 |
+
context_layer = self._merge_heads(context_layer)
|
335 |
+
|
336 |
+
output_tensor = self.dense(context_layer)
|
337 |
+
|
338 |
+
outputs = (output_tensor, present)
|
339 |
+
if output_attentions:
|
340 |
+
outputs += (attention_probs,)
|
341 |
+
|
342 |
+
return outputs
|
343 |
+
|
344 |
+
|
345 |
+
class MLP(nn.Module):
|
346 |
+
def __init__(self, config: RWConfig):
|
347 |
+
super().__init__()
|
348 |
+
hidden_size = config.hidden_size
|
349 |
+
|
350 |
+
self.dense_h_to_4h = Linear(hidden_size, 4 * hidden_size, bias=config.bias)
|
351 |
+
self.act = nn.GELU()
|
352 |
+
self.dense_4h_to_h = Linear(4 * hidden_size, hidden_size, bias=config.bias)
|
353 |
+
self.hidden_dropout = config.hidden_dropout
|
354 |
+
|
355 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
356 |
+
x = self.act(self.dense_h_to_4h(x))
|
357 |
+
x = self.dense_4h_to_h(x)
|
358 |
+
return x
|
359 |
+
|
360 |
+
|
361 |
+
class DecoderLayer(nn.Module):
|
362 |
+
def __init__(self, config: RWConfig):
|
363 |
+
super().__init__()
|
364 |
+
hidden_size = config.hidden_size
|
365 |
+
|
366 |
+
self.ln_attn = LayerNorm(hidden_size, eps=config.layer_norm_epsilon)
|
367 |
+
self.ln_mlp = LayerNorm(hidden_size, eps=config.layer_norm_epsilon)
|
368 |
+
|
369 |
+
self.num_heads = config.n_head
|
370 |
+
self.self_attention = Attention(config)
|
371 |
+
|
372 |
+
self.mlp = MLP(config)
|
373 |
+
|
374 |
+
self.apply_residual_connection_post_layernorm = config.apply_residual_connection_post_layernorm
|
375 |
+
self.hidden_dropout = config.hidden_dropout
|
376 |
+
|
377 |
+
self.config = config
|
378 |
+
|
379 |
+
def forward(
|
380 |
+
self,
|
381 |
+
hidden_states: torch.Tensor,
|
382 |
+
alibi: torch.Tensor,
|
383 |
+
attention_mask: torch.Tensor,
|
384 |
+
layer_past: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
|
385 |
+
head_mask: Optional[torch.Tensor] = None,
|
386 |
+
use_cache: bool = False,
|
387 |
+
output_attentions: bool = False,
|
388 |
+
):
|
389 |
+
|
390 |
+
ln_attn = self.ln_attn(hidden_states)
|
391 |
+
ln_mlp = self.ln_mlp(hidden_states)
|
392 |
+
|
393 |
+
residual = hidden_states
|
394 |
+
|
395 |
+
# Self attention.
|
396 |
+
attn_outputs = self.self_attention(
|
397 |
+
ln_attn,
|
398 |
+
layer_past=layer_past,
|
399 |
+
attention_mask=attention_mask,
|
400 |
+
alibi=alibi,
|
401 |
+
head_mask=head_mask,
|
402 |
+
use_cache=use_cache,
|
403 |
+
output_attentions=output_attentions,
|
404 |
+
)
|
405 |
+
|
406 |
+
attention_output = attn_outputs[0]
|
407 |
+
|
408 |
+
outputs = attn_outputs[1:]
|
409 |
+
|
410 |
+
# MLP.
|
411 |
+
mlp_output = self.mlp(ln_mlp)
|
412 |
+
|
413 |
+
output = dropout_add(
|
414 |
+
mlp_output + attention_output, residual, self.config.hidden_dropout, training=self.training
|
415 |
+
)
|
416 |
+
|
417 |
+
if use_cache:
|
418 |
+
outputs = (output,) + outputs
|
419 |
+
else:
|
420 |
+
outputs = (output,) + outputs[1:]
|
421 |
+
|
422 |
+
return outputs # hidden_states, present, attentions
|
423 |
+
|
424 |
+
|
425 |
+
class RWPreTrainedModel(PreTrainedModel):
|
426 |
+
_keys_to_ignore_on_load_missing = [r"h.*.self_attention.scale_mask_softmax.causal_mask", r"lm_head.weight"]
|
427 |
+
"""
|
428 |
+
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
|
429 |
+
models.
|
430 |
+
"""
|
431 |
+
|
432 |
+
config_class = RWConfig
|
433 |
+
base_model_prefix = "transformer"
|
434 |
+
supports_gradient_checkpointing = True
|
435 |
+
_no_split_modules = ["DecoderLayer"]
|
436 |
+
|
437 |
+
def __init__(self, *inputs, **kwargs):
|
438 |
+
super().__init__(*inputs, **kwargs)
|
439 |
+
|
440 |
+
def _init_weights(self, module: nn.Module):
|
441 |
+
"""Initialize the weights."""
|
442 |
+
if isinstance(module, nn.Linear) or isinstance(module, Linear):
|
443 |
+
# Slightly different from the TF version which uses truncated_normal for initialization
|
444 |
+
# cf https://github.com/pytorch/pytorch/pull/5617
|
445 |
+
module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
|
446 |
+
if module.bias is not None:
|
447 |
+
module.bias.data.zero_()
|
448 |
+
elif isinstance(module, nn.Embedding):
|
449 |
+
module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
|
450 |
+
if module.padding_idx is not None:
|
451 |
+
module.weight.data[module.padding_idx].zero_()
|
452 |
+
elif isinstance(module, LayerNorm):
|
453 |
+
module.bias.data.zero_()
|
454 |
+
module.weight.data.fill_(1.0)
|
455 |
+
|
456 |
+
def _set_gradient_checkpointing(self, module: nn.Module, value: bool = False):
|
457 |
+
if isinstance(module, RWModel):
|
458 |
+
module.gradient_checkpointing = value
|
459 |
+
|
460 |
+
@staticmethod
|
461 |
+
def _convert_to_standard_cache(
|
462 |
+
past_key_value: Tuple[Tuple[torch.Tensor, torch.Tensor]], batch_size: int
|
463 |
+
) -> Tuple[Tuple[torch.Tensor, torch.Tensor]]:
|
464 |
+
"""
|
465 |
+
Standardizes the format of the cache so as to match most implementations, i.e. to tuple(tuple([batch_size,
|
466 |
+
num_heads, ...]))
|
467 |
+
"""
|
468 |
+
batch_size_times_num_heads, head_dim, seq_length = past_key_value[0][0].shape
|
469 |
+
num_heads = batch_size_times_num_heads // batch_size
|
470 |
+
# key: [batch_size * num_heads, head_dim, seq_length] -> [batch_size, num_heads, head_dim, seq_length]
|
471 |
+
# value: [batch_size * num_heads, seq_length, head_dim] -> [batch_size, num_heads, seq_length, head_dim]
|
472 |
+
return tuple(
|
473 |
+
(
|
474 |
+
layer_past[0].view(batch_size, num_heads, head_dim, seq_length),
|
475 |
+
layer_past[1].view(batch_size, num_heads, seq_length, head_dim),
|
476 |
+
)
|
477 |
+
for layer_past in past_key_value
|
478 |
+
)
|
479 |
+
|
480 |
+
@staticmethod
|
481 |
+
def _convert_to_rw_cache(
|
482 |
+
past_key_value: Tuple[Tuple[torch.Tensor, torch.Tensor]]
|
483 |
+
) -> Tuple[Tuple[torch.Tensor, torch.Tensor]]:
|
484 |
+
batch_size, num_heads, head_dim, seq_length = past_key_value[0][0].shape
|
485 |
+
batch_size_times_num_heads = batch_size * num_heads
|
486 |
+
# key: [batch_size, num_heads, head_dim, seq_length] -> [batch_size * num_heads, head_dim, seq_length]
|
487 |
+
# value: [batch_size, num_heads, seq_length, head_dim] -> [batch_size * num_heads, seq_length, head_dim]
|
488 |
+
return tuple(
|
489 |
+
(
|
490 |
+
layer_past[0].view(batch_size_times_num_heads, head_dim, seq_length),
|
491 |
+
layer_past[1].view(batch_size_times_num_heads, seq_length, head_dim),
|
492 |
+
)
|
493 |
+
for layer_past in past_key_value
|
494 |
+
)
|
495 |
+
|
496 |
+
|
497 |
+
class RWModel(RWPreTrainedModel):
|
498 |
+
def __init__(self, config: RWConfig):
|
499 |
+
super().__init__(config)
|
500 |
+
|
501 |
+
self.embed_dim = config.hidden_size
|
502 |
+
self.num_heads = config.n_head
|
503 |
+
self.alibi = config.alibi
|
504 |
+
|
505 |
+
# Embedding + LN Embedding
|
506 |
+
self.word_embeddings = nn.Embedding(config.vocab_size, self.embed_dim)
|
507 |
+
|
508 |
+
# Transformer blocks
|
509 |
+
self.h = nn.ModuleList([DecoderLayer(config) for _ in range(config.num_hidden_layers)])
|
510 |
+
|
511 |
+
# Final Layer Norm
|
512 |
+
self.ln_f = LayerNorm(self.embed_dim, eps=config.layer_norm_epsilon)
|
513 |
+
|
514 |
+
self.gradient_checkpointing = False
|
515 |
+
|
516 |
+
# Initialize weights and apply final processing
|
517 |
+
self.post_init()
|
518 |
+
|
519 |
+
def get_input_embeddings(self):
|
520 |
+
return self.word_embeddings
|
521 |
+
|
522 |
+
def _prepare_attn_mask(
|
523 |
+
self, attention_mask: torch.Tensor, input_shape: Tuple[int, int], past_key_values_length: int
|
524 |
+
) -> torch.BoolTensor:
|
525 |
+
# create causal mask
|
526 |
+
# [batch_size, seq_length] -> [batch_size, 1, tgt_length, src_length]
|
527 |
+
combined_attention_mask = None
|
528 |
+
device = attention_mask.device
|
529 |
+
_, src_length = input_shape
|
530 |
+
|
531 |
+
if src_length > 1:
|
532 |
+
combined_attention_mask = _make_causal_mask(
|
533 |
+
input_shape, device=device, past_key_values_length=past_key_values_length
|
534 |
+
)
|
535 |
+
|
536 |
+
# [batch_size, seq_length] -> [batch_size, 1, tgt_length, src_length]
|
537 |
+
expanded_attn_mask = _expand_mask(attention_mask, tgt_length=src_length)
|
538 |
+
combined_attention_mask = (
|
539 |
+
expanded_attn_mask if combined_attention_mask is None else expanded_attn_mask | combined_attention_mask
|
540 |
+
)
|
541 |
+
|
542 |
+
return combined_attention_mask
|
543 |
+
|
544 |
+
def set_input_embeddings(self, new_embeddings: torch.Tensor):
|
545 |
+
self.word_embeddings = new_embeddings
|
546 |
+
|
547 |
+
def forward(
|
548 |
+
self,
|
549 |
+
input_ids: Optional[torch.LongTensor] = None,
|
550 |
+
past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
|
551 |
+
attention_mask: Optional[torch.Tensor] = None,
|
552 |
+
head_mask: Optional[torch.LongTensor] = None,
|
553 |
+
inputs_embeds: Optional[torch.LongTensor] = None,
|
554 |
+
use_cache: Optional[bool] = None,
|
555 |
+
output_attentions: Optional[bool] = None,
|
556 |
+
output_hidden_states: Optional[bool] = None,
|
557 |
+
return_dict: Optional[bool] = None,
|
558 |
+
**deprecated_arguments,
|
559 |
+
) -> Union[Tuple[torch.Tensor, ...], BaseModelOutputWithPastAndCrossAttentions]:
|
560 |
+
if deprecated_arguments.pop("position_ids", False) is not False:
|
561 |
+
# `position_ids` could have been `torch.Tensor` or `None` so defaulting pop to `False` allows to detect if users were passing explicitly `None`
|
562 |
+
warnings.warn(
|
563 |
+
"`position_ids` have no functionality in BLOOM and will be removed in v5.0.0. You can safely ignore"
|
564 |
+
" passing `position_ids`.",
|
565 |
+
FutureWarning,
|
566 |
+
)
|
567 |
+
if len(deprecated_arguments) > 0:
|
568 |
+
raise ValueError(f"Got unexpected arguments: {deprecated_arguments}")
|
569 |
+
|
570 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
571 |
+
output_hidden_states = (
|
572 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
573 |
+
)
|
574 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
575 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
576 |
+
|
577 |
+
if input_ids is not None and inputs_embeds is not None:
|
578 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
579 |
+
elif input_ids is not None:
|
580 |
+
batch_size, seq_length = input_ids.shape
|
581 |
+
elif inputs_embeds is not None:
|
582 |
+
batch_size, seq_length, _ = inputs_embeds.shape
|
583 |
+
else:
|
584 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
585 |
+
|
586 |
+
if past_key_values is None:
|
587 |
+
past_key_values = tuple([None] * len(self.h))
|
588 |
+
|
589 |
+
# Prepare head mask if needed
|
590 |
+
# 1.0 in head_mask indicate we keep the head
|
591 |
+
# attention_probs has shape batch_size x num_heads x N x N
|
592 |
+
# head_mask has shape n_layer x batch x num_heads x N x N
|
593 |
+
head_mask = self.get_head_mask(head_mask, self.config.n_layer)
|
594 |
+
|
595 |
+
if inputs_embeds is None:
|
596 |
+
inputs_embeds = self.word_embeddings(input_ids)
|
597 |
+
|
598 |
+
hidden_states = inputs_embeds
|
599 |
+
|
600 |
+
presents = () if use_cache else None
|
601 |
+
all_self_attentions = () if output_attentions else None
|
602 |
+
all_hidden_states = () if output_hidden_states else None
|
603 |
+
|
604 |
+
# Compute alibi tensor: check build_alibi_tensor documentation
|
605 |
+
seq_length_with_past = seq_length
|
606 |
+
past_key_values_length = 0
|
607 |
+
if past_key_values[0] is not None:
|
608 |
+
past_key_values_length = past_key_values[0][0].shape[2]
|
609 |
+
seq_length_with_past = seq_length_with_past + past_key_values_length
|
610 |
+
if attention_mask is None:
|
611 |
+
attention_mask = torch.ones((batch_size, seq_length_with_past), device=hidden_states.device)
|
612 |
+
else:
|
613 |
+
attention_mask = attention_mask.to(hidden_states.device)
|
614 |
+
|
615 |
+
if self.alibi:
|
616 |
+
alibi = build_alibi_tensor(attention_mask, self.num_heads, dtype=hidden_states.dtype)
|
617 |
+
else:
|
618 |
+
alibi = None
|
619 |
+
|
620 |
+
causal_mask = self._prepare_attn_mask(
|
621 |
+
attention_mask,
|
622 |
+
input_shape=(batch_size, seq_length),
|
623 |
+
past_key_values_length=past_key_values_length,
|
624 |
+
)
|
625 |
+
|
626 |
+
for i, (block, layer_past) in enumerate(zip(self.h, past_key_values)):
|
627 |
+
|
628 |
+
if output_hidden_states:
|
629 |
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
630 |
+
|
631 |
+
if self.gradient_checkpointing and self.training:
|
632 |
+
|
633 |
+
if use_cache:
|
634 |
+
logger.warning(
|
635 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
636 |
+
)
|
637 |
+
use_cache = False
|
638 |
+
|
639 |
+
def create_custom_forward(module):
|
640 |
+
def custom_forward(*inputs):
|
641 |
+
# None for past_key_value
|
642 |
+
return module(*inputs, use_cache=use_cache, output_attentions=output_attentions)
|
643 |
+
|
644 |
+
return custom_forward
|
645 |
+
|
646 |
+
outputs = torch.utils.checkpoint.checkpoint(
|
647 |
+
create_custom_forward(block),
|
648 |
+
hidden_states,
|
649 |
+
alibi,
|
650 |
+
causal_mask,
|
651 |
+
head_mask[i],
|
652 |
+
)
|
653 |
+
else:
|
654 |
+
outputs = block(
|
655 |
+
hidden_states,
|
656 |
+
layer_past=layer_past,
|
657 |
+
attention_mask=causal_mask,
|
658 |
+
head_mask=head_mask[i],
|
659 |
+
use_cache=use_cache,
|
660 |
+
output_attentions=output_attentions,
|
661 |
+
alibi=alibi,
|
662 |
+
)
|
663 |
+
|
664 |
+
hidden_states = outputs[0]
|
665 |
+
if use_cache is True:
|
666 |
+
presents = presents + (outputs[1],)
|
667 |
+
|
668 |
+
if output_attentions:
|
669 |
+
all_self_attentions = all_self_attentions + (outputs[2 if use_cache else 1],)
|
670 |
+
|
671 |
+
# Add last hidden state
|
672 |
+
hidden_states = self.ln_f(hidden_states)
|
673 |
+
|
674 |
+
if output_hidden_states:
|
675 |
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
676 |
+
|
677 |
+
if not return_dict:
|
678 |
+
return tuple(v for v in [hidden_states, presents, all_hidden_states, all_self_attentions] if v is not None)
|
679 |
+
|
680 |
+
return BaseModelOutputWithPastAndCrossAttentions(
|
681 |
+
last_hidden_state=hidden_states,
|
682 |
+
past_key_values=presents,
|
683 |
+
hidden_states=all_hidden_states,
|
684 |
+
attentions=all_self_attentions,
|
685 |
+
)
|
686 |
+
|
687 |
+
|
688 |
+
class RWForCausalLM(RWPreTrainedModel):
|
689 |
+
_keys_to_ignore_on_load_missing = [r"h.*.self_attention.scale_mask_softmax.causal_mask", r"lm_head.weight"]
|
690 |
+
|
691 |
+
def __init__(self, config: RWConfig):
|
692 |
+
super().__init__(config)
|
693 |
+
self.transformer = RWModel(config)
|
694 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
695 |
+
|
696 |
+
# Initialize weights and apply final processing
|
697 |
+
self.post_init()
|
698 |
+
|
699 |
+
def get_output_embeddings(self):
|
700 |
+
return self.lm_head
|
701 |
+
|
702 |
+
def set_output_embeddings(self, new_embeddings: torch.Tensor):
|
703 |
+
self.lm_head = new_embeddings
|
704 |
+
|
705 |
+
def prepare_inputs_for_generation(
|
706 |
+
self,
|
707 |
+
input_ids: torch.LongTensor,
|
708 |
+
past: Optional[torch.Tensor] = None,
|
709 |
+
attention_mask: Optional[torch.Tensor] = None,
|
710 |
+
**kwargs,
|
711 |
+
) -> dict:
|
712 |
+
# only last token for input_ids if past is not None
|
713 |
+
if past:
|
714 |
+
input_ids = input_ids[:, -1].unsqueeze(-1)
|
715 |
+
|
716 |
+
# the cache may be in the stardard format (e.g. in contrastive search), convert to our's format if needed
|
717 |
+
if past[0][0].shape[0] == input_ids.shape[0]:
|
718 |
+
past = self._convert_to_rw_cache(past)
|
719 |
+
|
720 |
+
return {
|
721 |
+
"input_ids": input_ids,
|
722 |
+
"past_key_values": past,
|
723 |
+
"use_cache": kwargs.get("use_cache"),
|
724 |
+
"attention_mask": attention_mask,
|
725 |
+
}
|
726 |
+
|
727 |
+
def forward(
|
728 |
+
self,
|
729 |
+
input_ids: Optional[torch.LongTensor] = None,
|
730 |
+
past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
|
731 |
+
attention_mask: Optional[torch.Tensor] = None,
|
732 |
+
head_mask: Optional[torch.Tensor] = None,
|
733 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
734 |
+
labels: Optional[torch.Tensor] = None,
|
735 |
+
use_cache: Optional[bool] = None,
|
736 |
+
output_attentions: Optional[bool] = None,
|
737 |
+
output_hidden_states: Optional[bool] = None,
|
738 |
+
return_dict: Optional[bool] = None,
|
739 |
+
**deprecated_arguments,
|
740 |
+
) -> Union[Tuple[torch.Tensor], CausalLMOutputWithCrossAttentions]:
|
741 |
+
r"""
|
742 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
743 |
+
Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
|
744 |
+
`labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100`
|
745 |
+
are ignored (masked), the loss is only computed for labels in `[0, ..., config.vocab_size]`
|
746 |
+
"""
|
747 |
+
if deprecated_arguments.pop("position_ids", False) is not False:
|
748 |
+
# `position_ids` could have been `torch.Tensor` or `None` so defaulting pop to `False` allows to detect if users were passing explicitly `None`
|
749 |
+
warnings.warn(
|
750 |
+
"`position_ids` have no functionality in BLOOM and will be removed in v5.0.0. You can safely ignore"
|
751 |
+
" passing `position_ids`.",
|
752 |
+
FutureWarning,
|
753 |
+
)
|
754 |
+
if len(deprecated_arguments) > 0:
|
755 |
+
raise ValueError(f"Got unexpected arguments: {deprecated_arguments}")
|
756 |
+
|
757 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
758 |
+
|
759 |
+
transformer_outputs = self.transformer(
|
760 |
+
input_ids,
|
761 |
+
past_key_values=past_key_values,
|
762 |
+
attention_mask=attention_mask,
|
763 |
+
head_mask=head_mask,
|
764 |
+
inputs_embeds=inputs_embeds,
|
765 |
+
use_cache=use_cache,
|
766 |
+
output_attentions=output_attentions,
|
767 |
+
output_hidden_states=output_hidden_states,
|
768 |
+
return_dict=return_dict,
|
769 |
+
)
|
770 |
+
hidden_states = transformer_outputs[0]
|
771 |
+
|
772 |
+
lm_logits = self.lm_head(hidden_states)
|
773 |
+
|
774 |
+
loss = None
|
775 |
+
if labels is not None:
|
776 |
+
# Shift so that tokens < n predict n
|
777 |
+
shift_logits = lm_logits[..., :-1, :].contiguous()
|
778 |
+
shift_labels = labels[..., 1:].contiguous()
|
779 |
+
batch_size, seq_length, vocab_size = shift_logits.shape
|
780 |
+
# Flatten the tokens
|
781 |
+
loss_fct = CrossEntropyLoss()
|
782 |
+
loss = loss_fct(
|
783 |
+
shift_logits.view(batch_size * seq_length, vocab_size), shift_labels.view(batch_size * seq_length)
|
784 |
+
)
|
785 |
+
|
786 |
+
if not return_dict:
|
787 |
+
output = (lm_logits,) + transformer_outputs[1:]
|
788 |
+
return ((loss,) + output) if loss is not None else output
|
789 |
+
|
790 |
+
return CausalLMOutputWithCrossAttentions(
|
791 |
+
loss=loss,
|
792 |
+
logits=lm_logits,
|
793 |
+
past_key_values=transformer_outputs.past_key_values,
|
794 |
+
hidden_states=transformer_outputs.hidden_states,
|
795 |
+
attentions=transformer_outputs.attentions,
|
796 |
+
)
|
797 |
+
|
798 |
+
def _reorder_cache(
|
799 |
+
self, past: Tuple[Tuple[torch.Tensor, torch.Tensor], ...], beam_idx: torch.LongTensor
|
800 |
+
) -> Tuple[Tuple[torch.Tensor, torch.Tensor], ...]:
|
801 |
+
"""
|
802 |
+
This function is used to re-order the `past_key_values` cache if [`~PreTrainedModel.beam_search`] or
|
803 |
+
[`~PreTrainedModel.beam_sample`] is called. This is required to match `past_key_values` with the correct
|
804 |
+
beam_idx at every generation step.
|
805 |
+
|
806 |
+
Output shares the same memory storage as `past`.
|
807 |
+
"""
|
808 |
+
standardized_past = self._convert_to_standard_cache(past, batch_size=len(beam_idx))
|
809 |
+
|
810 |
+
# Get a copy of `beam_idx` on all the devices where we need those indices.
|
811 |
+
device_to_beam_idx = {
|
812 |
+
past_state.device: beam_idx.to(past_state.device) for layer_past in past for past_state in layer_past
|
813 |
+
}
|
814 |
+
reordered_past = tuple(
|
815 |
+
(
|
816 |
+
layer_past[0].index_select(0, device_to_beam_idx[layer_past[0].device]),
|
817 |
+
layer_past[1].index_select(0, device_to_beam_idx[layer_past[0].device]),
|
818 |
+
)
|
819 |
+
for layer_past in standardized_past
|
820 |
+
)
|
821 |
+
return self._convert_to_rw_cache(reordered_past)
|
822 |
+
|
823 |
+
|
824 |
+
class RWForSequenceClassification(RWPreTrainedModel):
|
825 |
+
_keys_to_ignore_on_load_missing = [r"h.*.self_attention.scale_mask_softmax.causal_mask", r"lm_head.weight"]
|
826 |
+
|
827 |
+
def __init__(self, config: RWConfig):
|
828 |
+
super().__init__(config)
|
829 |
+
self.num_labels = config.num_labels
|
830 |
+
self.transformer = RWModel(config)
|
831 |
+
self.score = nn.Linear(config.hidden_size, config.num_labels, bias=False)
|
832 |
+
|
833 |
+
# Initialize weights and apply final processing
|
834 |
+
self.post_init()
|
835 |
+
|
836 |
+
def forward(
|
837 |
+
self,
|
838 |
+
input_ids: Optional[torch.LongTensor] = None,
|
839 |
+
past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
|
840 |
+
attention_mask: Optional[torch.Tensor] = None,
|
841 |
+
head_mask: Optional[torch.Tensor] = None,
|
842 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
843 |
+
labels: Optional[torch.Tensor] = None,
|
844 |
+
use_cache: Optional[bool] = None,
|
845 |
+
output_attentions: Optional[bool] = None,
|
846 |
+
output_hidden_states: Optional[bool] = None,
|
847 |
+
return_dict: Optional[bool] = None,
|
848 |
+
**deprecated_arguments,
|
849 |
+
) -> Union[Tuple[torch.Tensor], SequenceClassifierOutputWithPast]:
|
850 |
+
r"""
|
851 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
852 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
853 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
854 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
855 |
+
"""
|
856 |
+
if deprecated_arguments.pop("position_ids", False) is not False:
|
857 |
+
# `position_ids` could have been `torch.Tensor` or `None` so defaulting pop to `False` allows to detect if users were passing explicitly `None`
|
858 |
+
warnings.warn(
|
859 |
+
"`position_ids` have no functionality in BLOOM and will be removed in v5.0.0. You can safely ignore"
|
860 |
+
" passing `position_ids`.",
|
861 |
+
FutureWarning,
|
862 |
+
)
|
863 |
+
if len(deprecated_arguments) > 0:
|
864 |
+
raise ValueError(f"Got unexpected arguments: {deprecated_arguments}")
|
865 |
+
|
866 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
867 |
+
|
868 |
+
transformer_outputs = self.transformer(
|
869 |
+
input_ids,
|
870 |
+
past_key_values=past_key_values,
|
871 |
+
attention_mask=attention_mask,
|
872 |
+
head_mask=head_mask,
|
873 |
+
inputs_embeds=inputs_embeds,
|
874 |
+
use_cache=use_cache,
|
875 |
+
output_attentions=output_attentions,
|
876 |
+
output_hidden_states=output_hidden_states,
|
877 |
+
return_dict=return_dict,
|
878 |
+
)
|
879 |
+
|
880 |
+
hidden_states = transformer_outputs[0]
|
881 |
+
logits = self.score(hidden_states)
|
882 |
+
|
883 |
+
if input_ids is not None:
|
884 |
+
batch_size = input_ids.shape[0]
|
885 |
+
else:
|
886 |
+
batch_size = inputs_embeds.shape[0]
|
887 |
+
|
888 |
+
if self.config.pad_token_id is None and batch_size != 1:
|
889 |
+
raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
|
890 |
+
if self.config.pad_token_id is None:
|
891 |
+
sequence_lengths = -1
|
892 |
+
else:
|
893 |
+
if input_ids is not None:
|
894 |
+
sequence_lengths = torch.ne(input_ids, self.config.pad_token_id).sum(dim=-1) - 1
|
895 |
+
else:
|
896 |
+
sequence_lengths = -1
|
897 |
+
logger.warning(
|
898 |
+
f"{self.__class__.__name__} will not detect padding tokens in `inputs_embeds`. Results may be "
|
899 |
+
"unexpected if using padding tokens in conjunction with `inputs_embeds.`"
|
900 |
+
)
|
901 |
+
|
902 |
+
pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
|
903 |
+
|
904 |
+
loss = None
|
905 |
+
if labels is not None:
|
906 |
+
if self.config.problem_type is None:
|
907 |
+
if self.num_labels == 1:
|
908 |
+
self.config.problem_type = "regression"
|
909 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
910 |
+
self.config.problem_type = "single_label_classification"
|
911 |
+
else:
|
912 |
+
self.config.problem_type = "multi_label_classification"
|
913 |
+
|
914 |
+
if self.config.problem_type == "regression":
|
915 |
+
loss_fct = MSELoss()
|
916 |
+
if self.num_labels == 1:
|
917 |
+
loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
|
918 |
+
else:
|
919 |
+
loss = loss_fct(pooled_logits, labels)
|
920 |
+
elif self.config.problem_type == "single_label_classification":
|
921 |
+
loss_fct = CrossEntropyLoss()
|
922 |
+
loss = loss_fct(pooled_logits, labels)
|
923 |
+
elif self.config.problem_type == "multi_label_classification":
|
924 |
+
loss_fct = BCEWithLogitsLoss()
|
925 |
+
loss = loss_fct(pooled_logits, labels)
|
926 |
+
if not return_dict:
|
927 |
+
output = (pooled_logits,) + transformer_outputs[1:]
|
928 |
+
return ((loss,) + output) if loss is not None else output
|
929 |
+
|
930 |
+
return SequenceClassifierOutputWithPast(
|
931 |
+
loss=loss,
|
932 |
+
logits=pooled_logits,
|
933 |
+
past_key_values=transformer_outputs.past_key_values,
|
934 |
+
hidden_states=transformer_outputs.hidden_states,
|
935 |
+
attentions=transformer_outputs.attentions,
|
936 |
+
)
|
937 |
+
|
938 |
+
|
939 |
+
class RWForTokenClassification(RWPreTrainedModel):
|
940 |
+
_keys_to_ignore_on_load_missing = [r"h.*.self_attention.scale_mask_softmax.causal_mask", r"lm_head.weight"]
|
941 |
+
|
942 |
+
def __init__(self, config: RWConfig):
|
943 |
+
super().__init__(config)
|
944 |
+
self.num_labels = config.num_labels
|
945 |
+
|
946 |
+
self.transformer = RWModel(config)
|
947 |
+
if hasattr(config, "classifier_dropout") and config.classifier_dropout is not None:
|
948 |
+
classifier_dropout = config.classifier_dropout
|
949 |
+
elif hasattr(config, "hidden_dropout") and config.hidden_dropout is not None:
|
950 |
+
classifier_dropout = config.hidden_dropout
|
951 |
+
else:
|
952 |
+
classifier_dropout = 0.1
|
953 |
+
self.dropout = nn.Dropout(classifier_dropout)
|
954 |
+
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
|
955 |
+
|
956 |
+
# Initialize weights and apply final processing
|
957 |
+
self.post_init()
|
958 |
+
|
959 |
+
def forward(
|
960 |
+
self,
|
961 |
+
input_ids: Optional[torch.LongTensor] = None,
|
962 |
+
past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
|
963 |
+
attention_mask: Optional[torch.Tensor] = None,
|
964 |
+
head_mask: Optional[torch.Tensor] = None,
|
965 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
966 |
+
labels: Optional[torch.Tensor] = None,
|
967 |
+
use_cache: Optional[bool] = None,
|
968 |
+
output_attentions: Optional[bool] = None,
|
969 |
+
output_hidden_states: Optional[bool] = None,
|
970 |
+
return_dict: Optional[bool] = None,
|
971 |
+
**deprecated_arguments,
|
972 |
+
) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]:
|
973 |
+
r"""
|
974 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
975 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
976 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
977 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
978 |
+
"""
|
979 |
+
if deprecated_arguments.pop("position_ids", False) is not False:
|
980 |
+
# `position_ids` could have been `torch.Tensor` or `None` so defaulting pop to `False` allows to detect if users were passing explicitly `None`
|
981 |
+
warnings.warn(
|
982 |
+
"`position_ids` have no functionality in BLOOM and will be removed in v5.0.0. You can safely ignore"
|
983 |
+
" passing `position_ids`.",
|
984 |
+
FutureWarning,
|
985 |
+
)
|
986 |
+
if len(deprecated_arguments) > 0:
|
987 |
+
raise ValueError(f"Got unexpected arguments: {deprecated_arguments}")
|
988 |
+
|
989 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
990 |
+
|
991 |
+
transformer_outputs = self.transformer(
|
992 |
+
input_ids,
|
993 |
+
past_key_values=past_key_values,
|
994 |
+
attention_mask=attention_mask,
|
995 |
+
head_mask=head_mask,
|
996 |
+
inputs_embeds=inputs_embeds,
|
997 |
+
use_cache=use_cache,
|
998 |
+
output_attentions=output_attentions,
|
999 |
+
output_hidden_states=output_hidden_states,
|
1000 |
+
return_dict=return_dict,
|
1001 |
+
)
|
1002 |
+
|
1003 |
+
hidden_states = transformer_outputs[0]
|
1004 |
+
hidden_states = self.dropout(hidden_states)
|
1005 |
+
logits = self.classifier(hidden_states)
|
1006 |
+
|
1007 |
+
loss = None
|
1008 |
+
if labels is not None:
|
1009 |
+
batch_size, seq_length = labels.shape
|
1010 |
+
loss_fct = CrossEntropyLoss()
|
1011 |
+
loss = loss_fct(logits.view(batch_size * seq_length, self.num_labels), labels.view(batch_size * seq_length))
|
1012 |
+
|
1013 |
+
if not return_dict:
|
1014 |
+
output = (logits,) + transformer_outputs[2:]
|
1015 |
+
return ((loss,) + output) if loss is not None else output
|
1016 |
+
|
1017 |
+
return TokenClassifierOutput(
|
1018 |
+
loss=loss,
|
1019 |
+
logits=logits,
|
1020 |
+
hidden_states=transformer_outputs.hidden_states,
|
1021 |
+
attentions=transformer_outputs.attentions,
|
1022 |
+
)
|
1023 |
+
|
1024 |
+
|
1025 |
+
class RWForQuestionAnswering(RWPreTrainedModel):
|
1026 |
+
_keys_to_ignore_on_load_missing = [r"h.*.self_attention.scale_mask_softmax.causal_mask", r"lm_head.weight"]
|
1027 |
+
|
1028 |
+
def __init__(self, config):
|
1029 |
+
super().__init__(config)
|
1030 |
+
self.transformer = RWModel(config)
|
1031 |
+
self.qa_outputs = nn.Linear(config.hidden_size, 2)
|
1032 |
+
|
1033 |
+
# Initialize weights and apply final processing
|
1034 |
+
self.post_init()
|
1035 |
+
|
1036 |
+
def forward(
|
1037 |
+
self,
|
1038 |
+
input_ids: Optional[torch.LongTensor] = None,
|
1039 |
+
attention_mask: Optional[torch.FloatTensor] = None,
|
1040 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1041 |
+
head_mask: Optional[torch.FloatTensor] = None,
|
1042 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1043 |
+
start_positions: Optional[torch.LongTensor] = None,
|
1044 |
+
end_positions: Optional[torch.LongTensor] = None,
|
1045 |
+
output_attentions: Optional[bool] = None,
|
1046 |
+
output_hidden_states: Optional[bool] = None,
|
1047 |
+
return_dict: Optional[bool] = None,
|
1048 |
+
) -> Union[Tuple, QuestionAnsweringModelOutput]:
|
1049 |
+
r"""
|
1050 |
+
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
1051 |
+
Labels for position (index) of the start of the labelled span for computing the token classification loss.
|
1052 |
+
Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
|
1053 |
+
are not taken into account for computing the loss.
|
1054 |
+
end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
1055 |
+
Labels for position (index) of the end of the labelled span for computing the token classification loss.
|
1056 |
+
Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
|
1057 |
+
are not taken into account for computing the loss.
|
1058 |
+
"""
|
1059 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1060 |
+
|
1061 |
+
outputs = self.transformer(
|
1062 |
+
input_ids,
|
1063 |
+
attention_mask=attention_mask,
|
1064 |
+
position_ids=position_ids,
|
1065 |
+
head_mask=head_mask,
|
1066 |
+
inputs_embeds=inputs_embeds,
|
1067 |
+
output_attentions=output_attentions,
|
1068 |
+
output_hidden_states=output_hidden_states,
|
1069 |
+
return_dict=return_dict,
|
1070 |
+
)
|
1071 |
+
|
1072 |
+
sequence_output = outputs[0]
|
1073 |
+
|
1074 |
+
logits = self.qa_outputs(sequence_output)
|
1075 |
+
start_logits, end_logits = logits.split(1, dim=-1)
|
1076 |
+
start_logits = start_logits.squeeze(-1).contiguous()
|
1077 |
+
end_logits = end_logits.squeeze(-1).contiguous()
|
1078 |
+
|
1079 |
+
total_loss = None
|
1080 |
+
if start_positions is not None and end_positions is not None:
|
1081 |
+
# If we are on multi-GPU, split add a dimension
|
1082 |
+
if len(start_positions.size()) > 1:
|
1083 |
+
start_positions = start_positions.squeeze(-1)
|
1084 |
+
if len(end_positions.size()) > 1:
|
1085 |
+
end_positions = end_positions.squeeze(-1)
|
1086 |
+
# sometimes the start/end positions are outside our model inputs, we ignore these terms
|
1087 |
+
ignored_index = start_logits.size(1)
|
1088 |
+
start_positions = start_positions.clamp(0, ignored_index)
|
1089 |
+
end_positions = end_positions.clamp(0, ignored_index)
|
1090 |
+
|
1091 |
+
loss_fct = CrossEntropyLoss(ignore_index=ignored_index)
|
1092 |
+
start_loss = loss_fct(start_logits, start_positions)
|
1093 |
+
end_loss = loss_fct(end_logits, end_positions)
|
1094 |
+
total_loss = (start_loss + end_loss) / 2
|
1095 |
+
|
1096 |
+
if not return_dict:
|
1097 |
+
output = (start_logits, end_logits) + outputs[2:]
|
1098 |
+
return ((total_loss,) + output) if total_loss is not None else output
|
1099 |
+
|
1100 |
+
return QuestionAnsweringModelOutput(
|
1101 |
+
loss=total_loss,
|
1102 |
+
start_logits=start_logits,
|
1103 |
+
end_logits=end_logits,
|
1104 |
+
hidden_states=outputs.hidden_states,
|
1105 |
+
attentions=outputs.attentions,
|
1106 |
+
)
|
pytorch_model-00001-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:770439505668e74fd22664afe2307c3fa6c3d46a54bf19b0b8ef1b68e738ba00
|
3 |
+
size 9211125767
|
pytorch_model-00002-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:34837514af4f79495f44376ac0b24678b7fb55d13e076a6554326c7c1b366d1f
|
3 |
+
size 9798428805
|
pytorch_model-00003-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:518c4c73654e8a27fa10a5004f5291e9daad50b7f77095478e2610da8d595a6f
|
3 |
+
size 9227870553
|
pytorch_model-00004-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:da40ea2abb4fba88c95cf5de79e635460646c73ee72be08dc070c1f7ac80e17b
|
3 |
+
size 9798428869
|
pytorch_model-00005-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b03438aa4ecaa7e7d4cc074b28e84da4fdf91a8f34c6bb7a2c1c3642c42da9f5
|
3 |
+
size 9227870617
|
pytorch_model-00006-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:df7866835f8249f66161362826af6476bd5660b34df14028d1410844ea0bb202
|
3 |
+
size 9798428869
|
pytorch_model-00007-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:37cffd3abd8a5db306118f84a95dbbe99e65531a654a94376eaa61a4a10f38c8
|
3 |
+
size 9227870617
|
pytorch_model-00008-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f579ed55df0c8b0aaf3adddc38c9d3f7ad867183b488168a01ce24889c8092f8
|
3 |
+
size 9798428869
|
pytorch_model-00009-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a63313464c68b6f0a3429c49ba891c4a97cb7a3025d54edf26ffc3594f635a7c
|
3 |
+
size 9227870617
|
pytorch_model-00010-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:33069ed9465646bd3d25133bf6d4907df231bede4fd5d310446e1715f91f2f5a
|
3 |
+
size 9798428869
|
pytorch_model-00011-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:74b1316102ac0994fd07ebd230ff0a252896520733707c7333fe505f71dd5465
|
3 |
+
size 9227870617
|
pytorch_model-00012-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:00d91dec3759c87d5c64ce8cf4694342e301631e772359741b863a8db5954004
|
3 |
+
size 9798428869
|
pytorch_model-00013-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dd07f1c13ba2eea37fa55c0517599b5fd68ee9b2173aa557e11c665f5b6a8678
|
3 |
+
size 9227870617
|
pytorch_model-00014-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f95d4d7885f5f15668550e7e4956088936d86243f77123c99249d64aaa462e29
|
3 |
+
size 9798428869
|
pytorch_model-00015-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ff358398d8aa23a9e666eebd0567151eefa96a7b6cff41c23fbf9f311b27ac8d
|
3 |
+
size 9227870617
|
pytorch_model-00016-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:99b1244597d1a396d2d9c516ec9e312bba37c88876e060b4e1484fbb1156682a
|
3 |
+
size 9798428869
|
pytorch_model-00017-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1af1f84068f582a67ebecc9e9b64be2bd63faf94b7e91c4e851c80f7865b39e4
|
3 |
+
size 9227870617
|
pytorch_model-00018-of-00018.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5269964738f900cc327187d5bc5ce9c76f26572b8a8cce842f2a9cf9ee973a56
|
3 |
+
size 5922590931
|
pytorch_model.bin.index.json
ADDED
@@ -0,0 +1,491 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 167343947776
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"lm_head.weight": "pytorch_model-00018-of-00018.bin",
|
7 |
+
"transformer.h.0.ln_attn.bias": "pytorch_model-00001-of-00018.bin",
|
8 |
+
"transformer.h.0.ln_attn.weight": "pytorch_model-00001-of-00018.bin",
|
9 |
+
"transformer.h.0.ln_mlp.bias": "pytorch_model-00001-of-00018.bin",
|
10 |
+
"transformer.h.0.ln_mlp.weight": "pytorch_model-00001-of-00018.bin",
|
11 |
+
"transformer.h.0.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00018.bin",
|
12 |
+
"transformer.h.0.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00018.bin",
|
13 |
+
"transformer.h.0.self_attention.dense.weight": "pytorch_model-00001-of-00018.bin",
|
14 |
+
"transformer.h.0.self_attention.query_key_value.weight": "pytorch_model-00001-of-00018.bin",
|
15 |
+
"transformer.h.1.ln_attn.bias": "pytorch_model-00001-of-00018.bin",
|
16 |
+
"transformer.h.1.ln_attn.weight": "pytorch_model-00001-of-00018.bin",
|
17 |
+
"transformer.h.1.ln_mlp.bias": "pytorch_model-00001-of-00018.bin",
|
18 |
+
"transformer.h.1.ln_mlp.weight": "pytorch_model-00001-of-00018.bin",
|
19 |
+
"transformer.h.1.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00018.bin",
|
20 |
+
"transformer.h.1.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00018.bin",
|
21 |
+
"transformer.h.1.self_attention.dense.weight": "pytorch_model-00001-of-00018.bin",
|
22 |
+
"transformer.h.1.self_attention.query_key_value.weight": "pytorch_model-00001-of-00018.bin",
|
23 |
+
"transformer.h.10.ln_attn.bias": "pytorch_model-00004-of-00018.bin",
|
24 |
+
"transformer.h.10.ln_attn.weight": "pytorch_model-00004-of-00018.bin",
|
25 |
+
"transformer.h.10.ln_mlp.bias": "pytorch_model-00004-of-00018.bin",
|
26 |
+
"transformer.h.10.ln_mlp.weight": "pytorch_model-00004-of-00018.bin",
|
27 |
+
"transformer.h.10.mlp.dense_4h_to_h.weight": "pytorch_model-00004-of-00018.bin",
|
28 |
+
"transformer.h.10.mlp.dense_h_to_4h.weight": "pytorch_model-00004-of-00018.bin",
|
29 |
+
"transformer.h.10.self_attention.dense.weight": "pytorch_model-00004-of-00018.bin",
|
30 |
+
"transformer.h.10.self_attention.query_key_value.weight": "pytorch_model-00004-of-00018.bin",
|
31 |
+
"transformer.h.11.ln_attn.bias": "pytorch_model-00004-of-00018.bin",
|
32 |
+
"transformer.h.11.ln_attn.weight": "pytorch_model-00004-of-00018.bin",
|
33 |
+
"transformer.h.11.ln_mlp.bias": "pytorch_model-00004-of-00018.bin",
|
34 |
+
"transformer.h.11.ln_mlp.weight": "pytorch_model-00004-of-00018.bin",
|
35 |
+
"transformer.h.11.mlp.dense_4h_to_h.weight": "pytorch_model-00004-of-00018.bin",
|
36 |
+
"transformer.h.11.mlp.dense_h_to_4h.weight": "pytorch_model-00004-of-00018.bin",
|
37 |
+
"transformer.h.11.self_attention.dense.weight": "pytorch_model-00004-of-00018.bin",
|
38 |
+
"transformer.h.11.self_attention.query_key_value.weight": "pytorch_model-00004-of-00018.bin",
|
39 |
+
"transformer.h.12.ln_attn.bias": "pytorch_model-00004-of-00018.bin",
|
40 |
+
"transformer.h.12.ln_attn.weight": "pytorch_model-00004-of-00018.bin",
|
41 |
+
"transformer.h.12.ln_mlp.bias": "pytorch_model-00004-of-00018.bin",
|
42 |
+
"transformer.h.12.ln_mlp.weight": "pytorch_model-00004-of-00018.bin",
|
43 |
+
"transformer.h.12.mlp.dense_4h_to_h.weight": "pytorch_model-00004-of-00018.bin",
|
44 |
+
"transformer.h.12.mlp.dense_h_to_4h.weight": "pytorch_model-00004-of-00018.bin",
|
45 |
+
"transformer.h.12.self_attention.dense.weight": "pytorch_model-00004-of-00018.bin",
|
46 |
+
"transformer.h.12.self_attention.query_key_value.weight": "pytorch_model-00004-of-00018.bin",
|
47 |
+
"transformer.h.13.ln_attn.bias": "pytorch_model-00004-of-00018.bin",
|
48 |
+
"transformer.h.13.ln_attn.weight": "pytorch_model-00004-of-00018.bin",
|
49 |
+
"transformer.h.13.ln_mlp.bias": "pytorch_model-00004-of-00018.bin",
|
50 |
+
"transformer.h.13.ln_mlp.weight": "pytorch_model-00004-of-00018.bin",
|
51 |
+
"transformer.h.13.mlp.dense_4h_to_h.weight": "pytorch_model-00005-of-00018.bin",
|
52 |
+
"transformer.h.13.mlp.dense_h_to_4h.weight": "pytorch_model-00005-of-00018.bin",
|
53 |
+
"transformer.h.13.self_attention.dense.weight": "pytorch_model-00004-of-00018.bin",
|
54 |
+
"transformer.h.13.self_attention.query_key_value.weight": "pytorch_model-00004-of-00018.bin",
|
55 |
+
"transformer.h.14.ln_attn.bias": "pytorch_model-00005-of-00018.bin",
|
56 |
+
"transformer.h.14.ln_attn.weight": "pytorch_model-00005-of-00018.bin",
|
57 |
+
"transformer.h.14.ln_mlp.bias": "pytorch_model-00005-of-00018.bin",
|
58 |
+
"transformer.h.14.ln_mlp.weight": "pytorch_model-00005-of-00018.bin",
|
59 |
+
"transformer.h.14.mlp.dense_4h_to_h.weight": "pytorch_model-00005-of-00018.bin",
|
60 |
+
"transformer.h.14.mlp.dense_h_to_4h.weight": "pytorch_model-00005-of-00018.bin",
|
61 |
+
"transformer.h.14.self_attention.dense.weight": "pytorch_model-00005-of-00018.bin",
|
62 |
+
"transformer.h.14.self_attention.query_key_value.weight": "pytorch_model-00005-of-00018.bin",
|
63 |
+
"transformer.h.15.ln_attn.bias": "pytorch_model-00005-of-00018.bin",
|
64 |
+
"transformer.h.15.ln_attn.weight": "pytorch_model-00005-of-00018.bin",
|
65 |
+
"transformer.h.15.ln_mlp.bias": "pytorch_model-00005-of-00018.bin",
|
66 |
+
"transformer.h.15.ln_mlp.weight": "pytorch_model-00005-of-00018.bin",
|
67 |
+
"transformer.h.15.mlp.dense_4h_to_h.weight": "pytorch_model-00005-of-00018.bin",
|
68 |
+
"transformer.h.15.mlp.dense_h_to_4h.weight": "pytorch_model-00005-of-00018.bin",
|
69 |
+
"transformer.h.15.self_attention.dense.weight": "pytorch_model-00005-of-00018.bin",
|
70 |
+
"transformer.h.15.self_attention.query_key_value.weight": "pytorch_model-00005-of-00018.bin",
|
71 |
+
"transformer.h.16.ln_attn.bias": "pytorch_model-00005-of-00018.bin",
|
72 |
+
"transformer.h.16.ln_attn.weight": "pytorch_model-00005-of-00018.bin",
|
73 |
+
"transformer.h.16.ln_mlp.bias": "pytorch_model-00005-of-00018.bin",
|
74 |
+
"transformer.h.16.ln_mlp.weight": "pytorch_model-00005-of-00018.bin",
|
75 |
+
"transformer.h.16.mlp.dense_4h_to_h.weight": "pytorch_model-00006-of-00018.bin",
|
76 |
+
"transformer.h.16.mlp.dense_h_to_4h.weight": "pytorch_model-00005-of-00018.bin",
|
77 |
+
"transformer.h.16.self_attention.dense.weight": "pytorch_model-00005-of-00018.bin",
|
78 |
+
"transformer.h.16.self_attention.query_key_value.weight": "pytorch_model-00005-of-00018.bin",
|
79 |
+
"transformer.h.17.ln_attn.bias": "pytorch_model-00006-of-00018.bin",
|
80 |
+
"transformer.h.17.ln_attn.weight": "pytorch_model-00006-of-00018.bin",
|
81 |
+
"transformer.h.17.ln_mlp.bias": "pytorch_model-00006-of-00018.bin",
|
82 |
+
"transformer.h.17.ln_mlp.weight": "pytorch_model-00006-of-00018.bin",
|
83 |
+
"transformer.h.17.mlp.dense_4h_to_h.weight": "pytorch_model-00006-of-00018.bin",
|
84 |
+
"transformer.h.17.mlp.dense_h_to_4h.weight": "pytorch_model-00006-of-00018.bin",
|
85 |
+
"transformer.h.17.self_attention.dense.weight": "pytorch_model-00006-of-00018.bin",
|
86 |
+
"transformer.h.17.self_attention.query_key_value.weight": "pytorch_model-00006-of-00018.bin",
|
87 |
+
"transformer.h.18.ln_attn.bias": "pytorch_model-00006-of-00018.bin",
|
88 |
+
"transformer.h.18.ln_attn.weight": "pytorch_model-00006-of-00018.bin",
|
89 |
+
"transformer.h.18.ln_mlp.bias": "pytorch_model-00006-of-00018.bin",
|
90 |
+
"transformer.h.18.ln_mlp.weight": "pytorch_model-00006-of-00018.bin",
|
91 |
+
"transformer.h.18.mlp.dense_4h_to_h.weight": "pytorch_model-00006-of-00018.bin",
|
92 |
+
"transformer.h.18.mlp.dense_h_to_4h.weight": "pytorch_model-00006-of-00018.bin",
|
93 |
+
"transformer.h.18.self_attention.dense.weight": "pytorch_model-00006-of-00018.bin",
|
94 |
+
"transformer.h.18.self_attention.query_key_value.weight": "pytorch_model-00006-of-00018.bin",
|
95 |
+
"transformer.h.19.ln_attn.bias": "pytorch_model-00006-of-00018.bin",
|
96 |
+
"transformer.h.19.ln_attn.weight": "pytorch_model-00006-of-00018.bin",
|
97 |
+
"transformer.h.19.ln_mlp.bias": "pytorch_model-00006-of-00018.bin",
|
98 |
+
"transformer.h.19.ln_mlp.weight": "pytorch_model-00006-of-00018.bin",
|
99 |
+
"transformer.h.19.mlp.dense_4h_to_h.weight": "pytorch_model-00006-of-00018.bin",
|
100 |
+
"transformer.h.19.mlp.dense_h_to_4h.weight": "pytorch_model-00006-of-00018.bin",
|
101 |
+
"transformer.h.19.self_attention.dense.weight": "pytorch_model-00006-of-00018.bin",
|
102 |
+
"transformer.h.19.self_attention.query_key_value.weight": "pytorch_model-00006-of-00018.bin",
|
103 |
+
"transformer.h.2.ln_attn.bias": "pytorch_model-00001-of-00018.bin",
|
104 |
+
"transformer.h.2.ln_attn.weight": "pytorch_model-00001-of-00018.bin",
|
105 |
+
"transformer.h.2.ln_mlp.bias": "pytorch_model-00001-of-00018.bin",
|
106 |
+
"transformer.h.2.ln_mlp.weight": "pytorch_model-00001-of-00018.bin",
|
107 |
+
"transformer.h.2.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00018.bin",
|
108 |
+
"transformer.h.2.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00018.bin",
|
109 |
+
"transformer.h.2.self_attention.dense.weight": "pytorch_model-00001-of-00018.bin",
|
110 |
+
"transformer.h.2.self_attention.query_key_value.weight": "pytorch_model-00001-of-00018.bin",
|
111 |
+
"transformer.h.20.ln_attn.bias": "pytorch_model-00006-of-00018.bin",
|
112 |
+
"transformer.h.20.ln_attn.weight": "pytorch_model-00006-of-00018.bin",
|
113 |
+
"transformer.h.20.ln_mlp.bias": "pytorch_model-00006-of-00018.bin",
|
114 |
+
"transformer.h.20.ln_mlp.weight": "pytorch_model-00006-of-00018.bin",
|
115 |
+
"transformer.h.20.mlp.dense_4h_to_h.weight": "pytorch_model-00007-of-00018.bin",
|
116 |
+
"transformer.h.20.mlp.dense_h_to_4h.weight": "pytorch_model-00007-of-00018.bin",
|
117 |
+
"transformer.h.20.self_attention.dense.weight": "pytorch_model-00006-of-00018.bin",
|
118 |
+
"transformer.h.20.self_attention.query_key_value.weight": "pytorch_model-00006-of-00018.bin",
|
119 |
+
"transformer.h.21.ln_attn.bias": "pytorch_model-00007-of-00018.bin",
|
120 |
+
"transformer.h.21.ln_attn.weight": "pytorch_model-00007-of-00018.bin",
|
121 |
+
"transformer.h.21.ln_mlp.bias": "pytorch_model-00007-of-00018.bin",
|
122 |
+
"transformer.h.21.ln_mlp.weight": "pytorch_model-00007-of-00018.bin",
|
123 |
+
"transformer.h.21.mlp.dense_4h_to_h.weight": "pytorch_model-00007-of-00018.bin",
|
124 |
+
"transformer.h.21.mlp.dense_h_to_4h.weight": "pytorch_model-00007-of-00018.bin",
|
125 |
+
"transformer.h.21.self_attention.dense.weight": "pytorch_model-00007-of-00018.bin",
|
126 |
+
"transformer.h.21.self_attention.query_key_value.weight": "pytorch_model-00007-of-00018.bin",
|
127 |
+
"transformer.h.22.ln_attn.bias": "pytorch_model-00007-of-00018.bin",
|
128 |
+
"transformer.h.22.ln_attn.weight": "pytorch_model-00007-of-00018.bin",
|
129 |
+
"transformer.h.22.ln_mlp.bias": "pytorch_model-00007-of-00018.bin",
|
130 |
+
"transformer.h.22.ln_mlp.weight": "pytorch_model-00007-of-00018.bin",
|
131 |
+
"transformer.h.22.mlp.dense_4h_to_h.weight": "pytorch_model-00007-of-00018.bin",
|
132 |
+
"transformer.h.22.mlp.dense_h_to_4h.weight": "pytorch_model-00007-of-00018.bin",
|
133 |
+
"transformer.h.22.self_attention.dense.weight": "pytorch_model-00007-of-00018.bin",
|
134 |
+
"transformer.h.22.self_attention.query_key_value.weight": "pytorch_model-00007-of-00018.bin",
|
135 |
+
"transformer.h.23.ln_attn.bias": "pytorch_model-00007-of-00018.bin",
|
136 |
+
"transformer.h.23.ln_attn.weight": "pytorch_model-00007-of-00018.bin",
|
137 |
+
"transformer.h.23.ln_mlp.bias": "pytorch_model-00007-of-00018.bin",
|
138 |
+
"transformer.h.23.ln_mlp.weight": "pytorch_model-00007-of-00018.bin",
|
139 |
+
"transformer.h.23.mlp.dense_4h_to_h.weight": "pytorch_model-00008-of-00018.bin",
|
140 |
+
"transformer.h.23.mlp.dense_h_to_4h.weight": "pytorch_model-00007-of-00018.bin",
|
141 |
+
"transformer.h.23.self_attention.dense.weight": "pytorch_model-00007-of-00018.bin",
|
142 |
+
"transformer.h.23.self_attention.query_key_value.weight": "pytorch_model-00007-of-00018.bin",
|
143 |
+
"transformer.h.24.ln_attn.bias": "pytorch_model-00008-of-00018.bin",
|
144 |
+
"transformer.h.24.ln_attn.weight": "pytorch_model-00008-of-00018.bin",
|
145 |
+
"transformer.h.24.ln_mlp.bias": "pytorch_model-00008-of-00018.bin",
|
146 |
+
"transformer.h.24.ln_mlp.weight": "pytorch_model-00008-of-00018.bin",
|
147 |
+
"transformer.h.24.mlp.dense_4h_to_h.weight": "pytorch_model-00008-of-00018.bin",
|
148 |
+
"transformer.h.24.mlp.dense_h_to_4h.weight": "pytorch_model-00008-of-00018.bin",
|
149 |
+
"transformer.h.24.self_attention.dense.weight": "pytorch_model-00008-of-00018.bin",
|
150 |
+
"transformer.h.24.self_attention.query_key_value.weight": "pytorch_model-00008-of-00018.bin",
|
151 |
+
"transformer.h.25.ln_attn.bias": "pytorch_model-00008-of-00018.bin",
|
152 |
+
"transformer.h.25.ln_attn.weight": "pytorch_model-00008-of-00018.bin",
|
153 |
+
"transformer.h.25.ln_mlp.bias": "pytorch_model-00008-of-00018.bin",
|
154 |
+
"transformer.h.25.ln_mlp.weight": "pytorch_model-00008-of-00018.bin",
|
155 |
+
"transformer.h.25.mlp.dense_4h_to_h.weight": "pytorch_model-00008-of-00018.bin",
|
156 |
+
"transformer.h.25.mlp.dense_h_to_4h.weight": "pytorch_model-00008-of-00018.bin",
|
157 |
+
"transformer.h.25.self_attention.dense.weight": "pytorch_model-00008-of-00018.bin",
|
158 |
+
"transformer.h.25.self_attention.query_key_value.weight": "pytorch_model-00008-of-00018.bin",
|
159 |
+
"transformer.h.26.ln_attn.bias": "pytorch_model-00008-of-00018.bin",
|
160 |
+
"transformer.h.26.ln_attn.weight": "pytorch_model-00008-of-00018.bin",
|
161 |
+
"transformer.h.26.ln_mlp.bias": "pytorch_model-00008-of-00018.bin",
|
162 |
+
"transformer.h.26.ln_mlp.weight": "pytorch_model-00008-of-00018.bin",
|
163 |
+
"transformer.h.26.mlp.dense_4h_to_h.weight": "pytorch_model-00008-of-00018.bin",
|
164 |
+
"transformer.h.26.mlp.dense_h_to_4h.weight": "pytorch_model-00008-of-00018.bin",
|
165 |
+
"transformer.h.26.self_attention.dense.weight": "pytorch_model-00008-of-00018.bin",
|
166 |
+
"transformer.h.26.self_attention.query_key_value.weight": "pytorch_model-00008-of-00018.bin",
|
167 |
+
"transformer.h.27.ln_attn.bias": "pytorch_model-00008-of-00018.bin",
|
168 |
+
"transformer.h.27.ln_attn.weight": "pytorch_model-00008-of-00018.bin",
|
169 |
+
"transformer.h.27.ln_mlp.bias": "pytorch_model-00008-of-00018.bin",
|
170 |
+
"transformer.h.27.ln_mlp.weight": "pytorch_model-00008-of-00018.bin",
|
171 |
+
"transformer.h.27.mlp.dense_4h_to_h.weight": "pytorch_model-00009-of-00018.bin",
|
172 |
+
"transformer.h.27.mlp.dense_h_to_4h.weight": "pytorch_model-00009-of-00018.bin",
|
173 |
+
"transformer.h.27.self_attention.dense.weight": "pytorch_model-00008-of-00018.bin",
|
174 |
+
"transformer.h.27.self_attention.query_key_value.weight": "pytorch_model-00008-of-00018.bin",
|
175 |
+
"transformer.h.28.ln_attn.bias": "pytorch_model-00009-of-00018.bin",
|
176 |
+
"transformer.h.28.ln_attn.weight": "pytorch_model-00009-of-00018.bin",
|
177 |
+
"transformer.h.28.ln_mlp.bias": "pytorch_model-00009-of-00018.bin",
|
178 |
+
"transformer.h.28.ln_mlp.weight": "pytorch_model-00009-of-00018.bin",
|
179 |
+
"transformer.h.28.mlp.dense_4h_to_h.weight": "pytorch_model-00009-of-00018.bin",
|
180 |
+
"transformer.h.28.mlp.dense_h_to_4h.weight": "pytorch_model-00009-of-00018.bin",
|
181 |
+
"transformer.h.28.self_attention.dense.weight": "pytorch_model-00009-of-00018.bin",
|
182 |
+
"transformer.h.28.self_attention.query_key_value.weight": "pytorch_model-00009-of-00018.bin",
|
183 |
+
"transformer.h.29.ln_attn.bias": "pytorch_model-00009-of-00018.bin",
|
184 |
+
"transformer.h.29.ln_attn.weight": "pytorch_model-00009-of-00018.bin",
|
185 |
+
"transformer.h.29.ln_mlp.bias": "pytorch_model-00009-of-00018.bin",
|
186 |
+
"transformer.h.29.ln_mlp.weight": "pytorch_model-00009-of-00018.bin",
|
187 |
+
"transformer.h.29.mlp.dense_4h_to_h.weight": "pytorch_model-00009-of-00018.bin",
|
188 |
+
"transformer.h.29.mlp.dense_h_to_4h.weight": "pytorch_model-00009-of-00018.bin",
|
189 |
+
"transformer.h.29.self_attention.dense.weight": "pytorch_model-00009-of-00018.bin",
|
190 |
+
"transformer.h.29.self_attention.query_key_value.weight": "pytorch_model-00009-of-00018.bin",
|
191 |
+
"transformer.h.3.ln_attn.bias": "pytorch_model-00002-of-00018.bin",
|
192 |
+
"transformer.h.3.ln_attn.weight": "pytorch_model-00002-of-00018.bin",
|
193 |
+
"transformer.h.3.ln_mlp.bias": "pytorch_model-00002-of-00018.bin",
|
194 |
+
"transformer.h.3.ln_mlp.weight": "pytorch_model-00002-of-00018.bin",
|
195 |
+
"transformer.h.3.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00018.bin",
|
196 |
+
"transformer.h.3.mlp.dense_h_to_4h.weight": "pytorch_model-00002-of-00018.bin",
|
197 |
+
"transformer.h.3.self_attention.dense.weight": "pytorch_model-00002-of-00018.bin",
|
198 |
+
"transformer.h.3.self_attention.query_key_value.weight": "pytorch_model-00002-of-00018.bin",
|
199 |
+
"transformer.h.30.ln_attn.bias": "pytorch_model-00009-of-00018.bin",
|
200 |
+
"transformer.h.30.ln_attn.weight": "pytorch_model-00009-of-00018.bin",
|
201 |
+
"transformer.h.30.ln_mlp.bias": "pytorch_model-00009-of-00018.bin",
|
202 |
+
"transformer.h.30.ln_mlp.weight": "pytorch_model-00009-of-00018.bin",
|
203 |
+
"transformer.h.30.mlp.dense_4h_to_h.weight": "pytorch_model-00010-of-00018.bin",
|
204 |
+
"transformer.h.30.mlp.dense_h_to_4h.weight": "pytorch_model-00009-of-00018.bin",
|
205 |
+
"transformer.h.30.self_attention.dense.weight": "pytorch_model-00009-of-00018.bin",
|
206 |
+
"transformer.h.30.self_attention.query_key_value.weight": "pytorch_model-00009-of-00018.bin",
|
207 |
+
"transformer.h.31.ln_attn.bias": "pytorch_model-00010-of-00018.bin",
|
208 |
+
"transformer.h.31.ln_attn.weight": "pytorch_model-00010-of-00018.bin",
|
209 |
+
"transformer.h.31.ln_mlp.bias": "pytorch_model-00010-of-00018.bin",
|
210 |
+
"transformer.h.31.ln_mlp.weight": "pytorch_model-00010-of-00018.bin",
|
211 |
+
"transformer.h.31.mlp.dense_4h_to_h.weight": "pytorch_model-00010-of-00018.bin",
|
212 |
+
"transformer.h.31.mlp.dense_h_to_4h.weight": "pytorch_model-00010-of-00018.bin",
|
213 |
+
"transformer.h.31.self_attention.dense.weight": "pytorch_model-00010-of-00018.bin",
|
214 |
+
"transformer.h.31.self_attention.query_key_value.weight": "pytorch_model-00010-of-00018.bin",
|
215 |
+
"transformer.h.32.ln_attn.bias": "pytorch_model-00010-of-00018.bin",
|
216 |
+
"transformer.h.32.ln_attn.weight": "pytorch_model-00010-of-00018.bin",
|
217 |
+
"transformer.h.32.ln_mlp.bias": "pytorch_model-00010-of-00018.bin",
|
218 |
+
"transformer.h.32.ln_mlp.weight": "pytorch_model-00010-of-00018.bin",
|
219 |
+
"transformer.h.32.mlp.dense_4h_to_h.weight": "pytorch_model-00010-of-00018.bin",
|
220 |
+
"transformer.h.32.mlp.dense_h_to_4h.weight": "pytorch_model-00010-of-00018.bin",
|
221 |
+
"transformer.h.32.self_attention.dense.weight": "pytorch_model-00010-of-00018.bin",
|
222 |
+
"transformer.h.32.self_attention.query_key_value.weight": "pytorch_model-00010-of-00018.bin",
|
223 |
+
"transformer.h.33.ln_attn.bias": "pytorch_model-00010-of-00018.bin",
|
224 |
+
"transformer.h.33.ln_attn.weight": "pytorch_model-00010-of-00018.bin",
|
225 |
+
"transformer.h.33.ln_mlp.bias": "pytorch_model-00010-of-00018.bin",
|
226 |
+
"transformer.h.33.ln_mlp.weight": "pytorch_model-00010-of-00018.bin",
|
227 |
+
"transformer.h.33.mlp.dense_4h_to_h.weight": "pytorch_model-00010-of-00018.bin",
|
228 |
+
"transformer.h.33.mlp.dense_h_to_4h.weight": "pytorch_model-00010-of-00018.bin",
|
229 |
+
"transformer.h.33.self_attention.dense.weight": "pytorch_model-00010-of-00018.bin",
|
230 |
+
"transformer.h.33.self_attention.query_key_value.weight": "pytorch_model-00010-of-00018.bin",
|
231 |
+
"transformer.h.34.ln_attn.bias": "pytorch_model-00010-of-00018.bin",
|
232 |
+
"transformer.h.34.ln_attn.weight": "pytorch_model-00010-of-00018.bin",
|
233 |
+
"transformer.h.34.ln_mlp.bias": "pytorch_model-00010-of-00018.bin",
|
234 |
+
"transformer.h.34.ln_mlp.weight": "pytorch_model-00010-of-00018.bin",
|
235 |
+
"transformer.h.34.mlp.dense_4h_to_h.weight": "pytorch_model-00011-of-00018.bin",
|
236 |
+
"transformer.h.34.mlp.dense_h_to_4h.weight": "pytorch_model-00011-of-00018.bin",
|
237 |
+
"transformer.h.34.self_attention.dense.weight": "pytorch_model-00010-of-00018.bin",
|
238 |
+
"transformer.h.34.self_attention.query_key_value.weight": "pytorch_model-00010-of-00018.bin",
|
239 |
+
"transformer.h.35.ln_attn.bias": "pytorch_model-00011-of-00018.bin",
|
240 |
+
"transformer.h.35.ln_attn.weight": "pytorch_model-00011-of-00018.bin",
|
241 |
+
"transformer.h.35.ln_mlp.bias": "pytorch_model-00011-of-00018.bin",
|
242 |
+
"transformer.h.35.ln_mlp.weight": "pytorch_model-00011-of-00018.bin",
|
243 |
+
"transformer.h.35.mlp.dense_4h_to_h.weight": "pytorch_model-00011-of-00018.bin",
|
244 |
+
"transformer.h.35.mlp.dense_h_to_4h.weight": "pytorch_model-00011-of-00018.bin",
|
245 |
+
"transformer.h.35.self_attention.dense.weight": "pytorch_model-00011-of-00018.bin",
|
246 |
+
"transformer.h.35.self_attention.query_key_value.weight": "pytorch_model-00011-of-00018.bin",
|
247 |
+
"transformer.h.36.ln_attn.bias": "pytorch_model-00011-of-00018.bin",
|
248 |
+
"transformer.h.36.ln_attn.weight": "pytorch_model-00011-of-00018.bin",
|
249 |
+
"transformer.h.36.ln_mlp.bias": "pytorch_model-00011-of-00018.bin",
|
250 |
+
"transformer.h.36.ln_mlp.weight": "pytorch_model-00011-of-00018.bin",
|
251 |
+
"transformer.h.36.mlp.dense_4h_to_h.weight": "pytorch_model-00011-of-00018.bin",
|
252 |
+
"transformer.h.36.mlp.dense_h_to_4h.weight": "pytorch_model-00011-of-00018.bin",
|
253 |
+
"transformer.h.36.self_attention.dense.weight": "pytorch_model-00011-of-00018.bin",
|
254 |
+
"transformer.h.36.self_attention.query_key_value.weight": "pytorch_model-00011-of-00018.bin",
|
255 |
+
"transformer.h.37.ln_attn.bias": "pytorch_model-00011-of-00018.bin",
|
256 |
+
"transformer.h.37.ln_attn.weight": "pytorch_model-00011-of-00018.bin",
|
257 |
+
"transformer.h.37.ln_mlp.bias": "pytorch_model-00011-of-00018.bin",
|
258 |
+
"transformer.h.37.ln_mlp.weight": "pytorch_model-00011-of-00018.bin",
|
259 |
+
"transformer.h.37.mlp.dense_4h_to_h.weight": "pytorch_model-00012-of-00018.bin",
|
260 |
+
"transformer.h.37.mlp.dense_h_to_4h.weight": "pytorch_model-00011-of-00018.bin",
|
261 |
+
"transformer.h.37.self_attention.dense.weight": "pytorch_model-00011-of-00018.bin",
|
262 |
+
"transformer.h.37.self_attention.query_key_value.weight": "pytorch_model-00011-of-00018.bin",
|
263 |
+
"transformer.h.38.ln_attn.bias": "pytorch_model-00012-of-00018.bin",
|
264 |
+
"transformer.h.38.ln_attn.weight": "pytorch_model-00012-of-00018.bin",
|
265 |
+
"transformer.h.38.ln_mlp.bias": "pytorch_model-00012-of-00018.bin",
|
266 |
+
"transformer.h.38.ln_mlp.weight": "pytorch_model-00012-of-00018.bin",
|
267 |
+
"transformer.h.38.mlp.dense_4h_to_h.weight": "pytorch_model-00012-of-00018.bin",
|
268 |
+
"transformer.h.38.mlp.dense_h_to_4h.weight": "pytorch_model-00012-of-00018.bin",
|
269 |
+
"transformer.h.38.self_attention.dense.weight": "pytorch_model-00012-of-00018.bin",
|
270 |
+
"transformer.h.38.self_attention.query_key_value.weight": "pytorch_model-00012-of-00018.bin",
|
271 |
+
"transformer.h.39.ln_attn.bias": "pytorch_model-00012-of-00018.bin",
|
272 |
+
"transformer.h.39.ln_attn.weight": "pytorch_model-00012-of-00018.bin",
|
273 |
+
"transformer.h.39.ln_mlp.bias": "pytorch_model-00012-of-00018.bin",
|
274 |
+
"transformer.h.39.ln_mlp.weight": "pytorch_model-00012-of-00018.bin",
|
275 |
+
"transformer.h.39.mlp.dense_4h_to_h.weight": "pytorch_model-00012-of-00018.bin",
|
276 |
+
"transformer.h.39.mlp.dense_h_to_4h.weight": "pytorch_model-00012-of-00018.bin",
|
277 |
+
"transformer.h.39.self_attention.dense.weight": "pytorch_model-00012-of-00018.bin",
|
278 |
+
"transformer.h.39.self_attention.query_key_value.weight": "pytorch_model-00012-of-00018.bin",
|
279 |
+
"transformer.h.4.ln_attn.bias": "pytorch_model-00002-of-00018.bin",
|
280 |
+
"transformer.h.4.ln_attn.weight": "pytorch_model-00002-of-00018.bin",
|
281 |
+
"transformer.h.4.ln_mlp.bias": "pytorch_model-00002-of-00018.bin",
|
282 |
+
"transformer.h.4.ln_mlp.weight": "pytorch_model-00002-of-00018.bin",
|
283 |
+
"transformer.h.4.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00018.bin",
|
284 |
+
"transformer.h.4.mlp.dense_h_to_4h.weight": "pytorch_model-00002-of-00018.bin",
|
285 |
+
"transformer.h.4.self_attention.dense.weight": "pytorch_model-00002-of-00018.bin",
|
286 |
+
"transformer.h.4.self_attention.query_key_value.weight": "pytorch_model-00002-of-00018.bin",
|
287 |
+
"transformer.h.40.ln_attn.bias": "pytorch_model-00012-of-00018.bin",
|
288 |
+
"transformer.h.40.ln_attn.weight": "pytorch_model-00012-of-00018.bin",
|
289 |
+
"transformer.h.40.ln_mlp.bias": "pytorch_model-00012-of-00018.bin",
|
290 |
+
"transformer.h.40.ln_mlp.weight": "pytorch_model-00012-of-00018.bin",
|
291 |
+
"transformer.h.40.mlp.dense_4h_to_h.weight": "pytorch_model-00012-of-00018.bin",
|
292 |
+
"transformer.h.40.mlp.dense_h_to_4h.weight": "pytorch_model-00012-of-00018.bin",
|
293 |
+
"transformer.h.40.self_attention.dense.weight": "pytorch_model-00012-of-00018.bin",
|
294 |
+
"transformer.h.40.self_attention.query_key_value.weight": "pytorch_model-00012-of-00018.bin",
|
295 |
+
"transformer.h.41.ln_attn.bias": "pytorch_model-00012-of-00018.bin",
|
296 |
+
"transformer.h.41.ln_attn.weight": "pytorch_model-00012-of-00018.bin",
|
297 |
+
"transformer.h.41.ln_mlp.bias": "pytorch_model-00012-of-00018.bin",
|
298 |
+
"transformer.h.41.ln_mlp.weight": "pytorch_model-00012-of-00018.bin",
|
299 |
+
"transformer.h.41.mlp.dense_4h_to_h.weight": "pytorch_model-00013-of-00018.bin",
|
300 |
+
"transformer.h.41.mlp.dense_h_to_4h.weight": "pytorch_model-00013-of-00018.bin",
|
301 |
+
"transformer.h.41.self_attention.dense.weight": "pytorch_model-00012-of-00018.bin",
|
302 |
+
"transformer.h.41.self_attention.query_key_value.weight": "pytorch_model-00012-of-00018.bin",
|
303 |
+
"transformer.h.42.ln_attn.bias": "pytorch_model-00013-of-00018.bin",
|
304 |
+
"transformer.h.42.ln_attn.weight": "pytorch_model-00013-of-00018.bin",
|
305 |
+
"transformer.h.42.ln_mlp.bias": "pytorch_model-00013-of-00018.bin",
|
306 |
+
"transformer.h.42.ln_mlp.weight": "pytorch_model-00013-of-00018.bin",
|
307 |
+
"transformer.h.42.mlp.dense_4h_to_h.weight": "pytorch_model-00013-of-00018.bin",
|
308 |
+
"transformer.h.42.mlp.dense_h_to_4h.weight": "pytorch_model-00013-of-00018.bin",
|
309 |
+
"transformer.h.42.self_attention.dense.weight": "pytorch_model-00013-of-00018.bin",
|
310 |
+
"transformer.h.42.self_attention.query_key_value.weight": "pytorch_model-00013-of-00018.bin",
|
311 |
+
"transformer.h.43.ln_attn.bias": "pytorch_model-00013-of-00018.bin",
|
312 |
+
"transformer.h.43.ln_attn.weight": "pytorch_model-00013-of-00018.bin",
|
313 |
+
"transformer.h.43.ln_mlp.bias": "pytorch_model-00013-of-00018.bin",
|
314 |
+
"transformer.h.43.ln_mlp.weight": "pytorch_model-00013-of-00018.bin",
|
315 |
+
"transformer.h.43.mlp.dense_4h_to_h.weight": "pytorch_model-00013-of-00018.bin",
|
316 |
+
"transformer.h.43.mlp.dense_h_to_4h.weight": "pytorch_model-00013-of-00018.bin",
|
317 |
+
"transformer.h.43.self_attention.dense.weight": "pytorch_model-00013-of-00018.bin",
|
318 |
+
"transformer.h.43.self_attention.query_key_value.weight": "pytorch_model-00013-of-00018.bin",
|
319 |
+
"transformer.h.44.ln_attn.bias": "pytorch_model-00013-of-00018.bin",
|
320 |
+
"transformer.h.44.ln_attn.weight": "pytorch_model-00013-of-00018.bin",
|
321 |
+
"transformer.h.44.ln_mlp.bias": "pytorch_model-00013-of-00018.bin",
|
322 |
+
"transformer.h.44.ln_mlp.weight": "pytorch_model-00013-of-00018.bin",
|
323 |
+
"transformer.h.44.mlp.dense_4h_to_h.weight": "pytorch_model-00014-of-00018.bin",
|
324 |
+
"transformer.h.44.mlp.dense_h_to_4h.weight": "pytorch_model-00013-of-00018.bin",
|
325 |
+
"transformer.h.44.self_attention.dense.weight": "pytorch_model-00013-of-00018.bin",
|
326 |
+
"transformer.h.44.self_attention.query_key_value.weight": "pytorch_model-00013-of-00018.bin",
|
327 |
+
"transformer.h.45.ln_attn.bias": "pytorch_model-00014-of-00018.bin",
|
328 |
+
"transformer.h.45.ln_attn.weight": "pytorch_model-00014-of-00018.bin",
|
329 |
+
"transformer.h.45.ln_mlp.bias": "pytorch_model-00014-of-00018.bin",
|
330 |
+
"transformer.h.45.ln_mlp.weight": "pytorch_model-00014-of-00018.bin",
|
331 |
+
"transformer.h.45.mlp.dense_4h_to_h.weight": "pytorch_model-00014-of-00018.bin",
|
332 |
+
"transformer.h.45.mlp.dense_h_to_4h.weight": "pytorch_model-00014-of-00018.bin",
|
333 |
+
"transformer.h.45.self_attention.dense.weight": "pytorch_model-00014-of-00018.bin",
|
334 |
+
"transformer.h.45.self_attention.query_key_value.weight": "pytorch_model-00014-of-00018.bin",
|
335 |
+
"transformer.h.46.ln_attn.bias": "pytorch_model-00014-of-00018.bin",
|
336 |
+
"transformer.h.46.ln_attn.weight": "pytorch_model-00014-of-00018.bin",
|
337 |
+
"transformer.h.46.ln_mlp.bias": "pytorch_model-00014-of-00018.bin",
|
338 |
+
"transformer.h.46.ln_mlp.weight": "pytorch_model-00014-of-00018.bin",
|
339 |
+
"transformer.h.46.mlp.dense_4h_to_h.weight": "pytorch_model-00014-of-00018.bin",
|
340 |
+
"transformer.h.46.mlp.dense_h_to_4h.weight": "pytorch_model-00014-of-00018.bin",
|
341 |
+
"transformer.h.46.self_attention.dense.weight": "pytorch_model-00014-of-00018.bin",
|
342 |
+
"transformer.h.46.self_attention.query_key_value.weight": "pytorch_model-00014-of-00018.bin",
|
343 |
+
"transformer.h.47.ln_attn.bias": "pytorch_model-00014-of-00018.bin",
|
344 |
+
"transformer.h.47.ln_attn.weight": "pytorch_model-00014-of-00018.bin",
|
345 |
+
"transformer.h.47.ln_mlp.bias": "pytorch_model-00014-of-00018.bin",
|
346 |
+
"transformer.h.47.ln_mlp.weight": "pytorch_model-00014-of-00018.bin",
|
347 |
+
"transformer.h.47.mlp.dense_4h_to_h.weight": "pytorch_model-00014-of-00018.bin",
|
348 |
+
"transformer.h.47.mlp.dense_h_to_4h.weight": "pytorch_model-00014-of-00018.bin",
|
349 |
+
"transformer.h.47.self_attention.dense.weight": "pytorch_model-00014-of-00018.bin",
|
350 |
+
"transformer.h.47.self_attention.query_key_value.weight": "pytorch_model-00014-of-00018.bin",
|
351 |
+
"transformer.h.48.ln_attn.bias": "pytorch_model-00014-of-00018.bin",
|
352 |
+
"transformer.h.48.ln_attn.weight": "pytorch_model-00014-of-00018.bin",
|
353 |
+
"transformer.h.48.ln_mlp.bias": "pytorch_model-00014-of-00018.bin",
|
354 |
+
"transformer.h.48.ln_mlp.weight": "pytorch_model-00014-of-00018.bin",
|
355 |
+
"transformer.h.48.mlp.dense_4h_to_h.weight": "pytorch_model-00015-of-00018.bin",
|
356 |
+
"transformer.h.48.mlp.dense_h_to_4h.weight": "pytorch_model-00015-of-00018.bin",
|
357 |
+
"transformer.h.48.self_attention.dense.weight": "pytorch_model-00014-of-00018.bin",
|
358 |
+
"transformer.h.48.self_attention.query_key_value.weight": "pytorch_model-00014-of-00018.bin",
|
359 |
+
"transformer.h.49.ln_attn.bias": "pytorch_model-00015-of-00018.bin",
|
360 |
+
"transformer.h.49.ln_attn.weight": "pytorch_model-00015-of-00018.bin",
|
361 |
+
"transformer.h.49.ln_mlp.bias": "pytorch_model-00015-of-00018.bin",
|
362 |
+
"transformer.h.49.ln_mlp.weight": "pytorch_model-00015-of-00018.bin",
|
363 |
+
"transformer.h.49.mlp.dense_4h_to_h.weight": "pytorch_model-00015-of-00018.bin",
|
364 |
+
"transformer.h.49.mlp.dense_h_to_4h.weight": "pytorch_model-00015-of-00018.bin",
|
365 |
+
"transformer.h.49.self_attention.dense.weight": "pytorch_model-00015-of-00018.bin",
|
366 |
+
"transformer.h.49.self_attention.query_key_value.weight": "pytorch_model-00015-of-00018.bin",
|
367 |
+
"transformer.h.5.ln_attn.bias": "pytorch_model-00002-of-00018.bin",
|
368 |
+
"transformer.h.5.ln_attn.weight": "pytorch_model-00002-of-00018.bin",
|
369 |
+
"transformer.h.5.ln_mlp.bias": "pytorch_model-00002-of-00018.bin",
|
370 |
+
"transformer.h.5.ln_mlp.weight": "pytorch_model-00002-of-00018.bin",
|
371 |
+
"transformer.h.5.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00018.bin",
|
372 |
+
"transformer.h.5.mlp.dense_h_to_4h.weight": "pytorch_model-00002-of-00018.bin",
|
373 |
+
"transformer.h.5.self_attention.dense.weight": "pytorch_model-00002-of-00018.bin",
|
374 |
+
"transformer.h.5.self_attention.query_key_value.weight": "pytorch_model-00002-of-00018.bin",
|
375 |
+
"transformer.h.50.ln_attn.bias": "pytorch_model-00015-of-00018.bin",
|
376 |
+
"transformer.h.50.ln_attn.weight": "pytorch_model-00015-of-00018.bin",
|
377 |
+
"transformer.h.50.ln_mlp.bias": "pytorch_model-00015-of-00018.bin",
|
378 |
+
"transformer.h.50.ln_mlp.weight": "pytorch_model-00015-of-00018.bin",
|
379 |
+
"transformer.h.50.mlp.dense_4h_to_h.weight": "pytorch_model-00015-of-00018.bin",
|
380 |
+
"transformer.h.50.mlp.dense_h_to_4h.weight": "pytorch_model-00015-of-00018.bin",
|
381 |
+
"transformer.h.50.self_attention.dense.weight": "pytorch_model-00015-of-00018.bin",
|
382 |
+
"transformer.h.50.self_attention.query_key_value.weight": "pytorch_model-00015-of-00018.bin",
|
383 |
+
"transformer.h.51.ln_attn.bias": "pytorch_model-00015-of-00018.bin",
|
384 |
+
"transformer.h.51.ln_attn.weight": "pytorch_model-00015-of-00018.bin",
|
385 |
+
"transformer.h.51.ln_mlp.bias": "pytorch_model-00015-of-00018.bin",
|
386 |
+
"transformer.h.51.ln_mlp.weight": "pytorch_model-00015-of-00018.bin",
|
387 |
+
"transformer.h.51.mlp.dense_4h_to_h.weight": "pytorch_model-00016-of-00018.bin",
|
388 |
+
"transformer.h.51.mlp.dense_h_to_4h.weight": "pytorch_model-00015-of-00018.bin",
|
389 |
+
"transformer.h.51.self_attention.dense.weight": "pytorch_model-00015-of-00018.bin",
|
390 |
+
"transformer.h.51.self_attention.query_key_value.weight": "pytorch_model-00015-of-00018.bin",
|
391 |
+
"transformer.h.52.ln_attn.bias": "pytorch_model-00016-of-00018.bin",
|
392 |
+
"transformer.h.52.ln_attn.weight": "pytorch_model-00016-of-00018.bin",
|
393 |
+
"transformer.h.52.ln_mlp.bias": "pytorch_model-00016-of-00018.bin",
|
394 |
+
"transformer.h.52.ln_mlp.weight": "pytorch_model-00016-of-00018.bin",
|
395 |
+
"transformer.h.52.mlp.dense_4h_to_h.weight": "pytorch_model-00016-of-00018.bin",
|
396 |
+
"transformer.h.52.mlp.dense_h_to_4h.weight": "pytorch_model-00016-of-00018.bin",
|
397 |
+
"transformer.h.52.self_attention.dense.weight": "pytorch_model-00016-of-00018.bin",
|
398 |
+
"transformer.h.52.self_attention.query_key_value.weight": "pytorch_model-00016-of-00018.bin",
|
399 |
+
"transformer.h.53.ln_attn.bias": "pytorch_model-00016-of-00018.bin",
|
400 |
+
"transformer.h.53.ln_attn.weight": "pytorch_model-00016-of-00018.bin",
|
401 |
+
"transformer.h.53.ln_mlp.bias": "pytorch_model-00016-of-00018.bin",
|
402 |
+
"transformer.h.53.ln_mlp.weight": "pytorch_model-00016-of-00018.bin",
|
403 |
+
"transformer.h.53.mlp.dense_4h_to_h.weight": "pytorch_model-00016-of-00018.bin",
|
404 |
+
"transformer.h.53.mlp.dense_h_to_4h.weight": "pytorch_model-00016-of-00018.bin",
|
405 |
+
"transformer.h.53.self_attention.dense.weight": "pytorch_model-00016-of-00018.bin",
|
406 |
+
"transformer.h.53.self_attention.query_key_value.weight": "pytorch_model-00016-of-00018.bin",
|
407 |
+
"transformer.h.54.ln_attn.bias": "pytorch_model-00016-of-00018.bin",
|
408 |
+
"transformer.h.54.ln_attn.weight": "pytorch_model-00016-of-00018.bin",
|
409 |
+
"transformer.h.54.ln_mlp.bias": "pytorch_model-00016-of-00018.bin",
|
410 |
+
"transformer.h.54.ln_mlp.weight": "pytorch_model-00016-of-00018.bin",
|
411 |
+
"transformer.h.54.mlp.dense_4h_to_h.weight": "pytorch_model-00016-of-00018.bin",
|
412 |
+
"transformer.h.54.mlp.dense_h_to_4h.weight": "pytorch_model-00016-of-00018.bin",
|
413 |
+
"transformer.h.54.self_attention.dense.weight": "pytorch_model-00016-of-00018.bin",
|
414 |
+
"transformer.h.54.self_attention.query_key_value.weight": "pytorch_model-00016-of-00018.bin",
|
415 |
+
"transformer.h.55.ln_attn.bias": "pytorch_model-00016-of-00018.bin",
|
416 |
+
"transformer.h.55.ln_attn.weight": "pytorch_model-00016-of-00018.bin",
|
417 |
+
"transformer.h.55.ln_mlp.bias": "pytorch_model-00016-of-00018.bin",
|
418 |
+
"transformer.h.55.ln_mlp.weight": "pytorch_model-00016-of-00018.bin",
|
419 |
+
"transformer.h.55.mlp.dense_4h_to_h.weight": "pytorch_model-00017-of-00018.bin",
|
420 |
+
"transformer.h.55.mlp.dense_h_to_4h.weight": "pytorch_model-00017-of-00018.bin",
|
421 |
+
"transformer.h.55.self_attention.dense.weight": "pytorch_model-00016-of-00018.bin",
|
422 |
+
"transformer.h.55.self_attention.query_key_value.weight": "pytorch_model-00016-of-00018.bin",
|
423 |
+
"transformer.h.56.ln_attn.bias": "pytorch_model-00017-of-00018.bin",
|
424 |
+
"transformer.h.56.ln_attn.weight": "pytorch_model-00017-of-00018.bin",
|
425 |
+
"transformer.h.56.ln_mlp.bias": "pytorch_model-00017-of-00018.bin",
|
426 |
+
"transformer.h.56.ln_mlp.weight": "pytorch_model-00017-of-00018.bin",
|
427 |
+
"transformer.h.56.mlp.dense_4h_to_h.weight": "pytorch_model-00017-of-00018.bin",
|
428 |
+
"transformer.h.56.mlp.dense_h_to_4h.weight": "pytorch_model-00017-of-00018.bin",
|
429 |
+
"transformer.h.56.self_attention.dense.weight": "pytorch_model-00017-of-00018.bin",
|
430 |
+
"transformer.h.56.self_attention.query_key_value.weight": "pytorch_model-00017-of-00018.bin",
|
431 |
+
"transformer.h.57.ln_attn.bias": "pytorch_model-00017-of-00018.bin",
|
432 |
+
"transformer.h.57.ln_attn.weight": "pytorch_model-00017-of-00018.bin",
|
433 |
+
"transformer.h.57.ln_mlp.bias": "pytorch_model-00017-of-00018.bin",
|
434 |
+
"transformer.h.57.ln_mlp.weight": "pytorch_model-00017-of-00018.bin",
|
435 |
+
"transformer.h.57.mlp.dense_4h_to_h.weight": "pytorch_model-00017-of-00018.bin",
|
436 |
+
"transformer.h.57.mlp.dense_h_to_4h.weight": "pytorch_model-00017-of-00018.bin",
|
437 |
+
"transformer.h.57.self_attention.dense.weight": "pytorch_model-00017-of-00018.bin",
|
438 |
+
"transformer.h.57.self_attention.query_key_value.weight": "pytorch_model-00017-of-00018.bin",
|
439 |
+
"transformer.h.58.ln_attn.bias": "pytorch_model-00017-of-00018.bin",
|
440 |
+
"transformer.h.58.ln_attn.weight": "pytorch_model-00017-of-00018.bin",
|
441 |
+
"transformer.h.58.ln_mlp.bias": "pytorch_model-00017-of-00018.bin",
|
442 |
+
"transformer.h.58.ln_mlp.weight": "pytorch_model-00017-of-00018.bin",
|
443 |
+
"transformer.h.58.mlp.dense_4h_to_h.weight": "pytorch_model-00018-of-00018.bin",
|
444 |
+
"transformer.h.58.mlp.dense_h_to_4h.weight": "pytorch_model-00017-of-00018.bin",
|
445 |
+
"transformer.h.58.self_attention.dense.weight": "pytorch_model-00017-of-00018.bin",
|
446 |
+
"transformer.h.58.self_attention.query_key_value.weight": "pytorch_model-00017-of-00018.bin",
|
447 |
+
"transformer.h.59.ln_attn.bias": "pytorch_model-00018-of-00018.bin",
|
448 |
+
"transformer.h.59.ln_attn.weight": "pytorch_model-00018-of-00018.bin",
|
449 |
+
"transformer.h.59.ln_mlp.bias": "pytorch_model-00018-of-00018.bin",
|
450 |
+
"transformer.h.59.ln_mlp.weight": "pytorch_model-00018-of-00018.bin",
|
451 |
+
"transformer.h.59.mlp.dense_4h_to_h.weight": "pytorch_model-00018-of-00018.bin",
|
452 |
+
"transformer.h.59.mlp.dense_h_to_4h.weight": "pytorch_model-00018-of-00018.bin",
|
453 |
+
"transformer.h.59.self_attention.dense.weight": "pytorch_model-00018-of-00018.bin",
|
454 |
+
"transformer.h.59.self_attention.query_key_value.weight": "pytorch_model-00018-of-00018.bin",
|
455 |
+
"transformer.h.6.ln_attn.bias": "pytorch_model-00002-of-00018.bin",
|
456 |
+
"transformer.h.6.ln_attn.weight": "pytorch_model-00002-of-00018.bin",
|
457 |
+
"transformer.h.6.ln_mlp.bias": "pytorch_model-00002-of-00018.bin",
|
458 |
+
"transformer.h.6.ln_mlp.weight": "pytorch_model-00002-of-00018.bin",
|
459 |
+
"transformer.h.6.mlp.dense_4h_to_h.weight": "pytorch_model-00003-of-00018.bin",
|
460 |
+
"transformer.h.6.mlp.dense_h_to_4h.weight": "pytorch_model-00003-of-00018.bin",
|
461 |
+
"transformer.h.6.self_attention.dense.weight": "pytorch_model-00002-of-00018.bin",
|
462 |
+
"transformer.h.6.self_attention.query_key_value.weight": "pytorch_model-00002-of-00018.bin",
|
463 |
+
"transformer.h.7.ln_attn.bias": "pytorch_model-00003-of-00018.bin",
|
464 |
+
"transformer.h.7.ln_attn.weight": "pytorch_model-00003-of-00018.bin",
|
465 |
+
"transformer.h.7.ln_mlp.bias": "pytorch_model-00003-of-00018.bin",
|
466 |
+
"transformer.h.7.ln_mlp.weight": "pytorch_model-00003-of-00018.bin",
|
467 |
+
"transformer.h.7.mlp.dense_4h_to_h.weight": "pytorch_model-00003-of-00018.bin",
|
468 |
+
"transformer.h.7.mlp.dense_h_to_4h.weight": "pytorch_model-00003-of-00018.bin",
|
469 |
+
"transformer.h.7.self_attention.dense.weight": "pytorch_model-00003-of-00018.bin",
|
470 |
+
"transformer.h.7.self_attention.query_key_value.weight": "pytorch_model-00003-of-00018.bin",
|
471 |
+
"transformer.h.8.ln_attn.bias": "pytorch_model-00003-of-00018.bin",
|
472 |
+
"transformer.h.8.ln_attn.weight": "pytorch_model-00003-of-00018.bin",
|
473 |
+
"transformer.h.8.ln_mlp.bias": "pytorch_model-00003-of-00018.bin",
|
474 |
+
"transformer.h.8.ln_mlp.weight": "pytorch_model-00003-of-00018.bin",
|
475 |
+
"transformer.h.8.mlp.dense_4h_to_h.weight": "pytorch_model-00003-of-00018.bin",
|
476 |
+
"transformer.h.8.mlp.dense_h_to_4h.weight": "pytorch_model-00003-of-00018.bin",
|
477 |
+
"transformer.h.8.self_attention.dense.weight": "pytorch_model-00003-of-00018.bin",
|
478 |
+
"transformer.h.8.self_attention.query_key_value.weight": "pytorch_model-00003-of-00018.bin",
|
479 |
+
"transformer.h.9.ln_attn.bias": "pytorch_model-00003-of-00018.bin",
|
480 |
+
"transformer.h.9.ln_attn.weight": "pytorch_model-00003-of-00018.bin",
|
481 |
+
"transformer.h.9.ln_mlp.bias": "pytorch_model-00003-of-00018.bin",
|
482 |
+
"transformer.h.9.ln_mlp.weight": "pytorch_model-00003-of-00018.bin",
|
483 |
+
"transformer.h.9.mlp.dense_4h_to_h.weight": "pytorch_model-00004-of-00018.bin",
|
484 |
+
"transformer.h.9.mlp.dense_h_to_4h.weight": "pytorch_model-00003-of-00018.bin",
|
485 |
+
"transformer.h.9.self_attention.dense.weight": "pytorch_model-00003-of-00018.bin",
|
486 |
+
"transformer.h.9.self_attention.query_key_value.weight": "pytorch_model-00003-of-00018.bin",
|
487 |
+
"transformer.ln_f.bias": "pytorch_model-00018-of-00018.bin",
|
488 |
+
"transformer.ln_f.weight": "pytorch_model-00018-of-00018.bin",
|
489 |
+
"transformer.word_embeddings.weight": "pytorch_model-00001-of-00018.bin"
|
490 |
+
}
|
491 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
">>TITLE<<",
|
4 |
+
">>ABSTRACT<<",
|
5 |
+
">>INTRODUCTION<<",
|
6 |
+
">>SUMMARY<<",
|
7 |
+
">>COMMENT<<",
|
8 |
+
">>ANSWER<<",
|
9 |
+
">>QUESTION<<",
|
10 |
+
">>DOMAIN<<",
|
11 |
+
">>PREFIX<<",
|
12 |
+
">>SUFFIX<<",
|
13 |
+
">>MIDDLE<<"
|
14 |
+
],
|
15 |
+
"eos_token": "<|endoftext|>",
|
16 |
+
"pad_token": "[PAD]"
|
17 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"clean_up_tokenization_spaces": true,
|
4 |
+
"eos_token": "<|endoftext|>",
|
5 |
+
"model_max_length": 2048,
|
6 |
+
"padding_side": "right",
|
7 |
+
"tokenizer_class": "PreTrainedTokenizerFast"
|
8 |
+
}
|
trainer_state.json
ADDED
@@ -0,0 +1,658 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"best_metric": null,
|
3 |
+
"best_model_checkpoint": null,
|
4 |
+
"epoch": 1.9930151338766007,
|
5 |
+
"global_step": 214,
|
6 |
+
"is_hyper_param_search": false,
|
7 |
+
"is_local_process_zero": true,
|
8 |
+
"is_world_process_zero": true,
|
9 |
+
"log_history": [
|
10 |
+
{
|
11 |
+
"epoch": 0.02,
|
12 |
+
"learning_rate": 2e-05,
|
13 |
+
"loss": 0.8616,
|
14 |
+
"step": 2
|
15 |
+
},
|
16 |
+
{
|
17 |
+
"epoch": 0.04,
|
18 |
+
"learning_rate": 1.9995608365087945e-05,
|
19 |
+
"loss": 0.7122,
|
20 |
+
"step": 4
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"epoch": 0.06,
|
24 |
+
"learning_rate": 1.9982437317643218e-05,
|
25 |
+
"loss": 0.6609,
|
26 |
+
"step": 6
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"epoch": 0.07,
|
30 |
+
"learning_rate": 1.996049842615217e-05,
|
31 |
+
"loss": 0.6289,
|
32 |
+
"step": 8
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"epoch": 0.09,
|
36 |
+
"learning_rate": 1.992981096013517e-05,
|
37 |
+
"loss": 0.6091,
|
38 |
+
"step": 10
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"epoch": 0.11,
|
42 |
+
"learning_rate": 1.9890401873221642e-05,
|
43 |
+
"loss": 0.5863,
|
44 |
+
"step": 12
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"epoch": 0.13,
|
48 |
+
"learning_rate": 1.984230577947597e-05,
|
49 |
+
"loss": 0.5834,
|
50 |
+
"step": 14
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"epoch": 0.15,
|
54 |
+
"learning_rate": 1.9785564922995042e-05,
|
55 |
+
"loss": 0.5628,
|
56 |
+
"step": 16
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"epoch": 0.17,
|
60 |
+
"learning_rate": 1.972022914080411e-05,
|
61 |
+
"loss": 0.5446,
|
62 |
+
"step": 18
|
63 |
+
},
|
64 |
+
{
|
65 |
+
"epoch": 0.19,
|
66 |
+
"learning_rate": 1.964635581908359e-05,
|
67 |
+
"loss": 0.5434,
|
68 |
+
"step": 20
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"epoch": 0.2,
|
72 |
+
"learning_rate": 1.9564009842765225e-05,
|
73 |
+
"loss": 0.5196,
|
74 |
+
"step": 22
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"epoch": 0.22,
|
78 |
+
"learning_rate": 1.9473263538541916e-05,
|
79 |
+
"loss": 0.5292,
|
80 |
+
"step": 24
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"epoch": 0.24,
|
84 |
+
"learning_rate": 1.9374196611341212e-05,
|
85 |
+
"loss": 0.5139,
|
86 |
+
"step": 26
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"epoch": 0.26,
|
90 |
+
"learning_rate": 1.9266896074318335e-05,
|
91 |
+
"loss": 0.5088,
|
92 |
+
"step": 28
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"epoch": 0.28,
|
96 |
+
"learning_rate": 1.9151456172430186e-05,
|
97 |
+
"loss": 0.5079,
|
98 |
+
"step": 30
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"epoch": 0.3,
|
102 |
+
"learning_rate": 1.9027978299657436e-05,
|
103 |
+
"loss": 0.5086,
|
104 |
+
"step": 32
|
105 |
+
},
|
106 |
+
{
|
107 |
+
"epoch": 0.32,
|
108 |
+
"learning_rate": 1.8896570909947477e-05,
|
109 |
+
"loss": 0.5024,
|
110 |
+
"step": 34
|
111 |
+
},
|
112 |
+
{
|
113 |
+
"epoch": 0.34,
|
114 |
+
"learning_rate": 1.875734942195637e-05,
|
115 |
+
"loss": 0.5046,
|
116 |
+
"step": 36
|
117 |
+
},
|
118 |
+
{
|
119 |
+
"epoch": 0.35,
|
120 |
+
"learning_rate": 1.8610436117673557e-05,
|
121 |
+
"loss": 0.4777,
|
122 |
+
"step": 38
|
123 |
+
},
|
124 |
+
{
|
125 |
+
"epoch": 0.37,
|
126 |
+
"learning_rate": 1.845596003501826e-05,
|
127 |
+
"loss": 0.5006,
|
128 |
+
"step": 40
|
129 |
+
},
|
130 |
+
{
|
131 |
+
"epoch": 0.39,
|
132 |
+
"learning_rate": 1.829405685450202e-05,
|
133 |
+
"loss": 0.4796,
|
134 |
+
"step": 42
|
135 |
+
},
|
136 |
+
{
|
137 |
+
"epoch": 0.41,
|
138 |
+
"learning_rate": 1.8124868780056814e-05,
|
139 |
+
"loss": 0.4701,
|
140 |
+
"step": 44
|
141 |
+
},
|
142 |
+
{
|
143 |
+
"epoch": 0.43,
|
144 |
+
"learning_rate": 1.7948544414133534e-05,
|
145 |
+
"loss": 0.4784,
|
146 |
+
"step": 46
|
147 |
+
},
|
148 |
+
{
|
149 |
+
"epoch": 0.45,
|
150 |
+
"learning_rate": 1.7765238627180424e-05,
|
151 |
+
"loss": 0.4773,
|
152 |
+
"step": 48
|
153 |
+
},
|
154 |
+
{
|
155 |
+
"epoch": 0.47,
|
156 |
+
"learning_rate": 1.7575112421616203e-05,
|
157 |
+
"loss": 0.4783,
|
158 |
+
"step": 50
|
159 |
+
},
|
160 |
+
{
|
161 |
+
"epoch": 0.48,
|
162 |
+
"learning_rate": 1.7378332790417275e-05,
|
163 |
+
"loss": 0.4772,
|
164 |
+
"step": 52
|
165 |
+
},
|
166 |
+
{
|
167 |
+
"epoch": 0.5,
|
168 |
+
"learning_rate": 1.717507257044331e-05,
|
169 |
+
"loss": 0.4671,
|
170 |
+
"step": 54
|
171 |
+
},
|
172 |
+
{
|
173 |
+
"epoch": 0.52,
|
174 |
+
"learning_rate": 1.6965510290629973e-05,
|
175 |
+
"loss": 0.4716,
|
176 |
+
"step": 56
|
177 |
+
},
|
178 |
+
{
|
179 |
+
"epoch": 0.54,
|
180 |
+
"learning_rate": 1.6749830015182106e-05,
|
181 |
+
"loss": 0.4539,
|
182 |
+
"step": 58
|
183 |
+
},
|
184 |
+
{
|
185 |
+
"epoch": 0.56,
|
186 |
+
"learning_rate": 1.6528221181905217e-05,
|
187 |
+
"loss": 0.4613,
|
188 |
+
"step": 60
|
189 |
+
},
|
190 |
+
{
|
191 |
+
"epoch": 0.58,
|
192 |
+
"learning_rate": 1.6300878435817115e-05,
|
193 |
+
"loss": 0.4758,
|
194 |
+
"step": 62
|
195 |
+
},
|
196 |
+
{
|
197 |
+
"epoch": 0.6,
|
198 |
+
"learning_rate": 1.6068001458185934e-05,
|
199 |
+
"loss": 0.4623,
|
200 |
+
"step": 64
|
201 |
+
},
|
202 |
+
{
|
203 |
+
"epoch": 0.61,
|
204 |
+
"learning_rate": 1.5829794791144723e-05,
|
205 |
+
"loss": 0.4734,
|
206 |
+
"step": 66
|
207 |
+
},
|
208 |
+
{
|
209 |
+
"epoch": 0.63,
|
210 |
+
"learning_rate": 1.5586467658036526e-05,
|
211 |
+
"loss": 0.4512,
|
212 |
+
"step": 68
|
213 |
+
},
|
214 |
+
{
|
215 |
+
"epoch": 0.65,
|
216 |
+
"learning_rate": 1.533823377964791e-05,
|
217 |
+
"loss": 0.4713,
|
218 |
+
"step": 70
|
219 |
+
},
|
220 |
+
{
|
221 |
+
"epoch": 0.67,
|
222 |
+
"learning_rate": 1.5085311186492206e-05,
|
223 |
+
"loss": 0.4789,
|
224 |
+
"step": 72
|
225 |
+
},
|
226 |
+
{
|
227 |
+
"epoch": 0.69,
|
228 |
+
"learning_rate": 1.482792202730745e-05,
|
229 |
+
"loss": 0.5663,
|
230 |
+
"step": 74
|
231 |
+
},
|
232 |
+
{
|
233 |
+
"epoch": 0.71,
|
234 |
+
"learning_rate": 1.4566292373937133e-05,
|
235 |
+
"loss": 0.4551,
|
236 |
+
"step": 76
|
237 |
+
},
|
238 |
+
{
|
239 |
+
"epoch": 0.73,
|
240 |
+
"learning_rate": 1.4300652022765207e-05,
|
241 |
+
"loss": 0.461,
|
242 |
+
"step": 78
|
243 |
+
},
|
244 |
+
{
|
245 |
+
"epoch": 0.75,
|
246 |
+
"learning_rate": 1.4031234292879726e-05,
|
247 |
+
"loss": 0.4673,
|
248 |
+
"step": 80
|
249 |
+
},
|
250 |
+
{
|
251 |
+
"epoch": 0.76,
|
252 |
+
"learning_rate": 1.3758275821142382e-05,
|
253 |
+
"loss": 0.4589,
|
254 |
+
"step": 82
|
255 |
+
},
|
256 |
+
{
|
257 |
+
"epoch": 0.78,
|
258 |
+
"learning_rate": 1.348201635434399e-05,
|
259 |
+
"loss": 0.4495,
|
260 |
+
"step": 84
|
261 |
+
},
|
262 |
+
{
|
263 |
+
"epoch": 0.8,
|
264 |
+
"learning_rate": 1.3202698538628376e-05,
|
265 |
+
"loss": 0.4645,
|
266 |
+
"step": 86
|
267 |
+
},
|
268 |
+
{
|
269 |
+
"epoch": 0.82,
|
270 |
+
"learning_rate": 1.292056770636976e-05,
|
271 |
+
"loss": 0.4555,
|
272 |
+
"step": 88
|
273 |
+
},
|
274 |
+
{
|
275 |
+
"epoch": 0.84,
|
276 |
+
"learning_rate": 1.2635871660690677e-05,
|
277 |
+
"loss": 0.4464,
|
278 |
+
"step": 90
|
279 |
+
},
|
280 |
+
{
|
281 |
+
"epoch": 0.86,
|
282 |
+
"learning_rate": 1.234886045780984e-05,
|
283 |
+
"loss": 0.4646,
|
284 |
+
"step": 92
|
285 |
+
},
|
286 |
+
{
|
287 |
+
"epoch": 0.88,
|
288 |
+
"learning_rate": 1.2059786187410984e-05,
|
289 |
+
"loss": 0.4599,
|
290 |
+
"step": 94
|
291 |
+
},
|
292 |
+
{
|
293 |
+
"epoch": 0.89,
|
294 |
+
"learning_rate": 1.176890275122573e-05,
|
295 |
+
"loss": 0.4534,
|
296 |
+
"step": 96
|
297 |
+
},
|
298 |
+
{
|
299 |
+
"epoch": 0.91,
|
300 |
+
"learning_rate": 1.1476465640024814e-05,
|
301 |
+
"loss": 0.4744,
|
302 |
+
"step": 98
|
303 |
+
},
|
304 |
+
{
|
305 |
+
"epoch": 0.93,
|
306 |
+
"learning_rate": 1.1182731709213658e-05,
|
307 |
+
"loss": 0.4626,
|
308 |
+
"step": 100
|
309 |
+
},
|
310 |
+
{
|
311 |
+
"epoch": 0.95,
|
312 |
+
"learning_rate": 1.0887958953229349e-05,
|
313 |
+
"loss": 0.4407,
|
314 |
+
"step": 102
|
315 |
+
},
|
316 |
+
{
|
317 |
+
"epoch": 0.97,
|
318 |
+
"learning_rate": 1.0592406278937143e-05,
|
319 |
+
"loss": 0.452,
|
320 |
+
"step": 104
|
321 |
+
},
|
322 |
+
{
|
323 |
+
"epoch": 0.99,
|
324 |
+
"learning_rate": 1.0296333278225599e-05,
|
325 |
+
"loss": 0.4496,
|
326 |
+
"step": 106
|
327 |
+
},
|
328 |
+
{
|
329 |
+
"epoch": 1.01,
|
330 |
+
"learning_rate": 1e-05,
|
331 |
+
"loss": 0.4138,
|
332 |
+
"step": 108
|
333 |
+
},
|
334 |
+
{
|
335 |
+
"epoch": 1.02,
|
336 |
+
"learning_rate": 9.703666721774403e-06,
|
337 |
+
"loss": 0.2924,
|
338 |
+
"step": 110
|
339 |
+
},
|
340 |
+
{
|
341 |
+
"epoch": 1.04,
|
342 |
+
"learning_rate": 9.407593721062858e-06,
|
343 |
+
"loss": 0.3184,
|
344 |
+
"step": 112
|
345 |
+
},
|
346 |
+
{
|
347 |
+
"epoch": 1.06,
|
348 |
+
"learning_rate": 9.112041046770653e-06,
|
349 |
+
"loss": 0.2885,
|
350 |
+
"step": 114
|
351 |
+
},
|
352 |
+
{
|
353 |
+
"epoch": 1.08,
|
354 |
+
"learning_rate": 8.817268290786343e-06,
|
355 |
+
"loss": 0.2842,
|
356 |
+
"step": 116
|
357 |
+
},
|
358 |
+
{
|
359 |
+
"epoch": 1.1,
|
360 |
+
"learning_rate": 8.52353435997519e-06,
|
361 |
+
"loss": 0.2763,
|
362 |
+
"step": 118
|
363 |
+
},
|
364 |
+
{
|
365 |
+
"epoch": 1.12,
|
366 |
+
"learning_rate": 8.231097248774273e-06,
|
367 |
+
"loss": 0.2765,
|
368 |
+
"step": 120
|
369 |
+
},
|
370 |
+
{
|
371 |
+
"epoch": 1.14,
|
372 |
+
"learning_rate": 7.940213812589018e-06,
|
373 |
+
"loss": 0.2788,
|
374 |
+
"step": 122
|
375 |
+
},
|
376 |
+
{
|
377 |
+
"epoch": 1.15,
|
378 |
+
"learning_rate": 7.651139542190164e-06,
|
379 |
+
"loss": 0.2821,
|
380 |
+
"step": 124
|
381 |
+
},
|
382 |
+
{
|
383 |
+
"epoch": 1.17,
|
384 |
+
"learning_rate": 7.364128339309326e-06,
|
385 |
+
"loss": 0.2834,
|
386 |
+
"step": 126
|
387 |
+
},
|
388 |
+
{
|
389 |
+
"epoch": 1.19,
|
390 |
+
"learning_rate": 7.079432293630244e-06,
|
391 |
+
"loss": 0.2728,
|
392 |
+
"step": 128
|
393 |
+
},
|
394 |
+
{
|
395 |
+
"epoch": 1.21,
|
396 |
+
"learning_rate": 6.797301461371626e-06,
|
397 |
+
"loss": 0.274,
|
398 |
+
"step": 130
|
399 |
+
},
|
400 |
+
{
|
401 |
+
"epoch": 1.23,
|
402 |
+
"learning_rate": 6.517983645656014e-06,
|
403 |
+
"loss": 0.276,
|
404 |
+
"step": 132
|
405 |
+
},
|
406 |
+
{
|
407 |
+
"epoch": 1.25,
|
408 |
+
"learning_rate": 6.241724178857621e-06,
|
409 |
+
"loss": 0.2723,
|
410 |
+
"step": 134
|
411 |
+
},
|
412 |
+
{
|
413 |
+
"epoch": 1.27,
|
414 |
+
"learning_rate": 5.96876570712028e-06,
|
415 |
+
"loss": 0.2876,
|
416 |
+
"step": 136
|
417 |
+
},
|
418 |
+
{
|
419 |
+
"epoch": 1.29,
|
420 |
+
"learning_rate": 5.699347977234799e-06,
|
421 |
+
"loss": 0.2714,
|
422 |
+
"step": 138
|
423 |
+
},
|
424 |
+
{
|
425 |
+
"epoch": 1.3,
|
426 |
+
"learning_rate": 5.43370762606287e-06,
|
427 |
+
"loss": 0.2758,
|
428 |
+
"step": 140
|
429 |
+
},
|
430 |
+
{
|
431 |
+
"epoch": 1.32,
|
432 |
+
"learning_rate": 5.172077972692553e-06,
|
433 |
+
"loss": 0.2816,
|
434 |
+
"step": 142
|
435 |
+
},
|
436 |
+
{
|
437 |
+
"epoch": 1.34,
|
438 |
+
"learning_rate": 4.914688813507798e-06,
|
439 |
+
"loss": 0.2787,
|
440 |
+
"step": 144
|
441 |
+
},
|
442 |
+
{
|
443 |
+
"epoch": 1.36,
|
444 |
+
"learning_rate": 4.661766220352098e-06,
|
445 |
+
"loss": 0.2801,
|
446 |
+
"step": 146
|
447 |
+
},
|
448 |
+
{
|
449 |
+
"epoch": 1.38,
|
450 |
+
"learning_rate": 4.413532341963477e-06,
|
451 |
+
"loss": 0.271,
|
452 |
+
"step": 148
|
453 |
+
},
|
454 |
+
{
|
455 |
+
"epoch": 1.4,
|
456 |
+
"learning_rate": 4.170205208855281e-06,
|
457 |
+
"loss": 0.2708,
|
458 |
+
"step": 150
|
459 |
+
},
|
460 |
+
{
|
461 |
+
"epoch": 1.42,
|
462 |
+
"learning_rate": 3.931998541814069e-06,
|
463 |
+
"loss": 0.2728,
|
464 |
+
"step": 152
|
465 |
+
},
|
466 |
+
{
|
467 |
+
"epoch": 1.43,
|
468 |
+
"learning_rate": 3.6991215641828903e-06,
|
469 |
+
"loss": 0.2719,
|
470 |
+
"step": 154
|
471 |
+
},
|
472 |
+
{
|
473 |
+
"epoch": 1.45,
|
474 |
+
"learning_rate": 3.4717788180947855e-06,
|
475 |
+
"loss": 0.272,
|
476 |
+
"step": 156
|
477 |
+
},
|
478 |
+
{
|
479 |
+
"epoch": 1.47,
|
480 |
+
"learning_rate": 3.250169984817897e-06,
|
481 |
+
"loss": 0.2724,
|
482 |
+
"step": 158
|
483 |
+
},
|
484 |
+
{
|
485 |
+
"epoch": 1.49,
|
486 |
+
"learning_rate": 3.0344897093700333e-06,
|
487 |
+
"loss": 0.2744,
|
488 |
+
"step": 160
|
489 |
+
},
|
490 |
+
{
|
491 |
+
"epoch": 1.51,
|
492 |
+
"learning_rate": 2.8249274295566863e-06,
|
493 |
+
"loss": 0.2736,
|
494 |
+
"step": 162
|
495 |
+
},
|
496 |
+
{
|
497 |
+
"epoch": 1.53,
|
498 |
+
"learning_rate": 2.6216672095827267e-06,
|
499 |
+
"loss": 0.2681,
|
500 |
+
"step": 164
|
501 |
+
},
|
502 |
+
{
|
503 |
+
"epoch": 1.55,
|
504 |
+
"learning_rate": 2.424887578383799e-06,
|
505 |
+
"loss": 0.2703,
|
506 |
+
"step": 166
|
507 |
+
},
|
508 |
+
{
|
509 |
+
"epoch": 1.56,
|
510 |
+
"learning_rate": 2.234761372819577e-06,
|
511 |
+
"loss": 0.2649,
|
512 |
+
"step": 168
|
513 |
+
},
|
514 |
+
{
|
515 |
+
"epoch": 1.58,
|
516 |
+
"learning_rate": 2.0514555858664663e-06,
|
517 |
+
"loss": 0.2781,
|
518 |
+
"step": 170
|
519 |
+
},
|
520 |
+
{
|
521 |
+
"epoch": 1.6,
|
522 |
+
"learning_rate": 1.875131219943187e-06,
|
523 |
+
"loss": 0.2645,
|
524 |
+
"step": 172
|
525 |
+
},
|
526 |
+
{
|
527 |
+
"epoch": 1.62,
|
528 |
+
"learning_rate": 1.7059431454979825e-06,
|
529 |
+
"loss": 0.27,
|
530 |
+
"step": 174
|
531 |
+
},
|
532 |
+
{
|
533 |
+
"epoch": 1.64,
|
534 |
+
"learning_rate": 1.5440399649817384e-06,
|
535 |
+
"loss": 0.2683,
|
536 |
+
"step": 176
|
537 |
+
},
|
538 |
+
{
|
539 |
+
"epoch": 1.66,
|
540 |
+
"learning_rate": 1.3895638823264447e-06,
|
541 |
+
"loss": 0.2645,
|
542 |
+
"step": 178
|
543 |
+
},
|
544 |
+
{
|
545 |
+
"epoch": 1.68,
|
546 |
+
"learning_rate": 1.2426505780436326e-06,
|
547 |
+
"loss": 0.2712,
|
548 |
+
"step": 180
|
549 |
+
},
|
550 |
+
{
|
551 |
+
"epoch": 1.69,
|
552 |
+
"learning_rate": 1.1034290900525279e-06,
|
553 |
+
"loss": 0.2621,
|
554 |
+
"step": 182
|
555 |
+
},
|
556 |
+
{
|
557 |
+
"epoch": 1.71,
|
558 |
+
"learning_rate": 9.720217003425648e-07,
|
559 |
+
"loss": 0.268,
|
560 |
+
"step": 184
|
561 |
+
},
|
562 |
+
{
|
563 |
+
"epoch": 1.73,
|
564 |
+
"learning_rate": 8.485438275698154e-07,
|
565 |
+
"loss": 0.2641,
|
566 |
+
"step": 186
|
567 |
+
},
|
568 |
+
{
|
569 |
+
"epoch": 1.75,
|
570 |
+
"learning_rate": 7.331039256816664e-07,
|
571 |
+
"loss": 0.2623,
|
572 |
+
"step": 188
|
573 |
+
},
|
574 |
+
{
|
575 |
+
"epoch": 1.77,
|
576 |
+
"learning_rate": 6.258033886587911e-07,
|
577 |
+
"loss": 0.2714,
|
578 |
+
"step": 190
|
579 |
+
},
|
580 |
+
{
|
581 |
+
"epoch": 1.79,
|
582 |
+
"learning_rate": 5.267364614580861e-07,
|
583 |
+
"loss": 0.2723,
|
584 |
+
"step": 192
|
585 |
+
},
|
586 |
+
{
|
587 |
+
"epoch": 1.81,
|
588 |
+
"learning_rate": 4.359901572347758e-07,
|
589 |
+
"loss": 0.2611,
|
590 |
+
"step": 194
|
591 |
+
},
|
592 |
+
{
|
593 |
+
"epoch": 1.83,
|
594 |
+
"learning_rate": 3.5364418091641374e-07,
|
595 |
+
"loss": 0.2724,
|
596 |
+
"step": 196
|
597 |
+
},
|
598 |
+
{
|
599 |
+
"epoch": 1.84,
|
600 |
+
"learning_rate": 2.7977085919589253e-07,
|
601 |
+
"loss": 0.2738,
|
602 |
+
"step": 198
|
603 |
+
},
|
604 |
+
{
|
605 |
+
"epoch": 1.86,
|
606 |
+
"learning_rate": 2.1443507700495968e-07,
|
607 |
+
"loss": 0.2623,
|
608 |
+
"step": 200
|
609 |
+
},
|
610 |
+
{
|
611 |
+
"epoch": 1.88,
|
612 |
+
"learning_rate": 1.5769422052403172e-07,
|
613 |
+
"loss": 0.2695,
|
614 |
+
"step": 202
|
615 |
+
},
|
616 |
+
{
|
617 |
+
"epoch": 1.9,
|
618 |
+
"learning_rate": 1.0959812677835968e-07,
|
619 |
+
"loss": 0.2661,
|
620 |
+
"step": 204
|
621 |
+
},
|
622 |
+
{
|
623 |
+
"epoch": 1.92,
|
624 |
+
"learning_rate": 7.018903986483083e-08,
|
625 |
+
"loss": 0.2712,
|
626 |
+
"step": 206
|
627 |
+
},
|
628 |
+
{
|
629 |
+
"epoch": 1.94,
|
630 |
+
"learning_rate": 3.950157384783104e-08,
|
631 |
+
"loss": 0.2706,
|
632 |
+
"step": 208
|
633 |
+
},
|
634 |
+
{
|
635 |
+
"epoch": 1.96,
|
636 |
+
"learning_rate": 1.7562682356786488e-08,
|
637 |
+
"loss": 0.276,
|
638 |
+
"step": 210
|
639 |
+
},
|
640 |
+
{
|
641 |
+
"epoch": 1.97,
|
642 |
+
"learning_rate": 4.39163491205652e-09,
|
643 |
+
"loss": 0.2767,
|
644 |
+
"step": 212
|
645 |
+
},
|
646 |
+
{
|
647 |
+
"epoch": 1.99,
|
648 |
+
"learning_rate": 0.0,
|
649 |
+
"loss": 0.2624,
|
650 |
+
"step": 214
|
651 |
+
}
|
652 |
+
],
|
653 |
+
"max_steps": 214,
|
654 |
+
"num_train_epochs": 2,
|
655 |
+
"total_flos": 1536113535614976.0,
|
656 |
+
"trial_name": null,
|
657 |
+
"trial_params": null
|
658 |
+
}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fe7ade02010de890951f8d2a3a60933d8a512b39c7bdca5d9951b162a710a84e
|
3 |
+
size 5051
|
zero_to_fp32.py
ADDED
@@ -0,0 +1,584 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
# Copyright (c) Microsoft Corporation.
|
4 |
+
# SPDX-License-Identifier: Apache-2.0
|
5 |
+
|
6 |
+
# DeepSpeed Team
|
7 |
+
|
8 |
+
# This script extracts fp32 consolidated weights from a zero 2 and 3 DeepSpeed checkpoints. It gets
|
9 |
+
# copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
|
10 |
+
# the future. Once extracted, the weights don't require DeepSpeed and can be used in any
|
11 |
+
# application.
|
12 |
+
#
|
13 |
+
# example: python zero_to_fp32.py . pytorch_model.bin
|
14 |
+
|
15 |
+
import argparse
|
16 |
+
import torch
|
17 |
+
import glob
|
18 |
+
import math
|
19 |
+
import os
|
20 |
+
import re
|
21 |
+
from collections import OrderedDict
|
22 |
+
from dataclasses import dataclass
|
23 |
+
|
24 |
+
# while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
|
25 |
+
# DeepSpeed data structures it has to be available in the current python environment.
|
26 |
+
from deepspeed.utils import logger
|
27 |
+
from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
|
28 |
+
FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
|
29 |
+
FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
|
30 |
+
|
31 |
+
|
32 |
+
@dataclass
|
33 |
+
class zero_model_state:
|
34 |
+
buffers: dict()
|
35 |
+
param_shapes: dict()
|
36 |
+
shared_params: list
|
37 |
+
ds_version: int
|
38 |
+
frozen_param_shapes: dict()
|
39 |
+
frozen_param_fragments: dict()
|
40 |
+
|
41 |
+
|
42 |
+
debug = 0
|
43 |
+
|
44 |
+
# load to cpu
|
45 |
+
device = torch.device('cpu')
|
46 |
+
|
47 |
+
|
48 |
+
def atoi(text):
|
49 |
+
return int(text) if text.isdigit() else text
|
50 |
+
|
51 |
+
|
52 |
+
def natural_keys(text):
|
53 |
+
'''
|
54 |
+
alist.sort(key=natural_keys) sorts in human order
|
55 |
+
http://nedbatchelder.com/blog/200712/human_sorting.html
|
56 |
+
(See Toothy's implementation in the comments)
|
57 |
+
'''
|
58 |
+
return [atoi(c) for c in re.split(r'(\d+)', text)]
|
59 |
+
|
60 |
+
|
61 |
+
def get_model_state_file(checkpoint_dir, zero_stage):
|
62 |
+
if not os.path.isdir(checkpoint_dir):
|
63 |
+
raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
|
64 |
+
|
65 |
+
# there should be only one file
|
66 |
+
if zero_stage == 2:
|
67 |
+
file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
|
68 |
+
elif zero_stage == 3:
|
69 |
+
file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
|
70 |
+
|
71 |
+
if not os.path.exists(file):
|
72 |
+
raise FileNotFoundError(f"can't find model states file at '{file}'")
|
73 |
+
|
74 |
+
return file
|
75 |
+
|
76 |
+
|
77 |
+
def get_checkpoint_files(checkpoint_dir, glob_pattern):
|
78 |
+
# XXX: need to test that this simple glob rule works for multi-node setup too
|
79 |
+
ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
|
80 |
+
|
81 |
+
if len(ckpt_files) == 0:
|
82 |
+
raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
|
83 |
+
|
84 |
+
return ckpt_files
|
85 |
+
|
86 |
+
|
87 |
+
def get_optim_files(checkpoint_dir):
|
88 |
+
return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
|
89 |
+
|
90 |
+
|
91 |
+
def get_model_state_files(checkpoint_dir):
|
92 |
+
return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
|
93 |
+
|
94 |
+
|
95 |
+
def parse_model_states(files):
|
96 |
+
zero_model_states = []
|
97 |
+
for file in files:
|
98 |
+
state_dict = torch.load(file, map_location=device)
|
99 |
+
|
100 |
+
if BUFFER_NAMES not in state_dict:
|
101 |
+
raise ValueError(f"{file} is not a model state checkpoint")
|
102 |
+
buffer_names = state_dict[BUFFER_NAMES]
|
103 |
+
if debug:
|
104 |
+
print("Found buffers:", buffer_names)
|
105 |
+
|
106 |
+
# recover just the buffers while restoring them to fp32 if they were saved in fp16
|
107 |
+
buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
|
108 |
+
param_shapes = state_dict[PARAM_SHAPES]
|
109 |
+
|
110 |
+
# collect parameters that are included in param_shapes
|
111 |
+
param_names = []
|
112 |
+
for s in param_shapes:
|
113 |
+
for name in s.keys():
|
114 |
+
param_names.append(name)
|
115 |
+
|
116 |
+
# update with frozen parameters
|
117 |
+
frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
|
118 |
+
if frozen_param_shapes is not None:
|
119 |
+
if debug:
|
120 |
+
print(f"Found frozen_param_shapes: {frozen_param_shapes}")
|
121 |
+
param_names += list(frozen_param_shapes.keys())
|
122 |
+
|
123 |
+
# record shared parameters so that they can be recovered based on partners
|
124 |
+
# this is because such parameters holding reference only are not saved by optimizer
|
125 |
+
shared_params = []
|
126 |
+
for param in state_dict["module"]:
|
127 |
+
if param not in [*param_names, *buffer_names]:
|
128 |
+
for share_param in state_dict["module"]:
|
129 |
+
if (state_dict["module"][share_param].data_ptr() == state_dict["module"][param].data_ptr()
|
130 |
+
and share_param != param):
|
131 |
+
shared_params.append([param, share_param])
|
132 |
+
break
|
133 |
+
|
134 |
+
ds_version = state_dict.get(DS_VERSION, None)
|
135 |
+
|
136 |
+
frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
|
137 |
+
|
138 |
+
z_model_state = zero_model_state(buffers=buffers,
|
139 |
+
param_shapes=param_shapes,
|
140 |
+
shared_params=shared_params,
|
141 |
+
ds_version=ds_version,
|
142 |
+
frozen_param_shapes=frozen_param_shapes,
|
143 |
+
frozen_param_fragments=frozen_param_fragments)
|
144 |
+
zero_model_states.append(z_model_state)
|
145 |
+
|
146 |
+
return zero_model_states
|
147 |
+
|
148 |
+
|
149 |
+
def parse_optim_states(files, ds_checkpoint_dir):
|
150 |
+
|
151 |
+
total_files = len(files)
|
152 |
+
state_dicts = []
|
153 |
+
for f in files:
|
154 |
+
state_dicts.append(torch.load(f, map_location=device))
|
155 |
+
|
156 |
+
if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
|
157 |
+
raise ValueError(f"{files[0]} is not a zero checkpoint")
|
158 |
+
zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
|
159 |
+
world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
|
160 |
+
|
161 |
+
# For ZeRO-2 each param group can have different partition_count as data parallelism for expert
|
162 |
+
# parameters can be different from data parallelism for non-expert parameters. So we can just
|
163 |
+
# use the max of the partition_count to get the dp world_size.
|
164 |
+
|
165 |
+
if type(world_size) is list:
|
166 |
+
world_size = max(world_size)
|
167 |
+
|
168 |
+
if world_size != total_files:
|
169 |
+
raise ValueError(
|
170 |
+
f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
|
171 |
+
"Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
|
172 |
+
)
|
173 |
+
|
174 |
+
# the groups are named differently in each stage
|
175 |
+
if zero_stage == 2:
|
176 |
+
fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
|
177 |
+
elif zero_stage == 3:
|
178 |
+
fp32_groups_key = FP32_FLAT_GROUPS
|
179 |
+
else:
|
180 |
+
raise ValueError(f"unknown zero stage {zero_stage}")
|
181 |
+
|
182 |
+
if zero_stage == 2:
|
183 |
+
fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
|
184 |
+
elif zero_stage == 3:
|
185 |
+
# if there is more than one param group, there will be multiple flattened tensors - one
|
186 |
+
# flattened tensor per group - for simplicity merge them into a single tensor
|
187 |
+
#
|
188 |
+
# XXX: could make the script more memory efficient for when there are multiple groups - it
|
189 |
+
# will require matching the sub-lists of param_shapes for each param group flattened tensor
|
190 |
+
|
191 |
+
fp32_flat_groups = [
|
192 |
+
torch.cat(state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key], 0) for i in range(len(state_dicts))
|
193 |
+
]
|
194 |
+
|
195 |
+
return zero_stage, world_size, fp32_flat_groups
|
196 |
+
|
197 |
+
|
198 |
+
def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir):
|
199 |
+
"""
|
200 |
+
Returns fp32 state_dict reconstructed from ds checkpoint
|
201 |
+
|
202 |
+
Args:
|
203 |
+
- ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
|
204 |
+
|
205 |
+
"""
|
206 |
+
print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
|
207 |
+
|
208 |
+
optim_files = get_optim_files(ds_checkpoint_dir)
|
209 |
+
zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
|
210 |
+
print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
|
211 |
+
|
212 |
+
model_files = get_model_state_files(ds_checkpoint_dir)
|
213 |
+
|
214 |
+
zero_model_states = parse_model_states(model_files)
|
215 |
+
print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
|
216 |
+
|
217 |
+
if zero_stage == 2:
|
218 |
+
return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states)
|
219 |
+
elif zero_stage == 3:
|
220 |
+
return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states)
|
221 |
+
|
222 |
+
|
223 |
+
def _zero2_merge_frozen_params(state_dict, zero_model_states):
|
224 |
+
if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
|
225 |
+
return
|
226 |
+
|
227 |
+
frozen_param_shapes = zero_model_states[0].frozen_param_shapes
|
228 |
+
frozen_param_fragments = zero_model_states[0].frozen_param_fragments
|
229 |
+
|
230 |
+
if debug:
|
231 |
+
num_elem = sum(s.numel() for s in frozen_param_shapes.values())
|
232 |
+
print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
|
233 |
+
|
234 |
+
wanted_params = len(frozen_param_shapes)
|
235 |
+
wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
|
236 |
+
avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
|
237 |
+
print(f'Frozen params: Have {avail_numel} numels to process.')
|
238 |
+
print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
|
239 |
+
|
240 |
+
total_params = 0
|
241 |
+
total_numel = 0
|
242 |
+
for name, shape in frozen_param_shapes.items():
|
243 |
+
total_params += 1
|
244 |
+
unpartitioned_numel = shape.numel()
|
245 |
+
total_numel += unpartitioned_numel
|
246 |
+
|
247 |
+
state_dict[name] = frozen_param_fragments[name]
|
248 |
+
|
249 |
+
if debug:
|
250 |
+
print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
|
251 |
+
|
252 |
+
print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
|
253 |
+
|
254 |
+
|
255 |
+
def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
|
256 |
+
param_shapes = zero_model_states[0].param_shapes
|
257 |
+
|
258 |
+
# Reconstruction protocol:
|
259 |
+
#
|
260 |
+
# XXX: document this
|
261 |
+
|
262 |
+
if debug:
|
263 |
+
for i in range(world_size):
|
264 |
+
for j in range(len(fp32_flat_groups[0])):
|
265 |
+
print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
|
266 |
+
|
267 |
+
# XXX: memory usage doubles here (zero2)
|
268 |
+
num_param_groups = len(fp32_flat_groups[0])
|
269 |
+
merged_single_partition_of_fp32_groups = []
|
270 |
+
for i in range(num_param_groups):
|
271 |
+
merged_partitions = [sd[i] for sd in fp32_flat_groups]
|
272 |
+
full_single_fp32_vector = torch.cat(merged_partitions, 0)
|
273 |
+
merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
|
274 |
+
avail_numel = sum(
|
275 |
+
[full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
|
276 |
+
|
277 |
+
if debug:
|
278 |
+
wanted_params = sum([len(shapes) for shapes in param_shapes])
|
279 |
+
wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
|
280 |
+
# not asserting if there is a mismatch due to possible padding
|
281 |
+
print(f"Have {avail_numel} numels to process.")
|
282 |
+
print(f"Need {wanted_numel} numels in {wanted_params} params.")
|
283 |
+
|
284 |
+
# params
|
285 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
286 |
+
# out-of-core computing solution
|
287 |
+
total_numel = 0
|
288 |
+
total_params = 0
|
289 |
+
for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
|
290 |
+
offset = 0
|
291 |
+
avail_numel = full_single_fp32_vector.numel()
|
292 |
+
for name, shape in shapes.items():
|
293 |
+
|
294 |
+
unpartitioned_numel = shape.numel()
|
295 |
+
total_numel += unpartitioned_numel
|
296 |
+
total_params += 1
|
297 |
+
|
298 |
+
if debug:
|
299 |
+
print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
|
300 |
+
state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
|
301 |
+
offset += unpartitioned_numel
|
302 |
+
|
303 |
+
# Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
|
304 |
+
# avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
|
305 |
+
# paddings performed in the code it's almost impossible to predict the exact numbers w/o the
|
306 |
+
# live optimizer object, so we are checking that the numbers are within the right range
|
307 |
+
align_to = 2 * world_size
|
308 |
+
|
309 |
+
def zero2_align(x):
|
310 |
+
return align_to * math.ceil(x / align_to)
|
311 |
+
|
312 |
+
if debug:
|
313 |
+
print(f"original offset={offset}, avail_numel={avail_numel}")
|
314 |
+
|
315 |
+
offset = zero2_align(offset)
|
316 |
+
avail_numel = zero2_align(avail_numel)
|
317 |
+
|
318 |
+
if debug:
|
319 |
+
print(f"aligned offset={offset}, avail_numel={avail_numel}")
|
320 |
+
|
321 |
+
# Sanity check
|
322 |
+
if offset != avail_numel:
|
323 |
+
raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
324 |
+
|
325 |
+
print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
|
326 |
+
|
327 |
+
|
328 |
+
def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states):
|
329 |
+
state_dict = OrderedDict()
|
330 |
+
|
331 |
+
# buffers
|
332 |
+
buffers = zero_model_states[0].buffers
|
333 |
+
state_dict.update(buffers)
|
334 |
+
if debug:
|
335 |
+
print(f"added {len(buffers)} buffers")
|
336 |
+
|
337 |
+
_zero2_merge_frozen_params(state_dict, zero_model_states)
|
338 |
+
|
339 |
+
_zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
|
340 |
+
|
341 |
+
# recover shared parameters
|
342 |
+
for pair in zero_model_states[0].shared_params:
|
343 |
+
state_dict[pair[0]] = state_dict[pair[1]]
|
344 |
+
|
345 |
+
return state_dict
|
346 |
+
|
347 |
+
|
348 |
+
def zero3_partitioned_param_info(unpartitioned_numel, world_size):
|
349 |
+
remainder = unpartitioned_numel % world_size
|
350 |
+
padding_numel = (world_size - remainder) if remainder else 0
|
351 |
+
partitioned_numel = math.ceil(unpartitioned_numel / world_size)
|
352 |
+
return partitioned_numel, padding_numel
|
353 |
+
|
354 |
+
|
355 |
+
def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
|
356 |
+
if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
|
357 |
+
return
|
358 |
+
|
359 |
+
if debug:
|
360 |
+
for i in range(world_size):
|
361 |
+
num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
|
362 |
+
print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
|
363 |
+
|
364 |
+
frozen_param_shapes = zero_model_states[0].frozen_param_shapes
|
365 |
+
wanted_params = len(frozen_param_shapes)
|
366 |
+
wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
|
367 |
+
avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
|
368 |
+
print(f'Frozen params: Have {avail_numel} numels to process.')
|
369 |
+
print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
|
370 |
+
|
371 |
+
total_params = 0
|
372 |
+
total_numel = 0
|
373 |
+
for name, shape in zero_model_states[0].frozen_param_shapes.items():
|
374 |
+
total_params += 1
|
375 |
+
unpartitioned_numel = shape.numel()
|
376 |
+
total_numel += unpartitioned_numel
|
377 |
+
|
378 |
+
param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
|
379 |
+
state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
|
380 |
+
|
381 |
+
partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
|
382 |
+
|
383 |
+
if debug:
|
384 |
+
print(
|
385 |
+
f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
|
386 |
+
)
|
387 |
+
|
388 |
+
print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
|
389 |
+
|
390 |
+
|
391 |
+
def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
|
392 |
+
param_shapes = zero_model_states[0].param_shapes
|
393 |
+
avail_numel = fp32_flat_groups[0].numel() * world_size
|
394 |
+
# Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
|
395 |
+
# param, re-consolidating each param, while dealing with padding if any
|
396 |
+
|
397 |
+
# merge list of dicts, preserving order
|
398 |
+
param_shapes = {k: v for d in param_shapes for k, v in d.items()}
|
399 |
+
|
400 |
+
if debug:
|
401 |
+
for i in range(world_size):
|
402 |
+
print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
|
403 |
+
|
404 |
+
wanted_params = len(param_shapes)
|
405 |
+
wanted_numel = sum(shape.numel() for shape in param_shapes.values())
|
406 |
+
# not asserting if there is a mismatch due to possible padding
|
407 |
+
avail_numel = fp32_flat_groups[0].numel() * world_size
|
408 |
+
print(f"Trainable params: Have {avail_numel} numels to process.")
|
409 |
+
print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
|
410 |
+
|
411 |
+
# params
|
412 |
+
# XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
|
413 |
+
# out-of-core computing solution
|
414 |
+
offset = 0
|
415 |
+
total_numel = 0
|
416 |
+
total_params = 0
|
417 |
+
for name, shape in param_shapes.items():
|
418 |
+
|
419 |
+
unpartitioned_numel = shape.numel()
|
420 |
+
total_numel += unpartitioned_numel
|
421 |
+
total_params += 1
|
422 |
+
|
423 |
+
partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
|
424 |
+
|
425 |
+
if debug:
|
426 |
+
print(
|
427 |
+
f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
|
428 |
+
)
|
429 |
+
|
430 |
+
# XXX: memory usage doubles here
|
431 |
+
state_dict[name] = torch.cat(
|
432 |
+
tuple(fp32_flat_groups[i].narrow(0, offset, partitioned_numel) for i in range(world_size)),
|
433 |
+
0).narrow(0, 0, unpartitioned_numel).view(shape)
|
434 |
+
offset += partitioned_numel
|
435 |
+
|
436 |
+
offset *= world_size
|
437 |
+
|
438 |
+
# Sanity check
|
439 |
+
if offset != avail_numel:
|
440 |
+
raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
|
441 |
+
|
442 |
+
print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
|
443 |
+
|
444 |
+
|
445 |
+
def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states):
|
446 |
+
state_dict = OrderedDict()
|
447 |
+
|
448 |
+
# buffers
|
449 |
+
buffers = zero_model_states[0].buffers
|
450 |
+
state_dict.update(buffers)
|
451 |
+
if debug:
|
452 |
+
print(f"added {len(buffers)} buffers")
|
453 |
+
|
454 |
+
_zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
|
455 |
+
|
456 |
+
_zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
|
457 |
+
|
458 |
+
# recover shared parameters
|
459 |
+
for pair in zero_model_states[0].shared_params:
|
460 |
+
state_dict[pair[0]] = state_dict[pair[1]]
|
461 |
+
|
462 |
+
return state_dict
|
463 |
+
|
464 |
+
|
465 |
+
def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag=None):
|
466 |
+
"""
|
467 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
|
468 |
+
``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
|
469 |
+
via a model hub.
|
470 |
+
|
471 |
+
Args:
|
472 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder
|
473 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
|
474 |
+
|
475 |
+
Returns:
|
476 |
+
- pytorch ``state_dict``
|
477 |
+
|
478 |
+
Note: this approach may not work if your application doesn't have sufficient free CPU memory and
|
479 |
+
you may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
|
480 |
+
the checkpoint.
|
481 |
+
|
482 |
+
A typical usage might be ::
|
483 |
+
|
484 |
+
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
|
485 |
+
# do the training and checkpoint saving
|
486 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
|
487 |
+
model = model.cpu() # move to cpu
|
488 |
+
model.load_state_dict(state_dict)
|
489 |
+
# submit to model hub or save the model to share with others
|
490 |
+
|
491 |
+
In this example the ``model`` will no longer be usable in the deepspeed context of the same
|
492 |
+
application. i.e. you will need to re-initialize the deepspeed engine, since
|
493 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
494 |
+
|
495 |
+
If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
|
496 |
+
|
497 |
+
"""
|
498 |
+
if tag is None:
|
499 |
+
latest_path = os.path.join(checkpoint_dir, 'latest')
|
500 |
+
if os.path.isfile(latest_path):
|
501 |
+
with open(latest_path, 'r') as fd:
|
502 |
+
tag = fd.read().strip()
|
503 |
+
else:
|
504 |
+
raise ValueError(f"Unable to find 'latest' file at {latest_path}")
|
505 |
+
|
506 |
+
ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
|
507 |
+
|
508 |
+
if not os.path.isdir(ds_checkpoint_dir):
|
509 |
+
raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
|
510 |
+
|
511 |
+
return _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir)
|
512 |
+
|
513 |
+
|
514 |
+
def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir, output_file, tag=None):
|
515 |
+
"""
|
516 |
+
Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
|
517 |
+
loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
|
518 |
+
|
519 |
+
Args:
|
520 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
521 |
+
- ``output_file``: path to the pytorch fp32 state_dict output file (e.g. path/pytorch_model.bin)
|
522 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
|
523 |
+
"""
|
524 |
+
|
525 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
|
526 |
+
print(f"Saving fp32 state dict to {output_file}")
|
527 |
+
torch.save(state_dict, output_file)
|
528 |
+
|
529 |
+
|
530 |
+
def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
|
531 |
+
"""
|
532 |
+
1. Put the provided model to cpu
|
533 |
+
2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
|
534 |
+
3. Load it into the provided model
|
535 |
+
|
536 |
+
Args:
|
537 |
+
- ``model``: the model object to update
|
538 |
+
- ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
|
539 |
+
- ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
|
540 |
+
|
541 |
+
Returns:
|
542 |
+
- ``model`: modified model
|
543 |
+
|
544 |
+
Make sure you have plenty of CPU memory available before you call this function. If you don't
|
545 |
+
have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
|
546 |
+
conveniently placed for you in the checkpoint folder.
|
547 |
+
|
548 |
+
A typical usage might be ::
|
549 |
+
|
550 |
+
from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
|
551 |
+
model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
|
552 |
+
# submit to model hub or save the model to share with others
|
553 |
+
|
554 |
+
Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
|
555 |
+
of the same application. i.e. you will need to re-initialize the deepspeed engine, since
|
556 |
+
``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
|
557 |
+
|
558 |
+
"""
|
559 |
+
logger.info(f"Extracting fp32 weights")
|
560 |
+
state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
|
561 |
+
|
562 |
+
logger.info(f"Overwriting model with fp32 weights")
|
563 |
+
model = model.cpu()
|
564 |
+
model.load_state_dict(state_dict, strict=False)
|
565 |
+
|
566 |
+
return model
|
567 |
+
|
568 |
+
|
569 |
+
if __name__ == "__main__":
|
570 |
+
|
571 |
+
parser = argparse.ArgumentParser()
|
572 |
+
parser.add_argument("checkpoint_dir",
|
573 |
+
type=str,
|
574 |
+
help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
|
575 |
+
parser.add_argument(
|
576 |
+
"output_file",
|
577 |
+
type=str,
|
578 |
+
help="path to the pytorch fp32 state_dict output file (e.g. path/checkpoint-12/pytorch_model.bin)")
|
579 |
+
parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
|
580 |
+
args = parser.parse_args()
|
581 |
+
|
582 |
+
debug = args.debug
|
583 |
+
|
584 |
+
convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir, args.output_file)
|