
"""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 			lowercase					( lowercase__		):
			lowercase        =     '''longformer'''






			def __init__(self  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	Union[List[int], int] = 512      ,SCREAMING_SNAKE_CASE_  :	int = 2      ,SCREAMING_SNAKE_CASE_  :	int = 1      ,SCREAMING_SNAKE_CASE_  :	int = 0      ,SCREAMING_SNAKE_CASE_  :	int = 2      ,SCREAMING_SNAKE_CASE_  :	int = 30_522      ,SCREAMING_SNAKE_CASE_  :	int = 768      ,SCREAMING_SNAKE_CASE_  :	int = 12      ,SCREAMING_SNAKE_CASE_  :	int = 12      ,SCREAMING_SNAKE_CASE_  :	int = 3_072      ,SCREAMING_SNAKE_CASE_  :	str = "gelu"      ,SCREAMING_SNAKE_CASE_  :	float = 0.1      ,SCREAMING_SNAKE_CASE_  :	float = 0.1      ,SCREAMING_SNAKE_CASE_  :	int = 512      ,SCREAMING_SNAKE_CASE_  :	int = 2      ,SCREAMING_SNAKE_CASE_  :	float = 0.02      ,SCREAMING_SNAKE_CASE_  :	float = 1e-12      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,**SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,)       ->	Tuple:





				"""simple docstring"""


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

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





class 			lowercase					( lowercase__		):






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





				"""simple docstring"""


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






			@property
			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	Mapping[str, Mapping[int, str]]:





				"""simple docstring"""


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






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





				"""simple docstring"""


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






			@property
			def 					UpperCAmelCase							(self  :	Optional[Any]			)       ->	float:





				"""simple docstring"""


				return 1e-4






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





				"""simple docstring"""


				return max(super().default_onnx_opset      ,14			)






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





				"""simple docstring"""


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

				return inputs




"""simple docstring"""






from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType



class 			lowercase					( lowercase__		):
			lowercase        =     ['''image_processor''', '''tokenizer''']
			lowercase        =     '''BlipImageProcessor'''
			lowercase        =     ('''BertTokenizer''', '''BertTokenizerFast''')






			def __init__(self  :	Any      ,SCREAMING_SNAKE_CASE_  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	Dict:





				"""simple docstring"""


				lowerCAmelCase												=  False
				super().__init__(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  self.image_processor






			def __call__(self  :	int      ,SCREAMING_SNAKE_CASE_  :	ImageInput = None      ,SCREAMING_SNAKE_CASE_  :	Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None      ,SCREAMING_SNAKE_CASE_  :	bool = True      ,SCREAMING_SNAKE_CASE_  :	Union[bool, str, PaddingStrategy] = False      ,SCREAMING_SNAKE_CASE_  :	Union[bool, str, TruncationStrategy] = None      ,SCREAMING_SNAKE_CASE_  :	Optional[int] = None      ,SCREAMING_SNAKE_CASE_  :	int = 0      ,SCREAMING_SNAKE_CASE_  :	Optional[int] = None      ,SCREAMING_SNAKE_CASE_  :	Optional[bool] = None      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = True      ,SCREAMING_SNAKE_CASE_  :	Optional[Union[str, TensorType]] = None      ,**SCREAMING_SNAKE_CASE_  :	str      ,)       ->	BatchEncoding:





				"""simple docstring"""


				if images is None and text is None:
					raise ValueError('''You have to specify either images or text.'''			)

				# Get only text
				if images is None:
					lowerCAmelCase												=  self.tokenizer
					lowerCAmelCase												=  self.tokenizer(
					    text=SCREAMING_SNAKE_CASE_      ,add_special_tokens=SCREAMING_SNAKE_CASE_      ,padding=SCREAMING_SNAKE_CASE_      ,truncation=SCREAMING_SNAKE_CASE_      ,max_length=SCREAMING_SNAKE_CASE_      ,stride=SCREAMING_SNAKE_CASE_      ,pad_to_multiple_of=SCREAMING_SNAKE_CASE_      ,return_attention_mask=SCREAMING_SNAKE_CASE_      ,return_overflowing_tokens=SCREAMING_SNAKE_CASE_      ,return_special_tokens_mask=SCREAMING_SNAKE_CASE_      ,return_offsets_mapping=SCREAMING_SNAKE_CASE_      ,return_token_type_ids=SCREAMING_SNAKE_CASE_      ,return_length=SCREAMING_SNAKE_CASE_      ,verbose=SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_      ,)
					return text_encoding

				# add pixel_values
				lowerCAmelCase												=  self.image_processor(SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_			)

				if text is not None:
					lowerCAmelCase												=  self.tokenizer(
					    text=SCREAMING_SNAKE_CASE_      ,add_special_tokens=SCREAMING_SNAKE_CASE_      ,padding=SCREAMING_SNAKE_CASE_      ,truncation=SCREAMING_SNAKE_CASE_      ,max_length=SCREAMING_SNAKE_CASE_      ,stride=SCREAMING_SNAKE_CASE_      ,pad_to_multiple_of=SCREAMING_SNAKE_CASE_      ,return_attention_mask=SCREAMING_SNAKE_CASE_      ,return_overflowing_tokens=SCREAMING_SNAKE_CASE_      ,return_special_tokens_mask=SCREAMING_SNAKE_CASE_      ,return_offsets_mapping=SCREAMING_SNAKE_CASE_      ,return_token_type_ids=SCREAMING_SNAKE_CASE_      ,return_length=SCREAMING_SNAKE_CASE_      ,verbose=SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_      ,)
				else:
					lowerCAmelCase												=  None

				if text_encoding is not None:
					encoding_image_processor.update(SCREAMING_SNAKE_CASE_			)

				return encoding_image_processor






			def 					UpperCAmelCase							(self  :	List[str]      ,*SCREAMING_SNAKE_CASE_  :	str      ,**SCREAMING_SNAKE_CASE_  :	str			)       ->	Union[str, Any]:





				"""simple docstring"""


				return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	List[Any]      ,*SCREAMING_SNAKE_CASE_  :	str      ,**SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	Any:





				"""simple docstring"""


				return self.tokenizer.decode(*SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_			)






			@property
			def 					UpperCAmelCase							(self  :	Dict			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  self.tokenizer.model_input_names
				lowerCAmelCase												=  self.image_processor.model_input_names
				return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names			)			)


