






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


lowerCamelCase : Dict						   =       logging.get_logger(__name__)

lowerCamelCase : Union[str, Any]						   =       {
    '''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 		lowerCAmelCase     ( __a			):

					'''simple docstring'''

					_A						:			int									=      '''marian'''
					_A						:			Any									=      ['''past_key_values''']
					_A						:			List[Any]									=      {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}



					def __init__(  self				:	Union[str, Any]		,     __a				:	Any=58101		,     __a				:	Optional[Any]=None		,     __a				:	List[str]=1024		,     __a				:	Any=12		,     __a				:	Tuple=4096		,     __a				:	Union[str, Any]=16		,     __a				:	Tuple=12		,     __a				:	Optional[int]=4096		,     __a				:	List[Any]=16		,     __a				:	Optional[Any]=0.0		,     __a				:	Optional[Any]=0.0		,     __a				:	Optional[int]=True		,     __a				:	str=True		,     __a				:	Tuple="gelu"		,     __a				:	str=1024		,     __a				:	str=0.1		,     __a				:	Dict=0.0		,     __a				:	List[str]=0.0		,     __a				:	List[Any]=0.02		,     __a				:	int=58100		,     __a				:	Tuple=False		,     __a				:	Optional[int]=58100		,     __a				:	int=0		,     __a				:	Optional[int]=0		,     __a				:	Optional[int]=True		,     **__a				:	Dict		,     )			->  Dict:


												"""simple docstring"""

												__lowercase      :							str				=     vocab_size
												__lowercase      :							Any				=     decoder_vocab_size or vocab_size
												__lowercase      :							Optional[int]				=     max_position_embeddings
												__lowercase      :							Dict				=     d_model
												__lowercase      :							Any				=     encoder_ffn_dim
												__lowercase      :							List[Any]				=     encoder_layers
												__lowercase      :							Optional[Any]				=     encoder_attention_heads
												__lowercase      :							str				=     decoder_ffn_dim
												__lowercase      :							Any				=     decoder_layers
												__lowercase      :							Optional[Any]				=     decoder_attention_heads
												__lowercase      :							Any				=     dropout
												__lowercase      :							Optional[int]				=     attention_dropout
												__lowercase      :							Union[str, Any]				=     activation_dropout
												__lowercase      :							Tuple				=     activation_function
												__lowercase      :							Any				=     init_std
												__lowercase      :							Optional[Any]				=     encoder_layerdrop
												__lowercase      :							int				=     decoder_layerdrop
												__lowercase      :							List[str]				=     use_cache
												__lowercase      :							List[str]				=     encoder_layers
												__lowercase      :							List[str]				=     scale_embedding  # scale factor will be sqrt(d_model) if True
												__lowercase      :							Optional[Any]				=     share_encoder_decoder_embeddings
												super().__init__(
												    pad_token_id=__A		,     eos_token_id=__A		,     is_encoder_decoder=__A		,     decoder_start_token_id=__A		,     forced_eos_token_id=__A		,     **__A		,     )

class 		lowerCAmelCase     ( __a			):

					'''simple docstring'''

					@property
					# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
					def       lowerCAmelCase				(  self				:	Any							)			->  Mapping[str, Mapping[int, str]]:


												"""simple docstring"""

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

																			if self.use_past:
																										__lowercase      :							Optional[int]				=     {0: """batch"""}
																										__lowercase      :							Optional[int]				=     {0: """batch""", 1: """past_decoder_sequence + sequence"""}
																			else:
																										__lowercase      :							Any				=     {0: """batch""", 1: """decoder_sequence"""}
																										__lowercase      :							int				=     {0: """batch""", 1: """decoder_sequence"""}

																			if self.use_past:
																										self.fill_with_past_key_values_(__A		,     direction="""inputs"""							)
												elif self.task == "causal-lm":
																			# TODO: figure this case out.
																			__lowercase      :							Any				=     OrderedDict(
																			    [
																			        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
																			        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
																			    ]							)
																			if self.use_past:
																										__lowercase			,			__lowercase      :							int				=     self.num_layers
																										for i in range(__A							):
																																	__lowercase      :							Optional[Any]				=     {0: """batch""", 2: """past_sequence + sequence"""}
																																	__lowercase      :							Any				=     {0: """batch""", 2: """past_sequence + sequence"""}
												else:
																			__lowercase      :							Dict				=     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				:	int							)			->  Mapping[str, Mapping[int, str]]:


												"""simple docstring"""

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



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


												"""simple docstring"""

												__lowercase      :							Optional[Any]				=     self._generate_dummy_inputs_for_encoder_and_decoder(
												    __A		,     __A		,     __A		,     __A		,     __A							)

												# Generate decoder inputs
												__lowercase      :							Optional[Any]				=     seq_length if not self.use_past else 1
												__lowercase      :							Optional[int]				=     self._generate_dummy_inputs_for_encoder_and_decoder(
												    __A		,     __A		,     __A		,     __A		,     __A							)
												__lowercase      :							List[str]				=     {F"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
												__lowercase      :							List[Any]				=     dict(**__A		,     **__A							)

												if self.use_past:
																			if not is_torch_available():
																										raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""							)
																			else:
																										import torch
																			__lowercase			,			__lowercase      :							Any				=     common_inputs["""input_ids"""].shape
																			__lowercase      :							int				=     common_inputs["""decoder_input_ids"""].shape[1]
																			__lowercase			,			__lowercase      :							Dict				=     self.num_attention_heads
																			__lowercase      :							Optional[int]				=     (
																			    batch,
																			    num_encoder_attention_heads,
																			    encoder_seq_length,
																			    self._config.hidden_size // num_encoder_attention_heads,
																			)
																			__lowercase      :							Union[str, Any]				=     decoder_seq_length + 3
																			__lowercase      :							Optional[Any]				=     (
																			    batch,
																			    num_decoder_attention_heads,
																			    decoder_past_length,
																			    self._config.hidden_size // num_decoder_attention_heads,
																			)

																			__lowercase      :							Tuple				=     torch.cat(
																			    [common_inputs["""decoder_attention_mask"""], torch.ones(__A		,     __A							)]		,     dim=1							)

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

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



					def       lowerCAmelCase				(  self				:	List[str]		,     __a				:	PreTrainedTokenizer		,     __a				:	int = -1		,     __a				:	int = -1		,     __a				:	bool = False		,     __a				:	Optional[TensorType] = None		,     )			->  Mapping[str, Any]:


												"""simple docstring"""

												__lowercase      :							int				=     self._generate_dummy_inputs_for_encoder_and_decoder(
												    __A		,     __A		,     __A		,     __A		,     __A							)

												if self.use_past:
																			if not is_torch_available():
																										raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""							)
																			else:
																										import torch
																			__lowercase			,			__lowercase      :							str				=     common_inputs["""input_ids"""].shape
																			# Not using the same length for past_key_values
																			__lowercase      :							Optional[int]				=     seqlen + 2
																			__lowercase			,			__lowercase      :							Dict				=     self.num_layers
																			__lowercase			,			__lowercase      :							Optional[int]				=     self.num_attention_heads
																			__lowercase      :							Union[str, Any]				=     (
																			    batch,
																			    num_encoder_attention_heads,
																			    past_key_values_length,
																			    self._config.hidden_size // num_encoder_attention_heads,
																			)

																			__lowercase      :							Optional[int]				=     common_inputs["""attention_mask"""].dtype
																			__lowercase      :							int				=     torch.cat(
																			    [common_inputs["""attention_mask"""], torch.ones(__A		,     __A		,     dtype=__A							)]		,     dim=1							)
																			__lowercase      :							str				=     [
																			    (torch.zeros(__A							), torch.zeros(__A							)) for _ in range(__A							)
																			]
												return common_inputs



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


												"""simple docstring"""

												__lowercase      :							int				=     compute_effective_axis_dimension(
												    __A		,     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
												__lowercase      :							Any				=     tokenizer.num_special_tokens_to_add(__A							)
												__lowercase      :							str				=     compute_effective_axis_dimension(
												    __A		,     fixed_dimension=OnnxConfig.default_fixed_sequence		,     num_token_to_add=__A							)

												# Generate dummy inputs according to compute batch and sequence
												__lowercase      :							Tuple				=     [""" """.join([tokenizer.unk_token]							) * seq_length] * batch_size
												__lowercase      :							Dict				=     dict(tokenizer(__A		,     return_tensors=__A							)							)
												return common_inputs



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


												"""simple docstring"""

												if self.task in ["default", "seq2seq-lm"]:
																			__lowercase      :							Union[str, Any]				=     self._generate_dummy_inputs_for_default_and_seqaseq_lm(
																			    __A		,     batch_size=__A		,     seq_length=__A		,     is_pair=__A		,     framework=__A							)

												else:
																			__lowercase      :							Any				=     self._generate_dummy_inputs_for_causal_lm(
																			    __A		,     batch_size=__A		,     seq_length=__A		,     is_pair=__A		,     framework=__A							)

												return common_inputs



					def       lowerCAmelCase				(  self				:	Dict		,     __a				:	Any		,     __a				:	Any		,     __a				:	Tuple		,     __a				:	Dict							)			->  Union[str, Any]:


												"""simple docstring"""

												if self.task in ["default", "seq2seq-lm"]:
																			__lowercase      :							Union[str, Any]				=     super()._flatten_past_key_values_(__A		,     __A		,     __A		,     __A							)
												else:
																			__lowercase      :							List[str]				=     super(__A		,     self							)._flatten_past_key_values_(
																			    __A		,     __A		,     __A		,     __A							)



					@property
					def       lowerCAmelCase				(  self				:	Any							)			->  float:


												"""simple docstring"""

												return 1E-4







lowerCamelCase : List[str]						   =       '''0.18.2'''

from .configuration_utils import ConfigMixin
from .utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_inflect_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
    is_transformers_available,
    is_transformers_version,
    is_unidecode_available,
    logging,
)


try:
	if not is_onnx_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_onnx_objects import *  # noqa F403
else:
	from .pipelines import OnnxRuntimeModel

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_pt_objects import *  # noqa F403
else:
	from .models import (
	    AutoencoderKL,
	    ControlNetModel,
	    ModelMixin,
	    PriorTransformer,
	    TaFilmDecoder,
	    TransformeraDModel,
	    UNetaDModel,
	    UNetaDConditionModel,
	    UNetaDModel,
	    UNetaDConditionModel,
	    VQModel,
	)
	from .optimization import (
	    get_constant_schedule,
	    get_constant_schedule_with_warmup,
	    get_cosine_schedule_with_warmup,
	    get_cosine_with_hard_restarts_schedule_with_warmup,
	    get_linear_schedule_with_warmup,
	    get_polynomial_decay_schedule_with_warmup,
	    get_scheduler,
	)
	from .pipelines import (
	    AudioPipelineOutput,
	    ConsistencyModelPipeline,
	    DanceDiffusionPipeline,
	    DDIMPipeline,
	    DDPMPipeline,
	    DiffusionPipeline,
	    DiTPipeline,
	    ImagePipelineOutput,
	    KarrasVePipeline,
	    LDMPipeline,
	    LDMSuperResolutionPipeline,
	    PNDMPipeline,
	    RePaintPipeline,
	    ScoreSdeVePipeline,
	)
	from .schedulers import (
	    CMStochasticIterativeScheduler,
	    DDIMInverseScheduler,
	    DDIMParallelScheduler,
	    DDIMScheduler,
	    DDPMParallelScheduler,
	    DDPMScheduler,
	    DEISMultistepScheduler,
	    DPMSolverMultistepInverseScheduler,
	    DPMSolverMultistepScheduler,
	    DPMSolverSinglestepScheduler,
	    EulerAncestralDiscreteScheduler,
	    EulerDiscreteScheduler,
	    HeunDiscreteScheduler,
	    IPNDMScheduler,
	    KarrasVeScheduler,
	    KDPMaAncestralDiscreteScheduler,
	    KDPMaDiscreteScheduler,
	    PNDMScheduler,
	    RePaintScheduler,
	    SchedulerMixin,
	    ScoreSdeVeScheduler,
	    UnCLIPScheduler,
	    UniPCMultistepScheduler,
	    VQDiffusionScheduler,
	)
	from .training_utils import EMAModel

try:
	if not (is_torch_available() and is_scipy_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
	from .schedulers import LMSDiscreteScheduler

try:
	if not (is_torch_available() and is_torchsde_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
	from .schedulers import DPMSolverSDEScheduler

try:
	if not (is_torch_available() and is_transformers_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
	from .pipelines import (
	    AltDiffusionImgaImgPipeline,
	    AltDiffusionPipeline,
	    AudioLDMPipeline,
	    CycleDiffusionPipeline,
	    IFImgaImgPipeline,
	    IFImgaImgSuperResolutionPipeline,
	    IFInpaintingPipeline,
	    IFInpaintingSuperResolutionPipeline,
	    IFPipeline,
	    IFSuperResolutionPipeline,
	    ImageTextPipelineOutput,
	    KandinskyImgaImgPipeline,
	    KandinskyInpaintPipeline,
	    KandinskyPipeline,
	    KandinskyPriorPipeline,
	    KandinskyVaaControlnetImgaImgPipeline,
	    KandinskyVaaControlnetPipeline,
	    KandinskyVaaImgaImgPipeline,
	    KandinskyVaaInpaintPipeline,
	    KandinskyVaaPipeline,
	    KandinskyVaaPriorEmbaEmbPipeline,
	    KandinskyVaaPriorPipeline,
	    LDMTextToImagePipeline,
	    PaintByExamplePipeline,
	    SemanticStableDiffusionPipeline,
	    ShapEImgaImgPipeline,
	    ShapEPipeline,
	    StableDiffusionAttendAndExcitePipeline,
	    StableDiffusionControlNetImgaImgPipeline,
	    StableDiffusionControlNetInpaintPipeline,
	    StableDiffusionControlNetPipeline,
	    StableDiffusionDepthaImgPipeline,
	    StableDiffusionDiffEditPipeline,
	    StableDiffusionImageVariationPipeline,
	    StableDiffusionImgaImgPipeline,
	    StableDiffusionInpaintPipeline,
	    StableDiffusionInpaintPipelineLegacy,
	    StableDiffusionInstructPixaPixPipeline,
	    StableDiffusionLatentUpscalePipeline,
	    StableDiffusionLDMaDPipeline,
	    StableDiffusionModelEditingPipeline,
	    StableDiffusionPanoramaPipeline,
	    StableDiffusionParadigmsPipeline,
	    StableDiffusionPipeline,
	    StableDiffusionPipelineSafe,
	    StableDiffusionPixaPixZeroPipeline,
	    StableDiffusionSAGPipeline,
	    StableDiffusionUpscalePipeline,
	    StableUnCLIPImgaImgPipeline,
	    StableUnCLIPPipeline,
	    TextToVideoSDPipeline,
	    TextToVideoZeroPipeline,
	    UnCLIPImageVariationPipeline,
	    UnCLIPPipeline,
	    UniDiffuserModel,
	    UniDiffuserPipeline,
	    UniDiffuserTextDecoder,
	    VersatileDiffusionDualGuidedPipeline,
	    VersatileDiffusionImageVariationPipeline,
	    VersatileDiffusionPipeline,
	    VersatileDiffusionTextToImagePipeline,
	    VideoToVideoSDPipeline,
	    VQDiffusionPipeline,
	)

try:
	if not (is_torch_available() and is_transformers_available() and is_invisible_watermark_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_torch_and_transformers_and_invisible_watermark_objects import *  # noqa F403
else:
	from .pipelines import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

try:
	if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
	from .pipelines import StableDiffusionKDiffusionPipeline

try:
	if not (is_torch_available() and is_transformers_available() and is_onnx_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_torch_and_transformers_and_onnx_objects import *  # noqa F403
else:
	from .pipelines import (
	    OnnxStableDiffusionImgaImgPipeline,
	    OnnxStableDiffusionInpaintPipeline,
	    OnnxStableDiffusionInpaintPipelineLegacy,
	    OnnxStableDiffusionPipeline,
	    OnnxStableDiffusionUpscalePipeline,
	    StableDiffusionOnnxPipeline,
	)

try:
	if not (is_torch_available() and is_librosa_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_torch_and_librosa_objects import *  # noqa F403
else:
	from .pipelines import AudioDiffusionPipeline, Mel

try:
	if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
	from .pipelines import SpectrogramDiffusionPipeline

try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_flax_objects import *  # noqa F403
else:
	from .models.controlnet_flax import FlaxControlNetModel
	from .models.modeling_flax_utils import FlaxModelMixin
	from .models.unet_ad_condition_flax import FlaxUNetaDConditionModel
	from .models.vae_flax import FlaxAutoencoderKL
	from .pipelines import FlaxDiffusionPipeline
	from .schedulers import (
	    FlaxDDIMScheduler,
	    FlaxDDPMScheduler,
	    FlaxDPMSolverMultistepScheduler,
	    FlaxKarrasVeScheduler,
	    FlaxLMSDiscreteScheduler,
	    FlaxPNDMScheduler,
	    FlaxSchedulerMixin,
	    FlaxScoreSdeVeScheduler,
	)


try:
	if not (is_flax_available() and is_transformers_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_flax_and_transformers_objects import *  # noqa F403
else:
	from .pipelines import (
	    FlaxStableDiffusionControlNetPipeline,
	    FlaxStableDiffusionImgaImgPipeline,
	    FlaxStableDiffusionInpaintPipeline,
	    FlaxStableDiffusionPipeline,
	)

try:
	if not (is_note_seq_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from .utils.dummy_note_seq_objects import *  # noqa F403
else:
	from .pipelines import MidiProcessor