

"""simple docstring"""




from dataclasses import asdict, dataclass
from typing import Optional

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


_lowerCamelCase    :       Tuple        =							logging.get_logger(__name__)

# TODO Update this
_lowerCamelCase    :       List[str]        =							{
    "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  __UpperCAmelCase					(	lowerCamelCase__						):
   UpperCamelCase       					=					"""esm"""



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

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






@dataclass
class  __UpperCAmelCase					:
   UpperCamelCase       					=					None
   UpperCamelCase       					=					True
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False
   UpperCamelCase       					=					0

   UpperCamelCase       					=					True
   UpperCamelCase       					=					False

   UpperCamelCase       					=					1_2_8
   UpperCamelCase       					=					None



   def 	__magic_name__   (							self							:					str						):
     if self.trunk is None:
       UpperCAmelCase	:							List[str]						=			TrunkConfig()
     elif isinstance(self.trunk,		_A						):
       UpperCAmelCase	:							Optional[int]						=			TrunkConfig(**self.trunk						)





   def 	__magic_name__   (							self							:					Tuple						):
     UpperCAmelCase	:							str						=			asdict(self						)
     UpperCAmelCase	:							Tuple						=			self.trunk.to_dict()
     return output






@dataclass
class  __UpperCAmelCase					:
   UpperCamelCase       					=					4_8
   UpperCamelCase       					=					1_0_2_4
   UpperCamelCase       					=					1_2_8
   UpperCamelCase       					=					3_2
   UpperCamelCase       					=					3_2
   UpperCamelCase       					=					3_2
   UpperCamelCase       					=					0
   UpperCamelCase       					=					0
   UpperCamelCase       					=					False
   UpperCamelCase       					=					4
   UpperCamelCase       					=					1_2_8
   UpperCamelCase       					=					None



   def 	__magic_name__   (							self							:					List[Any]						):
     if self.structure_module is None:
       UpperCAmelCase	:							str						=			StructureModuleConfig()
     elif isinstance(self.structure_module,		_A						):
       UpperCAmelCase	:							Union[str, 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}.'''						)

     UpperCAmelCase	:							List[Any]						=			self.sequence_state_dim // self.sequence_head_width
     UpperCAmelCase	:							Optional[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 	__magic_name__   (							self							:					List[Any]						):
     UpperCAmelCase	:							List[Any]						=			asdict(self						)
     UpperCAmelCase	:							Dict						=			self.structure_module.to_dict()
     return output






@dataclass
class  __UpperCAmelCase					:
   UpperCamelCase       					=					3_8_4
   UpperCamelCase       					=					1_2_8
   UpperCamelCase       					=					1_6
   UpperCamelCase       					=					1_2_8
   UpperCamelCase       					=					1_2
   UpperCamelCase       					=					4
   UpperCamelCase       					=					8
   UpperCamelCase       					=					0.1
   UpperCamelCase       					=					8
   UpperCamelCase       					=					1
   UpperCamelCase       					=					2
   UpperCamelCase       					=					7
   UpperCamelCase       					=					1_0
   UpperCamelCase       					=					1E-8
   UpperCamelCase       					=					1E5



   def 	__magic_name__   (							self							:					Union[str, Any]						):
     return asdict(self						)






def       a__					(		)  ->						Tuple:
  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 require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import ChineseCLIPImageProcessor





class  __UpperCAmelCase					(	unittest.TestCase						):



   def __init__(							self							:					List[Any],		__A							:					str,		__A							:					List[str]=7,		__A							:					List[str]=3,		__A							:					Optional[int]=1_8,		__A							:					List[Any]=3_0,		__A							:					Tuple=4_0_0,		__A							:					Tuple=True,		__A							:					List[Any]=None,		__A							:					str=True,		__A							:					int=None,		__A							:					Optional[Any]=True,		__A							:					List[Any]=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3],		__A							:					List[str]=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1],		__A							:					Tuple=True,		):
     UpperCAmelCase	:							int						=			size if size is not None else {'''height''': 2_2_4, '''width''': 2_2_4}
     UpperCAmelCase	:							Optional[Any]						=			crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}
     UpperCAmelCase	:							int						=			parent
     UpperCAmelCase	:							Union[str, Any]						=			batch_size
     UpperCAmelCase	:							List[Any]						=			num_channels
     UpperCAmelCase	:							Dict						=			image_size
     UpperCAmelCase	:							List[str]						=			min_resolution
     UpperCAmelCase	:							Optional[Any]						=			max_resolution
     UpperCAmelCase	:							Union[str, Any]						=			do_resize
     UpperCAmelCase	:							Dict						=			size
     UpperCAmelCase	:							Any						=			do_center_crop
     UpperCAmelCase	:							Union[str, Any]						=			crop_size
     UpperCAmelCase	:							List[str]						=			do_normalize
     UpperCAmelCase	:							Optional[Any]						=			image_mean
     UpperCAmelCase	:							Optional[Any]						=			image_std
     UpperCAmelCase	:							List[Any]						=			do_convert_rgb



   def 	__magic_name__   (							self							:					int						):
     return {
         "do_resize": self.do_resize,
         "size": self.size,
         "do_center_crop": self.do_center_crop,
         "crop_size": self.crop_size,
         "do_normalize": self.do_normalize,
         "image_mean": self.image_mean,
         "image_std": self.image_std,
         "do_convert_rgb": self.do_convert_rgb,
     }





   def 	__magic_name__   (							self							:					Optional[Any],		__A							:					Any=False,		__A							:					str=False,		__A							:					List[Any]=False						):
     assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

     if equal_resolution:
       UpperCAmelCase	:							Dict						=			[]
       for i in range(self.batch_size						):
         image_inputs.append(
             np.random.randint(
                 2_5_5,		size=(self.num_channels, self.max_resolution, self.max_resolution),		dtype=np.uinta						)						)
     else:
       UpperCAmelCase	:							Tuple						=			[]
       for i in range(self.batch_size						):
         UpperCAmelCase			,						UpperCAmelCase	:							Tuple						=			np.random.choice(np.arange(self.min_resolution,		self.max_resolution						),		2						)
         image_inputs.append(np.random.randint(2_5_5,		size=(self.num_channels, width, height),		dtype=np.uinta						)						)

     if not numpify and not torchify:
       # PIL expects the channel dimension as last dimension
       UpperCAmelCase	:							Optional[int]						=			[Image.fromarray(np.moveaxis(__A,		0,		-1						)						) for x in image_inputs]

     if torchify:
       UpperCAmelCase	:							str						=			[torch.from_numpy(__A						) for x in image_inputs]

     return image_inputs






@require_torch
@require_vision
class  __UpperCAmelCase					(	lowerCamelCase__      ,  unittest.TestCase						):
   UpperCamelCase       					=					ChineseCLIPImageProcessor if is_vision_available() else None



   def 	__magic_name__   (							self							:					Dict						):
     UpperCAmelCase	:							Optional[Any]						=			ChineseCLIPImageProcessingTester(self,		do_center_crop=__A						)



   @property
   def 	__magic_name__   (							self							:					Tuple						):
     return self.image_processor_tester.prepare_image_processor_dict()



   def 	__magic_name__   (							self							:					Any						):
     UpperCAmelCase	:							List[Any]						=			self.image_processing_class(**self.image_processor_dict						)
     self.assertTrue(hasattr(__A,		'''do_resize'''						)						)
     self.assertTrue(hasattr(__A,		'''size'''						)						)
     self.assertTrue(hasattr(__A,		'''do_center_crop'''						)						)
     self.assertTrue(hasattr(__A,		'''center_crop'''						)						)
     self.assertTrue(hasattr(__A,		'''do_normalize'''						)						)
     self.assertTrue(hasattr(__A,		'''image_mean'''						)						)
     self.assertTrue(hasattr(__A,		'''image_std'''						)						)
     self.assertTrue(hasattr(__A,		'''do_convert_rgb'''						)						)



   def 	__magic_name__   (							self							:					Optional[Any]						):
     UpperCAmelCase	:							Union[str, Any]						=			self.image_processing_class.from_dict(self.image_processor_dict						)
     self.assertEqual(image_processor.size,		{'''height''': 2_2_4, '''width''': 2_2_4}						)
     self.assertEqual(image_processor.crop_size,		{'''height''': 1_8, '''width''': 1_8}						)

     UpperCAmelCase	:							int						=			self.image_processing_class.from_dict(self.image_processor_dict,		size=4_2,		crop_size=8_4						)
     self.assertEqual(image_processor.size,		{'''shortest_edge''': 4_2}						)
     self.assertEqual(image_processor.crop_size,		{'''height''': 8_4, '''width''': 8_4}						)



   def 	__magic_name__   (							self							:					Union[str, Any]						):
     pass



   def 	__magic_name__   (							self							:					Tuple						):
     # Initialize image_processing
     UpperCAmelCase	:							Dict						=			self.image_processing_class(**self.image_processor_dict						)
     # create random PIL images
     UpperCAmelCase	:							Optional[int]						=			self.image_processor_tester.prepare_inputs(equal_resolution=__A						)
     for image in image_inputs:
       self.assertIsInstance(__A,		Image.Image						)

     # Test not batched input
     UpperCAmelCase	:							str						=			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.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         ),		)

     # Test batched
     UpperCAmelCase	:							Any						=			image_processing(__A,		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.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         ),		)



   def 	__magic_name__   (							self							:					Optional[Any]						):
     # Initialize image_processing
     UpperCAmelCase	:							List[str]						=			self.image_processing_class(**self.image_processor_dict						)
     # create random numpy tensors
     UpperCAmelCase	:							List[Any]						=			self.image_processor_tester.prepare_inputs(equal_resolution=__A,		numpify=__A						)
     for image in image_inputs:
       self.assertIsInstance(__A,		np.ndarray						)

     # Test not batched input
     UpperCAmelCase	:							List[str]						=			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.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         ),		)

     # Test batched
     UpperCAmelCase	:							Dict						=			image_processing(__A,		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.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         ),		)





   def 	__magic_name__   (							self							:					Any						):
     # Initialize image_processing
     UpperCAmelCase	:							str						=			self.image_processing_class(**self.image_processor_dict						)
     # create random PyTorch tensors
     UpperCAmelCase	:							Optional[Any]						=			self.image_processor_tester.prepare_inputs(equal_resolution=__A,		torchify=__A						)
     for image in image_inputs:
       self.assertIsInstance(__A,		torch.Tensor						)

     # Test not batched input
     UpperCAmelCase	:							str						=			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.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         ),		)

     # Test batched
     UpperCAmelCase	:							List[str]						=			image_processing(__A,		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.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         ),		)






@require_torch
@require_vision
class  __UpperCAmelCase					(	lowerCamelCase__      ,  unittest.TestCase						):
   UpperCamelCase       					=					ChineseCLIPImageProcessor if is_vision_available() else None



   def 	__magic_name__   (							self							:					Optional[Any]						):
     UpperCAmelCase	:							str						=			ChineseCLIPImageProcessingTester(self,		num_channels=4,		do_center_crop=__A						)
     UpperCAmelCase	:							Dict						=			3



   @property
   def 	__magic_name__   (							self							:					List[Any]						):
     return self.image_processor_tester.prepare_image_processor_dict()



   def 	__magic_name__   (							self							:					Dict						):
     UpperCAmelCase	:							List[Any]						=			self.image_processing_class(**self.image_processor_dict						)
     self.assertTrue(hasattr(__A,		'''do_resize'''						)						)
     self.assertTrue(hasattr(__A,		'''size'''						)						)
     self.assertTrue(hasattr(__A,		'''do_center_crop'''						)						)
     self.assertTrue(hasattr(__A,		'''center_crop'''						)						)
     self.assertTrue(hasattr(__A,		'''do_normalize'''						)						)
     self.assertTrue(hasattr(__A,		'''image_mean'''						)						)
     self.assertTrue(hasattr(__A,		'''image_std'''						)						)
     self.assertTrue(hasattr(__A,		'''do_convert_rgb'''						)						)



   def 	__magic_name__   (							self							:					List[Any]						):
     pass





   def 	__magic_name__   (							self							:					Tuple						):
     # Initialize image_processing
     UpperCAmelCase	:							Optional[Any]						=			self.image_processing_class(**self.image_processor_dict						)
     # create random PIL images
     UpperCAmelCase	:							Dict						=			self.image_processor_tester.prepare_inputs(equal_resolution=__A						)
     for image in image_inputs:
       self.assertIsInstance(__A,		Image.Image						)

     # Test not batched input
     UpperCAmelCase	:							Tuple						=			image_processing(image_inputs[0],		return_tensors='''pt'''						).pixel_values
     self.assertEqual(
         encoded_images.shape,		(
             1,
             self.expected_encoded_image_num_channels,
             self.image_processor_tester.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         ),		)

     # Test batched
     UpperCAmelCase	:							Tuple						=			image_processing(__A,		return_tensors='''pt'''						).pixel_values
     self.assertEqual(
         encoded_images.shape,		(
             self.image_processor_tester.batch_size,
             self.expected_encoded_image_num_channels,
             self.image_processor_tester.crop_size['''height'''],
             self.image_processor_tester.crop_size['''width'''],
         ),		)





