'''simple docstring'''




from dataclasses import asdict, dataclass
from typing import Optional

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


__lowercase        =    logging.get_logger(__name__)

# TODO Update this
__lowercase        =    {
    '''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 							a__(   lowerCAmelCase__      ):


			'''simple docstring'''






			UpperCAmelCase_     :	Union[str, Any]						=			'''esm'''



			def __init__(  self			,       __lowerCAmelCase=None			,       __lowerCAmelCase=None			,       __lowerCAmelCase=None			,       __lowerCAmelCase=768			,       __lowerCAmelCase=12			,       __lowerCAmelCase=12			,       __lowerCAmelCase=3072			,       __lowerCAmelCase=0.1			,       __lowerCAmelCase=0.1			,       __lowerCAmelCase=1026			,       __lowerCAmelCase=0.02			,       __lowerCAmelCase=1E-1_2			,       __lowerCAmelCase="absolute"			,       __lowerCAmelCase=True			,       __lowerCAmelCase=None			,       __lowerCAmelCase=False			,       __lowerCAmelCase=False			,       __lowerCAmelCase=None			,       __lowerCAmelCase=None			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					super().__init__(pad_token_id=__lowerCAmelCase			,       mask_token_id=__lowerCAmelCase			,       **__lowerCAmelCase)

					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(__lowerCAmelCase			,       __lowerCAmelCase):
									lowerCAmelCase     =    EsmFoldConfig(**__lowerCAmelCase)
							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"""			,       __lowerCAmelCase):
							raise ValueError("""The HuggingFace port of ESMFold does not support use_esm_attn_map at this time!""")







			def 				a_			(  self):




					"""simple docstring"""


					lowerCAmelCase     =    super().to_dict()
					if isinstance(self.esmfold_config			,       __lowerCAmelCase):
							lowerCAmelCase     =    self.esmfold_config.to_dict()
					return output







@dataclass
class 							a__:


			'''simple docstring'''






			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 				a_			(  self):




					"""simple docstring"""


					if self.trunk is None:
							lowerCAmelCase     =    TrunkConfig()
					elif isinstance(self.trunk			,       __lowerCAmelCase):
							lowerCAmelCase     =    TrunkConfig(**self.trunk)







			def 				a_			(  self):




					"""simple docstring"""


					lowerCAmelCase     =    asdict(self)
					lowerCAmelCase     =    self.trunk.to_dict()
					return output







@dataclass
class 							a__:


			'''simple docstring'''






			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 				a_			(  self):




					"""simple docstring"""


					if self.structure_module is None:
							lowerCAmelCase     =    StructureModuleConfig()
					elif isinstance(self.structure_module			,       __lowerCAmelCase):
							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 				a_			(  self):




					"""simple docstring"""


					lowerCAmelCase     =    asdict(self)
					lowerCAmelCase     =    self.structure_module.to_dict()
					return output







@dataclass
class 							a__:


			'''simple docstring'''






			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 				a_			(  self):




					"""simple docstring"""


					return asdict(self)







def 							snake_case__				(     )       ->      List[str]:

		'''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>",
		)





'''simple docstring'''




from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
						import PIL


__lowercase        =    logging.get_logger(__name__)






def 							snake_case__				(     _A:   Dict ,  _A:   Any					)       ->      Union[str, Any]:

		'''simple docstring'''


		lowerCAmelCase     =    b.T
		lowerCAmelCase     =    np.sum(np.square(_A					) ,  axis=1					)
		lowerCAmelCase     =    np.sum(np.square(_A					) ,  axis=0					)
		lowerCAmelCase     =    np.matmul(_A ,  _A					)
		lowerCAmelCase     =    aa[:, None] - 2 * ab + ba[None, :]
		return d






def 							snake_case__				(     _A:   Dict ,  _A:   Dict					)       ->      Optional[Any]:

		'''simple docstring'''


		lowerCAmelCase     =    x.reshape(-1 ,  3					)
		lowerCAmelCase     =    squared_euclidean_distance(_A ,  _A					)
		return np.argmin(_A ,  axis=1					)






class 							a__(   lowerCAmelCase__      ):


			'''simple docstring'''






			UpperCAmelCase_     :	List[Any]						=			['''pixel_values''']



			def __init__(  self			,       __lowerCAmelCase = None			,       __lowerCAmelCase = True			,       __lowerCAmelCase = None			,       __lowerCAmelCase = PILImageResampling.BILINEAR			,       __lowerCAmelCase = True			,       __lowerCAmelCase = True			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					super().__init__(**__lowerCAmelCase)
					lowerCAmelCase     =    size if size is not None else {"""height""": 256, """width""": 256}
					lowerCAmelCase     =    get_size_dict(__lowerCAmelCase)
					lowerCAmelCase     =    np.array(__lowerCAmelCase) if clusters is not None else None
					lowerCAmelCase     =    do_resize
					lowerCAmelCase     =    size
					lowerCAmelCase     =    resample
					lowerCAmelCase     =    do_normalize
					lowerCAmelCase     =    do_color_quantize



			def 				a_			(  self			,       __lowerCAmelCase			,       __lowerCAmelCase			,       __lowerCAmelCase = PILImageResampling.BILINEAR			,       __lowerCAmelCase = None			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					lowerCAmelCase     =    get_size_dict(__lowerCAmelCase)
					if "height" not in size or "width" not in size:
							raise ValueError(f"Size dictionary must contain both height and width keys. Got {size.keys()}")
					return resize(
					    __lowerCAmelCase			,       size=(size["""height"""], size["""width"""])			,       resample=__lowerCAmelCase			,       data_format=__lowerCAmelCase			,       **__lowerCAmelCase)



			def 				a_			(  self			,       __lowerCAmelCase			,       __lowerCAmelCase = None			,       ):




					"""simple docstring"""


					lowerCAmelCase     =    rescale(image=__lowerCAmelCase			,       scale=1 / 127.5			,       data_format=__lowerCAmelCase)
					lowerCAmelCase     =    image - 1
					return image







			def 				a_			(  self			,       __lowerCAmelCase			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = ChannelDimension.FIRST			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					lowerCAmelCase     =    do_resize if do_resize is not None else self.do_resize
					lowerCAmelCase     =    size if size is not None else self.size
					lowerCAmelCase     =    get_size_dict(__lowerCAmelCase)
					lowerCAmelCase     =    resample if resample is not None else self.resample
					lowerCAmelCase     =    do_normalize if do_normalize is not None else self.do_normalize
					lowerCAmelCase     =    do_color_quantize if do_color_quantize is not None else self.do_color_quantize
					lowerCAmelCase     =    clusters if clusters is not None else self.clusters
					lowerCAmelCase     =    np.array(__lowerCAmelCase)

					lowerCAmelCase     =    make_list_of_images(__lowerCAmelCase)

					if not valid_images(__lowerCAmelCase):
							raise ValueError(
							    """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
							    """torch.Tensor, tf.Tensor or jax.ndarray.""")

					if do_resize and size is None or resample is None:
							raise ValueError("""Size and resample must be specified if do_resize is True.""")

					if do_color_quantize and clusters is None:
							raise ValueError("""Clusters must be specified if do_color_quantize is True.""")

					# All transformations expect numpy arrays.
					lowerCAmelCase     =    [to_numpy_array(__lowerCAmelCase) for image in images]

					if do_resize:
							lowerCAmelCase     =    [self.resize(image=__lowerCAmelCase			,       size=__lowerCAmelCase			,       resample=__lowerCAmelCase) for image in images]

					if do_normalize:
							lowerCAmelCase     =    [self.normalize(image=__lowerCAmelCase) for image in images]

					if do_color_quantize:
							lowerCAmelCase     =    [to_channel_dimension_format(__lowerCAmelCase			,       ChannelDimension.LAST) for image in images]
							# color quantize from (batch_size, height, width, 3) to (batch_size, height, width)
							lowerCAmelCase     =    np.array(__lowerCAmelCase)
							lowerCAmelCase     =    color_quantize(__lowerCAmelCase			,       __lowerCAmelCase).reshape(images.shape[:-1])

							# flatten to (batch_size, height*width)
							lowerCAmelCase     =    images.shape[0]
							lowerCAmelCase     =    images.reshape(__lowerCAmelCase			,       -1)

							# We need to convert back to a list of images to keep consistent behaviour across processors.
							lowerCAmelCase     =    list(__lowerCAmelCase)
					else:
							lowerCAmelCase     =    [to_channel_dimension_format(__lowerCAmelCase			,       __lowerCAmelCase) for image in images]

					lowerCAmelCase     =    {"""input_ids""": images}
					return BatchFeature(data=__lowerCAmelCase			,       tensor_type=__lowerCAmelCase)




