




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


UpperCAmelCase_				 =					logging.get_logger(__name__)

UpperCAmelCase_				 =					{
    "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_      (       __lowercase      ):







  '''simple docstring'''







  lowerCAmelCase_ :    List[str]    =  """longformer"""


  def __init__(  self			:		Tuple  ,						_UpperCAmelCase			:		Union[List[int], int] = 5_12  ,						_UpperCAmelCase			:		int = 2  ,						_UpperCAmelCase			:		int = 1  ,						_UpperCAmelCase			:		int = 0  ,						_UpperCAmelCase			:		int = 2  ,						_UpperCAmelCase			:		int = 3_05_22  ,						_UpperCAmelCase			:		int = 7_68  ,						_UpperCAmelCase			:		int = 12  ,						_UpperCAmelCase			:		int = 12  ,						_UpperCAmelCase			:		int = 30_72  ,						_UpperCAmelCase			:		str = "gelu"  ,						_UpperCAmelCase			:		float = 0.1  ,						_UpperCAmelCase			:		float = 0.1  ,						_UpperCAmelCase			:		int = 5_12  ,						_UpperCAmelCase			:		int = 2  ,						_UpperCAmelCase			:		float = 0.02  ,						_UpperCAmelCase			:		float = 1E-12  ,						_UpperCAmelCase			:		bool = False  ,						**_UpperCAmelCase			:		Dict  ,						):






   """simple docstring"""






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

   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   lowerCAmelCase_      (       __lowercase      ):







  '''simple docstring'''







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






   """simple docstring"""






   super().__init__(SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__       )
   UpperCAmelCase__								=			True


  @property
  def 							SCREAMING_SNAKE_CASE__	(  self			:		List[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 							SCREAMING_SNAKE_CASE__	(  self			:		Dict       ):






   """simple docstring"""






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


  @property
  def 							SCREAMING_SNAKE_CASE__	(  self			:		int       ):






   """simple docstring"""






   return 1E-4


  @property
  def 							SCREAMING_SNAKE_CASE__	(  self			:		Optional[Any]       ):






   """simple docstring"""






   return max(super().default_onnx_opset  ,						14       )



  def 							SCREAMING_SNAKE_CASE__	(  self			:		Union[str, Any]  ,						_UpperCAmelCase			:		"PreTrainedTokenizerBase"  ,						_UpperCAmelCase			:		int = -1  ,						_UpperCAmelCase			:		int = -1  ,						_UpperCAmelCase			:		bool = False  ,						_UpperCAmelCase			:		Optional[TensorType] = None  ,						):






   """simple docstring"""






   UpperCAmelCase__								=			super().generate_dummy_inputs(
       preprocessor=SCREAMING_SNAKE_CASE__  ,						batch_size=SCREAMING_SNAKE_CASE__  ,						seq_length=SCREAMING_SNAKE_CASE__  ,						is_pair=SCREAMING_SNAKE_CASE__  ,						framework=SCREAMING_SNAKE_CASE__       )
   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


from typing import TYPE_CHECKING

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


SCREAMING_SNAKE_CASE__   :			List[str]												=    {
    "configuration_blip": [
        "BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "BlipConfig",
        "BlipTextConfig",
        "BlipVisionConfig",
    ],
    "processing_blip": ["BlipProcessor"],
}

try:
					if not is_vision_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					SCREAMING_SNAKE_CASE__   :			str												=    ["BlipImageProcessor"]


try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					SCREAMING_SNAKE_CASE__   :			int												=    [
					    "BLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "BlipModel",
					    "BlipPreTrainedModel",
					    "BlipForConditionalGeneration",
					    "BlipForQuestionAnswering",
					    "BlipVisionModel",
					    "BlipTextModel",
					    "BlipForImageTextRetrieval",
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					SCREAMING_SNAKE_CASE__   :			Any												=    [
					    "TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "TFBlipModel",
					    "TFBlipPreTrainedModel",
					    "TFBlipForConditionalGeneration",
					    "TFBlipForQuestionAnswering",
					    "TFBlipVisionModel",
					    "TFBlipTextModel",
					    "TFBlipForImageTextRetrieval",
					]

if TYPE_CHECKING:
					from .configuration_blip import BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP, BlipConfig, BlipTextConfig, BlipVisionConfig
					from .processing_blip import BlipProcessor

					try:
										if not is_vision_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .image_processing_blip import BlipImageProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_blip import (
										    BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
										    BlipForConditionalGeneration,
										    BlipForImageTextRetrieval,
										    BlipForQuestionAnswering,
										    BlipModel,
										    BlipPreTrainedModel,
										    BlipTextModel,
										    BlipVisionModel,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_blip import (
										    TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFBlipForConditionalGeneration,
										    TFBlipForImageTextRetrieval,
										    TFBlipForQuestionAnswering,
										    TFBlipModel,
										    TFBlipPreTrainedModel,
										    TFBlipTextModel,
										    TFBlipVisionModel,
										)

else:
					import sys

					SCREAMING_SNAKE_CASE__   :			Tuple												=    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



