






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


  """simple docstring"""


  def __init__( self      ,  UpperCamelCase__      ,  UpperCamelCase__=12      ,  UpperCamelCase__=7      ,  UpperCamelCase__=True      ,  UpperCamelCase__=True      ,  UpperCamelCase__=True      ,  UpperCamelCase__=99      ,  UpperCamelCase__=32      ,  UpperCamelCase__=32      ,  UpperCamelCase__=5      ,  UpperCamelCase__=4      ,  UpperCamelCase__=37      ,  UpperCamelCase__=0.1      ,  UpperCamelCase__=0.1      ,  UpperCamelCase__=512      ,  UpperCamelCase__=0.02      ,  UpperCamelCase__=0      ,  UpperCamelCase__=None      ,  ):






         """simple docstring"""


         a_	    = parent
         a_	    = batch_size
         a_	    = seq_length
         a_	    = is_training
         a_	    = use_input_mask
         a_	    = use_labels
         a_	    = vocab_size
         a_	    = hidden_size
         a_	    = projection_dim
         a_	    = num_hidden_layers
         a_	    = num_attention_heads
         a_	    = intermediate_size
         a_	    = dropout
         a_	    = attention_dropout
         a_	    = max_position_embeddings
         a_	    = initializer_range
         a_	    = scope
         a_	    = bos_token_id







  def       _a					( self  ):






         """simple docstring"""


         a_	    = ids_tensor([self.batch_size, self.seq_length]      ,  self.vocab_size  )

         a_	    = None
         if self.use_input_mask:
                a_	    = random_attention_mask([self.batch_size, self.seq_length]  )

         if input_mask is not None:
                a_    ,					a_	    = input_mask.shape
                a_	    = np.random.randint(1      ,  seq_length - 1      ,  size=(batch_size,)  )
                for batch_idx, start_index in enumerate(UpperCamelCase__  ):
                       a_	    = 1
                       a_	    = 0

         a_	    = self.get_config()

         return config, input_ids, input_mask







  def       _a					( self  ):






         """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       _a					( self      ,  UpperCamelCase__      ,  UpperCamelCase__      ,  UpperCamelCase__  ):






         """simple docstring"""


         a_	    = BlipTextModel(config=UpperCamelCase__  )
         model.to(UpperCamelCase__  )
         model.eval()
         with torch.no_grad():
                a_	    = model(UpperCamelCase__      ,  attention_mask=UpperCamelCase__  )
                a_	    = model(UpperCamelCase__  )
         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       _a					( self  ):






         """simple docstring"""


         a_	    = self.prepare_config_and_inputs()
         a_    ,					a_    ,					a_	    = config_and_inputs
         a_	    = {'input_ids': input_ids, 'attention_mask': input_mask}
         return config, inputs_dict





@require_torch
class      __SCREAMING_SNAKE_CASE					(__A       ,					unittest.TestCase					):


  """simple docstring"""


  _a     :   Dict			 =    (BlipTextModel,) if is_torch_available() else ()
  _a     :   str			 =    False
  _a     :   str			 =    False
  _a     :   str			 =    False







  def       _a					( self  ):






         """simple docstring"""


         a_	    = BlipTextModelTester(self  )
         a_	    = ConfigTester(self      ,  config_class=UpperCamelCase__      ,  hidden_size=37  )







  def       _a					( self  ):






         """simple docstring"""


         self.config_tester.run_common_tests()







  def       _a					( self  ):






         """simple docstring"""


         a_	    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*UpperCamelCase__  )







  def       _a					( self  ):






         """simple docstring"""


         pass







  def       _a					( self  ):






         """simple docstring"""


         pass







  @unittest.skip(reason='Blip does not use inputs_embeds'  )
  def       _a					( self  ):






         """simple docstring"""


         pass







  @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'  )
  def       _a					( self  ):






         """simple docstring"""


         pass







  @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'  )
  def       _a					( self  ):






         """simple docstring"""


         pass







  @slow
  def       _a					( self  ):






         """simple docstring"""


         for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                a_	    = BlipTextModel.from_pretrained(UpperCamelCase__  )
                self.assertIsNotNone(UpperCamelCase__  )







  def       _a					( self  ):






         """simple docstring"""


         super().test_pt_tf_model_equivalence(allow_missing_keys=UpperCamelCase__  )












'''simple docstring'''







from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCAmelCase					   =       logging.get_logger(__name__)

__lowerCAmelCase					   =       {
    "uw-madison/nystromformer-512": "https://huggingface.co/uw-madison/nystromformer-512/resolve/main/config.json",
    # See all Nystromformer models at https://huggingface.co/models?filter=nystromformer
}




class      __SCREAMING_SNAKE_CASE					(__A					):


  """simple docstring"""


  _a     :   Union[str, Any]			 =    '''nystromformer'''







  def __init__( self      ,  UpperCamelCase__=30_000      ,  UpperCamelCase__=768      ,  UpperCamelCase__=12      ,  UpperCamelCase__=12      ,  UpperCamelCase__=3_072      ,  UpperCamelCase__="gelu_new"      ,  UpperCamelCase__=0.1      ,  UpperCamelCase__=0.1      ,  UpperCamelCase__=510      ,  UpperCamelCase__=2      ,  UpperCamelCase__=64      ,  UpperCamelCase__=64      ,  UpperCamelCase__=65      ,  UpperCamelCase__=False      ,  UpperCamelCase__=0.02      ,  UpperCamelCase__=1e-5      ,  UpperCamelCase__=1      ,  UpperCamelCase__=0      ,  UpperCamelCase__=2      ,  **UpperCamelCase__      ,  ):






         """simple docstring"""


         a_	    = vocab_size
         a_	    = max_position_embeddings
         a_	    = hidden_size
         a_	    = num_hidden_layers
         a_	    = num_attention_heads
         a_	    = intermediate_size
         a_	    = hidden_act
         a_	    = hidden_dropout_prob
         a_	    = attention_probs_dropout_prob
         a_	    = initializer_range
         a_	    = type_vocab_size
         a_	    = segment_means_seq_len
         a_	    = num_landmarks
         a_	    = conv_kernel_size
         a_	    = inv_coeff_init_option
         a_	    = layer_norm_eps
         super().__init__(pad_token_id=UpperCamelCase__      ,  bos_token_id=UpperCamelCase__      ,  eos_token_id=UpperCamelCase__      ,  **UpperCamelCase__  )




