



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


UpperCamelCase__						=			logging.get_logger(__name__)

UpperCamelCase__						=			{
    '''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   a__			(       __a  ):
						snake_case__             = '''marian'''
						snake_case__             = ['''past_key_values''']
						snake_case__             = {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}





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




											"""simple docstring"""







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




class   a__			(       __a  ):





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




											"""simple docstring"""







											if self.task in ["default", "seq2seq-lm"]:
																_lowerCAmelCase:Union[str, Any]									=  OrderedDict(
																    [
																        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
																        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
																    ])

																if self.use_past:
																					_lowerCAmelCase:Dict									=  {0: '''batch'''}
																					_lowerCAmelCase:Optional[int]									=  {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
																else:
																					_lowerCAmelCase:Union[str, Any]									=  {0: '''batch''', 1: '''decoder_sequence'''}
																					_lowerCAmelCase:Union[str, Any]									=  {0: '''batch''', 1: '''decoder_sequence'''}

																if self.use_past:
																					self.fill_with_past_key_values_(snake_case__     ,direction='''inputs''')
											elif self.task == "causal-lm":
																# TODO: figure this case out.
																_lowerCAmelCase:Dict									=  OrderedDict(
																    [
																        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
																        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
																    ])
																if self.use_past:
																					_lowerCAmelCase							,   _lowerCAmelCase:Dict									=  self.num_layers
																					for i in range(snake_case__):
																										_lowerCAmelCase:Union[str, Any]									=  {0: '''batch''', 2: '''past_sequence + sequence'''}
																										_lowerCAmelCase:Optional[Any]									=  {0: '''batch''', 2: '''past_sequence + sequence'''}
											else:
																_lowerCAmelCase:Optional[Any]									=  OrderedDict(
																    [
																        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
																        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
																        ('''decoder_input_ids''', {0: '''batch''', 1: '''decoder_sequence'''}),
																        ('''decoder_attention_mask''', {0: '''batch''', 1: '''decoder_sequence'''}),
																    ])

											return common_inputs





						@property
						# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
						def       __UpperCamelCase     (							self      :	Union[str, Any])						->       Optional[Any]:




											"""simple docstring"""







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





						def       __UpperCamelCase     (							self      :	int     ,a__      :	PreTrainedTokenizer     ,a__      :	int = -1     ,a__      :	int = -1     ,a__      :	bool = False     ,a__      :	Optional[TensorType] = None     ,)						->       Optional[Any]:




											"""simple docstring"""







											_lowerCAmelCase:Optional[Any]									=  self._generate_dummy_inputs_for_encoder_and_decoder(
											    snake_case__     ,snake_case__     ,snake_case__     ,snake_case__     ,snake_case__)

											# Generate decoder inputs
											_lowerCAmelCase:Optional[Any]									=  seq_length if not self.use_past else 1
											_lowerCAmelCase:Tuple									=  self._generate_dummy_inputs_for_encoder_and_decoder(
											    snake_case__     ,snake_case__     ,snake_case__     ,snake_case__     ,snake_case__)
											_lowerCAmelCase:Tuple									=  {F'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
											_lowerCAmelCase:int									=  dict(**snake_case__     ,**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:Tuple									=  common_inputs['''input_ids'''].shape
																_lowerCAmelCase:str									=  common_inputs['''decoder_input_ids'''].shape[1]
																_lowerCAmelCase							,   _lowerCAmelCase:List[Any]									=  self.num_attention_heads
																_lowerCAmelCase:str									=  (
																    batch,
																    num_encoder_attention_heads,
																    encoder_seq_length,
																    self._config.hidden_size // num_encoder_attention_heads,
																)
																_lowerCAmelCase:List[Any]									=  decoder_seq_length + 3
																_lowerCAmelCase:Optional[Any]									=  (
																    batch,
																    num_decoder_attention_heads,
																    decoder_past_length,
																    self._config.hidden_size // num_decoder_attention_heads,
																)

																_lowerCAmelCase:Any									=  torch.cat(
																    [common_inputs['''decoder_attention_mask'''], torch.ones(snake_case__     ,snake_case__)]     ,dim=1)

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

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





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




											"""simple docstring"""







											_lowerCAmelCase:str									=  self._generate_dummy_inputs_for_encoder_and_decoder(
											    snake_case__     ,snake_case__     ,snake_case__     ,snake_case__     ,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:int									=  common_inputs['''input_ids'''].shape
																# Not using the same length for past_key_values
																_lowerCAmelCase:Tuple									=  seqlen + 2
																_lowerCAmelCase							,   _lowerCAmelCase:List[Any]									=  self.num_layers
																_lowerCAmelCase							,   _lowerCAmelCase:List[Any]									=  self.num_attention_heads
																_lowerCAmelCase:Dict									=  (
																    batch,
																    num_encoder_attention_heads,
																    past_key_values_length,
																    self._config.hidden_size // num_encoder_attention_heads,
																)

																_lowerCAmelCase:int									=  common_inputs['''attention_mask'''].dtype
																_lowerCAmelCase:str									=  torch.cat(
																    [common_inputs['''attention_mask'''], torch.ones(snake_case__     ,snake_case__     ,dtype=snake_case__)]     ,dim=1)
																_lowerCAmelCase:Tuple									=  [
																    (torch.zeros(snake_case__), torch.zeros(snake_case__)) for _ in range(snake_case__)
																]
											return common_inputs





						def       __UpperCamelCase     (							self      :	List[Any]     ,a__      :	PreTrainedTokenizer     ,a__      :	int = -1     ,a__      :	int = -1     ,a__      :	bool = False     ,a__      :	Optional[TensorType] = None     ,)						->       int:




											"""simple docstring"""







											_lowerCAmelCase:Dict									=  compute_effective_axis_dimension(
											    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:Optional[int]									=  tokenizer.num_special_tokens_to_add(snake_case__)
											_lowerCAmelCase:Any									=  compute_effective_axis_dimension(
											    snake_case__     ,fixed_dimension=OnnxConfig.default_fixed_sequence     ,num_token_to_add=snake_case__)

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





						def       __UpperCamelCase     (							self      :	int     ,a__      :	PreTrainedTokenizer     ,a__      :	int = -1     ,a__      :	int = -1     ,a__      :	bool = False     ,a__      :	Optional[TensorType] = None     ,)						->       Dict:




											"""simple docstring"""







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

											else:
																_lowerCAmelCase:Dict									=  self._generate_dummy_inputs_for_causal_lm(
																    snake_case__     ,batch_size=snake_case__     ,seq_length=snake_case__     ,is_pair=snake_case__     ,framework=snake_case__)

											return common_inputs





						def       __UpperCamelCase     (							self      :	Optional[Any]     ,a__      :	Tuple     ,a__      :	List[str]     ,a__      :	List[Any]     ,a__      :	Tuple)						->       Tuple:




											"""simple docstring"""







											if self.task in ["default", "seq2seq-lm"]:
																_lowerCAmelCase:Any									=  super()._flatten_past_key_values_(snake_case__     ,snake_case__     ,snake_case__     ,snake_case__)
											else:
																_lowerCAmelCase:Dict									=  super(snake_case__     ,self)._flatten_past_key_values_(
																    snake_case__     ,snake_case__     ,snake_case__     ,snake_case__)







						@property
						def       __UpperCamelCase     (							self      :	Any)						->       Any:




											"""simple docstring"""







											return 1E-4












"""simple docstring"""






# NOTE: This file is deprecated and will be removed in a future version.
# It only exists so that temporarely `from diffusers.pipelines import DiffusionPipeline` works

from ...utils import deprecate
from ..controlnet.pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline  # noqa: F401


deprecate(
    '''stable diffusion controlnet''',
    '''0.22.0''',
    '''Importing `FlaxStableDiffusionControlNetPipeline` from diffusers.pipelines.stable_diffusion.flax_pipeline_stable_diffusion_controlnet is deprecated. Please import `from diffusers import FlaxStableDiffusionControlNetPipeline` instead.''',
    standard_warn=False,
    stacklevel=3,
)






