
'''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     __snake_case		:
					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=512,    A=0.02,    A=0,    A=None,    ):

									"""simple docstring"""


									lowerCamelCase					:			int									= parent
									lowerCamelCase					:			int									= batch_size
									lowerCamelCase					:			List[str]									= seq_length
									lowerCamelCase					:			Union[str, Any]									= is_training
									lowerCamelCase					:			Union[str, Any]									= use_input_mask
									lowerCamelCase					:			int									= use_labels
									lowerCamelCase					:			Dict									= vocab_size
									lowerCamelCase					:			Any									= hidden_size
									lowerCamelCase					:			int									= projection_dim
									lowerCamelCase					:			Optional[Any]									= num_hidden_layers
									lowerCamelCase					:			Optional[Any]									= num_attention_heads
									lowerCamelCase					:			Tuple									= intermediate_size
									lowerCamelCase					:			Optional[int]									= dropout
									lowerCamelCase					:			Tuple									= attention_dropout
									lowerCamelCase					:			int									= max_position_embeddings
									lowerCamelCase					:			int									= initializer_range
									lowerCamelCase					:			int									= scope
									lowerCamelCase					:			Optional[int]									= bos_token_id
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


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

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

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

									lowerCamelCase					:			Any									= self.get_config()

									return config, input_ids, tf.convert_to_tensor(A      )
					def     UpperCAmelCase_							(     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     UpperCAmelCase_							(     self,    A,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= TFBlipTextModel(config=A      )
									lowerCamelCase					:			List[str]									= model(A,    attention_mask=A,    training=A      )
									lowerCamelCase					:			Optional[int]									= 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      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= self.prepare_config_and_inputs()
									lowerCamelCase					:			int									= config_and_inputs
									lowerCamelCase					:			List[str]									= {'input_ids': input_ids, 'attention_mask': input_mask}
									return config, inputs_dict





@require_tf
class     __snake_case		(   a__    ,   unittest.TestCase):
					_lowerCAmelCase			     =	(TFBlipTextModel,) if is_tf_available() else ()
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[int]									= BlipTextModelTester(self      )
									lowerCamelCase					:			Union[str, Any]									= ConfigTester(self,    config_class=A,    hidden_size=37      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									self.config_tester.run_common_tests()
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Any									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*A      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									pass
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									pass
					@unittest.skip(reason='Blip does not use inputs_embeds'      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


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

									"""simple docstring"""


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

									"""simple docstring"""


									pass
					@slow
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


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




					def     UpperCAmelCase_							(     self,    A=True      ):

									"""simple docstring"""


									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,
    is_vision_available,
)


A			      =      {
    'configuration_clip': [
        'CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'CLIPConfig',
        'CLIPOnnxConfig',
        'CLIPTextConfig',
        'CLIPVisionConfig',
    ],
    'processing_clip': ['CLIPProcessor'],
    'tokenization_clip': ['CLIPTokenizer'],
}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A			      =      ['CLIPTokenizerFast']

try:
					if not is_vision_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A			      =      ['CLIPFeatureExtractor']
					A			      =      ['CLIPImageProcessor']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A			      =      [
					    'CLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'CLIPModel',
					    'CLIPPreTrainedModel',
					    'CLIPTextModel',
					    'CLIPTextModelWithProjection',
					    'CLIPVisionModel',
					    'CLIPVisionModelWithProjection',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A			      =      [
					    'TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'TFCLIPModel',
					    'TFCLIPPreTrainedModel',
					    'TFCLIPTextModel',
					    'TFCLIPVisionModel',
					]

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A			      =      [
					    'FlaxCLIPModel',
					    'FlaxCLIPPreTrainedModel',
					    'FlaxCLIPTextModel',
					    'FlaxCLIPTextPreTrainedModel',
					    'FlaxCLIPVisionModel',
					    'FlaxCLIPVisionPreTrainedModel',
					]


if TYPE_CHECKING:
					from .configuration_clip import (
					    CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    CLIPConfig,
					    CLIPOnnxConfig,
					    CLIPTextConfig,
					    CLIPVisionConfig,
					)
					from .processing_clip import CLIPProcessor
					from .tokenization_clip import CLIPTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_clip_fast import CLIPTokenizerFast

					try:
										if not is_vision_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .feature_extraction_clip import CLIPFeatureExtractor
										from .image_processing_clip import CLIPImageProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_clip import (
										    CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
										    CLIPModel,
										    CLIPPreTrainedModel,
										    CLIPTextModel,
										    CLIPTextModelWithProjection,
										    CLIPVisionModel,
										    CLIPVisionModelWithProjection,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_clip import (
										    TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFCLIPModel,
										    TFCLIPPreTrainedModel,
										    TFCLIPTextModel,
										    TFCLIPVisionModel,
										)

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_clip import (
										    FlaxCLIPModel,
										    FlaxCLIPPreTrainedModel,
										    FlaxCLIPTextModel,
										    FlaxCLIPTextPreTrainedModel,
										    FlaxCLIPVisionModel,
										    FlaxCLIPVisionPreTrainedModel,
										)


else:
					import sys

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