cognitivess commited on
Commit
edb3b2c
1 Parent(s): 6d9bf6c

Update cognitivess_model/configuration_cognitivess.py

Browse files
cognitivess_model/configuration_cognitivess.py CHANGED
@@ -1,6 +1,5 @@
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
@@ -23,11 +22,9 @@ logger = logging.get_logger(__name__)
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.
@@ -39,26 +36,25 @@ class CognitivessConfig(PretrainedConfig):
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):
@@ -67,27 +63,42 @@ class CognitivessConfig(PretrainedConfig):
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
@@ -101,23 +112,25 @@ class CognitivessConfig(PretrainedConfig):
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
@@ -126,8 +139,6 @@ class CognitivessConfig(PretrainedConfig):
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:
@@ -137,9 +148,14 @@ class CognitivessConfig(PretrainedConfig):
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,
@@ -147,4 +163,24 @@ class CognitivessConfig(PretrainedConfig):
147
  eos_token_id=eos_token_id,
148
  tie_word_embeddings=tie_word_embeddings,
149
  **kwargs,
150
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
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.
 
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):
 
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
 
112
  self,
113
  vocab_size=32000,
114
  hidden_size=4096,
115
+ intermediate_size=11008,
116
  num_hidden_layers=32,
117
  num_attention_heads=32,
118
+ num_key_value_heads=None,
 
119
  hidden_act="silu",
120
+ max_position_embeddings=2048,
121
  initializer_range=0.02,
122
  rms_norm_eps=1e-6,
123
  use_cache=True,
124
  pad_token_id=None,
125
  bos_token_id=1,
126
  eos_token_id=2,
127
+ pretraining_tp=1,
128
  tie_word_embeddings=False,
129
  rope_theta=10000.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
 
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:
 
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,
 
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}")