



"""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  :    List[str]      ,							snake_case  :    Any      ,							)			->						Dict:






									'''simple docstring'''

									A         =					parent
									A         =					13
									A         =					7
									A         =					True
									A         =					True
									A         =					False
									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



		def 					A_		( self  :    Any				)			->						List[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
									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         =					ids_tensor([self.batch_size]      ,							self.num_choices				)

									A         =					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  :    str      ,							snake_case  :    int      ,							snake_case  :    Optional[Any]      ,							snake_case  :    str      ,							snake_case  :    Dict      ,							snake_case  :    Optional[Any]      ,							snake_case  :    Optional[Any]				)			->						int:






									'''simple docstring'''

									A         =					TFDistilBertModel(config=snake_case				)
									A         =					{'input_ids': input_ids, 'attention_mask': input_mask}

									A         =					model(snake_case				)

									A         =					[input_ids, input_mask]

									A         =					model(snake_case				)

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



		def 					A_		( self  :    List[str]      ,							snake_case  :    List[Any]      ,							snake_case  :    Any      ,							snake_case  :    int      ,							snake_case  :    str      ,							snake_case  :    List[Any]      ,							snake_case  :    Optional[Any]				)			->						Any:






									'''simple docstring'''

									A         =					TFDistilBertForMaskedLM(config=snake_case				)
									A         =					{'input_ids': input_ids, 'attention_mask': input_mask}
									A         =					model(snake_case				)
									self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.seq_length, self.vocab_size)				)



		def 					A_		( self  :    Dict      ,							snake_case  :    int      ,							snake_case  :    List[str]      ,							snake_case  :    Union[str, Any]      ,							snake_case  :    str      ,							snake_case  :    str      ,							snake_case  :    Dict				)			->						int:






									'''simple docstring'''

									A         =					TFDistilBertForQuestionAnswering(config=snake_case				)
									A         =					{
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									}
									A         =					model(snake_case				)
									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  :    Optional[int]      ,							snake_case  :    int      ,							snake_case  :    int      ,							snake_case  :    Union[str, Any]      ,							snake_case  :    List[Any]      ,							snake_case  :    Dict      ,							snake_case  :    Dict				)			->						Optional[Any]:






									'''simple docstring'''

									A         =					self.num_labels
									A         =					TFDistilBertForSequenceClassification(snake_case				)
									A         =					{'input_ids': input_ids, 'attention_mask': input_mask}
									A         =					model(snake_case				)
									self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.num_labels)				)



		def 					A_		( self  :    Union[str, Any]      ,							snake_case  :    List[Any]      ,							snake_case  :    int      ,							snake_case  :    List[Any]      ,							snake_case  :    Optional[int]      ,							snake_case  :    Optional[Any]      ,							snake_case  :    int				)			->						Union[str, Any]:






									'''simple docstring'''

									A         =					self.num_choices
									A         =					TFDistilBertForMultipleChoice(snake_case				)
									A         =					tf.tile(tf.expand_dims(snake_case      ,							1				)      ,							(1, self.num_choices, 1)				)
									A         =					tf.tile(tf.expand_dims(snake_case      ,							1				)      ,							(1, self.num_choices, 1)				)
									A         =					{
									    'input_ids': multiple_choice_inputs_ids,
									    'attention_mask': multiple_choice_input_mask,
									}
									A         =					model(snake_case				)
									self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.num_choices)				)



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






									'''simple docstring'''

									A         =					self.num_labels
									A         =					TFDistilBertForTokenClassification(snake_case				)
									A         =					{'input_ids': input_ids, 'attention_mask': input_mask}
									A         =					model(snake_case				)
									self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.seq_length, self.num_labels)				)



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






									'''simple docstring'''

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






@require_tf
class      UpperCAmelCase__		(      UpperCamelCase   ,UpperCamelCase   ,unittest.TestCase     ):
		lowerCAmelCase_       :	str 							=     (
		    (
		        TFDistilBertModel,
		        TFDistilBertForMaskedLM,
		        TFDistilBertForQuestionAnswering,
		        TFDistilBertForSequenceClassification,
		        TFDistilBertForTokenClassification,
		        TFDistilBertForMultipleChoice,
		    )
		    if is_tf_available()
		    else None
		)
		lowerCAmelCase_       :	Dict 							=     (
		    {
		        """feature-extraction""": TFDistilBertModel,
		        """fill-mask""": TFDistilBertForMaskedLM,
		        """question-answering""": TFDistilBertForQuestionAnswering,
		        """text-classification""": TFDistilBertForSequenceClassification,
		        """token-classification""": TFDistilBertForTokenClassification,
		        """zero-shot""": TFDistilBertForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)
		lowerCAmelCase_       :	Tuple 							=     False
		lowerCAmelCase_       :	List[str] 							=     False



		def 					A_		( self  :    Dict				)			->						int:






									'''simple docstring'''

									A         =					TFDistilBertModelTester(self				)
									A         =					ConfigTester(self      ,							config_class=snake_case      ,							dim=37				)



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






									'''simple docstring'''

									self.config_tester.run_common_tests()



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






									'''simple docstring'''

									A         =					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_model(*snake_case				)



		def 					A_		( self  :    List[str]				)			->						int:






									'''simple docstring'''

									A         =					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_masked_lm(*snake_case				)



		def 					A_		( self  :    List[Any]				)			->						Dict:






									'''simple docstring'''

									A         =					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_question_answering(*snake_case				)



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






									'''simple docstring'''

									A         =					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_sequence_classification(*snake_case				)



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






									'''simple docstring'''

									A         =					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_multiple_choice(*snake_case				)



		def 					A_		( self  :    List[str]				)			->						Optional[int]:






									'''simple docstring'''

									A         =					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_token_classification(*snake_case				)



		@slow
		def 					A_		( self  :    int				)			->						List[Any]:






									'''simple docstring'''

									for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]				):
																A         =					TFDistilBertModel.from_pretrained(snake_case				)
																self.assertIsNotNone(snake_case				)






@require_tf
class      UpperCAmelCase__		(      unittest.TestCase     ):



		@slow
		def 					A_		( self  :    List[Any]				)			->						Any:






									'''simple docstring'''

									A         =					TFDistilBertModel.from_pretrained('distilbert-base-uncased'				)
									A         =					tf.constant([[0, 1, 2, 3, 4, 5]]				)
									A         =					model(snake_case				)[0]

									A         =					[1, 6, 768]
									self.assertEqual(output.shape      ,							snake_case				)

									A         =					tf.constant(
									    [
									        [
									            [0.19261885, -0.13732955, 0.4119799],
									            [0.22150156, -0.07422661, 0.39037204],
									            [0.22756018, -0.0896414, 0.3701467],
									        ]
									    ]				)
									tf.debugging.assert_near(output[:, :3, :3]      ,							snake_case      ,							atol=1E-4				)








"""simple docstring"""







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_torch_available


A    =			{
    'configuration_gpt_neo': ['GPT_NEO_PRETRAINED_CONFIG_ARCHIVE_MAP', 'GPTNeoConfig', 'GPTNeoOnnxConfig'],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							A    =			[
							    'GPT_NEO_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'GPTNeoForCausalLM',
							    'GPTNeoForQuestionAnswering',
							    'GPTNeoForSequenceClassification',
							    'GPTNeoForTokenClassification',
							    'GPTNeoModel',
							    'GPTNeoPreTrainedModel',
							    'load_tf_weights_in_gpt_neo',
							]

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							A    =			[
							    'FlaxGPTNeoForCausalLM',
							    'FlaxGPTNeoModel',
							    'FlaxGPTNeoPreTrainedModel',
							]


if TYPE_CHECKING:
							from .configuration_gpt_neo import GPT_NEO_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTNeoConfig, GPTNeoOnnxConfig

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_gpt_neo import (
														    GPT_NEO_PRETRAINED_MODEL_ARCHIVE_LIST,
														    GPTNeoForCausalLM,
														    GPTNeoForQuestionAnswering,
														    GPTNeoForSequenceClassification,
														    GPTNeoForTokenClassification,
														    GPTNeoModel,
														    GPTNeoPreTrainedModel,
														    load_tf_weights_in_gpt_neo,
														)

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_gpt_neo import FlaxGPTNeoForCausalLM, FlaxGPTNeoModel, FlaxGPTNeoPreTrainedModel


else:
							import sys

							A    =			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



