chienqian
commited on
Commit
•
578867d
1
Parent(s):
93b5486
init
Browse files- config.json +54 -0
- configuration_mistral.py +202 -0
- generation_config.json +6 -0
- model-00001-of-00004.safetensors +3 -0
- model-00002-of-00004.safetensors +3 -0
- model-00003-of-00004.safetensors +3 -0
- model-00004-of-00004.safetensors +3 -0
- model.safetensors.index.json +427 -0
- modeling_beacon.py +1143 -0
- modeling_mistral.py +1297 -0
- modeling_utils.py +711 -0
- special_tokens_map.json +24 -0
- tokenizer.json +0 -0
- tokenizer_config.json +44 -0
- trainer_state.json +2156 -0
- training_args.bin +3 -0
config.json
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "data/outputs/__mistral_1__",
|
3 |
+
"architectures": [
|
4 |
+
"MistralForCausalLM"
|
5 |
+
],
|
6 |
+
"auto_map": {
|
7 |
+
"AutoConfig": "configuration_mistral.MistralConfig",
|
8 |
+
"AutoModelForCausalLM": "modeling_mistral.MistralForCausalLM"
|
9 |
+
},
|
10 |
+
"attention_dropout": 0.0,
|
11 |
+
"beacon_attend_prev": false,
|
12 |
+
"beacon_attn": "step-expansion",
|
13 |
+
"beacon_embed_init": "eos",
|
14 |
+
"beacon_param": [
|
15 |
+
"q",
|
16 |
+
"k",
|
17 |
+
"v",
|
18 |
+
"o"
|
19 |
+
],
|
20 |
+
"beacon_ratio": [
|
21 |
+
2,
|
22 |
+
4,
|
23 |
+
8
|
24 |
+
],
|
25 |
+
"beacon_ratio_mix": "step-random",
|
26 |
+
"beacon_sink_size": 1,
|
27 |
+
"beacon_stride": 2048,
|
28 |
+
"beacon_window": 2048,
|
29 |
+
"beacon_pos": "append",
|
30 |
+
"bos_token_id": 1,
|
31 |
+
"eos_token_id": 2,
|
32 |
+
"hidden_act": "silu",
|
33 |
+
"hidden_size": 4096,
|
34 |
+
"initializer_range": 0.02,
|
35 |
+
"intermediate_size": 14336,
|
36 |
+
"max_position_embeddings": 32768,
|
37 |
+
"model_type": "mistral",
|
38 |
+
"num_attention_heads": 32,
|
39 |
+
"num_hidden_layers": 32,
|
40 |
+
"num_key_value_heads": 8,
|
41 |
+
"retrieval_cache_dir": "/share/shared_models",
|
42 |
+
"retrieval_key_length": null,
|
43 |
+
"retrieval_method": null,
|
44 |
+
"retrieval_topk": null,
|
45 |
+
"rms_norm_eps": 1e-05,
|
46 |
+
"rope_scaling": null,
|
47 |
+
"rope_theta": 1000000.0,
|
48 |
+
"sliding_window": null,
|
49 |
+
"tie_word_embeddings": false,
|
50 |
+
"torch_dtype": "bfloat16",
|
51 |
+
"transformers_version": "4.39.3",
|
52 |
+
"use_cache": true,
|
53 |
+
"vocab_size": 32000
|
54 |
+
}
|
configuration_mistral.py
ADDED
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2023 Mistral AI and the 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 |
+
""" Mistral model configuration"""
|
16 |
+
|
17 |
+
from transformers.configuration_utils import PretrainedConfig
|
18 |
+
from transformers.utils import logging
|
19 |
+
|
20 |
+
|
21 |
+
logger = logging.get_logger(__name__)
|
22 |
+
|
23 |
+
MISTRAL_PRETRAINED_CONFIG_ARCHIVE_MAP = {
|
24 |
+
"mistralai/Mistral-7B-v0.1": "https://huggingface.co/mistralai/Mistral-7B-v0.1/resolve/main/config.json",
|
25 |
+
"mistralai/Mistral-7B-Instruct-v0.1": "https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1/resolve/main/config.json",
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
class MistralConfig(PretrainedConfig):
|
30 |
+
r"""
|
31 |
+
This is the configuration class to store the configuration of a [`MistralModel`]. It is used to instantiate an
|
32 |
+
Mistral model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
33 |
+
with the defaults will yield a similar configuration to that of the Mistral-7B-v0.1 or Mistral-7B-Instruct-v0.1.
|
34 |
+
|
35 |
+
[mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
|
36 |
+
[mistralai/Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1)
|
37 |
+
|
38 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
39 |
+
documentation from [`PretrainedConfig`] for more information.
|
40 |
+
|
41 |
+
|
42 |
+
Args:
|
43 |
+
vocab_size (`int`, *optional*, defaults to 32000):
|
44 |
+
Vocabulary size of the Mistral model. Defines the number of different tokens that can be represented by the
|
45 |
+
`inputs_ids` passed when calling [`MistralModel`]
|
46 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
47 |
+
Dimension of the hidden representations.
|
48 |
+
intermediate_size (`int`, *optional*, defaults to 14336):
|
49 |
+
Dimension of the MLP representations.
|
50 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
51 |
+
Number of hidden layers in the Transformer encoder.
|
52 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
53 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
54 |
+
num_key_value_heads (`int`, *optional*, defaults to 8):
|
55 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
56 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
57 |
+
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
58 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
59 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
60 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `8`.
|
61 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
62 |
+
The non-linear activation function (function or string) in the decoder.
|
63 |
+
max_position_embeddings (`int`, *optional*, defaults to `4096*32`):
|
64 |
+
The maximum sequence length that this model might ever be used with. Mistral's sliding window attention
|
65 |
+
allows sequence of up to 4096*32 tokens.
|
66 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
67 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
68 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
69 |
+
The epsilon used by the rms normalization layers.
|
70 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
71 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
72 |
+
relevant if `config.is_decoder=True`.
|
73 |
+
pad_token_id (`int`, *optional*):
|
74 |
+
The id of the padding token.
|
75 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
76 |
+
The id of the "beginning-of-sequence" token.
|
77 |
+
eos_token_id (`int`, *optional*, defaults to 2):
|
78 |
+
The id of the "end-of-sequence" token.
|
79 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
80 |
+
Whether the model's input and output word embeddings should be tied.
|
81 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
82 |
+
The base period of the RoPE embeddings.
|
83 |
+
sliding_window (`int`, *optional*, defaults to 4096):
|
84 |
+
Sliding window attention window size. If not specified, will default to `4096`.
|
85 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
86 |
+
The dropout ratio for the attention probabilities.
|
87 |
+
|
88 |
+
```python
|
89 |
+
>>> from transformers import MistralModel, MistralConfig
|
90 |
+
|
91 |
+
>>> # Initializing a Mistral 7B style configuration
|
92 |
+
>>> configuration = MistralConfig()
|
93 |
+
|
94 |
+
>>> # Initializing a model from the Mistral 7B style configuration
|
95 |
+
>>> model = MistralModel(configuration)
|
96 |
+
|
97 |
+
>>> # Accessing the model configuration
|
98 |
+
>>> configuration = model.config
|
99 |
+
```"""
|
100 |
+
|
101 |
+
model_type = "mistral"
|
102 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
103 |
+
|
104 |
+
def __init__(
|
105 |
+
self,
|
106 |
+
vocab_size=32000,
|
107 |
+
hidden_size=4096,
|
108 |
+
intermediate_size=14336,
|
109 |
+
num_hidden_layers=32,
|
110 |
+
num_attention_heads=32,
|
111 |
+
num_key_value_heads=8,
|
112 |
+
hidden_act="silu",
|
113 |
+
max_position_embeddings=4096 * 32,
|
114 |
+
initializer_range=0.02,
|
115 |
+
rms_norm_eps=1e-6,
|
116 |
+
use_cache=True,
|
117 |
+
pad_token_id=None,
|
118 |
+
bos_token_id=1,
|
119 |
+
eos_token_id=2,
|
120 |
+
tie_word_embeddings=False,
|
121 |
+
rope_theta=10000.0,
|
122 |
+
sliding_window=4096,
|
123 |
+
rope_scaling=None,
|
124 |
+
attention_dropout=0.0,
|
125 |
+
beacon_window=1024,
|
126 |
+
beacon_stride=1024,
|
127 |
+
beacon_attn="full-coverage",
|
128 |
+
beacon_ratio=[2,4,8,16,32],
|
129 |
+
beacon_ratio_mix="step-random",
|
130 |
+
beacon_param=[],
|
131 |
+
beacon_embed_init="eos",
|
132 |
+
beacon_sink_size=0,
|
133 |
+
beacon_attend_prev=True,
|
134 |
+
beacon_pos="interleave",
|
135 |
+
beacon_parallel_window=1,
|
136 |
+
beacon_accum=True,
|
137 |
+
**kwargs,
|
138 |
+
):
|
139 |
+
self.vocab_size = vocab_size
|
140 |
+
self.max_position_embeddings = max_position_embeddings
|
141 |
+
self.hidden_size = hidden_size
|
142 |
+
self.intermediate_size = intermediate_size
|
143 |
+
self.num_hidden_layers = num_hidden_layers
|
144 |
+
self.num_attention_heads = num_attention_heads
|
145 |
+
self.sliding_window = sliding_window
|
146 |
+
|
147 |
+
# for backward compatibility
|
148 |
+
if num_key_value_heads is None:
|
149 |
+
num_key_value_heads = num_attention_heads
|
150 |
+
|
151 |
+
self.num_key_value_heads = num_key_value_heads
|
152 |
+
self.hidden_act = hidden_act
|
153 |
+
self.initializer_range = initializer_range
|
154 |
+
self.rms_norm_eps = rms_norm_eps
|
155 |
+
self.use_cache = use_cache
|
156 |
+
self.rope_theta = rope_theta
|
157 |
+
self.attention_dropout = attention_dropout
|
158 |
+
|
159 |
+
self.rope_scaling = rope_scaling
|
160 |
+
self._rope_scaling_validation()
|
161 |
+
|
162 |
+
self.beacon_window = beacon_window
|
163 |
+
self.beacon_stride = beacon_stride
|
164 |
+
self.beacon_attn = beacon_attn
|
165 |
+
self.beacon_ratio = beacon_ratio
|
166 |
+
self.beacon_ratio_mix = beacon_ratio_mix
|
167 |
+
self.beacon_param = beacon_param
|
168 |
+
self.beacon_embed_init = beacon_embed_init
|
169 |
+
self.beacon_sink_size = beacon_sink_size
|
170 |
+
self.beacon_attend_prev = beacon_attend_prev
|
171 |
+
self.beacon_pos = beacon_pos
|
172 |
+
self.beacon_parallel_window = beacon_parallel_window
|
173 |
+
self.beacon_accum = beacon_accum
|
174 |
+
|
175 |
+
super().__init__(
|
176 |
+
pad_token_id=pad_token_id,
|
177 |
+
bos_token_id=bos_token_id,
|
178 |
+
eos_token_id=eos_token_id,
|
179 |
+
tie_word_embeddings=tie_word_embeddings,
|
180 |
+
**kwargs,
|
181 |
+
)
|
182 |
+
|
183 |
+
def _rope_scaling_validation(self):
|
184 |
+
"""
|
185 |
+
Validate the `rope_scaling` configuration.
|
186 |
+
"""
|
187 |
+
if self.rope_scaling is None:
|
188 |
+
return
|
189 |
+
|
190 |
+
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
|
191 |
+
raise ValueError(
|
192 |
+
"`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
|
193 |
+
f"got {self.rope_scaling}"
|
194 |
+
)
|
195 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
196 |
+
rope_scaling_factor = self.rope_scaling.get("factor", None)
|
197 |
+
if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
|
198 |
+
raise ValueError(
|
199 |
+
f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
|
200 |
+
)
|
201 |
+
if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
|
202 |
+
raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
|
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.39.3"
|
6 |
+
}
|
model-00001-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9e416c8668a41968e4198a650f19b03ed8fb38e1b5a41fc856bd2e3af31c7a84
|
3 |
+
size 4993488960
|
model-00002-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:18967ee869eed6db5ed9bd3f8571f1341c2bdd67fa4c0da47f7a5cd7bd577bde
|
3 |
+
size 4915886400
|
model-00003-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:feb331d8c928fc013ff4d0c16db25f5046c2feaeec6755b78d98ff7420c95dc6
|
3 |
+
size 4999789088
|
model-00004-of-00004.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6eb37682a3e4b2fe960edab7a9b4a50027fac9a01edba9695f3c5096dd9d6bbc
|
3 |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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"metadata": {
|
3 |
+
"total_size": 17167826944
|
4 |
+
},
|
5 |
+
"weight_map": {
|
6 |
+
"lm_head.weight": "model-00004-of-00004.safetensors",
|
7 |
+
"model.beacon_embed_tokens.weight": "model-00001-of-00004.safetensors",
|
8 |
+
"model.embed_tokens.weight": "model-00001-of-00004.safetensors",
|
9 |
+
"model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
10 |
+
"model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
11 |
+
"model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
12 |
+
"model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
13 |
+
"model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
14 |
+
"model.layers.0.self_attn.beacon_k_proj.weight": "model-00001-of-00004.safetensors",
|
15 |
+
"model.layers.0.self_attn.beacon_o_proj.weight": "model-00001-of-00004.safetensors",
|
16 |
+
"model.layers.0.self_attn.beacon_q_proj.weight": "model-00001-of-00004.safetensors",
|
17 |
+
"model.layers.0.self_attn.beacon_v_proj.weight": "model-00001-of-00004.safetensors",
|
18 |
+
"model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
19 |
+
"model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
20 |
+
"model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
21 |
+
"model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
22 |
+
"model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
23 |
+
"model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
24 |
+
"model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
25 |
+
"model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
26 |
+
"model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
27 |
+
"model.layers.1.self_attn.beacon_k_proj.weight": "model-00001-of-00004.safetensors",
|
28 |
+
"model.layers.1.self_attn.beacon_o_proj.weight": "model-00001-of-00004.safetensors",
|
29 |
+
"model.layers.1.self_attn.beacon_q_proj.weight": "model-00001-of-00004.safetensors",
|
30 |
+
"model.layers.1.self_attn.beacon_v_proj.weight": "model-00001-of-00004.safetensors",
|
31 |
+
"model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
32 |
+
"model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
33 |
+
"model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
34 |
+
"model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
35 |
+
"model.layers.10.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
36 |
+
"model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
37 |
+
"model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
38 |
+
"model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
39 |
+
"model.layers.10.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
40 |
+
"model.layers.10.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
41 |
+
"model.layers.10.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
42 |
+
"model.layers.10.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
43 |
+
"model.layers.10.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
44 |
+
"model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
45 |
+
"model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
46 |
+
"model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
47 |
+
"model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
48 |
+
"model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
49 |
+
"model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
50 |
+
"model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
51 |
+
"model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
52 |
+
"model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
53 |
+
"model.layers.11.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
54 |
+
"model.layers.11.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
55 |
+
"model.layers.11.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
56 |
+
"model.layers.11.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
57 |
+
"model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
58 |
+
"model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
59 |
+
"model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
60 |
+
"model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
61 |
+
"model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
62 |
+
"model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
63 |
+
"model.layers.12.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
64 |
+
"model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
65 |
+
"model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
66 |
+
"model.layers.12.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
67 |
+
"model.layers.12.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
68 |
+
"model.layers.12.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
69 |
+
"model.layers.12.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
70 |
+
"model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
71 |
+
"model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
72 |
+
"model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
73 |
+
"model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
74 |
+
"model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
75 |
+
"model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
76 |
+
"model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
77 |
+
"model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
78 |
+
"model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
79 |
+
"model.layers.13.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
80 |
+
"model.layers.13.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
81 |
+
"model.layers.13.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
82 |
+
"model.layers.13.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
83 |
+
"model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
84 |
+
"model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
85 |
+
"model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
86 |
+
"model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
87 |
+
"model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
88 |
+
"model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
89 |
+
"model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
90 |
+
"model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
91 |
+
"model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
92 |
+
"model.layers.14.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
93 |
+
"model.layers.14.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
94 |
+
"model.layers.14.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
95 |
+
"model.layers.14.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
96 |
+
"model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
97 |
+
"model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
98 |
+
"model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
99 |
+
"model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
100 |
+
"model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
101 |
+
"model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
102 |
+
"model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
103 |
+
"model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
104 |
+
"model.layers.15.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
105 |
+
"model.layers.15.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
106 |
+
"model.layers.15.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
107 |
+
"model.layers.15.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
108 |
+
"model.layers.15.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
109 |
+
"model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
110 |
+
"model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
111 |
+
"model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
112 |
+
"model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
113 |
+
"model.layers.16.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
114 |
+
"model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
115 |
+
"model.layers.16.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
116 |
+
"model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
117 |
+
"model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
118 |
+
"model.layers.16.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
119 |
+
"model.layers.16.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
120 |
+
"model.layers.16.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
121 |
+
"model.layers.16.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
122 |
+
"model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
123 |
+
"model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
124 |
+
"model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
125 |
+
"model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
126 |
+
"model.layers.17.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
127 |
+
"model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
128 |
+
"model.layers.17.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
129 |
+
"model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
130 |
+
"model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
131 |
+
"model.layers.17.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
132 |
+
"model.layers.17.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
133 |
+
"model.layers.17.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
134 |
+
"model.layers.17.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
135 |
+
"model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
136 |
+
"model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
137 |
+
"model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
138 |
+
"model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
139 |
+
"model.layers.18.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
140 |
+
"model.layers.18.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
141 |
+
"model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
142 |
+
"model.layers.18.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
143 |
+
"model.layers.18.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
144 |
+
"model.layers.18.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
145 |
+
"model.layers.18.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
146 |
+
"model.layers.18.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
147 |
+
"model.layers.18.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
148 |
+
"model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
|
149 |
+
"model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
150 |
+
"model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
|
151 |
+
"model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
|
152 |
+
"model.layers.19.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
153 |
+
"model.layers.19.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
154 |
+
"model.layers.19.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
155 |
+
"model.layers.19.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
156 |
+
"model.layers.19.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
157 |
+
"model.layers.19.self_attn.beacon_k_proj.weight": "model-00003-of-00004.safetensors",
|
158 |
+
"model.layers.19.self_attn.beacon_o_proj.weight": "model-00003-of-00004.safetensors",
|
159 |
+
"model.layers.19.self_attn.beacon_q_proj.weight": "model-00003-of-00004.safetensors",
|
160 |
+
"model.layers.19.self_attn.beacon_v_proj.weight": "model-00003-of-00004.safetensors",
|
161 |
+
"model.layers.19.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
162 |
+
"model.layers.19.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
163 |
+
"model.layers.19.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
164 |
+
"model.layers.19.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
165 |
+
"model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
166 |
+
"model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
167 |
+
"model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
168 |
+
"model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
169 |
+
"model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
170 |
+
"model.layers.2.self_attn.beacon_k_proj.weight": "model-00001-of-00004.safetensors",
|
171 |
+
"model.layers.2.self_attn.beacon_o_proj.weight": "model-00001-of-00004.safetensors",
|
172 |
+
"model.layers.2.self_attn.beacon_q_proj.weight": "model-00001-of-00004.safetensors",
|
173 |
+
"model.layers.2.self_attn.beacon_v_proj.weight": "model-00001-of-00004.safetensors",
|
174 |
+
"model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
175 |
+
"model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
176 |
+
"model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
177 |
+
"model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
178 |
+
"model.layers.20.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
179 |
+
"model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
180 |
+
"model.layers.20.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
181 |
+
"model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
182 |
+
"model.layers.20.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
183 |
+
"model.layers.20.self_attn.beacon_k_proj.weight": "model-00003-of-00004.safetensors",
|
184 |
+
"model.layers.20.self_attn.beacon_o_proj.weight": "model-00003-of-00004.safetensors",
|
185 |
+
"model.layers.20.self_attn.beacon_q_proj.weight": "model-00003-of-00004.safetensors",
|
186 |
+
"model.layers.20.self_attn.beacon_v_proj.weight": "model-00003-of-00004.safetensors",
|
187 |
+
"model.layers.20.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
188 |
+
"model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
189 |
+
"model.layers.20.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
190 |
+
"model.layers.20.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
191 |
+
"model.layers.21.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
192 |
+
"model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
193 |
+
"model.layers.21.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
194 |
+
"model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
195 |
+
"model.layers.21.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
196 |
+
"model.layers.21.self_attn.beacon_k_proj.weight": "model-00003-of-00004.safetensors",
|
197 |
+
"model.layers.21.self_attn.beacon_o_proj.weight": "model-00003-of-00004.safetensors",
|
198 |
+
"model.layers.21.self_attn.beacon_q_proj.weight": "model-00003-of-00004.safetensors",
|
199 |
+
"model.layers.21.self_attn.beacon_v_proj.weight": "model-00003-of-00004.safetensors",
|
200 |
+
"model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
201 |
+
"model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
202 |
+
"model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
203 |
+
"model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
204 |
+
"model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
205 |
+
"model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
206 |
+
"model.layers.22.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
207 |
+
"model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
208 |
+
"model.layers.22.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
209 |
+
"model.layers.22.self_attn.beacon_k_proj.weight": "model-00003-of-00004.safetensors",
|
210 |
+
"model.layers.22.self_attn.beacon_o_proj.weight": "model-00003-of-00004.safetensors",
|
211 |
+
"model.layers.22.self_attn.beacon_q_proj.weight": "model-00003-of-00004.safetensors",
|
212 |
+
"model.layers.22.self_attn.beacon_v_proj.weight": "model-00003-of-00004.safetensors",
|
213 |
+
"model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
214 |
+
"model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
215 |
+
"model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
216 |
+
"model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
217 |
+
"model.layers.23.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
218 |
+
"model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
219 |
+
"model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
220 |
+
"model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
221 |
+
"model.layers.23.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
222 |
+
"model.layers.23.self_attn.beacon_k_proj.weight": "model-00003-of-00004.safetensors",
|
223 |
+
"model.layers.23.self_attn.beacon_o_proj.weight": "model-00003-of-00004.safetensors",
|
224 |
+
"model.layers.23.self_attn.beacon_q_proj.weight": "model-00003-of-00004.safetensors",
|
225 |
+
"model.layers.23.self_attn.beacon_v_proj.weight": "model-00003-of-00004.safetensors",
|
226 |
+
"model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
227 |
+
"model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
228 |
+
"model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
229 |
+
"model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
230 |
+
"model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
231 |
+
"model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
232 |
+
"model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
233 |
+
"model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
234 |
+
"model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
235 |
+
"model.layers.24.self_attn.beacon_k_proj.weight": "model-00003-of-00004.safetensors",
|
236 |
+
"model.layers.24.self_attn.beacon_o_proj.weight": "model-00003-of-00004.safetensors",
|
237 |
+
"model.layers.24.self_attn.beacon_q_proj.weight": "model-00003-of-00004.safetensors",
|
238 |
+
"model.layers.24.self_attn.beacon_v_proj.weight": "model-00003-of-00004.safetensors",
|
239 |
+
"model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
240 |
+
"model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
241 |
+
"model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
242 |
+
"model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
243 |
+
"model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
244 |
+
"model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
245 |
+
"model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
246 |
+
"model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
247 |
+
"model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
248 |
+
"model.layers.25.self_attn.beacon_k_proj.weight": "model-00003-of-00004.safetensors",
|
249 |
+
"model.layers.25.self_attn.beacon_o_proj.weight": "model-00003-of-00004.safetensors",
|
250 |
+
"model.layers.25.self_attn.beacon_q_proj.weight": "model-00003-of-00004.safetensors",
|
251 |
+
"model.layers.25.self_attn.beacon_v_proj.weight": "model-00003-of-00004.safetensors",
|
252 |
+
"model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
253 |
+
"model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
254 |
+
"model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
255 |
+
"model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
256 |
+
"model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
257 |
+
"model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
258 |
+
"model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
259 |
+
"model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
260 |
+
"model.layers.26.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
261 |
+
"model.layers.26.self_attn.beacon_k_proj.weight": "model-00003-of-00004.safetensors",
|
262 |
+
"model.layers.26.self_attn.beacon_o_proj.weight": "model-00003-of-00004.safetensors",
|
263 |
+
"model.layers.26.self_attn.beacon_q_proj.weight": "model-00003-of-00004.safetensors",
|
264 |
+
"model.layers.26.self_attn.beacon_v_proj.weight": "model-00003-of-00004.safetensors",
|
265 |
+
"model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
266 |
+
"model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
267 |
+
"model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
268 |
+
"model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
269 |
+
"model.layers.27.input_layernorm.weight": "model-00003-of-00004.safetensors",
|
270 |
+
"model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
|
271 |
+
"model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
|
272 |
+
"model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
|
273 |
+
"model.layers.27.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
|
274 |
+
"model.layers.27.self_attn.beacon_k_proj.weight": "model-00003-of-00004.safetensors",
|
275 |
+
"model.layers.27.self_attn.beacon_o_proj.weight": "model-00003-of-00004.safetensors",
|
276 |
+
"model.layers.27.self_attn.beacon_q_proj.weight": "model-00003-of-00004.safetensors",
|
277 |
+
"model.layers.27.self_attn.beacon_v_proj.weight": "model-00003-of-00004.safetensors",
|
278 |
+
"model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
279 |
+
"model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
280 |
+
"model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
281 |
+
"model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
282 |
+
"model.layers.28.input_layernorm.weight": "model-00004-of-00004.safetensors",
|
283 |
+
"model.layers.28.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
|
284 |
+
"model.layers.28.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
285 |
+
"model.layers.28.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
|
286 |
+
"model.layers.28.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
287 |
+
"model.layers.28.self_attn.beacon_k_proj.weight": "model-00004-of-00004.safetensors",
|
288 |
+
"model.layers.28.self_attn.beacon_o_proj.weight": "model-00004-of-00004.safetensors",
|
289 |
+
"model.layers.28.self_attn.beacon_q_proj.weight": "model-00004-of-00004.safetensors",
|
290 |
+
"model.layers.28.self_attn.beacon_v_proj.weight": "model-00004-of-00004.safetensors",
|
291 |
+
"model.layers.28.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
|
292 |
+
"model.layers.28.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
|
293 |
+
"model.layers.28.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
|
294 |
+
"model.layers.28.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
|
295 |
+
"model.layers.29.input_layernorm.weight": "model-00004-of-00004.safetensors",
|
296 |
+
"model.layers.29.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
|
297 |
+
"model.layers.29.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
298 |
+
"model.layers.29.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
|
299 |
+
"model.layers.29.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
300 |
+
"model.layers.29.self_attn.beacon_k_proj.weight": "model-00004-of-00004.safetensors",
|
301 |
+
"model.layers.29.self_attn.beacon_o_proj.weight": "model-00004-of-00004.safetensors",
|
302 |
+
"model.layers.29.self_attn.beacon_q_proj.weight": "model-00004-of-00004.safetensors",
|
303 |
+
"model.layers.29.self_attn.beacon_v_proj.weight": "model-00004-of-00004.safetensors",
|
304 |
+
"model.layers.29.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
|
305 |
+
"model.layers.29.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
|
306 |
+
"model.layers.29.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
|
307 |
+
"model.layers.29.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
|
308 |
+
"model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
309 |
+
"model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
310 |
+
"model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
311 |
+
"model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
312 |
+
"model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
313 |
+
"model.layers.3.self_attn.beacon_k_proj.weight": "model-00001-of-00004.safetensors",
|
314 |
+
"model.layers.3.self_attn.beacon_o_proj.weight": "model-00001-of-00004.safetensors",
|
315 |
+
"model.layers.3.self_attn.beacon_q_proj.weight": "model-00001-of-00004.safetensors",
|
316 |
+
"model.layers.3.self_attn.beacon_v_proj.weight": "model-00001-of-00004.safetensors",
|
317 |
+
"model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
318 |
+
"model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
319 |
+
"model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
320 |
+
"model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
321 |
+
"model.layers.30.input_layernorm.weight": "model-00004-of-00004.safetensors",
|
322 |
+
"model.layers.30.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
|
323 |
+
"model.layers.30.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
324 |
+
"model.layers.30.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
|
325 |
+
"model.layers.30.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
326 |
+
"model.layers.30.self_attn.beacon_k_proj.weight": "model-00004-of-00004.safetensors",
|
327 |
+
"model.layers.30.self_attn.beacon_o_proj.weight": "model-00004-of-00004.safetensors",
|
328 |
+
"model.layers.30.self_attn.beacon_q_proj.weight": "model-00004-of-00004.safetensors",
|
329 |
+
"model.layers.30.self_attn.beacon_v_proj.weight": "model-00004-of-00004.safetensors",
|
330 |
+
"model.layers.30.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
|
331 |
+
"model.layers.30.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
|
332 |
+
"model.layers.30.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
|
333 |
+
"model.layers.30.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
|
334 |
+
"model.layers.31.input_layernorm.weight": "model-00004-of-00004.safetensors",
|
335 |
+
"model.layers.31.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
|
336 |
+
"model.layers.31.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
|
337 |
+
"model.layers.31.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
|
338 |
+
"model.layers.31.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
|
339 |
+
"model.layers.31.self_attn.beacon_k_proj.weight": "model-00004-of-00004.safetensors",
|
340 |
+
"model.layers.31.self_attn.beacon_o_proj.weight": "model-00004-of-00004.safetensors",
|
341 |
+
"model.layers.31.self_attn.beacon_q_proj.weight": "model-00004-of-00004.safetensors",
|
342 |
+
"model.layers.31.self_attn.beacon_v_proj.weight": "model-00004-of-00004.safetensors",
|
343 |
+
"model.layers.31.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
|
344 |
+
"model.layers.31.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
|
345 |
+
"model.layers.31.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
|
346 |
+
"model.layers.31.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
|
347 |
+
"model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
348 |
+
"model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
349 |
+
"model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
350 |
+
"model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
351 |
+
"model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
352 |
+
"model.layers.4.self_attn.beacon_k_proj.weight": "model-00001-of-00004.safetensors",
|
353 |
+
"model.layers.4.self_attn.beacon_o_proj.weight": "model-00001-of-00004.safetensors",
|
354 |
+
"model.layers.4.self_attn.beacon_q_proj.weight": "model-00001-of-00004.safetensors",
|
355 |
+
"model.layers.4.self_attn.beacon_v_proj.weight": "model-00001-of-00004.safetensors",
|
356 |
+
"model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
357 |
+
"model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
358 |
+
"model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
359 |
+
"model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
360 |
+
"model.layers.5.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
361 |
+
"model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
362 |
+
"model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
363 |
+
"model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
364 |
+
"model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
365 |
+
"model.layers.5.self_attn.beacon_k_proj.weight": "model-00001-of-00004.safetensors",
|
366 |
+
"model.layers.5.self_attn.beacon_o_proj.weight": "model-00001-of-00004.safetensors",
|
367 |
+
"model.layers.5.self_attn.beacon_q_proj.weight": "model-00001-of-00004.safetensors",
|
368 |
+
"model.layers.5.self_attn.beacon_v_proj.weight": "model-00001-of-00004.safetensors",
|
369 |
+
"model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
370 |
+
"model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
371 |
+
"model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
372 |
+
"model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
373 |
+
"model.layers.6.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
374 |
+
"model.layers.6.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
375 |
+
"model.layers.6.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
376 |
+
"model.layers.6.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
377 |
+
"model.layers.6.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
378 |
+
"model.layers.6.self_attn.beacon_k_proj.weight": "model-00001-of-00004.safetensors",
|
379 |
+
"model.layers.6.self_attn.beacon_o_proj.weight": "model-00001-of-00004.safetensors",
|
380 |
+
"model.layers.6.self_attn.beacon_q_proj.weight": "model-00001-of-00004.safetensors",
|
381 |
+
"model.layers.6.self_attn.beacon_v_proj.weight": "model-00001-of-00004.safetensors",
|
382 |
+
"model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
383 |
+
"model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
384 |
+
"model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
385 |
+
"model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
386 |
+
"model.layers.7.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
387 |
+
"model.layers.7.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
388 |
+
"model.layers.7.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
389 |
+
"model.layers.7.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
390 |
+
"model.layers.7.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
391 |
+
"model.layers.7.self_attn.beacon_k_proj.weight": "model-00001-of-00004.safetensors",
|
392 |
+
"model.layers.7.self_attn.beacon_o_proj.weight": "model-00001-of-00004.safetensors",
|
393 |
+
"model.layers.7.self_attn.beacon_q_proj.weight": "model-00001-of-00004.safetensors",
|
394 |
+
"model.layers.7.self_attn.beacon_v_proj.weight": "model-00001-of-00004.safetensors",
|
395 |
+
"model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
396 |
+
"model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
397 |
+
"model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
398 |
+
"model.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
399 |
+
"model.layers.8.input_layernorm.weight": "model-00001-of-00004.safetensors",
|
400 |
+
"model.layers.8.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
|
401 |
+
"model.layers.8.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
|
402 |
+
"model.layers.8.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
|
403 |
+
"model.layers.8.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
|
404 |
+
"model.layers.8.self_attn.beacon_k_proj.weight": "model-00001-of-00004.safetensors",
|
405 |
+
"model.layers.8.self_attn.beacon_o_proj.weight": "model-00001-of-00004.safetensors",
|
406 |
+
"model.layers.8.self_attn.beacon_q_proj.weight": "model-00001-of-00004.safetensors",
|
407 |
+
"model.layers.8.self_attn.beacon_v_proj.weight": "model-00001-of-00004.safetensors",
|
408 |
+
"model.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
409 |
+
"model.layers.8.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
|
410 |
+
"model.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
411 |
+
"model.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
412 |
+
"model.layers.9.input_layernorm.weight": "model-00002-of-00004.safetensors",
|
413 |
+
"model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
|
414 |
+
"model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
|
415 |
+
"model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
|
416 |
+
"model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
|
417 |
+
"model.layers.9.self_attn.beacon_k_proj.weight": "model-00002-of-00004.safetensors",
|
418 |
+
"model.layers.9.self_attn.beacon_o_proj.weight": "model-00002-of-00004.safetensors",
|
419 |
+
"model.layers.9.self_attn.beacon_q_proj.weight": "model-00002-of-00004.safetensors",
|
420 |
+
"model.layers.9.self_attn.beacon_v_proj.weight": "model-00002-of-00004.safetensors",
|
421 |
+
"model.layers.9.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
|
422 |
+
"model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
|
423 |
+
"model.layers.9.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
|
424 |
+
"model.layers.9.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
|
425 |
+
"model.norm.weight": "model-00004-of-00004.safetensors"
|
426 |
+
}
|
427 |
+
}
|
modeling_beacon.py
ADDED
@@ -0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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
import time
|
4 |
+
import numpy as np
|
5 |
+
import torch.distributed as dist
|
6 |
+
from copy import deepcopy
|
7 |
+
from transformers.utils import logging
|
8 |
+
from transformers import AutoTokenizer
|
9 |
+
from itertools import cycle
|
10 |
+
from typing import List
|
11 |
+
|
12 |
+
logger = logging.get_logger(__name__)
|
13 |
+
|
14 |
+
|
15 |
+
class Memory(torch.nn.Module):
|
16 |
+
def __init__(
|
17 |
+
self,
|
18 |
+
model_config,
|
19 |
+
k_seq_dim:int=2,
|
20 |
+
v_seq_dim:int=2,
|
21 |
+
):
|
22 |
+
"""Setup necessary attributes."""
|
23 |
+
super().__init__()
|
24 |
+
|
25 |
+
self.config = model_config
|
26 |
+
|
27 |
+
# initialize necessary parameters
|
28 |
+
self.k_seq_dim = k_seq_dim
|
29 |
+
self.v_seq_dim = v_seq_dim
|
30 |
+
self.rng = np.random.default_rng(42)
|
31 |
+
|
32 |
+
self._post_validation()
|
33 |
+
self.reset()
|
34 |
+
|
35 |
+
@property
|
36 |
+
def beacon_token(self):
|
37 |
+
return self.config.vocab_size
|
38 |
+
|
39 |
+
def _post_validation(self, verbose=True):
|
40 |
+
assert self.config.beacon_window >= self.config.beacon_stride, f"Make sure the beacon_window {self.config.beacon_window} >= beacon_stride {self.config.beacon_stride}!"
|
41 |
+
for ratio in self.config.beacon_ratio:
|
42 |
+
assert ratio >= 0, f"Make sure all beacon ratios are greater than or equal to 0, found {self.config.beacon_ratio}!"
|
43 |
+
assert self.config.beacon_attn in ["segmentation", "step-expansion", "full-coverage"], f"beacon_attn {self.config.beacon_attn} not implemented!"
|
44 |
+
assert self.config.beacon_ratio_mix in ["instance-random", "step-random", "sequence"] or "adapt-" in self.config.beacon_ratio_mix, f"beacon_ratio_mix {self.config.beacon_ratio_mix} not implemented!"
|
45 |
+
# assert self.config.beacon_pos in ["append", "interleave"], f"beacon_pos {self.config.beacon_pos} not implemented!"
|
46 |
+
if self.config.beacon_pos == "interleave":
|
47 |
+
assert self.config.beacon_window == self.config.beacon_stride, f"Make sure the beacon_window equals to beacon_stride when using interleaving mode."
|
48 |
+
if self.config.beacon_parallel_window > 1:
|
49 |
+
assert self.config._attn_implementation != "flash_attention_2", f"Currently parallel window does not support flash_attention_2!"
|
50 |
+
|
51 |
+
self._cpu = torch.device("cpu")
|
52 |
+
|
53 |
+
if verbose:
|
54 |
+
info = f"applying activation beacon on {self.config.beacon_param} (the beacon embedding is initialized from {'bos' if self.config.beacon_embed_init == 'bos' else 'eos'} embedding, the beacon tokens are positioned with '{self.config.beacon_pos}' method), with window size {self.config.beacon_window}, stride {self.config.beacon_stride}, {self.config.beacon_attn} attention{' (attending to previous beacons)' if self.config.beacon_attend_prev else ' (no attending to previous beacons)'}, sink size {self.config.beacon_sink_size}, compression ratio {self.config.beacon_ratio} (mixed by {self.config.beacon_ratio_mix})..."
|
55 |
+
logger.info(info)
|
56 |
+
|
57 |
+
def set(self, verbose=True, **kwargs):
|
58 |
+
"""
|
59 |
+
Set attributes out of the constructor.
|
60 |
+
"""
|
61 |
+
for k, v in kwargs.items():
|
62 |
+
setattr(self.config, k, v)
|
63 |
+
self._post_validation(verbose=verbose)
|
64 |
+
|
65 |
+
def reset(self, **kwargs):
|
66 |
+
"""Initialize attributes for a new sequence."""
|
67 |
+
# the cursor pointing to the start of the current window
|
68 |
+
self.start_idx = 0
|
69 |
+
# the cursor pointing to the end of the current window
|
70 |
+
self.end_idx = 0
|
71 |
+
# the beacon sizes of all strides
|
72 |
+
self.all_beacon_sizes = []
|
73 |
+
# the loss per batch
|
74 |
+
self.batch_loss = None
|
75 |
+
# the valid token number per batch
|
76 |
+
self.valid_token_num = None
|
77 |
+
# the step index for processing the input_ids
|
78 |
+
self.step_idx = 0
|
79 |
+
# used in set_compression_ratio
|
80 |
+
self.compression_ratio = None
|
81 |
+
# the previous inputs is a full window or not, defaults to True
|
82 |
+
self.is_full_window = True
|
83 |
+
# the number of raw activations to preserve in update_memory (only useful when beacon_stride < beacon_window)
|
84 |
+
self.raw_size_to_cache = 0
|
85 |
+
|
86 |
+
# the number of tokens in previous stride that should be compressed by the upcoming beacon
|
87 |
+
self.interleave_remainder = 0
|
88 |
+
# compression ratio for the unfinished window
|
89 |
+
self.interleave_compression_ratio = None
|
90 |
+
self.beacon_indices = None
|
91 |
+
|
92 |
+
self.all_input_ids = None
|
93 |
+
self.all_attention_mask = None
|
94 |
+
self.all_labels = None
|
95 |
+
|
96 |
+
# NOTE: will be reset in prepare()
|
97 |
+
self.beacon_skip_first = None
|
98 |
+
self.beacon_skip_last = None
|
99 |
+
|
100 |
+
# the attention sink activations
|
101 |
+
self.sink_activations = [(None, None) for _ in range(self.config.num_hidden_layers)]
|
102 |
+
# the beacon activations
|
103 |
+
self.beacon_activations = [(None, None) for _ in range(self.config.num_hidden_layers)]
|
104 |
+
# the raw activations of recent tokens
|
105 |
+
self.raw_activations = [(None, None) for _ in range(self.config.num_hidden_layers)]
|
106 |
+
|
107 |
+
# NOTE: in case we want to resume the memory from a particular state
|
108 |
+
for k, v in kwargs.items():
|
109 |
+
# NOTE: deepcopy to untie the memory state and the model memory
|
110 |
+
setattr(self, deepcopy(k), deepcopy(v))
|
111 |
+
|
112 |
+
def export(self):
|
113 |
+
"""Export all necessary attributes of the memory module."""
|
114 |
+
return {
|
115 |
+
"start_idx": self.start_idx,
|
116 |
+
"end_idx": self.end_idx,
|
117 |
+
"all_beacon_sizes": self.all_beacon_sizes,
|
118 |
+
"batch_loss": self.batch_loss,
|
119 |
+
"valid_token_num": self.valid_token_num,
|
120 |
+
"step_idx": self.step_idx,
|
121 |
+
"compression_ratio": self.compression_ratio,
|
122 |
+
"is_full_window": self.is_full_window,
|
123 |
+
"raw_size_to_cache": self.raw_size_to_cache,
|
124 |
+
"interleave_remainder": self.interleave_remainder,
|
125 |
+
"interleave_compression_ratio": self.interleave_compression_ratio,
|
126 |
+
"beacon_indices": self.beacon_indices,
|
127 |
+
"all_input_ids": self.all_input_ids,
|
128 |
+
"all_attention_mask": self.all_attention_mask,
|
129 |
+
"all_labels": self.all_labels,
|
130 |
+
"beacon_skip_first": self.beacon_skip_first,
|
131 |
+
"beacon_skip_last": self.beacon_skip_last,
|
132 |
+
# NOTE: deepcopy to untie the memory state and the model memory
|
133 |
+
"sink_activations": deepcopy(self.sink_activations),
|
134 |
+
"beacon_activations": deepcopy(self.beacon_activations),
|
135 |
+
"raw_activations": deepcopy(self.raw_activations),
|
136 |
+
}
|
137 |
+
|
138 |
+
@property
|
139 |
+
def all_sequence_length(self):
|
140 |
+
if self.all_input_ids is None:
|
141 |
+
return 0
|
142 |
+
else:
|
143 |
+
return self.all_input_ids.shape[1]
|
144 |
+
|
145 |
+
@property
|
146 |
+
def batch_size(self):
|
147 |
+
if self.all_input_ids is None:
|
148 |
+
return 0
|
149 |
+
else:
|
150 |
+
return self.all_input_ids.shape[0]
|
151 |
+
|
152 |
+
@property
|
153 |
+
def finish(self):
|
154 |
+
is_finish = self.end_idx == self.all_sequence_length
|
155 |
+
return is_finish
|
156 |
+
|
157 |
+
@property
|
158 |
+
def dtype(self):
|
159 |
+
return self.config.torch_dtype
|
160 |
+
|
161 |
+
@property
|
162 |
+
def min_value(self):
|
163 |
+
return torch.finfo(self.dtype).min
|
164 |
+
|
165 |
+
@property
|
166 |
+
def max_position_embeddings(self):
|
167 |
+
max_position_embeddings = self.config.max_position_embeddings
|
168 |
+
if getattr(self.config, "rope_scaling", None) is not None:
|
169 |
+
scaling_factor = self.config.rope_scaling["factor"]
|
170 |
+
max_position_embeddings = max_position_embeddings * scaling_factor
|
171 |
+
return max_position_embeddings
|
172 |
+
|
173 |
+
@property
|
174 |
+
def beacon_window(self):
|
175 |
+
if (
|
176 |
+
self.beacon_skip_last is not None
|
177 |
+
and self.start_idx < self.beacon_skip_last
|
178 |
+
and self.start_idx + self.config.beacon_window > self.beacon_skip_last
|
179 |
+
):
|
180 |
+
return self.beacon_skip_last - self.start_idx
|
181 |
+
else:
|
182 |
+
return self.config.beacon_window
|
183 |
+
|
184 |
+
@property
|
185 |
+
def beacon_stride(self):
|
186 |
+
if (
|
187 |
+
self.beacon_skip_last is not None
|
188 |
+
and self.start_idx < self.beacon_skip_last
|
189 |
+
and self.start_idx + self.config.beacon_window > self.beacon_skip_last
|
190 |
+
):
|
191 |
+
return self.beacon_skip_last - self.start_idx
|
192 |
+
else:
|
193 |
+
return self.config.beacon_stride
|
194 |
+
|
195 |
+
def get_memory_size(self):
|
196 |
+
"""
|
197 |
+
Sink memory size, beacon memory size and raw memory size.
|
198 |
+
"""
|
199 |
+
sink_memory_size = 0
|
200 |
+
beacon_memory_size = 0
|
201 |
+
raw_memory_size = 0
|
202 |
+
if self.sink_activations[0][0] is not None:
|
203 |
+
sink_memory_size += self.sink_activations[0][0].shape[self.k_seq_dim]
|
204 |
+
if self.beacon_activations[0][0] is not None:
|
205 |
+
beacon_memory_size += self.beacon_activations[0][0].shape[self.k_seq_dim]
|
206 |
+
if self.raw_activations[0][0] is not None:
|
207 |
+
raw_memory_size += self.raw_activations[0][0].shape[self.k_seq_dim]
|
208 |
+
return sink_memory_size, beacon_memory_size, raw_memory_size
|
209 |
+
|
210 |
+
def prepare(self, input_ids, attention_mask, labels, skip_first=None, skip_last=None):
|
211 |
+
"""
|
212 |
+
Prepare inputs for the model. These inputs belong to the same sequence.
|
213 |
+
"""
|
214 |
+
# assert input_ids.shape[0] == 1, "Make sure the batch size is 1!"
|
215 |
+
# assert attention_mask is None or (attention_mask == 1).all(), "Make sure there is no padding!"
|
216 |
+
|
217 |
+
self._device = input_ids.device
|
218 |
+
|
219 |
+
# accumulate input_ids
|
220 |
+
if self.all_input_ids is None:
|
221 |
+
self.all_input_ids = input_ids.cpu()
|
222 |
+
else:
|
223 |
+
self.all_input_ids = torch.cat([self.all_input_ids, input_ids.cpu()], dim=1)
|
224 |
+
|
225 |
+
# accumulate attention_mask
|
226 |
+
if attention_mask is None:
|
227 |
+
attention_mask = torch.ones_like(input_ids, device=torch.device("cpu"))
|
228 |
+
if self.all_attention_mask is None:
|
229 |
+
self.all_attention_mask = attention_mask.cpu()
|
230 |
+
else:
|
231 |
+
self.all_attention_mask = torch.cat([self.all_attention_mask, attention_mask.cpu()], dim=1)
|
232 |
+
|
233 |
+
# accumulate labels if exisits
|
234 |
+
if labels is not None:
|
235 |
+
# rotate labels in advance so that the loss of the last token is not ignored in every window
|
236 |
+
labels = torch.cat([labels[:, 1:].cpu(), torch.tensor([-100]).expand(labels.shape[0], 1)], dim=1)
|
237 |
+
if self.all_labels is None:
|
238 |
+
self.all_labels = labels.cpu()
|
239 |
+
else:
|
240 |
+
self.all_labels = torch.cat([self.all_labels, labels], dim=1)
|
241 |
+
assert self.all_input_ids.shape[1] == self.all_labels.shape[1], f"Found inconsistent all_input_ids {self.all_input_ids.shape} and all_labels {self.all_labels.shape}!"
|
242 |
+
|
243 |
+
# how many tokens to skip at the beginning of the sequence? (They will be packed in a single chunk and processed by the model, after which their activations will be cached in sink_activations.)
|
244 |
+
if skip_first is not None:
|
245 |
+
assert self.config.beacon_parallel_window == 1, f"Make sure the parallel window is set to 1 when using beacon_skip!"
|
246 |
+
assert self.config.beacon_window == self.config.beacon_stride, f"Make sure the beacon_window equals to beacon_stride when using beacon_skip."
|
247 |
+
assert self.config.beacon_sink_size == 0, f"Make sure the beacon_sink_size is set to 0 when using beacon_skip!"
|
248 |
+
# stop compression after how many tokens
|
249 |
+
if skip_last is not None:
|
250 |
+
skip_first = skip_first if skip_first is not None else 0
|
251 |
+
# assert (skip_last - skip_first) % self.config.beacon_window == 0, f"skip_last ({skip_last}) - skip_first ({skip_first}) = {skip_last - skip_first} is not divisible by window size {self.config.beacon_window}"
|
252 |
+
assert self.config.beacon_sink_size == 0, "Make sure the beacon_sink_size is zero when using skip_last!"
|
253 |
+
self.beacon_skip_first = skip_first
|
254 |
+
self.beacon_skip_last = skip_last
|
255 |
+
|
256 |
+
def set_compression_ratio(self, start_idx, end_idx):
|
257 |
+
"""Choose a condensing ratio from self.config.beacon_ratio"""
|
258 |
+
def filter_ratio(ratios, stride):
|
259 |
+
valid_ratios = []
|
260 |
+
for ratio in ratios:
|
261 |
+
# stride must be bigger than condensing ratio because we there must be at least one beacon
|
262 |
+
if stride < ratio:
|
263 |
+
continue
|
264 |
+
# the stride must be evenly divisible by condensing ratio
|
265 |
+
if ratio > 0 and (stride % ratio) != 0:
|
266 |
+
continue
|
267 |
+
# when training, ratio=0 is valid if previous windows contain beacon or later windows contain beacon
|
268 |
+
if ratio == 0 and self.training:
|
269 |
+
previous_has_zero = -1 in self.all_beacon_sizes
|
270 |
+
following_has_nonzero = (start_idx + stride + self.beacon_window) <= self.all_sequence_length
|
271 |
+
if previous_has_zero or (not following_has_nonzero):
|
272 |
+
continue
|
273 |
+
valid_ratios.append(ratio)
|
274 |
+
assert len(valid_ratios), f"Cannot find valid condensing ratio (among {ratios}) for stride {stride}!"
|
275 |
+
return valid_ratios
|
276 |
+
|
277 |
+
def get_max_length(ratios):
|
278 |
+
max_lengths = []
|
279 |
+
for compression_ratio in ratios:
|
280 |
+
if compression_ratio > 0:
|
281 |
+
# NOTE: here we must use the scaled position embeddings
|
282 |
+
max_lengths.append((self.max_position_embeddings - self.beacon_window) * compression_ratio + self.beacon_window)
|
283 |
+
else:
|
284 |
+
max_lengths.append(self.max_position_embeddings)
|
285 |
+
return max_lengths
|
286 |
+
|
287 |
+
if len(self.config.beacon_ratio) == 1:
|
288 |
+
return self.config.beacon_ratio[0]
|
289 |
+
|
290 |
+
ratio_mix = self.config.beacon_ratio_mix
|
291 |
+
|
292 |
+
beacon_ratio = filter_ratio(self.config.beacon_ratio, self.beacon_stride)
|
293 |
+
|
294 |
+
if ratio_mix == "instance-random":
|
295 |
+
if self.compression_ratio is None:
|
296 |
+
beacon_ratio = self.rng.choice(beacon_ratio).tolist()
|
297 |
+
self.compression_ratio = beacon_ratio
|
298 |
+
else:
|
299 |
+
beacon_ratio = self.compression_ratio
|
300 |
+
|
301 |
+
elif ratio_mix == "step-random":
|
302 |
+
beacon_ratio = self.rng.choice(beacon_ratio).tolist()
|
303 |
+
|
304 |
+
elif ratio_mix == "sequence":
|
305 |
+
if self.compression_ratio is None:
|
306 |
+
self.compression_ratio = cycle(beacon_ratio)
|
307 |
+
beacon_ratio = next(self.compression_ratio)
|
308 |
+
|
309 |
+
elif "adapt" in ratio_mix:
|
310 |
+
if self.compression_ratio is None:
|
311 |
+
future_length = int(ratio_mix.split("-")[1])
|
312 |
+
sequence_length = self.all_input_ids.shape[1] + future_length
|
313 |
+
max_lengths = get_max_length(beacon_ratio)
|
314 |
+
# ascendingly sort the max lengths
|
315 |
+
valid_max_lengths_and_indices = [x for x in enumerate(max_lengths) if x[1] >= sequence_length]
|
316 |
+
if len(valid_max_lengths_and_indices):
|
317 |
+
minimum_length_index = min(valid_max_lengths_and_indices, key=lambda x: x[1])[0]
|
318 |
+
# use the minimal possible length for this sequence (the smallest fold ratio)
|
319 |
+
beacon_ratio = beacon_ratio[minimum_length_index]
|
320 |
+
else:
|
321 |
+
beacon_ratio = max(beacon_ratio)
|
322 |
+
# logger.warning(f"Failed to find valid fold window and size for sequence length {sequence_length}, as the maximum theoretical length is {max(max_lengths)}. Fall back to use the maximum one: {beacon_ratio}.")
|
323 |
+
self.compression_ratio = beacon_ratio
|
324 |
+
else:
|
325 |
+
beacon_ratio = self.compression_ratio
|
326 |
+
|
327 |
+
return beacon_ratio
|
328 |
+
|
329 |
+
def step(self):
|
330 |
+
# parallel does not support stride < window
|
331 |
+
# parallel does not support non-compression
|
332 |
+
# the input_ids is not long enough for parallel
|
333 |
+
if (
|
334 |
+
self.config.beacon_parallel_window > 1
|
335 |
+
and self.config.beacon_stride == self.config.beacon_window
|
336 |
+
and 0 not in self.config.beacon_ratio
|
337 |
+
and self.all_input_ids[:, self.end_idx:].shape[1] >= self.config.beacon_parallel_window * self.config.beacon_window
|
338 |
+
):
|
339 |
+
input_ids_list = []
|
340 |
+
attention_mask_list = []
|
341 |
+
position_ids_list = []
|
342 |
+
labels_list = []
|
343 |
+
|
344 |
+
beacon_size_list = []
|
345 |
+
beacon_indices_list = []
|
346 |
+
|
347 |
+
for i in range(self.config.beacon_parallel_window):
|
348 |
+
if i == 0:
|
349 |
+
_input_ids, _attention_mask, _position_ids, _past_key_values, _labels = self._step()
|
350 |
+
else:
|
351 |
+
_input_ids, _attention_mask, _position_ids, _past_key_values, _labels = self._step(ignore_memory=True)
|
352 |
+
|
353 |
+
input_ids_list.append(_input_ids)
|
354 |
+
attention_mask_list.append(_attention_mask)
|
355 |
+
position_ids_list.append(_position_ids)
|
356 |
+
labels_list.append(_labels)
|
357 |
+
beacon_size_list.append(_past_key_values[0][2])
|
358 |
+
beacon_indices_list.append(_past_key_values[0][3])
|
359 |
+
|
360 |
+
if i == 0:
|
361 |
+
past_key_values = _past_key_values
|
362 |
+
if past_key_values[0][0] is None:
|
363 |
+
mem_size = 0
|
364 |
+
else:
|
365 |
+
mem_size = past_key_values[0][0].shape[self.k_seq_dim]
|
366 |
+
|
367 |
+
else:
|
368 |
+
# no memory
|
369 |
+
assert _past_key_values[0][0] is None
|
370 |
+
|
371 |
+
batch_size = self.all_input_ids.shape[0]
|
372 |
+
# NOTE: we do not need to repliace beacon tokens for the last window
|
373 |
+
seq_len = sum(x.shape[1] for x in input_ids_list) + sum(beacon_size_list) - beacon_size_list[-1]
|
374 |
+
|
375 |
+
input_ids = _input_ids.new_zeros((batch_size, seq_len)) + self.beacon_token
|
376 |
+
# all 0
|
377 |
+
attention_mask = _attention_mask.new_zeros((batch_size, 1, seq_len, mem_size + seq_len)) + self.min_value
|
378 |
+
position_ids = torch.arange(mem_size + seq_len, device=self._device).expand(batch_size, mem_size + seq_len)
|
379 |
+
# 2 indicates the beacon token is used for replication
|
380 |
+
beacon_indices = beacon_indices_list[0].new_zeros(seq_len) + 2
|
381 |
+
if _labels is not None:
|
382 |
+
# -100 because no loss on beacon tokens
|
383 |
+
labels = _labels.new_zeros((batch_size, seq_len)) - 100
|
384 |
+
else:
|
385 |
+
labels = None
|
386 |
+
|
387 |
+
start_idx = 0
|
388 |
+
position_offset = mem_size
|
389 |
+
for i in range(self.config.beacon_parallel_window):
|
390 |
+
beacon_size = beacon_size_list[i]
|
391 |
+
|
392 |
+
# populate input_ids
|
393 |
+
_input_ids = input_ids_list[i]
|
394 |
+
cur_seq_len = _input_ids.shape[1]
|
395 |
+
input_ids[:, start_idx: start_idx + cur_seq_len] = _input_ids
|
396 |
+
|
397 |
+
# populate attention_mask and position_ids
|
398 |
+
_attention_mask = attention_mask_list[i]
|
399 |
+
_position_ids = position_ids_list[i]
|
400 |
+
# the attention mask in the first window contains the mask for memory, which is redundant here
|
401 |
+
if i == 0:
|
402 |
+
_attention_mask = _attention_mask[:, :, :, mem_size:]
|
403 |
+
_position_ids = _position_ids[:, mem_size:] - mem_size
|
404 |
+
|
405 |
+
attention_mask[:, :, start_idx: start_idx + cur_seq_len, mem_size + start_idx: mem_size + start_idx + cur_seq_len] = _attention_mask
|
406 |
+
position_ids[:, mem_size + start_idx: mem_size + start_idx + cur_seq_len] = _position_ids + position_offset
|
407 |
+
|
408 |
+
# populate beacon_indices
|
409 |
+
_beacon_indices = beacon_indices_list[i]
|
410 |
+
beacon_indices[start_idx: start_idx + cur_seq_len] = _beacon_indices
|
411 |
+
|
412 |
+
# populate labels
|
413 |
+
if labels is not None:
|
414 |
+
# populate labels
|
415 |
+
_labels = labels_list[i]
|
416 |
+
labels[:, start_idx: start_idx + cur_seq_len] = _labels
|
417 |
+
|
418 |
+
# NOTE: when there is sink activations, we need to bias the position_ids for the first window
|
419 |
+
if i == 0 and self.config.beacon_sink_size > 0 and self.sink_activations[0][0] is None:
|
420 |
+
position_offset += 1
|
421 |
+
|
422 |
+
# modify the attention and position for replicated beacon tokens
|
423 |
+
if i != self.config.beacon_parallel_window - 1:
|
424 |
+
replicate_beacon_row_start = start_idx + cur_seq_len
|
425 |
+
replicate_beacon_col_start = mem_size + start_idx + cur_seq_len
|
426 |
+
# NOTE: any attention mask is okay for replicated beacon tokens, but for convenience we use the causal mask
|
427 |
+
attention_mask[:, :, replicate_beacon_row_start: replicate_beacon_row_start + beacon_size, replicate_beacon_col_start: replicate_beacon_col_start + beacon_size] = _attention_mask.new_full((beacon_size, beacon_size), self.min_value).triu(1)
|
428 |
+
# NOTE: all future tokens can attend to the replicated beacon tokens
|
429 |
+
attention_mask[:, :, replicate_beacon_row_start + beacon_size:, replicate_beacon_col_start: replicate_beacon_col_start + beacon_size] = 0
|
430 |
+
# NOTE: the position of replicated beacon tokens start from 0
|
431 |
+
position_ids[:, mem_size + start_idx + cur_seq_len: mem_size + start_idx + cur_seq_len + beacon_size] = torch.arange(position_offset, position_offset + beacon_size, device=_input_ids.device)[None:]
|
432 |
+
|
433 |
+
start_idx += cur_seq_len + beacon_size
|
434 |
+
position_offset += beacon_size
|
435 |
+
|
436 |
+
# the memory is visible to all subsequent tokens
|
437 |
+
attention_mask[:, :, :, :max(mem_size, self.config.beacon_sink_size)] = 0
|
438 |
+
|
439 |
+
# NOTE: modify beacon_indices
|
440 |
+
for i, (key, value, _, _) in enumerate(past_key_values):
|
441 |
+
past_key_values[i] = (key, value, sum(beacon_size_list), beacon_indices)
|
442 |
+
|
443 |
+
# NOTE: update _beacon_indices so that the next-token logits can be properly sliced out in self.output()
|
444 |
+
self.beacon_indices = beacon_indices
|
445 |
+
|
446 |
+
return input_ids, attention_mask, position_ids, past_key_values, labels
|
447 |
+
|
448 |
+
else:
|
449 |
+
return self._step()
|
450 |
+
|
451 |
+
def _step(self, ignore_memory=False):
|
452 |
+
"""
|
453 |
+
Yield inputs for the current sliding window, including the input_ids, attention_mask, position_ids, and past_key_values.
|
454 |
+
"""
|
455 |
+
#============================================#
|
456 |
+
# Check whether the inputs fulfills a window.
|
457 |
+
#============================================#
|
458 |
+
|
459 |
+
# the starting position of the current window w.r.t. the start of the current input sequence
|
460 |
+
start_idx = self.start_idx
|
461 |
+
# the end position of the current window w.r.t. the start of the current input sequence
|
462 |
+
end_idx = start_idx + self.beacon_window
|
463 |
+
# indicates if the current window is completely filled by raw activations and new tokens
|
464 |
+
# we only append beacon tokens for full windows
|
465 |
+
if end_idx > self.all_sequence_length:
|
466 |
+
# the input is shorter than the initial window size
|
467 |
+
end_idx = self.all_sequence_length
|
468 |
+
is_full_window = False
|
469 |
+
else:
|
470 |
+
is_full_window = True
|
471 |
+
|
472 |
+
# NOTE: in training, the entire sequence is input to the model at once
|
473 |
+
# In the last window, we do not need to append beacons because they will not be used at all
|
474 |
+
if self.training and end_idx == self.all_sequence_length:
|
475 |
+
next_start_idx = start_idx
|
476 |
+
is_full_window = False
|
477 |
+
raw_size_to_cache = -1
|
478 |
+
beacon_size = 0
|
479 |
+
compression_ratio = -1
|
480 |
+
|
481 |
+
# NOTE: we do not compress the beacon_skip_first tokens at the beginning of the sequence
|
482 |
+
elif self.step_idx == 0 and self.beacon_skip_first is not None:
|
483 |
+
end_idx = start_idx + self.beacon_skip_first
|
484 |
+
assert end_idx <= self.all_sequence_length
|
485 |
+
next_start_idx = end_idx
|
486 |
+
is_full_window = True
|
487 |
+
raw_size_to_cache = -1
|
488 |
+
beacon_size = 0
|
489 |
+
compression_ratio = -1
|
490 |
+
|
491 |
+
# NOTE: we do not compress tokens after beacon_skip_last tokens
|
492 |
+
elif self.beacon_skip_last is not None and start_idx >= self.beacon_skip_last:
|
493 |
+
end_idx = min(start_idx + self.beacon_window, self.all_sequence_length)
|
494 |
+
next_start_idx = end_idx
|
495 |
+
is_full_window = False
|
496 |
+
raw_size_to_cache = -1
|
497 |
+
beacon_size = 0
|
498 |
+
compression_ratio = -1
|
499 |
+
|
500 |
+
else:
|
501 |
+
#============================================#
|
502 |
+
# Set compression ratio
|
503 |
+
#============================================#
|
504 |
+
if self.config.beacon_pos == "append":
|
505 |
+
if is_full_window:
|
506 |
+
# determine compression ratio for the current window
|
507 |
+
beacon_stride = self.beacon_stride
|
508 |
+
compression_ratio = self.set_compression_ratio(start_idx=start_idx, end_idx=end_idx)
|
509 |
+
|
510 |
+
if compression_ratio > 0:
|
511 |
+
# the stride must be evenly divisible by compression_ratio
|
512 |
+
beacon_size = beacon_stride // compression_ratio
|
513 |
+
else:
|
514 |
+
# the raw activations are used as beacon activations
|
515 |
+
beacon_size = -1
|
516 |
+
|
517 |
+
# forward start_idx and end_idx
|
518 |
+
next_start_idx = start_idx + beacon_stride
|
519 |
+
# how many raw activations to save
|
520 |
+
raw_size_to_cache = end_idx - next_start_idx
|
521 |
+
else:
|
522 |
+
# no stride because the sequence has finished
|
523 |
+
next_start_idx = start_idx
|
524 |
+
# cache all raw activations
|
525 |
+
raw_size_to_cache = -1
|
526 |
+
beacon_size = 0
|
527 |
+
compression_ratio = 0
|
528 |
+
|
529 |
+
elif self.config.beacon_pos == "interleave":
|
530 |
+
# the number of raw tokens in the input_ids
|
531 |
+
input_size = end_idx - self.end_idx
|
532 |
+
# set compression ratio once the previous window has finished, otherwise, reuse the interleave_compression_ratio if the input belongs to an unfinished window
|
533 |
+
if self.is_full_window:
|
534 |
+
compression_ratio = self.set_compression_ratio(start_idx=start_idx, end_idx=end_idx)
|
535 |
+
self.interleave_compression_ratio = compression_ratio
|
536 |
+
else:
|
537 |
+
compression_ratio = self.interleave_compression_ratio
|
538 |
+
|
539 |
+
# the beacon size is non-zero even if the window is not full
|
540 |
+
if compression_ratio > 0:
|
541 |
+
# this number of beacon tokens will be inserted among the raw tokens
|
542 |
+
beacon_size = (input_size + self.interleave_remainder) // compression_ratio
|
543 |
+
else:
|
544 |
+
# the raw activations are used as beacon activations
|
545 |
+
beacon_size = -1
|
546 |
+
|
547 |
+
if is_full_window:
|
548 |
+
# move forward one window
|
549 |
+
next_start_idx = start_idx + self.beacon_stride
|
550 |
+
# no save raw activations
|
551 |
+
raw_size_to_cache = 0
|
552 |
+
else:
|
553 |
+
# no stride because the sequence has not finished
|
554 |
+
next_start_idx = start_idx
|
555 |
+
# cache all recent raw activations to be used in the next window
|
556 |
+
raw_size_to_cache = -1
|
557 |
+
|
558 |
+
#============================================#
|
559 |
+
# Slice out input_ids (raw tokens in the current window)
|
560 |
+
#============================================#
|
561 |
+
input_ids = self.all_input_ids[:, self.end_idx: end_idx].to(self._device)
|
562 |
+
attention_mask = self.all_attention_mask[:, self.end_idx: end_idx].to(self._device)
|
563 |
+
if self.all_labels is not None:
|
564 |
+
labels = self.all_labels[:, self.end_idx: end_idx].to(self._device)
|
565 |
+
else:
|
566 |
+
labels = None
|
567 |
+
batch_size = input_ids.shape[0]
|
568 |
+
|
569 |
+
#============================================#
|
570 |
+
# Insert beacon tokens if necessary.
|
571 |
+
#============================================#
|
572 |
+
# t1 = time.time()
|
573 |
+
|
574 |
+
if self.config.beacon_pos == "append":
|
575 |
+
# append beacons if necessary
|
576 |
+
if is_full_window and beacon_size > 0:
|
577 |
+
input_ids = torch.cat([input_ids, input_ids.new_full((batch_size, beacon_size), self.beacon_token)], dim=1)
|
578 |
+
# NOTE: prepend 1 to attention_mask because we have past_key_values
|
579 |
+
attention_mask = torch.cat([attention_mask, attention_mask.new_ones(batch_size, beacon_size)], dim=1)
|
580 |
+
if labels is not None:
|
581 |
+
labels = torch.cat([labels, labels.new_zeros(batch_size, beacon_size) - 100], dim=1)
|
582 |
+
|
583 |
+
elif self.config.beacon_pos == "interleave":
|
584 |
+
input_len = input_ids.shape[1]
|
585 |
+
if beacon_size > 0:
|
586 |
+
# insert beacon tokens in between raw tokens
|
587 |
+
input_ids_with_beacons = input_ids.new_full((input_ids.shape[0], input_len + beacon_size), self.beacon_token)
|
588 |
+
raw_token_indices = torch.arange(input_ids_with_beacons.shape[1], device=input_ids.device)
|
589 |
+
interleave_start_idx = compression_ratio - self.interleave_remainder
|
590 |
+
raw_token_indices = raw_token_indices[raw_token_indices % (compression_ratio + 1) != interleave_start_idx].unsqueeze(0).expand_as(input_ids)
|
591 |
+
input_ids_with_beacons = input_ids_with_beacons.scatter(dim=1, index=raw_token_indices, src=input_ids)
|
592 |
+
input_ids = input_ids_with_beacons
|
593 |
+
# attention mask
|
594 |
+
attention_mask_with_beacons = attention_mask.new_full((attention_mask.shape[0], attention_mask.shape[1] + beacon_size), 1)
|
595 |
+
attention_mask_with_beacons = attention_mask_with_beacons.scatter(dim=1, index=raw_token_indices, src=attention_mask)
|
596 |
+
attention_mask = attention_mask_with_beacons
|
597 |
+
# labels
|
598 |
+
if labels is not None:
|
599 |
+
labels_with_beacons = labels.new_full((labels.shape[0], labels.shape[1] + beacon_size), -100)
|
600 |
+
labels_with_beacons = labels_with_beacons.scatter(dim=1, index=raw_token_indices, src=labels)
|
601 |
+
labels = labels_with_beacons
|
602 |
+
|
603 |
+
if compression_ratio > 0:
|
604 |
+
# update the reminder
|
605 |
+
self.interleave_remainder = (input_len + self.interleave_remainder) % compression_ratio
|
606 |
+
|
607 |
+
# NOTE: skip computing loss in the very first window because the beacon tokens will be used in the next window
|
608 |
+
if self.training and self.step_idx == 0 and not (self.config.beacon_pos == 'interleave' and self.config.beacon_attn == 'full-coverage'):
|
609 |
+
labels[:] = -100
|
610 |
+
|
611 |
+
# t2 = time.time()
|
612 |
+
|
613 |
+
#============================================#
|
614 |
+
# Prepare beacon_indices for interleave beacon_pos, a boolean mask where True indicates the beacon tokens.
|
615 |
+
# The mask is applied on the inputs of the entire window, including the cached activations and the input_ids.
|
616 |
+
#============================================#
|
617 |
+
beacon_indices = (input_ids[0] == self.beacon_token).long()
|
618 |
+
if self.is_full_window:
|
619 |
+
self.beacon_indices = torch.tensor([], dtype=torch.long, device=input_ids.device)
|
620 |
+
# the beacon_indices always tracks the beacon tokens in both the cached activations and the input_ids
|
621 |
+
beacon_indices = torch.cat([self.beacon_indices, beacon_indices])
|
622 |
+
# record the beacon_indices for the next window
|
623 |
+
self.beacon_indices = beacon_indices
|
624 |
+
if is_full_window and beacon_size == -1:
|
625 |
+
# NOTE: the first beacon_stride raw tokens serve as beacon tokens
|
626 |
+
# we use -1 to indicate these raw tokens, so that the attention mask and position ids will not be modified
|
627 |
+
beacon_indices[:self.beacon_stride] = -1
|
628 |
+
|
629 |
+
# t3 = time.time()
|
630 |
+
|
631 |
+
#============================================#
|
632 |
+
# Prepare past_key_values.
|
633 |
+
# beacon_size: how many beacon tokens are there in the input_ids
|
634 |
+
# beacon_indices: the boolean mask for the entire window where True indicates the beacon tokens (for append, the beacon_indices corresponds to input_ids, while for 'interleave', the beacon_indices corresponds to the entire window including both the input_ids and the cached activations)
|
635 |
+
#============================================#
|
636 |
+
past_key_values = []
|
637 |
+
for layer_idx in range(self.config.num_hidden_layers):
|
638 |
+
if ignore_memory:
|
639 |
+
key, value = None, None
|
640 |
+
else:
|
641 |
+
sink_key, sink_value = self.sink_activations[layer_idx]
|
642 |
+
beacon_key, beacon_value = self.beacon_activations[layer_idx]
|
643 |
+
raw_key, raw_value = self.raw_activations[layer_idx]
|
644 |
+
|
645 |
+
key = cat_tensor([
|
646 |
+
sink_key, beacon_key, raw_key,
|
647 |
+
], dim=self.k_seq_dim)
|
648 |
+
value = cat_tensor([
|
649 |
+
sink_value, beacon_value, raw_value,
|
650 |
+
], dim=self.v_seq_dim)
|
651 |
+
|
652 |
+
layer_past_key_values = (key, value, beacon_size, beacon_indices)
|
653 |
+
past_key_values.append(layer_past_key_values)
|
654 |
+
|
655 |
+
# t4 = time.time()
|
656 |
+
|
657 |
+
#============================================#
|
658 |
+
# Prepare attention_mask and position_ids.
|
659 |
+
#============================================#
|
660 |
+
first_key = past_key_values[0][0]
|
661 |
+
mem_size = first_key.shape[self.k_seq_dim] if first_key is not None else 0
|
662 |
+
if mem_size > 0:
|
663 |
+
attention_mask = torch.cat([attention_mask.new_ones(batch_size, mem_size), attention_mask], dim=1)
|
664 |
+
|
665 |
+
input_length = input_ids.shape[1]
|
666 |
+
position_ids = torch.arange(attention_mask.shape[-1], dtype=torch.long, device=self._device).repeat(batch_size, 1)
|
667 |
+
|
668 |
+
if self.config._attn_implementation == "flash_attention_2":
|
669 |
+
assert self.config.beacon_attn == "full-coverage", f"Make sure to set beacon_attn='full-coverage' when using flash attention! Found {self.config.beacon_attn}."
|
670 |
+
if 0 in attention_mask:
|
671 |
+
pass
|
672 |
+
else:
|
673 |
+
attention_mask = None
|
674 |
+
elif self.config._attn_implementation == "sdpa" and self.config.beacon_pos == "append" and beacon_size <= 0 and (input_length == 1 or mem_size == 0):
|
675 |
+
attention_mask = None
|
676 |
+
else:
|
677 |
+
attention_mask, position_ids = self._make_4d_attention_mask_and_position_ids(
|
678 |
+
attention_mask,
|
679 |
+
position_ids,
|
680 |
+
mem_size,
|
681 |
+
beacon_size,
|
682 |
+
compression_ratio,
|
683 |
+
)
|
684 |
+
|
685 |
+
# t5 = time.time()
|
686 |
+
|
687 |
+
# print(f"prepare inputs {t2-t1}, prepare indices {t3-t2}, prepare memory {t4-t3}, prepare attention mask {t5-t4}")
|
688 |
+
|
689 |
+
#============================================#
|
690 |
+
# Update necessary attributes.
|
691 |
+
#============================================#
|
692 |
+
# keep track of whether the current inputs is a full_window
|
693 |
+
self.is_full_window = is_full_window
|
694 |
+
# keep track of the raw_size_to_cache
|
695 |
+
self.raw_size_to_cache = raw_size_to_cache
|
696 |
+
# involked in self.output()
|
697 |
+
self.all_beacon_sizes.append(beacon_size)
|
698 |
+
# update start_idx and end_idx
|
699 |
+
# NOTE: the update of start_idx will influence self.beacon_window and self.beacon_stride in case self.beacon_skip_last is not None
|
700 |
+
# Therefore, we must make sure all calls to self.beacon_window and self.beacon_stride happen before the update of start_idx
|
701 |
+
self.start_idx = next_start_idx
|
702 |
+
self.end_idx = end_idx
|
703 |
+
self.step_idx += 1
|
704 |
+
|
705 |
+
# print(f"start_idx: {start_idx}")
|
706 |
+
# print(f"next_start_idx: {next_start_idx}")
|
707 |
+
# print(f"beacon_size: {beacon_size}")
|
708 |
+
# print(f"raw_size_to_cache: {raw_size_to_cache}")
|
709 |
+
# print(f"interleave_remainder:{self.interleave_remainder}")
|
710 |
+
# print(f"input_ids: {input_ids}")
|
711 |
+
# print(f"input_len: {input_len}")
|
712 |
+
# print(f"beacon_indices: {beacon_indices}")
|
713 |
+
# print(f"position_ids: {position_ids}")
|
714 |
+
# print(f"attention_mask:\n{attention_mask == 0}")
|
715 |
+
# x = input()
|
716 |
+
# if x == "s":
|
717 |
+
# return
|
718 |
+
|
719 |
+
return input_ids, attention_mask, position_ids, past_key_values, labels
|
720 |
+
|
721 |
+
def update_memory(self, past_key_values):
|
722 |
+
"""
|
723 |
+
Accumulate beacon activations and raw activations.
|
724 |
+
"""
|
725 |
+
for layer_idx, (key, value, beacon_size, beacon_indices) in enumerate(past_key_values):
|
726 |
+
# NOTE: the past_key_values are incrementally returned (only the new keys and values are returned)
|
727 |
+
previous_raw_key, previous_raw_value = self.raw_activations[layer_idx]
|
728 |
+
|
729 |
+
if self.beacon_skip_first is not None and self.sink_activations[layer_idx][0] is None:
|
730 |
+
assert key.shape[self.k_seq_dim] == self.beacon_skip_first
|
731 |
+
assert value.shape[self.k_seq_dim] == self.beacon_skip_first
|
732 |
+
self.sink_activations[layer_idx] = [
|
733 |
+
key,
|
734 |
+
value,
|
735 |
+
]
|
736 |
+
# NOTE: no need to update raw activations and beacon activations as all activations are kept as sink activations
|
737 |
+
continue
|
738 |
+
|
739 |
+
if self.beacon_activations[layer_idx][0] is None and self.config.beacon_sink_size > 0:
|
740 |
+
# save the sink activations
|
741 |
+
# NOTE: we do not slice the key/value activations, which may cause duplication when beacon_ratio=-1 for the first window, but it's okay
|
742 |
+
self.sink_activations[layer_idx] = [
|
743 |
+
slice_tensor(key, end=self.config.beacon_sink_size, dim=self.k_seq_dim),
|
744 |
+
slice_tensor(value, end=self.config.beacon_sink_size, dim=self.v_seq_dim),
|
745 |
+
]
|
746 |
+
|
747 |
+
if not self.is_full_window:
|
748 |
+
# this means the current input does not fulfill a window
|
749 |
+
# thus, the key and value are all raw activations, and we accumulate them until the window is fulfilled
|
750 |
+
assert self.raw_size_to_cache == -1
|
751 |
+
raw_key = cat_tensor([
|
752 |
+
previous_raw_key,
|
753 |
+
key
|
754 |
+
], dim=self.k_seq_dim)
|
755 |
+
raw_value = cat_tensor([
|
756 |
+
previous_raw_value,
|
757 |
+
value
|
758 |
+
], dim=self.v_seq_dim)
|
759 |
+
self.raw_activations[layer_idx] = (raw_key, raw_value)
|
760 |
+
|
761 |
+
else:
|
762 |
+
# NOTE: use the correct previous_beacon_key and value!
|
763 |
+
previous_beacon_key, previous_beacon_value = self.beacon_activations[layer_idx]
|
764 |
+
|
765 |
+
beacon_key, beacon_value, raw_key, raw_value = self._extract_beacon_and_raw_memory(
|
766 |
+
key,
|
767 |
+
value,
|
768 |
+
previous_beacon_key,
|
769 |
+
previous_beacon_value,
|
770 |
+
previous_raw_key,
|
771 |
+
previous_raw_value,
|
772 |
+
beacon_indices,
|
773 |
+
)
|
774 |
+
|
775 |
+
self.beacon_activations[layer_idx] = (beacon_key, beacon_value)
|
776 |
+
self.raw_activations[layer_idx] = (raw_key, raw_value)
|
777 |
+
|
778 |
+
def update_loss(self, batch_loss, valid_token_num):
|
779 |
+
"""
|
780 |
+
Accumulate loss for later perplexity computation and backward pass.
|
781 |
+
"""
|
782 |
+
if self.batch_loss is None:
|
783 |
+
# NOTE: multiply valid_token_num because batch_loss is divided by it in advance
|
784 |
+
self.batch_loss = batch_loss * valid_token_num
|
785 |
+
self.valid_token_num = valid_token_num
|
786 |
+
else:
|
787 |
+
# NOTE: avoid in-place operations, otherwise there will be gradient errors in training
|
788 |
+
self.batch_loss = self.batch_loss + batch_loss * valid_token_num
|
789 |
+
self.valid_token_num = self.valid_token_num + valid_token_num
|
790 |
+
|
791 |
+
def output(self, model_outputs):
|
792 |
+
"""
|
793 |
+
Override loss with accumulated loss. Update the next-token logits.
|
794 |
+
"""
|
795 |
+
# override loss
|
796 |
+
if self.batch_loss is not None:
|
797 |
+
# here the batch_loss is the summation of all token losses in each element
|
798 |
+
loss = self.batch_loss.sum() / self.valid_token_num.sum()
|
799 |
+
|
800 |
+
# NOTE: prevent nan
|
801 |
+
batch_loss = self.batch_loss / self.valid_token_num
|
802 |
+
if (self.valid_token_num == 0).any():
|
803 |
+
batch_loss = batch_loss.masked_fill(self.valid_token_num == 0, 0.)
|
804 |
+
|
805 |
+
# NOTE: we must use dict to override values, otherwise trainer cannot find loss
|
806 |
+
model_outputs["loss"] = loss
|
807 |
+
model_outputs["batch_loss"] = batch_loss
|
808 |
+
|
809 |
+
# override last_hidden_states (used in generation)
|
810 |
+
beacon_size = self.all_beacon_sizes[-1]
|
811 |
+
# remove logits corresponding to beacon tokens
|
812 |
+
if beacon_size > 0:
|
813 |
+
logits = model_outputs["logits"]
|
814 |
+
beacon_indices = self.beacon_indices[-logits.shape[1]:]
|
815 |
+
model_outputs["logits"] = logits[:, beacon_indices == 0]
|
816 |
+
|
817 |
+
return model_outputs
|
818 |
+
|
819 |
+
def _make_4d_attention_mask_and_position_ids(
|
820 |
+
self,
|
821 |
+
attention_mask,
|
822 |
+
position_ids,
|
823 |
+
mem_size,
|
824 |
+
beacon_size,
|
825 |
+
compression_ratio,
|
826 |
+
):
|
827 |
+
"""
|
828 |
+
Convert attention_mask into causal 4D attention_mask (batch_size, head_num, query_len, key_len).
|
829 |
+
"""
|
830 |
+
tgt_size = attention_mask.size(-1) - mem_size
|
831 |
+
dtype = self.dtype
|
832 |
+
min_value = self.min_value
|
833 |
+
device = self._device
|
834 |
+
batch_size, src_size = attention_mask.size()
|
835 |
+
|
836 |
+
# square for memory, and lower triangular for input_ids
|
837 |
+
causal_mask = torch.full((tgt_size, tgt_size), min_value, device=device, dtype=dtype)
|
838 |
+
mask_cond = torch.arange(causal_mask.size(-1), device=device)
|
839 |
+
causal_mask.masked_fill_(mask_cond < (mask_cond + 1).view(causal_mask.size(-1), -1), 0)
|
840 |
+
causal_mask = torch.cat([torch.zeros(tgt_size, mem_size, dtype=dtype, device=device), causal_mask], dim=-1)
|
841 |
+
causal_mask = causal_mask[None, None, ...].expand(batch_size, 1, tgt_size, src_size)
|
842 |
+
# 1 for non-padding tokens
|
843 |
+
expand_mask = attention_mask[:, None, None, :].expand(batch_size, 1, tgt_size, src_size)
|
844 |
+
invert_mask = 1.0 - expand_mask
|
845 |
+
invert_mask.masked_fill_(invert_mask.bool(), min_value)
|
846 |
+
|
847 |
+
attention_mask = causal_mask.masked_fill(invert_mask.bool(), min_value)
|
848 |
+
|
849 |
+
if self.config.beacon_attn == "step-expansion":
|
850 |
+
# each beacon can attend to one more sub-interval than its predecessor
|
851 |
+
|
852 |
+
if self.config.beacon_pos == "append" and beacon_size > 0:
|
853 |
+
window_size = self.beacon_window
|
854 |
+
window_size_with_beacon = window_size + beacon_size
|
855 |
+
beacon_start_idx = -beacon_size
|
856 |
+
# batch_size, head_num, window_size
|
857 |
+
reference_attention_mask = attention_mask[..., -beacon_size - 1, -window_size_with_beacon: -beacon_size]
|
858 |
+
|
859 |
+
# compression_ratio, 2 * compression_ratio, ..., beacon_size * compression_ratio
|
860 |
+
beacon_arange = torch.arange(1, beacon_size + 1, device=device) * compression_ratio
|
861 |
+
# 0, 1, 2, ..., window_size - 1
|
862 |
+
ordinal_arange = torch.arange(window_size, device=device)
|
863 |
+
# beacon_size, window_size
|
864 |
+
valid_pos = ordinal_arange.expand(beacon_size, window_size) < beacon_arange.unsqueeze(-1)
|
865 |
+
# beacon_size, window_size
|
866 |
+
ordinal_attention_mask = torch.where(valid_pos, 0, min_value)
|
867 |
+
# NOTE: add reference attention_mask so that padding tokens are considered
|
868 |
+
ordinal_attention_mask = ordinal_attention_mask[None, None, ...] + reference_attention_mask.unsqueeze(-2)
|
869 |
+
|
870 |
+
if self.config.beacon_attend_prev:
|
871 |
+
beacon_attention_mask = attention_mask.new_full((beacon_size, beacon_size), min_value).triu(1)
|
872 |
+
# the beacon token is next to the last ordinal token it attends to
|
873 |
+
ordinal_position_ids = position_ids[:, -window_size_with_beacon: -beacon_size]
|
874 |
+
beacon_position_ids = ordinal_position_ids[:, compression_ratio - 1::compression_ratio] + torch.arange(1, beacon_size + 1, device=device)[None]
|
875 |
+
position_ids[:, beacon_start_idx:] = beacon_position_ids
|
876 |
+
else:
|
877 |
+
beacon_attention_mask = attention_mask.new_full((beacon_size, beacon_size), min_value).fill_diagonal_(0)
|
878 |
+
# the beacon token is next to the last ordinal token it attends to
|
879 |
+
ordinal_position_ids = position_ids[:, -window_size_with_beacon: -beacon_size]
|
880 |
+
beacon_position_ids = ordinal_position_ids[:, compression_ratio - 1::compression_ratio] + 1
|
881 |
+
position_ids[:, beacon_start_idx:] = beacon_position_ids
|
882 |
+
|
883 |
+
attention_mask[..., beacon_start_idx:, -window_size_with_beacon: -beacon_size] = ordinal_attention_mask
|
884 |
+
attention_mask[..., beacon_start_idx:, beacon_start_idx:] = beacon_attention_mask
|
885 |
+
|
886 |
+
# NOTE: the attention mask should be modified when there is beacon token within the window, not in the input_ids
|
887 |
+
elif self.config.beacon_pos == "interleave" and (self.beacon_indices == 1).any():
|
888 |
+
assert self.config.beacon_attend_prev == False, f"Make sure beacon_attend_prev is False if using 'interleave' beacon pos!"
|
889 |
+
|
890 |
+
beacon_indices = self.beacon_indices
|
891 |
+
|
892 |
+
cur_position_ids = position_ids[:, -len(beacon_indices):]
|
893 |
+
base_position = cur_position_ids[:, 0] - 1
|
894 |
+
# NOTE: alternate position so that the position of raw tokens are consistent
|
895 |
+
position_template = cur_position_ids.new_ones(cur_position_ids.shape)
|
896 |
+
position_template[:, compression_ratio + 1::compression_ratio + 1] = 0
|
897 |
+
cur_position_ids = base_position + position_template.cumsum(-1)
|
898 |
+
position_ids[:, -len(beacon_indices):] = cur_position_ids
|
899 |
+
|
900 |
+
cur_input_length = len(beacon_indices)
|
901 |
+
cur_attention_mask = attention_mask[..., -cur_input_length:, -cur_input_length:]
|
902 |
+
# mask all beacon columns
|
903 |
+
cur_attention_mask[..., beacon_indices] = min_value
|
904 |
+
# beacon tokens can attend to themselves
|
905 |
+
input_ids_attention_mask = cur_attention_mask[..., -tgt_size:, -tgt_size:]
|
906 |
+
input_ids_attention_mask[..., range(tgt_size), range(tgt_size)] = 0
|
907 |
+
|
908 |
+
elif self.config.beacon_attn == "segmentation":
|
909 |
+
# each beacon can attend to its corresponding sub-interval
|
910 |
+
|
911 |
+
if self.config.beacon_pos == "append" and beacon_size > 0:
|
912 |
+
window_size = self.beacon_window
|
913 |
+
window_size_with_beacon = window_size + beacon_size
|
914 |
+
beacon_start_idx = -beacon_size
|
915 |
+
# batch_size, head_num, window_size
|
916 |
+
reference_attention_mask = attention_mask[..., -beacon_size - 1, -window_size_with_beacon: -beacon_size]
|
917 |
+
|
918 |
+
# beacon_size, compression_ratio
|
919 |
+
indices = torch.arange(compression_ratio * beacon_size, device=device).view(beacon_size, -1)
|
920 |
+
# beacon_size, window_size
|
921 |
+
ordinal_attention_mask = attention_mask.new_full((beacon_size, window_size), min_value)
|
922 |
+
ordinal_attention_mask.scatter_(dim=-1, index=indices, value=0)
|
923 |
+
|
924 |
+
# NOTE: add reference attention_mask so that padding tokens are considered
|
925 |
+
ordinal_attention_mask = ordinal_attention_mask[None, None, ...] + reference_attention_mask.unsqueeze(-2)
|
926 |
+
|
927 |
+
if self.config.beacon_attend_prev:
|
928 |
+
beacon_attention_mask = attention_mask.new_full((beacon_size, beacon_size), min_value).triu(1)
|
929 |
+
# the beacon token is next to the last ordinal token it attends to
|
930 |
+
beacon_position_ids = position_ids.new_full(beacon_size, fill_value=compression_ratio + mem_size)
|
931 |
+
beacon_position_ids = beacon_position_ids + torch.arange(beacon_size)
|
932 |
+
position_ids[:, beacon_start_idx:] = beacon_position_ids
|
933 |
+
else:
|
934 |
+
beacon_attention_mask = attention_mask.new_full((beacon_size, beacon_size), min_value).fill_diagonal_(0)
|
935 |
+
# the beacon token is next to the last ordinal token it attends to
|
936 |
+
beacon_position_ids = position_ids.new_full(beacon_size, fill_value=compression_ratio + mem_size)
|
937 |
+
position_ids[:, beacon_start_idx:] = beacon_position_ids
|
938 |
+
|
939 |
+
attention_mask[..., beacon_start_idx:, -window_size_with_beacon: -beacon_size] = ordinal_attention_mask
|
940 |
+
attention_mask[..., beacon_start_idx:, beacon_start_idx:] = beacon_attention_mask
|
941 |
+
# beacons of different ratios are blind to others
|
942 |
+
attention_mask[..., beacon_start_idx:, -beacon_size: beacon_start_idx] = min_value
|
943 |
+
|
944 |
+
elif self.config.beacon_pos == "interleave":
|
945 |
+
raise NotImplementedError
|
946 |
+
|
947 |
+
elif self.config.beacon_attn == "full-coverage":
|
948 |
+
pass
|
949 |
+
|
950 |
+
return attention_mask, position_ids
|
951 |
+
|
952 |
+
def _extract_beacon_and_raw_memory(
|
953 |
+
self,
|
954 |
+
key,
|
955 |
+
value,
|
956 |
+
previous_beacon_key,
|
957 |
+
previous_beacon_value,
|
958 |
+
previous_raw_key,
|
959 |
+
previous_raw_value,
|
960 |
+
beacon_indices,
|
961 |
+
):
|
962 |
+
"""Extract beacon and raw memory from the returned key and value when the window is full."""
|
963 |
+
key = cat_tensor([
|
964 |
+
previous_raw_key,
|
965 |
+
key
|
966 |
+
], dim=self.k_seq_dim)
|
967 |
+
value = cat_tensor([
|
968 |
+
previous_raw_value,
|
969 |
+
value
|
970 |
+
], dim=self.v_seq_dim)
|
971 |
+
|
972 |
+
# NOTE: we use magic slice instead of boolean index here for efficiency
|
973 |
+
beacon_key = slice_tensor(key, index=torch.logical_or(beacon_indices == 1, beacon_indices == -1), dim=self.k_seq_dim)
|
974 |
+
beacon_value = slice_tensor(value, index=torch.logical_or(beacon_indices == 1, beacon_indices == -1), dim=self.v_seq_dim)
|
975 |
+
|
976 |
+
if self.config.beacon_accum:
|
977 |
+
beacon_key = cat_tensor([previous_beacon_key, beacon_key], dim=self.k_seq_dim)
|
978 |
+
beacon_value = cat_tensor([previous_beacon_value, beacon_value], dim=self.v_seq_dim)
|
979 |
+
|
980 |
+
if self.raw_size_to_cache > 0:
|
981 |
+
raw_key = slice_tensor(key, index=beacon_indices == 0, dim=self.k_seq_dim)
|
982 |
+
raw_key = slice_tensor(raw_key, start=-raw_size_to_cache, dim=self.k_seq_dim)
|
983 |
+
|
984 |
+
raw_value = slice_tensor(value, index=beacon_indices == 0, dim=self.v_seq_dim)
|
985 |
+
raw_value = slice_tensor(raw_value, start=-raw_size_to_cache, dim=self.v_seq_dim)
|
986 |
+
|
987 |
+
else:
|
988 |
+
raw_key = None
|
989 |
+
raw_value = None
|
990 |
+
|
991 |
+
return beacon_key, beacon_value, raw_key, raw_value
|
992 |
+
|
993 |
+
|
994 |
+
def slice_tensor(x, start=None, end=None, step=None, index=None, dim=2):
|
995 |
+
if x is None:
|
996 |
+
return None
|
997 |
+
if end == 0:
|
998 |
+
return None
|
999 |
+
if start == x.shape[dim]:
|
1000 |
+
return None
|
1001 |
+
if start is not None and start == end:
|
1002 |
+
return None
|
1003 |
+
if dim == 2:
|
1004 |
+
if index is not None:
|
1005 |
+
return x[:, :, index]
|
1006 |
+
elif start is None and end is not None:
|
1007 |
+
if step is None:
|
1008 |
+
return x[:, :, :end, ...]
|
1009 |
+
else:
|
1010 |
+
return x[:, :, :end:step, ...]
|
1011 |
+
elif start is not None and end is None:
|
1012 |
+
if step is None:
|
1013 |
+
return x[:, :, start:, ...]
|
1014 |
+
else:
|
1015 |
+
return x[:, :, start::step, ...]
|
1016 |
+
elif start is not None and end is not None:
|
1017 |
+
if step is None:
|
1018 |
+
return x[:, :, start:end, ...]
|
1019 |
+
else:
|
1020 |
+
return x[:, :, start:end:step, ...]
|
1021 |
+
elif dim == 1:
|
1022 |
+
if index is not None:
|
1023 |
+
return x[:, :, index]
|
1024 |
+
elif start is None and end is not None:
|
1025 |
+
if step is None:
|
1026 |
+
return x[:, :end, ...]
|
1027 |
+
else:
|
1028 |
+
return x[:, :end:step, ...]
|
1029 |
+
elif start is not None and end is None:
|
1030 |
+
if step is None:
|
1031 |
+
return x[:, start:, ...]
|
1032 |
+
else:
|
1033 |
+
return x[:, start::step, ...]
|
1034 |
+
elif start is not None and end is not None:
|
1035 |
+
if step is None:
|
1036 |
+
return x[:, start:end, ...]
|
1037 |
+
else:
|
1038 |
+
return x[:, start:end:step, ...]
|
1039 |
+
else:
|
1040 |
+
raise NotImplementedError
|
1041 |
+
|
1042 |
+
def cat_tensor(list_of_tensors, dim=-1):
|
1043 |
+
list_of_tensors = [t for t in list_of_tensors if t is not None]
|
1044 |
+
if len(list_of_tensors) > 1:
|
1045 |
+
result = torch.cat(list_of_tensors, dim=dim)
|
1046 |
+
elif len(list_of_tensors) == 1:
|
1047 |
+
result = list_of_tensors[0]
|
1048 |
+
else:
|
1049 |
+
result = None
|
1050 |
+
return result
|
1051 |
+
|
1052 |
+
def slice_activations(activations, start=None, end=None, k_seq_dim=2, v_seq_dim=2):
|
1053 |
+
new_activations = []
|
1054 |
+
for key, value in activations:
|
1055 |
+
new_key = slice_tensor(key, start=start, end=end, dim=k_seq_dim)
|
1056 |
+
new_value = slice_tensor(value, start=start, end=end, dim=v_seq_dim)
|
1057 |
+
new_activations.append([new_key, new_value])
|
1058 |
+
return new_activations
|
1059 |
+
|
1060 |
+
def cat_activations(list_of_activations, k_seq_dim=2, v_seq_dim=2):
|
1061 |
+
assert all(len(x) == len(list_of_activations[0]) for x in list_of_activations), f"Make sure all activations have the same number of layers! Found {[len(x) for x in list_of_activations]}."
|
1062 |
+
|
1063 |
+
new_activations = []
|
1064 |
+
for layer_idx in range(len(list_of_activations[0])):
|
1065 |
+
keys = [x[layer_idx][0] for x in list_of_activations]
|
1066 |
+
values = [x[layer_idx][1] for x in list_of_activations]
|
1067 |
+
|
1068 |
+
new_key = cat_tensor(keys, dim=k_seq_dim)
|
1069 |
+
new_value = cat_tensor(values, dim=v_seq_dim)
|
1070 |
+
new_activations.append([new_key, new_value])
|
1071 |
+
return new_activations
|
1072 |
+
|
1073 |
+
def interleave_activations(main_activations, augment_activations, main_spans, augment_spans, k_seq_dim=2, v_seq_dim=2, device=torch.device("cuda")):
|
1074 |
+
""" Interleave main_activations and augment_activations according to main_span and augment_span.
|
1075 |
+
|
1076 |
+
Args:
|
1077 |
+
main_span: a list of tuples (start_idx, end_idx). when start_idx and end_idx is None, the augment_activations will be plugged in.
|
1078 |
+
augment_span: a list of tuples (start_idx, end_idx)
|
1079 |
+
"""
|
1080 |
+
assert len(main_activations) == len(augment_activations) , f"Make sure main and augment activations have the same number of layers! Found {len(main_activations)} and {len(augment_activations)}!"
|
1081 |
+
assert sum(x[0] is None and x[1] is None for x in main_spans) == len(augment_spans), f"Make sure the number of slots for augmentation (start_idx=None and end_idx=None in main_spans) matches the number of augmentations. Found {sum(x for x in main_spans if x[0] is None and x[1] is None)} slots but {len(augment_spans)} augmentations!"
|
1082 |
+
|
1083 |
+
new_activations = []
|
1084 |
+
for layer_idx in range(len(main_activations)):
|
1085 |
+
main_key, main_value = main_activations[layer_idx]
|
1086 |
+
augment_key, augment_value = augment_activations[layer_idx]
|
1087 |
+
|
1088 |
+
sliced_keys = []
|
1089 |
+
sliced_values = []
|
1090 |
+
|
1091 |
+
augment_idx = 0
|
1092 |
+
for start, end in main_spans:
|
1093 |
+
if start is None and end is None:
|
1094 |
+
# this means the augment key/value should be plugged in
|
1095 |
+
augment_start, augment_end = augment_spans[augment_idx]
|
1096 |
+
sliced_key = slice_tensor(
|
1097 |
+
augment_key,
|
1098 |
+
start=augment_start,
|
1099 |
+
end=augment_end,
|
1100 |
+
dim=k_seq_dim
|
1101 |
+
).to(device)
|
1102 |
+
sliced_value = slice_tensor(
|
1103 |
+
augment_value,
|
1104 |
+
start=augment_start,
|
1105 |
+
end=augment_end,
|
1106 |
+
dim=v_seq_dim
|
1107 |
+
).to(device)
|
1108 |
+
|
1109 |
+
else:
|
1110 |
+
sliced_key = slice_tensor(
|
1111 |
+
main_key,
|
1112 |
+
start=start,
|
1113 |
+
end=end,
|
1114 |
+
dim=k_seq_dim
|
1115 |
+
)
|
1116 |
+
sliced_value = slice_tensor(
|
1117 |
+
main_value,
|
1118 |
+
start=start,
|
1119 |
+
end=end,
|
1120 |
+
dim=v_seq_dim
|
1121 |
+
)
|
1122 |
+
|
1123 |
+
sliced_keys.append(sliced_key)
|
1124 |
+
sliced_values.append(sliced_value)
|
1125 |
+
|
1126 |
+
new_key = cat_tensor(sliced_keys, dim=k_seq_dim)
|
1127 |
+
new_value = cat_tensor(sliced_values, dim=v_seq_dim)
|
1128 |
+
new_activations.append([new_key, new_value])
|
1129 |
+
|
1130 |
+
return new_activations
|
1131 |
+
|
1132 |
+
def softmax(x:np.ndarray, axis=-1, temperature=1):
|
1133 |
+
if isinstance(x, list):
|
1134 |
+
x = np.array(x)
|
1135 |
+
x = x / temperature
|
1136 |
+
x = x - x.max(axis=axis, keepdims=True)
|
1137 |
+
y = np.exp(x)
|
1138 |
+
return y / y.sum(axis=axis, keepdims=True)
|
1139 |
+
|
1140 |
+
def l1_norm(x):
|
1141 |
+
sum_x = sum(x)
|
1142 |
+
x = [y/sum_x for y in x]
|
1143 |
+
return x
|
modeling_mistral.py
ADDED
@@ -0,0 +1,1297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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rights reserved.
|
3 |
+
#
|
4 |
+
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
|
5 |
+
# and OPT implementations in this library. It has been modified from its
|
6 |
+
# original forms to accommodate minor architectural differences compared
|
7 |
+
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
|
8 |
+
#
|
9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10 |
+
# you may not use this file except in compliance with the License.
|
11 |
+
# You may obtain a copy of the License at
|
12 |
+
#
|
13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14 |
+
#
|
15 |
+
# Unless required by applicable law or agreed to in writing, software
|
16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18 |
+
# See the License for the specific language governing permissions and
|
19 |
+
# limitations under the License.
|
20 |
+
""" PyTorch Mistral model."""
|
21 |
+
import inspect
|
22 |
+
import math
|
23 |
+
import warnings
|
24 |
+
from typing import List, Optional, Tuple, Union
|
25 |
+
|
26 |
+
import torch
|
27 |
+
import torch.nn.functional as F
|
28 |
+
import torch.utils.checkpoint
|
29 |
+
from torch import nn
|
30 |
+
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
|
31 |
+
|
32 |
+
from transformers.activations import ACT2FN
|
33 |
+
from transformers.cache_utils import Cache
|
34 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
|
35 |
+
from transformers.modeling_utils import PreTrainedModel
|
36 |
+
from transformers.utils import (
|
37 |
+
add_start_docstrings,
|
38 |
+
add_start_docstrings_to_model_forward,
|
39 |
+
is_flash_attn_2_available,
|
40 |
+
is_flash_attn_greater_or_equal_2_10,
|
41 |
+
logging,
|
42 |
+
replace_return_docstrings,
|
43 |
+
)
|
44 |
+
from transformers.integrations import is_deepspeed_zero3_enabled
|
45 |
+
from .configuration_mistral import MistralConfig
|
46 |
+
|
47 |
+
|
48 |
+
if is_flash_attn_2_available():
|
49 |
+
from flash_attn import flash_attn_func, flash_attn_varlen_func
|
50 |
+
from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
51 |
+
|
52 |
+
_flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
|
53 |
+
|
54 |
+
from .modeling_beacon import Memory
|
55 |
+
from .modeling_utils import optional_grad_ctx, compute_loss, get_rope, ModelOutput
|
56 |
+
|
57 |
+
|
58 |
+
logger = logging.get_logger(__name__)
|
59 |
+
|
60 |
+
_CONFIG_FOR_DOC = "MistralConfig"
|
61 |
+
|
62 |
+
# Copied from transformers.models.llama.modeling_llama._get_unpad_data
|
63 |
+
def _get_unpad_data(attention_mask):
|
64 |
+
seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
|
65 |
+
indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
|
66 |
+
max_seqlen_in_batch = seqlens_in_batch.max().item()
|
67 |
+
cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0))
|
68 |
+
return (
|
69 |
+
indices,
|
70 |
+
cu_seqlens,
|
71 |
+
max_seqlen_in_batch,
|
72 |
+
)
|
73 |
+
|
74 |
+
|
75 |
+
# Copied from transformers.models.llama.modeling_llama.MistralRMSNorm with Mistral->Mistral
|
76 |
+
class MistralRMSNorm(nn.Module):
|
77 |
+
def __init__(self, hidden_size, eps=1e-6):
|
78 |
+
"""
|
79 |
+
MistralRMSNorm is equivalent to T5LayerNorm
|
80 |
+
"""
|
81 |
+
super().__init__()
|
82 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
83 |
+
self.variance_epsilon = eps
|
84 |
+
|
85 |
+
def forward(self, hidden_states):
|
86 |
+
input_dtype = hidden_states.dtype
|
87 |
+
hidden_states = hidden_states.to(torch.float32)
|
88 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
89 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
90 |
+
return self.weight * hidden_states.to(input_dtype)
|
91 |
+
|
92 |
+
|
93 |
+
# Copied from transformers.models.mistral.modeling_mistral.MistralMLP with Mistral->Mistral
|
94 |
+
class MistralMLP(nn.Module):
|
95 |
+
def __init__(self, config):
|
96 |
+
super().__init__()
|
97 |
+
self.config = config
|
98 |
+
self.hidden_size = config.hidden_size
|
99 |
+
self.intermediate_size = config.intermediate_size
|
100 |
+
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
101 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
102 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
|
103 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
104 |
+
|
105 |
+
def forward(self, x):
|
106 |
+
down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
107 |
+
return down_proj
|
108 |
+
|
109 |
+
|
110 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
111 |
+
"""
|
112 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
113 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
114 |
+
"""
|
115 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
116 |
+
if n_rep == 1:
|
117 |
+
return hidden_states
|
118 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
119 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
120 |
+
|
121 |
+
|
122 |
+
class MistralAttention(nn.Module):
|
123 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
124 |
+
|
125 |
+
def __init__(self, config: MistralConfig, layer_idx: Optional[int] = None):
|
126 |
+
super().__init__()
|
127 |
+
self.config = config
|
128 |
+
self.layer_idx = layer_idx
|
129 |
+
if layer_idx is None:
|
130 |
+
logger.warning_once(
|
131 |
+
f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
|
132 |
+
"to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
|
133 |
+
"when creating this class."
|
134 |
+
)
|
135 |
+
|
136 |
+
self.attention_dropout = config.attention_dropout
|
137 |
+
self.hidden_size = config.hidden_size
|
138 |
+
self.num_heads = config.num_attention_heads
|
139 |
+
self.head_dim = self.hidden_size // self.num_heads
|
140 |
+
self.num_key_value_heads = config.num_key_value_heads
|
141 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
142 |
+
self.max_position_embeddings = config.max_position_embeddings
|
143 |
+
self.rope_theta = config.rope_theta
|
144 |
+
self.is_causal = True
|
145 |
+
|
146 |
+
if (self.head_dim * self.num_heads) != self.hidden_size:
|
147 |
+
raise ValueError(
|
148 |
+
f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
|
149 |
+
f" and `num_heads`: {self.num_heads})."
|
150 |
+
)
|
151 |
+
self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=False)
|
152 |
+
self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False)
|
153 |
+
self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False)
|
154 |
+
self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
|
155 |
+
|
156 |
+
self.rotary_emb = get_rope(self.head_dim, config.rope_theta, config.max_position_embeddings, getattr(config, "rope_scaling", None))
|
157 |
+
|
158 |
+
# NOTE: add extra parameters for beacon tokens
|
159 |
+
# skip post initialization to speed up loading
|
160 |
+
if "q" in config.beacon_param:
|
161 |
+
self.beacon_q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=self.q_proj.bias is not None)
|
162 |
+
# NOTE: initialize the beacon parameters as zero
|
163 |
+
self.beacon_q_proj.weight.data.zero_()
|
164 |
+
self.beacon_q_proj._is_hf_initialized = True
|
165 |
+
if "k" in config.beacon_param:
|
166 |
+
self.beacon_k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=self.k_proj.bias is not None)
|
167 |
+
self.beacon_k_proj.weight.data.zero_()
|
168 |
+
self.beacon_k_proj._is_hf_initialized = True
|
169 |
+
if "v" in config.beacon_param:
|
170 |
+
self.beacon_v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=self.v_proj.bias is not None)
|
171 |
+
self.beacon_v_proj.weight.data.zero_()
|
172 |
+
self.beacon_v_proj._is_hf_initialized = True
|
173 |
+
if "o" in config.beacon_param:
|
174 |
+
self.beacon_o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=self.o_proj.bias is not None)
|
175 |
+
self.beacon_o_proj.weight.data.zero_()
|
176 |
+
self.beacon_o_proj._is_hf_initialized = True
|
177 |
+
|
178 |
+
def _init_beacon_proj(self, missing_keys):
|
179 |
+
"""Initialize the beacon projection weight with that of the ordinal projection."""
|
180 |
+
beacon_param = self.config.beacon_param
|
181 |
+
|
182 |
+
if is_deepspeed_zero3_enabled():
|
183 |
+
# FIXME: after deepspeed initialization, some weights becomes non-zero
|
184 |
+
# For Mistral, there are rows that are full of zeros
|
185 |
+
# For Mistral, there are values bigger than 1e29...
|
186 |
+
|
187 |
+
import deepspeed
|
188 |
+
if "q" in beacon_param:
|
189 |
+
params = [self.beacon_q_proj.weight, self.q_proj.weight]
|
190 |
+
if self.q_proj.bias is not None:
|
191 |
+
params.extend([self.beacon_q_proj.bias, self.q_proj.bias])
|
192 |
+
with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
|
193 |
+
# FIXME: after deepspeed initialization, some weights becomes non-zero, but there are rows that are full of zeros
|
194 |
+
if (self.beacon_q_proj.weight.sum(-1) == 0).any() or (self.beacon_q_proj.weight > 1e29).any():
|
195 |
+
self.beacon_q_proj.weight.data[:] = self.q_proj.weight.data
|
196 |
+
if self.q_proj.bias is not None:
|
197 |
+
self.beacon_q_proj.bias.data[:] = self.q_proj.bias.data
|
198 |
+
if "k" in beacon_param:
|
199 |
+
params = [self.beacon_k_proj.weight, self.k_proj.weight]
|
200 |
+
if self.k_proj.bias is not None:
|
201 |
+
params.extend([self.beacon_k_proj.bias, self.k_proj.bias])
|
202 |
+
with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
|
203 |
+
# FIXME: after deepspeed initialization, some weights becomes non-zero, but there are rows that are full of zeros
|
204 |
+
if (self.beacon_k_proj.weight.sum(-1) == 0).any() or (self.beacon_k_proj.weight > 1e29).any():
|
205 |
+
self.beacon_k_proj.weight.data[:] = self.k_proj.weight.data
|
206 |
+
if self.k_proj.bias is not None:
|
207 |
+
self.beacon_k_proj.bias.data[:] = self.k_proj.bias.data
|
208 |
+
if "v" in beacon_param:
|
209 |
+
params = [self.beacon_v_proj.weight, self.v_proj.weight]
|
210 |
+
if self.v_proj.bias is not None:
|
211 |
+
params.extend([self.beacon_v_proj.bias, self.v_proj.bias])
|
212 |
+
with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
|
213 |
+
# FIXME: after deepspeed initialization, some weights becomes non-zero, but there are rows that are full of zeros
|
214 |
+
if (self.beacon_v_proj.weight.sum(-1) == 0).any() or (self.beacon_v_proj.weight > 1e29).any():
|
215 |
+
self.beacon_v_proj.weight.data[:] = self.v_proj.weight.data
|
216 |
+
if self.v_proj.bias is not None:
|
217 |
+
self.beacon_v_proj.bias.data[:] = self.v_proj.bias.data
|
218 |
+
if "o" in beacon_param:
|
219 |
+
params = [self.beacon_o_proj.weight, self.o_proj.weight]
|
220 |
+
if self.o_proj.bias is not None:
|
221 |
+
params.extend([self.beacon_o_proj.bias, self.o_proj.bias])
|
222 |
+
with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
|
223 |
+
# FIXME: after deepspeed initialization, some weights becomes non-zero, but there are rows that are full of zeros
|
224 |
+
if (self.beacon_o_proj.weight.sum(-1) == 0).any() or (self.beacon_o_proj.weight > 1e29).any():
|
225 |
+
self.beacon_o_proj.weight.data[:] = self.o_proj.weight.data
|
226 |
+
if self.o_proj.bias is not None:
|
227 |
+
self.beacon_o_proj.bias.data[:] = self.o_proj.bias.data
|
228 |
+
else:
|
229 |
+
# only copy the value in-place, without tieing the weight
|
230 |
+
if "q" in beacon_param and any("beacon_q_proj" in missing_key for missing_key in missing_keys):
|
231 |
+
# FIXME: some beacon weights are not initialized as zero for mistral model, why?
|
232 |
+
# if (self.beacon_q_proj.weight == 0).all():
|
233 |
+
self.beacon_q_proj.weight.data[:] = self.q_proj.weight.data
|
234 |
+
if self.q_proj.bias is not None:
|
235 |
+
self.beacon_q_proj.bias.data[:] = self.q_proj.bias.data
|
236 |
+
if "k" in beacon_param and any("beacon_k_proj" in missing_key for missing_key in missing_keys):
|
237 |
+
# if (self.beacon_k_proj.weight == 0).all():
|
238 |
+
self.beacon_k_proj.weight.data[:] = self.k_proj.weight.data
|
239 |
+
if self.k_proj.bias is not None:
|
240 |
+
self.beacon_k_proj.bias.data[:] = self.k_proj.bias.data
|
241 |
+
if "v" in beacon_param and any("beacon_v_proj" in missing_key for missing_key in missing_keys):
|
242 |
+
# if (self.beacon_v_proj.weight == 0).all():
|
243 |
+
self.beacon_v_proj.weight.data[:] = self.v_proj.weight.data
|
244 |
+
if self.v_proj.bias is not None:
|
245 |
+
self.beacon_v_proj.bias.data[:] = self.v_proj.bias.data
|
246 |
+
if "o" in beacon_param and any("beacon_o_proj" in missing_key for missing_key in missing_keys):
|
247 |
+
# if (self.beacon_o_proj.weight == 0).all():
|
248 |
+
self.beacon_o_proj.weight.data[:] = self.o_proj.weight.data
|
249 |
+
if self.o_proj.bias is not None:
|
250 |
+
self.beacon_o_proj.bias.data[:] = self.o_proj.bias.data
|
251 |
+
|
252 |
+
def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
|
253 |
+
return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
|
254 |
+
|
255 |
+
def qkv_proj_with_beacon(self, hidden_states, beacon_size, beacon_indices):
|
256 |
+
if beacon_size > 0:
|
257 |
+
# NOTE: when beacon_pos == "interleave", the beacon_indices points to all beacon tokens in the current window (cached activations + input_ids), so we shall slice out the part corresponding to the input_ids
|
258 |
+
cur_beacon_indices = beacon_indices[-hidden_states.shape[1]:]
|
259 |
+
|
260 |
+
# NOTE: there is slight redundant computation because ordinal tokens should never be projected by beacon matrices, but we are doing this for efficiency
|
261 |
+
if "q" in self.config.beacon_param:
|
262 |
+
ordinal_query_states = self.q_proj(hidden_states)
|
263 |
+
beacon_query_states = self.beacon_q_proj(hidden_states)
|
264 |
+
query_states = torch.where((cur_beacon_indices == 0)[:, None], ordinal_query_states, beacon_query_states)
|
265 |
+
if (cur_beacon_indices == 2).any():
|
266 |
+
# beacon_indices == 2 means the beacon token is used to replicate the ones in previous window for parallel encoding
|
267 |
+
# we should slice out all beacon tokens then copy them to the replicate beacon tokens
|
268 |
+
query_states[:, cur_beacon_indices == 2] = beacon_query_states[:, cur_beacon_indices == 1][:, :(cur_beacon_indices == 2).sum()]
|
269 |
+
else:
|
270 |
+
query_states = self.q_proj(hidden_states)
|
271 |
+
|
272 |
+
if "k" in self.config.beacon_param:
|
273 |
+
ordinal_key_states = self.k_proj(hidden_states)
|
274 |
+
beacon_key_states = self.beacon_k_proj(hidden_states)
|
275 |
+
key_states = torch.where((cur_beacon_indices == 0)[:, None], ordinal_key_states, beacon_key_states)
|
276 |
+
if (cur_beacon_indices == 2).any():
|
277 |
+
# beacon_indices == 2 means the beacon token is used to replicate the ones in previous window for parallel encoding
|
278 |
+
# we should slice out all beacon tokens then copy them to the replicate beacon tokens
|
279 |
+
key_states[:, cur_beacon_indices == 2] = beacon_key_states[:, cur_beacon_indices == 1][:, :(cur_beacon_indices == 2).sum()]
|
280 |
+
else:
|
281 |
+
key_states = self.k_proj(hidden_states)
|
282 |
+
|
283 |
+
if "v" in self.config.beacon_param:
|
284 |
+
ordinal_value_states = self.v_proj(hidden_states)
|
285 |
+
beacon_value_states = self.beacon_v_proj(hidden_states)
|
286 |
+
value_states = torch.where((cur_beacon_indices == 0)[:, None], ordinal_value_states, beacon_value_states)
|
287 |
+
if (cur_beacon_indices == 2).any():
|
288 |
+
# beacon_indices == 2 means the beacon token is used to replicate the ones in previous window for parallel encoding
|
289 |
+
# we should slice out all beacon tokens then copy them to the replicate beacon tokens
|
290 |
+
value_states[:, cur_beacon_indices == 2] = beacon_value_states[:, cur_beacon_indices == 1][:, :(cur_beacon_indices == 2).sum()]
|
291 |
+
else:
|
292 |
+
value_states = self.v_proj(hidden_states)
|
293 |
+
|
294 |
+
else:
|
295 |
+
query_states = self.q_proj(hidden_states)
|
296 |
+
key_states = self.k_proj(hidden_states)
|
297 |
+
value_states = self.v_proj(hidden_states)
|
298 |
+
|
299 |
+
return query_states, key_states, value_states
|
300 |
+
|
301 |
+
def o_proj_with_beacon(self, attn_output, beacon_size, beacon_indices):
|
302 |
+
if beacon_size > 0:
|
303 |
+
# NOTE: when beacon_pos == "interleave", the beacon_indices points to all beacon tokens in the current window (cached activations + input_ids), so we shall slice out the part corresponding to the input_ids
|
304 |
+
cur_beacon_indices = beacon_indices[-attn_output.shape[1]:]
|
305 |
+
|
306 |
+
if "o" in self.config.beacon_param:
|
307 |
+
ordinal_attn_output = self.o_proj(attn_output)
|
308 |
+
beacon_attn_output = self.beacon_o_proj(attn_output)
|
309 |
+
attn_output = torch.where((cur_beacon_indices == 0)[:, None], ordinal_attn_output, beacon_attn_output)
|
310 |
+
else:
|
311 |
+
attn_output = self.o_proj(attn_output)
|
312 |
+
else:
|
313 |
+
attn_output = self.o_proj(attn_output)
|
314 |
+
return attn_output
|
315 |
+
|
316 |
+
def forward(
|
317 |
+
self,
|
318 |
+
hidden_states: torch.Tensor,
|
319 |
+
attention_mask: Optional[torch.Tensor] = None,
|
320 |
+
position_ids: Optional[torch.LongTensor] = None,
|
321 |
+
past_key_value: Optional[Cache] = None,
|
322 |
+
output_attentions: bool = False,
|
323 |
+
use_cache: bool = False,
|
324 |
+
**kwargs,
|
325 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
326 |
+
if "padding_mask" in kwargs:
|
327 |
+
warnings.warn(
|
328 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
329 |
+
)
|
330 |
+
|
331 |
+
bsz, q_len, _ = hidden_states.size()
|
332 |
+
kv_seq_len = hidden_states.shape[-2]
|
333 |
+
past_key, past_value, beacon_size, beacon_indices = past_key_value
|
334 |
+
|
335 |
+
if past_key is not None:
|
336 |
+
past_seq_len = past_key.shape[2]
|
337 |
+
kv_seq_len += past_seq_len
|
338 |
+
else:
|
339 |
+
past_seq_len = 0
|
340 |
+
|
341 |
+
query_states, key_states, value_states = self.qkv_proj_with_beacon(hidden_states, beacon_size, beacon_indices)
|
342 |
+
|
343 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
344 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
345 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
346 |
+
|
347 |
+
# return keys and values before rope
|
348 |
+
# NOTE: incrementally return keys and values for efficiency
|
349 |
+
past_key_value = (key_states, value_states, beacon_size, beacon_indices)
|
350 |
+
|
351 |
+
if past_key is not None:
|
352 |
+
# reuse k, v, self_attention
|
353 |
+
key_states = torch.cat([past_key, key_states], dim=2)
|
354 |
+
value_states = torch.cat([past_value, value_states], dim=2)
|
355 |
+
|
356 |
+
query_states, key_states = self.rotary_emb(query_states, key_states, position_ids)
|
357 |
+
|
358 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
359 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
360 |
+
|
361 |
+
attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
|
362 |
+
|
363 |
+
if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
|
364 |
+
raise ValueError(
|
365 |
+
f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
|
366 |
+
f" {attn_weights.size()}"
|
367 |
+
)
|
368 |
+
|
369 |
+
if attention_mask is not None:
|
370 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
371 |
+
raise ValueError(
|
372 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
373 |
+
)
|
374 |
+
attn_weights = attn_weights + attention_mask
|
375 |
+
|
376 |
+
# upcast attention to fp32
|
377 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
|
378 |
+
attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
|
379 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
380 |
+
|
381 |
+
if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
|
382 |
+
raise ValueError(
|
383 |
+
f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
|
384 |
+
f" {attn_output.size()}"
|
385 |
+
)
|
386 |
+
|
387 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
388 |
+
|
389 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
390 |
+
|
391 |
+
attn_output = self.o_proj_with_beacon(attn_output, beacon_size, beacon_indices)
|
392 |
+
|
393 |
+
if not output_attentions:
|
394 |
+
attn_weights = None
|
395 |
+
|
396 |
+
return attn_output, attn_weights, past_key_value
|
397 |
+
|
398 |
+
|
399 |
+
class MistralSdpaAttention(MistralAttention):
|
400 |
+
"""
|
401 |
+
Mistral attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
|
402 |
+
`MistralAttention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
|
403 |
+
SDPA API.
|
404 |
+
"""
|
405 |
+
|
406 |
+
# Adapted from MistralAttention.forward
|
407 |
+
def forward(
|
408 |
+
self,
|
409 |
+
hidden_states: torch.Tensor,
|
410 |
+
attention_mask: Optional[torch.Tensor] = None,
|
411 |
+
position_ids: Optional[torch.LongTensor] = None,
|
412 |
+
past_key_value: Optional[Cache] = None,
|
413 |
+
output_attentions: bool = False,
|
414 |
+
use_cache: bool = False,
|
415 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
416 |
+
if output_attentions:
|
417 |
+
# TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
|
418 |
+
logger.warning_once(
|
419 |
+
"MistralModel is using MistralSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
|
420 |
+
'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
|
421 |
+
)
|
422 |
+
return super().forward(
|
423 |
+
hidden_states=hidden_states,
|
424 |
+
attention_mask=attention_mask,
|
425 |
+
position_ids=position_ids,
|
426 |
+
past_key_value=past_key_value,
|
427 |
+
output_attentions=output_attentions,
|
428 |
+
use_cache=use_cache,
|
429 |
+
)
|
430 |
+
bsz, q_len, _ = hidden_states.size()
|
431 |
+
kv_seq_len = hidden_states.shape[-2]
|
432 |
+
past_key, past_value, beacon_size, beacon_indices = past_key_value
|
433 |
+
if past_key is not None:
|
434 |
+
past_seq_len = past_key.shape[2]
|
435 |
+
kv_seq_len += past_seq_len
|
436 |
+
else:
|
437 |
+
past_seq_len = 0
|
438 |
+
|
439 |
+
query_states, key_states, value_states = self.qkv_proj_with_beacon(hidden_states, beacon_size, beacon_indices)
|
440 |
+
|
441 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
442 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
443 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
444 |
+
|
445 |
+
# return keys and values before rope
|
446 |
+
# NOTE: incrementally return keys and values for efficiency
|
447 |
+
past_key_value = (key_states, value_states, beacon_size, beacon_indices)
|
448 |
+
|
449 |
+
if past_key is not None:
|
450 |
+
# reuse k, v, self_attention
|
451 |
+
key_states = torch.cat([past_key, key_states], dim=2)
|
452 |
+
value_states = torch.cat([past_value, value_states], dim=2)
|
453 |
+
|
454 |
+
query_states, key_states = self.rotary_emb(query_states, key_states, position_ids)
|
455 |
+
|
456 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
457 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
458 |
+
|
459 |
+
if attention_mask is not None:
|
460 |
+
if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
|
461 |
+
raise ValueError(
|
462 |
+
f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
|
463 |
+
)
|
464 |
+
|
465 |
+
# SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
|
466 |
+
# Reference: https://github.com/pytorch/pytorch/issues/112577.
|
467 |
+
if query_states.device.type == "cuda" and attention_mask is not None:
|
468 |
+
query_states = query_states.contiguous()
|
469 |
+
key_states = key_states.contiguous()
|
470 |
+
value_states = value_states.contiguous()
|
471 |
+
|
472 |
+
attn_output = torch.nn.functional.scaled_dot_product_attention(
|
473 |
+
query_states,
|
474 |
+
key_states,
|
475 |
+
value_states,
|
476 |
+
attn_mask=attention_mask,
|
477 |
+
dropout_p=self.attention_dropout if self.training else 0.0,
|
478 |
+
# The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
|
479 |
+
is_causal=self.is_causal and attention_mask is None and q_len > 1,
|
480 |
+
)
|
481 |
+
|
482 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
483 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
|
484 |
+
attn_output = self.o_proj_with_beacon(attn_output, beacon_size, beacon_indices)
|
485 |
+
|
486 |
+
return attn_output, None, past_key_value
|
487 |
+
|
488 |
+
|
489 |
+
class MistralFlashAttention2(MistralAttention):
|
490 |
+
"""
|
491 |
+
Mistral flash attention module. This module inherits from `MistralAttention` as the weights of the module stays
|
492 |
+
untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
|
493 |
+
flash attention and deal with padding tokens in case the input contains any of them.
|
494 |
+
"""
|
495 |
+
|
496 |
+
def __init__(self, *args, **kwargs):
|
497 |
+
super().__init__(*args, **kwargs)
|
498 |
+
|
499 |
+
# TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
|
500 |
+
# flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
|
501 |
+
# Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
|
502 |
+
self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
|
503 |
+
|
504 |
+
def forward(
|
505 |
+
self,
|
506 |
+
hidden_states: torch.Tensor,
|
507 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
508 |
+
position_ids: Optional[torch.LongTensor] = None,
|
509 |
+
past_key_value: Optional[Cache] = None,
|
510 |
+
output_attentions: bool = False,
|
511 |
+
use_cache: bool = False,
|
512 |
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
|
513 |
+
output_attentions = False
|
514 |
+
|
515 |
+
bsz, q_len, _ = hidden_states.size()
|
516 |
+
kv_seq_len = hidden_states.shape[-2]
|
517 |
+
|
518 |
+
past_key, past_value, beacon_size, beacon_indices = past_key_value
|
519 |
+
if past_key is not None:
|
520 |
+
past_seq_len = past_key.shape[2]
|
521 |
+
kv_seq_len += past_seq_len
|
522 |
+
else:
|
523 |
+
past_seq_len = 0
|
524 |
+
|
525 |
+
query_states, key_states, value_states = self.qkv_proj_with_beacon(hidden_states, beacon_size, beacon_indices)
|
526 |
+
|
527 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
528 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
529 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
530 |
+
|
531 |
+
# return keys and values before rope
|
532 |
+
# NOTE: incrementally return keys and values for efficiency
|
533 |
+
past_key_value = (key_states, value_states, beacon_size, beacon_indices)
|
534 |
+
|
535 |
+
if past_key is not None:
|
536 |
+
# reuse k, v, self_attention
|
537 |
+
key_states = torch.cat([past_key, key_states], dim=2)
|
538 |
+
value_states = torch.cat([past_value, value_states], dim=2)
|
539 |
+
|
540 |
+
query_states, key_states = self.rotary_emb(query_states, key_states, position_ids)
|
541 |
+
|
542 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
543 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
544 |
+
|
545 |
+
# TODO: These transpose are quite inefficient but Flash Attention requires the layout [batch_size, sequence_length, num_heads, head_dim]. We would need to refactor the KV cache
|
546 |
+
# to be able to avoid many of these transpose/reshape/view.
|
547 |
+
query_states = query_states.transpose(1, 2)
|
548 |
+
key_states = key_states.transpose(1, 2)
|
549 |
+
value_states = value_states.transpose(1, 2)
|
550 |
+
|
551 |
+
dropout_rate = self.attention_dropout if self.training else 0.0
|
552 |
+
|
553 |
+
# In PEFT, usually we cast the layer norms in float32 for training stability reasons
|
554 |
+
# therefore the input hidden states gets silently casted in float32. Hence, we need
|
555 |
+
# cast them back in the correct dtype just to be sure everything works as expected.
|
556 |
+
# This might slowdown training & inference so it is recommended to not cast the LayerNorms
|
557 |
+
# in fp32. (MistralRMSNorm handles it correctly)
|
558 |
+
|
559 |
+
input_dtype = query_states.dtype
|
560 |
+
if input_dtype == torch.float32:
|
561 |
+
if torch.is_autocast_enabled():
|
562 |
+
target_dtype = torch.get_autocast_gpu_dtype()
|
563 |
+
# Handle the case where the model is quantized
|
564 |
+
elif hasattr(self.config, "_pre_quantization_dtype"):
|
565 |
+
target_dtype = self.config._pre_quantization_dtype
|
566 |
+
else:
|
567 |
+
target_dtype = self.q_proj.weight.dtype
|
568 |
+
|
569 |
+
logger.warning_once(
|
570 |
+
f"The input hidden states seems to be silently casted in float32, this might be related to"
|
571 |
+
f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
|
572 |
+
f" {target_dtype}."
|
573 |
+
)
|
574 |
+
|
575 |
+
query_states = query_states.to(target_dtype)
|
576 |
+
key_states = key_states.to(target_dtype)
|
577 |
+
value_states = value_states.to(target_dtype)
|
578 |
+
|
579 |
+
attn_output = self._flash_attention_forward(
|
580 |
+
query_states,
|
581 |
+
key_states,
|
582 |
+
value_states,
|
583 |
+
attention_mask,
|
584 |
+
q_len,
|
585 |
+
dropout=dropout_rate
|
586 |
+
)
|
587 |
+
|
588 |
+
attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
|
589 |
+
attn_output = self.o_proj_with_beacon(attn_output, beacon_size, beacon_indices)
|
590 |
+
|
591 |
+
if not output_attentions:
|
592 |
+
attn_weights = None
|
593 |
+
|
594 |
+
return attn_output, attn_weights, past_key_value
|
595 |
+
|
596 |
+
def _flash_attention_forward(
|
597 |
+
self, query_states, key_states, value_states, attention_mask, query_length, dropout=0.0, softmax_scale=None
|
598 |
+
):
|
599 |
+
"""
|
600 |
+
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
|
601 |
+
first unpad the input, then computes the attention scores and pad the final attention scores.
|
602 |
+
|
603 |
+
Args:
|
604 |
+
query_states (`torch.Tensor`):
|
605 |
+
Input query states to be passed to Flash Attention API
|
606 |
+
key_states (`torch.Tensor`):
|
607 |
+
Input key states to be passed to Flash Attention API
|
608 |
+
value_states (`torch.Tensor`):
|
609 |
+
Input value states to be passed to Flash Attention API
|
610 |
+
attention_mask (`torch.Tensor`):
|
611 |
+
The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
|
612 |
+
position of padding tokens and 1 for the position of non-padding tokens.
|
613 |
+
dropout (`float`):
|
614 |
+
Attention dropout
|
615 |
+
softmax_scale (`float`, *optional*):
|
616 |
+
The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
|
617 |
+
"""
|
618 |
+
if not self._flash_attn_uses_top_left_mask:
|
619 |
+
causal = self.is_causal
|
620 |
+
else:
|
621 |
+
# TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in MistralFlashAttention2 __init__.
|
622 |
+
causal = self.is_causal and query_length != 1
|
623 |
+
|
624 |
+
# Contains at least one padding token in the sequence
|
625 |
+
if attention_mask is not None:
|
626 |
+
batch_size = query_states.shape[0]
|
627 |
+
query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
|
628 |
+
query_states, key_states, value_states, attention_mask, query_length
|
629 |
+
)
|
630 |
+
|
631 |
+
cu_seqlens_q, cu_seqlens_k = cu_seq_lens
|
632 |
+
max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
|
633 |
+
|
634 |
+
attn_output_unpad = flash_attn_varlen_func(
|
635 |
+
query_states,
|
636 |
+
key_states,
|
637 |
+
value_states,
|
638 |
+
cu_seqlens_q=cu_seqlens_q,
|
639 |
+
cu_seqlens_k=cu_seqlens_k,
|
640 |
+
max_seqlen_q=max_seqlen_in_batch_q,
|
641 |
+
max_seqlen_k=max_seqlen_in_batch_k,
|
642 |
+
dropout_p=dropout,
|
643 |
+
softmax_scale=softmax_scale,
|
644 |
+
causal=causal,
|
645 |
+
)
|
646 |
+
|
647 |
+
attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
|
648 |
+
else:
|
649 |
+
attn_output = flash_attn_func(
|
650 |
+
query_states, key_states, value_states, dropout, softmax_scale=softmax_scale, causal=causal
|
651 |
+
)
|
652 |
+
|
653 |
+
return attn_output
|
654 |
+
|
655 |
+
def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
|
656 |
+
indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
|
657 |
+
batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
|
658 |
+
|
659 |
+
key_layer = index_first_axis(
|
660 |
+
key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
|
661 |
+
)
|
662 |
+
value_layer = index_first_axis(
|
663 |
+
value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
|
664 |
+
)
|
665 |
+
if query_length == kv_seq_len:
|
666 |
+
query_layer = index_first_axis(
|
667 |
+
query_layer.reshape(batch_size * kv_seq_len, self.num_heads, head_dim), indices_k
|
668 |
+
)
|
669 |
+
cu_seqlens_q = cu_seqlens_k
|
670 |
+
max_seqlen_in_batch_q = max_seqlen_in_batch_k
|
671 |
+
indices_q = indices_k
|
672 |
+
elif query_length == 1:
|
673 |
+
max_seqlen_in_batch_q = 1
|
674 |
+
cu_seqlens_q = torch.arange(
|
675 |
+
batch_size + 1, dtype=torch.int32, device=query_layer.device
|
676 |
+
) # There is a memcpy here, that is very bad.
|
677 |
+
indices_q = cu_seqlens_q[:-1]
|
678 |
+
query_layer = query_layer.squeeze(1)
|
679 |
+
else:
|
680 |
+
# The -q_len: slice assumes left padding.
|
681 |
+
attention_mask = attention_mask[:, -query_length:]
|
682 |
+
query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
|
683 |
+
|
684 |
+
return (
|
685 |
+
query_layer,
|
686 |
+
key_layer,
|
687 |
+
value_layer,
|
688 |
+
indices_q,
|
689 |
+
(cu_seqlens_q, cu_seqlens_k),
|
690 |
+
(max_seqlen_in_batch_q, max_seqlen_in_batch_k),
|
691 |
+
)
|
692 |
+
|
693 |
+
|
694 |
+
MISTRAL_ATTENTION_CLASSES = {
|
695 |
+
"eager": MistralAttention,
|
696 |
+
"sdpa": MistralSdpaAttention,
|
697 |
+
"flash_attention_2": MistralFlashAttention2,
|
698 |
+
}
|
699 |
+
|
700 |
+
|
701 |
+
class MistralDecoderLayer(nn.Module):
|
702 |
+
def __init__(self, config: MistralConfig, layer_idx: int):
|
703 |
+
super().__init__()
|
704 |
+
self.hidden_size = config.hidden_size
|
705 |
+
|
706 |
+
if config.sliding_window is not None and config._attn_implementation != "flash_attention_2":
|
707 |
+
logger.warning_once(
|
708 |
+
f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
|
709 |
+
"unexpected results may be encountered."
|
710 |
+
)
|
711 |
+
self.self_attn = MISTRAL_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx)
|
712 |
+
|
713 |
+
self.mlp = MistralMLP(config)
|
714 |
+
self.input_layernorm = MistralRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
715 |
+
self.post_attention_layernorm = MistralRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
716 |
+
|
717 |
+
def forward(
|
718 |
+
self,
|
719 |
+
hidden_states: torch.Tensor,
|
720 |
+
attention_mask: Optional[torch.Tensor] = None,
|
721 |
+
position_ids: Optional[torch.LongTensor] = None,
|
722 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
723 |
+
output_attentions: Optional[bool] = False,
|
724 |
+
use_cache: Optional[bool] = False,
|
725 |
+
**kwargs,
|
726 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
727 |
+
"""
|
728 |
+
Args:
|
729 |
+
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
|
730 |
+
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
|
731 |
+
`(batch, sequence_length)` where padding elements are indicated by 0.
|
732 |
+
output_attentions (`bool`, *optional*):
|
733 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
734 |
+
returned tensors for more detail.
|
735 |
+
use_cache (`bool`, *optional*):
|
736 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
|
737 |
+
(see `past_key_values`).
|
738 |
+
past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
|
739 |
+
"""
|
740 |
+
if "padding_mask" in kwargs:
|
741 |
+
warnings.warn(
|
742 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
743 |
+
)
|
744 |
+
|
745 |
+
residual = hidden_states
|
746 |
+
|
747 |
+
hidden_states = self.input_layernorm(hidden_states)
|
748 |
+
|
749 |
+
# Self Attention
|
750 |
+
hidden_states, self_attn_weights, present_key_value = self.self_attn(
|
751 |
+
hidden_states=hidden_states,
|
752 |
+
attention_mask=attention_mask,
|
753 |
+
position_ids=position_ids,
|
754 |
+
past_key_value=past_key_value,
|
755 |
+
output_attentions=output_attentions,
|
756 |
+
use_cache=use_cache,
|
757 |
+
)
|
758 |
+
hidden_states = residual + hidden_states
|
759 |
+
|
760 |
+
# Fully Connected
|
761 |
+
residual = hidden_states
|
762 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
763 |
+
hidden_states = self.mlp(hidden_states)
|
764 |
+
hidden_states = residual + hidden_states
|
765 |
+
|
766 |
+
outputs = (hidden_states,)
|
767 |
+
|
768 |
+
if output_attentions:
|
769 |
+
outputs += (self_attn_weights,)
|
770 |
+
|
771 |
+
if use_cache:
|
772 |
+
outputs += (present_key_value,)
|
773 |
+
|
774 |
+
return outputs
|
775 |
+
|
776 |
+
|
777 |
+
MISTRAL_START_DOCSTRING = r"""
|
778 |
+
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
|
779 |
+
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
|
780 |
+
etc.)
|
781 |
+
|
782 |
+
This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
|
783 |
+
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
|
784 |
+
and behavior.
|
785 |
+
|
786 |
+
Parameters:
|
787 |
+
config ([`MistralConfig`]):
|
788 |
+
Model configuration class with all the parameters of the model. Initializing with a config file does not
|
789 |
+
load the weights associated with the model, only the configuration. Check out the
|
790 |
+
[`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
791 |
+
"""
|
792 |
+
|
793 |
+
|
794 |
+
@add_start_docstrings(
|
795 |
+
"The bare Mistral Model outputting raw hidden-states without any specific head on top.",
|
796 |
+
MISTRAL_START_DOCSTRING,
|
797 |
+
)
|
798 |
+
class MistralPreTrainedModel(PreTrainedModel):
|
799 |
+
config_class = MistralConfig
|
800 |
+
base_model_prefix = "model"
|
801 |
+
supports_gradient_checkpointing = True
|
802 |
+
_no_split_modules = ["MistralDecoderLayer"]
|
803 |
+
_skip_keys_device_placement = "past_key_values"
|
804 |
+
_supports_flash_attn_2 = True
|
805 |
+
_supports_sdpa = True
|
806 |
+
_supports_cache_class = True
|
807 |
+
|
808 |
+
def _init_weights(self, module):
|
809 |
+
std = self.config.initializer_range
|
810 |
+
if isinstance(module, nn.Linear):
|
811 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
812 |
+
if module.bias is not None:
|
813 |
+
module.bias.data.zero_()
|
814 |
+
elif isinstance(module, nn.Embedding):
|
815 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
816 |
+
if module.padding_idx is not None:
|
817 |
+
module.weight.data[module.padding_idx].zero_()
|
818 |
+
|
819 |
+
|
820 |
+
MISTRAL_INPUTS_DOCSTRING = r"""
|
821 |
+
Args:
|
822 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
823 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
824 |
+
it.
|
825 |
+
|
826 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
827 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
828 |
+
|
829 |
+
[What are input IDs?](../glossary#input-ids)
|
830 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
831 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
832 |
+
|
833 |
+
- 1 for tokens that are **not masked**,
|
834 |
+
- 0 for tokens that are **masked**.
|
835 |
+
|
836 |
+
[What are attention masks?](../glossary#attention-mask)
|
837 |
+
|
838 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
839 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
840 |
+
|
841 |
+
If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
|
842 |
+
`past_key_values`).
|
843 |
+
|
844 |
+
If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
|
845 |
+
and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
|
846 |
+
information on the default strategy.
|
847 |
+
|
848 |
+
- 1 indicates the head is **not masked**,
|
849 |
+
- 0 indicates the head is **masked**.
|
850 |
+
position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
851 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
852 |
+
config.n_positions - 1]`.
|
853 |
+
|
854 |
+
[What are position IDs?](../glossary#position-ids)
|
855 |
+
past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
856 |
+
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
|
857 |
+
blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
|
858 |
+
returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
|
859 |
+
|
860 |
+
Two formats are allowed:
|
861 |
+
- a [`~cache_utils.Cache`] instance;
|
862 |
+
- Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
|
863 |
+
shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
|
864 |
+
cache format.
|
865 |
+
|
866 |
+
The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
|
867 |
+
legacy cache format will be returned.
|
868 |
+
|
869 |
+
If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
|
870 |
+
have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
|
871 |
+
of shape `(batch_size, sequence_length)`.
|
872 |
+
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
873 |
+
Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
|
874 |
+
is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
|
875 |
+
model's internal embedding lookup matrix.
|
876 |
+
use_cache (`bool`, *optional*):
|
877 |
+
If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
|
878 |
+
`past_key_values`).
|
879 |
+
output_attentions (`bool`, *optional*):
|
880 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
|
881 |
+
tensors for more detail.
|
882 |
+
output_hidden_states (`bool`, *optional*):
|
883 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
|
884 |
+
more detail.
|
885 |
+
return_dict (`bool`, *optional*):
|
886 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
887 |
+
"""
|
888 |
+
|
889 |
+
|
890 |
+
@add_start_docstrings(
|
891 |
+
"The bare Mistral Model outputting raw hidden-states without any specific head on top.",
|
892 |
+
MISTRAL_START_DOCSTRING,
|
893 |
+
)
|
894 |
+
class MistralModel(MistralPreTrainedModel):
|
895 |
+
"""
|
896 |
+
Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`MistralDecoderLayer`]
|
897 |
+
|
898 |
+
Args:
|
899 |
+
config: MistralConfig
|
900 |
+
"""
|
901 |
+
|
902 |
+
def __init__(self, config: MistralConfig):
|
903 |
+
super().__init__(config)
|
904 |
+
self.padding_idx = config.pad_token_id
|
905 |
+
self.vocab_size = config.vocab_size
|
906 |
+
|
907 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
908 |
+
|
909 |
+
# BEACON: add beacon embedding
|
910 |
+
self.beacon_embed_tokens = nn.Embedding(1, config.hidden_size, self.padding_idx)
|
911 |
+
self.beacon_embed_tokens._is_hf_initialized = True
|
912 |
+
|
913 |
+
self.layers = nn.ModuleList(
|
914 |
+
[MistralDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
915 |
+
)
|
916 |
+
self._attn_implementation = config._attn_implementation
|
917 |
+
self.norm = MistralRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
918 |
+
|
919 |
+
self.gradient_checkpointing = False
|
920 |
+
# Initialize weights and apply final processing
|
921 |
+
self.post_init()
|
922 |
+
|
923 |
+
def _init_beacon_embed(self, missing_keys):
|
924 |
+
"""Initialize the beacon token embedding with that of the eos token."""
|
925 |
+
if is_deepspeed_zero3_enabled():
|
926 |
+
import deepspeed
|
927 |
+
params = [self.beacon_embed_tokens.weight, self.embed_tokens.weight]
|
928 |
+
with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
|
929 |
+
# deepspeed will initialize the parameters to zero
|
930 |
+
if (self.beacon_embed_tokens.weight == 0).all():
|
931 |
+
if self.config.beacon_embed_init == "bos":
|
932 |
+
self.beacon_embed_tokens.weight.data[:] = self.embed_tokens.weight.data[self.config.bos_token_id]
|
933 |
+
elif self.config.beacon_embed_init == "eos":
|
934 |
+
if isinstance(self.config.eos_token_id, list):
|
935 |
+
eos_token_id = self.config.eos_token_id[0]
|
936 |
+
else:
|
937 |
+
eos_token_id = self.config.eos_token_id
|
938 |
+
self.beacon_embed_tokens.weight.data[:] = self.embed_tokens.weight.data[eos_token_id]
|
939 |
+
else:
|
940 |
+
raise NotImplementedError(f"Make sure beacon_embed_init is either eos or bos, found {self.config.beacon_embed_init}")
|
941 |
+
else:
|
942 |
+
if any("beacon_embed_tokens" in missing_key for missing_key in missing_keys):
|
943 |
+
if self.config.beacon_embed_init == "bos":
|
944 |
+
self.beacon_embed_tokens.weight.data[:] = self.embed_tokens.weight.data[self.config.bos_token_id]
|
945 |
+
elif self.config.beacon_embed_init == "eos":
|
946 |
+
if isinstance(self.config.eos_token_id, list):
|
947 |
+
eos_token_id = self.config.eos_token_id[0]
|
948 |
+
else:
|
949 |
+
eos_token_id = self.config.eos_token_id
|
950 |
+
self.beacon_embed_tokens.weight.data[:] = self.embed_tokens.weight.data[eos_token_id]
|
951 |
+
else:
|
952 |
+
raise NotImplementedError(f"Make sure beacon_embed_init is either eos or bos, found {self.config.beacon_embed_init}")
|
953 |
+
|
954 |
+
def get_input_embeddings(self):
|
955 |
+
return self.embed_tokens
|
956 |
+
|
957 |
+
def set_input_embeddings(self, value):
|
958 |
+
self.embed_tokens = value
|
959 |
+
|
960 |
+
@add_start_docstrings_to_model_forward(MISTRAL_INPUTS_DOCSTRING)
|
961 |
+
def forward(
|
962 |
+
self,
|
963 |
+
input_ids: torch.LongTensor = None,
|
964 |
+
attention_mask: Optional[torch.Tensor] = None,
|
965 |
+
position_ids: Optional[torch.LongTensor] = None,
|
966 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
967 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
968 |
+
use_cache: Optional[bool] = None,
|
969 |
+
output_attentions: Optional[bool] = None,
|
970 |
+
output_hidden_states: Optional[bool] = None,
|
971 |
+
return_dict: Optional[bool] = None,
|
972 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
973 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
974 |
+
output_hidden_states = (
|
975 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
976 |
+
)
|
977 |
+
# BEACON: always use cache
|
978 |
+
use_cache = True
|
979 |
+
|
980 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
981 |
+
|
982 |
+
# retrieve input_ids and inputs_embeds
|
983 |
+
if input_ids is not None and inputs_embeds is not None:
|
984 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
985 |
+
elif input_ids is not None:
|
986 |
+
batch_size, seq_length = input_ids.shape[:2]
|
987 |
+
elif inputs_embeds is not None:
|
988 |
+
batch_size, seq_length = inputs_embeds.shape[:2]
|
989 |
+
else:
|
990 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
991 |
+
|
992 |
+
past_key, past_value, beacon_size, beacon_indices = past_key_values[0]
|
993 |
+
|
994 |
+
# BEACON: separately embed ordinal tokens and beacon tokens because ordinal tokens do not receive gradients
|
995 |
+
if beacon_size > 0:
|
996 |
+
# NOTE: when beacon_pos == "interleave", the beacon_indices points to all beacon tokens in the current window (cached activations + input_ids), so we shall slice out the part corresponding to the input_ids
|
997 |
+
cur_beacon_indices = beacon_indices[-input_ids.shape[1]:]
|
998 |
+
|
999 |
+
ordinal_input_ids = input_ids[:, cur_beacon_indices == 0]
|
1000 |
+
beacon_input_ids = input_ids[:, cur_beacon_indices > 0]
|
1001 |
+
ordinal_inputs_embeds = self.embed_tokens(ordinal_input_ids)
|
1002 |
+
beacon_input_embeds = self.beacon_embed_tokens(beacon_input_ids - self.config.vocab_size)
|
1003 |
+
# create a new embedding tensor
|
1004 |
+
inputs_embeds = beacon_input_embeds.new_zeros(*input_ids.shape, beacon_input_embeds.shape[-1])
|
1005 |
+
inputs_embeds[:, cur_beacon_indices == 0] = ordinal_inputs_embeds
|
1006 |
+
inputs_embeds[:, cur_beacon_indices > 0] = beacon_input_embeds
|
1007 |
+
|
1008 |
+
else:
|
1009 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
1010 |
+
|
1011 |
+
# embed positions
|
1012 |
+
hidden_states = inputs_embeds
|
1013 |
+
|
1014 |
+
# print(f"input_ids: {input_ids}")
|
1015 |
+
# print(f"beacon_indices: {beacon_indices}")
|
1016 |
+
# print(f"position_ids: {position_ids}")
|
1017 |
+
# print(f"attention_mask:\n{attention_mask == 0}")
|
1018 |
+
# x = input()
|
1019 |
+
# if x == "s":
|
1020 |
+
# return
|
1021 |
+
|
1022 |
+
# decoder layers
|
1023 |
+
all_hidden_states = () if output_hidden_states else None
|
1024 |
+
all_self_attns = () if output_attentions else None
|
1025 |
+
# BEACON: still use tuple to organize cache
|
1026 |
+
next_decoder_cache = () if use_cache else None
|
1027 |
+
|
1028 |
+
for idx, decoder_layer in enumerate(self.layers):
|
1029 |
+
if output_hidden_states:
|
1030 |
+
all_hidden_states += (hidden_states,)
|
1031 |
+
|
1032 |
+
# BEACON: slice out the past_key_value of the corresponding layer
|
1033 |
+
past_key_value = past_key_values[idx] if past_key_values is not None else None
|
1034 |
+
|
1035 |
+
if self.gradient_checkpointing and self.training:
|
1036 |
+
layer_outputs = self._gradient_checkpointing_func(
|
1037 |
+
decoder_layer.__call__,
|
1038 |
+
hidden_states,
|
1039 |
+
attention_mask,
|
1040 |
+
position_ids,
|
1041 |
+
past_key_value,
|
1042 |
+
output_attentions,
|
1043 |
+
use_cache,
|
1044 |
+
)
|
1045 |
+
else:
|
1046 |
+
layer_outputs = decoder_layer(
|
1047 |
+
hidden_states,
|
1048 |
+
attention_mask=attention_mask,
|
1049 |
+
position_ids=position_ids,
|
1050 |
+
past_key_value=past_key_value,
|
1051 |
+
output_attentions=output_attentions,
|
1052 |
+
use_cache=use_cache,
|
1053 |
+
)
|
1054 |
+
|
1055 |
+
hidden_states = layer_outputs[0]
|
1056 |
+
|
1057 |
+
if use_cache:
|
1058 |
+
next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
|
1059 |
+
|
1060 |
+
if output_attentions:
|
1061 |
+
all_self_attns += (layer_outputs[1],)
|
1062 |
+
|
1063 |
+
hidden_states = self.norm(hidden_states)
|
1064 |
+
|
1065 |
+
# add hidden states from the last decoder layer
|
1066 |
+
if output_hidden_states:
|
1067 |
+
all_hidden_states += (hidden_states,)
|
1068 |
+
|
1069 |
+
next_cache = next_decoder_cache if use_cache else None
|
1070 |
+
|
1071 |
+
if not return_dict:
|
1072 |
+
return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
|
1073 |
+
return BaseModelOutputWithPast(
|
1074 |
+
last_hidden_state=hidden_states,
|
1075 |
+
past_key_values=next_cache,
|
1076 |
+
hidden_states=all_hidden_states,
|
1077 |
+
attentions=all_self_attns,
|
1078 |
+
)
|
1079 |
+
|
1080 |
+
|
1081 |
+
class MistralForCausalLM(MistralPreTrainedModel):
|
1082 |
+
_tied_weights_keys = ["lm_head.weight"]
|
1083 |
+
|
1084 |
+
def __init__(self, config):
|
1085 |
+
super().__init__(config)
|
1086 |
+
self.model = MistralModel(config)
|
1087 |
+
self.vocab_size = config.vocab_size
|
1088 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
1089 |
+
# Initialize weights and apply final processing
|
1090 |
+
self.post_init()
|
1091 |
+
|
1092 |
+
def get_input_embeddings(self):
|
1093 |
+
return self.model.embed_tokens
|
1094 |
+
|
1095 |
+
def set_input_embeddings(self, value):
|
1096 |
+
self.model.embed_tokens = value
|
1097 |
+
|
1098 |
+
def get_output_embeddings(self):
|
1099 |
+
return self.lm_head
|
1100 |
+
|
1101 |
+
def set_output_embeddings(self, new_embeddings):
|
1102 |
+
self.lm_head = new_embeddings
|
1103 |
+
|
1104 |
+
def set_decoder(self, decoder):
|
1105 |
+
self.model = decoder
|
1106 |
+
|
1107 |
+
def get_decoder(self):
|
1108 |
+
return self.model
|
1109 |
+
|
1110 |
+
@classmethod
|
1111 |
+
def from_pretrained(cls, *args, **kwargs):
|
1112 |
+
"""Override the default from_pretrained to extend vocab size according to beacon_size."""
|
1113 |
+
kwargs.update(output_loading_info=True)
|
1114 |
+
model, loading_info = super().from_pretrained(*args, **kwargs)
|
1115 |
+
|
1116 |
+
# NOTE: set memory after from_pretrained because there may be another transformer model inside the Memory object, which may cause weird erros during loading
|
1117 |
+
config = model.config
|
1118 |
+
model.memory = Memory(
|
1119 |
+
model_config=config,
|
1120 |
+
k_seq_dim=2,
|
1121 |
+
v_seq_dim=2,
|
1122 |
+
)
|
1123 |
+
|
1124 |
+
missing_keys = loading_info["missing_keys"]
|
1125 |
+
# NOTE: the beacon parameters may or may not be loaded from the checkpoint
|
1126 |
+
# if it is loaded from the checkpoint, we should not re-initilize it
|
1127 |
+
model.model._init_beacon_embed(missing_keys)
|
1128 |
+
# initialize weights of possible q,k,v,o,mlp
|
1129 |
+
for layer in model.model.layers:
|
1130 |
+
layer.self_attn._init_beacon_proj(missing_keys)
|
1131 |
+
|
1132 |
+
return model
|
1133 |
+
|
1134 |
+
def _native_forward(
|
1135 |
+
self,
|
1136 |
+
input_ids: torch.LongTensor = None,
|
1137 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1138 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1139 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
1140 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1141 |
+
labels: Optional[torch.LongTensor] = None,
|
1142 |
+
use_cache: Optional[bool] = None,
|
1143 |
+
output_attentions: Optional[bool] = None,
|
1144 |
+
output_hidden_states: Optional[bool] = None,
|
1145 |
+
return_dict: Optional[bool] = None,
|
1146 |
+
) -> Union[Tuple, ModelOutput]:
|
1147 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
1148 |
+
output_hidden_states = (
|
1149 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
1150 |
+
)
|
1151 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
1152 |
+
|
1153 |
+
# when we directly call _native_forward, the past_key_values would be None
|
1154 |
+
if past_key_values is None:
|
1155 |
+
# NOTE: set beacon size to 0 to avoid using any beacon parameters, see Qwen2Attention.forward
|
1156 |
+
past_key_values = [(None, None, 0, None) for _ in range(self.config.num_hidden_layers)]
|
1157 |
+
|
1158 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
1159 |
+
outputs = self.model(
|
1160 |
+
input_ids=input_ids,
|
1161 |
+
attention_mask=attention_mask,
|
1162 |
+
position_ids=position_ids,
|
1163 |
+
past_key_values=past_key_values,
|
1164 |
+
inputs_embeds=inputs_embeds,
|
1165 |
+
use_cache=use_cache,
|
1166 |
+
output_attentions=output_attentions,
|
1167 |
+
output_hidden_states=output_hidden_states,
|
1168 |
+
return_dict=return_dict,
|
1169 |
+
)
|
1170 |
+
|
1171 |
+
hidden_states = outputs[0]
|
1172 |
+
logits = self.lm_head(hidden_states)
|
1173 |
+
logits = logits.float()
|
1174 |
+
|
1175 |
+
loss = None
|
1176 |
+
batch_loss = None
|
1177 |
+
token_loss = None
|
1178 |
+
|
1179 |
+
if labels is not None:
|
1180 |
+
loss, batch_loss, token_loss = compute_loss(logits, labels, shift=False)
|
1181 |
+
|
1182 |
+
if not return_dict:
|
1183 |
+
output = (logits,) + outputs[1:]
|
1184 |
+
return (loss,) + output if loss is not None else output
|
1185 |
+
|
1186 |
+
return ModelOutput(
|
1187 |
+
loss=loss,
|
1188 |
+
batch_loss=batch_loss,
|
1189 |
+
token_loss=token_loss,
|
1190 |
+
logits=logits,
|
1191 |
+
past_key_values=outputs.past_key_values,
|
1192 |
+
hidden_states=outputs.hidden_states,
|
1193 |
+
attentions=outputs.attentions,
|
1194 |
+
)
|
1195 |
+
|
1196 |
+
def _beacon_forward(self,
|
1197 |
+
input_ids: torch.LongTensor = None,
|
1198 |
+
attention_mask: Optional[torch.Tensor] = None,
|
1199 |
+
position_ids: Optional[torch.LongTensor] = None,
|
1200 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
1201 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
1202 |
+
labels: Optional[torch.LongTensor] = None,
|
1203 |
+
use_cache: Optional[bool] = None,
|
1204 |
+
output_attentions: Optional[bool] = None,
|
1205 |
+
output_hidden_states: Optional[bool] = None,
|
1206 |
+
return_dict: Optional[bool] = None,
|
1207 |
+
beacon_skip_first=None,
|
1208 |
+
beacon_skip_last=None
|
1209 |
+
):
|
1210 |
+
# t1 = time.time()
|
1211 |
+
|
1212 |
+
# initialize cache
|
1213 |
+
self.memory.prepare(
|
1214 |
+
input_ids=input_ids,
|
1215 |
+
attention_mask=attention_mask,
|
1216 |
+
labels=labels
|
1217 |
+
)
|
1218 |
+
|
1219 |
+
# t2 = time.time()
|
1220 |
+
|
1221 |
+
while not self.memory.finish:
|
1222 |
+
|
1223 |
+
# t3 = time.time()
|
1224 |
+
|
1225 |
+
input_ids, attention_mask, position_ids, past_key_values, labels = self.memory.step()
|
1226 |
+
|
1227 |
+
# t4 = time.time()
|
1228 |
+
|
1229 |
+
outputs = self._native_forward(
|
1230 |
+
input_ids=input_ids,
|
1231 |
+
attention_mask=attention_mask,
|
1232 |
+
position_ids=position_ids,
|
1233 |
+
past_key_values=past_key_values,
|
1234 |
+
inputs_embeds=inputs_embeds,
|
1235 |
+
use_cache=use_cache,
|
1236 |
+
output_attentions=output_attentions,
|
1237 |
+
output_hidden_states=output_hidden_states,
|
1238 |
+
return_dict=return_dict,
|
1239 |
+
labels=labels,
|
1240 |
+
)
|
1241 |
+
|
1242 |
+
# t5 = time.time()
|
1243 |
+
|
1244 |
+
# update past_key_values
|
1245 |
+
self.memory.update_memory(outputs.past_key_values)
|
1246 |
+
|
1247 |
+
# t6 = time.time()
|
1248 |
+
|
1249 |
+
if labels is not None:
|
1250 |
+
# update loss
|
1251 |
+
self.memory.update_loss(outputs.batch_loss, (labels != -100).sum(-1))
|
1252 |
+
|
1253 |
+
# t7 = time.time()
|
1254 |
+
|
1255 |
+
# print(f"step time: {t4-t3}, forward time: {t5-t4}, update time: {t6-t5}, loss time: {t7-t6}")
|
1256 |
+
# input()
|
1257 |
+
|
1258 |
+
# t8 = time.time()
|
1259 |
+
|
1260 |
+
# output loss, past_key_values, and perplexity
|
1261 |
+
outputs = self.memory.output(outputs)
|
1262 |
+
|
1263 |
+
# t9 = time.time()
|
1264 |
+
|
1265 |
+
# print(f"output time: {t9-t8}")
|
1266 |
+
# input()
|
1267 |
+
|
1268 |
+
return outputs
|
1269 |
+
|
1270 |
+
def forward(self, **kwargs):
|
1271 |
+
"""Forward computation over a batch of sequences.
|
1272 |
+
"""
|
1273 |
+
# only allow gradient when training
|
1274 |
+
with optional_grad_ctx(with_grad=self.training):
|
1275 |
+
# we can disable beacon to use the original mistral
|
1276 |
+
if hasattr(self, "_enable_beacon") and self._enable_beacon == False:
|
1277 |
+
return self._native_forward(**kwargs)
|
1278 |
+
else:
|
1279 |
+
return self._beacon_forward(**kwargs)
|
1280 |
+
|
1281 |
+
def prepare_inputs_for_generation(
|
1282 |
+
self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, beacon_skip_first=None, beacon_skip_last=None, **kwargs
|
1283 |
+
):
|
1284 |
+
if past_key_values:
|
1285 |
+
input_ids = input_ids[:, -1:]
|
1286 |
+
|
1287 |
+
model_inputs = {"input_ids": input_ids, "beacon_skip_first": beacon_skip_first, "beacon_skip_last": beacon_skip_last}
|
1288 |
+
return model_inputs
|
1289 |
+
|
1290 |
+
@staticmethod
|
1291 |
+
def _reorder_cache(past_key_values, beam_idx):
|
1292 |
+
reordered_past = ()
|
1293 |
+
for layer_past in past_key_values:
|
1294 |
+
reordered_past += (
|
1295 |
+
tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
|
1296 |
+
)
|
1297 |
+
return reordered_past
|
modeling_utils.py
ADDED
@@ -0,0 +1,711 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from tqdm import tqdm
|
4 |
+
from dataclasses import dataclass
|
5 |
+
from contextlib import nullcontext
|
6 |
+
from typing import Mapping, Optional, Tuple
|
7 |
+
from accelerate import Accelerator
|
8 |
+
from collections import defaultdict
|
9 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast
|
10 |
+
|
11 |
+
|
12 |
+
def optional_grad_ctx(with_grad=False):
|
13 |
+
if with_grad:
|
14 |
+
return nullcontext()
|
15 |
+
else:
|
16 |
+
return torch.no_grad()
|
17 |
+
|
18 |
+
def move_to_device(data, device):
|
19 |
+
"""
|
20 |
+
Prepares one `data` before feeding it to the model, be it a tensor or a nested list/dictionary of tensors.
|
21 |
+
"""
|
22 |
+
if isinstance(data, Mapping):
|
23 |
+
return type(data)({k: move_to_device(v, device) for k, v in data.items()})
|
24 |
+
elif isinstance(data, (tuple, list)):
|
25 |
+
return type(data)(move_to_device(v, device) for v in data)
|
26 |
+
elif isinstance(data, torch.Tensor):
|
27 |
+
kwargs = {"device": device}
|
28 |
+
return data.to(**kwargs)
|
29 |
+
else:
|
30 |
+
return data
|
31 |
+
|
32 |
+
def get_shifted_labels(input_ids):
|
33 |
+
if isinstance(input_ids, torch.Tensor):
|
34 |
+
labels = input_ids.clone()
|
35 |
+
labels = torch.cat([labels[:, 1:], labels.new_zeros((input_ids.shape[0], 1)) - 100], dim=-1)
|
36 |
+
elif isinstance(input_ids, list) and isinstance(input_ids[0], int):
|
37 |
+
labels = input_ids.copy()
|
38 |
+
labels = labels[1:] + [-100]
|
39 |
+
elif isinstance(input_ids, list) and isinstance(input_ids[0], list):
|
40 |
+
labels = input_ids.copy()
|
41 |
+
for i, label in enumerate(labels):
|
42 |
+
labels[i] = labels[i][1:] + [-100]
|
43 |
+
else:
|
44 |
+
raise NotImplementedError
|
45 |
+
return labels
|
46 |
+
|
47 |
+
def compute_loss(logits, labels, shift=False):
|
48 |
+
"""
|
49 |
+
Returns:
|
50 |
+
token_loss: batch_size, seq_length
|
51 |
+
"""
|
52 |
+
if shift:
|
53 |
+
labels = get_shifted_labels(labels)
|
54 |
+
|
55 |
+
labels = labels.to(logits.device)
|
56 |
+
batch_size = logits.shape[0]
|
57 |
+
|
58 |
+
# NOTE: the loss on -100 labels is 0 by default
|
59 |
+
token_loss = torch.nn.functional.cross_entropy(
|
60 |
+
logits.flatten(0, 1),
|
61 |
+
labels.reshape(-1),
|
62 |
+
reduction="none"
|
63 |
+
).reshape(batch_size, -1) # batch_size, seq_len
|
64 |
+
|
65 |
+
# print(token_loss)
|
66 |
+
|
67 |
+
valid_token_num = (labels != -100).sum(-1) # batch_size
|
68 |
+
all_valid_token_num = valid_token_num.sum()
|
69 |
+
|
70 |
+
if all_valid_token_num > 0:
|
71 |
+
loss = token_loss.sum() / valid_token_num.sum()
|
72 |
+
else:
|
73 |
+
loss = token_loss.sum()
|
74 |
+
|
75 |
+
batch_loss = token_loss.sum(-1) / valid_token_num
|
76 |
+
# prevent nan
|
77 |
+
if (valid_token_num == 0).any():
|
78 |
+
batch_loss = batch_loss.masked_fill(valid_token_num == 0, 0.)
|
79 |
+
|
80 |
+
return loss, batch_loss, token_loss
|
81 |
+
|
82 |
+
|
83 |
+
@torch.no_grad()
|
84 |
+
def evaluate_perplexity(model, dataloader, accelerator:Optional[Accelerator]=None):
|
85 |
+
if accelerator is not None and type(dataloader) == torch.utils.data.DataLoader:
|
86 |
+
# if the dataloader has been prepared, we shall not prepare it twice, especially in case of deepspeed
|
87 |
+
dataloader = accelerator.prepare(dataloader)
|
88 |
+
|
89 |
+
# if accelerator.process_index == 0:
|
90 |
+
# for name, x in model.named_parameters():
|
91 |
+
# print(f"{name: ^80} {x.dtype}")
|
92 |
+
|
93 |
+
all_loss = defaultdict(list)
|
94 |
+
for i, x in enumerate(tqdm(dataloader, desc="Computing Perplexity")):
|
95 |
+
# NOTE: important to reset memory for every batch
|
96 |
+
if hasattr(model, "memory"):
|
97 |
+
model.memory.reset()
|
98 |
+
|
99 |
+
# the seq id
|
100 |
+
index = x.pop("index")
|
101 |
+
# length is used to group training data, no use here
|
102 |
+
length = x.pop("length", None)
|
103 |
+
|
104 |
+
output = model(**x)
|
105 |
+
|
106 |
+
valid_token_num = (x["labels"] != -100).sum(-1)
|
107 |
+
|
108 |
+
# NOTE: we need the loss for each element in the batch for accurate computation, because the number of valid tokens may differ among elements
|
109 |
+
if hasattr(output, "batch_loss"):
|
110 |
+
# output from our model has batch_loss by default
|
111 |
+
batch_loss = output.batch_loss
|
112 |
+
else:
|
113 |
+
# output from other models does not
|
114 |
+
loss, batch_loss, token_loss = compute_loss(output.logits, x["labels"], shift=True)
|
115 |
+
|
116 |
+
index = index.tolist()
|
117 |
+
batch_loss = batch_loss.tolist()
|
118 |
+
valid_token_num = valid_token_num.tolist()
|
119 |
+
|
120 |
+
if accelerator is not None and accelerator.num_processes > 1:
|
121 |
+
# num_device * batch_size
|
122 |
+
index = accelerator.gather_for_metrics(index)
|
123 |
+
batch_loss = accelerator.gather_for_metrics(batch_loss)
|
124 |
+
valid_token_num = accelerator.gather_for_metrics(valid_token_num)
|
125 |
+
|
126 |
+
for _id, _loss, _num in zip(index, batch_loss, valid_token_num):
|
127 |
+
# loss times num is the total loss of all valid tokens
|
128 |
+
all_loss[_id].append((_loss * _num, _num))
|
129 |
+
|
130 |
+
all_loss = dict(all_loss)
|
131 |
+
for _id, loss_and_num in all_loss.items():
|
132 |
+
# sum up the loss for all valid tokens in the entire sequence, and divide the number of valid tokens
|
133 |
+
all_loss[_id] = sum([x[0] for x in loss_and_num]) / sum(x[1] for x in loss_and_num)
|
134 |
+
|
135 |
+
# average across then take exp
|
136 |
+
perplexity = math.exp(sum(all_loss.values()) / len(all_loss))
|
137 |
+
return perplexity
|
138 |
+
|
139 |
+
|
140 |
+
@torch.no_grad()
|
141 |
+
def evaluate_generation(model, dataloader, accelerator:Optional[Accelerator]=None, tokenizer=None, return_new_tokens_only=True, **generation_config):
|
142 |
+
if accelerator is not None and type(dataloader) == torch.utils.data.DataLoader:
|
143 |
+
# if the dataloader has been prepared, we shall not prepare it twice, especially in case of deepspeed
|
144 |
+
dataloader = accelerator.prepare(dataloader)
|
145 |
+
|
146 |
+
all_indices = []
|
147 |
+
all_outputs = []
|
148 |
+
|
149 |
+
index = 0
|
150 |
+
|
151 |
+
for i, x in enumerate(tqdm(dataloader, desc="Computing Generation")):
|
152 |
+
# if i > 3:
|
153 |
+
# break
|
154 |
+
|
155 |
+
# NOTE: important to reset memory for every batch
|
156 |
+
if hasattr(model, "memory"):
|
157 |
+
model.memory.reset()
|
158 |
+
|
159 |
+
# length is used to group training data, no use here
|
160 |
+
length = x.pop("length", None)
|
161 |
+
|
162 |
+
# if indices are None, we use batch size
|
163 |
+
indices = x.pop("index", None)
|
164 |
+
if indices is None:
|
165 |
+
indices = list(range(index, index + x['input_ids'].shape[0]))
|
166 |
+
index += x['input_ids'].shape[0]
|
167 |
+
else:
|
168 |
+
indices = indices.tolist()
|
169 |
+
|
170 |
+
outputs = model.generate(**x, **generation_config)
|
171 |
+
if return_new_tokens_only:
|
172 |
+
start_idx = x["input_ids"].shape[1]
|
173 |
+
outputs = outputs[:, start_idx:]
|
174 |
+
|
175 |
+
outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
176 |
+
|
177 |
+
if accelerator is not None and accelerator.num_processes > 1:
|
178 |
+
outputs = accelerator.gather_for_metrics(outputs)
|
179 |
+
indices = accelerator.gather_for_metrics(indices)
|
180 |
+
|
181 |
+
outputs = outputs
|
182 |
+
indices = indices
|
183 |
+
all_indices.extend(indices)
|
184 |
+
all_outputs.extend(outputs)
|
185 |
+
|
186 |
+
return all_indices, all_outputs
|
187 |
+
|
188 |
+
|
189 |
+
@torch.no_grad()
|
190 |
+
def evaluate_nll(model, dataloader, accelerator:Optional[Accelerator]=None):
|
191 |
+
if accelerator is not None and type(dataloader) == torch.utils.data.DataLoader:
|
192 |
+
# if the dataloader has been prepared, we shall not prepare it twice, especially in case of deepspeed
|
193 |
+
dataloader = accelerator.prepare(dataloader)
|
194 |
+
|
195 |
+
# if accelerator.process_index == 0:
|
196 |
+
# for name, x in model.named_parameters():
|
197 |
+
# print(f"{name: ^80} {x.dtype}")
|
198 |
+
|
199 |
+
all_loss = defaultdict(list)
|
200 |
+
for i, x in enumerate(tqdm(dataloader, desc="Computing Perplexity")):
|
201 |
+
# NOTE: important to reset memory for every batch
|
202 |
+
if hasattr(model, "memory"):
|
203 |
+
model.memory.reset()
|
204 |
+
|
205 |
+
# the seq id
|
206 |
+
index = x.pop("index")
|
207 |
+
# length is used to group training data, no use here
|
208 |
+
length = x.pop("length", None)
|
209 |
+
|
210 |
+
output = model(**x)
|
211 |
+
|
212 |
+
valid_token_num = (x["labels"] != -100).sum()
|
213 |
+
|
214 |
+
# NOTE: we need the loss for each element in the batch for accurate computation, because the number of valid tokens may differ among elements
|
215 |
+
if hasattr(output, "batch_loss"):
|
216 |
+
# output from our model has batch_loss by default
|
217 |
+
batch_loss = output.batch_loss
|
218 |
+
else:
|
219 |
+
# output from other models does not
|
220 |
+
loss, batch_loss, token_loss = compute_loss(output.logits, x["labels"], shift=True)
|
221 |
+
|
222 |
+
if accelerator is not None and accelerator.num_processes > 1:
|
223 |
+
# num_device * batch_size
|
224 |
+
index = accelerator.gather_for_metrics(index)
|
225 |
+
batch_loss = accelerator.gather_for_metrics(batch_loss)
|
226 |
+
valid_token_num = accelerator.gather_for_metrics(valid_token_num)
|
227 |
+
|
228 |
+
for _id, _loss in zip(index.tolist(), batch_loss.tolist()):
|
229 |
+
# loss times num is the total loss of all valid tokens
|
230 |
+
all_loss[_id].append(_loss)
|
231 |
+
|
232 |
+
return all_loss
|
233 |
+
|
234 |
+
|
235 |
+
@dataclass
|
236 |
+
class ModelOutput(BaseModelOutputWithPast):
|
237 |
+
loss: Optional[torch.FloatTensor] = None
|
238 |
+
batch_loss: Optional[torch.FloatTensor] = None
|
239 |
+
token_loss: Optional[torch.FloatTensor] = None
|
240 |
+
logits: torch.FloatTensor = None
|
241 |
+
past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None
|
242 |
+
hidden_states: Optional[Tuple[torch.FloatTensor]] = None
|
243 |
+
attentions: Optional[Tuple[torch.FloatTensor]] = None
|
244 |
+
|
245 |
+
|
246 |
+
|
247 |
+
########## Various RoPE Scaling Methods Below (wrap the encoding process within the module for convenience) ##########
|
248 |
+
|
249 |
+
def get_rope(head_dim, base, max_position_embeddings, rope_scaling=None):
|
250 |
+
"""
|
251 |
+
Get rope module. {native, linear scaling, dynamic ntk scaling, yarn scaling, llama3 scaling}
|
252 |
+
"""
|
253 |
+
if rope_scaling is None:
|
254 |
+
rope = RotaryEmbedding(
|
255 |
+
dim=head_dim,
|
256 |
+
base=base,
|
257 |
+
max_position_embeddings=max_position_embeddings,
|
258 |
+
)
|
259 |
+
else:
|
260 |
+
scaling_type = rope_scaling["type"]
|
261 |
+
scaling_factor = rope_scaling["factor"]
|
262 |
+
if scaling_type == "linear":
|
263 |
+
rope = LinearScalingRotaryEmbedding(
|
264 |
+
dim=head_dim,
|
265 |
+
base=base,
|
266 |
+
max_position_embeddings=max_position_embeddings,
|
267 |
+
scaling_factor=scaling_factor,
|
268 |
+
)
|
269 |
+
elif scaling_type == "dynamic":
|
270 |
+
rope = DynamicNTKScalingRotaryEmbedding(
|
271 |
+
dim=head_dim,
|
272 |
+
base=base,
|
273 |
+
max_position_embeddings=max_position_embeddings,
|
274 |
+
scaling_factor=scaling_factor,
|
275 |
+
)
|
276 |
+
elif scaling_type == "yarn":
|
277 |
+
rope = YarnRotaryEmbedding(
|
278 |
+
dim=head_dim,
|
279 |
+
base=base,
|
280 |
+
max_position_embeddings=max_position_embeddings,
|
281 |
+
scaling_factor=scaling_factor,
|
282 |
+
)
|
283 |
+
elif scaling_type == "yarn-t":
|
284 |
+
rope = YarnDynamicTemperatureRotaryEmbedding(
|
285 |
+
dim=head_dim,
|
286 |
+
base=base,
|
287 |
+
max_position_embeddings=max_position_embeddings,
|
288 |
+
scaling_factor=scaling_factor,
|
289 |
+
)
|
290 |
+
elif scaling_type == "yarn-t-logn":
|
291 |
+
rope = YarnDynamicTemperatureLogNRotaryEmbedding(
|
292 |
+
dim=head_dim,
|
293 |
+
base=base,
|
294 |
+
max_position_embeddings=max_position_embeddings,
|
295 |
+
scaling_factor=scaling_factor,
|
296 |
+
)
|
297 |
+
elif scaling_type == "llama3":
|
298 |
+
rope = Llama3RotaryEmbedding(
|
299 |
+
dim=head_dim,
|
300 |
+
base=base,
|
301 |
+
max_position_embeddings=max_position_embeddings,
|
302 |
+
scaling_factor=scaling_factor,
|
303 |
+
original_max_position_embeddings=rope_scaling.get("original_max_position_embeddings", 8192),
|
304 |
+
low_freq_factor=rope_scaling.get("low_freq_factor", 1),
|
305 |
+
high_freq_factor=rope_scaling.get("high_freq_factor", 4),
|
306 |
+
)
|
307 |
+
else:
|
308 |
+
raise ValueError(f"Unknown RoPE scaling type {scaling_type}")
|
309 |
+
|
310 |
+
return rope
|
311 |
+
|
312 |
+
|
313 |
+
def rotate_half(x):
|
314 |
+
"""Rotates half the hidden dims of the input."""
|
315 |
+
x1 = x[..., : x.shape[-1] // 2]
|
316 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
317 |
+
return torch.cat((-x2, x1), dim=-1)
|
318 |
+
|
319 |
+
|
320 |
+
class RotaryEmbedding(torch.nn.Module):
|
321 |
+
def __init__(self, dim, max_position_embeddings=32768, base=10000, device=None):
|
322 |
+
super().__init__()
|
323 |
+
|
324 |
+
self.dim = dim
|
325 |
+
self.max_position_embeddings = max_position_embeddings
|
326 |
+
self.base = base
|
327 |
+
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2, dtype=torch.float32).to(device) / self.dim))
|
328 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
329 |
+
|
330 |
+
# Build here to make `torch.jit.trace` work.
|
331 |
+
self._set_cos_sin_cache(
|
332 |
+
seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
|
333 |
+
)
|
334 |
+
|
335 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
336 |
+
self.max_seq_len_cached = seq_len
|
337 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=torch.float32)
|
338 |
+
freqs = torch.outer(t, self.inv_freq)
|
339 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
340 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
341 |
+
self.register_buffer("cos_cached", emb.cos(), persistent=False)
|
342 |
+
self.register_buffer("sin_cached", emb.sin(), persistent=False)
|
343 |
+
|
344 |
+
def forward(self, q, k, position_ids):
|
345 |
+
seq_len = max(position_ids.max().item() + 1, k.shape[2])
|
346 |
+
|
347 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
348 |
+
if seq_len > self.max_seq_len_cached:
|
349 |
+
self._set_cos_sin_cache(seq_len=seq_len, device=k.device, dtype=k.dtype)
|
350 |
+
|
351 |
+
# batch_size, 1, key_len, head_dim
|
352 |
+
k_cos = self.cos_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
353 |
+
k_sin = self.sin_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
354 |
+
|
355 |
+
q_cos = k_cos[..., -q.shape[2]:, :]
|
356 |
+
q_sin = k_sin[..., -q.shape[2]:, :]
|
357 |
+
|
358 |
+
q_embed = (q * q_cos) + (rotate_half(q) * q_sin)
|
359 |
+
k_embed = (k * k_cos) + (rotate_half(k) * k_sin)
|
360 |
+
return q_embed, k_embed
|
361 |
+
|
362 |
+
|
363 |
+
class LinearScalingRotaryEmbedding(RotaryEmbedding):
|
364 |
+
"""RotaryEmbedding extended with linear scaling. Credits to the Reddit user /u/kaiokendev"""
|
365 |
+
|
366 |
+
def __init__(self, dim, max_position_embeddings=32768, base=10000, device=None, scaling_factor=1.0):
|
367 |
+
self.scaling_factor = scaling_factor
|
368 |
+
super().__init__(dim, max_position_embeddings, base, device)
|
369 |
+
|
370 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
371 |
+
self.max_seq_len_cached = seq_len
|
372 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=torch.float32)
|
373 |
+
t = t / self.scaling_factor
|
374 |
+
|
375 |
+
freqs = torch.outer(t, self.inv_freq)
|
376 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
377 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
378 |
+
self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
|
379 |
+
self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
|
380 |
+
|
381 |
+
|
382 |
+
class DynamicNTKScalingRotaryEmbedding(RotaryEmbedding):
|
383 |
+
"""RotaryEmbedding extended with Dynamic NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla"""
|
384 |
+
|
385 |
+
def __init__(self, dim, max_position_embeddings=32768, base=10000, device=None, scaling_factor=1.0):
|
386 |
+
self.scaling_factor = scaling_factor
|
387 |
+
super().__init__(dim, max_position_embeddings, base, device)
|
388 |
+
|
389 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
390 |
+
self.max_seq_len_cached = seq_len
|
391 |
+
|
392 |
+
if seq_len > self.max_position_embeddings:
|
393 |
+
base = self.base * (
|
394 |
+
(self.scaling_factor * seq_len / self.max_position_embeddings) - (self.scaling_factor - 1)
|
395 |
+
) ** (self.dim / (self.dim - 2))
|
396 |
+
inv_freq = 1.0 / (base ** (torch.arange(0, self.dim, 2, dtype=torch.float32).to(device) / self.dim))
|
397 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
398 |
+
|
399 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype)
|
400 |
+
|
401 |
+
freqs = torch.outer(t, self.inv_freq)
|
402 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
403 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
404 |
+
self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
|
405 |
+
self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
|
406 |
+
|
407 |
+
|
408 |
+
class YarnRotaryEmbedding(torch.nn.Module):
|
409 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0, beta_slow=2, beta_fast=128):
|
410 |
+
super().__init__()
|
411 |
+
|
412 |
+
self.base = base
|
413 |
+
self.dim = dim
|
414 |
+
self.scaling_factor = scaling_factor
|
415 |
+
self.beta_slow = beta_slow
|
416 |
+
self.beta_fast = beta_fast
|
417 |
+
self.max_position_embeddings = max_position_embeddings
|
418 |
+
|
419 |
+
self._set_cos_sin_cache(
|
420 |
+
seq_len=math.ceil(max_position_embeddings * scaling_factor), device=device, dtype=torch.get_default_dtype()
|
421 |
+
)
|
422 |
+
|
423 |
+
def _get_factor(self):
|
424 |
+
# the dimension whose index is smaller than fast_dim rotates more than beta_fast
|
425 |
+
fast_dim = self.dim / 2 * (math.log(self.max_position_embeddings / (2 * math.pi * self.beta_fast)) / math.log(self.base))
|
426 |
+
fast_dim = max(math.floor(fast_dim), 0)
|
427 |
+
# the dimension whose index is bigger than slow_dim rotates less than beta_slow
|
428 |
+
slow_dim = self.dim / 2 * (math.log(self.max_position_embeddings / (2 * math.pi * self.beta_slow)) / math.log(self.base))
|
429 |
+
slow_dim = min(math.ceil(slow_dim), self.dim - 1)
|
430 |
+
|
431 |
+
if fast_dim == slow_dim:
|
432 |
+
slow_dim += 0.001
|
433 |
+
|
434 |
+
# NOTE: very important to use full precision here so that the factor is correct
|
435 |
+
dim_arange = torch.arange(0, self.dim // 2, dtype=torch.float32)
|
436 |
+
dim_factor = (dim_arange - fast_dim) / (slow_dim - fast_dim)
|
437 |
+
dim_factor = torch.clamp(dim_factor, 0, 1)
|
438 |
+
|
439 |
+
# align with the paper notation
|
440 |
+
return (1 - dim_factor)
|
441 |
+
|
442 |
+
def _get_temperature(self):
|
443 |
+
if self.scaling_factor <= 1:
|
444 |
+
return 1.0
|
445 |
+
return 0.07 * math.log(self.scaling_factor) + 1.0
|
446 |
+
|
447 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
448 |
+
dim_arange = torch.arange(0, self.dim, 2, device=device, dtype=torch.float32) / self.dim
|
449 |
+
# dim / 2
|
450 |
+
freq = self.base ** dim_arange
|
451 |
+
theta = 1 / freq
|
452 |
+
interleave_theta = theta / self.scaling_factor
|
453 |
+
|
454 |
+
factor = self._get_factor().to(device)
|
455 |
+
yarn_theta = factor * theta + (1 - factor) * interleave_theta
|
456 |
+
self.register_buffer("inv_freq", yarn_theta, persistent=False)
|
457 |
+
|
458 |
+
t = torch.arange(seq_len, device=device, dtype=torch.float32)
|
459 |
+
freqs = torch.outer(t, self.inv_freq)
|
460 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
461 |
+
|
462 |
+
# get attention temperature
|
463 |
+
temperature = self._get_temperature()
|
464 |
+
|
465 |
+
self.register_buffer("cos_cached", emb.cos() * temperature, persistent=False)
|
466 |
+
self.register_buffer("sin_cached", emb.sin() * temperature, persistent=False)
|
467 |
+
self.max_seq_len_cached = seq_len
|
468 |
+
|
469 |
+
def forward(self, q, k, position_ids):
|
470 |
+
seq_len = max(position_ids.max().item() + 1, k.shape[2])
|
471 |
+
|
472 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
473 |
+
if seq_len > self.max_seq_len_cached:
|
474 |
+
self.scaling_factor = seq_len / self.max_position_embeddings
|
475 |
+
self._set_cos_sin_cache(seq_len=seq_len, device=k.device, dtype=k.dtype)
|
476 |
+
|
477 |
+
k_cos = self.cos_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
478 |
+
k_sin = self.sin_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
479 |
+
|
480 |
+
q_cos = k_cos[..., -q.shape[2]:, :]
|
481 |
+
q_sin = k_sin[..., -q.shape[2]:, :]
|
482 |
+
|
483 |
+
q_embed = (q * q_cos) + (rotate_half(q) * q_sin)
|
484 |
+
k_embed = (k * k_cos) + (rotate_half(k) * k_sin)
|
485 |
+
return q_embed, k_embed
|
486 |
+
|
487 |
+
|
488 |
+
class YarnDynamicTemperatureRotaryEmbedding(torch.nn.Module):
|
489 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0, beta_slow=2, beta_fast=128):
|
490 |
+
super().__init__()
|
491 |
+
|
492 |
+
self.base = base
|
493 |
+
self.dim = dim
|
494 |
+
self.scaling_factor = scaling_factor
|
495 |
+
self.beta_slow = beta_slow
|
496 |
+
self.beta_fast = beta_fast
|
497 |
+
self.max_position_embeddings = max_position_embeddings
|
498 |
+
|
499 |
+
self._set_cos_sin_cache(
|
500 |
+
seq_len=math.ceil(max_position_embeddings * scaling_factor), device=device, dtype=torch.get_default_dtype()
|
501 |
+
)
|
502 |
+
|
503 |
+
def _get_factor(self):
|
504 |
+
# the dimension whose index is smaller than fast_dim rotates more than beta_fast
|
505 |
+
fast_dim = self.dim / 2 * (math.log(self.max_position_embeddings / (2 * math.pi * self.beta_fast)) / math.log(self.base))
|
506 |
+
fast_dim = max(math.floor(fast_dim), 0)
|
507 |
+
# the dimension whose index is bigger than slow_dim rotates less than beta_slow
|
508 |
+
slow_dim = self.dim / 2 * (math.log(self.max_position_embeddings / (2 * math.pi * self.beta_slow)) / math.log(self.base))
|
509 |
+
slow_dim = min(math.ceil(slow_dim), self.dim - 1)
|
510 |
+
|
511 |
+
if fast_dim == slow_dim:
|
512 |
+
slow_dim += 0.001
|
513 |
+
|
514 |
+
# NOTE: very important to use full precision here so that the factor is correct
|
515 |
+
dim_arange = torch.arange(0, self.dim // 2, dtype=torch.float32)
|
516 |
+
dim_factor = (dim_arange - fast_dim) / (slow_dim - fast_dim)
|
517 |
+
dim_factor = torch.clamp(dim_factor, 0, 1)
|
518 |
+
|
519 |
+
# align with the paper notation
|
520 |
+
return (1 - dim_factor)
|
521 |
+
|
522 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
523 |
+
dim_arange = torch.arange(0, self.dim, 2, device=device, dtype=torch.float32) / self.dim
|
524 |
+
# dim / 2
|
525 |
+
freq = self.base ** dim_arange
|
526 |
+
theta = 1 / freq
|
527 |
+
interleave_theta = theta / self.scaling_factor
|
528 |
+
|
529 |
+
factor = self._get_factor().to(device)
|
530 |
+
yarn_theta = factor * theta + (1 - factor) * interleave_theta
|
531 |
+
self.register_buffer("inv_freq", yarn_theta, persistent=False)
|
532 |
+
|
533 |
+
positions = torch.arange(seq_len, device=device, dtype=torch.float32)
|
534 |
+
freqs = torch.outer(positions, self.inv_freq)
|
535 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
536 |
+
|
537 |
+
# NOTE: get attention temperature that will be applied on the query vector
|
538 |
+
# temperature = torch.log(positions + 1) / math.log(self.max_position_embeddings)
|
539 |
+
temperature = (0.07 * torch.log((positions + 1) / self.max_position_embeddings) + 1) ** 2
|
540 |
+
temperature[:self.max_position_embeddings] = 1
|
541 |
+
self.register_buffer("temperature", temperature.unsqueeze(1), persistent=False)
|
542 |
+
|
543 |
+
self.register_buffer("cos_cached", emb.cos(), persistent=False)
|
544 |
+
self.register_buffer("sin_cached", emb.sin(), persistent=False)
|
545 |
+
self.max_seq_len_cached = seq_len
|
546 |
+
|
547 |
+
def forward(self, q, k, position_ids):
|
548 |
+
seq_len = max(position_ids.max().item() + 1, k.shape[2])
|
549 |
+
|
550 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
551 |
+
if seq_len > self.max_seq_len_cached:
|
552 |
+
self.scaling_factor = seq_len / self.max_position_embeddings
|
553 |
+
self._set_cos_sin_cache(seq_len=seq_len, device=k.device, dtype=k.dtype)
|
554 |
+
|
555 |
+
# batch_size, 1, key_len, head_dim
|
556 |
+
k_cos = self.cos_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
557 |
+
k_sin = self.sin_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
558 |
+
|
559 |
+
q_cos = k_cos[..., -q.shape[2]:, :]
|
560 |
+
q_sin = k_sin[..., -q.shape[2]:, :]
|
561 |
+
|
562 |
+
q_position_ids = position_ids[:, -q.shape[2]:]
|
563 |
+
temperature = self.temperature[q_position_ids].to(dtype=k.dtype).unsqueeze(1)
|
564 |
+
q_cos = q_cos * temperature
|
565 |
+
q_sin = q_sin * temperature
|
566 |
+
|
567 |
+
q_embed = (q * q_cos) + (rotate_half(q) * q_sin)
|
568 |
+
k_embed = (k * k_cos) + (rotate_half(k) * k_sin)
|
569 |
+
return q_embed, k_embed
|
570 |
+
|
571 |
+
|
572 |
+
class YarnDynamicTemperatureLogNRotaryEmbedding(torch.nn.Module):
|
573 |
+
def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0, beta_slow=2, beta_fast=128):
|
574 |
+
super().__init__()
|
575 |
+
|
576 |
+
self.base = base
|
577 |
+
self.dim = dim
|
578 |
+
self.scaling_factor = scaling_factor
|
579 |
+
self.beta_slow = beta_slow
|
580 |
+
self.beta_fast = beta_fast
|
581 |
+
self.max_position_embeddings = max_position_embeddings
|
582 |
+
|
583 |
+
self._set_cos_sin_cache(
|
584 |
+
seq_len=math.ceil(max_position_embeddings * scaling_factor), device=device, dtype=torch.get_default_dtype()
|
585 |
+
)
|
586 |
+
|
587 |
+
def _get_factor(self):
|
588 |
+
# the dimension whose index is smaller than fast_dim rotates more than beta_fast
|
589 |
+
fast_dim = self.dim / 2 * (math.log(self.max_position_embeddings / (2 * math.pi * self.beta_fast)) / math.log(self.base))
|
590 |
+
fast_dim = max(math.floor(fast_dim), 0)
|
591 |
+
# the dimension whose index is bigger than slow_dim rotates less than beta_slow
|
592 |
+
slow_dim = self.dim / 2 * (math.log(self.max_position_embeddings / (2 * math.pi * self.beta_slow)) / math.log(self.base))
|
593 |
+
slow_dim = min(math.ceil(slow_dim), self.dim - 1)
|
594 |
+
|
595 |
+
if fast_dim == slow_dim:
|
596 |
+
slow_dim += 0.001
|
597 |
+
|
598 |
+
# NOTE: very important to use full precision here so that the factor is correct
|
599 |
+
dim_arange = torch.arange(0, self.dim // 2, dtype=torch.float32)
|
600 |
+
dim_factor = (dim_arange - fast_dim) / (slow_dim - fast_dim)
|
601 |
+
dim_factor = torch.clamp(dim_factor, 0, 1)
|
602 |
+
|
603 |
+
# align with the paper notation
|
604 |
+
return (1 - dim_factor)
|
605 |
+
|
606 |
+
def _set_cos_sin_cache(self, seq_len, device, dtype):
|
607 |
+
dim_arange = torch.arange(0, self.dim, 2, device=device, dtype=torch.float32) / self.dim
|
608 |
+
# dim / 2
|
609 |
+
freq = self.base ** dim_arange
|
610 |
+
theta = 1 / freq
|
611 |
+
interleave_theta = theta / self.scaling_factor
|
612 |
+
|
613 |
+
factor = self._get_factor().to(device)
|
614 |
+
yarn_theta = factor * theta + (1 - factor) * interleave_theta
|
615 |
+
self.register_buffer("inv_freq", yarn_theta, persistent=False)
|
616 |
+
|
617 |
+
positions = torch.arange(seq_len, device=device, dtype=torch.float32)
|
618 |
+
freqs = torch.outer(positions, self.inv_freq)
|
619 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
620 |
+
|
621 |
+
# NOTE: get attention temperature that will be applied on the query vector
|
622 |
+
temperature = torch.log(positions + 1) / math.log(self.max_position_embeddings)
|
623 |
+
# temperature = (0.07 * torch.log((positions + 1) / self.max_position_embeddings) + 1) ** 2
|
624 |
+
temperature[:self.max_position_embeddings] = 1
|
625 |
+
self.register_buffer("temperature", temperature.unsqueeze(1), persistent=False)
|
626 |
+
|
627 |
+
self.register_buffer("cos_cached", emb.cos(), persistent=False)
|
628 |
+
self.register_buffer("sin_cached", emb.sin(), persistent=False)
|
629 |
+
self.max_seq_len_cached = seq_len
|
630 |
+
|
631 |
+
def forward(self, q, k, position_ids):
|
632 |
+
seq_len = max(position_ids.max().item() + 1, k.shape[2])
|
633 |
+
|
634 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
635 |
+
if seq_len > self.max_seq_len_cached:
|
636 |
+
self.scaling_factor = seq_len / self.max_position_embeddings
|
637 |
+
self._set_cos_sin_cache(seq_len=seq_len, device=k.device, dtype=k.dtype)
|
638 |
+
|
639 |
+
# batch_size, 1, key_len, head_dim
|
640 |
+
k_cos = self.cos_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
641 |
+
k_sin = self.sin_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
642 |
+
|
643 |
+
q_cos = k_cos[..., -q.shape[2]:, :]
|
644 |
+
q_sin = k_sin[..., -q.shape[2]:, :]
|
645 |
+
|
646 |
+
q_position_ids = position_ids[:, -q.shape[2]:]
|
647 |
+
temperature = self.temperature[q_position_ids].to(dtype=k.dtype).unsqueeze(1)
|
648 |
+
q_cos = q_cos * temperature
|
649 |
+
q_sin = q_sin * temperature
|
650 |
+
|
651 |
+
q_embed = (q * q_cos) + (rotate_half(q) * q_sin)
|
652 |
+
k_embed = (k * k_cos) + (rotate_half(k) * k_sin)
|
653 |
+
return q_embed, k_embed
|
654 |
+
|
655 |
+
|
656 |
+
class Llama3RotaryEmbedding(torch.nn.Module):
|
657 |
+
def __init__(self, dim, max_position_embeddings=8192, base=10000, device=None, scaling_factor=1.0, original_max_position_embeddings=8192, low_freq_factor=1, high_freq_factor=4):
|
658 |
+
super().__init__()
|
659 |
+
|
660 |
+
self.base = base
|
661 |
+
self.dim = dim
|
662 |
+
self.scaling_factor = scaling_factor
|
663 |
+
self.original_max_position_embeddings = original_max_position_embeddings
|
664 |
+
self.max_position_embeddings = max(max_position_embeddings, int(original_max_position_embeddings * scaling_factor))
|
665 |
+
self.low_freq_factor = low_freq_factor
|
666 |
+
self.high_freq_factor = high_freq_factor
|
667 |
+
|
668 |
+
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2, dtype=torch.float32).to(device) / self.dim))
|
669 |
+
low_freq_wavelen = self.original_max_position_embeddings / low_freq_factor
|
670 |
+
high_freq_wavelen = self.original_max_position_embeddings / high_freq_factor
|
671 |
+
new_freqs = []
|
672 |
+
for freq in inv_freq:
|
673 |
+
wavelen = 2 * math.pi / freq
|
674 |
+
if wavelen < high_freq_wavelen:
|
675 |
+
new_freqs.append(freq)
|
676 |
+
elif wavelen > low_freq_wavelen:
|
677 |
+
new_freqs.append(freq / scaling_factor)
|
678 |
+
else:
|
679 |
+
assert low_freq_wavelen != high_freq_wavelen
|
680 |
+
smooth = (self.original_max_position_embeddings / wavelen - low_freq_factor) / (high_freq_factor - low_freq_factor)
|
681 |
+
new_freqs.append((1 - smooth) * freq / scaling_factor + smooth * freq)
|
682 |
+
inv_freq = torch.tensor(new_freqs, dtype=inv_freq.dtype, device=inv_freq.device)
|
683 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
684 |
+
|
685 |
+
self._set_cos_sin_cache(seq_len=self.max_position_embeddings, device=device)
|
686 |
+
|
687 |
+
def _set_cos_sin_cache(self, seq_len, device):
|
688 |
+
self.max_seq_len_cached = seq_len
|
689 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=torch.float32)
|
690 |
+
freqs = torch.outer(t, self.inv_freq)
|
691 |
+
# Different from paper, but it uses a different permutation in order to obtain the same calculation
|
692 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
693 |
+
self.register_buffer("cos_cached", emb.cos(), persistent=False)
|
694 |
+
self.register_buffer("sin_cached", emb.sin(), persistent=False)
|
695 |
+
|
696 |
+
def forward(self, q, k, position_ids):
|
697 |
+
seq_len = max(position_ids.max().item() + 1, k.shape[2])
|
698 |
+
|
699 |
+
# x: [bs, num_attention_heads, seq_len, head_size]
|
700 |
+
if seq_len > self.max_seq_len_cached:
|
701 |
+
self._set_cos_sin_cache(seq_len=seq_len, device=k.device)
|
702 |
+
|
703 |
+
k_cos = self.cos_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
704 |
+
k_sin = self.sin_cached[position_ids].to(dtype=k.dtype).unsqueeze(1)
|
705 |
+
|
706 |
+
q_cos = k_cos[..., -q.shape[2]:, :]
|
707 |
+
q_sin = k_sin[..., -q.shape[2]:, :]
|
708 |
+
|
709 |
+
q_embed = (q * q_cos) + (rotate_half(q) * q_sin)
|
710 |
+
k_embed = (k * k_cos) + (rotate_half(k) * k_sin)
|
711 |
+
return q_embed, k_embed
|
special_tokens_map.json
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"eos_token": {
|
10 |
+
"content": "</s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"pad_token": "</s>",
|
17 |
+
"unk_token": {
|
18 |
+
"content": "<unk>",
|
19 |
+
"lstrip": false,
|
20 |
+
"normalized": false,
|
21 |
+
"rstrip": false,
|
22 |
+
"single_word": false
|
23 |
+
}
|
24 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": true,
|
3 |
+
"add_eos_token": false,
|
4 |
+
"added_tokens_decoder": {
|
5 |
+
"0": {
|
6 |
+
"content": "<unk>",
|
7 |
+
"lstrip": false,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false,
|
11 |
+
"special": true
|
12 |
+
},
|
13 |
+
"1": {
|
14 |
+
"content": "<s>",
|
15 |
+
"lstrip": false,
|
16 |
+
"normalized": false,
|
17 |
+
"rstrip": false,
|
18 |
+
"single_word": false,
|
19 |
+
"special": true
|
20 |
+
},
|
21 |
+
"2": {
|
22 |
+
"content": "</s>",
|
23 |
+
"lstrip": false,
|
24 |
+
"normalized": false,
|
25 |
+
"rstrip": false,
|
26 |
+
"single_word": false,
|
27 |
+
"special": true
|
28 |
+
}
|
29 |
+
},
|
30 |
+
"additional_special_tokens": [],
|
31 |
+
"bos_token": "<s>",
|
32 |
+
"chat_template": "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}",
|
33 |
+
"clean_up_tokenization_spaces": false,
|
34 |
+
"eos_token": "</s>",
|
35 |
+
"legacy": true,
|
36 |
+
"model_max_length": 1000000000000000019884624838656,
|
37 |
+
"pad_token": "</s>",
|
38 |
+
"padding_side": "left",
|
39 |
+
"sp_model_kwargs": {},
|
40 |
+
"spaces_between_special_tokens": false,
|
41 |
+
"tokenizer_class": "LlamaTokenizer",
|
42 |
+
"unk_token": "<unk>",
|
43 |
+
"use_default_system_prompt": false
|
44 |
+
}
|
trainer_state.json
ADDED
@@ -0,0 +1,2156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"best_metric": null,
|
3 |
+
"best_model_checkpoint": null,
|
4 |
+
"epoch": 1.0,
|
5 |
+
"eval_steps": 500,
|
6 |
+
"global_step": 15260,
|
7 |
+
"is_hyper_param_search": false,
|
8 |
+
"is_local_process_zero": true,
|
9 |
+
"is_world_process_zero": true,
|
10 |
+
"log_history": [
|
11 |
+
{
|
12 |
+
"epoch": 0.0,
|
13 |
+
"grad_norm": 0.9230163097381592,
|
14 |
+
"learning_rate": 4.984598243544371e-05,
|
15 |
+
"loss": 2.0529,
|
16 |
+
"step": 50
|
17 |
+
},
|
18 |
+
{
|
19 |
+
"epoch": 0.01,
|
20 |
+
"grad_norm": 1.205999732017517,
|
21 |
+
"learning_rate": 4.968213396251148e-05,
|
22 |
+
"loss": 1.8376,
|
23 |
+
"step": 100
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"epoch": 0.01,
|
27 |
+
"grad_norm": 0.5816870331764221,
|
28 |
+
"learning_rate": 4.951828548957924e-05,
|
29 |
+
"loss": 1.7882,
|
30 |
+
"step": 150
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"epoch": 0.01,
|
34 |
+
"grad_norm": 0.45057499408721924,
|
35 |
+
"learning_rate": 4.935443701664701e-05,
|
36 |
+
"loss": 1.8113,
|
37 |
+
"step": 200
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"epoch": 0.02,
|
41 |
+
"grad_norm": 0.5159332752227783,
|
42 |
+
"learning_rate": 4.9190588543714776e-05,
|
43 |
+
"loss": 1.8183,
|
44 |
+
"step": 250
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"epoch": 0.02,
|
48 |
+
"grad_norm": 0.42658549547195435,
|
49 |
+
"learning_rate": 4.9026740070782544e-05,
|
50 |
+
"loss": 1.8049,
|
51 |
+
"step": 300
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"epoch": 0.02,
|
55 |
+
"grad_norm": 0.6193262338638306,
|
56 |
+
"learning_rate": 4.8862891597850306e-05,
|
57 |
+
"loss": 1.8195,
|
58 |
+
"step": 350
|
59 |
+
},
|
60 |
+
{
|
61 |
+
"epoch": 0.03,
|
62 |
+
"grad_norm": 0.40126094222068787,
|
63 |
+
"learning_rate": 4.8699043124918075e-05,
|
64 |
+
"loss": 1.8445,
|
65 |
+
"step": 400
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"epoch": 0.03,
|
69 |
+
"grad_norm": 0.4089142978191376,
|
70 |
+
"learning_rate": 4.853519465198584e-05,
|
71 |
+
"loss": 1.7967,
|
72 |
+
"step": 450
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"epoch": 0.03,
|
76 |
+
"grad_norm": 0.3923342525959015,
|
77 |
+
"learning_rate": 4.837134617905361e-05,
|
78 |
+
"loss": 1.7941,
|
79 |
+
"step": 500
|
80 |
+
},
|
81 |
+
{
|
82 |
+
"epoch": 0.04,
|
83 |
+
"grad_norm": 0.415017694234848,
|
84 |
+
"learning_rate": 4.820749770612138e-05,
|
85 |
+
"loss": 1.7999,
|
86 |
+
"step": 550
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"epoch": 0.04,
|
90 |
+
"grad_norm": 0.5846891403198242,
|
91 |
+
"learning_rate": 4.804364923318915e-05,
|
92 |
+
"loss": 1.8064,
|
93 |
+
"step": 600
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"epoch": 0.04,
|
97 |
+
"grad_norm": 0.3614323139190674,
|
98 |
+
"learning_rate": 4.787980076025692e-05,
|
99 |
+
"loss": 1.7865,
|
100 |
+
"step": 650
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"epoch": 0.05,
|
104 |
+
"grad_norm": 0.37756502628326416,
|
105 |
+
"learning_rate": 4.7715952287324686e-05,
|
106 |
+
"loss": 1.7745,
|
107 |
+
"step": 700
|
108 |
+
},
|
109 |
+
{
|
110 |
+
"epoch": 0.05,
|
111 |
+
"grad_norm": 0.3763517141342163,
|
112 |
+
"learning_rate": 4.7552103814392455e-05,
|
113 |
+
"loss": 1.8188,
|
114 |
+
"step": 750
|
115 |
+
},
|
116 |
+
{
|
117 |
+
"epoch": 0.05,
|
118 |
+
"grad_norm": 0.41242149472236633,
|
119 |
+
"learning_rate": 4.7388255341460216e-05,
|
120 |
+
"loss": 1.8238,
|
121 |
+
"step": 800
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"epoch": 0.06,
|
125 |
+
"grad_norm": 0.4072262644767761,
|
126 |
+
"learning_rate": 4.7224406868527985e-05,
|
127 |
+
"loss": 1.838,
|
128 |
+
"step": 850
|
129 |
+
},
|
130 |
+
{
|
131 |
+
"epoch": 0.06,
|
132 |
+
"grad_norm": 0.5368711352348328,
|
133 |
+
"learning_rate": 4.7060558395595753e-05,
|
134 |
+
"loss": 1.8121,
|
135 |
+
"step": 900
|
136 |
+
},
|
137 |
+
{
|
138 |
+
"epoch": 0.06,
|
139 |
+
"grad_norm": 0.3726208508014679,
|
140 |
+
"learning_rate": 4.689670992266352e-05,
|
141 |
+
"loss": 1.7872,
|
142 |
+
"step": 950
|
143 |
+
},
|
144 |
+
{
|
145 |
+
"epoch": 0.07,
|
146 |
+
"grad_norm": 0.3755347728729248,
|
147 |
+
"learning_rate": 4.673286144973129e-05,
|
148 |
+
"loss": 1.8164,
|
149 |
+
"step": 1000
|
150 |
+
},
|
151 |
+
{
|
152 |
+
"epoch": 0.07,
|
153 |
+
"grad_norm": 0.6106815934181213,
|
154 |
+
"learning_rate": 4.656901297679906e-05,
|
155 |
+
"loss": 1.8034,
|
156 |
+
"step": 1050
|
157 |
+
},
|
158 |
+
{
|
159 |
+
"epoch": 0.07,
|
160 |
+
"grad_norm": 0.4525647461414337,
|
161 |
+
"learning_rate": 4.640516450386683e-05,
|
162 |
+
"loss": 1.8174,
|
163 |
+
"step": 1100
|
164 |
+
},
|
165 |
+
{
|
166 |
+
"epoch": 0.08,
|
167 |
+
"grad_norm": 0.4508289396762848,
|
168 |
+
"learning_rate": 4.6241316030934596e-05,
|
169 |
+
"loss": 1.7958,
|
170 |
+
"step": 1150
|
171 |
+
},
|
172 |
+
{
|
173 |
+
"epoch": 0.08,
|
174 |
+
"grad_norm": 0.5615507960319519,
|
175 |
+
"learning_rate": 4.6077467558002365e-05,
|
176 |
+
"loss": 1.807,
|
177 |
+
"step": 1200
|
178 |
+
},
|
179 |
+
{
|
180 |
+
"epoch": 0.08,
|
181 |
+
"grad_norm": 0.5430244207382202,
|
182 |
+
"learning_rate": 4.5913619085070133e-05,
|
183 |
+
"loss": 1.7694,
|
184 |
+
"step": 1250
|
185 |
+
},
|
186 |
+
{
|
187 |
+
"epoch": 0.09,
|
188 |
+
"grad_norm": 0.4304679334163666,
|
189 |
+
"learning_rate": 4.57497706121379e-05,
|
190 |
+
"loss": 1.9162,
|
191 |
+
"step": 1300
|
192 |
+
},
|
193 |
+
{
|
194 |
+
"epoch": 0.09,
|
195 |
+
"grad_norm": 0.4160442650318146,
|
196 |
+
"learning_rate": 4.5585922139205664e-05,
|
197 |
+
"loss": 1.8106,
|
198 |
+
"step": 1350
|
199 |
+
},
|
200 |
+
{
|
201 |
+
"epoch": 0.09,
|
202 |
+
"grad_norm": 0.5771602988243103,
|
203 |
+
"learning_rate": 4.542207366627343e-05,
|
204 |
+
"loss": 1.7815,
|
205 |
+
"step": 1400
|
206 |
+
},
|
207 |
+
{
|
208 |
+
"epoch": 0.1,
|
209 |
+
"grad_norm": 0.6032801866531372,
|
210 |
+
"learning_rate": 4.52582251933412e-05,
|
211 |
+
"loss": 1.8171,
|
212 |
+
"step": 1450
|
213 |
+
},
|
214 |
+
{
|
215 |
+
"epoch": 0.1,
|
216 |
+
"grad_norm": 0.4265432059764862,
|
217 |
+
"learning_rate": 4.509437672040897e-05,
|
218 |
+
"loss": 1.7537,
|
219 |
+
"step": 1500
|
220 |
+
},
|
221 |
+
{
|
222 |
+
"epoch": 0.1,
|
223 |
+
"grad_norm": 0.6046428084373474,
|
224 |
+
"learning_rate": 4.493052824747673e-05,
|
225 |
+
"loss": 1.8251,
|
226 |
+
"step": 1550
|
227 |
+
},
|
228 |
+
{
|
229 |
+
"epoch": 0.1,
|
230 |
+
"grad_norm": 0.4501182436943054,
|
231 |
+
"learning_rate": 4.47666797745445e-05,
|
232 |
+
"loss": 1.8186,
|
233 |
+
"step": 1600
|
234 |
+
},
|
235 |
+
{
|
236 |
+
"epoch": 0.11,
|
237 |
+
"grad_norm": 0.5386430621147156,
|
238 |
+
"learning_rate": 4.460283130161227e-05,
|
239 |
+
"loss": 1.82,
|
240 |
+
"step": 1650
|
241 |
+
},
|
242 |
+
{
|
243 |
+
"epoch": 0.11,
|
244 |
+
"grad_norm": 0.549318790435791,
|
245 |
+
"learning_rate": 4.443898282868004e-05,
|
246 |
+
"loss": 1.9232,
|
247 |
+
"step": 1700
|
248 |
+
},
|
249 |
+
{
|
250 |
+
"epoch": 0.11,
|
251 |
+
"grad_norm": 0.432767778635025,
|
252 |
+
"learning_rate": 4.4275134355747806e-05,
|
253 |
+
"loss": 1.7913,
|
254 |
+
"step": 1750
|
255 |
+
},
|
256 |
+
{
|
257 |
+
"epoch": 0.12,
|
258 |
+
"grad_norm": 0.5354149341583252,
|
259 |
+
"learning_rate": 4.4111285882815574e-05,
|
260 |
+
"loss": 1.7933,
|
261 |
+
"step": 1800
|
262 |
+
},
|
263 |
+
{
|
264 |
+
"epoch": 0.12,
|
265 |
+
"grad_norm": 0.46177294850349426,
|
266 |
+
"learning_rate": 4.394743740988334e-05,
|
267 |
+
"loss": 1.7801,
|
268 |
+
"step": 1850
|
269 |
+
},
|
270 |
+
{
|
271 |
+
"epoch": 0.12,
|
272 |
+
"grad_norm": 4.336757183074951,
|
273 |
+
"learning_rate": 4.378358893695111e-05,
|
274 |
+
"loss": 1.774,
|
275 |
+
"step": 1900
|
276 |
+
},
|
277 |
+
{
|
278 |
+
"epoch": 0.13,
|
279 |
+
"grad_norm": 0.44567111134529114,
|
280 |
+
"learning_rate": 4.361974046401888e-05,
|
281 |
+
"loss": 1.7708,
|
282 |
+
"step": 1950
|
283 |
+
},
|
284 |
+
{
|
285 |
+
"epoch": 0.13,
|
286 |
+
"grad_norm": 0.4324832260608673,
|
287 |
+
"learning_rate": 4.345589199108664e-05,
|
288 |
+
"loss": 1.7743,
|
289 |
+
"step": 2000
|
290 |
+
},
|
291 |
+
{
|
292 |
+
"epoch": 0.13,
|
293 |
+
"grad_norm": 0.35905638337135315,
|
294 |
+
"learning_rate": 4.329204351815441e-05,
|
295 |
+
"loss": 1.8115,
|
296 |
+
"step": 2050
|
297 |
+
},
|
298 |
+
{
|
299 |
+
"epoch": 0.14,
|
300 |
+
"grad_norm": 0.6442646980285645,
|
301 |
+
"learning_rate": 4.312819504522218e-05,
|
302 |
+
"loss": 1.7691,
|
303 |
+
"step": 2100
|
304 |
+
},
|
305 |
+
{
|
306 |
+
"epoch": 0.14,
|
307 |
+
"grad_norm": 0.385105162858963,
|
308 |
+
"learning_rate": 4.296434657228995e-05,
|
309 |
+
"loss": 1.7991,
|
310 |
+
"step": 2150
|
311 |
+
},
|
312 |
+
{
|
313 |
+
"epoch": 0.14,
|
314 |
+
"grad_norm": 0.4879704713821411,
|
315 |
+
"learning_rate": 4.2800498099357716e-05,
|
316 |
+
"loss": 1.7906,
|
317 |
+
"step": 2200
|
318 |
+
},
|
319 |
+
{
|
320 |
+
"epoch": 0.15,
|
321 |
+
"grad_norm": 0.3042909801006317,
|
322 |
+
"learning_rate": 4.2636649626425485e-05,
|
323 |
+
"loss": 1.7957,
|
324 |
+
"step": 2250
|
325 |
+
},
|
326 |
+
{
|
327 |
+
"epoch": 0.15,
|
328 |
+
"grad_norm": 0.41942423582077026,
|
329 |
+
"learning_rate": 4.247280115349325e-05,
|
330 |
+
"loss": 1.791,
|
331 |
+
"step": 2300
|
332 |
+
},
|
333 |
+
{
|
334 |
+
"epoch": 0.15,
|
335 |
+
"grad_norm": 0.40257078409194946,
|
336 |
+
"learning_rate": 4.230895268056102e-05,
|
337 |
+
"loss": 1.7815,
|
338 |
+
"step": 2350
|
339 |
+
},
|
340 |
+
{
|
341 |
+
"epoch": 0.16,
|
342 |
+
"grad_norm": 0.4478552043437958,
|
343 |
+
"learning_rate": 4.214510420762879e-05,
|
344 |
+
"loss": 1.803,
|
345 |
+
"step": 2400
|
346 |
+
},
|
347 |
+
{
|
348 |
+
"epoch": 0.16,
|
349 |
+
"grad_norm": 284.23187255859375,
|
350 |
+
"learning_rate": 4.198125573469656e-05,
|
351 |
+
"loss": 1.8267,
|
352 |
+
"step": 2450
|
353 |
+
},
|
354 |
+
{
|
355 |
+
"epoch": 0.16,
|
356 |
+
"grad_norm": 0.3262351453304291,
|
357 |
+
"learning_rate": 4.181740726176433e-05,
|
358 |
+
"loss": 1.8991,
|
359 |
+
"step": 2500
|
360 |
+
},
|
361 |
+
{
|
362 |
+
"epoch": 0.17,
|
363 |
+
"grad_norm": 0.4118567109107971,
|
364 |
+
"learning_rate": 4.165355878883209e-05,
|
365 |
+
"loss": 1.8224,
|
366 |
+
"step": 2550
|
367 |
+
},
|
368 |
+
{
|
369 |
+
"epoch": 0.17,
|
370 |
+
"grad_norm": 1.5378553867340088,
|
371 |
+
"learning_rate": 4.148971031589986e-05,
|
372 |
+
"loss": 1.7887,
|
373 |
+
"step": 2600
|
374 |
+
},
|
375 |
+
{
|
376 |
+
"epoch": 0.17,
|
377 |
+
"grad_norm": 0.3631303012371063,
|
378 |
+
"learning_rate": 4.1325861842967626e-05,
|
379 |
+
"loss": 1.7825,
|
380 |
+
"step": 2650
|
381 |
+
},
|
382 |
+
{
|
383 |
+
"epoch": 0.18,
|
384 |
+
"grad_norm": 0.3822169303894043,
|
385 |
+
"learning_rate": 4.116201337003539e-05,
|
386 |
+
"loss": 1.7608,
|
387 |
+
"step": 2700
|
388 |
+
},
|
389 |
+
{
|
390 |
+
"epoch": 0.18,
|
391 |
+
"grad_norm": 0.41518792510032654,
|
392 |
+
"learning_rate": 4.099816489710316e-05,
|
393 |
+
"loss": 1.8161,
|
394 |
+
"step": 2750
|
395 |
+
},
|
396 |
+
{
|
397 |
+
"epoch": 0.18,
|
398 |
+
"grad_norm": 0.517413318157196,
|
399 |
+
"learning_rate": 4.0834316424170925e-05,
|
400 |
+
"loss": 1.8081,
|
401 |
+
"step": 2800
|
402 |
+
},
|
403 |
+
{
|
404 |
+
"epoch": 0.19,
|
405 |
+
"grad_norm": 0.3587147891521454,
|
406 |
+
"learning_rate": 4.0670467951238694e-05,
|
407 |
+
"loss": 1.8077,
|
408 |
+
"step": 2850
|
409 |
+
},
|
410 |
+
{
|
411 |
+
"epoch": 0.19,
|
412 |
+
"grad_norm": 0.39981338381767273,
|
413 |
+
"learning_rate": 4.050661947830646e-05,
|
414 |
+
"loss": 1.7991,
|
415 |
+
"step": 2900
|
416 |
+
},
|
417 |
+
{
|
418 |
+
"epoch": 0.19,
|
419 |
+
"grad_norm": 0.35814446210861206,
|
420 |
+
"learning_rate": 4.034277100537423e-05,
|
421 |
+
"loss": 1.7933,
|
422 |
+
"step": 2950
|
423 |
+
},
|
424 |
+
{
|
425 |
+
"epoch": 0.2,
|
426 |
+
"grad_norm": 0.317147433757782,
|
427 |
+
"learning_rate": 4.0178922532442e-05,
|
428 |
+
"loss": 1.8309,
|
429 |
+
"step": 3000
|
430 |
+
},
|
431 |
+
{
|
432 |
+
"epoch": 0.2,
|
433 |
+
"grad_norm": 0.4601675271987915,
|
434 |
+
"learning_rate": 4.001507405950977e-05,
|
435 |
+
"loss": 1.7635,
|
436 |
+
"step": 3050
|
437 |
+
},
|
438 |
+
{
|
439 |
+
"epoch": 0.2,
|
440 |
+
"grad_norm": 0.3678904175758362,
|
441 |
+
"learning_rate": 3.985122558657754e-05,
|
442 |
+
"loss": 1.7948,
|
443 |
+
"step": 3100
|
444 |
+
},
|
445 |
+
{
|
446 |
+
"epoch": 0.21,
|
447 |
+
"grad_norm": 0.37515679001808167,
|
448 |
+
"learning_rate": 3.9687377113645305e-05,
|
449 |
+
"loss": 1.823,
|
450 |
+
"step": 3150
|
451 |
+
},
|
452 |
+
{
|
453 |
+
"epoch": 0.21,
|
454 |
+
"grad_norm": 0.4639309346675873,
|
455 |
+
"learning_rate": 3.952352864071307e-05,
|
456 |
+
"loss": 1.7888,
|
457 |
+
"step": 3200
|
458 |
+
},
|
459 |
+
{
|
460 |
+
"epoch": 0.21,
|
461 |
+
"grad_norm": 0.45223185420036316,
|
462 |
+
"learning_rate": 3.9359680167780836e-05,
|
463 |
+
"loss": 1.7366,
|
464 |
+
"step": 3250
|
465 |
+
},
|
466 |
+
{
|
467 |
+
"epoch": 0.22,
|
468 |
+
"grad_norm": 0.40405765175819397,
|
469 |
+
"learning_rate": 3.9195831694848604e-05,
|
470 |
+
"loss": 1.7682,
|
471 |
+
"step": 3300
|
472 |
+
},
|
473 |
+
{
|
474 |
+
"epoch": 0.22,
|
475 |
+
"grad_norm": 0.45404157042503357,
|
476 |
+
"learning_rate": 3.903198322191637e-05,
|
477 |
+
"loss": 1.798,
|
478 |
+
"step": 3350
|
479 |
+
},
|
480 |
+
{
|
481 |
+
"epoch": 0.22,
|
482 |
+
"grad_norm": 0.5335371494293213,
|
483 |
+
"learning_rate": 3.886813474898414e-05,
|
484 |
+
"loss": 1.8179,
|
485 |
+
"step": 3400
|
486 |
+
},
|
487 |
+
{
|
488 |
+
"epoch": 0.23,
|
489 |
+
"grad_norm": 0.4759540557861328,
|
490 |
+
"learning_rate": 3.870428627605191e-05,
|
491 |
+
"loss": 1.7829,
|
492 |
+
"step": 3450
|
493 |
+
},
|
494 |
+
{
|
495 |
+
"epoch": 0.23,
|
496 |
+
"grad_norm": 0.5050774216651917,
|
497 |
+
"learning_rate": 3.854043780311968e-05,
|
498 |
+
"loss": 1.7953,
|
499 |
+
"step": 3500
|
500 |
+
},
|
501 |
+
{
|
502 |
+
"epoch": 0.23,
|
503 |
+
"grad_norm": 0.44674813747406006,
|
504 |
+
"learning_rate": 3.837658933018745e-05,
|
505 |
+
"loss": 1.7945,
|
506 |
+
"step": 3550
|
507 |
+
},
|
508 |
+
{
|
509 |
+
"epoch": 0.24,
|
510 |
+
"grad_norm": 0.34432777762413025,
|
511 |
+
"learning_rate": 3.8212740857255216e-05,
|
512 |
+
"loss": 1.7968,
|
513 |
+
"step": 3600
|
514 |
+
},
|
515 |
+
{
|
516 |
+
"epoch": 0.24,
|
517 |
+
"grad_norm": 0.4797002077102661,
|
518 |
+
"learning_rate": 3.8048892384322984e-05,
|
519 |
+
"loss": 1.7275,
|
520 |
+
"step": 3650
|
521 |
+
},
|
522 |
+
{
|
523 |
+
"epoch": 0.24,
|
524 |
+
"grad_norm": 0.40203359723091125,
|
525 |
+
"learning_rate": 3.788504391139075e-05,
|
526 |
+
"loss": 1.7905,
|
527 |
+
"step": 3700
|
528 |
+
},
|
529 |
+
{
|
530 |
+
"epoch": 0.25,
|
531 |
+
"grad_norm": 0.3257518708705902,
|
532 |
+
"learning_rate": 3.7721195438458515e-05,
|
533 |
+
"loss": 1.8077,
|
534 |
+
"step": 3750
|
535 |
+
},
|
536 |
+
{
|
537 |
+
"epoch": 0.25,
|
538 |
+
"grad_norm": 0.38829201459884644,
|
539 |
+
"learning_rate": 3.755734696552628e-05,
|
540 |
+
"loss": 1.7965,
|
541 |
+
"step": 3800
|
542 |
+
},
|
543 |
+
{
|
544 |
+
"epoch": 0.25,
|
545 |
+
"grad_norm": 0.3530164062976837,
|
546 |
+
"learning_rate": 3.739349849259405e-05,
|
547 |
+
"loss": 1.7925,
|
548 |
+
"step": 3850
|
549 |
+
},
|
550 |
+
{
|
551 |
+
"epoch": 0.26,
|
552 |
+
"grad_norm": 0.521428644657135,
|
553 |
+
"learning_rate": 3.7229650019661814e-05,
|
554 |
+
"loss": 1.7921,
|
555 |
+
"step": 3900
|
556 |
+
},
|
557 |
+
{
|
558 |
+
"epoch": 0.26,
|
559 |
+
"grad_norm": 0.3673698902130127,
|
560 |
+
"learning_rate": 3.706580154672958e-05,
|
561 |
+
"loss": 1.7981,
|
562 |
+
"step": 3950
|
563 |
+
},
|
564 |
+
{
|
565 |
+
"epoch": 0.26,
|
566 |
+
"grad_norm": 0.3477175235748291,
|
567 |
+
"learning_rate": 3.690195307379735e-05,
|
568 |
+
"loss": 1.7857,
|
569 |
+
"step": 4000
|
570 |
+
},
|
571 |
+
{
|
572 |
+
"epoch": 0.27,
|
573 |
+
"grad_norm": 0.3988274037837982,
|
574 |
+
"learning_rate": 3.673810460086512e-05,
|
575 |
+
"loss": 1.8014,
|
576 |
+
"step": 4050
|
577 |
+
},
|
578 |
+
{
|
579 |
+
"epoch": 0.27,
|
580 |
+
"grad_norm": 0.48254644870758057,
|
581 |
+
"learning_rate": 3.657425612793289e-05,
|
582 |
+
"loss": 1.8317,
|
583 |
+
"step": 4100
|
584 |
+
},
|
585 |
+
{
|
586 |
+
"epoch": 0.27,
|
587 |
+
"grad_norm": 0.9297109842300415,
|
588 |
+
"learning_rate": 3.6410407655000656e-05,
|
589 |
+
"loss": 1.7732,
|
590 |
+
"step": 4150
|
591 |
+
},
|
592 |
+
{
|
593 |
+
"epoch": 0.28,
|
594 |
+
"grad_norm": 0.33822837471961975,
|
595 |
+
"learning_rate": 3.6246559182068425e-05,
|
596 |
+
"loss": 1.8004,
|
597 |
+
"step": 4200
|
598 |
+
},
|
599 |
+
{
|
600 |
+
"epoch": 0.28,
|
601 |
+
"grad_norm": 0.3119085431098938,
|
602 |
+
"learning_rate": 3.6082710709136193e-05,
|
603 |
+
"loss": 1.7709,
|
604 |
+
"step": 4250
|
605 |
+
},
|
606 |
+
{
|
607 |
+
"epoch": 0.28,
|
608 |
+
"grad_norm": 0.3552871346473694,
|
609 |
+
"learning_rate": 3.591886223620396e-05,
|
610 |
+
"loss": 1.7865,
|
611 |
+
"step": 4300
|
612 |
+
},
|
613 |
+
{
|
614 |
+
"epoch": 0.29,
|
615 |
+
"grad_norm": 0.5379615426063538,
|
616 |
+
"learning_rate": 3.575501376327173e-05,
|
617 |
+
"loss": 1.8026,
|
618 |
+
"step": 4350
|
619 |
+
},
|
620 |
+
{
|
621 |
+
"epoch": 0.29,
|
622 |
+
"grad_norm": 0.3345562815666199,
|
623 |
+
"learning_rate": 3.559116529033949e-05,
|
624 |
+
"loss": 1.8146,
|
625 |
+
"step": 4400
|
626 |
+
},
|
627 |
+
{
|
628 |
+
"epoch": 0.29,
|
629 |
+
"grad_norm": 0.5010606646537781,
|
630 |
+
"learning_rate": 3.542731681740726e-05,
|
631 |
+
"loss": 1.8117,
|
632 |
+
"step": 4450
|
633 |
+
},
|
634 |
+
{
|
635 |
+
"epoch": 0.29,
|
636 |
+
"grad_norm": 0.46487560868263245,
|
637 |
+
"learning_rate": 3.526346834447503e-05,
|
638 |
+
"loss": 1.7583,
|
639 |
+
"step": 4500
|
640 |
+
},
|
641 |
+
{
|
642 |
+
"epoch": 0.3,
|
643 |
+
"grad_norm": 0.4831026792526245,
|
644 |
+
"learning_rate": 3.50996198715428e-05,
|
645 |
+
"loss": 1.768,
|
646 |
+
"step": 4550
|
647 |
+
},
|
648 |
+
{
|
649 |
+
"epoch": 0.3,
|
650 |
+
"grad_norm": 0.5314655303955078,
|
651 |
+
"learning_rate": 3.493577139861057e-05,
|
652 |
+
"loss": 1.8041,
|
653 |
+
"step": 4600
|
654 |
+
},
|
655 |
+
{
|
656 |
+
"epoch": 0.3,
|
657 |
+
"grad_norm": 0.4257725477218628,
|
658 |
+
"learning_rate": 3.4771922925678335e-05,
|
659 |
+
"loss": 1.7929,
|
660 |
+
"step": 4650
|
661 |
+
},
|
662 |
+
{
|
663 |
+
"epoch": 0.31,
|
664 |
+
"grad_norm": 0.4357529878616333,
|
665 |
+
"learning_rate": 3.4608074452746104e-05,
|
666 |
+
"loss": 1.7826,
|
667 |
+
"step": 4700
|
668 |
+
},
|
669 |
+
{
|
670 |
+
"epoch": 0.31,
|
671 |
+
"grad_norm": 0.4604736268520355,
|
672 |
+
"learning_rate": 3.444422597981387e-05,
|
673 |
+
"loss": 1.8099,
|
674 |
+
"step": 4750
|
675 |
+
},
|
676 |
+
{
|
677 |
+
"epoch": 0.31,
|
678 |
+
"grad_norm": 0.44079703092575073,
|
679 |
+
"learning_rate": 3.428037750688164e-05,
|
680 |
+
"loss": 1.7825,
|
681 |
+
"step": 4800
|
682 |
+
},
|
683 |
+
{
|
684 |
+
"epoch": 0.32,
|
685 |
+
"grad_norm": 0.4325021207332611,
|
686 |
+
"learning_rate": 3.411652903394941e-05,
|
687 |
+
"loss": 1.7546,
|
688 |
+
"step": 4850
|
689 |
+
},
|
690 |
+
{
|
691 |
+
"epoch": 0.32,
|
692 |
+
"grad_norm": 0.3814845681190491,
|
693 |
+
"learning_rate": 3.395268056101718e-05,
|
694 |
+
"loss": 1.8295,
|
695 |
+
"step": 4900
|
696 |
+
},
|
697 |
+
{
|
698 |
+
"epoch": 0.32,
|
699 |
+
"grad_norm": 0.3426695764064789,
|
700 |
+
"learning_rate": 3.378883208808494e-05,
|
701 |
+
"loss": 1.8149,
|
702 |
+
"step": 4950
|
703 |
+
},
|
704 |
+
{
|
705 |
+
"epoch": 0.33,
|
706 |
+
"grad_norm": 0.3510643541812897,
|
707 |
+
"learning_rate": 3.362498361515271e-05,
|
708 |
+
"loss": 1.8042,
|
709 |
+
"step": 5000
|
710 |
+
},
|
711 |
+
{
|
712 |
+
"epoch": 0.33,
|
713 |
+
"grad_norm": 0.4605468213558197,
|
714 |
+
"learning_rate": 3.346113514222048e-05,
|
715 |
+
"loss": 1.7828,
|
716 |
+
"step": 5050
|
717 |
+
},
|
718 |
+
{
|
719 |
+
"epoch": 0.33,
|
720 |
+
"grad_norm": 0.3923262059688568,
|
721 |
+
"learning_rate": 3.329728666928824e-05,
|
722 |
+
"loss": 1.8252,
|
723 |
+
"step": 5100
|
724 |
+
},
|
725 |
+
{
|
726 |
+
"epoch": 0.34,
|
727 |
+
"grad_norm": 0.35685479640960693,
|
728 |
+
"learning_rate": 3.313343819635601e-05,
|
729 |
+
"loss": 1.8354,
|
730 |
+
"step": 5150
|
731 |
+
},
|
732 |
+
{
|
733 |
+
"epoch": 0.34,
|
734 |
+
"grad_norm": 0.6825860738754272,
|
735 |
+
"learning_rate": 3.2969589723423776e-05,
|
736 |
+
"loss": 1.7901,
|
737 |
+
"step": 5200
|
738 |
+
},
|
739 |
+
{
|
740 |
+
"epoch": 0.34,
|
741 |
+
"grad_norm": 0.6853482723236084,
|
742 |
+
"learning_rate": 3.2805741250491545e-05,
|
743 |
+
"loss": 1.8072,
|
744 |
+
"step": 5250
|
745 |
+
},
|
746 |
+
{
|
747 |
+
"epoch": 0.35,
|
748 |
+
"grad_norm": 0.5828983783721924,
|
749 |
+
"learning_rate": 3.264189277755931e-05,
|
750 |
+
"loss": 1.7666,
|
751 |
+
"step": 5300
|
752 |
+
},
|
753 |
+
{
|
754 |
+
"epoch": 0.35,
|
755 |
+
"grad_norm": 0.4155603051185608,
|
756 |
+
"learning_rate": 3.247804430462708e-05,
|
757 |
+
"loss": 1.8165,
|
758 |
+
"step": 5350
|
759 |
+
},
|
760 |
+
{
|
761 |
+
"epoch": 0.35,
|
762 |
+
"grad_norm": 0.3048844635486603,
|
763 |
+
"learning_rate": 3.231419583169485e-05,
|
764 |
+
"loss": 1.7664,
|
765 |
+
"step": 5400
|
766 |
+
},
|
767 |
+
{
|
768 |
+
"epoch": 0.36,
|
769 |
+
"grad_norm": 0.786605715751648,
|
770 |
+
"learning_rate": 3.215034735876262e-05,
|
771 |
+
"loss": 1.8138,
|
772 |
+
"step": 5450
|
773 |
+
},
|
774 |
+
{
|
775 |
+
"epoch": 0.36,
|
776 |
+
"grad_norm": 0.9150344133377075,
|
777 |
+
"learning_rate": 3.198649888583039e-05,
|
778 |
+
"loss": 1.8106,
|
779 |
+
"step": 5500
|
780 |
+
},
|
781 |
+
{
|
782 |
+
"epoch": 0.36,
|
783 |
+
"grad_norm": 0.43113359808921814,
|
784 |
+
"learning_rate": 3.1822650412898156e-05,
|
785 |
+
"loss": 1.7895,
|
786 |
+
"step": 5550
|
787 |
+
},
|
788 |
+
{
|
789 |
+
"epoch": 0.37,
|
790 |
+
"grad_norm": 0.4392976760864258,
|
791 |
+
"learning_rate": 3.165880193996592e-05,
|
792 |
+
"loss": 1.7897,
|
793 |
+
"step": 5600
|
794 |
+
},
|
795 |
+
{
|
796 |
+
"epoch": 0.37,
|
797 |
+
"grad_norm": 0.5544856786727905,
|
798 |
+
"learning_rate": 3.1494953467033686e-05,
|
799 |
+
"loss": 1.783,
|
800 |
+
"step": 5650
|
801 |
+
},
|
802 |
+
{
|
803 |
+
"epoch": 0.37,
|
804 |
+
"grad_norm": 0.30507203936576843,
|
805 |
+
"learning_rate": 3.1331104994101455e-05,
|
806 |
+
"loss": 1.819,
|
807 |
+
"step": 5700
|
808 |
+
},
|
809 |
+
{
|
810 |
+
"epoch": 0.38,
|
811 |
+
"grad_norm": 0.39048048853874207,
|
812 |
+
"learning_rate": 3.1167256521169224e-05,
|
813 |
+
"loss": 1.8011,
|
814 |
+
"step": 5750
|
815 |
+
},
|
816 |
+
{
|
817 |
+
"epoch": 0.38,
|
818 |
+
"grad_norm": 0.3265933096408844,
|
819 |
+
"learning_rate": 3.100340804823699e-05,
|
820 |
+
"loss": 1.7867,
|
821 |
+
"step": 5800
|
822 |
+
},
|
823 |
+
{
|
824 |
+
"epoch": 0.38,
|
825 |
+
"grad_norm": 0.8230869174003601,
|
826 |
+
"learning_rate": 3.083955957530476e-05,
|
827 |
+
"loss": 1.8035,
|
828 |
+
"step": 5850
|
829 |
+
},
|
830 |
+
{
|
831 |
+
"epoch": 0.39,
|
832 |
+
"grad_norm": 0.5455942153930664,
|
833 |
+
"learning_rate": 3.067571110237253e-05,
|
834 |
+
"loss": 1.7662,
|
835 |
+
"step": 5900
|
836 |
+
},
|
837 |
+
{
|
838 |
+
"epoch": 0.39,
|
839 |
+
"grad_norm": 0.4801247715950012,
|
840 |
+
"learning_rate": 3.0511862629440298e-05,
|
841 |
+
"loss": 1.7932,
|
842 |
+
"step": 5950
|
843 |
+
},
|
844 |
+
{
|
845 |
+
"epoch": 0.39,
|
846 |
+
"grad_norm": 0.3930888772010803,
|
847 |
+
"learning_rate": 3.0348014156508063e-05,
|
848 |
+
"loss": 1.7954,
|
849 |
+
"step": 6000
|
850 |
+
},
|
851 |
+
{
|
852 |
+
"epoch": 0.4,
|
853 |
+
"grad_norm": 0.3690837323665619,
|
854 |
+
"learning_rate": 3.018416568357583e-05,
|
855 |
+
"loss": 1.8081,
|
856 |
+
"step": 6050
|
857 |
+
},
|
858 |
+
{
|
859 |
+
"epoch": 0.4,
|
860 |
+
"grad_norm": 0.45955517888069153,
|
861 |
+
"learning_rate": 3.00203172106436e-05,
|
862 |
+
"loss": 1.7859,
|
863 |
+
"step": 6100
|
864 |
+
},
|
865 |
+
{
|
866 |
+
"epoch": 0.4,
|
867 |
+
"grad_norm": 0.3670261800289154,
|
868 |
+
"learning_rate": 2.985646873771137e-05,
|
869 |
+
"loss": 1.7891,
|
870 |
+
"step": 6150
|
871 |
+
},
|
872 |
+
{
|
873 |
+
"epoch": 0.41,
|
874 |
+
"grad_norm": 0.5386211276054382,
|
875 |
+
"learning_rate": 2.9692620264779137e-05,
|
876 |
+
"loss": 1.8026,
|
877 |
+
"step": 6200
|
878 |
+
},
|
879 |
+
{
|
880 |
+
"epoch": 0.41,
|
881 |
+
"grad_norm": 0.5107685327529907,
|
882 |
+
"learning_rate": 2.95287717918469e-05,
|
883 |
+
"loss": 1.8281,
|
884 |
+
"step": 6250
|
885 |
+
},
|
886 |
+
{
|
887 |
+
"epoch": 0.41,
|
888 |
+
"grad_norm": 0.3285304009914398,
|
889 |
+
"learning_rate": 2.9364923318914668e-05,
|
890 |
+
"loss": 1.788,
|
891 |
+
"step": 6300
|
892 |
+
},
|
893 |
+
{
|
894 |
+
"epoch": 0.42,
|
895 |
+
"grad_norm": 0.699974775314331,
|
896 |
+
"learning_rate": 2.9201074845982436e-05,
|
897 |
+
"loss": 1.8138,
|
898 |
+
"step": 6350
|
899 |
+
},
|
900 |
+
{
|
901 |
+
"epoch": 0.42,
|
902 |
+
"grad_norm": 0.3917068839073181,
|
903 |
+
"learning_rate": 2.90372263730502e-05,
|
904 |
+
"loss": 1.7874,
|
905 |
+
"step": 6400
|
906 |
+
},
|
907 |
+
{
|
908 |
+
"epoch": 0.42,
|
909 |
+
"grad_norm": 0.4506165087223053,
|
910 |
+
"learning_rate": 2.887337790011797e-05,
|
911 |
+
"loss": 1.8026,
|
912 |
+
"step": 6450
|
913 |
+
},
|
914 |
+
{
|
915 |
+
"epoch": 0.43,
|
916 |
+
"grad_norm": 0.5004333257675171,
|
917 |
+
"learning_rate": 2.870952942718574e-05,
|
918 |
+
"loss": 1.7651,
|
919 |
+
"step": 6500
|
920 |
+
},
|
921 |
+
{
|
922 |
+
"epoch": 0.43,
|
923 |
+
"grad_norm": 0.4514022171497345,
|
924 |
+
"learning_rate": 2.8545680954253507e-05,
|
925 |
+
"loss": 1.7393,
|
926 |
+
"step": 6550
|
927 |
+
},
|
928 |
+
{
|
929 |
+
"epoch": 0.43,
|
930 |
+
"grad_norm": 0.4520861804485321,
|
931 |
+
"learning_rate": 2.8381832481321276e-05,
|
932 |
+
"loss": 1.7651,
|
933 |
+
"step": 6600
|
934 |
+
},
|
935 |
+
{
|
936 |
+
"epoch": 0.44,
|
937 |
+
"grad_norm": 0.5931407809257507,
|
938 |
+
"learning_rate": 2.821798400838904e-05,
|
939 |
+
"loss": 1.7623,
|
940 |
+
"step": 6650
|
941 |
+
},
|
942 |
+
{
|
943 |
+
"epoch": 0.44,
|
944 |
+
"grad_norm": 0.518058180809021,
|
945 |
+
"learning_rate": 2.805413553545681e-05,
|
946 |
+
"loss": 1.7582,
|
947 |
+
"step": 6700
|
948 |
+
},
|
949 |
+
{
|
950 |
+
"epoch": 0.44,
|
951 |
+
"grad_norm": 0.34412890672683716,
|
952 |
+
"learning_rate": 2.7890287062524578e-05,
|
953 |
+
"loss": 1.8062,
|
954 |
+
"step": 6750
|
955 |
+
},
|
956 |
+
{
|
957 |
+
"epoch": 0.45,
|
958 |
+
"grad_norm": 0.4060100018978119,
|
959 |
+
"learning_rate": 2.7726438589592347e-05,
|
960 |
+
"loss": 1.8026,
|
961 |
+
"step": 6800
|
962 |
+
},
|
963 |
+
{
|
964 |
+
"epoch": 0.45,
|
965 |
+
"grad_norm": 0.5105322003364563,
|
966 |
+
"learning_rate": 2.7562590116660115e-05,
|
967 |
+
"loss": 1.7946,
|
968 |
+
"step": 6850
|
969 |
+
},
|
970 |
+
{
|
971 |
+
"epoch": 0.45,
|
972 |
+
"grad_norm": 0.4951707422733307,
|
973 |
+
"learning_rate": 2.7398741643727884e-05,
|
974 |
+
"loss": 1.7421,
|
975 |
+
"step": 6900
|
976 |
+
},
|
977 |
+
{
|
978 |
+
"epoch": 0.46,
|
979 |
+
"grad_norm": 0.5833694338798523,
|
980 |
+
"learning_rate": 2.723489317079565e-05,
|
981 |
+
"loss": 1.774,
|
982 |
+
"step": 6950
|
983 |
+
},
|
984 |
+
{
|
985 |
+
"epoch": 0.46,
|
986 |
+
"grad_norm": 0.3745187520980835,
|
987 |
+
"learning_rate": 2.7071044697863417e-05,
|
988 |
+
"loss": 1.7682,
|
989 |
+
"step": 7000
|
990 |
+
},
|
991 |
+
{
|
992 |
+
"epoch": 0.46,
|
993 |
+
"grad_norm": 0.4256528615951538,
|
994 |
+
"learning_rate": 2.6907196224931186e-05,
|
995 |
+
"loss": 1.7371,
|
996 |
+
"step": 7050
|
997 |
+
},
|
998 |
+
{
|
999 |
+
"epoch": 0.47,
|
1000 |
+
"grad_norm": 0.3425038754940033,
|
1001 |
+
"learning_rate": 2.6743347751998955e-05,
|
1002 |
+
"loss": 1.7922,
|
1003 |
+
"step": 7100
|
1004 |
+
},
|
1005 |
+
{
|
1006 |
+
"epoch": 0.47,
|
1007 |
+
"grad_norm": 0.5452577471733093,
|
1008 |
+
"learning_rate": 2.6579499279066723e-05,
|
1009 |
+
"loss": 1.8093,
|
1010 |
+
"step": 7150
|
1011 |
+
},
|
1012 |
+
{
|
1013 |
+
"epoch": 0.47,
|
1014 |
+
"grad_norm": 0.4865332245826721,
|
1015 |
+
"learning_rate": 2.641565080613449e-05,
|
1016 |
+
"loss": 1.7855,
|
1017 |
+
"step": 7200
|
1018 |
+
},
|
1019 |
+
{
|
1020 |
+
"epoch": 0.48,
|
1021 |
+
"grad_norm": 0.513595461845398,
|
1022 |
+
"learning_rate": 2.6251802333202257e-05,
|
1023 |
+
"loss": 1.7647,
|
1024 |
+
"step": 7250
|
1025 |
+
},
|
1026 |
+
{
|
1027 |
+
"epoch": 0.48,
|
1028 |
+
"grad_norm": 0.508758544921875,
|
1029 |
+
"learning_rate": 2.6087953860270025e-05,
|
1030 |
+
"loss": 1.8106,
|
1031 |
+
"step": 7300
|
1032 |
+
},
|
1033 |
+
{
|
1034 |
+
"epoch": 0.48,
|
1035 |
+
"grad_norm": 0.8143779635429382,
|
1036 |
+
"learning_rate": 2.5924105387337794e-05,
|
1037 |
+
"loss": 1.7777,
|
1038 |
+
"step": 7350
|
1039 |
+
},
|
1040 |
+
{
|
1041 |
+
"epoch": 0.48,
|
1042 |
+
"grad_norm": 0.44763991236686707,
|
1043 |
+
"learning_rate": 2.5760256914405563e-05,
|
1044 |
+
"loss": 1.7972,
|
1045 |
+
"step": 7400
|
1046 |
+
},
|
1047 |
+
{
|
1048 |
+
"epoch": 0.49,
|
1049 |
+
"grad_norm": 0.6493588089942932,
|
1050 |
+
"learning_rate": 2.5596408441473324e-05,
|
1051 |
+
"loss": 1.8002,
|
1052 |
+
"step": 7450
|
1053 |
+
},
|
1054 |
+
{
|
1055 |
+
"epoch": 0.49,
|
1056 |
+
"grad_norm": 0.4406678378582001,
|
1057 |
+
"learning_rate": 2.5432559968541093e-05,
|
1058 |
+
"loss": 1.7884,
|
1059 |
+
"step": 7500
|
1060 |
+
},
|
1061 |
+
{
|
1062 |
+
"epoch": 0.49,
|
1063 |
+
"grad_norm": 0.500289797782898,
|
1064 |
+
"learning_rate": 2.526871149560886e-05,
|
1065 |
+
"loss": 1.7323,
|
1066 |
+
"step": 7550
|
1067 |
+
},
|
1068 |
+
{
|
1069 |
+
"epoch": 0.5,
|
1070 |
+
"grad_norm": 0.4473750591278076,
|
1071 |
+
"learning_rate": 2.5104863022676627e-05,
|
1072 |
+
"loss": 1.7923,
|
1073 |
+
"step": 7600
|
1074 |
+
},
|
1075 |
+
{
|
1076 |
+
"epoch": 0.5,
|
1077 |
+
"grad_norm": 0.3302167057991028,
|
1078 |
+
"learning_rate": 2.49410145497444e-05,
|
1079 |
+
"loss": 1.7537,
|
1080 |
+
"step": 7650
|
1081 |
+
},
|
1082 |
+
{
|
1083 |
+
"epoch": 0.5,
|
1084 |
+
"grad_norm": 0.5885249376296997,
|
1085 |
+
"learning_rate": 2.4777166076812167e-05,
|
1086 |
+
"loss": 1.769,
|
1087 |
+
"step": 7700
|
1088 |
+
},
|
1089 |
+
{
|
1090 |
+
"epoch": 0.51,
|
1091 |
+
"grad_norm": 0.3272787034511566,
|
1092 |
+
"learning_rate": 2.4613317603879932e-05,
|
1093 |
+
"loss": 1.7479,
|
1094 |
+
"step": 7750
|
1095 |
+
},
|
1096 |
+
{
|
1097 |
+
"epoch": 0.51,
|
1098 |
+
"grad_norm": 0.38857901096343994,
|
1099 |
+
"learning_rate": 2.44494691309477e-05,
|
1100 |
+
"loss": 1.7615,
|
1101 |
+
"step": 7800
|
1102 |
+
},
|
1103 |
+
{
|
1104 |
+
"epoch": 0.51,
|
1105 |
+
"grad_norm": 0.7423263192176819,
|
1106 |
+
"learning_rate": 2.4285620658015466e-05,
|
1107 |
+
"loss": 1.7882,
|
1108 |
+
"step": 7850
|
1109 |
+
},
|
1110 |
+
{
|
1111 |
+
"epoch": 0.52,
|
1112 |
+
"grad_norm": 0.3933955729007721,
|
1113 |
+
"learning_rate": 2.4121772185083235e-05,
|
1114 |
+
"loss": 1.804,
|
1115 |
+
"step": 7900
|
1116 |
+
},
|
1117 |
+
{
|
1118 |
+
"epoch": 0.52,
|
1119 |
+
"grad_norm": 0.3640703856945038,
|
1120 |
+
"learning_rate": 2.3957923712151003e-05,
|
1121 |
+
"loss": 1.7408,
|
1122 |
+
"step": 7950
|
1123 |
+
},
|
1124 |
+
{
|
1125 |
+
"epoch": 0.52,
|
1126 |
+
"grad_norm": 0.7845476865768433,
|
1127 |
+
"learning_rate": 2.3794075239218772e-05,
|
1128 |
+
"loss": 1.8048,
|
1129 |
+
"step": 8000
|
1130 |
+
},
|
1131 |
+
{
|
1132 |
+
"epoch": 0.53,
|
1133 |
+
"grad_norm": 0.46670156717300415,
|
1134 |
+
"learning_rate": 2.363022676628654e-05,
|
1135 |
+
"loss": 1.7889,
|
1136 |
+
"step": 8050
|
1137 |
+
},
|
1138 |
+
{
|
1139 |
+
"epoch": 0.53,
|
1140 |
+
"grad_norm": 0.5479481220245361,
|
1141 |
+
"learning_rate": 2.346637829335431e-05,
|
1142 |
+
"loss": 1.7725,
|
1143 |
+
"step": 8100
|
1144 |
+
},
|
1145 |
+
{
|
1146 |
+
"epoch": 0.53,
|
1147 |
+
"grad_norm": 0.4924238324165344,
|
1148 |
+
"learning_rate": 2.3302529820422074e-05,
|
1149 |
+
"loss": 1.7956,
|
1150 |
+
"step": 8150
|
1151 |
+
},
|
1152 |
+
{
|
1153 |
+
"epoch": 0.54,
|
1154 |
+
"grad_norm": 0.5267847776412964,
|
1155 |
+
"learning_rate": 2.3138681347489843e-05,
|
1156 |
+
"loss": 1.7683,
|
1157 |
+
"step": 8200
|
1158 |
+
},
|
1159 |
+
{
|
1160 |
+
"epoch": 0.54,
|
1161 |
+
"grad_norm": 0.42921149730682373,
|
1162 |
+
"learning_rate": 2.297483287455761e-05,
|
1163 |
+
"loss": 1.7662,
|
1164 |
+
"step": 8250
|
1165 |
+
},
|
1166 |
+
{
|
1167 |
+
"epoch": 0.54,
|
1168 |
+
"grad_norm": 0.4606122374534607,
|
1169 |
+
"learning_rate": 2.281098440162538e-05,
|
1170 |
+
"loss": 1.7773,
|
1171 |
+
"step": 8300
|
1172 |
+
},
|
1173 |
+
{
|
1174 |
+
"epoch": 0.55,
|
1175 |
+
"grad_norm": 0.4239887595176697,
|
1176 |
+
"learning_rate": 2.2647135928693145e-05,
|
1177 |
+
"loss": 1.7753,
|
1178 |
+
"step": 8350
|
1179 |
+
},
|
1180 |
+
{
|
1181 |
+
"epoch": 0.55,
|
1182 |
+
"grad_norm": 0.46374326944351196,
|
1183 |
+
"learning_rate": 2.2483287455760914e-05,
|
1184 |
+
"loss": 1.814,
|
1185 |
+
"step": 8400
|
1186 |
+
},
|
1187 |
+
{
|
1188 |
+
"epoch": 0.55,
|
1189 |
+
"grad_norm": 0.3622525632381439,
|
1190 |
+
"learning_rate": 2.231943898282868e-05,
|
1191 |
+
"loss": 1.7955,
|
1192 |
+
"step": 8450
|
1193 |
+
},
|
1194 |
+
{
|
1195 |
+
"epoch": 0.56,
|
1196 |
+
"grad_norm": 0.7099259495735168,
|
1197 |
+
"learning_rate": 2.2155590509896447e-05,
|
1198 |
+
"loss": 1.8063,
|
1199 |
+
"step": 8500
|
1200 |
+
},
|
1201 |
+
{
|
1202 |
+
"epoch": 0.56,
|
1203 |
+
"grad_norm": 0.4248027801513672,
|
1204 |
+
"learning_rate": 2.1991742036964216e-05,
|
1205 |
+
"loss": 1.7714,
|
1206 |
+
"step": 8550
|
1207 |
+
},
|
1208 |
+
{
|
1209 |
+
"epoch": 0.56,
|
1210 |
+
"grad_norm": 0.3817599415779114,
|
1211 |
+
"learning_rate": 2.1827893564031985e-05,
|
1212 |
+
"loss": 1.8087,
|
1213 |
+
"step": 8600
|
1214 |
+
},
|
1215 |
+
{
|
1216 |
+
"epoch": 0.57,
|
1217 |
+
"grad_norm": 0.4455879032611847,
|
1218 |
+
"learning_rate": 2.1664045091099753e-05,
|
1219 |
+
"loss": 1.7811,
|
1220 |
+
"step": 8650
|
1221 |
+
},
|
1222 |
+
{
|
1223 |
+
"epoch": 0.57,
|
1224 |
+
"grad_norm": 0.4604770243167877,
|
1225 |
+
"learning_rate": 2.1500196618167522e-05,
|
1226 |
+
"loss": 1.7511,
|
1227 |
+
"step": 8700
|
1228 |
+
},
|
1229 |
+
{
|
1230 |
+
"epoch": 0.57,
|
1231 |
+
"grad_norm": 0.43301329016685486,
|
1232 |
+
"learning_rate": 2.1336348145235287e-05,
|
1233 |
+
"loss": 1.762,
|
1234 |
+
"step": 8750
|
1235 |
+
},
|
1236 |
+
{
|
1237 |
+
"epoch": 0.58,
|
1238 |
+
"grad_norm": 0.4077916741371155,
|
1239 |
+
"learning_rate": 2.1172499672303055e-05,
|
1240 |
+
"loss": 1.7512,
|
1241 |
+
"step": 8800
|
1242 |
+
},
|
1243 |
+
{
|
1244 |
+
"epoch": 0.58,
|
1245 |
+
"grad_norm": 0.3406469225883484,
|
1246 |
+
"learning_rate": 2.1008651199370824e-05,
|
1247 |
+
"loss": 1.8008,
|
1248 |
+
"step": 8850
|
1249 |
+
},
|
1250 |
+
{
|
1251 |
+
"epoch": 0.58,
|
1252 |
+
"grad_norm": 1.0516856908798218,
|
1253 |
+
"learning_rate": 2.084480272643859e-05,
|
1254 |
+
"loss": 1.7822,
|
1255 |
+
"step": 8900
|
1256 |
+
},
|
1257 |
+
{
|
1258 |
+
"epoch": 0.59,
|
1259 |
+
"grad_norm": 0.4626096189022064,
|
1260 |
+
"learning_rate": 2.0680954253506358e-05,
|
1261 |
+
"loss": 1.7883,
|
1262 |
+
"step": 8950
|
1263 |
+
},
|
1264 |
+
{
|
1265 |
+
"epoch": 0.59,
|
1266 |
+
"grad_norm": 0.9625229239463806,
|
1267 |
+
"learning_rate": 2.0517105780574126e-05,
|
1268 |
+
"loss": 1.7423,
|
1269 |
+
"step": 9000
|
1270 |
+
},
|
1271 |
+
{
|
1272 |
+
"epoch": 0.59,
|
1273 |
+
"grad_norm": 0.5017744302749634,
|
1274 |
+
"learning_rate": 2.035325730764189e-05,
|
1275 |
+
"loss": 1.7559,
|
1276 |
+
"step": 9050
|
1277 |
+
},
|
1278 |
+
{
|
1279 |
+
"epoch": 0.6,
|
1280 |
+
"grad_norm": 0.41525375843048096,
|
1281 |
+
"learning_rate": 2.018940883470966e-05,
|
1282 |
+
"loss": 1.7961,
|
1283 |
+
"step": 9100
|
1284 |
+
},
|
1285 |
+
{
|
1286 |
+
"epoch": 0.6,
|
1287 |
+
"grad_norm": 0.48959624767303467,
|
1288 |
+
"learning_rate": 2.002556036177743e-05,
|
1289 |
+
"loss": 1.797,
|
1290 |
+
"step": 9150
|
1291 |
+
},
|
1292 |
+
{
|
1293 |
+
"epoch": 0.6,
|
1294 |
+
"grad_norm": 0.5421375036239624,
|
1295 |
+
"learning_rate": 1.9861711888845197e-05,
|
1296 |
+
"loss": 1.7637,
|
1297 |
+
"step": 9200
|
1298 |
+
},
|
1299 |
+
{
|
1300 |
+
"epoch": 0.61,
|
1301 |
+
"grad_norm": 0.47492170333862305,
|
1302 |
+
"learning_rate": 1.9697863415912966e-05,
|
1303 |
+
"loss": 1.7559,
|
1304 |
+
"step": 9250
|
1305 |
+
},
|
1306 |
+
{
|
1307 |
+
"epoch": 0.61,
|
1308 |
+
"grad_norm": 0.8118923902511597,
|
1309 |
+
"learning_rate": 1.9534014942980734e-05,
|
1310 |
+
"loss": 1.8089,
|
1311 |
+
"step": 9300
|
1312 |
+
},
|
1313 |
+
{
|
1314 |
+
"epoch": 0.61,
|
1315 |
+
"grad_norm": 0.6577257513999939,
|
1316 |
+
"learning_rate": 1.93701664700485e-05,
|
1317 |
+
"loss": 1.7974,
|
1318 |
+
"step": 9350
|
1319 |
+
},
|
1320 |
+
{
|
1321 |
+
"epoch": 0.62,
|
1322 |
+
"grad_norm": 0.3861309587955475,
|
1323 |
+
"learning_rate": 1.9206317997116268e-05,
|
1324 |
+
"loss": 1.7601,
|
1325 |
+
"step": 9400
|
1326 |
+
},
|
1327 |
+
{
|
1328 |
+
"epoch": 0.62,
|
1329 |
+
"grad_norm": 0.4553438723087311,
|
1330 |
+
"learning_rate": 1.9042469524184037e-05,
|
1331 |
+
"loss": 1.8411,
|
1332 |
+
"step": 9450
|
1333 |
+
},
|
1334 |
+
{
|
1335 |
+
"epoch": 0.62,
|
1336 |
+
"grad_norm": 0.5294969081878662,
|
1337 |
+
"learning_rate": 1.8878621051251802e-05,
|
1338 |
+
"loss": 1.8056,
|
1339 |
+
"step": 9500
|
1340 |
+
},
|
1341 |
+
{
|
1342 |
+
"epoch": 0.63,
|
1343 |
+
"grad_norm": 0.4538947641849518,
|
1344 |
+
"learning_rate": 1.871477257831957e-05,
|
1345 |
+
"loss": 1.7922,
|
1346 |
+
"step": 9550
|
1347 |
+
},
|
1348 |
+
{
|
1349 |
+
"epoch": 0.63,
|
1350 |
+
"grad_norm": 0.40422508120536804,
|
1351 |
+
"learning_rate": 1.855092410538734e-05,
|
1352 |
+
"loss": 1.7954,
|
1353 |
+
"step": 9600
|
1354 |
+
},
|
1355 |
+
{
|
1356 |
+
"epoch": 0.63,
|
1357 |
+
"grad_norm": 0.9616673588752747,
|
1358 |
+
"learning_rate": 1.8387075632455104e-05,
|
1359 |
+
"loss": 1.7896,
|
1360 |
+
"step": 9650
|
1361 |
+
},
|
1362 |
+
{
|
1363 |
+
"epoch": 0.64,
|
1364 |
+
"grad_norm": 0.3476395606994629,
|
1365 |
+
"learning_rate": 1.8223227159522873e-05,
|
1366 |
+
"loss": 1.8015,
|
1367 |
+
"step": 9700
|
1368 |
+
},
|
1369 |
+
{
|
1370 |
+
"epoch": 0.64,
|
1371 |
+
"grad_norm": 0.388485312461853,
|
1372 |
+
"learning_rate": 1.805937868659064e-05,
|
1373 |
+
"loss": 1.7918,
|
1374 |
+
"step": 9750
|
1375 |
+
},
|
1376 |
+
{
|
1377 |
+
"epoch": 0.64,
|
1378 |
+
"grad_norm": 0.5417673587799072,
|
1379 |
+
"learning_rate": 1.789553021365841e-05,
|
1380 |
+
"loss": 1.7444,
|
1381 |
+
"step": 9800
|
1382 |
+
},
|
1383 |
+
{
|
1384 |
+
"epoch": 0.65,
|
1385 |
+
"grad_norm": 0.3682622015476227,
|
1386 |
+
"learning_rate": 1.773168174072618e-05,
|
1387 |
+
"loss": 1.7803,
|
1388 |
+
"step": 9850
|
1389 |
+
},
|
1390 |
+
{
|
1391 |
+
"epoch": 0.65,
|
1392 |
+
"grad_norm": 0.6654282212257385,
|
1393 |
+
"learning_rate": 1.7567833267793947e-05,
|
1394 |
+
"loss": 1.7559,
|
1395 |
+
"step": 9900
|
1396 |
+
},
|
1397 |
+
{
|
1398 |
+
"epoch": 0.65,
|
1399 |
+
"grad_norm": 0.5030877590179443,
|
1400 |
+
"learning_rate": 1.7403984794861712e-05,
|
1401 |
+
"loss": 1.7657,
|
1402 |
+
"step": 9950
|
1403 |
+
},
|
1404 |
+
{
|
1405 |
+
"epoch": 0.66,
|
1406 |
+
"grad_norm": 0.627768874168396,
|
1407 |
+
"learning_rate": 1.724013632192948e-05,
|
1408 |
+
"loss": 1.7261,
|
1409 |
+
"step": 10000
|
1410 |
+
},
|
1411 |
+
{
|
1412 |
+
"epoch": 0.66,
|
1413 |
+
"grad_norm": 0.4117398262023926,
|
1414 |
+
"learning_rate": 1.707628784899725e-05,
|
1415 |
+
"loss": 1.7837,
|
1416 |
+
"step": 10050
|
1417 |
+
},
|
1418 |
+
{
|
1419 |
+
"epoch": 0.66,
|
1420 |
+
"grad_norm": 0.40106311440467834,
|
1421 |
+
"learning_rate": 1.6912439376065015e-05,
|
1422 |
+
"loss": 1.7961,
|
1423 |
+
"step": 10100
|
1424 |
+
},
|
1425 |
+
{
|
1426 |
+
"epoch": 0.67,
|
1427 |
+
"grad_norm": 0.32165274024009705,
|
1428 |
+
"learning_rate": 1.6748590903132783e-05,
|
1429 |
+
"loss": 1.7629,
|
1430 |
+
"step": 10150
|
1431 |
+
},
|
1432 |
+
{
|
1433 |
+
"epoch": 0.67,
|
1434 |
+
"grad_norm": 0.47640106081962585,
|
1435 |
+
"learning_rate": 1.6584742430200552e-05,
|
1436 |
+
"loss": 1.777,
|
1437 |
+
"step": 10200
|
1438 |
+
},
|
1439 |
+
{
|
1440 |
+
"epoch": 0.67,
|
1441 |
+
"grad_norm": 0.45250073075294495,
|
1442 |
+
"learning_rate": 1.6420893957268317e-05,
|
1443 |
+
"loss": 1.771,
|
1444 |
+
"step": 10250
|
1445 |
+
},
|
1446 |
+
{
|
1447 |
+
"epoch": 0.67,
|
1448 |
+
"grad_norm": 0.45913493633270264,
|
1449 |
+
"learning_rate": 1.6257045484336086e-05,
|
1450 |
+
"loss": 1.7971,
|
1451 |
+
"step": 10300
|
1452 |
+
},
|
1453 |
+
{
|
1454 |
+
"epoch": 0.68,
|
1455 |
+
"grad_norm": 0.5237872004508972,
|
1456 |
+
"learning_rate": 1.6093197011403854e-05,
|
1457 |
+
"loss": 1.7989,
|
1458 |
+
"step": 10350
|
1459 |
+
},
|
1460 |
+
{
|
1461 |
+
"epoch": 0.68,
|
1462 |
+
"grad_norm": 0.47246378660202026,
|
1463 |
+
"learning_rate": 1.5929348538471623e-05,
|
1464 |
+
"loss": 1.7867,
|
1465 |
+
"step": 10400
|
1466 |
+
},
|
1467 |
+
{
|
1468 |
+
"epoch": 0.68,
|
1469 |
+
"grad_norm": 0.3215338885784149,
|
1470 |
+
"learning_rate": 1.576550006553939e-05,
|
1471 |
+
"loss": 1.7864,
|
1472 |
+
"step": 10450
|
1473 |
+
},
|
1474 |
+
{
|
1475 |
+
"epoch": 0.69,
|
1476 |
+
"grad_norm": 1.0621765851974487,
|
1477 |
+
"learning_rate": 1.560165159260716e-05,
|
1478 |
+
"loss": 1.7482,
|
1479 |
+
"step": 10500
|
1480 |
+
},
|
1481 |
+
{
|
1482 |
+
"epoch": 0.69,
|
1483 |
+
"grad_norm": 0.5376123785972595,
|
1484 |
+
"learning_rate": 1.5437803119674925e-05,
|
1485 |
+
"loss": 1.7635,
|
1486 |
+
"step": 10550
|
1487 |
+
},
|
1488 |
+
{
|
1489 |
+
"epoch": 0.69,
|
1490 |
+
"grad_norm": 0.8421134352684021,
|
1491 |
+
"learning_rate": 1.5273954646742694e-05,
|
1492 |
+
"loss": 1.7854,
|
1493 |
+
"step": 10600
|
1494 |
+
},
|
1495 |
+
{
|
1496 |
+
"epoch": 0.7,
|
1497 |
+
"grad_norm": 0.4911418855190277,
|
1498 |
+
"learning_rate": 1.5110106173810462e-05,
|
1499 |
+
"loss": 1.7514,
|
1500 |
+
"step": 10650
|
1501 |
+
},
|
1502 |
+
{
|
1503 |
+
"epoch": 0.7,
|
1504 |
+
"grad_norm": 0.32285892963409424,
|
1505 |
+
"learning_rate": 1.4946257700878227e-05,
|
1506 |
+
"loss": 1.7701,
|
1507 |
+
"step": 10700
|
1508 |
+
},
|
1509 |
+
{
|
1510 |
+
"epoch": 0.7,
|
1511 |
+
"grad_norm": 0.6105034947395325,
|
1512 |
+
"learning_rate": 1.4782409227945996e-05,
|
1513 |
+
"loss": 1.7726,
|
1514 |
+
"step": 10750
|
1515 |
+
},
|
1516 |
+
{
|
1517 |
+
"epoch": 0.71,
|
1518 |
+
"grad_norm": 0.36749064922332764,
|
1519 |
+
"learning_rate": 1.4618560755013763e-05,
|
1520 |
+
"loss": 1.8059,
|
1521 |
+
"step": 10800
|
1522 |
+
},
|
1523 |
+
{
|
1524 |
+
"epoch": 0.71,
|
1525 |
+
"grad_norm": 0.46773606538772583,
|
1526 |
+
"learning_rate": 1.4454712282081531e-05,
|
1527 |
+
"loss": 1.8167,
|
1528 |
+
"step": 10850
|
1529 |
+
},
|
1530 |
+
{
|
1531 |
+
"epoch": 0.71,
|
1532 |
+
"grad_norm": 0.5864791870117188,
|
1533 |
+
"learning_rate": 1.42908638091493e-05,
|
1534 |
+
"loss": 1.7503,
|
1535 |
+
"step": 10900
|
1536 |
+
},
|
1537 |
+
{
|
1538 |
+
"epoch": 0.72,
|
1539 |
+
"grad_norm": 0.5605257153511047,
|
1540 |
+
"learning_rate": 1.4127015336217067e-05,
|
1541 |
+
"loss": 1.8021,
|
1542 |
+
"step": 10950
|
1543 |
+
},
|
1544 |
+
{
|
1545 |
+
"epoch": 0.72,
|
1546 |
+
"grad_norm": 0.6443638205528259,
|
1547 |
+
"learning_rate": 1.3963166863284835e-05,
|
1548 |
+
"loss": 1.7622,
|
1549 |
+
"step": 11000
|
1550 |
+
},
|
1551 |
+
{
|
1552 |
+
"epoch": 0.72,
|
1553 |
+
"grad_norm": 0.323830246925354,
|
1554 |
+
"learning_rate": 1.3799318390352602e-05,
|
1555 |
+
"loss": 1.7814,
|
1556 |
+
"step": 11050
|
1557 |
+
},
|
1558 |
+
{
|
1559 |
+
"epoch": 0.73,
|
1560 |
+
"grad_norm": 0.5781140327453613,
|
1561 |
+
"learning_rate": 1.363546991742037e-05,
|
1562 |
+
"loss": 1.7693,
|
1563 |
+
"step": 11100
|
1564 |
+
},
|
1565 |
+
{
|
1566 |
+
"epoch": 0.73,
|
1567 |
+
"grad_norm": 0.7093366980552673,
|
1568 |
+
"learning_rate": 1.347162144448814e-05,
|
1569 |
+
"loss": 1.7426,
|
1570 |
+
"step": 11150
|
1571 |
+
},
|
1572 |
+
{
|
1573 |
+
"epoch": 0.73,
|
1574 |
+
"grad_norm": 0.4438339173793793,
|
1575 |
+
"learning_rate": 1.3307772971555906e-05,
|
1576 |
+
"loss": 1.7855,
|
1577 |
+
"step": 11200
|
1578 |
+
},
|
1579 |
+
{
|
1580 |
+
"epoch": 0.74,
|
1581 |
+
"grad_norm": 0.4285770356655121,
|
1582 |
+
"learning_rate": 1.3143924498623675e-05,
|
1583 |
+
"loss": 1.7898,
|
1584 |
+
"step": 11250
|
1585 |
+
},
|
1586 |
+
{
|
1587 |
+
"epoch": 0.74,
|
1588 |
+
"grad_norm": 0.6678707599639893,
|
1589 |
+
"learning_rate": 1.298007602569144e-05,
|
1590 |
+
"loss": 1.7668,
|
1591 |
+
"step": 11300
|
1592 |
+
},
|
1593 |
+
{
|
1594 |
+
"epoch": 0.74,
|
1595 |
+
"grad_norm": 0.5140306353569031,
|
1596 |
+
"learning_rate": 1.2816227552759209e-05,
|
1597 |
+
"loss": 1.7804,
|
1598 |
+
"step": 11350
|
1599 |
+
},
|
1600 |
+
{
|
1601 |
+
"epoch": 0.75,
|
1602 |
+
"grad_norm": 0.3694643974304199,
|
1603 |
+
"learning_rate": 1.2652379079826975e-05,
|
1604 |
+
"loss": 1.7633,
|
1605 |
+
"step": 11400
|
1606 |
+
},
|
1607 |
+
{
|
1608 |
+
"epoch": 0.75,
|
1609 |
+
"grad_norm": 0.3662973940372467,
|
1610 |
+
"learning_rate": 1.2488530606894744e-05,
|
1611 |
+
"loss": 1.758,
|
1612 |
+
"step": 11450
|
1613 |
+
},
|
1614 |
+
{
|
1615 |
+
"epoch": 0.75,
|
1616 |
+
"grad_norm": 0.41093963384628296,
|
1617 |
+
"learning_rate": 1.2324682133962513e-05,
|
1618 |
+
"loss": 1.7501,
|
1619 |
+
"step": 11500
|
1620 |
+
},
|
1621 |
+
{
|
1622 |
+
"epoch": 0.76,
|
1623 |
+
"grad_norm": 0.4775155782699585,
|
1624 |
+
"learning_rate": 1.216083366103028e-05,
|
1625 |
+
"loss": 1.7986,
|
1626 |
+
"step": 11550
|
1627 |
+
},
|
1628 |
+
{
|
1629 |
+
"epoch": 0.76,
|
1630 |
+
"grad_norm": 0.36493539810180664,
|
1631 |
+
"learning_rate": 1.1996985188098048e-05,
|
1632 |
+
"loss": 1.7555,
|
1633 |
+
"step": 11600
|
1634 |
+
},
|
1635 |
+
{
|
1636 |
+
"epoch": 0.76,
|
1637 |
+
"grad_norm": 0.9100409746170044,
|
1638 |
+
"learning_rate": 1.1833136715165815e-05,
|
1639 |
+
"loss": 1.7505,
|
1640 |
+
"step": 11650
|
1641 |
+
},
|
1642 |
+
{
|
1643 |
+
"epoch": 0.77,
|
1644 |
+
"grad_norm": 0.41831496357917786,
|
1645 |
+
"learning_rate": 1.1669288242233583e-05,
|
1646 |
+
"loss": 1.7612,
|
1647 |
+
"step": 11700
|
1648 |
+
},
|
1649 |
+
{
|
1650 |
+
"epoch": 0.77,
|
1651 |
+
"grad_norm": 0.4716850221157074,
|
1652 |
+
"learning_rate": 1.150543976930135e-05,
|
1653 |
+
"loss": 1.7838,
|
1654 |
+
"step": 11750
|
1655 |
+
},
|
1656 |
+
{
|
1657 |
+
"epoch": 0.77,
|
1658 |
+
"grad_norm": 0.3609485924243927,
|
1659 |
+
"learning_rate": 1.1341591296369119e-05,
|
1660 |
+
"loss": 1.7926,
|
1661 |
+
"step": 11800
|
1662 |
+
},
|
1663 |
+
{
|
1664 |
+
"epoch": 0.78,
|
1665 |
+
"grad_norm": 0.3157222270965576,
|
1666 |
+
"learning_rate": 1.1177742823436886e-05,
|
1667 |
+
"loss": 1.7448,
|
1668 |
+
"step": 11850
|
1669 |
+
},
|
1670 |
+
{
|
1671 |
+
"epoch": 0.78,
|
1672 |
+
"grad_norm": 0.46687546372413635,
|
1673 |
+
"learning_rate": 1.1013894350504654e-05,
|
1674 |
+
"loss": 1.7975,
|
1675 |
+
"step": 11900
|
1676 |
+
},
|
1677 |
+
{
|
1678 |
+
"epoch": 0.78,
|
1679 |
+
"grad_norm": 0.6575301289558411,
|
1680 |
+
"learning_rate": 1.0850045877572421e-05,
|
1681 |
+
"loss": 1.736,
|
1682 |
+
"step": 11950
|
1683 |
+
},
|
1684 |
+
{
|
1685 |
+
"epoch": 0.79,
|
1686 |
+
"grad_norm": 1.4544192552566528,
|
1687 |
+
"learning_rate": 1.0686197404640188e-05,
|
1688 |
+
"loss": 1.7763,
|
1689 |
+
"step": 12000
|
1690 |
+
},
|
1691 |
+
{
|
1692 |
+
"epoch": 0.79,
|
1693 |
+
"grad_norm": 0.5222745537757874,
|
1694 |
+
"learning_rate": 1.0522348931707957e-05,
|
1695 |
+
"loss": 1.7786,
|
1696 |
+
"step": 12050
|
1697 |
+
},
|
1698 |
+
{
|
1699 |
+
"epoch": 0.79,
|
1700 |
+
"grad_norm": 0.6186469197273254,
|
1701 |
+
"learning_rate": 1.0358500458775725e-05,
|
1702 |
+
"loss": 1.7963,
|
1703 |
+
"step": 12100
|
1704 |
+
},
|
1705 |
+
{
|
1706 |
+
"epoch": 0.8,
|
1707 |
+
"grad_norm": 1.1090551614761353,
|
1708 |
+
"learning_rate": 1.0194651985843492e-05,
|
1709 |
+
"loss": 1.808,
|
1710 |
+
"step": 12150
|
1711 |
+
},
|
1712 |
+
{
|
1713 |
+
"epoch": 0.8,
|
1714 |
+
"grad_norm": 0.46629172563552856,
|
1715 |
+
"learning_rate": 1.003080351291126e-05,
|
1716 |
+
"loss": 1.7754,
|
1717 |
+
"step": 12200
|
1718 |
+
},
|
1719 |
+
{
|
1720 |
+
"epoch": 0.8,
|
1721 |
+
"grad_norm": 1.5671145915985107,
|
1722 |
+
"learning_rate": 9.866955039979028e-06,
|
1723 |
+
"loss": 1.7846,
|
1724 |
+
"step": 12250
|
1725 |
+
},
|
1726 |
+
{
|
1727 |
+
"epoch": 0.81,
|
1728 |
+
"grad_norm": 0.5020501613616943,
|
1729 |
+
"learning_rate": 9.703106567046794e-06,
|
1730 |
+
"loss": 1.753,
|
1731 |
+
"step": 12300
|
1732 |
+
},
|
1733 |
+
{
|
1734 |
+
"epoch": 0.81,
|
1735 |
+
"grad_norm": 0.34436970949172974,
|
1736 |
+
"learning_rate": 9.539258094114563e-06,
|
1737 |
+
"loss": 1.8023,
|
1738 |
+
"step": 12350
|
1739 |
+
},
|
1740 |
+
{
|
1741 |
+
"epoch": 0.81,
|
1742 |
+
"grad_norm": 0.4563136100769043,
|
1743 |
+
"learning_rate": 9.375409621182332e-06,
|
1744 |
+
"loss": 1.7644,
|
1745 |
+
"step": 12400
|
1746 |
+
},
|
1747 |
+
{
|
1748 |
+
"epoch": 0.82,
|
1749 |
+
"grad_norm": 0.3465505540370941,
|
1750 |
+
"learning_rate": 9.211561148250098e-06,
|
1751 |
+
"loss": 1.7819,
|
1752 |
+
"step": 12450
|
1753 |
+
},
|
1754 |
+
{
|
1755 |
+
"epoch": 0.82,
|
1756 |
+
"grad_norm": 0.4823606610298157,
|
1757 |
+
"learning_rate": 9.047712675317867e-06,
|
1758 |
+
"loss": 1.7626,
|
1759 |
+
"step": 12500
|
1760 |
+
},
|
1761 |
+
{
|
1762 |
+
"epoch": 0.82,
|
1763 |
+
"grad_norm": 0.5832303166389465,
|
1764 |
+
"learning_rate": 8.883864202385634e-06,
|
1765 |
+
"loss": 1.724,
|
1766 |
+
"step": 12550
|
1767 |
+
},
|
1768 |
+
{
|
1769 |
+
"epoch": 0.83,
|
1770 |
+
"grad_norm": 0.590023934841156,
|
1771 |
+
"learning_rate": 8.7200157294534e-06,
|
1772 |
+
"loss": 1.7708,
|
1773 |
+
"step": 12600
|
1774 |
+
},
|
1775 |
+
{
|
1776 |
+
"epoch": 0.83,
|
1777 |
+
"grad_norm": 0.3506929278373718,
|
1778 |
+
"learning_rate": 8.55616725652117e-06,
|
1779 |
+
"loss": 1.7979,
|
1780 |
+
"step": 12650
|
1781 |
+
},
|
1782 |
+
{
|
1783 |
+
"epoch": 0.83,
|
1784 |
+
"grad_norm": 0.5510967373847961,
|
1785 |
+
"learning_rate": 8.392318783588938e-06,
|
1786 |
+
"loss": 1.7531,
|
1787 |
+
"step": 12700
|
1788 |
+
},
|
1789 |
+
{
|
1790 |
+
"epoch": 0.84,
|
1791 |
+
"grad_norm": 0.4131988286972046,
|
1792 |
+
"learning_rate": 8.228470310656705e-06,
|
1793 |
+
"loss": 1.7869,
|
1794 |
+
"step": 12750
|
1795 |
+
},
|
1796 |
+
{
|
1797 |
+
"epoch": 0.84,
|
1798 |
+
"grad_norm": 0.3922310173511505,
|
1799 |
+
"learning_rate": 8.064621837724473e-06,
|
1800 |
+
"loss": 1.8283,
|
1801 |
+
"step": 12800
|
1802 |
+
},
|
1803 |
+
{
|
1804 |
+
"epoch": 0.84,
|
1805 |
+
"grad_norm": 0.4114150106906891,
|
1806 |
+
"learning_rate": 7.90077336479224e-06,
|
1807 |
+
"loss": 1.8061,
|
1808 |
+
"step": 12850
|
1809 |
+
},
|
1810 |
+
{
|
1811 |
+
"epoch": 0.85,
|
1812 |
+
"grad_norm": 0.5551263093948364,
|
1813 |
+
"learning_rate": 7.736924891860007e-06,
|
1814 |
+
"loss": 1.8083,
|
1815 |
+
"step": 12900
|
1816 |
+
},
|
1817 |
+
{
|
1818 |
+
"epoch": 0.85,
|
1819 |
+
"grad_norm": 0.4596497714519501,
|
1820 |
+
"learning_rate": 7.573076418927776e-06,
|
1821 |
+
"loss": 1.768,
|
1822 |
+
"step": 12950
|
1823 |
+
},
|
1824 |
+
{
|
1825 |
+
"epoch": 0.85,
|
1826 |
+
"grad_norm": 0.5840251445770264,
|
1827 |
+
"learning_rate": 7.409227945995543e-06,
|
1828 |
+
"loss": 1.7793,
|
1829 |
+
"step": 13000
|
1830 |
+
},
|
1831 |
+
{
|
1832 |
+
"epoch": 0.86,
|
1833 |
+
"grad_norm": 0.6608572602272034,
|
1834 |
+
"learning_rate": 7.245379473063311e-06,
|
1835 |
+
"loss": 1.7433,
|
1836 |
+
"step": 13050
|
1837 |
+
},
|
1838 |
+
{
|
1839 |
+
"epoch": 0.86,
|
1840 |
+
"grad_norm": 0.4415280818939209,
|
1841 |
+
"learning_rate": 7.08153100013108e-06,
|
1842 |
+
"loss": 1.7555,
|
1843 |
+
"step": 13100
|
1844 |
+
},
|
1845 |
+
{
|
1846 |
+
"epoch": 0.86,
|
1847 |
+
"grad_norm": 0.8738279938697815,
|
1848 |
+
"learning_rate": 6.9176825271988474e-06,
|
1849 |
+
"loss": 1.7655,
|
1850 |
+
"step": 13150
|
1851 |
+
},
|
1852 |
+
{
|
1853 |
+
"epoch": 0.87,
|
1854 |
+
"grad_norm": 0.5214579105377197,
|
1855 |
+
"learning_rate": 6.753834054266614e-06,
|
1856 |
+
"loss": 1.7626,
|
1857 |
+
"step": 13200
|
1858 |
+
},
|
1859 |
+
{
|
1860 |
+
"epoch": 0.87,
|
1861 |
+
"grad_norm": 0.42428484559059143,
|
1862 |
+
"learning_rate": 6.589985581334382e-06,
|
1863 |
+
"loss": 1.754,
|
1864 |
+
"step": 13250
|
1865 |
+
},
|
1866 |
+
{
|
1867 |
+
"epoch": 0.87,
|
1868 |
+
"grad_norm": 0.4472542703151703,
|
1869 |
+
"learning_rate": 6.42613710840215e-06,
|
1870 |
+
"loss": 1.8004,
|
1871 |
+
"step": 13300
|
1872 |
+
},
|
1873 |
+
{
|
1874 |
+
"epoch": 0.87,
|
1875 |
+
"grad_norm": 0.44398799538612366,
|
1876 |
+
"learning_rate": 6.2622886354699175e-06,
|
1877 |
+
"loss": 1.7692,
|
1878 |
+
"step": 13350
|
1879 |
+
},
|
1880 |
+
{
|
1881 |
+
"epoch": 0.88,
|
1882 |
+
"grad_norm": 0.39280277490615845,
|
1883 |
+
"learning_rate": 6.098440162537685e-06,
|
1884 |
+
"loss": 1.756,
|
1885 |
+
"step": 13400
|
1886 |
+
},
|
1887 |
+
{
|
1888 |
+
"epoch": 0.88,
|
1889 |
+
"grad_norm": 0.5377512574195862,
|
1890 |
+
"learning_rate": 5.934591689605453e-06,
|
1891 |
+
"loss": 1.8203,
|
1892 |
+
"step": 13450
|
1893 |
+
},
|
1894 |
+
{
|
1895 |
+
"epoch": 0.88,
|
1896 |
+
"grad_norm": 0.384995698928833,
|
1897 |
+
"learning_rate": 5.770743216673221e-06,
|
1898 |
+
"loss": 1.7671,
|
1899 |
+
"step": 13500
|
1900 |
+
},
|
1901 |
+
{
|
1902 |
+
"epoch": 0.89,
|
1903 |
+
"grad_norm": 0.5518258810043335,
|
1904 |
+
"learning_rate": 5.606894743740988e-06,
|
1905 |
+
"loss": 1.7892,
|
1906 |
+
"step": 13550
|
1907 |
+
},
|
1908 |
+
{
|
1909 |
+
"epoch": 0.89,
|
1910 |
+
"grad_norm": 0.5481269955635071,
|
1911 |
+
"learning_rate": 5.443046270808756e-06,
|
1912 |
+
"loss": 1.7621,
|
1913 |
+
"step": 13600
|
1914 |
+
},
|
1915 |
+
{
|
1916 |
+
"epoch": 0.89,
|
1917 |
+
"grad_norm": 0.6983498930931091,
|
1918 |
+
"learning_rate": 5.279197797876524e-06,
|
1919 |
+
"loss": 1.7699,
|
1920 |
+
"step": 13650
|
1921 |
+
},
|
1922 |
+
{
|
1923 |
+
"epoch": 0.9,
|
1924 |
+
"grad_norm": 0.42530539631843567,
|
1925 |
+
"learning_rate": 5.1153493249442916e-06,
|
1926 |
+
"loss": 1.781,
|
1927 |
+
"step": 13700
|
1928 |
+
},
|
1929 |
+
{
|
1930 |
+
"epoch": 0.9,
|
1931 |
+
"grad_norm": 0.5558788776397705,
|
1932 |
+
"learning_rate": 4.951500852012059e-06,
|
1933 |
+
"loss": 1.7386,
|
1934 |
+
"step": 13750
|
1935 |
+
},
|
1936 |
+
{
|
1937 |
+
"epoch": 0.9,
|
1938 |
+
"grad_norm": 0.40052852034568787,
|
1939 |
+
"learning_rate": 4.787652379079827e-06,
|
1940 |
+
"loss": 1.7761,
|
1941 |
+
"step": 13800
|
1942 |
+
},
|
1943 |
+
{
|
1944 |
+
"epoch": 0.91,
|
1945 |
+
"grad_norm": 0.3250432312488556,
|
1946 |
+
"learning_rate": 4.623803906147595e-06,
|
1947 |
+
"loss": 1.7782,
|
1948 |
+
"step": 13850
|
1949 |
+
},
|
1950 |
+
{
|
1951 |
+
"epoch": 0.91,
|
1952 |
+
"grad_norm": 0.38817328214645386,
|
1953 |
+
"learning_rate": 4.4599554332153624e-06,
|
1954 |
+
"loss": 1.7407,
|
1955 |
+
"step": 13900
|
1956 |
+
},
|
1957 |
+
{
|
1958 |
+
"epoch": 0.91,
|
1959 |
+
"grad_norm": 0.49112117290496826,
|
1960 |
+
"learning_rate": 4.29610696028313e-06,
|
1961 |
+
"loss": 1.7229,
|
1962 |
+
"step": 13950
|
1963 |
+
},
|
1964 |
+
{
|
1965 |
+
"epoch": 0.92,
|
1966 |
+
"grad_norm": 2.6235454082489014,
|
1967 |
+
"learning_rate": 4.132258487350898e-06,
|
1968 |
+
"loss": 1.7547,
|
1969 |
+
"step": 14000
|
1970 |
+
},
|
1971 |
+
{
|
1972 |
+
"epoch": 0.92,
|
1973 |
+
"grad_norm": 0.4624078571796417,
|
1974 |
+
"learning_rate": 3.968410014418666e-06,
|
1975 |
+
"loss": 1.8014,
|
1976 |
+
"step": 14050
|
1977 |
+
},
|
1978 |
+
{
|
1979 |
+
"epoch": 0.92,
|
1980 |
+
"grad_norm": 0.3169557452201843,
|
1981 |
+
"learning_rate": 3.8045615414864338e-06,
|
1982 |
+
"loss": 1.7387,
|
1983 |
+
"step": 14100
|
1984 |
+
},
|
1985 |
+
{
|
1986 |
+
"epoch": 0.93,
|
1987 |
+
"grad_norm": 0.6099672913551331,
|
1988 |
+
"learning_rate": 3.640713068554201e-06,
|
1989 |
+
"loss": 1.8081,
|
1990 |
+
"step": 14150
|
1991 |
+
},
|
1992 |
+
{
|
1993 |
+
"epoch": 0.93,
|
1994 |
+
"grad_norm": 0.4258570969104767,
|
1995 |
+
"learning_rate": 3.4768645956219688e-06,
|
1996 |
+
"loss": 1.7663,
|
1997 |
+
"step": 14200
|
1998 |
+
},
|
1999 |
+
{
|
2000 |
+
"epoch": 0.93,
|
2001 |
+
"grad_norm": 2.3566250801086426,
|
2002 |
+
"learning_rate": 3.313016122689737e-06,
|
2003 |
+
"loss": 1.7435,
|
2004 |
+
"step": 14250
|
2005 |
+
},
|
2006 |
+
{
|
2007 |
+
"epoch": 0.94,
|
2008 |
+
"grad_norm": 0.4608743190765381,
|
2009 |
+
"learning_rate": 3.1491676497575042e-06,
|
2010 |
+
"loss": 1.7605,
|
2011 |
+
"step": 14300
|
2012 |
+
},
|
2013 |
+
{
|
2014 |
+
"epoch": 0.94,
|
2015 |
+
"grad_norm": 0.38116034865379333,
|
2016 |
+
"learning_rate": 2.985319176825272e-06,
|
2017 |
+
"loss": 1.7673,
|
2018 |
+
"step": 14350
|
2019 |
+
},
|
2020 |
+
{
|
2021 |
+
"epoch": 0.94,
|
2022 |
+
"grad_norm": 0.5122969746589661,
|
2023 |
+
"learning_rate": 2.8214707038930397e-06,
|
2024 |
+
"loss": 1.767,
|
2025 |
+
"step": 14400
|
2026 |
+
},
|
2027 |
+
{
|
2028 |
+
"epoch": 0.95,
|
2029 |
+
"grad_norm": 0.5967180132865906,
|
2030 |
+
"learning_rate": 2.657622230960808e-06,
|
2031 |
+
"loss": 1.8025,
|
2032 |
+
"step": 14450
|
2033 |
+
},
|
2034 |
+
{
|
2035 |
+
"epoch": 0.95,
|
2036 |
+
"grad_norm": 0.4944264590740204,
|
2037 |
+
"learning_rate": 2.493773758028575e-06,
|
2038 |
+
"loss": 1.7947,
|
2039 |
+
"step": 14500
|
2040 |
+
},
|
2041 |
+
{
|
2042 |
+
"epoch": 0.95,
|
2043 |
+
"grad_norm": 0.353904128074646,
|
2044 |
+
"learning_rate": 2.329925285096343e-06,
|
2045 |
+
"loss": 1.795,
|
2046 |
+
"step": 14550
|
2047 |
+
},
|
2048 |
+
{
|
2049 |
+
"epoch": 0.96,
|
2050 |
+
"grad_norm": 0.531599223613739,
|
2051 |
+
"learning_rate": 2.166076812164111e-06,
|
2052 |
+
"loss": 1.7888,
|
2053 |
+
"step": 14600
|
2054 |
+
},
|
2055 |
+
{
|
2056 |
+
"epoch": 0.96,
|
2057 |
+
"grad_norm": 0.43692663311958313,
|
2058 |
+
"learning_rate": 2.0022283392318783e-06,
|
2059 |
+
"loss": 1.7695,
|
2060 |
+
"step": 14650
|
2061 |
+
},
|
2062 |
+
{
|
2063 |
+
"epoch": 0.96,
|
2064 |
+
"grad_norm": 0.489036500453949,
|
2065 |
+
"learning_rate": 1.838379866299646e-06,
|
2066 |
+
"loss": 1.7895,
|
2067 |
+
"step": 14700
|
2068 |
+
},
|
2069 |
+
{
|
2070 |
+
"epoch": 0.97,
|
2071 |
+
"grad_norm": 0.41665858030319214,
|
2072 |
+
"learning_rate": 1.674531393367414e-06,
|
2073 |
+
"loss": 1.7757,
|
2074 |
+
"step": 14750
|
2075 |
+
},
|
2076 |
+
{
|
2077 |
+
"epoch": 0.97,
|
2078 |
+
"grad_norm": 0.507135272026062,
|
2079 |
+
"learning_rate": 1.5106829204351817e-06,
|
2080 |
+
"loss": 1.7717,
|
2081 |
+
"step": 14800
|
2082 |
+
},
|
2083 |
+
{
|
2084 |
+
"epoch": 0.97,
|
2085 |
+
"grad_norm": 0.4490343928337097,
|
2086 |
+
"learning_rate": 1.3468344475029494e-06,
|
2087 |
+
"loss": 1.7953,
|
2088 |
+
"step": 14850
|
2089 |
+
},
|
2090 |
+
{
|
2091 |
+
"epoch": 0.98,
|
2092 |
+
"grad_norm": 0.7222400307655334,
|
2093 |
+
"learning_rate": 1.182985974570717e-06,
|
2094 |
+
"loss": 1.7899,
|
2095 |
+
"step": 14900
|
2096 |
+
},
|
2097 |
+
{
|
2098 |
+
"epoch": 0.98,
|
2099 |
+
"grad_norm": 0.46795913577079773,
|
2100 |
+
"learning_rate": 1.0191375016384849e-06,
|
2101 |
+
"loss": 1.7826,
|
2102 |
+
"step": 14950
|
2103 |
+
},
|
2104 |
+
{
|
2105 |
+
"epoch": 0.98,
|
2106 |
+
"grad_norm": 1.0008032321929932,
|
2107 |
+
"learning_rate": 8.552890287062526e-07,
|
2108 |
+
"loss": 1.7784,
|
2109 |
+
"step": 15000
|
2110 |
+
},
|
2111 |
+
{
|
2112 |
+
"epoch": 0.99,
|
2113 |
+
"grad_norm": 0.5528744459152222,
|
2114 |
+
"learning_rate": 6.914405557740202e-07,
|
2115 |
+
"loss": 1.7827,
|
2116 |
+
"step": 15050
|
2117 |
+
},
|
2118 |
+
{
|
2119 |
+
"epoch": 0.99,
|
2120 |
+
"grad_norm": 0.38615551590919495,
|
2121 |
+
"learning_rate": 5.275920828417879e-07,
|
2122 |
+
"loss": 1.784,
|
2123 |
+
"step": 15100
|
2124 |
+
},
|
2125 |
+
{
|
2126 |
+
"epoch": 0.99,
|
2127 |
+
"grad_norm": 0.44470590353012085,
|
2128 |
+
"learning_rate": 3.6374360990955564e-07,
|
2129 |
+
"loss": 1.8012,
|
2130 |
+
"step": 15150
|
2131 |
+
},
|
2132 |
+
{
|
2133 |
+
"epoch": 1.0,
|
2134 |
+
"grad_norm": 0.39151865243911743,
|
2135 |
+
"learning_rate": 1.998951369773234e-07,
|
2136 |
+
"loss": 1.7987,
|
2137 |
+
"step": 15200
|
2138 |
+
},
|
2139 |
+
{
|
2140 |
+
"epoch": 1.0,
|
2141 |
+
"grad_norm": 0.4639741778373718,
|
2142 |
+
"learning_rate": 3.60466640450911e-08,
|
2143 |
+
"loss": 1.7547,
|
2144 |
+
"step": 15250
|
2145 |
+
}
|
2146 |
+
],
|
2147 |
+
"logging_steps": 50,
|
2148 |
+
"max_steps": 15260,
|
2149 |
+
"num_input_tokens_seen": 0,
|
2150 |
+
"num_train_epochs": 1,
|
2151 |
+
"save_steps": 3815,
|
2152 |
+
"total_flos": 1.0144210157797009e+20,
|
2153 |
+
"train_batch_size": 1,
|
2154 |
+
"trial_name": null,
|
2155 |
+
"trial_params": null
|
2156 |
+
}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:159c5f78c2f0e9f940068cc8d592ff2759448a8c6e4f50e6cf5d852260e7440f
|
3 |
+
size 7352
|