




'''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 	__lowercase				:

			def __init__(self			,   A			,   A=1_3			,   A=7			,   A=True			,   A=True			,   A=True			,   A=True			,   A=9_9			,   A=3_2			,   A=2			,   A=4			,   A=3_7			,   A="gelu"			,   A=0.1			,   A=0.1			,   A=5_1_2			,   A=1_6			,   A=2			,   A=0.02			,   A=3			,   A=4			,   A=None			,   A=0			,   ):
								lowerCamelCase_					:      Any     =		parent
								lowerCamelCase_					:      Union[str, Any]     =		batch_size
								lowerCamelCase_					:      Optional[Any]     =		seq_length
								lowerCamelCase_					:      List[Any]     =		is_training
								lowerCamelCase_					:      List[str]     =		use_input_mask
								lowerCamelCase_					:      List[str]     =		use_token_type_ids
								lowerCamelCase_					:      Union[str, Any]     =		use_labels
								lowerCamelCase_					:      str     =		vocab_size
								lowerCamelCase_					:      str     =		hidden_size
								lowerCamelCase_					:      Tuple     =		num_hidden_layers
								lowerCamelCase_					:      int     =		num_attention_heads
								lowerCamelCase_					:      Dict     =		intermediate_size
								lowerCamelCase_					:      List[Any]     =		hidden_act
								lowerCamelCase_					:      Union[str, Any]     =		hidden_dropout_prob
								lowerCamelCase_					:      Optional[Any]     =		attention_probs_dropout_prob
								lowerCamelCase_					:      int     =		max_position_embeddings
								lowerCamelCase_					:      Union[str, Any]     =		type_vocab_size
								lowerCamelCase_					:      Dict     =		type_sequence_label_size
								lowerCamelCase_					:      Optional[int]     =		initializer_range
								lowerCamelCase_					:      Tuple     =		num_labels
								lowerCamelCase_					:      Dict     =		num_choices
								lowerCamelCase_					:      int     =		scope
								lowerCamelCase_					:      Union[str, Any]     =		projection_dim

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[int]     =		ids_tensor([self.batch_size, self.seq_length]			,   self.vocab_size      )

								lowerCamelCase_					:      int     =		None
								if self.use_input_mask:
													# follow test_modeling_tf_ctrl.py
													lowerCamelCase_					:      List[str]     =		random_attention_mask([self.batch_size, self.seq_length]      )

								lowerCamelCase_					:      Dict     =		None
								if self.use_token_type_ids:
													lowerCamelCase_					:      Optional[int]     =		ids_tensor([self.batch_size, self.seq_length]			,   self.type_vocab_size      )

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

								lowerCamelCase_					:      Tuple     =		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=_lowercase			,   initializer_range=self.initializer_range			,   )
								lowerCamelCase_					:      Tuple     =		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        UpperCAmelCase__ (self			,   A			,   A			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      List[str]     =		TFDPRContextEncoder(config=_lowercase      )
								lowerCamelCase_					:      Dict     =		model(_lowercase			,   attention_mask=_lowercase			,   token_type_ids=_lowercase      )
								lowerCamelCase_					:      Union[str, Any]     =		model(_lowercase			,   token_type_ids=_lowercase      )
								lowerCamelCase_					:      int     =		model(_lowercase      )
								self.parent.assertEqual(result.pooler_output.shape			,   (self.batch_size, self.projection_dim or self.hidden_size)      )

			def        UpperCAmelCase__ (self			,   A			,   A			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      List[Any]     =		TFDPRQuestionEncoder(config=_lowercase      )
								lowerCamelCase_					:      Optional[int]     =		model(_lowercase			,   attention_mask=_lowercase			,   token_type_ids=_lowercase      )
								lowerCamelCase_					:      Optional[int]     =		model(_lowercase			,   token_type_ids=_lowercase      )
								lowerCamelCase_					:      List[Any]     =		model(_lowercase      )
								self.parent.assertEqual(result.pooler_output.shape			,   (self.batch_size, self.projection_dim or self.hidden_size)      )

			def        UpperCAmelCase__ (self			,   A			,   A			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      List[Any]     =		TFDPRReader(config=_lowercase      )
								lowerCamelCase_					:      Union[str, Any]     =		model(_lowercase			,   attention_mask=_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)      )
								self.parent.assertEqual(result.relevance_logits.shape			,   (self.batch_size,)      )






			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Dict     =		self.prepare_config_and_inputs()
								(
								    (
								    lowerCamelCase_ 
								),      (
								    lowerCamelCase_ 
								),      (
								    lowerCamelCase_ 
								),      (
								    lowerCamelCase_ 
								),      (
								    lowerCamelCase_ 
								),      (
								    lowerCamelCase_ 
								),      (
								    lowerCamelCase_ 
								),       
								)					:      Optional[Any]     =		config_and_inputs
								lowerCamelCase_					:      List[str]     =		{'''input_ids''': input_ids}
								return config, inputs_dict

@require_tf
class 	__lowercase				(  UpperCAmelCase_      ,     UpperCAmelCase_      ,     unittest.TestCase    ):
			lowerCamelCase			:		Any	      =			(
			    (
			        TFDPRContextEncoder,
			        TFDPRQuestionEncoder,
			        TFDPRReader,
			    )
			    if is_tf_available()
			    else ()
			)
			lowerCamelCase			:		Tuple	      =			{"feature-extraction": TFDPRQuestionEncoder} if is_tf_available() else {}

			lowerCamelCase			:		List[str]	      =			False
			lowerCamelCase			:		str	      =			False
			lowerCamelCase			:		Union[str, Any]	      =			False
			lowerCamelCase			:		Optional[Any]	      =			False
			lowerCamelCase			:		Union[str, Any]	      =			False

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		TFDPRModelTester(self      )
								lowerCamelCase_					:      Optional[int]     =		ConfigTester(self			,   config_class=_lowercase			,   hidden_size=3_7      )

			def        UpperCAmelCase__ (self      ):
								self.config_tester.run_common_tests()

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Dict     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_dpr_context_encoder(*_lowercase      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_dpr_question_encoder(*_lowercase      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      str     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_dpr_reader(*_lowercase      )






			@slow
			def        UpperCAmelCase__ (self      ):
								for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase_					:      Optional[Any]     =		TFDPRContextEncoder.from_pretrained(_lowercase      )
													self.assertIsNotNone(_lowercase      )

								for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase_					:      Tuple     =		TFDPRContextEncoder.from_pretrained(_lowercase      )
													self.assertIsNotNone(_lowercase      )

								for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase_					:      int     =		TFDPRQuestionEncoder.from_pretrained(_lowercase      )
													self.assertIsNotNone(_lowercase      )

								for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase_					:      int     =		TFDPRReader.from_pretrained(_lowercase      )
													self.assertIsNotNone(_lowercase      )

@require_tf
class 	__lowercase				(  unittest.TestCase    ):

			@slow
			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      List[Any]     =		TFDPRQuestionEncoder.from_pretrained('''facebook/dpr-question_encoder-single-nq-base'''      )

								lowerCamelCase_					:      List[str]     =		tf.constant(
								    [[1_0_1, 7_5_9_2, 1_0_1_0, 2_0_0_3, 2_0_2_6, 3_8_9_9, 1_0_1_4_0, 1_0_2_9, 1_0_2]]      )  # [CLS] hello, is my dog cute? [SEP]
								lowerCamelCase_					:      Dict     =		model(_lowercase      )[0]  # embedding shape = (1, 768)
								# compare the actual values for a slice.
								lowerCamelCase_					:      Optional[int]     =		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[:, :1_0].numpy()			,   expected_slice.numpy()			,   atol=1E-4      )      )




'''simple docstring'''


def lowercase_	(   _lowercase = 1_000				)     ->							int:
					'''simple docstring'''

					lowerCamelCase_					:      Dict     =		2**power
					lowerCamelCase_					:      Union[str, Any]     =		str(_lowercase				)
					lowerCamelCase_					:      Union[str, Any]     =		list(_lowercase				)
					lowerCamelCase_					:      Dict     =		0

					for i in list_num:
										sum_of_num += int(_lowercase				)

					return sum_of_num


if __name__ == "__main__":
					__lowercase							:   Optional[Any]					=     int(input('''Enter the power of 2: ''').strip())
					print('''2 ^ ''', power, ''' = ''', 2**power)
					__lowercase							:   Tuple					=     solution(power)
					print('''Sum of the digits is: ''', result)


