

"""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     :    int    =		logging.get_logger(__name__)

__A     :    Tuple    =		{
    'facebook/mbart-large-cc25': 'https://huggingface.co/facebook/mbart-large-cc25/resolve/main/config.json',
    # See all MBART models at https://huggingface.co/models?filter=mbart
}





class 			__UpperCamelCase (   _A						):
		SCREAMING_SNAKE_CASE								=    "mbart"
		SCREAMING_SNAKE_CASE								=    ["past_key_values"]
		SCREAMING_SNAKE_CASE								=    {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}


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





class 			__UpperCamelCase (   _A						):


		@property
		def 					SCREAMING_SNAKE_CASE__   (self :		int):
							if self.task in ["default", "seq2seq-lm"]:
												A			=					OrderedDict(
												    [
												        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
												        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
												    ])

												if self.use_past:
																	A			=					{0: "batch"}
																	A			=					{0: "batch", 1: "past_decoder_sequence + sequence"}
												else:
																	A			=					{0: "batch", 1: "decoder_sequence"}
																	A			=					{0: "batch", 1: "decoder_sequence"}

												if self.use_past:
																	self.fill_with_past_key_values_(__SCREAMING_SNAKE_CASE     ,     direction="inputs")
							elif self.task == "causal-lm":
												# TODO: figure this case out.
												A			=					OrderedDict(
												    [
												        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
												        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
												    ])
												if self.use_past:
																	A			,    A			=					self.num_layers
																	for i in range(__SCREAMING_SNAKE_CASE):
																						A			=					{0: "batch", 2: "past_sequence + sequence"}
																						A			=					{0: "batch", 2: "past_sequence + sequence"}
							else:
												A			=					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
		def 					SCREAMING_SNAKE_CASE__   (self :		List[Any]):
							if self.task in ["default", "seq2seq-lm"]:
												A			=					super().outputs
							else:
												A			=					super(__SCREAMING_SNAKE_CASE     ,     self).outputs
												if self.use_past:
																	A			,    A			=					self.num_layers
																	for i in range(__SCREAMING_SNAKE_CASE):
																						A			=					{0: "batch", 2: "past_sequence + sequence"}
																						A			=					{0: "batch", 2: "past_sequence + sequence"}
							return common_outputs


		def 					SCREAMING_SNAKE_CASE__   (self :		Tuple     ,     __SCREAMING_SNAKE_CASE :		PreTrainedTokenizer     ,     __SCREAMING_SNAKE_CASE :		int = -1     ,     __SCREAMING_SNAKE_CASE :		int = -1     ,     __SCREAMING_SNAKE_CASE :		bool = False     ,     __SCREAMING_SNAKE_CASE :		Optional[TensorType] = None     ,     ):
							A			=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE)

							# Generate decoder inputs
							A			=					seq_length if not self.use_past else 1
							A			=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE)
							A			=					{F"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
							A			=					dict(**__SCREAMING_SNAKE_CASE     ,     **__SCREAMING_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
												A			,    A			=					common_inputs["input_ids"].shape
												A			=					common_inputs["decoder_input_ids"].shape[1]
												A			,    A			=					self.num_attention_heads
												A			=					(
												    batch,
												    num_encoder_attention_heads,
												    encoder_seq_length,
												    self._config.hidden_size // num_encoder_attention_heads,
												)
												A			=					decoder_seq_length + 3
												A			=					(
												    batch,
												    num_decoder_attention_heads,
												    decoder_past_length,
												    self._config.hidden_size // num_decoder_attention_heads,
												)

												A			=					torch.cat(
												    [common_inputs["decoder_attention_mask"], torch.ones(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE)]     ,     dim=1)

												A			=					[]
												# If the number of encoder and decoder layers are present in the model configuration, both are considered
												A			,    A			=					self.num_layers
												A			=					min(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE)
												A			=					max(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE) - min_num_layers
												A			=					"encoder" if num_encoder_layers > num_decoder_layers else "decoder"

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


		def 					SCREAMING_SNAKE_CASE__   (self :		Optional[Any]     ,     __SCREAMING_SNAKE_CASE :		PreTrainedTokenizer     ,     __SCREAMING_SNAKE_CASE :		int = -1     ,     __SCREAMING_SNAKE_CASE :		int = -1     ,     __SCREAMING_SNAKE_CASE :		bool = False     ,     __SCREAMING_SNAKE_CASE :		Optional[TensorType] = None     ,     ):
							A			=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_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
												A			,    A			=					common_inputs["input_ids"].shape
												# Not using the same length for past_key_values
												A			=					seqlen + 2
												A			,    A			=					self.num_layers
												A			,    A			=					self.num_attention_heads
												A			=					(
												    batch,
												    num_encoder_attention_heads,
												    past_key_values_length,
												    self._config.hidden_size // num_encoder_attention_heads,
												)

												A			=					common_inputs["attention_mask"].dtype
												A			=					torch.cat(
												    [common_inputs["attention_mask"], torch.ones(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     dtype=__SCREAMING_SNAKE_CASE)]     ,     dim=1)
												A			=					[
												    (torch.zeros(__SCREAMING_SNAKE_CASE), torch.zeros(__SCREAMING_SNAKE_CASE)) for _ in range(__SCREAMING_SNAKE_CASE)
												]
							return common_inputs


		def 					SCREAMING_SNAKE_CASE__   (self :		List[Any]     ,     __SCREAMING_SNAKE_CASE :		PreTrainedTokenizer     ,     __SCREAMING_SNAKE_CASE :		int = -1     ,     __SCREAMING_SNAKE_CASE :		int = -1     ,     __SCREAMING_SNAKE_CASE :		bool = False     ,     __SCREAMING_SNAKE_CASE :		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
							A			=					compute_effective_axis_dimension(
							    __SCREAMING_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
							A			=					tokenizer.num_special_tokens_to_add(__SCREAMING_SNAKE_CASE)
							A			=					compute_effective_axis_dimension(
							    __SCREAMING_SNAKE_CASE     ,     fixed_dimension=OnnxConfig.default_fixed_sequence     ,     num_token_to_add=__SCREAMING_SNAKE_CASE)

							# Generate dummy inputs according to compute batch and sequence
							A			=					[" ".join([tokenizer.unk_token]) * seq_length] * batch_size
							A			=					dict(tokenizer(__SCREAMING_SNAKE_CASE     ,     return_tensors=__SCREAMING_SNAKE_CASE))
							return common_inputs


		def 					SCREAMING_SNAKE_CASE__   (self :		Optional[Any]     ,     __SCREAMING_SNAKE_CASE :		PreTrainedTokenizer     ,     __SCREAMING_SNAKE_CASE :		int = -1     ,     __SCREAMING_SNAKE_CASE :		int = -1     ,     __SCREAMING_SNAKE_CASE :		bool = False     ,     __SCREAMING_SNAKE_CASE :		Optional[TensorType] = None     ,     ):
							if self.task in ["default", "seq2seq-lm"]:
												A			=					self._generate_dummy_inputs_for_default_and_seqaseq_lm(
												    __SCREAMING_SNAKE_CASE     ,     batch_size=__SCREAMING_SNAKE_CASE     ,     seq_length=__SCREAMING_SNAKE_CASE     ,     is_pair=__SCREAMING_SNAKE_CASE     ,     framework=__SCREAMING_SNAKE_CASE)

							elif self.task == "causal-lm":
												A			=					self._generate_dummy_inputs_for_causal_lm(
												    __SCREAMING_SNAKE_CASE     ,     batch_size=__SCREAMING_SNAKE_CASE     ,     seq_length=__SCREAMING_SNAKE_CASE     ,     is_pair=__SCREAMING_SNAKE_CASE     ,     framework=__SCREAMING_SNAKE_CASE)
							else:
												A			=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
												    __SCREAMING_SNAKE_CASE     ,     batch_size=__SCREAMING_SNAKE_CASE     ,     seq_length=__SCREAMING_SNAKE_CASE     ,     is_pair=__SCREAMING_SNAKE_CASE     ,     framework=__SCREAMING_SNAKE_CASE)

							return common_inputs


		def 					SCREAMING_SNAKE_CASE__   (self :		Dict     ,     __SCREAMING_SNAKE_CASE :		str     ,     __SCREAMING_SNAKE_CASE :		str     ,     __SCREAMING_SNAKE_CASE :		Union[str, Any]     ,     __SCREAMING_SNAKE_CASE :		Any):
							if self.task in ["default", "seq2seq-lm"]:
												A			=					super()._flatten_past_key_values_(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE)
							else:
												A			=					super(__SCREAMING_SNAKE_CASE     ,     self)._flatten_past_key_values_(
												    __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE)








"""simple docstring"""




import copy

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


__A     :    str    =		logging.get_logger(__name__)

__A     :    Union[str, Any]    =		{
    'facebook/sam-vit-huge': 'https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json',
    'facebook/sam-vit-large': 'https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json',
    'facebook/sam-vit-base': 'https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json',
}





class 			__UpperCamelCase (   _A						):


		def __init__(self :		int     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=2_5_6     ,     __SCREAMING_SNAKE_CASE :		List[str]=1_0_2_4     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=1_6     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=1_6     ,     __SCREAMING_SNAKE_CASE :		List[str]=4     ,     __SCREAMING_SNAKE_CASE :		List[Any]="gelu"     ,     __SCREAMING_SNAKE_CASE :		str=1E-6     ,     **__SCREAMING_SNAKE_CASE :		Optional[int]     ,     ):
							super().__init__(**__SCREAMING_SNAKE_CASE)
							A			=					hidden_size
							A			=					image_size
							A			=					patch_size
							A			=					image_size // patch_size
							A			=					mask_input_channels
							A			=					num_point_embeddings
							A			=					hidden_act
							A			=					layer_norm_eps





class 			__UpperCamelCase (   _A						):


		def __init__(self :		List[Any]     ,     __SCREAMING_SNAKE_CASE :		Tuple=2_5_6     ,     __SCREAMING_SNAKE_CASE :		str="relu"     ,     __SCREAMING_SNAKE_CASE :		List[Any]=2_0_4_8     ,     __SCREAMING_SNAKE_CASE :		Tuple=2     ,     __SCREAMING_SNAKE_CASE :		Any=8     ,     __SCREAMING_SNAKE_CASE :		Union[str, Any]=2     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=3     ,     __SCREAMING_SNAKE_CASE :		List[Any]=3     ,     __SCREAMING_SNAKE_CASE :		Tuple=2_5_6     ,     __SCREAMING_SNAKE_CASE :		int=1E-6     ,     **__SCREAMING_SNAKE_CASE :		int     ,     ):
							super().__init__(**__SCREAMING_SNAKE_CASE)
							A			=					hidden_size
							A			=					hidden_act
							A			=					mlp_dim
							A			=					num_hidden_layers
							A			=					num_attention_heads
							A			=					attention_downsample_rate
							A			=					num_multimask_outputs
							A			=					iou_head_depth
							A			=					iou_head_hidden_dim
							A			=					layer_norm_eps





class 			__UpperCamelCase (   _A						):


		def __init__(self :		List[str]     ,     __SCREAMING_SNAKE_CASE :		List[Any]=7_6_8     ,     __SCREAMING_SNAKE_CASE :		int=2_5_6     ,     __SCREAMING_SNAKE_CASE :		Tuple=1_2     ,     __SCREAMING_SNAKE_CASE :		str=1_2     ,     __SCREAMING_SNAKE_CASE :		Any=3     ,     __SCREAMING_SNAKE_CASE :		Dict=1_0_2_4     ,     __SCREAMING_SNAKE_CASE :		str=1_6     ,     __SCREAMING_SNAKE_CASE :		Tuple="gelu"     ,     __SCREAMING_SNAKE_CASE :		int=1E-06     ,     __SCREAMING_SNAKE_CASE :		Dict=0.0     ,     __SCREAMING_SNAKE_CASE :		str=1E-10     ,     __SCREAMING_SNAKE_CASE :		List[str]=True     ,     __SCREAMING_SNAKE_CASE :		Union[str, Any]=4.0     ,     __SCREAMING_SNAKE_CASE :		str=True     ,     __SCREAMING_SNAKE_CASE :		Any=True     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=1_4     ,     __SCREAMING_SNAKE_CASE :		Tuple=[2, 5, 8, 1_1]     ,     __SCREAMING_SNAKE_CASE :		str=1_2_8     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=None     ,     **__SCREAMING_SNAKE_CASE :		Optional[Any]     ,     ):
							super().__init__(**__SCREAMING_SNAKE_CASE)

							A			=					hidden_size
							A			=					output_channels
							A			=					num_hidden_layers
							A			=					num_attention_heads
							A			=					num_channels
							A			=					image_size
							A			=					patch_size
							A			=					hidden_act
							A			=					layer_norm_eps
							A			=					attention_dropout
							A			=					initializer_range
							A			=					qkv_bias
							A			=					mlp_ratio
							A			=					use_abs_pos
							A			=					use_rel_pos
							A			=					window_size
							A			=					global_attn_indexes
							A			=					num_pos_feats
							A			=					int(hidden_size * mlp_ratio) if mlp_dim is None else mlp_dim





class 			__UpperCamelCase (   _A						):
		SCREAMING_SNAKE_CASE								=    "sam"
		SCREAMING_SNAKE_CASE								=    True


		def __init__(self :		Optional[int]     ,     __SCREAMING_SNAKE_CASE :		Dict=None     ,     __SCREAMING_SNAKE_CASE :		Union[str, Any]=None     ,     __SCREAMING_SNAKE_CASE :		Optional[int]=None     ,     __SCREAMING_SNAKE_CASE :		List[Any]=0.0_2     ,     **__SCREAMING_SNAKE_CASE :		Optional[Any]     ,     ):
							super().__init__(**__SCREAMING_SNAKE_CASE)
							A			=					vision_config if vision_config is not None else {}
							A			=					prompt_encoder_config if prompt_encoder_config is not None else {}
							A			=					mask_decoder_config if mask_decoder_config is not None else {}

							if isinstance(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE):
												A			=					vision_config.to_dict()
							if isinstance(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE):
												A			=					prompt_encoder_config.to_dict()
							if isinstance(__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE):
												A			=					mask_decoder_config.to_dict()

							A			=					SamVisionConfig(**__SCREAMING_SNAKE_CASE)
							A			=					SamPromptEncoderConfig(**__SCREAMING_SNAKE_CASE)
							A			=					SamMaskDecoderConfig(**__SCREAMING_SNAKE_CASE)
							A			=					initializer_range


		def 					SCREAMING_SNAKE_CASE__   (self :		List[str]):
							A			=					copy.deepcopy(self.__dict__)
							A			=					self.vision_config.to_dict()
							A			=					self.prompt_encoder_config.to_dict()
							A			=					self.mask_decoder_config.to_dict()
							A			=					self.__class__.model_type
							return output





