
'''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 		snake_case_       :



   """simple docstring"""





   def __init__( self			,   UpperCamelCase			,   UpperCamelCase=13			,   UpperCamelCase=7			,   UpperCamelCase=True			,   UpperCamelCase=True			,   UpperCamelCase=True			,   UpperCamelCase=True			,   UpperCamelCase=99			,   UpperCamelCase=32			,   UpperCamelCase=5			,   UpperCamelCase=4			,   UpperCamelCase=37			,   UpperCamelCase="gelu"			,   UpperCamelCase=0.1			,   UpperCamelCase=0.1			,   UpperCamelCase=5_12			,   UpperCamelCase=16			,   UpperCamelCase=2			,   UpperCamelCase=0.0_2			,   UpperCamelCase=3			,   UpperCamelCase=4			,   UpperCamelCase=None			,   ):
          lowerCamelCase__				   =      parent
          lowerCamelCase__				   =      batch_size
          lowerCamelCase__				   =      seq_length
          lowerCamelCase__				   =      is_training
          lowerCamelCase__				   =      use_input_mask
          lowerCamelCase__				   =      use_token_type_ids
          lowerCamelCase__				   =      use_labels
          lowerCamelCase__				   =      vocab_size
          lowerCamelCase__				   =      hidden_size
          lowerCamelCase__				   =      num_hidden_layers
          lowerCamelCase__				   =      num_attention_heads
          lowerCamelCase__				   =      intermediate_size
          lowerCamelCase__				   =      hidden_act
          lowerCamelCase__				   =      hidden_dropout_prob
          lowerCamelCase__				   =      attention_probs_dropout_prob
          lowerCamelCase__				   =      max_position_embeddings
          lowerCamelCase__				   =      type_vocab_size
          lowerCamelCase__				   =      type_sequence_label_size
          lowerCamelCase__				   =      initializer_range
          lowerCamelCase__				   =      num_labels
          lowerCamelCase__				   =      num_choices
          lowerCamelCase__				   =      scope







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      ids_tensor([self.batch_size, self.seq_length]			,   self.vocab_size)

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

          lowerCamelCase__				   =      None
          if self.use_token_type_ids:
                 lowerCamelCase__				   =      ids_tensor([self.batch_size, self.seq_length]			,   self.type_vocab_size)

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

          lowerCamelCase__				   =      self.get_config()

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







   def     __UpperCAmelCase      ( self):
          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=UpperCamelCase			,   initializer_range=self.initializer_range			,   )







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      self.get_config()
          lowerCamelCase__				   =      3_00
          return config







   def     __UpperCAmelCase      ( self):
          (
              (
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		
          )				   =      self.prepare_config_and_inputs()

          lowerCamelCase__				   =      True
          lowerCamelCase__				   =      floats_tensor([self.batch_size, self.seq_length, self.hidden_size])
          lowerCamelCase__				   =      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			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase):
          lowerCamelCase__				   =      YosoModel(config=UpperCamelCase)
          model.to(UpperCamelCase)
          model.eval()
          lowerCamelCase__				   =      model(UpperCamelCase			,   attention_mask=UpperCamelCase			,   token_type_ids=UpperCamelCase)
          lowerCamelCase__				   =      model(UpperCamelCase			,   token_type_ids=UpperCamelCase)
          lowerCamelCase__				   =      model(UpperCamelCase)
          self.parent.assertEqual(result.last_hidden_state.shape			,   (self.batch_size, self.seq_length, self.hidden_size))







   def     __UpperCAmelCase      ( self			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   ):
          lowerCamelCase__				   =      True
          lowerCamelCase__				   =      YosoModel(UpperCamelCase)
          model.to(UpperCamelCase)
          model.eval()
          lowerCamelCase__				   =      model(
              UpperCamelCase			,   attention_mask=UpperCamelCase			,   token_type_ids=UpperCamelCase			,   encoder_hidden_states=UpperCamelCase			,   encoder_attention_mask=UpperCamelCase			,   )
          lowerCamelCase__				   =      model(
              UpperCamelCase			,   attention_mask=UpperCamelCase			,   token_type_ids=UpperCamelCase			,   encoder_hidden_states=UpperCamelCase			,   )
          lowerCamelCase__				   =      model(UpperCamelCase			,   attention_mask=UpperCamelCase			,   token_type_ids=UpperCamelCase)
          self.parent.assertEqual(result.last_hidden_state.shape			,   (self.batch_size, self.seq_length, self.hidden_size))







   def     __UpperCAmelCase      ( self			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase):
          lowerCamelCase__				   =      YosoForMaskedLM(config=UpperCamelCase)
          model.to(UpperCamelCase)
          model.eval()
          lowerCamelCase__				   =      model(UpperCamelCase			,   attention_mask=UpperCamelCase			,   token_type_ids=UpperCamelCase			,   labels=UpperCamelCase)
          self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.seq_length, self.vocab_size))







   def     __UpperCAmelCase      ( self			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase):
          lowerCamelCase__				   =      YosoForQuestionAnswering(config=UpperCamelCase)
          model.to(UpperCamelCase)
          model.eval()
          lowerCamelCase__				   =      model(
              UpperCamelCase			,   attention_mask=UpperCamelCase			,   token_type_ids=UpperCamelCase			,   start_positions=UpperCamelCase			,   end_positions=UpperCamelCase			,   )
          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			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase):
          lowerCamelCase__				   =      self.num_labels
          lowerCamelCase__				   =      YosoForSequenceClassification(UpperCamelCase)
          model.to(UpperCamelCase)
          model.eval()
          lowerCamelCase__				   =      model(UpperCamelCase			,   attention_mask=UpperCamelCase			,   token_type_ids=UpperCamelCase			,   labels=UpperCamelCase)
          self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.num_labels))







   def     __UpperCAmelCase      ( self			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase):
          lowerCamelCase__				   =      self.num_labels
          lowerCamelCase__				   =      YosoForTokenClassification(config=UpperCamelCase)
          model.to(UpperCamelCase)
          model.eval()
          lowerCamelCase__				   =      model(UpperCamelCase			,   attention_mask=UpperCamelCase			,   token_type_ids=UpperCamelCase			,   labels=UpperCamelCase)
          self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.seq_length, self.num_labels))







   def     __UpperCAmelCase      ( self			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase			,   UpperCamelCase):
          lowerCamelCase__				   =      self.num_choices
          lowerCamelCase__				   =      YosoForMultipleChoice(config=UpperCamelCase)
          model.to(UpperCamelCase)
          model.eval()
          lowerCamelCase__				   =      input_ids.unsqueeze(1).expand(-1			,   self.num_choices			,   -1).contiguous()
          lowerCamelCase__				   =      token_type_ids.unsqueeze(1).expand(-1			,   self.num_choices			,   -1).contiguous()
          lowerCamelCase__				   =      input_mask.unsqueeze(1).expand(-1			,   self.num_choices			,   -1).contiguous()
          lowerCamelCase__				   =      model(
              UpperCamelCase			,   attention_mask=UpperCamelCase			,   token_type_ids=UpperCamelCase			,   labels=UpperCamelCase			,   )
          self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.num_choices))







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      self.prepare_config_and_inputs()
          (
              (
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		(
              lowerCamelCase__
          )   ,		
          )				   =      config_and_inputs
          lowerCamelCase__				   =      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
          return config, inputs_dict







@require_torch
class 		snake_case_       (						A__		,	A__		,	unittest.TestCase						):



   """simple docstring"""





   __lowerCAmelCase	:							Optional[int]								=(
       (
           YosoModel,
           YosoForMaskedLM,
           YosoForMultipleChoice,
           YosoForQuestionAnswering,
           YosoForSequenceClassification,
           YosoForTokenClassification,
       )
       if is_torch_available()
       else ()
   )
   __lowerCAmelCase	:							int								=False
   __lowerCAmelCase	:							Union[str, Any]								=False
   __lowerCAmelCase	:							str								=False

   __lowerCAmelCase	:							Dict								=()
   __lowerCAmelCase	:							int								=(
       {
           '''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):
          lowerCamelCase__				   =      YosoModelTester(self)
          lowerCamelCase__				   =      ConfigTester(self			,   config_class=UpperCamelCase			,   hidden_size=37)







   def     __UpperCAmelCase      ( self):
          self.config_tester.run_common_tests()







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*UpperCamelCase)







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      self.model_tester.prepare_config_and_inputs()
          for type in ["absolute", "relative_key", "relative_key_query"]:
                 lowerCamelCase__				   =      type
                 self.model_tester.create_and_check_model(*UpperCamelCase)







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase)







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase)







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*UpperCamelCase)







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase)







   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*UpperCamelCase)







   @slow
   def     __UpperCAmelCase      ( self):
          for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 lowerCamelCase__				   =      YosoModel.from_pretrained(UpperCamelCase)
                 self.assertIsNotNone(UpperCamelCase)







   def     __UpperCAmelCase      ( self):
          return







@require_torch
class 		snake_case_       (						unittest.TestCase						):



   """simple docstring"""





   @slow
   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      YosoModel.from_pretrained("uw-madison/yoso-4096")
          lowerCamelCase__				   =      torch.tensor([[0, 1, 2, 3, 4, 5]])

          with torch.no_grad():
                 lowerCamelCase__				   =      model(UpperCamelCase)[0]

          lowerCamelCase__				   =      torch.Size((1, 6, 7_68))
          self.assertEqual(output.shape			,   UpperCamelCase)

          lowerCamelCase__				   =      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]			,   UpperCamelCase			,   atol=1E-4))







   @slow
   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      YosoForMaskedLM.from_pretrained("uw-madison/yoso-4096")
          lowerCamelCase__				   =      torch.tensor([[0, 1, 2, 3, 4, 5]])

          with torch.no_grad():
                 lowerCamelCase__				   =      model(UpperCamelCase)[0]

          lowerCamelCase__				   =      5_02_65

          lowerCamelCase__				   =      torch.Size((1, 6, vocab_size))
          self.assertEqual(output.shape			,   UpperCamelCase)

          lowerCamelCase__				   =      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]			,   UpperCamelCase			,   atol=1E-4))







   @slow
   def     __UpperCAmelCase      ( self):
          lowerCamelCase__				   =      YosoForMaskedLM.from_pretrained("uw-madison/yoso-4096")
          lowerCamelCase__				   =      torch.arange(40_96).unsqueeze(0)

          with torch.no_grad():
                 lowerCamelCase__				   =      model(UpperCamelCase)[0]

          lowerCamelCase__				   =      5_02_65

          lowerCamelCase__				   =      torch.Size((1, 40_96, vocab_size))
          self.assertEqual(output.shape			,   UpperCamelCase)

          lowerCamelCase__				   =      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]			,   UpperCamelCase			,   atol=1E-4))



'''simple docstring'''







def   lowerCAmelCase(  a__    :  float      , a__    :  float      , a__    :  int      ):







       '''simple docstring'''






       lowerCamelCase__				   =      [1 / first_term]
       lowerCamelCase__				   =      1 / first_term
       for _ in range(number_of_terms - 1      ):
              first_term += common_difference
              arithmetic_progression.append(a__      )
       lowerCamelCase__				   =      [1 / step for step in arithmetic_progression]
       return sum(a__      )


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    print(sum_of_harmonic_progression(1 / 2, 2, 2))

