

"""simple docstring"""

from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxSeqaSeqConfigWithPast
from ...utils import logging


a_			   =					logging.get_logger(__name__)

a_			   =					{
    '''google/umt5-small''': '''https://huggingface.co/google/umt5-small/resolve/main/config.json''',
    # See all umt5 models at https://huggingface.co/models?filter=umt5
}







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							Dict							       =		"""umt5"""
						_A		:							Any							       =		["""past_key_values"""]







						def __init__(self   ,		lowercase__=25_01_12   ,		lowercase__=5_12   ,		lowercase__=64   ,		lowercase__=10_24   ,		lowercase__=8   ,		lowercase__=None   ,		lowercase__=6   ,		lowercase__=32   ,		lowercase__=1_28   ,		lowercase__=0.1   ,		lowercase__=1e-6   ,		lowercase__=1.0   ,		lowercase__="gated-gelu"   ,		lowercase__=True   ,		lowercase__=True   ,		lowercase__="T5Tokenizer"   ,		lowercase__=True   ,		lowercase__=0   ,		lowercase__=1   ,		lowercase__=0   ,		**lowercase__   ,		):
											super().__init__(
											    is_encoder_decoder=lowercase__   ,		tokenizer_class=lowercase__   ,		tie_word_embeddings=lowercase__   ,		pad_token_id=lowercase__   ,		eos_token_id=lowercase__   ,		decoder_start_token_id=lowercase__   ,		**lowercase__   ,		)
											snake_case_					:		List[Any] 					=					vocab_size
											snake_case_					:		Dict 					=					d_model
											snake_case_					:		str 					=					d_kv
											snake_case_					:		Optional[Any] 					=					d_ff
											snake_case_					:		List[Any] 					=					num_layers
											snake_case_					:		Dict 					=					(
											    num_decoder_layers if num_decoder_layers is not None else self.num_layers
											)  # default = symmetry
											snake_case_					:		List[Any] 					=					num_heads
											snake_case_					:		List[str] 					=					relative_attention_num_buckets
											snake_case_					:		Optional[Any] 					=					relative_attention_max_distance
											snake_case_					:		Tuple 					=					dropout_rate
											snake_case_					:		Optional[int] 					=					layer_norm_epsilon
											snake_case_					:		List[str] 					=					initializer_factor
											snake_case_					:		List[str] 					=					feed_forward_proj
											snake_case_					:		List[str] 					=					use_cache

											snake_case_					:		Optional[int] 					=					self.feed_forward_proj.split("""-"""       )
											snake_case_					:		List[Any] 					=					act_info[-1]
											snake_case_					:		int 					=					act_info[0] == """gated"""

											if len(lowercase__       ) > 1 and act_info[0] != "gated" or len(lowercase__       ) > 2:
																raise ValueError(
																    f'`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer.'
																    """Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. """
																    """'gated-gelu' or 'relu'"""       )

											if feed_forward_proj == "gated-gelu":
																snake_case_					:		str 					=					"""gelu_new"""







						@property
						def 						__UpperCamelCase							(self       ):
											return self.d_model







						@property
						def 						__UpperCamelCase							(self       ):
											return self.num_heads







						@property
						def 						__UpperCamelCase							(self       ):
											return self.num_layers







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						@property
						# Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.inputs
						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Any 					=					{
											    """input_ids""": {0: """batch""", 1: """encoder_sequence"""},
											    """attention_mask""": {0: """batch""", 1: """encoder_sequence"""},
											}
											if self.use_past:
																snake_case_					:		Optional[int] 					=					"""past_encoder_sequence + sequence"""
																snake_case_					:		Dict 					=					{0: """batch"""}
																snake_case_					:		str 					=					{0: """batch""", 1: """past_decoder_sequence + sequence"""}
											else:
																snake_case_					:		Tuple 					=					{0: """batch""", 1: """decoder_sequence"""}
																snake_case_					:		Union[str, Any] 					=					{0: """batch""", 1: """decoder_sequence"""}

											if self.use_past:
																self.fill_with_past_key_values_(lowercase__   ,		direction="""inputs"""       )

											return common_inputs







						@property
						# Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.default_onnx_opset
						def 						__UpperCamelCase							(self       ):
											return 13







						@property
						def 						__UpperCamelCase							(self       ):
											return 5e-4









"""simple docstring"""

import copy

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


a_			   =					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(_UpperCAmelCase)
class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							Optional[int]							       =		"""rag"""
						_A		:							Optional[Any]							       =		True







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

											from ..auto.configuration_auto import AutoConfig

											snake_case_					:		List[str] 					=					AutoConfig.for_model(lowercase__   ,		**lowercase__       )
											snake_case_					:		Tuple 					=					AutoConfig.for_model(lowercase__   ,		**lowercase__       )

											snake_case_					:		int 					=					reduce_loss
											snake_case_					:		Optional[int] 					=					label_smoothing
											snake_case_					:		Dict 					=					exclude_bos_score
											snake_case_					:		Union[str, Any] 					=					do_marginalize

											snake_case_					:		Union[str, Any] 					=					title_sep
											snake_case_					:		int 					=					doc_sep
											snake_case_					:		int 					=					n_docs
											snake_case_					:		List[str] 					=					max_combined_length

											snake_case_					:		Tuple 					=					dataset
											snake_case_					:		int 					=					dataset_split
											snake_case_					:		str 					=					index_name

											snake_case_					:		List[str] 					=					retrieval_vector_size
											snake_case_					:		Dict 					=					retrieval_batch_size
											snake_case_					:		str 					=					passages_path
											snake_case_					:		Union[str, Any] 					=					index_path
											snake_case_					:		Tuple 					=					use_dummy_dataset

											snake_case_					:		Dict 					=					output_retrieved

											snake_case_					:		str 					=					do_deduplication

											snake_case_					:		Any 					=					use_cache

											if self.forced_eos_token_id is None:
																snake_case_					:		Any 					=					getattr(self.generator   ,		"""forced_eos_token_id"""   ,		lowercase__       )







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







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Optional[Any] 					=					copy.deepcopy(self.__dict__       )
											snake_case_					:		Any 					=					self.question_encoder.to_dict()
											snake_case_					:		Dict 					=					self.generator.to_dict()
											snake_case_					:		Union[str, Any] 					=					self.__class__.model_type
											return output




