



'''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			,							__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			,							)							->  Union[str, Any]:

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





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

					'''simple docstring'''
					__UpperCAmelCase :   int    					=  ids_tensor([self.batch_size, self.seq_length]			,							self.vocab_size					)

					__UpperCAmelCase :   Dict    					=  None
					if self.use_input_mask:
								__UpperCAmelCase :   Optional[int]    					=  random_attention_mask([self.batch_size, self.seq_length]					)

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

					__UpperCAmelCase :   str    					=  self.get_config()

					return config, input_ids, input_mask





		def 				__A							(  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 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  str:

					'''simple docstring'''
					__UpperCAmelCase :   Optional[Any]    					=  BlipTextModel(config=__UpperCAmelCase					)
					model.to(__UpperCAmelCase					)
					model.eval()
					with torch.no_grad():
								__UpperCAmelCase :   Union[str, Any]    					=  model(__UpperCAmelCase			,							attention_mask=__UpperCAmelCase					)
								__UpperCAmelCase :   List[Any]    					=  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					)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   Optional[Any]    					=  self.prepare_config_and_inputs()
					__UpperCAmelCase					,	__UpperCAmelCase					,	__UpperCAmelCase :   Tuple    					=  config_and_inputs
					__UpperCAmelCase :   Optional[Any]    					=  {"""input_ids""": input_ids, """attention_mask""": input_mask}
					return config, inputs_dict



@require_torch
class _A	(     __SCREAMING_SNAKE_CASE						,					unittest.TestCase     ):
		_SCREAMING_SNAKE_CASE       :     Union[str, Any]       =      (BlipTextModel,) if is_torch_available() else ()
		_SCREAMING_SNAKE_CASE       :     List[Any]       =      False
		_SCREAMING_SNAKE_CASE       :     Any       =      False
		_SCREAMING_SNAKE_CASE       :     str       =      False





		def 				__A							(  self					)							->  Tuple:

					'''simple docstring'''
					__UpperCAmelCase :   List[str]    					=  BlipTextModelTester(self					)
					__UpperCAmelCase :   Optional[Any]    					=  ConfigTester(self			,							config_class=__UpperCAmelCase			,							hidden_size=37					)





		def 				__A							(  self					)							->  List[str]:

					'''simple docstring'''
					self.config_tester.run_common_tests()





		def 				__A							(  self					)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   int    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__UpperCAmelCase					)





		def 				__A							(  self					)							->  Dict:

					'''simple docstring'''
					pass





		def 				__A							(  self					)							->  Dict:

					'''simple docstring'''
					pass





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

					'''simple docstring'''
					pass





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

					'''simple docstring'''
					pass





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

					'''simple docstring'''
					pass





		@slow
		def 				__A							(  self					)							->  Dict:

					'''simple docstring'''
					for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								__UpperCAmelCase :   str    					=  BlipTextModel.from_pretrained(__UpperCAmelCase					)
								self.assertIsNotNone(__UpperCAmelCase					)





		def 				__A							(  self					)							->  Optional[Any]:

					'''simple docstring'''
					super().test_pt_tf_model_equivalence(allow_missing_keys=__UpperCAmelCase					)









'''simple docstring'''
from __future__ import annotations


def 	lowercase_						( lowerCAmelCase__						:	int      ,				lowerCAmelCase__						:	int      ,				lowerCAmelCase__						:	int			):

			"""simple docstring"""





			assert (
			    c % greatest_common_divisor(lowerCAmelCase__      ,				lowerCAmelCase__			) == 0
			)  # greatest_common_divisor(a,b) function implemented below
			((__UpperCAmelCase)					,	(__UpperCAmelCase)					,	(__UpperCAmelCase)) :   int    					=  extended_gcd(lowerCAmelCase__      ,				lowerCAmelCase__			)  # extended_gcd(a,b) function implemented below
			__UpperCAmelCase :   Union[str, Any]    					=  c / d
			return (r * x, r * y)


def 	lowercase_						( lowerCAmelCase__						:	int      ,				lowerCAmelCase__						:	int      ,				lowerCAmelCase__						:	int      ,				lowerCAmelCase__						:	int = 2			):

			"""simple docstring"""





			((__UpperCAmelCase)					,	(__UpperCAmelCase)) :   List[str]    					=  diophantine(lowerCAmelCase__      ,				lowerCAmelCase__      ,				lowerCAmelCase__			)  # Initial value
			__UpperCAmelCase :   List[str]    					=  greatest_common_divisor(lowerCAmelCase__      ,				lowerCAmelCase__			)
			__UpperCAmelCase :   List[str]    					=  a // d
			__UpperCAmelCase :   Tuple    					=  b // d

			for i in range(lowerCAmelCase__			):
						__UpperCAmelCase :   List[Any]    					=  xa + i * q
						__UpperCAmelCase :   Tuple    					=  ya - i * p
						print(lowerCAmelCase__      ,				lowerCAmelCase__			)


def 	lowercase_						( lowerCAmelCase__						:	int      ,				lowerCAmelCase__						:	int			):

			"""simple docstring"""





			if a < b:
						__UpperCAmelCase					,	__UpperCAmelCase :   List[str]    					=  b, a

			while a % b != 0:
						__UpperCAmelCase					,	__UpperCAmelCase :   Optional[int]    					=  b, a % b

			return b


def 	lowercase_						( lowerCAmelCase__						:	int      ,				lowerCAmelCase__						:	int			):

			"""simple docstring"""





			assert a >= 0 and b >= 0

			if b == 0:
						__UpperCAmelCase					,	__UpperCAmelCase					,	__UpperCAmelCase :   List[str]    					=  a, 1, 0
			else:
						((__UpperCAmelCase)					,	(__UpperCAmelCase)					,	(__UpperCAmelCase)) :   str    					=  extended_gcd(lowerCAmelCase__      ,				a % b			)
						__UpperCAmelCase :   Optional[Any]    					=  q
						__UpperCAmelCase :   Dict    					=  p - q * (a // b)

			assert a % d == 0 and b % d == 0
			assert d == a * x + b * y

			return (d, x, y)


if __name__ == "__main__":
					from doctest import testmod

					testmod(name='''diophantine''', verbose=True)
					testmod(name='''diophantine_all_soln''', verbose=True)
					testmod(name='''extended_gcd''', verbose=True)
					testmod(name='''greatest_common_divisor''', verbose=True)




