
    qiU*                     p    d Z ddlmZmZ ddlmZ ddlmZ  ej                  e	      Z
 G d de      ZdgZy)zAFMoE model configuration   )PreTrainedConfiglayer_type_validation)RopeParameters)loggingc            <           e Zd ZdZdZdgZdgdgfddgdgfdgdgfdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(d
ed	z  ded	z  ded	z  ded	z  ded	z  ded	z  ded	z  ded	z  ded	z  ded	z  ded	z  de	d	z  de	d	z  de
d	z  de
d	z  de	d	z  deeeef   z  d	z  ded	z  ded	z  ded	z  de	d	z  ded	z  d ed	z  d!ed	z  d"e	d	z  d#e
d	z  d$e
d	z  d%e
d	z  d&e
d	z  f: fd'Z xZS ))AfmoeConfiga  
    This is the configuration class to store the configuration of a [`AfmoeModel`]. It is used to instantiate an
    AFMoE model according to the specified arguments, defining the model architecture. Instantiating a configuration
    with the defaults will yield a similar configuration to that of [arcee-ai/Trinity-Mini](https://huggingface.co/arcee-ai/Trinity-Mini).

    AFMoE is an Adaptive Feedforward MoE (Mixture of Experts) model with token-choice routing, shared experts, and a
    hybrid attention mechanism combining sliding window and full attention patterns.

    Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PreTrainedConfig`] for more information.

    Args:
        vocab_size (`int`, *optional*, defaults to 200192):
            Vocabulary size of the AFMoE model. Defines the number of different tokens that can be represented by the
            `inputs_ids` passed when calling [`AfmoeModel`].
        hidden_size (`int`, *optional*, defaults to 2048):
            Dimension of the hidden representations.
        intermediate_size (`int`, *optional*, defaults to 6144):
            Dimension of the dense MLP representations.
        moe_intermediate_size (`int`, *optional*, defaults to 1408):
            Intermediate size of the routed expert MLPs.
        num_hidden_layers (`int`, *optional*, defaults to 32):
            Number of hidden layers in the Transformer decoder.
        num_dense_layers (`int`, *optional*, defaults to 1):
            Number of initial dense layers before MoE layers begin. Layers with index < num_dense_layers will use
            standard dense MLPs instead of MoE.
        num_attention_heads (`int`, *optional*, defaults to 16):
            Number of attention heads for each attention layer in the Transformer decoder.
        num_key_value_heads (`int`, *optional*):
            This is the number of key_value heads that should be used to implement Grouped Query Attention. If
            `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
            `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
            converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
            by meanpooling all the original heads within that group. For more details, check out [this
            paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to
            `num_attention_heads`.
        head_dim (`int`, *optional*, defaults to 128):
            The dimension of each attention head.
        hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
            The non-linear activation function (function or string) in the MLP blocks.
        max_position_embeddings (`int`, *optional*, defaults to 16384):
            The maximum sequence length that this model might ever be used with.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        rms_norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the RMS normalization layers.
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return the last key/values attentions (not used by all models). Only
            relevant if `config.is_decoder=True`.
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether the model's input and output word embeddings should be tied.
        rope_theta (`float`, *optional*, defaults to 10000.0):
            The base period of the RoPE embeddings.
        rope_parameters (`RopeParameters`, *optional*):
            Dictionary containing the configuration parameters for the RoPE embeddings. The dictionary should contain
            a value for `rope_theta` and optionally parameters used for scaling in case you want to use RoPE
            with longer `max_position_embeddings`.
        num_experts (`int`, *optional*, defaults to 64):
            Number of routed experts in MoE layers.
        num_experts_per_tok (`int`, *optional*, defaults to 6):
            Number of experts to route each token to. This is the top-k value for the token-choice routing.
        num_shared_experts (`int`, *optional*, defaults to 2):
            Number of shared experts that are always activated for all tokens.
        route_scale (`float`, *optional*, defaults to 1.0):
            Scaling factor applied to routing weights.
        global_attn_every_n_layers (`int`, *optional*, defaults to 4):
            The frequency of full attention layers. Every Nth layer will use full attention, while others use sliding
            window attention.
        sliding_window (`int`, *optional*, defaults to 1024):
            Sliding window size for local attention layers.
        layer_types (`list[str]`, *optional*):
            A list that explicitly maps each layer index with its attention type. Each element should be either
            "sliding_attention" or "full_attention". If not provided, it will be automatically generated based on
            `global_attn_every_n_layers`.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        mup_enabled (`bool`, *optional*, defaults to `False`):
            Whether to enable muP (Maximal Update Parametrization) input scaling. When enabled, input embeddings
            are scaled by `sqrt(hidden_size)`.
        eos_token_id (`int`, *optional*):
            End of stream token id.
        pad_token_id (`int`, *optional*):
            Padding token id.
        bos_token_id (`int`, *optional*):
            Beginning of stream token id.

    Example:
    ```python
    >>> from transformers import AfmoeModel, AfmoeConfig

    >>> # Initializing an AFMoE configuration
    >>> configuration = AfmoeConfig()

    >>> # Initializing a model from the afmoe-small-sft-v1 style configuration
    >>> model = AfmoeModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```
    afmoepast_key_values	input_idsinputs_embedshidden_statesattention_mask)embed_tokenslayersnormN
vocab_sizehidden_sizeintermediate_sizemoe_intermediate_sizenum_hidden_layersnum_dense_layersnum_attention_headsnum_key_value_headshead_dim
hidden_actmax_position_embeddingsinitializer_rangerms_norm_eps	use_cachetie_word_embeddings
rope_thetarope_parametersnum_expertsnum_experts_per_toknum_shared_expertsroute_scaleglobal_attn_every_n_layerssliding_windowlayer_typesattention_dropoutmup_enabledeos_token_idpad_token_idbos_token_idc                    || _         || _        || _        || _        || _        || _        || _        |	| _        |
| _        || _	        || _
        || _        || _        || _        || _        || _        || _        || _        || _        d| _        || _        || _        || _        || _        || _        | j0                  ;t3        | j                        D cg c]  }t5        |dz   |z        rdnd c}| _        t7        | j0                         ||}|| _        || _        || _        || _        || _         tC         |   di | y c c}w )NF   sliding_attentionfull_attention )#r   r   r   r   r   r   r   r   r   r   r   r   r!   r"   r   r$   r#   r%   r&   attention_biasr*   r'   r(   r+   r)   rangeboolr   r   r,   r-   r.   r    super__init__)!selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   kwargsi	__class__s!                                   _/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/afmoe/configuration_afmoe.pyr8   zAfmoeConfig.__init__   sr   B %'>$&!2!2 0#6  $!2("$. &;"#6 &"4&# "3*D',&&# t556  (,QU6P,P'Q#Wgg D 	d../&"5#6 (((#6 "6" s   E)i  i   i   i      r0      N   silui @  g{Gz?gh㈵>TFg     @N@         g      ?   i   Ng        FNNN)__name__
__module____qualname____doc__
model_typekeys_to_ignore_at_inferencebase_model_pp_planintstrfloatr6   r   dictlistr8   __classcell__)r<   s   @r=   r   r      sv   cJ J#4"5 &(9:#%568IJ!"_$56 "("&(,,0(*'(*,*."!'.3*.%)!%+0#*MQ"$*+)*$'12%)#'*-#($($($(=N#$JN# 4ZN# :	N#
  #TzN# :N# *N# !4ZN# !4ZN# *N# $JN# "%tN# !4<N# dlN# $;N#  "D[!N#" DL#N#$ ($sN/B*CCdJ%N#& 4Z'N#( !4Z)N#*  $J+N#, T\-N#. %($J/N#0 d
1N#2 D[3N#4 !4<5N#6 D[7N#8 Tk9N#: Tk;N#< Tk=N# N#    r   N)rI   configuration_utilsr   r   modeling_rope_utilsr   utilsr   
get_loggerrF   loggerr   __all__r3   rS   r=   <module>rZ      s@      J 1  
		H	%~#" ~#B /rS   