




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__:
      def __init__(				self: List[Any]    ,       UpperCamelCase_: Union[str, Any]    ,       UpperCamelCase_: Dict=12    ,       UpperCamelCase_: int=7    ,       UpperCamelCase_: Union[str, Any]=True    ,       UpperCamelCase_: List[str]=True    ,       UpperCamelCase_: Union[str, Any]=True    ,       UpperCamelCase_: Union[str, Any]=99    ,       UpperCamelCase_: List[Any]=32    ,       UpperCamelCase_: Any=32    ,       UpperCamelCase_: Tuple=2    ,       UpperCamelCase_: List[str]=4    ,       UpperCamelCase_: Any=37    ,       UpperCamelCase_: Union[str, Any]=0.1    ,       UpperCamelCase_: Dict=0.1    ,       UpperCamelCase_: Optional[int]=5_12    ,       UpperCamelCase_: Optional[Any]=0.02    ,       UpperCamelCase_: Union[str, Any]=0    ,       UpperCamelCase_: Optional[Any]=None    ,       ):
             __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 			lowerCAmelCase__						(				self: Union[str, Any]   ):
             __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(__lowerCAmelCase   ):
                           __lowerCamelCase   =						1
                           __lowerCamelCase   =						0

             __lowerCamelCase   =						self.get_config()

             return config, input_ids, tf.convert_to_tensor(__lowerCAmelCase   )
      def 			lowerCAmelCase__						(				self: Optional[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 			lowerCAmelCase__						(				self: str    ,       UpperCamelCase_: Dict    ,       UpperCamelCase_: Tuple    ,       UpperCamelCase_: int   ):
             __lowerCamelCase   =						TFBlipTextModel(config=__lowerCAmelCase   )
             __lowerCamelCase   =						model(__lowerCAmelCase    ,       attention_mask=__lowerCAmelCase    ,       training=__lowerCAmelCase   )
             __lowerCamelCase   =						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 			lowerCAmelCase__						(				self: Union[str, Any]   ):
             __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__(					__lowerCamelCase ,     unittest.TestCase):
      UpperCAmelCase__      :	Tuple    		=   (TFBlipTextModel,) if is_tf_available() else ()
      UpperCAmelCase__      :	List[Any]    		=   False
      UpperCAmelCase__      :	List[Any]    		=   False
      UpperCAmelCase__      :	int    		=   False
      def 			lowerCAmelCase__						(				self: Tuple   ):
             __lowerCamelCase   =						BlipTextModelTester(self   )
             __lowerCamelCase   =						ConfigTester(self    ,       config_class=__lowerCAmelCase    ,       hidden_size=37   )
      def 			lowerCAmelCase__						(				self: Tuple   ):
             self.config_tester.run_common_tests()
      def 			lowerCAmelCase__						(				self: Optional[int]   ):
             __lowerCamelCase   =						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__lowerCAmelCase   )
      def 			lowerCAmelCase__						(				self: Optional[int]   ):
             pass
      def 			lowerCAmelCase__						(				self: Tuple   ):
             pass
      @unittest.skip(reason="""Blip does not use inputs_embeds"""   )
      def 			lowerCAmelCase__						(				self: Tuple   ):
             pass
      @unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""   )
      def 			lowerCAmelCase__						(				self: Union[str, Any]   ):
             pass
      @unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""   )
      def 			lowerCAmelCase__						(				self: Optional[int]   ):
             pass
      @slow
      def 			lowerCAmelCase__						(				self: int   ):







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




      def 			lowerCAmelCase__						(				self: Optional[int]    ,       UpperCamelCase_: List[str]=True   ):
             super().test_pt_tf_model_equivalence(allow_missing_keys=__lowerCAmelCase   )








from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_a 						=      logging.get_logger(__name__)

_a 						=      {
    "hustvl/yolos-small": "https://huggingface.co/hustvl/yolos-small/resolve/main/config.json",
    # See all YOLOS models at https://huggingface.co/models?filter=yolos
}






class 					__A    (    lowerCAmelCase ):

			'''simple docstring'''







			lowerCAmelCase_							     =						"""yolos"""





			def __init__(    self       ,  __lowerCAmelCase=7_6_8       ,  __lowerCAmelCase=1_2       ,  __lowerCAmelCase=1_2       ,  __lowerCAmelCase=3_0_7_2       ,  __lowerCAmelCase="gelu"       ,  __lowerCAmelCase=0.0       ,  __lowerCAmelCase=0.0       ,  __lowerCAmelCase=0.02       ,  __lowerCAmelCase=1E-12       ,  __lowerCAmelCase=[5_1_2, 8_6_4]       ,  __lowerCAmelCase=1_6       ,  __lowerCAmelCase=3       ,  __lowerCAmelCase=True       ,  __lowerCAmelCase=1_0_0       ,  __lowerCAmelCase=True       ,  __lowerCAmelCase=False       ,  __lowerCAmelCase=1       ,  __lowerCAmelCase=5       ,  __lowerCAmelCase=2       ,  __lowerCAmelCase=5       ,  __lowerCAmelCase=2       ,  __lowerCAmelCase=0.1       ,  **__lowerCAmelCase       ,  ):



				'''simple docstring'''







				super().__init__(**__lowerCAmelCase							)

				lowerCamelCase__								=		hidden_size
				lowerCamelCase__								=		num_hidden_layers
				lowerCamelCase__								=		num_attention_heads
				lowerCamelCase__								=		intermediate_size
				lowerCamelCase__								=		hidden_act
				lowerCamelCase__								=		hidden_dropout_prob
				lowerCamelCase__								=		attention_probs_dropout_prob
				lowerCamelCase__								=		initializer_range
				lowerCamelCase__								=		layer_norm_eps
				lowerCamelCase__								=		image_size
				lowerCamelCase__								=		patch_size
				lowerCamelCase__								=		num_channels
				lowerCamelCase__								=		qkv_bias
				lowerCamelCase__								=		num_detection_tokens
				lowerCamelCase__								=		use_mid_position_embeddings
				lowerCamelCase__								=		auxiliary_loss
				# Hungarian matcher
				lowerCamelCase__								=		class_cost
				lowerCamelCase__								=		bbox_cost
				lowerCamelCase__								=		giou_cost
				# Loss coefficients
				lowerCamelCase__								=		bbox_loss_coefficient
				lowerCamelCase__								=		giou_loss_coefficient
				lowerCamelCase__								=		eos_coefficient






class 					__A    (    lowerCAmelCase ):

			'''simple docstring'''







			lowerCAmelCase_							     =						version.parse("""1.11""" )





			@property
			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				return OrderedDict(
				    [
				        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
				    ]							)





			@property
			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				return 1E-4





			@property
			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				return 1_2



