"""simple docstring"""





from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
       import tensorflow as tf

       from transformers import TFBlipTextModel
       from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST


class      UpperCAmelCase_	:


      def __init__(   self		,			a		,			a=1_2		,			a=7		,			a=True		,			a=True		,			a=True		,			a=9_9		,			a=3_2		,			a=3_2		,			a=2		,			a=4		,			a=3_7		,			a=0.1		,			a=0.1		,			a=5_1_2		,			a=0.02		,			a=0		,			a=None		,			)       ->					Union[str, Any]:
             lowercase__			:		Any       =	parent
             lowercase__			:		str       =	batch_size
             lowercase__			:		List[Any]       =	seq_length
             lowercase__			:		Union[str, Any]       =	is_training
             lowercase__			:		List[str]       =	use_input_mask
             lowercase__			:		int       =	use_labels
             lowercase__			:		List[Any]       =	vocab_size
             lowercase__			:		str       =	hidden_size
             lowercase__			:		int       =	projection_dim
             lowercase__			:		Optional[int]       =	num_hidden_layers
             lowercase__			:		Any       =	num_attention_heads
             lowercase__			:		Optional[Any]       =	intermediate_size
             lowercase__			:		Optional[Any]       =	dropout
             lowercase__			:		Optional[int]       =	attention_dropout
             lowercase__			:		Optional[int]       =	max_position_embeddings
             lowercase__			:		str       =	initializer_range
             lowercase__			:		Tuple       =	scope
             lowercase__			:		int       =	bos_token_id


      def 		_UpperCAmelCase       (   self							)       ->					Optional[Any]:
             lowercase__			:		List[Any]       =	ids_tensor([self.batch_size, self.seq_length]		,			self.vocab_size							)

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

             if input_mask is not None:
                    lowercase__			:		int       =	input_mask.numpy()
                    lowercase__    ,      lowercase__			:		Tuple       =	input_mask.shape
                    lowercase__			:		List[str]       =	np.random.randint(1		,			seq_length - 1		,			size=(batch_size,)							)
                    for batch_idx, start_index in enumerate(a							):
                           lowercase__			:		Dict       =	1
                           lowercase__			:		Union[str, Any]       =	0

             lowercase__			:		Tuple       =	self.get_config()

             return config, input_ids, tf.convert_to_tensor(a							)


      def 		_UpperCAmelCase       (   self							)       ->					List[Any]:
             return BlipTextConfig(
                 vocab_size=self.vocab_size		,			hidden_size=self.hidden_size		,			projection_dim=self.projection_dim		,			num_hidden_layers=self.num_hidden_layers		,			num_attention_heads=self.num_attention_heads		,			intermediate_size=self.intermediate_size		,			dropout=self.dropout		,			attention_dropout=self.attention_dropout		,			max_position_embeddings=self.max_position_embeddings		,			initializer_range=self.initializer_range		,			bos_token_id=self.bos_token_id		,			)


      def 		_UpperCAmelCase       (   self		,			a		,			a		,			a							)       ->					Any:
             lowercase__			:		List[Any]       =	TFBlipTextModel(config=a							)
             lowercase__			:		Optional[int]       =	model(a		,			attention_mask=a		,			training=a							)
             lowercase__			:		List[str]       =	model(a		,			training=a							)
             self.parent.assertEqual(result.last_hidden_state.shape		,			(self.batch_size, self.seq_length, self.hidden_size)							)
             self.parent.assertEqual(result.pooler_output.shape		,			(self.batch_size, self.hidden_size)							)


      def 		_UpperCAmelCase       (   self							)       ->					Any:
             lowercase__			:		Optional[Any]       =	self.prepare_config_and_inputs()
             lowercase__    ,      lowercase__    ,      lowercase__			:		Any       =	config_and_inputs
             lowercase__			:		Any       =	{'input_ids': input_ids, 'attention_mask': input_mask}
             return config, inputs_dict





@require_tf
class      UpperCAmelCase_	(    _a ,							unittest.TestCase):
      lowerCamelCase__		:    Dict   =  (TFBlipTextModel,) if is_tf_available() else ()
      lowerCamelCase__		:    Optional[Any]   =  False
      lowerCamelCase__		:    List[str]   =  False
      lowerCamelCase__		:    Any   =  False


      def 		_UpperCAmelCase       (   self							)       ->					List[str]:
             lowercase__			:		Optional[int]       =	BlipTextModelTester(self							)
             lowercase__			:		int       =	ConfigTester(self		,			config_class=a		,			hidden_size=3_7							)


      def 		_UpperCAmelCase       (   self							)       ->					Tuple:
             self.config_tester.run_common_tests()


      def 		_UpperCAmelCase       (   self							)       ->					int:
             lowercase__			:		Dict       =	self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*a							)


      def 		_UpperCAmelCase       (   self							)       ->					Optional[Any]:
             pass


      def 		_UpperCAmelCase       (   self							)       ->					Optional[int]:
             pass


      @unittest.skip(reason='Blip does not use inputs_embeds'							)
      def 		_UpperCAmelCase       (   self							)       ->					List[str]:
             pass


      @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'							)
      def 		_UpperCAmelCase       (   self							)       ->					Dict:
             pass


      @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'							)
      def 		_UpperCAmelCase       (   self							)       ->					str:
             pass


      @slow
      def 		_UpperCAmelCase       (   self							)       ->					int:
             for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    lowercase__			:		Any       =	TFBlipTextModel.from_pretrained(a							)
                    self.assertIsNotNone(a							)


      def 		_UpperCAmelCase       (   self		,			a=True							)       ->					List[str]:
             super().test_pt_tf_model_equivalence(allow_missing_keys=a							)






"""simple docstring"""

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowercase__    :  List[Any]							    =	{
    '''configuration_distilbert''': [
        '''DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''DistilBertConfig''',
        '''DistilBertOnnxConfig''',
    ],
    '''tokenization_distilbert''': ['''DistilBertTokenizer'''],
}

try:
     if not is_tokenizers_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__    :  Any							    =	['''DistilBertTokenizerFast''']

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__    :  int							    =	[
         '''DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''DistilBertForMaskedLM''',
         '''DistilBertForMultipleChoice''',
         '''DistilBertForQuestionAnswering''',
         '''DistilBertForSequenceClassification''',
         '''DistilBertForTokenClassification''',
         '''DistilBertModel''',
         '''DistilBertPreTrainedModel''',
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__    :  Dict							    =	[
         '''TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''TFDistilBertForMaskedLM''',
         '''TFDistilBertForMultipleChoice''',
         '''TFDistilBertForQuestionAnswering''',
         '''TFDistilBertForSequenceClassification''',
         '''TFDistilBertForTokenClassification''',
         '''TFDistilBertMainLayer''',
         '''TFDistilBertModel''',
         '''TFDistilBertPreTrainedModel''',
     ]

try:
     if not is_flax_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__    :  Tuple							    =	[
         '''FlaxDistilBertForMaskedLM''',
         '''FlaxDistilBertForMultipleChoice''',
         '''FlaxDistilBertForQuestionAnswering''',
         '''FlaxDistilBertForSequenceClassification''',
         '''FlaxDistilBertForTokenClassification''',
         '''FlaxDistilBertModel''',
         '''FlaxDistilBertPreTrainedModel''',
     ]


if TYPE_CHECKING:
     from .configuration_distilbert import (
         DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
         DistilBertConfig,
         DistilBertOnnxConfig,
     )
     from .tokenization_distilbert import DistilBertTokenizer

     try:
          if not is_tokenizers_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_distilbert_fast import DistilBertTokenizerFast

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_distilbert import (
              DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
              DistilBertForMaskedLM,
              DistilBertForMultipleChoice,
              DistilBertForQuestionAnswering,
              DistilBertForSequenceClassification,
              DistilBertForTokenClassification,
              DistilBertModel,
              DistilBertPreTrainedModel,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_distilbert import (
              TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFDistilBertForMaskedLM,
              TFDistilBertForMultipleChoice,
              TFDistilBertForQuestionAnswering,
              TFDistilBertForSequenceClassification,
              TFDistilBertForTokenClassification,
              TFDistilBertMainLayer,
              TFDistilBertModel,
              TFDistilBertPreTrainedModel,
          )

     try:
          if not is_flax_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_flax_distilbert import (
              FlaxDistilBertForMaskedLM,
              FlaxDistilBertForMultipleChoice,
              FlaxDistilBertForQuestionAnswering,
              FlaxDistilBertForSequenceClassification,
              FlaxDistilBertForTokenClassification,
              FlaxDistilBertModel,
              FlaxDistilBertPreTrainedModel,
          )

else:
     import sys

     lowercase__    :  Union[str, Any]							    =	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





