'''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     a__      :






     def __init__( self		:		List[str]  ,				a		:		Any  ,				a		:		Union[str, Any]=12  ,				a		:		List[Any]=7  ,				a		:		str=True  ,				a		:		str=True  ,				a		:		Dict=True  ,				a		:		Union[str, Any]=99  ,				a		:		Optional[Any]=32  ,				a		:		int=32  ,				a		:		int=2  ,				a		:		Optional[int]=4  ,				a		:		Dict=37  ,				a		:		Optional[Any]=0.1  ,				a		:		Dict=0.1  ,				a		:		Optional[int]=5_12  ,				a		:		List[Any]=0.02  ,				a		:		Union[str, Any]=0  ,				a		:		Any=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    SCREAMING_SNAKE_CASE__   ( self		:		str    ):





         """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    SCREAMING_SNAKE_CASE__   ( self		:		List[str]    ):





         """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    SCREAMING_SNAKE_CASE__   ( self		:		Optional[Any]  ,				a		:		int  ,				a		:		Tuple  ,				a		:		Union[str, Any]    ):





         """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    SCREAMING_SNAKE_CASE__   ( self		:		Union[str, Any]    ):





         """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     a__      (   UpperCAmelCase__							,   unittest.TestCase ):
     lowerCamelCase  :     List[Any]							=(TFBlipTextModel,) if is_tf_available() else ()
     lowerCamelCase  :     Any							=False
     lowerCamelCase  :     List[str]							=False
     lowerCamelCase  :     int							=False






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]    ):





         """simple docstring"""



         __lowerCamelCase		=  BlipTextModelTester(self    )
         __lowerCamelCase		=  ConfigTester(self  ,				config_class=a  ,				hidden_size=37    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		str    ):





         """simple docstring"""



         self.config_tester.run_common_tests()






     def    SCREAMING_SNAKE_CASE__   ( self		:		str    ):





         """simple docstring"""



         __lowerCamelCase		=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*a    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]    ):





         """simple docstring"""



         pass






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[Any]    ):





         """simple docstring"""



         pass






     @unittest.skip(reason='''Blip does not use inputs_embeds'''    )
     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]    ):





         """simple docstring"""



         pass






     @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''    )
     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[Any]    ):





         """simple docstring"""



         pass






     @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''    )
     def    SCREAMING_SNAKE_CASE__   ( self		:		List[str]    ):





         """simple docstring"""



         pass






     @slow
     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]    ):





         """simple docstring"""



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






     def    SCREAMING_SNAKE_CASE__   ( self		:		int  ,				a		:		int=True    ):





         """simple docstring"""



         super().test_pt_tf_model_equivalence(allow_missing_keys=a    )








import copy
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
from ..auto import CONFIG_MAPPING


lowerCamelCase	:							Tuple				=logging.get_logger(__name__)

lowerCamelCase	:							Optional[Any]				={
    '''microsoft/conditional-detr-resnet-50''': (
        '''https://huggingface.co/microsoft/conditional-detr-resnet-50/resolve/main/config.json'''
    ),
}





class 			__a  (    A__       ):
 _lowerCAmelCase       :       Optional[Any]        = '''conditional_detr'''
 _lowerCAmelCase       :       List[Any]        = ['''past_key_values''']
 _lowerCAmelCase       :       List[str]        = {
     '''hidden_size''': '''d_model''',
     '''num_attention_heads''': '''encoder_attention_heads''',
 }







 def __init__(		self					:   str							,   SCREAMING_SNAKE_CASE					:   Tuple=True							,   SCREAMING_SNAKE_CASE					:   Optional[int]=None							,   SCREAMING_SNAKE_CASE					:   Tuple=3							,   SCREAMING_SNAKE_CASE					:   Any=3_00							,   SCREAMING_SNAKE_CASE					:   Tuple=6							,   SCREAMING_SNAKE_CASE					:   int=20_48							,   SCREAMING_SNAKE_CASE					:   Union[str, Any]=8							,   SCREAMING_SNAKE_CASE					:   int=6							,   SCREAMING_SNAKE_CASE					:   Dict=20_48							,   SCREAMING_SNAKE_CASE					:   Optional[int]=8							,   SCREAMING_SNAKE_CASE					:   Dict=0.0							,   SCREAMING_SNAKE_CASE					:   List[Any]=0.0							,   SCREAMING_SNAKE_CASE					:   int=True							,   SCREAMING_SNAKE_CASE					:   int="relu"							,   SCREAMING_SNAKE_CASE					:   Any=2_56							,   SCREAMING_SNAKE_CASE					:   int=0.1							,   SCREAMING_SNAKE_CASE					:   int=0.0							,   SCREAMING_SNAKE_CASE					:   Optional[int]=0.0							,   SCREAMING_SNAKE_CASE					:   List[str]=0.0_2							,   SCREAMING_SNAKE_CASE					:   Optional[int]=1.0							,   SCREAMING_SNAKE_CASE					:   List[str]=False							,   SCREAMING_SNAKE_CASE					:   int="sine"							,   SCREAMING_SNAKE_CASE					:   str="resnet50"							,   SCREAMING_SNAKE_CASE					:   int=True							,   SCREAMING_SNAKE_CASE					:   Tuple=False							,   SCREAMING_SNAKE_CASE					:   Tuple=2							,   SCREAMING_SNAKE_CASE					:   Tuple=5							,   SCREAMING_SNAKE_CASE					:   List[str]=2							,   SCREAMING_SNAKE_CASE					:   List[str]=1							,   SCREAMING_SNAKE_CASE					:   Optional[Any]=1							,   SCREAMING_SNAKE_CASE					:   str=2							,   SCREAMING_SNAKE_CASE					:   Any=5							,   SCREAMING_SNAKE_CASE					:   int=2							,   SCREAMING_SNAKE_CASE					:   List[Any]=0.2_5							,   **SCREAMING_SNAKE_CASE					:   Union[str, Any]							,   ):


      '''simple docstring'''






      if backbone_config is not None and use_timm_backbone:
           raise ValueError("You can't specify both `backbone_config` and `use_timm_backbone`."						)

      if not use_timm_backbone:
           if backbone_config is None:
                logger.info("`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."						)
                UpperCamelCase__			:   Tuple       				=  CONFIG_MAPPING["resnet"](out_features=["stage4"]						)
           elif isinstance(SCREAMING_SNAKE_CASE							,   SCREAMING_SNAKE_CASE						):
                UpperCamelCase__			:   Union[str, Any]       				=  backbone_config.get("model_type"						)
                UpperCamelCase__			:   Tuple       				=  CONFIG_MAPPING[backbone_model_type]
                UpperCamelCase__			:   Any       				=  config_class.from_dict(SCREAMING_SNAKE_CASE						)

      UpperCamelCase__			:   Optional[Any]       				=  use_timm_backbone
      UpperCamelCase__			:   List[Any]       				=  backbone_config
      UpperCamelCase__			:   Tuple       				=  num_channels
      UpperCamelCase__			:   List[Any]       				=  num_queries
      UpperCamelCase__			:   Dict       				=  d_model
      UpperCamelCase__			:   Any       				=  encoder_ffn_dim
      UpperCamelCase__			:   List[str]       				=  encoder_layers
      UpperCamelCase__			:   List[str]       				=  encoder_attention_heads
      UpperCamelCase__			:   Optional[int]       				=  decoder_ffn_dim
      UpperCamelCase__			:   str       				=  decoder_layers
      UpperCamelCase__			:   Optional[Any]       				=  decoder_attention_heads
      UpperCamelCase__			:   int       				=  dropout
      UpperCamelCase__			:   Optional[int]       				=  attention_dropout
      UpperCamelCase__			:   Any       				=  activation_dropout
      UpperCamelCase__			:   int       				=  activation_function
      UpperCamelCase__			:   int       				=  init_std
      UpperCamelCase__			:   List[Any]       				=  init_xavier_std
      UpperCamelCase__			:   List[str]       				=  encoder_layerdrop
      UpperCamelCase__			:   List[Any]       				=  decoder_layerdrop
      UpperCamelCase__			:   List[Any]       				=  encoder_layers
      UpperCamelCase__			:   Optional[Any]       				=  auxiliary_loss
      UpperCamelCase__			:   List[str]       				=  position_embedding_type
      UpperCamelCase__			:   Optional[Any]       				=  backbone
      UpperCamelCase__			:   Optional[int]       				=  use_pretrained_backbone
      UpperCamelCase__			:   List[Any]       				=  dilation
      # Hungarian matcher
      UpperCamelCase__			:   List[str]       				=  class_cost
      UpperCamelCase__			:   Union[str, Any]       				=  bbox_cost
      UpperCamelCase__			:   int       				=  giou_cost
      # Loss coefficients
      UpperCamelCase__			:   str       				=  mask_loss_coefficient
      UpperCamelCase__			:   List[Any]       				=  dice_loss_coefficient
      UpperCamelCase__			:   int       				=  cls_loss_coefficient
      UpperCamelCase__			:   Tuple       				=  bbox_loss_coefficient
      UpperCamelCase__			:   Any       				=  giou_loss_coefficient
      UpperCamelCase__			:   List[Any]       				=  focal_alpha
      super().__init__(is_encoder_decoder=SCREAMING_SNAKE_CASE							,   **SCREAMING_SNAKE_CASE						)







 @property
 def 					__lowercase					(		self					:   Union[str, Any]						):


      '''simple docstring'''






      return self.encoder_attention_heads







 @property
 def 					__lowercase					(		self					:   Tuple						):


      '''simple docstring'''






      return self.d_model







 def 					__lowercase					(		self					:   List[Any]						):


      '''simple docstring'''






      UpperCamelCase__			:   Any       				=  copy.deepcopy(self.__dict__						)
      if self.backbone_config is not None:
           UpperCamelCase__			:   List[str]       				=  self.backbone_config.to_dict()
      UpperCamelCase__			:   int       				=  self.__class__.model_type
      return output







class 			__a  (    A__       ):
 _lowerCAmelCase       :       Tuple        = version.parse('''1.11'''       )







 @property
 def 					__lowercase					(		self					:   Any						):


      '''simple docstring'''






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







 @property
 def 					__lowercase					(		self					:   Tuple						):


      '''simple docstring'''






      return 1e-5







 @property
 def 					__lowercase					(		self					:   List[str]						):


      '''simple docstring'''






      return 12