




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


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 		lowercase_   (			A       ):


   """simple docstring"""

   lowerCamelCase_      =						'''longformer'''



   def __init__(   self :     Optional[int]  ,				__lowerCamelCase :     Union[List[int], int] = 5_1_2  ,				__lowerCamelCase :     int = 2  ,				__lowerCamelCase :     int = 1  ,				__lowerCamelCase :     int = 0  ,				__lowerCamelCase :     int = 2  ,				__lowerCamelCase :     int = 3_0_5_2_2  ,				__lowerCamelCase :     int = 7_6_8  ,				__lowerCamelCase :     int = 1_2  ,				__lowerCamelCase :     int = 1_2  ,				__lowerCamelCase :     int = 3_0_7_2  ,				__lowerCamelCase :     str = "gelu"  ,				__lowerCamelCase :     float = 0.1  ,				__lowerCamelCase :     float = 0.1  ,				__lowerCamelCase :     int = 5_1_2  ,				__lowerCamelCase :     int = 2  ,				__lowerCamelCase :     float = 0.0_2  ,				__lowerCamelCase :     float = 1e-12  ,				__lowerCamelCase :     bool = False  ,				**__lowerCamelCase :     List[Any]  ,				):

      """simple docstring"""
      super().__init__(pad_token_id=__lowerCamelCase  ,				**__lowerCamelCase   )

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







class 		lowercase_   (			A       ):


   """simple docstring"""

   def __init__(   self :     Tuple  ,				__lowerCamelCase :     "PretrainedConfig"  ,				__lowerCamelCase :     str = "default"  ,				__lowerCamelCase :     "List[PatchingSpec]" = None   ):

      """simple docstring"""
      super().__init__(__lowerCamelCase  ,				__lowerCamelCase  ,				__lowerCamelCase   )
      _SCREAMING_SNAKE_CASE	=				True



   @property
   def 							lowerCAmelCase_      (   self :     Any   ):

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



   @property
   def 							lowerCAmelCase_      (   self :     Tuple   ):

      """simple docstring"""
      _SCREAMING_SNAKE_CASE	=				super().outputs
      if self.task == "default":
         _SCREAMING_SNAKE_CASE	=				{0: "batch"}
      return outputs



   @property
   def 							lowerCAmelCase_      (   self :     Dict   ):

      """simple docstring"""
      return 1e-4



   @property
   def 							lowerCAmelCase_      (   self :     int   ):

      """simple docstring"""
      return max(super().default_onnx_opset  ,				1_4   )



   def 							lowerCAmelCase_      (   self :     Optional[Any]  ,				__lowerCamelCase :     "PreTrainedTokenizerBase"  ,				__lowerCamelCase :     int = -1  ,				__lowerCamelCase :     int = -1  ,				__lowerCamelCase :     bool = False  ,				__lowerCamelCase :     Optional[TensorType] = None  ,				):

      """simple docstring"""
      _SCREAMING_SNAKE_CASE	=				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
      _SCREAMING_SNAKE_CASE	=				torch.zeros_like(inputs["input_ids"]   )
      # make every second token global
      _SCREAMING_SNAKE_CASE	=				1

      return inputs







'''simple docstring'''



from typing import TYPE_CHECKING

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


lowerCamelCase_			=						{
    'configuration_ctrl': ['CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CTRLConfig'],
    'tokenization_ctrl': ['CTRLTokenizer'],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase_			=						[
     'CTRL_PRETRAINED_MODEL_ARCHIVE_LIST',
     'CTRLForSequenceClassification',
     'CTRLLMHeadModel',
     'CTRLModel',
     'CTRLPreTrainedModel',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase_			=						[
     'TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST',
     'TFCTRLForSequenceClassification',
     'TFCTRLLMHeadModel',
     'TFCTRLModel',
     'TFCTRLPreTrainedModel',
 ]


if TYPE_CHECKING:
 from .configuration_ctrl import CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP, CTRLConfig
 from .tokenization_ctrl import CTRLTokenizer

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_ctrl import (
      CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
      CTRLForSequenceClassification,
      CTRLLMHeadModel,
      CTRLModel,
      CTRLPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_ctrl import (
      TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFCTRLForSequenceClassification,
      TFCTRLLMHeadModel,
      TFCTRLModel,
      TFCTRLPreTrainedModel,
  )

else:
 import sys

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

