



'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
 import numpy
 import tensorflow as tf

 from transformers import (
     TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
     TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
     TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
     BertConfig,
     DPRConfig,
     TFDPRContextEncoder,
     TFDPRQuestionEncoder,
     TFDPRReader,
 )


class 				snake_case :



       def __init__(				self     ,UpperCAmelCase_     ,UpperCAmelCase_=13     ,UpperCAmelCase_=7     ,UpperCAmelCase_=True     ,UpperCAmelCase_=True     ,UpperCAmelCase_=True     ,UpperCAmelCase_=True     ,UpperCAmelCase_=99     ,UpperCAmelCase_=32     ,UpperCAmelCase_=2     ,UpperCAmelCase_=4     ,UpperCAmelCase_=37     ,UpperCAmelCase_="gelu"     ,UpperCAmelCase_=0.1     ,UpperCAmelCase_=0.1     ,UpperCAmelCase_=512     ,UpperCAmelCase_=16     ,UpperCAmelCase_=2     ,UpperCAmelCase_=0.02     ,UpperCAmelCase_=3     ,UpperCAmelCase_=4     ,UpperCAmelCase_=None     ,UpperCAmelCase_=0     ,)  ->							int:
           lowercase__		       =						parent
           lowercase__		       =						batch_size
           lowercase__		       =						seq_length
           lowercase__		       =						is_training
           lowercase__		       =						use_input_mask
           lowercase__		       =						use_token_type_ids
           lowercase__		       =						use_labels
           lowercase__		       =						vocab_size
           lowercase__		       =						hidden_size
           lowercase__		       =						num_hidden_layers
           lowercase__		       =						num_attention_heads
           lowercase__		       =						intermediate_size
           lowercase__		       =						hidden_act
           lowercase__		       =						hidden_dropout_prob
           lowercase__		       =						attention_probs_dropout_prob
           lowercase__		       =						max_position_embeddings
           lowercase__		       =						type_vocab_size
           lowercase__		       =						type_sequence_label_size
           lowercase__		       =						initializer_range
           lowercase__		       =						num_labels
           lowercase__		       =						num_choices
           lowercase__		       =						scope
           lowercase__		       =						projection_dim



       def 							_a      (				self      )  ->							str:
           lowercase__		       =						ids_tensor([self.batch_size, self.seq_length]     ,self.vocab_size      )

           lowercase__		       =						None
           if self.use_input_mask:
               # follow test_modeling_tf_ctrl.py
               lowercase__		       =						random_attention_mask([self.batch_size, self.seq_length]      )

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

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

           lowercase__		       =						BertConfig(
               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     ,)
           lowercase__		       =						DPRConfig(projection_dim=self.projection_dim     ,**config.to_dict()      )

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



       def 							_a      (				self     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_      )  ->							Tuple:
           lowercase__		       =						TFDPRContextEncoder(config=UpperCAmelCase_      )
           lowercase__		       =						model(UpperCAmelCase_     ,attention_mask=UpperCAmelCase_     ,token_type_ids=UpperCAmelCase_      )
           lowercase__		       =						model(UpperCAmelCase_     ,token_type_ids=UpperCAmelCase_      )
           lowercase__		       =						model(UpperCAmelCase_      )
           self.parent.assertEqual(result.pooler_output.shape     ,(self.batch_size, self.projection_dim or self.hidden_size)      )



       def 							_a      (				self     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_      )  ->							Dict:
           lowercase__		       =						TFDPRQuestionEncoder(config=UpperCAmelCase_      )
           lowercase__		       =						model(UpperCAmelCase_     ,attention_mask=UpperCAmelCase_     ,token_type_ids=UpperCAmelCase_      )
           lowercase__		       =						model(UpperCAmelCase_     ,token_type_ids=UpperCAmelCase_      )
           lowercase__		       =						model(UpperCAmelCase_      )
           self.parent.assertEqual(result.pooler_output.shape     ,(self.batch_size, self.projection_dim or self.hidden_size)      )



       def 							_a      (				self     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_     ,UpperCAmelCase_      )  ->							Optional[Any]:
           lowercase__		       =						TFDPRReader(config=UpperCAmelCase_      )
           lowercase__		       =						model(UpperCAmelCase_     ,attention_mask=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)      )
           self.parent.assertEqual(result.relevance_logits.shape     ,(self.batch_size,)      )







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





@require_tf
class 				snake_case (UpperCamelCase		,      UpperCamelCase		,      unittest.TestCase   ):
       lowerCAmelCase__  :str						   =					(
           (
               TFDPRContextEncoder,
               TFDPRQuestionEncoder,
               TFDPRReader,
           )
           if is_tf_available()
           else ()
       )
       lowerCAmelCase__  :Union[str, Any]						   =					{"feature-extraction": TFDPRQuestionEncoder} if is_tf_available() else {}

       lowerCAmelCase__  :Optional[int]						   =					False
       lowerCAmelCase__  :Tuple						   =					False
       lowerCAmelCase__  :Optional[Any]						   =					False
       lowerCAmelCase__  :Optional[int]						   =					False
       lowerCAmelCase__  :Any						   =					False



       def 							_a      (				self      )  ->							Optional[int]:
           lowercase__		       =						TFDPRModelTester(self      )
           lowercase__		       =						ConfigTester(self     ,config_class=UpperCAmelCase_     ,hidden_size=37      )



       def 							_a      (				self      )  ->							Dict:
           self.config_tester.run_common_tests()



       def 							_a      (				self      )  ->							Any:
           lowercase__		       =						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_dpr_context_encoder(*UpperCAmelCase_      )



       def 							_a      (				self      )  ->							Any:
           lowercase__		       =						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_dpr_question_encoder(*UpperCAmelCase_      )



       def 							_a      (				self      )  ->							List[str]:
           lowercase__		       =						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_dpr_reader(*UpperCAmelCase_      )







       @slow
       def 							_a      (				self      )  ->							Optional[Any]:
           for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               lowercase__		       =						TFDPRContextEncoder.from_pretrained(UpperCAmelCase_      )
               self.assertIsNotNone(UpperCAmelCase_      )

           for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               lowercase__		       =						TFDPRContextEncoder.from_pretrained(UpperCAmelCase_      )
               self.assertIsNotNone(UpperCAmelCase_      )

           for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               lowercase__		       =						TFDPRQuestionEncoder.from_pretrained(UpperCAmelCase_      )
               self.assertIsNotNone(UpperCAmelCase_      )

           for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               lowercase__		       =						TFDPRReader.from_pretrained(UpperCAmelCase_      )
               self.assertIsNotNone(UpperCAmelCase_      )





@require_tf
class 				snake_case (unittest.TestCase   ):



       @slow
       def 							_a      (				self      )  ->							List[Any]:
           lowercase__		       =						TFDPRQuestionEncoder.from_pretrained("facebook/dpr-question_encoder-single-nq-base"      )

           lowercase__		       =						tf.constant(
               [[101, 7_592, 1_010, 2_003, 2_026, 3_899, 10_140, 1_029, 102]]      )  # [CLS] hello, is my dog cute? [SEP]
           lowercase__		       =						model(UpperCAmelCase_      )[0]  # embedding shape = (1, 768)
           # compare the actual values for a slice.
           lowercase__		       =						tf.constant(
               [
                   [
                       0.03_23_62_53,
                       0.12_75_33_35,
                       0.16_81_85_09,
                       0.00_27_97_86,
                       0.3_89_69_33,
                       0.24_26_49_45,
                       0.2_17_89_71,
                       -0.02_33_52_27,
                       -0.08_48_19_59,
                       -0.14_32_41_17,
                   ]
               ]      )
           self.assertTrue(numpy.allclose(output[:, :10].numpy()     ,expected_slice.numpy()     ,atol=1E-4      )      )









'''simple docstring'''





def        lowerCamelCase  (				_snake_case  :						int     ,_snake_case  :						int       ):





    '''simple docstring'''


    return x if y == 0 else greatest_common_divisor(_snake_case     ,x % y       )




def        lowerCamelCase  (				_snake_case  :						int     ,_snake_case  :						int       ):





    '''simple docstring'''


    return (x * y) // greatest_common_divisor(_snake_case     ,_snake_case       )




def        lowerCamelCase  (				_snake_case  :						int = 20       ):





    '''simple docstring'''


    lowercase__		       =						1
    for i in range(1     ,n + 1       ):
        lowercase__		       =						lcm(_snake_case     ,_snake_case       )
    return g


if __name__ == "__main__":
 print(f'''{solution() = }''')




