





"""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 		SCREAMING_SNAKE_CASE_							(    snake_case__   ):
				"""simple docstring"""
				__snake_case   :       Union[str, Any]	 =		"""longformer"""




				def __init__(     self  :str						,    __lowercase  :Union[List[int], int] = 512						,    __lowercase  :int = 2						,    __lowercase  :int = 1						,    __lowercase  :int = 0						,    __lowercase  :int = 2						,    __lowercase  :int = 3_0522						,    __lowercase  :int = 768						,    __lowercase  :int = 12						,    __lowercase  :int = 12						,    __lowercase  :int = 3072						,    __lowercase  :str = "gelu"						,    __lowercase  :float = 0.1						,    __lowercase  :float = 0.1						,    __lowercase  :int = 512						,    __lowercase  :int = 2						,    __lowercase  :float = 0.02						,    __lowercase  :float = 1e-1_2						,    __lowercase  :bool = False						,    **__lowercase  :Any						,    ):
											super().__init__(pad_token_id=__lowercase						,    **__lowercase			)

											__lowerCamelCase      :      Optional[Any]         =attention_window
											__lowerCamelCase      :      Union[str, Any]         =sep_token_id
											__lowerCamelCase      :      Tuple         =bos_token_id
											__lowerCamelCase      :      Tuple         =eos_token_id
											__lowerCamelCase      :      Optional[Any]         =vocab_size
											__lowerCamelCase      :      Tuple         =hidden_size
											__lowerCamelCase      :      List[Any]         =num_hidden_layers
											__lowerCamelCase      :      Optional[int]         =num_attention_heads
											__lowerCamelCase      :      List[Any]         =hidden_act
											__lowerCamelCase      :      Optional[Any]         =intermediate_size
											__lowerCamelCase      :      Optional[int]         =hidden_dropout_prob
											__lowerCamelCase      :      Tuple         =attention_probs_dropout_prob
											__lowerCamelCase      :      List[Any]         =max_position_embeddings
											__lowerCamelCase      :      Tuple         =type_vocab_size
											__lowerCamelCase      :      Dict         =initializer_range
											__lowerCamelCase      :      List[Any]         =layer_norm_eps
											__lowerCamelCase      :      Any         =onnx_export

class 		SCREAMING_SNAKE_CASE_							(    snake_case__   ):
				"""simple docstring"""




				def __init__(     self  :List[str]						,    __lowercase  :"PretrainedConfig"						,    __lowercase  :str = "default"						,    __lowercase  :"List[PatchingSpec]" = None			):
											super().__init__(__lowercase						,    __lowercase						,    __lowercase			)
											__lowerCamelCase      :      Optional[Any]         =True




				@property
				def 					__lowercase  (     self  :int			):
											if self.task == "multiple-choice":
																		__lowerCamelCase      :      Dict         ={0: '''batch''', 1: '''choice''', 2: '''sequence'''}
											else:
																		__lowerCamelCase      :      Optional[Any]         ={0: '''batch''', 1: '''sequence'''}
											return OrderedDict(
											    [
											        ('''input_ids''', dynamic_axis),
											        ('''attention_mask''', dynamic_axis),
											        ('''global_attention_mask''', dynamic_axis),
											    ]			)




				@property
				def 					__lowercase  (     self  :List[str]			):
											__lowerCamelCase      :      Optional[int]         =super().outputs
											if self.task == "default":
																		__lowerCamelCase      :      Tuple         ={0: '''batch'''}
											return outputs




				@property
				def 					__lowercase  (     self  :Tuple			):
											return 1e-4




				@property
				def 					__lowercase  (     self  :Optional[int]			):
											# needs to be >= 14 to support tril operator
											return max(super().default_onnx_opset						,    14			)




				def 					__lowercase  (     self  :Any						,    __lowercase  :"PreTrainedTokenizerBase"						,    __lowercase  :int = -1						,    __lowercase  :int = -1						,    __lowercase  :bool = False						,    __lowercase  :Optional[TensorType] = None						,    ):
											__lowerCamelCase      :      Optional[Any]         =super().generate_dummy_inputs(
											    preprocessor=__lowercase						,    batch_size=__lowercase						,    seq_length=__lowercase						,    is_pair=__lowercase						,    framework=__lowercase			)
											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      :      Tuple         =torch.zeros_like(inputs['''input_ids''']			)
											# make every second token global
											__lowerCamelCase      :      List[str]         =1

											return inputs











"""simple docstring"""





from typing import List, Optional, Union

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


_UpperCamelCase							=      logging.get_logger(__name__)

_UpperCamelCase							=      {
    'huggingface/time-series-transformer-tourism-monthly': (
        'https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json'
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}
class 		SCREAMING_SNAKE_CASE_							(    snake_case__   ):
				"""simple docstring"""
				__snake_case   :       Union[str, Any]	 =		"""time_series_transformer"""
				__snake_case   :       Any	 =		{
				    """hidden_size""": """d_model""",
				    """num_attention_heads""": """encoder_attention_heads""",
				    """num_hidden_layers""": """encoder_layers""",
				}




				def __init__(     self  :List[Any]						,    __lowercase  :Optional[int] = None						,    __lowercase  :Optional[int] = None						,    __lowercase  :str = "student_t"						,    __lowercase  :str = "nll"						,    __lowercase  :int = 1						,    __lowercase  :List[int] = [1, 2, 3, 4, 5, 6, 7]						,    __lowercase  :Optional[Union[str, bool]] = "mean"						,    __lowercase  :int = 0						,    __lowercase  :int = 0						,    __lowercase  :int = 0						,    __lowercase  :int = 0						,    __lowercase  :Optional[List[int]] = None						,    __lowercase  :Optional[List[int]] = None						,    __lowercase  :int = 32						,    __lowercase  :int = 32						,    __lowercase  :int = 2						,    __lowercase  :int = 2						,    __lowercase  :int = 2						,    __lowercase  :int = 2						,    __lowercase  :bool = True						,    __lowercase  :str = "gelu"						,    __lowercase  :int = 64						,    __lowercase  :float = 0.1						,    __lowercase  :float = 0.1						,    __lowercase  :float = 0.1						,    __lowercase  :float = 0.1						,    __lowercase  :float = 0.1						,    __lowercase  :int = 100						,    __lowercase  :float = 0.02						,    __lowercase  :int=True						,    **__lowercase  :Optional[Any]						,    ):
											# time series specific configuration
											__lowerCamelCase      :      Tuple         =prediction_length
											__lowerCamelCase      :      List[Any]         =context_length or prediction_length
											__lowerCamelCase      :      Dict         =distribution_output
											__lowerCamelCase      :      str         =loss
											__lowerCamelCase      :      Tuple         =input_size
											__lowerCamelCase      :      int         =num_time_features
											__lowerCamelCase      :      int         =lags_sequence
											__lowerCamelCase      :      Optional[int]         =scaling
											__lowerCamelCase      :      str         =num_dynamic_real_features
											__lowerCamelCase      :      Optional[Any]         =num_static_real_features
											__lowerCamelCase      :      List[Any]         =num_static_categorical_features
											if cardinality and num_static_categorical_features > 0:
																		if len(__lowercase			) != num_static_categorical_features:
																									raise ValueError(
																									    '''The cardinality should be a list of the same length as `num_static_categorical_features`'''			)
																		__lowerCamelCase      :      Optional[int]         =cardinality
											else:
																		__lowerCamelCase      :      str         =[0]
											if embedding_dimension and num_static_categorical_features > 0:
																		if len(__lowercase			) != num_static_categorical_features:
																									raise ValueError(
																									    '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''			)
																		__lowerCamelCase      :      int         =embedding_dimension
											else:
																		__lowerCamelCase      :      Optional[int]         =[min(50						,    (cat + 1) // 2			) for cat in self.cardinality]
											__lowerCamelCase      :      List[str]         =num_parallel_samples

											# Transformer architecture configuration
											__lowerCamelCase      :      str         =input_size * len(__lowercase			) + self._number_of_features
											__lowerCamelCase      :      Union[str, Any]         =d_model
											__lowerCamelCase      :      int         =encoder_attention_heads
											__lowerCamelCase      :      int         =decoder_attention_heads
											__lowerCamelCase      :      Dict         =encoder_ffn_dim
											__lowerCamelCase      :      int         =decoder_ffn_dim
											__lowerCamelCase      :      List[Any]         =encoder_layers
											__lowerCamelCase      :      int         =decoder_layers

											__lowerCamelCase      :      Union[str, Any]         =dropout
											__lowerCamelCase      :      Optional[Any]         =attention_dropout
											__lowerCamelCase      :      List[str]         =activation_dropout
											__lowerCamelCase      :      List[str]         =encoder_layerdrop
											__lowerCamelCase      :      int         =decoder_layerdrop

											__lowerCamelCase      :      Tuple         =activation_function
											__lowerCamelCase      :      str         =init_std

											__lowerCamelCase      :      Dict         =use_cache

											super().__init__(is_encoder_decoder=__lowercase						,    **__lowercase			)




				@property
				def 					__lowercase  (     self  :int			):
											return (
											    sum(self.embedding_dimension			)
											    + self.num_dynamic_real_features
											    + self.num_time_features
											    + self.num_static_real_features
											    + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
											)




