Guanzheng commited on
Commit
86e45fc
·
verified ·
1 Parent(s): fdfd442

Update configuration_clex.py

Browse files
Files changed (1) hide show
  1. configuration_clex.py +194 -0
configuration_clex.py CHANGED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Hugging Face's logo
2
+ Hugging Face
3
+ Search models, datasets, users...
4
+ Models
5
+ Datasets
6
+ Spaces
7
+ Posts
8
+ Docs
9
+ Pricing
10
+
11
+
12
+
13
+
14
+ DAMO-NLP-SG
15
+ /
16
+ CLEX-7B-16K
17
+
18
+ like
19
+ 3
20
+ Text Generation
21
+ Transformers
22
+ PyTorch
23
+ English
24
+ llama
25
+ custom_code
26
+ Inference Endpoints
27
+ text-generation-inference
28
+
29
+ arxiv:
30
+ 2310.16450
31
+
32
+ License:
33
+ mit
34
+ Model card
35
+ Files and versions
36
+ Community
37
+ Settings
38
+ CLEX-7B-16K
39
+ /
40
+ configuration_clex.py
41
+ Guanzheng's picture
42
+ Guanzheng
43
+ Create configuration_clex.py
44
+ 71d09d9
45
+ VERIFIED
46
+ about 1 hour ago
47
+ raw
48
+ history
49
+ blame
50
+ edit
51
+ delete
52
+ No virus
53
+ 7.84 kB
54
+ # coding=utf-8
55
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
56
+ #
57
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
58
+ # and OPT implementations in this library. It has been modified from its
59
+ # original forms to accommodate minor architectural differences compared
60
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
61
+ #
62
+ # Licensed under the Apache License, Version 2.0 (the "License");
63
+ # you may not use this file except in compliance with the License.
64
+ # You may obtain a copy of the License at
65
+ #
66
+ # http://www.apache.org/licenses/LICENSE-2.0
67
+ #
68
+ # Unless required by applicable law or agreed to in writing, software
69
+ # distributed under the License is distributed on an "AS IS" BASIS,
70
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
71
+ # See the License for the specific language governing permissions and
72
+ # limitations under the License.
73
+ """ LLaMA model configuration"""
74
+
75
+ from transformers.configuration_utils import PretrainedConfig
76
+ from transformers.utils import logging
77
+ from transformers import LlamaConfig
78
+
79
+
80
+ logger = logging.get_logger(__name__)
81
+
82
+ LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
83
+
84
+
85
+ class CLEXLlamaConfig(LlamaConfig):
86
+ r"""
87
+ This is the configuration class to store the configuration of a [`LlamaModel`]. It is used to instantiate an LLaMA
88
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
89
+ defaults will yield a similar configuration to that of the LLaMA-7B.
90
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
91
+ documentation from [`PretrainedConfig`] for more information.
92
+ Args:
93
+ vocab_size (`int`, *optional*, defaults to 32000):
94
+ Vocabulary size of the LLaMA model. Defines the number of different tokens that can be represented by the
95
+ `inputs_ids` passed when calling [`LlamaModel`]
96
+ hidden_size (`int`, *optional*, defaults to 4096):
97
+ Dimension of the hidden representations.
98
+ intermediate_size (`int`, *optional*, defaults to 11008):
99
+ Dimension of the MLP representations.
100
+ num_hidden_layers (`int`, *optional*, defaults to 32):
101
+ Number of hidden layers in the Transformer encoder.
102
+ num_attention_heads (`int`, *optional*, defaults to 32):
103
+ Number of attention heads for each attention layer in the Transformer encoder.
104
+ num_key_value_heads (`int`, *optional*):
105
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
106
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
107
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
108
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
109
+ by meanpooling all the original heads within that group. For more details checkout [this
110
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
111
+ `num_attention_heads`.
112
+ pretraining_tp (`int`, *optional*, defaults to `1`):
113
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
114
+ document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
115
+ necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
116
+ issue](https://github.com/pytorch/pytorch/issues/76232).
117
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
118
+ The non-linear activation function (function or string) in the decoder.
119
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
120
+ The maximum sequence length that this model might ever be used with. Typically set this to something large
121
+ just in case (e.g., 512 or 1024 or 2048).
122
+ initializer_range (`float`, *optional*, defaults to 0.02):
123
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
124
+ rms_norm_eps (`float`, *optional*, defaults to 1e-12):
125
+ The epsilon used by the rms normalization layers.
126
+ use_cache (`bool`, *optional*, defaults to `True`):
127
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
128
+ relevant if `config.is_decoder=True`.
129
+ tie_word_embeddings(`bool`, *optional*, defaults to `False`):
130
+ Whether to tie weight embeddings
131
+ rope_scaling (`Dict`, *optional*):
132
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports three scaling
133
+ strategies: linear and dynamic. Their scaling factor must be an float greater than 1. The expected format
134
+ is `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
135
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
136
+ these scaling strategies behave:
137
+ https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
138
+ experimental feature, subject to breaking API changes in future versions.
139
+ Example:
140
+ ```python
141
+ >>> from transformers import LlamaModel, LlamaConfig
142
+ >>> # Initializing a LLaMA llama-7b style configuration
143
+ >>> configuration = LlamaConfig()
144
+ >>> # Initializing a model from the llama-7b style configuration
145
+ >>> model = LlamaModel(configuration)
146
+ >>> # Accessing the model configuration
147
+ >>> configuration = model.config
148
+ ```"""
149
+ model_type = "llama"
150
+ keys_to_ignore_at_inference = ["past_key_values"]
151
+
152
+ def __init__(
153
+ self,
154
+ rope_scaling=None,
155
+ use_flashattn=True,
156
+ log_scale=True,
157
+ **kwargs,
158
+ ):
159
+ super().__init__(
160
+ **kwargs,
161
+ )
162
+ self.use_flashattn = use_flashattn
163
+ self.log_scale = log_scale
164
+ self.rope_theta = 10000
165
+ self.max_position_embeddings = 4096
166
+ self.data_length = 4096
167
+ self.rope_scaling = rope_scaling
168
+ self._rope_scaling_validation()
169
+
170
+
171
+ def _rope_scaling_validation(self):
172
+ """
173
+ Validate the `rope_scaling` configuration.
174
+ """
175
+ if self.rope_scaling is None:
176
+ return
177
+
178
+ # if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
179
+ # raise ValueError(
180
+ # "`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, "
181
+ # f"got {self.rope_scaling}"
182
+ # )
183
+ rope_scaling_type = self.rope_scaling.get("type", None)
184
+ rope_scaling_max_factor = self.rope_scaling.get("max_factor", None)
185
+ rope_scaling_param_factor = self.rope_scaling.get("param_factor", None)
186
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic", "clex"]:
187
+ raise ValueError(
188
+ f"`rope_scaling`'s name field must be one of ['linear', 'dynamic', 'clex'], got {rope_scaling_type}"
189
+ )
190
+ # if rope_scaling_max_factor is None or not isinstance(rope_scaling_max_factor, float) or rope_scaling_max_factor <= 1.0:
191
+ # raise ValueError(f"`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_max_factor}")
192
+ # if rope_scaling_param_factor is None or not isinstance(rope_scaling_param_factor, float) or rope_scaling_param_factor <= 1.0:
193
+ # raise ValueError(f"`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_param_factor}")
194
+