



'''simple docstring'''




from typing import List, Optional, Union

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


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

UpperCamelCase__       :	str    = {
    '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 						_UpperCamelCase  (							__SCREAMING_SNAKE_CASE    ):


			'''simple docstring'''

			_A      :		Union[str, Any]			    =		'''time_series_transformer'''
			_A      :		int			    =		{
			    '''hidden_size''': '''d_model''',
			    '''num_attention_heads''': '''encoder_attention_heads''',
			    '''num_hidden_layers''': '''encoder_layers''',
			}

			def __init__(							self     : Tuple							,     lowerCAmelCase__     : Optional[int] = None							,     lowerCAmelCase__     : Optional[int] = None							,     lowerCAmelCase__     : str = "student_t"							,     lowerCAmelCase__     : str = "nll"							,     lowerCAmelCase__     : int = 1							,     lowerCAmelCase__     : List[int] = [1, 2, 3, 4, 5, 6, 7]							,     lowerCAmelCase__     : Optional[Union[str, bool]] = "mean"							,     lowerCAmelCase__     : int = 0							,     lowerCAmelCase__     : int = 0							,     lowerCAmelCase__     : int = 0							,     lowerCAmelCase__     : int = 0							,     lowerCAmelCase__     : Optional[List[int]] = None							,     lowerCAmelCase__     : Optional[List[int]] = None							,     lowerCAmelCase__     : int = 3_2							,     lowerCAmelCase__     : int = 3_2							,     lowerCAmelCase__     : int = 2							,     lowerCAmelCase__     : int = 2							,     lowerCAmelCase__     : int = 2							,     lowerCAmelCase__     : int = 2							,     lowerCAmelCase__     : bool = True							,     lowerCAmelCase__     : str = "gelu"							,     lowerCAmelCase__     : int = 6_4							,     lowerCAmelCase__     : float = 0.1							,     lowerCAmelCase__     : float = 0.1							,     lowerCAmelCase__     : float = 0.1							,     lowerCAmelCase__     : float = 0.1							,     lowerCAmelCase__     : float = 0.1							,     lowerCAmelCase__     : int = 1_0_0							,     lowerCAmelCase__     : float = 0.02							,     lowerCAmelCase__     : Union[str, Any]=True							,     **lowerCAmelCase__     : Optional[int]							,     ):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Any           =		prediction_length
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		context_length or prediction_length
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		distribution_output
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		loss
					__SCREAMING_SNAKE_CASE       :		Tuple           =		input_size
					__SCREAMING_SNAKE_CASE       :		Any           =		num_time_features
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		lags_sequence
					__SCREAMING_SNAKE_CASE       :		Dict           =		scaling
					__SCREAMING_SNAKE_CASE       :		List[str]           =		num_dynamic_real_features
					__SCREAMING_SNAKE_CASE       :		Tuple           =		num_static_real_features
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		num_static_categorical_features
					if cardinality and num_static_categorical_features > 0:
							if len(lowerCAmelCase__						) != num_static_categorical_features:
									raise ValueError(
									    """The cardinality should be a list of the same length as `num_static_categorical_features`"""						)
							__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		cardinality
					else:
							__SCREAMING_SNAKE_CASE       :		List[Any]           =		[0]
					if embedding_dimension and num_static_categorical_features > 0:
							if len(lowerCAmelCase__						) != 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       :		Any           =		embedding_dimension
					else:
							__SCREAMING_SNAKE_CASE       :		Dict           =		[min(5_0							,     (cat + 1) // 2						) for cat in self.cardinality]
					__SCREAMING_SNAKE_CASE       :		List[str]           =		num_parallel_samples

					# Transformer architecture configuration
					__SCREAMING_SNAKE_CASE       :		List[str]           =		input_size * len(lowerCAmelCase__						) + self._number_of_features
					__SCREAMING_SNAKE_CASE       :		Dict           =		d_model
					__SCREAMING_SNAKE_CASE       :		Dict           =		encoder_attention_heads
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		decoder_attention_heads
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		encoder_ffn_dim
					__SCREAMING_SNAKE_CASE       :		int           =		decoder_ffn_dim
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		encoder_layers
					__SCREAMING_SNAKE_CASE       :		Tuple           =		decoder_layers

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

					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		activation_function
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		init_std

					__SCREAMING_SNAKE_CASE       :		str           =		use_cache

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



			@property
			def UpperCamelCase__					(							self     : Optional[Any]						):





					"""simple docstring"""






					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 Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


SCREAMING_SNAKE_CASE							:Optional[int]							 =				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE							:Optional[int]							 =				{'vocab_file': 'sentencepiece.bpe.model'}

SCREAMING_SNAKE_CASE							:Tuple							 =				{
    'vocab_file': {
        'camembert-base': 'https://huggingface.co/camembert-base/resolve/main/sentencepiece.bpe.model',
    }
}

SCREAMING_SNAKE_CASE							:List[Any]							 =				{
    'camembert-base': 512,
}

SCREAMING_SNAKE_CASE							:List[str]							 =				'▁'





class 							UpperCAmelCase      (  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_					    =     VOCAB_FILES_NAMES
	snake_case_					    =     PRETRAINED_VOCAB_FILES_MAP
	snake_case_					    =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	snake_case_					    =     ["input_ids", "attention_mask"]






	def __init__(       self					: Optional[Any]							,A					: List[str]							,A					: List[Any]="<s>"							,A					: Tuple="</s>"							,A					: Any="</s>"							,A					: Optional[Any]="<s>"							,A					: Tuple="<unk>"							,A					: str="<pad>"							,A					: int="<mask>"							,A					: Optional[int]=["<s>NOTUSED", "</s>NOTUSED"]							,A					: Optional[Dict[str, Any]] = None							,**A					: Optional[Any]							,):
					# Mask token behave like a normal word, i.e. include the space before it
					__A   			= AddedToken(A							,lstrip=A							,rstrip=A ) if isinstance(A							,A ) else mask_token

					__A   			= {} if sp_model_kwargs is None else sp_model_kwargs

					super().__init__(
					    bos_token=A							,eos_token=A							,unk_token=A							,sep_token=A							,cls_token=A							,pad_token=A							,mask_token=A							,additional_special_tokens=A							,sp_model_kwargs=self.sp_model_kwargs							,**A							,)
					__A   			= spm.SentencePieceProcessor(**self.sp_model_kwargs )
					self.sp_model.Load(str(A ) )
					__A   			= vocab_file
					# HACK: These tokens were added by fairseq but don't seem to be actually used when duplicated in the actual
					# sentencepiece vocabulary (this is the case for <s> and </s>
					__A   			= {"<s>NOTUSED": 0, "<pad>": 1, "</s>NOTUSED": 2, "<unk>": 3}
					__A   			= len(self.fairseq_tokens_to_ids )
					__A   			= len(self.sp_model ) + len(self.fairseq_tokens_to_ids )
					__A   			= {v: k for k, v in self.fairseq_tokens_to_ids.items()}






	def 				UpperCamelCase_  (       self					: int							,A					: List[int]							,A					: Optional[List[int]] = None ):

					if token_ids_a is None:
									return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
					__A   			= [self.cls_token_id]
					__A   			= [self.sep_token_id]
					return cls + token_ids_a + sep + sep + token_ids_a + sep






	def 				UpperCamelCase_  (       self					: Dict							,A					: List[int]							,A					: Optional[List[int]] = None							,A					: bool = False ):
					if already_has_special_tokens:
									return super().get_special_tokens_mask(
									    token_ids_a=A							,token_ids_a=A							,already_has_special_tokens=A )

					if token_ids_a is None:
									return [1] + ([0] * len(A )) + [1]
					return [1] + ([0] * len(A )) + [1, 1] + ([0] * len(A )) + [1]






	def 				UpperCamelCase_  (       self					: Union[str, Any]							,A					: List[int]							,A					: Optional[List[int]] = None ):
					__A   			= [self.sep_token_id]
					__A   			= [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]






	@property
	def 				UpperCamelCase_  (       self					: Dict ):
					return len(self.fairseq_tokens_to_ids ) + len(self.sp_model )






	def 				UpperCamelCase_  (       self					: int ):
					__A   			= {self.convert_ids_to_tokens(A ): i for i in range(self.vocab_size )}
					vocab.update(self.added_tokens_encoder )
					return vocab






	def 				UpperCamelCase_  (       self					: Any							,A					: str ):
					return self.sp_model.encode(A							,out_type=A )






	def 				UpperCamelCase_  (       self					: List[str]							,A					: Dict ):
					if token in self.fairseq_tokens_to_ids:
									return self.fairseq_tokens_to_ids[token]
					elif self.sp_model.PieceToId(A ) == 0:
									# Convert sentence piece unk token to fairseq unk token index
									return self.unk_token_id
					return self.fairseq_offset + self.sp_model.PieceToId(A )






	def 				UpperCamelCase_  (       self					: Dict							,A					: Tuple ):
					if index in self.fairseq_ids_to_tokens:
									return self.fairseq_ids_to_tokens[index]
					return self.sp_model.IdToPiece(index - self.fairseq_offset )






	def 				UpperCamelCase_  (       self					: Optional[Any]							,A					: Dict ):
					__A   			= []
					__A   			= ""
					__A   			= False
					for token in tokens:
									# make sure that special tokens are not decoded using sentencepiece model
									if token in self.all_special_tokens:
													if not prev_is_special:
																	out_string += " "
													out_string += self.sp_model.decode(A ) + token
													__A   			= True
													__A   			= []
									else:
													current_sub_tokens.append(A )
													__A   			= False
					out_string += self.sp_model.decode(A )
					return out_string.strip()






	def __getstate__(       self					: Dict ):
					__A   			= self.__dict__.copy()
					__A   			= None
					return state






	def __setstate__(       self					: Union[str, Any]							,A					: Any ):
					__A   			= d

					# for backward compatibility
					if not hasattr(self							,"sp_model_kwargs" ):
									__A   			= {}

					__A   			= spm.SentencePieceProcessor(**self.sp_model_kwargs )
					self.sp_model.Load(self.vocab_file )







	def 				UpperCamelCase_  (       self					: Any							,A					: str							,A					: Optional[str] = None ):
					if not os.path.isdir(A ):
									logger.error(f'''Vocabulary path ({save_directory}) should be a directory''' )
									return
					__A   			= os.path.join(
					    A							,(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"] )

					if os.path.abspath(self.vocab_file ) != os.path.abspath(A ) and os.path.isfile(self.vocab_file ):
									copyfile(self.vocab_file							,A )
					elif not os.path.isfile(self.vocab_file ):
									with open(A							,"wb" ) as fi:
													__A   			= self.sp_model.serialized_model_proto()
													fi.write(A )

					return (out_vocab_file,)
