
from dataclasses import asdict, dataclass
from typing import Optional

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


__A							=logging.get_logger(__name__)

# TODO Update this
__A							={
    '''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	( snake_case_		):
	lowerCAmelCase__   =					'esm'



	def __init__(       self		,    lowercase=None		,    lowercase=None		,    lowercase=None		,    lowercase=768		,    lowercase=12		,    lowercase=12		,    lowercase=3072		,    lowercase=0.1		,    lowercase=0.1		,    lowercase=1026		,    lowercase=0.0_2		,    lowercase=1e-12		,    lowercase="absolute"		,    lowercase=True		,    lowercase=None		,    lowercase=False		,    lowercase=False		,    lowercase=None		,    lowercase=None		,    **lowercase		,    )							->			int:
					super().__init__(pad_token_id=lowercase		,    mask_token_id=lowercase		,    **lowercase					)

					lowerCamelCase_         =     vocab_size
					lowerCamelCase_         =     hidden_size
					lowerCamelCase_         =     num_hidden_layers
					lowerCamelCase_         =     num_attention_heads
					lowerCamelCase_         =     intermediate_size
					lowerCamelCase_         =     hidden_dropout_prob
					lowerCamelCase_         =     attention_probs_dropout_prob
					lowerCamelCase_         =     max_position_embeddings
					lowerCamelCase_         =     initializer_range
					lowerCamelCase_         =     layer_norm_eps
					lowerCamelCase_         =     position_embedding_type
					lowerCamelCase_         =     use_cache
					lowerCamelCase_         =     emb_layer_norm_before
					lowerCamelCase_         =     token_dropout
					lowerCamelCase_         =     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_         =     EsmFoldConfig()
									elif isinstance(lowercase		,    lowercase					):
													lowerCamelCase_         =     EsmFoldConfig(**lowercase					)
									lowerCamelCase_         =     esmfold_config
									if vocab_list is None:
													logger.warning("No vocab_list supplied for folding model, assuming the ESM-2 vocabulary!"					)
													lowerCamelCase_         =     get_default_vocab_list()
									else:
													lowerCamelCase_         =     vocab_list
					else:
									lowerCamelCase_         =     None
									lowerCamelCase_         =     None
					if self.esmfold_config is not None and getattr(self.esmfold_config		,    "use_esm_attn_map"		,    lowercase					):
									raise ValueError("The HuggingFace port of ESMFold does not support use_esm_attn_map at this time!"					)



	def        SCREAMING_SNAKE_CASE_(       self					)							->			Any:
					lowerCamelCase_         =     super().to_dict()
					if isinstance(self.esmfold_config		,    lowercase					):
									lowerCamelCase_         =     self.esmfold_config.to_dict()
					return output




@dataclass
class        _SCREAMING_SNAKE_CASE	:
	lowerCAmelCase__   =					None
	lowerCAmelCase__   =					True
	lowerCAmelCase__   =					False
	lowerCAmelCase__   =					False
	lowerCAmelCase__   =					False
	lowerCAmelCase__   =					0

	lowerCAmelCase__   =					True
	lowerCAmelCase__   =					False

	lowerCAmelCase__   =					1_28
	lowerCAmelCase__   =					None



	def        SCREAMING_SNAKE_CASE_(       self					)							->			str:
					if self.trunk is None:
									lowerCamelCase_         =     TrunkConfig()
					elif isinstance(self.trunk		,    lowercase					):
									lowerCamelCase_         =     TrunkConfig(**self.trunk					)



	def        SCREAMING_SNAKE_CASE_(       self					)							->			Dict:
					lowerCamelCase_         =     asdict(self					)
					lowerCamelCase_         =     self.trunk.to_dict()
					return output




@dataclass
class        _SCREAMING_SNAKE_CASE	:
	lowerCAmelCase__   =					48
	lowerCAmelCase__   =					10_24
	lowerCAmelCase__   =					1_28
	lowerCAmelCase__   =					32
	lowerCAmelCase__   =					32
	lowerCAmelCase__   =					32
	lowerCAmelCase__   =					0
	lowerCAmelCase__   =					0
	lowerCAmelCase__   =					False
	lowerCAmelCase__   =					4
	lowerCAmelCase__   =					1_28
	lowerCAmelCase__   =					None



	def        SCREAMING_SNAKE_CASE_(       self					)							->			Dict:
					if self.structure_module is None:
									lowerCamelCase_         =     StructureModuleConfig()
					elif isinstance(self.structure_module		,    lowercase					):
									lowerCamelCase_         =     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_         =     self.sequence_state_dim // self.sequence_head_width
					lowerCamelCase_         =     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        SCREAMING_SNAKE_CASE_(       self					)							->			str:
					lowerCamelCase_         =     asdict(self					)
					lowerCamelCase_         =     self.structure_module.to_dict()
					return output




@dataclass
class        _SCREAMING_SNAKE_CASE	:
	lowerCAmelCase__   =					3_84
	lowerCAmelCase__   =					1_28
	lowerCAmelCase__   =					16
	lowerCAmelCase__   =					1_28
	lowerCAmelCase__   =					12
	lowerCAmelCase__   =					4
	lowerCAmelCase__   =					8
	lowerCAmelCase__   =					0.1
	lowerCAmelCase__   =					8
	lowerCAmelCase__   =					1
	lowerCAmelCase__   =					2
	lowerCAmelCase__   =					7
	lowerCAmelCase__   =					10
	lowerCAmelCase__   =					1e-8
	lowerCAmelCase__   =					1e5



	def        SCREAMING_SNAKE_CASE_(       self					)							->			Union[str, Any]:
					return asdict(self					)





def      lowerCamelCase_					(							):
				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>",
				)




import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin




class        _SCREAMING_SNAKE_CASE	( snake_case_		):
	lowerCAmelCase__   =					'MCTCTFeatureExtractor'
	lowerCAmelCase__   =					'AutoTokenizer'



	def __init__(       self		,    lowercase		,    lowercase					)							->			str:
					super().__init__(lowercase		,    lowercase					)
					lowerCamelCase_         =     self.feature_extractor
					lowerCamelCase_         =     False



	def __call__(       self		,    *lowercase		,    **lowercase					)							->			List[str]:
					# For backward compatibility
					if self._in_target_context_manager:
									return self.current_processor(*lowercase		,    **lowercase					)

					if "raw_speech" in kwargs:
									warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."					)
									lowerCamelCase_         =     kwargs.pop("raw_speech"					)
					else:
									lowerCamelCase_         =     kwargs.pop("audio"		,    lowercase					)
					lowerCamelCase_         =     kwargs.pop("sampling_rate"		,    lowercase					)
					lowerCamelCase_         =     kwargs.pop("text"		,    lowercase					)
					if len(lowercase					) > 0:
									lowerCamelCase_         =     args[0]
									lowerCamelCase_         =     args[1:]

					if audio is None and text is None:
									raise ValueError("You need to specify either an `audio` or `text` input to process."					)

					if audio is not None:
									lowerCamelCase_         =     self.feature_extractor(lowercase		,    *lowercase		,    sampling_rate=lowercase		,    **lowercase					)
					if text is not None:
									lowerCamelCase_         =     self.tokenizer(lowercase		,    **lowercase					)

					if text is None:
									return inputs
					elif audio is None:
									return encodings
					else:
									lowerCamelCase_         =     encodings["input_ids"]
									return inputs



	def        SCREAMING_SNAKE_CASE_(       self		,    *lowercase		,    **lowercase					)							->			Optional[Any]:
					return self.tokenizer.batch_decode(*lowercase		,    **lowercase					)



	def        SCREAMING_SNAKE_CASE_(       self		,    *lowercase		,    **lowercase					)							->			Optional[Any]:
					# For backward compatibility
					if self._in_target_context_manager:
									return self.current_processor.pad(*lowercase		,    **lowercase					)

					lowerCamelCase_         =     kwargs.pop("input_features"		,    lowercase					)
					lowerCamelCase_         =     kwargs.pop("labels"		,    lowercase					)
					if len(lowercase					) > 0:
									lowerCamelCase_         =     args[0]
									lowerCamelCase_         =     args[1:]

					if input_features is not None:
									lowerCamelCase_         =     self.feature_extractor.pad(lowercase		,    *lowercase		,    **lowercase					)
					if labels is not None:
									lowerCamelCase_         =     self.tokenizer.pad(lowercase		,    **lowercase					)

					if labels is None:
									return input_features
					elif input_features is None:
									return labels
					else:
									lowerCamelCase_         =     labels["input_ids"]
									return input_features



	def        SCREAMING_SNAKE_CASE_(       self		,    *lowercase		,    **lowercase					)							->			List[str]:
					return self.tokenizer.decode(*lowercase		,    **lowercase					)



	@contextmanager
	def        SCREAMING_SNAKE_CASE_(       self					)							->			Optional[int]:
					warnings.warn(
					    "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your "
					    "labels by using the argument `text` of the regular `__call__` method (either in the same call as "
					    "your audio inputs, or in a separate call."					)
					lowerCamelCase_         =     True
					lowerCamelCase_         =     self.tokenizer
					yield
					lowerCamelCase_         =     self.feature_extractor
					lowerCamelCase_         =     False


