






"""simple docstring"""
from dataclasses import asdict, dataclass
from typing import Optional

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


lowerCamelCase_							      = logging.get_logger(__name__)

# TODO Update this
lowerCamelCase_							      = {
    '''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_			(__A	):
	__magic_name__       =							'''esm'''





	def __init__( self   :					Any      ,      lowerCAmelCase_   :					Dict=None      ,      lowerCAmelCase_   :					Optional[Any]=None      ,      lowerCAmelCase_   :					int=None      ,      lowerCAmelCase_   :					Union[str, Any]=768      ,      lowerCAmelCase_   :					List[str]=12      ,      lowerCAmelCase_   :					int=12      ,      lowerCAmelCase_   :					Optional[int]=3_072      ,      lowerCAmelCase_   :					Union[str, Any]=0.1      ,      lowerCAmelCase_   :					Union[str, Any]=0.1      ,      lowerCAmelCase_   :					int=1_026      ,      lowerCAmelCase_   :					List[str]=0.0_2      ,      lowerCAmelCase_   :					List[Any]=1e-12      ,      lowerCAmelCase_   :					Any="absolute"      ,      lowerCAmelCase_   :					int=True      ,      lowerCAmelCase_   :					Union[str, Any]=None      ,      lowerCAmelCase_   :					str=False      ,      lowerCAmelCase_   :					str=False      ,      lowerCAmelCase_   :					List[Any]=None      ,      lowerCAmelCase_   :					int=None      ,      **lowerCAmelCase_   :					Optional[int]      ,      )		->     Optional[Any]:
				super().__init__(pad_token_id=lowerCAmelCase_      ,      mask_token_id=lowerCAmelCase_      ,      **lowerCAmelCase_		)

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







@dataclass
class      UpperCamelCase_			:
	__magic_name__       =							None
	__magic_name__       =							True
	__magic_name__       =							False
	__magic_name__       =							False
	__magic_name__       =							False
	__magic_name__       =							0

	__magic_name__       =							True
	__magic_name__       =							False

	__magic_name__       =							1_28
	__magic_name__       =							None





	def 	_SCREAMING_SNAKE_CASE ( self   :					Dict		)		->     List[Any]:
				if self.trunk is None:
							UpperCAmelCase_	:					List[str]     	=   TrunkConfig()
				elif isinstance(self.trunk      ,      lowerCAmelCase_		):
							UpperCAmelCase_	:					Dict     	=   TrunkConfig(**self.trunk		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					Tuple		)		->     Tuple:
				UpperCAmelCase_	:					List[Any]     	=   asdict(self		)
				UpperCAmelCase_	:					Dict     	=   self.trunk.to_dict()
				return output







@dataclass
class      UpperCamelCase_			:
	__magic_name__       =							48
	__magic_name__       =							10_24
	__magic_name__       =							1_28
	__magic_name__       =							32
	__magic_name__       =							32
	__magic_name__       =							32
	__magic_name__       =							0
	__magic_name__       =							0
	__magic_name__       =							False
	__magic_name__       =							4
	__magic_name__       =							1_28
	__magic_name__       =							None





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[Any]		)		->     Tuple:
				if self.structure_module is None:
							UpperCAmelCase_	:					int     	=   StructureModuleConfig()
				elif isinstance(self.structure_module      ,      lowerCAmelCase_		):
							UpperCAmelCase_	:					Optional[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_	:					Dict     	=   self.sequence_state_dim // self.sequence_head_width
				UpperCAmelCase_	:					Tuple     	=   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 	_SCREAMING_SNAKE_CASE ( self   :					Dict		)		->     Dict:
				UpperCAmelCase_	:					Optional[int]     	=   asdict(self		)
				UpperCAmelCase_	:					int     	=   self.structure_module.to_dict()
				return output







@dataclass
class      UpperCamelCase_			:
	__magic_name__       =							3_84
	__magic_name__       =							1_28
	__magic_name__       =							16
	__magic_name__       =							1_28
	__magic_name__       =							12
	__magic_name__       =							4
	__magic_name__       =							8
	__magic_name__       =							0.1
	__magic_name__       =							8
	__magic_name__       =							1
	__magic_name__       =							2
	__magic_name__       =							7
	__magic_name__       =							10
	__magic_name__       =							1e-8
	__magic_name__       =							1e5





	def 	_SCREAMING_SNAKE_CASE ( self   :					Dict		)		->     Dict:
				return asdict(self		)





def 							snake_case (  ):
			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

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
							import torch

							from transformers.generation import DisjunctiveConstraint

@require_torch
class 							_UpperCamelCase					(       unittest.TestCase	):






			'''simple docstring'''

			def    lowerCAmelCase__						(							self			:							Dict   ):
							# For consistency across different places the DisjunctiveConstraint is called,
							# dc.token_ids is a list of integers. It is also initialized only by integers.

							UpperCamelCase_:				Optional[int]						=    [[1, 2, 4], [1, 2, 3, 4]]
							UpperCamelCase_:				List[str]						=    DisjunctiveConstraint(snake_case_   )
							self.assertTrue(isinstance(dc.token_ids    ,						snake_case_   )   )

							with self.assertRaises(snake_case_   ):
											DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]   )   )

							with self.assertRaises(snake_case_   ):
											DisjunctiveConstraint([torch.LongTensor([1, 2, 4]   ), torch.LongTensor([1, 2, 3, 4, 5]   )]   )

			def    lowerCAmelCase__						(							self			:							Optional[Any]   ):
							# We can't have constraints that are complete subsets of another. This leads to a preverse
							# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
							# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
							# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
							# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
							UpperCamelCase_:				Dict						=    [[1, 2], [1, 2, 3, 4]]

							with self.assertRaises(snake_case_   ):
											DisjunctiveConstraint(snake_case_   )  # fails here

			def    lowerCAmelCase__						(							self			:							int   ):
							UpperCamelCase_:				Dict						=    [[1, 2, 3], [1, 2, 4]]

							UpperCamelCase_:				Dict						=    DisjunctiveConstraint(snake_case_   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				str						=    dc.update(1   )
							UpperCamelCase_:				Union[str, Any]						=    stepped is True and completed is False and reset is False
							self.assertTrue(snake_case_   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Optional[int]						=    dc.update(2   )
							UpperCamelCase_:				Tuple						=    stepped is True and completed is False and reset is False
							self.assertTrue(snake_case_   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1, 2]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Optional[int]						=    dc.update(3   )
							UpperCamelCase_:				Union[str, Any]						=    stepped is True and completed is True and reset is False
							self.assertTrue(snake_case_   )
							self.assertTrue(dc.completed   )  # Completed!
							self.assertTrue(dc.current_seq == [1, 2, 3]   )




			def    lowerCAmelCase__						(							self			:							List[str]   ):
							UpperCamelCase_:				Optional[int]						=    [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

							UpperCamelCase_:				Tuple						=    DisjunctiveConstraint(snake_case_   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Dict						=    dc.update(1   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Union[str, Any]						=    dc.update(2   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1, 2]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Any						=    dc.update(4   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.current_seq == [1, 2, 4]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				int						=    dc.update(5   )
							self.assertTrue(dc.completed   )  # Completed!
							self.assertTrue(dc.current_seq == [1, 2, 4, 5]   )

							dc.reset()

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				int						=    dc.update(1   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.remaining() == 3   )
							self.assertTrue(dc.current_seq == [1]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				Tuple						=    dc.update(2   )
							self.assertTrue(not dc.completed   )
							self.assertTrue(dc.remaining() == 2   )
							self.assertTrue(dc.current_seq == [1, 2]   )

							UpperCamelCase_, UpperCamelCase_, UpperCamelCase_:				List[str]						=    dc.update(5   )
							self.assertTrue(dc.completed   )  # Completed!
							self.assertTrue(dc.remaining() == 0   )
							self.assertTrue(dc.current_seq == [1, 2, 5]   )






