




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





     '''simple docstring'''



     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							,)      ->				List[Any]:
          snake_case			:      int        =			parent
          snake_case			:      Any        =			batch_size
          snake_case			:      Optional[int]        =			seq_length
          snake_case			:      Tuple        =			is_training
          snake_case			:      Optional[Any]        =			use_input_mask
          snake_case			:      int        =			use_labels
          snake_case			:      List[Any]        =			vocab_size
          snake_case			:      Tuple        =			hidden_size
          snake_case			:      Any        =			projection_dim
          snake_case			:      List[str]        =			num_hidden_layers
          snake_case			:      Any        =			num_attention_heads
          snake_case			:      Dict        =			intermediate_size
          snake_case			:      Optional[Any]        =			dropout
          snake_case			:      Dict        =			attention_dropout
          snake_case			:      Dict        =			max_position_embeddings
          snake_case			:      Optional[Any]        =			initializer_range
          snake_case			:      Optional[Any]        =			scope
          snake_case			:      int        =			bos_token_id







     def 			snake_case_      (				self							)      ->				Optional[Any]:
          snake_case			:      List[Any]        =			ids_tensor([self.batch_size, self.seq_length]							,self.vocab_size							)

          snake_case			:      Optional[int]        =			None
          if self.use_input_mask:
               snake_case			:      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			:      Optional[int]        =			np.random.randint(1							,seq_length - 1							,size=(batch_size,)							)
               for batch_idx, start_index in enumerate(__a							):
                    snake_case			:      Any        =			1
                    snake_case			:      Optional[Any]        =			0

          snake_case			:      Tuple        =			self.get_config()

          return config, input_ids, tf.convert_to_tensor(__a							)







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







@require_tf
class 					_a (a__,		unittest.TestCase	):





     '''simple docstring'''



     lowerCAmelCase_  :     Optional[Any]          =					(TFBlipTextModel,) if is_tf_available() else ()
     lowerCAmelCase_  :     Union[str, Any]          =					False
     lowerCAmelCase_  :     Any          =					False
     lowerCAmelCase_  :     Dict          =					False







     def 			snake_case_      (				self							)      ->				int:
          snake_case			:      List[str]        =			BlipTextModelTester(self							)
          snake_case			:      List[Any]        =			ConfigTester(self							,config_class=__a							,hidden_size=37							)







     def 			snake_case_      (				self							)      ->				Optional[int]:
          self.config_tester.run_common_tests()







     def 			snake_case_      (				self							)      ->				Optional[int]:
          snake_case			:      Optional[Any]        =			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*__a							)







     def 			snake_case_      (				self							)      ->				str:
          pass







     def 			snake_case_      (				self							)      ->				Dict:
          pass







     @unittest.skip(reason="""Blip does not use inputs_embeds"""							)
     def 			snake_case_      (				self							)      ->				Dict:
          pass







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







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







     @slow
     def 			snake_case_      (				self							)      ->				str:
          for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               snake_case			:      List[str]        =			TFBlipTextModel.from_pretrained(__a							)
               self.assertIsNotNone(__a							)







     def 			snake_case_      (				self							,__a=True							)      ->				Tuple:
          super().test_pt_tf_model_equivalence(allow_missing_keys=__a							)









'''simple docstring'''







import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


lowercase      :   Tuple      =       logging.get_logger(__name__)

lowercase      :   Dict      =       {
    """ut/deta""": """https://huggingface.co/ut/deta/resolve/main/config.json""",
}







class 					_a (a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     str          =					"""deta"""
     lowerCAmelCase_  :     Any          =					{
         """hidden_size""": """d_model""",
         """num_attention_heads""": """encoder_attention_heads""",
     }







     def __init__(				self							,__a=None							,__a=900							,__a=2_048							,__a=6							,__a=2_048							,__a=8							,__a=6							,__a=1_024							,__a=8							,__a=0.0							,__a=True							,__a="relu"							,__a=256							,__a=0.1							,__a=0.0							,__a=0.0							,__a=0.02							,__a=1.0							,__a=True							,__a=False							,__a="sine"							,__a=5							,__a=4							,__a=4							,__a=True							,__a=300							,__a=True							,__a=True							,__a=1							,__a=5							,__a=2							,__a=1							,__a=1							,__a=5							,__a=2							,__a=0.1							,__a=0.25							,**__a							,)      ->				int:
          if backbone_config is None:
               logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""							)
               snake_case			:      int        =			CONFIG_MAPPING["""resnet"""](out_features=["""stage2""", """stage3""", """stage4"""]							)
          else:
               if isinstance(__a							,__a							):
                    snake_case			:      str        =			backbone_config.pop("""model_type"""							)
                    snake_case			:      Optional[Any]        =			CONFIG_MAPPING[backbone_model_type]
                    snake_case			:      List[Any]        =			config_class.from_dict(__a							)

          snake_case			:      Any        =			backbone_config
          snake_case			:      Optional[Any]        =			num_queries
          snake_case			:      Dict        =			max_position_embeddings
          snake_case			:      int        =			d_model
          snake_case			:      str        =			encoder_ffn_dim
          snake_case			:      Dict        =			encoder_layers
          snake_case			:      List[Any]        =			encoder_attention_heads
          snake_case			:      int        =			decoder_ffn_dim
          snake_case			:      List[Any]        =			decoder_layers
          snake_case			:      Dict        =			decoder_attention_heads
          snake_case			:      Dict        =			dropout
          snake_case			:      Dict        =			attention_dropout
          snake_case			:      List[Any]        =			activation_dropout
          snake_case			:      Dict        =			activation_function
          snake_case			:      List[Any]        =			init_std
          snake_case			:      Any        =			init_xavier_std
          snake_case			:      List[Any]        =			encoder_layerdrop
          snake_case			:      Optional[Any]        =			auxiliary_loss
          snake_case			:      Optional[int]        =			position_embedding_type
          # deformable attributes
          snake_case			:      Tuple        =			num_feature_levels
          snake_case			:      List[Any]        =			encoder_n_points
          snake_case			:      Dict        =			decoder_n_points
          snake_case			:      int        =			two_stage
          snake_case			:      Any        =			two_stage_num_proposals
          snake_case			:      List[str]        =			with_box_refine
          snake_case			:      Tuple        =			assign_first_stage
          if two_stage is True and with_box_refine is False:
               raise ValueError("""If two_stage is True, with_box_refine must be True."""							)
          # Hungarian matcher
          snake_case			:      Optional[int]        =			class_cost
          snake_case			:      int        =			bbox_cost
          snake_case			:      Optional[int]        =			giou_cost
          # Loss coefficients
          snake_case			:      str        =			mask_loss_coefficient
          snake_case			:      Any        =			dice_loss_coefficient
          snake_case			:      List[Any]        =			bbox_loss_coefficient
          snake_case			:      List[Any]        =			giou_loss_coefficient
          snake_case			:      List[str]        =			eos_coefficient
          snake_case			:      Optional[Any]        =			focal_alpha
          super().__init__(is_encoder_decoder=__a							,**__a							)







     @property
     def 			snake_case_      (				self							)      ->				int:
          return self.encoder_attention_heads







     @property
     def 			snake_case_      (				self							)      ->				int:
          return self.d_model







     def 			snake_case_      (				self							)      ->				List[str]:
          snake_case			:      List[str]        =			copy.deepcopy(self.__dict__							)
          snake_case			:      List[str]        =			self.backbone_config.to_dict()
          snake_case			:      List[Any]        =			self.__class__.model_type
          return output



