TommyChien commited on
Commit
e1d722a
·
verified ·
1 Parent(s): 172be20

Upload folder using huggingface_hub

Browse files
added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
config.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/share/qhj/FlagEmbedding/research/Long_LLM/activation_beacon/data/outputs/beacon-qwen2.5-3B-full_coverage-interleave-2048_2048-8,16,32,64,128-step_random-qkv-redpajama/checkpoint-11432",
3
+ "architectures": [
4
+ "Qwen2ForCausalLM"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_qwen2.Qwen2Config",
8
+ "AutoModelForCausalLM": "modeling_qwen2.Qwen2ForCausalLM"
9
+ },
10
+ "attention_dropout": 0.0,
11
+ "beacon_attend_prev": true,
12
+ "beacon_attn": "full-coverage",
13
+ "beacon_embed_init": "eos",
14
+ "beacon_parallel_window": 1,
15
+ "beacon_param": [
16
+ "q",
17
+ "k",
18
+ "v"
19
+ ],
20
+ "beacon_pos": "interleave",
21
+ "beacon_ratio": [
22
+ 8,
23
+ 16,
24
+ 32,
25
+ 64,
26
+ 128
27
+ ],
28
+ "beacon_ratio_mix": "step-random",
29
+ "beacon_sink_size": 0,
30
+ "beacon_stride": 2048,
31
+ "beacon_window": 2048,
32
+ "bos_token_id": 151643,
33
+ "eos_token_id": 151645,
34
+ "hidden_act": "silu",
35
+ "hidden_size": 2048,
36
+ "initializer_range": 0.02,
37
+ "intermediate_size": 11008,
38
+ "max_position_embeddings": 32768,
39
+ "max_window_layers": 70,
40
+ "model_type": "qwen2",
41
+ "num_attention_heads": 16,
42
+ "num_hidden_layers": 36,
43
+ "num_key_value_heads": 2,
44
+ "rms_norm_eps": 1e-06,
45
+ "rope_scaling": null,
46
+ "rope_theta": 1000000.0,
47
+ "sliding_window": 32768,
48
+ "tie_word_embeddings": true,
49
+ "torch_dtype": "bfloat16",
50
+ "transformers_version": "4.44.2",
51
+ "use_cache": true,
52
+ "use_sliding_window": false,
53
+ "vocab_size": 151936
54
+ }
configuration_qwen2.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The Qwen team, Alibaba Group 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
+ """ Qwen2 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
+ QWEN2_PRETRAINED_CONFIG_ARCHIVE_MAP = {
24
+ "Qwen/Qwen2-7B-beta": "https://huggingface.co/Qwen/Qwen2-7B-beta/resolve/main/config.json",
25
+ }
26
+
27
+
28
+ class Qwen2Config(PretrainedConfig):
29
+ r"""
30
+ This is the configuration class to store the configuration of a [`Qwen2Model`]. It is used to instantiate a
31
+ Qwen2 model according to the specified arguments, defining the model architecture. Instantiating a configuration
32
+ with the defaults will yield a similar configuration to that of
33
+ Qwen2-7B-beta [Qwen/Qwen2-7B-beta](https://huggingface.co/Qwen/Qwen2-7B-beta).
34
+
35
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
36
+ documentation from [`PretrainedConfig`] for more information.
37
+
38
+
39
+ Args:
40
+ vocab_size (`int`, *optional*, defaults to 151936):
41
+ Vocabulary size of the Qwen2 model. Defines the number of different tokens that can be represented by the
42
+ `inputs_ids` passed when calling [`Qwen2Model`]
43
+ hidden_size (`int`, *optional*, defaults to 4096):
44
+ Dimension of the hidden representations.
45
+ intermediate_size (`int`, *optional*, defaults to 22016):
46
+ Dimension of the MLP representations.
47
+ num_hidden_layers (`int`, *optional*, defaults to 32):
48
+ Number of hidden layers in the Transformer encoder.
49
+ num_attention_heads (`int`, *optional*, defaults to 32):
50
+ Number of attention heads for each attention layer in the Transformer encoder.
51
+ num_key_value_heads (`int`, *optional*, defaults to 32):
52
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
53
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
54
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
55
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
56
+ by meanpooling all the original heads within that group. For more details checkout [this
57
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
58
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
59
+ The non-linear activation function (function or string) in the decoder.
60
+ max_position_embeddings (`int`, *optional*, defaults to 32768):
61
+ The maximum sequence length that this model might ever be used with.
62
+ initializer_range (`float`, *optional*, defaults to 0.02):
63
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
64
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
65
+ The epsilon used by the rms normalization layers.
66
+ use_cache (`bool`, *optional*, defaults to `True`):
67
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
68
+ relevant if `config.is_decoder=True`.
69
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
70
+ Whether the model's input and output word embeddings should be tied.
71
+ rope_theta (`float`, *optional*, defaults to 10000.0):
72
+ The base period of the RoPE embeddings.
73
+ use_sliding_window (`bool`, *optional*, defaults to `False`):
74
+ Whether to use sliding window attention.
75
+ sliding_window (`int`, *optional*, defaults to 4096):
76
+ Sliding window attention (SWA) window size. If not specified, will default to `4096`.
77
+ max_window_layers (`int`, *optional*, defaults to 28):
78
+ The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
79
+ attention_dropout (`float`, *optional*, defaults to 0.0):
80
+ The dropout ratio for the attention probabilities.
81
+
82
+ ```python
83
+ >>> from transformers import Qwen2Model, Qwen2Config
84
+
85
+ >>> # Initializing a Qwen2 style configuration
86
+ >>> configuration = Qwen2Config()
87
+
88
+ >>> # Initializing a model from the Qwen2-7B style configuration
89
+ >>> model = Qwen2Model(configuration)
90
+
91
+ >>> # Accessing the model configuration
92
+ >>> configuration = model.config
93
+ ```"""
94
+
95
+ model_type = "qwen2"
96
+ keys_to_ignore_at_inference = ["past_key_values"]
97
+
98
+ def __init__(
99
+ self,
100
+ vocab_size=151936,
101
+ hidden_size=4096,
102
+ intermediate_size=22016,
103
+ num_hidden_layers=32,
104
+ num_attention_heads=32,
105
+ num_key_value_heads=32,
106
+ hidden_act="silu",
107
+ max_position_embeddings=32768,
108
+ initializer_range=0.02,
109
+ rms_norm_eps=1e-6,
110
+ use_cache=True,
111
+ tie_word_embeddings=False,
112
+ rope_theta=10000.0,
113
+ use_sliding_window=False,
114
+ sliding_window=4096,
115
+ rope_scaling=None,
116
+ max_window_layers=28,
117
+ attention_dropout=0.0,
118
+ beacon_window=1024,
119
+ beacon_stride=1024,
120
+ beacon_attn="full-coverage",
121
+ beacon_ratio=[2,4,8,16,32],
122
+ beacon_ratio_mix="step-random",
123
+ beacon_param=[],
124
+ beacon_embed_init="eos",
125
+ beacon_sink_size=0,
126
+ beacon_attend_prev=True,
127
+ beacon_pos="interleave",
128
+ beacon_parallel_window=1,
129
+ beacon_accum=True,
130
+ **kwargs,
131
+ ):
132
+ self.vocab_size = vocab_size
133
+ self.max_position_embeddings = max_position_embeddings
134
+ self.hidden_size = hidden_size
135
+ self.intermediate_size = intermediate_size
136
+ self.num_hidden_layers = num_hidden_layers
137
+ self.num_attention_heads = num_attention_heads
138
+ self.use_sliding_window = use_sliding_window
139
+ self.sliding_window = sliding_window
140
+ self.max_window_layers = max_window_layers
141
+ self.rope_scaling = rope_scaling
142
+
143
+ # for backward compatibility
144
+ if num_key_value_heads is None:
145
+ num_key_value_heads = num_attention_heads
146
+
147
+ self.num_key_value_heads = num_key_value_heads
148
+ self.hidden_act = hidden_act
149
+ self.initializer_range = initializer_range
150
+ self.rms_norm_eps = rms_norm_eps
151
+ self.use_cache = use_cache
152
+ self.rope_theta = rope_theta
153
+ self.attention_dropout = attention_dropout
154
+
155
+ self.beacon_window = beacon_window
156
+ self.beacon_stride = beacon_stride
157
+ self.beacon_attn = beacon_attn
158
+ self.beacon_ratio = beacon_ratio
159
+ self.beacon_ratio_mix = beacon_ratio_mix
160
+ self.beacon_param = beacon_param
161
+ self.beacon_embed_init = beacon_embed_init
162
+ self.beacon_sink_size = beacon_sink_size
163
+ self.beacon_attend_prev = beacon_attend_prev
164
+ self.beacon_pos = beacon_pos
165
+ self.beacon_parallel_window = beacon_parallel_window
166
+ self.beacon_accum = beacon_accum
167
+
168
+ super().__init__(
169
+ tie_word_embeddings=tie_word_embeddings,
170
+ **kwargs,
171
+ )
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "repetition_penalty": 1.05,
10
+ "temperature": 0.7,
11
+ "top_k": 20,
12
+ "top_p": 0.8,
13
+ "transformers_version": "4.44.2"
14
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f13f9296edeb60c73d88689b2bf243e256a9d9b4b5c2e269dc506d0185db79d2
3
+ size 4977615904
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:62e294c3f286bb75023f332477afe93396e4758a5e0d62e2c5f487e1196aa794
3
+ size 2194343032
model.safetensors.index.json ADDED
@@ -0,0 +1,659 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 7171883008
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00002-of-00002.safetensors",
7
+ "model.beacon_embed_tokens.weight": "model-00001-of-00002.safetensors",
8
+ "model.embed_tokens.weight": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
14
+ "model.layers.0.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
15
+ "model.layers.0.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
16
+ "model.layers.0.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
17
+ "model.layers.0.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
18
+ "model.layers.0.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
19
+ "model.layers.0.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
20
+ "model.layers.0.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
21
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.0.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
24
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
25
+ "model.layers.0.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
26
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
27
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
28
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
29
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
30
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
31
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.1.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
33
+ "model.layers.1.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
34
+ "model.layers.1.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
35
+ "model.layers.1.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
36
+ "model.layers.1.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
37
+ "model.layers.1.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
38
+ "model.layers.1.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
39
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
40
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
41
+ "model.layers.1.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
42
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
43
+ "model.layers.1.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
44
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
45
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
46
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
47
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
48
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
49
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
50
+ "model.layers.10.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
51
+ "model.layers.10.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
52
+ "model.layers.10.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
53
+ "model.layers.10.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
54
+ "model.layers.10.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
55
+ "model.layers.10.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
56
+ "model.layers.10.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
57
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
58
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
59
+ "model.layers.10.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
60
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
61
+ "model.layers.10.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
62
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
63
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
64
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
65
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
66
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
67
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
68
+ "model.layers.11.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
69
+ "model.layers.11.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
70
+ "model.layers.11.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
71
+ "model.layers.11.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
72
+ "model.layers.11.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
73
+ "model.layers.11.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
74
+ "model.layers.11.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
75
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
76
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
77
+ "model.layers.11.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
78
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
79
+ "model.layers.11.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
80
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
81
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
82
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
83
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
84
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
85
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
86
+ "model.layers.12.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
87
+ "model.layers.12.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
88
+ "model.layers.12.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
89
+ "model.layers.12.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
90
+ "model.layers.12.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
91
+ "model.layers.12.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
92
+ "model.layers.12.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
93
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
94
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
95
+ "model.layers.12.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
96
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
97
+ "model.layers.12.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
98
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
99
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
100
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
101
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
102
+ "model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
103
+ "model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
104
+ "model.layers.13.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
105
+ "model.layers.13.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
106
+ "model.layers.13.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
107
+ "model.layers.13.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
108
+ "model.layers.13.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
109
+ "model.layers.13.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
110
+ "model.layers.13.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
111
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
112
+ "model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
113
+ "model.layers.13.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
114
+ "model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
115
+ "model.layers.13.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
116
+ "model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
117
+ "model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
118
+ "model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
119
+ "model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
120
+ "model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
121
+ "model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
122
+ "model.layers.14.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
123
+ "model.layers.14.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
124
+ "model.layers.14.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
125
+ "model.layers.14.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
126
+ "model.layers.14.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
127
+ "model.layers.14.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
128
+ "model.layers.14.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
129
+ "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
130
+ "model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
131
+ "model.layers.14.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
132
+ "model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
133
+ "model.layers.14.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
134
+ "model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
135
+ "model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
136
+ "model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
137
+ "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
138
+ "model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
139
+ "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
140
+ "model.layers.15.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
141
+ "model.layers.15.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
142
+ "model.layers.15.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
143
+ "model.layers.15.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
144
+ "model.layers.15.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
145
+ "model.layers.15.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
146
+ "model.layers.15.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
147
+ "model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
148
+ "model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
149
+ "model.layers.15.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
150
+ "model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
151
+ "model.layers.15.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
152
+ "model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
153
+ "model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
154
+ "model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
155
+ "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
156
+ "model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
157
+ "model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
158
+ "model.layers.16.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
159
+ "model.layers.16.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
160
+ "model.layers.16.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
161
+ "model.layers.16.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
162
+ "model.layers.16.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
163
+ "model.layers.16.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
164
+ "model.layers.16.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
165
+ "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
166
+ "model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
167
+ "model.layers.16.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
168
+ "model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
169
+ "model.layers.16.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
170
+ "model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
171
+ "model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
172
+ "model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
173
+ "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
174
+ "model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
175
+ "model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
176
+ "model.layers.17.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
177
+ "model.layers.17.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
178
+ "model.layers.17.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
179
+ "model.layers.17.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
180
+ "model.layers.17.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
181
+ "model.layers.17.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
182
+ "model.layers.17.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
183
+ "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
184
+ "model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
185
+ "model.layers.17.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
186
+ "model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
187
+ "model.layers.17.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
188
+ "model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
189
+ "model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
190
+ "model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
191
+ "model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
192
+ "model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
193
+ "model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
194
+ "model.layers.18.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
195
+ "model.layers.18.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
196
+ "model.layers.18.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
197
+ "model.layers.18.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
198
+ "model.layers.18.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
199
+ "model.layers.18.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
200
+ "model.layers.18.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
201
+ "model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
202
+ "model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
203
+ "model.layers.18.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
204
+ "model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
205
+ "model.layers.18.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
206
+ "model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
207
+ "model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
208
+ "model.layers.19.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
209
+ "model.layers.19.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
210
+ "model.layers.19.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
211
+ "model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
212
+ "model.layers.19.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
213
+ "model.layers.19.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
214
+ "model.layers.19.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
215
+ "model.layers.19.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
216
+ "model.layers.19.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
217
+ "model.layers.19.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
218
+ "model.layers.19.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
219
+ "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
220
+ "model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
221
+ "model.layers.19.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
222
+ "model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
223
+ "model.layers.19.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
224
+ "model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
225
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
226
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
227
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
228
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
229
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
230
+ "model.layers.2.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
231
+ "model.layers.2.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
232
+ "model.layers.2.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
233
+ "model.layers.2.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
234
+ "model.layers.2.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
235
+ "model.layers.2.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
236
+ "model.layers.2.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
237
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
238
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
239
+ "model.layers.2.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
240
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
241
+ "model.layers.2.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
242
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
243
+ "model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
244
+ "model.layers.20.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
245
+ "model.layers.20.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
246
+ "model.layers.20.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
247
+ "model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
248
+ "model.layers.20.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
249
+ "model.layers.20.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
250
+ "model.layers.20.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
251
+ "model.layers.20.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
252
+ "model.layers.20.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
253
+ "model.layers.20.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
254
+ "model.layers.20.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
255
+ "model.layers.20.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
256
+ "model.layers.20.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
257
+ "model.layers.20.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
258
+ "model.layers.20.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
259
+ "model.layers.20.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
260
+ "model.layers.20.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
261
+ "model.layers.21.input_layernorm.weight": "model-00001-of-00002.safetensors",
262
+ "model.layers.21.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
263
+ "model.layers.21.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
264
+ "model.layers.21.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
265
+ "model.layers.21.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
266
+ "model.layers.21.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
267
+ "model.layers.21.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
268
+ "model.layers.21.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
269
+ "model.layers.21.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
270
+ "model.layers.21.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
271
+ "model.layers.21.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
272
+ "model.layers.21.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
273
+ "model.layers.21.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
274
+ "model.layers.21.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
275
+ "model.layers.21.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
276
+ "model.layers.21.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
277
+ "model.layers.21.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
278
+ "model.layers.21.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
279
+ "model.layers.22.input_layernorm.weight": "model-00001-of-00002.safetensors",
280
+ "model.layers.22.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
281
+ "model.layers.22.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
282
+ "model.layers.22.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
283
+ "model.layers.22.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
284
+ "model.layers.22.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
285
+ "model.layers.22.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
286
+ "model.layers.22.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
287
+ "model.layers.22.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
288
+ "model.layers.22.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
289
+ "model.layers.22.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
290
+ "model.layers.22.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
291
+ "model.layers.22.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
292
+ "model.layers.22.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
293
+ "model.layers.22.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
294
+ "model.layers.22.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
295
+ "model.layers.22.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
296
+ "model.layers.22.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
297
+ "model.layers.23.input_layernorm.weight": "model-00001-of-00002.safetensors",
298
+ "model.layers.23.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
299
+ "model.layers.23.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
300
+ "model.layers.23.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
301
+ "model.layers.23.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
302
+ "model.layers.23.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
303
+ "model.layers.23.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
304
+ "model.layers.23.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
305
+ "model.layers.23.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
306
+ "model.layers.23.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
307
+ "model.layers.23.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
308
+ "model.layers.23.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
309
+ "model.layers.23.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
310
+ "model.layers.23.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
311
+ "model.layers.23.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
312
+ "model.layers.23.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
313
+ "model.layers.23.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
314
+ "model.layers.23.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
315
+ "model.layers.24.input_layernorm.weight": "model-00001-of-00002.safetensors",
316
+ "model.layers.24.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
317
+ "model.layers.24.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
318
+ "model.layers.24.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
319
+ "model.layers.24.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
320
+ "model.layers.24.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
321
+ "model.layers.24.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
322
+ "model.layers.24.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
323
+ "model.layers.24.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
324
+ "model.layers.24.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
325
+ "model.layers.24.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
326
+ "model.layers.24.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
327
+ "model.layers.24.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
328
+ "model.layers.24.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
329
+ "model.layers.24.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
330
+ "model.layers.24.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
331
+ "model.layers.24.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
332
+ "model.layers.24.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
333
+ "model.layers.25.input_layernorm.weight": "model-00001-of-00002.safetensors",
334
+ "model.layers.25.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
335
+ "model.layers.25.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
336
+ "model.layers.25.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
337
+ "model.layers.25.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
338
+ "model.layers.25.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
339
+ "model.layers.25.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
340
+ "model.layers.25.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
341
+ "model.layers.25.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
342
+ "model.layers.25.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
343
+ "model.layers.25.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
344
+ "model.layers.25.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
345
+ "model.layers.25.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
346
+ "model.layers.25.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
347
+ "model.layers.25.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
348
+ "model.layers.25.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
349
+ "model.layers.25.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
350
+ "model.layers.25.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
351
+ "model.layers.26.input_layernorm.weight": "model-00002-of-00002.safetensors",
352
+ "model.layers.26.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
353
+ "model.layers.26.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
354
+ "model.layers.26.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
355
+ "model.layers.26.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
356
+ "model.layers.26.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
357
+ "model.layers.26.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
358
+ "model.layers.26.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
359
+ "model.layers.26.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
360
+ "model.layers.26.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
361
+ "model.layers.26.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
362
+ "model.layers.26.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
363
+ "model.layers.26.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
364
+ "model.layers.26.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
365
+ "model.layers.26.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
366
+ "model.layers.26.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
367
+ "model.layers.26.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
368
+ "model.layers.26.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
369
+ "model.layers.27.input_layernorm.weight": "model-00002-of-00002.safetensors",
370
+ "model.layers.27.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
371
+ "model.layers.27.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
372
+ "model.layers.27.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
373
+ "model.layers.27.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
374
+ "model.layers.27.self_attn.beacon_k_proj.bias": "model-00002-of-00002.safetensors",
375
+ "model.layers.27.self_attn.beacon_k_proj.weight": "model-00002-of-00002.safetensors",
376
+ "model.layers.27.self_attn.beacon_q_proj.bias": "model-00002-of-00002.safetensors",
377
+ "model.layers.27.self_attn.beacon_q_proj.weight": "model-00002-of-00002.safetensors",
378
+ "model.layers.27.self_attn.beacon_v_proj.bias": "model-00002-of-00002.safetensors",
379
+ "model.layers.27.self_attn.beacon_v_proj.weight": "model-00002-of-00002.safetensors",
380
+ "model.layers.27.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
381
+ "model.layers.27.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
382
+ "model.layers.27.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
383
+ "model.layers.27.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
384
+ "model.layers.27.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
385
+ "model.layers.27.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
386
+ "model.layers.27.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
387
+ "model.layers.28.input_layernorm.weight": "model-00002-of-00002.safetensors",
388
+ "model.layers.28.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
389
+ "model.layers.28.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
390
+ "model.layers.28.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
391
+ "model.layers.28.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
392
+ "model.layers.28.self_attn.beacon_k_proj.bias": "model-00002-of-00002.safetensors",
393
+ "model.layers.28.self_attn.beacon_k_proj.weight": "model-00002-of-00002.safetensors",
394
+ "model.layers.28.self_attn.beacon_q_proj.bias": "model-00002-of-00002.safetensors",
395
+ "model.layers.28.self_attn.beacon_q_proj.weight": "model-00002-of-00002.safetensors",
396
+ "model.layers.28.self_attn.beacon_v_proj.bias": "model-00002-of-00002.safetensors",
397
+ "model.layers.28.self_attn.beacon_v_proj.weight": "model-00002-of-00002.safetensors",
398
+ "model.layers.28.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
399
+ "model.layers.28.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
400
+ "model.layers.28.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
401
+ "model.layers.28.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
402
+ "model.layers.28.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
403
+ "model.layers.28.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
404
+ "model.layers.28.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
405
+ "model.layers.29.input_layernorm.weight": "model-00002-of-00002.safetensors",
406
+ "model.layers.29.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
407
+ "model.layers.29.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
408
+ "model.layers.29.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
409
+ "model.layers.29.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
410
+ "model.layers.29.self_attn.beacon_k_proj.bias": "model-00002-of-00002.safetensors",
411
+ "model.layers.29.self_attn.beacon_k_proj.weight": "model-00002-of-00002.safetensors",
412
+ "model.layers.29.self_attn.beacon_q_proj.bias": "model-00002-of-00002.safetensors",
413
+ "model.layers.29.self_attn.beacon_q_proj.weight": "model-00002-of-00002.safetensors",
414
+ "model.layers.29.self_attn.beacon_v_proj.bias": "model-00002-of-00002.safetensors",
415
+ "model.layers.29.self_attn.beacon_v_proj.weight": "model-00002-of-00002.safetensors",
416
+ "model.layers.29.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
417
+ "model.layers.29.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
418
+ "model.layers.29.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
419
+ "model.layers.29.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
420
+ "model.layers.29.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
421
+ "model.layers.29.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
422
+ "model.layers.29.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
423
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
424
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
425
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
426
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
427
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
428
+ "model.layers.3.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
429
+ "model.layers.3.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
430
+ "model.layers.3.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
431
+ "model.layers.3.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
432
+ "model.layers.3.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
433
+ "model.layers.3.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
434
+ "model.layers.3.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
435
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
436
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
437
+ "model.layers.3.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
438
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
439
+ "model.layers.3.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
440
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
441
+ "model.layers.30.input_layernorm.weight": "model-00002-of-00002.safetensors",
442
+ "model.layers.30.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
443
+ "model.layers.30.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
444
+ "model.layers.30.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
445
+ "model.layers.30.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
446
+ "model.layers.30.self_attn.beacon_k_proj.bias": "model-00002-of-00002.safetensors",
447
+ "model.layers.30.self_attn.beacon_k_proj.weight": "model-00002-of-00002.safetensors",
448
+ "model.layers.30.self_attn.beacon_q_proj.bias": "model-00002-of-00002.safetensors",
449
+ "model.layers.30.self_attn.beacon_q_proj.weight": "model-00002-of-00002.safetensors",
450
+ "model.layers.30.self_attn.beacon_v_proj.bias": "model-00002-of-00002.safetensors",
451
+ "model.layers.30.self_attn.beacon_v_proj.weight": "model-00002-of-00002.safetensors",
452
+ "model.layers.30.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
453
+ "model.layers.30.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
454
+ "model.layers.30.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
455
+ "model.layers.30.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
456
+ "model.layers.30.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
457
+ "model.layers.30.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
458
+ "model.layers.30.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
459
+ "model.layers.31.input_layernorm.weight": "model-00002-of-00002.safetensors",
460
+ "model.layers.31.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
461
+ "model.layers.31.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
462
+ "model.layers.31.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
463
+ "model.layers.31.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
464
+ "model.layers.31.self_attn.beacon_k_proj.bias": "model-00002-of-00002.safetensors",
465
+ "model.layers.31.self_attn.beacon_k_proj.weight": "model-00002-of-00002.safetensors",
466
+ "model.layers.31.self_attn.beacon_q_proj.bias": "model-00002-of-00002.safetensors",
467
+ "model.layers.31.self_attn.beacon_q_proj.weight": "model-00002-of-00002.safetensors",
468
+ "model.layers.31.self_attn.beacon_v_proj.bias": "model-00002-of-00002.safetensors",
469
+ "model.layers.31.self_attn.beacon_v_proj.weight": "model-00002-of-00002.safetensors",
470
+ "model.layers.31.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
471
+ "model.layers.31.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
472
+ "model.layers.31.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
473
+ "model.layers.31.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
474
+ "model.layers.31.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
475
+ "model.layers.31.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
476
+ "model.layers.31.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
477
+ "model.layers.32.input_layernorm.weight": "model-00002-of-00002.safetensors",
478
+ "model.layers.32.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
479
+ "model.layers.32.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
480
+ "model.layers.32.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
481
+ "model.layers.32.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
482
+ "model.layers.32.self_attn.beacon_k_proj.bias": "model-00002-of-00002.safetensors",
483
+ "model.layers.32.self_attn.beacon_k_proj.weight": "model-00002-of-00002.safetensors",
484
+ "model.layers.32.self_attn.beacon_q_proj.bias": "model-00002-of-00002.safetensors",
485
+ "model.layers.32.self_attn.beacon_q_proj.weight": "model-00002-of-00002.safetensors",
486
+ "model.layers.32.self_attn.beacon_v_proj.bias": "model-00002-of-00002.safetensors",
487
+ "model.layers.32.self_attn.beacon_v_proj.weight": "model-00002-of-00002.safetensors",
488
+ "model.layers.32.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
489
+ "model.layers.32.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
490
+ "model.layers.32.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
491
+ "model.layers.32.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
492
+ "model.layers.32.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
493
+ "model.layers.32.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
494
+ "model.layers.32.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
495
+ "model.layers.33.input_layernorm.weight": "model-00002-of-00002.safetensors",
496
+ "model.layers.33.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
497
+ "model.layers.33.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
498
+ "model.layers.33.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
499
+ "model.layers.33.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
500
+ "model.layers.33.self_attn.beacon_k_proj.bias": "model-00002-of-00002.safetensors",
501
+ "model.layers.33.self_attn.beacon_k_proj.weight": "model-00002-of-00002.safetensors",
502
+ "model.layers.33.self_attn.beacon_q_proj.bias": "model-00002-of-00002.safetensors",
503
+ "model.layers.33.self_attn.beacon_q_proj.weight": "model-00002-of-00002.safetensors",
504
+ "model.layers.33.self_attn.beacon_v_proj.bias": "model-00002-of-00002.safetensors",
505
+ "model.layers.33.self_attn.beacon_v_proj.weight": "model-00002-of-00002.safetensors",
506
+ "model.layers.33.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
507
+ "model.layers.33.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
508
+ "model.layers.33.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
509
+ "model.layers.33.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
510
+ "model.layers.33.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
511
+ "model.layers.33.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
512
+ "model.layers.33.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
513
+ "model.layers.34.input_layernorm.weight": "model-00002-of-00002.safetensors",
514
+ "model.layers.34.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
515
+ "model.layers.34.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
516
+ "model.layers.34.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
517
+ "model.layers.34.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
518
+ "model.layers.34.self_attn.beacon_k_proj.bias": "model-00002-of-00002.safetensors",
519
+ "model.layers.34.self_attn.beacon_k_proj.weight": "model-00002-of-00002.safetensors",
520
+ "model.layers.34.self_attn.beacon_q_proj.bias": "model-00002-of-00002.safetensors",
521
+ "model.layers.34.self_attn.beacon_q_proj.weight": "model-00002-of-00002.safetensors",
522
+ "model.layers.34.self_attn.beacon_v_proj.bias": "model-00002-of-00002.safetensors",
523
+ "model.layers.34.self_attn.beacon_v_proj.weight": "model-00002-of-00002.safetensors",
524
+ "model.layers.34.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
525
+ "model.layers.34.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
526
+ "model.layers.34.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
527
+ "model.layers.34.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
528
+ "model.layers.34.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
529
+ "model.layers.34.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
530
+ "model.layers.34.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
531
+ "model.layers.35.input_layernorm.weight": "model-00002-of-00002.safetensors",
532
+ "model.layers.35.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
533
+ "model.layers.35.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
534
+ "model.layers.35.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
535
+ "model.layers.35.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
536
+ "model.layers.35.self_attn.beacon_k_proj.bias": "model-00002-of-00002.safetensors",
537
+ "model.layers.35.self_attn.beacon_k_proj.weight": "model-00002-of-00002.safetensors",
538
+ "model.layers.35.self_attn.beacon_q_proj.bias": "model-00002-of-00002.safetensors",
539
+ "model.layers.35.self_attn.beacon_q_proj.weight": "model-00002-of-00002.safetensors",
540
+ "model.layers.35.self_attn.beacon_v_proj.bias": "model-00002-of-00002.safetensors",
541
+ "model.layers.35.self_attn.beacon_v_proj.weight": "model-00002-of-00002.safetensors",
542
+ "model.layers.35.self_attn.k_proj.bias": "model-00002-of-00002.safetensors",
543
+ "model.layers.35.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
544
+ "model.layers.35.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
545
+ "model.layers.35.self_attn.q_proj.bias": "model-00002-of-00002.safetensors",
546
+ "model.layers.35.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
547
+ "model.layers.35.self_attn.v_proj.bias": "model-00002-of-00002.safetensors",
548
+ "model.layers.35.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
549
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
550
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
551
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
552
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
553
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
554
+ "model.layers.4.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
555
+ "model.layers.4.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
556
+ "model.layers.4.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
557
+ "model.layers.4.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
558
+ "model.layers.4.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
559
+ "model.layers.4.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
560
+ "model.layers.4.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
561
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
562
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
563
+ "model.layers.4.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
564
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
565
+ "model.layers.4.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
566
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
567
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
568
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
569
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
570
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
571
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
572
+ "model.layers.5.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
573
+ "model.layers.5.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
574
+ "model.layers.5.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
575
+ "model.layers.5.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
576
+ "model.layers.5.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
577
+ "model.layers.5.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
578
+ "model.layers.5.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
579
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
580
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
581
+ "model.layers.5.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
582
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
583
+ "model.layers.5.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
584
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
585
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
586
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
587
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
588
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
589
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
590
+ "model.layers.6.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
591
+ "model.layers.6.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
592
+ "model.layers.6.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
593
+ "model.layers.6.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
594
+ "model.layers.6.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
595
+ "model.layers.6.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
596
+ "model.layers.6.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
597
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
598
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
599
+ "model.layers.6.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
600
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
601
+ "model.layers.6.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
602
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
603
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
604
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
605
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
606
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
607
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
608
+ "model.layers.7.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
609
+ "model.layers.7.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
610
+ "model.layers.7.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
611
+ "model.layers.7.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
612
+ "model.layers.7.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
613
+ "model.layers.7.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
614
+ "model.layers.7.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
615
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
616
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
617
+ "model.layers.7.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
618
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
619
+ "model.layers.7.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
620
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
621
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
622
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
623
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
624
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
625
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
626
+ "model.layers.8.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
627
+ "model.layers.8.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
628
+ "model.layers.8.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
629
+ "model.layers.8.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
630
+ "model.layers.8.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
631
+ "model.layers.8.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
632
+ "model.layers.8.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
633
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
634
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
635
+ "model.layers.8.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
636
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
637
+ "model.layers.8.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
638
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
639
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
640
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
641
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
642
+ "model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
643
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
644
+ "model.layers.9.self_attn.beacon_k_proj.bias": "model-00001-of-00002.safetensors",
645
+ "model.layers.9.self_attn.beacon_k_proj.weight": "model-00001-of-00002.safetensors",
646
+ "model.layers.9.self_attn.beacon_q_proj.bias": "model-00001-of-00002.safetensors",
647
+ "model.layers.9.self_attn.beacon_q_proj.weight": "model-00001-of-00002.safetensors",
648
+ "model.layers.9.self_attn.beacon_v_proj.bias": "model-00001-of-00002.safetensors",
649
+ "model.layers.9.self_attn.beacon_v_proj.weight": "model-00001-of-00002.safetensors",
650
+ "model.layers.9.self_attn.k_proj.bias": "model-00001-of-00002.safetensors",
651
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
652
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
653
+ "model.layers.9.self_attn.q_proj.bias": "model-00001-of-00002.safetensors",
654
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
655
+ "model.layers.9.self_attn.v_proj.bias": "model-00001-of-00002.safetensors",
656
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
657
+ "model.norm.weight": "model-00002-of-00002.safetensors"
658
+ }
659
+ }
model_args.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"model_cache_dir": null, "dataset_cache_dir": null, "data_root": "/share/peitian/Data/Datasets/long-llm", "train_data": ["/share/peitian/Data/Datasets/long-llm/gpt/one_detail_book.train.16K.json", "/share/peitian/Data/Datasets/long-llm/gpt/one_detail_paper.train.16K.json", "/share/peitian/Data/Datasets/long-llm/longalpaca/train.json", "/share/peitian/Data/Datasets/long-llm/booksum/train.16K.json", "/share/peitian/Data/Datasets/long-llm/redpajama/train.json[5000]", "/share/qhj/rags/data/long_context/train/0830.all.30k.jsonl"], "eval_data": null, "model_name_or_path": "/share/qhj/FlagEmbedding/research/Long_LLM/activation_beacon/data/outputs/beacon-qwen2.5-3B-full_coverage-interleave-2048_2048-8,16,32,64,128-step_random-qkv-redpajama/checkpoint-11432", "padding_side": "left", "no_use_fast": false, "access_token": null, "attn_impl": "flash_attention_2", "max_length": 40000, "chat_template": "qwen", "max_position_embeddings": null, "mistral_sliding_window": null, "rope_theta": null, "rope_method": null, "rope_factor": 1.0, "lora": null, "lora_unload": true, "load_in_4_bit": false, "dtype": "bf16", "device_map": null, "batch_size": 1, "cpu": false, "enable_tp": false, "enable_vllm": false, "vllm_mem": 0.9, "vllm_tp": 1, "vllm_len": null, "vllm_disable_ar": false, "enable_beacon": true, "beacon_window": 2048, "beacon_stride": 2048, "beacon_attn": "full-coverage", "beacon_ratio": [8, 16, 32, 64, 128], "beacon_ratio_mix": "step-random", "beacon_param": ["q", "k", "v"], "beacon_embed_init": "eos", "beacon_sink_size": 0, "beacon_attend_prev": true, "beacon_pos": "interleave", "beacon_parallel_window": null, "max_new_tokens": null, "do_sample": null, "temperature": null, "top_p": null}
modeling_beacon.py ADDED
@@ -0,0 +1,1143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_qwen2.py ADDED
@@ -0,0 +1,1309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ """ PyTorch Qwen2 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_qwen2 import Qwen2Config
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
+
61
+ _CHECKPOINT_FOR_DOC = "Qwen/Qwen2-7B-beta"
62
+ _CONFIG_FOR_DOC = "Qwen2Config"
63
+
64
+ QWEN2_PRETRAINED_MODEL_ARCHIVE_LIST = [
65
+ "Qwen/Qwen2-7B-beta",
66
+ # See all Qwen2 models at https://huggingface.co/models?filter=qwen2
67
+ ]
68
+
69
+
70
+ # Copied from transformers.models.llama.modeling_llama._get_unpad_data
71
+ def _get_unpad_data(attention_mask):
72
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
73
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
74
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
75
+ cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.int32), (1, 0))
76
+ return (
77
+ indices,
78
+ cu_seqlens,
79
+ max_seqlen_in_batch,
80
+ )
81
+
82
+
83
+ # Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->Qwen2
84
+ class Qwen2RMSNorm(nn.Module):
85
+ def __init__(self, hidden_size, eps=1e-6):
86
+ """
87
+ Qwen2RMSNorm is equivalent to T5LayerNorm
88
+ """
89
+ super().__init__()
90
+ self.weight = nn.Parameter(torch.ones(hidden_size))
91
+ self.variance_epsilon = eps
92
+
93
+ def forward(self, hidden_states):
94
+ input_dtype = hidden_states.dtype
95
+ hidden_states = hidden_states.to(torch.float32)
96
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
97
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
98
+ return self.weight * hidden_states.to(input_dtype)
99
+
100
+
101
+ # Copied from transformers.models.mistral.modeling_mistral.Qwen2MLP with Qwen2->Qwen2
102
+ class Qwen2MLP(nn.Module):
103
+ def __init__(self, config):
104
+ super().__init__()
105
+ self.config = config
106
+ self.hidden_size = config.hidden_size
107
+ self.intermediate_size = config.intermediate_size
108
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
109
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
110
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
111
+ self.act_fn = ACT2FN[config.hidden_act]
112
+
113
+ def forward(self, x):
114
+ down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
115
+ return down_proj
116
+
117
+
118
+ # Copied from transformers.models.llama.modeling_llama.repeat_kv
119
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
120
+ """
121
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
122
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
123
+ """
124
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
125
+ if n_rep == 1:
126
+ return hidden_states
127
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
128
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
129
+
130
+
131
+ class Qwen2Attention(nn.Module):
132
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
133
+
134
+ def __init__(self, config: Qwen2Config, layer_idx: Optional[int] = None):
135
+ super().__init__()
136
+ self.config = config
137
+ self.layer_idx = layer_idx
138
+ if layer_idx is None:
139
+ logger.warning_once(
140
+ f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
141
+ "to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
142
+ "when creating this class."
143
+ )
144
+
145
+ self.attention_dropout = config.attention_dropout
146
+ self.hidden_size = config.hidden_size
147
+ self.num_heads = config.num_attention_heads
148
+ self.head_dim = self.hidden_size // self.num_heads
149
+ self.num_key_value_heads = config.num_key_value_heads
150
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
151
+ self.max_position_embeddings = config.max_position_embeddings
152
+ self.rope_theta = config.rope_theta
153
+ self.is_causal = True
154
+
155
+ if (self.head_dim * self.num_heads) != self.hidden_size:
156
+ raise ValueError(
157
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
158
+ f" and `num_heads`: {self.num_heads})."
159
+ )
160
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=True)
161
+ self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
162
+ self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
163
+ self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
164
+
165
+ self.rotary_emb = get_rope(self.head_dim, config.rope_theta, config.max_position_embeddings, getattr(config, "rope_scaling", None))
166
+
167
+ # NOTE: add extra parameters for beacon tokens
168
+ # skip post initialization to speed up loading
169
+ if "q" in config.beacon_param:
170
+ self.beacon_q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=self.q_proj.bias is not None)
171
+ # NOTE: initialize the beacon parameters as zero
172
+ self.beacon_q_proj.weight.data.zero_()
173
+ self.beacon_q_proj._is_hf_initialized = True
174
+ if "k" in config.beacon_param:
175
+ 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)
176
+ self.beacon_k_proj.weight.data.zero_()
177
+ self.beacon_k_proj._is_hf_initialized = True
178
+ if "v" in config.beacon_param:
179
+ 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)
180
+ self.beacon_v_proj.weight.data.zero_()
181
+ self.beacon_v_proj._is_hf_initialized = True
182
+ if "o" in config.beacon_param:
183
+ self.beacon_o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=self.o_proj.bias is not None)
184
+ self.beacon_o_proj.weight.data.zero_()
185
+ self.beacon_o_proj._is_hf_initialized = True
186
+
187
+ def _init_beacon_proj(self, missing_keys):
188
+ """Initialize the beacon projection weight with that of the ordinal projection."""
189
+ beacon_param = self.config.beacon_param
190
+
191
+ if is_deepspeed_zero3_enabled():
192
+ # FIXME: after deepspeed initialization, some weights becomes non-zero
193
+ # For Mistral, there are rows that are full of zeros
194
+ # For Mistral, there are values bigger than 1e29...
195
+
196
+ import deepspeed
197
+ if "q" in beacon_param:
198
+ params = [self.beacon_q_proj.weight, self.q_proj.weight]
199
+ if self.q_proj.bias is not None:
200
+ params.extend([self.beacon_q_proj.bias, self.q_proj.bias])
201
+ with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
202
+ # FIXME: after deepspeed initialization, some weights becomes non-zero, but there are rows that are full of zeros
203
+ if (self.beacon_q_proj.weight.sum(-1) == 0).any() or (self.beacon_q_proj.weight > 1e29).any():
204
+ self.beacon_q_proj.weight.data[:] = self.q_proj.weight.data
205
+ if self.q_proj.bias is not None:
206
+ self.beacon_q_proj.bias.data[:] = self.q_proj.bias.data
207
+ if "k" in beacon_param:
208
+ params = [self.beacon_k_proj.weight, self.k_proj.weight]
209
+ if self.k_proj.bias is not None:
210
+ params.extend([self.beacon_k_proj.bias, self.k_proj.bias])
211
+ with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
212
+ # FIXME: after deepspeed initialization, some weights becomes non-zero, but there are rows that are full of zeros
213
+ if (self.beacon_k_proj.weight.sum(-1) == 0).any() or (self.beacon_k_proj.weight > 1e29).any():
214
+ self.beacon_k_proj.weight.data[:] = self.k_proj.weight.data
215
+ if self.k_proj.bias is not None:
216
+ self.beacon_k_proj.bias.data[:] = self.k_proj.bias.data
217
+ if "v" in beacon_param:
218
+ params = [self.beacon_v_proj.weight, self.v_proj.weight]
219
+ if self.v_proj.bias is not None:
220
+ params.extend([self.beacon_v_proj.bias, self.v_proj.bias])
221
+ with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
222
+ # FIXME: after deepspeed initialization, some weights becomes non-zero, but there are rows that are full of zeros
223
+ if (self.beacon_v_proj.weight.sum(-1) == 0).any() or (self.beacon_v_proj.weight > 1e29).any():
224
+ self.beacon_v_proj.weight.data[:] = self.v_proj.weight.data
225
+ if self.v_proj.bias is not None:
226
+ self.beacon_v_proj.bias.data[:] = self.v_proj.bias.data
227
+ if "o" in beacon_param:
228
+ params = [self.beacon_o_proj.weight, self.o_proj.weight]
229
+ if self.o_proj.bias is not None:
230
+ params.extend([self.beacon_o_proj.bias, self.o_proj.bias])
231
+ with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
232
+ # FIXME: after deepspeed initialization, some weights becomes non-zero, but there are rows that are full of zeros
233
+ if (self.beacon_o_proj.weight.sum(-1) == 0).any() or (self.beacon_o_proj.weight > 1e29).any():
234
+ self.beacon_o_proj.weight.data[:] = self.o_proj.weight.data
235
+ if self.o_proj.bias is not None:
236
+ self.beacon_o_proj.bias.data[:] = self.o_proj.bias.data
237
+ else:
238
+ # only copy the value in-place, without tieing the weight
239
+ if "q" in beacon_param and any("beacon_q_proj" in missing_key for missing_key in missing_keys):
240
+ # FIXME: some beacon weights are not initialized as zero for mistral model, why?
241
+ # if (self.beacon_q_proj.weight == 0).all():
242
+ self.beacon_q_proj.weight.data[:] = self.q_proj.weight.data
243
+ if self.q_proj.bias is not None:
244
+ self.beacon_q_proj.bias.data[:] = self.q_proj.bias.data
245
+ if "k" in beacon_param and any("beacon_k_proj" in missing_key for missing_key in missing_keys):
246
+ # if (self.beacon_k_proj.weight == 0).all():
247
+ self.beacon_k_proj.weight.data[:] = self.k_proj.weight.data
248
+ if self.k_proj.bias is not None:
249
+ self.beacon_k_proj.bias.data[:] = self.k_proj.bias.data
250
+ if "v" in beacon_param and any("beacon_v_proj" in missing_key for missing_key in missing_keys):
251
+ # if (self.beacon_v_proj.weight == 0).all():
252
+ self.beacon_v_proj.weight.data[:] = self.v_proj.weight.data
253
+ if self.v_proj.bias is not None:
254
+ self.beacon_v_proj.bias.data[:] = self.v_proj.bias.data
255
+ if "o" in beacon_param and any("beacon_o_proj" in missing_key for missing_key in missing_keys):
256
+ # if (self.beacon_o_proj.weight == 0).all():
257
+ self.beacon_o_proj.weight.data[:] = self.o_proj.weight.data
258
+ if self.o_proj.bias is not None:
259
+ self.beacon_o_proj.bias.data[:] = self.o_proj.bias.data
260
+
261
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
262
+ return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
263
+
264
+ def qkv_proj_with_beacon(self, hidden_states, beacon_size, beacon_indices):
265
+ if beacon_size > 0:
266
+ # 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
267
+ cur_beacon_indices = beacon_indices[-hidden_states.shape[1]:]
268
+
269
+ # NOTE: there is slight redundant computation because ordinal tokens should never be projected by beacon matrices, but we are doing this for efficiency
270
+ if "q" in self.config.beacon_param:
271
+ ordinal_query_states = self.q_proj(hidden_states)
272
+ beacon_query_states = self.beacon_q_proj(hidden_states)
273
+ query_states = torch.where((cur_beacon_indices == 0)[:, None], ordinal_query_states, beacon_query_states)
274
+ if (cur_beacon_indices == 2).any():
275
+ # beacon_indices == 2 means the beacon token is used to replicate the ones in previous window for parallel encoding
276
+ # we should slice out all beacon tokens then copy them to the replicate beacon tokens
277
+ query_states[:, cur_beacon_indices == 2] = beacon_query_states[:, cur_beacon_indices == 1][:, :(cur_beacon_indices == 2).sum()]
278
+ else:
279
+ query_states = self.q_proj(hidden_states)
280
+
281
+ if "k" in self.config.beacon_param:
282
+ ordinal_key_states = self.k_proj(hidden_states)
283
+ beacon_key_states = self.beacon_k_proj(hidden_states)
284
+ key_states = torch.where((cur_beacon_indices == 0)[:, None], ordinal_key_states, beacon_key_states)
285
+ if (cur_beacon_indices == 2).any():
286
+ # beacon_indices == 2 means the beacon token is used to replicate the ones in previous window for parallel encoding
287
+ # we should slice out all beacon tokens then copy them to the replicate beacon tokens
288
+ key_states[:, cur_beacon_indices == 2] = beacon_key_states[:, cur_beacon_indices == 1][:, :(cur_beacon_indices == 2).sum()]
289
+ else:
290
+ key_states = self.k_proj(hidden_states)
291
+
292
+ if "v" in self.config.beacon_param:
293
+ ordinal_value_states = self.v_proj(hidden_states)
294
+ beacon_value_states = self.beacon_v_proj(hidden_states)
295
+ value_states = torch.where((cur_beacon_indices == 0)[:, None], ordinal_value_states, beacon_value_states)
296
+ if (cur_beacon_indices == 2).any():
297
+ # beacon_indices == 2 means the beacon token is used to replicate the ones in previous window for parallel encoding
298
+ # we should slice out all beacon tokens then copy them to the replicate beacon tokens
299
+ value_states[:, cur_beacon_indices == 2] = beacon_value_states[:, cur_beacon_indices == 1][:, :(cur_beacon_indices == 2).sum()]
300
+ else:
301
+ value_states = self.v_proj(hidden_states)
302
+
303
+ else:
304
+ query_states = self.q_proj(hidden_states)
305
+ key_states = self.k_proj(hidden_states)
306
+ value_states = self.v_proj(hidden_states)
307
+
308
+ return query_states, key_states, value_states
309
+
310
+ def o_proj_with_beacon(self, attn_output, beacon_size, beacon_indices):
311
+ if beacon_size > 0:
312
+ # 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
313
+ cur_beacon_indices = beacon_indices[-attn_output.shape[1]:]
314
+
315
+ if "o" in self.config.beacon_param:
316
+ ordinal_attn_output = self.o_proj(attn_output)
317
+ beacon_attn_output = self.beacon_o_proj(attn_output)
318
+ attn_output = torch.where((cur_beacon_indices == 0)[:, None], ordinal_attn_output, beacon_attn_output)
319
+ else:
320
+ attn_output = self.o_proj(attn_output)
321
+ else:
322
+ attn_output = self.o_proj(attn_output)
323
+ return attn_output
324
+
325
+ def forward(
326
+ self,
327
+ hidden_states: torch.Tensor,
328
+ attention_mask: Optional[torch.Tensor] = None,
329
+ position_ids: Optional[torch.LongTensor] = None,
330
+ past_key_value: Optional[Cache] = None,
331
+ output_attentions: bool = False,
332
+ use_cache: bool = False,
333
+ **kwargs,
334
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
335
+ if "padding_mask" in kwargs:
336
+ warnings.warn(
337
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
338
+ )
339
+
340
+ bsz, q_len, _ = hidden_states.size()
341
+ kv_seq_len = hidden_states.shape[-2]
342
+ past_key, past_value, beacon_size, beacon_indices = past_key_value
343
+
344
+ if past_key is not None:
345
+ past_seq_len = past_key.shape[2]
346
+ kv_seq_len += past_seq_len
347
+ else:
348
+ past_seq_len = 0
349
+
350
+ query_states, key_states, value_states = self.qkv_proj_with_beacon(hidden_states, beacon_size, beacon_indices)
351
+
352
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
353
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
354
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
355
+
356
+ # return keys and values before rope
357
+ # NOTE: incrementally return keys and values for efficiency
358
+ past_key_value = (key_states, value_states, beacon_size, beacon_indices)
359
+
360
+ if past_key is not None:
361
+ # reuse k, v, self_attention
362
+ key_states = torch.cat([past_key, key_states], dim=2)
363
+ value_states = torch.cat([past_value, value_states], dim=2)
364
+
365
+ query_states, key_states = self.rotary_emb(query_states, key_states, position_ids)
366
+
367
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
368
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
369
+
370
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
371
+
372
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
373
+ raise ValueError(
374
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
375
+ f" {attn_weights.size()}"
376
+ )
377
+
378
+ if attention_mask is not None:
379
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
380
+ raise ValueError(
381
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
382
+ )
383
+ attn_weights = attn_weights + attention_mask
384
+
385
+ # upcast attention to fp32
386
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
387
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
388
+ attn_output = torch.matmul(attn_weights, value_states)
389
+
390
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
391
+ raise ValueError(
392
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
393
+ f" {attn_output.size()}"
394
+ )
395
+
396
+ attn_output = attn_output.transpose(1, 2).contiguous()
397
+
398
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
399
+
400
+ attn_output = self.o_proj_with_beacon(attn_output, beacon_size, beacon_indices)
401
+
402
+ if not output_attentions:
403
+ attn_weights = None
404
+
405
+ return attn_output, attn_weights, past_key_value
406
+
407
+
408
+ class Qwen2SdpaAttention(Qwen2Attention):
409
+ """
410
+ Qwen2 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
411
+ `Qwen2Attention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
412
+ SDPA API.
413
+ """
414
+
415
+ # Adapted from Qwen2Attention.forward
416
+ def forward(
417
+ self,
418
+ hidden_states: torch.Tensor,
419
+ attention_mask: Optional[torch.Tensor] = None,
420
+ position_ids: Optional[torch.LongTensor] = None,
421
+ past_key_value: Optional[Cache] = None,
422
+ output_attentions: bool = False,
423
+ use_cache: bool = False,
424
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
425
+ if output_attentions:
426
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
427
+ logger.warning_once(
428
+ "Qwen2Model is using Qwen2SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
429
+ '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.'
430
+ )
431
+ return super().forward(
432
+ hidden_states=hidden_states,
433
+ attention_mask=attention_mask,
434
+ position_ids=position_ids,
435
+ past_key_value=past_key_value,
436
+ output_attentions=output_attentions,
437
+ use_cache=use_cache,
438
+ )
439
+ bsz, q_len, _ = hidden_states.size()
440
+ kv_seq_len = hidden_states.shape[-2]
441
+ past_key, past_value, beacon_size, beacon_indices = past_key_value
442
+ if past_key is not None:
443
+ past_seq_len = past_key.shape[2]
444
+ kv_seq_len += past_seq_len
445
+ else:
446
+ past_seq_len = 0
447
+
448
+ query_states, key_states, value_states = self.qkv_proj_with_beacon(hidden_states, beacon_size, beacon_indices)
449
+
450
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
451
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
452
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
453
+
454
+ # return keys and values before rope
455
+ # NOTE: incrementally return keys and values for efficiency
456
+ past_key_value = (key_states, value_states, beacon_size, beacon_indices)
457
+
458
+ if past_key is not None:
459
+ # reuse k, v, self_attention
460
+ key_states = torch.cat([past_key, key_states], dim=2)
461
+ value_states = torch.cat([past_value, value_states], dim=2)
462
+
463
+ query_states, key_states = self.rotary_emb(query_states, key_states, position_ids)
464
+
465
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
466
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
467
+
468
+ if attention_mask is not None:
469
+ if attention_mask.size() != (bsz, 1, q_len, kv_seq_len):
470
+ raise ValueError(
471
+ f"Attention mask should be of size {(bsz, 1, q_len, kv_seq_len)}, but is {attention_mask.size()}"
472
+ )
473
+
474
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
475
+ # Reference: https://github.com/pytorch/pytorch/issues/112577.
476
+ if query_states.device.type == "cuda" and attention_mask is not None:
477
+ query_states = query_states.contiguous()
478
+ key_states = key_states.contiguous()
479
+ value_states = value_states.contiguous()
480
+
481
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
482
+ query_states,
483
+ key_states,
484
+ value_states,
485
+ attn_mask=attention_mask,
486
+ dropout_p=self.attention_dropout if self.training else 0.0,
487
+ # 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.
488
+ is_causal=self.is_causal and attention_mask is None and q_len > 1,
489
+ )
490
+
491
+ attn_output = attn_output.transpose(1, 2).contiguous()
492
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
493
+ attn_output = self.o_proj_with_beacon(attn_output, beacon_size, beacon_indices)
494
+
495
+ return attn_output, None, past_key_value
496
+
497
+
498
+ class Qwen2FlashAttention2(Qwen2Attention):
499
+ """
500
+ Qwen2 flash attention module. This module inherits from `Qwen2Attention` as the weights of the module stays
501
+ untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
502
+ flash attention and deal with padding tokens in case the input contains any of them.
503
+ """
504
+
505
+ def __init__(self, *args, **kwargs):
506
+ super().__init__(*args, **kwargs)
507
+
508
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
509
+ # 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.
510
+ # 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).
511
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
512
+
513
+ def forward(
514
+ self,
515
+ hidden_states: torch.Tensor,
516
+ attention_mask: Optional[torch.LongTensor] = None,
517
+ position_ids: Optional[torch.LongTensor] = None,
518
+ past_key_value: Optional[Cache] = None,
519
+ output_attentions: bool = False,
520
+ use_cache: bool = False,
521
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
522
+ output_attentions = False
523
+
524
+ bsz, q_len, _ = hidden_states.size()
525
+ kv_seq_len = hidden_states.shape[-2]
526
+
527
+ past_key, past_value, beacon_size, beacon_indices = past_key_value
528
+ if past_key is not None:
529
+ past_seq_len = past_key.shape[2]
530
+ kv_seq_len += past_seq_len
531
+ else:
532
+ past_seq_len = 0
533
+
534
+ query_states, key_states, value_states = self.qkv_proj_with_beacon(hidden_states, beacon_size, beacon_indices)
535
+
536
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
537
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
538
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
539
+
540
+ # return keys and values before rope
541
+ # NOTE: incrementally return keys and values for efficiency
542
+ past_key_value = (key_states, value_states, beacon_size, beacon_indices)
543
+
544
+ if past_key is not None:
545
+ # reuse k, v, self_attention
546
+ key_states = torch.cat([past_key, key_states], dim=2)
547
+ value_states = torch.cat([past_value, value_states], dim=2)
548
+
549
+ query_states, key_states = self.rotary_emb(query_states, key_states, position_ids)
550
+
551
+ # FlashAttention will automatically handle grouped query attention
552
+ # key_states = repeat_kv(key_states, self.num_key_value_groups)
553
+ # value_states = repeat_kv(value_states, self.num_key_value_groups)
554
+
555
+ # 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
556
+ # to be able to avoid many of these transpose/reshape/view.
557
+ query_states = query_states.transpose(1, 2)
558
+ key_states = key_states.transpose(1, 2)
559
+ value_states = value_states.transpose(1, 2)
560
+
561
+ dropout_rate = self.attention_dropout if self.training else 0.0
562
+
563
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
564
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
565
+ # cast them back in the correct dtype just to be sure everything works as expected.
566
+ # This might slowdown training & inference so it is recommended to not cast the LayerNorms
567
+ # in fp32. (Qwen2RMSNorm handles it correctly)
568
+
569
+ input_dtype = query_states.dtype
570
+ if input_dtype == torch.float32:
571
+ if torch.is_autocast_enabled():
572
+ target_dtype = torch.get_autocast_gpu_dtype()
573
+ # Handle the case where the model is quantized
574
+ elif hasattr(self.config, "_pre_quantization_dtype"):
575
+ target_dtype = self.config._pre_quantization_dtype
576
+ else:
577
+ target_dtype = self.q_proj.weight.dtype
578
+
579
+ logger.warning_once(
580
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
581
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
582
+ f" {target_dtype}."
583
+ )
584
+
585
+ query_states = query_states.to(target_dtype)
586
+ key_states = key_states.to(target_dtype)
587
+ value_states = value_states.to(target_dtype)
588
+
589
+ attn_output = self._flash_attention_forward(
590
+ query_states,
591
+ key_states,
592
+ value_states,
593
+ attention_mask,
594
+ q_len,
595
+ dropout=dropout_rate
596
+ )
597
+
598
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
599
+ attn_output = self.o_proj_with_beacon(attn_output, beacon_size, beacon_indices)
600
+
601
+ if not output_attentions:
602
+ attn_weights = None
603
+
604
+ return attn_output, attn_weights, past_key_value
605
+
606
+ def _flash_attention_forward(
607
+ self, query_states, key_states, value_states, attention_mask, query_length, dropout=0.0, softmax_scale=None
608
+ ):
609
+ """
610
+ Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token
611
+ first unpad the input, then computes the attention scores and pad the final attention scores.
612
+
613
+ Args:
614
+ query_states (`torch.Tensor`):
615
+ Input query states to be passed to Flash Attention API
616
+ key_states (`torch.Tensor`):
617
+ Input key states to be passed to Flash Attention API
618
+ value_states (`torch.Tensor`):
619
+ Input value states to be passed to Flash Attention API
620
+ attention_mask (`torch.Tensor`):
621
+ The padding mask - corresponds to a tensor of size `(batch_size, seq_len)` where 0 stands for the
622
+ position of padding tokens and 1 for the position of non-padding tokens.
623
+ dropout (`float`):
624
+ Attention dropout
625
+ softmax_scale (`float`, *optional*):
626
+ The scaling of QK^T before applying softmax. Default to 1 / sqrt(head_dim)
627
+ """
628
+ if not self._flash_attn_uses_top_left_mask:
629
+ causal = self.is_causal
630
+ else:
631
+ # TODO: Remove the `query_length != 1` check once Flash Attention for RoCm is bumped to 2.1. For details, please see the comment in Qwen2FlashAttention2 __init__.
632
+ causal = self.is_causal and query_length != 1
633
+
634
+ # Contains at least one padding token in the sequence
635
+ if attention_mask is not None:
636
+ batch_size = query_states.shape[0]
637
+ query_states, key_states, value_states, indices_q, cu_seq_lens, max_seq_lens = self._upad_input(
638
+ query_states, key_states, value_states, attention_mask, query_length
639
+ )
640
+
641
+ cu_seqlens_q, cu_seqlens_k = cu_seq_lens
642
+ max_seqlen_in_batch_q, max_seqlen_in_batch_k = max_seq_lens
643
+
644
+ attn_output_unpad = flash_attn_varlen_func(
645
+ query_states,
646
+ key_states,
647
+ value_states,
648
+ cu_seqlens_q=cu_seqlens_q,
649
+ cu_seqlens_k=cu_seqlens_k,
650
+ max_seqlen_q=max_seqlen_in_batch_q,
651
+ max_seqlen_k=max_seqlen_in_batch_k,
652
+ dropout_p=dropout,
653
+ softmax_scale=softmax_scale,
654
+ causal=causal,
655
+ )
656
+
657
+ attn_output = pad_input(attn_output_unpad, indices_q, batch_size, query_length)
658
+ else:
659
+ attn_output = flash_attn_func(
660
+ query_states, key_states, value_states, dropout, softmax_scale=softmax_scale, causal=causal
661
+ )
662
+
663
+ return attn_output
664
+
665
+ def _upad_input(self, query_layer, key_layer, value_layer, attention_mask, query_length):
666
+ indices_k, cu_seqlens_k, max_seqlen_in_batch_k = _get_unpad_data(attention_mask)
667
+ batch_size, kv_seq_len, num_key_value_heads, head_dim = key_layer.shape
668
+
669
+ key_layer = index_first_axis(
670
+ key_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
671
+ )
672
+ value_layer = index_first_axis(
673
+ value_layer.reshape(batch_size * kv_seq_len, num_key_value_heads, head_dim), indices_k
674
+ )
675
+ if query_length == kv_seq_len:
676
+ query_layer = index_first_axis(
677
+ query_layer.reshape(batch_size * kv_seq_len, self.num_heads, head_dim), indices_k
678
+ )
679
+ cu_seqlens_q = cu_seqlens_k
680
+ max_seqlen_in_batch_q = max_seqlen_in_batch_k
681
+ indices_q = indices_k
682
+ elif query_length == 1:
683
+ max_seqlen_in_batch_q = 1
684
+ cu_seqlens_q = torch.arange(
685
+ batch_size + 1, dtype=torch.int32, device=query_layer.device
686
+ ) # There is a memcpy here, that is very bad.
687
+ indices_q = cu_seqlens_q[:-1]
688
+ query_layer = query_layer.squeeze(1)
689
+ else:
690
+ # The -q_len: slice assumes left padding.
691
+ attention_mask = attention_mask[:, -query_length:]
692
+ query_layer, indices_q, cu_seqlens_q, max_seqlen_in_batch_q = unpad_input(query_layer, attention_mask)
693
+
694
+ return (
695
+ query_layer,
696
+ key_layer,
697
+ value_layer,
698
+ indices_q,
699
+ (cu_seqlens_q, cu_seqlens_k),
700
+ (max_seqlen_in_batch_q, max_seqlen_in_batch_k),
701
+ )
702
+
703
+
704
+ QWEN2_ATTENTION_CLASSES = {
705
+ "eager": Qwen2Attention,
706
+ "sdpa": Qwen2SdpaAttention,
707
+ "flash_attention_2": Qwen2FlashAttention2,
708
+ }
709
+
710
+
711
+ class Qwen2DecoderLayer(nn.Module):
712
+ def __init__(self, config: Qwen2Config, layer_idx: int):
713
+ super().__init__()
714
+ self.hidden_size = config.hidden_size
715
+
716
+ if config.use_sliding_window and config._attn_implementation != "flash_attention_2":
717
+ logger.warning_once(
718
+ f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
719
+ "unexpected results may be encountered."
720
+ )
721
+ self.self_attn = QWEN2_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx)
722
+
723
+ self.mlp = Qwen2MLP(config)
724
+ self.input_layernorm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
725
+ self.post_attention_layernorm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
726
+
727
+ def forward(
728
+ self,
729
+ hidden_states: torch.Tensor,
730
+ attention_mask: Optional[torch.Tensor] = None,
731
+ position_ids: Optional[torch.LongTensor] = None,
732
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
733
+ output_attentions: Optional[bool] = False,
734
+ use_cache: Optional[bool] = False,
735
+ **kwargs,
736
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
737
+ if "padding_mask" in kwargs:
738
+ warnings.warn(
739
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. "
740
+ "Please make sure use `attention_mask` instead.`"
741
+ )
742
+ """
743
+ Args:
744
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
745
+ attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
746
+ `(batch, sequence_length)` where padding elements are indicated by 0.
747
+ output_attentions (`bool`, *optional*):
748
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
749
+ returned tensors for more detail.
750
+ use_cache (`bool`, *optional*):
751
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
752
+ (see `past_key_values`).
753
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
754
+ """
755
+ residual = hidden_states
756
+
757
+ hidden_states = self.input_layernorm(hidden_states)
758
+
759
+ # Self Attention
760
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
761
+ hidden_states=hidden_states,
762
+ attention_mask=attention_mask,
763
+ position_ids=position_ids,
764
+ past_key_value=past_key_value,
765
+ output_attentions=output_attentions,
766
+ use_cache=use_cache,
767
+ )
768
+ hidden_states = residual + hidden_states
769
+
770
+ # Fully Connected
771
+ residual = hidden_states
772
+ hidden_states = self.post_attention_layernorm(hidden_states)
773
+ hidden_states = self.mlp(hidden_states)
774
+ hidden_states = residual + hidden_states
775
+
776
+ outputs = (hidden_states,)
777
+
778
+ if output_attentions:
779
+ outputs += (self_attn_weights,)
780
+
781
+ if use_cache:
782
+ outputs += (present_key_value,)
783
+
784
+ return outputs
785
+
786
+
787
+ QWEN2_START_DOCSTRING = r"""
788
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
789
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
790
+ etc.)
791
+
792
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
793
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
794
+ and behavior.
795
+
796
+ Parameters:
797
+ config ([`Qwen2Config`]):
798
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
799
+ load the weights associated with the model, only the configuration. Check out the
800
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
801
+ """
802
+
803
+
804
+ @add_start_docstrings(
805
+ "The bare Qwen2 Model outputting raw hidden-states without any specific head on top.",
806
+ QWEN2_START_DOCSTRING,
807
+ )
808
+ class Qwen2PreTrainedModel(PreTrainedModel):
809
+ config_class = Qwen2Config
810
+ base_model_prefix = "model"
811
+ supports_gradient_checkpointing = True
812
+ _no_split_modules = ["Qwen2DecoderLayer"]
813
+ _skip_keys_device_placement = "past_key_values"
814
+ _supports_flash_attn_2 = True
815
+ _supports_sdpa = True
816
+ _supports_cache_class = True
817
+
818
+ def _init_weights(self, module):
819
+ std = self.config.initializer_range
820
+ if isinstance(module, nn.Linear):
821
+ module.weight.data.normal_(mean=0.0, std=std)
822
+ if module.bias is not None:
823
+ module.bias.data.zero_()
824
+ elif isinstance(module, nn.Embedding):
825
+ module.weight.data.normal_(mean=0.0, std=std)
826
+ if module.padding_idx is not None:
827
+ module.weight.data[module.padding_idx].zero_()
828
+
829
+
830
+ QWEN2_INPUTS_DOCSTRING = r"""
831
+ Args:
832
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
833
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
834
+ it.
835
+
836
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
837
+ [`PreTrainedTokenizer.__call__`] for details.
838
+
839
+ [What are input IDs?](../glossary#input-ids)
840
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
841
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
842
+
843
+ - 1 for tokens that are **not masked**,
844
+ - 0 for tokens that are **masked**.
845
+
846
+ [What are attention masks?](../glossary#attention-mask)
847
+
848
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
849
+ [`PreTrainedTokenizer.__call__`] for details.
850
+
851
+ If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
852
+ `past_key_values`).
853
+
854
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
855
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
856
+ information on the default strategy.
857
+
858
+ - 1 indicates the head is **not masked**,
859
+ - 0 indicates the head is **masked**.
860
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
861
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
862
+ config.n_positions - 1]`.
863
+
864
+ [What are position IDs?](../glossary#position-ids)
865
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
866
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
867
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
868
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
869
+
870
+ Two formats are allowed:
871
+ - a [`~cache_utils.Cache`] instance;
872
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
873
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
874
+ cache format.
875
+
876
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
877
+ legacy cache format will be returned.
878
+
879
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
880
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
881
+ of shape `(batch_size, sequence_length)`.
882
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
883
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
884
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
885
+ model's internal embedding lookup matrix.
886
+ use_cache (`bool`, *optional*):
887
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
888
+ `past_key_values`).
889
+ output_attentions (`bool`, *optional*):
890
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
891
+ tensors for more detail.
892
+ output_hidden_states (`bool`, *optional*):
893
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
894
+ more detail.
895
+ return_dict (`bool`, *optional*):
896
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
897
+ """
898
+
899
+
900
+ @add_start_docstrings(
901
+ "The bare Qwen2 Model outputting raw hidden-states without any specific head on top.",
902
+ QWEN2_START_DOCSTRING,
903
+ )
904
+ class Qwen2Model(Qwen2PreTrainedModel):
905
+ """
906
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Qwen2DecoderLayer`]
907
+
908
+ Args:
909
+ config: Qwen2Config
910
+ """
911
+
912
+ def __init__(self, config: Qwen2Config):
913
+ super().__init__(config)
914
+ self.padding_idx = config.pad_token_id
915
+ self.vocab_size = config.vocab_size
916
+
917
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
918
+
919
+ # BEACON: add beacon embedding
920
+ self.beacon_embed_tokens = nn.Embedding(1, config.hidden_size, self.padding_idx)
921
+ self.beacon_embed_tokens._is_hf_initialized = True
922
+
923
+ self.layers = nn.ModuleList(
924
+ [Qwen2DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
925
+ )
926
+ self._attn_implementation = config._attn_implementation
927
+ self.norm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
928
+
929
+ self.gradient_checkpointing = False
930
+ # Initialize weights and apply final processing
931
+ self.post_init()
932
+
933
+ def _init_beacon_embed(self, missing_keys):
934
+ """Initialize the beacon token embedding with that of the eos token."""
935
+ if is_deepspeed_zero3_enabled():
936
+ import deepspeed
937
+ params = [self.beacon_embed_tokens.weight, self.embed_tokens.weight]
938
+ with deepspeed.zero.GatheredParameters(params, modifier_rank=0):
939
+ # deepspeed will initialize the parameters to zero
940
+ if (self.beacon_embed_tokens.weight == 0).all():
941
+ if self.config.beacon_embed_init == "bos":
942
+ self.beacon_embed_tokens.weight.data[:] = self.embed_tokens.weight.data[self.config.bos_token_id]
943
+ elif self.config.beacon_embed_init == "eos":
944
+ if isinstance(self.config.eos_token_id, list):
945
+ eos_token_id = self.config.eos_token_id[0]
946
+ else:
947
+ eos_token_id = self.config.eos_token_id
948
+ self.beacon_embed_tokens.weight.data[:] = self.embed_tokens.weight.data[eos_token_id]
949
+ else:
950
+ raise NotImplementedError(f"Make sure beacon_embed_init is either eos or bos, found {self.config.beacon_embed_init}")
951
+ else:
952
+ if any("beacon_embed_tokens" in missing_key for missing_key in missing_keys):
953
+ if self.config.beacon_embed_init == "bos":
954
+ self.beacon_embed_tokens.weight.data[:] = self.embed_tokens.weight.data[self.config.bos_token_id]
955
+ elif self.config.beacon_embed_init == "eos":
956
+ if isinstance(self.config.eos_token_id, list):
957
+ eos_token_id = self.config.eos_token_id[0]
958
+ else:
959
+ eos_token_id = self.config.eos_token_id
960
+ self.beacon_embed_tokens.weight.data[:] = self.embed_tokens.weight.data[eos_token_id]
961
+ else:
962
+ raise NotImplementedError(f"Make sure beacon_embed_init is either eos or bos, found {self.config.beacon_embed_init}")
963
+
964
+ def get_input_embeddings(self):
965
+ return self.embed_tokens
966
+
967
+ def set_input_embeddings(self, value):
968
+ self.embed_tokens = value
969
+
970
+ @add_start_docstrings_to_model_forward(QWEN2_INPUTS_DOCSTRING)
971
+ def forward(
972
+ self,
973
+ input_ids: torch.LongTensor = None,
974
+ attention_mask: Optional[torch.Tensor] = None,
975
+ position_ids: Optional[torch.LongTensor] = None,
976
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
977
+ inputs_embeds: Optional[torch.FloatTensor] = None,
978
+ use_cache: Optional[bool] = None,
979
+ output_attentions: Optional[bool] = None,
980
+ output_hidden_states: Optional[bool] = None,
981
+ return_dict: Optional[bool] = None,
982
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
983
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
984
+ output_hidden_states = (
985
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
986
+ )
987
+ # BEACON: always use cache
988
+ use_cache = True
989
+
990
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
991
+
992
+ # retrieve input_ids and inputs_embeds
993
+ if input_ids is not None and inputs_embeds is not None:
994
+ raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
995
+ elif input_ids is not None:
996
+ batch_size, seq_length = input_ids.shape[:2]
997
+ elif inputs_embeds is not None:
998
+ batch_size, seq_length = inputs_embeds.shape[:2]
999
+ else:
1000
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
1001
+
1002
+ past_key, past_value, beacon_size, beacon_indices = past_key_values[0]
1003
+
1004
+ # BEACON: separately embed ordinal tokens and beacon tokens because ordinal tokens do not receive gradients
1005
+ if beacon_size > 0:
1006
+ # 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
1007
+ cur_beacon_indices = beacon_indices[-input_ids.shape[1]:]
1008
+
1009
+ ordinal_input_ids = input_ids[:, cur_beacon_indices == 0]
1010
+ beacon_input_ids = input_ids[:, cur_beacon_indices > 0]
1011
+ ordinal_inputs_embeds = self.embed_tokens(ordinal_input_ids)
1012
+ beacon_input_embeds = self.beacon_embed_tokens(beacon_input_ids - self.config.vocab_size)
1013
+ # create a new embedding tensor
1014
+ inputs_embeds = beacon_input_embeds.new_zeros(*input_ids.shape, beacon_input_embeds.shape[-1])
1015
+ inputs_embeds[:, cur_beacon_indices == 0] = ordinal_inputs_embeds
1016
+ inputs_embeds[:, cur_beacon_indices > 0] = beacon_input_embeds
1017
+
1018
+ else:
1019
+ inputs_embeds = self.embed_tokens(input_ids)
1020
+
1021
+ # embed positions
1022
+ hidden_states = inputs_embeds
1023
+
1024
+ # print(f"input_ids: {input_ids}")
1025
+ # print(f"beacon_indices: {beacon_indices}")
1026
+ # print(f"position_ids: {position_ids}")
1027
+ # print(f"attention_mask:\n{attention_mask == 0}")
1028
+ # x = input()
1029
+ # if x == "s":
1030
+ # return
1031
+
1032
+ # decoder layers
1033
+ all_hidden_states = () if output_hidden_states else None
1034
+ all_self_attns = () if output_attentions else None
1035
+ # BEACON: still use tuple to organize cache
1036
+ next_decoder_cache = () if use_cache else None
1037
+
1038
+ for idx, decoder_layer in enumerate(self.layers):
1039
+ if output_hidden_states:
1040
+ all_hidden_states += (hidden_states,)
1041
+
1042
+ # BEACON: slice out the past_key_value of the corresponding layer
1043
+ past_key_value = past_key_values[idx] if past_key_values is not None else None
1044
+
1045
+ if self.gradient_checkpointing and self.training:
1046
+ layer_outputs = self._gradient_checkpointing_func(
1047
+ decoder_layer.__call__,
1048
+ hidden_states,
1049
+ attention_mask,
1050
+ position_ids,
1051
+ past_key_value,
1052
+ output_attentions,
1053
+ use_cache,
1054
+ )
1055
+ else:
1056
+ layer_outputs = decoder_layer(
1057
+ hidden_states,
1058
+ attention_mask=attention_mask,
1059
+ position_ids=position_ids,
1060
+ past_key_value=past_key_value,
1061
+ output_attentions=output_attentions,
1062
+ use_cache=use_cache,
1063
+ )
1064
+
1065
+ hidden_states = layer_outputs[0]
1066
+
1067
+ if use_cache:
1068
+ next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
1069
+
1070
+ if output_attentions:
1071
+ all_self_attns += (layer_outputs[1],)
1072
+
1073
+ hidden_states = self.norm(hidden_states)
1074
+
1075
+ # add hidden states from the last decoder layer
1076
+ if output_hidden_states:
1077
+ all_hidden_states += (hidden_states,)
1078
+
1079
+ next_cache = next_decoder_cache if use_cache else None
1080
+
1081
+ if not return_dict:
1082
+ return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
1083
+ return BaseModelOutputWithPast(
1084
+ last_hidden_state=hidden_states,
1085
+ past_key_values=next_cache,
1086
+ hidden_states=all_hidden_states,
1087
+ attentions=all_self_attns,
1088
+ )
1089
+
1090
+
1091
+ class Qwen2ForCausalLM(Qwen2PreTrainedModel):
1092
+ _tied_weights_keys = ["lm_head.weight"]
1093
+
1094
+ def __init__(self, config):
1095
+ super().__init__(config)
1096
+ self.model = Qwen2Model(config)
1097
+ self.vocab_size = config.vocab_size
1098
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
1099
+ # Initialize weights and apply final processing
1100
+ self.post_init()
1101
+
1102
+ def get_input_embeddings(self):
1103
+ return self.model.embed_tokens
1104
+
1105
+ def set_input_embeddings(self, value):
1106
+ self.model.embed_tokens = value
1107
+
1108
+ def get_output_embeddings(self):
1109
+ return self.lm_head
1110
+
1111
+ def set_output_embeddings(self, new_embeddings):
1112
+ self.lm_head = new_embeddings
1113
+
1114
+ def set_decoder(self, decoder):
1115
+ self.model = decoder
1116
+
1117
+ def get_decoder(self):
1118
+ return self.model
1119
+
1120
+ @classmethod
1121
+ def from_pretrained(cls, *args, **kwargs):
1122
+ """Override the default from_pretrained to extend vocab size according to beacon_size."""
1123
+ kwargs.update(output_loading_info=True)
1124
+ model, loading_info = super().from_pretrained(*args, **kwargs)
1125
+
1126
+ # NOTE: set memory after from_pretrained because there may be another transformer model inside the Memory object, which may cause weird erros during loading
1127
+ config = model.config
1128
+ model.memory = Memory(
1129
+ model_config=config,
1130
+ k_seq_dim=2,
1131
+ v_seq_dim=2,
1132
+ )
1133
+
1134
+ missing_keys = loading_info["missing_keys"]
1135
+ # NOTE: the beacon parameters may or may not be loaded from the checkpoint
1136
+ # if it is loaded from the checkpoint, we should not re-initilize it
1137
+ model.model._init_beacon_embed(missing_keys)
1138
+ # initialize weights of possible q,k,v,o,mlp
1139
+ for layer in model.model.layers:
1140
+ layer.self_attn._init_beacon_proj(missing_keys)
1141
+
1142
+ return model
1143
+
1144
+ def _native_forward(
1145
+ self,
1146
+ input_ids: torch.LongTensor = None,
1147
+ attention_mask: Optional[torch.Tensor] = None,
1148
+ position_ids: Optional[torch.LongTensor] = None,
1149
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1150
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1151
+ labels: Optional[torch.LongTensor] = None,
1152
+ use_cache: Optional[bool] = None,
1153
+ output_attentions: Optional[bool] = None,
1154
+ output_hidden_states: Optional[bool] = None,
1155
+ return_dict: Optional[bool] = None,
1156
+ ) -> Union[Tuple, ModelOutput]:
1157
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1158
+ output_hidden_states = (
1159
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1160
+ )
1161
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1162
+
1163
+ # when we directly call _native_forward, the past_key_values would be None
1164
+ if past_key_values is None:
1165
+ # NOTE: set beacon size to 0 to avoid using any beacon parameters, see Qwen2Attention.forward
1166
+ past_key_values = [(None, None, 0, None) for _ in range(self.config.num_hidden_layers)]
1167
+
1168
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1169
+ outputs = self.model(
1170
+ input_ids=input_ids,
1171
+ attention_mask=attention_mask,
1172
+ position_ids=position_ids,
1173
+ past_key_values=past_key_values,
1174
+ inputs_embeds=inputs_embeds,
1175
+ use_cache=use_cache,
1176
+ output_attentions=output_attentions,
1177
+ output_hidden_states=output_hidden_states,
1178
+ return_dict=return_dict,
1179
+ )
1180
+
1181
+ hidden_states = outputs[0]
1182
+ logits = self.lm_head(hidden_states)
1183
+ logits = logits.float()
1184
+
1185
+ loss = None
1186
+ batch_loss = None
1187
+ token_loss = None
1188
+
1189
+ if labels is not None:
1190
+ loss, batch_loss, token_loss = compute_loss(logits, labels, shift=False)
1191
+
1192
+ if not return_dict:
1193
+ output = (logits,) + outputs[1:]
1194
+ return (loss,) + output if loss is not None else output
1195
+
1196
+ return ModelOutput(
1197
+ loss=loss,
1198
+ batch_loss=batch_loss,
1199
+ token_loss=token_loss,
1200
+ logits=logits,
1201
+ past_key_values=outputs.past_key_values,
1202
+ hidden_states=outputs.hidden_states,
1203
+ attentions=outputs.attentions,
1204
+ )
1205
+
1206
+ def _beacon_forward(self,
1207
+ input_ids: torch.LongTensor = None,
1208
+ attention_mask: Optional[torch.Tensor] = None,
1209
+ position_ids: Optional[torch.LongTensor] = None,
1210
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1211
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1212
+ labels: Optional[torch.LongTensor] = None,
1213
+ use_cache: Optional[bool] = None,
1214
+ output_attentions: Optional[bool] = None,
1215
+ output_hidden_states: Optional[bool] = None,
1216
+ return_dict: Optional[bool] = None,
1217
+ beacon_skip_first: Optional[int] = None,
1218
+ beacon_skip_last: Optional[int] = None,
1219
+ ):
1220
+ # t1 = time.time()
1221
+
1222
+ # initialize cache
1223
+ self.memory.prepare(
1224
+ input_ids=input_ids,
1225
+ attention_mask=attention_mask,
1226
+ labels=labels,
1227
+ skip_first=beacon_skip_first,
1228
+ skip_last=beacon_skip_last,
1229
+ )
1230
+
1231
+ # t2 = time.time()
1232
+
1233
+ while not self.memory.finish:
1234
+
1235
+ # t3 = time.time()
1236
+
1237
+ input_ids, attention_mask, position_ids, past_key_values, labels = self.memory.step()
1238
+
1239
+ # t4 = time.time()
1240
+
1241
+ outputs = self._native_forward(
1242
+ input_ids=input_ids,
1243
+ attention_mask=attention_mask,
1244
+ position_ids=position_ids,
1245
+ past_key_values=past_key_values,
1246
+ inputs_embeds=inputs_embeds,
1247
+ use_cache=use_cache,
1248
+ output_attentions=output_attentions,
1249
+ output_hidden_states=output_hidden_states,
1250
+ return_dict=return_dict,
1251
+ labels=labels,
1252
+ )
1253
+
1254
+ # t5 = time.time()
1255
+
1256
+ # update past_key_values
1257
+ self.memory.update_memory(outputs.past_key_values)
1258
+
1259
+ # t6 = time.time()
1260
+
1261
+ if labels is not None:
1262
+ # update loss
1263
+ self.memory.update_loss(outputs.batch_loss, (labels != -100).sum(-1))
1264
+
1265
+ # t7 = time.time()
1266
+
1267
+ # print(f"step time: {t4-t3}, forward time: {t5-t4}, update time: {t6-t5}, loss time: {t7-t6}")
1268
+ # input()
1269
+
1270
+ # t8 = time.time()
1271
+
1272
+ # output loss, past_key_values, and perplexity
1273
+ outputs = self.memory.output(outputs)
1274
+
1275
+ # t9 = time.time()
1276
+
1277
+ # print(f"output time: {t9-t8}")
1278
+ # input()
1279
+
1280
+ return outputs
1281
+
1282
+ def forward(self, **kwargs):
1283
+ """Forward computation over a batch of sequences.
1284
+ """
1285
+ # only allow gradient when training
1286
+ with optional_grad_ctx(with_grad=self.training):
1287
+ # we can disable beacon to use the original mistral
1288
+ if hasattr(self, "_enable_beacon") and self._enable_beacon == False:
1289
+ return self._native_forward(**kwargs)
1290
+ else:
1291
+ return self._beacon_forward(**kwargs)
1292
+
1293
+ def prepare_inputs_for_generation(
1294
+ self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, beacon_skip_first=None, beacon_skip_last=None, **kwargs
1295
+ ):
1296
+ if past_key_values:
1297
+ input_ids = input_ids[:, -1:]
1298
+
1299
+ model_inputs = {"input_ids": input_ids, "beacon_skip_first": beacon_skip_first, "beacon_skip_last": beacon_skip_last}
1300
+ return model_inputs
1301
+
1302
+ @staticmethod
1303
+ def _reorder_cache(past_key_values, beam_idx):
1304
+ reordered_past = ()
1305
+ for layer_past in past_key_values:
1306
+ reordered_past += (
1307
+ tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past),
1308
+ )
1309
+ return reordered_past
modeling_utils.py ADDED
@@ -0,0 +1,711 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "model_max_length": 131072,
203
+ "pad_token": "<|endoftext|>",
204
+ "padding_side": "left",
205
+ "split_special_tokens": false,
206
+ "tokenizer_class": "Qwen2Tokenizer",
207
+ "unk_token": null
208
+ }
trainer_state.json ADDED
@@ -0,0 +1,2616 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 3.0,
5
+ "eval_steps": 500,
6
+ "global_step": 18498,
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.008108984755108661,
13
+ "grad_norm": 1.6712403297424316,
14
+ "learning_rate": 9.980942340442787e-06,
15
+ "loss": 1.5976,
16
+ "step": 50
17
+ },
18
+ {
19
+ "epoch": 0.016217969510217322,
20
+ "grad_norm": 1.9675096273422241,
21
+ "learning_rate": 9.960668234530858e-06,
22
+ "loss": 1.4389,
23
+ "step": 100
24
+ },
25
+ {
26
+ "epoch": 0.02432695426532598,
27
+ "grad_norm": 4.630291938781738,
28
+ "learning_rate": 9.940394128618928e-06,
29
+ "loss": 1.387,
30
+ "step": 150
31
+ },
32
+ {
33
+ "epoch": 0.032435939020434644,
34
+ "grad_norm": 2.186373710632324,
35
+ "learning_rate": 9.920120022707e-06,
36
+ "loss": 1.4025,
37
+ "step": 200
38
+ },
39
+ {
40
+ "epoch": 0.0405449237755433,
41
+ "grad_norm": 1.8459932804107666,
42
+ "learning_rate": 9.89984591679507e-06,
43
+ "loss": 1.3795,
44
+ "step": 250
45
+ },
46
+ {
47
+ "epoch": 0.04865390853065196,
48
+ "grad_norm": 1.8652907609939575,
49
+ "learning_rate": 9.879571810883141e-06,
50
+ "loss": 1.3835,
51
+ "step": 300
52
+ },
53
+ {
54
+ "epoch": 0.056762893285760625,
55
+ "grad_norm": 1.97219979763031,
56
+ "learning_rate": 9.859297704971211e-06,
57
+ "loss": 1.3549,
58
+ "step": 350
59
+ },
60
+ {
61
+ "epoch": 0.06487187804086929,
62
+ "grad_norm": 1.764737844467163,
63
+ "learning_rate": 9.839023599059281e-06,
64
+ "loss": 1.3785,
65
+ "step": 400
66
+ },
67
+ {
68
+ "epoch": 0.07298086279597794,
69
+ "grad_norm": 1.37200927734375,
70
+ "learning_rate": 9.818749493147353e-06,
71
+ "loss": 1.397,
72
+ "step": 450
73
+ },
74
+ {
75
+ "epoch": 0.0810898475510866,
76
+ "grad_norm": 0.783941388130188,
77
+ "learning_rate": 9.798475387235423e-06,
78
+ "loss": 1.4055,
79
+ "step": 500
80
+ },
81
+ {
82
+ "epoch": 0.08919883230619527,
83
+ "grad_norm": 2.4082376956939697,
84
+ "learning_rate": 9.778201281323494e-06,
85
+ "loss": 1.2851,
86
+ "step": 550
87
+ },
88
+ {
89
+ "epoch": 0.09730781706130393,
90
+ "grad_norm": 1.2580335140228271,
91
+ "learning_rate": 9.757927175411566e-06,
92
+ "loss": 1.3557,
93
+ "step": 600
94
+ },
95
+ {
96
+ "epoch": 0.10541680181641258,
97
+ "grad_norm": 1.688684105873108,
98
+ "learning_rate": 9.737653069499636e-06,
99
+ "loss": 1.3462,
100
+ "step": 650
101
+ },
102
+ {
103
+ "epoch": 0.11352578657152125,
104
+ "grad_norm": 1.7642041444778442,
105
+ "learning_rate": 9.717378963587707e-06,
106
+ "loss": 1.3122,
107
+ "step": 700
108
+ },
109
+ {
110
+ "epoch": 0.1216347713266299,
111
+ "grad_norm": 1.5700275897979736,
112
+ "learning_rate": 9.697104857675777e-06,
113
+ "loss": 1.3248,
114
+ "step": 750
115
+ },
116
+ {
117
+ "epoch": 0.12974375608173858,
118
+ "grad_norm": 1.8756022453308105,
119
+ "learning_rate": 9.676830751763849e-06,
120
+ "loss": 1.3364,
121
+ "step": 800
122
+ },
123
+ {
124
+ "epoch": 0.13785274083684723,
125
+ "grad_norm": 2.0151844024658203,
126
+ "learning_rate": 9.656556645851919e-06,
127
+ "loss": 1.3566,
128
+ "step": 850
129
+ },
130
+ {
131
+ "epoch": 0.1459617255919559,
132
+ "grad_norm": 1.8269509077072144,
133
+ "learning_rate": 9.636282539939989e-06,
134
+ "loss": 1.3291,
135
+ "step": 900
136
+ },
137
+ {
138
+ "epoch": 0.15407071034706454,
139
+ "grad_norm": 2.033515453338623,
140
+ "learning_rate": 9.61600843402806e-06,
141
+ "loss": 1.3239,
142
+ "step": 950
143
+ },
144
+ {
145
+ "epoch": 0.1621796951021732,
146
+ "grad_norm": 1.2932145595550537,
147
+ "learning_rate": 9.59573432811613e-06,
148
+ "loss": 1.3458,
149
+ "step": 1000
150
+ },
151
+ {
152
+ "epoch": 0.17028867985728185,
153
+ "grad_norm": 1.7336113452911377,
154
+ "learning_rate": 9.575460222204202e-06,
155
+ "loss": 1.3227,
156
+ "step": 1050
157
+ },
158
+ {
159
+ "epoch": 0.17839766461239054,
160
+ "grad_norm": 2.2469635009765625,
161
+ "learning_rate": 9.555186116292272e-06,
162
+ "loss": 1.3055,
163
+ "step": 1100
164
+ },
165
+ {
166
+ "epoch": 0.1865066493674992,
167
+ "grad_norm": 1.9851100444793701,
168
+ "learning_rate": 9.534912010380343e-06,
169
+ "loss": 1.2713,
170
+ "step": 1150
171
+ },
172
+ {
173
+ "epoch": 0.19461563412260785,
174
+ "grad_norm": 1.896209716796875,
175
+ "learning_rate": 9.514637904468413e-06,
176
+ "loss": 1.3926,
177
+ "step": 1200
178
+ },
179
+ {
180
+ "epoch": 0.2027246188777165,
181
+ "grad_norm": 1.941974401473999,
182
+ "learning_rate": 9.494363798556485e-06,
183
+ "loss": 1.2845,
184
+ "step": 1250
185
+ },
186
+ {
187
+ "epoch": 0.21083360363282516,
188
+ "grad_norm": 1.7393105030059814,
189
+ "learning_rate": 9.474089692644555e-06,
190
+ "loss": 1.3989,
191
+ "step": 1300
192
+ },
193
+ {
194
+ "epoch": 0.21894258838793382,
195
+ "grad_norm": 2.3268821239471436,
196
+ "learning_rate": 9.453815586732625e-06,
197
+ "loss": 1.3939,
198
+ "step": 1350
199
+ },
200
+ {
201
+ "epoch": 0.2270515731430425,
202
+ "grad_norm": 2.2540266513824463,
203
+ "learning_rate": 9.433541480820698e-06,
204
+ "loss": 1.3421,
205
+ "step": 1400
206
+ },
207
+ {
208
+ "epoch": 0.23516055789815116,
209
+ "grad_norm": 1.5483736991882324,
210
+ "learning_rate": 9.413267374908768e-06,
211
+ "loss": 1.3236,
212
+ "step": 1450
213
+ },
214
+ {
215
+ "epoch": 0.2432695426532598,
216
+ "grad_norm": 1.2663439512252808,
217
+ "learning_rate": 9.392993268996838e-06,
218
+ "loss": 1.3333,
219
+ "step": 1500
220
+ },
221
+ {
222
+ "epoch": 0.25137852740836847,
223
+ "grad_norm": 0.978643536567688,
224
+ "learning_rate": 9.37271916308491e-06,
225
+ "loss": 1.3522,
226
+ "step": 1550
227
+ },
228
+ {
229
+ "epoch": 0.25948751216347715,
230
+ "grad_norm": 2.664464235305786,
231
+ "learning_rate": 9.35244505717298e-06,
232
+ "loss": 1.3969,
233
+ "step": 1600
234
+ },
235
+ {
236
+ "epoch": 0.2675964969185858,
237
+ "grad_norm": 0.9333709478378296,
238
+ "learning_rate": 9.332170951261051e-06,
239
+ "loss": 1.3423,
240
+ "step": 1650
241
+ },
242
+ {
243
+ "epoch": 0.27570548167369446,
244
+ "grad_norm": 2.0592761039733887,
245
+ "learning_rate": 9.31189684534912e-06,
246
+ "loss": 1.3274,
247
+ "step": 1700
248
+ },
249
+ {
250
+ "epoch": 0.2838144664288031,
251
+ "grad_norm": 1.6379183530807495,
252
+ "learning_rate": 9.291622739437192e-06,
253
+ "loss": 1.321,
254
+ "step": 1750
255
+ },
256
+ {
257
+ "epoch": 0.2919234511839118,
258
+ "grad_norm": 1.659201979637146,
259
+ "learning_rate": 9.271348633525262e-06,
260
+ "loss": 1.3662,
261
+ "step": 1800
262
+ },
263
+ {
264
+ "epoch": 0.30003243593902046,
265
+ "grad_norm": 2.4258599281311035,
266
+ "learning_rate": 9.251074527613332e-06,
267
+ "loss": 1.2489,
268
+ "step": 1850
269
+ },
270
+ {
271
+ "epoch": 0.3081414206941291,
272
+ "grad_norm": 2.314232349395752,
273
+ "learning_rate": 9.230800421701404e-06,
274
+ "loss": 1.3549,
275
+ "step": 1900
276
+ },
277
+ {
278
+ "epoch": 0.31625040544923777,
279
+ "grad_norm": 1.78170645236969,
280
+ "learning_rate": 9.210526315789474e-06,
281
+ "loss": 1.3405,
282
+ "step": 1950
283
+ },
284
+ {
285
+ "epoch": 0.3243593902043464,
286
+ "grad_norm": 2.3508291244506836,
287
+ "learning_rate": 9.190252209877545e-06,
288
+ "loss": 1.335,
289
+ "step": 2000
290
+ },
291
+ {
292
+ "epoch": 0.3324683749594551,
293
+ "grad_norm": 3.0449280738830566,
294
+ "learning_rate": 9.169978103965615e-06,
295
+ "loss": 1.3188,
296
+ "step": 2050
297
+ },
298
+ {
299
+ "epoch": 0.3405773597145637,
300
+ "grad_norm": 2.0919177532196045,
301
+ "learning_rate": 9.149703998053687e-06,
302
+ "loss": 1.3369,
303
+ "step": 2100
304
+ },
305
+ {
306
+ "epoch": 0.3486863444696724,
307
+ "grad_norm": 1.5090256929397583,
308
+ "learning_rate": 9.129429892141757e-06,
309
+ "loss": 1.3782,
310
+ "step": 2150
311
+ },
312
+ {
313
+ "epoch": 0.3567953292247811,
314
+ "grad_norm": 1.5943760871887207,
315
+ "learning_rate": 9.109155786229828e-06,
316
+ "loss": 1.2826,
317
+ "step": 2200
318
+ },
319
+ {
320
+ "epoch": 0.3649043139798897,
321
+ "grad_norm": 1.4445804357528687,
322
+ "learning_rate": 9.0888816803179e-06,
323
+ "loss": 1.2706,
324
+ "step": 2250
325
+ },
326
+ {
327
+ "epoch": 0.3730132987349984,
328
+ "grad_norm": 1.366866111755371,
329
+ "learning_rate": 9.06860757440597e-06,
330
+ "loss": 1.3081,
331
+ "step": 2300
332
+ },
333
+ {
334
+ "epoch": 0.381122283490107,
335
+ "grad_norm": 1.5148597955703735,
336
+ "learning_rate": 9.04833346849404e-06,
337
+ "loss": 1.3117,
338
+ "step": 2350
339
+ },
340
+ {
341
+ "epoch": 0.3892312682452157,
342
+ "grad_norm": 1.9457615613937378,
343
+ "learning_rate": 9.028059362582111e-06,
344
+ "loss": 1.3385,
345
+ "step": 2400
346
+ },
347
+ {
348
+ "epoch": 0.3973402530003244,
349
+ "grad_norm": 1.0214955806732178,
350
+ "learning_rate": 9.007785256670181e-06,
351
+ "loss": 1.4173,
352
+ "step": 2450
353
+ },
354
+ {
355
+ "epoch": 0.405449237755433,
356
+ "grad_norm": 2.3479509353637695,
357
+ "learning_rate": 8.987511150758253e-06,
358
+ "loss": 1.338,
359
+ "step": 2500
360
+ },
361
+ {
362
+ "epoch": 0.4135582225105417,
363
+ "grad_norm": 1.7548096179962158,
364
+ "learning_rate": 8.967237044846323e-06,
365
+ "loss": 1.3245,
366
+ "step": 2550
367
+ },
368
+ {
369
+ "epoch": 0.4216672072656503,
370
+ "grad_norm": 1.3919732570648193,
371
+ "learning_rate": 8.946962938934394e-06,
372
+ "loss": 1.2934,
373
+ "step": 2600
374
+ },
375
+ {
376
+ "epoch": 0.429776192020759,
377
+ "grad_norm": 2.419706344604492,
378
+ "learning_rate": 8.926688833022464e-06,
379
+ "loss": 1.2451,
380
+ "step": 2650
381
+ },
382
+ {
383
+ "epoch": 0.43788517677586763,
384
+ "grad_norm": 0.7026298642158508,
385
+ "learning_rate": 8.906414727110536e-06,
386
+ "loss": 1.3075,
387
+ "step": 2700
388
+ },
389
+ {
390
+ "epoch": 0.4459941615309763,
391
+ "grad_norm": 1.9528323411941528,
392
+ "learning_rate": 8.886140621198606e-06,
393
+ "loss": 1.3071,
394
+ "step": 2750
395
+ },
396
+ {
397
+ "epoch": 0.454103146286085,
398
+ "grad_norm": 1.322129487991333,
399
+ "learning_rate": 8.865866515286676e-06,
400
+ "loss": 1.3234,
401
+ "step": 2800
402
+ },
403
+ {
404
+ "epoch": 0.46221213104119363,
405
+ "grad_norm": 3.2143826484680176,
406
+ "learning_rate": 8.845592409374747e-06,
407
+ "loss": 1.3553,
408
+ "step": 2850
409
+ },
410
+ {
411
+ "epoch": 0.4703211157963023,
412
+ "grad_norm": 2.3696305751800537,
413
+ "learning_rate": 8.825318303462817e-06,
414
+ "loss": 1.2905,
415
+ "step": 2900
416
+ },
417
+ {
418
+ "epoch": 0.47843010055141094,
419
+ "grad_norm": 1.7011082172393799,
420
+ "learning_rate": 8.805044197550889e-06,
421
+ "loss": 1.2826,
422
+ "step": 2950
423
+ },
424
+ {
425
+ "epoch": 0.4865390853065196,
426
+ "grad_norm": 1.8602455854415894,
427
+ "learning_rate": 8.784770091638959e-06,
428
+ "loss": 1.2119,
429
+ "step": 3000
430
+ },
431
+ {
432
+ "epoch": 0.4946480700616283,
433
+ "grad_norm": 1.8766978979110718,
434
+ "learning_rate": 8.76449598572703e-06,
435
+ "loss": 1.25,
436
+ "step": 3050
437
+ },
438
+ {
439
+ "epoch": 0.5027570548167369,
440
+ "grad_norm": 1.2416331768035889,
441
+ "learning_rate": 8.744221879815102e-06,
442
+ "loss": 1.3494,
443
+ "step": 3100
444
+ },
445
+ {
446
+ "epoch": 0.5108660395718456,
447
+ "grad_norm": 2.160327434539795,
448
+ "learning_rate": 8.723947773903172e-06,
449
+ "loss": 1.2821,
450
+ "step": 3150
451
+ },
452
+ {
453
+ "epoch": 0.5189750243269543,
454
+ "grad_norm": 1.5392768383026123,
455
+ "learning_rate": 8.703673667991243e-06,
456
+ "loss": 1.3716,
457
+ "step": 3200
458
+ },
459
+ {
460
+ "epoch": 0.5270840090820629,
461
+ "grad_norm": 1.9121636152267456,
462
+ "learning_rate": 8.683399562079313e-06,
463
+ "loss": 1.2615,
464
+ "step": 3250
465
+ },
466
+ {
467
+ "epoch": 0.5351929938371716,
468
+ "grad_norm": 1.8084639310836792,
469
+ "learning_rate": 8.663125456167383e-06,
470
+ "loss": 1.3391,
471
+ "step": 3300
472
+ },
473
+ {
474
+ "epoch": 0.5433019785922802,
475
+ "grad_norm": 2.516788959503174,
476
+ "learning_rate": 8.642851350255455e-06,
477
+ "loss": 1.2747,
478
+ "step": 3350
479
+ },
480
+ {
481
+ "epoch": 0.5514109633473889,
482
+ "grad_norm": 5.785072326660156,
483
+ "learning_rate": 8.622577244343525e-06,
484
+ "loss": 1.3414,
485
+ "step": 3400
486
+ },
487
+ {
488
+ "epoch": 0.5595199481024976,
489
+ "grad_norm": 3.8145599365234375,
490
+ "learning_rate": 8.602303138431596e-06,
491
+ "loss": 1.2274,
492
+ "step": 3450
493
+ },
494
+ {
495
+ "epoch": 0.5676289328576062,
496
+ "grad_norm": 0.36742010712623596,
497
+ "learning_rate": 8.582029032519666e-06,
498
+ "loss": 1.2184,
499
+ "step": 3500
500
+ },
501
+ {
502
+ "epoch": 0.5757379176127149,
503
+ "grad_norm": 2.2382278442382812,
504
+ "learning_rate": 8.561754926607738e-06,
505
+ "loss": 1.2359,
506
+ "step": 3550
507
+ },
508
+ {
509
+ "epoch": 0.5838469023678236,
510
+ "grad_norm": 3.001042127609253,
511
+ "learning_rate": 8.541480820695808e-06,
512
+ "loss": 1.2839,
513
+ "step": 3600
514
+ },
515
+ {
516
+ "epoch": 0.5919558871229322,
517
+ "grad_norm": 1.2254408597946167,
518
+ "learning_rate": 8.521206714783878e-06,
519
+ "loss": 1.3025,
520
+ "step": 3650
521
+ },
522
+ {
523
+ "epoch": 0.6000648718780409,
524
+ "grad_norm": 2.408430576324463,
525
+ "learning_rate": 8.50093260887195e-06,
526
+ "loss": 1.2959,
527
+ "step": 3700
528
+ },
529
+ {
530
+ "epoch": 0.6081738566331495,
531
+ "grad_norm": 1.125710129737854,
532
+ "learning_rate": 8.480658502960019e-06,
533
+ "loss": 1.3165,
534
+ "step": 3750
535
+ },
536
+ {
537
+ "epoch": 0.6162828413882582,
538
+ "grad_norm": 1.7280784845352173,
539
+ "learning_rate": 8.46038439704809e-06,
540
+ "loss": 1.3033,
541
+ "step": 3800
542
+ },
543
+ {
544
+ "epoch": 0.6243918261433669,
545
+ "grad_norm": 1.7289584875106812,
546
+ "learning_rate": 8.440110291136162e-06,
547
+ "loss": 1.3818,
548
+ "step": 3850
549
+ },
550
+ {
551
+ "epoch": 0.6325008108984755,
552
+ "grad_norm": 1.4574753046035767,
553
+ "learning_rate": 8.419836185224232e-06,
554
+ "loss": 1.2858,
555
+ "step": 3900
556
+ },
557
+ {
558
+ "epoch": 0.6406097956535842,
559
+ "grad_norm": 1.9952958822250366,
560
+ "learning_rate": 8.399562079312304e-06,
561
+ "loss": 1.323,
562
+ "step": 3950
563
+ },
564
+ {
565
+ "epoch": 0.6487187804086928,
566
+ "grad_norm": 2.3702497482299805,
567
+ "learning_rate": 8.379287973400374e-06,
568
+ "loss": 1.3362,
569
+ "step": 4000
570
+ },
571
+ {
572
+ "epoch": 0.6568277651638015,
573
+ "grad_norm": 2.1261913776397705,
574
+ "learning_rate": 8.359013867488445e-06,
575
+ "loss": 1.2978,
576
+ "step": 4050
577
+ },
578
+ {
579
+ "epoch": 0.6649367499189102,
580
+ "grad_norm": 0.6903754472732544,
581
+ "learning_rate": 8.338739761576515e-06,
582
+ "loss": 1.3273,
583
+ "step": 4100
584
+ },
585
+ {
586
+ "epoch": 0.6730457346740188,
587
+ "grad_norm": 1.848915934562683,
588
+ "learning_rate": 8.318465655664587e-06,
589
+ "loss": 1.294,
590
+ "step": 4150
591
+ },
592
+ {
593
+ "epoch": 0.6811547194291274,
594
+ "grad_norm": 2.0583913326263428,
595
+ "learning_rate": 8.298191549752657e-06,
596
+ "loss": 1.3353,
597
+ "step": 4200
598
+ },
599
+ {
600
+ "epoch": 0.6892637041842361,
601
+ "grad_norm": 1.5055549144744873,
602
+ "learning_rate": 8.277917443840727e-06,
603
+ "loss": 1.3305,
604
+ "step": 4250
605
+ },
606
+ {
607
+ "epoch": 0.6973726889393448,
608
+ "grad_norm": 1.6197587251663208,
609
+ "learning_rate": 8.257643337928798e-06,
610
+ "loss": 1.3765,
611
+ "step": 4300
612
+ },
613
+ {
614
+ "epoch": 0.7054816736944535,
615
+ "grad_norm": 1.927742838859558,
616
+ "learning_rate": 8.237369232016868e-06,
617
+ "loss": 1.3372,
618
+ "step": 4350
619
+ },
620
+ {
621
+ "epoch": 0.7135906584495622,
622
+ "grad_norm": 2.3434853553771973,
623
+ "learning_rate": 8.21709512610494e-06,
624
+ "loss": 1.3041,
625
+ "step": 4400
626
+ },
627
+ {
628
+ "epoch": 0.7216996432046707,
629
+ "grad_norm": 2.09249210357666,
630
+ "learning_rate": 8.19682102019301e-06,
631
+ "loss": 1.2946,
632
+ "step": 4450
633
+ },
634
+ {
635
+ "epoch": 0.7298086279597794,
636
+ "grad_norm": 0.19756704568862915,
637
+ "learning_rate": 8.176546914281081e-06,
638
+ "loss": 1.3014,
639
+ "step": 4500
640
+ },
641
+ {
642
+ "epoch": 0.7379176127148881,
643
+ "grad_norm": 1.2464430332183838,
644
+ "learning_rate": 8.156272808369151e-06,
645
+ "loss": 1.2552,
646
+ "step": 4550
647
+ },
648
+ {
649
+ "epoch": 0.7460265974699968,
650
+ "grad_norm": 1.7760344743728638,
651
+ "learning_rate": 8.135998702457221e-06,
652
+ "loss": 1.2963,
653
+ "step": 4600
654
+ },
655
+ {
656
+ "epoch": 0.7541355822251055,
657
+ "grad_norm": 1.922969937324524,
658
+ "learning_rate": 8.115724596545294e-06,
659
+ "loss": 1.2849,
660
+ "step": 4650
661
+ },
662
+ {
663
+ "epoch": 0.762244566980214,
664
+ "grad_norm": 3.757589340209961,
665
+ "learning_rate": 8.095450490633364e-06,
666
+ "loss": 1.2511,
667
+ "step": 4700
668
+ },
669
+ {
670
+ "epoch": 0.7703535517353227,
671
+ "grad_norm": 2.4983339309692383,
672
+ "learning_rate": 8.075176384721434e-06,
673
+ "loss": 1.2169,
674
+ "step": 4750
675
+ },
676
+ {
677
+ "epoch": 0.7784625364904314,
678
+ "grad_norm": 2.1676225662231445,
679
+ "learning_rate": 8.054902278809506e-06,
680
+ "loss": 1.2711,
681
+ "step": 4800
682
+ },
683
+ {
684
+ "epoch": 0.7865715212455401,
685
+ "grad_norm": 2.8060524463653564,
686
+ "learning_rate": 8.034628172897576e-06,
687
+ "loss": 1.3246,
688
+ "step": 4850
689
+ },
690
+ {
691
+ "epoch": 0.7946805060006488,
692
+ "grad_norm": 1.917485237121582,
693
+ "learning_rate": 8.014354066985647e-06,
694
+ "loss": 1.2669,
695
+ "step": 4900
696
+ },
697
+ {
698
+ "epoch": 0.8027894907557573,
699
+ "grad_norm": 2.1371405124664307,
700
+ "learning_rate": 7.994079961073717e-06,
701
+ "loss": 1.3554,
702
+ "step": 4950
703
+ },
704
+ {
705
+ "epoch": 0.810898475510866,
706
+ "grad_norm": 0.9637095928192139,
707
+ "learning_rate": 7.973805855161789e-06,
708
+ "loss": 1.2862,
709
+ "step": 5000
710
+ },
711
+ {
712
+ "epoch": 0.8190074602659747,
713
+ "grad_norm": 1.3636858463287354,
714
+ "learning_rate": 7.953531749249859e-06,
715
+ "loss": 1.3134,
716
+ "step": 5050
717
+ },
718
+ {
719
+ "epoch": 0.8271164450210834,
720
+ "grad_norm": 0.9230815768241882,
721
+ "learning_rate": 7.933257643337929e-06,
722
+ "loss": 1.2352,
723
+ "step": 5100
724
+ },
725
+ {
726
+ "epoch": 0.8352254297761921,
727
+ "grad_norm": 1.7373725175857544,
728
+ "learning_rate": 7.912983537426e-06,
729
+ "loss": 1.318,
730
+ "step": 5150
731
+ },
732
+ {
733
+ "epoch": 0.8433344145313006,
734
+ "grad_norm": 2.0280568599700928,
735
+ "learning_rate": 7.89270943151407e-06,
736
+ "loss": 1.2464,
737
+ "step": 5200
738
+ },
739
+ {
740
+ "epoch": 0.8514433992864093,
741
+ "grad_norm": 1.1584951877593994,
742
+ "learning_rate": 7.872435325602142e-06,
743
+ "loss": 1.2292,
744
+ "step": 5250
745
+ },
746
+ {
747
+ "epoch": 0.859552384041518,
748
+ "grad_norm": 1.7846872806549072,
749
+ "learning_rate": 7.852161219690212e-06,
750
+ "loss": 1.2976,
751
+ "step": 5300
752
+ },
753
+ {
754
+ "epoch": 0.8676613687966267,
755
+ "grad_norm": 1.7553609609603882,
756
+ "learning_rate": 7.831887113778283e-06,
757
+ "loss": 1.2684,
758
+ "step": 5350
759
+ },
760
+ {
761
+ "epoch": 0.8757703535517353,
762
+ "grad_norm": 2.1919806003570557,
763
+ "learning_rate": 7.811613007866353e-06,
764
+ "loss": 1.2956,
765
+ "step": 5400
766
+ },
767
+ {
768
+ "epoch": 0.883879338306844,
769
+ "grad_norm": 0.717258870601654,
770
+ "learning_rate": 7.791338901954425e-06,
771
+ "loss": 1.2186,
772
+ "step": 5450
773
+ },
774
+ {
775
+ "epoch": 0.8919883230619526,
776
+ "grad_norm": 1.4364169836044312,
777
+ "learning_rate": 7.771064796042496e-06,
778
+ "loss": 1.2596,
779
+ "step": 5500
780
+ },
781
+ {
782
+ "epoch": 0.9000973078170613,
783
+ "grad_norm": 1.99948251247406,
784
+ "learning_rate": 7.750790690130566e-06,
785
+ "loss": 1.3616,
786
+ "step": 5550
787
+ },
788
+ {
789
+ "epoch": 0.90820629257217,
790
+ "grad_norm": 1.5464040040969849,
791
+ "learning_rate": 7.730516584218636e-06,
792
+ "loss": 1.2595,
793
+ "step": 5600
794
+ },
795
+ {
796
+ "epoch": 0.9163152773272786,
797
+ "grad_norm": 1.500651240348816,
798
+ "learning_rate": 7.710242478306708e-06,
799
+ "loss": 1.3223,
800
+ "step": 5650
801
+ },
802
+ {
803
+ "epoch": 0.9244242620823873,
804
+ "grad_norm": 1.6872031688690186,
805
+ "learning_rate": 7.689968372394778e-06,
806
+ "loss": 1.2099,
807
+ "step": 5700
808
+ },
809
+ {
810
+ "epoch": 0.9325332468374959,
811
+ "grad_norm": 1.5728824138641357,
812
+ "learning_rate": 7.66969426648285e-06,
813
+ "loss": 1.2975,
814
+ "step": 5750
815
+ },
816
+ {
817
+ "epoch": 0.9406422315926046,
818
+ "grad_norm": 2.0520365238189697,
819
+ "learning_rate": 7.649420160570919e-06,
820
+ "loss": 1.2895,
821
+ "step": 5800
822
+ },
823
+ {
824
+ "epoch": 0.9487512163477133,
825
+ "grad_norm": 1.6994986534118652,
826
+ "learning_rate": 7.62914605465899e-06,
827
+ "loss": 1.2421,
828
+ "step": 5850
829
+ },
830
+ {
831
+ "epoch": 0.9568602011028219,
832
+ "grad_norm": 2.1418871879577637,
833
+ "learning_rate": 7.608871948747061e-06,
834
+ "loss": 1.2464,
835
+ "step": 5900
836
+ },
837
+ {
838
+ "epoch": 0.9649691858579306,
839
+ "grad_norm": 3.202744960784912,
840
+ "learning_rate": 7.588597842835131e-06,
841
+ "loss": 1.2565,
842
+ "step": 5950
843
+ },
844
+ {
845
+ "epoch": 0.9730781706130393,
846
+ "grad_norm": 2.3648183345794678,
847
+ "learning_rate": 7.568323736923202e-06,
848
+ "loss": 1.262,
849
+ "step": 6000
850
+ },
851
+ {
852
+ "epoch": 0.9811871553681479,
853
+ "grad_norm": 1.500482439994812,
854
+ "learning_rate": 7.548049631011273e-06,
855
+ "loss": 1.2281,
856
+ "step": 6050
857
+ },
858
+ {
859
+ "epoch": 0.9892961401232566,
860
+ "grad_norm": 2.1810970306396484,
861
+ "learning_rate": 7.527775525099344e-06,
862
+ "loss": 1.2318,
863
+ "step": 6100
864
+ },
865
+ {
866
+ "epoch": 0.9974051248783652,
867
+ "grad_norm": 1.3932199478149414,
868
+ "learning_rate": 7.507501419187414e-06,
869
+ "loss": 1.2344,
870
+ "step": 6150
871
+ },
872
+ {
873
+ "epoch": 1.0055141096334739,
874
+ "grad_norm": 2.48954701423645,
875
+ "learning_rate": 7.487227313275484e-06,
876
+ "loss": 1.3035,
877
+ "step": 6200
878
+ },
879
+ {
880
+ "epoch": 1.0136230943885824,
881
+ "grad_norm": 1.4061833620071411,
882
+ "learning_rate": 7.466953207363555e-06,
883
+ "loss": 1.308,
884
+ "step": 6250
885
+ },
886
+ {
887
+ "epoch": 1.0217320791436912,
888
+ "grad_norm": 1.1377198696136475,
889
+ "learning_rate": 7.4466791014516275e-06,
890
+ "loss": 1.2877,
891
+ "step": 6300
892
+ },
893
+ {
894
+ "epoch": 1.0298410638987998,
895
+ "grad_norm": 1.90823233127594,
896
+ "learning_rate": 7.426404995539697e-06,
897
+ "loss": 1.2371,
898
+ "step": 6350
899
+ },
900
+ {
901
+ "epoch": 1.0379500486539086,
902
+ "grad_norm": 1.5908371210098267,
903
+ "learning_rate": 7.406130889627768e-06,
904
+ "loss": 1.2861,
905
+ "step": 6400
906
+ },
907
+ {
908
+ "epoch": 1.0460590334090172,
909
+ "grad_norm": 2.892045259475708,
910
+ "learning_rate": 7.385856783715839e-06,
911
+ "loss": 1.2856,
912
+ "step": 6450
913
+ },
914
+ {
915
+ "epoch": 1.0541680181641258,
916
+ "grad_norm": 1.4647297859191895,
917
+ "learning_rate": 7.36558267780391e-06,
918
+ "loss": 1.2431,
919
+ "step": 6500
920
+ },
921
+ {
922
+ "epoch": 1.0622770029192345,
923
+ "grad_norm": 1.2635786533355713,
924
+ "learning_rate": 7.34530857189198e-06,
925
+ "loss": 1.3269,
926
+ "step": 6550
927
+ },
928
+ {
929
+ "epoch": 1.0703859876743431,
930
+ "grad_norm": 1.0140317678451538,
931
+ "learning_rate": 7.325034465980051e-06,
932
+ "loss": 1.2724,
933
+ "step": 6600
934
+ },
935
+ {
936
+ "epoch": 1.078494972429452,
937
+ "grad_norm": 1.1980386972427368,
938
+ "learning_rate": 7.304760360068122e-06,
939
+ "loss": 1.2909,
940
+ "step": 6650
941
+ },
942
+ {
943
+ "epoch": 1.0866039571845605,
944
+ "grad_norm": 2.5311107635498047,
945
+ "learning_rate": 7.284486254156193e-06,
946
+ "loss": 1.2296,
947
+ "step": 6700
948
+ },
949
+ {
950
+ "epoch": 1.094712941939669,
951
+ "grad_norm": 1.5901424884796143,
952
+ "learning_rate": 7.2642121482442626e-06,
953
+ "loss": 1.2136,
954
+ "step": 6750
955
+ },
956
+ {
957
+ "epoch": 1.1028219266947779,
958
+ "grad_norm": 1.0336142778396606,
959
+ "learning_rate": 7.243938042332333e-06,
960
+ "loss": 1.2908,
961
+ "step": 6800
962
+ },
963
+ {
964
+ "epoch": 1.1109309114498864,
965
+ "grad_norm": 2.5491976737976074,
966
+ "learning_rate": 7.223663936420404e-06,
967
+ "loss": 1.2256,
968
+ "step": 6850
969
+ },
970
+ {
971
+ "epoch": 1.1190398962049952,
972
+ "grad_norm": 2.592517137527466,
973
+ "learning_rate": 7.203389830508475e-06,
974
+ "loss": 1.2808,
975
+ "step": 6900
976
+ },
977
+ {
978
+ "epoch": 1.1271488809601038,
979
+ "grad_norm": 1.5294160842895508,
980
+ "learning_rate": 7.1831157245965456e-06,
981
+ "loss": 1.2279,
982
+ "step": 6950
983
+ },
984
+ {
985
+ "epoch": 1.1352578657152124,
986
+ "grad_norm": 2.665705680847168,
987
+ "learning_rate": 7.162841618684616e-06,
988
+ "loss": 1.2813,
989
+ "step": 7000
990
+ },
991
+ {
992
+ "epoch": 1.1433668504703212,
993
+ "grad_norm": 5.743466854095459,
994
+ "learning_rate": 7.142567512772687e-06,
995
+ "loss": 1.2601,
996
+ "step": 7050
997
+ },
998
+ {
999
+ "epoch": 1.1514758352254297,
1000
+ "grad_norm": 1.979543924331665,
1001
+ "learning_rate": 7.122293406860759e-06,
1002
+ "loss": 1.2568,
1003
+ "step": 7100
1004
+ },
1005
+ {
1006
+ "epoch": 1.1595848199805385,
1007
+ "grad_norm": 0.2160961776971817,
1008
+ "learning_rate": 7.1020193009488294e-06,
1009
+ "loss": 1.2234,
1010
+ "step": 7150
1011
+ },
1012
+ {
1013
+ "epoch": 1.167693804735647,
1014
+ "grad_norm": 2.09420108795166,
1015
+ "learning_rate": 7.0817451950369e-06,
1016
+ "loss": 1.2727,
1017
+ "step": 7200
1018
+ },
1019
+ {
1020
+ "epoch": 1.1758027894907557,
1021
+ "grad_norm": 1.4437772035598755,
1022
+ "learning_rate": 7.06147108912497e-06,
1023
+ "loss": 1.2535,
1024
+ "step": 7250
1025
+ },
1026
+ {
1027
+ "epoch": 1.1839117742458645,
1028
+ "grad_norm": 2.6284403800964355,
1029
+ "learning_rate": 7.041196983213041e-06,
1030
+ "loss": 1.1969,
1031
+ "step": 7300
1032
+ },
1033
+ {
1034
+ "epoch": 1.192020759000973,
1035
+ "grad_norm": 1.897250771522522,
1036
+ "learning_rate": 7.020922877301112e-06,
1037
+ "loss": 1.2579,
1038
+ "step": 7350
1039
+ },
1040
+ {
1041
+ "epoch": 1.2001297437560818,
1042
+ "grad_norm": 1.591044545173645,
1043
+ "learning_rate": 7.000648771389182e-06,
1044
+ "loss": 1.2553,
1045
+ "step": 7400
1046
+ },
1047
+ {
1048
+ "epoch": 1.2082387285111904,
1049
+ "grad_norm": 2.323927402496338,
1050
+ "learning_rate": 6.980374665477253e-06,
1051
+ "loss": 1.2802,
1052
+ "step": 7450
1053
+ },
1054
+ {
1055
+ "epoch": 1.216347713266299,
1056
+ "grad_norm": 2.145848035812378,
1057
+ "learning_rate": 6.960100559565324e-06,
1058
+ "loss": 1.3271,
1059
+ "step": 7500
1060
+ },
1061
+ {
1062
+ "epoch": 1.2244566980214078,
1063
+ "grad_norm": 1.1199519634246826,
1064
+ "learning_rate": 6.939826453653395e-06,
1065
+ "loss": 1.2948,
1066
+ "step": 7550
1067
+ },
1068
+ {
1069
+ "epoch": 1.2325656827765163,
1070
+ "grad_norm": 1.5974798202514648,
1071
+ "learning_rate": 6.919552347741465e-06,
1072
+ "loss": 1.2925,
1073
+ "step": 7600
1074
+ },
1075
+ {
1076
+ "epoch": 1.240674667531625,
1077
+ "grad_norm": 1.1883361339569092,
1078
+ "learning_rate": 6.899278241829535e-06,
1079
+ "loss": 1.2288,
1080
+ "step": 7650
1081
+ },
1082
+ {
1083
+ "epoch": 1.2487836522867337,
1084
+ "grad_norm": 2.2361881732940674,
1085
+ "learning_rate": 6.879004135917606e-06,
1086
+ "loss": 1.2732,
1087
+ "step": 7700
1088
+ },
1089
+ {
1090
+ "epoch": 1.2568926370418423,
1091
+ "grad_norm": 0.9524820446968079,
1092
+ "learning_rate": 6.858730030005677e-06,
1093
+ "loss": 1.3427,
1094
+ "step": 7750
1095
+ },
1096
+ {
1097
+ "epoch": 1.265001621796951,
1098
+ "grad_norm": 2.439042091369629,
1099
+ "learning_rate": 6.8384559240937475e-06,
1100
+ "loss": 1.2915,
1101
+ "step": 7800
1102
+ },
1103
+ {
1104
+ "epoch": 1.2731106065520597,
1105
+ "grad_norm": 2.7487218379974365,
1106
+ "learning_rate": 6.818181818181818e-06,
1107
+ "loss": 1.3025,
1108
+ "step": 7850
1109
+ },
1110
+ {
1111
+ "epoch": 1.2812195913071682,
1112
+ "grad_norm": 1.3138405084609985,
1113
+ "learning_rate": 6.79790771226989e-06,
1114
+ "loss": 1.2678,
1115
+ "step": 7900
1116
+ },
1117
+ {
1118
+ "epoch": 1.289328576062277,
1119
+ "grad_norm": 2.2130439281463623,
1120
+ "learning_rate": 6.777633606357961e-06,
1121
+ "loss": 1.2955,
1122
+ "step": 7950
1123
+ },
1124
+ {
1125
+ "epoch": 1.2974375608173856,
1126
+ "grad_norm": 2.6008100509643555,
1127
+ "learning_rate": 6.757359500446031e-06,
1128
+ "loss": 1.2413,
1129
+ "step": 8000
1130
+ },
1131
+ {
1132
+ "epoch": 1.3055465455724944,
1133
+ "grad_norm": 2.495473861694336,
1134
+ "learning_rate": 6.737085394534102e-06,
1135
+ "loss": 1.3061,
1136
+ "step": 8050
1137
+ },
1138
+ {
1139
+ "epoch": 1.313655530327603,
1140
+ "grad_norm": 0.8150402307510376,
1141
+ "learning_rate": 6.716811288622173e-06,
1142
+ "loss": 1.3055,
1143
+ "step": 8100
1144
+ },
1145
+ {
1146
+ "epoch": 1.3217645150827115,
1147
+ "grad_norm": 1.7135632038116455,
1148
+ "learning_rate": 6.696537182710244e-06,
1149
+ "loss": 1.2723,
1150
+ "step": 8150
1151
+ },
1152
+ {
1153
+ "epoch": 1.3298734998378203,
1154
+ "grad_norm": 2.367229700088501,
1155
+ "learning_rate": 6.6762630767983135e-06,
1156
+ "loss": 1.2817,
1157
+ "step": 8200
1158
+ },
1159
+ {
1160
+ "epoch": 1.337982484592929,
1161
+ "grad_norm": 1.9759521484375,
1162
+ "learning_rate": 6.655988970886384e-06,
1163
+ "loss": 1.2453,
1164
+ "step": 8250
1165
+ },
1166
+ {
1167
+ "epoch": 1.3460914693480377,
1168
+ "grad_norm": 1.2894783020019531,
1169
+ "learning_rate": 6.635714864974455e-06,
1170
+ "loss": 1.338,
1171
+ "step": 8300
1172
+ },
1173
+ {
1174
+ "epoch": 1.3542004541031463,
1175
+ "grad_norm": 0.24668912589550018,
1176
+ "learning_rate": 6.615440759062526e-06,
1177
+ "loss": 1.255,
1178
+ "step": 8350
1179
+ },
1180
+ {
1181
+ "epoch": 1.3623094388582548,
1182
+ "grad_norm": 2.6564314365386963,
1183
+ "learning_rate": 6.5951666531505966e-06,
1184
+ "loss": 1.1793,
1185
+ "step": 8400
1186
+ },
1187
+ {
1188
+ "epoch": 1.3704184236133636,
1189
+ "grad_norm": 1.1451148986816406,
1190
+ "learning_rate": 6.574892547238667e-06,
1191
+ "loss": 1.2857,
1192
+ "step": 8450
1193
+ },
1194
+ {
1195
+ "epoch": 1.3785274083684722,
1196
+ "grad_norm": 2.693976879119873,
1197
+ "learning_rate": 6.554618441326738e-06,
1198
+ "loss": 1.2497,
1199
+ "step": 8500
1200
+ },
1201
+ {
1202
+ "epoch": 1.386636393123581,
1203
+ "grad_norm": 2.3329060077667236,
1204
+ "learning_rate": 6.534344335414808e-06,
1205
+ "loss": 1.2665,
1206
+ "step": 8550
1207
+ },
1208
+ {
1209
+ "epoch": 1.3947453778786896,
1210
+ "grad_norm": 2.251298427581787,
1211
+ "learning_rate": 6.514070229502879e-06,
1212
+ "loss": 1.33,
1213
+ "step": 8600
1214
+ },
1215
+ {
1216
+ "epoch": 1.4028543626337981,
1217
+ "grad_norm": 3.0650289058685303,
1218
+ "learning_rate": 6.4937961235909495e-06,
1219
+ "loss": 1.2996,
1220
+ "step": 8650
1221
+ },
1222
+ {
1223
+ "epoch": 1.410963347388907,
1224
+ "grad_norm": 2.1476645469665527,
1225
+ "learning_rate": 6.47352201767902e-06,
1226
+ "loss": 1.3232,
1227
+ "step": 8700
1228
+ },
1229
+ {
1230
+ "epoch": 1.4190723321440155,
1231
+ "grad_norm": 1.236338496208191,
1232
+ "learning_rate": 6.453247911767092e-06,
1233
+ "loss": 1.2547,
1234
+ "step": 8750
1235
+ },
1236
+ {
1237
+ "epoch": 1.4271813168991243,
1238
+ "grad_norm": 2.276726722717285,
1239
+ "learning_rate": 6.432973805855163e-06,
1240
+ "loss": 1.2067,
1241
+ "step": 8800
1242
+ },
1243
+ {
1244
+ "epoch": 1.4352903016542329,
1245
+ "grad_norm": 1.871100664138794,
1246
+ "learning_rate": 6.412699699943233e-06,
1247
+ "loss": 1.238,
1248
+ "step": 8850
1249
+ },
1250
+ {
1251
+ "epoch": 1.4433992864093415,
1252
+ "grad_norm": 1.9131008386611938,
1253
+ "learning_rate": 6.392425594031304e-06,
1254
+ "loss": 1.2436,
1255
+ "step": 8900
1256
+ },
1257
+ {
1258
+ "epoch": 1.4515082711644502,
1259
+ "grad_norm": 1.6729109287261963,
1260
+ "learning_rate": 6.372151488119375e-06,
1261
+ "loss": 1.2732,
1262
+ "step": 8950
1263
+ },
1264
+ {
1265
+ "epoch": 1.4596172559195588,
1266
+ "grad_norm": 1.4220985174179077,
1267
+ "learning_rate": 6.351877382207446e-06,
1268
+ "loss": 1.3043,
1269
+ "step": 9000
1270
+ },
1271
+ {
1272
+ "epoch": 1.4677262406746676,
1273
+ "grad_norm": 1.5014866590499878,
1274
+ "learning_rate": 6.331603276295516e-06,
1275
+ "loss": 1.2501,
1276
+ "step": 9050
1277
+ },
1278
+ {
1279
+ "epoch": 1.4758352254297762,
1280
+ "grad_norm": 1.6406453847885132,
1281
+ "learning_rate": 6.311329170383586e-06,
1282
+ "loss": 1.2457,
1283
+ "step": 9100
1284
+ },
1285
+ {
1286
+ "epoch": 1.4839442101848848,
1287
+ "grad_norm": 2.01636004447937,
1288
+ "learning_rate": 6.291055064471657e-06,
1289
+ "loss": 1.1894,
1290
+ "step": 9150
1291
+ },
1292
+ {
1293
+ "epoch": 1.4920531949399936,
1294
+ "grad_norm": 1.5200086832046509,
1295
+ "learning_rate": 6.270780958559728e-06,
1296
+ "loss": 1.1833,
1297
+ "step": 9200
1298
+ },
1299
+ {
1300
+ "epoch": 1.5001621796951021,
1301
+ "grad_norm": 1.9229196310043335,
1302
+ "learning_rate": 6.2505068526477985e-06,
1303
+ "loss": 1.2219,
1304
+ "step": 9250
1305
+ },
1306
+ {
1307
+ "epoch": 1.508271164450211,
1308
+ "grad_norm": 2.19616961479187,
1309
+ "learning_rate": 6.230232746735869e-06,
1310
+ "loss": 1.2788,
1311
+ "step": 9300
1312
+ },
1313
+ {
1314
+ "epoch": 1.5163801492053195,
1315
+ "grad_norm": 1.4525929689407349,
1316
+ "learning_rate": 6.20995864082394e-06,
1317
+ "loss": 1.2963,
1318
+ "step": 9350
1319
+ },
1320
+ {
1321
+ "epoch": 1.524489133960428,
1322
+ "grad_norm": 2.227957248687744,
1323
+ "learning_rate": 6.189684534912011e-06,
1324
+ "loss": 1.324,
1325
+ "step": 9400
1326
+ },
1327
+ {
1328
+ "epoch": 1.5325981187155369,
1329
+ "grad_norm": 1.158480167388916,
1330
+ "learning_rate": 6.1694104290000815e-06,
1331
+ "loss": 1.2185,
1332
+ "step": 9450
1333
+ },
1334
+ {
1335
+ "epoch": 1.5407071034706454,
1336
+ "grad_norm": 1.3199654817581177,
1337
+ "learning_rate": 6.1491363230881514e-06,
1338
+ "loss": 1.2714,
1339
+ "step": 9500
1340
+ },
1341
+ {
1342
+ "epoch": 1.5488160882257542,
1343
+ "grad_norm": 2.110074043273926,
1344
+ "learning_rate": 6.128862217176224e-06,
1345
+ "loss": 1.256,
1346
+ "step": 9550
1347
+ },
1348
+ {
1349
+ "epoch": 1.5569250729808628,
1350
+ "grad_norm": 1.322704553604126,
1351
+ "learning_rate": 6.108588111264294e-06,
1352
+ "loss": 1.1785,
1353
+ "step": 9600
1354
+ },
1355
+ {
1356
+ "epoch": 1.5650340577359714,
1357
+ "grad_norm": 2.572434425354004,
1358
+ "learning_rate": 6.0883140053523645e-06,
1359
+ "loss": 1.2349,
1360
+ "step": 9650
1361
+ },
1362
+ {
1363
+ "epoch": 1.5731430424910802,
1364
+ "grad_norm": 2.033780574798584,
1365
+ "learning_rate": 6.068039899440435e-06,
1366
+ "loss": 1.2203,
1367
+ "step": 9700
1368
+ },
1369
+ {
1370
+ "epoch": 1.5812520272461887,
1371
+ "grad_norm": 1.9049453735351562,
1372
+ "learning_rate": 6.047765793528506e-06,
1373
+ "loss": 1.2043,
1374
+ "step": 9750
1375
+ },
1376
+ {
1377
+ "epoch": 1.5893610120012975,
1378
+ "grad_norm": 2.882568597793579,
1379
+ "learning_rate": 6.027491687616577e-06,
1380
+ "loss": 1.217,
1381
+ "step": 9800
1382
+ },
1383
+ {
1384
+ "epoch": 1.597469996756406,
1385
+ "grad_norm": 2.430227279663086,
1386
+ "learning_rate": 6.0072175817046475e-06,
1387
+ "loss": 1.2795,
1388
+ "step": 9850
1389
+ },
1390
+ {
1391
+ "epoch": 1.6055789815115147,
1392
+ "grad_norm": 1.9852076768875122,
1393
+ "learning_rate": 5.986943475792718e-06,
1394
+ "loss": 1.2434,
1395
+ "step": 9900
1396
+ },
1397
+ {
1398
+ "epoch": 1.6136879662666233,
1399
+ "grad_norm": 2.1857733726501465,
1400
+ "learning_rate": 5.966669369880789e-06,
1401
+ "loss": 1.2756,
1402
+ "step": 9950
1403
+ },
1404
+ {
1405
+ "epoch": 1.621796951021732,
1406
+ "grad_norm": 2.7323496341705322,
1407
+ "learning_rate": 5.946395263968859e-06,
1408
+ "loss": 1.2921,
1409
+ "step": 10000
1410
+ },
1411
+ {
1412
+ "epoch": 1.6299059357768408,
1413
+ "grad_norm": 2.2632415294647217,
1414
+ "learning_rate": 5.92612115805693e-06,
1415
+ "loss": 1.2763,
1416
+ "step": 10050
1417
+ },
1418
+ {
1419
+ "epoch": 1.6380149205319494,
1420
+ "grad_norm": 2.0098931789398193,
1421
+ "learning_rate": 5.9058470521450005e-06,
1422
+ "loss": 1.292,
1423
+ "step": 10100
1424
+ },
1425
+ {
1426
+ "epoch": 1.646123905287058,
1427
+ "grad_norm": 2.09377384185791,
1428
+ "learning_rate": 5.885572946233071e-06,
1429
+ "loss": 1.2738,
1430
+ "step": 10150
1431
+ },
1432
+ {
1433
+ "epoch": 1.6542328900421666,
1434
+ "grad_norm": 2.292084217071533,
1435
+ "learning_rate": 5.865298840321142e-06,
1436
+ "loss": 1.2726,
1437
+ "step": 10200
1438
+ },
1439
+ {
1440
+ "epoch": 1.6623418747972754,
1441
+ "grad_norm": 2.7795863151550293,
1442
+ "learning_rate": 5.845024734409213e-06,
1443
+ "loss": 1.2523,
1444
+ "step": 10250
1445
+ },
1446
+ {
1447
+ "epoch": 1.6704508595523841,
1448
+ "grad_norm": 3.0921523571014404,
1449
+ "learning_rate": 5.8247506284972835e-06,
1450
+ "loss": 1.2684,
1451
+ "step": 10300
1452
+ },
1453
+ {
1454
+ "epoch": 1.6785598443074927,
1455
+ "grad_norm": 1.036535382270813,
1456
+ "learning_rate": 5.804476522585355e-06,
1457
+ "loss": 1.2404,
1458
+ "step": 10350
1459
+ },
1460
+ {
1461
+ "epoch": 1.6866688290626013,
1462
+ "grad_norm": 1.3650333881378174,
1463
+ "learning_rate": 5.784202416673426e-06,
1464
+ "loss": 1.247,
1465
+ "step": 10400
1466
+ },
1467
+ {
1468
+ "epoch": 1.6947778138177099,
1469
+ "grad_norm": 2.558058977127075,
1470
+ "learning_rate": 5.763928310761497e-06,
1471
+ "loss": 1.2938,
1472
+ "step": 10450
1473
+ },
1474
+ {
1475
+ "epoch": 1.7028867985728187,
1476
+ "grad_norm": 2.6575851440429688,
1477
+ "learning_rate": 5.743654204849567e-06,
1478
+ "loss": 1.2974,
1479
+ "step": 10500
1480
+ },
1481
+ {
1482
+ "epoch": 1.7109957833279275,
1483
+ "grad_norm": 1.657400369644165,
1484
+ "learning_rate": 5.723380098937637e-06,
1485
+ "loss": 1.3268,
1486
+ "step": 10550
1487
+ },
1488
+ {
1489
+ "epoch": 1.719104768083036,
1490
+ "grad_norm": 2.027801275253296,
1491
+ "learning_rate": 5.703105993025708e-06,
1492
+ "loss": 1.3029,
1493
+ "step": 10600
1494
+ },
1495
+ {
1496
+ "epoch": 1.7272137528381446,
1497
+ "grad_norm": 1.3793126344680786,
1498
+ "learning_rate": 5.682831887113779e-06,
1499
+ "loss": 1.1812,
1500
+ "step": 10650
1501
+ },
1502
+ {
1503
+ "epoch": 1.7353227375932532,
1504
+ "grad_norm": 1.5861361026763916,
1505
+ "learning_rate": 5.6625577812018495e-06,
1506
+ "loss": 1.2871,
1507
+ "step": 10700
1508
+ },
1509
+ {
1510
+ "epoch": 1.743431722348362,
1511
+ "grad_norm": 2.3719797134399414,
1512
+ "learning_rate": 5.64228367528992e-06,
1513
+ "loss": 1.1947,
1514
+ "step": 10750
1515
+ },
1516
+ {
1517
+ "epoch": 1.7515407071034708,
1518
+ "grad_norm": 2.675689697265625,
1519
+ "learning_rate": 5.622009569377991e-06,
1520
+ "loss": 1.2902,
1521
+ "step": 10800
1522
+ },
1523
+ {
1524
+ "epoch": 1.7596496918585793,
1525
+ "grad_norm": 2.018069267272949,
1526
+ "learning_rate": 5.601735463466062e-06,
1527
+ "loss": 1.1827,
1528
+ "step": 10850
1529
+ },
1530
+ {
1531
+ "epoch": 1.767758676613688,
1532
+ "grad_norm": 1.1704685688018799,
1533
+ "learning_rate": 5.5814613575541325e-06,
1534
+ "loss": 1.1498,
1535
+ "step": 10900
1536
+ },
1537
+ {
1538
+ "epoch": 1.7758676613687965,
1539
+ "grad_norm": 2.0111939907073975,
1540
+ "learning_rate": 5.561187251642202e-06,
1541
+ "loss": 1.2358,
1542
+ "step": 10950
1543
+ },
1544
+ {
1545
+ "epoch": 1.7839766461239053,
1546
+ "grad_norm": 3.043297529220581,
1547
+ "learning_rate": 5.540913145730273e-06,
1548
+ "loss": 1.26,
1549
+ "step": 11000
1550
+ },
1551
+ {
1552
+ "epoch": 1.792085630879014,
1553
+ "grad_norm": 3.0858490467071533,
1554
+ "learning_rate": 5.520639039818344e-06,
1555
+ "loss": 1.2519,
1556
+ "step": 11050
1557
+ },
1558
+ {
1559
+ "epoch": 1.8001946156341226,
1560
+ "grad_norm": 2.669131278991699,
1561
+ "learning_rate": 5.500364933906415e-06,
1562
+ "loss": 1.3174,
1563
+ "step": 11100
1564
+ },
1565
+ {
1566
+ "epoch": 1.8083036003892312,
1567
+ "grad_norm": 1.4813052415847778,
1568
+ "learning_rate": 5.480090827994486e-06,
1569
+ "loss": 1.2528,
1570
+ "step": 11150
1571
+ },
1572
+ {
1573
+ "epoch": 1.8164125851443398,
1574
+ "grad_norm": 2.2234039306640625,
1575
+ "learning_rate": 5.459816722082557e-06,
1576
+ "loss": 1.2984,
1577
+ "step": 11200
1578
+ },
1579
+ {
1580
+ "epoch": 1.8245215698994486,
1581
+ "grad_norm": 3.4711413383483887,
1582
+ "learning_rate": 5.439542616170628e-06,
1583
+ "loss": 1.2174,
1584
+ "step": 11250
1585
+ },
1586
+ {
1587
+ "epoch": 1.8326305546545574,
1588
+ "grad_norm": 1.9171231985092163,
1589
+ "learning_rate": 5.4192685102586985e-06,
1590
+ "loss": 1.2657,
1591
+ "step": 11300
1592
+ },
1593
+ {
1594
+ "epoch": 1.840739539409666,
1595
+ "grad_norm": 1.7139352560043335,
1596
+ "learning_rate": 5.398994404346769e-06,
1597
+ "loss": 1.274,
1598
+ "step": 11350
1599
+ },
1600
+ {
1601
+ "epoch": 1.8488485241647745,
1602
+ "grad_norm": 2.9915032386779785,
1603
+ "learning_rate": 5.37872029843484e-06,
1604
+ "loss": 1.1745,
1605
+ "step": 11400
1606
+ },
1607
+ {
1608
+ "epoch": 1.856957508919883,
1609
+ "grad_norm": 3.0832788944244385,
1610
+ "learning_rate": 5.35844619252291e-06,
1611
+ "loss": 1.3089,
1612
+ "step": 11450
1613
+ },
1614
+ {
1615
+ "epoch": 1.8650664936749919,
1616
+ "grad_norm": 2.364255905151367,
1617
+ "learning_rate": 5.338172086610981e-06,
1618
+ "loss": 1.2146,
1619
+ "step": 11500
1620
+ },
1621
+ {
1622
+ "epoch": 1.8731754784301007,
1623
+ "grad_norm": 3.9903273582458496,
1624
+ "learning_rate": 5.3178979806990514e-06,
1625
+ "loss": 1.3103,
1626
+ "step": 11550
1627
+ },
1628
+ {
1629
+ "epoch": 1.8812844631852093,
1630
+ "grad_norm": 3.4954657554626465,
1631
+ "learning_rate": 5.297623874787122e-06,
1632
+ "loss": 1.1682,
1633
+ "step": 11600
1634
+ },
1635
+ {
1636
+ "epoch": 1.8893934479403178,
1637
+ "grad_norm": 1.927339792251587,
1638
+ "learning_rate": 5.277349768875193e-06,
1639
+ "loss": 1.224,
1640
+ "step": 11650
1641
+ },
1642
+ {
1643
+ "epoch": 1.8975024326954264,
1644
+ "grad_norm": 1.446385145187378,
1645
+ "learning_rate": 5.257075662963264e-06,
1646
+ "loss": 1.3907,
1647
+ "step": 11700
1648
+ },
1649
+ {
1650
+ "epoch": 1.9056114174505352,
1651
+ "grad_norm": 2.112168312072754,
1652
+ "learning_rate": 5.2368015570513345e-06,
1653
+ "loss": 1.2041,
1654
+ "step": 11750
1655
+ },
1656
+ {
1657
+ "epoch": 1.913720402205644,
1658
+ "grad_norm": 2.601565361022949,
1659
+ "learning_rate": 5.216527451139405e-06,
1660
+ "loss": 1.2827,
1661
+ "step": 11800
1662
+ },
1663
+ {
1664
+ "epoch": 1.9218293869607526,
1665
+ "grad_norm": 1.9448506832122803,
1666
+ "learning_rate": 5.196253345227475e-06,
1667
+ "loss": 1.1899,
1668
+ "step": 11850
1669
+ },
1670
+ {
1671
+ "epoch": 1.9299383717158611,
1672
+ "grad_norm": 1.7583825588226318,
1673
+ "learning_rate": 5.175979239315546e-06,
1674
+ "loss": 1.2681,
1675
+ "step": 11900
1676
+ },
1677
+ {
1678
+ "epoch": 1.9380473564709697,
1679
+ "grad_norm": 1.319887399673462,
1680
+ "learning_rate": 5.155705133403617e-06,
1681
+ "loss": 1.2311,
1682
+ "step": 11950
1683
+ },
1684
+ {
1685
+ "epoch": 1.9461563412260785,
1686
+ "grad_norm": 1.5955997705459595,
1687
+ "learning_rate": 5.135431027491688e-06,
1688
+ "loss": 1.2043,
1689
+ "step": 12000
1690
+ },
1691
+ {
1692
+ "epoch": 1.9542653259811873,
1693
+ "grad_norm": 2.112924337387085,
1694
+ "learning_rate": 5.115156921579759e-06,
1695
+ "loss": 1.21,
1696
+ "step": 12050
1697
+ },
1698
+ {
1699
+ "epoch": 1.9623743107362959,
1700
+ "grad_norm": 2.8387506008148193,
1701
+ "learning_rate": 5.09488281566783e-06,
1702
+ "loss": 1.253,
1703
+ "step": 12100
1704
+ },
1705
+ {
1706
+ "epoch": 1.9704832954914044,
1707
+ "grad_norm": 2.55635142326355,
1708
+ "learning_rate": 5.0746087097559005e-06,
1709
+ "loss": 1.2277,
1710
+ "step": 12150
1711
+ },
1712
+ {
1713
+ "epoch": 1.978592280246513,
1714
+ "grad_norm": 2.2216525077819824,
1715
+ "learning_rate": 5.054334603843971e-06,
1716
+ "loss": 1.1755,
1717
+ "step": 12200
1718
+ },
1719
+ {
1720
+ "epoch": 1.9867012650016218,
1721
+ "grad_norm": 1.1123380661010742,
1722
+ "learning_rate": 5.034060497932042e-06,
1723
+ "loss": 1.229,
1724
+ "step": 12250
1725
+ },
1726
+ {
1727
+ "epoch": 1.9948102497567306,
1728
+ "grad_norm": 2.5723652839660645,
1729
+ "learning_rate": 5.013786392020113e-06,
1730
+ "loss": 1.2028,
1731
+ "step": 12300
1732
+ },
1733
+ {
1734
+ "epoch": 2.002919234511839,
1735
+ "grad_norm": 2.5151309967041016,
1736
+ "learning_rate": 4.993512286108183e-06,
1737
+ "loss": 1.2314,
1738
+ "step": 12350
1739
+ },
1740
+ {
1741
+ "epoch": 2.0110282192669477,
1742
+ "grad_norm": 1.5693440437316895,
1743
+ "learning_rate": 4.973238180196253e-06,
1744
+ "loss": 1.2771,
1745
+ "step": 12400
1746
+ },
1747
+ {
1748
+ "epoch": 2.0191372040220563,
1749
+ "grad_norm": 4.562756538391113,
1750
+ "learning_rate": 4.952964074284324e-06,
1751
+ "loss": 1.2614,
1752
+ "step": 12450
1753
+ },
1754
+ {
1755
+ "epoch": 2.027246188777165,
1756
+ "grad_norm": 0.9000415802001953,
1757
+ "learning_rate": 4.932689968372395e-06,
1758
+ "loss": 1.2383,
1759
+ "step": 12500
1760
+ },
1761
+ {
1762
+ "epoch": 2.035355173532274,
1763
+ "grad_norm": 1.2384685277938843,
1764
+ "learning_rate": 4.912415862460466e-06,
1765
+ "loss": 1.2501,
1766
+ "step": 12550
1767
+ },
1768
+ {
1769
+ "epoch": 2.0434641582873825,
1770
+ "grad_norm": 1.771003246307373,
1771
+ "learning_rate": 4.892141756548537e-06,
1772
+ "loss": 1.2603,
1773
+ "step": 12600
1774
+ },
1775
+ {
1776
+ "epoch": 2.051573143042491,
1777
+ "grad_norm": 2.1732709407806396,
1778
+ "learning_rate": 4.871867650636607e-06,
1779
+ "loss": 1.1763,
1780
+ "step": 12650
1781
+ },
1782
+ {
1783
+ "epoch": 2.0596821277975996,
1784
+ "grad_norm": 1.5497926473617554,
1785
+ "learning_rate": 4.851593544724678e-06,
1786
+ "loss": 1.2558,
1787
+ "step": 12700
1788
+ },
1789
+ {
1790
+ "epoch": 2.067791112552708,
1791
+ "grad_norm": 1.6834354400634766,
1792
+ "learning_rate": 4.831319438812749e-06,
1793
+ "loss": 1.2592,
1794
+ "step": 12750
1795
+ },
1796
+ {
1797
+ "epoch": 2.075900097307817,
1798
+ "grad_norm": 1.920637845993042,
1799
+ "learning_rate": 4.811045332900819e-06,
1800
+ "loss": 1.279,
1801
+ "step": 12800
1802
+ },
1803
+ {
1804
+ "epoch": 2.084009082062926,
1805
+ "grad_norm": 1.851440191268921,
1806
+ "learning_rate": 4.79077122698889e-06,
1807
+ "loss": 1.2904,
1808
+ "step": 12850
1809
+ },
1810
+ {
1811
+ "epoch": 2.0921180668180344,
1812
+ "grad_norm": 3.262347936630249,
1813
+ "learning_rate": 4.770497121076961e-06,
1814
+ "loss": 1.1763,
1815
+ "step": 12900
1816
+ },
1817
+ {
1818
+ "epoch": 2.100227051573143,
1819
+ "grad_norm": 1.7690410614013672,
1820
+ "learning_rate": 4.750223015165032e-06,
1821
+ "loss": 1.246,
1822
+ "step": 12950
1823
+ },
1824
+ {
1825
+ "epoch": 2.1083360363282515,
1826
+ "grad_norm": 2.3499839305877686,
1827
+ "learning_rate": 4.7299489092531024e-06,
1828
+ "loss": 1.1969,
1829
+ "step": 13000
1830
+ },
1831
+ {
1832
+ "epoch": 2.1164450210833605,
1833
+ "grad_norm": 2.815704822540283,
1834
+ "learning_rate": 4.709674803341173e-06,
1835
+ "loss": 1.2299,
1836
+ "step": 13050
1837
+ },
1838
+ {
1839
+ "epoch": 2.124554005838469,
1840
+ "grad_norm": 1.6346577405929565,
1841
+ "learning_rate": 4.689400697429244e-06,
1842
+ "loss": 1.1941,
1843
+ "step": 13100
1844
+ },
1845
+ {
1846
+ "epoch": 2.1326629905935777,
1847
+ "grad_norm": 1.3435848951339722,
1848
+ "learning_rate": 4.669126591517315e-06,
1849
+ "loss": 1.2193,
1850
+ "step": 13150
1851
+ },
1852
+ {
1853
+ "epoch": 2.1407719753486862,
1854
+ "grad_norm": 2.11517596244812,
1855
+ "learning_rate": 4.6488524856053854e-06,
1856
+ "loss": 1.2868,
1857
+ "step": 13200
1858
+ },
1859
+ {
1860
+ "epoch": 2.148880960103795,
1861
+ "grad_norm": 1.5125885009765625,
1862
+ "learning_rate": 4.628578379693456e-06,
1863
+ "loss": 1.2034,
1864
+ "step": 13250
1865
+ },
1866
+ {
1867
+ "epoch": 2.156989944858904,
1868
+ "grad_norm": 2.0965402126312256,
1869
+ "learning_rate": 4.608304273781526e-06,
1870
+ "loss": 1.2484,
1871
+ "step": 13300
1872
+ },
1873
+ {
1874
+ "epoch": 2.1650989296140124,
1875
+ "grad_norm": 1.9137533903121948,
1876
+ "learning_rate": 4.588030167869597e-06,
1877
+ "loss": 1.2531,
1878
+ "step": 13350
1879
+ },
1880
+ {
1881
+ "epoch": 2.173207914369121,
1882
+ "grad_norm": 2.630784749984741,
1883
+ "learning_rate": 4.5677560619576685e-06,
1884
+ "loss": 1.2074,
1885
+ "step": 13400
1886
+ },
1887
+ {
1888
+ "epoch": 2.1813168991242295,
1889
+ "grad_norm": 1.4360569715499878,
1890
+ "learning_rate": 4.547481956045739e-06,
1891
+ "loss": 1.22,
1892
+ "step": 13450
1893
+ },
1894
+ {
1895
+ "epoch": 2.189425883879338,
1896
+ "grad_norm": 2.066938638687134,
1897
+ "learning_rate": 4.52720785013381e-06,
1898
+ "loss": 1.1438,
1899
+ "step": 13500
1900
+ },
1901
+ {
1902
+ "epoch": 2.197534868634447,
1903
+ "grad_norm": 1.7182413339614868,
1904
+ "learning_rate": 4.50693374422188e-06,
1905
+ "loss": 1.2681,
1906
+ "step": 13550
1907
+ },
1908
+ {
1909
+ "epoch": 2.2056438533895557,
1910
+ "grad_norm": 1.706874132156372,
1911
+ "learning_rate": 4.486659638309951e-06,
1912
+ "loss": 1.1888,
1913
+ "step": 13600
1914
+ },
1915
+ {
1916
+ "epoch": 2.2137528381446643,
1917
+ "grad_norm": 1.8634135723114014,
1918
+ "learning_rate": 4.466385532398021e-06,
1919
+ "loss": 1.2953,
1920
+ "step": 13650
1921
+ },
1922
+ {
1923
+ "epoch": 2.221861822899773,
1924
+ "grad_norm": 1.77712881565094,
1925
+ "learning_rate": 4.446111426486092e-06,
1926
+ "loss": 1.2461,
1927
+ "step": 13700
1928
+ },
1929
+ {
1930
+ "epoch": 2.2299708076548814,
1931
+ "grad_norm": 1.9737837314605713,
1932
+ "learning_rate": 4.425837320574163e-06,
1933
+ "loss": 1.2856,
1934
+ "step": 13750
1935
+ },
1936
+ {
1937
+ "epoch": 2.2380797924099904,
1938
+ "grad_norm": 2.7296142578125,
1939
+ "learning_rate": 4.405563214662234e-06,
1940
+ "loss": 1.2124,
1941
+ "step": 13800
1942
+ },
1943
+ {
1944
+ "epoch": 2.246188777165099,
1945
+ "grad_norm": 3.5112380981445312,
1946
+ "learning_rate": 4.385289108750304e-06,
1947
+ "loss": 1.2143,
1948
+ "step": 13850
1949
+ },
1950
+ {
1951
+ "epoch": 2.2542977619202076,
1952
+ "grad_norm": 3.4935994148254395,
1953
+ "learning_rate": 4.365015002838375e-06,
1954
+ "loss": 1.3156,
1955
+ "step": 13900
1956
+ },
1957
+ {
1958
+ "epoch": 2.262406746675316,
1959
+ "grad_norm": 2.2354025840759277,
1960
+ "learning_rate": 4.344740896926446e-06,
1961
+ "loss": 1.3025,
1962
+ "step": 13950
1963
+ },
1964
+ {
1965
+ "epoch": 2.2705157314304247,
1966
+ "grad_norm": 2.089087724685669,
1967
+ "learning_rate": 4.324466791014517e-06,
1968
+ "loss": 1.2249,
1969
+ "step": 14000
1970
+ },
1971
+ {
1972
+ "epoch": 2.2786247161855337,
1973
+ "grad_norm": 2.6738228797912598,
1974
+ "learning_rate": 4.304192685102587e-06,
1975
+ "loss": 1.1766,
1976
+ "step": 14050
1977
+ },
1978
+ {
1979
+ "epoch": 2.2867337009406423,
1980
+ "grad_norm": 1.6028488874435425,
1981
+ "learning_rate": 4.283918579190658e-06,
1982
+ "loss": 1.2806,
1983
+ "step": 14100
1984
+ },
1985
+ {
1986
+ "epoch": 2.294842685695751,
1987
+ "grad_norm": 2.742100954055786,
1988
+ "learning_rate": 4.263644473278729e-06,
1989
+ "loss": 1.2241,
1990
+ "step": 14150
1991
+ },
1992
+ {
1993
+ "epoch": 2.3029516704508595,
1994
+ "grad_norm": 1.2533172369003296,
1995
+ "learning_rate": 4.2433703673668e-06,
1996
+ "loss": 1.2563,
1997
+ "step": 14200
1998
+ },
1999
+ {
2000
+ "epoch": 2.311060655205968,
2001
+ "grad_norm": 2.783311128616333,
2002
+ "learning_rate": 4.22309626145487e-06,
2003
+ "loss": 1.2382,
2004
+ "step": 14250
2005
+ },
2006
+ {
2007
+ "epoch": 2.319169639961077,
2008
+ "grad_norm": 1.9947431087493896,
2009
+ "learning_rate": 4.202822155542941e-06,
2010
+ "loss": 1.2533,
2011
+ "step": 14300
2012
+ },
2013
+ {
2014
+ "epoch": 2.3272786247161856,
2015
+ "grad_norm": 2.8825254440307617,
2016
+ "learning_rate": 4.182548049631012e-06,
2017
+ "loss": 1.2332,
2018
+ "step": 14350
2019
+ },
2020
+ {
2021
+ "epoch": 2.335387609471294,
2022
+ "grad_norm": 1.9132847785949707,
2023
+ "learning_rate": 4.162273943719083e-06,
2024
+ "loss": 1.225,
2025
+ "step": 14400
2026
+ },
2027
+ {
2028
+ "epoch": 2.3434965942264028,
2029
+ "grad_norm": 2.9740896224975586,
2030
+ "learning_rate": 4.1419998378071526e-06,
2031
+ "loss": 1.302,
2032
+ "step": 14450
2033
+ },
2034
+ {
2035
+ "epoch": 2.3516055789815113,
2036
+ "grad_norm": 2.5434772968292236,
2037
+ "learning_rate": 4.121725731895223e-06,
2038
+ "loss": 1.2857,
2039
+ "step": 14500
2040
+ },
2041
+ {
2042
+ "epoch": 2.3597145637366204,
2043
+ "grad_norm": 0.8146458864212036,
2044
+ "learning_rate": 4.101451625983294e-06,
2045
+ "loss": 1.1667,
2046
+ "step": 14550
2047
+ },
2048
+ {
2049
+ "epoch": 2.367823548491729,
2050
+ "grad_norm": 2.3713395595550537,
2051
+ "learning_rate": 4.081177520071365e-06,
2052
+ "loss": 1.1799,
2053
+ "step": 14600
2054
+ },
2055
+ {
2056
+ "epoch": 2.3759325332468375,
2057
+ "grad_norm": 2.5800139904022217,
2058
+ "learning_rate": 4.0609034141594364e-06,
2059
+ "loss": 1.2639,
2060
+ "step": 14650
2061
+ },
2062
+ {
2063
+ "epoch": 2.384041518001946,
2064
+ "grad_norm": 8.0242338180542,
2065
+ "learning_rate": 4.040629308247507e-06,
2066
+ "loss": 1.2168,
2067
+ "step": 14700
2068
+ },
2069
+ {
2070
+ "epoch": 2.3921505027570547,
2071
+ "grad_norm": 0.9941585063934326,
2072
+ "learning_rate": 4.020355202335577e-06,
2073
+ "loss": 1.2966,
2074
+ "step": 14750
2075
+ },
2076
+ {
2077
+ "epoch": 2.4002594875121637,
2078
+ "grad_norm": 0.7390837669372559,
2079
+ "learning_rate": 4.000081096423648e-06,
2080
+ "loss": 1.3237,
2081
+ "step": 14800
2082
+ },
2083
+ {
2084
+ "epoch": 2.4083684722672722,
2085
+ "grad_norm": 0.5450477004051208,
2086
+ "learning_rate": 3.979806990511719e-06,
2087
+ "loss": 1.284,
2088
+ "step": 14850
2089
+ },
2090
+ {
2091
+ "epoch": 2.416477457022381,
2092
+ "grad_norm": 1.7690049409866333,
2093
+ "learning_rate": 3.959532884599789e-06,
2094
+ "loss": 1.286,
2095
+ "step": 14900
2096
+ },
2097
+ {
2098
+ "epoch": 2.4245864417774894,
2099
+ "grad_norm": 2.655095100402832,
2100
+ "learning_rate": 3.93925877868786e-06,
2101
+ "loss": 1.1513,
2102
+ "step": 14950
2103
+ },
2104
+ {
2105
+ "epoch": 2.432695426532598,
2106
+ "grad_norm": 1.2846322059631348,
2107
+ "learning_rate": 3.918984672775931e-06,
2108
+ "loss": 1.2024,
2109
+ "step": 15000
2110
+ },
2111
+ {
2112
+ "epoch": 2.440804411287707,
2113
+ "grad_norm": 6.425904273986816,
2114
+ "learning_rate": 3.898710566864002e-06,
2115
+ "loss": 1.2462,
2116
+ "step": 15050
2117
+ },
2118
+ {
2119
+ "epoch": 2.4489133960428155,
2120
+ "grad_norm": 2.2578928470611572,
2121
+ "learning_rate": 3.878436460952072e-06,
2122
+ "loss": 1.2289,
2123
+ "step": 15100
2124
+ },
2125
+ {
2126
+ "epoch": 2.457022380797924,
2127
+ "grad_norm": 3.1006276607513428,
2128
+ "learning_rate": 3.858162355040143e-06,
2129
+ "loss": 1.2839,
2130
+ "step": 15150
2131
+ },
2132
+ {
2133
+ "epoch": 2.4651313655530327,
2134
+ "grad_norm": 2.598376512527466,
2135
+ "learning_rate": 3.837888249128214e-06,
2136
+ "loss": 1.2496,
2137
+ "step": 15200
2138
+ },
2139
+ {
2140
+ "epoch": 2.4732403503081413,
2141
+ "grad_norm": 0.7084365487098694,
2142
+ "learning_rate": 3.817614143216285e-06,
2143
+ "loss": 1.2325,
2144
+ "step": 15250
2145
+ },
2146
+ {
2147
+ "epoch": 2.48134933506325,
2148
+ "grad_norm": 2.280824661254883,
2149
+ "learning_rate": 3.797340037304355e-06,
2150
+ "loss": 1.1541,
2151
+ "step": 15300
2152
+ },
2153
+ {
2154
+ "epoch": 2.489458319818359,
2155
+ "grad_norm": 10.274874687194824,
2156
+ "learning_rate": 3.7770659313924257e-06,
2157
+ "loss": 1.1489,
2158
+ "step": 15350
2159
+ },
2160
+ {
2161
+ "epoch": 2.4975673045734674,
2162
+ "grad_norm": 2.2401506900787354,
2163
+ "learning_rate": 3.7567918254804964e-06,
2164
+ "loss": 1.1696,
2165
+ "step": 15400
2166
+ },
2167
+ {
2168
+ "epoch": 2.505676289328576,
2169
+ "grad_norm": 2.0671870708465576,
2170
+ "learning_rate": 3.7365177195685676e-06,
2171
+ "loss": 1.2512,
2172
+ "step": 15450
2173
+ },
2174
+ {
2175
+ "epoch": 2.5137852740836846,
2176
+ "grad_norm": 2.2912776470184326,
2177
+ "learning_rate": 3.7162436136566384e-06,
2178
+ "loss": 1.2278,
2179
+ "step": 15500
2180
+ },
2181
+ {
2182
+ "epoch": 2.5218942588387936,
2183
+ "grad_norm": 1.7719197273254395,
2184
+ "learning_rate": 3.6959695077447087e-06,
2185
+ "loss": 1.2984,
2186
+ "step": 15550
2187
+ },
2188
+ {
2189
+ "epoch": 2.530003243593902,
2190
+ "grad_norm": 1.9428201913833618,
2191
+ "learning_rate": 3.6756954018327795e-06,
2192
+ "loss": 1.2511,
2193
+ "step": 15600
2194
+ },
2195
+ {
2196
+ "epoch": 2.5381122283490107,
2197
+ "grad_norm": 2.804948091506958,
2198
+ "learning_rate": 3.6554212959208502e-06,
2199
+ "loss": 1.2599,
2200
+ "step": 15650
2201
+ },
2202
+ {
2203
+ "epoch": 2.5462212131041193,
2204
+ "grad_norm": 2.306248188018799,
2205
+ "learning_rate": 3.635147190008921e-06,
2206
+ "loss": 1.2252,
2207
+ "step": 15700
2208
+ },
2209
+ {
2210
+ "epoch": 2.554330197859228,
2211
+ "grad_norm": 2.2706100940704346,
2212
+ "learning_rate": 3.6148730840969913e-06,
2213
+ "loss": 1.1874,
2214
+ "step": 15750
2215
+ },
2216
+ {
2217
+ "epoch": 2.5624391826143365,
2218
+ "grad_norm": 1.6053426265716553,
2219
+ "learning_rate": 3.594598978185062e-06,
2220
+ "loss": 1.1885,
2221
+ "step": 15800
2222
+ },
2223
+ {
2224
+ "epoch": 2.5705481673694455,
2225
+ "grad_norm": 2.0183823108673096,
2226
+ "learning_rate": 3.5743248722731332e-06,
2227
+ "loss": 1.2176,
2228
+ "step": 15850
2229
+ },
2230
+ {
2231
+ "epoch": 2.578657152124554,
2232
+ "grad_norm": 1.6887139081954956,
2233
+ "learning_rate": 3.554050766361204e-06,
2234
+ "loss": 1.1165,
2235
+ "step": 15900
2236
+ },
2237
+ {
2238
+ "epoch": 2.5867661368796626,
2239
+ "grad_norm": 1.6139768362045288,
2240
+ "learning_rate": 3.5337766604492747e-06,
2241
+ "loss": 1.2512,
2242
+ "step": 15950
2243
+ },
2244
+ {
2245
+ "epoch": 2.594875121634771,
2246
+ "grad_norm": 1.026294231414795,
2247
+ "learning_rate": 3.513502554537345e-06,
2248
+ "loss": 1.2485,
2249
+ "step": 16000
2250
+ },
2251
+ {
2252
+ "epoch": 2.60298410638988,
2253
+ "grad_norm": 2.261563777923584,
2254
+ "learning_rate": 3.493228448625416e-06,
2255
+ "loss": 1.2493,
2256
+ "step": 16050
2257
+ },
2258
+ {
2259
+ "epoch": 2.6110930911449888,
2260
+ "grad_norm": 2.9573357105255127,
2261
+ "learning_rate": 3.4729543427134866e-06,
2262
+ "loss": 1.2542,
2263
+ "step": 16100
2264
+ },
2265
+ {
2266
+ "epoch": 2.6192020759000973,
2267
+ "grad_norm": 2.836587905883789,
2268
+ "learning_rate": 3.4526802368015573e-06,
2269
+ "loss": 1.2571,
2270
+ "step": 16150
2271
+ },
2272
+ {
2273
+ "epoch": 2.627311060655206,
2274
+ "grad_norm": 5.188553333282471,
2275
+ "learning_rate": 3.4324061308896276e-06,
2276
+ "loss": 1.3193,
2277
+ "step": 16200
2278
+ },
2279
+ {
2280
+ "epoch": 2.6354200454103145,
2281
+ "grad_norm": 1.9180452823638916,
2282
+ "learning_rate": 3.412132024977699e-06,
2283
+ "loss": 1.2382,
2284
+ "step": 16250
2285
+ },
2286
+ {
2287
+ "epoch": 2.643529030165423,
2288
+ "grad_norm": 2.1819140911102295,
2289
+ "learning_rate": 3.3918579190657696e-06,
2290
+ "loss": 1.2826,
2291
+ "step": 16300
2292
+ },
2293
+ {
2294
+ "epoch": 2.651638014920532,
2295
+ "grad_norm": 2.264775037765503,
2296
+ "learning_rate": 3.3715838131538403e-06,
2297
+ "loss": 1.2507,
2298
+ "step": 16350
2299
+ },
2300
+ {
2301
+ "epoch": 2.6597469996756407,
2302
+ "grad_norm": 1.7436145544052124,
2303
+ "learning_rate": 3.351309707241911e-06,
2304
+ "loss": 1.2057,
2305
+ "step": 16400
2306
+ },
2307
+ {
2308
+ "epoch": 2.6678559844307492,
2309
+ "grad_norm": 2.5168802738189697,
2310
+ "learning_rate": 3.3310356013299814e-06,
2311
+ "loss": 1.215,
2312
+ "step": 16450
2313
+ },
2314
+ {
2315
+ "epoch": 2.675964969185858,
2316
+ "grad_norm": 1.952141284942627,
2317
+ "learning_rate": 3.310761495418052e-06,
2318
+ "loss": 1.255,
2319
+ "step": 16500
2320
+ },
2321
+ {
2322
+ "epoch": 2.684073953940967,
2323
+ "grad_norm": 1.5202018022537231,
2324
+ "learning_rate": 3.290487389506123e-06,
2325
+ "loss": 1.224,
2326
+ "step": 16550
2327
+ },
2328
+ {
2329
+ "epoch": 2.6921829386960754,
2330
+ "grad_norm": 1.8313968181610107,
2331
+ "learning_rate": 3.2702132835941937e-06,
2332
+ "loss": 1.3158,
2333
+ "step": 16600
2334
+ },
2335
+ {
2336
+ "epoch": 2.700291923451184,
2337
+ "grad_norm": 2.5669538974761963,
2338
+ "learning_rate": 3.249939177682265e-06,
2339
+ "loss": 1.2905,
2340
+ "step": 16650
2341
+ },
2342
+ {
2343
+ "epoch": 2.7084009082062925,
2344
+ "grad_norm": 2.714341878890991,
2345
+ "learning_rate": 3.2296650717703356e-06,
2346
+ "loss": 1.2508,
2347
+ "step": 16700
2348
+ },
2349
+ {
2350
+ "epoch": 2.716509892961401,
2351
+ "grad_norm": 2.8722524642944336,
2352
+ "learning_rate": 3.209390965858406e-06,
2353
+ "loss": 1.2905,
2354
+ "step": 16750
2355
+ },
2356
+ {
2357
+ "epoch": 2.7246188777165097,
2358
+ "grad_norm": 2.822148323059082,
2359
+ "learning_rate": 3.1891168599464767e-06,
2360
+ "loss": 1.1907,
2361
+ "step": 16800
2362
+ },
2363
+ {
2364
+ "epoch": 2.7327278624716187,
2365
+ "grad_norm": 0.6179723143577576,
2366
+ "learning_rate": 3.1688427540345474e-06,
2367
+ "loss": 1.276,
2368
+ "step": 16850
2369
+ },
2370
+ {
2371
+ "epoch": 2.7408368472267273,
2372
+ "grad_norm": 1.800058126449585,
2373
+ "learning_rate": 3.148568648122618e-06,
2374
+ "loss": 1.1746,
2375
+ "step": 16900
2376
+ },
2377
+ {
2378
+ "epoch": 2.748945831981836,
2379
+ "grad_norm": 2.2209925651550293,
2380
+ "learning_rate": 3.1282945422106885e-06,
2381
+ "loss": 1.245,
2382
+ "step": 16950
2383
+ },
2384
+ {
2385
+ "epoch": 2.7570548167369444,
2386
+ "grad_norm": 2.067692995071411,
2387
+ "learning_rate": 3.1080204362987593e-06,
2388
+ "loss": 1.2182,
2389
+ "step": 17000
2390
+ },
2391
+ {
2392
+ "epoch": 2.7651638014920534,
2393
+ "grad_norm": 2.8044259548187256,
2394
+ "learning_rate": 3.0877463303868304e-06,
2395
+ "loss": 1.1653,
2396
+ "step": 17050
2397
+ },
2398
+ {
2399
+ "epoch": 2.773272786247162,
2400
+ "grad_norm": 2.077935218811035,
2401
+ "learning_rate": 3.067472224474901e-06,
2402
+ "loss": 1.2223,
2403
+ "step": 17100
2404
+ },
2405
+ {
2406
+ "epoch": 2.7813817710022706,
2407
+ "grad_norm": 0.14890266954898834,
2408
+ "learning_rate": 3.047198118562972e-06,
2409
+ "loss": 1.2318,
2410
+ "step": 17150
2411
+ },
2412
+ {
2413
+ "epoch": 2.789490755757379,
2414
+ "grad_norm": 1.6987643241882324,
2415
+ "learning_rate": 3.0269240126510423e-06,
2416
+ "loss": 1.2607,
2417
+ "step": 17200
2418
+ },
2419
+ {
2420
+ "epoch": 2.7975997405124877,
2421
+ "grad_norm": 2.667273759841919,
2422
+ "learning_rate": 3.006649906739113e-06,
2423
+ "loss": 1.2486,
2424
+ "step": 17250
2425
+ },
2426
+ {
2427
+ "epoch": 2.8057087252675963,
2428
+ "grad_norm": 1.8006951808929443,
2429
+ "learning_rate": 2.9863758008271838e-06,
2430
+ "loss": 1.2674,
2431
+ "step": 17300
2432
+ },
2433
+ {
2434
+ "epoch": 2.8138177100227053,
2435
+ "grad_norm": 3.4938597679138184,
2436
+ "learning_rate": 2.9661016949152545e-06,
2437
+ "loss": 1.2782,
2438
+ "step": 17350
2439
+ },
2440
+ {
2441
+ "epoch": 2.821926694777814,
2442
+ "grad_norm": 3.029115915298462,
2443
+ "learning_rate": 2.945827589003325e-06,
2444
+ "loss": 1.2397,
2445
+ "step": 17400
2446
+ },
2447
+ {
2448
+ "epoch": 2.8300356795329225,
2449
+ "grad_norm": 1.7525807619094849,
2450
+ "learning_rate": 2.9255534830913956e-06,
2451
+ "loss": 1.1576,
2452
+ "step": 17450
2453
+ },
2454
+ {
2455
+ "epoch": 2.838144664288031,
2456
+ "grad_norm": 2.326188564300537,
2457
+ "learning_rate": 2.905279377179467e-06,
2458
+ "loss": 1.2581,
2459
+ "step": 17500
2460
+ },
2461
+ {
2462
+ "epoch": 2.84625364904314,
2463
+ "grad_norm": 2.2817983627319336,
2464
+ "learning_rate": 2.8850052712675375e-06,
2465
+ "loss": 1.1471,
2466
+ "step": 17550
2467
+ },
2468
+ {
2469
+ "epoch": 2.8543626337982486,
2470
+ "grad_norm": 1.9472275972366333,
2471
+ "learning_rate": 2.8647311653556083e-06,
2472
+ "loss": 1.2784,
2473
+ "step": 17600
2474
+ },
2475
+ {
2476
+ "epoch": 2.862471618553357,
2477
+ "grad_norm": 2.6982924938201904,
2478
+ "learning_rate": 2.8444570594436786e-06,
2479
+ "loss": 1.181,
2480
+ "step": 17650
2481
+ },
2482
+ {
2483
+ "epoch": 2.8705806033084658,
2484
+ "grad_norm": 2.204470634460449,
2485
+ "learning_rate": 2.8241829535317494e-06,
2486
+ "loss": 1.3165,
2487
+ "step": 17700
2488
+ },
2489
+ {
2490
+ "epoch": 2.8786895880635743,
2491
+ "grad_norm": 1.8621634244918823,
2492
+ "learning_rate": 2.80390884761982e-06,
2493
+ "loss": 1.1949,
2494
+ "step": 17750
2495
+ },
2496
+ {
2497
+ "epoch": 2.886798572818683,
2498
+ "grad_norm": 2.0357561111450195,
2499
+ "learning_rate": 2.783634741707891e-06,
2500
+ "loss": 1.2433,
2501
+ "step": 17800
2502
+ },
2503
+ {
2504
+ "epoch": 2.894907557573792,
2505
+ "grad_norm": 1.873806118965149,
2506
+ "learning_rate": 2.7633606357959612e-06,
2507
+ "loss": 1.2737,
2508
+ "step": 17850
2509
+ },
2510
+ {
2511
+ "epoch": 2.9030165423289005,
2512
+ "grad_norm": 2.299546241760254,
2513
+ "learning_rate": 2.7430865298840324e-06,
2514
+ "loss": 1.2296,
2515
+ "step": 17900
2516
+ },
2517
+ {
2518
+ "epoch": 2.911125527084009,
2519
+ "grad_norm": 2.267756938934326,
2520
+ "learning_rate": 2.722812423972103e-06,
2521
+ "loss": 1.2348,
2522
+ "step": 17950
2523
+ },
2524
+ {
2525
+ "epoch": 2.9192345118391176,
2526
+ "grad_norm": 3.639319658279419,
2527
+ "learning_rate": 2.702538318060174e-06,
2528
+ "loss": 1.2168,
2529
+ "step": 18000
2530
+ },
2531
+ {
2532
+ "epoch": 2.9273434965942267,
2533
+ "grad_norm": 2.825929641723633,
2534
+ "learning_rate": 2.6822642121482447e-06,
2535
+ "loss": 1.2045,
2536
+ "step": 18050
2537
+ },
2538
+ {
2539
+ "epoch": 2.9354524813493352,
2540
+ "grad_norm": 1.6339542865753174,
2541
+ "learning_rate": 2.661990106236315e-06,
2542
+ "loss": 1.2303,
2543
+ "step": 18100
2544
+ },
2545
+ {
2546
+ "epoch": 2.943561466104444,
2547
+ "grad_norm": 1.8570992946624756,
2548
+ "learning_rate": 2.6417160003243857e-06,
2549
+ "loss": 1.2268,
2550
+ "step": 18150
2551
+ },
2552
+ {
2553
+ "epoch": 2.9516704508595524,
2554
+ "grad_norm": 2.2465381622314453,
2555
+ "learning_rate": 2.6214418944124565e-06,
2556
+ "loss": 1.1506,
2557
+ "step": 18200
2558
+ },
2559
+ {
2560
+ "epoch": 2.959779435614661,
2561
+ "grad_norm": 2.456606149673462,
2562
+ "learning_rate": 2.6011677885005272e-06,
2563
+ "loss": 1.2371,
2564
+ "step": 18250
2565
+ },
2566
+ {
2567
+ "epoch": 2.9678884203697695,
2568
+ "grad_norm": 1.7189408540725708,
2569
+ "learning_rate": 2.5808936825885984e-06,
2570
+ "loss": 1.1677,
2571
+ "step": 18300
2572
+ },
2573
+ {
2574
+ "epoch": 2.975997405124878,
2575
+ "grad_norm": 1.5492075681686401,
2576
+ "learning_rate": 2.5606195766766687e-06,
2577
+ "loss": 1.2146,
2578
+ "step": 18350
2579
+ },
2580
+ {
2581
+ "epoch": 2.984106389879987,
2582
+ "grad_norm": 2.5447022914886475,
2583
+ "learning_rate": 2.5403454707647395e-06,
2584
+ "loss": 1.1574,
2585
+ "step": 18400
2586
+ },
2587
+ {
2588
+ "epoch": 2.9922153746350957,
2589
+ "grad_norm": 1.8842716217041016,
2590
+ "learning_rate": 2.5200713648528103e-06,
2591
+ "loss": 1.2093,
2592
+ "step": 18450
2593
+ }
2594
+ ],
2595
+ "logging_steps": 50,
2596
+ "max_steps": 24664,
2597
+ "num_input_tokens_seen": 0,
2598
+ "num_train_epochs": 4,
2599
+ "save_steps": 500,
2600
+ "stateful_callbacks": {
2601
+ "TrainerControl": {
2602
+ "args": {
2603
+ "should_epoch_stop": false,
2604
+ "should_evaluate": false,
2605
+ "should_log": false,
2606
+ "should_save": true,
2607
+ "should_training_stop": false
2608
+ },
2609
+ "attributes": {}
2610
+ }
2611
+ },
2612
+ "total_flos": 4.035905534827063e+19,
2613
+ "train_batch_size": 1,
2614
+ "trial_name": null,
2615
+ "trial_params": null
2616
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac288aead743a18ffaa2e3cb073d2fe3883f0c3af3644f95f1a8704de0c9c475
3
+ size 7672
vocab.json ADDED
The diff for this file is too large to render. See raw diff