o
    ei(                     @   sx   d Z ddlmZ ddlmZ ddlmZ ddlmZ e	e
ZG dd deZG d	d
 d
eZG dd deZdgZdS )zDBRX model configuration    )Any   )PreTrainedConfig)RopeParameters)loggingc                	       sB   e Zd ZdZdZ			ddededB ded	ef fd
dZ  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.
    attn_config        N   
attn_pdropclip_qkv
kv_n_headskwargsc                    s(   t  jdi | || _|| _|| _d S )N )super__init__r   r   r   )selfr   r   r   r   	__class__r   i/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/transformers/models/dbrx/configuration_dbrx.pyr   .   s   
zDbrxAttentionConfig.__init__)r	   Nr
   )
__name__
__module____qualname____doc__base_config_keyfloatintr   r   __classcell__r   r   r   r   r      s    r   c                       sd   e Zd ZdZdZ									dd
edB dededededB dededB def fddZ	  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   N      r
   {Gz?      ?
ffn_act_fnffn_hidden_sizemoe_num_experts	moe_top_kmoe_jitter_epsmoe_loss_weightmoe_normalize_expert_weightsr   c	                    s   t    |d u rddi}|| _|| _|| _|| _|| _|| _|| _|| _	dD ]}
|
|	v r2|	
|
 q't|	dkr@td|	d S )Nnamesilu)
model_typeattn_implementationexperts_implementationtransformers_version_commit_hashtorch_dtypedtyper   zFound unknown kwargs=)r   r   hidden_sizer%   r&   r'   r(   r)   r*   r+   poplen
ValueError)r   r5   r%   r&   r'   r(   r)   r*   r+   r   kr   r   r   r   R   s$   
	
zDbrxFFNConfig.__init__)r    Nr!   r"   r
   Nr#   r$   )r   r   r   r   r   dictr   r   r   r   r   r   r   r   r   r   ;   s8    	
r   c                %       s   e Zd ZdZdZeedZdddddZ			
																d"de	dB de	dB de	dB de	dB de	dB de
dB de
dB dedB dedB dedB de
dB dedB deeeef B dB de	dB de	dB de	dB dedB def$ fd d!Z  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 [transformers-community/dbrx-instruct](https://huggingface.co/transformers-community/dbrx-instruct) architecture.
    Note: this link points to a re-upload; the original repository is closed.

    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   r   n_headsd_modeln_layersmax_seq_len)num_attention_headsr5   num_hidden_layersmax_position_embeddings          }  r	   NT{Gz?F
vocab_sizeresid_pdrop	emb_pdropr   r   	use_cacheinitializer_rangeoutput_router_logitsrope_parameterspad_token_idbos_token_ideos_token_idtie_word_embeddingsr   c                    s   |d u r	t  | _nt|trt di || _n|| _|	d u r#t | _nt|	tr1tdi |	| _n|	| _|| _|| _|| _|| _	|| _
|| _|| _|
| _|| _|| _| jj| _|r]td|| _|| _|| _|| _|| _t jdi | d S )Nz5tie_word_embeddings is not supported for DBRX models.r   )r   r   
isinstancer:   r   r   r>   r=   r?   r@   rI   rJ   rK   rL   rM   rN   r   num_key_value_headsr8   rP   rQ   rR   rS   rO   r   r   )r   r>   r=   r?   r@   rI   rJ   rK   r   r   rL   rM   rN   rO   rP   rQ   rR   rS   r   r   r   r   r      s:   




zDbrxConfig.__init__)rD   rE   rF   rD   rG   r	   r	   NNTrH   FNNNNF)r   r   r   r   r.   r   r   sub_configsattribute_mapr   r   boolr   r:   strr   r   r   r   r   r   r   r;   y   s~    7
		
r;   N)r   typingr   configuration_utilsr   modeling_rope_utilsr   utilsr   
get_loggerr   loggerr   r   r;   __all__r   r   r   r   <module>   s   
!>
{