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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 The Qwen team, Alibaba Group 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 |
+
"""RWKV6Qwen2 model configuration"""
|
| 16 |
+
|
| 17 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 18 |
+
from transformers.modeling_rope_utils import rope_config_validation
|
| 19 |
+
from transformers.utils import logging
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
logger = logging.get_logger(__name__)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class RWKV6Qwen2Config(PretrainedConfig):
|
| 26 |
+
r"""
|
| 27 |
+
This is the configuration class to store the configuration of a [`RWKV6Qwen2Model`]. It is used to instantiate a
|
| 28 |
+
RWKV6Qwen2 model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
| 29 |
+
with the defaults will yield a similar configuration to that of
|
| 30 |
+
Qwen2-7B-beta [Qwen/Qwen2-7B-beta](https://huggingface.co/Qwen/Qwen2-7B-beta).
|
| 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 151936):
|
| 38 |
+
Vocabulary size of the RWKV6Qwen2 model. Defines the number of different tokens that can be represented by the
|
| 39 |
+
`inputs_ids` passed when calling [`RWKV6Qwen2Model`]
|
| 40 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
| 41 |
+
Dimension of the hidden representations.
|
| 42 |
+
intermediate_size (`int`, *optional*, defaults to 22016):
|
| 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 32):
|
| 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 `32`.
|
| 55 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 56 |
+
The non-linear activation function (function or string) in the decoder.
|
| 57 |
+
max_position_embeddings (`int`, *optional*, defaults to 32768):
|
| 58 |
+
The maximum sequence length that this model might ever be used with.
|
| 59 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 60 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 61 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
| 62 |
+
The epsilon used by the rms normalization layers.
|
| 63 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 64 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 65 |
+
relevant if `config.is_decoder=True`.
|
| 66 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 67 |
+
Whether the model's input and output word embeddings should be tied.
|
| 68 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 69 |
+
The base period of the RoPE embeddings.
|
| 70 |
+
rope_scaling (`Dict`, *optional*):
|
| 71 |
+
Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
|
| 72 |
+
and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
|
| 73 |
+
accordingly.
|
| 74 |
+
Expected contents:
|
| 75 |
+
`rope_type` (`str`):
|
| 76 |
+
The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
|
| 77 |
+
'llama3'], with 'default' being the original RoPE implementation.
|
| 78 |
+
`factor` (`float`, *optional*):
|
| 79 |
+
Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
|
| 80 |
+
most scaling types, a `factor` of x will enable the model to handle sequences of length x *
|
| 81 |
+
original maximum pre-trained length.
|
| 82 |
+
`original_max_position_embeddings` (`int`, *optional*):
|
| 83 |
+
Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
|
| 84 |
+
pretraining.
|
| 85 |
+
`attention_factor` (`float`, *optional*):
|
| 86 |
+
Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
|
| 87 |
+
computation. If unspecified, it defaults to value recommended by the implementation, using the
|
| 88 |
+
`factor` field to infer the suggested value.
|
| 89 |
+
`beta_fast` (`float`, *optional*):
|
| 90 |
+
Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
|
| 91 |
+
ramp function. If unspecified, it defaults to 32.
|
| 92 |
+
`beta_slow` (`float`, *optional*):
|
| 93 |
+
Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
|
| 94 |
+
ramp function. If unspecified, it defaults to 1.
|
| 95 |
+
`short_factor` (`List[float]`, *optional*):
|
| 96 |
+
Only used with 'longrope'. The scaling factor to be applied to short contexts (<
|
| 97 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
| 98 |
+
size divided by the number of attention heads divided by 2
|
| 99 |
+
`long_factor` (`List[float]`, *optional*):
|
| 100 |
+
Only used with 'longrope'. The scaling factor to be applied to long contexts (<
|
| 101 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
| 102 |
+
size divided by the number of attention heads divided by 2
|
| 103 |
+
`low_freq_factor` (`float`, *optional*):
|
| 104 |
+
Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
|
| 105 |
+
`high_freq_factor` (`float`, *optional*):
|
| 106 |
+
Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
|
| 107 |
+
use_sliding_window (`bool`, *optional*, defaults to `False`):
|
| 108 |
+
Whether to use sliding window attention.
|
| 109 |
+
sliding_window (`int`, *optional*, defaults to 4096):
|
| 110 |
+
Sliding window attention (SWA) window size. If not specified, will default to `4096`.
|
| 111 |
+
max_window_layers (`int`, *optional*, defaults to 28):
|
| 112 |
+
The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
|
| 113 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 114 |
+
The dropout ratio for the attention probabilities.
|
| 115 |
+
|
| 116 |
+
```python
|
| 117 |
+
>>> from transformers import RWKV6Qwen2Model, RWKV6Qwen2Config
|
| 118 |
+
|
| 119 |
+
>>> # Initializing a RWKV6Qwen2 style configuration
|
| 120 |
+
>>> configuration = RWKV6Qwen2Config()
|
| 121 |
+
|
| 122 |
+
>>> # Initializing a model from the RWKV6Qwen2-7B style configuration
|
| 123 |
+
>>> model = RWKV6Qwen2Model(configuration)
|
| 124 |
+
|
| 125 |
+
>>> # Accessing the model configuration
|
| 126 |
+
>>> configuration = model.config
|
| 127 |
+
```"""
|
| 128 |
+
|
| 129 |
+
model_type = "rwkv6qwen2"
|
| 130 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 131 |
+
|
| 132 |
+
def __init__(
|
| 133 |
+
self,
|
| 134 |
+
vocab_size=151936,
|
| 135 |
+
hidden_size=4096,
|
| 136 |
+
intermediate_size=22016,
|
| 137 |
+
num_hidden_layers=32,
|
| 138 |
+
num_attention_heads=32,
|
| 139 |
+
num_key_value_heads=32,
|
| 140 |
+
lora_rank_tokenshift=None,
|
| 141 |
+
lora_rank_decay=None,
|
| 142 |
+
hidden_act="silu",
|
| 143 |
+
max_position_embeddings=32768,
|
| 144 |
+
initializer_range=0.02,
|
| 145 |
+
rms_norm_eps=1e-6,
|
| 146 |
+
use_cache=True,
|
| 147 |
+
tie_word_embeddings=False,
|
| 148 |
+
use_rope=False,
|
| 149 |
+
rope_theta=10000.0,
|
| 150 |
+
rope_scaling=None,
|
| 151 |
+
use_sliding_window=False,
|
| 152 |
+
sliding_window=4096,
|
| 153 |
+
max_window_layers=28,
|
| 154 |
+
attention_dropout=0.0,
|
| 155 |
+
attention_bias=True,
|
| 156 |
+
attention_output_bias=False,
|
| 157 |
+
gate_rank_type=1,
|
| 158 |
+
lora_rank_gate=None,
|
| 159 |
+
balance_state=True,
|
| 160 |
+
groupnorm_att=False,
|
| 161 |
+
use_tokenshift=True,
|
| 162 |
+
**kwargs,
|
| 163 |
+
):
|
| 164 |
+
self.vocab_size = vocab_size
|
| 165 |
+
self.max_position_embeddings = max_position_embeddings
|
| 166 |
+
self.hidden_size = hidden_size
|
| 167 |
+
self.intermediate_size = intermediate_size
|
| 168 |
+
self.num_hidden_layers = num_hidden_layers
|
| 169 |
+
self.num_attention_heads = num_attention_heads
|
| 170 |
+
self.use_sliding_window = use_sliding_window
|
| 171 |
+
self.sliding_window = sliding_window if use_sliding_window else None
|
| 172 |
+
self.max_window_layers = max_window_layers
|
| 173 |
+
|
| 174 |
+
# for backward compatibility
|
| 175 |
+
if num_key_value_heads is None:
|
| 176 |
+
num_key_value_heads = num_attention_heads
|
| 177 |
+
|
| 178 |
+
self.num_key_value_heads = num_key_value_heads
|
| 179 |
+
self.lora_rank_tokenshift = lora_rank_tokenshift
|
| 180 |
+
self.lora_rank_decay = lora_rank_decay
|
| 181 |
+
self.hidden_act = hidden_act
|
| 182 |
+
self.initializer_range = initializer_range
|
| 183 |
+
self.rms_norm_eps = rms_norm_eps
|
| 184 |
+
self.use_cache = use_cache
|
| 185 |
+
self.use_rope = use_rope
|
| 186 |
+
self.rope_theta = rope_theta
|
| 187 |
+
self.rope_scaling = rope_scaling
|
| 188 |
+
self.attention_dropout = attention_dropout
|
| 189 |
+
# Validate the correctness of rotary position embeddings parameters
|
| 190 |
+
# BC: if there is a 'type' field, move it to 'rope_type'.
|
| 191 |
+
if self.rope_scaling is not None and "type" in self.rope_scaling:
|
| 192 |
+
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
|
| 193 |
+
rope_config_validation(self)
|
| 194 |
+
|
| 195 |
+
self.attention_bias = attention_bias
|
| 196 |
+
self.attention_output_bias = attention_output_bias
|
| 197 |
+
self.gate_rank_type = gate_rank_type
|
| 198 |
+
self.lora_rank_gate = lora_rank_gate
|
| 199 |
+
self.balance_state = balance_state
|
| 200 |
+
self.groupnorm_att = groupnorm_att
|
| 201 |
+
self.use_tokenshift = use_tokenshift
|
| 202 |
+
|
| 203 |
+
super().__init__(
|
| 204 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 205 |
+
**kwargs,
|
| 206 |
+
)
|