


'''simple docstring'''




from __future__ import annotations

import unittest

from transformers import DebertaConfig, 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 (
				    TFDebertaForMaskedLM,
				    TFDebertaForQuestionAnswering,
				    TFDebertaForSequenceClassification,
				    TFDebertaForTokenClassification,
				    TFDebertaModel,
				)





class _snake_case :
							"""simple docstring"""





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



											"""simple docstring"""







											__lowerCamelCase		:   Union[str, Any]           =       parent
											__lowerCamelCase		:   Tuple           =       13
											__lowerCamelCase		:   Optional[int]           =       7
											__lowerCamelCase		:   List[Any]           =       True
											__lowerCamelCase		:   Any           =       True
											__lowerCamelCase		:   Optional[int]           =       True
											__lowerCamelCase		:   Optional[Any]           =       True
											__lowerCamelCase		:   Any           =       99
											__lowerCamelCase		:   Tuple           =       32
											__lowerCamelCase		:   Tuple           =       2
											__lowerCamelCase		:   Union[str, Any]           =       4
											__lowerCamelCase		:   Any           =       37
											__lowerCamelCase		:   Optional[Any]           =       "gelu"
											__lowerCamelCase		:   List[str]           =       0.1
											__lowerCamelCase		:   Dict           =       0.1
											__lowerCamelCase		:   str           =       512
											__lowerCamelCase		:   str           =       16
											__lowerCamelCase		:   Any           =       False
											__lowerCamelCase		:   List[str]           =       -1
											__lowerCamelCase		:   List[str]           =       True
											__lowerCamelCase		:   Optional[Any]           =       2
											__lowerCamelCase		:   int           =       0.02
											__lowerCamelCase		:   Optional[int]           =       3
											__lowerCamelCase		:   Any           =       4
											__lowerCamelCase		:   Union[str, Any]           =       None







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



											"""simple docstring"""







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

											__lowerCamelCase		:   Tuple           =       None
											if self.use_input_mask:
															__lowerCamelCase		:   Optional[int]           =       random_attention_mask([self.batch_size, self.seq_length]						)

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

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

											__lowerCamelCase		:   Optional[int]           =       DebertaConfig(
											    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      ,					max_relative_positions=self.max_relative_positions      ,					position_biased_input=self.position_biased_input      ,					initializer_range=self.initializer_range      ,					return_dict=__A      ,					)

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







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A						)  ->Optional[Any]:



											"""simple docstring"""







											__lowerCamelCase		:   Optional[Any]           =       TFDebertaModel(config=__A						)
											__lowerCamelCase		:   int           =       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

											__lowerCamelCase		:   str           =       [input_ids, input_mask]
											__lowerCamelCase		:   Optional[Any]           =       model(__A						)

											__lowerCamelCase		:   Any           =       model(__A						)

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







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A						)  ->Optional[int]:



											"""simple docstring"""







											__lowerCamelCase		:   Union[str, Any]           =       TFDebertaForMaskedLM(config=__A						)
											__lowerCamelCase		:   Optional[int]           =       {
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}
											__lowerCamelCase		:   int           =       model(__A						)
											self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.seq_length, self.vocab_size)						)







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A						)  ->List[Any]:



											"""simple docstring"""







											__lowerCamelCase		:   List[str]           =       self.num_labels
											__lowerCamelCase		:   Union[str, Any]           =       TFDebertaForSequenceClassification(config=__A						)
											__lowerCamelCase		:   Tuple           =       {
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}

											__lowerCamelCase		:   List[Any]           =       model(__A						)
											self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.num_labels)						)







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A						)  ->Dict:



											"""simple docstring"""







											__lowerCamelCase		:   List[Any]           =       self.num_labels
											__lowerCamelCase		:   List[str]           =       TFDebertaForTokenClassification(config=__A						)
											__lowerCamelCase		:   str           =       {
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}
											__lowerCamelCase		:   int           =       model(__A						)
											self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.seq_length, self.num_labels)						)







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A      ,					__A						)  ->Any:



											"""simple docstring"""







											__lowerCamelCase		:   Optional[Any]           =       TFDebertaForQuestionAnswering(config=__A						)
											__lowerCamelCase		:   Union[str, Any]           =       {
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}

											__lowerCamelCase		:   Union[str, Any]           =       model(__A						)
											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 		__SCREAMING_SNAKE_CASE( self						)  ->int:



											"""simple docstring"""







											__lowerCamelCase		:   int           =       self.prepare_config_and_inputs()
											(
											    (
											    __lowerCamelCase
											)    ,       (
											    __lowerCamelCase
											)    ,       (
											    __lowerCamelCase
											)    ,       (
											    __lowerCamelCase
											)    ,       (
											    __lowerCamelCase
											)    ,       (
											    __lowerCamelCase
											)    ,       (
											    __lowerCamelCase
											)    ,       
											)		:   Tuple           =       config_and_inputs
											__lowerCamelCase		:   List[str]           =       {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
											return config, inputs_dict





@require_tf
class _snake_case (			a__     , a__     , unittest.TestCase ):
							"""simple docstring"""





							__a				       =  (
							    (
							        TFDebertaModel,
							        TFDebertaForMaskedLM,
							        TFDebertaForQuestionAnswering,
							        TFDebertaForSequenceClassification,
							        TFDebertaForTokenClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							__a				       =  (
							    {
							        '''feature-extraction''': TFDebertaModel,
							        '''fill-mask''': TFDebertaForMaskedLM,
							        '''question-answering''': TFDebertaForQuestionAnswering,
							        '''text-classification''': TFDebertaForSequenceClassification,
							        '''token-classification''': TFDebertaForTokenClassification,
							        '''zero-shot''': TFDebertaForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)

							__a				       =  False
							__a				       =  False







							def 		__SCREAMING_SNAKE_CASE( self						)  ->List[str]:



											"""simple docstring"""







											__lowerCamelCase		:   int           =       TFDebertaModelTester(self						)
											__lowerCamelCase		:   List[str]           =       ConfigTester(self      ,					config_class=__A      ,					hidden_size=37						)







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Any:



											"""simple docstring"""







											self.config_tester.run_common_tests()







							def 		__SCREAMING_SNAKE_CASE( self						)  ->int:



											"""simple docstring"""







											__lowerCamelCase		:   Optional[int]           =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__A						)







							def 		__SCREAMING_SNAKE_CASE( self						)  ->str:



											"""simple docstring"""







											__lowerCamelCase		:   List[str]           =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*__A						)







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Union[str, Any]:



											"""simple docstring"""







											__lowerCamelCase		:   Tuple           =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*__A						)







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Optional[int]:



											"""simple docstring"""







											__lowerCamelCase		:   int           =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*__A						)







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Any:



											"""simple docstring"""







											__lowerCamelCase		:   Optional[Any]           =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*__A						)







							@slow
							def 		__SCREAMING_SNAKE_CASE( self						)  ->Any:



											"""simple docstring"""







											__lowerCamelCase		:   List[Any]           =       TFDebertaModel.from_pretrained("kamalkraj/deberta-base"						)
											self.assertIsNotNone(__A						)





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





							@unittest.skip(reason="Model not available yet"						)
							def 		__SCREAMING_SNAKE_CASE( self						)  ->Optional[Any]:



											"""simple docstring"""







											pass







							@slow
							def 		__SCREAMING_SNAKE_CASE( self						)  ->int:



											"""simple docstring"""







											__lowerCamelCase		:   Any           =       TFDebertaModel.from_pretrained("kamalkraj/deberta-base"						)
											__lowerCamelCase		:   Tuple           =       tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]						)
											__lowerCamelCase		:   List[str]           =       tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
											__lowerCamelCase		:   Any           =       model(__A      ,					attention_mask=__A						)[0]

											__lowerCamelCase		:   List[str]           =       tf.constant(
											    [
											        [
											            [-0.5985_5896, -0.8055_2566, -0.846_2135],
											            [1.448_4025, -0.9348_3794, -0.8059_3085],
											            [0.312_2741, 0.0031_6059, -1.413_1377],
											        ]
											    ]						)
											tf.debugging.assert_near(output[:, 1:4, 1:4]      ,					__A      ,					atol=1E-4						)









'''simple docstring'''




import argparse
import copy
import json
import multiprocessing
import os
import time

from create_dummy_models import COMPOSITE_MODELS, create_tiny_models
from huggingface_hub import ModelFilter, hf_api

import transformers
from transformers import AutoFeatureExtractor, AutoImageProcessor, AutoTokenizer
from transformers.image_processing_utils import BaseImageProcessor





def 				a_							(    )      ->List[Any]:






				'''simple docstring'''

				__lowerCamelCase		:   Optional[Any]           =       set()
				# Each auto modeling files contains multiple mappings. Let's get them in a dynamic way.
				for module_name in ["modeling_auto", "modeling_tf_auto", "modeling_flax_auto"]:
								__lowerCamelCase		:   Dict           =       getattr(transformers.models.auto				,    lowercase				,    lowercase     )
								if module is None:
												continue
								# all mappings in a single auto modeling file
								__lowerCamelCase		:   Any           =       [
								    x
								    for x in dir(lowercase     )
								    if x.endswith("_MAPPING_NAMES"     )
								    and (x.startswith("MODEL_"     ) or x.startswith("TF_MODEL_"     ) or x.startswith("FLAX_MODEL_"     ))
								]
								for name in mapping_names:
												__lowerCamelCase		:   Union[str, Any]           =       getattr(lowercase				,    lowercase     )
												if mapping is not None:
																for v in mapping.values():
																				if isinstance(lowercase				,    (list, tuple)     ):
																								model_names.update(lowercase     )
																				elif isinstance(lowercase				,    lowercase     ):
																								model_names.add(lowercase     )

				return sorted(lowercase     )





def 				a_							(    )      ->int:






				'''simple docstring'''

				__lowerCamelCase		:   Tuple           =       set(get_all_model_names()     )

				with open("tests/utils/tiny_model_summary.json"     ) as fp:
								__lowerCamelCase		:   Optional[int]           =       json.load(lowercase     )
				__lowerCamelCase		:   Union[str, Any]           =       set()
				for model_base_name in tiny_model_info:
								tiny_models_names.update(tiny_model_info[model_base_name]["model_classes"]     )

				# Remove a tiny model name if one of its framework implementation hasn't yet a tiny version on the Hub.
				__lowerCamelCase		:   List[str]           =       model_names.difference(lowercase     )
				for model_name in copy.copy(lowercase     ):
								if not model_name.startswith("TF"     ) and F'TF{model_name}' in not_on_hub:
												tiny_models_names.remove(lowercase     )
								elif model_name.startswith("TF"     ) and model_name[2:] in not_on_hub:
												tiny_models_names.remove(lowercase     )

				return sorted(lowercase     )





def 				a_							(    lowercase     )      ->str:






				'''simple docstring'''

				__lowerCamelCase		:   Optional[int]           =       COMPOSITE_MODELS.values()

				# All tiny model base names on Hub
				__lowerCamelCase		:   List[Any]           =       get_all_model_names()
				__lowerCamelCase		:   Any           =       hf_api.list_models(
				    filter=ModelFilter(
				        author="hf-internal-testing"				,    )     )
				__lowerCamelCase		:   str           =       set()
				for x in models:
								__lowerCamelCase		:   Any           =       x.modelId
								__lowerCamelCase    ,       __lowerCamelCase		:   List[Any]           =       model.split("/"     )
								if not model.startswith("tiny-random-"     ):
												continue
								__lowerCamelCase		:   int           =       model.replace("tiny-random-"				,    ""     )
								if not model[0].isupper():
												continue
								if model not in model_names and model not in special_models:
												continue
								_models.add(lowercase     )

				__lowerCamelCase		:   Tuple           =       sorted(_models     )
				# All tiny model names on Hub
				__lowerCamelCase		:   Union[str, Any]           =       {}
				for model in models:
								__lowerCamelCase		:   List[str]           =       F'hf-internal-testing/tiny-random-{model}'
								__lowerCamelCase		:   Any           =       model.split("-"     )[0]
								try:
												__lowerCamelCase		:   str           =       hf_api.repo_info(lowercase     )
												__lowerCamelCase		:   str           =       {
												    "tokenizer_classes": set(),
												    "processor_classes": set(),
												    "model_classes": set(),
												    "sha": repo_info.sha,
												}
								except Exception:
												continue
								try:
												time.sleep(1     )
												__lowerCamelCase		:   Optional[int]           =       AutoTokenizer.from_pretrained(lowercase     )
												content["tokenizer_classes"].add(tokenizer_fast.__class__.__name__     )
								except Exception:
												pass
								try:
												time.sleep(1     )
												__lowerCamelCase		:   List[Any]           =       AutoTokenizer.from_pretrained(lowercase				,    use_fast=lowercase     )
												content["tokenizer_classes"].add(tokenizer_slow.__class__.__name__     )
								except Exception:
												pass
								try:
												time.sleep(1     )
												__lowerCamelCase		:   List[Any]           =       AutoImageProcessor.from_pretrained(lowercase     )
												content["processor_classes"].add(img_p.__class__.__name__     )
								except Exception:
												pass
								try:
												time.sleep(1     )
												__lowerCamelCase		:   Tuple           =       AutoFeatureExtractor.from_pretrained(lowercase     )
												if not isinstance(lowercase				,    lowercase     ):
																content["processor_classes"].add(feat_p.__class__.__name__     )
								except Exception:
												pass
								try:
												time.sleep(1     )
												__lowerCamelCase		:   Optional[Any]           =       getattr(lowercase				,    lowercase     )
												__lowerCamelCase		:   Optional[Any]           =       model_class.from_pretrained(lowercase     )
												content["model_classes"].add(m.__class__.__name__     )
								except Exception:
												pass
								try:
												time.sleep(1     )
												__lowerCamelCase		:   List[str]           =       getattr(lowercase				,    F'TF{model}'     )
												__lowerCamelCase		:   Dict           =       model_class.from_pretrained(lowercase     )
												content["model_classes"].add(m.__class__.__name__     )
								except Exception:
												pass

								__lowerCamelCase		:   List[Any]           =       sorted(content["tokenizer_classes"]     )
								__lowerCamelCase		:   str           =       sorted(content["processor_classes"]     )
								__lowerCamelCase		:   Union[str, Any]           =       sorted(content["model_classes"]     )

								__lowerCamelCase		:   Tuple           =       content
								with open(os.path.join(lowercase				,    "hub_tiny_model_summary.json"     )				,    "w"     ) as fp:
												json.dump(lowercase				,    lowercase				,    ensure_ascii=lowercase				,    indent=4     )


if __name__ == "__main__":
				__lowercase	:   Any   		=					argparse.ArgumentParser()
				parser.add_argument("""--num_workers""", default=1, type=int, help="""The number of workers to run.""")
				__lowercase	:   Optional[int]   		=					parser.parse_args()

				# This has to be `spawn` to avoid hanging forever!
				multiprocessing.set_start_method("""spawn""")

				__lowercase	:   str   		=					"""tiny_models"""
				__lowercase	:   List[Any]   		=					True
				__lowercase	:   Optional[int]   		=					None
				__lowercase	:   List[Any]   		=					get_tiny_model_names_from_repo()
				__lowercase	:   List[Any]   		=					True
				__lowercase	:   Dict   		=					True
				__lowercase	:   Tuple   		=					"""hf-internal-testing"""

				create_tiny_models(
				    output_path,
				    all,
				    model_types,
				    models_to_skip,
				    no_check,
				    upload,
				    organization,
				    token=os.environ.get("""TOKEN""", None),
				    num_workers=args.num_workers,
				)





