

import warnings

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__UpperCAmelCase    				=     logging.get_logger(__name__)

__UpperCAmelCase    				=     {
    'xlnet-base-cased': 'https://huggingface.co/xlnet-base-cased/resolve/main/config.json',
    'xlnet-large-cased': 'https://huggingface.co/xlnet-large-cased/resolve/main/config.json',
}





class A__    ( _snake_case ):



 """simple docstring"""







 _lowercase     :					Any      =						'''xlnet'''
 _lowercase     :					Any      =						['''mems''']
 _lowercase     :					Optional[Any]      =						{
     '''n_token''': '''vocab_size''',  # Backward compatibility
     '''hidden_size''': '''d_model''',
     '''num_attention_heads''': '''n_head''',
     '''num_hidden_layers''': '''n_layer''',
 }

 def __init__(		self :	int     ,						A_ :	List[Any]=3_2_0_0_0     ,						A_ :	Optional[Any]=1_0_2_4     ,						A_ :	str=2_4     ,						A_ :	Optional[Any]=1_6     ,						A_ :	List[Any]=4_0_9_6     ,						A_ :	List[Any]="gelu"     ,						A_ :	Any=True     ,						A_ :	List[str]="bi"     ,						A_ :	Dict=0.02     ,						A_ :	Tuple=1E-12     ,						A_ :	str=0.1     ,						A_ :	Union[str, Any]=5_1_2     ,						A_ :	List[Any]=None     ,						A_ :	Dict=True     ,						A_ :	Dict=False     ,						A_ :	str=False     ,						A_ :	Tuple=-1     ,						A_ :	str=False     ,						A_ :	Any="last"     ,						A_ :	Union[str, Any]=True     ,						A_ :	Union[str, Any]="tanh"     ,						A_ :	int=0.1     ,						A_ :	Optional[int]=5     ,						A_ :	List[str]=5     ,						A_ :	Dict=5     ,						A_ :	str=1     ,						A_ :	Dict=2     ,						**A_ :	Tuple     ,						):






      '''simple docstring'''




      _lowerCAmelCase   :					Dict        =    vocab_size
      _lowerCAmelCase   :					int        =    d_model
      _lowerCAmelCase   :					List[Any]        =    n_layer
      _lowerCAmelCase   :					Optional[Any]        =    n_head
      if d_model % n_head != 0:
           raise ValueError(F'''\'d_model % n_head\' ({d_model % n_head}) should be equal to 0'''       )
      if "d_head" in kwargs:
           if kwargs["d_head"] != d_model // n_head:
                raise ValueError(
                    F'''`d_head` ({kwargs['d_head']}) should be equal to `d_model // n_head` ({d_model // n_head})'''       )
      _lowerCAmelCase   :					Any        =    d_model // n_head
      _lowerCAmelCase   :					Optional[Any]        =    ff_activation
      _lowerCAmelCase   :					Any        =    d_inner
      _lowerCAmelCase   :					Union[str, Any]        =    untie_r
      _lowerCAmelCase   :					Dict        =    attn_type

      _lowerCAmelCase   :					List[str]        =    initializer_range
      _lowerCAmelCase   :					Union[str, Any]        =    layer_norm_eps

      _lowerCAmelCase   :					Dict        =    dropout
      _lowerCAmelCase   :					Tuple        =    mem_len
      _lowerCAmelCase   :					Union[str, Any]        =    reuse_len
      _lowerCAmelCase   :					Any        =    bi_data
      _lowerCAmelCase   :					str        =    clamp_len
      _lowerCAmelCase   :					str        =    same_length

      _lowerCAmelCase   :					Any        =    summary_type
      _lowerCAmelCase   :					int        =    summary_use_proj
      _lowerCAmelCase   :					Optional[Any]        =    summary_activation
      _lowerCAmelCase   :					Dict        =    summary_last_dropout
      _lowerCAmelCase   :					str        =    start_n_top
      _lowerCAmelCase   :					Dict        =    end_n_top

      _lowerCAmelCase   :					str        =    bos_token_id
      _lowerCAmelCase   :					Any        =    pad_token_id
      _lowerCAmelCase   :					Tuple        =    eos_token_id

      if "use_cache" in kwargs:
           warnings.warn(
               "The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`"
               " instead."     ,						lowerCAmelCase__     ,						)
           _lowerCAmelCase   :					List[str]        =    kwargs["use_cache"]

      _lowerCAmelCase   :					Dict        =    use_mems_eval
      _lowerCAmelCase   :					int        =    use_mems_train
      super().__init__(pad_token_id=lowerCAmelCase__     ,						bos_token_id=lowerCAmelCase__     ,						eos_token_id=lowerCAmelCase__     ,						**lowerCAmelCase__       )

 @property
 def    __magic_name__       (		self :	Dict       ):






      '''simple docstring'''




      logger.info(F'''The model {self.model_type} is one of the few models that has no sequence length limit.'''       )
      return -1


 @max_position_embeddings.setter
 def    __magic_name__       (		self :	List[str]     ,						A_ :	int       ):






      '''simple docstring'''




      raise NotImplementedError(
          F'''The model {self.model_type} is one of the few models that has no sequence length limit.'''       )









from typing import Dict

import numpy as np
import torch

from . import residue_constants as rc
from .tensor_utils import tensor_tree_map, tree_map







def 	_snake_case		(    SCREAMING_SNAKE_CASE				)       ->      Dict[str, torch.Tensor]:

     """simple docstring"""







     _lowerCAmelCase   :					int        =    []
     _lowerCAmelCase   :					Tuple        =    []
     _lowerCAmelCase   :					List[Any]        =    []

     for rt in rc.restypes:
          _lowerCAmelCase   :					int        =    rc.restype_name_to_atomaa_names[rc.restype_atoa[rt]]
          restype_atomaa_to_atomaa_list.append([(rc.atom_order[name] if name else 0) for name in atom_names]				)
          _lowerCAmelCase   :					str        =    {name: i for i, name in enumerate(SCREAMING_SNAKE_CASE				)}
          restype_atomaa_to_atomaa_list.append(
              [(atom_name_to_idxaa[name] if name in atom_name_to_idxaa else 0) for name in rc.atom_types]				)

          restype_atomaa_mask_list.append([(1.0 if name else 0.0) for name in atom_names]				)

     # Add dummy mapping for restype 'UNK'
     restype_atomaa_to_atomaa_list.append([0] * 14				)
     restype_atomaa_to_atomaa_list.append([0] * 37				)
     restype_atomaa_mask_list.append([0.0] * 14				)

     _lowerCAmelCase   :					List[str]        =    torch.tensor(
         SCREAMING_SNAKE_CASE		,							dtype=torch.intaa		,							device=protein["aatype"].device		,							)
     _lowerCAmelCase   :					str        =    torch.tensor(
         SCREAMING_SNAKE_CASE		,							dtype=torch.intaa		,							device=protein["aatype"].device		,							)
     _lowerCAmelCase   :					Optional[Any]        =    torch.tensor(
         SCREAMING_SNAKE_CASE		,							dtype=torch.floataa		,							device=protein["aatype"].device		,							)
     _lowerCAmelCase   :					List[str]        =    protein["aatype"].to(torch.long				)

     # create the mapping for (residx, atom14) --> atom37, i.e. an array
     # with shape (num_res, 14) containing the atom37 indices for this protein
     _lowerCAmelCase   :					Dict        =    restype_atomaa_to_atomaa[protein_aatype]
     _lowerCAmelCase   :					Optional[Any]        =    restype_atomaa_mask[protein_aatype]

     _lowerCAmelCase   :					Any        =    residx_atomaa_mask
     _lowerCAmelCase   :					Dict        =    residx_atomaa_to_atomaa.long()

     # create the gather indices for mapping back
     _lowerCAmelCase   :					Optional[int]        =    restype_atomaa_to_atomaa[protein_aatype]
     _lowerCAmelCase   :					str        =    residx_atomaa_to_atomaa.long()

     # create the corresponding mask
     _lowerCAmelCase   :					Dict        =    torch.zeros([21, 37]		,							dtype=torch.floataa		,							device=protein["aatype"].device				)
     for restype, restype_letter in enumerate(rc.restypes				):
          _lowerCAmelCase   :					Optional[Any]        =    rc.restype_atoa[restype_letter]
          _lowerCAmelCase   :					int        =    rc.residue_atoms[restype_name]
          for atom_name in atom_names:
               _lowerCAmelCase   :					Union[str, Any]        =    rc.atom_order[atom_name]
               _lowerCAmelCase   :					Dict        =    1

     _lowerCAmelCase   :					Tuple        =    restype_atomaa_mask[protein_aatype]
     _lowerCAmelCase   :					List[str]        =    residx_atomaa_mask

     return protein







def 	_snake_case		(    SCREAMING_SNAKE_CASE				)       ->      Dict[str, np.ndarray]:

     """simple docstring"""







     _lowerCAmelCase   :					Any        =    tree_map(lambda SCREAMING_SNAKE_CASE				: torch.tensor(SCREAMING_SNAKE_CASE		,							device=batch["aatype"].device				)		,							SCREAMING_SNAKE_CASE		,							np.ndarray				)
     _lowerCAmelCase   :					Optional[int]        =    tensor_tree_map(lambda SCREAMING_SNAKE_CASE				: np.array(SCREAMING_SNAKE_CASE				)		,							make_atomaa_masks(SCREAMING_SNAKE_CASE				)				)
     return out






