




"""simple docstring"""





import warnings
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				=							logging.get_logger(__name__)

A				=							{
    """facebook/bart-large""": """https://huggingface.co/facebook/bart-large/resolve/main/config.json""",
    # See all BART models at https://huggingface.co/models?filter=bart
}



class   a__					(						__magic_name__ ):
			lowercase_		=						"bart"
			lowercase_		=						["past_key_values"]
			lowercase_		=						{"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}


			def __init__(   self   :     List[Any]   ,	UpperCamelCase_   :     Optional[Any]=50265   ,	UpperCamelCase_   :     int=1024   ,	UpperCamelCase_   :     List[str]=12   ,	UpperCamelCase_   :     List[str]=4096   ,	UpperCamelCase_   :     int=16   ,	UpperCamelCase_   :     Optional[int]=12   ,	UpperCamelCase_   :     Any=4096   ,	UpperCamelCase_   :     Dict=16   ,	UpperCamelCase_   :     Optional[Any]=0.0   ,	UpperCamelCase_   :     int=0.0   ,	UpperCamelCase_   :     Dict="gelu"   ,	UpperCamelCase_   :     int=1024   ,	UpperCamelCase_   :     Optional[int]=0.1   ,	UpperCamelCase_   :     int=0.0   ,	UpperCamelCase_   :     Optional[Any]=0.0   ,	UpperCamelCase_   :     Any=0.02   ,	UpperCamelCase_   :     str=0.0   ,	UpperCamelCase_   :     Tuple=False   ,	UpperCamelCase_   :     Dict=True   ,	UpperCamelCase_   :     Union[str, Any]=3   ,	UpperCamelCase_   :     Optional[int]=1   ,	UpperCamelCase_   :     Any=0   ,	UpperCamelCase_   :     Tuple=2   ,	UpperCamelCase_   :     Optional[int]=True   ,	UpperCamelCase_   :     Dict=2   ,	UpperCamelCase_   :     Optional[int]=2   ,	**UpperCamelCase_   :     Any   ,	):


						"""simple docstring"""




						__UpperCAmelCase						:			str												=       vocab_size
						__UpperCAmelCase						:			Optional[int]												=       max_position_embeddings
						__UpperCAmelCase						:			List[str]												=       d_model
						__UpperCAmelCase						:			List[str]												=       encoder_ffn_dim
						__UpperCAmelCase						:			List[str]												=       encoder_layers
						__UpperCAmelCase						:			Optional[int]												=       encoder_attention_heads
						__UpperCAmelCase						:			Tuple												=       decoder_ffn_dim
						__UpperCAmelCase						:			List[Any]												=       decoder_layers
						__UpperCAmelCase						:			Dict												=       decoder_attention_heads
						__UpperCAmelCase						:			int												=       dropout
						__UpperCAmelCase						:			str												=       attention_dropout
						__UpperCAmelCase						:			Dict												=       activation_dropout
						__UpperCAmelCase						:			str												=       activation_function
						__UpperCAmelCase						:			Union[str, Any]												=       init_std
						__UpperCAmelCase						:			Optional[int]												=       encoder_layerdrop
						__UpperCAmelCase						:			List[str]												=       decoder_layerdrop
						__UpperCAmelCase						:			Dict												=       classifier_dropout
						__UpperCAmelCase						:			Any												=       use_cache
						__UpperCAmelCase						:			Optional[int]												=       encoder_layers
						__UpperCAmelCase						:			int												=       scale_embedding  # scale factor will be sqrt(d_model) if True

						super().__init__(
						    num_labels=UpperCamelCase_   ,	pad_token_id=UpperCamelCase_   ,	bos_token_id=UpperCamelCase_   ,	eos_token_id=UpperCamelCase_   ,	is_encoder_decoder=UpperCamelCase_   ,	decoder_start_token_id=UpperCamelCase_   ,	forced_eos_token_id=UpperCamelCase_   ,	**UpperCamelCase_   ,	)

						# ensure backward compatibility for BART CNN models
						if self.forced_bos_token_id is None and kwargs.get("force_bos_token_to_be_generated"   ,	UpperCamelCase_):
									__UpperCAmelCase						:			Dict												=       self.bos_token_id
									warnings.warn(
									    F"Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. "
									    "The config can simply be saved and uploaded again to be fixed.")






class   a__					(						__magic_name__ ):


			@property
			def    a_  (   self   :     int):


						"""simple docstring"""




						if self.task in ["default", "seq2seq-lm"]:
									__UpperCAmelCase						:			Optional[Any]												=       OrderedDict(
									    [
									        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
									        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
									    ])

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

									if self.use_past:
												self.fill_with_past_key_values_(UpperCamelCase_   ,	direction="inputs")
						elif self.task == "causal-lm":
									# TODO: figure this case out.
									__UpperCAmelCase						:			Dict												=       OrderedDict(
									    [
									        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
									        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
									    ])
									if self.use_past:
												__UpperCAmelCase						,  __UpperCAmelCase						:			int												=       self.num_layers
												for i in range(UpperCamelCase_):
															__UpperCAmelCase						:			int												=       {0: "batch", 2: "past_sequence + sequence"}
															__UpperCAmelCase						:			int												=       {0: "batch", 2: "past_sequence + sequence"}
						else:
									__UpperCAmelCase						:			Union[str, 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
			def    a_  (   self   :     Any):


						"""simple docstring"""




						if self.task in ["default", "seq2seq-lm"]:
									__UpperCAmelCase						:			Optional[Any]												=       super().outputs
						else:
									__UpperCAmelCase						:			Any												=       super(UpperCamelCase_   ,	self).outputs
									if self.use_past:
												__UpperCAmelCase						,  __UpperCAmelCase						:			Optional[Any]												=       self.num_layers
												for i in range(UpperCamelCase_):
															__UpperCAmelCase						:			Tuple												=       {0: "batch", 2: "past_sequence + sequence"}
															__UpperCAmelCase						:			List[str]												=       {0: "batch", 2: "past_sequence + sequence"}
						return common_outputs


			def    a_  (   self   :     List[str]   ,	UpperCamelCase_   :     PreTrainedTokenizer   ,	UpperCamelCase_   :     int = -1   ,	UpperCamelCase_   :     int = -1   ,	UpperCamelCase_   :     bool = False   ,	UpperCamelCase_   :     Optional[TensorType] = None   ,	):


						"""simple docstring"""




						__UpperCAmelCase						:			List[str]												=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
						    UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_)

						# Generate decoder inputs
						__UpperCAmelCase						:			str												=       seq_length if not self.use_past else 1
						__UpperCAmelCase						:			Tuple												=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
						    UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_)
						__UpperCAmelCase						:			Union[str, Any]												=       {F"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
						__UpperCAmelCase						:			Optional[Any]												=       dict(**UpperCamelCase_   ,	**UpperCamelCase_)

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

									__UpperCAmelCase						:			str												=       torch.cat(
									    [common_inputs["decoder_attention_mask"], torch.ones(UpperCamelCase_   ,	UpperCamelCase_)]   ,	dim=1)

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

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


			def    a_  (   self   :     str   ,	UpperCamelCase_   :     PreTrainedTokenizer   ,	UpperCamelCase_   :     int = -1   ,	UpperCamelCase_   :     int = -1   ,	UpperCamelCase_   :     bool = False   ,	UpperCamelCase_   :     Optional[TensorType] = None   ,	):


						"""simple docstring"""




						__UpperCAmelCase						:			Any												=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
						    UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_)

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

									__UpperCAmelCase						:			List[Any]												=       common_inputs["attention_mask"].dtype
									__UpperCAmelCase						:			Optional[int]												=       torch.cat(
									    [common_inputs["attention_mask"], torch.ones(UpperCamelCase_   ,	UpperCamelCase_   ,	dtype=UpperCamelCase_)]   ,	dim=1)
									__UpperCAmelCase						:			Tuple												=       [
									    (torch.zeros(UpperCamelCase_), torch.zeros(UpperCamelCase_)) for _ in range(UpperCamelCase_)
									]
						return common_inputs


			def    a_  (   self   :     Tuple   ,	UpperCamelCase_   :     PreTrainedTokenizer   ,	UpperCamelCase_   :     int = -1   ,	UpperCamelCase_   :     int = -1   ,	UpperCamelCase_   :     bool = False   ,	UpperCamelCase_   :     Optional[TensorType] = None   ,	):


						"""simple docstring"""




						__UpperCAmelCase						:			Optional[int]												=       compute_effective_axis_dimension(
						    UpperCamelCase_   ,	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
						__UpperCAmelCase						:			Dict												=       tokenizer.num_special_tokens_to_add(UpperCamelCase_)
						__UpperCAmelCase						:			Optional[Any]												=       compute_effective_axis_dimension(
						    UpperCamelCase_   ,	fixed_dimension=OnnxConfig.default_fixed_sequence   ,	num_token_to_add=UpperCamelCase_)

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


			def    a_  (   self   :     Optional[Any]   ,	UpperCamelCase_   :     PreTrainedTokenizer   ,	UpperCamelCase_   :     int = -1   ,	UpperCamelCase_   :     int = -1   ,	UpperCamelCase_   :     bool = False   ,	UpperCamelCase_   :     Optional[TensorType] = None   ,	):


						"""simple docstring"""




						if self.task in ["default", "seq2seq-lm"]:
									__UpperCAmelCase						:			int												=       self._generate_dummy_inputs_for_default_and_seqaseq_lm(
									    UpperCamelCase_   ,	batch_size=UpperCamelCase_   ,	seq_length=UpperCamelCase_   ,	is_pair=UpperCamelCase_   ,	framework=UpperCamelCase_)

						elif self.task == "causal-lm":
									__UpperCAmelCase						:			Tuple												=       self._generate_dummy_inputs_for_causal_lm(
									    UpperCamelCase_   ,	batch_size=UpperCamelCase_   ,	seq_length=UpperCamelCase_   ,	is_pair=UpperCamelCase_   ,	framework=UpperCamelCase_)
						else:
									__UpperCAmelCase						:			Dict												=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
									    UpperCamelCase_   ,	batch_size=UpperCamelCase_   ,	seq_length=UpperCamelCase_   ,	is_pair=UpperCamelCase_   ,	framework=UpperCamelCase_)

						return common_inputs


			def    a_  (   self   :     Any   ,	UpperCamelCase_   :     Optional[Any]   ,	UpperCamelCase_   :     Tuple   ,	UpperCamelCase_   :     Any   ,	UpperCamelCase_   :     Optional[int]):


						"""simple docstring"""




						if self.task in ["default", "seq2seq-lm"]:
									__UpperCAmelCase						:			Any												=       super()._flatten_past_key_values_(UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_)
						else:
									__UpperCAmelCase						:			List[str]												=       super(UpperCamelCase_   ,	self)._flatten_past_key_values_(
									    UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_   ,	UpperCamelCase_)








from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


SCREAMING_SNAKE_CASE__     :     str		    =       {
    "configuration_altclip": [
        "ALTCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "AltCLIPConfig",
        "AltCLIPTextConfig",
        "AltCLIPVisionConfig",
    ],
    "processing_altclip": ["AltCLIPProcessor"],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				SCREAMING_SNAKE_CASE__     :     Any		    =       [
				    "ALTCLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
				    "AltCLIPPreTrainedModel",
				    "AltCLIPModel",
				    "AltCLIPTextModel",
				    "AltCLIPVisionModel",
				]


if TYPE_CHECKING:
				from .configuration_altclip import (
				    ALTCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    AltCLIPConfig,
				    AltCLIPTextConfig,
				    AltCLIPVisionConfig,
				)
				from .processing_altclip import AltCLIPProcessor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_altclip import (
								    ALTCLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
								    AltCLIPModel,
								    AltCLIPPreTrainedModel,
								    AltCLIPTextModel,
								    AltCLIPVisionModel,
								)


else:
				import sys

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