



"""simple docstring"""







import unittest

from transformers import SqueezeBertConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, 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 (
         SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
         SqueezeBertForMaskedLM,
         SqueezeBertForMultipleChoice,
         SqueezeBertForQuestionAnswering,
         SqueezeBertForSequenceClassification,
         SqueezeBertForTokenClassification,
         SqueezeBertModel,
     )







class       UpperCamelCase__   (	A__  ):




      """simple docstring"""




      def __init__(      self				:      Tuple    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]    ,			SCREAMING_SNAKE_CASE_				:      Any=1_3    ,			SCREAMING_SNAKE_CASE_				:      List[str]=7    ,			SCREAMING_SNAKE_CASE_				:      int=True    ,			SCREAMING_SNAKE_CASE_				:      Dict=True    ,			SCREAMING_SNAKE_CASE_				:      Dict=False    ,			SCREAMING_SNAKE_CASE_				:      List[Any]=True    ,			SCREAMING_SNAKE_CASE_				:      Any=9_9    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]=3_2    ,			SCREAMING_SNAKE_CASE_				:      Any=5    ,			SCREAMING_SNAKE_CASE_				:      List[Any]=4    ,			SCREAMING_SNAKE_CASE_				:      Dict=6_4    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]="gelu"    ,			SCREAMING_SNAKE_CASE_				:      Tuple=0.1    ,			SCREAMING_SNAKE_CASE_				:      Any=0.1    ,			SCREAMING_SNAKE_CASE_				:      List[Any]=5_1_2    ,			SCREAMING_SNAKE_CASE_				:      Dict=1_6    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=2    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]=0.02    ,			SCREAMING_SNAKE_CASE_				:      List[str]=3    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=4    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]=None    ,			SCREAMING_SNAKE_CASE_				:      Tuple=2    ,			SCREAMING_SNAKE_CASE_				:      List[str]=2    ,			SCREAMING_SNAKE_CASE_				:      str=2    ,			SCREAMING_SNAKE_CASE_				:      Dict=2    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=4    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]=1    ,			):
        lowerCAmelCase_   :				List[Any]								= parent
        lowerCAmelCase_   :				Optional[int]								= batch_size
        lowerCAmelCase_   :				Dict								= seq_length
        lowerCAmelCase_   :				Dict								= is_training
        lowerCAmelCase_   :				Optional[int]								= use_input_mask
        lowerCAmelCase_   :				int								= use_token_type_ids
        lowerCAmelCase_   :				Optional[int]								= use_labels
        lowerCAmelCase_   :				Tuple								= vocab_size
        lowerCAmelCase_   :				Any								= hidden_size
        lowerCAmelCase_   :				Union[str, Any]								= num_hidden_layers
        lowerCAmelCase_   :				Tuple								= num_attention_heads
        lowerCAmelCase_   :				List[Any]								= intermediate_size
        lowerCAmelCase_   :				List[str]								= hidden_act
        lowerCAmelCase_   :				List[str]								= hidden_dropout_prob
        lowerCAmelCase_   :				Optional[int]								= attention_probs_dropout_prob
        lowerCAmelCase_   :				str								= max_position_embeddings
        lowerCAmelCase_   :				str								= type_vocab_size
        lowerCAmelCase_   :				List[str]								= type_sequence_label_size
        lowerCAmelCase_   :				Optional[Any]								= initializer_range
        lowerCAmelCase_   :				Tuple								= num_labels
        lowerCAmelCase_   :				List[Any]								= num_choices
        lowerCAmelCase_   :				Dict								= scope
        lowerCAmelCase_   :				int								= q_groups
        lowerCAmelCase_   :				Tuple								= k_groups
        lowerCAmelCase_   :				List[Any]								= v_groups
        lowerCAmelCase_   :				Tuple								= post_attention_groups
        lowerCAmelCase_   :				int								= intermediate_groups
        lowerCAmelCase_   :				List[Any]								= output_groups



      def      SCREAMING_SNAKE_CASE__ (      self				:      Union[str, Any]       ):
        lowerCAmelCase_   :				Optional[Any]								= ids_tensor([self.batch_size, self.seq_length]    ,			self.vocab_size       )

        lowerCAmelCase_   :				List[Any]								= None
        if self.use_input_mask:
          lowerCAmelCase_   :				List[str]								= random_attention_mask([self.batch_size, self.seq_length]       )

        lowerCAmelCase_   :				Optional[Any]								= None
        lowerCAmelCase_   :				Any								= None
        lowerCAmelCase_   :				str								= None
        if self.use_labels:
          lowerCAmelCase_   :				str								= ids_tensor([self.batch_size]    ,			self.type_sequence_label_size       )
          lowerCAmelCase_   :				Union[str, Any]								= ids_tensor([self.batch_size, self.seq_length]    ,			self.num_labels       )
          lowerCAmelCase_   :				Union[str, Any]								= ids_tensor([self.batch_size]    ,			self.num_choices       )

        lowerCAmelCase_   :				Optional[int]								= self.get_config()

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



      def      SCREAMING_SNAKE_CASE__ (      self				:      str       ):
        return SqueezeBertConfig(
            embedding_size=self.hidden_size    ,			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    ,			attention_probs_dropout_prob=self.hidden_dropout_prob    ,			attention_dropout=self.attention_probs_dropout_prob    ,			max_position_embeddings=self.max_position_embeddings    ,			initializer_range=self.initializer_range    ,			q_groups=self.q_groups    ,			k_groups=self.k_groups    ,			v_groups=self.v_groups    ,			post_attention_groups=self.post_attention_groups    ,			intermediate_groups=self.intermediate_groups    ,			output_groups=self.output_groups    ,			)



      def      SCREAMING_SNAKE_CASE__ (      self				:      Tuple    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]    ,			SCREAMING_SNAKE_CASE_				:      int    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]    ,			SCREAMING_SNAKE_CASE_				:      Any       ):
        lowerCAmelCase_   :				List[Any]								= SqueezeBertModel(config=_A       )
        model.to(_A       )
        model.eval()
        lowerCAmelCase_   :				Any								= model(_A    ,			_A       )
        lowerCAmelCase_   :				List[str]								= model(_A       )
        self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, self.seq_length, self.hidden_size)       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Dict    ,			SCREAMING_SNAKE_CASE_				:      Any    ,			SCREAMING_SNAKE_CASE_				:      Tuple    ,			SCREAMING_SNAKE_CASE_				:      str    ,			SCREAMING_SNAKE_CASE_				:      Any    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]    ,			SCREAMING_SNAKE_CASE_				:      Any       ):
        lowerCAmelCase_   :				List[Any]								= SqueezeBertForMaskedLM(config=_A       )
        model.to(_A       )
        model.eval()
        lowerCAmelCase_   :				List[str]								= model(_A    ,			attention_mask=_A    ,			labels=_A       )
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.vocab_size)       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[int]    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]    ,			SCREAMING_SNAKE_CASE_				:      Any    ,			SCREAMING_SNAKE_CASE_				:      Tuple    ,			SCREAMING_SNAKE_CASE_				:      int    ,			SCREAMING_SNAKE_CASE_				:      List[Any]       ):
        lowerCAmelCase_   :				Union[str, Any]								= SqueezeBertForQuestionAnswering(config=_A       )
        model.to(_A       )
        model.eval()
        lowerCAmelCase_   :				Dict								= model(
            _A    ,			attention_mask=_A    ,			start_positions=_A    ,			end_positions=_A       )
        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      SCREAMING_SNAKE_CASE__ (      self				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      List[str]    ,			SCREAMING_SNAKE_CASE_				:      Tuple    ,			SCREAMING_SNAKE_CASE_				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      List[str]    ,			SCREAMING_SNAKE_CASE_				:      List[str]    ,			SCREAMING_SNAKE_CASE_				:      List[str]       ):
        lowerCAmelCase_   :				int								= self.num_labels
        lowerCAmelCase_   :				List[str]								= SqueezeBertForSequenceClassification(_A       )
        model.to(_A       )
        model.eval()
        lowerCAmelCase_   :				Dict								= model(_A    ,			attention_mask=_A    ,			labels=_A       )
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels)       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      str    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]    ,			SCREAMING_SNAKE_CASE_				:      str    ,			SCREAMING_SNAKE_CASE_				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      List[str]    ,			SCREAMING_SNAKE_CASE_				:      str    ,			SCREAMING_SNAKE_CASE_				:      Dict       ):
        lowerCAmelCase_   :				Optional[Any]								= self.num_labels
        lowerCAmelCase_   :				Optional[int]								= SqueezeBertForTokenClassification(config=_A       )
        model.to(_A       )
        model.eval()

        lowerCAmelCase_   :				Optional[int]								= model(_A    ,			attention_mask=_A    ,			labels=_A       )
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.num_labels)       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      Tuple    ,			SCREAMING_SNAKE_CASE_				:      str    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]    ,			SCREAMING_SNAKE_CASE_				:      int    ,			SCREAMING_SNAKE_CASE_				:      str    ,			SCREAMING_SNAKE_CASE_				:      List[Any]       ):
        lowerCAmelCase_   :				List[Any]								= self.num_choices
        lowerCAmelCase_   :				Union[str, Any]								= SqueezeBertForMultipleChoice(config=_A       )
        model.to(_A       )
        model.eval()
        lowerCAmelCase_   :				Dict								= input_ids.unsqueeze(1       ).expand(-1    ,			self.num_choices    ,			-1       ).contiguous()
        lowerCAmelCase_   :				str								= input_mask.unsqueeze(1       ).expand(-1    ,			self.num_choices    ,			-1       ).contiguous()
        lowerCAmelCase_   :				Optional[int]								= model(
            _A    ,			attention_mask=_A    ,			labels=_A    ,			)
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_choices)       )





      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[int]       ):
        lowerCAmelCase_   :				Optional[Any]								= self.prepare_config_and_inputs()
        (lowerCAmelCase_)   :				Dict								= config_and_inputs
        lowerCAmelCase_   :				Dict								= {"input_ids": input_ids, "attention_mask": input_mask}
        return config, inputs_dict







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




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     (
          (
              SqueezeBertModel,
              SqueezeBertForMaskedLM,
              SqueezeBertForMultipleChoice,
              SqueezeBertForQuestionAnswering,
              SqueezeBertForSequenceClassification,
              SqueezeBertForTokenClassification,
          )
          if is_torch_available()
          else None
      )
      _SCREAMING_SNAKE_CASE  				=     (
          {
              """feature-extraction""": SqueezeBertModel,
              """fill-mask""": SqueezeBertForMaskedLM,
              """question-answering""": SqueezeBertForQuestionAnswering,
              """text-classification""": SqueezeBertForSequenceClassification,
              """token-classification""": SqueezeBertForTokenClassification,
              """zero-shot""": SqueezeBertForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      _SCREAMING_SNAKE_CASE  				=     False
      _SCREAMING_SNAKE_CASE  				=     True
      _SCREAMING_SNAKE_CASE  				=     False



      def      SCREAMING_SNAKE_CASE__ (      self				:      int       ):
        lowerCAmelCase_   :				int								= SqueezeBertModelTester(self       )
        lowerCAmelCase_   :				List[str]								= ConfigTester(self    ,			config_class=_A    ,			dim=3_7       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      List[str]       ):
        self.config_tester.run_common_tests()



      def      SCREAMING_SNAKE_CASE__ (      self				:      Tuple       ):
        lowerCAmelCase_   :				Tuple								= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_squeezebert_model(*_A       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      List[Any]       ):
        lowerCAmelCase_   :				List[str]								= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_squeezebert_for_masked_lm(*_A       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      int       ):
        lowerCAmelCase_   :				Tuple								= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_squeezebert_for_question_answering(*_A       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Dict       ):
        lowerCAmelCase_   :				Union[str, Any]								= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_squeezebert_for_sequence_classification(*_A       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Tuple       ):
        lowerCAmelCase_   :				int								= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_squeezebert_for_token_classification(*_A       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Union[str, Any]       ):
        lowerCAmelCase_   :				Tuple								= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_squeezebert_for_multiple_choice(*_A       )





      @slow
      def      SCREAMING_SNAKE_CASE__ (      self				:      Any       ):






        for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          lowerCAmelCase_   :				Tuple								= SqueezeBertModel.from_pretrained(_A       )
          self.assertIsNotNone(_A       )







@require_sentencepiece
@require_tokenizers
@require_torch
class       UpperCamelCase__   (	unittest.TestCase  ):




      """simple docstring"""




      @slow
      def      SCREAMING_SNAKE_CASE__ (      self				:      int       ):
        lowerCAmelCase_   :				str								= SqueezeBertForSequenceClassification.from_pretrained('squeezebert/squeezebert-mnli'       )

        lowerCAmelCase_   :				Optional[int]								= torch.tensor([[1, 2_9_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 1_3, 1_5_8_8, 2]]       )
        lowerCAmelCase_   :				List[Any]								= model(_A       )[0]
        lowerCAmelCase_   :				Union[str, Any]								= torch.Size((1, 3)       )
        self.assertEqual(output.shape    ,			_A       )
        lowerCAmelCase_   :				int								= torch.tensor([[0.64_01, -0.03_49, -0.60_41]]       )
        self.assertTrue(torch.allclose(_A    ,			_A    ,			atol=1E-4       )       )






from __future__ import annotations

from math import pi, sqrt




def       _snake_case	(   lowerCAmelCase							:   float   , lowerCAmelCase							:   float	):
		"""simple docstring"""







		if inductance <= 0:
				raise ValueError("Inductance cannot be 0 or negative"	)

		elif capacitance <= 0:
				raise ValueError("Capacitance cannot be 0 or negative"	)

		else:
				return (
				    "Resonant frequency",
				    float(1 / (2 * pi * (sqrt(inductance * capacitance	)))	),
				)


if __name__ == "__main__":
		import doctest

		doctest.testmod()
