hahafofo commited on
Commit
1f5430c
·
1 Parent(s): 06860d2
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.safetensors filter=lfs diff=lfs merge=lfs -text
37
+ training_args.bin filter=lfs diff=lfs merge=lfs -text
38
+ qwen.tiktoken filter=lfs diff=lfs merge=lfs -text
config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "./models/Qwen-1_8B-Chat",
3
+ "architectures": [
4
+ "QWenLMHeadModel"
5
+ ],
6
+ "attn_dropout_prob": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_qwen.QWenConfig",
9
+ "AutoModelForCausalLM": "modeling_qwen.QWenLMHeadModel"
10
+ },
11
+ "bf16": true,
12
+ "emb_dropout_prob": 0.0,
13
+ "fp16": false,
14
+ "fp32": false,
15
+ "hidden_size": 2048,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 11008,
18
+ "kv_channels": 128,
19
+ "layer_norm_epsilon": 1e-06,
20
+ "max_position_embeddings": 8192,
21
+ "model_type": "qwen",
22
+ "no_bias": true,
23
+ "num_attention_heads": 16,
24
+ "num_hidden_layers": 24,
25
+ "onnx_safe": null,
26
+ "rotary_emb_base": 10000,
27
+ "rotary_pct": 1.0,
28
+ "scale_attn_weights": true,
29
+ "seq_length": 8192,
30
+ "softmax_in_fp32": false,
31
+ "tie_word_embeddings": false,
32
+ "tokenizer_class": "QWenTokenizer",
33
+ "torch_dtype": "bfloat16",
34
+ "transformers_version": "4.35.2",
35
+ "use_cache": false,
36
+ "use_cache_kernel": false,
37
+ "use_cache_quantization": false,
38
+ "use_dynamic_ntk": true,
39
+ "use_flash_attn": true,
40
+ "use_logn_attn": true,
41
+ "vocab_size": 151936
42
+ }
configuration_qwen.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ from transformers import PretrainedConfig
7
+
8
+
9
+ class QWenConfig(PretrainedConfig):
10
+ model_type = "qwen"
11
+ keys_to_ignore_at_inference = ["past_key_values"]
12
+
13
+ def __init__(
14
+ self,
15
+ vocab_size=151936,
16
+ hidden_size=4096,
17
+ num_hidden_layers=32,
18
+ num_attention_heads=32,
19
+ emb_dropout_prob=0.0,
20
+ attn_dropout_prob=0.0,
21
+ layer_norm_epsilon=1e-6,
22
+ initializer_range=0.02,
23
+ max_position_embeddings=8192,
24
+ scale_attn_weights=True,
25
+ use_cache=True,
26
+ bf16=False,
27
+ fp16=False,
28
+ fp32=False,
29
+ kv_channels=128,
30
+ rotary_pct=1.0,
31
+ rotary_emb_base=10000,
32
+ use_dynamic_ntk=True,
33
+ use_logn_attn=True,
34
+ use_flash_attn="auto",
35
+ intermediate_size=22016,
36
+ no_bias=True,
37
+ tie_word_embeddings=False,
38
+ use_cache_quantization=False,
39
+ use_cache_kernel=False,
40
+ softmax_in_fp32=False,
41
+ **kwargs,
42
+ ):
43
+ self.vocab_size = vocab_size
44
+ self.hidden_size = hidden_size
45
+ self.intermediate_size = intermediate_size
46
+ self.num_hidden_layers = num_hidden_layers
47
+ self.num_attention_heads = num_attention_heads
48
+ self.emb_dropout_prob = emb_dropout_prob
49
+ self.attn_dropout_prob = attn_dropout_prob
50
+ self.layer_norm_epsilon = layer_norm_epsilon
51
+ self.initializer_range = initializer_range
52
+ self.scale_attn_weights = scale_attn_weights
53
+ self.use_cache = use_cache
54
+ self.max_position_embeddings = max_position_embeddings
55
+ self.bf16 = bf16
56
+ self.fp16 = fp16
57
+ self.fp32 = fp32
58
+ self.kv_channels = kv_channels
59
+ self.rotary_pct = rotary_pct
60
+ self.rotary_emb_base = rotary_emb_base
61
+ self.use_dynamic_ntk = use_dynamic_ntk
62
+ self.use_logn_attn = use_logn_attn
63
+ self.use_flash_attn = use_flash_attn
64
+ self.no_bias = no_bias
65
+ self.use_cache_quantization = use_cache_quantization
66
+ self.use_cache_kernel = use_cache_kernel
67
+ self.softmax_in_fp32 = softmax_in_fp32
68
+ super().__init__(
69
+ tie_word_embeddings=tie_word_embeddings,
70
+ **kwargs
71
+ )
cpp_kernels.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from torch.utils import cpp_extension
2
+ import pathlib
3
+ import os
4
+ import subprocess
5
+
6
+ def _get_cuda_bare_metal_version(cuda_dir):
7
+ raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"],
8
+ universal_newlines=True)
9
+ output = raw_output.split()
10
+ release_idx = output.index("release") + 1
11
+ release = output[release_idx].split(".")
12
+ bare_metal_major = release[0]
13
+ bare_metal_minor = release[1][0]
14
+
15
+ return raw_output, bare_metal_major, bare_metal_minor
16
+
17
+ def _create_build_dir(buildpath):
18
+ try:
19
+ os.mkdir(buildpath)
20
+ except OSError:
21
+ if not os.path.isdir(buildpath):
22
+ print(f"Creation of the build directory {buildpath} failed")
23
+
24
+ # Check if cuda 11 is installed for compute capability 8.0
25
+ cc_flag = []
26
+ _, bare_metal_major, bare_metal_minor = _get_cuda_bare_metal_version(cpp_extension.CUDA_HOME)
27
+ if int(bare_metal_major) >= 11:
28
+ cc_flag.append('-gencode')
29
+ cc_flag.append('arch=compute_80,code=sm_80')
30
+ if int(bare_metal_minor) >= 7:
31
+ cc_flag.append('-gencode')
32
+ cc_flag.append('arch=compute_90,code=sm_90')
33
+
34
+ # Build path
35
+ srcpath = pathlib.Path(__file__).parent.absolute()
36
+ buildpath = srcpath / 'build'
37
+ _create_build_dir(buildpath)
38
+
39
+ def _cpp_extention_load_helper(name, sources, extra_cuda_flags):
40
+ return cpp_extension.load(
41
+ name=name,
42
+ sources=sources,
43
+ build_directory=buildpath,
44
+ extra_cflags=['-O3', ],
45
+ extra_cuda_cflags=['-O3',
46
+ '-gencode', 'arch=compute_70,code=sm_70',
47
+ '--use_fast_math'] + extra_cuda_flags + cc_flag,
48
+ verbose=1
49
+ )
50
+
51
+ extra_flags = []
52
+
53
+ cache_autogptq_cuda_256_sources = ["./cache_autogptq_cuda_256.cpp",
54
+ "./cache_autogptq_cuda_kernel_256.cu"]
55
+ cache_autogptq_cuda_256 = _cpp_extention_load_helper("cache_autogptq_cuda_256", cache_autogptq_cuda_256_sources, extra_flags)
generation_config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "chat_format": "chatml",
3
+ "do_sample": true,
4
+ "eos_token_id": 151643,
5
+ "max_new_tokens": 512,
6
+ "max_window_size": 6144,
7
+ "pad_token_id": 151643,
8
+ "repetition_penalty": 1.1,
9
+ "top_k": 0,
10
+ "top_p": 0.8,
11
+ "transformers_version": "4.35.2"
12
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:694061c10a45ea519f391b6b3d4035bec1e2ea5fa04e109e4683932666cd4c0b
3
+ size 3673678408
modeling_qwen.py ADDED
@@ -0,0 +1,1378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ import copy
7
+ import importlib
8
+ import math
9
+ import pathlib
10
+ from typing import TYPE_CHECKING, Optional, Tuple, Union, Callable, List, Any, Generator
11
+
12
+ import torch
13
+ import torch.nn.functional as F
14
+ import torch.utils.checkpoint
15
+ import warnings
16
+
17
+ from torch.nn import CrossEntropyLoss
18
+ from transformers import PreTrainedTokenizer, GenerationConfig, StoppingCriteriaList
19
+ from transformers.generation.logits_process import LogitsProcessorList
20
+
21
+ if TYPE_CHECKING:
22
+ from transformers.generation.streamers import BaseStreamer
23
+ from transformers.generation.utils import GenerateOutput
24
+ from transformers.modeling_outputs import (
25
+ BaseModelOutputWithPast,
26
+ CausalLMOutputWithPast,
27
+ )
28
+ from transformers.modeling_utils import PreTrainedModel
29
+ from transformers.utils import logging
30
+
31
+ try:
32
+ from einops import rearrange
33
+ except ImportError:
34
+ rearrange = None
35
+ from torch import nn
36
+
37
+ SUPPORT_CUDA = torch.cuda.is_available()
38
+ SUPPORT_BF16 = SUPPORT_CUDA and torch.cuda.is_bf16_supported()
39
+ SUPPORT_FP16 = SUPPORT_CUDA and torch.cuda.get_device_capability(0)[0] >= 7
40
+ SUPPORT_TORCH2 = hasattr(torch, '__version__') and int(torch.__version__.split(".")[0]) >= 2
41
+
42
+
43
+ from .configuration_qwen import QWenConfig
44
+ from .qwen_generation_utils import (
45
+ HistoryType,
46
+ make_context,
47
+ decode_tokens,
48
+ get_stop_words_ids,
49
+ StopWordsLogitsProcessor,
50
+ )
51
+
52
+
53
+ logger = logging.get_logger(__name__)
54
+
55
+ _CHECKPOINT_FOR_DOC = "qwen"
56
+ _CONFIG_FOR_DOC = "QWenConfig"
57
+
58
+ QWen_PRETRAINED_MODEL_ARCHIVE_LIST = ["qwen-7b"]
59
+
60
+ _ERROR_BAD_CHAT_FORMAT = """\
61
+ We detect you are probably using the pretrained model (rather than chat model) for chatting, since the chat_format in generation_config is not "chatml".
62
+ If you are directly using the model downloaded from Huggingface, please make sure you are using our "Qwen/Qwen-7B-Chat" Huggingface model (rather than "Qwen/Qwen-7B") when you call model.chat().
63
+ 我们检测到您可能在使用预训练模型(而非chat模型)进行多轮chat,因为您当前在generation_config指定的chat_format,并未设置为我们在对话中所支持的"chatml"格式。
64
+ 如果您在直接使用我们从Huggingface提供的模型,请确保您在调用model.chat()时,使用的是"Qwen/Qwen-7B-Chat"模型(而非"Qwen/Qwen-7B"预训练模型)。
65
+ """
66
+
67
+ _SENTINEL = object()
68
+ _ERROR_STREAM_IN_CHAT = """\
69
+ Pass argument `stream` to model.chat() is buggy, deprecated, and marked for removal. Please use model.chat_stream(...) instead of model.chat(..., stream=True).
70
+ 向model.chat()传入参数stream的用法可能存在Bug,该用法已被废弃,将在未来被移除。请使用model.chat_stream(...)代替model.chat(..., stream=True)。
71
+ """
72
+
73
+ _ERROR_INPUT_CPU_QUERY_WITH_FLASH_ATTN_ACTIVATED = """\
74
+ We detect you have activated flash attention support, but running model computation on CPU. Please make sure that your input data has been placed on GPU. If you actually want to run CPU computation, please following the readme and set device_map="cpu" to disable flash attention when loading the model (calling AutoModelForCausalLM.from_pretrained).
75
+ 检测到您的模型已激活了flash attention支持,但正在执行CPU运算任务。如使用flash attention,请您确认模型输入已经传到GPU上。如果您确认要执行CPU运算,请您在载入模型(调用AutoModelForCausalLM.from_pretrained)时,按照readme说法,指定device_map="cpu"以禁用flash attention。
76
+ """
77
+
78
+ apply_rotary_emb_func = None
79
+ rms_norm = None
80
+ flash_attn_unpadded_func = None
81
+ flash_attn_func = None
82
+
83
+ def _import_flash_attn():
84
+ global apply_rotary_emb_func, rms_norm, flash_attn_unpadded_func, flash_attn_func
85
+ try:
86
+ from flash_attn.layers.rotary import apply_rotary_emb_func as __apply_rotary_emb_func
87
+ apply_rotary_emb_func = __apply_rotary_emb_func
88
+ except ImportError:
89
+ logger.warn(
90
+ "Warning: import flash_attn rotary fail, please install FlashAttention rotary to get higher efficiency "
91
+ "https://github.com/Dao-AILab/flash-attention/tree/main/csrc/rotary"
92
+ )
93
+
94
+ try:
95
+ from flash_attn.ops.rms_norm import rms_norm as __rms_norm
96
+ rms_norm = __rms_norm
97
+ except ImportError:
98
+ logger.warn(
99
+ "Warning: import flash_attn rms_norm fail, please install FlashAttention layer_norm to get higher efficiency "
100
+ "https://github.com/Dao-AILab/flash-attention/tree/main/csrc/layer_norm"
101
+ )
102
+
103
+ try:
104
+ import flash_attn
105
+ _flash_attn_func = None
106
+ if not hasattr(flash_attn, '__version__'):
107
+ from flash_attn.flash_attn_interface import flash_attn_unpadded_func as __flash_attn_unpadded_func
108
+ else:
109
+ if int(flash_attn.__version__.split(".")[0]) >= 2:
110
+ if int(flash_attn.__version__.split(".")[1]) >= 1:
111
+ from flash_attn.flash_attn_interface import flash_attn_func as _flash_attn_func
112
+ from flash_attn.flash_attn_interface import flash_attn_varlen_func as __flash_attn_unpadded_func
113
+ else:
114
+ from flash_attn.flash_attn_interface import flash_attn_unpadded_func as __flash_attn_unpadded_func
115
+ flash_attn_unpadded_func = __flash_attn_unpadded_func
116
+ flash_attn_func = _flash_attn_func
117
+ except ImportError:
118
+ logger.warn(
119
+ "Warning: import flash_attn fail, please install FlashAttention to get higher efficiency "
120
+ "https://github.com/Dao-AILab/flash-attention"
121
+ )
122
+
123
+ def quantize_cache_v(fdata, bits, qmax, qmin):
124
+ # b, s, head, h-dim->b, head, s, h-dim
125
+ qtype = torch.uint8
126
+ device = fdata.device
127
+ shape = fdata.shape
128
+
129
+ fdata_cal = torch.flatten(fdata, 2)
130
+ fmax = torch.amax(fdata_cal, dim=-1, keepdim=True)
131
+ fmin = torch.amin(fdata_cal, dim=-1, keepdim=True)
132
+ # Compute params
133
+ if qmax.device != fmax.device:
134
+ qmax = qmax.to(device)
135
+ qmin = qmin.to(device)
136
+ scale = (fmax - fmin) / (qmax - qmin)
137
+ zero = qmin - fmin / scale
138
+ scale = scale.unsqueeze(-1).repeat(1,1,shape[2],1).contiguous()
139
+ zero = zero.unsqueeze(-1).repeat(1,1,shape[2],1).contiguous()
140
+ # Quantize
141
+ res_data = fdata / scale + zero
142
+ qdata = torch.clamp(res_data, qmin, qmax).to(qtype)
143
+ return qdata.contiguous(), scale, zero
144
+
145
+ def dequantize_cache_torch(qdata, scale, zero):
146
+ data = scale * (qdata - zero)
147
+ return data
148
+
149
+ class FlashSelfAttention(torch.nn.Module):
150
+ def __init__(
151
+ self,
152
+ causal=False,
153
+ softmax_scale=None,
154
+ attention_dropout=0.0,
155
+ ):
156
+ super().__init__()
157
+ assert flash_attn_unpadded_func is not None, (
158
+ "Please install FlashAttention first, " "e.g., with pip install flash-attn"
159
+ )
160
+ assert (
161
+ rearrange is not None
162
+ ), "Please install einops first, e.g., with pip install einops"
163
+ self.causal = causal
164
+ self.softmax_scale = softmax_scale
165
+ self.dropout_p = attention_dropout
166
+
167
+ def unpad_input(self, hidden_states, attention_mask):
168
+ valid_mask = attention_mask.squeeze(1).squeeze(1).eq(0)
169
+ seqlens_in_batch = valid_mask.sum(dim=-1, dtype=torch.int32)
170
+ indices = torch.nonzero(valid_mask.flatten(), as_tuple=False).flatten()
171
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
172
+ cu_seqlens = F.pad(torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0))
173
+ hidden_states = hidden_states[indices]
174
+ return hidden_states, indices, cu_seqlens, max_seqlen_in_batch
175
+
176
+ def pad_input(self, hidden_states, indices, batch, seqlen):
177
+ output = torch.zeros(batch * seqlen, *hidden_states.shape[1:], device=hidden_states.device,
178
+ dtype=hidden_states.dtype)
179
+ output[indices] = hidden_states
180
+ return rearrange(output, '(b s) ... -> b s ...', b=batch)
181
+
182
+ def forward(self, q, k, v, attention_mask=None):
183
+ assert all((i.dtype in [torch.float16, torch.bfloat16] for i in (q, k, v)))
184
+ assert all((i.is_cuda for i in (q, k, v)))
185
+ batch_size, seqlen_q = q.shape[0], q.shape[1]
186
+ seqlen_k = k.shape[1]
187
+ seqlen_out = seqlen_q
188
+
189
+ if flash_attn_func is not None and batch_size == 1:
190
+ dropout_p = self.dropout_p if self.training else 0
191
+ output = flash_attn_func(q, k, v, dropout_p, softmax_scale=self.softmax_scale, causal=self.causal)
192
+ return output
193
+
194
+ q, k, v = [rearrange(x, "b s ... -> (b s) ...") for x in [q, k, v]]
195
+ cu_seqlens_q = torch.arange(
196
+ 0,
197
+ (batch_size + 1) * seqlen_q,
198
+ step=seqlen_q,
199
+ dtype=torch.int32,
200
+ device=q.device,
201
+ )
202
+
203
+ if batch_size > 1 and attention_mask is not None:
204
+ k, indices_k, cu_seqlens_k, seqlen_k = self.unpad_input(k, attention_mask)
205
+ if q.size(0) == v.size(0):
206
+ q = q[indices_k]
207
+ cu_seqlens_q = cu_seqlens_k
208
+ seqlen_q = seqlen_k
209
+ v = v[indices_k]
210
+ else:
211
+ cu_seqlens_k = torch.arange(
212
+ 0,
213
+ (batch_size + 1) * seqlen_k,
214
+ step=seqlen_k,
215
+ dtype=torch.int32,
216
+ device=q.device,
217
+ )
218
+
219
+ if self.training:
220
+ assert seqlen_k == seqlen_q
221
+ is_causal = self.causal
222
+ dropout_p = self.dropout_p
223
+ else:
224
+ is_causal = seqlen_q == seqlen_k
225
+ dropout_p = 0
226
+
227
+ output = flash_attn_unpadded_func(
228
+ q,
229
+ k,
230
+ v,
231
+ cu_seqlens_q,
232
+ cu_seqlens_k,
233
+ seqlen_q,
234
+ seqlen_k,
235
+ dropout_p,
236
+ softmax_scale=self.softmax_scale,
237
+ causal=is_causal,
238
+ )
239
+ if batch_size > 1 and attention_mask is not None and seqlen_q == seqlen_k:
240
+ output = self.pad_input(output, indices_k, batch_size, seqlen_out)
241
+ else:
242
+ new_shape = (batch_size, output.shape[0] // batch_size) + output.shape[1:]
243
+ output = output.view(new_shape)
244
+ return output
245
+
246
+
247
+ class QWenAttention(nn.Module):
248
+ def __init__(self, config):
249
+ super().__init__()
250
+
251
+ self.register_buffer("masked_bias", torch.tensor(-1e4), persistent=False)
252
+ self.seq_length = config.seq_length
253
+
254
+ self.hidden_size = config.hidden_size
255
+ self.split_size = config.hidden_size
256
+ self.num_heads = config.num_attention_heads
257
+ self.head_dim = self.hidden_size // self.num_heads
258
+
259
+ self.use_flash_attn = config.use_flash_attn
260
+ self.scale_attn_weights = True
261
+
262
+ self.projection_size = config.kv_channels * config.num_attention_heads
263
+
264
+ assert self.projection_size % config.num_attention_heads == 0
265
+ self.hidden_size_per_attention_head = (
266
+ self.projection_size // config.num_attention_heads
267
+ )
268
+
269
+ self.c_attn = nn.Linear(config.hidden_size, 3 * self.projection_size)
270
+
271
+ self.c_proj = nn.Linear(
272
+ config.hidden_size, self.projection_size, bias=not config.no_bias
273
+ )
274
+
275
+ self.is_fp32 = not (config.bf16 or config.fp16)
276
+ if (
277
+ self.use_flash_attn
278
+ and flash_attn_unpadded_func is not None
279
+ and not self.is_fp32
280
+ ):
281
+ self.core_attention_flash = FlashSelfAttention(
282
+ causal=True, attention_dropout=config.attn_dropout_prob
283
+ )
284
+ self.bf16 = config.bf16
285
+
286
+ self.use_dynamic_ntk = config.use_dynamic_ntk
287
+ self.use_logn_attn = config.use_logn_attn
288
+
289
+ logn_list = [
290
+ math.log(i, self.seq_length) if i > self.seq_length else 1
291
+ for i in range(1, 32768)
292
+ ]
293
+ logn_tensor = torch.tensor(logn_list)[None, :, None, None]
294
+ self.register_buffer("logn_tensor", logn_tensor, persistent=False)
295
+
296
+ self.attn_dropout = nn.Dropout(config.attn_dropout_prob)
297
+ self.softmax_in_fp32 = config.softmax_in_fp32 if hasattr(config, 'softmax_in_fp32') else False
298
+ self.use_cache_quantization = config.use_cache_quantization if hasattr(config, 'use_cache_quantization') else False
299
+ self.use_cache_kernel = config.use_cache_kernel if hasattr(config,'use_cache_kernel') else False
300
+ cache_dtype = torch.float
301
+ if self.bf16:
302
+ cache_dtype=torch.bfloat16
303
+ elif config.fp16:
304
+ cache_dtype = torch.float16
305
+ self.cache_qmax = torch.tensor(torch.iinfo(torch.uint8).max, dtype=cache_dtype)
306
+ self.cache_qmin = torch.tensor(torch.iinfo(torch.uint8).min, dtype=cache_dtype)
307
+
308
+ if config.use_cache_quantization and config.use_cache_kernel:
309
+ # pre check if the support files existing
310
+ module_root = pathlib.Path(__file__).parent
311
+ src_files = ("cache_autogptq_cuda_256.cpp", "cache_autogptq_cuda_kernel_256.cu")
312
+ if any(not (module_root/src).is_file() for src in src_files):
313
+ warnings.warn("KV cache kernel source files (.cpp and .cu) not found.")
314
+ self.cache_kernels = None
315
+ else:
316
+ try:
317
+ from .cpp_kernels import cache_autogptq_cuda_256
318
+ self.cache_kernels = cache_autogptq_cuda_256
319
+ except ImportError:
320
+ warnings.warn("Failed to import KV cache kernels.")
321
+ self.cache_kernels = None
322
+
323
+ def _attn(self, query, key, value, causal_mask=None, attention_mask=None, head_mask=None):
324
+ device = query.device
325
+ if self.use_cache_quantization:
326
+ qk, qk_scale, qk_zero = key
327
+ if self.use_cache_kernel and self.cache_kernels is not None:
328
+ shape = query.shape[:-1] + (qk.shape[-2],)
329
+ attn_weights = torch.zeros(shape, dtype=torch.float16, device=device)
330
+ self.cache_kernels.vecquant8matmul_batched_faster_old(
331
+ query.contiguous() if query.dtype == torch.float16 else query.to(torch.float16).contiguous(),
332
+ qk.transpose(-1, -2).contiguous(),
333
+ attn_weights,
334
+ qk_scale.contiguous() if qk_scale.dtype == torch.float16 else qk_scale.to(torch.float16).contiguous(),
335
+ qk_zero.contiguous()if qk_zero.dtype == torch.float16 else qk_zero.to(torch.float16).contiguous())
336
+ # attn_weights = attn_weights.to(query.dtype).contiguous()
337
+ else:
338
+ key = dequantize_cache_torch(qk, qk_scale, qk_zero)
339
+ attn_weights = torch.matmul(query, key.transpose(-1, -2))
340
+ else:
341
+ attn_weights = torch.matmul(query, key.transpose(-1, -2))
342
+
343
+ if self.scale_attn_weights:
344
+ if self.use_cache_quantization:
345
+ size_temp = value[0].size(-1)
346
+ else:
347
+ size_temp = value.size(-1)
348
+ attn_weights = attn_weights / (size_temp ** 0.5)
349
+
350
+ mask_value = torch.finfo(attn_weights.dtype).min
351
+ if causal_mask is not None:
352
+ attn_weights = torch.where(
353
+ causal_mask, attn_weights.to(attn_weights.dtype), mask_value
354
+ )
355
+
356
+ if attention_mask is not None:
357
+ attn_weights = attn_weights + attention_mask
358
+
359
+ if self.softmax_in_fp32:
360
+ attn_weights = nn.functional.softmax(attn_weights.float(), dim=-1)
361
+ else:
362
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1)
363
+
364
+ attn_weights = attn_weights.type(query.dtype)
365
+ attn_weights = self.attn_dropout(attn_weights)
366
+
367
+ if head_mask is not None:
368
+ attn_weights = attn_weights * head_mask
369
+
370
+ if self.use_cache_quantization:
371
+ qv, qv_scale, qv_zero = value
372
+ if self.use_cache_kernel and self.cache_kernels is not None:
373
+ shape = attn_weights.shape[:-1] + (query.shape[-1],)
374
+ attn_output = torch.zeros(shape, dtype=torch.float16, device=device)
375
+ self.cache_kernels.vecquant8matmul_batched_column_compression_faster_old(
376
+ attn_weights.contiguous() if attn_weights.dtype == torch.float16 else attn_weights.to(torch.float16).contiguous(),
377
+ qv.contiguous(), # dtype: int32
378
+ attn_output,
379
+ qv_scale.contiguous() if qv_scale.dtype == torch.float16 else qv_scale.to(torch.float16).contiguous(),
380
+ qv_zero.contiguous() if qv_zero.dtype == torch.float16 else qv_zero.to(torch.float16).contiguous())
381
+ if attn_output.dtype != query.dtype:
382
+ attn_output = attn_output.to(query.dtype)
383
+ attn_weights = attn_weights.to(query.dtype)
384
+ else:
385
+ value = dequantize_cache_torch(qv, qv_scale, qv_zero)
386
+ attn_output = torch.matmul(attn_weights, value)
387
+ else:
388
+ attn_output = torch.matmul(attn_weights, value)
389
+
390
+ attn_output = attn_output.transpose(1, 2)
391
+
392
+ return attn_output, attn_weights
393
+
394
+ def _split_heads(self, tensor, num_heads, attn_head_size):
395
+ new_shape = tensor.size()[:-1] + (num_heads, attn_head_size)
396
+ tensor = tensor.view(new_shape)
397
+ return tensor
398
+
399
+ def _merge_heads(self, tensor, num_heads, attn_head_size):
400
+ tensor = tensor.contiguous()
401
+ new_shape = tensor.size()[:-2] + (num_heads * attn_head_size,)
402
+ return tensor.view(new_shape)
403
+
404
+ def forward(
405
+ self,
406
+ hidden_states: Optional[Tuple[torch.FloatTensor]],
407
+ rotary_pos_emb_list: Optional[List[List[torch.Tensor]]] = None,
408
+ layer_past: Optional[Tuple[torch.Tensor]] = None,
409
+ attention_mask: Optional[torch.FloatTensor] = None,
410
+ head_mask: Optional[torch.FloatTensor] = None,
411
+ encoder_hidden_states: Optional[torch.Tensor] = None,
412
+ encoder_attention_mask: Optional[torch.FloatTensor] = None,
413
+ output_attentions: Optional[bool] = False,
414
+ use_cache: Optional[bool] = False,
415
+ ):
416
+ mixed_x_layer = self.c_attn(hidden_states)
417
+
418
+ query, key, value = mixed_x_layer.split(self.split_size, dim=2)
419
+
420
+ query = self._split_heads(query, self.num_heads, self.head_dim)
421
+ key = self._split_heads(key, self.num_heads, self.head_dim)
422
+ value = self._split_heads(value, self.num_heads, self.head_dim)
423
+
424
+ if rotary_pos_emb_list is not None:
425
+ cur_len = query.shape[1]
426
+ if len(rotary_pos_emb_list) == 1:
427
+ rotary_pos_emb = rotary_pos_emb_list[0]
428
+ rotary_pos_emb = [i[:, -cur_len:, :, :] for i in rotary_pos_emb]
429
+ rotary_pos_emb = (rotary_pos_emb,) * 2
430
+ q_pos_emb, k_pos_emb = rotary_pos_emb
431
+ # Slice the pos emb for current inference
432
+ query = apply_rotary_pos_emb(query, q_pos_emb)
433
+ key = apply_rotary_pos_emb(key, k_pos_emb)
434
+ else:
435
+ query_list = []
436
+ key_list = []
437
+ for i, rotary_pos_emb in enumerate(rotary_pos_emb_list):
438
+ rotary_pos_emb = [i[:, -cur_len:, :, :] for i in rotary_pos_emb]
439
+ rotary_pos_emb = (rotary_pos_emb,) * 2
440
+ q_pos_emb, k_pos_emb = rotary_pos_emb
441
+ # Slice the pos emb for current inference
442
+ query_list += [apply_rotary_pos_emb(query[i:i+1, :, :], q_pos_emb)]
443
+ key_list += [apply_rotary_pos_emb(key[i:i+1, :, :], k_pos_emb)]
444
+ query = torch.cat(query_list, dim=0)
445
+ key = torch.cat(key_list, dim=0)
446
+
447
+ if self.use_cache_quantization:
448
+ key = quantize_cache_v(key.permute(0, 2, 1, 3),
449
+ bits=8,
450
+ qmin=self.cache_qmin,
451
+ qmax=self.cache_qmax)
452
+ value = quantize_cache_v(value.permute(0, 2, 1, 3),
453
+ bits=8,
454
+ qmin=self.cache_qmin,
455
+ qmax=self.cache_qmax)
456
+
457
+
458
+ if layer_past is not None:
459
+ past_key, past_value = layer_past[0], layer_past[1]
460
+ if self.use_cache_quantization:
461
+ # use_cache_quantization:
462
+ # present=((q_key,key_scale,key_zero_point),
463
+ # (q_value,value_scale,value_zero_point))
464
+ key = (torch.cat((past_key[0], key[0]), dim=2),
465
+ torch.cat((past_key[1], key[1]), dim=2),
466
+ torch.cat((past_key[2], key[2]), dim=2))
467
+ value = (torch.cat((past_value[0], value[0]), dim=2),
468
+ torch.cat((past_value[1], value[1]), dim=2),
469
+ torch.cat((past_value[2], value[2]), dim=2))
470
+ else:
471
+ # not use_cache_quantization:
472
+ # present=(key,value)
473
+ key = torch.cat((past_key, key), dim=1)
474
+ value = torch.cat((past_value, value), dim=1)
475
+
476
+ if use_cache:
477
+ present = (key, value)
478
+ else:
479
+ present = None
480
+
481
+ key_size = key[0].size(2) if self.use_cache_quantization else key.size(1)
482
+ if key_size > self.seq_length and self.use_logn_attn and not self.training:
483
+ if self.use_cache_quantization:
484
+ seq_start = key[0].size(2) - query.size(1)
485
+ seq_end = key[0].size(2)
486
+ else:
487
+ seq_start = key.size(1) - query.size(1)
488
+ seq_end = key.size(1)
489
+ logn_tensor = self.logn_tensor[:, seq_start:seq_end, :, :].type_as(query)
490
+ query = query * logn_tensor.expand_as(query)
491
+
492
+ if (
493
+ self.use_flash_attn
494
+ and flash_attn_unpadded_func is not None
495
+ and not self.is_fp32
496
+ and query.is_cuda
497
+ ):
498
+ q, k, v = query, key, value
499
+ attn_output = self.core_attention_flash(q, k, v, attention_mask=attention_mask)
500
+ else:
501
+ key_size = key[0].size(2) if self.use_cache_quantization else key.size(1)
502
+ if query.size(1) == key_size:
503
+ causal_mask = torch.tril(
504
+ torch.ones((key_size, key_size), dtype=torch.bool, device=query.device)
505
+ ).view(1, 1, key_size, key_size)
506
+ else:
507
+ causal_mask = None
508
+ query = query.permute(0, 2, 1, 3)
509
+ if not self.use_cache_quantization:
510
+ key = key.permute(0, 2, 1, 3)
511
+ value = value.permute(0, 2, 1, 3)
512
+ if (
513
+ causal_mask is None
514
+ and self.use_flash_attn
515
+ and flash_attn_unpadded_func is not None
516
+ and not self.is_fp32
517
+ and not query.is_cuda
518
+ ):
519
+ raise Exception(_ERROR_INPUT_CPU_QUERY_WITH_FLASH_ATTN_ACTIVATED)
520
+
521
+ if not self.use_cache_quantization and SUPPORT_TORCH2:
522
+ if attention_mask is not None:
523
+ attention_mask = attention_mask.expand(
524
+ -1, -1, causal_mask.size(2), -1
525
+ )
526
+ if causal_mask is not None:
527
+ attention_mask.masked_fill(~causal_mask, torch.finfo(query.dtype).min)
528
+ else:
529
+ attention_mask = causal_mask
530
+ attn_output = F.scaled_dot_product_attention(
531
+ query, key, value, attn_mask=attention_mask
532
+ ).transpose(1, 2)
533
+ attn_weight = None
534
+ else:
535
+ attn_output, attn_weight = self._attn(
536
+ query, key, value, causal_mask, attention_mask, head_mask
537
+ )
538
+ context_layer = self._merge_heads(
539
+ attn_output, self.num_heads, self.head_dim
540
+ )
541
+
542
+ attn_output = self.c_proj(context_layer)
543
+
544
+ outputs = (attn_output, present)
545
+ if output_attentions:
546
+ if (
547
+ self.use_flash_attn
548
+ and flash_attn_unpadded_func is not None
549
+ and not self.is_fp32
550
+ ):
551
+ raise ValueError("Cannot output attentions while using flash-attn")
552
+ elif not self.use_cache_quantization and SUPPORT_TORCH2:
553
+ raise ValueError("Cannot output attentions while using scaled_dot_product_attention")
554
+ else:
555
+ outputs += (attn_weight,)
556
+
557
+ return outputs
558
+
559
+
560
+ class QWenMLP(nn.Module):
561
+ def __init__(self, config):
562
+ super().__init__()
563
+ self.w1 = nn.Linear(
564
+ config.hidden_size, config.intermediate_size // 2, bias=not config.no_bias
565
+ )
566
+ self.w2 = nn.Linear(
567
+ config.hidden_size, config.intermediate_size // 2, bias=not config.no_bias
568
+ )
569
+ ff_dim_in = config.intermediate_size // 2
570
+ self.c_proj = nn.Linear(ff_dim_in, config.hidden_size, bias=not config.no_bias)
571
+
572
+ def forward(self, hidden_states):
573
+ a1 = self.w1(hidden_states)
574
+ a2 = self.w2(hidden_states)
575
+ intermediate_parallel = a1 * F.silu(a2)
576
+ output = self.c_proj(intermediate_parallel)
577
+ return output
578
+
579
+
580
+ class QWenBlock(nn.Module):
581
+ def __init__(self, config):
582
+ super().__init__()
583
+ hidden_size = config.hidden_size
584
+ self.bf16 = config.bf16
585
+
586
+ self.ln_1 = RMSNorm(
587
+ hidden_size,
588
+ eps=config.layer_norm_epsilon,
589
+ )
590
+ self.attn = QWenAttention(config)
591
+ self.ln_2 = RMSNorm(
592
+ hidden_size,
593
+ eps=config.layer_norm_epsilon,
594
+ )
595
+
596
+ self.mlp = QWenMLP(config)
597
+
598
+ def forward(
599
+ self,
600
+ hidden_states: Optional[Tuple[torch.FloatTensor]],
601
+ rotary_pos_emb_list: Optional[List[List[torch.Tensor]]] = None,
602
+ layer_past: Optional[Tuple[torch.Tensor]] = None,
603
+ attention_mask: Optional[torch.FloatTensor] = None,
604
+ head_mask: Optional[torch.FloatTensor] = None,
605
+ encoder_hidden_states: Optional[torch.Tensor] = None,
606
+ encoder_attention_mask: Optional[torch.FloatTensor] = None,
607
+ use_cache: Optional[bool] = False,
608
+ output_attentions: Optional[bool] = False,
609
+ ):
610
+ layernorm_output = self.ln_1(hidden_states)
611
+
612
+ attn_outputs = self.attn(
613
+ layernorm_output,
614
+ rotary_pos_emb_list,
615
+ layer_past=layer_past,
616
+ attention_mask=attention_mask,
617
+ head_mask=head_mask,
618
+ use_cache=use_cache,
619
+ output_attentions=output_attentions,
620
+ )
621
+ attn_output = attn_outputs[0]
622
+
623
+ outputs = attn_outputs[1:]
624
+
625
+ residual = hidden_states
626
+ layernorm_input = attn_output + residual
627
+
628
+ layernorm_output = self.ln_2(layernorm_input)
629
+
630
+ residual = layernorm_input
631
+ mlp_output = self.mlp(layernorm_output)
632
+ hidden_states = residual + mlp_output
633
+
634
+ if use_cache:
635
+ outputs = (hidden_states,) + outputs
636
+ else:
637
+ outputs = (hidden_states,) + outputs[1:]
638
+
639
+ return outputs
640
+
641
+
642
+ class QWenPreTrainedModel(PreTrainedModel):
643
+ config_class = QWenConfig
644
+ base_model_prefix = "transformer"
645
+ is_parallelizable = False
646
+ supports_gradient_checkpointing = True
647
+ _no_split_modules = ["QWenBlock"]
648
+ _skip_keys_device_placement = "past_key_values"
649
+
650
+ def __init__(self, *inputs, **kwargs):
651
+ super().__init__(*inputs, **kwargs)
652
+
653
+ def _init_weights(self, module):
654
+ """Initialize the weights."""
655
+ if isinstance(module, nn.Linear):
656
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
657
+ if module.bias is not None:
658
+ module.bias.data.zero_()
659
+ elif isinstance(module, nn.Embedding):
660
+ module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
661
+ if module.padding_idx is not None:
662
+ module.weight.data[module.padding_idx].zero_()
663
+ elif isinstance(module, RMSNorm):
664
+ module.weight.data.fill_(1.0)
665
+
666
+ for name, p in module.named_parameters():
667
+ if name == "c_proj.weight":
668
+ p.data.normal_(
669
+ mean=0.0,
670
+ std=(
671
+ self.config.initializer_range
672
+ / math.sqrt(2 * self.config.num_hidden_layers)
673
+ ),
674
+ )
675
+ def _set_gradient_checkpointing(self, enable: bool = False, gradient_checkpointing_func: Callable = None):
676
+ is_gradient_checkpointing_set = False
677
+
678
+ if isinstance(self, QWenModel):
679
+ self.gradient_checkpointing = enable
680
+ self._gradient_checkpointing_func = gradient_checkpointing_func
681
+ is_gradient_checkpointing_set = True
682
+
683
+ for module in self.modules():
684
+ if isinstance(module, QWenModel):
685
+ module.gradient_checkpointing = enable
686
+ module._gradient_checkpointing_func = gradient_checkpointing_func
687
+ is_gradient_checkpointing_set = True
688
+
689
+ if not is_gradient_checkpointing_set:
690
+ raise ValueError(f"{self.__class__.__name__} is not compatible with gradient checkpointing. Make sure all the architecture support it by setting a boolean attribute 'gradient_checkpointing' to modules of the model that uses checkpointing.")
691
+
692
+
693
+
694
+ class QWenModel(QWenPreTrainedModel):
695
+ _keys_to_ignore_on_load_missing = ["attn.masked_bias"]
696
+
697
+ def __init__(self, config):
698
+ super().__init__(config)
699
+ self.vocab_size = config.vocab_size
700
+ self.num_hidden_layers = config.num_hidden_layers
701
+ self.embed_dim = config.hidden_size
702
+ self.use_cache_quantization = self.config.use_cache_quantization if hasattr(self.config, 'use_cache_quantization') else False
703
+
704
+ self.gradient_checkpointing = False
705
+ self.use_dynamic_ntk = config.use_dynamic_ntk
706
+ self.seq_length = config.seq_length
707
+
708
+ self.wte = nn.Embedding(self.vocab_size, self.embed_dim)
709
+
710
+ self.drop = nn.Dropout(config.emb_dropout_prob)
711
+
712
+ if config.rotary_pct == 1.0:
713
+ self.rotary_ndims = None
714
+ else:
715
+ assert config.rotary_pct < 1
716
+ self.rotary_ndims = int(
717
+ config.kv_channels * config.rotary_pct
718
+ )
719
+ dim = (
720
+ self.rotary_ndims
721
+ if self.rotary_ndims is not None
722
+ else config.kv_channels
723
+ )
724
+ self.rotary_emb = RotaryEmbedding(dim, base=config.rotary_emb_base)
725
+
726
+ self.use_flash_attn = config.use_flash_attn
727
+ self.is_fp32 = not (config.bf16 or config.fp16)
728
+
729
+ self.h = nn.ModuleList(
730
+ [
731
+ QWenBlock(
732
+ config
733
+ )
734
+ for i in range(config.num_hidden_layers)
735
+ ]
736
+ )
737
+ self.ln_f = RMSNorm(
738
+ self.embed_dim,
739
+ eps=config.layer_norm_epsilon,
740
+ )
741
+
742
+ self.post_init()
743
+
744
+ def get_input_embeddings(self):
745
+ return self.wte
746
+
747
+ def set_input_embeddings(self, new_embeddings):
748
+ self.wte = new_embeddings
749
+
750
+ def get_ntk_alpha(self, true_seq_len):
751
+ context_value = math.log(true_seq_len / self.seq_length, 2) + 1
752
+ ntk_alpha = 2 ** math.ceil(context_value) - 1
753
+ ntk_alpha = max(ntk_alpha, 1)
754
+ return ntk_alpha
755
+
756
+ def forward(
757
+ self,
758
+ input_ids: Optional[torch.LongTensor] = None,
759
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
760
+ attention_mask: Optional[torch.FloatTensor] = None,
761
+ token_type_ids: Optional[torch.LongTensor] = None,
762
+ position_ids: Optional[torch.LongTensor] = None,
763
+ head_mask: Optional[torch.FloatTensor] = None,
764
+ inputs_embeds: Optional[torch.FloatTensor] = None,
765
+ encoder_hidden_states: Optional[torch.Tensor] = None,
766
+ encoder_attention_mask: Optional[torch.FloatTensor] = None,
767
+ use_cache: Optional[bool] = None,
768
+ output_attentions: Optional[bool] = None,
769
+ output_hidden_states: Optional[bool] = None,
770
+ return_dict: Optional[bool] = None,
771
+ ):
772
+ output_attentions = (
773
+ output_attentions
774
+ if output_attentions is not None
775
+ else self.config.output_attentions
776
+ )
777
+ output_hidden_states = (
778
+ output_hidden_states
779
+ if output_hidden_states is not None
780
+ else self.config.output_hidden_states
781
+ )
782
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
783
+ return_dict = (
784
+ return_dict if return_dict is not None else self.config.use_return_dict
785
+ )
786
+
787
+ if input_ids is not None and inputs_embeds is not None:
788
+ raise ValueError(
789
+ "You cannot specify both input_ids and inputs_embeds at the same time"
790
+ )
791
+ elif input_ids is not None:
792
+ input_shape = input_ids.size()
793
+ input_ids = input_ids.view(-1, input_shape[-1])
794
+ batch_size = input_ids.shape[0]
795
+ elif inputs_embeds is not None:
796
+ input_shape = inputs_embeds.size()[:-1]
797
+ batch_size = inputs_embeds.shape[0]
798
+ else:
799
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
800
+
801
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
802
+
803
+ if token_type_ids is not None:
804
+ token_type_ids = token_type_ids.view(-1, input_shape[-1])
805
+ if position_ids is not None:
806
+ position_ids = position_ids.view(-1, input_shape[-1])
807
+
808
+ if past_key_values is None:
809
+ past_length = 0
810
+ past_key_values = tuple([None] * len(self.h))
811
+ else:
812
+ if self.use_cache_quantization:
813
+ past_length = past_key_values[0][0][0].size(2)
814
+ else:
815
+ past_length = past_key_values[0][0].size(-2)
816
+ if position_ids is None:
817
+ position_ids = torch.arange(
818
+ past_length,
819
+ input_shape[-1] + past_length,
820
+ dtype=torch.long,
821
+ device=device,
822
+ )
823
+ position_ids = position_ids.unsqueeze(0).view(-1, input_shape[-1])
824
+
825
+ if attention_mask is not None:
826
+ if batch_size <= 0:
827
+ raise ValueError("batch_size has to be defined and > 0")
828
+ attention_mask = attention_mask.view(batch_size, -1)
829
+ attention_mask = attention_mask[:, None, None, :]
830
+ attention_mask = attention_mask.to(dtype=self.dtype)
831
+ attention_mask = (1.0 - attention_mask) * torch.finfo(self.dtype).min
832
+
833
+ encoder_attention_mask = None
834
+ head_mask = self.get_head_mask(head_mask, self.config.num_hidden_layers)
835
+
836
+ if inputs_embeds is None:
837
+ inputs_embeds = self.wte(input_ids)
838
+ hidden_states = inputs_embeds
839
+
840
+ kv_seq_len = hidden_states.size()[1]
841
+ if past_key_values[0] is not None:
842
+ # past key values[0][0] shape: bs * seq_len * head_num * dim
843
+ if self.use_cache_quantization:
844
+ kv_seq_len += past_key_values[0][0][0].shape[2]
845
+ else:
846
+ kv_seq_len += past_key_values[0][0].shape[1]
847
+
848
+ if self.training or not self.use_dynamic_ntk:
849
+ ntk_alpha_list = [1.0]
850
+ elif kv_seq_len != hidden_states.size()[1]:
851
+ ntk_alpha_list = self.rotary_emb._ntk_alpha_cached_list
852
+ else:
853
+ ntk_alpha_list = []
854
+ if attention_mask is not None and kv_seq_len > self.seq_length:
855
+ true_seq_lens = attention_mask.squeeze(1).squeeze(1).eq(0).sum(dim=-1, dtype=torch.int32)
856
+ for i in range(hidden_states.size()[0]):
857
+ true_seq_len = true_seq_lens[i].item()
858
+ ntk_alpha = self.get_ntk_alpha(true_seq_len)
859
+ ntk_alpha_list.append(ntk_alpha)
860
+ else:
861
+ ntk_alpha = self.get_ntk_alpha(kv_seq_len)
862
+ ntk_alpha_list.append(ntk_alpha)
863
+ self.rotary_emb._ntk_alpha_cached_list = ntk_alpha_list
864
+ rotary_pos_emb_list = [
865
+ self.rotary_emb(kv_seq_len, ntk_alpha=ntk_alpha) for ntk_alpha in ntk_alpha_list
866
+ ]
867
+
868
+ hidden_states = self.drop(hidden_states)
869
+ output_shape = input_shape + (hidden_states.size(-1),)
870
+
871
+ if self.gradient_checkpointing and self.training:
872
+ if use_cache:
873
+ logger.warning_once(
874
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
875
+ )
876
+ use_cache = False
877
+
878
+ presents = () if use_cache else None
879
+ all_self_attentions = () if output_attentions else None
880
+ all_hidden_states = () if output_hidden_states else None
881
+ for i, (block, layer_past) in enumerate(zip(self.h, past_key_values)):
882
+
883
+ if output_hidden_states:
884
+ all_hidden_states = all_hidden_states + (hidden_states,)
885
+
886
+ if self.gradient_checkpointing and self.training:
887
+
888
+ def create_custom_forward(module):
889
+ def custom_forward(*inputs):
890
+ # None for past_key_value
891
+ return module(*inputs, use_cache, output_attentions)
892
+
893
+ return custom_forward
894
+
895
+ outputs = torch.utils.checkpoint.checkpoint(
896
+ create_custom_forward(block),
897
+ hidden_states,
898
+ rotary_pos_emb_list,
899
+ None,
900
+ attention_mask,
901
+ head_mask[i],
902
+ encoder_hidden_states,
903
+ encoder_attention_mask,
904
+ )
905
+ else:
906
+ outputs = block(
907
+ hidden_states,
908
+ layer_past=layer_past,
909
+ rotary_pos_emb_list=rotary_pos_emb_list,
910
+ attention_mask=attention_mask,
911
+ head_mask=head_mask[i],
912
+ encoder_hidden_states=encoder_hidden_states,
913
+ encoder_attention_mask=encoder_attention_mask,
914
+ use_cache=use_cache,
915
+ output_attentions=output_attentions,
916
+ )
917
+
918
+ hidden_states = outputs[0]
919
+ if use_cache is True:
920
+ presents = presents + (outputs[1],)
921
+
922
+ if output_attentions:
923
+ all_self_attentions = all_self_attentions + (outputs[2 if use_cache else 1],)
924
+
925
+ hidden_states = self.ln_f(hidden_states)
926
+ hidden_states = hidden_states.view(output_shape)
927
+ # Add last hidden state
928
+ if output_hidden_states:
929
+ all_hidden_states = all_hidden_states + (hidden_states,)
930
+
931
+ if not return_dict:
932
+ return tuple(
933
+ v for v in [hidden_states, presents, all_hidden_states] if v is not None
934
+ )
935
+
936
+ return BaseModelOutputWithPast(
937
+ last_hidden_state=hidden_states,
938
+ past_key_values=presents,
939
+ hidden_states=all_hidden_states,
940
+ attentions=all_self_attentions,
941
+ )
942
+
943
+
944
+ class QWenLMHeadModel(QWenPreTrainedModel):
945
+ _keys_to_ignore_on_load_missing = [r"h\.\d+\.attn\.rotary_emb\.inv_freq"]
946
+ _keys_to_ignore_on_load_unexpected = [r"h\.\d+\.attn\.masked_bias"]
947
+
948
+ def __init__(self, config):
949
+ super().__init__(config)
950
+ assert (
951
+ config.bf16 + config.fp16 + config.fp32 <= 1
952
+ ), "Only one of \"bf16\", \"fp16\", \"fp32\" can be true"
953
+
954
+ autoset_precision = config.bf16 + config.fp16 + config.fp32 == 0
955
+
956
+ if autoset_precision:
957
+ if SUPPORT_BF16:
958
+ logger.warn(
959
+ "The model is automatically converting to bf16 for faster inference. "
960
+ "If you want to disable the automatic precision, please manually add bf16/fp16/fp32=True to \"AutoModelForCausalLM.from_pretrained\"."
961
+ )
962
+ config.bf16 = True
963
+ elif SUPPORT_FP16:
964
+ logger.warn(
965
+ "The model is automatically converting to fp16 for faster inference. "
966
+ "If you want to disable the automatic precision, please manually add bf16/fp16/fp32=True to \"AutoModelForCausalLM.from_pretrained\"."
967
+ )
968
+ config.fp16 = True
969
+ else:
970
+ config.fp32 = True
971
+
972
+ if config.bf16 and SUPPORT_CUDA and not SUPPORT_BF16:
973
+ logger.warn("Your device does NOT seem to support bf16, you can switch to fp16 or fp32 by by passing fp16/fp32=True in \"AutoModelForCausalLM.from_pretrained\".")
974
+ if config.fp16 and SUPPORT_CUDA and not SUPPORT_FP16:
975
+ logger.warn("Your device does NOT support faster inference with fp16, please switch to fp32 which is likely to be faster")
976
+ if config.fp32:
977
+ if SUPPORT_BF16:
978
+ logger.warn("Your device support faster inference by passing bf16=True in \"AutoModelForCausalLM.from_pretrained\".")
979
+ elif SUPPORT_FP16:
980
+ logger.warn("Your device support faster inference by passing fp16=True in \"AutoModelForCausalLM.from_pretrained\".")
981
+
982
+ if config.use_flash_attn == "auto":
983
+ if config.bf16 or config.fp16:
984
+ logger.warn("Try importing flash-attention for faster inference...")
985
+ config.use_flash_attn = True
986
+ else:
987
+ config.use_flash_attn = False
988
+ if config.use_flash_attn and config.fp32:
989
+ logger.warn("Flash attention will be disabled because it does NOT support fp32.")
990
+
991
+ if config.use_flash_attn:
992
+ _import_flash_attn()
993
+
994
+ self.transformer = QWenModel(config)
995
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
996
+
997
+ if config.bf16:
998
+ self.transformer.bfloat16()
999
+ self.lm_head.bfloat16()
1000
+ if config.fp16:
1001
+ self.transformer.half()
1002
+ self.lm_head.half()
1003
+ self.post_init()
1004
+
1005
+ def get_output_embeddings(self):
1006
+ return self.lm_head
1007
+
1008
+ def set_output_embeddings(self, new_embeddings):
1009
+ self.lm_head = new_embeddings
1010
+
1011
+ def prepare_inputs_for_generation(
1012
+ self, input_ids, past_key_values=None, inputs_embeds=None, **kwargs
1013
+ ):
1014
+ if past_key_values:
1015
+ input_ids = input_ids[:, -1].unsqueeze(-1)
1016
+
1017
+ if input_ids.size(0) == 1:
1018
+ attention_mask = None
1019
+ else:
1020
+ attention_mask = kwargs.get("attention_mask", None)
1021
+
1022
+ if inputs_embeds is not None and past_key_values is None:
1023
+ model_inputs = {"inputs_embeds": inputs_embeds}
1024
+ else:
1025
+ model_inputs = {"input_ids": input_ids}
1026
+
1027
+ model_inputs.update(
1028
+ {
1029
+ "past_key_values": past_key_values,
1030
+ "use_cache": kwargs.get("use_cache"),
1031
+ "attention_mask": attention_mask,
1032
+ }
1033
+ )
1034
+ return model_inputs
1035
+
1036
+ def forward(
1037
+ self,
1038
+ input_ids: Optional[torch.LongTensor] = None,
1039
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
1040
+ attention_mask: Optional[torch.FloatTensor] = None,
1041
+ token_type_ids: Optional[torch.LongTensor] = None,
1042
+ position_ids: Optional[torch.LongTensor] = None,
1043
+ head_mask: Optional[torch.FloatTensor] = None,
1044
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1045
+ encoder_hidden_states: Optional[torch.Tensor] = None,
1046
+ encoder_attention_mask: Optional[torch.FloatTensor] = None,
1047
+ labels: Optional[torch.LongTensor] = None,
1048
+ use_cache: Optional[bool] = None,
1049
+ output_attentions: Optional[bool] = None,
1050
+ output_hidden_states: Optional[bool] = None,
1051
+ return_dict: Optional[bool] = None,
1052
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1053
+
1054
+ return_dict = (
1055
+ return_dict if return_dict is not None else self.config.use_return_dict
1056
+ )
1057
+
1058
+ transformer_outputs = self.transformer(
1059
+ input_ids,
1060
+ past_key_values=past_key_values,
1061
+ attention_mask=attention_mask,
1062
+ token_type_ids=token_type_ids,
1063
+ position_ids=position_ids,
1064
+ head_mask=head_mask,
1065
+ inputs_embeds=inputs_embeds,
1066
+ encoder_hidden_states=encoder_hidden_states,
1067
+ encoder_attention_mask=encoder_attention_mask,
1068
+ use_cache=use_cache,
1069
+ output_attentions=output_attentions,
1070
+ output_hidden_states=output_hidden_states,
1071
+ return_dict=return_dict,
1072
+ )
1073
+ hidden_states = transformer_outputs[0]
1074
+
1075
+ lm_logits = self.lm_head(hidden_states)
1076
+
1077
+ loss = None
1078
+ if labels is not None:
1079
+ labels = labels.to(lm_logits.device)
1080
+ shift_logits = lm_logits[..., :-1, :].contiguous()
1081
+ shift_labels = labels[..., 1:].contiguous()
1082
+ loss_fct = CrossEntropyLoss()
1083
+ loss = loss_fct(
1084
+ shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1)
1085
+ )
1086
+
1087
+ if not return_dict:
1088
+ output = (lm_logits,) + transformer_outputs[1:]
1089
+ return ((loss,) + output) if loss is not None else output
1090
+
1091
+ return CausalLMOutputWithPast(
1092
+ loss=loss,
1093
+ logits=lm_logits,
1094
+ past_key_values=transformer_outputs.past_key_values,
1095
+ hidden_states=transformer_outputs.hidden_states,
1096
+ attentions=transformer_outputs.attentions,
1097
+ )
1098
+
1099
+ @staticmethod
1100
+ def _reorder_cache(
1101
+ past_key_values: Tuple[Tuple[torch.Tensor]], beam_idx: torch.Tensor
1102
+ ) -> Tuple[Tuple[torch.Tensor]]:
1103
+
1104
+ return tuple(
1105
+ tuple(
1106
+ past_state.index_select(0, beam_idx.to(past_state.device))
1107
+ for past_state in layer_past
1108
+ )
1109
+ for layer_past in past_key_values
1110
+ )
1111
+
1112
+ def chat(
1113
+ self,
1114
+ tokenizer: PreTrainedTokenizer,
1115
+ query: str,
1116
+ history: Optional[HistoryType],
1117
+ system: str = "You are a helpful assistant.",
1118
+ stream: Optional[bool] = _SENTINEL,
1119
+ stop_words_ids: Optional[List[List[int]]] = None,
1120
+ generation_config: Optional[GenerationConfig] = None,
1121
+ **kwargs,
1122
+ ) -> Tuple[str, HistoryType]:
1123
+ generation_config = generation_config if generation_config is not None else self.generation_config
1124
+
1125
+ assert stream is _SENTINEL, _ERROR_STREAM_IN_CHAT
1126
+ assert generation_config.chat_format == 'chatml', _ERROR_BAD_CHAT_FORMAT
1127
+ if history is None:
1128
+ history = []
1129
+ else:
1130
+ # make a copy of the user's input such that is is left untouched
1131
+ history = copy.deepcopy(history)
1132
+
1133
+ if stop_words_ids is None:
1134
+ stop_words_ids = []
1135
+
1136
+ max_window_size = kwargs.get('max_window_size', None)
1137
+ if max_window_size is None:
1138
+ max_window_size = generation_config.max_window_size
1139
+ raw_text, context_tokens = make_context(
1140
+ tokenizer,
1141
+ query,
1142
+ history=history,
1143
+ system=system,
1144
+ max_window_size=max_window_size,
1145
+ chat_format=generation_config.chat_format,
1146
+ )
1147
+
1148
+ stop_words_ids.extend(get_stop_words_ids(
1149
+ generation_config.chat_format, tokenizer
1150
+ ))
1151
+ input_ids = torch.tensor([context_tokens]).to(self.device)
1152
+ outputs = self.generate(
1153
+ input_ids,
1154
+ stop_words_ids=stop_words_ids,
1155
+ return_dict_in_generate=False,
1156
+ generation_config=generation_config,
1157
+ **kwargs,
1158
+ )
1159
+
1160
+ response = decode_tokens(
1161
+ outputs[0],
1162
+ tokenizer,
1163
+ raw_text_len=len(raw_text),
1164
+ context_length=len(context_tokens),
1165
+ chat_format=generation_config.chat_format,
1166
+ verbose=False,
1167
+ errors='replace'
1168
+ )
1169
+
1170
+ # as history is a copy of the user inputs,
1171
+ # we can always return the new turn to the user.
1172
+ # separating input history and output history also enables the user
1173
+ # to implement more complex history management
1174
+ history.append((query, response))
1175
+
1176
+ return response, history
1177
+
1178
+ def chat_stream(
1179
+ self,
1180
+ tokenizer: PreTrainedTokenizer,
1181
+ query: str,
1182
+ history: Optional[HistoryType],
1183
+ system: str = "You are a helpful assistant.",
1184
+ stop_words_ids: Optional[List[List[int]]] = None,
1185
+ logits_processor: Optional[LogitsProcessorList] = None,
1186
+ generation_config: Optional[GenerationConfig] = None,
1187
+ **kwargs,
1188
+ ) -> Generator[str, Any, None]:
1189
+ generation_config = generation_config if generation_config is not None else self.generation_config
1190
+ assert generation_config.chat_format == 'chatml', _ERROR_BAD_CHAT_FORMAT
1191
+ if history is None:
1192
+ history = []
1193
+ if stop_words_ids is None:
1194
+ stop_words_ids = []
1195
+
1196
+ max_window_size = kwargs.get('max_window_size', None)
1197
+ if max_window_size is None:
1198
+ max_window_size = generation_config.max_window_size
1199
+ raw_text, context_tokens = make_context(
1200
+ tokenizer,
1201
+ query,
1202
+ history=history,
1203
+ system=system,
1204
+ max_window_size=max_window_size,
1205
+ chat_format=generation_config.chat_format,
1206
+ )
1207
+
1208
+ stop_words_ids.extend(get_stop_words_ids(
1209
+ generation_config.chat_format, tokenizer
1210
+ ))
1211
+ if stop_words_ids is not None:
1212
+ stop_words_logits_processor = StopWordsLogitsProcessor(
1213
+ stop_words_ids=stop_words_ids,
1214
+ eos_token_id=generation_config.eos_token_id,
1215
+ )
1216
+ if logits_processor is None:
1217
+ logits_processor = LogitsProcessorList([stop_words_logits_processor])
1218
+ else:
1219
+ logits_processor.append(stop_words_logits_processor)
1220
+ input_ids = torch.tensor([context_tokens]).to(self.device)
1221
+
1222
+ from transformers_stream_generator.main import NewGenerationMixin, StreamGenerationConfig
1223
+ self.__class__.generate_stream = NewGenerationMixin.generate
1224
+ self.__class__.sample_stream = NewGenerationMixin.sample_stream
1225
+ stream_config = StreamGenerationConfig(**generation_config.to_dict(), do_stream=True)
1226
+
1227
+ def stream_generator():
1228
+ outputs = []
1229
+ for token in self.generate_stream(
1230
+ input_ids,
1231
+ return_dict_in_generate=False,
1232
+ generation_config=stream_config,
1233
+ logits_processor=logits_processor,
1234
+ seed=-1,
1235
+ **kwargs):
1236
+ outputs.append(token.item())
1237
+ yield tokenizer.decode(outputs, skip_special_tokens=True, errors='ignore')
1238
+
1239
+ return stream_generator()
1240
+
1241
+ def generate(
1242
+ self,
1243
+ inputs: Optional[torch.Tensor] = None,
1244
+ generation_config: Optional[GenerationConfig] = None,
1245
+ logits_processor: Optional[LogitsProcessorList] = None,
1246
+ stopping_criteria: Optional[StoppingCriteriaList] = None,
1247
+ prefix_allowed_tokens_fn: Optional[
1248
+ Callable[[int, torch.Tensor], List[int]]
1249
+ ] = None,
1250
+ synced_gpus: Optional[bool] = None,
1251
+ assistant_model: Optional["PreTrainedModel"] = None,
1252
+ streamer: Optional["BaseStreamer"] = None,
1253
+ **kwargs,
1254
+ ) -> Union[GenerateOutput, torch.LongTensor]:
1255
+ generation_config = generation_config if generation_config is not None else self.generation_config
1256
+
1257
+ # Process stop_words_ids.
1258
+ stop_words_ids = kwargs.pop("stop_words_ids", None)
1259
+ if stop_words_ids is None and generation_config is not None:
1260
+ stop_words_ids = getattr(generation_config, "stop_words_ids", None)
1261
+ if stop_words_ids is None:
1262
+ stop_words_ids = getattr(generation_config, "stop_words_ids", None)
1263
+
1264
+ if stop_words_ids is not None:
1265
+ stop_words_logits_processor = StopWordsLogitsProcessor(
1266
+ stop_words_ids=stop_words_ids,
1267
+ eos_token_id=generation_config.eos_token_id,
1268
+ )
1269
+ if logits_processor is None:
1270
+ logits_processor = LogitsProcessorList([stop_words_logits_processor])
1271
+ else:
1272
+ logits_processor.append(stop_words_logits_processor)
1273
+
1274
+ return super().generate(
1275
+ inputs,
1276
+ generation_config=generation_config,
1277
+ logits_processor=logits_processor,
1278
+ stopping_criteria=stopping_criteria,
1279
+ prefix_allowed_tokens_fn=prefix_allowed_tokens_fn,
1280
+ synced_gpus=synced_gpus,
1281
+ assistant_model=assistant_model,
1282
+ streamer=streamer,
1283
+ **kwargs,
1284
+ )
1285
+
1286
+
1287
+ class RotaryEmbedding(torch.nn.Module):
1288
+ def __init__(self, dim, base=10000):
1289
+ super().__init__()
1290
+ self.dim = dim
1291
+ self.base = base
1292
+ inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2).float() / dim))
1293
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
1294
+ if importlib.util.find_spec("einops") is None:
1295
+ raise RuntimeError("einops is required for Rotary Embedding")
1296
+
1297
+ self._rotary_pos_emb_cache = None
1298
+ self._seq_len_cached = 0
1299
+ self._ntk_alpha_cached = 1.0
1300
+ self._ntk_alpha_cached_list = [1.0]
1301
+
1302
+ def update_rotary_pos_emb_cache(self, seqlen, ntk_alpha=1.0):
1303
+ if seqlen > self._seq_len_cached or ntk_alpha != self._ntk_alpha_cached:
1304
+ base = self.base * ntk_alpha ** (self.dim / (self.dim - 2))
1305
+ self.inv_freq = 1.0 / (
1306
+ base
1307
+ ** (
1308
+ torch.arange(0, self.dim, 2, device=self.inv_freq.device).float()
1309
+ / self.dim
1310
+ )
1311
+ )
1312
+ self._seq_len_cached = max(2 * seqlen, 16)
1313
+ self._ntk_alpha_cached = ntk_alpha
1314
+ seq = torch.arange(self._seq_len_cached, device=self.inv_freq.device)
1315
+ freqs = torch.outer(seq.type_as(self.inv_freq), self.inv_freq)
1316
+
1317
+ emb = torch.cat((freqs, freqs), dim=-1)
1318
+ from einops import rearrange
1319
+
1320
+ emb = rearrange(emb, "n d -> 1 n 1 d")
1321
+
1322
+ cos, sin = emb.cos(), emb.sin()
1323
+ self._rotary_pos_emb_cache = [cos, sin]
1324
+
1325
+ def forward(self, max_seq_len, ntk_alpha=1.0):
1326
+ self.update_rotary_pos_emb_cache(max_seq_len, ntk_alpha)
1327
+ cos, sin = self._rotary_pos_emb_cache
1328
+ return [cos[:, :max_seq_len], sin[:, :max_seq_len]]
1329
+
1330
+
1331
+ def _rotate_half(x):
1332
+ from einops import rearrange
1333
+
1334
+ x = rearrange(x, "... (j d) -> ... j d", j=2)
1335
+ x1, x2 = x.unbind(dim=-2)
1336
+ return torch.cat((-x2, x1), dim=-1)
1337
+
1338
+
1339
+ def apply_rotary_pos_emb(t, freqs):
1340
+ """ Apply rotary embedding to the first rotary_dim of the iput
1341
+
1342
+ Arguments:
1343
+ t (tensor(batch_size, seq_len, n_head, head_dim)):
1344
+ the input embedding/hidden states
1345
+ freqs (list[tensor(1, seq_len, 1, rotary_dim), tensor(1, seq_len, 1, rotary_dim)]):
1346
+ the cached cos/sin position embeddings
1347
+ """
1348
+ rot_dim = freqs[0].shape[-1]
1349
+ cos, sin = freqs
1350
+ t_float = t.float()
1351
+ if apply_rotary_emb_func is not None and t.is_cuda:
1352
+ # apply_rotary_emb in flash_attn requires cos/sin to be of
1353
+ # shape (seqlen, rotary_dim / 2) and apply rotary embedding
1354
+ # to the first rotary_dim of the input
1355
+ cos = cos.squeeze(0).squeeze(1)[:, : rot_dim // 2]
1356
+ sin = sin.squeeze(0).squeeze(1)[:, : rot_dim // 2]
1357
+ return apply_rotary_emb_func(t_float, cos, sin).type_as(t)
1358
+ else:
1359
+ t_rot, t_pass = t_float[..., :rot_dim], t_float[..., rot_dim:]
1360
+ t_rot = (t_rot * cos) + (_rotate_half(t_rot) * sin)
1361
+ return torch.cat((t_rot, t_pass), dim=-1).type_as(t)
1362
+
1363
+
1364
+ class RMSNorm(torch.nn.Module):
1365
+ def __init__(self, dim: int, eps: float = 1e-6):
1366
+ super().__init__()
1367
+ self.eps = eps
1368
+ self.weight = nn.Parameter(torch.ones(dim))
1369
+
1370
+ def _norm(self, x):
1371
+ return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
1372
+
1373
+ def forward(self, x):
1374
+ if rms_norm is not None and x.is_cuda:
1375
+ return rms_norm(x, self.weight, self.eps)
1376
+ else:
1377
+ output = self._norm(x.float()).type_as(x)
1378
+ return output * self.weight
qwen.tiktoken ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2b1b8dfb5cc5f024bafc373121c6aba3f66f9a5a0269e243470a1de16a33186
3
+ size 2561218
qwen_generation_utils.py ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ """Generation support."""
7
+
8
+ from typing import Tuple, List, Union, Iterable
9
+
10
+ import numpy as np
11
+ import torch
12
+ import torch.nn.functional as F
13
+ from transformers import PreTrainedTokenizer
14
+ from transformers import logging
15
+ from transformers.generation import LogitsProcessor
16
+
17
+ logger = logging.get_logger(__name__)
18
+
19
+ # Types.
20
+ HistoryType = List[Tuple[str, str]]
21
+ TokensType = List[int]
22
+ BatchTokensType = List[List[int]]
23
+
24
+
25
+ def pad_batch(batch: BatchTokensType, pad_id: int, seq_length: int) -> BatchTokensType:
26
+ for tokens in batch:
27
+ context_length = len(tokens)
28
+ if context_length < seq_length:
29
+ tokens.extend([pad_id] * (seq_length - context_length))
30
+ return batch
31
+
32
+
33
+ def get_ltor_masks_and_position_ids(
34
+ data,
35
+ eod_token,
36
+ reset_position_ids,
37
+ reset_attention_mask,
38
+ eod_mask_loss,
39
+ ):
40
+ """Build masks and position id for left to right model."""
41
+
42
+ # Extract batch size and sequence length.
43
+ micro_batch_size, seq_length = data.size()
44
+
45
+ # Attention mask (lower triangular).
46
+ if reset_attention_mask:
47
+ att_mask_batch = micro_batch_size
48
+ else:
49
+ att_mask_batch = 1
50
+ attention_mask = torch.tril(
51
+ torch.ones((att_mask_batch, seq_length, seq_length), device=data.device)
52
+ ).view(att_mask_batch, 1, seq_length, seq_length)
53
+
54
+ # Loss mask.
55
+ loss_mask = torch.ones(data.size(), dtype=torch.float, device=data.device)
56
+ if eod_mask_loss:
57
+ loss_mask[data == eod_token] = 0.0
58
+
59
+ # Position ids.
60
+ position_ids = torch.arange(seq_length, dtype=torch.long, device=data.device)
61
+ position_ids = position_ids.unsqueeze(0).expand_as(data)
62
+ # We need to clone as the ids will be modifed based on batch index.
63
+ if reset_position_ids:
64
+ position_ids = position_ids.clone()
65
+
66
+ if reset_position_ids or reset_attention_mask:
67
+ # Loop through the batches:
68
+ for b in range(micro_batch_size):
69
+
70
+ # Find indecies where EOD token is.
71
+ eod_index = position_ids[b, data[b] == eod_token]
72
+ # Detach indecies from positions if going to modify positions.
73
+ if reset_position_ids:
74
+ eod_index = eod_index.clone()
75
+
76
+ # Loop through EOD indecies:
77
+ prev_index = 0
78
+ for j in range(eod_index.size()[0]):
79
+ i = eod_index[j]
80
+ # Mask attention loss.
81
+ if reset_attention_mask:
82
+ attention_mask[b, 0, (i + 1) :, : (i + 1)] = 0
83
+ # Reset positions.
84
+ if reset_position_ids:
85
+ position_ids[b, (i + 1) :] -= i + 1 - prev_index
86
+ prev_index = i + 1
87
+
88
+ # Convert attention mask to binary:
89
+ attention_mask = attention_mask < 0.5
90
+
91
+ return attention_mask, loss_mask, position_ids
92
+
93
+
94
+ def get_batch(context_tokens: torch.LongTensor, eod_id: int):
95
+ """Generate batch from context tokens."""
96
+ # Move to GPU.
97
+ tokens = context_tokens.contiguous().to(context_tokens.device)
98
+ # Get the attention mask and postition ids.
99
+ attention_mask, _, position_ids = get_ltor_masks_and_position_ids(
100
+ tokens,
101
+ eod_id,
102
+ reset_position_ids=False,
103
+ reset_attention_mask=False,
104
+ eod_mask_loss=False,
105
+ )
106
+ return tokens, attention_mask, position_ids
107
+
108
+
109
+ def get_stop_words_ids(chat_format, tokenizer):
110
+ if chat_format == "raw":
111
+ stop_words_ids = [tokenizer.encode("Human:"), [tokenizer.eod_id]]
112
+ elif chat_format == "chatml":
113
+ stop_words_ids = [[tokenizer.im_end_id], [tokenizer.im_start_id]]
114
+ else:
115
+ raise NotImplementedError(f"Unknown chat format {chat_format!r}")
116
+ return stop_words_ids
117
+
118
+
119
+ def make_context(
120
+ tokenizer: PreTrainedTokenizer,
121
+ query: str,
122
+ history: List[Tuple[str, str]] = None,
123
+ system: str = "",
124
+ max_window_size: int = 6144,
125
+ chat_format: str = "chatml",
126
+ ):
127
+ if history is None:
128
+ history = []
129
+
130
+ if chat_format == "chatml":
131
+ im_start, im_end = "<|im_start|>", "<|im_end|>"
132
+ im_start_tokens = [tokenizer.im_start_id]
133
+ im_end_tokens = [tokenizer.im_end_id]
134
+ nl_tokens = tokenizer.encode("\n")
135
+
136
+ def _tokenize_str(role, content):
137
+ return f"{role}\n{content}", tokenizer.encode(
138
+ role, allowed_special=set()
139
+ ) + nl_tokens + tokenizer.encode(content, allowed_special=set())
140
+
141
+ system_text, system_tokens_part = _tokenize_str("system", system)
142
+ system_tokens = im_start_tokens + system_tokens_part + im_end_tokens
143
+
144
+ raw_text = ""
145
+ context_tokens = []
146
+
147
+ for turn_query, turn_response in reversed(history):
148
+ query_text, query_tokens_part = _tokenize_str("user", turn_query)
149
+ query_tokens = im_start_tokens + query_tokens_part + im_end_tokens
150
+ response_text, response_tokens_part = _tokenize_str(
151
+ "assistant", turn_response
152
+ )
153
+ response_tokens = im_start_tokens + response_tokens_part + im_end_tokens
154
+
155
+ next_context_tokens = nl_tokens + query_tokens + nl_tokens + response_tokens
156
+ prev_chat = (
157
+ f"\n{im_start}{query_text}{im_end}\n{im_start}{response_text}{im_end}"
158
+ )
159
+
160
+ current_context_size = (
161
+ len(system_tokens) + len(next_context_tokens) + len(context_tokens)
162
+ )
163
+ if current_context_size < max_window_size:
164
+ context_tokens = next_context_tokens + context_tokens
165
+ raw_text = prev_chat + raw_text
166
+ else:
167
+ break
168
+
169
+ context_tokens = system_tokens + context_tokens
170
+ raw_text = f"{im_start}{system_text}{im_end}" + raw_text
171
+ context_tokens += (
172
+ nl_tokens
173
+ + im_start_tokens
174
+ + _tokenize_str("user", query)[1]
175
+ + im_end_tokens
176
+ + nl_tokens
177
+ + im_start_tokens
178
+ + tokenizer.encode("assistant")
179
+ + nl_tokens
180
+ )
181
+ raw_text += f"\n{im_start}user\n{query}{im_end}\n{im_start}assistant\n"
182
+
183
+ elif chat_format == "raw":
184
+ raw_text = query
185
+ context_tokens = tokenizer.encode(raw_text)
186
+ else:
187
+ raise NotImplementedError(f"Unknown chat format {chat_format!r}")
188
+
189
+ return raw_text, context_tokens
190
+
191
+
192
+ def _decode_default(
193
+ tokens: List[int],
194
+ *,
195
+ stop_words: List[str],
196
+ eod_words: List[str],
197
+ tokenizer: PreTrainedTokenizer,
198
+ raw_text_len: int,
199
+ verbose: bool = False,
200
+ return_end_reason: bool = False,
201
+ errors: str='replace',
202
+ ):
203
+ trim_decode_tokens = tokenizer.decode(tokens, errors=errors)[raw_text_len:]
204
+ if verbose:
205
+ print("\nRaw Generate: ", trim_decode_tokens)
206
+
207
+ end_reason = f"Gen length {len(tokens)}"
208
+ for stop_word in stop_words:
209
+ trim_decode_tokens = trim_decode_tokens.replace(stop_word, "").strip()
210
+ for eod_word in eod_words:
211
+ if eod_word in trim_decode_tokens:
212
+ end_reason = f"Gen {eod_word!r}"
213
+ trim_decode_tokens = trim_decode_tokens.split(eod_word)[0]
214
+ trim_decode_tokens = trim_decode_tokens.strip()
215
+ if verbose:
216
+ print("\nEnd Reason:", end_reason)
217
+ print("\nGenerate: ", trim_decode_tokens)
218
+
219
+ if return_end_reason:
220
+ return trim_decode_tokens, end_reason
221
+ else:
222
+ return trim_decode_tokens
223
+
224
+
225
+ def _decode_chatml(
226
+ tokens: List[int],
227
+ *,
228
+ stop_words: List[str],
229
+ eod_token_ids: List[int],
230
+ tokenizer: PreTrainedTokenizer,
231
+ raw_text_len: int,
232
+ context_length: int,
233
+ verbose: bool = False,
234
+ return_end_reason: bool = False,
235
+ errors: str='replace'
236
+ ):
237
+ end_reason = f"Gen length {len(tokens)}"
238
+ eod_token_idx = context_length
239
+ for eod_token_idx in range(context_length, len(tokens)):
240
+ if tokens[eod_token_idx] in eod_token_ids:
241
+ end_reason = f"Gen {tokenizer.decode([tokens[eod_token_idx]])!r}"
242
+ break
243
+
244
+ trim_decode_tokens = tokenizer.decode(tokens[:eod_token_idx], errors=errors)[raw_text_len:]
245
+ if verbose:
246
+ print("\nRaw Generate w/o EOD:", tokenizer.decode(tokens, errors=errors)[raw_text_len:])
247
+ print("\nRaw Generate:", trim_decode_tokens)
248
+ print("\nEnd Reason:", end_reason)
249
+ for stop_word in stop_words:
250
+ trim_decode_tokens = trim_decode_tokens.replace(stop_word, "").strip()
251
+ trim_decode_tokens = trim_decode_tokens.strip()
252
+ if verbose:
253
+ print("\nGenerate:", trim_decode_tokens)
254
+
255
+ if return_end_reason:
256
+ return trim_decode_tokens, end_reason
257
+ else:
258
+ return trim_decode_tokens
259
+
260
+
261
+ def decode_tokens(
262
+ tokens: Union[torch.LongTensor, TokensType],
263
+ tokenizer: PreTrainedTokenizer,
264
+ raw_text_len: int,
265
+ context_length: int,
266
+ chat_format: str,
267
+ verbose: bool = False,
268
+ return_end_reason: bool = False,
269
+ errors: str="replace",
270
+ ) -> str:
271
+ if torch.is_tensor(tokens):
272
+ tokens = tokens.cpu().numpy().tolist()
273
+
274
+ if chat_format == "chatml":
275
+ return _decode_chatml(
276
+ tokens,
277
+ stop_words=[],
278
+ eod_token_ids=[tokenizer.im_start_id, tokenizer.im_end_id],
279
+ tokenizer=tokenizer,
280
+ raw_text_len=raw_text_len,
281
+ context_length=context_length,
282
+ verbose=verbose,
283
+ return_end_reason=return_end_reason,
284
+ errors=errors,
285
+ )
286
+ elif chat_format == "raw":
287
+ return _decode_default(
288
+ tokens,
289
+ stop_words=["<|endoftext|>"],
290
+ eod_words=["<|endoftext|>"],
291
+ tokenizer=tokenizer,
292
+ raw_text_len=raw_text_len,
293
+ verbose=verbose,
294
+ return_end_reason=return_end_reason,
295
+ errors=errors,
296
+ )
297
+ else:
298
+ raise NotImplementedError(f"Unknown chat format {chat_format!r}")
299
+
300
+
301
+ class StopWordsLogitsProcessor(LogitsProcessor):
302
+ """
303
+ :class:`transformers.LogitsProcessor` that enforces that when specified sequences appear, stop geration.
304
+
305
+ Args:
306
+ stop_words_ids (:obj:`List[List[int]]`):
307
+ List of list of token ids of stop ids. In order to get the tokens of the words
308
+ that should not appear in the generated text, use :obj:`tokenizer(bad_word,
309
+ add_prefix_space=True).input_ids`.
310
+ eos_token_id (:obj:`int`):
311
+ The id of the `end-of-sequence` token.
312
+ """
313
+
314
+ def __init__(self, stop_words_ids: Iterable[Iterable[int]], eos_token_id: int):
315
+
316
+ if not isinstance(stop_words_ids, List) or len(stop_words_ids) == 0:
317
+ raise ValueError(
318
+ f"`stop_words_ids` has to be a non-emtpy list, but is {stop_words_ids}."
319
+ )
320
+ if any(not isinstance(bad_word_ids, list) for bad_word_ids in stop_words_ids):
321
+ raise ValueError(
322
+ f"`stop_words_ids` has to be a list of lists, but is {stop_words_ids}."
323
+ )
324
+ if any(
325
+ any(
326
+ (not isinstance(token_id, (int, np.integer)) or token_id < 0)
327
+ for token_id in stop_word_ids
328
+ )
329
+ for stop_word_ids in stop_words_ids
330
+ ):
331
+ raise ValueError(
332
+ f"Each list in `stop_words_ids` has to be a list of positive integers, but is {stop_words_ids}."
333
+ )
334
+
335
+ self.stop_words_ids = list(
336
+ filter(
337
+ lambda bad_token_seq: bad_token_seq != [eos_token_id], stop_words_ids
338
+ )
339
+ )
340
+ self.eos_token_id = eos_token_id
341
+ for stop_token_seq in self.stop_words_ids:
342
+ assert (
343
+ len(stop_token_seq) > 0
344
+ ), "Stop words token sequences {} cannot have an empty list".format(
345
+ stop_words_ids
346
+ )
347
+
348
+ def __call__(
349
+ self, input_ids: torch.LongTensor, scores: torch.FloatTensor
350
+ ) -> torch.FloatTensor:
351
+ stopped_samples = self._calc_stopped_samples(input_ids)
352
+ for i, should_stop in enumerate(stopped_samples):
353
+ if should_stop:
354
+ scores[i, self.eos_token_id] = float(2**15)
355
+ return scores
356
+
357
+ def _tokens_match(self, prev_tokens: torch.LongTensor, tokens: List[int]) -> bool:
358
+ if len(tokens) == 0:
359
+ # if bad word tokens is just one token always ban it
360
+ return True
361
+ elif len(tokens) > len(prev_tokens):
362
+ # if bad word tokens are longer then prev input_ids they can't be equal
363
+ return False
364
+ elif prev_tokens[-len(tokens) :].tolist() == tokens:
365
+ # if tokens match
366
+ return True
367
+ else:
368
+ return False
369
+
370
+ def _calc_stopped_samples(self, prev_input_ids: Iterable[int]) -> Iterable[int]:
371
+ stopped_samples = []
372
+ for prev_input_ids_slice in prev_input_ids:
373
+ match = False
374
+ for stop_token_seq in self.stop_words_ids:
375
+ if self._tokens_match(prev_input_ids_slice, stop_token_seq):
376
+ # if tokens do not match continue
377
+ match = True
378
+ break
379
+ stopped_samples.append(match)
380
+
381
+ return stopped_samples
382
+
383
+
384
+ def top_k_logits(logits, top_k=0, top_p=0.0, filter_value=-float("Inf")):
385
+ """This function has been mostly taken from huggingface conversational
386
+ ai code at
387
+ https://medium.com/huggingface/how-to-build-a-state-of-the-art-
388
+ conversational-ai-with-transfer-learning-2d818ac26313"""
389
+
390
+ if top_k > 0:
391
+ # Remove all tokens with a probability less than the
392
+ # last token of the top-k
393
+ indices_to_remove = logits < torch.topk(logits, top_k)[0][..., -1, None]
394
+ logits[indices_to_remove] = filter_value
395
+
396
+ if top_p > 0.0:
397
+ # Cconvert to 1D
398
+ sorted_logits, sorted_indices = torch.sort(logits, descending=True, dim=-1)
399
+ cumulative_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1)
400
+
401
+ # Remove tokens with cumulative probability above the threshold
402
+ sorted_indices_to_remove = cumulative_probs > top_p
403
+ # Shift the indices to the right to keep also the first token
404
+ # above the threshold
405
+ sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()
406
+ sorted_indices_to_remove[..., 0] = 0
407
+ for i in range(sorted_indices.size(0)):
408
+ indices_to_remove = sorted_indices[i][sorted_indices_to_remove[i]]
409
+ logits[i][indices_to_remove] = filter_value
410
+
411
+ return logits
412
+
413
+
414
+ def switch(val1, val2, boolean):
415
+ boolean = boolean.type_as(val1)
416
+ return (1 - boolean) * val1 + boolean * val2
special_tokens_map.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "pad_token": "<|endoftext|>"
3
+ }
tokenization_qwen.py ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ """Tokenization classes for QWen."""
7
+
8
+ import base64
9
+ import logging
10
+ import os
11
+ import unicodedata
12
+ from typing import Collection, Dict, List, Set, Tuple, Union
13
+
14
+ import tiktoken
15
+ from transformers import PreTrainedTokenizer, AddedToken
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+
20
+ VOCAB_FILES_NAMES = {"vocab_file": "qwen.tiktoken"}
21
+
22
+ PAT_STR = r"""(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"""
23
+ ENDOFTEXT = "<|endoftext|>"
24
+ IMSTART = "<|im_start|>"
25
+ IMEND = "<|im_end|>"
26
+ # as the default behavior is changed to allow special tokens in
27
+ # regular texts, the surface forms of special tokens need to be
28
+ # as different as possible to minimize the impact
29
+ EXTRAS = tuple((f"<|extra_{i}|>" for i in range(205)))
30
+ # changed to use actual index to avoid misconfiguration with vocabulary expansion
31
+ SPECIAL_START_ID = 151643
32
+ SPECIAL_TOKENS = tuple(
33
+ enumerate(
34
+ (
35
+ (
36
+ ENDOFTEXT,
37
+ IMSTART,
38
+ IMEND,
39
+ )
40
+ + EXTRAS
41
+ ),
42
+ start=SPECIAL_START_ID,
43
+ )
44
+ )
45
+ SPECIAL_TOKENS_SET = set(t for i, t in SPECIAL_TOKENS)
46
+
47
+
48
+ def _load_tiktoken_bpe(tiktoken_bpe_file: str) -> Dict[bytes, int]:
49
+ with open(tiktoken_bpe_file, "rb") as f:
50
+ contents = f.read()
51
+ return {
52
+ base64.b64decode(token): int(rank)
53
+ for token, rank in (line.split() for line in contents.splitlines() if line)
54
+ }
55
+
56
+
57
+ class QWenTokenizer(PreTrainedTokenizer):
58
+ """QWen tokenizer."""
59
+
60
+ vocab_files_names = VOCAB_FILES_NAMES
61
+
62
+ def __init__(
63
+ self,
64
+ vocab_file,
65
+ errors="replace",
66
+ extra_vocab_file=None,
67
+ **kwargs,
68
+ ):
69
+ super().__init__(**kwargs)
70
+
71
+ # how to handle errors in decoding UTF-8 byte sequences
72
+ # use ignore if you are in streaming inference
73
+ self.errors = errors
74
+
75
+ self.mergeable_ranks = _load_tiktoken_bpe(vocab_file) # type: Dict[bytes, int]
76
+ self.special_tokens = {
77
+ token: index
78
+ for index, token in SPECIAL_TOKENS
79
+ }
80
+
81
+ # try load extra vocab from file
82
+ if extra_vocab_file is not None:
83
+ used_ids = set(self.mergeable_ranks.values()) | set(self.special_tokens.values())
84
+ extra_mergeable_ranks = _load_tiktoken_bpe(extra_vocab_file)
85
+ for token, index in extra_mergeable_ranks.items():
86
+ if token in self.mergeable_ranks:
87
+ logger.info(f"extra token {token} exists, skipping")
88
+ continue
89
+ if index in used_ids:
90
+ logger.info(f'the index {index} for extra token {token} exists, skipping')
91
+ continue
92
+ self.mergeable_ranks[token] = index
93
+ # the index may be sparse after this, but don't worry tiktoken.Encoding will handle this
94
+
95
+ enc = tiktoken.Encoding(
96
+ "Qwen",
97
+ pat_str=PAT_STR,
98
+ mergeable_ranks=self.mergeable_ranks,
99
+ special_tokens=self.special_tokens,
100
+ )
101
+ assert (
102
+ len(self.mergeable_ranks) + len(self.special_tokens) == enc.n_vocab
103
+ ), f"{len(self.mergeable_ranks) + len(self.special_tokens)} != {enc.n_vocab} in encoding"
104
+
105
+ self.decoder = {
106
+ v: k for k, v in self.mergeable_ranks.items()
107
+ } # type: dict[int, bytes|str]
108
+ self.decoder.update({v: k for k, v in self.special_tokens.items()})
109
+
110
+ self.tokenizer = enc # type: tiktoken.Encoding
111
+
112
+ self.eod_id = self.tokenizer.eot_token
113
+ self.im_start_id = self.special_tokens[IMSTART]
114
+ self.im_end_id = self.special_tokens[IMEND]
115
+
116
+ def __getstate__(self):
117
+ # for pickle lovers
118
+ state = self.__dict__.copy()
119
+ del state["tokenizer"]
120
+ return state
121
+
122
+ def __setstate__(self, state):
123
+ # tokenizer is not python native; don't pass it; rebuild it
124
+ self.__dict__.update(state)
125
+ enc = tiktoken.Encoding(
126
+ "Qwen",
127
+ pat_str=PAT_STR,
128
+ mergeable_ranks=self.mergeable_ranks,
129
+ special_tokens=self.special_tokens,
130
+ )
131
+ self.tokenizer = enc
132
+
133
+ def __len__(self) -> int:
134
+ return self.tokenizer.n_vocab
135
+
136
+ def get_vocab(self) -> Dict[bytes, int]:
137
+ return self.mergeable_ranks
138
+
139
+ def convert_tokens_to_ids(
140
+ self, tokens: Union[bytes, str, List[Union[bytes, str]]]
141
+ ) -> List[int]:
142
+ ids = []
143
+ if isinstance(tokens, (str, bytes)):
144
+ if tokens in self.special_tokens:
145
+ return self.special_tokens[tokens]
146
+ else:
147
+ return self.mergeable_ranks.get(tokens)
148
+ for token in tokens:
149
+ if token in self.special_tokens:
150
+ ids.append(self.special_tokens[token])
151
+ else:
152
+ ids.append(self.mergeable_ranks.get(token))
153
+ return ids
154
+
155
+ def _add_tokens(
156
+ self,
157
+ new_tokens: Union[List[str], List[AddedToken]],
158
+ special_tokens: bool = False,
159
+ ) -> int:
160
+ if not special_tokens and new_tokens:
161
+ raise ValueError("Adding regular tokens is not supported")
162
+ for token in new_tokens:
163
+ surface_form = token.content if isinstance(token, AddedToken) else token
164
+ if surface_form not in SPECIAL_TOKENS_SET:
165
+ raise ValueError("Adding unknown special tokens is not supported")
166
+ return 0
167
+
168
+ def save_vocabulary(self, save_directory: str, **kwargs) -> Tuple[str]:
169
+ """
170
+ Save only the vocabulary of the tokenizer (vocabulary).
171
+
172
+ Returns:
173
+ `Tuple(str)`: Paths to the files saved.
174
+ """
175
+ file_path = os.path.join(save_directory, "qwen.tiktoken")
176
+ with open(file_path, "w", encoding="utf8") as w:
177
+ for k, v in self.mergeable_ranks.items():
178
+ line = base64.b64encode(k).decode("utf8") + " " + str(v) + "\n"
179
+ w.write(line)
180
+ return (file_path,)
181
+
182
+ def tokenize(
183
+ self,
184
+ text: str,
185
+ allowed_special: Union[Set, str] = "all",
186
+ disallowed_special: Union[Collection, str] = (),
187
+ **kwargs,
188
+ ) -> List[Union[bytes, str]]:
189
+ """
190
+ Converts a string in a sequence of tokens.
191
+
192
+ Args:
193
+ text (`str`):
194
+ The sequence to be encoded.
195
+ allowed_special (`Literal["all"]` or `set`):
196
+ The surface forms of the tokens to be encoded as special tokens in regular texts.
197
+ Default to "all".
198
+ disallowed_special (`Literal["all"]` or `Collection`):
199
+ The surface forms of the tokens that should not be in regular texts and trigger errors.
200
+ Default to an empty tuple.
201
+
202
+ kwargs (additional keyword arguments, *optional*):
203
+ Will be passed to the underlying model specific encode method.
204
+
205
+ Returns:
206
+ `List[bytes|str]`: The list of tokens.
207
+ """
208
+ tokens = []
209
+ text = unicodedata.normalize("NFC", text)
210
+
211
+ # this implementation takes a detour: text -> token id -> token surface forms
212
+ for t in self.tokenizer.encode(
213
+ text, allowed_special=allowed_special, disallowed_special=disallowed_special
214
+ ):
215
+ tokens.append(self.decoder[t])
216
+ return tokens
217
+
218
+ def convert_tokens_to_string(self, tokens: List[Union[bytes, str]]) -> str:
219
+ """
220
+ Converts a sequence of tokens in a single string.
221
+ """
222
+ text = ""
223
+ temp = b""
224
+ for t in tokens:
225
+ if isinstance(t, str):
226
+ if temp:
227
+ text += temp.decode("utf-8", errors=self.errors)
228
+ temp = b""
229
+ text += t
230
+ elif isinstance(t, bytes):
231
+ temp += t
232
+ else:
233
+ raise TypeError("token should only be of type types or str")
234
+ if temp:
235
+ text += temp.decode("utf-8", errors=self.errors)
236
+ return text
237
+
238
+ @property
239
+ def vocab_size(self):
240
+ return self.tokenizer.n_vocab
241
+
242
+ def _convert_id_to_token(self, index: int) -> Union[bytes, str]:
243
+ """Converts an id to a token, special tokens included"""
244
+ if index in self.decoder:
245
+ return self.decoder[index]
246
+ raise ValueError("unknown ids")
247
+
248
+ def _convert_token_to_id(self, token: Union[bytes, str]) -> int:
249
+ """Converts a token to an id using the vocab, special tokens included"""
250
+ if token in self.special_tokens:
251
+ return self.special_tokens[token]
252
+ if token in self.mergeable_ranks:
253
+ return self.mergeable_ranks[token]
254
+ raise ValueError("unknown token")
255
+
256
+ def _tokenize(self, text: str, **kwargs):
257
+ """
258
+ Converts a string in a sequence of tokens (string), using the tokenizer. Split in words for word-based
259
+ vocabulary or sub-words for sub-word-based vocabularies (BPE/SentencePieces/WordPieces).
260
+
261
+ Do NOT take care of added tokens.
262
+ """
263
+ raise NotImplementedError
264
+
265
+ def _decode(
266
+ self,
267
+ token_ids: Union[int, List[int]],
268
+ skip_special_tokens: bool = False,
269
+ errors: str = None,
270
+ **kwargs,
271
+ ) -> str:
272
+ if isinstance(token_ids, int):
273
+ token_ids = [token_ids]
274
+ if skip_special_tokens:
275
+ token_ids = [i for i in token_ids if i < self.eod_id]
276
+ return self.tokenizer.decode(token_ids, errors=errors or self.errors)
tokenizer_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {},
3
+ "auto_map": {
4
+ "AutoTokenizer": [
5
+ "tokenization_qwen.QWenTokenizer",
6
+ null
7
+ ]
8
+ },
9
+ "clean_up_tokenization_spaces": true,
10
+ "model_max_length": 512,
11
+ "pad_token": "<|endoftext|>",
12
+ "padding_side": "right",
13
+ "tokenizer_class": "QWenTokenizer"
14
+ }
trainer_state.json ADDED
@@ -0,0 +1,2008 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 4.962406015037594,
5
+ "eval_steps": 500,
6
+ "global_step": 330,
7
+ "is_hyper_param_search": false,
8
+ "is_local_process_zero": true,
9
+ "is_world_process_zero": true,
10
+ "log_history": [
11
+ {
12
+ "epoch": 0.02,
13
+ "learning_rate": 0.0,
14
+ "loss": 3.6699,
15
+ "step": 1
16
+ },
17
+ {
18
+ "epoch": 0.03,
19
+ "learning_rate": 5e-06,
20
+ "loss": 3.616,
21
+ "step": 2
22
+ },
23
+ {
24
+ "epoch": 0.05,
25
+ "learning_rate": 7.924812503605782e-06,
26
+ "loss": 3.6394,
27
+ "step": 3
28
+ },
29
+ {
30
+ "epoch": 0.06,
31
+ "learning_rate": 1e-05,
32
+ "loss": 3.5342,
33
+ "step": 4
34
+ },
35
+ {
36
+ "epoch": 0.08,
37
+ "learning_rate": 1e-05,
38
+ "loss": 3.3909,
39
+ "step": 5
40
+ },
41
+ {
42
+ "epoch": 0.09,
43
+ "learning_rate": 1e-05,
44
+ "loss": 3.0278,
45
+ "step": 6
46
+ },
47
+ {
48
+ "epoch": 0.11,
49
+ "learning_rate": 1e-05,
50
+ "loss": 3.0232,
51
+ "step": 7
52
+ },
53
+ {
54
+ "epoch": 0.12,
55
+ "learning_rate": 1e-05,
56
+ "loss": 2.7886,
57
+ "step": 8
58
+ },
59
+ {
60
+ "epoch": 0.14,
61
+ "learning_rate": 1e-05,
62
+ "loss": 2.7587,
63
+ "step": 9
64
+ },
65
+ {
66
+ "epoch": 0.15,
67
+ "learning_rate": 1e-05,
68
+ "loss": 2.6985,
69
+ "step": 10
70
+ },
71
+ {
72
+ "epoch": 0.17,
73
+ "learning_rate": 1e-05,
74
+ "loss": 2.4939,
75
+ "step": 11
76
+ },
77
+ {
78
+ "epoch": 0.18,
79
+ "learning_rate": 1e-05,
80
+ "loss": 2.4019,
81
+ "step": 12
82
+ },
83
+ {
84
+ "epoch": 0.2,
85
+ "learning_rate": 1e-05,
86
+ "loss": 2.5276,
87
+ "step": 13
88
+ },
89
+ {
90
+ "epoch": 0.21,
91
+ "learning_rate": 1e-05,
92
+ "loss": 2.479,
93
+ "step": 14
94
+ },
95
+ {
96
+ "epoch": 0.23,
97
+ "learning_rate": 1e-05,
98
+ "loss": 2.2505,
99
+ "step": 15
100
+ },
101
+ {
102
+ "epoch": 0.24,
103
+ "learning_rate": 1e-05,
104
+ "loss": 2.2395,
105
+ "step": 16
106
+ },
107
+ {
108
+ "epoch": 0.26,
109
+ "learning_rate": 1e-05,
110
+ "loss": 2.0909,
111
+ "step": 17
112
+ },
113
+ {
114
+ "epoch": 0.27,
115
+ "learning_rate": 1e-05,
116
+ "loss": 2.3071,
117
+ "step": 18
118
+ },
119
+ {
120
+ "epoch": 0.29,
121
+ "learning_rate": 1e-05,
122
+ "loss": 2.222,
123
+ "step": 19
124
+ },
125
+ {
126
+ "epoch": 0.3,
127
+ "learning_rate": 1e-05,
128
+ "loss": 2.4785,
129
+ "step": 20
130
+ },
131
+ {
132
+ "epoch": 0.32,
133
+ "learning_rate": 1e-05,
134
+ "loss": 2.2537,
135
+ "step": 21
136
+ },
137
+ {
138
+ "epoch": 0.33,
139
+ "learning_rate": 1e-05,
140
+ "loss": 2.244,
141
+ "step": 22
142
+ },
143
+ {
144
+ "epoch": 0.35,
145
+ "learning_rate": 1e-05,
146
+ "loss": 2.408,
147
+ "step": 23
148
+ },
149
+ {
150
+ "epoch": 0.36,
151
+ "learning_rate": 1e-05,
152
+ "loss": 1.9875,
153
+ "step": 24
154
+ },
155
+ {
156
+ "epoch": 0.38,
157
+ "learning_rate": 1e-05,
158
+ "loss": 2.3292,
159
+ "step": 25
160
+ },
161
+ {
162
+ "epoch": 0.39,
163
+ "learning_rate": 1e-05,
164
+ "loss": 2.1417,
165
+ "step": 26
166
+ },
167
+ {
168
+ "epoch": 0.41,
169
+ "learning_rate": 1e-05,
170
+ "loss": 2.165,
171
+ "step": 27
172
+ },
173
+ {
174
+ "epoch": 0.42,
175
+ "learning_rate": 1e-05,
176
+ "loss": 2.0793,
177
+ "step": 28
178
+ },
179
+ {
180
+ "epoch": 0.44,
181
+ "learning_rate": 1e-05,
182
+ "loss": 2.3461,
183
+ "step": 29
184
+ },
185
+ {
186
+ "epoch": 0.45,
187
+ "learning_rate": 1e-05,
188
+ "loss": 2.1355,
189
+ "step": 30
190
+ },
191
+ {
192
+ "epoch": 0.47,
193
+ "learning_rate": 1e-05,
194
+ "loss": 1.8263,
195
+ "step": 31
196
+ },
197
+ {
198
+ "epoch": 0.48,
199
+ "learning_rate": 1e-05,
200
+ "loss": 2.0223,
201
+ "step": 32
202
+ },
203
+ {
204
+ "epoch": 0.5,
205
+ "learning_rate": 1e-05,
206
+ "loss": 2.2253,
207
+ "step": 33
208
+ },
209
+ {
210
+ "epoch": 0.51,
211
+ "learning_rate": 1e-05,
212
+ "loss": 2.3689,
213
+ "step": 34
214
+ },
215
+ {
216
+ "epoch": 0.53,
217
+ "learning_rate": 1e-05,
218
+ "loss": 2.0426,
219
+ "step": 35
220
+ },
221
+ {
222
+ "epoch": 0.54,
223
+ "learning_rate": 1e-05,
224
+ "loss": 2.0056,
225
+ "step": 36
226
+ },
227
+ {
228
+ "epoch": 0.56,
229
+ "learning_rate": 1e-05,
230
+ "loss": 2.0055,
231
+ "step": 37
232
+ },
233
+ {
234
+ "epoch": 0.57,
235
+ "learning_rate": 1e-05,
236
+ "loss": 2.0377,
237
+ "step": 38
238
+ },
239
+ {
240
+ "epoch": 0.59,
241
+ "learning_rate": 1e-05,
242
+ "loss": 2.1296,
243
+ "step": 39
244
+ },
245
+ {
246
+ "epoch": 0.6,
247
+ "learning_rate": 1e-05,
248
+ "loss": 1.9558,
249
+ "step": 40
250
+ },
251
+ {
252
+ "epoch": 0.62,
253
+ "learning_rate": 1e-05,
254
+ "loss": 1.8363,
255
+ "step": 41
256
+ },
257
+ {
258
+ "epoch": 0.63,
259
+ "learning_rate": 1e-05,
260
+ "loss": 2.1641,
261
+ "step": 42
262
+ },
263
+ {
264
+ "epoch": 0.65,
265
+ "learning_rate": 1e-05,
266
+ "loss": 1.8467,
267
+ "step": 43
268
+ },
269
+ {
270
+ "epoch": 0.66,
271
+ "learning_rate": 1e-05,
272
+ "loss": 1.9818,
273
+ "step": 44
274
+ },
275
+ {
276
+ "epoch": 0.68,
277
+ "learning_rate": 1e-05,
278
+ "loss": 2.2552,
279
+ "step": 45
280
+ },
281
+ {
282
+ "epoch": 0.69,
283
+ "learning_rate": 1e-05,
284
+ "loss": 1.7173,
285
+ "step": 46
286
+ },
287
+ {
288
+ "epoch": 0.71,
289
+ "learning_rate": 1e-05,
290
+ "loss": 1.9606,
291
+ "step": 47
292
+ },
293
+ {
294
+ "epoch": 0.72,
295
+ "learning_rate": 1e-05,
296
+ "loss": 2.1582,
297
+ "step": 48
298
+ },
299
+ {
300
+ "epoch": 0.74,
301
+ "learning_rate": 1e-05,
302
+ "loss": 1.9778,
303
+ "step": 49
304
+ },
305
+ {
306
+ "epoch": 0.75,
307
+ "learning_rate": 1e-05,
308
+ "loss": 1.7875,
309
+ "step": 50
310
+ },
311
+ {
312
+ "epoch": 0.77,
313
+ "learning_rate": 1e-05,
314
+ "loss": 1.7636,
315
+ "step": 51
316
+ },
317
+ {
318
+ "epoch": 0.78,
319
+ "learning_rate": 1e-05,
320
+ "loss": 1.6118,
321
+ "step": 52
322
+ },
323
+ {
324
+ "epoch": 0.8,
325
+ "learning_rate": 1e-05,
326
+ "loss": 1.886,
327
+ "step": 53
328
+ },
329
+ {
330
+ "epoch": 0.81,
331
+ "learning_rate": 1e-05,
332
+ "loss": 1.699,
333
+ "step": 54
334
+ },
335
+ {
336
+ "epoch": 0.83,
337
+ "learning_rate": 1e-05,
338
+ "loss": 1.6429,
339
+ "step": 55
340
+ },
341
+ {
342
+ "epoch": 0.84,
343
+ "learning_rate": 1e-05,
344
+ "loss": 1.9658,
345
+ "step": 56
346
+ },
347
+ {
348
+ "epoch": 0.86,
349
+ "learning_rate": 1e-05,
350
+ "loss": 1.6691,
351
+ "step": 57
352
+ },
353
+ {
354
+ "epoch": 0.87,
355
+ "learning_rate": 1e-05,
356
+ "loss": 1.6262,
357
+ "step": 58
358
+ },
359
+ {
360
+ "epoch": 0.89,
361
+ "learning_rate": 1e-05,
362
+ "loss": 1.9305,
363
+ "step": 59
364
+ },
365
+ {
366
+ "epoch": 0.9,
367
+ "learning_rate": 1e-05,
368
+ "loss": 1.7902,
369
+ "step": 60
370
+ },
371
+ {
372
+ "epoch": 0.92,
373
+ "learning_rate": 1e-05,
374
+ "loss": 1.789,
375
+ "step": 61
376
+ },
377
+ {
378
+ "epoch": 0.93,
379
+ "learning_rate": 1e-05,
380
+ "loss": 1.9741,
381
+ "step": 62
382
+ },
383
+ {
384
+ "epoch": 0.95,
385
+ "learning_rate": 1e-05,
386
+ "loss": 1.7437,
387
+ "step": 63
388
+ },
389
+ {
390
+ "epoch": 0.96,
391
+ "learning_rate": 1e-05,
392
+ "loss": 1.8843,
393
+ "step": 64
394
+ },
395
+ {
396
+ "epoch": 0.98,
397
+ "learning_rate": 1e-05,
398
+ "loss": 1.852,
399
+ "step": 65
400
+ },
401
+ {
402
+ "epoch": 0.99,
403
+ "learning_rate": 1e-05,
404
+ "loss": 1.8561,
405
+ "step": 66
406
+ },
407
+ {
408
+ "epoch": 1.01,
409
+ "learning_rate": 1e-05,
410
+ "loss": 1.7507,
411
+ "step": 67
412
+ },
413
+ {
414
+ "epoch": 1.02,
415
+ "learning_rate": 1e-05,
416
+ "loss": 1.3836,
417
+ "step": 68
418
+ },
419
+ {
420
+ "epoch": 1.04,
421
+ "learning_rate": 1e-05,
422
+ "loss": 1.5647,
423
+ "step": 69
424
+ },
425
+ {
426
+ "epoch": 1.05,
427
+ "learning_rate": 1e-05,
428
+ "loss": 1.6693,
429
+ "step": 70
430
+ },
431
+ {
432
+ "epoch": 1.07,
433
+ "learning_rate": 1e-05,
434
+ "loss": 1.4477,
435
+ "step": 71
436
+ },
437
+ {
438
+ "epoch": 1.08,
439
+ "learning_rate": 1e-05,
440
+ "loss": 1.6273,
441
+ "step": 72
442
+ },
443
+ {
444
+ "epoch": 1.1,
445
+ "learning_rate": 1e-05,
446
+ "loss": 1.7846,
447
+ "step": 73
448
+ },
449
+ {
450
+ "epoch": 1.11,
451
+ "learning_rate": 1e-05,
452
+ "loss": 1.563,
453
+ "step": 74
454
+ },
455
+ {
456
+ "epoch": 1.13,
457
+ "learning_rate": 1e-05,
458
+ "loss": 1.4053,
459
+ "step": 75
460
+ },
461
+ {
462
+ "epoch": 1.14,
463
+ "learning_rate": 1e-05,
464
+ "loss": 1.7382,
465
+ "step": 76
466
+ },
467
+ {
468
+ "epoch": 1.16,
469
+ "learning_rate": 1e-05,
470
+ "loss": 1.4874,
471
+ "step": 77
472
+ },
473
+ {
474
+ "epoch": 1.17,
475
+ "learning_rate": 1e-05,
476
+ "loss": 1.5523,
477
+ "step": 78
478
+ },
479
+ {
480
+ "epoch": 1.19,
481
+ "learning_rate": 1e-05,
482
+ "loss": 1.4858,
483
+ "step": 79
484
+ },
485
+ {
486
+ "epoch": 1.2,
487
+ "learning_rate": 1e-05,
488
+ "loss": 1.705,
489
+ "step": 80
490
+ },
491
+ {
492
+ "epoch": 1.22,
493
+ "learning_rate": 1e-05,
494
+ "loss": 1.3546,
495
+ "step": 81
496
+ },
497
+ {
498
+ "epoch": 1.23,
499
+ "learning_rate": 1e-05,
500
+ "loss": 1.2475,
501
+ "step": 82
502
+ },
503
+ {
504
+ "epoch": 1.25,
505
+ "learning_rate": 1e-05,
506
+ "loss": 1.4983,
507
+ "step": 83
508
+ },
509
+ {
510
+ "epoch": 1.26,
511
+ "learning_rate": 1e-05,
512
+ "loss": 1.4156,
513
+ "step": 84
514
+ },
515
+ {
516
+ "epoch": 1.28,
517
+ "learning_rate": 1e-05,
518
+ "loss": 1.3414,
519
+ "step": 85
520
+ },
521
+ {
522
+ "epoch": 1.29,
523
+ "learning_rate": 1e-05,
524
+ "loss": 1.5126,
525
+ "step": 86
526
+ },
527
+ {
528
+ "epoch": 1.31,
529
+ "learning_rate": 1e-05,
530
+ "loss": 1.3543,
531
+ "step": 87
532
+ },
533
+ {
534
+ "epoch": 1.32,
535
+ "learning_rate": 1e-05,
536
+ "loss": 1.5546,
537
+ "step": 88
538
+ },
539
+ {
540
+ "epoch": 1.34,
541
+ "learning_rate": 1e-05,
542
+ "loss": 1.5876,
543
+ "step": 89
544
+ },
545
+ {
546
+ "epoch": 1.35,
547
+ "learning_rate": 1e-05,
548
+ "loss": 1.4072,
549
+ "step": 90
550
+ },
551
+ {
552
+ "epoch": 1.37,
553
+ "learning_rate": 1e-05,
554
+ "loss": 1.3553,
555
+ "step": 91
556
+ },
557
+ {
558
+ "epoch": 1.38,
559
+ "learning_rate": 1e-05,
560
+ "loss": 1.5311,
561
+ "step": 92
562
+ },
563
+ {
564
+ "epoch": 1.4,
565
+ "learning_rate": 1e-05,
566
+ "loss": 1.454,
567
+ "step": 93
568
+ },
569
+ {
570
+ "epoch": 1.41,
571
+ "learning_rate": 1e-05,
572
+ "loss": 1.39,
573
+ "step": 94
574
+ },
575
+ {
576
+ "epoch": 1.43,
577
+ "learning_rate": 1e-05,
578
+ "loss": 1.4627,
579
+ "step": 95
580
+ },
581
+ {
582
+ "epoch": 1.44,
583
+ "learning_rate": 1e-05,
584
+ "loss": 1.5155,
585
+ "step": 96
586
+ },
587
+ {
588
+ "epoch": 1.46,
589
+ "learning_rate": 1e-05,
590
+ "loss": 1.3862,
591
+ "step": 97
592
+ },
593
+ {
594
+ "epoch": 1.47,
595
+ "learning_rate": 1e-05,
596
+ "loss": 1.1501,
597
+ "step": 98
598
+ },
599
+ {
600
+ "epoch": 1.49,
601
+ "learning_rate": 1e-05,
602
+ "loss": 1.3959,
603
+ "step": 99
604
+ },
605
+ {
606
+ "epoch": 1.5,
607
+ "learning_rate": 1e-05,
608
+ "loss": 1.6432,
609
+ "step": 100
610
+ },
611
+ {
612
+ "epoch": 1.52,
613
+ "learning_rate": 1e-05,
614
+ "loss": 1.4406,
615
+ "step": 101
616
+ },
617
+ {
618
+ "epoch": 1.53,
619
+ "learning_rate": 1e-05,
620
+ "loss": 1.52,
621
+ "step": 102
622
+ },
623
+ {
624
+ "epoch": 1.55,
625
+ "learning_rate": 1e-05,
626
+ "loss": 1.4255,
627
+ "step": 103
628
+ },
629
+ {
630
+ "epoch": 1.56,
631
+ "learning_rate": 1e-05,
632
+ "loss": 1.2903,
633
+ "step": 104
634
+ },
635
+ {
636
+ "epoch": 1.58,
637
+ "learning_rate": 1e-05,
638
+ "loss": 1.5818,
639
+ "step": 105
640
+ },
641
+ {
642
+ "epoch": 1.59,
643
+ "learning_rate": 1e-05,
644
+ "loss": 1.386,
645
+ "step": 106
646
+ },
647
+ {
648
+ "epoch": 1.61,
649
+ "learning_rate": 1e-05,
650
+ "loss": 1.283,
651
+ "step": 107
652
+ },
653
+ {
654
+ "epoch": 1.62,
655
+ "learning_rate": 1e-05,
656
+ "loss": 1.3798,
657
+ "step": 108
658
+ },
659
+ {
660
+ "epoch": 1.64,
661
+ "learning_rate": 1e-05,
662
+ "loss": 1.4538,
663
+ "step": 109
664
+ },
665
+ {
666
+ "epoch": 1.65,
667
+ "learning_rate": 1e-05,
668
+ "loss": 1.2159,
669
+ "step": 110
670
+ },
671
+ {
672
+ "epoch": 1.67,
673
+ "learning_rate": 1e-05,
674
+ "loss": 1.4725,
675
+ "step": 111
676
+ },
677
+ {
678
+ "epoch": 1.68,
679
+ "learning_rate": 1e-05,
680
+ "loss": 1.381,
681
+ "step": 112
682
+ },
683
+ {
684
+ "epoch": 1.7,
685
+ "learning_rate": 1e-05,
686
+ "loss": 1.252,
687
+ "step": 113
688
+ },
689
+ {
690
+ "epoch": 1.71,
691
+ "learning_rate": 1e-05,
692
+ "loss": 1.341,
693
+ "step": 114
694
+ },
695
+ {
696
+ "epoch": 1.73,
697
+ "learning_rate": 1e-05,
698
+ "loss": 1.5052,
699
+ "step": 115
700
+ },
701
+ {
702
+ "epoch": 1.74,
703
+ "learning_rate": 1e-05,
704
+ "loss": 1.1877,
705
+ "step": 116
706
+ },
707
+ {
708
+ "epoch": 1.76,
709
+ "learning_rate": 1e-05,
710
+ "loss": 1.1438,
711
+ "step": 117
712
+ },
713
+ {
714
+ "epoch": 1.77,
715
+ "learning_rate": 1e-05,
716
+ "loss": 1.3111,
717
+ "step": 118
718
+ },
719
+ {
720
+ "epoch": 1.79,
721
+ "learning_rate": 1e-05,
722
+ "loss": 1.136,
723
+ "step": 119
724
+ },
725
+ {
726
+ "epoch": 1.8,
727
+ "learning_rate": 1e-05,
728
+ "loss": 1.0645,
729
+ "step": 120
730
+ },
731
+ {
732
+ "epoch": 1.82,
733
+ "learning_rate": 1e-05,
734
+ "loss": 1.2853,
735
+ "step": 121
736
+ },
737
+ {
738
+ "epoch": 1.83,
739
+ "learning_rate": 1e-05,
740
+ "loss": 1.1764,
741
+ "step": 122
742
+ },
743
+ {
744
+ "epoch": 1.85,
745
+ "learning_rate": 1e-05,
746
+ "loss": 1.2228,
747
+ "step": 123
748
+ },
749
+ {
750
+ "epoch": 1.86,
751
+ "learning_rate": 1e-05,
752
+ "loss": 0.9635,
753
+ "step": 124
754
+ },
755
+ {
756
+ "epoch": 1.88,
757
+ "learning_rate": 1e-05,
758
+ "loss": 1.3114,
759
+ "step": 125
760
+ },
761
+ {
762
+ "epoch": 1.89,
763
+ "learning_rate": 1e-05,
764
+ "loss": 1.2582,
765
+ "step": 126
766
+ },
767
+ {
768
+ "epoch": 1.91,
769
+ "learning_rate": 1e-05,
770
+ "loss": 1.0929,
771
+ "step": 127
772
+ },
773
+ {
774
+ "epoch": 1.92,
775
+ "learning_rate": 1e-05,
776
+ "loss": 1.3374,
777
+ "step": 128
778
+ },
779
+ {
780
+ "epoch": 1.94,
781
+ "learning_rate": 1e-05,
782
+ "loss": 1.2309,
783
+ "step": 129
784
+ },
785
+ {
786
+ "epoch": 1.95,
787
+ "learning_rate": 1e-05,
788
+ "loss": 1.2563,
789
+ "step": 130
790
+ },
791
+ {
792
+ "epoch": 1.97,
793
+ "learning_rate": 1e-05,
794
+ "loss": 1.2559,
795
+ "step": 131
796
+ },
797
+ {
798
+ "epoch": 1.98,
799
+ "learning_rate": 1e-05,
800
+ "loss": 1.2581,
801
+ "step": 132
802
+ },
803
+ {
804
+ "epoch": 2.0,
805
+ "learning_rate": 1e-05,
806
+ "loss": 1.2812,
807
+ "step": 133
808
+ },
809
+ {
810
+ "epoch": 2.02,
811
+ "learning_rate": 1e-05,
812
+ "loss": 1.0479,
813
+ "step": 134
814
+ },
815
+ {
816
+ "epoch": 2.03,
817
+ "learning_rate": 1e-05,
818
+ "loss": 1.0381,
819
+ "step": 135
820
+ },
821
+ {
822
+ "epoch": 2.05,
823
+ "learning_rate": 1e-05,
824
+ "loss": 1.1208,
825
+ "step": 136
826
+ },
827
+ {
828
+ "epoch": 2.06,
829
+ "learning_rate": 1e-05,
830
+ "loss": 1.0136,
831
+ "step": 137
832
+ },
833
+ {
834
+ "epoch": 2.08,
835
+ "learning_rate": 1e-05,
836
+ "loss": 1.0657,
837
+ "step": 138
838
+ },
839
+ {
840
+ "epoch": 2.09,
841
+ "learning_rate": 1e-05,
842
+ "loss": 1.1409,
843
+ "step": 139
844
+ },
845
+ {
846
+ "epoch": 2.11,
847
+ "learning_rate": 1e-05,
848
+ "loss": 1.0947,
849
+ "step": 140
850
+ },
851
+ {
852
+ "epoch": 2.12,
853
+ "learning_rate": 1e-05,
854
+ "loss": 1.1044,
855
+ "step": 141
856
+ },
857
+ {
858
+ "epoch": 2.14,
859
+ "learning_rate": 1e-05,
860
+ "loss": 0.962,
861
+ "step": 142
862
+ },
863
+ {
864
+ "epoch": 2.15,
865
+ "learning_rate": 1e-05,
866
+ "loss": 1.0793,
867
+ "step": 143
868
+ },
869
+ {
870
+ "epoch": 2.17,
871
+ "learning_rate": 1e-05,
872
+ "loss": 1.0441,
873
+ "step": 144
874
+ },
875
+ {
876
+ "epoch": 2.18,
877
+ "learning_rate": 1e-05,
878
+ "loss": 0.884,
879
+ "step": 145
880
+ },
881
+ {
882
+ "epoch": 2.2,
883
+ "learning_rate": 1e-05,
884
+ "loss": 1.1797,
885
+ "step": 146
886
+ },
887
+ {
888
+ "epoch": 2.21,
889
+ "learning_rate": 1e-05,
890
+ "loss": 1.0734,
891
+ "step": 147
892
+ },
893
+ {
894
+ "epoch": 2.23,
895
+ "learning_rate": 1e-05,
896
+ "loss": 0.8103,
897
+ "step": 148
898
+ },
899
+ {
900
+ "epoch": 2.24,
901
+ "learning_rate": 1e-05,
902
+ "loss": 0.8786,
903
+ "step": 149
904
+ },
905
+ {
906
+ "epoch": 2.26,
907
+ "learning_rate": 1e-05,
908
+ "loss": 0.8878,
909
+ "step": 150
910
+ },
911
+ {
912
+ "epoch": 2.27,
913
+ "learning_rate": 1e-05,
914
+ "loss": 0.9835,
915
+ "step": 151
916
+ },
917
+ {
918
+ "epoch": 2.29,
919
+ "learning_rate": 1e-05,
920
+ "loss": 0.832,
921
+ "step": 152
922
+ },
923
+ {
924
+ "epoch": 2.3,
925
+ "learning_rate": 1e-05,
926
+ "loss": 1.0483,
927
+ "step": 153
928
+ },
929
+ {
930
+ "epoch": 2.32,
931
+ "learning_rate": 1e-05,
932
+ "loss": 0.7673,
933
+ "step": 154
934
+ },
935
+ {
936
+ "epoch": 2.33,
937
+ "learning_rate": 1e-05,
938
+ "loss": 0.9498,
939
+ "step": 155
940
+ },
941
+ {
942
+ "epoch": 2.35,
943
+ "learning_rate": 1e-05,
944
+ "loss": 1.0992,
945
+ "step": 156
946
+ },
947
+ {
948
+ "epoch": 2.36,
949
+ "learning_rate": 1e-05,
950
+ "loss": 0.7458,
951
+ "step": 157
952
+ },
953
+ {
954
+ "epoch": 2.38,
955
+ "learning_rate": 1e-05,
956
+ "loss": 0.9574,
957
+ "step": 158
958
+ },
959
+ {
960
+ "epoch": 2.39,
961
+ "learning_rate": 1e-05,
962
+ "loss": 0.9847,
963
+ "step": 159
964
+ },
965
+ {
966
+ "epoch": 2.41,
967
+ "learning_rate": 1e-05,
968
+ "loss": 0.963,
969
+ "step": 160
970
+ },
971
+ {
972
+ "epoch": 2.42,
973
+ "learning_rate": 1e-05,
974
+ "loss": 0.8669,
975
+ "step": 161
976
+ },
977
+ {
978
+ "epoch": 2.44,
979
+ "learning_rate": 1e-05,
980
+ "loss": 1.0586,
981
+ "step": 162
982
+ },
983
+ {
984
+ "epoch": 2.45,
985
+ "learning_rate": 1e-05,
986
+ "loss": 0.859,
987
+ "step": 163
988
+ },
989
+ {
990
+ "epoch": 2.47,
991
+ "learning_rate": 1e-05,
992
+ "loss": 0.7095,
993
+ "step": 164
994
+ },
995
+ {
996
+ "epoch": 2.48,
997
+ "learning_rate": 1e-05,
998
+ "loss": 0.7627,
999
+ "step": 165
1000
+ },
1001
+ {
1002
+ "epoch": 2.5,
1003
+ "learning_rate": 1e-05,
1004
+ "loss": 1.0254,
1005
+ "step": 166
1006
+ },
1007
+ {
1008
+ "epoch": 2.51,
1009
+ "learning_rate": 1e-05,
1010
+ "loss": 1.1962,
1011
+ "step": 167
1012
+ },
1013
+ {
1014
+ "epoch": 2.53,
1015
+ "learning_rate": 1e-05,
1016
+ "loss": 0.7622,
1017
+ "step": 168
1018
+ },
1019
+ {
1020
+ "epoch": 2.54,
1021
+ "learning_rate": 1e-05,
1022
+ "loss": 0.991,
1023
+ "step": 169
1024
+ },
1025
+ {
1026
+ "epoch": 2.56,
1027
+ "learning_rate": 1e-05,
1028
+ "loss": 0.9023,
1029
+ "step": 170
1030
+ },
1031
+ {
1032
+ "epoch": 2.57,
1033
+ "learning_rate": 1e-05,
1034
+ "loss": 0.9691,
1035
+ "step": 171
1036
+ },
1037
+ {
1038
+ "epoch": 2.59,
1039
+ "learning_rate": 1e-05,
1040
+ "loss": 0.9405,
1041
+ "step": 172
1042
+ },
1043
+ {
1044
+ "epoch": 2.6,
1045
+ "learning_rate": 1e-05,
1046
+ "loss": 0.851,
1047
+ "step": 173
1048
+ },
1049
+ {
1050
+ "epoch": 2.62,
1051
+ "learning_rate": 1e-05,
1052
+ "loss": 0.7875,
1053
+ "step": 174
1054
+ },
1055
+ {
1056
+ "epoch": 2.63,
1057
+ "learning_rate": 1e-05,
1058
+ "loss": 1.0168,
1059
+ "step": 175
1060
+ },
1061
+ {
1062
+ "epoch": 2.65,
1063
+ "learning_rate": 1e-05,
1064
+ "loss": 0.7197,
1065
+ "step": 176
1066
+ },
1067
+ {
1068
+ "epoch": 2.66,
1069
+ "learning_rate": 1e-05,
1070
+ "loss": 0.6833,
1071
+ "step": 177
1072
+ },
1073
+ {
1074
+ "epoch": 2.68,
1075
+ "learning_rate": 1e-05,
1076
+ "loss": 0.9674,
1077
+ "step": 178
1078
+ },
1079
+ {
1080
+ "epoch": 2.69,
1081
+ "learning_rate": 1e-05,
1082
+ "loss": 0.6438,
1083
+ "step": 179
1084
+ },
1085
+ {
1086
+ "epoch": 2.71,
1087
+ "learning_rate": 1e-05,
1088
+ "loss": 0.82,
1089
+ "step": 180
1090
+ },
1091
+ {
1092
+ "epoch": 2.72,
1093
+ "learning_rate": 1e-05,
1094
+ "loss": 0.9368,
1095
+ "step": 181
1096
+ },
1097
+ {
1098
+ "epoch": 2.74,
1099
+ "learning_rate": 1e-05,
1100
+ "loss": 0.9289,
1101
+ "step": 182
1102
+ },
1103
+ {
1104
+ "epoch": 2.75,
1105
+ "learning_rate": 1e-05,
1106
+ "loss": 0.6869,
1107
+ "step": 183
1108
+ },
1109
+ {
1110
+ "epoch": 2.77,
1111
+ "learning_rate": 1e-05,
1112
+ "loss": 0.7579,
1113
+ "step": 184
1114
+ },
1115
+ {
1116
+ "epoch": 2.78,
1117
+ "learning_rate": 1e-05,
1118
+ "loss": 0.6716,
1119
+ "step": 185
1120
+ },
1121
+ {
1122
+ "epoch": 2.8,
1123
+ "learning_rate": 1e-05,
1124
+ "loss": 0.6981,
1125
+ "step": 186
1126
+ },
1127
+ {
1128
+ "epoch": 2.81,
1129
+ "learning_rate": 1e-05,
1130
+ "loss": 0.6319,
1131
+ "step": 187
1132
+ },
1133
+ {
1134
+ "epoch": 2.83,
1135
+ "learning_rate": 1e-05,
1136
+ "loss": 0.659,
1137
+ "step": 188
1138
+ },
1139
+ {
1140
+ "epoch": 2.84,
1141
+ "learning_rate": 1e-05,
1142
+ "loss": 0.7576,
1143
+ "step": 189
1144
+ },
1145
+ {
1146
+ "epoch": 2.86,
1147
+ "learning_rate": 1e-05,
1148
+ "loss": 0.5602,
1149
+ "step": 190
1150
+ },
1151
+ {
1152
+ "epoch": 2.87,
1153
+ "learning_rate": 1e-05,
1154
+ "loss": 0.5778,
1155
+ "step": 191
1156
+ },
1157
+ {
1158
+ "epoch": 2.89,
1159
+ "learning_rate": 1e-05,
1160
+ "loss": 0.8159,
1161
+ "step": 192
1162
+ },
1163
+ {
1164
+ "epoch": 2.9,
1165
+ "learning_rate": 1e-05,
1166
+ "loss": 0.6415,
1167
+ "step": 193
1168
+ },
1169
+ {
1170
+ "epoch": 2.92,
1171
+ "learning_rate": 1e-05,
1172
+ "loss": 0.7226,
1173
+ "step": 194
1174
+ },
1175
+ {
1176
+ "epoch": 2.93,
1177
+ "learning_rate": 1e-05,
1178
+ "loss": 0.7825,
1179
+ "step": 195
1180
+ },
1181
+ {
1182
+ "epoch": 2.95,
1183
+ "learning_rate": 1e-05,
1184
+ "loss": 0.6911,
1185
+ "step": 196
1186
+ },
1187
+ {
1188
+ "epoch": 2.96,
1189
+ "learning_rate": 1e-05,
1190
+ "loss": 0.7701,
1191
+ "step": 197
1192
+ },
1193
+ {
1194
+ "epoch": 2.98,
1195
+ "learning_rate": 1e-05,
1196
+ "loss": 0.6469,
1197
+ "step": 198
1198
+ },
1199
+ {
1200
+ "epoch": 2.99,
1201
+ "learning_rate": 1e-05,
1202
+ "loss": 0.7353,
1203
+ "step": 199
1204
+ },
1205
+ {
1206
+ "epoch": 3.01,
1207
+ "learning_rate": 1e-05,
1208
+ "loss": 0.7989,
1209
+ "step": 200
1210
+ },
1211
+ {
1212
+ "epoch": 3.02,
1213
+ "learning_rate": 1e-05,
1214
+ "loss": 0.6068,
1215
+ "step": 201
1216
+ },
1217
+ {
1218
+ "epoch": 3.04,
1219
+ "learning_rate": 1e-05,
1220
+ "loss": 0.6215,
1221
+ "step": 202
1222
+ },
1223
+ {
1224
+ "epoch": 3.05,
1225
+ "learning_rate": 1e-05,
1226
+ "loss": 0.6768,
1227
+ "step": 203
1228
+ },
1229
+ {
1230
+ "epoch": 3.07,
1231
+ "learning_rate": 1e-05,
1232
+ "loss": 0.4917,
1233
+ "step": 204
1234
+ },
1235
+ {
1236
+ "epoch": 3.08,
1237
+ "learning_rate": 1e-05,
1238
+ "loss": 0.6764,
1239
+ "step": 205
1240
+ },
1241
+ {
1242
+ "epoch": 3.1,
1243
+ "learning_rate": 1e-05,
1244
+ "loss": 0.727,
1245
+ "step": 206
1246
+ },
1247
+ {
1248
+ "epoch": 3.11,
1249
+ "learning_rate": 1e-05,
1250
+ "loss": 0.5708,
1251
+ "step": 207
1252
+ },
1253
+ {
1254
+ "epoch": 3.13,
1255
+ "learning_rate": 1e-05,
1256
+ "loss": 0.4929,
1257
+ "step": 208
1258
+ },
1259
+ {
1260
+ "epoch": 3.14,
1261
+ "learning_rate": 1e-05,
1262
+ "loss": 0.6027,
1263
+ "step": 209
1264
+ },
1265
+ {
1266
+ "epoch": 3.16,
1267
+ "learning_rate": 1e-05,
1268
+ "loss": 0.4757,
1269
+ "step": 210
1270
+ },
1271
+ {
1272
+ "epoch": 3.17,
1273
+ "learning_rate": 1e-05,
1274
+ "loss": 0.5414,
1275
+ "step": 211
1276
+ },
1277
+ {
1278
+ "epoch": 3.19,
1279
+ "learning_rate": 1e-05,
1280
+ "loss": 0.5502,
1281
+ "step": 212
1282
+ },
1283
+ {
1284
+ "epoch": 3.2,
1285
+ "learning_rate": 1e-05,
1286
+ "loss": 0.6625,
1287
+ "step": 213
1288
+ },
1289
+ {
1290
+ "epoch": 3.22,
1291
+ "learning_rate": 1e-05,
1292
+ "loss": 0.4143,
1293
+ "step": 214
1294
+ },
1295
+ {
1296
+ "epoch": 3.23,
1297
+ "learning_rate": 1e-05,
1298
+ "loss": 0.3563,
1299
+ "step": 215
1300
+ },
1301
+ {
1302
+ "epoch": 3.25,
1303
+ "learning_rate": 1e-05,
1304
+ "loss": 0.5016,
1305
+ "step": 216
1306
+ },
1307
+ {
1308
+ "epoch": 3.26,
1309
+ "learning_rate": 1e-05,
1310
+ "loss": 0.5261,
1311
+ "step": 217
1312
+ },
1313
+ {
1314
+ "epoch": 3.28,
1315
+ "learning_rate": 1e-05,
1316
+ "loss": 0.4548,
1317
+ "step": 218
1318
+ },
1319
+ {
1320
+ "epoch": 3.29,
1321
+ "learning_rate": 1e-05,
1322
+ "loss": 0.5206,
1323
+ "step": 219
1324
+ },
1325
+ {
1326
+ "epoch": 3.31,
1327
+ "learning_rate": 1e-05,
1328
+ "loss": 0.4218,
1329
+ "step": 220
1330
+ },
1331
+ {
1332
+ "epoch": 3.32,
1333
+ "learning_rate": 1e-05,
1334
+ "loss": 0.5183,
1335
+ "step": 221
1336
+ },
1337
+ {
1338
+ "epoch": 3.34,
1339
+ "learning_rate": 1e-05,
1340
+ "loss": 0.5362,
1341
+ "step": 222
1342
+ },
1343
+ {
1344
+ "epoch": 3.35,
1345
+ "learning_rate": 1e-05,
1346
+ "loss": 0.4651,
1347
+ "step": 223
1348
+ },
1349
+ {
1350
+ "epoch": 3.37,
1351
+ "learning_rate": 1e-05,
1352
+ "loss": 0.4265,
1353
+ "step": 224
1354
+ },
1355
+ {
1356
+ "epoch": 3.38,
1357
+ "learning_rate": 1e-05,
1358
+ "loss": 0.4581,
1359
+ "step": 225
1360
+ },
1361
+ {
1362
+ "epoch": 3.4,
1363
+ "learning_rate": 1e-05,
1364
+ "loss": 0.5511,
1365
+ "step": 226
1366
+ },
1367
+ {
1368
+ "epoch": 3.41,
1369
+ "learning_rate": 1e-05,
1370
+ "loss": 0.4235,
1371
+ "step": 227
1372
+ },
1373
+ {
1374
+ "epoch": 3.43,
1375
+ "learning_rate": 1e-05,
1376
+ "loss": 0.5037,
1377
+ "step": 228
1378
+ },
1379
+ {
1380
+ "epoch": 3.44,
1381
+ "learning_rate": 1e-05,
1382
+ "loss": 0.4882,
1383
+ "step": 229
1384
+ },
1385
+ {
1386
+ "epoch": 3.46,
1387
+ "learning_rate": 1e-05,
1388
+ "loss": 0.4317,
1389
+ "step": 230
1390
+ },
1391
+ {
1392
+ "epoch": 3.47,
1393
+ "learning_rate": 1e-05,
1394
+ "loss": 0.3565,
1395
+ "step": 231
1396
+ },
1397
+ {
1398
+ "epoch": 3.49,
1399
+ "learning_rate": 1e-05,
1400
+ "loss": 0.4123,
1401
+ "step": 232
1402
+ },
1403
+ {
1404
+ "epoch": 3.5,
1405
+ "learning_rate": 1e-05,
1406
+ "loss": 0.7997,
1407
+ "step": 233
1408
+ },
1409
+ {
1410
+ "epoch": 3.52,
1411
+ "learning_rate": 1e-05,
1412
+ "loss": 0.5753,
1413
+ "step": 234
1414
+ },
1415
+ {
1416
+ "epoch": 3.53,
1417
+ "learning_rate": 1e-05,
1418
+ "loss": 0.5398,
1419
+ "step": 235
1420
+ },
1421
+ {
1422
+ "epoch": 3.55,
1423
+ "learning_rate": 1e-05,
1424
+ "loss": 0.5202,
1425
+ "step": 236
1426
+ },
1427
+ {
1428
+ "epoch": 3.56,
1429
+ "learning_rate": 1e-05,
1430
+ "loss": 0.4584,
1431
+ "step": 237
1432
+ },
1433
+ {
1434
+ "epoch": 3.58,
1435
+ "learning_rate": 1e-05,
1436
+ "loss": 0.6103,
1437
+ "step": 238
1438
+ },
1439
+ {
1440
+ "epoch": 3.59,
1441
+ "learning_rate": 1e-05,
1442
+ "loss": 0.4005,
1443
+ "step": 239
1444
+ },
1445
+ {
1446
+ "epoch": 3.61,
1447
+ "learning_rate": 1e-05,
1448
+ "loss": 0.435,
1449
+ "step": 240
1450
+ },
1451
+ {
1452
+ "epoch": 3.62,
1453
+ "learning_rate": 1e-05,
1454
+ "loss": 0.4691,
1455
+ "step": 241
1456
+ },
1457
+ {
1458
+ "epoch": 3.64,
1459
+ "learning_rate": 1e-05,
1460
+ "loss": 0.4488,
1461
+ "step": 242
1462
+ },
1463
+ {
1464
+ "epoch": 3.65,
1465
+ "learning_rate": 1e-05,
1466
+ "loss": 0.3904,
1467
+ "step": 243
1468
+ },
1469
+ {
1470
+ "epoch": 3.67,
1471
+ "learning_rate": 1e-05,
1472
+ "loss": 0.4746,
1473
+ "step": 244
1474
+ },
1475
+ {
1476
+ "epoch": 3.68,
1477
+ "learning_rate": 1e-05,
1478
+ "loss": 0.4092,
1479
+ "step": 245
1480
+ },
1481
+ {
1482
+ "epoch": 3.7,
1483
+ "learning_rate": 1e-05,
1484
+ "loss": 0.3671,
1485
+ "step": 246
1486
+ },
1487
+ {
1488
+ "epoch": 3.71,
1489
+ "learning_rate": 1e-05,
1490
+ "loss": 0.391,
1491
+ "step": 247
1492
+ },
1493
+ {
1494
+ "epoch": 3.73,
1495
+ "learning_rate": 1e-05,
1496
+ "loss": 0.5338,
1497
+ "step": 248
1498
+ },
1499
+ {
1500
+ "epoch": 3.74,
1501
+ "learning_rate": 1e-05,
1502
+ "loss": 0.3056,
1503
+ "step": 249
1504
+ },
1505
+ {
1506
+ "epoch": 3.76,
1507
+ "learning_rate": 1e-05,
1508
+ "loss": 0.3119,
1509
+ "step": 250
1510
+ },
1511
+ {
1512
+ "epoch": 3.77,
1513
+ "learning_rate": 1e-05,
1514
+ "loss": 0.5096,
1515
+ "step": 251
1516
+ },
1517
+ {
1518
+ "epoch": 3.79,
1519
+ "learning_rate": 1e-05,
1520
+ "loss": 0.3941,
1521
+ "step": 252
1522
+ },
1523
+ {
1524
+ "epoch": 3.8,
1525
+ "learning_rate": 1e-05,
1526
+ "loss": 0.4121,
1527
+ "step": 253
1528
+ },
1529
+ {
1530
+ "epoch": 3.82,
1531
+ "learning_rate": 1e-05,
1532
+ "loss": 0.4883,
1533
+ "step": 254
1534
+ },
1535
+ {
1536
+ "epoch": 3.83,
1537
+ "learning_rate": 1e-05,
1538
+ "loss": 0.4144,
1539
+ "step": 255
1540
+ },
1541
+ {
1542
+ "epoch": 3.85,
1543
+ "learning_rate": 1e-05,
1544
+ "loss": 0.3773,
1545
+ "step": 256
1546
+ },
1547
+ {
1548
+ "epoch": 3.86,
1549
+ "learning_rate": 1e-05,
1550
+ "loss": 0.2575,
1551
+ "step": 257
1552
+ },
1553
+ {
1554
+ "epoch": 3.88,
1555
+ "learning_rate": 1e-05,
1556
+ "loss": 0.412,
1557
+ "step": 258
1558
+ },
1559
+ {
1560
+ "epoch": 3.89,
1561
+ "learning_rate": 1e-05,
1562
+ "loss": 0.3506,
1563
+ "step": 259
1564
+ },
1565
+ {
1566
+ "epoch": 3.91,
1567
+ "learning_rate": 1e-05,
1568
+ "loss": 0.3076,
1569
+ "step": 260
1570
+ },
1571
+ {
1572
+ "epoch": 3.92,
1573
+ "learning_rate": 1e-05,
1574
+ "loss": 0.4445,
1575
+ "step": 261
1576
+ },
1577
+ {
1578
+ "epoch": 3.94,
1579
+ "learning_rate": 1e-05,
1580
+ "loss": 0.3698,
1581
+ "step": 262
1582
+ },
1583
+ {
1584
+ "epoch": 3.95,
1585
+ "learning_rate": 1e-05,
1586
+ "loss": 0.3619,
1587
+ "step": 263
1588
+ },
1589
+ {
1590
+ "epoch": 3.97,
1591
+ "learning_rate": 1e-05,
1592
+ "loss": 0.3515,
1593
+ "step": 264
1594
+ },
1595
+ {
1596
+ "epoch": 3.98,
1597
+ "learning_rate": 1e-05,
1598
+ "loss": 0.3284,
1599
+ "step": 265
1600
+ },
1601
+ {
1602
+ "epoch": 4.0,
1603
+ "learning_rate": 1e-05,
1604
+ "loss": 0.4578,
1605
+ "step": 266
1606
+ },
1607
+ {
1608
+ "epoch": 4.02,
1609
+ "learning_rate": 1e-05,
1610
+ "loss": 0.3942,
1611
+ "step": 267
1612
+ },
1613
+ {
1614
+ "epoch": 4.03,
1615
+ "learning_rate": 1e-05,
1616
+ "loss": 0.3376,
1617
+ "step": 268
1618
+ },
1619
+ {
1620
+ "epoch": 4.05,
1621
+ "learning_rate": 1e-05,
1622
+ "loss": 0.337,
1623
+ "step": 269
1624
+ },
1625
+ {
1626
+ "epoch": 4.06,
1627
+ "learning_rate": 1e-05,
1628
+ "loss": 0.2748,
1629
+ "step": 270
1630
+ },
1631
+ {
1632
+ "epoch": 4.08,
1633
+ "learning_rate": 1e-05,
1634
+ "loss": 0.3154,
1635
+ "step": 271
1636
+ },
1637
+ {
1638
+ "epoch": 4.09,
1639
+ "learning_rate": 1e-05,
1640
+ "loss": 0.3655,
1641
+ "step": 272
1642
+ },
1643
+ {
1644
+ "epoch": 4.11,
1645
+ "learning_rate": 1e-05,
1646
+ "loss": 0.3308,
1647
+ "step": 273
1648
+ },
1649
+ {
1650
+ "epoch": 4.12,
1651
+ "learning_rate": 1e-05,
1652
+ "loss": 0.2619,
1653
+ "step": 274
1654
+ },
1655
+ {
1656
+ "epoch": 4.14,
1657
+ "learning_rate": 1e-05,
1658
+ "loss": 0.2412,
1659
+ "step": 275
1660
+ },
1661
+ {
1662
+ "epoch": 4.15,
1663
+ "learning_rate": 1e-05,
1664
+ "loss": 0.2608,
1665
+ "step": 276
1666
+ },
1667
+ {
1668
+ "epoch": 4.17,
1669
+ "learning_rate": 1e-05,
1670
+ "loss": 0.2722,
1671
+ "step": 277
1672
+ },
1673
+ {
1674
+ "epoch": 4.18,
1675
+ "learning_rate": 1e-05,
1676
+ "loss": 0.2229,
1677
+ "step": 278
1678
+ },
1679
+ {
1680
+ "epoch": 4.2,
1681
+ "learning_rate": 1e-05,
1682
+ "loss": 0.3556,
1683
+ "step": 279
1684
+ },
1685
+ {
1686
+ "epoch": 4.21,
1687
+ "learning_rate": 1e-05,
1688
+ "loss": 0.2753,
1689
+ "step": 280
1690
+ },
1691
+ {
1692
+ "epoch": 4.23,
1693
+ "learning_rate": 1e-05,
1694
+ "loss": 0.1647,
1695
+ "step": 281
1696
+ },
1697
+ {
1698
+ "epoch": 4.24,
1699
+ "learning_rate": 1e-05,
1700
+ "loss": 0.181,
1701
+ "step": 282
1702
+ },
1703
+ {
1704
+ "epoch": 4.26,
1705
+ "learning_rate": 1e-05,
1706
+ "loss": 0.2137,
1707
+ "step": 283
1708
+ },
1709
+ {
1710
+ "epoch": 4.27,
1711
+ "learning_rate": 1e-05,
1712
+ "loss": 0.2369,
1713
+ "step": 284
1714
+ },
1715
+ {
1716
+ "epoch": 4.29,
1717
+ "learning_rate": 1e-05,
1718
+ "loss": 0.1902,
1719
+ "step": 285
1720
+ },
1721
+ {
1722
+ "epoch": 4.3,
1723
+ "learning_rate": 1e-05,
1724
+ "loss": 0.2406,
1725
+ "step": 286
1726
+ },
1727
+ {
1728
+ "epoch": 4.32,
1729
+ "learning_rate": 1e-05,
1730
+ "loss": 0.1385,
1731
+ "step": 287
1732
+ },
1733
+ {
1734
+ "epoch": 4.33,
1735
+ "learning_rate": 1e-05,
1736
+ "loss": 0.2464,
1737
+ "step": 288
1738
+ },
1739
+ {
1740
+ "epoch": 4.35,
1741
+ "learning_rate": 1e-05,
1742
+ "loss": 0.3149,
1743
+ "step": 289
1744
+ },
1745
+ {
1746
+ "epoch": 4.36,
1747
+ "learning_rate": 1e-05,
1748
+ "loss": 0.1562,
1749
+ "step": 290
1750
+ },
1751
+ {
1752
+ "epoch": 4.38,
1753
+ "learning_rate": 1e-05,
1754
+ "loss": 0.2204,
1755
+ "step": 291
1756
+ },
1757
+ {
1758
+ "epoch": 4.39,
1759
+ "learning_rate": 1e-05,
1760
+ "loss": 0.2969,
1761
+ "step": 292
1762
+ },
1763
+ {
1764
+ "epoch": 4.41,
1765
+ "learning_rate": 1e-05,
1766
+ "loss": 0.2168,
1767
+ "step": 293
1768
+ },
1769
+ {
1770
+ "epoch": 4.42,
1771
+ "learning_rate": 1e-05,
1772
+ "loss": 0.2189,
1773
+ "step": 294
1774
+ },
1775
+ {
1776
+ "epoch": 4.44,
1777
+ "learning_rate": 1e-05,
1778
+ "loss": 0.254,
1779
+ "step": 295
1780
+ },
1781
+ {
1782
+ "epoch": 4.45,
1783
+ "learning_rate": 1e-05,
1784
+ "loss": 0.1854,
1785
+ "step": 296
1786
+ },
1787
+ {
1788
+ "epoch": 4.47,
1789
+ "learning_rate": 1e-05,
1790
+ "loss": 0.182,
1791
+ "step": 297
1792
+ },
1793
+ {
1794
+ "epoch": 4.48,
1795
+ "learning_rate": 1e-05,
1796
+ "loss": 0.1822,
1797
+ "step": 298
1798
+ },
1799
+ {
1800
+ "epoch": 4.5,
1801
+ "learning_rate": 1e-05,
1802
+ "loss": 0.3223,
1803
+ "step": 299
1804
+ },
1805
+ {
1806
+ "epoch": 4.51,
1807
+ "learning_rate": 1e-05,
1808
+ "loss": 0.409,
1809
+ "step": 300
1810
+ },
1811
+ {
1812
+ "epoch": 4.53,
1813
+ "learning_rate": 1e-05,
1814
+ "loss": 0.1711,
1815
+ "step": 301
1816
+ },
1817
+ {
1818
+ "epoch": 4.54,
1819
+ "learning_rate": 1e-05,
1820
+ "loss": 0.2508,
1821
+ "step": 302
1822
+ },
1823
+ {
1824
+ "epoch": 4.56,
1825
+ "learning_rate": 1e-05,
1826
+ "loss": 0.2287,
1827
+ "step": 303
1828
+ },
1829
+ {
1830
+ "epoch": 4.57,
1831
+ "learning_rate": 1e-05,
1832
+ "loss": 0.2624,
1833
+ "step": 304
1834
+ },
1835
+ {
1836
+ "epoch": 4.59,
1837
+ "learning_rate": 1e-05,
1838
+ "loss": 0.2577,
1839
+ "step": 305
1840
+ },
1841
+ {
1842
+ "epoch": 4.6,
1843
+ "learning_rate": 1e-05,
1844
+ "loss": 0.2291,
1845
+ "step": 306
1846
+ },
1847
+ {
1848
+ "epoch": 4.62,
1849
+ "learning_rate": 1e-05,
1850
+ "loss": 0.2088,
1851
+ "step": 307
1852
+ },
1853
+ {
1854
+ "epoch": 4.63,
1855
+ "learning_rate": 1e-05,
1856
+ "loss": 0.282,
1857
+ "step": 308
1858
+ },
1859
+ {
1860
+ "epoch": 4.65,
1861
+ "learning_rate": 1e-05,
1862
+ "loss": 0.2005,
1863
+ "step": 309
1864
+ },
1865
+ {
1866
+ "epoch": 4.66,
1867
+ "learning_rate": 1e-05,
1868
+ "loss": 0.1633,
1869
+ "step": 310
1870
+ },
1871
+ {
1872
+ "epoch": 4.68,
1873
+ "learning_rate": 1e-05,
1874
+ "loss": 0.2802,
1875
+ "step": 311
1876
+ },
1877
+ {
1878
+ "epoch": 4.69,
1879
+ "learning_rate": 1e-05,
1880
+ "loss": 0.1332,
1881
+ "step": 312
1882
+ },
1883
+ {
1884
+ "epoch": 4.71,
1885
+ "learning_rate": 1e-05,
1886
+ "loss": 0.2053,
1887
+ "step": 313
1888
+ },
1889
+ {
1890
+ "epoch": 4.72,
1891
+ "learning_rate": 1e-05,
1892
+ "loss": 0.2388,
1893
+ "step": 314
1894
+ },
1895
+ {
1896
+ "epoch": 4.74,
1897
+ "learning_rate": 1e-05,
1898
+ "loss": 0.2342,
1899
+ "step": 315
1900
+ },
1901
+ {
1902
+ "epoch": 4.75,
1903
+ "learning_rate": 1e-05,
1904
+ "loss": 0.1563,
1905
+ "step": 316
1906
+ },
1907
+ {
1908
+ "epoch": 4.77,
1909
+ "learning_rate": 1e-05,
1910
+ "loss": 0.2479,
1911
+ "step": 317
1912
+ },
1913
+ {
1914
+ "epoch": 4.78,
1915
+ "learning_rate": 1e-05,
1916
+ "loss": 0.2365,
1917
+ "step": 318
1918
+ },
1919
+ {
1920
+ "epoch": 4.8,
1921
+ "learning_rate": 1e-05,
1922
+ "loss": 0.2418,
1923
+ "step": 319
1924
+ },
1925
+ {
1926
+ "epoch": 4.81,
1927
+ "learning_rate": 1e-05,
1928
+ "loss": 0.2198,
1929
+ "step": 320
1930
+ },
1931
+ {
1932
+ "epoch": 4.83,
1933
+ "learning_rate": 1e-05,
1934
+ "loss": 0.193,
1935
+ "step": 321
1936
+ },
1937
+ {
1938
+ "epoch": 4.84,
1939
+ "learning_rate": 1e-05,
1940
+ "loss": 0.2195,
1941
+ "step": 322
1942
+ },
1943
+ {
1944
+ "epoch": 4.86,
1945
+ "learning_rate": 1e-05,
1946
+ "loss": 0.1273,
1947
+ "step": 323
1948
+ },
1949
+ {
1950
+ "epoch": 4.87,
1951
+ "learning_rate": 1e-05,
1952
+ "loss": 0.1448,
1953
+ "step": 324
1954
+ },
1955
+ {
1956
+ "epoch": 4.89,
1957
+ "learning_rate": 1e-05,
1958
+ "loss": 0.1977,
1959
+ "step": 325
1960
+ },
1961
+ {
1962
+ "epoch": 4.9,
1963
+ "learning_rate": 1e-05,
1964
+ "loss": 0.149,
1965
+ "step": 326
1966
+ },
1967
+ {
1968
+ "epoch": 4.92,
1969
+ "learning_rate": 1e-05,
1970
+ "loss": 0.2235,
1971
+ "step": 327
1972
+ },
1973
+ {
1974
+ "epoch": 4.93,
1975
+ "learning_rate": 1e-05,
1976
+ "loss": 0.2269,
1977
+ "step": 328
1978
+ },
1979
+ {
1980
+ "epoch": 4.95,
1981
+ "learning_rate": 1e-05,
1982
+ "loss": 0.1771,
1983
+ "step": 329
1984
+ },
1985
+ {
1986
+ "epoch": 4.96,
1987
+ "learning_rate": 1e-05,
1988
+ "loss": 0.2369,
1989
+ "step": 330
1990
+ },
1991
+ {
1992
+ "epoch": 4.96,
1993
+ "step": 330,
1994
+ "total_flos": 8037448286208.0,
1995
+ "train_loss": 1.0460747798283896,
1996
+ "train_runtime": 22298.7817,
1997
+ "train_samples_per_second": 0.477,
1998
+ "train_steps_per_second": 0.015
1999
+ }
2000
+ ],
2001
+ "logging_steps": 1.0,
2002
+ "max_steps": 330,
2003
+ "num_train_epochs": 5,
2004
+ "save_steps": 1000,
2005
+ "total_flos": 8037448286208.0,
2006
+ "trial_name": null,
2007
+ "trial_params": null
2008
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da691b29292887570af5c8c71617ad6e583c8ad685d020300584667de9031a4d
3
+ size 6776