§
    Ý˜ºh«´ ã                   ód  — d dl Z 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 d dlZd dlmZ d dlmZ d dlmZ d dlmZ ddlmZmZmZmZmZ dd	lmZ dd
lmZmZm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC ddlmDZDmEZEmFZFmGZGmHZH ddlImJZJ ddlKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZe ddlfmgZgmhZhmiZimjZjmkZkmlZlmmZm erddlnmoZo ddlpmqZq ddlrmsZs  e2jt        eu¦  «        Zv e.¦   «         rd dlwmxZxmyZy g d¢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{Ze{Z€e{Z�e|Z‚e|Zƒe|Z„e}Z…e}Z†e~Z‡e~Zˆeeƒef         Z‰ee„e�f         ZŠee‡e…f         Z‹eeˆe†f         ZŒee‚e€f         Z�ee{e|f         ZŽee}e~f         Z�eeŽe�f         Z� G d&„ d'eJ¦  «        Z‘d(„ Z’d/d*„Z“d+e”e-         d,ed-e-fd.„Z•dS )0é    N)Ú	dataclass)ÚTYPE_CHECKINGÚAnyÚCallableÚOptionalÚUnion)Úfile_exists)Úversion)Únné   )ÚCacheÚDynamicCacheÚEncoderDecoderCacheÚQuantizedCacheÚStaticCache)ÚPretrainedConfig)Úcheck_python_requirementsÚget_cached_module_fileÚget_class_in_moduleÚresolve_trust_remote_code)Úis_deepspeed_zero3_enabled)Úis_fsdp_managed_module)Úcreate_masks_for_generate)Úisin_mps_friendly)ÚExtensionsTrie)ÚModelOutputÚis_accelerate_availableÚis_hqq_availableÚis_optimum_quanto_availableÚis_torchdynamo_exportingÚloggingé   )ÚDisjunctiveConstraintÚPhrasalConstraint)Ú
BeamScorerÚBeamSearchScorerÚConstrainedBeamSearchScorer)	ÚAssistantVocabTranslatorCacheÚAssistedCandidateGeneratorÚ-AssistedCandidateGeneratorDifferentTokenizersÚCandidateGeneratorÚEarlyExitCandidateGeneratorÚPromptLookupCandidateGeneratorÚ%UniversalSpeculativeDecodingGeneratorÚ_prepare_attention_maskÚ_prepare_token_type_ids)Ú ALL_STATIC_CACHE_IMPLEMENTATIONSÚ'DEPRECATED_STATIC_CACHE_IMPLEMENTATIONSÚSTATIC_CACHE_IMPLEMENTATIONSÚGenerationConfigÚGenerationMode)ÚContinuousMixin)Ú#EncoderNoRepeatNGramLogitsProcessorÚ'EncoderRepetitionPenaltyLogitsProcessorÚEpsilonLogitsWarperÚEtaLogitsWarperÚExponentialDecayLengthPenaltyÚForcedBOSTokenLogitsProcessorÚForcedEOSTokenLogitsProcessorÚHammingDiversityLogitsProcessorÚInfNanRemoveLogitsProcessorÚLogitNormalizationÚLogitsProcessorListÚMinLengthLogitsProcessorÚ!MinNewTokensLengthLogitsProcessorÚMinPLogitsWarperÚNoBadWordsLogitsProcessorÚNoRepeatNGramLogitsProcessorÚ PrefixConstrainedLogitsProcessorÚ RepetitionPenaltyLogitsProcessorÚSequenceBiasLogitsProcessorÚ$SuppressTokensAtBeginLogitsProcessorÚSuppressTokensLogitsProcessorÚTemperatureLogitsWarperÚTopKLogitsWarperÚTopPLogitsWarperÚTypicalLogitsWarperÚ.UnbatchedClassifierFreeGuidanceLogitsProcessor)ÚConfidenceCriteriaÚEosTokenCriteriaÚMaxLengthCriteriaÚMaxTimeCriteriaÚStoppingCriteriaÚStoppingCriteriaListÚStopStringCriteria)ÚPreTrainedModel)ÚPreTrainedTokenizerBase)ÚBaseStreamer)ÚAlignDevicesHookÚadd_hook_to_module)Úpast_key_valuesÚcache_paramsÚstateÚmemsÚpast_buckets_statesc                   óH  — e Zd ZU 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	ej
                                   ed<   dZee	e	ej
                                   ed<   dZee	e	e	ej
                                            ed<   dS )	ÚGenerateDecoderOnlyOutputaw  
    Outputs of decoder-only generation models, when using non-beam methods.

    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`):
            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)`.
        logits (`tuple(torch.FloatTensor)` *optional*, returned when `output_logits=True`):
            Unprocessed 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`):
            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`):
            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)`.
        past_key_values (`tuple(tuple(torch.FloatTensor)))`, *optional*, returned when `use_cache=True`):
            Returns the model cache, used to speed up decoding. Different models have a different cache format, check
            the model's documentation. Usually, a [`~cache_utils.Cache`] instance.
    Ú	sequencesNÚscoresÚlogitsÚ
attentionsÚhidden_statesr]   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚtorchÚ
LongTensorÚ__annotations__re   r   ÚtupleÚFloatTensorrf   rg   rh   r]   © ó    úe/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/transformers/generation/utils.pyrc   rc   ‰   sÒ   € € € € € € ðð ð4 ÔÐÐÑØ15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø<@€J�˜˜u UÔ%6Ô7Ô8Ô9Ð@Ð@Ñ@Ø?C€M�8˜E %¨Ô(9Ô":Ô;Ô<ÐCÐCÑCØHL€O�X˜e E¨%°Ô0AÔ*BÔ$CÔDÔEÐLÐLÑLÐLÐLrs   rc   c                   óä  — e Zd ZU 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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Zee	e	e	ej
                                            ed<   dS )ÚGenerateEncoderDecoderOutputaI  
    Outputs of encoder-decoder generation models, when using non-beam methods.

    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`):
            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)`.
        logits (`tuple(torch.FloatTensor)` *optional*, returned when `output_logits=True`):
            Unprocessed 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`):
            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`):
            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`):
            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`):
            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`):
            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)`.
        past_key_values (`tuple(tuple(torch.FloatTensor)))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
            Returns the model cache, used to speed up decoding. Different models have a different cache format, check
            the model's documentation. Usually, a [`~cache_utils.Cache`] instance.
    rd   Nre   rf   Úencoder_attentionsÚencoder_hidden_statesÚdecoder_attentionsÚcross_attentionsÚdecoder_hidden_statesr]   )ri   rj   rk   rl   rm   rn   ro   re   r   rp   rq   rf   rw   rx   ry   rz   r{   r]   rr   rs   rt   rv   rv   ­   s4  € € € € € € ð!ð !ðF ÔÐÐÑØ15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø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ØHL€O�X˜e E¨%°Ô0AÔ*BÔ$CÔDÔEÐLÐLÑLÐLÐLrs   rv   c                   ó�  — e Zd ZU 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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Zeeeeej	                                            ed
<   dS )ÚGenerateBeamDecoderOnlyOutputaé
  
    Outputs of decoder-only generation models, when using beam methods.

    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`):
            Final beam scores of the generated `sequences`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `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)`.
        logits (`tuple(torch.FloatTensor)` *optional*, returned when `output_logits=True`):
            Unprocessed 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_beams, config.vocab_size)`.
        beam_indices (`torch.LongTensor`, *optional*, returned when `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`):
            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`):
            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)`.
        past_key_values (`tuple(tuple(torch.FloatTensor)))`, *optional*, returned when `use_cache=True`):
            Returns the model cache, used to speed up decoding. Different models have a different cache format, check
            the model's documentation. Usually, a [`~cache_utils.Cache`] instance.
    rd   NÚsequences_scoresre   rf   Úbeam_indicesrg   rh   r]   )ri   rj   rk   rl   rm   rn   ro   r~   r   rq   re   rp   rf   r   rg   rh   r]   rr   rs   rt   r}   r}   Ý   s  € € € € € € ðð ð@ ÔÐÐÑØ48Ð�h˜uÔ0Ô1Ð8Ð8Ñ8Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø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ØHL€O�X˜e E¨%°Ô0AÔ*BÔ$CÔDÔEÐLÐLÑLÐLÐLrs   r}   c                   ó,  — e Zd ZU 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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Zeeeeej	                                            ed<   dS )Ú GenerateBeamEncoderDecoderOutputa¼  
    Outputs of encoder-decoder generation models, when using beam methods.

    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`):
            Final beam scores of the generated `sequences`.
        scores (`tuple(torch.FloatTensor)` *optional*, returned when `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)`.
        logits (`tuple(torch.FloatTensor)` *optional*, returned when `output_logits=True`):
            Unprocessed 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_beams, config.vocab_size)`.
        beam_indices (`torch.LongTensor`, *optional*, returned when `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`):
            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`):
            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`):
            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`):
            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`):
            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)`.
        past_key_values (`tuple(tuple(torch.FloatTensor)))`, *optional*, returned when `use_cache=True`):
            Returns the model cache, used to speed up decoding. Different models have a different cache format, check
            the model's documentation. Usually, a [`~cache_utils.Cache`] instance.
    rd   Nr~   re   rf   r   rw   rx   ry   rz   r{   r]   )ri   rj   rk   rl   rm   rn   ro   r~   r   rq   re   rp   rf   r   rw   rx   ry   rz   r{   r]   rr   rs   rt   r�   r�   	  se  € € € € € € ð(ð (ðT ÔÐÐÑØ48Ð�h˜uÔ0Ô1Ð8Ð8Ñ8Ø15€FˆH�U˜5Ô,Ô-Ô.Ð5Ð5Ñ5Ø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ØHL€O�X˜e E¨%°Ô0AÔ*BÔ$CÔDÔEÐLÐLÑLÐLÐLrs   r�   c            $       ó´  — e Zd ZdZ	 	 d~deeeej        f                  dee	         de
fd„Zdej        deej                 d	eej                 deej        ej        f         fd
„Zdej        deej                 d	eej                 deej        ej        f         fd„Z	 	 	 	 ddej        dee         deej                 deej                 d	eej                 f
d„Z	 	 	 d€deej                 deej                 deeeej        f                  deej        ee         eeej        f         f         fd„Z	 	 	 d€deej                 deej                 deeeej        f                  dej        fd„Zdej        dedeeef         dej        fd„Zdej        dee         dedeeef         fd„Z	 d�dededeeej        f         dej        deej                 deej        eeej        f         f         fd„Ze	 	 	 d‚ded e	deej                 deej        eeef         f         fd!„¦   «         Z 	 	 dƒd"e!deeef         d e	d#edeeef         f
d$„Z"dedej        dej        d%d&d'e#d(d)d*d)dede$fd+„Z%	 	 	 	 	 	 	 	 d„ded,ee         d-ej        d.ee
eej        ge&e         f                  d'ee#         dee         deeeef                  d/eej                 d0eej                 de#fd1„Z'	 d�ded2ee(         d3ed)         de(fd4„Z)d5ee#e(f         d6ee#e(f         dee#e(f         fd7„Z*	 	 d…d8ej        d9eej                 d:eej                 d;e	dej        f
d<„Z+d=„ Z,deeef         fd>„Z-d?„ Z.d@„ Z/	 d�dee         dAee	         dBedeeef         fdC„Z0dD„ Z1dEededFedefdG„Z2e3de	fdH„¦   «         Z4deded%d&dedIede	fdJ„Z5de	fdK„Z6	 	 d~dedLee	         deeej        ef                  fdM„Z7dedede	fdN„Z8 ej9        ¦   «         	 	 	 	 	 	 	 	 	 	 	 	 d†deej                 dee         d'ee#         d2ee(         d.ee
eej        ge&e         f                  dOee	         d%ed&         dPedQ         d/eej                 d0eej                 dAee	         dReeee
f                  dee:ej        f         fdS„¦   «         Z;dTe	dOe	dej        de	fdU„Z<	 d�dej        d3ed)         dej        fdV„Z=dej        d'e#d2e(dedOe	dPedQ         dee>ej        f         fdW„Z?edXej        dej        fdY„¦   «         Z@edXej        dedZedej        fd[„¦   «         ZAedXej        d:ej        dej        fd\„¦   «         ZBed]ej        d^ej        d_ej        d`ej        daedbedceddee	ef         deeCfdf„¦   «         ZDed]ej        d`ej        dgej        ddee	ef         fdh„¦   «         ZEdiej        djej        dkej        daedcedle	dmedZednededeej        ej        ej        f         fdo„ZFdpej        dqej        drej        dgej        dZedeej        ej        ej        f         fds„ZGd8ej        dqej        d_ej        dpej        d:ej        drej        d]ej        d`ej        dgej        dtej        dZedaedcedeeCddee	ef         deej        ej        ej        ej        f         f du„ZHdej        d'e#d2e(dedOe	deeIej        f         fdv„ZJdej        dweKd'e#d2e(dedOe	fdx„ZLdej        dyeMd'e#d2e(dedOe	deeIej        f         fdz„ZNdej        d{e$d'e#d2e(dedOe	dPedQ         dee>ej        f         fd|„ZOdej        defd}„ZPdS )‡ÚGenerationMixinaO	  
    A class containing all functions for auto-regressive text generation, to be used as a mixin in model classes.
    Inheriting from this class causes the model to have special generation-related behavior, such as loading a
    `GenerationConfig` at initialization time or ensuring `generate`-related tests are run in `transformers` CI.

    A model class should inherit from `GenerationMixin` to enable calling methods like `generate`, or when it
    has defined a custom `generate` method that relies on `GenerationMixin`, directly or indirectly, which
    approximately shares the same interface to public methods like `generate`. Three examples:
        - `LlamaForCausalLM` should inherit from `GenerationMixin` to enable calling `generate` and other public
            methods in the mixin;
        - `BlipForQuestionAnswering` has a custom `generate` method that approximately shares the same interface as
           `GenerationMixin.generate` (it has a few extra arguments, and the same output). That function also calls
           `GenerationMixin.generate` indirectly, through an inner model. As such, `BlipForQuestionAnswering` should
           inherit from `GenerationMixin` to benefit from all generation-related automation in our codebase;
        - `BarkModel` has a custom `generate` method and one of its inner models calls `GenerationMixin.generate`.
            However, its `generate` does not share the same interface as `GenerationMixin.generate`. In this case,
            `BarkModel` should NOT inherit from `GenerationMixin`, as it breaks the `generate` interface.

    The class exposes [`~generation.GenerationMixin.generate`], which can be used for:
        - *greedy decoding* if `num_beams=1` and `do_sample=False`
        - *multinomial sampling* if `num_beams=1` and `do_sample=True`
        - *beam-search decoding* if `num_beams>1` and `do_sample=False`
        - *beam-search multinomial sampling* if `num_beams>1` and `do_sample=True`
        - *diverse beam-search decoding* if `num_beams>1` and `num_beam_groups>1`
        - *constrained beam-search decoding* if `constraints!=None` or `force_words_ids!=None`
        - *assisted decoding* if `assistant_model` or `prompt_lookup_num_tokens` is passed to `.generate()`

    To learn more about decoding strategies refer to the [text generation strategies guide](../generation_strategies).
    NÚpretrained_model_name_or_pathÚtrust_remote_codeÚreturnc                 ó¬  — t           j                             |¦  «        }d}|r@t           j                             t           j                             |d¦  «        ¦  «        sd}nt	          |d¦  «        sd}|st          d|› d�¦  «        ‚d|› d�}t          |||| |¬¦  «         t          |fd	d
i|¤Ž t          |fddi|¤Ž}t          d|¦  «        }|S )at  
        Loads and returns a custom generate function, given a model repo.

        Args:
            pretrained_model_name_or_path (`str` or `os.PathLike`):
                 Can be either:
                    - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                    - A path to a *directory* containing model weights saved using
                      [`~PreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.
            trust_remote_code (`bool`, *optional*):
                Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
                should only be set to `True` for repositories you trust and in which you have read the code, as it will
                execute code present on the Hub on your local machine.
            **kwargs:
                Additional keyword arguments for remote code loading.

        Raises:
            OSError: If `pretrained_model_name_or_path` does not contain a `custom_generate` subdirectory.

        Returns:
            A callable that can be used to generate text.
        Tzcustom_generate/generate.pyFú`zw` does not contain a `custom_generate` subdirectory with a `generate.py` file, can't load the custom generate function.zThe repository `zS` contains custom generation code that will override the default `generate` method.)Úhas_local_codeÚhas_remote_codeÚerror_messageÚrequirements_filez custom_generate/requirements.txtÚmodule_fileÚgenerate)
ÚosÚpathÚexistsÚjoinr	   ÚOSErrorr   r   r   r   )	Úselfr„   r…   ÚkwargsÚis_local_codeÚhas_custom_generate_folderr‹   ÚmoduleÚcustom_generate_functions	            rt   Úload_custom_generatez$GenerationMixin.load_custom_generate}  sX  € õ: œŸšÐ'DÑEÔEˆØ%)Ð"Øð 	3Ý”7—>’>¥"¤'§,¢,Ð/LÐNkÑ"lÔ"lÑmÔmð 3Ø-2Ð*øåÐ<Ð>[Ñ\Ô\ð 3Ø-2Ð*à)ð 	ÝðOÐ1ð Oð Oð Oñô ð ð-Ð<ð -ð -ð -ð 	õ 	"ØØ)Ø(Ø -Ð-Ø'ð	
ñ 	
ô 	
ð 	
õ 	"Ø)ð	
ð 	
Ø=_ð	
Øcið	
ð 	
ð 	
õ (Ø)ð
ð 
Ø7Tð
ØX^ð
ð 
ˆõ $7°zÀ6Ñ#JÔ#JÐ Ø'Ð'rs   Ú	input_idsÚinputs_embedsÚcache_positionc                 óh  — t          ¦   «         r|                      |||¦  «        S |�,|j        d         dk    r|dd…|j        d          d…f         }n\|€|d         |j        d         k    r|dd…|j        d          d…f         }n(|j        d         |j        d         k    r|dd…|f         }||fS )aü  
        Generic cache-dependent input preparation
        The code is put in a separate function to allow granular unit testing
        as it needs a different implementation to be exportable.

        If we have cache: let's slice `input_ids` through `cache_position`, to keep only the unprocessed tokens
        - Exception 1: when passing input_embeds, input_ids may be missing entries
        - Exception 2: some generation methods do special slicing of input_ids, so we don't need to do it here
        - Exception 3: with synced GPUs cache_position may go out of bounds, but we only want dummy token in that case.
        - Exception 4: If input_embeds are passed then slice it through `cache_position`, to keep only the unprocessed tokens and
          generate the first token for each sequence. Later use the generated Input ids for continuation.

        The current implementation does not rely on ``self`` and could be
        a class method. It is left as a standard method to be easily rewritten.
        Nr"   r   éÿÿÿÿ)r    Ú,_cache_dependant_input_preparation_exportingÚshape)r”   r›   rœ   r�   s       rt   Ú"_cache_dependant_input_preparationz2GenerationMixin._cache_dependant_input_preparationÀ  så   € õ* $Ñ%Ô%ð 	oØ×DÒDÀYÐP]Ð_mÑnÔnÐnØÐ$¨¬¸Ô);¸qÒ)@Ð)@Ø)¨!¨!¨!¨nÔ.BÀ1Ô.EÐ-EÐ-GÐ-GÐ*GÔHˆMˆMàÐ%Ø˜rÔ" i¤o°aÔ&8Ò8Ð8à! ! ! ! nÔ&:¸1Ô&=Ð%=Ð%?Ð%?Ð"?Ô@ˆIˆIØŒ_˜QÔ >Ô#7¸Ô#:Ò:Ð:Ø! ! ! ! ^Ð"3Ô4ˆIØ˜iÐ'Ð'rs   c                 ó¦   ‡‡‡— |€|dd…|f         }n<d„ Šd„ Šd„ Št          j        |j        d         dk    ˆfd„ˆˆfd„|||g¦  «        \  }}||fS )	zý
        This method implements method ``_cache_dependant_input_preparation``
        with :func:`torch.cond` to make it exportable with :func:`torch.export.export`.
        The code is put in a separate function to allow granular unit testing.
        Nc                 óZ   — | d d …|j         d          d …f                              ¦   «         S ©Nr   ©r¡   Úclone)rœ   r�   s     rt   Úbranch_1zNGenerationMixin._cache_dependant_input_preparation_exporting.<locals>.branch_1ú  s3   € Ø$ Q Q Q¨Ô)=¸aÔ)@Ð(@Ð(BÐ(BÐ%BÔC×IÒIÑKÔKÐKrs   c                 óZ   — | d d …|j         d          d …f                              ¦   «         S r¥   r¦   ©r›   r�   s     rt   Úbranch_2zNGenerationMixin._cache_dependant_input_preparation_exporting.<locals>.branch_2ý  s3   € Ø     ^Ô%9¸!Ô%<Ð$<Ð$>Ð$>Ð!>Ô?×EÒEÑGÔGÐGrs   c                 ó>   — | d d …|f                               ¦   «         S ©N©r§   rª   s     rt   Úbranch_3zNGenerationMixin._cache_dependant_input_preparation_exporting.<locals>.branch_3   s"   € Ø     NÐ!2Ô3×9Ò9Ñ;Ô;Ð;rs   r"   r   c                 óD   •—  ‰||¦  «        |                       ¦   «         fS r­   r®   )r›   rœ   r�   r¨   s      €rt   ú<lambda>zNGenerationMixin._cache_dependant_input_preparation_exporting.<locals>.<lambda>  s'   ø€ Ø ˜ °Ñ?Ô?Ø!ŸšÑ)Ô)ðF€ rs   c                 ój   •— |t          j        |d         | j        d         k    ‰ˆfd„| |g¦  «        fS )NrŸ   r"   c                 ól   •— t          j        | j        d         |j        d         k    ‰d„ | |g¦  «        S )Nr"   r   c                 ó*   — |                       ¦   «         S r­   r®   rª   s     rt   r±   zrGenerationMixin._cache_dependant_input_preparation_exporting.<locals>.<lambda>.<locals>.<lambda>.<locals>.<lambda>  s   € ÀyÇÂÑGXÔGX€ rs   ©rm   Úcondr¡   )r›   r�   r¯   s     €rt   r±   z`GenerationMixin._cache_dependant_input_preparation_exporting.<locals>.<lambda>.<locals>.<lambda>  s?   ø€ Ý %¤
Ø$-¤O°AÔ$6¸.Ô:NÈqÔ:QÒ$QØ$,Ø%XÐ%XØ%.°Ð$?ñ	!"ô !"ð rs   rµ   )r›   rœ   r�   r«   r¯   s      €€rt   r±   zNGenerationMixin._cache_dependant_input_preparation_exporting.<locals>.<lambda>  sR   ø€ Ø%Ýœ
Ø*¨2Ô.°)´/À!Ô2DÒDØ$ðð ð ð ð '¨Ð7ñô ðF€ rs   rµ   )r”   r›   rœ   r�   r¨   r«   r¯   s       @@@rt   r    z<GenerationMixin._cache_dependant_input_preparation_exportingâ  sÂ   øøø€ ð Ð Ø! ! ! ! ^Ð"3Ô4ˆIˆIðLð Lð LðHð Hð Hð<ð <ð <õ (-¤zØ” Ô" aÒ'ðð ð ð ðð ð ð ð ð" ˜M¨>Ð:ñ5(ô (Ñ$ˆM˜9ð8 ˜iÐ'Ð'rs   r]   Úattention_maskc           
      óì  — i }||d<   |�||d<   |                       |||¦  «        \  }}| j        j        rdnd}| j        j        sT|�)t          |¦  «        |j        d         k    rd||<   ||d<   nL|                     t          j        ¬¦  «        ||<   d|d<   n#|                     t          j        ¬¦  «        ||<   | j        j        r|nd}	| j        j        r|                     d	d¦  «        n|}| j        j        rd	nd
}
| j        j        rdnd}|��| 	                    |¦  «        €ˆ|t          t          j        | j        ¦  «        j                             ¦   «         ¦  «        v rI|                     ¦   «                              d¦  «        dz
  }|                     |dk    d¦  «         |||<   dD ]Š}| 	                    |¦  «        }|�q|�j| 	                    d¦  «        �|d         j        d         n||         j        d         }|dd…| d…f         }|                     t          j        ¬¦  «        }|||<   Œ‹t'          |t(          ¦  «        �r[|j        �rS|��P|j        dk    �rD| j        j        s|d         �|d         j        \  }}}n||         j        dd…         \  }}t/          | | j        | ¦  «        }t3          |d¦  «        r|                     ¦   «         nd}t/          |dd¦  «        }|€|�t/          |dd¦  «        }|€s| 	                    d¦  «        }| 	                    |¦  «        }t/          | dt6          ¦  «        } || j        t          j        ||f| j        ¬¦  «        |||||¬¦  «        }n/ ||||                     ¦   «         | j        ||| j        |¬¦  «        }|�|||
<   |	�|	|d
<   |                     ¦   «         D ]\  }}||vr|||<   Œ|                     dd¦  «         |S )a‚  
        Prepare the model inputs for generation. It includes operations like computing the 4D attention mask or
        slicing inputs given the existing cache.

        See the forward pass in the model documentation for expected arguments (different models might have different
        requirements for e.g. `past_key_values`). This function should work as is for most LLMs.
        r�   Nr]   Údecoder_input_idsr›   r"   rœ   )Úmemory_formatÚdecoder_attention_maskr·   Údecoder_position_idsÚposition_idsrŸ   r   )r½   Útoken_type_idsr¼   r   Úget_decoderÚ5_prepare_4d_causal_attention_mask_with_cache_positionr¾   r   ©Údtype)ÚconfigÚinput_embedsr·   r�   r]   r½   r¾   )Úsequence_lengthÚtarget_lengthrÂ   r�   Ú
batch_sizerÃ   r]   Úlabels) r¢   rÃ   Úis_encoder_decoderÚlenr¡   r§   rm   Úcontiguous_formatÚpopÚgetÚsetÚinspectÚ	signatureÚforwardÚ
parametersÚkeysÚlongÚcumsumÚmasked_fill_Ú
isinstancer   Úis_compileableÚndimÚgetattrÚbase_model_prefixÚhasattrr¿   r   ÚemptyrÂ   Úget_max_cache_shapeÚitems)r”   r›   r]   r·   rœ   r�   r•   Úmodel_inputsÚinput_ids_keyÚencoder_attention_maskÚattention_mask_keyÚposition_ids_keyr½   Úmodel_input_nameÚmodel_inputÚcurrent_input_lengthrÇ   rÅ   Ú_Ú
base_modelÚdecoderÚcausal_mask_creation_functionr¾   ÚkeyÚvalues                            rt   Úprepare_inputs_for_generationz-GenerationMixin.prepare_inputs_for_generation!  sÞ  € ð$ ˆØ)7ˆÐ%Ñ&ð Ð&Ø.=ˆLÐ*Ñ+Ø'+×'NÒ'NØ˜=¨.ñ(ô (Ñ$ˆM˜9ð
 04¬{Ô/MÐ^Ð+Ð+ÐS^ˆàŒ{Ô-ð 		aØÐ(­S°Ñ-@Ô-@ÀMÔDWÐXYÔDZÒ-ZÐ-ZØ.2�˜]Ñ+Ø0=�˜_Ñ-Ð-ð /8¯oªoÍEÔLc¨oÑ.dÔ.d�˜]Ñ+Ø04�˜_Ñ-Ð-à*3¯/ª/ÍÔH_¨/Ñ*`Ô*`ˆL˜Ñ'ð 48´;Ô3QÐ![  ÐW[Ðà:>¼+Ô:XÐlˆF�JŠJÐ/°Ñ6Ô6Ð6Ð^lð 	ð :>¼Ô9WÐmÐ5Ð5Ð]mÐØ59´[Ô5SÐgÐ1Ð1ÐYgÐàÐ&Ø—
’
Ð+Ñ,Ô,Ð4Ø ¥C­Ô(9¸$¼,Ñ(GÔ(GÔ(R×(WÒ(WÑ(YÔ(YÑ$ZÔ$ZÐZÐZà)×.Ò.Ñ0Ô0×7Ò7¸Ñ;Ô;¸aÑ?ˆLØ×%Ò% n¸Ò&9¸1Ñ=Ô=Ð=Ø'3ˆFÐ#Ñ$ð ![ð 	=ð 	=ÐØ Ÿ*š*Ð%5Ñ6Ô6ˆKØÐ&Ø"Ð.ð (×+Ò+¨OÑ<Ô<ÐHð % _Ô5Ô;¸AÔ>Ð>à)¨-Ô8Ô>¸qÔAð )ð
 #.¨a¨a¨aÐ2FÐ1FÐ1GÐ1GÐ.GÔ"H�KØ"-×"3Ò"3Å%ÔBYÐ"3Ñ"ZÔ"Z�KØ1<�Ð-Ñ.øõ
 �­Ñ.Ô.ñ1	àÔ.ñ1	ð Ñ*ØÔ# qÒ(Ñ(à”;Ô1ð T°lÀ?Ô6SÐ6_Ø1=¸oÔ1NÔ1TÑ.�
˜O¨Q¨Qà.:¸=Ô.IÔ.OÐPRÐQRÐPRÔ.SÑ+�
˜Oõ !  tÔ'=¸tÑDÔDˆJÝ29¸*ÀmÑ2TÔ2TÐ^�j×,Ò,Ñ.Ô.Ð.ÐZ^ˆGÝ,3ØÐSÐUYñ-ô -Ð)ð -Ð4¸Ð9LÝ07ØÐTÐVZñ1ô 1Ð-ð
 -Ð4Ø!-×!1Ò!1Ð2BÑ!CÔ!C�Ø+×/Ò/Ð0@ÑAÔA�å07¸Ð>YÕ[tÑ0uÔ0uÐ-Ø!>Ð!>Øœ;å!&¤¨j¸/Ð-JÐRVÔR\Ð!]Ñ!]Ô!]Ø#1Ø#1Ø$3Ø!-Ø#1ð	"ñ 	"ô 	"��ð "?Ð!>Ø"Ø$3Ø"1×"EÒ"EÑ"GÔ"GØœ*Ø#1Ø)Øœ;Ø$3ð	"ñ 	"ô 	"�ð Ð%Ø/=ˆLÐ+Ñ,à!Ð-Ø-CˆLÐ)Ñ*ð !Ÿ,š,™.œ.ð 	*ð 	*‰JˆC�Ø˜,Ð&Ð&Ø$)�˜SÑ!øð 	×Ò˜ 4Ñ(Ô(Ð(ØÐrs   ÚinputsÚbos_token_idÚmodel_kwargsc                 ó$  ‡— | 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Ë|d
         €|                     d
¦  «         n­| j         j        s…d
t          t          j
        | j        ¦  «        j                             ¦   «         ¦  «        v }|st          d| j        j        › d�¦  «        ‚|                      |||¬¦  «        |d	<   |d
         d
c}Šn|�t          d¦  «        ‚|d
         d
c}Š|                      |||¦  «        }|‰|fS )zT
        This function extracts the model-specific `inputs` for generation.
        Úencoderc                 ó,   •— i | ]\  }}|€|‰k    ¯||“ŒS r­   rr   )Ú.0ÚkÚvÚ
input_names      €rt   ú
<dictcomp>z9GenerationMixin._prepare_model_inputs.<locals>.<dictcomp>À  s/   ø€ ÐbÐbÐb¡  AÀÀÐRSÐWaÒRaÐRa˜˜1ÐRaÐRaÐRars   Nz
`inputs`: z` were passed alongside z0 which is not allowed. Make sure to either pass z or z=...r›   rœ   zAYou 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.)rÃ   rÉ   rÜ   ró   Úmain_input_namerß   rÌ   Ú
ValueErrorrÎ   rÏ   rÐ   rî   rÒ   rÓ   Ú	__class__ri   Ú*_maybe_initialize_input_ids_for_generation)r”   rï   rð   rñ   Úinputs_kwargÚhas_inputs_embeds_forwardingrø   s         @rt   Ú_prepare_model_inputsz%GenerationMixin._prepare_model_inputs¬  sA  ø€ ð Œ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Ø˜OÔ,Ð4Ø× Ò  Ñ1Ô1Ð1Ð1Ø”[Ô3ð TØ/>Å#ÝÔ% dÔ&HÑIÔIÔT×YÒYÑ[Ô[ñCô Cð 0Ð,ð 4ð Ý$ðxÐ\`Ô\jÔ\sð xð xð xñô ð ð -1×,[Ò,[Ø˜L°|ð -\ñ -ô -�˜[Ñ)ð &2°/Ô%BÀOÐ"�˜
˜
àÐ%Ý$Ð%tÑuÔuÐuØ%1°/Ô%BÀOÐ"�˜
ð ×@Ò@ÀÈÐWcÑdÔdˆØ�z <Ð/Ð/rs   c                 ó8  — |�|S |                      d¦  «        }| j        j        rL|�J|j                             ¦   «         dd…         }t          j        |t
          j        | j        ¬¦  «        dz  S d}| 	                    ¦   «         D ]+}t          |t
          j        ¦  «        r|j        d         } nŒ,d|v r(t          j        |dft
          j        | j        ¬¦  «        S |€t          d	¦  «        ‚t          j        |dft
          j        | j        ¬¦  «        |z  S )
z3Initializes input ids for generation, if necessary.NÚencoder_outputsrŸ   ©rÂ   Údeviceiœÿÿÿr"   r   rœ   zB`bos_token_id` has to be defined when no `input_ids` are provided.)rÍ   rÃ   rÉ   Úlast_hidden_stateÚsizerm   ÚonesrÔ   r  Úvaluesr×   ÚTensorr¡   rû   )r”   rï   rð   rñ   r  r¡   rÇ   rí   s           rt   rý   z:GenerationMixin._maybe_initialize_input_ids_for_generationï  s$  € ð ÐØˆMà&×*Ò*Ð+<Ñ=Ô=ˆØŒ;Ô)ð 	R¨oÐ.Ià#Ô5×:Ò:Ñ<Ô<¸S¸b¸SÔAˆEÝ”:˜e­5¬:¸d¼kÐJÑJÔJÈTÑQÐQð ˆ
Ø!×(Ò(Ñ*Ô*ð 	ð 	ˆEÝ˜%¥¤Ñ.Ô.ð Ø"œ[¨œ^�
Ø�ðð ˜lÐ*Ð*Ý”:˜z¨1˜oµU´ZÈÌÐTÑTÔTÐTàÐÝÐaÑbÔbÐbåŒz˜: q˜/µ´ÀDÄKÐPÑPÔPÐS_Ñ_Ð_rs   Úinputs_tensorÚgeneration_configc                 óZ  — |j         }|j        }d|v r|d         j        d         dk    r|d         }t          j        |j        d d…         t          j        |j        ¬¦  «        }|€|S t          |j        ¦  «        dk    o|j        t          j	        t          j        fv }|s|S |d uo"t          ||¬¦  «                             ¦   «         }|d u p#t          ||¬¦  «                             ¦   «          }	||	z  }
|                     |¦  «                             ¦   «         }||
z  ||
 z  z   }|S )Nr›   r"   r   r   r  ©ÚelementsÚtest_elements)Ú_pad_token_tensorÚ_eos_token_tensorr¡   rm   r  rÔ   r  rÊ   rÂ   Úintr   ÚanyÚne)r”   r
  r  rñ   Úpad_token_idÚeos_token_idÚdefault_attention_maskÚis_input_idsÚis_pad_token_in_inputsÚ&is_pad_token_not_equal_to_eos_token_idÚcan_infer_attention_maskÚattention_mask_from_paddingr·   s                rt   Ú&_prepare_attention_mask_for_generationz6GenerationMixin._prepare_attention_mask_for_generation  sn  € ð )Ô:ˆØ(Ô:ˆð ˜,Ð&Ð&¨<¸Ô+DÔ+JÈ1Ô+MÐPQÒ+QÐ+QØ(¨Ô5ˆMõ "'¤¨MÔ,?ÀÀÀÔ,CÍ5Ì:Ð^kÔ^rÐ!sÑ!sÔ!sÐØÐØ)Ð)å˜=Ô.Ñ/Ô/°1Ò4Ðg¸Ô9LÕQVÔQZÕ\aÔ\fÐPgÐ9gˆØð 	*Ø)Ð)à".°dÐ":ð "
Ý }ÀLÐQÑQÔQ×UÒUÑWÔWð 	ð 3?À$Ð2Fð 2
Ý |À<ÐPÑPÔP×TÒTÑVÔVðL
Ð.ð $:Ð<bÑ#bÐ Ø&3×&6Ò&6°|Ñ&DÔ&D×&IÒ&IÑ&KÔ&KÐ#ð (Ð*BÑBÐE[Ð_wÐ^wÑEwÑwð 	ð Ðrs   rå   c                 ó"  ‡‡	— |                       ¦   «         }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 ¦   «         }|j        |d
<   |j        |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     €rt   ú	<genexpr>z\GenerationMixin._prepare_encoder_decoder_kwargs_for_generation.<locals>.<dictcomp>.<genexpr>I  s1   øè è € ÐIÐI°!�x×*Ò*¨1Ñ-Ô-ÐIÐIÐIÐIÐIÐIrs   ©r  )rõ   rí   r)  Úirrelevant_prefixs     @€rt   rù   zRGenerationMixin._prepare_encoder_decoder_kwargs_for_generation.<locals>.<dictcomp>F  sT   øø€ ð 
ð 
ð 
á�˜%ÝÐIÐIÐIÐIÐ7HÐIÑIÔIÑIÔIð
Ø�eð
ð 
ð 
rs   r•   rñ   c                 ó$   •— i | ]\  }}|‰v ¯	||“ŒS rr   rr   )rõ   r)  rí   Úencoder_signatures      €rt   rù   zRGenerationMixin._prepare_encoder_decoder_kwargs_for_generation.<locals>.<dictcomp>N  s2   ø€ ð ð ð Ù$3 H¨eÐQYÐ]nÐQnÐQn�˜%ÐQnÐQnÐQnrs   Úoutput_attentionsÚoutput_hidden_statesÚreturn_dictr  rr   )Úget_encoderrÜ   r   r!  r\   r[   rß   rÎ   rÏ   rÐ   rÑ   rÒ   r/  r0  rú   )
r”   r
  rñ   rå   r  ró   Úencoder_kwargsÚencoder_accepts_wildcardr.  r,  s
           @@rt   Ú._prepare_encoder_decoder_kwargs_for_generationz>GenerationMixin._prepare_encoder_decoder_kwargs_for_generation3  sŒ  øø€ ð ×"Ò"Ñ$Ô$ˆõ �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ð /@Ô.QˆÐ*Ñ+Ø1BÔ1WˆÐ-Ñ.ð 0@Ð/KÐ+Ð+ÐQUÔQeÐØ(,ˆ�}Ñ%Ø+8ˆÐ'Ñ(Ø7>°wÐ7PÐ7PÀÐ7PÐ7PˆÐ&Ñ'àÐrs   rÇ   Údecoder_start_token_idr  c                 óš  — |�d|v r|                      d¦  «        }n"d|v r|dk    r|                      d¦  «        }nd}|€| j        }|j        dk    rH|j        d         |k    r t	          d|› d|j        d         › �¦  «        ‚|                     dd¦  «        }n&t          j        |dft          j        |¬	¦  «        |z  }|€|}�nd
| j	        j
                             ¦   «         v s5| j        j        dk    r&d
| j        j        j                             ¦   «         v rn¬| j        j        dv rn�|dd…df         |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 modelsNr¹   r›   r"   r   z1`decoder_start_token_id` expected to have length z	 but got rŸ   r  Údonutzvision-encoder-decoder)Úwhisper©Údimr»   )rÌ   r  rÙ   r¡   rû   Úviewrm   r  rÔ   rü   ri   ÚlowerrÃ   Ú
model_typeró   ÚallÚitemÚcatÚ	ones_like)r”   rÇ   rå   rñ   r6  r  r¹   r»   s           rt   Ú)_prepare_decoder_input_ids_for_generationz9GenerationMixin._prepare_decoder_input_ids_for_generation\  sC  € ð Ð#Ð(;¸|Ð(KÐ(KØ ,× 0Ò 0Ð1DÑ EÔ EÐÐØ˜LÐ(Ð(Ð-=ÀÒ-LÐ-LØ ,× 0Ò 0°Ñ =Ô =ÐÐà $Ðð ˆ>Ø”[ˆFØ!Ô&¨!Ò+Ð+Ø%Ô+¨AÔ.°*Ò<Ð<Ý Ø~È
Ð~Ð~Ð]sÔ]yÐz{Ô]|Ð~Ð~ñô ð ð &<×%@Ò%@ÀÀQÑ%GÔ%GÐ"Ð"õ ”
˜J¨˜?µ%´*ÀVÐLÑLÔLÐOeÑeð #ð Ð$Ø 6ÐÑð ˜œÔ/×5Ò5Ñ7Ô7Ð7Ð7ØŒKÔ"Ð&>Ò>Ð>À7ÈdÌkÔNaÔNl×NrÒNrÑNtÔNtÐCtÐCtàØŒ[Ô# {Ð2Ð2Øð      1 Ô%Ð)?ÀÀÀÀ1ÀÔ)EÒE×JÒJÑLÔL×QÒQÑSÔSð 	PÝ %¤	Ð+AÐCTÐ*UÐ[]Ð ^Ñ ^Ô ^ÐØ'¨<Ð7Ð7Ø)5Ð6NÔ)OÐ&Ý).¬Ý”_Ð%;Ñ<Ô<¸Q¸Q¸QÀÀÀ¸UÔCÐE[Ð\Øð*ñ *ô *Ð&ð :P�Ð5Ñ6à  ,Ð.Ð.rs   r"   FÚexpand_sizerÉ   c                 óæ   ‡ — ‰ dk    r||fS ˆ fd„}|�|                      ‰ d¬¦  «        } ||¦  «        }|r8|                     d¦  «        €t          d¦  «        ‚ ||d         ¦  «        |d<   ||fS )zIExpands tensors from [batch_size, ...] to [batch_size * expand_size, ...]r"   c                 ó®   •— | D ]P}|dk    rH| |         �@t          | |         t          j        ¦  «        r | |                              ‰d¬¦  «        | |<   ŒQ| S )Nr�   r   r:  )r×   rm   r	  Úrepeat_interleave)Údict_to_expandrì   rD  s     €rt   Ú_expand_dict_for_generationzRGenerationMixin._expand_inputs_for_generation.<locals>._expand_dict_for_generation¤  sq   ø€ Ø%ð dð d�àÐ+Ò+Ð+Ø& sÔ+Ð7Ý" >°#Ô#6½¼ÑEÔEð 8ð +9¸Ô*=×*OÒ*OÐP[ÐabÐ*OÑ*cÔ*c�N 3Ñ'øØ!Ð!rs   Nr   r:  r  zMIf `is_encoder_decoder` is True, make sure that `encoder_outputs` is defined.)rG  rÍ   rû   )rD  rÉ   r›   rñ   rI  s   `    rt   Ú_expand_inputs_for_generationz-GenerationMixin._expand_inputs_for_generation—  s¸   ø€ ð ˜!ÒÐØ˜lÐ*Ð*ð	"ð 	"ð 	"ð 	"ð 	"ð Ð Ø!×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Ð*Ñ+à˜,Ð&Ð&rs   ÚoutputsÚnum_new_tokensc                 óP  — t           D ]$}||v r|dv rd}n|}t          ||¦  «        ||<    nŒ%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	<   |                     d
d¦  «        r|d         dd …         |z   |d<   nw|                     d¦  «        }
t          j	        |
d         dz   |
d         |z   dz   |
j
        ¬¦  «                             |
j        ¦  «        }t          j        |
|f¦  «        |d<   |S )N)ra   r`   r]   r¾   rŸ   r:  r·   r   r"   r»   r$  Tr�   rÁ   )ÚALL_CACHE_NAMESrÚ   rm   rA  Ú	unsqueezeÚnew_onesr¡   rÍ   rÌ   ÚarangerÂ   Útor  )r”   rK  rñ   rÉ   rL  Úpossible_cache_nameÚ
cache_namer¾   r·   r»   Úpast_positionsÚnew_positionss               rt   Ú#_update_model_kwargs_for_generationz3GenerationMixin._update_model_kwargs_for_generationº  s2  € õ $3ð 	ð 	ÐØ" gÐ-Ð-à&Ð*IÐIÐIØ!2�J�Jà!4�JÝ+2°7Ð<OÑ+PÔ+P�˜ZÑ(Ø�ð .ð ˜|Ð+Ð+Ø)Ð*:Ô;ˆ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ð
 ×Ò˜K¨Ñ.Ô.ð 	XØ-9Ð:JÔ-KÈBÈCÈCÔ-PÐSaÑ-aˆLÐ)Ñ*Ð*à)×-Ò-Ð.>Ñ?Ô?ˆNÝ!œLØ˜rÔ" QÑ&¨°rÔ(:¸^Ñ(KÈaÑ(OÐWeÔWkðñ ô çŠb�Ô&Ñ'Ô'ð õ .3¬Y¸ÈÐ7VÑ-WÔ-WˆLÐ)Ñ*ØÐrs   Úassistant_modelrX   Úlogits_processorÚtarget_tokenizerrY   Úassistant_tokenizerc	                 ó^  — t          d„ |||fD ¦   «         ¦  «        }	|j        �t          || ||||¬¦  «        }
nó|j        �(t	          |j        |j        |j        |j        ¬¦  «        }
nÄ|	r­|j        du rZt          j
        ||| j                             ¦   «         j        |d¬¦  «        }d|j        _        t!          |||||||||¬¦	  «	        }
n_|j        du rt#          ||||||||¬	¦  «        }
n>t%          d
t'          |j        ¦  «        j        › �¦  «        ‚t+          ||||||¬¦  «        }
|
S )zU
        Returns the candidate generator to be used in `assisted_generation`
        c              3   ó   K  — | ]}|d uV — Œ	d S r­   rr   )rõ   r÷   s     rt   r*  z;GenerationMixin._get_candidate_generator.<locals>.<genexpr>ù  s&   è è € Ð"sÐ"s°Q 1¨D =Ð"sÐ"sÐ"sÐ"sÐ"sÐ"srs   N)r›   rX  r  rñ   r
  rY  )r  Únum_output_tokensÚmax_matching_ngram_sizeÚ
max_lengthT)rX  Úassistant_prune_lm_head)	r›   rX  r  rñ   r
  rY  rZ  r[  Úatm_translatorF)r›   rX  r  rñ   r
  rY  rZ  r[  z7Invalid value for `do_sample`: expected a boolean, got )r?  Úassistant_early_exitr,   Úprompt_lookup_num_tokensr-   r  r_  r`  Ú	do_sampler(   Úget_translatorrÃ   Úget_text_configÚ
vocab_sizer  Úrepetition_penaltyr.   r*   rû   Útyperi   r)   )r”   r  r›   r
  rX  rY  rZ  r[  rñ   Údifferent_tokenizersÚcandidate_generatorrb  s               rt   Ú_get_candidate_generatorz(GenerationMixin._get_candidate_generatorë  sÈ  € õ  #Ð"sÐ"s¸?ÐL\Ð^qÐ:rÐ"sÑ"sÔ"sÑsÔsÐàÔ1Ð=Ý"=Ø#Ø $Ø"3Ø)Ø+Ø!1ð#ñ #ô #ÐÐð Ô7ÐCÝ"@Ø.Ô@Ø"3Ô"LØ(9Ô(QØ,Ô7ð	#ñ #ô #ÐÐð "ð -	Ø Ô*¨dÐ2Ð2Ý!>Ô!MØ$Ø'Ø”K×/Ò/Ñ1Ô1Ô<Ø$3Ø,0ð"ñ "ô "�ð HL�Ô1ÔDÝ&KØ'Ø$3Ø&7Ø!-Ø"/Ø%5Ø%5Ø(;Ø#1ð
'ñ 
'ô 
'Ð#Ð#ð #Ô,°Ð5Ð5Ý&SØ'Ø$3Ø&7Ø!-Ø"/Ø%5Ø%5Ø(;ð	'ñ 	'ô 	'Ð#Ð#õ !ØzÍdÐSdÔSnÑNoÔNoÔNxÐzÐzñô ð õ #=Ø#Ø /Ø"3Ø)Ø+Ø!1ð#ñ #ô #Ðð #Ð"rs   Úinput_ids_seq_lengthÚencoder_input_idsÚprefix_allowed_tokens_fnÚnegative_prompt_idsÚnegative_prompt_attention_maskc
           	      ó*  — t          ¦   «         }
|€g }|j        �<|j        dk    r1|
                     t          |j        | ||	|j        ¬¦  «        ¦  «         |j        �(|
                     t          |j        ¬¦  «        ¦  «         |j        �?|j        dk    r4|
                     t          |j        |j	        |j
        ¬¦  «        ¦  «         |j        �g|j        dk    r\t          |j        ¦  «        dk    r*|
                     t          |j        |¬	¦  «        ¦  «         nt          j        d
t"          ¦  «         |j        �3|j        dk    r(|
                     t'          |j        ¬¦  «        ¦  «         |j        �2|j        dk    r'|
                     t+          |j        ¦  «        ¦  «         |j        �f|j        dk    r[t          |j        ¦  «        dk    r)|
                     t/          |j        |¦  «        ¦  «         nt          j        dt"          ¦  «         |j        �-|
                     t3          |j        |j        ¦  «        ¦  «         |j        �Kt9          |dd¦  «        �:|j        dk    r/|
                     t;          |j        |j        |¬¦  «        ¦  «         |j        �Lt9          |dd¦  «        �;|j        dk    r0|
                     t?          ||j        |j        |¬¦  «        ¦  «         |�0|
                     tA          ||j	        |j
        z  ¦  «        ¦  «         |j!        �'|
                     tE          |j!        ¦  «        ¦  «         |j#        �/|
                     tI          |j%        |j#        |¬¦  «        ¦  «         |j&        du r!|
                     tO          ¦   «         ¦  «         |j(        �.|
                     tS          |j(        |j        |¦  «        ¦  «         |j*        �)|
                     tW          |j*        |¬¦  «        ¦  «         |j,        �@|}|dk    s|j!        €|n|dz   }|
                     t[          |j,        ||¬¦  «        ¦  «         |  .                    |
|¦  «        }
|j/        �r|j	        dk    rjta          |j        tb          ¦  «        rt          |j        ¦  «        dz   }n:ta          |j        td          j3        ¦  «        r|j        j        d         dz   }nd}nd}|j4        �2|j4        dk    r'|
                     tk          |j4        ¦  «        ¦  «         |j6        �4|j6        dk    r)|
                     to          |j6        |¬¦  «        ¦  «         |j8        �4|j8        dk     r)|
                     ts          |j8        |¬¦  «        ¦  «         |j:        �)|
                     tw          |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@        ||¬¦  «        ¦  «         |jB        �J|
                     |jB         C                    | jD         E                    ¦   «         jF        |¦  «        ¦  «         |jG        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"   )Úunconditional_idsÚunconditional_attention_maskr$  ©Úsequence_biasç        )Údiversity_penaltyÚ	num_beamsÚnum_beam_groupsç      ð?r   )Úpenaltyro  zyPassing `encoder_repetition_penalty` requires some form of `input_ids` to be passed to `generate`, ignoring the argument.)r}  r   z{Passing `encoder_no_repeat_ngram_size` requires some form of `input_ids` to be passed to `generate`, ignoring the argument.r  ©r  T)Útop_kÚmin_tokens_to_keep)Útop_pr€  )Úmin_pr€  )Úmassr€  )Úepsilonr€  )r„  r€  r  )IrA   Úguidance_scaleÚappendrP   r$  rw  rI   ry  r>   rz  r{  Úencoder_repetition_penaltyrÊ   r¡   r8   ÚwarningsÚwarnÚUserWarningri  rH   Úno_repeat_ngram_sizerF   Úencoder_no_repeat_ngram_sizer7   Úbad_words_idsrE   r  Ú
min_lengthrÚ   rB   Úmin_new_tokensrC   rG   Úforced_bos_token_idr<   Úforced_eos_token_idr=   r`  Úremove_invalid_valuesr?   Ú exponential_decay_length_penaltyr;   Úsuppress_tokensrK   Úbegin_suppress_tokensrJ   Ú_merge_criteria_processor_listre  r×   Úlistrm   r	  ÚtemperaturerL   r  rM   r�  rN   r‚  rD   Ú	typical_prO   Úepsilon_cutoffr9   Ú
eta_cutoffr:   Úwatermarking_configÚconstruct_processorrÃ   rg  rh  Úrenormalize_logitsr@   )r”   r  rn  ro  rp  rY  r  rñ   rq  rr  Ú
processorsÚbegin_indexr€  s                rt   Ú_get_logits_processorz%GenerationMixin._get_logits_processor;  s…  € õ" )Ñ*Ô*ˆ
ØÐ#Ø!ÐàÔ+Ð7Ð<MÔ<\Ð`aÒ<aÐ<aØ×ÒÝ>Ø%Ô4ØØ&9Ø1OØ/Ô9ðñ ô ñô ð ð Ô*Ð6Ø×ÒÕ9ÐHYÔHgÐhÑhÔhÑiÔiÐiàÔ.Ð:Ð?PÔ?bÐehÒ?hÐ?hØ×ÒÝ/Ø&7Ô&IØ/Ô9Ø$5Ô$Eðñ ô ñô ð ð Ô8ÐDØ!Ô<ÀÒCÐCåÐ$Ô*Ñ+Ô+¨qÒ0Ð0Ø×!Ò!Ý;Ø 1Ô LØ*;ðñ ô ñô ð ð õ ”ð9åñô ð ð
 Ô/Ð;Ð@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åÐ$Ô*Ñ+Ô+¨qÒ0Ð0Ø×!Ò!Ý7Ø)ÔFØ)ñô ñô ð ð õ ”ð9åñô ð ð
 Ô*Ð6Ø×ÒÝ)Ø%Ô3Ø%Ô7ñô ñô ð ð Ô(Ð4ÝÐ)Ð+>ÀÑEÔEÐQØ!Ô,¨qÒ0Ð0à×ÒÝ(Ø%Ô0Ø%Ô7Ø!ðñ ô ñô ð ð Ô,Ð8ÝÐ)Ð+>ÀÑEÔEÐQØ!Ô0°1Ò4Ð4à×ÒÝ1Ø(Ø%Ô4Ø%Ô7Ø!ð	ñ ô ñô ð ð $Ð/Ø×ÒÝ0Ø,Ø%Ô/Ð3DÔ3TÑTñô ñô ð ð Ô0Ð<Ø×ÒÝ-Ø%Ô9ñô ñô ð ð
 Ô0Ð<Ø×ÒÝ-Ø%Ô0Ø%Ô9Ø!ðñ ô ñô ð ð Ô2°dÐ:Ð:Ø×ÒÕ9Ñ;Ô;Ñ<Ô<Ð<ØÔ=ÐIØ×ÒÝ-Ø%ÔFØ%Ô7Ø(ñô ñô ð ð Ô,Ð8Ø×ÒÝ-Ø%Ô5Ø!ðñ ô ñô ð ð Ô2Ð>Ø.ˆKð )¨1Ò,Ð,Ð0AÔ0UÐ0]ð �à  1‘_ð ð
 ×ÒÝ4Ø%Ô;ØØ!ðñ ô ñô ð ð ×8Ò8¸ÐEUÑVÔVˆ
ð Ô&ñ -	ð !Ô*¨QÒ.Ð.ÝÐ/ÔAÅ4ÑHÔHð +Ý),Ð->Ô-PÑ)QÔ)QÐTUÑ)UÐ&Ð&ÝÐ 1Ô CÅUÄ\ÑRÔRð +Ø):Ô)LÔ)RÐSTÔ)UÐXYÑ)YÐ&Ð&à)*Ð&Ð&à%&Ð"ð !Ô,Ð8Ð=NÔ=ZÐ^aÒ=aÐ=aØ×!Ò!Õ"9Ð:KÔ:WÑ"XÔ"XÑYÔYÐYØ Ô&Ð2Ð7HÔ7NÐRSÒ7SÐ7SØ×!Ò!Ý$Ð+<Ô+BÐWiÐjÑjÔjñô ð ð !Ô&Ð2Ð7HÔ7NÐQTÒ7TÐ7TØ×!Ò!Ý$Ð+<Ô+BÐWiÐjÑjÔjñô ð ð !Ô&Ð2à×!Ò!Ý$Ð+<Ô+BÐWiÐjÑjÔjñô ð ð !Ô*Ð6Ð;LÔ;VÐY\Ò;\Ð;\Ø×!Ò!Ý'Ð->Ô-HÐ]oÐpÑpÔpñô ð ð !Ô/Ð;ÀÐFWÔFfÐ@lÐ@lÒ@lÐ@lÐilÒ@lÐ@lÐ@lÐ@lÐ@lØ×!Ò!Ý'Ø 1Ô @ÐUgðñ ô ñô ð ð
 !Ô+Ð7¸CÐBSÔB^Ð<dÐ<dÒ<dÐ<dÐadÒ<dÐ<dÐ<dÐ<dÐ<dØ×!Ò!Ý#Ø 1Ô <ÐQcÐlrðñ ô ñô ð ð Ô0Ð<Ø×ÒØ!Ô5×IÒIØ”K×/Ò/Ñ1Ô1Ô<¸fñô ñô ð ð Ô/°4Ð7Ð7Ø×ÒÕ0Ñ2Ô2Ñ3Ô3Ð3ØÐrs   Ústopping_criteriaÚ	tokenizerc                 óš  — t          ¦   «         }|j        �?t          | j        dd ¦  «        }|                     t          |j        |¬¦  «        ¦  «         |j        �(|                     t          |j        ¬¦  «        ¦  «         |j        �:|€t          d¦  «        ‚|                     t          |j        |¬¦  «        ¦  «         |j        �(|                     t          |j        ¬¦  «        ¦  «         |j        r:|j        �3|j        dk    r(|                     t          |j        ¬¦  «        ¦  «         |                      ||¦  «        }|S )	NÚmax_position_embeddings)r`  r¥  )Úmax_timea  There are one or more stop strings, either in the arguments to `generate` or in the model's generation config, but we could not locate a tokenizer. When generating with stop strings, you must pass the model's tokenizer to the `tokenizer` argument of `generate`.)Ústop_stringsr£  )r  r   )Úassistant_confidence_threshold)rV   r`  rÚ   rÃ   r†  rS   r¦  rT   r§  rû   rW   r  rR   Úis_assistantr¨  rQ   r–  )r”   r  r¢  r£  r•   Úcriteriar¥  s          rt   Ú_get_stopping_criteriaz&GenerationMixin._get_stopping_criteria   sk  € õ (Ñ)Ô)ˆØÔ'Ð3Ý&-¨d¬kÐ;TÐVZÑ&[Ô&[Ð#Ø�OŠOÝ!Ø0Ô;Ø,Cðñ ô ñô ð ð Ô%Ð1Ø�OŠO�OÐ5FÔ5OÐPÑPÔPÑQÔQÐQØÔ)Ð5ØÐ Ý ðsñô ð ð
 �OŠOÕ.Ð<MÔ<ZÐfoÐpÑpÔpÑqÔqÐqØÔ.Ð:Ø�OŠOÕ,Ð:KÔ:]Ð^Ñ^Ô^Ñ_Ô_Ð_àÔ*ð	à!Ô@ÐLØ!Ô@À1ÒDÐDà�OŠOÝ"ÐBSÔBrÐsÑsÔsñô ð ð ×6Ò6°xÐARÑSÔSˆØˆrs   Údefault_listÚcustom_listc                 ó  — t          |¦  «        dk    r|S  t          |¦  «        ¦   «         }|D ]¾}d}|D ] }t          |¦  «        t          |¦  «        u r€t          |t          ¦  «        rdnd}t                               d|› dt          |¦  «        › dt          |¦  «        › dt          |¦  «        › d	�	¦  «         |                     |¦  «         d
} nŒ¡|s|                     |¦  «         Œ¿|D ]}||vr|                     |¦  «         Œ|S )a4  
        Merge user-defined processors/criteria with the ones instantiated inside `generate`. In case the same
        processor/criteria is present on both lists, use the user-defined one.

        (Note: up to v4.49.0, this function threw an exception is the same logit processor was found twice.)
        r   Fzstopping criteriazlogits processorz	A custom z	 of type zt has been passed to `.generate()`, but it was also created in `.generate()`, given its parameterization. The custom z5 will take precedence. Please check the docstring of z$ to see related `.generate()` flags.T)rÊ   rj  r×   rU   ÚloggerÚwarning_oncer†  )r”   r¬  r­  Ú
final_listÚdefaultÚusing_customÚcustomÚobject_types           rt   r–  z.GenerationMixin._merge_criteria_processor_listG  sk  € õ ˆ{ÑÔ˜qÒ Ð ØÐà'•T˜,Ñ'Ô'Ñ)Ô)ˆ
Ø#ð 	+ð 	+ˆGØ ˆLØ%ð ð �Ý˜‘<”<¥4¨¡=¤=Ð0Ð0Ý9CÀFÕL\Ñ9]Ô9]Ð"uÐ"5Ð"5Ðcu�KÝ×'Ò'ð/ Kð /ð /½$¸v¹,¼,ð /ð /ÝeiÐjpÑeqÔeqð/ð /åOSÐTZÉ|Ì|ð/ð /ð /ñô ð ð ×%Ò% fÑ-Ô-Ð-Ø#'�LØ�Eð 1ð  ð +Ø×!Ò! 'Ñ*Ô*Ð*øà!ð 	*ð 	*ˆFØ˜ZÐ'Ð'Ø×!Ò! &Ñ)Ô)Ð)øØÐrs   rd   re   r   Únormalize_logitsc                 ó6  — |€tt          j        |d         j        d         ¦  «                             dd¦  «                             |j        ¦  «        }|                     dt          |¦  «        ¦  «        }t          j        |¦  «         	                    t          |¦  «        d¦  «         
                    dd¦  «        }|r…| 	                    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 quickly 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 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*):
                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("openai-community/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 | log probability | 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 1: 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`.
        >>> # Tip 2: the output length does NOT include the input length
        >>> output_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:  )rm   rQ  r¡   r<  rR  r  ÚexpandrÊ   ÚstackÚreshapeÚ	transposerÃ   rg  rh  r   Ú
functionalÚlog_softmaxrÔ   ÚsumÚmaxr§   Úgather)r”   rd   re   r   r¶  Úbeam_indices_maskÚmax_beam_lengthÚbeam_sequence_indicesÚcut_idxÚindicesÚtransition_scoress              rt   Úcompute_transition_scoresz)GenerationMixin.compute_transition_scoresl  s
  € ðh ÐÝ œ<¨¨q¬	¬¸Ô(:Ñ;Ô;×@Ò@ÀÀQÑGÔG×JÒJÈ9ÔK[Ñ\Ô\ˆLØ'×.Ò.¨rµ3°v±;´;Ñ?Ô?ˆLõ ”˜VÑ$Ô$×,Ò,­S°©[¬[¸"Ñ=Ô=×GÒGÈÈ1ÑMÔMˆð ð 	:Ø—^’^ B¨¬×(CÒ(CÑ(EÔ(EÔ(PÐRXÔR^Ð_aÔRbÑcÔcˆ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¬{×/JÒ/JÑ/LÔ/LÔ/WÑ WÐð ”/ "Ô%¨Ñ7ˆØ˜A˜A˜A˜w˜x˜x˜KÔ(Ð+@Ñ@ˆð #ŸMšM¨!¨WÑ5Ô5Ðð 01ÐÐ+Ñ,à Ð rs   c                 óÂ  ‡ ‡‡— ‰€d S ‰ j         j        r]‰j         j        sQg d¢Šˆfd„t          ‰j         ¦  «        D ¦   «         Št          ˆˆ fd„‰D ¦   «         ¦  «        }|st	          d¦  «        ‚d}‰ j                              ¦   «         j        ‰j                              ¦   «         j        k    r|�t	          d|› d�¦  «        ‚d S |�|€t	          d|› d�¦  «        ‚d S )	N)Úencoder_attention_headsÚencoder_ffn_dimÚencoder_layersc                 ó   •— g | ]}|‰v ¯|‘Œ	S rr   rr   )rõ   ÚattrÚattributes_to_checks     €rt   ú
<listcomp>z7GenerationMixin._validate_assistant.<locals>.<listcomp>ì  s%   ø€ Ð"oÐ"oÐ"o¨DÐSWÐ[nÐSnÐSn 4ÐSnÐSnÐSnrs   c              3   óp   •K  — | ]0}t          ‰j        |¦  «        t          ‰j        |¦  «        k    V — Œ1d S r­   )rÚ   rÃ   )rõ   rÍ  rX  r”   s     €€rt   r*  z6GenerationMixin._validate_assistant.<locals>.<genexpr>í  sR   øè è € ð ð ØX\•˜œ TÑ*Ô*­g°oÔ6LÈdÑ.SÔ.SÒSðð ð ð ð ð rs   zÊThe main model and the assistant don't have compatible encoder-dependent input shapes. Ensure you load the assistant with the correct encoder-decoder class, e.g. `AutoModelForSpeechSeq2Seq` for Whisper.zc(see https://huggingface.co/docs/transformers/en/generation_strategies#universal-assisted-decoding)z•`assistant_tokenizer` is not required when the main and assistant models use the same tokenizer. Please omit `assistant_tokenizer` from `generate()` ú.z~The main and assistant models have different tokenizers. Please provide `tokenizer` and `assistant_tokenizer` to `generate()` )rÃ   rÉ   Údirr?  rû   rg  rh  )r”   rX  r£  r[  Ú	are_equalÚdoc_referencerÎ  s   ``    @rt   Ú_validate_assistantz#GenerationMixin._validate_assistantæ  sy  øøø€ ØÐ"ØˆFàŒ;Ô)ð 
	°/Ô2HÔ2[ð 
	Ø"bÐ"bÐ"bÐØ"oÐ"oÐ"oÐ"oµC¸Ô8NÑ4OÔ4OÐ"oÑ"oÔ"oÐÝð ð ð ð ð Ø`sðñ ô ñ ô ˆIð ð Ý ðJñô ð ð rð 	ð Œ;×&Ò&Ñ(Ô(Ô3°Ô7M×7]Ò7]Ñ7_Ô7_Ô7jÒjÐjØ"Ð.Ý ð }ð  mzð  }ð  }ð  }ñô ð ð /Ð.ð
 Ð Ð$7Ð$?Ý ð fð  Vcð  fð  fð  fñô ð ð %@Ð$?rs   c                 óf  — | 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|                     |¦  «         Œ!|rt          d|› d	�¦  «        ‚dS )
zXValidates model kwargs for generation. Generate argument typos will also be caught here.)r¹   Nr•   rñ   ró   rê   c                 ó   — h | ]}d |› �’ŒS )r"  rr   )rõ   Úxs     rt   ú	<setcomp>z9GenerationMixin._validate_model_kwargs.<locals>.<setcomp>)  s   € ÐJÐJÐJ°!˜~¨!˜~˜~ÐJÐJÐJrs   z8The 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Ú   rÛ   rß   r†  rû   )r”   rñ   rì   Úunused_model_argsÚ
model_argsré   ró   Úencoder_model_argsrê   Údecoder_model_argsrí   s              rt   Ú_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ð Œ;Ô)ð 	KÝ   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�
à&×,Ò,Ñ.Ô.ð 	.ð 	.‰JˆC�ØÐ  S°
Ð%:Ð%:Ø!×(Ò(¨Ñ-Ô-Ð-øàð 	ÝðFÐK\ð Fð Fð Fñô ð ð	ð 	rs   c           	      ó6  — |r5|j         €.|j        dk    r#t          j        d|j        › d�t          ¦  «         ||j        k    r.| j        j        rdnd}t          d|› d|› d	|j        › d
�¦  «        ‚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 z}. This can lead to unexpected behavior. You should consider increasing `max_length` or, better yet, setting `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_tokensr`  rˆ  r‰  rŠ  rÃ   rÉ   rû   rŽ  r�  )r”   r  Úinput_ids_lengthÚhas_default_max_lengthÚinput_ids_stringÚmin_length_error_suffixrŽ  s          rt   Ú_validate_generated_lengthz*GenerationMixin._validate_generated_length5  s  € ð "ð 	Ð&7Ô&FÐ&NÐSdÔSoÐsuÒSuÐSuåŒMðÐCTÔC_ð ð ð õ ñ	ô ð ð Ð0Ô;Ò;Ð;Ø6:´kÔ6TÐeÐ2Ð2ÐZeÐÝðUÐ#3ð Uð UÐ9Ið Uð UØ%Ô0ðUð Uð Uñô ð ð+ð 	 ð "ð 	Ø#Ø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Ð8rs   c                 óö  — |j         �D|s2|j        �+t                               d|j         › d|j        › d�¦  «         |j         |z   |_        nž|dk    r9||j        d         k    r(| j        j        s|xj        |j        d         z  c_        n_|r]|j        t          ¦   «         j        k    rA|j        |z   |_        t          | j        dd¦  «        }|�t          |j        |¦  «        |_        |j
        �=|s+t                               d|j
        › d	|j        › d
�¦  «         |j
        |z   |_        nK|dk    rE||j        d         k    r4| j        j        s(t          |j        |j        d         z
  d¦  «        |_        |S )z]Prepared max and min length in generation configs to avoid clashes between similar attributesNz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)rœ   r"   r¥  zBoth `min_new_tokens` (=z) and `min_length`(=zÇ) seem to have been set. `min_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)r   )rá  r`  r¯  Úwarningr¡   rÃ   rÉ   r4   rÚ   Úminr�  rŽ  r¿  )r”   r  rã  Úhas_default_min_lengthrå   râ  r
  r¥  s           rt   Ú_prepare_generated_lengthz)GenerationMixin._prepare_generated_lengtha  sû  € ð Ô+Ð7Ø)ð Ð.?Ô.JÐ.VÝ—’ðfÐ/@Ô/Oð fð fØ(Ô3ðfð fð fñô ð ð ,=Ô+KÐN^Ñ+^ÐÔ(Ð(ð
  Ò/Ð/Ø  MÔ$7¸Ô$:Ò:Ð:Ø”KÔ2ð ;ð Ð(Ô(¨MÔ,?ÀÔ,BÑBÐ(Ô(Ð(Ø#ð 	nØ Ô+Õ/?Ñ/AÔ/AÔ/LÒLÐLØ/@Ô/KÐN^Ñ/^Ð!Ô,Ý*1°$´+Ð?XÐZ^Ñ*_Ô*_Ð'Ø*Ð6Ý36Ð7HÔ7SÐUlÑ3mÔ3mÐ%Ô0ð Ô+Ð7Ø)ð Ý—’ðfÐ/@Ô/Oð fð fØ(Ô3ðfð fð fñô ð ð ,=Ô+KÐN^Ñ+^ÐÔ(Ð(ð  Ò/Ð/Ø  MÔ$7¸Ô$:Ò:Ð:Ø”KÔ2ð ;õ ,/Ð/@Ô/KÈmÔNaÐbcÔNdÑ/dÐfgÑ+hÔ+hÐÔ(à Ð rs   Úuse_model_defaultsr•   c                 ó  — d}|€¸| j         j        r‘| j         j        t          | j         ¦  «        k    rot	          | j                             ¦   «         ¦  «        dk    rEt          j        | j        ¦  «        }|| j         k    r!t          j
        dt          ¦  «         || _         | j         }d}|j        dk    rd|_        t          j        |¦  «        }|�s¢t          j        t          j        | j         j        ¦  «        j        ¦  «        }|du s|�€|t          j        d¦  «        k    rîi }t          ¦   «         }| j         }	|	j                             ¦   «         D ]w\  }
}|
                     d¦  «        s|
d	k    rŒ!|
d
k    r|	j        dk    rŒ3t-          ||
d¦  «        }t-          ||
d¦  «        }||k    r||k    r|||
<   t/          ||
|¦  «         Œx|j        dk    rd|_        |€1t	          |¦  «        dk    rt4                               d|› d�¦  «         n`|j        €| j         j        |_        |j        €| j         j        |_        |j        €| j         j        |_        |j        €| j         j        |_         |j         di |¤Ž}||fS )zË
        Prepares the base generation config, then applies any generation configuration options from kwargs. This
        function handles retrocompatibility with respect to configuration files.
        FNr   a?  You have modified the pretrained model configuration to control generation. This is a deprecated strategy to control generation and will be removed in v5. Please use and modify the model generation configuration (see https://huggingface.co/docs/transformers/generation_strategies#default-text-generation-configuration )TÚhybridz4.50.0rè   Útransformers_versionÚcache_implementationrx  zX`generation_config` default values have been modified to match model-specific defaults: z=. If this is not desired, please set these values explicitly.rr   )!r  Ú_from_model_configÚ_original_object_hashÚhashrÊ   rÃ   Ú&_get_non_default_generation_parametersr4   Úfrom_model_configrˆ  r‰  rŠ  rð  ÚcopyÚdeepcopyr
   Úparserï  Úbase_versionÚ__dict__rß   r'  rÚ   Úsetattrr˜  re  r¯  r°  rð   r  r  r6  Úupdate)r”   r  rì  r•   Úusing_model_generation_configÚnew_generation_configÚmodel_base_versionÚmodified_valuesÚ global_default_generation_configÚmodel_generation_configrì   Úmodel_gen_config_valueÚglobal_default_valueÚcustom_gen_config_valuerñ   s                  rt   Ú_prepare_generation_configz*GenerationMixin._prepare_generation_config™  s  € ð ).Ð%ØÐ$ð Ô&Ô9ðCàÔ*Ô@ÅDÈÔI_ÑD`ÔD`Ò`Ð`Ý˜œ×JÒJÑLÔLÑMÔMÐPQÒQÐQå(8Ô(JÈ4Ì;Ñ(WÔ(WÐ%Ø(¨DÔ,BÒBÐBÝ”MðBõ $ñô ð ð .C�DÔ*à $Ô 6ÐØ,0Ð)ð !Ô5¸ÒAÐAØ9=Ð!Ô6õ !œMÐ*;Ñ<Ô<Ðà,ñ +	mõ ")¤­w¬}¸TÔ=SÔ=hÑ/iÔ/iÔ/vÑ!wÔ!wÐØ! TÐ)Ð)Ø"Ñ*Ð/AÅWÄ]ÐS[ÑE\ÔE\Ò/\Ð/\à"$�Ý3CÑ3EÔ3EÐ0Ø*.Ô*@Ð'à3JÔ3S×3YÒ3YÑ3[Ô3[ð Pð PÑ/�CÐ/Ø—~’~ cÑ*Ô*ð !¨cÐ5KÒ.KÐ.KØ àÐ4Ò4Ð4Ð9PÔ9eÐiqÒ9qÐ9qØ Ý+2Ð3SÐUXÐZ^Ñ+_Ô+_Ð(Ý.5Ð6GÈÈdÑ.SÔ.SÐ+à/Ð3GÒGÐGØ2Ð6JÒJÐJà/E˜¨Ñ,ÝÐ 1°3Ð8NÑOÔOÐOøð %Ô0°CÒ7Ð7Ø27Ð%Ô/Ø%Ð-µ#°oÑ2FÔ2FÈÒ2JÐ2JÝ×'Ò'ðjØ*ðjð jð jñô ð øð
 %Ô1Ð9Ø59Ô5KÔ5XÐ%Ô2Ø$Ô1Ð9Ø59Ô5KÔ5XÐ%Ô2Ø$Ô1Ð9Ø59Ô5KÔ5XÐ%Ô2Ø$Ô;ÐCØ?CÔ?UÔ?lÐ%Ô<ð 0Ð(Ô/Ð9Ð9°&Ð9Ð9ˆà  ,Ð.Ð.rs   c                 óö  — d|v r
|d         �|S d|v rT| j         j        sHt          j        |d         ddd…df         t          j        ¬¦  «                             d¦  «        dz
  }n�d|v rT| j         j        rHt          j        |d         ddd…df         t          j        ¬¦  «                             d¦  «        dz
  }n7t          j        |t          j        |¬¦  «                             d¦  «        dz
  }d}|                     d	¦  «        �g|d	         }d}t          |t          ¦  «        r|d         d         j
        d
         }n$t          |d¦  «        r|                     ¦   «         }||d…         }||d<   |S )zbCalculates `cache_position` for the pre-fill stage based on `input_ids` and optionally past lengthr�   Nrœ   r   rÁ   r"   Údecoder_inputs_embedsr  r]   r   Úget_seq_length)rÃ   rÉ   rm   rB  Úint64rÕ   r  rÍ   r×   rp   r¡   rÜ   r	  )r”   Ú
seq_lengthr  rñ   r�   Úpast_lengthÚcaches          rt   Ú_get_initial_cache_positionz+GenerationMixin._get_initial_cache_positionü  sš  € ð ˜|Ð+Ð+°Ð=MÔ0NÐ0ZØÐØ˜lÐ*Ð*°4´;Ô3QÐ*Ý"œ_¨\¸/Ô-JÈ1ÈaÈaÈaÐQRÈ7Ô-SÕ[`Ô[fÐgÑgÔg×nÒnÐopÑqÔqÐtuÑuˆNˆNØ$¨Ð4Ð4¸¼Ô9WÐ4å” Ð-DÔ EÀaÈÈÈÈAÀgÔ NÕV[ÔVaÐbÑbÔb×iÒiÐjkÑlÔlÐopÑpð ˆNõ #œZ¨
½%¼+ÈfÐUÑUÔU×\Ò\Ð]^Ñ_Ô_ÐbcÑcˆNàˆØ×ÒÐ-Ñ.Ô.Ð:Ø Ð!2Ô3ˆEØˆKå˜%¥Ñ'Ô'ð 5Ø# Aœh qœkÔ/°Ô2��Ý˜Ð 0Ñ1Ô1ð 5Ø#×2Ò2Ñ4Ô4�à+¨K¨L¨LÔ9ˆNà)7ˆÐ%Ñ&ØÐrs   rð  Úmax_cache_lenc                 óÜ  — | j         j        p|                     d¦  «        du}d|v }t          | d¦  «        r|r| j        j        n| j        }t          | d¦  «         p |j        |k    p|j        |k    p
|j        |k     }|r>t          | d¦  «        r.|p+| j        j	        j        |d         d         j
        d         k    }|r�| j                              d¬¦  «        ||d	œ}	t          di |	¤Ž| _        |rZ| j                              d¬
¦  «        |d         d         j
        d         |d	œ}
t          | j        t          di |
¤Ž¦  «        | _        n| j                             ¦   «          | j        S )zö
        Sets a cache for `generate`, that will persist across calls. A new cache will only be initialized a
        new `generate` call requires a larger cache or uses a different batch size.

        Returns the resulting cache object.
        r  NÚ	offloadedÚ_cacher   r"   T)rê   )rÃ   r  Ú
offloading)ró   rr   )rÃ   rÉ   rÍ   rÜ   r  Úself_attention_cacher  Úmax_batch_sizer  Úcross_attention_cacher¡   rg  r   r   Úreset)r”   rð  rÇ   r  rñ   Úrequires_cross_attention_cacheÚoffload_cacheÚcache_to_checkÚneed_new_cacheÚself_attention_cache_kwargsÚcross_attention_cache_kwargss              rt   Ú
_get_cachezGenerationMixin._get_cache  sË  € ð ŒKÔ*Ð]¨l×.>Ò.>Ð?PÑ.QÔ.QÐY]Ð.]ð 	'ð $Ð';Ð;ˆå�4˜Ñ"Ô"ð 	qØA_Ðp˜Tœ[Ô=Ð=ÐeiÔepˆNõ ˜˜hÑ'Ô'Ð'ð <ØÔ(¨MÒ9ð<àÔ,°
Ò:ð<ð Ô+¨mÒ;ð	 	ð *ð 	­g°d¸HÑ.EÔ.Eð 	àð rØ”;Ô4ÔBÀlÐSdÔFeÐfgÔFhÔFnÐopÔFqÒqð ð
 ð 	 àœ+×5Ò5¸dÐ5ÑCÔCØ!.Ø+ð+ð +Ð'õ
 &ÐDÐDÐ(CÐDÐDˆDŒKØ-ð là"œk×9Ò9À$Ð9ÑGÔGØ%1Ð2CÔ%DÀQÔ%GÔ%MÈaÔ%PØ"/ð0ð 0Ð,õ
 2°$´+½{Ð?jÐ?jÐMiÐ?jÐ?jÑkÔk�”øàŒK×ÒÑÔÐØŒ{Ðrs   c                 óJ   ‡ — ‰ j          ot          ˆ fd„dD ¦   «         ¦  «        S )a¡  
        Return `True` if current model can use a `DynamicCache` instance when initializing the `past_key_values`.
        This adds exception for some models like `Mamba` models which use their own caches
        and do not need to initialize the Cache in advance in order to save memory (because no back and forth
        `to_legacy_cache` and `from_legacy_cache` will be performed for mamba-based models).
        c              3   óN   •K  — | ]}|‰j                              ¦   «         vV — Œ d S r­   )ri   r=  )rõ   Úspecial_model_nameÚclss     €rt   r*  zBGenerationMixin._supports_default_dynamic_cache.<locals>.<genexpr>P  sJ   øè è € ð ,
ð ,
à"ð  c¤l×&8Ò&8Ñ&:Ô&:Ð:ð,
ð ,
ð ,
ð ,
ð ,
ð ,
rs   )ÚreformerÚminimaxÚxlnetÚlfm2)Ú_is_statefulr?  )r"  s   `rt   Ú_supports_default_dynamic_cachez/GenerationMixin._supports_default_dynamic_cacheG  sL   ø€ ð Ô#Ð#ð 
­ð ,
ð ,
ð ,
ð ,
ð'ð,
ñ ,
ô ,
ñ )
ô )
ð 	
rs   Úmax_cache_lengthc                 óØ  ‡ — t          ˆ fd„dD ¦   «         ¦  «        }|sdnd}‰ j        j        p|                     d¦  «        du}|                     |¦  «        }	|	�r|j        �t          d|› d�¦  «        ‚t          |	t          ¦  «        rA‰                      ¦   «         r-|st          j
        |	¦  «        nt          j
        |	¦  «        ||<   dS |j        d	u rdS ‰                      ¦   «         s,|j        �#t          j        d
|j        › d�t          ¦  «         dS |�1|j        �*t                                d|j        › d�¦  «         d|_        |                     |¦  «        }
|
t&          j        t&          j        fv s|j        dk    ri }n	d‰ j        i}|j        ��š|j        t,          v rw|j        t.          v r+t                                d|j        › dt0          › d�¦  «         ‰                      |j        t5          |j        |j        ¦  «        |z  ||¬¦  «        ||<   dS |j        dk    rÎ‰ j        j        s‰                      ¦   «         st          d¦  «        ‚|j        �|j        ni }d|vr‰ j                             ¦   «         |d<   |                     dd¦  «        }|dk    rtA          ¦   «         stC          d¦  «        ‚|dk    rtE          ¦   «         stC          d¦  «        ‚tG          dd|i|¤Ž||<   dS |j        dk    rt          di |¤ddi¤Ž||<   dS d|j        v rt          di |¤Ž||<   dS dS |st          di |¤Žn#t          t          di |¤Žt          di |¤Ž¦  «        ||<   dS ) zÐ
        Prepares the cache for generation (if applicable), given `generate`'s parameterization. If a cache is
        instantiated, writes it to `model_kwargs`, under the name expected by the model.
        c              3   óX   •K  — | ]$}|‰j         j                             ¦   «         v V — Œ%d S r­   )rü   ri   r=  )rõ   Ú
class_namer”   s     €rt   r*  z@GenerationMixin._prepare_cache_for_generation.<locals>.<genexpr>g  s:   øè è € ÐtÐtÐPZ˜j¨D¬NÔ,C×,IÒ,IÑ,KÔ,KÐKÐtÐtÐtÐtÐtÐtrs   )ÚmambaÚfalconh1r]   r^   r  NzMPassing both `cache_implementation` (used to initialize certain caches) and `zB` (a Cache object) is unsupported. Please use only one of the two.FzŠThis model does not support `Cache` instances, it only supports the legacy cache format (tuple of tuples). `cache_implementation` (set to z) will be ignored.zRAn assistant model is provided, using a dynamic cache instead of a cache of type='z'.Údynamic_fullrÃ   zUsing `cache_implementation='z(' is deprecated. Please only use one of z9, and the layer structure will be inferred automatically.)rð  rÇ   r  rñ   Ú	quantizedz�This model does not support the quantized cache. If you want your model to support quantized cache, please open an issue and tag @zucchini-nlp.ÚbackendÚquantozžYou need to install optimum-quanto in order to use KV cache quantization with optimum-quanto backend. Please install it via  with `pip install optimum-quanto`ÚHQQzYou need to install `HQQ` in order to use KV cache quantization with HQQ backend. Please install it via  with `pip install hqq`r  r  TÚdynamicrr   )$r  rÃ   rÉ   rÍ   rð  rû   r×   rp   r(  r   Úfrom_legacy_cacher   r$  rˆ  r‰  rŠ  r¯  r°  Úget_generation_moder5   ÚASSISTED_GENERATIONÚCONTRASTIVE_SEARCHr1   r2   r3   r  r¿  rz  Únum_return_sequencesÚcache_configrg  rÌ   r   ÚImportErrorr   r   )r”   r  rñ   rX  rÇ   r)  Úis_hybrid_cacherT  r  Úuser_defined_cacheÚgeneration_modeÚdynamic_cache_kwargsr:  r1  s   `             rt   Ú_prepare_cache_for_generationz-GenerationMixin._prepare_cache_for_generationZ  sÄ  ø€ õ ÐtÐtÐtÐtÐ^sÐtÑtÔtÑtÔtˆØ.=ÐQÐ&Ð&À>ˆ
ð ŒKÔ*Ð]¨l×.>Ò.>Ð?PÑ.QÔ.QÐY]Ð.]ð 	'ð *×-Ò-¨jÑ9Ô9ÐØÐ)Ø Ô5ÐAÝ ðTÐdnð Tð Tð Tñô ð õ Ð,­eÑ4Ô4ð ¸×9]Ò9]Ñ9_Ô9_ð ð :ðS•LÔ2Ð3EÑFÔFÐFå,Ô>Ð?QÑRÔRð ˜ZÑ(ð
 ˆFð Ô&¨%Ð/Ð/ØˆFð ×3Ò3Ñ5Ô5ð 	Ø Ô5ÐAÝ”ðØBSÔBhðð ð õ  ñ	ô ð ð ˆFð Ð&Ð+<Ô+QÐ+]Ý×Òð?Ø%Ô:ð?ð ?ð ?ñô ð ð 6:ÐÔ2ð
 ,×?Ò?ÀÑPÔPˆà¥Ô BÅNÔDeÐfÐfÐfØ Ô5¸ÒGÐGà#%Ð Ð à$,¨d¬kÐ#:Ð ØÔ1Ñ=Ø Ô5Õ9YÐYÐYØ$Ô9Õ=dÐdÐdÝ×'Ò'ð~Ð8IÔ8^ð ~ð ~Ý&Bð~ð ~ð ~ñô ð ð ,0¯?ª?Ø):Ô)OÝ"Ð#4Ô#>Ð@QÔ@fÑgÔgÐjtÑtØ"2Ø!-ð	 ,;ñ ,ô ,�˜ZÑ(Ð(Ð(ð #Ô7¸;ÒFÐFØ”;Ô1ð ¸×9]Ò9]Ñ9_Ô9_ð Ý$ðMñô ð ð
 BSÔA_ÐAkÐ0Ô=Ð=Ðqs�à <Ð/Ð/Ø-1¬[×-HÒ-HÑ-JÔ-J�L Ñ*à&×*Ò*¨9°hÑ?Ô?�à˜hÒ&Ð&Õ/JÑ/LÔ/LÐ&Ý%ðSñô ð ð  Ò%Ð%Õ.>Ñ.@Ô.@Ð%Ý%ðHñô ð õ ,:Ð+ZÐ+ZÀ'Ð+ZÈ\Ð+ZÐ+Z�˜ZÑ(Ð(Ð(Ø"Ô7¸;ÒFÐFÝ+7Ð+`Ð+`Ð:NÐ+`Ð+`Ð[_Ð+`Ð+`Ð+`�˜ZÑ(Ð(Ð(ØÐ/ÔDÐDÐDÝ+7Ð+OÐ+OÐ:NÐ+OÐ+O�˜ZÑ(Ð(Ð(ð EÐDð 6ðu•Ð4Ð4Ð3Ð4Ð4Ð4å(­Ð)MÐ)MÐ8LÐ)MÐ)MÍ|ÐOsÐOsÐ^rÐOsÐOsÑtÔtð ˜Ñ$Ð$Ð$rs   c                 ó€   — dt          t          j        | j        ¦  «        j                             ¦   «         ¦  «        v S )zË
        Return True if the current model supports the keyword argument `logits_to_keep` in forward()
        to save memory. Checking it in this way allows to avoid using a new model attribute.
        Úlogits_to_keep)rÎ   rÏ   rÐ   rÑ   rÒ   rÓ   )r”   s    rt   Ú_supports_logits_to_keepz(GenerationMixin._supports_logits_to_keepÚ  s3   € ð
  ¥3¥wÔ'8¸¼Ñ'FÔ'FÔ'Q×'VÒ'VÑ'XÔ'XÑ#YÔ#YÐYÐYrs   Úkwargs_has_attention_maskc                 ó,  ‡ — dˆ fd„	} ||j         |¬¦  «        } ||j        |¬¦  «        } ||j        |¬¦  «        } ||j        |¬¦  «        }‰ j        j        r|�|n|}|� |j        dk    r|                     d¦  «        }|€F|�D|�|st           	                    d¦  «         |d         }t           	                    d|› d�¦  «         ‰ j        j        r|€t          d¦  «        ‚|�At          ||¬	¦  «                             ¦   «         r|�|st                               d
¦  «         |�Jt          j        |¦  «        s|dk                          ¦   «         rt           	                    d|› d�¦  «         ||_        ||_        ||_        ||_        dS )aó  
        Prepares the special tokens for generation, overwriting the generation config with their processed versions
        converted to tensor.

        Note that `generation_config` is changed in place and stops being serializable after this method is called.
        That is no problem if called within `generate` (`generation_config` is a local copy that doesn't leave the
        function). However, if called outside `generate`, consider creating a copy of `generation_config` first.
        Nc                 óÂ   •— | €| S |�|n‰j         }t          | t          j        ¦  «        r|                      |¦  «        S t          j        | |t          j        ¬¦  «        S )N©r  rÂ   )r  r×   rm   r	  rR  ÚtensorrÔ   )Útokenr  r”   s     €rt   Ú_tensor_or_nonez@GenerationMixin._prepare_special_tokens.<locals>._tensor_or_noneñ  s\   ø€ Øˆ}Ø�à%Ð1�V�V°t´{ˆFÝ˜%¥¤Ñ.Ô.ð (Ø—x’x Ñ'Ô'Ð'Ý”< ¨f½E¼JÐGÑGÔGÐGrs   r~  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.z)Setting `pad_token_id` to `eos_token_id`:z for open-end generation.z\`decoder_start_token_id` or `bos_token_id` has to be defined for encoder-decoder generation.r  zäThe attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.z;`eos_token_id` should consist of positive integers, but is zq. Your generation will not stop until the maximum length is reached. Depending on other flags, it may even crash.r­   )rð   r  r  r6  rÃ   rÉ   rÙ   rO  r¯  rè  rû   r   r  r°  rm   Úis_floating_pointÚ_bos_token_tensorr  r  Ú_decoder_start_token_tensor)	r”   r  rD  r  rJ  Úbos_token_tensorÚeos_token_tensorÚpad_token_tensorÚdecoder_start_token_tensors	   `        rt   Ú_prepare_special_tokensz'GenerationMixin._prepare_special_tokensá  sU  ø€ ð 	Hð 	Hð 	Hð 	Hð 	Hð 	Hð +˜?Ð+<Ô+IÐRXÐYÑYÔYÐØ*˜?Ð+<Ô+IÐRXÐYÑYÔYÐØ*˜?Ð+<Ô+IÐRXÐYÑYÔYÐØ%4 _Ð5FÔ5]ÐflÐ%mÑ%mÔ%mÐ"ð Œ;Ô)ð 	à.HÐ.TÐ*Ð*ÐZjð 'ð
 Ð'Ð,<Ô,AÀQÒ,FÐ,FØ/×9Ò9¸!Ñ<Ô<Ðð Ð#Ð(8Ð(DØ(Ð4Ð=VÐ4Ý—’ðqñô ð ð  0°Ô2ÐÝ�NŠNÐrÐGWÐrÐrÐrÑsÔsÐsð Œ;Ô)ð 	Ð.HÐ.PÝØnñô ð ð Ð(Ý!Ð+;ÐK[Ð\Ñ\Ô\×`Ò`ÑbÔbð )ð )Ð4Ð=VÐ4Ý×#Ò#ðCñô ð ð
 Ð'ÝÔ#Ð$4Ñ5Ô5ð (Ø:JÈQÒ:N×9SÒ9SÑ9UÔ9Uð (õ �NŠNðrÐN^ð rð rð rñô ð ð /?ÐÔ+Ø.>ÐÔ+Ø.>ÐÔ+Ø8RÐÔ5Ð5Ð5rs   c                 ó.  — |j         rdS | j        j        dk    p!t          |j        duo|j        j        ¦  «        }t          |                     d¦  «        t          ¦  «        o|d         j	        }|o|}t          | dd¦  «        �|| j        j	        z  }t          | d¦  «        rMt          | j                             ¦   «         ¦  «        }d|v ot!          |¦  «        dk    }|| z  }d	|v }|| z  }|j        �|st"                               d
¦  «         |S )zp
        Determines whether to trigger auto-compilation of the model's forward pass at generation time.
        FÚcudaNr]   Úhf_quantizerr  Úcpur"   ÚdiskzsYou have set `compile_config`, but we are unable to meet the criteria for compilation. Compilation will be skipped.)Údisable_compiler  rj  ÚboolÚcompile_configÚ_compile_all_devicesr×   rÍ   r   rØ   rÚ   rU  rÜ   rÎ   r  r  rÊ   r¯  r°  )	r”   rñ   r  Úvalid_hardwareÚusing_compilable_cacheÚcan_compileÚall_model_devicesÚhas_cpu_offloadÚhas_disk_offloads	            rt   Ú_valid_auto_compile_criteriaz,GenerationMixin._valid_auto_compile_criteria3  s[  € ð
 Ô,ð 	Ø�5ð œÔ)¨VÒ3ð 
µtØÔ,°DÐ8ÐrÐ=NÔ=]Ô=rñ8
ô 8
ˆõ �|×'Ò'Ð(9Ñ:Ô:½EÑBÔBÐuÀ|ÐTeÔGfÔGuð 	ð %Ð?Ð)?ˆõ �4˜¨Ñ.Ô.Ð:Ø˜4Ô,Ô;Ñ;ˆKå�4˜Ñ)Ô)ð 	0Ý # DÔ$6×$=Ò$=Ñ$?Ô$?Ñ @Ô @Ðà#Ð'8Ð8ÐW½SÐARÑ=SÔ=SÐVWÒ=WˆOØ˜Ð.Ñ.ˆKð  &Ð):Ð:ÐØÐ/Ð/Ñ/ˆKð Ô+Ð7ÀÐ7Ý×Òð#ñô ð ð
 Ðrs   Úsynced_gpusÚstreamerrZ   Úcustom_generatec                 óÆ  ‡‡+— |                      dd¦  «        }|�tt          |t          ¦  «        r_h d£Š+ˆ+fd„t          ¦   «                              ¦   «         D ¦   «         }|                     |¦  «          | j        |fd|i|¤Ž} |d?d| i|¤ŽS |                      dd¦  «        }|                      dd¦  «        } | j        ‰|fi |¤Ž\  Š}|                      | 	                    ¦   «         ¦  «         |  
                    |||¦  «         |€4t          ¦   «         st          | ¦  «        ot          j        ¦   «         dk    }|�|nt          ¦   «         }|�|nt!          ¦   «         }d	t#          t%          j        | j        ¦  «        j                             ¦   «         ¦  «        v }d
|v}|                     d	d¦  «        du}|                      |‰j        |¦  «        \  }}}|j        d         }|j        }|                      ‰||¬¦  «         | j        j        sj‰j        �c|dk    r]tA          |j        ¦  «        dk    rEtC          j"        |dd…df         ‰j        k    ¦  «        dk    rtF           $                    d¦  «         | j        j        s|dk    rd‰_%        |s|r|r|  &                    |‰|¦  «        |d	<   n5|r3|dk    r-tA          |d	         j        ¦  «        dk    rtO          d¦  «        ‚| j        j        rd
|vr|  (                    |||‰¦  «        }| j        j        r(|  )                    |||‰j*        |j        ¬¦  «        \  }}n|dk    r|n|                      d¦  «        } | j+        d?|tY          ‰j-        ‰j.        ¦  «        | j        j        dœ|¤Ž\  }}‰j/        r|  0                    ||¦  «        }|�'| 1                    | 2                    ¦   «         ¦  «         |j        d         }|                     d¦  «        du o‰j3        du}|                     d¦  «        du o‰j4        du}|  5                    ‰|||||¬¦  «        Š|  6                    ¦   «         r	d|vrd|d<   |  7                    ‰||¦  «         ‰j3        dz
  }|j        d         |k    r"|dk    r| j        j        s||j        d         z  }|  8                    ‰||||¦  «         ‰ 9                    |¦  «        } |�‰j-        dk    rtO          d¦  «        ‚| j        j:        |j        j:        k    rBtw          j<        d|j        j:        › d| j        j:        › d| j        j:        › d�tz          ¦  «         |  >                    ‰|||||j        ||	|
¬¦	  «	        }! | j?        d?‰||d œ|¤Ž}"‰j%        |d!<   t          |t€          ¦  «        r || |f|!|"‰||d"œ|¤Ž}#�nK| t‚          jB        k    r¾‰j.        dk    rtO          d#‰j.        › d$�¦  «        ‚|dk    rtO          d%¦  «        ‚|d!         stO          d&¦  «        ‚‰jC        d'v rtO          d(¦  «        ‚| jD        rtO          d)| jE        jF        › �¦  «        ‚|  G                    ‰|||||||¬*¦  «        }$ | jH        |f|$|!|"‰||d+œ|¤Ž}#�n}| t‚          jI        k    rBtF           J                    d,¦  «         |stO          d-¦  «        ‚t—          jL        | |fd.‰|d/œ|¤ŽS | t‚          jM        k    rMtF           J                    d0¦  «         |stF           J                    d1¦  «         t—          jL        | |fd2‰|d/œ|¤ŽS | t‚          jN        t‚          jO        fv r | jP        |f|!|"‰||d"œ|¤Ž}#�nž| t‚          jQ        t‚          jR        fv r | jS        |f|!|"‰|d3œ|¤Ž}#�no| t‚          jT        k    rjtF           J                    d4¦  «         t«          |‰j-        |j        ‰jV        ‰jW        ‰j.        ‰jX        ‰j3        ¬5¦  «        }% | jY        ||%f|!|"‰|d3œ|¤Ž}#�nõ| t‚          jZ        k    �rätF           J                    d6¦  «         g }&‰j[        �‰j[        }&‰j\        ��iˆfd7„}'t          ‰j\        tº          ¦  «        rtA          ‰j\        ¦  «        dk    r
 |'¦   «          ‰j\        D �]}(t          |(d         tº          ¦  «        rˆt          |(tº          ¦  «        rtA          |(¦  «        dk    r
 |'¦   «          t½          d8„ |(D ¦   «         ¦  «        r
 |'¦   «          t½          d9„ |(D ¦   «         ¦  «        r
 |'¦   «          t¿          |(¦  «        })ndt          |(tº          ¦  «        rtA          |(¦  «        dk    r
 |'¦   «          t½          d:„ |(D ¦   «         ¦  «        r
 |'¦   «          tÁ          |(¦  «        })|& a                    |)¦  «         �Œ!tÅ          |&|‰j-        |j        ‰jV        ‰jW        ‰j.        ‰j3        ¬;¦  «        }* | jc        |f|*|!|"‰|d<œ|¤Ž}#‰jd        du rCtË          |#d=¦  «        r3tÍ          |#jg        d>¦  «        �|#jg         h                    ¦   «         |#_g        |#S )@aó  

        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 be 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 has the following loading
                priority: 1) from the `generation_config.json` model file, if it exists; 2) from the model
                configuration. Please note that unspecified parameters will inherit [`~generation.GenerationConfig`]'s
                default values, whose documentation should be checked to parameterize generation.
            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 complements 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://huggingface.co/papers/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` if using `FullyShardedDataParallel` or DeepSpeed ZeRO Stage 3 with multiple GPUs to avoid
                deadlocking if one GPU finishes generating before other GPUs. Otherwise, defaults 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 assistant 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`.
            use_model_defaults (`bool`, *optional*):
                When it is `True`, unset parameters in `generation_config` will be set to the model-specific default
                generation configuration (`model.generation_config`), as opposed to the global defaults
                (`GenerationConfig()`). If unset, models saved starting from `v4.50` will consider this flag to be
                `True`.
            custom_generate (`str` or `Callable`, *optional*):
                One of the following:
                - `str` (Hugging Face Hub repository name): runs the custom `generate` function defined at
                  `custom_generate/generate.py` in that repository instead of the standard `generate` method. The
                  repository fully replaces the generation logic, and the return type may differ.
                - `str` (local repository path): same as above but from a local path, `trust_remote_code` not required.
                - `Callable`: `generate` will perform the usual input preparation steps, then call the provided callable to
                  run the decoding loop.
                For more information, see [the docs](../../generation_strategies#custom-generation-methods).
            kwargs (`dict[str, Any]`, *optional*):
                Ad hoc parametrization of `generation_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.LongTensor`.

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

                    - [`~generation.GenerateDecoderOnlyOutput`],
                    - [`~generation.GenerateBeamDecoderOnlyOutput`]

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

                    - [`~generation.GenerateEncoderDecoderOutput`],
                    - [`~generation.GenerateBeamEncoderDecoderOutput`]
        r…   N>   r”   r•   re  r…   Úglobal_keys_to_excludec                 ó$   •— i | ]\  }}|‰v¯	||“ŒS rr   rr   )rõ   rì   rí   rg  s      €rt   rù   z,GenerationMixin.generate.<locals>.<dictcomp>Û  s+   ø€ Ð!uÐ!uÐ!u±°°eÐSVÐ^tÐStÐSt # uÐStÐStÐStrs   Úmodelr£  r[  r"   r·   r  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œ   Tr›   z1`attention_mask` passed to `generate` must be 2D.)rÇ   rå   rñ   r6  r  )r›   rD  rÉ   r`  rŽ  )r  rã  rê  rå   r
  râ  rB  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  rn  ro  rp  rY  r  rñ   rq  rr  )r  r¢  r£  r$  )rY  r¢  r  rc  rd  zFnum_return_sequences has to be 1 when doing assisted generate, but is rÑ  z6assisted generate is only supported for batch_size = 1z+assisted generate requires `use_cache=True`)Ústaticrî  Úsliding_windowz=assisted generate is not supported with Static cache classes`zCassisted generation is not supported with stateful models, such as )r  r›   r
  rX  rY  rZ  r[  rñ   )rl  rY  r¢  r  rc  rd  zèDoLa generation was moved to a `custom_generate` repo: https://hf.co/transformers-community/dola. To prevent loss of backward compatibility, add `custom_generate='transformers-community/dola'` to your `generate` call before v4.62.0.z„DoLa generation requires `trust_remote_code=True` in your `generate` call, since it loads https://hf.co/transformers-community/dola.ztransformers-community/dola)re  r  r…   a  Contrastive search was moved to a `custom_generate` repo: https://hf.co/transformers-community/contrastive-search. To prevent loss of backward compatibility, add `custom_generate='transformers-community/contrastive-search'` to your `generate` call before v4.62.0.z•Contrastive search requires `trust_remote_code=True` in your `generate` call, since it loads https://hf.co/transformers-community/contrastive-search.z)transformers-community/contrastive-search)rY  r¢  r  rc  z¹Group Beam Search is scheduled to be moved to a `custom_generate` repository in v4.55.0. To prevent loss of backward compatibility, add `trust_remote_code=True` to your `generate` call.)rÇ   rz  r  Úlength_penaltyÚdo_early_stoppingÚnum_beam_hyps_to_keepr{  r`  z¿Constrained Beam Search is scheduled to be moved to a `custom_generate` repository in v4.55.0. To prevent loss of backward compatibility, add `trust_remote_code=True` to your `generate` call.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 rÑ  )rû   Úforce_words_ids©r  s   €rt   Ú	typeerrorz+GenerationMixin.generate.<locals>.typeerror%
  s3   ø€ Ý$ð]Ø8IÔ8Yð]ð ]ð ]ñô ð rs   c              3   óB   K  — | ]}t          |t          ¦  «         V — Œd S r­   )r×   r—  ©rõ   Ú	token_idss     rt   r*  z+GenerationMixin.generate.<locals>.<genexpr>5
  s/   è è € ÐYÐYÀ9¥:¨i½Ñ#>Ô#>Ð>ÐYÐYÐYÐYÐYÐYrs   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     rt   r*  z5GenerationMixin.generate.<locals>.<genexpr>.<genexpr>8
  s9   è è € ÐjÐjÐT\¥Z°½#Ñ%>Ô%>Ð!>Ð!NÀ(ÈQÂ,ÐjÐjÐjÐjÐjÐjrs   Nr+  rt  s     rt   r*  z+GenerationMixin.generate.<locals>.<genexpr>7
  sN   è è € ð ð à )õ  ÐjÐjÐ`iÐjÑjÔjÑjÔjðð ð ð ð ð rs   c              3   óN   K  — | ] }t          |t          ¦  «         p|d k     V — Œ!dS rx  ry  rz  s     rt   r*  z+GenerationMixin.generate.<locals>.<genexpr>A
  s9   è è € ÐhÐhÐS[¥J¨x½Ñ$=Ô$=Ð =Ð MÀÈAÂÐhÐhÐhÐhÐhÐhrs   )ÚconstraintsrÇ   rz  r  rl  rm  rn  r`  )Úconstrained_beam_scorerrY  r¢  r  rc  r]   Úto_legacy_cacherr   )irÌ   r×   ÚstrÚlocalsrß   rü  rš   r  rÞ  rö  rÕ  r   r   ÚdistÚget_world_sizerA   rV   rÎ   rÏ   rÐ   rÑ   rÒ   rÓ   rÍ   r   rð   r¡   r  rR  rÃ   rÉ   r  rÊ   rm   r¾  r¯  rè  r$  r  rû   r5  rC  rM  rJ  r¿  rz  r9  Útoken_healingÚheal_tokensÚputrV  r`  rŽ  rë  rC  ræ  r@  r6  rj  rˆ  r‰  rŠ  r¡  r«  r   r5   r7  rð  r'  rü   ri   rm  Ú_assisted_decodingÚDOLA_GENERATIONr°  rƒ   rŽ   r8  ÚSAMPLEÚGREEDY_SEARCHÚ_sampleÚBEAM_SAMPLEÚBEAM_SEARCHÚ_beam_searchÚGROUP_BEAM_SEARCHr&   rl  Úearly_stoppingr{  Ú_group_beam_searchÚCONSTRAINED_BEAM_SEARCHr}  rp  r—  r  r#   r$   r†  r'   Ú_constrained_beam_searchÚreturn_legacy_cacherÜ   rÚ   r]   r  ),r”   rï   r  rY  r¢  rp  rc  rX  rd  rq  rr  rì  re  r•   r…   Úgenerate_argumentsr™   r£  r[  rñ   Úaccepts_attention_maskÚrequires_attention_maskrD  r
  rå   rÇ   r  r›   râ  rã  rê  r)  r>  Úprepared_logits_processorÚprepared_stopping_criteriaÚresultrl  Úbeam_scorerÚfinal_constraintsrr  Úword_idsÚ
constraintr~  rg  s,     `                                        @rt   rŽ   zGenerationMixin.generate\  s  øø€ ðf #ŸJšJÐ':¸DÑAÔAÐØÐ&­:°oÅsÑ+KÔ+KÐ&ð&ð &ð &Ð"ð "vÐ!uÐ!uÐ!u½v¹x¼x¿~º~Ñ?OÔ?OÐ!uÑ!uÔ!uÐØ×%Ò% fÑ-Ô-Ð-à'@ tÔ'@Øð(ð (Ø3Dð(ØHNð(ð (Ð$ð ,Ð+ÐMÐM°$ÐMÐ:LÐMÐMÐMð —J’J˜{¨DÑ1Ô1ˆ	Ø$ŸjšjÐ)>ÀÑEÔEÐà*I¨$Ô*IØÐ1ð+
ð +
Ø5;ð+
ð +
Ñ'Ð˜<ð 	×#Ò# L×$5Ò$5Ñ$7Ô$7Ñ8Ô8Ð8Ø× Ò  °)Ð=PÑQÔQÐQð ÐÝ5Ñ7Ô7ÐWÕ;QÐRVÑ;WÔ;WÐvÕ]aÔ]pÑ]rÔ]rÐuvÒ]vˆKà/?Ð/KÐ+Ð+ÕQdÑQfÔQfÐØ1BÐ1NÐ-Ð-ÕThÑTjÔTjÐà!1µS½Ô9JÈ4Ì<Ñ9XÔ9XÔ9c×9hÒ9hÑ9jÔ9jÑ5kÔ5kÐ!kÐØ"3¸<Ð"GÐØ$0×$4Ò$4Ð5EÀtÑ$LÔ$LÐTXÐ$XÐ!ð 9=×8RÒ8RØÐ%Ô2°Lñ9
ô 9
Ñ5ˆÐ'¨ð #Ô(¨Ô+ˆ
àÔ%ˆØ×$Ò$Ð%6Ð8QÐZ`Ð$ÑaÔaÐað Œ{Ô-ð 	ð "Ô3Ð?Ø ’N�NÝ˜Ô+Ñ,Ô,°Ò1Ð1Ý”I˜m¨A¨A¨A¨r¨EÔ2Ð6GÔ6YÒYÑZÔZÐ]^Ò^Ð^å—’ðlñô ð ð Œ{Ô-ð 	/Ð2BÀoÒ2UÐ2UØ*.ÐÔ'à(ð 	VÐ-Dð 	VÐI_ð 	VØ-1×-XÒ-XØÐ0°,ñ.ô .ˆLÐ)Ñ*Ð*ð 'ð 	Và ;Ò.Ð.µ3°|ÐDTÔ7UÔ7[Ñ3\Ô3\Ð_`Ò3`Ð3`Ý Ð!TÑUÔUÐUàŒ;Ô)ð 	Ð.?À|Ð.SÐ.Sà×NÒNØ˜|Ð-=Ð?Pñô ˆLð
 Œ;Ô)ð 		lØ&*×&TÒ&TØ%Ø!1Ø)Ø'8Ô'TØ$Ô+ð 'Uñ 'ô 'Ñ#ˆI�|�|ð *:¸[Ò)HÐ)H˜˜Èl×N^ÒN^Ð_jÑNkÔNkˆIð #E $Ô"Dð #
ØÝÐ-Ô7Ð9JÔ9_Ñ`Ô`Ø#œ{Ô=ð#
ð #
ð ð	#
ð #
Ñˆ	�<ð Ô*ð 	?Ø×(Ò(¨°IÑ>Ô>ˆIàÐØ�LŠL˜Ÿš™œÑ)Ô)Ð)ð %œ?¨1Ô-ÐØ!'§¢¨LÑ!9Ô!9¸TÐ!AÐ!nÐFWÔFbÐjnÐFnÐØ!'§¢¨LÑ!9Ô!9¸TÐ!AÐ!nÐFWÔFbÐjnÐFnÐØ ×:Ò:Ø/Ø#9Ø#9Ø-Ø'Ø-ð ;ñ 
ô 
Ðð ×(Ò(Ñ*Ô*ð 	/Ð/?À|Ð/SÐ/SØ-.ˆLÐ)Ñ*à×'Ò'Ð(9Ð;KÐMcÑdÔdÐdð -Ô7¸!Ñ;ÐàÔ Ô"Ð&6Ò6Ð6Ø  OÒ3Ð3Ø”KÔ2ð 4ð  Ô 3°AÔ 6Ñ6ÐØ×*Ò*Ø˜|¨_¸jÐJZñ	
ô 	
ð 	
ð
 ,×?Ò?ÀÑPÔPˆàÐÐ%6Ô%@À1Ò%DÐ%DÝØlñô ð ð Œ;Ô˜yÔ/Ô4Ò4Ð4ÝŒMð*Ø@IÔ@PÔ@Uð*ð *àœ+Ô*ð*ð *ð UYÔT_ÔTdð	*ð *ð *õ ñô ð ð %)×$>Ò$>Ø/Ø!1Ø+Ø%=Ø-Ø Ô'Ø%Ø 3Ø+Ið %?ñ 
%
ô 
%
Ð!ð &A TÔ%@ð &
Ø/ÐCTÐ`ið&
ð &
Ømsð&
ð &
Ð"ð
 %6Ô$?ˆ�[Ñ!õ �o¥xÑ0Ô0ð Q	Ø$�_ØØð	ð ";Ø"<Ø"3Ø'Ø!ð	ð 	ð ð	ð 	ˆF‰Fð ¥Ô BÒBÐBØ Ô5¸Ò9Ð9Ý ðHØ/ÔDðHð Hð Hñô ð ð ˜AŠ~ˆ~Ý Ð!YÑZÔZÐZØ Ô,ð PÝ Ð!NÑOÔOÐOØ Ô5Ð9_Ð_Ð_Ý Ð!`ÑaÔaÐaØÔ ð õ !ØsÐZ^ÔZhÔZqÐsÐsñô ð ð
 #'×"?Ò"?Ø"3Ø#Ø+Ø /Ø!1Ø!*Ø$7Ø)ð #@ñ 	#ô 	#Ðð -�TÔ,Øð	à$7Ø!:Ø"<Ø"3Ø'Ø!ð	ð 	ð ð	ð 	ˆF‰Fð ¥Ô >Ò>Ð>Ý×Òð:ñô ð ð
 %ð Ý ðJñô ð õ #Ô+ØØðð !>Ø"3Ø"3ðð ð ðð ð ð ¥Ô AÒAÐAÝ×Òð:ñô ð ð
 %ð Ý×#Ò#ðXñô ð õ
 #Ô+ØØðð !LØ"3Ø"3ðð ð ðð ð ð ¥Ô!6½Ô8TÐ UÐUÐUà!�T”\Øðà!:Ø"<Ø"3Ø'Ø!ðð ð ðð ˆF‰Fð ¥Ô!;½^Ô=WÐ XÐXÐXà&�TÔ&Øðà!:Ø"<Ø"3Ø'ðð ð ðð ˆF‰Fð ¥Ô @Ò@Ð@Ý×Òðsñô ð õ
 +Ø%Ø+Ô5Ø$Ô+Ø0Ô?Ø"3Ô"BØ&7Ô&LØ 1Ô AØ,Ô7ð	ñ 	ô 	ˆKð -�TÔ,ØØðð ";Ø"<Ø"3Ø'ðð ð ðð ˆF‰Fð ¥Ô FÒFÑFÝ×Òðsñô ð ð !#ÐØ Ô,Ð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ð	'ñ 	'ô 	'Ð#ð 3�TÔ2Øðà(?Ø!:Ø"<Ø"3Ø'ðð ð ðð ˆFð Ô1°TÐ9Ð9Ý˜Ð 1Ñ2Ô2ð :å˜Ô.Ð0AÑBÔBÐNà%+Ô%;×%KÒ%KÑ%MÔ%MˆFÔ"Øˆrs   Úthis_peer_finishedc                 óÆ   — |rZt          j        |rdnd|¬¦  «        }t          j        |t          j        j        ¬¦  «         |                     ¦   «         dk    rdS n|rdS dS )z¿
        Returns whether there are still unfinished sequences in the device. The existence of unfinished sequences is
        fed through `this_peer_finished`. ZeRO stage 3-friendly.
        rx  r|  r~  )ÚopFT)rm   rH  r‚  Ú
all_reduceÚReduceOpÚSUMr@  )r”   rŸ  rc  r  Úthis_peer_finished_flags        rt   Ú_has_unfinished_sequencesz)GenerationMixin._has_unfinished_sequencesf
  s}   € ð
 ð 
	õ ',¤lÐ:LÐ3U°3°3ÐRUÐ^dÐ&eÑ&eÔ&eÐ#åŒOÐ3½¼Ô8IÐJÑJÔJÐJà&×+Ò+Ñ-Ô-°Ò4Ð4Ø�uð 5àð 	Ø�5Øˆtrs   c                 ó¼  ‡‡— ‰€t          d¦  «        ‚‰j        ‰j        }}t          ‰                     ¦   «         ¦  «        }t          d|¬¦  «        }d„ ‰                     |d¬¦  «        D ¦   «         } ‰|dd¬	¦  «        j                             |j	        ¦  «        }t          j        ||k    ||¦  «        }	 |                     ¦   «         d
k    r|S |dd…df                              ¦   «         }‰                     ‰                     d¦  «        ¦  «        d
         Šˆˆfd„|D ¦   «         }	t!          t#          ||	¦  «        ¦  «        D �]\  }
\  }}||
         }t          j        ||k    ¦  «                             ¦   «         rŒ<	 ˆfd„|                     |¬¦  «        D ¦   «         }t+          |¦  «        dk    rŒs||fxx         dz  cc<   |                     |¬¦  «         |dd…         }	 |                     ¦   «         d
k    rŒ¾t+          |||k             ¦  «        dk    r||d<   |                      |                     d
¦  «        |¬¦  «        ||
<   �Œ|S )a¸  
        Generates sequences of token ids for models with a language modeling head.
        Parameters:
            input_ids (`torch.LongTensor`): The sequence used as a prompt for the generation.
            tokenizer (`PreTrainedTokenizerBase`, *optional*): The tokenizer used to decode the input ids.
        Return:
            `torch.LongTensor` where each sequence has its tail token replaced with its appropriate extension.
        Nzs When generating with token healing, you must pass the model's tokenizer to the `tokenizer` argument of `generate`.r"   )rá  r  c                 ó6   — g | ]}|                      ¦   «         ‘ŒS rr   )Ústrip)rõ   r(  s     rt   rÏ  z/GenerationMixin.heal_tokens.<locals>.<listcomp>�
  s    € ÐbÐbÐb �1—7’7‘9”9ÐbÐbÐbrs   T)Úskip_special_tokensÚpt)Úreturn_tensorsÚpaddingr   rŸ   ú c              3   ój   •K  — | ]-}‰                      |¦  «                             d ‰¦  «        V — Œ.dS )r®  N)ÚdecodeÚreplace)rõ   ÚtÚ	space_tokr£  s     €€rt   r*  z.GenerationMixin.heal_tokens.<locals>.<genexpr>¥
  sA   øè è € ÐSÐSÀQ�Y×%Ò% aÑ(Ô(×0Ò0°°iÑ@Ô@ÐSÐSÐSÐSÐSÐSrs   c                 ó>   •— i | ]}‰                      |¦  «        fd “ŒS )g      $@)Úconvert_tokens_to_ids)rõ   Úalt_tokr£  s     €rt   rù   z/GenerationMixin.heal_tokens.<locals>.<dictcomp>±
  s9   ø€ ð ð ð ØFM�×0Ò0°Ñ9Ô9Ð;¸Tðð ð rs   )Úprefixr|  rv  rq  )rû   rð   r  r   Ú	get_vocabr4   Úbatch_decoder›   rR  r  rm   ÚwhereÚnumelÚtolistÚconvert_ids_to_tokensrµ  Ú	enumerateÚzipr?  r@  Ú
extensionsrÊ   rü  rŽ   rO  )r”   r›   r£  rð   r  Ú
vocab_trier  ÚpromptsÚtail_idsÚ	tail_toksÚ	batch_idxÚtail_idÚtail_tokÚ	batch_idsÚseq_biasÚtrimmed_idsr³  s     `             @rt   r…  zGenerationMixin.heal_tokensx
  sÒ  øø€ ð ÐÝð*ñô ð ð
 &/Ô%;¸YÔ=S�lˆÝ# I×$7Ò$7Ñ$9Ô$9Ñ:Ô:ˆ
Ý,¸AÈLÐYÑYÔYÐð cÐb i×&<Ò&<¸YÐ\`Ð&<Ñ&aÔ&aÐbÑbÔbˆØ�IØØØð
ñ 
ô 
ô —B’B�yÔ'Ñ(Ô(ð	 	õ ”K 	¨\Ò 9¸<ÈÑSÔSˆ	ð	ð �?Š?ÑÔ Ò!Ð!ØÐà˜Q˜Q˜Q ˜UÔ#×*Ò*Ñ,Ô,ˆà×3Ò3°I×4SÒ4SÐTWÑ4XÔ4XÑYÔYÐZ[Ô\ˆ	ð TÐSÐSÐSÐSÈ(ÐSÑSÔSˆ	å.7½¸HÀiÑ8PÔ8PÑ.QÔ.Qð "	pñ "	pÑ*ˆIÑ*˜ Ø! )Ô,ˆIÝŒy˜ lÒ2Ñ3Ô3×8Ò8Ñ:Ô:ð Øððð ð ð ØQ[×QfÒQfÐnvÐQfÑQwÔQwðñ ô ˆHõ �8‰}Œ} Ò!Ð!Øð �g�ZÐ Ð Ô  CÑ'Ð Ð Ñ Ø×$Ò$°8Ð$Ñ<Ô<Ð<à# C R Cœ.ˆKðð × Ò Ñ"Ô" aÒ'Ð'Øõ �9˜Y¨,Ò6Ô7Ñ8Ô8¸AÒ=Ð=Ø".�˜B‘à#'§=¢=°×1FÒ1FÀqÑ1IÔ1IÐ]n =Ñ#oÔ#oˆI�iÑ Ñ àÐrs   c                 ó4	  — |j         }|j        }	|j        }
|j        }|j        }|j        }t          d„ |D ¦   «         ¦  «        }|j        }|r|rdn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}|j        dd…         \  }}d}t          j        |t          j        |j        ¬	¦  «        }|                      ||j        |¦  «        }| j        }|                      ||¦  «        }|rrd
t&          j        d<   | j        j        dk    r9|j        �2|j        j        r&t0                               d¦  «         d|j        _        |                      |j        ¦  «        }|j        � | j        ||fi |¤Ž}d}nd}|                      |||j        ¬¦  «        �rB | j        |fi |¤Ž}|                     |	rd|	ini ¦  «         |                     |
rd|
ini ¦  «         |r | di |¤ddi¤Ž}d}n |di |¤ddi¤Ž}|                       ||| j        j	        ¬¦  «        }|r|rŒ¦|j!        dd…ddd…f          "                    dt          j#        |j        ¬¦  «        }  ||| ¦  «        }!|ri|r||!fz  }|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  }|rKtR          j*         +                    |!d¬¦  «        }"t          j,        |"d¬¦  «         -                    d¦  «        }#nt          j.        |!d¬¦  «        }#|r|#|z  |d|z
  z  z   }#t          j/        ||#dd…df         gd¬¦  «        }|�'| 0                    |# 1                    ¦   «         ¦  «         | |||¦  «         z  }| 2                    ¦   «         dk    }|dz  }~|                      |||j        ¬¦  «        �°B|�| 3                    ¦   «          |r_| j        j	        r+ti          ||||||||| 
                    d¦  «        ¬¦	  «	        S tk          |||||| 
                    d¦  «        ¬¦  «        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.

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            logits_processor (`LogitsProcessorList`):
                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`):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            generation_config ([`~generation.GenerationConfig`]):
                The generation configuration to be used as parametrization of the decoding method.
            synced_gpus (`bool`):
                Whether to continue running the while loop until max_length (needed to avoid deadlocking with
                `FullyShardedDataParallel` and DeepSpeed 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.GenerateDecoderOnlyOutput`], [`~generation.GenerateEncoderDecoderOutput`] or `torch.LongTensor`:
            A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.GenerateDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.GenerateEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.
        c              3   ó6   K  — | ]}t          |d ¦  «        V — ŒdS )r  N)rÜ   )rõ   rª  s     rt   r*  z*GenerationMixin._sample.<locals>.<genexpr>þ
  s,   è è € Ð'lÐ'lÈh­°¸.Ñ(IÔ(IÐ'lÐ'lÐ'lÐ'lÐ'lÐ'lrs   rr   Nr  rg   rh   r   Fr  Ú0ÚTOKENIZERS_PARALLELISMÚflash_attention_2z¹When using Flash Attention 2 and a static cache, you cannot use the option `CompileConfig(fullgraph=True)` as FA2 introduces graph breaks. We overrode the option with `fullgraph=False`.Tr~  r/  r0  r1  ©rÉ   rŸ   ©rö  rÂ   r  r:  r"   ©Únum_samplesr   r]   ©	rd   re   rf   rw   rx   ry   rz   r{   r]   ©rd   re   rf   rg   rh   r]   )6r  r/  r0  Úoutput_scoresÚoutput_logitsÚreturn_dict_in_generater  re  rÃ   rÉ   rÍ   r¡   rm   r  rÔ   r  r  Ú__call__rb  r�   ÚenvironÚ_attn_implementationrZ  Ú	fullgraphr¯  r°  Úget_compiled_callÚprefill_chunk_sizeÚ_prefill_chunkingr¦  rî   rü  rW  rf   rR  Úfloat32ry   rg   rz   r{   rh   r   r¼  ÚsoftmaxÚmultinomialÚsqueezeÚargmaxrA  r†  rV  r¿  Úendrv   rc   )$r”   r›   rY  r¢  r  rc  rd  rñ   r  r/  r0  rÖ  r×  rØ  Úhas_eos_stopping_criteriare  re   Ú
raw_logitsry   rz   r{   rw   rx   rÇ   Úcur_lenrŸ  Úunfinished_sequencesÚmodel_forwardÚcompile_forwardÚ
is_prefillrà   rK  Únext_token_logitsÚnext_token_scoresÚprobsÚnext_tokenss$                                       rt   r‹  zGenerationMixin._sampleÍ
  s_  € ðV )Ô:ˆØ-Ô?ÐØ0ÔEÐØ)Ô7ˆØ)Ô7ˆØ"3Ô"KÐÝ$'Ð'lÐ'lÐZkÐ'lÑ'lÔ'lÑ$lÔ$lÐ!Ø%Ô/ˆ	ð 0ÐL°MÐL��ÈˆØ3ÐP¸ÐP�R�RÈDˆ
Ø$;Ð\Ð@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ð "ð
 (œo¨b¨q¨bÔ1Ñˆ
�GØ"ÐÝ$œz¨*½E¼JÈyÔO_Ð`Ñ`Ô`ÐØ×7Ò7¸ÀÔAQÐS_Ñ`Ô`ˆàœˆØ×;Ò;¸LÐJ[Ñ\Ô\ˆØð 	UØ36�BŒJÐ/Ñ0àŒ{Ô/Ð3FÒFÐFà$Ô3Ð?ÐDUÔDdÔDnÐ?Ý×'Ò'ðfñô ð ð BGÐ%Ô4Ô>Ø ×2Ò2Ð3DÔ3SÑTÔTˆMàÔ/Ð;Ø1˜4Ô1°)Ð=NÐ_Ð_ÐR^Ð_Ð_ˆLØˆJˆJàˆJà×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ I	à=˜4Ô=¸iÐXÐXÈ<ÐXÐXˆLð ×ÒÐL]Ð eÐ!4Ð6GÐ HÐ HÐceÑfÔfÐfØ×ÒÐRfÐ nÐ!7Ð9MÐ NÐ NÐlnÑoÔoÐoàð JØ˜$Ð@Ð@ Ð@Ð@¸4Ð@Ð@Ð@�Ø"�
�
à'˜-ÐIÐI¨,ÐIÐIÀDÐIÐIÐI�ð  ×CÒCØØØ#'¤;Ô#Að Dñ ô ˆLð
 ð Ð1ð Øð !(¤¨q¨q¨q°"°a°a°a¨xÔ 8× ;Ò ;ÀÍUÌ]ÐclÔcsÐ ;Ñ tÔ tÐð !1Ð 0°Ð<MÑ NÔ NÐð 'ð Ø ð 3ØÐ0Ð2Ñ2�FØ ð 7ØÐ#4Ð"6Ñ6�JØ$ð HØ&Ø9=¼Ô9WÐr˜Ô3Ð5Ð5Ð^eÔ^pÐ]rñÐ&ð ”{Ô5ð HØ(¨WÔ-EÐ,GÑGÐ(à'ð Ø)àœ;Ô9ð6˜Ô6Ð8Ð8à%Ô3Ð5ñÐ)ð ð FÝœ×-Ò-Ð.?ÀRÐ-ÑHÔH�å#Ô/°À1ÐEÑEÔE×MÒMÈaÑPÔP��å#œlÐ+<À"ÐEÑEÔE�ð )ð mØ)Ð,@Ñ@À<ÐSTÐWkÑSkÑClÑl�õ œ	 9¨k¸!¸!¸!¸T¸'Ô.BÐ"CÈÐLÑLÔLˆIØÐ#Ø—’˜[Ÿ_š_Ñ.Ô.Ñ/Ô/Ð/à#7Ð;LÐ;LÈYÐX^Ñ;_Ô;_Ð:_Ñ#_Ð Ø!5×!9Ò!9Ñ!;Ô!;¸qÒ!@ÐØ�q‰LˆGð ðS ×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ I	ðV ÐØ�LŠL‰NŒNˆNà"ð 	ØŒ{Ô-ð Ý3Ø'Ø!Ø%Ø'9Ø*?Ø'9Ø%5Ø*?Ø$0×$4Ò$4Ð5FÑ$GÔ$Gð
ñ 
ô 
ð 
õ 1Ø'Ø!Ø%Ø1Ø"7Ø$0×$4Ò$4Ð5FÑ$GÔ$Gðñ ô ð ð Ðrs   rH  c                 óŠ   — t          | j        ¦  «        }t          j        | |d         |d         z  g|dd…         z   ¦  «        S )z=[batch_size, num_beams, ...] -> [batch_size * num_beams, ...]r   r"   r   N©r—  r¡   rm   rº  )rH  r¡   s     rt   Ú_flatten_beam_dimz!GenerationMixin._flatten_beam_dim‘  sB   € õ �V”\Ñ"Ô"ˆÝŒ}˜V e¨A¤h°°q´Ñ&9Ð%:¸UÀ1À2À2¼YÑ%FÑGÔGÐGrs   rz  c                 ón   — t          | j        ¦  «        }t          j        | ||g|dd…         z   ¦  «        S )z=[batch_size * num_beams, ...] -> [batch_size, num_beams, ...]r"   Nrò  )rH  rÇ   rz  r¡   s       rt   Ú_unflatten_beam_dimz#GenerationMixin._unflatten_beam_dim—  s7   € õ �V”\Ñ"Ô"ˆÝŒ}˜V j°)Ð%<¸uÀQÀRÀR¼yÑ%HÑIÔIÐIrs   c                 ó  — t          |j        ¦  «        t          | j        ¦  «        k     r?|                     d¦  «        }t          |j        ¦  «        t          | j        ¦  «        k     °?t          j        | |d¬¦  «        }|S )aü  
        Gathers the beam slices indexed by beam_indices into new beam array.

        Args:
            tensor (`torch.Tensor`): A tensor containing data to be gathered. The tensor is a 2D or a 3D tensor
                with the two first dimensions depicting the batch and the beam dimensions.
            beam_indices (`torch.Tensor` of shape `(batch_size, num_beams_to_select)`): The indices of the beams to
                select .

        Returns:
            A tensor with the selected beams
        rŸ   r"   )ÚinputrÅ  r;  )rÊ   r¡   rO  rm   Útake_along_dim)rH  r   Úgathered_tensors      rt   Ú_gather_beamszGenerationMixin._gather_beams�  sw   € õ �,Ô$Ñ%Ô%­¨F¬LÑ(9Ô(9Ò9Ð9Ø'×1Ò1°"Ñ5Ô5ˆLõ �,Ô$Ñ%Ô%­¨F¬LÑ(9Ô(9Ò9Ð9åÔ.°VÀ\ÐWXÐYÑYÔYˆØÐrs   Ú#is_early_stop_heuristic_unsatisfiedÚrunning_beam_scoresÚbeam_scoresÚis_sent_finishedrè  r`  Údecoder_prompt_lenr�  rl  c	                 óö   — |dk    r|dk    r||z
  }	n||z
  }	|dd…dd…f         |	|z  z  }
t          j        |t          j        |dd¬¦  «        d         d¦  «        }| t          j        |
|k    d	d¬¦  «        z  S )
uH  
        Determine whether early stopping is possible by checking if the best possible score of running beams
        could still improve upon the finished ones.

        Mechanism:
        - Without a length penalty, beam scores typically decrease as more tokens are generated.
        So, if the *best possible* score from any running beam is already worse than the *worst* finished beam,
        we can safely stop early.
        - With a length penalty, scores may increase with longer sequences. In this case, we use heuristics
        to estimate the best possible score â€” though this estimate may not always be correct â€” and stop
        if no further improvement seems likely.

        We apply different heuristics depending on the value of `early_stopping`:
        1. `early_stopping == False`:
        -> Use a heuristic that assumes the best score comes from the current length minus the decoder prompt length.
        -> See detailed discussion: https://github.com/huggingface/transformers/pull/20901#issuecomment-1369845565

        2. `early_stopping == "never"`:
        -> Estimate the best score using either `max_length` or `cur_len`, depending on the sign of `length_penalty`.
        -> A positive length penalty favors longer sequences, so we use `max_length` in that case.

        NOTE: the canonical beam search implementation can be replicated with `early_stopping="never"` and
        `length_penalty=0.0`, which are NOT the default flags. The default behavior was empirically found to produce
        better sequences (prior to 2022), and changing it is BC breaking.
        Úneverrx  Nr"   T)r;  Úkeepdimr   ç    eÍÍÁrŸ   )rm   rº  ré  r  )rû  rü  rý  rþ  rè  r`  rÿ  r�  rl  Úbest_hypothetical_lengthÚbest_possible_running_scoreÚworst_finished_scores               rt   Ú_check_early_stop_heuristicz+GenerationMixin._check_early_stop_heuristic±  sµ   € ðJ ˜WÒ$Ð$¨¸#Ò)=Ð)=Ø'1Ð4FÑ'FÐ$Ð$à'.Ð1CÑ'CÐ$Ø&9¸!¸!¸!¸R¸a¸R¸%Ô&@ÐD\Ð^lÑDlÑ&mÐ#Ý$œ{Ð+;½U¼YÀ{ÐXYÐcgÐ=hÑ=hÔ=hÐijÔ=kÐmsÑtÔtÐØ2µU´YØ'Ð*>Ò>ÀBÐPTð6
ñ 6
ô 6
ñ 
ð 	
rs   Ú!next_token_hits_stopping_criteriac                 ó˜   — t          j        | ¦  «        }t          j        |¦  «        |du z   }t          j        |¦  «         }||z  |z  S )zv
        Beam Search stopping condition -- halts the generation loop if any of these conditions becomes False
        T)rm   r  r?  )rû  rþ  r  r�  Úimprovement_possibleÚexists_open_beamÚvalid_continuationss          rt   Ú%_beam_search_has_unfinished_sequencesz5GenerationMixin._beam_search_has_unfinished_sequencesà  s]   € õ  %œyÐ)LÑMÔMÐõ #œYÐ'7Ñ8Ô8¸NÈdÐ<RÑSÐTÐõ  %œyÐ)JÑKÔKÐKÐà#Ð&6Ñ6Ð9LÑLÐLrs   Úaccumulated_log_probsÚrunning_sequencesÚrunning_beam_indicesre  Úbeams_to_keeprh  c                 óì  — |rMt          j        t          j                             |d¬¦  «        |¬¦  «        }t          j        |d|¬¦  «        }nt          j        ||¬¦  «        \  }}||	z  }|                      ||¦  «        }|                      ||¦  «        }||	z  }||dd…dd…|f<   t          j        |
|j	        ¬¦  «         
                    dd¦  «        |z  }||z   }||dd…dd…||z
  f<   |||fS )	a'  
        Get top-K continuations given the accumulated log probs on the next token.

        A few notes to understand what's going on:
        1. Each item in batch has `num_beams` * `vocab_size` candidate continuations. For each item, get the
        top K [K = (number of EOS tokens + 1) * `num_beams`] candidates with the highest accumulated
        log-probabilities, or sample them without replacement using the accumulated scores
        2. We gather the top K (as opposed to `num_beams`, or any number lower than K) here so that we have at
        least `num_beams` sequences remaining to continue the live beam search.
        3. Note that other stopping criteria might result in impossible to continue beams, i.e. all continuations
        selected in this step hit the stopping criteria.
        rŸ   r:  rÒ  r"   )r÷  r;  Úindex©rö   Nr~  )rm   râ  r   r¼  rá  rÀ  Útopkrú  rQ  r  r<  )r”   r  r  r  rè  rÿ  re  r  rz  rh  rÇ   Útopk_indicesÚtopk_log_probsÚtopk_current_beam_indicesÚtopk_running_beam_indicesÚtopk_running_sequencesÚtopk_idsÚbatch_offsetÚbatch_modified_indicess                      rt   Ú_get_top_k_continuationsz(GenerationMixin._get_top_k_continuations÷  sA  € ð< ð 	^Ý Ô,Ý”×%Ò%Ð&;ÀÐ%ÑDÔDÐR_ðñ ô ˆLõ #œ\Ð0EÈ1ÐT`ÐaÑaÔaˆNˆNå+0¬:Ð6KÈ}Ð+]Ñ+]Ô+]Ñ(ˆN˜Lð %1°JÑ$>Ð!Ø$(×$6Ò$6Ð7KÐMfÑ$gÔ$gÐ!Ø!%×!3Ò!3Ð4EÐG`Ñ!aÔ!aÐØ *Ñ,ˆð 19Ð˜q˜q˜q ! ! ! W˜}Ñ-õ ”| J°x´ÐGÑGÔG×LÒLÈRÐQRÑSÔSÐV_Ñ_ˆØ!:¸\Ñ!IÐØH^Ð! ! ! ! Q Q Q¨Ð2DÑ(DÐ"DÑEàÐ5Ð7PÐPÐPrs   r  r  r  c                 ó  — ||                      t          j        ¦  «        dz  z   }t          j        ||¬¦  «        d         }|                      ||¦  «        }|                      ||¦  «        }	|                      ||¦  «        }
||	|
fS )zÂ
        Given the top-K continuations, their scores, and whether they hit a stopping criteria, select the
        best non-finished beams to continue beam search in the next iteration.
        r  r  r"   )rR  rm   rà  r  rú  )r”   r  r  r  r  rz  Útopk_running_log_probsÚnext_topk_indicesr  rü  r  s              rt   Ú%_get_running_beams_for_next_iterationz5GenerationMixin._get_running_beams_for_next_iteration-  sš   € ð "0Ð2S×2VÒ2VÕW\ÔWdÑ2eÔ2eÐhnÑ2nÑ!nÐå!œJÐ'=ÀÐKÑKÔKÈAÔNÐØ ×.Ò.Ð/EÐGXÑYÔYÐØ"×0Ò0Ð1GÐIZÑ[Ô[ÐØ#×1Ò1Ð2KÐM^Ñ_Ô_ÐØ Ð"5Ð7KÐKÐKrs   Útop_num_beam_maskc                 óÐ  — |	|
ddd…f         z  }||dz   |z
  |z  z  }t          j        |dd¬¦  «        |du z  }||                     t           j        ¦  «        dz  z  }||                      t           j        ¦  «        dz  z  }|| dz  z  }t          j        ||fd¬¦  «        }t          j        ||fd¬¦  «        }t          j        ||fd¬¦  «        }t          j        ||fd¬¦  «        }t          j        ||¬¦  «        d         }|                      ||¦  «        }|                      ||¦  «        }|                      ||¦  «        }|                      ||¦  «        }||||fS )	z¥
        Updates the finished beams if (and only if) there are new completed sequences that have a higher score than
        the current finished sequences.
        Nr"   rŸ   T)ÚaxisÚkeepdimsr  r:  r  )rm   r?  rR  rà  rA  r  rú  )r”   rd   r  rý  r  r   r  rû  rþ  r  r#  rz  rè  rÿ  rl  r�  Údid_top_num_beams_just_finishedÚbeams_in_batch_are_fullÚmerged_sequencesÚmerged_scoresÚmerged_beam_indicesÚmerged_is_sent_finishedÚtopk_merged_indicess                          rt   Ú_update_finished_beamsz&GenerationMixin._update_finished_beamsC  s²  € ð2 +LÐN_Ð`dÐfgÐfgÐfgÐ`gÔNhÑ*hÐ'ð (¨G°a©KÐ:LÑ,LÐQ_Ñ+_Ñ`ˆå"'¤)Ð,<À2ÐPTÐ"UÑ"UÔ"UÐYgÐkoÐYoÑ"pÐØÐ1×4Ò4µU´]ÑCÔCÀfÑLÑLˆàÐ?Ð?×CÒCÅEÄMÑRÔRÐU[Ñ[Ñ[ˆð 	Ð;Ð;¸vÑEÑEˆõ
 !œ9 iÐ1GÐ%HÈaÐPÑPÔPÐÝœ	 ;°Ð"?ÀQÐGÑGÔGˆÝ#œi¨Ð7PÐ(QÐWXÐYÑYÔYÐÝ"'¤)Ð-=Ð?^Ð,_ÐefÐ"gÑ"gÔ"gÐÝ#œj¨¸)ÐDÑDÔDÀQÔGÐØ×&Ò&Ð'7Ð9LÑMÔMˆ	Ø×(Ò(¨Ð8KÑLÔLˆØ×)Ò)Ð*=Ð?RÑSÔSˆØ×-Ò-Ð.EÐGZÑ[Ô[ÐØ˜+ |Ð5EÐEÐErs   c                 óú  — |j         }|j        }|j        }	|j        }
|j        }|j        }|j        }|j        }|j        }|j	        }|j
        }|j        }|j        }|j        dd…         \  }}||z  }| j        j        dk    r| j        j        }nH| j        j        dk    r|                      ¦   «         j        }n| j                             ¦   «         j        }|}d}|�|j        d         nd}t-          dd|z   ¦  «        |z  }t/          j        t/          j        |t.          j        ¬¦  «        t/          j        ||z
  t.          j        ¬¦  «        fd¬	¦  «                             |j        ¦  «        }|                      ||j        |¦  «        }|j        }|rtA          d
¦  «        ‚|r|rdnd}|r|rdn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}%|�
|p|d         nd}&t/          j#        |||f|&t.          j$        |j        ¬¦  «        }'|  %                    |||¦  «        |'dd…dd…d|…f<   |' &                    ¦   «          '                    ¦   «         }(t/          j        ||ft.          j(        |j        ¬¦  «        })d|)dd…dd…f<   t/          j#        ||fdt.          j(        |j        ¬¦  «        }*t/          j        ||ft.          j        |j        ¬¦  «        }+t/          j        |dft.          j        |j        ¬¦  «        },t/          j        ||ft.          j        |j        ¬¦  «        }-t/          j#        ||||z
  fdt.          j)        |j        ¬¦  «        }.|. &                    ¦   «          '                    ¦   «         } |  *                    |||j        ¬¦  «        �rc|  +                    |'dd…dd…d|…f         ¦  «        }/ | j,        |/fi |¤Ž}0|0 -                    |	rd|	ini ¦  «         |0 -                    |
rd|
ini ¦  «          | di |0¤ddi¤Ž}1|  .                    |1|| j        j!        ¬¦  «        }|r|rŒ¹|1j/        dd…ddd…f                              dt.          j0        |j        ¬¦  «        }2tb          j2         3                    |2d¬	¦  «        }3 ||/|3¦  «        }3|r�|r||2 '                    ¦   «         fz  }|r|r||3 '                    ¦   «         fz  }|	r6|!| j        j!        r|1j4        fn|1j5        fz  }!| j        j!        r|"|1j6        fz  }"|
r|#| j        j!        r|1j7        fn|1j8        fz  }#~1|  %                    |3||¦  «        }3|3|)dd…dd…df         z   }3t/          j9        |3|||z  f¦  «        }3|  :                    |3|'|.|||||||¬¦
  «
        \  }4}5}6 ||  +                    |5dd…dd…d|dz   …f         ¦  «        |¦  «        }-|  %                    |-||¦  «        }-|  ;                    |4|5|6|-|¬¦  «        \  }'})}.|  <                    |(|5|*|4| |6|,|+|-||||||¬¦  «        \  }(}*} }+| "                    dd¦  «        �k|  +                    |.d||z
  f         ¦  «        }7t{          | d¦  «        r |  >                    |d         |7¦  «        |d<   n|d          ?                    |7¦  «         |dz   }|  @                    |,|)|*|+|||||¬ ¦	  «	        },|  A                    |,|+|-|¦  «         }|  *                    |||j        ¬¦  «        �°c|  +                    |(dd…d|…dd…f         ¦  «        }(|  +                    |*dd…d|…f         ¦  «        }*|  +                    | dd…d|…dd…f         ¦  «        } | dz                        ¦   «          B                    d¬	¦  «                             ¦   «         }8||8z   }9|(dd…d|9…f         }(| dd…d|8…f         } |rg|sd}*| j        j!        r-t‡          |(|*||| |$|%|!|"|#| "                    d¦  «        ¬!¦  «        S t‰          |(|*||| |!|#| "                    d¦  «        ¬"¦  «        S |(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.

        If it's the first time you're diving into Beam Search, we recommend you read the following blog post:
        https://huggingface.co/blog/how-to-generate (especially the beam search section).

        You can recompute the sequence scores from the individual scores using the `compute_transition_scores` function
        (https://huggingface.co/docs/transformers/main_classes/text_generation#transformers.GenerationMixin.compute_transition_scores)

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size*num_beams, sequence_length)`):
                The sequence used as a prompt for the generation.
            logits_processor (`LogitsProcessorList`):
                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`:
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            generation_config ([`~generation.GenerationConfig`]):
                The generation configuration to be used as parametrization of the decoding method.
            synced_gpus (`bool`):
                Whether to continue running the while loop until max_length (needed to avoid deadlocking with
                `FullyShardedDataParallel` and DeepSpeed 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.GenerateBeamDecoderOnlyOutput`], [`~generation.GenerateBeamEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.GenerateBeamDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.GenerateBeamEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.
        Nr   ÚMoshiDepthDecoderÚImageGPTForCausalImageModelingFr   r"   rÁ   r:  zÃ`low_memory=True` is not supported after the beam search refactor. Please check the discussion in #35802 *after the PR got merged*, and add a comment there if your questions are not yet answered.rr   r  rg   rh   rŸ   )Ú
fill_valuerÂ   r  r  r  r~  r/  r0  r1  TrÐ  rÑ  )
r  r  r  rè  rÿ  re  r  rz  rh  rÇ   )r  r  r  r  rz  )rd   r  rý  r  r   r  rû  rþ  r  r#  rz  rè  rÿ  rl  r�  r]   .Ú_reorder_cache)	rû  rü  rý  rþ  rè  r`  rÿ  r�  rl  ©rd   r~   re   rf   r   rw   rx   ry   rz   r{   r]   ©rd   r~   re   rf   r   rg   rh   r]   )Er  r  r/  r0  rÖ  r×  rØ  re  r�  rl  r`  rz  r9  r¡   rü   ri   rÃ   Úaudio_vocab_sizeÚget_output_embeddingsÚout_featuresrg  rh  r¿  rm   rA  r  rY  ÚzerosrR  r  r  Ú
low_memoryrû   rÉ   rÍ   Úfullr
  rõ  Údetachr§   ÚfloatÚint32r¦  ró  rî   rü  rW  rf   rà  r   r¼  r½  ry   rg   rz   r{   rh   rº  r  r"  r.  rÜ   r3  Úreorder_cacher  r  r¾  r�   r}   ):r”   r›   rY  r¢  r  rc  rñ   r  r  r/  r0  rÖ  r×  rØ  re  r�  rl  r`  rz  r9  Úbatch_size_unflattenedrè  rÇ   rh  rÿ  rŸ  Ún_eos_tokensr  r#  Ú
sequentialÚ
all_scoresrç  r   ry   rz   r{   rw   rx   Úoutput_fill_valuer  rd   rü  rý  rþ  rû  r  r  Úflat_running_sequencesrà   Úmodel_outputsrf   Ú	log_probsr  r  r  Úbeam_idxÚmax_generated_lengthÚoutput_lengths:                                                             rt   rŽ  zGenerationMixin._beam_searchz  s8  € ð\ )Ô:ˆØ(Ô:ˆØ-Ô?ÐØ0ÔEÐØ)Ô7ˆØ)Ô7ˆØ"3Ô"KÐØ%Ô/ˆ	Ø*Ô9ˆØ*Ô9ˆØ&Ô1ˆ
Ø%Ô/ˆ	Ø0ÔEÐà*3¬/¸"¸1¸"Ô*=Ñ'Ð Ø+¨yÑ8ˆ
àŒ>Ô"Ð&9Ò9Ð9ØœÔ5ˆJˆJØŒ^Ô$Ð(HÒHÐHØ×3Ò3Ñ5Ô5ÔBˆJˆJàœ×4Ò4Ñ6Ô6ÔAˆJØ$ÐØ"Ðð 1=Ð0H�|Ô)¨!Ô,Ð,ÈaˆÝ˜A˜q <Ñ/Ñ0Ô0°9Ñ<ˆÝ!œIÝŒZ˜­5¬:Ð6Ñ6Ô6½¼À]ÐU^ÑE^ÕglÔgqÐ8rÑ8rÔ8rÐsØð
ñ 
ô 
÷ Š"ˆYÔÑ
Ô
ð 	ð
 ×7Ò7¸ÀÔAQÐS_Ñ`Ô`ˆð 'Ô1ˆ
Øð 	Ýðtñô ð ð 4ÐP¸ÐP�R�RÈDˆ
Ø3ÐP¸ÐP�R�RÈDˆ
Ø5ÐR¸-ÐR�r�rÈdˆØ$;Ð\Ð@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ð "ð @LÐ?W˜LÐ;¨L¸¬OøÐ]_ÐÝ!œJØ˜ JÐ/Ø(Ý”+ØÔ#ð	
ñ 
ô 
Ðð -1×,DÒ,DÀYÐPZÐ\eÑ,fÔ,fÐ˜!˜!˜!˜Q˜Q˜Q   ˜.Ñ)Ø%×,Ò,Ñ.Ô.×4Ò4Ñ6Ô6ˆ	õ
 $œk¨:°yÐ*AÍÌÐ]fÔ]mÐnÑnÔnÐØ%)Ð˜A˜A˜A˜q˜r˜r˜EÑ"Ý”j *¨iÐ!8ÀTÕQVÔQ\ÐenÔeuÐvÑvÔvˆõ !œ;¨
°IÐ'>ÅeÄjÐYbÔYiÐjÑjÔjÐõ /4¬j¸*Àa¸ÕPUÔPZÐclÔcsÐ.tÑ.tÔ.tÐ+õ -2¬KØ˜Ð#­5¬:¸iÔ>Nð-
ñ -
ô -
Ð)õ
  %œzØ˜ J°Ñ$8Ð9ÀbÕPUÔP[ÐdmÔdtð 
ñ  
ô  
Ðð ,×2Ò2Ñ4Ô4×:Ò:Ñ<Ô<ˆð ×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ L	à%)×%;Ò%;Ð<MÈaÈaÈaÐQRÐQRÐQRÐT\ÐU\ÐT\ÈnÔ<]Ñ%^Ô%^Ð"Ø=˜4Ô=Ð>TÐeÐeÐXdÐeÐeˆLð ×ÒÐL]Ð eÐ!4Ð6GÐ HÐ HÐceÑfÔfÐfØ×ÒÐRfÐ nÐ!7Ð9MÐ NÐ NÐlnÑoÔoÐoà ˜DÐBÐB <ÐBÐB¸TÐBÐBÐBˆMð  ×CÒCØØØ#'¤;Ô#Að Dñ ô ˆLð
 ð Ð1ð Øð #Ô)¨!¨!¨!¨R°°°¨(Ô3×6Ò6¸DÍÌÐ^gÔ^nÐ6ÑoÔoˆFõ œ×1Ò1°&¸bÐ1ÑAÔAˆIØ(Ð(Ð)?ÀÑKÔKˆIð 'ð Ø ð 4Ø 6§<¢<¡>¤>Ð"3Ñ3�JØ*ð 7¨}ð 7Ø 9§?¢?Ñ#4Ô#4Ð"6Ñ6�Jà$ð NØ&àœ;Ô9ð9˜Ô9Ð;Ð;à+Ô6Ð8ñÐ&ð
 ”{Ô5ð NØ(¨]Ô-KÐ,MÑMÐ(à'ð Ø)àœ;Ô9ð<˜Ô<Ð>Ð>à+Ô9Ð;ñÐ)ð à×0Ò0°¸JÈ	ÑRÔRˆIØ!Ð$7¸¸¸¸1¸1¸1¸d¸
Ô$CÑCˆIÝœ i°*¸iÈ*Ñ>TÐ1UÑVÔVˆIð QU×PmÒPmØ&/Ø"3Ø%9ØØ#5Ø#Ø+Ø#Ø%Ø%ð Qnñ Qô QÑMˆNÐ2Ð4Mð 1BÐ0AØ×&Ò&Ð'=¸a¸a¸aÀÀÀÀMÀgÐPQÁkÀMÐ>QÔ'RÑSÔSØñ1ô 1Ð-ð 15×0HÒ0HØ1°:¸}ñ1ô 1Ð-ð
 LP×KuÒKuØ-Ø'=Ø*CØ2SØ#ð Lvñ Lô LÑHÐÐ2Ð4Hð FJ×E`ÒE`Ø#Ø'=Ø'Ø-Ø)Ø*CØ4WØ!1Ø2SØ"3Ø#ØØ#5Ø-Ø-ð Fañ Fô FÑBˆI�{ LÐ2Bð. ×ÒÐ 1°4Ñ8Ô8ÐDØ×1Ò1Ð2FÀsÈGÐVhÑLhÐGhÔ2iÑjÔj�Ý˜4Ð!1Ñ2Ô2ð LØ6:×6IÒ6IÈ,ÐWhÔJiÐksÑ6tÔ6t�LÐ!2Ñ3Ð3à Ð!2Ô3×AÒAÀ(ÑKÔKÐKà ‘kˆGØ26×2RÒ2RØ4WØ$7Ø'Ø!1ØØ%Ø#5Ø-Ø-ð 3Sñ 
3ô 
3Ð/ð &*×%OÒ%OØ3Ø Ø1Øñ	&ô &ð "ÐðO ×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ L	ð` ×*Ò*¨9°Q°Q°QÐ8MÐ9MÐ8MÈqÈqÈqÐ5PÔ+QÑRÔRˆ	Ø×,Ò,¨[¸¸¸Ð<QÐ=QÐ<QÐ9QÔ-RÑSÔSˆØ×-Ò-¨l¸1¸1¸1Ð>SÐ?SÐ>SÐUVÐUVÐUVÐ;VÔ.WÑXÔXˆð ".°Ñ!1× 7Ò 7Ñ 9Ô 9×>Ò>À1Ð>ÑEÔE×IÒIÑKÔKÐØ*Ð-AÑAˆØ˜a˜a˜a  - Ð/Ô0ˆ	Ø# A A AÐ'<Ð(<Ð'<Ð$<Ô=ˆà"ð 	Ø ð #Ø"�àŒ{Ô-ð Ý7Ø'Ø%0Ø%Ø%Ø!-Ø'9Ø*?Ø'9Ø%5Ø*?Ø$0×$4Ò$4Ð5FÑ$GÔ$Gðñ ô ð õ 5Ø'Ø%0Ø%Ø%Ø!-Ø1Ø"7Ø$0×$4Ò$4Ð5FÑ$GÔ$Gð	ñ 	ô 	ð 	ð Ðrs   r›  c                 ó  ‡4‡5‡6‡7‡8‡9‡:— |j         }|j        }	|j        }
|j        }|j        }|j        }|j        }|j        Š9|j        }‰9|z  Š:t          |j
        ¦  «        |z  Š5|j        }|j        \  }}|                      ||j        |¦  «        }|r|rˆ5ˆ:fd„t          |¦  «        D ¦   «         Š8ndŠ8‰9‰5z  |k    rt          d‰9‰5z  › d|› d�¦  «        ‚|r|rdn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}t'          j        ‰5‰9fd
t&          j        |¬¦  «        }d|dd…dd‰:…f<   |                     ‰5‰9z  f¦  «        }d}|j        d         }|                      |||j        ¬¦  «        �rút'          j        ‰5‰9z  |j        |¬¦  «        }t'          j        ‰5‰9z  t&          j        |¬¦  «        } | j        |fi |¤Ž}|                     |
rd|
ini ¦  «         |                     |rd|ini ¦  «          | di |¤ddi¤Ž} |                      | || j        j        ¬¦  «        }|r|r|dz   }ŒÝ|r&t'          j        | j        dd…ddd…f         ¦  «        }!|r.| j        dd…ddd…f                               d|j        ¬¦  «        }"t          |¦  «        D �]•Š6‰6‰:z  }#tC          |#‰:z   ‰9¦  «        }$|$|#z
  }%g }&t          ‰5¦  «        D ]2Š4|& "                    ˆ4ˆ9fd„t          |#|$¦  «        D ¦   «         ¦  «         Œ3||&         }'| j        |&ddd…f                               t&          j#        |j        ¬¦  «        }(tH          j%         &                    |(d¬¦  «        })|)j        d         }* ||'|)|‰6¬¦  «        }+|+||&          '                    d¦  «        z   })|) (                    |+¦  «        })|r|+|!|&<   |)                     ‰5|%|*z  ¦  «        })|	�|	j        d         nd},t'          j)        |)tU          dd|,z   ¦  «        |%z  ddd¬¦  «        \  })}-t'          j+        |-|*d¬¦  «        }.|-|*z  }-‰8�tY          ‰8d¦  «        nd}/| -                    |'|)|-|.||	|/‰6|¬¦	  «	        }0|0d         ||&<   |0d          }1|0d!         Š7|rB|r@t]          ˆ6ˆ7ˆ8fd"„t          t          ‰8d         ¦  «        ¦  «        D ¦   «         ¦  «        ‰8‰6<   |'‰7         ||&<   t'          j/        |'‰7dd…f         |1 '                    d¦  «        gd¬¦  «        }'|'dd…df         ||&<   ‰9t'          j+        ‰7|%d¬¦  «        z  |#z   ‰7|%z  z   ||&<   �Œ—|ri|r||!fz  }|r||"fz  }|
r6|| j        j        r| j0        fn| j1        fz  }| j        j        r|| j2        fz  }|r|| j        j        r| j3        fn| j4        fz  }t'          j/        || '                    d¦  «        gd¬¦  «        }~ |                     d#d¦  «        �Ktk          | d$¦  «        r |  6                    |d#         |¦  «        |d#<   n|d#          7                    |¦  «         |dz   }|j8        sts           |||¦  «        ¦  «        rd}|                      |||j        ¬¦  «        �°ú‰8�tY          ‰8d¦  «        nd}2| :                    |||-|.||	|j;        |2|¬%¦	  «	        }3|rŽ|sd|3d&<   | j        j        r?ty          |3d'         |3d&         |||3d(         ||||||                     d#¦  «        ¬)¦  «        S t{          |3d'         |3d&         |||3d(         |||                     d#¦  «        ¬*¦  «        S |3d'         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.

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size*num_beams, 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`):
                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`):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            generation_config ([`~generation.GenerationConfig`]):
                The generation configuration to be used as parametrization of the decoding method.
            synced_gpus (`bool`):
                Whether to continue running the while loop until max_length (needed to avoid deadlocking with
                `FullyShardedDataParallel` and DeepSpeed 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.GenerateBeamDecoderOnlyOutput`], [`~generation.GenerateBeamEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.GenerateBeamDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.GenerateBeamEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.
        c           	      ób   •— g | ]+}t          d „ t          ‰‰z  ¦  «        D ¦   «         ¦  «        ‘Œ,S )c              3   ó   K  — | ]}d V — ŒdS ©rr   Nrr   ©rõ   rè   s     rt   r*  z@GenerationMixin._group_beam_search.<locals>.<listcomp>.<genexpr>  s"   è è € Ð!PÐ!P¨ "Ð!PÐ!PÐ!PÐ!PÐ!PÐ!Prs   )rp   Úrange)rõ   rè   rÇ   Únum_sub_beamss     €€rt   rÏ  z6GenerationMixin._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Ðqrs   Nú)Batch dimension of `input_ids` should be ú	, but is rÑ  rr   r  rg   rh   r  r  r   Fr"   r~  r/  r0  r1  TrÐ  rŸ   )rö  r  c                 ó    •— g | ]
}‰‰z  |z   ‘ŒS rr   rr   )rõ   ÚidxrÅ  rz  s     €€rt   rÏ  z6GenerationMixin._group_beam_search.<locals>.<listcomp>R  s#   ø€ ÐfÐfÐf¸˜ YÑ.°Ñ4ÐfÐfÐfrs   r:  )Úcurrent_tokensÚbeam_group_idxr   ©r;  ÚlargestÚsortedÚfloor)Úrounding_mode)r  r  r   Úgroup_indexrÿ  Únext_beam_scoresÚnext_beam_tokensÚnext_beam_indicesc              3   óT   •K  — | ]"}‰‰         ‰|                  ‰|         fz   V — Œ#d S r­   rr   )rõ   ÚirW  rH  r   s     €€€rt   r*  z5GenerationMixin._group_beam_search.<locals>.<genexpr>‰  sM   øè è € ð 9ð 9ØWX˜ ^Ô4°X¸a´[ÔAÀXÈaÄ[ÀNÑRð9ð 9ð 9ð 9ð 9ð 9rs   r]   r3  ©r  r  r`  r   rÿ  Úsequence_scoresrd   r   r4  r5  )>r  r  r/  r0  rÖ  r×  rØ  rz  r{  rÊ   Ú
_beam_hypsr  r¡   r  rP  rû   rÃ   rÉ   rÍ   rm   r;  r=  r<  r¦  r9  rÂ   rÔ   rî   rü  rW  Ú
zeros_likerf   rR  ré  Úextendrà  r   r¼  r½  rO  Ú	expand_asr  r¿  Údivr¾  Úprocessrp   rA  ry   rg   rz   r{   rh   rÜ   r3  r?  Úis_doner?  Úfinalizer`  r�   r}   );r”   r›   r›  rY  r¢  r  rc  rñ   r  r  r/  r0  rÖ  r×  rØ  r{  r  Úbatch_beam_sizerè  re   rç  ry   rz   r{   rw   rx   rý  rŸ  rÿ  rV  Úreordering_indicesrà   rK  Úprocessed_scoreÚraw_logit_scoreÚgroup_start_idxÚgroup_end_idxÚ
group_sizeÚbatch_group_indicesÚgroup_input_idsrí  rî  rh  Únext_token_scores_processedrA  rð  Únext_indicesÚprocess_beam_indicesÚbeam_outputsÚbeam_next_tokensÚfinal_beam_indicesÚsequence_outputsrÅ  rÇ   rW  rH  r   rz  rQ  s;                                                       @@@@@@@rt   r‘  z"GenerationMixin._group_beam_searchÊ  sš
  øøøøøøø€ ðV )Ô:ˆØ(Ô:ˆØ-Ô?ÐØ0ÔEÐØ)Ô7ˆØ)Ô7ˆØ"3Ô"KÐàÔ)ˆ	Ø%Ô5ˆØ! _Ñ4ˆÝ˜Ô/Ñ0Ô0°OÑCˆ
ØÔ!ˆà#,¤?Ñ ˆ˜Ø×7Ò7¸ÀÔAQÐS_Ñ`Ô`ˆà"ð 	  }ð 	 Ø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��ÈˆØ3ÐP¸ÐP�R�RÈDˆ
Ø$;Ð\Ð@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ˆà"Ðà&œ_¨QÔ/ÐØ×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ [	*å"œ[¨°iÑ)?ÀyÄÐ_eÐfÑfÔfˆNõ "'¤¨Z¸)Ñ-CÍ5Ì:Ð^dÐ!eÑ!eÔ!eÐð >˜4Ô=¸iÐXÐXÈ<ÐXÐXˆLð ×ÒÐL]Ð eÐ!4Ð6GÐ HÐ HÐceÑfÔfÐfØ×ÒÐRfÐ nÐ!7Ð9MÐ NÐ NÐlnÑoÔoÐoà�dÐ<Ð<˜\Ð<Ð<°tÐ<Ð<Ð<ˆGð  ×CÒCØØØ#'¤;Ô#Að Dñ ô ˆLð
 ð Ð1ð Ø! A™+�Øàð MÝ"'Ô"2°7´>À!À!À!ÀRÈÈÈÀ(Ô3KÑ"LÔ"L�Øð bð #*¤.°°°°B¸¸¸°Ô":×"=Ò"=À4ÐPYÔP`Ð"=Ñ"aÔ"a�å"'¨Ñ"8Ô"8ð Oñ O�Ø"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×$QÒ$QÝœ-°	Ô0@ð %Rñ %ô %Ð!õ %'¤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^Ñ$_Ô$_Ð!ð 9EÐ8P˜|Ô1°!Ô4Ð4ÐVW�Ý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Ø .Ø'9ð  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Ø ð 5Ø ?Ð"4Ñ4�JØ$ð 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ð ð ×ÒÐ 1°4Ñ8Ô8ÐDÝ˜4Ð!1Ñ2Ô2ð VØ6:×6IÒ6IØ$Ð%6Ô7Ð9Kñ7ô 7�LÐ!2Ñ3Ð3ð !Ð!2Ô3×AÒAÐBTÑUÔUÐUð  ‘kˆGàÔ"ð *¥cÐ*;Ð*;¸IÀvÑ*NÔ*NÑ&OÔ&Oð *Ø%)Ð"ðw ×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ [	*ðz 7CÐ6N�S ¨rÑ2Ô2Ð2ÐTXÐØ&×/Ò/ØØØØØ%Ø%Ø(Ô3Ø+Ø1ð 0ñ 

ô 

Ðð #ð 	1Ø ð ;Ø6:Ð Ð!2Ñ3àŒ{Ô-ð Ý7Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø%Ø!1°.Ô!AØ'9Ø*?Ø'9Ø%5Ø*?Ø$0×$4Ò$4Ð5FÑ$GÔ$Gðñ ô ð õ 5Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø%Ø!1°.Ô!AØ1Ø"7Ø$0×$4Ò$4Ð5FÑ$GÔ$Gð	ñ 	ô 	ð 	ð $ KÔ0Ð0rs   r~  c                 óŠ  ‡*‡+— |j         }|j        }	|j        }
|j        }|j        }|j        }|j        }t          |j        ¦  «        }|j	        }|j
        dd…         \  }}|                      ||j        |¦  «        }||z  |k    rt          d||z  › d|› d�¦  «        ‚|r|rdn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}t'          j        ||ft&          j        |j        ¬¦  «        }d|dd…dd…f<   |                     ||z  f¦  «        }d}|j
        d         }|                      |||j        ¬¦  «        �rR | j        |fi |¤Ž}|                     |
rd|
ini ¦  «         |                     |rd|ini ¦  «          | di |¤ddi¤Ž}|                      ||| j        j        ¬¦  «        }|r|r|dz   }Œš|j        dd…ddd…f                              dt&          j        |j        ¬¦  «        }t<          j                              |d¬¦  «        }  ||| ¦  «        }!|!|dd…df          !                    |!¦  «        z   } |  "                    ¦   «         }"|ri|r|| fz  }|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  ¦  «        } |	�|	j
        d         nd}$t'          j(        | tS          dd|$z   ¦  «        |z  ddd¬¦  «        \  } }%|%|#z   *                    ¦   «         }&|%|#z  }%| +                    || |%|&|"||	‰+|¬¦	  «	        }'|'d         }|'d         }(|'d         Š*t'          j,        |‰*dd…f         |( -                    d¦  «        gd¬¦  «        }~|                     dd¦  «        �Kt]          | d¦  «        r |  /                    |d         ‰*¦  «        |d<   n|d          0                    ‰*¦  «         |r8|r6t          ˆ*ˆ+fd „t          t          ‰+¦  «        ¦  «        D ¦   «         ¦  «        Š+|dz   }|j1        ste           |||¦  «        ¦  «        rd}|                      |||j        ¬¦  «        �°R| 3                    |||%|&||	|j4        ‰+|¬!¦	  «	        })|rŽ|sd|)d"<   | j        j        r?tk          |)d#         |)d"         |||)d$         ||||||                     d¦  «        ¬%¦  «        S tm          |)d#         |)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.

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size*num_beams, 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`):
                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`):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            generation_config ([`~generation.GenerationConfig`]):
                The generation configuration to be used as parametrization of the decoding method.
            synced_gpus (`bool`):
                Whether to continue running the while loop until max_length (needed to avoid deadlocking with
                `FullyShardedDataParallel` and DeepSpeed 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.GenerateBeamDecoderOnlyOutput`], [`~generation.GenerateBeamEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.GenerateBeamDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.GenerateBeamEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.
        Nr   rR  rS  rÑ  rr   c              3   ó   K  — | ]}d V — ŒdS rN  rr   rO  s     rt   r*  z;GenerationMixin._constrained_beam_search.<locals>.<genexpr>4  s"   è è € Ð5Ð5˜�"Ð5Ð5Ð5Ð5Ð5Ð5rs   r  rg   rh   r  r  r"   Fr~  r/  r0  r1  TrÐ  rŸ   rÑ  r:  r   rX  )r  r  r   rÿ  r^  r_  r`  r]   r3  c              3   óH   •K  — | ]}‰‰|                  ‰|         fz   V — Œd S r­   rr   )rõ   rb  rH  r   s     €€rt   r*  z;GenerationMixin._constrained_beam_search.<locals>.<genexpr>®  s8   øè è € Ð$rÐ$rÐTU \°(¸1´+Ô%>À(È1Ä+ÀÑ%OÐ$rÐ$rÐ$rÐ$rÐ$rÐ$rrs   rc  rd  rd   r   r4  r5  )7r  r  r/  r0  rÖ  r×  rØ  rÊ   re  rz  r¡   r  r  rû   rp   rP  rÃ   rÉ   rÍ   rm   r9  r=  r<  r¦  rî   rü  rW  rf   rR  rà  r   r¼  r½  rh  r§   ry   rg   rz   r{   rh   r  r¿  rÔ   rj  rA  rO  rÜ   r3  r?  rk  r?  rl  r`  r�   r}   ),r”   r›   r~  rY  r¢  r  rc  rñ   r  r  r/  r0  rÖ  r×  rØ  rÇ   rz  rm  rè  re   rç  ry   rz   r{   rw   rx   rý  rŸ  rÿ  rà   rK  rí  rî  rv  Úscores_for_all_vocabrh  rA  rð  rw  ry  rz  r|  rH  r   s,                                             @@rt   r“  z(GenerationMixin._constrained_beam_searchñ  s  øø€ ðX )Ô:ˆØ(Ô:ˆØ-Ô?ÐØ0ÔEÐØ)Ô7ˆØ)Ô7ˆØ"3Ô"KÐåÐ0Ô;Ñ<Ô<ˆ
Ø+Ô5ˆ	à#,¤?°2°A°2Ô#6Ñ ˆ˜Ø×7Ò7¸ÀÔAQÐS_Ñ`Ô`ˆà�zÑ! _Ò4Ð4ÝØo¸IÈ
Ñ<RÐoÐoÐ]lÐoÐoÐoñô ð ð
 0ÐL°MÐL��ÈˆØ3ÐP¸ÐP�R�RÈDˆ
à: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ˆà"Ðà&œ_¨QÔ/ÐØ×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ j	*Ø=˜4Ô=¸iÐXÐXÈ<ÐXÐXˆLð ×ÒÐL]Ð eÐ!4Ð6GÐ HÐ HÐceÑfÔfÐfØ×ÒÐRfÐ nÐ!7Ð9MÐ NÐ NÐlnÑoÔoÐoà�dÐ<Ð<˜\Ð<Ð<°tÐ<Ð<Ð<ˆGð  ×CÒCØØØ#'¤;Ô#Að Dñ ô ˆLð
 ð Ð1ð Ø! A™+�Øð
 !(¤¨q¨q¨q°"°a°a°a¨xÔ 8× ;Ò ;ÀÍUÌ]ÐclÔcsÐ ;Ñ tÔ tÐÝ "¤× 9Ò 9Ø! rð !:ñ !ô !Ðð +;Ð*:¸9ÐFWÑ*XÔ*XÐ'à ;¸kÈ!È!È!ÈTÈ'Ô>R×>\Ò>\Ø+ñ?ô ?ñ !Ðð $5×#:Ò#:Ñ#<Ô#<Ð ð 'ð Ø ð 3ØÐ0Ð2Ñ2�FØ ð 7ØÐ#4Ð"6Ñ6�JØ$ð 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Ðð 5AÐ4L˜<Ô-¨aÔ0Ð0ÐRSˆLÝ-2¬ZØ!¥3 q¨!¨lÑ*:Ñ#;Ô#;¸iÑ#GÈQÐX\Ðeið.ñ .ô .Ñ*Ð˜{ð (¨*Ñ4×:Ò:Ñ<Ô<ˆLØ%¨
Ñ2ˆKð 3×:Ò:ØØ!ØØØ$Ø)Ø)Ø)Ø#5ð ;ñ 
ô 
ˆLð 'Ð'9Ô:ˆKØ+Ð,>Ô?ÐØ#Ð$7Ô8ˆHåœ	 9¨X°q°q°q¨[Ô#9Ð;K×;UÒ;UÐVXÑ;YÔ;YÐ"ZÐ`bÐcÑcÔcˆIð ð ×ÒÐ 1°4Ñ8Ô8ÐDÝ˜4Ð!1Ñ2Ô2ð LØ6:×6IÒ6IÈ,ÐWhÔJiÐksÑ6tÔ6t�LÐ!2Ñ3Ð3à Ð!2Ô3×AÒAÀ(ÑKÔKÐKà&ð s¨=ð sÝ$Ð$rÐ$rÐ$rÐ$rÐ$rÕY^Õ_bÐcoÑ_pÔ_pÑYqÔYqÐ$rÑ$rÔ$rÑrÔr�ð  ‘kˆGà&Ô.ð *µ#Ð6GÐ6GÈ	ÐSYÑ6ZÔ6ZÑ2[Ô2[ð *Ø%)Ð"ðU ×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ j	*ðX 3×;Ò;ØØØØØ%Ø%Ø(Ô3Ø%Ø1ð <ñ 

ô 

Ðð #ð 	1Ø ð ;Ø6:Ð Ð!2Ñ3ØŒ{Ô-ð Ý7Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø%Ø!1°.Ô!AØ'9Ø*?Ø'9Ø%5Ø*?Ø$0×$4Ò$4Ð5FÑ$GÔ$Gðñ ô ð õ 5Ø.¨{Ô;Ø%5Ð6GÔ%HØ!Ø%Ø!1°.Ô!AØ1Ø"7Ø$0×$4Ò$4Ð5FÑ$GÔ$Gð	ñ 	ô 	ð 	ð $ KÔ0Ð0rs   rl  c                 óÆ  ‡*‡+— |j         }	|j        }
|j        }|j        }|j        }|j        }|r|rdn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}|j	        dd…         \  }}t          j        |t          j        |j        ¬¦  «        }|                      ||j        |¦  «        }d}d	}|                      |||j        ¬
¦  «        �r|j	        d         }|                     |¦  «        \  }}|                     | j        ¦  «        }|�|                     | j        ¦  «        }|j	        d         |j	        d         z
  } ||d¦  «        }t%          j        |¦  «        }t'          ||j	        d         | j        j        ¦  «        }t)          ||j	        d         ¦  «        }d|v rIt          j        |d         t          j        |||z   |j        t          j        ¬¦  «        fd¬¦  «        |d<    | j        |fi |¤Ž} d| v r|dz   | d<   |                      |
rd|
ini ¦  «         |                      |rd|ini ¦  «          | di | ¤Ž}!|!j        dd…| dz
  d…f                              t          j        |j        ¬¦  «        Š*‰*                     ¦   «         Š+t9          |¦  «        dk    rGt;          |dz   ¦  «        D ]4}" ||dd…d||"z   …f         ‰*dd…|"dd…f         ¦  «        ‰*dd…|"dd…f<   Œ5|	r|�t=          |||‰*|¦  «        \  }#}$nØ|	rW‰*                     d¬¦  «        }%t          j         |%ddd…dd…f         d¬¦  «         !                    d¦  «        ddd…f         }&n‰* "                    d¬¦  «        }&|dd…|d…f         }'|'|&dd…dd…f         k      #                    d¬¦  «        dk      $                    ¦   «         }$|r|$|k    r|$dz  }$|&dd…d|$dz   …f         }#t          j        ||#fd¬¦  «        }|�'| %                    |# &                    ¦   «         ¦  «         |j	        d         }(|!j'         (                    |(dz
  ¦  «         | )                    |‰*|$¦  «         |  *                    |!|| j        j        |$dz   ¬¦  «        }|r|r�Œä|�r|$dz   })|r+|tW          ˆ*fd„t;          |)¦  «        D ¦   «         ¦  «        z  }|r+|tW          ˆ+fd„t;          |)¦  «        D ¦   «         ¦  «        z  }|r|(n|)})|
rc| j        j        r1tY          ||!j-        ||)¦  «        }tY          ||!j.        ||)d	¬¦  «        }n&|!j/        d         �tY          ||!j/        ||)d	¬¦  «        }|r;| j        j        rtY          ||!j0        ||)¦  «        }ntY          ||!j1        ||)¦  «        }| |||¦  «         z  }| 2                    ¦   «         dk    }d}|                      |||j        ¬
¦  «        �°|�| 3                    ¦   «          ti          |d¦  «        r+|j5        j6        j7        dk    r|j8        |j5        j6        _8        |r_| j        j        r+ts          |||||||||                     d¦  «        ¬¦	  «	        S tu          ||||||                     d¦  «        ¬¦  «        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 candidate sequences. Assisted generation is an example of a
        candidate decoding strategy. Can be used for text-decoder, text-to-text, speech-to-text, and vision-to-text
        models.

        Parameters:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                The sequence used as a prompt for the generation.
            candidate_generator (`CandidateGenerator`):
                A derived instance of [`CandidateGenerator`] that defines how candidate sequences are generated. For
                more information, the documentation of [`CandidateGenerator`] should be read.
            logits_processor (`LogitsProcessorList`):
                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`):
                An instance of [`StoppingCriteriaList`]. List of instances of class derived from [`StoppingCriteria`]
                used to tell if the generation loop should stop.
            generation_config ([`~generation.GenerationConfig`]):
                The generation configuration to be used as parametrization of the decoding method.
            synced_gpus (`bool`):
                Whether to continue running the while loop until max_length (needed to avoid deadlocking with
                `FullyShardedDataParallel` and DeepSpeed 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.GenerateDecoderOnlyOutput`], [`~generation.GenerateEncoderDecoderOutput`] or
            `torch.LongTensor`: A `torch.LongTensor` containing the generated tokens (default behaviour) or a
            [`~generation.GenerateDecoderOnlyOutput`] if `model.config.is_encoder_decoder=False` and
            `return_dict_in_generate=True` or a [`~generation.GenerateEncoderDecoderOutput`] if
            `model.config.is_encoder_decoder=True`.
        rr   Nr  rg   rh   r   r  FTr~  r"   r�   rG  r   r:  rB  r/  r0  rŸ   rÒ  )rÉ   rL  c              3   ó6   •K  — | ]}‰d d …|d d …f         V — Œd S r­   rr   )rõ   rb  Ú
new_logitss     €rt   r*  z5GenerationMixin._assisted_decoding.<locals>.<genexpr>   s6   øè è € Ð#[Ð#[¸A J¨q¨q¨q°!°Q°Q°Q¨wÔ$7Ð#[Ð#[Ð#[Ð#[Ð#[Ð#[rs   c              3   ó6   •K  — | ]}‰d d …|d d …f         V — Œd S r­   rr   )rõ   rb  rí  s     €rt   r*  z5GenerationMixin._assisted_decoding.<locals>.<genexpr>¢  s7   øè è € Ð'fÐ'fÀqÐ(9¸!¸!¸!¸QÀÀÀ¸'Ô(BÐ'fÐ'fÐ'fÐ'fÐ'fÐ'frs   )Úis_decoder_attentionrX  Ú	heuristicr]   rÔ  rÕ  );re  r/  r0  rÖ  r×  rØ  rÃ   rÉ   rÍ   r¡   rm   r  rÔ   r  r  r¦  Úget_candidatesrR  rö  r/   r0   rA  rQ  rî   rü  rf   rà  r§   rÊ   rP  Ú_speculative_samplingrá  râ  rã  rä  rÕ   r¾  r†  rV  r]   ÚcropÚupdate_candidate_strategyrW  rp   Ú_split_model_outputsrz   ry   rg   r{   rh   r¿  rå  rÜ   rX  r  Únum_assistant_tokens_scheduleÚnum_assistant_tokensrv   rc   ),r”   r›   rl  rY  r¢  r  rc  rd  rñ   re  r/  r0  rÖ  r×  rØ  re   rç  ry   rz   r{   rw   rx   rÇ   rè  ré  rŸ  Úis_first_iterationÚcandidate_input_idsÚcandidate_logitsÚcandidate_lengthÚis_done_candidateÚcandidate_kwargsrà   rK  rb  Úvalid_tokensÚ	n_matchesrï  Úselected_tokensÚcandidate_new_tokensÚnew_cur_lenÚnewly_added_lengthrƒ  rí  s,                                             @@rt   r‡  z"GenerationMixin._assisted_decodingá  s7	  øø€ ðb &Ô/ˆ	Ø-Ô?ÐØ0ÔEÐØ)Ô7ˆØ)Ô7ˆØ"3Ô"KÐð 0ÐL°MÐL��ÈˆØ3ÐP¸ÐP�R�RÈDˆ
Ø$;Ð\Ð@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ð "ð
 (œo¨b¨q¨bÔ1Ñˆ
�GÝ$œz¨*½E¼JÈyÔO_Ð`Ñ`Ô`ÐØ×7Ò7¸ÀÔAQÐS_Ñ`Ô`ˆà"ÐØ!ÐØ×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ X	'Ø”o aÔ(ˆGð 5H×4VÒ4VÐW`Ñ4aÔ4aÑ1ÐÐ!1Ø"5×"8Ò"8¸¼Ñ"EÔ"EÐØÐ+Ø#3×#6Ò#6°t´{Ñ#CÔ#CÐ à2Ô8¸Ô;¸i¼oÈaÔ>PÑPÐØ 1Ð 1Ð2EÀtÑ LÔ LÐõ  $œy¨Ñ6Ô6ÐÝ6Ø Ð"5Ô";¸AÔ">ÀÄÔ@^ñ ô  Ðõ  7Ð7GÐI\ÔIbÐcdÔIeÑfÔfÐØÐ#3Ð3Ð3Ý5:´Yà(Ð)9Ô:Ýœ W¨gÐ8HÑ.HÐQZÔQaÕinÔisÐtÑtÔtðð ð6ñ 6ô 6Ð Ð!1Ñ2ð >˜4Ô=Ð>QÐfÐfÐUeÐfÐfˆLØ <Ð/Ð/Ø1AÀAÑ1E�Ð-Ñ.ð ×ÒÐL]Ð eÐ!4Ð6GÐ HÐ HÐceÑfÔfÐfØ×ÒÐRfÐ nÐ!7Ð9MÐ NÐ NÐlnÑoÔoÐoà�dÐ*Ð*˜\Ð*Ð*ˆGð !œ¨¨¨Ð,<Ð+<¸qÑ+@Ð+BÐ+BÐ(BÔC×FÒFÝ”m¨IÔ,<ð Gñ ô ˆJð !+× 0Ò 0Ñ 2Ô 2ÐÝÐ#Ñ$Ô$ 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Ñ'Ð'ð
 ð CÐ-Ð9Ý*?Ø'Ø$Ø$ØØ%ñ+ô +Ñ'�˜i˜ið ð @Ø&×.Ò.°2Ð.Ñ6Ô6�EÝ&+Ô&7¸¸aÀÀÀÀAÀAÀA¸g¼ÐTUÐ&VÑ&VÔ&V×&^Ò&^Ð_`Ñ&aÔ&aÐbfÐhiÐhiÐhiÐbiÔ&j�O�Oà&0×&7Ò&7¸BÐ&7Ñ&?Ô&?�Oà':¸1¸1¸1¸g¸h¸h¸;Ô'GÐ$Ø 4¸ÈÈÈÈ3ÈBÈ3ÈÔ8OÒ OÐP×XÒXÐ]_ÐXÑ`Ô`ÐcdÒd×iÒiÑkÔk�	ð %ð #¨Ð6FÒ)FÐ)FØ ‘N�IØ.¨q¨q¨q°/°IÀ±M°/Ð/AÔB�õ œ	 9¨lÐ";ÀÐDÑDÔDˆIØÐ#Ø—’˜\×-Ò-Ñ/Ô/Ñ0Ô0Ð0Ø#œ/¨!Ô,ˆKð Ô#×(Ò(¨°q©Ñ9Ô9Ð9ð  ×9Ò9¸)ÀZÐQZÑ[Ô[Ð[ð  ×CÒCØØØ#'¤;Ô#AØ(¨1™}ð	 Dñ ô ˆLð ð Ð1ð Ùð 'ñ %Ø%.°¡]Ð"Ø ð \Ø�eÐ#[Ð#[Ð#[Ð#[ÅÐGYÑAZÔAZÐ#[Ñ#[Ô#[Ñ[Ô[Ñ[�FØ ð gØ¥%Ð'fÐ'fÐ'fÐ'fÍEÐRdÑLeÔLeÐ'fÑ'fÔ'fÑ"fÔ"fÑf�Jà4FÐ%^ [ [ÐL^Ð"Ø$ð Ø”{Ô5ð Ý+?Ø,¨gÔ.FÈÐQcñ,ô ,Ð(õ .BØ.Ø#Ô6Ø#Ø.Ø15ð.ñ .ô .Ð*Ð*ð !Ô+¨AÔ.Ð:Ý-AØ.Ø#Ô.Ø#Ø.Ø15ð.ñ .ô .Ð*ð (ð Ø”{Ô5ð Ý0DØ1°7Ô3PÐRYÐ[mñ1ô 1Ð-Ð-õ 1EØ1°7Ô3HÈ'ÐSeñ1ô 1Ð-ð $8Ð;LÐ;LÈYÐX^Ñ;_Ô;_Ð:_Ñ#_Ð Ø!5×!9Ò!9Ñ!;Ô!;¸qÒ!@ÐØ!&Ððq ×,Ò,Ð-?ÀÐU^ÔUeÐ,ÑfÔfñ X	'ðt ÐØ�LŠL‰NŒNˆNõ Ð'Ð):Ñ;Ô;ð	à#Ô3ÔEÔcÐgrÒrÐrð $Ô8ð  Ô/ÔAÔVð #ð 	ØŒ{Ô-ð Ý3Ø'Ø!Ø%Ø'9Ø*?Ø'9Ø%5Ø*?Ø$0×$4Ò$4Ð5FÑ$GÔ$Gð
ñ 
ô 
ð 
õ 1Ø'Ø!Ø%Ø1Ø"7Ø$0×$4Ò$4Ð5FÑ$GÔ$Gðñ ô ð ð Ðrs   c                 óÜ  — dt           j        j        _        |j        }t          j        |d d …d d…f         |d¬¦  «        }d|vrt          d¦  «        ‚| j        }|                      ||¦  «        }|r|  	                    |j
        ¦  «        }|                     dd ¦  «        }d}	|D ]“}
|	|
j        d         z   }|�|d d …d |…f         |d<   t          j        |	|t           j        |
j        ¬¦  «        |d	<   |d	                              d¦  «        |d
<    | j        |
fi |¤Ž} |di |¤ddi¤Ž}|j        |d<   |}	Œ”||d<   |d	         dd …         dz   |d	<   |                     d
d ¦  «        }|S )Né@   rŸ   r:  r]   z+Cannot use prefill chunking without a cacher·   r   r  r�   r½   r1  Tr"   rr   )rm   Ú_dynamorÃ   Úcache_size_limitrÞ  Úsplitrû   rÑ   rb  rÝ  rZ  rÌ   r¡   rQ  rÔ   r  rO  rî   r]   )r”   r›   r  rñ   Ú
chunk_sizeÚinput_chunksrê  rë  r·   r  Úinput_chunkÚcurrent_lengthrà   rK  rè   s                  rt   rß  z!GenerationMixin._prefill_chunkingë  s×  € ð 13�ŒÔÔ-à&Ô9ˆ
õ ”{ 9¨Q¨Q¨Q°°°¨VÔ#4°jÀbÐIÑIÔIˆà LÐ0Ð0ÝÐJÑKÔKÐKàœˆà×;Ò;¸LÐJ[Ñ\Ô\ˆØð 	UØ ×2Ò2Ð3DÔ3SÑTÔTˆMà%×)Ò)Ð*:¸DÑAÔAˆàˆØ'ð 	)ð 	)ˆKØ(¨;Ô+<¸RÔ+@Ñ@ˆNàÐ)Ø1?ÀÀÀÀ?ÀNÀ?Ð@RÔ1S�Ð-Ñ.Ý-2¬\Ø˜^µ5´:ÀkÔFXð.ñ .ô .ˆLÐ)Ñ*ð ,8Ð8HÔ+I×+SÒ+SÐTUÑ+VÔ+VˆL˜Ñ(Ø=˜4Ô=¸kÐZÐZÈ\ÐZÐZˆLà#�mÐEÐE lÐEÐEÀÐEÐEÐEˆGà.5Ô.EˆLÐ*Ñ+Ø(ˆKˆKà)7ˆÐ%Ñ&Ø)5Ð6FÔ)GÈÈÈÔ)LÈqÑ)PˆÐ%Ñ&Ø×Ò˜^¨TÑ2Ô2ˆàÐrs   )NN)NNNN)NNNr­   )r"   FN)Fr"   )NNNNNNNN)NF)NNNNNNNNNNNN)Qri   rj   rk   rl   r   r   r€  r�   ÚPathLikerY  r   rš   rm   rn   rq   rp   r¢   r    r   rî   r	  Údictr   rý   r4   r   r  r5  r  r  rC  ÚstaticmethodrJ  r   rW  rA   r+   rm  r—  r¡  rV   r«  r–  rÇ  rÕ  rÞ  ræ  rë  r  r  r  Úclassmethodr(  r@  rC  rR  rb  Úno_gradÚGenerateOutputrŽ   r¦  r…  ÚGenerateNonBeamOutputr‹  ró  rõ  rú  r=  r  r  r  r"  r.  ÚGenerateBeamOutputrŽ  r%   r‘  r'   r“  r‡  rß  rr   rs   rt   rƒ   rƒ   ^  s8  € € € € € ðð ð@ LPØ,0ðA(ð A(à'/°°c¸2¼;Ð6FÔ0GÔ'HðA(ð $ Dœ>ðA(ð
 
ðA(ð A(ð A(ð A(ðF (àÔ#ð (ð   Ô 1Ô2ð (ð ! Ô!1Ô2ð	 (ð
 
ˆuÔ  %Ô"2Ð2Ô	3ð (ð  (ð  (ð  (ðD=(àÔ#ð=(ð   Ô 1Ô2ð=(ð ! Ô!1Ô2ð	=(ð
 
ˆuÔ  %Ô"2Ð2Ô	3ð=(ð =(ð =(ð =(ðD ,0Ø59Ø59Ø59ðIð IàÔ#ðIð " %œðIð ! Ô!1Ô2ð	Ið
   Ô 1Ô2ðIð ! Ô!1Ô2ðIð Ið Ið IðZ *.Ø/3Ø:>ð	A0ð A0à˜œÔ&ðA0ð ˜uœ|Ô,ðA0ð ˜t C¨¬Ð$5Ô6Ô7ð	A0ð
 
ˆuŒ|˜X cœ]¨D°°e´lÐ1BÔ,CÐCÔ	DðA0ð A0ð A0ð A0ðJ *.Ø/3Ø:>ð	`ð `à˜œÔ&ð`ð ˜uœ|Ô,ð`ð ˜t C¨¬Ð$5Ô6Ô7ð	`ð
 
Ô	ð`ð `ð `ð `ð@"à”|ð"ð ,ð"ð ˜3 ˜8”nð	"ð
 
Ô	ð"ð "ð "ð "ðH'à”|ð'ð # 3œ-ð	'ð
 ,ð'ð 
ˆc�3ˆhŒð'ð 'ð 'ð 'ð^ *.ð9/ð 9/àð9/ð ð9/ð ˜3 ¤Ð,Ô-ð	9/ð
 !&¤ð9/ð ˜œÔ&ð9/ð 
ˆuÔ  c¨5¬<Ð&7Ô!8Ð8Ô	9ð9/ð 9/ð 9/ð 9/ðv àØ#(Ø04ð 'ð  'Øð 'à ð 'ð ˜EÔ,Ô-ð 'ð
 
ˆuÔ  c¨3 h¤Ð/Ô	0ð 'ð  'ð  'ñ „\ð 'ðL $)Øð/ð /àð/ð ˜3 ˜8”nð/ð !ð	/ð
 ð/ð 
ˆc�3ˆhŒð/ð /ð /ð /ðbN#à+ðN#ð Ô#ðN#ð ”|ð	N#ð
 +ðN#ð .ðN#ð 4ðN#ð 7ðN#ð ðN#ð 
ðN#ð N#ð N#ð N#ðf /3Ø.2ØW[Ø:>Ø $Ø15Ø6:ØAEðcð cà+ðcð ' sœmðcð !Ô+ð	cð
 #+¨8°S¸%¼,Ð4GÈÈcÌÐ4RÔ+SÔ"Tðcð #Ð#6Ô7ðcð ˜”ðcð ˜t C¨ Hœ~Ô.ðcð & e¤lÔ3ðcð )1°´Ô(>ðcð 
ðcð cð cð cðR :>ð	%ð %à+ð%ð $Ð$8Ô9ð%ð Ð5Ô6ð	%ð 
ð%ð %ð %ð %ðN#àÐ/Ð1EÐEÔFð#ð Ð.Ð0DÐDÔEð#ð 
Ð"Ð$8Ð8Ô	9ð	#ð #ð #ð #ðR 04Ø!&ðx!ð x!à”<ðx!ð �e”lÔ#ðx!ð ˜uœ|Ô,ð	x!ð
 ðx!ð 
Œðx!ð x!ð x!ð x!ðtð ð ð</°4¸¸S¸´>ð /ð /ð /ð /ðb*ð *ð *ðX6!ð 6!ð 6!ðr cgða/ð a/Ø!)Ð*:Ô!;ða/ØQYÐZ^ÔQ_ða/Ørvða/à	Ð Ð%Ô	&ða/ð a/ð a/ð a/ðFð ð ð:,¨sð ,Àð ,ÐTWð ,Ðjoð ,ð ,ð ,ð ,ð\ ð
°ð 
ð 
ð 
ñ „[ð
ð$~à+ð~ð ð~ð +ð	~ð
 ð~ð ð~ð 
ð~ð ~ð ~ð ~ð@Z¨$ð Zð Zð Zð Zð 59Ø59ð	PSð PSà+ðPSð $,¨D¤>ðPSð ˜˜uœ|¨SÐ0Ô1Ô2ð	PSð PSð PSð PSðd'¸ð 'ÐRbð 'Ðgkð 'ð 'ð 'ð 'ðR €U„]�_„_ð *.Ø8<Ø:>Ø<@ØW[Ø&*Ø7;Ø-1Ø6:ØAEØ-1Ø:>ðGð Gà˜œÔ&ðGð $Ð$4Ô5ðGð #Ð#6Ô7ð	Gð
 $Ð$8Ô9ðGð #+¨8°S¸%¼,Ð4GÈÈcÌÐ4RÔ+SÔ"TðGð ˜d”^ðGð "Ð"3Ô4ðGð ˜>Ô*ðGð & e¤lÔ3ðGð )1°´Ô(>ðGð % TœNðGð " %¨¨X¨Ô"6Ô7ðGð 
ˆ~˜uÔ/Ð/Ô	0ðGð Gð Gñ „_ðGðR¸Dð Ètð Ð]bÔ]ið Ðnrð ð ð ð ð& ]aðSð SØÔ)ðSØ6>Ð?XÔ6YðSà	Ô	ðSð Sð Sð SðjBàÔ#ðBð .ðBð 0ð	Bð
 ,ðBð ðBð ˜>Ô*ðBð 
Ð$ eÔ&6Ð6Ô	7ðBð Bð Bð BðH ðH %¤,ð H°5´<ð Hð Hð Hñ „\ðHð
 ðJ E¤Lð J¸cð JÈcð JÐV[ÔVbð Jð Jð Jñ „\ðJð
 ð˜eœlð ¸%¼,ð È5Ì<ð ð ð ñ „\ðð& ð,
Ø-2¬\ð,
à"œ\ð,
ð ”\ð,
ð  œ,ð	,
ð
 ð,
ð ð,
ð  ð,
ð ˜d C˜iÔ(ð,
ð ð,
ð ,
ð ,
ñ „\ð,
ð\ ðMØ-2¬\ðMàœ,ðMð ,1¬<ðMð ˜d C˜iÔ(ð	Mð Mð Mñ „\ðMð,4Qà$œ|ð4Qð !œ<ð4Qð $œlð	4Qð
 ð4Qð  ð4Qð ð4Qð ð4Qð ð4Qð ð4Qð ð4Qð 
ˆuŒ|˜Uœ\¨5¬<Ð7Ô	8ð4Qð 4Qð 4Qð 4QðlLàœðLð !&¤ðLð $)¤<ð	Lð
 ,1¬<ðLð ðLð 
ˆuŒ|˜Uœ\¨5¬<Ð7Ô	8ðLð Lð Lð Lð,3Fà”<ð3Fð !&¤ð3Fð ”\ð	3Fð
 œð3Fð ”lð3Fð $)¤<ð3Fð .3¬\ð3Fð  œ,ð3Fð ,1¬<ð3Fð !œ<ð3Fð ð3Fð ð3Fð  ð3Fð ð3Fð  ˜d C˜iÔ(ð!3Fð" 
ˆuŒ|˜Uœ\¨5¬<¸¼ÐEÔ	Fð#3Fð 3Fð 3Fð 3FðnNàÔ#ðNð .ðNð 0ð	Nð
 ,ðNð ðNð 
Ð! 5Ô#3Ð3Ô	4ðNð Nð Nð Nð`
e1àÔ#ðe1ð  ðe1ð .ð	e1ð
 0ðe1ð ,ðe1ð ðe1ð e1ð e1ð e1ðN	n1àÔ#ðn1ð "=ðn1ð .ð	n1ð
 0ðn1ð ,ðn1ð ðn1ð 
Ð! 5Ô#3Ð3Ô	4ðn1ð n1ð n1ð n1ð`HàÔ#ðHð 0ðHð .ð	Hð
 0ðHð ,ðHð ðHð ˜>Ô*ðHð 
Ð$ eÔ&6Ð6Ô	7ðHð Hð Hð HðT*¨5Ô+;ð *ÐP`ð *ð *ð *ð *ð *ð *rs   rƒ   c                 óÊ  — | dd…| d…f         }|                      d¬¦  «        }|dd…t          j        |¦  «        |f                              dd¦  «        }|                      d¬¦  «        }|dd…t          j        |¦  «        |f                              dd¦  «        }	|	|z  }
t          j        |
¦  «        }||
k    }|                      d¬¦  «        dk                          ¦   «         }|r||k    r|dz  }|dd…d|dz   …f         }nÔ|j        d         }|dd…|dd…f         }||k     rP|dd…|dd…f         }t          j        ||z
  d¬¦  «        }| 	                    |                     ¦   «         ¦  «         n|}t          j
        |d¬¦  «                             d¦  «        ddd…f         }|dk    r%t          j        |dd…d|…f         |fd¬¦  «        }n|}||fS )a  
    Applies sampling as in the speculative decoding paper (https://huggingface.co/papers/2211.17192, algorithm 1). Returns
    the selected tokens, as well as the number of candidate matches.

    NOTE: Unless otherwise stated, the variable names match those in the paper.
    NrŸ   r:  r   r"   )ré  rÒ  )rá  rm   rQ  rã  Ú	rand_likerÕ   r¾  r¡   ÚclampÚdiv_râ  rA  )r�  r�  r‘  rƒ  r’  Únew_candidate_input_idsÚqÚq_ir(  Úp_iÚprobability_ratioÚr_iÚis_acceptedr•  r”  ÚgammaÚ
p_n_plus_1Ú
q_n_plus_1Úp_primer²  s                       rt   rˆ  rˆ    sA  € ð 2°!°!°!Ð6FÐ5FÐ5GÐ5GÐ2GÔHÐð 	× Ò  RÐ Ñ(Ô(€AØ
ˆAˆAˆA�uŒ|Ð,Ñ-Ô-Ð/FÐFÔ
G×
OÒ
OÐPQÐSTÑ
UÔ
U€CØ×Ò˜rÐÑ"Ô"€AØ
ˆAˆAˆA�uŒ|Ð,Ñ-Ô-Ð/FÐFÔ
G×
OÒ
OÐPQÐSTÑ
UÔ
U€CØ˜c™	Ðõ
 Œ/Ð+Ñ
,Ô
,€CØÐ*Ò*€KØ�,×&Ò&¨2Ð&Ñ.Ô.°Ò2×7Ò7Ñ9Ô9€Ið ð ˜YÐ*:Ò:Ð:ð 	�Q‰ˆ	Ø.¨q¨q¨q°/°IÀ±M°/Ð/AÔBˆˆð !Ô& qÔ)ˆØ�q�q�q˜) Q Q Q�Ô'ˆ
Ø�uÒÐØ˜1˜1˜1˜i¨¨¨˜?Ô+ˆJÝ”k :°
Ñ#:ÀÐCÑCÔCˆGØ�LŠL˜Ÿš™œÑ'Ô'Ð'Ð'à ˆGÝÔ˜g°1Ð5Ñ5Ô5×=Ò=¸aÑ@Ô@ÀÀqÀqÀqÀÔIˆð �qŠ=ˆ=Ý œ9Ð&=¸a¸a¸aÀÀ)À¸mÔ&LÈaÐ%PÐVXÐYÑYÔYˆLˆLàˆLà˜Ð"Ð"rs   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   rr   rŸ   .Nr"   )rÊ   r¡   rP  )	rK  Únew_outputsrè  Ú	added_lenr…  Ú	new_tupleÚlayerÚlast_dim_sizerb  s	            rt   r‹  r‹  P  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�<ÑˆˆØ€Nrs   rF  rÃ   r†   c                 óæ   ‡ ‡‡— ‰ st          d¦  «        ‚t          ‰ d         ¦  «        Št          ˆfd„‰ D ¦   «         ¦  «        st          d¦  «        ‚d„ Šˆˆ fd„‰j        D ¦   «         } ‰di |¤ŽS )z³
    Stack a list of ModelOutput objects (or its subclasses) along the batch_size dimension. The function infers the
    specific ModelOutput subclass from the list provided.
    zInput list is empty.r   c              3   ó8   •K  — | ]}t          |‰¦  «        V — Œd S r­   )r×   )rõ   ÚobjÚmodel_output_clss     €rt   r*  z&stack_model_outputs.<locals>.<genexpr>v  s.   øè è € ÐJÐJ°S�z˜#Ð/Ñ0Ô0ÐJÐJÐJÐJÐJÐJrs   z4All elements in the list should be of the same type.c           	      óÀ  ‡ — t          d„ ‰ D ¦   «         ¦  «        rdS t          ‰ d         t          j        ¦  «        rt          j        ‰ d¬¦  «        S t          ‰ d         t
          ¦  «        r—t          ‰ d         d         t
          ¦  «        r;t          ˆ fd„t          t          ‰ d         ¦  «        ¦  «        D ¦   «         ¦  «        S t          ˆ fd„t          t          ‰ d         ¦  «        ¦  «        D ¦   «         ¦  «        S t          ‰ d         t          t          f¦  «        rt          j
        ‰ ¦  «        S t          dt          ‰ d         ¦  «        › �¦  «        ‚)z5
        Reverse of `_split` function above.
        c              3   ó   K  — | ]}|d u V — Œ	d S r­   rr   )rõ   Údatas     rt   r*  z7stack_model_outputs.<locals>._concat.<locals>.<genexpr>~  s&   è è € Ð-Ð- ˆt�tˆ|Ð-Ð-Ð-Ð-Ð-Ð-rs   Nr   r:  c           
   3   óž   •‡K  — | ]FŠt          ˆˆfd „t          t          ‰d         d         ¦  «        ¦  «        D ¦   «         ¦  «        V — ŒGdS )c              3   ó`   •‡K  — | ]'Št          j        ˆˆfd „‰D ¦   «         d¬¦  «        V — Œ(dS )c                 ó,   •— g | ]}|‰         ‰         ‘ŒS rr   rr   )rõ   rÍ  rb  Újs     €€rt   rÏ  zLstack_model_outputs.<locals>._concat.<locals>.<genexpr>.<genexpr>.<listcomp>†  s!   ø€ Ð$AÐ$AÐ$A°D T¨!¤W¨Q¤ZÐ$AÐ$AÐ$Ars   r   r:  N©rm   rA  )rõ   rÊ  rÆ  rb  s    @€€rt   r*  zAstack_model_outputs.<locals>._concat.<locals>.<genexpr>.<genexpr>†  sK   øøè è € ÐjÐjÈa�%œ)Ð$AÐ$AÐ$AÐ$AÐ$A¸DÐ$AÑ$AÔ$AÀqÐIÑIÔIÐjÐjÐjÐjÐjÐjrs   r   N)rp   rP  rÊ   ©rõ   rb  rÆ  s    @€rt   r*  z7stack_model_outputs.<locals>._concat.<locals>.<genexpr>…  sw   øøè è € ð ð àõ ÐjÐjÐjÐjÐjÕSXÕY\Ð]aÐbcÔ]dÐefÔ]gÑYhÔYhÑSiÔSiÐjÑjÔjÑjÔjðð ð ð ð ð rs   c              3   ó^   •‡K  — | ]&Št          j        ˆfd „‰D ¦   «         d¬¦  «        V — Œ'dS )c                 ó    •— g | ]
}|‰         ‘ŒS rr   rr   )rõ   rÍ  rb  s     €rt   rÏ  zBstack_model_outputs.<locals>._concat.<locals>.<genexpr>.<listcomp>Š  s   ø€ Ð'AÐ'AÐ'A°D¨¨Q¬Ð'AÐ'AÐ'Ars   r   r:  NrË  rÌ  s    @€rt   r*  z7stack_model_outputs.<locals>._concat.<locals>.<genexpr>Š  sH   øøè è € ÐgÐgÈa�UœYÐ'AÐ'AÐ'AÐ'A¸DÐ'AÑ'AÔ'AÀqÐIÑIÔIÐgÐgÐgÐgÐgÐgrs   zUnexpected attribute type: )r  r×   rm   r	  rA  rp   rP  rÊ   r  r=  rH  Ú	TypeErrorrj  )rÆ  s   `rt   Ú_concatz$stack_model_outputs.<locals>._concatz  s]  ø€ õ Ð-Ð-¨Ð-Ñ-Ô-Ñ-Ô-ð 	Ø�4Ý�d˜1”g�uœ|Ñ,Ô,ð 	KÝ”9˜T qÐ)Ñ)Ô)Ð)Ý˜˜Qœ¥Ñ'Ô'ð 	Kå˜$˜qœ' !œ*¥eÑ,Ô,ð hÝð ð ð ð å"¥3 t¨A¤w¡<¤<Ñ0Ô0ðñ ô ñ ô ð õ
 ÐgÐgÐgÐgÕSXÕY\Ð]aÐbcÔ]dÑYeÔYeÑSfÔSfÐgÑgÔgÑgÔgÐgÝ˜˜Qœ¥#¥u Ñ.Ô.ð 	Kå”< Ñ%Ô%Ð%åÐI½$¸tÀA¼w¹-¼-ÐIÐIÑJÔJÐJrs   c                 óB   •‡— i | ]Š‰ ‰ˆfd „‰D ¦   «         ¦  «        “ŒS )c                 ó0   •— g | ]}t          |‰¦  «        ‘ŒS rr   )rÚ   )rõ   Úmodel_outputrö   s     €rt   rÏ  z2stack_model_outputs.<locals>.<dictcomp>.<listcomp>“  s#   ø€ ÐOÐOÐO°•G˜L¨!Ñ,Ô,ÐOÐOÐOrs   rr   )rõ   rö   rÐ  rF  s    @€€rt   rù   z'stack_model_outputs.<locals>.<dictcomp>’  sK   øø€ ð ð ð àð 	
ˆ7ˆ7ÐOÐOÐOÐOÀÐOÑOÔOÑPÔPðð ð rs   rr   )rû   rj  r?  Ú__dataclass_fields__)rF  rÃ   Úconcatenated_datarÐ  rÃ  s   `  @@rt   Ústack_model_outputsrÖ  j  sÇ   øøø€ ð
 ð 1ÝÐ/Ñ0Ô0Ð0õ ˜M¨!Ô,Ñ-Ô-Ðõ ÐJÐJÐJÐJ¸MÐJÑJÔJÑJÔJð QÝÐOÑPÔPÐPðKð Kð Kð0ð ð ð ð à!Ô6ðñ ô Ðð ÐÐ0Ð0Ð/Ð0Ð0Ð0rs   )F)–rö  rÏ   r�   rˆ  Údataclassesr   Útypingr   r   r   r   r   rm   Útorch.distributedÚdistributedr‚  Úhuggingface_hubr	   Ú	packagingr
   r   Úcache_utilsr   r   r   r   r   Úconfiguration_utilsr   Údynamic_module_utilsr   r   r   r   Úintegrations.deepspeedr   Úintegrations.fsdpr   Úmasking_utilsr   Úpytorch_utilsr   Útokenization_utilsr   Úutilsr   r   r   r   r    r!   Úbeam_constraintsr#   r$   Úbeam_searchr%   r&   r'   rl  r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   Úcontinuous_batchingr6   Úlogits_processr7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   r¢  rQ   rR   rS   rT   rU   rV   rW   Úmodeling_utilsrX   Útokenization_utils_baserY   Ú	streamersrZ   Ú
get_loggerri   r¯  Úaccelerate.hooksr[   r\   rN  rc   rv   r}   r�   ÚGreedySearchDecoderOnlyOutputÚ"ContrastiveSearchDecoderOnlyOutputÚSampleDecoderOnlyOutputÚ%ContrastiveSearchEncoderDecoderOutputÚ GreedySearchEncoderDecoderOutputÚSampleEncoderDecoderOutputÚBeamSearchDecoderOnlyOutputÚBeamSampleDecoderOnlyOutputÚBeamSearchEncoderDecoderOutputÚBeamSampleEncoderDecoderOutputÚGreedySearchOutputÚSampleOutputÚBeamSearchOutputÚBeamSampleOutputÚContrastiveSearchOutputr©  rª  r¨  rƒ   rˆ  r‹  r—  rÖ  rr   rs   rt   ú<module>rþ     sW  ðð  €€€Ø €€€Ø 	€	€	€	Ø €€€Ø !Ð !Ð !Ð !Ð !Ð !Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @à €€€Ø  Ð  Ð  Ð  Ð  Ð  Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð 3Ð 2Ð 2Ð 2Ð 2Ð 2ðð ð ð ð ð ð ð ð ð ð ð ð @Ð ?Ð ?Ð ?Ð ?Ð ?Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø -Ð -Ð -Ð -Ð -Ð -Ø /Ð /Ð /Ð /Ð /Ð /ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð GÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ Rð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ðð ð ð ð ð ð ð ð ð ð ð ð ð ð 1Ð 0Ð 0Ð 0Ð 0Ð 0ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð8ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð (Ø0Ð0Ð0Ð0Ð0Ð0ØAÐAÐAÐAÐAÐAØ'Ð'Ð'Ð'Ð'Ð'à	ˆÔ	˜HÑ	%Ô	%€àÐÑÔð FØEÐEÐEÐEÐEÐEÐEÐEðð ð €ð ð Mð  Mð  Mð  Mð  M ñ  Mô  Mñ „ð MðF ð,Mð ,Mð ,Mð ,Mð ,M ;ñ ,Mô ,Mñ „ð,Mð^ ð(Mð (Mð (Mð (Mð (M Kñ (Mô (Mñ „ð(MðV ð5Mð 5Mð 5Mð 5Mð 5M {ñ 5Mô 5Mñ „ð5Mðt !:Ð Ø%>Ð "Ø3Ð à(DÐ %Ø#?Ð  Ø9Ð à;Ð Ø;Ð à!AÐ Ø!AÐ àÐ;Ð=ZÐZÔ[Ð ØÐ/Ð1HÐHÔI€ØÐ7Ð9TÐTÔUÐ ØÐ7Ð9TÐTÔUÐ ØÐ EÐGiÐ iÔjÐ ð Ð7Ð9UÐUÔVÐ ØÐ8Ð:ZÐZÔ[Ð ØÐ,Ð.@Ð@ÔA€ðw>ð w>ð w>ð w>ð w>�oñ w>ô w>ð w>ðt}5#ð 5#ð 5#ðpð ð ð ð4.1 t¨KÔ'8ð .1ÐBRð .1ÐWbð .1ð .1ð .1ð .1ð .1ð .1rs   