






'''simple docstring'''







from typing import Optional, Union

import torch
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithPoolingAndNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_mobilenet_va import MobileNetVaConfig


_A     :      List[str]   					=logging.get_logger(__name__)


# General docstring
_A     :      Tuple   					='''MobileNetV1Config'''

# Base docstring
_A     :      Optional[Any]   					='''google/mobilenet_v1_1.0_224'''
_A     :      Tuple   					=[1, 1_024, 7, 7]

# Image classification docstring
_A     :      Optional[int]   					='''google/mobilenet_v1_1.0_224'''
_A     :      int   					='''tabby, tabby cat'''


_A     :      List[Any]   					=[
    '''google/mobilenet_v1_1.0_224''',
    '''google/mobilenet_v1_0.75_192''',
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
]





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase=None				)				->	Union[str, Any]:
       lowerCamelCase__ :     Optional[int]	  =	{}

       if isinstance(a__    ,      a__				):
              lowerCamelCase__ :     List[str]	  =	model.mobilenet_va
       else:
              lowerCamelCase__ :     Union[str, Any]	  =	model

       lowerCamelCase__ :     Optional[int]	  =	'''MobilenetV1/Conv2d_0/'''
       lowerCamelCase__ :     Tuple	  =	backbone.conv_stem.convolution.weight
       lowerCamelCase__ :     Tuple	  =	backbone.conv_stem.normalization.bias
       lowerCamelCase__ :     Optional[Any]	  =	backbone.conv_stem.normalization.weight
       lowerCamelCase__ :     Union[str, Any]	  =	backbone.conv_stem.normalization.running_mean
       lowerCamelCase__ :     Any	  =	backbone.conv_stem.normalization.running_var

       for i in range(13				):
              lowerCamelCase__ :     Dict	  =	i + 1
              lowerCamelCase__ :     Union[str, Any]	  =	i * 2

              lowerCamelCase__ :     Any	  =	backbone.layer[pt_index]
              lowerCamelCase__ :     Optional[Any]	  =	f'''MobilenetV1/Conv2d_{tf_index}_depthwise/'''
              lowerCamelCase__ :     Any	  =	pointer.convolution.weight
              lowerCamelCase__ :     Tuple	  =	pointer.normalization.bias
              lowerCamelCase__ :     List[Any]	  =	pointer.normalization.weight
              lowerCamelCase__ :     Optional[Any]	  =	pointer.normalization.running_mean
              lowerCamelCase__ :     List[Any]	  =	pointer.normalization.running_var

              lowerCamelCase__ :     List[Any]	  =	backbone.layer[pt_index + 1]
              lowerCamelCase__ :     Any	  =	f'''MobilenetV1/Conv2d_{tf_index}_pointwise/'''
              lowerCamelCase__ :     Dict	  =	pointer.convolution.weight
              lowerCamelCase__ :     Optional[Any]	  =	pointer.normalization.bias
              lowerCamelCase__ :     Optional[Any]	  =	pointer.normalization.weight
              lowerCamelCase__ :     int	  =	pointer.normalization.running_mean
              lowerCamelCase__ :     str	  =	pointer.normalization.running_var

       if isinstance(a__    ,      a__				):
              lowerCamelCase__ :     List[Any]	  =	'''MobilenetV1/Logits/Conv2d_1c_1x1/'''
              lowerCamelCase__ :     List[str]	  =	model.classifier.weight
              lowerCamelCase__ :     List[str]	  =	model.classifier.bias

       return tf_to_pt_map





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase				)				->	int:



       try:
              import numpy as np
              import tensorflow as tf
       except ImportError:
              logger.error(
                  """Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see """
                  """https://www.tensorflow.org/install/ for installation instructions."""				)
              raise

       # Load weights from TF model
       lowerCamelCase__ :     Optional[Any]	  =	tf.train.list_variables(a__				)
       lowerCamelCase__ :     List[Any]	  =	{}
       for name, shape in init_vars:
              logger.info(f'''Loading TF weight {name} with shape {shape}'''				)
              lowerCamelCase__ :     Tuple	  =	tf.train.load_variable(a__    ,      a__				)
              lowerCamelCase__ :     Dict	  =	array

       # Build TF to PyTorch weights loading map
       lowerCamelCase__ :     int	  =	_build_tf_to_pytorch_map(a__    ,      a__    ,      a__				)

       for name, pointer in tf_to_pt_map.items():
              logger.info(f'''Importing {name}'''				)
              if name not in tf_weights:
                     logger.info(f'''{name} not in tf pre-trained weights, skipping'''				)
                     continue

              lowerCamelCase__ :     Union[str, Any]	  =	tf_weights[name]

              if "depthwise_weights" in name:
                     logger.info("""Transposing depthwise"""				)
                     lowerCamelCase__ :     Tuple	  =	np.transpose(a__    ,      (2, 3, 0, 1)				)
              elif "weights" in name:
                     logger.info("""Transposing"""				)
                     if len(pointer.shape				) == 2:  # copying into linear layer
                            lowerCamelCase__ :     Union[str, Any]	  =	array.squeeze().transpose()
                     else:
                            lowerCamelCase__ :     Optional[int]	  =	np.transpose(a__    ,      (3, 2, 0, 1)				)

              if pointer.shape != array.shape:
                     raise ValueError(f'''Pointer shape {pointer.shape} and array shape {array.shape} mismatched'''				)

              logger.info(f'''Initialize PyTorch weight {name} {array.shape}'''				)
              lowerCamelCase__ :     Tuple	  =	torch.from_numpy(a__				)

              tf_weights.pop(a__    ,      a__				)
              tf_weights.pop(name + """/RMSProp"""    ,      a__				)
              tf_weights.pop(name + """/RMSProp_1"""    ,      a__				)
              tf_weights.pop(name + """/ExponentialMovingAverage"""    ,      a__				)

       logger.info(f'''Weights not copied to PyTorch model: {', '.join(tf_weights.keys()				)}'''				)
       return model





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase				)				->	List[str]:
       lowerCamelCase__ :     List[Any]	  =	features.shape[-2:]
       lowerCamelCase__ :     List[Any]	  =	conv_layer.stride
       lowerCamelCase__ :     Optional[int]	  =	conv_layer.kernel_size

       if in_height % stride_height == 0:
              lowerCamelCase__ :     List[str]	  =	max(kernel_height - stride_height    ,      0				)
       else:
              lowerCamelCase__ :     str	  =	max(kernel_height - (in_height % stride_height)    ,      0				)

       if in_width % stride_width == 0:
              lowerCamelCase__ :     int	  =	max(kernel_width - stride_width    ,      0				)
       else:
              lowerCamelCase__ :     Tuple	  =	max(kernel_width - (in_width % stride_width)    ,      0				)

       lowerCamelCase__ :     List[str]	  =	pad_along_width // 2
       lowerCamelCase__ :     Any	  =	pad_along_width - pad_left
       lowerCamelCase__ :     str	  =	pad_along_height // 2
       lowerCamelCase__ :     Optional[int]	  =	pad_along_height - pad_top

       lowerCamelCase__ :     List[Any]	  =	(pad_left, pad_right, pad_top, pad_bottom)
       return nn.functional.pad(a__    ,      a__    ,      """constant"""    ,      0.0				)

class _lowercase     (    nn.Module		):




       def __init__(							self:    Any      ,							UpperCamelCase__:    Optional[Any]      ,							UpperCamelCase__:    str      ,							UpperCamelCase__:    int      ,							UpperCamelCase__:    int      ,							UpperCamelCase__:    Tuple = 1      ,							UpperCamelCase__:    Tuple = 1      ,							UpperCamelCase__:    Any = False      ,							UpperCamelCase__:    Optional[int] = True      ,							UpperCamelCase__:    Dict = True      ,							):
              super().__init__()
              lowerCamelCase__ :     Any	  =	config

              if in_channels % groups != 0:
                     raise ValueError(F'''Input channels ({in_channels}) are not divisible by {groups} groups.'''					)
              if out_channels % groups != 0:
                     raise ValueError(F'''Output channels ({out_channels}) are not divisible by {groups} groups.'''					)

              lowerCamelCase__ :     Any	  =	0 if config.tf_padding else int((kernel_size - 1) / 2					)

              lowerCamelCase__ :     List[str]	  =	nn.Convad(
                  in_channels=_lowerCamelCase      ,							out_channels=_lowerCamelCase      ,							kernel_size=_lowerCamelCase      ,							stride=_lowerCamelCase      ,							padding=_lowerCamelCase      ,							groups=_lowerCamelCase      ,							bias=_lowerCamelCase      ,							padding_mode="""zeros"""      ,							)

              if use_normalization:
                     lowerCamelCase__ :     List[Any]	  =	nn.BatchNormad(
                         num_features=_lowerCamelCase      ,							eps=config.layer_norm_eps      ,							momentum=0.9_997      ,							affine=_lowerCamelCase      ,							track_running_stats=_lowerCamelCase      ,							)
              else:
                     lowerCamelCase__ :     Dict	  =	None

              if use_activation:
                     if isinstance(_lowerCamelCase      ,							_lowerCamelCase					):
                            lowerCamelCase__ :     Any	  =	ACTaFN[use_activation]
                     elif isinstance(config.hidden_act      ,							_lowerCamelCase					):
                            lowerCamelCase__ :     List[str]	  =	ACTaFN[config.hidden_act]
                     else:
                            lowerCamelCase__ :     List[Any]	  =	config.hidden_act
              else:
                     lowerCamelCase__ :     Optional[Any]	  =	None




       def 		lowerCamelCase_    (							self:    int      ,							UpperCamelCase__:    Optional[Any]					):
              if self.config.tf_padding:
                     lowerCamelCase__ :     List[Any]	  =	apply_tf_padding(_lowerCamelCase      ,							self.convolution					)
              lowerCamelCase__ :     Dict	  =	self.convolution(_lowerCamelCase					)
              if self.normalization is not None:
                     lowerCamelCase__ :     int	  =	self.normalization(_lowerCamelCase					)
              if self.activation is not None:
                     lowerCamelCase__ :     List[Any]	  =	self.activation(_lowerCamelCase					)
              return features



class _lowercase     (    a__		):
       a    				=	MobileNetVaConfig
       a    				=	load_tf_weights_in_mobilenet_va
       a    				=	'mobilenet_v1'
       a    				=	'pixel_values'
       a    				=	False




       def 		lowerCamelCase_    (							self:    int      ,							UpperCamelCase__:    int					):
              if isinstance(_lowerCamelCase      ,							(nn.Linear, nn.Convad)					):
                     module.weight.data.normal_(mean=0.0      ,							std=self.config.initializer_range					)
                     if module.bias is not None:
                            module.bias.data.zero_()
              elif isinstance(_lowerCamelCase      ,							nn.BatchNormad					):
                     module.bias.data.zero_()
                     module.weight.data.fill_(1.0					)



_A     :      str   					=r'''
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it
    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`MobileNetV1Config`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
'''

_A     :      Union[str, Any]   					=r'''
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`MobileNetV1ImageProcessor.__call__`] for details.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
'''

@add_start_docstrings(
    """The bare MobileNetV1 model outputting raw hidden-states without any specific head on top."""    ,				a__    ,				)
class _lowercase     (    a__		):




       def __init__(							self:    int      ,							UpperCamelCase__:    Tuple      ,							UpperCamelCase__:    List[Any] = True					):
              super().__init__(_lowerCamelCase					)
              lowerCamelCase__ :     Optional[Any]	  =	config

              lowerCamelCase__ :     Dict	  =	32
              lowerCamelCase__ :     Optional[Any]	  =	max(int(depth * config.depth_multiplier					)      ,							config.min_depth					)

              lowerCamelCase__ :     str	  =	MobileNetVaConvLayer(
                  _lowerCamelCase      ,							in_channels=config.num_channels      ,							out_channels=_lowerCamelCase      ,							kernel_size=3      ,							stride=2      ,							)

              lowerCamelCase__ :     Union[str, Any]	  =	[1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1]

              lowerCamelCase__ :     Any	  =	nn.ModuleList()
              for i in range(13					):
                     lowerCamelCase__ :     int	  =	out_channels

                     if strides[i] == 2 or i == 0:
                            depth *= 2
                            lowerCamelCase__ :     Tuple	  =	max(int(depth * config.depth_multiplier					)      ,							config.min_depth					)

                     self.layer.append(
                         MobileNetVaConvLayer(
                             _lowerCamelCase      ,							in_channels=_lowerCamelCase      ,							out_channels=_lowerCamelCase      ,							kernel_size=3      ,							stride=strides[i]      ,							groups=_lowerCamelCase      ,							)					)

                     self.layer.append(
                         MobileNetVaConvLayer(
                             _lowerCamelCase      ,							in_channels=_lowerCamelCase      ,							out_channels=_lowerCamelCase      ,							kernel_size=1      ,							)					)

              lowerCamelCase__ :     int	  =	nn.AdaptiveAvgPoolad((1, 1)					) if add_pooling_layer else None

              # Initialize weights and apply final processing
              self.post_init()




       def 		lowerCamelCase_    (							self:    Optional[Any]      ,							UpperCamelCase__:    int					):
              raise NotImplementedError




       @add_start_docstrings_to_model_forward(_lowerCamelCase					)
       @add_code_sample_docstrings(
           checkpoint=_CHECKPOINT_FOR_DOC      ,							output_type=_lowerCamelCase      ,							config_class=_CONFIG_FOR_DOC      ,							modality="""vision"""      ,							expected_output=_EXPECTED_OUTPUT_SHAPE      ,							)
       def 		lowerCamelCase_    (							self:    Optional[int]      ,							UpperCamelCase__:    List[Any] = None      ,							UpperCamelCase__:    Optional[int] = None      ,							UpperCamelCase__:    Union[str, Any] = None      ,							):
              lowerCamelCase__ :     Union[str, Any]	  =	(
                  output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
              )
              lowerCamelCase__ :     List[Any]	  =	return_dict if return_dict is not None else self.config.use_return_dict

              if pixel_values is None:
                     raise ValueError("""You have to specify pixel_values"""					)

              lowerCamelCase__ :     Union[str, Any]	  =	self.conv_stem(_lowerCamelCase					)

              lowerCamelCase__ :     Tuple	  =	() if output_hidden_states else None

              for i, layer_module in enumerate(self.layer					):
                     lowerCamelCase__ :     Optional[int]	  =	layer_module(_lowerCamelCase					)

                     if output_hidden_states:
                            lowerCamelCase__ :     List[str]	  =	all_hidden_states + (hidden_states,)

              lowerCamelCase__ :     List[str]	  =	hidden_states

              if self.pooler is not None:
                     lowerCamelCase__ :     Tuple	  =	torch.flatten(self.pooler(_lowerCamelCase					)      ,							start_dim=1					)
              else:
                     lowerCamelCase__ :     List[Any]	  =	None

              if not return_dict:
                     return tuple(v for v in [last_hidden_state, pooled_output, all_hidden_states] if v is not None					)

              return BaseModelOutputWithPoolingAndNoAttention(
                  last_hidden_state=_lowerCamelCase      ,							pooler_output=_lowerCamelCase      ,							hidden_states=_lowerCamelCase      ,							)



@add_start_docstrings(
    """\n    MobileNetV1 model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    """    ,				a__    ,				)
class _lowercase     (    a__		):




       def __init__(							self:    List[str]      ,							UpperCamelCase__:    int					):
              super().__init__(_lowerCamelCase					)

              lowerCamelCase__ :     Optional[int]	  =	config.num_labels
              lowerCamelCase__ :     str	  =	MobileNetVaModel(_lowerCamelCase					)

              lowerCamelCase__ :     Dict	  =	self.mobilenet_va.layer[-1].convolution.out_channels

              # Classifier head
              lowerCamelCase__ :     Optional[int]	  =	nn.Dropout(config.classifier_dropout_prob      ,							inplace=_lowerCamelCase					)
              lowerCamelCase__ :     int	  =	nn.Linear(_lowerCamelCase      ,							config.num_labels					) if config.num_labels > 0 else nn.Identity()

              # Initialize weights and apply final processing
              self.post_init()




       @add_start_docstrings_to_model_forward(_lowerCamelCase					)
       @add_code_sample_docstrings(
           checkpoint=_IMAGE_CLASS_CHECKPOINT      ,							output_type=_lowerCamelCase      ,							config_class=_CONFIG_FOR_DOC      ,							expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT      ,							)
       def 		lowerCamelCase_    (							self:    Optional[Any]      ,							UpperCamelCase__:    int = None      ,							UpperCamelCase__:    Optional[Any] = None      ,							UpperCamelCase__:    Optional[int] = None      ,							UpperCamelCase__:    Optional[int] = None      ,							):
              lowerCamelCase__ :     Union[str, Any]	  =	return_dict if return_dict is not None else self.config.use_return_dict

              lowerCamelCase__ :     Dict	  =	self.mobilenet_va(_lowerCamelCase      ,							output_hidden_states=_lowerCamelCase      ,							return_dict=_lowerCamelCase					)

              lowerCamelCase__ :     List[Any]	  =	outputs.pooler_output if return_dict else outputs[1]

              lowerCamelCase__ :     Tuple	  =	self.classifier(self.dropout(_lowerCamelCase					)					)

              lowerCamelCase__ :     int	  =	None
              if labels is not None:
                     if self.config.problem_type is None:
                            if self.num_labels == 1:
                                   lowerCamelCase__ :     Any	  =	'''regression'''
                            elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
                                   lowerCamelCase__ :     Optional[int]	  =	'''single_label_classification'''
                            else:
                                   lowerCamelCase__ :     Dict	  =	'''multi_label_classification'''

                     if self.config.problem_type == "regression":
                            lowerCamelCase__ :     Any	  =	MSELoss()
                            if self.num_labels == 1:
                                   lowerCamelCase__ :     List[Any]	  =	loss_fct(logits.squeeze()      ,							labels.squeeze()					)
                            else:
                                   lowerCamelCase__ :     Dict	  =	loss_fct(_lowerCamelCase      ,							_lowerCamelCase					)
                     elif self.config.problem_type == "single_label_classification":
                            lowerCamelCase__ :     str	  =	CrossEntropyLoss()
                            lowerCamelCase__ :     int	  =	loss_fct(logits.view(-1      ,							self.num_labels					)      ,							labels.view(-1					)					)
                     elif self.config.problem_type == "multi_label_classification":
                            lowerCamelCase__ :     List[Any]	  =	BCEWithLogitsLoss()
                            lowerCamelCase__ :     List[Any]	  =	loss_fct(_lowerCamelCase      ,							_lowerCamelCase					)

              if not return_dict:
                     lowerCamelCase__ :     Optional[Any]	  =	(logits,) + outputs[2:]
                     return ((loss,) + output) if loss is not None else output

              return ImageClassifierOutputWithNoAttention(
                  loss=_lowerCamelCase      ,							logits=_lowerCamelCase      ,							hidden_states=outputs.hidden_states      ,							)









'''simple docstring'''







from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


_A     :      Optional[Any]   					=logging.get_logger(__name__)

_A     :      List[str]   					={
    '''Helsinki-NLP/opus-mt-en-de''': '''https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json''',
    # See all Marian models at https://huggingface.co/models?filter=marian
}

class _lowercase     (    _lowercase		):
							a    				=	"""marian"""
							a    				=	["""past_key_values"""]
							a    				=	{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}




							def __init__(							self:    Tuple      ,							UpperCamelCase__:    Optional[Any]=58_101      ,							UpperCamelCase__:    Optional[int]=None      ,							UpperCamelCase__:    Union[str, Any]=1_024      ,							UpperCamelCase__:    Any=12      ,							UpperCamelCase__:    Optional[int]=4_096      ,							UpperCamelCase__:    Tuple=16      ,							UpperCamelCase__:    Dict=12      ,							UpperCamelCase__:    Optional[Any]=4_096      ,							UpperCamelCase__:    Any=16      ,							UpperCamelCase__:    List[str]=0.0      ,							UpperCamelCase__:    Tuple=0.0      ,							UpperCamelCase__:    str=True      ,							UpperCamelCase__:    Optional[int]=True      ,							UpperCamelCase__:    Optional[int]="gelu"      ,							UpperCamelCase__:    Union[str, Any]=1_024      ,							UpperCamelCase__:    Optional[int]=0.1      ,							UpperCamelCase__:    Optional[Any]=0.0      ,							UpperCamelCase__:    Optional[Any]=0.0      ,							UpperCamelCase__:    Optional[int]=0.02      ,							UpperCamelCase__:    str=58_100      ,							UpperCamelCase__:    Tuple=False      ,							UpperCamelCase__:    Optional[Any]=58_100      ,							UpperCamelCase__:    int=0      ,							UpperCamelCase__:    Union[str, Any]=0      ,							UpperCamelCase__:    List[str]=True      ,							**UpperCamelCase__:    str      ,							):
														lowerCamelCase__ :     int	  =	vocab_size
														lowerCamelCase__ :     Tuple	  =	decoder_vocab_size or vocab_size
														lowerCamelCase__ :     List[str]	  =	max_position_embeddings
														lowerCamelCase__ :     Optional[Any]	  =	d_model
														lowerCamelCase__ :     int	  =	encoder_ffn_dim
														lowerCamelCase__ :     Union[str, Any]	  =	encoder_layers
														lowerCamelCase__ :     Dict	  =	encoder_attention_heads
														lowerCamelCase__ :     Optional[int]	  =	decoder_ffn_dim
														lowerCamelCase__ :     List[str]	  =	decoder_layers
														lowerCamelCase__ :     Dict	  =	decoder_attention_heads
														lowerCamelCase__ :     int	  =	dropout
														lowerCamelCase__ :     str	  =	attention_dropout
														lowerCamelCase__ :     Dict	  =	activation_dropout
														lowerCamelCase__ :     List[str]	  =	activation_function
														lowerCamelCase__ :     Union[str, Any]	  =	init_std
														lowerCamelCase__ :     str	  =	encoder_layerdrop
														lowerCamelCase__ :     Any	  =	decoder_layerdrop
														lowerCamelCase__ :     List[str]	  =	use_cache
														lowerCamelCase__ :     List[str]	  =	encoder_layers
														lowerCamelCase__ :     int	  =	scale_embedding  # scale factor will be sqrt(d_model) if True
														lowerCamelCase__ :     str	  =	share_encoder_decoder_embeddings
														super().__init__(
														    pad_token_id=UpperCamelCase__      ,							eos_token_id=UpperCamelCase__      ,							is_encoder_decoder=UpperCamelCase__      ,							decoder_start_token_id=UpperCamelCase__      ,							forced_eos_token_id=UpperCamelCase__      ,							**UpperCamelCase__      ,							)



class _lowercase     (    _lowercase		):




							@property
							# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
							def 		lowerCamelCase_    (							self:    Union[str, Any]					):
														if self.task in ["default", "seq2seq-lm"]:
																					lowerCamelCase__ :     List[str]	  =	OrderedDict(
																					    [
																					        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
																					        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
																					    ]					)

																					if self.use_past:
																												lowerCamelCase__ :     Dict	  =	{0: """batch"""}
																												lowerCamelCase__ :     Union[str, Any]	  =	{0: """batch""", 1: """past_decoder_sequence + sequence"""}
																					else:
																												lowerCamelCase__ :     Any	  =	{0: """batch""", 1: """decoder_sequence"""}
																												lowerCamelCase__ :     Dict	  =	{0: """batch""", 1: """decoder_sequence"""}

																					if self.use_past:
																												self.fill_with_past_key_values_(UpperCamelCase__      ,							direction="""inputs"""					)
														elif self.task == "causal-lm":
																					# TODO: figure this case out.
																					lowerCamelCase__ :     Union[str, Any]	  =	OrderedDict(
																					    [
																					        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
																					        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
																					    ]					)
																					if self.use_past:
																												lowerCamelCase__  ,		lowerCamelCase__ :     Tuple	  =	self.num_layers
																												for i in range(UpperCamelCase__					):
																																			lowerCamelCase__ :     Union[str, Any]	  =	{0: """batch""", 2: """past_sequence + sequence"""}
																																			lowerCamelCase__ :     List[str]	  =	{0: """batch""", 2: """past_sequence + sequence"""}
														else:
																					lowerCamelCase__ :     int	  =	OrderedDict(
																					    [
																					        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
																					        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
																					        ("""decoder_input_ids""", {0: """batch""", 1: """decoder_sequence"""}),
																					        ("""decoder_attention_mask""", {0: """batch""", 1: """decoder_sequence"""}),
																					    ]					)

														return common_inputs




							@property
							# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
							def 		lowerCamelCase_    (							self:    Optional[Any]					):
														if self.task in ["default", "seq2seq-lm"]:
																					lowerCamelCase__ :     Dict	  =	super().outputs
														else:
																					lowerCamelCase__ :     Any	  =	super(UpperCamelCase__      ,							self					).outputs
																					if self.use_past:
																												lowerCamelCase__  ,		lowerCamelCase__ :     str	  =	self.num_layers
																												for i in range(UpperCamelCase__					):
																																			lowerCamelCase__ :     Tuple	  =	{0: """batch""", 2: """past_sequence + sequence"""}
																																			lowerCamelCase__ :     Union[str, Any]	  =	{0: """batch""", 2: """past_sequence + sequence"""}
														return common_outputs




							def 		lowerCamelCase_    (							self:    str      ,							UpperCamelCase__:    PreTrainedTokenizer      ,							UpperCamelCase__:    int = -1      ,							UpperCamelCase__:    int = -1      ,							UpperCamelCase__:    bool = False      ,							UpperCamelCase__:    Optional[TensorType] = None      ,							):
														lowerCamelCase__ :     Union[str, Any]	  =	self._generate_dummy_inputs_for_encoder_and_decoder(
														    UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__					)

														# Generate decoder inputs
														lowerCamelCase__ :     Any	  =	seq_length if not self.use_past else 1
														lowerCamelCase__ :     Optional[Any]	  =	self._generate_dummy_inputs_for_encoder_and_decoder(
														    UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__					)
														lowerCamelCase__ :     str	  =	{F'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
														lowerCamelCase__ :     Optional[int]	  =	dict(**UpperCamelCase__      ,							**UpperCamelCase__					)

														if self.use_past:
																					if not is_torch_available():
																												raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""					)
																					else:
																												import torch
																					lowerCamelCase__  ,		lowerCamelCase__ :     Optional[Any]	  =	common_inputs["""input_ids"""].shape
																					lowerCamelCase__ :     Tuple	  =	common_inputs["""decoder_input_ids"""].shape[1]
																					lowerCamelCase__  ,		lowerCamelCase__ :     List[str]	  =	self.num_attention_heads
																					lowerCamelCase__ :     Any	  =	(
																					    batch,
																					    num_encoder_attention_heads,
																					    encoder_seq_length,
																					    self._config.hidden_size // num_encoder_attention_heads,
																					)
																					lowerCamelCase__ :     Tuple	  =	decoder_seq_length + 3
																					lowerCamelCase__ :     int	  =	(
																					    batch,
																					    num_decoder_attention_heads,
																					    decoder_past_length,
																					    self._config.hidden_size // num_decoder_attention_heads,
																					)

																					lowerCamelCase__ :     Optional[int]	  =	torch.cat(
																					    [common_inputs["""decoder_attention_mask"""], torch.ones(UpperCamelCase__      ,							UpperCamelCase__					)]      ,							dim=1					)

																					lowerCamelCase__ :     Any	  =	[]
																					# If the number of encoder and decoder layers are present in the model configuration, both are considered
																					lowerCamelCase__  ,		lowerCamelCase__ :     Any	  =	self.num_layers
																					lowerCamelCase__ :     str	  =	min(UpperCamelCase__      ,							UpperCamelCase__					)
																					lowerCamelCase__ :     str	  =	max(UpperCamelCase__      ,							UpperCamelCase__					) - min_num_layers
																					lowerCamelCase__ :     int	  =	"""encoder""" if num_encoder_layers > num_decoder_layers else """decoder"""

																					for _ in range(UpperCamelCase__					):
																												common_inputs["past_key_values"].append(
																												    (
																												        torch.zeros(UpperCamelCase__					),
																												        torch.zeros(UpperCamelCase__					),
																												        torch.zeros(UpperCamelCase__					),
																												        torch.zeros(UpperCamelCase__					),
																												    )					)
																					# TODO: test this.
																					lowerCamelCase__ :     Union[str, Any]	  =	encoder_shape if remaining_side_name == """encoder""" else decoder_shape
																					for _ in range(UpperCamelCase__      ,							UpperCamelCase__					):
																												common_inputs["past_key_values"].append((torch.zeros(UpperCamelCase__					), torch.zeros(UpperCamelCase__					))					)
														return common_inputs




							def 		lowerCamelCase_    (							self:    Optional[Any]      ,							UpperCamelCase__:    PreTrainedTokenizer      ,							UpperCamelCase__:    int = -1      ,							UpperCamelCase__:    int = -1      ,							UpperCamelCase__:    bool = False      ,							UpperCamelCase__:    Optional[TensorType] = None      ,							):
														lowerCamelCase__ :     Any	  =	self._generate_dummy_inputs_for_encoder_and_decoder(
														    UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__					)

														if self.use_past:
																					if not is_torch_available():
																												raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""					)
																					else:
																												import torch
																					lowerCamelCase__  ,		lowerCamelCase__ :     Any	  =	common_inputs["""input_ids"""].shape
																					# Not using the same length for past_key_values
																					lowerCamelCase__ :     Optional[Any]	  =	seqlen + 2
																					lowerCamelCase__  ,		lowerCamelCase__ :     Dict	  =	self.num_layers
																					lowerCamelCase__  ,		lowerCamelCase__ :     Dict	  =	self.num_attention_heads
																					lowerCamelCase__ :     Optional[Any]	  =	(
																					    batch,
																					    num_encoder_attention_heads,
																					    past_key_values_length,
																					    self._config.hidden_size // num_encoder_attention_heads,
																					)

																					lowerCamelCase__ :     Optional[Any]	  =	common_inputs["""attention_mask"""].dtype
																					lowerCamelCase__ :     int	  =	torch.cat(
																					    [common_inputs["""attention_mask"""], torch.ones(UpperCamelCase__      ,							UpperCamelCase__      ,							dtype=UpperCamelCase__					)]      ,							dim=1					)
																					lowerCamelCase__ :     int	  =	[
																					    (torch.zeros(UpperCamelCase__					), torch.zeros(UpperCamelCase__					)) for _ in range(UpperCamelCase__					)
																					]
														return common_inputs




							def 		lowerCamelCase_    (							self:    Optional[int]      ,							UpperCamelCase__:    PreTrainedTokenizer      ,							UpperCamelCase__:    int = -1      ,							UpperCamelCase__:    int = -1      ,							UpperCamelCase__:    bool = False      ,							UpperCamelCase__:    Optional[TensorType] = None      ,							):
														# Copied from OnnxConfig.generate_dummy_inputs
														# Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
														# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
														lowerCamelCase__ :     List[Any]	  =	compute_effective_axis_dimension(
														    UpperCamelCase__      ,							fixed_dimension=OnnxConfig.default_fixed_batch      ,							num_token_to_add=0					)

														# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
														lowerCamelCase__ :     Union[str, Any]	  =	tokenizer.num_special_tokens_to_add(UpperCamelCase__					)
														lowerCamelCase__ :     Any	  =	compute_effective_axis_dimension(
														    UpperCamelCase__      ,							fixed_dimension=OnnxConfig.default_fixed_sequence      ,							num_token_to_add=UpperCamelCase__					)

														# Generate dummy inputs according to compute batch and sequence
														lowerCamelCase__ :     Union[str, Any]	  =	[""" """.join([tokenizer.unk_token]					) * seq_length] * batch_size
														lowerCamelCase__ :     str	  =	dict(tokenizer(UpperCamelCase__      ,							return_tensors=UpperCamelCase__					)					)
														return common_inputs




							def 		lowerCamelCase_    (							self:    Optional[Any]      ,							UpperCamelCase__:    PreTrainedTokenizer      ,							UpperCamelCase__:    int = -1      ,							UpperCamelCase__:    int = -1      ,							UpperCamelCase__:    bool = False      ,							UpperCamelCase__:    Optional[TensorType] = None      ,							):
														if self.task in ["default", "seq2seq-lm"]:
																					lowerCamelCase__ :     Dict	  =	self._generate_dummy_inputs_for_default_and_seqaseq_lm(
																					    UpperCamelCase__      ,							batch_size=UpperCamelCase__      ,							seq_length=UpperCamelCase__      ,							is_pair=UpperCamelCase__      ,							framework=UpperCamelCase__					)

														else:
																					lowerCamelCase__ :     Tuple	  =	self._generate_dummy_inputs_for_causal_lm(
																					    UpperCamelCase__      ,							batch_size=UpperCamelCase__      ,							seq_length=UpperCamelCase__      ,							is_pair=UpperCamelCase__      ,							framework=UpperCamelCase__					)

														return common_inputs




							def 		lowerCamelCase_    (							self:    Union[str, Any]      ,							UpperCamelCase__:    Optional[Any]      ,							UpperCamelCase__:    List[Any]      ,							UpperCamelCase__:    Dict      ,							UpperCamelCase__:    Optional[Any]					):
														if self.task in ["default", "seq2seq-lm"]:
																					lowerCamelCase__ :     Dict	  =	super()._flatten_past_key_values_(UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__					)
														else:
																					lowerCamelCase__ :     List[Any]	  =	super(UpperCamelCase__      ,							self					)._flatten_past_key_values_(
																					    UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__      ,							UpperCamelCase__					)




							@property
							def 		lowerCamelCase_    (							self:    Union[str, Any]					):
														return 1e-4

