
import math
from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL
import torch
from transformers import CLIPTextModelWithProjection, CLIPTokenizer

from ...models import PriorTransformer
from ...pipelines import DiffusionPipeline
from ...schedulers import HeunDiscreteScheduler
from ...utils import (
    BaseOutput,
    is_accelerate_available,
    is_accelerate_version,
    logging,
    randn_tensor,
    replace_example_docstring,
)
from .renderer import ShapERenderer


SCREAMING_SNAKE_CASE__     :    List[Any]      							=					logging.get_logger(__name__)  # pylint: disable=invalid-name

SCREAMING_SNAKE_CASE__     :    Union[str, Any]      							=					"\n    Examples:\n        ```py\n        >>> import torch\n        >>> from diffusers import DiffusionPipeline\n        >>> from diffusers.utils import export_to_gif\n\n        >>> device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n\n        >>> repo = \"openai/shap-e\"\n        >>> pipe = DiffusionPipeline.from_pretrained(repo, torch_dtype=torch.float16)\n        >>> pipe = pipe.to(device)\n\n        >>> guidance_scale = 15.0\n        >>> prompt = \"a shark\"\n\n        >>> images = pipe(\n        ...     prompt,\n        ...     guidance_scale=guidance_scale,\n        ...     num_inference_steps=64,\n        ...     frame_size=256,\n        ... ).images\n\n        >>> gif_path = export_to_gif(images[0], \"shark_3d.gif\")\n        ```\n"

@dataclass
class      lowerCAmelCase__  (			__lowercase    ):
		a__ :		Union[List[List[PIL.Image.Image]], List[List[np.ndarray]]]





class      lowerCAmelCase__  (			__lowercase    ):






		def __init__(	self	:							Optional[Any]							,    SCREAMING_SNAKE_CASE__	:							PriorTransformer							,    SCREAMING_SNAKE_CASE__	:							CLIPTextModelWithProjection							,    SCREAMING_SNAKE_CASE__	:							CLIPTokenizer							,    SCREAMING_SNAKE_CASE__	:							HeunDiscreteScheduler							,    SCREAMING_SNAKE_CASE__	:							ShapERenderer							,    )  ->							List[Any]:
						super().__init__()

						self.register_modules(
						    prior=SCREAMING_SNAKE_CASE__							,    text_encoder=SCREAMING_SNAKE_CASE__							,    tokenizer=SCREAMING_SNAKE_CASE__							,    scheduler=SCREAMING_SNAKE_CASE__							,    renderer=SCREAMING_SNAKE_CASE__							,    )






		def 				__A (	self	:							Union[str, Any]							,    SCREAMING_SNAKE_CASE__	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							int							,    SCREAMING_SNAKE_CASE__	:							Optional[Any]							,    SCREAMING_SNAKE_CASE__	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							str						)  ->							int:
						if latents is None:
										__lowerCamelCase					      =			randn_tensor(SCREAMING_SNAKE_CASE__							,    generator=SCREAMING_SNAKE_CASE__							,    device=SCREAMING_SNAKE_CASE__							,    dtype=SCREAMING_SNAKE_CASE__						)
						else:
										if latents.shape != shape:
														raise ValueError(f'''Unexpected latents shape, got {latents.shape}, expected {shape}'''						)
										__lowerCamelCase					      =			latents.to(SCREAMING_SNAKE_CASE__						)

						__lowerCamelCase					      =			latents * scheduler.init_noise_sigma
						return latents






		def 				__A (	self	:							Union[str, Any]							,    SCREAMING_SNAKE_CASE__	:							List[str]=0						)  ->							Dict:
						if is_accelerate_available():
										from accelerate import cpu_offload
						else:
										raise ImportError('''Please install accelerate via `pip install accelerate`'''						)

						__lowerCamelCase					      =			torch.device(f'''cuda:{gpu_id}'''						)

						__lowerCamelCase					      =			[self.text_encoder, self.prior]
						for cpu_offloaded_model in models:
										if cpu_offloaded_model is not None:
														cpu_offload(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						)






		def 				__A (	self	:							List[str]							,    SCREAMING_SNAKE_CASE__	:							Any=0						)  ->							str:
						if is_accelerate_available() and is_accelerate_version('''>='''							,    '''0.17.0.dev0'''						):
										from accelerate import cpu_offload_with_hook
						else:
										raise ImportError('''`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.'''						)

						__lowerCamelCase					      =			torch.device(f'''cuda:{gpu_id}'''						)

						if self.device.type != "cpu":
										self.to('''cpu'''							,    silence_dtype_warnings=SCREAMING_SNAKE_CASE__						)
										torch.cuda.empty_cache()  # otherwise we don't see the memory savings (but they probably exist)

						__lowerCamelCase					      =			None
						for cpu_offloaded_model in [self.text_encoder, self.prior, self.renderer]:
										__lowerCamelCase      ,					__lowerCamelCase					      =			cpu_offload_with_hook(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    prev_module_hook=SCREAMING_SNAKE_CASE__						)

						if self.safety_checker is not None:
										__lowerCamelCase      ,					__lowerCamelCase					      =			cpu_offload_with_hook(self.safety_checker							,    SCREAMING_SNAKE_CASE__							,    prev_module_hook=SCREAMING_SNAKE_CASE__						)

						# We'll offload the last model manually.
						__lowerCamelCase					      =			hook






		@property
		def 				__A (	self	:							Union[str, Any]						)  ->							Optional[Any]:
						if self.device != torch.device('''meta'''						) or not hasattr(self.text_encoder							,    '''_hf_hook'''						):
										return self.device
						for module in self.text_encoder.modules():
										if (
										    hasattr(SCREAMING_SNAKE_CASE__							,    '''_hf_hook'''						)
										    and hasattr(module._hf_hook							,    '''execution_device'''						)
										    and module._hf_hook.execution_device is not None
										):
														return torch.device(module._hf_hook.execution_device						)
						return self.device






		def 				__A (	self	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							List[Any]							,    SCREAMING_SNAKE_CASE__	:							int							,    SCREAMING_SNAKE_CASE__	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							Any							,    )  ->							str:
						len(SCREAMING_SNAKE_CASE__						) if isinstance(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						) else 1

						# YiYi Notes: set pad_token_id to be 0, not sure why I can't set in the config file
						__lowerCamelCase					      =			0
						# get prompt text embeddings
						__lowerCamelCase					      =			self.tokenizer(
						    SCREAMING_SNAKE_CASE__							,    padding='''max_length'''							,    max_length=self.tokenizer.model_max_length							,    truncation=SCREAMING_SNAKE_CASE__							,    return_tensors='''pt'''							,    )
						__lowerCamelCase					      =			text_inputs.input_ids
						__lowerCamelCase					      =			self.tokenizer(SCREAMING_SNAKE_CASE__							,    padding='''longest'''							,    return_tensors='''pt'''						).input_ids

						if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						):
										__lowerCamelCase					      =			self.tokenizer.batch_decode(untruncated_ids[:, self.tokenizer.model_max_length - 1 : -1]						)
										logger.warning(
										    '''The following part of your input was truncated because CLIP can only handle sequences up to'''
										    f''' {self.tokenizer.model_max_length} tokens: {removed_text}'''						)

						__lowerCamelCase					      =			self.text_encoder(text_input_ids.to(SCREAMING_SNAKE_CASE__						)						)
						__lowerCamelCase					      =			text_encoder_output.text_embeds

						__lowerCamelCase					      =			prompt_embeds.repeat_interleave(SCREAMING_SNAKE_CASE__							,    dim=0						)
						# in Shap-E it normalize the prompt_embeds and then later rescale it
						__lowerCamelCase					      =			prompt_embeds / torch.linalg.norm(SCREAMING_SNAKE_CASE__							,    dim=-1							,    keepdim=SCREAMING_SNAKE_CASE__						)

						if do_classifier_free_guidance:
										__lowerCamelCase					      =			torch.zeros_like(SCREAMING_SNAKE_CASE__						)

										# For classifier free guidance, we need to do two forward passes.
										# Here we concatenate the unconditional and text embeddings into a single batch
										# to avoid doing two forward passes
										__lowerCamelCase					      =			torch.cat([negative_prompt_embeds, prompt_embeds]						)

						# Rescale the features to have unit variance
						__lowerCamelCase					      =			math.sqrt(prompt_embeds.shape[1]						) * prompt_embeds

						return prompt_embeds







		@torch.no_grad()
		@replace_example_docstring(SCREAMING_SNAKE_CASE__						)
		def __call__(	self	:							Any							,    SCREAMING_SNAKE_CASE__	:							str							,    SCREAMING_SNAKE_CASE__	:							int = 1							,    SCREAMING_SNAKE_CASE__	:							int = 25							,    SCREAMING_SNAKE_CASE__	:							Optional[Union[torch.Generator, List[torch.Generator]]] = None							,    SCREAMING_SNAKE_CASE__	:							Optional[torch.FloatTensor] = None							,    SCREAMING_SNAKE_CASE__	:							float = 4.0							,    SCREAMING_SNAKE_CASE__	:							int = 64							,    SCREAMING_SNAKE_CASE__	:							Optional[str] = "pil"							,    SCREAMING_SNAKE_CASE__	:							bool = True							,    )  ->							List[str]:

						if isinstance(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						):
										__lowerCamelCase					      =			1
						elif isinstance(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						):
										__lowerCamelCase					      =			len(SCREAMING_SNAKE_CASE__						)
						else:
										raise ValueError(f'''`prompt` has to be of type `str` or `list` but is {type(SCREAMING_SNAKE_CASE__						)}'''						)

						__lowerCamelCase					      =			self._execution_device

						__lowerCamelCase					      =			batch_size * num_images_per_prompt

						__lowerCamelCase					      =			guidance_scale > 1.0
						__lowerCamelCase					      =			self._encode_prompt(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						)

						# prior

						self.scheduler.set_timesteps(SCREAMING_SNAKE_CASE__							,    device=SCREAMING_SNAKE_CASE__						)
						__lowerCamelCase					      =			self.scheduler.timesteps

						__lowerCamelCase					      =			self.prior.config.num_embeddings
						__lowerCamelCase					      =			self.prior.config.embedding_dim

						__lowerCamelCase					      =			self.prepare_latents(
						    (batch_size, num_embeddings * embedding_dim)							,    prompt_embeds.dtype							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    self.scheduler							,    )

						# YiYi notes: for testing only to match ldm, we can directly create a latents with desired shape: batch_size, num_embeddings, embedding_dim
						__lowerCamelCase					      =			latents.reshape(latents.shape[0]							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						)

						for i, t in enumerate(self.progress_bar(SCREAMING_SNAKE_CASE__						)						):
										# expand the latents if we are doing classifier free guidance
										__lowerCamelCase					      =			torch.cat([latents] * 2						) if do_classifier_free_guidance else latents
										__lowerCamelCase					      =			self.scheduler.scale_model_input(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						)

										__lowerCamelCase					      =			self.prior(
										    SCREAMING_SNAKE_CASE__							,    timestep=SCREAMING_SNAKE_CASE__							,    proj_embedding=SCREAMING_SNAKE_CASE__							,    ).predicted_image_embedding

										# remove the variance
										__lowerCamelCase      ,					__lowerCamelCase					      =			noise_pred.split(
										    scaled_model_input.shape[2]							,    dim=2						)  # batch_size, num_embeddings, embedding_dim

										if do_classifier_free_guidance is not None:
														__lowerCamelCase      ,					__lowerCamelCase					      =			noise_pred.chunk(2						)
														__lowerCamelCase					      =			noise_pred_uncond + guidance_scale * (noise_pred - noise_pred_uncond)

										__lowerCamelCase					      =			self.scheduler.step(
										    SCREAMING_SNAKE_CASE__							,    timestep=SCREAMING_SNAKE_CASE__							,    sample=SCREAMING_SNAKE_CASE__							,    ).prev_sample

						if output_type == "latent":
										return ShapEPipelineOutput(images=SCREAMING_SNAKE_CASE__						)

						__lowerCamelCase					      =			[]
						for i, latent in enumerate(SCREAMING_SNAKE_CASE__						):
										__lowerCamelCase					      =			self.renderer.decode(
										    latent[None, :]							,    SCREAMING_SNAKE_CASE__							,    size=SCREAMING_SNAKE_CASE__							,    ray_batch_size=40_96							,    n_coarse_samples=64							,    n_fine_samples=1_28							,    )
										images.append(SCREAMING_SNAKE_CASE__						)

						__lowerCamelCase					      =			torch.stack(SCREAMING_SNAKE_CASE__						)

						if output_type not in ["np", "pil"]:
										raise ValueError(f'''Only the output types `pil` and `np` are supported not output_type={output_type}'''						)

						__lowerCamelCase					      =			images.cpu().numpy()

						if output_type == "pil":
										__lowerCamelCase					      =			[self.numpy_to_pil(SCREAMING_SNAKE_CASE__						) for image in images]

						# Offload last model to CPU
						if hasattr(self							,    '''final_offload_hook'''						) and self.final_offload_hook is not None:
										self.final_offload_hook.offload()

						if not return_dict:
										return (images,)

						return ShapEPipelineOutput(images=SCREAMING_SNAKE_CASE__						)





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

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


SCREAMING_SNAKE_CASE__     :    int      							=					logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__     :    List[str]      							=					{
    "facebook/m2m100_418M": "https://huggingface.co/facebook/m2m100_418M/resolve/main/config.json",
    # See all M2M100 models at https://huggingface.co/models?filter=m2m_100
}

class      lowerCAmelCase__  (			__lowercase    ):
		a__ :		Union[str, Any]   						=	"""m2m_100"""
		a__ :		Optional[int]   						=	["""past_key_values"""]
		a__ :		List[Any]   						=	{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}






		def __init__(	self	:							int							,    SCREAMING_SNAKE_CASE__	:							Tuple=12_81_12							,    SCREAMING_SNAKE_CASE__	:							Any=10_24							,    SCREAMING_SNAKE_CASE__	:							int=12							,    SCREAMING_SNAKE_CASE__	:							List[str]=40_96							,    SCREAMING_SNAKE_CASE__	:							Optional[int]=16							,    SCREAMING_SNAKE_CASE__	:							Optional[int]=12							,    SCREAMING_SNAKE_CASE__	:							int=40_96							,    SCREAMING_SNAKE_CASE__	:							Optional[Any]=16							,    SCREAMING_SNAKE_CASE__	:							Dict=0.05							,    SCREAMING_SNAKE_CASE__	:							List[Any]=0.05							,    SCREAMING_SNAKE_CASE__	:							Dict=True							,    SCREAMING_SNAKE_CASE__	:							Tuple=True							,    SCREAMING_SNAKE_CASE__	:							Optional[Any]="relu"							,    SCREAMING_SNAKE_CASE__	:							Dict=10_24							,    SCREAMING_SNAKE_CASE__	:							Optional[int]=0.1							,    SCREAMING_SNAKE_CASE__	:							Tuple=0.1							,    SCREAMING_SNAKE_CASE__	:							str=0.0							,    SCREAMING_SNAKE_CASE__	:							Any=0.02							,    SCREAMING_SNAKE_CASE__	:							int=2							,    SCREAMING_SNAKE_CASE__	:							List[Any]=True							,    SCREAMING_SNAKE_CASE__	:							Any=1							,    SCREAMING_SNAKE_CASE__	:							Union[str, Any]=0							,    SCREAMING_SNAKE_CASE__	:							str=2							,    **SCREAMING_SNAKE_CASE__	:							Tuple							,    )  ->							Tuple:
						__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=SCREAMING_SNAKE_CASE__							,    bos_token_id=SCREAMING_SNAKE_CASE__							,    eos_token_id=SCREAMING_SNAKE_CASE__							,    is_encoder_decoder=SCREAMING_SNAKE_CASE__							,    decoder_start_token_id=SCREAMING_SNAKE_CASE__							,    **SCREAMING_SNAKE_CASE__							,    )





class      lowerCAmelCase__  (			__lowercase    ):






		@property
		def 				__A (	self	:							List[Any]						)  ->							Mapping[str, Mapping[int, str]]:
						__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_(SCREAMING_SNAKE_CASE__							,    direction='''inputs'''						)
						return common_inputs






		def 				__A (	self	:							Any							,    SCREAMING_SNAKE_CASE__	:							PreTrainedTokenizer							,    SCREAMING_SNAKE_CASE__	:							int = -1							,    SCREAMING_SNAKE_CASE__	:							int = -1							,    SCREAMING_SNAKE_CASE__	:							bool = False							,    SCREAMING_SNAKE_CASE__	:							Optional[TensorType] = 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(
						    SCREAMING_SNAKE_CASE__							,    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(SCREAMING_SNAKE_CASE__						)
						__lowerCamelCase					      =			compute_effective_axis_dimension(
						    SCREAMING_SNAKE_CASE__							,    fixed_dimension=OnnxConfig.default_fixed_sequence							,    num_token_to_add=SCREAMING_SNAKE_CASE__						)

						# Generate dummy inputs according to compute batch and sequence
						__lowerCamelCase					      =			[''' '''.join([tokenizer.unk_token]						) * seq_length] * batch_size
						__lowerCamelCase					      =			dict(tokenizer(SCREAMING_SNAKE_CASE__							,    return_tensors=SCREAMING_SNAKE_CASE__						)						)
						return common_inputs






		def 				__A (	self	:							Union[str, Any]							,    SCREAMING_SNAKE_CASE__	:							PreTrainedTokenizer							,    SCREAMING_SNAKE_CASE__	:							int = -1							,    SCREAMING_SNAKE_CASE__	:							int = -1							,    SCREAMING_SNAKE_CASE__	:							bool = False							,    SCREAMING_SNAKE_CASE__	:							Optional[TensorType] = None							,    )  ->							Mapping[str, Any]:
						__lowerCamelCase					      =			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
						    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						)

						# Generate decoder inputs
						__lowerCamelCase					      =			seq_length if not self.use_past else 1
						__lowerCamelCase					      =			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
						    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						)
						__lowerCamelCase					      =			{f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
						__lowerCamelCase					      =			dict(**SCREAMING_SNAKE_CASE__							,    **SCREAMING_SNAKE_CASE__						)

						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(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						)]							,    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(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						)
										__lowerCamelCase					      =			max(SCREAMING_SNAKE_CASE__							,    SCREAMING_SNAKE_CASE__						) - min_num_layers
										__lowerCamelCase					      =			'''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

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







		a__ :		Dict   						=	_generate_dummy_inputs_for_default_and_seqaseq_lm



