






from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
							import tensorflow as tf

							from transformers import TFBlipTextModel
							from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST


class   __SCREAMING_SNAKE_CASE:
							def __init__(     self:      str       ,	UpperCamelCase:      Dict       ,	UpperCamelCase:      int=12       ,	UpperCamelCase:      List[str]=7       ,	UpperCamelCase:      str=True       ,	UpperCamelCase:      int=True       ,	UpperCamelCase:      List[Any]=True       ,	UpperCamelCase:      Dict=99       ,	UpperCamelCase:      Tuple=32       ,	UpperCamelCase:      str=32       ,	UpperCamelCase:      List[str]=2       ,	UpperCamelCase:      int=4       ,	UpperCamelCase:      str=37       ,	UpperCamelCase:      List[Any]=0.1       ,	UpperCamelCase:      str=0.1       ,	UpperCamelCase:      str=5_12       ,	UpperCamelCase:      int=0.02       ,	UpperCamelCase:      Tuple=0       ,	UpperCamelCase:      Dict=None       ,	)		->		int:
											snake_case__									=     parent
											snake_case__									=     batch_size
											snake_case__									=     seq_length
											snake_case__									=     is_training
											snake_case__									=     use_input_mask
											snake_case__									=     use_labels
											snake_case__									=     vocab_size
											snake_case__									=     hidden_size
											snake_case__									=     projection_dim
											snake_case__									=     num_hidden_layers
											snake_case__									=     num_attention_heads
											snake_case__									=     intermediate_size
											snake_case__									=     dropout
											snake_case__									=     attention_dropout
											snake_case__									=     max_position_embeddings
											snake_case__									=     initializer_range
											snake_case__									=     scope
											snake_case__									=     bos_token_id
							def lowerCAmelCase_ (     self:      str						)		->		Union[str, Any]:
											snake_case__									=     ids_tensor([self.batch_size, self.seq_length]       ,	self.vocab_size						)

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

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

											snake_case__									=     self.get_config()

											return config, input_ids, tf.convert_to_tensor(UpperCamelCase						)
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		List[str]:
											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 lowerCAmelCase_ (     self:      Optional[Any]       ,	UpperCamelCase:      str       ,	UpperCamelCase:      Union[str, Any]       ,	UpperCamelCase:      Optional[Any]						)		->		Any:
											snake_case__									=     TFBlipTextModel(config=UpperCamelCase						)
											snake_case__									=     model(UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	training=UpperCamelCase						)
											snake_case__									=     model(UpperCamelCase       ,	training=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 lowerCAmelCase_ (     self:      int						)		->		Optional[Any]:
											snake_case__									=     self.prepare_config_and_inputs()
											snake_case__							,						snake_case__							,						snake_case__									=     config_and_inputs
											snake_case__									=     {'input_ids': input_ids, 'attention_mask': input_mask}
											return config, inputs_dict


@require_tf
class   __SCREAMING_SNAKE_CASE(	a_    ,  unittest.TestCase	):
							_UpperCAmelCase     =       (TFBlipTextModel,) if is_tf_available() else ()
							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       False
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		Any:
											snake_case__									=     BlipTextModelTester(self						)
											snake_case__									=     ConfigTester(self       ,	config_class=UpperCamelCase       ,	hidden_size=37						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		Union[str, Any]:
											self.config_tester.run_common_tests()
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		int:
											snake_case__									=     self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*UpperCamelCase						)
							def lowerCAmelCase_ (     self:      Tuple						)		->		str:
											pass
							def lowerCAmelCase_ (     self:      Dict						)		->		str:
											pass
							@unittest.skip(reason='Blip does not use inputs_embeds'						)
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		int:
											pass
							@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		Optional[Any]:
											pass
							@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'						)
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		Union[str, Any]:
											pass
							@slow
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		int:
											for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															snake_case__									=     TFBlipTextModel.from_pretrained(UpperCamelCase						)
															self.assertIsNotNone(UpperCamelCase						)


							def lowerCAmelCase_ (     self:      int       ,	UpperCamelCase:      Optional[int]=True						)		->		Dict:
											super().test_pt_tf_model_equivalence(allow_missing_keys=UpperCamelCase						)








from argparse import ArgumentParser

from .env import EnvironmentCommand
def      a_ (      )			->			Optional[Any]:







				"""simple docstring"""
				snake_case__									=     ArgumentParser('Diffusers CLI tool'      ,   usage='diffusers-cli <command> [<args>]'  )
				snake_case__									=     parser.add_subparsers(help='diffusers-cli command helpers'  )

				# Register commands
				EnvironmentCommand.register_subcommand(_A  )

				# Let's go
				snake_case__									=     parser.parse_args()

				if not hasattr(_A      ,   'func'  ):
								parser.print_help()
								exit(1  )

				# Run
				snake_case__									=     args.func(_A  )
				service.run()


if __name__ == "__main__":
							main()




