cognitivess
commited on
Commit
•
684cf6f
1
Parent(s):
0cfbce2
Update cognitivess_model/configuration_cognitivess.py
Browse files
cognitivess_model/configuration_cognitivess.py
CHANGED
@@ -1,33 +1,150 @@
|
|
1 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
from transformers import PretrainedConfig
|
4 |
|
5 |
class CognitivessConfig(PretrainedConfig):
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
self.hidden_size = hidden_size
|
|
|
15 |
self.num_hidden_layers = num_hidden_layers
|
16 |
self.num_attention_heads = num_attention_heads
|
17 |
-
self.
|
18 |
-
self.
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
self.pad_token_id = pad_token_id
|
25 |
-
self.attention_dropout = attention_dropout
|
26 |
-
self.attention_bias = attention_bias
|
27 |
-
self.tie_word_embeddings = tie_word_embeddings
|
28 |
-
self.mlp_bias = mlp_bias
|
29 |
-
self.pretraining_tp = pretraining_tp
|
30 |
-
self.rope_scaling = rope_scaling
|
31 |
-
self.rope_theta = rope_theta
|
32 |
self.num_key_value_heads = num_key_value_heads
|
|
|
|
|
|
|
33 |
self.use_cache = use_cache
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2023 Cognitivess AI and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""Cognitivess model configuration"""
|
16 |
+
|
17 |
+
from ...configuration_utils import PretrainedConfig
|
18 |
+
from ...utils import logging
|
19 |
+
|
20 |
+
|
21 |
+
logger = logging.get_logger(__name__)
|
22 |
|
|
|
23 |
|
24 |
class CognitivessConfig(PretrainedConfig):
|
25 |
+
r"""
|
26 |
+
This is the configuration class to store the configuration of a [`CognitivessModel`]. It is used to instantiate an
|
27 |
+
Cognitivess model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
28 |
+
with the defaults will yield a similar configuration to that of the Cognitivess-8B-v0.1.
|
29 |
+
|
30 |
+
[CognitivessAI/cognitivess](https://huggingface.co/CognitivessAI/cognitivess)
|
31 |
+
|
32 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
33 |
+
documentation from [`PretrainedConfig`] for more information.
|
34 |
+
|
35 |
+
|
36 |
+
Args:
|
37 |
+
vocab_size (`int`, *optional*, defaults to 32000):
|
38 |
+
Vocabulary size of the Cognitivess model. Defines the number of different tokens that can be represented by the
|
39 |
+
`inputs_ids` passed when calling [`CognitivessModel`]
|
40 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
41 |
+
Dimension of the hidden representations.
|
42 |
+
intermediate_size (`int`, *optional*, defaults to 14336):
|
43 |
+
Dimension of the MLP representations.
|
44 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
45 |
+
Number of hidden layers in the Transformer encoder.
|
46 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
47 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
48 |
+
num_key_value_heads (`int`, *optional*, defaults to 8):
|
49 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
50 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
51 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
52 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
53 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
54 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `8`.
|
55 |
+
head_dim (`int`, *optional*, defaults to `hidden_size // num_attention_heads`):
|
56 |
+
The attention head dimension.
|
57 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
58 |
+
The non-linear activation function (function or string) in the decoder.
|
59 |
+
max_position_embeddings (`int`, *optional*, defaults to `4096*32`):
|
60 |
+
The maximum sequence length that this model might ever be used with. Cognitivess's sliding window attention
|
61 |
+
allows sequence of up to 4096*32 tokens.
|
62 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
63 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
64 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
65 |
+
The epsilon used by the rms normalization layers.
|
66 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
67 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
68 |
+
relevant if `config.is_decoder=True`.
|
69 |
+
pad_token_id (`int`, *optional*):
|
70 |
+
The id of the padding token.
|
71 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
72 |
+
The id of the "beginning-of-sequence" token.
|
73 |
+
eos_token_id (`int`, *optional*, defaults to 2):
|
74 |
+
The id of the "end-of-sequence" token.
|
75 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
76 |
+
Whether the model's input and output word embeddings should be tied.
|
77 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
78 |
+
The base period of the RoPE embeddings.
|
79 |
+
sliding_window (`int`, *optional*, defaults to 4096):
|
80 |
+
Sliding window attention window size. If not specified, will default to `4096`.
|
81 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
82 |
+
The dropout ratio for the attention probabilities.
|
83 |
+
|
84 |
+
```python
|
85 |
+
>>> from transformers import CognitivessModel, CognitivessConfig
|
86 |
+
|
87 |
+
>>> # Initializing a Cognitivess 8B style configuration
|
88 |
+
>>> configuration = CognitivessConfig()
|
89 |
+
|
90 |
+
>>> # Initializing a model from the Cognitivess 8B style configuration
|
91 |
+
>>> model = CognitivessModel(configuration)
|
92 |
+
|
93 |
+
>>> # Accessing the model configuration
|
94 |
+
>>> configuration = model.config
|
95 |
+
```"""
|
96 |
+
|
97 |
+
model_type = "Cognitivess"
|
98 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
99 |
+
|
100 |
+
def __init__(
|
101 |
+
self,
|
102 |
+
vocab_size=32000,
|
103 |
+
hidden_size=4096,
|
104 |
+
intermediate_size=14336,
|
105 |
+
num_hidden_layers=32,
|
106 |
+
num_attention_heads=32,
|
107 |
+
num_key_value_heads=8,
|
108 |
+
head_dim=None,
|
109 |
+
hidden_act="silu",
|
110 |
+
max_position_embeddings=4096 * 32,
|
111 |
+
initializer_range=0.02,
|
112 |
+
rms_norm_eps=1e-6,
|
113 |
+
use_cache=True,
|
114 |
+
pad_token_id=None,
|
115 |
+
bos_token_id=1,
|
116 |
+
eos_token_id=2,
|
117 |
+
tie_word_embeddings=False,
|
118 |
+
rope_theta=10000.0,
|
119 |
+
sliding_window=4096,
|
120 |
+
attention_dropout=0.0,
|
121 |
+
**kwargs,
|
122 |
+
):
|
123 |
+
self.vocab_size = vocab_size
|
124 |
+
self.max_position_embeddings = max_position_embeddings
|
125 |
self.hidden_size = hidden_size
|
126 |
+
self.intermediate_size = intermediate_size
|
127 |
self.num_hidden_layers = num_hidden_layers
|
128 |
self.num_attention_heads = num_attention_heads
|
129 |
+
self.sliding_window = sliding_window
|
130 |
+
self.head_dim = head_dim or hidden_size // num_attention_heads
|
131 |
+
|
132 |
+
# for backward compatibility
|
133 |
+
if num_key_value_heads is None:
|
134 |
+
num_key_value_heads = num_attention_heads
|
135 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
self.num_key_value_heads = num_key_value_heads
|
137 |
+
self.hidden_act = hidden_act
|
138 |
+
self.initializer_range = initializer_range
|
139 |
+
self.rms_norm_eps = rms_norm_eps
|
140 |
self.use_cache = use_cache
|
141 |
+
self.rope_theta = rope_theta
|
142 |
+
self.attention_dropout = attention_dropout
|
143 |
+
|
144 |
+
super().__init__(
|
145 |
+
pad_token_id=pad_token_id,
|
146 |
+
bos_token_id=bos_token_id,
|
147 |
+
eos_token_id=eos_token_id,
|
148 |
+
tie_word_embeddings=tie_word_embeddings,
|
149 |
+
**kwargs,
|
150 |
+
)
|