






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


__A		:	List[Any]      =		logging.get_logger(__name__)

__A		:	Tuple      =		{
    '''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  _UpperCAmelCase	(			_A							):
					SCREAMING_SNAKE_CASE_		:    Dict							   =       'bigbird_pegasus'
					SCREAMING_SNAKE_CASE_		:    int							   =       ['past_key_values']
					SCREAMING_SNAKE_CASE_		:    List[str]							   =       {
					    'num_attention_heads': 'encoder_attention_heads',
					    'hidden_size': 'd_model',
					    'attention_probs_dropout_prob': 'attention_dropout',
					}




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

							# extra config
							lowercase_			:			Union[str, Any]								=       attention_type
							lowercase_			:			List[str]								=       block_size
							lowercase_			:			List[Any]								=       num_random_blocks
							lowercase_			:			int								=       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  _UpperCAmelCase	(			_A							):




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



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

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



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




					def   A  (    self					:						Optional[int]   ,						A					:						Any   ,						A					:						List[str] = -1   ,						A					:						List[Any] = -1   ,						A					:						Optional[int] = False   ,						A					:						List[Any] = None   ,						)  ->  Mapping[str, Any]:
							lowercase_			:			List[Any]								=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    A   ,						A   ,						A   ,						A   ,						A       )

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

									lowercase_			:			List[str]								=       torch.cat(
									    [common_inputs['''decoder_attention_mask'''], torch.ones(A   ,						A       )]   ,						dim=1       )

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

									lowercase_			:			Dict								=       common_inputs['''attention_mask'''].dtype
									lowercase_			:			List[str]								=       torch.cat(
									    [common_inputs['''attention_mask'''], torch.ones(A   ,						A   ,						dtype=A       )]   ,						dim=1       )
									lowercase_			:			List[Any]								=       [
									    (torch.zeros(A       ), torch.zeros(A       )) for _ in range(A       )
									]
							return common_inputs




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




					def   A  (    self					:						Union[str, Any]   ,						A					:						List[Any]   ,						A					:						int = -1   ,						A					:						Tuple = -1   ,						A					:						Tuple = False   ,						A					:						Union[str, Any] = None   ,						)  ->  Mapping[str, Any]:



							if self.task in ["default", "seq2seq-lm"]:
									lowercase_			:			Optional[int]								=       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":
									lowercase_			:			Optional[Any]								=       self._generate_dummy_inputs_for_causal_lm(
									    A   ,						batch_size=A   ,						seq_length=A   ,						is_pair=A   ,						framework=A       )
							else:
									lowercase_			:			Any								=       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   A  (    self					:						Union[str, Any]   ,						A					:						List[Any]   ,						A					:						str   ,						A					:						Tuple   ,						A					:						Tuple       )  ->  Optional[int]:



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











"""simple docstring"""



from typing import TYPE_CHECKING

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


__A		:	Any      =		{
    '''configuration_markuplm''': ['''MARKUPLM_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''MarkupLMConfig'''],
    '''feature_extraction_markuplm''': ['''MarkupLMFeatureExtractor'''],
    '''processing_markuplm''': ['''MarkupLMProcessor'''],
    '''tokenization_markuplm''': ['''MarkupLMTokenizer'''],
}

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__A		:	List[str]      =		['''MarkupLMTokenizerFast''']

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__A		:	Optional[int]      =		[
						    '''MARKUPLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''MarkupLMForQuestionAnswering''',
						    '''MarkupLMForSequenceClassification''',
						    '''MarkupLMForTokenClassification''',
						    '''MarkupLMModel''',
						    '''MarkupLMPreTrainedModel''',
						]


if TYPE_CHECKING:
						from .configuration_markuplm import MARKUPLM_PRETRAINED_CONFIG_ARCHIVE_MAP, MarkupLMConfig
						from .feature_extraction_markuplm import MarkupLMFeatureExtractor
						from .processing_markuplm import MarkupLMProcessor
						from .tokenization_markuplm import MarkupLMTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_markuplm_fast import MarkupLMTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_markuplm import (
												    MARKUPLM_PRETRAINED_MODEL_ARCHIVE_LIST,
												    MarkupLMForQuestionAnswering,
												    MarkupLMForSequenceClassification,
												    MarkupLMForTokenClassification,
												    MarkupLMModel,
												    MarkupLMPreTrainedModel,
												)


else:
						import sys

						__A		:	Optional[Any]      =		_LazyModule(__name__, globals()['''__file__'''], _import_structure)



