





'''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 					SCREAMING_SNAKE_CASE       :


     def __init__(		self		,      _UpperCAmelCase		,      ):

          '''simple docstring'''






          __A		:					List[str]						=			parent
          __A		:					Optional[Any]						=			13
          __A		:					Tuple						=			7
          __A		:					List[Any]						=			True
          __A		:					int						=			True
          __A		:					int						=			False
          __A		:					Dict						=			True
          __A		:					List[str]						=			99
          __A		:					Optional[Any]						=			32
          __A		:					Dict						=			2
          __A		:					Optional[Any]						=			4
          __A		:					Tuple						=			37
          __A		:					List[str]						=			'gelu'
          __A		:					Optional[int]						=			0.1
          __A		:					Dict						=			0.1
          __A		:					List[str]						=			512
          __A		:					Optional[Any]						=			16
          __A		:					Optional[int]						=			2
          __A		:					Optional[int]						=			0.02
          __A		:					Dict						=			3
          __A		:					Dict						=			4
          __A		:					List[Any]						=			None


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Tuple						=			ids_tensor([self.batch_size, self.seq_length]		,      self.vocab_size)

          __A		:					int						=			None
          if self.use_input_mask:
               __A		:					Tuple						=			random_attention_mask([self.batch_size, self.seq_length])

          __A		:					Any						=			None
          __A		:					List[str]						=			None
          __A		:					Any						=			None
          if self.use_labels:
               __A		:					List[Any]						=			ids_tensor([self.batch_size]		,      self.type_sequence_label_size)
               __A		:					Dict						=			ids_tensor([self.batch_size, self.seq_length]		,      self.num_labels)
               __A		:					int						=			ids_tensor([self.batch_size]		,      self.num_choices)

          __A		:					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		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase):

          '''simple docstring'''






          __A		:					int						=			TFDistilBertModel(config=_UpperCAmelCase)
          __A		:					List[Any]						=			{'input_ids': input_ids, 'attention_mask': input_mask}

          __A		:					str						=			model(_UpperCAmelCase)

          __A		:					Any						=			[input_ids, input_mask]

          __A		:					Tuple						=			model(_UpperCAmelCase)

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


     def 				SCREAMING_SNAKE_CASE    (		self		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase):

          '''simple docstring'''






          __A		:					List[str]						=			TFDistilBertForMaskedLM(config=_UpperCAmelCase)
          __A		:					Union[str, Any]						=			{'input_ids': input_ids, 'attention_mask': input_mask}
          __A		:					Union[str, Any]						=			model(_UpperCAmelCase)
          self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.seq_length, self.vocab_size))


     def 				SCREAMING_SNAKE_CASE    (		self		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase):

          '''simple docstring'''






          __A		:					Optional[int]						=			TFDistilBertForQuestionAnswering(config=_UpperCAmelCase)
          __A		:					str						=			{
              'input_ids': input_ids,
              'attention_mask': input_mask,
          }
          __A		:					str						=			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 				SCREAMING_SNAKE_CASE    (		self		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase):

          '''simple docstring'''






          __A		:					Any						=			self.num_labels
          __A		:					Dict						=			TFDistilBertForSequenceClassification(_UpperCAmelCase)
          __A		:					Dict						=			{'input_ids': input_ids, 'attention_mask': input_mask}
          __A		:					Any						=			model(_UpperCAmelCase)
          self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_labels))


     def 				SCREAMING_SNAKE_CASE    (		self		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase):

          '''simple docstring'''






          __A		:					int						=			self.num_choices
          __A		:					List[str]						=			TFDistilBertForMultipleChoice(_UpperCAmelCase)
          __A		:					Optional[int]						=			tf.tile(tf.expand_dims(_UpperCAmelCase		,      1)		,      (1, self.num_choices, 1))
          __A		:					List[str]						=			tf.tile(tf.expand_dims(_UpperCAmelCase		,      1)		,      (1, self.num_choices, 1))
          __A		:					Any						=			{
              'input_ids': multiple_choice_inputs_ids,
              'attention_mask': multiple_choice_input_mask,
          }
          __A		:					Tuple						=			model(_UpperCAmelCase)
          self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_choices))


     def 				SCREAMING_SNAKE_CASE    (		self		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase):

          '''simple docstring'''






          __A		:					Tuple						=			self.num_labels
          __A		:					List[str]						=			TFDistilBertForTokenClassification(_UpperCAmelCase)
          __A		:					Tuple						=			{'input_ids': input_ids, 'attention_mask': input_mask}
          __A		:					str						=			model(_UpperCAmelCase)
          self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.seq_length, self.num_labels))


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					List[Any]						=			self.prepare_config_and_inputs()
          ((__A)					,(__A)					,(__A)					,(__A)					,(__A)					,(__A))		:					Optional[Any]						=			config_and_inputs
          __A		:					Optional[Any]						=			{'input_ids': input_ids, 'attention_mask': input_mask}
          return config, inputs_dict




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


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[int]						=			TFDistilBertModelTester(self)
          __A		:					Union[str, Any]						=			ConfigTester(self		,      config_class=_UpperCAmelCase		,      dim=37)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          self.config_tester.run_common_tests()


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Dict						=			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_distilbert_model(*_UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[int]						=			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_distilbert_for_masked_lm(*_UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Dict						=			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_distilbert_for_question_answering(*_UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Union[str, Any]						=			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_distilbert_for_sequence_classification(*_UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Union[str, Any]						=			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_distilbert_for_multiple_choice(*_UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					List[str]						=			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_distilbert_for_token_classification(*_UpperCAmelCase)


     @slow
     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]):
               __A		:					Optional[int]						=			TFDistilBertModel.from_pretrained(_UpperCAmelCase)
               self.assertIsNotNone(_UpperCAmelCase)




@require_tf
class 					SCREAMING_SNAKE_CASE       (unittest.TestCase				):


     @slow
     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[Any]						=			TFDistilBertModel.from_pretrained('distilbert-base-uncased')
          __A		:					Tuple						=			tf.constant([[0, 1, 2, 3, 4, 5]])
          __A		:					Dict						=			model(_UpperCAmelCase)[0]

          __A		:					Optional[int]						=			[1, 6, 768]
          self.assertEqual(output.shape		,      _UpperCAmelCase)

          __A		:					Optional[int]						=			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_torch_available


UpperCamelCase      					={
    "configuration_clap": [
        "CLAP_PRETRAINED_MODEL_ARCHIVE_LIST",
        "ClapAudioConfig",
        "ClapConfig",
        "ClapTextConfig",
    ],
    "processing_clap": ["ClapProcessor"],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase      					=[
          "CLAP_PRETRAINED_MODEL_ARCHIVE_LIST",
          "ClapModel",
          "ClapPreTrainedModel",
          "ClapTextModel",
          "ClapTextModelWithProjection",
          "ClapAudioModel",
          "ClapAudioModelWithProjection",
      ]
      UpperCamelCase      					=["ClapFeatureExtractor"]

if TYPE_CHECKING:
      from .configuration_clap import (
          CLAP_PRETRAINED_MODEL_ARCHIVE_LIST,
          ClapAudioConfig,
          ClapConfig,
          ClapTextConfig,
      )
      from .processing_clap import ClapProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .feature_extraction_clap import ClapFeatureExtractor
            from .modeling_clap import (
                CLAP_PRETRAINED_MODEL_ARCHIVE_LIST,
                ClapAudioModel,
                ClapAudioModelWithProjection,
                ClapModel,
                ClapPreTrainedModel,
                ClapTextModel,
                ClapTextModelWithProjection,
            )


else:
      import sys

      UpperCamelCase      					=_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






