

"""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_							:			List[Any]											= logging.get_logger(__name__)

A_							:			Dict											= {
    "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    lowerCamelCase						(A__			):
			lowerCamelCase__   :		str							=							'bart'
			lowerCamelCase__   :		List[Any]							=							['past_key_values']
			lowerCamelCase__   :		List[str]							=							{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}

			def __init__(					self				:						int    ,				__UpperCAmelCase				:						Optional[int]=5_0_2_6_5    ,				__UpperCAmelCase				:						List[str]=1_0_2_4    ,				__UpperCAmelCase				:						Union[str, Any]=1_2    ,				__UpperCAmelCase				:						Optional[Any]=4_0_9_6    ,				__UpperCAmelCase				:						Any=1_6    ,				__UpperCAmelCase				:						List[Any]=1_2    ,				__UpperCAmelCase				:						Any=4_0_9_6    ,				__UpperCAmelCase				:						Optional[Any]=1_6    ,				__UpperCAmelCase				:						Union[str, Any]=0.0    ,				__UpperCAmelCase				:						Optional[Any]=0.0    ,				__UpperCAmelCase				:						Optional[int]="gelu"    ,				__UpperCAmelCase				:						int=1_0_2_4    ,				__UpperCAmelCase				:						Tuple=0.1    ,				__UpperCAmelCase				:						Tuple=0.0    ,				__UpperCAmelCase				:						Tuple=0.0    ,				__UpperCAmelCase				:						Optional[int]=0.02    ,				__UpperCAmelCase				:						List[Any]=0.0    ,				__UpperCAmelCase				:						List[str]=False    ,				__UpperCAmelCase				:						str=True    ,				__UpperCAmelCase				:						str=3    ,				__UpperCAmelCase				:						List[Any]=1    ,				__UpperCAmelCase				:						str=0    ,				__UpperCAmelCase				:						Any=2    ,				__UpperCAmelCase				:						Tuple=True    ,				__UpperCAmelCase				:						int=2    ,				__UpperCAmelCase				:						Tuple=2    ,				**__UpperCAmelCase				:						Optional[int]    ,				)   ->    Tuple:
						SCREAMING_SNAKE_CASE__								=      vocab_size
						SCREAMING_SNAKE_CASE__								=      max_position_embeddings
						SCREAMING_SNAKE_CASE__								=      d_model
						SCREAMING_SNAKE_CASE__								=      encoder_ffn_dim
						SCREAMING_SNAKE_CASE__								=      encoder_layers
						SCREAMING_SNAKE_CASE__								=      encoder_attention_heads
						SCREAMING_SNAKE_CASE__								=      decoder_ffn_dim
						SCREAMING_SNAKE_CASE__								=      decoder_layers
						SCREAMING_SNAKE_CASE__								=      decoder_attention_heads
						SCREAMING_SNAKE_CASE__								=      dropout
						SCREAMING_SNAKE_CASE__								=      attention_dropout
						SCREAMING_SNAKE_CASE__								=      activation_dropout
						SCREAMING_SNAKE_CASE__								=      activation_function
						SCREAMING_SNAKE_CASE__								=      init_std
						SCREAMING_SNAKE_CASE__								=      encoder_layerdrop
						SCREAMING_SNAKE_CASE__								=      decoder_layerdrop
						SCREAMING_SNAKE_CASE__								=      classifier_dropout
						SCREAMING_SNAKE_CASE__								=      use_cache
						SCREAMING_SNAKE_CASE__								=      encoder_layers
						SCREAMING_SNAKE_CASE__								=      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       ):
									SCREAMING_SNAKE_CASE__								=      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    lowerCamelCase						(A__			):

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

									if self.use_past:
												SCREAMING_SNAKE_CASE__								=      {0: """batch"""}
												SCREAMING_SNAKE_CASE__								=      {0: """batch""", 1: """past_decoder_sequence + sequence"""}
									else:
												SCREAMING_SNAKE_CASE__								=      {0: """batch""", 1: """decoder_sequence"""}
												SCREAMING_SNAKE_CASE__								=      {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.
									SCREAMING_SNAKE_CASE__								=      OrderedDict(
									    [
									        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
									        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
									    ]       )
									if self.use_past:
												SCREAMING_SNAKE_CASE__							,		SCREAMING_SNAKE_CASE__								=      self.num_layers
												for i in range(__UpperCAmelCase       ):
															SCREAMING_SNAKE_CASE__								=      {0: """batch""", 2: """past_sequence + sequence"""}
															SCREAMING_SNAKE_CASE__								=      {0: """batch""", 2: """past_sequence + sequence"""}
						else:
									SCREAMING_SNAKE_CASE__								=      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				:						int       )   ->    Mapping[str, Mapping[int, str]]:
						if self.task in ["default", "seq2seq-lm"]:
									SCREAMING_SNAKE_CASE__								=      super().outputs
						else:
									SCREAMING_SNAKE_CASE__								=      super(__UpperCAmelCase    ,				self       ).outputs
									if self.use_past:
												SCREAMING_SNAKE_CASE__							,		SCREAMING_SNAKE_CASE__								=      self.num_layers
												for i in range(__UpperCAmelCase       ):
															SCREAMING_SNAKE_CASE__								=      {0: """batch""", 2: """past_sequence + sequence"""}
															SCREAMING_SNAKE_CASE__								=      {0: """batch""", 2: """past_sequence + sequence"""}
						return common_outputs

			def 					SCREAMING_SNAKE_CASE				(					self				:						Any    ,				__UpperCAmelCase				:						PreTrainedTokenizer    ,				__UpperCAmelCase				:						int = -1    ,				__UpperCAmelCase				:						int = -1    ,				__UpperCAmelCase				:						bool = False    ,				__UpperCAmelCase				:						Optional[TensorType] = None    ,				)   ->    Mapping[str, Any]:
						SCREAMING_SNAKE_CASE__								=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
						    __UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase       )

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

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

									SCREAMING_SNAKE_CASE__								=      []
									# If the number of encoder and decoder layers are present in the model configuration, both are considered
									SCREAMING_SNAKE_CASE__							,		SCREAMING_SNAKE_CASE__								=      self.num_layers
									SCREAMING_SNAKE_CASE__								=      min(__UpperCAmelCase    ,				__UpperCAmelCase       )
									SCREAMING_SNAKE_CASE__								=      max(__UpperCAmelCase    ,				__UpperCAmelCase       ) - min_num_layers
									SCREAMING_SNAKE_CASE__								=      """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.
									SCREAMING_SNAKE_CASE__								=      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 					SCREAMING_SNAKE_CASE				(					self				:						Tuple    ,				__UpperCAmelCase				:						PreTrainedTokenizer    ,				__UpperCAmelCase				:						int = -1    ,				__UpperCAmelCase				:						int = -1    ,				__UpperCAmelCase				:						bool = False    ,				__UpperCAmelCase				:						Optional[TensorType] = None    ,				)   ->    Mapping[str, Any]:
						SCREAMING_SNAKE_CASE__								=      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
									SCREAMING_SNAKE_CASE__							,		SCREAMING_SNAKE_CASE__								=      common_inputs["""input_ids"""].shape
									# Not using the same length for past_key_values
									SCREAMING_SNAKE_CASE__								=      seqlen + 2
									SCREAMING_SNAKE_CASE__							,		SCREAMING_SNAKE_CASE__								=      self.num_layers
									SCREAMING_SNAKE_CASE__							,		SCREAMING_SNAKE_CASE__								=      self.num_attention_heads
									SCREAMING_SNAKE_CASE__								=      (
									    batch,
									    num_encoder_attention_heads,
									    past_key_values_length,
									    self._config.hidden_size // num_encoder_attention_heads,
									)

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

			def 					SCREAMING_SNAKE_CASE				(					self				:						Optional[int]    ,				__UpperCAmelCase				:						PreTrainedTokenizer    ,				__UpperCAmelCase				:						int = -1    ,				__UpperCAmelCase				:						int = -1    ,				__UpperCAmelCase				:						bool = False    ,				__UpperCAmelCase				:						Optional[TensorType] = None    ,				)   ->    Mapping[str, Any]:
						# 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
						SCREAMING_SNAKE_CASE__								=      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
						SCREAMING_SNAKE_CASE__								=      tokenizer.num_special_tokens_to_add(__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      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
						SCREAMING_SNAKE_CASE__								=      [""" """.join([tokenizer.unk_token]       ) * seq_length] * batch_size
						SCREAMING_SNAKE_CASE__								=      dict(tokenizer(__UpperCAmelCase    ,				return_tensors=__UpperCAmelCase       )       )
						return common_inputs

			def 					SCREAMING_SNAKE_CASE				(					self				:						Tuple    ,				__UpperCAmelCase				:						PreTrainedTokenizer    ,				__UpperCAmelCase				:						int = -1    ,				__UpperCAmelCase				:						int = -1    ,				__UpperCAmelCase				:						bool = False    ,				__UpperCAmelCase				:						Optional[TensorType] = None    ,				)   ->    Mapping[str, Any]:
						if self.task in ["default", "seq2seq-lm"]:
									SCREAMING_SNAKE_CASE__								=      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":
									SCREAMING_SNAKE_CASE__								=      self._generate_dummy_inputs_for_causal_lm(
									    __UpperCAmelCase    ,				batch_size=__UpperCAmelCase    ,				seq_length=__UpperCAmelCase    ,				is_pair=__UpperCAmelCase    ,				framework=__UpperCAmelCase       )
						else:
									SCREAMING_SNAKE_CASE__								=      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 					SCREAMING_SNAKE_CASE				(					self				:						Union[str, Any]    ,				__UpperCAmelCase				:						Optional[int]    ,				__UpperCAmelCase				:						List[Any]    ,				__UpperCAmelCase				:						Tuple    ,				__UpperCAmelCase				:						Any       )   ->    Tuple:
						if self.task in ["default", "seq2seq-lm"]:
									SCREAMING_SNAKE_CASE__								=      super()._flatten_past_key_values_(__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase       )
						else:
									SCREAMING_SNAKE_CASE__								=      super(__UpperCAmelCase    ,				self       )._flatten_past_key_values_(
									    __UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase       )





"""simple docstring"""




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


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

A_							:			int											= {
    "caidas/swin2sr-classicalsr-x2-64": (
        "https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json"
    ),
}





class    lowerCamelCase						(A__			):
			lowerCamelCase__   :		List[str]							=							'swin2sr'

			lowerCamelCase__   :		Optional[Any]							=							{
			    'hidden_size': 'embed_dim',
			    'num_attention_heads': 'num_heads',
			    'num_hidden_layers': 'num_layers',
			}

			def __init__(					self				:						Tuple    ,				__UpperCAmelCase				:						Optional[int]=6_4    ,				__UpperCAmelCase				:						Tuple=1    ,				__UpperCAmelCase				:						Optional[Any]=3    ,				__UpperCAmelCase				:						List[str]=1_8_0    ,				__UpperCAmelCase				:						List[str]=[6, 6, 6, 6, 6, 6]    ,				__UpperCAmelCase				:						Optional[Any]=[6, 6, 6, 6, 6, 6]    ,				__UpperCAmelCase				:						Tuple=8    ,				__UpperCAmelCase				:						Union[str, Any]=2.0    ,				__UpperCAmelCase				:						int=True    ,				__UpperCAmelCase				:						Optional[Any]=0.0    ,				__UpperCAmelCase				:						str=0.0    ,				__UpperCAmelCase				:						Dict=0.1    ,				__UpperCAmelCase				:						Dict="gelu"    ,				__UpperCAmelCase				:						Tuple=False    ,				__UpperCAmelCase				:						List[str]=0.02    ,				__UpperCAmelCase				:						List[Any]=1e-5    ,				__UpperCAmelCase				:						str=2    ,				__UpperCAmelCase				:						Optional[int]=1.0    ,				__UpperCAmelCase				:						Union[str, Any]="1conv"    ,				__UpperCAmelCase				:						List[Any]="pixelshuffle"    ,				**__UpperCAmelCase				:						Any    ,				)   ->    Optional[int]:
						super().__init__(**__UpperCAmelCase       )

						SCREAMING_SNAKE_CASE__								=      image_size
						SCREAMING_SNAKE_CASE__								=      patch_size
						SCREAMING_SNAKE_CASE__								=      num_channels
						SCREAMING_SNAKE_CASE__								=      embed_dim
						SCREAMING_SNAKE_CASE__								=      depths
						SCREAMING_SNAKE_CASE__								=      len(__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      num_heads
						SCREAMING_SNAKE_CASE__								=      window_size
						SCREAMING_SNAKE_CASE__								=      mlp_ratio
						SCREAMING_SNAKE_CASE__								=      qkv_bias
						SCREAMING_SNAKE_CASE__								=      hidden_dropout_prob
						SCREAMING_SNAKE_CASE__								=      attention_probs_dropout_prob
						SCREAMING_SNAKE_CASE__								=      drop_path_rate
						SCREAMING_SNAKE_CASE__								=      hidden_act
						SCREAMING_SNAKE_CASE__								=      use_absolute_embeddings
						SCREAMING_SNAKE_CASE__								=      layer_norm_eps
						SCREAMING_SNAKE_CASE__								=      initializer_range
						SCREAMING_SNAKE_CASE__								=      upscale
						SCREAMING_SNAKE_CASE__								=      img_range
						SCREAMING_SNAKE_CASE__								=      resi_connection
						SCREAMING_SNAKE_CASE__								=      upsampler


