§
    [zniþô ã                   óò  — d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZmZ d dl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mZmZmZmZ dd	lmZm Z m!Z!m"Z" d
dl#m$Z$m%Z% d
dl&m'Z'm(Z(m)Z) d
dl*m+Z+ d
dl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF d
dlGmHZHmIZImJZJmKZKmLZL erddlMmNZN d
dlOmPZP  e"jQ        eR¦  «        ZS e!¦   «         rd dlTmUZUmVZV e G d„ de ¦  «        ¦   «         ZWe G d„ de ¦  «        ¦   «         ZXe G d„ de ¦  «        ¦   «         ZYe G d„ de ¦  «        ¦   «         ZZe G d„ de ¦  «        ¦   «         Z[e G d„ de ¦  «        ¦   «         Z\e G d„ d e ¦  «        ¦   «         Z]e G d!„ d"e ¦  «        ¦   «         Z^e G d#„ d$e ¦  «        ¦   «         Z_e G d%„ d&e ¦  «        ¦   «         Z`eeZeWf         Zaee\e[f         Zbee^e]f         Zcee`e_f         ZdeeXeYf         Zeeeaebecedeef         Zf G d'„ d(e¦  «        Zg G d)„ d*¦  «        Zhd+„ Zid=d-„Zjd d. ekd/¦  «         d
fd0ejl        d1emd2ekd3ekd4emd5ejl        fd6„Znd7ejl        d8ejl        d9ejl        d:ekd;emd5ejl        fd<„ZodS )>é    N)Ú	dataclass)ÚTYPE_CHECKINGÚAnyÚCallableÚDictÚListÚOptionalÚTupleÚUnion)Únné   )Úis_deepspeed_zero3_enabled)ÚCausalLMOutputWithPastÚSeq2SeqLMOutput)Ú'MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPINGÚMODEL_FOR_CAUSAL_LM_MAPPINGÚ&MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPINGÚ"MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPINGÚMODEL_FOR_VISION_2_SEQ_MAPPING)ÚExplicitEnumÚModelOutputÚis_accelerate_availableÚloggingé   )ÚDisjunctiveConstraintÚPhrasalConstraint)Ú
BeamScorerÚBeamSearchScorerÚConstrainedBeamSearchScorer)ÚGenerationConfig)Ú#EncoderNoRepeatNGramLogitsProcessorÚ'EncoderRepetitionPenaltyLogitsProcessorÚEpsilonLogitsWarperÚEtaLogitsWarperÚExponentialDecayLengthPenaltyÚForcedBOSTokenLogitsProcessorÚForcedEOSTokenLogitsProcessorÚForceTokensLogitsProcessorÚHammingDiversityLogitsProcessorÚInfNanRemoveLogitsProcessorÚLogitNormalizationÚLogitsProcessorListÚMinLengthLogitsProcessorÚ!MinNewTokensLengthLogitsProcessorÚNoBadWordsLogitsProcessorÚNoRepeatNGramLogitsProcessorÚ PrefixConstrainedLogitsProcessorÚ RepetitionPenaltyLogitsProcessorÚSequenceBiasLogitsProcessorÚ$SuppressTokensAtBeginLogitsProcessorÚSuppressTokensLogitsProcessorÚTemperatureLogitsWarperÚTopKLogitsWarperÚTopPLogitsWarperÚTypicalLogitsWarperÚ.UnbatchedClassifierFreeGuidanceLogitsProcessor)ÚMaxLengthCriteriaÚMaxTimeCriteriaÚStoppingCriteriaÚStoppingCriteriaListÚvalidate_stopping_criteria)ÚPreTrainedModel)ÚBaseStreamer)ÚAlignDevicesHookÚadd_hook_to_modulec                   óÔ   — e Zd ZU dZdZej        ed<   dZe	e
ej                          ed<   dZe	e
e
ej                                   ed<   dZe	e
e
ej                                   ed<   dS )ÚGreedySearchDecoderOnlyOutputa-  
    Base class for outputs of decoder-only generation models using greedy search.


    Args:
        sequences (`torch.LongTensor` of shape `(batch_size, 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`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Processed prediction scores of the language modeling head (scores for each vocabulary token before SoftMax)
            at each generation step. Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for
            each generated token), with each tensor of shape `(batch_size, config.vocab_size)`.
        attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, num_heads, generated_length, sequence_length)`.
        hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, generated_length, hidden_size)`.
    NÚ	sequencesÚscoresÚ
attentionsÚhidden_states©Ú__name__Ú
__module__Ú__qualname__Ú__doc__rF   ÚtorchÚ
LongTensorÚ__annotations__rG   r	   r
   ÚFloatTensorrH   rI   © ó    ú}/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/generation/utils.pyrE   rE   W   s’   € € € € € € ðð ð( #'€IˆuÔÐ&Ð&Ñ&Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø<@€J�˜˜u UÔ%6Ô7Ô8Ô9Ð@Ð@Ñ@Ø?C€M�8˜E %¨Ô(9Ô":Ô;Ô<ÐCÐCÑCÐCÐCrT   rE   c                   óp  — e Zd ZU dZdZej        ed<   dZe	e
ej                          ed<   dZe	e
ej                          ed<   dZe	e
ej                          ed<   dZe	e
e
ej                                   ed<   dZe	e
e
ej                                   ed<   dZe	e
e
ej                                   ed	<   dS )
Ú%ContrastiveSearchEncoderDecoderOutputaP
  
    Base class for outputs of decoder-only generation models using contrastive search.

    Args:
        sequences (`torch.LongTensor` of shape `(batch_size, 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`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Processed prediction scores of the language modeling head (scores for each vocabulary token before SoftMax)
            at each generation step. Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for
            each generated token), with each tensor of shape `(batch_size, config.vocab_size)`.
        encoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer of the decoder) of shape `(batch_size, num_heads,
            sequence_length, sequence_length)`.
        encoder_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 + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.
        decoder_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, num_heads, generated_length, sequence_length)`.
        cross_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, num_heads, generated_length, sequence_length)`.
        decoder_hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, generated_length, hidden_size)`.
    NrF   rG   Úencoder_attentionsÚencoder_hidden_statesÚdecoder_attentionsÚcross_attentionsÚdecoder_hidden_states©rK   rL   rM   rN   rF   rO   rP   rQ   rG   r	   r
   rR   rX   rY   rZ   r[   r\   rS   rT   rU   rW   rW   s   só   € € € € € € ðð ð8 #'€IˆuÔÐ&Ð&Ñ&Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø=AÐ˜  uÔ'8Ô!9Ô:ÐAÐAÑAØ@DÐ˜8 E¨%Ô*;Ô$<Ô=ÐDÐDÑDØDHÐ˜  u¨UÔ->Ô'?Ô!@ÔAÐHÐHÑHØBFÐ�h˜u U¨5Ô+<Ô%=Ô>Ô?ÐFÐFÑFØGKÐ˜8 E¨%°Ô0AÔ*BÔ$CÔDÐKÐKÑKÐKÐKrT   rW   c                   óÔ   — e Zd ZU dZdZej        ed<   dZe	e
ej                          ed<   dZe	e
e
ej                                   ed<   dZe	e
e
ej                                   ed<   dS )Ú"ContrastiveSearchDecoderOnlyOutputaA  
    Base class for outputs of decoder-only generation models using contrastive search.

    Args:
        sequences (`torch.LongTensor` of shape `(batch_size, 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`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when
        `config.output_scores=True`):
            Processed prediction scores of the language modeling head (scores for each vocabulary token before SoftMax)
            at each generation step. Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for
            each generated token), with each tensor of shape `(batch_size, config.vocab_size)`.
        attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, num_heads, generated_length, sequence_length)`.
        hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is
        passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, generated_length, hidden_size)`.
    NrF   rG   rH   rI   rJ   rS   rT   rU   r_   r_   š   ó’   € € € € € € ðð ð* #'€IˆuÔÐ&Ð&Ñ&Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø<@€J�˜˜u UÔ%6Ô7Ô8Ô9Ð@Ð@Ñ@Ø?C€M�8˜E %¨Ô(9Ô":Ô;Ô<ÐCÐCÑCÐCÐCrT   r_   c                   óp  — e Zd ZU dZdZej        ed<   dZe	e
ej                          ed<   dZe	e
ej                          ed<   dZe	e
ej                          ed<   dZe	e
e
ej                                   ed<   dZe	e
e
ej                                   ed<   dZe	e
e
ej                                   ed	<   dS )
Ú GreedySearchEncoderDecoderOutputaH  
    Base class for outputs of encoder-decoder generation models using greedy search. Hidden states and attention
    weights of the decoder (respectively the encoder) can be accessed via the encoder_attentions and the
    encoder_hidden_states attributes (respectively the decoder_attentions and the decoder_hidden_states attributes)


    Args:
        sequences (`torch.LongTensor` of shape `(batch_size, 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`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Processed prediction scores of the language modeling head (scores for each vocabulary token before SoftMax)
            at each generation step. Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for
            each generated token), with each tensor of shape `(batch_size, config.vocab_size)`.
        encoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer of the decoder) of shape `(batch_size, num_heads,
            sequence_length, sequence_length)`.
        encoder_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 + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.
        decoder_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, num_heads, generated_length, sequence_length)`.
        cross_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, num_heads, generated_length, sequence_length)`.
        decoder_hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, generated_length, hidden_size)`.
    NrF   rG   rX   rY   rZ   r[   r\   r]   rS   rT   rU   rb   rb   ·   só   € € € € € € ðð ð> #'€IˆuÔÐ&Ð&Ñ&Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø=AÐ˜  uÔ'8Ô!9Ô:ÐAÐAÑAØ@DÐ˜8 E¨%Ô*;Ô$<Ô=ÐDÐDÑDØDHÐ˜  u¨UÔ->Ô'?Ô!@ÔAÐHÐHÑHØBFÐ�h˜u U¨5Ô+<Ô%=Ô>Ô?ÐFÐFÑFØGKÐ˜8 E¨%°Ô0AÔ*BÔ$CÔDÐKÐKÑKÐKÐKrT   rb   c                   óÔ   — e Zd ZU dZdZej        ed<   dZe	e
ej                          ed<   dZe	e
e
ej                                   ed<   dZe	e
e
ej                                   ed<   dS )ÚSampleDecoderOnlyOutputaˆ  
    Base class for outputs of decoder-only generation models using sampling.


    Args:
        sequences (`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`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Processed prediction scores of the language modeling head (scores for each vocabulary token before SoftMax)
            at each generation step. Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for
            each generated token), with each tensor of shape `(batch_size*num_return_sequences, config.vocab_size)`.
        attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(num_return_sequences*batch_size, num_heads, generated_length,
            sequence_length)`.
        hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(num_return_sequences*batch_size, generated_length, hidden_size)`.
    NrF   rG   rH   rI   rJ   rS   rT   rU   rd   rd   á   r`   rT   rd   c                   óp  — e Zd ZU dZdZej        ed<   dZe	e
ej                          ed<   dZe	e
ej                          ed<   dZe	e
ej                          ed<   dZe	e
e
ej                                   ed<   dZe	e
e
ej                                   ed<   dZe	e
e
ej                                   ed	<   dS )
ÚSampleEncoderDecoderOutputaÍ  
    Base class for outputs of encoder-decoder generation models using sampling. Hidden states and attention weights of
    the decoder (respectively the encoder) can be accessed via the encoder_attentions and the encoder_hidden_states
    attributes (respectively the decoder_attentions and the decoder_hidden_states attributes)


    Args:
        sequences (`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`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Processed prediction scores of the language modeling head (scores for each vocabulary token before SoftMax)
            at each generation step. Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for
            each generated token), with each tensor of shape `(batch_size*num_return_sequences, config.vocab_size)`.
        encoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer of the decoder) of shape
            `(batch_size*num_return_sequences, num_heads, sequence_length, sequence_length)`.
        encoder_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 + one for the output of each layer) of
            shape `(batch_size*num_return_sequences, sequence_length, hidden_size)`.
        decoder_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_return_sequences, num_heads, generated_length,
            sequence_length)`.
        cross_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, num_heads, generated_length, sequence_length)`.
        decoder_hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_return_sequences, generated_length, hidden_size)`.
    NrF   rG   rX   rY   rZ   r[   r\   r]   rS   rT   rU   rf   rf   þ   sô   € € € € € € ðð ð@ #'€IˆuÔÐ&Ð&Ñ&Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø=AÐ˜  uÔ'8Ô!9Ô:ÐAÐAÑAØ@DÐ˜8 E¨%Ô*;Ô$<Ô=ÐDÐDÑDØDHÐ˜  u¨UÔ->Ô'?Ô!@ÔAÐHÐHÑHØBFÐ�h˜u U¨5Ô+<Ô%=Ô>Ô?ÐFÐFÑFØGKÐ˜8 E¨%°Ô0AÔ*BÔ$CÔDÐKÐKÑKÐKÐKrT   rf   c                   ó  — e Zd ZU dZdZej        ed<   dZe	ej
                 ed<   dZe	eej
                          ed<   dZe	ej                 ed<   dZe	eeej
                                   ed<   dZe	eeej
                                   ed<   dS )	ÚBeamSearchDecoderOnlyOutputa	  
    Base class for outputs of decoder-only generation models using beam search.

    Args:
        sequences (`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`.
        sequences_scores (`torch.FloatTensor` of shape `(batch_size*num_return_sequences)`, *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Final beam scores of the generated `sequences`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Beam transition scores for each vocabulary token at each generation step. Beam transition scores consisting
            of log probabilities of tokens conditioned on log softmax of previously generated tokens in this beam.
            Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for each generated token),
            with each tensor of shape `(batch_size*num_beams*num_return_sequences, config.vocab_size)`.
        beam_indices (`torch.LongTensor`, *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Beam indices of generated token id at each generation step. `torch.LongTensor` of shape
            `(batch_size*num_return_sequences, sequence_length)`.
        attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_beams, num_heads, generated_length, sequence_length)`.
        hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_beams*num_return_sequences, generated_length, hidden_size)`.
    NrF   Úsequences_scoresrG   Úbeam_indicesrH   rI   ©rK   rL   rM   rN   rF   rO   rP   rQ   ri   r	   rR   rG   r
   rj   rH   rI   rS   rT   rU   rh   rh   )  óÃ   € € € € € € ðð ð2 #'€IˆuÔÐ&Ð&Ñ&Ø48Ð�h˜uÔ0Ô1Ð8Ð8Ñ8Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø/3€L�(˜5Ô+Ô,Ð3Ð3Ñ3Ø<@€J�˜˜u UÔ%6Ô7Ô8Ô9Ð@Ð@Ñ@Ø?C€M�8˜E %¨Ô(9Ô":Ô;Ô<ÐCÐCÑCÐCÐCrT   rh   c                   ó¸  — e Zd ZU dZdZej        ed<   dZe	ej
                 ed<   dZe	eej
                          ed<   dZe	ej                 ed<   dZe	eej
                          ed<   dZe	eej
                          ed<   dZe	eeej
                                   ed	<   dZe	eeej
                                   ed
<   dZe	eeej
                                   ed<   dS )ÚBeamSearchEncoderDecoderOutputaM  
    Base class for outputs of encoder-decoder generation models using beam search. Hidden states and attention weights
    of the decoder (respectively the encoder) can be accessed via the encoder_attentions and the encoder_hidden_states
    attributes (respectively the decoder_attentions and the decoder_hidden_states attributes)

    Args:
        sequences (`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`.
        sequences_scores (`torch.FloatTensor` of shape `(batch_size*num_return_sequences)`, *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Final beam scores of the generated `sequences`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Beam transition scores for each vocabulary token at each generation step. Beam transition scores consisting
            of log probabilities of tokens conditioned on log softmax of previously generated tokens in this beam.
            Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for each generated token),
            with each tensor of shape `(batch_size*num_beams, config.vocab_size)`.
        beam_indices (`torch.LongTensor`, *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Beam indices of generated token id at each generation step. `torch.LongTensor` of shape
            `(batch_size*num_return_sequences, sequence_length)`.
        encoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer of the decoder) of shape `(batch_size, num_heads,
            sequence_length, sequence_length)`.
        encoder_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 + one for the output of each layer) of
            shape `(batch_size*num_beams*num_return_sequences, sequence_length, hidden_size)`.
        decoder_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_beams*num_return_sequences, num_heads, generated_length,
            sequence_length)`.
        cross_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, num_heads, generated_length, sequence_length)`.
        decoder_hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_beams*num_return_sequences, generated_length, hidden_size)`.
    NrF   ri   rG   rj   rX   rY   rZ   r[   r\   ©rK   rL   rM   rN   rF   rO   rP   rQ   ri   r	   rR   rG   r
   rj   rX   rY   rZ   r[   r\   rS   rT   rU   rn   rn   L  s%  € € € € € € ð#ð #ðJ #'€IˆuÔÐ&Ð&Ñ&Ø48Ð�h˜uÔ0Ô1Ð8Ð8Ñ8Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø/3€L�(˜5Ô+Ô,Ð3Ð3Ñ3Ø=AÐ˜  uÔ'8Ô!9Ô:ÐAÐAÑAØ@DÐ˜8 E¨%Ô*;Ô$<Ô=ÐDÐDÑDØDHÐ˜  u¨UÔ->Ô'?Ô!@ÔAÐHÐHÑHØBFÐ�h˜u U¨5Ô+<Ô%=Ô>Ô?ÐFÐFÑFØGKÐ˜8 E¨%°Ô0AÔ*BÔ$CÔDÐKÐKÑKÐKÐKrT   rn   c                   ó  — e Zd ZU dZdZej        ed<   dZe	ej
                 ed<   dZe	eej
                          ed<   dZe	ej                 ed<   dZe	eeej
                                   ed<   dZe	eeej
                                   ed<   dS )	ÚBeamSampleDecoderOnlyOutputaó  
    Base class for outputs of decoder-only generation models using beam sample.

    Args:
        sequences (`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`.
        sequences_scores (`torch.FloatTensor` of shape `(batch_size * num_return_sequence)`, *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Final beam scores of the generated `sequences`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Beam transition scores for each vocabulary token at each generation step. Beam transition scores consisting
            of log probabilities of tokens conditioned on log softmax of previously generated tokens in this beam.
            Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for each generated token),
            with each tensor of shape `(batch_size*num_beams*num_return_sequences, config.vocab_size)`.
        beam_indices (`torch.LongTensor`, *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Beam indices of generated token id at each generation step. `torch.LongTensor` of shape
            `(batch_size*num_return_sequences, sequence_length)`.
        attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_beams, num_heads, generated_length, sequence_length)`.
        hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_beams, generated_length, hidden_size)`.
    NrF   ri   rG   rj   rH   rI   rk   rS   rT   rU   rq   rq   ~  rl   rT   rq   c                   ó¸  — e Zd ZU dZdZej        ed<   dZe	ej
                 ed<   dZe	eej
                          ed<   dZe	ej                 ed<   dZe	eej
                          ed<   dZe	eej
                          ed<   dZe	eeej
                                   ed	<   dZe	eeej
                                   ed
<   dZe	eeej
                                   ed<   dS )ÚBeamSampleEncoderDecoderOutputaû  
    Base class for outputs of encoder-decoder generation models using beam sampling. Hidden states and attention
    weights of the decoder (respectively the encoder) can be accessed via the encoder_attentions and the
    encoder_hidden_states attributes (respectively the decoder_attentions and the decoder_hidden_states attributes)

    Args:
        sequences (`torch.LongTensor` of shape `(batch_size*num_beams, 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`.
        sequences_scores (`torch.FloatTensor` of shape `(batch_size * num_return_sequence)`, *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Final beam scores of the generated `sequences`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Beam transition scores for each vocabulary token at each generation step. Beam transition scores consisting
            of log probabilities of tokens conditioned on log softmax of previously generated tokens in this beam.
            Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for each generated token),
            with each tensor of shape `(batch_size*num_beams, config.vocab_size)`).
        beam_indices (`torch.LongTensor`, *optional*, returned when `output_scores=True` is passed or when `config.output_scores=True`):
            Beam indices of generated token id at each generation step. `torch.LongTensor` of shape
            `(batch_size*num_return_sequences, sequence_length)`.
        encoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer of the decoder) of shape `(batch_size, num_heads,
            sequence_length, sequence_length)`.
        encoder_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 + one for the output of each layer) of
            shape `(batch_size*num_beams, sequence_length, hidden_size)`.
        decoder_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_beams, num_heads, generated_length, sequence_length)`.
        cross_attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or `config.output_attentions=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size, num_heads, generated_length, sequence_length)`.
        decoder_hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
            `torch.FloatTensor` of shape `(batch_size*num_beams, generated_length, hidden_size)`.
    NrF   ri   rG   rj   rX   rY   rZ   r[   r\   ro   rS   rT   rU   rs   rs   ¡  s%  € € € € € € ð"ð "ðH #'€IˆuÔÐ&Ð&Ñ&Ø48Ð�h˜uÔ0Ô1Ð8Ð8Ñ8Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø/3€L�(˜5Ô+Ô,Ð3Ð3Ñ3Ø=AÐ˜  uÔ'8Ô!9Ô:ÐAÐAÑAØ@DÐ˜8 E¨%Ô*;Ô$<Ô=ÐDÐDÑDØDHÐ˜  u¨UÔ->Ô'?Ô!@ÔAÐHÐHÑHØBFÐ�h˜u U¨5Ô+<Ô%=Ô>Ô?ÐFÐFÑFØGKÐ˜8 E¨%°Ô0AÔ*BÔ$CÔDÐKÐKÑKÐKÐKrT   rs   c                   ó2   — e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
S )ÚGenerationModezg
    Possible generation modes, downstream of the [`~generation.GenerationMixin.generate`] method.
    Úcontrastive_searchÚgreedy_searchÚsampleÚassisted_generationÚbeam_searchÚbeam_sampleÚconstrained_beam_searchÚgroup_beam_searchN)rK   rL   rM   rN   ÚCONTRASTIVE_SEARCHÚGREEDY_SEARCHÚSAMPLEÚASSISTED_GENERATIONÚBEAM_SEARCHÚBEAM_SAMPLEÚCONSTRAINED_BEAM_SEARCHÚGROUP_BEAM_SEARCHrS   rT   rU   ru   ru   Ú  sH   € € € € € ðð ð
 .ÐØ#€MØ€FØ/Ðà€KØ€KØ7ÐØ+ÐÐÐrT   ru   c            $       óL  — e Zd ZdZd„ Z	 	 	 dVdeej                 dee         dee	e
ej        f                  deej        ee
         e	e
ej        f         f         fd„Z	 	 	 dVdeej                 dee         dee	e
ej        f                  dej        fd	„Zdej        d
ee         deeeee         f                  dej        fd„Z	 dWdej        dee
         de	e
ef         fd„Z	 	 	 dVdede
de	e
ej        f         dededej        deej        e	e
ej        f         f         fd„ZdXdededefd„Ze	 	 	 dYdededeej                 deej        e	e
ef         f         fd„¦   «         ZdZdedefd„Z	 	 d[dede	e
ef         dedede	e
ef         f
d„Zd„ Zd edefd!„Z d ed"ed#         de!fd$„Z"	 	 	 dVd ed%ed&ej        d'e#eej        gee         f         d(ee         dee	e
ef                  d)eej                 d*eej                 defd+„Z$d ed,ee%         de%fd-„Z&d.eee%f         d/eee%f         deee%f         fd0„Z'	 	 d\d1ej        d2eej                 d3eej                 d4edej        f
d5„Z(d6„ Z)de	e
ef         fd7„Z*d8„ Z+de	e
ef         d9ede	e
ef         fd:„Z,de	e
ef         d;ede	e
ef         fd<„Z- ej.        ¦   «         	 	 	 	 	 	 	 	 	 	 d]deej                 d ee         d(ee         d,ee%         d'ee#eej        gee         f                  d=ee         d"ed#         d>ed?         d)eej                 d*eej                 dee/ej        f         fd@„¦   «         Z0 ej.        ¦   «         	 	 	 	 	 	 	 	 	 	 	 	 	 	 d^dej        dBee         dCee1         d(ee         dDee         d,ee%         d
ee         deeeee         f                  dEee         dFee         dGee         dHee         d=ed>ed?         dIee         dee2ej        f         f dJ„¦   «         Z3	 	 	 	 	 	 	 	 	 	 	 d_dej        d(ee         d,ee%         dKee         d
ee         deeeee         f                  dEee         dFee         dGee         dHee         d=ed>ed?         dee4ej        f         fdL„Z5	 	 	 	 	 	 	 	 	 	 	 	 d`dej        d(ee         d,ee%         dDee         dKee         d
ee         deeeee         f                  dEee         dFee         dGee         dHee         d=ed>ed?         dee6ej        f         fdM„Z7	 	 	 	 	 	 	 	 	 	 dadej        dNe8d(ee         d,ee%         dKee         d
ee         deeeee         f                  dEee         dFee         dGee         dHee         d=edee9ej        f         fdO„Z:	 	 	 	 	 	 	 	 	 	 	 dbdej        dNe8d(ee         d,ee%         dDee         dKee         d
ee         deeeee         f                  dEee         dFee         dGee         dHee         d=edee;ej        f         fdP„Z<	 	 	 	 	 	 	 	 	 	 dadej        dNe8d(ee         d,ee%         dKee         d
ee         deeeee         f                  dEee         dFee         dGee         dHee         d=efdQ„Z=	 	 	 	 	 	 	 	 	 	 d]dej        dRe>d(ee         d,ee%         dKee         d
ee         deeeee         f                  dEee         dFee         dGee         dHee         d=ee         dee9ej        f         fdS„Z?	 	 	 	 	 	 	 	 	 	 	 	 dcdej        d"d#dTed(ee         dDee         d,ee%         d
ee         deeeee         f                  dEee         dFee         dGee         dHee         d=ed>ed?         fdU„Z@dS )dÚGenerationMixina·  
    A class containing all functions for auto-regressive text generation, to be used as a mixin in [`PreTrainedModel`].

    The class exposes [`~generation.GenerationMixin.generate`], which can be used for:
        - *greedy decoding* by calling [`~generation.GenerationMixin.greedy_search`] if `num_beams=1` and
          `do_sample=False`
        - *contrastive search* by calling [`~generation.GenerationMixin.contrastive_search`] if `penalty_alpha>0` and
          `top_k>1`
        - *multinomial sampling* by calling [`~generation.GenerationMixin.sample`] if `num_beams=1` and
          `do_sample=True`
        - *beam-search decoding* by calling [`~generation.GenerationMixin.beam_search`] if `num_beams>1` and
          `do_sample=False`
        - *beam-search multinomial sampling* by calling [`~generation.GenerationMixin.beam_sample`] if `num_beams>1`
          and `do_sample=True`
        - *diverse beam-search decoding* by calling [`~generation.GenerationMixin.group_beam_search`], if `num_beams>1`
          and `num_beam_groups>1`
        - *constrained beam-search decoding* by calling [`~generation.GenerationMixin.constrained_beam_search`], if
          `constraints!=None` or `force_words_ids!=None`

    You do not need to call any of the above methods directly. Pass custom parameter values to 'generate' instead. To
    learn more about decoding strategies refer to the [text generation strategies guide](../generation_strategies).
    c                 ó    — t          d¦  «        ‚)NzeA model class needs to define a `prepare_inputs_for_generation` method in order to use `.generate()`.)ÚNotImplementedError)ÚselfÚargsÚkwargss      rU   Úprepare_inputs_for_generationz-GenerationMixin.prepare_inputs_for_generation  s   € Ý!Øsñ
ô 
ð 	
rT   NÚinputsÚbos_token_idÚmodel_kwargsÚreturnc                 óÒ  ‡— | j         j        r2t          | d¦  «        r"| j        j        | j        k    r| j        j        Šn| j        Šˆfd„|                     ¦   «         D ¦   «         }|                     ‰d¦  «        }|�|�t          d|› d‰› d|› d‰› d�	¦  «        ‚|�|}‰d	k    r¦d
|v r¢| j         j        szd
t          t          j
        | j        ¦  «        j                             ¦   «         ¦  «        v }|st          d| j        j        › d�¦  «        ‚|                      |||¬¦  «        |d	<   n|�t          d¦  «        ‚|d
         d
c}Š|                      |||¦  «        }|‰|fS )zT
        This function extracts the model-specific `inputs` for generation.
        Úencoderc                 ó,   •— i | ]\  }}|€|‰k    ¯||“ŒS ©NrS   )Ú.0ÚkÚvÚ
input_names      €rU   ú
<dictcomp>z9GenerationMixin._prepare_model_inputs.<locals>.<dictcomp>  s/   ø€ ÐbÐbÐb¡  AÀÀÐRSÐWaÒRaÐRa˜˜1ÐRaÐRaÐRarT   Nz
`inputs`: z` were passed alongside z0 which is not allowed. Make sure to either pass z or z=...Ú	input_idsÚinputs_embedszAYou passed `inputs_embeds` to `.generate()`, but the model class z² doesn't have its forwarding implemented. See the GPT2 implementation for an example (https://github.com/huggingface/transformers/pull/21405), and feel free to open a PR with it!)r�   zMYou passed `inputs_embeds` and `input_ids` to `.generate()`. Please pick one.)ÚconfigÚis_encoder_decoderÚhasattrr“   Úmain_input_nameÚitemsÚpopÚ
ValueErrorÚsetÚinspectÚ	signaturer�   Ú
parametersÚkeysÚ	__class__rK   Ú*_maybe_initialize_input_ids_for_generation)rŠ   rŽ   r�   r�   Úinputs_kwargÚhas_inputs_embeds_forwardingr™   s         @rU   Ú_prepare_model_inputsz%GenerationMixin._prepare_model_inputs  s  ø€ ð ŒKÔ*ð	.å˜˜iÑ(Ô(ð	.ð ”Ô,°Ô0DÒDÐDàœÔ5ˆJˆJàÔ-ˆJàbÐbÐbÐb¨×);Ò);Ñ)=Ô)=ÐbÑbÔbˆð $×'Ò'¨
°DÑ9Ô9ˆØÐ#¨Ð(:ÝðI˜Vð Ið I¸Zð Ið IØ,2ðIð IØ8BðIð Ið Iñô ð ð Ð%Ø!ˆFð ˜Ò$Ð$¨¸LÐ)HÐ)HØ”;Ô1ð vØ/>Å#ÝÔ% dÔ&HÑIÔIÔT×YÒYÑ[Ô[ñCô Cð 0Ð,ð 4ð Ý$ðxÐ\`Ô\jÔ\sð xð xð xñô ð ð -1×,[Ò,[Ø˜L°|ð -\ñ -ô -�˜[Ñ)Ð)ð Ð%Ý$Ð%tÑuÔuÐuØ!-¨oÔ!>ÀÐˆF�Jð ×@Ò@ÀÈÐWcÑdÔdˆØ�z <Ð/Ð/rT   c                 óà  — |�|S |                      d¦  «        }| j        j        rL|�J|j                             ¦   «         dd…         }t          j        |t
          j        | j        ¬¦  «        dz  S |€t          d¦  «        ‚d}| 
                    ¦   «         D ]+}t          |t
          j        ¦  «        r|j        d         } nŒ,t          j        |dft
          j        | j        ¬¦  «        |z  S )	z3Initializes input ids for generation, if necessary.NÚencoder_outputséÿÿÿÿ©ÚdtypeÚdeviceiœÿÿÿzB`bos_token_id` has to be defined when no `input_ids` are provided.r   r   )Úgetr�   rž   Úlast_hidden_stateÚsizerO   ÚonesÚlongr³   r£   ÚvaluesÚ
isinstanceÚTensorÚshape)rŠ   rŽ   r�   r�   r¯   r¼   Ú
batch_sizeÚvalues           rU   rª   z:GenerationMixin._maybe_initialize_input_ids_for_generationH  sú   € ð ÐØˆMà&×*Ò*Ð+<Ñ=Ô=ˆØŒ;Ô)ð 	R¨oÐ.Ià#Ô5×:Ò:Ñ<Ô<¸S¸b¸SÔAˆEÝ”:˜e­5¬:¸d¼kÐJÑJÔJÈTÑQÐQàÐÝÐaÑbÔbÐbð ˆ
Ø!×(Ò(Ñ*Ô*ð 	ð 	ˆEÝ˜%¥¤Ñ.Ô.ð Ø"œ[¨œ^�
Ø�ðõ Œz˜: q˜/µ´ÀDÄKÐPÑPÔPÐS_Ñ_Ð_rT   Úpad_token_idÚeos_token_idc                 ó€  — t          |j        ¦  «        dk    o|j        t          j        t          j        fv }|d uo||v }t          |t          ¦  «        r|g}|d u p||v}|r+|r)|r'|                     |¦  «                             ¦   «         S t          j        |j        d d…         t          j        |j	        ¬¦  «        S )Nr   r±   )
Úlenr¼   r²   rO   Úintr¸   rº   Úner·   r³   )rŠ   rŽ   r¿   rÀ   Úis_input_idsÚis_pad_token_in_inputsÚ&is_pad_token_not_equal_to_eos_token_ids          rU   Ú&_prepare_attention_mask_for_generationz6GenerationMixin._prepare_attention_mask_for_generationd  sÓ   € õ ˜6œ<Ñ(Ô(¨AÒ-ÐY°&´,Å5Ä9ÍeÌjÐBYÐ2YˆØ".°dÐ":Ð!XÀÐQWÐAWÐÝ�l¥CÑ(Ô(ð 	*Ø(˜>ˆLØ2>À$Ð2FÐ1mÈLÐ`lÐLlÐ.ð ð 	XÐ2ð 	XÐ7]ð 	XØ—9’9˜\Ñ*Ô*×/Ò/Ñ1Ô1Ð1å”:˜fœl¨2¨A¨2Ô.µe´jÈÌÐWÑWÔWÐWrT   Úinputs_tensorÚmodel_input_namec                 óú  ‡‡— |                       ¦   «         }t          | d¦  «        r;t          |d¦  «        rd|j        _        nt	          |t          d¬¦  «        ¦  «         g d¢Šˆfd„|                     ¦   «         D ¦   «         }t          t          j	        |j
        ¦  «        j        ¦  «        Šd‰v pd‰v }|s ˆfd	„|                     ¦   «         D ¦   «         }|�|n| j        }d|d
<   |||<    |di |¤Ž|d<   |S )NÚhf_device_mapÚ_hf_hookT)Úio_same_device)Údecoder_Ú
cross_attnÚ	use_cachec                 óT   •‡— i | ]#\  Š}t          ˆfd „‰D ¦   «         ¦  «        ° ‰|“Œ$S )c              3   óB   •K  — | ]}‰                      |¦  «        V — Œd S r•   )Ú
startswith)r–   ÚpÚarguments     €rU   ú	<genexpr>z\GenerationMixin._prepare_encoder_decoder_kwargs_for_generation.<locals>.<dictcomp>.<genexpr>ˆ  s1   øè è € ÐIÐI°!�x×*Ò*¨1Ñ-Ô-ÐIÐIÐIÐIÐIÐIrT   ©Úany)r–   r¾   rÖ   Úirrelevant_prefixs     @€rU   rš   zRGenerationMixin._prepare_encoder_decoder_kwargs_for_generation.<locals>.<dictcomp>…  sT   øø€ ð 
ð 
ð 
á�˜%ÝÐIÐIÐIÐIÐ7HÐIÑIÔIÑIÔIð
Ø�eð
ð 
ð 
rT   rŒ   r�   c                 ó$   •— i | ]\  }}|‰v ¯	||“ŒS rS   rS   )r–   rÖ   r¾   Úencoder_signatures      €rU   rš   zRGenerationMixin._prepare_encoder_decoder_kwargs_for_generation.<locals>.<dictcomp>�  s2   ø€ ð ð ð Ù$3 H¨eÐQYÐ]nÐQnÐQn�˜%ÐQnÐQnÐQnrT   Úreturn_dictr¯   rS   )Úget_encoderrŸ   rÍ   rÎ   rC   rB   r¡   r¤   r¥   r¦   Úforwardr§   r    )	rŠ   rÉ   r�   rÊ   r“   Úencoder_kwargsÚencoder_accepts_wildcardrÜ   rÚ   s	          @@rU   Ú._prepare_encoder_decoder_kwargs_for_generationz>GenerationMixin._prepare_encoder_decoder_kwargs_for_generationv  sm  øø€ ð ×"Ò"Ñ$Ô$ˆõ �4˜Ñ)Ô)ð 	SÝ�w 
Ñ+Ô+ð SØ26�Ô Ô/Ð/å" 7Õ,<ÈDÐ,QÑ,QÔ,QÑRÔRÐRð DÐCÐCÐð
ð 
ð 
ð 
à#/×#5Ò#5Ñ#7Ô#7ð
ñ 
ô 
ˆõ
  ¥Ô 1°'´/Ñ BÔ BÔ MÑNÔNÐØ#+Ð/@Ð#@Ð#gÀNÐVgÐDgÐ Ø'ð 	ðð ð ð Ø7E×7KÒ7KÑ7MÔ7Mðñ ô ˆNð
 0@Ð/KÐ+Ð+ÐQUÔQeÐØ(,ˆ�}Ñ%Ø+8ˆÐ'Ñ(Ø7>°wÐ7PÐ7PÀÐ7PÐ7PˆÐ&Ñ'àÐrT   r½   Údecoder_start_token_idr³   c                 ó˜  — |�d|v r|                      d¦  «        }n"d|v r|dk    r|                      d¦  «        }nd}|                      ||¦  «        }|€| j        }t          j        |dft          j        |¬¦  «        |z  }|€|}n¿| j        j        dk    rd| j         	                    ¦   «         v rn“|dd…df         |k     
                    ¦   «                              ¦   «         r_t          j        ||gd	¬
¦  «        }d|v rC|d         }	t          j        t          j        |	¦  «        dd…dd…f         |	fd	¬
¦  «        }	|	|d<   ||fS )zGPrepares `decoder_input_ids` for generation with encoder-decoder modelsNÚdecoder_input_idsr›   r   r±   zvision-encoder-decoderÚdonutr   r°   ©ÚdimÚdecoder_attention_mask)r¢   Ú_get_decoder_start_token_idr³   rO   r·   r¸   r�   Ú
model_typeÚname_or_pathÚlowerÚallÚitemÚcatÚ	ones_like)
rŠ   r½   rÊ   r�   rã   r�   r³   rå   Údecoder_input_ids_startré   s
             rU   Ú)_prepare_decoder_input_ids_for_generationz9GenerationMixin._prepare_decoder_input_ids_for_generation™  sª  € ð Ð#Ð(;¸|Ð(KÐ(KØ ,× 0Ò 0Ð1DÑ EÔ EÐÐØ˜LÐ(Ð(Ð-=ÀÒ-LÐ-LØ ,× 0Ò 0°Ñ =Ô =ÐÐà $Ðð "&×!AÒ!AÐBXÐZfÑ!gÔ!gÐØˆ>Ø”[ˆFÝ"'¤*¨j¸!¨_ÅEÄJÐW]Ð"^Ñ"^Ô"^ÐawÑ"wÐð Ð$Ø 7ÐÐàŒ[Ô#Ð'?Ò?Ð?ÀGÈtÔO`×OfÒOfÑOhÔOhÐDhÐDhØð      1 Ô%Ð)?Ò?×DÒDÑFÔF×KÒKÑMÔMð 	PÝ %¤	Ð+BÐDUÐ*VÐ\^Ð _Ñ _Ô _ÐØ'¨<Ð7Ð7Ø)5Ð6NÔ)OÐ&Ý).¬Ý”_Ð%;Ñ<Ô<¸Q¸Q¸QÀÀÀ¸UÔCÐE[Ð\Øð*ñ *ô *Ð&ð :P�Ð5Ñ6à  ,Ð.Ð.rT   c                 óp   — |�|n| j         j        }|�|n| j         j        }|�|S |�|S t          d¦  «        ‚)Nz\`decoder_start_token_id` or `bos_token_id` has to be defined for encoder-decoder generation.)Úgeneration_configrã   r�   r£   )rŠ   rã   r�   s      rU   rê   z+GenerationMixin._get_decoder_start_token_idÆ  sc   € ð &Ð1ð #Ð"àÔ'Ô>ð 	ð
 (4Ð'?�|�|ÀTÔE[ÔEhˆà!Ð-Ø)Ð)ØÐ%ØÐÝØjñ
ô 
ð 	
rT   r   FÚexpand_sizerž   r›   c                 óÒ   ‡ — ˆ fd„}|�|                      ‰ d¬¦  «        } ||¦  «        }|r8|                     d¦  «        €t          d¦  «        ‚ ||d         ¦  «        |d<   ||fS )zIExpands tensors from [batch_size, ...] to [batch_size * expand_size, ...]c                 ó¢   •— | D ]J}| |         �@t          | |         t          j        ¦  «        r | |                              ‰d¬¦  «        | |<   ŒK| S )Nr   rç   )rº   rO   r»   Úrepeat_interleave)Údict_to_expandÚkeyrö   s     €rU   Ú_expand_dict_for_generationzRGenerationMixin._expand_inputs_for_generation.<locals>._expand_dict_for_generationß  sc   ø€ Ø%ð dð d�Ø! #Ô&Ð2µzÀ.ÐQTÔBUÕW\ÔWcÑ7dÔ7dÐ2Ø*8¸Ô*=×*OÒ*OÐP[ÐabÐ*OÑ*cÔ*c�N 3Ñ'øØ!Ð!rT   Nr   rç   r¯   zMIf `is_encoder_decoder` is True, make sure that `encoder_outputs` is defined.)rù   r´   r£   )rö   rž   r›   r�   rü   s   `    rU   Ú_expand_inputs_for_generationz-GenerationMixin._expand_inputs_for_generationÖ  s    ø€ ð	"ð 	"ð 	"ð 	"ð 	"ð Ð Ø!×3Ò3°KÀQÐ3ÑGÔGˆIà2Ð2°<Ñ@Ô@ˆàð 	kØ×ÒÐ 1Ñ2Ô2Ð:Ý Ð!pÑqÔqÐqØ.IÐ.IÈ,ÐWhÔJiÑ.jÔ.jˆLÐ*Ñ+à˜,Ð&Ð&rT   ÚoutputsÚstandardize_cache_formatc                 óÆ   — d }d|v r|j         }nd|v r|j        }nd|v r|j        }|r9t          | d¦  «        r)|j        j        d         }|                      ||¬¦  «        }|S )NÚpast_key_valuesÚmemsÚpast_buckets_statesÚ_convert_to_standard_cacher   )r½   )r  r  r  rŸ   Úlogitsr¼   r  )rŠ   rþ   rÿ   r  r½   s        rU   Ú_extract_past_from_model_outputz/GenerationMixin._extract_past_from_model_outputñ  s�   € ØˆØ Ð'Ð'Ø%Ô5ˆOˆOØ�wÐÐØ%œlˆOˆOØ" gÐ-Ð-Ø%Ô9ˆOð $ð 	f­°Ð6RÑ(SÔ(Sð 	fØ œÔ-¨aÔ0ˆJØ"×=Ò=¸oÐZdÐ=ÑeÔeˆOØÐrT   c                 ó  — |                       ||¬¦  «        |d<   t          |dd ¦  «        �
|j        |d<   d|v r@|d         }t          j        ||d d …df                              d¦  «        gd¬¦  «        |d<   |sHd|v rC|d         }t          j        ||                     |j        d         d	f¦  «        gd¬¦  «        |d<   nGd
|v rC|d
         }t          j        ||                     |j        d         d	f¦  «        gd¬¦  «        |d
<   |S )N©rÿ   r  ÚstateÚtoken_type_idsr°   rç   Úattention_maskr   r   ré   )r  Úgetattrr	  rO   rð   Ú	unsqueezeÚnew_onesr¼   )rŠ   rþ   r�   rž   rÿ   r
  r  ré   s           rU   Ú#_update_model_kwargs_for_generationz3GenerationMixin._update_model_kwargs_for_generation   sn  € ð +/×*NÒ*NØÐ.Fð +Oñ +
ô +
ˆÐ&Ñ'õ �7˜G TÑ*Ô*Ð6Ø$+¤MˆL˜Ñ!ð ˜|Ð+Ð+Ø)Ð*:Ô;ˆNÝ-2¬Y¸ÈÐWXÐWXÐWXÐZ\ÐW\ÔH]×HgÒHgÐhjÑHkÔHkÐ7lÐrtÐ-uÑ-uÔ-uˆLÐ)Ñ*à!ð 	à <Ð/Ð/Ø!-Ð.>Ô!?�Ý16´Ø# ^×%<Ò%<¸nÔ>RÐSTÔ>UÐWXÐ=YÑ%ZÔ%ZÐ[Ðacð2ñ 2ô 2�Ð-Ñ.øð
 (¨<Ð7Ð7Ø)5Ð6NÔ)OÐ&Ý9>¼Ø+Ð-C×-LÒ-LÐNdÔNjÐklÔNmÐopÐMqÑ-rÔ-rÐsØð:ñ :ô :�Ð5Ñ6ð
 ÐrT   c                 óJ   — t          d| j        j        › d| j        › �¦  «        ‚)NzGMake sure that a `_reorder_cache` function is correctly implemented in z to enable beam search for )r‰   r©   rL   )rŠ   r  Úbeam_idxs      rU   Ú_reorder_cachezGenerationMixin._reorder_cache%  s;   € Ý!ð8ÐVZÔVdÔVoð 8ð 8Ø'+¤~ð8ð 8ñ
ô 
ð 	
rT   rõ   c                 óâ  — t          ¦   «         }|j        dk    r5t          |j        t          ¦  «        rt          |j        ¦  «        dz   }nd}nd}|j        �2|j        dk    r'|                     t          |j        ¦  «        ¦  «         |j	        �4|j	        dk    r)|                     t          |j	        |¬¦  «        ¦  «         |j        �4|j        dk     r)|                     t          |j        |¬¦  «        ¦  «         |j        �4|j        dk     r)|                     t          |j        |¬¦  «        ¦  «         |j        �>d	|j        cxk     rdk     r,n n)|                     t!          |j        |¬
¦  «        ¦  «         |j        �>d	|j        cxk     rdk     r,n n)|                     t%          |j        |¬
¦  «        ¦  «         |j        du r!|                     t)          ¦   «         ¦  «         |S )z§
        This class returns a [`LogitsProcessorList`] list object that contains all relevant [`LogitsWarper`] instances
        used for multinomial sampling.
        r   r   Nç      ð?r   )Útop_kÚmin_tokens_to_keep)Útop_pr  )Úmassr  ç        )Úepsilonr  T)r,   Ú	num_beamsrº   rÀ   ÚlistrÂ   ÚtemperatureÚappendr6   r  r7   r  r8   Ú	typical_pr9   Úepsilon_cutoffr#   Ú
eta_cutoffr$   Úrenormalize_logitsr+   )rŠ   rõ   Úwarpersr  s       rU   Ú_get_logits_warperz"GenerationMixin._get_logits_warper+  s8  € õ &Ñ'Ô'ˆð Ô&¨Ò*Ð*ÝÐ+Ô8½$Ñ?Ô?ð 'Ý%(Ð):Ô)GÑ%HÔ%HÈ1Ñ%LÐ"Ð"à%&Ð"Ð"à!"Ðð Ô(Ð4Ð9JÔ9VÐZ]Ò9]Ð9]Ø�NŠNÕ2Ð3DÔ3PÑQÔQÑRÔRÐRØÔ"Ð.Ð3DÔ3JÈaÒ3OÐ3OØ�NŠNÕ+Ð2CÔ2IÐ^pÐqÑqÔqÑrÔrÐrØÔ"Ð.Ð3DÔ3JÈSÒ3PÐ3PØ�NŠNÕ+Ð2CÔ2IÐ^pÐqÑqÔqÑrÔrÐrØÔ&Ð2Ð7HÔ7RÐUXÒ7XÐ7XØ�NŠNÝ#Ð):Ô)DÐYkÐlÑlÔlñô ð ð Ô+Ð7¸CÐBSÔBbÐ<hÐ<hÒ<hÐ<hÐehÒ<hÐ<hÐ<hÐ<hÐ<hØ�NŠNÝ#Ð,=Ô,LÐasÐtÑtÔtñô ð ð Ô'Ð3¸Ð>OÔ>ZÐ8`Ð8`Ò8`Ð8`Ð]`Ò8`Ð8`Ð8`Ð8`Ð8`Ø�NŠNÝÐ(9Ô(DÐYkÐlÑlÔlñô ð ð Ô/°4Ð7Ð7Ø�NŠNÕ-Ñ/Ô/Ñ0Ô0Ð0ØˆrT   Úassistant_modelr@   c                 ó²  — |j         €|j        �t          j        }n™|j        dk    rT|j        du r>|j        �*|j        dk    r|j        �|j        dk    rt          j        }nTt          j	        }nGt          j
        }n:|j        dk    rt          j        }n"|j        du rt          j        }nt          j        }|� |dv rt          j        }nt!          d¦  «        ‚|S )z[
        Returns the generation mode triggered by a [`GenerationConfig`] instance.
        Nr   Fr   T)rw   rx   z�You've set `assistant_model`, which triggers assisted generate. Currently, assisted generate is only supported with Greedy Search and Sample.)ÚconstraintsÚforce_words_idsru   r„   r  Ú	do_sampler  Úpenalty_alphar~   r   r€   Únum_beam_groupsr…   rƒ   r‚   r�   r£   )rŠ   rõ   r%  Úgeneration_modes       rU   Ú_get_generation_modez$GenerationMixin._get_generation_modeZ  sþ   € ð Ô(Ð4Ð8IÔ8YÐ8eÝ,ÔDˆOˆOØÔ(¨AÒ-Ð-Ø Ô*¨eÐ3Ð3à%Ô+Ð7Ø)Ô/°!Ò3Ð3Ø)Ô7ÐCØ)Ô7¸!Ò;Ð;å&4Ô&G�O�Oå&4Ô&B�O�Oå"0Ô"7��à Ô0°1Ò4Ð4Ý"0Ô"B��Ø"Ô,°Ð4Ð4Ý"0Ô"<��å"0Ô"<�ð Ð&ØÐ"=Ð=Ð=Ý"0Ô"D��å ðGñô ð ð ÐrT   Úinput_ids_seq_lengthÚencoder_input_idsÚprefix_allowed_tokens_fnÚlogits_processorÚnegative_prompt_idsÚnegative_prompt_attention_maskc	           
      ó 	  — t          ¦   «         }	|j        �=|j        dk    r2|	                     t          |j        | |||d         ¬¦  «        ¦  «         |j        �(|	                     t          |j        ¬¦  «        ¦  «         |j        �?|j        dk    r4|	                     t          |j        |j        |j	        ¬¦  «        ¦  «         |j
        �4|j
        dk    r)|	                     t          |j
        |¬	¦  «        ¦  «         |j        �3|j        dk    r(|	                     t          |j        ¬
¦  «        ¦  «         |j        �2|j        dk    r'|	                     t          |j        ¦  «        ¦  «         |j        �O|j        dk    rD| j        j        r)|	                     t'          |j        |¦  «        ¦  «         nt)          d¦  «        ‚|j        �-|	                     t-          |j        |j        ¦  «        ¦  «         |j        �?|j        �8|j        dk    r-|	                     t3          |j        |j        ¦  «        ¦  «         |j        �@|j        �9|j        dk    r.|	                     t7          ||j        |j        ¦  «        ¦  «         |�0|	                     t9          ||j        |j	        z  ¦  «        ¦  «         |j        �'|	                     t=          |j        ¦  «        ¦  «         |j        �-|	                     tA          |j!        |j        ¦  «        ¦  «         |j"        du r!|	                     tG          ¦   «         ¦  «         |j$        �.|	                     tK          |j$        |j        |¦  «        ¦  «         |j&        �'|	                     tO          |j&        ¦  «        ¦  «         |j(        �[|}
|dk    s|j        €|
n|
dz   }
|j)        �|
|j)        d         d         z  }
|	                     tU          |j(        |
¦  «        ¦  «         |j)        �'|	                     tW          |j)        ¦  «        ¦  «         |  ,                    |	|¦  «        }	|j-        du r!|	                     t]          ¦   «         ¦  «         |	S )zÁ
        This class returns a [`LogitsProcessorList`] list object that contains all relevant [`LogitsProcessor`]
        instances used to modify the scores of the language model head.
        Nr   rÑ   )Úunconditional_idsÚunconditional_attention_maskrÑ   )Úsequence_biasr  )Údiversity_penaltyr  r+  r  )Úpenaltyr/  )r9  r   zTIt's impossible to use `encoder_no_repeat_ngram_size` with decoder-only architectureTr°   )/r,   Úguidance_scaler  r:   r7  r3   r8  r)   r  r+  Úencoder_repetition_penaltyr"   Úrepetition_penaltyr2   Úno_repeat_ngram_sizer0   Úencoder_no_repeat_ngram_sizer�   rž   r!   r£   Úbad_words_idsr/   rÀ   Ú
min_lengthr-   Úmin_new_tokensr.   r1   Úforced_bos_token_idr&   Úforced_eos_token_idr'   Ú
max_lengthÚremove_invalid_valuesr*   Ú exponential_decay_length_penaltyr%   Úsuppress_tokensr5   Úbegin_suppress_tokensÚforced_decoder_idsr4   r(   Ú_merge_criteria_processor_listr"  r+   )rŠ   rõ   r.  r/  r0  r1  r�   r2  r3  Ú
processorsÚbegin_indexs              rU   Ú_get_logits_processorz%GenerationMixin._get_logits_processor‚  s  € õ  )Ñ*Ô*ˆ
àÔ+Ð7Ð<MÔ<\Ð`aÒ<aÐ<aØ×ÒÝ>Ø%Ô4ØØ&9Ø1OØ*¨;Ô7ðñ ô ñô ð ð Ô*Ð6Ø×ÒÕ9ÐHYÔHgÐhÑhÔhÑiÔiÐiàÔ.Ð:Ð?PÔ?bÐehÒ?hÐ?hØ×ÒÝ/Ø&7Ô&IØ/Ô9Ø$5Ô$Eðñ ô ñô ð ð Ô8ÐDØ!Ô<ÀÒCÐCà×ÒÝ7Ø-ÔHÐ\mðñ ô ñô ð ð
 Ô/Ð;Ð@QÔ@dÐhkÒ@kÐ@kØ×ÒÕ>ÐGXÔGkÐlÑlÔlÑmÔmÐmØÔ1Ð=ÐBSÔBhÐklÒBlÐBlØ×ÒÕ:Ð;LÔ;aÑbÔbÑcÔcÐcàÔ:ÐFØ!Ô>ÀÒBÐBàŒ{Ô-ð 	Ø×!Ò!Ý7Ø)ÔFÐHYñô ñô ð ð õ !Øjñô ð ð Ô*Ð6Ø×ÒÝ)Ð*;Ô*IÐK\ÔKiÑjÔjñô ð ð Ô(Ð4Ø!Ô.Ð:Ø!Ô,¨qÒ0Ð0à×ÒÕ6Ð7HÔ7SÐUfÔUsÑtÔtÑuÔuÐuàÔ,Ð8Ø!Ô.Ð:Ø!Ô0°1Ò4Ð4à×ÒÝ1Ø(Ð*;Ô*JÐL]ÔLjñô ñô ð ð
 $Ð/Ø×ÒÝ0Ø,Ð.?Ô.IÐM^ÔMnÑ.nñô ñô ð ð
 Ô0Ð<Ø×ÒÕ;Ð<MÔ<aÑbÔbÑcÔcÐcØÔ0Ð<Ø×ÒÝ-Ð.?Ô.JÐL]ÔLqÑrÔrñô ð ð Ô2°dÐ:Ð:Ø×ÒÕ9Ñ;Ô;Ñ<Ô<Ð<ØÔ=ÐIØ×ÒÝ-Ø%ÔFØ%Ô2Ø(ñô ñô ð ð Ô,Ð8Ø×ÒÕ;Ð<MÔ<]Ñ^Ô^Ñ_Ô_Ð_ØÔ2Ð>Ø.ˆKð )¨1Ò,Ð,Ð0AÔ0UÐ0]ð �à  1‘_ð ð
 !Ô3Ð?àÐ0ÔCÀBÔGÈÔJÑJ�Ø×ÒÝ4Ð5FÔ5\Ð^iÑjÔjñô ð ð Ô/Ð;Ø×ÒÕ8Ð9JÔ9]Ñ^Ô^Ñ_Ô_Ð_Ø×8Ò8¸ÐEUÑVÔVˆ
àÔ/°4Ð7Ð7Ø×ÒÕ0Ñ2Ô2Ñ3Ô3Ð3ØÐrT   Ústopping_criteriac                 ó8  — t          ¦   «         }|j        �?t          | j        dd ¦  «        }|                     t          |j        |¬¦  «        ¦  «         |j        �(|                     t          |j        ¬¦  «        ¦  «         |                      ||¦  «        }|S )NÚmax_position_embeddings)rD  rP  )Úmax_time)	r>   rD  r  r�   r  r;   rQ  r<   rJ  )rŠ   rõ   rN  ÚcriteriarP  s        rU   Ú_get_stopping_criteriaz&GenerationMixin._get_stopping_criteria  s¦   € õ (Ñ)Ô)ˆØÔ'Ð3Ý&-¨d¬kÐ;TÐVZÑ&[Ô&[Ð#Ø�OŠOÝ!Ø0Ô;Ø,Cðñ ô ñô ð ð Ô%Ð1Ø�OŠO�OÐ5FÔ5OÐPÑPÔPÑQÔQÐQØ×6Ò6°xÐARÑSÔSˆØˆrT   Údefault_listÚcustom_listc                 ó@  — t          |¦  «        dk    r|S |D ]p}|D ]k}t          |¦  «        t          |¦  «        u rKt          |t          ¦  «        rdnd}t	          d|› dt          |¦  «        › d|› d|› d|› d	|› d
|› d�¦  «        ‚ŒlŒq|                     |¦  «         |S )Nr   zstopping criteriazlogits processorz	A custom z	 of type z with values zS has been passed to `.generate()`, but it has already been created with the values z. zŸ has been created by passing the corresponding arguments to generate or by the model's config default values. If you just want to change the default values of zO consider passing them as arguments to `.generate()` instead of using a custom ú.)rÂ   Útyperº   r=   r£   Úextend)rŠ   rT  rU  ÚdefaultÚcustomÚobject_types         rU   rJ  z.GenerationMixin._merge_criteria_processor_list  s'  € õ
 ˆ{ÑÔ˜qÒ Ð ØÐØ#ð 
	ð 
	ˆGØ%ð 	ð 	�Ý˜‘<”<¥4¨¡=¤=Ð0Ð0Ý9CÀFÕL\Ñ9]Ô9]Ð"uÐ"5Ð"5Ðcu�KÝ$ðh Kð hð h½$¸v¹,¼,ð hð hÐU[ð hð hØ[bðhð hØfmðhð hð Vaðhð hð Zeð	hð hð hñô ð ð 1ð	ð 	×Ò˜KÑ(Ô(Ð(ØÐrT   rF   rG   rj   Únormalize_logitsc                 óî  — |€tt          j        |d         j        d         ¦  «                             dd¦  «                             |j        ¦  «        }|                     dt          |¦  «        ¦  «        }t          j        |¦  «         	                    t          |¦  «        d¦  «         
                    dd¦  «        }|rs| 	                    d| j        j        |j        d         ¦  «        }t           j        j                             |d¬¦  «        }| 	                    d|j        d         ¦  «        }|dk     }d|                     ¦   «         z
                       d¦  «                             ¦   «         }|                     ¦   «         dd…d|…f         }|dd…d|…f         }d||<   || j        j        z  }|j        d         |z
  }|dd…|d…f         |z   }	|                     d|	¦  «        }
d|
|<   |
S )a"  
        Computes the transition scores of sequences given the generation scores (and beam indices, if beam search was
        used). This is a convenient method to quicky obtain the scores of the selected tokens at generation time.

        Parameters:
            sequences (`torch.LongTensor`):
                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`.
            scores (`tuple(torch.FloatTensor)`):
                Transition scores for each vocabulary token at each generation step. Beam transition scores consisting
                of log probabilities of tokens conditioned on log softmax of previously generated tokens Tuple of
                `torch.FloatTensor` with up to `max_new_tokens` elements (one element for each generated token), with
                each tensor of shape `(batch_size*num_beams, config.vocab_size)`.
            beam_indices (`torch.LongTensor`, *optional*):
                Beam indices of generated token id at each generation step. `torch.LongTensor` of shape
                `(batch_size*num_return_sequences, sequence_length)`. Only required if a `num_beams>1` at
                generate-time.
            normalize_logits (`bool`, *optional*, defaults to `False`):
                Whether to normalize the logits (which, for legacy reasons, may be unnormalized).

        Return:
            `torch.Tensor`: A `torch.Tensor` of shape `(batch_size*num_return_sequences, sequence_length)` containing
                the transition scores (logits)

        Examples:

        ```python
        >>> from transformers import GPT2Tokenizer, AutoModelForCausalLM
        >>> import numpy as np

        >>> tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
        >>> model = AutoModelForCausalLM.from_pretrained("gpt2")
        >>> tokenizer.pad_token_id = tokenizer.eos_token_id
        >>> inputs = tokenizer(["Today is"], return_tensors="pt")

        >>> # Example 1: Print the scores for each token generated with Greedy Search
        >>> outputs = model.generate(**inputs, max_new_tokens=5, return_dict_in_generate=True, output_scores=True)
        >>> transition_scores = model.compute_transition_scores(
        ...     outputs.sequences, outputs.scores, normalize_logits=True
        ... )
        >>> # input_length is the length of the input prompt for decoder-only models, like the GPT family, and 1 for
        >>> # encoder-decoder models, like BART or T5.
        >>> input_length = 1 if model.config.is_encoder_decoder else inputs.input_ids.shape[1]
        >>> generated_tokens = outputs.sequences[:, input_length:]
        >>> for tok, score in zip(generated_tokens[0], transition_scores[0]):
        ...     # | token | token string | logits | probability
        ...     print(f"| {tok:5d} | {tokenizer.decode(tok):8s} | {score.numpy():.3f} | {np.exp(score.numpy()):.2%}")
        |   262 |  the     | -1.414 | 24.33%
        |  1110 |  day     | -2.609 | 7.36%
        |   618 |  when    | -2.010 | 13.40%
        |   356 |  we      | -1.859 | 15.58%
        |   460 |  can     | -2.508 | 8.14%

        >>> # Example 2: Reconstruct the sequence scores from Beam Search
        >>> outputs = model.generate(
        ...     **inputs,
        ...     max_new_tokens=5,
        ...     num_beams=4,
        ...     num_return_sequences=4,
        ...     return_dict_in_generate=True,
        ...     output_scores=True,
        ... )
        >>> transition_scores = model.compute_transition_scores(
        ...     outputs.sequences, outputs.scores, outputs.beam_indices, normalize_logits=False
        ... )
        >>> # If you sum the generated tokens' scores and apply the length penalty, you'll get the sequence scores.
        >>> # Tip: recomputing the scores is only guaranteed to match with `normalize_logits=False`. Depending on the
        >>> # use case, you might want to recompute it with `normalize_logits=True`.
        >>> output_length = input_length + np.sum(transition_scores.numpy() < 0, axis=1)
        >>> length_penalty = model.generation_config.length_penalty
        >>> reconstructed_scores = transition_scores.sum(axis=1) / (output_length**length_penalty)
        >>> print(np.allclose(outputs.sequences_scores, reconstructed_scores))
        True
        ```Nr   r°   r   rç   )rO   Úaranger¼   ÚviewÚtor³   ÚexpandrÂ   ÚstackÚreshapeÚ	transposer�   Ú
vocab_sizer   Ú
functionalÚlog_softmaxr¸   ÚsumÚmaxÚcloneÚgather)rŠ   rF   rG   rj   r]  Úbeam_indices_maskÚmax_beam_lengthÚbeam_sequence_indicesÚcut_idxÚindicesÚtransition_scoress              rU   Úcompute_transition_scoresz)GenerationMixin.compute_transition_scores+  sï  € ðf ÐÝ œ<¨¨q¬	¬¸Ô(:Ñ;Ô;×@Ò@ÀÀQÑGÔG×JÒJÈ9ÔK[Ñ\Ô\ˆLØ'×.Ò.¨rµ3°v±;´;Ñ?Ô?ˆLõ ”˜VÑ$Ô$×,Ò,­S°©[¬[¸"Ñ=Ô=×GÒGÈÈ1ÑMÔMˆð ð 	:Ø—^’^ B¨¬Ô(>ÀÄÈRÔ@PÑQÔQˆFÝ”XÔ(×4Ò4°VÀÐ4ÑCÔCˆFØ—^’^ B¨¬°RÔ(8Ñ9Ô9ˆFð )¨1Ò,ÐØÐ0×5Ò5Ñ7Ô7Ñ7×<Ò<¸RÑ@Ô@×DÒDÑFÔFˆØ#×)Ò)Ñ+Ô+¨A¨A¨AÐ/?°Ð/?Ð,?Ô@ˆØ-¨a¨a¨aÐ1A°/Ð1AÐ.AÔBÐð +,ˆÐ&Ñ'ð !-¨t¬{Ô/EÑ EÐð ”/ "Ô%¨Ñ7ˆØ˜A˜A˜A˜w˜x˜x˜KÔ(Ð+@Ñ@ˆð #ŸMšM¨!¨WÑ5Ô5Ðð 01ÐÐ+Ñ,à Ð rT   c                 óp  — |                       ¦   «         s¡t          t          t          t          t
          g}t          ¦   «         }|D ]G}|                     t          | j	        ¦  «        d¬¦  «        }|�| 
                    |j        ¦  «         ŒHd| j        j        › d�}|r|d|› �z  }t          |¦  «        ‚dS )z™
        Confirms that the model class is compatible with generation. If not, raises an exception that points to the
        right class to use.
        N)rZ  zThe current model class (zQ) is not compatible with `.generate()`, as it doesn't have a language model head.z2 Please use one of the following classes instead: )Úcan_generater   r   r   r   r   r¤   r´   rX  r�   ÚaddrK   r©   Ú	TypeError)rŠ   Úgenerate_compatible_mappingsÚgenerate_compatible_classesÚmodel_mappingÚsupported_modelsÚexception_messages         rU   Ú_validate_model_classz%GenerationMixin._validate_model_class¤  sè   € ð
 × Ò Ñ"Ô"ð 	/å+Ý7Ý.Ý6Ý2ð,Ð(õ +.©%¬%Ð'Ø!=ð Oð O�Ø#0×#4Ò#4µT¸$¼+Ñ5FÔ5FÐPTÐ#4Ñ#UÔ#UÐ Ø#Ð/Ø/×3Ò3Ð4DÔ4MÑNÔNÐNøð9¨D¬NÔ,Cð 9ð 9ð 9ð ð +ð xØ!Ð%wÐZuÐ%wÐ%wÑwÐ!ÝÐ-Ñ.Ô.Ð.ð'	/ð 	/rT   c                 óz  — | j         j        rdD ]}|                     |d¦  «         Œg }t          t	          j        | j        ¦  «        j        ¦  «        }d|v sd|v r.|t          t	          j        | j        ¦  «        j        ¦  «        z  }| j         j        rÚt          | | j
        d¦  «        }t          | dd¦  «        }|€|�t          |dd¦  «        }|�0t          t	          j        |j        ¦  «        j        ¦  «        }||z  }t          | dd¦  «        }|€|�t          |dd¦  «        }|�:t          t	          j        |j        ¦  «        j        ¦  «        }	|d„ |	D ¦   «         z  }d|v r|dhz  }|                     ¦   «         D ] \  }}
|
�||vr|                     |¦  «         Œ!|rt          d	|› d
�¦  «        ‚dS )zXValidates model kwargs for generation. Generate argument typos will also be caught here.)rå   NrŒ   r�   r“   Údecoderc                 ó   — h | ]}d |› �’ŒS )rÏ   rS   )r–   Úxs     rU   ú	<setcomp>z9GenerationMixin._validate_model_kwargs.<locals>.<setcomp>ã  s   € ÐJÐJÐJ°!˜~¨!˜~˜~ÐJÐJÐJrT   Úassistant_encoder_outputsz8The following `model_kwargs` are not used by the model: zG (note: typos in the generate arguments will also show up in this list))r�   rž   r¢   r¤   r¥   r¦   r�   r§   rß   r  Úbase_model_prefixr¡   r  r£   )rŠ   r�   rû   Úunused_model_argsÚ
model_argsÚ
base_modelr“   Úencoder_model_argsr  Údecoder_model_argsr¾   s              rU   Ú_validate_model_kwargsz&GenerationMixin._validate_model_kwargs¾  s"  € ð Œ;Ô)ð 	,Ø,ð ,ð ,�Ø× Ò   dÑ+Ô+Ð+Ð+àÐÝ�Ô*¨4Ô+MÑNÔNÔYÑZÔZˆ
ð �zÐ!Ð! ^°zÐ%AÐ%AØ�#�gÔ/°´Ñ=Ô=ÔHÑIÔIÑIˆJð Œ;Ô)ð 	<Ý   tÔ'=¸tÑDÔDˆJõ ˜d I¨tÑ4Ô4ˆGð ˆ :Ð#9Ý! *¨i¸Ñ>Ô>�àÐ"Ý%(­Ô):¸7¼?Ñ)KÔ)KÔ)VÑ%WÔ%WÐ"ØÐ0Ñ0�
õ ˜d I¨tÑ4Ô4ˆGØˆ :Ð#9Ý! *¨i¸Ñ>Ô>�àÐ"Ý%(­Ô):¸7¼?Ñ)KÔ)KÔ)VÑ%WÔ%WÐ"ØÐJÐJÐ7IÐJÑJÔJÑJ�
ð +¨lÐ:Ð:ØÐ:Ð;Ñ;�
à&×,Ò,Ñ.Ô.ð 	.ð 	.‰JˆC�ØÐ  S°
Ð%:Ð%:Ø!×(Ò(¨Ñ-Ô-Ð-øàð 	ÝðFÐK\ð Fð Fð Fñô ð ð	ð 	rT   c           	      óL  — |r5|j         €.|j        dk    r#t          j        d|j        › d�t          ¦  «         ||j        k    r9| j        j        rdnd}t          j        d|› d|› d	|j        › d
�t          ¦  «         d}|r|d|j        › d�z  }|j        �>|j        |j        k    r.t          j        d|j        › d|j        › d�|z   t          ¦  «         |j        �H|j        |z   }||j        k    r5t          j        d|j        › d|› d|j        › d�|z   t          ¦  «         dS dS dS )z=Performs validation related to the resulting generated lengthNé   z0Using the model-agnostic default `max_length` (=zz) to control the generation length. We recommend setting `max_new_tokens` to control the maximum length of the generation.rå   r›   zInput length of z is z, but `max_length` is set to zX. This can lead to unexpected behavior. You should consider increasing `max_new_tokens`.z Generation will stop at the defined maximum length. You should decrease the minimum length and/or increase the maximum length.z" Note that `max_length` is set to z, its default value.z-Unfeasible length constraints: `min_length` (z.) is larger than the maximum possible length (z).z1Unfeasible length constraints: `min_new_tokens` (z$), when added to the prompt length (z/), is larger than the maximum possible length ()	Úmax_new_tokensrD  ÚwarningsÚwarnÚUserWarningr�   rž   r@  rA  )rŠ   rõ   Úinput_ids_lengthÚhas_default_max_lengthÚinput_ids_stringÚmin_length_error_suffixr@  s          rU   Ú_validate_generated_lengthz*GenerationMixin._validate_generated_lengthó  s  € ð "ð 	Ð&7Ô&FÐ&NÐSdÔSoÐsuÒSuÐSuåŒMðÐCTÔC_ð ð ð õ ñ	ô ð ð Ð0Ô;Ò;Ð;Ø6:´kÔ6TÐeÐ2Ð2ÐZeÐÝŒMð0Ð#3ð 0ð 0Ð9Ið 0ð 0Ø%Ô0ð0ð 0ð 0õ ñ	ô ð ð+ð 	 ð "ð 	Ø#ØgÐ5FÔ5QÐgÐgÐgñÐ#ð Ô'Ð3Ð8IÔ8TÐWhÔWsÒ8sÐ8sÝŒMðRÐ@QÔ@\ð Rð RØ1BÔ1MðRð Rð RØTkñlåñô ð ð
 Ô+Ð7Ø*Ô9Ð<LÑLˆJØÐ-Ô8Ò8Ð8Ý”ðVÐHYÔHhð Vð VØ3CðVð Và5FÔ5QðVð Vð VàXoñpõ  ñ	ô ð ð ð ð 8Ð7à8Ð8rT   Únew_mask_lengthc                 ó  — | j         j        rd}nd}||vr|S ||         }||j        d         z
  }|dk     rt          d¦  «        ‚t	          j        ||                     |j        d         |f¦  «        gd¬¦  «        ||<   |S )Nré   r  r   r   z@Cannot extend attention mask to a length less than it already isr°   rç   )r�   rž   r¼   r£   rO   rð   r  )rŠ   r�   r–  rû   ÚmaskÚmask_extension_lengths         rU   Ú_extend_attention_maskz&GenerationMixin._extend_attention_mask!  s§   € ØŒ;Ô)ð 	#Ø*ˆCˆCà"ˆCà�lÐ"Ð"ØÐà˜CÔ ˆØ /°$´*¸Q´-Ñ ?Ðà  1Ò$Ð$ÝÐ_Ñ`Ô`Ð`å!œIØ�4—=’= $¤*¨Q¤-Ð1FÐ!GÑHÔHÐIØð
ñ 
ô 
ˆ�SÑð
 ÐrT   Ú
new_lengthc                 óþ   — d|vs|d         €|S |d         }|d d …df                               d¦  «        }||j        d         z
  }|                     d|¦  «        }t          j        |d         |gd¬¦  «        |d<   |S )Nr
  r°   r   rç   )r  r¼   ÚrepeatrO   rð   )rŠ   r�   r›  r
  Úfinal_token_typeÚextension_lengthÚtoken_type_copiess          rU   Ú_extend_token_type_idsz&GenerationMixin._extend_token_type_ids7  sª   € Ø <Ð/Ð/°<Ð@PÔ3QÐ3YØÐà%Ð&6Ô7ˆØ)¨!¨!¨!¨R¨%Ô0×:Ò:¸2Ñ>Ô>ÐØ%¨Ô(<¸QÔ(?Ñ?ÐØ,×3Ò3°AÐ7GÑHÔHÐÝ).¬ØÐ*Ô+Ð->Ð?Øð*
ñ *
ô *
ˆÐ%Ñ&ð
 ÐrT   Úsynced_gpusÚstreamerrA   c                 óø  ‡— |€*t          ¦   «         rt          j        ¦   «         dk    rd}nd}|                      ¦   «          ‰€t| j        j        ra| j        j        t          | j        ¦  «        k    r?t          j	        | j
        ¦  «        }|| j        k    rt          j        d¦  «         || _        | j        Št          j        ‰¦  «        Š ‰j        d5i |¤Ž}‰                     ¦   «          |                      |                     ¦   «         ¦  «         |�|nt%          ¦   «         }|�|nt'          ¦   «         }‰j        €€‰j        �y|                     dd¦  «        €t.                               d¦  «         ‰j        }t3          |t4          ¦  «        r|d         }t.                               d	|› d
�¦  «         |‰_        |                      |‰j        |¦  «        \  }}}|j        d         }‰j        |d<   ‰j        |d<   | j
        j         s|dk    rd|d<   n
‰j!        |d<   dtE          tG          j$        | j%        ¦  «        j&         '                    ¦   «         ¦  «        v }d|v}|                     dd¦  «        €(|r&|r$|  (                    |‰j        ‰j        ¦  «        |d<   | j
        j         sd‰j        �]tS          |j        ¦  «        dk    rEtU          j+        |dd…df         ‰j        k    ¦  «        dk    rt.                               d¦  «         | j
        j         rd|vr|  ,                    |||¦  «        }| j
        j         r.|  -                    |||‰j.        ‰j        |j/        ¬¦  «        \  }}n|dk    r|n| 0                    d¦  «        }|�'| 1                    | 2                    ¦   «         ¦  «         |j        d         }|                     d¦  «        du o‰j3        du}‰j4        �C|s2‰j3        �+t.                               d‰j4        › d‰j3        › d�¦  «         ‰j4        |z   ‰_3        |  5                    ‰||¦  «         |  6                    ‰|¦  «        }|�‰j7        dk    rtq          d¦  «        ‚| j/        j9        |j/        j9        k    rBt          j        d|j/        j9        › d| j/        j9        › d| j/        j9        › d�tt          ¦  «         |  ;                    ‰||||||	|
¬¦  «        }|  <                    ‰|¬¦  «        }|tz          j>        k    �re‰j?        dk    rtq          d ‰j?        › d!�¦  «        ‚|dk    rtq          d"¦  «        ‚|d         stq          d#¦  «        ‚dtE          tG          j$        |j%        ¦  «        j&         '                    ¦   «         ¦  «        v }|j
        j         r_d$|vr[t          j        |¦  «        }|                     ||j        j        |¦  «        \  }}}| ,                    |||¦  «        }|d         |d$<   |j
        j         s|rd|v r|d         |d$<    | j@        |f|‰jA        |‰jA        r|  B                    ‰¦  «        nd|‰j        ‰j        ‰jC        ‰jD        ||d%œ|¤ŽS |tz          jE        k    r+ | jF        |f||‰j        ‰j        ‰jC        ‰jD        ||d&œ|¤ŽS |tz          jG        k    rT|d         stq          d'¦  «        ‚ | jH        |f‰jI        ‰jJ        ||‰j        ‰j        ‰jC        ‰jD        ||‰jK        d(œ|¤ŽS |tz          jL        k    rd|  B                    ‰¦  «        } | jM        d5|‰j?        | j
        j         d)œ|¤Ž\  }} | jN        |f|||‰j        ‰j        ‰jC        ‰jD        ||d*œ	|¤ŽS |tz          jO        k    r‚t¡          |‰j7        |j/        ‰jQ        ‰jR        ‰j?        ‰j3        ¬+¦  «        } | jM        d5|‰j7        | j
        j         d)œ|¤Ž\  }} | jS        ||f||‰j        ‰j        ‰jC        ‰jD        |d,œ|¤ŽS |tz          jT        k    r˜|  B                    ‰¦  «        }t¡          |‰j7        |j/        ‰jQ        ‰jR        ‰j?        ‰j3        ¬+¦  «        } | jM        d5|‰j7        | j
        j         d)œ|¤Ž\  }} | jU        ||f|||‰j        ‰j        ‰jC        ‰jD        |d-œ|¤ŽS |tz          jV        k    rˆt¡          |‰j7        |j/        ‰jQ        ‰jR        ‰j?        ‰jW        ‰j3        ¬.¦  «        } | jM        d5|‰j7        | j
        j         d)œ|¤Ž\  }} | jX        ||f||‰j        ‰j        ‰jC        ‰jD        |d,œ|¤ŽS |tz          jY        k    �rg }‰jZ        �‰jZ        }‰j[        ��iˆfd/„}t3          ‰j[        t4          ¦  «        rtS          ‰j[        ¦  «        dk    r
 |¦   «          ‰j[        D �]}t3          |d         t4          ¦  «        rˆt3          |t4          ¦  «        rtS          |¦  «        dk    r
 |¦   «          t¹          d0„ |D ¦   «         ¦  «        r
 |¦   «          t¹          d1„ |D ¦   «         ¦  «        r
 |¦   «          t»          |¦  «        }ndt3          |t4          ¦  «        rtS          |¦  «        dk    r
 |¦   «          t¹          d2„ |D ¦   «         ¦  «        r
 |¦   «          t½          |¦  «        }| _                    |¦  «         �Œ!tÁ          ||‰j7        |j/        ‰jQ        ‰jR        ‰j?        ‰j3        ¬3¦  «        }  | jM        d5|‰j7        | j
        j         d)œ|¤Ž\  }} | ja        |f| ||‰j        ‰j        ‰jC        ‰jD        |d4œ|¤ŽS dS )6a  

        Generates sequences of token ids for models with a language modeling head.

        <Tip warning={true}>

        Most generation-controlling parameters are set in `generation_config` which, if not passed, will be set to the
        model's default generation configuration. You can override any `generation_config` by passing the corresponding
        parameters to generate(), e.g. `.generate(inputs, num_beams=4, do_sample=True)`.

        For an overview of generation strategies and code examples, check out the [following
        guide](../generation_strategies).

        </Tip>

        Parameters:
            inputs (`torch.Tensor` of varying shape depending on the modality, *optional*):
                The sequence used as a prompt for the generation or as model inputs to the encoder. If `None` the
                method initializes it with `bos_token_id` and a batch size of 1. For decoder-only models `inputs`
                should of in the format of `input_ids`. For encoder-decoder models *inputs* can represent any of
                `input_ids`, `input_values`, `input_features`, or `pixel_values`.
            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 had 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.
            logits_processor (`LogitsProcessorList`, *optional*):
                Custom logits processors that complement the default logits processors built from arguments and
                generation config. If a logit processor is passed that is already created with the arguments or a
                generation config an error is thrown. This feature is intended for advanced users.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                Custom stopping criteria that complement the default stopping criteria built from arguments and a
                generation config. If a stopping criteria is passed that is already created with the arguments or a
                generation config an error is thrown. If your stopping criteria depends on the `scores` input, make
                sure you pass `return_dict_in_generate=True, output_scores=True` to `generate`. This feature is
                intended for advanced users.
            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: the batch ID `batch_id` and
                `input_ids`. It has to return a list with the allowed tokens for the next generation step conditioned
                on the batch ID `batch_id` and the previously generated tokens `inputs_ids`. This argument is useful
                for constrained generation conditioned on the prefix, as described in [Autoregressive Entity
                Retrieval](https://arxiv.org/abs/2010.00904).
            synced_gpus (`bool`, *optional*):
                Whether to continue running the while loop until max_length. Unless overridden this flag will be set to
                `True` under DeepSpeed ZeRO Stage 3 multiple GPUs environment to avoid hanging if one GPU finished
                generating before other GPUs. Otherwise it'll be set to `False`.
            assistant_model (`PreTrainedModel`, *optional*):
                An assistant model that can be used to accelerate generation. The assistant model must have the exact
                same tokenizer. The acceleration is achieved when forecasting candidate tokens with the assistent model
                is much faster than running generation with the model you're calling generate from. As such, the
                assistant model should be much smaller.
            streamer (`BaseStreamer`, *optional*):
                Streamer object that will be used to stream the generated sequences. Generated tokens are passed
                through `streamer.put(token_ids)` and the streamer is responsible for any further processing.
            negative_prompt_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                The negative prompt needed for some processors such as CFG. The batch size must match the input batch
                size. This is an experimental feature, subject to breaking API changes in future versions.
            negative_prompt_attention_mask (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Attention_mask for `negative_prompt_ids`.
            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. If the model is an encoder-decoder model, encoder
                specific kwargs should not be prefixed and decoder specific kwargs should be prefixed with *decoder_*.

        Return:
            [`~utils.ModelOutput`] or `torch.LongTensor`: A [`~utils.ModelOutput`] (if `return_dict_in_generate=True`
            or when `config.return_dict_in_generate=True`) or a `torch.FloatTensor`.

                If the model is *not* an encoder-decoder model (`model.config.is_encoder_decoder=False`), the possible
                [`~utils.ModelOutput`] types are:

                    - [`~generation.GreedySearchDecoderOnlyOutput`],
                    - [`~generation.SampleDecoderOnlyOutput`],
                    - [`~generation.BeamSearchDecoderOnlyOutput`],
                    - [`~generation.BeamSampleDecoderOnlyOutput`]

                If the model is an encoder-decoder model (`model.config.is_encoder_decoder=True`), the possible
                [`~utils.ModelOutput`] types are:

                    - [`~generation.GreedySearchEncoderDecoderOutput`],
                    - [`~generation.SampleEncoderDecoderOutput`],
                    - [`~generation.BeamSearchEncoderDecoderOutput`],
                    - [`~generation.BeamSampleEncoderDecoderOutput`]
        Nr   TFaS  You have modified the pretrained model configuration to control generation. This is a deprecated strategy to control generation and will be removed soon, in a future version. Please use and modify the model generation configuration (see https://huggingface.co/docs/transformers/generation_strategies#default-text-generation-configuration )r  z²The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.r   z)Setting `pad_token_id` to `eos_token_id`:z for open-end generation.Úoutput_attentionsÚoutput_hidden_statesrœ   rÑ   r¯   r   r°   z¬A decoder-only architecture is being used, but right-padding was detected! For correct generation results, please set `padding_side='left'` when initializing the tokenizer.)r½   rÊ   r�   rã   r�   r³   r›   rD  zBoth `max_new_tokens` (=z) and `max_length`(=zÇ) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)zZ`streamer` cannot be used with beam search (yet!). Make sure that `num_beams` is set to 1.z~You are calling .generate() with the `input_ids` being on a device type different than your model's device. `input_ids` is on z, whereas the model is on z¶. You may experience unexpected behaviors or slower generation. Please make sure that you have put `input_ids` to the correct device by calling for example input_ids = input_ids.to('z ') before running `.generate()`.)rõ   r.  r/  r0  r1  r�   r2  r3  )rõ   rN  zFnum_return_sequences has to be 1 when doing assisted generate, but is rW  z6assisted generate is only supported for batch_size = 1z+assisted generate requires `use_cache=True`rƒ  )r%  r)  r1  Úlogits_warperrN  r¿   rÀ   Úoutput_scoresÚreturn_dict_in_generater¢  r£  )r1  rN  r¿   rÀ   r¨  r©  r¢  r£  z,Contrastive search requires `use_cache=True`)r  r*  r1  rN  r¿   rÀ   r¨  r©  r¢  r£  Ú
sequential)r›   rö   rž   )	r1  r§  rN  r¿   rÀ   r¨  r©  r¢  r£  )r½   r  r³   Úlength_penaltyÚdo_early_stoppingÚnum_beam_hyps_to_keeprD  )r1  rN  r¿   rÀ   r¨  r©  r¢  )r1  r§  rN  r¿   rÀ   r¨  r©  r¢  )r½   r  r³   r«  r¬  r­  r+  rD  c                  ó4   •— t          d‰ j        › d�¦  «        ‚)Nzo`force_words_ids` has to either be a `List[List[List[int]]]` or `List[List[int]]` of positive integers, but is rW  )r£   r(  )rõ   s   €rU   Ú	typeerrorz+GenerationMixin.generate.<locals>.typeerror3  s3   ø€ Ý$ð]Ø8IÔ8Yð]ð ]ð ]ñô ð rT   c              3   óB   K  — | ]}t          |t          ¦  «         V — Œd S r•   )rº   r  ©r–   Ú	token_idss     rU   r×   z+GenerationMixin.generate.<locals>.<genexpr>C  s/   è è € ÐYÐYÀ9¥:¨i½Ñ#>Ô#>Ð>ÐYÐYÐYÐYÐYÐYrT   c              3   óH   K  — | ]}t          d „ |D ¦   «         ¦  «        V — ŒdS )c              3   óN   K  — | ] }t          |t          ¦  «         p|d k     V — Œ!dS ©r   N©rº   rÃ   ©r–   Útoken_ids     rU   r×   z5GenerationMixin.generate.<locals>.<genexpr>.<genexpr>F  s9   è è € ÐjÐjÐT\¥Z°½#Ñ%>Ô%>Ð!>Ð!NÀ(ÈQÂ,ÐjÐjÐjÐjÐjÐjrT   NrØ   r±  s     rU   r×   z+GenerationMixin.generate.<locals>.<genexpr>E  sN   è è € ð ð à )õ  ÐjÐjÐ`iÐjÑjÔjÑjÔjðð ð ð ð ð rT   c              3   óN   K  — | ] }t          |t          ¦  «         p|d k     V — Œ!dS rµ  r¶  r·  s     rU   r×   z+GenerationMixin.generate.<locals>.<genexpr>O  s9   è è € ÐhÐhÐS[¥J¨x½Ñ$=Ô$=Ð =Ð MÀÈAÂÐhÐhÐhÐhÐhÐhrT   )r'  r½   r  r³   r«  r¬  r­  rD  )Úconstrained_beam_scorerr1  rN  r¿   rÀ   r¨  r©  r¢  rS   )br   ÚdistÚget_world_sizer}  rõ   Ú_from_model_configÚ_original_object_hashÚhashr    Úfrom_model_configr�   rŽ  r�  ÚcopyÚdeepcopyÚupdateÚvalidaterŠ  r,   r>   r¿   rÀ   r´   ÚloggerÚwarningrº   r  r­   r�   r¼   r¥  r¦  rž   rÑ   r¤   r¥   r¦   rß   r§   r¨   rÈ   rÂ   rO   ri  râ   ró   rã   r³   r¢   ÚputÚcpurD  r�  r•  r-  r  r£   rX  r�  rM  rS  ru   r�   Únum_return_sequencesÚassisted_decodingr)  r$  r¨  r©  r   rw   r~   rv   r  r*  Ú
low_memoryr€   rý   rx   r‚   r   r«  Úearly_stoppingrz   rƒ   r{   r…   r+  r}   r„   r'  r(  rÙ   r   r   r  r   r|   )!rŠ   rŽ   rõ   r1  rN  r0  r¢  r%  r£  r2  r3  rŒ   Únew_generation_configr�   rÀ   rÉ   rÊ   r½   Úaccepts_attention_maskÚrequires_attention_maskr›   r‘  r’  r,  Ú!assistant_accepts_encoder_outputsÚassistant_model_kwargsr§  Úbeam_scorerÚfinal_constraintsr¯  Úword_idsÚ
constraintrº  s!     `                              rU   ÚgeneratezGenerationMixin.generateF  sL  ø€ ðN ÐÝ)Ñ+Ô+ð $µÔ0CÑ0EÔ0EÈÒ0IÐ0IØ"��à#�ð 	×"Ò"Ñ$Ô$Ð$ð Ð$ð
 Ô%Ô8ð C¸TÔ=SÔ=iÕmqØÔ&ñnô nò >ð >õ )9Ô(JÈ4Ì;Ñ(WÔ(WÐ%Ø(¨DÔ,BÒBÐBÝ”MðBñô ð ð .C�DÔ*Ø $Ô 6Ðå œMÐ*;Ñ<Ô<ÐØ/Ð(Ô/Ð9Ð9°&Ð9Ð9ˆØ×"Ò"Ñ$Ô$Ð$Ø×#Ò# L×$5Ò$5Ñ$7Ô$7Ñ8Ô8Ð8ð 0@Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐàÔ)Ð1Ð6GÔ6TÐ6`Ø×ÒÐ 0°$Ñ7Ô7Ð?Ý—’ðqñô ð ð -Ô9ˆLÝ˜,­Ñ-Ô-ð /Ø+¨Aœ�Ý�NŠNÐnÀ|ÐnÐnÐnÑoÔoÐoØ-9ÐÔ*ð 9=×8RÒ8RØÐ%Ô2°Lñ9
ô 9
Ñ5ˆÐ'¨ð #Ô(¨Ô+ˆ
ð ->Ô,OˆÐ(Ñ)Ø/@Ô/UˆÐ+Ñ,ð Œ{Ô-ð 	DÐ2BÀoÒ2UÐ2UØ(,ˆL˜Ñ%Ð%à(9Ô(CˆL˜Ñ%à!1µS½Ô9JÈ4Ì<Ñ9XÔ9XÔ9c×9hÒ9hÑ9jÔ9jÑ5kÔ5kÐ!kÐØ"3¸<Ð"GÐà×ÒÐ,¨dÑ3Ô3Ð;Ð@WÐ;Ð\rÐ;Ø-1×-XÒ-XØÐ0Ô=Ð?PÔ?]ñ.ô .ˆLÐ)Ñ*ð
 Œ{Ô-ð 	ð "Ô.Ð:Ý˜Ô+Ñ,Ô,°Ò1Ð1Ý”I˜m¨A¨A¨A¨r¨EÔ2Ð6GÔ6TÒTÑUÔUÐXYÒYÐYå—’ðlñô ð ð
 Œ;Ô)ð 	Ð.?À|Ð.SÐ.Sð  ×NÒNØ˜|Ð-=ñô ˆLð
 Œ;Ô)ð 
	lØ&*×&TÒ&TØ%Ø!1Ø)Ø'8Ô'OØ.Ô;Ø$Ô+ð 'Uñ 'ô 'Ñ#ˆI�|�|ð *:¸[Ò)HÐ)H˜˜Èl×N^ÒN^Ð_jÑNkÔNkˆIàÐØ�LŠL˜Ÿš™œÑ)Ô)Ð)ð %œ?¨2Ô.ÐØ!'§¢¨LÑ!9Ô!9¸TÐ!AÐ!nÐFWÔFbÐjnÐFnÐØÔ+Ð7Ø)ð Ð.?Ô.JÐ.VÝ—’ðfÐ/@Ô/Oð fð fØ(Ô3ðfð fð fñô ð ð ,=Ô+KÐN^Ñ+^ÐÔ(Ø×'Ò'Ð(9Ð;KÐMcÑdÔdÐdð ×3Ò3Ð4EÀÑWÔWˆàÐÐ%6Ô%@À1Ò%DÐ%DÝØlñô ð ð Œ;Ô˜yÔ/Ô4Ò4Ð4ÝŒMð*Ø@IÔ@PÔ@Uð*ð *àœ+Ô*ð*ð *ð UYÔT_ÔTdð	*ð *ð *õ ñô ð ð  ×5Ò5Ø/Ø!1Ø+Ø%=Ø-Ø%Ø 3Ø+Ið 6ñ 	
ô 	
Ðð !×7Ò7Ø/ÐCTð 8ñ 
ô 
Ðð �nÔ@Ò@Ñ@Ø Ô5¸Ò9Ð9Ý ðHØ/ÔDðHð Hð Hñô ð ð ˜AŠ~ˆ~Ý Ð!YÑZÔZÐZØ Ô,ð PÝ Ð!NÑOÔOÐOà0AÅSÝÔ! /Ô"9Ñ:Ô:ÔE×JÒJÑLÔLñFô Fð 1Ð-ð
 Ô%Ô8ð fÐ=XÐ`lÐ=lÐ=lÝ)-¬°|Ñ)DÔ)DÐ&ØJY×JoÒJoØ! ?Ô#DÔ#QÐSiñKô KÑG�Ð/Ð1Gð *9×)gÒ)gØ!Ð#9Ð;Kñ*ô *Ð&ð =SÐSdÔ<e�Ð8Ñ9ð $Ô*Ô=ð	\à5ð	\ð &¨Ð5Ð5ð =IÐIZÔ<[�Ð8Ñ9ð *�4Ô)Øðà /Ø+Ô5Ø!1ØL]ÔLgÐq˜d×5Ò5Ð6GÑHÔHÐHÐmqØ"3Ø.Ô;Ø.Ô;Ø/Ô=Ø(9Ô(QØ'Ø!ðð ð ðð ð ð �nÔ:Ò:Ð:à%�4Ô%Øðà!1Ø"3Ø.Ô;Ø.Ô;Ø/Ô=Ø(9Ô(QØ'Ø!ðð ð ðð ð ð ¥Ô AÒAÐAØ Ô,ð QÝ Ð!OÑPÔPÐPà*�4Ô*Øðà'Ô-Ø/Ô=Ø!1Ø"3Ø.Ô;Ø.Ô;Ø/Ô=Ø(9Ô(QØ'Ø!Ø,Ô7ðð ð ðð ð ð  ¥Ô 5Ò5Ð5à ×3Ò3Ð4EÑFÔFˆMð 'I dÔ&Hð 'Ø#Ø-ÔBØ#'¤;Ô#Að'ð 'ð ð	'ð 'Ñ#ˆI�|ð �4”;Øðà!1Ø+Ø"3Ø.Ô;Ø.Ô;Ø/Ô=Ø(9Ô(QØ'Ø!ðð ð ðð ð ð ¥Ô :Ò:Ð:å*Ø%Ø+Ô5Ø$Ô+Ø0Ô?Ø"3Ô"BØ&7Ô&LØ,Ô7ðñ ô ˆKð 'I dÔ&Hð 'Ø#Ø-Ô7Ø#'¤;Ô#Að'ð 'ð ð	'ð 'Ñ#ˆI�|ð $�4Ô#ØØðð "2Ø"3Ø.Ô;Ø.Ô;Ø/Ô=Ø(9Ô(QØ'ðð ð ðð ð ð ¥Ô :Ò:Ð:à ×3Ò3Ð4EÑFÔFˆMõ +Ø%Ø+Ô5Ø$Ô+Ø0Ô?Ø"3Ô"BØ&7Ô&LØ,Ô7ðñ ô ˆKð 'I dÔ&Hð 'Ø#Ø-Ô7Ø#'¤;Ô#Að'ð 'ð ð	'ð 'Ñ#ˆI�|ð $�4Ô#ØØðð "2Ø+Ø"3Ø.Ô;Ø.Ô;Ø/Ô=Ø(9Ô(QØ'ðð ð ðð ð ð ¥Ô @Ò@Ð@å*Ø%Ø+Ô5Ø$Ô+Ø0Ô?Ø"3Ô"BØ&7Ô&LØ 1Ô AØ,Ô7ð	ñ 	ô 	ˆKð 'I dÔ&Hð 'Ø#Ø-Ô7Ø#'¤;Ô#Að'ð 'ð ð	'ð 'Ñ#ˆI�|ð *�4Ô)ØØðð "2Ø"3Ø.Ô;Ø.Ô;Ø/Ô=Ø(9Ô(QØ'ðð ð ðð ð ð ¥Ô FÒFÑFØ "ÐØ Ô,Ð8Ø$5Ô$AÐ!à Ô0Ñ<ðð ð ð ð õ #Ð#4Ô#DÅdÑKÔKð åÐ,Ô<Ñ=Ô=ÀÒBÐBà�I‘K”K�Kà 1Ô Að 9ñ 9�HÝ! (¨1¤+­tÑ4Ô4ð AÝ)¨(µDÑ9Ô9ð (½SÀ¹]¼]ÈaÒ=OÐ=OØ%˜I™KœK˜KÝÐYÐYÐPXÐYÑYÔYÑYÔYð (Ø%˜I™KœK˜KÝð ð à-5ðñ ô ñ ô ð (ð &˜I™KœK˜Kå%:¸8Ñ%DÔ%D˜
˜
å)¨(µDÑ9Ô9ð (½SÀ¹]¼]ÈaÒ=OÐ=OØ%˜I™KœK˜KÝÐhÐhÐ_gÐhÑhÔhÑhÔhð (Ø%˜I™KœK˜Kå%6°xÑ%@Ô%@˜
Ø%×,Ò,¨ZÑ8Ô8Ð8Ñ8õ 'BØ-Ø%Ø+Ô5Ø$Ô+Ø0Ô?Ø"3Ô"BØ&7Ô&LØ,Ô7ð	'ñ 	'ô 	'Ð#ð 'I dÔ&Hð 'Ø#Ø-Ô7Ø#'¤;Ô#Að'ð 'ð ð	'ð 'Ñ#ˆI�|ð 0�4Ô/Øðà(?Ø!1Ø"3Ø.Ô;Ø.Ô;Ø/Ô=Ø(9Ô(QØ'ðð ð ðð ð ðy GÐFrT   r   r  r*  r§  r¥  r¦  r¨  r©  rª  c           	      ó¢  ‡;‡<‡=— |�|nt          ¦   «         }|�|nt          ¦   «         }|�|nt          ¦   «         }|�|n| j        j        }|�|n| j        j        }|�|n| j        j        }t          |t          ¦  «        r|g}|�,t          j	        |¦  «         
                    |j        ¦  «        nd}|�|n| j        j        }|	�|	n| j        j        }	|
�|
n| j        j        }
|�|n| j        j        }|r|rdnd}|r|	rdnd}|r|	rdnd}|r|
rdnd}|rJ| j        j        r>|	r|d                              d¦  «        nd}|
r|d                              d¦  «        nd}t          j        |j        d         t          j        |j        ¬¦  «        }d}|j        d         }	 |rot          j	        |rd
nd¦  «         
                    |j        ¦  «        }t-          j        |t,          j        j        ¬¦  «         |                     ¦   «         d
k    r�	nr|                     d¦  «        �€1d	|d<    | j        |fi |¤Ž} | di |¤d	d	|	dœ¤Ž}| j        j        r|j        d         }n|j        d         }|j        dd…ddd…f         }|                      ||| j        j        d	¬¦  «        }|s | j         d|| j        j        dœ|¤Ž\  } }|                     d¦  «        }!|!€tC          | j"        j#        › d�¦  «        ‚t          |!d         tH          t          j%        f¦  «        r|!d         d         j        d         |k    rtC          | j"        j#        › d�¦  «        ‚ |||¦  «        } |||¦  «        }tL          j'         (                    |d¬¦  «        }"t          j)        |"d|¬¦  «        \  }#}$|ra|r||fz  }|	r6|| j        j        r|j*        fn|j+        fz  }| j        j        r||j,        fz  }|
r|| j        j        r|j        fn|j        fz  }g }%|d         D ]uŠ=g }&‰=D ]Y}'|r+|& -                    |' .                    dd¬¦  «        ¦  «         Œ/|& -                    |' .                    |d¬¦  «        ¦  «         ŒZ|% -                    |&¦  «         Œv|%|d<   |�rëd„ |D ¦   «         }(g g g cŠ<Š;})t_          |¦  «        D ]û}* | j        |$dd…|*f          0                    dd¦  «        fi |¤Ž}+ | di |+¤d	d	|	dœ¤Ž}|(D ]#},|(|,          -                    ||,         ¦  «         Œ$| j        j        r|j        d         }-|j        }.n|j        d         }-|j        }.‰< -                    t          j1        |-d¦  «        ¦  «         ‰; -                    |.¦  «         |) -                    |j        dd…ddd…f         ¦  «         Œüt          j2        ˆ<fd„t_          |¦  «        D ¦   «         d¬¦  «        }-d„ t_          tg          |.¦  «        ¦  «        D ¦   «         }/t_          tg          |.¦  «        ¦  «        D ]5Š=t          j2        ˆ;ˆ=fd„t_          |¦  «        D ¦   «         d¬¦  «        |/‰=<   Œ6tI          |/¦  «        }.t          j4        |)d¬¦  «        }0ny | j        |$ 0                    dd¦  «        fi |¤Ž}+ | di |+¤d	d	|	dœ¤Ž}| j        j        r|j        d         }-|j        }.n|j        d         }-|j        }.|j        dd…ddd…f         }0| .                    |d¬¦  «        }1tk          |1|-|#||¦  «        }2|2 
                    d¦  «        }2|$t_          tg          |$¦  «        ¦  «        |2f         }3t          j2        t          j6        |- 1                    d¬¦  «        |¦  «        ¦  «        }-|-t_          |¦  «        |2dd…f         }-t          j4        ||- 7                    d¦  «        gd¬¦  «        }d}4|.D ]GŠ=t          j2        t          j6        ‰=|¦  «        ¦  «        t_          |¦  «        |2dd…f         Š=|4‰=fz  }4ŒH|rC | j        |$dd…|2f          0                    dd¦  «        fi |¤Ž}5 | di |5¤d	dddœ¤Ž}6|6d         }7nt|  8                    |d	¬¦  «        }7d}%|7D ]VŠ=d}&‰=D ]I}'t          j2        t          j6        |'|d¬¦  «        ¦  «        }'|'t_          |¦  «        |2df         }'|&|'fz  }&ŒJ|%|&fz  }%ŒW|%}7t          j2        t          j6        |0|¦  «        ¦  «        t_          |¦  «        |2dd…f         }| j        j        r¼d}8d}9|	rž|j,        D ]GŠ=t          j2        t          j6        ‰=|d¬¦  «        ¦  «        t_          |¦  «        |2df         Š=|8‰=fz  }8ŒH|j*        D ]GŠ=t          j2        t          j6        ‰=|d¬¦  «        ¦  «        t_          |¦  «        |2df         Š=|9‰=fz  }9ŒHts          |7|4|9pd|8pd¬¦  «        }ngd}:|	rO|j+        D ]GŠ=t          j2        t          j6        ‰=|d¬¦  «        ¦  «        t_          |¦  «        |2df         Š=|:‰=fz  }:ŒHtu          |7|4|:pd¬ ¦  «        }|r|r�Œ·|�|€tC          d!¦  «        ‚|3|z  |d|z
  z  z   }3t          j4        ||3dd…df         gd¬¦  «        }|�'| ;                    |3 <                    ¦   «         ¦  «         |                      ||| j        j        ¬"¦  «        }|�ˆ| =                    |3 >                    |j        d         d¦  «         ?                    | 7                    d¦  «        ¦  «         @                    d¬¦  «        ¦  «        }| A                    ¦   «         dk    rd	} |||¦  «        rd	}|r|sn�	Œã|�| B                    ¦   «          |r5| j        j        rt‡          |||||||¬#¦  «        S t‰          ||||¬$¦  «        S |S )%u  
        Generates sequences of token ids for models with a language modeling head using **contrastive search** and can
        be used for text-decoder, text-to-text, speech-to-text, and vision-to-text models.

        <Tip warning={true}>

        In most cases, you do not need to call [`~generation.GenerationMixin.contrastive_search`] directly. Use
        generate() instead. For an overview of generation strategies and code examples, check the [following
        guide](../generation_strategies).

        </Tip>

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            top_k (`int`, *optional*, defaults to 1):
                The size of the candidate set that is used to re-rank for contrastive search
            penalty_alpha (`float`, *optional*, defaults to 0):
                The degeneration penalty for contrastive search; activate when it is larger than 0
            logits_processor (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsProcessor`]
                used to modify the prediction scores of the language modeling head applied at each generation step.
            logits_warper (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsWarper`] used
                to warp the prediction score distribution of the language modeling head applied before multinomial
                sampling at each generation step.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            pad_token_id (`int`, *optional*):
                The id of the *padding* token.
            eos_token_id (`Union[int, List[int]]`, *optional*):
                The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more details.
            output_hidden_states (`bool`, *optional*, defaults to `False`):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more details.
            output_scores (`bool`, *optional*, defaults to `False`):
                Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
            return_dict_in_generate (`bool`, *optional*, defaults to `False`):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            synced_gpus (`bool`, *optional*, defaults to `False`):
                Whether to continue running the while loop until max_length (needed for ZeRO stage 3)
            streamer (`BaseStreamer`, *optional*):
                Streamer object that will be used to stream the generated sequences. Generated tokens are passed
                through `streamer.put(token_ids)` and the streamer is responsible for any further processing.
            sequential (`bool`, *optional*):
                Switches topk hidden state computation from parallel to sequential to reduce memory if True.
            model_kwargs:
                Additional model specific keyword arguments will be forwarded to the `forward` function of the model.
                If model is an encoder-decoder model the kwargs should include `encoder_outputs`.

        Return:
            [`~generation.ContrastiveSearchDecoderOnlyOutput`], [`~generation.ContrastiveSearchEncoderDecoderOutput`]
            or `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.ContrastiveSearchDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.ContrastiveSearchEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.

        Examples:
        ```python
        >>> from transformers import (
        ...     AutoTokenizer,
        ...     AutoModelForCausalLM,
        ...     StoppingCriteriaList,
        ...     MaxLengthCriteria,
        ... )

        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/opt-125m")
        >>> model = AutoModelForCausalLM.from_pretrained("facebook/opt-125m")
        >>> # set pad_token_id to eos_token_id because OPT does not have a PAD token
        >>> model.config.pad_token_id = model.config.eos_token_id
        >>> input_prompt = "DeepMind Company is"
        >>> input_ids = tokenizer(input_prompt, return_tensors="pt")
        >>> stopping_criteria = StoppingCriteriaList([MaxLengthCriteria(max_length=64)])
        >>> outputs = model.contrastive_search(
        ...     **input_ids, penalty_alpha=0.6, top_k=4, stopping_criteria=stopping_criteria
        ... )
        >>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
        ['DeepMind Company is a company that focuses on the development and commercialization of artificial intelligence (AI). DeepMindâ€™s mission is to help people understand and solve problems that are difficult to solve in the world today.\n\nIn this post, we talk about the benefits of deep learning in business and how it']
        ```NrS   r¯   rH   rI   r   r±   FTr  r  ©Úopr  rÑ   )rÝ   r¦  r¥  r°   )rž   rÿ   )rö   rž   zQ does not support caching and therefore **can't** be used for contrastive search.z| does not have a standard cache format and therefore **can't** be used for contrastive search without further modifications.rç   )rè   r—   r   c                 ó   — i | ]}|g “ŒS rS   rS   )r–   rû   s     rU   rš   z6GenerationMixin.contrastive_search.<locals>.<dictcomp>k  s   € Ð:Ð:Ð:¨3˜s BÐ:Ð:Ð:rT   c                 ó    •— g | ]
}‰|         ‘ŒS rS   rS   )r–   ÚiÚall_last_hstatess     €rU   ú
<listcomp>z6GenerationMixin.contrastive_search.<locals>.<listcomp>‡  s   ø€ Ð*UÐ*UÐ*UÀ1Ð+;¸AÔ+>Ð*UÐ*UÐ*UrT   c                 ó   — g | ]}d ‘ŒS ©r   rS   )r–   rÜ  s     rU   rÞ  z6GenerationMixin.contrastive_search.<locals>.<listcomp>ˆ  s   € Ð%PÐ%PÐ%P¨A aÐ%PÐ%PÐ%PrT   c                 óR   •— g | ]#}t          j        ‰|         ‰         d ¦  «        ‘Œ$S rà  )rO   Úsqueeze)r–   rÜ  Úall_hstatesÚlayers     €€rU   rÞ  z6GenerationMixin.contrastive_search.<locals>.<listcomp>‹  s.   ø€ ÐWÐWÐWÀQ�œ {°1¤~°eÔ'<¸aÑ@Ô@ÐWÐWÐWrT   rÈ  r  .)r  r\   rZ   r[   )r  rI   rH   úGIf `eos_token_id` is defined, make sure that `pad_token_id` is defined.©rž   ©rF   rG   rX   rY   rZ   r[   r\   ©rF   rG   rH   rI   )Er,   r>   rõ   r¿   rÀ   rË  rº   rÃ   rO   Útensorra  r³   r¨  r¥  r¦  r©  r�   rž   r´   r·   r¼   r¸   r»  Ú
all_reduceÚReduceOpÚSUMrï   r�   r\   rI   r  r  rý   r£   r©   rK   Útupler»   r   rg  ÚsoftmaxÚtopkrZ   rH   r[   r  rù   Úranger`  râ  rc  rÂ   rð   Ú_ranking_fastÚsplitr  r  r   r   rÇ  rÈ  ÚmulÚtilerÄ   Úprodrj  ÚendrW   r_   )>rŠ   r›   r  r*  r1  r§  rN  r¿   rÀ   r¥  r¦  r¨  r©  r¢  r£  rª  r�   Úeos_token_id_tensorrG   rZ   r[   r\   rX   rY   Úunfinished_sequencesÚthis_peer_finishedr½   Úthis_peer_finished_flagÚmodel_inputsrþ   Úlast_hidden_statesÚlogit_for_next_stepÚ_r  Ú
next_probsÚtop_k_probsÚ	top_k_idsÚnew_key_valuesr¡   rï   Úall_outputsÚ
all_logitsrÜ  Únext_model_inputsrû   Únext_hiddenÚfull_hidden_statesÚfinal_full_hstatesr  Úcontext_hiddenÚselected_idxÚnext_tokensÚnext_decoder_hidden_statesÚnext_model_inputÚselected_outputsÚnext_past_key_valuesÚnext_step_cross_attentionsÚnext_step_decoder_attentionsÚnext_step_attentionsrã  rÝ  rä  s>                                                              @@@rU   rv   z"GenerationMixin.contrastive_searchu  s{  øøø€ ðP 0@Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ)6Ð)B˜˜ÕH[ÑH]ÔH]ˆØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐØ'3Ð'?�|�|ÀTÔE[ÔEhˆØ'3Ð'?�|�|ÀTÔE[ÔEhˆØ#-Ð#9�Z�Z¸tÔ?UÔ?`ˆ
Ý�l¥CÑ(Ô(ð 	*Ø(˜>ˆLØQ]ÐQi�eœl¨<Ñ8Ô8×;Ò;¸IÔ<LÑMÔMÐMÐosÐØ)6Ð)B˜˜ÈÔH^ÔHlˆà!2Ð!>ÐÐÀDÔDZÔDlð 	ð %9Ð$DÐ Ð È$ÔJ`ÔJuð 	ð
 'Ð2ð $Ð#àÔ'Ô?ð 	 ð 0ÐL°MÐL��ÈˆØ$;Ð\Ð@QÐ\˜R˜RÐX\ÐØ"9ÐZÐ>OÐZ˜2˜2ÐVZÐØ'>Ð bÐCWÐ b  Ð^bÐð #ð 	 t¤{Ô'Eð 	ØVgÐ!q Ð.?Ô!@×!DÒ!DÀ\Ñ!RÔ!RÐ!RÐmqÐàH\Ðf�Ð.Ô/×3Ò3°OÑDÔDÐDÐbfð "õ
  %œz¨)¬/¸!Ô*<ÅEÄJÐW`ÔWgÐhÑhÔhÐà"ÐØ”_ QÔ'ˆ
ðQ	Øð õ +0¬,Ð>PÐ7Y°s°sÐVYÑ*ZÔ*Z×*]Ò*]Ð^gÔ^nÑ*oÔ*oÐ'å”Ð 7½D¼MÔ<MÐNÑNÔNÐNà*×/Ò/Ñ1Ô1°SÒ8Ð8Ùð ×ÒÐ 1Ñ2Ô2Ñ:à,0�˜[Ñ)ØA˜tÔAÀ)Ð\Ð\È|Ð\Ð\�ð ˜$ð ð Ø"ðØ04È4Ðctðð ð ð �ð ”;Ô1ð CØ)0Ô)FÀrÔ)JÐ&Ð&à)0Ô)>¸rÔ)BÐ&ð '.¤n°Q°Q°Q¸¸A¸A¸A°XÔ&>Ð#à#×GÒGØØ Ø'+¤{Ô'EØ-1ð	  Hñ  ô  �ð "ð à&H dÔ&Hð 'Ø$)¸d¼kÔ>\ð'ð 'Ø`lð'ð '‘O�A�|ð #/×"2Ò"2Ð3DÑ"EÔ"E�Ø"Ð*Ý$Øœ>Ô2ð 2ð 2ð 2ñô ð õ
 # ?°1Ô#5½½u¼|Ð7LÑMÔMðà& qÔ)¨!Ô,Ô2°1Ô5¸ÒCÐCå$Øœ>Ô2ð Uð Uð Uñô ð ð #3Ð"2°9Ð>QÑ"RÔ"RÐØ"/ -°	Ð;NÑ"OÔ"OÐÝœ×.Ò.Ð/BÈÐ.ÑKÔKˆJÝ%*¤Z°
ÀÀeÐ%LÑ%LÔ%LÑ"ˆK˜ð 'ð Ø ð 5ØÐ2Ð4Ñ4�FØ$ð HØ&Ø9=¼Ô9WÐr˜Ô3Ð5Ð5Ð^eÔ^pÐ]rñÐ&ð ”{Ô5ð HØ(¨WÔ-EÐ,GÑGÐ(à'ð Ø)àœ;Ô9ð6˜Ô6Ð8Ð8à%Ô3Ð5ñÐ)ð  ˆNØ%Ð&7Ô8ð -ð -�Ø�à!ð Kð K�DØ!ð KØŸš T×%;Ò%;¸AÀ1Ð%;Ñ%EÔ%EÑFÔFÐFÐFàŸš T×%;Ò%;¸EÀqÐ%;Ñ%IÔ%IÑJÔJÐJÐJØ×%Ò% eÑ,Ô,Ð,Ð,Ø.<ˆLÐ*Ñ+àñ ;2Ø:Ð:°'Ð:Ñ:Ô:�Ø<>ÀÀBÐ9Ð  +¨zÝ˜u™œð @ð @�Aà(J¨Ô(JÈ9ÐUVÐUVÐUVÐXYÐUYÌ?×K_ÒK_Ð`bÐdeÑKfÔKfÐ(wÐ(wÐjvÐ(wÐ(wÐ%à"˜dð ð Ø+ðà$(Ø-1Ø*;ð	ð ð ð �Gð  +ð >ð >˜Ø# CÔ(×/Ò/°¸´Ñ=Ô=Ð=Ð=à”{Ô5ð CØ&-Ô&CÀBÔ&G˜Ø-4Ô-JÐ*Ð*ð '.Ô&;¸BÔ&?˜Ø-4Ô-BÐ*à$×+Ò+­E¬M¸+ÀqÑ,IÔ,IÑJÔJÐJØ×&Ò&Ð'9Ñ:Ô:Ð:Ø×%Ò% g¤n°Q°Q°Q¸¸A¸A¸A°XÔ&>Ñ?Ô?Ð?Ð?õ $œkÐ*UÐ*UÐ*UÐ*UÍÈeÉÌÐ*UÑ*UÔ*UÐ[\Ð]Ñ]Ô]�Ø%PÐ%PµµsÐ;MÑ7NÔ7NÑ1OÔ1OÐ%PÑ%PÔ%PÐ"Ý"¥3Ð'9Ñ#:Ô#:Ñ;Ô;ð ð �EÝ05´ØWÐWÐWÐWÐWÍ%ÐPUÉ,Ì,ÐWÑWÔWÐ]^ð1ñ 1ô 1Ð& uÑ-Ð-õ &+Ð+=Ñ%>Ô%>Ð"õ œ :°1Ð5Ñ5Ô5��ð
 %G DÔ$FÀyÇ~Â~ÐVXÐZ[ÑG\ÔG\Ð$mÐ$mÐ`lÐ$mÐ$mÐ!à˜$ð ð Ø'ðà $Ø)-Ø&7ð	ð ð ð �ð ”;Ô1ð ?Ø")Ô"?ÀÔ"C�KØ)0Ô)FÐ&Ð&à")Ô"7¸Ô";�KØ)0Ô)>Ð&à œ¨¨¨¨2¨q¨q¨q¨Ô1�à/×AÒAÀ%ÈQÐAÑOÔOˆNõ
 )¨¸ÀkÐS`ÐbgÑhÔhˆLØ'Ÿ?š?¨5Ñ1Ô1ˆLð
 $¥E­#¨i©.¬.Ñ$9Ô$9¸<Ð$GÔHˆKÝœ+¥e¤k°+×2EÒ2EÈ!Ð2EÑ2LÔ2LÈeÑ&TÔ&TÑUÔUˆKØ%¥e¨JÑ&7Ô&7¸ÀqÀqÀqÐ&HÔIˆKÝ!&¤Ð,>À×@UÒ@UÐVWÑ@XÔ@XÐ+YÐ_`Ð!aÑ!aÔ!aÐà)+Ð&Ø+ð 7ð 7�Ýœ¥E¤K°°uÑ$=Ô$=Ñ>Ô>½uÀZÑ?PÔ?PÐR^Ð`aÐ`aÐ`aÐ?aÔb�Ø*¨u¨hÑ6Ð*Ð*ð ð 6Ø#E 4Ô#EØ˜a˜a˜a ˜oÔ.×3Ò3°B¸Ñ:Ô:ð$ð $Ø>Jð$ð $Ð ð $( 4ð $ð $Ø&ð$à $Ø).Ø&+ð	$ð $ð $ð $Ð ð (8Ð8IÔ'JÐ$Ð$ð (,×'KÒ'KÈGÐnrÐ'KÑ'sÔ'sÐ$Ø!#�Ø1ð /ð /�EØ�Eà %ð )ð )˜Ý$œ{­5¬;°t¸UÈÐ+JÑ+JÔ+JÑKÔK˜Ø#¥E¨*Ñ$5Ô$5°|ÀSÐ$HÔI˜Ø $ Ñ(˜˜Ø" u hÑ.�N�NØ'5Ð$å"'¤+­e¬k¸&À%Ñ.HÔ.HÑ"IÔ"IÍ%ÐPZÑJ[ÔJ[Ð]iÐklÐklÐklÐJlÔ"mÐð Œ{Ô-ð Ø-/Ð*Ø/1Ð,Ø$ð AØ!(Ô!9ð ?ð ?˜Ý %¤­E¬K¸¸uÈ!Ð,LÑ,LÔ,LÑ MÔ MÍeÐT^ÑN_ÔN_ÐamÐorÐNrÔ s˜Ø2°u°hÑ>Ð2Ð2Ø!(Ô!;ð Að A˜Ý %¤­E¬K¸¸uÈ!Ð,LÑ,LÔ,LÑ MÔ MÍeÐT^ÑN_ÔN_ÐamÐorÐNrÔ s˜Ø4¸¸Ñ@Ð4Ð4Ý)Ø$8Ø*DØ'CÐ'KÀtØ%?Ð%GÀ4ð	ñ ô ��ð (*Ð$Ø$ð 9Ø!(Ô!3ð 9ð 9˜Ý %¤­E¬K¸¸uÈ!Ð,LÑ,LÔ,LÑ MÔ MÍeÐT^ÑN_ÔN_ÐamÐorÐNrÔ s˜Ø,°°Ñ8Ð,Ð,Ý0Ø$8Ø"<Ø3Ð;°tðñ ô �ð ð Ð1ð Ùð Ð'ØÐ'Ý$Ð%nÑoÔoÐoØ)Ð,@Ñ@À<ÐSTÐWkÑSkÑClÑl�õ œ	 9¨k¸!¸!¸!¸T¸'Ô.BÐ"CÈÐLÑLÔLˆIØÐ#Ø—’˜[Ÿ_š_Ñ.Ô.Ñ/Ô/Ð/Ø×CÒCØ˜¸$¼+Ô:Xð Dñ ô ˆLð
 #Ð.Ø';×'?Ò'?Ø×$Ò$Ð%8Ô%>¸qÔ%AÀ1ÑEÔE×HÒHÐI\×IfÒIfÐghÑIiÔIiÑjÔj×oÒoÐtuÐoÑvÔvñ(ô (Ð$ð
 (×+Ò+Ñ-Ô-°Ò2Ð2Ø)-Ð&ð !Ð  ¨FÑ3Ô3ð *Ø%)Ð"à!ð ¨+ð ØñcQ	ðf ÐØ�LŠL‰NŒNˆNà"ð 	ØŒ{Ô-ð Ý<Ø'Ø!Ø'9Ø*?Ø'9Ø%5Ø*?ðñ ô ð õ :Ø'Ø!Ø1Ø"7ð	ñ ô ð ð ÐrT   rD  c           	      ó€  — |�|nt          ¦   «         }|�|nt          ¦   «         }|�*t          j        dt          ¦  «         t          ||¦  «        }|�|n| j        j        }|�|n| j        j        }t          |t          ¦  «        r|g}|�,t          j        |¦  «                             |j        ¦  «        nd}|	�|	n| j        j        }	|�|n| j        j        }|�|n| j        j        }|
�|
n| j        j        }
|
r|	rdnd}|
r|rdnd}|
r|rdnd}|
r|rdnd}|
rJ| j        j        r>|r|d                              d¦  «        nd}|r|d                              d¦  «        nd}t          j        |j        d         t          j        |j        ¬¦  «        }d	}	 |rot          j        |rdnd¦  «                             |j        ¦  «        }t3          j        |t2          j        j        ¬¦  «         |                     ¦   «         dk    r�nç | j        |fi |¤Ž} | di |¤d
||dœ¤Ž}|r|rŒ“|j        dd…ddd…f         } |||¦  «        }|
ra|	r||fz  }|r6|| j        j        r|j         fn|j!        fz  }| j        j        r||j"        fz  }|r|| j        j        r|j#        fn|j$        fz  }t          j%        |d¬¦  «        }|�|€tM          d¦  «        ‚||z  |d|z
  z  z   }t          j'        ||dd…df         gd¬¦  «        }|�'| (                    | )                    ¦   «         ¦  «         |  *                    ||| j        j        ¬¦  «        }|�ˆ| +                    | ,                    |j        d         d¦  «         -                    | .                    d¦  «        ¦  «         /                    d¬¦  «        ¦  «        }| 0                    ¦   «         dk    rd
} |||¦  «        rd
}|r|sn�ŒX|�| 1                    ¦   «          |
r5| j        j        rte          |||||||¬¦  «        S tg          ||||¬¦  «        S |S )aM  
        Generates sequences of token ids for models with a language modeling head using **greedy decoding** and can be
        used for text-decoder, text-to-text, speech-to-text, and vision-to-text models.

        <Tip warning={true}>

        In most cases, you do not need to call [`~generation.GenerationMixin.greedy_search`] directly. Use generate()
        instead. For an overview of generation strategies and code examples, check the [following
        guide](../generation_strategies).

        </Tip>


        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            logits_processor (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsProcessor`]
                used to modify the prediction scores of the language modeling head applied at each generation step.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.

            max_length (`int`, *optional*, defaults to 20):
                **DEPRECATED**. Use `logits_processor` or `stopping_criteria` directly to cap the number of generated
                tokens. The maximum length of the sequence to be generated.
            pad_token_id (`int`, *optional*):
                The id of the *padding* token.
            eos_token_id (`Union[int, List[int]]`, *optional*):
                The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more details.
            output_hidden_states (`bool`, *optional*, defaults to `False`):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more details.
            output_scores (`bool`, *optional*, defaults to `False`):
                Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
            return_dict_in_generate (`bool`, *optional*, defaults to `False`):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            synced_gpus (`bool`, *optional*, defaults to `False`):
                Whether to continue running the while loop until max_length (needed for ZeRO stage 3)
            streamer (`BaseStreamer`, *optional*):
                Streamer object that will be used to stream the generated sequences. Generated tokens are passed
                through `streamer.put(token_ids)` and the streamer is responsible for any further processing.
            model_kwargs:
                Additional model specific keyword arguments will be forwarded to the `forward` function of the model.
                If model is an encoder-decoder model the kwargs should include `encoder_outputs`.

        Return:
            [`~generation.GreedySearchDecoderOnlyOutput`], [`~generation.GreedySearchEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.GreedySearchDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.GreedySearchEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.

        Examples:

        ```python
        >>> from transformers import (
        ...     AutoTokenizer,
        ...     AutoModelForCausalLM,
        ...     LogitsProcessorList,
        ...     MinLengthLogitsProcessor,
        ...     StoppingCriteriaList,
        ...     MaxLengthCriteria,
        ... )

        >>> tokenizer = AutoTokenizer.from_pretrained("gpt2")
        >>> model = AutoModelForCausalLM.from_pretrained("gpt2")

        >>> # set pad_token_id to eos_token_id because GPT2 does not have a PAD token
        >>> model.generation_config.pad_token_id = model.generation_config.eos_token_id

        >>> input_prompt = "It might be possible to"
        >>> input_ids = tokenizer(input_prompt, return_tensors="pt").input_ids

        >>> # instantiate logits processors
        >>> logits_processor = LogitsProcessorList(
        ...     [
        ...         MinLengthLogitsProcessor(10, eos_token_id=model.generation_config.eos_token_id),
        ...     ]
        ... )
        >>> stopping_criteria = StoppingCriteriaList([MaxLengthCriteria(max_length=20)])

        >>> outputs = model.greedy_search(
        ...     input_ids, logits_processor=logits_processor, stopping_criteria=stopping_criteria
        ... )

        >>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
        ["It might be possible to get a better understanding of the nature of the problem, but it's not"]
        ```NzŽ`max_length` is deprecated in this function, use `stopping_criteria=StoppingCriteriaList([MaxLengthCriteria(max_length=max_length)])` instead.rS   r¯   rH   rI   r   r±   FTr  r  rØ  ©rÝ   r¥  r¦  r°   rç   rå  r   ræ  rç  rè  )4r,   r>   rŽ  r�  r�  r?   rõ   r¿   rÀ   rº   rÃ   rO   ré  ra  r³   r¨  r¥  r¦  r©  r�   rž   r´   r·   r¼   r¸   r»  rê  rë  rì  rï   r�   r  rZ   rH   r[   r\   rI   Úargmaxr£   rð   rÇ  rÈ  r  ró  rô  rÄ   r  rõ  rj  rö  rb   rE   )rŠ   r›   r1  rN  rD  r¿   rÀ   r¥  r¦  r¨  r©  r¢  r£  r�   r÷  rG   rZ   r[   r\   rX   rY   rø  rù  rú  rû  rþ   Únext_token_logitsÚnext_tokens_scoresr  s                                rU   rw   zGenerationMixin.greedy_search1	  sÜ  € ðZ 0@Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐØÐ!ÝŒMðqåñô ð õ
 !;Ð;LÈjÑ YÔ YÐØ'3Ð'?�|�|ÀTÔE[ÔEhˆØ'3Ð'?�|�|ÀTÔE[ÔEhˆÝ�l¥CÑ(Ô(ð 	*Ø(˜>ˆLØQ]ÐQi�eœl¨<Ñ8Ô8×;Ò;¸IÔ<LÑMÔMÐMÐosÐØ)6Ð)B˜˜ÈÔH^ÔHlˆà!2Ð!>ÐÐÀDÔDZÔDlð 	ð %9Ð$DÐ Ð È$ÔJ`ÔJuð 	ð
 'Ð2ð $Ð#àÔ'Ô?ð 	 ð 0ÐL°MÐL��ÈˆØ$;Ð\Ð@QÐ\˜R˜RÐX\ÐØ"9ÐZÐ>OÐZ˜2˜2ÐVZÐØ'>Ð bÐCWÐ b  Ð^bÐð #ð 	 t¤{Ô'Eð 	ØVgÐ!q Ð.?Ô!@×!DÒ!DÀ\Ñ!RÔ!RÐ!RÐmqÐàH\Ðf�Ð.Ô/×3Ò3°OÑDÔDÐDÐbfð "õ
  %œz¨)¬/¸!Ô*<ÅEÄJÐW`ÔWgÐhÑhÔhÐà"ÐðP	Øð õ +0¬,Ð>PÐ7Y°s°sÐVYÑ*ZÔ*Z×*]Ò*]Ð^gÔ^nÑ*oÔ*oÐ'å”Ð 7½D¼MÔ<MÐNÑNÔNÐNà*×/Ò/Ñ1Ô1°SÒ8Ð8Ùð >˜4Ô=¸iÐXÐXÈ<ÐXÐXˆLð �dð ð Øðà Ø"3Ø%9ð	ð ð ð ˆGð ð Ð1ð Øà '¤¨q¨q¨q°"°a°a°a¨xÔ 8Ðð "2Ð!1°)Ð=NÑ!OÔ!OÐð 'ð Ø ð 4ØÐ1Ð3Ñ3�FØ$ð HØ&Ø9=¼Ô9WÐr˜Ô3Ð5Ð5Ð^eÔ^pÐ]rñÐ&ð ”{Ô5ð HØ(¨WÔ-EÐ,GÑGÐ(à'ð Ø)àœ;Ô9ð6˜Ô6Ð8Ð8à%Ô3Ð5ñÐ)õ  œ,Ð'9¸rÐBÑBÔBˆKð Ð'ØÐ'Ý$Ð%nÑoÔoÐoØ)Ð,@Ñ@À<ÐSTÐWkÑSkÑClÑl�õ œ	 9¨k¸!¸!¸!¸T¸'Ô.BÐ"CÈÐLÑLÔLˆIØÐ#Ø—’˜[Ÿ_š_Ñ.Ô.Ñ/Ô/Ð/Ø×CÒCØ˜¸$¼+Ô:Xð Dñ ô ˆLð
 #Ð.Ø';×'?Ò'?Ø×$Ò$Ð%8Ô%>¸qÔ%AÀ1ÑEÔE×HÒHÐI\×IfÒIfÐghÑIiÔIiÑjÔj×oÒoÐtuÐoÑvÔvñ(ô (Ð$ð
 (×+Ò+Ñ-Ô-°Ò2Ð2Ø)-Ð&ð !Ð  ¨FÑ3Ô3ð *Ø%)Ð"à!ð ¨+ð ØñaP	ðd ÐØ�LŠL‰NŒNˆNà"ð 	ØŒ{Ô-ð Ý7Ø'Ø!Ø'9Ø*?Ø'9Ø%5Ø*?ðñ ô ð õ 5Ø'Ø!Ø1Ø"7ð	ñ ô ð ð ÐrT   c           	      ó$	  — |�|nt          ¦   «         }|�|nt          ¦   «         }|�*t          j        dt          ¦  «         t          ||¦  «        }|�|nt          ¦   «         }|�|n| j        j        }|�|n| j        j        }t          |t          ¦  «        r|g}|�,t          j        |¦  «                             |j        ¦  «        nd}|
�|
n| j        j        }
|�|n| j        j        }|	�|	n| j        j        }	|�|n| j        j        }|r|
rdnd}|r|rdnd}|r|rdnd}|r|	rdnd}|rJ| j        j        r>|r|d                              d¦  «        nd}|	r|d                              d¦  «        nd}t          j        |j        d         t          j        |j        ¬¦  «        }d	}	 |rot          j        |rdnd¦  «                             |j        ¦  «        }t3          j        |t2          j        j        ¬¦  «         |                     ¦   «         dk    r�n' | j        |fi |¤Ž} | di |¤d
||	dœ¤Ž}|r|rŒ“|j        dd…ddd…f         } |||¦  «        } |||¦  «        }|ra|
r||fz  }|r6|| j        j        r|j         fn|j!        fz  }| j        j        r||j"        fz  }|	r|| j        j        r|j#        fn|j$        fz  }tJ          j&         '                    |d¬¦  «        }t          j(        |d¬¦  «         )                    d¦  «        }|�|€tU          d¦  «        ‚||z  |d|z
  z  z   }t          j+        ||dd…df         gd¬¦  «        }|�'| ,                    | -                    ¦   «         ¦  «         |  .                    ||| j        j        ¬¦  «        }|�ˆ| /                    | 0                    |j        d         d¦  «         1                    | 2                    d¦  «        ¦  «         3                    d¬¦  «        ¦  «        }| 4                    ¦   «         dk    rd
} |||¦  «        rd
}|r|sn�Œ˜|�| 5                    ¦   «          |r5| j        j        rtm          |||||||¬¦  «        S to          ||||¬¦  «        S |S )a�  
        Generates sequences of token ids for models with a language modeling head using **multinomial sampling** and
        can be used for text-decoder, text-to-text, speech-to-text, and vision-to-text models.

        <Tip warning={true}>

        In most cases, you do not need to call [`~generation.GenerationMixin.sample`] directly. Use generate() instead.
        For an overview of generation strategies and code examples, check the [following
        guide](../generation_strategies).

        </Tip>

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            logits_processor (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsProcessor`]
                used to modify the prediction scores of the language modeling head applied at each generation step.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            logits_warper (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsWarper`] used
                to warp the prediction score distribution of the language modeling head applied before multinomial
                sampling at each generation step.
            max_length (`int`, *optional*, defaults to 20):
                **DEPRECATED**. Use `logits_processor` or `stopping_criteria` directly to cap the number of generated
                tokens. The maximum length of the sequence to be generated.
            pad_token_id (`int`, *optional*):
                The id of the *padding* token.
            eos_token_id (`Union[int, List[int]]`, *optional*):
                The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more details.
            output_hidden_states (`bool`, *optional*, defaults to `False`):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more details.
            output_scores (`bool`, *optional*, defaults to `False`):
                Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
            return_dict_in_generate (`bool`, *optional*, defaults to `False`):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            synced_gpus (`bool`, *optional*, defaults to `False`):
                Whether to continue running the while loop until max_length (needed for ZeRO stage 3)
            streamer (`BaseStreamer`, *optional*):
                Streamer object that will be used to stream the generated sequences. Generated tokens are passed
                through `streamer.put(token_ids)` and the streamer is responsible for any further processing.
            model_kwargs:
                Additional model specific kwargs will be forwarded to the `forward` function of the model. If model is
                an encoder-decoder model the kwargs should include `encoder_outputs`.

        Return:
            [`~generation.SampleDecoderOnlyOutput`], [`~generation.SampleEncoderDecoderOutput`] or `torch.LongTensor`:
            A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.SampleDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.SampleEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.

        Examples:

        ```python
        >>> from transformers import (
        ...     AutoTokenizer,
        ...     AutoModelForCausalLM,
        ...     LogitsProcessorList,
        ...     MinLengthLogitsProcessor,
        ...     TopKLogitsWarper,
        ...     TemperatureLogitsWarper,
        ...     StoppingCriteriaList,
        ...     MaxLengthCriteria,
        ... )
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("gpt2")
        >>> model = AutoModelForCausalLM.from_pretrained("gpt2")

        >>> # set pad_token_id to eos_token_id because GPT2 does not have a EOS token
        >>> model.config.pad_token_id = model.config.eos_token_id
        >>> model.generation_config.pad_token_id = model.config.eos_token_id

        >>> input_prompt = "Today is a beautiful day, and"
        >>> input_ids = tokenizer(input_prompt, return_tensors="pt").input_ids

        >>> # instantiate logits processors
        >>> logits_processor = LogitsProcessorList(
        ...     [
        ...         MinLengthLogitsProcessor(15, eos_token_id=model.generation_config.eos_token_id),
        ...     ]
        ... )
        >>> # instantiate logits processors
        >>> logits_warper = LogitsProcessorList(
        ...     [
        ...         TopKLogitsWarper(50),
        ...         TemperatureLogitsWarper(0.7),
        ...     ]
        ... )

        >>> stopping_criteria = StoppingCriteriaList([MaxLengthCriteria(max_length=20)])

        >>> torch.manual_seed(0)  # doctest: +IGNORE_RESULT
        >>> outputs = model.sample(
        ...     input_ids,
        ...     logits_processor=logits_processor,
        ...     logits_warper=logits_warper,
        ...     stopping_criteria=stopping_criteria,
        ... )

        >>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
        ['Today is a beautiful day, and we must do everything possible to make it a day of celebration.']
        ```NúŒ`max_length` is deprecated in this function, use `stopping_criteria=StoppingCriteriaList(MaxLengthCriteria(max_length=max_length))` instead.rS   r¯   rH   rI   r   r±   FTr  r  rØ  r  r°   rç   r   ©Únum_samplesrå  ræ  rç  rè  )8r,   r>   rŽ  r�  r�  r?   rõ   r¿   rÀ   rº   rÃ   rO   ré  ra  r³   r¨  r¥  r¦  r©  r�   rž   r´   r·   r¼   r¸   r»  rê  rë  rì  rï   r�   r  rZ   rH   r[   r\   rI   r   rg  rî  Úmultinomialrâ  r£   rð   rÇ  rÈ  r  ró  rô  rÄ   r  rõ  rj  rö  rf   rd   )rŠ   r›   r1  rN  r§  rD  r¿   rÀ   r¥  r¦  r¨  r©  r¢  r£  r�   r÷  rG   rZ   r[   r\   rX   rY   rø  rù  rú  rû  rþ   r  Únext_token_scoresÚprobsr  s                                  rU   rx   zGenerationMixin.sample4
  s-  € ð@ 0@Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐØÐ!ÝŒMðoåñô ð õ
 !;Ð;LÈjÑ YÔ YÐØ)6Ð)B˜˜ÕH[ÑH]ÔH]ˆØ'3Ð'?�|�|ÀTÔE[ÔEhˆØ'3Ð'?�|�|ÀTÔE[ÔEhˆÝ�l¥CÑ(Ô(ð 	*Ø(˜>ˆLØQ]ÐQi�eœl¨<Ñ8Ô8×;Ò;¸IÔ<LÑMÔMÐMÐosÐØ)6Ð)B˜˜ÈÔH^ÔHlˆà!2Ð!>ÐÐÀDÔDZÔDlð 	ð %9Ð$DÐ Ð È$ÔJ`ÔJuð 	ð
 'Ð2ð $Ð#àÔ'Ô?ð 	 ð 0ÐL°MÐL��ÈˆØ$;Ð\Ð@QÐ\˜R˜RÐX\ÐØ"9ÐZÐ>OÐZ˜2˜2ÐVZÐØ'>Ð bÐCWÐ b  Ð^bÐð #ð 	 t¤{Ô'Eð 	ØVgÐ!q Ð.?Ô!@×!DÒ!DÀ\Ñ!RÔ!RÐ!RÐmqÐàH\Ðf�Ð.Ô/×3Ò3°OÑDÔDÐDÐbfð "õ
  %œz¨)¬/¸!Ô*<ÅEÄJÐW`ÔWgÐhÑhÔhÐà"ÐðR	Øð õ +0¬,Ð>PÐ7Y°s°sÐVYÑ*ZÔ*Z×*]Ò*]Ð^gÔ^nÑ*oÔ*oÐ'å”Ð 7½D¼MÔ<MÐNÑNÔNÐNà*×/Ò/Ñ1Ô1°SÒ8Ð8Ùð >˜4Ô=¸iÐXÐXÈ<ÐXÐXˆLð �dð ð Øðà Ø"3Ø%9ð	ð ð ð ˆGð ð Ð1ð Øà '¤¨q¨q¨q°"°a°a°a¨xÔ 8Ðð !1Ð 0°Ð<MÑ NÔ NÐØ - ¨iÐ9JÑ KÔ KÐð 'ð Ø ð 3ØÐ0Ð2Ñ2�FØ$ð HØ&Ø9=¼Ô9WÐr˜Ô3Ð5Ð5Ð^eÔ^pÐ]rñÐ&ð ”{Ô5ð HØ(¨WÔ-EÐ,GÑGÐ(à'ð Ø)àœ;Ô9ð6˜Ô6Ð8Ð8à%Ô3Ð5ñÐ)õ ”M×)Ò)Ð*;ÀÐ)ÑDÔDˆEÝÔ+¨E¸qÐAÑAÔA×IÒIÈ!ÑLÔLˆKð Ð'ØÐ'Ý$Ð%nÑoÔoÐoØ)Ð,@Ñ@À<ÐSTÐWkÑSkÑClÑl�õ œ	 9¨k¸!¸!¸!¸T¸'Ô.BÐ"CÈÐLÑLÔLˆIØÐ#Ø—’˜[Ÿ_š_Ñ.Ô.Ñ/Ô/Ð/Ø×CÒCØ˜¸$¼+Ô:Xð Dñ ô ˆLð
 #Ð.Ø';×'?Ò'?Ø×$Ò$Ð%8Ô%>¸qÔ%AÀ1ÑEÔE×HÒHÐI\×IfÒIfÐghÑIiÔIiÑjÔj×oÒoÐtuÐoÑvÔvñ(ô (Ð$ð
 (×+Ò+Ñ-Ô-°Ò2Ð2Ø)-Ð&ð !Ð  ¨FÑ3Ô3ð *Ø%)Ð"à!ð ¨+ð ØñeR	ðh ÐØ�LŠL‰NŒNˆNà"ð 	ØŒ{Ô-ð Ý1Ø'Ø!Ø'9Ø*?Ø'9Ø%5Ø*?ðñ ô ð õ /Ø'Ø!Ø1Ø"7ð	ñ ô ð ð ÐrT   rÒ  c                 óF  ‡'‡(— |�|nt          ¦   «         }|�|nt          ¦   «         }|�*t          j        dt          ¦  «         t          ||¦  «        }t          |¦  «        dk    rt          j        dt          ¦  «         |�|n| j        j        }|�|n| j        j	        }t          |t          ¦  «        r|g}|
�|
n| j        j        }
|�|n| j        j        }|	�|	n| j        j        }	|�|n| j        j        }t          |j        ¦  «        }|j        }|j        \  }}||z  |k    rt'          d||z  › d|› d�¦  «        ‚|r|
rdnd}|r(|
r&t)          d	„ t+          |¦  «        D ¦   «         ¦  «        ndŠ(|r|rdnd}|r|rdnd}|r|	rdnd}|rJ| j        j        r>|r|d
                              d¦  «        nd}|	r|d
                              d¦  «        nd}t3          j        ||ft2          j        |j        ¬¦  «        }d|dd…dd…f<   |                     ||z  f¦  «        }d}	 |rot3          j        |rdnd¦  «                             |j        ¦  «        }tA          j!        |t@          j"        j#        ¬¦  «         | $                    ¦   «         dk    r�n| | j%        |fi |¤Ž} | di |¤d||	dœ¤Ž}|r|r|dz   }Œ˜|j&        dd…ddd…f         }tN          j(         )                    |d¬¦  «        } |||¦  «        }||dd…df          *                    |¦  «        z   }|ra|
r||fz  }|r6|| j        j        r|j+        fn|j,        fz  }| j        j        r||j-        fz  }|	r|| j        j        r|j.        fn|j/        fz  }|j        d         } |                     ||| z  ¦  «        }|rt          |¦  «        nd}!t3          j0        |tc          dd|!z   ¦  «        |z  ddd¬¦  «        \  }}"t3          j2        |"| d¬¦  «        }#|"| z  }"| 3                    |||"|#||‰(¬¦  «        }$|$d         }|$d         }%|$d         Š't3          j4        |‰'dd…f         |% 5                    d¦  «        gd¬¦  «        }|  6                    ||| j        j        ¬ ¦  «        }|d!         �|  7                    |d!         ‰'¦  «        |d!<   |r8|
r6t)          ˆ'ˆ(fd"„t+          t          ‰(¦  «        ¦  «        D ¦   «         ¦  «        Š(|dz   }|j8        s |||¦  «        r|snd}�Œí| 9                    |||"|#|||j:        ‰(¬#¦  «        }&|rd|
sd|&d$<   | j        j        r*tw          |&d%         |&d$         ||&d&         |||||¬'¦	  «	        S ty          |&d%         |&d$         ||&d&         ||¬(¦  «        S |&d%         S ))aÅ  
        Generates sequences of token ids for models with a language modeling head using **beam search decoding** and
        can be used for text-decoder, text-to-text, speech-to-text, and vision-to-text models.

        <Tip warning={true}>

        In most cases, you do not need to call [`~generation.GenerationMixin.beam_search`] directly. Use generate()
        instead. For an overview of generation strategies and code examples, check the [following
        guide](../generation_strategies).

        </Tip>

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            beam_scorer (`BeamScorer`):
                An derived instance of [`BeamScorer`] that defines how beam hypotheses are constructed, stored and
                sorted during generation. For more information, the documentation of [`BeamScorer`] should be read.
            logits_processor (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsProcessor`]
                used to modify the prediction scores of the language modeling head applied at each generation step.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            max_length (`int`, *optional*, defaults to 20):
                **DEPRECATED**. Use `logits_processor` or `stopping_criteria` directly to cap the number of generated
                tokens. The maximum length of the sequence to be generated.
            pad_token_id (`int`, *optional*):
                The id of the *padding* token.
            eos_token_id (`Union[int, List[int]]`, *optional*):
                The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more details.
            output_hidden_states (`bool`, *optional*, defaults to `False`):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more details.
            output_scores (`bool`, *optional*, defaults to `False`):
                Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
            return_dict_in_generate (`bool`, *optional*, defaults to `False`):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            synced_gpus (`bool`, *optional*, defaults to `False`):
                Whether to continue running the while loop until max_length (needed for ZeRO stage 3)
            model_kwargs:
                Additional model specific kwargs will be forwarded to the `forward` function of the model. If model is
                an encoder-decoder model the kwargs should include `encoder_outputs`.

        Return:
            [`generation.BeamSearchDecoderOnlyOutput`], [`~generation.BeamSearchEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.BeamSearchDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.BeamSearchEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.


        Examples:

        ```python
        >>> from transformers import (
        ...     AutoTokenizer,
        ...     AutoModelForSeq2SeqLM,
        ...     LogitsProcessorList,
        ...     MinLengthLogitsProcessor,
        ...     BeamSearchScorer,
        ... )
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("t5-base")
        >>> model = AutoModelForSeq2SeqLM.from_pretrained("t5-base")

        >>> encoder_input_str = "translate English to German: How old are you?"
        >>> encoder_input_ids = tokenizer(encoder_input_str, return_tensors="pt").input_ids


        >>> # lets run beam search using 3 beams
        >>> num_beams = 3
        >>> # define decoder start token ids
        >>> input_ids = torch.ones((num_beams, 1), device=model.device, dtype=torch.long)
        >>> input_ids = input_ids * model.config.decoder_start_token_id

        >>> # add encoder_outputs to model keyword arguments
        >>> model_kwargs = {
        ...     "encoder_outputs": model.get_encoder()(
        ...         encoder_input_ids.repeat_interleave(num_beams, dim=0), return_dict=True
        ...     )
        ... }

        >>> # instantiate beam scorer
        >>> beam_scorer = BeamSearchScorer(
        ...     batch_size=1,
        ...     num_beams=num_beams,
        ...     device=model.device,
        ... )

        >>> # instantiate logits processors
        >>> logits_processor = LogitsProcessorList(
        ...     [
        ...         MinLengthLogitsProcessor(5, eos_token_id=model.config.eos_token_id),
        ...     ]
        ... )

        >>> outputs = model.beam_search(input_ids, beam_scorer, logits_processor=logits_processor, **model_kwargs)

        >>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
        ['Wie alt bist du?']
        ```Nr  r   úKYou don't have defined any stopping_criteria, this will likely loop foreverú)Batch dimension of `input_ids` should be ú	, but is rW  rS   c              3   ó   K  — | ]}d V — ŒdS ©rS   NrS   ©r–   rþ  s     rU   r×   z.GenerationMixin.beam_search.<locals>.<genexpr>ò  ó"   è è € Ð5Ð5˜�"Ð5Ð5Ð5Ð5Ð5Ð5rT   r¯   rH   rI   r±   ç    eÍÍÁr   FTr  r  rØ  r  r°   rç   r   ©rè   ÚlargestÚsortedÚfloor©Úrounding_mode©r¿   rÀ   rj   Únext_beam_scoresÚnext_beam_tokensÚnext_beam_indicesræ  r  c              3   óH   •K  — | ]}‰‰|                  ‰|         fz   V — Œd S r•   rS   ©r–   rÜ  r  rj   s     €€rU   r×   z.GenerationMixin.beam_search.<locals>.<genexpr>_  ó8   øè è € Ð%sÐ%sÐUV l°8¸A´;Ô&?À8ÈAÄ;À.Ñ&PÐ%sÐ%sÐ%sÐ%sÐ%sÐ%srT   ©r¿   rÀ   rD  rj   Úsequence_scoresrF   rj   ©	rF   ri   rG   rj   rX   rY   rZ   r[   r\   ©rF   ri   rG   rj   rH   rI   )=r,   r>   rŽ  r�  r�  r?   rÂ   rõ   r¿   rÀ   rº   rÃ   r¨  r¥  r¦  r©  Ú
_beam_hypsr  r¼   r£   rí  rð  r�   rž   r´   rO   ÚzerosÚfloatr³   r`  ré  ra  r»  rê  rë  rì  rï   r�   r  r   rg  rh  Ú	expand_asrZ   rH   r[   r\   rI   rï  rj  ÚdivÚprocessrð   r  r  r  Úis_doneÚfinalizerD  rn   rh   ))rŠ   r›   rÒ  r1  rN  rD  r¿   rÀ   r¥  r¦  r¨  r©  r¢  r�   r½   r  Úbatch_beam_sizeÚcur_lenrG   rZ   r[   r\   rX   rY   Úbeam_scoresrù  rú  rû  rþ   r  r  Únext_token_scores_processedrf  Ún_eos_tokensr  Únext_indicesÚbeam_outputsÚbeam_next_tokensÚsequence_outputsr  rj   s)                                          @@rU   rz   zGenerationMixin.beam_searchN  sõ  øø€ ðv 0@Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐØÐ!ÝŒMðoåñô ð õ
 !;Ð;LÈjÑ YÔ YÐÝÐ Ñ!Ô! QÒ&Ð&ÝŒMÐgÕitÑuÔuÐuØ'3Ð'?�|�|ÀTÔE[ÔEhˆØ'3Ð'?�|�|ÀTÔE[ÔEhˆÝ�l¥CÑ(Ô(ð 	*Ø(˜>ˆLØ)6Ð)B˜˜ÈÔH^ÔHlˆà!2Ð!>ÐÐÀDÔDZÔDlð 	ð %9Ð$DÐ Ð È$ÔJ`ÔJuð 	ð
 'Ð2ð $Ð#àÔ'Ô?ð 	 õ ˜Ô/Ñ0Ô0ˆ
ØÔ)ˆ	à#,¤?Ñ ˆ˜à�zÑ! _Ò4Ð4ÝØo¸IÈ
Ñ<RÐoÐoÐ]lÐoÐoÐoñô ð ð
 0ÐL°MÐL��Èˆà:QÐnÐVcÐn�EÐ5Ð5�e OÑ4Ô4Ð5Ñ5Ô5Ñ5Ô5Ð5Ðjnð 	ð %<Ð\Ð@QÐ\˜R˜RÐX\ÐØ"9ÐZÐ>OÐZ˜2˜2ÐVZÐØ'>Ð bÐCWÐ b  Ð^bÐð #ð 	 t¤{Ô'Eð 	ØVgÐ!q Ð.?Ô!@×!DÒ!DÀ\Ñ!RÔ!RÐ!RÐmqÐàH\Ðf�Ð.Ô/×3Ò3°OÑDÔDÐDÐbfð "õ ”k :¨yÐ"9ÅÄÐU^ÔUeÐfÑfÔfˆØ!ˆ�A�A�A�q�r�r�EÑØ!×&Ò&¨
°YÑ(>Ð'@ÑAÔAˆà"Ððb	.Øð õ +0¬,Ð>PÐ7Y°s°sÐVYÑ*ZÔ*Z×*]Ò*]Ð^gÔ^nÑ*oÔ*oÐ'å”Ð 7½D¼MÔ<MÐNÑNÔNÐNà*×/Ò/Ñ1Ô1°SÒ8Ð8Ùà=˜4Ô=¸iÐXÐXÈ<ÐXÐXˆLà�dð ð Øðà Ø"3Ø%9ð	ð ð ð ˆGð ð Ð1ð Ø! A™+�Øà '¤¨q¨q¨q°"°a°a°a¨xÔ 8ÐÝ "¤× 9Ò 9Ø! rð !:ñ !ô !Ðð +;Ð*:¸9ÐFWÑ*XÔ*XÐ'Ø ;¸kÈ!È!È!ÈTÈ'Ô>R×>\Ò>\Ø+ñ?ô ?ñ !Ðð
 'ð Ø ð =ØÐ:Ð<Ñ<�FØ$ð HØ&Ø9=¼Ô9WÐr˜Ô3Ð5Ð5Ð^eÔ^pÐ]rñÐ&ð ”{Ô5ð HØ(¨WÔ-EÐ,GÑGÐ(à'ð Ø)àœ;Ô9ð6˜Ô6Ð8Ð8à%Ô3Ð5ñÐ)ð +Ô0°Ô4ˆJØ 1× 6Ò 6°zÀ9ÈzÑCYÑ ZÔ ZÐð 1=ÐC�3˜|Ñ,Ô,Ð,À!ˆLÝ-2¬ZØ!¥3 q¨!¨lÑ*:Ñ#;Ô#;¸iÑ#GÈQÐX\Ðeið.ñ .ô .Ñ*Ð˜{õ !œ9 [°*ÈGÐTÑTÔTˆLØ%¨
Ñ2ˆKð '×.Ò.ØØ!ØØØ)Ø)Ø)ð /ñ ô ˆLð 'Ð'9Ô:ˆKØ+Ð,>Ô?ÐØ#Ð$7Ô8ˆHåœ	 9¨X°q°q°q¨[Ô#9Ð;K×;UÒ;UÐVXÑ;YÔ;YÐ"ZÐ`bÐcÑcÔcˆIà×CÒCØ˜¸$¼+Ô:Xð Dñ ô ˆLð Ð-Ô.Ð:Ø26×2EÒ2EÀlÐSdÔFeÐgoÑ2pÔ2p�Ð.Ñ/à&ð u¨=ð uÝ$Ð%sÐ%sÐ%sÐ%sÐ%sÕZ_Õ`cÐdpÑ`qÔ`qÑZrÔZrÐ%sÑ%sÔ%sÑtÔt�ð  ‘kˆGàÔ"ð .Ð&7Ð&7¸	À6Ñ&JÔ&Jð .Ø"ð .Øà)-Ð&ñEb	.ðH '×/Ò/ØØØØØ%Ø%Ø(Ô3Ø%ð 0ñ 	
ô 	
Ðð #ð 	1Ø ð ;Ø6:Ð Ð!2Ñ3àŒ{Ô-ð Ý5Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø!1°.Ô!AØ'9Ø*?Ø'9Ø%5Ø*?ð
ñ 
ô 
ð 
õ 3Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø!1°.Ô!AØ1Ø"7ðñ ô ð ð $ KÔ0Ð0rT   c                 ó$  ‡)‡*— |�|nt          ¦   «         }|�|nt          ¦   «         }|�*t          j        dt          ¦  «         t          ||¦  «        }|�|n| j        j        }|�|n| j        j        }t          |t          ¦  «        r|g}|�|n| j        j        }|	�|	n| j        j        }	|
�|
n| j        j        }
|�|n| j        j        }t          |j        ¦  «        }|j        }|j        \  }}|r|rdnd}|r(|r&t'          d„ t)          |¦  «        D ¦   «         ¦  «        ndŠ*|r|	rdnd}|r|	rdnd}|r|
rdnd}|rJ| j        j        r>|	r|d                              d¦  «        nd}|
r|d                              d¦  «        nd}t1          j        ||ft0          j        |j        ¬¦  «        }|                     ||z  f¦  «        }d	}	 |rot1          j        |rdnd¦  «                             |j        ¦  «        }t?          j         |t>          j!        j"        ¬¦  «         | #                    ¦   «         dk    r�nÅ | j$        |fi |¤Ž} | di |¤d
|	|
dœ¤Ž}|r|r|dz   }Œ˜|j%        dd…ddd…f         }tL          j'         (                    |d¬¦  «        } |||¦  «        }  ||| ¦  «        } | |dd…df          )                    | ¦  «        z   }|ra|r|| fz  }|	r6|| j        j        r|j*        fn|j+        fz  }| j        j        r||j,        fz  }|
r|| j        j        r|j-        fn|j.        fz  }|j        d         }!|                     |||!z  ¦  «        }tL          j'         /                    |d¬¦  «        }"t1          j0        |"d|z  ¬¦  «        }#t1          j1        |d|#¦  «        }t1          j2        |d
d¬¦  «        \  }}$t1          j1        |#d|$¦  «        }#t1          j3        |#|!d¬¦  «        }%|#|!z  }#| 4                    |||#|%||‰*¬¦  «        }&|&d         }|&d         }'|&d         Š)t1          j5        |‰)dd…f         |' 6                    d¦  «        gd¬¦  «        }|  7                    ||| j        j        ¬¦  «        }|d         �|  8                    |d         ‰)¦  «        |d<   |r8|r6t'          ˆ)ˆ*fd„t)          t          ‰*¦  «        ¦  «        D ¦   «         ¦  «        Š*|dz   }|j9        s |||¦  «        r|snd
}�Œ6| :                    |||#|%|||j;        ‰*¬¦  «        }(|rd|sd|(d<   | j        j        r*ty          |(d          |(d         ||(d!         |||||¬"¦	  «	        S t{          |(d          |(d         ||(d!         ||¬#¦  «        S |(d          S )$a§  
        Generates sequences of token ids for models with a language modeling head using **beam search multinomial
        sampling** and can be used for text-decoder, text-to-text, speech-to-text, and vision-to-text models.

        <Tip warning={true}>

        In most cases, you do not need to call [`~generation.GenerationMixin.beam_sample`] directly. Use generate()
        instead. For an overview of generation strategies and code examples, check the [following
        guide](../generation_strategies).

        </Tip>

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            beam_scorer (`BeamScorer`):
                A derived instance of [`BeamScorer`] that defines how beam hypotheses are constructed, stored and
                sorted during generation. For more information, the documentation of [`BeamScorer`] should be read.
            logits_processor (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsProcessor`]
                used to modify the prediction scores of the language modeling head applied at each generation step.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            logits_warper (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsWarper`] used
                to warp the prediction score distribution of the language modeling head applied before multinomial
                sampling at each generation step.
            max_length (`int`, *optional*, defaults to 20):
                **DEPRECATED**. Use `logits_processor` or `stopping_criteria` directly to cap the number of generated
                tokens. The maximum length of the sequence to be generated.
            pad_token_id (`int`, *optional*):
                The id of the *padding* token.
            eos_token_id (`Union[int, List[int]]`, *optional*):
                The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more details.
            output_hidden_states (`bool`, *optional*, defaults to `False`):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more details.
            output_scores (`bool`, *optional*, defaults to `False`):
                Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
            return_dict_in_generate (`bool`, *optional*, defaults to `False`):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            synced_gpus (`bool`, *optional*, defaults to `False`):
                Whether to continue running the while loop until max_length (needed for ZeRO stage 3)
            model_kwargs:
                Additional model specific kwargs will be forwarded to the `forward` function of the model. If model is
                an encoder-decoder model the kwargs should include `encoder_outputs`.

        Return:
            [`~generation.BeamSampleDecoderOnlyOutput`], [`~generation.BeamSampleEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.BeamSampleDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.BeamSampleEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.

        Examples:

        ```python
        >>> from transformers import (
        ...     AutoTokenizer,
        ...     AutoModelForSeq2SeqLM,
        ...     LogitsProcessorList,
        ...     MinLengthLogitsProcessor,
        ...     TopKLogitsWarper,
        ...     TemperatureLogitsWarper,
        ...     BeamSearchScorer,
        ... )
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("t5-base")
        >>> model = AutoModelForSeq2SeqLM.from_pretrained("t5-base")

        >>> encoder_input_str = "translate English to German: How old are you?"
        >>> encoder_input_ids = tokenizer(encoder_input_str, return_tensors="pt").input_ids

        >>> # lets run beam search using 3 beams
        >>> num_beams = 3
        >>> # define decoder start token ids
        >>> input_ids = torch.ones((num_beams, 1), device=model.device, dtype=torch.long)
        >>> input_ids = input_ids * model.config.decoder_start_token_id

        >>> # add encoder_outputs to model keyword arguments
        >>> model_kwargs = {
        ...     "encoder_outputs": model.get_encoder()(
        ...         encoder_input_ids.repeat_interleave(num_beams, dim=0), return_dict=True
        ...     )
        ... }

        >>> # instantiate beam scorer
        >>> beam_scorer = BeamSearchScorer(
        ...     batch_size=1,
        ...     max_length=model.config.max_length,
        ...     num_beams=num_beams,
        ...     device=model.device,
        ... )

        >>> # instantiate logits processors
        >>> logits_processor = LogitsProcessorList(
        ...     [MinLengthLogitsProcessor(5, eos_token_id=model.config.eos_token_id)]
        ... )
        >>> # instantiate logits processors
        >>> logits_warper = LogitsProcessorList(
        ...     [
        ...         TopKLogitsWarper(50),
        ...         TemperatureLogitsWarper(0.7),
        ...     ]
        ... )

        >>> outputs = model.beam_sample(
        ...     input_ids, beam_scorer, logits_processor=logits_processor, logits_warper=logits_warper, **model_kwargs
        ... )

        >>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
        ['Wie alt bist du?']
        ```Nr  rS   c              3   ó   K  — | ]}d V — ŒdS r$  rS   r%  s     rU   r×   z.GenerationMixin.beam_sample.<locals>.<genexpr>;  r&  rT   r¯   rH   rI   r±   FTr  r  rØ  r  r   r°   rç   r   r  )Ú
descendingrè   r+  r,  r.  r/  r0  r1  ræ  r  c              3   óH   •K  — | ]}‰‰|                  ‰|         fz   V — Œd S r•   rS   r3  s     €€rU   r×   z.GenerationMixin.beam_sample.<locals>.<genexpr>¨  r4  rT   r5  r6  rF   rj   r7  r8  )>r,   r>   rŽ  r�  r�  r?   rõ   r¿   rÀ   rº   rÃ   r¨  r¥  r¦  r©  rÂ   r9  r  r¼   rí  rð  r�   rž   r´   rO   r:  r;  r³   r`  ré  ra  r»  rê  rë  rì  rï   r�   r  r   rg  rh  r<  rZ   rH   r[   r\   rI   rî  r  rl  Úsortr=  r>  rð   r  r  r  r?  r@  rD  rs   rq   )+rŠ   r›   rÒ  r1  rN  r§  rD  r¿   rÀ   r¥  r¦  r¨  r©  r¢  r�   r½   r  rA  rB  rG   rZ   r[   r\   rX   rY   rC  rù  rú  rû  rþ   r  r  rD  rf  r  r  Ú_indicesrF  rG  rH  rI  r  rj   s+                                            @@rU   r{   zGenerationMixin.beam_sample‘  s¯  øø€ ðP 0@Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐØÐ!ÝŒMðoåñô ð õ
 !;Ð;LÈjÑ YÔ YÐØ'3Ð'?�|�|ÀTÔE[ÔEhˆØ'3Ð'?�|�|ÀTÔE[ÔEhˆÝ�l¥CÑ(Ô(ð 	*Ø(˜>ˆLØ)6Ð)B˜˜ÈÔH^ÔHlˆà!2Ð!>ÐÐÀDÔDZÔDlð 	ð %9Ð$DÐ Ð È$ÔJ`ÔJuð 	ð
 'Ð2ð $Ð#àÔ'Ô?ð 	 õ ˜Ô/Ñ0Ô0ˆ
ØÔ)ˆ	à#,¤?Ñ ˆ˜ð 0ÐL°MÐL��Èˆà:QÐnÐVcÐn�EÐ5Ð5�e OÑ4Ô4Ð5Ñ5Ô5Ñ5Ô5Ð5Ðjnð 	ð %<Ð\Ð@QÐ\˜R˜RÐX\ÐØ"9ÐZÐ>OÐZ˜2˜2ÐVZÐØ'>Ð bÐCWÐ b  Ð^bÐð #ð 	 t¤{Ô'Eð 	ØVgÐ!q Ð.?Ô!@×!DÒ!DÀ\Ñ!RÔ!RÐ!RÐmqÐàH\Ðf�Ð.Ô/×3Ò3°OÑDÔDÐDÐbfð "õ ”k :¨yÐ"9ÅÄÐU^ÔUeÐfÑfÔfˆØ!×&Ò&¨
°YÑ(>Ð'@ÑAÔAˆà"Ððe	.Øð õ +0¬,Ð>PÐ7Y°s°sÐVYÑ*ZÔ*Z×*]Ò*]Ð^gÔ^nÑ*oÔ*oÐ'å”Ð 7½D¼MÔ<MÐNÑNÔNÐNà*×/Ò/Ñ1Ô1°SÒ8Ð8Ùà=˜4Ô=¸iÐXÐXÈ<ÐXÐXˆLà�dð ð Øðà Ø"3Ø%9ð	ð ð ð ˆGð ð Ð1ð Ø! A™+�Øà '¤¨q¨q¨q°"°a°a°a¨xÔ 8Ðå "¤× 9Ò 9Ø! rð !:ñ !ô !Ðð +;Ð*:¸9ÐFWÑ*XÔ*XÐ'Ø*7¨-¸	ÐC^Ñ*_Ô*_Ð'Ø ;¸kÈ!È!È!ÈTÈ'Ô>R×>\Ò>\Ø+ñ?ô ?ñ !Ðð
 'ð Ø ð =ØÐ:Ð<Ñ<�FØ$ð HØ&Ø9=¼Ô9WÐr˜Ô3Ð5Ð5Ð^eÔ^pÐ]rñÐ&ð ”{Ô5ð HØ(¨WÔ-EÐ,GÑGÐ(à'ð Ø)àœ;Ô9ð6˜Ô6Ð8Ð8à%Ô3Ð5ñÐ)ð +Ô0°Ô4ˆJØ 1× 6Ò 6°zÀ9ÈzÑCYÑ ZÔ ZÐå”M×)Ò)Ð*;ÀÐ)ÑDÔDˆEåÔ+¨E¸qÀ9¹}ÐMÑMÔMˆKÝ %¤Ð->ÀÀKÑ PÔ PÐå*/¬*Ð5FÐSWÐ]^Ð*_Ñ*_Ô*_Ñ'Ð˜xÝœ, {°B¸ÑAÔAˆKå œ9 [°*ÈGÐTÑTÔTˆLØ%¨
Ñ2ˆKð '×.Ò.ØØ!ØØØ)Ø)Ø)ð /ñ ô ˆLð 'Ð'9Ô:ˆKØ+Ð,>Ô?ÐØ#Ð$7Ô8ˆHåœ	 9¨X°q°q°q¨[Ô#9Ð;K×;UÒ;UÐVXÑ;YÔ;YÐ"ZÐ`bÐcÑcÔcˆIà×CÒCØ˜¸$¼+Ô:Xð Dñ ô ˆLð Ð-Ô.Ð:Ø26×2EÒ2EÀlÐSdÔFeÐgoÑ2pÔ2p�Ð.Ñ/à&ð u¨=ð uÝ$Ð%sÐ%sÐ%sÐ%sÐ%sÕZ_Õ`cÐdpÑ`qÔ`qÑZrÔZrÐ%sÑ%sÔ%sÑtÔt�ð  ‘kˆGàÔ"ð .Ð&7Ð&7¸	À6Ñ&JÔ&Jð .Ø"ð .Øà)-Ð&ñKe	.ðN '×/Ò/ØØØØØ%Ø%Ø(Ô3Ø%ð 0ñ 	
ô 	
Ðð #ð 	1Ø ð ;Ø6:Ð Ð!2Ñ3àŒ{Ô-ð Ý5Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø!1°.Ô!AØ'9Ø*?Ø'9Ø%5Ø*?ð
ñ 
ô 
ð 
õ 3Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø!1°.Ô!AØ1Ø"7ðñ ô ð ð $ KÔ0Ð0rT   c                 óN  ‡1‡2‡3‡4‡5‡6‡7— |�|nt          ¦   «         }|�|nt          ¦   «         }|�*t          j        dt          ¦  «         t          ||¦  «        }|�|n| j        j        }|�|n| j        j        }t          |t          ¦  «        r|g}|
�|
n| j        j        }
|�|n| j        j        }|	�|	n| j        j        }	|�|n| j        j        }|j        Š6|j        }‰6|z  Š7t#          |j        ¦  «        |z  Š2|j        }|j        \  }}|r|
rˆ2ˆ7fd„t+          |¦  «        D ¦   «         Š5ndŠ5‰6‰2z  |k    rt-          d‰6‰2z  › d|› d�¦  «        ‚|r|
rdnd}|r|rdnd}|r|rdnd}|r|	rdnd}|rJ| j        j        r>|r|d                              d	¦  «        nd}|	r|d                              d
¦  «        nd}t5          j        ‰2‰6fdt4          j        |¬¦  «        }d|dd…dd‰7…f<   |                     ‰2‰6z  f¦  «        }d}	 |rot5          j        |rdnd¦  «                             |j        ¦  «        }tA          j!        |t@          j"        j#        ¬¦  «         | $                    ¦   «         dk    r�n
t5          j%        ‰2‰6z  |j&        |¬¦  «        }t5          j%        ‰2‰6z  t4          j'        |¬¦  «        } | j(        |fi |¤Ž} | di |¤d||	dœ¤Ž}|r|r|dz   }ŒÛ|
r&t5          j)        |j*        dd…ddd…f         ¦  «        }t+          |¦  «        D �]rŠ3‰3‰7z  } tW          | ‰7z   ‰6¦  «        }!|!| z
  }"g }#t+          ‰2¦  «        D ]2Š1|# ,                    ˆ1ˆ6fd„t+          | |!¦  «        D ¦   «         ¦  «         Œ3||#         }$|j*        |#ddd…f         }%tZ          j.         /                    |%d¬¦  «        }&|&j        d         }' ||$|&|‰3¬¦  «        }(|(||#          0                    d¦  «        z   }&|& 1                    |(¦  «        }&|
r|(||#<   |&                     ‰2|"|'z  ¦  «        }&|rt#          |¦  «        nd})t5          j2        |&tg          dd|)z   ¦  «        |"z  ddd¬¦  «        \  }&}*t5          j4        |*|'d¬¦  «        }+|*|'z  }*‰5�tk          ‰5d¦  «        nd},| 6                    |$|&|*|+|||,‰3¬¦  «        }-|-d         ||#<   |-d         }.|-d          Š4|rB|
r@to          ˆ3ˆ4ˆ5fd!„t+          t#          ‰5d         ¦  «        ¦  «        D ¦   «         ¦  «        ‰5‰3<   |$‰4         ||#<   t5          j8        |$‰4dd…f         |. 0                    d¦  «        gd¬¦  «        }$|$dd…df         ||#<   ‰6t5          j4        ‰4|"d¬¦  «        z  | z   ‰4|"z  z   ||#<   �Œt|ra|
r||fz  }|r6|| j        j        r|j9        fn|j:        fz  }| j        j        r||j;        fz  }|	r|| j        j        r|j<        fn|j=        fz  }t5          j8        || 0                    d¦  «        gd¬¦  «        }|  >                    ||| j        j        ¬"¦  «        }|d#         �|  ?                    |d#         |¦  «        |d#<   |dz   }|j@        s |||¦  «        r|snd}�Œ{‰5�tk          ‰5d¦  «        nd}/| A                    |||*|+|||jB        |/¬$¦  «        }0|rd|
sd|0d%<   | j        j        r*t‡          |0d&         |0d%         ||0d'         |||||¬(¦	  «	        S t‰          |0d&         |0d%         ||0d'         ||¬)¦  «        S |0d&         S )*a  
        Generates sequences of token ids for models with a language modeling head using **diverse beam search
        decoding** and can be used for text-decoder, text-to-text, speech-to-text, and vision-to-text models.

        <Tip warning={true}>

        In most cases, you do not need to call [`~generation.GenerationMixin.group_beam_search`] directly. Use
        generate() instead. For an overview of generation strategies and code examples, check the [following
        guide](../generation_strategies).

        </Tip>

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            beam_scorer (`BeamScorer`):
                An derived instance of [`BeamScorer`] that defines how beam hypotheses are constructed, stored and
                sorted during generation. For more information, the documentation of [`BeamScorer`] should be read.
            logits_processor (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsProcessor`]
                used to modify the prediction scores of the language modeling head applied at each generation step.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            max_length (`int`, *optional*, defaults to 20):
                **DEPRECATED**. Use `logits_processor` or `stopping_criteria` directly to cap the number of generated
                tokens. The maximum length of the sequence to be generated.
            pad_token_id (`int`, *optional*):
                The id of the *padding* token.
            eos_token_id (`Union[int, List[int]]`, *optional*):
                The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more details.
            output_hidden_states (`bool`, *optional*, defaults to `False`):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more details.
            output_scores (`bool`, *optional*, defaults to `False`):
                Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
            return_dict_in_generate (`bool`, *optional*, defaults to `False`):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            synced_gpus (`bool`, *optional*, defaults to `False`):
                Whether to continue running the while loop until max_length (needed for ZeRO stage 3)

            model_kwargs:
                Additional model specific kwargs that will be forwarded to the `forward` function of the model. If
                model is an encoder-decoder model the kwargs should include `encoder_outputs`.

        Return:
            [`~generation.BeamSearchDecoderOnlyOutput`], [`~generation.BeamSearchEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.BeamSearchDecoderOnlyOutput`] if [`~generation.BeamSearchDecoderOnlyOutput`] if
            `model.config.is_encoder_decoder=False` and `return_dict_in_generate=True` or a
            [`~generation.BeamSearchEncoderDecoderOutput`] if `model.config.is_encoder_decoder=True`.

        Examples:

        ```python
        >>> from transformers import (
        ...     AutoTokenizer,
        ...     AutoModelForSeq2SeqLM,
        ...     LogitsProcessorList,
        ...     MinLengthLogitsProcessor,
        ...     HammingDiversityLogitsProcessor,
        ...     BeamSearchScorer,
        ... )
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("t5-base")
        >>> model = AutoModelForSeq2SeqLM.from_pretrained("t5-base")

        >>> encoder_input_str = "translate English to German: How old are you?"
        >>> encoder_input_ids = tokenizer(encoder_input_str, return_tensors="pt").input_ids


        >>> # lets run diverse beam search using 6 beams
        >>> num_beams = 6
        >>> # define decoder start token ids
        >>> input_ids = torch.ones((num_beams, 1), device=model.device, dtype=torch.long)
        >>> input_ids = input_ids * model.config.decoder_start_token_id

        >>> # add encoder_outputs to model keyword arguments
        >>> model_kwargs = {
        ...     "encoder_outputs": model.get_encoder()(
        ...         encoder_input_ids.repeat_interleave(num_beams, dim=0), return_dict=True
        ...     )
        ... }

        >>> # instantiate beam scorer
        >>> beam_scorer = BeamSearchScorer(
        ...     batch_size=1,
        ...     max_length=model.config.max_length,
        ...     num_beams=num_beams,
        ...     device=model.device,
        ...     num_beam_groups=3,
        ... )

        >>> # instantiate logits processors
        >>> logits_processor = LogitsProcessorList(
        ...     [
        ...         HammingDiversityLogitsProcessor(5.5, num_beams=6, num_beam_groups=3),
        ...         MinLengthLogitsProcessor(5, eos_token_id=model.config.eos_token_id),
        ...     ]
        ... )

        >>> outputs = model.group_beam_search(
        ...     input_ids, beam_scorer, logits_processor=logits_processor, **model_kwargs
        ... )

        >>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
        ['Wie alt bist du?']
        ```Nr  c           	      ób   •— g | ]+}t          d „ t          ‰‰z  ¦  «        D ¦   «         ¦  «        ‘Œ,S )c              3   ó   K  — | ]}d V — ŒdS r$  rS   r%  s     rU   r×   z?GenerationMixin.group_beam_search.<locals>.<listcomp>.<genexpr>~  s"   è è € Ð!PÐ!P¨ "Ð!PÐ!PÐ!PÐ!PÐ!PÐ!PrT   )rí  rð  )r–   rþ  r½   Únum_sub_beamss     €€rU   rÞ  z5GenerationMixin.group_beam_search.<locals>.<listcomp>~  s>   ø€ ÐqÐqÐqÐUV�EÐ!PÐ!P­e°MÀJÑ4NÑ.OÔ.OÐ!PÑ!PÔ!PÑPÔPÐqÐqÐqrT   r!  r"  rW  rS   r¯   rH   rI   r'  r±   r   FTr  r  rØ  r  r   r°   c                 ó    •— g | ]
}‰‰z  |z   ‘ŒS rS   rS   )r–   ÚidxÚ	batch_idxr  s     €€rU   rÞ  z5GenerationMixin.group_beam_search.<locals>.<listcomp>Æ  s#   ø€ ÐfÐfÐf¸˜ YÑ.°Ñ4ÐfÐfÐfrT   rç   )Úcurrent_tokensÚbeam_group_idxr   r(  r+  r,  )r¿   rÀ   rj   Úgroup_indexr/  r0  r1  c              3   óT   •K  — | ]"}‰‰         ‰|                  ‰|         fz   V — Œ#d S r•   rS   )r–   rÜ  rX  r  rj   s     €€€rU   r×   z4GenerationMixin.group_beam_search.<locals>.<genexpr>ø  sM   øè è € ð 9ð 9ØWX˜ ^Ô4°X¸a´[ÔAÀXÈaÄ[ÀNÑRð9ð 9ð 9ð 9ð 9ð 9rT   ræ  r  r5  r6  rF   rj   r7  r8  )Er,   r>   rŽ  r�  r�  r?   rõ   r¿   rÀ   rº   rÃ   r¨  r¥  r¦  r©  r  r+  rÂ   r9  r³   r¼   rð  r£   r�   rž   r´   rO   Úfullr;  r`  ré  ra  r»  rê  rë  rì  rï   r:  r²   r¸   r�   Ú
zeros_liker  ÚminrY  r   rg  rh  r  r<  rï  rj  r=  ri  r>  rí  rð   rZ   rH   r[   r\   rI   r  r  r?  r@  rD  rn   rh   )8rŠ   r›   rÒ  r1  rN  rD  r¿   rÀ   r¥  r¦  r¨  r©  r¢  r�   r+  r³   rA  rB  rG   rZ   r[   r\   rX   rY   rC  rù  rú  rW  Úreordering_indicesrû  rþ   Úprocessed_scoreÚgroup_start_idxÚgroup_end_idxÚ
group_sizeÚbatch_group_indicesÚgroup_input_idsr  r  rf  rD  rE  r  rF  Úprocess_beam_indicesrG  rH  Úfinal_beam_indicesrI  rV  r½   rX  r  rj   r  rS  s8                                                    @@@@@@@rU   r}   z!GenerationMixin.group_beam_searchÚ  sC
  øøøøøøø€ ðB 0@Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐØÐ!ÝŒMðoåñô ð õ
 !;Ð;LÈjÑ YÔ YÐØ'3Ð'?�|�|ÀTÔE[ÔEhˆØ'3Ð'?�|�|ÀTÔE[ÔEhˆÝ�l¥CÑ(Ô(ð 	*Ø(˜>ˆLØ)6Ð)B˜˜ÈÔH^ÔHlˆà!2Ð!>ÐÐÀDÔDZÔDlð 	ð %9Ð$DÐ Ð È$ÔJ`ÔJuð 	ð
 'Ð2ð $Ð#àÔ'Ô?ð 	 ð  Ô)ˆ	Ø%Ô5ˆØ! _Ñ4ˆÝ˜Ô/Ñ0Ô0°OÑCˆ
ØÔ!ˆà#,¤?Ñ ˆ˜à"ð 	  }ð 	 ØqÐqÐqÐqÐqÕZ_Ð`oÑZpÔZpÐqÑqÔqˆLˆLàˆLà�zÑ! _Ò4Ð4ÝØo¸IÈ
Ñ<RÐoÐoÐ]lÐoÐoÐoñô ð ð
 0ÐL°MÐL��ÈˆØ$;Ð\Ð@QÐ\˜R˜RÐX\ÐØ"9ÐZÐ>OÐZ˜2˜2ÐVZÐØ'>Ð bÐCWÐ b  Ð^bÐð #ð 	 t¤{Ô'Eð 	ØVgÐ!q Ð.?Ô!@×!DÒ!DÀ\Ñ!RÔ!RÐ!RÐmqÐàH\Ðf�Ð.Ô/×3Ò3°OÑDÔDÐDÐbfð "õ ”j *¨iÐ!8¸$ÅeÄkÐZ`ÐaÑaÔaˆØ*+ˆ�A�A�A��˜�Ð&Ñ'Ø!×&Ò&¨
°YÑ(>Ð'@ÑAÔAˆà"ÐðP	.Øð õ +0¬,Ð>PÐ7Y°s°sÐVYÑ*ZÔ*Z×*]Ò*]Ð^gÔ^nÑ*oÔ*oÐ'å”Ð 7½D¼MÔ<MÐNÑNÔNÐNà*×/Ò/Ñ1Ô1°SÒ8Ð8Ùõ #œ[¨°iÑ)?ÀyÄÐ_eÐfÑfÔfˆNõ "'¤¨Z¸)Ñ-CÍ5Ì:Ð^dÐ!eÑ!eÔ!eÐð >˜4Ô=¸iÐXÐXÈ<ÐXÐXˆLØ�dð ð Øðà Ø"3Ø%9ð	ð ð ð ˆGð ð Ð1ð Ø! A™+�Øàð MÝ"'Ô"2°7´>À!À!À!ÀRÈÈÈÀ(Ô3KÑ"LÔ"L�å"'¨Ñ"8Ô"8ð Jñ J�Ø"0°=Ñ"@�Ý # O°mÑ$CÀYÑ OÔ O�Ø*¨_Ñ<�
ð ')Ð#å!& zÑ!2Ô!2ð ð �IØ'×.Ò.ØfÐfÐfÐfÐfÅÀoÐWdÑ@eÔ@eÐfÑfÔfñô ð ð ð #,Ð,?Ô"@�ð %,¤NÐ3FÈÈAÈAÈAÐ3MÔ$NÐ!å$&¤M×$=Ò$=Ø%¨2ð %>ñ %ô %Ð!ð /Ô4°RÔ8�
à.>Ð.>Ø#Ð%6À~Ðftð/ñ /ô /Ð+ð %@À+ÐNaÔBb×BlÒBlÐmoÑBpÔBpÑ$pÐ!Ø$5×$?Ò$?Ð@[Ñ$\Ô$\Ð!à ð WØ;V�OÐ$7Ñ8ð %6×$:Ò$:¸:ÀzÐT^ÑG^Ñ$_Ô$_Ð!ð 5AÐG�s <Ñ0Ô0Ð0Àa�Ý16´Ø%¥s¨1¨a°,Ñ.>Ñ'?Ô'?À*Ñ'LÐRSÐ]aÐjnð2ñ 2ô 2Ñ.Ð! ;õ  %œy¨°jÐPWÐXÑXÔX�Ø)¨JÑ6�ð AMÐ@X¥s¨<¸Ñ'<Ô'<Ð'<Ð^bÐ$Ø*×2Ò2Ø#Ø%ØØ Ø!-Ø!-Ø!5Ø .ð  3ñ 	 ô 	 �ð 4@Ð@RÔ3S�Ð/Ñ0Ø#/Ð0BÔ#CÐ Ø'Ð(;Ô<�à*ð ¨}ð Ý38ð 9ð 9ð 9ð 9ð 9ð 9Ý\aÕbeÐfrÐstÔfuÑbvÔbvÑ\wÔ\wð9ñ 9ô 9ñ 4ô 4�L Ñ0ð 2AÀÔ1J�	Ð-Ñ.Ý"'¤)¨_¸XÀqÀqÀq¸[Ô-IÐK[×KeÒKeÐfhÑKiÔKiÐ,jÐprÐ"sÑ"sÔ"s�Ø6EÀaÀaÀaÈÀeÔ6L�Ð2Ñ3ð
 ¥¤	¨(°JÈgÐ VÑ VÔ VÑVØ%ñ&à *Ñ,ñ.ð #Ð#6Ñ7Ñ7ð 'ð Ø ð 1Ø˜Ð0Ñ0�FØ$ð HØ&Ø9=¼Ô9WÐr˜Ô3Ð5Ð5Ð^eÔ^pÐ]rñÐ&ð ”{Ô5ð HØ(¨WÔ-EÐ,GÑGÐ(à'ð Ø)àœ;Ô9ð6˜Ô6Ð8Ð8à%Ô3Ð5ñÐ)õ œ	 9¨n×.FÒ.FÀrÑ.JÔ.JÐ"KÐQSÐTÑTÔTˆIà×CÒCØ˜¸$¼+Ô:Xð Dñ ô ˆLð Ð-Ô.Ð:Ø26×2EÒ2EØ Ð!2Ô3Ð5Gñ3ô 3�Ð.Ñ/ð
  ‘kˆGàÔ"ð .Ð&7Ð&7¸	À6Ñ&JÔ&Jð .Ø"ð .Øà)-Ð&ñaP	.ðd 7CÐ6N�S ¨rÑ2Ô2Ð2ÐTXÐØ&×/Ò/ØØØØØ%Ø%Ø(Ô3Ø+ð 0ñ 	
ô 	
Ðð #ð 	1Ø ð ;Ø6:Ð Ð!2Ñ3àŒ{Ô-ð Ý5Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø!1°.Ô!AØ'9Ø*?Ø'9Ø%5Ø*?ð
ñ 
ô 
ð 
õ 3Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø!1°.Ô!AØ1Ø"7ðñ ô ð ð $ KÔ0Ð0rT   rº  c                 óp  ‡(‡)— |�|nt          ¦   «         }|�|nt          ¦   «         }|�*t          j        dt          ¦  «         t          ||¦  «        }t          |¦  «        dk    rt          j        dt          ¦  «         |�|n| j        j        }|�|n| j        j	        }t          |t          ¦  «        r|g}|
�|
n| j        j        }
|�|n| j        j        }|	�|	n| j        j        }	|�|n| j        j        }t          |j        ¦  «        }|j        }|j        \  }}||z  |k    rt'          d||z  › d|› d�¦  «        ‚|r|
rdnd}|r(|
r&t)          d	„ t+          |¦  «        D ¦   «         ¦  «        ndŠ)|r|rdnd}|r|rdnd}|r|	rdnd}|rJ| j        j        r>|r|d
                              d¦  «        nd}|	r|d
                              d¦  «        nd}t3          j        ||ft2          j        |j        ¬¦  «        }d|dd…dd…f<   |                     ||z  f¦  «        }d}	 |rot3          j        |rdnd¦  «                             |j        ¦  «        }tA          j!        |t@          j"        j#        ¬¦  «         | $                    ¦   «         dk    r�n‘ | j%        |fi |¤Ž} | di |¤d||	dœ¤Ž}|r|r|dz   }Œ˜|j&        dd…ddd…f         }tN          j(         )                    |d¬¦  «        } |||¦  «        }||dd…df          *                    |¦  «        z   }| +                    ¦   «         } |ra|
r||fz  }|r6|| j        j        r|j,        fn|j-        fz  }| j        j        r||j.        fz  }|	r|| j        j        r|j/        fn|j0        fz  }|j        d         }!|                     |||!z  ¦  «        }|rt          |¦  «        nd}"t3          j1        |te          dd|"z   ¦  «        |z  ddd¬¦  «        \  }}#|#|!z   3                    ¦   «         }$|#|!z  }#| 4                    |||#|$| ||‰)¬¦  «        }%|%d         }|%d         }&|%d         Š(t3          j5        |‰(dd…f         |& 6                    d¦  «        gd¬¦  «        }|  7                    ||| j        j        ¬¦  «        }|d         �|  8                    |d         ‰(¦  «        |d<   |r8|
r6t)          ˆ(ˆ)fd „t+          t          ‰)¦  «        ¦  «        D ¦   «         ¦  «        Š)|dz   }|j9        s |||¦  «        r|snd}�Œ| :                    |||#|$|||j;        ‰)¬!¦  «        }'|rd|
sd|'d"<   | j        j        r*ty          |'d#         |'d"         ||'d$         |||||¬%¦	  «	        S t{          |'d#         |'d"         ||'d$         ||¬&¦  «        S |'d#         S )'aó  
        Generates sequences of token ids for models with a language modeling head using **constrained beam search
        decoding** and can be used for text-decoder, text-to-text, speech-to-text, and vision-to-text models.

        <Tip warning={true}>

        In most cases, you do not need to call [`~generation.GenerationMixin.constrained_beam_search`] directly. Use
        generate() instead. For an overview of generation strategies and code examples, check the [following
        guide](../generation_strategies).

        </Tip>

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            constrained_beam_scorer (`ConstrainedBeamSearchScorer`):
                A derived instance of [`BeamScorer`] that defines how beam hypotheses are constructed, stored and
                sorted during generation, while satisfying a list of positive constraints. For more information, the
                documentation of [`ConstrainedBeamSearchScorer`] should be read.
            logits_processor (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsProcessor`]
                used to modify the prediction scores of the language modeling head applied at each generation step.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            logits_warper (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsWarper`] used
                to warp the prediction score distribution of the language modeling head applied before multinomial
                sampling at each generation step.
            max_length (`int`, *optional*, defaults to 20):
                **DEPRECATED**. Use `logits_processor` or `stopping_criteria` directly to cap the number of generated
                tokens. The maximum length of the sequence to be generated.
            pad_token_id (`int`, *optional*):
                The id of the *padding* token.
            eos_token_id (`Union[int, List[int]]`, *optional*):
                The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more details.
            output_hidden_states (`bool`, *optional*, defaults to `False`):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more details.
            output_scores (`bool`, *optional*, defaults to `False`):
                Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
            return_dict_in_generate (`bool`, *optional*, defaults to `False`):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            synced_gpus (`bool`, *optional*, defaults to `False`):
                Whether to continue running the while loop until max_length (needed for ZeRO stage 3)
            model_kwargs:
                Additional model specific kwargs will be forwarded to the `forward` function of the model. If model is
                an encoder-decoder model the kwargs should include `encoder_outputs`.

        Return:
            [`generation.BeamSearchDecoderOnlyOutput`], [`~generation.BeamSearchEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.BeamSearchDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.BeamSearchEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.


        Examples:

        ```python
        >>> from transformers import (
        ...     AutoTokenizer,
        ...     AutoModelForSeq2SeqLM,
        ...     LogitsProcessorList,
        ...     MinLengthLogitsProcessor,
        ...     ConstrainedBeamSearchScorer,
        ...     PhrasalConstraint,
        ... )
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("t5-base")
        >>> model = AutoModelForSeq2SeqLM.from_pretrained("t5-base")

        >>> encoder_input_str = "translate English to German: How old are you?"
        >>> encoder_input_ids = tokenizer(encoder_input_str, return_tensors="pt").input_ids


        >>> # lets run beam search using 3 beams
        >>> num_beams = 3
        >>> # define decoder start token ids
        >>> input_ids = torch.ones((num_beams, 1), device=model.device, dtype=torch.long)
        >>> input_ids = input_ids * model.config.decoder_start_token_id

        >>> # add encoder_outputs to model keyword arguments
        >>> model_kwargs = {
        ...     "encoder_outputs": model.get_encoder()(
        ...         encoder_input_ids.repeat_interleave(num_beams, dim=0), return_dict=True
        ...     )
        ... }

        >>> constraint_str = "Sie"
        >>> constraint_token_ids = tokenizer.encode(constraint_str)[:-1]  # slice to remove eos token
        >>> constraints = [PhrasalConstraint(token_ids=constraint_token_ids)]


        >>> # instantiate beam scorer
        >>> beam_scorer = ConstrainedBeamSearchScorer(
        ...     batch_size=1, num_beams=num_beams, device=model.device, constraints=constraints
        ... )

        >>> # instantiate logits processors
        >>> logits_processor = LogitsProcessorList(
        ...     [
        ...         MinLengthLogitsProcessor(5, eos_token_id=model.config.eos_token_id),
        ...     ]
        ... )

        >>> outputs = model.constrained_beam_search(
        ...     input_ids, beam_scorer, constraints=constraints, logits_processor=logits_processor, **model_kwargs
        ... )

        >>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
        ['Wie alt sind Sie?']
        ```Nr  r   r   r!  r"  rW  rS   c              3   ó   K  — | ]}d V — ŒdS r$  rS   r%  s     rU   r×   z:GenerationMixin.constrained_beam_search.<locals>.<genexpr>  r&  rT   r¯   rH   rI   r±   r'  r   FTr  r  rØ  r  r°   rç   r   r(  r.  r/  r0  r1  ræ  r  c              3   óH   •K  — | ]}‰‰|                  ‰|         fz   V — Œd S r•   rS   r3  s     €€rU   r×   z:GenerationMixin.constrained_beam_search.<locals>.<genexpr>s  r4  rT   r5  r6  rF   rj   r7  r8  )>r,   r>   rŽ  r�  r�  r?   rÂ   rõ   r¿   rÀ   rº   rÃ   r¨  r¥  r¦  r©  r9  r  r¼   r£   rí  rð  r�   rž   r´   rO   r:  r;  r³   r`  ré  ra  r»  rê  rë  rì  rï   r�   r  r   rg  rh  r<  rk  rZ   rH   r[   r\   rI   rï  rj  r¸   r>  rð   r  r  r  r?  r@  rD  rn   rh   )*rŠ   r›   rº  r1  rN  rD  r¿   rÀ   r¥  r¦  r¨  r©  r¢  r�   r½   r  rA  rB  rG   rZ   r[   r\   rX   rY   rC  rù  rú  rû  rþ   r  r  rD  Úscores_for_all_vocabrf  rE  r  rF  rG  rH  rI  r  rj   s*                                           @@rU   r|   z'GenerationMixin.constrained_beam_searchU  s  øø€ ðL 0@Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐØÐ!ÝŒMðoåñô ð õ
 !;Ð;LÈjÑ YÔ YÐÝÐ Ñ!Ô! QÒ&Ð&ÝŒMÐgÕitÑuÔuÐuØ'3Ð'?�|�|ÀTÔE[ÔEhˆØ'3Ð'?�|�|ÀTÔE[ÔEhˆÝ�l¥CÑ(Ô(ð 	*Ø(˜>ˆLØ)6Ð)B˜˜ÈÔH^ÔHlˆà!2Ð!>ÐÐÀDÔDZÔDlð 	ð %9Ð$DÐ Ð È$ÔJ`ÔJuð 	ð
 'Ð2ð $Ð#àÔ'Ô?ð 	 õ Ð0Ô;Ñ<Ô<ˆ
Ø+Ô5ˆ	à#,¤?Ñ ˆ˜à�zÑ! _Ò4Ð4ÝØo¸IÈ
Ñ<RÐoÐoÐ]lÐoÐoÐoñô ð ð
 0ÐL°MÐL��Èˆà:QÐnÐVcÐn�EÐ5Ð5�e OÑ4Ô4Ð5Ñ5Ô5Ñ5Ô5Ð5Ðjnð 	ð %<Ð\Ð@QÐ\˜R˜RÐX\ÐØ"9ÐZÐ>OÐZ˜2˜2ÐVZÐØ'>Ð bÐCWÐ b  Ð^bÐð #ð 	 t¤{Ô'Eð 	ØVgÐ!q Ð.?Ô!@×!DÒ!DÀ\Ñ!RÔ!RÐ!RÐmqÐàH\Ðf�Ð.Ô/×3Ò3°OÑDÔDÐDÐbfð "õ ”k :¨yÐ"9ÅÄÐU^ÔUeÐfÑfÔfˆØ!ˆ�A�A�A�q�r�r�EÑØ!×&Ò&¨
°YÑ(>Ð'@ÑAÔAˆà"Ððd	.Øð õ +0¬,Ð>PÐ7Y°s°sÐVYÑ*ZÔ*Z×*]Ò*]Ð^gÔ^nÑ*oÔ*oÐ'å”Ð 7½D¼MÔ<MÐNÑNÔNÐNà*×/Ò/Ñ1Ô1°SÒ8Ð8Ùà=˜4Ô=¸iÐXÐXÈ<ÐXÐXˆLà�dð ð Øðà Ø"3Ø%9ð	ð ð ð ˆGð ð Ð1ð Ø! A™+�Øà '¤¨q¨q¨q°"°a°a°a¨xÔ 8ÐÝ "¤× 9Ò 9Ø! rð !:ñ !ô !Ðð +;Ð*:¸9ÐFWÑ*XÔ*XÐ'à ;¸kÈ!È!È!ÈTÈ'Ô>R×>\Ò>\Ø+ñ?ô ?ñ !Ðð $5×#:Ò#:Ñ#<Ô#<Ð ð 'ð Ø ð 3ØÐ0Ð2Ñ2�FØ$ð HØ&Ø9=¼Ô9WÐr˜Ô3Ð5Ð5Ð^eÔ^pÐ]rñÐ&ð ”{Ô5ð HØ(¨WÔ-EÐ,GÑGÐ(à'ð Ø)àœ;Ô9ð6˜Ô6Ð8Ð8à%Ô3Ð5ñÐ)ð +Ô0°Ô4ˆJØ 1× 6Ò 6°zÀ9ÈzÑCYÑ ZÔ ZÐð 1=ÐC�3˜|Ñ,Ô,Ð,À!ˆLÝ-2¬ZØ!¥3 q¨!¨lÑ*:Ñ#;Ô#;¸iÑ#GÈQÐX\Ðeið.ñ .ô .Ñ*Ð˜{ð (¨*Ñ4×:Ò:Ñ<Ô<ˆLØ%¨
Ñ2ˆKð 3×:Ò:ØØ!ØØØ$Ø)Ø)Ø)ð ;ñ 	ô 	ˆLð 'Ð'9Ô:ˆKØ+Ð,>Ô?ÐØ#Ð$7Ô8ˆHåœ	 9¨X°q°q°q¨[Ô#9Ð;K×;UÒ;UÐVXÑ;YÔ;YÐ"ZÐ`bÐcÑcÔcˆIØ×CÒCØ˜¸$¼+Ô:Xð Dñ ô ˆLð Ð-Ô.Ð:Ø26×2EÒ2EÀlÐSdÔFeÐgoÑ2pÔ2p�Ð.Ñ/à&ð u¨=ð uÝ$Ð%sÐ%sÐ%sÐ%sÐ%sÕZ_Õ`cÐdpÑ`qÔ`qÑZrÔZrÐ%sÑ%sÔ%sÑtÔt�ð  ‘kˆGà&Ô.ð .Ð2CÐ2CÀIÈvÑ2VÔ2Vð .Ø"ð .Øà)-Ð&ñId	.ðL 3×;Ò;ØØØØØ%Ø%Ø(Ô3Ø%ð <ñ 	
ô 	
Ðð #ð 	1Ø ð ;Ø6:Ð Ð!2Ñ3ØŒ{Ô-ð Ý5Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø!1°.Ô!AØ'9Ø*?Ø'9Ø%5Ø*?ð
ñ 
ô 
ð 
õ 3Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø!1°.Ô!AØ1Ø"7ðñ ô ð ð $ KÔ0Ð0rT   r)  c           	      óÜ  ‡5— t          |d¦  «        r"t          j        dt          ¦  «         |j        }n|j        j        }dt          t          j        |j	        ¦  «        j
                             ¦   «         ¦  «        v }|�|nt          ¦   «         }|�|nt          ¦   «         }|�|nt          ¦   «         }|�|n| j        j        }|�|n| j        j        }|�|€t!          d¦  «        ‚t#          |t$          ¦  «        r|g}|�,t'          j        |¦  «                             |j        ¦  «        nd}|�|n| j        j        }|	�|	n| j        j        }	|
�|
n| j        j        }
|�|n| j        j        }|r|rdnd}|r|	rdnd}|r|	rdnd}|r|
rdnd}|rJ| j        j        r>|	r|d                              d¦  «        nd}|
r|d                              d¦  «        nd}|                     |j        d	         ¦  «                              d
¦  «        }|d	         j!        }d|j"        j#         $                    ¦   «         v s2|j        j%        �(d|j        j%        d	          $                    ¦   «         v rd
nd	}d}	 |rot'          j        |rdnd¦  «                             |j        ¦  «        }tM          j'        |tL          j(        j)        ¬¦  «         | *                    ¦   «         dk    r�n¹|j        d         }|}tW          t%          |¦  «        ¦  «        D �]Û} d|v rŠ|d         d	         |         j        d         }!|j        d
         |!z
  }"|dd…|" d…f         }#|j        j        r ||#|d         |d         ¬¦  «        }$nai }%|rd|v r|d         |%d<    ||#fd|d         i|%¤Ž}$n<|j        j        r |||d         ¬¦  «        }$ni }%|rd|v r|d         |%d<    ||fi |%¤Ž}$|$j,        |d<   t[          |¦  «        d	k    r- |||$j.        dd…ddd…f         ¦  «        |$j.        dd…ddd…f<   |$j.        dd…ddd…f          /                    d¬¦  «        }&t'          j0        ||&dd…df         fd¬¦  «        }|�v|& 1                    |j        d	         d
¦  «        }'|' 2                    | 3                    d
¦  «        ¦  «         4                    d	¬¦  «         5                    ¦   «          }'|'r n�ŒÙd}'�ŒÝ|j        d
         |j        d
         z
  }(tm          j6        |¦  «        })|  7                    |)|j        d
         ¦  «        })|  8                    |)|j        d
         ¦  «        }) | j9        |fi |)¤Ž}* | di |*¤|	|
dœ¤Ž}+|+j.        dd…|( d
z
  d…f         Š5t[          |¦  «        d	k    rGtW          |(d
z   ¦  «        D ]4}, ||dd…d||,z   …f         ‰5dd…|,dd…f         ¦  «        ‰5dd…|,dd…f<   Œ5t[          |¦  «        d	k    rGtW          |(d
z   ¦  «        D ]4}, ||dd…d||,z   …f         ‰5dd…|,dd…f         ¦  «        ‰5dd…|,dd…f<   Œ5|rW‰5 :                    d¬¦  «        }-t'          j;        |-d	dd…dd…f         d
¬¦  «         <                    d
¦  «        ddd…f         }.n‰5 /                    d¬¦  «        }.|dd…|( d…f         }/|/|.dd…dd…f         k      =                    d¬¦  «        d
k      >                    ¦   «         }0|'r|0|(k    r|0d
z  }0t          |0||z
  d
z
  ¦  «        }0|.dd…d|0d
z   …f         }1t'          j0        ||1fd¬¦  «        }|�'| @                    |1 A                    ¦   «         ¦  «         |j        d         }2|2d
z
  }3t…          | |+j,        |3¦  «        |+_,        t…          ||d         |3d
z
  ¦  «        |d<   |j        jC        dk    r,|0t%          |¦  «        k    r|dz  }nt‰          d|dz
  ¦  «        }|r|r�Œ�|rÑ|r.|t‹          ˆ5fd„tW          |0d
z   ¦  «        D ¦   «         ¦  «        z  }d|vr|2}4n|0d
z   }4|	rV| j        j        r1t�          ||+jG        ||4¦  «        }t�          ||+jH        ||4d¬¦  «        }nt�          ||+jI        ||4d¬¦  «        }|
r;| j        j        rt�          ||+jJ        ||4¦  «        }nt�          ||+jK        ||4¦  «        }|  L                    |+|| j        j        ¬¦  «        }|�’| M                    |dd…df          1                    |j        d	         d
¦  «         2                    | 3                    d
¦  «        ¦  «         4                    d	¬¦  «        ¦  «        }| D                    ¦   «         d	k    rd} |||¦  «        rd}|r|sn�Œ*|�| N                    ¦   «          |r5| j        j        rtŸ          |||||||¬ ¦  «        S t¡          ||||¬!¦  «        S |S )"aý  
        Generates sequences of token ids for models with a language modeling head using **greedy decoding** or
        **sample** (depending on `do_sample`), assisted by a smaller model. Can be used for text-decoder, text-to-text,
        speech-to-text, and vision-to-text models.

        <Tip warning={true}>

        In most cases, you do not need to call [`~generation.GenerationMixin.assisted_decoding`] directly. Use
        generate() instead. For an overview of generation strategies and code examples, check the [following
        guide](../generation_strategies).

        </Tip>

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            assistant_model (`PreTrainedModel`, *optional*):
                An assistant model that can be used to accelerate generation. The assistant model must have the exact
                same tokenizer. The acceleration is achieved when forecasting candidate tokens with the assistent model
                is much faster than running generation with the model you're calling generate from. As such, the
                assistant model should be much smaller.
            do_sample (`bool`, *optional*, defaults to `False`):
                Whether or not to use sampling ; use greedy decoding otherwise.
            logits_processor (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsProcessor`]
                used to modify the prediction scores of the language modeling head applied at each generation step.
            logits_warper (`LogitsProcessorList`, *optional*):
                An instance of [`LogitsProcessorList`]. List of instances of class derived from [`LogitsWarper`] used
                to warp the prediction score distribution of the language modeling head applied before multinomial
                sampling at each generation step.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            pad_token_id (`int`, *optional*):
                The id of the *padding* token.
            eos_token_id (`Union[int, List[int]]`, *optional*):
                The id of the *end-of-sequence* token. Optionally, use a list to set multiple *end-of-sequence* tokens.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more details.
            output_hidden_states (`bool`, *optional*, defaults to `False`):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more details.
            output_scores (`bool`, *optional*, defaults to `False`):
                Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
            return_dict_in_generate (`bool`, *optional*, defaults to `False`):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            synced_gpus (`bool`, *optional*, defaults to `False`):
                Whether to continue running the while loop until max_length (needed for ZeRO stage 3)
            streamer (`BaseStreamer`, *optional*):
                Streamer object that will be used to stream the generated sequences. Generated tokens are passed
                through `streamer.put(token_ids)` and the streamer is responsible for any further processing.
            model_kwargs:
                Additional model specific keyword arguments will be forwarded to the `forward` function of the model.
                If model is an encoder-decoder model the kwargs should include `encoder_outputs`.

        Return:
            [`~generation.GreedySearchDecoderOnlyOutput`], [`~generation.GreedySearchEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.GreedySearchDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.GreedySearchEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.

        Examples:

        ```python
        >>> from transformers import (
        ...     AutoTokenizer,
        ...     AutoModelForCausalLM,
        ...     LogitsProcessorList,
        ...     MinLengthLogitsProcessor,
        ...     StoppingCriteriaList,
        ...     MaxLengthCriteria,
        ... )

        >>> tokenizer = AutoTokenizer.from_pretrained("gpt2")
        >>> model = AutoModelForCausalLM.from_pretrained("gpt2")
        >>> assistant_model = AutoModelForCausalLM.from_pretrained("distilgpt2")
        >>> # set pad_token_id to eos_token_id because GPT2 does not have a PAD token
        >>> model.generation_config.pad_token_id = model.generation_config.eos_token_id
        >>> input_prompt = "It might be possible to"
        >>> input_ids = tokenizer(input_prompt, return_tensors="pt").input_ids
        >>> # instantiate logits processors
        >>> logits_processor = LogitsProcessorList(
        ...     [
        ...         MinLengthLogitsProcessor(10, eos_token_id=model.generation_config.eos_token_id),
        ...     ]
        ... )
        >>> stopping_criteria = StoppingCriteriaList([MaxLengthCriteria(max_length=20)])
        >>> outputs = model.assisted_decoding(
        ...     input_ids,
        ...     assistant_model=assistant_model,
        ...     logits_processor=logits_processor,
        ...     stopping_criteria=stopping_criteria,
        ... )
        >>> tokenizer.batch_decode(outputs, skip_special_tokens=True)
        ["It might be possible to get a better understanding of the nature of the problem, but it's not"]
        ```Únum_assistant_tokensz¿Setting `num_assistant_tokens` via `assistant_model.num_assistant_tokens` is deprecated and will be removed in v.37. Make sure to set `num_assistant_tokens` via the generation_config instead.r¯   Nrå  rS   rH   rI   r   r   ÚbloomFTr  r  rØ  r°   Úassistant_past_key_valueséþÿÿÿrƒ  )rå   r  r¯   r  )rå   r¯   rç   )r¥  r¦  r  Ú	heuristicg       @c              3   ó6   •K  — | ]}‰d d …|d d …f         V — Œd S r•   rS   )r–   rÜ  Ú
new_logitss     €rU   r×   z4GenerationMixin.assisted_decoding.<locals>.<genexpr>ù  s6   øè è € Ð#VÐ#V¸A J¨q¨q¨q°!°Q°Q°Q¨wÔ$7Ð#VÐ#VÐ#VÐ#VÐ#VÐ#VrT   )Úis_decoder_attentionræ  rç  rè  )QrŸ   rŽ  r�  ÚFutureWarningrl  rõ   r¤   r¥   r¦   rß   r§   r¨   r,   r>   r¿   rÀ   r£   rº   rÃ   rO   ré  ra  r³   r¨  r¥  r¦  r©  r�   rž   r´   Únewr¼   Úfill_rD  r©   rK   rí   Úarchitecturesr»  rê  rë  rì  rï   rð  r  rÂ   r  r  rð   rô  rÄ   r  rõ  ÚboolrÁ  rš  r¡  r�   rî  r  râ  Úcumsumri  r]  rÇ  rÈ  Ú_crop_past_key_valuesÚnum_assistant_tokens_schedulerj  rí  Ú_split_model_outputsr[   rZ   rH   r\   rI   r  ró  rö  rb   rE   )6rŠ   r›   r%  r)  r1  r§  rN  r¿   rÀ   r¥  r¦  r¨  r©  r¢  r£  r�   rl  rÐ  r÷  rG   rZ   r[   r\   rX   rY   rø  Úmax_lenÚassistant_kv_indexingrù  rú  rB  Úcandidate_input_idsrþ  Úprev_seq_lenÚnew_token_lenÚassist_inputsÚassistant_model_outputsrà   Ú	new_tokenÚlast_assistant_token_is_eosÚcandidate_lengthÚcandidate_kwargsrû  rþ   rÜ  r  Úselected_tokensÚcandidate_new_tokensÚ	n_matchesÚvalid_tokensÚnew_cur_lenÚnew_cache_sizeÚ	added_lenrr  s6                                                        @rU   rÊ  z!GenerationMixin.assisted_decoding¤  sp  ø€ õj �?Ð$:Ñ;Ô;ð 	ZÝŒMð RÝñô ð ð $3Ô#GÐ Ð à#2Ô#DÔ#YÐ ð ->ÅÝÔ˜oÔ5Ñ6Ô6ÔA×FÒFÑHÔHñB
ô B
ð -
Ð)ð
 0@Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ)6Ð)B˜˜ÕH[ÑH]ÔH]ˆØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐØ'3Ð'?�|�|ÀTÔE[ÔEhˆØ'3Ð'?�|�|ÀTÔE[ÔEhˆØÐ#¨Ð(<ÝÐfÑgÔgÐgÝ�l¥CÑ(Ô(ð 	*Ø(˜>ˆLØQ]ÐQi�eœl¨<Ñ8Ô8×;Ò;¸IÔ<LÑMÔMÐMÐosÐØ)6Ð)B˜˜ÈÔH^ÔHlˆà!2Ð!>ÐÐÀDÔDZÔDlð 	ð %9Ð$DÐ Ð È$ÔJ`ÔJuð 	ð
 'Ð2ð $Ð#àÔ'Ô?ð 	 ð 0ÐL°MÐL��ÈˆØ$;Ð\Ð@QÐ\˜R˜RÐX\ÐØ"9ÐZÐ>OÐZ˜2˜2ÐVZÐØ'>Ð bÐCWÐ b  Ð^bÐð #ð 	 t¤{Ô'Eð 	ØVgÐ!q Ð.?Ô!@×!DÒ!DÀ\Ñ!RÔ!RÐ!RÐmqÐàH\Ðf�Ð.Ô/×3Ò3°OÑDÔDÐDÐbfð "ð
  )Ÿ}š}¨Y¬_¸QÔ-?Ñ@Ô@×FÒFÀqÑIÔIÐð $ AÔ&Ô1ˆð ˜/Ô3Ô<×BÒBÑDÔDÐDÐDàÔ&Ô4Ð@Ø˜Ô5ÔCÀAÔF×LÒLÑNÔNÐNÐNð	 ˆAð ð 	ð #ÐðX	Øð õ +0¬,Ð>PÐ7Y°s°sÐVYÑ*ZÔ*Z×*]Ò*]Ð^gÔ^nÑ*oÔ*oÐ'å”Ð 7½D¼MÔ<MÐNÑNÔNÐNà*×/Ò/Ñ1Ô1°SÒ8Ð8Ùð  ”o bÔ)ˆGð
 #,ÐÝ�3Ð3Ñ4Ô4Ñ5Ô5ð 78ñ 78�à.°,Ð>Ð>Ø#/Ð0KÔ#LÈQÔ#OÐPeÔ#fÔ#lÐmoÔ#p�Là$7Ô$=¸aÔ$@À<Ñ$O�MØ$7¸¸¸¸M¸>¸?¸?Ð8JÔ$K�Mà&Ô-Ô@ð Ø2A°/Ø.;Ø,8Ð9TÔ,UØ,8Ð9TÔ,Uð3ñ 3ô 3Ð/Ð/ð *,˜à<ð jÐA\Ð`lÐAlÐAlØ@LÐMhÔ@i˜NÐ+<Ñ=à2A°/Ø)ð3ð 3Ø;GÐHcÔ;dð3Øhvð3ð 3Ð/Ð/ð 'Ô-Ô@ð iØ2A°/Ø.AØ,8Ð9TÔ,Uð3ñ 3ô 3Ð/Ð/ð
 *,˜à<ð jÐA\Ð`lÐAlÐAlØ@LÐMhÔ@i˜NÐ+<Ñ=à2A°/ÐBUÐ2hÐ2hÐYgÐ2hÐ2hÐ/ð =TÔ<c�Ð8Ñ9ÝÐ'Ñ(Ô(¨1Ò,Ð,Ø?OÐ?OØ+Ð-DÔ-KÈAÈAÈAÈrÐSTÐSTÐSTÈHÔ-Uñ@ô @Ð+Ô2°1°1°1°b¸!¸!¸!°8Ñ<ð 4Ô:¸1¸1¸1¸bÀ!À!À!¸8ÔD×KÒKÐPRÐKÑSÔS�	Ý&+¤iÐ1DÀiÐPQÐPQÐPQÐSWÐPWÔFXÐ0YÐ_aÐ&bÑ&bÔ&bÐ#ð 'Ð2Ø2;·.².ÐATÔAZÐ[\ÔA]Ð_`Ñ2aÔ2aÐ/à4×7Ò7Ð8K×8UÒ8UÐVWÑ8XÔ8XÑYÔY×^Ò^ÐcdÐ^ÑeÔe×jÒjÑlÔlÐlð 0ð 3ð Ø˜ñð 38Ð/Ñ/à2Ô8¸Ô;¸i¼oÈaÔ>PÑPÐõ  $œy¨Ñ6Ô6ÐØ#×:Ò:Ð;KÐM`ÔMfÐghÔMiÑjÔjÐØ#×:Ò:Ð;KÐM`ÔMfÐghÔMiÑjÔjÐà=˜4Ô=Ð>QÐfÐfÐUeÐfÐfˆLð �dð ð Øðà"3Ø%9ðð ð ð ˆGð !œ¨¨¨Ð,<Ð+<¸qÑ+@Ð+BÐ+BÐ(BÔCˆJÝÐ#Ñ$Ô$ qÒ(Ð(ÝÐ/°!Ñ3Ñ4Ô4ð wð w�AØ*:Ð*:Ð;NÈqÈqÈqÐR_ÐT[Ð^_ÑT_ÐR_ÐO_Ô;`ÐblÐmnÐmnÐmnÐpqÐstÐstÐstÐmtÔbuÑ*vÔ*v�J˜q˜q˜q ! Q Q Q˜wÑ'Ð'Ý�=Ñ!Ô! AÒ%Ð%ÝÐ/°!Ñ3Ñ4Ô4ð tð t�AØ*7¨-Ð8KÈAÈAÈAÈ}ÐQXÐ[\ÑQ\È}ÐL\Ô8]Ð_iÐjkÐjkÐjkÐmnÐpqÐpqÐpqÐjqÔ_rÑ*sÔ*s�J˜q˜q˜q ! Q Q Q˜wÑ'Ð'ð ð <Ø"×*Ò*¨rÐ*Ñ2Ô2�Ý"'Ô"3°E¸!¸Q¸Q¸QÀÀÀ¸'´NÐPQÐ"RÑ"RÔ"R×"ZÒ"ZÐ[\Ñ"]Ô"]Ð^bÐdeÐdeÐdeÐ^eÔ"f��à",×"3Ò"3¸Ð"3Ñ";Ô";�ð $7°q°q°qÐ;KÐ:KÐ:LÐ:LÐ7LÔ#MÐ Ø0°OÀAÀAÀAÀsÈÀsÀFÔ4KÒKÐL×TÒTÐY[ÐTÑ\Ô\Ð_`Ò`×eÒeÑgÔgˆIð +ð ¨yÐ<LÒ/LÐ/LØ˜Q‘�	Ý˜I w°Ñ'8¸1Ñ'<Ñ=Ô=ˆIð +¨1¨1¨1¨o°	¸A±¨oÐ+=Ô>ˆLÝœ	 9¨lÐ";ÀÐDÑDÔDˆIØÐ#Ø—’˜\×-Ò-Ñ/Ô/Ñ0Ô0Ð0Ø#œ/¨"Ô-ˆKð )¨1™_ˆNÝ&;¸DÀ'ÔBYÐ[iÑ&jÔ&jˆGÔ#Ý8MØ Ð.IÔ!JÈNÐ]^ÑL^ñ9ô 9ˆLÐ4Ñ5ð Ô0ÔNÐR]Ò]Ð]Ø¥Ð$8Ñ 9Ô 9Ò9Ð9Ø(¨CÑ/Ð(Ð(å+.¨sÐ4HÈ3Ñ4NÑ+OÔ+OÐ(ð ð Ð1ð Ùð 'ð %Ø ð WØ�eÐ#VÐ#VÐ#VÐ#VÅÀyÐSTÁ}ÑAUÔAUÐ#VÑ#VÔ#VÑVÔVÑV�Fà$¨LÐ8Ð8Ø +�I�Ià )¨A¡�Ià$ð Ø”{Ô5ð Ý+?Ø,¨gÔ.FÈÐQZñ,ô ,Ð(õ .BØ.Ø#Ô6Ø#Ø%Ø15ð.ñ .ô .Ð*Ð*õ .BØ.Ø#Ô.Ø#Ø%Ø15ð.ñ .ô .Ð*ð (ð Ø”{Ô5ð Ý0DØ1°7Ô3PÐRYÐ[dñ1ô 1Ð-Ð-õ 1EØ1°7Ô3HÈ'ÐS\ñ1ô 1Ð-ð  ×CÒCØ˜¸$¼+Ô:Xð Dñ ô ˆLð
 #Ð.Ø';×'?Ò'?Ø˜a˜a˜a ˜eÔ$ß’TÐ-Ô3°AÔ6¸Ñ:Ô:ß’RÐ+×5Ò5°aÑ8Ô8Ñ9Ô9ß’T˜a�T‘[”[ñ	(ô (Ð$ð (×+Ò+Ñ-Ô-°Ò2Ð2Ø)-Ð&ð !Ð  ¨FÑ3Ô3ð *Ø%)Ð"à!ð ¨+ð ØñqX	ðt ÐØ�LŠL‰NŒNˆNà"ð 	ØŒ{Ô-ð Ý7Ø'Ø!Ø'9Ø*?Ø'9Ø%5Ø*?ðñ ô ð õ 5Ø'Ø!Ø1Ø"7ð	ñ ô ð ð ÐrT   )NNNr•   )NN)r   FN©F)FF)NF)
NNNNNNNNNN)r   r   NNNNNNNNNFNN)NNNNNNNNNFN)NNNNNNNNNNFN)
NNNNNNNNNF)NNNNNNNNNNF)FNNNNNNNNNFN)ArK   rL   rM   rN   r�   r	   rO   r»   rÃ   r   Ústrr
   r­   rP   rª   r   r   rÈ   r   râ   r³   ró   rê   Ústaticmethodrx  rý   r   r  r  r  r    r,   r$  ru   r-  r   rM  r>   rS  rJ  rs  r}  rŠ  r•  rš  r¡  Úno_gradÚGenerateOutputrÖ  r;  ÚContrastiveSearchOutputrv   ÚGreedySearchOutputrw   ÚSampleOutputrx   r   ÚBeamSearchOutputrz   ÚBeamSampleOutputr{   r}   r   r|   rÊ  rS   rT   rU   r‡   r‡   ë  s£  € € € € € ðð ð.
ð 
ð 
ð *.Ø&*Ø:>ð	>0ð >0à˜œÔ&ð>0ð ˜s”mð>0ð ˜t C¨¬Ð$5Ô6Ô7ð	>0ð
 
ˆuŒ|˜X cœ]¨D°°e´lÐ1BÔ,CÐCÔ	Dð>0ð >0ð >0ð >0ðD *.Ø&*Ø:>ð	`ð `à˜œÔ&ð`ð ˜s”mð`ð ˜t C¨¬Ð$5Ô6Ô7ð	`ð
 
Ô	ð`ð `ð `ð `ð8Xà”ðXð ˜s”mðXð ˜u S¨$¨s¬) ^Ô4Ô5ð	Xð
 
Ô	ðXð Xð Xð Xð& \`ð!ð !Ø"œ\ð!ØKSÐTWÌ=ð!à	ˆc�3ˆhŒð!ð !ð !ð !ðP '+Ø Ø#ð+/ð +/àð+/ð ð+/ð ˜3 ¤Ð,Ô-ð	+/ð
 !$ð+/ð ð+/ð ”ð+/ð 
ˆuÔ  c¨5¬<Ð&7Ô!8Ð8Ô	9ð+/ð +/ð +/ð +/ðZ
ð 
À#ð 
Ð\_ð 
Ðknð 
ð 
ð 
ð 
ð  àØ#(Ø04ð'ð 'Øð'à ð'ð ˜EÔ,Ô-ð'ð
 
ˆuÔ  c¨3 h¤Ð/Ô	0ð'ð 'ð 'ñ „\ð'ð4ð °{ð Ð^bð ð ð ð ð& $)Ø).ð#ð #àð#ð ˜3 ˜8”nð#ð !ð	#ð
 #'ð#ð 
ˆc�3ˆhŒð#ð #ð #ð #ðJ
ð 
ð 
ð-à+ð-ð 
ð-ð -ð -ð -ð^&Ø!1ð&ØDLÐM^ÔD_ð&à	ð&ð &ð &ð &ð^ 26Ø6:ØAEðAð Aà+ðAð "ðAð !Ô+ð	Að
 #+¨C°´Ð+>ÀÀSÄ	Ð+IÔ"JðAð #Ð#6Ô7ðAð ˜t C¨ Hœ~Ô.ðAð & e¤lÔ3ðAð )1°´Ô(>ðAð 
ðAð Að Að AðFØ!1ðØFNÐOcÔFdðà	ðð ð ð ð"àÐ/Ð1EÐEÔFðð Ð.Ð0DÐDÔEðð 
Ð"Ð$8Ð8Ô	9ð	ð ð ð ð2 04Ø!&ðw!ð w!à”<ðw!ð �e”lÔ#ðw!ð ˜uœ|Ô,ð	w!ð
 ðw!ð 
Œðw!ð w!ð w!ð w!ðr/ð /ð /ð43°4¸¸S¸´>ð 3ð 3ð 3ð 3ðj,ð ,ð ,ð\°4¸¸S¸´>ð ÐTWð Ð\`ÐadÐfiÐaiÔ\jð ð ð ð ð,°4¸¸S¸´>ð Èsð ÐW[Ð\_ÐadÐ\dÔWeð ð ð ð ð €U„]�_„_ð *.Ø8<Ø:>Ø<@ØW[Ø&*Ø7;Ø-1Ø6:ØAEðlð là˜œÔ&ðlð $Ð$4Ô5ðlð #Ð#6Ô7ð	lð
 $Ð$8Ô9ðlð #+¨8°S¸%¼,Ð4GÈÈcÌÐ4RÔ+SÔ"Tðlð ˜d”^ðlð "Ð"3Ô4ðlð ˜>Ô*ðlð & e¤lÔ3ðlð )1°´Ô(>ðlð 
ˆ~˜uÔ/Ð/Ô	0ðlð lð lñ „_ðlð\ €U„]�_„_ð  !Ø)*Ø:>Ø7;Ø<@Ø&*Ø8<Ø,0Ø/3Ø(,Ø26Ø!Ø-1Ø%)ð!yð yàÔ#ðyð ˜Œ}ðyð   ”ð	yð
 #Ð#6Ô7ðyð  Ð 3Ô4ðyð $Ð$8Ô9ðyð ˜s”mðyð ˜u S¨$¨s¬) ^Ô4Ô5ðyð $ Dœ>ðyð ' tœnðyð   ”~ðyð "*¨$¤ðyð ðyð ˜>Ô*ðyð  ˜T”Nð!yð$ 
Ð&¨Ô(8Ð8Ô	9ð%yð yð yñ „_ðyð| ;?Ø<@Ø$(Ø&*Ø8<Ø,0Ø/3Ø(,Ø26Ø!Ø-1ðAð AàÔ#ðAð #Ð#6Ô7ðAð $Ð$8Ô9ð	Að
 ˜S”MðAð ˜s”mðAð ˜u S¨$¨s¬) ^Ô4Ô5ðAð $ Dœ>ðAð ' tœnðAð   ”~ðAð "*¨$¤ðAð ðAð ˜>Ô*ðAð 
Ð! 5Ô#3Ð3Ô	4ðAð Að Að AðL ;?Ø<@Ø7;Ø$(Ø&*Ø8<Ø,0Ø/3Ø(,Ø26Ø!Ø-1ðXð XàÔ#ðXð #Ð#6Ô7ðXð $Ð$8Ô9ð	Xð
  Ð 3Ô4ðXð ˜S”MðXð ˜s”mðXð ˜u S¨$¨s¬) ^Ô4Ô5ðXð $ Dœ>ðXð ' tœnðXð   ”~ðXð "*¨$¤ðXð ðXð ˜>Ô*ðXð  
ˆ|˜UÔ-Ð-Ô	.ð!Xð Xð Xð Xð| ;?Ø<@Ø$(Ø&*Ø8<Ø,0Ø/3Ø(,Ø26Ø!ðA1ð A1àÔ#ðA1ð  ðA1ð #Ð#6Ô7ð	A1ð
 $Ð$8Ô9ðA1ð ˜S”MðA1ð ˜s”mðA1ð ˜u S¨$¨s¬) ^Ô4Ô5ðA1ð $ Dœ>ðA1ð ' tœnðA1ð   ”~ðA1ð "*¨$¤ðA1ð ðA1ð 
Ð Ô!1Ð1Ô	2ðA1ð A1ð A1ð A1ðN
 ;?Ø<@Ø7;Ø$(Ø&*Ø8<Ø,0Ø/3Ø(,Ø26Ø!ðG1ð G1àÔ#ðG1ð  ðG1ð #Ð#6Ô7ð	G1ð
 $Ð$8Ô9ðG1ð  Ð 3Ô4ðG1ð ˜S”MðG1ð ˜s”mðG1ð ˜u S¨$¨s¬) ^Ô4Ô5ðG1ð $ Dœ>ðG1ð ' tœnðG1ð   ”~ðG1ð "*¨$¤ðG1ð ðG1ð  
Ð Ô!1Ð1Ô	2ð!G1ð G1ð G1ð G1ðZ
 ;?Ø<@Ø$(Ø&*Ø8<Ø,0Ø/3Ø(,Ø26Ø!ðy1ð y1àÔ#ðy1ð  ðy1ð #Ð#6Ô7ð	y1ð
 $Ð$8Ô9ðy1ð ˜S”Mðy1ð ˜s”mðy1ð ˜u S¨$¨s¬) ^Ô4Ô5ðy1ð $ Dœ>ðy1ð ' tœnðy1ð   ”~ðy1ð "*¨$¤ðy1ð ðy1ð y1ð y1ð y1ð~ ;?Ø<@Ø$(Ø&*Ø8<Ø,0Ø/3Ø(,Ø26Ø&*ðM1ð M1àÔ#ðM1ð "=ðM1ð #Ð#6Ô7ð	M1ð
 $Ð$8Ô9ðM1ð ˜S”MðM1ð ˜s”mðM1ð ˜u S¨$¨s¬) ^Ô4Ô5ðM1ð $ Dœ>ðM1ð ' tœnðM1ð   ”~ðM1ð "*¨$¤ðM1ð ˜d”^ðM1ð 
Ð Ô!1Ð1Ô	2ðM1ð M1ð M1ð M1ðf
  Ø:>Ø7;Ø<@Ø&*Ø8<Ø,0Ø/3Ø(,Ø26Ø!Ø-1ðhð hàÔ#ðhð +ðhð ð	hð
 #Ð#6Ô7ðhð  Ð 3Ô4ðhð $Ð$8Ô9ðhð ˜s”mðhð ˜u S¨$¨s¬) ^Ô4Ô5ðhð $ Dœ>ðhð ' tœnðhð   ”~ðhð "*¨$¤ðhð ðhð ˜>Ô*ðhð hð hð hð hð hrT   r‡   c           
      ó¦  — g }| j         j        r�t          t          |¦  «        ¦  «        D ]o}|                     ||         d         dd…dd…d|…dd…f         ||         d         dd…dd…d|…dd…f         ||         d         ||         d         f¦  «         Œpt          |¦  «        }�n%d| j        j                             ¦   «         v s2| j         j	        �£d| j         j	        d                              ¦   «         v r}t          t          |¦  «        ¦  «        D ]O}|                     ||         d         dd…dd…d|…f         ||         d         dd…d|…dd…f         f¦  «         ŒPt          |¦  «        }�nVd| j        j                             ¦   «         v s2| j         j	        �©d| j         j	        d                              ¦   «         v rƒ| j         j
        r:t          t          |¦  «        ¦  «        D ]}||         dd…d|…dd…f         ||<   Œn¾t          t          |¦  «        ¦  «        D ]}||         dd…dd…d|…dd…f         ||<   Œ n�t          t          |¦  «        ¦  «        D ]U}|                     ||         d         dd…dd…d|…dd…f         ||         d         dd…dd…d|…dd…f         f¦  «         ŒVt          |¦  «        }|S )z9Crops the past key values up to a certain maximum length.r   Nr   r   é   rm  Ú
gptbigcode)r�   rž   rð  rÂ   r  rí  r©   rK   rí   rw  Úmulti_query)Úmodelr  Úmaximum_lengthÚnew_pastrU  s        rU   rz  rz  O  sb  € à€HØ„|Ô&ð )*Ý�˜_Ñ-Ô-Ñ.Ô.ð 	ð 	ˆCØ�OŠOà# CÔ(¨Ô+¨A¨A¨A¨q¨q¨q°/°>°/À1À1À1Ð,DÔEØ# CÔ(¨Ô+¨A¨A¨A¨q¨q¨q°/°>°/À1À1À1Ð,DÔEØ# CÔ(¨Ô+Ø# CÔ(¨Ô+ð	ñô ð ð õ   ™/œ/ˆ‰à	�E”OÔ,×2Ò2Ñ4Ô4Ð	4Ð	4ØŒÔ"Ð.°7¸e¼lÔ>XÐYZÔ>[×>aÒ>aÑ>cÔ>cÐ3cÐ3cå�˜_Ñ-Ô-Ñ.Ô.ð 	ð 	ˆCØ�OŠOà# CÔ(¨Ô+¨A¨A¨A¨q¨q¨q°/°>°/Ð,AÔBØ# CÔ(¨Ô+¨A¨A¨A¨°¨ÀÀÀÐ,AÔBðñô ð ð õ   ™/œ/ˆ‰à	˜œÔ1×7Ò7Ñ9Ô9Ð	9Ð	9ØŒÔ"Ð.°<À5Ä<ÔC]Ð^_ÔC`×CfÒCfÑChÔChÐ3hÐ3hàŒ<Ô#ð 	VÝ�S Ñ1Ô1Ñ2Ô2ð Sð S�Ø'6°sÔ';¸A¸A¸A¸À¸ÐPQÐPQÐPQÐ<QÔ'R� Ñ$Ð$ðSõ �S Ñ1Ô1Ñ2Ô2ð Vð V�Ø'6°sÔ';¸A¸A¸A¸q¸q¸qÀ/À>À/ÐSTÐSTÐSTÐ<TÔ'U� Ñ$Ð$ðVõ �˜_Ñ-Ô-Ñ.Ô.ð 	ð 	ˆCØ�OŠOà# CÔ(¨Ô+¨A¨A¨A¨q¨q¨q°/°>°/À1À1À1Ð,DÔEØ# CÔ(¨Ô+¨A¨A¨A¨q¨q¨q°/°>°/À1À1À1Ð,DÔEðñô ð ð õ   ™/œ/ˆØÐrT   Fc                 ó4  — t          | ¦  «        dk    r;d}|D ]&}|r|n|j        d         }||dd|…d|…f         fz  }Œ'| |fz  } |dz  }||z  }t          |¦  «        D ]9}d}|D ],}|r||z   n|j        d         }||d||dz   …d|…f         fz  }Œ-| |fz  } Œ:| S )z»
    Given the (decoder/cross attentions)/(decoder hidden states) for multiple generated tokens, splits it into a tuple
    where each member corresponds to a single generated token.
    r   rS   r°   .Nr   )rÂ   r¼   rð  )	rþ   Únew_outputsrB  rŽ  rs  Ú	new_tuplerä  Úlast_dim_sizerÜ  s	            rU   r|  r|    s  € õ ˆ7�|„|�qÒÐØˆ	Ø ð 	Að 	AˆEØ';ÐP˜G˜GÀÄÈRÄˆMØ˜%  X g X¨~°¨~Ð =Ô>Ð@Ñ@ˆIˆIØ�I�<Ñˆà�1‰ˆØ�WÑˆ	å�9ÑÔð  ð  ˆØˆ	Ø ð 	Bð 	BˆEØ+?ÐT˜G a™K˜KÀUÄ[ÐQSÄ_ˆMØ˜%  Q¨¨Q© Y°°°Ð >Ô?ÐAÑAˆIˆIØ�I�<ÑˆˆØ€NrT   r  ÚInfr  r  r  Úfilter_valuer  r‘   c                 ó¢   — |dk    r t          |||¬¦  «        d| ¦  «        } d|cxk    rdk    rn n t          |||¬¦  «        d| ¦  «        } | S )a
  
    Filter a distribution of logits using top-k and/or nucleus (top-p) filtering

    Args:
        logits: logits distribution shape (batch size, vocabulary size)
        top_k (`int`, *optional*, defaults to 0):
            If > 0, only keep the top k tokens with highest probability (top-k filtering)
        top_p (`float`, *optional*, defaults to 1.0):
            If < 1.0, only keep the top tokens with cumulative probability >= top_p (nucleus filtering). Nucleus
            filtering is described in Holtzman et al. (http://arxiv.org/abs/1904.09751)
        min_tokens_to_keep (`int`, *optional*, defaults to 1):
            Minimumber of tokens we keep per batch example in the output.

    From: https://gist.github.com/thomwolf/1a5a29f6962089e871b94cbd09daf317
    r   )r  r¥  r  Nr  )r  r¥  r  )r7   r8   )r  r  r  r¥  r  s        rU   Útop_k_top_p_filteringr§  ™  s†   € ð, ˆq‚y€yØpÕ!¨¸LÐ]oÐpÑpÔpØ�&ñ
ô 
ˆð 	ˆEÐÐÒÐ�SÒÐÐÐÐØpÕ!¨¸LÐ]oÐpÑpÔpØ�&ñ
ô 
ˆð €MrT   r	  r  Únext_top_k_probsÚalphaÚ
beam_widthc                 óÞ  — | |                       dd¬¦  «        z  }||                      dd¬¦  «        z  }t          j        ||                     dd¦  «        ¦  «                             d¦  «        }t          j        |d¬¦  «        \  }}	|                     d¦  «        }d|z
  |z  ||z  z
  }
t          j        t          j        |
|¦  «        ¦  «        }
|
                     d¬¦  «        \  }	}|S )a  
    Reranks the top_k candidates based on a degeneration penalty (cosine similarity with previous tokens), as described
    in the paper "A Contrastive Framework for Neural Text Generation". Returns the index of the best candidate for each
    row in the batch.
    r   T)rè   Úkeepdimr   r°   rç   r  )	ÚnormrO   Úmatmulre  râ  rj  r`  rc  rò  )r	  r  r¨  r©  rª  Únorm_context_hiddenÚnorm_next_hiddenÚcosine_matrixÚdegeneration_penaltyrþ  Úcontrastive_scorer
  s               rU   rñ  rñ  ¼  sú   € ð )¨>×+>Ò+>À1ÈdÐ+>Ñ+SÔ+SÑSÐØ" [×%5Ò%5¸!ÀTÐ%5Ñ%JÔ%JÑJÐÝ”LÐ!4Ð6F×6PÒ6PÐQRÐTUÑ6VÔ6VÑWÔW×_Ò_Ð`bÑcÔc€MÝ#œi¨¸2Ð>Ñ>Ô>ÑÐ˜!Ø'×,Ò,¨RÑ0Ô0ÐØ˜u™Ð(8Ñ8¸5ÐCWÑ;WÑWÐÝœ¥E¤KÐ0AÀ:Ñ$NÔ$NÑOÔOÐØ'×+Ò+°Ð+Ñ3Ô3�O€A€|ØÐrT   r�  )prÁ  r¥   rŽ  Údataclassesr   Útypingr   r   r   r   r   r	   r
   r   rO   Útorch.distributedÚdistributedr»  r   Úintegrations.deepspeedr   Úmodeling_outputsr   r   Úmodels.autor   r   r   r   r   Úutilsr   r   r   r   Úbeam_constraintsr   r   rz   r   r   r   Úconfiguration_utilsr    Úlogits_processr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   rN  r;   r<   r=   r>   r?   Úmodeling_utilsr@   Ú	streamersrA   Ú
get_loggerrK   rÅ  Úaccelerate.hooksrB   rC   rE   rW   r_   rb   rd   rf   rh   rn   rq   rs   r•  r–  r—  r˜  r”  r“  ru   r‡   rz  r|  r;  rR   rÃ   r§  rñ  rS   rT   rU   ú<module>rÃ     s…  ðð" €€€Ø €€€Ø €€€Ø !Ð !Ð !Ð !Ð !Ð !Ø SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ Sà €€€Ø  Ð  Ð  Ð  Ð  Ð  Ø Ð Ð Ð Ð Ð à ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø FÐ FÐ FÐ FÐ FÐ FÐ FÐ Fðð ð ð ð ð ð ð ð ð ð ð ð ð ð PÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OØ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RØ 1Ð 1Ð 1Ð 1Ð 1Ð 1ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð8ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð (Ø0Ð0Ð0Ð0Ð0Ð0Ø'Ð'Ð'Ð'Ð'Ð'à	ˆÔ	˜HÑ	%Ô	%€àÐÑÔð FØEÐEÐEÐEÐEÐEÐEÐEð ðDð Dð Dð Dð D Kñ Dô Dñ „ðDð6 ð#Lð #Lð #Lð #Lð #L¨Kñ #Lô #Lñ „ð#LðL ðDð Dð Dð Dð D¨ñ Dô Dñ „ðDð8 ð&Lð &Lð &Lð &Lð &L {ñ &Lô &Lñ „ð&LðR ðDð Dð Dð Dð D˜kñ Dô Dñ „ðDð8 ð'Lð 'Lð 'Lð 'Lð 'L ñ 'Lô 'Lñ „ð'LðT ðDð Dð Dð Dð D +ñ Dô Dñ „ðDðD ð.Lð .Lð .Lð .Lð .L [ñ .Lô .Lñ „ð.Lðb ðDð Dð Dð Dð D +ñ Dô Dñ „ðDðD ð-Lð -Lð -Lð -Lð -L [ñ -Lô -Lñ „ð-Lð` Ð;Ð=ZÐZÔ[Ð ØÐ/Ð1HÐHÔI€ØÐ7Ð9TÐTÔUÐ ØÐ7Ð9TÐTÔUÐ ØÐ EÐGiÐ iÔjÐ ØÐ)¨<Ð9IÐK[Ð]tÐtÔu€ð,ð ,ð ,ð ,ð ,�\ñ ,ô ,ð ,ð"aAð aAð aAð aAð aAñ aAô aAð aAðHC-ð -ð -ð`ð ð ð ð8 ØØ ˜5 ™<œ<˜-Øð ð  ØÔð àð ð ð ð ð	 ð
 ð ð Ôð ð  ð  ð  ðFØÔ%ðàÔ"ðð Ô'ðð ð	ð
 ðð Ôðð ð ð ð ð rT   