




"""simple docstring"""







from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


__A   :  Union[str, Any]					=      logging.get_logger(__name__)

__A   :  Any					=      {
    '''Helsinki-NLP/opus-mt-en-de''': '''https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json''',
    # See all Marian models at https://huggingface.co/models?filter=marian
}




class       lowerCAmelCase__       (			__a    ):


				"""simple docstring"""





				__UpperCAmelCase :     Union[str, Any]       =      '''marian'''
				__UpperCAmelCase :     List[str]       =      ['''past_key_values''']
				__UpperCAmelCase :     Optional[Any]       =      {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}



				def __init__(     self					:	List[Any]    ,   lowercase__					:	Tuple=5_8_1_0_1    ,   lowercase__					:	str=None    ,   lowercase__					:	List[Any]=1_0_2_4    ,   lowercase__					:	List[str]=1_2    ,   lowercase__					:	Any=4_0_9_6    ,   lowercase__					:	Any=1_6    ,   lowercase__					:	Optional[Any]=1_2    ,   lowercase__					:	Union[str, Any]=4_0_9_6    ,   lowercase__					:	int=1_6    ,   lowercase__					:	Any=0.0    ,   lowercase__					:	Union[str, Any]=0.0    ,   lowercase__					:	Dict=True    ,   lowercase__					:	List[Any]=True    ,   lowercase__					:	Dict="gelu"    ,   lowercase__					:	str=1_0_2_4    ,   lowercase__					:	Tuple=0.1    ,   lowercase__					:	List[str]=0.0    ,   lowercase__					:	Any=0.0    ,   lowercase__					:	int=0.0_2    ,   lowercase__					:	Tuple=5_8_1_0_0    ,   lowercase__					:	List[Any]=False    ,   lowercase__					:	Dict=5_8_1_0_0    ,   lowercase__					:	List[Any]=0    ,   lowercase__					:	int=0    ,   lowercase__					:	Union[str, Any]=True    ,   **lowercase__					:	str    ,   ):
						__lowercase				:		Any												=				vocab_size
						__lowercase				:		Any												=				decoder_vocab_size or vocab_size
						__lowercase				:		Any												=				max_position_embeddings
						__lowercase				:		List[Any]												=				d_model
						__lowercase				:		int												=				encoder_ffn_dim
						__lowercase				:		Optional[int]												=				encoder_layers
						__lowercase				:		int												=				encoder_attention_heads
						__lowercase				:		Dict												=				decoder_ffn_dim
						__lowercase				:		Dict												=				decoder_layers
						__lowercase				:		Any												=				decoder_attention_heads
						__lowercase				:		int												=				dropout
						__lowercase				:		Dict												=				attention_dropout
						__lowercase				:		List[str]												=				activation_dropout
						__lowercase				:		Union[str, Any]												=				activation_function
						__lowercase				:		List[str]												=				init_std
						__lowercase				:		List[str]												=				encoder_layerdrop
						__lowercase				:		Optional[int]												=				decoder_layerdrop
						__lowercase				:		str												=				use_cache
						__lowercase				:		Optional[Any]												=				encoder_layers
						__lowercase				:		Optional[int]												=				scale_embedding  # scale factor will be sqrt(d_model) if True
						__lowercase				:		Optional[int]												=				share_encoder_decoder_embeddings
						super().__init__(
						    pad_token_id=snake_case__    ,   eos_token_id=snake_case__    ,   is_encoder_decoder=snake_case__    ,   decoder_start_token_id=snake_case__    ,   forced_eos_token_id=snake_case__    ,   **snake_case__    ,   )





class       lowerCAmelCase__       (			__a    ):


				"""simple docstring"""





				@property
				# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
				def       snake_case    (     self					:	Union[str, Any]						):
						if self.task in ["default", "seq2seq-lm"]:
								__lowercase				:		List[Any]												=				OrderedDict(
								    [
								        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
								        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
								    ]						)

								if self.use_past:
										__lowercase				:		Any												=				{0: "batch"}
										__lowercase				:		Optional[int]												=				{0: "batch", 1: "past_decoder_sequence + sequence"}
								else:
										__lowercase				:		Dict												=				{0: "batch", 1: "decoder_sequence"}
										__lowercase				:		Optional[int]												=				{0: "batch", 1: "decoder_sequence"}

								if self.use_past:
										self.fill_with_past_key_values_(snake_case__    ,   direction="inputs"						)
						elif self.task == "causal-lm":
								# TODO: figure this case out.
								__lowercase				:		List[str]												=				OrderedDict(
								    [
								        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
								        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
								    ]						)
								if self.use_past:
										__lowercase						,__lowercase				:		str												=				self.num_layers
										for i in range(snake_case__						):
												__lowercase				:		Union[str, Any]												=				{0: "batch", 2: "past_sequence + sequence"}
												__lowercase				:		str												=				{0: "batch", 2: "past_sequence + sequence"}
						else:
								__lowercase				:		Any												=				OrderedDict(
								    [
								        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
								        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
								        ("decoder_input_ids", {0: "batch", 1: "decoder_sequence"}),
								        ("decoder_attention_mask", {0: "batch", 1: "decoder_sequence"}),
								    ]						)

						return common_inputs



				@property
				# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
				def       snake_case    (     self					:	Union[str, Any]						):
						if self.task in ["default", "seq2seq-lm"]:
								__lowercase				:		Union[str, Any]												=				super().outputs
						else:
								__lowercase				:		Union[str, Any]												=				super(snake_case__    ,   self						).outputs
								if self.use_past:
										__lowercase						,__lowercase				:		Any												=				self.num_layers
										for i in range(snake_case__						):
												__lowercase				:		str												=				{0: "batch", 2: "past_sequence + sequence"}
												__lowercase				:		int												=				{0: "batch", 2: "past_sequence + sequence"}
						return common_outputs



				def       snake_case    (     self					:	int    ,   lowercase__					:	PreTrainedTokenizer    ,   lowercase__					:	int = -1    ,   lowercase__					:	int = -1    ,   lowercase__					:	bool = False    ,   lowercase__					:	Optional[TensorType] = None    ,   ):
						__lowercase				:		Optional[Any]												=				self._generate_dummy_inputs_for_encoder_and_decoder(
						    snake_case__    ,   snake_case__    ,   snake_case__    ,   snake_case__    ,   snake_case__						)

						# Generate decoder inputs
						__lowercase				:		List[Any]												=				seq_length if not self.use_past else 1
						__lowercase				:		Dict												=				self._generate_dummy_inputs_for_encoder_and_decoder(
						    snake_case__    ,   snake_case__    ,   snake_case__    ,   snake_case__    ,   snake_case__						)
						__lowercase				:		Optional[Any]												=				{f'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
						__lowercase				:		str												=				dict(**snake_case__    ,   **snake_case__						)

						if self.use_past:
								if not is_torch_available():
										raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."						)
								else:
										import torch
								__lowercase						,__lowercase				:		Tuple												=				common_inputs["input_ids"].shape
								__lowercase				:		str												=				common_inputs["decoder_input_ids"].shape[1]
								__lowercase						,__lowercase				:		Optional[Any]												=				self.num_attention_heads
								__lowercase				:		Optional[Any]												=				(
								    batch,
								    num_encoder_attention_heads,
								    encoder_seq_length,
								    self._config.hidden_size // num_encoder_attention_heads,
								)
								__lowercase				:		List[str]												=				decoder_seq_length + 3
								__lowercase				:		Optional[Any]												=				(
								    batch,
								    num_decoder_attention_heads,
								    decoder_past_length,
								    self._config.hidden_size // num_decoder_attention_heads,
								)

								__lowercase				:		Tuple												=				torch.cat(
								    [common_inputs["decoder_attention_mask"], torch.ones(snake_case__    ,   snake_case__						)]    ,   dim=1						)

								__lowercase				:		str												=				[]
								# If the number of encoder and decoder layers are present in the model configuration, both are considered
								__lowercase						,__lowercase				:		Dict												=				self.num_layers
								__lowercase				:		Tuple												=				min(snake_case__    ,   snake_case__						)
								__lowercase				:		List[Any]												=				max(snake_case__    ,   snake_case__						) - min_num_layers
								__lowercase				:		Optional[int]												=				"encoder" if num_encoder_layers > num_decoder_layers else "decoder"

								for _ in range(snake_case__						):
										common_inputs["past_key_values"].append(
										    (
										        torch.zeros(snake_case__						),
										        torch.zeros(snake_case__						),
										        torch.zeros(snake_case__						),
										        torch.zeros(snake_case__						),
										    )						)
								# TODO: test this.
								__lowercase				:		Optional[Any]												=				encoder_shape if remaining_side_name == "encoder" else decoder_shape
								for _ in range(snake_case__    ,   snake_case__						):
										common_inputs["past_key_values"].append((torch.zeros(snake_case__						), torch.zeros(snake_case__						))						)
						return common_inputs



				def       snake_case    (     self					:	Optional[int]    ,   lowercase__					:	PreTrainedTokenizer    ,   lowercase__					:	int = -1    ,   lowercase__					:	int = -1    ,   lowercase__					:	bool = False    ,   lowercase__					:	Optional[TensorType] = None    ,   ):
						__lowercase				:		str												=				self._generate_dummy_inputs_for_encoder_and_decoder(
						    snake_case__    ,   snake_case__    ,   snake_case__    ,   snake_case__    ,   snake_case__						)

						if self.use_past:
								if not is_torch_available():
										raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."						)
								else:
										import torch
								__lowercase						,__lowercase				:		Optional[int]												=				common_inputs["input_ids"].shape
								# Not using the same length for past_key_values
								__lowercase				:		int												=				seqlen + 2
								__lowercase						,__lowercase				:		Dict												=				self.num_layers
								__lowercase						,__lowercase				:		List[Any]												=				self.num_attention_heads
								__lowercase				:		Any												=				(
								    batch,
								    num_encoder_attention_heads,
								    past_key_values_length,
								    self._config.hidden_size // num_encoder_attention_heads,
								)

								__lowercase				:		List[str]												=				common_inputs["attention_mask"].dtype
								__lowercase				:		Optional[int]												=				torch.cat(
								    [common_inputs["attention_mask"], torch.ones(snake_case__    ,   snake_case__    ,   dtype=snake_case__						)]    ,   dim=1						)
								__lowercase				:		str												=				[
								    (torch.zeros(snake_case__						), torch.zeros(snake_case__						)) for _ in range(snake_case__						)
								]
						return common_inputs



				def       snake_case    (     self					:	List[Any]    ,   lowercase__					:	PreTrainedTokenizer    ,   lowercase__					:	int = -1    ,   lowercase__					:	int = -1    ,   lowercase__					:	bool = False    ,   lowercase__					:	Optional[TensorType] = None    ,   ):
						# Copied from OnnxConfig.generate_dummy_inputs
						# Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
						# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
						__lowercase				:		Union[str, Any]												=				compute_effective_axis_dimension(
						    snake_case__    ,   fixed_dimension=OnnxConfig.default_fixed_batch    ,   num_token_to_add=0						)

						# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
						__lowercase				:		Dict												=				tokenizer.num_special_tokens_to_add(snake_case__						)
						__lowercase				:		Union[str, Any]												=				compute_effective_axis_dimension(
						    snake_case__    ,   fixed_dimension=OnnxConfig.default_fixed_sequence    ,   num_token_to_add=snake_case__						)

						# Generate dummy inputs according to compute batch and sequence
						__lowercase				:		List[str]												=				[" ".join([tokenizer.unk_token]						) * seq_length] * batch_size
						__lowercase				:		List[Any]												=				dict(tokenizer(snake_case__    ,   return_tensors=snake_case__						)						)
						return common_inputs



				def       snake_case    (     self					:	int    ,   lowercase__					:	PreTrainedTokenizer    ,   lowercase__					:	int = -1    ,   lowercase__					:	int = -1    ,   lowercase__					:	bool = False    ,   lowercase__					:	Optional[TensorType] = None    ,   ):
						if self.task in ["default", "seq2seq-lm"]:
								__lowercase				:		int												=				self._generate_dummy_inputs_for_default_and_seqaseq_lm(
								    snake_case__    ,   batch_size=snake_case__    ,   seq_length=snake_case__    ,   is_pair=snake_case__    ,   framework=snake_case__						)

						else:
								__lowercase				:		Tuple												=				self._generate_dummy_inputs_for_causal_lm(
								    snake_case__    ,   batch_size=snake_case__    ,   seq_length=snake_case__    ,   is_pair=snake_case__    ,   framework=snake_case__						)

						return common_inputs



				def       snake_case    (     self					:	Optional[Any]    ,   lowercase__					:	Tuple    ,   lowercase__					:	List[str]    ,   lowercase__					:	List[Any]    ,   lowercase__					:	Tuple						):
						if self.task in ["default", "seq2seq-lm"]:
								__lowercase				:		List[str]												=				super()._flatten_past_key_values_(snake_case__    ,   snake_case__    ,   snake_case__    ,   snake_case__						)
						else:
								__lowercase				:		List[Any]												=				super(snake_case__    ,   self						)._flatten_past_key_values_(
								    snake_case__    ,   snake_case__    ,   snake_case__    ,   snake_case__						)



				@property
				def       snake_case    (     self					:	Any						):
						return 1e-4










"""simple docstring"""







from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A   :  str					=      logging.get_logger(__name__)

__A   :  str					=      {
    'uclanlp/visualbert-vqa': 'https://huggingface.co/uclanlp/visualbert-vqa/resolve/main/config.json',
    'uclanlp/visualbert-vqa-pre': 'https://huggingface.co/uclanlp/visualbert-vqa-pre/resolve/main/config.json',
    'uclanlp/visualbert-vqa-coco-pre': (
        'https://huggingface.co/uclanlp/visualbert-vqa-coco-pre/resolve/main/config.json'
    ),
    'uclanlp/visualbert-vcr': 'https://huggingface.co/uclanlp/visualbert-vcr/resolve/main/config.json',
    'uclanlp/visualbert-vcr-pre': 'https://huggingface.co/uclanlp/visualbert-vcr-pre/resolve/main/config.json',
    'uclanlp/visualbert-vcr-coco-pre': (
        'https://huggingface.co/uclanlp/visualbert-vcr-coco-pre/resolve/main/config.json'
    ),
    'uclanlp/visualbert-nlvr2': 'https://huggingface.co/uclanlp/visualbert-nlvr2/resolve/main/config.json',
    'uclanlp/visualbert-nlvr2-pre': 'https://huggingface.co/uclanlp/visualbert-nlvr2-pre/resolve/main/config.json',
    'uclanlp/visualbert-nlvr2-coco-pre': (
        'https://huggingface.co/uclanlp/visualbert-nlvr2-coco-pre/resolve/main/config.json'
    )
    # See all VisualBERT models at https://huggingface.co/models?filter=visual_bert
}




class       lowerCAmelCase__       (			lowerCAmelCase_    ):


				"""simple docstring"""





				__UpperCAmelCase :     Tuple       =      "visual_bert"



				def __init__(     self					:	List[Any]    ,   lowercase__					:	Dict=3_0_5_2_2    ,   lowercase__					:	Any=7_6_8    ,   lowercase__					:	Dict=5_1_2    ,   lowercase__					:	Tuple=1_2    ,   lowercase__					:	Any=1_2    ,   lowercase__					:	Union[str, Any]=3_0_7_2    ,   lowercase__					:	Tuple="gelu"    ,   lowercase__					:	Dict=0.1    ,   lowercase__					:	Tuple=0.1    ,   lowercase__					:	str=5_1_2    ,   lowercase__					:	str=2    ,   lowercase__					:	Any=0.0_2    ,   lowercase__					:	Any=1e-12    ,   lowercase__					:	Any=False    ,   lowercase__					:	List[str]=True    ,   lowercase__					:	Dict=1    ,   lowercase__					:	List[Any]=0    ,   lowercase__					:	Tuple=2    ,   **lowercase__					:	Any    ,   ):
						super().__init__(pad_token_id=lowercase__    ,   bos_token_id=lowercase__    ,   eos_token_id=lowercase__    ,   **lowercase__						)

						__lowercase				:		Optional[int]												=				vocab_size
						__lowercase				:		Any												=				max_position_embeddings
						__lowercase				:		Optional[Any]												=				hidden_size
						__lowercase				:		List[str]												=				visual_embedding_dim
						__lowercase				:		Dict												=				num_hidden_layers
						__lowercase				:		Any												=				num_attention_heads
						__lowercase				:		str												=				intermediate_size
						__lowercase				:		Dict												=				hidden_act
						__lowercase				:		Any												=				hidden_dropout_prob
						__lowercase				:		Optional[int]												=				attention_probs_dropout_prob
						__lowercase				:		Dict												=				initializer_range
						__lowercase				:		str												=				type_vocab_size
						__lowercase				:		List[Any]												=				layer_norm_eps
						__lowercase				:		Tuple												=				bypass_transformer
						__lowercase				:		List[str]												=				special_visual_initialize
