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


_lowercase											=			logging.get_logger(__name__)

_lowercase											=			{
    '''google/bigbird-pegasus-large-arxiv''': (
        '''https://huggingface.co/google/bigbird-pegasus-large-arxiv/resolve/main/config.json'''
    ),
    '''google/bigbird-pegasus-large-pubmed''': (
        '''https://huggingface.co/google/bigbird-pegasus-large-pubmed/resolve/main/config.json'''
    ),
    '''google/bigbird-pegasus-large-bigpatent''': (
        '''https://huggingface.co/google/bigbird-pegasus-large-bigpatent/resolve/main/config.json'''
    ),
    # See all BigBirdPegasus models at https://huggingface.co/models?filter=bigbird_pegasus
}







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						_lowerCamelCase:      Dict =      '''bigbird_pegasus'''
						_lowerCamelCase:      List[Any] =      ['''past_key_values''']
						_lowerCamelCase:      Union[str, Any] =      {
						    '''num_attention_heads''': '''encoder_attention_heads''',
						    '''hidden_size''': '''d_model''',
						    '''attention_probs_dropout_prob''': '''attention_dropout''',
						}


						def __init__(	self       : Union[str, Any]					,A_       : Tuple=9_6103					,A_       : Any=4096					,A_       : Union[str, Any]=16					,A_       : List[Any]=4096					,A_       : str=16					,A_       : Optional[Any]=16					,A_       : Optional[Any]=4096					,A_       : str=16					,A_       : Optional[int]=0.0					,A_       : List[Any]=0.0					,A_       : Dict=True					,A_       : List[str]=True					,A_       : Union[str, Any]="gelu_new"					,A_       : int=1024					,A_       : Optional[int]=0.1					,A_       : Dict=0.0					,A_       : Union[str, Any]=0.0					,A_       : Union[str, Any]=0.02					,A_       : Tuple=2					,A_       : Dict=0.0					,A_       : int=True					,A_       : str=0					,A_       : int=2					,A_       : List[str]=1					,A_       : Tuple="block_sparse"					,A_       : Any=64					,A_       : Any=3					,A_       : Union[str, Any]=False					,**A_       : Union[str, Any]					,)       ->				List[str]:
							A  				=				vocab_size
							A  				=				max_position_embeddings
							A  				=				d_model
							A  				=				encoder_ffn_dim
							A  				=				encoder_layers
							A  				=				encoder_attention_heads
							A  				=				decoder_ffn_dim
							A  				=				decoder_layers
							A  				=				decoder_attention_heads
							A  				=				dropout
							A  				=				attention_dropout
							A  				=				activation_dropout
							A  				=				activation_function
							A  				=				init_std
							A  				=				encoder_layerdrop
							A  				=				decoder_layerdrop
							A  				=				classifier_dropout
							A  				=				use_cache
							A  				=				encoder_layers
							A  				=				scale_embedding  # scale factor will be sqrt(d_model) if True

							# extra config
							A  				=				attention_type
							A  				=				block_size
							A  				=				num_random_blocks
							A  				=				use_bias

							super().__init__(
							    pad_token_id=A_					,bos_token_id=A_					,eos_token_id=A_					,is_encoder_decoder=A_					,decoder_start_token_id=A_					,**A_					,)







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						@property
						def   _SCREAMING_SNAKE_CASE (	self       : int )       ->				Mapping[str, Mapping[int, str]]:
							if self.task in ["default", "seq2seq-lm"]:
								A  				=				OrderedDict(
								    [
								        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
								        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
								    ] )

								if self.use_past:
									A  				=				{0: 'batch'}
									A  				=				{0: 'batch', 1: 'past_decoder_sequence + sequence'}
								else:
									A  				=				{0: 'batch', 1: 'decoder_sequence'}
									A  				=				{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  				=				OrderedDict(
								    [
								        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
								        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
								    ] )
								if self.use_past:
									A				, A  				=				self.num_layers
									for i in range(A_ ):
										A  				=				{0: 'batch', 2: 'past_sequence + sequence'}
										A  				=				{0: 'batch', 2: 'past_sequence + sequence'}
							else:
								A  				=				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[str] )       ->				Mapping[str, Mapping[int, str]]:
							if self.task in ["default", "seq2seq-lm"]:
								A  				=				super().outputs
							else:
								A  				=				super(A_					,self ).outputs
								if self.use_past:
									A				, A  				=				self.num_layers
									for i in range(A_ ):
										A  				=				{0: 'batch', 2: 'past_sequence + sequence'}
										A  				=				{0: 'batch', 2: 'past_sequence + sequence'}
							return common_outputs


						def   _SCREAMING_SNAKE_CASE (	self       : Optional[int]					,A_       : PreTrainedTokenizer					,A_       : int = -1					,A_       : int = -1					,A_       : bool = False					,A_       : Optional[TensorType] = None					,)       ->				Mapping[str, Any]:
							A  				=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    A_					,A_					,A_					,A_					,A_ )

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

								A  				=				torch.cat(
								    [common_inputs['decoder_attention_mask'], torch.ones(A_					,A_ )]					,dim=1 )

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

								A  				=				common_inputs['attention_mask'].dtype
								A  				=				torch.cat(
								    [common_inputs['attention_mask'], torch.ones(A_					,A_					,dtype=A_ )]					,dim=1 )
								A  				=				[
								    (torch.zeros(A_ ), torch.zeros(A_ )) for _ in range(A_ )
								]
							return common_inputs


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


						def   _SCREAMING_SNAKE_CASE (	self       : int					,A_       : PreTrainedTokenizer					,A_       : int = -1					,A_       : int = -1					,A_       : bool = False					,A_       : Optional[TensorType] = None					,)       ->				Mapping[str, Any]:
							if self.task in ["default", "seq2seq-lm"]:
								A  				=				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  				=				self._generate_dummy_inputs_for_causal_lm(
								    A_					,batch_size=A_					,seq_length=A_					,is_pair=A_					,framework=A_ )
							else:
								A  				=				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       : List[str]					,A_       : Optional[Any]					,A_       : Optional[Any]					,A_       : List[Any]					,A_       : Dict )       ->				Dict:
							if self.task in ["default", "seq2seq-lm"]:
								A  				=				super()._flatten_past_key_values_(A_					,A_					,A_					,A_ )
							else:
								A  				=				super(A_					,self )._flatten_past_key_values_(
								    A_					,A_					,A_					,A_ )

"""simple docstring"""


from typing import Callable, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowercase											=			logging.get_logger(__name__)

_lowercase											=			{
    '''microsoft/prophetnet-large-uncased''': (
        '''https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json'''
    ),
}







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						_lowerCamelCase:      int =      '''prophetnet'''
						_lowerCamelCase:      Optional[Any] =      ['''past_key_values''']
						_lowerCamelCase:      Dict =      {
						    '''num_attention_heads''': '''num_encoder_attention_heads''',
						}


						def __init__(	self       : Tuple					,A_       : Optional[float] = 0.1					,A_       : Optional[Union[str, Callable]] = "gelu"					,A_       : Optional[int] = 3_0522					,A_       : Optional[int] = 1024					,A_       : Optional[int] = 4096					,A_       : Optional[int] = 12					,A_       : Optional[int] = 16					,A_       : Optional[int] = 4096					,A_       : Optional[int] = 12					,A_       : Optional[int] = 16					,A_       : Optional[float] = 0.1					,A_       : Optional[float] = 0.1					,A_       : Optional[int] = 512					,A_       : Optional[float] = 0.02					,A_       : Optional[bool] = True					,A_       : Optional[bool] = True					,A_       : Optional[int] = 0					,A_       : Optional[int] = 2					,A_       : Optional[int] = 32					,A_       : Optional[int] = 128					,A_       : Optional[bool] = False					,A_       : Optional[float] = 0.0					,A_       : Optional[bool] = True					,A_       : Optional[int] = 0					,A_       : Optional[int] = 1					,A_       : Optional[int] = 2					,**A_       : Tuple					,)       ->				Any:
							A  				=				vocab_size
							A  				=				hidden_size
							A  				=				encoder_ffn_dim
							A  				=				num_encoder_layers
							A  				=				num_encoder_attention_heads
							A  				=				decoder_ffn_dim
							A  				=				num_decoder_layers
							A  				=				num_decoder_attention_heads
							A  				=				max_position_embeddings
							A  				=				init_std  # Normal(0, this parameter)
							A  				=				activation_function

							# parameters for prophetnet
							A  				=				ngram
							A  				=				num_buckets
							A  				=				relative_max_distance
							A  				=				disable_ngram_loss
							A  				=				eps

							# 3 Types of Dropout
							A  				=				attention_dropout
							A  				=				activation_dropout
							A  				=				dropout

							A  				=				use_cache

							super().__init__(
							    pad_token_id=A_					,bos_token_id=A_					,eos_token_id=A_					,is_encoder_decoder=A_					,add_cross_attention=A_					,decoder_start_token_id=A_					,**A_					,)


						@property
						def   _SCREAMING_SNAKE_CASE (	self       : List[Any] )       ->				int:
							return self.num_encoder_layers + self.num_decoder_layers




						@num_hidden_layers.setter
						def   _SCREAMING_SNAKE_CASE (	self       : int					,A_       : Any )       ->				int:
							raise NotImplementedError(
							    'This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'
							    ' `num_decoder_layers`.' )