






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 						_a    (      a :Dict[str, torch.Tensor] )							->			Dict[str, torch.Tensor]:
 a		  =      []
 a		  =      []
 a		  =      []

 for rt in rc.restypes:
  a		  =      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] )
  a		  =      {name: i for i, name in enumerate(a )}
  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 )

 a		  =      torch.tensor(
     a	,							dtype=torch.intaa	,							device=protein['''aatype'''].device	,							)
 a		  =      torch.tensor(
     a	,							dtype=torch.intaa	,							device=protein['''aatype'''].device	,							)
 a		  =      torch.tensor(
     a	,							dtype=torch.floataa	,							device=protein['''aatype'''].device	,							)
 a		  =      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
 a		  =      restype_atomaa_to_atomaa[protein_aatype]
 a		  =      restype_atomaa_mask[protein_aatype]

 a		  =      residx_atomaa_mask
 a		  =      residx_atomaa_to_atomaa.long()

 # create the gather indices for mapping back
 a		  =      restype_atomaa_to_atomaa[protein_aatype]
 a		  =      residx_atomaa_to_atomaa.long()

 # create the corresponding mask
 a		  =      torch.zeros([21, 37]	,							dtype=torch.floataa	,							device=protein['''aatype'''].device )
 for restype, restype_letter in enumerate(rc.restypes ):
  a		  =      rc.restype_atoa[restype_letter]
  a		  =      rc.residue_atoms[restype_name]
  for atom_name in atom_names:
   a		  =      rc.atom_order[atom_name]
   a		  =      1

 a		  =      restype_atomaa_mask[protein_aatype]
 a		  =      residx_atomaa_mask

 return protein

def 						_a    (      a :Dict[str, torch.Tensor] )							->			Dict[str, np.ndarray]:
 a		  =      tree_map(lambda a : torch.tensor(a	,							device=batch['''aatype'''].device )	,							a	,							np.ndarray )
 a		  =      tensor_tree_map(lambda a : np.array(a )	,							make_atomaa_masks(a ) )
 return out










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


UpperCAmelCase__				   =		logging.get_logger(__name__)

UpperCAmelCase__				   =		{}






class 		lowercase_					(	lowercase   ):






      '''simple docstring'''




      __snake_case       =  '''llama'''
      __snake_case       =  ['''past_key_values''']







      def __init__(      self      :						Optional[Any] ,					__UpperCAmelCase      :						Union[str, Any]=32_000 ,					__UpperCAmelCase      :						str=4_096 ,					__UpperCAmelCase      :						int=11_008 ,					__UpperCAmelCase      :						Tuple=32 ,					__UpperCAmelCase      :						Optional[int]=32 ,					__UpperCAmelCase      :						List[str]=None ,					__UpperCAmelCase      :						Union[str, Any]="silu" ,					__UpperCAmelCase      :						Tuple=2_048 ,					__UpperCAmelCase      :						Optional[Any]=0.02 ,					__UpperCAmelCase      :						Any=1e-6 ,					__UpperCAmelCase      :						Union[str, Any]=True ,					__UpperCAmelCase      :						Optional[int]=0 ,					__UpperCAmelCase      :						Optional[int]=1 ,					__UpperCAmelCase      :						Optional[int]=2 ,					__UpperCAmelCase      :						Tuple=1 ,					__UpperCAmelCase      :						List[str]=False ,					__UpperCAmelCase      :						Tuple=None ,					**__UpperCAmelCase      :						Tuple ,					)    ->str:




       """simple docstring"""


       a		  =      vocab_size
       a		  =      max_position_embeddings
       a		  =      hidden_size
       a		  =      intermediate_size
       a		  =      num_hidden_layers
       a		  =      num_attention_heads

       # for backward compatibility
       if num_key_value_heads is None:
        a		  =      num_attention_heads

       a		  =      num_key_value_heads
       a		  =      hidden_act
       a		  =      initializer_range
       a		  =      rms_norm_eps
       a		  =      pretraining_tp
       a		  =      use_cache
       a		  =      rope_scaling
       self._rope_scaling_validation()

       super().__init__(
           pad_token_id=__UpperCAmelCase ,					bos_token_id=__UpperCAmelCase ,					eos_token_id=__UpperCAmelCase ,					tie_word_embeddings=__UpperCAmelCase ,					**__UpperCAmelCase ,					)







      def       __lowerCAmelCase					(      self      :						Tuple  )    ->Tuple:




       """simple docstring"""


       if self.rope_scaling is None:
        return

       if not isinstance(self.rope_scaling ,					__UpperCAmelCase  ) or len(self.rope_scaling  ) != 2:
        raise ValueError(
            '''`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '''
            F"""got {self.rope_scaling}"""  )
       a		  =      self.rope_scaling.get('''type''' ,					__UpperCAmelCase  )
       a		  =      self.rope_scaling.get('''factor''' ,					__UpperCAmelCase  )
       if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
        raise ValueError(
            F"""`rope_scaling`'s name field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"""  )
       if rope_scaling_factor is None or not isinstance(__UpperCAmelCase ,					__UpperCAmelCase  ) or rope_scaling_factor <= 1.0:
        raise ValueError(F"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""  )


