+
    œ°³jûY ã                   óþ  € R t ^ RIHt ^ RIHt ^ RIt^ RIHt ^RIHtH	t	 ^RI
Ht ^RIHtHtHtHtHt ^RIHt ^R	IHt ^R
IHt ^RIHtHt ^RIHt ^RIHt ]P>                  ! ] 4      t!]! RR7      ] ! R R]4      4       4       t"]] ! R R]4      4       4       t#]! RR7      ] ! R R]4      4       4       t$] ! R R]$4      4       t%]! RR7       ! R R]$4      4       t&]! RR7       ! R R]$]4      4       t'. ROt(R# ) 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                   ót   a € ] tR t^$t o RtRtRtRtRtRt	Rt
RtRtRtRtRtRtRtRtRtRtRtV 3R ltRtV tR# )Ú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.
Nc                ó   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R	&   S[ P                  R,          ;R
&   S[S[ P                  R3,          R,          ;R&   S[S[ P                  R3,          R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  R3,          R,          ;R&   S[S[ P                  R3,          R,          ;R&   S[S[ P                  R3,          R,          ;R&   S[S[ P                  R3,          R,          ;R&   S[S[ P                  R3,          R,          ;R&   # )é   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©ÚtorchÚFloatTensorr   Ú
LongTensorÚtuple)ÚformatÚ__classdict__s   "€Úe/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/rag/modeling_rag.pyÚ__annotate__Ú%RetrievAugLMMarginOutput.__annotate__$   sþ  ø‡ ‚ ñZ ×
Ñ
˜dÕ
"Ñ)ñ[ ñ\ ×Ñ Õ$Ñ+ñ] ñ^ ×!Ñ! DÕ(Ñ/ñ_ ñ` ˜T•\Ñ(ña ñb  ×+Ñ+¨dÕ2Ñ9ñc ñd ×'Ñ'¨$Õ.Ñ5ñe ñf ×'Ñ'¨$Õ.Ñ5ñg ñh "×,Ñ,¨tÕ3Ñ:ñi ñj ).×(9Ñ(9¸DÕ(@ÑGñk ñl !&¡e×&7Ñ&7¸Ð&<Õ =ÀÕ DÑKñm ñn #¡5×#4Ñ#4°cÐ#9Õ:¸TÕAÑHño ñp &+×%6Ñ%6¸Õ%=ÑDñq ñr "'¡u×'8Ñ'8¸#Ð'=Õ!>ÀÕ!EÑLñs ñt $¡E×$5Ñ$5°sÐ$:Õ;¸dÕBÑIñu ñv "'¡u×'8Ñ'8¸#Ð'=Õ!>ÀÕ!EÑLñw ñx $¡E×$5Ñ$5°sÐ$:Õ;¸dÕBÑIñy ñz !&¡e×&7Ñ&7¸Ð&<Õ =ÀÕ DÑKò{ ó    © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r3   s   @r4   r   r   $   sx   ø‡ € ñDðL &*€DØ'+€FØ+/€JØ$(€OØ59ÐØ15ÐØ15ÐØ6:ÐØCGÐ&ØGKÐØDHÐØ@DÐ#ØHLÐØEIÐØHLÐØEIÐØGKÐ÷{ ƒ r7   r   c                   óp   a € ] tR t^„t o RtRtRtRtRtRt	Rt
RtRtRtRtRtRtRtRtRtRtV 3R ltRtV tR# )Ú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.
Nc                ór  <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R	&   S[S[ P                  R
3,          R,          ;R&   S[S[ P                  R
3,          R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  R
3,          R,          ;R&   S[S[ P                  R
3,          R,          ;R&   S[S[ P                  R
3,          R,          ;R&   S[S[ P                  R
3,          R,          ;R&   S[S[ P                  R
3,          R,          ;R&   # )r   Nr   r   r   r    r!   r"   r#   r$   .r%   r&   r'   r(   r)   r*   r+   r,   r-   )r2   r3   s   "€r4   r5   ÚRetrievAugLMOutput.__annotate__„   sä  ø‡ ‚ ñN ×Ñ Õ$Ñ+ñO ñP ×!Ñ! DÕ(Ñ/ñQ ñR ˜T•\Ñ(ñS ñT  ×+Ñ+¨dÕ2Ñ9ñU ñV ×'Ñ'¨$Õ.Ñ5ñW ñX ×'Ñ'¨$Õ.Ñ5ñY ñZ "×,Ñ,¨tÕ3Ñ:ñ[ ñ\ ).×(9Ñ(9¸DÕ(@ÑGñ] ñ^ !&¡e×&7Ñ&7¸Ð&<Õ =ÀÕ DÑKñ_ ñ` #¡5×#4Ñ#4°cÐ#9Õ:¸TÕAÑHña ñb &+×%6Ñ%6¸Õ%=ÑDñc ñd "'¡u×'8Ñ'8¸#Ð'=Õ!>ÀÕ!EÑLñe ñf $¡E×$5Ñ$5°sÐ$:Õ;¸dÕBÑIñg ñh "'¡u×'8Ñ'8¸#Ð'=Õ!>ÀÕ!EÑLñi ñj $¡E×$5Ñ$5°sÐ$:Õ;¸dÕBÑIñk ñl !&¡e×&7Ñ&7¸Ð&<Õ =ÀÕ DÑKòm r7   r8   )r9   r:   r;   r<   r=   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r>   r?   r@   rA   s   @r4   rC   rC   „   ss   ø‡ € ñBðH (,€FØ+/€JØ$(€OØ59ÐØ15ÐØ15ÐØ6:ÐØCGÐ&ØGKÐØDHÐØ@DÐ#ØHLÐØEIÐØHLÐØEIÐØGKÐ÷m ƒ r7   rC   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                   óX   a € ] tR t^Ýt o RtRtRt]RV 3R lR ll4       tV 3R lt	Rt
V tR# )	ÚRagPreTrainedModelÚragTNc                ó\   <€ V ^8„  d   QhRS[ R,          RS[ R,          RS[R,          RS[/# )r   Ú.question_encoder_pretrained_model_name_or_pathNÚ'generator_pretrained_model_name_or_pathÚ	retrieverÚreturn)Ústrr   r   )r2   r3   s   "€r4   r5   ÚRagPreTrainedModel.__annotate__î   sL   ø€ ÷ Boñ Boá8;¸d½
ðBoñ 25°tµðBoñ   $Õ&ð	Boñ 
ñBor7   c                ó¶  € VP                  4        UUu/ uF-  w  rVVP                  R4      '       g   K  V\        R4      R VbK/  	  pppVP                  4        UUu/ uF-  w  rVVP                  R4      '       g   K  V\        R4      R VbK/  	  pppV F  p	VRV	,            K  	  V F  p	VRV	,            K  	  VP                  RR4      p
V
fO   Vf   Q R4       h^RIHp RV9  d$   ^RIHp VP                  ! V3/ VBR	R
/B w  r×W×R&   VP                  ! V3/ VB p
VP                  RR4      pVfQ   Vf   Q R4       h^RIH	p RV9  d&   ^RIHp VP                  ! V3/ VBR	R
/B w  ppVVR&   VP                  ! V3/ VB pVP                  R4      pVf-   \        P                  ! V
P                  VP                  3/ VB pV ! W®VVR7      # u uppi u uppi )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©Ú	AutoModelÚconfig)Ú
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Ú	generatorrV   rL   )ÚitemsÚ
startswithÚlenÚpopÚauto.modeling_autorU   Úauto.configuration_autorW   Úfrom_pretrainedrZ   Úgetr   Ú'from_question_encoder_generator_configsrV   )ÚclsrJ   rK   rL   ÚkwargsÚargumentÚvalueÚkwargs_question_encoderÚkwargs_generatorÚkeyr[   rU   rW   Úquestion_encoder_configr\   rZ   Úgenerator_configrV   s   &&&&,             r4   Ú*from_pretrained_question_encoder_generatorÚ=RagPreTrainedModel.from_pretrained_question_encoder_generatorí   sX  € ð| $*§<¡<¤>ô#
á#1‘�Ø×"Ñ"Ð#6×7ô 8ˆH”SÐ,Ó-Ð/Ð0°%Ò7Ù#1ð 	 ñ #
ð $*§<¡<¤>ô
á#1‘�Ø×"Ñ" <×0ô 1ˆH”S˜Ó&Ð(Ð)¨5Ò0Ù#1ð 	ñ 
ó +ˆCØÐ*¨SÕ0Ò1ñ +ã#ˆCØ�| cÕ)Ò*ñ $ð 3×6Ñ6°wÀÓEÐØÒ#ØAÒMð ðóÐMõ 7àÐ6Ô6Ý@àCM×C]ÒC]ØBñDà-ñDð *.òDÑ@Ð'ð
 5L¨Ñ1à(×8Ò8Ø>ñ ØBYñ Ðð %×(Ñ(¨°$Ó7ˆ	ØÒØ:ÒFð ð!óÐFõ CàÐ/Ô/Ý@à5?×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   ”G´GÁGÁ=Gc                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r   rV   r   )r2   r3   s   "€r4   r5   rO   Ý   s   ø‡ ‚ ñ Ñò r7   r8   )NNN)r9   r:   r;   r<   Úbase_model_prefixÚ_supports_flash_attnÚ_supports_sdpaÚclassmethodro   r>   r?   r@   rA   s   @r4   rG   rG   Ý   s<   ø‡ € ð ÐØÐØ€Nà÷Boñ Boó ðBo÷# ƒ r7   rG   c                   ób   a a€ ] tR tRt oRV3R lV 3R lllt]RV3R lR ll4       tRtVtV ;t	# )	ÚRagModelis  c          	      ój   <€ V ^8„  d   QhRS[ R,          RS[R,          RS[R,          RS[R,          /# ©r   rV   Nr[   r\   rL   ©r   r   r   )r2   r3   s   "€r4   r5   ÚRagModel.__annotate__u  sG   ø€ ÷ 2ñ 2á  4Õ'ð2ñ *¨DÕ0ð2ñ # TÕ)ð	2ñ
   $Õ&ñ2r7   c                ó–  <€ Vf   Ve   Vf   Q R4       hVf.   \         P                  ! VP                  VP                  3/ VB pM2\        WP                  4      '       g   Q RV RV P                   24       h\
        SV `  V4       Vf"   ^RIHp VP                  VP                  4      pVf"   ^RIHp VP                  VP                  4      pW@n        V P                  e;   \        V\        4      '       g   Q R\        V P                  4       R24       hW@n        W n
        W0n        RV n        R	V n        V P%                  4        R# )
á‘  
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 rT   rY   z`self.retriever` is of type z&, but should be of type `RagRetriever`F)r   re   rV   Ú
isinstanceÚconfig_classÚsuperÚ__init__ra   rU   Úfrom_configr[   rZ   r\   rL   r   ÚtypeÚctx_encoderÚcontext_encoder_trainingÚ	post_init)	ÚselfrV   r[   r\   rL   rg   rU   rZ   Ú	__class__s	   &&&&&,  €r4   r�   ÚRagModel.__init__u  sB  ø€ ð  Ò!Ð&6Ò&BÀyÒG\ð 	
Ø_ó	
Ð]ð Š>Ü×FÒFØ ×'Ñ'¨×)9Ñ)9ñØ=Cñ‰Fô ˜f×&7Ñ&7×8Ò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Ò6ð Ø.¬t°D·N±NÓ/CÐ.DÐDjÐkóÐ6ð 'ŒNà 0ÔØ"ŒàˆÔØ(-ˆÔ%à�‰Ör7   c                ó,  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[S[S[ P                  ,          ,          R,          RS[ P                  R,          RS[ P
                  R,          RS[R,          RS[ P                  R,          R	S[ P                  R,          R
S[ P                  R,          RS[R,          RS[R,          RS[R,          RS[R,          RS[R,          RS[S[ P                  ,          S[	,          /# )r   Ú	input_idsNÚattention_maskÚencoder_outputsÚdecoder_input_idsÚdecoder_attention_maskr   r   r"   r#   Ú	use_cacheÚoutput_attentionsÚoutput_hidden_statesÚoutput_retrievedÚn_docsrM   )
r.   r0   ÚTensorr1   r/   Ú
BoolTensorr   ÚboolÚintrC   )r2   r3   s   "€r4   r5   r{   ª  s9  ø€ ÷ e
ñ 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
r7   c                ó4	  € Ve   TMV P                   P                  pV
e   T
MV P                   P                  p
Ve   TMV P                   P                  pVe   TMV P                   P                  pVe   TMV P                   P
                  pV P                  RJ;'       d)    VRJ ;'       g    V	RJ ;'       g    VRJ ;'       d    VRJ pVEfn   V'       EdD   V P                  WRR7      pV^ ,          pV P                  VVP                  4       P                  R\        P                  R7      P                  4       \        V P                  P                   RR4      VRR7      pV P                  '       Ed   VR	,          VR
,          VR,          VR,          VR,          VR,          3w  pp	ppppVP                  V4      pV	P                  V4      p	VP                  V4      pVP                  V4      pV P!                  VVRR7      P"                  pVP%                  R%VVP&                  ^,          4      p\        P(                  ! VP+                  ^4      VP-                  ^^4      4      P/                  ^4      pMÀVR	,          VR
,          VR,          VR,          3w  r‰ppVP                  V4      pVP                  V4      pV	P                  V4      p	\        P(                  ! VP+                  ^4      VP-                  ^^4      4      P/                  ^4      pM!Vf   Q R4       hV	f   Q R4       hVf   Q R4       hVf   Q R4       hVP&                  ^,          V,          ^ 8X  g    Q RV RVP&                  ^ ,           R24       hVe   VP1                  V^ R7      pVe   VP1                  V^ R7      pV P                  VV	VVVVV
VRR7	      pV'       g   RpRpRpRpRpMXP2                  pVP4                  pV'       d	   V'       g	   R&pRp	RpRp\7        R'/ RVP8                  bRVbRVP:                  bR	VbR
V	bRXbRXbRXbRVbRVbRVP<                  bR VP>                  bR!VP@                  bR"VPB                  bR#VPD                  bR$VPF                  b # )(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.
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)rŒ   Úreturn_dictÚcpu©ÚdeviceÚdtypeÚprefixÚpt©rŸ   r”   Úreturn_tensorsr"   r#   r    Útokenized_doc_idsÚtokenized_doc_attention_maskÚdoc_idsz˜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)	r‹   rŒ   r�   rŽ   r�   r   r�   r‘   rš   r   r   r   r!   r$   r%   r&   r'   r(   r)   r*   r+   r,   éÿÿÿÿ©Nr8   )$rV   r”   r�   r‘   r’   r“   rL   r[   ÚdetachÚtor.   Úfloat32ÚnumpyÚgetattrr\   r…   r„   Úpooler_outputÚviewÚshapeÚbmmÚ	unsqueezeÚ	transposeÚsqueezeÚrepeat_interleaveÚhidden_statesÚ
attentionsrC   r   r   Úencoder_last_hidden_stateÚencoder_hidden_statesÚencoder_attentionsÚdecoder_hidden_statesÚdecoder_attentionsÚcross_attentions)r‡   r‹   rŒ   r�   rŽ   r�   r   r   r"   r#   r�   r‘   r’   r“   r”   rg   Úhas_to_retrieveÚquestion_enc_outputsr$   Úretriever_outputsr    Úretrieved_doc_input_idsÚretrieved_doc_attention_maskr!   Úgen_outputsr%   r&   s   &&&&&&&&&&&&&&&,           r4   ÚforwardÚ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ÐbÐ.DÈÐ.L×bÐbÐPZÐ^bÐPb÷(ð (à 4Ð'ð 	ð Ó"ßˆØ'+×'<Ñ'<ØÈ$ð (=ó (Ð$ð 6JÈ!Õ5LÐ2à$(§N¡NØØ6×=Ñ=Ó?×BÑBÈ%ÔW\×WdÑWdÐBÓe×kÑkÓmÜ" 4§>¡>×#8Ñ#8¸(ÀDÓIØ!Ø#'ð %3ó %Ð!ð ×0×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ð!
ð 	
r7   )r…   r„   r\   r[   rL   ©NNNN)NNNNNNNNNNNNNN)
r9   r:   r;   r<   r�   r   rÈ   r?   r@   Ú__classcell__©rˆ   r3   s   @@r4   rw   rw   s  s2   ù‡ € ÷2õ 2ðh ÷e
ñ e
ó ÷e
ð e
r7   rw   zu
    A RAG-sequence model implementation. It performs RAG-sequence specific marginalization in the forward pass.
    c                   ó  a a€ ] tR tRt oRV3R lV 3R llltV3R lR ltV3R lR lt]RV3R lR	 ll4       t]	R
 4       t
]	R 4       t]	R 4       t]P                  ! 4       RV3R lR ll4       tRR lt]R 4       tRtVtV ;t# )ÚRagSequenceForGenerationi’  c          	      ój   <€ V ^8„  d   QhRS[ R,          RS[R,          RS[R,          RS[R,          /# ry   rz   )r2   r3   s   "€r4   r5   Ú%RagSequenceForGeneration.__annotate__˜  sG   ø€ ÷ ñ á  4Õ'ðñ *¨DÕ0ðñ # TÕ)ð	ñ
   $Õ&ñr7   c                óð   <€ Vf   Ve   Vf   Q R4       hVf-   \         P                  ! VP                  VP                  3/ VB p\        SV `  V4       \        WW4R7      V n        V P                  4        R# ©r}   NzHEither a configuration or an encoder and a generator has to be provided.)rV   r[   r\   rL   ©r   re   rV   r€   r�   rw   rH   r†   ©r‡   rV   r[   r\   rL   rg   rˆ   s   &&&&&,€r4   r�   Ú!RagSequenceForGeneration.__init__˜  s€   ø€ ð  Ò!Ð&6Ò&BÀyÒG\ð 	
ØVó	
Ð]ð Š>Ü×FÒFØ ×'Ñ'¨×)9Ñ)9ñØ=CñˆFô 	‰Ñ˜Ô ô  6ÐXaÔwˆŒà�‰Ör7   c                ó    <€ V ^8„  d   QhRS[ /# ©r   rL   r   )r2   r3   s   "€r4   r5   rÐ   ·  ó   ø€ ÷ 'ñ '¡|ñ 'r7   c                ó&   € WP                   n        R # r¬   ©rH   rL   ©r‡   rL   s   &&r4   Úset_retrieverÚ&RagSequenceForGeneration.set_retriever·  ó   € Ø&�‰Ör7   c                ó    <€ V ^8„  d   QhRS[ /# ©r   r„   r   )r2   r3   s   "€r4   r5   rÐ   º  ó   ø€ ÷ +ñ +¹Oñ +r7   c                óH   € R V P                   n        WP                   n        R# ©TN©rH   r…   r„   ©r‡   r„   s   &&r4   Ú set_context_encoder_for_trainingÚ9RagSequenceForGeneration.set_context_encoder_for_trainingº  ó   € Ø,0ˆ�‰Ô)Ø*�‰Ör7   c          $      óH  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[S[S[ P                  ,          ,          R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[ P                  R,          R	S[ P                  R,          R
S[ P                  R,          RS[R,          RS[R,          RS[R,          RS[R,          RS[R,          RS[R,          RS[ P                  R,          RS[R,          RS[	/# )r   r‹   NrŒ   r�   rŽ   r�   r   r"   r#   r   r�   r‘   r’   r“   Úexclude_bos_scoreÚreduce_lossÚlabelsr”   rM   )
r.   r0   r•   r1   r–   r   r/   r—   r˜   r   )r2   r3   s   "€r4   r5   rÐ   ¿  s\  ø€ ÷ ^
ñ ^
á×#Ñ# dÕ*ð^
ñ Ÿ™ tÕ+ð^
ñ ™u¡U§\¡\Õ2Õ3°dÕ:ð	^
ñ
 !×+Ñ+¨dÕ2ð^
ñ !&× 0Ñ 0°4Õ 7ð^
ñ  �ð^
ñ !×+Ñ+¨dÕ2ð^
ñ !&× 0Ñ 0°4Õ 7ð^
ñ ×%Ñ%¨Õ,ð^
ñ ˜$•;ð^
ñ   $�;ð^
ñ # T�kð^
ñ  �+ð^
ñ   $�;ð^
ñ  ˜D•[ð!^
ñ" × Ñ  4Õ'ð#^
ñ$ �d•
ð%^
ñ( 
"ñ)^
r7   c                óD  € Ve   TMV P                   P                  pVe   TMV P                   P                  pVe   TMV P                   P                  pVe	   Vf   TpRp
V P	                  VVVVVVVV	VV
VVVVR7      pRpVeA   V P                  VP                  VP                  VVV P                   P                  VVR7      p\        R/ RVbRVP                  bRVP                  bRVP                  bR	VP                  bR
VP                  bRVP                  bRVP                  bRVP                  bRVP                   bRVP"                  bRVP$                  bRVP&                  bRVP(                  bRVP*                  bRVP,                  bRVP.                  b # )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.
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©r‹   rŒ   r�   rŽ   r�   r"   r#   r   r   r�   r‘   r’   r“   r”   )rë   Úepsilonrê   r”   r   r   r   r   r"   r#   r    r!   r$   r%   r&   r'   r(   r)   r*   r+   r,   r8   )rV   r”   rê   rë   rH   Úget_nllr   r   Úlabel_smoothingr   r   r"   r#   r    r!   r$   r%   r&   r'   r(   r)   r*   r+   r,   )r‡   r‹   rŒ   r�   rŽ   r�   r   r"   r#   r   r�   r‘   r’   r“   rê   rë   rì   r”   rg   Úoutputsr   s   &&&&&&&&&&&&&&&&&&,  r4   rÈ   Ú 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ð#
ð 	
r7   c                ó.   € V P                   P                  # r¬   rÚ   ©r‡   s   &r4   rL   Ú"RagSequenceForGeneration.retriever_  ó   € à�x‰x×!Ñ!Ð!r7   c                ó.   € V P                   P                  # r¬   ©rH   r\   rõ   s   &r4   r\   Ú"RagSequenceForGeneration.generatorc  r÷   r7   c                ó.   € V P                   P                  # r¬   ©rH   r[   rõ   s   &r4   r[   Ú)RagSequenceForGeneration.question_encoderg  ó   € à�x‰x×(Ñ(Ð(r7   c                óL  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          R	S[R,          R
S[R,          RS[ P                  /
# )r   r‹   NrŒ   r"   r#   r   Údo_deduplicationÚnum_return_sequencesÚ	num_beamsr”   rM   )r.   r0   r/   r—   r˜   )r2   r3   s   "€r4   r5   rÐ   l  sÔ   ø€ ÷ VYñ 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r7   c
                ó˜  € V	e   T	MV P                   P                  p	Ve   TMV P                   P                  pVe   TM\        V P                   R^4      pVe   TM\        V P                   R^4      pVf   Vf   Q R4       hV P                  e¦   Vf¢   V P                  WR7      ^ ,          pV P	                  VVP                  4       P                  R\        P                  R7      P                  4       \        V P                  P                   RR4      V	R	R
7      R,          pVP                  V4      p. pWŠR&   WŠR&   RV
R&   Ve   VP                  ^ ,          MVP                  ^ ,          V	,          p\        V4       EF’  pW?V	,          V^,           V	,           pV P                  P                  ! V3/ V
B pV'       dV   \        P                  ! \!        V Uu/ uF  p\#        VP%                  4       4      VbK  	  upP'                  4       4      4      pVP                  ^ ,          pVe(   WV^,            P)                  V^4      pV ! VVRR7      pM…Vf   Q R4       hVf   Q R4       hVP)                  V^4      pWOV	,          V^,           V	,           pVP)                  V^4      pW_V^,           1R3,          pVP)                  V^4      pV ! VVVVRR7      pVR,          ) P+                  V4      ^,          pVP-                  VV,          4       EK•  	  V P/                  WÐP                   P                  P0                  R7      # u upi )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  z= At least one of input_ids or context_input_ids must be given©rŒ   r›   rœ   rŸ   r    r¡   r"   rŒ   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.ºNNN)r"   r#   r   rì   rê   r   )Úpad_token_id)rV   r”   r   r±   rL   r[   r­   r®   r.   r¯   r°   r\   r´   ÚrangeÚgenerateÚstackÚlistrN   ÚtolistÚvaluesÚrepeatÚtopkÚappendÚ_cat_and_padr  )r‡   r‹   rŒ   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   &&&&&&&&&&,               r4   r  Ú!RagSequenceForGeneration.generatek  sw  € ðB "Ò-‘°4·;±;×3EÑ3EˆØ/?Ò/KÑ+ÐQU×Q\ÑQ\×QmÑQmÐð $Ò/ñ !ä˜Ÿ™Ð&<¸aÓ@ð 	!ð
 "+Ò!6‘I¼GÀDÇKÁKÐQ\Ð^_Ó<`ˆ	àÒ$Ð(9Ò(Eð 	
ØKó	
ÐEð �>‰>Ò%Ð*;Ò*CØ%)×%:Ñ%:¸9Ð%:Ó%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ˆ
ä˜:×&ˆEà"3¸FµNÀeÈaÅiÐSYÕEYÐ"ZÐà#Ÿ~™~×6Ò6Ø#ñ àñ Ð÷  ä#(§;¢;¬tÑQaÓ4bÑQaÈA´S¸¿¹»³_ÀaÒ5GÑQaÑ4b×4iÑ4iÓ4kÓ/lÓ#mÐ à-×3Ñ3ØõˆNð
 Ò$Ø )°%¸!µ)Ð <× CÑ CÀNÐTUÓ V�Ù˜}Ð5EÐY]Ô^‘à-Ò9ð ðTóÐ9ð "Ò-ð ðJóÐ-ð
 (;×'AÑ'AØ" Aó(Ð$ð -CÈ6Å>ÐUZÐ]^ÕU^ÐbhÕThÐ,iÐ)Ø,E×,LÑ,LÈ^Ð]^Ó,_Ð)à(2¸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 'ðj × Ñ  ·[±[×5JÑ5J×5WÑ5WÐ ÓXÐXùòW 5cs   Ç#Mc                óh  a a€ \         P                  ! SR,          SP                  SP                  ^ ,          ^4      P	                  S P
                  P                  P                  4      .^4      oVe   TMS P
                  P                  pS P
                  P                  ;'       g!    S P
                  P                  P                  pVRJ;'       d'    SR	,          P                  V4      P                  4       p	V V3R lp
\        P                  P                  VR
R7      P                  VP                  ^ ,          V,          VR
VP!                  R
4      4      p\        P                  P                  V^R7      P#                  R
4      P#                  R
4      pVR,          pVR,          pVR,          p\         P                  ! WÞV,           V.^R7      pSP#                  ^4      P#                  R
4      P%                  ^V^^4      oSP'                  4       VP'                  4       8X  g   Q hVP)                  R
SR7      pVP+                  R
RR7      pV
! VV4      w  ppV'       d!   V	'       d   VR,          P+                  ^4      MVP+                  ^4      pVP+                  ^4      pVP-                  ^4      pVP-                  ^4      pV) pV) pV'       d!   VP+                  4       pVP+                  4       pVVP!                  R
4      ,          pRV,
          V,          VV,          ,           pV# )r  Nc                 ó  <€ SP                  SP                  P                  P                  4      pVP	                  4       '       d%   V P                  VR 4       VP                  VR 4       V P                  R4      VP                  R4      3# ©ç        r«   ©ÚeqrV   r\   r  ÚanyÚmasked_fill_r¸   ©ÚllÚ
smooth_objÚpad_maskr‡   Útargets   && €€r4   Ú
_mask_padsÚ4RagSequenceForGeneration.get_nll.<locals>._mask_pads  óh   ø€ Ø—y‘y §¡×!6Ñ!6×!CÑ!CÓDˆHØ�|‰|�~Š~Ø—‘ ¨#Ô.Ø×'Ñ'¨°#Ô6Ø—:‘:˜b“> :×#5Ñ#5°bÓ#9Ð9Ð9r7   r©   ©rª   r  T©rª   Úkeepdimç      ð?©r  ºé   NN©r  é    r«   )r  r  :Nr7  Nr  )r  r  :r7  r   Nr  )r  r  ºr   NNr  )r  r  r6  )r.   ÚcatÚnewr´   Úfill_rV   r\   r  r”   Úbos_token_idr&  Úallr   Ú
functionalÚlog_softmaxr³   Úsizer¶   r  rª   ÚgatherÚsumÚ	logsumexp)r‡   Ú
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   f&&f&&&&               r4   rð   Ú RagSequenceForGeneration.get_nll  s¥  ù€ ô —’Ø�E�]˜FŸJ™J v§|¡|°A¥¸Ó:×@Ñ@ÀÇÁ×AVÑAV×AcÑAcÓdÐeÐghó
ˆð "Ò-‘°4·;±;×3EÑ3Eˆð —{‘{×/Ñ/×UÐU°4·;±;×3HÑ3H×3UÑ3UˆØ dÐ*×RÐR¨v°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×[Ñ[Ð\^Ó_ˆð *¨+Õ6ÐØ*¨<Õ8ÐØ  Õ-ˆ	Ü—y’yÐ"4È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��\×Ñ˜aÔ ÀrÇvÁvÈaÃyˆØ—^‘^ AÓ&ˆ
Ø�\‰\˜!‹_ˆØ×)Ñ)¨!Ó,ˆ
à�3ˆØ!�kˆçØ—|‘|“~ˆHØ%Ÿ/™/Ó+ˆKà˜,×+Ñ+¨BÓ/Õ/ˆØ�g• Õ)¨E°KÕ,?Õ?ˆØˆr7   c                óB  € V ^ ,          P                  \        R V  4       4      \        R V  4       4      4      P                  V4      p^ pV  FN  pWBW3VP                  ^ ,          ,           1RVP                  ^,          13&   W4P                  ^ ,          ,          pKP  	  V# )r9  c              3   óF   "  € T F  qP                   ^ ,          x € K  	  R# 5i)r9  N©r´   ©Ú.0Úts   & r4   Ú	<genexpr>Ú8RagSequenceForGeneration._cat_and_pad.<locals>.<genexpr>A  s   é € Ð#@¹°1§G¡G¨A§J¢J»ùó   ‚!c              3   óF   "  € T F  qP                   ^,          x € K  	  R# 5i)r7  NrT  rU  s   & r4   rX  rY  A  s   é € ÐEbÑZaÐUVÇgÁgÈaÇjÂjÓZaùrZ  N)r<  rD  Úmaxr=  r´   )Útensorsr  ÚoutputÚindrW  s   &&   r4   r  Ú%RagSequenceForGeneration._cat_and_pad?  sˆ   € à˜•—‘¤Ñ#@¹Ó#@Ó @Ä#ÑEbÑZaÓEbÓBbÓc×iÑiÐjvÓwˆØˆÛˆAØ;<�3˜qŸw™w q�zÕ)Ð)¨<¨Q¯W©W°Q­Z¨<Ð7Ñ8Ø—7‘7˜1•:ÕŠCñ ð ˆr7   ©rH   rÊ   ©NNNNNNNNNNNNNNNNN)	NNNNNNNNN)Fr$  FN)r9   r:   r;   r<   r�   rÜ   ræ   r   rÈ   ÚpropertyrL   r\   r[   r.   Úno_gradr  rð   Ústaticmethodr  r?   r@   rË   rÌ   s   @@r4   rÎ   rÎ   ’  sÁ   ù‡ € ÷õ ÷>'ð '÷+ð +ð ÷^
ñ ^
ó ð^
ð@ ñ"ó ð"ð ñ"ó ð"ð ñ)ó ð)ð ‡]‚]ƒ_÷VYñ VYó ðVYôp9ðv ñó ÷ð r7   rÎ   zo
    A RAG-token model implementation. It performs RAG-token specific marginalization in the forward pass.
    c                   ól  a a€ ] tR tRt oRV3R lV 3R llltV3R lR ltV3R lR ltRR	 lt]R
 4       t	]R 4       t
]R 4       t]R 4       tRR lt]RV3R lR ll4       t]P$                  ! 4       RRRRRRRR]! 4       ]! 4       3
V3R lR ll4       tR tR tR tR tRR ltRR ltRtVtV ;t# )ÚRagTokenForGenerationiI  Nc          	      ój   <€ V ^8„  d   QhRS[ R,          RS[R,          RS[R,          RS[R,          /# ry   rz   )r2   r3   s   "€r4   r5   Ú"RagTokenForGeneration.__annotate__O  sG   ø€ ÷ ñ á  4Õ'ðñ *¨DÕ0ðñ # TÕ)ð	ñ
   $Õ&ñr7   c                óð   <€ Vf   Ve   Vf   Q R4       hVf-   \         P                  ! VP                  VP                  3/ VB p\        SV `  V4       \        WW4R7      V n        V P                  4        R# rÒ   rÓ   rÔ   s   &&&&&,€r4   r�   ÚRagTokenForGeneration.__init__O  s€   ø€ ð  Ò!Ð&6Ò&BÀyÒG\ð 	
ØVó	
Ð]ð Š>Ü×FÒFØ ×'Ñ'¨×)9Ñ)9ñØ=CñˆFô 	‰Ñ˜Ô ô  6ÐXaÔwˆŒà�‰Ör7   c                ó    <€ V ^8„  d   QhRS[ /# r×   r   )r2   r3   s   "€r4   r5   ri  o  rØ   r7   c                ó&   € WP                   n        R # r¬   rÚ   rÛ   s   &&r4   rÜ   Ú#RagTokenForGeneration.set_retrievero  rÞ   r7   c                ó    <€ V ^8„  d   QhRS[ /# rà   r   )r2   r3   s   "€r4   r5   ri  r  rá   r7   c                óH   € R V P                   n        WP                   n        R# rã   rä   rå   s   &&r4   ræ   Ú6RagTokenForGeneration.set_context_encoder_for_trainingr  rè   r7   c                óL   € Ve   VRRR 13,          pRR RVRVRVRVRVRVR	R
RV/	# )Nr  r‹   r�   r   r#   rŽ   r   r�   Údo_marginalizeTr”   r«   r8   )	r‡   rŽ   r   rŒ   r�   r�   r   r”   rg   s	   &&&&&&&&,r4   Úprepare_inputs_for_generationÚ3RagTokenForGeneration.prepare_inputs_for_generationv  sU   € ð Ò&à 1°!°R±S°&Õ 9Ðð ˜Ø˜Ø˜*Ø$ nØÐ!2Ø˜Ø˜Ø˜dØ�fð

ð 
	
r7   c                ó.   € V P                   P                  # r¬   rÚ   rõ   s   &r4   rL   ÚRagTokenForGeneration.retriever“  r÷   r7   c                ó.   € V P                   P                  # r¬   rù   rõ   s   &r4   r\   ÚRagTokenForGeneration.generator—  r÷   r7   c                ó.   € V P                   P                  # r¬   rü   rõ   s   &r4   r[   Ú&RagTokenForGeneration.question_encoder›  rþ   r7   c                ó˜  aa	€ R o	Rp\        \        V 4      4       EF  p\        V \        4      '       d®   V	V3R lV P                  P
                  V,          P                  V P                  P
                  V,          P                  V P                  P
                  V,          P                  V P                  P
                  V,          P                  3 4       w  rErgWEWg3pMJV	V3R lV P
                  V,          P                  V P
                  V,          P                  3 4       w  rEWE3pW(3,          pEK  	  \        V 4      ! V4      # )zeReorders cache for generation. BART-inspired but we need to take care of the extra dimension for docsc                 ó  € V P                   ^ ,          VP                   ^ ,          ,          pV P                  ! RV.V P                   R,          O5!  p V P                  ^ V4      p V P                  ! R.V P                   R,          O5!  pV# )r9  r6  r:  r«   )r´   r³   Úindex_select)rº   Ú	new_orderr”   Úresults   &&  r4   Ú_reorder_stackedÚ>RagTokenForGeneration._reorder_cache.<locals>._reorder_stacked£  sz   € Ø"×(Ñ(¨Õ+¨y¯©¸qÕ/AÕAˆFØ)×.Ò.¨r°6ÐT¸M×<OÑ<OÐPRÕ<SÓTˆMØ)×6Ñ6°q¸)ÓDˆMØ"×'Ò'¨ÐE¨]×-@Ñ-@ÀÕ-DÓEˆFØˆMr7   c              3   óh   <"  € T F'  pS! VSP                  VP                  4      4      x € K)  	  R # 5ir¬   ©r®   r�   ©rV  Úxr�  Úbeam_idxs   & €€r4   rX  Ú7RagTokenForGeneration._reorder_cache.<locals>.<genexpr>­  s4   øé € ð \ñ˜ñ % Q¨¯©°A·H±HÓ(=×>Ð>óùó   ƒ/2c              3   óh   <"  € T F'  pS! VSP                  VP                  4      4      x € K)  	  R # 5ir¬   r„  r…  s   & €€r4   rX  rˆ  ¸  s/   øé € ð 6ác˜ñ % Q¨¯©°A·H±HÓ(=×>Ð>Ûcùr‰  r8   )
r  r_   r~   r   Úself_attention_cacheÚlayersÚkeysr  Úcross_attention_cacherƒ   )
r   r‡  Úreordered_pastÚidxÚself_attention_kÚself_attention_vÚcross_attention_kÚcross_attention_vÚ	new_tupler�  s
   &f       @r4   Ú_reorder_cacheÚ$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Ð Ð4Eð .ÐARÐf‘	õ6à-×4Ñ4°SÕ9×>Ñ>À×@VÑ@VÐWZÕ@[×@bÑ@bÑcó6Ñ2Ð ð .Ð@�	Ø˜lÕ*‹Nñ% /ô& �OÔ$ ^Ó4Ð4r7   c                óš  € Ve   TMV P                   P                  p\        P                  P	                  VRR7      P                  VP                  ^ ,          V,          VRVP                  R4      4      p\        P                  ! V^R7      pWEP                  R4      P                  R4      ,           p\        P                  ! V^R7      # )Nr©   r«   )rV   r”   r   r@  rA  r³   r´   rB  r.   r¶   rE  )r‡   rF  r   r”   rH  rI  Úlog_prob_sums   &&&&   r4   ÚmarginalizeÚ!RagTokenForGeneration.marginalizeÀ  s£   € Ø!Ò-‘°4·;±;×3EÑ3Eˆô —}‘}×0Ñ0°ÀÐ0ÓD×IÑIØ×Ñ˜QÕ 6Õ)¨6°2°z·±ÀrÓ7Jó
ˆô ×(Ò(¨¸Ô;ˆØ#×&<Ñ&<¸RÓ&@×&JÑ&JÈ2Ó&NÕNˆÜ�Š˜|°Ô3Ð3r7   c          $      óH  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[S[S[ P                  ,          ,          R,          RS[ P                  R,          RS[ P
                  R,          RS[R,          RS[ P                  R,          R	S[ P                  R,          R
S[ P                  R,          RS[R,          RS[R,          RS[R,          RS[R,          RS[R,          RS[R,          RS[ P                  R,          RS[R,          RS[	/# )r   r‹   NrŒ   r�   rŽ   r�   r   r"   r#   r   r�   r‘   r’   r“   rs  rë   rì   r”   rM   )
r.   r0   r/   r1   r•   r–   r   r—   r˜   r   )r2   r3   s   "€r4   r5   ri  Ì  s^  ø€ ÷ j
ñ 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
r7   c                óœ  € Ve   TMV P                   P                  pVe   TMV P                   P                  pVe   TMV P                   P                  pVe	   Vf   TpRp
V P	                  VVVVVVVV	VV
VVVVR7      pRpVP
                  pVeF   Vf   Q hV P                  VP
                  VP                  VVV P                   P                  VR7      pV'       d   V P                  VVP                  V4      p\        R/ RVbRVbRVP                  bRVP                  bR	VP                  bR
VP                  bRVP                  bRVP                  bRVP                   bRVP"                  bRVP$                  bRVP&                  bRVP(                  bRVP*                  bRVP,                  bRVP.                  bRVP0                  b # )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,   r8   )rV   r”   rs  rë   rH   r   rð   r   rñ   rš  r   r   r"   r#   r    r!   r$   r%   r&   r'   r(   r)   r*   r+   r,   )r‡   r‹   rŒ   r�   rŽ   r�   r   r"   r#   r   r�   r‘   r’   r“   rs  rë   rì   r”   rg   rò   r   r   s   &&&&&&&&&&&&&&&&&&,   r4   rÈ   Ú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ð#
ð 	
r7   c                ó   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          R	S[S[S[ P                  .S[S[,          3,          R,          R
S[R,          RS[	R,          RS[ P                  /# )r   r‹   NrŒ   r"   r#   r   r”   Úgeneration_configÚprefix_allowed_tokens_fnÚlogits_processorÚstopping_criteriarM   )
r.   r0   r/   r˜   r   r   r•   r
  r   r   )r2   r3   s   "€r4   r5   ri  y  sò   ø€ ÷ I
ñ 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
r7   c           	     óŽ  aa€ V P                  RVRRR4      pV P                  ! V3/ VB w  r}VP                  4       pV\        P                  \        P
                  \        P                  \        P                  39  d   \        RV R24      h\        \        V 4      \        V,          4      pV P                  VP                  4       4       V P                  WçV4       VP                  RR4      RJpV P!                  VV4       Se   SMV P"                  P$                  oV P&                  Ee!   VEf   V P)                  WR7      ^ ,          pV P'                  VVP+                  4       P-                  R\.        P0                  R7      P3                  4       \        V P4                  P"                  R	R4      SR
R7      pVR,          VR,          VR,          prCVP-                  V4      pVP-                  V4      pVP-                  V4      p\.        P6                  ! VP9                  ^4      VP;                  ^^4      4      P=                  ^4      pVP>                  ^ ,          S,          ^ 8X  g    Q RS RVP>                  ^ ,           R24       hVP>                  ^ ,          S,          oV P@                  P4                  PC                  4       pV! W4RR7      p\.        PD                  ! SVPF                  ,          ^3VPH                  \.        PJ                  \M        V PO                  4       4      PP                  R7      pVP>                  R#,          pVR,          pR$VV3R llpV! WGPF                  R7      pV! VVPF                  R7      VR&   VPS                  VPF                  ^ R7      pW]R&   VVR&   WMR&   SVR&   VPT                  VR&   V PW                  VVVVV	VPP                  R7      pV PY                  WzR7      pV P[                  VVRVP>                  ^ ,          VP\                  ^,
          R7       V! V V3R VR!VR"V/VBVB # )%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 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 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 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.rŒ   r  r›   rœ   rŸ   r    r¡   r"   r#   r    r¦   r§   r¨   T)r‹   rŒ   rš   )rž   r�   Úlast_hidden_statec                 ó2  <€ V R,          P                  S^S3V P                  R,          ,           4      p V P                  SVS3V P                  R,          ,           4      p V P                  SV,          S,          3V P                  R,          ,           4      # )Nr6  :é   NN)NNr  )Úreshaper´   Úexpand)Útensorr  r  r”   s   &&€€r4   Úextend_enc_outputÚ9RagTokenForGeneration.generate.<locals>.extend_enc_output  s}   ø€ à˜MÕ*×2Ñ2°JÀÀ6Ð3JÈVÏ\É\ÐZ\ÕM]Õ3]Ó^ˆFà—]‘] J°	¸6Ð#BÀVÇ\Á\ÐRTÕEUÕ#UÓVˆFà—>‘> :°	Õ#9¸FÕ#BÐ"DÀvÇ|Á|ÐTVÕGWÕ"WÓXÐXr7   )r  r©   r   r�   r”   r�   )r   Úinput_ids_seq_lengthÚencoder_input_idsr¡  r¢  r�   )r   r£  )Úgeneration_moder  Úmax_cache_lengthr¢  r£  r   r«   r¬   )/Ú_extract_generation_mode_kwargsÚ_prepare_generation_configÚget_generation_moder
   ÚSAMPLEÚGREEDY_SEARCHÚBEAM_SEARCHÚBEAM_SAMPLEÚ
ValueErrorr±   rƒ   r   Ú_validate_model_kwargsÚcopyÚ_validate_generation_moderd   Ú_prepare_special_tokensrV   r”   rL   r[   r­   r®   r.   r¯   r°   r\   rµ   r¶   r·   r¸   r´   rH   Úget_encoderÚfullr  Údecoder_start_token_idÚlongÚnextÚ
parametersr�   r¹   r�   Ú_get_logits_processorÚ_get_stopping_criteriaÚ_prepare_cache_for_generationÚ
max_length)r‡   r‹   rŒ   r"   r#   r   r”   r   r¡  r¢  r£  rg   Úgeneration_mode_kwargsr  r¯  Údecoding_methodÚkwargs_has_attention_maskr  Úoutr    Úencoderr�   r­  r¥  r«  Úprepared_logits_processorÚprepared_stopping_criteriar  s   &&&&&&f&&&&,               @r4   r  ÚRagTokenForGeneration.generatex  s‡  ù€ ðb "&×!EÑ!EÀdÈFÐTYÐ[_ÐaeÓ!fÐØ*.×*IÒ*IÐJ[Ñ*fÐ_eÑ*fÑ'ÐØ+×?Ñ?ÓAˆØÜ×!Ñ!Ü×(Ñ(Ü×&Ñ&Ü×&Ñ&ð	#
ô 
ô Ø3°OÐ3DÐDyÐzóð ô "¤$ t£*Ô.FÀÕ.WÓXˆØ×#Ñ# L×$5Ñ$5Ó$7Ô8Ø×&Ñ& ÐKaÔbà$0×$4Ñ$4Ð5EÀtÓ$LÐTXÐ$XÐ!Ø×$Ñ$Ð%6Ð8QÔRð "Ò-‘°4·;±;×3EÑ3Eˆð �>‰>Ó%Ð*;Ó*CØ%)×%:Ñ%:¸9Ð%:Ó%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ˆÙ!Ð,=ÐrvÔwˆä—J’JØÐ+×5Ñ5Õ5°qÐ9Ø×4Ñ4Ü—*‘*Ü˜Ÿ™Ó)Ó*×1Ñ1ô	
ˆ	ð  )Ÿ™¨rÕ2ÐØ+Ð,?Õ@Ð÷	Yð 	Yñ "3Ð3I×UpÑUpÔ!qÐÙ/@ØÐ):×)DÑ)Dô0
ˆÐ+Ñ,ð  ×1Ñ1Ð2C×2MÑ2MÐSTÐ1ÓUˆ
ð &0�\Ñ"Ø*9ˆÐ&Ñ'Ø)?Ð%Ñ&Ø!'ˆ�XÑØ$5×$?Ñ$?ˆ�[Ñ!à$(×$>Ñ$>Ø/Ø!5Ø/Ø%=Ø-Ø×#Ñ#ð %?ó %
Ð!ð &*×%@Ñ%@Ø/ð &Aó &
Ð"ð 	×*Ñ*ØØØ Ø —‘ qÕ)Ø.×9Ñ9¸AÕ=ð 	+ô 	
ñ ØØñ
ð 7ð
ð 9ð	
ð
 0ð
ð %ð
ð ñ
ð 	
r7   c                ó(   € V P                  W4      pV# r¬   )r–  )r‡   r   r‡  s   &&&r4   Ú_temporary_reorder_cacheÚ.RagTokenForGeneration._temporary_reorder_cacheE  s   € ð ×-Ñ-¨oÓHˆØÐr7   c                óJ   € V P                   P                  P                  4       # r¬   )rH   r\   Úget_input_embeddingsrõ   s   &r4   rÓ  Ú*RagTokenForGeneration.get_input_embeddingsL  s   € Ø�x‰x×!Ñ!×6Ñ6Ó8Ð8r7   c                óJ   € V P                   P                  P                  4       # r¬   )rH   r\   Úget_output_embeddingsrõ   s   &r4   rÖ  Ú+RagTokenForGeneration.get_output_embeddingsO  s   € Ø�x‰x×!Ñ!×7Ñ7Ó9Ð9r7   c                óL   € V P                   P                  P                  V4      # r¬   )rH   r\   Úset_output_embeddings)r‡   Únew_embeddingss   &&r4   rÙ  Ú+RagTokenForGeneration.set_output_embeddingsR  s   € Ø�x‰x×!Ñ!×7Ñ7¸ÓGÐGr7   c                ó´   € Vf   V P                   P                  pVP                  VP                  4      pVRRR13,          P	                  4       VR&   W#R&   V# )zCShift input ids one token to the right, and pad with start_token_idNr  r«   r5  r8  )rV   r¿  Ú	new_zerosr´   Úclone)r‡   r‹   Ústart_token_idÚshifted_input_idss   &&& r4   Úshift_tokens_rightÚ(RagTokenForGeneration.shift_tokens_rightU  s[   € àÒ!Ø!Ÿ[™[×?Ñ?ˆNØ%×/Ñ/°	·±Ó@ÐØ#,¨Q°°°¨VÕ#4×#:Ñ#:Ó#<Ð˜%Ñ Ø"0˜$ÑØ Ð r7   c                ó$  a a€ Ve   TMS P                   P                  p\        P                  ! SR,          SP	                  SP
                  ^ ,          ^4      P                  S P                   P                  P                  4      .^4      oV V3R lpS P                  WV4      pSP                  R4      oSP                  4       VP                  4       8X  g   Q hVP                  RSR7      p	VP                  RRR7      p
V! Wš4      w  ršV	P                  ^4      p	V
P                  ^4      p
V	) pV
) pV'       d!   VP                  4       pVP                  4       pWXP                  R4      ,          pRV,
          V,          WÜ,          ,           pV# )Nc                 ó  <€ SP                  SP                  P                  P                  4      pVP	                  4       '       d%   V P                  VR 4       VP                  VR 4       V P                  R4      VP                  R4      3# r#  r%  r)  s   && €€r4   r.  Ú1RagTokenForGeneration.get_nll.<locals>._mask_padse  r0  r7   r1  Tr2  r4  r5  r«   )rV   r”   r.   r;  r<  r´   r=  r\   r  rš  r¶   rª   rC  rD  rB  )r‡   rF  r   r-  rë   rï   r”   r.  rM  r*  r+  rN  rO  rP  r   s   f&&f&&&        r4   rð   ÚRagTokenForGeneration.get_nll^  sQ  ù€ Ø!Ò-‘°4·;±;×3EÑ3Eˆä—’Ø�E�]˜FŸJ™J v§|¡|°A¥¸Ó:×@Ñ@ÀÇÁ×AVÑAV×AcÑAcÓdÐeÐghó
ˆö	:ð ×'Ñ'¨
ÀÓGˆà×!Ñ! "Ó%ˆØ�z‰z‹|˜|×/Ñ/Ó1Ô1Ð1Ð1à× Ñ  R¨vÐ Ó6ˆØ!×%Ñ%¨"°dÐ%Ó;ˆ
Ù# BÓ3‰ˆØ�V‰V�A‹YˆØ—^‘^ AÓ&ˆ
à�3ˆØ!�kˆçØ—|‘|“~ˆHØ%Ÿ/™/Ó+ˆKà×+Ñ+¨BÓ/Õ/ˆØ�g• Õ)¨EÕ,?Õ?ˆØˆr7   ra  rÊ   )NNNNNNr¬   rb  )Fr$  N)r9   r:   r;   r<   r�   rÜ   ræ   rt  rc  rL   r\   r[   re  r–  rš  r   rÈ   r.   rd  r   r   r  rÐ  rÓ  rÖ  rÙ  rá  rð   r?   r@   rË   rÌ   s   @@r4   rg  rg  I  s	  ù‡ € ÷õ ÷@'ð '÷+ð +ô
ð: ñ"ó ð"ð ñ"ó ð"ð ñ)ó ð)ð ñ5ó ð5ô@	4ð ÷j
ñ j
ó ðj
ðX ‡]‚]ƒ_ð .2Ø26Ø59Ø:>Ø/3Ø!Ø59ØTXÙ7JÓ7LÙ9MÓ9O÷I
ñ I
ó ðI
òXò9ò:òHô!÷"ô "r7   rg  )rw   rG   rÎ   rg  ))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_loggerr9   Úloggerr   rC   rG   rw   rÎ   rg  Ú__all__r8   r7   r4   Ú<module>rõ     sZ  ðñ  å $Ý !ã Ý ç 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‚r7   