




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        __lowerCAmelCase					:

			"""simple docstring"""







			def __init__( self     ,		lowerCamelCase__     ,		lowerCamelCase__=13     ,		lowerCamelCase__=7     ,		lowerCamelCase__=True     ,		lowerCamelCase__=True     ,		lowerCamelCase__=True     ,		lowerCamelCase__=True     ,		lowerCamelCase__=99     ,		lowerCamelCase__=32     ,		lowerCamelCase__=2     ,		lowerCamelCase__=4     ,		lowerCamelCase__=37     ,		lowerCamelCase__="gelu"     ,		lowerCamelCase__=0.1     ,		lowerCamelCase__=0.1     ,		lowerCamelCase__=512     ,		lowerCamelCase__=16     ,		lowerCamelCase__=2     ,		lowerCamelCase__=0.02     ,		lowerCamelCase__=3     ,		lowerCamelCase__=4     ,		lowerCamelCase__=None     ,		lowerCamelCase__=0     ,		)       -> Tuple:



							'''simple docstring'''
							__lowerCamelCase									=       parent
							__lowerCamelCase									=       batch_size
							__lowerCamelCase									=       seq_length
							__lowerCamelCase									=       is_training
							__lowerCamelCase									=       use_input_mask
							__lowerCamelCase									=       use_token_type_ids
							__lowerCamelCase									=       use_labels
							__lowerCamelCase									=       vocab_size
							__lowerCamelCase									=       hidden_size
							__lowerCamelCase									=       num_hidden_layers
							__lowerCamelCase									=       num_attention_heads
							__lowerCamelCase									=       intermediate_size
							__lowerCamelCase									=       hidden_act
							__lowerCamelCase									=       hidden_dropout_prob
							__lowerCamelCase									=       attention_probs_dropout_prob
							__lowerCamelCase									=       max_position_embeddings
							__lowerCamelCase									=       type_vocab_size
							__lowerCamelCase									=       type_sequence_label_size
							__lowerCamelCase									=       initializer_range
							__lowerCamelCase									=       num_labels
							__lowerCamelCase									=       num_choices
							__lowerCamelCase									=       scope
							__lowerCamelCase									=       projection_dim


			def  lowercase_       ( self				)       -> List[Any]:



							'''simple docstring'''
							__lowerCamelCase									=       ids_tensor([self.batch_size, self.seq_length]     ,		self.vocab_size				)

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

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

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

							__lowerCamelCase									=       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=lowerCamelCase__     ,		initializer_range=self.initializer_range     ,		)
							__lowerCamelCase									=       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  lowercase_       ( self     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__				)       -> Tuple:



							'''simple docstring'''
							__lowerCamelCase									=       TFDPRContextEncoder(config=lowerCamelCase__				)
							__lowerCamelCase									=       model(lowerCamelCase__     ,		attention_mask=lowerCamelCase__     ,		token_type_ids=lowerCamelCase__				)
							__lowerCamelCase									=       model(lowerCamelCase__     ,		token_type_ids=lowerCamelCase__				)
							__lowerCamelCase									=       model(lowerCamelCase__				)
							self.parent.assertEqual(result.pooler_output.shape     ,		(self.batch_size, self.projection_dim or self.hidden_size)				)


			def  lowercase_       ( self     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__				)       -> Dict:



							'''simple docstring'''
							__lowerCamelCase									=       TFDPRQuestionEncoder(config=lowerCamelCase__				)
							__lowerCamelCase									=       model(lowerCamelCase__     ,		attention_mask=lowerCamelCase__     ,		token_type_ids=lowerCamelCase__				)
							__lowerCamelCase									=       model(lowerCamelCase__     ,		token_type_ids=lowerCamelCase__				)
							__lowerCamelCase									=       model(lowerCamelCase__				)
							self.parent.assertEqual(result.pooler_output.shape     ,		(self.batch_size, self.projection_dim or self.hidden_size)				)


			def  lowercase_       ( self     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__				)       -> Tuple:



							'''simple docstring'''
							__lowerCamelCase									=       TFDPRReader(config=lowerCamelCase__				)
							__lowerCamelCase									=       model(lowerCamelCase__     ,		attention_mask=lowerCamelCase__				)

							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  lowercase_       ( self				)       -> Any:



							'''simple docstring'''
							__lowerCamelCase									=       self.prepare_config_and_inputs()
							(
							    (
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		
							)									=       config_and_inputs
							__lowerCamelCase									=       {'input_ids': input_ids}
							return config, inputs_dict







@require_tf
class        __lowerCAmelCase					(			__magic_name__     ,							__magic_name__     ,							unittest.TestCase					):

			"""simple docstring"""







			snake_case_  						=			(
			    (
			        TFDPRContextEncoder,
			        TFDPRQuestionEncoder,
			        TFDPRReader,
			    )
			    if is_tf_available()
			    else ()
			)
			snake_case_  						=			{'''feature-extraction''': TFDPRQuestionEncoder} if is_tf_available() else {}

			snake_case_  						=			False
			snake_case_  						=			False
			snake_case_  						=			False
			snake_case_  						=			False
			snake_case_  						=			False


			def  lowercase_       ( self				)       -> List[Any]:



							'''simple docstring'''
							__lowerCamelCase									=       TFDPRModelTester(self				)
							__lowerCamelCase									=       ConfigTester(self     ,		config_class=lowerCamelCase__     ,		hidden_size=37				)


			def  lowercase_       ( self				)       -> List[Any]:



							'''simple docstring'''
							self.config_tester.run_common_tests()


			def  lowercase_       ( self				)       -> str:



							'''simple docstring'''
							__lowerCamelCase									=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_context_encoder(*lowerCamelCase__				)


			def  lowercase_       ( self				)       -> Optional[Any]:



							'''simple docstring'''
							__lowerCamelCase									=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_question_encoder(*lowerCamelCase__				)


			def  lowercase_       ( self				)       -> int:



							'''simple docstring'''
							__lowerCamelCase									=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_reader(*lowerCamelCase__				)






			@slow
			def  lowercase_       ( self				)       -> Union[str, Any]:



							'''simple docstring'''
							for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowerCamelCase									=       TFDPRContextEncoder.from_pretrained(lowerCamelCase__				)
											self.assertIsNotNone(lowerCamelCase__				)

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

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

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







@require_tf
class        __lowerCAmelCase					(			unittest.TestCase					):

			"""simple docstring"""







			@slow
			def  lowercase_       ( self				)       -> int:



							'''simple docstring'''
							__lowerCamelCase									=       TFDPRQuestionEncoder.from_pretrained('facebook/dpr-question_encoder-single-nq-base'				)

							__lowerCamelCase									=       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]
							__lowerCamelCase									=       model(lowerCamelCase__				)[0]  # embedding shape = (1, 768)
							# compare the actual values for a slice.
							__lowerCamelCase									=       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				)				)








from datetime import datetime as dt
import os

from github import Github


__A								=       [
    "good first issue",
    "good second issue",
    "good difficult issue",
    "feature request",
    "new model",
    "wip",
]







def      lowerCamelCase_						(			)	->			int:





				"""simple docstring"""


				__lowerCamelCase									=       Github(os.environ['GITHUB_TOKEN'] )
				__lowerCamelCase									=       g.get_repo('huggingface/transformers' )
				__lowerCamelCase									=       repo.get_issues(state='open' )

				for issue in open_issues:
								__lowerCamelCase									=       sorted([comment for comment in issue.get_comments()]					,	key=lambda UpperCamelCase__ : i.created_at					,	reverse=UpperCamelCase__ )
								__lowerCamelCase									=       comments[0] if len(UpperCamelCase__ ) > 0 else None
								if (
								    last_comment is not None
								    and last_comment.user.login == "github-actions[bot]"
								    and (dt.utcnow() - issue.updated_at).days > 7
								    and (dt.utcnow() - issue.created_at).days >= 30
								    and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels() )
								):
												# print(f"Would close issue {issue.number} since it has been 7 days of inactivity since bot mention.")
												issue.edit(state='closed' )
								elif (
								    (dt.utcnow() - issue.updated_at).days > 23
								    and (dt.utcnow() - issue.created_at).days >= 30
								    and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels() )
								):
												# print(f"Would add stale comment to {issue.number}")
												issue.create_comment(
												    'This issue has been automatically marked as stale because it has not had '
												    'recent activity. If you think this still needs to be addressed '
												    'please comment on this thread.\n\nPlease note that issues that do not follow the '
												    '[contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) '
												    'are likely to be ignored.' )


if __name__ == "__main__":
					main()


