from typing import List, Optional

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


A__           =							logging.get_logger(__name__)

A__           =							{
    """huggingface/autoformer-tourism-monthly""": """https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json""",
}
class   _lowerCAmelCase		(     __SCREAMING_SNAKE_CASE				):
							_UpperCAmelCase						    =     'autoformer'
							_UpperCAmelCase						    =     {
							    'hidden_size': 'd_model',
							    'num_attention_heads': 'encoder_attention_heads',
							    'num_hidden_layers': 'encoder_layers',
							}







							def __init__(				self     :    Optional[int]	,					__snake_case     :    Optional[int] = None	,					__snake_case     :    Optional[int] = None	,					__snake_case     :    str = "student_t"	,					__snake_case     :    str = "nll"	,					__snake_case     :    int = 1	,					__snake_case     :    List[int] = [1, 2, 3, 4, 5, 6, 7]	,					__snake_case     :    bool = True	,					__snake_case     :    int = 0	,					__snake_case     :    int = 0	,					__snake_case     :    int = 0	,					__snake_case     :    int = 0	,					__snake_case     :    Optional[List[int]] = None	,					__snake_case     :    Optional[List[int]] = None	,					__snake_case     :    int = 64	,					__snake_case     :    int = 2	,					__snake_case     :    int = 2	,					__snake_case     :    int = 2	,					__snake_case     :    int = 2	,					__snake_case     :    int = 32	,					__snake_case     :    int = 32	,					__snake_case     :    str = "gelu"	,					__snake_case     :    float = 0.1	,					__snake_case     :    float = 0.1	,					__snake_case     :    float = 0.1	,					__snake_case     :    float = 0.1	,					__snake_case     :    float = 0.1	,					__snake_case     :    int = 100	,					__snake_case     :    float = 0.0_2	,					__snake_case     :    bool = True	,					__snake_case     :    List[Any]=True	,					__snake_case     :    int = 10	,					__snake_case     :    int = 25	,					__snake_case     :    int = 3	,					**__snake_case     :    Optional[int]	,					):
										# time series specific configuration
										lowerCamelCase						:List[str]						  =     prediction_length
										lowerCamelCase						:Tuple						  =     context_length if context_length is not None else prediction_length
										lowerCamelCase						:Union[str, Any]						  =     distribution_output
										lowerCamelCase						:Tuple						  =     loss
										lowerCamelCase						:Optional[Any]						  =     input_size
										lowerCamelCase						:Any						  =     num_time_features
										lowerCamelCase						:Dict						  =     lags_sequence
										lowerCamelCase						:Optional[int]						  =     scaling
										lowerCamelCase						:Dict						  =     num_dynamic_real_features
										lowerCamelCase						:Union[str, Any]						  =     num_static_real_features
										lowerCamelCase						:List[str]						  =     num_static_categorical_features
										if cardinality is not None and num_static_categorical_features > 0:
													if len(__snake_case		) != num_static_categorical_features:
																raise ValueError(
																    '''The cardinality should be a list of the same length as `num_static_categorical_features`'''		)
													lowerCamelCase						:Dict						  =     cardinality
										else:
													lowerCamelCase						:Optional[Any]						  =     [0]
										if embedding_dimension is not None and num_static_categorical_features > 0:
													if len(__snake_case		) != num_static_categorical_features:
																raise ValueError(
																    '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''		)
													lowerCamelCase						:Optional[int]						  =     embedding_dimension
										else:
													lowerCamelCase						:Optional[int]						  =     [min(50	,					(cat + 1) // 2		) for cat in self.cardinality]
										lowerCamelCase						:Union[str, Any]						  =     num_parallel_samples

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

										lowerCamelCase						:Optional[Any]						  =     dropout
										lowerCamelCase						:str						  =     attention_dropout
										lowerCamelCase						:Optional[int]						  =     activation_dropout
										lowerCamelCase						:List[str]						  =     encoder_layerdrop
										lowerCamelCase						:List[str]						  =     decoder_layerdrop

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

										lowerCamelCase						:str						  =     use_cache

										# Autoformer
										lowerCamelCase						:int						  =     label_length
										lowerCamelCase						:List[str]						  =     moving_average
										lowerCamelCase						:List[str]						  =     autocorrelation_factor

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







							@property
							def 				snake_case  (				self     :    List[Any]		):
										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 unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
			from PIL import Image
else:
			class   _lowerCAmelCase		:







										@staticmethod
										def 				snake_case  (				*__snake_case     :    str	,					**__snake_case     :    str		):
													pass
@is_pipeline_test
@require_vision
class   _lowerCAmelCase		(     unittest.TestCase				):







							@require_torch
							def 				snake_case  (				self     :    Union[str, Any]		):
										lowerCamelCase						:Optional[int]						  =     pipeline(
										    model='''hf-internal-testing/tiny-random-clip-zero-shot-image-classification'''	,					)
										lowerCamelCase						:List[str]						  =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
										lowerCamelCase						:Dict						  =     image_classifier(__snake_case	,					candidate_labels=['''a''', '''b''', '''c''']		)

										# The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
										# python and torch versions.
										self.assertIn(
										    nested_simplify(__snake_case		)	,					[
										        [{'''score''': 0.3_3_3, '''label''': '''a'''}, {'''score''': 0.3_3_3, '''label''': '''b'''}, {'''score''': 0.3_3_3, '''label''': '''c'''}],
										        [{'''score''': 0.3_3_3, '''label''': '''a'''}, {'''score''': 0.3_3_3, '''label''': '''c'''}, {'''score''': 0.3_3_3, '''label''': '''b'''}],
										    ]	,					)

										lowerCamelCase						:Tuple						  =     image_classifier([image] * 5	,					candidate_labels=['''A''', '''B''', '''C''']	,					batch_size=2		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										    ]	,					)







							@require_tf
							def 				snake_case  (				self     :    Tuple		):
										lowerCamelCase						:Tuple						  =     pipeline(
										    model='''hf-internal-testing/tiny-random-clip-zero-shot-image-classification'''	,					framework='''tf'''		)
										lowerCamelCase						:List[str]						  =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
										lowerCamelCase						:Optional[Any]						  =     image_classifier(__snake_case	,					candidate_labels=['''a''', '''b''', '''c''']		)

										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[{'''score''': 0.3_3_3, '''label''': '''a'''}, {'''score''': 0.3_3_3, '''label''': '''b'''}, {'''score''': 0.3_3_3, '''label''': '''c'''}]	,					)

										lowerCamelCase						:int						  =     image_classifier([image] * 5	,					candidate_labels=['''A''', '''B''', '''C''']	,					batch_size=2		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										    ]	,					)







							@slow
							@require_torch
							def 				snake_case  (				self     :    Any		):
										lowerCamelCase						:str						  =     pipeline(
										    task='''zero-shot-image-classification'''	,					model='''openai/clip-vit-base-patch32'''	,					)
										# This is an image of 2 cats with remotes and no planes
										lowerCamelCase						:List[str]						  =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
										lowerCamelCase						:Optional[Any]						  =     image_classifier(__snake_case	,					candidate_labels=['''cat''', '''plane''', '''remote''']		)

										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        {'''score''': 0.5_1_1, '''label''': '''remote'''},
										        {'''score''': 0.4_8_5, '''label''': '''cat'''},
										        {'''score''': 0.0_0_4, '''label''': '''plane'''},
										    ]	,					)

										lowerCamelCase						:Any						  =     image_classifier([image] * 5	,					candidate_labels=['''cat''', '''plane''', '''remote''']	,					batch_size=2		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        [
										            {'''score''': 0.5_1_1, '''label''': '''remote'''},
										            {'''score''': 0.4_8_5, '''label''': '''cat'''},
										            {'''score''': 0.0_0_4, '''label''': '''plane'''},
										        ],
										    ]
										    * 5	,					)







							@slow
							@require_tf
							def 				snake_case  (				self     :    Optional[Any]		):
										lowerCamelCase						:Union[str, Any]						  =     pipeline(
										    task='''zero-shot-image-classification'''	,					model='''openai/clip-vit-base-patch32'''	,					framework='''tf'''		)
										# This is an image of 2 cats with remotes and no planes
										lowerCamelCase						:Dict						  =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
										lowerCamelCase						:Dict						  =     image_classifier(__snake_case	,					candidate_labels=['''cat''', '''plane''', '''remote''']		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        {'''score''': 0.5_1_1, '''label''': '''remote'''},
										        {'''score''': 0.4_8_5, '''label''': '''cat'''},
										        {'''score''': 0.0_0_4, '''label''': '''plane'''},
										    ]	,					)

										lowerCamelCase						:Any						  =     image_classifier([image] * 5	,					candidate_labels=['''cat''', '''plane''', '''remote''']	,					batch_size=2		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        [
										            {'''score''': 0.5_1_1, '''label''': '''remote'''},
										            {'''score''': 0.4_8_5, '''label''': '''cat'''},
										            {'''score''': 0.0_0_4, '''label''': '''plane'''},
										        ],
										    ]
										    * 5	,					)



