
    g8                         d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	  e	j
        e          Z G d de          Ze G d	 d
                      Ze G d d                      Ze G d d                      Zd ZdS )zESM model configuration    )asdict	dataclass)Optional   )PretrainedConfig)loggingc                   X     e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z fdZ xZS )	EsmConfigae  
    This is the configuration class to store the configuration of a [`ESMModel`]. It is used to instantiate a ESM model
    according to the specified arguments, defining the model architecture. Instantiating a configuration with the
    defaults will yield a similar configuration to that of the ESM
    [facebook/esm-1b](https://huggingface.co/facebook/esm-1b) architecture.

    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*):
            Vocabulary size of the ESM model. Defines the number of different tokens that can be represented by the
            `inputs_ids` passed when calling [`ESMModel`].
        mask_token_id (`int`, *optional*):
            The index of the mask token in the vocabulary. This must be included in the config because of the
            "mask-dropout" scaling trick, which will scale the inputs depending on the number of masked tokens.
        pad_token_id (`int`, *optional*):
            The index of the padding token in the vocabulary. This must be included in the config because certain parts
            of the ESM code use this instead of the attention mask.
        hidden_size (`int`, *optional*, defaults to 768):
            Dimensionality of the encoder layers and the pooler layer.
        num_hidden_layers (`int`, *optional*, defaults to 12):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 12):
            Number of attention heads for each attention layer in the Transformer encoder.
        intermediate_size (`int`, *optional*, defaults to 3072):
            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
        hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
        attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
            The dropout ratio for the attention probabilities.
        max_position_embeddings (`int`, *optional*, defaults to 1026):
            The maximum sequence length that this model might ever be used with. Typically set this to something large
            just in case (e.g., 512 or 1024 or 2048).
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        layer_norm_eps (`float`, *optional*, defaults to 1e-12):
            The epsilon used by the layer normalization layers.
        position_embedding_type (`str`, *optional*, defaults to `"absolute"`):
            Type of position embedding. Choose one of `"absolute"`, `"relative_key"`, `"relative_key_query", "rotary"`.
            For positional embeddings use `"absolute"`. For more information on `"relative_key"`, please refer to
            [Self-Attention with Relative Position Representations (Shaw et al.)](https://arxiv.org/abs/1803.02155).
            For more information on `"relative_key_query"`, please refer to *Method 4* in [Improve Transformer Models
            with Better Relative Position Embeddings (Huang et al.)](https://arxiv.org/abs/2009.13658).
        is_decoder (`bool`, *optional*, defaults to `False`):
            Whether the model is used as a decoder or not. If `False`, the model is used as an encoder.
        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`.
        emb_layer_norm_before (`bool`, *optional*):
            Whether to apply layer normalization after embeddings but before the main stem of the network.
        token_dropout (`bool`, defaults to `False`):
            When this is enabled, masked tokens are treated as if they had been dropped out by input dropout.

    Examples:

    ```python
    >>> from transformers import EsmModel, EsmConfig

    >>> # Initializing a ESM facebook/esm-1b style configuration >>> configuration = EsmConfig()

    >>> # Initializing a model from the configuration >>> model = ESMModel(configuration)

    >>> # Accessing the model configuration >>> configuration = model.config
    ```esmN         皙?  {Gz?-q=absoluteTFc                     t                      j        d||d| || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        || _        || _        |r|)t"                              d           t'                      }n!t)          |t*                    rt'          di |}|| _        |.t"                              d           t1                      | _        n|| _        nd | _        d | _        | j        %t5          | j        dd          rt7          d          d S d S )N)pad_token_idmask_token_idzCNo esmfold_config supplied for folding model, using default values.zHNo vocab_list supplied for folding model, assuming the ESM-2 vocabulary!use_esm_attn_mapFzOThe HuggingFace port of ESMFold does not support use_esm_attn_map at this time! )super__init__
vocab_sizehidden_sizenum_hidden_layersnum_attention_headsintermediate_sizehidden_dropout_probattention_probs_dropout_probmax_position_embeddingsinitializer_rangelayer_norm_epsposition_embedding_type	use_cacheemb_layer_norm_beforetoken_dropoutis_folding_modelloggerinfoEsmFoldConfig
isinstancedictesmfold_configwarningget_default_vocab_list
vocab_listgetattr
ValueError)selfr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r/   r2   kwargs	__class__s                        e/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/esm/configuration_esm.pyr   zEsmConfig.__init__c   sv   . 	Zl-ZZSYZZZ$&!2#6 !2#6 ,H)'>$!2,'>$"%:"* 0 	#%abbb!.ND11 A!.!@!@!@!@"0D!ijjj"8":":","&D"DO*wt7JL^`e/f/f*nooo +***    c                     t                                                      }t          | j        t                    r| j                                        |d<   |S )
        Serializes this instance to a Python dictionary. Override the default [`~PretrainedConfig.to_dict`].

        Returns:
            `Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
        r/   )r   to_dictr-   r/   r,   )r5   outputr7   s     r8   r<   zEsmConfig.to_dict   sM     ""d)=99 	E'+':'B'B'D'DF#$r9   )NNNr   r   r   r   r   r   r   r   r   r   TNFFNN)__name__
__module____qualname____doc__
model_typer   r<   __classcell__)r7   s   @r8   r
   r
      s        A AF J %( $ *")8p 8p 8p 8p 8p 8pt
 
 
 
 
 
 
 
 
r9   r
   c                       e Zd ZU dZeed<   dZeed<   dZeed<   dZ	eed<   dZ
eed<   d	Zeed
<   dZeed<   dZeed<   dZeed<   dZded<   d Zd ZdS )r,   Nesm_typeTfp16_esmFr   esm_ablate_pairwiseesm_ablate_sequencer   esm_input_dropoutembed_aa	bypass_lm   lddt_head_hid_dimTrunkConfigtrunkc                     | j         t                      | _         d S t          | j         t                    rt          di | j         | _         d S d S )Nr   )rO   rN   r-   r.   r5   s    r8   __post_init__zEsmFoldConfig.__post_init__   sR    :$DJJJ
D)) 	3$22tz22DJJJ	3 	3r9   c                 \    t          |           }| j                                        |d<   |S )r;   rO   )r   rO   r<   r5   r=   s     r8   r<   zEsmFoldConfig.to_dict   s+     *,,..wr9   )r>   r?   r@   rE   str__annotations__rF   boolr   rG   rH   rI   floatrJ   rK   rM   intrO   rR   r<   r   r9   r8   r,   r,      s         HcHd"d""" %%%% %%%% u   HdIt s   E=3 3 3	 	 	 	 	r9   r,   c                       e Zd ZU dZeed<   dZeed<   dZeed<   dZeed<   dZ	eed	<   dZ
eed
<   dZeed<   dZeed<   dZeed<   dZeed<   dZee         ed<   dZded<   d Zd ZdS )rN   0   
num_blocksi   sequence_state_dimrL   pairwise_state_dim    sequence_head_widthpairwise_head_widthposition_binsr   dropout
layer_dropFcpu_grad_checkpoint   max_recycles
chunk_sizeNStructureModuleConfigstructure_modulec           	      T   | j         t                      | _         n0t          | j         t                    rt          di | j         | _         | j        dk    rt          d| j         d          | j        | j        z  dk    r t          d| j         d| j         d          | j        | j        z  dk    r t          d| j         d| j         d          | j        | j        z  }| j        | j	        z  }| j        || j        z  k    r#t          d| j         d| d	| j         d          | j        || j	        z  k    r#t          d
| j         d| d	| j	         d          | j        dz  dk    rt          d| j         d          | j
        dk    rt          d| j
         d          d S )Nr   z'`max_recycles` should be positive, got .zM`sequence_state_dim` should be a round multiple of `sequence_state_dim`, got z and zM`pairwise_state_dim` should be a round multiple of `pairwise_state_dim`, got zW`sequence_state_dim` should be equal to `sequence_num_heads * sequence_head_width, got z != z * zW`pairwise_state_dim` should be equal to `pairwise_num_heads * pairwise_head_width, got    z)`pairwise_state_dim` should be even, got g?z.`dropout` should not be greater than 0.4, got r   )rj   ri   r-   r.   rg   r4   r]   r^   r`   ra   rc   )r5   sequence_num_headspairwise_num_headss      r8   rR   zTrunkConfig.__post_init__   s    ($9$;$;D!!-t44 	S$9$R$RD<Q$R$RD!!![tGX[[[\\\"T%<<AAM+M M262IM M M   "T%<<AAM+M M262IM M M  
 "48PP!48PP"&84;S&SSSd+d d1Cd dHLH`d d d   "&84;S&SSSd+d d1Cd dHLH`d d d   "Q&!++cI`cccddd<3]dl]]]^^^ r9   c                 \    t          |           }| j                                        |d<   |S )r;   rj   )r   rj   r<   rT   s     r8   r<   zTrunkConfig.to_dict   s.     %)%:%B%B%D%D!"r9   )r>   r?   r@   r\   rY   rV   r]   r^   r`   ra   rb   rc   rX   rd   re   rW   rg   rh   r   rj   rR   r<   r   r9   r8   rN   rN      s        J""""!!!!!!!!!!!!M3GUJ %%%%L# #J###04-444$_ $_ $_L	 	 	 	 	r9   rN   c                       e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   d	Z
eed
<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   d ZdS ) ri   a  
    Args:
        sequence_dim:
            Single representation channel dimension
        pairwise_dim:
            Pair representation channel dimension
        ipa_dim:
            IPA hidden channel dimension
        resnet_dim:
            Angle resnet (Alg. 23 lines 11-14) hidden channel dimension
        num_heads_ipa:
            Number of IPA heads
        num_qk_points:
            Number of query/key points to generate during IPA
        num_v_points:
            Number of value points to generate during IPA
        dropout_rate:
            Dropout rate used throughout the layer
        num_blocks:
            Number of structure module blocks
        num_transition_layers:
            Number of layers in the single representation transition (Alg. 23 lines 8-9)
        num_resnet_blocks:
            Number of blocks in the angle resnet
        num_angles:
            Number of angles to generate in the angle resnet
        trans_scale_factor:
            Scale of single representation transition hidden dimension
        epsilon:
            Small number used in angle resnet normalization
        inf:
            Large number used for attention masking
    i  sequence_dimrL   pairwise_dim   ipa_dim
resnet_dimr   num_heads_iparf   num_qk_points   num_v_pointsr   dropout_rater\      num_transition_layersrm   num_resnet_blocks   
num_angles
   trans_scale_factorg:0yE>epsilong     j@infc                      t          |           S )N)r   rQ   s    r8   r<   zStructureModuleConfig.to_dict@  s    d||r9   N)r>   r?   r@   rA   rr   rY   rV   rs   ru   rv   rw   rx   rz   r{   rX   r\   r}   r~   r   r   r   r   r<   r   r9   r8   ri   ri     s%           D L#L#GSJM3M3L#L%J!"3"""sJ    GUC    r9   ri   c                      dS )N)!z<cls>z<pad>z<eos>z<unk>LAGVSERTIDPKQNFYMHWCXBUZOrl   -z<null_1>z<mask>r   r   r9   r8   r1   r1   D  s    " "r9   N)rA   dataclassesr   r   typingr   configuration_utilsr   utilsr   
get_loggerr>   r*   r
   r,   rN   ri   r1   r   r9   r8   <module>r      s[     ) ) ) ) ) ) ) )       3 3 3 3 3 3       
	H	%	%
J J J J J  J J JZ        @ = = = = = = = =@ 4 4 4 4 4 4 4 4n# # # # #r9   