



'''simple docstring'''






import unittest

from transformers import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING, 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        SCREAMING_SNAKE_CASE:







							"""simple docstring"""






							@staticmethod
							def   A			(		*__snake_case    :  Dict	,    **__snake_case    :  List[Any]	)    ->	Optional[int]:
														pass

@is_pipeline_test
@require_torch
@require_vision
class        SCREAMING_SNAKE_CASE(							unittest.TestCase    ):







	"""simple docstring"""






	lowerCamelCase__    				= MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING







	def   A			(		self    :  List[str]	,    __snake_case    :  List[str]	,    __snake_case    :  Optional[Any]	,    __snake_case    :  Union[str, Any]	)    ->	Optional[int]:
								UpperCAmelCase				: Tuple											=	pipeline('''visual-question-answering'''	,    model='''hf-internal-testing/tiny-vilt-random-vqa'''	)
								UpperCAmelCase				: Tuple											=	[
								    {
								        '''image''': Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''	),
								        '''question''': '''How many cats are there?''',
								    },
								    {
								        '''image''': '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
								        '''question''': '''How many cats are there?''',
								    },
								]
								return vqa_pipeline, examples







	def   A			(		self    :  Tuple	,    __snake_case    :  Optional[Any]	,    __snake_case    :  Any	)    ->	List[Any]:
								UpperCAmelCase				: Union[str, Any]											=	vqa_pipeline(__snake_case	,    top_k=1	)
								self.assertEqual(
								    __snake_case	,    [
								        [{'''score''': ANY(__snake_case	), '''answer''': ANY(__snake_case	)}],
								        [{'''score''': ANY(__snake_case	), '''answer''': ANY(__snake_case	)}],
								    ]	,    )







	@require_torch
	def   A			(		self    :  Optional[Any]	)    ->	Dict:
								UpperCAmelCase				: Union[str, Any]											=	pipeline('''visual-question-answering'''	,    model='''hf-internal-testing/tiny-vilt-random-vqa'''	)
								UpperCAmelCase				: Optional[int]											=	'''./tests/fixtures/tests_samples/COCO/000000039769.png'''
								UpperCAmelCase				: List[Any]											=	'''How many cats are there?'''

								UpperCAmelCase				: Any											=	vqa_pipeline(image=__snake_case	,    question='''How many cats are there?'''	,    top_k=2	)
								self.assertEqual(
								    __snake_case	,    [{'''score''': ANY(__snake_case	), '''answer''': ANY(__snake_case	)}, {'''score''': ANY(__snake_case	), '''answer''': ANY(__snake_case	)}]	)

								UpperCAmelCase				: List[str]											=	vqa_pipeline({'''image''': image, '''question''': question}	,    top_k=2	)
								self.assertEqual(
								    __snake_case	,    [{'''score''': ANY(__snake_case	), '''answer''': ANY(__snake_case	)}, {'''score''': ANY(__snake_case	), '''answer''': ANY(__snake_case	)}]	)







	@slow
	@require_torch
	def   A			(		self    :  Dict	)    ->	List[Any]:
								UpperCAmelCase				: int											=	pipeline('''visual-question-answering'''	,    model='''dandelin/vilt-b32-finetuned-vqa'''	)
								UpperCAmelCase				: Union[str, Any]											=	'''./tests/fixtures/tests_samples/COCO/000000039769.png'''
								UpperCAmelCase				: Optional[Any]											=	'''How many cats are there?'''

								UpperCAmelCase				: int											=	vqa_pipeline(image=__snake_case	,    question=__snake_case	,    top_k=2	)
								self.assertEqual(
								    nested_simplify(__snake_case	,    decimals=4	)	,    [{'''score''': 0.87_99, '''answer''': '''2'''}, {'''score''': 0.2_96, '''answer''': '''1'''}]	)

								UpperCAmelCase				: Union[str, Any]											=	vqa_pipeline({'''image''': image, '''question''': question}	,    top_k=2	)
								self.assertEqual(
								    nested_simplify(__snake_case	,    decimals=4	)	,    [{'''score''': 0.87_99, '''answer''': '''2'''}, {'''score''': 0.2_96, '''answer''': '''1'''}]	)

								UpperCAmelCase				: str											=	vqa_pipeline(
								    [{'''image''': image, '''question''': question}, {'''image''': image, '''question''': question}]	,    top_k=2	)
								self.assertEqual(
								    nested_simplify(__snake_case	,    decimals=4	)	,    [[{'''score''': 0.87_99, '''answer''': '''2'''}, {'''score''': 0.2_96, '''answer''': '''1'''}]] * 2	,    )







	@require_tf
	@unittest.skip('''Visual question answering not implemented in TF'''	)
	def   A			(		self    :  Any	)    ->	List[Any]:
								pass










'''simple docstring'''






from typing import List, Optional, Union

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


UpperCamelCase__:     Optional[Any]										=    logging.get_logger(__name__)

UpperCamelCase__:     Tuple										=    {
    "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        SCREAMING_SNAKE_CASE(							A__    ):







	"""simple docstring"""






	lowerCamelCase__    				= """time_series_transformer"""
	lowerCamelCase__    				= {
	    """hidden_size""": """d_model""",
	    """num_attention_heads""": """encoder_attention_heads""",
	    """num_hidden_layers""": """encoder_layers""",
	}







	def __init__(		self    :  str	,    __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    :  Optional[Union[str, bool]] = "mean"	,    __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 = 32	,    __snake_case    :  int = 32	,    __snake_case    :  int = 2	,    __snake_case    :  int = 2	,    __snake_case    :  int = 2	,    __snake_case    :  int = 2	,    __snake_case    :  bool = True	,    __snake_case    :  str = "gelu"	,    __snake_case    :  int = 64	,    __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.02	,    __snake_case    :  Optional[Any]=True	,    **__snake_case    :  List[Any]	,    )    ->	List[str]:
								# time series specific configuration
								UpperCAmelCase				: List[Any]											=	prediction_length
								UpperCAmelCase				: List[Any]											=	context_length or prediction_length
								UpperCAmelCase				: Tuple											=	distribution_output
								UpperCAmelCase				: Optional[Any]											=	loss
								UpperCAmelCase				: Tuple											=	input_size
								UpperCAmelCase				: Optional[int]											=	num_time_features
								UpperCAmelCase				: Dict											=	lags_sequence
								UpperCAmelCase				: Any											=	scaling
								UpperCAmelCase				: Tuple											=	num_dynamic_real_features
								UpperCAmelCase				: Any											=	num_static_real_features
								UpperCAmelCase				: Optional[int]											=	num_static_categorical_features
								if cardinality 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`'''	)
															UpperCAmelCase				: Any											=	cardinality
								else:
															UpperCAmelCase				: Optional[Any]											=	[0]
								if embedding_dimension 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`'''	)
															UpperCAmelCase				: Optional[int]											=	embedding_dimension
								else:
															UpperCAmelCase				: Optional[Any]											=	[min(50	,    (cat + 1) // 2	) for cat in self.cardinality]
								UpperCAmelCase				: List[Any]											=	num_parallel_samples

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

								UpperCAmelCase				: Optional[int]											=	dropout
								UpperCAmelCase				: Union[str, Any]											=	attention_dropout
								UpperCAmelCase				: List[Any]											=	activation_dropout
								UpperCAmelCase				: Optional[int]											=	encoder_layerdrop
								UpperCAmelCase				: Dict											=	decoder_layerdrop

								UpperCAmelCase				: Tuple											=	activation_function
								UpperCAmelCase				: Dict											=	init_std

								UpperCAmelCase				: Optional[int]											=	use_cache

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







	@property
	def   A			(		self    :  Union[str, Any]	)    ->	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
								)





