| |
|
|
| from transformers.configuration_utils import PretrainedConfig |
| from transformers.modeling_rope_utils import rope_config_validation |
| from transformers.utils import logging |
|
|
|
|
| logger = logging.get_logger(__name__) |
|
|
|
|
| class NeoLLMConfig(PretrainedConfig): |
| r""" |
| This is the configuration class to store the configuration of a [`NeoLLMModel`]. It is used to instantiate a |
| NeoLLM model according to the specified arguments, defining the model architecture. |
| |
| Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. |
| """ |
|
|
| model_type = "neollm" |
| keys_to_ignore_at_inference = [] |
|
|
| def __init__( |
| self, |
| vocab_size=151665, |
| hidden_size=512, |
| intermediate_size=1024, |
| num_hidden_layers=12, |
| num_attention_heads=8, |
| num_key_value_heads=2, |
| hidden_act="xielu", |
| max_position_embeddings=32768, |
| initializer_range=0.02, |
| rms_norm_eps=1e-6, |
| tie_word_embeddings=True, |
| rope_theta=10000.0, |
| rope_scaling=None, |
| partial_rotary_factor=0.25, |
| attention_bias=False, |
| attention_dropout=0.1, |
| head_dim=64, |
| linear_conv_kernel_dim=4, |
| linear_key_head_dim=64, |
| linear_value_head_dim=64, |
| linear_num_key_heads=8, |
| linear_num_value_heads=8, |
| layer_types=None, |
| fan_ratio=0.125, |
| dropout_rate=0.1, |
| **kwargs, |
| ): |
| super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs) |
| self.vocab_size = vocab_size |
| self.max_position_embeddings = max_position_embeddings |
| self.hidden_size = hidden_size |
| self.intermediate_size = intermediate_size |
| self.num_hidden_layers = num_hidden_layers |
| self.num_attention_heads = num_attention_heads |
| self.num_key_value_heads = num_key_value_heads |
| self.hidden_act = hidden_act |
| self.initializer_range = initializer_range |
| self.rms_norm_eps = rms_norm_eps |
| self.rope_theta = rope_theta |
| self.rope_scaling = rope_scaling |
| self.partial_rotary_factor = partial_rotary_factor |
| self.attention_bias = attention_bias |
| self.attention_dropout = attention_dropout |
| self.head_dim = head_dim |
| rope_config_validation(self) |
|
|
| self.layer_types = layer_types |
| if self.layer_types is None: |
| interval_pattern = kwargs.get("full_attention_interval", 4) |
| self.layer_types = [ |
| "linear_attention" if bool((i + 1) % interval_pattern) else "full_attention" |
| for i in range(self.num_hidden_layers) |
| ] |
|
|
| |
| self.linear_conv_kernel_dim = linear_conv_kernel_dim |
| self.linear_key_head_dim = linear_key_head_dim |
| self.linear_value_head_dim = linear_value_head_dim |
| self.linear_num_key_heads = linear_num_key_heads |
| self.linear_num_value_heads = linear_num_value_heads |
| self.fan_ratio = fan_ratio |
| self.dropout_rate = dropout_rate |
|
|
| __all__ = ["NeoLLMConfig"] |