fariliang commited on
Commit
3cecdf5
·
1 Parent(s): 1212651

Batman initialization

Browse files
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ batmanlive.mp4 filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModel, AutoTokenizer
2
+ import gradio as gr
3
+ import mdtex2html
4
+
5
+ import os
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("batmanmodel", trust_remote_code=True)
8
+ model = AutoModel.from_pretrained("batmanmodel", trust_remote_code=True).half().cuda()
9
+ model = model.eval()
10
+
11
+ """Override Chatbot.postprocess"""
12
+
13
+
14
+ def postprocess(self, y):
15
+ if y is None:
16
+ return []
17
+ for i, (message, response) in enumerate(y):
18
+ y[i] = (
19
+ None if message is None else mdtex2html.convert((message)),
20
+ None if response is None else mdtex2html.convert(response),
21
+ )
22
+ return y
23
+
24
+
25
+ gr.Chatbot.postprocess = postprocess
26
+
27
+
28
+ def parse_text(text):
29
+ """copy from https://github.com/GaiZhenbiao/ChuanhuChatGPT/"""
30
+ lines = text.split("\n")
31
+ lines = [line for line in lines if line != ""]
32
+ count = 0
33
+ for i, line in enumerate(lines):
34
+ if "```" in line:
35
+ count += 1
36
+ items = line.split('`')
37
+ if count % 2 == 1:
38
+ lines[i] = f'<pre><code class="language-{items[-1]}">'
39
+ else:
40
+ lines[i] = f'<br></code></pre>'
41
+ else:
42
+ if i > 0:
43
+ if count % 2 == 1:
44
+ line = line.replace("`", "\`")
45
+ line = line.replace("<", "&lt;")
46
+ line = line.replace(">", "&gt;")
47
+ line = line.replace(" ", "&nbsp;")
48
+ line = line.replace("*", "&ast;")
49
+ line = line.replace("_", "&lowbar;")
50
+ line = line.replace("-", "&#45;")
51
+ line = line.replace(".", "&#46;")
52
+ line = line.replace("!", "&#33;")
53
+ line = line.replace("(", "&#40;")
54
+ line = line.replace(")", "&#41;")
55
+ line = line.replace("$", "&#36;")
56
+ lines[i] = "<br>"+line
57
+ text = "".join(lines)
58
+ return text
59
+
60
+
61
+ def predict(input, chatbot, max_length, top_p, temperature, history):
62
+ chatbot.append((parse_text(input), ""))
63
+ for response, history in model.stream_chat(tokenizer, input, history, max_length=max_length, top_p=top_p,
64
+ temperature=temperature):
65
+ chatbot[-1] = (parse_text(input), parse_text(response))
66
+
67
+ yield chatbot, history
68
+
69
+
70
+ def reset_user_input():
71
+ return gr.update(value='')
72
+
73
+
74
+ def reset_state():
75
+ return [], []
76
+
77
+ def video_identity(video):
78
+ return video
79
+
80
+ with gr.Blocks() as demo:
81
+ gr.HTML("""<h1 align="center">蝙蝠通讯器</h1>""")
82
+
83
+ chatbot = gr.Chatbot()
84
+ with gr.Row():
85
+ with gr.Column(scale=4):
86
+ with gr.Column(scale=12):
87
+ user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=10).style(
88
+ container=False)
89
+ with gr.Column(min_width=32, scale=1):
90
+ submitBtn = gr.Button("和蝙蝠侠通话", variant="primary")
91
+ with gr.Column(scale=1):
92
+ emptyBtn = gr.Button("清除聊天记录")
93
+ thisvideo = gr.Video("batmanlive.mp4")
94
+ max_length = gr.Slider(0, 4096, value=2048, step=1.0, label="Maximum length", interactive=True,visible=False)
95
+ top_p = gr.Slider(0, 1, value=0.7, step=0.01, label="Top P", interactive=True,visible=False)
96
+ temperature = gr.Slider(0, 1, value=0.95, step=0.01, label="Temperature", interactive=True,visible=False)
97
+
98
+ history = gr.State([])
99
+
100
+ submitBtn.click(predict, [user_input, chatbot, max_length, top_p, temperature, history], [chatbot, history],
101
+ show_progress=True)
102
+ submitBtn.click(reset_user_input, [], [user_input])
103
+
104
+ emptyBtn.click(reset_state, outputs=[chatbot, history], show_progress=True)
105
+
106
+ demo.queue().launch(share=False, inbrowser=True)
batmanlive.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:10641ca7f0685d22b61e86aed51121230bc6a386037dba8a128dbf2f554318a7
3
+ size 473665047
batmanmodel/config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "model",
3
+ "architectures": [
4
+ "ChatGLMForConditionalGeneration"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_chatglm.ChatGLMConfig",
8
+ "AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration",
9
+ "AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration"
10
+ },
11
+ "bos_token_id": 130004,
12
+ "eos_token_id": 130005,
13
+ "gmask_token_id": 130001,
14
+ "hidden_size": 4096,
15
+ "inner_hidden_size": 16384,
16
+ "layernorm_epsilon": 1e-05,
17
+ "mask_token_id": 130000,
18
+ "max_sequence_length": 2048,
19
+ "model_type": "chatglm",
20
+ "num_attention_heads": 32,
21
+ "num_layers": 28,
22
+ "pad_token_id": 3,
23
+ "position_encoding_2d": true,
24
+ "pre_seq_len": 256,
25
+ "prefix_projection": false,
26
+ "quantization_bit": 0,
27
+ "torch_dtype": "float16",
28
+ "transformers_version": "4.27.1",
29
+ "use_cache": true,
30
+ "vocab_size": 130528
31
+ }
batmanmodel/configuration_chatglm.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ ChatGLM model configuration """
2
+
3
+ from transformers.configuration_utils import PretrainedConfig
4
+ from transformers.utils import logging
5
+
6
+ logger = logging.get_logger(__name__)
7
+
8
+
9
+ class ChatGLMConfig(PretrainedConfig):
10
+ r"""
11
+ This is the configuration class to store the configuration of a [`~ChatGLMModel`].
12
+ It is used to instantiate an ChatGLM model according to the specified arguments, defining the model
13
+ architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of
14
+ the ChatGLM-6B [THUDM/ChatGLM-6B](https://huggingface.co/THUDM/chatglm-6b) architecture.
15
+
16
+ Configuration objects inherit from [`PretrainedConfig`] and can be used
17
+ to control the model outputs. Read the documentation from [`PretrainedConfig`]
18
+ for more information.
19
+
20
+
21
+ Args:
22
+ vocab_size (`int`, *optional*, defaults to 150528):
23
+ Vocabulary size of the ChatGLM-6B model. Defines the number of different tokens that can be represented by the
24
+ `inputs_ids` passed when calling [`~ChatGLMModel`] or
25
+ [`~TFChatGLMModel`].
26
+ hidden_size (`int`, *optional*, defaults to 4096):
27
+ Dimension of the encoder layers and the pooler layer.
28
+ num_hidden_layers (`int`, *optional*, defaults to 28):
29
+ Number of hidden layers in the Transformer encoder.
30
+ num_attention_heads (`int`, *optional*, defaults to 32):
31
+ Number of attention heads for each attention layer in the Transformer encoder.
32
+ inner_hidden_size (`int`, *optional*, defaults to 16384):
33
+ Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
34
+ max_sequence_length (`int`, *optional*, defaults to 512):
35
+ The maximum sequence length that this model might ever be used with.
36
+ Typically set this to something large just in case (e.g., 512 or 1024 or 2048).
37
+ layernorm_epsilon (`float`, *optional*, defaults to 1e-5):
38
+ The epsilon used by the layer normalization layers.
39
+ use_cache (`bool`, *optional*, defaults to `True`):
40
+ Whether the model should return the last key/values attentions (not used by all models).
41
+ Example:
42
+
43
+ ```python
44
+ >>> from configuration_chatglm import ChatGLMConfig
45
+ >>> from modeling_chatglm import ChatGLMModel
46
+
47
+ >>> # Initializing a ChatGLM-6B THUDM/ChatGLM-6B style configuration
48
+ >>> configuration = ChatGLMConfig()
49
+
50
+ >>> # Initializing a model from the THUDM/ChatGLM-6B style configuration
51
+ >>> model = ChatGLMModel(configuration)
52
+
53
+ >>> # Accessing the model configuration
54
+ >>> configuration = model.config
55
+ ```
56
+ """
57
+ model_type = "chatglm"
58
+
59
+ def __init__(
60
+ self,
61
+ vocab_size=150528,
62
+ hidden_size=4096,
63
+ num_layers=28,
64
+ num_attention_heads=32,
65
+ layernorm_epsilon=1e-5,
66
+ use_cache=False,
67
+ bos_token_id=150004,
68
+ eos_token_id=150005,
69
+ mask_token_id=150000,
70
+ gmask_token_id=150001,
71
+ pad_token_id=0,
72
+ max_sequence_length=2048,
73
+ inner_hidden_size=16384,
74
+ position_encoding_2d=True,
75
+ quantization_bit=0,
76
+ pre_seq_len=None,
77
+ prefix_projection=False,
78
+ **kwargs
79
+ ):
80
+ self.num_layers = num_layers
81
+ self.vocab_size = vocab_size
82
+ self.hidden_size = hidden_size
83
+ self.num_attention_heads = num_attention_heads
84
+ self.max_sequence_length = max_sequence_length
85
+ self.layernorm_epsilon = layernorm_epsilon
86
+ self.inner_hidden_size = inner_hidden_size
87
+ self.use_cache = use_cache
88
+ self.bos_token_id = bos_token_id
89
+ self.eos_token_id = eos_token_id
90
+ self.pad_token_id = pad_token_id
91
+ self.mask_token_id = mask_token_id
92
+ self.gmask_token_id = gmask_token_id
93
+ self.position_encoding_2d = position_encoding_2d
94
+ self.quantization_bit = quantization_bit
95
+ self.pre_seq_len = pre_seq_len
96
+ self.prefix_projection = prefix_projection
97
+
98
+ super().__init__(
99
+ pad_token_id=pad_token_id,
100
+ bos_token_id=bos_token_id,
101
+ eos_token_id=eos_token_id,
102
+ **kwargs
103
+ )
batmanmodel/generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 130004,
4
+ "eos_token_id": 130005,
5
+ "pad_token_id": 3,
6
+ "transformers_version": "4.27.1"
7
+ }
batmanmodel/ice_text.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e974d9a69c242ce014c88c2b26089270f6198f3c0b700a887666cd3e816f17e
3
+ size 2706249
batmanmodel/modeling_chatglm.py ADDED
@@ -0,0 +1,1403 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ PyTorch ChatGLM model. """
2
+
3
+ import math
4
+ import copy
5
+ import os
6
+ import warnings
7
+ import re
8
+ import sys
9
+
10
+ import torch
11
+ import torch.utils.checkpoint
12
+ import torch.nn.functional as F
13
+ from torch import nn
14
+ from torch.nn import CrossEntropyLoss, LayerNorm
15
+ from torch.nn.utils import skip_init
16
+ from typing import Optional, Tuple, Union, List, Callable, Dict, Any
17
+
18
+ from transformers.utils import (
19
+ add_code_sample_docstrings,
20
+ add_start_docstrings,
21
+ add_start_docstrings_to_model_forward,
22
+ )
23
+ from transformers.modeling_outputs import (
24
+ BaseModelOutputWithPast,
25
+ CausalLMOutputWithPast,
26
+ BaseModelOutputWithPastAndCrossAttentions,
27
+ )
28
+ from transformers.modeling_utils import PreTrainedModel
29
+ from transformers.utils import logging
30
+ from transformers.generation.logits_process import LogitsProcessor
31
+ from transformers.generation.utils import LogitsProcessorList, StoppingCriteriaList, GenerationConfig, ModelOutput
32
+
33
+ from .configuration_chatglm import ChatGLMConfig
34
+
35
+ # flags required to enable jit fusion kernels
36
+
37
+ if sys.platform != 'darwin':
38
+ torch._C._jit_set_profiling_mode(False)
39
+ torch._C._jit_set_profiling_executor(False)
40
+ torch._C._jit_override_can_fuse_on_cpu(True)
41
+ torch._C._jit_override_can_fuse_on_gpu(True)
42
+
43
+ logger = logging.get_logger(__name__)
44
+
45
+ _CHECKPOINT_FOR_DOC = "THUDM/ChatGLM-6B"
46
+ _CONFIG_FOR_DOC = "ChatGLM6BConfig"
47
+
48
+ CHATGLM_6B_PRETRAINED_MODEL_ARCHIVE_LIST = [
49
+ "THUDM/chatglm-6b",
50
+ # See all ChatGLM-6B models at https://huggingface.co/models?filter=chatglm
51
+ ]
52
+
53
+
54
+ class InvalidScoreLogitsProcessor(LogitsProcessor):
55
+ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
56
+ if torch.isnan(scores).any() or torch.isinf(scores).any():
57
+ scores.zero_()
58
+ scores[..., 5] = 5e4
59
+ return scores
60
+
61
+
62
+ def load_tf_weights_in_chatglm_6b(model, config, tf_checkpoint_path):
63
+ """Load tf checkpoints in a pytorch model."""
64
+ try:
65
+ import re
66
+
67
+ import numpy as np
68
+ import tensorflow as tf
69
+ except ImportError:
70
+ logger.error(
71
+ "Loading a TensorFlow model in PyTorch, requires TensorFlow to be installed. Please see "
72
+ "https://www.tensorflow.org/install/ for installation instructions."
73
+ )
74
+ raise
75
+ tf_path = os.path.abspath(tf_checkpoint_path)
76
+ logger.info(f"Converting TensorFlow checkpoint from {tf_path}")
77
+ # Load weights from TF model
78
+ init_vars = tf.train.list_variables(tf_path)
79
+ names = []
80
+ arrays = []
81
+ for name, shape in init_vars:
82
+ logger.info(f"Loading TF weight {name} with shape {shape}")
83
+ array = tf.train.load_variable(tf_path, name)
84
+ names.append(name)
85
+ arrays.append(array)
86
+
87
+ for name, array in zip(names, arrays):
88
+ name = name.split("/")
89
+ # adam_v and adam_m are variables used in AdamWeightDecayOptimizer to calculated m and v
90
+ # which are not required for using pretrained model
91
+ if any(
92
+ n in ["adam_v", "adam_m", "AdamWeightDecayOptimizer", "AdamWeightDecayOptimizer_1", "global_step"]
93
+ for n in name
94
+ ):
95
+ logger.info(f"Skipping {'/'.join(name)}")
96
+ continue
97
+ pointer = model
98
+ for m_name in name:
99
+ if re.fullmatch(r"[A-Za-z]+_\d+", m_name):
100
+ scope_names = re.split(r"_(\d+)", m_name)
101
+ else:
102
+ scope_names = [m_name]
103
+ if scope_names[0] == "kernel" or scope_names[0] == "gamma":
104
+ pointer = getattr(pointer, "weight")
105
+ elif scope_names[0] == "output_bias" or scope_names[0] == "beta":
106
+ pointer = getattr(pointer, "bias")
107
+ elif scope_names[0] == "output_weights":
108
+ pointer = getattr(pointer, "weight")
109
+ elif scope_names[0] == "squad":
110
+ pointer = getattr(pointer, "classifier")
111
+ else:
112
+ try:
113
+ pointer = getattr(pointer, scope_names[0])
114
+ except AttributeError:
115
+ logger.info(f"Skipping {'/'.join(name)}")
116
+ continue
117
+ if len(scope_names) >= 2:
118
+ num = int(scope_names[1])
119
+ pointer = pointer[num]
120
+ if m_name[-11:] == "_embeddings":
121
+ pointer = getattr(pointer, "weight")
122
+ elif m_name == "kernel":
123
+ array = np.transpose(array)
124
+ try:
125
+ assert (
126
+ pointer.shape == array.shape
127
+ ), f"Pointer shape {pointer.shape} and array shape {array.shape} mismatched"
128
+ except AssertionError as e:
129
+ e.args += (pointer.shape, array.shape)
130
+ raise
131
+ logger.info(f"Initialize PyTorch weight {name}")
132
+ pointer.data = torch.from_numpy(array)
133
+ return model
134
+
135
+
136
+ class PrefixEncoder(torch.nn.Module):
137
+ """
138
+ The torch.nn model to encode the prefix
139
+ Input shape: (batch-size, prefix-length)
140
+ Output shape: (batch-size, prefix-length, 2*layers*hidden)
141
+ """
142
+
143
+ def __init__(self, config):
144
+ super().__init__()
145
+ self.prefix_projection = config.prefix_projection
146
+ if self.prefix_projection:
147
+ # Use a two-layer MLP to encode the prefix
148
+ self.embedding = torch.nn.Embedding(config.pre_seq_len, config.hidden_size)
149
+ self.trans = torch.nn.Sequential(
150
+ torch.nn.Linear(config.hidden_size, config.hidden_size),
151
+ torch.nn.Tanh(),
152
+ torch.nn.Linear(config.hidden_size, config.num_layers * config.hidden_size * 2)
153
+ )
154
+ else:
155
+ self.embedding = torch.nn.Embedding(config.pre_seq_len, config.num_layers * config.hidden_size * 2)
156
+
157
+ def forward(self, prefix: torch.Tensor):
158
+ if self.prefix_projection:
159
+ prefix_tokens = self.embedding(prefix)
160
+ past_key_values = self.trans(prefix_tokens)
161
+ else:
162
+ past_key_values = self.embedding(prefix)
163
+ return past_key_values
164
+
165
+
166
+ @torch.jit.script
167
+ def gelu_impl(x):
168
+ """OpenAI's gelu implementation."""
169
+ return 0.5 * x * (1.0 + torch.tanh(0.7978845608028654 * x *
170
+ (1.0 + 0.044715 * x * x)))
171
+
172
+
173
+ def gelu(x):
174
+ return gelu_impl(x)
175
+
176
+
177
+ class RotaryEmbedding(torch.nn.Module):
178
+ def __init__(self, dim, base=10000, precision=torch.half, learnable=False):
179
+ super().__init__()
180
+ inv_freq = 1. / (base ** (torch.arange(0, dim, 2).float() / dim))
181
+ inv_freq = inv_freq.half()
182
+ self.learnable = learnable
183
+ if learnable:
184
+ self.inv_freq = torch.nn.Parameter(inv_freq)
185
+ self.max_seq_len_cached = None
186
+ else:
187
+ self.register_buffer('inv_freq', inv_freq)
188
+ self.max_seq_len_cached = None
189
+ self.cos_cached = None
190
+ self.sin_cached = None
191
+ self.precision = precision
192
+
193
+ def _load_from_state_dict(self, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys,
194
+ error_msgs):
195
+ pass
196
+
197
+ def forward(self, x, seq_dim=1, seq_len=None):
198
+ if seq_len is None:
199
+ seq_len = x.shape[seq_dim]
200
+ if self.max_seq_len_cached is None or (seq_len > self.max_seq_len_cached):
201
+ self.max_seq_len_cached = None if self.learnable else seq_len
202
+ t = torch.arange(seq_len, device=x.device, dtype=self.inv_freq.dtype)
203
+ freqs = torch.einsum('i,j->ij', t, self.inv_freq)
204
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
205
+ emb = torch.cat((freqs, freqs), dim=-1).to(x.device)
206
+ if self.precision == torch.bfloat16:
207
+ emb = emb.float()
208
+
209
+ # [sx, 1 (b * np), hn]
210
+ cos_cached = emb.cos()[:, None, :]
211
+ sin_cached = emb.sin()[:, None, :]
212
+ if self.precision == torch.bfloat16:
213
+ cos_cached = cos_cached.bfloat16()
214
+ sin_cached = sin_cached.bfloat16()
215
+ if self.learnable:
216
+ return cos_cached, sin_cached
217
+ self.cos_cached, self.sin_cached = cos_cached, sin_cached
218
+ return self.cos_cached[:seq_len, ...], self.sin_cached[:seq_len, ...]
219
+
220
+ def _apply(self, fn):
221
+ if self.cos_cached is not None:
222
+ self.cos_cached = fn(self.cos_cached)
223
+ if self.sin_cached is not None:
224
+ self.sin_cached = fn(self.sin_cached)
225
+ return super()._apply(fn)
226
+
227
+
228
+ def rotate_half(x):
229
+ x1, x2 = x[..., :x.shape[-1] // 2], x[..., x.shape[-1] // 2:]
230
+ return torch.cat((-x2, x1), dim=x1.ndim - 1) # dim=-1 triggers a bug in earlier torch versions
231
+
232
+
233
+ @torch.jit.script
234
+ def apply_rotary_pos_emb_index(q, k, cos, sin, position_id):
235
+ # position_id: [sq, b], q, k: [sq, b, np, hn], cos: [sq, 1, hn] -> [sq, b, 1, hn]
236
+ cos, sin = F.embedding(position_id, cos.squeeze(1)).unsqueeze(2), \
237
+ F.embedding(position_id, sin.squeeze(1)).unsqueeze(2)
238
+ q, k = (q * cos) + (rotate_half(q) * sin), (k * cos) + (rotate_half(k) * sin)
239
+ return q, k
240
+
241
+
242
+ def attention_fn(
243
+ self,
244
+ query_layer,
245
+ key_layer,
246
+ value_layer,
247
+ attention_mask,
248
+ hidden_size_per_partition,
249
+ layer_id,
250
+ layer_past=None,
251
+ scaling_attention_score=True,
252
+ use_cache=False,
253
+ ):
254
+ if layer_past is not None:
255
+ past_key, past_value = layer_past[0], layer_past[1]
256
+ key_layer = torch.cat((past_key, key_layer), dim=0)
257
+ value_layer = torch.cat((past_value, value_layer), dim=0)
258
+
259
+ # seqlen, batch, num_attention_heads, hidden_size_per_attention_head
260
+ seq_len, b, nh, hidden_size = key_layer.shape
261
+
262
+ if use_cache:
263
+ present = (key_layer, value_layer)
264
+ else:
265
+ present = None
266
+
267
+ query_key_layer_scaling_coeff = float(layer_id + 1)
268
+ if scaling_attention_score:
269
+ query_layer = query_layer / (math.sqrt(hidden_size) * query_key_layer_scaling_coeff)
270
+
271
+ # ===================================
272
+ # Raw attention scores. [b, np, s, s]
273
+ # ===================================
274
+
275
+ # [b, np, sq, sk]
276
+ output_size = (query_layer.size(1), query_layer.size(2), query_layer.size(0), key_layer.size(0))
277
+
278
+ # [sq, b, np, hn] -> [sq, b * np, hn]
279
+ query_layer = query_layer.view(output_size[2], output_size[0] * output_size[1], -1)
280
+ # [sk, b, np, hn] -> [sk, b * np, hn]
281
+ key_layer = key_layer.view(output_size[3], output_size[0] * output_size[1], -1)
282
+
283
+ matmul_result = torch.zeros(
284
+ 1, 1, 1,
285
+ dtype=query_layer.dtype,
286
+ device=query_layer.device,
287
+ )
288
+
289
+ matmul_result = torch.baddbmm(
290
+ matmul_result,
291
+ query_layer.transpose(0, 1), # [b * np, sq, hn]
292
+ key_layer.transpose(0, 1).transpose(1, 2), # [b * np, hn, sk]
293
+ beta=0.0,
294
+ alpha=1.0,
295
+ )
296
+
297
+ # change view to [b, np, sq, sk]
298
+ attention_scores = matmul_result.view(*output_size)
299
+
300
+ if self.scale_mask_softmax:
301
+ self.scale_mask_softmax.scale = query_key_layer_scaling_coeff
302
+ attention_probs = self.scale_mask_softmax(attention_scores, attention_mask.contiguous())
303
+ else:
304
+ if not (attention_mask == 0).all():
305
+ # if auto-regressive, skip
306
+ attention_scores.masked_fill_(attention_mask, -10000.0)
307
+ dtype = attention_scores.dtype
308
+ attention_scores = attention_scores.float()
309
+ attention_scores = attention_scores * query_key_layer_scaling_coeff
310
+
311
+ attention_probs = F.softmax(attention_scores, dim=-1)
312
+
313
+ attention_probs = attention_probs.type(dtype)
314
+
315
+ # =========================
316
+ # Context layer. [sq, b, hp]
317
+ # =========================
318
+
319
+ # value_layer -> context layer.
320
+ # [sk, b, np, hn] --> [b, np, sq, hn]
321
+
322
+ # context layer shape: [b, np, sq, hn]
323
+ output_size = (value_layer.size(1), value_layer.size(2), query_layer.size(0), value_layer.size(3))
324
+
325
+ # change view [sk, b * np, hn]
326
+ value_layer = value_layer.view(value_layer.size(0), output_size[0] * output_size[1], -1)
327
+
328
+ # change view [b * np, sq, sk]
329
+ attention_probs = attention_probs.view(output_size[0] * output_size[1], output_size[2], -1)
330
+
331
+ # matmul: [b * np, sq, hn]
332
+ context_layer = torch.bmm(attention_probs, value_layer.transpose(0, 1))
333
+
334
+ # change view [b, np, sq, hn]
335
+ context_layer = context_layer.view(*output_size)
336
+
337
+ # [b, np, sq, hn] --> [sq, b, np, hn]
338
+ context_layer = context_layer.permute(2, 0, 1, 3).contiguous()
339
+
340
+ # [sq, b, np, hn] --> [sq, b, hp]
341
+ new_context_layer_shape = context_layer.size()[:-2] + (hidden_size_per_partition,)
342
+ context_layer = context_layer.view(*new_context_layer_shape)
343
+
344
+ outputs = (context_layer, present, attention_probs)
345
+
346
+ return outputs
347
+
348
+
349
+ class SelfAttention(torch.nn.Module):
350
+ def __init__(self, hidden_size, num_attention_heads,
351
+ layer_id, hidden_size_per_attention_head=None, bias=True,
352
+ params_dtype=torch.float, position_encoding_2d=True):
353
+ super(SelfAttention, self).__init__()
354
+
355
+ self.layer_id = layer_id
356
+ self.hidden_size = hidden_size
357
+ self.hidden_size_per_partition = hidden_size
358
+ self.num_attention_heads = num_attention_heads
359
+ self.num_attention_heads_per_partition = num_attention_heads
360
+ self.position_encoding_2d = position_encoding_2d
361
+ self.rotary_emb = RotaryEmbedding(
362
+ self.hidden_size // (self.num_attention_heads * 2)
363
+ if position_encoding_2d
364
+ else self.hidden_size // self.num_attention_heads,
365
+ base=10000,
366
+ precision=torch.half,
367
+ learnable=False,
368
+ )
369
+
370
+ self.scale_mask_softmax = None
371
+
372
+ if hidden_size_per_attention_head is None:
373
+ self.hidden_size_per_attention_head = hidden_size // num_attention_heads
374
+ else:
375
+ self.hidden_size_per_attention_head = hidden_size_per_attention_head
376
+
377
+ self.inner_hidden_size = num_attention_heads * self.hidden_size_per_attention_head
378
+
379
+ # Strided linear layer.
380
+ self.query_key_value = skip_init(
381
+ torch.nn.Linear,
382
+ hidden_size,
383
+ 3 * self.inner_hidden_size,
384
+ bias=bias,
385
+ dtype=params_dtype,
386
+ )
387
+
388
+ self.dense = skip_init(
389
+ torch.nn.Linear,
390
+ self.inner_hidden_size,
391
+ hidden_size,
392
+ bias=bias,
393
+ dtype=params_dtype,
394
+ )
395
+
396
+ @staticmethod
397
+ def attention_mask_func(attention_scores, attention_mask):
398
+ attention_scores.masked_fill_(attention_mask, -10000.0)
399
+ return attention_scores
400
+
401
+ def split_tensor_along_last_dim(self, tensor, num_partitions,
402
+ contiguous_split_chunks=False):
403
+ """Split a tensor along its last dimension.
404
+ Arguments:
405
+ tensor: input tensor.
406
+ num_partitions: number of partitions to split the tensor
407
+ contiguous_split_chunks: If True, make each chunk contiguous
408
+ in memory.
409
+ """
410
+ # Get the size and dimension.
411
+ last_dim = tensor.dim() - 1
412
+ last_dim_size = tensor.size()[last_dim] // num_partitions
413
+ # Split.
414
+ tensor_list = torch.split(tensor, last_dim_size, dim=last_dim)
415
+ # Note: torch.split does not create contiguous tensors by default.
416
+ if contiguous_split_chunks:
417
+ return tuple(chunk.contiguous() for chunk in tensor_list)
418
+
419
+ return tensor_list
420
+
421
+ def forward(
422
+ self,
423
+ hidden_states: torch.Tensor,
424
+ position_ids,
425
+ attention_mask: torch.Tensor,
426
+ layer_id,
427
+ layer_past: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
428
+ use_cache: bool = False,
429
+ output_attentions: bool = False,
430
+ ):
431
+ """
432
+ hidden_states: [seq_len, batch, hidden_size]
433
+ attention_mask: [(1, 1), seq_len, seq_len]
434
+ """
435
+
436
+ # [seq_len, batch, 3 * hidden_size]
437
+ mixed_raw_layer = self.query_key_value(hidden_states)
438
+
439
+ # [seq_len, batch, 3 * hidden_size] --> [seq_len, batch, num_attention_heads, 3 * hidden_size_per_attention_head]
440
+ new_tensor_shape = mixed_raw_layer.size()[:-1] + (
441
+ self.num_attention_heads_per_partition,
442
+ 3 * self.hidden_size_per_attention_head,
443
+ )
444
+ mixed_raw_layer = mixed_raw_layer.view(*new_tensor_shape)
445
+
446
+ # [seq_len, batch, num_attention_heads, hidden_size_per_attention_head]
447
+ (query_layer, key_layer, value_layer) = self.split_tensor_along_last_dim(mixed_raw_layer, 3)
448
+
449
+ if self.position_encoding_2d:
450
+ q1, q2 = query_layer.chunk(2, dim=(query_layer.ndim - 1))
451
+ k1, k2 = key_layer.chunk(2, dim=(key_layer.ndim - 1))
452
+ cos, sin = self.rotary_emb(q1, seq_len=position_ids.max() + 1)
453
+ position_ids, block_position_ids = position_ids[:, 0, :].transpose(0, 1).contiguous(), \
454
+ position_ids[:, 1, :].transpose(0, 1).contiguous()
455
+ q1, k1 = apply_rotary_pos_emb_index(q1, k1, cos, sin, position_ids)
456
+ q2, k2 = apply_rotary_pos_emb_index(q2, k2, cos, sin, block_position_ids)
457
+ query_layer = torch.concat([q1, q2], dim=(q1.ndim - 1))
458
+ key_layer = torch.concat([k1, k2], dim=(k1.ndim - 1))
459
+ else:
460
+ position_ids = position_ids.transpose(0, 1)
461
+ cos, sin = self.rotary_emb(value_layer, seq_len=position_ids.max() + 1)
462
+ # [seq_len, batch, num_attention_heads, hidden_size_per_attention_head]
463
+ query_layer, key_layer = apply_rotary_pos_emb_index(query_layer, key_layer, cos, sin, position_ids)
464
+
465
+ # [seq_len, batch, hidden_size]
466
+ context_layer, present, attention_probs = attention_fn(
467
+ self=self,
468
+ query_layer=query_layer,
469
+ key_layer=key_layer,
470
+ value_layer=value_layer,
471
+ attention_mask=attention_mask,
472
+ hidden_size_per_partition=self.hidden_size_per_partition,
473
+ layer_id=layer_id,
474
+ layer_past=layer_past,
475
+ use_cache=use_cache
476
+ )
477
+
478
+ output = self.dense(context_layer)
479
+
480
+ outputs = (output, present)
481
+
482
+ if output_attentions:
483
+ outputs += (attention_probs,)
484
+
485
+ return outputs # output, present, attention_probs
486
+
487
+
488
+ class GEGLU(torch.nn.Module):
489
+ def __init__(self):
490
+ super().__init__()
491
+ self.activation_fn = F.gelu
492
+
493
+ def forward(self, x):
494
+ # dim=-1 breaks in jit for pt<1.10
495
+ x1, x2 = x.chunk(2, dim=(x.ndim - 1))
496
+ return x1 * self.activation_fn(x2)
497
+
498
+
499
+ class GLU(torch.nn.Module):
500
+ def __init__(self, hidden_size, inner_hidden_size=None,
501
+ layer_id=None, bias=True, activation_func=gelu, params_dtype=torch.float):
502
+ super(GLU, self).__init__()
503
+ self.layer_id = layer_id
504
+ self.activation_func = activation_func
505
+
506
+ # Project to 4h.
507
+ self.hidden_size = hidden_size
508
+ if inner_hidden_size is None:
509
+ inner_hidden_size = 4 * hidden_size
510
+ self.inner_hidden_size = inner_hidden_size
511
+ self.dense_h_to_4h = skip_init(
512
+ torch.nn.Linear,
513
+ self.hidden_size,
514
+ self.inner_hidden_size,
515
+ bias=bias,
516
+ dtype=params_dtype,
517
+ )
518
+ # Project back to h.
519
+ self.dense_4h_to_h = skip_init(
520
+ torch.nn.Linear,
521
+ self.inner_hidden_size,
522
+ self.hidden_size,
523
+ bias=bias,
524
+ dtype=params_dtype,
525
+ )
526
+
527
+ def forward(self, hidden_states):
528
+ """
529
+ hidden_states: [seq_len, batch, hidden_size]
530
+ """
531
+
532
+ # [seq_len, batch, inner_hidden_size]
533
+ intermediate_parallel = self.dense_h_to_4h(hidden_states)
534
+
535
+ intermediate_parallel = self.activation_func(intermediate_parallel)
536
+
537
+ output = self.dense_4h_to_h(intermediate_parallel)
538
+
539
+ return output
540
+
541
+
542
+ class GLMBlock(torch.nn.Module):
543
+ def __init__(
544
+ self,
545
+ hidden_size,
546
+ num_attention_heads,
547
+ layernorm_epsilon,
548
+ layer_id,
549
+ inner_hidden_size=None,
550
+ hidden_size_per_attention_head=None,
551
+ layernorm=LayerNorm,
552
+ use_bias=True,
553
+ params_dtype=torch.float,
554
+ num_layers=28,
555
+ position_encoding_2d=True
556
+ ):
557
+ super(GLMBlock, self).__init__()
558
+ # Set output layer initialization if not provided.
559
+
560
+ self.layer_id = layer_id
561
+
562
+ # Layernorm on the input data.
563
+ self.input_layernorm = layernorm(hidden_size, eps=layernorm_epsilon)
564
+
565
+ self.position_encoding_2d = position_encoding_2d
566
+
567
+ # Self attention.
568
+ self.attention = SelfAttention(
569
+ hidden_size,
570
+ num_attention_heads,
571
+ layer_id,
572
+ hidden_size_per_attention_head=hidden_size_per_attention_head,
573
+ bias=use_bias,
574
+ params_dtype=params_dtype,
575
+ position_encoding_2d=self.position_encoding_2d
576
+ )
577
+
578
+ # Layernorm on the input data.
579
+ self.post_attention_layernorm = layernorm(hidden_size, eps=layernorm_epsilon)
580
+
581
+ self.num_layers = num_layers
582
+
583
+ # GLU
584
+ self.mlp = GLU(
585
+ hidden_size,
586
+ inner_hidden_size=inner_hidden_size,
587
+ bias=use_bias,
588
+ layer_id=layer_id,
589
+ params_dtype=params_dtype,
590
+ )
591
+
592
+ def forward(
593
+ self,
594
+ hidden_states: torch.Tensor,
595
+ position_ids,
596
+ attention_mask: torch.Tensor,
597
+ layer_id,
598
+ layer_past: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
599
+ use_cache: bool = False,
600
+ output_attentions: bool = False,
601
+ ):
602
+ """
603
+ hidden_states: [seq_len, batch, hidden_size]
604
+ attention_mask: [(1, 1), seq_len, seq_len]
605
+ """
606
+
607
+ # Layer norm at the begining of the transformer layer.
608
+ # [seq_len, batch, hidden_size]
609
+ attention_input = self.input_layernorm(hidden_states)
610
+
611
+ # Self attention.
612
+ attention_outputs = self.attention(
613
+ attention_input,
614
+ position_ids,
615
+ attention_mask=attention_mask,
616
+ layer_id=layer_id,
617
+ layer_past=layer_past,
618
+ use_cache=use_cache,
619
+ output_attentions=output_attentions
620
+ )
621
+
622
+ attention_output = attention_outputs[0]
623
+
624
+ outputs = attention_outputs[1:]
625
+
626
+ # Residual connection.
627
+ alpha = (2 * self.num_layers) ** 0.5
628
+ hidden_states = attention_input * alpha + attention_output
629
+
630
+ mlp_input = self.post_attention_layernorm(hidden_states)
631
+
632
+ # MLP.
633
+ mlp_output = self.mlp(mlp_input)
634
+
635
+ # Second residual connection.
636
+ output = mlp_input * alpha + mlp_output
637
+
638
+ if use_cache:
639
+ outputs = (output,) + outputs
640
+ else:
641
+ outputs = (output,) + outputs[1:]
642
+
643
+ return outputs # hidden_states, present, attentions
644
+
645
+
646
+ class ChatGLMPreTrainedModel(PreTrainedModel):
647
+ """
648
+ An abstract class to handle weights initialization and
649
+ a simple interface for downloading and loading pretrained models.
650
+ """
651
+
652
+ is_parallelizable = False
653
+ supports_gradient_checkpointing = True
654
+ config_class = ChatGLMConfig
655
+ base_model_prefix = "transformer"
656
+ _no_split_modules = ["GLMBlock"]
657
+
658
+ def __init__(self, *inputs, **kwargs):
659
+ super().__init__(*inputs, **kwargs)
660
+
661
+ def _init_weights(self, module: nn.Module):
662
+ """Initialize the weights."""
663
+ return
664
+
665
+ def get_masks(self, input_ids, device):
666
+ batch_size, seq_length = input_ids.shape
667
+ context_lengths = [seq.tolist().index(self.config.bos_token_id) for seq in input_ids]
668
+ attention_mask = torch.ones((batch_size, seq_length, seq_length), device=device)
669
+ attention_mask.tril_()
670
+ for i, context_length in enumerate(context_lengths):
671
+ attention_mask[i, :, :context_length] = 1
672
+ attention_mask.unsqueeze_(1)
673
+ attention_mask = (attention_mask < 0.5).bool()
674
+
675
+ return attention_mask
676
+
677
+ def get_position_ids(self, input_ids, mask_positions, device, gmask=False):
678
+ batch_size, seq_length = input_ids.shape
679
+ context_lengths = [seq.tolist().index(self.config.bos_token_id) for seq in input_ids]
680
+ if self.position_encoding_2d:
681
+ position_ids = torch.arange(seq_length, dtype=torch.long, device=device).unsqueeze(0).repeat(batch_size, 1)
682
+ for i, context_length in enumerate(context_lengths):
683
+ position_ids[i, context_length:] = mask_positions[i]
684
+ block_position_ids = [torch.cat((
685
+ torch.zeros(context_length, dtype=torch.long, device=device),
686
+ torch.arange(seq_length - context_length, dtype=torch.long, device=device) + 1
687
+ )) for context_length in context_lengths]
688
+ block_position_ids = torch.stack(block_position_ids, dim=0)
689
+ position_ids = torch.stack((position_ids, block_position_ids), dim=1)
690
+ else:
691
+ position_ids = torch.arange(seq_length, dtype=torch.long, device=device).unsqueeze(0).repeat(batch_size, 1)
692
+ if not gmask:
693
+ for i, context_length in enumerate(context_lengths):
694
+ position_ids[context_length:] = mask_positions[i]
695
+
696
+ return position_ids
697
+
698
+ def _set_gradient_checkpointing(self, module, value=False):
699
+ if isinstance(module, ChatGLMModel):
700
+ module.gradient_checkpointing = value
701
+
702
+
703
+ CHATGLM_6B_START_DOCSTRING = r"""
704
+ This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class.
705
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general
706
+ usage and behavior.
707
+
708
+ Parameters:
709
+ config ([`~ChatGLM6BConfig`]): Model configuration class with all the parameters of the model.
710
+ Initializing with a config file does not load the weights associated with the model, only the configuration.
711
+ Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
712
+ """
713
+
714
+ CHATGLM_6B_INPUTS_DOCSTRING = r"""
715
+ Args:
716
+ input_ids (`torch.LongTensor` of shape `({0})`):
717
+ Indices of input sequence tokens in the vocabulary.
718
+
719
+ Indices can be obtained using [`ChatGLM6BTokenizer`].
720
+ See [`PreTrainedTokenizer.encode`] and
721
+ [`PreTrainedTokenizer.__call__`] for details.
722
+
723
+ [What are input IDs?](../glossary#input-ids)
724
+ attention_mask (`torch.FloatTensor` of shape `({0})`, *optional*):
725
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
726
+
727
+ - 1 for tokens that are **not masked**,
728
+ - 0 for tokens that are **masked**.
729
+
730
+ [What are attention masks?](../glossary#attention-mask)
731
+ token_type_ids (`torch.LongTensor` of shape `({0})`, *optional*):
732
+ Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0, 1]`:
733
+
734
+ - 0 corresponds to a *sentence A* token,
735
+ - 1 corresponds to a *sentence B* token.
736
+
737
+ [What are token type IDs?](../glossary#token-type-ids)
738
+ position_ids (`torch.LongTensor` of shape `({0})`, *optional*):
739
+ Indices of positions of each input sequence tokens in the position embeddings.
740
+ Selected in the range `[0, config.max_position_embeddings - 1]`.
741
+
742
+ [What are position IDs?](../glossary#position-ids)
743
+ head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
744
+ Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:
745
+
746
+ - 1 indicates the head is **not masked**,
747
+ - 0 indicates the head is **masked**.
748
+
749
+ inputs_embeds (`torch.FloatTensor` of shape `({0}, hidden_size)`, *optional*):
750
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
751
+ This is useful if you want more control over how to convert *input_ids* indices into associated vectors
752
+ than the model's internal embedding lookup matrix.
753
+ output_attentions (`bool`, *optional*):
754
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
755
+ tensors for more detail.
756
+ output_hidden_states (`bool`, *optional*):
757
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
758
+ more detail.
759
+ return_dict (`bool`, *optional*):
760
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
761
+ """
762
+
763
+
764
+ @add_start_docstrings(
765
+ "The bare ChatGLM-6B Model transformer outputting raw hidden-states without any specific head on top.",
766
+ CHATGLM_6B_START_DOCSTRING,
767
+ )
768
+ class ChatGLMModel(ChatGLMPreTrainedModel):
769
+ """
770
+
771
+ The model can behave as an encoder (with only self-attention) as well
772
+ as a decoder, in which case a layer of cross-attention is added between
773
+ the self-attention layers, following the architecture described in [Attention is
774
+ all you need](https://arxiv.org/abs/1706.03762) by Ashish Vaswani,
775
+ Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser and Illia Polosukhin.
776
+
777
+ To behave as an decoder the model needs to be initialized with the
778
+ `is_decoder` argument of the configuration set to `True`.
779
+ To be used in a Seq2Seq model, the model needs to initialized with both `is_decoder`
780
+ argument and `add_cross_attention` set to `True`; an
781
+ `encoder_hidden_states` is then expected as an input to the forward pass.
782
+ """
783
+
784
+ def __init__(self, config: ChatGLMConfig):
785
+ super().__init__(config)
786
+
787
+ # recording parameters
788
+ self.max_sequence_length = config.max_sequence_length
789
+ self.hidden_size = config.hidden_size
790
+ self.params_dtype = torch.half
791
+ self.num_attention_heads = config.num_attention_heads
792
+ self.vocab_size = config.vocab_size
793
+ self.num_layers = config.num_layers
794
+ self.layernorm_epsilon = config.layernorm_epsilon
795
+ self.inner_hidden_size = config.inner_hidden_size
796
+ self.hidden_size_per_attention_head = self.hidden_size // self.num_attention_heads
797
+ self.position_encoding_2d = config.position_encoding_2d
798
+ self.pre_seq_len = config.pre_seq_len
799
+ self.prefix_projection = config.prefix_projection
800
+
801
+ self.word_embeddings = skip_init(
802
+ torch.nn.Embedding,
803
+ num_embeddings=self.vocab_size, embedding_dim=self.hidden_size,
804
+ dtype=self.params_dtype
805
+ )
806
+ self.gradient_checkpointing = False
807
+
808
+ def get_layer(layer_id):
809
+ return GLMBlock(
810
+ self.hidden_size,
811
+ self.num_attention_heads,
812
+ self.layernorm_epsilon,
813
+ layer_id,
814
+ inner_hidden_size=self.inner_hidden_size,
815
+ hidden_size_per_attention_head=self.hidden_size_per_attention_head,
816
+ layernorm=LayerNorm,
817
+ use_bias=True,
818
+ params_dtype=self.params_dtype,
819
+ position_encoding_2d=self.position_encoding_2d,
820
+ )
821
+
822
+ self.layers = torch.nn.ModuleList(
823
+ [get_layer(layer_id) for layer_id in range(self.num_layers)]
824
+ )
825
+
826
+ # Final layer norm before output.
827
+ self.final_layernorm = LayerNorm(self.hidden_size, eps=self.layernorm_epsilon)
828
+
829
+ if self.pre_seq_len is not None:
830
+ for param in self.parameters():
831
+ param.requires_grad = False
832
+ self.prefix_tokens = torch.arange(self.pre_seq_len).long()
833
+ self.prefix_encoder = PrefixEncoder(config)
834
+ self.dropout = torch.nn.Dropout(0.1)
835
+
836
+ # total_params = sum(p.numel() for p in self.parameters())
837
+ # trainable_params = sum(p.numel() for p in self.parameters() if p.requires_grad)
838
+ # print("Using p-tuning v2: # trainable_params = {} / {}".format(trainable_params, total_params))
839
+
840
+ def get_input_embeddings(self):
841
+ return self.word_embeddings
842
+
843
+ def set_input_embeddings(self, new_embeddings: torch.Tensor):
844
+ self.word_embeddings = new_embeddings
845
+
846
+ def get_prompt(self, batch_size, device, dtype=torch.half):
847
+ prefix_tokens = self.prefix_tokens.unsqueeze(0).expand(batch_size, -1).to(device)
848
+ past_key_values = self.prefix_encoder(prefix_tokens).type(dtype)
849
+ past_key_values = past_key_values.view(
850
+ batch_size,
851
+ self.pre_seq_len,
852
+ self.num_layers * 2,
853
+ self.num_attention_heads,
854
+ self.hidden_size // self.num_attention_heads
855
+ )
856
+ # seq_len, b, nh, hidden_size
857
+ past_key_values = self.dropout(past_key_values)
858
+ past_key_values = past_key_values.permute([2, 1, 0, 3, 4]).split(2)
859
+ # past_key_values = [(v[0], v[1]) for v in past_key_values]
860
+ return past_key_values
861
+
862
+ @add_start_docstrings_to_model_forward(CHATGLM_6B_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
863
+ @add_code_sample_docstrings(
864
+ checkpoint=_CHECKPOINT_FOR_DOC,
865
+ output_type=BaseModelOutputWithPastAndCrossAttentions,
866
+ config_class=_CONFIG_FOR_DOC,
867
+ )
868
+ def forward(
869
+ self,
870
+ input_ids: Optional[torch.LongTensor] = None,
871
+ position_ids: Optional[torch.LongTensor] = None,
872
+ attention_mask: Optional[torch.Tensor] = None,
873
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor, torch.Tensor], ...]] = None,
874
+ inputs_embeds: Optional[torch.LongTensor] = None,
875
+ use_cache: Optional[bool] = None,
876
+ output_attentions: Optional[bool] = None,
877
+ output_hidden_states: Optional[bool] = None,
878
+ return_dict: Optional[bool] = None,
879
+ ) -> Union[Tuple[torch.Tensor, ...], BaseModelOutputWithPast]:
880
+
881
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
882
+ output_hidden_states = (
883
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
884
+ )
885
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
886
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
887
+
888
+ if self.gradient_checkpointing and self.training:
889
+ if use_cache:
890
+ logger.warning_once(
891
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
892
+ )
893
+ use_cache = False
894
+
895
+ if input_ids is not None and inputs_embeds is not None:
896
+ raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
897
+ elif input_ids is not None:
898
+ batch_size, seq_length = input_ids.shape[:2]
899
+ elif inputs_embeds is not None:
900
+ batch_size, seq_length, _ = inputs_embeds.shape[:2]
901
+ else:
902
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
903
+
904
+ if inputs_embeds is None:
905
+ inputs_embeds = self.word_embeddings(input_ids)
906
+
907
+ if past_key_values is None:
908
+ if self.pre_seq_len is not None:
909
+ past_key_values = self.get_prompt(batch_size=input_ids.shape[0], device=input_ids.device,
910
+ dtype=inputs_embeds.dtype)
911
+ else:
912
+ past_key_values = tuple([None] * len(self.layers))
913
+
914
+ if attention_mask is None:
915
+ attention_mask = self.get_masks(
916
+ input_ids,
917
+ device=input_ids.device
918
+ )
919
+
920
+
921
+ if position_ids is None:
922
+ MASK, gMASK = self.config.mask_token_id, self.config.gmask_token_id
923
+ mask_token = gMASK if gMASK in input_ids else MASK
924
+ use_gmask = True if gMASK in input_ids else False
925
+
926
+ mask_positions = [seq.tolist().index(mask_token) for seq in input_ids]
927
+ position_ids = self.get_position_ids(
928
+ input_ids,
929
+ mask_positions=mask_positions,
930
+ device=input_ids.device,
931
+ gmask=use_gmask
932
+ )
933
+
934
+ if self.pre_seq_len is not None and attention_mask is not None:
935
+ prefix_attention_mask = torch.ones(batch_size, 1, input_ids.size(-1), self.pre_seq_len).to(
936
+ attention_mask.device)
937
+ prefix_attention_mask = (prefix_attention_mask < 0.5).bool()
938
+ attention_mask = torch.cat((prefix_attention_mask, attention_mask), dim=3)
939
+
940
+ # [seq_len, batch, hidden_size]
941
+ hidden_states = inputs_embeds.transpose(0, 1)
942
+
943
+ presents = () if use_cache else None
944
+ all_self_attentions = () if output_attentions else None
945
+ all_hidden_states = () if output_hidden_states else None
946
+
947
+ if attention_mask is None:
948
+ attention_mask = torch.zeros(1, 1, device=input_ids.device).bool()
949
+
950
+ else:
951
+ attention_mask = attention_mask.to(input_ids.device)
952
+
953
+ for i, layer in enumerate(self.layers):
954
+
955
+ if output_hidden_states:
956
+ all_hidden_states = all_hidden_states + (hidden_states,)
957
+ layer_past = past_key_values[i]
958
+
959
+ if self.gradient_checkpointing and self.training:
960
+ layer_ret = torch.utils.checkpoint.checkpoint(
961
+ layer,
962
+ hidden_states,
963
+ position_ids,
964
+ attention_mask,
965
+ torch.tensor(i),
966
+ layer_past,
967
+ use_cache,
968
+ output_attentions
969
+ )
970
+ else:
971
+ layer_ret = layer(
972
+ hidden_states,
973
+ position_ids=position_ids,
974
+ attention_mask=attention_mask,
975
+ layer_id=torch.tensor(i),
976
+ layer_past=layer_past,
977
+ use_cache=use_cache,
978
+ output_attentions=output_attentions
979
+ )
980
+
981
+ hidden_states = layer_ret[0]
982
+
983
+ if use_cache:
984
+ presents = presents + (layer_ret[1],)
985
+
986
+ if output_attentions:
987
+ all_self_attentions = all_self_attentions + (layer_ret[2 if use_cache else 1],)
988
+
989
+ # Final layer norm.
990
+ hidden_states = self.final_layernorm(hidden_states)
991
+
992
+ if output_hidden_states:
993
+ all_hidden_states = all_hidden_states + (hidden_states,)
994
+
995
+ if not return_dict:
996
+ return tuple(v for v in [hidden_states, presents, all_hidden_states, all_self_attentions] if v is not None)
997
+
998
+ return BaseModelOutputWithPast(
999
+ last_hidden_state=hidden_states,
1000
+ past_key_values=presents,
1001
+ hidden_states=all_hidden_states,
1002
+ attentions=all_self_attentions,
1003
+ )
1004
+
1005
+
1006
+ class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel):
1007
+ def __init__(self, config: ChatGLMConfig):
1008
+ super().__init__(config)
1009
+
1010
+ # self.hidden_size = config.hidden_size
1011
+ # self.params_dtype = torch.half
1012
+ # self.vocab_size = config.vocab_size
1013
+ self.max_sequence_length = config.max_sequence_length
1014
+
1015
+ self.position_encoding_2d = config.position_encoding_2d
1016
+
1017
+ self.transformer = ChatGLMModel(config)
1018
+
1019
+ self.lm_head = skip_init(
1020
+ nn.Linear,
1021
+ config.hidden_size,
1022
+ config.vocab_size,
1023
+ bias=False,
1024
+ dtype=torch.half
1025
+ )
1026
+
1027
+ self.config = config
1028
+
1029
+ self.quantized = False
1030
+
1031
+ if self.config.quantization_bit:
1032
+ self.quantize(self.config.quantization_bit, empty_init=True)
1033
+
1034
+ def get_output_embeddings(self):
1035
+ return self.lm_head
1036
+
1037
+ def set_output_embeddings(self, new_embeddings):
1038
+ self.lm_head = new_embeddings
1039
+
1040
+ def _update_model_kwargs_for_generation(
1041
+ self,
1042
+ outputs: ModelOutput,
1043
+ model_kwargs: Dict[str, Any],
1044
+ is_encoder_decoder: bool = False,
1045
+ standardize_cache_format: bool = False,
1046
+ ) -> Dict[str, Any]:
1047
+ # update past_key_values
1048
+ model_kwargs["past_key_values"] = self._extract_past_from_model_output(
1049
+ outputs, standardize_cache_format=standardize_cache_format
1050
+ )
1051
+
1052
+ # update attention mask
1053
+ if "attention_mask" in model_kwargs:
1054
+ attention_mask = model_kwargs["attention_mask"]
1055
+ if attention_mask is not None and attention_mask.dtype == torch.bool:
1056
+ attention_mask = torch.cat(
1057
+ [attention_mask, attention_mask.new_ones((*attention_mask.shape[:3], 1))], dim=3)
1058
+ new_attention_mask = attention_mask[:, :, -1:].clone()
1059
+ new_attention_mask[..., -1] = False
1060
+ model_kwargs["attention_mask"] = torch.cat(
1061
+ [attention_mask, new_attention_mask], dim=2
1062
+ )
1063
+
1064
+ # update position ids
1065
+ if "position_ids" in model_kwargs:
1066
+ position_ids = model_kwargs["position_ids"]
1067
+ new_position_id = position_ids[..., -1:].clone()
1068
+ new_position_id[:, 1, :] += 1
1069
+ model_kwargs["position_ids"] = torch.cat(
1070
+ [position_ids, new_position_id], dim=-1
1071
+ )
1072
+
1073
+ return model_kwargs
1074
+
1075
+ def prepare_inputs_for_generation(
1076
+ self,
1077
+ input_ids: torch.LongTensor,
1078
+ past: Optional[torch.Tensor] = None,
1079
+ past_key_values: Optional[torch.Tensor] = None,
1080
+ attention_mask: Optional[torch.Tensor] = None,
1081
+ position_ids: Optional[torch.Tensor] = None,
1082
+ **kwargs
1083
+ ) -> dict:
1084
+ batch_size, seq_length = input_ids.shape
1085
+ MASK, gMASK = self.config.mask_token_id, self.config.gmask_token_id
1086
+ mask_token = gMASK if gMASK in input_ids else MASK
1087
+ use_gmask = True if gMASK in input_ids else False
1088
+ seqs = input_ids.tolist()
1089
+ mask_positions = [seq.index(mask_token) for seq in seqs]
1090
+
1091
+ # only last token for input_ids if past is not None
1092
+ if past is not None or past_key_values is not None:
1093
+ last_token = input_ids[:, -1].unsqueeze(-1)
1094
+ if attention_mask is not None and attention_mask.dtype == torch.bool:
1095
+ attention_mask = attention_mask[:, :, -1:]
1096
+ else:
1097
+ attention_mask = None
1098
+ if position_ids is not None:
1099
+ position_ids = position_ids[..., -1:]
1100
+ else:
1101
+ context_lengths = [seq.index(self.config.bos_token_id) for seq in seqs]
1102
+ if self.position_encoding_2d:
1103
+ position_ids = torch.tensor(
1104
+ [[mask_position, seq_length - context_length] for mask_position, context_length in
1105
+ zip(mask_positions, context_lengths)], dtype=torch.long, device=input_ids.device).unsqueeze(-1)
1106
+ else:
1107
+ position_ids = torch.tensor([mask_position for mask_position in mask_positions], dtype=torch.long,
1108
+ device=input_ids.device).unsqueeze(-1)
1109
+
1110
+ if past is None:
1111
+ past = past_key_values
1112
+ return {
1113
+ "input_ids": last_token,
1114
+ "past_key_values": past,
1115
+ "position_ids": position_ids,
1116
+ "attention_mask": attention_mask
1117
+ }
1118
+ else:
1119
+ if attention_mask is not None and attention_mask.dtype != torch.bool:
1120
+ logger.warning_once(f"The dtype of attention mask ({attention_mask.dtype}) is not bool")
1121
+ attention_mask = None
1122
+ if attention_mask is None:
1123
+ attention_mask = self.get_masks(
1124
+ input_ids,
1125
+ device=input_ids.device
1126
+ )
1127
+ if position_ids is None:
1128
+ position_ids = self.get_position_ids(
1129
+ input_ids,
1130
+ device=input_ids.device,
1131
+ mask_positions=mask_positions,
1132
+ gmask=use_gmask
1133
+ )
1134
+
1135
+ return {
1136
+ "input_ids": input_ids,
1137
+ "past_key_values": past,
1138
+ "position_ids": position_ids,
1139
+ "attention_mask": attention_mask
1140
+ }
1141
+
1142
+ def forward(
1143
+ self,
1144
+ input_ids: Optional[torch.Tensor] = None,
1145
+ position_ids: Optional[torch.Tensor] = None,
1146
+ attention_mask: Optional[torch.Tensor] = None,
1147
+ past_key_values: Optional[Tuple[torch.FloatTensor]] = None,
1148
+ inputs_embeds: Optional[torch.Tensor] = None,
1149
+ labels: Optional[torch.Tensor] = None,
1150
+ use_cache: Optional[bool] = None,
1151
+ output_attentions: Optional[bool] = None,
1152
+ output_hidden_states: Optional[bool] = None,
1153
+ return_dict: Optional[bool] = None,
1154
+ ):
1155
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
1156
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1157
+
1158
+ transformer_outputs = self.transformer(
1159
+ input_ids=input_ids,
1160
+ position_ids=position_ids,
1161
+ attention_mask=attention_mask,
1162
+ past_key_values=past_key_values,
1163
+ inputs_embeds=inputs_embeds,
1164
+ use_cache=use_cache,
1165
+ output_attentions=output_attentions,
1166
+ output_hidden_states=output_hidden_states,
1167
+ return_dict=return_dict,
1168
+ )
1169
+
1170
+ hidden_states = transformer_outputs[0]
1171
+
1172
+ lm_logits = self.lm_head(hidden_states).permute(1, 0, 2).contiguous()
1173
+
1174
+ loss = None
1175
+ if labels is not None:
1176
+ lm_logits = lm_logits.to(torch.float32)
1177
+
1178
+ # Shift so that tokens < n predict n
1179
+ shift_logits = lm_logits[..., :-1, :].contiguous()
1180
+ shift_labels = labels[..., 1:].contiguous()
1181
+ # Flatten the tokens
1182
+ loss_fct = CrossEntropyLoss(ignore_index=-100)
1183
+ loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
1184
+
1185
+ lm_logits = lm_logits.to(hidden_states.dtype)
1186
+ loss = loss.to(hidden_states.dtype)
1187
+
1188
+ if not return_dict:
1189
+ output = (lm_logits,) + transformer_outputs[1:]
1190
+ return ((loss,) + output) if loss is not None else output
1191
+
1192
+ return CausalLMOutputWithPast(
1193
+ loss=loss,
1194
+ logits=lm_logits,
1195
+ past_key_values=transformer_outputs.past_key_values,
1196
+ hidden_states=transformer_outputs.hidden_states,
1197
+ attentions=transformer_outputs.attentions,
1198
+ )
1199
+
1200
+ @staticmethod
1201
+ def _reorder_cache(
1202
+ past: Tuple[Tuple[torch.Tensor, torch.Tensor], ...], beam_idx: torch.LongTensor
1203
+ ) -> Tuple[Tuple[torch.Tensor, torch.Tensor], ...]:
1204
+ """
1205
+ This function is used to re-order the `past_key_values` cache if [`~PreTrainedModel.beam_search`] or
1206
+ [`~PreTrainedModel.beam_sample`] is called. This is required to match `past_key_values` with the correct
1207
+ beam_idx at every generation step.
1208
+
1209
+ Output shares the same memory storage as `past`.
1210
+ """
1211
+ return tuple(
1212
+ (
1213
+ layer_past[0].index_select(1, beam_idx.to(layer_past[0].device)),
1214
+ layer_past[1].index_select(1, beam_idx.to(layer_past[1].device)),
1215
+ )
1216
+ for layer_past in past
1217
+ )
1218
+
1219
+ def process_response(self, response):
1220
+ response = response.strip()
1221
+ response = response.replace("[[训练时间]]", "2023年")
1222
+ punkts = [
1223
+ [",", ","],
1224
+ ["!", "!"],
1225
+ [":", ":"],
1226
+ [";", ";"],
1227
+ ["\?", "?"],
1228
+ ]
1229
+ for item in punkts:
1230
+ response = re.sub(r"([\u4e00-\u9fff])%s" % item[0], r"\1%s" % item[1], response)
1231
+ response = re.sub(r"%s([\u4e00-\u9fff])" % item[0], r"%s\1" % item[1], response)
1232
+ return response
1233
+
1234
+ @torch.no_grad()
1235
+ def chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 2048, num_beams=1,
1236
+ do_sample=True, top_p=0.7, temperature=0.95, logits_processor=None, **kwargs):
1237
+ if history is None:
1238
+ history = []
1239
+ if logits_processor is None:
1240
+ logits_processor = LogitsProcessorList()
1241
+ logits_processor.append(InvalidScoreLogitsProcessor())
1242
+ gen_kwargs = {"max_length": max_length, "num_beams": num_beams, "do_sample": do_sample, "top_p": top_p,
1243
+ "temperature": temperature, "logits_processor": logits_processor, **kwargs}
1244
+ if not history:
1245
+ prompt = query
1246
+ else:
1247
+ prompt = ""
1248
+ for i, (old_query, response) in enumerate(history):
1249
+ prompt += "[Round {}]\n问:{}\n答:{}\n".format(i, old_query, response)
1250
+ prompt += "[Round {}]\n问:{}\n答:".format(len(history), query)
1251
+ inputs = tokenizer([prompt], return_tensors="pt")
1252
+ inputs = inputs.to(self.device)
1253
+ outputs = self.generate(**inputs, **gen_kwargs)
1254
+ outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):]
1255
+ response = tokenizer.decode(outputs)
1256
+ response = self.process_response(response)
1257
+ history = history + [(query, response)]
1258
+ return response, history
1259
+
1260
+ @torch.no_grad()
1261
+ def stream_chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 2048,
1262
+ do_sample=True, top_p=0.7, temperature=0.95, logits_processor=None, **kwargs):
1263
+ if history is None:
1264
+ history = []
1265
+ if logits_processor is None:
1266
+ logits_processor = LogitsProcessorList()
1267
+ logits_processor.append(InvalidScoreLogitsProcessor())
1268
+ gen_kwargs = {"max_length": max_length, "do_sample": do_sample, "top_p": top_p,
1269
+ "temperature": temperature, "logits_processor": logits_processor, **kwargs}
1270
+ if not history:
1271
+ prompt = query
1272
+ else:
1273
+ prompt = ""
1274
+ for i, (old_query, response) in enumerate(history):
1275
+ prompt += "[Round {}]\n问:{}\n答:{}\n".format(i, old_query, response)
1276
+ prompt += "[Round {}]\n问:{}\n答:".format(len(history), query)
1277
+ inputs = tokenizer([prompt], return_tensors="pt")
1278
+ inputs = inputs.to(self.device)
1279
+ for outputs in self.stream_generate(**inputs, **gen_kwargs):
1280
+ outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):]
1281
+ response = tokenizer.decode(outputs)
1282
+ response = self.process_response(response)
1283
+ new_history = history + [(query, response)]
1284
+ yield response, new_history
1285
+
1286
+ @torch.no_grad()
1287
+ def stream_generate(
1288
+ self,
1289
+ input_ids,
1290
+ generation_config: Optional[GenerationConfig] = None,
1291
+ logits_processor: Optional[LogitsProcessorList] = None,
1292
+ stopping_criteria: Optional[StoppingCriteriaList] = None,
1293
+ prefix_allowed_tokens_fn: Optional[Callable[[int, torch.Tensor], List[int]]] = None,
1294
+ **kwargs,
1295
+ ):
1296
+ batch_size, input_ids_seq_length = input_ids.shape[0], input_ids.shape[-1]
1297
+
1298
+ if generation_config is None:
1299
+ generation_config = self.generation_config
1300
+ generation_config = copy.deepcopy(generation_config)
1301
+ model_kwargs = generation_config.update(**kwargs)
1302
+ bos_token_id, eos_token_id = generation_config.bos_token_id, generation_config.eos_token_id
1303
+
1304
+ if isinstance(eos_token_id, int):
1305
+ eos_token_id = [eos_token_id]
1306
+
1307
+ has_default_max_length = kwargs.get("max_length") is None and generation_config.max_length is not None
1308
+ if has_default_max_length and generation_config.max_new_tokens is None:
1309
+ warnings.warn(
1310
+ f"Using `max_length`'s default ({generation_config.max_length}) to control the generation length. "
1311
+ "This behaviour is deprecated and will be removed from the config in v5 of Transformers -- we"
1312
+ " recommend using `max_new_tokens` to control the maximum length of the generation.",
1313
+ UserWarning,
1314
+ )
1315
+ elif generation_config.max_new_tokens is not None:
1316
+ generation_config.max_length = generation_config.max_new_tokens + input_ids_seq_length
1317
+ if not has_default_max_length:
1318
+ logger.warn(
1319
+ f"Both `max_new_tokens` (={generation_config.max_new_tokens}) and `max_length`(="
1320
+ f"{generation_config.max_length}) seem to have been set. `max_new_tokens` will take precedence. "
1321
+ "Please refer to the documentation for more information. "
1322
+ "(https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)",
1323
+ UserWarning,
1324
+ )
1325
+
1326
+ if input_ids_seq_length >= generation_config.max_length:
1327
+ input_ids_string = "decoder_input_ids" if self.config.is_encoder_decoder else "input_ids"
1328
+ logger.warning(
1329
+ f"Input length of {input_ids_string} is {input_ids_seq_length}, but `max_length` is set to"
1330
+ f" {generation_config.max_length}. This can lead to unexpected behavior. You should consider"
1331
+ " increasing `max_new_tokens`."
1332
+ )
1333
+
1334
+ # 2. Set generation parameters if not already defined
1335
+ logits_processor = logits_processor if logits_processor is not None else LogitsProcessorList()
1336
+ stopping_criteria = stopping_criteria if stopping_criteria is not None else StoppingCriteriaList()
1337
+
1338
+ logits_processor = self._get_logits_processor(
1339
+ generation_config=generation_config,
1340
+ input_ids_seq_length=input_ids_seq_length,
1341
+ encoder_input_ids=input_ids,
1342
+ prefix_allowed_tokens_fn=prefix_allowed_tokens_fn,
1343
+ logits_processor=logits_processor,
1344
+ )
1345
+
1346
+ stopping_criteria = self._get_stopping_criteria(
1347
+ generation_config=generation_config, stopping_criteria=stopping_criteria
1348
+ )
1349
+ logits_warper = self._get_logits_warper(generation_config)
1350
+
1351
+ unfinished_sequences = input_ids.new(input_ids.shape[0]).fill_(1)
1352
+ scores = None
1353
+ while True:
1354
+ model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)
1355
+ # forward pass to get next token
1356
+ outputs = self(
1357
+ **model_inputs,
1358
+ return_dict=True,
1359
+ output_attentions=False,
1360
+ output_hidden_states=False,
1361
+ )
1362
+
1363
+ next_token_logits = outputs.logits[:, -1, :]
1364
+
1365
+ # pre-process distribution
1366
+ next_token_scores = logits_processor(input_ids, next_token_logits)
1367
+ next_token_scores = logits_warper(input_ids, next_token_scores)
1368
+
1369
+ # sample
1370
+ probs = nn.functional.softmax(next_token_scores, dim=-1)
1371
+ if generation_config.do_sample:
1372
+ next_tokens = torch.multinomial(probs, num_samples=1).squeeze(1)
1373
+ else:
1374
+ next_tokens = torch.argmax(probs, dim=-1)
1375
+
1376
+ # update generated ids, model inputs, and length for next step
1377
+ input_ids = torch.cat([input_ids, next_tokens[:, None]], dim=-1)
1378
+ model_kwargs = self._update_model_kwargs_for_generation(
1379
+ outputs, model_kwargs, is_encoder_decoder=self.config.is_encoder_decoder
1380
+ )
1381
+ unfinished_sequences = unfinished_sequences.mul((sum(next_tokens != i for i in eos_token_id)).long())
1382
+
1383
+ # stop when each sentence is finished, or if we exceed the maximum length
1384
+ if unfinished_sequences.max() == 0 or stopping_criteria(input_ids, scores):
1385
+ break
1386
+ yield input_ids
1387
+
1388
+ def quantize(self, bits: int, empty_init=False, **kwargs):
1389
+ if bits == 0:
1390
+ return
1391
+
1392
+ from .quantization import quantize
1393
+
1394
+ if self.quantized:
1395
+ logger.info("Already quantized.")
1396
+ return self
1397
+
1398
+ self.quantized = True
1399
+
1400
+ self.config.quantization_bit = bits
1401
+
1402
+ self.transformer = quantize(self.transformer, bits, empty_init=empty_init, **kwargs)
1403
+ return self
batmanmodel/optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c3be52cfac79f00e4b6c18bc68f301872e8a00db0c57cf4731a94eb85028722
3
+ size 469763375
batmanmodel/pytorch_model-00001-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c83efdbe57a56460e9c7cdb3416cc2cdbfae14468e5c42b2862ab079c3cad92
3
+ size 9930121905
batmanmodel/pytorch_model-00002-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1cf7ce1e16ef13f89321e85bcd15f8e3e68ef7721a07aed6700d9cf20dc59383
3
+ size 3720752797
batmanmodel/pytorch_model.bin.index.json ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 13650740992
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "pytorch_model-00002-of-00002.bin",
7
+ "transformer.final_layernorm.bias": "pytorch_model-00002-of-00002.bin",
8
+ "transformer.final_layernorm.weight": "pytorch_model-00002-of-00002.bin",
9
+ "transformer.layers.0.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
10
+ "transformer.layers.0.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
11
+ "transformer.layers.0.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
12
+ "transformer.layers.0.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
13
+ "transformer.layers.0.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
14
+ "transformer.layers.0.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
15
+ "transformer.layers.0.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
16
+ "transformer.layers.0.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
17
+ "transformer.layers.0.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
18
+ "transformer.layers.0.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
19
+ "transformer.layers.0.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
20
+ "transformer.layers.0.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
21
+ "transformer.layers.0.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
22
+ "transformer.layers.1.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
23
+ "transformer.layers.1.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
24
+ "transformer.layers.1.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
25
+ "transformer.layers.1.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
26
+ "transformer.layers.1.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
27
+ "transformer.layers.1.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
28
+ "transformer.layers.1.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
29
+ "transformer.layers.1.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
30
+ "transformer.layers.1.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
31
+ "transformer.layers.1.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
32
+ "transformer.layers.1.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
33
+ "transformer.layers.1.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
34
+ "transformer.layers.1.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
35
+ "transformer.layers.10.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
36
+ "transformer.layers.10.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
37
+ "transformer.layers.10.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
38
+ "transformer.layers.10.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
39
+ "transformer.layers.10.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
40
+ "transformer.layers.10.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
41
+ "transformer.layers.10.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
42
+ "transformer.layers.10.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
43
+ "transformer.layers.10.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
44
+ "transformer.layers.10.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
45
+ "transformer.layers.10.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
46
+ "transformer.layers.10.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
47
+ "transformer.layers.10.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
48
+ "transformer.layers.11.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
49
+ "transformer.layers.11.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
50
+ "transformer.layers.11.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
51
+ "transformer.layers.11.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
52
+ "transformer.layers.11.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
53
+ "transformer.layers.11.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
54
+ "transformer.layers.11.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
55
+ "transformer.layers.11.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
56
+ "transformer.layers.11.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
57
+ "transformer.layers.11.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
58
+ "transformer.layers.11.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
59
+ "transformer.layers.11.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
60
+ "transformer.layers.11.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
61
+ "transformer.layers.12.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
62
+ "transformer.layers.12.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
63
+ "transformer.layers.12.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
64
+ "transformer.layers.12.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
65
+ "transformer.layers.12.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
66
+ "transformer.layers.12.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
67
+ "transformer.layers.12.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
68
+ "transformer.layers.12.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
69
+ "transformer.layers.12.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
70
+ "transformer.layers.12.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
71
+ "transformer.layers.12.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
72
+ "transformer.layers.12.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
73
+ "transformer.layers.12.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
74
+ "transformer.layers.13.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
75
+ "transformer.layers.13.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
76
+ "transformer.layers.13.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
77
+ "transformer.layers.13.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
78
+ "transformer.layers.13.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
79
+ "transformer.layers.13.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
80
+ "transformer.layers.13.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
81
+ "transformer.layers.13.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
82
+ "transformer.layers.13.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
83
+ "transformer.layers.13.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
84
+ "transformer.layers.13.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
85
+ "transformer.layers.13.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
86
+ "transformer.layers.13.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
87
+ "transformer.layers.14.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
88
+ "transformer.layers.14.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
89
+ "transformer.layers.14.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
90
+ "transformer.layers.14.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
91
+ "transformer.layers.14.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
92
+ "transformer.layers.14.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
93
+ "transformer.layers.14.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
94
+ "transformer.layers.14.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
95
+ "transformer.layers.14.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
96
+ "transformer.layers.14.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
97
+ "transformer.layers.14.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
98
+ "transformer.layers.14.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
99
+ "transformer.layers.14.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
100
+ "transformer.layers.15.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
101
+ "transformer.layers.15.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
102
+ "transformer.layers.15.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
103
+ "transformer.layers.15.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
104
+ "transformer.layers.15.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
105
+ "transformer.layers.15.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
106
+ "transformer.layers.15.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
107
+ "transformer.layers.15.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
108
+ "transformer.layers.15.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
109
+ "transformer.layers.15.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
110
+ "transformer.layers.15.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
111
+ "transformer.layers.15.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
112
+ "transformer.layers.15.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
113
+ "transformer.layers.16.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
114
+ "transformer.layers.16.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
115
+ "transformer.layers.16.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
116
+ "transformer.layers.16.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
117
+ "transformer.layers.16.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
118
+ "transformer.layers.16.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
119
+ "transformer.layers.16.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
120
+ "transformer.layers.16.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
121
+ "transformer.layers.16.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
122
+ "transformer.layers.16.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
123
+ "transformer.layers.16.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
124
+ "transformer.layers.16.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
125
+ "transformer.layers.16.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
126
+ "transformer.layers.17.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
127
+ "transformer.layers.17.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
128
+ "transformer.layers.17.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
129
+ "transformer.layers.17.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
130
+ "transformer.layers.17.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
131
+ "transformer.layers.17.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
132
+ "transformer.layers.17.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
133
+ "transformer.layers.17.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
134
+ "transformer.layers.17.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
135
+ "transformer.layers.17.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
136
+ "transformer.layers.17.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
137
+ "transformer.layers.17.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
138
+ "transformer.layers.17.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
139
+ "transformer.layers.18.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
140
+ "transformer.layers.18.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
141
+ "transformer.layers.18.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
142
+ "transformer.layers.18.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
143
+ "transformer.layers.18.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
144
+ "transformer.layers.18.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
145
+ "transformer.layers.18.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
146
+ "transformer.layers.18.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
147
+ "transformer.layers.18.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
148
+ "transformer.layers.18.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
149
+ "transformer.layers.18.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
150
+ "transformer.layers.18.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
151
+ "transformer.layers.18.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
152
+ "transformer.layers.19.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
153
+ "transformer.layers.19.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
154
+ "transformer.layers.19.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
155
+ "transformer.layers.19.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
156
+ "transformer.layers.19.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
157
+ "transformer.layers.19.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
158
+ "transformer.layers.19.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
159
+ "transformer.layers.19.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
160
+ "transformer.layers.19.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
161
+ "transformer.layers.19.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
162
+ "transformer.layers.19.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
163
+ "transformer.layers.19.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
164
+ "transformer.layers.19.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
165
+ "transformer.layers.2.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
166
+ "transformer.layers.2.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
167
+ "transformer.layers.2.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
168
+ "transformer.layers.2.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
169
+ "transformer.layers.2.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
170
+ "transformer.layers.2.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
171
+ "transformer.layers.2.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
172
+ "transformer.layers.2.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
173
+ "transformer.layers.2.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
174
+ "transformer.layers.2.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
175
+ "transformer.layers.2.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
176
+ "transformer.layers.2.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
177
+ "transformer.layers.2.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
178
+ "transformer.layers.20.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
179
+ "transformer.layers.20.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
180
+ "transformer.layers.20.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
181
+ "transformer.layers.20.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
182
+ "transformer.layers.20.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
183
+ "transformer.layers.20.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
184
+ "transformer.layers.20.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
185
+ "transformer.layers.20.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
186
+ "transformer.layers.20.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
187
+ "transformer.layers.20.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
188
+ "transformer.layers.20.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
189
+ "transformer.layers.20.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
190
+ "transformer.layers.20.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
191
+ "transformer.layers.21.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
192
+ "transformer.layers.21.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
193
+ "transformer.layers.21.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
194
+ "transformer.layers.21.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
195
+ "transformer.layers.21.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
196
+ "transformer.layers.21.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
197
+ "transformer.layers.21.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
198
+ "transformer.layers.21.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
199
+ "transformer.layers.21.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
200
+ "transformer.layers.21.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
201
+ "transformer.layers.21.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
202
+ "transformer.layers.21.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
203
+ "transformer.layers.21.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
204
+ "transformer.layers.22.attention.dense.bias": "pytorch_model-00002-of-00002.bin",
205
+ "transformer.layers.22.attention.dense.weight": "pytorch_model-00002-of-00002.bin",
206
+ "transformer.layers.22.attention.query_key_value.bias": "pytorch_model-00002-of-00002.bin",
207
+ "transformer.layers.22.attention.query_key_value.weight": "pytorch_model-00002-of-00002.bin",
208
+ "transformer.layers.22.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
209
+ "transformer.layers.22.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
210
+ "transformer.layers.22.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
211
+ "transformer.layers.22.mlp.dense_4h_to_h.bias": "pytorch_model-00002-of-00002.bin",
212
+ "transformer.layers.22.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00002.bin",
213
+ "transformer.layers.22.mlp.dense_h_to_4h.bias": "pytorch_model-00002-of-00002.bin",
214
+ "transformer.layers.22.mlp.dense_h_to_4h.weight": "pytorch_model-00002-of-00002.bin",
215
+ "transformer.layers.22.post_attention_layernorm.bias": "pytorch_model-00002-of-00002.bin",
216
+ "transformer.layers.22.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
217
+ "transformer.layers.23.attention.dense.bias": "pytorch_model-00002-of-00002.bin",
218
+ "transformer.layers.23.attention.dense.weight": "pytorch_model-00002-of-00002.bin",
219
+ "transformer.layers.23.attention.query_key_value.bias": "pytorch_model-00002-of-00002.bin",
220
+ "transformer.layers.23.attention.query_key_value.weight": "pytorch_model-00002-of-00002.bin",
221
+ "transformer.layers.23.attention.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
222
+ "transformer.layers.23.input_layernorm.bias": "pytorch_model-00002-of-00002.bin",
223
+ "transformer.layers.23.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
224
+ "transformer.layers.23.mlp.dense_4h_to_h.bias": "pytorch_model-00002-of-00002.bin",
225
+ "transformer.layers.23.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00002.bin",
226
+ "transformer.layers.23.mlp.dense_h_to_4h.bias": "pytorch_model-00002-of-00002.bin",
227
+ "transformer.layers.23.mlp.dense_h_to_4h.weight": "pytorch_model-00002-of-00002.bin",
228
+ "transformer.layers.23.post_attention_layernorm.bias": "pytorch_model-00002-of-00002.bin",
229
+ "transformer.layers.23.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
230
+ "transformer.layers.24.attention.dense.bias": "pytorch_model-00002-of-00002.bin",
231
+ "transformer.layers.24.attention.dense.weight": "pytorch_model-00002-of-00002.bin",
232
+ "transformer.layers.24.attention.query_key_value.bias": "pytorch_model-00002-of-00002.bin",
233
+ "transformer.layers.24.attention.query_key_value.weight": "pytorch_model-00002-of-00002.bin",
234
+ "transformer.layers.24.attention.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
235
+ "transformer.layers.24.input_layernorm.bias": "pytorch_model-00002-of-00002.bin",
236
+ "transformer.layers.24.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
237
+ "transformer.layers.24.mlp.dense_4h_to_h.bias": "pytorch_model-00002-of-00002.bin",
238
+ "transformer.layers.24.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00002.bin",
239
+ "transformer.layers.24.mlp.dense_h_to_4h.bias": "pytorch_model-00002-of-00002.bin",
240
+ "transformer.layers.24.mlp.dense_h_to_4h.weight": "pytorch_model-00002-of-00002.bin",
241
+ "transformer.layers.24.post_attention_layernorm.bias": "pytorch_model-00002-of-00002.bin",
242
+ "transformer.layers.24.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
243
+ "transformer.layers.25.attention.dense.bias": "pytorch_model-00002-of-00002.bin",
244
+ "transformer.layers.25.attention.dense.weight": "pytorch_model-00002-of-00002.bin",
245
+ "transformer.layers.25.attention.query_key_value.bias": "pytorch_model-00002-of-00002.bin",
246
+ "transformer.layers.25.attention.query_key_value.weight": "pytorch_model-00002-of-00002.bin",
247
+ "transformer.layers.25.attention.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
248
+ "transformer.layers.25.input_layernorm.bias": "pytorch_model-00002-of-00002.bin",
249
+ "transformer.layers.25.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
250
+ "transformer.layers.25.mlp.dense_4h_to_h.bias": "pytorch_model-00002-of-00002.bin",
251
+ "transformer.layers.25.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00002.bin",
252
+ "transformer.layers.25.mlp.dense_h_to_4h.bias": "pytorch_model-00002-of-00002.bin",
253
+ "transformer.layers.25.mlp.dense_h_to_4h.weight": "pytorch_model-00002-of-00002.bin",
254
+ "transformer.layers.25.post_attention_layernorm.bias": "pytorch_model-00002-of-00002.bin",
255
+ "transformer.layers.25.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
256
+ "transformer.layers.26.attention.dense.bias": "pytorch_model-00002-of-00002.bin",
257
+ "transformer.layers.26.attention.dense.weight": "pytorch_model-00002-of-00002.bin",
258
+ "transformer.layers.26.attention.query_key_value.bias": "pytorch_model-00002-of-00002.bin",
259
+ "transformer.layers.26.attention.query_key_value.weight": "pytorch_model-00002-of-00002.bin",
260
+ "transformer.layers.26.attention.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
261
+ "transformer.layers.26.input_layernorm.bias": "pytorch_model-00002-of-00002.bin",
262
+ "transformer.layers.26.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
263
+ "transformer.layers.26.mlp.dense_4h_to_h.bias": "pytorch_model-00002-of-00002.bin",
264
+ "transformer.layers.26.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00002.bin",
265
+ "transformer.layers.26.mlp.dense_h_to_4h.bias": "pytorch_model-00002-of-00002.bin",
266
+ "transformer.layers.26.mlp.dense_h_to_4h.weight": "pytorch_model-00002-of-00002.bin",
267
+ "transformer.layers.26.post_attention_layernorm.bias": "pytorch_model-00002-of-00002.bin",
268
+ "transformer.layers.26.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
269
+ "transformer.layers.27.attention.dense.bias": "pytorch_model-00002-of-00002.bin",
270
+ "transformer.layers.27.attention.dense.weight": "pytorch_model-00002-of-00002.bin",
271
+ "transformer.layers.27.attention.query_key_value.bias": "pytorch_model-00002-of-00002.bin",
272
+ "transformer.layers.27.attention.query_key_value.weight": "pytorch_model-00002-of-00002.bin",
273
+ "transformer.layers.27.attention.rotary_emb.inv_freq": "pytorch_model-00002-of-00002.bin",
274
+ "transformer.layers.27.input_layernorm.bias": "pytorch_model-00002-of-00002.bin",
275
+ "transformer.layers.27.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
276
+ "transformer.layers.27.mlp.dense_4h_to_h.bias": "pytorch_model-00002-of-00002.bin",
277
+ "transformer.layers.27.mlp.dense_4h_to_h.weight": "pytorch_model-00002-of-00002.bin",
278
+ "transformer.layers.27.mlp.dense_h_to_4h.bias": "pytorch_model-00002-of-00002.bin",
279
+ "transformer.layers.27.mlp.dense_h_to_4h.weight": "pytorch_model-00002-of-00002.bin",
280
+ "transformer.layers.27.post_attention_layernorm.bias": "pytorch_model-00002-of-00002.bin",
281
+ "transformer.layers.27.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
282
+ "transformer.layers.3.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
283
+ "transformer.layers.3.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
284
+ "transformer.layers.3.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
285
+ "transformer.layers.3.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
286
+ "transformer.layers.3.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
287
+ "transformer.layers.3.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
288
+ "transformer.layers.3.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
289
+ "transformer.layers.3.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
290
+ "transformer.layers.3.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
291
+ "transformer.layers.3.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
292
+ "transformer.layers.3.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
293
+ "transformer.layers.3.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
294
+ "transformer.layers.3.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
295
+ "transformer.layers.4.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
296
+ "transformer.layers.4.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
297
+ "transformer.layers.4.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
298
+ "transformer.layers.4.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
299
+ "transformer.layers.4.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
300
+ "transformer.layers.4.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
301
+ "transformer.layers.4.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
302
+ "transformer.layers.4.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
303
+ "transformer.layers.4.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
304
+ "transformer.layers.4.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
305
+ "transformer.layers.4.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
306
+ "transformer.layers.4.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
307
+ "transformer.layers.4.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
308
+ "transformer.layers.5.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
309
+ "transformer.layers.5.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
310
+ "transformer.layers.5.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
311
+ "transformer.layers.5.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
312
+ "transformer.layers.5.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
313
+ "transformer.layers.5.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
314
+ "transformer.layers.5.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
315
+ "transformer.layers.5.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
316
+ "transformer.layers.5.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
317
+ "transformer.layers.5.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
318
+ "transformer.layers.5.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
319
+ "transformer.layers.5.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
320
+ "transformer.layers.5.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
321
+ "transformer.layers.6.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
322
+ "transformer.layers.6.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
323
+ "transformer.layers.6.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
324
+ "transformer.layers.6.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
325
+ "transformer.layers.6.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
326
+ "transformer.layers.6.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
327
+ "transformer.layers.6.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
328
+ "transformer.layers.6.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
329
+ "transformer.layers.6.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
330
+ "transformer.layers.6.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
331
+ "transformer.layers.6.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
332
+ "transformer.layers.6.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
333
+ "transformer.layers.6.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
334
+ "transformer.layers.7.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
335
+ "transformer.layers.7.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
336
+ "transformer.layers.7.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
337
+ "transformer.layers.7.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
338
+ "transformer.layers.7.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
339
+ "transformer.layers.7.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
340
+ "transformer.layers.7.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
341
+ "transformer.layers.7.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
342
+ "transformer.layers.7.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
343
+ "transformer.layers.7.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
344
+ "transformer.layers.7.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
345
+ "transformer.layers.7.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
346
+ "transformer.layers.7.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
347
+ "transformer.layers.8.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
348
+ "transformer.layers.8.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
349
+ "transformer.layers.8.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
350
+ "transformer.layers.8.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
351
+ "transformer.layers.8.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
352
+ "transformer.layers.8.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
353
+ "transformer.layers.8.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
354
+ "transformer.layers.8.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
355
+ "transformer.layers.8.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
356
+ "transformer.layers.8.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
357
+ "transformer.layers.8.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
358
+ "transformer.layers.8.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
359
+ "transformer.layers.8.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
360
+ "transformer.layers.9.attention.dense.bias": "pytorch_model-00001-of-00002.bin",
361
+ "transformer.layers.9.attention.dense.weight": "pytorch_model-00001-of-00002.bin",
362
+ "transformer.layers.9.attention.query_key_value.bias": "pytorch_model-00001-of-00002.bin",
363
+ "transformer.layers.9.attention.query_key_value.weight": "pytorch_model-00001-of-00002.bin",
364
+ "transformer.layers.9.attention.rotary_emb.inv_freq": "pytorch_model-00001-of-00002.bin",
365
+ "transformer.layers.9.input_layernorm.bias": "pytorch_model-00001-of-00002.bin",
366
+ "transformer.layers.9.input_layernorm.weight": "pytorch_model-00001-of-00002.bin",
367
+ "transformer.layers.9.mlp.dense_4h_to_h.bias": "pytorch_model-00001-of-00002.bin",
368
+ "transformer.layers.9.mlp.dense_4h_to_h.weight": "pytorch_model-00001-of-00002.bin",
369
+ "transformer.layers.9.mlp.dense_h_to_4h.bias": "pytorch_model-00001-of-00002.bin",
370
+ "transformer.layers.9.mlp.dense_h_to_4h.weight": "pytorch_model-00001-of-00002.bin",
371
+ "transformer.layers.9.post_attention_layernorm.bias": "pytorch_model-00001-of-00002.bin",
372
+ "transformer.layers.9.post_attention_layernorm.weight": "pytorch_model-00001-of-00002.bin",
373
+ "transformer.prefix_encoder.embedding.weight": "pytorch_model-00002-of-00002.bin",
374
+ "transformer.word_embeddings.weight": "pytorch_model-00001-of-00002.bin"
375
+ }
376
+ }
batmanmodel/quantization.py ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/SgAPUGgyNNGjQ2SBpoAZAAGg0NB6mgDIAAAAA2oaApSREBNAARhGiYEaEwU8pvImlP0k2aam1GaGqbFNM1MHpTwmkepmyU9R6nqPKekHqNNPUxNGhp6n6p6QaZ6o9TG1GMqcoV9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f7j999pppjR+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
+ if source_bit_width == 8:
90
+ func = kernels.int8WeightExtractionHalf
91
+ elif source_bit_width == 4:
92
+ func = kernels.int4WeightExtractionHalf
93
+ else:
94
+ assert False, "Unsupported bit-width"
95
+
96
+ with torch.cuda.device(weight.device):
97
+ n, m = weight.size(0), weight.size(1)
98
+ out = torch.empty(n, m * (8 // source_bit_width), dtype=torch.half, device="cuda")
99
+ stream = torch.cuda.current_stream()
100
+
101
+ gridDim = (n, 1, 1)
102
+ blockDim = (min(round_up(m, 32), 1024), 1, 1)
103
+
104
+ func(
105
+ gridDim,
106
+ blockDim,
107
+ 0,
108
+ stream,
109
+ [
110
+ ctypes.c_void_p(weight.data_ptr()),
111
+ ctypes.c_void_p(scale_list.data_ptr()),
112
+ ctypes.c_void_p(out.data_ptr()),
113
+ ctypes.c_int32(n),
114
+ ctypes.c_int32(m),
115
+ ],
116
+ )
117
+ return out
118
+
119
+
120
+ class QuantizedLinear(Linear):
121
+ def __init__(self, weight_bit_width: int, weight_tensor=None, bias_tensor=None, empty_init=False, *args, **kwargs):
122
+ super(QuantizedLinear, self).__init__(*args, **kwargs)
123
+ self.weight_bit_width = weight_bit_width
124
+
125
+ shape = self.weight.shape
126
+ del self.weight
127
+
128
+ if weight_tensor is None or empty_init:
129
+ self.weight = torch.empty(
130
+ shape[0], shape[1] * weight_bit_width // 8, dtype=torch.int8, device=kwargs["device"]
131
+ )
132
+ self.weight_scale = torch.empty(shape[0], dtype=kwargs["dtype"], device=kwargs["device"])
133
+ else:
134
+ self.weight_scale = (weight_tensor.abs().max(dim=-1).values / ((2 ** (weight_bit_width - 1)) - 1)).half()
135
+ self.weight = torch.round(weight_tensor / self.weight_scale[:, None]).to(torch.int8)
136
+ if weight_bit_width == 4:
137
+ self.weight = compress_int4_weight(self.weight)
138
+
139
+ self.weight = Parameter(self.weight.to(kwargs["device"]), requires_grad=False)
140
+ self.weight_scale = Parameter(self.weight_scale.to(kwargs["device"]), requires_grad=False)
141
+ if bias_tensor is not None:
142
+ self.bias = Parameter(bias_tensor.to(kwargs["device"]), requires_grad=False)
143
+ else:
144
+ self.bias = None
145
+
146
+ def forward(self, input):
147
+ output = W8A16Linear.apply(input, self.weight, self.weight_scale, self.weight_bit_width)
148
+ if self.bias is not None:
149
+ output = output + self.bias
150
+ return output
151
+
152
+
153
+ def quantize(model, weight_bit_width, empty_init=False, **kwargs):
154
+ """Replace fp16 linear with quantized linear"""
155
+
156
+ for layer in model.layers:
157
+ layer.attention.query_key_value = QuantizedLinear(
158
+ weight_bit_width=weight_bit_width,
159
+ weight_tensor=layer.attention.query_key_value.weight.to(torch.cuda.current_device()),
160
+ bias_tensor=layer.attention.query_key_value.bias,
161
+ in_features=layer.attention.query_key_value.in_features,
162
+ out_features=layer.attention.query_key_value.out_features,
163
+ bias=True,
164
+ dtype=torch.half,
165
+ device=layer.attention.query_key_value.weight.device,
166
+ empty_init=empty_init
167
+ )
168
+ layer.attention.dense = QuantizedLinear(
169
+ weight_bit_width=weight_bit_width,
170
+ weight_tensor=layer.attention.dense.weight.to(torch.cuda.current_device()),
171
+ bias_tensor=layer.attention.dense.bias,
172
+ in_features=layer.attention.dense.in_features,
173
+ out_features=layer.attention.dense.out_features,
174
+ bias=True,
175
+ dtype=torch.half,
176
+ device=layer.attention.dense.weight.device,
177
+ empty_init=empty_init
178
+ )
179
+ layer.mlp.dense_h_to_4h = QuantizedLinear(
180
+ weight_bit_width=weight_bit_width,
181
+ weight_tensor=layer.mlp.dense_h_to_4h.weight.to(torch.cuda.current_device()),
182
+ bias_tensor=layer.mlp.dense_h_to_4h.bias,
183
+ in_features=layer.mlp.dense_h_to_4h.in_features,
184
+ out_features=layer.mlp.dense_h_to_4h.out_features,
185
+ bias=True,
186
+ dtype=torch.half,
187
+ device=layer.mlp.dense_h_to_4h.weight.device,
188
+ empty_init=empty_init
189
+ )
190
+ layer.mlp.dense_4h_to_h = QuantizedLinear(
191
+ weight_bit_width=weight_bit_width,
192
+ weight_tensor=layer.mlp.dense_4h_to_h.weight.to(torch.cuda.current_device()),
193
+ bias_tensor=layer.mlp.dense_4h_to_h.bias,
194
+ in_features=layer.mlp.dense_4h_to_h.in_features,
195
+ out_features=layer.mlp.dense_4h_to_h.out_features,
196
+ bias=True,
197
+ dtype=torch.half,
198
+ device=layer.mlp.dense_4h_to_h.weight.device,
199
+ empty_init=empty_init
200
+ )
201
+ return model
batmanmodel/rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:952ee9eac7aebb927e96ede2d2f94ab4e32f0108f095d1aacff616554661f6bc
3
+ size 14575
batmanmodel/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:789a1605f05260342a605be992efe3dec445d76b75c62bdef618345fc0105cc0
3
+ size 627
batmanmodel/special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<sop>",
3
+ "eos_token": "</s>",
4
+ "mask_token": "[MASK]",
5
+ "pad_token": "<pad>",
6
+ "unk_token": "<unk>"
7
+ }
batmanmodel/tokenization_chatglm.py ADDED
@@ -0,0 +1,433 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tokenization classes for ChatGLM."""
2
+ from typing import List, Optional, Union
3
+ import os
4
+
5
+ from transformers.tokenization_utils import PreTrainedTokenizer
6
+ from transformers.utils import logging, PaddingStrategy
7
+ from transformers.tokenization_utils_base import EncodedInput, BatchEncoding
8
+ from typing import Dict
9
+ import sentencepiece as spm
10
+ import numpy as np
11
+
12
+ logger = logging.get_logger(__name__)
13
+
14
+ PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES = {
15
+ "THUDM/chatglm-6b": 2048,
16
+ }
17
+
18
+
19
+ class TextTokenizer:
20
+ def __init__(self, model_path):
21
+ self.sp = spm.SentencePieceProcessor()
22
+ self.sp.Load(model_path)
23
+ self.num_tokens = self.sp.vocab_size()
24
+
25
+ def encode(self, text):
26
+ return self.sp.EncodeAsIds(text)
27
+
28
+ def decode(self, ids: List[int]):
29
+ return self.sp.DecodeIds(ids)
30
+
31
+ def tokenize(self, text):
32
+ return self.sp.EncodeAsPieces(text)
33
+
34
+ def convert_tokens_to_ids(self, tokens):
35
+ return [self.sp.PieceToId(token) for token in tokens]
36
+
37
+ def convert_token_to_id(self, token):
38
+ return self.sp.PieceToId(token)
39
+
40
+ def convert_id_to_token(self, idx):
41
+ return self.sp.IdToPiece(idx)
42
+
43
+ def __len__(self):
44
+ return self.num_tokens
45
+
46
+
47
+ class SPTokenizer:
48
+ def __init__(
49
+ self,
50
+ vocab_file,
51
+ num_image_tokens=20000,
52
+ max_blank_length=80,
53
+ byte_fallback=True,
54
+ ):
55
+ assert vocab_file is not None
56
+ self.vocab_file = vocab_file
57
+ self.num_image_tokens = num_image_tokens
58
+ self.special_tokens = ["[MASK]", "[gMASK]", "[sMASK]", "<unused_0>", "<sop>", "<eop>", "<ENC>", "<dBLOCK>"]
59
+ self.max_blank_length = max_blank_length
60
+ self.byte_fallback = byte_fallback
61
+ self.text_tokenizer = TextTokenizer(vocab_file)
62
+
63
+ def _get_text_tokenizer(self):
64
+ return self.text_tokenizer
65
+
66
+ @staticmethod
67
+ def get_blank_token(length: int):
68
+ assert length >= 2
69
+ return f"<|blank_{length}|>"
70
+
71
+ @staticmethod
72
+ def get_tab_token():
73
+ return f"<|tab|>"
74
+
75
+ @property
76
+ def num_text_tokens(self):
77
+ return self.text_tokenizer.num_tokens
78
+
79
+ @property
80
+ def num_tokens(self):
81
+ return self.num_image_tokens + self.num_text_tokens
82
+
83
+ @staticmethod
84
+ def _encode_whitespaces(text: str, max_len: int = 80):
85
+ text = text.replace("\t", SPTokenizer.get_tab_token())
86
+ for i in range(max_len, 1, -1):
87
+ text = text.replace(" " * i, SPTokenizer.get_blank_token(i))
88
+ return text
89
+
90
+ def _preprocess(self, text: str, linebreak=True, whitespaces=True):
91
+ if linebreak:
92
+ text = text.replace("\n", "<n>")
93
+ if whitespaces:
94
+ text = self._encode_whitespaces(text, max_len=self.max_blank_length)
95
+ return text
96
+
97
+ def encode(
98
+ self, text: str, linebreak=True, whitespaces=True, add_dummy_prefix=True
99
+ ) -> List[int]:
100
+ """
101
+ @param text: Text to encode.
102
+ @param linebreak: Whether to encode newline (\n) in text.
103
+ @param whitespaces: Whether to encode multiple whitespaces or tab in text, useful for source code encoding.
104
+ @param special_tokens: Whether to encode special token ([MASK], [gMASK], etc.) in text.
105
+ @param add_dummy_prefix: Whether to add dummy blank space in the beginning.
106
+ """
107
+ text = self._preprocess(text, linebreak, whitespaces)
108
+ if not add_dummy_prefix:
109
+ text = "<n>" + text
110
+ tmp = self._get_text_tokenizer().encode(text)
111
+ tokens = [x + self.num_image_tokens for x in tmp]
112
+ return tokens if add_dummy_prefix else tokens[2:]
113
+
114
+ def decode(self, text_ids: List[int]) -> str:
115
+ ids = [int(_id) - self.num_image_tokens for _id in text_ids]
116
+ ids = [_id for _id in ids if _id >= 0]
117
+ text = self._get_text_tokenizer().decode(ids)
118
+ text = text.replace("<n>", "\n")
119
+ text = text.replace(SPTokenizer.get_tab_token(), "\t")
120
+ for i in range(2, self.max_blank_length + 1):
121
+ text = text.replace(self.get_blank_token(i), " " * i)
122
+ return text
123
+
124
+ def tokenize(
125
+ self, text: str, linebreak=True, whitespaces=True, add_dummy_prefix=True
126
+ ) -> List[str]:
127
+ """
128
+ @param text: Text to encode.
129
+ @param linebreak: Whether to encode newline (\n) in text.
130
+ @param whitespaces: Whether to encode multiple whitespaces or tab in text, useful for source code encoding.
131
+ @param special_tokens: Whether to encode special token ([MASK], [gMASK], etc.) in text.
132
+ @param add_dummy_prefix: Whether to add dummy blank space in the beginning.
133
+ """
134
+ text = self._preprocess(text, linebreak, whitespaces)
135
+ if not add_dummy_prefix:
136
+ text = "<n>" + text
137
+ tokens = self._get_text_tokenizer().tokenize(text)
138
+ return tokens if add_dummy_prefix else tokens[2:]
139
+
140
+ def __getitem__(self, x: Union[int, str]):
141
+ if isinstance(x, int):
142
+ if x < self.num_image_tokens:
143
+ return "<image_{}>".format(x)
144
+ else:
145
+ return self.text_tokenizer.convert_id_to_token(x - self.num_image_tokens)
146
+ elif isinstance(x, str):
147
+ if x.startswith("<image_") and x.endswith(">") and x[7:-1].isdigit():
148
+ return int(x[7:-1])
149
+ else:
150
+ return self.text_tokenizer.convert_token_to_id(x) + self.num_image_tokens
151
+ else:
152
+ raise ValueError("The key should be str or int.")
153
+
154
+
155
+ class ChatGLMTokenizer(PreTrainedTokenizer):
156
+ """
157
+ Construct a ChatGLM tokenizer. Based on byte-level Byte-Pair-Encoding.
158
+
159
+ Args:
160
+ vocab_file (`str`):
161
+ Path to the vocabulary file.
162
+ """
163
+
164
+ vocab_files_names = {"vocab_file": "ice_text.model"}
165
+ max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
166
+ model_input_names = ["input_ids", "attention_mask", "position_ids"]
167
+
168
+ def __init__(
169
+ self,
170
+ vocab_file,
171
+ do_lower_case=False,
172
+ remove_space=False,
173
+ bos_token='<sop>',
174
+ eos_token='</s>',
175
+ eop_token='<eop>',
176
+ mask_token='[MASK]',
177
+ gmask_token='[gMASK]',
178
+ padding_side="left",
179
+ num_image_tokens=20000,
180
+ **kwargs
181
+ ) -> None:
182
+ super().__init__(
183
+ do_lower_case=do_lower_case,
184
+ remove_space=remove_space,
185
+ padding_side=padding_side,
186
+ bos_token=bos_token,
187
+ eos_token=eos_token,
188
+ eop_token=eop_token,
189
+ mask_token=mask_token,
190
+ gmask_token=gmask_token,
191
+ num_image_tokens=num_image_tokens,
192
+ **kwargs
193
+ )
194
+
195
+ self.do_lower_case = do_lower_case
196
+ self.remove_space = remove_space
197
+ self.vocab_file = vocab_file
198
+
199
+ self.bos_token = bos_token
200
+ self.eos_token = eos_token
201
+ self.eop_token = eop_token
202
+ self.mask_token = mask_token
203
+ self.gmask_token = gmask_token
204
+
205
+ self.sp_tokenizer = SPTokenizer(vocab_file, num_image_tokens=num_image_tokens)
206
+
207
+ """ Initialisation """
208
+
209
+ @property
210
+ def gmask_token_id(self) -> Optional[int]:
211
+ if self.gmask_token is None:
212
+ return None
213
+ return self.convert_tokens_to_ids(self.gmask_token)
214
+
215
+ @property
216
+ def eop_token_id(self) -> Optional[int]:
217
+ """
218
+ `Optional[int]`: Id of the end of sentence token in the vocabulary. Returns `None` if the token has not been
219
+ set.
220
+ """
221
+ if self.eop_token is None:
222
+ return None
223
+ return self.convert_tokens_to_ids(self.eop_token)
224
+
225
+ @property
226
+ def vocab_size(self):
227
+ """ Returns vocab size """
228
+ return self.sp_tokenizer.num_tokens
229
+
230
+ def get_vocab(self):
231
+ """ Returns vocab as a dict """
232
+ vocab = {self._convert_id_to_token(i): i for i in range(self.vocab_size)}
233
+ vocab.update(self.added_tokens_encoder)
234
+ return vocab
235
+
236
+ def preprocess_text(self, inputs):
237
+ if self.remove_space:
238
+ outputs = " ".join(inputs.strip().split())
239
+ else:
240
+ outputs = inputs
241
+
242
+ if self.do_lower_case:
243
+ outputs = outputs.lower()
244
+
245
+ return outputs
246
+
247
+ def _tokenize(self, text, **kwargs):
248
+ """ Returns a tokenized string. """
249
+ text = self.preprocess_text(text)
250
+
251
+ seq = self.sp_tokenizer.tokenize(text)
252
+
253
+ return seq
254
+
255
+ def _decode(
256
+ self,
257
+ token_ids: Union[int, List[int]],
258
+ skip_special_tokens: bool = False,
259
+ clean_up_tokenization_spaces: bool = True,
260
+ **kwargs
261
+ ) -> str:
262
+ if isinstance(token_ids, int):
263
+ token_ids = [token_ids]
264
+ if len(token_ids) == 0:
265
+ return ""
266
+ if self.pad_token_id in token_ids: # remove pad
267
+ token_ids = list(filter((self.pad_token_id).__ne__, token_ids))
268
+ return self.sp_tokenizer.decode(token_ids)
269
+
270
+ def _convert_token_to_id(self, token):
271
+ """ Converts a token (str) in an id using the vocab. """
272
+ return self.sp_tokenizer[token]
273
+
274
+ def _convert_id_to_token(self, index):
275
+ """Converts an index (integer) in a token (str) using the vocab."""
276
+ return self.sp_tokenizer[index]
277
+
278
+ def save_vocabulary(self, save_directory, filename_prefix=None):
279
+ """
280
+ Save the vocabulary and special tokens file to a directory.
281
+
282
+ Args:
283
+ save_directory (`str`):
284
+ The directory in which to save the vocabulary.
285
+ filename_prefix (`str`, *optional*):
286
+ An optional prefix to add to the named of the saved files.
287
+
288
+ Returns:
289
+ `Tuple(str)`: Paths to the files saved.
290
+ """
291
+ if os.path.isdir(save_directory):
292
+ vocab_file = os.path.join(
293
+ save_directory, self.vocab_files_names["vocab_file"]
294
+ )
295
+ else:
296
+ vocab_file = save_directory
297
+
298
+ with open(self.vocab_file, 'rb') as fin:
299
+ proto_str = fin.read()
300
+
301
+ with open(vocab_file, "wb") as writer:
302
+ writer.write(proto_str)
303
+
304
+ return (vocab_file,)
305
+
306
+ def build_inputs_with_special_tokens(
307
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
308
+ ) -> List[int]:
309
+ """
310
+ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
311
+ adding special tokens. A BERT sequence has the following format:
312
+
313
+ - single sequence: `[CLS] X [SEP]`
314
+ - pair of sequences: `[CLS] A [SEP] B [SEP]`
315
+
316
+ Args:
317
+ token_ids_0 (`List[int]`):
318
+ List of IDs to which the special tokens will be added.
319
+ token_ids_1 (`List[int]`, *optional*):
320
+ Optional second list of IDs for sequence pairs.
321
+
322
+ Returns:
323
+ `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
324
+ """
325
+ mask_ids = self.sp_tokenizer[self.mask_token]
326
+ gmask_ids = self.sp_tokenizer[self.gmask_token]
327
+ eop_id = self.sp_tokenizer[self.eop_token]
328
+ if mask_ids not in token_ids_0 and gmask_ids not in token_ids_0:
329
+ token_ids_0 += [gmask_ids]
330
+
331
+ if token_ids_0[-1] != mask_ids and token_ids_0[-1] != gmask_ids:
332
+ token_ids_0 += [self.sp_tokenizer[self.eos_token]]
333
+
334
+ token_ids_0 += [self.sp_tokenizer[self.bos_token]]
335
+
336
+ if token_ids_1 is not None:
337
+ if not token_ids_1 or token_ids_1[-1] != eop_id:
338
+ token_ids_1 += [eop_id]
339
+ token_ids_0 += token_ids_1
340
+
341
+ return token_ids_0
342
+
343
+ def _pad(
344
+ self,
345
+ encoded_inputs: Union[Dict[str, EncodedInput], BatchEncoding],
346
+ max_length: Optional[int] = None,
347
+ padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
348
+ pad_to_multiple_of: Optional[int] = None,
349
+ return_attention_mask: Optional[bool] = None,
350
+ ) -> dict:
351
+ """
352
+ Pad encoded inputs (on left/right and up to predefined length or max length in the batch)
353
+
354
+ Args:
355
+ encoded_inputs:
356
+ Dictionary of tokenized inputs (`List[int]`) or batch of tokenized inputs (`List[List[int]]`).
357
+ max_length: maximum length of the returned list and optionally padding length (see below).
358
+ Will truncate by taking into account the special tokens.
359
+ padding_strategy: PaddingStrategy to use for padding.
360
+
361
+ - PaddingStrategy.LONGEST Pad to the longest sequence in the batch
362
+ - PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
363
+ - PaddingStrategy.DO_NOT_PAD: Do not pad
364
+ The tokenizer padding sides are defined in self.padding_side:
365
+
366
+ - 'left': pads on the left of the sequences
367
+ - 'right': pads on the right of the sequences
368
+ pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
369
+ This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
370
+ `>= 7.5` (Volta).
371
+ return_attention_mask:
372
+ (optional) Set to False to avoid returning attention mask (default: set to model specifics)
373
+ """
374
+ # Load from model defaults
375
+ bos_token_id = self.sp_tokenizer[self.bos_token]
376
+ mask_token_id = self.sp_tokenizer[self.mask_token]
377
+ gmask_token_id = self.sp_tokenizer[self.gmask_token]
378
+ assert self.padding_side == "left"
379
+
380
+ required_input = encoded_inputs[self.model_input_names[0]]
381
+ seq_length = len(required_input)
382
+
383
+ if padding_strategy == PaddingStrategy.LONGEST:
384
+ max_length = len(required_input)
385
+
386
+ if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
387
+ max_length = ((max_length // pad_to_multiple_of) + 1) * pad_to_multiple_of
388
+
389
+ needs_to_be_padded = padding_strategy != PaddingStrategy.DO_NOT_PAD and len(required_input) != max_length
390
+
391
+ # Initialize attention mask if not present.
392
+ if max_length is not None:
393
+ if "attention_mask" not in encoded_inputs:
394
+ if bos_token_id in required_input:
395
+ context_length = required_input.index(bos_token_id)
396
+ else:
397
+ context_length = seq_length
398
+ attention_mask = np.ones((1, seq_length, seq_length))
399
+ attention_mask = np.tril(attention_mask)
400
+ attention_mask[:, :, :context_length] = 1
401
+ attention_mask = np.bool_(attention_mask < 0.5)
402
+ encoded_inputs["attention_mask"] = attention_mask
403
+
404
+ if "position_ids" not in encoded_inputs:
405
+ position_ids = np.arange(seq_length, dtype=np.int64)
406
+ mask_token = mask_token_id if mask_token_id in required_input else gmask_token_id
407
+ if mask_token in required_input:
408
+ mask_position = required_input.index(mask_token)
409
+ position_ids[context_length:] = mask_position
410
+ block_position_ids = np.concatenate(
411
+ [np.zeros(context_length, dtype=np.int64),
412
+ np.arange(1, seq_length - context_length + 1, dtype=np.int64)])
413
+ encoded_inputs["position_ids"] = np.stack([position_ids, block_position_ids], axis=0)
414
+
415
+ if needs_to_be_padded:
416
+ difference = max_length - len(required_input)
417
+
418
+ if "attention_mask" in encoded_inputs:
419
+ encoded_inputs["attention_mask"] = np.pad(encoded_inputs["attention_mask"],
420
+ pad_width=[(0, 0), (difference, 0), (difference, 0)],
421
+ mode='constant', constant_values=True)
422
+ if "token_type_ids" in encoded_inputs:
423
+ encoded_inputs["token_type_ids"] = [self.pad_token_type_id] * difference + encoded_inputs[
424
+ "token_type_ids"
425
+ ]
426
+ if "special_tokens_mask" in encoded_inputs:
427
+ encoded_inputs["special_tokens_mask"] = [1] * difference + encoded_inputs["special_tokens_mask"]
428
+ if "position_ids" in encoded_inputs:
429
+ encoded_inputs["position_ids"] = np.pad(encoded_inputs["position_ids"],
430
+ pad_width=[(0, 0), (difference, 0)])
431
+ encoded_inputs[self.model_input_names[0]] = [self.pad_token_id] * difference + required_input
432
+
433
+ return encoded_inputs
batmanmodel/tokenizer_config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoTokenizer": [
4
+ "tokenization_chatglm.ChatGLMTokenizer",
5
+ null
6
+ ]
7
+ },
8
+ "bos_token": "<sop>",
9
+ "do_lower_case": false,
10
+ "eop_token": "<eop>",
11
+ "eos_token": "</s>",
12
+ "gmask_token": "[gMASK]",
13
+ "mask_token": "[MASK]",
14
+ "model_max_length": 1000000000000000019884624838656,
15
+ "num_image_tokens": 0,
16
+ "pad_token": "<pad>",
17
+ "padding_side": "left",
18
+ "remove_space": false,
19
+ "special_tokens_map_file": null,
20
+ "tokenizer_class": "ChatGLMTokenizer",
21
+ "unk_token": "<unk>"
22
+ }
batmanmodel/trainer_state.json ADDED
@@ -0,0 +1,1816 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 26.666666666666668,
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.09,
12
+ "learning_rate": 0.019933333333333334,
13
+ "loss": 5.3456,
14
+ "step": 10
15
+ },
16
+ {
17
+ "epoch": 0.18,
18
+ "learning_rate": 0.019866666666666668,
19
+ "loss": 4.291,
20
+ "step": 20
21
+ },
22
+ {
23
+ "epoch": 0.27,
24
+ "learning_rate": 0.0198,
25
+ "loss": 4.0509,
26
+ "step": 30
27
+ },
28
+ {
29
+ "epoch": 0.36,
30
+ "learning_rate": 0.019733333333333335,
31
+ "loss": 4.027,
32
+ "step": 40
33
+ },
34
+ {
35
+ "epoch": 0.44,
36
+ "learning_rate": 0.019666666666666666,
37
+ "loss": 3.9933,
38
+ "step": 50
39
+ },
40
+ {
41
+ "epoch": 0.53,
42
+ "learning_rate": 0.0196,
43
+ "loss": 3.9961,
44
+ "step": 60
45
+ },
46
+ {
47
+ "epoch": 0.62,
48
+ "learning_rate": 0.019533333333333333,
49
+ "loss": 4.0272,
50
+ "step": 70
51
+ },
52
+ {
53
+ "epoch": 0.71,
54
+ "learning_rate": 0.019466666666666667,
55
+ "loss": 3.9878,
56
+ "step": 80
57
+ },
58
+ {
59
+ "epoch": 0.8,
60
+ "learning_rate": 0.0194,
61
+ "loss": 3.834,
62
+ "step": 90
63
+ },
64
+ {
65
+ "epoch": 0.89,
66
+ "learning_rate": 0.019333333333333334,
67
+ "loss": 3.925,
68
+ "step": 100
69
+ },
70
+ {
71
+ "epoch": 0.98,
72
+ "learning_rate": 0.019266666666666668,
73
+ "loss": 3.8185,
74
+ "step": 110
75
+ },
76
+ {
77
+ "epoch": 1.07,
78
+ "learning_rate": 0.0192,
79
+ "loss": 3.6609,
80
+ "step": 120
81
+ },
82
+ {
83
+ "epoch": 1.16,
84
+ "learning_rate": 0.019133333333333332,
85
+ "loss": 3.4043,
86
+ "step": 130
87
+ },
88
+ {
89
+ "epoch": 1.24,
90
+ "learning_rate": 0.01906666666666667,
91
+ "loss": 3.4379,
92
+ "step": 140
93
+ },
94
+ {
95
+ "epoch": 1.33,
96
+ "learning_rate": 0.019,
97
+ "loss": 3.3543,
98
+ "step": 150
99
+ },
100
+ {
101
+ "epoch": 1.42,
102
+ "learning_rate": 0.018933333333333333,
103
+ "loss": 3.3777,
104
+ "step": 160
105
+ },
106
+ {
107
+ "epoch": 1.51,
108
+ "learning_rate": 0.018866666666666667,
109
+ "loss": 3.3729,
110
+ "step": 170
111
+ },
112
+ {
113
+ "epoch": 1.6,
114
+ "learning_rate": 0.0188,
115
+ "loss": 3.2977,
116
+ "step": 180
117
+ },
118
+ {
119
+ "epoch": 1.69,
120
+ "learning_rate": 0.018733333333333334,
121
+ "loss": 3.3726,
122
+ "step": 190
123
+ },
124
+ {
125
+ "epoch": 1.78,
126
+ "learning_rate": 0.018666666666666668,
127
+ "loss": 3.2906,
128
+ "step": 200
129
+ },
130
+ {
131
+ "epoch": 1.87,
132
+ "learning_rate": 0.018600000000000002,
133
+ "loss": 3.3786,
134
+ "step": 210
135
+ },
136
+ {
137
+ "epoch": 1.96,
138
+ "learning_rate": 0.018533333333333332,
139
+ "loss": 3.4823,
140
+ "step": 220
141
+ },
142
+ {
143
+ "epoch": 2.04,
144
+ "learning_rate": 0.018466666666666666,
145
+ "loss": 3.1159,
146
+ "step": 230
147
+ },
148
+ {
149
+ "epoch": 2.13,
150
+ "learning_rate": 0.0184,
151
+ "loss": 2.6933,
152
+ "step": 240
153
+ },
154
+ {
155
+ "epoch": 2.22,
156
+ "learning_rate": 0.018333333333333333,
157
+ "loss": 2.8112,
158
+ "step": 250
159
+ },
160
+ {
161
+ "epoch": 2.31,
162
+ "learning_rate": 0.018266666666666667,
163
+ "loss": 2.7356,
164
+ "step": 260
165
+ },
166
+ {
167
+ "epoch": 2.4,
168
+ "learning_rate": 0.0182,
169
+ "loss": 2.6313,
170
+ "step": 270
171
+ },
172
+ {
173
+ "epoch": 2.49,
174
+ "learning_rate": 0.01813333333333333,
175
+ "loss": 2.793,
176
+ "step": 280
177
+ },
178
+ {
179
+ "epoch": 2.58,
180
+ "learning_rate": 0.01806666666666667,
181
+ "loss": 2.6872,
182
+ "step": 290
183
+ },
184
+ {
185
+ "epoch": 2.67,
186
+ "learning_rate": 0.018000000000000002,
187
+ "loss": 2.7139,
188
+ "step": 300
189
+ },
190
+ {
191
+ "epoch": 2.76,
192
+ "learning_rate": 0.017933333333333332,
193
+ "loss": 2.7769,
194
+ "step": 310
195
+ },
196
+ {
197
+ "epoch": 2.84,
198
+ "learning_rate": 0.017866666666666666,
199
+ "loss": 2.8021,
200
+ "step": 320
201
+ },
202
+ {
203
+ "epoch": 2.93,
204
+ "learning_rate": 0.0178,
205
+ "loss": 2.744,
206
+ "step": 330
207
+ },
208
+ {
209
+ "epoch": 3.02,
210
+ "learning_rate": 0.017733333333333334,
211
+ "loss": 2.5654,
212
+ "step": 340
213
+ },
214
+ {
215
+ "epoch": 3.11,
216
+ "learning_rate": 0.017666666666666667,
217
+ "loss": 2.103,
218
+ "step": 350
219
+ },
220
+ {
221
+ "epoch": 3.2,
222
+ "learning_rate": 0.0176,
223
+ "loss": 1.9702,
224
+ "step": 360
225
+ },
226
+ {
227
+ "epoch": 3.29,
228
+ "learning_rate": 0.017533333333333335,
229
+ "loss": 2.0923,
230
+ "step": 370
231
+ },
232
+ {
233
+ "epoch": 3.38,
234
+ "learning_rate": 0.017466666666666665,
235
+ "loss": 2.0385,
236
+ "step": 380
237
+ },
238
+ {
239
+ "epoch": 3.47,
240
+ "learning_rate": 0.0174,
241
+ "loss": 2.0464,
242
+ "step": 390
243
+ },
244
+ {
245
+ "epoch": 3.56,
246
+ "learning_rate": 0.017333333333333336,
247
+ "loss": 2.1224,
248
+ "step": 400
249
+ },
250
+ {
251
+ "epoch": 3.64,
252
+ "learning_rate": 0.017266666666666666,
253
+ "loss": 1.9771,
254
+ "step": 410
255
+ },
256
+ {
257
+ "epoch": 3.73,
258
+ "learning_rate": 0.0172,
259
+ "loss": 2.0532,
260
+ "step": 420
261
+ },
262
+ {
263
+ "epoch": 3.82,
264
+ "learning_rate": 0.017133333333333334,
265
+ "loss": 2.0539,
266
+ "step": 430
267
+ },
268
+ {
269
+ "epoch": 3.91,
270
+ "learning_rate": 0.017066666666666667,
271
+ "loss": 2.1778,
272
+ "step": 440
273
+ },
274
+ {
275
+ "epoch": 4.0,
276
+ "learning_rate": 0.017,
277
+ "loss": 2.1258,
278
+ "step": 450
279
+ },
280
+ {
281
+ "epoch": 4.09,
282
+ "learning_rate": 0.016933333333333335,
283
+ "loss": 1.3978,
284
+ "step": 460
285
+ },
286
+ {
287
+ "epoch": 4.18,
288
+ "learning_rate": 0.01686666666666667,
289
+ "loss": 1.4555,
290
+ "step": 470
291
+ },
292
+ {
293
+ "epoch": 4.27,
294
+ "learning_rate": 0.0168,
295
+ "loss": 1.4586,
296
+ "step": 480
297
+ },
298
+ {
299
+ "epoch": 4.36,
300
+ "learning_rate": 0.016733333333333333,
301
+ "loss": 1.3938,
302
+ "step": 490
303
+ },
304
+ {
305
+ "epoch": 4.44,
306
+ "learning_rate": 0.016666666666666666,
307
+ "loss": 1.4537,
308
+ "step": 500
309
+ },
310
+ {
311
+ "epoch": 4.53,
312
+ "learning_rate": 0.0166,
313
+ "loss": 1.4599,
314
+ "step": 510
315
+ },
316
+ {
317
+ "epoch": 4.62,
318
+ "learning_rate": 0.016533333333333334,
319
+ "loss": 1.4753,
320
+ "step": 520
321
+ },
322
+ {
323
+ "epoch": 4.71,
324
+ "learning_rate": 0.016466666666666668,
325
+ "loss": 1.4019,
326
+ "step": 530
327
+ },
328
+ {
329
+ "epoch": 4.8,
330
+ "learning_rate": 0.016399999999999998,
331
+ "loss": 1.5184,
332
+ "step": 540
333
+ },
334
+ {
335
+ "epoch": 4.89,
336
+ "learning_rate": 0.01633333333333333,
337
+ "loss": 1.5686,
338
+ "step": 550
339
+ },
340
+ {
341
+ "epoch": 4.98,
342
+ "learning_rate": 0.01626666666666667,
343
+ "loss": 1.5537,
344
+ "step": 560
345
+ },
346
+ {
347
+ "epoch": 5.07,
348
+ "learning_rate": 0.016200000000000003,
349
+ "loss": 1.0763,
350
+ "step": 570
351
+ },
352
+ {
353
+ "epoch": 5.16,
354
+ "learning_rate": 0.016133333333333333,
355
+ "loss": 0.9228,
356
+ "step": 580
357
+ },
358
+ {
359
+ "epoch": 5.24,
360
+ "learning_rate": 0.016066666666666667,
361
+ "loss": 0.9826,
362
+ "step": 590
363
+ },
364
+ {
365
+ "epoch": 5.33,
366
+ "learning_rate": 0.016,
367
+ "loss": 0.8872,
368
+ "step": 600
369
+ },
370
+ {
371
+ "epoch": 5.42,
372
+ "learning_rate": 0.015933333333333334,
373
+ "loss": 0.9621,
374
+ "step": 610
375
+ },
376
+ {
377
+ "epoch": 5.51,
378
+ "learning_rate": 0.015866666666666668,
379
+ "loss": 0.899,
380
+ "step": 620
381
+ },
382
+ {
383
+ "epoch": 5.6,
384
+ "learning_rate": 0.0158,
385
+ "loss": 0.9813,
386
+ "step": 630
387
+ },
388
+ {
389
+ "epoch": 5.69,
390
+ "learning_rate": 0.015733333333333332,
391
+ "loss": 1.0132,
392
+ "step": 640
393
+ },
394
+ {
395
+ "epoch": 5.78,
396
+ "learning_rate": 0.015666666666666666,
397
+ "loss": 0.9755,
398
+ "step": 650
399
+ },
400
+ {
401
+ "epoch": 5.87,
402
+ "learning_rate": 0.015600000000000001,
403
+ "loss": 1.0833,
404
+ "step": 660
405
+ },
406
+ {
407
+ "epoch": 5.96,
408
+ "learning_rate": 0.015533333333333333,
409
+ "loss": 1.0784,
410
+ "step": 670
411
+ },
412
+ {
413
+ "epoch": 6.04,
414
+ "learning_rate": 0.015466666666666667,
415
+ "loss": 0.7878,
416
+ "step": 680
417
+ },
418
+ {
419
+ "epoch": 6.13,
420
+ "learning_rate": 0.0154,
421
+ "loss": 0.614,
422
+ "step": 690
423
+ },
424
+ {
425
+ "epoch": 6.22,
426
+ "learning_rate": 0.015333333333333334,
427
+ "loss": 0.5681,
428
+ "step": 700
429
+ },
430
+ {
431
+ "epoch": 6.31,
432
+ "learning_rate": 0.015266666666666666,
433
+ "loss": 0.5968,
434
+ "step": 710
435
+ },
436
+ {
437
+ "epoch": 6.4,
438
+ "learning_rate": 0.0152,
439
+ "loss": 0.5988,
440
+ "step": 720
441
+ },
442
+ {
443
+ "epoch": 6.49,
444
+ "learning_rate": 0.015133333333333334,
445
+ "loss": 0.6354,
446
+ "step": 730
447
+ },
448
+ {
449
+ "epoch": 6.58,
450
+ "learning_rate": 0.015066666666666666,
451
+ "loss": 0.6298,
452
+ "step": 740
453
+ },
454
+ {
455
+ "epoch": 6.67,
456
+ "learning_rate": 0.015,
457
+ "loss": 0.5882,
458
+ "step": 750
459
+ },
460
+ {
461
+ "epoch": 6.76,
462
+ "learning_rate": 0.014933333333333335,
463
+ "loss": 0.646,
464
+ "step": 760
465
+ },
466
+ {
467
+ "epoch": 6.84,
468
+ "learning_rate": 0.014866666666666667,
469
+ "loss": 0.6301,
470
+ "step": 770
471
+ },
472
+ {
473
+ "epoch": 6.93,
474
+ "learning_rate": 0.0148,
475
+ "loss": 0.6405,
476
+ "step": 780
477
+ },
478
+ {
479
+ "epoch": 7.02,
480
+ "learning_rate": 0.014733333333333334,
481
+ "loss": 0.595,
482
+ "step": 790
483
+ },
484
+ {
485
+ "epoch": 7.11,
486
+ "learning_rate": 0.014666666666666666,
487
+ "loss": 0.3715,
488
+ "step": 800
489
+ },
490
+ {
491
+ "epoch": 7.2,
492
+ "learning_rate": 0.0146,
493
+ "loss": 0.3624,
494
+ "step": 810
495
+ },
496
+ {
497
+ "epoch": 7.29,
498
+ "learning_rate": 0.014533333333333334,
499
+ "loss": 0.3811,
500
+ "step": 820
501
+ },
502
+ {
503
+ "epoch": 7.38,
504
+ "learning_rate": 0.014466666666666668,
505
+ "loss": 0.3839,
506
+ "step": 830
507
+ },
508
+ {
509
+ "epoch": 7.47,
510
+ "learning_rate": 0.0144,
511
+ "loss": 0.3361,
512
+ "step": 840
513
+ },
514
+ {
515
+ "epoch": 7.56,
516
+ "learning_rate": 0.014333333333333333,
517
+ "loss": 0.3779,
518
+ "step": 850
519
+ },
520
+ {
521
+ "epoch": 7.64,
522
+ "learning_rate": 0.014266666666666667,
523
+ "loss": 0.3904,
524
+ "step": 860
525
+ },
526
+ {
527
+ "epoch": 7.73,
528
+ "learning_rate": 0.014199999999999999,
529
+ "loss": 0.4182,
530
+ "step": 870
531
+ },
532
+ {
533
+ "epoch": 7.82,
534
+ "learning_rate": 0.014133333333333333,
535
+ "loss": 0.4236,
536
+ "step": 880
537
+ },
538
+ {
539
+ "epoch": 7.91,
540
+ "learning_rate": 0.014066666666666668,
541
+ "loss": 0.4546,
542
+ "step": 890
543
+ },
544
+ {
545
+ "epoch": 8.0,
546
+ "learning_rate": 0.013999999999999999,
547
+ "loss": 0.3946,
548
+ "step": 900
549
+ },
550
+ {
551
+ "epoch": 8.09,
552
+ "learning_rate": 0.013933333333333334,
553
+ "loss": 0.2343,
554
+ "step": 910
555
+ },
556
+ {
557
+ "epoch": 8.18,
558
+ "learning_rate": 0.013866666666666668,
559
+ "loss": 0.2428,
560
+ "step": 920
561
+ },
562
+ {
563
+ "epoch": 8.27,
564
+ "learning_rate": 0.0138,
565
+ "loss": 0.2321,
566
+ "step": 930
567
+ },
568
+ {
569
+ "epoch": 8.36,
570
+ "learning_rate": 0.013733333333333334,
571
+ "loss": 0.2408,
572
+ "step": 940
573
+ },
574
+ {
575
+ "epoch": 8.44,
576
+ "learning_rate": 0.013666666666666667,
577
+ "loss": 0.241,
578
+ "step": 950
579
+ },
580
+ {
581
+ "epoch": 8.53,
582
+ "learning_rate": 0.013600000000000001,
583
+ "loss": 0.2302,
584
+ "step": 960
585
+ },
586
+ {
587
+ "epoch": 8.62,
588
+ "learning_rate": 0.013533333333333333,
589
+ "loss": 0.2488,
590
+ "step": 970
591
+ },
592
+ {
593
+ "epoch": 8.71,
594
+ "learning_rate": 0.013466666666666667,
595
+ "loss": 0.2364,
596
+ "step": 980
597
+ },
598
+ {
599
+ "epoch": 8.8,
600
+ "learning_rate": 0.0134,
601
+ "loss": 0.2432,
602
+ "step": 990
603
+ },
604
+ {
605
+ "epoch": 8.89,
606
+ "learning_rate": 0.013333333333333332,
607
+ "loss": 0.2963,
608
+ "step": 1000
609
+ },
610
+ {
611
+ "epoch": 8.98,
612
+ "learning_rate": 0.013266666666666666,
613
+ "loss": 0.2464,
614
+ "step": 1010
615
+ },
616
+ {
617
+ "epoch": 9.07,
618
+ "learning_rate": 0.013200000000000002,
619
+ "loss": 0.1637,
620
+ "step": 1020
621
+ },
622
+ {
623
+ "epoch": 9.16,
624
+ "learning_rate": 0.013133333333333332,
625
+ "loss": 0.1554,
626
+ "step": 1030
627
+ },
628
+ {
629
+ "epoch": 9.24,
630
+ "learning_rate": 0.013066666666666667,
631
+ "loss": 0.1372,
632
+ "step": 1040
633
+ },
634
+ {
635
+ "epoch": 9.33,
636
+ "learning_rate": 0.013000000000000001,
637
+ "loss": 0.1651,
638
+ "step": 1050
639
+ },
640
+ {
641
+ "epoch": 9.42,
642
+ "learning_rate": 0.012933333333333333,
643
+ "loss": 0.1425,
644
+ "step": 1060
645
+ },
646
+ {
647
+ "epoch": 9.51,
648
+ "learning_rate": 0.012866666666666667,
649
+ "loss": 0.1493,
650
+ "step": 1070
651
+ },
652
+ {
653
+ "epoch": 9.6,
654
+ "learning_rate": 0.0128,
655
+ "loss": 0.1637,
656
+ "step": 1080
657
+ },
658
+ {
659
+ "epoch": 9.69,
660
+ "learning_rate": 0.012733333333333334,
661
+ "loss": 0.1624,
662
+ "step": 1090
663
+ },
664
+ {
665
+ "epoch": 9.78,
666
+ "learning_rate": 0.012666666666666666,
667
+ "loss": 0.1555,
668
+ "step": 1100
669
+ },
670
+ {
671
+ "epoch": 9.87,
672
+ "learning_rate": 0.0126,
673
+ "loss": 0.1524,
674
+ "step": 1110
675
+ },
676
+ {
677
+ "epoch": 9.96,
678
+ "learning_rate": 0.012533333333333334,
679
+ "loss": 0.1699,
680
+ "step": 1120
681
+ },
682
+ {
683
+ "epoch": 10.04,
684
+ "learning_rate": 0.012466666666666666,
685
+ "loss": 0.1323,
686
+ "step": 1130
687
+ },
688
+ {
689
+ "epoch": 10.13,
690
+ "learning_rate": 0.0124,
691
+ "loss": 0.0931,
692
+ "step": 1140
693
+ },
694
+ {
695
+ "epoch": 10.22,
696
+ "learning_rate": 0.012333333333333335,
697
+ "loss": 0.1054,
698
+ "step": 1150
699
+ },
700
+ {
701
+ "epoch": 10.31,
702
+ "learning_rate": 0.012266666666666665,
703
+ "loss": 0.0922,
704
+ "step": 1160
705
+ },
706
+ {
707
+ "epoch": 10.4,
708
+ "learning_rate": 0.0122,
709
+ "loss": 0.0937,
710
+ "step": 1170
711
+ },
712
+ {
713
+ "epoch": 10.49,
714
+ "learning_rate": 0.012133333333333335,
715
+ "loss": 0.105,
716
+ "step": 1180
717
+ },
718
+ {
719
+ "epoch": 10.58,
720
+ "learning_rate": 0.012066666666666668,
721
+ "loss": 0.1058,
722
+ "step": 1190
723
+ },
724
+ {
725
+ "epoch": 10.67,
726
+ "learning_rate": 0.012,
727
+ "loss": 0.107,
728
+ "step": 1200
729
+ },
730
+ {
731
+ "epoch": 10.76,
732
+ "learning_rate": 0.011933333333333334,
733
+ "loss": 0.112,
734
+ "step": 1210
735
+ },
736
+ {
737
+ "epoch": 10.84,
738
+ "learning_rate": 0.011866666666666668,
739
+ "loss": 0.1196,
740
+ "step": 1220
741
+ },
742
+ {
743
+ "epoch": 10.93,
744
+ "learning_rate": 0.0118,
745
+ "loss": 0.1118,
746
+ "step": 1230
747
+ },
748
+ {
749
+ "epoch": 11.02,
750
+ "learning_rate": 0.011733333333333333,
751
+ "loss": 0.1035,
752
+ "step": 1240
753
+ },
754
+ {
755
+ "epoch": 11.11,
756
+ "learning_rate": 0.011666666666666667,
757
+ "loss": 0.075,
758
+ "step": 1250
759
+ },
760
+ {
761
+ "epoch": 11.2,
762
+ "learning_rate": 0.0116,
763
+ "loss": 0.0698,
764
+ "step": 1260
765
+ },
766
+ {
767
+ "epoch": 11.29,
768
+ "learning_rate": 0.011533333333333333,
769
+ "loss": 0.0727,
770
+ "step": 1270
771
+ },
772
+ {
773
+ "epoch": 11.38,
774
+ "learning_rate": 0.011466666666666667,
775
+ "loss": 0.0729,
776
+ "step": 1280
777
+ },
778
+ {
779
+ "epoch": 11.47,
780
+ "learning_rate": 0.011399999999999999,
781
+ "loss": 0.0701,
782
+ "step": 1290
783
+ },
784
+ {
785
+ "epoch": 11.56,
786
+ "learning_rate": 0.011333333333333332,
787
+ "loss": 0.0871,
788
+ "step": 1300
789
+ },
790
+ {
791
+ "epoch": 11.64,
792
+ "learning_rate": 0.011266666666666668,
793
+ "loss": 0.075,
794
+ "step": 1310
795
+ },
796
+ {
797
+ "epoch": 11.73,
798
+ "learning_rate": 0.011200000000000002,
799
+ "loss": 0.0759,
800
+ "step": 1320
801
+ },
802
+ {
803
+ "epoch": 11.82,
804
+ "learning_rate": 0.011133333333333334,
805
+ "loss": 0.0876,
806
+ "step": 1330
807
+ },
808
+ {
809
+ "epoch": 11.91,
810
+ "learning_rate": 0.011066666666666667,
811
+ "loss": 0.0748,
812
+ "step": 1340
813
+ },
814
+ {
815
+ "epoch": 12.0,
816
+ "learning_rate": 0.011000000000000001,
817
+ "loss": 0.0809,
818
+ "step": 1350
819
+ },
820
+ {
821
+ "epoch": 12.09,
822
+ "learning_rate": 0.010933333333333333,
823
+ "loss": 0.0545,
824
+ "step": 1360
825
+ },
826
+ {
827
+ "epoch": 12.18,
828
+ "learning_rate": 0.010866666666666667,
829
+ "loss": 0.0567,
830
+ "step": 1370
831
+ },
832
+ {
833
+ "epoch": 12.27,
834
+ "learning_rate": 0.0108,
835
+ "loss": 0.0405,
836
+ "step": 1380
837
+ },
838
+ {
839
+ "epoch": 12.36,
840
+ "learning_rate": 0.010733333333333333,
841
+ "loss": 0.0535,
842
+ "step": 1390
843
+ },
844
+ {
845
+ "epoch": 12.44,
846
+ "learning_rate": 0.010666666666666666,
847
+ "loss": 0.0491,
848
+ "step": 1400
849
+ },
850
+ {
851
+ "epoch": 12.53,
852
+ "learning_rate": 0.0106,
853
+ "loss": 0.0488,
854
+ "step": 1410
855
+ },
856
+ {
857
+ "epoch": 12.62,
858
+ "learning_rate": 0.010533333333333332,
859
+ "loss": 0.0575,
860
+ "step": 1420
861
+ },
862
+ {
863
+ "epoch": 12.71,
864
+ "learning_rate": 0.010466666666666666,
865
+ "loss": 0.0528,
866
+ "step": 1430
867
+ },
868
+ {
869
+ "epoch": 12.8,
870
+ "learning_rate": 0.010400000000000001,
871
+ "loss": 0.0549,
872
+ "step": 1440
873
+ },
874
+ {
875
+ "epoch": 12.89,
876
+ "learning_rate": 0.010333333333333335,
877
+ "loss": 0.0651,
878
+ "step": 1450
879
+ },
880
+ {
881
+ "epoch": 12.98,
882
+ "learning_rate": 0.010266666666666667,
883
+ "loss": 0.051,
884
+ "step": 1460
885
+ },
886
+ {
887
+ "epoch": 13.07,
888
+ "learning_rate": 0.0102,
889
+ "loss": 0.0468,
890
+ "step": 1470
891
+ },
892
+ {
893
+ "epoch": 13.16,
894
+ "learning_rate": 0.010133333333333334,
895
+ "loss": 0.0412,
896
+ "step": 1480
897
+ },
898
+ {
899
+ "epoch": 13.24,
900
+ "learning_rate": 0.010066666666666666,
901
+ "loss": 0.0413,
902
+ "step": 1490
903
+ },
904
+ {
905
+ "epoch": 13.33,
906
+ "learning_rate": 0.01,
907
+ "loss": 0.0449,
908
+ "step": 1500
909
+ },
910
+ {
911
+ "epoch": 13.42,
912
+ "learning_rate": 0.009933333333333334,
913
+ "loss": 0.0452,
914
+ "step": 1510
915
+ },
916
+ {
917
+ "epoch": 13.51,
918
+ "learning_rate": 0.009866666666666668,
919
+ "loss": 0.0481,
920
+ "step": 1520
921
+ },
922
+ {
923
+ "epoch": 13.6,
924
+ "learning_rate": 0.0098,
925
+ "loss": 0.0396,
926
+ "step": 1530
927
+ },
928
+ {
929
+ "epoch": 13.69,
930
+ "learning_rate": 0.009733333333333333,
931
+ "loss": 0.0454,
932
+ "step": 1540
933
+ },
934
+ {
935
+ "epoch": 13.78,
936
+ "learning_rate": 0.009666666666666667,
937
+ "loss": 0.0472,
938
+ "step": 1550
939
+ },
940
+ {
941
+ "epoch": 13.87,
942
+ "learning_rate": 0.0096,
943
+ "loss": 0.0397,
944
+ "step": 1560
945
+ },
946
+ {
947
+ "epoch": 13.96,
948
+ "learning_rate": 0.009533333333333335,
949
+ "loss": 0.0482,
950
+ "step": 1570
951
+ },
952
+ {
953
+ "epoch": 14.04,
954
+ "learning_rate": 0.009466666666666667,
955
+ "loss": 0.0377,
956
+ "step": 1580
957
+ },
958
+ {
959
+ "epoch": 14.13,
960
+ "learning_rate": 0.0094,
961
+ "loss": 0.0309,
962
+ "step": 1590
963
+ },
964
+ {
965
+ "epoch": 14.22,
966
+ "learning_rate": 0.009333333333333334,
967
+ "loss": 0.0327,
968
+ "step": 1600
969
+ },
970
+ {
971
+ "epoch": 14.31,
972
+ "learning_rate": 0.009266666666666666,
973
+ "loss": 0.0417,
974
+ "step": 1610
975
+ },
976
+ {
977
+ "epoch": 14.4,
978
+ "learning_rate": 0.0092,
979
+ "loss": 0.0322,
980
+ "step": 1620
981
+ },
982
+ {
983
+ "epoch": 14.49,
984
+ "learning_rate": 0.009133333333333334,
985
+ "loss": 0.039,
986
+ "step": 1630
987
+ },
988
+ {
989
+ "epoch": 14.58,
990
+ "learning_rate": 0.009066666666666666,
991
+ "loss": 0.0334,
992
+ "step": 1640
993
+ },
994
+ {
995
+ "epoch": 14.67,
996
+ "learning_rate": 0.009000000000000001,
997
+ "loss": 0.0411,
998
+ "step": 1650
999
+ },
1000
+ {
1001
+ "epoch": 14.76,
1002
+ "learning_rate": 0.008933333333333333,
1003
+ "loss": 0.033,
1004
+ "step": 1660
1005
+ },
1006
+ {
1007
+ "epoch": 14.84,
1008
+ "learning_rate": 0.008866666666666667,
1009
+ "loss": 0.0353,
1010
+ "step": 1670
1011
+ },
1012
+ {
1013
+ "epoch": 14.93,
1014
+ "learning_rate": 0.0088,
1015
+ "loss": 0.0368,
1016
+ "step": 1680
1017
+ },
1018
+ {
1019
+ "epoch": 15.02,
1020
+ "learning_rate": 0.008733333333333333,
1021
+ "loss": 0.035,
1022
+ "step": 1690
1023
+ },
1024
+ {
1025
+ "epoch": 15.11,
1026
+ "learning_rate": 0.008666666666666668,
1027
+ "loss": 0.0283,
1028
+ "step": 1700
1029
+ },
1030
+ {
1031
+ "epoch": 15.2,
1032
+ "learning_rate": 0.0086,
1033
+ "loss": 0.0269,
1034
+ "step": 1710
1035
+ },
1036
+ {
1037
+ "epoch": 15.29,
1038
+ "learning_rate": 0.008533333333333334,
1039
+ "loss": 0.0284,
1040
+ "step": 1720
1041
+ },
1042
+ {
1043
+ "epoch": 15.38,
1044
+ "learning_rate": 0.008466666666666667,
1045
+ "loss": 0.0294,
1046
+ "step": 1730
1047
+ },
1048
+ {
1049
+ "epoch": 15.47,
1050
+ "learning_rate": 0.0084,
1051
+ "loss": 0.0312,
1052
+ "step": 1740
1053
+ },
1054
+ {
1055
+ "epoch": 15.56,
1056
+ "learning_rate": 0.008333333333333333,
1057
+ "loss": 0.0305,
1058
+ "step": 1750
1059
+ },
1060
+ {
1061
+ "epoch": 15.64,
1062
+ "learning_rate": 0.008266666666666667,
1063
+ "loss": 0.0321,
1064
+ "step": 1760
1065
+ },
1066
+ {
1067
+ "epoch": 15.73,
1068
+ "learning_rate": 0.008199999999999999,
1069
+ "loss": 0.0271,
1070
+ "step": 1770
1071
+ },
1072
+ {
1073
+ "epoch": 15.82,
1074
+ "learning_rate": 0.008133333333333334,
1075
+ "loss": 0.0323,
1076
+ "step": 1780
1077
+ },
1078
+ {
1079
+ "epoch": 15.91,
1080
+ "learning_rate": 0.008066666666666666,
1081
+ "loss": 0.0322,
1082
+ "step": 1790
1083
+ },
1084
+ {
1085
+ "epoch": 16.0,
1086
+ "learning_rate": 0.008,
1087
+ "loss": 0.039,
1088
+ "step": 1800
1089
+ },
1090
+ {
1091
+ "epoch": 16.09,
1092
+ "learning_rate": 0.007933333333333334,
1093
+ "loss": 0.0235,
1094
+ "step": 1810
1095
+ },
1096
+ {
1097
+ "epoch": 16.18,
1098
+ "learning_rate": 0.007866666666666666,
1099
+ "loss": 0.0242,
1100
+ "step": 1820
1101
+ },
1102
+ {
1103
+ "epoch": 16.27,
1104
+ "learning_rate": 0.0078000000000000005,
1105
+ "loss": 0.0302,
1106
+ "step": 1830
1107
+ },
1108
+ {
1109
+ "epoch": 16.36,
1110
+ "learning_rate": 0.007733333333333333,
1111
+ "loss": 0.0256,
1112
+ "step": 1840
1113
+ },
1114
+ {
1115
+ "epoch": 16.44,
1116
+ "learning_rate": 0.007666666666666667,
1117
+ "loss": 0.0315,
1118
+ "step": 1850
1119
+ },
1120
+ {
1121
+ "epoch": 16.53,
1122
+ "learning_rate": 0.0076,
1123
+ "loss": 0.0233,
1124
+ "step": 1860
1125
+ },
1126
+ {
1127
+ "epoch": 16.62,
1128
+ "learning_rate": 0.007533333333333333,
1129
+ "loss": 0.0286,
1130
+ "step": 1870
1131
+ },
1132
+ {
1133
+ "epoch": 16.71,
1134
+ "learning_rate": 0.0074666666666666675,
1135
+ "loss": 0.0263,
1136
+ "step": 1880
1137
+ },
1138
+ {
1139
+ "epoch": 16.8,
1140
+ "learning_rate": 0.0074,
1141
+ "loss": 0.0348,
1142
+ "step": 1890
1143
+ },
1144
+ {
1145
+ "epoch": 16.89,
1146
+ "learning_rate": 0.007333333333333333,
1147
+ "loss": 0.0206,
1148
+ "step": 1900
1149
+ },
1150
+ {
1151
+ "epoch": 16.98,
1152
+ "learning_rate": 0.007266666666666667,
1153
+ "loss": 0.0274,
1154
+ "step": 1910
1155
+ },
1156
+ {
1157
+ "epoch": 17.07,
1158
+ "learning_rate": 0.0072,
1159
+ "loss": 0.0216,
1160
+ "step": 1920
1161
+ },
1162
+ {
1163
+ "epoch": 17.16,
1164
+ "learning_rate": 0.0071333333333333335,
1165
+ "loss": 0.021,
1166
+ "step": 1930
1167
+ },
1168
+ {
1169
+ "epoch": 17.24,
1170
+ "learning_rate": 0.007066666666666666,
1171
+ "loss": 0.0214,
1172
+ "step": 1940
1173
+ },
1174
+ {
1175
+ "epoch": 17.33,
1176
+ "learning_rate": 0.006999999999999999,
1177
+ "loss": 0.0247,
1178
+ "step": 1950
1179
+ },
1180
+ {
1181
+ "epoch": 17.42,
1182
+ "learning_rate": 0.006933333333333334,
1183
+ "loss": 0.0259,
1184
+ "step": 1960
1185
+ },
1186
+ {
1187
+ "epoch": 17.51,
1188
+ "learning_rate": 0.006866666666666667,
1189
+ "loss": 0.0235,
1190
+ "step": 1970
1191
+ },
1192
+ {
1193
+ "epoch": 17.6,
1194
+ "learning_rate": 0.0068000000000000005,
1195
+ "loss": 0.0243,
1196
+ "step": 1980
1197
+ },
1198
+ {
1199
+ "epoch": 17.69,
1200
+ "learning_rate": 0.006733333333333333,
1201
+ "loss": 0.0224,
1202
+ "step": 1990
1203
+ },
1204
+ {
1205
+ "epoch": 17.78,
1206
+ "learning_rate": 0.006666666666666666,
1207
+ "loss": 0.0237,
1208
+ "step": 2000
1209
+ },
1210
+ {
1211
+ "epoch": 17.87,
1212
+ "learning_rate": 0.006600000000000001,
1213
+ "loss": 0.0229,
1214
+ "step": 2010
1215
+ },
1216
+ {
1217
+ "epoch": 17.96,
1218
+ "learning_rate": 0.006533333333333334,
1219
+ "loss": 0.0333,
1220
+ "step": 2020
1221
+ },
1222
+ {
1223
+ "epoch": 18.04,
1224
+ "learning_rate": 0.006466666666666667,
1225
+ "loss": 0.0222,
1226
+ "step": 2030
1227
+ },
1228
+ {
1229
+ "epoch": 18.13,
1230
+ "learning_rate": 0.0064,
1231
+ "loss": 0.0238,
1232
+ "step": 2040
1233
+ },
1234
+ {
1235
+ "epoch": 18.22,
1236
+ "learning_rate": 0.006333333333333333,
1237
+ "loss": 0.0178,
1238
+ "step": 2050
1239
+ },
1240
+ {
1241
+ "epoch": 18.31,
1242
+ "learning_rate": 0.006266666666666667,
1243
+ "loss": 0.0201,
1244
+ "step": 2060
1245
+ },
1246
+ {
1247
+ "epoch": 18.4,
1248
+ "learning_rate": 0.0062,
1249
+ "loss": 0.0197,
1250
+ "step": 2070
1251
+ },
1252
+ {
1253
+ "epoch": 18.49,
1254
+ "learning_rate": 0.006133333333333333,
1255
+ "loss": 0.0224,
1256
+ "step": 2080
1257
+ },
1258
+ {
1259
+ "epoch": 18.58,
1260
+ "learning_rate": 0.006066666666666667,
1261
+ "loss": 0.0228,
1262
+ "step": 2090
1263
+ },
1264
+ {
1265
+ "epoch": 18.67,
1266
+ "learning_rate": 0.006,
1267
+ "loss": 0.021,
1268
+ "step": 2100
1269
+ },
1270
+ {
1271
+ "epoch": 18.76,
1272
+ "learning_rate": 0.005933333333333334,
1273
+ "loss": 0.0221,
1274
+ "step": 2110
1275
+ },
1276
+ {
1277
+ "epoch": 18.84,
1278
+ "learning_rate": 0.005866666666666667,
1279
+ "loss": 0.0227,
1280
+ "step": 2120
1281
+ },
1282
+ {
1283
+ "epoch": 18.93,
1284
+ "learning_rate": 0.0058,
1285
+ "loss": 0.0205,
1286
+ "step": 2130
1287
+ },
1288
+ {
1289
+ "epoch": 19.02,
1290
+ "learning_rate": 0.005733333333333333,
1291
+ "loss": 0.0219,
1292
+ "step": 2140
1293
+ },
1294
+ {
1295
+ "epoch": 19.11,
1296
+ "learning_rate": 0.005666666666666666,
1297
+ "loss": 0.0197,
1298
+ "step": 2150
1299
+ },
1300
+ {
1301
+ "epoch": 19.2,
1302
+ "learning_rate": 0.005600000000000001,
1303
+ "loss": 0.0174,
1304
+ "step": 2160
1305
+ },
1306
+ {
1307
+ "epoch": 19.29,
1308
+ "learning_rate": 0.005533333333333334,
1309
+ "loss": 0.0175,
1310
+ "step": 2170
1311
+ },
1312
+ {
1313
+ "epoch": 19.38,
1314
+ "learning_rate": 0.0054666666666666665,
1315
+ "loss": 0.0172,
1316
+ "step": 2180
1317
+ },
1318
+ {
1319
+ "epoch": 19.47,
1320
+ "learning_rate": 0.0054,
1321
+ "loss": 0.0189,
1322
+ "step": 2190
1323
+ },
1324
+ {
1325
+ "epoch": 19.56,
1326
+ "learning_rate": 0.005333333333333333,
1327
+ "loss": 0.0168,
1328
+ "step": 2200
1329
+ },
1330
+ {
1331
+ "epoch": 19.64,
1332
+ "learning_rate": 0.005266666666666666,
1333
+ "loss": 0.0168,
1334
+ "step": 2210
1335
+ },
1336
+ {
1337
+ "epoch": 19.73,
1338
+ "learning_rate": 0.005200000000000001,
1339
+ "loss": 0.0215,
1340
+ "step": 2220
1341
+ },
1342
+ {
1343
+ "epoch": 19.82,
1344
+ "learning_rate": 0.0051333333333333335,
1345
+ "loss": 0.0204,
1346
+ "step": 2230
1347
+ },
1348
+ {
1349
+ "epoch": 19.91,
1350
+ "learning_rate": 0.005066666666666667,
1351
+ "loss": 0.0202,
1352
+ "step": 2240
1353
+ },
1354
+ {
1355
+ "epoch": 20.0,
1356
+ "learning_rate": 0.005,
1357
+ "loss": 0.0158,
1358
+ "step": 2250
1359
+ },
1360
+ {
1361
+ "epoch": 20.09,
1362
+ "learning_rate": 0.004933333333333334,
1363
+ "loss": 0.0139,
1364
+ "step": 2260
1365
+ },
1366
+ {
1367
+ "epoch": 20.18,
1368
+ "learning_rate": 0.004866666666666667,
1369
+ "loss": 0.0169,
1370
+ "step": 2270
1371
+ },
1372
+ {
1373
+ "epoch": 20.27,
1374
+ "learning_rate": 0.0048,
1375
+ "loss": 0.015,
1376
+ "step": 2280
1377
+ },
1378
+ {
1379
+ "epoch": 20.36,
1380
+ "learning_rate": 0.004733333333333333,
1381
+ "loss": 0.0135,
1382
+ "step": 2290
1383
+ },
1384
+ {
1385
+ "epoch": 20.44,
1386
+ "learning_rate": 0.004666666666666667,
1387
+ "loss": 0.0156,
1388
+ "step": 2300
1389
+ },
1390
+ {
1391
+ "epoch": 20.53,
1392
+ "learning_rate": 0.0046,
1393
+ "loss": 0.014,
1394
+ "step": 2310
1395
+ },
1396
+ {
1397
+ "epoch": 20.62,
1398
+ "learning_rate": 0.004533333333333333,
1399
+ "loss": 0.0171,
1400
+ "step": 2320
1401
+ },
1402
+ {
1403
+ "epoch": 20.71,
1404
+ "learning_rate": 0.0044666666666666665,
1405
+ "loss": 0.0171,
1406
+ "step": 2330
1407
+ },
1408
+ {
1409
+ "epoch": 20.8,
1410
+ "learning_rate": 0.0044,
1411
+ "loss": 0.0215,
1412
+ "step": 2340
1413
+ },
1414
+ {
1415
+ "epoch": 20.89,
1416
+ "learning_rate": 0.004333333333333334,
1417
+ "loss": 0.016,
1418
+ "step": 2350
1419
+ },
1420
+ {
1421
+ "epoch": 20.98,
1422
+ "learning_rate": 0.004266666666666667,
1423
+ "loss": 0.0186,
1424
+ "step": 2360
1425
+ },
1426
+ {
1427
+ "epoch": 21.07,
1428
+ "learning_rate": 0.0042,
1429
+ "loss": 0.0155,
1430
+ "step": 2370
1431
+ },
1432
+ {
1433
+ "epoch": 21.16,
1434
+ "learning_rate": 0.0041333333333333335,
1435
+ "loss": 0.0128,
1436
+ "step": 2380
1437
+ },
1438
+ {
1439
+ "epoch": 21.24,
1440
+ "learning_rate": 0.004066666666666667,
1441
+ "loss": 0.0146,
1442
+ "step": 2390
1443
+ },
1444
+ {
1445
+ "epoch": 21.33,
1446
+ "learning_rate": 0.004,
1447
+ "loss": 0.016,
1448
+ "step": 2400
1449
+ },
1450
+ {
1451
+ "epoch": 21.42,
1452
+ "learning_rate": 0.003933333333333333,
1453
+ "loss": 0.0125,
1454
+ "step": 2410
1455
+ },
1456
+ {
1457
+ "epoch": 21.51,
1458
+ "learning_rate": 0.0038666666666666667,
1459
+ "loss": 0.0129,
1460
+ "step": 2420
1461
+ },
1462
+ {
1463
+ "epoch": 21.6,
1464
+ "learning_rate": 0.0038,
1465
+ "loss": 0.0135,
1466
+ "step": 2430
1467
+ },
1468
+ {
1469
+ "epoch": 21.69,
1470
+ "learning_rate": 0.0037333333333333337,
1471
+ "loss": 0.0132,
1472
+ "step": 2440
1473
+ },
1474
+ {
1475
+ "epoch": 21.78,
1476
+ "learning_rate": 0.0036666666666666666,
1477
+ "loss": 0.0174,
1478
+ "step": 2450
1479
+ },
1480
+ {
1481
+ "epoch": 21.87,
1482
+ "learning_rate": 0.0036,
1483
+ "loss": 0.0158,
1484
+ "step": 2460
1485
+ },
1486
+ {
1487
+ "epoch": 21.96,
1488
+ "learning_rate": 0.003533333333333333,
1489
+ "loss": 0.0172,
1490
+ "step": 2470
1491
+ },
1492
+ {
1493
+ "epoch": 22.04,
1494
+ "learning_rate": 0.003466666666666667,
1495
+ "loss": 0.0153,
1496
+ "step": 2480
1497
+ },
1498
+ {
1499
+ "epoch": 22.13,
1500
+ "learning_rate": 0.0034000000000000002,
1501
+ "loss": 0.0133,
1502
+ "step": 2490
1503
+ },
1504
+ {
1505
+ "epoch": 22.22,
1506
+ "learning_rate": 0.003333333333333333,
1507
+ "loss": 0.0135,
1508
+ "step": 2500
1509
+ },
1510
+ {
1511
+ "epoch": 22.31,
1512
+ "learning_rate": 0.003266666666666667,
1513
+ "loss": 0.0126,
1514
+ "step": 2510
1515
+ },
1516
+ {
1517
+ "epoch": 22.4,
1518
+ "learning_rate": 0.0032,
1519
+ "loss": 0.0148,
1520
+ "step": 2520
1521
+ },
1522
+ {
1523
+ "epoch": 22.49,
1524
+ "learning_rate": 0.0031333333333333335,
1525
+ "loss": 0.0152,
1526
+ "step": 2530
1527
+ },
1528
+ {
1529
+ "epoch": 22.58,
1530
+ "learning_rate": 0.0030666666666666663,
1531
+ "loss": 0.0132,
1532
+ "step": 2540
1533
+ },
1534
+ {
1535
+ "epoch": 22.67,
1536
+ "learning_rate": 0.003,
1537
+ "loss": 0.017,
1538
+ "step": 2550
1539
+ },
1540
+ {
1541
+ "epoch": 22.76,
1542
+ "learning_rate": 0.0029333333333333334,
1543
+ "loss": 0.0147,
1544
+ "step": 2560
1545
+ },
1546
+ {
1547
+ "epoch": 22.84,
1548
+ "learning_rate": 0.0028666666666666667,
1549
+ "loss": 0.0174,
1550
+ "step": 2570
1551
+ },
1552
+ {
1553
+ "epoch": 22.93,
1554
+ "learning_rate": 0.0028000000000000004,
1555
+ "loss": 0.0114,
1556
+ "step": 2580
1557
+ },
1558
+ {
1559
+ "epoch": 23.02,
1560
+ "learning_rate": 0.0027333333333333333,
1561
+ "loss": 0.0143,
1562
+ "step": 2590
1563
+ },
1564
+ {
1565
+ "epoch": 23.11,
1566
+ "learning_rate": 0.0026666666666666666,
1567
+ "loss": 0.0127,
1568
+ "step": 2600
1569
+ },
1570
+ {
1571
+ "epoch": 23.2,
1572
+ "learning_rate": 0.0026000000000000003,
1573
+ "loss": 0.0127,
1574
+ "step": 2610
1575
+ },
1576
+ {
1577
+ "epoch": 23.29,
1578
+ "learning_rate": 0.0025333333333333336,
1579
+ "loss": 0.0121,
1580
+ "step": 2620
1581
+ },
1582
+ {
1583
+ "epoch": 23.38,
1584
+ "learning_rate": 0.002466666666666667,
1585
+ "loss": 0.0132,
1586
+ "step": 2630
1587
+ },
1588
+ {
1589
+ "epoch": 23.47,
1590
+ "learning_rate": 0.0024,
1591
+ "loss": 0.0114,
1592
+ "step": 2640
1593
+ },
1594
+ {
1595
+ "epoch": 23.56,
1596
+ "learning_rate": 0.0023333333333333335,
1597
+ "loss": 0.0102,
1598
+ "step": 2650
1599
+ },
1600
+ {
1601
+ "epoch": 23.64,
1602
+ "learning_rate": 0.0022666666666666664,
1603
+ "loss": 0.0158,
1604
+ "step": 2660
1605
+ },
1606
+ {
1607
+ "epoch": 23.73,
1608
+ "learning_rate": 0.0022,
1609
+ "loss": 0.0144,
1610
+ "step": 2670
1611
+ },
1612
+ {
1613
+ "epoch": 23.82,
1614
+ "learning_rate": 0.0021333333333333334,
1615
+ "loss": 0.014,
1616
+ "step": 2680
1617
+ },
1618
+ {
1619
+ "epoch": 23.91,
1620
+ "learning_rate": 0.0020666666666666667,
1621
+ "loss": 0.0121,
1622
+ "step": 2690
1623
+ },
1624
+ {
1625
+ "epoch": 24.0,
1626
+ "learning_rate": 0.002,
1627
+ "loss": 0.0159,
1628
+ "step": 2700
1629
+ },
1630
+ {
1631
+ "epoch": 24.09,
1632
+ "learning_rate": 0.0019333333333333333,
1633
+ "loss": 0.0104,
1634
+ "step": 2710
1635
+ },
1636
+ {
1637
+ "epoch": 24.18,
1638
+ "learning_rate": 0.0018666666666666669,
1639
+ "loss": 0.0122,
1640
+ "step": 2720
1641
+ },
1642
+ {
1643
+ "epoch": 24.27,
1644
+ "learning_rate": 0.0018,
1645
+ "loss": 0.011,
1646
+ "step": 2730
1647
+ },
1648
+ {
1649
+ "epoch": 24.36,
1650
+ "learning_rate": 0.0017333333333333335,
1651
+ "loss": 0.0129,
1652
+ "step": 2740
1653
+ },
1654
+ {
1655
+ "epoch": 24.44,
1656
+ "learning_rate": 0.0016666666666666666,
1657
+ "loss": 0.0145,
1658
+ "step": 2750
1659
+ },
1660
+ {
1661
+ "epoch": 24.53,
1662
+ "learning_rate": 0.0016,
1663
+ "loss": 0.0134,
1664
+ "step": 2760
1665
+ },
1666
+ {
1667
+ "epoch": 24.62,
1668
+ "learning_rate": 0.0015333333333333332,
1669
+ "loss": 0.0121,
1670
+ "step": 2770
1671
+ },
1672
+ {
1673
+ "epoch": 24.71,
1674
+ "learning_rate": 0.0014666666666666667,
1675
+ "loss": 0.0136,
1676
+ "step": 2780
1677
+ },
1678
+ {
1679
+ "epoch": 24.8,
1680
+ "learning_rate": 0.0014000000000000002,
1681
+ "loss": 0.0128,
1682
+ "step": 2790
1683
+ },
1684
+ {
1685
+ "epoch": 24.89,
1686
+ "learning_rate": 0.0013333333333333333,
1687
+ "loss": 0.0124,
1688
+ "step": 2800
1689
+ },
1690
+ {
1691
+ "epoch": 24.98,
1692
+ "learning_rate": 0.0012666666666666668,
1693
+ "loss": 0.0132,
1694
+ "step": 2810
1695
+ },
1696
+ {
1697
+ "epoch": 25.07,
1698
+ "learning_rate": 0.0012,
1699
+ "loss": 0.0116,
1700
+ "step": 2820
1701
+ },
1702
+ {
1703
+ "epoch": 25.16,
1704
+ "learning_rate": 0.0011333333333333332,
1705
+ "loss": 0.0118,
1706
+ "step": 2830
1707
+ },
1708
+ {
1709
+ "epoch": 25.24,
1710
+ "learning_rate": 0.0010666666666666667,
1711
+ "loss": 0.0123,
1712
+ "step": 2840
1713
+ },
1714
+ {
1715
+ "epoch": 25.33,
1716
+ "learning_rate": 0.001,
1717
+ "loss": 0.0117,
1718
+ "step": 2850
1719
+ },
1720
+ {
1721
+ "epoch": 25.42,
1722
+ "learning_rate": 0.0009333333333333334,
1723
+ "loss": 0.0144,
1724
+ "step": 2860
1725
+ },
1726
+ {
1727
+ "epoch": 25.51,
1728
+ "learning_rate": 0.0008666666666666667,
1729
+ "loss": 0.0112,
1730
+ "step": 2870
1731
+ },
1732
+ {
1733
+ "epoch": 25.6,
1734
+ "learning_rate": 0.0008,
1735
+ "loss": 0.0125,
1736
+ "step": 2880
1737
+ },
1738
+ {
1739
+ "epoch": 25.69,
1740
+ "learning_rate": 0.0007333333333333333,
1741
+ "loss": 0.0121,
1742
+ "step": 2890
1743
+ },
1744
+ {
1745
+ "epoch": 25.78,
1746
+ "learning_rate": 0.0006666666666666666,
1747
+ "loss": 0.0131,
1748
+ "step": 2900
1749
+ },
1750
+ {
1751
+ "epoch": 25.87,
1752
+ "learning_rate": 0.0006,
1753
+ "loss": 0.0102,
1754
+ "step": 2910
1755
+ },
1756
+ {
1757
+ "epoch": 25.96,
1758
+ "learning_rate": 0.0005333333333333334,
1759
+ "loss": 0.012,
1760
+ "step": 2920
1761
+ },
1762
+ {
1763
+ "epoch": 26.04,
1764
+ "learning_rate": 0.0004666666666666667,
1765
+ "loss": 0.0106,
1766
+ "step": 2930
1767
+ },
1768
+ {
1769
+ "epoch": 26.13,
1770
+ "learning_rate": 0.0004,
1771
+ "loss": 0.0103,
1772
+ "step": 2940
1773
+ },
1774
+ {
1775
+ "epoch": 26.22,
1776
+ "learning_rate": 0.0003333333333333333,
1777
+ "loss": 0.011,
1778
+ "step": 2950
1779
+ },
1780
+ {
1781
+ "epoch": 26.31,
1782
+ "learning_rate": 0.0002666666666666667,
1783
+ "loss": 0.0114,
1784
+ "step": 2960
1785
+ },
1786
+ {
1787
+ "epoch": 26.4,
1788
+ "learning_rate": 0.0002,
1789
+ "loss": 0.0133,
1790
+ "step": 2970
1791
+ },
1792
+ {
1793
+ "epoch": 26.49,
1794
+ "learning_rate": 0.00013333333333333334,
1795
+ "loss": 0.0105,
1796
+ "step": 2980
1797
+ },
1798
+ {
1799
+ "epoch": 26.58,
1800
+ "learning_rate": 6.666666666666667e-05,
1801
+ "loss": 0.0137,
1802
+ "step": 2990
1803
+ },
1804
+ {
1805
+ "epoch": 26.67,
1806
+ "learning_rate": 0.0,
1807
+ "loss": 0.0106,
1808
+ "step": 3000
1809
+ }
1810
+ ],
1811
+ "max_steps": 3000,
1812
+ "num_train_epochs": 27,
1813
+ "total_flos": 8.31451847196672e+17,
1814
+ "trial_name": null,
1815
+ "trial_params": null
1816
+ }
batmanmodel/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df629dc9b91c49cd538d997ae569e4cfce6b8346e305b2d4c871f22a2aefec57
3
+ size 3707
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ protobuf
2
+ transformers==4.27.1
3
+ cpm_kernels
4
+ torch>=1.10
5
+ gradio
6
+ mdtex2html
7
+ sentencepiece