
from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

_SCREAMING_SNAKE_CASE    :      Any          =			TypeVar('T')
_SCREAMING_SNAKE_CASE    :      Optional[int]          =			TypeVar('U')







class  UpperCamelCase__		(    Generic[T, U]   ):







	'''simple docstring'''





	def __init__(			self				,       UpperCamelCase__				,       UpperCamelCase__		):
					A__  :	Tuple         =							key
					A__  :	Optional[int]         =							val
					A__  :	int         =							None
					A__  :	List[Any]         =							None





	def __repr__(			self		):
					return (
					    F"Node: key: {self.key}, val: {self.val}, "
					    F"has next: {bool(self.next		)}, has prev: {bool(self.prev		)}"
					)







class  UpperCamelCase__		(    Generic[T, U]   ):







	'''simple docstring'''





	def __init__(			self		):
					A__  :	Dict         =							DoubleLinkedListNode(A__				,       A__		)
					A__  :	Tuple         =							DoubleLinkedListNode(A__				,       A__		)
					A__       ,							A__  :	Tuple         =							self.rear, self.head





	def __repr__(			self		):
					A__  :	str         =							['''DoubleLinkedList''']
					A__  :	List[str]         =							self.head
					while node.next is not None:
									rep.append(str(A__		)		)
									A__  :	Any         =							node.next
					rep.append(str(self.rear		)		)
					return ",\n    ".join(A__		)





	def   __snake_case				(			self				,       UpperCamelCase__		):
					A__  :	Optional[int]         =							self.rear.prev

					# All nodes other than self.head are guaranteed to have non-None previous
					assert previous is not None

					A__  :	List[str]         =							node
					A__  :	Optional[Any]         =							previous
					A__  :	Optional[Any]         =							node
					A__  :	str         =							self.rear





	def   __snake_case				(			self				,       UpperCamelCase__		):

					if node.prev is None or node.next is None:
									return None

					A__  :	Dict         =							node.next
					A__  :	int         =							node.prev
					A__  :	List[Any]         =							None
					A__  :	Dict         =							None
					return node







class  UpperCamelCase__		(    Generic[T, U]   ):







	'''simple docstring'''
	_lowerCAmelCase							       =				{}





	def __init__(			self				,       UpperCamelCase__		):
					A__  :	Optional[Any]         =							DoubleLinkedList()
					A__  :	Optional[Any]         =							capacity
					A__  :	Optional[Any]         =							0
					A__  :	Tuple         =							0
					A__  :	Tuple         =							0
					A__  :	List[Any]         =							{}





	def __repr__(			self		):
					return (
					    F"CacheInfo(hits={self.hits}, misses={self.miss}, "
					    F"capacity={self.capacity}, current size={self.num_keys})"
					)





	def __contains__(			self				,       UpperCamelCase__		):
					return key in self.cache





	def   __snake_case				(			self				,       UpperCamelCase__		):
					# Note: pythonic interface would throw KeyError rather than return None

					if key in self.cache:
									self.hits += 1
									A__  :	Union[str, Any]         =							self.cache[key]
									A__  :	List[str]         =							self.list.remove(self.cache[key]		)
									assert node == value_node

									# node is guaranteed not None because it is in self.cache
									assert node is not None
									self.list.add(A__		)
									return node.val
					self.miss += 1
					return None





	def   __snake_case				(			self				,       UpperCamelCase__				,       UpperCamelCase__		):

					if key not in self.cache:
									if self.num_keys >= self.capacity:
													# delete first node (oldest) when over capacity
													A__  :	List[str]         =							self.list.head.next

													# guaranteed to have a non-None first node when num_keys > 0
													# explain to type checker via assertions
													assert first_node is not None
													assert first_node.key is not None
													assert (
													    self.list.remove(A__		) is not None
													)  # node guaranteed to be in list assert node.key is not None

													del self.cache[first_node.key]
													self.num_keys -= 1
									A__  :	int         =							DoubleLinkedListNode(A__				,       A__		)
									self.list.add(self.cache[key]		)
									self.num_keys += 1

					else:
									# bump node to the end of the list, update value
									A__  :	List[str]         =							self.list.remove(self.cache[key]		)
									assert node is not None  # node guaranteed to be in list
									A__  :	List[str]         =							value
									self.list.add(A__		)





	@classmethod
	def   __snake_case				(			cls				,       UpperCamelCase__ = 128		):

					def cache_decorator_inner(UpperCamelCase__		) -> Callable[..., U]:
									def cache_decorator_wrapper(*UpperCamelCase__		) -> U:
													if func not in cls.decorator_function_to_instance_map:
																	A__  :	int         =							LRUCache(A__		)

													A__  :	str         =							cls.decorator_function_to_instance_map[func].get(args[0]		)
													if result is None:
																	A__  :	Union[str, Any]         =							func(*A__		)
																	cls.decorator_function_to_instance_map[func].put(args[0]				,       A__		)
													return result

									def cache_info() -> LRUCache[T, U]:
													return cls.decorator_function_to_instance_map[func]

									setattr(A__				,       '''cache_info'''				,       A__		)  # noqa: B010

									return cache_decorator_wrapper

					return cache_decorator_inner


if __name__ == "__main__":
					import doctest

					doctest.testmod()






from dataclasses import asdict, dataclass
from typing import Optional

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


_SCREAMING_SNAKE_CASE    :      Dict          =			logging.get_logger(__name__)

# TODO Update this
_SCREAMING_SNAKE_CASE    :      Optional[int]          =			{
    '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__		(    SCREAMING_SNAKE_CASE_   ):







	'''simple docstring'''
	_lowerCAmelCase							       =				"esm"





	def __init__(			self				,       UpperCamelCase__=None				,       UpperCamelCase__=None				,       UpperCamelCase__=None				,       UpperCamelCase__=768				,       UpperCamelCase__=12				,       UpperCamelCase__=12				,       UpperCamelCase__=3072				,       UpperCamelCase__=0.1				,       UpperCamelCase__=0.1				,       UpperCamelCase__=1026				,       UpperCamelCase__=0.0_2				,       UpperCamelCase__=1e-12				,       UpperCamelCase__="absolute"				,       UpperCamelCase__=True				,       UpperCamelCase__=None				,       UpperCamelCase__=False				,       UpperCamelCase__=False				,       UpperCamelCase__=None				,       UpperCamelCase__=None				,       **UpperCamelCase__				,       ):
					super().__init__(pad_token_id=UpperCamelCase__				,       mask_token_id=UpperCamelCase__				,       **UpperCamelCase__		)

					A__  :	Optional[Any]         =							vocab_size
					A__  :	int         =							hidden_size
					A__  :	List[str]         =							num_hidden_layers
					A__  :	Tuple         =							num_attention_heads
					A__  :	str         =							intermediate_size
					A__  :	List[str]         =							hidden_dropout_prob
					A__  :	Optional[Any]         =							attention_probs_dropout_prob
					A__  :	int         =							max_position_embeddings
					A__  :	List[str]         =							initializer_range
					A__  :	List[Any]         =							layer_norm_eps
					A__  :	int         =							position_embedding_type
					A__  :	Optional[Any]         =							use_cache
					A__  :	Optional[int]         =							emb_layer_norm_before
					A__  :	List[str]         =							token_dropout
					A__  :	Tuple         =							is_folding_model
					if is_folding_model:
									if esmfold_config is None:
													logger.info('''No esmfold_config supplied for folding model, using default values.'''		)
													A__  :	List[Any]         =							EsmFoldConfig()
									elif isinstance(UpperCamelCase__				,       UpperCamelCase__		):
													A__  :	Optional[int]         =							EsmFoldConfig(**UpperCamelCase__		)
									A__  :	int         =							esmfold_config
									if vocab_list is None:
													logger.warning('''No vocab_list supplied for folding model, assuming the ESM-2 vocabulary!'''		)
													A__  :	Any         =							get_default_vocab_list()
									else:
													A__  :	Dict         =							vocab_list
					else:
									A__  :	Optional[Any]         =							None
									A__  :	Tuple         =							None
					if self.esmfold_config is not None and getattr(self.esmfold_config				,       '''use_esm_attn_map'''				,       UpperCamelCase__		):
									raise ValueError('''The HuggingFace port of ESMFold does not support use_esm_attn_map at this time!'''		)





	def   __snake_case				(			self		):
					A__  :	Optional[int]         =							super().to_dict()
					if isinstance(self.esmfold_config				,       UpperCamelCase__		):
									A__  :	Dict         =							self.esmfold_config.to_dict()
					return output







@dataclass
class  UpperCamelCase__		:







	'''simple docstring'''
	_lowerCAmelCase							       =				None
	_lowerCAmelCase							       =				True
	_lowerCAmelCase							       =				False
	_lowerCAmelCase							       =				False
	_lowerCAmelCase							       =				False
	_lowerCAmelCase							       =				0

	_lowerCAmelCase							       =				True
	_lowerCAmelCase							       =				False

	_lowerCAmelCase							       =				128
	_lowerCAmelCase							       =				None





	def   __snake_case				(			self		):
					if self.trunk is None:
									A__  :	Tuple         =							TrunkConfig()
					elif isinstance(self.trunk				,       UpperCamelCase__		):
									A__  :	List[Any]         =							TrunkConfig(**self.trunk		)





	def   __snake_case				(			self		):
					A__  :	Optional[int]         =							asdict(self		)
					A__  :	int         =							self.trunk.to_dict()
					return output







@dataclass
class  UpperCamelCase__		:







	'''simple docstring'''
	_lowerCAmelCase							       =				48
	_lowerCAmelCase							       =				1_024
	_lowerCAmelCase							       =				128
	_lowerCAmelCase							       =				32
	_lowerCAmelCase							       =				32
	_lowerCAmelCase							       =				32
	_lowerCAmelCase							       =				0
	_lowerCAmelCase							       =				0
	_lowerCAmelCase							       =				False
	_lowerCAmelCase							       =				4
	_lowerCAmelCase							       =				128
	_lowerCAmelCase							       =				None





	def   __snake_case				(			self		):
					if self.structure_module is None:
									A__  :	str         =							StructureModuleConfig()
					elif isinstance(self.structure_module				,       UpperCamelCase__		):
									A__  :	str         =							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}."		)

					A__  :	Tuple         =							self.sequence_state_dim // self.sequence_head_width
					A__  :	int         =							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   __snake_case				(			self		):
					A__  :	List[Any]         =							asdict(self		)
					A__  :	Optional[int]         =							self.structure_module.to_dict()
					return output







@dataclass
class  UpperCamelCase__		:







	'''simple docstring'''
	_lowerCAmelCase							       =				384
	_lowerCAmelCase							       =				128
	_lowerCAmelCase							       =				16
	_lowerCAmelCase							       =				128
	_lowerCAmelCase							       =				12
	_lowerCAmelCase							       =				4
	_lowerCAmelCase							       =				8
	_lowerCAmelCase							       =				0.1
	_lowerCAmelCase							       =				8
	_lowerCAmelCase							       =				1
	_lowerCAmelCase							       =				2
	_lowerCAmelCase							       =				7
	_lowerCAmelCase							       =				10
	_lowerCAmelCase							       =				1e-8
	_lowerCAmelCase							       =				1e5





	def   __snake_case				(			self		):
					return asdict(self		)




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

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