


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

 def __init__(			self			:						Any,       a_			:						Optional[Any],       a_			:						Any=12,       a_			:						Union[str, Any]=7,       a_			:						int=True,       a_			:						Dict=True,       a_			:						Any=True,       a_			:						Tuple=99,       a_			:						Tuple=32,       a_			:						Any=32,       a_			:						Optional[Any]=5,       a_			:						Tuple=4,       a_			:						List[str]=37,       a_			:						Optional[Any]=0.1,       a_			:						List[str]=0.1,       a_			:						List[str]=512,       a_			:						List[Any]=0.02,       a_			:						List[str]=0,       a_			:						int=None,       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						List[str]       ):





    """simple docstring"""



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

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

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

    UpperCamelCase__			    =    self.get_config()

    return config, input_ids, input_mask

 def 		lowercase_    (			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 		lowercase_    (			self			:						Any,       a_			:						Optional[int],       a_			:						Union[str, Any],       a_			:						Union[str, Any]       ):





    """simple docstring"""



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





    """simple docstring"""



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







@require_torch
class 			UpperCAmelCase			(							SCREAMING_SNAKE_CASE__		,      unittest.TestCase):
 _lowerCamelCase			:       Union[str, Any]            =       (BlipTextModel,) if is_torch_available() else ()
 _lowerCamelCase			:       int            =       False
 _lowerCamelCase			:       int            =       False
 _lowerCamelCase			:       Optional[int]            =       False

 def 		lowercase_    (			self			:						List[str]       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						Tuple       ):





    """simple docstring"""



    self.config_tester.run_common_tests()

 def 		lowercase_    (			self			:						Optional[Any]       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						Any       ):





    """simple docstring"""



    pass

 def 		lowercase_    (			self			:						Optional[Any]       ):





    """simple docstring"""



    pass

 @unittest.skip(reason="Blip does not use inputs_embeds"       )
 def 		lowercase_    (			self			:						List[str]       ):





    """simple docstring"""



    pass

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





    """simple docstring"""



    pass

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





    """simple docstring"""



    pass

 @slow
 def 		lowercase_    (			self			:						List[str]       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						Dict       ):





    """simple docstring"""



    super().test_pt_tf_model_equivalence(allow_missing_keys=a_       )


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


UpperCAmelCase__			:  Dict					     =     {"""configuration_hubert""": ["""HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """HubertConfig"""]}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__			:  Union[str, Any]					     =     [
      """HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """HubertForCTC""",
      """HubertForSequenceClassification""",
      """HubertModel""",
      """HubertPreTrainedModel""",
  ]


try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__			:  List[Any]					     =     [
      """TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """TFHubertForCTC""",
      """TFHubertModel""",
      """TFHubertPreTrainedModel""",
  ]

if TYPE_CHECKING:
  from .configuration_hubert import HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, HubertConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_hubert import (
        HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        HubertForCTC,
        HubertForSequenceClassification,
        HubertModel,
        HubertPreTrainedModel,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_hubert import (
        TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFHubertForCTC,
        TFHubertModel,
        TFHubertPreTrainedModel,
    )


else:
  import sys

  UpperCAmelCase__			:  str					     =     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




