



from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 tensorflow as tf

							from transformers import (
							    TFDebertaVaForMaskedLM,
							    TFDebertaVaForQuestionAnswering,
							    TFDebertaVaForSequenceClassification,
							    TFDebertaVaForTokenClassification,
							    TFDebertaVaModel,
							)


class   __lowerCAmelCase  :
					"""simple docstring"""






					def __init__(  self       :							Tuple					,       _snake_case       :							str					,       _snake_case       :							Dict=13					,       _snake_case       :							Any=7					,       _snake_case       :							Tuple=True					,       _snake_case       :							Optional[int]=True					,       _snake_case       :							Dict=True					,       _snake_case       :							Any=True					,       _snake_case       :							Union[str, Any]=99					,       _snake_case       :							str=32					,       _snake_case       :							Union[str, Any]=2					,       _snake_case       :							List[Any]=4					,       _snake_case       :							Dict=37					,       _snake_case       :							Optional[int]="gelu"					,       _snake_case       :							List[str]=0.1					,       _snake_case       :							Tuple=0.1					,       _snake_case       :							str=5_12					,       _snake_case       :							Optional[int]=16					,       _snake_case       :							int=2					,       _snake_case       :							Dict=0.02					,       _snake_case       :							int=False					,       _snake_case       :							Tuple=True					,       _snake_case       :							str="None"					,       _snake_case       :							Dict=3					,       _snake_case       :							Dict=4					,       _snake_case       :							str=None					,       ):






								"""simple docstring"""


								A__	  =     parent
								A__	  =     batch_size
								A__	  =     seq_length
								A__	  =     is_training
								A__	  =     use_input_mask
								A__	  =     use_token_type_ids
								A__	  =     use_labels
								A__	  =     vocab_size
								A__	  =     hidden_size
								A__	  =     num_hidden_layers
								A__	  =     num_attention_heads
								A__	  =     intermediate_size
								A__	  =     hidden_act
								A__	  =     hidden_dropout_prob
								A__	  =     attention_probs_dropout_prob
								A__	  =     max_position_embeddings
								A__	  =     type_vocab_size
								A__	  =     type_sequence_label_size
								A__	  =     initializer_range
								A__	  =     num_labels
								A__	  =     num_choices
								A__	  =     relative_attention
								A__	  =     position_biased_input
								A__	  =     pos_att_type
								A__	  =     scope



					def      _a				(  self       :							Optional[Any]       ):






								"""simple docstring"""


								A__	  =     ids_tensor([self.batch_size, self.seq_length]					,       self.vocab_size       )

								A__	  =     None
								if self.use_input_mask:
											A__	  =     random_attention_mask([self.batch_size, self.seq_length]       )

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

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

								A__	  =     DebertaVaConfig(
								    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					,       relative_attention=self.relative_attention					,       position_biased_input=self.position_biased_input					,       initializer_range=self.initializer_range					,       return_dict=UpperCAmelCase_					,       )

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



					def      _a				(  self       :							Dict					,       _snake_case       :							str					,       _snake_case       :							Dict					,       _snake_case       :							Optional[int]					,       _snake_case       :							int					,       _snake_case       :							Union[str, Any]					,       _snake_case       :							int					,       _snake_case       :							Optional[Any]       ):






								"""simple docstring"""


								A__	  =     TFDebertaVaModel(config=UpperCAmelCase_       )
								A__	  =     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

								A__	  =     [input_ids, input_mask]
								A__	  =     model(UpperCAmelCase_       )

								A__	  =     model(UpperCAmelCase_       )

								self.parent.assertEqual(result.last_hidden_state.shape					,       (self.batch_size, self.seq_length, self.hidden_size)       )



					def      _a				(  self       :							Tuple					,       _snake_case       :							Union[str, Any]					,       _snake_case       :							Union[str, Any]					,       _snake_case       :							int					,       _snake_case       :							int					,       _snake_case       :							Union[str, Any]					,       _snake_case       :							Optional[int]					,       _snake_case       :							Optional[int]       ):






								"""simple docstring"""


								A__	  =     TFDebertaVaForMaskedLM(config=UpperCAmelCase_       )
								A__	  =     {
								    'input_ids': input_ids,
								    'attention_mask': input_mask,
								    'token_type_ids': token_type_ids,
								}
								A__	  =     model(UpperCAmelCase_       )
								self.parent.assertEqual(result.logits.shape					,       (self.batch_size, self.seq_length, self.vocab_size)       )



					def      _a				(  self       :							Dict					,       _snake_case       :							Tuple					,       _snake_case       :							Optional[int]					,       _snake_case       :							Dict					,       _snake_case       :							Tuple					,       _snake_case       :							Optional[Any]					,       _snake_case       :							str					,       _snake_case       :							Any       ):






								"""simple docstring"""


								A__	  =     self.num_labels
								A__	  =     TFDebertaVaForSequenceClassification(config=UpperCAmelCase_       )
								A__	  =     {
								    'input_ids': input_ids,
								    'attention_mask': input_mask,
								    'token_type_ids': token_type_ids,
								}

								A__	  =     model(UpperCAmelCase_       )
								self.parent.assertEqual(result.logits.shape					,       (self.batch_size, self.num_labels)       )



					def      _a				(  self       :							Dict					,       _snake_case       :							Dict					,       _snake_case       :							str					,       _snake_case       :							Optional[Any]					,       _snake_case       :							List[Any]					,       _snake_case       :							Union[str, Any]					,       _snake_case       :							List[str]					,       _snake_case       :							List[Any]       ):






								"""simple docstring"""


								A__	  =     self.num_labels
								A__	  =     TFDebertaVaForTokenClassification(config=UpperCAmelCase_       )
								A__	  =     {
								    'input_ids': input_ids,
								    'attention_mask': input_mask,
								    'token_type_ids': token_type_ids,
								}
								A__	  =     model(UpperCAmelCase_       )
								self.parent.assertEqual(result.logits.shape					,       (self.batch_size, self.seq_length, self.num_labels)       )



					def      _a				(  self       :							Union[str, Any]					,       _snake_case       :							Tuple					,       _snake_case       :							Union[str, Any]					,       _snake_case       :							Dict					,       _snake_case       :							Dict					,       _snake_case       :							str					,       _snake_case       :							Tuple					,       _snake_case       :							Optional[int]       ):






								"""simple docstring"""


								A__	  =     TFDebertaVaForQuestionAnswering(config=UpperCAmelCase_       )
								A__	  =     {
								    'input_ids': input_ids,
								    'attention_mask': input_mask,
								    'token_type_ids': token_type_ids,
								}

								A__	  =     model(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)       )



					def      _a				(  self       :							str       ):






								"""simple docstring"""


								A__	  =     self.prepare_config_and_inputs()
								(
								    (
								    A__							
								)  ,			(
								    A__							
								)  ,			(
								    A__							
								)  ,			(
								    A__							
								)  ,			(
								    A__							
								)  ,			(
								    A__							
								)  ,			(
								    A__							
								)  ,										
								)	  =     config_and_inputs
								A__	  =     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
								return config, inputs_dict







@require_tf
class   __lowerCAmelCase  (		_lowerCAmelCase				,  _lowerCAmelCase				,  unittest.TestCase   ):
					"""simple docstring"""






					A__					:		Optional[int]      							=     (
					    (
					        TFDebertaVaModel,
					        TFDebertaVaForMaskedLM,
					        TFDebertaVaForQuestionAnswering,
					        TFDebertaVaForSequenceClassification,
					        TFDebertaVaForTokenClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					A__					:		str      							=     (
					    {
					        '''feature-extraction''': TFDebertaVaModel,
					        '''fill-mask''': TFDebertaVaForMaskedLM,
					        '''question-answering''': TFDebertaVaForQuestionAnswering,
					        '''text-classification''': TFDebertaVaForSequenceClassification,
					        '''token-classification''': TFDebertaVaForTokenClassification,
					        '''zero-shot''': TFDebertaVaForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)

					A__					:		Dict      							=     False
					A__					:		List[str]      							=     False



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






								"""simple docstring"""


								A__	  =     TFDebertaVaModelTester(self       )
								A__	  =     ConfigTester(self					,       config_class=UpperCAmelCase_					,       hidden_size=37       )



					def      _a				(  self       :							Optional[int]       ):






								"""simple docstring"""


								self.config_tester.run_common_tests()



					def      _a				(  self       :							Any       ):






								"""simple docstring"""


								A__	  =     self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*UpperCAmelCase_       )



					def      _a				(  self       :							Tuple       ):






								"""simple docstring"""


								A__	  =     self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase_       )



					def      _a				(  self       :							List[Any]       ):






								"""simple docstring"""


								A__	  =     self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_       )



					def      _a				(  self       :							List[Any]       ):






								"""simple docstring"""


								A__	  =     self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase_       )



					def      _a				(  self       :							int       ):






								"""simple docstring"""


								A__	  =     self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_       )



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






								"""simple docstring"""


								A__	  =     TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'       )
								self.assertIsNotNone(UpperCAmelCase_       )







@require_tf
class   __lowerCAmelCase  (		unittest.TestCase   ):
					"""simple docstring"""






					@unittest.skip(reason='Model not available yet'       )
					def      _a				(  self       :							Any       ):






								"""simple docstring"""


								pass



					@slow
					def      _a				(  self       :							Dict       ):






								"""simple docstring"""


								A__	  =     TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'       )
								A__	  =     tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]       )
								A__	  =     tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
								A__	  =     model(UpperCAmelCase_					,       attention_mask=UpperCAmelCase_       )[0]

								A__	  =     tf.constant(
								    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]       )
								tf.debugging.assert_near(output[:, 1:4, 1:4]					,       UpperCAmelCase_					,       atol=1E-4       )






"""simple docstring"""


import os
import zipfile

import requests
from get_ci_error_statistics import download_artifact, get_artifacts_links



def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_=7					)->				Optional[Any]:







       """simple docstring"""
       UpperCamelCase       			=		None
       if token is not None:
              UpperCamelCase       			=		{"Accept": "application/vnd.github+json", "Authorization": F"Bearer {token}"}

       # The id of a workflow (not of a workflow run)
       UpperCamelCase       			=		"636036"

       UpperCamelCase       			=		F"https://api.github.com/repos/huggingface/transformers/actions/workflows/{workflow_id}/runs"
       # On `main` branch + event being `schedule` + not returning PRs + only `num_runs` results
       url += F"?branch=main&event=schedule&exclude_pull_requests=true&per_page={num_runs}"

       UpperCamelCase       			=		requests.get(UpperCAmelCase_		,   headers=UpperCAmelCase_					).json()

       return result["workflow_runs"]



def 						lowerCamelCase__      (				UpperCAmelCase_					)->				Any:







       """simple docstring"""
       UpperCamelCase       			=		get_daily_ci_runs(UpperCAmelCase_					)
       UpperCamelCase       			=		None
       for workflow_run in workflow_runs:
              if workflow_run["status"] == "completed":
                     UpperCamelCase       			=		workflow_run["id"]
                     break

       return workflow_run_id



def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				int:







       """simple docstring"""
       UpperCamelCase       			=		get_last_daily_ci_runs(UpperCAmelCase_					)
       if workflow_run_id is not None:
              UpperCamelCase       			=		get_artifacts_links(worflow_run_id=UpperCAmelCase_		,   token=UpperCAmelCase_					)
              for artifact_name in artifact_names:
                     if artifact_name in artifacts_links:
                            UpperCamelCase       			=		artifacts_links[artifact_name]
                            download_artifact(
                                artifact_name=UpperCAmelCase_		,   artifact_url=UpperCAmelCase_		,   output_dir=UpperCAmelCase_		,   token=UpperCAmelCase_					)



def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Optional[int]:







       """simple docstring"""
       get_last_daily_ci_artifacts(UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)

       UpperCamelCase       			=		{}
       for artifact_name in artifact_names:
              UpperCamelCase       			=		os.path.join(UpperCAmelCase_		,   F"{artifact_name}.zip"					)
              if os.path.isfile(UpperCAmelCase_					):
                     UpperCamelCase       			=		{}
                     with zipfile.ZipFile(UpperCAmelCase_					) as z:
                            for filename in z.namelist():
                                   if not os.path.isdir(UpperCAmelCase_					):
                                          # read the file
                                          with z.open(UpperCAmelCase_					) as f:
                                                 UpperCamelCase       			=		f.read().decode("UTF-8"					)

       return results





