




'''simple docstring'''


import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
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 (
     MODEL_FOR_PRETRAINING_MAPPING,
     AlbertForMaskedLM,
     AlbertForMultipleChoice,
     AlbertForPreTraining,
     AlbertForQuestionAnswering,
     AlbertForSequenceClassification,
     AlbertForTokenClassification,
     AlbertModel,
 )
 from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST







class      SCREAMING_SNAKE_CASE    :






      def __init__( self   :  List[str]						,						lowercase__   :  int						,						lowercase__   :  List[str]=13						,						lowercase__   :  Union[str, Any]=7						,						lowercase__   :  List[str]=True						,						lowercase__   :  Union[str, Any]=True						,						lowercase__   :  List[str]=True						,						lowercase__   :  Any=True						,						lowercase__   :  str=99						,						lowercase__   :  Optional[Any]=16						,						lowercase__   :  int=36						,						lowercase__   :  List[str]=6						,						lowercase__   :  str=6						,						lowercase__   :  int=6						,						lowercase__   :  List[str]=37						,						lowercase__   :  Dict="gelu"						,						lowercase__   :  Optional[int]=0.1						,						lowercase__   :  List[Any]=0.1						,						lowercase__   :  List[Any]=512						,						lowercase__   :  str=16						,						lowercase__   :  Optional[int]=2						,						lowercase__   :  Union[str, Any]=0.02						,						lowercase__   :  str=3						,						lowercase__   :  List[str]=4						,						lowercase__   :  Union[str, Any]=None						,						):


           '''simple docstring'''

           a_     :							Any     						=  parent
           a_     :							int     						=  batch_size
           a_     :							Optional[Any]     						=  seq_length
           a_     :							int     						=  is_training
           a_     :							List[Any]     						=  use_input_mask
           a_     :							List[Any]     						=  use_token_type_ids
           a_     :							str     						=  use_labels
           a_     :							List[Any]     						=  vocab_size
           a_     :							str     						=  embedding_size
           a_     :							str     						=  hidden_size
           a_     :							Union[str, Any]     						=  num_hidden_layers
           a_     :							Any     						=  num_hidden_groups
           a_     :							Tuple     						=  num_attention_heads
           a_     :							int     						=  intermediate_size
           a_     :							Dict     						=  hidden_act
           a_     :							Optional[int]     						=  hidden_dropout_prob
           a_     :							Union[str, Any]     						=  attention_probs_dropout_prob
           a_     :							int     						=  max_position_embeddings
           a_     :							List[str]     						=  type_vocab_size
           a_     :							int     						=  type_sequence_label_size
           a_     :							List[Any]     						=  initializer_range
           a_     :							int     						=  num_labels
           a_     :							str     						=  num_choices
           a_     :							Tuple     						=  scope






      def 							lowercase_						( self   :  Optional[int]       ):


           '''simple docstring'''

           a_     :							List[Any]     						=  ids_tensor([self.batch_size, self.seq_length]						,						self.vocab_size       )

           a_     :							Optional[int]     						=  None
           if self.use_input_mask:
                a_     :							Union[str, Any]     						=  random_attention_mask([self.batch_size, self.seq_length]       )

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

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

           a_     :							Any     						=  self.get_config()

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






      def 							lowercase_						( self   :  Optional[int]       ):


           '''simple docstring'''

           return AlbertConfig(
               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						,						initializer_range=self.initializer_range						,						num_hidden_groups=self.num_hidden_groups						,						)






      def 							lowercase_						( self   :  int						,						lowercase__   :  Optional[Any]						,						lowercase__   :  List[str]						,						lowercase__   :  Union[str, Any]						,						lowercase__   :  Any						,						lowercase__   :  List[str]						,						lowercase__   :  str						,						lowercase__   :  Dict       ):


           '''simple docstring'''

           a_     :							Union[str, Any]     						=  AlbertModel(config=lowercase__       )
           model.to(lowercase__       )
           model.eval()
           a_     :							Optional[int]     						=  model(lowercase__						,						attention_mask=lowercase__						,						token_type_ids=lowercase__       )
           a_     :							List[str]     						=  model(lowercase__						,						token_type_ids=lowercase__       )
           a_     :							Any     						=  model(lowercase__       )
           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 							lowercase_						( self   :  Tuple						,						lowercase__   :  Union[str, Any]						,						lowercase__   :  Tuple						,						lowercase__   :  List[str]						,						lowercase__   :  Optional[Any]						,						lowercase__   :  Any						,						lowercase__   :  Dict						,						lowercase__   :  Dict       ):


           '''simple docstring'''

           a_     :							int     						=  AlbertForPreTraining(config=lowercase__       )
           model.to(lowercase__       )
           model.eval()
           a_     :							Tuple     						=  model(
               lowercase__						,						attention_mask=lowercase__						,						token_type_ids=lowercase__						,						labels=lowercase__						,						sentence_order_label=lowercase__						,						)
           self.parent.assertEqual(result.prediction_logits.shape						,						(self.batch_size, self.seq_length, self.vocab_size)       )
           self.parent.assertEqual(result.sop_logits.shape						,						(self.batch_size, config.num_labels)       )






      def 							lowercase_						( self   :  Union[str, Any]						,						lowercase__   :  List[Any]						,						lowercase__   :  Union[str, Any]						,						lowercase__   :  Any						,						lowercase__   :  Dict						,						lowercase__   :  int						,						lowercase__   :  str						,						lowercase__   :  int       ):


           '''simple docstring'''

           a_     :							Union[str, Any]     						=  AlbertForMaskedLM(config=lowercase__       )
           model.to(lowercase__       )
           model.eval()
           a_     :							Tuple     						=  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 							lowercase_						( self   :  Union[str, Any]						,						lowercase__   :  List[str]						,						lowercase__   :  str						,						lowercase__   :  str						,						lowercase__   :  Optional[int]						,						lowercase__   :  Optional[Any]						,						lowercase__   :  Optional[Any]						,						lowercase__   :  List[str]       ):


           '''simple docstring'''

           a_     :							str     						=  AlbertForQuestionAnswering(config=lowercase__       )
           model.to(lowercase__       )
           model.eval()
           a_     :							str     						=  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 							lowercase_						( self   :  Any						,						lowercase__   :  Dict						,						lowercase__   :  Optional[Any]						,						lowercase__   :  int						,						lowercase__   :  str						,						lowercase__   :  Union[str, Any]						,						lowercase__   :  Dict						,						lowercase__   :  List[Any]       ):


           '''simple docstring'''

           a_     :							int     						=  self.num_labels
           a_     :							Union[str, Any]     						=  AlbertForSequenceClassification(lowercase__       )
           model.to(lowercase__       )
           model.eval()
           a_     :							Union[str, Any]     						=  model(lowercase__						,						attention_mask=lowercase__						,						token_type_ids=lowercase__						,						labels=lowercase__       )
           self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.num_labels)       )






      def 							lowercase_						( self   :  Tuple						,						lowercase__   :  int						,						lowercase__   :  Union[str, Any]						,						lowercase__   :  Dict						,						lowercase__   :  Union[str, Any]						,						lowercase__   :  List[Any]						,						lowercase__   :  Dict						,						lowercase__   :  str       ):


           '''simple docstring'''

           a_     :							Union[str, Any]     						=  self.num_labels
           a_     :							Dict     						=  AlbertForTokenClassification(config=lowercase__       )
           model.to(lowercase__       )
           model.eval()
           a_     :							Optional[int]     						=  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 							lowercase_						( self   :  List[str]						,						lowercase__   :  Optional[Any]						,						lowercase__   :  str						,						lowercase__   :  Dict						,						lowercase__   :  List[str]						,						lowercase__   :  Optional[int]						,						lowercase__   :  Tuple						,						lowercase__   :  List[Any]       ):


           '''simple docstring'''

           a_     :							Union[str, Any]     						=  self.num_choices
           a_     :							List[Any]     						=  AlbertForMultipleChoice(config=lowercase__       )
           model.to(lowercase__       )
           model.eval()
           a_     :							Union[str, Any]     						=  input_ids.unsqueeze(1       ).expand(-1						,						self.num_choices						,						-1       ).contiguous()
           a_     :							Optional[Any]     						=  token_type_ids.unsqueeze(1       ).expand(-1						,						self.num_choices						,						-1       ).contiguous()
           a_     :							Optional[int]     						=  input_mask.unsqueeze(1       ).expand(-1						,						self.num_choices						,						-1       ).contiguous()
           a_     :							Dict     						=  model(
               lowercase__						,						attention_mask=lowercase__						,						token_type_ids=lowercase__						,						labels=lowercase__						,						)
           self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.num_choices)       )






      def 							lowercase_						( self   :  int       ):


           '''simple docstring'''

           a_     :							str     						=  self.prepare_config_and_inputs()
           (
               (
               a_
           )						,     (
               a_
           )						,     (
               a_
           )						,     (
               a_
           )						,     (
               a_
           )						,     (
               a_
           )						,     (
               a_
           )						,     
           )     :							Union[str, Any]     						=  config_and_inputs
           a_     :							Tuple     						=  {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
           return config, inputs_dict







@require_torch
class      SCREAMING_SNAKE_CASE    (						snake_case_							,      snake_case_							,      unittest.TestCase				):
      __magic_name__  :       List[Any]   							=					(
          (
              AlbertModel,
              AlbertForPreTraining,
              AlbertForMaskedLM,
              AlbertForMultipleChoice,
              AlbertForSequenceClassification,
              AlbertForTokenClassification,
              AlbertForQuestionAnswering,
          )
          if is_torch_available()
          else ()
      )
      __magic_name__  :       List[str]   							=					(
          {
              '''feature-extraction''': AlbertModel,
              '''fill-mask''': AlbertForMaskedLM,
              '''question-answering''': AlbertForQuestionAnswering,
              '''text-classification''': AlbertForSequenceClassification,
              '''token-classification''': AlbertForTokenClassification,
              '''zero-shot''': AlbertForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      __magic_name__  :       int   							=					True






      def 							lowercase_						( self   :  Optional[Any]						,						lowercase__   :  int						,						lowercase__   :  Union[str, Any]						,						lowercase__   :  Tuple=False       ):


           '''simple docstring'''

           a_     :							str     						=  super()._prepare_for_class(lowercase__						,						lowercase__						,						return_labels=lowercase__       )

           if return_labels:
                if model_class in get_values(lowercase__       ):
                     a_     :							Union[str, Any]     						=  torch.zeros(
                         (self.model_tester.batch_size, self.model_tester.seq_length)						,						dtype=torch.long						,						device=lowercase__       )
                     a_     :							List[Any]     						=  torch.zeros(
                         self.model_tester.batch_size						,						dtype=torch.long						,						device=lowercase__       )
           return inputs_dict






      def 							lowercase_						( self   :  Any       ):


           '''simple docstring'''

           a_     :							Dict     						=  AlbertModelTester(self       )
           a_     :							str     						=  ConfigTester(self						,						config_class=lowercase__						,						hidden_size=37       )






      def 							lowercase_						( self   :  Union[str, Any]       ):


           '''simple docstring'''

           self.config_tester.run_common_tests()






      def 							lowercase_						( self   :  int       ):


           '''simple docstring'''

           a_     :							Union[str, Any]     						=  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*lowercase__       )






      def 							lowercase_						( self   :  List[str]       ):


           '''simple docstring'''

           a_     :							List[Any]     						=  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_pretraining(*lowercase__       )






      def 							lowercase_						( self   :  Any       ):


           '''simple docstring'''

           a_     :							Tuple     						=  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*lowercase__       )






      def 							lowercase_						( self   :  str       ):


           '''simple docstring'''

           a_     :							str     						=  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*lowercase__       )






      def 							lowercase_						( self   :  Optional[int]       ):


           '''simple docstring'''

           a_     :							List[str]     						=  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*lowercase__       )






      def 							lowercase_						( self   :  Optional[Any]       ):


           '''simple docstring'''

           a_     :							Optional[Any]     						=  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*lowercase__       )






      def 							lowercase_						( self   :  str       ):


           '''simple docstring'''

           a_     :							Dict     						=  self.model_tester.prepare_config_and_inputs()
           for type in ["absolute", "relative_key", "relative_key_query"]:
                a_     :							str     						=  type
                self.model_tester.create_and_check_model(*lowercase__       )






      @slow
      def 							lowercase_						( self   :  List[str]       ):


           '''simple docstring'''

           for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                a_     :							List[Any]     						=  AlbertModel.from_pretrained(lowercase__       )
                self.assertIsNotNone(lowercase__       )







@require_torch
class      SCREAMING_SNAKE_CASE    (						unittest.TestCase				):






      @slow
      def 							lowercase_						( self   :  str       ):


           '''simple docstring'''

           a_     :							Any     						=  AlbertModel.from_pretrained("""albert-base-v2"""       )
           a_     :							Any     						=  torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]       )
           a_     :							int     						=  torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
           with torch.no_grad():
                a_     :							List[str]     						=  model(lowercase__						,						attention_mask=lowercase__       )[0]
           a_     :							Tuple     						=  torch.Size((1, 11, 768)       )
           self.assertEqual(output.shape						,						lowercase__       )
           a_     :							Tuple     						=  torch.tensor(
               [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]       )

           self.assertTrue(torch.allclose(output[:, 1:4, 1:4]						,						lowercase__						,						atol=1e-4       )       )






'''simple docstring'''


from math import sqrt

import numpy as np
from sympy import symbols

# Coefficient
# Speed of light (m/s)
lowerCAmelCase_      :  List[Any]				     =  2_9979_2458

# Symbols
lowerCAmelCase_     ,   lowerCAmelCase_     ,   lowerCAmelCase_     ,   lowerCAmelCase_      :  Tuple				     =  symbols('ct x y z')



def  _SCREAMING_SNAKE_CASE     (      UpperCamelCase__    :					float				):




     """simple docstring"""


     if velocity > c:
          raise ValueError("""Speed must not exceed light speed 299,792,458 [m/s]!"""				)
     elif velocity < 1:
          # Usually the speed should be much higher than 1 (c order of magnitude)
          raise ValueError("""Speed must be greater than or equal to 1!"""				)

     return velocity / c



def  _SCREAMING_SNAKE_CASE     (      UpperCamelCase__    :					float				):




     """simple docstring"""


     return 1 / sqrt(1 - beta(UpperCamelCase__				) ** 2				)



def  _SCREAMING_SNAKE_CASE     (      UpperCamelCase__    :					float				):




     """simple docstring"""


     return np.array(
         [
             [gamma(UpperCamelCase__				), -gamma(UpperCamelCase__				) * beta(UpperCamelCase__				), 0, 0],
             [-gamma(UpperCamelCase__				) * beta(UpperCamelCase__				), gamma(UpperCamelCase__				), 0, 0],
             [0, 0, 1, 0],
             [0, 0, 0, 1],
         ]				)



def  _SCREAMING_SNAKE_CASE     (      UpperCamelCase__    :					float ,    UpperCamelCase__    :					np.ndarray | None = None				):




     """simple docstring"""


     if event is None:
          a_     :							str     						=  np.array([ct, x, y, z]				)  # Symbolic four vector
     else:
          event[0] *= c  # x0 is ct (speed of light * time)

     return transformation_matrix(UpperCamelCase__				) @ event


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 # Example of symbolic vector:
 lowerCAmelCase_      :  Union[str, Any]				     =  transform(2997_9245)
 print('Example of four vector: ')
 print(f"ct' = {four_vector[0]}")
 print(f"x' = {four_vector[1]}")
 print(f"y' = {four_vector[2]}")
 print(f"z' = {four_vector[3]}")

 # Substitute symbols with numerical values
 lowerCAmelCase_      :  Tuple				     =  {ct: c, x: 1, y: 1, z: 1}
 lowerCAmelCase_      :  Optional[int]				     =  [four_vector[i].subs(sub_dict) for i in range(4)]

 print(f"\n{numerical_vector}")
