


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




							"""simple docstring"""


							def __init__(							self :						List[str]					,			lowerCamelCase :						Any					,			lowerCamelCase :						Optional[Any]=12					,			lowerCamelCase :						Optional[Any]=7					,			lowerCamelCase :						List[Any]=True					,			lowerCamelCase :						Any=True					,			lowerCamelCase :						Optional[int]=True					,			lowerCamelCase :						List[Any]=99					,			lowerCamelCase :						List[Any]=32					,			lowerCamelCase :						List[Any]=32					,			lowerCamelCase :						str=2					,			lowerCamelCase :						Tuple=4					,			lowerCamelCase :						int=37					,			lowerCamelCase :						str=0.1					,			lowerCamelCase :						List[str]=0.1					,			lowerCamelCase :						Tuple=512					,			lowerCamelCase :						List[Any]=0.02					,			lowerCamelCase :						str=0					,			lowerCamelCase :						List[str]=None					,			)			->					str:
														__snake_case	:    List[Any]											=     parent
														__snake_case	:    Dict											=     batch_size
														__snake_case	:    List[str]											=     seq_length
														__snake_case	:    Dict											=     is_training
														__snake_case	:    Any											=     use_input_mask
														__snake_case	:    List[str]											=     use_labels
														__snake_case	:    Optional[int]											=     vocab_size
														__snake_case	:    List[str]											=     hidden_size
														__snake_case	:    List[str]											=     projection_dim
														__snake_case	:    Optional[Any]											=     num_hidden_layers
														__snake_case	:    List[str]											=     num_attention_heads
														__snake_case	:    List[str]											=     intermediate_size
														__snake_case	:    List[str]											=     dropout
														__snake_case	:    str											=     attention_dropout
														__snake_case	:    Dict											=     max_position_embeddings
														__snake_case	:    str											=     initializer_range
														__snake_case	:    int											=     scope
														__snake_case	:    Union[str, Any]											=     bos_token_id

							def 					__snake_case      (							self :						Tuple       )			->					str:
														__snake_case	:    Optional[int]											=     ids_tensor([self.batch_size, self.seq_length]					,			self.vocab_size       )

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

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

														__snake_case	:    Optional[int]											=     self.get_config()

														return config, input_ids, tf.convert_to_tensor(lowerCamelCase       )

							def 					__snake_case      (							self :						str       )			->					str:
														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 					__snake_case      (							self :						Any					,			lowerCamelCase :						Dict					,			lowerCamelCase :						Optional[int]					,			lowerCamelCase :						Union[str, Any]       )			->					List[str]:
														__snake_case	:    List[str]											=     TFBlipTextModel(config=lowerCamelCase       )
														__snake_case	:    Optional[int]											=     model(lowerCamelCase					,			attention_mask=lowerCamelCase					,			training=lowerCamelCase       )
														__snake_case	:    Optional[int]											=     model(lowerCamelCase					,			training=lowerCamelCase       )
														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 					__snake_case      (							self :						List[Any]       )			->					Tuple:
														__snake_case	:    Union[str, Any]											=     self.prepare_config_and_inputs()
														__snake_case				,    __snake_case				,    __snake_case	:    str											=     config_and_inputs
														__snake_case	:    Optional[Any]											=     {"input_ids": input_ids, "attention_mask": input_mask}
														return config, inputs_dict

@require_tf
class        a	(_lowerCAmelCase  ,       unittest.TestCase   ):




							"""simple docstring"""


							__UpperCAmelCase					:							Optional[Any]  						=						(TFBlipTextModel,) if is_tf_available() else ()
							__UpperCAmelCase					:							Optional[Any]  						=						False
							__UpperCAmelCase					:							str  						=						False
							__UpperCAmelCase					:							str  						=						False

							def 					__snake_case      (							self :						Optional[Any]       )			->					str:
														__snake_case	:    List[str]											=     BlipTextModelTester(self       )
														__snake_case	:    List[Any]											=     ConfigTester(self					,			config_class=lowerCamelCase					,			hidden_size=37       )

							def 					__snake_case      (							self :						List[Any]       )			->					Optional[int]:
														self.config_tester.run_common_tests()

							def 					__snake_case      (							self :						int       )			->					Dict:
														__snake_case	:    int											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*lowerCamelCase       )

							def 					__snake_case      (							self :						Any       )			->					List[str]:
														pass

							def 					__snake_case      (							self :						Optional[int]       )			->					List[str]:
														pass

							@unittest.skip(reason="Blip does not use inputs_embeds"       )
							def 					__snake_case      (							self :						int       )			->					Union[str, Any]:
														pass

							@unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"       )
							def 					__snake_case      (							self :						str       )			->					Optional[int]:
														pass

							@unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"       )
							def 					__snake_case      (							self :						Optional[Any]       )			->					Optional[Any]:
														pass

							@slow
							def 					__snake_case      (							self :						Union[str, Any]       )			->					str:
														for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					__snake_case	:    Tuple											=     TFBlipTextModel.from_pretrained(lowerCamelCase       )
																					self.assertIsNotNone(lowerCamelCase       )






							def 					__snake_case      (							self :						str					,			lowerCamelCase :						Optional[int]=True       )			->					Any:
														super().test_pt_tf_model_equivalence(allow_missing_keys=lowerCamelCase       )





import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


_snake_case  :	int			      =       {
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

_snake_case  :	Dict			      =       logging.WARNING







def        lowerCAmelCase_  (      ):
							__snake_case	:    Union[str, Any]											=     os.getenv("DATASETS_VERBOSITY"							,			__lowerCamelCase			)
							if env_level_str:
														if env_level_str in log_levels:
																					return log_levels[env_level_str]
														else:
																					logging.getLogger().warning(
																					    F'Unknown option DATASETS_VERBOSITY={env_level_str}, '
																					    F'has to be one of: { ", ".join(log_levels.keys()			) }'			)
							return _default_log_level







def        lowerCAmelCase_  (      ):
							return __name__.split("."			)[0]







def        lowerCAmelCase_  (      ):
							return logging.getLogger(_get_library_name()			)







def        lowerCAmelCase_  (      ):
							# Apply our default configuration to the library root logger.
							__snake_case	:    str											=     _get_library_root_logger()
							library_root_logger.setLevel(_get_default_logging_level()			)







def        lowerCAmelCase_  (      ):
							__snake_case	:    Dict											=     _get_library_root_logger()
							library_root_logger.setLevel(logging.NOTSET			)







def        lowerCAmelCase_  (      __lowerCamelCase = None			):
							if name is None:
														__snake_case	:    Tuple											=     _get_library_name()
							return logging.getLogger(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return _get_library_root_logger().getEffectiveLevel()







def        lowerCAmelCase_  (      __lowerCamelCase			):
							_get_library_root_logger().setLevel(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return set_verbosity(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return set_verbosity(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return set_verbosity(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							return set_verbosity(__lowerCamelCase			)







def        lowerCAmelCase_  (      ):
							__snake_case	:    List[str]											=     False







def        lowerCAmelCase_  (      ):
							__snake_case	:    Tuple											=     True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()

class        a	:




							"""simple docstring"""


							def __init__(							self :						int					,			*lowerCamelCase :						Optional[Any]					,			**lowerCamelCase :						List[str]       )			->					Optional[int]:  # pylint: disable=unused-argument
														__snake_case	:    int											=     args[0] if args else None

							def __iter__(							self :						Dict       )			->					Optional[int]:
														return iter(self._iterator       )

							def __getattr__(							self :						int					,			lowerCamelCase :						Optional[Any]       )			->					List[Any]:

														def empty_fn(*lowerCamelCase :						Optional[int]					,			**lowerCamelCase :						List[Any]       ):  # pylint: disable=unused-argument
																					return

														return empty_fn

							def __enter__(							self :						List[str]       )			->					int:
														return self






							def __exit__(							self :						Dict					,			lowerCamelCase :						Any					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						str       )			->					Dict:
														return
_snake_case  :	Optional[Any]			      =       True

class        a	:




							"""simple docstring"""


							def __call__(							self :						str					,			*lowerCamelCase :						Optional[Any]					,			lowerCamelCase :						Tuple=False					,			**lowerCamelCase :						Union[str, Any]       )			->					Optional[Any]:
														if _tqdm_active and not disable:
																					return tqdm_lib.tqdm(*lowerCamelCase					,			**lowerCamelCase       )
														else:
																					return EmptyTqdm(*lowerCamelCase					,			**lowerCamelCase       )

							def 					__snake_case      (							self :						str					,			*lowerCamelCase :						str					,			**lowerCamelCase :						Tuple       )			->					str:
														__snake_case	:    Optional[Any]											=     None
														if _tqdm_active:
																					return tqdm_lib.tqdm.set_lock(*lowerCamelCase					,			**lowerCamelCase       )






							def 					__snake_case      (							self :						List[Any]       )			->					List[Any]:
														if _tqdm_active:
																					return tqdm_lib.tqdm.get_lock()
_snake_case  :	int			      =       _tqdm_cls()







def        lowerCAmelCase_  (      ):
							global _tqdm_active
							return bool(_tqdm_active			)







def        lowerCAmelCase_  (      ):
							global _tqdm_active
							__snake_case	:    Tuple											=     True







def        lowerCAmelCase_  (      ):
							global _tqdm_active
							__snake_case	:    List[Any]											=     False

