


"""simple docstring"""






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

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


UpperCamelCase__							:int       =  logging.get_logger(__name__)

UpperCamelCase__							:Union[str, Any]       =  {
    """facebook/blenderbot-3B""": """https://huggingface.co/facebook/blenderbot-3B/resolve/main/config.json""",
    # See all Blenderbot models at https://huggingface.co/models?filter=blenderbot
}






class     A(     lowerCamelCase__		):

		"""simple docstring"""





		A         =       "blenderbot"
		A         =       ["past_key_values"]
		A         =       {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}
		def __init__(   self				,							SCREAMING_SNAKE_CASE__=80_08				,							SCREAMING_SNAKE_CASE__=1_28				,							SCREAMING_SNAKE_CASE__=2				,							SCREAMING_SNAKE_CASE__=1_02_40				,							SCREAMING_SNAKE_CASE__=32				,							SCREAMING_SNAKE_CASE__=24				,							SCREAMING_SNAKE_CASE__=1_02_40				,							SCREAMING_SNAKE_CASE__=32				,							SCREAMING_SNAKE_CASE__=0.0				,							SCREAMING_SNAKE_CASE__=0.0				,							SCREAMING_SNAKE_CASE__=True				,							SCREAMING_SNAKE_CASE__=True				,							SCREAMING_SNAKE_CASE__="gelu"				,							SCREAMING_SNAKE_CASE__=25_60				,							SCREAMING_SNAKE_CASE__=0.1				,							SCREAMING_SNAKE_CASE__=0.0				,							SCREAMING_SNAKE_CASE__=0.0				,							SCREAMING_SNAKE_CASE__=0.0_2				,							SCREAMING_SNAKE_CASE__=1				,							SCREAMING_SNAKE_CASE__=False				,							SCREAMING_SNAKE_CASE__=0				,							SCREAMING_SNAKE_CASE__=1				,							SCREAMING_SNAKE_CASE__=2				,							SCREAMING_SNAKE_CASE__=3				,							SCREAMING_SNAKE_CASE__=2				,							**SCREAMING_SNAKE_CASE__				,							)			->  str:

					"""simple docstring"""



					_UpperCamelCase				:int				    =  vocab_size
					_UpperCamelCase				:Dict				    =  max_position_embeddings
					_UpperCamelCase				:Dict				    =  d_model
					_UpperCamelCase				:List[Any]				    =  encoder_ffn_dim
					_UpperCamelCase				:Dict				    =  encoder_layers
					_UpperCamelCase				:Dict				    =  encoder_attention_heads
					_UpperCamelCase				:Union[str, Any]				    =  decoder_ffn_dim
					_UpperCamelCase				:Any				    =  decoder_layers
					_UpperCamelCase				:Dict				    =  decoder_attention_heads
					_UpperCamelCase				:List[str]				    =  dropout
					_UpperCamelCase				:List[Any]				    =  attention_dropout
					_UpperCamelCase				:List[str]				    =  activation_dropout
					_UpperCamelCase				:Dict				    =  activation_function
					_UpperCamelCase				:Any				    =  init_std
					_UpperCamelCase				:List[Any]				    =  encoder_layerdrop
					_UpperCamelCase				:Tuple				    =  decoder_layerdrop
					_UpperCamelCase				:Optional[Any]				    =  use_cache
					_UpperCamelCase				:List[Any]				    =  encoder_layers
					_UpperCamelCase				:Dict				    =  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__				,							encoder_no_repeat_ngram_size=SCREAMING_SNAKE_CASE__				,							forced_eos_token_id=SCREAMING_SNAKE_CASE__				,							**SCREAMING_SNAKE_CASE__				,							)






class     A(     lowerCamelCase__		):

		"""simple docstring"""





		@property
		def      _UpperCamelCase(   self      )			->  Mapping[str, Mapping[int, str]]:

					"""simple docstring"""



					if self.task in ["default", "seq2seq-lm"]:
								_UpperCamelCase				:Union[str, Any]				    =  OrderedDict(
								    [
								        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
								        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
								    ]      )
								if self.use_past:
											_UpperCamelCase				:Optional[int]				    =  {0: '''batch'''}
											_UpperCamelCase				:List[Any]				    =  {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
								else:
											_UpperCamelCase				:List[str]				    =  {0: '''batch''', 1: '''decoder_sequence'''}
											_UpperCamelCase				:Optional[int]				    =  {0: '''batch''', 1: '''decoder_sequence'''}
								if self.use_past:
											self.fill_with_past_key_values_(SCREAMING_SNAKE_CASE__				,							direction='''inputs'''      )
					elif self.task == "causal-lm":
								_UpperCamelCase				:Optional[int]				    =  OrderedDict(
								    [
								        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
								        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
								    ]      )
								if self.use_past:
											_UpperCamelCase    ,			_UpperCamelCase				:int				    =  self.num_layers
											for i in range(SCREAMING_SNAKE_CASE__      ):
														_UpperCamelCase				:int				    =  {0: '''batch''', 2: '''past_sequence + sequence'''}
														_UpperCamelCase				:List[Any]				    =  {0: '''batch''', 2: '''past_sequence + sequence'''}
					else:
								_UpperCamelCase				: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      )			->  Mapping[str, Mapping[int, str]]:

					"""simple docstring"""



					if self.task in ["default", "seq2seq-lm"]:
								_UpperCamelCase				:List[str]				    =  super().outputs
					else:
								_UpperCamelCase				:List[str]				    =  super(SCREAMING_SNAKE_CASE__				,							self      ).outputs
								if self.use_past:
											_UpperCamelCase    ,			_UpperCamelCase				:Optional[Any]				    =  self.num_layers
											for i in range(SCREAMING_SNAKE_CASE__      ):
														_UpperCamelCase				:Optional[int]				    =  {0: '''batch''', 2: '''past_sequence + sequence'''}
														_UpperCamelCase				:Any				    =  {0: '''batch''', 2: '''past_sequence + sequence'''}
					return common_outputs
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__ = -1				,							SCREAMING_SNAKE_CASE__ = -1				,							SCREAMING_SNAKE_CASE__ = False				,							SCREAMING_SNAKE_CASE__ = None				,							)			->  Mapping[str, Any]:

					"""simple docstring"""



					_UpperCamelCase				:Optional[Any]				    =  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
					_UpperCamelCase				:Dict				    =  seq_length if not self.use_past else 1
					_UpperCamelCase				:int				    =  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__      )
					_UpperCamelCase				:List[Any]				    =  {f"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
					_UpperCamelCase				:List[Any]				    =  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
								_UpperCamelCase    ,			_UpperCamelCase				:int				    =  common_inputs['''input_ids'''].shape
								_UpperCamelCase				:Dict				    =  common_inputs['''decoder_input_ids'''].shape[1]
								_UpperCamelCase    ,			_UpperCamelCase				:Dict				    =  self.num_attention_heads
								_UpperCamelCase				:Any				    =  (
								    batch,
								    num_encoder_attention_heads,
								    encoder_seq_length,
								    self._config.hidden_size // num_encoder_attention_heads,
								)
								_UpperCamelCase				:Tuple				    =  decoder_seq_length
								_UpperCamelCase				:int				    =  (
								    batch,
								    num_decoder_attention_heads,
								    decoder_past_length,
								    self._config.hidden_size // num_decoder_attention_heads,
								)
								_UpperCamelCase				:List[Any]				    =  torch.cat(
								    [common_inputs['''decoder_attention_mask'''], torch.ones(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )]				,							dim=1      )
								_UpperCamelCase				:int				    =  []
								_UpperCamelCase    ,			_UpperCamelCase				:int				    =  self.num_layers

								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__      ),
											    )      )
					return common_inputs
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__ = -1				,							SCREAMING_SNAKE_CASE__ = -1				,							SCREAMING_SNAKE_CASE__ = False				,							SCREAMING_SNAKE_CASE__ = None				,							)			->  Mapping[str, Any]:

					"""simple docstring"""



					_UpperCamelCase				:str				    =  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__      )

					if self.use_past:
								if not is_torch_available():
											raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''      )
								else:
											import torch
								_UpperCamelCase    ,			_UpperCamelCase				:int				    =  common_inputs['''input_ids'''].shape
								_UpperCamelCase				:str				    =  seqlen
								_UpperCamelCase    ,			_UpperCamelCase				:Optional[Any]				    =  self.num_layers
								_UpperCamelCase    ,			_UpperCamelCase				:Optional[Any]				    =  self.num_attention_heads
								_UpperCamelCase				:Optional[Any]				    =  (
								    batch,
								    num_encoder_attention_heads,
								    past_key_values_length,
								    self._config.hidden_size // num_encoder_attention_heads,
								)
								_UpperCamelCase				:Dict				    =  common_inputs['''attention_mask'''].dtype
								_UpperCamelCase				:int				    =  torch.cat(
								    [common_inputs['''attention_mask'''], torch.ones(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							dtype=SCREAMING_SNAKE_CASE__      )]				,							dim=1      )
								_UpperCamelCase				:Union[str, Any]				    =  [
								    (torch.zeros(SCREAMING_SNAKE_CASE__      ), torch.zeros(SCREAMING_SNAKE_CASE__      )) for _ in range(SCREAMING_SNAKE_CASE__      )
								]
					return common_inputs
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__ = -1				,							SCREAMING_SNAKE_CASE__ = -1				,							SCREAMING_SNAKE_CASE__ = False				,							SCREAMING_SNAKE_CASE__ = None				,							)			->  Mapping[str, Any]:

					"""simple docstring"""



					_UpperCamelCase				:Any				    =  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
					_UpperCamelCase				:Tuple				    =  tokenizer.num_special_tokens_to_add(SCREAMING_SNAKE_CASE__      )
					_UpperCamelCase				:List[Any]				    =  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
					_UpperCamelCase				:str				    =  [''' '''.join([tokenizer.unk_token]      ) * seq_length] * batch_size
					_UpperCamelCase				:int				    =  dict(tokenizer(SCREAMING_SNAKE_CASE__				,							return_tensors=SCREAMING_SNAKE_CASE__      )      )
					return common_inputs
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__ = -1				,							SCREAMING_SNAKE_CASE__ = -1				,							SCREAMING_SNAKE_CASE__ = False				,							SCREAMING_SNAKE_CASE__ = None				,							)			->  Mapping[str, Any]:

					"""simple docstring"""



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

					elif self.task == "causal-lm":
								_UpperCamelCase				:int				    =  self._generate_dummy_inputs_for_causal_lm(
								    SCREAMING_SNAKE_CASE__				,							batch_size=SCREAMING_SNAKE_CASE__				,							seq_length=SCREAMING_SNAKE_CASE__				,							is_pair=SCREAMING_SNAKE_CASE__				,							framework=SCREAMING_SNAKE_CASE__      )
					else:
								_UpperCamelCase				:Dict				    =  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
								    SCREAMING_SNAKE_CASE__				,							batch_size=SCREAMING_SNAKE_CASE__				,							seq_length=SCREAMING_SNAKE_CASE__				,							is_pair=SCREAMING_SNAKE_CASE__				,							framework=SCREAMING_SNAKE_CASE__      )

					return common_inputs
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )			->  Tuple:

					"""simple docstring"""



					if self.task in ["default", "seq2seq-lm"]:
								_UpperCamelCase				:List[str]				    =  super()._flatten_past_key_values_(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )
					else:
								_UpperCamelCase				:Optional[Any]				    =  super(SCREAMING_SNAKE_CASE__				,							self      )._flatten_past_key_values_(
								    SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )





		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )			->  Optional[int]:

					"""simple docstring"""



					if direction not in ["inputs", "outputs"]:
								raise ValueError(f"direction must either be \"inputs\" or \"outputs\", but {direction} was given"      )

					_UpperCamelCase				:int				    =  '''past_key_values''' if direction == '''inputs''' else '''present'''
					_UpperCamelCase    ,			_UpperCamelCase				:int				    =  self.num_layers

					_UpperCamelCase				:Dict				    =  '''past_encoder_sequence'''
					_UpperCamelCase				:int				    =  '''past_decoder_sequence''' if direction == '''inputs''' else '''past_decoder_sequence + sequence'''

					for i in range(SCREAMING_SNAKE_CASE__      ):
								_UpperCamelCase				:Any				    =  {0: '''batch''', 2: decoder_sequence}
								_UpperCamelCase				:Optional[int]				    =  {0: '''batch''', 2: decoder_sequence}
								_UpperCamelCase				:Union[str, Any]				    =  {0: '''batch''', 2: encoder_sequence}
								_UpperCamelCase				:List[str]				    =  {0: '''batch''', 2: encoder_sequence}





"""simple docstring"""






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

import numpy as np
import PIL

from ...utils import BaseOutput, is_invisible_watermark_available, is_torch_available, is_transformers_available






@dataclass
class     A(     lowerCamelCase__		):

		"""simple docstring"""





		A         =       42


if is_transformers_available() and is_torch_available() and is_invisible_watermark_available():
					from .pipeline_stable_diffusion_xl import StableDiffusionXLPipeline
					from .pipeline_stable_diffusion_xl_imgaimg import StableDiffusionXLImgaImgPipeline

