





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







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







							def 						__lowerCamelCase   (				self					:     Tuple      )       ->Optional[int]:
										lowerCamelCase__       :						Any        =							ids_tensor([self.batch_size, self.seq_length]		, self.vocab_size      )

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

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

										lowerCamelCase__       :						str        =							self.get_config()

										return config, input_ids, tf.convert_to_tensor(A      )







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


@require_tf
class        __SCREAMING_SNAKE_CASE      (			lowerCAmelCase_					,unittest.TestCase ):
							_UpperCAmelCase				:  Tuple			   =   (TFBlipTextModel,) if is_tf_available() else ()
							_UpperCAmelCase				:  Optional[int]			   =   False
							_UpperCAmelCase				:  List[str]			   =   False
							_UpperCAmelCase				:  int			   =   False







							def 						__lowerCamelCase   (				self					:     Tuple      )       ->Tuple:
										lowerCamelCase__       :						Optional[Any]        =							BlipTextModelTester(self      )
										lowerCamelCase__       :						Any        =							ConfigTester(self		, config_class=A		, hidden_size=3_7      )







							def 						__lowerCamelCase   (				self					:     Union[str, Any]      )       ->List[Any]:
										self.config_tester.run_common_tests()







							def 						__lowerCamelCase   (				self					:     List[Any]      )       ->List[str]:
										lowerCamelCase__       :						List[Any]        =							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*A      )







							def 						__lowerCamelCase   (				self					:     Optional[Any]      )       ->Union[str, Any]:
										pass







							def 						__lowerCamelCase   (				self					:     str      )       ->Dict:
										pass







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







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







							@unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''      )
							def 						__lowerCamelCase   (				self					:     Any      )       ->Union[str, Any]:
										pass







							@slow
							def 						__lowerCamelCase   (				self					:     List[Any]      )       ->List[Any]:
										for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase__       :						List[Any]        =							TFBlipTextModel.from_pretrained(A      )
													self.assertIsNotNone(A      )







							def 						__lowerCamelCase   (				self					:     Any		, A					:     Tuple=True      )       ->Dict:
										super().test_pt_tf_model_equivalence(allow_missing_keys=A      )










import inspect
import warnings
from typing import Any, Dict, Optional, Union

from packaging import version



def 	_a						(   *UpperCAmelCase      ,  UpperCAmelCase = None      ,  UpperCAmelCase=True      ,  UpperCAmelCase=2					)    ->    str:







   """simple docstring"""
   from .. import __version__

   lowerCamelCase__       :						Optional[Any]        =							take_from
   lowerCamelCase__       :						Any        =							()
   if not isinstance(args[0]      ,  UpperCAmelCase					):
      lowerCamelCase__       :						Optional[int]        =							(args,)

   for attribute, version_name, message in args:
      if version.parse(version.parse(UpperCAmelCase					).base_version					) >= version.parse(UpperCAmelCase					):
         raise ValueError(
             f"The deprecation tuple {(attribute, version_name, message)} should be removed since diffusers'"
             f" version {__version__} is >= {version_name}"					)

      lowerCamelCase__       :						List[Any]        =							None
      if isinstance(UpperCAmelCase      ,  UpperCAmelCase					) and attribute in deprecated_kwargs:
         values += (deprecated_kwargs.pop(UpperCAmelCase					),)
         lowerCamelCase__       :						Tuple        =							f"The `{attribute}` argument is deprecated and will be removed in version {version_name}."
      elif hasattr(UpperCAmelCase      ,  UpperCAmelCase					):
         values += (getattr(UpperCAmelCase      ,  UpperCAmelCase					),)
         lowerCamelCase__       :						Union[str, Any]        =							f"The `{attribute}` attribute is deprecated and will be removed in version {version_name}."
      elif deprecated_kwargs is None:
         lowerCamelCase__       :						int        =							f"`{attribute}` is deprecated and will be removed in version {version_name}."

      if warning is not None:
         lowerCamelCase__       :						int        =							warning + ''' ''' if standard_warn else ''''''
         warnings.warn(warning + message      ,  UpperCAmelCase      ,  stacklevel=UpperCAmelCase					)

   if isinstance(UpperCAmelCase      ,  UpperCAmelCase					) and len(UpperCAmelCase					) > 0:
      lowerCamelCase__       :						Tuple        =							inspect.getouterframes(inspect.currentframe()					)[1]
      lowerCamelCase__       :						Optional[Any]        =							call_frame.filename
      lowerCamelCase__       :						List[Any]        =							call_frame.lineno
      lowerCamelCase__       :						Optional[Any]        =							call_frame.function
      lowerCamelCase__       ,							lowerCamelCase__       :						Union[str, Any]        =							next(iter(deprecated_kwargs.items()					)					)
      raise TypeError(f"{function} in {filename} line {line_number-1} got an unexpected keyword argument `{key}`"					)

   if len(UpperCAmelCase					) == 0:
      return
   elif len(UpperCAmelCase					) == 1:
      return values[0]
   return values



