




"""simple docstring"""




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






				'''simple docstring'''





				def __init__(       self		, _a		, _a=12		, _a=7		, _a=True		, _a=True		, _a=True		, _a=99		, _a=32		, _a=32		, _a=2		, _a=4		, _a=37		, _a=0.1		, _a=0.1		, _a=512		, _a=0.02		, _a=0		, _a=None		, ):





							"""simple docstring"""
							lowerCamelCase			      =					parent
							lowerCamelCase			      =					batch_size
							lowerCamelCase			      =					seq_length
							lowerCamelCase			      =					is_training
							lowerCamelCase			      =					use_input_mask
							lowerCamelCase			      =					use_labels
							lowerCamelCase			      =					vocab_size
							lowerCamelCase			      =					hidden_size
							lowerCamelCase			      =					projection_dim
							lowerCamelCase			      =					num_hidden_layers
							lowerCamelCase			      =					num_attention_heads
							lowerCamelCase			      =					intermediate_size
							lowerCamelCase			      =					dropout
							lowerCamelCase			      =					attention_dropout
							lowerCamelCase			      =					max_position_embeddings
							lowerCamelCase			      =					initializer_range
							lowerCamelCase			      =					scope
							lowerCamelCase			      =					bos_token_id





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					ids_tensor([self.batch_size, self.seq_length]		, self.vocab_size )

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

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

							lowerCamelCase			      =					self.get_config()

							return config, input_ids, tf.convert_to_tensor(_a )





				def    _lowerCAmelCase				(       self ):





							"""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    _lowerCAmelCase				(       self		, _a		, _a		, _a ):





							"""simple docstring"""
							lowerCamelCase			      =					TFBlipTextModel(config=_a )
							lowerCamelCase			      =					model(_a		, attention_mask=_a		, training=_a )
							lowerCamelCase			      =					model(_a		, training=_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    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					self.prepare_config_and_inputs()
							lowerCamelCase      ,   lowerCamelCase      ,   lowerCamelCase			      =					config_and_inputs
							lowerCamelCase			      =					{"""input_ids""": input_ids, """attention_mask""": input_mask}
							return config, inputs_dict






@require_tf
class     __magic_name__							(       UpperCAmelCase__						,					unittest.TestCase				):






				'''simple docstring'''
				__UpperCamelCase			  =						(TFBlipTextModel,) if is_tf_available() else ()
				__UpperCamelCase			  =						False
				__UpperCamelCase			  =						False
				__UpperCamelCase			  =						False





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					BlipTextModelTester(self )
							lowerCamelCase			      =					ConfigTester(self		, config_class=_a		, hidden_size=37 )





				def    _lowerCAmelCase				(       self ):





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





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_a )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							pass





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							pass





				@unittest.skip(reason="""Blip does not use inputs_embeds""" )
				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							pass





				@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING""" )
				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							pass





				@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING""" )
				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							pass





				@slow
				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowerCamelCase			      =					TFBlipTextModel.from_pretrained(_a )
										self.assertIsNotNone(_a )





				def    _lowerCAmelCase				(       self		, _a=True ):





							"""simple docstring"""
							super().test_pt_tf_model_equivalence(allow_missing_keys=_a )









"""simple docstring"""




import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase							:			int     							=							logging.get_logger(__name__)

lowerCAmelCase							:			List[str]     							=							{
    """asapp/sew-d-tiny-100k""": """https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json""",
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}






class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''
				__UpperCamelCase			  =						"sew-d"





				def __init__(       self		, _a=32		, _a=768		, _a=12		, _a=12		, _a=3_072		, _a=2		, _a=512		, _a=256		, _a=True		, _a=True		, _a=("p2c", "c2p")		, _a="layer_norm"		, _a="gelu_python"		, _a=0.1		, _a=0.1		, _a=0.1		, _a=0.0		, _a=0.1		, _a=0.02		, _a=1e-7		, _a=1e-5		, _a="group"		, _a="gelu"		, _a=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)		, _a=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)		, _a=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)		, _a=False		, _a=128		, _a=16		, _a=True		, _a=0.05		, _a=10		, _a=2		, _a=0.0		, _a=10		, _a=0		, _a="mean"		, _a=False		, _a=False		, _a=256		, _a=0		, _a=1		, _a=2		, **_a		, ):





							"""simple docstring"""
							super().__init__(**_a		, pad_token_id=_a		, bos_token_id=_a		, eos_token_id=_a )
							lowerCamelCase			      =					hidden_size
							lowerCamelCase			      =					feat_extract_norm
							lowerCamelCase			      =					feat_extract_activation
							lowerCamelCase			      =					list(_a )
							lowerCamelCase			      =					list(_a )
							lowerCamelCase			      =					list(_a )
							lowerCamelCase			      =					conv_bias
							lowerCamelCase			      =					num_conv_pos_embeddings
							lowerCamelCase			      =					num_conv_pos_embedding_groups
							lowerCamelCase			      =					len(self.conv_dim )
							lowerCamelCase			      =					num_hidden_layers
							lowerCamelCase			      =					intermediate_size
							lowerCamelCase			      =					squeeze_factor
							lowerCamelCase			      =					max_position_embeddings
							lowerCamelCase			      =					position_buckets
							lowerCamelCase			      =					share_att_key
							lowerCamelCase			      =					relative_attention
							lowerCamelCase			      =					norm_rel_ebd
							lowerCamelCase			      =					list(_a )
							lowerCamelCase			      =					hidden_act
							lowerCamelCase			      =					num_attention_heads
							lowerCamelCase			      =					hidden_dropout
							lowerCamelCase			      =					attention_dropout
							lowerCamelCase			      =					activation_dropout
							lowerCamelCase			      =					feat_proj_dropout
							lowerCamelCase			      =					final_dropout
							lowerCamelCase			      =					layer_norm_eps
							lowerCamelCase			      =					feature_layer_norm_eps
							lowerCamelCase			      =					initializer_range
							lowerCamelCase			      =					vocab_size

							if (
							    (len(self.conv_stride ) != self.num_feat_extract_layers)
							    or (len(self.conv_kernel ) != self.num_feat_extract_layers)
							    or (len(self.conv_dim ) != self.num_feat_extract_layers)
							):
										raise ValueError(
										    """Configuration for convolutional layers is incorrect."""
										    """It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,"""
										    f'but is `len(config.conv_dim) = {len(self.conv_dim )}`, `len(config.conv_stride)'
										    f'= {len(self.conv_stride )}`, `len(config.conv_kernel) = {len(self.conv_kernel )}`.' )

							# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
							lowerCamelCase			      =					apply_spec_augment
							lowerCamelCase			      =					mask_time_prob
							lowerCamelCase			      =					mask_time_length
							lowerCamelCase			      =					mask_time_min_masks
							lowerCamelCase			      =					mask_feature_prob
							lowerCamelCase			      =					mask_feature_length
							lowerCamelCase			      =					mask_feature_min_masks

							# ctc loss
							lowerCamelCase			      =					ctc_loss_reduction
							lowerCamelCase			      =					ctc_zero_infinity

							# sequence classification
							lowerCamelCase			      =					use_weighted_layer_sum
							lowerCamelCase			      =					classifier_proj_size





				@property
				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							return functools.reduce(operator.mul		, self.conv_stride		, 1 )



