


import copy
from typing import TYPE_CHECKING, Any, Mapping, Optional, OrderedDict

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


if TYPE_CHECKING:
				from ... import PreTrainedTokenizerBase, TensorType

lowerCAmelCase							=						logging.get_logger(__name__)




class        lowerCamelCase      (     _UpperCamelCase   ):
	_lowerCAmelCase    :		Any        =	'''vision-encoder-decoder'''
	_lowerCAmelCase    :		Tuple        =	True


	def __init__(						self							,    **lowercase__):
							super().__init__(**lowercase__)
							if "encoder" not in kwargs or "decoder" not in kwargs:
													raise ValueError(
													    F"A configuraton of type {self.model_type} cannot be instantiated because "
													    F"not both `encoder` and `decoder` sub-configurations are passed, but only {kwargs}")

							__UpperCAmelCase :       int  						=  kwargs.pop('''encoder''')
							__UpperCAmelCase :       Optional[int]  						=  encoder_config.pop('''model_type''')
							__UpperCAmelCase :       Tuple  						=  kwargs.pop('''decoder''')
							__UpperCAmelCase :       Any  						=  decoder_config.pop('''model_type''')

							__UpperCAmelCase :       Union[str, Any]  						=  AutoConfig.for_model(lowercase__							,    **lowercase__)
							__UpperCAmelCase :       List[str]  						=  AutoConfig.for_model(lowercase__							,    **lowercase__)
							__UpperCAmelCase :       str  						=  True


	@classmethod
	def    A(						cls							,    lowercase__							,    lowercase__							,    **lowercase__):
							logger.info('''Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config''')
							__UpperCAmelCase :       Union[str, Any]  						=  True
							__UpperCAmelCase :       Optional[Any]  						=  True

							return cls(encoder=encoder_config.to_dict()							,    decoder=decoder_config.to_dict()							,    **lowercase__)


	def    A(						self):
							__UpperCAmelCase :       Optional[int]  						=  copy.deepcopy(self.__dict__)
							__UpperCAmelCase :       Optional[int]  						=  self.encoder.to_dict()
							__UpperCAmelCase :       Optional[Any]  						=  self.decoder.to_dict()
							__UpperCAmelCase :       List[str]  						=  self.__class__.model_type
							return output






class        lowerCamelCase      (     _UpperCamelCase   ):
	_lowerCAmelCase    :		int        =	version.parse('''1.11'''   )


	@property
	def    A(						self):
							return OrderedDict(
							    [
							        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
							    ])


	@property
	def    A(						self):
							return 1e-4


	@property
	def    A(						self):
							return OrderedDict({'''last_hidden_state''': {0: '''batch''', 1: '''encoder_sequence'''}})






class        lowerCamelCase      (     _UpperCamelCase   ):


	@property
	def    A(						self):
							__UpperCAmelCase :       Dict  						=  OrderedDict()
							__UpperCAmelCase :       str  						=  {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
							__UpperCAmelCase :       str  						=  {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
							__UpperCAmelCase :       str  						=  {0: '''batch''', 1: '''encoder_sequence'''}

							return common_inputs


	def    A(						self							,    lowercase__							,    lowercase__ = -1							,    lowercase__ = -1							,    lowercase__ = False							,    lowercase__ = None							,    ):
							import torch

							__UpperCAmelCase :       Optional[Any]  						=  OrderedDict()

							__UpperCAmelCase :       int  						=  super().generate_dummy_inputs(
							    lowercase__							,    batch_size=lowercase__							,    seq_length=lowercase__							,    is_pair=lowercase__							,    framework=lowercase__)

							__UpperCAmelCase						,			__UpperCAmelCase :       Optional[Any]  						=  dummy_input['''input_ids'''].shape
							__UpperCAmelCase :       List[Any]  						=  (batch, encoder_sequence, self._config.encoder_hidden_size)
							__UpperCAmelCase :       Optional[Any]  						=  dummy_input.pop('''input_ids''')
							__UpperCAmelCase :       Optional[int]  						=  dummy_input.pop('''attention_mask''')
							__UpperCAmelCase :       Tuple  						=  torch.zeros(lowercase__)

							return common_inputs






class        lowerCamelCase      (     _UpperCamelCase   ):


	@property
	def    A(						self):
							pass


	def    A(						self							,    lowercase__):
							return VisionEncoderDecoderEncoderOnnxConfig(lowercase__)


	def    A(						self							,    lowercase__							,    lowercase__							,    lowercase__ = "default"):
							__UpperCAmelCase :       List[Any]  						=  encoder_config.hidden_size
							return VisionEncoderDecoderDecoderOnnxConfig(lowercase__							,    lowercase__)





import functools
import operator

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


lowerCAmelCase							=						logging.get_logger(__name__)

lowerCAmelCase							=						{
    """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        lowerCamelCase      (     _UpperCamelCase   ):
	_lowerCAmelCase    :		List[str]        =	'''sew-d'''


	def __init__(						self							,    lowercase__=3_2							,    lowercase__=7_6_8							,    lowercase__=1_2							,    lowercase__=1_2							,    lowercase__=3_0_7_2							,    lowercase__=2							,    lowercase__=5_1_2							,    lowercase__=2_5_6							,    lowercase__=True							,    lowercase__=True							,    lowercase__=("p2c", "c2p")							,    lowercase__="layer_norm"							,    lowercase__="gelu_python"							,    lowercase__=0.1							,    lowercase__=0.1							,    lowercase__=0.1							,    lowercase__=0.0							,    lowercase__=0.1							,    lowercase__=0.0_2							,    lowercase__=1e-7							,    lowercase__=1e-5							,    lowercase__="group"							,    lowercase__="gelu"							,    lowercase__=(6_4, 1_2_8, 1_2_8, 1_2_8, 1_2_8, 2_5_6, 2_5_6, 2_5_6, 2_5_6, 5_1_2, 5_1_2, 5_1_2, 5_1_2)							,    lowercase__=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)							,    lowercase__=(1_0, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)							,    lowercase__=False							,    lowercase__=1_2_8							,    lowercase__=1_6							,    lowercase__=True							,    lowercase__=0.0_5							,    lowercase__=1_0							,    lowercase__=2							,    lowercase__=0.0							,    lowercase__=1_0							,    lowercase__=0							,    lowercase__="mean"							,    lowercase__=False							,    lowercase__=False							,    lowercase__=2_5_6							,    lowercase__=0							,    lowercase__=1							,    lowercase__=2							,    **lowercase__							,    ):
							super().__init__(**lowercase__							,    pad_token_id=lowercase__							,    bos_token_id=lowercase__							,    eos_token_id=lowercase__)
							__UpperCAmelCase :       Dict  						=  hidden_size
							__UpperCAmelCase :       int  						=  feat_extract_norm
							__UpperCAmelCase :       List[str]  						=  feat_extract_activation
							__UpperCAmelCase :       str  						=  list(lowercase__)
							__UpperCAmelCase :       Optional[int]  						=  list(lowercase__)
							__UpperCAmelCase :       Tuple  						=  list(lowercase__)
							__UpperCAmelCase :       Tuple  						=  conv_bias
							__UpperCAmelCase :       int  						=  num_conv_pos_embeddings
							__UpperCAmelCase :       int  						=  num_conv_pos_embedding_groups
							__UpperCAmelCase :       Any  						=  len(self.conv_dim)
							__UpperCAmelCase :       str  						=  num_hidden_layers
							__UpperCAmelCase :       Optional[Any]  						=  intermediate_size
							__UpperCAmelCase :       Union[str, Any]  						=  squeeze_factor
							__UpperCAmelCase :       Union[str, Any]  						=  max_position_embeddings
							__UpperCAmelCase :       List[str]  						=  position_buckets
							__UpperCAmelCase :       Tuple  						=  share_att_key
							__UpperCAmelCase :       int  						=  relative_attention
							__UpperCAmelCase :       str  						=  norm_rel_ebd
							__UpperCAmelCase :       Dict  						=  list(lowercase__)
							__UpperCAmelCase :       int  						=  hidden_act
							__UpperCAmelCase :       int  						=  num_attention_heads
							__UpperCAmelCase :       Optional[int]  						=  hidden_dropout
							__UpperCAmelCase :       int  						=  attention_dropout
							__UpperCAmelCase :       Optional[int]  						=  activation_dropout
							__UpperCAmelCase :       Optional[Any]  						=  feat_proj_dropout
							__UpperCAmelCase :       Optional[Any]  						=  final_dropout
							__UpperCAmelCase :       Optional[int]  						=  layer_norm_eps
							__UpperCAmelCase :       str  						=  feature_layer_norm_eps
							__UpperCAmelCase :       Optional[int]  						=  initializer_range
							__UpperCAmelCase :       Tuple  						=  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
							__UpperCAmelCase :       Optional[int]  						=  apply_spec_augment
							__UpperCAmelCase :       List[str]  						=  mask_time_prob
							__UpperCAmelCase :       Union[str, Any]  						=  mask_time_length
							__UpperCAmelCase :       Optional[int]  						=  mask_time_min_masks
							__UpperCAmelCase :       Optional[int]  						=  mask_feature_prob
							__UpperCAmelCase :       List[str]  						=  mask_feature_length
							__UpperCAmelCase :       List[Any]  						=  mask_feature_min_masks

							# ctc loss
							__UpperCAmelCase :       int  						=  ctc_loss_reduction
							__UpperCAmelCase :       Union[str, Any]  						=  ctc_zero_infinity

							# sequence classification
							__UpperCAmelCase :       List[str]  						=  use_weighted_layer_sum
							__UpperCAmelCase :       Tuple  						=  classifier_proj_size


	@property
	def    A(						self):
							return functools.reduce(operator.mul							,    self.conv_stride							,    1)

