


'''simple docstring'''



from collections import OrderedDict
from typing import TYPE_CHECKING, Any, List, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import TensorType, logging


if TYPE_CHECKING:
	from ...onnx.config import PatchingSpec
	from ...tokenization_utils_base import PreTrainedTokenizerBase


_lowercase      :      Optional[Any]            =					logging.get_logger(__name__)

_lowercase      :      str            =					{
    """allenai/longformer-base-4096""": """https://huggingface.co/allenai/longformer-base-4096/resolve/main/config.json""",
    """allenai/longformer-large-4096""": """https://huggingface.co/allenai/longformer-large-4096/resolve/main/config.json""",
    """allenai/longformer-large-4096-finetuned-triviaqa""": (
        """https://huggingface.co/allenai/longformer-large-4096-finetuned-triviaqa/resolve/main/config.json"""
    ),
    """allenai/longformer-base-4096-extra.pos.embd.only""": (
        """https://huggingface.co/allenai/longformer-base-4096-extra.pos.embd.only/resolve/main/config.json"""
    ),
    """allenai/longformer-large-4096-extra.pos.embd.only""": (
        """https://huggingface.co/allenai/longformer-large-4096-extra.pos.embd.only/resolve/main/config.json"""
    ),
}






class 	UpperCamelCase__(       lowerCAmelCase	):
				__magic_name__    :				Any  		=	"longformer"




				def __init__(		self      :			Dict				,   lowerCAmelCase      :			Union[List[int], int] = 512				,   lowerCAmelCase      :			int = 2				,   lowerCAmelCase      :			int = 1				,   lowerCAmelCase      :			int = 0				,   lowerCAmelCase      :			int = 2				,   lowerCAmelCase      :			int = 30522				,   lowerCAmelCase      :			int = 768				,   lowerCAmelCase      :			int = 12				,   lowerCAmelCase      :			int = 12				,   lowerCAmelCase      :			int = 3072				,   lowerCAmelCase      :			str = "gelu"				,   lowerCAmelCase      :			float = 0.1				,   lowerCAmelCase      :			float = 0.1				,   lowerCAmelCase      :			int = 512				,   lowerCAmelCase      :			int = 2				,   lowerCAmelCase      :			float = 0.02				,   lowerCAmelCase      :			float = 1E-12				,   lowerCAmelCase      :			bool = False				,   **lowerCAmelCase      :			Union[str, Any]				,   )->					List[str]:

										"""simple docstring"""




										super().__init__(pad_token_id=lowerCAmelCase				,   **lowerCAmelCase				)

										UpperCAmelCase					    =     attention_window
										UpperCAmelCase					    =     sep_token_id
										UpperCAmelCase					    =     bos_token_id
										UpperCAmelCase					    =     eos_token_id
										UpperCAmelCase					    =     vocab_size
										UpperCAmelCase					    =     hidden_size
										UpperCAmelCase					    =     num_hidden_layers
										UpperCAmelCase					    =     num_attention_heads
										UpperCAmelCase					    =     hidden_act
										UpperCAmelCase					    =     intermediate_size
										UpperCAmelCase					    =     hidden_dropout_prob
										UpperCAmelCase					    =     attention_probs_dropout_prob
										UpperCAmelCase					    =     max_position_embeddings
										UpperCAmelCase					    =     type_vocab_size
										UpperCAmelCase					    =     initializer_range
										UpperCAmelCase					    =     layer_norm_eps
										UpperCAmelCase					    =     onnx_export







class 	UpperCamelCase__(       lowerCAmelCase	):




				def __init__(		self      :			List[Any]				,   lowerCAmelCase      :			"PretrainedConfig"				,   lowerCAmelCase      :			str = "default"				,   lowerCAmelCase      :			"List[PatchingSpec]" = None				)->					Tuple:

										"""simple docstring"""




										super().__init__(lowerCAmelCase				,   lowerCAmelCase				,   lowerCAmelCase				)
										UpperCAmelCase					    =     True




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

										"""simple docstring"""




										if self.task == "multiple-choice":
																UpperCAmelCase					    =     {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
										else:
																UpperCAmelCase					    =     {0: '''batch''', 1: '''sequence'''}
										return OrderedDict(
										    [
										        ('''input_ids''', dynamic_axis),
										        ('''attention_mask''', dynamic_axis),
										        ('''global_attention_mask''', dynamic_axis),
										    ]				)




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

										"""simple docstring"""




										UpperCAmelCase					    =     super().outputs
										if self.task == "default":
																UpperCAmelCase					    =     {0: '''batch'''}
										return outputs




				@property
				def 					a__(		self      :			Dict				)->					float:

										"""simple docstring"""




										return 1E-4




				@property
				def 					a__(		self      :			Tuple				)->					int:

										"""simple docstring"""




										return max(super().default_onnx_opset				,   14				)





				def 					a__(		self      :			int				,   lowerCAmelCase      :			"PreTrainedTokenizerBase"				,   lowerCAmelCase      :			int = -1				,   lowerCAmelCase      :			int = -1				,   lowerCAmelCase      :			bool = False				,   lowerCAmelCase      :			Optional[TensorType] = None				,   )->					Mapping[str, Any]:

										"""simple docstring"""




										UpperCAmelCase					    =     super().generate_dummy_inputs(
										    preprocessor=lowerCAmelCase				,   batch_size=lowerCAmelCase				,   seq_length=lowerCAmelCase				,   is_pair=lowerCAmelCase				,   framework=lowerCAmelCase				)
										import torch

										# for some reason, replacing this code by inputs["global_attention_mask"] = torch.randint(2, inputs["input_ids"].shape, dtype=torch.int64)
										# makes the export fail randomly
										UpperCAmelCase					    =     torch.zeros_like(inputs['''input_ids''']				)
										# make every second token global
										UpperCAmelCase					    =     1

										return inputs









'''simple docstring'''



from .data_collator import (
    DataCollatorForLanguageModeling,
    DataCollatorForPermutationLanguageModeling,
    DataCollatorForSeqaSeq,
    DataCollatorForSOP,
    DataCollatorForTokenClassification,
    DataCollatorForWholeWordMask,
    DataCollatorWithPadding,
    DefaultDataCollator,
    default_data_collator,
)
from .metrics import glue_compute_metrics, xnli_compute_metrics
from .processors import (
    DataProcessor,
    InputExample,
    InputFeatures,
    SingleSentenceClassificationProcessor,
    SquadExample,
    SquadFeatures,
    SquadVaProcessor,
    SquadVaProcessor,
    glue_convert_examples_to_features,
    glue_output_modes,
    glue_processors,
    glue_tasks_num_labels,
    squad_convert_examples_to_features,
    xnli_output_modes,
    xnli_processors,
    xnli_tasks_num_labels,
)





