
    i\&                        d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZmZ  e	j                  e      Ze G d d	e             Ze G d
 de             Ze G d de             Z ed      e G d de                    Zd ZdgZy)zESM model configuration    )Union)strict   )PreTrainedConfig)auto_docstringlogging)intervalis_divisible_byc                   >   e Zd ZU dZdZedz  ed<   dZedz  ed<   dZedz  ed<   dZ	edz  ed	<   d
Z
edz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   y)StructureModuleConfiga  
    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  Nsequence_dim   pairwise_dim   ipa_dim
resnet_dim   num_heads_ipa   num_qk_points   num_v_points皙?dropout_rate
num_blocks   num_transition_layers   num_resnet_blocks   
num_angles
   trans_scale_factorg:0yE>epsilong     j@inf)__name__
__module____qualname____doc__r   int__annotations__r   r   r   r   r   r   r   floatr   r   r   r!   r#   r$   r%        z/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/transformers/models/esm/configuration_esm.pyr   r      s     D  #L#*""L#*"GS4Z Jd
  "M3:" !M3:! L#* !$L%$,$Jd
()3:)$%sTz%Jd
%'d
' GUT\ Cr.   r   c                       e Zd ZU deiZdZedz  ed<   dZedz  ed<     e	d      d	
      Z
edz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<     ed      d
      Zeez  dz  ed<   dZeez  dz  ed<   dZedz  ed<     ed      d
      Zedz  ed<   d	Zedz  ed<   dZeedf   dz  ed<    fdZd Z xZS )TrunkConfigstructure_module0   Nr   i   sequence_state_dimr   )divisorr   )defaultpairwise_state_dim    sequence_head_widthpairwise_head_widthposition_binsg?)max        dropout
layer_dropFcpu_grad_checkpointr   )minr   max_recycles
chunk_sizer   c                     | j                   t               | _         n4t        | j                   t              rt        di | j                   | _         t	        |   di | y Nr-   )r2   r   
isinstancedictsuper__post_init__selfkwargs	__class__s     r/   rI   zTrunkConfig.__post_init__b   sP      ($9$;D!--t4$9$RD<Q<Q$RD!''r.   c           	         | j                   | j                   z  dk7  r&t        d| j                    d| j                    d      | j                  | j                  z  dk7  r&t        d| j                   d| j                   d      | j                   | j                  z  }| j                  | j                  z  }| j                   || j                  z  k7  r)t        d| j                    d| d| j                   d      | j                  || j                  z  k7  r)t        d	| j                   d| d| j                   d      y )
Nr   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 )r4   
ValueErrorr7   r9   r:   )rK   sequence_num_headspairwise_num_headss      r/   validate_architecturez!TrunkConfig.validate_architecturei   s   ""T%<%<<A++,E$2I2I1J!M  ""T%<%<<A++,E$2I2I1J!M 
 "448P8PP!448P8PP""&84;S;S&SS++,D1C0DCH`H`Gaabd  ""&84;S;S&SS++,D1C0DCH`H`Gaabd  Tr.   )r&   r'   r(   r   sub_configsr   r*   r+   r4   r
   r7   r9   r:   r;   r	   r>   r,   r?   r@   boolrB   rC   r2   r   rG   rI   rS   __classcell__rM   s   @r/   r1   r1   Q   s    %'<=KJd
%)d
)%?_Q%?%Ld
L&(t(&(t( "M3:""3(s"3C"@GUS[4@%(Jd"(',,.xAq9L#*9 Jd
 DHeD"99:TAH(r.   r1   c                        e Zd ZU deiZdZedz  ed<   dZe	dz  ed<   dZ
e	dz  ed<   dZe	dz  ed<   dZe	dz  ed	<   d
Zeez  dz  ed<   dZe	dz  ed<   dZe	dz  ed<   dZedz  ed<   dZeedf   dz  ed<    fdZ xZS )EsmFoldConfigtrunkNesm_typeTfp16_esmFuse_esm_attn_mapesm_ablate_pairwiseesm_ablate_sequencer=   esm_input_dropoutembed_aa	bypass_lmr   lddt_head_hid_dimr1   c                     | j                   t               | _         n4t        | j                   t              rt        di | j                   | _         t	        |   di | y rE   )rZ   r1   rF   rG   rH   rI   rJ   s     r/   rI   zEsmFoldConfig.__post_init__   sG    ::$DJ

D)$2tzz2DJ''r.   )r&   r'   r(   r1   rT   r[   strr+   r\   rU   r]   r^   r_   r`   r,   r*   ra   rb   rc   rZ   r   rG   rI   rV   rW   s   @r/   rY   rY      s    K(KHcDj HdTk $)dTk)',,',,,/us{T)/ HdTk "Itd{"$'sTz'/3E5}$%,3( (r.   rY   zfacebook/esm-1b)
checkpointc                       e Zd ZU dZdZdeiZdZedz  e	d<   dZ
edz  e	d<   dZedz  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dz  e	d<   dZedz  e	d<   dZee	d<   dZee	d<   dZedz  e	d<   dZedz  e	d<   dZee	d<   dZedz  e	d<   dZedz  e	d<   dZedz  e	d<   dZeez  dz  e	d<   dZe e   e!ed f   z  dz  e	d!<   dZ"edz  e	d"<   dZ#edz  e	d#<   dZ$ee	d$<    fd%Z% xZ&S )&	EsmConfigae  
    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.
    position_embedding_type (`str`, *optional*, defaults to `"absolute"`):
        Type of position embedding. Choose either `"absolute"` or "rotary"`.
    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.
    is_folding_model (`bool`, defaults to `False`):
        When this is enabled, ESMFold model will be initialized.
    esmfold_config (`dict`, *optional*):
        Configuration to initiate the ESMFold module.
    vocab_list (`list`, *optional*):
        List of the vocabulary items.

    Examples:

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

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

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

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```esmesmfold_configN
vocab_sizemask_token_idpad_token_idi   hidden_sizer   num_hidden_layersnum_attention_headsi   intermediate_sizer   hidden_dropout_probattention_probs_dropout_probi  max_position_embeddingsg{Gz?initializer_rangeg-q=layer_norm_epsabsoluteposition_embedding_typeT	use_cacheemb_layer_norm_beforeFtoken_dropoutis_folding_model.
vocab_list
is_decoderadd_cross_attentiontie_word_embeddingsc                    | j                   r| j                  %t        j                  d       t	               | _        n4t        | j                  t              rt	        di | j                  | _        | j                  3t        j                  d       t               | _        nd | _        d | _        | j                  "t        | j                  dd      rt        d      t        | 4  di | y )NzCNo esmfold_config supplied for folding model, using default values.zHNo vocab_list supplied for folding model, assuming the ESM-2 vocabulary!r]   FzOThe HuggingFace port of ESMFold does not support use_esm_attn_map at this time!r-   )r|   rj   loggerinforY   rF   rG   r}   warningget_default_vocab_listgetattrrP   rH   rI   rJ   s     r/   rI   zEsmConfig.__post_init__   s      ""*ab&3o#D//6&3&Jd6I6I&J#&ij"8":"&D"DO*wt7J7JL^`e/fnoo''r.   )'r&   r'   r(   r)   
model_typerY   rT   rk   r*   r+   rl   rm   rn   ro   rp   rq   rr   r,   rs   rt   ru   rv   rx   re   ry   rU   rz   r{   r|   rj   rG   r}   listtupler~   r   r   rI   rV   rW   s   @r/   rh   rh      s\   @ J#]3K!Jd
! $M3:$#L#*#Ks!!!s!(++14 %$,4#'S'#u##(NEDL(*4S4Z4It)-4$;-!&M4$;&$)dTk)26ND=(4/659JS	E#s(O+d29#Jt#',, $$( (r.   rh   c                       y)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OrO   -z<null_1>z<mask>r-   r-   r.   r/   r   r      s    "r.   N)r)   typingr   huggingface_hub.dataclassesr   configuration_utilsr   utilsr   r   utils.type_validatorsr	   r
   
get_loggerr&   r   r   r1   rY   rh   r   __all__r-   r.   r/   <module>r      s      . 3 , > 
		H	% 1, 1 1h /" / /d ($ ( (, ,-M(  M(  .M(`#L -r.   