



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


__SCREAMING_SNAKE_CASE     =	logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE     =	{
    """facebook/mbart-large-cc25""": """https://huggingface.co/facebook/mbart-large-cc25/resolve/main/config.json""",
    # See all MBART models at https://huggingface.co/models?filter=mbart
}

class 						lowerCamelCase_     (			__UpperCamelCase    ):






						'''simple docstring'''
						a__ =	"mbart"
						a__ =	["past_key_values"]
						a__ =	{"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}







						def __init__(						self   :      Union[str, Any]						,						__lowerCamelCase   :      Optional[Any]=5_02_65						,						__lowerCamelCase   :      Union[str, Any]=10_24						,						__lowerCamelCase   :      Optional[Any]=12						,						__lowerCamelCase   :      Any=40_96						,						__lowerCamelCase   :      Dict=16						,						__lowerCamelCase   :      List[Any]=12						,						__lowerCamelCase   :      Optional[int]=40_96						,						__lowerCamelCase   :      List[Any]=16						,						__lowerCamelCase   :      Union[str, Any]=0.0						,						__lowerCamelCase   :      Tuple=0.0						,						__lowerCamelCase   :      Any=True						,						__lowerCamelCase   :      Optional[int]=True						,						__lowerCamelCase   :      Tuple="gelu"						,						__lowerCamelCase   :      Dict=10_24						,						__lowerCamelCase   :      int=0.1						,						__lowerCamelCase   :      List[str]=0.0						,						__lowerCamelCase   :      Union[str, Any]=0.0						,						__lowerCamelCase   :      Union[str, Any]=0.02						,						__lowerCamelCase   :      Tuple=0.0						,						__lowerCamelCase   :      Optional[Any]=False						,						__lowerCamelCase   :      Union[str, Any]=1						,						__lowerCamelCase   :      str=0						,						__lowerCamelCase   :      Any=2						,						__lowerCamelCase   :      Union[str, Any]=2						,						**__lowerCamelCase   :      Any						,						)   ->					Optional[Any]:
									A				:       Union[str, Any]														=    vocab_size
									A				:       Optional[int]														=    max_position_embeddings
									A				:       Dict														=    d_model
									A				:       Tuple														=    encoder_ffn_dim
									A				:       int														=    encoder_layers
									A				:       Union[str, Any]														=    encoder_attention_heads
									A				:       int														=    decoder_ffn_dim
									A				:       Optional[Any]														=    decoder_layers
									A				:       Optional[int]														=    decoder_attention_heads
									A				:       Any														=    dropout
									A				:       Any														=    attention_dropout
									A				:       Union[str, Any]														=    activation_dropout
									A				:       str														=    activation_function
									A				:       Tuple														=    init_std
									A				:       Optional[Any]														=    encoder_layerdrop
									A				:       Optional[int]														=    decoder_layerdrop
									A				:       Optional[int]														=    classifier_dropout
									A				:       Optional[int]														=    use_cache
									A				:       List[str]														=    encoder_layers
									A				:       int														=    scale_embedding  # scale factor will be sqrt(d_model) if True
									super().__init__(
									    pad_token_id=a_						,						bos_token_id=a_						,						eos_token_id=a_						,						is_encoder_decoder=a_						,						forced_eos_token_id=a_						,						**a_						,						)







class 						lowerCamelCase_     (			__UpperCamelCase    ):






						'''simple docstring'''







						@property
						def       SCREAMING_SNAKE_CASE__		(						self   :      Dict			)   ->					int:





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

												if self.use_past:
															A				:       List[Any]														=    {0: '''batch'''}
															A				:       Optional[Any]														=    {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
												else:
															A				:       Any														=    {0: '''batch''', 1: '''decoder_sequence'''}
															A				:       str														=    {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.
												A				:       Tuple														=    OrderedDict(
												    [
												        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
												        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
												    ]			)
												if self.use_past:
															A				:       Dict														=    self.num_layers
															for i in range(a_			):
																		A				:       Any														=    {0: '''batch''', 2: '''past_sequence + sequence'''}
																		A				:       Tuple														=    {0: '''batch''', 2: '''past_sequence + sequence'''}
									else:
												A				:       Union[str, 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
						def       SCREAMING_SNAKE_CASE__		(						self   :      List[Any]			)   ->					int:





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







						def       SCREAMING_SNAKE_CASE__		(						self   :      Dict						,						__lowerCamelCase   :      PreTrainedTokenizer						,						__lowerCamelCase   :      int = -1						,						__lowerCamelCase   :      int = -1						,						__lowerCamelCase   :      bool = False						,						__lowerCamelCase   :      Optional[TensorType] = None						,						)   ->					str:
									A				:       str														=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
									    a_						,						a_						,						a_						,						a_						,						a_			)

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

												A				:       Dict														=    torch.cat(
												    [common_inputs["decoder_attention_mask"], torch.ones(a_						,						a_			)]						,						dim=1			)

												A				:       Union[str, Any]														=    []
												# If the number of encoder and decoder layers are present in the model configuration, both are considered
												A				:       str														=    self.num_layers
												A				:       int														=    min(a_						,						a_			)
												A				:       Optional[int]														=    max(a_						,						a_			) - min_num_layers
												A				:       List[Any]														=    '''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.
												A				:       List[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       SCREAMING_SNAKE_CASE__		(						self   :      Optional[int]						,						__lowerCamelCase   :      PreTrainedTokenizer						,						__lowerCamelCase   :      int = -1						,						__lowerCamelCase   :      int = -1						,						__lowerCamelCase   :      bool = False						,						__lowerCamelCase   :      Optional[TensorType] = None						,						)   ->					List[Any]:
									A				:       Optional[int]														=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
									    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
												A				:       Optional[int]														=    common_inputs['''input_ids'''].shape
												# Not using the same length for past_key_values
												A				:       Any														=    seqlen + 2
												A				:       List[Any]														=    self.num_layers
												A				:       List[str]														=    self.num_attention_heads
												A				:       Dict														=    (
												    batch,
												    num_encoder_attention_heads,
												    past_key_values_length,
												    self._config.hidden_size // num_encoder_attention_heads,
												)

												A				:       Optional[int]														=    common_inputs['''attention_mask'''].dtype
												A				:       int														=    torch.cat(
												    [common_inputs["attention_mask"], torch.ones(a_						,						a_						,						dtype=a_			)]						,						dim=1			)
												A				:       Any														=    [
												    (torch.zeros(a_			), torch.zeros(a_			)) for _ in range(a_			)
												]
									return common_inputs







						def       SCREAMING_SNAKE_CASE__		(						self   :      Any						,						__lowerCamelCase   :      PreTrainedTokenizer						,						__lowerCamelCase   :      int = -1						,						__lowerCamelCase   :      int = -1						,						__lowerCamelCase   :      bool = False						,						__lowerCamelCase   :      Optional[TensorType] = None						,						)   ->					Optional[int]:
									A				:       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
									A				:       str														=    tokenizer.num_special_tokens_to_add(a_			)
									A				:       List[Any]														=    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
									A				:       int														=    [''' '''.join([tokenizer.unk_token]			) * seq_length] * batch_size
									A				:       List[Any]														=    dict(tokenizer(a_						,						return_tensors=a_			)			)
									return common_inputs







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





									if self.task in ["default", "seq2seq-lm"]:
												A				:       List[str]														=    self._generate_dummy_inputs_for_default_and_seqaseq_lm(
												    a_						,						batch_size=a_						,						seq_length=a_						,						is_pair=a_						,						framework=a_			)

									elif self.task == "causal-lm":
												A				:       str														=    self._generate_dummy_inputs_for_causal_lm(
												    a_						,						batch_size=a_						,						seq_length=a_						,						is_pair=a_						,						framework=a_			)
									else:
												A				:       Optional[int]														=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
												    a_						,						batch_size=a_						,						seq_length=a_						,						is_pair=a_						,						framework=a_			)

									return common_inputs







						def       SCREAMING_SNAKE_CASE__		(						self   :      Union[str, Any]						,						__lowerCamelCase   :      Dict						,						__lowerCamelCase   :      Optional[int]						,						__lowerCamelCase   :      Tuple						,						__lowerCamelCase   :      Optional[Any]			)   ->					Optional[int]:





									if self.task in ["default", "seq2seq-lm"]:
												A				:       int														=    super()._flatten_past_key_values_(a_						,						a_						,						a_						,						a_			)
									else:
												A				:       int														=    super(a_						,						self			)._flatten_past_key_values_(
												    a_						,						a_						,						a_						,						a_			)




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


__A       ={
    "configuration_speech_to_text_2": ["SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP", "Speech2Text2Config"],
    "processing_speech_to_text_2": ["Speech2Text2Processor"],
    "tokenization_speech_to_text_2": ["Speech2Text2Tokenizer"],
}


try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__A       =[
				    "SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST",
				    "Speech2Text2ForCausalLM",
				    "Speech2Text2PreTrainedModel",
				]


if TYPE_CHECKING:
				from .configuration_speech_to_text_a import SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextaConfig
				from .processing_speech_to_text_a import SpeechaTextaProcessor
				from .tokenization_speech_to_text_a import SpeechaTextaTokenizer

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_speech_to_text_a import (
								    SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST,
								    SpeechaTextaForCausalLM,
								    SpeechaTextaPreTrainedModel,
								)

else:
				import sys

				__A       =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





