


"""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 				SCREAMING_SNAKE_CASE__    (		_UpperCAmelCase    ):
       """simple docstring"""


       def __init__(						self		,					snake_case__		,					snake_case__=13		,					snake_case__=7		,					snake_case__=True		,					snake_case__=True		,					snake_case__=False		,					snake_case__=True		,					snake_case__=99		,					snake_case__=32		,					snake_case__=5		,					snake_case__=4		,					snake_case__=64		,					snake_case__="gelu"		,					snake_case__=0.1		,					snake_case__=0.1		,					snake_case__=512		,					snake_case__=16		,					snake_case__=2		,					snake_case__=0.02		,					snake_case__=3		,					snake_case__=4		,					snake_case__=None		,					snake_case__=2		,					snake_case__=2		,					snake_case__=2		,					snake_case__=2		,					snake_case__=4		,					snake_case__=1		,					):






         """simple docstring"""





         lowerCAmelCase					:					Tuple								=							parent
         lowerCAmelCase					:					Optional[int]								=							batch_size
         lowerCAmelCase					:					Optional[Any]								=							seq_length
         lowerCAmelCase					:					int								=							is_training
         lowerCAmelCase					:					Union[str, Any]								=							use_input_mask
         lowerCAmelCase					:					Union[str, Any]								=							use_token_type_ids
         lowerCAmelCase					:					Dict								=							use_labels
         lowerCAmelCase					:					Union[str, Any]								=							vocab_size
         lowerCAmelCase					:					Union[str, Any]								=							hidden_size
         lowerCAmelCase					:					Tuple								=							num_hidden_layers
         lowerCAmelCase					:					Any								=							num_attention_heads
         lowerCAmelCase					:					int								=							intermediate_size
         lowerCAmelCase					:					str								=							hidden_act
         lowerCAmelCase					:					Optional[Any]								=							hidden_dropout_prob
         lowerCAmelCase					:					str								=							attention_probs_dropout_prob
         lowerCAmelCase					:					List[Any]								=							max_position_embeddings
         lowerCAmelCase					:					Optional[Any]								=							type_vocab_size
         lowerCAmelCase					:					int								=							type_sequence_label_size
         lowerCAmelCase					:					Dict								=							initializer_range
         lowerCAmelCase					:					Dict								=							num_labels
         lowerCAmelCase					:					Tuple								=							num_choices
         lowerCAmelCase					:					Optional[int]								=							scope
         lowerCAmelCase					:					List[Any]								=							q_groups
         lowerCAmelCase					:					Tuple								=							k_groups
         lowerCAmelCase					:					Any								=							v_groups
         lowerCAmelCase					:					List[str]								=							post_attention_groups
         lowerCAmelCase					:					Tuple								=							intermediate_groups
         lowerCAmelCase					:					int								=							output_groups

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[Any]								=							ids_tensor([self.batch_size, self.seq_length]		,					self.vocab_size						)

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

         lowerCAmelCase					:					Optional[int]								=							None
         lowerCAmelCase					:					List[Any]								=							None
         lowerCAmelCase					:					Dict								=							None
         if self.use_labels:
           lowerCAmelCase					:					Tuple								=							ids_tensor([self.batch_size]		,					self.type_sequence_label_size						)
           lowerCAmelCase					:					List[Any]								=							ids_tensor([self.batch_size, self.seq_length]		,					self.num_labels						)
           lowerCAmelCase					:					Tuple								=							ids_tensor([self.batch_size]		,					self.num_choices						)

         lowerCAmelCase					:					Dict								=							self.get_config()

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

       def 	lowercase__							(						self						):






         """simple docstring"""





         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 	lowercase__							(						self		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__						):






         """simple docstring"""





         lowerCAmelCase					:					List[str]								=							SqueezeBertModel(config=SCREAMING_SNAKE_CASE_						)
         model.to(SCREAMING_SNAKE_CASE_						)
         model.eval()
         lowerCAmelCase					:					Any								=							model(SCREAMING_SNAKE_CASE_		,					SCREAMING_SNAKE_CASE_						)
         lowerCAmelCase					:					Any								=							model(SCREAMING_SNAKE_CASE_						)
         self.parent.assertEqual(result.last_hidden_state.shape		,					(self.batch_size, self.seq_length, self.hidden_size)						)

       def 	lowercase__							(						self		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__						):






         """simple docstring"""





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

       def 	lowercase__							(						self		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__						):






         """simple docstring"""





         lowerCAmelCase					:					List[Any]								=							SqueezeBertForQuestionAnswering(config=SCREAMING_SNAKE_CASE_						)
         model.to(SCREAMING_SNAKE_CASE_						)
         model.eval()
         lowerCAmelCase					:					str								=							model(
             SCREAMING_SNAKE_CASE_		,					attention_mask=SCREAMING_SNAKE_CASE_		,					start_positions=SCREAMING_SNAKE_CASE_		,					end_positions=SCREAMING_SNAKE_CASE_						)
         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 	lowercase__							(						self		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__						):






         """simple docstring"""





         lowerCAmelCase					:					str								=							self.num_labels
         lowerCAmelCase					:					Optional[Any]								=							SqueezeBertForSequenceClassification(SCREAMING_SNAKE_CASE_						)
         model.to(SCREAMING_SNAKE_CASE_						)
         model.eval()
         lowerCAmelCase					:					Union[str, Any]								=							model(SCREAMING_SNAKE_CASE_		,					attention_mask=SCREAMING_SNAKE_CASE_		,					labels=SCREAMING_SNAKE_CASE_						)
         self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.num_labels)						)

       def 	lowercase__							(						self		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__						):






         """simple docstring"""





         lowerCAmelCase					:					Any								=							self.num_labels
         lowerCAmelCase					:					str								=							SqueezeBertForTokenClassification(config=SCREAMING_SNAKE_CASE_						)
         model.to(SCREAMING_SNAKE_CASE_						)
         model.eval()

         lowerCAmelCase					:					Dict								=							model(SCREAMING_SNAKE_CASE_		,					attention_mask=SCREAMING_SNAKE_CASE_		,					labels=SCREAMING_SNAKE_CASE_						)
         self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.seq_length, self.num_labels)						)

       def 	lowercase__							(						self		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__		,					snake_case__						):






         """simple docstring"""





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







       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[int]								=							self.prepare_config_and_inputs()
         (lowerCAmelCase)					:					Optional[int]								=							config_and_inputs
         lowerCAmelCase					:					Optional[int]								=							{"""input_ids""": input_ids, """attention_mask""": input_mask}
         return config, inputs_dict


@require_torch
class 				SCREAMING_SNAKE_CASE__    (		_UpperCAmelCase       ,   _UpperCAmelCase       ,   unittest.TestCase    ):
       """simple docstring"""


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

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Any								=							SqueezeBertModelTester(self						)
         lowerCAmelCase					:					List[Any]								=							ConfigTester(self		,					config_class=SCREAMING_SNAKE_CASE_		,					dim=37						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         self.config_tester.run_common_tests()

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Tuple								=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_model(*SCREAMING_SNAKE_CASE_						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Any								=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_masked_lm(*SCREAMING_SNAKE_CASE_						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Tuple								=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_question_answering(*SCREAMING_SNAKE_CASE_						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					List[Any]								=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_sequence_classification(*SCREAMING_SNAKE_CASE_						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					str								=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_token_classification(*SCREAMING_SNAKE_CASE_						)

       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					List[str]								=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_multiple_choice(*SCREAMING_SNAKE_CASE_						)







       @slow
       def 	lowercase__							(						self						):






         """simple docstring"""





         for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           lowerCAmelCase					:					Optional[Any]								=							SqueezeBertModel.from_pretrained(SCREAMING_SNAKE_CASE_						)
           self.assertIsNotNone(SCREAMING_SNAKE_CASE_						)


@require_sentencepiece
@require_tokenizers
@require_torch
class 				SCREAMING_SNAKE_CASE__    (		unittest.TestCase    ):
       """simple docstring"""


       @slow
       def 	lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase					:					Optional[Any]								=							SqueezeBertForSequenceClassification.from_pretrained("squeezebert/squeezebert-mnli"						)

         lowerCAmelCase					:					Dict								=							torch.tensor([[1, 29_414, 232, 328, 740, 1_140, 12_695, 69, 13, 1_588, 2]]						)
         lowerCAmelCase					:					List[str]								=							model(SCREAMING_SNAKE_CASE_						)[0]
         lowerCAmelCase					:					Optional[Any]								=							torch.Size((1, 3)						)
         self.assertEqual(output.shape		,					SCREAMING_SNAKE_CASE_						)
         lowerCAmelCase					:					Optional[int]								=							torch.tensor([[0.6401, -0.0349, -0.6041]]						)
         self.assertTrue(torch.allclose(SCREAMING_SNAKE_CASE_		,					SCREAMING_SNAKE_CASE_		,					atol=1e-4						)						)









"""simple docstring"""







from __future__ import annotations

from math import pi

# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of
# Pi and the function
lowerCAmelCase__				    =       1.0_5_4_5_7_1_8_1_7e-3_4  # unit of ℏ : J * s

lowerCAmelCase__				    =       3e8  # unit of c : m * s^-1
def  a__      (    SCREAMING_SNAKE_CASE   :   float    ,				SCREAMING_SNAKE_CASE   :   float    ,				SCREAMING_SNAKE_CASE   :   float    ):


  '''simple docstring'''







  if (force, area, distance).count(0    ) != 1:
    raise ValueError("One and only one argument must be 0"    )
  if force < 0:
    raise ValueError("Magnitude of force can not be negative"    )
  if distance < 0:
    raise ValueError("Distance can not be negative"    )
  if area < 0:
    raise ValueError("Area can not be negative"    )
  if force == 0:
    lowerCAmelCase					:					Any								=							(REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2 * area) / (
        2_4_0 * (distance) ** 4
    )
    return {"force": force}
  elif area == 0:
    lowerCAmelCase					:					Any								=							(2_4_0 * force * (distance) ** 4) / (
        REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2
    )
    return {"area": area}
  elif distance == 0:
    lowerCAmelCase					:					Dict								=							(
        (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2 * area) / (2_4_0 * force)
    ) ** (1 / 4)
    return {"distance": distance}
  raise ValueError("One and only one argument must be 0"    )


# Run doctest
if __name__ == "__main__":
     import doctest

     doctest.testmod()





