






'''simple docstring'''







import gc
import random
import unittest

import numpy as np
import torch
from transformers import XLMRobertaTokenizer

from diffusers import (
    AltDiffusionImgaImgPipeline,
    AutoencoderKL,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.image_processor import VaeImageProcessor
from diffusers.pipelines.alt_diffusion.modeling_roberta_series import (
    RobertaSeriesConfig,
    RobertaSeriesModelWithTransformation,
)
from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()

class _lowercase     (    unittest.TestCase		):




       def 		lowerCamelCase_    (							self:    List[Any]					):
              # clean up the VRAM after each test
              super().tearDown()
              gc.collect()
              torch.cuda.empty_cache()




       @property
       def 		lowerCamelCase_    (							self:    Optional[int]					):
              lowerCamelCase__ :     List[Any]	  =	1
              lowerCamelCase__ :     Any	  =	3
              lowerCamelCase__ :     List[str]	  =	(32, 32)

              lowerCamelCase__ :     Tuple	  =	floats_tensor((batch_size, num_channels) + sizes      ,							rng=random.Random(0					)					).to(UpperCamelCase__					)
              return image




       @property
       def 		lowerCamelCase_    (							self:    Dict					):
              torch.manual_seed(0					)
              lowerCamelCase__ :     Dict	  =	UNetaDConditionModel(
                  block_out_channels=(32, 64)      ,							layers_per_block=2      ,							sample_size=32      ,							in_channels=4      ,							out_channels=4      ,							down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""")      ,							up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""")      ,							cross_attention_dim=32      ,							)
              return model




       @property
       def 		lowerCamelCase_    (							self:    Union[str, Any]					):
              torch.manual_seed(0					)
              lowerCamelCase__ :     Dict	  =	AutoencoderKL(
                  block_out_channels=[32, 64]      ,							in_channels=3      ,							out_channels=3      ,							down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]      ,							up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]      ,							latent_channels=4      ,							)
              return model




       @property
       def 		lowerCamelCase_    (							self:    Dict					):
              torch.manual_seed(0					)
              lowerCamelCase__ :     Union[str, Any]	  =	RobertaSeriesConfig(
                  hidden_size=32      ,							project_dim=32      ,							intermediate_size=37      ,							layer_norm_eps=1e-05      ,							num_attention_heads=4      ,							num_hidden_layers=5      ,							pad_token_id=1      ,							vocab_size=5_006      ,							)
              return RobertaSeriesModelWithTransformation(UpperCamelCase__					)




       @property
       def 		lowerCamelCase_    (							self:    Optional[Any]					):
              def extract(*UpperCamelCase__:    List[Any]      ,							**UpperCamelCase__:    int					):

                     class _lowercase     :




                            def __init__(							self:    int					):
                                   lowerCamelCase__ :     int	  =	torch.ones([0]					)




                            def 		lowerCamelCase_    (							self:    str      ,							UpperCamelCase__:    Union[str, Any]					):
                                   self.pixel_values.to(UpperCamelCase__					)
                                   return self



                     return Out()

              return extract




       def 		lowerCamelCase_    (							self:    Dict					):
              lowerCamelCase__ :     Union[str, Any]	  =	"""cpu"""  # ensure determinism for the device-dependent torch.Generator
              lowerCamelCase__ :     Optional[int]	  =	self.dummy_cond_unet
              lowerCamelCase__ :     Any	  =	PNDMScheduler(skip_prk_steps=UpperCamelCase__					)
              lowerCamelCase__ :     str	  =	self.dummy_vae
              lowerCamelCase__ :     List[str]	  =	self.dummy_text_encoder
              lowerCamelCase__ :     Optional[int]	  =	XLMRobertaTokenizer.from_pretrained("""hf-internal-testing/tiny-xlm-roberta"""					)
              lowerCamelCase__ :     int	  =	77

              lowerCamelCase__ :     List[str]	  =	self.dummy_image.to(UpperCamelCase__					)
              lowerCamelCase__ :     Union[str, Any]	  =	init_image / 2 + 0.5

              # make sure here that pndm scheduler skips prk
              lowerCamelCase__ :     Any	  =	AltDiffusionImgaImgPipeline(
                  unet=UpperCamelCase__      ,							scheduler=UpperCamelCase__      ,							vae=UpperCamelCase__      ,							text_encoder=UpperCamelCase__      ,							tokenizer=UpperCamelCase__      ,							safety_checker=UpperCamelCase__      ,							feature_extractor=self.dummy_extractor      ,							)
              lowerCamelCase__ :     List[Any]	  =	VaeImageProcessor(vae_scale_factor=alt_pipe.vae_scale_factor      ,							do_normalize=UpperCamelCase__					)
              lowerCamelCase__ :     Optional[Any]	  =	alt_pipe.to(UpperCamelCase__					)
              alt_pipe.set_progress_bar_config(disable=UpperCamelCase__					)

              lowerCamelCase__ :     List[str]	  =	"""A painting of a squirrel eating a burger"""
              lowerCamelCase__ :     int	  =	torch.Generator(device=UpperCamelCase__					).manual_seed(0					)
              lowerCamelCase__ :     Optional[Any]	  =	alt_pipe(
                  [prompt]      ,							generator=UpperCamelCase__      ,							guidance_scale=6.0      ,							num_inference_steps=2      ,							output_type="""np"""      ,							image=UpperCamelCase__      ,							)

              lowerCamelCase__ :     Tuple	  =	output.images

              lowerCamelCase__ :     str	  =	torch.Generator(device=UpperCamelCase__					).manual_seed(0					)
              lowerCamelCase__ :     Tuple	  =	alt_pipe(
                  [prompt]      ,							generator=UpperCamelCase__      ,							guidance_scale=6.0      ,							num_inference_steps=2      ,							output_type="""np"""      ,							image=UpperCamelCase__      ,							return_dict=UpperCamelCase__      ,							)[0]

              lowerCamelCase__ :     Dict	  =	image[0, -3:, -3:, -1]
              lowerCamelCase__ :     List[str]	  =	image_from_tuple[0, -3:, -3:, -1]

              assert image.shape == (1, 32, 32, 3)
              lowerCamelCase__ :     Optional[Any]	  =	np.array([0.4_427, 0.3_731, 0.4_249, 0.4_941, 0.4_546, 0.4_148, 0.4_193, 0.4_666, 0.4_499]					)

              assert np.abs(image_slice.flatten() - expected_slice					).max() < 5e-3
              assert np.abs(image_from_tuple_slice.flatten() - expected_slice					).max() < 5e-3




       @unittest.skipIf(torch_device != """cuda"""      ,							"""This test requires a GPU"""					)
       def 		lowerCamelCase_    (							self:    int					):
              lowerCamelCase__ :     Optional[Any]	  =	self.dummy_cond_unet
              lowerCamelCase__ :     Optional[Any]	  =	PNDMScheduler(skip_prk_steps=UpperCamelCase__					)
              lowerCamelCase__ :     Optional[Any]	  =	self.dummy_vae
              lowerCamelCase__ :     str	  =	self.dummy_text_encoder
              lowerCamelCase__ :     Dict	  =	XLMRobertaTokenizer.from_pretrained("""hf-internal-testing/tiny-xlm-roberta"""					)
              lowerCamelCase__ :     List[str]	  =	77

              lowerCamelCase__ :     Dict	  =	self.dummy_image.to(UpperCamelCase__					)

              # put models in fp16
              lowerCamelCase__ :     int	  =	unet.half()
              lowerCamelCase__ :     Tuple	  =	vae.half()
              lowerCamelCase__ :     Optional[int]	  =	bert.half()

              # make sure here that pndm scheduler skips prk
              lowerCamelCase__ :     str	  =	AltDiffusionImgaImgPipeline(
                  unet=UpperCamelCase__      ,							scheduler=UpperCamelCase__      ,							vae=UpperCamelCase__      ,							text_encoder=UpperCamelCase__      ,							tokenizer=UpperCamelCase__      ,							safety_checker=UpperCamelCase__      ,							feature_extractor=self.dummy_extractor      ,							)
              lowerCamelCase__ :     Union[str, Any]	  =	VaeImageProcessor(vae_scale_factor=alt_pipe.vae_scale_factor      ,							do_normalize=UpperCamelCase__					)
              lowerCamelCase__ :     Optional[int]	  =	alt_pipe.to(UpperCamelCase__					)
              alt_pipe.set_progress_bar_config(disable=UpperCamelCase__					)

              lowerCamelCase__ :     Union[str, Any]	  =	"""A painting of a squirrel eating a burger"""
              lowerCamelCase__ :     Tuple	  =	torch.manual_seed(0					)
              lowerCamelCase__ :     List[str]	  =	alt_pipe(
                  [prompt]      ,							generator=UpperCamelCase__      ,							num_inference_steps=2      ,							output_type="""np"""      ,							image=UpperCamelCase__      ,							).images

              assert image.shape == (1, 32, 32, 3)




       @unittest.skipIf(torch_device != """cuda"""      ,							"""This test requires a GPU"""					)
       def 		lowerCamelCase_    (							self:    Tuple					):
              lowerCamelCase__ :     Tuple	  =	load_image(
                  """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
                  """/img2img/sketch-mountains-input.jpg"""					)
              # resize to resolution that is divisible by 8 but not 16 or 32
              lowerCamelCase__ :     int	  =	init_image.resize((760, 504)					)

              lowerCamelCase__ :     Optional[Any]	  =	"""BAAI/AltDiffusion"""
              lowerCamelCase__ :     str	  =	AltDiffusionImgaImgPipeline.from_pretrained(
                  UpperCamelCase__      ,							safety_checker=UpperCamelCase__      ,							)
              pipe.to(UpperCamelCase__					)
              pipe.set_progress_bar_config(disable=UpperCamelCase__					)
              pipe.enable_attention_slicing()

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

              lowerCamelCase__ :     Dict	  =	torch.manual_seed(0					)
              lowerCamelCase__ :     Any	  =	pipe(
                  prompt=UpperCamelCase__      ,							image=UpperCamelCase__      ,							strength=0.75      ,							guidance_scale=7.5      ,							generator=UpperCamelCase__      ,							output_type="""np"""      ,							)
              lowerCamelCase__ :     Optional[int]	  =	output.images[0]

              lowerCamelCase__ :     List[str]	  =	image[255:258, 383:386, -1]

              assert image.shape == (504, 760, 3)
              lowerCamelCase__ :     Any	  =	np.array([0.9_358, 0.9_397, 0.9_599, 0.9_901, 1.0_000, 1.0_000, 0.9_882, 1.0_000, 1.0_000]					)

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



@slow
@require_torch_gpu
class _lowercase     (    unittest.TestCase		):




       def 		lowerCamelCase_    (							self:    List[str]					):
              # clean up the VRAM after each test
              super().tearDown()
              gc.collect()
              torch.cuda.empty_cache()




       def 		lowerCamelCase_    (							self:    int					):
              lowerCamelCase__ :     List[Any]	  =	load_image(
                  """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
                  """/img2img/sketch-mountains-input.jpg"""					)
              lowerCamelCase__ :     str	  =	init_image.resize((768, 512)					)
              lowerCamelCase__ :     Any	  =	load_numpy(
                  """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/img2img/fantasy_landscape_alt.npy"""					)

              lowerCamelCase__ :     Dict	  =	"""BAAI/AltDiffusion"""
              lowerCamelCase__ :     List[str]	  =	AltDiffusionImgaImgPipeline.from_pretrained(
                  UpperCamelCase__      ,							safety_checker=UpperCamelCase__      ,							)
              pipe.to(UpperCamelCase__					)
              pipe.set_progress_bar_config(disable=UpperCamelCase__					)
              pipe.enable_attention_slicing()

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

              lowerCamelCase__ :     List[Any]	  =	torch.manual_seed(0					)
              lowerCamelCase__ :     Tuple	  =	pipe(
                  prompt=UpperCamelCase__      ,							image=UpperCamelCase__      ,							strength=0.75      ,							guidance_scale=7.5      ,							generator=UpperCamelCase__      ,							output_type="""np"""      ,							)
              lowerCamelCase__ :     Union[str, Any]	  =	output.images[0]

              assert image.shape == (512, 768, 3)
              # img2img is flaky across GPUs even in fp32, so using MAE here
              assert np.abs(expected_image - image					).max() < 1e-2









'''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

