


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


SCREAMING_SNAKE_CASE						:Any			=  logging.get_logger(__name__)

SCREAMING_SNAKE_CASE						:List[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      __lowerCAmelCase  (			__snake_case       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							'longformer'



  def __init__(  self							:							Optional[int]     ,					_lowerCAmelCase							:							Any = 5_1_2     ,					_lowerCAmelCase							:							List[Any] = 2     ,					_lowerCAmelCase							:							List[str] = 1     ,					_lowerCAmelCase							:							Tuple = 0     ,					_lowerCAmelCase							:							Tuple = 2     ,					_lowerCAmelCase							:							int = 3_0_5_2_2     ,					_lowerCAmelCase							:							Union[str, Any] = 7_6_8     ,					_lowerCAmelCase							:							Dict = 1_2     ,					_lowerCAmelCase							:							Optional[Any] = 1_2     ,					_lowerCAmelCase							:							str = 3_0_7_2     ,					_lowerCAmelCase							:							Optional[int] = "gelu"     ,					_lowerCAmelCase							:							Optional[int] = 0.1     ,					_lowerCAmelCase							:							Any = 0.1     ,					_lowerCAmelCase							:							Optional[Any] = 5_1_2     ,					_lowerCAmelCase							:							Union[str, Any] = 2     ,					_lowerCAmelCase							:							Any = 0.02     ,					_lowerCAmelCase							:							Any = 1e-12     ,					_lowerCAmelCase							:							Any = False     ,					**_lowerCAmelCase							:							Union[str, Any]     ,					) ->			List[str]:




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

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






class      __lowerCAmelCase  (			__snake_case       ):






  """simple docstring"""





  def __init__(  self							:							int     ,					_lowerCAmelCase							:							List[Any]     ,					_lowerCAmelCase							:							List[Any] = "default"     ,					_lowerCAmelCase							:							int = None	) ->			Any:




     """simple docstring"""
     super().__init__(_lowerCAmelCase     ,					_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       True



  @property
  def        lowerCAmelCase__	(  self							:							int	) ->			List[str]:




     """simple docstring"""






     if self.task == "multiple-choice":
        snake_case_            =       {0: "batch", 1: "choice", 2: "sequence"}
     else:
        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							:							Optional[Any]	) ->			int:




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



  @property
  def        lowerCAmelCase__	(  self							:							str	) ->			List[Any]:




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



  @property
  def        lowerCAmelCase__	(  self							:							Dict	) ->			str:




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



  def        lowerCAmelCase__	(  self							:							str     ,					_lowerCAmelCase							:							Any     ,					_lowerCAmelCase							:							Dict = -1     ,					_lowerCAmelCase							:							str = -1     ,					_lowerCAmelCase							:							str = False     ,					_lowerCAmelCase							:							Any = None     ,					) ->			List[str]:




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

     return inputs








"""simple docstring"""



from typing import TYPE_CHECKING

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


lowercase_							=							{
    'configuration_mobilebert': [
        'MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'MobileBertConfig',
        'MobileBertOnnxConfig',
    ],
    'tokenization_mobilebert': ['MobileBertTokenizer'],
}

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase_							=							['MobileBertTokenizerFast']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase_							=							[
		    'MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'MobileBertForMaskedLM',
		    'MobileBertForMultipleChoice',
		    'MobileBertForNextSentencePrediction',
		    'MobileBertForPreTraining',
		    'MobileBertForQuestionAnswering',
		    'MobileBertForSequenceClassification',
		    'MobileBertForTokenClassification',
		    'MobileBertLayer',
		    'MobileBertModel',
		    'MobileBertPreTrainedModel',
		    'load_tf_weights_in_mobilebert',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase_							=							[
		    'TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'TFMobileBertForMaskedLM',
		    'TFMobileBertForMultipleChoice',
		    'TFMobileBertForNextSentencePrediction',
		    'TFMobileBertForPreTraining',
		    'TFMobileBertForQuestionAnswering',
		    'TFMobileBertForSequenceClassification',
		    'TFMobileBertForTokenClassification',
		    'TFMobileBertMainLayer',
		    'TFMobileBertModel',
		    'TFMobileBertPreTrainedModel',
		]


if TYPE_CHECKING:
		from .configuration_mobilebert import (
		    MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    MobileBertConfig,
		    MobileBertOnnxConfig,
		)
		from .tokenization_mobilebert import MobileBertTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_mobilebert_fast import MobileBertTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mobilebert import (
				    MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    MobileBertForMaskedLM,
				    MobileBertForMultipleChoice,
				    MobileBertForNextSentencePrediction,
				    MobileBertForPreTraining,
				    MobileBertForQuestionAnswering,
				    MobileBertForSequenceClassification,
				    MobileBertForTokenClassification,
				    MobileBertLayer,
				    MobileBertModel,
				    MobileBertPreTrainedModel,
				    load_tf_weights_in_mobilebert,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_mobilebert import (
				    TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFMobileBertForMaskedLM,
				    TFMobileBertForMultipleChoice,
				    TFMobileBertForNextSentencePrediction,
				    TFMobileBertForPreTraining,
				    TFMobileBertForQuestionAnswering,
				    TFMobileBertForSequenceClassification,
				    TFMobileBertForTokenClassification,
				    TFMobileBertMainLayer,
				    TFMobileBertModel,
				    TFMobileBertPreTrainedModel,
				)

else:
		import sys

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