code: 
  
  
  
  
  
  '''simple docstring'''
  
  import unittest
  
  from transformers import YosoConfig, is_torch_available
  from transformers.testing_utils import require_torch, slow, torch_device
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
    import torch
  
    from transformers import (
        YosoForMaskedLM,
        YosoForMultipleChoice,
        YosoForQuestionAnswering,
        YosoForSequenceClassification,
        YosoForTokenClassification,
        YosoModel,
    )
    from transformers.models.yoso.modeling_yoso import YOSO_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  
  
  
  
  class      UpperCAmelCase			:
   def __init__(       self   :List[Any]		, lowercase_   :Any		, lowercase_   :List[Any]=13		, lowercase_   :List[str]=7		, lowercase_   :Optional[int]=True		, lowercase_   :str=True		, lowercase_   :str=True		, lowercase_   :Tuple=True		, lowercase_   :Optional[Any]=99		, lowercase_   :Any=32		, lowercase_   :List[str]=5		, lowercase_   :Optional[Any]=4		, lowercase_   :List[Any]=37		, lowercase_   :Any="gelu"		, lowercase_   :Optional[Any]=0.1		, lowercase_   :Any=0.1		, lowercase_   :List[Any]=5_12		, lowercase_   :Any=16		, lowercase_   :Tuple=2		, lowercase_   :Dict=0.0_2		, lowercase_   :int=3		, lowercase_   :Any=4		, lowercase_   :Union[str, Any]=None		, )->							Optional[Any]:
       A__       =    parent
       A__       =    batch_size
       A__       =    seq_length
       A__       =    is_training
       A__       =    use_input_mask
       A__       =    use_token_type_ids
       A__       =    use_labels
       A__       =    vocab_size
       A__       =    hidden_size
       A__       =    num_hidden_layers
       A__       =    num_attention_heads
       A__       =    intermediate_size
       A__       =    hidden_act
       A__       =    hidden_dropout_prob
       A__       =    attention_probs_dropout_prob
       A__       =    max_position_embeddings
       A__       =    type_vocab_size
       A__       =    type_sequence_label_size
       A__       =    initializer_range
       A__       =    num_labels
       A__       =    num_choices
       A__       =    scope
   def   UpperCAmelCase_							(       self   :Union[str, Any]							)->							List[str]:
       A__       =    ids_tensor([self.batch_size, self.seq_length]		, self.vocab_size							)
  
       A__       =    None
       if self.use_input_mask:
           A__       =    random_attention_mask([self.batch_size, self.seq_length]							)
  
       A__       =    None
       if self.use_token_type_ids:
           A__       =    ids_tensor([self.batch_size, self.seq_length]		, self.type_vocab_size							)
  
       A__       =    None
       A__       =    None
       A__       =    None
       if self.use_labels:
           A__       =    ids_tensor([self.batch_size]		, self.type_sequence_label_size							)
           A__       =    ids_tensor([self.batch_size, self.seq_length]		, self.num_labels							)
           A__       =    ids_tensor([self.batch_size]		, self.num_choices							)
  
       A__       =    self.get_config()
  
       return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
   def   UpperCAmelCase_							(       self   :int							)->							Dict:
       return YosoConfig(
           vocab_size=self.vocab_size		, hidden_size=self.hidden_size		, 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		, is_decoder=lowercase_		, initializer_range=self.initializer_range		, )
   def   UpperCAmelCase_							(       self   :List[str]							)->							Optional[int]:
       A__       =    self.get_config()
       A__       =    3_00
       return config
   def   UpperCAmelCase_							(       self   :Dict							)->							str:
       (
           (
           A__
       ),			(
           A__
       ),			(
           A__
       ),			(
           A__
       ),			(
           A__
       ),			(
           A__
       ),			(
           A__
       ),			
       )       =    self.prepare_config_and_inputs()
  
       A__       =    True
       A__       =    floats_tensor([self.batch_size, self.seq_length, self.hidden_size]							)
       A__       =    ids_tensor([self.batch_size, self.seq_length]		, vocab_size=2							)
  
       return (
           config,
           input_ids,
           token_type_ids,
           input_mask,
           sequence_labels,
           token_labels,
           choice_labels,
           encoder_hidden_states,
           encoder_attention_mask,
       )
   def   UpperCAmelCase_							(       self   :List[str]		, lowercase_   :List[Any]		, lowercase_   :str		, lowercase_   :Any		, lowercase_   :List[Any]		, lowercase_   :Tuple		, lowercase_   :Dict		, lowercase_   :Optional[int]							)->							Tuple:
       A__       =    YosoModel(config=lowercase_							)
       model.to(lowercase_							)
       model.eval()
       A__       =    model(lowercase_		, attention_mask=lowercase_		, token_type_ids=lowercase_							)
       A__       =    model(lowercase_		, token_type_ids=lowercase_							)
       A__       =    model(lowercase_							)
       self.parent.assertEqual(result.last_hidden_state.shape		, (self.batch_size, self.seq_length, self.hidden_size)							)
   def   UpperCAmelCase_							(       self   :Union[str, Any]		, lowercase_   :Union[str, Any]		, lowercase_   :Optional[Any]		, lowercase_   :Optional[Any]		, lowercase_   :str		, lowercase_   :List[str]		, lowercase_   :str		, lowercase_   :Tuple		, lowercase_   :str		, lowercase_   :Any		, )->							Tuple:
       A__       =    True
       A__       =    YosoModel(lowercase_							)
       model.to(lowercase_							)
       model.eval()
       A__       =    model(
           lowercase_		, attention_mask=lowercase_		, token_type_ids=lowercase_		, encoder_hidden_states=lowercase_		, encoder_attention_mask=lowercase_		, )
       A__       =    model(
           lowercase_		, attention_mask=lowercase_		, token_type_ids=lowercase_		, encoder_hidden_states=lowercase_		, )
       A__       =    model(lowercase_		, attention_mask=lowercase_		, token_type_ids=lowercase_							)
       self.parent.assertEqual(result.last_hidden_state.shape		, (self.batch_size, self.seq_length, self.hidden_size)							)
   def   UpperCAmelCase_							(       self   :int		, lowercase_   :str		, lowercase_   :Any		, lowercase_   :Any		, lowercase_   :Optional[int]		, lowercase_   :List[str]		, lowercase_   :int		, lowercase_   :str							)->							Any:
       A__       =    YosoForMaskedLM(config=lowercase_							)
       model.to(lowercase_							)
       model.eval()
       A__       =    model(lowercase_		, attention_mask=lowercase_		, token_type_ids=lowercase_		, labels=lowercase_							)
       self.parent.assertEqual(result.logits.shape		, (self.batch_size, self.seq_length, self.vocab_size)							)
   def   UpperCAmelCase_							(       self   :List[Any]		, lowercase_   :List[str]		, lowercase_   :Tuple		, lowercase_   :Optional[int]		, lowercase_   :Union[str, Any]		, lowercase_   :List[str]		, lowercase_   :Any		, lowercase_   :Dict							)->							List[str]:
       A__       =    YosoForQuestionAnswering(config=lowercase_							)
       model.to(lowercase_							)
       model.eval()
       A__       =    model(
           lowercase_		, attention_mask=lowercase_		, token_type_ids=lowercase_		, start_positions=lowercase_		, end_positions=lowercase_		, )
       self.parent.assertEqual(result.start_logits.shape		, (self.batch_size, self.seq_length)							)
       self.parent.assertEqual(result.end_logits.shape		, (self.batch_size, self.seq_length)							)
   def   UpperCAmelCase_							(       self   :Dict		, lowercase_   :List[str]		, lowercase_   :int		, lowercase_   :str		, lowercase_   :List[str]		, lowercase_   :List[str]		, lowercase_   :Dict		, lowercase_   :Union[str, Any]							)->							Union[str, Any]:
       A__       =    self.num_labels
       A__       =    YosoForSequenceClassification(lowercase_							)
       model.to(lowercase_							)
       model.eval()
       A__       =    model(lowercase_		, attention_mask=lowercase_		, token_type_ids=lowercase_		, labels=lowercase_							)
       self.parent.assertEqual(result.logits.shape		, (self.batch_size, self.num_labels)							)
   def   UpperCAmelCase_							(       self   :Union[str, Any]		, lowercase_   :str		, lowercase_   :List[Any]		, lowercase_   :Optional[int]		, lowercase_   :Tuple		, lowercase_   :Dict		, lowercase_   :Optional[Any]		, lowercase_   :Optional[Any]							)->							Tuple:
       A__       =    self.num_labels
       A__       =    YosoForTokenClassification(config=lowercase_							)
       model.to(lowercase_							)
       model.eval()
       A__       =    model(lowercase_		, attention_mask=lowercase_		, token_type_ids=lowercase_		, labels=lowercase_							)
       self.parent.assertEqual(result.logits.shape		, (self.batch_size, self.seq_length, self.num_labels)							)
   def   UpperCAmelCase_							(       self   :Optional[Any]		, lowercase_   :Optional[Any]		, lowercase_   :Union[str, Any]		, lowercase_   :List[str]		, lowercase_   :int		, lowercase_   :int		, lowercase_   :Union[str, Any]		, lowercase_   :Union[str, Any]							)->							str:
       A__       =    self.num_choices
       A__       =    YosoForMultipleChoice(config=lowercase_							)
       model.to(lowercase_							)
       model.eval()
       A__       =    input_ids.unsqueeze(1							).expand(-1		, self.num_choices		, -1							).contiguous()
       A__       =    token_type_ids.unsqueeze(1							).expand(-1		, self.num_choices		, -1							).contiguous()
       A__       =    input_mask.unsqueeze(1							).expand(-1		, self.num_choices		, -1							).contiguous()
       A__       =    model(
           lowercase_		, attention_mask=lowercase_		, token_type_ids=lowercase_		, labels=lowercase_		, )
       self.parent.assertEqual(result.logits.shape		, (self.batch_size, self.num_choices)							)
  
  
  
   def   UpperCAmelCase_							(       self   :List[Any]							)->							Optional[int]:
       A__       =    self.prepare_config_and_inputs()
       (
           (
           A__
       ),			(
           A__
       ),			(
           A__
       ),			(
           A__
       ),			(
           A__
       ),			(
           A__
       ),			(
           A__
       ),			
       )       =    config_and_inputs
       A__       =    {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
       return config, inputs_dict
  
  
  
  
  
  
  @require_torch
  class      UpperCAmelCase			( UpperCamelCase__    , UpperCamelCase__    , unittest.TestCase       ):
   __lowercase     	=       (
       (
           YosoModel,
           YosoForMaskedLM,
           YosoForMultipleChoice,
           YosoForQuestionAnswering,
           YosoForSequenceClassification,
           YosoForTokenClassification,
       )
       if is_torch_available()
       else ()
   )
   __lowercase     	=       False
   __lowercase     	=       False
   __lowercase     	=       False
  
   __lowercase     	=       ()
   __lowercase     	=       (
       {
           """feature-extraction""": YosoModel,
           """fill-mask""": YosoForMaskedLM,
           """question-answering""": YosoForQuestionAnswering,
           """text-classification""": YosoForSequenceClassification,
           """token-classification""": YosoForTokenClassification,
           """zero-shot""": YosoForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   def   UpperCAmelCase_							(       self   :Optional[Any]							)->							Any:
       A__       =    YosoModelTester(self							)
       A__       =    ConfigTester(self		, config_class=lowercase_		, hidden_size=37							)
   def   UpperCAmelCase_							(       self   :Optional[Any]							)->							List[str]:
       self.config_tester.run_common_tests()
   def   UpperCAmelCase_							(       self   :Optional[int]							)->							Optional[int]:
       A__       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*lowercase_							)
   def   UpperCAmelCase_							(       self   :List[Any]							)->							List[Any]:
       A__       =    self.model_tester.prepare_config_and_inputs()
       for type in ["absolute", "relative_key", "relative_key_query"]:
           A__       =    type
           self.model_tester.create_and_check_model(*lowercase_							)
   def   UpperCAmelCase_							(       self   :str							)->							str:
       A__       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*lowercase_							)
   def   UpperCAmelCase_							(       self   :List[str]							)->							List[Any]:
       A__       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*lowercase_							)
   def   UpperCAmelCase_							(       self   :str							)->							Tuple:
       A__       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*lowercase_							)
   def   UpperCAmelCase_							(       self   :Optional[int]							)->							str:
       A__       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*lowercase_							)
   def   UpperCAmelCase_							(       self   :str							)->							Dict:
       A__       =    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*lowercase_							)
   @slow
   def   UpperCAmelCase_							(       self   :Tuple							)->							Union[str, Any]:
       for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           A__       =    YosoModel.from_pretrained(lowercase_							)
           self.assertIsNotNone(lowercase_							)
  
  
  
   def   UpperCAmelCase_							(       self   :Any							)->							int:
       return
  
  
  
  
  
  
  @require_torch
  class      UpperCAmelCase			( unittest.TestCase       ):
   @slow
   def   UpperCAmelCase_							(       self   :Optional[int]							)->							List[str]:
       A__       =    YosoModel.from_pretrained("uw-madison/yoso-4096"							)
       A__       =    torch.tensor([[0, 1, 2, 3, 4, 5]]							)
  
       with torch.no_grad():
           A__       =    model(lowercase_							)[0]
  
       A__       =    torch.Size((1, 6, 7_68)							)
       self.assertEqual(output.shape		, lowercase_							)
  
       A__       =    torch.tensor(
           [[[-0.0_6_1_1, 0.1_2_4_2, 0.0_8_4_0], [0.0_2_8_0, -0.0_0_4_8, 0.1_1_2_5], [0.0_1_0_6, 0.0_2_2_6, 0.0_7_5_1]]]							)
  
       self.assertTrue(torch.allclose(output[:, :3, :3]		, lowercase_		, atol=1E-4							)							)
   @slow
   def   UpperCAmelCase_							(       self   :List[str]							)->							Optional[int]:
       A__       =    YosoForMaskedLM.from_pretrained("uw-madison/yoso-4096"							)
       A__       =    torch.tensor([[0, 1, 2, 3, 4, 5]]							)
  
       with torch.no_grad():
           A__       =    model(lowercase_							)[0]
  
       A__       =    5_02_65
  
       A__       =    torch.Size((1, 6, vocab_size)							)
       self.assertEqual(output.shape		, lowercase_							)
  
       A__       =    torch.tensor(
           [[[-2.1_3_1_3, -3.7_2_8_5, -2.2_4_0_7], [-2.7_0_4_7, -3.3_3_1_4, -2.6_4_0_8], [0.0_6_2_9, -2.5_1_6_6, -0.3_3_5_6]]]							)
  
       self.assertTrue(torch.allclose(output[:, :3, :3]		, lowercase_		, atol=1E-4							)							)
  
  
  
   @slow
   def   UpperCAmelCase_							(       self   :str							)->							Optional[Any]:
       A__       =    YosoForMaskedLM.from_pretrained("uw-madison/yoso-4096"							)
       A__       =    torch.arange(40_96							).unsqueeze(0							)
  
       with torch.no_grad():
           A__       =    model(lowercase_							)[0]
  
       A__       =    5_02_65
  
       A__       =    torch.Size((1, 40_96, vocab_size)							)
       self.assertEqual(output.shape		, lowercase_							)
  
       A__       =    torch.tensor(
           [[[-2.3_9_1_4, -4.3_7_4_2, -5.0_9_5_6], [-4.0_9_8_8, -4.2_3_8_4, -7.0_4_0_6], [-3.1_4_2_7, -3.7_1_9_2, -6.6_8_0_0]]]							)
  
       self.assertTrue(torch.allclose(output[:, :3, :3]		, lowercase_		, atol=1E-4							)							)
  
  
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  import os
  import tempfile
  import unittest
  from typing import List
  
  from transformers.models.esm.tokenization_esm import VOCAB_FILES_NAMES, EsmTokenizer
  from transformers.testing_utils import require_tokenizers
  from transformers.tokenization_utils import PreTrainedTokenizer
  from transformers.tokenization_utils_base import PreTrainedTokenizerBase
  
  
  
  
  
  
  @require_tokenizers
  class      UpperCAmelCase			( unittest.TestCase       ):
   __lowercase     	=       EsmTokenizer
   def   UpperCAmelCase_							(       self   :Any							)->							int:
       super().setUp()
       A__       =    tempfile.mkdtemp()
       # fmt: off
       A__       =    ["<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>"]  # noqa: E501
       # fmt: on
       A__       =    os.path.join(self.tmpdirname		, VOCAB_FILES_NAMES["vocab_file"]							)
       with open(self.vocab_file		, "w"		, encoding="utf-8"							) as vocab_writer:
           vocab_writer.write("".join([x + "\n" for x in vocab_tokens]							)							)
   def   UpperCAmelCase_							(       self   :Any		, **lowercase_   :int							)->							List[PreTrainedTokenizerBase]:
       return [self.get_tokenizer(**lowercase_							)]
   def   UpperCAmelCase_							(       self   :Any		, **lowercase_   :Dict							)->							PreTrainedTokenizer:
       return self.tokenizer_class.from_pretrained(self.tmpdirname		, **lowercase_							)
   def   UpperCAmelCase_							(       self   :int							)->							Dict:
       A__       =    self.tokenizer_class(self.vocab_file							)
  
       A__       =    tokenizer.tokenize("LAGVS"							)
       self.assertListEqual(lowercase_		, ["L", "A", "G", "V", "S"]							)
       self.assertListEqual(tokenizer.convert_tokens_to_ids(lowercase_							)		, [4, 5, 6, 7, 8]							)
   def   UpperCAmelCase_							(       self   :Tuple							)->							Tuple:
       A__       =    self.tokenizer_class(self.vocab_file							)
  
       A__       =    "LAGVS"
       self.assertListEqual(tokenizer.encode(lowercase_							)		, [0, 4, 5, 6, 7, 8, 2]							)
   def   UpperCAmelCase_							(       self   :Any							)->							Tuple:
       A__       =    self.tokenizer_class(self.vocab_file							)
  
       A__       =    ["LAGVS", "WCB"]
       A__       =    tokenizer(lowercase_		, padding=lowercase_							)["input_ids"]
  
       self.assertListEqual(lowercase_		, [[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2]]							)
   def   UpperCAmelCase_							(       self   :str							)->							Any:
       A__       =    self.tokenizer_class(self.vocab_file							)
  
       A__       =    ["LAGVS", "WCB"]
       A__       =    tokenizer(lowercase_		, padding=lowercase_							)["input_ids"]
  
       self.assertListEqual(lowercase_		, [[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2, 1, 1]]							)
  
  
  
   def   UpperCAmelCase_							(       self   :Optional[Any]							)->							List[str]:
       A__       =    self.get_tokenizers(fast=lowercase_							)
       for tokenizer in tokenizers:
           with self.subTest(F"{tokenizer.__class__.__name__}"							):
               A__       =    "<unk>"
               A__       =    "<mask>"
  
               A__       =    tokenizer.tokenize(lowercase_							)
               A__       =    tokenizer.tokenize(lowercase_							)
  
               self.assertEqual(len(lowercase_							)		, 1							)
               self.assertEqual(len(lowercase_							)		, 1							)
               self.assertEqual(token_a[0]		, lowercase_							)
               self.assertEqual(token_a[0]		, lowercase_							)
  
  
  
  