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						(					__snake_case			):
     _SCREAMING_SNAKE_CASE     :     List[str]		="""autoformer"""
     _SCREAMING_SNAKE_CASE     :     Optional[Any]		={
         """hidden_size""": """d_model""",
         """num_attention_heads""": """encoder_attention_heads""",
         """num_hidden_layers""": """encoder_layers""",
     }



     def __init__(					self				,      lowerCAmelCase__ = None				,      lowerCAmelCase__ = None				,      lowerCAmelCase__ = "student_t"				,      lowerCAmelCase__ = "nll"				,      lowerCAmelCase__ = 1				,      lowerCAmelCase__ = [1, 2, 3, 4, 5, 6, 7]				,      lowerCAmelCase__ = True				,      lowerCAmelCase__ = 0				,      lowerCAmelCase__ = 0				,      lowerCAmelCase__ = 0				,      lowerCAmelCase__ = 0				,      lowerCAmelCase__ = None				,      lowerCAmelCase__ = None				,      lowerCAmelCase__ = 64				,      lowerCAmelCase__ = 2				,      lowerCAmelCase__ = 2				,      lowerCAmelCase__ = 2				,      lowerCAmelCase__ = 2				,      lowerCAmelCase__ = 32				,      lowerCAmelCase__ = 32				,      lowerCAmelCase__ = "gelu"				,      lowerCAmelCase__ = 0.1				,      lowerCAmelCase__ = 0.1				,      lowerCAmelCase__ = 0.1				,      lowerCAmelCase__ = 0.1				,      lowerCAmelCase__ = 0.1				,      lowerCAmelCase__ = 100				,      lowerCAmelCase__ = 0.02				,      lowerCAmelCase__ = True				,      lowerCAmelCase__=True				,      lowerCAmelCase__ = 10				,      lowerCAmelCase__ = 25				,      lowerCAmelCase__ = 3				,      **lowerCAmelCase__				,      ):
            _A=	prediction_length
            _A=	context_length if context_length is not None else prediction_length
            _A=	distribution_output
            _A=	loss
            _A=	input_size
            _A=	num_time_features
            _A=	lags_sequence
            _A=	scaling
            _A=	num_dynamic_real_features
            _A=	num_static_real_features
            _A=	num_static_categorical_features
            if cardinality is not None 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`'       )
                   _A=	cardinality
            else:
                   _A=	[0]
            if embedding_dimension is not None 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`'       )
                   _A=	embedding_dimension
            else:
                   _A=	[min(50				,      (cat + 1) // 2       ) for cat in self.cardinality]
            _A=	num_parallel_samples

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

            _A=	dropout
            _A=	attention_dropout
            _A=	activation_dropout
            _A=	encoder_layerdrop
            _A=	decoder_layerdrop

            _A=	activation_function
            _A=	init_std

            _A=	use_cache

            # Autoformer
            _A=	label_length
            _A=	moving_average
            _A=	autocorrelation_factor

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





     @property
     def 			a__  (					self       ):
            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
import tempfile
import unittest
import uuid
from pathlib import Path

from transformers.testing_utils import get_tests_dir, require_soundfile, require_torch, require_vision
from transformers.tools.agent_types import AgentAudio, AgentImage, AgentText
from transformers.utils import is_soundfile_availble, is_torch_available, is_vision_available


if is_torch_available():
      import torch

if is_soundfile_availble():
      import soundfile as sf

if is_vision_available():
      from PIL import Image

def 							UpperCamelCase				(    lowerCAmelCase_=""   )		->						str:




       '''simple docstring'''






       _A=	tempfile.mkdtemp()
       return os.path.join(lowerCAmelCase_       ,					str(uuid.uuida()   ) + suffix   )





@require_soundfile
@require_torch
class      lowerCAmelCase						(					unittest.TestCase			):



     def 			a__  (					self       ):
            _A=	torch.rand(12				,      dtype=torch.floataa       ) - 0.5
            _A=	AgentAudio(lowerCAmelCase__       )
            _A=	str(agent_type.to_string()       )

            # Ensure that the tensor and the agent_type's tensor are the same
            self.assertTrue(torch.allclose(lowerCAmelCase__				,      agent_type.to_raw()				,      atol=1E-4       )       )

            del agent_type

            # Ensure the path remains even after the object deletion
            self.assertTrue(os.path.exists(lowerCAmelCase__       )       )

            # Ensure that the file contains the same value as the original tensor
            _A,			_A=	sf.read(lowerCAmelCase__       )
            self.assertTrue(torch.allclose(lowerCAmelCase__				,      torch.tensor(lowerCAmelCase__       )				,      atol=1E-4       )       )





     def 			a__  (					self       ):
            _A=	torch.rand(12				,      dtype=torch.floataa       ) - 0.5
            _A=	get_new_path(suffix='.wav'       )
            sf.write(lowerCAmelCase__				,      lowerCAmelCase__				,      16000       )

            _A=	AgentAudio(lowerCAmelCase__       )

            self.assertTrue(torch.allclose(lowerCAmelCase__				,      agent_type.to_raw()				,      atol=1E-4       )       )
            self.assertEqual(agent_type.to_string()				,      lowerCAmelCase__       )





@require_vision
@require_torch
class      lowerCAmelCase						(					unittest.TestCase			):



     def 			a__  (					self       ):
            _A=	torch.randint(0				,      256				,      (64, 64, 3)       )
            _A=	AgentImage(lowerCAmelCase__       )
            _A=	str(agent_type.to_string()       )

            # Ensure that the tensor and the agent_type's tensor are the same
            self.assertTrue(torch.allclose(lowerCAmelCase__				,      agent_type._tensor				,      atol=1E-4       )       )

            self.assertIsInstance(agent_type.to_raw()				,      Image.Image       )

            # Ensure the path remains even after the object deletion
            del agent_type
            self.assertTrue(os.path.exists(lowerCAmelCase__       )       )



     def 			a__  (					self       ):
            _A=	Path(get_tests_dir('fixtures/tests_samples/COCO'       )       ) / '000000039769.png'
            _A=	Image.open(lowerCAmelCase__       )
            _A=	AgentImage(lowerCAmelCase__       )

            self.assertTrue(path.samefile(agent_type.to_string()       )       )
            self.assertTrue(image == agent_type.to_raw()       )

            # Ensure the path remains even after the object deletion
            del agent_type
            self.assertTrue(os.path.exists(lowerCAmelCase__       )       )





     def 			a__  (					self       ):
            _A=	Path(get_tests_dir('fixtures/tests_samples/COCO'       )       ) / '000000039769.png'
            _A=	Image.open(lowerCAmelCase__       )
            _A=	AgentImage(lowerCAmelCase__       )

            self.assertFalse(path.samefile(agent_type.to_string()       )       )
            self.assertTrue(image == agent_type.to_raw()       )

            # Ensure the path remains even after the object deletion
            del agent_type
            self.assertTrue(os.path.exists(lowerCAmelCase__       )       )





class      lowerCAmelCase						(					unittest.TestCase			):



     def 			a__  (					self       ):
            _A=	'Hey!'
            _A=	AgentText(lowerCAmelCase__       )

            self.assertEqual(lowerCAmelCase__				,      agent_type.to_string()       )
            self.assertEqual(lowerCAmelCase__				,      agent_type.to_raw()       )
            self.assertEqual(lowerCAmelCase__				,      lowerCAmelCase__       )