cognitivess commited on
Commit
1634cc3
1 Parent(s): a137844

Rename cognitivess_model/configuration_Cognitivess.py to cognitivess_model/configuration_cognitivess.py

Browse files
cognitivess_model/configuration_Cognitivess.py DELETED
@@ -1,186 +0,0 @@
1
- # coding=utf-8
2
- # Copyright 2022 Cognitivess and the HuggingFace Inc. team. All rights reserved.
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """Cognitivess model configuration"""
15
-
16
- from ...configuration_utils import PretrainedConfig
17
- from ...utils import logging
18
-
19
-
20
- logger = logging.get_logger(__name__)
21
-
22
-
23
- class CognitivessConfig(PretrainedConfig):
24
- r"""
25
- This is the configuration class to store the configuration of a [`CognitivessModel`]. It is used to instantiate an Cognitivess
26
- model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
27
- defaults will yield a similar configuration to that of the Cognitivess.
28
-
29
- Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
30
- documentation from [`PretrainedConfig`] for more information.
31
-
32
-
33
- Args:
34
- vocab_size (`int`, *optional*, defaults to 32000):
35
- Vocabulary size of the Cognitivess model. Defines the number of different tokens that can be represented by the
36
- `inputs_ids` passed when calling [`CognitivessModel`]
37
- hidden_size (`int`, *optional*, defaults to 4096):
38
- Dimension of the hidden representations.
39
- intermediate_size (`int`, *optional*, defaults to 11008):
40
- Dimension of the MLP representations.
41
- num_hidden_layers (`int`, *optional*, defaults to 32):
42
- Number of hidden layers in the Transformer decoder.
43
- num_attention_heads (`int`, *optional*, defaults to 32):
44
- Number of attention heads for each attention layer in the Transformer decoder.
45
- num_key_value_heads (`int`, *optional*):
46
- This is the number of key_value heads that should be used to implement Grouped Query Attention. If
47
- `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
48
- `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
49
- converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
50
- by meanpooling all the original heads within that group. For more details checkout [this
51
- paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
52
- `num_attention_heads`.
53
- hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
54
- The non-linear activation function (function or string) in the decoder.
55
- max_position_embeddings (`int`, *optional*, defaults to 2048):
56
- The maximum sequence length that this model might ever be used with. Cognitivess 1 supports up to 2048 tokens,
57
- Cognitivess 2 up to 4096, CodeCognitivess up to 16384.
58
- initializer_range (`float`, *optional*, defaults to 0.02):
59
- The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
60
- rms_norm_eps (`float`, *optional*, defaults to 1e-06):
61
- The epsilon used by the rms normalization layers.
62
- use_cache (`bool`, *optional*, defaults to `True`):
63
- Whether or not the model should return the last key/values attentions (not used by all models). Only
64
- relevant if `config.is_decoder=True`.
65
- pad_token_id (`int`, *optional*):
66
- Padding token id.
67
- bos_token_id (`int`, *optional*, defaults to 1):
68
- Beginning of stream token id.
69
- eos_token_id (`int`, *optional*, defaults to 2):
70
- End of stream token id.
71
- pretraining_tp (`int`, *optional*, defaults to 1):
72
- Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
73
- document](https://huggingface.co/docs/transformers/main/perf_train_gpu_many#tensor-parallelism) to understand more about it. This value is
74
- necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
75
- issue](https://github.com/pytorch/pytorch/issues/76232).
76
- tie_word_embeddings (`bool`, *optional*, defaults to `False`):
77
- Whether to tie weight embeddings
78
- rope_theta (`float`, *optional*, defaults to 10000.0):
79
- The base period of the RoPE embeddings.
80
- rope_scaling (`Dict`, *optional*):
81
- Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
82
- strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
83
- `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
84
- `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
85
- these scaling strategies behave:
86
- https://www.reddit.com/r/LocalCognitivess/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
87
- experimental feature, subject to breaking API changes in future versions.
88
- attention_bias (`bool`, *optional*, defaults to `False`):
89
- Whether to use a bias in the query, key, value and output projection layers during self-attention.
90
- attention_dropout (`float`, *optional*, defaults to 0.0):
91
- The dropout ratio for the attention probabilities.
92
- mlp_bias (`bool`, *optional*, defaults to `False`):
93
- Whether to use a bias in up_proj, down_proj and gate_proj layers in the MLP layers.
94
-
95
- ```python
96
- >>> from transformers import CognitivessModel, CognitivessConfig
97
-
98
- >>> # Initializing a Cognitivess Cognitivess style configuration
99
- >>> configuration = CognitivessConfig()
100
-
101
- >>> # Initializing a model from the Cognitivess style configuration
102
- >>> model = CognitivessModel(configuration)
103
-
104
- >>> # Accessing the model configuration
105
- >>> configuration = model.config
106
- ```"""
107
-
108
- model_type = "Cognitivess"
109
- keys_to_ignore_at_inference = ["past_key_values"]
110
-
111
- def __init__(
112
- self,
113
- vocab_size=128256,
114
- hidden_size=4096,
115
- intermediate_size=14336,
116
- num_hidden_layers=32,
117
- num_attention_heads=32,
118
- num_key_value_heads=8,
119
- hidden_act="silu",
120
- max_position_embeddings=8192,
121
- initializer_range=0.02,
122
- rms_norm_eps=1e-05,
123
- use_cache=True,
124
- pad_token_id=0,
125
- bos_token_id=128000,
126
- eos_token_id=128001,
127
- pretraining_tp=1,
128
- tie_word_embeddings=False,
129
- rope_theta=500000.0,
130
- rope_scaling=None,
131
- attention_bias=False,
132
- attention_dropout=0.0,
133
- mlp_bias=False,
134
- **kwargs,
135
- ):
136
- self.vocab_size = vocab_size
137
- self.max_position_embeddings = max_position_embeddings
138
- self.hidden_size = hidden_size
139
- self.intermediate_size = intermediate_size
140
- self.num_hidden_layers = num_hidden_layers
141
- self.num_attention_heads = num_attention_heads
142
-
143
- # for backward compatibility
144
- if num_key_value_heads is None:
145
- num_key_value_heads = num_attention_heads
146
-
147
- self.num_key_value_heads = num_key_value_heads
148
- self.hidden_act = hidden_act
149
- self.initializer_range = initializer_range
150
- self.rms_norm_eps = rms_norm_eps
151
- self.pretraining_tp = pretraining_tp
152
- self.use_cache = use_cache
153
- self.rope_theta = rope_theta
154
- self.rope_scaling = rope_scaling
155
- self._rope_scaling_validation()
156
- self.attention_bias = attention_bias
157
- self.attention_dropout = attention_dropout
158
- self.mlp_bias = mlp_bias
159
-
160
- super().__init__(
161
- pad_token_id=pad_token_id,
162
- bos_token_id=bos_token_id,
163
- eos_token_id=eos_token_id,
164
- tie_word_embeddings=tie_word_embeddings,
165
- **kwargs,
166
- )
167
-
168
- def _rope_scaling_validation(self):
169
- """
170
- Validate the `rope_scaling` configuration.
171
- """
172
- if self.rope_scaling is None:
173
- return
174
-
175
- if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
176
- raise ValueError(
177
- "`rope_scaling` must be a dictionary with two fields, `type` and `factor`, " f"got {self.rope_scaling}"
178
- )
179
- rope_scaling_type = self.rope_scaling.get("type", None)
180
- rope_scaling_factor = self.rope_scaling.get("factor", None)
181
- if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
182
- raise ValueError(
183
- f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
184
- )
185
- if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
186
- raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cognitivess_model/configuration_cognitivess.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+ class CognitivessConfig(PretrainedConfig):
4
+ model_type = "cognitivess"
5
+
6
+ def __init__(
7
+ self,
8
+ vocab_size=128256,
9
+ hidden_size=4096,
10
+ intermediate_size=14336,
11
+ num_hidden_layers=32,
12
+ num_attention_heads=32,
13
+ num_key_value_heads=8,
14
+ hidden_act="silu",
15
+ max_position_embeddings=8192,
16
+ initializer_range=0.02,
17
+ rms_norm_eps=1e-5,
18
+ use_cache=True,
19
+ pad_token_id=0,
20
+ bos_token_id=128000,
21
+ eos_token_id=128001,
22
+ tie_word_embeddings=False,
23
+ attention_dropout=0.0,
24
+ pretraining_tp=1,
25
+ rope_theta=500000.0,
26
+ **kwargs
27
+ ):
28
+ super().__init__(
29
+ vocab_size=vocab_size,
30
+ hidden_size=hidden_size,
31
+ intermediate_size=intermediate_size,
32
+ num_hidden_layers=num_hidden_layers,
33
+ num_attention_heads=num_attention_heads,
34
+ num_key_value_heads=num_key_value_heads,
35
+ hidden_act=hidden_act,
36
+ max_position_embeddings=max_position_embeddings,
37
+ initializer_range=initializer_range,
38
+ rms_norm_eps=rms_norm_eps,
39
+ use_cache=use_cache,
40
+ pad_token_id=pad_token_id,
41
+ bos_token_id=bos_token_id,
42
+ eos_token_id=eos_token_id,
43
+ tie_word_embeddings=tie_word_embeddings,
44
+ pretraining_tp=pretraining_tp,
45
+ rope_theta=rope_theta,
46
+ **kwargs
47
+ )
48
+ self.attention_dropout = attention_dropout