

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







			'''simple docstring'''

			def __init__(	self					:							Optional[int]				,  _UpperCamelCase					:							int				,  ) ->Tuple:
									snake_case_  =      parent
									snake_case_  =      1_3
									snake_case_  =      7
									snake_case_  =      True
									snake_case_  =      True
									snake_case_  =      False
									snake_case_  =      True
									snake_case_  =      9_9
									snake_case_  =      3_2
									snake_case_  =      2
									snake_case_  =      4
									snake_case_  =      3_7
									snake_case_  =      '''gelu'''
									snake_case_  =      0.1
									snake_case_  =      0.1
									snake_case_  =      5_1_2
									snake_case_  =      1_6
									snake_case_  =      2
									snake_case_  =      0.02
									snake_case_  =      3
									snake_case_  =      4
									snake_case_  =      None







			def 							snake_case__(	self					:							Optional[Any]				) ->Any:
									snake_case_  =      ids_tensor([self.batch_size, self.seq_length]				,  self.vocab_size				)

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

									snake_case_  =      None
									snake_case_  =      None
									snake_case_  =      None
									if self.use_labels:
															snake_case_  =      ids_tensor([self.batch_size]				,  self.type_sequence_label_size				)
															snake_case_  =      ids_tensor([self.batch_size, self.seq_length]				,  self.num_labels				)
															snake_case_  =      ids_tensor([self.batch_size]				,  self.num_choices				)

									snake_case_  =      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 							snake_case__(	self					:							List[str]				,  _UpperCamelCase					:							Optional[int]				,  _UpperCamelCase					:							Any				,  _UpperCamelCase					:							List[str]				,  _UpperCamelCase					:							List[Any]				,  _UpperCamelCase					:							int				,  _UpperCamelCase					:							Any				) ->List[str]:
									snake_case_  =      TFDistilBertModel(config=_UpperCamelCase				)
									snake_case_  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask}

									snake_case_  =      model(_UpperCamelCase				)

									snake_case_  =      [input_ids, input_mask]

									snake_case_  =      model(_UpperCamelCase				)

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







			def 							snake_case__(	self					:							Any				,  _UpperCamelCase					:							Tuple				,  _UpperCamelCase					:							Any				,  _UpperCamelCase					:							Dict				,  _UpperCamelCase					:							Optional[int]				,  _UpperCamelCase					:							Union[str, Any]				,  _UpperCamelCase					:							str				) ->str:
									snake_case_  =      TFDistilBertForMaskedLM(config=_UpperCamelCase				)
									snake_case_  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask}
									snake_case_  =      model(_UpperCamelCase				)
									self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.vocab_size)				)







			def 							snake_case__(	self					:							Union[str, Any]				,  _UpperCamelCase					:							Tuple				,  _UpperCamelCase					:							Tuple				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							int				,  _UpperCamelCase					:							Union[str, Any]				,  _UpperCamelCase					:							Tuple				) ->Optional[int]:
									snake_case_  =      TFDistilBertForQuestionAnswering(config=_UpperCamelCase				)
									snake_case_  =      {
									    '''input_ids''': input_ids,
									    '''attention_mask''': input_mask,
									}
									snake_case_  =      model(_UpperCamelCase				)
									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 							snake_case__(	self					:							Dict				,  _UpperCamelCase					:							Tuple				,  _UpperCamelCase					:							List[str]				,  _UpperCamelCase					:							List[str]				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							Tuple				) ->str:
									snake_case_  =      self.num_labels
									snake_case_  =      TFDistilBertForSequenceClassification(_UpperCamelCase				)
									snake_case_  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask}
									snake_case_  =      model(_UpperCamelCase				)
									self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.num_labels)				)







			def 							snake_case__(	self					:							Union[str, Any]				,  _UpperCamelCase					:							int				,  _UpperCamelCase					:							Optional[int]				,  _UpperCamelCase					:							Tuple				,  _UpperCamelCase					:							str				,  _UpperCamelCase					:							Optional[int]				,  _UpperCamelCase					:							Optional[int]				) ->Optional[Any]:
									snake_case_  =      self.num_choices
									snake_case_  =      TFDistilBertForMultipleChoice(_UpperCamelCase				)
									snake_case_  =      tf.tile(tf.expand_dims(_UpperCamelCase				,  1				)				,  (1, self.num_choices, 1)				)
									snake_case_  =      tf.tile(tf.expand_dims(_UpperCamelCase				,  1				)				,  (1, self.num_choices, 1)				)
									snake_case_  =      {
									    '''input_ids''': multiple_choice_inputs_ids,
									    '''attention_mask''': multiple_choice_input_mask,
									}
									snake_case_  =      model(_UpperCamelCase				)
									self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.num_choices)				)







			def 							snake_case__(	self					:							Tuple				,  _UpperCamelCase					:							Optional[Any]				,  _UpperCamelCase					:							List[str]				,  _UpperCamelCase					:							Union[str, Any]				,  _UpperCamelCase					:							Optional[int]				,  _UpperCamelCase					:							Union[str, Any]				,  _UpperCamelCase					:							Any				) ->Optional[Any]:
									snake_case_  =      self.num_labels
									snake_case_  =      TFDistilBertForTokenClassification(_UpperCamelCase				)
									snake_case_  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask}
									snake_case_  =      model(_UpperCamelCase				)
									self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.num_labels)				)







			def 							snake_case__(	self					:							Union[str, Any]				) ->int:
									snake_case_  =      self.prepare_config_and_inputs()
									((snake_case_),       (snake_case_),       (snake_case_),       (snake_case_),       (snake_case_),       (snake_case_))  =      config_and_inputs
									snake_case_  =      {'''input_ids''': input_ids, '''attention_mask''': input_mask}
									return config, inputs_dict






@require_tf
class       snake_case_  (						__A      ,			__A      ,			unittest.TestCase   ):







			'''simple docstring'''

			SCREAMING_SNAKE_CASE	:  int		     =							(
			    (
			        TFDistilBertModel,
			        TFDistilBertForMaskedLM,
			        TFDistilBertForQuestionAnswering,
			        TFDistilBertForSequenceClassification,
			        TFDistilBertForTokenClassification,
			        TFDistilBertForMultipleChoice,
			    )
			    if is_tf_available()
			    else None
			)
			SCREAMING_SNAKE_CASE	:  List[Any]		     =							(
			    {
			        "feature-extraction": TFDistilBertModel,
			        "fill-mask": TFDistilBertForMaskedLM,
			        "question-answering": TFDistilBertForQuestionAnswering,
			        "text-classification": TFDistilBertForSequenceClassification,
			        "token-classification": TFDistilBertForTokenClassification,
			        "zero-shot": TFDistilBertForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			SCREAMING_SNAKE_CASE	:  Dict		     =							False
			SCREAMING_SNAKE_CASE	:  Optional[Any]		     =							False







			def 							snake_case__(	self					:							Optional[int]				) ->Dict:
									snake_case_  =      TFDistilBertModelTester(self				)
									snake_case_  =      ConfigTester(self				,  config_class=_UpperCamelCase				,  dim=3_7				)







			def 							snake_case__(	self					:							str				) ->Union[str, Any]:
									self.config_tester.run_common_tests()







			def 							snake_case__(	self					:							Tuple				) ->Union[str, Any]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_model(*_UpperCamelCase				)







			def 							snake_case__(	self					:							str				) ->List[Any]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_masked_lm(*_UpperCamelCase				)







			def 							snake_case__(	self					:							Optional[Any]				) ->List[Any]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_question_answering(*_UpperCamelCase				)







			def 							snake_case__(	self					:							Tuple				) ->str:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_sequence_classification(*_UpperCamelCase				)







			def 							snake_case__(	self					:							Tuple				) ->Optional[Any]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_multiple_choice(*_UpperCamelCase				)







			def 							snake_case__(	self					:							Optional[int]				) ->List[str]:
									snake_case_  =      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_distilbert_for_token_classification(*_UpperCamelCase				)







			@slow
			def 							snake_case__(	self					:							List[str]				) ->Union[str, Any]:
									for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]				):
															snake_case_  =      TFDistilBertModel.from_pretrained(_UpperCamelCase				)
															self.assertIsNotNone(_UpperCamelCase				)






@require_tf
class       snake_case_  (						unittest.TestCase   ):







			'''simple docstring'''

			@slow
			def 							snake_case__(	self					:							Dict				) ->Optional[int]:
									snake_case_  =      TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''				)
									snake_case_  =      tf.constant([[0, 1, 2, 3, 4, 5]]				)
									snake_case_  =      model(_UpperCamelCase				)[0]

									snake_case_  =      [1, 6, 7_6_8]
									self.assertEqual(output.shape				,  _UpperCamelCase				)

									snake_case_  =      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]				,  _UpperCamelCase				,  atol=1e-4				)

"""simple docstring"""




from typing import TYPE_CHECKING

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


A__ :       List[str]				= {
    'configuration_biogpt': ['BIOGPT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'BioGptConfig'],
    'tokenization_biogpt': ['BioGptTokenizer'],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  A__ :       Dict				= [
      'BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST',
      'BioGptForCausalLM',
      'BioGptForTokenClassification',
      'BioGptForSequenceClassification',
      'BioGptModel',
      'BioGptPreTrainedModel',
  ]


if TYPE_CHECKING:
  from .configuration_biogpt import BIOGPT_PRETRAINED_CONFIG_ARCHIVE_MAP, BioGptConfig
  from .tokenization_biogpt import BioGptTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_biogpt import (
        BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST,
        BioGptForCausalLM,
        BioGptForSequenceClassification,
        BioGptForTokenClassification,
        BioGptModel,
        BioGptPreTrainedModel,
    )


else:
  import sys

  A__ :       int				= _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
