Ë
    ÜÓ^jZ ã                   óü  — d Z ddlmZ ddlmZ ddlZddlmZ ddlmZm	Z	 ddl
mZ dd	lmZmZmZmZmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ ddlmZ ddlmZ  ej>                  e «      Z! ed¬«      e G d„ de«      «       «       Z"ee G d„ de«      «       «       Z# ed¬«      e G d„ de«      «       «       Z$e G d„ de$«      «       Z% ed¬«       G d„ de$«      «       Z& ed¬«       G d „ d!e$e«      «       Z'g d"¢Z(y)#zRAG model implementation.é    )ÚCallable)Ú	dataclassN)Únné   )ÚCacheÚEncoderDecoderCache)ÚPreTrainedConfig)ÚGenerationConfigÚGenerationMixinÚGenerationModeÚLogitsProcessorListÚStoppingCriteriaList)ÚGENERATION_MODES_MAPPING)ÚModelOutput)ÚPreTrainedModel)Úauto_docstringÚloggingé   )Ú	RagConfig)ÚRagRetrieverzI
    Base class for retriever augmented marginalized models outputs.
    )Úcustom_introc                   óì  — e Zd ZU dZdZej                  dz  ed<   dZej                  dz  ed<   dZ	ej                  dz  ed<   dZ
edz  ed<   dZej                  dz  ed<   dZej                  dz  ed<   dZej                  dz  ed	<   dZej                  dz  ed
<   dZej                  dz  ed<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   dZej                  dz  ed<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   y)ÚRetrievAugLMMarginOutputa¢  
    loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
        Language modeling loss.
    logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
        Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
        each vocabulary token.
    doc_scores (`torch.FloatTensor` of shape `(batch_size, config.n_docs)`):
        Score between each retrieved document embeddings (see `retrieved_doc_embeds`) and
        `question_encoder_last_hidden_state`.
    past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
        It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

        Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
        (see `past_key_values` input) to speed up sequential decoding.
    retrieved_doc_embeds (`torch.FloatTensor` of shape `(batch_size, config.n_docs, hidden_size)`, *optional*, returned when *output_retrieved=True*):
        Embedded documents retrieved by the retriever. Is used with `question_encoder_last_hidden_state` to compute
        the `doc_scores`.
    retrieved_doc_ids (`torch.LongTensor` of shape `(batch_size, config.n_docs)`, *optional*, returned when *output_retrieved=True*):
        The indexes of the embedded documents retrieved by the retriever.
    context_input_ids (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
        Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.
    context_attention_mask (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
        Attention mask post-processed from the retrieved documents and the question encoder `input_ids` by the
        retriever.
    question_encoder_last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
        Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
        model.
    question_enc_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
        Tuple of `torch.FloatTensor` (one for the output of the embeddings and one for the output of each layer) of
        shape `(batch_size, sequence_length, hidden_size)`.

        Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.
    question_enc_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
        Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
        sequence_length)`.

        Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
        average in the self-attention heads.
    generator_enc_last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
        Sequence of hidden-states at the output of the last layer of the generator encoder of the model.
    generator_enc_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
        Tuple of `torch.FloatTensor` (one for the output of the embeddings and one for the output of each layer) of
        shape `(batch_size, sequence_length, hidden_size)`.

        Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.
    generator_enc_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
        Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
        sequence_length)`.

        Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
        average in the self-attention heads.
    generator_dec_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
        Tuple of `torch.FloatTensor` (one for the output of the embeddings and one for the output of each layer) of
        shape `(batch_size, sequence_length, hidden_size)`.

        Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.
    generator_dec_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
        Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
        sequence_length)`.

        Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
        average in the self-attention heads.
    generator_cross_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
        Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
        sequence_length)`.

        Cross-attentions weights of the generator decoder, after the attention softmax, used to compute the
        weighted average in the cross-attention heads.
    NÚlossÚlogitsÚ
doc_scoresÚpast_key_valuesÚretrieved_doc_embedsÚretrieved_doc_idsÚcontext_input_idsÚcontext_attention_maskÚ"question_encoder_last_hidden_state.Úquestion_enc_hidden_statesÚquestion_enc_attentionsÚgenerator_enc_last_hidden_stateÚgenerator_enc_hidden_statesÚgenerator_enc_attentionsÚgenerator_dec_hidden_statesÚgenerator_dec_attentionsÚgenerator_cross_attentions)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚtorchÚFloatTensorÚ__annotations__r   r   r   r   r   r   Ú
LongTensorr    r!   r"   r#   Útupler$   r%   r&   r'   r(   r)   r*   © ó    úo/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/rag/modeling_rag.pyr   r   $   s¼  … ñDðL &*€Dˆ%×
Ñ
˜dÑ
"Ó)Ø'+€FˆE×Ñ Ñ$Ó+Ø+/€J�×!Ñ! DÑ(Ó/Ø$(€O�U˜T‘\Ó(Ø59Ð˜%×+Ñ+¨dÑ2Ó9Ø15Ð�u×'Ñ'¨$Ñ.Ó5Ø15Ð�u×'Ñ'¨$Ñ.Ó5Ø6:Ð˜E×,Ñ,¨tÑ3Ó:ØCGÐ&¨×(9Ñ(9¸DÑ(@ÓGØGKÐ  e×&7Ñ&7¸Ð&<Ñ =ÀÑ DÓKØDHÐ˜U 5×#4Ñ#4°cÐ#9Ñ:¸TÑAÓHØ@DÐ# U×%6Ñ%6¸Ñ%=ÓDØHLÐ  u×'8Ñ'8¸#Ð'=Ñ!>ÀÑ!EÓLØEIÐ˜e E×$5Ñ$5°sÐ$:Ñ;¸dÑBÓIØHLÐ  u×'8Ñ'8¸#Ð'=Ñ!>ÀÑ!EÓLØEIÐ˜e E×$5Ñ$5°sÐ$:Ñ;¸dÑBÓIØGKÐ  e×&7Ñ&7¸Ð&<Ñ =ÀÑ DÔKr5   r   c                   óÄ  — e Zd ZU dZdZej                  dz  ed<   dZej                  dz  ed<   dZ	e
dz  ed<   dZej                  dz  ed<   dZej                  dz  ed<   dZej                  dz  ed<   dZej                  dz  ed	<   dZej                  dz  ed
<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   dZej                  dz  ed<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   dZeej                  df   dz  ed<   y)ÚRetrievAugLMOutputa"  
    logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
        Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
        each vocabulary token.
    doc_scores (`torch.FloatTensor` of shape `(batch_size, config.n_docs)`):
        Score between each retrieved document embeddings (see `retrieved_doc_embeds`) and
        `question_encoder_last_hidden_state`.
    past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
        It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

        Contains precomputed hidden-states (key and values in the attention blocks) of the decoder that can be used
        (see `past_key_values` input) to speed up sequential decoding.
    retrieved_doc_embeds (`torch.FloatTensor` of shape `(batch_size, config.n_docs, hidden_size)`, *optional*, returned when *output_retrieved=True*):
        Embedded documents retrieved by the retriever. Is used with `question_encoder_last_hidden_state` to compute
        the `doc_scores`.
    retrieved_doc_ids (`torch.LongTensor` of shape `(batch_size, config.n_docs)`, *optional*, returned when *output_retrieved=True*):
        The indexes of the embedded documents retrieved by the retriever.
    context_input_ids (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
        Input ids post-processed from the retrieved documents and the question encoder input_ids by the retriever.
    context_attention_mask (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
        Attention mask post-processed from the retrieved documents and the question encoder `input_ids` by the
        retriever.
    question_encoder_last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
        Sequence of hidden states at the output of the last layer of the question encoder pooled output of the
        model.
    question_enc_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
        Tuple of `torch.FloatTensor` (one for the output of the embeddings and one for the output of each layer) of
        shape `(batch_size, sequence_length, hidden_size)`.

        Hidden states of the question encoder at the output of each layer plus the initial embedding outputs.
    question_enc_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
        Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
        sequence_length)`.

        Attentions weights of the question encoder, after the attention softmax, used to compute the weighted
        average in the self-attention heads.
    generator_enc_last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
        Sequence of hidden-states at the output of the last layer of the generator encoder of the model.
    generator_enc_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
        Tuple of `torch.FloatTensor` (one for the output of the embeddings and one for the output of each layer) of
        shape `(batch_size, sequence_length, hidden_size)`.

        Hidden states of the generator encoder at the output of each layer plus the initial embedding outputs.
    generator_enc_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
        Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
        sequence_length)`.

        Attentions weights of the generator encoder, after the attention softmax, used to compute the weighted
        average in the self-attention heads.
    generator_dec_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
        Tuple of `torch.FloatTensor` (one for the output of the embeddings and one for the output of each layer) of
        shape `(batch_size, sequence_length, hidden_size)`.

        Hidden states of the generator decoder at the output of each layer plus the initial embedding outputs.
    generator_dec_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
        Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
        sequence_length)`.

        Attentions weights of the generator decoder, after the attention softmax, used to compute the weighted
        average in the self-attention heads.
    generator_cross_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
        Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
        sequence_length)`.

        Cross-attentions weights of the generator decoder, after the attention softmax, used to compute the
        weighted average in the cross-attention heads.
    Nr   r   r   r   r   r    r!   r"   .r#   r$   r%   r&   r'   r(   r)   r*   )r+   r,   r-   r.   r   r/   r0   r1   r   r   r   r   r   r2   r    r!   r"   r#   r3   r$   r%   r&   r'   r(   r)   r*   r4   r5   r6   r8   r8   „   s§  … ñBðH (,€FˆE×Ñ Ñ$Ó+Ø+/€J�×!Ñ! DÑ(Ó/Ø$(€O�U˜T‘\Ó(Ø59Ð˜%×+Ñ+¨dÑ2Ó9Ø15Ð�u×'Ñ'¨$Ñ.Ó5Ø15Ð�u×'Ñ'¨$Ñ.Ó5Ø6:Ð˜E×,Ñ,¨tÑ3Ó:ØCGÐ&¨×(9Ñ(9¸DÑ(@ÓGØGKÐ  e×&7Ñ&7¸Ð&<Ñ =ÀÑ DÓKØDHÐ˜U 5×#4Ñ#4°cÐ#9Ñ:¸TÑAÓHØ@DÐ# U×%6Ñ%6¸Ñ%=ÓDØHLÐ  u×'8Ñ'8¸#Ð'=Ñ!>ÀÑ!EÓLØEIÐ˜e E×$5Ñ$5°sÐ$:Ñ;¸dÑBÓIØHLÐ  u×'8Ñ'8¸#Ð'=Ñ!>ÀÑ!EÓLØEIÐ˜e E×$5Ñ$5°sÐ$:Ñ;¸dÑBÓIØGKÐ  e×&7Ñ&7¸Ð&<Ñ =ÀÑ DÔKr5   r8   a¹  
    RAG models were released with the paper [Retrieval-Augmented Generation for Knowledge-Intensive NLP
    Tasks](https://huggingface.co/papers/2005.11401) by Patrick Lewis, Ethan Perez, Aleksandra Piktus et al.

    RAG is a retriever augmented model and encapsulate three components: a question encoder, a dataset retriever and a
    generator, the encoder and generator are trainable while the retriever is just an indexed dataset.
    c            
       ó`   — e Zd ZU eed<   dZdZdZe	 	 	 d
de	dz  de	dz  de
dz  defd	„«       Zy)ÚRagPreTrainedModelÚconfigÚragTNÚ.question_encoder_pretrained_model_name_or_pathÚ'generator_pretrained_model_name_or_pathÚ	retrieverÚreturnc                 ó^  — |j                  «       D ��ci c]%  \  }}|j                  d«      r|t        d«      d |“Œ' }}}|j                  «       D ��ci c]%  \  }}|j                  d«      r|t        d«      d |“Œ' }}}|D ]  }	|d|	z   = Œ
 |D ]  }	|d|	z   = Œ
 |j                  dd«      }
|
€K|€J d«       ‚ddlm} d|vr%dd	lm}  |j                  |fi |¤d
di¤Ž\  }}||d<    |j                  |fi |¤Ž}
|j                  dd«      }|€K|€J d«       ‚ddlm	} d|vr%dd	lm}  |j                  |fi |¤d
di¤Ž\  }}||d<    |j                  |fi |¤Ž}|j                  d«      }|€+t        j                  |
j                  |j                  fi |¤Ž} | |
|||¬«      S c c}}w c c}}w )a  
        Instantiates an question encoder and a generator from one or two base classes of the library from pretrained
        model checkpoints.

        The model is set in evaluation mode by default using `model.eval()` (Dropout modules are deactivated). To train
        the model, you need to first set it back in training mode with `model.train()`.

        Params:
            question_encoder_pretrained_model_name_or_path (`str`, *optional*, defaults to `None`):
                Information necessary to initiate the question encoder. Can be either:

                    - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                    - A path to a *directory* containing model weights saved using
                      [`~PreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.

            generator_pretrained_model_name_or_path (`str`, *optional*, defaults to `None`):
                Information necessary to initiate the generator. Can be either:

                    - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                    - A path to a *directory* containing model weights saved using
                      [`~PreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.

            model_args (remaining positional arguments, *optional*):
                All remaining positional arguments will be passed to the underlying model's `__init__` method.
            retriever ([`RagRetriever`], *optional*):
                The retriever to use.
            kwwargs (remaining dictionary of keyword arguments, *optional*):
                Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
                `output_attentions=True`).

                - To update the question_encoder configuration, use the prefix *question_encoder_* for each
                  configuration parameter.
                - To update the generator configuration, use the prefix *generator_* for each configuration parameter.
                - To update the parent model configuration, do not use a prefix for each configuration parameter.

                Behaves differently depending on whether a `config` is provided or automatically loaded.

        Example:

        ```python
        >>> from transformers import RagModel

        >>> # initialize a RAG from two pretrained models.
        >>> model = RagModel.from_pretrained_question_encoder_generator(
        ...     "facebook/dpr-question_encoder-single-nq-base", "google-t5/t5-small"
        ... )
        >>> # saving model after fine-tuning
        >>> model.save_pretrained("./rag")
        >>> # load fine-tuned model
        >>> model = RagModel.from_pretrained("./rag")
        ```Úquestion_encoder_NÚ
generator_ÚmodelznIf `model` is not defined as an argument, a `question_encoder_pretrained_model_name_or_path` has to be definedé   ©Ú	AutoModelr;   )Ú
AutoConfigÚreturn_unused_kwargsTzqIf `generator_model` is not defined as an argument, a `generator_pretrained_model_name_or_path` has to be defined©ÚAutoModelForSeq2SeqLM)Úquestion_encoderÚ	generatorr;   r?   )ÚitemsÚ
startswithÚlenÚpopÚauto.modeling_autorG   Úauto.configuration_autorH   Úfrom_pretrainedrK   Úgetr   Ú'from_question_encoder_generator_configsr;   )Úclsr=   r>   r?   ÚkwargsÚargumentÚvalueÚkwargs_question_encoderÚkwargs_generatorÚkeyrL   rG   rH   Úquestion_encoder_configrM   rK   Úgenerator_configr;   s                     r6   Ú*from_pretrained_question_encoder_generatorz=RagPreTrainedModel.from_pretrained_question_encoder_generatorí   so  € ð| $*§<¡<£>÷#
á�˜%Ø×"Ñ"Ð#6Ô7ð ”SÐ,Ó-Ð/Ð0°%Ñ7ð#
Ðñ #
ð $*§<¡<£>÷
á�˜%Ø×"Ñ" <Ô0ð ”S˜Ó&Ð(Ð)¨5Ñ0ð
Ðñ 
ð +ò 	2ˆCØÐ*¨SÑ0Ñ1ð	2à#ò 	+ˆCØ�| cÑ)Ñ*ð	+ð 3×6Ñ6°wÀÓEÐØÐ#ØAÐMð ðóÐMõ 7àÐ6Ñ6Ý@àC]À:×C]ÑC]ØBñDà-ñDð *.òDÑ@Ð'Ð)@ð
 5LÐ'¨Ñ1à8˜y×8Ñ8Ø>ñ ØBYñ Ðð %×(Ñ(¨°$Ó7ˆ	ØÐØ:ÐFð ð!óÐFõ CàÐ/Ñ/Ý@à5O°Z×5OÑ5OØ;ñ6Ø?Oñ6Øfjò6Ñ2Ð Ð"2ð .>Ð  Ñ*à=Ð-×=Ñ=Ø7ñØ;KñˆIð
 —‘˜HÓ%ˆØˆ>Ü×FÑFØ ×'Ñ'¨×)9Ñ)9ñØ=CñˆFñ Ð$4À	ÐRXÐdmÔnÐnùóO#
ùó
s   ”*F#Á*F))NNN)r+   r,   r-   r   r1   Úbase_model_prefixÚ_supports_flash_attnÚ_supports_sdpaÚclassmethodÚstrr   r   r`   r4   r5   r6   r:   r:   Ý   sy   … ð ÓØÐØÐØ€Nàð FJØ>BØ)-ñ	Boà8;¸d¹
ðBoð 25°t±ðBoð   $Ñ&ð	Boð 
òBoó ñBor5   r:   c            !       óÞ  ‡ — e Zd Z	 	 	 	 ddedz  dedz  dedz  dedz  fˆ fd„Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddej                  dz  dej                  dz  d	eeej                        dz  d
ej                  dz  dej                  dz  dedz  dej                  dz  dej                  dz  dej                  dz  dedz  dedz  dedz  dedz  dedz  deej                     ez  fd„«       Zˆ xZS )ÚRagModelNr;   rL   rM   r?   c                 óh  •— |€|�|€J d«       ‚|€,t        j                  |j                  |j                  fi |¤Ž}n-t        || j                  «      sJ d|› d| j                  › �«       ‚t
        ‰| �  |«       |€!ddlm} |j                  |j                  «      }|€!ddlm} |j                  |j                  «      }|| _        | j                  �5t        |t        «      sJ dt        | j                  «      › d	�«       ‚|| _        || _
        || _        d| _        d
| _        | j%                  «        y)áÉ  
        question_encoder (`PreTrainedModel`, *optional*):
            The model responsible for encoding the question into hidden states for retrieval.
        generator (`PreTrainedModel`, *optional*):
            The model responsible for generating text based on retrieved documents.
        retriever (`RagRetriever`, *optional*):
            The component responsible for retrieving documents from a knowledge base given the encoded question.
        NzQEither a configuration or an question_encoder and a generator has to be provided.zconfig: z has to be of type rE   rF   rJ   z`self.retriever` is of type z&, but should be of type `RagRetriever`F)r   rV   r;   Ú
isinstanceÚconfig_classÚsuperÚ__init__rR   rG   Úfrom_configrL   rK   rM   r?   r   ÚtypeÚctx_encoderÚcontext_encoder_trainingÚ	post_init)	Úselfr;   rL   rM   r?   rX   rG   rK   Ú	__class__s	           €r6   rm   zRagModel.__init__u  sF  ø€ ð  Ð!Ð&6Ð&BÀyÐG\ð 	
Ø_ó	
Ð]ð ˆ>Ü×FÑFØ ×'Ñ'¨×)9Ñ)9ñØ=Cñ‰Fô ˜f d×&7Ñ&7Ô8Ðs¸HÀVÀHÐL_Ð`d×`qÑ`qÐ_rÐ:sÓsÐ8Ü‰Ñ˜Ô ØÐ#Ý6à(×4Ñ4°V×5LÑ5LÓMÐàÐÝBà-×9Ñ9¸&×:JÑ:JÓKˆIà"ˆŒØ�>‰>Ð%Ü˜i¬Ô6ð Ø.¬t°D·N±NÓ/CÐ.DÐDjÐkóÐ6ð 'ˆDŒNà 0ˆÔØ"ˆŒàˆÔØ(-ˆÔ%à�‰Õr5   Ú	input_idsÚattention_maskÚencoder_outputsÚdecoder_input_idsÚdecoder_attention_maskr   r   r    r!   Ú	use_cacheÚoutput_attentionsÚoutput_hidden_statesÚoutput_retrievedÚn_docsr@   c                 ó  — |�|n| j                   j                  }|
�|
n| j                   j                  }
|�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j
                  }| j                  duxr |du xs
 |	du xs |du xr |du }|�€*|�r| j                  ||d¬«      }|d   }| j                  ||j                  «       j                  dt        j                  ¬«      j                  «       t        | j                  j                   dd«      |d¬	«      }| j                  rè|d
   |d   |d   |d   |d   |d   f\  }}	}}}}|j                  |«      }|	j                  |«      }	|j                  |«      }|j                  |«      }| j!                  ||d¬«      j"                  }|j%                  d||j&                  d   «      }t        j(                  |j+                  d«      |j-                  dd«      «      j/                  d«      }nª|d
   |d   |d   |d   f\  }}	}}|j                  |«      }|j                  |«      }|	j                  |«      }	t        j(                  |j+                  d«      |j-                  dd«      «      j/                  d«      }n|€J d«       ‚|	€J d«       ‚|€J d«       ‚|€J d«       ‚|j&                  d   |z  dk(  sJ d|› d|j&                  d   › d�«       ‚|�|j1                  |d¬«      }|�|j1                  |d¬«      }| j                  ||	|||||
|d¬«	      }|sd}d}d}d}d}nj2                  }|j4                  }|r|sd}d}	d}d}t7        d*i d|j8                  “d|“d|j:                  “d
|“d|	“d“d “d!“d"|“d#|“d$|j<                  “d%|j>                  “d&|j@                  “d'|jB                  “d(|jD                  “d)|jF                  “ŽS )+ay  
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. [`RagConfig`], used to initialize the model, specifies
            which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
            obtain the indices.

            [What are input IDs?](../glossary#input-ids)
        encoder_outputs (`tuple(tuple(torch.FloatTensor)`, *optional*)
            Tuple consists of (`generator_enc_last_hidden_state`, *optional*: `generator_enc_hidden_states`,
            *optional*: `generator_enc_attentions`). `generator_enc_last_hidden_state` of shape `(batch_size, n_docs *
            sequence_length, hidden_size)` is a sequence of hidden-states at the output of the last layer of the
            generator's encoder.

            Used by the ([`RagModel`]) model during decoding.
        decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Provide for generation tasks. `None` by default, construct as per instructions for the generator model
            you're using with your RAG instance.
        decoder_attention_mask (`torch.BoolTensor` of shape `(batch_size,  target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
            be used by default.
        doc_scores (`torch.FloatTensor` of shape `(batch_size, config.n_docs)`):
            Score between each retrieved document embeddings (see `retrieved_doc_embeds`) and
            `question_encoder_last_hidden_state`. If the model has is not initialized with a `retriever` `doc_scores`
            has to be provided to the forward pass. `doc_scores` can be computed via
            `question_encoder_last_hidden_state` and `retrieved_doc_embeds`, see examples for more information.
        context_input_ids (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
            Input IDs post-processed from the retrieved documents and the question encoder `input_ids` by the
            retriever. If the model was not initialized with a `retriever` ``context_input_ids` has to be provided to
            the forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
        context_attention_mask (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`,*optional*, returned when *output_retrieved=True*):
            Attention mask post-processed from the retrieved documents and the question encoder `input_ids` by the
            retriever. If the model has is not initialized with a `retriever` `context_attention_mask` has to be
            provided to the forward pass. `context_attention_mask` are returned by [`~RagRetriever.__call__`].
        output_retrieved (`bool`, *optional*):
            Whether or not to return the `retrieved_doc_embeds`, `retrieved_doc_ids`, `context_input_ids` and
            `context_attention_mask`. See returned tensors for more detail.
        n_docs (`int`, *optional*):
            The number of documents to retrieve.

        Example:

        ```python
        >>> from transformers import AutoTokenizer, RagRetriever, RagModel
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/rag-token-base")
        >>> retriever = RagRetriever.from_pretrained(
        ...     "facebook/rag-token-base", index_name="exact", use_dummy_dataset=True
        ... )
        >>> # initialize with RagRetriever to do everything in one forward call
        >>> model = RagModel.from_pretrained("facebook/rag-token-base", retriever=retriever)

        >>> inputs = tokenizer("How many people live in Paris?", return_tensors="pt")
        >>> outputs = model(input_ids=inputs["input_ids"])
        ```NT)rv   Úreturn_dictr   Úcpu©ÚdeviceÚdtypeÚprefixÚpt©r…   r~   Úreturn_tensorsr    r!   r   Útokenized_doc_idsÚtokenized_doc_attention_maskÚdoc_idséÿÿÿÿr   rE   z˜Make sure that `context_input_ids` are passed, if no `retriever` is set. Alternatively, you can set a retriever using the `set_retriever(...)` function.z�Make sure that `context_attention_mask` are passed, if no `retriever` is set. Alternatively, you can set a retriever using the `set_retriever(...)` function.z‘Make sure that `doc_scores` are passed, if no `retriever` is set. Alternatively, you can set a retriever using the `set_retriever(...)` function.z^Make sure that `doc_scores` are passed when passing `encoder_outputs` to the forward function.úM The first dimension of `context_input_ids` should be a multiple of `n_docs`=ú	, but is ú.©Údim)	ru   rv   rw   rx   ry   r   rz   r{   r€   ©Nr   r   r   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r4   )$r;   r~   rz   r{   r|   r}   r?   rL   ÚdetachÚtor/   Úfloat32ÚnumpyÚgetattrrM   rq   rp   Úpooler_outputÚviewÚshapeÚbmmÚ	unsqueezeÚ	transposeÚsqueezeÚrepeat_interleaveÚhidden_statesÚ
attentionsr8   r   r   Úencoder_last_hidden_stateÚencoder_hidden_statesÚencoder_attentionsÚdecoder_hidden_statesÚdecoder_attentionsÚcross_attentions)rs   ru   rv   rw   rx   ry   r   r   r    r!   rz   r{   r|   r}   r~   rX   Úhas_to_retrieveÚquestion_enc_outputsr"   Úretriever_outputsr   Úretrieved_doc_input_idsÚretrieved_doc_attention_maskr   Úgen_outputsr#   r$   s                              r6   ÚforwardzRagModel.forward©  s�  € ðT "Ð-‘°4·;±;×3EÑ3EˆØ!*Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø1BÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð 0@Ð/KÑ+ÐQU×Q\ÑQ\×QmÑQmÐð �N‰N $Ð&ò (Ø" dÐ*ÒbÐ.DÈÐ.LÒbÐPZÐ^bÐPbò(à 4Ð'ð 	ð Ñ"ÚØ'+×'<Ñ'<Ø¨nÈ$ð (=ó (Ð$ð 6JÈ!Ñ5LÐ2à$(§N¡NØØ6×=Ñ=Ó?×BÑBÈ%ÔW\×WdÑWdÐBÓe×kÑkÓmÜ" 4§>¡>×#8Ñ#8¸(ÀDÓIØ!Ø#'ð %3ó %Ð!ð ×0Ò0ð *Ð*=Ñ>Ø)Ð*BÑCØ)Ð*@ÑAØ)Ð*=Ñ>Ø)Ð*HÑIØ)¨)Ñ4ðñØ)Ø.Ø,Ø/Ø4Ø)ð ):×(<Ñ(<¸YÓ(GÐ%Ø-C×-FÑ-FÀyÓ-QÐ*à.E×.HÑ.HÈÓ.SÐ+Ø3O×3RÑ3RÐS\Ó3]Ð0Ø+/×+;Ñ+;Ø/Ð@\Ðjnð ,<ó ,ç#‘mð )ð ,@×+DÑ+DØ˜FÐ$F×$LÑ$LÈQÑ$Oó,Ð(ô
 "'§¡Ø:×DÑDÀQÓGÐI]×IgÑIgÐhiÐklÓImó"ç‘g˜a“jñ ð *Ð*=Ñ>Ø)Ð*BÑCØ)Ð*@ÑAØ)¨)Ñ4ð	jÑfÐ%Ð'=Ð?SÐUfð ,@×+BÑ+BÐCeÓ+fÐ(Ø(9×(<Ñ(<¸YÓ(GÐ%Ø-C×-FÑ-FÀyÓ-QÐ*ô "'§¡Ø:×DÑDÀQÓGÐI]×IgÑIgÐhiÐklÓImó"ç‘g˜a“jñ ð )Ð4ð ðPóÐ4ð .Ð9ð ðTóÐ9ð "Ð-ð ðJóÐ-ð
 Ð%ð 	
Øló	
Ð%ð × Ñ  Ñ# fÑ,°Ò2ð 	
Ø[Ð\bÐ[cð dØ!×'Ñ'¨Ñ*Ð+¨1ð.ó	
Ð2ð Ð(Ø 1× CÑ CÀFÐPQÐ CÓ RÐà!Ð-Ø%;×%MÑ%MÈfÐZ[Ð%MÓ%\Ð"à—n‘nØ'Ø1Ø+Ø/Ø#9Ø+ØØ/Øð %ó 

ˆñ Ø15Ð.Ø)-Ð&Ø&*Ð#Ø#'Ð Ø $Ñà)=×)KÑ)KÐ&Ø&:×&EÑ&EÐ#áÑ&6à 'ÐØ%)Ð"Ø#'Ð Ø $Ðä!ò 
Ø×%Ò%ð
á!ð
ð (×7Ò7ð
ñ 0ð	
ñ
 $:ð
ñ "6ð
ñ 0ð
ñ 0Rð
ñ (Bð
ñ %<ð
ð -8×,QÒ,Qð
ð )4×(IÒ(Ið
ð &1×%CÒ%Cð
ð )4×(IÒ(Ið
ð &1×%CÒ%Cð
ð  (3×'CÒ'Cð!
ð 	
r5   ©NNNN)NNNNNNNNNNNNNN)r+   r,   r-   r	   r   r   rm   r   r/   r2   ÚTensorr3   r0   Ú
BoolTensorr   ÚboolÚintr8   r®   Ú__classcell__©rt   s   @r6   rg   rg   s  s½  ø„ ð +/Ø37Ø,0Ø)-ñ2à  4Ñ'ð2ð *¨DÑ0ð2ð # TÑ)ð	2ð
   $Ñ&õ2ðh ð .2Ø.2ØBFØ59Ø:>Ø(,Ø/3Ø59Ø:>Ø!%Ø)-Ø,0Ø(,Ø!ñe
à×#Ñ# dÑ*ðe
ð Ÿ™ tÑ+ðe
ð ˜u U×%6Ñ%6Ñ7Ñ8¸4Ñ?ð	e
ð
 !×+Ñ+¨dÑ2ðe
ð !&× 0Ñ 0°4Ñ 7ðe
ð  ™ðe
ð ×%Ñ%¨Ñ,ðe
ð !×+Ñ+¨dÑ2ðe
ð !&× 0Ñ 0°4Ñ 7ðe
ð ˜$‘;ðe
ð   $™;ðe
ð # T™kðe
ð  ™+ðe
ð �d‘
ðe
ð" 
ˆu�|‰|Ñ	Ð1Ñ	1ò#e
ó ôe
r5   rg   zu
    A RAG-sequence model implementation. It performs RAG-sequence specific marginalization in the forward pass.
    c            &       ór  ‡ — e Zd Z	 	 	 	 d&dedz  dedz  dedz  dedz  fˆ fd„Zdefd„Zdefd	„Ze		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d'd
e
j                  dz  de
j                  dz  deee
j                        dz  de
j                  dz  de
j                  dz  dedz  de
j                  dz  de
j                  dz  de
j                   dz  dedz  dedz  dedz  dedz  dedz  dedz  de
j                  dz  dedz  def$d„«       Zed„ «       Zed„ «       Zed„ «       Z e
j2                  «       	 	 	 	 	 	 	 	 	 d(d
e
j                  dz  de
j                  dz  de
j                  dz  de
j                  dz  de
j                   dz  d edz  d!edz  d"edz  dedz  de
j                  fd#„«       Z	 d)d$„Zed%„ «       Zˆ xZS )*ÚRagSequenceForGenerationNr;   rL   rM   r?   c                 óà   •— |€|�|€J d«       ‚|€+t        j                  |j                  |j                  fi |¤Ž}t        ‰| �  |«       t        ||||¬«      | _        | j                  «        y©ri   NzHEither a configuration or an encoder and a generator has to be provided.)r;   rL   rM   r?   ©r   rV   r;   rl   rm   rg   r<   rr   ©rs   r;   rL   rM   r?   rX   rt   s         €r6   rm   z!RagSequenceForGeneration.__init__˜  s†   ø€ ð  Ð!Ð&6Ð&BÀyÐG\ð 	
ØVó	
Ð]ð ˆ>Ü×FÑFØ ×'Ñ'¨×)9Ñ)9ñØ=CñˆFô 	‰Ñ˜Ô ô  6Ð<LÐXaÐmvÔwˆŒà�‰Õr5   c                 ó&   — || j                   _        y r’   ©r<   r?   ©rs   r?   s     r6   Úset_retrieverz&RagSequenceForGeneration.set_retriever·  ó   € Ø&ˆ�‰Õr5   rp   c                 óH   — d| j                   _        || j                   _        y ©NT©r<   rq   rp   ©rs   rp   s     r6   Ú set_context_encoder_for_trainingz9RagSequenceForGeneration.set_context_encoder_for_trainingº  ó   € Ø,0ˆ�‰Ô)Ø*ˆ�‰Õr5   ru   rv   rw   rx   ry   r   r    r!   r   rz   r{   r|   r}   Úexclude_bos_scoreÚreduce_lossÚlabelsr~   r@   c                 ó,  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|�|€|}d}
| j	                  ||||||||	||
||||¬«      }d}|�@| j                  |j                  |j                  ||| j                   j                  ||¬«      }t        di d|“d|j                  “d|j                  “d|j                  “d	|j                  “d
|j                  “d|j                  “d|j                  “d|j                  “d|j                   “d|j"                  “d|j$                  “d|j&                  “d|j(                  “d|j*                  “d|j,                  “d|j.                  “ŽS )a3  
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. [`RagConfig`], used to initialize the model, specifies
            which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
            obtain the indices.

            [What are input IDs?](../glossary#input-ids)
        encoder_outputs (`tuple(tuple(torch.FloatTensor)`, *optional*)
            Tuple consists of (`generator_enc_last_hidden_state`, *optional*: `generator_enc_hidden_states`,
            *optional*: `generator_enc_attentions`). `generator_enc_last_hidden_state` of shape `(batch_size, n_docs *
            sequence_length, hidden_size)` is a sequence of hidden-states at the output of the last layer of the
            generator's encoder.

            Used by the ([`RagModel`]) model during decoding.
        decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Provide for generation tasks. `None` by default, construct as per instructions for the generator model
            you're using with your RAG instance.
        decoder_attention_mask (`torch.BoolTensor` of shape `(batch_size,  target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
            be used by default.
        context_input_ids (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
            Input IDs post-processed from the retrieved documents and the question encoder `input_ids` by the
            retriever. If the model was not initialized with a `retriever` ``context_input_ids` has to be provided to
            the forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
        context_attention_mask (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`,*optional*, returned when *output_retrieved=True*):
            Attention mask post-processed from the retrieved documents and the question encoder `input_ids` by the
            retriever. If the model has is not initialized with a `retriever` `context_attention_mask` has to be
            provided to the forward pass. `context_attention_mask` are returned by [`~RagRetriever.__call__`].
        doc_scores (`torch.FloatTensor` of shape `(batch_size, config.n_docs)`):
            Score between each retrieved document embeddings (see `retrieved_doc_embeds`) and
            `question_encoder_last_hidden_state`. If the model has is not initialized with a `retriever` `doc_scores`
            has to be provided to the forward pass. `doc_scores` can be computed via
            `question_encoder_last_hidden_state` and `retrieved_doc_embeds`, see examples for more information.
        output_retrieved (`bool`, *optional*):
            Whether or not to return the `retrieved_doc_embeds`, `retrieved_doc_ids`, `context_input_ids` and
            `context_attention_mask`. See returned tensors for more detail.
        exclude_bos_score (`bool`, *optional*):
            Only relevant if `labels` is passed. If `True`, the score of the BOS token is disregarded when computing
            the loss.
        reduce_loss (`bool`, *optional*):
            Only relevant if `labels` is passed. If `True`, the NLL loss is reduced using the `torch.Tensor.sum`
            operation.
        n_docs (`int`, *optional*):
            The number of documents to retrieve.

        Example:

        ```python
        >>> from transformers import AutoTokenizer, RagRetriever, RagSequenceForGeneration
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/rag-sequence-nq")
        >>> retriever = RagRetriever.from_pretrained(
        ...     "facebook/rag-sequence-nq", index_name="exact", use_dummy_dataset=True
        ... )
        >>> # initialize with RagRetriever to do everything in one forward call
        >>> model = RagSequenceForGeneration.from_pretrained("facebook/rag-token-nq", retriever=retriever)

        >>> inputs = tokenizer("How many people live in Paris?", return_tensors="pt")
        >>> targets = tokenizer(text_target="In Paris, there are 10 million people.", return_tensors="pt")
        >>> input_ids = inputs["input_ids"]
        >>> labels = targets["input_ids"]
        >>> outputs = model(input_ids=input_ids, labels=labels)

        >>> # or use retriever separately
        >>> model = RagSequenceForGeneration.from_pretrained("facebook/rag-sequence-nq", use_dummy_dataset=True)
        >>> # 1. Encode
        >>> question_hidden_states = model.question_encoder(input_ids)[0]
        >>> # 2. Retrieve
        >>> docs_dict = retriever(input_ids.numpy(), question_hidden_states.detach().numpy(), return_tensors="pt")
        >>> doc_scores = torch.bmm(
        ...     question_hidden_states.unsqueeze(1), docs_dict["retrieved_doc_embeds"].float().transpose(1, 2)
        ... ).squeeze(1)
        >>> # 3. Forward to generator
        >>> outputs = model(
        ...     context_input_ids=docs_dict["context_input_ids"],
        ...     context_attention_mask=docs_dict["context_attention_mask"],
        ...     doc_scores=doc_scores,
        ...     decoder_input_ids=labels,
        ... )
        ```NF©ru   rv   rw   rx   ry   r    r!   r   r   rz   r{   r|   r}   r~   )rÈ   ÚepsilonrÇ   r~   r   r   r   r   r    r!   r   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r4   )r;   r~   rÇ   rÈ   r<   Úget_nllr   r   Úlabel_smoothingr   r   r    r!   r   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   )rs   ru   rv   rw   rx   ry   r   r    r!   r   rz   r{   r|   r}   rÇ   rÈ   rÉ   r~   rX   Úoutputsr   s                        r6   r®   z RagSequenceForGeneration.forward¾  sü  € ðN "Ð-‘°4·;±;×3EÑ3EˆØ1BÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐØ%0Ð%<‘kÀ$Ç+Á+×BYÑBYˆàÐØ Ð(Ø$*Ð!ØˆIà—(‘(ØØ)Ø+Ø/Ø#9Ø/Ø#9Ø!Ø+ØØ/Ø!5Ø-Øð ó 
ˆð" ˆØÐØ—<‘<Ø—‘Ø×"Ñ"Ø!Ø'ØŸ™×3Ñ3Ø"3Øð  ó ˆDô (ò 
Ùð
à—>’>ð
ð ×)Ò)ð
ð $×3Ò3ð	
ð
 &×7Ò7ð
ð $+×#AÒ#Að
ð ")×!=Ò!=ð
ð &×7Ò7ð
ð 07×/YÒ/Yð
ð (/×'IÒ'Ið
ð %,×$CÒ$Cð
ð -4×,SÒ,Sð
ð )0×(KÒ(Kð
ð &-×%EÒ%Eð
ð )0×(KÒ(Kð
ð  &-×%EÒ%Eð!
ð" (/×'IÒ'Ið#
ð 	
r5   c                 ó.   — | j                   j                  S r’   r½   ©rs   s    r6   r?   z"RagSequenceForGeneration.retriever_  ó   € à�x‰x×!Ñ!Ð!r5   c                 ó.   — | j                   j                  S r’   ©r<   rM   rÑ   s    r6   rM   z"RagSequenceForGeneration.generatorc  rÒ   r5   c                 ó.   — | j                   j                  S r’   ©r<   rL   rÑ   s    r6   rL   z)RagSequenceForGeneration.question_encoderg  ó   € à�x‰x×(Ñ(Ð(r5   Údo_deduplicationÚnum_return_sequencesÚ	num_beamsc
                 óÖ  — |	�|	n| j                   j                  }	|�|n| j                   j                  }|�|nt        | j                   dd«      }|�|nt        | j                   dd«      }|€	|€J d«       ‚| j                  �œ|€š| j                  ||¬«      d   }| j	                  ||j                  «       j                  dt        j                  ¬	«      j                  «       t        | j                  j                   d
d«      |	d¬«      d   }|j                  |«      }g }||
d<   ||
d<   d|
d<   |�|j                  d   n|j                  d   |	z  }t        |«      D �]T  }|||	z  |dz   |	z   } | j                  j                  |fi |
¤Ž}|rRt        j                  t!        |D �ci c]  }t#        |j%                  «       «      |“Œ c}j'                  «       «      «      }|j                  d   }|�$|||dz    j)                  |d«      } | ||d¬«      }nq|€J d«       ‚|€J d«       ‚|j)                  |d«      }|||	z  |dz   |	z   }|j)                  |d«      }|||dz   …dd…f   }|j)                  |d«      } | ||||d¬«      }|d    j+                  |«      d   }|j-                  ||   «       �ŒW | j/                  || j                   j                  j0                  ¬«      S c c}w )a  
        Implements RAG sequence "thorough" decoding. Read the [`~generation.GenerationMixin.generate`]` documentation
        for more information on how to set other generate input parameters.

        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                The sequence used as a prompt for the generation. If `input_ids` is not passed, then
                `context_input_ids` has to be provided.
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

                - 1 for tokens that are **not masked**,
                - 0 for tokens that are **masked**.

                [What are attention masks?](../glossary#attention-mask)
            context_input_ids (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
                Input IDs post-processed from the retrieved documents and the question encoder input_ids by the
                retriever.
            context_attention_mask (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
                Attention mask post-processed from the retrieved documents and the question encoder `input_ids` by the
                retriever.

                If the model is not initialized with a `retriever` or `input_ids` is not given, `context_input_ids` and
                `context_attention_mask` have to be provided to the forward pass. They are returned by
                [`~RagRetriever.__call__`].
            doc_scores (`torch.FloatTensor` of shape `(batch_size, config.n_docs)`):
                Score between each retrieved document embeddings (see `retrieved_doc_embeds`) and
                `question_encoder_last_hidden_state`.

                If the model is not initialized with a `retriever` or `input_ids` is not given, `doc_scores` has to be
                provided to the forward pass. `doc_scores` are returned by [`~RagRetriever.__call__`].
            do_deduplication (`bool`, *optional*):
                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.
            num_return_sequences(`int`, *optional*, defaults to 1):
                The number of independently computed returned sequences for each element in the batch. Note that this
                is not the value we pass to the `generator`'s `[`~generation.GenerationMixin.generate`]` function,
                where we set `num_return_sequences` to `num_beams`.
            num_beams (`int`, *optional*, defaults to 1):
                Number of beams for beam search. 1 means no beam search.
            n_docs (`int`, *optional*, defaults to `config.n_docs`)
                Number of documents to retrieve and/or number of documents for which to generate an answer.
            kwargs (`dict[str, Any]`, *optional*):
                Additional kwargs will be passed to [`~generation.GenerationMixin.generate`].

        Return:
            `torch.LongTensor` of shape `(batch_size * num_return_sequences, sequence_length)`: The generated
            sequences. The second dimension (sequence length) is either equal to `max_length` or shorter if all batches
            finished early due to the `eos_token_id`.
        NrÙ   r   rÚ   z= At least one of input_ids or context_input_ids must be given©rv   r   r�   r‚   r…   r†   r‡   r    rv   T)rÉ   rÇ   z�Make sure that `context_attention_mask` are passed, if no `input_ids` is set. Alternatively, you can set a retriever using the `set_retriever(...)` function.z‘Make sure that `doc_scores` are passed, if no `input_ids` is set. Alternatively, you can set a retriever using the `set_retriever(...)` function.)r    r!   r   rÉ   rÇ   r   )Úpad_token_id)r;   r~   rØ   r—   r?   rL   r“   r”   r/   r•   r–   rM   rš   ÚrangeÚgenerateÚstackÚlistre   ÚtolistÚvaluesÚrepeatÚtopkÚappendÚ_cat_and_padrÝ   )rs   ru   rv   r    r!   r   rØ   rÙ   rÚ   r~   Úmodel_kwargsÚnum_doc_return_sequencesÚquestion_hidden_statesÚhyposÚ
batch_sizeÚindexÚgenerator_input_idsÚoutput_sequencesÚkÚnum_candidatesÚnew_input_idsrÏ   Úindividual_input_idsÚindividual_attention_maskÚindividual_doc_scoresÚtop_cand_indss                             r6   rß   z!RagSequenceForGeneration.generatek  s‰  € ðB "Ð-‘°4·;±;×3EÑ3EˆØ/?Ð/KÑ+ÐQU×Q\ÑQ\×QmÑQmÐð $Ð/ñ !ä˜Ÿ™Ð&<¸aÓ@ð 	!ð
 "+Ð!6‘I¼GÀDÇKÁKÐQ\Ð^_Ó<`ˆ	àÐ$Ð(9Ð(Eð 	
ØKó	
ÐEð �>‰>Ð%Ð*;Ð*CØ%)×%:Ñ%:¸9ÐUcÐ%:Ó%dÐefÑ%gÐ"Ø $§¡ØØ&×-Ñ-Ó/×2Ñ2¸%ÄuÇ}Á}Ð2ÓU×[Ñ[Ó]Ü˜tŸ~™~×4Ñ4°hÀÓEØØ#ð !/ó !ð "ñ!#Ðð !2× 4Ñ 4°YÓ ?ÐàˆØ$-ˆ�[Ñ!Ø/8ˆÐ+Ñ,Ø)-ˆÐ%Ñ&à+4Ð+@�Y—_‘_ QÒ'ÐFW×F]ÑF]Ð^_ÑF`ÐdjÑFjˆ
ä˜:Ó&ó 3	:ˆEà"3°E¸F±NÀeÈaÁiÐSYÑEYÐ"ZÐà6˜tŸ~™~×6Ñ6Ø#ñ àñ Ðñ  ä#(§;¡;¬tÐQaÖ4bÈA´S¸¿¹»³_ÀaÑ5GÒ4b×4iÑ4iÓ4kÓ/lÓ#mÐ à-×3Ñ3ØñˆNð
 Ð$Ø )¨%°%¸!±)Ð <× CÑ CÀNÐTUÓ V�Ù˜}Ð5EÐY]Ô^‘à-Ð9ð ðTóÐ9ð "Ð-ð ðJóÐ-ð
 (;×'AÑ'AØ" Aó(Ð$ð -CÀ5È6Á>ÐUZÐ]^ÑU^ÐbhÑThÐ,iÐ)Ø,E×,LÑ,LÈ^Ð]^Ó,_Ð)à(2°5¸EÀA¹IÐ3FÊÐ3IÑ(JÐ%Ø(=×(DÑ(DÀ^ÐUVÓ(WÐ%áØ&:Ø+DØ4Ø+Ø&*ô�ð & f™oÐ-×3Ñ3Ð4LÓMÈaÑPˆMð �L‰LÐ)¨-Ñ8Ö9ðg3	:ðj × Ñ  °T·[±[×5JÑ5J×5WÑ5WÐ ÓXÐXùòW 5cs   Æ&!K&c                 ó  ‡ ‡— t        j                  ‰d d …dd …f   ‰j                  ‰j                  d   d«      j	                  ‰ j
                  j                  j                  «      gd«      Š|�|n‰ j
                  j                  }‰ j
                  j                  xs  ‰ j
                  j                  j                  }|d uxr& ‰d d …df   j                  |«      j                  «       }	ˆ ˆfd„}
t        j                  j                  |d¬«      j                  |j                  d   |z  |d|j!                  d«      «      }t        j                  j                  |d¬«      j#                  d«      j#                  d«      }|d d …d d …d d…d d …f   }|d d …d d …dd…d d …f   }|d d …d d …dd …d d …f   }t        j                  |||z   |gd¬«      }‰j#                  d«      j#                  d«      j%                  d|dd«      Š‰j'                  «       |j'                  «       k(  sJ ‚|j)                  d‰¬«      }|j+                  dd¬	«      } |
||«      \  }}|r|	r|d d …d d …dd …f   j+                  d«      n|j+                  d«      }|j+                  d«      }|j-                  d«      }|j-                  d«      }| }| }|r |j+                  «       }|j+                  «       }||j!                  d«      z  }d
|z
  |z  ||z  z   }|S )Nr   r   c                 ó  •— ‰j                  ‰j                  j                  j                  «      }|j	                  «       r$| j                  |d«       |j                  |d«       | j                  d«      |j                  d«      fS ©Nç        rŒ   ©Úeqr;   rM   rÝ   ÚanyÚmasked_fill_rž   ©ÚllÚ
smooth_objÚpad_maskrs   Útargets      €€r6   Ú
_mask_padsz4RagSequenceForGeneration.get_nll.<locals>._mask_pads  óf   ø€ Ø—y‘y §¡×!6Ñ!6×!CÑ!CÓDˆHØ�|‰|Œ~Ø—‘ ¨#Ô.Ø×'Ñ'¨°#Ô6Ø—:‘:˜b“> :×#5Ñ#5°bÓ#9Ð9Ð9r5   rŒ   r�   rE   ©r‘   rí   T©r‘   Úkeepdimç      ð?)r/   ÚcatÚnewrš   Úfill_r;   rM   rÝ   r~   Úbos_token_idrü   Úallr   Ú
functionalÚlog_softmaxr™   Úsizerœ   rä   r‘   ÚgatherÚsumÚ	logsumexp)rs   Ú
seq_logitsr   r  rÈ   rÌ   rÇ   r~   r  Úuse_bosr  Úseq_logprobsÚdoc_logprobsÚfirst_token_scoresÚsecond_token_scoresÚ	remainderÚrag_logprobsr   r  Únll_lossÚsmooth_lossÚeps_ir   s   `  `                   r6   rÍ   z RagSequenceForGeneration.get_nll  sÖ  ù€ ô —‘Ø’A�q‘r�E‰]˜FŸJ™J v§|¡|°A¡¸Ó:×@Ñ@ÀÇÁ×AVÑAV×AcÑAcÓdÐeÐghó
ˆð "Ð-‘°4·;±;×3EÑ3Eˆð —{‘{×/Ñ/ÒU°4·;±;×3HÑ3H×3UÑ3UˆØ dÐ*ÒR¨v²a¸°d©|¯©¸|Ó/L×/PÑ/PÓ/Rˆõ	:ô —}‘}×0Ñ0°ÀÐ0ÓD×IÑIØ×Ñ˜QÑ 6Ñ)¨6°2°z·±ÀrÓ7Jó
ˆô —}‘}×0Ñ0°ÀÐ0ÓC×MÑMÈbÓQ×[Ñ[Ð\^Ó_ˆð *ª!ªQ°°°²A¨+Ñ6ÐØ*ª1ªa°°1°²a¨<Ñ8ÐØ ¢¢A q¡rª1 Ñ-ˆ	Ü—y‘yÐ"4Ð6IÈLÑ6XÐZcÐ!dÐjkÔlˆð ×!Ñ! !Ó$×.Ñ.¨rÓ2×9Ñ9¸!¸VÀQÈÓJˆØ�z‰z‹|˜|×/Ñ/Ó1Ò1Ð1Ð1à× Ñ  R¨vÐ Ó6ˆØ!×%Ñ%¨"°dÐ%Ó;ˆ
á# B¨
Ó3‰ˆˆJñ %6¹'ˆR’’1�a‘b�‰\×Ñ˜aÔ ÀrÇvÁvÈaÃyˆØ—^‘^ AÓ&ˆ
Ø�\‰\˜!‹_ˆØ×)Ñ)¨!Ó,ˆ
à�3ˆØ!�kˆáØ—|‘|“~ˆHØ%Ÿ/™/Ó+ˆKà˜,×+Ñ+¨BÓ/Ñ/ˆØ�g‘ Ñ)¨E°KÑ,?Ñ?ˆØˆr5   c                 ó  — | d   j                  t        d„ | D «       «      t        d„ | D «       «      «      j                  |«      }d}| D ]<  }|||||j                  d   z   …d |j                  d   …f<   ||j                  d   z  }Œ> |S )Nr   c              3   ó:   K  — | ]  }|j                   d    –— Œ y­w)r   N©rš   ©Ú.0Úts     r6   ú	<genexpr>z8RagSequenceForGeneration._cat_and_pad.<locals>.<genexpr>A  s   è ø€ Ò#@°1 A§G¡G¨A¥JÑ#@ùó   ‚c              3   ó:   K  — | ]  }|j                   d    –— Œ y­w)r   Nr"  r#  s     r6   r&  z8RagSequenceForGeneration._cat_and_pad.<locals>.<genexpr>A  s   è ø€ ÒEbÐUVÀaÇgÁgÈaÅjÑEbùr'  r   )r  r  Úmaxr  rš   )ÚtensorsrÝ   ÚoutputÚindr%  s        r6   rç   z%RagSequenceForGeneration._cat_and_pad?  s“   € à˜‘—‘¤Ñ#@¸Ô#@Ó @Ä#ÑEbÐZaÔEbÓBbÓc×iÑiÐjvÓwˆØˆØò 	ˆAØ;<ˆF�3˜˜qŸw™w q™zÑ)Ð)¨<¨Q¯W©W°Q©Z¨<Ð7Ñ8Ø�1—7‘7˜1‘:Ñ‰Cð	ð ˆr5   r¯   ©NNNNNNNNNNNNNNNNN)	NNNNNNNNN)Frú   FN)r+   r,   r-   r	   r   r   rm   r¿   rÅ   r   r/   r2   r°   r3   r±   r   r0   r²   r³   r   r®   Úpropertyr?   rM   rL   Úno_gradrß   rÍ   Ústaticmethodrç   r´   rµ   s   @r6   r·   r·   ’  s_  ø„ ð +/Ø37Ø,0Ø)-ñà  4Ñ'ðð *¨DÑ0ðð # TÑ)ð	ð
   $Ñ&õð>' |ó 'ð+¸Oó +ð ð .2Ø.2Ø=AØ59Ø:>Ø(,Ø59Ø:>Ø/3Ø!%Ø)-Ø,0Ø(,Ø)-Ø#'Ø*.Ø!ñ%^
à×#Ñ# dÑ*ð^
ð Ÿ™ tÑ+ð^
ð ˜u U§\¡\Ñ2Ñ3°dÑ:ð	^
ð
 !×+Ñ+¨dÑ2ð^
ð !&× 0Ñ 0°4Ñ 7ð^
ð  ™ð^
ð !×+Ñ+¨dÑ2ð^
ð !&× 0Ñ 0°4Ñ 7ð^
ð ×%Ñ%¨Ñ,ð^
ð ˜$‘;ð^
ð   $™;ð^
ð # T™kð^
ð  ™+ð^
ð   $™;ð^
ð  ˜D‘[ð!^
ð" × Ñ  4Ñ'ð#^
ð$ �d‘
ð%^
ð( 
"ò)^
ó ð^
ð@ ñ"ó ð"ð ñ"ó ð"ð ñ)ó ð)ð €U‡]�]ƒ_ð .2Ø26Ø59Ø:>Ø/3Ø(,Ø+/Ø $Ø!ñVYà×#Ñ# dÑ*ðVYð ×(Ñ(¨4Ñ/ðVYð !×+Ñ+¨dÑ2ð	VYð
 !&× 0Ñ 0°4Ñ 7ðVYð ×%Ñ%¨Ñ,ðVYð  ™+ðVYð " D™jðVYð ˜‘:ðVYð �d‘
ðVYð 
×	Ñ	òVYó ðVYðr osó9ðv ñó ôr5   r·   zo
    A RAG-token model implementation. It performs RAG-token specific marginalization in the forward pass.
    c            &       óô  ‡ — e Zd Z	 	 	 	 d.dedz  dedz  dedz  dedz  fˆ fd„Zdefd„Zdefd	„Z	 	 	 	 	 	 d/d
„Z	e
d„ «       Ze
d„ «       Ze
d„ «       Zed„ «       Zd0d„Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d1dej&                  dz  dej(                  dz  deeej,                        dz  dej&                  dz  dej.                  dz  dedz  dej&                  dz  dej&                  dz  dej(                  dz  dedz  dedz  dedz  dedz  dedz  dedz  dej&                  dz  d edz  d!ef$d"„«       Z ej:                  «       dddddddd e«        e«       f
dej&                  dz  dej&                  dz  dej&                  dz  dej&                  dz  dej(                  dz  d edz  d#e dz  d$e!eej,                  ge"e   f   dz  d%edz  d&edz  d!ej&                  fd'„«       Z#d(„ Z$d)„ Z%d*„ Z&d+„ Z'd0d,„Z(d2d-„Z)ˆ xZ*S )3ÚRagTokenForGenerationNr;   rL   rM   r?   c                 óà   •— |€|�|€J d«       ‚|€+t        j                  |j                  |j                  fi |¤Ž}t        ‰| �  |«       t        ||||¬«      | _        | j                  «        yr¹   rº   r»   s         €r6   rm   zRagTokenForGeneration.__init__O  s†   ø€ ð  Ð!Ð&6Ð&BÀyÐG\ð 	
ØVó	
Ð]ð ˆ>Ü×FÑFØ ×'Ñ'¨×)9Ñ)9ñØ=CñˆFô 	‰Ñ˜Ô ô  6Ð<LÐXaÐmvÔwˆŒà�‰Õr5   c                 ó&   — || j                   _        y r’   r½   r¾   s     r6   r¿   z#RagTokenForGeneration.set_retrievero  rÀ   r5   rp   c                 óH   — d| j                   _        || j                   _        y rÂ   rÃ   rÄ   s     r6   rÅ   z6RagTokenForGeneration.set_context_encoder_for_trainingr  rÆ   r5   c           
      ó4   — |�|d d …dd …f   }d ||||||d|dœ	S )NrŒ   T)	ru   rw   r   r!   rx   r   rz   Údo_marginalizer~   r4   )	rs   rx   r   rv   rz   rw   r   r~   rX   s	            r6   Úprepare_inputs_for_generationz3RagTokenForGeneration.prepare_inputs_for_generationv  sB   € ð Ð&à 1²!°R±S°&Ñ 9Ðð Ø.Ø$Ø&4Ø!2Ø.Ø"Ø"Øñ

ð 
	
r5   c                 ó.   — | j                   j                  S r’   r½   rÑ   s    r6   r?   zRagTokenForGeneration.retriever“  rÒ   r5   c                 ó.   — | j                   j                  S r’   rÔ   rÑ   s    r6   rM   zRagTokenForGeneration.generator—  rÒ   r5   c                 ó.   — | j                   j                  S r’   rÖ   rÑ   s    r6   rL   z&RagTokenForGeneration.question_encoder›  r×   r5   c                 óV  ‡‡	— d„ Š	d}t        t        | «      «      D ]û  }t        | t        «      r ˆ	ˆfd„| j                  j
                  |   j                  | j                  j
                  |   j                  | j                  j
                  |   j                  | j                  j
                  |   j                  fD «       \  }}}}||||f}nCˆ	ˆfd„| j
                  |   j                  | j
                  |   j                  fD «       \  }}||f}||fz  }Œý  t        | «      |«      S )zeReorders cache for generation. BART-inspired but we need to take care of the extra dimension for docsc                 óê   — | j                   d   |j                   d   z  } | j                  d|g| j                   dd  ¢­Ž } | j                  d|«      }  | j                  dg| j                   dd  ¢­Ž }|S )Nr   rŒ   r   rE   )rš   r™   Úindex_select)r    Ú	new_orderr~   Úresults       r6   Ú_reorder_stackedz>RagTokenForGeneration._reorder_cache.<locals>._reorder_stacked£  sƒ   € Ø"×(Ñ(¨Ñ+¨y¯©¸qÑ/AÑAˆFØ.˜M×.Ñ.¨r°6ÐT¸M×<OÑ<OÐPQÐPRÐ<SÒTˆMØ)×6Ñ6°q¸)ÓDˆMØ'�]×'Ñ'¨ÐE¨]×-@Ñ-@ÀÀÐ-DÒEˆFØˆMr5   r4   c              3   ób   •K  — | ]&  } ‰|‰j                  |j                  «      «      –— Œ( y ­wr’   ©r”   rƒ   ©r$  ÚxrA  Úbeam_idxs     €€r6   r&  z7RagTokenForGeneration._reorder_cache.<locals>.<genexpr>­  s/   øè ø€ ò \àñ % Q¨¯©°A·H±HÓ(=×>ñ\ùó   ƒ,/c              3   ób   •K  — | ]&  } ‰|‰j                  |j                  «      «      –— Œ( y ­wr’   rC  rD  s     €€r6   r&  z7RagTokenForGeneration._reorder_cache.<locals>.<genexpr>¸  s-   øè ø€ ò 6àñ % Q¨¯©°A·H±HÓ(=×>ñ6ùrG  )
rÞ   rP   rj   r   Úself_attention_cacheÚlayersÚkeysrã   Úcross_attention_cachero   )
r   rF  Úreordered_pastÚidxÚself_attention_kÚself_attention_vÚcross_attention_kÚcross_attention_vÚ	new_tuplerA  s
    `       @r6   Ú_reorder_cachez$RagTokenForGeneration._reorder_cacheŸ  s;  ù€ ò	ð ˆÜœ˜_Ó-Ó.ò 	+ˆCÜ˜/Ô+>Ô?ô\ð (×<Ñ<×CÑCÀCÑH×MÑMØ'×<Ñ<×CÑCÀCÑH×OÑOØ'×=Ñ=×DÑDÀSÑI×NÑNØ'×=Ñ=×DÑDÀSÑI×PÑPð	ô\ÑXÐ Ð"2Ð4EÐGXð .Ð/?ÐARÐTeÐf‘	ô6à-×4Ñ4°SÑ9×>Ñ>À×@VÑ@VÐWZÑ@[×@bÑ@bÐcô6Ñ2Ð Ð"2ð .Ð/?Ð@�	Ø˜y˜lÑ*‰Nð%	+ð& %Œt�OÓ$ ^Ó4Ð4r5   c                 ó|  — |�|n| j                   j                  }t        j                  j	                  |d¬«      j                  |j                  d   |z  |d|j                  d«      «      }t        j                  |d¬«      }||j                  d«      j                  d«      z   }t        j                  |d¬«      S )NrŒ   r�   r   r   )r;   r~   r   r  r  r™   rš   r  r/   rœ   r  )rs   r  r   r~   r  r  Úlog_prob_sums          r6   Úmarginalizez!RagTokenForGeneration.marginalizeÀ  s¥   € Ø!Ð-‘°4·;±;×3EÑ3Eˆô —}‘}×0Ñ0°ÀÐ0ÓD×IÑIØ×Ñ˜QÑ 6Ñ)¨6°2°z·±ÀrÓ7Jó
ˆô ×(Ñ(¨¸Ô;ˆØ# l×&<Ñ&<¸RÓ&@×&JÑ&JÈ2Ó&NÑNˆÜ�‰˜|°Ô3Ð3r5   ru   rv   rw   rx   ry   r   r    r!   r   rz   r{   r|   r}   r7  rÈ   rÉ   r~   r@   c                 ót  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|�|€|}d}
| j	                  ||||||||	||
||||¬«      }d}|j
                  }|�C|€J ‚| j                  |j
                  |j                  ||| j                   j                  |¬«      }|r| j                  ||j                  |«      }t        di d|“d|“d|j                  “d|j                  “d	|j                  “d
|j                  “d|j                  “d|j                  “d|j                   “d|j"                  “d|j$                  “d|j&                  “d|j(                  “d|j*                  “d|j,                  “d|j.                  “d|j0                  “ŽS )aƒ  
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. [`RagConfig`], used to initialize the model, specifies
            which generator to use, it also specifies a compatible generator tokenizer. Use that tokenizer class to
            obtain the indices.

            [What are input IDs?](../glossary#input-ids)
        encoder_outputs (`tuple(tuple(torch.FloatTensor)`, *optional*)
            Tuple consists of (`generator_enc_last_hidden_state`, *optional*: `generator_enc_hidden_states`,
            *optional*: `generator_enc_attentions`). `generator_enc_last_hidden_state` of shape `(batch_size, n_docs *
            sequence_length, hidden_size)` is a sequence of hidden-states at the output of the last layer of the
            generator's encoder.

            Used by the ([`RagModel`]) model during decoding.
        decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Provide for generation tasks. `None` by default, construct as per instructions for the generator model
            you're using with your RAG instance.
        decoder_attention_mask (`torch.BoolTensor` of shape `(batch_size,  target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
            be used by default.
        context_input_ids (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
            Input IDs post-processed from the retrieved documents and the question encoder `input_ids` by the
            retriever. If the model was not initialized with a `retriever` ``context_input_ids` has to be provided to
            the forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
        context_attention_mask (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`,*optional*, returned when *output_retrieved=True*):
            Attention mask post-processed from the retrieved documents and the question encoder `input_ids` by the
            retriever. If the model has is not initialized with a `retriever` `context_attention_mask` has to be
            provided to the forward pass. `context_attention_mask` are returned by [`~RagRetriever.__call__`].
        doc_scores (`torch.FloatTensor` of shape `(batch_size, config.n_docs)`):
            Score between each retrieved document embeddings (see `retrieved_doc_embeds`) and
            `question_encoder_last_hidden_state`. If the model has is not initialized with a `retriever` `doc_scores`
            has to be provided to the forward pass. `doc_scores` can be computed via
            `question_encoder_last_hidden_state` and `retrieved_doc_embeds`, see examples for more information.
        output_retrieved (`bool`, *optional*):
            Whether or not to return the `retrieved_doc_embeds`, `retrieved_doc_ids`, `context_input_ids` and
            `context_attention_mask`. See returned tensors for more detail.
        do_marginalize (`bool`, *optional*):
            If `True`, the logits are marginalized over all documents by making use of
            `torch.nn.functional.log_softmax`.
        reduce_loss (`bool`, *optional*):
            Only relevant if `labels` is passed. If `True`, the NLL loss is reduced using the `torch.Tensor.sum`
            operation.
        n_docs (`int`, *optional*):
            The number of documents to retrieve.

        Example:

        ```python
        >>> from transformers import AutoTokenizer, RagRetriever, RagTokenForGeneration
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/rag-token-nq")
        >>> retriever = RagRetriever.from_pretrained(
        ...     "facebook/rag-token-nq", index_name="exact", use_dummy_dataset=True
        ... )
        >>> # initialize with RagRetriever to do everything in one forward call
        >>> model = RagTokenForGeneration.from_pretrained("facebook/rag-token-nq", retriever=retriever)

        >>> inputs = tokenizer("How many people live in Paris?", return_tensors="pt")
        >>> targets = tokenizer(text_target="In Paris, there are 10 million people.", return_tensors="pt")
        >>> input_ids = inputs["input_ids"]
        >>> labels = targets["input_ids"]
        >>> outputs = model(input_ids=input_ids, labels=labels)

        >>> # or use retriever separately
        >>> model = RagTokenForGeneration.from_pretrained("facebook/rag-token-nq", use_dummy_dataset=True)
        >>> # 1. Encode
        >>> question_hidden_states = model.question_encoder(input_ids)[0]
        >>> # 2. Retrieve
        >>> docs_dict = retriever(input_ids.numpy(), question_hidden_states.detach().numpy(), return_tensors="pt")
        >>> doc_scores = torch.bmm(
        ...     question_hidden_states.unsqueeze(1), docs_dict["retrieved_doc_embeds"].float().transpose(1, 2)
        ... ).squeeze(1)
        >>> # 3. Forward to generator
        >>> outputs = model(
        ...     context_input_ids=docs_dict["context_input_ids"],
        ...     context_attention_mask=docs_dict["context_attention_mask"],
        ...     doc_scores=doc_scores,
        ...     decoder_input_ids=labels,
        ... )

        >>> # or directly generate
        >>> generated = model.generate(
        ...     context_input_ids=docs_dict["context_input_ids"],
        ...     context_attention_mask=docs_dict["context_attention_mask"],
        ...     doc_scores=doc_scores,
        ... )
        >>> generated_string = tokenizer.batch_decode(generated, skip_special_tokens=True)
        ```NFrË   )rÈ   rÌ   r~   r   r   r   r   r    r!   r   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r4   )r;   r~   r7  rÈ   r<   r   rÍ   r   rÎ   rW  r   r   r    r!   r   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   )rs   ru   rv   rw   rx   ry   r   r    r!   r   rz   r{   r|   r}   r7  rÈ   rÉ   r~   rX   rÏ   r   r   s                         r6   r®   zRagTokenForGeneration.forwardË  s"  € ð^ "Ð-‘°4·;±;×3EÑ3EˆØ+9Ð+E™È4Ï;É;×KeÑKeˆØ%0Ð%<‘kÀ$Ç+Á+×BYÑBYˆàÐØ Ð(Ø$*Ð!ØˆIà—(‘(ØØ)Ø+Ø/Ø#9Ø/Ø#9Ø!Ø+ØØ/Ø!5Ø-Øð ó 
ˆð" ˆØ—‘ˆØÐØ$Ð0Ð0Ð0Ø—<‘<Ø—‘Ø×"Ñ"ØØ'ØŸ™×3Ñ3Øð  ó ˆDñ Ø×%Ñ% f¨g×.@Ñ.@À&ÓIˆFä'ò 
Ùð
áð
ð ×)Ò)ð
ð $×3Ò3ð	
ð
 &×7Ò7ð
ð $+×#AÒ#Að
ð ")×!=Ò!=ð
ð &×7Ò7ð
ð 07×/YÒ/Yð
ð (/×'IÒ'Ið
ð %,×$CÒ$Cð
ð -4×,SÒ,Sð
ð )0×(KÒ(Kð
ð &-×%EÒ%Eð
ð )0×(KÒ(Kð
ð  &-×%EÒ%Eð!
ð" (/×'IÒ'Ið#
ð 	
r5   Úgeneration_configÚprefix_allowed_tokens_fnÚlogits_processorÚstopping_criteriac           	      ó  ‡‡— | j                  d|ddd«      } | j                  |fi |¤Ž\  }}|j                  «       }|t        j                  t        j
                  t        j                  t        j                  fvrt        d|› d�«      ‚t        t        | «      t        |   «      }| j                  |j                  «       «       | j                  |||«       |j                  dd«      du}| j!                  ||«       ‰�‰n| j"                  j$                  Š| j&                  ��|�€| j)                  ||¬«      d   }| j'                  ||j+                  «       j-                  dt.        j0                  ¬	«      j3                  «       t        | j4                  j"                  d
d«      ‰d¬«      }|d   |d   |d   }}}|j-                  |«      }|j-                  |«      }|j-                  |«      }t/        j6                  |j9                  d«      |j;                  dd«      «      j=                  d«      }|j>                  d   ‰z  dk(  sJ d‰› d|j>                  d   › d�«       ‚|j>                  d   ‰z  Š| j@                  j4                  jC                  «       } |||d¬«      }t/        jD                  ‰|jF                  z  df|jH                  t.        jJ                  tM        | jO                  «       «      jP                  ¬«      }|j>                  d   }|d   }d%ˆˆfd„	} |||jF                  ¬«      } |||jF                  ¬«      |d<   |jS                  |jF                  d¬«      }||d<   ||d<   ||d<   ‰|d<   |jT                  |d <   | jW                  |||||	|jP                  ¬!«      }| jY                  ||
¬"«      }| j[                  ||d|j>                  d   |j\                  dz
  ¬#«        || |f|||d$œ|¤|¤ŽS )&aÙ  
        Implements RAG token decoding.

        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                The sequence used as a prompt for the generation. If `input_ids` is not passed, then
                `context_input_ids` has to be provided.
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

                - 1 for tokens that are **not masked**,
                - 0 for tokens that are **masked**.

                [What are attention masks?](../glossary#attention-mask)
            context_input_ids (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
                Input IDs post-processed from the retrieved documents and the question encoder `input_ids` by the
                retriever.

                If the model has is not initialized with a `retriever`, `context_input_ids` has to be provided to the
                forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
            context_attention_mask (`torch.LongTensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
                Attention mask post-processed from the retrieved documents and the question encoder `input_ids` by the
                retriever.

                If the model has is not initialized with a `retriever`, `context_input_ids` has to be provided to the
                forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
            doc_scores (`torch.FloatTensor` of shape `(batch_size, config.n_docs)`):
                Score between each retrieved document embeddings (see `retrieved_doc_embeds`) and
                `question_encoder_last_hidden_state`.

                If the model has is not initialized with a `retriever`, `context_input_ids` has to be provided to the
                forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
            n_docs (`int`, *optional*, defaults to `config.n_docs`)
                Number of documents to retrieve and/or number of documents for which to generate an answer.
            generation_config (`~generation.GenerationConfig`, *optional*):
                The generation configuration to be used as base parametrization for the generation call. `**kwargs`
                passed to generate matching the attributes of `generation_config` will override them. If
                `generation_config` is not provided, the default will be used, which has the following loading
                priority: 1) from the `generation_config.json` model file, if it exists; 2) from the model
                configuration. Please note that unspecified parameters will inherit [`~generation.GenerationConfig`]'s
                default values, whose documentation should be checked to parameterize generation.
            prefix_allowed_tokens_fn (`Callable[[int, torch.Tensor], list[int]]`, *optional*):
                If provided, this function constraints the beam search to allowed tokens only at each step. If not
                provided no constraint is applied. This function takes 2 arguments `inputs_ids` and the batch ID
                `batch_id`. It has to return a list with the allowed tokens for the next generation step conditioned on
                the previously generated tokens `inputs_ids` and the batch ID `batch_id`. This argument is useful for
                constrained generation conditioned on the prefix, as described in [Autoregressive Entity
                Retrieval](https://huggingface.co/papers/2010.00904).
            logits_processor (`LogitsProcessorList`, *optional*):
                Custom logits processors that complement the default logits processors built from arguments and a
                model's config. If a logit processor is passed that is already created with the arguments or a model's
                config an error is thrown.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                Custom stopping criteria that complement the default stopping criteria built from arguments and a
                model's config. If a stopping criteria is passed that is already created with the arguments or a
                model's config an error is thrown.
            kwargs (`dict[str, Any]`, *optional*):
                Ad hoc parametrization of `generate_config` and/or additional model-specific kwargs that will be
                forwarded to the `forward` function of the model.

        Return:
            `torch.LongTensor` of shape `(batch_size * num_return_sequences, sequence_length)`: The generated
            sequences. The second dimension (sequence_length) is either equal to `max_length` or shorter if all batches
            finished early due to the `eos_token_id`.
        NFz!RAG model is not compatible with z5 generation. Please check your generation parameters.rv   rÜ   r   r�   r‚   r…   r†   r‡   r    r!   r   r   rE   r�   rŽ   r�   T)ru   rv   r€   )r„   rƒ   rŒ   Úlast_hidden_statec                 óô   •— | d d d d …f   j                  ‰d‰f| j                  dd  z   «      } | j                  ‰|‰f| j                  dd  z   «      } | j                  ‰|z  ‰z  f| j                  dd  z   «      S )Nr   r   )Úreshaperš   Úexpand)ÚtensorrÚ   rì   r~   s     €€r6   Úextend_enc_outputz9RagTokenForGeneration.generate.<locals>.extend_enc_output  sŒ   ø€ à˜D $ª˜MÑ*×2Ñ2°JÀÀ6Ð3JÈVÏ\É\ÐZ[ÐZ\ÐM]Ñ3]Ó^ˆFà—]‘] J°	¸6Ð#BÀVÇ\Á\ÐRSÐRTÐEUÑ#UÓVˆFà—>‘> :°	Ñ#9¸FÑ#BÐ"DÀvÇ|Á|ÐTUÐTVÐGWÑ"WÓXÐXr5   )rÚ   r�   r   rw   r~   rz   )rY  Úinput_ids_seq_lengthÚencoder_input_idsrZ  r[  rƒ   )rY  r\  )Úgeneration_moderì   Úmax_cache_length)r[  r\  rY  r’   )/Ú_extract_generation_mode_kwargsÚ_prepare_generation_configÚget_generation_moder   ÚSAMPLEÚGREEDY_SEARCHÚBEAM_SEARCHÚBEAM_SAMPLEÚ
ValueErrorr—   ro   r   Ú_validate_model_kwargsÚcopyÚ_validate_generation_moderU   Ú_prepare_special_tokensr;   r~   r?   rL   r“   r”   r/   r•   r–   rM   r›   rœ   r�   rž   rš   r<   Úget_encoderÚfullrÚ   Údecoder_start_token_idÚlongÚnextÚ
parametersrƒ   rŸ   rz   Ú_get_logits_processorÚ_get_stopping_criteriaÚ_prepare_cache_for_generationÚ
max_length)rs   ru   rv   r    r!   r   r~   rY  rZ  r[  r\  rX   Úgeneration_mode_kwargsrè   rf  Údecoding_methodÚkwargs_has_attention_maskrê   Úoutr   Úencoderrw   rd  r^  rc  Úprepared_logits_processorÚprepared_stopping_criteriarì   s         `                    @r6   rß   zRagTokenForGeneration.generatex  s�  ù€ ðb "&×!EÑ!EÀdÈFÐTYÐ[_ÐaeÓ!fÐØ*I¨$×*IÑ*IÐJ[Ñ*fÐ_eÑ*fÑ'Ð˜<Ø+×?Ñ?ÓAˆØÜ×!Ñ!Ü×(Ñ(Ü×&Ñ&Ü×&Ñ&ð	#
ñ 
ô Ø3°OÐ3DÐDyÐzóð ô "¤$ t£*Ô.FÀÑ.WÓXˆØ×#Ñ# L×$5Ñ$5Ó$7Ô8Ø×&Ñ& Ð8IÐKaÔbà$0×$4Ñ$4Ð5EÀtÓ$LÐTXÐ$XÐ!Ø×$Ñ$Ð%6Ð8QÔRð "Ð-‘°4·;±;×3EÑ3Eˆð �>‰>Ñ%Ð*;Ñ*CØ%)×%:Ñ%:¸9ÐUcÐ%:Ó%dÐefÑ%gÐ"Ø—.‘.ØØ&×-Ñ-Ó/×2Ñ2¸%ÄuÇ}Á}Ð2ÓU×[Ñ[Ó]Ü˜tŸ~™~×4Ñ4°hÀÓEØØ#ð !ó ˆCð Ð'Ñ(ØÐ,Ñ-ØÐ*Ñ+ð 8LÐ5Ðð $8×#:Ñ#:Ð;QÓ#RÐ Ø 1× 4Ñ 4°YÓ ?ÐØ%;×%>Ñ%>¸yÓ%IÐ"ô Ÿ™Ð#9×#CÑ#CÀAÓ#FÐH\×HfÑHfÐghÐjkÓHlÓm×uÑuØóˆJð "×'Ñ'¨Ñ*¨VÑ3¸Ò9ð 	
Ø[Ð\bÐ[cð dØ!×'Ñ'¨Ñ*Ð+¨1ð.ó	
Ð9ð '×,Ñ,¨QÑ/°6Ñ9ˆ
à—(‘(×$Ñ$×0Ñ0Ó2ˆÙ!Ð,=ÐNdÐrvÔwˆä—J‘JØÐ+×5Ñ5Ñ5°qÐ9Ø×4Ñ4Ü—*‘*Ü˜Ÿ™Ó)Ó*×1Ñ1ô	
ˆ	ð  )Ÿ™¨rÑ2ÐØ+Ð,?Ñ@Ðö	Yñ "3Ð3IÐUf×UpÑUpÔ!qÐÙ/@ØÐ):×)DÑ)Dô0
ˆÐ+Ñ,ð  ×1Ñ1Ð2C×2MÑ2MÐSTÐ1ÓUˆ
ð &0ˆ�\Ñ"Ø*9ˆÐ&Ñ'Ø)?ˆÐ%Ñ&Ø!'ˆ�XÑØ$5×$?Ñ$?ˆ�[Ñ!à$(×$>Ñ$>Ø/Ø!5Ø/Ø%=Ø-Ø×#Ñ#ð %?ó %
Ð!ð &*×%@Ñ%@Ø/ÐCTð &Aó &
Ð"ð 	×*Ñ*ØØØ Ø —‘ qÑ)Ø.×9Ñ9¸AÑ=ð 	+ô 	
ñ ØØð
ð 7Ø8Ø/ñ
ð %ð
ð ñ
ð 	
r5   c                 ó*   — | j                  ||«      }|S r’   )rT  )rs   r   rF  s      r6   Ú_temporary_reorder_cachez.RagTokenForGeneration._temporary_reorder_cacheE  s   € ð ×-Ñ-¨o¸xÓHˆØÐr5   c                 óJ   — | j                   j                  j                  «       S r’   )r<   rM   Úget_input_embeddingsrÑ   s    r6   rˆ  z*RagTokenForGeneration.get_input_embeddingsL  s   € Ø�x‰x×!Ñ!×6Ñ6Ó8Ð8r5   c                 óJ   — | j                   j                  j                  «       S r’   )r<   rM   Úget_output_embeddingsrÑ   s    r6   rŠ  z+RagTokenForGeneration.get_output_embeddingsO  s   € Ø�x‰x×!Ñ!×7Ñ7Ó9Ð9r5   c                 óL   — | j                   j                  j                  |«      S r’   )r<   rM   Úset_output_embeddings)rs   Únew_embeddingss     r6   rŒ  z+RagTokenForGeneration.set_output_embeddingsR  s   € Ø�x‰x×!Ñ!×7Ñ7¸ÓGÐGr5   c                 óÂ   — |€| j                   j                  }|j                  |j                  «      }|dd…dd…f   j	                  «       |dd…dd…f<   ||dd…df<   |S )zCShift input ids one token to the right, and pad with start_token_idNrŒ   r   r   )r;   rv  Ú	new_zerosrš   Úclone)rs   ru   Ústart_token_idÚshifted_input_idss       r6   Úshift_tokens_rightz(RagTokenForGeneration.shift_tokens_rightU  sh   € àÐ!Ø!Ÿ[™[×?Ñ?ˆNØ%×/Ñ/°	·±Ó@ÐØ#,ªQ°°°¨VÑ#4×#:Ñ#:Ó#<Ðš!˜Q™R˜%Ñ Ø"0Ðš!˜Q˜$ÑØ Ð r5   c                 óê  ‡ ‡— |�|n‰ j                   j                  }t        j                  ‰d d …dd …f   ‰j	                  ‰j
                  d   d«      j                  ‰ j                   j                  j                  «      gd«      Šˆ ˆfd„}‰ j                  |||«      }‰j                  d«      Š‰j                  «       |j                  «       k(  sJ ‚|j                  d‰¬«      }	|j                  dd¬«      }
 ||	|
«      \  }	}
|	j                  d«      }	|
j                  d«      }
|	 }|
 }|r |j                  «       }|j                  «       }||j                  d«      z  }d|z
  |z  ||z  z   }|S )	Nr   r   c                 ó  •— ‰j                  ‰j                  j                  j                  «      }|j	                  «       r$| j                  |d«       |j                  |d«       | j                  d«      |j                  d«      fS rù   rû   rÿ   s      €€r6   r  z1RagTokenForGeneration.get_nll.<locals>._mask_padse  r  r5   rŒ   r  Tr  r	  )r;   r~   r/   r
  r  rš   r  rM   rÝ   rW  rœ   r‘   r  r  r  )rs   r  r   r  rÈ   rÌ   r~   r  r  r   r  r  r  r  r   s   `  `           r6   rÍ   zRagTokenForGeneration.get_nll^  sa  ù€ Ø!Ð-‘°4·;±;×3EÑ3Eˆä—‘Ø’A�q‘r�E‰]˜FŸJ™J v§|¡|°A¡¸Ó:×@Ñ@ÀÇÁ×AVÑAV×AcÑAcÓdÐeÐghó
ˆõ	:ð ×'Ñ'¨
°JÀÓGˆà×!Ñ! "Ó%ˆØ�z‰z‹|˜|×/Ñ/Ó1Ò1Ð1Ð1à× Ñ  R¨vÐ Ó6ˆØ!×%Ñ%¨"°dÐ%Ó;ˆ
Ù# B¨
Ó3‰ˆˆJØ�V‰V�A‹YˆØ—^‘^ AÓ&ˆ
à�3ˆØ!�kˆáØ—|‘|“~ˆHØ%Ÿ/™/Ó+ˆKà˜,×+Ñ+¨BÓ/Ñ/ˆØ�g‘ Ñ)¨E°KÑ,?Ñ?ˆØˆr5   r¯   )NNNNNNr’   r-  )Frú   N)+r+   r,   r-   r	   r   r   rm   r¿   rÅ   r8  r.  r?   rM   rL   r0  rT  rW  r   r/   r2   r0   r3   r°   r±   r   r²   r³   r   r®   r/  r   r   r
   r   rá   rß   r†  rˆ  rŠ  rŒ  r“  rÍ   r´   rµ   s   @r6   r2  r2  I  sº  ø„ ð +/Ø37Ø,0Ø)-ñà  4Ñ'ðð *¨DÑ0ðð # TÑ)ð	ð
   $Ñ&õð@' |ó 'ð+¸Oó +ð ØØØØØó
ð: ñ"ó ð"ð ñ"ó ð"ð ñ)ó ð)ð ñ5ó ð5ó@	4ð ð .2Ø37Ø=AØ59Ø:>Ø(,Ø59Ø:>Ø/3Ø!%Ø)-Ø,0Ø(,Ø&*Ø#'Ø*.Ø!ñ%j
à×#Ñ# dÑ*ðj
ð ×)Ñ)¨DÑ0ðj
ð ˜u U§\¡\Ñ2Ñ3°dÑ:ð	j
ð
 !×+Ñ+¨dÑ2ðj
ð !&× 0Ñ 0°4Ñ 7ðj
ð  ™ðj
ð !×+Ñ+¨dÑ2ðj
ð !&× 0Ñ 0°4Ñ 7ðj
ð ×%Ñ%¨Ñ,ðj
ð ˜$‘;ðj
ð   $™;ðj
ð # T™kðj
ð  ™+ðj
ð ˜t™ðj
ð  ˜D‘[ð!j
ð" × Ñ  4Ñ'ð#j
ð$ �d‘
ð%j
ð( 
"ò)j
ó ðj
ðX €U‡]�]ƒ_ð .2Ø26Ø59Ø:>Ø/3Ø!Ø59ØTXÙ7JÓ7LÙ9MÓ9OñI
à×#Ñ# dÑ*ðI
ð ×(Ñ(¨4Ñ/ðI
ð !×+Ñ+¨dÑ2ð	I
ð
 !&× 0Ñ 0°4Ñ 7ðI
ð ×%Ñ%¨Ñ,ðI
ð �d‘
ðI
ð ,¨dÑ2ðI
ð #+¨C°·±Ð+>ÀÀSÁ	Ð+IÑ"JÈTÑ"QðI
ð .°Ñ4ðI
ð 0°$Ñ6ðI
ð 
×	Ñ	òI
ó ðI
òXò9ò:òHó!÷"r5   r2  )rg   r:   r·   r2  ))r.   Úcollections.abcr   Údataclassesr   r/   r   Úcache_utilsr   r   Úconfiguration_utilsr	   Ú
generationr
   r   r   r   r   Úgeneration.utilsr   Úmodeling_outputsr   Úmodeling_utilsr   Úutilsr   r   Úconfiguration_ragr   Úretrieval_ragr   Ú
get_loggerr+   Úloggerr   r8   r:   rg   r·   r2  Ú__all__r4   r5   r6   ú<module>r¤     s\  ðñ  å $Ý !ã Ý ç 5Ý 3ß vÕ vÝ 8Ý +Ý -ß ,Ý (Ý 'ð 
ˆ×	Ñ	˜HÓ	%€ñ ðôð
 ôWL˜{ó WLó óðWLðt Ø
ôTL˜ó TLó ó ðTLñn ðôð ôIo˜ó Ioó óðIoðX ô[
Ð!ó [
ó ð[
ñ| ðôô
oÐ1ó oóð
oñd ðôô
rÐ.°ó róð
ròj b�r5   