

from typing import List, Optional

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


_SCREAMING_SNAKE_CASE	:    Optional[Any]       =     logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE	:    Dict       =     {
    '''huggingface/autoformer-tourism-monthly''': '''https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json''',
}






class 			UpperCAmelCase__						(			_UpperCamelCase			):






  """simple docstring"""


  a 	=   '''autoformer'''
  a 	=   {
      '''hidden_size''': '''d_model''',
      '''num_attention_heads''': '''encoder_attention_heads''',
      '''num_hidden_layers''': '''encoder_layers''',
  }






  def __init__(				self		:						Any      ,  __lowerCamelCase		:						Tuple = None      ,  __lowerCamelCase		:						Union[str, Any] = None      ,  __lowerCamelCase		:						Optional[Any] = "student_t"      ,  __lowerCamelCase		:						Any = "nll"      ,  __lowerCamelCase		:						Dict = 1      ,  __lowerCamelCase		:						str = [1, 2, 3, 4, 5, 6, 7]      ,  __lowerCamelCase		:						List[Any] = True      ,  __lowerCamelCase		:						Optional[int] = 0      ,  __lowerCamelCase		:						List[Any] = 0      ,  __lowerCamelCase		:						Dict = 0      ,  __lowerCamelCase		:						Optional[Any] = 0      ,  __lowerCamelCase		:						List[Any] = None      ,  __lowerCamelCase		:						int = None      ,  __lowerCamelCase		:						Optional[int] = 64      ,  __lowerCamelCase		:						Dict = 2      ,  __lowerCamelCase		:						List[Any] = 2      ,  __lowerCamelCase		:						List[str] = 2      ,  __lowerCamelCase		:						List[str] = 2      ,  __lowerCamelCase		:						List[str] = 32      ,  __lowerCamelCase		:						List[str] = 32      ,  __lowerCamelCase		:						int = "gelu"      ,  __lowerCamelCase		:						Tuple = 0.1      ,  __lowerCamelCase		:						Optional[Any] = 0.1      ,  __lowerCamelCase		:						int = 0.1      ,  __lowerCamelCase		:						Any = 0.1      ,  __lowerCamelCase		:						List[str] = 0.1      ,  __lowerCamelCase		:						Union[str, Any] = 100      ,  __lowerCamelCase		:						Union[str, Any] = 0.02      ,  __lowerCamelCase		:						List[str] = True      ,  __lowerCamelCase		:						List[str]=True      ,  __lowerCamelCase		:						str = 10      ,  __lowerCamelCase		:						Dict = 25      ,  __lowerCamelCase		:						Tuple = 3      ,  **__lowerCamelCase		:						Dict      ,  )						->				List[Any]:
       # time series specific configuration
       SCREAMING_SNAKE_CASE__       =       prediction_length
       SCREAMING_SNAKE_CASE__       =       context_length if context_length is not None else prediction_length
       SCREAMING_SNAKE_CASE__       =       distribution_output
       SCREAMING_SNAKE_CASE__       =       loss
       SCREAMING_SNAKE_CASE__       =       input_size
       SCREAMING_SNAKE_CASE__       =       num_time_features
       SCREAMING_SNAKE_CASE__       =       lags_sequence
       SCREAMING_SNAKE_CASE__       =       scaling
       SCREAMING_SNAKE_CASE__       =       num_dynamic_real_features
       SCREAMING_SNAKE_CASE__       =       num_static_real_features
       SCREAMING_SNAKE_CASE__       =       num_static_categorical_features
       if cardinality is not None 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`'''   )
            SCREAMING_SNAKE_CASE__       =       cardinality
       else:
            SCREAMING_SNAKE_CASE__       =       [0]
       if embedding_dimension is not None 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`'''   )
            SCREAMING_SNAKE_CASE__       =       embedding_dimension
       else:
            SCREAMING_SNAKE_CASE__       =       [min(50      ,  (cat + 1) // 2   ) for cat in self.cardinality]
       SCREAMING_SNAKE_CASE__       =       num_parallel_samples

       # Transformer architecture configuration
       SCREAMING_SNAKE_CASE__       =       input_size * len(self.lags_sequence   ) + self._number_of_features
       SCREAMING_SNAKE_CASE__       =       d_model
       SCREAMING_SNAKE_CASE__       =       encoder_attention_heads
       SCREAMING_SNAKE_CASE__       =       decoder_attention_heads
       SCREAMING_SNAKE_CASE__       =       encoder_ffn_dim
       SCREAMING_SNAKE_CASE__       =       decoder_ffn_dim
       SCREAMING_SNAKE_CASE__       =       encoder_layers
       SCREAMING_SNAKE_CASE__       =       decoder_layers

       SCREAMING_SNAKE_CASE__       =       dropout
       SCREAMING_SNAKE_CASE__       =       attention_dropout
       SCREAMING_SNAKE_CASE__       =       activation_dropout
       SCREAMING_SNAKE_CASE__       =       encoder_layerdrop
       SCREAMING_SNAKE_CASE__       =       decoder_layerdrop

       SCREAMING_SNAKE_CASE__       =       activation_function
       SCREAMING_SNAKE_CASE__       =       init_std

       SCREAMING_SNAKE_CASE__       =       use_cache

       # Autoformer
       SCREAMING_SNAKE_CASE__       =       label_length
       SCREAMING_SNAKE_CASE__       =       moving_average
       SCREAMING_SNAKE_CASE__       =       autocorrelation_factor

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







  @property
  def  lowercase_						(				self		:						Tuple   )						->				List[Any]:
       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
       )






import os
from shutil import copyfile
from typing import List, Optional, Tuple

from tokenizers import processors

from ...tokenization_utils import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
				from .tokenization_mbart import MBartTokenizer
else:
				lowerCAmelCase       		=    None


lowerCAmelCase       		=    logging.get_logger(__name__)


lowerCAmelCase       		=    {"""vocab_file""": """sentencepiece.bpe.model""", """tokenizer_file""": """tokenizer.json"""}

lowerCAmelCase       		=    {
    """vocab_file""": {
        """facebook/mbart-large-en-ro""": (
            """https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/sentencepiece.bpe.model"""
        ),
        """facebook/mbart-large-cc25""": (
            """https://huggingface.co/facebook/mbart-large-cc25/resolve/main/sentencepiece.bpe.model"""
        ),
    },
    """tokenizer_file""": {
        """facebook/mbart-large-en-ro""": """https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/tokenizer.json""",
        """facebook/mbart-large-cc25""": """https://huggingface.co/facebook/mbart-large-cc25/resolve/main/tokenizer.json""",
    },
}

lowerCAmelCase       		=    {
    """facebook/mbart-large-en-ro""": 1_024,
    """facebook/mbart-large-cc25""": 1_024,
}

# fmt: off
lowerCAmelCase       		=    ["""ar_AR""", """cs_CZ""", """de_DE""", """en_XX""", """es_XX""", """et_EE""", """fi_FI""", """fr_XX""", """gu_IN""", """hi_IN""", """it_IT""", """ja_XX""", """kk_KZ""", """ko_KR""", """lt_LT""", """lv_LV""", """my_MM""", """ne_NP""", """nl_XX""", """ro_RO""", """ru_RU""", """si_LK""", """tr_TR""", """vi_VN""", """zh_CN"""]




class 							lowerCamelCase   (  _UpperCamelCase ):
	_lowerCAmelCase     :		List[str]										=						VOCAB_FILES_NAMES
	_lowerCAmelCase     :		Union[str, Any]										=						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	_lowerCAmelCase     :		str										=						PRETRAINED_VOCAB_FILES_MAP
	_lowerCAmelCase     :		Optional[int]										=						['''input_ids''', '''attention_mask''']
	_lowerCAmelCase     :		Optional[int]										=						MBartTokenizer

	_lowerCAmelCase     :		List[int]										=						[]
	_lowerCAmelCase     :		List[int]										=						[]


	def __init__(    self				,     lowercase__=None				,     lowercase__=None				,     lowercase__="<s>"				,     lowercase__="</s>"				,     lowercase__="</s>"				,     lowercase__="<s>"				,     lowercase__="<unk>"				,     lowercase__="<pad>"				,     lowercase__="<mask>"				,     lowercase__=None				,     lowercase__=None				,     lowercase__=None				,     **lowercase__				,     ):
							# Mask token behave like a normal word, i.e. include the space before it
							__UpperCAmelCase			:							Any	    =	AddedToken(lowercase__				,     lstrip=lowercase__				,     rstrip=lowercase__) if isinstance(lowercase__				,     lowercase__) else mask_token

							super().__init__(
							    vocab_file=lowercase__				,     tokenizer_file=lowercase__				,     bos_token=lowercase__				,     eos_token=lowercase__				,     sep_token=lowercase__				,     cls_token=lowercase__				,     unk_token=lowercase__				,     pad_token=lowercase__				,     mask_token=lowercase__				,     src_lang=lowercase__				,     tgt_lang=lowercase__				,     additional_special_tokens=lowercase__				,     **lowercase__				,     )

							__UpperCAmelCase			:							Optional[Any]	    =	vocab_file
							__UpperCAmelCase			:							int	    =	False if not self.vocab_file else True

							__UpperCAmelCase			:							str	    =	FAIRSEQ_LANGUAGE_CODES.copy()

							if additional_special_tokens is not None:
													# Only add those special tokens if they are not already there.
													_additional_special_tokens.extend(
													    [t for t in additional_special_tokens if t not in _additional_special_tokens])

							self.add_special_tokens({'''additional_special_tokens''': _additional_special_tokens})
							__UpperCAmelCase			:							Union[str, Any]	    =	{
							    lang_code: self.convert_tokens_to_ids(lowercase__) for lang_code in FAIRSEQ_LANGUAGE_CODES
							}

							__UpperCAmelCase			:							Any	    =	src_lang if src_lang is not None else '''en_XX'''
							__UpperCAmelCase			:							Optional[int]	    =	self.convert_tokens_to_ids(self._src_lang)
							__UpperCAmelCase			:							List[Any]	    =	tgt_lang
							self.set_src_lang_special_tokens(self._src_lang)


	@property
	def  A(    self):
							return self._src_lang


	@src_lang.setter
	def  A(    self				,     lowercase__):
							__UpperCAmelCase			:							List[str]	    =	new_src_lang
							self.set_src_lang_special_tokens(self._src_lang)


	def  A(    self				,     lowercase__				,     lowercase__ = None):
							if token_ids_a is None:
													return self.prefix_tokens + token_ids_a + self.suffix_tokens
							# We don't expect to process pairs, but leave the pair logic for API consistency
							return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens


	def  A(    self				,     lowercase__				,     lowercase__ = None):
							__UpperCAmelCase			:							Optional[int]	    =	[self.sep_token_id]
							__UpperCAmelCase			:							int	    =	[self.cls_token_id]

							if token_ids_a is None:
													return len(cls + token_ids_a + sep) * [0]
							return len(cls + token_ids_a + sep + sep + token_ids_a + sep) * [0]


	def  A(    self				,     lowercase__				,     lowercase__				,     lowercase__				,     lowercase__				,     **lowercase__):
							if src_lang is None or tgt_lang is None:
													raise ValueError('''Translation requires a `src_lang` and a `tgt_lang` for this model''')
							__UpperCAmelCase			:							Optional[Any]	    =	src_lang
							__UpperCAmelCase			:							Union[str, Any]	    =	self(lowercase__				,     add_special_tokens=lowercase__				,     return_tensors=lowercase__				,     **lowercase__)
							__UpperCAmelCase			:							int	    =	self.convert_tokens_to_ids(lowercase__)
							__UpperCAmelCase			:							Tuple	    =	tgt_lang_id
							return inputs


	def  A(    self				,     lowercase__				,     lowercase__ = "en_XX"				,     lowercase__ = None				,     lowercase__ = "ro_RO"				,     **lowercase__				,     ):
							__UpperCAmelCase			:							Any	    =	src_lang
							__UpperCAmelCase			:							Tuple	    =	tgt_lang
							return super().prepare_seqaseq_batch(lowercase__				,     lowercase__				,     **lowercase__)


	def  A(    self):
							return self.set_src_lang_special_tokens(self.src_lang)


	def  A(    self):
							return self.set_tgt_lang_special_tokens(self.tgt_lang)


	def  A(    self				,     lowercase__):
							__UpperCAmelCase			:							Optional[Any]	    =	self.convert_tokens_to_ids(lowercase__)
							__UpperCAmelCase			:							Union[str, Any]	    =	[]
							__UpperCAmelCase			:							Dict	    =	[self.eos_token_id, self.cur_lang_code]

							__UpperCAmelCase			:							int	    =	self.convert_ids_to_tokens(self.prefix_tokens)
							__UpperCAmelCase			:							Dict	    =	self.convert_ids_to_tokens(self.suffix_tokens)

							__UpperCAmelCase			:							str	    =	processors.TemplateProcessing(
							    single=prefix_tokens_str + ['''$A'''] + suffix_tokens_str				,     pair=prefix_tokens_str + ['''$A''', '''$B'''] + suffix_tokens_str				,     special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str				,     self.prefix_tokens + self.suffix_tokens))				,     )


	def  A(    self				,     lowercase__):
							__UpperCAmelCase			:							List[str]	    =	self.convert_tokens_to_ids(lowercase__)
							__UpperCAmelCase			:							List[Any]	    =	[]
							__UpperCAmelCase			:							List[Any]	    =	[self.eos_token_id, self.cur_lang_code]

							__UpperCAmelCase			:							Tuple	    =	self.convert_ids_to_tokens(self.prefix_tokens)
							__UpperCAmelCase			:							Tuple	    =	self.convert_ids_to_tokens(self.suffix_tokens)

							__UpperCAmelCase			:							Optional[int]	    =	processors.TemplateProcessing(
							    single=prefix_tokens_str + ['''$A'''] + suffix_tokens_str				,     pair=prefix_tokens_str + ['''$A''', '''$B'''] + suffix_tokens_str				,     special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str				,     self.prefix_tokens + self.suffix_tokens))				,     )


	def  A(    self				,     lowercase__				,     lowercase__ = None):
							if not self.can_save_slow_tokenizer:
													raise ValueError(
													    '''Your fast tokenizer does not have the necessary information to save the vocabulary for a slow '''
													    '''tokenizer.''')

							if not os.path.isdir(lowercase__):
													logger.error(F"Vocabulary path ({save_directory}) should be a directory.")
													return
							__UpperCAmelCase			:							List[Any]	    =	os.path.join(
							    lowercase__				,     (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file'''])

							if os.path.abspath(self.vocab_file) != os.path.abspath(lowercase__):
													copyfile(self.vocab_file				,     lowercase__)

							return (out_vocab_file,)

