


import copy

from ...configuration_utils import PretrainedConfig
from ...utils import add_start_docstrings


UpperCAmelCase    =					r"""
    [`RagConfig`] stores the configuration of a *RagModel*. Configuration objects inherit from [`PretrainedConfig`] and
    can be used to control the model outputs. Read the documentation from [`PretrainedConfig`] for more information.

    Args:
        title_sep (`str`, *optional*, defaults to  `\" / \"`):
            Separator inserted between the title and the text of the retrieved document when calling [`RagRetriever`].
        doc_sep (`str`, *optional*, defaults to  `\" // \"`):
            Separator inserted between the text of the retrieved document and the original input when calling
            [`RagRetriever`].
        n_docs (`int`, *optional*, defaults to 5):
            Number of documents to retrieve.
        max_combined_length (`int`, *optional*, defaults to 300):
            Max length of contextualized input returned by [`~RagRetriever.__call__`].
        retrieval_vector_size (`int`, *optional*, defaults to 768):
            Dimensionality of the document embeddings indexed by [`RagRetriever`].
        retrieval_batch_size (`int`, *optional*, defaults to 8):
            Retrieval batch size, defined as the number of queries issues concurrently to the faiss index encapsulated
            [`RagRetriever`].
        dataset (`str`, *optional*, defaults to `\"wiki_dpr\"`):
            A dataset identifier of the indexed dataset in HuggingFace Datasets (list all available datasets and ids
            using `datasets.list_datasets()`).
        dataset_split (`str`, *optional*, defaults to `\"train\"`)
            Which split of the `dataset` to load.
        index_name (`str`, *optional*, defaults to `\"compressed\"`)
            The index name of the index associated with the `dataset`. One can choose between `\"legacy\"`, `\"exact\"` and
            `\"compressed\"`.
        index_path (`str`, *optional*)
            The path to the serialized faiss index on disk.
        passages_path (`str`, *optional*):
            A path to text passages compatible with the faiss index. Required if using
            [`~models.rag.retrieval_rag.LegacyIndex`]
        use_dummy_dataset (`bool`, *optional*, defaults to `False`)
            Whether to load a \"dummy\" variant of the dataset specified by `dataset`.
        label_smoothing (`float`, *optional*, defaults to 0.0):
            Only relevant if `return_loss` is set to `True`. Controls the `epsilon` parameter value for label smoothing
            in the loss calculation. If set to 0, no label smoothing is performed.
        do_marginalize (`bool`, *optional*, defaults to `False`):
            If `True`, the logits are marginalized over all documents by making use of
            `torch.nn.functional.log_softmax`.
        reduce_loss (`bool`, *optional*, defaults to `False`):
            Whether or not to reduce the NLL loss using the `torch.Tensor.sum` operation.
        do_deduplication (`bool`, *optional*, defaults to `True`):
            Whether or not to deduplicate the generations from different context documents for a given input. Has to be
            set to `False` if used while training with distributed backend.
        exclude_bos_score (`bool`, *optional*, defaults to `False`):
            Whether or not to disregard the BOS token when computing the loss.
        output_retrieved(`bool`, *optional*, defaults to `False`):
            If set to `True`, `retrieved_doc_embeds`, `retrieved_doc_ids`, `context_input_ids` and
            `context_attention_mask` are returned. See returned tensors for more detail.
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return the last key/values attentions (not used by all models).
        forced_eos_token_id (`int`, *optional*):
            The id of the token to force as the last generated token when `max_length` is reached. Usually set to
            `eos_token_id`.
"""







@add_start_docstrings(lowerCamelCase__ )
class lowerCAmelCase_		(				lowerCamelCase__ ):

 '''simple docstring'''

 __snake_case				=						"rag"
 __snake_case				=						True



 def __init__(			self	,   _UpperCAmelCase=None	,   _UpperCAmelCase=True	,   _UpperCAmelCase=None	,   _UpperCAmelCase=None	,   _UpperCAmelCase=None	,   _UpperCAmelCase=None	,   _UpperCAmelCase=None	,   _UpperCAmelCase=" / "	,   _UpperCAmelCase=" // "	,   _UpperCAmelCase=5	,   _UpperCAmelCase=3_00	,   _UpperCAmelCase=7_68	,   _UpperCAmelCase=8	,   _UpperCAmelCase="wiki_dpr"	,   _UpperCAmelCase="train"	,   _UpperCAmelCase="compressed"	,   _UpperCAmelCase=None	,   _UpperCAmelCase=None	,   _UpperCAmelCase=False	,   _UpperCAmelCase=False	,   _UpperCAmelCase=0.0	,   _UpperCAmelCase=True	,   _UpperCAmelCase=False	,   _UpperCAmelCase=False	,   _UpperCAmelCase=False	,   _UpperCAmelCase=True	,   _UpperCAmelCase=None	,   **_UpperCAmelCase	,   ):
       super().__init__(
           bos_token_id=_UpperCAmelCase	,   pad_token_id=_UpperCAmelCase	,   eos_token_id=_UpperCAmelCase	,   decoder_start_token_id=_UpperCAmelCase	,   forced_eos_token_id=_UpperCAmelCase	,   is_encoder_decoder=_UpperCAmelCase	,   prefix=_UpperCAmelCase	,   vocab_size=_UpperCAmelCase	,   **_UpperCAmelCase	,   )
       assert (
           "question_encoder" in kwargs and "generator" in kwargs
       ), "Config has to be initialized with question_encoder and generator config"
       snake_case_ =   kwargs.pop('''question_encoder'''      )
       snake_case_ =   question_encoder_config.pop('''model_type'''      )
       snake_case_ =   kwargs.pop('''generator'''      )
       snake_case_ =   decoder_config.pop('''model_type'''      )

       from ..auto.configuration_auto import AutoConfig

       snake_case_ =   AutoConfig.for_model(_UpperCAmelCase	,   **_UpperCAmelCase      )
       snake_case_ =   AutoConfig.for_model(_UpperCAmelCase	,   **_UpperCAmelCase      )

       snake_case_ =   reduce_loss
       snake_case_ =   label_smoothing
       snake_case_ =   exclude_bos_score
       snake_case_ =   do_marginalize

       snake_case_ =   title_sep
       snake_case_ =   doc_sep
       snake_case_ =   n_docs
       snake_case_ =   max_combined_length

       snake_case_ =   dataset
       snake_case_ =   dataset_split
       snake_case_ =   index_name

       snake_case_ =   retrieval_vector_size
       snake_case_ =   retrieval_batch_size
       snake_case_ =   passages_path
       snake_case_ =   index_path
       snake_case_ =   use_dummy_dataset

       snake_case_ =   output_retrieved

       snake_case_ =   do_deduplication

       snake_case_ =   use_cache

       if self.forced_eos_token_id is None:
             snake_case_ =   getattr(self.generator	,   '''forced_eos_token_id'''	,   _UpperCAmelCase      )



 @classmethod
 def 		UpperCamelCase__  (			cls	,   _UpperCAmelCase	,   _UpperCAmelCase	,   **_UpperCAmelCase      ):
       return cls(question_encoder=question_encoder_config.to_dict()	,   generator=generator_config.to_dict()	,   **_UpperCAmelCase      )





 def 		UpperCamelCase__  (			self      ):
       snake_case_ =   copy.deepcopy(self.__dict__      )
       snake_case_ =   self.question_encoder.to_dict()
       snake_case_ =   self.generator.to_dict()
       snake_case_ =   self.__class__.model_type
       return output



from typing import List, Optional, Union

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


UpperCAmelCase    =					logging.get_logger(__name__)

UpperCAmelCase    =					{
    """huggingface/informer-tourism-monthly""": (
        """https://huggingface.co/huggingface/informer-tourism-monthly/resolve/main/config.json"""
    ),
    # See all Informer models at https://huggingface.co/models?filter=informer
}







class lowerCAmelCase_		(				lowerCamelCase__ ):

 '''simple docstring'''

 __snake_case				=						"informer"
 __snake_case				=						{
     "hidden_size": "d_model",
     "num_attention_heads": "encoder_attention_heads",
     "num_hidden_layers": "encoder_layers",
 }



 def __init__(			self	,   _UpperCAmelCase = None	,   _UpperCAmelCase = None	,   _UpperCAmelCase = "student_t"	,   _UpperCAmelCase = "nll"	,   _UpperCAmelCase = 1	,   _UpperCAmelCase = None	,   _UpperCAmelCase = "mean"	,   _UpperCAmelCase = 0	,   _UpperCAmelCase = 0	,   _UpperCAmelCase = 0	,   _UpperCAmelCase = 0	,   _UpperCAmelCase = None	,   _UpperCAmelCase = None	,   _UpperCAmelCase = 64	,   _UpperCAmelCase = 32	,   _UpperCAmelCase = 32	,   _UpperCAmelCase = 2	,   _UpperCAmelCase = 2	,   _UpperCAmelCase = 2	,   _UpperCAmelCase = 2	,   _UpperCAmelCase = True	,   _UpperCAmelCase = "gelu"	,   _UpperCAmelCase = 0.05	,   _UpperCAmelCase = 0.1	,   _UpperCAmelCase = 0.1	,   _UpperCAmelCase = 0.1	,   _UpperCAmelCase = 0.1	,   _UpperCAmelCase = 1_00	,   _UpperCAmelCase = 0.02	,   _UpperCAmelCase=True	,   _UpperCAmelCase = "prob"	,   _UpperCAmelCase = 5	,   _UpperCAmelCase = True	,   **_UpperCAmelCase	,   ):
       # time series specific configuration
       snake_case_ =   prediction_length
       snake_case_ =   context_length or prediction_length
       snake_case_ =   distribution_output
       snake_case_ =   loss
       snake_case_ =   input_size
       snake_case_ =   num_time_features
       snake_case_ =   lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
       snake_case_ =   scaling
       snake_case_ =   num_dynamic_real_features
       snake_case_ =   num_static_real_features
       snake_case_ =   num_static_categorical_features

       # set cardinality
       if cardinality 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`'''      )
             snake_case_ =   cardinality
       else:
             snake_case_ =   [0]

       # set embedding_dimension
       if embedding_dimension 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`'''      )
             snake_case_ =   embedding_dimension
       else:
             snake_case_ =   [min(50	,   (cat + 1) // 2      ) for cat in self.cardinality]

       snake_case_ =   num_parallel_samples

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

       snake_case_ =   dropout
       snake_case_ =   attention_dropout
       snake_case_ =   activation_dropout
       snake_case_ =   encoder_layerdrop
       snake_case_ =   decoder_layerdrop

       snake_case_ =   activation_function
       snake_case_ =   init_std

       snake_case_ =   use_cache

       # Informer
       snake_case_ =   attention_type
       snake_case_ =   sampling_factor
       snake_case_ =   distil

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





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