






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   lowerCamelCase      (_snake_case			):







		'''simple docstring'''



		_snake_case    :    str       						=  '''time_series_transformer'''
		_snake_case    :    Optional[int]       						=  {
		    '''hidden_size''': '''d_model''',
		    '''num_attention_heads''': '''encoder_attention_heads''',
		    '''num_hidden_layers''': '''encoder_layers''',
		}



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

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

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

							UpperCAmelCase_    :      int            =						activation_function
							UpperCAmelCase_    :      List[Any]            =						init_std

							UpperCAmelCase_    :      Optional[Any]            =						use_cache

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



		@property
		def 					__UpperCAmelCase			(							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
							)














import importlib
import shutil
import threading
import warnings
from typing import List

import fsspec
import fsspec.asyn

from . import compression
from .hffilesystem import HfFileSystem


__UpperCAmelCase								=						importlib.util.find_spec('s3fs') is not None

if _has_safs:
		from .safilesystem import SaFileSystem  # noqa: F401

__UpperCAmelCase								=						[
    compression.BzaFileSystem,
    compression.GzipFileSystem,
    compression.LzaFileSystem,
    compression.XzFileSystem,
    compression.ZstdFileSystem,
]

# Register custom filesystems
for fs_class in COMPRESSION_FILESYSTEMS + [HfFileSystem]:
		if fs_class.protocol in fsspec.registry and fsspec.registry[fs_class.protocol] is not fs_class:
				warnings.warn(F'A filesystem protocol was already set for {fs_class.protocol} and will be overwritten.')
		fsspec.register_implementation(fs_class.protocol, fs_class, clobber=True)




def      lowercase__      (     __snake_case    :							str  ):


					'''simple docstring'''


					if "://" in dataset_path:
										UpperCAmelCase_    :      int            =						dataset_path.split('://'  )[1]
					return dataset_path




def      lowercase__      (     __snake_case    :							fsspec.AbstractFileSystem  ):


					'''simple docstring'''


					if fs is not None and fs.protocol != "file":
										return True
					else:
										return False




def      lowercase__      (     __snake_case    :							fsspec.AbstractFileSystem     ,       __snake_case    :							str     ,       __snake_case    :							str  ):


					'''simple docstring'''


					UpperCAmelCase_    :      List[str]            =						not is_remote_filesystem(__snake_case  )
					if is_local:
										# LocalFileSystem.mv does copy + rm, it is more efficient to simply move a local directory
										shutil.move(fs._strip_protocol(__snake_case  )     ,       fs._strip_protocol(__snake_case  )  )
					else:
										fs.mv(__snake_case     ,       __snake_case     ,       recursive=__snake_case  )






def      lowercase__      (     ):


					'''simple docstring'''


					if hasattr(fsspec.asyn     ,       'reset_lock'  ):
										# for future fsspec>2022.05.0
										fsspec.asyn.reset_lock()
					else:
										UpperCAmelCase_    :      Optional[Any]            =						None
										UpperCAmelCase_    :      Union[str, Any]            =						None
										UpperCAmelCase_    :      int            =						threading.Lock()






