





from dataclasses import asdict, dataclass
from typing import Optional

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


_A :   int  			=  logging.get_logger(__name__)

# TODO Update this
_A :   List[Any]  			=  {
    'facebook/esm-1b': 'https://huggingface.co/facebook/esm-1b/resolve/main/config.json',
    # See all ESM models at https://huggingface.co/models?filter=esm
}


class        __SCREAMING_SNAKE_CASE      (			lowerCAmelCase_ ):
       _UpperCAmelCase				:  str			   =   "esm"







       def __init__(				self					:     int		, A					:     int=None		, A					:     List[str]=None		, A					:     Union[str, Any]=None		, A					:     Optional[int]=7_6_8		, A					:     Optional[Any]=1_2		, A					:     Any=1_2		, A					:     str=3_0_7_2		, A					:     str=0.1		, A					:     Dict=0.1		, A					:     str=1_0_2_6		, A					:     Union[str, Any]=0.02		, A					:     Dict=1e-12		, A					:     str="absolute"		, A					:     str=True		, A					:     Union[str, Any]=None		, A					:     Dict=False		, A					:     List[str]=False		, A					:     List[str]=None		, A					:     List[str]=None		, **A					:     int		, )       ->Tuple:
         super().__init__(pad_token_id=A		, mask_token_id=A		, **A      )

         lowerCamelCase__       :						List[Any]        =							vocab_size
         lowerCamelCase__       :						Union[str, Any]        =							hidden_size
         lowerCamelCase__       :						Union[str, Any]        =							num_hidden_layers
         lowerCamelCase__       :						Dict        =							num_attention_heads
         lowerCamelCase__       :						int        =							intermediate_size
         lowerCamelCase__       :						Dict        =							hidden_dropout_prob
         lowerCamelCase__       :						List[Any]        =							attention_probs_dropout_prob
         lowerCamelCase__       :						Any        =							max_position_embeddings
         lowerCamelCase__       :						Optional[Any]        =							initializer_range
         lowerCamelCase__       :						Tuple        =							layer_norm_eps
         lowerCamelCase__       :						List[Any]        =							position_embedding_type
         lowerCamelCase__       :						Dict        =							use_cache
         lowerCamelCase__       :						int        =							emb_layer_norm_before
         lowerCamelCase__       :						Dict        =							token_dropout
         lowerCamelCase__       :						Optional[int]        =							is_folding_model
         if is_folding_model:
           if esmfold_config is None:
             logger.info('''No esmfold_config supplied for folding model, using default values.'''      )
             lowerCamelCase__       :						Tuple        =							EsmFoldConfig()
           elif isinstance(A		, A      ):
             lowerCamelCase__       :						int        =							EsmFoldConfig(**A      )
           lowerCamelCase__       :						Any        =							esmfold_config
           if vocab_list is None:
             logger.warning('''No vocab_list supplied for folding model, assuming the ESM-2 vocabulary!'''      )
             lowerCamelCase__       :						List[str]        =							get_default_vocab_list()
           else:
             lowerCamelCase__       :						Any        =							vocab_list
         else:
           lowerCamelCase__       :						Optional[Any]        =							None
           lowerCamelCase__       :						Union[str, Any]        =							None
         if self.esmfold_config is not None and getattr(self.esmfold_config		, '''use_esm_attn_map'''		, A      ):
           raise ValueError('''The HuggingFace port of ESMFold does not support use_esm_attn_map at this time!'''      )







       def 						__lowerCamelCase   (				self					:     Dict      )       ->Optional[int]:
         lowerCamelCase__       :						List[Any]        =							super().to_dict()
         if isinstance(self.esmfold_config		, A      ):
           lowerCamelCase__       :						List[str]        =							self.esmfold_config.to_dict()
         return output


@dataclass
class        __SCREAMING_SNAKE_CASE      :
       _UpperCAmelCase				:  str			   =   None
       _UpperCAmelCase				:  bool			   =   True
       _UpperCAmelCase				:  bool			   =   False
       _UpperCAmelCase				:  bool			   =   False
       _UpperCAmelCase				:  bool			   =   False
       _UpperCAmelCase				:  float			   =   0

       _UpperCAmelCase				:  bool			   =   True
       _UpperCAmelCase				:  bool			   =   False

       _UpperCAmelCase				:  int			   =   1_2_8
       _UpperCAmelCase				:  "TrunkConfig"			   =   None







       def 						__lowerCamelCase   (				self					:     Dict      )       ->Any:
         if self.trunk is None:
           lowerCamelCase__       :						List[Any]        =							TrunkConfig()
         elif isinstance(self.trunk		, A      ):
           lowerCamelCase__       :						List[str]        =							TrunkConfig(**self.trunk      )







       def 						__lowerCamelCase   (				self					:     Dict      )       ->List[Any]:
         lowerCamelCase__       :						Optional[int]        =							asdict(self      )
         lowerCamelCase__       :						Optional[Any]        =							self.trunk.to_dict()
         return output


@dataclass
class        __SCREAMING_SNAKE_CASE      :
       _UpperCAmelCase				:  int			   =   4_8
       _UpperCAmelCase				:  int			   =   1_0_2_4
       _UpperCAmelCase				:  int			   =   1_2_8
       _UpperCAmelCase				:  int			   =   3_2
       _UpperCAmelCase				:  int			   =   3_2
       _UpperCAmelCase				:  int			   =   3_2
       _UpperCAmelCase				:  float			   =   0
       _UpperCAmelCase				:  float			   =   0
       _UpperCAmelCase				:  bool			   =   False
       _UpperCAmelCase				:  int			   =   4
       _UpperCAmelCase				:  Optional[int]			   =   1_2_8
       _UpperCAmelCase				:  "StructureModuleConfig"			   =   None







       def 						__lowerCamelCase   (				self					:     int      )       ->Union[str, Any]:
         if self.structure_module is None:
           lowerCamelCase__       :						Optional[Any]        =							StructureModuleConfig()
         elif isinstance(self.structure_module		, A      ):
           lowerCamelCase__       :						str        =							StructureModuleConfig(**self.structure_module      )

         if self.max_recycles <= 0:
           raise ValueError(F"`max_recycles` should be positive, got {self.max_recycles}."      )
         if self.sequence_state_dim % self.sequence_state_dim != 0:
           raise ValueError(
               '''`sequence_state_dim` should be a round multiple of `sequence_state_dim`, got'''
               F" {self.sequence_state_dim} and {self.sequence_state_dim}."      )
         if self.pairwise_state_dim % self.pairwise_state_dim != 0:
           raise ValueError(
               '''`pairwise_state_dim` should be a round multiple of `pairwise_state_dim`, got'''
               F" {self.pairwise_state_dim} and {self.pairwise_state_dim}."      )

         lowerCamelCase__       :						List[str]        =							self.sequence_state_dim // self.sequence_head_width
         lowerCamelCase__       :						int        =							self.pairwise_state_dim // self.pairwise_head_width

         if self.sequence_state_dim != sequence_num_heads * self.sequence_head_width:
           raise ValueError(
               '''`sequence_state_dim` should be equal to `sequence_num_heads * sequence_head_width, got'''
               F" {self.sequence_state_dim} != {sequence_num_heads} * {self.sequence_head_width}."      )
         if self.pairwise_state_dim != pairwise_num_heads * self.pairwise_head_width:
           raise ValueError(
               '''`pairwise_state_dim` should be equal to `pairwise_num_heads * pairwise_head_width, got'''
               F" {self.pairwise_state_dim} != {pairwise_num_heads} * {self.pairwise_head_width}."      )
         if self.pairwise_state_dim % 2 != 0:
           raise ValueError(F"`pairwise_state_dim` should be even, got {self.pairwise_state_dim}."      )

         if self.dropout >= 0.4:
           raise ValueError(F"`dropout` should not be greater than 0.4, got {self.dropout}."      )







       def 						__lowerCamelCase   (				self					:     List[str]      )       ->Dict:
         lowerCamelCase__       :						Optional[Any]        =							asdict(self      )
         lowerCamelCase__       :						Tuple        =							self.structure_module.to_dict()
         return output


@dataclass
class        __SCREAMING_SNAKE_CASE      :
       _UpperCAmelCase				:  int			   =   3_8_4
       _UpperCAmelCase				:  int			   =   1_2_8
       _UpperCAmelCase				:  int			   =   1_6
       _UpperCAmelCase				:  int			   =   1_2_8
       _UpperCAmelCase				:  int			   =   1_2
       _UpperCAmelCase				:  int			   =   4
       _UpperCAmelCase				:  int			   =   8
       _UpperCAmelCase				:  float			   =   0.1
       _UpperCAmelCase				:  int			   =   8
       _UpperCAmelCase				:  int			   =   1
       _UpperCAmelCase				:  int			   =   2
       _UpperCAmelCase				:  int			   =   7
       _UpperCAmelCase				:  int			   =   1_0
       _UpperCAmelCase				:  float			   =   1e-8
       _UpperCAmelCase				:  float			   =   1e5







       def 						__lowerCamelCase   (				self					:     str      )       ->str:
         return asdict(self      )



def 	_a						(   )    ->    Optional[int]:







  """simple docstring"""
  return (
      "<cls>",
      "<pad>",
      "<eos>",
      "<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",
      "O",
      ".",
      "-",
      "<null_1>",
      "<mask>",
  )










from math import ceil
from typing import List, Optional, Union

import numpy as np

from ...audio_utils import mel_filter_bank, spectrogram, window_function
from ...feature_extraction_sequence_utils import BatchFeature, SequenceFeatureExtractor
from ...utils import TensorType, logging


_A :   List[str]  			=  logging.get_logger(__name__)


class        __SCREAMING_SNAKE_CASE      (			lowerCAmelCase_ ):
       _UpperCAmelCase				:  Any			   =   ["audio_values", "audio_mask"]







       def __init__(				self					:     Any		, A					:     Union[str, Any]=2_0_4_8		, A					:     Any=1		, A					:     int=[1_6, 1_6]		, A					:     Any=1_2_8		, A					:     List[Any]=4_4_1_0_0		, A					:     Dict=8_6		, A					:     Dict=2_0_4_8		, A					:     str=0.0		, **A					:     Union[str, Any]		, )       ->List[Any]:
          super().__init__(
              feature_size=A		, sampling_rate=A		, padding_value=A		, **A		, )

          lowerCamelCase__       :						Dict        =							spectrogram_length
          lowerCamelCase__       :						Optional[int]        =							num_channels
          lowerCamelCase__       :						str        =							patch_size
          lowerCamelCase__       :						Any        =							feature_size // self.patch_size[1]
          lowerCamelCase__       :						Union[str, Any]        =							n_fft
          lowerCamelCase__       :						Union[str, Any]        =							sampling_rate // hop_length_to_sampling_rate
          lowerCamelCase__       :						Optional[Any]        =							sampling_rate
          lowerCamelCase__       :						Optional[Any]        =							padding_value
          lowerCamelCase__       :						Union[str, Any]        =							mel_filter_bank(
              num_frequency_bins=1 + n_fft // 2		, num_mel_filters=A		, min_frequency=0.0		, max_frequency=2_20_50.0		, sampling_rate=A		, norm='''slaney'''		, mel_scale='''slaney'''		, ).T







       def 						__lowerCamelCase   (				self					:     List[Any]		, A					:     np.array      )       ->np.ndarray:
          lowerCamelCase__       :						Any        =							spectrogram(
              A		, window_function(self.n_fft		, '''hann'''      )		, frame_length=self.n_fft		, hop_length=self.hop_length		, power=2.0		, mel_filters=self.mel_filters.T		, log_mel='''dB'''		, db_range=80.0		, )
          lowerCamelCase__       :						Any        =							log_spec[:, :-1]
          lowerCamelCase__       :						int        =							log_spec - 20.0
          lowerCamelCase__       :						int        =							np.clip(log_spec / 40.0		, -2.0		, 0.0      ) + 1.0
          return log_spec







       def __call__(				self					:     Union[str, Any]		, A					:     Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]		, A					:     Optional[Union[str, TensorType]] = None		, A					:     Optional[bool] = True		, A					:     Optional[int] = None		, A					:     bool = False		, A					:     bool = False		, **A					:     str		, )       ->BatchFeature:

          if sampling_rate is not None:
             if sampling_rate != self.sampling_rate:
                raise ValueError(
                    '''This feature extractor is set to support sampling rate'''
                    F" of {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled"
                    F" with {self.sampling_rate} and not {sampling_rate}."      )
          else:
             logger.warning(
                 '''It is strongly recommended to pass the `sampling_rate` argument to this function. '''
                 '''Failing to do so can result in silent errors that might be hard to debug.'''      )

          lowerCamelCase__       :						List[str]        =							isinstance(A		, np.ndarray      ) and len(raw_speech.shape      ) > 1
          if is_batched_numpy and len(raw_speech.shape      ) > 2:
             raise ValueError(F"Only mono-channel audio is supported for input to {self}"      )
          lowerCamelCase__       :						Any        =							is_batched_numpy or (
              isinstance(A		, (list, tuple)      ) and (isinstance(raw_speech[0]		, (np.ndarray, tuple, list)      ))
          )
          if is_batched:
             lowerCamelCase__       :						Optional[int]        =							[np.asarray([speech]		, dtype=np.floataa      ).T for speech in raw_speech]
          elif not is_batched and not isinstance(A		, np.ndarray      ):
             lowerCamelCase__       :						Optional[int]        =							np.asarray(A		, dtype=np.floataa      )
          elif isinstance(A		, np.ndarray      ) and raw_speech.dtype is np.dtype(np.floataa      ):
             lowerCamelCase__       :						Optional[Any]        =							raw_speech.astype(np.floataa      )
          # always return batch
          if not is_batched:
             lowerCamelCase__       :						int        =							[np.asarray([raw_speech]      ).T]

          # Convert audio signals to log mel spectrograms, truncate by time axis
          lowerCamelCase__       :						List[str]        =							[
              self._np_extract_fbank_features(waveform.squeeze()      ).T[: self.spectrogram_length] for waveform in raw_speech
          ]
          if isinstance(audio_features[0]		, A      ):
             lowerCamelCase__       :						Dict        =							[np.asarray(A		, dtype=np.floataa      ) for feature in audio_features]

          # Create audio attention mask
          lowerCamelCase__       :						Optional[Any]        =							max(
              [ceil(feature.shape[0] / self.patch_size[0]      ) * self.freq_len for feature in audio_features]      )  # The maximum number of audio patches in a batch
          if return_attention_mask:
             lowerCamelCase__       :						List[Any]        =							[
                 (ceil(feature.shape[0] / self.patch_size[0]      ) * self.freq_len) * [1]
                 + (max_patch_len - ceil(feature.shape[0] / self.patch_size[0]      ) * self.freq_len) * [0]
                 for feature in audio_features
             ]
             lowerCamelCase__       :						List[str]        =							np.array(A      ).astype(np.floataa      )

          # convert into correct format for padding
          lowerCamelCase__       :						str        =							max_patch_len // self.freq_len * self.patch_size[0]  # The maximum audio size in a batch
          lowerCamelCase__       :						Optional[Any]        =							np.ones([len(A      ), 1, max_time_len, self.feature_size]      ).astype(np.floataa      )
          lowerCamelCase__       :						Tuple        =							padded_audio_features * self.padding_value
          for i in range(len(A      )      ):
             lowerCamelCase__       :						int        =							audio_features[i]
             lowerCamelCase__       :						Optional[int]        =							feature

          # return as BatchFeature
          if return_attention_mask:
             lowerCamelCase__       :						Optional[int]        =							{'''audio_values''': padded_audio_features, '''audio_mask''': audio_mask}
          else:
             lowerCamelCase__       :						Tuple        =							{'''audio_values''': padded_audio_features}

          lowerCamelCase__       :						Union[str, Any]        =							BatchFeature(data=A		, tensor_type=A      )
          return encoded_inputs



