



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


__lowerCamelCase						=       logging.get_logger(__name__)

__lowerCamelCase						=       {
    """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 		_snake_case   (      __a					):





 """simple docstring"""



 lowerCamelCase_        =      '''longformer'''
 def __init__(    self						,     a = 5_1_2						,     a = 2						,     a = 1						,     a = 0						,     a = 2						,     a = 3_0_5_2_2						,     a = 7_6_8						,     a = 1_2						,     a = 1_2						,     a = 3_0_7_2						,     a = "gelu"						,     a = 0.1						,     a = 0.1						,     a = 5_1_2						,     a = 2						,     a = 0.02						,     a = 1e-12						,     a = False						,     **a						,     )						->				int:




   """simple docstring"""







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

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







class 		_snake_case   (      __a					):





 """simple docstring"""



 def __init__(    self						,     a						,     a = "default"						,     a = None       )						->				Tuple:




   """simple docstring"""







   super().__init__(_lowercase						,     _lowercase						,     _lowercase       )
   _A							     =     True
 @property
 def lowercase_		(    self       )						->				List[Any]:




   """simple docstring"""







   if self.task == "multiple-choice":
     _A							     =     {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
   else:
     _A							     =     {0: '''batch''', 1: '''sequence'''}
   return OrderedDict(
       [
           ('''input_ids''', dynamic_axis),
           ('''attention_mask''', dynamic_axis),
           ('''global_attention_mask''', dynamic_axis),
       ]       )
 @property
 def lowercase_		(    self       )						->				Union[str, Any]:




   """simple docstring"""







   _A							     =     super().outputs
   if self.task == "default":
     _A							     =     {0: '''batch'''}
   return outputs
 @property
 def lowercase_		(    self       )						->				int:




   """simple docstring"""







   return 1e-4
 @property
 def lowercase_		(    self       )						->				List[str]:




   """simple docstring"""







   return max(super().default_onnx_opset						,     1_4       )



 def lowercase_		(    self						,     a						,     a = -1						,     a = -1						,     a = False						,     a = None						,     )						->				Dict:




   """simple docstring"""







   _A							     =     super().generate_dummy_inputs(
       preprocessor=_lowercase						,     batch_size=_lowercase						,     seq_length=_lowercase						,     is_pair=_lowercase						,     framework=_lowercase       )
   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
   _A							     =     torch.zeros_like(inputs['''input_ids''']       )
   # make every second token global
   _A							     =     1

   return inputs
from typing import TYPE_CHECKING

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


UpperCAmelCase_           =				{
    '''configuration_mega''': ['''MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''MegaConfig''', '''MegaOnnxConfig'''],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_           =				[
      '''MEGA_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''MegaForCausalLM''',
      '''MegaForMaskedLM''',
      '''MegaForMultipleChoice''',
      '''MegaForQuestionAnswering''',
      '''MegaForSequenceClassification''',
      '''MegaForTokenClassification''',
      '''MegaModel''',
      '''MegaPreTrainedModel''',
  ]

if TYPE_CHECKING:
  from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_mega import (
        MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
        MegaForCausalLM,
        MegaForMaskedLM,
        MegaForMultipleChoice,
        MegaForQuestionAnswering,
        MegaForSequenceClassification,
        MegaForTokenClassification,
        MegaModel,
        MegaPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase_           =				_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)