'''simple docstring'''

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask


if is_torch_available():
      import torch

      from transformers import BlipTextModel
      from transformers.models.blip.modeling_blip import BLIP_PRETRAINED_MODEL_ARCHIVE_LIST




class    lowerCamelCase__  :



   def __init__(    self					,      lowerCAmelCase__					,      lowerCAmelCase__=12					,      lowerCAmelCase__=7					,      lowerCAmelCase__=True					,      lowerCAmelCase__=True					,      lowerCAmelCase__=True					,      lowerCAmelCase__=99					,      lowerCAmelCase__=32					,      lowerCAmelCase__=32					,      lowerCAmelCase__=5					,      lowerCAmelCase__=4					,      lowerCAmelCase__=37					,      lowerCAmelCase__=0.1					,      lowerCAmelCase__=0.1					,      lowerCAmelCase__=512					,      lowerCAmelCase__=0.02					,      lowerCAmelCase__=0					,      lowerCAmelCase__=None					,      )				->     Optional[int]:
        """simple docstring"""





        _UpperCamelCase  :Optional[int]       =parent
        _UpperCamelCase  :List[str]       =batch_size
        _UpperCamelCase  :Tuple       =seq_length
        _UpperCamelCase  :int       =is_training
        _UpperCamelCase  :Optional[Any]       =use_input_mask
        _UpperCamelCase  :Any       =use_labels
        _UpperCamelCase  :List[Any]       =vocab_size
        _UpperCamelCase  :Optional[Any]       =hidden_size
        _UpperCamelCase  :str       =projection_dim
        _UpperCamelCase  :Tuple       =num_hidden_layers
        _UpperCamelCase  :int       =num_attention_heads
        _UpperCamelCase  :Optional[int]       =intermediate_size
        _UpperCamelCase  :List[Any]       =dropout
        _UpperCamelCase  :Dict       =attention_dropout
        _UpperCamelCase  :Optional[int]       =max_position_embeddings
        _UpperCamelCase  :Optional[Any]       =initializer_range
        _UpperCamelCase  :Optional[Any]       =scope
        _UpperCamelCase  :Tuple       =bos_token_id



   def  _UpperCamelCase		(    self     )				->     Optional[Any]:
        """simple docstring"""





        _UpperCamelCase  :Any       =ids_tensor([self.batch_size, self.seq_length]					,      self.vocab_size     )

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

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

        _UpperCamelCase  :Any       =self.get_config()

        return config, input_ids, input_mask



   def  _UpperCamelCase		(    self     )				->     Dict:
        """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  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     Tuple:
        """simple docstring"""





        _UpperCamelCase  :Tuple       =BlipTextModel(config=lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()
        with torch.no_grad():
             _UpperCamelCase  :Union[str, Any]       =model(lowerCAmelCase__					,      attention_mask=lowerCAmelCase__     )
             _UpperCamelCase  :Optional[Any]       =model(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  _UpperCamelCase		(    self     )				->     Dict:
        """simple docstring"""





        _UpperCamelCase  :str       =self.prepare_config_and_inputs()
        _UpperCamelCase       ,      _UpperCamelCase       ,      _UpperCamelCase  :Union[str, Any]       =config_and_inputs
        _UpperCamelCase  :Tuple       ={"""input_ids""": input_ids, """attention_mask""": input_mask}
        return config, inputs_dict




@require_torch
class    lowerCamelCase__  (   __snake_case       ,				unittest.TestCase     ):
   __UpperCAmelCase           =						(BlipTextModel,) if is_torch_available() else ()
   __UpperCAmelCase           =						False
   __UpperCAmelCase           =						False
   __UpperCAmelCase           =						False



   def  _UpperCamelCase		(    self     )				->     Optional[Any]:
        """simple docstring"""





        _UpperCamelCase  :int       =BlipTextModelTester(self     )
        _UpperCamelCase  :int       =ConfigTester(self					,      config_class=lowerCAmelCase__					,      hidden_size=37     )



   def  _UpperCamelCase		(    self     )				->     int:
        """simple docstring"""





        self.config_tester.run_common_tests()



   def  _UpperCamelCase		(    self     )				->     List[str]:
        """simple docstring"""





        _UpperCamelCase  :Optional[int]       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     Tuple:
        """simple docstring"""





        pass



   def  _UpperCamelCase		(    self     )				->     Any:
        """simple docstring"""





        pass



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





        pass



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





        pass



   @unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""     )
   def  _UpperCamelCase		(    self     )				->     Dict:
        """simple docstring"""





        pass



   @slow
   def  _UpperCamelCase		(    self     )				->     List[str]:
        """simple docstring"""





        for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             _UpperCamelCase  :List[Any]       =BlipTextModel.from_pretrained(lowerCAmelCase__     )
             self.assertIsNotNone(lowerCAmelCase__     )




   def  _UpperCamelCase		(    self     )				->     Dict:
        """simple docstring"""





        super().test_pt_tf_model_equivalence(allow_missing_keys=lowerCAmelCase__     )



'''simple docstring'''

from collections import OrderedDict
from typing import Mapping

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


__lowercase:		List[str]    						=  logging.get_logger(__name__)

__lowercase:		List[Any]    						=  {
    "uclanlp/plbart-base": "https://huggingface.co/uclanlp/plbart-base/resolve/main/config.json",
    # See all PLBART models at https://huggingface.co/models?filter=plbart
}







class 			UpperCAmelCase			(							SCREAMING_SNAKE_CASE__):
 _lowerCamelCase			:       Optional[int]            =       'plbart'
 _lowerCamelCase			:       Union[str, Any]            =       ['past_key_values']
 _lowerCamelCase			:       Tuple            =       {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}

 def __init__(			self			:						Optional[Any],       a_			:						Union[str, Any]=5_0005,       a_			:						int=1024,       a_			:						str=6,       a_			:						Union[str, Any]=3072,       a_			:						Optional[int]=12,       a_			:						Optional[Any]=6,       a_			:						Dict=3072,       a_			:						Dict=12,       a_			:						int=0.0,       a_			:						List[Any]=0.0,       a_			:						Optional[Any]=True,       a_			:						List[str]=True,       a_			:						Tuple="gelu",       a_			:						Any=768,       a_			:						Dict=0.1,       a_			:						List[Any]=0.1,       a_			:						Union[str, Any]=0.0,       a_			:						Optional[Any]=0.02,       a_			:						Union[str, Any]=0.0,       a_			:						int=True,       a_			:						Dict=1,       a_			:						Optional[int]=0,       a_			:						Optional[int]=2,       a_			:						Any=2,       **a_			:						Optional[Any],       ):





    """simple docstring"""



    UpperCamelCase__			    =    vocab_size
    UpperCamelCase__			    =    max_position_embeddings
    UpperCamelCase__			    =    d_model
    UpperCamelCase__			    =    encoder_ffn_dim
    UpperCamelCase__			    =    encoder_layers
    UpperCamelCase__			    =    encoder_attention_heads
    UpperCamelCase__			    =    decoder_ffn_dim
    UpperCamelCase__			    =    decoder_layers
    UpperCamelCase__			    =    decoder_attention_heads
    UpperCamelCase__			    =    dropout
    UpperCamelCase__			    =    attention_dropout
    UpperCamelCase__			    =    activation_dropout
    UpperCamelCase__			    =    activation_function
    UpperCamelCase__			    =    init_std
    UpperCamelCase__			    =    encoder_layerdrop
    UpperCamelCase__			    =    decoder_layerdrop
    UpperCamelCase__			    =    classifier_dropout
    UpperCamelCase__			    =    use_cache
    UpperCamelCase__			    =    encoder_layers
    UpperCamelCase__			    =    scale_embedding  # scale factor will be sqrt(d_model) if True
    super().__init__(
        pad_token_id=a_,       bos_token_id=a_,       eos_token_id=a_,       is_encoder_decoder=a_,       forced_eos_token_id=a_,       **a_,       )







class 			UpperCAmelCase			(							SCREAMING_SNAKE_CASE__):

 @property
 def 		lowercase_    (			self			:						int       ):





    """simple docstring"""



    return OrderedDict(
        [
            ("input_ids", {0: "batch", 1: "sequence"}),
            ("attention_mask", {0: "batch", 1: "sequence"}),
        ]       )

 @property
 def 		lowercase_    (			self			:						Tuple       ):





    """simple docstring"""



    if self.use_past:
       return OrderedDict(
           [
               ("last_hidden_state", {0: "batch", 1: "sequence"}),
               ("past_keys", {0: "batch", 2: "sequence"}),
               ("encoder_last_hidden_state", {0: "batch", 1: "sequence"}),
           ]       )
    else:
       return OrderedDict(
           [
               ("last_hidden_state", {0: "batch", 1: "sequence"}),
               ("encoder_last_hidden_state", {0: "batch", 1: "sequence"}),
           ]       )