




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



					'''simple docstring'''





					def __init__(  self    :	Optional[Any]			,					_lowercase    :	str			,					_lowercase    :	Any=12			,					_lowercase    :	Union[str, Any]=7			,					_lowercase    :	List[Any]=True			,					_lowercase    :	Union[str, Any]=True			,					_lowercase    :	Union[str, Any]=True			,					_lowercase    :	Optional[Any]=99			,					_lowercase    :	List[Any]=32			,					_lowercase    :	List[str]=32			,					_lowercase    :	Union[str, Any]=5			,					_lowercase    :	Optional[int]=4			,					_lowercase    :	Optional[Any]=37			,					_lowercase    :	Optional[int]=0.1			,					_lowercase    :	Tuple=0.1			,					_lowercase    :	List[Any]=512			,					_lowercase    :	str=0.02			,					_lowercase    :	Any=0			,					_lowercase    :	Optional[Any]=None			,					)						->       int:
								A_       		=   parent
								A_       		=   batch_size
								A_       		=   seq_length
								A_       		=   is_training
								A_       		=   use_input_mask
								A_       		=   use_labels
								A_       		=   vocab_size
								A_       		=   hidden_size
								A_       		=   projection_dim
								A_       		=   num_hidden_layers
								A_       		=   num_attention_heads
								A_       		=   intermediate_size
								A_       		=   dropout
								A_       		=   attention_dropout
								A_       		=   max_position_embeddings
								A_       		=   initializer_range
								A_       		=   scope
								A_       		=   bos_token_id



					def 						__snake_case	(  self    :	Optional[int])						->       Optional[Any]:
								A_       		=   ids_tensor([self.batch_size, self.seq_length]			,					self.vocab_size)

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

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

								A_       		=   self.get_config()

								return config, input_ids, input_mask



					def 						__snake_case	(  self    :	Dict)						->       Dict:
								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    :	str			,					_lowercase    :	Tuple			,					_lowercase    :	List[str]			,					_lowercase    :	int)						->       Optional[int]:
								A_       		=   BlipTextModel(config=_lowercase)
								model.to(_lowercase)
								model.eval()
								with torch.no_grad():
											A_       		=   model(_lowercase			,					attention_mask=_lowercase)
											A_       		=   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 						__snake_case	(  self    :	Union[str, Any])						->       Optional[Any]:
								A_       		=   self.prepare_config_and_inputs()
								A_		,   A_		,   A_       		=   config_and_inputs
								A_       		=   {'input_ids': input_ids, 'attention_mask': input_mask}
								return config, inputs_dict





@require_torch
class      __UpperCAmelCase							(    lowerCAmelCase ,unittest.TestCase							):



					'''simple docstring'''





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



					def 						__snake_case	(  self    :	Dict)						->       str:
								A_       		=   BlipTextModelTester(self)
								A_       		=   ConfigTester(self			,					config_class=_lowercase			,					hidden_size=37)



					def 						__snake_case	(  self    :	Optional[Any])						->       Union[str, Any]:
								self.config_tester.run_common_tests()



					def 						__snake_case	(  self    :	Optional[int])						->       List[Any]:
								A_       		=   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_lowercase)



					def 						__snake_case	(  self    :	int)						->       Any:
								pass



					def 						__snake_case	(  self    :	str)						->       Dict:
								pass



					@unittest.skip(reason='Blip does not use inputs_embeds')
					def 						__snake_case	(  self    :	int)						->       List[str]:
								pass



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



					@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING')
					def 						__snake_case	(  self    :	int)						->       Tuple:
								pass



					@slow
					def 						__snake_case	(  self    :	Dict)						->       Optional[int]:
								for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											A_       		=   BlipTextModel.from_pretrained(_lowercase)
											self.assertIsNotNone(_lowercase)



					def 						__snake_case	(  self    :	int)						->       Union[str, Any]:
								super().test_pt_tf_model_equivalence(allow_missing_keys=_lowercase)










'''simple docstring'''
from unittest.mock import patch

import datasets
from datasets import Dataset





def  lowerCamelCase(       )		->		Any:
			A_       		=   Dataset.from_dict({'col_1': [3, 2, 0, 1]}    )

			with patch('tqdm.auto.tqdm'    ) as mock_tqdm:
						datasets.disable_progress_bar()
						dset.map(lambda SCREAMING_SNAKE_CASE_    : {"col_2": x["col_1"] + 1}    )
						mock_tqdm.assert_not_called()

						mock_tqdm.reset_mock()

						datasets.enable_progress_bar()
						dset.map(lambda SCREAMING_SNAKE_CASE_    : {"col_2": x["col_1"] + 1}    )
						mock_tqdm.assert_called()




