



'''simple docstring'''

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 __snake_case(				_lowerCAmelCase		,							unittest.TestCase ):


						'''simple docstring'''



						UpperCAmelCase							:   List[str]									=		MgpstrTokenizer
						UpperCAmelCase							:   List[str]									=		False
						UpperCAmelCase							:   Optional[int]									=		{}
						UpperCAmelCase							:   List[str]									=		False


						def     __snake_case   ( self				)     ->     int:
							super().setUp()

							# fmt: off
							lowerCAmelCase   =     ["""[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
							lowerCAmelCase   =     dict(zip(A_     ,	range(len(A_				)				)				)				)

							lowerCAmelCase   =     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     __snake_case   ( self     ,	**A_				)     ->     Optional[int]:
							return MgpstrTokenizer.from_pretrained(self.tmpdirname     ,	**A_				)


						def     __snake_case   ( self     ,	A_				)     ->     Dict:
							lowerCAmelCase   =     """tester"""
							lowerCAmelCase   =     """tester"""
							return input_text, output_text


						@unittest.skip("""MGP-STR always lower cases letters."""				)
						def     __snake_case   ( self				)     ->     Optional[int]:
							pass


						def     __snake_case   ( self				)     ->     Optional[int]:
							lowerCAmelCase   =     self.get_tokenizers(do_lower_case=A_				)
							for tokenizer in tokenizers:
								with self.subTest(f'{tokenizer.__class__.__name__}'				):
									lowerCAmelCase   =     """[SPECIAL_TOKEN]"""

									tokenizer.add_special_tokens({"""cls_token""": special_token}				)
									lowerCAmelCase   =     tokenizer.encode([special_token]     ,	add_special_tokens=A_				)
									self.assertEqual(len(A_				)     ,	1				)

									lowerCAmelCase   =     tokenizer.decode(A_     ,	skip_special_tokens=A_				)
									self.assertTrue(special_token not in decoded				)


						def     __snake_case   ( self				)     ->     Tuple:
							lowerCAmelCase   =     self.get_tokenizers()
							for tokenizer in tokenizers:
								with self.subTest(f'{tokenizer.__class__.__name__}'				):
									lowerCAmelCase,       lowerCAmelCase   =     self.get_input_output_texts(A_				)

									lowerCAmelCase   =     tokenizer.tokenize(A_				)
									lowerCAmelCase   =     tokenizer.convert_tokens_to_ids(A_				)
									lowerCAmelCase   =     tokenizer.encode(A_     ,	add_special_tokens=A_				)
									self.assertListEqual(A_     ,	A_				)

									lowerCAmelCase   =     tokenizer.convert_ids_to_tokens(A_				)
									self.assertNotEqual(len(A_				)     ,	0				)
									lowerCAmelCase   =     tokenizer.decode(A_				)
									self.assertIsInstance(A_     ,	A_				)

									self.assertEqual(text_a.replace(""" """     ,	""""""				)     ,	A_				)


						@unittest.skip("""MGP-STR tokenizer only handles one sequence."""				)
						def     __snake_case   ( self				)     ->     Tuple:
							pass




						@unittest.skip("""inputs cannot be pretokenized in MgpstrTokenizer"""				)
						def     __snake_case   ( self				)     ->     Tuple:
							pass




'''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 __snake_case(				_lowerCAmelCase ):


						'''simple docstring'''



						UpperCAmelCase							:   List[Any]									=		"time_series_transformer"
						UpperCAmelCase							:   int									=		{
						    "hidden_size": "d_model",
						    "num_attention_heads": "encoder_attention_heads",
						    "num_hidden_layers": "encoder_layers",
						}


						def __init__( self     ,	A_ = None     ,	A_ = None     ,	A_ = "student_t"     ,	A_ = "nll"     ,	A_ = 1     ,	A_ = [1, 2, 3, 4, 5, 6, 7]     ,	A_ = "mean"     ,	A_ = 0     ,	A_ = 0     ,	A_ = 0     ,	A_ = 0     ,	A_ = None     ,	A_ = None     ,	A_ = 32     ,	A_ = 32     ,	A_ = 2     ,	A_ = 2     ,	A_ = 2     ,	A_ = 2     ,	A_ = True     ,	A_ = "gelu"     ,	A_ = 64     ,	A_ = 0.1     ,	A_ = 0.1     ,	A_ = 0.1     ,	A_ = 0.1     ,	A_ = 0.1     ,	A_ = 100     ,	A_ = 0.0_2     ,	A_=True     ,	**A_     ,	)     ->     Optional[Any]:
							# time series specific configuration
							lowerCAmelCase   =     prediction_length
							lowerCAmelCase   =     context_length or prediction_length
							lowerCAmelCase   =     distribution_output
							lowerCAmelCase   =     loss
							lowerCAmelCase   =     input_size
							lowerCAmelCase   =     num_time_features
							lowerCAmelCase   =     lags_sequence
							lowerCAmelCase   =     scaling
							lowerCAmelCase   =     num_dynamic_real_features
							lowerCAmelCase   =     num_static_real_features
							lowerCAmelCase   =     num_static_categorical_features
							if cardinality 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`"""				)
								lowerCAmelCase   =     cardinality
							else:
								lowerCAmelCase   =     [0]
							if embedding_dimension 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`"""				)
								lowerCAmelCase   =     embedding_dimension
							else:
								lowerCAmelCase   =     [min(50     ,	(cat + 1) // 2				) for cat in self.cardinality]
							lowerCAmelCase   =     num_parallel_samples

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

							lowerCAmelCase   =     dropout
							lowerCAmelCase   =     attention_dropout
							lowerCAmelCase   =     activation_dropout
							lowerCAmelCase   =     encoder_layerdrop
							lowerCAmelCase   =     decoder_layerdrop

							lowerCAmelCase   =     activation_function
							lowerCAmelCase   =     init_std

							lowerCAmelCase   =     use_cache

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




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