

"""simple docstring"""




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      __lowercase			(    __lowerCamelCase					):
  snake_case_				       =       """autoformer"""
  snake_case_				       =       {
      """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 = 100					,A		:			float = 0.0_2					,A		:			bool = True					,A		:			List[Any]=True					,A		:			int = 10					,A		:			int = 25					,A		:			int = 3					,**A		:			List[str]					,):






   '''simple docstring'''
   # time series specific configuration
   UpperCAmelCase__					:  List[str]					   =					prediction_length
   UpperCAmelCase__					:  int					   =					context_length if context_length is not None else prediction_length
   UpperCAmelCase__					:  List[Any]					   =					distribution_output
   UpperCAmelCase__					:  Optional[int]					   =					loss
   UpperCAmelCase__					:  Optional[int]					   =					input_size
   UpperCAmelCase__					:  Dict					   =					num_time_features
   UpperCAmelCase__					:  Union[str, Any]					   =					lags_sequence
   UpperCAmelCase__					:  Dict					   =					scaling
   UpperCAmelCase__					:  Tuple					   =					num_dynamic_real_features
   UpperCAmelCase__					:  List[str]					   =					num_static_real_features
   UpperCAmelCase__					:  Union[str, Any]					   =					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__					:  List[str]					   =					cardinality
   else:
    UpperCAmelCase__					:  Dict					   =					[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__					:  Optional[int]					   =					embedding_dimension
   else:
    UpperCAmelCase__					:  Tuple					   =					[min(50					,(cat + 1) // 2    ) for cat in self.cardinality]
   UpperCAmelCase__					:  Optional[int]					   =					num_parallel_samples

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

   UpperCAmelCase__					:  Union[str, Any]					   =					dropout
   UpperCAmelCase__					:  List[str]					   =					attention_dropout
   UpperCAmelCase__					:  Dict					   =					activation_dropout
   UpperCAmelCase__					:  str					   =					encoder_layerdrop
   UpperCAmelCase__					:  Union[str, Any]					   =					decoder_layerdrop

   UpperCAmelCase__					:  Union[str, Any]					   =					activation_function
   UpperCAmelCase__					:  Tuple					   =					init_std

   UpperCAmelCase__					:  Union[str, Any]					   =					use_cache

   # Autoformer
   UpperCAmelCase__					:  int					   =					label_length
   UpperCAmelCase__					:  Optional[Any]					   =					moving_average
   UpperCAmelCase__					:  Optional[int]					   =					autocorrelation_factor

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




  @property
  def    __lowercase       (  self		:			Tuple    ):






   '''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
   )








"""simple docstring"""




from typing import Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
      from PIL import Image

      from ..image_utils import load_image

if is_torch_available():
      from ..models.auto.modeling_auto import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING

__UpperCAmelCase =				logging.get_logger(__name__)







@add_end_docstrings(__lowerCamelCase					)
class      __lowercase			(    __lowerCamelCase					):

  def __init__(  self		:			List[str]					,*A		:			Optional[int]					,**A		:			List[str]    ):






   '''simple docstring'''
   super().__init__(*A					,**A    )
   self.check_model_type(A    )

  def    __lowercase       (  self		:			Optional[int]					,A		:			Dict=None					,A		:			Optional[int]=None					,A		:			Tuple=None					,**A		:			str    ):






   '''simple docstring'''
   UpperCAmelCase__   ,      UpperCAmelCase__					:  Any					   =					{}, {}
   if padding is not None:
    UpperCAmelCase__					:  Union[str, Any]					   =					padding
   if truncation is not None:
    UpperCAmelCase__					:  List[str]					   =					truncation
   if top_k is not None:
    UpperCAmelCase__					:  List[Any]					   =					top_k
   return preprocess_params, {}, postprocess_params

  def __call__(  self		:			List[Any]					,A		:			Union["Image.Image", str]					,A		:			str = None					,**A		:			Union[str, Any]    ):






   '''simple docstring'''
   if isinstance(A					,(Image.Image, str)    ) and isinstance(A					,A    ):
    UpperCAmelCase__					:  Any					   =					{"""image""": image, """question""": question}
   else:
    UpperCAmelCase__					:  Dict					   =					image
   UpperCAmelCase__					:  Dict					   =					super().__call__(A					,**A    )
   return results

  def    __lowercase       (  self		:			Optional[int]					,A		:			Optional[Any]					,A		:			Optional[Any]=False					,A		:			List[Any]=False    ):






   '''simple docstring'''
   UpperCAmelCase__					:  List[Any]					   =					load_image(inputs["""image"""]    )
   UpperCAmelCase__					:  Optional[Any]					   =					self.tokenizer(
       inputs["""question"""]					,return_tensors=self.framework					,padding=A					,truncation=A    )
   UpperCAmelCase__					:  int					   =					self.image_processor(images=A					,return_tensors=self.framework    )
   model_inputs.update(A    )
   return model_inputs

  def    __lowercase       (  self		:			Dict					,A		:			Tuple    ):






   '''simple docstring'''
   UpperCAmelCase__					:  List[Any]					   =					self.model(**A    )
   return model_outputs




  def    __lowercase       (  self		:			int					,A		:			List[Any]					,A		:			List[str]=5    ):






   '''simple docstring'''
   if top_k > self.model.config.num_labels:
    UpperCAmelCase__					:  Any					   =					self.model.config.num_labels

   if self.framework == "pt":
    UpperCAmelCase__					:  Optional[int]					   =					model_outputs.logits.sigmoid()[0]
    UpperCAmelCase__   ,      UpperCAmelCase__					:  Optional[int]					   =					probs.topk(A    )
   else:
    raise ValueError(f"Unsupported framework: {self.framework}"    )

   UpperCAmelCase__					:  List[str]					   =					scores.tolist()
   UpperCAmelCase__					:  Optional[int]					   =					ids.tolist()
   return [{"score": score, "answer": self.model.config.idalabel[_id]} for score, _id in zip(A					,A    )]





