Ë
    S^(h¾&  ã                   óœ   — 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 G d„ d	e«      Z G d
„ de«      ZdgZy)zDBRX model configurationé    )ÚAnyÚOptionalé   )ÚPretrainedConfig)Úloggingc                   óL   ‡ — e Zd ZdZdZ	 	 	 	 d	dedee   dededef
ˆ fd„Z	ˆ xZ
S )
ÚDbrxAttentionConfiga_  Configuration class for Dbrx Attention.

    [`DbrxAttention`] class. It is used to instantiate attention layers
    according to the specified arguments, defining the layers architecture.

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

    Args:
        attn_pdrop (`float`, *optional*, defaults to 0.0):
            The dropout probability for the attention layers.
        clip_qkv (`float`, *optional*):
            If set, clip the queries, keys, and values in the attention layer to this value.
        kv_n_heads (`int`, *optional*, defaults to 1): For grouped_query_attention only, allow user to specify number of kv heads.
        rope_theta (`float`, *optional*, defaults to 10000.0): The base frequency for rope.
    Úattn_configÚ
attn_pdropÚclip_qkvÚ
kv_n_headsÚ
rope_thetaÚkwargsc                 óÎ   •— t        ‰| �  di |¤Ž || _        || _        || _        || _        dD ]  }||v sŒ|j                  |«       Œ t        |«      dk7  rt        d|›�«      ‚y )N©Ú
model_typeÚattn_implementationÚtransformers_versionÚ_commit_hashÚtorch_dtyper   úFound unknown kwargs=© )	ÚsuperÚ__init__r   r   r   r   ÚpopÚlenÚ
ValueError)Úselfr   r   r   r   r   ÚkÚ	__class__s          €úi/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/dbrx/configuration_dbrx.pyr   zDbrxAttentionConfig.__init__.   sx   ø€ ô 	‰ÑÑ"˜6Ò"Ø$ˆŒØ ˆŒØ$ˆŒØ$ˆŒàmò 	ˆAØ�FŠ{Ø—
‘
˜1•ð	ô ˆv‹;˜!ÒÜÐ5¨f¨YÐ7Ó8Ð8ð ó    )ç        Né   g     ˆÃ@)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úbase_config_keyÚfloatr   Úintr   r   Ú__classcell__©r    s   @r!   r	   r	      s[   ø„ ñð" $€Oð  Ø$(ØØ#ñ9àð9ð ˜5‘/ð9ð ð	9ð
 ð9ð ÷9ñ 9r"   r	   c                   ód   ‡ — e Zd ZdZdZ	 	 	 	 	 	 	 ddededededee   ded	ee   d
e	fˆ fd„Z
ˆ xZS )ÚDbrxFFNConfiga|  Configuration class for Dbrx FFN.

    [`DbrxFFN`] class. It is used to instantiate feedforward layers according to
    the specified arguments, defining the layers architecture.

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

    Args:
        ffn_act_fn (`dict`, *optional*, defaults to `None`): A dict specifying activation function for the FFN.
            The dict should have a key 'name' with the value being the name of the activation function along with
            any additional keyword arguments. If `None`, then set to `{"name": "silu"}`.
        ffn_hidden_size (`int`, *optional*, defaults to 3584): The hidden size of the feedforward network.
        moe_num_experts (`int`, *optional*, defaults to 4): The number of experts in the mixture of experts layer.
        moe_top_k (`int`, *optional*, defaults to 1): The number of experts to use in the mixture of experts layer.
        moe_jitter_eps (`float`, *optional*, defaults to `None`): If not `None`, the jitter epsilon for the mixture of experts layer.
        moe_loss_weight (`float`, *optional*, defaults to 0.01): The loss weight for the mixture of experts layer.
        moe_normalize_expert_weights (`float`, *optional*, defaults to 1.0): The normalization factor for the expert weights.
    Ú
ffn_configÚ
ffn_act_fnÚffn_hidden_sizeÚmoe_num_expertsÚ	moe_top_kÚmoe_jitter_epsÚmoe_loss_weightÚmoe_normalize_expert_weightsr   c                 ó  •— t         ‰
| �  «        |€ddi}|| _        || _        || _        || _        || _        || _        || _        dD ]  }	|	|v sŒ|j                  |	«       Œ t        |«      dk7  rt        d|›�«      ‚y )NÚnameÚsilur   r   r   )r   r   r1   r2   r3   r4   r5   r6   r7   r   r   r   )r   r1   r2   r3   r4   r5   r6   r7   r   r   r    s             €r!   r   zDbrxFFNConfig.__init__Z   s�   ø€ ô 	‰ÑÔØÐØ  &Ð)ˆJØ$ˆŒØ.ˆÔØ.ˆÔØ"ˆŒØ,ˆÔØ.ˆÔØ,HˆÔ)àmò 	ˆAØ�FŠ{Ø—
‘
˜1•ð	ô ˆv‹;˜!ÒÜÐ5¨f¨YÐ7Ó8Ð8ð r"   )Ni   é   r$   Ng{®Gáz„?g      ð?)r%   r&   r'   r(   r)   Údictr+   r   r*   r   r   r,   r-   s   @r!   r/   r/   C   s†   ø„ ñð( #€Oð  Ø#Ø ØØ*.Ø!%Ø8;ñ9àð9ð ð9ð ð	9ð
 ð9ð ! ™ð9ð ð9ð '/¨u¡oð9ð ÷9ñ 9r"   r/   c                   óš   ‡ — e Zd ZdZdZeedœZdddddœZ	 	 	 	 	 	 	 	 	 	 	 	 dde	de	de	de	d	e	d
e
de
dee   dee   dede
dedefˆ fd„Zˆ xZS )Ú
DbrxConfiga.  

    This is the configuration class to store the configuration of a [`DbrxModel`]. It is used to instantiate a Dbrx model according to the
    specified arguments, defining the model architecture. Instantiating a configuration with the
    defaults will yield a different configuration to that of the [databricks/dbrx-instruct](https://huggingface.co/databricks/dbrx-instruct) architecture.

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


    Args:
        d_model (`int`, *optional*, defaults to 2048):
            Dimensionality of the embeddings and hidden states.
        n_heads (`int`, *optional*, defaults to 16):
            Number of attention heads for each attention layer in the Transformer encoder.
        n_layers (`int`, *optional*, defaults to 24):
            Number of hidden layers in the Transformer encoder.
        max_seq_len (`int`, *optional*, defaults to 2048):
            The maximum sequence length of the model.
        vocab_size (`int`, *optional*, defaults to 32000):
            Vocabulary size of the Dbrx model. Defines the maximum number of different tokens that can be represented by
            the `inputs_ids` passed when calling [`DbrxModel`].
        resid_pdrop (`float`, *optional*, defaults to 0.0):
            The dropout probability applied to the attention output before combining with residual.
        emb_pdrop (`float`, *optional*, defaults to 0.0):
            The dropout probability for the embedding layer.
        attn_config (`dict`, *optional*):
            A dictionary used to configure the model's attention module.
        ffn_config (`dict`, *optional*):
            A dictionary used to configure the model's FFN module.
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return the last key/values attentions (not used by all models).
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        output_router_logits (`bool`, *optional*, defaults to `False`):
            Whether or not the router logits should be returned by the model. Enabling this will also
            allow the model to output the auxiliary loss. See [here]() for more details.


    Example:
    ```python
    >>> from transformers import DbrxConfig, DbrxModel

    >>> # Initializing a Dbrx configuration
    >>> configuration = DbrxConfig(n_layers=2, d_model=256, n_heads=8, vocab_size=128)

    >>> # Initializing a model (with random weights) from the configuration
    >>> model = DbrxModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```
    Údbrx)r
   r0   Ún_headsÚd_modelÚn_layersÚmax_seq_len)Únum_attention_headsÚhidden_sizeÚnum_hidden_layersÚmax_position_embeddingsÚ
vocab_sizeÚresid_pdropÚ	emb_pdropr
   r0   Ú	use_cacheÚinitializer_rangeÚoutput_router_logitsr   c                 ó  •— |€t        «       | _        n(t        |t        «      rt        di |¤Ž| _        n|| _        |	€t	        «       | _        n(t        |	t        «      rt	        di |	¤Ž| _        n|	| _        || _        || _        || _        || _	        || _
        || _        || _        |
| _        || _        || _        | j                  j                   | _        |j%                  dd«      }|rt'        d«      ‚t)        ‰| �T  dd|i|¤Ž y )NÚtie_word_embeddingsFz5tie_word_embeddings is not supported for DBRX models.r   )r	   r
   Ú
isinstancer<   r/   r0   rA   r@   rB   rC   rH   rI   rJ   rK   rL   rM   r   Únum_key_value_headsr   r   r   r   )r   rA   r@   rB   rC   rH   rI   rJ   r
   r0   rK   rL   rM   r   rO   r    s                  €r!   r   zDbrxConfig.__init__·   sü   ø€ ð  ÐÜ2Ó4ˆDÕÜ˜¤TÔ*Ü2ÑA°[ÑAˆDÕà*ˆDÔàÐÜ+›oˆD�OÜ˜
¤DÔ)Ü+Ñ9¨jÑ9ˆD�Oà(ˆDŒOàˆŒØˆŒØ ˆŒØ&ˆÔØ$ˆŒØ&ˆÔØ"ˆŒØ"ˆŒØ!2ˆÔØ$8ˆÔ!Ø#'×#3Ñ#3×#>Ñ#>ˆÔ à$Ÿj™jÐ)>ÀÓFÐÙÜÐTÓUÐUä‰ÑÑKÐ-@ÐKÀFÓKr"   )é   é   é   rR   i }  r#   r#   NNTg{®Gáz”?F)r%   r&   r'   r(   r   r	   r/   Úsub_configsÚattribute_mapr+   r*   r   Úboolr   r   r,   r-   s   @r!   r>   r>   w   s÷   ø„ ñ4ðl €JØ"5À]ÑS€Kà(Ø Ø'Ø#0ñ	€Mð ØØØØØ ØØ59Ø.2ØØ#'Ø%*ñ.Làð.Lð ð.Lð ð	.Lð
 ð.Lð ð.Lð ð.Lð ð.Lð Ð1Ñ2ð.Lð ˜]Ñ+ð.Lð ð.Lð !ð.Lð #ð.Lð ÷.Lñ .Lr"   r>   N)r(   Útypingr   r   Úconfiguration_utilsr   Úutilsr   Ú
get_loggerr%   Úloggerr	   r/   r>   Ú__all__r   r"   r!   ú<module>r^      s^   ðñ ç  å 3Ý ð 
ˆ×	Ñ	˜HÓ	%€ô&9Ð*ô &9ôR19Ð$ô 19ôhnLÐ!ô nLðb ˆ.�r"   