|
|
"""Helion model configuration.""" |
|
|
|
|
|
from transformers.configuration_utils import PretrainedConfig |
|
|
from transformers.utils import logging |
|
|
|
|
|
logger = logging.get_logger(__name__) |
|
|
|
|
|
|
|
|
class HelionConfig(PretrainedConfig): |
|
|
""" |
|
|
Configuration class for Helion model. |
|
|
|
|
|
Args: |
|
|
vocab_size (int, optional): Vocabulary size. Defaults to 32768. |
|
|
hidden_size (int, optional): Dimensionality of hidden layers. Defaults to 4096. |
|
|
intermediate_size (int, optional): Dimensionality of MLP. Defaults to 14336. |
|
|
num_hidden_layers (int, optional): Number of decoder layers. Defaults to 32. |
|
|
num_attention_heads (int, optional): Number of attention heads. Defaults to 32. |
|
|
num_key_value_heads (int, optional): Number of key-value heads for GQA. Defaults to 8. |
|
|
hidden_act (str, optional): Activation function. Defaults to "silu". |
|
|
max_position_embeddings (int, optional): Maximum sequence length. Defaults to 8192. |
|
|
initializer_range (float, optional): Standard deviation for weight initialization. Defaults to 0.02. |
|
|
rms_norm_eps (float, optional): Epsilon for RMS normalization. Defaults to 1e-6. |
|
|
use_cache (bool, optional): Whether to use KV cache. Defaults to True. |
|
|
pad_token_id (int, optional): Padding token ID. Defaults to None. |
|
|
bos_token_id (int, optional): Beginning of sequence token ID. Defaults to 1. |
|
|
eos_token_id (int, optional): End of sequence token ID. Defaults to 2. |
|
|
tie_word_embeddings (bool, optional): Tie input/output embeddings. Defaults to False. |
|
|
rope_theta (float, optional): Base for RoPE. Defaults to 10000.0. |
|
|
rope_scaling (dict, optional): RoPE scaling config. Defaults to None. |
|
|
attention_bias (bool, optional): Add bias to attention projections. Defaults to False. |
|
|
attention_dropout (float, optional): Dropout for attention. Defaults to 0.0. |
|
|
mlp_bias (bool, optional): Add bias to MLP. Defaults to False. |
|
|
""" |
|
|
|
|
|
model_type = "helion" |
|
|
keys_to_ignore_at_inference = ["past_key_values"] |
|
|
|
|
|
def __init__( |
|
|
self, |
|
|
vocab_size=32768, |
|
|
hidden_size=4096, |
|
|
intermediate_size=14336, |
|
|
num_hidden_layers=32, |
|
|
num_attention_heads=32, |
|
|
num_key_value_heads=8, |
|
|
hidden_act="silu", |
|
|
max_position_embeddings=8192, |
|
|
initializer_range=0.02, |
|
|
rms_norm_eps=1e-6, |
|
|
use_cache=True, |
|
|
pad_token_id=None, |
|
|
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, |
|
|
mlp_bias=False, |
|
|
residual_dropout=0.0, |
|
|
embedding_dropout=0.0, |
|
|
use_sliding_window=False, |
|
|
sliding_window=None, |
|
|
use_flash_attention_2=True, |
|
|
pretraining_tp=1, |
|
|
**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 |
|
|
self.mlp_bias = mlp_bias |
|
|
self.residual_dropout = residual_dropout |
|
|
self.embedding_dropout = embedding_dropout |
|
|
self.use_sliding_window = use_sliding_window |
|
|
self.sliding_window = sliding_window |
|
|
self.use_flash_attention_2 = use_flash_attention_2 |
|
|
self.pretraining_tp = pretraining_tp |
|
|
|
|
|
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, |
|
|
) |