"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import DistilBertConfig, 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.models.distilbert.modeling_tf_distilbert import (
	    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
	    TFDistilBertForMaskedLM,
	    TFDistilBertForMultipleChoice,
	    TFDistilBertForQuestionAnswering,
	    TFDistilBertForSequenceClassification,
	    TFDistilBertForTokenClassification,
	    TFDistilBertModel,
	)






class   __UpperCAmelCase		:

				def __init__( self      ,					_lowerCamelCase      ,					):
										lowerCamelCase__   =parent
										lowerCamelCase__   =13
										lowerCamelCase__   =7
										lowerCamelCase__   =True
										lowerCamelCase__   =True
										lowerCamelCase__   =False
										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.0_2
										lowerCamelCase__   =3
										lowerCamelCase__   =4
										lowerCamelCase__   =None

				def 						_a      ( self ):
										lowerCamelCase__   =ids_tensor([self.batch_size, self.seq_length]      ,					self.vocab_size )

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

										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__   =DistilBertConfig(
										    vocab_size=self.vocab_size      ,					dim=self.hidden_size      ,					n_layers=self.num_hidden_layers      ,					n_heads=self.num_attention_heads      ,					hidden_dim=self.intermediate_size      ,					hidden_act=self.hidden_act      ,					dropout=self.hidden_dropout_prob      ,					attention_dropout=self.attention_probs_dropout_prob      ,					max_position_embeddings=self.max_position_embeddings      ,					initializer_range=self.initializer_range      ,					)

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

				def 						_a      ( self      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase ):
										lowerCamelCase__   =TFDistilBertModel(config=_lowerCamelCase )
										lowerCamelCase__   ={"input_ids": input_ids, "attention_mask": input_mask}

										lowerCamelCase__   =model(_lowerCamelCase )

										lowerCamelCase__   =[input_ids, input_mask]

										lowerCamelCase__   =model(_lowerCamelCase )

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

				def 						_a      ( self      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase ):
										lowerCamelCase__   =TFDistilBertForMaskedLM(config=_lowerCamelCase )
										lowerCamelCase__   ={"input_ids": input_ids, "attention_mask": input_mask}
										lowerCamelCase__   =model(_lowerCamelCase )
										self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.seq_length, self.vocab_size) )

				def 						_a      ( self      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase ):
										lowerCamelCase__   =TFDistilBertForQuestionAnswering(config=_lowerCamelCase )
										lowerCamelCase__   ={
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										}
										lowerCamelCase__   =model(_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) )

				def 						_a      ( self      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase ):
										lowerCamelCase__   =self.num_labels
										lowerCamelCase__   =TFDistilBertForSequenceClassification(_lowerCamelCase )
										lowerCamelCase__   ={"input_ids": input_ids, "attention_mask": input_mask}
										lowerCamelCase__   =model(_lowerCamelCase )
										self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.num_labels) )

				def 						_a      ( self      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase ):
										lowerCamelCase__   =self.num_choices
										lowerCamelCase__   =TFDistilBertForMultipleChoice(_lowerCamelCase )
										lowerCamelCase__   =tf.tile(tf.expand_dims(_lowerCamelCase      ,					1 )      ,					(1, self.num_choices, 1) )
										lowerCamelCase__   =tf.tile(tf.expand_dims(_lowerCamelCase      ,					1 )      ,					(1, self.num_choices, 1) )
										lowerCamelCase__   ={
										    "input_ids": multiple_choice_inputs_ids,
										    "attention_mask": multiple_choice_input_mask,
										}
										lowerCamelCase__   =model(_lowerCamelCase )
										self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.num_choices) )

				def 						_a      ( self      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase ):
										lowerCamelCase__   =self.num_labels
										lowerCamelCase__   =TFDistilBertForTokenClassification(_lowerCamelCase )
										lowerCamelCase__   ={"input_ids": input_ids, "attention_mask": input_mask}
										lowerCamelCase__   =model(_lowerCamelCase )
										self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.seq_length, self.num_labels) )






				def 						_a      ( self ):
										lowerCamelCase__   =self.prepare_config_and_inputs()
										((lowerCamelCase__)   , (lowerCamelCase__)   , (lowerCamelCase__)   , (lowerCamelCase__)   , (lowerCamelCase__)   , (lowerCamelCase__))   =config_and_inputs
										lowerCamelCase__   ={"input_ids": input_ids, "attention_mask": input_mask}
										return config, inputs_dict






@require_tf
class   __UpperCAmelCase		(      __lowerCAmelCase , __lowerCAmelCase , unittest.TestCase      ):
				A__ :  Any    				=			(
				    (
				        TFDistilBertModel,
				        TFDistilBertForMaskedLM,
				        TFDistilBertForQuestionAnswering,
				        TFDistilBertForSequenceClassification,
				        TFDistilBertForTokenClassification,
				        TFDistilBertForMultipleChoice,
				    )
				    if is_tf_available()
				    else None
				)
				A__ :  Any    				=			(
				    {
				        '''feature-extraction''': TFDistilBertModel,
				        '''fill-mask''': TFDistilBertForMaskedLM,
				        '''question-answering''': TFDistilBertForQuestionAnswering,
				        '''text-classification''': TFDistilBertForSequenceClassification,
				        '''token-classification''': TFDistilBertForTokenClassification,
				        '''zero-shot''': TFDistilBertForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				A__ :  Optional[int]    				=			False
				A__ :  Any    				=			False

				def 						_a      ( self ):
										lowerCamelCase__   =TFDistilBertModelTester(self )
										lowerCamelCase__   =ConfigTester(self      ,					config_class=_lowerCamelCase      ,					dim=37 )

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

				def 						_a      ( self ):
										lowerCamelCase__   =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_model(*_lowerCamelCase )

				def 						_a      ( self ):
										lowerCamelCase__   =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_masked_lm(*_lowerCamelCase )

				def 						_a      ( self ):
										lowerCamelCase__   =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_question_answering(*_lowerCamelCase )

				def 						_a      ( self ):
										lowerCamelCase__   =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_sequence_classification(*_lowerCamelCase )

				def 						_a      ( self ):
										lowerCamelCase__   =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_multiple_choice(*_lowerCamelCase )

				def 						_a      ( self ):
										lowerCamelCase__   =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_token_classification(*_lowerCamelCase )






				@slow
				def 						_a      ( self ):
										for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1] ):
																lowerCamelCase__   =TFDistilBertModel.from_pretrained(_lowerCamelCase )
																self.assertIsNotNone(_lowerCamelCase )






@require_tf
class   __UpperCAmelCase		(      unittest.TestCase      ):

				@slow
				def 						_a      ( self ):
										lowerCamelCase__   =TFDistilBertModel.from_pretrained("distilbert-base-uncased" )
										lowerCamelCase__   =tf.constant([[0, 1, 2, 3, 4, 5]] )
										lowerCamelCase__   =model(_lowerCamelCase )[0]

										lowerCamelCase__   =[1, 6, 768]
										self.assertEqual(output.shape      ,					_lowerCamelCase )

										lowerCamelCase__   =tf.constant(
										    [
										        [
										            [0.1_9_2_6_1_8_8_5, -0.1_3_7_3_2_9_5_5, 0.4_1_1_9_7_9_9],
										            [0.2_2_1_5_0_1_5_6, -0.0_7_4_2_2_6_6_1, 0.3_9_0_3_7_2_0_4],
										            [0.2_2_7_5_6_0_1_8, -0.0_8_9_6_4_1_4, 0.3_7_0_1_4_6_7],
										        ]
										    ] )
										tf.debugging.assert_near(output[:, :3, :3]      ,					_lowerCamelCase      ,					atol=1E-4 )



"""simple docstring"""


import fire

from transformers import AutoConfig, AutoModelForSeqaSeqLM, AutoTokenizer





def      lowerCamelCase_					(   __lowerCAmelCase  ,       __lowerCAmelCase  ,       **__lowerCAmelCase							)				->   List[str]:




						'''simple docstring'''



						lowerCamelCase__   =AutoConfig.from_pretrained(__lowerCAmelCase  ,       **__lowerCAmelCase							)
						lowerCamelCase__   =AutoModelForSeqaSeqLM.from_config(__lowerCAmelCase							)
						model.save_pretrained(__lowerCAmelCase							)
						AutoTokenizer.from_pretrained(__lowerCAmelCase							).save_pretrained(__lowerCAmelCase							)
						return model


if __name__ == "__main__":
	fire.Fire(save_randomly_initialized_version)


