Andrew82106 commited on
Commit
98f918a
·
1 Parent(s): c264fd7

First model version

Browse files
Files changed (50) hide show
  1. .gitattributes +4 -0
  2. ChatGLM2-6B +0 -1
  3. output/adgen-chatglm2-6b-pt-128-2e-2/all_results.json +8 -0
  4. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/config.json +45 -0
  5. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/configuration_chatglm.py +59 -0
  6. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/generation_config.json +6 -0
  7. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/modeling_chatglm.py +1193 -0
  8. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/optimizer.pt +3 -0
  9. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/pytorch_model.bin +3 -0
  10. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/quantization.py +188 -0
  11. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/rng_state.pth +3 -0
  12. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/scheduler.pt +3 -0
  13. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/special_tokens_map.json +1 -0
  14. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/tokenization_chatglm.py +257 -0
  15. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/tokenizer.model +3 -0
  16. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/tokenizer_config.json +15 -0
  17. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/trainer_state.json +616 -0
  18. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/training_args.bin +3 -0
  19. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/config.json +45 -0
  20. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/configuration_chatglm.py +59 -0
  21. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/generation_config.json +6 -0
  22. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/modeling_chatglm.py +1193 -0
  23. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/optimizer.pt +3 -0
  24. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/pytorch_model.bin +3 -0
  25. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/quantization.py +188 -0
  26. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/rng_state.pth +3 -0
  27. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/scheduler.pt +3 -0
  28. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/special_tokens_map.json +1 -0
  29. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/tokenization_chatglm.py +257 -0
  30. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/tokenizer.model +3 -0
  31. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/tokenizer_config.json +15 -0
  32. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/trainer_state.json +1216 -0
  33. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/training_args.bin +3 -0
  34. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/config.json +45 -0
  35. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/configuration_chatglm.py +59 -0
  36. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/generation_config.json +6 -0
  37. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/modeling_chatglm.py +1193 -0
  38. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/optimizer.pt +3 -0
  39. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/pytorch_model.bin +3 -0
  40. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/quantization.py +188 -0
  41. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/rng_state.pth +3 -0
  42. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/scheduler.pt +3 -0
  43. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/special_tokens_map.json +1 -0
  44. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/tokenization_chatglm.py +257 -0
  45. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/tokenizer.model +3 -0
  46. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/tokenizer_config.json +15 -0
  47. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/trainer_state.json +1816 -0
  48. output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/training_args.bin +3 -0
  49. output/adgen-chatglm2-6b-pt-128-2e-2/train_results.json +8 -0
  50. output/adgen-chatglm2-6b-pt-128-2e-2/trainer_state.json +1825 -0
.gitattributes ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ *.bin filter=lfs diff=lfs merge=lfs -text
2
+ *.pt filter=lfs diff=lfs merge=lfs -text
3
+ *.model filter=lfs diff=lfs merge=lfs -text
4
+ *.pth filter=lfs diff=lfs merge=lfs -text
ChatGLM2-6B DELETED
@@ -1 +0,0 @@
1
- Subproject commit a7950261989a28c8b59e161a0ba5d49fd7a68d0a
 
 
output/adgen-chatglm2-6b-pt-128-2e-2/all_results.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 13.37,
3
+ "train_loss": 0.2174228900273641,
4
+ "train_runtime": 38888.8061,
5
+ "train_samples": 3589,
6
+ "train_samples_per_second": 1.234,
7
+ "train_steps_per_second": 0.077
8
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/config.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "../THUDM/chatglm2-6b",
3
+ "add_bias_linear": false,
4
+ "add_qkv_bias": true,
5
+ "apply_query_key_layer_scaling": true,
6
+ "apply_residual_connection_post_layernorm": false,
7
+ "architectures": [
8
+ "ChatGLMForConditionalGeneration"
9
+ ],
10
+ "attention_dropout": 0.0,
11
+ "attention_softmax_in_fp32": true,
12
+ "auto_map": {
13
+ "AutoConfig": "configuration_chatglm.ChatGLMConfig",
14
+ "AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration",
15
+ "AutoModelForCausalLM": "modeling_chatglm.ChatGLMForConditionalGeneration",
16
+ "AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration"
17
+ },
18
+ "bias_dropout_fusion": true,
19
+ "eos_token_id": 2,
20
+ "ffn_hidden_size": 13696,
21
+ "fp32_residual_connection": false,
22
+ "hidden_dropout": 0.0,
23
+ "hidden_size": 4096,
24
+ "kv_channels": 128,
25
+ "layernorm_epsilon": 1e-05,
26
+ "model_type": "chatglm",
27
+ "multi_query_attention": true,
28
+ "multi_query_group_num": 2,
29
+ "num_attention_heads": 32,
30
+ "num_layers": 28,
31
+ "original_rope": true,
32
+ "pad_token_id": 0,
33
+ "padded_vocab_size": 65024,
34
+ "post_layer_norm": true,
35
+ "pre_seq_len": 128,
36
+ "prefix_projection": false,
37
+ "quantization_bit": 4,
38
+ "rmsnorm": true,
39
+ "seq_length": 32768,
40
+ "tie_word_embeddings": false,
41
+ "torch_dtype": "float16",
42
+ "transformers_version": "4.27.1",
43
+ "use_cache": true,
44
+ "vocab_size": 65024
45
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/configuration_chatglm.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+
4
+ class ChatGLMConfig(PretrainedConfig):
5
+ model_type = "chatglm"
6
+ def __init__(
7
+ self,
8
+ num_layers=28,
9
+ padded_vocab_size=65024,
10
+ hidden_size=4096,
11
+ ffn_hidden_size=13696,
12
+ kv_channels=128,
13
+ num_attention_heads=32,
14
+ seq_length=2048,
15
+ hidden_dropout=0.0,
16
+ attention_dropout=0.0,
17
+ layernorm_epsilon=1e-5,
18
+ rmsnorm=True,
19
+ apply_residual_connection_post_layernorm=False,
20
+ post_layer_norm=True,
21
+ add_bias_linear=False,
22
+ add_qkv_bias=False,
23
+ bias_dropout_fusion=True,
24
+ multi_query_attention=False,
25
+ multi_query_group_num=1,
26
+ apply_query_key_layer_scaling=True,
27
+ attention_softmax_in_fp32=True,
28
+ fp32_residual_connection=False,
29
+ quantization_bit=0,
30
+ pre_seq_len=None,
31
+ prefix_projection=False,
32
+ **kwargs
33
+ ):
34
+ self.num_layers = num_layers
35
+ self.vocab_size = padded_vocab_size
36
+ self.padded_vocab_size = padded_vocab_size
37
+ self.hidden_size = hidden_size
38
+ self.ffn_hidden_size = ffn_hidden_size
39
+ self.kv_channels = kv_channels
40
+ self.num_attention_heads = num_attention_heads
41
+ self.seq_length = seq_length
42
+ self.hidden_dropout = hidden_dropout
43
+ self.attention_dropout = attention_dropout
44
+ self.layernorm_epsilon = layernorm_epsilon
45
+ self.rmsnorm = rmsnorm
46
+ self.apply_residual_connection_post_layernorm = apply_residual_connection_post_layernorm
47
+ self.post_layer_norm = post_layer_norm
48
+ self.add_bias_linear = add_bias_linear
49
+ self.add_qkv_bias = add_qkv_bias
50
+ self.bias_dropout_fusion = bias_dropout_fusion
51
+ self.multi_query_attention = multi_query_attention
52
+ self.multi_query_group_num = multi_query_group_num
53
+ self.apply_query_key_layer_scaling = apply_query_key_layer_scaling
54
+ self.attention_softmax_in_fp32 = attention_softmax_in_fp32
55
+ self.fp32_residual_connection = fp32_residual_connection
56
+ self.quantization_bit = quantization_bit
57
+ self.pre_seq_len = pre_seq_len
58
+ self.prefix_projection = prefix_projection
59
+ super().__init__(**kwargs)
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "eos_token_id": 2,
4
+ "pad_token_id": 0,
5
+ "transformers_version": "4.27.1"
6
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/modeling_chatglm.py ADDED
@@ -0,0 +1,1193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ PyTorch ChatGLM model. """
2
+
3
+ import math
4
+ import copy
5
+ import warnings
6
+ import re
7
+ import sys
8
+
9
+ import torch
10
+ import torch.utils.checkpoint
11
+ import torch.nn.functional as F
12
+ from torch import nn
13
+ from torch.nn import CrossEntropyLoss, LayerNorm
14
+ from torch.nn.utils import skip_init
15
+ from typing import Optional, Tuple, Union, List, Callable, Dict, Any
16
+
17
+ from transformers.modeling_outputs import (
18
+ BaseModelOutputWithPast,
19
+ CausalLMOutputWithPast,
20
+ )
21
+ from transformers.modeling_utils import PreTrainedModel
22
+ from transformers.utils import logging
23
+ from transformers.generation.logits_process import LogitsProcessor
24
+ from transformers.generation.utils import LogitsProcessorList, StoppingCriteriaList, GenerationConfig, ModelOutput
25
+
26
+ from .configuration_chatglm import ChatGLMConfig
27
+
28
+ # flags required to enable jit fusion kernels
29
+
30
+ if sys.platform != 'darwin':
31
+ torch._C._jit_set_profiling_mode(False)
32
+ torch._C._jit_set_profiling_executor(False)
33
+ torch._C._jit_override_can_fuse_on_cpu(True)
34
+ torch._C._jit_override_can_fuse_on_gpu(True)
35
+
36
+ logger = logging.get_logger(__name__)
37
+
38
+ _CHECKPOINT_FOR_DOC = "THUDM/ChatGLM2-6B"
39
+ _CONFIG_FOR_DOC = "ChatGLM6BConfig"
40
+
41
+ CHATGLM_6B_PRETRAINED_MODEL_ARCHIVE_LIST = [
42
+ "THUDM/chatglm2-6b",
43
+ # See all ChatGLM models at https://huggingface.co/models?filter=chatglm
44
+ ]
45
+
46
+
47
+ def default_init(cls, *args, **kwargs):
48
+ return cls(*args, **kwargs)
49
+
50
+
51
+ class InvalidScoreLogitsProcessor(LogitsProcessor):
52
+ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
53
+ if torch.isnan(scores).any() or torch.isinf(scores).any():
54
+ scores.zero_()
55
+ scores[..., 5] = 5e4
56
+ return scores
57
+
58
+
59
+ class PrefixEncoder(torch.nn.Module):
60
+ """
61
+ The torch.nn model to encode the prefix
62
+ Input shape: (batch-size, prefix-length)
63
+ Output shape: (batch-size, prefix-length, 2*layers*hidden)
64
+ """
65
+
66
+ def __init__(self, config: ChatGLMConfig):
67
+ super().__init__()
68
+ self.prefix_projection = config.prefix_projection
69
+ if self.prefix_projection:
70
+ # Use a two-layer MLP to encode the prefix
71
+ kv_size = config.num_layers * config.kv_channels * config.multi_query_group_num * 2
72
+ self.embedding = torch.nn.Embedding(config.pre_seq_len, kv_size)
73
+ self.trans = torch.nn.Sequential(
74
+ torch.nn.Linear(kv_size, config.hidden_size),
75
+ torch.nn.Tanh(),
76
+ torch.nn.Linear(config.hidden_size, kv_size)
77
+ )
78
+ else:
79
+ self.embedding = torch.nn.Embedding(config.pre_seq_len,
80
+ config.num_layers * config.kv_channels * config.multi_query_group_num * 2)
81
+
82
+ def forward(self, prefix: torch.Tensor):
83
+ if self.prefix_projection:
84
+ prefix_tokens = self.embedding(prefix)
85
+ past_key_values = self.trans(prefix_tokens)
86
+ else:
87
+ past_key_values = self.embedding(prefix)
88
+ return past_key_values
89
+
90
+
91
+ def split_tensor_along_last_dim(
92
+ tensor: torch.Tensor,
93
+ num_partitions: int,
94
+ contiguous_split_chunks: bool = False,
95
+ ) -> List[torch.Tensor]:
96
+ """Split a tensor along its last dimension.
97
+
98
+ Arguments:
99
+ tensor: input tensor.
100
+ num_partitions: number of partitions to split the tensor
101
+ contiguous_split_chunks: If True, make each chunk contiguous
102
+ in memory.
103
+
104
+ Returns:
105
+ A list of Tensors
106
+ """
107
+ # Get the size and dimension.
108
+ last_dim = tensor.dim() - 1
109
+ last_dim_size = tensor.size()[last_dim] // num_partitions
110
+ # Split.
111
+ tensor_list = torch.split(tensor, last_dim_size, dim=last_dim)
112
+ # Note: torch.split does not create contiguous tensors by default.
113
+ if contiguous_split_chunks:
114
+ return tuple(chunk.contiguous() for chunk in tensor_list)
115
+
116
+ return tensor_list
117
+
118
+
119
+ class RotaryEmbedding(nn.Module):
120
+ def __init__(self, dim, original_impl=False, device=None, dtype=None):
121
+ super().__init__()
122
+ inv_freq = 1.0 / (10000 ** (torch.arange(0, dim, 2, device=device).to(dtype=dtype) / dim))
123
+ self.register_buffer("inv_freq", inv_freq)
124
+ self.dim = dim
125
+ self.original_impl = original_impl
126
+
127
+ def forward_impl(
128
+ self, seq_len: int, n_elem: int, dtype: torch.dtype, device: torch.device, base: int = 10000
129
+ ):
130
+ """Enhanced Transformer with Rotary Position Embedding.
131
+
132
+ Derived from: https://github.com/labmlai/annotated_deep_learning_paper_implementations/blob/master/labml_nn/
133
+ transformers/rope/__init__.py. MIT License:
134
+ https://github.com/labmlai/annotated_deep_learning_paper_implementations/blob/master/license.
135
+ """
136
+ # $\Theta = {\theta_i = 10000^{\frac{2(i-1)}{d}}, i \in [1, 2, ..., \frac{d}{2}]}$
137
+ theta = 1.0 / (base ** (torch.arange(0, n_elem, 2, dtype=dtype, device=device) / n_elem))
138
+
139
+ # Create position indexes `[0, 1, ..., seq_len - 1]`
140
+ seq_idx = torch.arange(seq_len, dtype=dtype, device=device)
141
+
142
+ # Calculate the product of position index and $\theta_i$
143
+ idx_theta = torch.outer(seq_idx, theta).float()
144
+
145
+ cache = torch.stack([torch.cos(idx_theta), torch.sin(idx_theta)], dim=-1)
146
+
147
+ # this is to mimic the behaviour of complex32, else we will get different results
148
+ if dtype in (torch.float16, torch.bfloat16, torch.int8):
149
+ cache = cache.bfloat16() if dtype == torch.bfloat16 else cache.half()
150
+ return cache
151
+
152
+ def forward(self, max_seq_len, offset=0):
153
+ return self.forward_impl(
154
+ max_seq_len, self.dim, dtype=self.inv_freq.dtype, device=self.inv_freq.device
155
+ )
156
+
157
+
158
+ @torch.jit.script
159
+ def apply_rotary_pos_emb(x: torch.Tensor, rope_cache: torch.Tensor) -> torch.Tensor:
160
+ # x: [sq, b, np, hn]
161
+ sq, b, np, hn = x.size(0), x.size(1), x.size(2), x.size(3)
162
+ rot_dim = rope_cache.shape[-2] * 2
163
+ x, x_pass = x[..., :rot_dim], x[..., rot_dim:]
164
+ # truncate to support variable sizes
165
+ rope_cache = rope_cache[:sq]
166
+ xshaped = x.reshape(sq, -1, np, rot_dim // 2, 2)
167
+ rope_cache = rope_cache.view(sq, -1, 1, xshaped.size(3), 2)
168
+ x_out2 = torch.stack(
169
+ [
170
+ xshaped[..., 0] * rope_cache[..., 0] - xshaped[..., 1] * rope_cache[..., 1],
171
+ xshaped[..., 1] * rope_cache[..., 0] + xshaped[..., 0] * rope_cache[..., 1],
172
+ ],
173
+ -1,
174
+ )
175
+ x_out2 = x_out2.flatten(3)
176
+ return torch.cat((x_out2, x_pass), dim=-1)
177
+
178
+
179
+ class RMSNorm(torch.nn.Module):
180
+ def __init__(self, normalized_shape, eps=1e-5, device=None, dtype=None, **kwargs):
181
+ super().__init__()
182
+ self.weight = torch.nn.Parameter(torch.empty(normalized_shape, device=device, dtype=dtype))
183
+ self.eps = eps
184
+
185
+ def forward(self, hidden_states: torch.Tensor):
186
+ input_dtype = hidden_states.dtype
187
+ variance = hidden_states.to(torch.float32).pow(2).mean(-1, keepdim=True)
188
+ hidden_states = hidden_states * torch.rsqrt(variance + self.eps)
189
+
190
+ return (self.weight * hidden_states).to(input_dtype)
191
+
192
+
193
+ class CoreAttention(torch.nn.Module):
194
+ def __init__(self, config: ChatGLMConfig, layer_number):
195
+ super(CoreAttention, self).__init__()
196
+
197
+ self.apply_query_key_layer_scaling = config.apply_query_key_layer_scaling
198
+ self.attention_softmax_in_fp32 = config.attention_softmax_in_fp32
199
+ if self.apply_query_key_layer_scaling:
200
+ self.attention_softmax_in_fp32 = True
201
+ self.layer_number = max(1, layer_number)
202
+
203
+ projection_size = config.kv_channels * config.num_attention_heads
204
+
205
+ # Per attention head and per partition values.
206
+ self.hidden_size_per_partition = projection_size
207
+ self.hidden_size_per_attention_head = projection_size // config.num_attention_heads
208
+ self.num_attention_heads_per_partition = config.num_attention_heads
209
+
210
+ coeff = None
211
+ self.norm_factor = math.sqrt(self.hidden_size_per_attention_head)
212
+ if self.apply_query_key_layer_scaling:
213
+ coeff = self.layer_number
214
+ self.norm_factor *= coeff
215
+ self.coeff = coeff
216
+
217
+ self.attention_dropout = torch.nn.Dropout(config.attention_dropout)
218
+
219
+ def forward(self, query_layer, key_layer, value_layer, attention_mask):
220
+ pytorch_major_version = int(torch.__version__.split('.')[0])
221
+ if pytorch_major_version >= 2:
222
+ query_layer, key_layer, value_layer = [k.permute(1, 2, 0, 3) for k in [query_layer, key_layer, value_layer]]
223
+ if attention_mask is None and query_layer.shape[2] == key_layer.shape[2]:
224
+ context_layer = torch.nn.functional.scaled_dot_product_attention(query_layer, key_layer, value_layer,
225
+ is_causal=True)
226
+ else:
227
+ if attention_mask is not None:
228
+ attention_mask = ~attention_mask
229
+ context_layer = torch.nn.functional.scaled_dot_product_attention(query_layer, key_layer, value_layer,
230
+ attention_mask)
231
+ context_layer = context_layer.permute(2, 0, 1, 3)
232
+ new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size_per_partition,)
233
+ context_layer = context_layer.reshape(*new_context_layer_shape)
234
+ else:
235
+ # Raw attention scores
236
+
237
+ # [b, np, sq, sk]
238
+ output_size = (query_layer.size(1), query_layer.size(2), query_layer.size(0), key_layer.size(0))
239
+
240
+ # [sq, b, np, hn] -> [sq, b * np, hn]
241
+ query_layer = query_layer.view(output_size[2], output_size[0] * output_size[1], -1)
242
+ # [sk, b, np, hn] -> [sk, b * np, hn]
243
+ key_layer = key_layer.view(output_size[3], output_size[0] * output_size[1], -1)
244
+
245
+ # preallocting input tensor: [b * np, sq, sk]
246
+ matmul_input_buffer = torch.empty(
247
+ output_size[0] * output_size[1], output_size[2], output_size[3], dtype=query_layer.dtype,
248
+ device=query_layer.device
249
+ )
250
+
251
+ # Raw attention scores. [b * np, sq, sk]
252
+ matmul_result = torch.baddbmm(
253
+ matmul_input_buffer,
254
+ query_layer.transpose(0, 1), # [b * np, sq, hn]
255
+ key_layer.transpose(0, 1).transpose(1, 2), # [b * np, hn, sk]
256
+ beta=0.0,
257
+ alpha=(1.0 / self.norm_factor),
258
+ )
259
+
260
+ # change view to [b, np, sq, sk]
261
+ attention_scores = matmul_result.view(*output_size)
262
+
263
+ # ===========================
264
+ # Attention probs and dropout
265
+ # ===========================
266
+
267
+ # attention scores and attention mask [b, np, sq, sk]
268
+ if self.attention_softmax_in_fp32:
269
+ attention_scores = attention_scores.float()
270
+ if self.coeff is not None:
271
+ attention_scores = attention_scores * self.coeff
272
+ if attention_mask is None and attention_scores.shape[2] == attention_scores.shape[3]:
273
+ attention_mask = torch.ones(output_size[0], 1, output_size[2], output_size[3],
274
+ device=attention_scores.device, dtype=torch.bool)
275
+ attention_mask.tril_()
276
+ attention_mask = ~attention_mask
277
+ if attention_mask is not None:
278
+ attention_scores = attention_scores.masked_fill(attention_mask, float("-inf"))
279
+ attention_probs = F.softmax(attention_scores, dim=-1)
280
+ attention_probs = attention_probs.type_as(value_layer)
281
+
282
+ # This is actually dropping out entire tokens to attend to, which might
283
+ # seem a bit unusual, but is taken from the original Transformer paper.
284
+ attention_probs = self.attention_dropout(attention_probs)
285
+ # =========================
286
+ # Context layer. [sq, b, hp]
287
+ # =========================
288
+
289
+ # value_layer -> context layer.
290
+ # [sk, b, np, hn] --> [b, np, sq, hn]
291
+
292
+ # context layer shape: [b, np, sq, hn]
293
+ output_size = (value_layer.size(1), value_layer.size(2), query_layer.size(0), value_layer.size(3))
294
+ # change view [sk, b * np, hn]
295
+ value_layer = value_layer.view(value_layer.size(0), output_size[0] * output_size[1], -1)
296
+ # change view [b * np, sq, sk]
297
+ attention_probs = attention_probs.view(output_size[0] * output_size[1], output_size[2], -1)
298
+ # matmul: [b * np, sq, hn]
299
+ context_layer = torch.bmm(attention_probs, value_layer.transpose(0, 1))
300
+ # change view [b, np, sq, hn]
301
+ context_layer = context_layer.view(*output_size)
302
+ # [b, np, sq, hn] --> [sq, b, np, hn]
303
+ context_layer = context_layer.permute(2, 0, 1, 3).contiguous()
304
+ # [sq, b, np, hn] --> [sq, b, hp]
305
+ new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size_per_partition,)
306
+ context_layer = context_layer.view(*new_context_layer_shape)
307
+
308
+ return context_layer
309
+
310
+
311
+ class SelfAttention(torch.nn.Module):
312
+ """Parallel self-attention layer abstract class.
313
+
314
+ Self-attention layer takes input with size [s, b, h]
315
+ and returns output of the same size.
316
+ """
317
+
318
+ def __init__(self, config: ChatGLMConfig, layer_number, device=None):
319
+ super(SelfAttention, self).__init__()
320
+ self.layer_number = max(1, layer_number)
321
+
322
+ self.projection_size = config.kv_channels * config.num_attention_heads
323
+
324
+ # Per attention head and per partition values.
325
+ self.hidden_size_per_attention_head = self.projection_size // config.num_attention_heads
326
+ self.num_attention_heads_per_partition = config.num_attention_heads
327
+
328
+ self.multi_query_attention = config.multi_query_attention
329
+ self.qkv_hidden_size = 3 * self.projection_size
330
+ if self.multi_query_attention:
331
+ self.num_multi_query_groups_per_partition = config.multi_query_group_num
332
+ self.qkv_hidden_size = (
333
+ self.projection_size + 2 * self.hidden_size_per_attention_head * config.multi_query_group_num
334
+ )
335
+ self.query_key_value = nn.Linear(config.hidden_size, self.qkv_hidden_size,
336
+ bias=config.add_bias_linear or config.add_qkv_bias,
337
+ device=device, **_config_to_kwargs(config)
338
+ )
339
+
340
+ self.core_attention = CoreAttention(config, self.layer_number)
341
+
342
+ # Output.
343
+ self.dense = nn.Linear(self.projection_size, config.hidden_size, bias=config.add_bias_linear,
344
+ device=device, **_config_to_kwargs(config)
345
+ )
346
+
347
+ def _allocate_memory(self, inference_max_sequence_len, batch_size, device=None, dtype=None):
348
+ if self.multi_query_attention:
349
+ num_attention_heads = self.num_multi_query_groups_per_partition
350
+ else:
351
+ num_attention_heads = self.num_attention_heads_per_partition
352
+ return torch.empty(
353
+ inference_max_sequence_len,
354
+ batch_size,
355
+ num_attention_heads,
356
+ self.hidden_size_per_attention_head,
357
+ dtype=dtype,
358
+ device=device,
359
+ )
360
+
361
+ def forward(
362
+ self, hidden_states, attention_mask, rotary_pos_emb, kv_cache=None, use_cache=True
363
+ ):
364
+ # hidden_states: [sq, b, h]
365
+
366
+ # =================================================
367
+ # Pre-allocate memory for key-values for inference.
368
+ # =================================================
369
+ # =====================
370
+ # Query, Key, and Value
371
+ # =====================
372
+
373
+ # Attention heads [sq, b, h] --> [sq, b, (np * 3 * hn)]
374
+ mixed_x_layer = self.query_key_value(hidden_states)
375
+
376
+ if self.multi_query_attention:
377
+ (query_layer, key_layer, value_layer) = mixed_x_layer.split(
378
+ [
379
+ self.num_attention_heads_per_partition * self.hidden_size_per_attention_head,
380
+ self.num_multi_query_groups_per_partition * self.hidden_size_per_attention_head,
381
+ self.num_multi_query_groups_per_partition * self.hidden_size_per_attention_head,
382
+ ],
383
+ dim=-1,
384
+ )
385
+ query_layer = query_layer.view(
386
+ query_layer.size()[:-1] + (self.num_attention_heads_per_partition, self.hidden_size_per_attention_head)
387
+ )
388
+ key_layer = key_layer.view(
389
+ key_layer.size()[:-1] + (self.num_multi_query_groups_per_partition, self.hidden_size_per_attention_head)
390
+ )
391
+ value_layer = value_layer.view(
392
+ value_layer.size()[:-1]
393
+ + (self.num_multi_query_groups_per_partition, self.hidden_size_per_attention_head)
394
+ )
395
+ else:
396
+ new_tensor_shape = mixed_x_layer.size()[:-1] + \
397
+ (self.num_attention_heads_per_partition,
398
+ 3 * self.hidden_size_per_attention_head)
399
+ mixed_x_layer = mixed_x_layer.view(*new_tensor_shape)
400
+
401
+ # [sq, b, np, 3 * hn] --> 3 [sq, b, np, hn]
402
+ (query_layer, key_layer, value_layer) = split_tensor_along_last_dim(mixed_x_layer, 3)
403
+
404
+ # apply relative positional encoding (rotary embedding)
405
+ if rotary_pos_emb is not None:
406
+ query_layer = apply_rotary_pos_emb(query_layer, rotary_pos_emb)
407
+ key_layer = apply_rotary_pos_emb(key_layer, rotary_pos_emb)
408
+
409
+ # adjust key and value for inference
410
+ if kv_cache is not None:
411
+ cache_k, cache_v = kv_cache
412
+ key_layer = torch.cat((cache_k, key_layer), dim=0)
413
+ value_layer = torch.cat((cache_v, value_layer), dim=0)
414
+ if use_cache:
415
+ kv_cache = (key_layer, value_layer)
416
+ else:
417
+ kv_cache = None
418
+
419
+ if self.multi_query_attention:
420
+ key_layer = key_layer.unsqueeze(-2)
421
+ key_layer = key_layer.expand(
422
+ -1, -1, -1, self.num_attention_heads_per_partition // self.num_multi_query_groups_per_partition, -1
423
+ )
424
+ key_layer = key_layer.contiguous().view(
425
+ key_layer.size()[:2] + (self.num_attention_heads_per_partition, self.hidden_size_per_attention_head)
426
+ )
427
+ value_layer = value_layer.unsqueeze(-2)
428
+ value_layer = value_layer.expand(
429
+ -1, -1, -1, self.num_attention_heads_per_partition // self.num_multi_query_groups_per_partition, -1
430
+ )
431
+ value_layer = value_layer.contiguous().view(
432
+ value_layer.size()[:2] + (self.num_attention_heads_per_partition, self.hidden_size_per_attention_head)
433
+ )
434
+
435
+ # ==================================
436
+ # core attention computation
437
+ # ==================================
438
+
439
+ context_layer = self.core_attention(query_layer, key_layer, value_layer, attention_mask)
440
+
441
+ # =================
442
+ # Output. [sq, b, h]
443
+ # =================
444
+
445
+ output = self.dense(context_layer)
446
+
447
+ return output, kv_cache
448
+
449
+
450
+ def _config_to_kwargs(args):
451
+ common_kwargs = {
452
+ "dtype": args.torch_dtype,
453
+ }
454
+ return common_kwargs
455
+
456
+
457
+ class MLP(torch.nn.Module):
458
+ """MLP.
459
+
460
+ MLP will take the input with h hidden state, project it to 4*h
461
+ hidden dimension, perform nonlinear transformation, and project the
462
+ state back into h hidden dimension.
463
+ """
464
+
465
+ def __init__(self, config: ChatGLMConfig, device=None):
466
+ super(MLP, self).__init__()
467
+
468
+ self.add_bias = config.add_bias_linear
469
+
470
+ # Project to 4h. If using swiglu double the output width, see https://arxiv.org/pdf/2002.05202.pdf
471
+ self.dense_h_to_4h = nn.Linear(
472
+ config.hidden_size,
473
+ config.ffn_hidden_size * 2,
474
+ bias=self.add_bias,
475
+ device=device,
476
+ **_config_to_kwargs(config)
477
+ )
478
+
479
+ def swiglu(x):
480
+ x = torch.chunk(x, 2, dim=-1)
481
+ return F.silu(x[0]) * x[1]
482
+
483
+ self.activation_func = swiglu
484
+
485
+ # Project back to h.
486
+ self.dense_4h_to_h = nn.Linear(
487
+ config.ffn_hidden_size,
488
+ config.hidden_size,
489
+ bias=self.add_bias,
490
+ device=device,
491
+ **_config_to_kwargs(config)
492
+ )
493
+
494
+ def forward(self, hidden_states):
495
+ # [s, b, 4hp]
496
+ intermediate_parallel = self.dense_h_to_4h(hidden_states)
497
+ intermediate_parallel = self.activation_func(intermediate_parallel)
498
+ # [s, b, h]
499
+ output = self.dense_4h_to_h(intermediate_parallel)
500
+ return output
501
+
502
+
503
+ class GLMBlock(torch.nn.Module):
504
+ """A single transformer layer.
505
+
506
+ Transformer layer takes input with size [s, b, h] and returns an
507
+ output of the same size.
508
+ """
509
+
510
+ def __init__(self, config: ChatGLMConfig, layer_number, device=None):
511
+ super(GLMBlock, self).__init__()
512
+ self.layer_number = layer_number
513
+
514
+ self.apply_residual_connection_post_layernorm = config.apply_residual_connection_post_layernorm
515
+
516
+ self.fp32_residual_connection = config.fp32_residual_connection
517
+
518
+ LayerNormFunc = RMSNorm if config.rmsnorm else LayerNorm
519
+ # Layernorm on the input data.
520
+ self.input_layernorm = LayerNormFunc(config.hidden_size, eps=config.layernorm_epsilon, device=device,
521
+ dtype=config.torch_dtype)
522
+
523
+ # Self attention.
524
+ self.self_attention = SelfAttention(config, layer_number, device=device)
525
+ self.hidden_dropout = config.hidden_dropout
526
+
527
+ # Layernorm on the attention output
528
+ self.post_attention_layernorm = LayerNormFunc(config.hidden_size, eps=config.layernorm_epsilon, device=device,
529
+ dtype=config.torch_dtype)
530
+
531
+ # MLP
532
+ self.mlp = MLP(config, device=device)
533
+
534
+ def forward(
535
+ self, hidden_states, attention_mask, rotary_pos_emb, kv_cache=None, use_cache=True,
536
+ ):
537
+ # hidden_states: [s, b, h]
538
+
539
+ # Layer norm at the beginning of the transformer layer.
540
+ layernorm_output = self.input_layernorm(hidden_states)
541
+ # Self attention.
542
+ attention_output, kv_cache = self.self_attention(
543
+ layernorm_output,
544
+ attention_mask,
545
+ rotary_pos_emb,
546
+ kv_cache=kv_cache,
547
+ use_cache=use_cache
548
+ )
549
+
550
+ # Residual connection.
551
+ if self.apply_residual_connection_post_layernorm:
552
+ residual = layernorm_output
553
+ else:
554
+ residual = hidden_states
555
+
556
+ layernorm_input = torch.nn.functional.dropout(attention_output, p=self.hidden_dropout, training=self.training)
557
+ layernorm_input = residual + layernorm_input
558
+
559
+ # Layer norm post the self attention.
560
+ layernorm_output = self.post_attention_layernorm(layernorm_input)
561
+
562
+ # MLP.
563
+ mlp_output = self.mlp(layernorm_output)
564
+
565
+ # Second residual connection.
566
+ if self.apply_residual_connection_post_layernorm:
567
+ residual = layernorm_output
568
+ else:
569
+ residual = layernorm_input
570
+
571
+ output = torch.nn.functional.dropout(mlp_output, p=self.hidden_dropout, training=self.training)
572
+ output = residual + output
573
+
574
+ return output, kv_cache
575
+
576
+
577
+ class GLMTransformer(torch.nn.Module):
578
+ """Transformer class."""
579
+
580
+ def __init__(self, config: ChatGLMConfig, device=None):
581
+ super(GLMTransformer, self).__init__()
582
+
583
+ self.fp32_residual_connection = config.fp32_residual_connection
584
+ self.post_layer_norm = config.post_layer_norm
585
+
586
+ # Number of layers.
587
+ self.num_layers = config.num_layers
588
+
589
+ # Transformer layers.
590
+ def build_layer(layer_number):
591
+ return GLMBlock(config, layer_number, device=device)
592
+
593
+ self.layers = torch.nn.ModuleList([build_layer(i + 1) for i in range(self.num_layers)])
594
+
595
+ if self.post_layer_norm:
596
+ LayerNormFunc = RMSNorm if config.rmsnorm else LayerNorm
597
+ # Final layer norm before output.
598
+ self.final_layernorm = LayerNormFunc(config.hidden_size, eps=config.layernorm_epsilon, device=device,
599
+ dtype=config.torch_dtype)
600
+
601
+ self.gradient_checkpointing = False
602
+
603
+ def _get_layer(self, layer_number):
604
+ return self.layers[layer_number]
605
+
606
+ def forward(
607
+ self, hidden_states, attention_mask, rotary_pos_emb, kv_caches=None,
608
+ use_cache: Optional[bool] = True,
609
+ output_hidden_states: Optional[bool] = False,
610
+ ):
611
+ if not kv_caches:
612
+ kv_caches = [None for _ in range(self.num_layers)]
613
+ presents = () if use_cache else None
614
+ if self.gradient_checkpointing and self.training:
615
+ if use_cache:
616
+ logger.warning_once(
617
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
618
+ )
619
+ use_cache = False
620
+
621
+ all_self_attentions = None
622
+ all_hidden_states = () if output_hidden_states else None
623
+ for index in range(self.num_layers):
624
+ if output_hidden_states:
625
+ all_hidden_states = all_hidden_states + (hidden_states,)
626
+
627
+ layer = self._get_layer(index)
628
+ if self.gradient_checkpointing and self.training:
629
+ layer_ret = torch.utils.checkpoint.checkpoint(
630
+ layer,
631
+ hidden_states,
632
+ attention_mask,
633
+ rotary_pos_emb,
634
+ kv_caches[index],
635
+ use_cache
636
+ )
637
+ else:
638
+ layer_ret = layer(
639
+ hidden_states,
640
+ attention_mask,
641
+ rotary_pos_emb,
642
+ kv_cache=kv_caches[index],
643
+ use_cache=use_cache
644
+ )
645
+ hidden_states, kv_cache = layer_ret
646
+ if use_cache:
647
+ presents = presents + (kv_cache,)
648
+
649
+ if output_hidden_states:
650
+ all_hidden_states = all_hidden_states + (hidden_states,)
651
+
652
+ # Final layer norm.
653
+ if self.post_layer_norm:
654
+ hidden_states = self.final_layernorm(hidden_states)
655
+
656
+ return hidden_states, presents, all_hidden_states, all_self_attentions
657
+
658
+
659
+ class ChatGLMPreTrainedModel(PreTrainedModel):
660
+ """
661
+ An abstract class to handle weights initialization and
662
+ a simple interface for downloading and loading pretrained models.
663
+ """
664
+
665
+ is_parallelizable = False
666
+ supports_gradient_checkpointing = True
667
+ config_class = ChatGLMConfig
668
+ base_model_prefix = "transformer"
669
+ _no_split_modules = ["GLMBlock"]
670
+
671
+ def _init_weights(self, module: nn.Module):
672
+ """Initialize the weights."""
673
+ return
674
+
675
+ def get_masks(self, input_ids, past_key_values, padding_mask=None):
676
+ batch_size, seq_length = input_ids.shape
677
+ full_attention_mask = torch.ones(batch_size, seq_length, seq_length, device=input_ids.device)
678
+ full_attention_mask.tril_()
679
+ past_length = 0
680
+ if past_key_values:
681
+ past_length = past_key_values[0][0].shape[0]
682
+ if past_length:
683
+ full_attention_mask = torch.cat((torch.ones(batch_size, seq_length, past_length,
684
+ device=input_ids.device), full_attention_mask), dim=-1)
685
+ if padding_mask is not None:
686
+ full_attention_mask = full_attention_mask * padding_mask.unsqueeze(1)
687
+ if not past_length and padding_mask is not None:
688
+ full_attention_mask -= padding_mask.unsqueeze(-1) - 1
689
+ full_attention_mask = (full_attention_mask < 0.5).bool()
690
+ full_attention_mask.unsqueeze_(1)
691
+ return full_attention_mask
692
+
693
+ def get_position_ids(self, input_ids, device):
694
+ batch_size, seq_length = input_ids.shape
695
+ position_ids = torch.arange(seq_length, dtype=torch.long, device=device).unsqueeze(0).repeat(batch_size, 1)
696
+ return position_ids
697
+
698
+ def _set_gradient_checkpointing(self, module, value=False):
699
+ if isinstance(module, GLMTransformer):
700
+ module.gradient_checkpointing = value
701
+
702
+
703
+ class Embedding(torch.nn.Module):
704
+ """Language model embeddings."""
705
+
706
+ def __init__(self, config: ChatGLMConfig, device=None):
707
+ super(Embedding, self).__init__()
708
+
709
+ self.hidden_size = config.hidden_size
710
+ # Word embeddings (parallel).
711
+ self.word_embeddings = nn.Embedding(
712
+ config.padded_vocab_size,
713
+ self.hidden_size,
714
+ dtype=config.torch_dtype,
715
+ device=device
716
+ )
717
+ self.fp32_residual_connection = config.fp32_residual_connection
718
+
719
+ def forward(self, input_ids):
720
+ # Embeddings.
721
+ words_embeddings = self.word_embeddings(input_ids)
722
+ embeddings = words_embeddings
723
+ # Data format change to avoid explicit tranposes : [b s h] --> [s b h].
724
+ embeddings = embeddings.transpose(0, 1).contiguous()
725
+ # If the input flag for fp32 residual connection is set, convert for float.
726
+ if self.fp32_residual_connection:
727
+ embeddings = embeddings.float()
728
+ return embeddings
729
+
730
+
731
+ class ChatGLMModel(ChatGLMPreTrainedModel):
732
+ def __init__(self, config: ChatGLMConfig, device=None, empty_init=True):
733
+ super().__init__(config)
734
+ if empty_init:
735
+ init_method = skip_init
736
+ else:
737
+ init_method = default_init
738
+ init_kwargs = {}
739
+ if device is not None:
740
+ init_kwargs["device"] = device
741
+ self.embedding = init_method(Embedding, config, **init_kwargs)
742
+ self.num_layers = config.num_layers
743
+ self.multi_query_group_num = config.multi_query_group_num
744
+ self.kv_channels = config.kv_channels
745
+
746
+ # Rotary positional embeddings
747
+ self.seq_length = config.seq_length
748
+ rotary_dim = (
749
+ config.hidden_size // config.num_attention_heads if config.kv_channels is None else config.kv_channels
750
+ )
751
+
752
+ self.rotary_pos_emb = RotaryEmbedding(rotary_dim // 2, original_impl=config.original_rope, device=device,
753
+ dtype=config.torch_dtype)
754
+ self.encoder = init_method(GLMTransformer, config, **init_kwargs)
755
+ self.output_layer = init_method(nn.Linear, config.hidden_size, config.padded_vocab_size, bias=False,
756
+ dtype=config.torch_dtype, **init_kwargs)
757
+ self.pre_seq_len = config.pre_seq_len
758
+ self.prefix_projection = config.prefix_projection
759
+ if self.pre_seq_len is not None:
760
+ for param in self.parameters():
761
+ param.requires_grad = False
762
+ self.prefix_tokens = torch.arange(self.pre_seq_len).long()
763
+ self.prefix_encoder = PrefixEncoder(config)
764
+ self.dropout = torch.nn.Dropout(0.1)
765
+
766
+ def get_input_embeddings(self):
767
+ return self.embedding.word_embeddings
768
+
769
+ def get_prompt(self, batch_size, device, dtype=torch.half):
770
+ prefix_tokens = self.prefix_tokens.unsqueeze(0).expand(batch_size, -1).to(device)
771
+ past_key_values = self.prefix_encoder(prefix_tokens).type(dtype)
772
+ past_key_values = past_key_values.view(
773
+ batch_size,
774
+ self.pre_seq_len,
775
+ self.num_layers * 2,
776
+ self.multi_query_group_num,
777
+ self.kv_channels
778
+ )
779
+ # seq_len, b, nh, hidden_size
780
+ past_key_values = self.dropout(past_key_values)
781
+ past_key_values = past_key_values.permute([2, 1, 0, 3, 4]).split(2)
782
+ return past_key_values
783
+
784
+ def forward(
785
+ self,
786
+ input_ids,
787
+ position_ids: Optional[torch.Tensor] = None,
788
+ attention_mask: Optional[torch.BoolTensor] = None,
789
+ full_attention_mask: Optional[torch.BoolTensor] = None,
790
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
791
+ inputs_embeds: Optional[torch.Tensor] = None,
792
+ use_cache: Optional[bool] = None,
793
+ output_hidden_states: Optional[bool] = None,
794
+ return_dict: Optional[bool] = None,
795
+ ):
796
+ output_hidden_states = (
797
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
798
+ )
799
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
800
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
801
+
802
+ batch_size, seq_length = input_ids.shape
803
+
804
+ if inputs_embeds is None:
805
+ inputs_embeds = self.embedding(input_ids)
806
+
807
+ if self.pre_seq_len is not None:
808
+ if past_key_values is None:
809
+ past_key_values = self.get_prompt(batch_size=batch_size, device=input_ids.device,
810
+ dtype=inputs_embeds.dtype)
811
+ if attention_mask is not None:
812
+ attention_mask = torch.cat([attention_mask.new_ones((batch_size, self.pre_seq_len)),
813
+ attention_mask], dim=-1)
814
+
815
+ if full_attention_mask is None:
816
+ if (attention_mask is not None and not attention_mask.all()) or (past_key_values and seq_length != 1):
817
+ full_attention_mask = self.get_masks(input_ids, past_key_values, padding_mask=attention_mask)
818
+
819
+ # Rotary positional embeddings
820
+ rotary_pos_emb = self.rotary_pos_emb(self.seq_length)
821
+ if position_ids is not None:
822
+ rotary_pos_emb = rotary_pos_emb[position_ids]
823
+ else:
824
+ rotary_pos_emb = rotary_pos_emb[None, :seq_length]
825
+ rotary_pos_emb = rotary_pos_emb.transpose(0, 1).contiguous()
826
+
827
+ # Run encoder.
828
+ hidden_states, presents, all_hidden_states, all_self_attentions = self.encoder(
829
+ inputs_embeds, full_attention_mask, rotary_pos_emb=rotary_pos_emb,
830
+ kv_caches=past_key_values, use_cache=use_cache, output_hidden_states=output_hidden_states
831
+ )
832
+
833
+ if not return_dict:
834
+ return tuple(v for v in [hidden_states, presents, all_hidden_states, all_self_attentions] if v is not None)
835
+
836
+ return BaseModelOutputWithPast(
837
+ last_hidden_state=hidden_states,
838
+ past_key_values=presents,
839
+ hidden_states=all_hidden_states,
840
+ attentions=all_self_attentions,
841
+ )
842
+
843
+ def quantize(self, weight_bit_width: int):
844
+ from .quantization import quantize
845
+ quantize(self.encoder, weight_bit_width)
846
+ return self
847
+
848
+
849
+ class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel):
850
+ def __init__(self, config: ChatGLMConfig, empty_init=True, device=None):
851
+ super().__init__(config)
852
+
853
+ self.max_sequence_length = config.max_length
854
+ self.transformer = ChatGLMModel(config, empty_init=empty_init, device=device)
855
+ self.config = config
856
+ self.quantized = False
857
+
858
+ if self.config.quantization_bit:
859
+ self.quantize(self.config.quantization_bit, empty_init=True)
860
+
861
+ def _update_model_kwargs_for_generation(
862
+ self,
863
+ outputs: ModelOutput,
864
+ model_kwargs: Dict[str, Any],
865
+ is_encoder_decoder: bool = False,
866
+ standardize_cache_format: bool = False,
867
+ ) -> Dict[str, Any]:
868
+ # update past_key_values
869
+ model_kwargs["past_key_values"] = self._extract_past_from_model_output(
870
+ outputs, standardize_cache_format=standardize_cache_format
871
+ )
872
+
873
+ # update attention mask
874
+ if "attention_mask" in model_kwargs:
875
+ attention_mask = model_kwargs["attention_mask"]
876
+ model_kwargs["attention_mask"] = torch.cat(
877
+ [attention_mask, attention_mask.new_ones((attention_mask.shape[0], 1))], dim=-1
878
+ )
879
+
880
+ # update position ids
881
+ if "position_ids" in model_kwargs:
882
+ position_ids = model_kwargs["position_ids"]
883
+ new_position_id = position_ids[..., -1:].clone()
884
+ new_position_id += 1
885
+ model_kwargs["position_ids"] = torch.cat(
886
+ [position_ids, new_position_id], dim=-1
887
+ )
888
+
889
+ model_kwargs["is_first_forward"] = False
890
+ return model_kwargs
891
+
892
+ def prepare_inputs_for_generation(
893
+ self,
894
+ input_ids: torch.LongTensor,
895
+ past_key_values: Optional[torch.Tensor] = None,
896
+ attention_mask: Optional[torch.Tensor] = None,
897
+ position_ids: Optional[torch.Tensor] = None,
898
+ is_first_forward: bool = True,
899
+ **kwargs
900
+ ) -> dict:
901
+ # only last token for input_ids if past is not None
902
+ if position_ids is None:
903
+ position_ids = self.get_position_ids(input_ids, device=input_ids.device)
904
+ if not is_first_forward:
905
+ position_ids = position_ids[..., -1:]
906
+ input_ids = input_ids[:, -1:]
907
+ return {
908
+ "input_ids": input_ids,
909
+ "past_key_values": past_key_values,
910
+ "position_ids": position_ids,
911
+ "attention_mask": attention_mask,
912
+ "return_last_logit": True
913
+ }
914
+
915
+ def forward(
916
+ self,
917
+ input_ids: Optional[torch.Tensor] = None,
918
+ position_ids: Optional[torch.Tensor] = None,
919
+ attention_mask: Optional[torch.Tensor] = None,
920
+ past_key_values: Optional[Tuple[torch.FloatTensor]] = None,
921
+ inputs_embeds: Optional[torch.Tensor] = None,
922
+ labels: Optional[torch.Tensor] = None,
923
+ use_cache: Optional[bool] = None,
924
+ output_attentions: Optional[bool] = None,
925
+ output_hidden_states: Optional[bool] = None,
926
+ return_dict: Optional[bool] = None,
927
+ return_last_logit: Optional[bool] = False,
928
+ ):
929
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
930
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
931
+
932
+ transformer_outputs = self.transformer(
933
+ input_ids=input_ids,
934
+ position_ids=position_ids,
935
+ attention_mask=attention_mask,
936
+ past_key_values=past_key_values,
937
+ inputs_embeds=inputs_embeds,
938
+ use_cache=use_cache,
939
+ output_hidden_states=output_hidden_states,
940
+ return_dict=return_dict,
941
+ )
942
+
943
+ hidden_states = transformer_outputs[0]
944
+ if return_last_logit:
945
+ hidden_states = hidden_states[-1:]
946
+ lm_logits = self.transformer.output_layer(hidden_states)
947
+ lm_logits = lm_logits.transpose(0, 1).contiguous()
948
+
949
+ loss = None
950
+ if labels is not None:
951
+ lm_logits = lm_logits.to(torch.float32)
952
+
953
+ # Shift so that tokens < n predict n
954
+ shift_logits = lm_logits[..., :-1, :].contiguous()
955
+ shift_labels = labels[..., 1:].contiguous()
956
+ # Flatten the tokens
957
+ loss_fct = CrossEntropyLoss(ignore_index=-100)
958
+ loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
959
+
960
+ lm_logits = lm_logits.to(hidden_states.dtype)
961
+ loss = loss.to(hidden_states.dtype)
962
+
963
+ if not return_dict:
964
+ output = (lm_logits,) + transformer_outputs[1:]
965
+ return ((loss,) + output) if loss is not None else output
966
+
967
+ return CausalLMOutputWithPast(
968
+ loss=loss,
969
+ logits=lm_logits,
970
+ past_key_values=transformer_outputs.past_key_values,
971
+ hidden_states=transformer_outputs.hidden_states,
972
+ attentions=transformer_outputs.attentions,
973
+ )
974
+
975
+ @staticmethod
976
+ def _reorder_cache(
977
+ past: Tuple[Tuple[torch.Tensor, torch.Tensor], ...], beam_idx: torch.LongTensor
978
+ ) -> Tuple[Tuple[torch.Tensor, torch.Tensor], ...]:
979
+ """
980
+ This function is used to re-order the `past_key_values` cache if [`~PreTrainedModel.beam_search`] or
981
+ [`~PreTrainedModel.beam_sample`] is called. This is required to match `past_key_values` with the correct
982
+ beam_idx at every generation step.
983
+
984
+ Output shares the same memory storage as `past`.
985
+ """
986
+ return tuple(
987
+ (
988
+ layer_past[0].index_select(1, beam_idx.to(layer_past[0].device)),
989
+ layer_past[1].index_select(1, beam_idx.to(layer_past[1].device)),
990
+ )
991
+ for layer_past in past
992
+ )
993
+
994
+ def process_response(self, response):
995
+ response = response.strip()
996
+ response = response.replace("[[训练时间]]", "2023年")
997
+ return response
998
+
999
+ def build_inputs(self, tokenizer, query: str, history: List[Tuple[str, str]] = None):
1000
+ prompt = tokenizer.build_prompt(query, history=history)
1001
+ inputs = tokenizer([prompt], return_tensors="pt")
1002
+ inputs = inputs.to(self.device)
1003
+ return inputs
1004
+
1005
+ def build_stream_inputs(self, tokenizer, query: str, history: List[Tuple[str, str]] = None):
1006
+ if history:
1007
+ prompt = "\n\n[Round {}]\n\n问:{}\n\n答:".format(len(history) + 1, query)
1008
+ input_ids = tokenizer.encode(prompt, add_special_tokens=False)
1009
+ input_ids = input_ids[1:]
1010
+ inputs = tokenizer.batch_encode_plus([(input_ids, None)], return_tensors="pt", add_special_tokens=False)
1011
+ else:
1012
+ prompt = "[Round {}]\n\n问:{}\n\n答:".format(len(history) + 1, query)
1013
+ inputs = tokenizer([prompt], return_tensors="pt")
1014
+ inputs = inputs.to(self.device)
1015
+ return inputs
1016
+
1017
+ @torch.inference_mode()
1018
+ def chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 8192, num_beams=1,
1019
+ do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, **kwargs):
1020
+ if history is None:
1021
+ history = []
1022
+ if logits_processor is None:
1023
+ logits_processor = LogitsProcessorList()
1024
+ logits_processor.append(InvalidScoreLogitsProcessor())
1025
+ gen_kwargs = {"max_length": max_length, "num_beams": num_beams, "do_sample": do_sample, "top_p": top_p,
1026
+ "temperature": temperature, "logits_processor": logits_processor, **kwargs}
1027
+ inputs = self.build_inputs(tokenizer, query, history=history)
1028
+ outputs = self.generate(**inputs, **gen_kwargs)
1029
+ outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):]
1030
+ response = tokenizer.decode(outputs)
1031
+ response = self.process_response(response)
1032
+ history = history + [(query, response)]
1033
+ return response, history
1034
+
1035
+ @torch.inference_mode()
1036
+ def stream_chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, past_key_values=None,
1037
+ max_length: int = 8192, do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None,
1038
+ return_past_key_values=False, **kwargs):
1039
+ if history is None:
1040
+ history = []
1041
+ if logits_processor is None:
1042
+ logits_processor = LogitsProcessorList()
1043
+ logits_processor.append(InvalidScoreLogitsProcessor())
1044
+ gen_kwargs = {"max_length": max_length, "do_sample": do_sample, "top_p": top_p,
1045
+ "temperature": temperature, "logits_processor": logits_processor, **kwargs}
1046
+ if past_key_values is None and not return_past_key_values:
1047
+ inputs = self.build_inputs(tokenizer, query, history=history)
1048
+ else:
1049
+ inputs = self.build_stream_inputs(tokenizer, query, history=history)
1050
+ if past_key_values is not None:
1051
+ past_length = past_key_values[0][0].shape[0]
1052
+ if self.transformer.pre_seq_len is not None:
1053
+ past_length -= self.transformer.pre_seq_len
1054
+ inputs.position_ids += past_length
1055
+ attention_mask = inputs.attention_mask
1056
+ attention_mask = torch.cat((attention_mask.new_ones(1, past_length), attention_mask), dim=1)
1057
+ inputs['attention_mask'] = attention_mask
1058
+ for outputs in self.stream_generate(**inputs, past_key_values=past_key_values,
1059
+ return_past_key_values=return_past_key_values, **gen_kwargs):
1060
+ if return_past_key_values:
1061
+ outputs, past_key_values = outputs
1062
+ outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):]
1063
+ response = tokenizer.decode(outputs)
1064
+ if response and response[-1] != "�":
1065
+ response = self.process_response(response)
1066
+ new_history = history + [(query, response)]
1067
+ if return_past_key_values:
1068
+ yield response, new_history, past_key_values
1069
+ else:
1070
+ yield response, new_history
1071
+
1072
+ @torch.inference_mode()
1073
+ def stream_generate(
1074
+ self,
1075
+ input_ids,
1076
+ generation_config: Optional[GenerationConfig] = None,
1077
+ logits_processor: Optional[LogitsProcessorList] = None,
1078
+ stopping_criteria: Optional[StoppingCriteriaList] = None,
1079
+ prefix_allowed_tokens_fn: Optional[Callable[[int, torch.Tensor], List[int]]] = None,
1080
+ return_past_key_values=False,
1081
+ **kwargs,
1082
+ ):
1083
+ batch_size, input_ids_seq_length = input_ids.shape[0], input_ids.shape[-1]
1084
+
1085
+ if generation_config is None:
1086
+ generation_config = self.generation_config
1087
+ generation_config = copy.deepcopy(generation_config)
1088
+ model_kwargs = generation_config.update(**kwargs)
1089
+ bos_token_id, eos_token_id = generation_config.bos_token_id, generation_config.eos_token_id
1090
+
1091
+ if isinstance(eos_token_id, int):
1092
+ eos_token_id = [eos_token_id]
1093
+
1094
+ has_default_max_length = kwargs.get("max_length") is None and generation_config.max_length is not None
1095
+ if has_default_max_length and generation_config.max_new_tokens is None:
1096
+ warnings.warn(
1097
+ f"Using `max_length`'s default ({generation_config.max_length}) to control the generation length. "
1098
+ "This behaviour is deprecated and will be removed from the config in v5 of Transformers -- we"
1099
+ " recommend using `max_new_tokens` to control the maximum length of the generation.",
1100
+ UserWarning,
1101
+ )
1102
+ elif generation_config.max_new_tokens is not None:
1103
+ generation_config.max_length = generation_config.max_new_tokens + input_ids_seq_length
1104
+ if not has_default_max_length:
1105
+ logger.warn(
1106
+ f"Both `max_new_tokens` (={generation_config.max_new_tokens}) and `max_length`(="
1107
+ f"{generation_config.max_length}) seem to have been set. `max_new_tokens` will take precedence. "
1108
+ "Please refer to the documentation for more information. "
1109
+ "(https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)",
1110
+ UserWarning,
1111
+ )
1112
+
1113
+ if input_ids_seq_length >= generation_config.max_length:
1114
+ input_ids_string = "decoder_input_ids" if self.config.is_encoder_decoder else "input_ids"
1115
+ logger.warning(
1116
+ f"Input length of {input_ids_string} is {input_ids_seq_length}, but `max_length` is set to"
1117
+ f" {generation_config.max_length}. This can lead to unexpected behavior. You should consider"
1118
+ " increasing `max_new_tokens`."
1119
+ )
1120
+
1121
+ # 2. Set generation parameters if not already defined
1122
+ logits_processor = logits_processor if logits_processor is not None else LogitsProcessorList()
1123
+ stopping_criteria = stopping_criteria if stopping_criteria is not None else StoppingCriteriaList()
1124
+
1125
+ logits_processor = self._get_logits_processor(
1126
+ generation_config=generation_config,
1127
+ input_ids_seq_length=input_ids_seq_length,
1128
+ encoder_input_ids=input_ids,
1129
+ prefix_allowed_tokens_fn=prefix_allowed_tokens_fn,
1130
+ logits_processor=logits_processor,
1131
+ )
1132
+
1133
+ stopping_criteria = self._get_stopping_criteria(
1134
+ generation_config=generation_config, stopping_criteria=stopping_criteria
1135
+ )
1136
+ logits_warper = self._get_logits_warper(generation_config)
1137
+
1138
+ unfinished_sequences = input_ids.new(input_ids.shape[0]).fill_(1)
1139
+ scores = None
1140
+ while True:
1141
+ model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)
1142
+ # forward pass to get next token
1143
+ outputs = self(
1144
+ **model_inputs,
1145
+ return_dict=True,
1146
+ output_attentions=False,
1147
+ output_hidden_states=False,
1148
+ )
1149
+
1150
+ next_token_logits = outputs.logits[:, -1, :]
1151
+
1152
+ # pre-process distribution
1153
+ next_token_scores = logits_processor(input_ids, next_token_logits)
1154
+ next_token_scores = logits_warper(input_ids, next_token_scores)
1155
+
1156
+ # sample
1157
+ probs = nn.functional.softmax(next_token_scores, dim=-1)
1158
+ if generation_config.do_sample:
1159
+ next_tokens = torch.multinomial(probs, num_samples=1).squeeze(1)
1160
+ else:
1161
+ next_tokens = torch.argmax(probs, dim=-1)
1162
+
1163
+ # update generated ids, model inputs, and length for next step
1164
+ input_ids = torch.cat([input_ids, next_tokens[:, None]], dim=-1)
1165
+ model_kwargs = self._update_model_kwargs_for_generation(
1166
+ outputs, model_kwargs, is_encoder_decoder=self.config.is_encoder_decoder
1167
+ )
1168
+ unfinished_sequences = unfinished_sequences.mul((sum(next_tokens != i for i in eos_token_id)).long())
1169
+ if return_past_key_values:
1170
+ yield input_ids, outputs.past_key_values
1171
+ else:
1172
+ yield input_ids
1173
+ # stop when each sentence is finished, or if we exceed the maximum length
1174
+ if unfinished_sequences.max() == 0 or stopping_criteria(input_ids, scores):
1175
+ break
1176
+
1177
+ def quantize(self, bits: int, empty_init=False, device=None, **kwargs):
1178
+ if bits == 0:
1179
+ return
1180
+
1181
+ from .quantization import quantize
1182
+
1183
+ if self.quantized:
1184
+ logger.info("Already quantized.")
1185
+ return self
1186
+
1187
+ self.quantized = True
1188
+
1189
+ self.config.quantization_bit = bits
1190
+
1191
+ self.transformer.encoder = quantize(self.transformer.encoder, bits, empty_init=empty_init, device=device,
1192
+ **kwargs)
1193
+ return self
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1dbee3cd9cd2c207741380969eab11a944bf8405ee2dee9aebff76003ab4aa72
3
+ size 14681391
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d98fba9a9e9bb90ccd82d5505f00b81e1f4c544b22fb5b51740f1df8a3cea0d
3
+ size 7340861
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/quantization.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from torch.nn import Linear
2
+ from torch.nn.parameter import Parameter
3
+
4
+ import bz2
5
+ import torch
6
+ import base64
7
+ import ctypes
8
+ from transformers.utils import logging
9
+
10
+ from typing import List
11
+ from functools import partial
12
+
13
+ logger = logging.get_logger(__name__)
14
+
15
+ try:
16
+ from cpm_kernels.kernels.base import LazyKernelCModule, KernelFunction, round_up
17
+
18
+ class Kernel:
19
+ def __init__(self, code: bytes, function_names: List[str]):
20
+ self.code = code
21
+ self._function_names = function_names
22
+ self._cmodule = LazyKernelCModule(self.code)
23
+
24
+ for name in self._function_names:
25
+ setattr(self, name, KernelFunction(self._cmodule, name))
26
+
27
+ quantization_code = "$QlpoOTFBWSZTWU9yuJUAQHN//////////f/n/8/n///n//bt4dTidcVx8X3V9FV/92/v4B7/AD5FBQFAAAChSgKpFCFAFVSigUAAAEKhSgUUqgFBKigqVREQAABQBQIANDTTIGI00BkZBkNGE0A0BkBkGQGRkaNAaAGQNBoGgDIAAYIGTI0DQAQAaGmmQMRpoDIyDIaMJoBoDIDIMgMjI0aA0AMgaDQNAGQAAwQMmRoGgAgA0NNMgYjTQGRkGQ0YTQDQGQGQZAZGRo0BoAZA0GgaAMgABggZMjQNABABoaaZAxGmgMjIMhowmgGgMg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dLqLhYkzGMzCZWGMQzGMSsZYY6Di1t4nlJ+Em63mJxrVLxPbYxNEdgc1dU2iOKyoYYWjNrEeHTYybVk0atSa7ehuwsWMWTqn1TrnS6hYsi71d1+s+k+ic70e20fzE/VaTdxT9ZtU4GIXdeNx3X77guYYfpHeTQjaMX6brOu4OY4K7Y2d9mbHarI5ox3p4GpJ2Vd/Tst60f7j999pppjR+Q/Qf8J/VaORs3cji7FfFuN61+ui9s8hix1OCh5KGVV23BPXvZfz3CLyHpix+exi8z/KnCnosY2eunor+cxyPO/xJ0vKey9OvE9VjqaYu0x3Z3jd6o2b1T12D+F8l232lwaaacD5LE8LBxu7WTlbWraWpew8Xexjel3E+wWD4APITdNqR8F3R3T0lunCQ4GaE9R37DxeCYfcHi4xci5ovKfxVs55y2hf+65E/Xdp6jR5nrebTmi5incpkyOjs50JvrZwstbbW6kfuuQw+2mykf/EXNFzxfKTrxew929TR6bWnGL//F3JFOFCQT3K4lQ"
28
+
29
+ kernels = Kernel(
30
+ bz2.decompress(base64.b64decode(quantization_code)),
31
+ [
32
+ "int4WeightCompression",
33
+ "int4WeightExtractionFloat",
34
+ "int4WeightExtractionHalf",
35
+ "int8WeightExtractionFloat",
36
+ "int8WeightExtractionHalf",
37
+ ],
38
+ )
39
+ except Exception as exception:
40
+ kernels = None
41
+ logger.warning("Failed to load cpm_kernels:" + str(exception))
42
+
43
+
44
+ class W8A16Linear(torch.autograd.Function):
45
+ @staticmethod
46
+ def forward(ctx, inp: torch.Tensor, quant_w: torch.Tensor, scale_w: torch.Tensor, weight_bit_width):
47
+ ctx.inp_shape = inp.size()
48
+ ctx.weight_bit_width = weight_bit_width
49
+ out_features = quant_w.size(0)
50
+ inp = inp.contiguous().view(-1, inp.size(-1))
51
+ weight = extract_weight_to_half(quant_w, scale_w, weight_bit_width)
52
+ ctx.weight_shape = weight.size()
53
+ output = inp.mm(weight.t())
54
+ ctx.save_for_backward(inp, quant_w, scale_w)
55
+ return output.view(*(ctx.inp_shape[:-1] + (out_features,)))
56
+
57
+ @staticmethod
58
+ def backward(ctx, grad_output: torch.Tensor):
59
+ inp, quant_w, scale_w = ctx.saved_tensors
60
+ weight = extract_weight_to_half(quant_w, scale_w, ctx.weight_bit_width)
61
+ grad_output = grad_output.contiguous().view(-1, weight.size(0))
62
+ grad_input = grad_output.mm(weight)
63
+ grad_weight = grad_output.t().mm(inp)
64
+ return grad_input.view(ctx.inp_shape), grad_weight.view(ctx.weight_shape), None, None
65
+
66
+
67
+ def compress_int4_weight(weight: torch.Tensor): # (n, m)
68
+ with torch.cuda.device(weight.device):
69
+ n, m = weight.size(0), weight.size(1)
70
+ assert m % 2 == 0
71
+ m = m // 2
72
+ out = torch.empty(n, m, dtype=torch.int8, device="cuda")
73
+ stream = torch.cuda.current_stream()
74
+
75
+ gridDim = (n, 1, 1)
76
+ blockDim = (min(round_up(m, 32), 1024), 1, 1)
77
+
78
+ kernels.int4WeightCompression(
79
+ gridDim,
80
+ blockDim,
81
+ 0,
82
+ stream,
83
+ [ctypes.c_void_p(weight.data_ptr()), ctypes.c_void_p(out.data_ptr()), ctypes.c_int32(n), ctypes.c_int32(m)],
84
+ )
85
+ return out
86
+
87
+
88
+ def extract_weight_to_half(weight: torch.Tensor, scale_list: torch.Tensor, source_bit_width: int):
89
+ assert scale_list.dtype in [torch.half, torch.bfloat16]
90
+ assert weight.dtype in [torch.int8]
91
+ if source_bit_width == 8:
92
+ return weight.to(scale_list.dtype) * scale_list[:, None]
93
+ elif source_bit_width == 4:
94
+ func = (
95
+ kernels.int4WeightExtractionHalf if scale_list.dtype == torch.half else kernels.int4WeightExtractionBFloat16
96
+ )
97
+ else:
98
+ assert False, "Unsupported bit-width"
99
+
100
+ with torch.cuda.device(weight.device):
101
+ n, m = weight.size(0), weight.size(1)
102
+ out = torch.empty(n, m * (8 // source_bit_width), dtype=scale_list.dtype, device="cuda")
103
+ stream = torch.cuda.current_stream()
104
+
105
+ gridDim = (n, 1, 1)
106
+ blockDim = (min(round_up(m, 32), 1024), 1, 1)
107
+
108
+ func(
109
+ gridDim,
110
+ blockDim,
111
+ 0,
112
+ stream,
113
+ [
114
+ ctypes.c_void_p(weight.data_ptr()),
115
+ ctypes.c_void_p(scale_list.data_ptr()),
116
+ ctypes.c_void_p(out.data_ptr()),
117
+ ctypes.c_int32(n),
118
+ ctypes.c_int32(m),
119
+ ],
120
+ )
121
+ return out
122
+
123
+
124
+ class QuantizedLinear(torch.nn.Module):
125
+ def __init__(self, weight_bit_width: int, weight, bias=None, device="cpu", dtype=None, empty_init=False, *args,
126
+ **kwargs):
127
+ super().__init__()
128
+ self.weight_bit_width = weight_bit_width
129
+
130
+ shape = weight.shape
131
+
132
+ if weight is None or empty_init:
133
+ self.weight = torch.empty(shape[0], shape[1] * weight_bit_width // 8, dtype=torch.int8, device=device)
134
+ self.weight_scale = torch.empty(shape[0], dtype=dtype, device=device)
135
+ else:
136
+ self.weight_scale = weight.abs().max(dim=-1).values / ((2 ** (weight_bit_width - 1)) - 1)
137
+ self.weight = torch.round(weight / self.weight_scale[:, None]).to(torch.int8)
138
+ if weight_bit_width == 4:
139
+ self.weight = compress_int4_weight(self.weight)
140
+
141
+ self.weight = Parameter(self.weight.to(device), requires_grad=False)
142
+ self.weight_scale = Parameter(self.weight_scale.to(device), requires_grad=False)
143
+ self.bias = Parameter(bias.to(device), requires_grad=False) if bias is not None else None
144
+
145
+ def forward(self, input):
146
+ output = W8A16Linear.apply(input, self.weight, self.weight_scale, self.weight_bit_width)
147
+ if self.bias is not None:
148
+ output = output + self.bias
149
+ return output
150
+
151
+
152
+ def quantize(model, weight_bit_width, empty_init=False, device=None):
153
+ """Replace fp16 linear with quantized linear"""
154
+ for layer in model.layers:
155
+ layer.self_attention.query_key_value = QuantizedLinear(
156
+ weight_bit_width=weight_bit_width,
157
+ weight=layer.self_attention.query_key_value.weight.to(torch.cuda.current_device()),
158
+ bias=layer.self_attention.query_key_value.bias,
159
+ dtype=layer.self_attention.query_key_value.weight.dtype,
160
+ device=layer.self_attention.query_key_value.weight.device if device is None else device,
161
+ empty_init=empty_init
162
+ )
163
+ layer.self_attention.dense = QuantizedLinear(
164
+ weight_bit_width=weight_bit_width,
165
+ weight=layer.self_attention.dense.weight.to(torch.cuda.current_device()),
166
+ bias=layer.self_attention.dense.bias,
167
+ dtype=layer.self_attention.dense.weight.dtype,
168
+ device=layer.self_attention.dense.weight.device if device is None else device,
169
+ empty_init=empty_init
170
+ )
171
+ layer.mlp.dense_h_to_4h = QuantizedLinear(
172
+ weight_bit_width=weight_bit_width,
173
+ weight=layer.mlp.dense_h_to_4h.weight.to(torch.cuda.current_device()),
174
+ bias=layer.mlp.dense_h_to_4h.bias,
175
+ dtype=layer.mlp.dense_h_to_4h.weight.dtype,
176
+ device=layer.mlp.dense_h_to_4h.weight.device if device is None else device,
177
+ empty_init=empty_init
178
+ )
179
+ layer.mlp.dense_4h_to_h = QuantizedLinear(
180
+ weight_bit_width=weight_bit_width,
181
+ weight=layer.mlp.dense_4h_to_h.weight.to(torch.cuda.current_device()),
182
+ bias=layer.mlp.dense_4h_to_h.bias,
183
+ dtype=layer.mlp.dense_4h_to_h.weight.dtype,
184
+ device=layer.mlp.dense_4h_to_h.weight.device if device is None else device,
185
+ empty_init=empty_init
186
+ )
187
+
188
+ return model
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f99a4220d5ccad06ddf7840907a6f870430be166923d830024c3c4d7e004f2cf
3
+ size 14575
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6b8b2da7849875ff5dc7c5782252c5e9dcc13e8a73ea1fba2a34327b3fe26b3a
3
+ size 627
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {}
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/tokenization_chatglm.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ from typing import List, Optional, Union, Dict
4
+ from sentencepiece import SentencePieceProcessor
5
+ from transformers import PreTrainedTokenizer
6
+ from transformers.utils import logging, PaddingStrategy
7
+ from transformers.tokenization_utils_base import EncodedInput, BatchEncoding
8
+
9
+
10
+ class SPTokenizer:
11
+ def __init__(self, model_path: str):
12
+ # reload tokenizer
13
+ assert os.path.isfile(model_path), model_path
14
+ self.sp_model = SentencePieceProcessor(model_file=model_path)
15
+
16
+ # BOS / EOS token IDs
17
+ self.n_words: int = self.sp_model.vocab_size()
18
+ self.bos_id: int = self.sp_model.bos_id()
19
+ self.eos_id: int = self.sp_model.eos_id()
20
+ self.pad_id: int = self.sp_model.unk_id()
21
+ assert self.sp_model.vocab_size() == self.sp_model.get_piece_size()
22
+
23
+ special_tokens = ["[MASK]", "[gMASK]", "[sMASK]", "sop", "eop"]
24
+ self.special_tokens = {}
25
+ self.index_special_tokens = {}
26
+ for token in special_tokens:
27
+ self.special_tokens[token] = self.n_words
28
+ self.index_special_tokens[self.n_words] = token
29
+ self.n_words += 1
30
+
31
+ def tokenize(self, s: str):
32
+ return self.sp_model.EncodeAsPieces(s)
33
+
34
+ def encode(self, s: str, bos: bool = False, eos: bool = False) -> List[int]:
35
+ assert type(s) is str
36
+ t = self.sp_model.encode(s)
37
+ if bos:
38
+ t = [self.bos_id] + t
39
+ if eos:
40
+ t = t + [self.eos_id]
41
+ return t
42
+
43
+ def decode(self, t: List[int]) -> str:
44
+ return self.sp_model.decode(t)
45
+
46
+ def decode_tokens(self, tokens: List[str]) -> str:
47
+ text = self.sp_model.DecodePieces(tokens)
48
+ return text
49
+
50
+ def convert_token_to_id(self, token):
51
+ """ Converts a token (str) in an id using the vocab. """
52
+ if token in self.special_tokens:
53
+ return self.special_tokens[token]
54
+ return self.sp_model.PieceToId(token)
55
+
56
+ def convert_id_to_token(self, index):
57
+ """Converts an index (integer) in a token (str) using the vocab."""
58
+ if index in self.index_special_tokens or index in [self.eos_id, self.bos_id, self.pad_id] or index < 0:
59
+ return ""
60
+ return self.sp_model.IdToPiece(index)
61
+
62
+
63
+ class ChatGLMTokenizer(PreTrainedTokenizer):
64
+ vocab_files_names = {"vocab_file": "tokenizer.model"}
65
+
66
+ model_input_names = ["input_ids", "attention_mask", "position_ids"]
67
+
68
+ def __init__(self, vocab_file, padding_side="left", clean_up_tokenization_spaces=False, **kwargs):
69
+ super().__init__(padding_side=padding_side, clean_up_tokenization_spaces=clean_up_tokenization_spaces, **kwargs)
70
+ self.name = "GLMTokenizer"
71
+
72
+ self.vocab_file = vocab_file
73
+ self.tokenizer = SPTokenizer(vocab_file)
74
+ self.special_tokens = {
75
+ "<bos>": self.tokenizer.bos_id,
76
+ "<eos>": self.tokenizer.eos_id,
77
+ "<pad>": self.tokenizer.pad_id
78
+ }
79
+
80
+ def get_command(self, token):
81
+ if token in self.special_tokens:
82
+ return self.special_tokens[token]
83
+ assert token in self.tokenizer.special_tokens, f"{token} is not a special token for {self.name}"
84
+ return self.tokenizer.special_tokens[token]
85
+
86
+ @property
87
+ def unk_token(self) -> str:
88
+ return "<unk>"
89
+
90
+ @property
91
+ def pad_token(self) -> str:
92
+ return "<unk>"
93
+
94
+ @property
95
+ def pad_token_id(self):
96
+ return self.get_command("<pad>")
97
+
98
+ @property
99
+ def eos_token(self) -> str:
100
+ return "</s>"
101
+
102
+ @property
103
+ def eos_token_id(self):
104
+ return self.get_command("<eos>")
105
+
106
+ @property
107
+ def vocab_size(self):
108
+ return self.tokenizer.n_words
109
+
110
+ def get_vocab(self):
111
+ """ Returns vocab as a dict """
112
+ vocab = {self._convert_id_to_token(i): i for i in range(self.vocab_size)}
113
+ vocab.update(self.added_tokens_encoder)
114
+ return vocab
115
+
116
+ def _tokenize(self, text, **kwargs):
117
+ return self.tokenizer.tokenize(text)
118
+
119
+ def _convert_token_to_id(self, token):
120
+ """ Converts a token (str) in an id using the vocab. """
121
+ return self.tokenizer.convert_token_to_id(token)
122
+
123
+ def _convert_id_to_token(self, index):
124
+ """Converts an index (integer) in a token (str) using the vocab."""
125
+ return self.tokenizer.convert_id_to_token(index)
126
+
127
+ def convert_tokens_to_string(self, tokens: List[str]) -> str:
128
+ return self.tokenizer.decode_tokens(tokens)
129
+
130
+ def save_vocabulary(self, save_directory, filename_prefix=None):
131
+ """
132
+ Save the vocabulary and special tokens file to a directory.
133
+
134
+ Args:
135
+ save_directory (`str`):
136
+ The directory in which to save the vocabulary.
137
+ filename_prefix (`str`, *optional*):
138
+ An optional prefix to add to the named of the saved files.
139
+
140
+ Returns:
141
+ `Tuple(str)`: Paths to the files saved.
142
+ """
143
+ if os.path.isdir(save_directory):
144
+ vocab_file = os.path.join(
145
+ save_directory, self.vocab_files_names["vocab_file"]
146
+ )
147
+ else:
148
+ vocab_file = save_directory
149
+
150
+ with open(self.vocab_file, 'rb') as fin:
151
+ proto_str = fin.read()
152
+
153
+ with open(vocab_file, "wb") as writer:
154
+ writer.write(proto_str)
155
+
156
+ return (vocab_file,)
157
+
158
+ def get_prefix_tokens(self):
159
+ prefix_tokens = [self.get_command("[gMASK]"), self.get_command("sop")]
160
+ return prefix_tokens
161
+
162
+ def build_prompt(self, query, history=None):
163
+ if history is None:
164
+ history = []
165
+ prompt = ""
166
+ for i, (old_query, response) in enumerate(history):
167
+ prompt += "[Round {}]\n\n问:{}\n\n答:{}\n\n".format(i + 1, old_query, response)
168
+ prompt += "[Round {}]\n\n问:{}\n\n答:".format(len(history) + 1, query)
169
+ return prompt
170
+
171
+ def build_inputs_with_special_tokens(
172
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
173
+ ) -> List[int]:
174
+ """
175
+ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
176
+ adding special tokens. A BERT sequence has the following format:
177
+
178
+ - single sequence: `[CLS] X [SEP]`
179
+ - pair of sequences: `[CLS] A [SEP] B [SEP]`
180
+
181
+ Args:
182
+ token_ids_0 (`List[int]`):
183
+ List of IDs to which the special tokens will be added.
184
+ token_ids_1 (`List[int]`, *optional*):
185
+ Optional second list of IDs for sequence pairs.
186
+
187
+ Returns:
188
+ `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
189
+ """
190
+ prefix_tokens = self.get_prefix_tokens()
191
+ token_ids_0 = prefix_tokens + token_ids_0
192
+ if token_ids_1 is not None:
193
+ token_ids_0 = token_ids_0 + token_ids_1 + [self.get_command("<eos>")]
194
+ return token_ids_0
195
+
196
+ def _pad(
197
+ self,
198
+ encoded_inputs: Union[Dict[str, EncodedInput], BatchEncoding],
199
+ max_length: Optional[int] = None,
200
+ padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
201
+ pad_to_multiple_of: Optional[int] = None,
202
+ return_attention_mask: Optional[bool] = None,
203
+ ) -> dict:
204
+ """
205
+ Pad encoded inputs (on left/right and up to predefined length or max length in the batch)
206
+
207
+ Args:
208
+ encoded_inputs:
209
+ Dictionary of tokenized inputs (`List[int]`) or batch of tokenized inputs (`List[List[int]]`).
210
+ max_length: maximum length of the returned list and optionally padding length (see below).
211
+ Will truncate by taking into account the special tokens.
212
+ padding_strategy: PaddingStrategy to use for padding.
213
+
214
+ - PaddingStrategy.LONGEST Pad to the longest sequence in the batch
215
+ - PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
216
+ - PaddingStrategy.DO_NOT_PAD: Do not pad
217
+ The tokenizer padding sides are defined in self.padding_side:
218
+
219
+ - 'left': pads on the left of the sequences
220
+ - 'right': pads on the right of the sequences
221
+ pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
222
+ This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
223
+ `>= 7.5` (Volta).
224
+ return_attention_mask:
225
+ (optional) Set to False to avoid returning attention mask (default: set to model specifics)
226
+ """
227
+ # Load from model defaults
228
+ assert self.padding_side == "left"
229
+
230
+ required_input = encoded_inputs[self.model_input_names[0]]
231
+ seq_length = len(required_input)
232
+
233
+ if padding_strategy == PaddingStrategy.LONGEST:
234
+ max_length = len(required_input)
235
+
236
+ if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
237
+ max_length = ((max_length // pad_to_multiple_of) + 1) * pad_to_multiple_of
238
+
239
+ needs_to_be_padded = padding_strategy != PaddingStrategy.DO_NOT_PAD and len(required_input) != max_length
240
+
241
+ # Initialize attention mask if not present.
242
+ if "attention_mask" not in encoded_inputs:
243
+ encoded_inputs["attention_mask"] = [1] * seq_length
244
+
245
+ if "position_ids" not in encoded_inputs:
246
+ encoded_inputs["position_ids"] = list(range(seq_length))
247
+
248
+ if needs_to_be_padded:
249
+ difference = max_length - len(required_input)
250
+
251
+ if "attention_mask" in encoded_inputs:
252
+ encoded_inputs["attention_mask"] = [0] * difference + encoded_inputs["attention_mask"]
253
+ if "position_ids" in encoded_inputs:
254
+ encoded_inputs["position_ids"] = [0] * difference + encoded_inputs["position_ids"]
255
+ encoded_inputs[self.model_input_names[0]] = [self.pad_token_id] * difference + required_input
256
+
257
+ return encoded_inputs
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7dc4c393423b76e4373e5157ddc34803a0189ba96b21ddbb40269d31468a6f2
3
+ size 1018370
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoTokenizer": [
4
+ "tokenization_chatglm.ChatGLMTokenizer",
5
+ null
6
+ ]
7
+ },
8
+ "clean_up_tokenization_spaces": false,
9
+ "do_lower_case": false,
10
+ "model_max_length": 1000000000000000019884624838656,
11
+ "padding_side": "left",
12
+ "remove_space": false,
13
+ "special_tokens_map_file": null,
14
+ "tokenizer_class": "ChatGLMTokenizer"
15
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/trainer_state.json ADDED
@@ -0,0 +1,616 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 4.458066313736417,
5
+ "global_step": 1000,
6
+ "is_hyper_param_search": false,
7
+ "is_local_process_zero": true,
8
+ "is_world_process_zero": true,
9
+ "log_history": [
10
+ {
11
+ "epoch": 0.04,
12
+ "learning_rate": 0.019933333333333334,
13
+ "loss": 1.811,
14
+ "step": 10
15
+ },
16
+ {
17
+ "epoch": 0.09,
18
+ "learning_rate": 0.019866666666666668,
19
+ "loss": 1.2846,
20
+ "step": 20
21
+ },
22
+ {
23
+ "epoch": 0.13,
24
+ "learning_rate": 0.0198,
25
+ "loss": 1.1671,
26
+ "step": 30
27
+ },
28
+ {
29
+ "epoch": 0.18,
30
+ "learning_rate": 0.019733333333333335,
31
+ "loss": 0.9238,
32
+ "step": 40
33
+ },
34
+ {
35
+ "epoch": 0.22,
36
+ "learning_rate": 0.019666666666666666,
37
+ "loss": 0.832,
38
+ "step": 50
39
+ },
40
+ {
41
+ "epoch": 0.27,
42
+ "learning_rate": 0.0196,
43
+ "loss": 0.7667,
44
+ "step": 60
45
+ },
46
+ {
47
+ "epoch": 0.31,
48
+ "learning_rate": 0.019533333333333333,
49
+ "loss": 0.5746,
50
+ "step": 70
51
+ },
52
+ {
53
+ "epoch": 0.36,
54
+ "learning_rate": 0.019466666666666667,
55
+ "loss": 0.6013,
56
+ "step": 80
57
+ },
58
+ {
59
+ "epoch": 0.4,
60
+ "learning_rate": 0.0194,
61
+ "loss": 0.622,
62
+ "step": 90
63
+ },
64
+ {
65
+ "epoch": 0.45,
66
+ "learning_rate": 0.019333333333333334,
67
+ "loss": 0.5471,
68
+ "step": 100
69
+ },
70
+ {
71
+ "epoch": 0.49,
72
+ "learning_rate": 0.019266666666666668,
73
+ "loss": 0.5042,
74
+ "step": 110
75
+ },
76
+ {
77
+ "epoch": 0.53,
78
+ "learning_rate": 0.0192,
79
+ "loss": 0.48,
80
+ "step": 120
81
+ },
82
+ {
83
+ "epoch": 0.58,
84
+ "learning_rate": 0.019133333333333332,
85
+ "loss": 0.4302,
86
+ "step": 130
87
+ },
88
+ {
89
+ "epoch": 0.62,
90
+ "learning_rate": 0.01906666666666667,
91
+ "loss": 0.4385,
92
+ "step": 140
93
+ },
94
+ {
95
+ "epoch": 0.67,
96
+ "learning_rate": 0.019,
97
+ "loss": 0.4081,
98
+ "step": 150
99
+ },
100
+ {
101
+ "epoch": 0.71,
102
+ "learning_rate": 0.018933333333333333,
103
+ "loss": 0.3896,
104
+ "step": 160
105
+ },
106
+ {
107
+ "epoch": 0.76,
108
+ "learning_rate": 0.018866666666666667,
109
+ "loss": 0.4021,
110
+ "step": 170
111
+ },
112
+ {
113
+ "epoch": 0.8,
114
+ "learning_rate": 0.0188,
115
+ "loss": 0.3946,
116
+ "step": 180
117
+ },
118
+ {
119
+ "epoch": 0.85,
120
+ "learning_rate": 0.018733333333333334,
121
+ "loss": 0.4153,
122
+ "step": 190
123
+ },
124
+ {
125
+ "epoch": 0.89,
126
+ "learning_rate": 0.018666666666666668,
127
+ "loss": 0.3587,
128
+ "step": 200
129
+ },
130
+ {
131
+ "epoch": 0.94,
132
+ "learning_rate": 0.018600000000000002,
133
+ "loss": 0.3735,
134
+ "step": 210
135
+ },
136
+ {
137
+ "epoch": 0.98,
138
+ "learning_rate": 0.018533333333333332,
139
+ "loss": 0.3399,
140
+ "step": 220
141
+ },
142
+ {
143
+ "epoch": 1.03,
144
+ "learning_rate": 0.018466666666666666,
145
+ "loss": 0.3416,
146
+ "step": 230
147
+ },
148
+ {
149
+ "epoch": 1.07,
150
+ "learning_rate": 0.0184,
151
+ "loss": 0.3426,
152
+ "step": 240
153
+ },
154
+ {
155
+ "epoch": 1.11,
156
+ "learning_rate": 0.018333333333333333,
157
+ "loss": 0.3181,
158
+ "step": 250
159
+ },
160
+ {
161
+ "epoch": 1.16,
162
+ "learning_rate": 0.018266666666666667,
163
+ "loss": 0.2859,
164
+ "step": 260
165
+ },
166
+ {
167
+ "epoch": 1.2,
168
+ "learning_rate": 0.0182,
169
+ "loss": 0.3226,
170
+ "step": 270
171
+ },
172
+ {
173
+ "epoch": 1.25,
174
+ "learning_rate": 0.01813333333333333,
175
+ "loss": 0.3054,
176
+ "step": 280
177
+ },
178
+ {
179
+ "epoch": 1.29,
180
+ "learning_rate": 0.01806666666666667,
181
+ "loss": 0.302,
182
+ "step": 290
183
+ },
184
+ {
185
+ "epoch": 1.34,
186
+ "learning_rate": 0.018000000000000002,
187
+ "loss": 0.3099,
188
+ "step": 300
189
+ },
190
+ {
191
+ "epoch": 1.38,
192
+ "learning_rate": 0.017933333333333332,
193
+ "loss": 0.3026,
194
+ "step": 310
195
+ },
196
+ {
197
+ "epoch": 1.43,
198
+ "learning_rate": 0.017866666666666666,
199
+ "loss": 0.2892,
200
+ "step": 320
201
+ },
202
+ {
203
+ "epoch": 1.47,
204
+ "learning_rate": 0.0178,
205
+ "loss": 0.3006,
206
+ "step": 330
207
+ },
208
+ {
209
+ "epoch": 1.52,
210
+ "learning_rate": 0.017733333333333334,
211
+ "loss": 0.2935,
212
+ "step": 340
213
+ },
214
+ {
215
+ "epoch": 1.56,
216
+ "learning_rate": 0.017666666666666667,
217
+ "loss": 0.285,
218
+ "step": 350
219
+ },
220
+ {
221
+ "epoch": 1.6,
222
+ "learning_rate": 0.0176,
223
+ "loss": 0.2606,
224
+ "step": 360
225
+ },
226
+ {
227
+ "epoch": 1.65,
228
+ "learning_rate": 0.017533333333333335,
229
+ "loss": 0.2912,
230
+ "step": 370
231
+ },
232
+ {
233
+ "epoch": 1.69,
234
+ "learning_rate": 0.017466666666666665,
235
+ "loss": 0.2856,
236
+ "step": 380
237
+ },
238
+ {
239
+ "epoch": 1.74,
240
+ "learning_rate": 0.0174,
241
+ "loss": 0.2725,
242
+ "step": 390
243
+ },
244
+ {
245
+ "epoch": 1.78,
246
+ "learning_rate": 0.017333333333333336,
247
+ "loss": 0.2755,
248
+ "step": 400
249
+ },
250
+ {
251
+ "epoch": 1.83,
252
+ "learning_rate": 0.017266666666666666,
253
+ "loss": 0.2562,
254
+ "step": 410
255
+ },
256
+ {
257
+ "epoch": 1.87,
258
+ "learning_rate": 0.0172,
259
+ "loss": 0.2845,
260
+ "step": 420
261
+ },
262
+ {
263
+ "epoch": 1.92,
264
+ "learning_rate": 0.017133333333333334,
265
+ "loss": 0.2686,
266
+ "step": 430
267
+ },
268
+ {
269
+ "epoch": 1.96,
270
+ "learning_rate": 0.017066666666666667,
271
+ "loss": 0.2586,
272
+ "step": 440
273
+ },
274
+ {
275
+ "epoch": 2.01,
276
+ "learning_rate": 0.017,
277
+ "loss": 0.2552,
278
+ "step": 450
279
+ },
280
+ {
281
+ "epoch": 2.05,
282
+ "learning_rate": 0.016933333333333335,
283
+ "loss": 0.2529,
284
+ "step": 460
285
+ },
286
+ {
287
+ "epoch": 2.1,
288
+ "learning_rate": 0.01686666666666667,
289
+ "loss": 0.2364,
290
+ "step": 470
291
+ },
292
+ {
293
+ "epoch": 2.14,
294
+ "learning_rate": 0.0168,
295
+ "loss": 0.2541,
296
+ "step": 480
297
+ },
298
+ {
299
+ "epoch": 2.18,
300
+ "learning_rate": 0.016733333333333333,
301
+ "loss": 0.2423,
302
+ "step": 490
303
+ },
304
+ {
305
+ "epoch": 2.23,
306
+ "learning_rate": 0.016666666666666666,
307
+ "loss": 0.2336,
308
+ "step": 500
309
+ },
310
+ {
311
+ "epoch": 2.27,
312
+ "learning_rate": 0.0166,
313
+ "loss": 0.239,
314
+ "step": 510
315
+ },
316
+ {
317
+ "epoch": 2.32,
318
+ "learning_rate": 0.016533333333333334,
319
+ "loss": 0.2359,
320
+ "step": 520
321
+ },
322
+ {
323
+ "epoch": 2.36,
324
+ "learning_rate": 0.016466666666666668,
325
+ "loss": 0.2481,
326
+ "step": 530
327
+ },
328
+ {
329
+ "epoch": 2.41,
330
+ "learning_rate": 0.016399999999999998,
331
+ "loss": 0.2419,
332
+ "step": 540
333
+ },
334
+ {
335
+ "epoch": 2.45,
336
+ "learning_rate": 0.01633333333333333,
337
+ "loss": 0.2289,
338
+ "step": 550
339
+ },
340
+ {
341
+ "epoch": 2.5,
342
+ "learning_rate": 0.01626666666666667,
343
+ "loss": 0.2268,
344
+ "step": 560
345
+ },
346
+ {
347
+ "epoch": 2.54,
348
+ "learning_rate": 0.016200000000000003,
349
+ "loss": 0.2393,
350
+ "step": 570
351
+ },
352
+ {
353
+ "epoch": 2.59,
354
+ "learning_rate": 0.016133333333333333,
355
+ "loss": 0.2234,
356
+ "step": 580
357
+ },
358
+ {
359
+ "epoch": 2.63,
360
+ "learning_rate": 0.016066666666666667,
361
+ "loss": 0.2382,
362
+ "step": 590
363
+ },
364
+ {
365
+ "epoch": 2.67,
366
+ "learning_rate": 0.016,
367
+ "loss": 0.237,
368
+ "step": 600
369
+ },
370
+ {
371
+ "epoch": 2.72,
372
+ "learning_rate": 0.015933333333333334,
373
+ "loss": 0.2492,
374
+ "step": 610
375
+ },
376
+ {
377
+ "epoch": 2.76,
378
+ "learning_rate": 0.015866666666666668,
379
+ "loss": 0.2263,
380
+ "step": 620
381
+ },
382
+ {
383
+ "epoch": 2.81,
384
+ "learning_rate": 0.0158,
385
+ "loss": 0.2515,
386
+ "step": 630
387
+ },
388
+ {
389
+ "epoch": 2.85,
390
+ "learning_rate": 0.015733333333333332,
391
+ "loss": 0.2299,
392
+ "step": 640
393
+ },
394
+ {
395
+ "epoch": 2.9,
396
+ "learning_rate": 0.015666666666666666,
397
+ "loss": 0.2311,
398
+ "step": 650
399
+ },
400
+ {
401
+ "epoch": 2.94,
402
+ "learning_rate": 0.015600000000000001,
403
+ "loss": 0.2204,
404
+ "step": 660
405
+ },
406
+ {
407
+ "epoch": 2.99,
408
+ "learning_rate": 0.015533333333333333,
409
+ "loss": 0.2243,
410
+ "step": 670
411
+ },
412
+ {
413
+ "epoch": 3.03,
414
+ "learning_rate": 0.015466666666666667,
415
+ "loss": 0.2,
416
+ "step": 680
417
+ },
418
+ {
419
+ "epoch": 3.08,
420
+ "learning_rate": 0.0154,
421
+ "loss": 0.2016,
422
+ "step": 690
423
+ },
424
+ {
425
+ "epoch": 3.12,
426
+ "learning_rate": 0.015333333333333334,
427
+ "loss": 0.2251,
428
+ "step": 700
429
+ },
430
+ {
431
+ "epoch": 3.17,
432
+ "learning_rate": 0.015266666666666666,
433
+ "loss": 0.2055,
434
+ "step": 710
435
+ },
436
+ {
437
+ "epoch": 3.21,
438
+ "learning_rate": 0.0152,
439
+ "loss": 0.2205,
440
+ "step": 720
441
+ },
442
+ {
443
+ "epoch": 3.25,
444
+ "learning_rate": 0.015133333333333334,
445
+ "loss": 0.2066,
446
+ "step": 730
447
+ },
448
+ {
449
+ "epoch": 3.3,
450
+ "learning_rate": 0.015066666666666666,
451
+ "loss": 0.2174,
452
+ "step": 740
453
+ },
454
+ {
455
+ "epoch": 3.34,
456
+ "learning_rate": 0.015,
457
+ "loss": 0.2163,
458
+ "step": 750
459
+ },
460
+ {
461
+ "epoch": 3.39,
462
+ "learning_rate": 0.014933333333333335,
463
+ "loss": 0.2049,
464
+ "step": 760
465
+ },
466
+ {
467
+ "epoch": 3.43,
468
+ "learning_rate": 0.014866666666666667,
469
+ "loss": 0.2039,
470
+ "step": 770
471
+ },
472
+ {
473
+ "epoch": 3.48,
474
+ "learning_rate": 0.0148,
475
+ "loss": 0.1941,
476
+ "step": 780
477
+ },
478
+ {
479
+ "epoch": 3.52,
480
+ "learning_rate": 0.014733333333333334,
481
+ "loss": 0.2051,
482
+ "step": 790
483
+ },
484
+ {
485
+ "epoch": 3.57,
486
+ "learning_rate": 0.014666666666666666,
487
+ "loss": 0.2097,
488
+ "step": 800
489
+ },
490
+ {
491
+ "epoch": 3.61,
492
+ "learning_rate": 0.0146,
493
+ "loss": 0.2104,
494
+ "step": 810
495
+ },
496
+ {
497
+ "epoch": 3.66,
498
+ "learning_rate": 0.014533333333333334,
499
+ "loss": 0.2157,
500
+ "step": 820
501
+ },
502
+ {
503
+ "epoch": 3.7,
504
+ "learning_rate": 0.014466666666666668,
505
+ "loss": 0.2053,
506
+ "step": 830
507
+ },
508
+ {
509
+ "epoch": 3.74,
510
+ "learning_rate": 0.0144,
511
+ "loss": 0.2005,
512
+ "step": 840
513
+ },
514
+ {
515
+ "epoch": 3.79,
516
+ "learning_rate": 0.014333333333333333,
517
+ "loss": 0.2075,
518
+ "step": 850
519
+ },
520
+ {
521
+ "epoch": 3.83,
522
+ "learning_rate": 0.014266666666666667,
523
+ "loss": 0.2065,
524
+ "step": 860
525
+ },
526
+ {
527
+ "epoch": 3.88,
528
+ "learning_rate": 0.014199999999999999,
529
+ "loss": 0.2091,
530
+ "step": 870
531
+ },
532
+ {
533
+ "epoch": 3.92,
534
+ "learning_rate": 0.014133333333333333,
535
+ "loss": 0.2003,
536
+ "step": 880
537
+ },
538
+ {
539
+ "epoch": 3.97,
540
+ "learning_rate": 0.014066666666666668,
541
+ "loss": 0.2111,
542
+ "step": 890
543
+ },
544
+ {
545
+ "epoch": 4.01,
546
+ "learning_rate": 0.013999999999999999,
547
+ "loss": 0.2019,
548
+ "step": 900
549
+ },
550
+ {
551
+ "epoch": 4.06,
552
+ "learning_rate": 0.013933333333333334,
553
+ "loss": 0.1953,
554
+ "step": 910
555
+ },
556
+ {
557
+ "epoch": 4.1,
558
+ "learning_rate": 0.013866666666666668,
559
+ "loss": 0.1912,
560
+ "step": 920
561
+ },
562
+ {
563
+ "epoch": 4.15,
564
+ "learning_rate": 0.0138,
565
+ "loss": 0.1947,
566
+ "step": 930
567
+ },
568
+ {
569
+ "epoch": 4.19,
570
+ "learning_rate": 0.013733333333333334,
571
+ "loss": 0.1879,
572
+ "step": 940
573
+ },
574
+ {
575
+ "epoch": 4.24,
576
+ "learning_rate": 0.013666666666666667,
577
+ "loss": 0.1923,
578
+ "step": 950
579
+ },
580
+ {
581
+ "epoch": 4.28,
582
+ "learning_rate": 0.013600000000000001,
583
+ "loss": 0.1841,
584
+ "step": 960
585
+ },
586
+ {
587
+ "epoch": 4.32,
588
+ "learning_rate": 0.013533333333333333,
589
+ "loss": 0.1878,
590
+ "step": 970
591
+ },
592
+ {
593
+ "epoch": 4.37,
594
+ "learning_rate": 0.013466666666666667,
595
+ "loss": 0.192,
596
+ "step": 980
597
+ },
598
+ {
599
+ "epoch": 4.41,
600
+ "learning_rate": 0.0134,
601
+ "loss": 0.186,
602
+ "step": 990
603
+ },
604
+ {
605
+ "epoch": 4.46,
606
+ "learning_rate": 0.013333333333333332,
607
+ "loss": 0.1852,
608
+ "step": 1000
609
+ }
610
+ ],
611
+ "max_steps": 3000,
612
+ "num_train_epochs": 14,
613
+ "total_flos": 5.75649567735808e+16,
614
+ "trial_name": null,
615
+ "trial_params": null
616
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-1000/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e6686835e3bd90bbdc74d1b219b44b2e320a817dfae63b8e2323d2410ad705c7
3
+ size 3707
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/config.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "../THUDM/chatglm2-6b",
3
+ "add_bias_linear": false,
4
+ "add_qkv_bias": true,
5
+ "apply_query_key_layer_scaling": true,
6
+ "apply_residual_connection_post_layernorm": false,
7
+ "architectures": [
8
+ "ChatGLMForConditionalGeneration"
9
+ ],
10
+ "attention_dropout": 0.0,
11
+ "attention_softmax_in_fp32": true,
12
+ "auto_map": {
13
+ "AutoConfig": "configuration_chatglm.ChatGLMConfig",
14
+ "AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration",
15
+ "AutoModelForCausalLM": "modeling_chatglm.ChatGLMForConditionalGeneration",
16
+ "AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration"
17
+ },
18
+ "bias_dropout_fusion": true,
19
+ "eos_token_id": 2,
20
+ "ffn_hidden_size": 13696,
21
+ "fp32_residual_connection": false,
22
+ "hidden_dropout": 0.0,
23
+ "hidden_size": 4096,
24
+ "kv_channels": 128,
25
+ "layernorm_epsilon": 1e-05,
26
+ "model_type": "chatglm",
27
+ "multi_query_attention": true,
28
+ "multi_query_group_num": 2,
29
+ "num_attention_heads": 32,
30
+ "num_layers": 28,
31
+ "original_rope": true,
32
+ "pad_token_id": 0,
33
+ "padded_vocab_size": 65024,
34
+ "post_layer_norm": true,
35
+ "pre_seq_len": 128,
36
+ "prefix_projection": false,
37
+ "quantization_bit": 4,
38
+ "rmsnorm": true,
39
+ "seq_length": 32768,
40
+ "tie_word_embeddings": false,
41
+ "torch_dtype": "float16",
42
+ "transformers_version": "4.27.1",
43
+ "use_cache": true,
44
+ "vocab_size": 65024
45
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/configuration_chatglm.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+
4
+ class ChatGLMConfig(PretrainedConfig):
5
+ model_type = "chatglm"
6
+ def __init__(
7
+ self,
8
+ num_layers=28,
9
+ padded_vocab_size=65024,
10
+ hidden_size=4096,
11
+ ffn_hidden_size=13696,
12
+ kv_channels=128,
13
+ num_attention_heads=32,
14
+ seq_length=2048,
15
+ hidden_dropout=0.0,
16
+ attention_dropout=0.0,
17
+ layernorm_epsilon=1e-5,
18
+ rmsnorm=True,
19
+ apply_residual_connection_post_layernorm=False,
20
+ post_layer_norm=True,
21
+ add_bias_linear=False,
22
+ add_qkv_bias=False,
23
+ bias_dropout_fusion=True,
24
+ multi_query_attention=False,
25
+ multi_query_group_num=1,
26
+ apply_query_key_layer_scaling=True,
27
+ attention_softmax_in_fp32=True,
28
+ fp32_residual_connection=False,
29
+ quantization_bit=0,
30
+ pre_seq_len=None,
31
+ prefix_projection=False,
32
+ **kwargs
33
+ ):
34
+ self.num_layers = num_layers
35
+ self.vocab_size = padded_vocab_size
36
+ self.padded_vocab_size = padded_vocab_size
37
+ self.hidden_size = hidden_size
38
+ self.ffn_hidden_size = ffn_hidden_size
39
+ self.kv_channels = kv_channels
40
+ self.num_attention_heads = num_attention_heads
41
+ self.seq_length = seq_length
42
+ self.hidden_dropout = hidden_dropout
43
+ self.attention_dropout = attention_dropout
44
+ self.layernorm_epsilon = layernorm_epsilon
45
+ self.rmsnorm = rmsnorm
46
+ self.apply_residual_connection_post_layernorm = apply_residual_connection_post_layernorm
47
+ self.post_layer_norm = post_layer_norm
48
+ self.add_bias_linear = add_bias_linear
49
+ self.add_qkv_bias = add_qkv_bias
50
+ self.bias_dropout_fusion = bias_dropout_fusion
51
+ self.multi_query_attention = multi_query_attention
52
+ self.multi_query_group_num = multi_query_group_num
53
+ self.apply_query_key_layer_scaling = apply_query_key_layer_scaling
54
+ self.attention_softmax_in_fp32 = attention_softmax_in_fp32
55
+ self.fp32_residual_connection = fp32_residual_connection
56
+ self.quantization_bit = quantization_bit
57
+ self.pre_seq_len = pre_seq_len
58
+ self.prefix_projection = prefix_projection
59
+ super().__init__(**kwargs)
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "eos_token_id": 2,
4
+ "pad_token_id": 0,
5
+ "transformers_version": "4.27.1"
6
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/modeling_chatglm.py ADDED
@@ -0,0 +1,1193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ PyTorch ChatGLM model. """
2
+
3
+ import math
4
+ import copy
5
+ import warnings
6
+ import re
7
+ import sys
8
+
9
+ import torch
10
+ import torch.utils.checkpoint
11
+ import torch.nn.functional as F
12
+ from torch import nn
13
+ from torch.nn import CrossEntropyLoss, LayerNorm
14
+ from torch.nn.utils import skip_init
15
+ from typing import Optional, Tuple, Union, List, Callable, Dict, Any
16
+
17
+ from transformers.modeling_outputs import (
18
+ BaseModelOutputWithPast,
19
+ CausalLMOutputWithPast,
20
+ )
21
+ from transformers.modeling_utils import PreTrainedModel
22
+ from transformers.utils import logging
23
+ from transformers.generation.logits_process import LogitsProcessor
24
+ from transformers.generation.utils import LogitsProcessorList, StoppingCriteriaList, GenerationConfig, ModelOutput
25
+
26
+ from .configuration_chatglm import ChatGLMConfig
27
+
28
+ # flags required to enable jit fusion kernels
29
+
30
+ if sys.platform != 'darwin':
31
+ torch._C._jit_set_profiling_mode(False)
32
+ torch._C._jit_set_profiling_executor(False)
33
+ torch._C._jit_override_can_fuse_on_cpu(True)
34
+ torch._C._jit_override_can_fuse_on_gpu(True)
35
+
36
+ logger = logging.get_logger(__name__)
37
+
38
+ _CHECKPOINT_FOR_DOC = "THUDM/ChatGLM2-6B"
39
+ _CONFIG_FOR_DOC = "ChatGLM6BConfig"
40
+
41
+ CHATGLM_6B_PRETRAINED_MODEL_ARCHIVE_LIST = [
42
+ "THUDM/chatglm2-6b",
43
+ # See all ChatGLM models at https://huggingface.co/models?filter=chatglm
44
+ ]
45
+
46
+
47
+ def default_init(cls, *args, **kwargs):
48
+ return cls(*args, **kwargs)
49
+
50
+
51
+ class InvalidScoreLogitsProcessor(LogitsProcessor):
52
+ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
53
+ if torch.isnan(scores).any() or torch.isinf(scores).any():
54
+ scores.zero_()
55
+ scores[..., 5] = 5e4
56
+ return scores
57
+
58
+
59
+ class PrefixEncoder(torch.nn.Module):
60
+ """
61
+ The torch.nn model to encode the prefix
62
+ Input shape: (batch-size, prefix-length)
63
+ Output shape: (batch-size, prefix-length, 2*layers*hidden)
64
+ """
65
+
66
+ def __init__(self, config: ChatGLMConfig):
67
+ super().__init__()
68
+ self.prefix_projection = config.prefix_projection
69
+ if self.prefix_projection:
70
+ # Use a two-layer MLP to encode the prefix
71
+ kv_size = config.num_layers * config.kv_channels * config.multi_query_group_num * 2
72
+ self.embedding = torch.nn.Embedding(config.pre_seq_len, kv_size)
73
+ self.trans = torch.nn.Sequential(
74
+ torch.nn.Linear(kv_size, config.hidden_size),
75
+ torch.nn.Tanh(),
76
+ torch.nn.Linear(config.hidden_size, kv_size)
77
+ )
78
+ else:
79
+ self.embedding = torch.nn.Embedding(config.pre_seq_len,
80
+ config.num_layers * config.kv_channels * config.multi_query_group_num * 2)
81
+
82
+ def forward(self, prefix: torch.Tensor):
83
+ if self.prefix_projection:
84
+ prefix_tokens = self.embedding(prefix)
85
+ past_key_values = self.trans(prefix_tokens)
86
+ else:
87
+ past_key_values = self.embedding(prefix)
88
+ return past_key_values
89
+
90
+
91
+ def split_tensor_along_last_dim(
92
+ tensor: torch.Tensor,
93
+ num_partitions: int,
94
+ contiguous_split_chunks: bool = False,
95
+ ) -> List[torch.Tensor]:
96
+ """Split a tensor along its last dimension.
97
+
98
+ Arguments:
99
+ tensor: input tensor.
100
+ num_partitions: number of partitions to split the tensor
101
+ contiguous_split_chunks: If True, make each chunk contiguous
102
+ in memory.
103
+
104
+ Returns:
105
+ A list of Tensors
106
+ """
107
+ # Get the size and dimension.
108
+ last_dim = tensor.dim() - 1
109
+ last_dim_size = tensor.size()[last_dim] // num_partitions
110
+ # Split.
111
+ tensor_list = torch.split(tensor, last_dim_size, dim=last_dim)
112
+ # Note: torch.split does not create contiguous tensors by default.
113
+ if contiguous_split_chunks:
114
+ return tuple(chunk.contiguous() for chunk in tensor_list)
115
+
116
+ return tensor_list
117
+
118
+
119
+ class RotaryEmbedding(nn.Module):
120
+ def __init__(self, dim, original_impl=False, device=None, dtype=None):
121
+ super().__init__()
122
+ inv_freq = 1.0 / (10000 ** (torch.arange(0, dim, 2, device=device).to(dtype=dtype) / dim))
123
+ self.register_buffer("inv_freq", inv_freq)
124
+ self.dim = dim
125
+ self.original_impl = original_impl
126
+
127
+ def forward_impl(
128
+ self, seq_len: int, n_elem: int, dtype: torch.dtype, device: torch.device, base: int = 10000
129
+ ):
130
+ """Enhanced Transformer with Rotary Position Embedding.
131
+
132
+ Derived from: https://github.com/labmlai/annotated_deep_learning_paper_implementations/blob/master/labml_nn/
133
+ transformers/rope/__init__.py. MIT License:
134
+ https://github.com/labmlai/annotated_deep_learning_paper_implementations/blob/master/license.
135
+ """
136
+ # $\Theta = {\theta_i = 10000^{\frac{2(i-1)}{d}}, i \in [1, 2, ..., \frac{d}{2}]}$
137
+ theta = 1.0 / (base ** (torch.arange(0, n_elem, 2, dtype=dtype, device=device) / n_elem))
138
+
139
+ # Create position indexes `[0, 1, ..., seq_len - 1]`
140
+ seq_idx = torch.arange(seq_len, dtype=dtype, device=device)
141
+
142
+ # Calculate the product of position index and $\theta_i$
143
+ idx_theta = torch.outer(seq_idx, theta).float()
144
+
145
+ cache = torch.stack([torch.cos(idx_theta), torch.sin(idx_theta)], dim=-1)
146
+
147
+ # this is to mimic the behaviour of complex32, else we will get different results
148
+ if dtype in (torch.float16, torch.bfloat16, torch.int8):
149
+ cache = cache.bfloat16() if dtype == torch.bfloat16 else cache.half()
150
+ return cache
151
+
152
+ def forward(self, max_seq_len, offset=0):
153
+ return self.forward_impl(
154
+ max_seq_len, self.dim, dtype=self.inv_freq.dtype, device=self.inv_freq.device
155
+ )
156
+
157
+
158
+ @torch.jit.script
159
+ def apply_rotary_pos_emb(x: torch.Tensor, rope_cache: torch.Tensor) -> torch.Tensor:
160
+ # x: [sq, b, np, hn]
161
+ sq, b, np, hn = x.size(0), x.size(1), x.size(2), x.size(3)
162
+ rot_dim = rope_cache.shape[-2] * 2
163
+ x, x_pass = x[..., :rot_dim], x[..., rot_dim:]
164
+ # truncate to support variable sizes
165
+ rope_cache = rope_cache[:sq]
166
+ xshaped = x.reshape(sq, -1, np, rot_dim // 2, 2)
167
+ rope_cache = rope_cache.view(sq, -1, 1, xshaped.size(3), 2)
168
+ x_out2 = torch.stack(
169
+ [
170
+ xshaped[..., 0] * rope_cache[..., 0] - xshaped[..., 1] * rope_cache[..., 1],
171
+ xshaped[..., 1] * rope_cache[..., 0] + xshaped[..., 0] * rope_cache[..., 1],
172
+ ],
173
+ -1,
174
+ )
175
+ x_out2 = x_out2.flatten(3)
176
+ return torch.cat((x_out2, x_pass), dim=-1)
177
+
178
+
179
+ class RMSNorm(torch.nn.Module):
180
+ def __init__(self, normalized_shape, eps=1e-5, device=None, dtype=None, **kwargs):
181
+ super().__init__()
182
+ self.weight = torch.nn.Parameter(torch.empty(normalized_shape, device=device, dtype=dtype))
183
+ self.eps = eps
184
+
185
+ def forward(self, hidden_states: torch.Tensor):
186
+ input_dtype = hidden_states.dtype
187
+ variance = hidden_states.to(torch.float32).pow(2).mean(-1, keepdim=True)
188
+ hidden_states = hidden_states * torch.rsqrt(variance + self.eps)
189
+
190
+ return (self.weight * hidden_states).to(input_dtype)
191
+
192
+
193
+ class CoreAttention(torch.nn.Module):
194
+ def __init__(self, config: ChatGLMConfig, layer_number):
195
+ super(CoreAttention, self).__init__()
196
+
197
+ self.apply_query_key_layer_scaling = config.apply_query_key_layer_scaling
198
+ self.attention_softmax_in_fp32 = config.attention_softmax_in_fp32
199
+ if self.apply_query_key_layer_scaling:
200
+ self.attention_softmax_in_fp32 = True
201
+ self.layer_number = max(1, layer_number)
202
+
203
+ projection_size = config.kv_channels * config.num_attention_heads
204
+
205
+ # Per attention head and per partition values.
206
+ self.hidden_size_per_partition = projection_size
207
+ self.hidden_size_per_attention_head = projection_size // config.num_attention_heads
208
+ self.num_attention_heads_per_partition = config.num_attention_heads
209
+
210
+ coeff = None
211
+ self.norm_factor = math.sqrt(self.hidden_size_per_attention_head)
212
+ if self.apply_query_key_layer_scaling:
213
+ coeff = self.layer_number
214
+ self.norm_factor *= coeff
215
+ self.coeff = coeff
216
+
217
+ self.attention_dropout = torch.nn.Dropout(config.attention_dropout)
218
+
219
+ def forward(self, query_layer, key_layer, value_layer, attention_mask):
220
+ pytorch_major_version = int(torch.__version__.split('.')[0])
221
+ if pytorch_major_version >= 2:
222
+ query_layer, key_layer, value_layer = [k.permute(1, 2, 0, 3) for k in [query_layer, key_layer, value_layer]]
223
+ if attention_mask is None and query_layer.shape[2] == key_layer.shape[2]:
224
+ context_layer = torch.nn.functional.scaled_dot_product_attention(query_layer, key_layer, value_layer,
225
+ is_causal=True)
226
+ else:
227
+ if attention_mask is not None:
228
+ attention_mask = ~attention_mask
229
+ context_layer = torch.nn.functional.scaled_dot_product_attention(query_layer, key_layer, value_layer,
230
+ attention_mask)
231
+ context_layer = context_layer.permute(2, 0, 1, 3)
232
+ new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size_per_partition,)
233
+ context_layer = context_layer.reshape(*new_context_layer_shape)
234
+ else:
235
+ # Raw attention scores
236
+
237
+ # [b, np, sq, sk]
238
+ output_size = (query_layer.size(1), query_layer.size(2), query_layer.size(0), key_layer.size(0))
239
+
240
+ # [sq, b, np, hn] -> [sq, b * np, hn]
241
+ query_layer = query_layer.view(output_size[2], output_size[0] * output_size[1], -1)
242
+ # [sk, b, np, hn] -> [sk, b * np, hn]
243
+ key_layer = key_layer.view(output_size[3], output_size[0] * output_size[1], -1)
244
+
245
+ # preallocting input tensor: [b * np, sq, sk]
246
+ matmul_input_buffer = torch.empty(
247
+ output_size[0] * output_size[1], output_size[2], output_size[3], dtype=query_layer.dtype,
248
+ device=query_layer.device
249
+ )
250
+
251
+ # Raw attention scores. [b * np, sq, sk]
252
+ matmul_result = torch.baddbmm(
253
+ matmul_input_buffer,
254
+ query_layer.transpose(0, 1), # [b * np, sq, hn]
255
+ key_layer.transpose(0, 1).transpose(1, 2), # [b * np, hn, sk]
256
+ beta=0.0,
257
+ alpha=(1.0 / self.norm_factor),
258
+ )
259
+
260
+ # change view to [b, np, sq, sk]
261
+ attention_scores = matmul_result.view(*output_size)
262
+
263
+ # ===========================
264
+ # Attention probs and dropout
265
+ # ===========================
266
+
267
+ # attention scores and attention mask [b, np, sq, sk]
268
+ if self.attention_softmax_in_fp32:
269
+ attention_scores = attention_scores.float()
270
+ if self.coeff is not None:
271
+ attention_scores = attention_scores * self.coeff
272
+ if attention_mask is None and attention_scores.shape[2] == attention_scores.shape[3]:
273
+ attention_mask = torch.ones(output_size[0], 1, output_size[2], output_size[3],
274
+ device=attention_scores.device, dtype=torch.bool)
275
+ attention_mask.tril_()
276
+ attention_mask = ~attention_mask
277
+ if attention_mask is not None:
278
+ attention_scores = attention_scores.masked_fill(attention_mask, float("-inf"))
279
+ attention_probs = F.softmax(attention_scores, dim=-1)
280
+ attention_probs = attention_probs.type_as(value_layer)
281
+
282
+ # This is actually dropping out entire tokens to attend to, which might
283
+ # seem a bit unusual, but is taken from the original Transformer paper.
284
+ attention_probs = self.attention_dropout(attention_probs)
285
+ # =========================
286
+ # Context layer. [sq, b, hp]
287
+ # =========================
288
+
289
+ # value_layer -> context layer.
290
+ # [sk, b, np, hn] --> [b, np, sq, hn]
291
+
292
+ # context layer shape: [b, np, sq, hn]
293
+ output_size = (value_layer.size(1), value_layer.size(2), query_layer.size(0), value_layer.size(3))
294
+ # change view [sk, b * np, hn]
295
+ value_layer = value_layer.view(value_layer.size(0), output_size[0] * output_size[1], -1)
296
+ # change view [b * np, sq, sk]
297
+ attention_probs = attention_probs.view(output_size[0] * output_size[1], output_size[2], -1)
298
+ # matmul: [b * np, sq, hn]
299
+ context_layer = torch.bmm(attention_probs, value_layer.transpose(0, 1))
300
+ # change view [b, np, sq, hn]
301
+ context_layer = context_layer.view(*output_size)
302
+ # [b, np, sq, hn] --> [sq, b, np, hn]
303
+ context_layer = context_layer.permute(2, 0, 1, 3).contiguous()
304
+ # [sq, b, np, hn] --> [sq, b, hp]
305
+ new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size_per_partition,)
306
+ context_layer = context_layer.view(*new_context_layer_shape)
307
+
308
+ return context_layer
309
+
310
+
311
+ class SelfAttention(torch.nn.Module):
312
+ """Parallel self-attention layer abstract class.
313
+
314
+ Self-attention layer takes input with size [s, b, h]
315
+ and returns output of the same size.
316
+ """
317
+
318
+ def __init__(self, config: ChatGLMConfig, layer_number, device=None):
319
+ super(SelfAttention, self).__init__()
320
+ self.layer_number = max(1, layer_number)
321
+
322
+ self.projection_size = config.kv_channels * config.num_attention_heads
323
+
324
+ # Per attention head and per partition values.
325
+ self.hidden_size_per_attention_head = self.projection_size // config.num_attention_heads
326
+ self.num_attention_heads_per_partition = config.num_attention_heads
327
+
328
+ self.multi_query_attention = config.multi_query_attention
329
+ self.qkv_hidden_size = 3 * self.projection_size
330
+ if self.multi_query_attention:
331
+ self.num_multi_query_groups_per_partition = config.multi_query_group_num
332
+ self.qkv_hidden_size = (
333
+ self.projection_size + 2 * self.hidden_size_per_attention_head * config.multi_query_group_num
334
+ )
335
+ self.query_key_value = nn.Linear(config.hidden_size, self.qkv_hidden_size,
336
+ bias=config.add_bias_linear or config.add_qkv_bias,
337
+ device=device, **_config_to_kwargs(config)
338
+ )
339
+
340
+ self.core_attention = CoreAttention(config, self.layer_number)
341
+
342
+ # Output.
343
+ self.dense = nn.Linear(self.projection_size, config.hidden_size, bias=config.add_bias_linear,
344
+ device=device, **_config_to_kwargs(config)
345
+ )
346
+
347
+ def _allocate_memory(self, inference_max_sequence_len, batch_size, device=None, dtype=None):
348
+ if self.multi_query_attention:
349
+ num_attention_heads = self.num_multi_query_groups_per_partition
350
+ else:
351
+ num_attention_heads = self.num_attention_heads_per_partition
352
+ return torch.empty(
353
+ inference_max_sequence_len,
354
+ batch_size,
355
+ num_attention_heads,
356
+ self.hidden_size_per_attention_head,
357
+ dtype=dtype,
358
+ device=device,
359
+ )
360
+
361
+ def forward(
362
+ self, hidden_states, attention_mask, rotary_pos_emb, kv_cache=None, use_cache=True
363
+ ):
364
+ # hidden_states: [sq, b, h]
365
+
366
+ # =================================================
367
+ # Pre-allocate memory for key-values for inference.
368
+ # =================================================
369
+ # =====================
370
+ # Query, Key, and Value
371
+ # =====================
372
+
373
+ # Attention heads [sq, b, h] --> [sq, b, (np * 3 * hn)]
374
+ mixed_x_layer = self.query_key_value(hidden_states)
375
+
376
+ if self.multi_query_attention:
377
+ (query_layer, key_layer, value_layer) = mixed_x_layer.split(
378
+ [
379
+ self.num_attention_heads_per_partition * self.hidden_size_per_attention_head,
380
+ self.num_multi_query_groups_per_partition * self.hidden_size_per_attention_head,
381
+ self.num_multi_query_groups_per_partition * self.hidden_size_per_attention_head,
382
+ ],
383
+ dim=-1,
384
+ )
385
+ query_layer = query_layer.view(
386
+ query_layer.size()[:-1] + (self.num_attention_heads_per_partition, self.hidden_size_per_attention_head)
387
+ )
388
+ key_layer = key_layer.view(
389
+ key_layer.size()[:-1] + (self.num_multi_query_groups_per_partition, self.hidden_size_per_attention_head)
390
+ )
391
+ value_layer = value_layer.view(
392
+ value_layer.size()[:-1]
393
+ + (self.num_multi_query_groups_per_partition, self.hidden_size_per_attention_head)
394
+ )
395
+ else:
396
+ new_tensor_shape = mixed_x_layer.size()[:-1] + \
397
+ (self.num_attention_heads_per_partition,
398
+ 3 * self.hidden_size_per_attention_head)
399
+ mixed_x_layer = mixed_x_layer.view(*new_tensor_shape)
400
+
401
+ # [sq, b, np, 3 * hn] --> 3 [sq, b, np, hn]
402
+ (query_layer, key_layer, value_layer) = split_tensor_along_last_dim(mixed_x_layer, 3)
403
+
404
+ # apply relative positional encoding (rotary embedding)
405
+ if rotary_pos_emb is not None:
406
+ query_layer = apply_rotary_pos_emb(query_layer, rotary_pos_emb)
407
+ key_layer = apply_rotary_pos_emb(key_layer, rotary_pos_emb)
408
+
409
+ # adjust key and value for inference
410
+ if kv_cache is not None:
411
+ cache_k, cache_v = kv_cache
412
+ key_layer = torch.cat((cache_k, key_layer), dim=0)
413
+ value_layer = torch.cat((cache_v, value_layer), dim=0)
414
+ if use_cache:
415
+ kv_cache = (key_layer, value_layer)
416
+ else:
417
+ kv_cache = None
418
+
419
+ if self.multi_query_attention:
420
+ key_layer = key_layer.unsqueeze(-2)
421
+ key_layer = key_layer.expand(
422
+ -1, -1, -1, self.num_attention_heads_per_partition // self.num_multi_query_groups_per_partition, -1
423
+ )
424
+ key_layer = key_layer.contiguous().view(
425
+ key_layer.size()[:2] + (self.num_attention_heads_per_partition, self.hidden_size_per_attention_head)
426
+ )
427
+ value_layer = value_layer.unsqueeze(-2)
428
+ value_layer = value_layer.expand(
429
+ -1, -1, -1, self.num_attention_heads_per_partition // self.num_multi_query_groups_per_partition, -1
430
+ )
431
+ value_layer = value_layer.contiguous().view(
432
+ value_layer.size()[:2] + (self.num_attention_heads_per_partition, self.hidden_size_per_attention_head)
433
+ )
434
+
435
+ # ==================================
436
+ # core attention computation
437
+ # ==================================
438
+
439
+ context_layer = self.core_attention(query_layer, key_layer, value_layer, attention_mask)
440
+
441
+ # =================
442
+ # Output. [sq, b, h]
443
+ # =================
444
+
445
+ output = self.dense(context_layer)
446
+
447
+ return output, kv_cache
448
+
449
+
450
+ def _config_to_kwargs(args):
451
+ common_kwargs = {
452
+ "dtype": args.torch_dtype,
453
+ }
454
+ return common_kwargs
455
+
456
+
457
+ class MLP(torch.nn.Module):
458
+ """MLP.
459
+
460
+ MLP will take the input with h hidden state, project it to 4*h
461
+ hidden dimension, perform nonlinear transformation, and project the
462
+ state back into h hidden dimension.
463
+ """
464
+
465
+ def __init__(self, config: ChatGLMConfig, device=None):
466
+ super(MLP, self).__init__()
467
+
468
+ self.add_bias = config.add_bias_linear
469
+
470
+ # Project to 4h. If using swiglu double the output width, see https://arxiv.org/pdf/2002.05202.pdf
471
+ self.dense_h_to_4h = nn.Linear(
472
+ config.hidden_size,
473
+ config.ffn_hidden_size * 2,
474
+ bias=self.add_bias,
475
+ device=device,
476
+ **_config_to_kwargs(config)
477
+ )
478
+
479
+ def swiglu(x):
480
+ x = torch.chunk(x, 2, dim=-1)
481
+ return F.silu(x[0]) * x[1]
482
+
483
+ self.activation_func = swiglu
484
+
485
+ # Project back to h.
486
+ self.dense_4h_to_h = nn.Linear(
487
+ config.ffn_hidden_size,
488
+ config.hidden_size,
489
+ bias=self.add_bias,
490
+ device=device,
491
+ **_config_to_kwargs(config)
492
+ )
493
+
494
+ def forward(self, hidden_states):
495
+ # [s, b, 4hp]
496
+ intermediate_parallel = self.dense_h_to_4h(hidden_states)
497
+ intermediate_parallel = self.activation_func(intermediate_parallel)
498
+ # [s, b, h]
499
+ output = self.dense_4h_to_h(intermediate_parallel)
500
+ return output
501
+
502
+
503
+ class GLMBlock(torch.nn.Module):
504
+ """A single transformer layer.
505
+
506
+ Transformer layer takes input with size [s, b, h] and returns an
507
+ output of the same size.
508
+ """
509
+
510
+ def __init__(self, config: ChatGLMConfig, layer_number, device=None):
511
+ super(GLMBlock, self).__init__()
512
+ self.layer_number = layer_number
513
+
514
+ self.apply_residual_connection_post_layernorm = config.apply_residual_connection_post_layernorm
515
+
516
+ self.fp32_residual_connection = config.fp32_residual_connection
517
+
518
+ LayerNormFunc = RMSNorm if config.rmsnorm else LayerNorm
519
+ # Layernorm on the input data.
520
+ self.input_layernorm = LayerNormFunc(config.hidden_size, eps=config.layernorm_epsilon, device=device,
521
+ dtype=config.torch_dtype)
522
+
523
+ # Self attention.
524
+ self.self_attention = SelfAttention(config, layer_number, device=device)
525
+ self.hidden_dropout = config.hidden_dropout
526
+
527
+ # Layernorm on the attention output
528
+ self.post_attention_layernorm = LayerNormFunc(config.hidden_size, eps=config.layernorm_epsilon, device=device,
529
+ dtype=config.torch_dtype)
530
+
531
+ # MLP
532
+ self.mlp = MLP(config, device=device)
533
+
534
+ def forward(
535
+ self, hidden_states, attention_mask, rotary_pos_emb, kv_cache=None, use_cache=True,
536
+ ):
537
+ # hidden_states: [s, b, h]
538
+
539
+ # Layer norm at the beginning of the transformer layer.
540
+ layernorm_output = self.input_layernorm(hidden_states)
541
+ # Self attention.
542
+ attention_output, kv_cache = self.self_attention(
543
+ layernorm_output,
544
+ attention_mask,
545
+ rotary_pos_emb,
546
+ kv_cache=kv_cache,
547
+ use_cache=use_cache
548
+ )
549
+
550
+ # Residual connection.
551
+ if self.apply_residual_connection_post_layernorm:
552
+ residual = layernorm_output
553
+ else:
554
+ residual = hidden_states
555
+
556
+ layernorm_input = torch.nn.functional.dropout(attention_output, p=self.hidden_dropout, training=self.training)
557
+ layernorm_input = residual + layernorm_input
558
+
559
+ # Layer norm post the self attention.
560
+ layernorm_output = self.post_attention_layernorm(layernorm_input)
561
+
562
+ # MLP.
563
+ mlp_output = self.mlp(layernorm_output)
564
+
565
+ # Second residual connection.
566
+ if self.apply_residual_connection_post_layernorm:
567
+ residual = layernorm_output
568
+ else:
569
+ residual = layernorm_input
570
+
571
+ output = torch.nn.functional.dropout(mlp_output, p=self.hidden_dropout, training=self.training)
572
+ output = residual + output
573
+
574
+ return output, kv_cache
575
+
576
+
577
+ class GLMTransformer(torch.nn.Module):
578
+ """Transformer class."""
579
+
580
+ def __init__(self, config: ChatGLMConfig, device=None):
581
+ super(GLMTransformer, self).__init__()
582
+
583
+ self.fp32_residual_connection = config.fp32_residual_connection
584
+ self.post_layer_norm = config.post_layer_norm
585
+
586
+ # Number of layers.
587
+ self.num_layers = config.num_layers
588
+
589
+ # Transformer layers.
590
+ def build_layer(layer_number):
591
+ return GLMBlock(config, layer_number, device=device)
592
+
593
+ self.layers = torch.nn.ModuleList([build_layer(i + 1) for i in range(self.num_layers)])
594
+
595
+ if self.post_layer_norm:
596
+ LayerNormFunc = RMSNorm if config.rmsnorm else LayerNorm
597
+ # Final layer norm before output.
598
+ self.final_layernorm = LayerNormFunc(config.hidden_size, eps=config.layernorm_epsilon, device=device,
599
+ dtype=config.torch_dtype)
600
+
601
+ self.gradient_checkpointing = False
602
+
603
+ def _get_layer(self, layer_number):
604
+ return self.layers[layer_number]
605
+
606
+ def forward(
607
+ self, hidden_states, attention_mask, rotary_pos_emb, kv_caches=None,
608
+ use_cache: Optional[bool] = True,
609
+ output_hidden_states: Optional[bool] = False,
610
+ ):
611
+ if not kv_caches:
612
+ kv_caches = [None for _ in range(self.num_layers)]
613
+ presents = () if use_cache else None
614
+ if self.gradient_checkpointing and self.training:
615
+ if use_cache:
616
+ logger.warning_once(
617
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
618
+ )
619
+ use_cache = False
620
+
621
+ all_self_attentions = None
622
+ all_hidden_states = () if output_hidden_states else None
623
+ for index in range(self.num_layers):
624
+ if output_hidden_states:
625
+ all_hidden_states = all_hidden_states + (hidden_states,)
626
+
627
+ layer = self._get_layer(index)
628
+ if self.gradient_checkpointing and self.training:
629
+ layer_ret = torch.utils.checkpoint.checkpoint(
630
+ layer,
631
+ hidden_states,
632
+ attention_mask,
633
+ rotary_pos_emb,
634
+ kv_caches[index],
635
+ use_cache
636
+ )
637
+ else:
638
+ layer_ret = layer(
639
+ hidden_states,
640
+ attention_mask,
641
+ rotary_pos_emb,
642
+ kv_cache=kv_caches[index],
643
+ use_cache=use_cache
644
+ )
645
+ hidden_states, kv_cache = layer_ret
646
+ if use_cache:
647
+ presents = presents + (kv_cache,)
648
+
649
+ if output_hidden_states:
650
+ all_hidden_states = all_hidden_states + (hidden_states,)
651
+
652
+ # Final layer norm.
653
+ if self.post_layer_norm:
654
+ hidden_states = self.final_layernorm(hidden_states)
655
+
656
+ return hidden_states, presents, all_hidden_states, all_self_attentions
657
+
658
+
659
+ class ChatGLMPreTrainedModel(PreTrainedModel):
660
+ """
661
+ An abstract class to handle weights initialization and
662
+ a simple interface for downloading and loading pretrained models.
663
+ """
664
+
665
+ is_parallelizable = False
666
+ supports_gradient_checkpointing = True
667
+ config_class = ChatGLMConfig
668
+ base_model_prefix = "transformer"
669
+ _no_split_modules = ["GLMBlock"]
670
+
671
+ def _init_weights(self, module: nn.Module):
672
+ """Initialize the weights."""
673
+ return
674
+
675
+ def get_masks(self, input_ids, past_key_values, padding_mask=None):
676
+ batch_size, seq_length = input_ids.shape
677
+ full_attention_mask = torch.ones(batch_size, seq_length, seq_length, device=input_ids.device)
678
+ full_attention_mask.tril_()
679
+ past_length = 0
680
+ if past_key_values:
681
+ past_length = past_key_values[0][0].shape[0]
682
+ if past_length:
683
+ full_attention_mask = torch.cat((torch.ones(batch_size, seq_length, past_length,
684
+ device=input_ids.device), full_attention_mask), dim=-1)
685
+ if padding_mask is not None:
686
+ full_attention_mask = full_attention_mask * padding_mask.unsqueeze(1)
687
+ if not past_length and padding_mask is not None:
688
+ full_attention_mask -= padding_mask.unsqueeze(-1) - 1
689
+ full_attention_mask = (full_attention_mask < 0.5).bool()
690
+ full_attention_mask.unsqueeze_(1)
691
+ return full_attention_mask
692
+
693
+ def get_position_ids(self, input_ids, device):
694
+ batch_size, seq_length = input_ids.shape
695
+ position_ids = torch.arange(seq_length, dtype=torch.long, device=device).unsqueeze(0).repeat(batch_size, 1)
696
+ return position_ids
697
+
698
+ def _set_gradient_checkpointing(self, module, value=False):
699
+ if isinstance(module, GLMTransformer):
700
+ module.gradient_checkpointing = value
701
+
702
+
703
+ class Embedding(torch.nn.Module):
704
+ """Language model embeddings."""
705
+
706
+ def __init__(self, config: ChatGLMConfig, device=None):
707
+ super(Embedding, self).__init__()
708
+
709
+ self.hidden_size = config.hidden_size
710
+ # Word embeddings (parallel).
711
+ self.word_embeddings = nn.Embedding(
712
+ config.padded_vocab_size,
713
+ self.hidden_size,
714
+ dtype=config.torch_dtype,
715
+ device=device
716
+ )
717
+ self.fp32_residual_connection = config.fp32_residual_connection
718
+
719
+ def forward(self, input_ids):
720
+ # Embeddings.
721
+ words_embeddings = self.word_embeddings(input_ids)
722
+ embeddings = words_embeddings
723
+ # Data format change to avoid explicit tranposes : [b s h] --> [s b h].
724
+ embeddings = embeddings.transpose(0, 1).contiguous()
725
+ # If the input flag for fp32 residual connection is set, convert for float.
726
+ if self.fp32_residual_connection:
727
+ embeddings = embeddings.float()
728
+ return embeddings
729
+
730
+
731
+ class ChatGLMModel(ChatGLMPreTrainedModel):
732
+ def __init__(self, config: ChatGLMConfig, device=None, empty_init=True):
733
+ super().__init__(config)
734
+ if empty_init:
735
+ init_method = skip_init
736
+ else:
737
+ init_method = default_init
738
+ init_kwargs = {}
739
+ if device is not None:
740
+ init_kwargs["device"] = device
741
+ self.embedding = init_method(Embedding, config, **init_kwargs)
742
+ self.num_layers = config.num_layers
743
+ self.multi_query_group_num = config.multi_query_group_num
744
+ self.kv_channels = config.kv_channels
745
+
746
+ # Rotary positional embeddings
747
+ self.seq_length = config.seq_length
748
+ rotary_dim = (
749
+ config.hidden_size // config.num_attention_heads if config.kv_channels is None else config.kv_channels
750
+ )
751
+
752
+ self.rotary_pos_emb = RotaryEmbedding(rotary_dim // 2, original_impl=config.original_rope, device=device,
753
+ dtype=config.torch_dtype)
754
+ self.encoder = init_method(GLMTransformer, config, **init_kwargs)
755
+ self.output_layer = init_method(nn.Linear, config.hidden_size, config.padded_vocab_size, bias=False,
756
+ dtype=config.torch_dtype, **init_kwargs)
757
+ self.pre_seq_len = config.pre_seq_len
758
+ self.prefix_projection = config.prefix_projection
759
+ if self.pre_seq_len is not None:
760
+ for param in self.parameters():
761
+ param.requires_grad = False
762
+ self.prefix_tokens = torch.arange(self.pre_seq_len).long()
763
+ self.prefix_encoder = PrefixEncoder(config)
764
+ self.dropout = torch.nn.Dropout(0.1)
765
+
766
+ def get_input_embeddings(self):
767
+ return self.embedding.word_embeddings
768
+
769
+ def get_prompt(self, batch_size, device, dtype=torch.half):
770
+ prefix_tokens = self.prefix_tokens.unsqueeze(0).expand(batch_size, -1).to(device)
771
+ past_key_values = self.prefix_encoder(prefix_tokens).type(dtype)
772
+ past_key_values = past_key_values.view(
773
+ batch_size,
774
+ self.pre_seq_len,
775
+ self.num_layers * 2,
776
+ self.multi_query_group_num,
777
+ self.kv_channels
778
+ )
779
+ # seq_len, b, nh, hidden_size
780
+ past_key_values = self.dropout(past_key_values)
781
+ past_key_values = past_key_values.permute([2, 1, 0, 3, 4]).split(2)
782
+ return past_key_values
783
+
784
+ def forward(
785
+ self,
786
+ input_ids,
787
+ position_ids: Optional[torch.Tensor] = None,
788
+ attention_mask: Optional[torch.BoolTensor] = None,
789
+ full_attention_mask: Optional[torch.BoolTensor] = None,
790
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
791
+ inputs_embeds: Optional[torch.Tensor] = None,
792
+ use_cache: Optional[bool] = None,
793
+ output_hidden_states: Optional[bool] = None,
794
+ return_dict: Optional[bool] = None,
795
+ ):
796
+ output_hidden_states = (
797
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
798
+ )
799
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
800
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
801
+
802
+ batch_size, seq_length = input_ids.shape
803
+
804
+ if inputs_embeds is None:
805
+ inputs_embeds = self.embedding(input_ids)
806
+
807
+ if self.pre_seq_len is not None:
808
+ if past_key_values is None:
809
+ past_key_values = self.get_prompt(batch_size=batch_size, device=input_ids.device,
810
+ dtype=inputs_embeds.dtype)
811
+ if attention_mask is not None:
812
+ attention_mask = torch.cat([attention_mask.new_ones((batch_size, self.pre_seq_len)),
813
+ attention_mask], dim=-1)
814
+
815
+ if full_attention_mask is None:
816
+ if (attention_mask is not None and not attention_mask.all()) or (past_key_values and seq_length != 1):
817
+ full_attention_mask = self.get_masks(input_ids, past_key_values, padding_mask=attention_mask)
818
+
819
+ # Rotary positional embeddings
820
+ rotary_pos_emb = self.rotary_pos_emb(self.seq_length)
821
+ if position_ids is not None:
822
+ rotary_pos_emb = rotary_pos_emb[position_ids]
823
+ else:
824
+ rotary_pos_emb = rotary_pos_emb[None, :seq_length]
825
+ rotary_pos_emb = rotary_pos_emb.transpose(0, 1).contiguous()
826
+
827
+ # Run encoder.
828
+ hidden_states, presents, all_hidden_states, all_self_attentions = self.encoder(
829
+ inputs_embeds, full_attention_mask, rotary_pos_emb=rotary_pos_emb,
830
+ kv_caches=past_key_values, use_cache=use_cache, output_hidden_states=output_hidden_states
831
+ )
832
+
833
+ if not return_dict:
834
+ return tuple(v for v in [hidden_states, presents, all_hidden_states, all_self_attentions] if v is not None)
835
+
836
+ return BaseModelOutputWithPast(
837
+ last_hidden_state=hidden_states,
838
+ past_key_values=presents,
839
+ hidden_states=all_hidden_states,
840
+ attentions=all_self_attentions,
841
+ )
842
+
843
+ def quantize(self, weight_bit_width: int):
844
+ from .quantization import quantize
845
+ quantize(self.encoder, weight_bit_width)
846
+ return self
847
+
848
+
849
+ class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel):
850
+ def __init__(self, config: ChatGLMConfig, empty_init=True, device=None):
851
+ super().__init__(config)
852
+
853
+ self.max_sequence_length = config.max_length
854
+ self.transformer = ChatGLMModel(config, empty_init=empty_init, device=device)
855
+ self.config = config
856
+ self.quantized = False
857
+
858
+ if self.config.quantization_bit:
859
+ self.quantize(self.config.quantization_bit, empty_init=True)
860
+
861
+ def _update_model_kwargs_for_generation(
862
+ self,
863
+ outputs: ModelOutput,
864
+ model_kwargs: Dict[str, Any],
865
+ is_encoder_decoder: bool = False,
866
+ standardize_cache_format: bool = False,
867
+ ) -> Dict[str, Any]:
868
+ # update past_key_values
869
+ model_kwargs["past_key_values"] = self._extract_past_from_model_output(
870
+ outputs, standardize_cache_format=standardize_cache_format
871
+ )
872
+
873
+ # update attention mask
874
+ if "attention_mask" in model_kwargs:
875
+ attention_mask = model_kwargs["attention_mask"]
876
+ model_kwargs["attention_mask"] = torch.cat(
877
+ [attention_mask, attention_mask.new_ones((attention_mask.shape[0], 1))], dim=-1
878
+ )
879
+
880
+ # update position ids
881
+ if "position_ids" in model_kwargs:
882
+ position_ids = model_kwargs["position_ids"]
883
+ new_position_id = position_ids[..., -1:].clone()
884
+ new_position_id += 1
885
+ model_kwargs["position_ids"] = torch.cat(
886
+ [position_ids, new_position_id], dim=-1
887
+ )
888
+
889
+ model_kwargs["is_first_forward"] = False
890
+ return model_kwargs
891
+
892
+ def prepare_inputs_for_generation(
893
+ self,
894
+ input_ids: torch.LongTensor,
895
+ past_key_values: Optional[torch.Tensor] = None,
896
+ attention_mask: Optional[torch.Tensor] = None,
897
+ position_ids: Optional[torch.Tensor] = None,
898
+ is_first_forward: bool = True,
899
+ **kwargs
900
+ ) -> dict:
901
+ # only last token for input_ids if past is not None
902
+ if position_ids is None:
903
+ position_ids = self.get_position_ids(input_ids, device=input_ids.device)
904
+ if not is_first_forward:
905
+ position_ids = position_ids[..., -1:]
906
+ input_ids = input_ids[:, -1:]
907
+ return {
908
+ "input_ids": input_ids,
909
+ "past_key_values": past_key_values,
910
+ "position_ids": position_ids,
911
+ "attention_mask": attention_mask,
912
+ "return_last_logit": True
913
+ }
914
+
915
+ def forward(
916
+ self,
917
+ input_ids: Optional[torch.Tensor] = None,
918
+ position_ids: Optional[torch.Tensor] = None,
919
+ attention_mask: Optional[torch.Tensor] = None,
920
+ past_key_values: Optional[Tuple[torch.FloatTensor]] = None,
921
+ inputs_embeds: Optional[torch.Tensor] = None,
922
+ labels: Optional[torch.Tensor] = None,
923
+ use_cache: Optional[bool] = None,
924
+ output_attentions: Optional[bool] = None,
925
+ output_hidden_states: Optional[bool] = None,
926
+ return_dict: Optional[bool] = None,
927
+ return_last_logit: Optional[bool] = False,
928
+ ):
929
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
930
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
931
+
932
+ transformer_outputs = self.transformer(
933
+ input_ids=input_ids,
934
+ position_ids=position_ids,
935
+ attention_mask=attention_mask,
936
+ past_key_values=past_key_values,
937
+ inputs_embeds=inputs_embeds,
938
+ use_cache=use_cache,
939
+ output_hidden_states=output_hidden_states,
940
+ return_dict=return_dict,
941
+ )
942
+
943
+ hidden_states = transformer_outputs[0]
944
+ if return_last_logit:
945
+ hidden_states = hidden_states[-1:]
946
+ lm_logits = self.transformer.output_layer(hidden_states)
947
+ lm_logits = lm_logits.transpose(0, 1).contiguous()
948
+
949
+ loss = None
950
+ if labels is not None:
951
+ lm_logits = lm_logits.to(torch.float32)
952
+
953
+ # Shift so that tokens < n predict n
954
+ shift_logits = lm_logits[..., :-1, :].contiguous()
955
+ shift_labels = labels[..., 1:].contiguous()
956
+ # Flatten the tokens
957
+ loss_fct = CrossEntropyLoss(ignore_index=-100)
958
+ loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
959
+
960
+ lm_logits = lm_logits.to(hidden_states.dtype)
961
+ loss = loss.to(hidden_states.dtype)
962
+
963
+ if not return_dict:
964
+ output = (lm_logits,) + transformer_outputs[1:]
965
+ return ((loss,) + output) if loss is not None else output
966
+
967
+ return CausalLMOutputWithPast(
968
+ loss=loss,
969
+ logits=lm_logits,
970
+ past_key_values=transformer_outputs.past_key_values,
971
+ hidden_states=transformer_outputs.hidden_states,
972
+ attentions=transformer_outputs.attentions,
973
+ )
974
+
975
+ @staticmethod
976
+ def _reorder_cache(
977
+ past: Tuple[Tuple[torch.Tensor, torch.Tensor], ...], beam_idx: torch.LongTensor
978
+ ) -> Tuple[Tuple[torch.Tensor, torch.Tensor], ...]:
979
+ """
980
+ This function is used to re-order the `past_key_values` cache if [`~PreTrainedModel.beam_search`] or
981
+ [`~PreTrainedModel.beam_sample`] is called. This is required to match `past_key_values` with the correct
982
+ beam_idx at every generation step.
983
+
984
+ Output shares the same memory storage as `past`.
985
+ """
986
+ return tuple(
987
+ (
988
+ layer_past[0].index_select(1, beam_idx.to(layer_past[0].device)),
989
+ layer_past[1].index_select(1, beam_idx.to(layer_past[1].device)),
990
+ )
991
+ for layer_past in past
992
+ )
993
+
994
+ def process_response(self, response):
995
+ response = response.strip()
996
+ response = response.replace("[[训练时间]]", "2023年")
997
+ return response
998
+
999
+ def build_inputs(self, tokenizer, query: str, history: List[Tuple[str, str]] = None):
1000
+ prompt = tokenizer.build_prompt(query, history=history)
1001
+ inputs = tokenizer([prompt], return_tensors="pt")
1002
+ inputs = inputs.to(self.device)
1003
+ return inputs
1004
+
1005
+ def build_stream_inputs(self, tokenizer, query: str, history: List[Tuple[str, str]] = None):
1006
+ if history:
1007
+ prompt = "\n\n[Round {}]\n\n问:{}\n\n答:".format(len(history) + 1, query)
1008
+ input_ids = tokenizer.encode(prompt, add_special_tokens=False)
1009
+ input_ids = input_ids[1:]
1010
+ inputs = tokenizer.batch_encode_plus([(input_ids, None)], return_tensors="pt", add_special_tokens=False)
1011
+ else:
1012
+ prompt = "[Round {}]\n\n问:{}\n\n答:".format(len(history) + 1, query)
1013
+ inputs = tokenizer([prompt], return_tensors="pt")
1014
+ inputs = inputs.to(self.device)
1015
+ return inputs
1016
+
1017
+ @torch.inference_mode()
1018
+ def chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 8192, num_beams=1,
1019
+ do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, **kwargs):
1020
+ if history is None:
1021
+ history = []
1022
+ if logits_processor is None:
1023
+ logits_processor = LogitsProcessorList()
1024
+ logits_processor.append(InvalidScoreLogitsProcessor())
1025
+ gen_kwargs = {"max_length": max_length, "num_beams": num_beams, "do_sample": do_sample, "top_p": top_p,
1026
+ "temperature": temperature, "logits_processor": logits_processor, **kwargs}
1027
+ inputs = self.build_inputs(tokenizer, query, history=history)
1028
+ outputs = self.generate(**inputs, **gen_kwargs)
1029
+ outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):]
1030
+ response = tokenizer.decode(outputs)
1031
+ response = self.process_response(response)
1032
+ history = history + [(query, response)]
1033
+ return response, history
1034
+
1035
+ @torch.inference_mode()
1036
+ def stream_chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, past_key_values=None,
1037
+ max_length: int = 8192, do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None,
1038
+ return_past_key_values=False, **kwargs):
1039
+ if history is None:
1040
+ history = []
1041
+ if logits_processor is None:
1042
+ logits_processor = LogitsProcessorList()
1043
+ logits_processor.append(InvalidScoreLogitsProcessor())
1044
+ gen_kwargs = {"max_length": max_length, "do_sample": do_sample, "top_p": top_p,
1045
+ "temperature": temperature, "logits_processor": logits_processor, **kwargs}
1046
+ if past_key_values is None and not return_past_key_values:
1047
+ inputs = self.build_inputs(tokenizer, query, history=history)
1048
+ else:
1049
+ inputs = self.build_stream_inputs(tokenizer, query, history=history)
1050
+ if past_key_values is not None:
1051
+ past_length = past_key_values[0][0].shape[0]
1052
+ if self.transformer.pre_seq_len is not None:
1053
+ past_length -= self.transformer.pre_seq_len
1054
+ inputs.position_ids += past_length
1055
+ attention_mask = inputs.attention_mask
1056
+ attention_mask = torch.cat((attention_mask.new_ones(1, past_length), attention_mask), dim=1)
1057
+ inputs['attention_mask'] = attention_mask
1058
+ for outputs in self.stream_generate(**inputs, past_key_values=past_key_values,
1059
+ return_past_key_values=return_past_key_values, **gen_kwargs):
1060
+ if return_past_key_values:
1061
+ outputs, past_key_values = outputs
1062
+ outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):]
1063
+ response = tokenizer.decode(outputs)
1064
+ if response and response[-1] != "�":
1065
+ response = self.process_response(response)
1066
+ new_history = history + [(query, response)]
1067
+ if return_past_key_values:
1068
+ yield response, new_history, past_key_values
1069
+ else:
1070
+ yield response, new_history
1071
+
1072
+ @torch.inference_mode()
1073
+ def stream_generate(
1074
+ self,
1075
+ input_ids,
1076
+ generation_config: Optional[GenerationConfig] = None,
1077
+ logits_processor: Optional[LogitsProcessorList] = None,
1078
+ stopping_criteria: Optional[StoppingCriteriaList] = None,
1079
+ prefix_allowed_tokens_fn: Optional[Callable[[int, torch.Tensor], List[int]]] = None,
1080
+ return_past_key_values=False,
1081
+ **kwargs,
1082
+ ):
1083
+ batch_size, input_ids_seq_length = input_ids.shape[0], input_ids.shape[-1]
1084
+
1085
+ if generation_config is None:
1086
+ generation_config = self.generation_config
1087
+ generation_config = copy.deepcopy(generation_config)
1088
+ model_kwargs = generation_config.update(**kwargs)
1089
+ bos_token_id, eos_token_id = generation_config.bos_token_id, generation_config.eos_token_id
1090
+
1091
+ if isinstance(eos_token_id, int):
1092
+ eos_token_id = [eos_token_id]
1093
+
1094
+ has_default_max_length = kwargs.get("max_length") is None and generation_config.max_length is not None
1095
+ if has_default_max_length and generation_config.max_new_tokens is None:
1096
+ warnings.warn(
1097
+ f"Using `max_length`'s default ({generation_config.max_length}) to control the generation length. "
1098
+ "This behaviour is deprecated and will be removed from the config in v5 of Transformers -- we"
1099
+ " recommend using `max_new_tokens` to control the maximum length of the generation.",
1100
+ UserWarning,
1101
+ )
1102
+ elif generation_config.max_new_tokens is not None:
1103
+ generation_config.max_length = generation_config.max_new_tokens + input_ids_seq_length
1104
+ if not has_default_max_length:
1105
+ logger.warn(
1106
+ f"Both `max_new_tokens` (={generation_config.max_new_tokens}) and `max_length`(="
1107
+ f"{generation_config.max_length}) seem to have been set. `max_new_tokens` will take precedence. "
1108
+ "Please refer to the documentation for more information. "
1109
+ "(https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)",
1110
+ UserWarning,
1111
+ )
1112
+
1113
+ if input_ids_seq_length >= generation_config.max_length:
1114
+ input_ids_string = "decoder_input_ids" if self.config.is_encoder_decoder else "input_ids"
1115
+ logger.warning(
1116
+ f"Input length of {input_ids_string} is {input_ids_seq_length}, but `max_length` is set to"
1117
+ f" {generation_config.max_length}. This can lead to unexpected behavior. You should consider"
1118
+ " increasing `max_new_tokens`."
1119
+ )
1120
+
1121
+ # 2. Set generation parameters if not already defined
1122
+ logits_processor = logits_processor if logits_processor is not None else LogitsProcessorList()
1123
+ stopping_criteria = stopping_criteria if stopping_criteria is not None else StoppingCriteriaList()
1124
+
1125
+ logits_processor = self._get_logits_processor(
1126
+ generation_config=generation_config,
1127
+ input_ids_seq_length=input_ids_seq_length,
1128
+ encoder_input_ids=input_ids,
1129
+ prefix_allowed_tokens_fn=prefix_allowed_tokens_fn,
1130
+ logits_processor=logits_processor,
1131
+ )
1132
+
1133
+ stopping_criteria = self._get_stopping_criteria(
1134
+ generation_config=generation_config, stopping_criteria=stopping_criteria
1135
+ )
1136
+ logits_warper = self._get_logits_warper(generation_config)
1137
+
1138
+ unfinished_sequences = input_ids.new(input_ids.shape[0]).fill_(1)
1139
+ scores = None
1140
+ while True:
1141
+ model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)
1142
+ # forward pass to get next token
1143
+ outputs = self(
1144
+ **model_inputs,
1145
+ return_dict=True,
1146
+ output_attentions=False,
1147
+ output_hidden_states=False,
1148
+ )
1149
+
1150
+ next_token_logits = outputs.logits[:, -1, :]
1151
+
1152
+ # pre-process distribution
1153
+ next_token_scores = logits_processor(input_ids, next_token_logits)
1154
+ next_token_scores = logits_warper(input_ids, next_token_scores)
1155
+
1156
+ # sample
1157
+ probs = nn.functional.softmax(next_token_scores, dim=-1)
1158
+ if generation_config.do_sample:
1159
+ next_tokens = torch.multinomial(probs, num_samples=1).squeeze(1)
1160
+ else:
1161
+ next_tokens = torch.argmax(probs, dim=-1)
1162
+
1163
+ # update generated ids, model inputs, and length for next step
1164
+ input_ids = torch.cat([input_ids, next_tokens[:, None]], dim=-1)
1165
+ model_kwargs = self._update_model_kwargs_for_generation(
1166
+ outputs, model_kwargs, is_encoder_decoder=self.config.is_encoder_decoder
1167
+ )
1168
+ unfinished_sequences = unfinished_sequences.mul((sum(next_tokens != i for i in eos_token_id)).long())
1169
+ if return_past_key_values:
1170
+ yield input_ids, outputs.past_key_values
1171
+ else:
1172
+ yield input_ids
1173
+ # stop when each sentence is finished, or if we exceed the maximum length
1174
+ if unfinished_sequences.max() == 0 or stopping_criteria(input_ids, scores):
1175
+ break
1176
+
1177
+ def quantize(self, bits: int, empty_init=False, device=None, **kwargs):
1178
+ if bits == 0:
1179
+ return
1180
+
1181
+ from .quantization import quantize
1182
+
1183
+ if self.quantized:
1184
+ logger.info("Already quantized.")
1185
+ return self
1186
+
1187
+ self.quantized = True
1188
+
1189
+ self.config.quantization_bit = bits
1190
+
1191
+ self.transformer.encoder = quantize(self.transformer.encoder, bits, empty_init=empty_init, device=device,
1192
+ **kwargs)
1193
+ return self
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74a45040fc7c76dbf4a2aba24d53c8ae667865a904194fa3be53def9fb8625cf
3
+ size 14681391
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f512f1a2ef39d0cbf8f39386c7f3594b93decc021c74106174d13f5d99a29c0
3
+ size 7340861
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/quantization.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from torch.nn import Linear
2
+ from torch.nn.parameter import Parameter
3
+
4
+ import bz2
5
+ import torch
6
+ import base64
7
+ import ctypes
8
+ from transformers.utils import logging
9
+
10
+ from typing import List
11
+ from functools import partial
12
+
13
+ logger = logging.get_logger(__name__)
14
+
15
+ try:
16
+ from cpm_kernels.kernels.base import LazyKernelCModule, KernelFunction, round_up
17
+
18
+ class Kernel:
19
+ def __init__(self, code: bytes, function_names: List[str]):
20
+ self.code = code
21
+ self._function_names = function_names
22
+ self._cmodule = LazyKernelCModule(self.code)
23
+
24
+ for name in self._function_names:
25
+ setattr(self, name, KernelFunction(self._cmodule, name))
26
+
27
+ quantization_code = "$QlpoOTFBWSZTWU9yuJUAQHN//////////f/n/8/n///n//bt4dTidcVx8X3V9FV/92/v4B7/AD5FBQFAAAChSgKpFCFAFVSigUAAAEKhSgUUqgFBKigqVREQAABQBQIANDTTIGI00BkZBkNGE0A0BkBkGQGRkaNAaAGQNBoGgDIAAYIGTI0DQAQAaGmmQMRpoDIyDIaMJoBoDIDIMgMjI0aA0AMgaDQNAGQAAwQMmRoGgAgA0NNMgYjTQGRkGQ0YTQDQGQGQZAZGRo0BoAZA0GgaAMgABggZMjQNABABoaaZAxGmgMjIMhowmgGgMgMgyAyMjRoDQAyBoNA0AZAADBAyZGgaAAmqU1NEgJqnptU/Sn4jRR6J6epk2pqb1Q/SgAPUGgyNNGjQ2SBpoAZAAGg0NB6mgDIAAAAA2oaApSREBNAARhGiYEaEwU8pvImlP0k2aam1GaGqbFNM1MHpTwmkepmyU9R6nqPKekHqNNPUxNGhp6n6p6QaZ6o9TG1GMqcoV9ly6nRanHlq6zPNbnGZNi6HSug+2nPiZ13XcnFYZW+45W11CumhzYhchOJ2GLLV1OBjBjGf4TptOddTSOcVxhqYZMYwZXZZY00zI1paX5X9J+b+f4e+x43RXSxXPOdquiGpduatGyXneN696M9t4HU2eR5XX/kPhP261NTx3JO1Ow7LyuDmeo9a7d351T1ZxnvnrvYnrXv/hXxPCeuYx2XsNmO003eg9J3Z6U7b23meJ4ri01OdzTk9BNO96brz+qT5nuvvH3ds/G+m/JcG/F2XYuhXlvO+jP7U3XgrzPN/lr8Sf1n6j4j7jZs+s/T0tNaNNYzTs12rxjwztHlnire3Nzc3N1wuBwOBwXBvZfoHpD7rFmR99V5vj3aXza3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32
+ "int4WeightCompression",
33
+ "int4WeightExtractionFloat",
34
+ "int4WeightExtractionHalf",
35
+ "int8WeightExtractionFloat",
36
+ "int8WeightExtractionHalf",
37
+ ],
38
+ )
39
+ except Exception as exception:
40
+ kernels = None
41
+ logger.warning("Failed to load cpm_kernels:" + str(exception))
42
+
43
+
44
+ class W8A16Linear(torch.autograd.Function):
45
+ @staticmethod
46
+ def forward(ctx, inp: torch.Tensor, quant_w: torch.Tensor, scale_w: torch.Tensor, weight_bit_width):
47
+ ctx.inp_shape = inp.size()
48
+ ctx.weight_bit_width = weight_bit_width
49
+ out_features = quant_w.size(0)
50
+ inp = inp.contiguous().view(-1, inp.size(-1))
51
+ weight = extract_weight_to_half(quant_w, scale_w, weight_bit_width)
52
+ ctx.weight_shape = weight.size()
53
+ output = inp.mm(weight.t())
54
+ ctx.save_for_backward(inp, quant_w, scale_w)
55
+ return output.view(*(ctx.inp_shape[:-1] + (out_features,)))
56
+
57
+ @staticmethod
58
+ def backward(ctx, grad_output: torch.Tensor):
59
+ inp, quant_w, scale_w = ctx.saved_tensors
60
+ weight = extract_weight_to_half(quant_w, scale_w, ctx.weight_bit_width)
61
+ grad_output = grad_output.contiguous().view(-1, weight.size(0))
62
+ grad_input = grad_output.mm(weight)
63
+ grad_weight = grad_output.t().mm(inp)
64
+ return grad_input.view(ctx.inp_shape), grad_weight.view(ctx.weight_shape), None, None
65
+
66
+
67
+ def compress_int4_weight(weight: torch.Tensor): # (n, m)
68
+ with torch.cuda.device(weight.device):
69
+ n, m = weight.size(0), weight.size(1)
70
+ assert m % 2 == 0
71
+ m = m // 2
72
+ out = torch.empty(n, m, dtype=torch.int8, device="cuda")
73
+ stream = torch.cuda.current_stream()
74
+
75
+ gridDim = (n, 1, 1)
76
+ blockDim = (min(round_up(m, 32), 1024), 1, 1)
77
+
78
+ kernels.int4WeightCompression(
79
+ gridDim,
80
+ blockDim,
81
+ 0,
82
+ stream,
83
+ [ctypes.c_void_p(weight.data_ptr()), ctypes.c_void_p(out.data_ptr()), ctypes.c_int32(n), ctypes.c_int32(m)],
84
+ )
85
+ return out
86
+
87
+
88
+ def extract_weight_to_half(weight: torch.Tensor, scale_list: torch.Tensor, source_bit_width: int):
89
+ assert scale_list.dtype in [torch.half, torch.bfloat16]
90
+ assert weight.dtype in [torch.int8]
91
+ if source_bit_width == 8:
92
+ return weight.to(scale_list.dtype) * scale_list[:, None]
93
+ elif source_bit_width == 4:
94
+ func = (
95
+ kernels.int4WeightExtractionHalf if scale_list.dtype == torch.half else kernels.int4WeightExtractionBFloat16
96
+ )
97
+ else:
98
+ assert False, "Unsupported bit-width"
99
+
100
+ with torch.cuda.device(weight.device):
101
+ n, m = weight.size(0), weight.size(1)
102
+ out = torch.empty(n, m * (8 // source_bit_width), dtype=scale_list.dtype, device="cuda")
103
+ stream = torch.cuda.current_stream()
104
+
105
+ gridDim = (n, 1, 1)
106
+ blockDim = (min(round_up(m, 32), 1024), 1, 1)
107
+
108
+ func(
109
+ gridDim,
110
+ blockDim,
111
+ 0,
112
+ stream,
113
+ [
114
+ ctypes.c_void_p(weight.data_ptr()),
115
+ ctypes.c_void_p(scale_list.data_ptr()),
116
+ ctypes.c_void_p(out.data_ptr()),
117
+ ctypes.c_int32(n),
118
+ ctypes.c_int32(m),
119
+ ],
120
+ )
121
+ return out
122
+
123
+
124
+ class QuantizedLinear(torch.nn.Module):
125
+ def __init__(self, weight_bit_width: int, weight, bias=None, device="cpu", dtype=None, empty_init=False, *args,
126
+ **kwargs):
127
+ super().__init__()
128
+ self.weight_bit_width = weight_bit_width
129
+
130
+ shape = weight.shape
131
+
132
+ if weight is None or empty_init:
133
+ self.weight = torch.empty(shape[0], shape[1] * weight_bit_width // 8, dtype=torch.int8, device=device)
134
+ self.weight_scale = torch.empty(shape[0], dtype=dtype, device=device)
135
+ else:
136
+ self.weight_scale = weight.abs().max(dim=-1).values / ((2 ** (weight_bit_width - 1)) - 1)
137
+ self.weight = torch.round(weight / self.weight_scale[:, None]).to(torch.int8)
138
+ if weight_bit_width == 4:
139
+ self.weight = compress_int4_weight(self.weight)
140
+
141
+ self.weight = Parameter(self.weight.to(device), requires_grad=False)
142
+ self.weight_scale = Parameter(self.weight_scale.to(device), requires_grad=False)
143
+ self.bias = Parameter(bias.to(device), requires_grad=False) if bias is not None else None
144
+
145
+ def forward(self, input):
146
+ output = W8A16Linear.apply(input, self.weight, self.weight_scale, self.weight_bit_width)
147
+ if self.bias is not None:
148
+ output = output + self.bias
149
+ return output
150
+
151
+
152
+ def quantize(model, weight_bit_width, empty_init=False, device=None):
153
+ """Replace fp16 linear with quantized linear"""
154
+ for layer in model.layers:
155
+ layer.self_attention.query_key_value = QuantizedLinear(
156
+ weight_bit_width=weight_bit_width,
157
+ weight=layer.self_attention.query_key_value.weight.to(torch.cuda.current_device()),
158
+ bias=layer.self_attention.query_key_value.bias,
159
+ dtype=layer.self_attention.query_key_value.weight.dtype,
160
+ device=layer.self_attention.query_key_value.weight.device if device is None else device,
161
+ empty_init=empty_init
162
+ )
163
+ layer.self_attention.dense = QuantizedLinear(
164
+ weight_bit_width=weight_bit_width,
165
+ weight=layer.self_attention.dense.weight.to(torch.cuda.current_device()),
166
+ bias=layer.self_attention.dense.bias,
167
+ dtype=layer.self_attention.dense.weight.dtype,
168
+ device=layer.self_attention.dense.weight.device if device is None else device,
169
+ empty_init=empty_init
170
+ )
171
+ layer.mlp.dense_h_to_4h = QuantizedLinear(
172
+ weight_bit_width=weight_bit_width,
173
+ weight=layer.mlp.dense_h_to_4h.weight.to(torch.cuda.current_device()),
174
+ bias=layer.mlp.dense_h_to_4h.bias,
175
+ dtype=layer.mlp.dense_h_to_4h.weight.dtype,
176
+ device=layer.mlp.dense_h_to_4h.weight.device if device is None else device,
177
+ empty_init=empty_init
178
+ )
179
+ layer.mlp.dense_4h_to_h = QuantizedLinear(
180
+ weight_bit_width=weight_bit_width,
181
+ weight=layer.mlp.dense_4h_to_h.weight.to(torch.cuda.current_device()),
182
+ bias=layer.mlp.dense_4h_to_h.bias,
183
+ dtype=layer.mlp.dense_4h_to_h.weight.dtype,
184
+ device=layer.mlp.dense_4h_to_h.weight.device if device is None else device,
185
+ empty_init=empty_init
186
+ )
187
+
188
+ return model
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c01a404b3d199706c595e3e7a05a01448ef608a179cd507bad120ea058b0dddc
3
+ size 14575
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2181151705bc21abd4b28f2057fc0eb4770b8b2410347d913d2ae5fb451e29d
3
+ size 627
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {}
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/tokenization_chatglm.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ from typing import List, Optional, Union, Dict
4
+ from sentencepiece import SentencePieceProcessor
5
+ from transformers import PreTrainedTokenizer
6
+ from transformers.utils import logging, PaddingStrategy
7
+ from transformers.tokenization_utils_base import EncodedInput, BatchEncoding
8
+
9
+
10
+ class SPTokenizer:
11
+ def __init__(self, model_path: str):
12
+ # reload tokenizer
13
+ assert os.path.isfile(model_path), model_path
14
+ self.sp_model = SentencePieceProcessor(model_file=model_path)
15
+
16
+ # BOS / EOS token IDs
17
+ self.n_words: int = self.sp_model.vocab_size()
18
+ self.bos_id: int = self.sp_model.bos_id()
19
+ self.eos_id: int = self.sp_model.eos_id()
20
+ self.pad_id: int = self.sp_model.unk_id()
21
+ assert self.sp_model.vocab_size() == self.sp_model.get_piece_size()
22
+
23
+ special_tokens = ["[MASK]", "[gMASK]", "[sMASK]", "sop", "eop"]
24
+ self.special_tokens = {}
25
+ self.index_special_tokens = {}
26
+ for token in special_tokens:
27
+ self.special_tokens[token] = self.n_words
28
+ self.index_special_tokens[self.n_words] = token
29
+ self.n_words += 1
30
+
31
+ def tokenize(self, s: str):
32
+ return self.sp_model.EncodeAsPieces(s)
33
+
34
+ def encode(self, s: str, bos: bool = False, eos: bool = False) -> List[int]:
35
+ assert type(s) is str
36
+ t = self.sp_model.encode(s)
37
+ if bos:
38
+ t = [self.bos_id] + t
39
+ if eos:
40
+ t = t + [self.eos_id]
41
+ return t
42
+
43
+ def decode(self, t: List[int]) -> str:
44
+ return self.sp_model.decode(t)
45
+
46
+ def decode_tokens(self, tokens: List[str]) -> str:
47
+ text = self.sp_model.DecodePieces(tokens)
48
+ return text
49
+
50
+ def convert_token_to_id(self, token):
51
+ """ Converts a token (str) in an id using the vocab. """
52
+ if token in self.special_tokens:
53
+ return self.special_tokens[token]
54
+ return self.sp_model.PieceToId(token)
55
+
56
+ def convert_id_to_token(self, index):
57
+ """Converts an index (integer) in a token (str) using the vocab."""
58
+ if index in self.index_special_tokens or index in [self.eos_id, self.bos_id, self.pad_id] or index < 0:
59
+ return ""
60
+ return self.sp_model.IdToPiece(index)
61
+
62
+
63
+ class ChatGLMTokenizer(PreTrainedTokenizer):
64
+ vocab_files_names = {"vocab_file": "tokenizer.model"}
65
+
66
+ model_input_names = ["input_ids", "attention_mask", "position_ids"]
67
+
68
+ def __init__(self, vocab_file, padding_side="left", clean_up_tokenization_spaces=False, **kwargs):
69
+ super().__init__(padding_side=padding_side, clean_up_tokenization_spaces=clean_up_tokenization_spaces, **kwargs)
70
+ self.name = "GLMTokenizer"
71
+
72
+ self.vocab_file = vocab_file
73
+ self.tokenizer = SPTokenizer(vocab_file)
74
+ self.special_tokens = {
75
+ "<bos>": self.tokenizer.bos_id,
76
+ "<eos>": self.tokenizer.eos_id,
77
+ "<pad>": self.tokenizer.pad_id
78
+ }
79
+
80
+ def get_command(self, token):
81
+ if token in self.special_tokens:
82
+ return self.special_tokens[token]
83
+ assert token in self.tokenizer.special_tokens, f"{token} is not a special token for {self.name}"
84
+ return self.tokenizer.special_tokens[token]
85
+
86
+ @property
87
+ def unk_token(self) -> str:
88
+ return "<unk>"
89
+
90
+ @property
91
+ def pad_token(self) -> str:
92
+ return "<unk>"
93
+
94
+ @property
95
+ def pad_token_id(self):
96
+ return self.get_command("<pad>")
97
+
98
+ @property
99
+ def eos_token(self) -> str:
100
+ return "</s>"
101
+
102
+ @property
103
+ def eos_token_id(self):
104
+ return self.get_command("<eos>")
105
+
106
+ @property
107
+ def vocab_size(self):
108
+ return self.tokenizer.n_words
109
+
110
+ def get_vocab(self):
111
+ """ Returns vocab as a dict """
112
+ vocab = {self._convert_id_to_token(i): i for i in range(self.vocab_size)}
113
+ vocab.update(self.added_tokens_encoder)
114
+ return vocab
115
+
116
+ def _tokenize(self, text, **kwargs):
117
+ return self.tokenizer.tokenize(text)
118
+
119
+ def _convert_token_to_id(self, token):
120
+ """ Converts a token (str) in an id using the vocab. """
121
+ return self.tokenizer.convert_token_to_id(token)
122
+
123
+ def _convert_id_to_token(self, index):
124
+ """Converts an index (integer) in a token (str) using the vocab."""
125
+ return self.tokenizer.convert_id_to_token(index)
126
+
127
+ def convert_tokens_to_string(self, tokens: List[str]) -> str:
128
+ return self.tokenizer.decode_tokens(tokens)
129
+
130
+ def save_vocabulary(self, save_directory, filename_prefix=None):
131
+ """
132
+ Save the vocabulary and special tokens file to a directory.
133
+
134
+ Args:
135
+ save_directory (`str`):
136
+ The directory in which to save the vocabulary.
137
+ filename_prefix (`str`, *optional*):
138
+ An optional prefix to add to the named of the saved files.
139
+
140
+ Returns:
141
+ `Tuple(str)`: Paths to the files saved.
142
+ """
143
+ if os.path.isdir(save_directory):
144
+ vocab_file = os.path.join(
145
+ save_directory, self.vocab_files_names["vocab_file"]
146
+ )
147
+ else:
148
+ vocab_file = save_directory
149
+
150
+ with open(self.vocab_file, 'rb') as fin:
151
+ proto_str = fin.read()
152
+
153
+ with open(vocab_file, "wb") as writer:
154
+ writer.write(proto_str)
155
+
156
+ return (vocab_file,)
157
+
158
+ def get_prefix_tokens(self):
159
+ prefix_tokens = [self.get_command("[gMASK]"), self.get_command("sop")]
160
+ return prefix_tokens
161
+
162
+ def build_prompt(self, query, history=None):
163
+ if history is None:
164
+ history = []
165
+ prompt = ""
166
+ for i, (old_query, response) in enumerate(history):
167
+ prompt += "[Round {}]\n\n问:{}\n\n答:{}\n\n".format(i + 1, old_query, response)
168
+ prompt += "[Round {}]\n\n问:{}\n\n答:".format(len(history) + 1, query)
169
+ return prompt
170
+
171
+ def build_inputs_with_special_tokens(
172
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
173
+ ) -> List[int]:
174
+ """
175
+ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
176
+ adding special tokens. A BERT sequence has the following format:
177
+
178
+ - single sequence: `[CLS] X [SEP]`
179
+ - pair of sequences: `[CLS] A [SEP] B [SEP]`
180
+
181
+ Args:
182
+ token_ids_0 (`List[int]`):
183
+ List of IDs to which the special tokens will be added.
184
+ token_ids_1 (`List[int]`, *optional*):
185
+ Optional second list of IDs for sequence pairs.
186
+
187
+ Returns:
188
+ `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
189
+ """
190
+ prefix_tokens = self.get_prefix_tokens()
191
+ token_ids_0 = prefix_tokens + token_ids_0
192
+ if token_ids_1 is not None:
193
+ token_ids_0 = token_ids_0 + token_ids_1 + [self.get_command("<eos>")]
194
+ return token_ids_0
195
+
196
+ def _pad(
197
+ self,
198
+ encoded_inputs: Union[Dict[str, EncodedInput], BatchEncoding],
199
+ max_length: Optional[int] = None,
200
+ padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
201
+ pad_to_multiple_of: Optional[int] = None,
202
+ return_attention_mask: Optional[bool] = None,
203
+ ) -> dict:
204
+ """
205
+ Pad encoded inputs (on left/right and up to predefined length or max length in the batch)
206
+
207
+ Args:
208
+ encoded_inputs:
209
+ Dictionary of tokenized inputs (`List[int]`) or batch of tokenized inputs (`List[List[int]]`).
210
+ max_length: maximum length of the returned list and optionally padding length (see below).
211
+ Will truncate by taking into account the special tokens.
212
+ padding_strategy: PaddingStrategy to use for padding.
213
+
214
+ - PaddingStrategy.LONGEST Pad to the longest sequence in the batch
215
+ - PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
216
+ - PaddingStrategy.DO_NOT_PAD: Do not pad
217
+ The tokenizer padding sides are defined in self.padding_side:
218
+
219
+ - 'left': pads on the left of the sequences
220
+ - 'right': pads on the right of the sequences
221
+ pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
222
+ This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
223
+ `>= 7.5` (Volta).
224
+ return_attention_mask:
225
+ (optional) Set to False to avoid returning attention mask (default: set to model specifics)
226
+ """
227
+ # Load from model defaults
228
+ assert self.padding_side == "left"
229
+
230
+ required_input = encoded_inputs[self.model_input_names[0]]
231
+ seq_length = len(required_input)
232
+
233
+ if padding_strategy == PaddingStrategy.LONGEST:
234
+ max_length = len(required_input)
235
+
236
+ if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
237
+ max_length = ((max_length // pad_to_multiple_of) + 1) * pad_to_multiple_of
238
+
239
+ needs_to_be_padded = padding_strategy != PaddingStrategy.DO_NOT_PAD and len(required_input) != max_length
240
+
241
+ # Initialize attention mask if not present.
242
+ if "attention_mask" not in encoded_inputs:
243
+ encoded_inputs["attention_mask"] = [1] * seq_length
244
+
245
+ if "position_ids" not in encoded_inputs:
246
+ encoded_inputs["position_ids"] = list(range(seq_length))
247
+
248
+ if needs_to_be_padded:
249
+ difference = max_length - len(required_input)
250
+
251
+ if "attention_mask" in encoded_inputs:
252
+ encoded_inputs["attention_mask"] = [0] * difference + encoded_inputs["attention_mask"]
253
+ if "position_ids" in encoded_inputs:
254
+ encoded_inputs["position_ids"] = [0] * difference + encoded_inputs["position_ids"]
255
+ encoded_inputs[self.model_input_names[0]] = [self.pad_token_id] * difference + required_input
256
+
257
+ return encoded_inputs
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7dc4c393423b76e4373e5157ddc34803a0189ba96b21ddbb40269d31468a6f2
3
+ size 1018370
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoTokenizer": [
4
+ "tokenization_chatglm.ChatGLMTokenizer",
5
+ null
6
+ ]
7
+ },
8
+ "clean_up_tokenization_spaces": false,
9
+ "do_lower_case": false,
10
+ "model_max_length": 1000000000000000019884624838656,
11
+ "padding_side": "left",
12
+ "remove_space": false,
13
+ "special_tokens_map_file": null,
14
+ "tokenizer_class": "ChatGLMTokeniz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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 8.916132627472834,
5
+ "global_step": 2000,
6
+ "is_hyper_param_search": false,
7
+ "is_local_process_zero": true,
8
+ "is_world_process_zero": true,
9
+ "log_history": [
10
+ {
11
+ "epoch": 0.04,
12
+ "learning_rate": 0.019933333333333334,
13
+ "loss": 1.811,
14
+ "step": 10
15
+ },
16
+ {
17
+ "epoch": 0.09,
18
+ "learning_rate": 0.019866666666666668,
19
+ "loss": 1.2846,
20
+ "step": 20
21
+ },
22
+ {
23
+ "epoch": 0.13,
24
+ "learning_rate": 0.0198,
25
+ "loss": 1.1671,
26
+ "step": 30
27
+ },
28
+ {
29
+ "epoch": 0.18,
30
+ "learning_rate": 0.019733333333333335,
31
+ "loss": 0.9238,
32
+ "step": 40
33
+ },
34
+ {
35
+ "epoch": 0.22,
36
+ "learning_rate": 0.019666666666666666,
37
+ "loss": 0.832,
38
+ "step": 50
39
+ },
40
+ {
41
+ "epoch": 0.27,
42
+ "learning_rate": 0.0196,
43
+ "loss": 0.7667,
44
+ "step": 60
45
+ },
46
+ {
47
+ "epoch": 0.31,
48
+ "learning_rate": 0.019533333333333333,
49
+ "loss": 0.5746,
50
+ "step": 70
51
+ },
52
+ {
53
+ "epoch": 0.36,
54
+ "learning_rate": 0.019466666666666667,
55
+ "loss": 0.6013,
56
+ "step": 80
57
+ },
58
+ {
59
+ "epoch": 0.4,
60
+ "learning_rate": 0.0194,
61
+ "loss": 0.622,
62
+ "step": 90
63
+ },
64
+ {
65
+ "epoch": 0.45,
66
+ "learning_rate": 0.019333333333333334,
67
+ "loss": 0.5471,
68
+ "step": 100
69
+ },
70
+ {
71
+ "epoch": 0.49,
72
+ "learning_rate": 0.019266666666666668,
73
+ "loss": 0.5042,
74
+ "step": 110
75
+ },
76
+ {
77
+ "epoch": 0.53,
78
+ "learning_rate": 0.0192,
79
+ "loss": 0.48,
80
+ "step": 120
81
+ },
82
+ {
83
+ "epoch": 0.58,
84
+ "learning_rate": 0.019133333333333332,
85
+ "loss": 0.4302,
86
+ "step": 130
87
+ },
88
+ {
89
+ "epoch": 0.62,
90
+ "learning_rate": 0.01906666666666667,
91
+ "loss": 0.4385,
92
+ "step": 140
93
+ },
94
+ {
95
+ "epoch": 0.67,
96
+ "learning_rate": 0.019,
97
+ "loss": 0.4081,
98
+ "step": 150
99
+ },
100
+ {
101
+ "epoch": 0.71,
102
+ "learning_rate": 0.018933333333333333,
103
+ "loss": 0.3896,
104
+ "step": 160
105
+ },
106
+ {
107
+ "epoch": 0.76,
108
+ "learning_rate": 0.018866666666666667,
109
+ "loss": 0.4021,
110
+ "step": 170
111
+ },
112
+ {
113
+ "epoch": 0.8,
114
+ "learning_rate": 0.0188,
115
+ "loss": 0.3946,
116
+ "step": 180
117
+ },
118
+ {
119
+ "epoch": 0.85,
120
+ "learning_rate": 0.018733333333333334,
121
+ "loss": 0.4153,
122
+ "step": 190
123
+ },
124
+ {
125
+ "epoch": 0.89,
126
+ "learning_rate": 0.018666666666666668,
127
+ "loss": 0.3587,
128
+ "step": 200
129
+ },
130
+ {
131
+ "epoch": 0.94,
132
+ "learning_rate": 0.018600000000000002,
133
+ "loss": 0.3735,
134
+ "step": 210
135
+ },
136
+ {
137
+ "epoch": 0.98,
138
+ "learning_rate": 0.018533333333333332,
139
+ "loss": 0.3399,
140
+ "step": 220
141
+ },
142
+ {
143
+ "epoch": 1.03,
144
+ "learning_rate": 0.018466666666666666,
145
+ "loss": 0.3416,
146
+ "step": 230
147
+ },
148
+ {
149
+ "epoch": 1.07,
150
+ "learning_rate": 0.0184,
151
+ "loss": 0.3426,
152
+ "step": 240
153
+ },
154
+ {
155
+ "epoch": 1.11,
156
+ "learning_rate": 0.018333333333333333,
157
+ "loss": 0.3181,
158
+ "step": 250
159
+ },
160
+ {
161
+ "epoch": 1.16,
162
+ "learning_rate": 0.018266666666666667,
163
+ "loss": 0.2859,
164
+ "step": 260
165
+ },
166
+ {
167
+ "epoch": 1.2,
168
+ "learning_rate": 0.0182,
169
+ "loss": 0.3226,
170
+ "step": 270
171
+ },
172
+ {
173
+ "epoch": 1.25,
174
+ "learning_rate": 0.01813333333333333,
175
+ "loss": 0.3054,
176
+ "step": 280
177
+ },
178
+ {
179
+ "epoch": 1.29,
180
+ "learning_rate": 0.01806666666666667,
181
+ "loss": 0.302,
182
+ "step": 290
183
+ },
184
+ {
185
+ "epoch": 1.34,
186
+ "learning_rate": 0.018000000000000002,
187
+ "loss": 0.3099,
188
+ "step": 300
189
+ },
190
+ {
191
+ "epoch": 1.38,
192
+ "learning_rate": 0.017933333333333332,
193
+ "loss": 0.3026,
194
+ "step": 310
195
+ },
196
+ {
197
+ "epoch": 1.43,
198
+ "learning_rate": 0.017866666666666666,
199
+ "loss": 0.2892,
200
+ "step": 320
201
+ },
202
+ {
203
+ "epoch": 1.47,
204
+ "learning_rate": 0.0178,
205
+ "loss": 0.3006,
206
+ "step": 330
207
+ },
208
+ {
209
+ "epoch": 1.52,
210
+ "learning_rate": 0.017733333333333334,
211
+ "loss": 0.2935,
212
+ "step": 340
213
+ },
214
+ {
215
+ "epoch": 1.56,
216
+ "learning_rate": 0.017666666666666667,
217
+ "loss": 0.285,
218
+ "step": 350
219
+ },
220
+ {
221
+ "epoch": 1.6,
222
+ "learning_rate": 0.0176,
223
+ "loss": 0.2606,
224
+ "step": 360
225
+ },
226
+ {
227
+ "epoch": 1.65,
228
+ "learning_rate": 0.017533333333333335,
229
+ "loss": 0.2912,
230
+ "step": 370
231
+ },
232
+ {
233
+ "epoch": 1.69,
234
+ "learning_rate": 0.017466666666666665,
235
+ "loss": 0.2856,
236
+ "step": 380
237
+ },
238
+ {
239
+ "epoch": 1.74,
240
+ "learning_rate": 0.0174,
241
+ "loss": 0.2725,
242
+ "step": 390
243
+ },
244
+ {
245
+ "epoch": 1.78,
246
+ "learning_rate": 0.017333333333333336,
247
+ "loss": 0.2755,
248
+ "step": 400
249
+ },
250
+ {
251
+ "epoch": 1.83,
252
+ "learning_rate": 0.017266666666666666,
253
+ "loss": 0.2562,
254
+ "step": 410
255
+ },
256
+ {
257
+ "epoch": 1.87,
258
+ "learning_rate": 0.0172,
259
+ "loss": 0.2845,
260
+ "step": 420
261
+ },
262
+ {
263
+ "epoch": 1.92,
264
+ "learning_rate": 0.017133333333333334,
265
+ "loss": 0.2686,
266
+ "step": 430
267
+ },
268
+ {
269
+ "epoch": 1.96,
270
+ "learning_rate": 0.017066666666666667,
271
+ "loss": 0.2586,
272
+ "step": 440
273
+ },
274
+ {
275
+ "epoch": 2.01,
276
+ "learning_rate": 0.017,
277
+ "loss": 0.2552,
278
+ "step": 450
279
+ },
280
+ {
281
+ "epoch": 2.05,
282
+ "learning_rate": 0.016933333333333335,
283
+ "loss": 0.2529,
284
+ "step": 460
285
+ },
286
+ {
287
+ "epoch": 2.1,
288
+ "learning_rate": 0.01686666666666667,
289
+ "loss": 0.2364,
290
+ "step": 470
291
+ },
292
+ {
293
+ "epoch": 2.14,
294
+ "learning_rate": 0.0168,
295
+ "loss": 0.2541,
296
+ "step": 480
297
+ },
298
+ {
299
+ "epoch": 2.18,
300
+ "learning_rate": 0.016733333333333333,
301
+ "loss": 0.2423,
302
+ "step": 490
303
+ },
304
+ {
305
+ "epoch": 2.23,
306
+ "learning_rate": 0.016666666666666666,
307
+ "loss": 0.2336,
308
+ "step": 500
309
+ },
310
+ {
311
+ "epoch": 2.27,
312
+ "learning_rate": 0.0166,
313
+ "loss": 0.239,
314
+ "step": 510
315
+ },
316
+ {
317
+ "epoch": 2.32,
318
+ "learning_rate": 0.016533333333333334,
319
+ "loss": 0.2359,
320
+ "step": 520
321
+ },
322
+ {
323
+ "epoch": 2.36,
324
+ "learning_rate": 0.016466666666666668,
325
+ "loss": 0.2481,
326
+ "step": 530
327
+ },
328
+ {
329
+ "epoch": 2.41,
330
+ "learning_rate": 0.016399999999999998,
331
+ "loss": 0.2419,
332
+ "step": 540
333
+ },
334
+ {
335
+ "epoch": 2.45,
336
+ "learning_rate": 0.01633333333333333,
337
+ "loss": 0.2289,
338
+ "step": 550
339
+ },
340
+ {
341
+ "epoch": 2.5,
342
+ "learning_rate": 0.01626666666666667,
343
+ "loss": 0.2268,
344
+ "step": 560
345
+ },
346
+ {
347
+ "epoch": 2.54,
348
+ "learning_rate": 0.016200000000000003,
349
+ "loss": 0.2393,
350
+ "step": 570
351
+ },
352
+ {
353
+ "epoch": 2.59,
354
+ "learning_rate": 0.016133333333333333,
355
+ "loss": 0.2234,
356
+ "step": 580
357
+ },
358
+ {
359
+ "epoch": 2.63,
360
+ "learning_rate": 0.016066666666666667,
361
+ "loss": 0.2382,
362
+ "step": 590
363
+ },
364
+ {
365
+ "epoch": 2.67,
366
+ "learning_rate": 0.016,
367
+ "loss": 0.237,
368
+ "step": 600
369
+ },
370
+ {
371
+ "epoch": 2.72,
372
+ "learning_rate": 0.015933333333333334,
373
+ "loss": 0.2492,
374
+ "step": 610
375
+ },
376
+ {
377
+ "epoch": 2.76,
378
+ "learning_rate": 0.015866666666666668,
379
+ "loss": 0.2263,
380
+ "step": 620
381
+ },
382
+ {
383
+ "epoch": 2.81,
384
+ "learning_rate": 0.0158,
385
+ "loss": 0.2515,
386
+ "step": 630
387
+ },
388
+ {
389
+ "epoch": 2.85,
390
+ "learning_rate": 0.015733333333333332,
391
+ "loss": 0.2299,
392
+ "step": 640
393
+ },
394
+ {
395
+ "epoch": 2.9,
396
+ "learning_rate": 0.015666666666666666,
397
+ "loss": 0.2311,
398
+ "step": 650
399
+ },
400
+ {
401
+ "epoch": 2.94,
402
+ "learning_rate": 0.015600000000000001,
403
+ "loss": 0.2204,
404
+ "step": 660
405
+ },
406
+ {
407
+ "epoch": 2.99,
408
+ "learning_rate": 0.015533333333333333,
409
+ "loss": 0.2243,
410
+ "step": 670
411
+ },
412
+ {
413
+ "epoch": 3.03,
414
+ "learning_rate": 0.015466666666666667,
415
+ "loss": 0.2,
416
+ "step": 680
417
+ },
418
+ {
419
+ "epoch": 3.08,
420
+ "learning_rate": 0.0154,
421
+ "loss": 0.2016,
422
+ "step": 690
423
+ },
424
+ {
425
+ "epoch": 3.12,
426
+ "learning_rate": 0.015333333333333334,
427
+ "loss": 0.2251,
428
+ "step": 700
429
+ },
430
+ {
431
+ "epoch": 3.17,
432
+ "learning_rate": 0.015266666666666666,
433
+ "loss": 0.2055,
434
+ "step": 710
435
+ },
436
+ {
437
+ "epoch": 3.21,
438
+ "learning_rate": 0.0152,
439
+ "loss": 0.2205,
440
+ "step": 720
441
+ },
442
+ {
443
+ "epoch": 3.25,
444
+ "learning_rate": 0.015133333333333334,
445
+ "loss": 0.2066,
446
+ "step": 730
447
+ },
448
+ {
449
+ "epoch": 3.3,
450
+ "learning_rate": 0.015066666666666666,
451
+ "loss": 0.2174,
452
+ "step": 740
453
+ },
454
+ {
455
+ "epoch": 3.34,
456
+ "learning_rate": 0.015,
457
+ "loss": 0.2163,
458
+ "step": 750
459
+ },
460
+ {
461
+ "epoch": 3.39,
462
+ "learning_rate": 0.014933333333333335,
463
+ "loss": 0.2049,
464
+ "step": 760
465
+ },
466
+ {
467
+ "epoch": 3.43,
468
+ "learning_rate": 0.014866666666666667,
469
+ "loss": 0.2039,
470
+ "step": 770
471
+ },
472
+ {
473
+ "epoch": 3.48,
474
+ "learning_rate": 0.0148,
475
+ "loss": 0.1941,
476
+ "step": 780
477
+ },
478
+ {
479
+ "epoch": 3.52,
480
+ "learning_rate": 0.014733333333333334,
481
+ "loss": 0.2051,
482
+ "step": 790
483
+ },
484
+ {
485
+ "epoch": 3.57,
486
+ "learning_rate": 0.014666666666666666,
487
+ "loss": 0.2097,
488
+ "step": 800
489
+ },
490
+ {
491
+ "epoch": 3.61,
492
+ "learning_rate": 0.0146,
493
+ "loss": 0.2104,
494
+ "step": 810
495
+ },
496
+ {
497
+ "epoch": 3.66,
498
+ "learning_rate": 0.014533333333333334,
499
+ "loss": 0.2157,
500
+ "step": 820
501
+ },
502
+ {
503
+ "epoch": 3.7,
504
+ "learning_rate": 0.014466666666666668,
505
+ "loss": 0.2053,
506
+ "step": 830
507
+ },
508
+ {
509
+ "epoch": 3.74,
510
+ "learning_rate": 0.0144,
511
+ "loss": 0.2005,
512
+ "step": 840
513
+ },
514
+ {
515
+ "epoch": 3.79,
516
+ "learning_rate": 0.014333333333333333,
517
+ "loss": 0.2075,
518
+ "step": 850
519
+ },
520
+ {
521
+ "epoch": 3.83,
522
+ "learning_rate": 0.014266666666666667,
523
+ "loss": 0.2065,
524
+ "step": 860
525
+ },
526
+ {
527
+ "epoch": 3.88,
528
+ "learning_rate": 0.014199999999999999,
529
+ "loss": 0.2091,
530
+ "step": 870
531
+ },
532
+ {
533
+ "epoch": 3.92,
534
+ "learning_rate": 0.014133333333333333,
535
+ "loss": 0.2003,
536
+ "step": 880
537
+ },
538
+ {
539
+ "epoch": 3.97,
540
+ "learning_rate": 0.014066666666666668,
541
+ "loss": 0.2111,
542
+ "step": 890
543
+ },
544
+ {
545
+ "epoch": 4.01,
546
+ "learning_rate": 0.013999999999999999,
547
+ "loss": 0.2019,
548
+ "step": 900
549
+ },
550
+ {
551
+ "epoch": 4.06,
552
+ "learning_rate": 0.013933333333333334,
553
+ "loss": 0.1953,
554
+ "step": 910
555
+ },
556
+ {
557
+ "epoch": 4.1,
558
+ "learning_rate": 0.013866666666666668,
559
+ "loss": 0.1912,
560
+ "step": 920
561
+ },
562
+ {
563
+ "epoch": 4.15,
564
+ "learning_rate": 0.0138,
565
+ "loss": 0.1947,
566
+ "step": 930
567
+ },
568
+ {
569
+ "epoch": 4.19,
570
+ "learning_rate": 0.013733333333333334,
571
+ "loss": 0.1879,
572
+ "step": 940
573
+ },
574
+ {
575
+ "epoch": 4.24,
576
+ "learning_rate": 0.013666666666666667,
577
+ "loss": 0.1923,
578
+ "step": 950
579
+ },
580
+ {
581
+ "epoch": 4.28,
582
+ "learning_rate": 0.013600000000000001,
583
+ "loss": 0.1841,
584
+ "step": 960
585
+ },
586
+ {
587
+ "epoch": 4.32,
588
+ "learning_rate": 0.013533333333333333,
589
+ "loss": 0.1878,
590
+ "step": 970
591
+ },
592
+ {
593
+ "epoch": 4.37,
594
+ "learning_rate": 0.013466666666666667,
595
+ "loss": 0.192,
596
+ "step": 980
597
+ },
598
+ {
599
+ "epoch": 4.41,
600
+ "learning_rate": 0.0134,
601
+ "loss": 0.186,
602
+ "step": 990
603
+ },
604
+ {
605
+ "epoch": 4.46,
606
+ "learning_rate": 0.013333333333333332,
607
+ "loss": 0.1852,
608
+ "step": 1000
609
+ },
610
+ {
611
+ "epoch": 4.5,
612
+ "learning_rate": 0.013266666666666666,
613
+ "loss": 0.1861,
614
+ "step": 1010
615
+ },
616
+ {
617
+ "epoch": 4.55,
618
+ "learning_rate": 0.013200000000000002,
619
+ "loss": 0.1871,
620
+ "step": 1020
621
+ },
622
+ {
623
+ "epoch": 4.59,
624
+ "learning_rate": 0.013133333333333332,
625
+ "loss": 0.1843,
626
+ "step": 1030
627
+ },
628
+ {
629
+ "epoch": 4.64,
630
+ "learning_rate": 0.013066666666666667,
631
+ "loss": 0.1981,
632
+ "step": 1040
633
+ },
634
+ {
635
+ "epoch": 4.68,
636
+ "learning_rate": 0.013000000000000001,
637
+ "loss": 0.1956,
638
+ "step": 1050
639
+ },
640
+ {
641
+ "epoch": 4.73,
642
+ "learning_rate": 0.012933333333333333,
643
+ "loss": 0.1903,
644
+ "step": 1060
645
+ },
646
+ {
647
+ "epoch": 4.77,
648
+ "learning_rate": 0.012866666666666667,
649
+ "loss": 0.1966,
650
+ "step": 1070
651
+ },
652
+ {
653
+ "epoch": 4.81,
654
+ "learning_rate": 0.0128,
655
+ "loss": 0.1977,
656
+ "step": 1080
657
+ },
658
+ {
659
+ "epoch": 4.86,
660
+ "learning_rate": 0.012733333333333334,
661
+ "loss": 0.1907,
662
+ "step": 1090
663
+ },
664
+ {
665
+ "epoch": 4.9,
666
+ "learning_rate": 0.012666666666666666,
667
+ "loss": 0.1775,
668
+ "step": 1100
669
+ },
670
+ {
671
+ "epoch": 4.95,
672
+ "learning_rate": 0.0126,
673
+ "loss": 0.1932,
674
+ "step": 1110
675
+ },
676
+ {
677
+ "epoch": 4.99,
678
+ "learning_rate": 0.012533333333333334,
679
+ "loss": 0.1992,
680
+ "step": 1120
681
+ },
682
+ {
683
+ "epoch": 5.04,
684
+ "learning_rate": 0.012466666666666666,
685
+ "loss": 0.1872,
686
+ "step": 1130
687
+ },
688
+ {
689
+ "epoch": 5.08,
690
+ "learning_rate": 0.0124,
691
+ "loss": 0.1682,
692
+ "step": 1140
693
+ },
694
+ {
695
+ "epoch": 5.13,
696
+ "learning_rate": 0.012333333333333335,
697
+ "loss": 0.1684,
698
+ "step": 1150
699
+ },
700
+ {
701
+ "epoch": 5.17,
702
+ "learning_rate": 0.012266666666666665,
703
+ "loss": 0.1823,
704
+ "step": 1160
705
+ },
706
+ {
707
+ "epoch": 5.22,
708
+ "learning_rate": 0.0122,
709
+ "loss": 0.1803,
710
+ "step": 1170
711
+ },
712
+ {
713
+ "epoch": 5.26,
714
+ "learning_rate": 0.012133333333333335,
715
+ "loss": 0.1794,
716
+ "step": 1180
717
+ },
718
+ {
719
+ "epoch": 5.31,
720
+ "learning_rate": 0.012066666666666668,
721
+ "loss": 0.1902,
722
+ "step": 1190
723
+ },
724
+ {
725
+ "epoch": 5.35,
726
+ "learning_rate": 0.012,
727
+ "loss": 0.1783,
728
+ "step": 1200
729
+ },
730
+ {
731
+ "epoch": 5.39,
732
+ "learning_rate": 0.011933333333333334,
733
+ "loss": 0.1851,
734
+ "step": 1210
735
+ },
736
+ {
737
+ "epoch": 5.44,
738
+ "learning_rate": 0.011866666666666668,
739
+ "loss": 0.1963,
740
+ "step": 1220
741
+ },
742
+ {
743
+ "epoch": 5.48,
744
+ "learning_rate": 0.0118,
745
+ "loss": 0.18,
746
+ "step": 1230
747
+ },
748
+ {
749
+ "epoch": 5.53,
750
+ "learning_rate": 0.011733333333333333,
751
+ "loss": 0.1805,
752
+ "step": 1240
753
+ },
754
+ {
755
+ "epoch": 5.57,
756
+ "learning_rate": 0.011666666666666667,
757
+ "loss": 0.1765,
758
+ "step": 1250
759
+ },
760
+ {
761
+ "epoch": 5.62,
762
+ "learning_rate": 0.0116,
763
+ "loss": 0.1687,
764
+ "step": 1260
765
+ },
766
+ {
767
+ "epoch": 5.66,
768
+ "learning_rate": 0.011533333333333333,
769
+ "loss": 0.1852,
770
+ "step": 1270
771
+ },
772
+ {
773
+ "epoch": 5.71,
774
+ "learning_rate": 0.011466666666666667,
775
+ "loss": 0.1854,
776
+ "step": 1280
777
+ },
778
+ {
779
+ "epoch": 5.75,
780
+ "learning_rate": 0.011399999999999999,
781
+ "loss": 0.1745,
782
+ "step": 1290
783
+ },
784
+ {
785
+ "epoch": 5.8,
786
+ "learning_rate": 0.011333333333333332,
787
+ "loss": 0.1802,
788
+ "step": 1300
789
+ },
790
+ {
791
+ "epoch": 5.84,
792
+ "learning_rate": 0.011266666666666668,
793
+ "loss": 0.1892,
794
+ "step": 1310
795
+ },
796
+ {
797
+ "epoch": 5.88,
798
+ "learning_rate": 0.011200000000000002,
799
+ "loss": 0.1908,
800
+ "step": 1320
801
+ },
802
+ {
803
+ "epoch": 5.93,
804
+ "learning_rate": 0.011133333333333334,
805
+ "loss": 0.1898,
806
+ "step": 1330
807
+ },
808
+ {
809
+ "epoch": 5.97,
810
+ "learning_rate": 0.011066666666666667,
811
+ "loss": 0.1881,
812
+ "step": 1340
813
+ },
814
+ {
815
+ "epoch": 6.02,
816
+ "learning_rate": 0.011000000000000001,
817
+ "loss": 0.1784,
818
+ "step": 1350
819
+ },
820
+ {
821
+ "epoch": 6.06,
822
+ "learning_rate": 0.010933333333333333,
823
+ "loss": 0.1814,
824
+ "step": 1360
825
+ },
826
+ {
827
+ "epoch": 6.11,
828
+ "learning_rate": 0.010866666666666667,
829
+ "loss": 0.1724,
830
+ "step": 1370
831
+ },
832
+ {
833
+ "epoch": 6.15,
834
+ "learning_rate": 0.0108,
835
+ "loss": 0.178,
836
+ "step": 1380
837
+ },
838
+ {
839
+ "epoch": 6.2,
840
+ "learning_rate": 0.010733333333333333,
841
+ "loss": 0.1707,
842
+ "step": 1390
843
+ },
844
+ {
845
+ "epoch": 6.24,
846
+ "learning_rate": 0.010666666666666666,
847
+ "loss": 0.1711,
848
+ "step": 1400
849
+ },
850
+ {
851
+ "epoch": 6.29,
852
+ "learning_rate": 0.0106,
853
+ "loss": 0.1626,
854
+ "step": 1410
855
+ },
856
+ {
857
+ "epoch": 6.33,
858
+ "learning_rate": 0.010533333333333332,
859
+ "loss": 0.1676,
860
+ "step": 1420
861
+ },
862
+ {
863
+ "epoch": 6.38,
864
+ "learning_rate": 0.010466666666666666,
865
+ "loss": 0.1632,
866
+ "step": 1430
867
+ },
868
+ {
869
+ "epoch": 6.42,
870
+ "learning_rate": 0.010400000000000001,
871
+ "loss": 0.171,
872
+ "step": 1440
873
+ },
874
+ {
875
+ "epoch": 6.46,
876
+ "learning_rate": 0.010333333333333335,
877
+ "loss": 0.1746,
878
+ "step": 1450
879
+ },
880
+ {
881
+ "epoch": 6.51,
882
+ "learning_rate": 0.010266666666666667,
883
+ "loss": 0.1764,
884
+ "step": 1460
885
+ },
886
+ {
887
+ "epoch": 6.55,
888
+ "learning_rate": 0.0102,
889
+ "loss": 0.1805,
890
+ "step": 1470
891
+ },
892
+ {
893
+ "epoch": 6.6,
894
+ "learning_rate": 0.010133333333333334,
895
+ "loss": 0.1759,
896
+ "step": 1480
897
+ },
898
+ {
899
+ "epoch": 6.64,
900
+ "learning_rate": 0.010066666666666666,
901
+ "loss": 0.1798,
902
+ "step": 1490
903
+ },
904
+ {
905
+ "epoch": 6.69,
906
+ "learning_rate": 0.01,
907
+ "loss": 0.1673,
908
+ "step": 1500
909
+ },
910
+ {
911
+ "epoch": 6.73,
912
+ "learning_rate": 0.009933333333333334,
913
+ "loss": 0.185,
914
+ "step": 1510
915
+ },
916
+ {
917
+ "epoch": 6.78,
918
+ "learning_rate": 0.009866666666666668,
919
+ "loss": 0.1712,
920
+ "step": 1520
921
+ },
922
+ {
923
+ "epoch": 6.82,
924
+ "learning_rate": 0.0098,
925
+ "loss": 0.1586,
926
+ "step": 1530
927
+ },
928
+ {
929
+ "epoch": 6.87,
930
+ "learning_rate": 0.009733333333333333,
931
+ "loss": 0.1709,
932
+ "step": 1540
933
+ },
934
+ {
935
+ "epoch": 6.91,
936
+ "learning_rate": 0.009666666666666667,
937
+ "loss": 0.1657,
938
+ "step": 1550
939
+ },
940
+ {
941
+ "epoch": 6.95,
942
+ "learning_rate": 0.0096,
943
+ "loss": 0.1738,
944
+ "step": 1560
945
+ },
946
+ {
947
+ "epoch": 7.0,
948
+ "learning_rate": 0.009533333333333335,
949
+ "loss": 0.1633,
950
+ "step": 1570
951
+ },
952
+ {
953
+ "epoch": 7.04,
954
+ "learning_rate": 0.009466666666666667,
955
+ "loss": 0.167,
956
+ "step": 1580
957
+ },
958
+ {
959
+ "epoch": 7.09,
960
+ "learning_rate": 0.0094,
961
+ "loss": 0.1629,
962
+ "step": 1590
963
+ },
964
+ {
965
+ "epoch": 7.13,
966
+ "learning_rate": 0.009333333333333334,
967
+ "loss": 0.1679,
968
+ "step": 1600
969
+ },
970
+ {
971
+ "epoch": 7.18,
972
+ "learning_rate": 0.009266666666666666,
973
+ "loss": 0.1639,
974
+ "step": 1610
975
+ },
976
+ {
977
+ "epoch": 7.22,
978
+ "learning_rate": 0.0092,
979
+ "loss": 0.1652,
980
+ "step": 1620
981
+ },
982
+ {
983
+ "epoch": 7.27,
984
+ "learning_rate": 0.009133333333333334,
985
+ "loss": 0.17,
986
+ "step": 1630
987
+ },
988
+ {
989
+ "epoch": 7.31,
990
+ "learning_rate": 0.009066666666666666,
991
+ "loss": 0.1663,
992
+ "step": 1640
993
+ },
994
+ {
995
+ "epoch": 7.36,
996
+ "learning_rate": 0.009000000000000001,
997
+ "loss": 0.165,
998
+ "step": 1650
999
+ },
1000
+ {
1001
+ "epoch": 7.4,
1002
+ "learning_rate": 0.008933333333333333,
1003
+ "loss": 0.1724,
1004
+ "step": 1660
1005
+ },
1006
+ {
1007
+ "epoch": 7.44,
1008
+ "learning_rate": 0.008866666666666667,
1009
+ "loss": 0.1708,
1010
+ "step": 1670
1011
+ },
1012
+ {
1013
+ "epoch": 7.49,
1014
+ "learning_rate": 0.0088,
1015
+ "loss": 0.1673,
1016
+ "step": 1680
1017
+ },
1018
+ {
1019
+ "epoch": 7.53,
1020
+ "learning_rate": 0.008733333333333333,
1021
+ "loss": 0.1707,
1022
+ "step": 1690
1023
+ },
1024
+ {
1025
+ "epoch": 7.58,
1026
+ "learning_rate": 0.008666666666666668,
1027
+ "loss": 0.1633,
1028
+ "step": 1700
1029
+ },
1030
+ {
1031
+ "epoch": 7.62,
1032
+ "learning_rate": 0.0086,
1033
+ "loss": 0.1624,
1034
+ "step": 1710
1035
+ },
1036
+ {
1037
+ "epoch": 7.67,
1038
+ "learning_rate": 0.008533333333333334,
1039
+ "loss": 0.1574,
1040
+ "step": 1720
1041
+ },
1042
+ {
1043
+ "epoch": 7.71,
1044
+ "learning_rate": 0.008466666666666667,
1045
+ "loss": 0.1678,
1046
+ "step": 1730
1047
+ },
1048
+ {
1049
+ "epoch": 7.76,
1050
+ "learning_rate": 0.0084,
1051
+ "loss": 0.1625,
1052
+ "step": 1740
1053
+ },
1054
+ {
1055
+ "epoch": 7.8,
1056
+ "learning_rate": 0.008333333333333333,
1057
+ "loss": 0.1696,
1058
+ "step": 1750
1059
+ },
1060
+ {
1061
+ "epoch": 7.85,
1062
+ "learning_rate": 0.008266666666666667,
1063
+ "loss": 0.1577,
1064
+ "step": 1760
1065
+ },
1066
+ {
1067
+ "epoch": 7.89,
1068
+ "learning_rate": 0.008199999999999999,
1069
+ "loss": 0.1716,
1070
+ "step": 1770
1071
+ },
1072
+ {
1073
+ "epoch": 7.94,
1074
+ "learning_rate": 0.008133333333333334,
1075
+ "loss": 0.1687,
1076
+ "step": 1780
1077
+ },
1078
+ {
1079
+ "epoch": 7.98,
1080
+ "learning_rate": 0.008066666666666666,
1081
+ "loss": 0.1638,
1082
+ "step": 1790
1083
+ },
1084
+ {
1085
+ "epoch": 8.02,
1086
+ "learning_rate": 0.008,
1087
+ "loss": 0.1557,
1088
+ "step": 1800
1089
+ },
1090
+ {
1091
+ "epoch": 8.07,
1092
+ "learning_rate": 0.007933333333333334,
1093
+ "loss": 0.1536,
1094
+ "step": 1810
1095
+ },
1096
+ {
1097
+ "epoch": 8.11,
1098
+ "learning_rate": 0.007866666666666666,
1099
+ "loss": 0.1661,
1100
+ "step": 1820
1101
+ },
1102
+ {
1103
+ "epoch": 8.16,
1104
+ "learning_rate": 0.0078000000000000005,
1105
+ "loss": 0.1609,
1106
+ "step": 1830
1107
+ },
1108
+ {
1109
+ "epoch": 8.2,
1110
+ "learning_rate": 0.007733333333333333,
1111
+ "loss": 0.1561,
1112
+ "step": 1840
1113
+ },
1114
+ {
1115
+ "epoch": 8.25,
1116
+ "learning_rate": 0.007666666666666667,
1117
+ "loss": 0.1547,
1118
+ "step": 1850
1119
+ },
1120
+ {
1121
+ "epoch": 8.29,
1122
+ "learning_rate": 0.0076,
1123
+ "loss": 0.1685,
1124
+ "step": 1860
1125
+ },
1126
+ {
1127
+ "epoch": 8.34,
1128
+ "learning_rate": 0.007533333333333333,
1129
+ "loss": 0.1649,
1130
+ "step": 1870
1131
+ },
1132
+ {
1133
+ "epoch": 8.38,
1134
+ "learning_rate": 0.0074666666666666675,
1135
+ "loss": 0.1585,
1136
+ "step": 1880
1137
+ },
1138
+ {
1139
+ "epoch": 8.43,
1140
+ "learning_rate": 0.0074,
1141
+ "loss": 0.1659,
1142
+ "step": 1890
1143
+ },
1144
+ {
1145
+ "epoch": 8.47,
1146
+ "learning_rate": 0.007333333333333333,
1147
+ "loss": 0.1563,
1148
+ "step": 1900
1149
+ },
1150
+ {
1151
+ "epoch": 8.51,
1152
+ "learning_rate": 0.007266666666666667,
1153
+ "loss": 0.16,
1154
+ "step": 1910
1155
+ },
1156
+ {
1157
+ "epoch": 8.56,
1158
+ "learning_rate": 0.0072,
1159
+ "loss": 0.1643,
1160
+ "step": 1920
1161
+ },
1162
+ {
1163
+ "epoch": 8.6,
1164
+ "learning_rate": 0.0071333333333333335,
1165
+ "loss": 0.1556,
1166
+ "step": 1930
1167
+ },
1168
+ {
1169
+ "epoch": 8.65,
1170
+ "learning_rate": 0.007066666666666666,
1171
+ "loss": 0.1618,
1172
+ "step": 1940
1173
+ },
1174
+ {
1175
+ "epoch": 8.69,
1176
+ "learning_rate": 0.006999999999999999,
1177
+ "loss": 0.1608,
1178
+ "step": 1950
1179
+ },
1180
+ {
1181
+ "epoch": 8.74,
1182
+ "learning_rate": 0.006933333333333334,
1183
+ "loss": 0.1622,
1184
+ "step": 1960
1185
+ },
1186
+ {
1187
+ "epoch": 8.78,
1188
+ "learning_rate": 0.006866666666666667,
1189
+ "loss": 0.1686,
1190
+ "step": 1970
1191
+ },
1192
+ {
1193
+ "epoch": 8.83,
1194
+ "learning_rate": 0.0068000000000000005,
1195
+ "loss": 0.1624,
1196
+ "step": 1980
1197
+ },
1198
+ {
1199
+ "epoch": 8.87,
1200
+ "learning_rate": 0.006733333333333333,
1201
+ "loss": 0.1623,
1202
+ "step": 1990
1203
+ },
1204
+ {
1205
+ "epoch": 8.92,
1206
+ "learning_rate": 0.006666666666666666,
1207
+ "loss": 0.1658,
1208
+ "step": 2000
1209
+ }
1210
+ ],
1211
+ "max_steps": 3000,
1212
+ "num_train_epochs": 14,
1213
+ "total_flos": 1.151299135471616e+17,
1214
+ "trial_name": null,
1215
+ "trial_params": null
1216
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-2000/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e6686835e3bd90bbdc74d1b219b44b2e320a817dfae63b8e2323d2410ad705c7
3
+ size 3707
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/config.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "../THUDM/chatglm2-6b",
3
+ "add_bias_linear": false,
4
+ "add_qkv_bias": true,
5
+ "apply_query_key_layer_scaling": true,
6
+ "apply_residual_connection_post_layernorm": false,
7
+ "architectures": [
8
+ "ChatGLMForConditionalGeneration"
9
+ ],
10
+ "attention_dropout": 0.0,
11
+ "attention_softmax_in_fp32": true,
12
+ "auto_map": {
13
+ "AutoConfig": "configuration_chatglm.ChatGLMConfig",
14
+ "AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration",
15
+ "AutoModelForCausalLM": "modeling_chatglm.ChatGLMForConditionalGeneration",
16
+ "AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration"
17
+ },
18
+ "bias_dropout_fusion": true,
19
+ "eos_token_id": 2,
20
+ "ffn_hidden_size": 13696,
21
+ "fp32_residual_connection": false,
22
+ "hidden_dropout": 0.0,
23
+ "hidden_size": 4096,
24
+ "kv_channels": 128,
25
+ "layernorm_epsilon": 1e-05,
26
+ "model_type": "chatglm",
27
+ "multi_query_attention": true,
28
+ "multi_query_group_num": 2,
29
+ "num_attention_heads": 32,
30
+ "num_layers": 28,
31
+ "original_rope": true,
32
+ "pad_token_id": 0,
33
+ "padded_vocab_size": 65024,
34
+ "post_layer_norm": true,
35
+ "pre_seq_len": 128,
36
+ "prefix_projection": false,
37
+ "quantization_bit": 4,
38
+ "rmsnorm": true,
39
+ "seq_length": 32768,
40
+ "tie_word_embeddings": false,
41
+ "torch_dtype": "float16",
42
+ "transformers_version": "4.27.1",
43
+ "use_cache": true,
44
+ "vocab_size": 65024
45
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/configuration_chatglm.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+
4
+ class ChatGLMConfig(PretrainedConfig):
5
+ model_type = "chatglm"
6
+ def __init__(
7
+ self,
8
+ num_layers=28,
9
+ padded_vocab_size=65024,
10
+ hidden_size=4096,
11
+ ffn_hidden_size=13696,
12
+ kv_channels=128,
13
+ num_attention_heads=32,
14
+ seq_length=2048,
15
+ hidden_dropout=0.0,
16
+ attention_dropout=0.0,
17
+ layernorm_epsilon=1e-5,
18
+ rmsnorm=True,
19
+ apply_residual_connection_post_layernorm=False,
20
+ post_layer_norm=True,
21
+ add_bias_linear=False,
22
+ add_qkv_bias=False,
23
+ bias_dropout_fusion=True,
24
+ multi_query_attention=False,
25
+ multi_query_group_num=1,
26
+ apply_query_key_layer_scaling=True,
27
+ attention_softmax_in_fp32=True,
28
+ fp32_residual_connection=False,
29
+ quantization_bit=0,
30
+ pre_seq_len=None,
31
+ prefix_projection=False,
32
+ **kwargs
33
+ ):
34
+ self.num_layers = num_layers
35
+ self.vocab_size = padded_vocab_size
36
+ self.padded_vocab_size = padded_vocab_size
37
+ self.hidden_size = hidden_size
38
+ self.ffn_hidden_size = ffn_hidden_size
39
+ self.kv_channels = kv_channels
40
+ self.num_attention_heads = num_attention_heads
41
+ self.seq_length = seq_length
42
+ self.hidden_dropout = hidden_dropout
43
+ self.attention_dropout = attention_dropout
44
+ self.layernorm_epsilon = layernorm_epsilon
45
+ self.rmsnorm = rmsnorm
46
+ self.apply_residual_connection_post_layernorm = apply_residual_connection_post_layernorm
47
+ self.post_layer_norm = post_layer_norm
48
+ self.add_bias_linear = add_bias_linear
49
+ self.add_qkv_bias = add_qkv_bias
50
+ self.bias_dropout_fusion = bias_dropout_fusion
51
+ self.multi_query_attention = multi_query_attention
52
+ self.multi_query_group_num = multi_query_group_num
53
+ self.apply_query_key_layer_scaling = apply_query_key_layer_scaling
54
+ self.attention_softmax_in_fp32 = attention_softmax_in_fp32
55
+ self.fp32_residual_connection = fp32_residual_connection
56
+ self.quantization_bit = quantization_bit
57
+ self.pre_seq_len = pre_seq_len
58
+ self.prefix_projection = prefix_projection
59
+ super().__init__(**kwargs)
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "eos_token_id": 2,
4
+ "pad_token_id": 0,
5
+ "transformers_version": "4.27.1"
6
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/modeling_chatglm.py ADDED
@@ -0,0 +1,1193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ PyTorch ChatGLM model. """
2
+
3
+ import math
4
+ import copy
5
+ import warnings
6
+ import re
7
+ import sys
8
+
9
+ import torch
10
+ import torch.utils.checkpoint
11
+ import torch.nn.functional as F
12
+ from torch import nn
13
+ from torch.nn import CrossEntropyLoss, LayerNorm
14
+ from torch.nn.utils import skip_init
15
+ from typing import Optional, Tuple, Union, List, Callable, Dict, Any
16
+
17
+ from transformers.modeling_outputs import (
18
+ BaseModelOutputWithPast,
19
+ CausalLMOutputWithPast,
20
+ )
21
+ from transformers.modeling_utils import PreTrainedModel
22
+ from transformers.utils import logging
23
+ from transformers.generation.logits_process import LogitsProcessor
24
+ from transformers.generation.utils import LogitsProcessorList, StoppingCriteriaList, GenerationConfig, ModelOutput
25
+
26
+ from .configuration_chatglm import ChatGLMConfig
27
+
28
+ # flags required to enable jit fusion kernels
29
+
30
+ if sys.platform != 'darwin':
31
+ torch._C._jit_set_profiling_mode(False)
32
+ torch._C._jit_set_profiling_executor(False)
33
+ torch._C._jit_override_can_fuse_on_cpu(True)
34
+ torch._C._jit_override_can_fuse_on_gpu(True)
35
+
36
+ logger = logging.get_logger(__name__)
37
+
38
+ _CHECKPOINT_FOR_DOC = "THUDM/ChatGLM2-6B"
39
+ _CONFIG_FOR_DOC = "ChatGLM6BConfig"
40
+
41
+ CHATGLM_6B_PRETRAINED_MODEL_ARCHIVE_LIST = [
42
+ "THUDM/chatglm2-6b",
43
+ # See all ChatGLM models at https://huggingface.co/models?filter=chatglm
44
+ ]
45
+
46
+
47
+ def default_init(cls, *args, **kwargs):
48
+ return cls(*args, **kwargs)
49
+
50
+
51
+ class InvalidScoreLogitsProcessor(LogitsProcessor):
52
+ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
53
+ if torch.isnan(scores).any() or torch.isinf(scores).any():
54
+ scores.zero_()
55
+ scores[..., 5] = 5e4
56
+ return scores
57
+
58
+
59
+ class PrefixEncoder(torch.nn.Module):
60
+ """
61
+ The torch.nn model to encode the prefix
62
+ Input shape: (batch-size, prefix-length)
63
+ Output shape: (batch-size, prefix-length, 2*layers*hidden)
64
+ """
65
+
66
+ def __init__(self, config: ChatGLMConfig):
67
+ super().__init__()
68
+ self.prefix_projection = config.prefix_projection
69
+ if self.prefix_projection:
70
+ # Use a two-layer MLP to encode the prefix
71
+ kv_size = config.num_layers * config.kv_channels * config.multi_query_group_num * 2
72
+ self.embedding = torch.nn.Embedding(config.pre_seq_len, kv_size)
73
+ self.trans = torch.nn.Sequential(
74
+ torch.nn.Linear(kv_size, config.hidden_size),
75
+ torch.nn.Tanh(),
76
+ torch.nn.Linear(config.hidden_size, kv_size)
77
+ )
78
+ else:
79
+ self.embedding = torch.nn.Embedding(config.pre_seq_len,
80
+ config.num_layers * config.kv_channels * config.multi_query_group_num * 2)
81
+
82
+ def forward(self, prefix: torch.Tensor):
83
+ if self.prefix_projection:
84
+ prefix_tokens = self.embedding(prefix)
85
+ past_key_values = self.trans(prefix_tokens)
86
+ else:
87
+ past_key_values = self.embedding(prefix)
88
+ return past_key_values
89
+
90
+
91
+ def split_tensor_along_last_dim(
92
+ tensor: torch.Tensor,
93
+ num_partitions: int,
94
+ contiguous_split_chunks: bool = False,
95
+ ) -> List[torch.Tensor]:
96
+ """Split a tensor along its last dimension.
97
+
98
+ Arguments:
99
+ tensor: input tensor.
100
+ num_partitions: number of partitions to split the tensor
101
+ contiguous_split_chunks: If True, make each chunk contiguous
102
+ in memory.
103
+
104
+ Returns:
105
+ A list of Tensors
106
+ """
107
+ # Get the size and dimension.
108
+ last_dim = tensor.dim() - 1
109
+ last_dim_size = tensor.size()[last_dim] // num_partitions
110
+ # Split.
111
+ tensor_list = torch.split(tensor, last_dim_size, dim=last_dim)
112
+ # Note: torch.split does not create contiguous tensors by default.
113
+ if contiguous_split_chunks:
114
+ return tuple(chunk.contiguous() for chunk in tensor_list)
115
+
116
+ return tensor_list
117
+
118
+
119
+ class RotaryEmbedding(nn.Module):
120
+ def __init__(self, dim, original_impl=False, device=None, dtype=None):
121
+ super().__init__()
122
+ inv_freq = 1.0 / (10000 ** (torch.arange(0, dim, 2, device=device).to(dtype=dtype) / dim))
123
+ self.register_buffer("inv_freq", inv_freq)
124
+ self.dim = dim
125
+ self.original_impl = original_impl
126
+
127
+ def forward_impl(
128
+ self, seq_len: int, n_elem: int, dtype: torch.dtype, device: torch.device, base: int = 10000
129
+ ):
130
+ """Enhanced Transformer with Rotary Position Embedding.
131
+
132
+ Derived from: https://github.com/labmlai/annotated_deep_learning_paper_implementations/blob/master/labml_nn/
133
+ transformers/rope/__init__.py. MIT License:
134
+ https://github.com/labmlai/annotated_deep_learning_paper_implementations/blob/master/license.
135
+ """
136
+ # $\Theta = {\theta_i = 10000^{\frac{2(i-1)}{d}}, i \in [1, 2, ..., \frac{d}{2}]}$
137
+ theta = 1.0 / (base ** (torch.arange(0, n_elem, 2, dtype=dtype, device=device) / n_elem))
138
+
139
+ # Create position indexes `[0, 1, ..., seq_len - 1]`
140
+ seq_idx = torch.arange(seq_len, dtype=dtype, device=device)
141
+
142
+ # Calculate the product of position index and $\theta_i$
143
+ idx_theta = torch.outer(seq_idx, theta).float()
144
+
145
+ cache = torch.stack([torch.cos(idx_theta), torch.sin(idx_theta)], dim=-1)
146
+
147
+ # this is to mimic the behaviour of complex32, else we will get different results
148
+ if dtype in (torch.float16, torch.bfloat16, torch.int8):
149
+ cache = cache.bfloat16() if dtype == torch.bfloat16 else cache.half()
150
+ return cache
151
+
152
+ def forward(self, max_seq_len, offset=0):
153
+ return self.forward_impl(
154
+ max_seq_len, self.dim, dtype=self.inv_freq.dtype, device=self.inv_freq.device
155
+ )
156
+
157
+
158
+ @torch.jit.script
159
+ def apply_rotary_pos_emb(x: torch.Tensor, rope_cache: torch.Tensor) -> torch.Tensor:
160
+ # x: [sq, b, np, hn]
161
+ sq, b, np, hn = x.size(0), x.size(1), x.size(2), x.size(3)
162
+ rot_dim = rope_cache.shape[-2] * 2
163
+ x, x_pass = x[..., :rot_dim], x[..., rot_dim:]
164
+ # truncate to support variable sizes
165
+ rope_cache = rope_cache[:sq]
166
+ xshaped = x.reshape(sq, -1, np, rot_dim // 2, 2)
167
+ rope_cache = rope_cache.view(sq, -1, 1, xshaped.size(3), 2)
168
+ x_out2 = torch.stack(
169
+ [
170
+ xshaped[..., 0] * rope_cache[..., 0] - xshaped[..., 1] * rope_cache[..., 1],
171
+ xshaped[..., 1] * rope_cache[..., 0] + xshaped[..., 0] * rope_cache[..., 1],
172
+ ],
173
+ -1,
174
+ )
175
+ x_out2 = x_out2.flatten(3)
176
+ return torch.cat((x_out2, x_pass), dim=-1)
177
+
178
+
179
+ class RMSNorm(torch.nn.Module):
180
+ def __init__(self, normalized_shape, eps=1e-5, device=None, dtype=None, **kwargs):
181
+ super().__init__()
182
+ self.weight = torch.nn.Parameter(torch.empty(normalized_shape, device=device, dtype=dtype))
183
+ self.eps = eps
184
+
185
+ def forward(self, hidden_states: torch.Tensor):
186
+ input_dtype = hidden_states.dtype
187
+ variance = hidden_states.to(torch.float32).pow(2).mean(-1, keepdim=True)
188
+ hidden_states = hidden_states * torch.rsqrt(variance + self.eps)
189
+
190
+ return (self.weight * hidden_states).to(input_dtype)
191
+
192
+
193
+ class CoreAttention(torch.nn.Module):
194
+ def __init__(self, config: ChatGLMConfig, layer_number):
195
+ super(CoreAttention, self).__init__()
196
+
197
+ self.apply_query_key_layer_scaling = config.apply_query_key_layer_scaling
198
+ self.attention_softmax_in_fp32 = config.attention_softmax_in_fp32
199
+ if self.apply_query_key_layer_scaling:
200
+ self.attention_softmax_in_fp32 = True
201
+ self.layer_number = max(1, layer_number)
202
+
203
+ projection_size = config.kv_channels * config.num_attention_heads
204
+
205
+ # Per attention head and per partition values.
206
+ self.hidden_size_per_partition = projection_size
207
+ self.hidden_size_per_attention_head = projection_size // config.num_attention_heads
208
+ self.num_attention_heads_per_partition = config.num_attention_heads
209
+
210
+ coeff = None
211
+ self.norm_factor = math.sqrt(self.hidden_size_per_attention_head)
212
+ if self.apply_query_key_layer_scaling:
213
+ coeff = self.layer_number
214
+ self.norm_factor *= coeff
215
+ self.coeff = coeff
216
+
217
+ self.attention_dropout = torch.nn.Dropout(config.attention_dropout)
218
+
219
+ def forward(self, query_layer, key_layer, value_layer, attention_mask):
220
+ pytorch_major_version = int(torch.__version__.split('.')[0])
221
+ if pytorch_major_version >= 2:
222
+ query_layer, key_layer, value_layer = [k.permute(1, 2, 0, 3) for k in [query_layer, key_layer, value_layer]]
223
+ if attention_mask is None and query_layer.shape[2] == key_layer.shape[2]:
224
+ context_layer = torch.nn.functional.scaled_dot_product_attention(query_layer, key_layer, value_layer,
225
+ is_causal=True)
226
+ else:
227
+ if attention_mask is not None:
228
+ attention_mask = ~attention_mask
229
+ context_layer = torch.nn.functional.scaled_dot_product_attention(query_layer, key_layer, value_layer,
230
+ attention_mask)
231
+ context_layer = context_layer.permute(2, 0, 1, 3)
232
+ new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size_per_partition,)
233
+ context_layer = context_layer.reshape(*new_context_layer_shape)
234
+ else:
235
+ # Raw attention scores
236
+
237
+ # [b, np, sq, sk]
238
+ output_size = (query_layer.size(1), query_layer.size(2), query_layer.size(0), key_layer.size(0))
239
+
240
+ # [sq, b, np, hn] -> [sq, b * np, hn]
241
+ query_layer = query_layer.view(output_size[2], output_size[0] * output_size[1], -1)
242
+ # [sk, b, np, hn] -> [sk, b * np, hn]
243
+ key_layer = key_layer.view(output_size[3], output_size[0] * output_size[1], -1)
244
+
245
+ # preallocting input tensor: [b * np, sq, sk]
246
+ matmul_input_buffer = torch.empty(
247
+ output_size[0] * output_size[1], output_size[2], output_size[3], dtype=query_layer.dtype,
248
+ device=query_layer.device
249
+ )
250
+
251
+ # Raw attention scores. [b * np, sq, sk]
252
+ matmul_result = torch.baddbmm(
253
+ matmul_input_buffer,
254
+ query_layer.transpose(0, 1), # [b * np, sq, hn]
255
+ key_layer.transpose(0, 1).transpose(1, 2), # [b * np, hn, sk]
256
+ beta=0.0,
257
+ alpha=(1.0 / self.norm_factor),
258
+ )
259
+
260
+ # change view to [b, np, sq, sk]
261
+ attention_scores = matmul_result.view(*output_size)
262
+
263
+ # ===========================
264
+ # Attention probs and dropout
265
+ # ===========================
266
+
267
+ # attention scores and attention mask [b, np, sq, sk]
268
+ if self.attention_softmax_in_fp32:
269
+ attention_scores = attention_scores.float()
270
+ if self.coeff is not None:
271
+ attention_scores = attention_scores * self.coeff
272
+ if attention_mask is None and attention_scores.shape[2] == attention_scores.shape[3]:
273
+ attention_mask = torch.ones(output_size[0], 1, output_size[2], output_size[3],
274
+ device=attention_scores.device, dtype=torch.bool)
275
+ attention_mask.tril_()
276
+ attention_mask = ~attention_mask
277
+ if attention_mask is not None:
278
+ attention_scores = attention_scores.masked_fill(attention_mask, float("-inf"))
279
+ attention_probs = F.softmax(attention_scores, dim=-1)
280
+ attention_probs = attention_probs.type_as(value_layer)
281
+
282
+ # This is actually dropping out entire tokens to attend to, which might
283
+ # seem a bit unusual, but is taken from the original Transformer paper.
284
+ attention_probs = self.attention_dropout(attention_probs)
285
+ # =========================
286
+ # Context layer. [sq, b, hp]
287
+ # =========================
288
+
289
+ # value_layer -> context layer.
290
+ # [sk, b, np, hn] --> [b, np, sq, hn]
291
+
292
+ # context layer shape: [b, np, sq, hn]
293
+ output_size = (value_layer.size(1), value_layer.size(2), query_layer.size(0), value_layer.size(3))
294
+ # change view [sk, b * np, hn]
295
+ value_layer = value_layer.view(value_layer.size(0), output_size[0] * output_size[1], -1)
296
+ # change view [b * np, sq, sk]
297
+ attention_probs = attention_probs.view(output_size[0] * output_size[1], output_size[2], -1)
298
+ # matmul: [b * np, sq, hn]
299
+ context_layer = torch.bmm(attention_probs, value_layer.transpose(0, 1))
300
+ # change view [b, np, sq, hn]
301
+ context_layer = context_layer.view(*output_size)
302
+ # [b, np, sq, hn] --> [sq, b, np, hn]
303
+ context_layer = context_layer.permute(2, 0, 1, 3).contiguous()
304
+ # [sq, b, np, hn] --> [sq, b, hp]
305
+ new_context_layer_shape = context_layer.size()[:-2] + (self.hidden_size_per_partition,)
306
+ context_layer = context_layer.view(*new_context_layer_shape)
307
+
308
+ return context_layer
309
+
310
+
311
+ class SelfAttention(torch.nn.Module):
312
+ """Parallel self-attention layer abstract class.
313
+
314
+ Self-attention layer takes input with size [s, b, h]
315
+ and returns output of the same size.
316
+ """
317
+
318
+ def __init__(self, config: ChatGLMConfig, layer_number, device=None):
319
+ super(SelfAttention, self).__init__()
320
+ self.layer_number = max(1, layer_number)
321
+
322
+ self.projection_size = config.kv_channels * config.num_attention_heads
323
+
324
+ # Per attention head and per partition values.
325
+ self.hidden_size_per_attention_head = self.projection_size // config.num_attention_heads
326
+ self.num_attention_heads_per_partition = config.num_attention_heads
327
+
328
+ self.multi_query_attention = config.multi_query_attention
329
+ self.qkv_hidden_size = 3 * self.projection_size
330
+ if self.multi_query_attention:
331
+ self.num_multi_query_groups_per_partition = config.multi_query_group_num
332
+ self.qkv_hidden_size = (
333
+ self.projection_size + 2 * self.hidden_size_per_attention_head * config.multi_query_group_num
334
+ )
335
+ self.query_key_value = nn.Linear(config.hidden_size, self.qkv_hidden_size,
336
+ bias=config.add_bias_linear or config.add_qkv_bias,
337
+ device=device, **_config_to_kwargs(config)
338
+ )
339
+
340
+ self.core_attention = CoreAttention(config, self.layer_number)
341
+
342
+ # Output.
343
+ self.dense = nn.Linear(self.projection_size, config.hidden_size, bias=config.add_bias_linear,
344
+ device=device, **_config_to_kwargs(config)
345
+ )
346
+
347
+ def _allocate_memory(self, inference_max_sequence_len, batch_size, device=None, dtype=None):
348
+ if self.multi_query_attention:
349
+ num_attention_heads = self.num_multi_query_groups_per_partition
350
+ else:
351
+ num_attention_heads = self.num_attention_heads_per_partition
352
+ return torch.empty(
353
+ inference_max_sequence_len,
354
+ batch_size,
355
+ num_attention_heads,
356
+ self.hidden_size_per_attention_head,
357
+ dtype=dtype,
358
+ device=device,
359
+ )
360
+
361
+ def forward(
362
+ self, hidden_states, attention_mask, rotary_pos_emb, kv_cache=None, use_cache=True
363
+ ):
364
+ # hidden_states: [sq, b, h]
365
+
366
+ # =================================================
367
+ # Pre-allocate memory for key-values for inference.
368
+ # =================================================
369
+ # =====================
370
+ # Query, Key, and Value
371
+ # =====================
372
+
373
+ # Attention heads [sq, b, h] --> [sq, b, (np * 3 * hn)]
374
+ mixed_x_layer = self.query_key_value(hidden_states)
375
+
376
+ if self.multi_query_attention:
377
+ (query_layer, key_layer, value_layer) = mixed_x_layer.split(
378
+ [
379
+ self.num_attention_heads_per_partition * self.hidden_size_per_attention_head,
380
+ self.num_multi_query_groups_per_partition * self.hidden_size_per_attention_head,
381
+ self.num_multi_query_groups_per_partition * self.hidden_size_per_attention_head,
382
+ ],
383
+ dim=-1,
384
+ )
385
+ query_layer = query_layer.view(
386
+ query_layer.size()[:-1] + (self.num_attention_heads_per_partition, self.hidden_size_per_attention_head)
387
+ )
388
+ key_layer = key_layer.view(
389
+ key_layer.size()[:-1] + (self.num_multi_query_groups_per_partition, self.hidden_size_per_attention_head)
390
+ )
391
+ value_layer = value_layer.view(
392
+ value_layer.size()[:-1]
393
+ + (self.num_multi_query_groups_per_partition, self.hidden_size_per_attention_head)
394
+ )
395
+ else:
396
+ new_tensor_shape = mixed_x_layer.size()[:-1] + \
397
+ (self.num_attention_heads_per_partition,
398
+ 3 * self.hidden_size_per_attention_head)
399
+ mixed_x_layer = mixed_x_layer.view(*new_tensor_shape)
400
+
401
+ # [sq, b, np, 3 * hn] --> 3 [sq, b, np, hn]
402
+ (query_layer, key_layer, value_layer) = split_tensor_along_last_dim(mixed_x_layer, 3)
403
+
404
+ # apply relative positional encoding (rotary embedding)
405
+ if rotary_pos_emb is not None:
406
+ query_layer = apply_rotary_pos_emb(query_layer, rotary_pos_emb)
407
+ key_layer = apply_rotary_pos_emb(key_layer, rotary_pos_emb)
408
+
409
+ # adjust key and value for inference
410
+ if kv_cache is not None:
411
+ cache_k, cache_v = kv_cache
412
+ key_layer = torch.cat((cache_k, key_layer), dim=0)
413
+ value_layer = torch.cat((cache_v, value_layer), dim=0)
414
+ if use_cache:
415
+ kv_cache = (key_layer, value_layer)
416
+ else:
417
+ kv_cache = None
418
+
419
+ if self.multi_query_attention:
420
+ key_layer = key_layer.unsqueeze(-2)
421
+ key_layer = key_layer.expand(
422
+ -1, -1, -1, self.num_attention_heads_per_partition // self.num_multi_query_groups_per_partition, -1
423
+ )
424
+ key_layer = key_layer.contiguous().view(
425
+ key_layer.size()[:2] + (self.num_attention_heads_per_partition, self.hidden_size_per_attention_head)
426
+ )
427
+ value_layer = value_layer.unsqueeze(-2)
428
+ value_layer = value_layer.expand(
429
+ -1, -1, -1, self.num_attention_heads_per_partition // self.num_multi_query_groups_per_partition, -1
430
+ )
431
+ value_layer = value_layer.contiguous().view(
432
+ value_layer.size()[:2] + (self.num_attention_heads_per_partition, self.hidden_size_per_attention_head)
433
+ )
434
+
435
+ # ==================================
436
+ # core attention computation
437
+ # ==================================
438
+
439
+ context_layer = self.core_attention(query_layer, key_layer, value_layer, attention_mask)
440
+
441
+ # =================
442
+ # Output. [sq, b, h]
443
+ # =================
444
+
445
+ output = self.dense(context_layer)
446
+
447
+ return output, kv_cache
448
+
449
+
450
+ def _config_to_kwargs(args):
451
+ common_kwargs = {
452
+ "dtype": args.torch_dtype,
453
+ }
454
+ return common_kwargs
455
+
456
+
457
+ class MLP(torch.nn.Module):
458
+ """MLP.
459
+
460
+ MLP will take the input with h hidden state, project it to 4*h
461
+ hidden dimension, perform nonlinear transformation, and project the
462
+ state back into h hidden dimension.
463
+ """
464
+
465
+ def __init__(self, config: ChatGLMConfig, device=None):
466
+ super(MLP, self).__init__()
467
+
468
+ self.add_bias = config.add_bias_linear
469
+
470
+ # Project to 4h. If using swiglu double the output width, see https://arxiv.org/pdf/2002.05202.pdf
471
+ self.dense_h_to_4h = nn.Linear(
472
+ config.hidden_size,
473
+ config.ffn_hidden_size * 2,
474
+ bias=self.add_bias,
475
+ device=device,
476
+ **_config_to_kwargs(config)
477
+ )
478
+
479
+ def swiglu(x):
480
+ x = torch.chunk(x, 2, dim=-1)
481
+ return F.silu(x[0]) * x[1]
482
+
483
+ self.activation_func = swiglu
484
+
485
+ # Project back to h.
486
+ self.dense_4h_to_h = nn.Linear(
487
+ config.ffn_hidden_size,
488
+ config.hidden_size,
489
+ bias=self.add_bias,
490
+ device=device,
491
+ **_config_to_kwargs(config)
492
+ )
493
+
494
+ def forward(self, hidden_states):
495
+ # [s, b, 4hp]
496
+ intermediate_parallel = self.dense_h_to_4h(hidden_states)
497
+ intermediate_parallel = self.activation_func(intermediate_parallel)
498
+ # [s, b, h]
499
+ output = self.dense_4h_to_h(intermediate_parallel)
500
+ return output
501
+
502
+
503
+ class GLMBlock(torch.nn.Module):
504
+ """A single transformer layer.
505
+
506
+ Transformer layer takes input with size [s, b, h] and returns an
507
+ output of the same size.
508
+ """
509
+
510
+ def __init__(self, config: ChatGLMConfig, layer_number, device=None):
511
+ super(GLMBlock, self).__init__()
512
+ self.layer_number = layer_number
513
+
514
+ self.apply_residual_connection_post_layernorm = config.apply_residual_connection_post_layernorm
515
+
516
+ self.fp32_residual_connection = config.fp32_residual_connection
517
+
518
+ LayerNormFunc = RMSNorm if config.rmsnorm else LayerNorm
519
+ # Layernorm on the input data.
520
+ self.input_layernorm = LayerNormFunc(config.hidden_size, eps=config.layernorm_epsilon, device=device,
521
+ dtype=config.torch_dtype)
522
+
523
+ # Self attention.
524
+ self.self_attention = SelfAttention(config, layer_number, device=device)
525
+ self.hidden_dropout = config.hidden_dropout
526
+
527
+ # Layernorm on the attention output
528
+ self.post_attention_layernorm = LayerNormFunc(config.hidden_size, eps=config.layernorm_epsilon, device=device,
529
+ dtype=config.torch_dtype)
530
+
531
+ # MLP
532
+ self.mlp = MLP(config, device=device)
533
+
534
+ def forward(
535
+ self, hidden_states, attention_mask, rotary_pos_emb, kv_cache=None, use_cache=True,
536
+ ):
537
+ # hidden_states: [s, b, h]
538
+
539
+ # Layer norm at the beginning of the transformer layer.
540
+ layernorm_output = self.input_layernorm(hidden_states)
541
+ # Self attention.
542
+ attention_output, kv_cache = self.self_attention(
543
+ layernorm_output,
544
+ attention_mask,
545
+ rotary_pos_emb,
546
+ kv_cache=kv_cache,
547
+ use_cache=use_cache
548
+ )
549
+
550
+ # Residual connection.
551
+ if self.apply_residual_connection_post_layernorm:
552
+ residual = layernorm_output
553
+ else:
554
+ residual = hidden_states
555
+
556
+ layernorm_input = torch.nn.functional.dropout(attention_output, p=self.hidden_dropout, training=self.training)
557
+ layernorm_input = residual + layernorm_input
558
+
559
+ # Layer norm post the self attention.
560
+ layernorm_output = self.post_attention_layernorm(layernorm_input)
561
+
562
+ # MLP.
563
+ mlp_output = self.mlp(layernorm_output)
564
+
565
+ # Second residual connection.
566
+ if self.apply_residual_connection_post_layernorm:
567
+ residual = layernorm_output
568
+ else:
569
+ residual = layernorm_input
570
+
571
+ output = torch.nn.functional.dropout(mlp_output, p=self.hidden_dropout, training=self.training)
572
+ output = residual + output
573
+
574
+ return output, kv_cache
575
+
576
+
577
+ class GLMTransformer(torch.nn.Module):
578
+ """Transformer class."""
579
+
580
+ def __init__(self, config: ChatGLMConfig, device=None):
581
+ super(GLMTransformer, self).__init__()
582
+
583
+ self.fp32_residual_connection = config.fp32_residual_connection
584
+ self.post_layer_norm = config.post_layer_norm
585
+
586
+ # Number of layers.
587
+ self.num_layers = config.num_layers
588
+
589
+ # Transformer layers.
590
+ def build_layer(layer_number):
591
+ return GLMBlock(config, layer_number, device=device)
592
+
593
+ self.layers = torch.nn.ModuleList([build_layer(i + 1) for i in range(self.num_layers)])
594
+
595
+ if self.post_layer_norm:
596
+ LayerNormFunc = RMSNorm if config.rmsnorm else LayerNorm
597
+ # Final layer norm before output.
598
+ self.final_layernorm = LayerNormFunc(config.hidden_size, eps=config.layernorm_epsilon, device=device,
599
+ dtype=config.torch_dtype)
600
+
601
+ self.gradient_checkpointing = False
602
+
603
+ def _get_layer(self, layer_number):
604
+ return self.layers[layer_number]
605
+
606
+ def forward(
607
+ self, hidden_states, attention_mask, rotary_pos_emb, kv_caches=None,
608
+ use_cache: Optional[bool] = True,
609
+ output_hidden_states: Optional[bool] = False,
610
+ ):
611
+ if not kv_caches:
612
+ kv_caches = [None for _ in range(self.num_layers)]
613
+ presents = () if use_cache else None
614
+ if self.gradient_checkpointing and self.training:
615
+ if use_cache:
616
+ logger.warning_once(
617
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
618
+ )
619
+ use_cache = False
620
+
621
+ all_self_attentions = None
622
+ all_hidden_states = () if output_hidden_states else None
623
+ for index in range(self.num_layers):
624
+ if output_hidden_states:
625
+ all_hidden_states = all_hidden_states + (hidden_states,)
626
+
627
+ layer = self._get_layer(index)
628
+ if self.gradient_checkpointing and self.training:
629
+ layer_ret = torch.utils.checkpoint.checkpoint(
630
+ layer,
631
+ hidden_states,
632
+ attention_mask,
633
+ rotary_pos_emb,
634
+ kv_caches[index],
635
+ use_cache
636
+ )
637
+ else:
638
+ layer_ret = layer(
639
+ hidden_states,
640
+ attention_mask,
641
+ rotary_pos_emb,
642
+ kv_cache=kv_caches[index],
643
+ use_cache=use_cache
644
+ )
645
+ hidden_states, kv_cache = layer_ret
646
+ if use_cache:
647
+ presents = presents + (kv_cache,)
648
+
649
+ if output_hidden_states:
650
+ all_hidden_states = all_hidden_states + (hidden_states,)
651
+
652
+ # Final layer norm.
653
+ if self.post_layer_norm:
654
+ hidden_states = self.final_layernorm(hidden_states)
655
+
656
+ return hidden_states, presents, all_hidden_states, all_self_attentions
657
+
658
+
659
+ class ChatGLMPreTrainedModel(PreTrainedModel):
660
+ """
661
+ An abstract class to handle weights initialization and
662
+ a simple interface for downloading and loading pretrained models.
663
+ """
664
+
665
+ is_parallelizable = False
666
+ supports_gradient_checkpointing = True
667
+ config_class = ChatGLMConfig
668
+ base_model_prefix = "transformer"
669
+ _no_split_modules = ["GLMBlock"]
670
+
671
+ def _init_weights(self, module: nn.Module):
672
+ """Initialize the weights."""
673
+ return
674
+
675
+ def get_masks(self, input_ids, past_key_values, padding_mask=None):
676
+ batch_size, seq_length = input_ids.shape
677
+ full_attention_mask = torch.ones(batch_size, seq_length, seq_length, device=input_ids.device)
678
+ full_attention_mask.tril_()
679
+ past_length = 0
680
+ if past_key_values:
681
+ past_length = past_key_values[0][0].shape[0]
682
+ if past_length:
683
+ full_attention_mask = torch.cat((torch.ones(batch_size, seq_length, past_length,
684
+ device=input_ids.device), full_attention_mask), dim=-1)
685
+ if padding_mask is not None:
686
+ full_attention_mask = full_attention_mask * padding_mask.unsqueeze(1)
687
+ if not past_length and padding_mask is not None:
688
+ full_attention_mask -= padding_mask.unsqueeze(-1) - 1
689
+ full_attention_mask = (full_attention_mask < 0.5).bool()
690
+ full_attention_mask.unsqueeze_(1)
691
+ return full_attention_mask
692
+
693
+ def get_position_ids(self, input_ids, device):
694
+ batch_size, seq_length = input_ids.shape
695
+ position_ids = torch.arange(seq_length, dtype=torch.long, device=device).unsqueeze(0).repeat(batch_size, 1)
696
+ return position_ids
697
+
698
+ def _set_gradient_checkpointing(self, module, value=False):
699
+ if isinstance(module, GLMTransformer):
700
+ module.gradient_checkpointing = value
701
+
702
+
703
+ class Embedding(torch.nn.Module):
704
+ """Language model embeddings."""
705
+
706
+ def __init__(self, config: ChatGLMConfig, device=None):
707
+ super(Embedding, self).__init__()
708
+
709
+ self.hidden_size = config.hidden_size
710
+ # Word embeddings (parallel).
711
+ self.word_embeddings = nn.Embedding(
712
+ config.padded_vocab_size,
713
+ self.hidden_size,
714
+ dtype=config.torch_dtype,
715
+ device=device
716
+ )
717
+ self.fp32_residual_connection = config.fp32_residual_connection
718
+
719
+ def forward(self, input_ids):
720
+ # Embeddings.
721
+ words_embeddings = self.word_embeddings(input_ids)
722
+ embeddings = words_embeddings
723
+ # Data format change to avoid explicit tranposes : [b s h] --> [s b h].
724
+ embeddings = embeddings.transpose(0, 1).contiguous()
725
+ # If the input flag for fp32 residual connection is set, convert for float.
726
+ if self.fp32_residual_connection:
727
+ embeddings = embeddings.float()
728
+ return embeddings
729
+
730
+
731
+ class ChatGLMModel(ChatGLMPreTrainedModel):
732
+ def __init__(self, config: ChatGLMConfig, device=None, empty_init=True):
733
+ super().__init__(config)
734
+ if empty_init:
735
+ init_method = skip_init
736
+ else:
737
+ init_method = default_init
738
+ init_kwargs = {}
739
+ if device is not None:
740
+ init_kwargs["device"] = device
741
+ self.embedding = init_method(Embedding, config, **init_kwargs)
742
+ self.num_layers = config.num_layers
743
+ self.multi_query_group_num = config.multi_query_group_num
744
+ self.kv_channels = config.kv_channels
745
+
746
+ # Rotary positional embeddings
747
+ self.seq_length = config.seq_length
748
+ rotary_dim = (
749
+ config.hidden_size // config.num_attention_heads if config.kv_channels is None else config.kv_channels
750
+ )
751
+
752
+ self.rotary_pos_emb = RotaryEmbedding(rotary_dim // 2, original_impl=config.original_rope, device=device,
753
+ dtype=config.torch_dtype)
754
+ self.encoder = init_method(GLMTransformer, config, **init_kwargs)
755
+ self.output_layer = init_method(nn.Linear, config.hidden_size, config.padded_vocab_size, bias=False,
756
+ dtype=config.torch_dtype, **init_kwargs)
757
+ self.pre_seq_len = config.pre_seq_len
758
+ self.prefix_projection = config.prefix_projection
759
+ if self.pre_seq_len is not None:
760
+ for param in self.parameters():
761
+ param.requires_grad = False
762
+ self.prefix_tokens = torch.arange(self.pre_seq_len).long()
763
+ self.prefix_encoder = PrefixEncoder(config)
764
+ self.dropout = torch.nn.Dropout(0.1)
765
+
766
+ def get_input_embeddings(self):
767
+ return self.embedding.word_embeddings
768
+
769
+ def get_prompt(self, batch_size, device, dtype=torch.half):
770
+ prefix_tokens = self.prefix_tokens.unsqueeze(0).expand(batch_size, -1).to(device)
771
+ past_key_values = self.prefix_encoder(prefix_tokens).type(dtype)
772
+ past_key_values = past_key_values.view(
773
+ batch_size,
774
+ self.pre_seq_len,
775
+ self.num_layers * 2,
776
+ self.multi_query_group_num,
777
+ self.kv_channels
778
+ )
779
+ # seq_len, b, nh, hidden_size
780
+ past_key_values = self.dropout(past_key_values)
781
+ past_key_values = past_key_values.permute([2, 1, 0, 3, 4]).split(2)
782
+ return past_key_values
783
+
784
+ def forward(
785
+ self,
786
+ input_ids,
787
+ position_ids: Optional[torch.Tensor] = None,
788
+ attention_mask: Optional[torch.BoolTensor] = None,
789
+ full_attention_mask: Optional[torch.BoolTensor] = None,
790
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
791
+ inputs_embeds: Optional[torch.Tensor] = None,
792
+ use_cache: Optional[bool] = None,
793
+ output_hidden_states: Optional[bool] = None,
794
+ return_dict: Optional[bool] = None,
795
+ ):
796
+ output_hidden_states = (
797
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
798
+ )
799
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
800
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
801
+
802
+ batch_size, seq_length = input_ids.shape
803
+
804
+ if inputs_embeds is None:
805
+ inputs_embeds = self.embedding(input_ids)
806
+
807
+ if self.pre_seq_len is not None:
808
+ if past_key_values is None:
809
+ past_key_values = self.get_prompt(batch_size=batch_size, device=input_ids.device,
810
+ dtype=inputs_embeds.dtype)
811
+ if attention_mask is not None:
812
+ attention_mask = torch.cat([attention_mask.new_ones((batch_size, self.pre_seq_len)),
813
+ attention_mask], dim=-1)
814
+
815
+ if full_attention_mask is None:
816
+ if (attention_mask is not None and not attention_mask.all()) or (past_key_values and seq_length != 1):
817
+ full_attention_mask = self.get_masks(input_ids, past_key_values, padding_mask=attention_mask)
818
+
819
+ # Rotary positional embeddings
820
+ rotary_pos_emb = self.rotary_pos_emb(self.seq_length)
821
+ if position_ids is not None:
822
+ rotary_pos_emb = rotary_pos_emb[position_ids]
823
+ else:
824
+ rotary_pos_emb = rotary_pos_emb[None, :seq_length]
825
+ rotary_pos_emb = rotary_pos_emb.transpose(0, 1).contiguous()
826
+
827
+ # Run encoder.
828
+ hidden_states, presents, all_hidden_states, all_self_attentions = self.encoder(
829
+ inputs_embeds, full_attention_mask, rotary_pos_emb=rotary_pos_emb,
830
+ kv_caches=past_key_values, use_cache=use_cache, output_hidden_states=output_hidden_states
831
+ )
832
+
833
+ if not return_dict:
834
+ return tuple(v for v in [hidden_states, presents, all_hidden_states, all_self_attentions] if v is not None)
835
+
836
+ return BaseModelOutputWithPast(
837
+ last_hidden_state=hidden_states,
838
+ past_key_values=presents,
839
+ hidden_states=all_hidden_states,
840
+ attentions=all_self_attentions,
841
+ )
842
+
843
+ def quantize(self, weight_bit_width: int):
844
+ from .quantization import quantize
845
+ quantize(self.encoder, weight_bit_width)
846
+ return self
847
+
848
+
849
+ class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel):
850
+ def __init__(self, config: ChatGLMConfig, empty_init=True, device=None):
851
+ super().__init__(config)
852
+
853
+ self.max_sequence_length = config.max_length
854
+ self.transformer = ChatGLMModel(config, empty_init=empty_init, device=device)
855
+ self.config = config
856
+ self.quantized = False
857
+
858
+ if self.config.quantization_bit:
859
+ self.quantize(self.config.quantization_bit, empty_init=True)
860
+
861
+ def _update_model_kwargs_for_generation(
862
+ self,
863
+ outputs: ModelOutput,
864
+ model_kwargs: Dict[str, Any],
865
+ is_encoder_decoder: bool = False,
866
+ standardize_cache_format: bool = False,
867
+ ) -> Dict[str, Any]:
868
+ # update past_key_values
869
+ model_kwargs["past_key_values"] = self._extract_past_from_model_output(
870
+ outputs, standardize_cache_format=standardize_cache_format
871
+ )
872
+
873
+ # update attention mask
874
+ if "attention_mask" in model_kwargs:
875
+ attention_mask = model_kwargs["attention_mask"]
876
+ model_kwargs["attention_mask"] = torch.cat(
877
+ [attention_mask, attention_mask.new_ones((attention_mask.shape[0], 1))], dim=-1
878
+ )
879
+
880
+ # update position ids
881
+ if "position_ids" in model_kwargs:
882
+ position_ids = model_kwargs["position_ids"]
883
+ new_position_id = position_ids[..., -1:].clone()
884
+ new_position_id += 1
885
+ model_kwargs["position_ids"] = torch.cat(
886
+ [position_ids, new_position_id], dim=-1
887
+ )
888
+
889
+ model_kwargs["is_first_forward"] = False
890
+ return model_kwargs
891
+
892
+ def prepare_inputs_for_generation(
893
+ self,
894
+ input_ids: torch.LongTensor,
895
+ past_key_values: Optional[torch.Tensor] = None,
896
+ attention_mask: Optional[torch.Tensor] = None,
897
+ position_ids: Optional[torch.Tensor] = None,
898
+ is_first_forward: bool = True,
899
+ **kwargs
900
+ ) -> dict:
901
+ # only last token for input_ids if past is not None
902
+ if position_ids is None:
903
+ position_ids = self.get_position_ids(input_ids, device=input_ids.device)
904
+ if not is_first_forward:
905
+ position_ids = position_ids[..., -1:]
906
+ input_ids = input_ids[:, -1:]
907
+ return {
908
+ "input_ids": input_ids,
909
+ "past_key_values": past_key_values,
910
+ "position_ids": position_ids,
911
+ "attention_mask": attention_mask,
912
+ "return_last_logit": True
913
+ }
914
+
915
+ def forward(
916
+ self,
917
+ input_ids: Optional[torch.Tensor] = None,
918
+ position_ids: Optional[torch.Tensor] = None,
919
+ attention_mask: Optional[torch.Tensor] = None,
920
+ past_key_values: Optional[Tuple[torch.FloatTensor]] = None,
921
+ inputs_embeds: Optional[torch.Tensor] = None,
922
+ labels: Optional[torch.Tensor] = None,
923
+ use_cache: Optional[bool] = None,
924
+ output_attentions: Optional[bool] = None,
925
+ output_hidden_states: Optional[bool] = None,
926
+ return_dict: Optional[bool] = None,
927
+ return_last_logit: Optional[bool] = False,
928
+ ):
929
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
930
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
931
+
932
+ transformer_outputs = self.transformer(
933
+ input_ids=input_ids,
934
+ position_ids=position_ids,
935
+ attention_mask=attention_mask,
936
+ past_key_values=past_key_values,
937
+ inputs_embeds=inputs_embeds,
938
+ use_cache=use_cache,
939
+ output_hidden_states=output_hidden_states,
940
+ return_dict=return_dict,
941
+ )
942
+
943
+ hidden_states = transformer_outputs[0]
944
+ if return_last_logit:
945
+ hidden_states = hidden_states[-1:]
946
+ lm_logits = self.transformer.output_layer(hidden_states)
947
+ lm_logits = lm_logits.transpose(0, 1).contiguous()
948
+
949
+ loss = None
950
+ if labels is not None:
951
+ lm_logits = lm_logits.to(torch.float32)
952
+
953
+ # Shift so that tokens < n predict n
954
+ shift_logits = lm_logits[..., :-1, :].contiguous()
955
+ shift_labels = labels[..., 1:].contiguous()
956
+ # Flatten the tokens
957
+ loss_fct = CrossEntropyLoss(ignore_index=-100)
958
+ loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
959
+
960
+ lm_logits = lm_logits.to(hidden_states.dtype)
961
+ loss = loss.to(hidden_states.dtype)
962
+
963
+ if not return_dict:
964
+ output = (lm_logits,) + transformer_outputs[1:]
965
+ return ((loss,) + output) if loss is not None else output
966
+
967
+ return CausalLMOutputWithPast(
968
+ loss=loss,
969
+ logits=lm_logits,
970
+ past_key_values=transformer_outputs.past_key_values,
971
+ hidden_states=transformer_outputs.hidden_states,
972
+ attentions=transformer_outputs.attentions,
973
+ )
974
+
975
+ @staticmethod
976
+ def _reorder_cache(
977
+ past: Tuple[Tuple[torch.Tensor, torch.Tensor], ...], beam_idx: torch.LongTensor
978
+ ) -> Tuple[Tuple[torch.Tensor, torch.Tensor], ...]:
979
+ """
980
+ This function is used to re-order the `past_key_values` cache if [`~PreTrainedModel.beam_search`] or
981
+ [`~PreTrainedModel.beam_sample`] is called. This is required to match `past_key_values` with the correct
982
+ beam_idx at every generation step.
983
+
984
+ Output shares the same memory storage as `past`.
985
+ """
986
+ return tuple(
987
+ (
988
+ layer_past[0].index_select(1, beam_idx.to(layer_past[0].device)),
989
+ layer_past[1].index_select(1, beam_idx.to(layer_past[1].device)),
990
+ )
991
+ for layer_past in past
992
+ )
993
+
994
+ def process_response(self, response):
995
+ response = response.strip()
996
+ response = response.replace("[[训练时间]]", "2023年")
997
+ return response
998
+
999
+ def build_inputs(self, tokenizer, query: str, history: List[Tuple[str, str]] = None):
1000
+ prompt = tokenizer.build_prompt(query, history=history)
1001
+ inputs = tokenizer([prompt], return_tensors="pt")
1002
+ inputs = inputs.to(self.device)
1003
+ return inputs
1004
+
1005
+ def build_stream_inputs(self, tokenizer, query: str, history: List[Tuple[str, str]] = None):
1006
+ if history:
1007
+ prompt = "\n\n[Round {}]\n\n问:{}\n\n答:".format(len(history) + 1, query)
1008
+ input_ids = tokenizer.encode(prompt, add_special_tokens=False)
1009
+ input_ids = input_ids[1:]
1010
+ inputs = tokenizer.batch_encode_plus([(input_ids, None)], return_tensors="pt", add_special_tokens=False)
1011
+ else:
1012
+ prompt = "[Round {}]\n\n问:{}\n\n答:".format(len(history) + 1, query)
1013
+ inputs = tokenizer([prompt], return_tensors="pt")
1014
+ inputs = inputs.to(self.device)
1015
+ return inputs
1016
+
1017
+ @torch.inference_mode()
1018
+ def chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 8192, num_beams=1,
1019
+ do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, **kwargs):
1020
+ if history is None:
1021
+ history = []
1022
+ if logits_processor is None:
1023
+ logits_processor = LogitsProcessorList()
1024
+ logits_processor.append(InvalidScoreLogitsProcessor())
1025
+ gen_kwargs = {"max_length": max_length, "num_beams": num_beams, "do_sample": do_sample, "top_p": top_p,
1026
+ "temperature": temperature, "logits_processor": logits_processor, **kwargs}
1027
+ inputs = self.build_inputs(tokenizer, query, history=history)
1028
+ outputs = self.generate(**inputs, **gen_kwargs)
1029
+ outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):]
1030
+ response = tokenizer.decode(outputs)
1031
+ response = self.process_response(response)
1032
+ history = history + [(query, response)]
1033
+ return response, history
1034
+
1035
+ @torch.inference_mode()
1036
+ def stream_chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, past_key_values=None,
1037
+ max_length: int = 8192, do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None,
1038
+ return_past_key_values=False, **kwargs):
1039
+ if history is None:
1040
+ history = []
1041
+ if logits_processor is None:
1042
+ logits_processor = LogitsProcessorList()
1043
+ logits_processor.append(InvalidScoreLogitsProcessor())
1044
+ gen_kwargs = {"max_length": max_length, "do_sample": do_sample, "top_p": top_p,
1045
+ "temperature": temperature, "logits_processor": logits_processor, **kwargs}
1046
+ if past_key_values is None and not return_past_key_values:
1047
+ inputs = self.build_inputs(tokenizer, query, history=history)
1048
+ else:
1049
+ inputs = self.build_stream_inputs(tokenizer, query, history=history)
1050
+ if past_key_values is not None:
1051
+ past_length = past_key_values[0][0].shape[0]
1052
+ if self.transformer.pre_seq_len is not None:
1053
+ past_length -= self.transformer.pre_seq_len
1054
+ inputs.position_ids += past_length
1055
+ attention_mask = inputs.attention_mask
1056
+ attention_mask = torch.cat((attention_mask.new_ones(1, past_length), attention_mask), dim=1)
1057
+ inputs['attention_mask'] = attention_mask
1058
+ for outputs in self.stream_generate(**inputs, past_key_values=past_key_values,
1059
+ return_past_key_values=return_past_key_values, **gen_kwargs):
1060
+ if return_past_key_values:
1061
+ outputs, past_key_values = outputs
1062
+ outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):]
1063
+ response = tokenizer.decode(outputs)
1064
+ if response and response[-1] != "�":
1065
+ response = self.process_response(response)
1066
+ new_history = history + [(query, response)]
1067
+ if return_past_key_values:
1068
+ yield response, new_history, past_key_values
1069
+ else:
1070
+ yield response, new_history
1071
+
1072
+ @torch.inference_mode()
1073
+ def stream_generate(
1074
+ self,
1075
+ input_ids,
1076
+ generation_config: Optional[GenerationConfig] = None,
1077
+ logits_processor: Optional[LogitsProcessorList] = None,
1078
+ stopping_criteria: Optional[StoppingCriteriaList] = None,
1079
+ prefix_allowed_tokens_fn: Optional[Callable[[int, torch.Tensor], List[int]]] = None,
1080
+ return_past_key_values=False,
1081
+ **kwargs,
1082
+ ):
1083
+ batch_size, input_ids_seq_length = input_ids.shape[0], input_ids.shape[-1]
1084
+
1085
+ if generation_config is None:
1086
+ generation_config = self.generation_config
1087
+ generation_config = copy.deepcopy(generation_config)
1088
+ model_kwargs = generation_config.update(**kwargs)
1089
+ bos_token_id, eos_token_id = generation_config.bos_token_id, generation_config.eos_token_id
1090
+
1091
+ if isinstance(eos_token_id, int):
1092
+ eos_token_id = [eos_token_id]
1093
+
1094
+ has_default_max_length = kwargs.get("max_length") is None and generation_config.max_length is not None
1095
+ if has_default_max_length and generation_config.max_new_tokens is None:
1096
+ warnings.warn(
1097
+ f"Using `max_length`'s default ({generation_config.max_length}) to control the generation length. "
1098
+ "This behaviour is deprecated and will be removed from the config in v5 of Transformers -- we"
1099
+ " recommend using `max_new_tokens` to control the maximum length of the generation.",
1100
+ UserWarning,
1101
+ )
1102
+ elif generation_config.max_new_tokens is not None:
1103
+ generation_config.max_length = generation_config.max_new_tokens + input_ids_seq_length
1104
+ if not has_default_max_length:
1105
+ logger.warn(
1106
+ f"Both `max_new_tokens` (={generation_config.max_new_tokens}) and `max_length`(="
1107
+ f"{generation_config.max_length}) seem to have been set. `max_new_tokens` will take precedence. "
1108
+ "Please refer to the documentation for more information. "
1109
+ "(https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)",
1110
+ UserWarning,
1111
+ )
1112
+
1113
+ if input_ids_seq_length >= generation_config.max_length:
1114
+ input_ids_string = "decoder_input_ids" if self.config.is_encoder_decoder else "input_ids"
1115
+ logger.warning(
1116
+ f"Input length of {input_ids_string} is {input_ids_seq_length}, but `max_length` is set to"
1117
+ f" {generation_config.max_length}. This can lead to unexpected behavior. You should consider"
1118
+ " increasing `max_new_tokens`."
1119
+ )
1120
+
1121
+ # 2. Set generation parameters if not already defined
1122
+ logits_processor = logits_processor if logits_processor is not None else LogitsProcessorList()
1123
+ stopping_criteria = stopping_criteria if stopping_criteria is not None else StoppingCriteriaList()
1124
+
1125
+ logits_processor = self._get_logits_processor(
1126
+ generation_config=generation_config,
1127
+ input_ids_seq_length=input_ids_seq_length,
1128
+ encoder_input_ids=input_ids,
1129
+ prefix_allowed_tokens_fn=prefix_allowed_tokens_fn,
1130
+ logits_processor=logits_processor,
1131
+ )
1132
+
1133
+ stopping_criteria = self._get_stopping_criteria(
1134
+ generation_config=generation_config, stopping_criteria=stopping_criteria
1135
+ )
1136
+ logits_warper = self._get_logits_warper(generation_config)
1137
+
1138
+ unfinished_sequences = input_ids.new(input_ids.shape[0]).fill_(1)
1139
+ scores = None
1140
+ while True:
1141
+ model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)
1142
+ # forward pass to get next token
1143
+ outputs = self(
1144
+ **model_inputs,
1145
+ return_dict=True,
1146
+ output_attentions=False,
1147
+ output_hidden_states=False,
1148
+ )
1149
+
1150
+ next_token_logits = outputs.logits[:, -1, :]
1151
+
1152
+ # pre-process distribution
1153
+ next_token_scores = logits_processor(input_ids, next_token_logits)
1154
+ next_token_scores = logits_warper(input_ids, next_token_scores)
1155
+
1156
+ # sample
1157
+ probs = nn.functional.softmax(next_token_scores, dim=-1)
1158
+ if generation_config.do_sample:
1159
+ next_tokens = torch.multinomial(probs, num_samples=1).squeeze(1)
1160
+ else:
1161
+ next_tokens = torch.argmax(probs, dim=-1)
1162
+
1163
+ # update generated ids, model inputs, and length for next step
1164
+ input_ids = torch.cat([input_ids, next_tokens[:, None]], dim=-1)
1165
+ model_kwargs = self._update_model_kwargs_for_generation(
1166
+ outputs, model_kwargs, is_encoder_decoder=self.config.is_encoder_decoder
1167
+ )
1168
+ unfinished_sequences = unfinished_sequences.mul((sum(next_tokens != i for i in eos_token_id)).long())
1169
+ if return_past_key_values:
1170
+ yield input_ids, outputs.past_key_values
1171
+ else:
1172
+ yield input_ids
1173
+ # stop when each sentence is finished, or if we exceed the maximum length
1174
+ if unfinished_sequences.max() == 0 or stopping_criteria(input_ids, scores):
1175
+ break
1176
+
1177
+ def quantize(self, bits: int, empty_init=False, device=None, **kwargs):
1178
+ if bits == 0:
1179
+ return
1180
+
1181
+ from .quantization import quantize
1182
+
1183
+ if self.quantized:
1184
+ logger.info("Already quantized.")
1185
+ return self
1186
+
1187
+ self.quantized = True
1188
+
1189
+ self.config.quantization_bit = bits
1190
+
1191
+ self.transformer.encoder = quantize(self.transformer.encoder, bits, empty_init=empty_init, device=device,
1192
+ **kwargs)
1193
+ return self
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:10d05dee8e263551a2a275ff56057ace5864702053834527eea559d4aa5f1553
3
+ size 14681391
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:89243417f3dbd2ff1a4262cd5101ec58a779bc3b5693aa26687de571babc0495
3
+ size 7340861
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/quantization.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from torch.nn import Linear
2
+ from torch.nn.parameter import Parameter
3
+
4
+ import bz2
5
+ import torch
6
+ import base64
7
+ import ctypes
8
+ from transformers.utils import logging
9
+
10
+ from typing import List
11
+ from functools import partial
12
+
13
+ logger = logging.get_logger(__name__)
14
+
15
+ try:
16
+ from cpm_kernels.kernels.base import LazyKernelCModule, KernelFunction, round_up
17
+
18
+ class Kernel:
19
+ def __init__(self, code: bytes, function_names: List[str]):
20
+ self.code = code
21
+ self._function_names = function_names
22
+ self._cmodule = LazyKernelCModule(self.code)
23
+
24
+ for name in self._function_names:
25
+ setattr(self, name, KernelFunction(self._cmodule, name))
26
+
27
+ quantization_code = "$QlpoOTFBWSZTWU9yuJUAQHN//////////f/n/8/n///n//bt4dTidcVx8X3V9FV/92/v4B7/AD5FBQFAAAChSgKpFCFAFVSigUAAAEKhSgUUqgFBKigqVREQAABQBQIANDTTIGI00BkZBkNGE0A0BkBkGQGRkaNAaAGQNBoGgDIAAYIGTI0DQAQAaGmmQMRpoDIyDIaMJoBoDIDIMgMjI0aA0AMgaDQNAGQAAwQMmRoGgAgA0NNMgYjTQGRkGQ0YTQDQGQGQZAZGRo0BoAZA0GgaAMgABggZMjQNABABoaaZAxGmgMjIMhowmgGgMgMgyAyMjRoDQAyBoNA0AZAADBAyZGgaAAmqU1NEgJqnptU/Sn4jRR6J6epk2pqb1Q/SgAPUGgyNNGjQ2SBpoAZAAGg0NB6mgDIAAAAA2oaApSREBNAARhGiYEaEwU8pvImlP0k2aam1GaGqbFNM1MHpTwmkepmyU9R6nqPKekHqNNPUxNGhp6n6p6QaZ6o9TG1GMqcoV9ly6nRanHlq6zPNbnGZNi6HSug+2nPiZ13XcnFYZW+45W11CumhzYhchOJ2GLLV1OBjBjGf4TptOddTSOcVxhqYZMYwZXZZY00zI1paX5X9J+b+f4e+x43RXSxXPOdquiGpduatGyXneN696M9t4HU2eR5XX/kPhP261NTx3JO1Ow7LyuDmeo9a7d351T1ZxnvnrvYnrXv/hXxPCeuYx2XsNmO003eg9J3Z6U7b23meJ4ri01OdzTk9BNO96brz+qT5nuvvH3ds/G+m/JcG/F2XYuhXlvO+jP7U3XgrzPN/lr8Sf1n6j4j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JFOFCQT3K4lQ"
28
+
29
+ kernels = Kernel(
30
+ bz2.decompress(base64.b64decode(quantization_code)),
31
+ [
32
+ "int4WeightCompression",
33
+ "int4WeightExtractionFloat",
34
+ "int4WeightExtractionHalf",
35
+ "int8WeightExtractionFloat",
36
+ "int8WeightExtractionHalf",
37
+ ],
38
+ )
39
+ except Exception as exception:
40
+ kernels = None
41
+ logger.warning("Failed to load cpm_kernels:" + str(exception))
42
+
43
+
44
+ class W8A16Linear(torch.autograd.Function):
45
+ @staticmethod
46
+ def forward(ctx, inp: torch.Tensor, quant_w: torch.Tensor, scale_w: torch.Tensor, weight_bit_width):
47
+ ctx.inp_shape = inp.size()
48
+ ctx.weight_bit_width = weight_bit_width
49
+ out_features = quant_w.size(0)
50
+ inp = inp.contiguous().view(-1, inp.size(-1))
51
+ weight = extract_weight_to_half(quant_w, scale_w, weight_bit_width)
52
+ ctx.weight_shape = weight.size()
53
+ output = inp.mm(weight.t())
54
+ ctx.save_for_backward(inp, quant_w, scale_w)
55
+ return output.view(*(ctx.inp_shape[:-1] + (out_features,)))
56
+
57
+ @staticmethod
58
+ def backward(ctx, grad_output: torch.Tensor):
59
+ inp, quant_w, scale_w = ctx.saved_tensors
60
+ weight = extract_weight_to_half(quant_w, scale_w, ctx.weight_bit_width)
61
+ grad_output = grad_output.contiguous().view(-1, weight.size(0))
62
+ grad_input = grad_output.mm(weight)
63
+ grad_weight = grad_output.t().mm(inp)
64
+ return grad_input.view(ctx.inp_shape), grad_weight.view(ctx.weight_shape), None, None
65
+
66
+
67
+ def compress_int4_weight(weight: torch.Tensor): # (n, m)
68
+ with torch.cuda.device(weight.device):
69
+ n, m = weight.size(0), weight.size(1)
70
+ assert m % 2 == 0
71
+ m = m // 2
72
+ out = torch.empty(n, m, dtype=torch.int8, device="cuda")
73
+ stream = torch.cuda.current_stream()
74
+
75
+ gridDim = (n, 1, 1)
76
+ blockDim = (min(round_up(m, 32), 1024), 1, 1)
77
+
78
+ kernels.int4WeightCompression(
79
+ gridDim,
80
+ blockDim,
81
+ 0,
82
+ stream,
83
+ [ctypes.c_void_p(weight.data_ptr()), ctypes.c_void_p(out.data_ptr()), ctypes.c_int32(n), ctypes.c_int32(m)],
84
+ )
85
+ return out
86
+
87
+
88
+ def extract_weight_to_half(weight: torch.Tensor, scale_list: torch.Tensor, source_bit_width: int):
89
+ assert scale_list.dtype in [torch.half, torch.bfloat16]
90
+ assert weight.dtype in [torch.int8]
91
+ if source_bit_width == 8:
92
+ return weight.to(scale_list.dtype) * scale_list[:, None]
93
+ elif source_bit_width == 4:
94
+ func = (
95
+ kernels.int4WeightExtractionHalf if scale_list.dtype == torch.half else kernels.int4WeightExtractionBFloat16
96
+ )
97
+ else:
98
+ assert False, "Unsupported bit-width"
99
+
100
+ with torch.cuda.device(weight.device):
101
+ n, m = weight.size(0), weight.size(1)
102
+ out = torch.empty(n, m * (8 // source_bit_width), dtype=scale_list.dtype, device="cuda")
103
+ stream = torch.cuda.current_stream()
104
+
105
+ gridDim = (n, 1, 1)
106
+ blockDim = (min(round_up(m, 32), 1024), 1, 1)
107
+
108
+ func(
109
+ gridDim,
110
+ blockDim,
111
+ 0,
112
+ stream,
113
+ [
114
+ ctypes.c_void_p(weight.data_ptr()),
115
+ ctypes.c_void_p(scale_list.data_ptr()),
116
+ ctypes.c_void_p(out.data_ptr()),
117
+ ctypes.c_int32(n),
118
+ ctypes.c_int32(m),
119
+ ],
120
+ )
121
+ return out
122
+
123
+
124
+ class QuantizedLinear(torch.nn.Module):
125
+ def __init__(self, weight_bit_width: int, weight, bias=None, device="cpu", dtype=None, empty_init=False, *args,
126
+ **kwargs):
127
+ super().__init__()
128
+ self.weight_bit_width = weight_bit_width
129
+
130
+ shape = weight.shape
131
+
132
+ if weight is None or empty_init:
133
+ self.weight = torch.empty(shape[0], shape[1] * weight_bit_width // 8, dtype=torch.int8, device=device)
134
+ self.weight_scale = torch.empty(shape[0], dtype=dtype, device=device)
135
+ else:
136
+ self.weight_scale = weight.abs().max(dim=-1).values / ((2 ** (weight_bit_width - 1)) - 1)
137
+ self.weight = torch.round(weight / self.weight_scale[:, None]).to(torch.int8)
138
+ if weight_bit_width == 4:
139
+ self.weight = compress_int4_weight(self.weight)
140
+
141
+ self.weight = Parameter(self.weight.to(device), requires_grad=False)
142
+ self.weight_scale = Parameter(self.weight_scale.to(device), requires_grad=False)
143
+ self.bias = Parameter(bias.to(device), requires_grad=False) if bias is not None else None
144
+
145
+ def forward(self, input):
146
+ output = W8A16Linear.apply(input, self.weight, self.weight_scale, self.weight_bit_width)
147
+ if self.bias is not None:
148
+ output = output + self.bias
149
+ return output
150
+
151
+
152
+ def quantize(model, weight_bit_width, empty_init=False, device=None):
153
+ """Replace fp16 linear with quantized linear"""
154
+ for layer in model.layers:
155
+ layer.self_attention.query_key_value = QuantizedLinear(
156
+ weight_bit_width=weight_bit_width,
157
+ weight=layer.self_attention.query_key_value.weight.to(torch.cuda.current_device()),
158
+ bias=layer.self_attention.query_key_value.bias,
159
+ dtype=layer.self_attention.query_key_value.weight.dtype,
160
+ device=layer.self_attention.query_key_value.weight.device if device is None else device,
161
+ empty_init=empty_init
162
+ )
163
+ layer.self_attention.dense = QuantizedLinear(
164
+ weight_bit_width=weight_bit_width,
165
+ weight=layer.self_attention.dense.weight.to(torch.cuda.current_device()),
166
+ bias=layer.self_attention.dense.bias,
167
+ dtype=layer.self_attention.dense.weight.dtype,
168
+ device=layer.self_attention.dense.weight.device if device is None else device,
169
+ empty_init=empty_init
170
+ )
171
+ layer.mlp.dense_h_to_4h = QuantizedLinear(
172
+ weight_bit_width=weight_bit_width,
173
+ weight=layer.mlp.dense_h_to_4h.weight.to(torch.cuda.current_device()),
174
+ bias=layer.mlp.dense_h_to_4h.bias,
175
+ dtype=layer.mlp.dense_h_to_4h.weight.dtype,
176
+ device=layer.mlp.dense_h_to_4h.weight.device if device is None else device,
177
+ empty_init=empty_init
178
+ )
179
+ layer.mlp.dense_4h_to_h = QuantizedLinear(
180
+ weight_bit_width=weight_bit_width,
181
+ weight=layer.mlp.dense_4h_to_h.weight.to(torch.cuda.current_device()),
182
+ bias=layer.mlp.dense_4h_to_h.bias,
183
+ dtype=layer.mlp.dense_4h_to_h.weight.dtype,
184
+ device=layer.mlp.dense_4h_to_h.weight.device if device is None else device,
185
+ empty_init=empty_init
186
+ )
187
+
188
+ return model
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a2d7a10a8849129b5348701687171573d3947006905411832dbf4263eb6506bb
3
+ size 14575
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:789a1605f05260342a605be992efe3dec445d76b75c62bdef618345fc0105cc0
3
+ size 627
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {}
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/tokenization_chatglm.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ from typing import List, Optional, Union, Dict
4
+ from sentencepiece import SentencePieceProcessor
5
+ from transformers import PreTrainedTokenizer
6
+ from transformers.utils import logging, PaddingStrategy
7
+ from transformers.tokenization_utils_base import EncodedInput, BatchEncoding
8
+
9
+
10
+ class SPTokenizer:
11
+ def __init__(self, model_path: str):
12
+ # reload tokenizer
13
+ assert os.path.isfile(model_path), model_path
14
+ self.sp_model = SentencePieceProcessor(model_file=model_path)
15
+
16
+ # BOS / EOS token IDs
17
+ self.n_words: int = self.sp_model.vocab_size()
18
+ self.bos_id: int = self.sp_model.bos_id()
19
+ self.eos_id: int = self.sp_model.eos_id()
20
+ self.pad_id: int = self.sp_model.unk_id()
21
+ assert self.sp_model.vocab_size() == self.sp_model.get_piece_size()
22
+
23
+ special_tokens = ["[MASK]", "[gMASK]", "[sMASK]", "sop", "eop"]
24
+ self.special_tokens = {}
25
+ self.index_special_tokens = {}
26
+ for token in special_tokens:
27
+ self.special_tokens[token] = self.n_words
28
+ self.index_special_tokens[self.n_words] = token
29
+ self.n_words += 1
30
+
31
+ def tokenize(self, s: str):
32
+ return self.sp_model.EncodeAsPieces(s)
33
+
34
+ def encode(self, s: str, bos: bool = False, eos: bool = False) -> List[int]:
35
+ assert type(s) is str
36
+ t = self.sp_model.encode(s)
37
+ if bos:
38
+ t = [self.bos_id] + t
39
+ if eos:
40
+ t = t + [self.eos_id]
41
+ return t
42
+
43
+ def decode(self, t: List[int]) -> str:
44
+ return self.sp_model.decode(t)
45
+
46
+ def decode_tokens(self, tokens: List[str]) -> str:
47
+ text = self.sp_model.DecodePieces(tokens)
48
+ return text
49
+
50
+ def convert_token_to_id(self, token):
51
+ """ Converts a token (str) in an id using the vocab. """
52
+ if token in self.special_tokens:
53
+ return self.special_tokens[token]
54
+ return self.sp_model.PieceToId(token)
55
+
56
+ def convert_id_to_token(self, index):
57
+ """Converts an index (integer) in a token (str) using the vocab."""
58
+ if index in self.index_special_tokens or index in [self.eos_id, self.bos_id, self.pad_id] or index < 0:
59
+ return ""
60
+ return self.sp_model.IdToPiece(index)
61
+
62
+
63
+ class ChatGLMTokenizer(PreTrainedTokenizer):
64
+ vocab_files_names = {"vocab_file": "tokenizer.model"}
65
+
66
+ model_input_names = ["input_ids", "attention_mask", "position_ids"]
67
+
68
+ def __init__(self, vocab_file, padding_side="left", clean_up_tokenization_spaces=False, **kwargs):
69
+ super().__init__(padding_side=padding_side, clean_up_tokenization_spaces=clean_up_tokenization_spaces, **kwargs)
70
+ self.name = "GLMTokenizer"
71
+
72
+ self.vocab_file = vocab_file
73
+ self.tokenizer = SPTokenizer(vocab_file)
74
+ self.special_tokens = {
75
+ "<bos>": self.tokenizer.bos_id,
76
+ "<eos>": self.tokenizer.eos_id,
77
+ "<pad>": self.tokenizer.pad_id
78
+ }
79
+
80
+ def get_command(self, token):
81
+ if token in self.special_tokens:
82
+ return self.special_tokens[token]
83
+ assert token in self.tokenizer.special_tokens, f"{token} is not a special token for {self.name}"
84
+ return self.tokenizer.special_tokens[token]
85
+
86
+ @property
87
+ def unk_token(self) -> str:
88
+ return "<unk>"
89
+
90
+ @property
91
+ def pad_token(self) -> str:
92
+ return "<unk>"
93
+
94
+ @property
95
+ def pad_token_id(self):
96
+ return self.get_command("<pad>")
97
+
98
+ @property
99
+ def eos_token(self) -> str:
100
+ return "</s>"
101
+
102
+ @property
103
+ def eos_token_id(self):
104
+ return self.get_command("<eos>")
105
+
106
+ @property
107
+ def vocab_size(self):
108
+ return self.tokenizer.n_words
109
+
110
+ def get_vocab(self):
111
+ """ Returns vocab as a dict """
112
+ vocab = {self._convert_id_to_token(i): i for i in range(self.vocab_size)}
113
+ vocab.update(self.added_tokens_encoder)
114
+ return vocab
115
+
116
+ def _tokenize(self, text, **kwargs):
117
+ return self.tokenizer.tokenize(text)
118
+
119
+ def _convert_token_to_id(self, token):
120
+ """ Converts a token (str) in an id using the vocab. """
121
+ return self.tokenizer.convert_token_to_id(token)
122
+
123
+ def _convert_id_to_token(self, index):
124
+ """Converts an index (integer) in a token (str) using the vocab."""
125
+ return self.tokenizer.convert_id_to_token(index)
126
+
127
+ def convert_tokens_to_string(self, tokens: List[str]) -> str:
128
+ return self.tokenizer.decode_tokens(tokens)
129
+
130
+ def save_vocabulary(self, save_directory, filename_prefix=None):
131
+ """
132
+ Save the vocabulary and special tokens file to a directory.
133
+
134
+ Args:
135
+ save_directory (`str`):
136
+ The directory in which to save the vocabulary.
137
+ filename_prefix (`str`, *optional*):
138
+ An optional prefix to add to the named of the saved files.
139
+
140
+ Returns:
141
+ `Tuple(str)`: Paths to the files saved.
142
+ """
143
+ if os.path.isdir(save_directory):
144
+ vocab_file = os.path.join(
145
+ save_directory, self.vocab_files_names["vocab_file"]
146
+ )
147
+ else:
148
+ vocab_file = save_directory
149
+
150
+ with open(self.vocab_file, 'rb') as fin:
151
+ proto_str = fin.read()
152
+
153
+ with open(vocab_file, "wb") as writer:
154
+ writer.write(proto_str)
155
+
156
+ return (vocab_file,)
157
+
158
+ def get_prefix_tokens(self):
159
+ prefix_tokens = [self.get_command("[gMASK]"), self.get_command("sop")]
160
+ return prefix_tokens
161
+
162
+ def build_prompt(self, query, history=None):
163
+ if history is None:
164
+ history = []
165
+ prompt = ""
166
+ for i, (old_query, response) in enumerate(history):
167
+ prompt += "[Round {}]\n\n问:{}\n\n答:{}\n\n".format(i + 1, old_query, response)
168
+ prompt += "[Round {}]\n\n问:{}\n\n答:".format(len(history) + 1, query)
169
+ return prompt
170
+
171
+ def build_inputs_with_special_tokens(
172
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
173
+ ) -> List[int]:
174
+ """
175
+ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
176
+ adding special tokens. A BERT sequence has the following format:
177
+
178
+ - single sequence: `[CLS] X [SEP]`
179
+ - pair of sequences: `[CLS] A [SEP] B [SEP]`
180
+
181
+ Args:
182
+ token_ids_0 (`List[int]`):
183
+ List of IDs to which the special tokens will be added.
184
+ token_ids_1 (`List[int]`, *optional*):
185
+ Optional second list of IDs for sequence pairs.
186
+
187
+ Returns:
188
+ `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
189
+ """
190
+ prefix_tokens = self.get_prefix_tokens()
191
+ token_ids_0 = prefix_tokens + token_ids_0
192
+ if token_ids_1 is not None:
193
+ token_ids_0 = token_ids_0 + token_ids_1 + [self.get_command("<eos>")]
194
+ return token_ids_0
195
+
196
+ def _pad(
197
+ self,
198
+ encoded_inputs: Union[Dict[str, EncodedInput], BatchEncoding],
199
+ max_length: Optional[int] = None,
200
+ padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
201
+ pad_to_multiple_of: Optional[int] = None,
202
+ return_attention_mask: Optional[bool] = None,
203
+ ) -> dict:
204
+ """
205
+ Pad encoded inputs (on left/right and up to predefined length or max length in the batch)
206
+
207
+ Args:
208
+ encoded_inputs:
209
+ Dictionary of tokenized inputs (`List[int]`) or batch of tokenized inputs (`List[List[int]]`).
210
+ max_length: maximum length of the returned list and optionally padding length (see below).
211
+ Will truncate by taking into account the special tokens.
212
+ padding_strategy: PaddingStrategy to use for padding.
213
+
214
+ - PaddingStrategy.LONGEST Pad to the longest sequence in the batch
215
+ - PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
216
+ - PaddingStrategy.DO_NOT_PAD: Do not pad
217
+ The tokenizer padding sides are defined in self.padding_side:
218
+
219
+ - 'left': pads on the left of the sequences
220
+ - 'right': pads on the right of the sequences
221
+ pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
222
+ This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
223
+ `>= 7.5` (Volta).
224
+ return_attention_mask:
225
+ (optional) Set to False to avoid returning attention mask (default: set to model specifics)
226
+ """
227
+ # Load from model defaults
228
+ assert self.padding_side == "left"
229
+
230
+ required_input = encoded_inputs[self.model_input_names[0]]
231
+ seq_length = len(required_input)
232
+
233
+ if padding_strategy == PaddingStrategy.LONGEST:
234
+ max_length = len(required_input)
235
+
236
+ if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
237
+ max_length = ((max_length // pad_to_multiple_of) + 1) * pad_to_multiple_of
238
+
239
+ needs_to_be_padded = padding_strategy != PaddingStrategy.DO_NOT_PAD and len(required_input) != max_length
240
+
241
+ # Initialize attention mask if not present.
242
+ if "attention_mask" not in encoded_inputs:
243
+ encoded_inputs["attention_mask"] = [1] * seq_length
244
+
245
+ if "position_ids" not in encoded_inputs:
246
+ encoded_inputs["position_ids"] = list(range(seq_length))
247
+
248
+ if needs_to_be_padded:
249
+ difference = max_length - len(required_input)
250
+
251
+ if "attention_mask" in encoded_inputs:
252
+ encoded_inputs["attention_mask"] = [0] * difference + encoded_inputs["attention_mask"]
253
+ if "position_ids" in encoded_inputs:
254
+ encoded_inputs["position_ids"] = [0] * difference + encoded_inputs["position_ids"]
255
+ encoded_inputs[self.model_input_names[0]] = [self.pad_token_id] * difference + required_input
256
+
257
+ return encoded_inputs
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7dc4c393423b76e4373e5157ddc34803a0189ba96b21ddbb40269d31468a6f2
3
+ size 1018370
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoTokenizer": [
4
+ "tokenization_chatglm.ChatGLMTokenizer",
5
+ null
6
+ ]
7
+ },
8
+ "clean_up_tokenization_spaces": false,
9
+ "do_lower_case": false,
10
+ "model_max_length": 1000000000000000019884624838656,
11
+ "padding_side": "left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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 13.37419894120925,
5
+ "global_step": 3000,
6
+ "is_hyper_param_search": false,
7
+ "is_local_process_zero": true,
8
+ "is_world_process_zero": true,
9
+ "log_history": [
10
+ {
11
+ "epoch": 0.04,
12
+ "learning_rate": 0.019933333333333334,
13
+ "loss": 1.811,
14
+ "step": 10
15
+ },
16
+ {
17
+ "epoch": 0.09,
18
+ "learning_rate": 0.019866666666666668,
19
+ "loss": 1.2846,
20
+ "step": 20
21
+ },
22
+ {
23
+ "epoch": 0.13,
24
+ "learning_rate": 0.0198,
25
+ "loss": 1.1671,
26
+ "step": 30
27
+ },
28
+ {
29
+ "epoch": 0.18,
30
+ "learning_rate": 0.019733333333333335,
31
+ "loss": 0.9238,
32
+ "step": 40
33
+ },
34
+ {
35
+ "epoch": 0.22,
36
+ "learning_rate": 0.019666666666666666,
37
+ "loss": 0.832,
38
+ "step": 50
39
+ },
40
+ {
41
+ "epoch": 0.27,
42
+ "learning_rate": 0.0196,
43
+ "loss": 0.7667,
44
+ "step": 60
45
+ },
46
+ {
47
+ "epoch": 0.31,
48
+ "learning_rate": 0.019533333333333333,
49
+ "loss": 0.5746,
50
+ "step": 70
51
+ },
52
+ {
53
+ "epoch": 0.36,
54
+ "learning_rate": 0.019466666666666667,
55
+ "loss": 0.6013,
56
+ "step": 80
57
+ },
58
+ {
59
+ "epoch": 0.4,
60
+ "learning_rate": 0.0194,
61
+ "loss": 0.622,
62
+ "step": 90
63
+ },
64
+ {
65
+ "epoch": 0.45,
66
+ "learning_rate": 0.019333333333333334,
67
+ "loss": 0.5471,
68
+ "step": 100
69
+ },
70
+ {
71
+ "epoch": 0.49,
72
+ "learning_rate": 0.019266666666666668,
73
+ "loss": 0.5042,
74
+ "step": 110
75
+ },
76
+ {
77
+ "epoch": 0.53,
78
+ "learning_rate": 0.0192,
79
+ "loss": 0.48,
80
+ "step": 120
81
+ },
82
+ {
83
+ "epoch": 0.58,
84
+ "learning_rate": 0.019133333333333332,
85
+ "loss": 0.4302,
86
+ "step": 130
87
+ },
88
+ {
89
+ "epoch": 0.62,
90
+ "learning_rate": 0.01906666666666667,
91
+ "loss": 0.4385,
92
+ "step": 140
93
+ },
94
+ {
95
+ "epoch": 0.67,
96
+ "learning_rate": 0.019,
97
+ "loss": 0.4081,
98
+ "step": 150
99
+ },
100
+ {
101
+ "epoch": 0.71,
102
+ "learning_rate": 0.018933333333333333,
103
+ "loss": 0.3896,
104
+ "step": 160
105
+ },
106
+ {
107
+ "epoch": 0.76,
108
+ "learning_rate": 0.018866666666666667,
109
+ "loss": 0.4021,
110
+ "step": 170
111
+ },
112
+ {
113
+ "epoch": 0.8,
114
+ "learning_rate": 0.0188,
115
+ "loss": 0.3946,
116
+ "step": 180
117
+ },
118
+ {
119
+ "epoch": 0.85,
120
+ "learning_rate": 0.018733333333333334,
121
+ "loss": 0.4153,
122
+ "step": 190
123
+ },
124
+ {
125
+ "epoch": 0.89,
126
+ "learning_rate": 0.018666666666666668,
127
+ "loss": 0.3587,
128
+ "step": 200
129
+ },
130
+ {
131
+ "epoch": 0.94,
132
+ "learning_rate": 0.018600000000000002,
133
+ "loss": 0.3735,
134
+ "step": 210
135
+ },
136
+ {
137
+ "epoch": 0.98,
138
+ "learning_rate": 0.018533333333333332,
139
+ "loss": 0.3399,
140
+ "step": 220
141
+ },
142
+ {
143
+ "epoch": 1.03,
144
+ "learning_rate": 0.018466666666666666,
145
+ "loss": 0.3416,
146
+ "step": 230
147
+ },
148
+ {
149
+ "epoch": 1.07,
150
+ "learning_rate": 0.0184,
151
+ "loss": 0.3426,
152
+ "step": 240
153
+ },
154
+ {
155
+ "epoch": 1.11,
156
+ "learning_rate": 0.018333333333333333,
157
+ "loss": 0.3181,
158
+ "step": 250
159
+ },
160
+ {
161
+ "epoch": 1.16,
162
+ "learning_rate": 0.018266666666666667,
163
+ "loss": 0.2859,
164
+ "step": 260
165
+ },
166
+ {
167
+ "epoch": 1.2,
168
+ "learning_rate": 0.0182,
169
+ "loss": 0.3226,
170
+ "step": 270
171
+ },
172
+ {
173
+ "epoch": 1.25,
174
+ "learning_rate": 0.01813333333333333,
175
+ "loss": 0.3054,
176
+ "step": 280
177
+ },
178
+ {
179
+ "epoch": 1.29,
180
+ "learning_rate": 0.01806666666666667,
181
+ "loss": 0.302,
182
+ "step": 290
183
+ },
184
+ {
185
+ "epoch": 1.34,
186
+ "learning_rate": 0.018000000000000002,
187
+ "loss": 0.3099,
188
+ "step": 300
189
+ },
190
+ {
191
+ "epoch": 1.38,
192
+ "learning_rate": 0.017933333333333332,
193
+ "loss": 0.3026,
194
+ "step": 310
195
+ },
196
+ {
197
+ "epoch": 1.43,
198
+ "learning_rate": 0.017866666666666666,
199
+ "loss": 0.2892,
200
+ "step": 320
201
+ },
202
+ {
203
+ "epoch": 1.47,
204
+ "learning_rate": 0.0178,
205
+ "loss": 0.3006,
206
+ "step": 330
207
+ },
208
+ {
209
+ "epoch": 1.52,
210
+ "learning_rate": 0.017733333333333334,
211
+ "loss": 0.2935,
212
+ "step": 340
213
+ },
214
+ {
215
+ "epoch": 1.56,
216
+ "learning_rate": 0.017666666666666667,
217
+ "loss": 0.285,
218
+ "step": 350
219
+ },
220
+ {
221
+ "epoch": 1.6,
222
+ "learning_rate": 0.0176,
223
+ "loss": 0.2606,
224
+ "step": 360
225
+ },
226
+ {
227
+ "epoch": 1.65,
228
+ "learning_rate": 0.017533333333333335,
229
+ "loss": 0.2912,
230
+ "step": 370
231
+ },
232
+ {
233
+ "epoch": 1.69,
234
+ "learning_rate": 0.017466666666666665,
235
+ "loss": 0.2856,
236
+ "step": 380
237
+ },
238
+ {
239
+ "epoch": 1.74,
240
+ "learning_rate": 0.0174,
241
+ "loss": 0.2725,
242
+ "step": 390
243
+ },
244
+ {
245
+ "epoch": 1.78,
246
+ "learning_rate": 0.017333333333333336,
247
+ "loss": 0.2755,
248
+ "step": 400
249
+ },
250
+ {
251
+ "epoch": 1.83,
252
+ "learning_rate": 0.017266666666666666,
253
+ "loss": 0.2562,
254
+ "step": 410
255
+ },
256
+ {
257
+ "epoch": 1.87,
258
+ "learning_rate": 0.0172,
259
+ "loss": 0.2845,
260
+ "step": 420
261
+ },
262
+ {
263
+ "epoch": 1.92,
264
+ "learning_rate": 0.017133333333333334,
265
+ "loss": 0.2686,
266
+ "step": 430
267
+ },
268
+ {
269
+ "epoch": 1.96,
270
+ "learning_rate": 0.017066666666666667,
271
+ "loss": 0.2586,
272
+ "step": 440
273
+ },
274
+ {
275
+ "epoch": 2.01,
276
+ "learning_rate": 0.017,
277
+ "loss": 0.2552,
278
+ "step": 450
279
+ },
280
+ {
281
+ "epoch": 2.05,
282
+ "learning_rate": 0.016933333333333335,
283
+ "loss": 0.2529,
284
+ "step": 460
285
+ },
286
+ {
287
+ "epoch": 2.1,
288
+ "learning_rate": 0.01686666666666667,
289
+ "loss": 0.2364,
290
+ "step": 470
291
+ },
292
+ {
293
+ "epoch": 2.14,
294
+ "learning_rate": 0.0168,
295
+ "loss": 0.2541,
296
+ "step": 480
297
+ },
298
+ {
299
+ "epoch": 2.18,
300
+ "learning_rate": 0.016733333333333333,
301
+ "loss": 0.2423,
302
+ "step": 490
303
+ },
304
+ {
305
+ "epoch": 2.23,
306
+ "learning_rate": 0.016666666666666666,
307
+ "loss": 0.2336,
308
+ "step": 500
309
+ },
310
+ {
311
+ "epoch": 2.27,
312
+ "learning_rate": 0.0166,
313
+ "loss": 0.239,
314
+ "step": 510
315
+ },
316
+ {
317
+ "epoch": 2.32,
318
+ "learning_rate": 0.016533333333333334,
319
+ "loss": 0.2359,
320
+ "step": 520
321
+ },
322
+ {
323
+ "epoch": 2.36,
324
+ "learning_rate": 0.016466666666666668,
325
+ "loss": 0.2481,
326
+ "step": 530
327
+ },
328
+ {
329
+ "epoch": 2.41,
330
+ "learning_rate": 0.016399999999999998,
331
+ "loss": 0.2419,
332
+ "step": 540
333
+ },
334
+ {
335
+ "epoch": 2.45,
336
+ "learning_rate": 0.01633333333333333,
337
+ "loss": 0.2289,
338
+ "step": 550
339
+ },
340
+ {
341
+ "epoch": 2.5,
342
+ "learning_rate": 0.01626666666666667,
343
+ "loss": 0.2268,
344
+ "step": 560
345
+ },
346
+ {
347
+ "epoch": 2.54,
348
+ "learning_rate": 0.016200000000000003,
349
+ "loss": 0.2393,
350
+ "step": 570
351
+ },
352
+ {
353
+ "epoch": 2.59,
354
+ "learning_rate": 0.016133333333333333,
355
+ "loss": 0.2234,
356
+ "step": 580
357
+ },
358
+ {
359
+ "epoch": 2.63,
360
+ "learning_rate": 0.016066666666666667,
361
+ "loss": 0.2382,
362
+ "step": 590
363
+ },
364
+ {
365
+ "epoch": 2.67,
366
+ "learning_rate": 0.016,
367
+ "loss": 0.237,
368
+ "step": 600
369
+ },
370
+ {
371
+ "epoch": 2.72,
372
+ "learning_rate": 0.015933333333333334,
373
+ "loss": 0.2492,
374
+ "step": 610
375
+ },
376
+ {
377
+ "epoch": 2.76,
378
+ "learning_rate": 0.015866666666666668,
379
+ "loss": 0.2263,
380
+ "step": 620
381
+ },
382
+ {
383
+ "epoch": 2.81,
384
+ "learning_rate": 0.0158,
385
+ "loss": 0.2515,
386
+ "step": 630
387
+ },
388
+ {
389
+ "epoch": 2.85,
390
+ "learning_rate": 0.015733333333333332,
391
+ "loss": 0.2299,
392
+ "step": 640
393
+ },
394
+ {
395
+ "epoch": 2.9,
396
+ "learning_rate": 0.015666666666666666,
397
+ "loss": 0.2311,
398
+ "step": 650
399
+ },
400
+ {
401
+ "epoch": 2.94,
402
+ "learning_rate": 0.015600000000000001,
403
+ "loss": 0.2204,
404
+ "step": 660
405
+ },
406
+ {
407
+ "epoch": 2.99,
408
+ "learning_rate": 0.015533333333333333,
409
+ "loss": 0.2243,
410
+ "step": 670
411
+ },
412
+ {
413
+ "epoch": 3.03,
414
+ "learning_rate": 0.015466666666666667,
415
+ "loss": 0.2,
416
+ "step": 680
417
+ },
418
+ {
419
+ "epoch": 3.08,
420
+ "learning_rate": 0.0154,
421
+ "loss": 0.2016,
422
+ "step": 690
423
+ },
424
+ {
425
+ "epoch": 3.12,
426
+ "learning_rate": 0.015333333333333334,
427
+ "loss": 0.2251,
428
+ "step": 700
429
+ },
430
+ {
431
+ "epoch": 3.17,
432
+ "learning_rate": 0.015266666666666666,
433
+ "loss": 0.2055,
434
+ "step": 710
435
+ },
436
+ {
437
+ "epoch": 3.21,
438
+ "learning_rate": 0.0152,
439
+ "loss": 0.2205,
440
+ "step": 720
441
+ },
442
+ {
443
+ "epoch": 3.25,
444
+ "learning_rate": 0.015133333333333334,
445
+ "loss": 0.2066,
446
+ "step": 730
447
+ },
448
+ {
449
+ "epoch": 3.3,
450
+ "learning_rate": 0.015066666666666666,
451
+ "loss": 0.2174,
452
+ "step": 740
453
+ },
454
+ {
455
+ "epoch": 3.34,
456
+ "learning_rate": 0.015,
457
+ "loss": 0.2163,
458
+ "step": 750
459
+ },
460
+ {
461
+ "epoch": 3.39,
462
+ "learning_rate": 0.014933333333333335,
463
+ "loss": 0.2049,
464
+ "step": 760
465
+ },
466
+ {
467
+ "epoch": 3.43,
468
+ "learning_rate": 0.014866666666666667,
469
+ "loss": 0.2039,
470
+ "step": 770
471
+ },
472
+ {
473
+ "epoch": 3.48,
474
+ "learning_rate": 0.0148,
475
+ "loss": 0.1941,
476
+ "step": 780
477
+ },
478
+ {
479
+ "epoch": 3.52,
480
+ "learning_rate": 0.014733333333333334,
481
+ "loss": 0.2051,
482
+ "step": 790
483
+ },
484
+ {
485
+ "epoch": 3.57,
486
+ "learning_rate": 0.014666666666666666,
487
+ "loss": 0.2097,
488
+ "step": 800
489
+ },
490
+ {
491
+ "epoch": 3.61,
492
+ "learning_rate": 0.0146,
493
+ "loss": 0.2104,
494
+ "step": 810
495
+ },
496
+ {
497
+ "epoch": 3.66,
498
+ "learning_rate": 0.014533333333333334,
499
+ "loss": 0.2157,
500
+ "step": 820
501
+ },
502
+ {
503
+ "epoch": 3.7,
504
+ "learning_rate": 0.014466666666666668,
505
+ "loss": 0.2053,
506
+ "step": 830
507
+ },
508
+ {
509
+ "epoch": 3.74,
510
+ "learning_rate": 0.0144,
511
+ "loss": 0.2005,
512
+ "step": 840
513
+ },
514
+ {
515
+ "epoch": 3.79,
516
+ "learning_rate": 0.014333333333333333,
517
+ "loss": 0.2075,
518
+ "step": 850
519
+ },
520
+ {
521
+ "epoch": 3.83,
522
+ "learning_rate": 0.014266666666666667,
523
+ "loss": 0.2065,
524
+ "step": 860
525
+ },
526
+ {
527
+ "epoch": 3.88,
528
+ "learning_rate": 0.014199999999999999,
529
+ "loss": 0.2091,
530
+ "step": 870
531
+ },
532
+ {
533
+ "epoch": 3.92,
534
+ "learning_rate": 0.014133333333333333,
535
+ "loss": 0.2003,
536
+ "step": 880
537
+ },
538
+ {
539
+ "epoch": 3.97,
540
+ "learning_rate": 0.014066666666666668,
541
+ "loss": 0.2111,
542
+ "step": 890
543
+ },
544
+ {
545
+ "epoch": 4.01,
546
+ "learning_rate": 0.013999999999999999,
547
+ "loss": 0.2019,
548
+ "step": 900
549
+ },
550
+ {
551
+ "epoch": 4.06,
552
+ "learning_rate": 0.013933333333333334,
553
+ "loss": 0.1953,
554
+ "step": 910
555
+ },
556
+ {
557
+ "epoch": 4.1,
558
+ "learning_rate": 0.013866666666666668,
559
+ "loss": 0.1912,
560
+ "step": 920
561
+ },
562
+ {
563
+ "epoch": 4.15,
564
+ "learning_rate": 0.0138,
565
+ "loss": 0.1947,
566
+ "step": 930
567
+ },
568
+ {
569
+ "epoch": 4.19,
570
+ "learning_rate": 0.013733333333333334,
571
+ "loss": 0.1879,
572
+ "step": 940
573
+ },
574
+ {
575
+ "epoch": 4.24,
576
+ "learning_rate": 0.013666666666666667,
577
+ "loss": 0.1923,
578
+ "step": 950
579
+ },
580
+ {
581
+ "epoch": 4.28,
582
+ "learning_rate": 0.013600000000000001,
583
+ "loss": 0.1841,
584
+ "step": 960
585
+ },
586
+ {
587
+ "epoch": 4.32,
588
+ "learning_rate": 0.013533333333333333,
589
+ "loss": 0.1878,
590
+ "step": 970
591
+ },
592
+ {
593
+ "epoch": 4.37,
594
+ "learning_rate": 0.013466666666666667,
595
+ "loss": 0.192,
596
+ "step": 980
597
+ },
598
+ {
599
+ "epoch": 4.41,
600
+ "learning_rate": 0.0134,
601
+ "loss": 0.186,
602
+ "step": 990
603
+ },
604
+ {
605
+ "epoch": 4.46,
606
+ "learning_rate": 0.013333333333333332,
607
+ "loss": 0.1852,
608
+ "step": 1000
609
+ },
610
+ {
611
+ "epoch": 4.5,
612
+ "learning_rate": 0.013266666666666666,
613
+ "loss": 0.1861,
614
+ "step": 1010
615
+ },
616
+ {
617
+ "epoch": 4.55,
618
+ "learning_rate": 0.013200000000000002,
619
+ "loss": 0.1871,
620
+ "step": 1020
621
+ },
622
+ {
623
+ "epoch": 4.59,
624
+ "learning_rate": 0.013133333333333332,
625
+ "loss": 0.1843,
626
+ "step": 1030
627
+ },
628
+ {
629
+ "epoch": 4.64,
630
+ "learning_rate": 0.013066666666666667,
631
+ "loss": 0.1981,
632
+ "step": 1040
633
+ },
634
+ {
635
+ "epoch": 4.68,
636
+ "learning_rate": 0.013000000000000001,
637
+ "loss": 0.1956,
638
+ "step": 1050
639
+ },
640
+ {
641
+ "epoch": 4.73,
642
+ "learning_rate": 0.012933333333333333,
643
+ "loss": 0.1903,
644
+ "step": 1060
645
+ },
646
+ {
647
+ "epoch": 4.77,
648
+ "learning_rate": 0.012866666666666667,
649
+ "loss": 0.1966,
650
+ "step": 1070
651
+ },
652
+ {
653
+ "epoch": 4.81,
654
+ "learning_rate": 0.0128,
655
+ "loss": 0.1977,
656
+ "step": 1080
657
+ },
658
+ {
659
+ "epoch": 4.86,
660
+ "learning_rate": 0.012733333333333334,
661
+ "loss": 0.1907,
662
+ "step": 1090
663
+ },
664
+ {
665
+ "epoch": 4.9,
666
+ "learning_rate": 0.012666666666666666,
667
+ "loss": 0.1775,
668
+ "step": 1100
669
+ },
670
+ {
671
+ "epoch": 4.95,
672
+ "learning_rate": 0.0126,
673
+ "loss": 0.1932,
674
+ "step": 1110
675
+ },
676
+ {
677
+ "epoch": 4.99,
678
+ "learning_rate": 0.012533333333333334,
679
+ "loss": 0.1992,
680
+ "step": 1120
681
+ },
682
+ {
683
+ "epoch": 5.04,
684
+ "learning_rate": 0.012466666666666666,
685
+ "loss": 0.1872,
686
+ "step": 1130
687
+ },
688
+ {
689
+ "epoch": 5.08,
690
+ "learning_rate": 0.0124,
691
+ "loss": 0.1682,
692
+ "step": 1140
693
+ },
694
+ {
695
+ "epoch": 5.13,
696
+ "learning_rate": 0.012333333333333335,
697
+ "loss": 0.1684,
698
+ "step": 1150
699
+ },
700
+ {
701
+ "epoch": 5.17,
702
+ "learning_rate": 0.012266666666666665,
703
+ "loss": 0.1823,
704
+ "step": 1160
705
+ },
706
+ {
707
+ "epoch": 5.22,
708
+ "learning_rate": 0.0122,
709
+ "loss": 0.1803,
710
+ "step": 1170
711
+ },
712
+ {
713
+ "epoch": 5.26,
714
+ "learning_rate": 0.012133333333333335,
715
+ "loss": 0.1794,
716
+ "step": 1180
717
+ },
718
+ {
719
+ "epoch": 5.31,
720
+ "learning_rate": 0.012066666666666668,
721
+ "loss": 0.1902,
722
+ "step": 1190
723
+ },
724
+ {
725
+ "epoch": 5.35,
726
+ "learning_rate": 0.012,
727
+ "loss": 0.1783,
728
+ "step": 1200
729
+ },
730
+ {
731
+ "epoch": 5.39,
732
+ "learning_rate": 0.011933333333333334,
733
+ "loss": 0.1851,
734
+ "step": 1210
735
+ },
736
+ {
737
+ "epoch": 5.44,
738
+ "learning_rate": 0.011866666666666668,
739
+ "loss": 0.1963,
740
+ "step": 1220
741
+ },
742
+ {
743
+ "epoch": 5.48,
744
+ "learning_rate": 0.0118,
745
+ "loss": 0.18,
746
+ "step": 1230
747
+ },
748
+ {
749
+ "epoch": 5.53,
750
+ "learning_rate": 0.011733333333333333,
751
+ "loss": 0.1805,
752
+ "step": 1240
753
+ },
754
+ {
755
+ "epoch": 5.57,
756
+ "learning_rate": 0.011666666666666667,
757
+ "loss": 0.1765,
758
+ "step": 1250
759
+ },
760
+ {
761
+ "epoch": 5.62,
762
+ "learning_rate": 0.0116,
763
+ "loss": 0.1687,
764
+ "step": 1260
765
+ },
766
+ {
767
+ "epoch": 5.66,
768
+ "learning_rate": 0.011533333333333333,
769
+ "loss": 0.1852,
770
+ "step": 1270
771
+ },
772
+ {
773
+ "epoch": 5.71,
774
+ "learning_rate": 0.011466666666666667,
775
+ "loss": 0.1854,
776
+ "step": 1280
777
+ },
778
+ {
779
+ "epoch": 5.75,
780
+ "learning_rate": 0.011399999999999999,
781
+ "loss": 0.1745,
782
+ "step": 1290
783
+ },
784
+ {
785
+ "epoch": 5.8,
786
+ "learning_rate": 0.011333333333333332,
787
+ "loss": 0.1802,
788
+ "step": 1300
789
+ },
790
+ {
791
+ "epoch": 5.84,
792
+ "learning_rate": 0.011266666666666668,
793
+ "loss": 0.1892,
794
+ "step": 1310
795
+ },
796
+ {
797
+ "epoch": 5.88,
798
+ "learning_rate": 0.011200000000000002,
799
+ "loss": 0.1908,
800
+ "step": 1320
801
+ },
802
+ {
803
+ "epoch": 5.93,
804
+ "learning_rate": 0.011133333333333334,
805
+ "loss": 0.1898,
806
+ "step": 1330
807
+ },
808
+ {
809
+ "epoch": 5.97,
810
+ "learning_rate": 0.011066666666666667,
811
+ "loss": 0.1881,
812
+ "step": 1340
813
+ },
814
+ {
815
+ "epoch": 6.02,
816
+ "learning_rate": 0.011000000000000001,
817
+ "loss": 0.1784,
818
+ "step": 1350
819
+ },
820
+ {
821
+ "epoch": 6.06,
822
+ "learning_rate": 0.010933333333333333,
823
+ "loss": 0.1814,
824
+ "step": 1360
825
+ },
826
+ {
827
+ "epoch": 6.11,
828
+ "learning_rate": 0.010866666666666667,
829
+ "loss": 0.1724,
830
+ "step": 1370
831
+ },
832
+ {
833
+ "epoch": 6.15,
834
+ "learning_rate": 0.0108,
835
+ "loss": 0.178,
836
+ "step": 1380
837
+ },
838
+ {
839
+ "epoch": 6.2,
840
+ "learning_rate": 0.010733333333333333,
841
+ "loss": 0.1707,
842
+ "step": 1390
843
+ },
844
+ {
845
+ "epoch": 6.24,
846
+ "learning_rate": 0.010666666666666666,
847
+ "loss": 0.1711,
848
+ "step": 1400
849
+ },
850
+ {
851
+ "epoch": 6.29,
852
+ "learning_rate": 0.0106,
853
+ "loss": 0.1626,
854
+ "step": 1410
855
+ },
856
+ {
857
+ "epoch": 6.33,
858
+ "learning_rate": 0.010533333333333332,
859
+ "loss": 0.1676,
860
+ "step": 1420
861
+ },
862
+ {
863
+ "epoch": 6.38,
864
+ "learning_rate": 0.010466666666666666,
865
+ "loss": 0.1632,
866
+ "step": 1430
867
+ },
868
+ {
869
+ "epoch": 6.42,
870
+ "learning_rate": 0.010400000000000001,
871
+ "loss": 0.171,
872
+ "step": 1440
873
+ },
874
+ {
875
+ "epoch": 6.46,
876
+ "learning_rate": 0.010333333333333335,
877
+ "loss": 0.1746,
878
+ "step": 1450
879
+ },
880
+ {
881
+ "epoch": 6.51,
882
+ "learning_rate": 0.010266666666666667,
883
+ "loss": 0.1764,
884
+ "step": 1460
885
+ },
886
+ {
887
+ "epoch": 6.55,
888
+ "learning_rate": 0.0102,
889
+ "loss": 0.1805,
890
+ "step": 1470
891
+ },
892
+ {
893
+ "epoch": 6.6,
894
+ "learning_rate": 0.010133333333333334,
895
+ "loss": 0.1759,
896
+ "step": 1480
897
+ },
898
+ {
899
+ "epoch": 6.64,
900
+ "learning_rate": 0.010066666666666666,
901
+ "loss": 0.1798,
902
+ "step": 1490
903
+ },
904
+ {
905
+ "epoch": 6.69,
906
+ "learning_rate": 0.01,
907
+ "loss": 0.1673,
908
+ "step": 1500
909
+ },
910
+ {
911
+ "epoch": 6.73,
912
+ "learning_rate": 0.009933333333333334,
913
+ "loss": 0.185,
914
+ "step": 1510
915
+ },
916
+ {
917
+ "epoch": 6.78,
918
+ "learning_rate": 0.009866666666666668,
919
+ "loss": 0.1712,
920
+ "step": 1520
921
+ },
922
+ {
923
+ "epoch": 6.82,
924
+ "learning_rate": 0.0098,
925
+ "loss": 0.1586,
926
+ "step": 1530
927
+ },
928
+ {
929
+ "epoch": 6.87,
930
+ "learning_rate": 0.009733333333333333,
931
+ "loss": 0.1709,
932
+ "step": 1540
933
+ },
934
+ {
935
+ "epoch": 6.91,
936
+ "learning_rate": 0.009666666666666667,
937
+ "loss": 0.1657,
938
+ "step": 1550
939
+ },
940
+ {
941
+ "epoch": 6.95,
942
+ "learning_rate": 0.0096,
943
+ "loss": 0.1738,
944
+ "step": 1560
945
+ },
946
+ {
947
+ "epoch": 7.0,
948
+ "learning_rate": 0.009533333333333335,
949
+ "loss": 0.1633,
950
+ "step": 1570
951
+ },
952
+ {
953
+ "epoch": 7.04,
954
+ "learning_rate": 0.009466666666666667,
955
+ "loss": 0.167,
956
+ "step": 1580
957
+ },
958
+ {
959
+ "epoch": 7.09,
960
+ "learning_rate": 0.0094,
961
+ "loss": 0.1629,
962
+ "step": 1590
963
+ },
964
+ {
965
+ "epoch": 7.13,
966
+ "learning_rate": 0.009333333333333334,
967
+ "loss": 0.1679,
968
+ "step": 1600
969
+ },
970
+ {
971
+ "epoch": 7.18,
972
+ "learning_rate": 0.009266666666666666,
973
+ "loss": 0.1639,
974
+ "step": 1610
975
+ },
976
+ {
977
+ "epoch": 7.22,
978
+ "learning_rate": 0.0092,
979
+ "loss": 0.1652,
980
+ "step": 1620
981
+ },
982
+ {
983
+ "epoch": 7.27,
984
+ "learning_rate": 0.009133333333333334,
985
+ "loss": 0.17,
986
+ "step": 1630
987
+ },
988
+ {
989
+ "epoch": 7.31,
990
+ "learning_rate": 0.009066666666666666,
991
+ "loss": 0.1663,
992
+ "step": 1640
993
+ },
994
+ {
995
+ "epoch": 7.36,
996
+ "learning_rate": 0.009000000000000001,
997
+ "loss": 0.165,
998
+ "step": 1650
999
+ },
1000
+ {
1001
+ "epoch": 7.4,
1002
+ "learning_rate": 0.008933333333333333,
1003
+ "loss": 0.1724,
1004
+ "step": 1660
1005
+ },
1006
+ {
1007
+ "epoch": 7.44,
1008
+ "learning_rate": 0.008866666666666667,
1009
+ "loss": 0.1708,
1010
+ "step": 1670
1011
+ },
1012
+ {
1013
+ "epoch": 7.49,
1014
+ "learning_rate": 0.0088,
1015
+ "loss": 0.1673,
1016
+ "step": 1680
1017
+ },
1018
+ {
1019
+ "epoch": 7.53,
1020
+ "learning_rate": 0.008733333333333333,
1021
+ "loss": 0.1707,
1022
+ "step": 1690
1023
+ },
1024
+ {
1025
+ "epoch": 7.58,
1026
+ "learning_rate": 0.008666666666666668,
1027
+ "loss": 0.1633,
1028
+ "step": 1700
1029
+ },
1030
+ {
1031
+ "epoch": 7.62,
1032
+ "learning_rate": 0.0086,
1033
+ "loss": 0.1624,
1034
+ "step": 1710
1035
+ },
1036
+ {
1037
+ "epoch": 7.67,
1038
+ "learning_rate": 0.008533333333333334,
1039
+ "loss": 0.1574,
1040
+ "step": 1720
1041
+ },
1042
+ {
1043
+ "epoch": 7.71,
1044
+ "learning_rate": 0.008466666666666667,
1045
+ "loss": 0.1678,
1046
+ "step": 1730
1047
+ },
1048
+ {
1049
+ "epoch": 7.76,
1050
+ "learning_rate": 0.0084,
1051
+ "loss": 0.1625,
1052
+ "step": 1740
1053
+ },
1054
+ {
1055
+ "epoch": 7.8,
1056
+ "learning_rate": 0.008333333333333333,
1057
+ "loss": 0.1696,
1058
+ "step": 1750
1059
+ },
1060
+ {
1061
+ "epoch": 7.85,
1062
+ "learning_rate": 0.008266666666666667,
1063
+ "loss": 0.1577,
1064
+ "step": 1760
1065
+ },
1066
+ {
1067
+ "epoch": 7.89,
1068
+ "learning_rate": 0.008199999999999999,
1069
+ "loss": 0.1716,
1070
+ "step": 1770
1071
+ },
1072
+ {
1073
+ "epoch": 7.94,
1074
+ "learning_rate": 0.008133333333333334,
1075
+ "loss": 0.1687,
1076
+ "step": 1780
1077
+ },
1078
+ {
1079
+ "epoch": 7.98,
1080
+ "learning_rate": 0.008066666666666666,
1081
+ "loss": 0.1638,
1082
+ "step": 1790
1083
+ },
1084
+ {
1085
+ "epoch": 8.02,
1086
+ "learning_rate": 0.008,
1087
+ "loss": 0.1557,
1088
+ "step": 1800
1089
+ },
1090
+ {
1091
+ "epoch": 8.07,
1092
+ "learning_rate": 0.007933333333333334,
1093
+ "loss": 0.1536,
1094
+ "step": 1810
1095
+ },
1096
+ {
1097
+ "epoch": 8.11,
1098
+ "learning_rate": 0.007866666666666666,
1099
+ "loss": 0.1661,
1100
+ "step": 1820
1101
+ },
1102
+ {
1103
+ "epoch": 8.16,
1104
+ "learning_rate": 0.0078000000000000005,
1105
+ "loss": 0.1609,
1106
+ "step": 1830
1107
+ },
1108
+ {
1109
+ "epoch": 8.2,
1110
+ "learning_rate": 0.007733333333333333,
1111
+ "loss": 0.1561,
1112
+ "step": 1840
1113
+ },
1114
+ {
1115
+ "epoch": 8.25,
1116
+ "learning_rate": 0.007666666666666667,
1117
+ "loss": 0.1547,
1118
+ "step": 1850
1119
+ },
1120
+ {
1121
+ "epoch": 8.29,
1122
+ "learning_rate": 0.0076,
1123
+ "loss": 0.1685,
1124
+ "step": 1860
1125
+ },
1126
+ {
1127
+ "epoch": 8.34,
1128
+ "learning_rate": 0.007533333333333333,
1129
+ "loss": 0.1649,
1130
+ "step": 1870
1131
+ },
1132
+ {
1133
+ "epoch": 8.38,
1134
+ "learning_rate": 0.0074666666666666675,
1135
+ "loss": 0.1585,
1136
+ "step": 1880
1137
+ },
1138
+ {
1139
+ "epoch": 8.43,
1140
+ "learning_rate": 0.0074,
1141
+ "loss": 0.1659,
1142
+ "step": 1890
1143
+ },
1144
+ {
1145
+ "epoch": 8.47,
1146
+ "learning_rate": 0.007333333333333333,
1147
+ "loss": 0.1563,
1148
+ "step": 1900
1149
+ },
1150
+ {
1151
+ "epoch": 8.51,
1152
+ "learning_rate": 0.007266666666666667,
1153
+ "loss": 0.16,
1154
+ "step": 1910
1155
+ },
1156
+ {
1157
+ "epoch": 8.56,
1158
+ "learning_rate": 0.0072,
1159
+ "loss": 0.1643,
1160
+ "step": 1920
1161
+ },
1162
+ {
1163
+ "epoch": 8.6,
1164
+ "learning_rate": 0.0071333333333333335,
1165
+ "loss": 0.1556,
1166
+ "step": 1930
1167
+ },
1168
+ {
1169
+ "epoch": 8.65,
1170
+ "learning_rate": 0.007066666666666666,
1171
+ "loss": 0.1618,
1172
+ "step": 1940
1173
+ },
1174
+ {
1175
+ "epoch": 8.69,
1176
+ "learning_rate": 0.006999999999999999,
1177
+ "loss": 0.1608,
1178
+ "step": 1950
1179
+ },
1180
+ {
1181
+ "epoch": 8.74,
1182
+ "learning_rate": 0.006933333333333334,
1183
+ "loss": 0.1622,
1184
+ "step": 1960
1185
+ },
1186
+ {
1187
+ "epoch": 8.78,
1188
+ "learning_rate": 0.006866666666666667,
1189
+ "loss": 0.1686,
1190
+ "step": 1970
1191
+ },
1192
+ {
1193
+ "epoch": 8.83,
1194
+ "learning_rate": 0.0068000000000000005,
1195
+ "loss": 0.1624,
1196
+ "step": 1980
1197
+ },
1198
+ {
1199
+ "epoch": 8.87,
1200
+ "learning_rate": 0.006733333333333333,
1201
+ "loss": 0.1623,
1202
+ "step": 1990
1203
+ },
1204
+ {
1205
+ "epoch": 8.92,
1206
+ "learning_rate": 0.006666666666666666,
1207
+ "loss": 0.1658,
1208
+ "step": 2000
1209
+ },
1210
+ {
1211
+ "epoch": 8.96,
1212
+ "learning_rate": 0.006600000000000001,
1213
+ "loss": 0.1679,
1214
+ "step": 2010
1215
+ },
1216
+ {
1217
+ "epoch": 9.01,
1218
+ "learning_rate": 0.006533333333333334,
1219
+ "loss": 0.1573,
1220
+ "step": 2020
1221
+ },
1222
+ {
1223
+ "epoch": 9.05,
1224
+ "learning_rate": 0.006466666666666667,
1225
+ "loss": 0.1582,
1226
+ "step": 2030
1227
+ },
1228
+ {
1229
+ "epoch": 9.09,
1230
+ "learning_rate": 0.0064,
1231
+ "loss": 0.1576,
1232
+ "step": 2040
1233
+ },
1234
+ {
1235
+ "epoch": 9.14,
1236
+ "learning_rate": 0.006333333333333333,
1237
+ "loss": 0.1599,
1238
+ "step": 2050
1239
+ },
1240
+ {
1241
+ "epoch": 9.18,
1242
+ "learning_rate": 0.006266666666666667,
1243
+ "loss": 0.1574,
1244
+ "step": 2060
1245
+ },
1246
+ {
1247
+ "epoch": 9.23,
1248
+ "learning_rate": 0.0062,
1249
+ "loss": 0.1628,
1250
+ "step": 2070
1251
+ },
1252
+ {
1253
+ "epoch": 9.27,
1254
+ "learning_rate": 0.006133333333333333,
1255
+ "loss": 0.1622,
1256
+ "step": 2080
1257
+ },
1258
+ {
1259
+ "epoch": 9.32,
1260
+ "learning_rate": 0.006066666666666667,
1261
+ "loss": 0.1496,
1262
+ "step": 2090
1263
+ },
1264
+ {
1265
+ "epoch": 9.36,
1266
+ "learning_rate": 0.006,
1267
+ "loss": 0.1581,
1268
+ "step": 2100
1269
+ },
1270
+ {
1271
+ "epoch": 9.41,
1272
+ "learning_rate": 0.005933333333333334,
1273
+ "loss": 0.1645,
1274
+ "step": 2110
1275
+ },
1276
+ {
1277
+ "epoch": 9.45,
1278
+ "learning_rate": 0.005866666666666667,
1279
+ "loss": 0.161,
1280
+ "step": 2120
1281
+ },
1282
+ {
1283
+ "epoch": 9.5,
1284
+ "learning_rate": 0.0058,
1285
+ "loss": 0.1534,
1286
+ "step": 2130
1287
+ },
1288
+ {
1289
+ "epoch": 9.54,
1290
+ "learning_rate": 0.005733333333333333,
1291
+ "loss": 0.155,
1292
+ "step": 2140
1293
+ },
1294
+ {
1295
+ "epoch": 9.58,
1296
+ "learning_rate": 0.005666666666666666,
1297
+ "loss": 0.1496,
1298
+ "step": 2150
1299
+ },
1300
+ {
1301
+ "epoch": 9.63,
1302
+ "learning_rate": 0.005600000000000001,
1303
+ "loss": 0.1585,
1304
+ "step": 2160
1305
+ },
1306
+ {
1307
+ "epoch": 9.67,
1308
+ "learning_rate": 0.005533333333333334,
1309
+ "loss": 0.1522,
1310
+ "step": 2170
1311
+ },
1312
+ {
1313
+ "epoch": 9.72,
1314
+ "learning_rate": 0.0054666666666666665,
1315
+ "loss": 0.1493,
1316
+ "step": 2180
1317
+ },
1318
+ {
1319
+ "epoch": 9.76,
1320
+ "learning_rate": 0.0054,
1321
+ "loss": 0.1549,
1322
+ "step": 2190
1323
+ },
1324
+ {
1325
+ "epoch": 9.81,
1326
+ "learning_rate": 0.005333333333333333,
1327
+ "loss": 0.1544,
1328
+ "step": 2200
1329
+ },
1330
+ {
1331
+ "epoch": 9.85,
1332
+ "learning_rate": 0.005266666666666666,
1333
+ "loss": 0.1639,
1334
+ "step": 2210
1335
+ },
1336
+ {
1337
+ "epoch": 9.9,
1338
+ "learning_rate": 0.005200000000000001,
1339
+ "loss": 0.1643,
1340
+ "step": 2220
1341
+ },
1342
+ {
1343
+ "epoch": 9.94,
1344
+ "learning_rate": 0.0051333333333333335,
1345
+ "loss": 0.153,
1346
+ "step": 2230
1347
+ },
1348
+ {
1349
+ "epoch": 9.99,
1350
+ "learning_rate": 0.005066666666666667,
1351
+ "loss": 0.1702,
1352
+ "step": 2240
1353
+ },
1354
+ {
1355
+ "epoch": 10.03,
1356
+ "learning_rate": 0.005,
1357
+ "loss": 0.1538,
1358
+ "step": 2250
1359
+ },
1360
+ {
1361
+ "epoch": 10.08,
1362
+ "learning_rate": 0.004933333333333334,
1363
+ "loss": 0.1495,
1364
+ "step": 2260
1365
+ },
1366
+ {
1367
+ "epoch": 10.12,
1368
+ "learning_rate": 0.004866666666666667,
1369
+ "loss": 0.1484,
1370
+ "step": 2270
1371
+ },
1372
+ {
1373
+ "epoch": 10.16,
1374
+ "learning_rate": 0.0048,
1375
+ "loss": 0.1577,
1376
+ "step": 2280
1377
+ },
1378
+ {
1379
+ "epoch": 10.21,
1380
+ "learning_rate": 0.004733333333333333,
1381
+ "loss": 0.1502,
1382
+ "step": 2290
1383
+ },
1384
+ {
1385
+ "epoch": 10.25,
1386
+ "learning_rate": 0.004666666666666667,
1387
+ "loss": 0.1511,
1388
+ "step": 2300
1389
+ },
1390
+ {
1391
+ "epoch": 10.3,
1392
+ "learning_rate": 0.0046,
1393
+ "loss": 0.1619,
1394
+ "step": 2310
1395
+ },
1396
+ {
1397
+ "epoch": 10.34,
1398
+ "learning_rate": 0.004533333333333333,
1399
+ "loss": 0.1556,
1400
+ "step": 2320
1401
+ },
1402
+ {
1403
+ "epoch": 10.39,
1404
+ "learning_rate": 0.0044666666666666665,
1405
+ "loss": 0.1627,
1406
+ "step": 2330
1407
+ },
1408
+ {
1409
+ "epoch": 10.43,
1410
+ "learning_rate": 0.0044,
1411
+ "loss": 0.1516,
1412
+ "step": 2340
1413
+ },
1414
+ {
1415
+ "epoch": 10.48,
1416
+ "learning_rate": 0.004333333333333334,
1417
+ "loss": 0.1503,
1418
+ "step": 2350
1419
+ },
1420
+ {
1421
+ "epoch": 10.52,
1422
+ "learning_rate": 0.004266666666666667,
1423
+ "loss": 0.1562,
1424
+ "step": 2360
1425
+ },
1426
+ {
1427
+ "epoch": 10.57,
1428
+ "learning_rate": 0.0042,
1429
+ "loss": 0.1629,
1430
+ "step": 2370
1431
+ },
1432
+ {
1433
+ "epoch": 10.61,
1434
+ "learning_rate": 0.0041333333333333335,
1435
+ "loss": 0.1622,
1436
+ "step": 2380
1437
+ },
1438
+ {
1439
+ "epoch": 10.65,
1440
+ "learning_rate": 0.004066666666666667,
1441
+ "loss": 0.1509,
1442
+ "step": 2390
1443
+ },
1444
+ {
1445
+ "epoch": 10.7,
1446
+ "learning_rate": 0.004,
1447
+ "loss": 0.1598,
1448
+ "step": 2400
1449
+ },
1450
+ {
1451
+ "epoch": 10.74,
1452
+ "learning_rate": 0.003933333333333333,
1453
+ "loss": 0.1556,
1454
+ "step": 2410
1455
+ },
1456
+ {
1457
+ "epoch": 10.79,
1458
+ "learning_rate": 0.0038666666666666667,
1459
+ "loss": 0.154,
1460
+ "step": 2420
1461
+ },
1462
+ {
1463
+ "epoch": 10.83,
1464
+ "learning_rate": 0.0038,
1465
+ "loss": 0.1489,
1466
+ "step": 2430
1467
+ },
1468
+ {
1469
+ "epoch": 10.88,
1470
+ "learning_rate": 0.0037333333333333337,
1471
+ "loss": 0.1506,
1472
+ "step": 2440
1473
+ },
1474
+ {
1475
+ "epoch": 10.92,
1476
+ "learning_rate": 0.0036666666666666666,
1477
+ "loss": 0.1514,
1478
+ "step": 2450
1479
+ },
1480
+ {
1481
+ "epoch": 10.97,
1482
+ "learning_rate": 0.0036,
1483
+ "loss": 0.1543,
1484
+ "step": 2460
1485
+ },
1486
+ {
1487
+ "epoch": 11.01,
1488
+ "learning_rate": 0.003533333333333333,
1489
+ "loss": 0.155,
1490
+ "step": 2470
1491
+ },
1492
+ {
1493
+ "epoch": 11.06,
1494
+ "learning_rate": 0.003466666666666667,
1495
+ "loss": 0.1564,
1496
+ "step": 2480
1497
+ },
1498
+ {
1499
+ "epoch": 11.1,
1500
+ "learning_rate": 0.0034000000000000002,
1501
+ "loss": 0.1396,
1502
+ "step": 2490
1503
+ },
1504
+ {
1505
+ "epoch": 11.15,
1506
+ "learning_rate": 0.003333333333333333,
1507
+ "loss": 0.1572,
1508
+ "step": 2500
1509
+ },
1510
+ {
1511
+ "epoch": 11.19,
1512
+ "learning_rate": 0.003266666666666667,
1513
+ "loss": 0.1472,
1514
+ "step": 2510
1515
+ },
1516
+ {
1517
+ "epoch": 11.23,
1518
+ "learning_rate": 0.0032,
1519
+ "loss": 0.1519,
1520
+ "step": 2520
1521
+ },
1522
+ {
1523
+ "epoch": 11.28,
1524
+ "learning_rate": 0.0031333333333333335,
1525
+ "loss": 0.1547,
1526
+ "step": 2530
1527
+ },
1528
+ {
1529
+ "epoch": 11.32,
1530
+ "learning_rate": 0.0030666666666666663,
1531
+ "loss": 0.1499,
1532
+ "step": 2540
1533
+ },
1534
+ {
1535
+ "epoch": 11.37,
1536
+ "learning_rate": 0.003,
1537
+ "loss": 0.1516,
1538
+ "step": 2550
1539
+ },
1540
+ {
1541
+ "epoch": 11.41,
1542
+ "learning_rate": 0.0029333333333333334,
1543
+ "loss": 0.1636,
1544
+ "step": 2560
1545
+ },
1546
+ {
1547
+ "epoch": 11.46,
1548
+ "learning_rate": 0.0028666666666666667,
1549
+ "loss": 0.1424,
1550
+ "step": 2570
1551
+ },
1552
+ {
1553
+ "epoch": 11.5,
1554
+ "learning_rate": 0.0028000000000000004,
1555
+ "loss": 0.1487,
1556
+ "step": 2580
1557
+ },
1558
+ {
1559
+ "epoch": 11.55,
1560
+ "learning_rate": 0.0027333333333333333,
1561
+ "loss": 0.1531,
1562
+ "step": 2590
1563
+ },
1564
+ {
1565
+ "epoch": 11.59,
1566
+ "learning_rate": 0.0026666666666666666,
1567
+ "loss": 0.147,
1568
+ "step": 2600
1569
+ },
1570
+ {
1571
+ "epoch": 11.64,
1572
+ "learning_rate": 0.0026000000000000003,
1573
+ "loss": 0.157,
1574
+ "step": 2610
1575
+ },
1576
+ {
1577
+ "epoch": 11.68,
1578
+ "learning_rate": 0.0025333333333333336,
1579
+ "loss": 0.1572,
1580
+ "step": 2620
1581
+ },
1582
+ {
1583
+ "epoch": 11.72,
1584
+ "learning_rate": 0.002466666666666667,
1585
+ "loss": 0.154,
1586
+ "step": 2630
1587
+ },
1588
+ {
1589
+ "epoch": 11.77,
1590
+ "learning_rate": 0.0024,
1591
+ "loss": 0.1471,
1592
+ "step": 2640
1593
+ },
1594
+ {
1595
+ "epoch": 11.81,
1596
+ "learning_rate": 0.0023333333333333335,
1597
+ "loss": 0.1501,
1598
+ "step": 2650
1599
+ },
1600
+ {
1601
+ "epoch": 11.86,
1602
+ "learning_rate": 0.0022666666666666664,
1603
+ "loss": 0.1477,
1604
+ "step": 2660
1605
+ },
1606
+ {
1607
+ "epoch": 11.9,
1608
+ "learning_rate": 0.0022,
1609
+ "loss": 0.1466,
1610
+ "step": 2670
1611
+ },
1612
+ {
1613
+ "epoch": 11.95,
1614
+ "learning_rate": 0.0021333333333333334,
1615
+ "loss": 0.1582,
1616
+ "step": 2680
1617
+ },
1618
+ {
1619
+ "epoch": 11.99,
1620
+ "learning_rate": 0.0020666666666666667,
1621
+ "loss": 0.1527,
1622
+ "step": 2690
1623
+ },
1624
+ {
1625
+ "epoch": 12.04,
1626
+ "learning_rate": 0.002,
1627
+ "loss": 0.1547,
1628
+ "step": 2700
1629
+ },
1630
+ {
1631
+ "epoch": 12.08,
1632
+ "learning_rate": 0.0019333333333333333,
1633
+ "loss": 0.1492,
1634
+ "step": 2710
1635
+ },
1636
+ {
1637
+ "epoch": 12.13,
1638
+ "learning_rate": 0.0018666666666666669,
1639
+ "loss": 0.1451,
1640
+ "step": 2720
1641
+ },
1642
+ {
1643
+ "epoch": 12.17,
1644
+ "learning_rate": 0.0018,
1645
+ "loss": 0.1443,
1646
+ "step": 2730
1647
+ },
1648
+ {
1649
+ "epoch": 12.22,
1650
+ "learning_rate": 0.0017333333333333335,
1651
+ "loss": 0.1474,
1652
+ "step": 2740
1653
+ },
1654
+ {
1655
+ "epoch": 12.26,
1656
+ "learning_rate": 0.0016666666666666666,
1657
+ "loss": 0.1464,
1658
+ "step": 2750
1659
+ },
1660
+ {
1661
+ "epoch": 12.3,
1662
+ "learning_rate": 0.0016,
1663
+ "loss": 0.1523,
1664
+ "step": 2760
1665
+ },
1666
+ {
1667
+ "epoch": 12.35,
1668
+ "learning_rate": 0.0015333333333333332,
1669
+ "loss": 0.1522,
1670
+ "step": 2770
1671
+ },
1672
+ {
1673
+ "epoch": 12.39,
1674
+ "learning_rate": 0.0014666666666666667,
1675
+ "loss": 0.1479,
1676
+ "step": 2780
1677
+ },
1678
+ {
1679
+ "epoch": 12.44,
1680
+ "learning_rate": 0.0014000000000000002,
1681
+ "loss": 0.1465,
1682
+ "step": 2790
1683
+ },
1684
+ {
1685
+ "epoch": 12.48,
1686
+ "learning_rate": 0.0013333333333333333,
1687
+ "loss": 0.1439,
1688
+ "step": 2800
1689
+ },
1690
+ {
1691
+ "epoch": 12.53,
1692
+ "learning_rate": 0.0012666666666666668,
1693
+ "loss": 0.1506,
1694
+ "step": 2810
1695
+ },
1696
+ {
1697
+ "epoch": 12.57,
1698
+ "learning_rate": 0.0012,
1699
+ "loss": 0.1439,
1700
+ "step": 2820
1701
+ },
1702
+ {
1703
+ "epoch": 12.62,
1704
+ "learning_rate": 0.0011333333333333332,
1705
+ "loss": 0.1546,
1706
+ "step": 2830
1707
+ },
1708
+ {
1709
+ "epoch": 12.66,
1710
+ "learning_rate": 0.0010666666666666667,
1711
+ "loss": 0.145,
1712
+ "step": 2840
1713
+ },
1714
+ {
1715
+ "epoch": 12.71,
1716
+ "learning_rate": 0.001,
1717
+ "loss": 0.1544,
1718
+ "step": 2850
1719
+ },
1720
+ {
1721
+ "epoch": 12.75,
1722
+ "learning_rate": 0.0009333333333333334,
1723
+ "loss": 0.1494,
1724
+ "step": 2860
1725
+ },
1726
+ {
1727
+ "epoch": 12.79,
1728
+ "learning_rate": 0.0008666666666666667,
1729
+ "loss": 0.1504,
1730
+ "step": 2870
1731
+ },
1732
+ {
1733
+ "epoch": 12.84,
1734
+ "learning_rate": 0.0008,
1735
+ "loss": 0.1458,
1736
+ "step": 2880
1737
+ },
1738
+ {
1739
+ "epoch": 12.88,
1740
+ "learning_rate": 0.0007333333333333333,
1741
+ "loss": 0.1483,
1742
+ "step": 2890
1743
+ },
1744
+ {
1745
+ "epoch": 12.93,
1746
+ "learning_rate": 0.0006666666666666666,
1747
+ "loss": 0.1458,
1748
+ "step": 2900
1749
+ },
1750
+ {
1751
+ "epoch": 12.97,
1752
+ "learning_rate": 0.0006,
1753
+ "loss": 0.1481,
1754
+ "step": 2910
1755
+ },
1756
+ {
1757
+ "epoch": 13.02,
1758
+ "learning_rate": 0.0005333333333333334,
1759
+ "loss": 0.1495,
1760
+ "step": 2920
1761
+ },
1762
+ {
1763
+ "epoch": 13.06,
1764
+ "learning_rate": 0.0004666666666666667,
1765
+ "loss": 0.1429,
1766
+ "step": 2930
1767
+ },
1768
+ {
1769
+ "epoch": 13.11,
1770
+ "learning_rate": 0.0004,
1771
+ "loss": 0.1424,
1772
+ "step": 2940
1773
+ },
1774
+ {
1775
+ "epoch": 13.15,
1776
+ "learning_rate": 0.0003333333333333333,
1777
+ "loss": 0.1526,
1778
+ "step": 2950
1779
+ },
1780
+ {
1781
+ "epoch": 13.2,
1782
+ "learning_rate": 0.0002666666666666667,
1783
+ "loss": 0.147,
1784
+ "step": 2960
1785
+ },
1786
+ {
1787
+ "epoch": 13.24,
1788
+ "learning_rate": 0.0002,
1789
+ "loss": 0.1377,
1790
+ "step": 2970
1791
+ },
1792
+ {
1793
+ "epoch": 13.29,
1794
+ "learning_rate": 0.00013333333333333334,
1795
+ "loss": 0.1508,
1796
+ "step": 2980
1797
+ },
1798
+ {
1799
+ "epoch": 13.33,
1800
+ "learning_rate": 6.666666666666667e-05,
1801
+ "loss": 0.1482,
1802
+ "step": 2990
1803
+ },
1804
+ {
1805
+ "epoch": 13.37,
1806
+ "learning_rate": 0.0,
1807
+ "loss": 0.1481,
1808
+ "step": 3000
1809
+ }
1810
+ ],
1811
+ "max_steps": 3000,
1812
+ "num_train_epochs": 14,
1813
+ "total_flos": 1.726948703207424e+17,
1814
+ "trial_name": null,
1815
+ "trial_params": null
1816
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/checkpoint-3000/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e6686835e3bd90bbdc74d1b219b44b2e320a817dfae63b8e2323d2410ad705c7
3
+ size 3707
output/adgen-chatglm2-6b-pt-128-2e-2/train_results.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 13.37,
3
+ "train_loss": 0.2174228900273641,
4
+ "train_runtime": 38888.8061,
5
+ "train_samples": 3589,
6
+ "train_samples_per_second": 1.234,
7
+ "train_steps_per_second": 0.077
8
+ }
output/adgen-chatglm2-6b-pt-128-2e-2/trainer_state.json ADDED
@@ -0,0 +1,1825 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 13.37419894120925,
5
+ "global_step": 3000,
6
+ "is_hyper_param_search": false,
7
+ "is_local_process_zero": true,
8
+ "is_world_process_zero": true,
9
+ "log_history": [
10
+ {
11
+ "epoch": 0.04,
12
+ "learning_rate": 0.019933333333333334,
13
+ "loss": 1.811,
14
+ "step": 10
15
+ },
16
+ {
17
+ "epoch": 0.09,
18
+ "learning_rate": 0.019866666666666668,
19
+ "loss": 1.2846,
20
+ "step": 20
21
+ },
22
+ {
23
+ "epoch": 0.13,
24
+ "learning_rate": 0.0198,
25
+ "loss": 1.1671,
26
+ "step": 30
27
+ },
28
+ {
29
+ "epoch": 0.18,
30
+ "learning_rate": 0.019733333333333335,
31
+ "loss": 0.9238,
32
+ "step": 40
33
+ },
34
+ {
35
+ "epoch": 0.22,
36
+ "learning_rate": 0.019666666666666666,
37
+ "loss": 0.832,
38
+ "step": 50
39
+ },
40
+ {
41
+ "epoch": 0.27,
42
+ "learning_rate": 0.0196,
43
+ "loss": 0.7667,
44
+ "step": 60
45
+ },
46
+ {
47
+ "epoch": 0.31,
48
+ "learning_rate": 0.019533333333333333,
49
+ "loss": 0.5746,
50
+ "step": 70
51
+ },
52
+ {
53
+ "epoch": 0.36,
54
+ "learning_rate": 0.019466666666666667,
55
+ "loss": 0.6013,
56
+ "step": 80
57
+ },
58
+ {
59
+ "epoch": 0.4,
60
+ "learning_rate": 0.0194,
61
+ "loss": 0.622,
62
+ "step": 90
63
+ },
64
+ {
65
+ "epoch": 0.45,
66
+ "learning_rate": 0.019333333333333334,
67
+ "loss": 0.5471,
68
+ "step": 100
69
+ },
70
+ {
71
+ "epoch": 0.49,
72
+ "learning_rate": 0.019266666666666668,
73
+ "loss": 0.5042,
74
+ "step": 110
75
+ },
76
+ {
77
+ "epoch": 0.53,
78
+ "learning_rate": 0.0192,
79
+ "loss": 0.48,
80
+ "step": 120
81
+ },
82
+ {
83
+ "epoch": 0.58,
84
+ "learning_rate": 0.019133333333333332,
85
+ "loss": 0.4302,
86
+ "step": 130
87
+ },
88
+ {
89
+ "epoch": 0.62,
90
+ "learning_rate": 0.01906666666666667,
91
+ "loss": 0.4385,
92
+ "step": 140
93
+ },
94
+ {
95
+ "epoch": 0.67,
96
+ "learning_rate": 0.019,
97
+ "loss": 0.4081,
98
+ "step": 150
99
+ },
100
+ {
101
+ "epoch": 0.71,
102
+ "learning_rate": 0.018933333333333333,
103
+ "loss": 0.3896,
104
+ "step": 160
105
+ },
106
+ {
107
+ "epoch": 0.76,
108
+ "learning_rate": 0.018866666666666667,
109
+ "loss": 0.4021,
110
+ "step": 170
111
+ },
112
+ {
113
+ "epoch": 0.8,
114
+ "learning_rate": 0.0188,
115
+ "loss": 0.3946,
116
+ "step": 180
117
+ },
118
+ {
119
+ "epoch": 0.85,
120
+ "learning_rate": 0.018733333333333334,
121
+ "loss": 0.4153,
122
+ "step": 190
123
+ },
124
+ {
125
+ "epoch": 0.89,
126
+ "learning_rate": 0.018666666666666668,
127
+ "loss": 0.3587,
128
+ "step": 200
129
+ },
130
+ {
131
+ "epoch": 0.94,
132
+ "learning_rate": 0.018600000000000002,
133
+ "loss": 0.3735,
134
+ "step": 210
135
+ },
136
+ {
137
+ "epoch": 0.98,
138
+ "learning_rate": 0.018533333333333332,
139
+ "loss": 0.3399,
140
+ "step": 220
141
+ },
142
+ {
143
+ "epoch": 1.03,
144
+ "learning_rate": 0.018466666666666666,
145
+ "loss": 0.3416,
146
+ "step": 230
147
+ },
148
+ {
149
+ "epoch": 1.07,
150
+ "learning_rate": 0.0184,
151
+ "loss": 0.3426,
152
+ "step": 240
153
+ },
154
+ {
155
+ "epoch": 1.11,
156
+ "learning_rate": 0.018333333333333333,
157
+ "loss": 0.3181,
158
+ "step": 250
159
+ },
160
+ {
161
+ "epoch": 1.16,
162
+ "learning_rate": 0.018266666666666667,
163
+ "loss": 0.2859,
164
+ "step": 260
165
+ },
166
+ {
167
+ "epoch": 1.2,
168
+ "learning_rate": 0.0182,
169
+ "loss": 0.3226,
170
+ "step": 270
171
+ },
172
+ {
173
+ "epoch": 1.25,
174
+ "learning_rate": 0.01813333333333333,
175
+ "loss": 0.3054,
176
+ "step": 280
177
+ },
178
+ {
179
+ "epoch": 1.29,
180
+ "learning_rate": 0.01806666666666667,
181
+ "loss": 0.302,
182
+ "step": 290
183
+ },
184
+ {
185
+ "epoch": 1.34,
186
+ "learning_rate": 0.018000000000000002,
187
+ "loss": 0.3099,
188
+ "step": 300
189
+ },
190
+ {
191
+ "epoch": 1.38,
192
+ "learning_rate": 0.017933333333333332,
193
+ "loss": 0.3026,
194
+ "step": 310
195
+ },
196
+ {
197
+ "epoch": 1.43,
198
+ "learning_rate": 0.017866666666666666,
199
+ "loss": 0.2892,
200
+ "step": 320
201
+ },
202
+ {
203
+ "epoch": 1.47,
204
+ "learning_rate": 0.0178,
205
+ "loss": 0.3006,
206
+ "step": 330
207
+ },
208
+ {
209
+ "epoch": 1.52,
210
+ "learning_rate": 0.017733333333333334,
211
+ "loss": 0.2935,
212
+ "step": 340
213
+ },
214
+ {
215
+ "epoch": 1.56,
216
+ "learning_rate": 0.017666666666666667,
217
+ "loss": 0.285,
218
+ "step": 350
219
+ },
220
+ {
221
+ "epoch": 1.6,
222
+ "learning_rate": 0.0176,
223
+ "loss": 0.2606,
224
+ "step": 360
225
+ },
226
+ {
227
+ "epoch": 1.65,
228
+ "learning_rate": 0.017533333333333335,
229
+ "loss": 0.2912,
230
+ "step": 370
231
+ },
232
+ {
233
+ "epoch": 1.69,
234
+ "learning_rate": 0.017466666666666665,
235
+ "loss": 0.2856,
236
+ "step": 380
237
+ },
238
+ {
239
+ "epoch": 1.74,
240
+ "learning_rate": 0.0174,
241
+ "loss": 0.2725,
242
+ "step": 390
243
+ },
244
+ {
245
+ "epoch": 1.78,
246
+ "learning_rate": 0.017333333333333336,
247
+ "loss": 0.2755,
248
+ "step": 400
249
+ },
250
+ {
251
+ "epoch": 1.83,
252
+ "learning_rate": 0.017266666666666666,
253
+ "loss": 0.2562,
254
+ "step": 410
255
+ },
256
+ {
257
+ "epoch": 1.87,
258
+ "learning_rate": 0.0172,
259
+ "loss": 0.2845,
260
+ "step": 420
261
+ },
262
+ {
263
+ "epoch": 1.92,
264
+ "learning_rate": 0.017133333333333334,
265
+ "loss": 0.2686,
266
+ "step": 430
267
+ },
268
+ {
269
+ "epoch": 1.96,
270
+ "learning_rate": 0.017066666666666667,
271
+ "loss": 0.2586,
272
+ "step": 440
273
+ },
274
+ {
275
+ "epoch": 2.01,
276
+ "learning_rate": 0.017,
277
+ "loss": 0.2552,
278
+ "step": 450
279
+ },
280
+ {
281
+ "epoch": 2.05,
282
+ "learning_rate": 0.016933333333333335,
283
+ "loss": 0.2529,
284
+ "step": 460
285
+ },
286
+ {
287
+ "epoch": 2.1,
288
+ "learning_rate": 0.01686666666666667,
289
+ "loss": 0.2364,
290
+ "step": 470
291
+ },
292
+ {
293
+ "epoch": 2.14,
294
+ "learning_rate": 0.0168,
295
+ "loss": 0.2541,
296
+ "step": 480
297
+ },
298
+ {
299
+ "epoch": 2.18,
300
+ "learning_rate": 0.016733333333333333,
301
+ "loss": 0.2423,
302
+ "step": 490
303
+ },
304
+ {
305
+ "epoch": 2.23,
306
+ "learning_rate": 0.016666666666666666,
307
+ "loss": 0.2336,
308
+ "step": 500
309
+ },
310
+ {
311
+ "epoch": 2.27,
312
+ "learning_rate": 0.0166,
313
+ "loss": 0.239,
314
+ "step": 510
315
+ },
316
+ {
317
+ "epoch": 2.32,
318
+ "learning_rate": 0.016533333333333334,
319
+ "loss": 0.2359,
320
+ "step": 520
321
+ },
322
+ {
323
+ "epoch": 2.36,
324
+ "learning_rate": 0.016466666666666668,
325
+ "loss": 0.2481,
326
+ "step": 530
327
+ },
328
+ {
329
+ "epoch": 2.41,
330
+ "learning_rate": 0.016399999999999998,
331
+ "loss": 0.2419,
332
+ "step": 540
333
+ },
334
+ {
335
+ "epoch": 2.45,
336
+ "learning_rate": 0.01633333333333333,
337
+ "loss": 0.2289,
338
+ "step": 550
339
+ },
340
+ {
341
+ "epoch": 2.5,
342
+ "learning_rate": 0.01626666666666667,
343
+ "loss": 0.2268,
344
+ "step": 560
345
+ },
346
+ {
347
+ "epoch": 2.54,
348
+ "learning_rate": 0.016200000000000003,
349
+ "loss": 0.2393,
350
+ "step": 570
351
+ },
352
+ {
353
+ "epoch": 2.59,
354
+ "learning_rate": 0.016133333333333333,
355
+ "loss": 0.2234,
356
+ "step": 580
357
+ },
358
+ {
359
+ "epoch": 2.63,
360
+ "learning_rate": 0.016066666666666667,
361
+ "loss": 0.2382,
362
+ "step": 590
363
+ },
364
+ {
365
+ "epoch": 2.67,
366
+ "learning_rate": 0.016,
367
+ "loss": 0.237,
368
+ "step": 600
369
+ },
370
+ {
371
+ "epoch": 2.72,
372
+ "learning_rate": 0.015933333333333334,
373
+ "loss": 0.2492,
374
+ "step": 610
375
+ },
376
+ {
377
+ "epoch": 2.76,
378
+ "learning_rate": 0.015866666666666668,
379
+ "loss": 0.2263,
380
+ "step": 620
381
+ },
382
+ {
383
+ "epoch": 2.81,
384
+ "learning_rate": 0.0158,
385
+ "loss": 0.2515,
386
+ "step": 630
387
+ },
388
+ {
389
+ "epoch": 2.85,
390
+ "learning_rate": 0.015733333333333332,
391
+ "loss": 0.2299,
392
+ "step": 640
393
+ },
394
+ {
395
+ "epoch": 2.9,
396
+ "learning_rate": 0.015666666666666666,
397
+ "loss": 0.2311,
398
+ "step": 650
399
+ },
400
+ {
401
+ "epoch": 2.94,
402
+ "learning_rate": 0.015600000000000001,
403
+ "loss": 0.2204,
404
+ "step": 660
405
+ },
406
+ {
407
+ "epoch": 2.99,
408
+ "learning_rate": 0.015533333333333333,
409
+ "loss": 0.2243,
410
+ "step": 670
411
+ },
412
+ {
413
+ "epoch": 3.03,
414
+ "learning_rate": 0.015466666666666667,
415
+ "loss": 0.2,
416
+ "step": 680
417
+ },
418
+ {
419
+ "epoch": 3.08,
420
+ "learning_rate": 0.0154,
421
+ "loss": 0.2016,
422
+ "step": 690
423
+ },
424
+ {
425
+ "epoch": 3.12,
426
+ "learning_rate": 0.015333333333333334,
427
+ "loss": 0.2251,
428
+ "step": 700
429
+ },
430
+ {
431
+ "epoch": 3.17,
432
+ "learning_rate": 0.015266666666666666,
433
+ "loss": 0.2055,
434
+ "step": 710
435
+ },
436
+ {
437
+ "epoch": 3.21,
438
+ "learning_rate": 0.0152,
439
+ "loss": 0.2205,
440
+ "step": 720
441
+ },
442
+ {
443
+ "epoch": 3.25,
444
+ "learning_rate": 0.015133333333333334,
445
+ "loss": 0.2066,
446
+ "step": 730
447
+ },
448
+ {
449
+ "epoch": 3.3,
450
+ "learning_rate": 0.015066666666666666,
451
+ "loss": 0.2174,
452
+ "step": 740
453
+ },
454
+ {
455
+ "epoch": 3.34,
456
+ "learning_rate": 0.015,
457
+ "loss": 0.2163,
458
+ "step": 750
459
+ },
460
+ {
461
+ "epoch": 3.39,
462
+ "learning_rate": 0.014933333333333335,
463
+ "loss": 0.2049,
464
+ "step": 760
465
+ },
466
+ {
467
+ "epoch": 3.43,
468
+ "learning_rate": 0.014866666666666667,
469
+ "loss": 0.2039,
470
+ "step": 770
471
+ },
472
+ {
473
+ "epoch": 3.48,
474
+ "learning_rate": 0.0148,
475
+ "loss": 0.1941,
476
+ "step": 780
477
+ },
478
+ {
479
+ "epoch": 3.52,
480
+ "learning_rate": 0.014733333333333334,
481
+ "loss": 0.2051,
482
+ "step": 790
483
+ },
484
+ {
485
+ "epoch": 3.57,
486
+ "learning_rate": 0.014666666666666666,
487
+ "loss": 0.2097,
488
+ "step": 800
489
+ },
490
+ {
491
+ "epoch": 3.61,
492
+ "learning_rate": 0.0146,
493
+ "loss": 0.2104,
494
+ "step": 810
495
+ },
496
+ {
497
+ "epoch": 3.66,
498
+ "learning_rate": 0.014533333333333334,
499
+ "loss": 0.2157,
500
+ "step": 820
501
+ },
502
+ {
503
+ "epoch": 3.7,
504
+ "learning_rate": 0.014466666666666668,
505
+ "loss": 0.2053,
506
+ "step": 830
507
+ },
508
+ {
509
+ "epoch": 3.74,
510
+ "learning_rate": 0.0144,
511
+ "loss": 0.2005,
512
+ "step": 840
513
+ },
514
+ {
515
+ "epoch": 3.79,
516
+ "learning_rate": 0.014333333333333333,
517
+ "loss": 0.2075,
518
+ "step": 850
519
+ },
520
+ {
521
+ "epoch": 3.83,
522
+ "learning_rate": 0.014266666666666667,
523
+ "loss": 0.2065,
524
+ "step": 860
525
+ },
526
+ {
527
+ "epoch": 3.88,
528
+ "learning_rate": 0.014199999999999999,
529
+ "loss": 0.2091,
530
+ "step": 870
531
+ },
532
+ {
533
+ "epoch": 3.92,
534
+ "learning_rate": 0.014133333333333333,
535
+ "loss": 0.2003,
536
+ "step": 880
537
+ },
538
+ {
539
+ "epoch": 3.97,
540
+ "learning_rate": 0.014066666666666668,
541
+ "loss": 0.2111,
542
+ "step": 890
543
+ },
544
+ {
545
+ "epoch": 4.01,
546
+ "learning_rate": 0.013999999999999999,
547
+ "loss": 0.2019,
548
+ "step": 900
549
+ },
550
+ {
551
+ "epoch": 4.06,
552
+ "learning_rate": 0.013933333333333334,
553
+ "loss": 0.1953,
554
+ "step": 910
555
+ },
556
+ {
557
+ "epoch": 4.1,
558
+ "learning_rate": 0.013866666666666668,
559
+ "loss": 0.1912,
560
+ "step": 920
561
+ },
562
+ {
563
+ "epoch": 4.15,
564
+ "learning_rate": 0.0138,
565
+ "loss": 0.1947,
566
+ "step": 930
567
+ },
568
+ {
569
+ "epoch": 4.19,
570
+ "learning_rate": 0.013733333333333334,
571
+ "loss": 0.1879,
572
+ "step": 940
573
+ },
574
+ {
575
+ "epoch": 4.24,
576
+ "learning_rate": 0.013666666666666667,
577
+ "loss": 0.1923,
578
+ "step": 950
579
+ },
580
+ {
581
+ "epoch": 4.28,
582
+ "learning_rate": 0.013600000000000001,
583
+ "loss": 0.1841,
584
+ "step": 960
585
+ },
586
+ {
587
+ "epoch": 4.32,
588
+ "learning_rate": 0.013533333333333333,
589
+ "loss": 0.1878,
590
+ "step": 970
591
+ },
592
+ {
593
+ "epoch": 4.37,
594
+ "learning_rate": 0.013466666666666667,
595
+ "loss": 0.192,
596
+ "step": 980
597
+ },
598
+ {
599
+ "epoch": 4.41,
600
+ "learning_rate": 0.0134,
601
+ "loss": 0.186,
602
+ "step": 990
603
+ },
604
+ {
605
+ "epoch": 4.46,
606
+ "learning_rate": 0.013333333333333332,
607
+ "loss": 0.1852,
608
+ "step": 1000
609
+ },
610
+ {
611
+ "epoch": 4.5,
612
+ "learning_rate": 0.013266666666666666,
613
+ "loss": 0.1861,
614
+ "step": 1010
615
+ },
616
+ {
617
+ "epoch": 4.55,
618
+ "learning_rate": 0.013200000000000002,
619
+ "loss": 0.1871,
620
+ "step": 1020
621
+ },
622
+ {
623
+ "epoch": 4.59,
624
+ "learning_rate": 0.013133333333333332,
625
+ "loss": 0.1843,
626
+ "step": 1030
627
+ },
628
+ {
629
+ "epoch": 4.64,
630
+ "learning_rate": 0.013066666666666667,
631
+ "loss": 0.1981,
632
+ "step": 1040
633
+ },
634
+ {
635
+ "epoch": 4.68,
636
+ "learning_rate": 0.013000000000000001,
637
+ "loss": 0.1956,
638
+ "step": 1050
639
+ },
640
+ {
641
+ "epoch": 4.73,
642
+ "learning_rate": 0.012933333333333333,
643
+ "loss": 0.1903,
644
+ "step": 1060
645
+ },
646
+ {
647
+ "epoch": 4.77,
648
+ "learning_rate": 0.012866666666666667,
649
+ "loss": 0.1966,
650
+ "step": 1070
651
+ },
652
+ {
653
+ "epoch": 4.81,
654
+ "learning_rate": 0.0128,
655
+ "loss": 0.1977,
656
+ "step": 1080
657
+ },
658
+ {
659
+ "epoch": 4.86,
660
+ "learning_rate": 0.012733333333333334,
661
+ "loss": 0.1907,
662
+ "step": 1090
663
+ },
664
+ {
665
+ "epoch": 4.9,
666
+ "learning_rate": 0.012666666666666666,
667
+ "loss": 0.1775,
668
+ "step": 1100
669
+ },
670
+ {
671
+ "epoch": 4.95,
672
+ "learning_rate": 0.0126,
673
+ "loss": 0.1932,
674
+ "step": 1110
675
+ },
676
+ {
677
+ "epoch": 4.99,
678
+ "learning_rate": 0.012533333333333334,
679
+ "loss": 0.1992,
680
+ "step": 1120
681
+ },
682
+ {
683
+ "epoch": 5.04,
684
+ "learning_rate": 0.012466666666666666,
685
+ "loss": 0.1872,
686
+ "step": 1130
687
+ },
688
+ {
689
+ "epoch": 5.08,
690
+ "learning_rate": 0.0124,
691
+ "loss": 0.1682,
692
+ "step": 1140
693
+ },
694
+ {
695
+ "epoch": 5.13,
696
+ "learning_rate": 0.012333333333333335,
697
+ "loss": 0.1684,
698
+ "step": 1150
699
+ },
700
+ {
701
+ "epoch": 5.17,
702
+ "learning_rate": 0.012266666666666665,
703
+ "loss": 0.1823,
704
+ "step": 1160
705
+ },
706
+ {
707
+ "epoch": 5.22,
708
+ "learning_rate": 0.0122,
709
+ "loss": 0.1803,
710
+ "step": 1170
711
+ },
712
+ {
713
+ "epoch": 5.26,
714
+ "learning_rate": 0.012133333333333335,
715
+ "loss": 0.1794,
716
+ "step": 1180
717
+ },
718
+ {
719
+ "epoch": 5.31,
720
+ "learning_rate": 0.012066666666666668,
721
+ "loss": 0.1902,
722
+ "step": 1190
723
+ },
724
+ {
725
+ "epoch": 5.35,
726
+ "learning_rate": 0.012,
727
+ "loss": 0.1783,
728
+ "step": 1200
729
+ },
730
+ {
731
+ "epoch": 5.39,
732
+ "learning_rate": 0.011933333333333334,
733
+ "loss": 0.1851,
734
+ "step": 1210
735
+ },
736
+ {
737
+ "epoch": 5.44,
738
+ "learning_rate": 0.011866666666666668,
739
+ "loss": 0.1963,
740
+ "step": 1220
741
+ },
742
+ {
743
+ "epoch": 5.48,
744
+ "learning_rate": 0.0118,
745
+ "loss": 0.18,
746
+ "step": 1230
747
+ },
748
+ {
749
+ "epoch": 5.53,
750
+ "learning_rate": 0.011733333333333333,
751
+ "loss": 0.1805,
752
+ "step": 1240
753
+ },
754
+ {
755
+ "epoch": 5.57,
756
+ "learning_rate": 0.011666666666666667,
757
+ "loss": 0.1765,
758
+ "step": 1250
759
+ },
760
+ {
761
+ "epoch": 5.62,
762
+ "learning_rate": 0.0116,
763
+ "loss": 0.1687,
764
+ "step": 1260
765
+ },
766
+ {
767
+ "epoch": 5.66,
768
+ "learning_rate": 0.011533333333333333,
769
+ "loss": 0.1852,
770
+ "step": 1270
771
+ },
772
+ {
773
+ "epoch": 5.71,
774
+ "learning_rate": 0.011466666666666667,
775
+ "loss": 0.1854,
776
+ "step": 1280
777
+ },
778
+ {
779
+ "epoch": 5.75,
780
+ "learning_rate": 0.011399999999999999,
781
+ "loss": 0.1745,
782
+ "step": 1290
783
+ },
784
+ {
785
+ "epoch": 5.8,
786
+ "learning_rate": 0.011333333333333332,
787
+ "loss": 0.1802,
788
+ "step": 1300
789
+ },
790
+ {
791
+ "epoch": 5.84,
792
+ "learning_rate": 0.011266666666666668,
793
+ "loss": 0.1892,
794
+ "step": 1310
795
+ },
796
+ {
797
+ "epoch": 5.88,
798
+ "learning_rate": 0.011200000000000002,
799
+ "loss": 0.1908,
800
+ "step": 1320
801
+ },
802
+ {
803
+ "epoch": 5.93,
804
+ "learning_rate": 0.011133333333333334,
805
+ "loss": 0.1898,
806
+ "step": 1330
807
+ },
808
+ {
809
+ "epoch": 5.97,
810
+ "learning_rate": 0.011066666666666667,
811
+ "loss": 0.1881,
812
+ "step": 1340
813
+ },
814
+ {
815
+ "epoch": 6.02,
816
+ "learning_rate": 0.011000000000000001,
817
+ "loss": 0.1784,
818
+ "step": 1350
819
+ },
820
+ {
821
+ "epoch": 6.06,
822
+ "learning_rate": 0.010933333333333333,
823
+ "loss": 0.1814,
824
+ "step": 1360
825
+ },
826
+ {
827
+ "epoch": 6.11,
828
+ "learning_rate": 0.010866666666666667,
829
+ "loss": 0.1724,
830
+ "step": 1370
831
+ },
832
+ {
833
+ "epoch": 6.15,
834
+ "learning_rate": 0.0108,
835
+ "loss": 0.178,
836
+ "step": 1380
837
+ },
838
+ {
839
+ "epoch": 6.2,
840
+ "learning_rate": 0.010733333333333333,
841
+ "loss": 0.1707,
842
+ "step": 1390
843
+ },
844
+ {
845
+ "epoch": 6.24,
846
+ "learning_rate": 0.010666666666666666,
847
+ "loss": 0.1711,
848
+ "step": 1400
849
+ },
850
+ {
851
+ "epoch": 6.29,
852
+ "learning_rate": 0.0106,
853
+ "loss": 0.1626,
854
+ "step": 1410
855
+ },
856
+ {
857
+ "epoch": 6.33,
858
+ "learning_rate": 0.010533333333333332,
859
+ "loss": 0.1676,
860
+ "step": 1420
861
+ },
862
+ {
863
+ "epoch": 6.38,
864
+ "learning_rate": 0.010466666666666666,
865
+ "loss": 0.1632,
866
+ "step": 1430
867
+ },
868
+ {
869
+ "epoch": 6.42,
870
+ "learning_rate": 0.010400000000000001,
871
+ "loss": 0.171,
872
+ "step": 1440
873
+ },
874
+ {
875
+ "epoch": 6.46,
876
+ "learning_rate": 0.010333333333333335,
877
+ "loss": 0.1746,
878
+ "step": 1450
879
+ },
880
+ {
881
+ "epoch": 6.51,
882
+ "learning_rate": 0.010266666666666667,
883
+ "loss": 0.1764,
884
+ "step": 1460
885
+ },
886
+ {
887
+ "epoch": 6.55,
888
+ "learning_rate": 0.0102,
889
+ "loss": 0.1805,
890
+ "step": 1470
891
+ },
892
+ {
893
+ "epoch": 6.6,
894
+ "learning_rate": 0.010133333333333334,
895
+ "loss": 0.1759,
896
+ "step": 1480
897
+ },
898
+ {
899
+ "epoch": 6.64,
900
+ "learning_rate": 0.010066666666666666,
901
+ "loss": 0.1798,
902
+ "step": 1490
903
+ },
904
+ {
905
+ "epoch": 6.69,
906
+ "learning_rate": 0.01,
907
+ "loss": 0.1673,
908
+ "step": 1500
909
+ },
910
+ {
911
+ "epoch": 6.73,
912
+ "learning_rate": 0.009933333333333334,
913
+ "loss": 0.185,
914
+ "step": 1510
915
+ },
916
+ {
917
+ "epoch": 6.78,
918
+ "learning_rate": 0.009866666666666668,
919
+ "loss": 0.1712,
920
+ "step": 1520
921
+ },
922
+ {
923
+ "epoch": 6.82,
924
+ "learning_rate": 0.0098,
925
+ "loss": 0.1586,
926
+ "step": 1530
927
+ },
928
+ {
929
+ "epoch": 6.87,
930
+ "learning_rate": 0.009733333333333333,
931
+ "loss": 0.1709,
932
+ "step": 1540
933
+ },
934
+ {
935
+ "epoch": 6.91,
936
+ "learning_rate": 0.009666666666666667,
937
+ "loss": 0.1657,
938
+ "step": 1550
939
+ },
940
+ {
941
+ "epoch": 6.95,
942
+ "learning_rate": 0.0096,
943
+ "loss": 0.1738,
944
+ "step": 1560
945
+ },
946
+ {
947
+ "epoch": 7.0,
948
+ "learning_rate": 0.009533333333333335,
949
+ "loss": 0.1633,
950
+ "step": 1570
951
+ },
952
+ {
953
+ "epoch": 7.04,
954
+ "learning_rate": 0.009466666666666667,
955
+ "loss": 0.167,
956
+ "step": 1580
957
+ },
958
+ {
959
+ "epoch": 7.09,
960
+ "learning_rate": 0.0094,
961
+ "loss": 0.1629,
962
+ "step": 1590
963
+ },
964
+ {
965
+ "epoch": 7.13,
966
+ "learning_rate": 0.009333333333333334,
967
+ "loss": 0.1679,
968
+ "step": 1600
969
+ },
970
+ {
971
+ "epoch": 7.18,
972
+ "learning_rate": 0.009266666666666666,
973
+ "loss": 0.1639,
974
+ "step": 1610
975
+ },
976
+ {
977
+ "epoch": 7.22,
978
+ "learning_rate": 0.0092,
979
+ "loss": 0.1652,
980
+ "step": 1620
981
+ },
982
+ {
983
+ "epoch": 7.27,
984
+ "learning_rate": 0.009133333333333334,
985
+ "loss": 0.17,
986
+ "step": 1630
987
+ },
988
+ {
989
+ "epoch": 7.31,
990
+ "learning_rate": 0.009066666666666666,
991
+ "loss": 0.1663,
992
+ "step": 1640
993
+ },
994
+ {
995
+ "epoch": 7.36,
996
+ "learning_rate": 0.009000000000000001,
997
+ "loss": 0.165,
998
+ "step": 1650
999
+ },
1000
+ {
1001
+ "epoch": 7.4,
1002
+ "learning_rate": 0.008933333333333333,
1003
+ "loss": 0.1724,
1004
+ "step": 1660
1005
+ },
1006
+ {
1007
+ "epoch": 7.44,
1008
+ "learning_rate": 0.008866666666666667,
1009
+ "loss": 0.1708,
1010
+ "step": 1670
1011
+ },
1012
+ {
1013
+ "epoch": 7.49,
1014
+ "learning_rate": 0.0088,
1015
+ "loss": 0.1673,
1016
+ "step": 1680
1017
+ },
1018
+ {
1019
+ "epoch": 7.53,
1020
+ "learning_rate": 0.008733333333333333,
1021
+ "loss": 0.1707,
1022
+ "step": 1690
1023
+ },
1024
+ {
1025
+ "epoch": 7.58,
1026
+ "learning_rate": 0.008666666666666668,
1027
+ "loss": 0.1633,
1028
+ "step": 1700
1029
+ },
1030
+ {
1031
+ "epoch": 7.62,
1032
+ "learning_rate": 0.0086,
1033
+ "loss": 0.1624,
1034
+ "step": 1710
1035
+ },
1036
+ {
1037
+ "epoch": 7.67,
1038
+ "learning_rate": 0.008533333333333334,
1039
+ "loss": 0.1574,
1040
+ "step": 1720
1041
+ },
1042
+ {
1043
+ "epoch": 7.71,
1044
+ "learning_rate": 0.008466666666666667,
1045
+ "loss": 0.1678,
1046
+ "step": 1730
1047
+ },
1048
+ {
1049
+ "epoch": 7.76,
1050
+ "learning_rate": 0.0084,
1051
+ "loss": 0.1625,
1052
+ "step": 1740
1053
+ },
1054
+ {
1055
+ "epoch": 7.8,
1056
+ "learning_rate": 0.008333333333333333,
1057
+ "loss": 0.1696,
1058
+ "step": 1750
1059
+ },
1060
+ {
1061
+ "epoch": 7.85,
1062
+ "learning_rate": 0.008266666666666667,
1063
+ "loss": 0.1577,
1064
+ "step": 1760
1065
+ },
1066
+ {
1067
+ "epoch": 7.89,
1068
+ "learning_rate": 0.008199999999999999,
1069
+ "loss": 0.1716,
1070
+ "step": 1770
1071
+ },
1072
+ {
1073
+ "epoch": 7.94,
1074
+ "learning_rate": 0.008133333333333334,
1075
+ "loss": 0.1687,
1076
+ "step": 1780
1077
+ },
1078
+ {
1079
+ "epoch": 7.98,
1080
+ "learning_rate": 0.008066666666666666,
1081
+ "loss": 0.1638,
1082
+ "step": 1790
1083
+ },
1084
+ {
1085
+ "epoch": 8.02,
1086
+ "learning_rate": 0.008,
1087
+ "loss": 0.1557,
1088
+ "step": 1800
1089
+ },
1090
+ {
1091
+ "epoch": 8.07,
1092
+ "learning_rate": 0.007933333333333334,
1093
+ "loss": 0.1536,
1094
+ "step": 1810
1095
+ },
1096
+ {
1097
+ "epoch": 8.11,
1098
+ "learning_rate": 0.007866666666666666,
1099
+ "loss": 0.1661,
1100
+ "step": 1820
1101
+ },
1102
+ {
1103
+ "epoch": 8.16,
1104
+ "learning_rate": 0.0078000000000000005,
1105
+ "loss": 0.1609,
1106
+ "step": 1830
1107
+ },
1108
+ {
1109
+ "epoch": 8.2,
1110
+ "learning_rate": 0.007733333333333333,
1111
+ "loss": 0.1561,
1112
+ "step": 1840
1113
+ },
1114
+ {
1115
+ "epoch": 8.25,
1116
+ "learning_rate": 0.007666666666666667,
1117
+ "loss": 0.1547,
1118
+ "step": 1850
1119
+ },
1120
+ {
1121
+ "epoch": 8.29,
1122
+ "learning_rate": 0.0076,
1123
+ "loss": 0.1685,
1124
+ "step": 1860
1125
+ },
1126
+ {
1127
+ "epoch": 8.34,
1128
+ "learning_rate": 0.007533333333333333,
1129
+ "loss": 0.1649,
1130
+ "step": 1870
1131
+ },
1132
+ {
1133
+ "epoch": 8.38,
1134
+ "learning_rate": 0.0074666666666666675,
1135
+ "loss": 0.1585,
1136
+ "step": 1880
1137
+ },
1138
+ {
1139
+ "epoch": 8.43,
1140
+ "learning_rate": 0.0074,
1141
+ "loss": 0.1659,
1142
+ "step": 1890
1143
+ },
1144
+ {
1145
+ "epoch": 8.47,
1146
+ "learning_rate": 0.007333333333333333,
1147
+ "loss": 0.1563,
1148
+ "step": 1900
1149
+ },
1150
+ {
1151
+ "epoch": 8.51,
1152
+ "learning_rate": 0.007266666666666667,
1153
+ "loss": 0.16,
1154
+ "step": 1910
1155
+ },
1156
+ {
1157
+ "epoch": 8.56,
1158
+ "learning_rate": 0.0072,
1159
+ "loss": 0.1643,
1160
+ "step": 1920
1161
+ },
1162
+ {
1163
+ "epoch": 8.6,
1164
+ "learning_rate": 0.0071333333333333335,
1165
+ "loss": 0.1556,
1166
+ "step": 1930
1167
+ },
1168
+ {
1169
+ "epoch": 8.65,
1170
+ "learning_rate": 0.007066666666666666,
1171
+ "loss": 0.1618,
1172
+ "step": 1940
1173
+ },
1174
+ {
1175
+ "epoch": 8.69,
1176
+ "learning_rate": 0.006999999999999999,
1177
+ "loss": 0.1608,
1178
+ "step": 1950
1179
+ },
1180
+ {
1181
+ "epoch": 8.74,
1182
+ "learning_rate": 0.006933333333333334,
1183
+ "loss": 0.1622,
1184
+ "step": 1960
1185
+ },
1186
+ {
1187
+ "epoch": 8.78,
1188
+ "learning_rate": 0.006866666666666667,
1189
+ "loss": 0.1686,
1190
+ "step": 1970
1191
+ },
1192
+ {
1193
+ "epoch": 8.83,
1194
+ "learning_rate": 0.0068000000000000005,
1195
+ "loss": 0.1624,
1196
+ "step": 1980
1197
+ },
1198
+ {
1199
+ "epoch": 8.87,
1200
+ "learning_rate": 0.006733333333333333,
1201
+ "loss": 0.1623,
1202
+ "step": 1990
1203
+ },
1204
+ {
1205
+ "epoch": 8.92,
1206
+ "learning_rate": 0.006666666666666666,
1207
+ "loss": 0.1658,
1208
+ "step": 2000
1209
+ },
1210
+ {
1211
+ "epoch": 8.96,
1212
+ "learning_rate": 0.006600000000000001,
1213
+ "loss": 0.1679,
1214
+ "step": 2010
1215
+ },
1216
+ {
1217
+ "epoch": 9.01,
1218
+ "learning_rate": 0.006533333333333334,
1219
+ "loss": 0.1573,
1220
+ "step": 2020
1221
+ },
1222
+ {
1223
+ "epoch": 9.05,
1224
+ "learning_rate": 0.006466666666666667,
1225
+ "loss": 0.1582,
1226
+ "step": 2030
1227
+ },
1228
+ {
1229
+ "epoch": 9.09,
1230
+ "learning_rate": 0.0064,
1231
+ "loss": 0.1576,
1232
+ "step": 2040
1233
+ },
1234
+ {
1235
+ "epoch": 9.14,
1236
+ "learning_rate": 0.006333333333333333,
1237
+ "loss": 0.1599,
1238
+ "step": 2050
1239
+ },
1240
+ {
1241
+ "epoch": 9.18,
1242
+ "learning_rate": 0.006266666666666667,
1243
+ "loss": 0.1574,
1244
+ "step": 2060
1245
+ },
1246
+ {
1247
+ "epoch": 9.23,
1248
+ "learning_rate": 0.0062,
1249
+ "loss": 0.1628,
1250
+ "step": 2070
1251
+ },
1252
+ {
1253
+ "epoch": 9.27,
1254
+ "learning_rate": 0.006133333333333333,
1255
+ "loss": 0.1622,
1256
+ "step": 2080
1257
+ },
1258
+ {
1259
+ "epoch": 9.32,
1260
+ "learning_rate": 0.006066666666666667,
1261
+ "loss": 0.1496,
1262
+ "step": 2090
1263
+ },
1264
+ {
1265
+ "epoch": 9.36,
1266
+ "learning_rate": 0.006,
1267
+ "loss": 0.1581,
1268
+ "step": 2100
1269
+ },
1270
+ {
1271
+ "epoch": 9.41,
1272
+ "learning_rate": 0.005933333333333334,
1273
+ "loss": 0.1645,
1274
+ "step": 2110
1275
+ },
1276
+ {
1277
+ "epoch": 9.45,
1278
+ "learning_rate": 0.005866666666666667,
1279
+ "loss": 0.161,
1280
+ "step": 2120
1281
+ },
1282
+ {
1283
+ "epoch": 9.5,
1284
+ "learning_rate": 0.0058,
1285
+ "loss": 0.1534,
1286
+ "step": 2130
1287
+ },
1288
+ {
1289
+ "epoch": 9.54,
1290
+ "learning_rate": 0.005733333333333333,
1291
+ "loss": 0.155,
1292
+ "step": 2140
1293
+ },
1294
+ {
1295
+ "epoch": 9.58,
1296
+ "learning_rate": 0.005666666666666666,
1297
+ "loss": 0.1496,
1298
+ "step": 2150
1299
+ },
1300
+ {
1301
+ "epoch": 9.63,
1302
+ "learning_rate": 0.005600000000000001,
1303
+ "loss": 0.1585,
1304
+ "step": 2160
1305
+ },
1306
+ {
1307
+ "epoch": 9.67,
1308
+ "learning_rate": 0.005533333333333334,
1309
+ "loss": 0.1522,
1310
+ "step": 2170
1311
+ },
1312
+ {
1313
+ "epoch": 9.72,
1314
+ "learning_rate": 0.0054666666666666665,
1315
+ "loss": 0.1493,
1316
+ "step": 2180
1317
+ },
1318
+ {
1319
+ "epoch": 9.76,
1320
+ "learning_rate": 0.0054,
1321
+ "loss": 0.1549,
1322
+ "step": 2190
1323
+ },
1324
+ {
1325
+ "epoch": 9.81,
1326
+ "learning_rate": 0.005333333333333333,
1327
+ "loss": 0.1544,
1328
+ "step": 2200
1329
+ },
1330
+ {
1331
+ "epoch": 9.85,
1332
+ "learning_rate": 0.005266666666666666,
1333
+ "loss": 0.1639,
1334
+ "step": 2210
1335
+ },
1336
+ {
1337
+ "epoch": 9.9,
1338
+ "learning_rate": 0.005200000000000001,
1339
+ "loss": 0.1643,
1340
+ "step": 2220
1341
+ },
1342
+ {
1343
+ "epoch": 9.94,
1344
+ "learning_rate": 0.0051333333333333335,
1345
+ "loss": 0.153,
1346
+ "step": 2230
1347
+ },
1348
+ {
1349
+ "epoch": 9.99,
1350
+ "learning_rate": 0.005066666666666667,
1351
+ "loss": 0.1702,
1352
+ "step": 2240
1353
+ },
1354
+ {
1355
+ "epoch": 10.03,
1356
+ "learning_rate": 0.005,
1357
+ "loss": 0.1538,
1358
+ "step": 2250
1359
+ },
1360
+ {
1361
+ "epoch": 10.08,
1362
+ "learning_rate": 0.004933333333333334,
1363
+ "loss": 0.1495,
1364
+ "step": 2260
1365
+ },
1366
+ {
1367
+ "epoch": 10.12,
1368
+ "learning_rate": 0.004866666666666667,
1369
+ "loss": 0.1484,
1370
+ "step": 2270
1371
+ },
1372
+ {
1373
+ "epoch": 10.16,
1374
+ "learning_rate": 0.0048,
1375
+ "loss": 0.1577,
1376
+ "step": 2280
1377
+ },
1378
+ {
1379
+ "epoch": 10.21,
1380
+ "learning_rate": 0.004733333333333333,
1381
+ "loss": 0.1502,
1382
+ "step": 2290
1383
+ },
1384
+ {
1385
+ "epoch": 10.25,
1386
+ "learning_rate": 0.004666666666666667,
1387
+ "loss": 0.1511,
1388
+ "step": 2300
1389
+ },
1390
+ {
1391
+ "epoch": 10.3,
1392
+ "learning_rate": 0.0046,
1393
+ "loss": 0.1619,
1394
+ "step": 2310
1395
+ },
1396
+ {
1397
+ "epoch": 10.34,
1398
+ "learning_rate": 0.004533333333333333,
1399
+ "loss": 0.1556,
1400
+ "step": 2320
1401
+ },
1402
+ {
1403
+ "epoch": 10.39,
1404
+ "learning_rate": 0.0044666666666666665,
1405
+ "loss": 0.1627,
1406
+ "step": 2330
1407
+ },
1408
+ {
1409
+ "epoch": 10.43,
1410
+ "learning_rate": 0.0044,
1411
+ "loss": 0.1516,
1412
+ "step": 2340
1413
+ },
1414
+ {
1415
+ "epoch": 10.48,
1416
+ "learning_rate": 0.004333333333333334,
1417
+ "loss": 0.1503,
1418
+ "step": 2350
1419
+ },
1420
+ {
1421
+ "epoch": 10.52,
1422
+ "learning_rate": 0.004266666666666667,
1423
+ "loss": 0.1562,
1424
+ "step": 2360
1425
+ },
1426
+ {
1427
+ "epoch": 10.57,
1428
+ "learning_rate": 0.0042,
1429
+ "loss": 0.1629,
1430
+ "step": 2370
1431
+ },
1432
+ {
1433
+ "epoch": 10.61,
1434
+ "learning_rate": 0.0041333333333333335,
1435
+ "loss": 0.1622,
1436
+ "step": 2380
1437
+ },
1438
+ {
1439
+ "epoch": 10.65,
1440
+ "learning_rate": 0.004066666666666667,
1441
+ "loss": 0.1509,
1442
+ "step": 2390
1443
+ },
1444
+ {
1445
+ "epoch": 10.7,
1446
+ "learning_rate": 0.004,
1447
+ "loss": 0.1598,
1448
+ "step": 2400
1449
+ },
1450
+ {
1451
+ "epoch": 10.74,
1452
+ "learning_rate": 0.003933333333333333,
1453
+ "loss": 0.1556,
1454
+ "step": 2410
1455
+ },
1456
+ {
1457
+ "epoch": 10.79,
1458
+ "learning_rate": 0.0038666666666666667,
1459
+ "loss": 0.154,
1460
+ "step": 2420
1461
+ },
1462
+ {
1463
+ "epoch": 10.83,
1464
+ "learning_rate": 0.0038,
1465
+ "loss": 0.1489,
1466
+ "step": 2430
1467
+ },
1468
+ {
1469
+ "epoch": 10.88,
1470
+ "learning_rate": 0.0037333333333333337,
1471
+ "loss": 0.1506,
1472
+ "step": 2440
1473
+ },
1474
+ {
1475
+ "epoch": 10.92,
1476
+ "learning_rate": 0.0036666666666666666,
1477
+ "loss": 0.1514,
1478
+ "step": 2450
1479
+ },
1480
+ {
1481
+ "epoch": 10.97,
1482
+ "learning_rate": 0.0036,
1483
+ "loss": 0.1543,
1484
+ "step": 2460
1485
+ },
1486
+ {
1487
+ "epoch": 11.01,
1488
+ "learning_rate": 0.003533333333333333,
1489
+ "loss": 0.155,
1490
+ "step": 2470
1491
+ },
1492
+ {
1493
+ "epoch": 11.06,
1494
+ "learning_rate": 0.003466666666666667,
1495
+ "loss": 0.1564,
1496
+ "step": 2480
1497
+ },
1498
+ {
1499
+ "epoch": 11.1,
1500
+ "learning_rate": 0.0034000000000000002,
1501
+ "loss": 0.1396,
1502
+ "step": 2490
1503
+ },
1504
+ {
1505
+ "epoch": 11.15,
1506
+ "learning_rate": 0.003333333333333333,
1507
+ "loss": 0.1572,
1508
+ "step": 2500
1509
+ },
1510
+ {
1511
+ "epoch": 11.19,
1512
+ "learning_rate": 0.003266666666666667,
1513
+ "loss": 0.1472,
1514
+ "step": 2510
1515
+ },
1516
+ {
1517
+ "epoch": 11.23,
1518
+ "learning_rate": 0.0032,
1519
+ "loss": 0.1519,
1520
+ "step": 2520
1521
+ },
1522
+ {
1523
+ "epoch": 11.28,
1524
+ "learning_rate": 0.0031333333333333335,
1525
+ "loss": 0.1547,
1526
+ "step": 2530
1527
+ },
1528
+ {
1529
+ "epoch": 11.32,
1530
+ "learning_rate": 0.0030666666666666663,
1531
+ "loss": 0.1499,
1532
+ "step": 2540
1533
+ },
1534
+ {
1535
+ "epoch": 11.37,
1536
+ "learning_rate": 0.003,
1537
+ "loss": 0.1516,
1538
+ "step": 2550
1539
+ },
1540
+ {
1541
+ "epoch": 11.41,
1542
+ "learning_rate": 0.0029333333333333334,
1543
+ "loss": 0.1636,
1544
+ "step": 2560
1545
+ },
1546
+ {
1547
+ "epoch": 11.46,
1548
+ "learning_rate": 0.0028666666666666667,
1549
+ "loss": 0.1424,
1550
+ "step": 2570
1551
+ },
1552
+ {
1553
+ "epoch": 11.5,
1554
+ "learning_rate": 0.0028000000000000004,
1555
+ "loss": 0.1487,
1556
+ "step": 2580
1557
+ },
1558
+ {
1559
+ "epoch": 11.55,
1560
+ "learning_rate": 0.0027333333333333333,
1561
+ "loss": 0.1531,
1562
+ "step": 2590
1563
+ },
1564
+ {
1565
+ "epoch": 11.59,
1566
+ "learning_rate": 0.0026666666666666666,
1567
+ "loss": 0.147,
1568
+ "step": 2600
1569
+ },
1570
+ {
1571
+ "epoch": 11.64,
1572
+ "learning_rate": 0.0026000000000000003,
1573
+ "loss": 0.157,
1574
+ "step": 2610
1575
+ },
1576
+ {
1577
+ "epoch": 11.68,
1578
+ "learning_rate": 0.0025333333333333336,
1579
+ "loss": 0.1572,
1580
+ "step": 2620
1581
+ },
1582
+ {
1583
+ "epoch": 11.72,
1584
+ "learning_rate": 0.002466666666666667,
1585
+ "loss": 0.154,
1586
+ "step": 2630
1587
+ },
1588
+ {
1589
+ "epoch": 11.77,
1590
+ "learning_rate": 0.0024,
1591
+ "loss": 0.1471,
1592
+ "step": 2640
1593
+ },
1594
+ {
1595
+ "epoch": 11.81,
1596
+ "learning_rate": 0.0023333333333333335,
1597
+ "loss": 0.1501,
1598
+ "step": 2650
1599
+ },
1600
+ {
1601
+ "epoch": 11.86,
1602
+ "learning_rate": 0.0022666666666666664,
1603
+ "loss": 0.1477,
1604
+ "step": 2660
1605
+ },
1606
+ {
1607
+ "epoch": 11.9,
1608
+ "learning_rate": 0.0022,
1609
+ "loss": 0.1466,
1610
+ "step": 2670
1611
+ },
1612
+ {
1613
+ "epoch": 11.95,
1614
+ "learning_rate": 0.0021333333333333334,
1615
+ "loss": 0.1582,
1616
+ "step": 2680
1617
+ },
1618
+ {
1619
+ "epoch": 11.99,
1620
+ "learning_rate": 0.0020666666666666667,
1621
+ "loss": 0.1527,
1622
+ "step": 2690
1623
+ },
1624
+ {
1625
+ "epoch": 12.04,
1626
+ "learning_rate": 0.002,
1627
+ "loss": 0.1547,
1628
+ "step": 2700
1629
+ },
1630
+ {
1631
+ "epoch": 12.08,
1632
+ "learning_rate": 0.0019333333333333333,
1633
+ "loss": 0.1492,
1634
+ "step": 2710
1635
+ },
1636
+ {
1637
+ "epoch": 12.13,
1638
+ "learning_rate": 0.0018666666666666669,
1639
+ "loss": 0.1451,
1640
+ "step": 2720
1641
+ },
1642
+ {
1643
+ "epoch": 12.17,
1644
+ "learning_rate": 0.0018,
1645
+ "loss": 0.1443,
1646
+ "step": 2730
1647
+ },
1648
+ {
1649
+ "epoch": 12.22,
1650
+ "learning_rate": 0.0017333333333333335,
1651
+ "loss": 0.1474,
1652
+ "step": 2740
1653
+ },
1654
+ {
1655
+ "epoch": 12.26,
1656
+ "learning_rate": 0.0016666666666666666,
1657
+ "loss": 0.1464,
1658
+ "step": 2750
1659
+ },
1660
+ {
1661
+ "epoch": 12.3,
1662
+ "learning_rate": 0.0016,
1663
+ "loss": 0.1523,
1664
+ "step": 2760
1665
+ },
1666
+ {
1667
+ "epoch": 12.35,
1668
+ "learning_rate": 0.0015333333333333332,
1669
+ "loss": 0.1522,
1670
+ "step": 2770
1671
+ },
1672
+ {
1673
+ "epoch": 12.39,
1674
+ "learning_rate": 0.0014666666666666667,
1675
+ "loss": 0.1479,
1676
+ "step": 2780
1677
+ },
1678
+ {
1679
+ "epoch": 12.44,
1680
+ "learning_rate": 0.0014000000000000002,
1681
+ "loss": 0.1465,
1682
+ "step": 2790
1683
+ },
1684
+ {
1685
+ "epoch": 12.48,
1686
+ "learning_rate": 0.0013333333333333333,
1687
+ "loss": 0.1439,
1688
+ "step": 2800
1689
+ },
1690
+ {
1691
+ "epoch": 12.53,
1692
+ "learning_rate": 0.0012666666666666668,
1693
+ "loss": 0.1506,
1694
+ "step": 2810
1695
+ },
1696
+ {
1697
+ "epoch": 12.57,
1698
+ "learning_rate": 0.0012,
1699
+ "loss": 0.1439,
1700
+ "step": 2820
1701
+ },
1702
+ {
1703
+ "epoch": 12.62,
1704
+ "learning_rate": 0.0011333333333333332,
1705
+ "loss": 0.1546,
1706
+ "step": 2830
1707
+ },
1708
+ {
1709
+ "epoch": 12.66,
1710
+ "learning_rate": 0.0010666666666666667,
1711
+ "loss": 0.145,
1712
+ "step": 2840
1713
+ },
1714
+ {
1715
+ "epoch": 12.71,
1716
+ "learning_rate": 0.001,
1717
+ "loss": 0.1544,
1718
+ "step": 2850
1719
+ },
1720
+ {
1721
+ "epoch": 12.75,
1722
+ "learning_rate": 0.0009333333333333334,
1723
+ "loss": 0.1494,
1724
+ "step": 2860
1725
+ },
1726
+ {
1727
+ "epoch": 12.79,
1728
+ "learning_rate": 0.0008666666666666667,
1729
+ "loss": 0.1504,
1730
+ "step": 2870
1731
+ },
1732
+ {
1733
+ "epoch": 12.84,
1734
+ "learning_rate": 0.0008,
1735
+ "loss": 0.1458,
1736
+ "step": 2880
1737
+ },
1738
+ {
1739
+ "epoch": 12.88,
1740
+ "learning_rate": 0.0007333333333333333,
1741
+ "loss": 0.1483,
1742
+ "step": 2890
1743
+ },
1744
+ {
1745
+ "epoch": 12.93,
1746
+ "learning_rate": 0.0006666666666666666,
1747
+ "loss": 0.1458,
1748
+ "step": 2900
1749
+ },
1750
+ {
1751
+ "epoch": 12.97,
1752
+ "learning_rate": 0.0006,
1753
+ "loss": 0.1481,
1754
+ "step": 2910
1755
+ },
1756
+ {
1757
+ "epoch": 13.02,
1758
+ "learning_rate": 0.0005333333333333334,
1759
+ "loss": 0.1495,
1760
+ "step": 2920
1761
+ },
1762
+ {
1763
+ "epoch": 13.06,
1764
+ "learning_rate": 0.0004666666666666667,
1765
+ "loss": 0.1429,
1766
+ "step": 2930
1767
+ },
1768
+ {
1769
+ "epoch": 13.11,
1770
+ "learning_rate": 0.0004,
1771
+ "loss": 0.1424,
1772
+ "step": 2940
1773
+ },
1774
+ {
1775
+ "epoch": 13.15,
1776
+ "learning_rate": 0.0003333333333333333,
1777
+ "loss": 0.1526,
1778
+ "step": 2950
1779
+ },
1780
+ {
1781
+ "epoch": 13.2,
1782
+ "learning_rate": 0.0002666666666666667,
1783
+ "loss": 0.147,
1784
+ "step": 2960
1785
+ },
1786
+ {
1787
+ "epoch": 13.24,
1788
+ "learning_rate": 0.0002,
1789
+ "loss": 0.1377,
1790
+ "step": 2970
1791
+ },
1792
+ {
1793
+ "epoch": 13.29,
1794
+ "learning_rate": 0.00013333333333333334,
1795
+ "loss": 0.1508,
1796
+ "step": 2980
1797
+ },
1798
+ {
1799
+ "epoch": 13.33,
1800
+ "learning_rate": 6.666666666666667e-05,
1801
+ "loss": 0.1482,
1802
+ "step": 2990
1803
+ },
1804
+ {
1805
+ "epoch": 13.37,
1806
+ "learning_rate": 0.0,
1807
+ "loss": 0.1481,
1808
+ "step": 3000
1809
+ },
1810
+ {
1811
+ "epoch": 13.37,
1812
+ "step": 3000,
1813
+ "total_flos": 1.726948703207424e+17,
1814
+ "train_loss": 0.2174228900273641,
1815
+ "train_runtime": 38888.8061,
1816
+ "train_samples_per_second": 1.234,
1817
+ "train_steps_per_second": 0.077
1818
+ }
1819
+ ],
1820
+ "max_steps": 3000,
1821
+ "num_train_epochs": 14,
1822
+ "total_flos": 1.726948703207424e+17,
1823
+ "trial_name": null,
1824
+ "trial_params": null
1825
+ }