


'''simple docstring'''





import random
import unittest

import numpy as np
import torch

from diffusers import (
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionUpscalePipeline,
    PNDMScheduler,
)
from diffusers.utils import floats_tensor
from diffusers.utils.testing_utils import (
    is_onnx_available,
    load_image,
    nightly,
    require_onnxruntime,
    require_torch_gpu,
)

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
    import onnxruntime as ort







class     _lowercase				(							lowercase__							,						unittest.TestCase):


       """simple docstring"""




       A__      		=    "ssube/stable-diffusion-x4-upscaler-onnx"





       def 		lowerCAmelCase  (     self							:    List[str]      ,   __lowerCamelCase							:    Dict=0 ):


             '''simple docstring'''



             lowerCamelCase__	:       Union[str, Any]					=						floats_tensor((1, 3, 128, 128)      ,   rng=random.Random(__lowerCamelCase ) )
             lowerCamelCase__	:       str					=						torch.manual_seed(__lowerCamelCase )
             lowerCamelCase__	:       str					=						{
                 "prompt": "A painting of a squirrel eating a burger",
                 "image": image,
                 "generator": generator,
                 "num_inference_steps": 3,
                 "guidance_scale": 7.5,
                 "output_type": "numpy",
             }
             return inputs





       def 		lowerCAmelCase  (     self							:    Optional[Any] ):


             '''simple docstring'''



             lowerCamelCase__	:       int					=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,   provider="CPUExecutionProvider" )
             pipe.set_progress_bar_config(disable=__lowerCamelCase )

             lowerCamelCase__	:       List[Any]					=						self.get_dummy_inputs()
             lowerCamelCase__	:       List[Any]					=						pipe(**__lowerCamelCase ).images
             lowerCamelCase__	:       Any					=						image[0, -3:, -3:, -1].flatten()

             # started as 128, should now be 512
             assert image.shape == (1, 512, 512, 3)
             lowerCamelCase__	:       str					=						np.array(
                 [0.6_9_7_4_7_8_2, 0.6_8_9_0_2_0_9_3, 0.7_0_1_3_5_8_8_5, 0.7_5_8_3_6_1_8, 0.7_8_0_4_5_4_5, 0.7_8_5_4_9_1_2, 0.7_8_6_6_7_4_2_6, 0.7_8_7_4_3_8_6_3, 0.7_8_0_7_0_2_2_3] )
             assert np.abs(image_slice - expected_slice ).max() < 1E-1





       def 		lowerCAmelCase  (     self							:    Tuple ):


             '''simple docstring'''



             lowerCamelCase__	:       Tuple					=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,   provider="CPUExecutionProvider" )
             lowerCamelCase__	:       Dict					=						PNDMScheduler.from_config(pipe.scheduler.config      ,   skip_prk_steps=__lowerCamelCase )
             pipe.set_progress_bar_config(disable=__lowerCamelCase )

             lowerCamelCase__	:       int					=						self.get_dummy_inputs()
             lowerCamelCase__	:       Tuple					=						pipe(**__lowerCamelCase ).images
             lowerCamelCase__	:       List[Any]					=						image[0, -3:, -3:, -1]

             assert image.shape == (1, 512, 512, 3)
             lowerCamelCase__	:       Dict					=						np.array(
                 [0.6_8_9_8_8_9_2, 0.5_9_2_4_0_5_5_6, 0.5_2_4_9_9_5_2_7, 0.5_8_8_6_6_2_1_5, 0.5_2_2_5_8_2_3_5, 0.5_2_5_7_2_7_1_5, 0.6_2_4_1_4_4_7_3, 0.6_1_7_4_3_8_7, 0.6_2_1_4_9_6_4] )
             assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-1





       def 		lowerCAmelCase  (     self							:    int ):


             '''simple docstring'''



             lowerCamelCase__	:       Any					=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,   provider="CPUExecutionProvider" )
             lowerCamelCase__	:       Any					=						DPMSolverMultistepScheduler.from_config(pipe.scheduler.config )
             pipe.set_progress_bar_config(disable=__lowerCamelCase )

             lowerCamelCase__	:       Tuple					=						self.get_dummy_inputs()
             lowerCamelCase__	:       Dict					=						pipe(**__lowerCamelCase ).images
             lowerCamelCase__	:       List[str]					=						image[0, -3:, -3:, -1]

             assert image.shape == (1, 512, 512, 3)
             lowerCamelCase__	:       List[Any]					=						np.array(
                 [0.7_6_5_9_2_7_8, 0.7_6_4_3_7_6_6_4, 0.7_5_5_7_9_1_0_7, 0.7_6_9_1_1_1_6, 0.7_7_6_6_6_9_8_6, 0.7_7_2_7_6_7_2, 0.7_7_5_8_6_6_4, 0.7_8_1_2_2_2_6, 0.7_6_9_4_2_5_1_5] )

             assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-1





       def 		lowerCAmelCase  (     self							:    List[Any] ):


             '''simple docstring'''



             lowerCamelCase__	:       int					=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,   provider="CPUExecutionProvider" )
             lowerCamelCase__	:       Optional[Any]					=						EulerDiscreteScheduler.from_config(pipe.scheduler.config )
             pipe.set_progress_bar_config(disable=__lowerCamelCase )

             lowerCamelCase__	:       Any					=						self.get_dummy_inputs()
             lowerCamelCase__	:       Tuple					=						pipe(**__lowerCamelCase ).images
             lowerCamelCase__	:       str					=						image[0, -3:, -3:, -1]

             assert image.shape == (1, 512, 512, 3)
             lowerCamelCase__	:       Optional[Any]					=						np.array(
                 [0.6_9_7_4_7_8_2, 0.6_8_9_0_2_0_9_3, 0.7_0_1_3_5_8_8_5, 0.7_5_8_3_6_1_8, 0.7_8_0_4_5_4_5, 0.7_8_5_4_9_1_2, 0.7_8_6_6_7_4_2_6, 0.7_8_7_4_3_8_6_3, 0.7_8_0_7_0_2_2_3] )
             assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-1





       def 		lowerCAmelCase  (     self							:    int ):


             '''simple docstring'''



             lowerCamelCase__	:       int					=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,   provider="CPUExecutionProvider" )
             lowerCamelCase__	:       Optional[int]					=						EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config )
             pipe.set_progress_bar_config(disable=__lowerCamelCase )

             lowerCamelCase__	:       str					=						self.get_dummy_inputs()
             lowerCamelCase__	:       Dict					=						pipe(**__lowerCamelCase ).images
             lowerCamelCase__	:       Dict					=						image[0, -3:, -3:, -1]

             assert image.shape == (1, 512, 512, 3)
             lowerCamelCase__	:       Optional[int]					=						np.array(
                 [0.7_7_4_2_4_4_9_6, 0.7_7_3_6_0_1, 0.7_6_4_5_2_8_8, 0.7_7_6_9_5_9_8, 0.7_7_7_2_7_3_9, 0.7_7_3_8_6_8_8, 0.7_8_1_8_7_2_3_3, 0.7_7_8_7_9_5_8_4, 0.7_6_7_0_4_3] )

             assert np.abs(image_slice.flatten() - expected_slice ).max() < 1E-1







@nightly
@require_onnxruntime
@require_torch_gpu
class     _lowercase				(							unittest.TestCase):


       """simple docstring"""




       @property
       def 		lowerCAmelCase  (     self							:    Optional[Any] ):


             '''simple docstring'''



             return (
                 "CUDAExecutionProvider",
                 {
                     "gpu_mem_limit": "15000000000",  # 15GB
                     "arena_extend_strategy": "kSameAsRequested",
                 },
             )





       @property
       def 		lowerCAmelCase  (     self							:    Optional[int] ):


             '''simple docstring'''



             lowerCamelCase__	:       Any					=						ort.SessionOptions()
             lowerCamelCase__	:       List[Any]					=						False
             return options





       def 		lowerCAmelCase  (     self							:    str ):


             '''simple docstring'''



             lowerCamelCase__	:       Optional[int]					=						load_image(
                 "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
                 "/img2img/sketch-mountains-input.jpg" )
             lowerCamelCase__	:       List[str]					=						init_image.resize((128, 128) )
             # using the PNDM scheduler by default
             lowerCamelCase__	:       List[Any]					=						OnnxStableDiffusionUpscalePipeline.from_pretrained(
                 "ssube/stable-diffusion-x4-upscaler-onnx"      ,   provider=self.gpu_provider      ,   sess_options=self.gpu_options      ,   )
             pipe.set_progress_bar_config(disable=__lowerCamelCase )

             lowerCamelCase__	:       List[str]					=						"A fantasy landscape, trending on artstation"

             lowerCamelCase__	:       Any					=						torch.manual_seed(0 )
             lowerCamelCase__	:       Union[str, Any]					=						pipe(
                 prompt=__lowerCamelCase      ,   image=__lowerCamelCase      ,   guidance_scale=7.5      ,   num_inference_steps=10      ,   generator=__lowerCamelCase      ,   output_type="np"      ,   )
             lowerCamelCase__	:       List[Any]					=						output.images
             lowerCamelCase__	:       Optional[int]					=						images[0, 255:258, 383:386, -1]

             assert images.shape == (1, 512, 512, 3)
             lowerCamelCase__	:       Optional[int]					=						np.array([0.4_8_8_3, 0.4_9_4_7, 0.4_9_8_0, 0.4_9_7_5, 0.4_9_8_2, 0.4_9_8_0, 0.5_0_0_0, 0.5_0_0_6, 0.4_9_7_2] )
             # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

             assert np.abs(image_slice.flatten() - expected_slice ).max() < 2E-2





       def 		lowerCAmelCase  (     self							:    Dict ):


             '''simple docstring'''



             lowerCamelCase__	:       List[Any]					=						load_image(
                 "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
                 "/img2img/sketch-mountains-input.jpg" )
             lowerCamelCase__	:       Tuple					=						init_image.resize((128, 128) )
             lowerCamelCase__	:       str					=						LMSDiscreteScheduler.from_pretrained(
                 "ssube/stable-diffusion-x4-upscaler-onnx"      ,   subfolder="scheduler" )
             lowerCamelCase__	:       Optional[int]					=						OnnxStableDiffusionUpscalePipeline.from_pretrained(
                 "ssube/stable-diffusion-x4-upscaler-onnx"      ,   scheduler=__lowerCamelCase      ,   provider=self.gpu_provider      ,   sess_options=self.gpu_options      ,   )
             pipe.set_progress_bar_config(disable=__lowerCamelCase )

             lowerCamelCase__	:       Optional[int]					=						"A fantasy landscape, trending on artstation"

             lowerCamelCase__	:       Union[str, Any]					=						torch.manual_seed(0 )
             lowerCamelCase__	:       List[str]					=						pipe(
                 prompt=__lowerCamelCase      ,   image=__lowerCamelCase      ,   guidance_scale=7.5      ,   num_inference_steps=20      ,   generator=__lowerCamelCase      ,   output_type="np"      ,   )
             lowerCamelCase__	:       Optional[Any]					=						output.images
             lowerCamelCase__	:       Optional[int]					=						images[0, 255:258, 383:386, -1]

             assert images.shape == (1, 512, 512, 3)
             lowerCamelCase__	:       str					=						np.array(
                 [0.5_0_1_7_3_7_5_3, 0.5_0_2_2_3_3_5_6, 0.5_0_2_0_3_9, 0.5_0_2_3_3_0_3_6, 0.5_0_2_3_7_2_5, 0.5_0_2_2_6_0_1, 0.5_0_1_8_7_5_8, 0.5_0_2_3_4_0_8_5, 0.5_0_2_4_1_5_6_6] )
             # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

             assert np.abs(image_slice.flatten() - expected_slice ).max() < 2E-2






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


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

A   :					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     _lowercase				(							lowercase__):


       """simple docstring"""




       A__      		=    "blenderbot-small"
       A__      		=    ["past_key_values"]
       A__      		=    {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}





       def __init__(     self							:    Dict      ,   __lowerCamelCase							:    List[str]=50265      ,   __lowerCamelCase							:    str=512      ,   __lowerCamelCase							:    Tuple=8      ,   __lowerCamelCase							:    str=2048      ,   __lowerCamelCase							:    str=16      ,   __lowerCamelCase							:    List[Any]=8      ,   __lowerCamelCase							:    Any=2048      ,   __lowerCamelCase							:    List[str]=16      ,   __lowerCamelCase							:    Dict=0.0      ,   __lowerCamelCase							:    List[Any]=0.0      ,   __lowerCamelCase							:    Optional[int]=True      ,   __lowerCamelCase							:    Union[str, Any]=True      ,   __lowerCamelCase							:    Tuple="gelu"      ,   __lowerCamelCase							:    Tuple=512      ,   __lowerCamelCase							:    Dict=0.1      ,   __lowerCamelCase							:    int=0.0      ,   __lowerCamelCase							:    Union[str, Any]=0.0      ,   __lowerCamelCase							:    Any=0.0_2      ,   __lowerCamelCase							:    str=1      ,   __lowerCamelCase							:    Dict=False      ,   __lowerCamelCase							:    int=0      ,   __lowerCamelCase							:    Optional[Any]=1      ,   __lowerCamelCase							:    str=2      ,   __lowerCamelCase							:    Any=2      ,   **__lowerCamelCase							:    int      ,   ):


             '''simple docstring'''



             lowerCamelCase__	:       str					=						vocab_size
             lowerCamelCase__	:       Union[str, Any]					=						max_position_embeddings
             lowerCamelCase__	:       Union[str, Any]					=						d_model
             lowerCamelCase__	:       Optional[int]					=						encoder_ffn_dim
             lowerCamelCase__	:       Dict					=						encoder_layers
             lowerCamelCase__	:       Any					=						encoder_attention_heads
             lowerCamelCase__	:       Union[str, Any]					=						decoder_ffn_dim
             lowerCamelCase__	:       str					=						decoder_layers
             lowerCamelCase__	:       Optional[Any]					=						decoder_attention_heads
             lowerCamelCase__	:       List[str]					=						dropout
             lowerCamelCase__	:       List[Any]					=						attention_dropout
             lowerCamelCase__	:       Dict					=						activation_dropout
             lowerCamelCase__	:       Optional[Any]					=						activation_function
             lowerCamelCase__	:       Dict					=						init_std
             lowerCamelCase__	:       List[str]					=						encoder_layerdrop
             lowerCamelCase__	:       Dict					=						decoder_layerdrop
             lowerCamelCase__	:       int					=						use_cache
             lowerCamelCase__	:       List[Any]					=						encoder_layers
             lowerCamelCase__	:       Tuple					=						scale_embedding  # scale factor will be sqrt(d_model) if True

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







class     _lowercase				(							lowercase__):


       """simple docstring"""




       @property
       def 		lowerCAmelCase  (     self							:    List[str] ):


             '''simple docstring'''



             if self.task in ["default", "seq2seq-lm"]:
                   lowerCamelCase__	:       int					=						OrderedDict(
                       [
                           ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                           ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
                       ] )

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

                   if self.use_past:
                         self.fill_with_past_key_values_(__lowerCamelCase      ,   direction="inputs" )
             elif self.task == "causal-lm":
                   # TODO: figure this case out.
                   lowerCamelCase__	:       Tuple					=						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(__lowerCamelCase ):
                               lowerCamelCase__	:       Union[str, Any]					=						{0: "batch", 2: "past_sequence + sequence"}
                               lowerCamelCase__	:       Optional[int]					=						{0: "batch", 2: "past_sequence + sequence"}
             else:
                   lowerCamelCase__	:       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 		lowerCAmelCase  (     self							:    Optional[int] ):


             '''simple docstring'''



             if self.task in ["default", "seq2seq-lm"]:
                   lowerCamelCase__	:       Union[str, Any]					=						super().outputs
             else:
                   lowerCamelCase__	:       int					=						super(__lowerCamelCase      ,   self ).outputs
                   if self.use_past:
                         lowerCamelCase__					,     lowerCamelCase__	:       Tuple					=						self.num_layers
                         for i in range(__lowerCamelCase ):
                               lowerCamelCase__	:       Tuple					=						{0: "batch", 2: "past_sequence + sequence"}
                               lowerCamelCase__	:       Any					=						{0: "batch", 2: "past_sequence + sequence"}
             return common_outputs





       def 		lowerCAmelCase  (     self							:    int      ,   __lowerCamelCase							:    PreTrainedTokenizer      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    bool = False      ,   __lowerCamelCase							:    Optional[TensorType] = None      ,   ):


             '''simple docstring'''



             lowerCamelCase__	:       Union[str, Any]					=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )

             # Generate decoder inputs
             lowerCamelCase__	:       List[str]					=						seq_length if not self.use_past else 1
             lowerCamelCase__	:       List[Any]					=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )
             lowerCamelCase__	:       Optional[Any]					=						{f"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
             lowerCamelCase__	:       Optional[Any]					=						dict(**__lowerCamelCase      ,   **__lowerCamelCase )

             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__	:       Tuple					=						common_inputs["input_ids"].shape
                   lowerCamelCase__	:       int					=						common_inputs["decoder_input_ids"].shape[1]
                   lowerCamelCase__					,     lowerCamelCase__	:       Optional[Any]					=						self.num_attention_heads
                   lowerCamelCase__	:       str					=						(
                       batch,
                       num_encoder_attention_heads,
                       encoder_seq_length,
                       self._config.hidden_size // num_encoder_attention_heads,
                   )
                   lowerCamelCase__	:       Optional[int]					=						decoder_seq_length + 3
                   lowerCamelCase__	:       Dict					=						(
                       batch,
                       num_decoder_attention_heads,
                       decoder_past_length,
                       self._config.hidden_size // num_decoder_attention_heads,
                   )

                   lowerCamelCase__	:       List[Any]					=						torch.cat(
                       [common_inputs["decoder_attention_mask"], torch.ones(__lowerCamelCase      ,   __lowerCamelCase )]      ,   dim=1 )

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

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





       def 		lowerCAmelCase  (     self							:    Tuple      ,   __lowerCamelCase							:    PreTrainedTokenizer      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    bool = False      ,   __lowerCamelCase							:    Optional[TensorType] = None      ,   ):


             '''simple docstring'''



             lowerCamelCase__	:       str					=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )

             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__	:       int					=						common_inputs["input_ids"].shape
                   # Not using the same length for past_key_values
                   lowerCamelCase__	:       str					=						seqlen + 2
                   lowerCamelCase__					,     lowerCamelCase__	:       Optional[int]					=						self.num_layers
                   lowerCamelCase__					,     lowerCamelCase__	:       int					=						self.num_attention_heads
                   lowerCamelCase__	:       Tuple					=						(
                       batch,
                       num_encoder_attention_heads,
                       past_key_values_length,
                       self._config.hidden_size // num_encoder_attention_heads,
                   )

                   lowerCamelCase__	:       Union[str, Any]					=						common_inputs["attention_mask"].dtype
                   lowerCamelCase__	:       List[str]					=						torch.cat(
                       [common_inputs["attention_mask"], torch.ones(__lowerCamelCase      ,   __lowerCamelCase      ,   dtype=__lowerCamelCase )]      ,   dim=1 )
                   lowerCamelCase__	:       Tuple					=						[
                       (torch.zeros(__lowerCamelCase ), torch.zeros(__lowerCamelCase )) for _ in range(__lowerCamelCase )
                   ]
             return common_inputs





       def 		lowerCAmelCase  (     self							:    Union[str, Any]      ,   __lowerCamelCase							:    PreTrainedTokenizer      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    bool = False      ,   __lowerCamelCase							:    Optional[TensorType] = None      ,   ):


             '''simple docstring'''



             lowerCamelCase__	:       str					=						compute_effective_axis_dimension(
                 __lowerCamelCase      ,   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__	:       List[str]					=						tokenizer.num_special_tokens_to_add(__lowerCamelCase )
             lowerCamelCase__	:       Dict					=						compute_effective_axis_dimension(
                 __lowerCamelCase      ,   fixed_dimension=OnnxConfig.default_fixed_sequence      ,   num_token_to_add=__lowerCamelCase )

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





       def 		lowerCAmelCase  (     self							:    Any      ,   __lowerCamelCase							:    PreTrainedTokenizer      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    bool = False      ,   __lowerCamelCase							:    Optional[TensorType] = None      ,   ):


             '''simple docstring'''



             if self.task in ["default", "seq2seq-lm"]:
                   lowerCamelCase__	:       Optional[int]					=						self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                       __lowerCamelCase      ,   batch_size=__lowerCamelCase      ,   seq_length=__lowerCamelCase      ,   is_pair=__lowerCamelCase      ,   framework=__lowerCamelCase )

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

             return common_inputs





       def 		lowerCAmelCase  (     self							:    Any      ,   __lowerCamelCase							:    Union[str, Any]      ,   __lowerCamelCase							:    int      ,   __lowerCamelCase							:    Optional[Any]      ,   __lowerCamelCase							:    str ):


             '''simple docstring'''



             if self.task in ["default", "seq2seq-lm"]:
                   lowerCamelCase__	:       Dict					=						super()._flatten_past_key_values_(__lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )
             else:
                   lowerCamelCase__	:       int					=						super(__lowerCamelCase      ,   self )._flatten_past_key_values_(
                       __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )


