





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


				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.0_2 ,			UpperCAmelCase_=0 ,			UpperCAmelCase_=None ,			):
								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 _snake_case							(		self				):
								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			,	lowerCamelCase									=input_mask.shape
												lowerCamelCase									=np.random.randint(1 ,			seq_length - 1 ,			size=(batch_size,)				)
												for batch_idx, start_index in enumerate(UpperCAmelCase_				):
																lowerCamelCase									=1
																lowerCamelCase									=0

								lowerCamelCase									=self.get_config()

								return config, input_ids, input_mask


				def _snake_case							(		self				):
								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 ,			UpperCAmelCase_ ,			UpperCAmelCase_ ,			UpperCAmelCase_				):
								lowerCamelCase									=BlipTextModel(config=UpperCAmelCase_				)
								model.to(UpperCAmelCase_				)
								model.eval()
								with torch.no_grad():
												lowerCamelCase									=model(UpperCAmelCase_ ,			attention_mask=UpperCAmelCase_				)
												lowerCamelCase									=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 _snake_case							(		self				):
								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_torch
class    __A  (    __snake_case     ,       unittest.TestCase     ):
				__A  =					(BlipTextModel,) if is_torch_available() else ()
				__A  =					False
				__A  =					False
				__A  =					False


				def _snake_case							(		self				):
								lowerCamelCase									=BlipTextModelTester(self				)
								lowerCamelCase									=ConfigTester(self ,			config_class=UpperCAmelCase_ ,			hidden_size=37				)


				def _snake_case							(		self				):
								self.config_tester.run_common_tests()


				def _snake_case							(		self				):
								lowerCamelCase									=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*UpperCAmelCase_				)


				def _snake_case							(		self				):
								pass


				def _snake_case							(		self				):
								pass


				@unittest.skip(reason="""Blip does not use inputs_embeds"""				)
				def _snake_case							(		self				):
								pass


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


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


				@slow
				def _snake_case							(		self				):
								for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												lowerCamelCase									=BlipTextModel.from_pretrained(UpperCAmelCase_				)
												self.assertIsNotNone(UpperCAmelCase_				)


				def _snake_case							(		self				):
								super().test_pt_tf_model_equivalence(allow_missing_keys=UpperCAmelCase_				)








def   UpperCamelCase(   lowercase_				)      ->							float:





  '''simple docstring'''





  return -num if num < 0 else num



def   UpperCamelCase(   lowercase_				)      ->							int:





  '''simple docstring'''





  if len(lowercase_				) == 0:
    raise ValueError("""abs_min() arg is an empty sequence"""				)
  snake_case_					= x[0]
  for i in x:
    if abs_val(lowercase_				) < abs_val(lowercase_				):
      snake_case_					= i
  return j



def   UpperCamelCase(   lowercase_				)      ->							int:





  '''simple docstring'''





  if len(lowercase_				) == 0:
    raise ValueError("""abs_max() arg is an empty sequence"""				)
  snake_case_					= x[0]
  for i in x:
    if abs(lowercase_				) > abs(lowercase_				):
      snake_case_					= i
  return j



def   UpperCamelCase(   lowercase_				)      ->							int:





  '''simple docstring'''





  if len(lowercase_				) == 0:
    raise ValueError("""abs_max_sort() arg is an empty sequence"""				)
  return sorted(lowercase_     ,   key=lowercase_				)[-1]



def   UpperCamelCase(   )      ->							List[Any]:





  '''simple docstring'''





  assert abs_val(0				) == 0
  assert abs_val(34				) == 34
  assert abs_val(-100000000000				) == 100000000000

  snake_case_					= [-3, -1, 2, -11]
  assert abs_max(lowercase_				) == -11
  assert abs_max_sort(lowercase_				) == -11
  assert abs_min(lowercase_				) == -1


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    test_abs_val()
    print(abs_val(-34))  # --> 34