


'''simple docstring'''

import unittest

from transformers import MPNetConfig, 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, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import (
       MPNetForMaskedLM,
       MPNetForMultipleChoice,
       MPNetForQuestionAnswering,
       MPNetForSequenceClassification,
       MPNetForTokenClassification,
       MPNetModel,
   )





class 						__SCREAMING_SNAKE_CASE					:






     def __init__(			self     ,							__UpperCamelCase     ,							__UpperCamelCase=13     ,							__UpperCamelCase=7     ,							__UpperCamelCase=True     ,							__UpperCamelCase=True     ,							__UpperCamelCase=False     ,							__UpperCamelCase=True     ,							__UpperCamelCase=99     ,							__UpperCamelCase=64     ,							__UpperCamelCase=5     ,							__UpperCamelCase=4     ,							__UpperCamelCase=64     ,							__UpperCamelCase="gelu"     ,							__UpperCamelCase=0.1     ,							__UpperCamelCase=0.1     ,							__UpperCamelCase=512     ,							__UpperCamelCase=16     ,							__UpperCamelCase=2     ,							__UpperCamelCase=0.02     ,							__UpperCamelCase=3     ,							__UpperCamelCase=4     ,							__UpperCamelCase=None     ,							)       ->    Tuple:
          _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  a_					(			self		)       ->    List[str]:
          return MPNetConfig.from_pretrained("microsoft/mpnet-base"		)






     def  a_					(			self		)       ->    Tuple:
          _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
          _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, input_mask, sequence_labels, token_labels, choice_labels






     def  a_					(			self		)       ->    Any:
          return MPNetConfig(
              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     ,							initializer_range=self.initializer_range     ,							)






     def  a_					(			self     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase		)       ->    str:
          _a						=		MPNetModel(config=__UpperCamelCase		)
          model.to(__UpperCamelCase		)
          model.eval()
          _a						=		model(__UpperCamelCase     ,							__UpperCamelCase		)
          _a						=		model(__UpperCamelCase		)
          self.parent.assertEqual(result.last_hidden_state.shape     ,							(self.batch_size, self.seq_length, self.hidden_size)		)
          self.parent.assertEqual(result.pooler_output.shape     ,							(self.batch_size, self.hidden_size)		)






     def  a_					(			self     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase		)       ->    Tuple:
          _a						=		MPNetForQuestionAnswering(config=__UpperCamelCase		)
          model.to(__UpperCamelCase		)
          model.eval()
          _a						=		model(
              __UpperCamelCase     ,							attention_mask=__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  a_					(			self     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase		)       ->    Optional[Any]:
          _a						=		self.num_labels
          _a						=		MPNetForSequenceClassification(__UpperCamelCase		)
          model.to(__UpperCamelCase		)
          model.eval()
          _a						=		model(__UpperCamelCase     ,							attention_mask=__UpperCamelCase     ,							labels=__UpperCamelCase		)
          self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.num_labels)		)






     def  a_					(			self     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase		)       ->    List[str]:
          _a						=		self.num_choices
          _a						=		MPNetForMultipleChoice(config=__UpperCamelCase		)
          model.to(__UpperCamelCase		)
          model.eval()
          _a						=		input_ids.unsqueeze(1		).expand(-1     ,							self.num_choices     ,							-1		).contiguous()
          _a						=		input_mask.unsqueeze(1		).expand(-1     ,							self.num_choices     ,							-1		).contiguous()
          _a						=		model(
              __UpperCamelCase     ,							attention_mask=__UpperCamelCase     ,							labels=__UpperCamelCase     ,							)
          self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.num_choices)		)






     def  a_					(			self     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase     ,							__UpperCamelCase		)       ->    List[str]:
          _a						=		self.num_labels
          _a						=		MPNetForTokenClassification(config=__UpperCamelCase		)
          model.to(__UpperCamelCase		)
          model.eval()
          _a						=		model(__UpperCamelCase     ,							attention_mask=__UpperCamelCase     ,							labels=__UpperCamelCase		)
          self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.seq_length, self.num_labels)		)






     def  a_					(			self		)       ->    List[str]:
          _a						=		self.prepare_config_and_inputs()
          ((_a)			,			(_a)			,			(_a)			,			(_a)			,			(_a)			,			(_a))						=		config_and_inputs
          _a						=		{"input_ids": input_ids, "attention_mask": input_mask}
          return config, inputs_dict







@require_torch
class 						__SCREAMING_SNAKE_CASE					(      lowerCamelCase__ ,			lowerCamelCase__ ,			unittest.TestCase ):
     UpperCAmelCase 					=				(
         (
             MPNetForMaskedLM,
             MPNetForMultipleChoice,
             MPNetForQuestionAnswering,
             MPNetForSequenceClassification,
             MPNetForTokenClassification,
             MPNetModel,
         )
         if is_torch_available()
         else ()
     )
     UpperCAmelCase 					=				(
         {
             '''feature-extraction''': MPNetModel,
             '''fill-mask''': MPNetForMaskedLM,
             '''question-answering''': MPNetForQuestionAnswering,
             '''text-classification''': MPNetForSequenceClassification,
             '''token-classification''': MPNetForTokenClassification,
             '''zero-shot''': MPNetForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     UpperCAmelCase 					=				False
     UpperCAmelCase 					=				True






     def  a_					(			self		)       ->    int:
          _a						=		MPNetModelTester(self		)
          _a						=		ConfigTester(self     ,							config_class=__UpperCamelCase     ,							hidden_size=37		)






     def  a_					(			self		)       ->    Optional[Any]:
          self.config_tester.run_common_tests()






     def  a_					(			self		)       ->    List[Any]:
          _a						=		self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_model(*__UpperCamelCase		)






     def  a_					(			self		)       ->    Any:
          _a						=		self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_sequence_classification(*__UpperCamelCase		)






     def  a_					(			self		)       ->    Union[str, Any]:
          _a						=		self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_multiple_choice(*__UpperCamelCase		)






     def  a_					(			self		)       ->    int:
          _a						=		self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_token_classification(*__UpperCamelCase		)






     def  a_					(			self		)       ->    Tuple:
          _a						=		self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_question_answering(*__UpperCamelCase		)







@require_torch
class 						__SCREAMING_SNAKE_CASE					(      unittest.TestCase ):






     @slow
     def  a_					(			self		)       ->    Tuple:
          _a						=		MPNetModel.from_pretrained("microsoft/mpnet-base"		)
          _a						=		torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]		)
          _a						=		model(__UpperCamelCase		)[0]
          _a						=		torch.Size((1, 11, 768)		)
          self.assertEqual(output.shape     ,							__UpperCamelCase		)
          _a						=		torch.tensor(
              [[[-0.05_50, 0.19_43, -0.07_40], [-0.05_62, 0.22_11, -0.05_79], [-0.04_37, 0.33_37, -0.06_41]]]		)
          # compare the actual values for a slice.
          self.assertTrue(torch.allclose(output[:, :3, :3]     ,							__UpperCamelCase     ,							atol=1e-4		)		)





'''simple docstring'''

from manim import *





class 						__SCREAMING_SNAKE_CASE					(      lowerCamelCase__ ):






     def  a_					(			self		)       ->    str:
          _a						=		Rectangle(height=0.5     ,							width=0.5		)
          _a						=		Rectangle(height=0.46     ,							width=0.46		).set_stroke(width=0		)

          _a						=		[mem.copy() for i in range(6		)]
          _a						=		[mem.copy() for i in range(6		)]
          _a						=		VGroup(*__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)
          _a						=		VGroup(*__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)
          _a						=		VGroup(__UpperCamelCase     ,							__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)
          _a						=		Text("CPU"     ,							font_size=24		)
          _a						=		Group(__UpperCamelCase     ,							__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0.5     ,							aligned_edge=__UpperCamelCase		)
          cpu.move_to([-2.5, -0.5, 0]		)
          self.add(__UpperCamelCase		)

          _a						=		[mem.copy() for i in range(1		)]
          _a						=		VGroup(*__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)
          _a						=		Text("GPU"     ,							font_size=24		)
          _a						=		Group(__UpperCamelCase     ,							__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0.5     ,							aligned_edge=__UpperCamelCase		)
          gpu.align_to(__UpperCamelCase     ,							__UpperCamelCase		)
          gpu.set_x(gpu.get_x() - 1		)

          self.add(__UpperCamelCase		)

          _a						=		[mem.copy() for i in range(6		)]
          _a						=		VGroup(*__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0		)

          _a						=		Text("Model"     ,							font_size=24		)
          _a						=		Group(__UpperCamelCase     ,							__UpperCamelCase		).arrange(__UpperCamelCase     ,							buff=0.5     ,							aligned_edge=__UpperCamelCase		)
          model.move_to([3, -1.0, 0]		)

          self.play(
              Create(__UpperCamelCase     ,							run_time=1		)     ,							Create(__UpperCamelCase     ,							run_time=1		)     ,							Create(__UpperCamelCase     ,							run_time=1		)     ,							)

          _a						=		MarkupText(
              f"First, an empty model skeleton is loaded\ninto <span fgcolor='{YELLOW}'>memory</span> without using much RAM."     ,							font_size=24     ,							)

          _a						=		Square(side_length=2.2		)
          key.move_to([-5, 2, 0]		)

          _a						=		MarkupText(
              f"<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"     ,							font_size=18     ,							)

          key_text.move_to([-5, 2.4, 0]		)

          step_a.move_to([2, 2, 0]		)
          self.play(Write(__UpperCamelCase     ,							run_time=2.5		)     ,							Write(__UpperCamelCase		)     ,							Write(__UpperCamelCase		)		)

          self.add(__UpperCamelCase		)

          _a						=		[]
          _a						=		[]
          _a						=		[]
          for i, rect in enumerate(__UpperCamelCase		):
               _a						=		Rectangle(height=0.46     ,							width=0.46		).set_stroke(width=0.0		).set_fill(__UpperCamelCase     ,							opacity=0.7		)
               cpu_target.move_to(__UpperCamelCase		)
               cpu_target.generate_target()
               _a						=		0.46 / 4
               _a						=		0.46 / 3

               if i == 0:
                    cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT		)     ,							buff=0.02     ,							direction=__UpperCamelCase		)
                    cpu_target.target.set_x(cpu_target.target.get_x() + 0.1		)
               elif i == 3:
                    cpu_target.target.next_to(cpu_targs[0].target     ,							direction=__UpperCamelCase     ,							buff=0.0		)
               else:
                    cpu_target.target.next_to(cpu_targs[i - 1].target     ,							direction=__UpperCamelCase     ,							buff=0.0		)
               cpu_targs.append(__UpperCamelCase		)

               first_animations.append(rect.animate(run_time=0.5		).set_stroke(__UpperCamelCase		)		)
               second_animations.append(MoveToTarget(__UpperCamelCase     ,							run_time=1.5		)		)

          self.play(*__UpperCamelCase		)
          self.play(*__UpperCamelCase		)

          self.wait()

