



"""simple docstring"""






import functools
import operator

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


_lowercase : Tuple      						=						logging.get_logger(__name__)

_lowercase : 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        __SCREAMING_SNAKE_CASE	(      lowerCAmelCase_   ):


					'''simple docstring'''





					_a   			=							'sew-d'



					def __init__(       self							:  List[Any],  lowerCamelCase							:  List[str]=32,  lowerCamelCase							:  Any=768,  lowerCamelCase							:  str=12,  lowerCamelCase							:  Optional[int]=12,  lowerCamelCase							:  Optional[Any]=3072,  lowerCamelCase							:  Optional[Any]=2,  lowerCamelCase							:  List[Any]=512,  lowerCamelCase							:  Optional[int]=256,  lowerCamelCase							:  Tuple=True,  lowerCamelCase							:  Optional[int]=True,  lowerCamelCase							:  Optional[int]=("p2c", "c2p"),  lowerCamelCase							:  int="layer_norm",  lowerCamelCase							:  Tuple="gelu_python",  lowerCamelCase							:  str=0.1,  lowerCamelCase							:  Dict=0.1,  lowerCamelCase							:  Optional[int]=0.1,  lowerCamelCase							:  Dict=0.0,  lowerCamelCase							:  Dict=0.1,  lowerCamelCase							:  Tuple=0.02,  lowerCamelCase							:  int=1E-7,  lowerCamelCase							:  Dict=1E-5,  lowerCamelCase							:  Tuple="group",  lowerCamelCase							:  List[str]="gelu",  lowerCamelCase							:  Optional[int]=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512),  lowerCamelCase							:  Optional[int]=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1),  lowerCamelCase							:  int=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1),  lowerCamelCase							:  List[Any]=False,  lowerCamelCase							:  Any=128,  lowerCamelCase							:  Any=16,  lowerCamelCase							:  int=True,  lowerCamelCase							:  int=0.05,  lowerCamelCase							:  Union[str, Any]=10,  lowerCamelCase							:  str=2,  lowerCamelCase							:  Union[str, Any]=0.0,  lowerCamelCase							:  Any=10,  lowerCamelCase							:  int=0,  lowerCamelCase							:  List[Any]="mean",  lowerCamelCase							:  List[Any]=False,  lowerCamelCase							:  int=False,  lowerCamelCase							:  Union[str, Any]=256,  lowerCamelCase							:  str=0,  lowerCamelCase							:  List[Any]=1,  lowerCamelCase							:  Tuple=2,  **lowerCamelCase							:  str,  )->					Optional[int]:
								super().__init__(**lowerCamelCase,  pad_token_id=lowerCamelCase,  bos_token_id=lowerCamelCase,  eos_token_id=lowerCamelCase     )
								lowerCamelCase__		:		Any			=hidden_size
								lowerCamelCase__		:		Optional[int]			=feat_extract_norm
								lowerCamelCase__		:		Optional[int]			=feat_extract_activation
								lowerCamelCase__		:		Optional[int]			=list(lowerCamelCase     )
								lowerCamelCase__		:		str			=list(lowerCamelCase     )
								lowerCamelCase__		:		Optional[Any]			=list(lowerCamelCase     )
								lowerCamelCase__		:		Dict			=conv_bias
								lowerCamelCase__		:		Optional[Any]			=num_conv_pos_embeddings
								lowerCamelCase__		:		Tuple			=num_conv_pos_embedding_groups
								lowerCamelCase__		:		List[str]			=len(self.conv_dim     )
								lowerCamelCase__		:		str			=num_hidden_layers
								lowerCamelCase__		:		int			=intermediate_size
								lowerCamelCase__		:		Union[str, Any]			=squeeze_factor
								lowerCamelCase__		:		Dict			=max_position_embeddings
								lowerCamelCase__		:		Optional[Any]			=position_buckets
								lowerCamelCase__		:		Tuple			=share_att_key
								lowerCamelCase__		:		Any			=relative_attention
								lowerCamelCase__		:		str			=norm_rel_ebd
								lowerCamelCase__		:		Dict			=list(lowerCamelCase     )
								lowerCamelCase__		:		int			=hidden_act
								lowerCamelCase__		:		Optional[int]			=num_attention_heads
								lowerCamelCase__		:		Optional[Any]			=hidden_dropout
								lowerCamelCase__		:		Dict			=attention_dropout
								lowerCamelCase__		:		Tuple			=activation_dropout
								lowerCamelCase__		:		Any			=feat_proj_dropout
								lowerCamelCase__		:		Optional[Any]			=final_dropout
								lowerCamelCase__		:		Tuple			=layer_norm_eps
								lowerCamelCase__		:		Optional[Any]			=feature_layer_norm_eps
								lowerCamelCase__		:		Tuple			=initializer_range
								lowerCamelCase__		:		Any			=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__		:		Dict			=apply_spec_augment
								lowerCamelCase__		:		Optional[Any]			=mask_time_prob
								lowerCamelCase__		:		Optional[int]			=mask_time_length
								lowerCamelCase__		:		Optional[int]			=mask_time_min_masks
								lowerCamelCase__		:		int			=mask_feature_prob
								lowerCamelCase__		:		List[str]			=mask_feature_length
								lowerCamelCase__		:		int			=mask_feature_min_masks

								# ctc loss
								lowerCamelCase__		:		List[Any]			=ctc_loss_reduction
								lowerCamelCase__		:		Optional[int]			=ctc_zero_infinity

								# sequence classification
								lowerCamelCase__		:		int			=use_weighted_layer_sum
								lowerCamelCase__		:		Dict			=classifier_proj_size




					@property
					def 		snake_case       (       self							:  Union[str, Any]     )->					Union[str, Any]:
								return functools.reduce(operator.mul,  self.conv_stride,  1     )









"""simple docstring"""






from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType

class        __SCREAMING_SNAKE_CASE	(      lowerCAmelCase_   ):


					'''simple docstring'''





					_a   			=							['image_processor', 'tokenizer']
					_a   			=							'BlipImageProcessor'
					_a   			=							'AutoTokenizer'



					def __init__(       self							:  Tuple,  lowerCamelCase							:  List[str],  lowerCamelCase							:  Dict     )->					str:
								lowerCamelCase__		:		Any			=False
								super().__init__(lowerCamelCase,  lowerCamelCase     )
								lowerCamelCase__		:		List[str]			=self.image_processor



					def __call__(       self							:  Union[str, Any],  lowerCamelCase							:  ImageInput = None,  lowerCamelCase							:  Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,  lowerCamelCase							:  bool = True,  lowerCamelCase							:  Union[bool, str, PaddingStrategy] = False,  lowerCamelCase							:  Union[bool, str, TruncationStrategy] = None,  lowerCamelCase							:  Optional[int] = None,  lowerCamelCase							:  int = 0,  lowerCamelCase							:  Optional[int] = None,  lowerCamelCase							:  Optional[bool] = None,  lowerCamelCase							:  bool = False,  lowerCamelCase							:  bool = False,  lowerCamelCase							:  bool = False,  lowerCamelCase							:  bool = False,  lowerCamelCase							:  bool = False,  lowerCamelCase							:  bool = True,  lowerCamelCase							:  Optional[Union[str, TensorType]] = None,  **lowerCamelCase							:  List[str],  )->					BatchEncoding:
								if images is None and text is None:
											raise ValueError('''You have to specify either images or text.'''     )

								# Get only text
								if images is None:
											lowerCamelCase__		:		str			=self.tokenizer
											lowerCamelCase__		:		str			=self.tokenizer(
											    text=lowerCamelCase,  add_special_tokens=lowerCamelCase,  padding=lowerCamelCase,  truncation=lowerCamelCase,  max_length=lowerCamelCase,  stride=lowerCamelCase,  pad_to_multiple_of=lowerCamelCase,  return_attention_mask=lowerCamelCase,  return_overflowing_tokens=lowerCamelCase,  return_special_tokens_mask=lowerCamelCase,  return_offsets_mapping=lowerCamelCase,  return_token_type_ids=lowerCamelCase,  return_length=lowerCamelCase,  verbose=lowerCamelCase,  return_tensors=lowerCamelCase,  **lowerCamelCase,  )
											return text_encoding

								# add pixel_values
								lowerCamelCase__		:		Optional[int]			=self.image_processor(lowerCamelCase,  return_tensors=lowerCamelCase     )

								if text is not None:
											lowerCamelCase__		:		Union[str, Any]			=self.tokenizer(
											    text=lowerCamelCase,  add_special_tokens=lowerCamelCase,  padding=lowerCamelCase,  truncation=lowerCamelCase,  max_length=lowerCamelCase,  stride=lowerCamelCase,  pad_to_multiple_of=lowerCamelCase,  return_attention_mask=lowerCamelCase,  return_overflowing_tokens=lowerCamelCase,  return_special_tokens_mask=lowerCamelCase,  return_offsets_mapping=lowerCamelCase,  return_token_type_ids=lowerCamelCase,  return_length=lowerCamelCase,  verbose=lowerCamelCase,  return_tensors=lowerCamelCase,  **lowerCamelCase,  )
								else:
											lowerCamelCase__		:		Optional[Any]			=None

								if text_encoding is not None:
											encoding_image_processor.update(lowerCamelCase     )

								return encoding_image_processor



					def 		snake_case       (       self							:  str,  *lowerCamelCase							:  Any,  **lowerCamelCase							:  List[str]     )->					Union[str, Any]:
								return self.tokenizer.batch_decode(*lowerCamelCase,  **lowerCamelCase     )



					def 		snake_case       (       self							:  Dict,  *lowerCamelCase							:  str,  **lowerCamelCase							:  str     )->					Union[str, Any]:
								return self.tokenizer.decode(*lowerCamelCase,  **lowerCamelCase     )




					@property
					# Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
					def 		snake_case       (       self							:  List[str]     )->					List[str]:
								lowerCamelCase__		:		Union[str, Any]			=self.tokenizer.model_input_names
								lowerCamelCase__		:		List[str]			=self.image_processor.model_input_names
								return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names     )     )




