



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    lowerCamelCase__  :
     """simple docstring"""



     def __init__(self				,			__a				,			__a=12				,			__a=7				,			__a=True				,			__a=True				,			__a=True				,			__a=99				,			__a=32				,			__a=32				,			__a=2				,			__a=4				,			__a=37				,			__a=0.1				,			__a=0.1				,			__a=5_12				,			__a=0.02				,			__a=0				,			__a=None				,			):






           '''simple docstring'''



           lowerCamelCase								=		parent
           lowerCamelCase								=		batch_size
           lowerCamelCase								=		seq_length
           lowerCamelCase								=		is_training
           lowerCamelCase								=		use_input_mask
           lowerCamelCase								=		use_labels
           lowerCamelCase								=		vocab_size
           lowerCamelCase								=		hidden_size
           lowerCamelCase								=		projection_dim
           lowerCamelCase								=		num_hidden_layers
           lowerCamelCase								=		num_attention_heads
           lowerCamelCase								=		intermediate_size
           lowerCamelCase								=		dropout
           lowerCamelCase								=		attention_dropout
           lowerCamelCase								=		max_position_embeddings
           lowerCamelCase								=		initializer_range
           lowerCamelCase								=		scope
           lowerCamelCase								=		bos_token_id







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		ids_tensor([self.batch_size, self.seq_length]				,			self.vocab_size    )

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

           if input_mask is not None:
                 lowerCamelCase								=		input_mask.numpy()
                 lowerCamelCase			,							lowerCamelCase								=		input_mask.shape
                 lowerCamelCase								=		np.random.randint(1				,			seq_length - 1				,			size=(batch_size,)    )
                 for batch_idx, start_index in enumerate(__a    ):
                       lowerCamelCase								=		1
                       lowerCamelCase								=		0

           lowerCamelCase								=		self.get_config()

           return config, input_ids, tf.convert_to_tensor(__a    )







     def 						_a      (self    ):






           '''simple docstring'''



           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 						_a      (self				,			__a				,			__a				,			__a    ):






           '''simple docstring'''



           lowerCamelCase								=		TFBlipTextModel(config=__a    )
           lowerCamelCase								=		model(__a				,			attention_mask=__a				,			training=__a    )
           lowerCamelCase								=		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 						_a      (self    ):






           '''simple docstring'''



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





@require_tf
class    lowerCamelCase__  (						UpperCAmelCase_       ,    unittest.TestCase):
     """simple docstring"""



     _A       =			(TFBlipTextModel,) if is_tf_available() else ()
     _A       =			False
     _A       =			False
     _A       =			False







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		BlipTextModelTester(self    )
           lowerCamelCase								=		ConfigTester(self				,			config_class=__a				,			hidden_size=37    )







     def 						_a      (self    ):






           '''simple docstring'''



           self.config_tester.run_common_tests()







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*__a    )







     def 						_a      (self    ):






           '''simple docstring'''



           pass







     def 						_a      (self    ):






           '''simple docstring'''



           pass







     @unittest.skip(reason="Blip does not use inputs_embeds"    )
     def 						_a      (self    ):






           '''simple docstring'''



           pass







     @unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"    )
     def 						_a      (self    ):






           '''simple docstring'''



           pass







     @unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"    )
     def 						_a      (self    ):






           '''simple docstring'''



           pass







     @slow
     def 						_a      (self    ):






           '''simple docstring'''



           for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 lowerCamelCase								=		TFBlipTextModel.from_pretrained(__a    )
                 self.assertIsNotNone(__a    )







     def 						_a      (self				,			__a=True    ):






           '''simple docstring'''



           super().test_pt_tf_model_equivalence(allow_missing_keys=__a    )




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a_						:     List[str]	     =		{
    'configuration_clipseg': [
        'CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'CLIPSegConfig',
        'CLIPSegTextConfig',
        'CLIPSegVisionConfig',
    ],
    'processing_clipseg': ['CLIPSegProcessor'],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     a_						:     Any	     =		[
         'CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST',
         'CLIPSegModel',
         'CLIPSegPreTrainedModel',
         'CLIPSegTextModel',
         'CLIPSegVisionModel',
         'CLIPSegForImageSegmentation',
     ]

if TYPE_CHECKING:
     from .configuration_clipseg import (
         CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP,
         CLIPSegConfig,
         CLIPSegTextConfig,
         CLIPSegVisionConfig,
     )
     from .processing_clipseg import CLIPSegProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_clipseg import (
              CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST,
              CLIPSegForImageSegmentation,
              CLIPSegModel,
              CLIPSegPreTrainedModel,
              CLIPSegTextModel,
              CLIPSegVisionModel,
          )

else:
     import sys

     a_						:     Dict	     =		_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)