






from dataclasses import dataclass
from typing import Dict, Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .attention_processor import AttentionProcessor, AttnProcessor
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, DiagonalGaussianDistribution, Encoder



@dataclass
class 							_UpperCamelCase			(a_			):
      snake_case_  =							42



class 							_UpperCamelCase			(a_							,		a_			):
      snake_case_  =							True


      @register_to_config
      def __init__(	self					,						__UpperCamelCase = 3					,						__UpperCamelCase = 3					,						__UpperCamelCase = ("DownEncoderBlock2D",)					,						__UpperCamelCase = ("UpDecoderBlock2D",)					,						__UpperCamelCase = (6_4,)					,						__UpperCamelCase = 1					,						__UpperCamelCase = "silu"					,						__UpperCamelCase = 4					,						__UpperCamelCase = 3_2					,						__UpperCamelCase = 3_2					,						__UpperCamelCase = 0.1_8_2_1_5					,						)->	Any:
           super().__init__()

           # pass init params to Encoder
           __lowerCAmelCase								=					Encoder(
               in_channels=__UpperCamelCase					,						out_channels=__UpperCamelCase					,						down_block_types=__UpperCamelCase					,						block_out_channels=__UpperCamelCase					,						layers_per_block=__UpperCamelCase					,						act_fn=__UpperCamelCase					,						norm_num_groups=__UpperCamelCase					,						double_z=__UpperCamelCase					,						)

           # pass init params to Decoder
           __lowerCAmelCase								=					Decoder(
               in_channels=__UpperCamelCase					,						out_channels=__UpperCamelCase					,						up_block_types=__UpperCamelCase					,						block_out_channels=__UpperCamelCase					,						layers_per_block=__UpperCamelCase					,						norm_num_groups=__UpperCamelCase					,						act_fn=__UpperCamelCase					,						)

           __lowerCAmelCase								=					nn.Convad(2 * latent_channels					,						2 * latent_channels					,						1	)
           __lowerCAmelCase								=					nn.Convad(__UpperCamelCase					,						__UpperCamelCase					,						1	)

           __lowerCAmelCase								=					False
           __lowerCAmelCase								=					False

           # only relevant if vae tiling is enabled
           __lowerCAmelCase								=					self.config.sample_size
           __lowerCAmelCase								=					(
               self.config.sample_size[0]
               if isinstance(self.config.sample_size					,						(list, tuple)	)
               else self.config.sample_size
           )
           __lowerCAmelCase								=					int(sample_size / (2 ** (len(self.config.block_out_channels	) - 1))	)
           __lowerCAmelCase								=					0.2_5


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase=False	)->	Optional[Any]:
           if isinstance(__UpperCamelCase					,						(Encoder, Decoder)	):
                __lowerCAmelCase								=					value


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase = True	)->	Optional[Any]:
           __lowerCAmelCase								=					use_tiling


      def  __UpperCAmelCase		(	self	)->	Union[str, Any]:
           self.enable_tiling(__UpperCamelCase	)


      def  __UpperCAmelCase		(	self	)->	Union[str, Any]:
           __lowerCAmelCase								=					True


      def  __UpperCAmelCase		(	self	)->	int:
           __lowerCAmelCase								=					False


      @property
      # Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.attn_processors
      def  __UpperCAmelCase		(	self	)->	Dict[str, AttentionProcessor]:
           __lowerCAmelCase								=					{}

           def fn_recursive_add_processors(__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	):
                if hasattr(__UpperCamelCase					,						"set_processor"	):
                     __lowerCAmelCase								=					module.processor

                for sub_name, child in module.named_children():
                     fn_recursive_add_processors(F"""{name}.{sub_name}"""					,						__UpperCamelCase					,						__UpperCamelCase	)

                return processors

           for name, module in self.named_children():
                fn_recursive_add_processors(__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)

           return processors


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase	)->	List[Any]:
           __lowerCAmelCase								=					len(self.attn_processors.keys()	)

           if isinstance(__UpperCamelCase					,						__UpperCamelCase	) and len(__UpperCamelCase	) != count:
                raise ValueError(
                    F"""A dict of processors was passed, but the number of processors {len(__UpperCamelCase	)} does not match the"""
                    F""" number of attention layers: {count}. Please make sure to pass {count} processor classes."""	)

           def fn_recursive_attn_processor(__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	):
                if hasattr(__UpperCamelCase					,						"set_processor"	):
                     if not isinstance(__UpperCamelCase					,						__UpperCamelCase	):
                          module.set_processor(__UpperCamelCase	)
                     else:
                          module.set_processor(processor.pop(F"""{name}.processor"""	)	)

                for sub_name, child in module.named_children():
                     fn_recursive_attn_processor(F"""{name}.{sub_name}"""					,						__UpperCamelCase					,						__UpperCamelCase	)

           for name, module in self.named_children():
                fn_recursive_attn_processor(__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)


      def  __UpperCAmelCase		(	self	)->	List[str]:
           self.set_attn_processor(AttnProcessor()	)


      @apply_forward_hook
      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = True	)->	AutoencoderKLOutput:
           if self.use_tiling and (x.shape[-1] > self.tile_sample_min_size or x.shape[-2] > self.tile_sample_min_size):
                return self.tiled_encode(__UpperCamelCase					,						return_dict=__UpperCamelCase	)

           if self.use_slicing and x.shape[0] > 1:
                __lowerCAmelCase								=					[self.encoder(__UpperCamelCase	) for x_slice in x.split(1	)]
                __lowerCAmelCase								=					torch.cat(__UpperCamelCase	)
           else:
                __lowerCAmelCase								=					self.encoder(__UpperCamelCase	)

           __lowerCAmelCase								=					self.quant_conv(__UpperCamelCase	)
           __lowerCAmelCase								=					DiagonalGaussianDistribution(__UpperCamelCase	)

           if not return_dict:
                return (posterior,)

           return AutoencoderKLOutput(latent_dist=__UpperCamelCase	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = True	)->	Union[DecoderOutput, torch.FloatTensor]:
           if self.use_tiling and (z.shape[-1] > self.tile_latent_min_size or z.shape[-2] > self.tile_latent_min_size):
                return self.tiled_decode(__UpperCamelCase					,						return_dict=__UpperCamelCase	)

           __lowerCAmelCase								=					self.post_quant_conv(__UpperCamelCase	)
           __lowerCAmelCase								=					self.decoder(__UpperCamelCase	)

           if not return_dict:
                return (dec,)

           return DecoderOutput(sample=__UpperCamelCase	)


      @apply_forward_hook
      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = True	)->	Union[DecoderOutput, torch.FloatTensor]:
           if self.use_slicing and z.shape[0] > 1:
                __lowerCAmelCase								=					[self._decode(__UpperCamelCase	).sample for z_slice in z.split(1	)]
                __lowerCAmelCase								=					torch.cat(__UpperCamelCase	)
           else:
                __lowerCAmelCase								=					self._decode(__UpperCamelCase	).sample

           if not return_dict:
                return (decoded,)

           return DecoderOutput(sample=__UpperCamelCase	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	Optional[Any]:
           __lowerCAmelCase								=					min(a.shape[2]					,						b.shape[2]					,						__UpperCamelCase	)
           for y in range(__UpperCamelCase	):
                __lowerCAmelCase								=					a[:, :, -blend_extent + y, :] * (1 - y / blend_extent) + b[:, :, y, :] * (y / blend_extent)
           return b


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	Tuple:
           __lowerCAmelCase								=					min(a.shape[3]					,						b.shape[3]					,						__UpperCamelCase	)
           for x in range(__UpperCamelCase	):
                __lowerCAmelCase								=					a[:, :, :, -blend_extent + x] * (1 - x / blend_extent) + b[:, :, :, x] * (x / blend_extent)
           return b


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = True	)->	AutoencoderKLOutput:
           __lowerCAmelCase								=					int(self.tile_sample_min_size * (1 - self.tile_overlap_factor)	)
           __lowerCAmelCase								=					int(self.tile_latent_min_size * self.tile_overlap_factor	)
           __lowerCAmelCase								=					self.tile_latent_min_size - blend_extent

           # Split the image into 512x512 tiles and encode them separately.
           __lowerCAmelCase								=					[]
           for i in range(0					,						x.shape[2]					,						__UpperCamelCase	):
                __lowerCAmelCase								=					[]
                for j in range(0					,						x.shape[3]					,						__UpperCamelCase	):
                     __lowerCAmelCase								=					x[:, :, i : i + self.tile_sample_min_size, j : j + self.tile_sample_min_size]
                     __lowerCAmelCase								=					self.encoder(__UpperCamelCase	)
                     __lowerCAmelCase								=					self.quant_conv(__UpperCamelCase	)
                     row.append(__UpperCamelCase	)
                rows.append(__UpperCamelCase	)
           __lowerCAmelCase								=					[]
           for i, row in enumerate(__UpperCamelCase	):
                __lowerCAmelCase								=					[]
                for j, tile in enumerate(__UpperCamelCase	):
                     # blend the above tile and the left tile
                     # to the current tile and add the current tile to the result row
                     if i > 0:
                          __lowerCAmelCase								=					self.blend_v(rows[i - 1][j]					,						__UpperCamelCase					,						__UpperCamelCase	)
                     if j > 0:
                          __lowerCAmelCase								=					self.blend_h(row[j - 1]					,						__UpperCamelCase					,						__UpperCamelCase	)
                     result_row.append(tile[:, :, :row_limit, :row_limit]	)
                result_rows.append(torch.cat(__UpperCamelCase					,						dim=3	)	)

           __lowerCAmelCase								=					torch.cat(__UpperCamelCase					,						dim=2	)
           __lowerCAmelCase								=					DiagonalGaussianDistribution(__UpperCamelCase	)

           if not return_dict:
                return (posterior,)

           return AutoencoderKLOutput(latent_dist=__UpperCamelCase	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = True	)->	Union[DecoderOutput, torch.FloatTensor]:
           __lowerCAmelCase								=					int(self.tile_latent_min_size * (1 - self.tile_overlap_factor)	)
           __lowerCAmelCase								=					int(self.tile_sample_min_size * self.tile_overlap_factor	)
           __lowerCAmelCase								=					self.tile_sample_min_size - blend_extent

           # Split z into overlapping 64x64 tiles and decode them separately.
           # The tiles have an overlap to avoid seams between tiles.
           __lowerCAmelCase								=					[]
           for i in range(0					,						z.shape[2]					,						__UpperCamelCase	):
                __lowerCAmelCase								=					[]
                for j in range(0					,						z.shape[3]					,						__UpperCamelCase	):
                     __lowerCAmelCase								=					z[:, :, i : i + self.tile_latent_min_size, j : j + self.tile_latent_min_size]
                     __lowerCAmelCase								=					self.post_quant_conv(__UpperCamelCase	)
                     __lowerCAmelCase								=					self.decoder(__UpperCamelCase	)
                     row.append(__UpperCamelCase	)
                rows.append(__UpperCamelCase	)
           __lowerCAmelCase								=					[]
           for i, row in enumerate(__UpperCamelCase	):
                __lowerCAmelCase								=					[]
                for j, tile in enumerate(__UpperCamelCase	):
                     # blend the above tile and the left tile
                     # to the current tile and add the current tile to the result row
                     if i > 0:
                          __lowerCAmelCase								=					self.blend_v(rows[i - 1][j]					,						__UpperCamelCase					,						__UpperCamelCase	)
                     if j > 0:
                          __lowerCAmelCase								=					self.blend_h(row[j - 1]					,						__UpperCamelCase					,						__UpperCamelCase	)
                     result_row.append(tile[:, :, :row_limit, :row_limit]	)
                result_rows.append(torch.cat(__UpperCamelCase					,						dim=3	)	)

           __lowerCAmelCase								=					torch.cat(__UpperCamelCase					,						dim=2	)
           if not return_dict:
                return (dec,)

           return DecoderOutput(sample=__UpperCamelCase	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = False					,						__UpperCamelCase = True					,						__UpperCamelCase = None					,						)->	Union[DecoderOutput, torch.FloatTensor]:
           __lowerCAmelCase								=					sample
           __lowerCAmelCase								=					self.encode(__UpperCamelCase	).latent_dist
           if sample_posterior:
                __lowerCAmelCase								=					posterior.sample(generator=__UpperCamelCase	)
           else:
                __lowerCAmelCase								=					posterior.mode()
           __lowerCAmelCase								=					self.decode(__UpperCamelCase	).sample

           if not return_dict:
                return (dec,)

           return DecoderOutput(sample=__UpperCamelCase	)














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

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


lowerCamelCase			:					List[Any]         =	logging.get_logger(__name__)

lowerCamelCase			:					Union[str, Any]         =	{
    '''facebook/blenderbot_small-90M''': '''https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/config.json''',
    # See all BlenderbotSmall models at https://huggingface.co/models?filter=blenderbot_small
}



class 							_UpperCamelCase			(a_			):
      snake_case_  =							"""blenderbot-small"""
      snake_case_  =							["""past_key_values"""]
      snake_case_  =							{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}


      def __init__(	self					,						__UpperCamelCase=5_0_2_6_5					,						__UpperCamelCase=5_1_2					,						__UpperCamelCase=8					,						__UpperCamelCase=2_0_4_8					,						__UpperCamelCase=1_6					,						__UpperCamelCase=8					,						__UpperCamelCase=2_0_4_8					,						__UpperCamelCase=1_6					,						__UpperCamelCase=0.0					,						__UpperCamelCase=0.0					,						__UpperCamelCase=True					,						__UpperCamelCase=True					,						__UpperCamelCase="gelu"					,						__UpperCamelCase=5_1_2					,						__UpperCamelCase=0.1					,						__UpperCamelCase=0.0					,						__UpperCamelCase=0.0					,						__UpperCamelCase=0.0_2					,						__UpperCamelCase=1					,						__UpperCamelCase=False					,						__UpperCamelCase=0					,						__UpperCamelCase=1					,						__UpperCamelCase=2					,						__UpperCamelCase=2					,						**__UpperCamelCase					,						)->	Any:
           __lowerCAmelCase								=					vocab_size
           __lowerCAmelCase								=					max_position_embeddings
           __lowerCAmelCase								=					d_model
           __lowerCAmelCase								=					encoder_ffn_dim
           __lowerCAmelCase								=					encoder_layers
           __lowerCAmelCase								=					encoder_attention_heads
           __lowerCAmelCase								=					decoder_ffn_dim
           __lowerCAmelCase								=					decoder_layers
           __lowerCAmelCase								=					decoder_attention_heads
           __lowerCAmelCase								=					dropout
           __lowerCAmelCase								=					attention_dropout
           __lowerCAmelCase								=					activation_dropout
           __lowerCAmelCase								=					activation_function
           __lowerCAmelCase								=					init_std
           __lowerCAmelCase								=					encoder_layerdrop
           __lowerCAmelCase								=					decoder_layerdrop
           __lowerCAmelCase								=					use_cache
           __lowerCAmelCase								=					encoder_layers
           __lowerCAmelCase								=					scale_embedding  # scale factor will be sqrt(d_model) if True

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



class 							_UpperCamelCase			(a_			):


      @property
      def  __UpperCAmelCase		(	self	)->	Mapping[str, Mapping[int, str]]:
           if self.task in ["default", "seq2seq-lm"]:
                __lowerCAmelCase								=					OrderedDict(
                    [
                        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
                    ]	)

                if self.use_past:
                     __lowerCAmelCase								=					{0: "batch"}
                     __lowerCAmelCase								=					{0: "batch", 1: "past_decoder_sequence + sequence"}
                else:
                     __lowerCAmelCase								=					{0: "batch", 1: "decoder_sequence"}
                     __lowerCAmelCase								=					{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								=					OrderedDict(
                    [
                        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
                    ]	)
                if self.use_past:
                     __lowerCAmelCase			, __lowerCAmelCase								=					self.num_layers
                     for i in range(__UpperCamelCase	):
                          __lowerCAmelCase								=					{0: "batch", 2: "past_sequence + sequence"}
                          __lowerCAmelCase								=					{0: "batch", 2: "past_sequence + sequence"}
           else:
                __lowerCAmelCase								=					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  __UpperCAmelCase		(	self	)->	Mapping[str, Mapping[int, str]]:
           if self.task in ["default", "seq2seq-lm"]:
                __lowerCAmelCase								=					super().outputs
           else:
                __lowerCAmelCase								=					super(__UpperCamelCase					,						self	).outputs
                if self.use_past:
                     __lowerCAmelCase			, __lowerCAmelCase								=					self.num_layers
                     for i in range(__UpperCamelCase	):
                          __lowerCAmelCase								=					{0: "batch", 2: "past_sequence + sequence"}
                          __lowerCAmelCase								=					{0: "batch", 2: "past_sequence + sequence"}
           return common_outputs


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = -1					,						__UpperCamelCase = -1					,						__UpperCamelCase = False					,						__UpperCamelCase = None					,						)->	Mapping[str, Any]:
           __lowerCAmelCase								=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               __UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)

           # Generate decoder inputs
           __lowerCAmelCase								=					seq_length if not self.use_past else 1
           __lowerCAmelCase								=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               __UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)
           __lowerCAmelCase								=					{F"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
           __lowerCAmelCase								=					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								=					common_inputs["input_ids"].shape
                __lowerCAmelCase								=					common_inputs["decoder_input_ids"].shape[1]
                __lowerCAmelCase			, __lowerCAmelCase								=					self.num_attention_heads
                __lowerCAmelCase								=					(
                    batch,
                    num_encoder_attention_heads,
                    encoder_seq_length,
                    self._config.hidden_size // num_encoder_attention_heads,
                )
                __lowerCAmelCase								=					decoder_seq_length + 3
                __lowerCAmelCase								=					(
                    batch,
                    num_decoder_attention_heads,
                    decoder_past_length,
                    self._config.hidden_size // num_decoder_attention_heads,
                )

                __lowerCAmelCase								=					torch.cat(
                    [common_inputs["decoder_attention_mask"], torch.ones(__UpperCamelCase					,						__UpperCamelCase	)]					,						dim=1	)

                __lowerCAmelCase								=					[]
                # If the number of encoder and decoder layers are present in the model configuration, both are considered
                __lowerCAmelCase			, __lowerCAmelCase								=					self.num_layers
                __lowerCAmelCase								=					min(__UpperCamelCase					,						__UpperCamelCase	)
                __lowerCAmelCase								=					max(__UpperCamelCase					,						__UpperCamelCase	) - min_num_layers
                __lowerCAmelCase								=					"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								=					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  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = -1					,						__UpperCamelCase = -1					,						__UpperCamelCase = False					,						__UpperCamelCase = None					,						)->	Mapping[str, Any]:
           __lowerCAmelCase								=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               __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								=					common_inputs["input_ids"].shape
                # Not using the same length for past_key_values
                __lowerCAmelCase								=					seqlen + 2
                __lowerCAmelCase			, __lowerCAmelCase								=					self.num_layers
                __lowerCAmelCase			, __lowerCAmelCase								=					self.num_attention_heads
                __lowerCAmelCase								=					(
                    batch,
                    num_encoder_attention_heads,
                    past_key_values_length,
                    self._config.hidden_size // num_encoder_attention_heads,
                )

                __lowerCAmelCase								=					common_inputs["attention_mask"].dtype
                __lowerCAmelCase								=					torch.cat(
                    [common_inputs["attention_mask"], torch.ones(__UpperCamelCase					,						__UpperCamelCase					,						dtype=__UpperCamelCase	)]					,						dim=1	)
                __lowerCAmelCase								=					[
                    (torch.zeros(__UpperCamelCase	), torch.zeros(__UpperCamelCase	)) for _ in range(__UpperCamelCase	)
                ]
           return common_inputs


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = -1					,						__UpperCamelCase = -1					,						__UpperCamelCase = False					,						__UpperCamelCase = None					,						)->	Mapping[str, Any]:
           # 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								=					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								=					tokenizer.num_special_tokens_to_add(__UpperCamelCase	)
           __lowerCAmelCase								=					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								=					[" ".join([tokenizer.unk_token]	) * seq_length] * batch_size
           __lowerCAmelCase								=					dict(tokenizer(__UpperCamelCase					,						return_tensors=__UpperCamelCase	)	)
           return common_inputs


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase = -1					,						__UpperCamelCase = -1					,						__UpperCamelCase = False					,						__UpperCamelCase = None					,						)->	Mapping[str, Any]:
           if self.task in ["default", "seq2seq-lm"]:
                __lowerCAmelCase								=					self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                    __UpperCamelCase					,						batch_size=__UpperCamelCase					,						seq_length=__UpperCamelCase					,						is_pair=__UpperCamelCase					,						framework=__UpperCamelCase	)

           elif self.task == "causal-lm":
                __lowerCAmelCase								=					self._generate_dummy_inputs_for_causal_lm(
                    __UpperCamelCase					,						batch_size=__UpperCamelCase					,						seq_length=__UpperCamelCase					,						is_pair=__UpperCamelCase					,						framework=__UpperCamelCase	)
           else:
                __lowerCAmelCase								=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                    __UpperCamelCase					,						batch_size=__UpperCamelCase					,						seq_length=__UpperCamelCase					,						is_pair=__UpperCamelCase					,						framework=__UpperCamelCase	)

           return common_inputs


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	List[Any]:
           if self.task in ["default", "seq2seq-lm"]:
                __lowerCAmelCase								=					super()._flatten_past_key_values_(__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)
           else:
                __lowerCAmelCase								=					super(__UpperCamelCase					,						self	)._flatten_past_key_values_(
                    __UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)






