import tempfile
import unittest

import numpy as np

from diffusers import (
    DDIMScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionPipeline,
    PNDMScheduler,
)
from diffusers.utils.testing_utils import is_onnx_available, nightly, require_onnxruntime, require_torch_gpu

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
						import onnxruntime as ort



class __A     (      __snake_case		,unittest.TestCase						):

							'''simple docstring'''

							a_     =					'''hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline'''






							def 	SCREAMING_SNAKE_CASE__			(				self   ,	_snake_case=0 ):
												_lowerCAmelCase			:		Dict          = np.random.RandomState(__UpperCamelCase )
												_lowerCAmelCase			:		List[Any]          = {
												    "prompt": "A painting of a squirrel eating a burger",
												    "generator": generator,
												    "num_inference_steps": 2,
												    "guidance_scale": 7.5,
												    "output_type": "numpy",
												}
												return inputs






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Union[str, Any]          = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint   ,	provider="CPUExecutionProvider" )
												pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		str          = self.get_dummy_inputs()
												_lowerCAmelCase			:		List[str]          = pipe(**__UpperCamelCase ).images
												_lowerCAmelCase			:		List[str]          = image[0, -3:, -3:, -1]

												assert image.shape == (1, 128, 128, 3)
												_lowerCAmelCase			:		Optional[int]          = np.array([0.6_5072, 0.5_8492, 0.4_8219, 0.5_5521, 0.5_3180, 0.5_5939, 0.5_0697, 0.3_9800, 0.4_6455] )

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






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Optional[Any]          = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint   ,	provider="CPUExecutionProvider" )
												_lowerCAmelCase			:		Dict          = PNDMScheduler.from_config(pipe.scheduler.config   ,	skip_prk_steps=__UpperCamelCase )
												pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		str          = self.get_dummy_inputs()
												_lowerCAmelCase			:		Optional[Any]          = pipe(**__UpperCamelCase ).images
												_lowerCAmelCase			:		Any          = image[0, -3:, -3:, -1]

												assert image.shape == (1, 128, 128, 3)
												_lowerCAmelCase			:		Any          = np.array([0.6_5863, 0.5_9425, 0.4_9326, 0.5_6313, 0.5_3875, 0.5_6627, 0.5_1065, 0.3_9777, 0.4_6330] )

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






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Optional[Any]          = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint   ,	provider="CPUExecutionProvider" )
												_lowerCAmelCase			:		Optional[int]          = LMSDiscreteScheduler.from_config(pipe.scheduler.config )
												pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		Any          = self.get_dummy_inputs()
												_lowerCAmelCase			:		Dict          = pipe(**__UpperCamelCase ).images
												_lowerCAmelCase			:		List[str]          = image[0, -3:, -3:, -1]

												assert image.shape == (1, 128, 128, 3)
												_lowerCAmelCase			:		List[Any]          = np.array([0.5_3755, 0.6_0786, 0.4_7402, 0.4_9488, 0.5_1869, 0.4_9819, 0.4_7985, 0.3_8957, 0.4_4279] )

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






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Dict          = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint   ,	provider="CPUExecutionProvider" )
												_lowerCAmelCase			:		Union[str, Any]          = EulerDiscreteScheduler.from_config(pipe.scheduler.config )
												pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		Any          = self.get_dummy_inputs()
												_lowerCAmelCase			:		List[str]          = pipe(**__UpperCamelCase ).images
												_lowerCAmelCase			:		Union[str, Any]          = image[0, -3:, -3:, -1]

												assert image.shape == (1, 128, 128, 3)
												_lowerCAmelCase			:		Optional[int]          = np.array([0.5_3755, 0.6_0786, 0.4_7402, 0.4_9488, 0.5_1869, 0.4_9819, 0.4_7985, 0.3_8957, 0.4_4279] )

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






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		int          = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint   ,	provider="CPUExecutionProvider" )
												_lowerCAmelCase			:		Any          = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config )
												pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		Dict          = self.get_dummy_inputs()
												_lowerCAmelCase			:		int          = pipe(**__UpperCamelCase ).images
												_lowerCAmelCase			:		Optional[Any]          = image[0, -3:, -3:, -1]

												assert image.shape == (1, 128, 128, 3)
												_lowerCAmelCase			:		List[str]          = np.array([0.5_3817, 0.6_0812, 0.4_7384, 0.4_9530, 0.5_1894, 0.4_9814, 0.4_7984, 0.3_8958, 0.4_4271] )

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






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Any          = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint   ,	provider="CPUExecutionProvider" )
												_lowerCAmelCase			:		List[Any]          = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config )
												pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		Any          = self.get_dummy_inputs()
												_lowerCAmelCase			:		Any          = pipe(**__UpperCamelCase ).images
												_lowerCAmelCase			:		Union[str, Any]          = image[0, -3:, -3:, -1]

												assert image.shape == (1, 128, 128, 3)
												_lowerCAmelCase			:		int          = np.array([0.5_3895, 0.6_0808, 0.4_7933, 0.4_9608, 0.5_1886, 0.4_9950, 0.4_8053, 0.3_8957, 0.4_4200] )

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






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		List[str]          = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint   ,	provider="CPUExecutionProvider" )
												pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		Tuple          = self.get_dummy_inputs()
												_lowerCAmelCase			:		Dict          = 3 * [inputs["prompt"]]

												# forward
												_lowerCAmelCase			:		Tuple          = pipe(**__UpperCamelCase )
												_lowerCAmelCase			:		int          = output.images[0, -3:, -3:, -1]

												_lowerCAmelCase			:		Tuple          = self.get_dummy_inputs()
												_lowerCAmelCase			:		List[str]          = 3 * [inputs.pop("prompt" )]

												_lowerCAmelCase			:		Tuple          = pipe.tokenizer(
												    __UpperCamelCase   ,	padding="max_length"   ,	max_length=pipe.tokenizer.model_max_length   ,	truncation=__UpperCamelCase   ,	return_tensors="np"   ,	)
												_lowerCAmelCase			:		int          = text_inputs["input_ids"]

												_lowerCAmelCase			:		int          = pipe.text_encoder(input_ids=text_inputs.astype(np.intaa ) )[0]

												_lowerCAmelCase			:		str          = prompt_embeds

												# forward
												_lowerCAmelCase			:		List[Any]          = pipe(**__UpperCamelCase )
												_lowerCAmelCase			:		Dict          = output.images[0, -3:, -3:, -1]

												assert np.abs(image_slice_a.flatten() - image_slice_a.flatten() ).max() < 1E-4






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Any          = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint   ,	provider="CPUExecutionProvider" )
												pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		List[Any]          = self.get_dummy_inputs()
												_lowerCAmelCase			:		List[str]          = 3 * ["this is a negative prompt"]
												_lowerCAmelCase			:		Optional[int]          = negative_prompt
												_lowerCAmelCase			:		Optional[Any]          = 3 * [inputs["prompt"]]

												# forward
												_lowerCAmelCase			:		List[str]          = pipe(**__UpperCamelCase )
												_lowerCAmelCase			:		List[str]          = output.images[0, -3:, -3:, -1]

												_lowerCAmelCase			:		Any          = self.get_dummy_inputs()
												_lowerCAmelCase			:		Optional[int]          = 3 * [inputs.pop("prompt" )]

												_lowerCAmelCase			:		str          = []
												for p in [prompt, negative_prompt]:
																	_lowerCAmelCase			:		Optional[Any]          = pipe.tokenizer(
																	    __UpperCamelCase   ,	padding="max_length"   ,	max_length=pipe.tokenizer.model_max_length   ,	truncation=__UpperCamelCase   ,	return_tensors="np"   ,	)
																	_lowerCAmelCase			:		Union[str, Any]          = text_inputs["input_ids"]

																	embeds.append(pipe.text_encoder(input_ids=text_inputs.astype(np.intaa ) )[0] )

												_lowerCAmelCase      ,	_lowerCAmelCase			:		Union[str, Any]          = embeds

												# forward
												_lowerCAmelCase			:		Tuple          = pipe(**__UpperCamelCase )
												_lowerCAmelCase			:		Tuple          = output.images[0, -3:, -3:, -1]

												assert np.abs(image_slice_a.flatten() - image_slice_a.flatten() ).max() < 1E-4



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

							'''simple docstring'''

							@property
							def 	SCREAMING_SNAKE_CASE__			(				self ):
												return (
												    "CUDAExecutionProvider",
												    {
												        "gpu_mem_limit": "15000000000",  # 15GB
												        "arena_extend_strategy": "kSameAsRequested",
												    },
												)






							@property
							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Tuple          = ort.SessionOptions()
												_lowerCAmelCase			:		Any          = False
												return options






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Tuple          = OnnxStableDiffusionPipeline.from_pretrained(
												    "CompVis/stable-diffusion-v1-4"   ,	revision="onnx"   ,	safety_checker=__UpperCamelCase   ,	feature_extractor=__UpperCamelCase   ,	provider=self.gpu_provider   ,	sess_options=self.gpu_options   ,	)
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		List[str]          = "A painting of a squirrel eating a burger"
												np.random.seed(0 )
												_lowerCAmelCase			:		Dict          = sd_pipe([prompt]   ,	guidance_scale=6.0   ,	num_inference_steps=10   ,	output_type="np" )
												_lowerCAmelCase			:		Any          = output.images

												_lowerCAmelCase			:		List[str]          = image[0, -3:, -3:, -1]

												assert image.shape == (1, 512, 512, 3)
												_lowerCAmelCase			:		Dict          = np.array([0.0452, 0.0390, 0.0087, 0.0350, 0.0617, 0.0364, 0.0544, 0.0523, 0.0720] )

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






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Union[str, Any]          = DDIMScheduler.from_pretrained(
												    "runwayml/stable-diffusion-v1-5"   ,	subfolder="scheduler"   ,	revision="onnx" )
												_lowerCAmelCase			:		Optional[Any]          = OnnxStableDiffusionPipeline.from_pretrained(
												    "runwayml/stable-diffusion-v1-5"   ,	revision="onnx"   ,	scheduler=__UpperCamelCase   ,	safety_checker=__UpperCamelCase   ,	feature_extractor=__UpperCamelCase   ,	provider=self.gpu_provider   ,	sess_options=self.gpu_options   ,	)
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		Union[str, Any]          = "open neural network exchange"
												_lowerCAmelCase			:		List[str]          = np.random.RandomState(0 )
												_lowerCAmelCase			:		Any          = sd_pipe([prompt]   ,	guidance_scale=7.5   ,	num_inference_steps=10   ,	generator=__UpperCamelCase   ,	output_type="np" )
												_lowerCAmelCase			:		str          = output.images
												_lowerCAmelCase			:		str          = image[0, -3:, -3:, -1]

												assert image.shape == (1, 512, 512, 3)
												_lowerCAmelCase			:		Union[str, Any]          = np.array([0.2867, 0.1974, 0.1481, 0.7294, 0.7251, 0.6667, 0.4194, 0.5642, 0.6486] )

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






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Dict          = LMSDiscreteScheduler.from_pretrained(
												    "runwayml/stable-diffusion-v1-5"   ,	subfolder="scheduler"   ,	revision="onnx" )
												_lowerCAmelCase			:		Union[str, Any]          = OnnxStableDiffusionPipeline.from_pretrained(
												    "runwayml/stable-diffusion-v1-5"   ,	revision="onnx"   ,	scheduler=__UpperCamelCase   ,	safety_checker=__UpperCamelCase   ,	feature_extractor=__UpperCamelCase   ,	provider=self.gpu_provider   ,	sess_options=self.gpu_options   ,	)
												sd_pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		str          = "open neural network exchange"
												_lowerCAmelCase			:		Tuple          = np.random.RandomState(0 )
												_lowerCAmelCase			:		Optional[int]          = sd_pipe([prompt]   ,	guidance_scale=7.5   ,	num_inference_steps=10   ,	generator=__UpperCamelCase   ,	output_type="np" )
												_lowerCAmelCase			:		List[str]          = output.images
												_lowerCAmelCase			:		Union[str, Any]          = image[0, -3:, -3:, -1]

												assert image.shape == (1, 512, 512, 3)
												_lowerCAmelCase			:		Tuple          = np.array([0.2306, 0.1959, 0.1593, 0.6549, 0.6394, 0.5408, 0.5065, 0.6010, 0.6161] )

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






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Tuple          = 0

												def test_callback_fn(_snake_case   ,	_snake_case   ,	_snake_case ) -> None:
																	_lowerCAmelCase			:		List[Any]          = True
																	nonlocal number_of_steps
																	number_of_steps += 1
																	if step == 0:
																						assert latents.shape == (1, 4, 64, 64)
																						_lowerCAmelCase			:		Union[str, Any]          = latents[0, -3:, -3:, -1]
																						_lowerCAmelCase			:		Optional[Any]          = np.array(
																						    [-0.6772, -0.3835, -1.2456, 0.1905, -1.0974, 0.6967, -1.9353, 0.0178, 1.0167] )

																						assert np.abs(latents_slice.flatten() - expected_slice ).max() < 1E-3
																	elif step == 5:
																						assert latents.shape == (1, 4, 64, 64)
																						_lowerCAmelCase			:		str          = latents[0, -3:, -3:, -1]
																						_lowerCAmelCase			:		Optional[Any]          = np.array(
																						    [-0.3351, 0.2241, -0.1837, -0.2325, -0.6577, 0.3393, -0.0241, 0.5899, 1.3875] )

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

												_lowerCAmelCase			:		Optional[int]          = False

												_lowerCAmelCase			:		Dict          = OnnxStableDiffusionPipeline.from_pretrained(
												    "runwayml/stable-diffusion-v1-5"   ,	revision="onnx"   ,	safety_checker=__UpperCamelCase   ,	feature_extractor=__UpperCamelCase   ,	provider=self.gpu_provider   ,	sess_options=self.gpu_options   ,	)
												pipe.set_progress_bar_config(disable=__UpperCamelCase )

												_lowerCAmelCase			:		List[str]          = "Andromeda galaxy in a bottle"

												_lowerCAmelCase			:		Optional[int]          = np.random.RandomState(0 )
												pipe(
												    prompt=__UpperCamelCase   ,	num_inference_steps=5   ,	guidance_scale=7.5   ,	generator=__UpperCamelCase   ,	callback=__UpperCamelCase   ,	callback_steps=1   ,	)
												assert test_callback_fn.has_been_called
												assert number_of_steps == 6






							def 	SCREAMING_SNAKE_CASE__			(				self ):
												_lowerCAmelCase			:		Any          = OnnxStableDiffusionPipeline.from_pretrained(
												    "runwayml/stable-diffusion-v1-5"   ,	revision="onnx"   ,	safety_checker=__UpperCamelCase   ,	feature_extractor=__UpperCamelCase   ,	provider=self.gpu_provider   ,	sess_options=self.gpu_options   ,	)
												assert isinstance(__UpperCamelCase   ,	__UpperCamelCase )
												assert pipe.safety_checker is None

												_lowerCAmelCase			:		str          = pipe("example prompt"   ,	num_inference_steps=2 ).images[0]
												assert image is not None

												# check that there's no error when saving a pipeline with one of the models being None
												with tempfile.TemporaryDirectory() as tmpdirname:
																	pipe.save_pretrained(__UpperCamelCase )
																	_lowerCAmelCase			:		int          = OnnxStableDiffusionPipeline.from_pretrained(__UpperCamelCase )

												# sanity check that the pipeline still works
												assert pipe.safety_checker is None
												_lowerCAmelCase			:		Any          = pipe("example prompt"   ,	num_inference_steps=2 ).images[0]
												assert image is not None









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

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


A									=  logging.get_logger(__name__)

A									=  {
    'EleutherAI/gpt-neo-1.3B': 'https://huggingface.co/EleutherAI/gpt-neo-1.3B/resolve/main/config.json',
    # See all GPTNeo models at https://huggingface.co/models?filter=gpt_neo
}


class SCREAMING_SNAKE_CASE	(		__snake_case				):






			"""simple docstring"""




			__A    	=	"""gpt_neo"""
			__A    	=	["""past_key_values"""]
			__A    	=	{"""num_attention_heads""": """num_heads""", """num_hidden_layers""": """num_layers"""}


			def __init__(     self			,					__UpperCamelCase=5_02_57			,					__UpperCamelCase=20_48			,					__UpperCamelCase=20_48			,					__UpperCamelCase=24			,					__UpperCamelCase=[[["global", "local"], 12]]			,					__UpperCamelCase=16			,					__UpperCamelCase=None			,					__UpperCamelCase=2_56			,					__UpperCamelCase="gelu_new"			,					__UpperCamelCase=0.0			,					__UpperCamelCase=0.0			,					__UpperCamelCase=0.0			,					__UpperCamelCase=0.1			,					__UpperCamelCase=1E-5			,					__UpperCamelCase=0.02			,					__UpperCamelCase=True			,					__UpperCamelCase=5_02_56			,					__UpperCamelCase=5_02_56			,					**__UpperCamelCase			,					):

				"""simple docstring"""


				snake_case_   		=			vocab_size
				snake_case_   		=			max_position_embeddings
				snake_case_   		=			hidden_size
				snake_case_   		=			num_layers
				snake_case_   		=			num_heads
				snake_case_   		=			intermediate_size
				snake_case_   		=			window_size
				snake_case_   		=			activation_function
				snake_case_   		=			resid_dropout
				snake_case_   		=			embed_dropout
				snake_case_   		=			attention_dropout
				snake_case_   		=			classifier_dropout
				snake_case_   		=			layer_norm_epsilon
				snake_case_   		=			initializer_range
				snake_case_   		=			use_cache

				snake_case_   		=			bos_token_id
				snake_case_   		=			eos_token_id

				snake_case_   		=			attention_types
				snake_case_   		=			self.expand_attention_types_params(__UpperCamelCase				)

				if len(self.attention_layers				) != self.num_layers:
					raise ValueError(
					    'Configuration for convolutional module is incorrect. '
					    'It is required that `len(config.attention_layers)` == `config.num_layers` '
					    f"""but is `len(config.attention_layers) = {len(self.attention_layers				)}`, """
					    f"""`config.num_layers = {self.num_layers}`. """
					    '`config.attention_layers` is prepared using `config.attention_types`. '
					    'Please verify the value of `config.attention_types` argument.'				)

				super().__init__(bos_token_id=__UpperCamelCase			,					eos_token_id=__UpperCamelCase			,					**__UpperCamelCase				)







			@staticmethod
			def       __lowerCAmelCase			(     __UpperCamelCase				):

				"""simple docstring"""


				snake_case_   		=			[]
				for item in attention_types:
					for _ in range(item[1]				):
						attentions.extend(item[0]				)
				return attentions







def a(lowercase__      ,			lowercase__      ,			lowercase__      ,			lowercase__						):





	'''simple docstring'''
	import torch

	snake_case_   		=			input.size()
	snake_case_   		=			len(lowercase__						)
	snake_case_   		=			shape[dimension]

	snake_case_   		=			torch.arange(0      ,			lowercase__      ,			lowercase__						)
	snake_case_   		=			torch.div(sizedim - size      ,			lowercase__      ,			rounding_mode='floor'						) + 1
	snake_case_   		=			torch.arange(lowercase__						) + low_indices[:min_length][:, None]

	snake_case_   		=			[slice(lowercase__						)] * rank
	snake_case_   		=			indices
	snake_case_   		=			input[s]

	snake_case_   		=			list(range(0      ,			rank + 1						)						)
	perm.append(perm.pop(dimension + 1						)						)

	return sliced.permute(lowercase__						)





def a(lowercase__      ,			lowercase__						):





	'''simple docstring'''
	import torch

	snake_case_   		=			torch.arange(1      ,			lowercase__						)
	snake_case_   		=			torch.remainder(lowercase__      ,			lowercase__						)
	snake_case_   		=			remainders == 0
	snake_case_   		=			candidates[divisor_indices]
	snake_case_   		=			torch.max(lowercase__						)
	return largest_divisor, torch.div(lowercase__      ,			lowercase__      ,			rounding_mode='floor'						)






class SCREAMING_SNAKE_CASE	(		__snake_case				):






			"""simple docstring"""




			@property
			def       __lowerCAmelCase			(     self				):

				"""simple docstring"""


				snake_case_   		=			OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}				)
				if self.use_past:
					self.fill_with_past_key_values_(__UpperCamelCase			,					direction='inputs'				)
					snake_case_   		=			{0: 'batch', 1: 'past_sequence + sequence'}
				else:
					snake_case_   		=			{0: 'batch', 1: 'sequence'}

				return common_inputs


			@property
			def       __lowerCAmelCase			(     self				):

				"""simple docstring"""


				return self._config.num_heads


			def       __lowerCAmelCase			(     self			,					__UpperCamelCase			,					__UpperCamelCase = -1			,					__UpperCamelCase = -1			,					__UpperCamelCase = False			,					__UpperCamelCase = None			,					):

				"""simple docstring"""


				snake_case_   		=			super(__UpperCamelCase			,					self				).generate_dummy_inputs(
				    __UpperCamelCase			,					batch_size=__UpperCamelCase			,					seq_length=__UpperCamelCase			,					is_pair=__UpperCamelCase			,					framework=__UpperCamelCase				)

				# We need to order the input in the way they appears in the forward()
				snake_case_   		=			OrderedDict({'input_ids': common_inputs['input_ids']}				)

				# Need to add the past_keys
				if self.use_past:
					if not is_torch_available():
						raise ValueError('Cannot generate dummy past_keys inputs without PyTorch installed.'				)
					else:
						import torch

						snake_case_		,							snake_case_   		=			common_inputs['input_ids'].shape
						# Not using the same length for past_key_values
						snake_case_   		=			seqlen + 2
						snake_case_   		=			(
						    batch,
						    self.num_attention_heads,
						    past_key_values_length,
						    self._config.hidden_size // self.num_attention_heads,
						)
						snake_case_   		=			[
						    (torch.zeros(__UpperCamelCase				), torch.zeros(__UpperCamelCase				)) for _ in range(self.num_layers				)
						]

				snake_case_   		=			common_inputs['attention_mask']
				if self.use_past:
					snake_case_   		=			ordered_inputs['attention_mask'].dtype
					snake_case_   		=			torch.cat(
					    [ordered_inputs['attention_mask'], torch.ones(__UpperCamelCase			,					__UpperCamelCase			,					dtype=__UpperCamelCase				)]			,					dim=1				)

				return ordered_inputs







			@property
			def       __lowerCAmelCase			(     self				):

				"""simple docstring"""


				return 13
