
"""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  _snake_case	:






							def __init__(       self    :      Optional[Any]    ,			snake_case__    :      Optional[int]    ,			snake_case__    :      Tuple=1_2    ,			snake_case__    :      int=7    ,			snake_case__    :      Dict=True    ,			snake_case__    :      Optional[Any]=True    ,			snake_case__    :      Optional[int]=True    ,			snake_case__    :      List[str]=9_9    ,			snake_case__    :      Tuple=3_2    ,			snake_case__    :      Tuple=3_2    ,			snake_case__    :      str=5    ,			snake_case__    :      Union[str, Any]=4    ,			snake_case__    :      Tuple=3_7    ,			snake_case__    :      Any=0.1    ,			snake_case__    :      List[Any]=0.1    ,			snake_case__    :      Any=5_1_2    ,			snake_case__    :      str=0.02    ,			snake_case__    :      Any=0    ,			snake_case__    :      Any=None    ,			):






												"""simple docstring"""



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






							def 				__lowercase	(       self    :      List[str]     ):






												"""simple docstring"""



												__a:    Optional[Any]		     =       ids_tensor([self.batch_size, self.seq_length]    ,			self.vocab_size     )

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

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

												__a:    Optional[Any]		     =       self.get_config()

												return config, input_ids, input_mask






							def 				__lowercase	(       self    :      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 				__lowercase	(       self    :      Optional[Any]    ,			snake_case__    :      str    ,			snake_case__    :      int    ,			snake_case__    :      List[Any]     ):






												"""simple docstring"""



												__a:    Any		     =       BlipTextModel(config=snake_case__     )
												model.to(snake_case__     )
												model.eval()
												with torch.no_grad():
																	__a:    Optional[Any]		     =       model(snake_case__    ,			attention_mask=snake_case__     )
																	__a:    Dict		     =       model(snake_case__     )
												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 				__lowercase	(       self    :      int     ):






												"""simple docstring"""



												__a:    List[str]		     =       self.prepare_config_and_inputs()
												__a     ,					__a     ,					__a:    Union[str, Any]		     =       config_and_inputs
												__a:    Any		     =       {"""input_ids""": input_ids, """attention_mask""": input_mask}
												return config, inputs_dict






@require_torch
class  _snake_case	(    _lowercase			,					unittest.TestCase							):
							SCREAMING_SNAKE_CASE		  =    (BlipTextModel,) if is_torch_available() else ()
							SCREAMING_SNAKE_CASE		  =    False
							SCREAMING_SNAKE_CASE		  =    False
							SCREAMING_SNAKE_CASE		  =    False






							def 				__lowercase	(       self    :      Union[str, Any]     ):






												"""simple docstring"""



												__a:    Any		     =       BlipTextModelTester(self     )
												__a:    int		     =       ConfigTester(self    ,			config_class=snake_case__    ,			hidden_size=3_7     )






							def 				__lowercase	(       self    :      Any     ):






												"""simple docstring"""



												self.config_tester.run_common_tests()






							def 				__lowercase	(       self    :      List[str]     ):






												"""simple docstring"""



												__a:    Any		     =       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*snake_case__     )






							def 				__lowercase	(       self    :      Optional[int]     ):






												"""simple docstring"""



												pass






							def 				__lowercase	(       self    :      List[str]     ):






												"""simple docstring"""



												pass






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






												"""simple docstring"""



												pass






							@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""     )
							def 				__lowercase	(       self    :      List[str]     ):






												"""simple docstring"""



												pass






							@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""     )
							def 				__lowercase	(       self    :      List[str]     ):






												"""simple docstring"""



												pass






							@slow
							def 				__lowercase	(       self    :      Optional[int]     ):






												"""simple docstring"""



												for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	__a:    Union[str, Any]		     =       BlipTextModel.from_pretrained(snake_case__     )
																	self.assertIsNotNone(snake_case__     )






							def 				__lowercase	(       self    :      Union[str, Any]     ):






												"""simple docstring"""



												super().test_pt_tf_model_equivalence(allow_missing_keys=snake_case__     )


"""simple docstring"""
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


lowercase		:    Tuple			=       {
    'configuration_codegen': ['CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CodeGenConfig', 'CodeGenOnnxConfig'],
    'tokenization_codegen': ['CodeGenTokenizer'],
}

try:
			if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase		:    int			=       ['CodeGenTokenizerFast']

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase		:    Optional[int]			=       [
			    'CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST',
			    'CodeGenForCausalLM',
			    'CodeGenModel',
			    'CodeGenPreTrainedModel',
			]

if TYPE_CHECKING:
			from .configuration_codegen import CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP, CodeGenConfig, CodeGenOnnxConfig
			from .tokenization_codegen import CodeGenTokenizer

			try:
						if not is_tokenizers_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_codegen_fast import CodeGenTokenizerFast

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_codegen import (
						    CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST,
						    CodeGenForCausalLM,
						    CodeGenModel,
						    CodeGenPreTrainedModel,
						)

else:
			import sys

			lowercase		:    Optional[Any]			=       _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
