

'''simple docstring'''







import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    MODEL_FOR_PRETRAINING_MAPPING,
							    FunnelBaseModel,
							    FunnelForMaskedLM,
							    FunnelForMultipleChoice,
							    FunnelForPreTraining,
							    FunnelForQuestionAnswering,
							    FunnelForSequenceClassification,
							    FunnelForTokenClassification,
							    FunnelModel,
							)
class 					__a   :

						def __init__(		self	:						Any    ,			lowercase__	:						Tuple    ,			lowercase__	:						Tuple=13    ,			lowercase__	:						int=7    ,			lowercase__	:						Optional[Any]=True    ,			lowercase__	:						Union[str, Any]=True    ,			lowercase__	:						Union[str, Any]=True    ,			lowercase__	:						int=True    ,			lowercase__	:						Optional[Any]=99    ,			lowercase__	:						List[str]=[1, 1, 2]    ,			lowercase__	:						int=1    ,			lowercase__	:						Optional[Any]=32    ,			lowercase__	:						Optional[Any]=4    ,			lowercase__	:						Union[str, Any]=8    ,			lowercase__	:						str=37    ,			lowercase__	:						Tuple="gelu_new"    ,			lowercase__	:						Optional[int]=0.1    ,			lowercase__	:						Dict=0.1    ,			lowercase__	:						int=0.0    ,			lowercase__	:						Union[str, Any]=5_12    ,			lowercase__	:						List[Any]=3    ,			lowercase__	:						Tuple=0.02    ,			lowercase__	:						int=3    ,			lowercase__	:						Dict=4    ,			lowercase__	:						Any=None    ,			lowercase__	:						Dict=False    ,			)						->Optional[Any]:

							"""simple docstring"""



							_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							=     block_sizes
							_lowercase							=     num_decoder_layers
							_lowercase							=     d_model
							_lowercase							=     n_head
							_lowercase							=     d_head
							_lowercase							=     d_inner
							_lowercase							=     hidden_act
							_lowercase							=     hidden_dropout
							_lowercase							=     attention_dropout
							_lowercase							=     activation_dropout
							_lowercase							=     max_position_embeddings
							_lowercase							=     type_vocab_size
							_lowercase							=     2
							_lowercase							=     num_labels
							_lowercase							=     num_choices
							_lowercase							=     scope
							_lowercase							=     initializer_std

							# Used in the tests to check the size of the first attention layer
							_lowercase							=     n_head
							# Used in the tests to check the size of the first hidden state
							_lowercase							=     self.d_model
							# Used in the tests to check the number of output hidden states/attentions
							_lowercase							=     sum(self.block_sizes) + (0 if base else self.num_decoder_layers)
							# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
							# the last hidden state of the first block (which is the first hidden state of the decoder).
							if not base:
								_lowercase							=     self.num_hidden_layers + 2

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

							"""simple docstring"""



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

							_lowercase							=     None
							if self.use_input_mask:
								_lowercase							=     ids_tensor([self.batch_size, self.seq_length]    ,			vocab_size=2)

							_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							=     ids_tensor([self.batch_size, self.seq_length]    ,			1)

							_lowercase							=     self.get_config()

							return (
							    config,
							    input_ids,
							    token_type_ids,
							    input_mask,
							    sequence_labels,
							    token_labels,
							    choice_labels,
							    fake_token_labels,
							)

						def 	_UpperCAmelCase							(		self	:						List[str])						->Dict:

							"""simple docstring"""



							return FunnelConfig(
							    vocab_size=self.vocab_size    ,			block_sizes=self.block_sizes    ,			num_decoder_layers=self.num_decoder_layers    ,			d_model=self.d_model    ,			n_head=self.n_head    ,			d_head=self.d_head    ,			d_inner=self.d_inner    ,			hidden_act=self.hidden_act    ,			hidden_dropout=self.hidden_dropout    ,			attention_dropout=self.attention_dropout    ,			activation_dropout=self.activation_dropout    ,			max_position_embeddings=self.max_position_embeddings    ,			type_vocab_size=self.type_vocab_size    ,			initializer_std=self.initializer_std    ,			)

						def 	_UpperCAmelCase							(		self	:						Optional[Any]    ,			lowercase__	:						List[str]    ,			lowercase__	:						Any    ,			lowercase__	:						int    ,			lowercase__	:						Any    ,			lowercase__	:						str    ,			lowercase__	:						str    ,			lowercase__	:						int    ,			lowercase__	:						Dict    ,			)						->str:

							"""simple docstring"""



							_lowercase							=     FunnelModel(config=lowercase__)
							model.to(lowercase__)
							model.eval()
							_lowercase							=     model(lowercase__    ,			attention_mask=lowercase__    ,			token_type_ids=lowercase__)
							_lowercase							=     model(lowercase__    ,			token_type_ids=lowercase__)
							_lowercase							=     model(lowercase__)
							self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, self.seq_length, self.d_model))

							_lowercase							=     False
							_lowercase							=     model(lowercase__)
							self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, self.seq_length, self.d_model))

							_lowercase							=     False
							_lowercase							=     model(lowercase__)
							self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, self.seq_length, self.d_model))

						def 	_UpperCAmelCase							(		self	:						Any    ,			lowercase__	:						List[str]    ,			lowercase__	:						Union[str, Any]    ,			lowercase__	:						Optional[int]    ,			lowercase__	:						Dict    ,			lowercase__	:						Optional[int]    ,			lowercase__	:						Tuple    ,			lowercase__	:						List[str]    ,			lowercase__	:						Union[str, Any]    ,			)						->List[str]:

							"""simple docstring"""



							_lowercase							=     FunnelBaseModel(config=lowercase__)
							model.to(lowercase__)
							model.eval()
							_lowercase							=     model(lowercase__    ,			attention_mask=lowercase__    ,			token_type_ids=lowercase__)
							_lowercase							=     model(lowercase__    ,			token_type_ids=lowercase__)
							_lowercase							=     model(lowercase__)
							self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, 2, self.d_model))

							_lowercase							=     False
							_lowercase							=     model(lowercase__)
							self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, 3, self.d_model))

							_lowercase							=     False
							_lowercase							=     model(lowercase__)
							self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, 2, self.d_model))

						def 	_UpperCAmelCase							(		self	:						Optional[int]    ,			lowercase__	:						str    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Dict    ,			lowercase__	:						Any    ,			lowercase__	:						Dict    ,			lowercase__	:						List[Any]    ,			lowercase__	:						List[Any]    ,			lowercase__	:						List[Any]    ,			)						->List[Any]:

							"""simple docstring"""



							_lowercase							=     self.num_labels
							_lowercase							=     FunnelForPreTraining(config=lowercase__)
							model.to(lowercase__)
							model.eval()
							_lowercase							=     model(lowercase__    ,			attention_mask=lowercase__    ,			token_type_ids=lowercase__    ,			labels=lowercase__)
							self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length))

						def 	_UpperCAmelCase							(		self	:						Dict    ,			lowercase__	:						Dict    ,			lowercase__	:						List[Any]    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Optional[Any]    ,			lowercase__	:						List[str]    ,			lowercase__	:						str    ,			lowercase__	:						Optional[int]    ,			lowercase__	:						int    ,			)						->Union[str, Any]:

							"""simple docstring"""



							_lowercase							=     FunnelForMaskedLM(config=lowercase__)
							model.to(lowercase__)
							model.eval()
							_lowercase							=     model(lowercase__    ,			attention_mask=lowercase__    ,			token_type_ids=lowercase__    ,			labels=lowercase__)
							self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.vocab_size))

						def 	_UpperCAmelCase							(		self	:						Dict    ,			lowercase__	:						Tuple    ,			lowercase__	:						Union[str, Any]    ,			lowercase__	:						Any    ,			lowercase__	:						List[str]    ,			lowercase__	:						Optional[Any]    ,			lowercase__	:						Tuple    ,			lowercase__	:						List[Any]    ,			lowercase__	:						List[Any]    ,			)						->List[Any]:

							"""simple docstring"""



							_lowercase							=     self.num_labels
							_lowercase							=     FunnelForSequenceClassification(lowercase__)
							model.to(lowercase__)
							model.eval()
							_lowercase							=     model(lowercase__    ,			attention_mask=lowercase__    ,			token_type_ids=lowercase__    ,			labels=lowercase__)
							self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels))

						def 	_UpperCAmelCase							(		self	:						int    ,			lowercase__	:						Union[str, Any]    ,			lowercase__	:						str    ,			lowercase__	:						Dict    ,			lowercase__	:						List[str]    ,			lowercase__	:						Optional[Any]    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Any    ,			lowercase__	:						int    ,			)						->int:

							"""simple docstring"""



							_lowercase							=     self.num_choices
							_lowercase							=     FunnelForMultipleChoice(config=lowercase__)
							model.to(lowercase__)
							model.eval()
							_lowercase							=     input_ids.unsqueeze(1).expand(-1    ,			self.num_choices    ,			-1).contiguous()
							_lowercase							=     token_type_ids.unsqueeze(1).expand(-1    ,			self.num_choices    ,			-1).contiguous()
							_lowercase							=     input_mask.unsqueeze(1).expand(-1    ,			self.num_choices    ,			-1).contiguous()
							_lowercase							=     model(
							    lowercase__    ,			attention_mask=lowercase__    ,			token_type_ids=lowercase__    ,			labels=lowercase__    ,			)
							self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_choices))

						def 	_UpperCAmelCase							(		self	:						Optional[Any]    ,			lowercase__	:						List[str]    ,			lowercase__	:						Any    ,			lowercase__	:						List[str]    ,			lowercase__	:						Union[str, Any]    ,			lowercase__	:						Dict    ,			lowercase__	:						Optional[Any]    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Tuple    ,			)						->Optional[int]:

							"""simple docstring"""



							_lowercase							=     self.num_labels
							_lowercase							=     FunnelForTokenClassification(config=lowercase__)
							model.to(lowercase__)
							model.eval()
							_lowercase							=     model(lowercase__    ,			attention_mask=lowercase__    ,			token_type_ids=lowercase__    ,			labels=lowercase__)
							self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.num_labels))

						def 	_UpperCAmelCase							(		self	:						Tuple    ,			lowercase__	:						str    ,			lowercase__	:						Any    ,			lowercase__	:						Optional[Any]    ,			lowercase__	:						List[str]    ,			lowercase__	:						str    ,			lowercase__	:						List[str]    ,			lowercase__	:						str    ,			lowercase__	:						Union[str, Any]    ,			)						->Any:

							"""simple docstring"""



							_lowercase							=     FunnelForQuestionAnswering(config=lowercase__)
							model.to(lowercase__)
							model.eval()
							_lowercase							=     model(
							    lowercase__    ,			attention_mask=lowercase__    ,			token_type_ids=lowercase__    ,			start_positions=lowercase__    ,			end_positions=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))


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

							"""simple docstring"""



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






@require_torch
class 					__a   (		_snake_case							,_snake_case							,unittest.TestCase  ):
						__SCREAMING_SNAKE_CASE     :					List[Any]  =      False
						__SCREAMING_SNAKE_CASE     :					List[str]  =      False
						__SCREAMING_SNAKE_CASE     :					Optional[int]  =      (
						    (
						        FunnelModel,
						        FunnelForMaskedLM,
						        FunnelForPreTraining,
						        FunnelForQuestionAnswering,
						        FunnelForTokenClassification,
						    )
						    if is_torch_available()
						    else ()
						)
						__SCREAMING_SNAKE_CASE     :					int  =      (
						    {
						        'feature-extraction': (FunnelBaseModel, FunnelModel),
						        'fill-mask': FunnelForMaskedLM,
						        'question-answering': FunnelForQuestionAnswering,
						        'text-classification': FunnelForSequenceClassification,
						        'token-classification': FunnelForTokenClassification,
						        'zero-shot': FunnelForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)

						def 	_UpperCAmelCase							(		self	:						Optional[int]    ,			lowercase__	:						Optional[int]    ,			lowercase__	:						List[Any]    ,			lowercase__	:						int=False)						->str:

							"""simple docstring"""



							_lowercase							=     super()._prepare_for_class(lowercase__    ,			lowercase__    ,			return_labels=lowercase__)

							if return_labels:
								if model_class in get_values(lowercase__):
									_lowercase							=     torch.zeros(
									    (self.model_tester.batch_size, self.model_tester.seq_length)    ,			dtype=torch.long    ,			device=lowercase__)
							return inputs_dict

						def 	_UpperCAmelCase							(		self	:						Optional[Any])						->int:

							"""simple docstring"""



							_lowercase							=     FunnelModelTester(self)
							_lowercase							=     ConfigTester(self    ,			config_class=lowercase__)

						def 	_UpperCAmelCase							(		self	:						Any)						->str:

							"""simple docstring"""



							self.config_tester.run_common_tests()

						def 	_UpperCAmelCase							(		self	:						Dict)						->Optional[int]:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowercase__)

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

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*lowercase__)

						def 	_UpperCAmelCase							(		self	:						List[Any])						->Optional[int]:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*lowercase__)

						def 	_UpperCAmelCase							(		self	:						Tuple)						->Tuple:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*lowercase__)

						def 	_UpperCAmelCase							(		self	:						List[str])						->Optional[Any]:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*lowercase__)


						def 	_UpperCAmelCase							(		self	:						Any    ,			lowercase__	:						Optional[Any])						->Optional[Any]:

							"""simple docstring"""



							if hasattr(lowercase__    ,			"""weight""") and module.weight is not None:
								module.weight.data.fill_(3)
							if hasattr(lowercase__    ,			"""bias""") and module.bias is not None:
								module.bias.data.fill_(3)

							for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
								if hasattr(lowercase__    ,			lowercase__) and getattr(lowercase__    ,			lowercase__) is not None:
									_lowercase							=     getattr(lowercase__    ,			lowercase__)
									weight.data.fill_(3)






@require_torch
class 					__a   (		_snake_case							,unittest.TestCase  ):
						__SCREAMING_SNAKE_CASE     :					str  =      False
						__SCREAMING_SNAKE_CASE     :					Dict  =      False
						__SCREAMING_SNAKE_CASE     :					int  =      (
						    (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
						)

						def 	_UpperCAmelCase							(		self	:						Optional[Any])						->List[str]:

							"""simple docstring"""



							_lowercase							=     FunnelModelTester(self    ,			base=lowercase__)
							_lowercase							=     ConfigTester(self    ,			config_class=lowercase__)

						def 	_UpperCAmelCase							(		self	:						Any)						->Tuple:

							"""simple docstring"""



							self.config_tester.run_common_tests()

						def 	_UpperCAmelCase							(		self	:						str)						->Dict:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_base_model(*lowercase__)

						def 	_UpperCAmelCase							(		self	:						Tuple)						->Any:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*lowercase__)

						def 	_UpperCAmelCase							(		self	:						List[str])						->Tuple:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*lowercase__)

						def 	_UpperCAmelCase							(		self	:						Dict)						->Optional[int]:

							"""simple docstring"""



							_lowercase		,		_lowercase							=     self.model_tester.prepare_config_and_inputs_for_common()
							_lowercase							=     True

							for model_class in self.all_model_classes:
								if model_class.__name__ == "FunnelBaseModel":
									continue
								_lowercase							=     model_class(lowercase__)
								model.to(lowercase__)
								model.train()
								_lowercase							=     self._prepare_for_class(lowercase__    ,			lowercase__    ,			return_labels=lowercase__)
								_lowercase							=     model(**lowercase__).loss
								loss.backward()


						def 	_UpperCAmelCase							(		self	:						List[str]    ,			lowercase__	:						int)						->Optional[Any]:

							"""simple docstring"""



							if hasattr(lowercase__    ,			"""weight""") and module.weight is not None:
								module.weight.data.fill_(3)
							if hasattr(lowercase__    ,			"""bias""") and module.bias is not None:
								module.bias.data.fill_(3)

							for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
								if hasattr(lowercase__    ,			lowercase__) and getattr(lowercase__    ,			lowercase__) is not None:
									_lowercase							=     getattr(lowercase__    ,			lowercase__)
									weight.data.fill_(3)






@require_torch
@require_sentencepiece
@require_tokenizers
class 					__a   (		unittest.TestCase  ):

						def 	_UpperCAmelCase							(		self	:						Tuple)						->Dict:

							"""simple docstring"""



							_lowercase							=     13
							_lowercase							=     7
							_lowercase							=     torch.arange(0    ,			batch_size * sequence_length).long().reshape(lowercase__    ,			lowercase__)
							_lowercase							=     [0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
							_lowercase							=     torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths])

							_lowercase							=     FunnelModel.from_pretrained("""sgugger/funnel-random-tiny""")
							_lowercase							=     model(lowercase__    ,			token_type_ids=lowercase__)[0].abs()

							_lowercase							=     torch.tensor(2344.8352)
							_lowercase							=     torch.tensor(0.8052)
							self.assertTrue(torch.allclose(output.sum()    ,			lowercase__    ,			atol=1e-4))
							self.assertTrue(torch.allclose(output.mean()    ,			lowercase__    ,			atol=1e-4))

							_lowercase							=     torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]])
							_lowercase							=     model(lowercase__    ,			attention_mask=lowercase__    ,			token_type_ids=lowercase__)[0].abs()

							_lowercase							=     torch.tensor(2343.8425)
							_lowercase							=     torch.tensor(0.8049)
							self.assertTrue(torch.allclose(output.sum()    ,			lowercase__    ,			atol=1e-4))
							self.assertTrue(torch.allclose(output.mean()    ,			lowercase__    ,			atol=1e-4))


						@slow
						def 	_UpperCAmelCase							(		self	:						Optional[int])						->Tuple:

							"""simple docstring"""



							_lowercase							=     FunnelTokenizer.from_pretrained("""huggingface/funnel-small""")
							_lowercase							=     FunnelModel.from_pretrained("""huggingface/funnel-small""")
							_lowercase							=     tokenizer("""Hello! I am the Funnel Transformer model."""    ,			return_tensors="""pt""")
							_lowercase							=     model(**lowercase__)[0]

							_lowercase							=     torch.tensor(235.7246)
							_lowercase							=     torch.tensor(0.0256)
							self.assertTrue(torch.allclose(output.sum()    ,			lowercase__    ,			atol=1e-4))
							self.assertTrue(torch.allclose(output.mean()    ,			lowercase__    ,			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 					_SCREAMING_SNAKE_CASE		(						):
	_lowercase							=     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"]:
		_lowercase							=     getattr(transformers.models.auto							,       snake_case_							,       snake_case_	)
		if module is None:
			continue
		# all mappings in a single auto modeling file
		_lowercase							=     [
		    x
		    for x in dir(snake_case_	)
		    if x.endswith("""_MAPPING_NAMES"""	)
		    and (x.startswith("""MODEL_"""	) or x.startswith("""TF_MODEL_"""	) or x.startswith("""FLAX_MODEL_"""	))
		]
		for name in mapping_names:
			_lowercase							=     getattr(snake_case_							,       snake_case_	)
			if mapping is not None:
				for v in mapping.values():
					if isinstance(snake_case_							,       (list, tuple)	):
						model_names.update(snake_case_	)
					elif isinstance(snake_case_							,       snake_case_	):
						model_names.add(snake_case_	)

	return sorted(snake_case_	)






def 					_SCREAMING_SNAKE_CASE		(						):
	# All model names defined in auto mappings
	_lowercase							=     set(get_all_model_names()	)

	with open("""tests/utils/tiny_model_summary.json"""	) as fp:
		_lowercase							=     json.load(snake_case_	)
	_lowercase							=     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.
	_lowercase							=     model_names.difference(snake_case_	)
	for model_name in copy.copy(snake_case_	):
		if not model_name.startswith("""TF"""	) and F"""TF{model_name}""" in not_on_hub:
			tiny_models_names.remove(snake_case_	)
		elif model_name.startswith("""TF"""	) and model_name[2:] in not_on_hub:
			tiny_models_names.remove(snake_case_	)

	return sorted(snake_case_	)






def 					_SCREAMING_SNAKE_CASE		(						snake_case_	):
	_lowercase							=     COMPOSITE_MODELS.values()

	# All tiny model base names on Hub
	_lowercase							=     get_all_model_names()
	_lowercase							=     hf_api.list_models(
	    filter=ModelFilter(
	        author="""hf-internal-testing"""							,       )	)
	_lowercase							=     set()
	for x in models:
		_lowercase							=     x.modelId
		_lowercase		,		_lowercase							=     model.split("""/"""	)
		if not model.startswith("""tiny-random-"""	):
			continue
		_lowercase							=     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(snake_case_	)

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

		_lowercase							=     sorted(content["""tokenizer_classes"""]	)
		_lowercase							=     sorted(content["""processor_classes"""]	)
		_lowercase							=     sorted(content["""model_classes"""]	)

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


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

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

							_lowerCamelCase    =  'tiny_models'
							_lowerCamelCase    =  True
							_lowerCamelCase    =  None
							_lowerCamelCase    =  get_tiny_model_names_from_repo()
							_lowerCamelCase    =  True
							_lowerCamelCase    =  True
							_lowerCamelCase    =  '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,
							)




