

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

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

							"""simple docstring"""



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

						def 	_UpperCAmelCase							(		self	:						Optional[int])						->str:

							"""simple docstring"""



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

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

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

							_lowercase							=     self.get_config()

							return config, input_ids, input_mask

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

							"""simple docstring"""



							_lowercase							=     BlipTextModel(config=lowercase__)
							model.to(lowercase__)
							model.eval()
							with torch.no_grad():
								_lowercase							=     model(lowercase__    ,			attention_mask=lowercase__)
								_lowercase							=     model(lowercase__)
							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)						->Any:

							"""simple docstring"""



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






@require_torch
class 					__a   (		_snake_case							,unittest.TestCase  ):
						__SCREAMING_SNAKE_CASE     :					Optional[int]  =      (BlipTextModel,) if is_torch_available() else ()
						__SCREAMING_SNAKE_CASE     :					str  =      False
						__SCREAMING_SNAKE_CASE     :					int  =      False
						__SCREAMING_SNAKE_CASE     :					Tuple  =      False

						def 	_UpperCAmelCase							(		self	:						Union[str, Any])						->Any:

							"""simple docstring"""



							_lowercase							=     BlipTextModelTester(self)
							_lowercase							=     ConfigTester(self    ,			config_class=lowercase__    ,			hidden_size=37)

						def 	_UpperCAmelCase							(		self	:						str)						->Union[str, Any]:

							"""simple docstring"""



							self.config_tester.run_common_tests()

						def 	_UpperCAmelCase							(		self	:						Optional[int])						->str:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowercase__)

						def 	_UpperCAmelCase							(		self	:						Union[str, Any])						->Any:

							"""simple docstring"""



							pass

						def 	_UpperCAmelCase							(		self	:						int)						->str:

							"""simple docstring"""



							pass

						@unittest.skip(reason="""Blip does not use inputs_embeds""")
						def 	_UpperCAmelCase							(		self	:						List[Any])						->int:

							"""simple docstring"""



							pass

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

							"""simple docstring"""



							pass

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

							"""simple docstring"""



							pass

						@slow
						def 	_UpperCAmelCase							(		self	:						Tuple)						->Any:

							"""simple docstring"""



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


						def 	_UpperCAmelCase							(		self	:						int)						->List[Any]:

							"""simple docstring"""



							super().test_pt_tf_model_equivalence(allow_missing_keys=lowercase__)







'''simple docstring'''







from collections import namedtuple

_lowerCamelCase    =  namedtuple('from_to', 'from_ to')

_lowerCamelCase    =  {
    'millimeter': 'mm',
    'centimeter': 'cm',
    'meter': 'm',
    'kilometer': 'km',
    'inch': 'in',
    'inche': 'in',  # Trailing 's' has been stripped off
    'feet': 'ft',
    'foot': 'ft',
    'yard': 'yd',
    'mile': 'mi',
}

_lowerCamelCase    =  {
    'mm': from_to(0.001, 1_0_0_0),
    'cm': from_to(0.01, 1_0_0),
    'm': from_to(1, 1),
    'km': from_to(1_0_0_0, 0.001),
    'in': from_to(0.0254, 39.3701),
    'ft': from_to(0.3048, 3.2_8084),
    'yd': from_to(0.9144, 1.0_9361),
    'mi': from_to(1609.34, 0.0_0062_1371),
}






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_							,       snake_case_	):
	_lowercase							=     from_type.lower().rstrip("""s"""	)
	_lowercase							=     TYPE_CONVERSION.get(snake_case_							,       snake_case_	)
	_lowercase							=     to_type.lower().rstrip("""s"""	)
	_lowercase							=     TYPE_CONVERSION.get(snake_case_							,       snake_case_	)
	if new_from not in METRIC_CONVERSION:
		_lowercase							=     (
		    F"""Invalid 'from_type' value: {from_type!r}.\n"""
		    F"""Conversion abbreviations are: {", ".join(snake_case_	)}"""
		)
		raise ValueError(snake_case_	)
	if new_to not in METRIC_CONVERSION:
		_lowercase							=     (
		    F"""Invalid 'to_type' value: {to_type!r}.\n"""
		    F"""Conversion abbreviations are: {", ".join(snake_case_	)}"""
		)
		raise ValueError(snake_case_	)
	return value * METRIC_CONVERSION[new_from].from_ * METRIC_CONVERSION[new_to].to


if __name__ == "__main__":
							import doctest

							doctest.testmod()




