



from typing import List, Optional

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


UpperCAmelCase__     = logging.get_logger(__name__)

UpperCAmelCase__     = {
    "huggingface/autoformer-tourism-monthly": "https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json",
}







class     __lowerCAmelCase					(    A		):
			UpperCamelCase           =  '''autoformer'''
			UpperCamelCase           =  {
			    '''hidden_size''': '''d_model''',
			    '''num_attention_heads''': '''encoder_attention_heads''',
			    '''num_hidden_layers''': '''encoder_layers''',
			}



			def __init__(		self     :						Optional[int]				,	A     :						Optional[int] = None				,	A     :						Optional[int] = None				,	A     :						str = "student_t"				,	A     :						str = "nll"				,	A     :						int = 1				,	A     :						List[int] = [1, 2, 3, 4, 5, 6, 7]				,	A     :						bool = True				,	A     :						int = 0				,	A     :						int = 0				,	A     :						int = 0				,	A     :						int = 0				,	A     :						Optional[List[int]] = None				,	A     :						Optional[List[int]] = None				,	A     :						int = 64				,	A     :						int = 2				,	A     :						int = 2				,	A     :						int = 2				,	A     :						int = 2				,	A     :						int = 32				,	A     :						int = 32				,	A     :						str = "gelu"				,	A     :						float = 0.1				,	A     :						float = 0.1				,	A     :						float = 0.1				,	A     :						float = 0.1				,	A     :						float = 0.1				,	A     :						int = 1_00				,	A     :						float = 0.0_2				,	A     :						bool = True				,	A     :						List[Any]=True				,	A     :						int = 10				,	A     :						int = 25				,	A     :						int = 3				,	**A     :						Optional[Any]				,	)     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     prediction_length
						_UpperCAmelCase	 =     context_length if context_length is not None else prediction_length
						_UpperCAmelCase	 =     distribution_output
						_UpperCAmelCase	 =     loss
						_UpperCAmelCase	 =     input_size
						_UpperCAmelCase	 =     num_time_features
						_UpperCAmelCase	 =     lags_sequence
						_UpperCAmelCase	 =     scaling
						_UpperCAmelCase	 =     num_dynamic_real_features
						_UpperCAmelCase	 =     num_static_real_features
						_UpperCAmelCase	 =     num_static_categorical_features
						if cardinality is not None and num_static_categorical_features > 0:
									if len(A) != num_static_categorical_features:
												raise ValueError(
												    'The cardinality should be a list of the same length as `num_static_categorical_features`')
									_UpperCAmelCase	 =     cardinality
						else:
									_UpperCAmelCase	 =     [0]
						if embedding_dimension is not None and num_static_categorical_features > 0:
									if len(A) != num_static_categorical_features:
												raise ValueError(
												    'The embedding dimension should be a list of the same length as `num_static_categorical_features`')
									_UpperCAmelCase	 =     embedding_dimension
						else:
									_UpperCAmelCase	 =     [min(50				,	(cat + 1) // 2) for cat in self.cardinality]
						_UpperCAmelCase	 =     num_parallel_samples

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

						_UpperCAmelCase	 =     dropout
						_UpperCAmelCase	 =     attention_dropout
						_UpperCAmelCase	 =     activation_dropout
						_UpperCAmelCase	 =     encoder_layerdrop
						_UpperCAmelCase	 =     decoder_layerdrop

						_UpperCAmelCase	 =     activation_function
						_UpperCAmelCase	 =     init_std

						_UpperCAmelCase	 =     use_cache

						# Autoformer
						_UpperCAmelCase	 =     label_length
						_UpperCAmelCase	 =     moving_average
						_UpperCAmelCase	 =     autocorrelation_factor

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



			@property
			def 					_lowerCamelCase (		self     :						str)     ->					int:



						"""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 json
import os
import unittest

from transformers import MgpstrTokenizer
from transformers.models.mgp_str.tokenization_mgp_str import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class     __lowerCAmelCase					(    A       ,		unittest.TestCase		):
			UpperCamelCase           =  MgpstrTokenizer
			UpperCamelCase           =  False
			UpperCamelCase           =  {}
			UpperCamelCase           =  False



			def 					_lowerCamelCase (		self     :						int)     ->					List[Any]:



						"""simple docstring"""






						super().setUp()

						# fmt: off
						_UpperCAmelCase	 =     ['[GO]', '[s]', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
						# fmt: on
						_UpperCAmelCase	 =     dict(zip(A				,	range(len(A))))

						_UpperCAmelCase	 =     os.path.join(self.tmpdirname				,	VOCAB_FILES_NAMES['vocab_file'])
						with open(self.vocab_file				,	'w'				,	encoding='utf-8') as fp:
									fp.write(json.dumps(A) + '\n')



			def 					_lowerCamelCase (		self     :						Dict				,	**A     :						List[Any])     ->					Optional[Any]:



						"""simple docstring"""






						return MgpstrTokenizer.from_pretrained(self.tmpdirname				,	**A)



			def 					_lowerCamelCase (		self     :						List[str]				,	A     :						Optional[int])     ->					Dict:



						"""simple docstring"""






						_UpperCAmelCase	 =     'tester'
						_UpperCAmelCase	 =     'tester'
						return input_text, output_text



			@unittest.skip('MGP-STR always lower cases letters.')
			def 					_lowerCamelCase (		self     :						Optional[Any])     ->					int:



						"""simple docstring"""






						pass



			def 					_lowerCamelCase (		self     :						Optional[int])     ->					Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.get_tokenizers(do_lower_case=A)
						for tokenizer in tokenizers:
									with self.subTest(F"{tokenizer.__class__.__name__}"):
												_UpperCAmelCase	 =     '[SPECIAL_TOKEN]'

												tokenizer.add_special_tokens({'cls_token': special_token})
												_UpperCAmelCase	 =     tokenizer.encode([special_token]				,	add_special_tokens=A)
												self.assertEqual(len(A)				,	1)

												_UpperCAmelCase	 =     tokenizer.decode(A				,	skip_special_tokens=A)
												self.assertTrue(special_token not in decoded)



			def 					_lowerCamelCase (		self     :						Any)     ->					str:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.get_tokenizers()
						for tokenizer in tokenizers:
									with self.subTest(F"{tokenizer.__class__.__name__}"):
												_UpperCAmelCase ,  _UpperCAmelCase	 =     self.get_input_output_texts(A)

												_UpperCAmelCase	 =     tokenizer.tokenize(A)
												_UpperCAmelCase	 =     tokenizer.convert_tokens_to_ids(A)
												_UpperCAmelCase	 =     tokenizer.encode(A				,	add_special_tokens=A)
												self.assertListEqual(A				,	A)

												_UpperCAmelCase	 =     tokenizer.convert_ids_to_tokens(A)
												self.assertNotEqual(len(A)				,	0)
												_UpperCAmelCase	 =     tokenizer.decode(A)
												self.assertIsInstance(A				,	A)

												self.assertEqual(text_a.replace(' '				,	'')				,	A)



			@unittest.skip('MGP-STR tokenizer only handles one sequence.')
			def 					_lowerCamelCase (		self     :						str)     ->					List[str]:



						"""simple docstring"""






						pass



			@unittest.skip('inputs cannot be pretokenized in MgpstrTokenizer')
			def 					_lowerCamelCase (		self     :						Dict)     ->					Tuple:



						"""simple docstring"""






						pass
