naver-hyperclovax/HyperCLOVAX-SEED-Omni-8B
1933.1k
1# coding=utf-82# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.3#4# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX5# and OPT implementations in this library. It has been modified from its6# original forms to accommodate minor architectural differences compared7# to GPT-NeoX and OPT used by the Meta AI team that trained the model.8#9# Licensed under the Apache License, Version 2.0 (the "License");10# you may not use this file except in compliance with the License.11# You may obtain a copy of the License at12#13# http://www.apache.org/licenses/LICENSE-2.014#15# Unless required by applicable law or agreed to in writing, software16# distributed under the License is distributed on an "AS IS" BASIS,17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.18# See the License for the specific language governing permissions and19# limitations under the License.20"""LLaMA model configuration"""21 22from transformers.configuration_utils import PretrainedConfig23 24# from transformers.modeling_rope_utils import rope_config_validation25# from transformers import PretrainedConfig, rope_config_validation26 27 28class HyperCLOVAXConfig(PretrainedConfig):29 r"""30 This is the configuration class to store the configuration of a [`LlamaModel`]. It is used to instantiate an LLaMA31 model according to the specified arguments, defining the model architecture. Instantiating a configuration with the32 defaults will yield a similar configuration to that of the LLaMA-7B.33 34 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the35 documentation from [`PretrainedConfig`] for more information.36 37 38 Args:39 vocab_size (`int`, *optional*, defaults to 32000):40 Vocabulary size of the LLaMA model. Defines the number of different tokens that can be represented by the41 `inputs_ids` passed when calling [`LlamaModel`]42 hidden_size (`int`, *optional*, defaults to 4096):43 Dimension of the hidden representations.44 intermediate_size (`int`, *optional*, defaults to 11008):45 Dimension of the MLP representations.46 num_hidden_layers (`int`, *optional*, defaults to 32):47 Number of hidden layers in the Transformer decoder.48 num_attention_heads (`int`, *optional*, defaults to 32):49 Number of attention heads for each attention layer in the Transformer decoder.50 num_key_value_heads (`int`, *optional*):51 This is the number of key_value heads that should be used to implement Grouped Query Attention. If52 `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if53 `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When54 converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed55 by meanpooling all the original heads within that group. For more details checkout [this56 paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to57 `num_attention_heads`.58 hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):59 The non-linear activation function (function or string) in the decoder.60 max_position_embeddings (`int`, *optional*, defaults to 2048):61 The maximum sequence length that this model might ever be used with. Llama 1 supports up to 2048 tokens,62 Llama 2 up to 4096, CodeLlama up to 16384.63 initializer_range (`float`, *optional*, defaults to 0.02):64 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.65 rms_norm_eps (`float`, *optional*, defaults to 1e-06):66 The epsilon used by the rms normalization layers.67 use_cache (`bool`, *optional*, defaults to `True`):68 Whether or not the model should return the last key/values attentions (not used by all models). Only69 relevant if `config.is_decoder=True`.70 pad_token_id (`int`, *optional*):71 Padding token id.72 bos_token_id (`int`, *optional*, defaults to 1):73 Beginning of stream token id.74 eos_token_id (`int`, *optional*, defaults to 2):75 End of stream token id.76 pretraining_tp (`int`, *optional*, defaults to 1):77 Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this78 document](https://huggingface.co/docs/transformers/main/perf_train_gpu_many#tensor-parallelism) to79 understand more about it. This value is necessary to ensure exact reproducibility of the pretraining80 results. Please refer to [this issue](https://github.com/pytorch/pytorch/issues/76232).81 tie_word_embeddings (`bool`, *optional*, defaults to `False`):82 Whether to tie weight embeddings83 rope_theta (`float`, *optional*, defaults to 10000.0):84 The base period of the RoPE embeddings.85 rope_scaling (`Dict`, *optional*):86 Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type87 and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value88 accordingly.89 Expected contents:90 `rope_type` (`str`):91 The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',92 'llama3'], with 'default' being the original RoPE implementation.93 `factor` (`float`, *optional*):94 Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In95 most scaling types, a `factor` of x will enable the model to handle sequences of length x *96 original maximum pre-trained length.97 `original_max_position_embeddings` (`int`, *optional*):98 Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during99 pretraining.100 `attention_factor` (`float`, *optional*):101 Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention102 computation. If unspecified, it defaults to value recommended by the implementation, using the103 `factor` field to infer the suggested value.104 `beta_fast` (`float`, *optional*):105 Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear106 ramp function. If unspecified, it defaults to 32.107 `beta_slow` (`float`, *optional*):108 Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear109 ramp function. If unspecified, it defaults to 1.110 `short_factor` (`List[float]`, *optional*):111 Only used with 'longrope'. The scaling factor to be applied to short contexts (<112 `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden113 size divided by the number of attention heads divided by 2114 `long_factor` (`List[float]`, *optional*):115 Only used with 'longrope'. The scaling factor to be applied to long contexts (<116 `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden117 size divided by the number of attention heads divided by 2118 `low_freq_factor` (`float`, *optional*):119 Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE120 `high_freq_factor` (`float`, *optional*):121 Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE122 attention_bias (`bool`, *optional*, defaults to `False`):123 Whether to use a bias in the query, key, value and output projection layers during self-attention.124 attention_dropout (`float`, *optional*, defaults to 0.0):125 The dropout ratio for the attention probabilities.126 mlp_bias (`bool`, *optional*, defaults to `False`):127 Whether to use a bias in up_proj, down_proj and gate_proj layers in the MLP layers.128 head_dim (`int`, *optional*):129 The attention head dimension. If None, it will default to hidden_size // num_heads130 131 ```python132 >>> from transformers import LlamaModel, LlamaConfig133 134 >>> # Initializing a LLaMA llama-7b style configuration135 >>> configuration = LlamaConfig()136 137 >>> # Initializing a model from the llama-7b style configuration138 >>> model = LlamaModel(configuration)139 140 >>> # Accessing the model configuration141 >>> configuration = model.config142 ```"""143 144 model_type = "hyperclovax"145 keys_to_ignore_at_inference = ["past_key_values"]146 147 def __init__(148 self,149 vocab_size=32000,150 hidden_size=4096,151 intermediate_size=11008,152 num_hidden_layers=32,153 num_attention_heads=32,154 num_key_value_heads=None,155 hidden_act="silu",156 max_position_embeddings=2048,157 initializer_range=0.02,158 rms_norm_eps=1e-6,159 use_cache=True,160 pad_token_id=None,161 bos_token_id=1,162 eos_token_id=2,163 pretraining_tp=1,164 tie_word_embeddings=False,165 rope_theta=10000.0,166 rope_scaling=None,167 attention_bias=False,168 attention_dropout=0.0,169 mlp_bias=False,170 head_dim=None,171 embedding_multiplier=1.0, # mup172 logits_scaling=1.0, # mup173 attention_multiplier=1.0, # mup174 residual_multiplier=1.0, # mup175 use_post_norm=False, # post-norm176 auto_map={177 "AutoConfig": "configuration_hyperclovax.HyperCLOVAXConfig",178 "AutoModel": "modeling_hyperclovax.HyperCLOVAXModel",179 "AutoModelForCausalLM": "modeling_hyperclovax.HyperCLOVAXForCausalLM",180 },181 **kwargs,182 ):183 self.vocab_size = vocab_size184 self.max_position_embeddings = max_position_embeddings185 self.hidden_size = hidden_size186 self.intermediate_size = intermediate_size187 self.num_hidden_layers = num_hidden_layers188 self.num_attention_heads = num_attention_heads189 190 # for backward compatibility191 if num_key_value_heads is None:192 num_key_value_heads = num_attention_heads193 194 self.num_key_value_heads = num_key_value_heads195 self.hidden_act = hidden_act196 self.initializer_range = initializer_range197 self.rms_norm_eps = rms_norm_eps198 self.pretraining_tp = pretraining_tp199 self.use_cache = use_cache200 self.rope_theta = rope_theta201 self.rope_scaling = rope_scaling202 self.attention_bias = attention_bias203 self.attention_dropout = attention_dropout204 self.mlp_bias = mlp_bias205 self.head_dim = head_dim if head_dim is not None else self.hidden_size // self.num_attention_heads206 # Validate the correctness of rotary position embeddings parameters207 # BC: if there is a 'type' field, copy it it to 'rope_type'.208 if self.rope_scaling is not None and "type" in self.rope_scaling:209 self.rope_scaling["rope_type"] = self.rope_scaling["type"]210 # rope_config_validation(self)211 212 # mup213 self.embedding_multiplier = embedding_multiplier214 self.logits_scaling = logits_scaling215 self.attention_multiplier = attention_multiplier216 self.residual_multiplier = residual_multiplier217 218 # post-norm (dual-norm)219 self.use_post_norm = use_post_norm220 221 super().__init__(222 pad_token_id=pad_token_id,223 bos_token_id=bos_token_id,224 eos_token_id=eos_token_id,225 tie_word_embeddings=tie_word_embeddings,226 auto_map=auto_map,227 **kwargs,228 )229 