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







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







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		List[str]	   =     ids_tensor([self.batch_size, self.seq_length]						,   self.vocab_size		)

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

				__magic_name__		:		Tuple	   =     None
				__magic_name__		:		int	   =     None
				__magic_name__		:		Dict	   =     None
				if self.use_labels:
					__magic_name__		:		Optional[Any]	   =     ids_tensor([self.batch_size]						,   self.type_sequence_label_size		)
					__magic_name__		:		Optional[Any]	   =     ids_tensor([self.batch_size, self.seq_length]						,   self.num_labels		)
					__magic_name__		:		int	   =     ids_tensor([self.batch_size]						,   self.num_choices		)

				__magic_name__		:		Optional[Any]	   =     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 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a						,   _a						,   _a						,   _a						,   _a		):
				__magic_name__		:		Optional[Any]	   =     TFDistilBertModel(config=_a		)
				__magic_name__		:		Dict	   =     {"input_ids": input_ids, "attention_mask": input_mask}

				__magic_name__		:		str	   =     model(_a		)

				__magic_name__		:		List[str]	   =     [input_ids, input_mask]

				__magic_name__		:		Dict	   =     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		):
				__magic_name__		:		List[str]	   =     TFDistilBertForMaskedLM(config=_a		)
				__magic_name__		:		Any	   =     {"input_ids": input_ids, "attention_mask": input_mask}
				__magic_name__		:		List[str]	   =     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		):
				__magic_name__		:		str	   =     TFDistilBertForQuestionAnswering(config=_a		)
				__magic_name__		:		Optional[Any]	   =     {
				    "input_ids": input_ids,
				    "attention_mask": input_mask,
				}
				__magic_name__		:		str	   =     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						,   _a						,   _a						,   _a						,   _a						,   _a						,   _a		):
				__magic_name__		:		List[str]	   =     self.num_labels
				__magic_name__		:		List[Any]	   =     TFDistilBertForSequenceClassification(_a		)
				__magic_name__		:		Optional[Any]	   =     {"input_ids": input_ids, "attention_mask": input_mask}
				__magic_name__		:		int	   =     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		):
				__magic_name__		:		List[Any]	   =     self.num_choices
				__magic_name__		:		int	   =     TFDistilBertForMultipleChoice(_a		)
				__magic_name__		:		int	   =     tf.tile(tf.expand_dims(_a						,   1		)						,   (1, self.num_choices, 1)		)
				__magic_name__		:		Optional[int]	   =     tf.tile(tf.expand_dims(_a						,   1		)						,   (1, self.num_choices, 1)		)
				__magic_name__		:		Optional[int]	   =     {
				    "input_ids": multiple_choice_inputs_ids,
				    "attention_mask": multiple_choice_input_mask,
				}
				__magic_name__		:		Optional[Any]	   =     model(_a		)
				self.parent.assertEqual(result.logits.shape						,   (self.batch_size, self.num_choices)		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a						,   _a						,   _a						,   _a						,   _a		):
				__magic_name__		:		Dict	   =     self.num_labels
				__magic_name__		:		List[str]	   =     TFDistilBertForTokenClassification(_a		)
				__magic_name__		:		int	   =     {"input_ids": input_ids, "attention_mask": input_mask}
				__magic_name__		:		List[str]	   =     model(_a		)
				self.parent.assertEqual(result.logits.shape						,   (self.batch_size, self.seq_length, self.num_labels)		)







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		List[str]	   =     self.prepare_config_and_inputs()
				((__magic_name__)   ,    (__magic_name__)   ,    (__magic_name__)   ,    (__magic_name__)   ,    (__magic_name__)   ,    (__magic_name__))		:		int	   =     config_and_inputs
				__magic_name__		:		str	   =     {"input_ids": input_ids, "attention_mask": input_mask}
				return config, inputs_dict







@require_tf
class       _snake_case					(     snake_case				,						snake_case				,						unittest.TestCase				):
			UpperCamelCase__          =    (
			    (
			        TFDistilBertModel,
			        TFDistilBertForMaskedLM,
			        TFDistilBertForQuestionAnswering,
			        TFDistilBertForSequenceClassification,
			        TFDistilBertForTokenClassification,
			        TFDistilBertForMultipleChoice,
			    )
			    if is_tf_available()
			    else None
			)
			UpperCamelCase__          =    (
			    {
			        'feature-extraction': TFDistilBertModel,
			        'fill-mask': TFDistilBertForMaskedLM,
			        'question-answering': TFDistilBertForQuestionAnswering,
			        'text-classification': TFDistilBertForSequenceClassification,
			        'token-classification': TFDistilBertForTokenClassification,
			        'zero-shot': TFDistilBertForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			UpperCamelCase__          =    False
			UpperCamelCase__          =    False







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		List[str]	   =     TFDistilBertModelTester(self		)
				__magic_name__		:		List[str]	   =     ConfigTester(self						,   config_class=_a						,   dim=37		)







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







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		Optional[int]	   =     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_model(*_a		)







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		int	   =     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_masked_lm(*_a		)







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		Dict	   =     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_question_answering(*_a		)







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		Optional[Any]	   =     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_sequence_classification(*_a		)







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		str	   =     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_multiple_choice(*_a		)







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		Any	   =     self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_token_classification(*_a		)







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







@require_tf
class       _snake_case					(     unittest.TestCase				):







			@slow
			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		Optional[Any]	   =     TFDistilBertModel.from_pretrained("distilbert-base-uncased"		)
				__magic_name__		:		Union[str, Any]	   =     tf.constant([[0, 1, 2, 3, 4, 5]]		)
				__magic_name__		:		List[Any]	   =     model(_a		)[0]

				__magic_name__		:		Optional[Any]	   =     [1, 6, 768]
				self.assertEqual(output.shape						,   _a		)

				__magic_name__		:		List[str]	   =     tf.constant(
				    [
				        [
				            [0.19_26_18_85, -0.13_73_29_55, 0.4_11_97_99],
				            [0.22_15_01_56, -0.07_42_26_61, 0.39_03_72_04],
				            [0.22_75_60_18, -0.0_89_64_14, 0.3_70_14_67],
				        ]
				    ]		)
				tf.debugging.assert_near(output[:, :3, :3]						,   _a						,   atol=1e-4		)


from . import __version__

# Backward compatibility imports, to make sure all those objects can be found in file_utils
from .utils import (
    CLOUDFRONT_DISTRIB_PREFIX,
    CONFIG_NAME,
    DISABLE_TELEMETRY,
    DUMMY_INPUTS,
    DUMMY_MASK,
    ENV_VARS_TRUE_AND_AUTO_VALUES,
    ENV_VARS_TRUE_VALUES,
    FEATURE_EXTRACTOR_NAME,
    FLAX_WEIGHTS_NAME,
    HF_MODULES_CACHE,
    HUGGINGFACE_CO_PREFIX,
    HUGGINGFACE_CO_RESOLVE_ENDPOINT,
    MODEL_CARD_NAME,
    MULTIPLE_CHOICE_DUMMY_INPUTS,
    PYTORCH_PRETRAINED_BERT_CACHE,
    PYTORCH_TRANSFORMERS_CACHE,
    S3_BUCKET_PREFIX,
    SENTENCEPIECE_UNDERLINE,
    SPIECE_UNDERLINE,
    TF2_WEIGHTS_NAME,
    TF_WEIGHTS_NAME,
    TORCH_FX_REQUIRED_VERSION,
    TRANSFORMERS_CACHE,
    TRANSFORMERS_DYNAMIC_MODULE_NAME,
    USE_JAX,
    USE_TF,
    USE_TORCH,
    WEIGHTS_INDEX_NAME,
    WEIGHTS_NAME,
    ContextManagers,
    DummyObject,
    EntryNotFoundError,
    ExplicitEnum,
    ModelOutput,
    PaddingStrategy,
    PushToHubMixin,
    RepositoryNotFoundError,
    RevisionNotFoundError,
    TensorType,
    _LazyModule,
    add_code_sample_docstrings,
    add_end_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    cached_property,
    copy_func,
    default_cache_path,
    define_sagemaker_information,
    get_cached_models,
    get_file_from_repo,
    get_full_repo_name,
    get_torch_version,
    has_file,
    http_user_agent,
    is_apex_available,
    is_bsa_available,
    is_coloredlogs_available,
    is_datasets_available,
    is_detectrona_available,
    is_faiss_available,
    is_flax_available,
    is_ftfy_available,
    is_in_notebook,
    is_ipex_available,
    is_librosa_available,
    is_offline_mode,
    is_onnx_available,
    is_pandas_available,
    is_phonemizer_available,
    is_protobuf_available,
    is_psutil_available,
    is_pyanvml_available,
    is_pyctcdecode_available,
    is_pytesseract_available,
    is_pytorch_quantization_available,
    is_rjieba_available,
    is_sagemaker_dp_enabled,
    is_sagemaker_mp_enabled,
    is_scipy_available,
    is_sentencepiece_available,
    is_seqio_available,
    is_sklearn_available,
    is_soundfile_availble,
    is_spacy_available,
    is_speech_available,
    is_tensor,
    is_tensorflow_probability_available,
    is_tfaonnx_available,
    is_tf_available,
    is_timm_available,
    is_tokenizers_available,
    is_torch_available,
    is_torch_bfaa_available,
    is_torch_cuda_available,
    is_torch_fx_available,
    is_torch_fx_proxy,
    is_torch_mps_available,
    is_torch_tfaa_available,
    is_torch_tpu_available,
    is_torchaudio_available,
    is_training_run_on_sagemaker,
    is_vision_available,
    replace_return_docstrings,
    requires_backends,
    to_numpy,
    to_py_obj,
    torch_only_method,
)
