


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


__magic_name__   :   List[str]  							=logging.get_logger(__name__)

__magic_name__   :   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 		UpperCamelCase_		(					A   ):





						"""simple docstring"""




						UpperCAmelCase__	:       Optional[Any]         =     '''blenderbot'''
						UpperCAmelCase__	:       Dict         =     ['''past_key_values''']
						UpperCAmelCase__	:       Any         =     {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}
						def __init__( self				:					Dict	,				_lowerCamelCase				:					str=80_08	,				_lowerCamelCase				:					Dict=1_28	,				_lowerCamelCase				:					Tuple=2	,				_lowerCamelCase				:					Dict=1_02_40	,				_lowerCamelCase				:					Any=32	,				_lowerCamelCase				:					Dict=24	,				_lowerCamelCase				:					Tuple=1_02_40	,				_lowerCamelCase				:					List[str]=32	,				_lowerCamelCase				:					Optional[Any]=0.0	,				_lowerCamelCase				:					List[Any]=0.0	,				_lowerCamelCase				:					int=True	,				_lowerCamelCase				:					Dict=True	,				_lowerCamelCase				:					str="gelu"	,				_lowerCamelCase				:					Any=25_60	,				_lowerCamelCase				:					int=0.1	,				_lowerCamelCase				:					Optional[Any]=0.0	,				_lowerCamelCase				:					Union[str, Any]=0.0	,				_lowerCamelCase				:					Optional[int]=0.02	,				_lowerCamelCase				:					Tuple=1	,				_lowerCamelCase				:					Optional[Any]=False	,				_lowerCamelCase				:					List[Any]=0	,				_lowerCamelCase				:					Any=1	,				_lowerCamelCase				:					Optional[int]=2	,				_lowerCamelCase				:					int=3	,				_lowerCamelCase				:					Tuple=2	,				**_lowerCamelCase				:					List[Any]	,				)							->					str:
										__magic_name__	  = vocab_size
										__magic_name__	  = max_position_embeddings
										__magic_name__	  = d_model
										__magic_name__	  = encoder_ffn_dim
										__magic_name__	  = encoder_layers
										__magic_name__	  = encoder_attention_heads
										__magic_name__	  = decoder_ffn_dim
										__magic_name__	  = decoder_layers
										__magic_name__	  = decoder_attention_heads
										__magic_name__	  = dropout
										__magic_name__	  = attention_dropout
										__magic_name__	  = activation_dropout
										__magic_name__	  = activation_function
										__magic_name__	  = init_std
										__magic_name__	  = encoder_layerdrop
										__magic_name__	  = decoder_layerdrop
										__magic_name__	  = use_cache
										__magic_name__	  = encoder_layers
										__magic_name__	  = scale_embedding  # scale factor will be sqrt(d_model) if True

										super().__init__(
										    pad_token_id=_lowerCamelCase	,				bos_token_id=_lowerCamelCase	,				eos_token_id=_lowerCamelCase	,				is_encoder_decoder=_lowerCamelCase	,				decoder_start_token_id=_lowerCamelCase	,				encoder_no_repeat_ngram_size=_lowerCamelCase	,				forced_eos_token_id=_lowerCamelCase	,				**_lowerCamelCase	,				)






class 		UpperCamelCase_		(					A   ):





						"""simple docstring"""




						@property
						def 					__A					( self				:					str  )							->					Mapping[str, Mapping[int, str]]:
										if self.task in ["default", "seq2seq-lm"]:
														__magic_name__	  = OrderedDict(
														    [
														        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
														        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
														    ]  )
														if self.use_past:
																		__magic_name__	  = {0: "batch"}
																		__magic_name__	  = {0: "batch", 1: "past_decoder_sequence + sequence"}
														else:
																		__magic_name__	  = {0: "batch", 1: "decoder_sequence"}
																		__magic_name__	  = {0: "batch", 1: "decoder_sequence"}
														if self.use_past:
																		self.fill_with_past_key_values_(_lowerCamelCase	,				direction="inputs"  )
										elif self.task == "causal-lm":
														__magic_name__	  = OrderedDict(
														    [
														        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
														        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
														    ]  )
														if self.use_past:
																		__magic_name__  ,      __magic_name__	  = self.num_layers
																		for i in range(_lowerCamelCase  ):
																						__magic_name__	  = {0: "batch", 2: "past_sequence + sequence"}
																						__magic_name__	  = {0: "batch", 2: "past_sequence + sequence"}
										else:
														__magic_name__	  = 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 					__A					( self				:					Optional[int]  )							->					Mapping[str, Mapping[int, str]]:
										if self.task in ["default", "seq2seq-lm"]:
														__magic_name__	  = super().outputs
										else:
														__magic_name__	  = super(_lowerCamelCase	,				self  ).outputs
														if self.use_past:
																		__magic_name__  ,      __magic_name__	  = self.num_layers
																		for i in range(_lowerCamelCase  ):
																						__magic_name__	  = {0: "batch", 2: "past_sequence + sequence"}
																						__magic_name__	  = {0: "batch", 2: "past_sequence + sequence"}
										return common_outputs
						def 					__A					( self				:					List[Any]	,				_lowerCamelCase				:					PreTrainedTokenizer	,				_lowerCamelCase				:					int = -1	,				_lowerCamelCase				:					int = -1	,				_lowerCamelCase				:					bool = False	,				_lowerCamelCase				:					Optional[TensorType] = None	,				)							->					Mapping[str, Any]:
										__magic_name__	  = self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
										    _lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase  )
										# Generate decoder inputs
										__magic_name__	  = seq_length if not self.use_past else 1
										__magic_name__	  = self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
										    _lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase  )
										__magic_name__	  = {f'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
										__magic_name__	  = dict(**_lowerCamelCase	,				**_lowerCamelCase  )

										if self.use_past:
														if not is_torch_available():
																		raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."  )
														else:
																		import torch
														__magic_name__  ,      __magic_name__	  = common_inputs["input_ids"].shape
														__magic_name__	  = common_inputs["decoder_input_ids"].shape[1]
														__magic_name__  ,      __magic_name__	  = self.num_attention_heads
														__magic_name__	  = (
														    batch,
														    num_encoder_attention_heads,
														    encoder_seq_length,
														    self._config.hidden_size // num_encoder_attention_heads,
														)
														__magic_name__	  = decoder_seq_length
														__magic_name__	  = (
														    batch,
														    num_decoder_attention_heads,
														    decoder_past_length,
														    self._config.hidden_size // num_decoder_attention_heads,
														)
														__magic_name__	  = torch.cat(
														    [common_inputs["decoder_attention_mask"], torch.ones(_lowerCamelCase	,				_lowerCamelCase  )]	,				dim=1  )
														__magic_name__	  = []
														__magic_name__  ,      __magic_name__	  = self.num_layers

														for _ in range(_lowerCamelCase  ):
																		common_inputs["past_key_values"].append(
																		    (
																		        torch.zeros(_lowerCamelCase  ),
																		        torch.zeros(_lowerCamelCase  ),
																		        torch.zeros(_lowerCamelCase  ),
																		        torch.zeros(_lowerCamelCase  ),
																		    )  )
										return common_inputs
						def 					__A					( self				:					str	,				_lowerCamelCase				:					PreTrainedTokenizer	,				_lowerCamelCase				:					int = -1	,				_lowerCamelCase				:					int = -1	,				_lowerCamelCase				:					bool = False	,				_lowerCamelCase				:					Optional[TensorType] = None	,				)							->					Mapping[str, Any]:
										__magic_name__	  = self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
										    _lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase  )

										if self.use_past:
														if not is_torch_available():
																		raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."  )
														else:
																		import torch
														__magic_name__  ,      __magic_name__	  = common_inputs["input_ids"].shape
														__magic_name__	  = seqlen
														__magic_name__  ,      __magic_name__	  = self.num_layers
														__magic_name__  ,      __magic_name__	  = self.num_attention_heads
														__magic_name__	  = (
														    batch,
														    num_encoder_attention_heads,
														    past_key_values_length,
														    self._config.hidden_size // num_encoder_attention_heads,
														)
														__magic_name__	  = common_inputs["attention_mask"].dtype
														__magic_name__	  = torch.cat(
														    [common_inputs["attention_mask"], torch.ones(_lowerCamelCase	,				_lowerCamelCase	,				dtype=_lowerCamelCase  )]	,				dim=1  )
														__magic_name__	  = [
														    (torch.zeros(_lowerCamelCase  ), torch.zeros(_lowerCamelCase  )) for _ in range(_lowerCamelCase  )
														]
										return common_inputs
						def 					__A					( self				:					Dict	,				_lowerCamelCase				:					PreTrainedTokenizer	,				_lowerCamelCase				:					int = -1	,				_lowerCamelCase				:					int = -1	,				_lowerCamelCase				:					bool = False	,				_lowerCamelCase				:					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
										__magic_name__	  = compute_effective_axis_dimension(
										    _lowerCamelCase	,				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
										__magic_name__	  = tokenizer.num_special_tokens_to_add(_lowerCamelCase  )
										__magic_name__	  = compute_effective_axis_dimension(
										    _lowerCamelCase	,				fixed_dimension=OnnxConfig.default_fixed_sequence	,				num_token_to_add=_lowerCamelCase  )

										# Generate dummy inputs according to compute batch and sequence
										__magic_name__	  = [" ".join([tokenizer.unk_token]  ) * seq_length] * batch_size
										__magic_name__	  = dict(tokenizer(_lowerCamelCase	,				return_tensors=_lowerCamelCase  )  )
										return common_inputs
						def 					__A					( self				:					Optional[Any]	,				_lowerCamelCase				:					PreTrainedTokenizer	,				_lowerCamelCase				:					int = -1	,				_lowerCamelCase				:					int = -1	,				_lowerCamelCase				:					bool = False	,				_lowerCamelCase				:					Optional[TensorType] = None	,				)							->					Mapping[str, Any]:
										if self.task in ["default", "seq2seq-lm"]:
														__magic_name__	  = self._generate_dummy_inputs_for_default_and_seqaseq_lm(
														    _lowerCamelCase	,				batch_size=_lowerCamelCase	,				seq_length=_lowerCamelCase	,				is_pair=_lowerCamelCase	,				framework=_lowerCamelCase  )

										elif self.task == "causal-lm":
														__magic_name__	  = self._generate_dummy_inputs_for_causal_lm(
														    _lowerCamelCase	,				batch_size=_lowerCamelCase	,				seq_length=_lowerCamelCase	,				is_pair=_lowerCamelCase	,				framework=_lowerCamelCase  )
										else:
														__magic_name__	  = self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
														    _lowerCamelCase	,				batch_size=_lowerCamelCase	,				seq_length=_lowerCamelCase	,				is_pair=_lowerCamelCase	,				framework=_lowerCamelCase  )

										return common_inputs
						def 					__A					( self				:					List[str]	,				_lowerCamelCase				:					int	,				_lowerCamelCase				:					Dict	,				_lowerCamelCase				:					List[str]	,				_lowerCamelCase				:					Tuple  )							->					List[str]:
										if self.task in ["default", "seq2seq-lm"]:
														__magic_name__	  = super()._flatten_past_key_values_(_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase  )
										else:
														__magic_name__	  = super(_lowerCamelCase	,				self  )._flatten_past_key_values_(
														    _lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase	,				_lowerCamelCase  )

						def 					__A					( self				:					Optional[Any]	,				_lowerCamelCase				:					Mapping[str, Mapping[int, str]]	,				_lowerCamelCase				:					str  )							->					List[Any]:
										if direction not in ["inputs", "outputs"]:
														raise ValueError(f'direction must either be "inputs" or "outputs", but {direction} was given'  )

										__magic_name__	  = "past_key_values" if direction == "inputs" else "present"
										__magic_name__  ,      __magic_name__	  = self.num_layers

										__magic_name__	  = "past_encoder_sequence"
										__magic_name__	  = "past_decoder_sequence" if direction == "inputs" else "past_decoder_sequence + sequence"

										for i in range(_lowerCamelCase  ):
														__magic_name__	  = {0: "batch", 2: decoder_sequence}
														__magic_name__	  = {0: "batch", 2: decoder_sequence}
														__magic_name__	  = {0: "batch", 2: encoder_sequence}
														__magic_name__	  = {0: "batch", 2: encoder_sequence}







'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


__magic_name__   :   List[Any]  							={'configuration_yoso': ['YOSO_PRETRAINED_CONFIG_ARCHIVE_MAP', 'YosoConfig']}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__magic_name__   :   Union[str, Any]  							=[
						    'YOSO_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'YosoForMaskedLM',
						    'YosoForMultipleChoice',
						    'YosoForQuestionAnswering',
						    'YosoForSequenceClassification',
						    'YosoForTokenClassification',
						    'YosoLayer',
						    'YosoModel',
						    'YosoPreTrainedModel',
						]


if TYPE_CHECKING:
						from .configuration_yoso import YOSO_PRETRAINED_CONFIG_ARCHIVE_MAP, YosoConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_yoso import (
												    YOSO_PRETRAINED_MODEL_ARCHIVE_LIST,
												    YosoForMaskedLM,
												    YosoForMultipleChoice,
												    YosoForQuestionAnswering,
												    YosoForSequenceClassification,
												    YosoForTokenClassification,
												    YosoLayer,
												    YosoModel,
												    YosoPreTrainedModel,
												)


else:
						import sys

						__magic_name__   :   Optional[int]  							=_LazyModule(__name__, globals()['__file__'], _import_structure)



