






"""simple docstring"""



from dataclasses import asdict, dataclass
from typing import Optional

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


_UpperCamelCase		:  Optional[Any]						=		logging.get_logger(__name__)

# TODO Update this
_UpperCamelCase		:  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     (   a_	):
    UpperCAmelCase_ :     Tuple	     ="esm"







    def __init__(			self							,		_lowerCamelCase=None							,		_lowerCamelCase=None							,		_lowerCamelCase=None							,		_lowerCamelCase=7_6_8							,		_lowerCamelCase=1_2							,		_lowerCamelCase=1_2							,		_lowerCamelCase=3_0_7_2							,		_lowerCamelCase=0.1							,		_lowerCamelCase=0.1							,		_lowerCamelCase=1_0_2_6							,		_lowerCamelCase=0.0_2							,		_lowerCamelCase=1e-12							,		_lowerCamelCase="absolute"							,		_lowerCamelCase=True							,		_lowerCamelCase=None							,		_lowerCamelCase=False							,		_lowerCamelCase=False							,		_lowerCamelCase=None							,		_lowerCamelCase=None							,		**_lowerCamelCase							,		):
      super().__init__(pad_token_id=_lowerCamelCase							,		mask_token_id=_lowerCamelCase							,		**_lowerCamelCase       )

      lowercase							    =       vocab_size
      lowercase							    =       hidden_size
      lowercase							    =       num_hidden_layers
      lowercase							    =       num_attention_heads
      lowercase							    =       intermediate_size
      lowercase							    =       hidden_dropout_prob
      lowercase							    =       attention_probs_dropout_prob
      lowercase							    =       max_position_embeddings
      lowercase							    =       initializer_range
      lowercase							    =       layer_norm_eps
      lowercase							    =       position_embedding_type
      lowercase							    =       use_cache
      lowercase							    =       emb_layer_norm_before
      lowercase							    =       token_dropout
      lowercase							    =       is_folding_model
      if is_folding_model:
        if esmfold_config is None:
          logger.info('No esmfold_config supplied for folding model, using default values.'       )
          lowercase							    =       EsmFoldConfig()
        elif isinstance(_lowerCamelCase							,		_lowerCamelCase       ):
          lowercase							    =       EsmFoldConfig(**_lowerCamelCase       )
        lowercase							    =       esmfold_config
        if vocab_list is None:
          logger.warning('No vocab_list supplied for folding model, assuming the ESM-2 vocabulary!'       )
          lowercase							    =       get_default_vocab_list()
        else:
          lowercase							    =       vocab_list
      else:
        lowercase							    =       None
        lowercase							    =       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 			UpperCamelCase_      (			self       ):
      lowercase							    =       super().to_dict()
      if isinstance(self.esmfold_config							,		_lowerCamelCase       ):
        lowercase							    =       self.esmfold_config.to_dict()
      return output


@dataclass
class        a     :
    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	     =128
    UpperCAmelCase_ :     "TrunkConfig"	     =None







    def 			UpperCamelCase_      (			self       ):
      if self.trunk is None:
        lowercase							    =       TrunkConfig()
      elif isinstance(self.trunk							,		_lowerCamelCase       ):
        lowercase							    =       TrunkConfig(**self.trunk       )







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       asdict(self       )
      lowercase							    =       self.trunk.to_dict()
      return output


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







    def 			UpperCamelCase_      (			self       ):
      if self.structure_module is None:
        lowercase							    =       StructureModuleConfig()
      elif isinstance(self.structure_module							,		_lowerCamelCase       ):
        lowercase							    =       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}.'       )

      lowercase							    =       self.sequence_state_dim // self.sequence_head_width
      lowercase							    =       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 			UpperCamelCase_      (			self       ):
      lowercase							    =       asdict(self       )
      lowercase							    =       self.structure_module.to_dict()
      return output


@dataclass
class        a     :
    UpperCAmelCase_ :     int	     =384
    UpperCAmelCase_ :     int	     =128
    UpperCAmelCase_ :     int	     =16
    UpperCAmelCase_ :     int	     =128
    UpperCAmelCase_ :     int	     =12
    UpperCAmelCase_ :     int	     =4
    UpperCAmelCase_ :     int	     =8
    UpperCAmelCase_ :     float	     =0.1
    UpperCAmelCase_ :     int	     =8
    UpperCAmelCase_ :     int	     =1
    UpperCAmelCase_ :     int	     =2
    UpperCAmelCase_ :     int	     =7
    UpperCAmelCase_ :     int	     =10
    UpperCAmelCase_ :     float	     =1e-8
    UpperCAmelCase_ :     float	     =1e5







    def 			UpperCamelCase_      (			self       ):
      return asdict(self       )


def 						_SCREAMING_SNAKE_CASE (    ):





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



import unittest

import numpy as np

from transformers.file_utils import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision

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 DPTImageProcessor

class        a     (   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=[0.5, 0.5, 0.5]							,		_lowerCamelCase=[0.5, 0.5, 0.5]							,		):
      lowercase							    =       size if size is not None else {'height': 1_8, 'width': 1_8}
      lowercase							    =       parent
      lowercase							    =       batch_size
      lowercase							    =       num_channels
      lowercase							    =       image_size
      lowercase							    =       min_resolution
      lowercase							    =       max_resolution
      lowercase							    =       do_resize
      lowercase							    =       size
      lowercase							    =       do_normalize
      lowercase							    =       image_mean
      lowercase							    =       image_std







    def 			UpperCamelCase_      (			self       ):
      return {
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_normalize": self.do_normalize,
          "do_resize": self.do_resize,
          "size": self.size,
      }


@require_torch
@require_vision
class        a     (   a_,				unittest.TestCase	):
    UpperCAmelCase_ :     Optional[int]	     =DPTImageProcessor if is_vision_available() else None







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       DPTImageProcessingTester(self       )







    @property
    def 			UpperCamelCase_      (			self       ):
      return self.image_processor_tester.prepare_image_processor_dict()







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       self.image_processing_class(**self.image_processor_dict       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'image_mean'       )       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'image_std'       )       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'do_normalize'       )       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'do_resize'       )       )
      self.assertTrue(hasattr(_lowerCamelCase							,		'size'       )       )







    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       self.image_processing_class.from_dict(self.image_processor_dict       )
      self.assertEqual(image_processor.size							,		{'height': 1_8, 'width': 1_8}       )

      lowercase							    =       self.image_processing_class.from_dict(self.image_processor_dict							,		size=4_2       )
      self.assertEqual(image_processor.size							,		{'height': 4_2, 'width': 4_2}       )







    def 			UpperCamelCase_      (			self       ):
      # Initialize image_processing
      lowercase							    =       self.image_processing_class(**self.image_processor_dict       )
      # create random PIL images
      lowercase							    =       prepare_image_inputs(self.image_processor_tester							,		equal_resolution=_lowerCamelCase       )
      for image in image_inputs:
        self.assertIsInstance(_lowerCamelCase							,		Image.Image       )

      # Test not batched input
      lowercase							    =       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
      lowercase							    =       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'],
          )							,		)







    def 			UpperCamelCase_      (			self       ):
      # Initialize image_processing
      lowercase							    =       self.image_processing_class(**self.image_processor_dict       )
      # create random numpy tensors
      lowercase							    =       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
      lowercase							    =       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
      lowercase							    =       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'],
          )							,		)







    def 			UpperCamelCase_      (			self       ):
      # Initialize image_processing
      lowercase							    =       self.image_processing_class(**self.image_processor_dict       )
      # create random PyTorch tensors
      lowercase							    =       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
      lowercase							    =       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
      lowercase							    =       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'],
          )							,		)


