



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




			'''simple docstring'''






			def __init__(  self				:					List[Any]			,			a_				:					Any			,			a_				:					Union[str, Any]=12			,			a_				:					Any=7			,			a_				:					str=True			,			a_				:					Tuple=True			,			a_				:					List[Any]=True			,			a_				:					List[Any]=99			,			a_				:					Optional[int]=32			,			a_				:					List[Any]=32			,			a_				:					List[str]=5			,			a_				:					List[Any]=4			,			a_				:					Union[str, Any]=37			,			a_				:					Union[str, Any]=0.1			,			a_				:					Dict=0.1			,			a_				:					int=5_12			,			a_				:					Dict=0.0_2			,			a_				:					List[Any]=0			,			a_				:					Optional[int]=None			,			):
					'''simple docstring'''





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




			def 					snake_case__	(  self				:					Tuple					):
					'''simple docstring'''





					__UpperCAmelCase       :	List[str]						=      ids_tensor([self.batch_size, self.seq_length]			,			self.vocab_size					)

					__UpperCAmelCase       :	Any						=      None
					if self.use_input_mask:
							__UpperCAmelCase       :	Tuple						=      random_attention_mask([self.batch_size, self.seq_length]					)

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

					__UpperCAmelCase       :	Union[str, Any]						=      self.get_config()

					return config, input_ids, input_mask




			def 					snake_case__	(  self				:					Tuple					):
					'''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 					snake_case__	(  self				:					Optional[Any]			,			a_				:					Tuple			,			a_				:					str			,			a_				:					Any					):
					'''simple docstring'''





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





					__UpperCAmelCase       :	Any						=      self.prepare_config_and_inputs()
					__UpperCAmelCase				,   __UpperCAmelCase				,   __UpperCAmelCase       :	Union[str, Any]						=      config_and_inputs
					__UpperCAmelCase       :	Tuple						=      {'''input_ids''': input_ids, '''attention_mask''': input_mask}
					return config, inputs_dict

@require_torch
class 						UpperCAmelCase__     (     __UpperCamelCase		,unittest.TestCase  ):




			'''simple docstring'''






			UpperCamelCase     		=			(BlipTextModel,) if is_torch_available() else ()
			UpperCamelCase     		=			False
			UpperCamelCase     		=			False
			UpperCamelCase     		=			False




			def 					snake_case__	(  self				:					Tuple					):
					'''simple docstring'''





					__UpperCAmelCase       :	Dict						=      BlipTextModelTester(self					)
					__UpperCAmelCase       :	Tuple						=      ConfigTester(self			,			config_class=a_			,			hidden_size=37					)




			def 					snake_case__	(  self				:					Optional[Any]					):
					'''simple docstring'''





					self.config_tester.run_common_tests()




			def 					snake_case__	(  self				:					Any					):
					'''simple docstring'''





					__UpperCAmelCase       :	int						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*a_					)




			def 					snake_case__	(  self				:					List[str]					):
					'''simple docstring'''





					pass




			def 					snake_case__	(  self				:					Optional[int]					):
					'''simple docstring'''





					pass




			@unittest.skip(reason='''Blip does not use inputs_embeds'''					)
			def 					snake_case__	(  self				:					int					):
					'''simple docstring'''





					pass




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





					pass




			@unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''					)
			def 					snake_case__	(  self				:					Optional[int]					):
					'''simple docstring'''





					pass




			@slow
			def 					snake_case__	(  self				:					Any					):
					'''simple docstring'''





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




			def 					snake_case__	(  self				:					Union[str, Any]					):
					'''simple docstring'''





					super().test_pt_tf_model_equivalence(allow_missing_keys=a_					)










from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


__A       ={
    "configuration_speech_to_text_2": ["SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP", "Speech2Text2Config"],
    "processing_speech_to_text_2": ["Speech2Text2Processor"],
    "tokenization_speech_to_text_2": ["Speech2Text2Tokenizer"],
}


try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__A       =[
				    "SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST",
				    "Speech2Text2ForCausalLM",
				    "Speech2Text2PreTrainedModel",
				]


if TYPE_CHECKING:
				from .configuration_speech_to_text_a import SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextaConfig
				from .processing_speech_to_text_a import SpeechaTextaProcessor
				from .tokenization_speech_to_text_a import SpeechaTextaTokenizer

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_speech_to_text_a import (
								    SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST,
								    SpeechaTextaForCausalLM,
								    SpeechaTextaPreTrainedModel,
								)

else:
				import sys

				__A       =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





