

from dataclasses import asdict, dataclass
from typing import Optional

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


__A      :   Optional[int]          =	logging.get_logger(__name__)

# TODO Update this
__A      :   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       __A (							UpperCamelCase__       ):
    lowerCAmelCase_							:						List[Any]						 =							"""esm"""






    def __init__(		self	:			Optional[Any]			, UpperCAmelCase_	:			str=None			, UpperCAmelCase_	:			Union[str, Any]=None			, UpperCAmelCase_	:			Union[str, Any]=None			, UpperCAmelCase_	:			Union[str, Any]=768			, UpperCAmelCase_	:			Dict=12			, UpperCAmelCase_	:			Tuple=12			, UpperCAmelCase_	:			Union[str, Any]=3072			, UpperCAmelCase_	:			Dict=0.1			, UpperCAmelCase_	:			Optional[int]=0.1			, UpperCAmelCase_	:			int=1026			, UpperCAmelCase_	:			Dict=0.02			, UpperCAmelCase_	:			Optional[int]=1E-12			, UpperCAmelCase_	:			List[str]="absolute"			, UpperCAmelCase_	:			int=True			, UpperCAmelCase_	:			List[Any]=None			, UpperCAmelCase_	:			Optional[Any]=False			, UpperCAmelCase_	:			Dict=False			, UpperCAmelCase_	:			List[str]=None			, UpperCAmelCase_	:			List[Any]=None			, **UpperCAmelCase_	:			List[str]			, ):
        super().__init__(pad_token_id=lowerCAmelCase__			, mask_token_id=lowerCAmelCase__			, **lowerCAmelCase__			)

        lowerCAmelCase :	Union[str, Any]				=					vocab_size
        lowerCAmelCase :	List[Any]				=					hidden_size
        lowerCAmelCase :	Optional[Any]				=					num_hidden_layers
        lowerCAmelCase :	str				=					num_attention_heads
        lowerCAmelCase :	Tuple				=					intermediate_size
        lowerCAmelCase :	List[Any]				=					hidden_dropout_prob
        lowerCAmelCase :	Optional[int]				=					attention_probs_dropout_prob
        lowerCAmelCase :	int				=					max_position_embeddings
        lowerCAmelCase :	List[str]				=					initializer_range
        lowerCAmelCase :	Optional[int]				=					layer_norm_eps
        lowerCAmelCase :	Dict				=					position_embedding_type
        lowerCAmelCase :	int				=					use_cache
        lowerCAmelCase :	Tuple				=					emb_layer_norm_before
        lowerCAmelCase :	Union[str, Any]				=					token_dropout
        lowerCAmelCase :	List[Any]				=					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 :	List[Any]				=					EsmFoldConfig()
            elif isinstance(lowerCAmelCase__			, lowerCAmelCase__			):
                lowerCAmelCase :	Any				=					EsmFoldConfig(**lowerCAmelCase__			)
            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[Any]				=					get_default_vocab_list()
            else:
                lowerCAmelCase :	List[str]				=					vocab_list
        else:
            lowerCAmelCase :	Any				=					None
            lowerCAmelCase :	str				=					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 		lowercase__       (		self	:			List[Any]			):
        lowerCAmelCase :	Optional[Any]				=					super().to_dict()
        if isinstance(self.esmfold_config			, lowerCAmelCase__			):
            lowerCAmelCase :	List[str]				=					self.esmfold_config.to_dict()
        return output






@dataclass
class       __A :
    lowerCAmelCase_							:						str						 =							None
    lowerCAmelCase_							:						bool						 =							True
    lowerCAmelCase_							:						bool						 =							False
    lowerCAmelCase_							:						bool						 =							False
    lowerCAmelCase_							:						bool						 =							False
    lowerCAmelCase_							:						float						 =							0

    lowerCAmelCase_							:						bool						 =							True
    lowerCAmelCase_							:						bool						 =							False

    lowerCAmelCase_							:						int						 =							128
    lowerCAmelCase_							:						"TrunkConfig"						 =							None






    def 		lowercase__       (		self	:			Union[str, Any]			):




        if self.trunk is None:
            lowerCAmelCase :	List[Any]				=					TrunkConfig()
        elif isinstance(self.trunk			, lowerCAmelCase__			):
            lowerCAmelCase :	Dict				=					TrunkConfig(**self.trunk			)






    def 		lowercase__       (		self	:			int			):
        lowerCAmelCase :	Any				=					asdict(self			)
        lowerCAmelCase :	List[str]				=					self.trunk.to_dict()
        return output






@dataclass
class       __A :
    lowerCAmelCase_							:						int						 =							48
    lowerCAmelCase_							:						int						 =							1024
    lowerCAmelCase_							:						int						 =							128
    lowerCAmelCase_							:						int						 =							32
    lowerCAmelCase_							:						int						 =							32
    lowerCAmelCase_							:						int						 =							32
    lowerCAmelCase_							:						float						 =							0
    lowerCAmelCase_							:						float						 =							0
    lowerCAmelCase_							:						bool						 =							False
    lowerCAmelCase_							:						int						 =							4
    lowerCAmelCase_							:						Optional[int]						 =							128
    lowerCAmelCase_							:						"StructureModuleConfig"						 =							None






    def 		lowercase__       (		self	:			List[Any]			):




        if self.structure_module is None:
            lowerCAmelCase :	List[Any]				=					StructureModuleConfig()
        elif isinstance(self.structure_module			, lowerCAmelCase__			):
            lowerCAmelCase :	Dict				=					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 :	int				=					self.sequence_state_dim // self.sequence_head_width
        lowerCAmelCase :	Dict				=					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 		lowercase__       (		self	:			Optional[Any]			):
        lowerCAmelCase :	str				=					asdict(self			)
        lowerCAmelCase :	List[str]				=					self.structure_module.to_dict()
        return output






@dataclass
class       __A :
    lowerCAmelCase_							:						int						 =							384
    lowerCAmelCase_							:						int						 =							128
    lowerCAmelCase_							:						int						 =							16
    lowerCAmelCase_							:						int						 =							128
    lowerCAmelCase_							:						int						 =							12
    lowerCAmelCase_							:						int						 =							4
    lowerCAmelCase_							:						int						 =							8
    lowerCAmelCase_							:						float						 =							0.1
    lowerCAmelCase_							:						int						 =							8
    lowerCAmelCase_							:						int						 =							1
    lowerCAmelCase_							:						int						 =							2
    lowerCAmelCase_							:						int						 =							7
    lowerCAmelCase_							:						int						 =							10
    lowerCAmelCase_							:						float						 =							1E-8
    lowerCAmelCase_							:						float						 =							1E5






    def 		lowercase__       (		self	:			Any			):
        return asdict(self			)



def 						SCREAMING_SNAKE_CASE__ (							)    ->       Dict:



    '''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 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 MobileViTImageProcessor







class 				__lowerCAmelCase       (    unittest.TestCase):







      def __init__(    self		,      lowerCAmelCase__		,      lowerCAmelCase__=7		,      lowerCAmelCase__=3		,      lowerCAmelCase__=1_8		,      lowerCAmelCase__=3_0		,      lowerCAmelCase__=4_0_0		,      lowerCAmelCase__=True		,      lowerCAmelCase__=None		,      lowerCAmelCase__=True		,      lowerCAmelCase__=None		,      lowerCAmelCase__=True		,      )   ->						Optional[Any]:



        '''simple docstring'''




        a__	:					Union[str, Any]										=size if size is not None else {"shortest_edge": 2_0}
        a__	:					List[str]										=crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}
        a__	:					Tuple										=parent
        a__	:					Union[str, Any]										=batch_size
        a__	:					List[str]										=num_channels
        a__	:					List[Any]										=image_size
        a__	:					str										=min_resolution
        a__	:					Optional[int]										=max_resolution
        a__	:					Tuple										=do_resize
        a__	:					Union[str, Any]										=size
        a__	:					List[Any]										=do_center_crop
        a__	:					List[str]										=crop_size
        a__	:					Optional[int]										=do_flip_channel_order







      def    _lowercase  (    self							)   ->						Optional[int]:



        '''simple docstring'''




        return {
            "do_resize": self.do_resize,
            "size": self.size,
            "do_center_crop": self.do_center_crop,
            "crop_size": self.crop_size,
            "do_flip_channel_order": self.do_flip_channel_order,
        }







@require_torch
@require_vision
class 				__lowerCAmelCase       (    UpperCamelCase__						,				unittest.TestCase):
      _lowercase				:					int						=			MobileViTImageProcessor if is_vision_available() else None







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



        '''simple docstring'''




        a__	:					Tuple										=MobileViTImageProcessingTester(self							)







      @property
      def    _lowercase  (    self							)   ->						List[str]:



        '''simple docstring'''




        return self.image_processor_tester.prepare_image_processor_dict()







      def    _lowercase  (    self							)   ->						List[str]:



        '''simple docstring'''




        a__	:					str										=self.image_processing_class(**self.image_processor_dict							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "do_resize"							)							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "size"							)							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "do_center_crop"							)							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "center_crop"							)							)
        self.assertTrue(hasattr(lowerCAmelCase__		,      "do_flip_channel_order"							)							)







      def    _lowercase  (    self							)   ->						Optional[int]:



        '''simple docstring'''




        a__	:					List[Any]										=self.image_processing_class.from_dict(self.image_processor_dict							)
        self.assertEqual(image_processor.size		,      {"shortest_edge": 2_0}							)
        self.assertEqual(image_processor.crop_size		,      {"height": 1_8, "width": 1_8}							)

        a__	:					Union[str, Any]										=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    _lowercase  (    self							)   ->						Optional[Any]:



        '''simple docstring'''




        pass







      def    _lowercase  (    self							)   ->						Tuple:



        '''simple docstring'''




        a__	:					List[str]										=self.image_processing_class(**self.image_processor_dict							)
        # create random PIL images
        a__	:					Any										=prepare_image_inputs(self.image_processor_tester		,      equal_resolution=lowerCAmelCase__							)
        for image in image_inputs:
          self.assertIsInstance(lowerCAmelCase__		,      Image.Image							)

        # Test not batched input
        a__	:					Tuple										=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
        a__	:					List[Any]										=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.crop_size["height"],
                self.image_processor_tester.crop_size["width"],
            )		,      )







      def    _lowercase  (    self							)   ->						Any:



        '''simple docstring'''




        a__	:					Optional[Any]										=self.image_processing_class(**self.image_processor_dict							)
        # create random numpy tensors
        a__	:					List[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
        a__	:					Tuple										=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
        a__	:					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.crop_size["height"],
                self.image_processor_tester.crop_size["width"],
            )		,      )







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



        '''simple docstring'''




        a__	:					int										=self.image_processing_class(**self.image_processor_dict							)
        # create random PyTorch tensors
        a__	:					Tuple										=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
        a__	:					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
        a__	:					List[str]										=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.crop_size["height"],
                self.image_processor_tester.crop_size["width"],
            )		,      )






