'''simple docstring'''
import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers.models.esm.modeling_esmfold import EsmForProteinFolding







class lowerCamelCase				:




  '''simple docstring'''



  def __init__(   self      :							List[Any]	,				UpperCAmelCase__      :							int	,				UpperCAmelCase__      :							Optional[Any]=13	,				UpperCAmelCase__      :							List[Any]=7	,				UpperCAmelCase__      :							str=False	,				UpperCAmelCase__      :							Optional[Any]=True	,				UpperCAmelCase__      :							List[Any]=False	,				UpperCAmelCase__      :							int=False	,				UpperCAmelCase__      :							List[str]=19	,				UpperCAmelCase__      :							Dict=32	,				UpperCAmelCase__      :							Any=5	,				UpperCAmelCase__      :							Union[str, Any]=4	,				UpperCAmelCase__      :							List[str]=37	,				UpperCAmelCase__      :							Any="gelu"	,				UpperCAmelCase__      :							Optional[Any]=0.1	,				UpperCAmelCase__      :							Union[str, Any]=0.1	,				UpperCAmelCase__      :							int=512	,				UpperCAmelCase__      :							str=16	,				UpperCAmelCase__      :							Optional[int]=2	,				UpperCAmelCase__      :							Union[str, Any]=0.02	,				UpperCAmelCase__      :							Optional[Any]=3	,				UpperCAmelCase__      :							Dict=4	,				UpperCAmelCase__      :							int=None	,				)					->Tuple:
        UpperCAmelCase_      =	parent
        UpperCAmelCase_      =	batch_size
        UpperCAmelCase_      =	seq_length
        UpperCAmelCase_      =	is_training
        UpperCAmelCase_      =	use_input_mask
        UpperCAmelCase_      =	use_token_type_ids
        UpperCAmelCase_      =	use_labels
        UpperCAmelCase_      =	vocab_size
        UpperCAmelCase_      =	hidden_size
        UpperCAmelCase_      =	num_hidden_layers
        UpperCAmelCase_      =	num_attention_heads
        UpperCAmelCase_      =	intermediate_size
        UpperCAmelCase_      =	hidden_act
        UpperCAmelCase_      =	hidden_dropout_prob
        UpperCAmelCase_      =	attention_probs_dropout_prob
        UpperCAmelCase_      =	max_position_embeddings
        UpperCAmelCase_      =	type_vocab_size
        UpperCAmelCase_      =	type_sequence_label_size
        UpperCAmelCase_      =	initializer_range
        UpperCAmelCase_      =	num_labels
        UpperCAmelCase_      =	num_choices
        UpperCAmelCase_      =	scope






  def 			lowerCAmelCase__			(   self      :							int	)					->Optional[Any]:
        UpperCAmelCase_      =	ids_tensor([self.batch_size, self.seq_length]	,				self.vocab_size	)

        UpperCAmelCase_      =	None
        if self.use_input_mask:
              UpperCAmelCase_      =	random_attention_mask([self.batch_size, self.seq_length]	)

        UpperCAmelCase_      =	None
        UpperCAmelCase_      =	None
        UpperCAmelCase_      =	None
        if self.use_labels:
              UpperCAmelCase_      =	ids_tensor([self.batch_size]	,				self.type_sequence_label_size	)
              UpperCAmelCase_      =	ids_tensor([self.batch_size, self.seq_length]	,				self.num_labels	)
              UpperCAmelCase_      =	ids_tensor([self.batch_size]	,				self.num_choices	)

        UpperCAmelCase_      =	self.get_config()

        return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels






  def 			lowerCAmelCase__			(   self      :							Tuple	)					->Optional[Any]:
        UpperCAmelCase_      =	EsmConfig(
            vocab_size=33	,				hidden_size=self.hidden_size	,				pad_token_id=1	,				num_hidden_layers=self.num_hidden_layers	,				num_attention_heads=self.num_attention_heads	,				intermediate_size=self.intermediate_size	,				hidden_act=self.hidden_act	,				hidden_dropout_prob=self.hidden_dropout_prob	,				attention_probs_dropout_prob=self.attention_probs_dropout_prob	,				max_position_embeddings=self.max_position_embeddings	,				type_vocab_size=self.type_vocab_size	,				initializer_range=self.initializer_range	,				is_folding_model=UpperCAmelCase__	,				esmfold_config={'''trunk''': {'''num_blocks''': 2}, '''fp16_esm''': False}	,				)
        return config






  def 			lowerCAmelCase__			(   self      :							Optional[Any]	,				UpperCAmelCase__      :							List[Any]	,				UpperCAmelCase__      :							Any	,				UpperCAmelCase__      :							int	,				UpperCAmelCase__      :							Any	,				UpperCAmelCase__      :							int	,				UpperCAmelCase__      :							int	)					->Optional[int]:
        UpperCAmelCase_      =	EsmForProteinFolding(config=UpperCAmelCase__	).float()
        model.to(UpperCAmelCase__	)
        model.eval()
        UpperCAmelCase_      =	model(UpperCAmelCase__	,				attention_mask=UpperCAmelCase__	)
        UpperCAmelCase_      =	model(UpperCAmelCase__	)
        UpperCAmelCase_      =	model(UpperCAmelCase__	)

        self.parent.assertEqual(result.positions.shape	,				(8, self.batch_size, self.seq_length, 14, 3)	)
        self.parent.assertEqual(result.angles.shape	,				(8, self.batch_size, self.seq_length, 7, 2)	)






  def 			lowerCAmelCase__			(   self      :							Dict	)					->Union[str, Any]:
        UpperCAmelCase_      =	self.prepare_config_and_inputs()
        (
            (
            UpperCAmelCase_   
        )   ,		(
            UpperCAmelCase_   
        )   ,		(
            UpperCAmelCase_   
        )   ,		(
            UpperCAmelCase_   
        )   ,		(
            UpperCAmelCase_   
        )   ,		(
            UpperCAmelCase_   
        )   ,		   
        )      =	config_and_inputs
        UpperCAmelCase_      =	{'''input_ids''': input_ids, '''attention_mask''': input_mask}
        return config, inputs_dict







@require_torch
class lowerCamelCase				(						lowerCamelCase  ,		lowerCamelCase  ,		unittest.TestCase       ):




  '''simple docstring'''



  lowerCAmelCase__      				=						False

  lowerCAmelCase__      				=						(EsmForProteinFolding,) if is_torch_available() else ()
  lowerCAmelCase__      				=						()
  lowerCAmelCase__      				=						{} if is_torch_available() else {}
  lowerCAmelCase__      				=						False






  def 			lowerCAmelCase__			(   self      :							Union[str, Any]	)					->List[str]:
        UpperCAmelCase_      =	EsmFoldModelTester(self	)
        UpperCAmelCase_      =	ConfigTester(self	,				config_class=UpperCAmelCase__	,				hidden_size=37	)






  def 			lowerCAmelCase__			(   self      :							Tuple	)					->str:
        self.config_tester.run_common_tests()






  def 			lowerCAmelCase__			(   self      :							List[Any]	)					->Dict:
        UpperCAmelCase_      =	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*UpperCAmelCase__	)






  @unittest.skip('''Does not support attention outputs'''	)
  def 			lowerCAmelCase__			(   self      :							List[str]	)					->Optional[int]:
        pass






  @unittest.skip
  def 			lowerCAmelCase__			(   self      :							Dict	)					->Any:
        pass






  @unittest.skip('''Esm does not support embedding resizing'''	)
  def 			lowerCAmelCase__			(   self      :							List[Any]	)					->Tuple:
        pass






  @unittest.skip('''Esm does not support embedding resizing'''	)
  def 			lowerCAmelCase__			(   self      :							str	)					->List[Any]:
        pass






  @unittest.skip('''ESMFold does not support passing input embeds!'''	)
  def 			lowerCAmelCase__			(   self      :							Union[str, Any]	)					->int:
        pass






  @unittest.skip('''ESMFold does not support head pruning.'''	)
  def 			lowerCAmelCase__			(   self      :							int	)					->Any:
        pass






  @unittest.skip('''ESMFold does not support head pruning.'''	)
  def 			lowerCAmelCase__			(   self      :							List[str]	)					->List[Any]:
        pass






  @unittest.skip('''ESMFold does not support head pruning.'''	)
  def 			lowerCAmelCase__			(   self      :							Any	)					->Any:
        pass






  @unittest.skip('''ESMFold does not support head pruning.'''	)
  def 			lowerCAmelCase__			(   self      :							Tuple	)					->Optional[Any]:
        pass






  @unittest.skip('''ESMFold does not support head pruning.'''	)
  def 			lowerCAmelCase__			(   self      :							int	)					->str:
        pass






  @unittest.skip('''ESMFold does not output hidden states in the normal way.'''	)
  def 			lowerCAmelCase__			(   self      :							Any	)					->List[str]:
        pass






  @unittest.skip('''ESMfold does not output hidden states in the normal way.'''	)
  def 			lowerCAmelCase__			(   self      :							Dict	)					->List[Any]:
        pass






  @unittest.skip('''ESMFold only has one output format.'''	)
  def 			lowerCAmelCase__			(   self      :							int	)					->Optional[int]:
        pass






  @unittest.skip('''This test doesn\'t work for ESMFold and doesn\'t test core functionality'''	)
  def 			lowerCAmelCase__			(   self      :							str	)					->Any:
        pass






  @unittest.skip('''ESMFold does not support input chunking.'''	)
  def 			lowerCAmelCase__			(   self      :							Optional[Any]	)					->List[Any]:
        pass






  @unittest.skip('''ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'''	)
  def 			lowerCAmelCase__			(   self      :							Any	)					->Union[str, Any]:
        pass






  @unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''	)
  def 			lowerCAmelCase__			(   self      :							List[Any]	)					->Any:
        pass






  @unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''	)
  def 			lowerCAmelCase__			(   self      :							Optional[int]	)					->List[Any]:
        pass






  @unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''	)
  def 			lowerCAmelCase__			(   self      :							int	)					->Any:
        pass






  @unittest.skip('''ESMFold doesn\'t support data parallel.'''	)
  def 			lowerCAmelCase__			(   self      :							Tuple	)					->Dict:
        pass






  @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''	)
  def 			lowerCAmelCase__			(   self      :							Union[str, Any]	)					->Optional[int]:
        pass







@require_torch
class lowerCamelCase				(						lowerCamelCase       ):




  '''simple docstring'''



  @slow
  def 			lowerCAmelCase__			(   self      :							Union[str, Any]	)					->Optional[int]:
        UpperCAmelCase_      =	EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1'''	).float()
        model.eval()
        UpperCAmelCase_      =	torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]	)
        UpperCAmelCase_      =	model(UpperCAmelCase__	)['''positions''']
        UpperCAmelCase_      =	torch.tensor([2.5828, 0.7993, -10.9334]	,				dtype=torch.floataa	)
        self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]	,				UpperCAmelCase__	,				atol=1e-4	)	)









import os
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
						from .tokenization_big_bird import BigBirdTokenizer
else:
						__UpperCamelCase     		=							None

__UpperCamelCase     		=							logging.get_logger(__name__)
__UpperCamelCase     		=							{'vocab_file': 'spiece.model', 'tokenizer_file': 'tokenizer.json'}

__UpperCamelCase     		=							{
    'vocab_file': {
        'google/bigbird-roberta-base': 'https://huggingface.co/google/bigbird-roberta-base/resolve/main/spiece.model',
        'google/bigbird-roberta-large': (
            'https://huggingface.co/google/bigbird-roberta-large/resolve/main/spiece.model'
        ),
        'google/bigbird-base-trivia-itc': (
            'https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/spiece.model'
        ),
    },
    'tokenizer_file': {
        'google/bigbird-roberta-base': (
            'https://huggingface.co/google/bigbird-roberta-base/resolve/main/tokenizer.json'
        ),
        'google/bigbird-roberta-large': (
            'https://huggingface.co/google/bigbird-roberta-large/resolve/main/tokenizer.json'
        ),
        'google/bigbird-base-trivia-itc': (
            'https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/tokenizer.json'
        ),
    },
}

__UpperCamelCase     		=							{
    'google/bigbird-roberta-base': 4_0_9_6,
    'google/bigbird-roberta-large': 4_0_9_6,
    'google/bigbird-base-trivia-itc': 4_0_9_6,
}


__UpperCamelCase     		=							'▁'







class 							lowerCamelCase__						(				UpperCAmelCase   ):






			"""simple docstring"""






			_UpperCamelCase		:       Dict 			=		VOCAB_FILES_NAMES
			_UpperCamelCase		:       int 			=		PRETRAINED_VOCAB_FILES_MAP
			_UpperCamelCase		:       List[Any] 			=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			_UpperCamelCase		:       Optional[Any] 			=		BigBirdTokenizer
			_UpperCamelCase		:       Dict 			=		['input_ids', 'attention_mask']
			_UpperCamelCase		:       List[int] 			=		[]




			def __init__(				self   ,    snake_case=None   ,    snake_case=None   ,    snake_case="<unk>"   ,    snake_case="<s>"   ,    snake_case="</s>"   ,    snake_case="<pad>"   ,    snake_case="[SEP]"   ,    snake_case="[MASK]"   ,    snake_case="[CLS]"   ,    **snake_case   ,    ):

						'''simple docstring'''


						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else bos_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else eos_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else unk_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else pad_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else cls_token
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else sep_token

						# Mask token behave like a normal word, i.e. include the space before it
						UpperCamelCase__       =							AddedToken(snake_case   ,    lstrip=snake_case   ,    rstrip=snake_case  ) if isinstance(snake_case   ,    snake_case  ) else mask_token

						super().__init__(
						    snake_case   ,    tokenizer_file=snake_case   ,    bos_token=snake_case   ,    eos_token=snake_case   ,    unk_token=snake_case   ,    sep_token=snake_case   ,    pad_token=snake_case   ,    cls_token=snake_case   ,    mask_token=snake_case   ,    **snake_case   ,    )

						UpperCamelCase__       =							vocab_file
						UpperCamelCase__       =							False if not self.vocab_file else True




			def 					snake_case__					(				self   ,    snake_case   ,    snake_case = None  ):

						'''simple docstring'''


						UpperCamelCase__       =							[self.sep_token_id]
						UpperCamelCase__       =							[self.cls_token_id]
						if token_ids_a is None:
									return cls + token_ids_a + sep
						return cls + token_ids_a + sep + token_ids_a + sep




			def 					snake_case__					(				self   ,    snake_case   ,    snake_case = None   ,    snake_case = False  ):

						'''simple docstring'''


						if already_has_special_tokens:
									if token_ids_a is not None:
												raise ValueError(
												    "You should not supply a second sequence if the provided sequence of "
												    "ids is already formatted with special tokens for the model."  )
									return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

						if token_ids_a is None:
									return [1] + ([0] * len(snake_case  )) + [1]
						return [1] + ([0] * len(snake_case  )) + [1] + ([0] * len(snake_case  )) + [1]




			def 					snake_case__					(				self   ,    snake_case   ,    snake_case = None  ):

						'''simple docstring'''


						UpperCamelCase__       =							[self.sep_token_id]
						UpperCamelCase__       =							[self.cls_token_id]

						if token_ids_a is None:
									return len(cls + token_ids_a + sep  ) * [0]
						return len(cls + token_ids_a + sep  ) * [0] + len(token_ids_a + sep  ) * [1]







			def 					snake_case__					(				self   ,    snake_case   ,    snake_case = None  ):

						'''simple docstring'''


						if not self.can_save_slow_tokenizer:
									raise ValueError(
									    "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
									    "tokenizer."  )

						if not os.path.isdir(snake_case  ):
									logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''  )
									return
						UpperCamelCase__       =							os.path.join(
						    snake_case   ,    (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]  )

						if os.path.abspath(self.vocab_file  ) != os.path.abspath(snake_case  ):
									copyfile(self.vocab_file   ,    snake_case  )

						return (out_vocab_file,)


