| """ |
| Helion Model Configuration |
| """ |
|
|
| from transformers import PretrainedConfig |
|
|
|
|
| class HelionConfig(PretrainedConfig): |
| """ |
| Configuration class for Helion model. |
| |
| Args: |
| vocab_size (`int`, *optional*, defaults to 100000): |
| Vocabulary size of the Helion model. |
| hidden_size (`int`, *optional*, defaults to 6144): |
| Dimension of the hidden representations. |
| intermediate_size (`int`, *optional*, defaults to 24576): |
| Dimension of the MLP representations. |
| num_hidden_layers (`int`, *optional*, defaults to 48): |
| Number of hidden layers in the Transformer decoder. |
| num_attention_heads (`int`, *optional*, defaults to 32): |
| Number of attention heads for each attention layer. |
| num_key_value_heads (`int`, *optional*, defaults to 8): |
| Number of key-value heads for Grouped Query Attention. |
| hidden_act (`str` or `function`, *optional*, defaults to `"silu"`): |
| The non-linear activation function. |
| max_position_embeddings (`int`, *optional*, defaults to 16384): |
| Maximum sequence length that the model can handle. |
| initializer_range (`float`, *optional*, defaults to 0.02): |
| Standard deviation of the truncated_normal_initializer. |
| rms_norm_eps (`float`, *optional*, defaults to 1e-6): |
| Epsilon value for RMSNorm layers. |
| use_cache (`bool`, *optional*, defaults to `True`): |
| Whether to use cache for faster decoding. |
| pad_token_id (`int`, *optional*, defaults to 0): |
| Padding token id. |
| bos_token_id (`int`, *optional*, defaults to 1): |
| Beginning of stream token id. |
| eos_token_id (`int`, *optional*, defaults to 2): |
| End of stream token id. |
| tie_word_embeddings (`bool`, *optional*, defaults to `False`): |
| Whether to tie input and output embeddings. |
| rope_theta (`float`, *optional*, defaults to 10000.0): |
| The base period of the RoPE embeddings. |
| rope_scaling (`Dict`, *optional*): |
| Dictionary containing the scaling configuration for RoPE. |
| attention_bias (`bool`, *optional*, defaults to `False`): |
| Whether to use bias in attention layers. |
| attention_dropout (`float`, *optional*, defaults to 0.0): |
| Dropout probability for attention weights. |
| """ |
| |
| model_type = "helion" |
| keys_to_ignore_at_inference = ["past_key_values"] |
|
|
| def __init__( |
| self, |
| vocab_size=100000, |
| hidden_size=6144, |
| intermediate_size=24576, |
| num_hidden_layers=48, |
| num_attention_heads=32, |
| num_key_value_heads=8, |
| hidden_act="silu", |
| max_position_embeddings=16384, |
| initializer_range=0.02, |
| rms_norm_eps=1e-6, |
| use_cache=True, |
| pad_token_id=0, |
| bos_token_id=1, |
| eos_token_id=2, |
| tie_word_embeddings=False, |
| rope_theta=10000.0, |
| rope_scaling=None, |
| attention_bias=False, |
| attention_dropout=0.0, |
| **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 |
| |
| |
| if num_key_value_heads is None: |
| num_key_value_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.use_cache = use_cache |
| self.rope_theta = rope_theta |
| self.rope_scaling = rope_scaling |
| self.attention_bias = attention_bias |
| self.attention_dropout = attention_dropout |
| |
| |
| if self.rope_scaling is not None: |
| if not isinstance(self.rope_scaling, dict): |
| raise ValueError("`rope_scaling` must be a dictionary") |
| |
| required_keys = {"type", "factor"} |
| if not all(key in self.rope_scaling for key in required_keys): |
| raise ValueError(f"`rope_scaling` must contain keys {required_keys}") |
| |
| if self.rope_scaling["type"] not in ["linear", "dynamic"]: |
| raise ValueError("`rope_scaling.type` must be 'linear' or 'dynamic'") |
|
|
| super().__init__( |
| pad_token_id=pad_token_id, |
| bos_token_id=bos_token_id, |
| eos_token_id=eos_token_id, |
| tie_word_embeddings=tie_word_embeddings, |
| **kwargs, |
| ) |