



from dataclasses import asdict, dataclass
from typing import Optional

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


__snake_case    :		Dict  =logging.get_logger(__name__)

# TODO Update this
__snake_case    :		Optional[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 	lowerCamelCase__      (							lowerCamelCase__):




		'''simple docstring'''



		snake_case_     ="""esm"""



		def __init__(self		,__lowerCamelCase=None		,__lowerCamelCase=None		,__lowerCamelCase=None		,__lowerCamelCase=7_68		,__lowerCamelCase=12		,__lowerCamelCase=12		,__lowerCamelCase=30_72		,__lowerCamelCase=0.1		,__lowerCamelCase=0.1		,__lowerCamelCase=10_26		,__lowerCamelCase=0.02		,__lowerCamelCase=1e-12		,__lowerCamelCase="absolute"		,__lowerCamelCase=True		,__lowerCamelCase=None		,__lowerCamelCase=False		,__lowerCamelCase=False		,__lowerCamelCase=None		,__lowerCamelCase=None		,**__lowerCamelCase		,)					->      List[Any]:

						"""simple docstring"""






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

						lowerCAmelCase__					:    Optional[int]												=					vocab_size
						lowerCAmelCase__					:    str												=					hidden_size
						lowerCAmelCase__					:    Tuple												=					num_hidden_layers
						lowerCAmelCase__					:    Any												=					num_attention_heads
						lowerCAmelCase__					:    Optional[int]												=					intermediate_size
						lowerCAmelCase__					:    Tuple												=					hidden_dropout_prob
						lowerCAmelCase__					:    Tuple												=					attention_probs_dropout_prob
						lowerCAmelCase__					:    Tuple												=					max_position_embeddings
						lowerCAmelCase__					:    Tuple												=					initializer_range
						lowerCAmelCase__					:    Optional[int]												=					layer_norm_eps
						lowerCAmelCase__					:    int												=					position_embedding_type
						lowerCAmelCase__					:    Any												=					use_cache
						lowerCAmelCase__					:    Dict												=					emb_layer_norm_before
						lowerCAmelCase__					:    int												=					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__					:    Optional[int]												=					EsmFoldConfig()
										elif isinstance(__lowerCamelCase		,__lowerCamelCase			):
														lowerCAmelCase__					:    Optional[Any]												=					EsmFoldConfig(**__lowerCamelCase			)
										lowerCAmelCase__					:    int												=					esmfold_config
										if vocab_list is None:
														logger.warning('''No vocab_list supplied for folding model, assuming the ESM-2 vocabulary!'''			)
														lowerCAmelCase__					:    Dict												=					get_default_vocab_list()
										else:
														lowerCAmelCase__					:    Any												=					vocab_list
						else:
										lowerCAmelCase__					:    Tuple												=					None
										lowerCAmelCase__					:    List[Any]												=					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 		lowerCAmelCase__				(self			)					->      Any:

						"""simple docstring"""






						lowerCAmelCase__					:    int												=					super().to_dict()
						if isinstance(self.esmfold_config		,__lowerCamelCase			):
										lowerCAmelCase__					:    List[Any]												=					self.esmfold_config.to_dict()
						return output



@dataclass
class 	lowerCamelCase__      :




		'''simple docstring'''



		snake_case_     =None
		snake_case_     =True
		snake_case_     =False
		snake_case_     =False
		snake_case_     =False
		snake_case_     =0

		snake_case_     =True
		snake_case_     =False

		snake_case_     =128
		snake_case_     =None



		def 		lowerCAmelCase__				(self			)					->      Tuple:

						"""simple docstring"""






						if self.trunk is None:
										lowerCAmelCase__					:    Union[str, Any]												=					TrunkConfig()
						elif isinstance(self.trunk		,__lowerCamelCase			):
										lowerCAmelCase__					:    Optional[Any]												=					TrunkConfig(**self.trunk			)



		def 		lowerCAmelCase__				(self			)					->      Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    List[Any]												=					asdict(self			)
						lowerCAmelCase__					:    str												=					self.trunk.to_dict()
						return output



@dataclass
class 	lowerCamelCase__      :




		'''simple docstring'''



		snake_case_     =48
		snake_case_     =1024
		snake_case_     =128
		snake_case_     =32
		snake_case_     =32
		snake_case_     =32
		snake_case_     =0
		snake_case_     =0
		snake_case_     =False
		snake_case_     =4
		snake_case_     =128
		snake_case_     =None



		def 		lowerCAmelCase__				(self			)					->      Dict:

						"""simple docstring"""






						if self.structure_module is None:
										lowerCAmelCase__					:    Tuple												=					StructureModuleConfig()
						elif isinstance(self.structure_module		,__lowerCamelCase			):
										lowerCAmelCase__					:    List[Any]												=					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__					:    Tuple												=					self.sequence_state_dim // self.sequence_head_width
						lowerCAmelCase__					:    Union[str, Any]												=					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			)					->      Tuple:

						"""simple docstring"""






						lowerCAmelCase__					:    int												=					asdict(self			)
						lowerCAmelCase__					:    List[str]												=					self.structure_module.to_dict()
						return output



@dataclass
class 	lowerCamelCase__      :




		'''simple docstring'''



		snake_case_     =384
		snake_case_     =128
		snake_case_     =16
		snake_case_     =128
		snake_case_     =12
		snake_case_     =4
		snake_case_     =8
		snake_case_     =0.1
		snake_case_     =8
		snake_case_     =1
		snake_case_     =2
		snake_case_     =7
		snake_case_     =10
		snake_case_     =1e-8
		snake_case_     =1e5



		def 		lowerCAmelCase__				(self			)					->      Optional[Any]:

						"""simple docstring"""






						return asdict(self			)






def      lowerCAmelCase__		(   ):





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






import unittest

import numpy as np

from transformers.testing_utils import is_flaky, require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import DonutImageProcessor



class 	lowerCamelCase__      (							unittest.TestCase):




		'''simple docstring'''



		def __init__(self		,__lowerCamelCase		,__lowerCamelCase=7		,__lowerCamelCase=3		,__lowerCamelCase=18		,__lowerCamelCase=30		,__lowerCamelCase=4_00		,__lowerCamelCase=True		,__lowerCamelCase=None		,__lowerCamelCase=True		,__lowerCamelCase=False		,__lowerCamelCase=True		,__lowerCamelCase=True		,__lowerCamelCase=[0.5, 0.5, 0.5]		,__lowerCamelCase=[0.5, 0.5, 0.5]		,)					->      Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    List[Any]												=					parent
						lowerCAmelCase__					:    Optional[Any]												=					batch_size
						lowerCAmelCase__					:    str												=					num_channels
						lowerCAmelCase__					:    List[str]												=					image_size
						lowerCAmelCase__					:    List[Any]												=					min_resolution
						lowerCAmelCase__					:    Union[str, Any]												=					max_resolution
						lowerCAmelCase__					:    Union[str, Any]												=					do_resize
						lowerCAmelCase__					:    str												=					size if size is not None else {'''height''': 18, '''width''': 20}
						lowerCAmelCase__					:    List[str]												=					do_thumbnail
						lowerCAmelCase__					:    str												=					do_align_axis
						lowerCAmelCase__					:    Optional[Any]												=					do_pad
						lowerCAmelCase__					:    Tuple												=					do_normalize
						lowerCAmelCase__					:    List[Any]												=					image_mean
						lowerCAmelCase__					:    List[str]												=					image_std



		def 		lowerCAmelCase__				(self			)					->      Optional[Any]:

						"""simple docstring"""






						return {
						    "do_resize": self.do_resize,
						    "size": self.size,
						    "do_thumbnail": self.do_thumbnail,
						    "do_align_long_axis": self.do_align_axis,
						    "do_pad": self.do_pad,
						    "do_normalize": self.do_normalize,
						    "image_mean": self.image_mean,
						    "image_std": self.image_std,
						}



@require_torch
@require_vision
class 	lowerCamelCase__      (							lowerCamelCase__				,    unittest.TestCase):




		'''simple docstring'''



		snake_case_     =DonutImageProcessor if is_vision_available() else None



		def 		lowerCAmelCase__				(self			)					->      List[Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    Union[str, Any]												=					DonutImageProcessingTester(self			)



		@property
		def 		lowerCAmelCase__				(self			)					->      Any:

						"""simple docstring"""






						return self.image_processor_tester.prepare_image_processor_dict()



		def 		lowerCAmelCase__				(self			)					->      int:

						"""simple docstring"""






						lowerCAmelCase__					:    Optional[Any]												=					self.image_processing_class(**self.image_processor_dict			)
						self.assertTrue(hasattr(__lowerCamelCase		,'''do_resize'''			)			)
						self.assertTrue(hasattr(__lowerCamelCase		,'''size'''			)			)
						self.assertTrue(hasattr(__lowerCamelCase		,'''do_thumbnail'''			)			)
						self.assertTrue(hasattr(__lowerCamelCase		,'''do_align_long_axis'''			)			)
						self.assertTrue(hasattr(__lowerCamelCase		,'''do_pad'''			)			)
						self.assertTrue(hasattr(__lowerCamelCase		,'''do_normalize'''			)			)
						self.assertTrue(hasattr(__lowerCamelCase		,'''image_mean'''			)			)
						self.assertTrue(hasattr(__lowerCamelCase		,'''image_std'''			)			)



		def 		lowerCAmelCase__				(self			)					->      Tuple:

						"""simple docstring"""






						lowerCAmelCase__					:    Optional[int]												=					self.image_processing_class.from_dict(self.image_processor_dict			)
						self.assertEqual(image_processor.size		,{'''height''': 18, '''width''': 20}			)

						lowerCAmelCase__					:    int												=					self.image_processing_class.from_dict(self.image_processor_dict		,size=42			)
						self.assertEqual(image_processor.size		,{'''height''': 42, '''width''': 42}			)

						# Previous config had dimensions in (width, height) order
						lowerCAmelCase__					:    Union[str, Any]												=					self.image_processing_class.from_dict(self.image_processor_dict		,size=(42, 84)			)
						self.assertEqual(image_processor.size		,{'''height''': 84, '''width''': 42}			)



		def 		lowerCAmelCase__				(self			)					->      Optional[Any]:

						"""simple docstring"""






						pass



		@is_flaky()
		def 		lowerCAmelCase__				(self			)					->      Optional[Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    str												=					self.image_processing_class(**self.image_processor_dict			)
						# create random PIL images
						lowerCAmelCase__					:    Dict												=					prepare_image_inputs(self.image_processor_tester		,equal_resolution=__lowerCamelCase			)
						for image in image_inputs:
										self.assertIsInstance(__lowerCamelCase		,Image.Image			)

						# Test not batched input
						lowerCAmelCase__					:    Optional[Any]												=					image_processing(image_inputs[0]		,return_tensors='''pt'''			).pixel_values
						self.assertEqual(
						    encoded_images.shape		,(
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )		,)

						# Test batched
						lowerCAmelCase__					:    Optional[int]												=					image_processing(__lowerCamelCase		,return_tensors='''pt'''			).pixel_values
						self.assertEqual(
						    encoded_images.shape		,(
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )		,)



		@is_flaky()
		def 		lowerCAmelCase__				(self			)					->      Any:

						"""simple docstring"""






						lowerCAmelCase__					:    Optional[int]												=					self.image_processing_class(**self.image_processor_dict			)
						# create random numpy tensors
						lowerCAmelCase__					:    Any												=					prepare_image_inputs(self.image_processor_tester		,equal_resolution=__lowerCamelCase		,numpify=__lowerCamelCase			)
						for image in image_inputs:
										self.assertIsInstance(__lowerCamelCase		,np.ndarray			)

						# Test not batched input
						lowerCAmelCase__					:    Union[str, Any]												=					image_processing(image_inputs[0]		,return_tensors='''pt'''			).pixel_values
						self.assertEqual(
						    encoded_images.shape		,(
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )		,)

						# Test batched
						lowerCAmelCase__					:    int												=					image_processing(__lowerCamelCase		,return_tensors='''pt'''			).pixel_values
						self.assertEqual(
						    encoded_images.shape		,(
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )		,)



		@is_flaky()
		def 		lowerCAmelCase__				(self			)					->      Optional[Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    Any												=					self.image_processing_class(**self.image_processor_dict			)
						# create random PyTorch tensors
						lowerCAmelCase__					:    int												=					prepare_image_inputs(self.image_processor_tester		,equal_resolution=__lowerCamelCase		,torchify=__lowerCamelCase			)
						for image in image_inputs:
										self.assertIsInstance(__lowerCamelCase		,torch.Tensor			)

						# Test not batched input
						lowerCAmelCase__					:    Any												=					image_processing(image_inputs[0]		,return_tensors='''pt'''			).pixel_values
						self.assertEqual(
						    encoded_images.shape		,(
						        1,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )		,)

						# Test batched
						lowerCAmelCase__					:    Dict												=					image_processing(__lowerCamelCase		,return_tensors='''pt'''			).pixel_values
						self.assertEqual(
						    encoded_images.shape		,(
						        self.image_processor_tester.batch_size,
						        self.image_processor_tester.num_channels,
						        self.image_processor_tester.size['''height'''],
						        self.image_processor_tester.size['''width'''],
						    )		,)

