



'''simple docstring'''




from typing import List, Optional, Tuple, Union

import torch
from torch import nn
from torch.nn import CrossEntropyLoss

from ... import AutoBackbone
from ...modeling_outputs import SemanticSegmenterOutput
from ...modeling_utils import PreTrainedModel
from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
from ...utils.backbone_utils import BackboneMixin
from .configuration_upernet import UperNetConfig


lowerCamelCase							:Any       = [
    '''openmmlab/upernet-convnext-tiny''',
    # See all UperNet models at https://huggingface.co/models?filter=upernet
]

# General docstring
lowerCamelCase							:Optional[Any]       = '''UperNetConfig'''







class      _lowerCAmelCase							(      nn.Module			):


	def __init__(self	,				lowercase	,				lowercase	,				lowercase	,				lowercase = 0	,				lowercase = False	,				lowercase = 1	,				):
				super().__init__()
				A_     :						Any     =					nn.Convad(
				    in_channels=__snake_case	,				out_channels=__snake_case	,				kernel_size=__snake_case	,				padding=__snake_case	,				bias=__snake_case	,				dilation=__snake_case	,				)
				A_     :						Union[str, Any]     =					nn.BatchNormad(__snake_case							)
				A_     :						Dict     =					nn.ReLU()


	def    _a     (self	,				lowercase							):
				A_     :						Tuple     =					self.conv(__snake_case							)
				A_     :						int     =					self.batch_norm(__snake_case							)
				A_     :						str     =					self.activation(__snake_case							)

				return output







class      _lowerCAmelCase							(      nn.Module			):


	def __init__(self	,				lowercase	,				lowercase	,				lowercase							):
				super().__init__()
				A_     :						Dict     =					[
				    nn.AdaptiveAvgPoolad(__snake_case							),
				    UperNetConvModule(__snake_case	,				__snake_case	,				kernel_size=1							),
				]
				for i, layer in enumerate(self.layers							):
							self.add_module(str(__snake_case							)	,				__snake_case							)


	def    _a     (self	,				lowercase							):
				A_     :						List[str]     =					input
				for layer in self.layers:
							A_     :						int     =					layer(__snake_case							)
				return hidden_state







class      _lowerCAmelCase							(      nn.Module			):


	def __init__(self	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				super().__init__()
				A_     :						Optional[Any]     =					pool_scales
				A_     :						Optional[Any]     =					align_corners
				A_     :						List[Any]     =					in_channels
				A_     :						Any     =					channels
				A_     :						int     =					[]
				for i, pool_scale in enumerate(__snake_case							):
							A_     :						Tuple     =					UperNetPyramidPoolingBlock(pool_scale=__snake_case	,				in_channels=__snake_case	,				channels=__snake_case							)
							self.blocks.append(__snake_case							)
							self.add_module(str(__snake_case							)	,				__snake_case							)


	def    _a     (self	,				lowercase							):
				A_     :						Optional[int]     =					[]
				for ppm in self.blocks:
							A_     :						List[Any]     =					ppm(__snake_case							)
							A_     :						Dict     =					nn.functional.interpolate(
							    __snake_case	,				size=x.size()[2:]	,				mode="""bilinear"""	,				align_corners=self.align_corners							)
							ppm_outs.append(__snake_case							)
				return ppm_outs







class      _lowerCAmelCase							(      nn.Module			):


	def __init__(self	,				lowercase	,				lowercase							):
				super().__init__()

				A_     :						Dict     =					config
				A_     :						List[Any]     =					config.pool_scales  # e.g. (1, 2, 3, 6)
				A_     :						Tuple     =					in_channels
				A_     :						Tuple     =					config.hidden_size
				A_     :						Optional[int]     =					False
				A_     :						Optional[int]     =					nn.Convad(self.channels	,				config.num_labels	,				kernel_size=1							)

				# PSP Module
				A_     :						Optional[int]     =					UperNetPyramidPoolingModule(
				    self.pool_scales	,				self.in_channels[-1]	,				self.channels	,				align_corners=self.align_corners	,				)
				A_     :						Any     =					UperNetConvModule(
				    self.in_channels[-1] + len(self.pool_scales							) * self.channels	,				self.channels	,				kernel_size=3	,				padding=1	,				)
				# FPN Module
				A_     :						Optional[int]     =					nn.ModuleList()
				A_     :						Optional[Any]     =					nn.ModuleList()
				for in_channels in self.in_channels[:-1]:  # skip the top layer
							A_     :						Optional[int]     =					UperNetConvModule(__snake_case	,				self.channels	,				kernel_size=1							)
							A_     :						List[Any]     =					UperNetConvModule(self.channels	,				self.channels	,				kernel_size=3	,				padding=1							)
							self.lateral_convs.append(__snake_case							)
							self.fpn_convs.append(__snake_case							)

				A_     :						Union[str, Any]     =					UperNetConvModule(
				    len(self.in_channels							) * self.channels	,				self.channels	,				kernel_size=3	,				padding=1	,				)


	def    _a     (self							):
				self.apply(self._init_weights							)


	def    _a     (self	,				lowercase							):
				if isinstance(__snake_case	,				nn.Convad							):
							module.weight.data.normal_(mean=0.0	,				std=self.config.initializer_range							)
							if module.bias is not None:
										module.bias.data.zero_()


	def    _a     (self	,				lowercase							):
				A_     :						Any     =					inputs[-1]
				A_     :						int     =					[x]
				psp_outs.extend(self.psp_modules(__snake_case							)							)
				A_     :						str     =					torch.cat(__snake_case	,				dim=1							)
				A_     :						Optional[Any]     =					self.bottleneck(__snake_case							)

				return output


	def    _a     (self	,				lowercase							):
				# build laterals
				A_     :						str     =					[lateral_conv(encoder_hidden_states[i]							) for i, lateral_conv in enumerate(self.lateral_convs							)]

				laterals.append(self.psp_forward(__snake_case							)							)

				# build top-down path
				A_     :						str     =					len(__snake_case							)
				for i in range(used_backbone_levels - 1	,				0	,				-1							):
							A_     :						Any     =					laterals[i - 1].shape[2:]
							A_     :						Dict     =					laterals[i - 1] + nn.functional.interpolate(
							    laterals[i]	,				size=__snake_case	,				mode="""bilinear"""	,				align_corners=self.align_corners							)

				# build outputs
				A_     :						Dict     =					[self.fpn_convs[i](laterals[i]							) for i in range(used_backbone_levels - 1							)]
				# append psp feature
				fpn_outs.append(laterals[-1]							)

				for i in range(used_backbone_levels - 1	,				0	,				-1							):
							A_     :						Optional[Any]     =					nn.functional.interpolate(
							    fpn_outs[i]	,				size=fpn_outs[0].shape[2:]	,				mode="""bilinear"""	,				align_corners=self.align_corners							)
				A_     :						int     =					torch.cat(__snake_case	,				dim=1							)
				A_     :						Union[str, Any]     =					self.fpn_bottleneck(__snake_case							)
				A_     :						Optional[Any]     =					self.classifier(__snake_case							)

				return output







class      _lowerCAmelCase							(      nn.Module			):


	def __init__(self	,				lowercase	,				lowercase = 2	,				lowercase = 3	,				lowercase = 1							):
				super().__init__()

				A_     :						Any     =					config
				A_     :						Union[str, Any]     =					config.auxiliary_in_channels
				A_     :						Tuple     =					config.auxiliary_channels
				A_     :						Dict     =					config.auxiliary_num_convs
				A_     :						Tuple     =					config.auxiliary_concat_input
				A_     :						Dict     =					in_index

				A_     :						Union[str, Any]     =					(kernel_size // 2) * dilation
				A_     :						Union[str, Any]     =					[]
				convs.append(
				    UperNetConvModule(
				        self.in_channels	,				self.channels	,				kernel_size=__snake_case	,				padding=__snake_case	,				dilation=__snake_case							)							)
				for i in range(self.num_convs - 1							):
							convs.append(
							    UperNetConvModule(
							        self.channels	,				self.channels	,				kernel_size=__snake_case	,				padding=__snake_case	,				dilation=__snake_case							)							)
				if self.num_convs == 0:
							A_     :						Optional[int]     =					nn.Identity()
				else:
							A_     :						List[Any]     =					nn.Sequential(*__snake_case							)
				if self.concat_input:
							A_     :						Dict     =					UperNetConvModule(
							    self.in_channels + self.channels	,				self.channels	,				kernel_size=__snake_case	,				padding=kernel_size // 2							)

				A_     :						Optional[Any]     =					nn.Convad(self.channels	,				config.num_labels	,				kernel_size=1							)


	def    _a     (self							):
				self.apply(self._init_weights							)


	def    _a     (self	,				lowercase							):
				if isinstance(__snake_case	,				nn.Convad							):
							module.weight.data.normal_(mean=0.0	,				std=self.config.initializer_range							)
							if module.bias is not None:
										module.bias.data.zero_()


	def    _a     (self	,				lowercase							):
				# just take the relevant feature maps
				A_     :						Optional[int]     =					encoder_hidden_states[self.in_index]
				A_     :						Union[str, Any]     =					self.convs(__snake_case							)
				if self.concat_input:
							A_     :						str     =					self.conv_cat(torch.cat([hidden_states, output]	,				dim=1							)							)
				A_     :						str     =					self.classifier(__snake_case							)
				return output







class      _lowerCAmelCase							(      A__			):
	__SCREAMING_SNAKE_CASE       :		List[str]		      = UperNetConfig
	__SCREAMING_SNAKE_CASE       :		List[Any]		      = 'pixel_values'
	__SCREAMING_SNAKE_CASE       :		Union[str, Any]		      = True


	def    _a     (self	,				lowercase							):
				if isinstance(__snake_case	,				__snake_case							):
							module.backbone.init_weights()
							module.decode_head.init_weights()
							module.auxiliary_head.init_weights()


	def    _a     (self							):
				self.backbone.init_weights()
				self.decode_head.init_weights()
				self.auxiliary_head.init_weights()


	def    _a     (self	,				lowercase	,				lowercase=False							):
				if isinstance(__snake_case	,				__snake_case							):
							A_     :						str     =					value






lowerCamelCase							:Union[str, Any]       = R'''\n    Parameters:\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use\n    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n        config ([`UperNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'''

lowerCamelCase							:str       = R'''\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using\n            [`AutoImageProcessor`]. See [`SegformerImageProcessor.__call__`] for details.\n        output_attentions (`bool`, *optional*):\n            Whether or not to return the attentions tensors of all attention layers in case the backbone has them. See\n            `attentions` under returned tensors for more detail.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers of the backbone. See `hidden_states` under\n            returned tensors for more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'''







@add_start_docstrings(
    'UperNet framework leveraging any vision backbone e.g. for ADE20k, CityScapes.'				,      A__				,      )
class      _lowerCAmelCase							(      A__			):


	def __init__(self	,				lowercase							):
				super().__init__(__snake_case							)

				A_     :						List[str]     =					AutoBackbone.from_config(config.backbone_config							)

				# Semantic segmentation head(s)
				A_     :						Dict     =					UperNetHead(__snake_case	,				in_channels=self.backbone.channels							)
				A_     :						Optional[int]     =					UperNetFCNHead(__snake_case							) if config.use_auxiliary_head else None

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


	@add_start_docstrings_to_model_forward(UPERNET_INPUTS_DOCSTRING.format("""batch_size, sequence_length"""							)							)
	@replace_return_docstrings(output_type=__snake_case	,				config_class=_CONFIG_FOR_DOC							)
	def    _a     (self	,				lowercase = None	,				lowercase = None	,				lowercase = None	,				lowercase = None	,				lowercase = None	,				):
				A_     :						Dict     =					return_dict if return_dict is not None else self.config.use_return_dict
				A_     :						Any     =					(
				    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
				)
				A_     :						List[Any]     =					output_attentions if output_attentions is not None else self.config.output_attentions

				A_     :						Dict     =					self.backbone.forward_with_filtered_kwargs(
				    __snake_case	,				output_hidden_states=__snake_case	,				output_attentions=__snake_case							)
				A_     :						Tuple     =					outputs.feature_maps

				A_     :						Union[str, Any]     =					self.decode_head(__snake_case							)
				A_     :						Any     =					nn.functional.interpolate(__snake_case	,				size=pixel_values.shape[2:]	,				mode="""bilinear"""	,				align_corners=__snake_case							)

				A_     :						Tuple     =					None
				if self.auxiliary_head is not None:
							A_     :						Dict     =					self.auxiliary_head(__snake_case							)
							A_     :						Optional[Any]     =					nn.functional.interpolate(
							    __snake_case	,				size=pixel_values.shape[2:]	,				mode="""bilinear"""	,				align_corners=__snake_case							)

				A_     :						Optional[int]     =					None
				if labels is not None:
							if self.config.num_labels == 1:
										raise ValueError("""The number of labels should be greater than one"""							)
							else:
										# compute weighted loss
										A_     :						int     =					CrossEntropyLoss(ignore_index=self.config.loss_ignore_index							)
										A_     :						str     =					loss_fct(__snake_case	,				__snake_case							)
										A_     :						int     =					loss_fct(__snake_case	,				__snake_case							)
										A_     :						int     =					main_loss + self.config.auxiliary_loss_weight * auxiliary_loss

				if not return_dict:
							if output_hidden_states:
										A_     :						Optional[Any]     =					(logits,) + outputs[1:]
							else:
										A_     :						List[str]     =					(logits,) + outputs[2:]
							return ((loss,) + output) if loss is not None else output

				return SemanticSegmenterOutput(
				    loss=__snake_case	,				logits=__snake_case	,				hidden_states=outputs.hidden_states	,				attentions=outputs.attentions	,				)




'''simple docstring'''




import warnings
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


lowerCamelCase							:Dict       = logging.get_logger(__name__)

lowerCamelCase							:Any       = {
    '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/config.json''',
    # See all BART models at https://huggingface.co/models?filter=bart
}







class      _lowerCAmelCase							(      __UpperCAmelCase			):
	__SCREAMING_SNAKE_CASE       :		List[Any]		      = 'bart'
	__SCREAMING_SNAKE_CASE       :		Union[str, Any]		      = ['past_key_values']
	__SCREAMING_SNAKE_CASE       :		Dict		      = {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}


	def __init__(self	,				lowercase=50265	,				lowercase=1024	,				lowercase=12	,				lowercase=4096	,				lowercase=16	,				lowercase=12	,				lowercase=4096	,				lowercase=16	,				lowercase=0.0	,				lowercase=0.0	,				lowercase="gelu"	,				lowercase=1024	,				lowercase=0.1	,				lowercase=0.0	,				lowercase=0.0	,				lowercase=0.02	,				lowercase=0.0	,				lowercase=False	,				lowercase=True	,				lowercase=3	,				lowercase=1	,				lowercase=0	,				lowercase=2	,				lowercase=True	,				lowercase=2	,				lowercase=2	,				**lowercase	,				):
				A_     :						Optional[int]     =					vocab_size
				A_     :						Dict     =					max_position_embeddings
				A_     :						Dict     =					d_model
				A_     :						Any     =					encoder_ffn_dim
				A_     :						Dict     =					encoder_layers
				A_     :						Optional[int]     =					encoder_attention_heads
				A_     :						Tuple     =					decoder_ffn_dim
				A_     :						List[str]     =					decoder_layers
				A_     :						int     =					decoder_attention_heads
				A_     :						Dict     =					dropout
				A_     :						List[str]     =					attention_dropout
				A_     :						int     =					activation_dropout
				A_     :						Dict     =					activation_function
				A_     :						List[Any]     =					init_std
				A_     :						Dict     =					encoder_layerdrop
				A_     :						Tuple     =					decoder_layerdrop
				A_     :						Optional[int]     =					classifier_dropout
				A_     :						Union[str, Any]     =					use_cache
				A_     :						Dict     =					encoder_layers
				A_     :						Dict     =					scale_embedding  # scale factor will be sqrt(d_model) if True

				super().__init__(
				    num_labels=lowercase	,				pad_token_id=lowercase	,				bos_token_id=lowercase	,				eos_token_id=lowercase	,				is_encoder_decoder=lowercase	,				decoder_start_token_id=lowercase	,				forced_eos_token_id=lowercase	,				**lowercase	,				)

				# ensure backward compatibility for BART CNN models
				if self.forced_bos_token_id is None and kwargs.get("""force_bos_token_to_be_generated"""	,				lowercase							):
							A_     :						List[str]     =					self.bos_token_id
							warnings.warn(
							    F'Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. '
							    """The config can simply be saved and uploaded again to be fixed."""							)







class      _lowerCAmelCase							(      __UpperCAmelCase			):


	@property
	def    _a     (self							):
				if self.task in ["default", "seq2seq-lm"]:
							A_     :						List[Any]     =					OrderedDict(
							    [
							        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
							        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
							    ]							)

							if self.use_past:
										A_     :						Union[str, Any]     =					{0: """batch"""}
										A_     :						List[Any]     =					{0: """batch""", 1: """past_decoder_sequence + sequence"""}
							else:
										A_     :						Optional[int]     =					{0: """batch""", 1: """decoder_sequence"""}
										A_     :						List[str]     =					{0: """batch""", 1: """decoder_sequence"""}

							if self.use_past:
										self.fill_with_past_key_values_(lowercase	,				direction="""inputs"""							)
				elif self.task == "causal-lm":
							# TODO: figure this case out.
							A_     :						List[Any]     =					OrderedDict(
							    [
							        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
							        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
							    ]							)
							if self.use_past:
										A_,   A_     :						Optional[int]     =					self.num_layers
										for i in range(lowercase							):
													A_     :						List[str]     =					{0: """batch""", 2: """past_sequence + sequence"""}
													A_     :						List[str]     =					{0: """batch""", 2: """past_sequence + sequence"""}
				else:
							A_     :						Union[str, Any]     =					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
	def    _a     (self							):
				if self.task in ["default", "seq2seq-lm"]:
							A_     :						int     =					super().outputs
				else:
							A_     :						int     =					super(lowercase	,				self							).outputs
							if self.use_past:
										A_,   A_     :						Union[str, Any]     =					self.num_layers
										for i in range(lowercase							):
													A_     :						List[str]     =					{0: """batch""", 2: """past_sequence + sequence"""}
													A_     :						Optional[int]     =					{0: """batch""", 2: """past_sequence + sequence"""}
				return common_outputs


	def    _a     (self	,				lowercase	,				lowercase = -1	,				lowercase = -1	,				lowercase = False	,				lowercase = None	,				):
				A_     :						Optional[int]     =					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
				    lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							)

				# Generate decoder inputs
				A_     :						int     =					seq_length if not self.use_past else 1
				A_     :						int     =					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
				    lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							)
				A_     :						Optional[int]     =					{F'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
				A_     :						Dict     =					dict(**lowercase	,				**lowercase							)

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

							A_     :						List[str]     =					torch.cat(
							    [common_inputs["""decoder_attention_mask"""], torch.ones(lowercase	,				lowercase							)]	,				dim=1							)

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

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


	def    _a     (self	,				lowercase	,				lowercase = -1	,				lowercase = -1	,				lowercase = False	,				lowercase = None	,				):
				A_     :						Dict     =					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
				    lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							)

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

							A_     :						Union[str, Any]     =					common_inputs["""attention_mask"""].dtype
							A_     :						int     =					torch.cat(
							    [common_inputs["""attention_mask"""], torch.ones(lowercase	,				lowercase	,				dtype=lowercase							)]	,				dim=1							)
							A_     :						int     =					[
							    (torch.zeros(lowercase							), torch.zeros(lowercase							)) for _ in range(lowercase							)
							]
				return common_inputs


	def    _a     (self	,				lowercase	,				lowercase = -1	,				lowercase = -1	,				lowercase = False	,				lowercase = 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
				A_     :						List[Any]     =					compute_effective_axis_dimension(
				    lowercase	,				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
				A_     :						Union[str, Any]     =					tokenizer.num_special_tokens_to_add(lowercase							)
				A_     :						List[Any]     =					compute_effective_axis_dimension(
				    lowercase	,				fixed_dimension=OnnxConfig.default_fixed_sequence	,				num_token_to_add=lowercase							)

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


	def    _a     (self	,				lowercase	,				lowercase = -1	,				lowercase = -1	,				lowercase = False	,				lowercase = None	,				):
				if self.task in ["default", "seq2seq-lm"]:
							A_     :						Union[str, Any]     =					self._generate_dummy_inputs_for_default_and_seqaseq_lm(
							    lowercase	,				batch_size=lowercase	,				seq_length=lowercase	,				is_pair=lowercase	,				framework=lowercase							)

				elif self.task == "causal-lm":
							A_     :						List[str]     =					self._generate_dummy_inputs_for_causal_lm(
							    lowercase	,				batch_size=lowercase	,				seq_length=lowercase	,				is_pair=lowercase	,				framework=lowercase							)
				else:
							A_     :						Optional[Any]     =					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowercase	,				batch_size=lowercase	,				seq_length=lowercase	,				is_pair=lowercase	,				framework=lowercase							)

				return common_inputs


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				if self.task in ["default", "seq2seq-lm"]:
							A_     :						Optional[Any]     =					super()._flatten_past_key_values_(lowercase	,				lowercase	,				lowercase	,				lowercase							)
				else:
							A_     :						List[Any]     =					super(lowercase	,				self							)._flatten_past_key_values_(
							    lowercase	,				lowercase	,				lowercase	,				lowercase							)