Ë
    S^(hJ! ã                   ó   — d Z ddlZddlZddlZddlZddlmZmZmZm	Z	 ddl
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 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"m#Z# ddl$m%Z%m&Z& ddl'm(Z(  e"jR                  e*«      Z+dZ,dZ-de
j\                  de/de/fd„Z0 G d„ dejb                  «      Z2 G d„ dejb                  «      Z3 G d„ dejh                  «      Z5de5iZ6 G d„ dejh                  «      Z7 G d „ d!ejh                  «      Z8 G d"„ d#e«      Z9d$Z:d%Z;d&Z< G d'„ d(e9«      Z= G d)„ d*e9«      Z> e d+e:«       G d,„ d-e9«      «       Z? e d.e:«       G d/„ d0e9e«      «       Z@ G d1„ d2e9«      ZA G d3„ d4e9e«      ZBg d5¢ZCy)6zPyTorch Blenderbot model.é    N)ÚListÚOptionalÚTupleÚUnion)Únn)ÚCrossEntropyLossé   )ÚACT2FN)ÚGenerationMixin)Ú_prepare_4d_attention_maskÚ!_prepare_4d_causal_attention_mask)ÚBaseModelOutputÚ)BaseModelOutputWithPastAndCrossAttentionsÚ!CausalLMOutputWithCrossAttentionsÚSeq2SeqLMOutputÚSeq2SeqModelOutput)ÚPreTrainedModel)Úadd_end_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )Ú'BlenderbotSmallForConditionalGenerationÚBlenderbotSmallModelé   )ÚBlenderbotConfigr   z facebook/blenderbot-400M-distillÚ	input_idsÚpad_token_idÚdecoder_start_token_idc                 óÖ   — | j                  | j                  «      }| dd…dd…f   j                  «       |dd…dd…f<   ||dd…df<   |€t        d«      ‚|j	                  |dk(  |«       |S )z1
    Shift input ids one token to the right.
    Néÿÿÿÿr   r   z1self.model.config.pad_token_id has to be defined.iœÿÿÿ)Ú	new_zerosÚshapeÚcloneÚ
ValueErrorÚmasked_fill_)r   r   r    Úshifted_input_idss       úp/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/blenderbot/modeling_blenderbot.pyÚshift_tokens_rightr*   9   s}   € ð "×+Ñ+¨I¯O©OÓ<ÐØ(ª¨C¨R¨C¨Ñ0×6Ñ6Ó8Ð’a˜™�eÑØ4Ð’a˜�dÑàÐÜÐLÓMÐMà×"Ñ"Ð#4¸Ñ#<¸lÔKàÐó    c                   óV   ‡ — e Zd ZdZdedefˆ fd„Zddej                  defˆ fd„Zˆ xZ	S )	Ú$BlenderbotLearnedPositionalEmbeddingzN
    This module learns positional embeddings up to a fixed maximum size.
    Únum_embeddingsÚembedding_dimc                 ó&   •— t         ‰| �  ||«       y ©N)ÚsuperÚ__init__)Úselfr.   r/   Ú	__class__s      €r)   r3   z-BlenderbotLearnedPositionalEmbedding.__init__N   s   ø€ Ü‰Ñ˜¨Õ7r+   Úinput_ids_shapeÚpast_key_values_lengthc                 ó®   •— |dd \  }}t        j                  |||z   t         j                  | j                  j                  ¬«      }t
        ‰| �  |«      S )z3`input_ids_shape` is expected to be [bsz x seqlen].Nr   )ÚdtypeÚdevice)ÚtorchÚarangeÚlongÚweightr:   r2   Úforward)r4   r6   r7   ÚbszÚseq_lenÚ	positionsr5   s         €r)   r?   z,BlenderbotLearnedPositionalEmbedding.forwardQ   sR   ø€ à& r¨Ð*‰ˆˆWÜ—L‘LØ"Ð$:¸WÑ$DÌEÏJÉJÐ_c×_jÑ_j×_qÑ_qô
ˆ	ô ‰w‰˜yÓ)Ð)r+   )r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr3   r;   ÚSizer?   Ú__classcell__©r5   s   @r)   r-   r-   I   s7   ø„ ñð8 sð 8¸3õ 8ñ* u§z¡zð *È3÷ *ñ *r+   r-   c            
       ó`   ‡ — e Zd ZdZd	dedededee   fˆ fd„Zdej                  fˆ fd„Z
ˆ xZS )
ÚBlenderbotScaledWordEmbeddingz\
    This module overrides nn.Embeddings' forward by multiplying with embeddings scale.
    r.   r/   Úpadding_idxÚembed_scalec                 ó6   •— t         ‰| �  |||«       || _        y r1   )r2   r3   rN   )r4   r.   r/   rM   rN   r5   s        €r)   r3   z&BlenderbotScaledWordEmbedding.__init__`   s   ø€ Ü‰Ñ˜¨¸ÔDØ&ˆÕr+   r   c                 ó<   •— t         ‰| �  |«      | j                  z  S r1   )r2   r?   rN   )r4   r   r5   s     €r)   r?   z%BlenderbotScaledWordEmbedding.forwardd   s   ø€ Ü‰w‰˜yÓ)¨D×,<Ñ,<Ñ<Ð<r+   )ç      ð?)rC   rD   rE   rF   rG   r   Úfloatr3   r;   ÚTensorr?   rI   rJ   s   @r)   rL   rL   [   sE   ø„ ññ' sð '¸3ð 'ÈSð 'Ð_gÐhmÑ_nõ 'ð= §¡÷ =ñ =r+   rL   c                   ó†  ‡ — e Zd ZdZ	 	 	 	 	 ddededededededee   fˆ fd	„Z	d
e
j                  dedefd„Z	 	 	 	 	 dde
j                  dee
j                     deee
j                        dee
j                     dee
j                     dedee
j                  ee
j                     eee
j                        f   fd„Zˆ xZS )ÚBlenderbotAttentionz=Multi-headed attention from 'Attention Is All You Need' paperÚ	embed_dimÚ	num_headsÚdropoutÚ
is_decoderÚbiasÚ	is_causalÚconfigc                 ó
  •— t         ‰| �  «        || _        || _        || _        ||z  | _        || _        | j
                  |z  | j                  k7  rt        d| j                  › d|› d�«      ‚| j
                  dz  | _        || _	        || _
        t        j                  |||¬«      | _        t        j                  |||¬«      | _        t        j                  |||¬«      | _        t        j                  |||¬«      | _        y )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).g      à¿©rZ   )r2   r3   rV   rW   rX   Úhead_dimr\   r&   ÚscalingrY   r[   r   ÚLinearÚk_projÚv_projÚq_projÚout_proj)	r4   rV   rW   rX   rY   rZ   r[   r\   r5   s	           €r)   r3   zBlenderbotAttention.__init__l   sä   ø€ ô 	‰ÑÔØ"ˆŒØ"ˆŒØˆŒØ! YÑ.ˆŒØˆŒà�M‰M˜IÑ%¨$¯.©.Ò8ÜØMÈdÏnÉnÐM]Ø$ Y K¨rð3óð ð —}‘} dÑ*ˆŒØ$ˆŒØ"ˆŒä—i‘i 	¨9¸4Ô@ˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜŸ	™	 )¨Y¸TÔBˆ�r+   ÚtensorrA   r@   c                 óŽ   — |j                  ||| j                  | j                  «      j                  dd«      j	                  «       S )Nr   r   )ÚviewrW   r_   Ú	transposeÚ
contiguous)r4   rf   rA   r@   s       r)   Ú_shapezBlenderbotAttention._shape‹   s7   € Ø�{‰{˜3 ¨¯©¸¿¹ÓG×QÑQÐRSÐUVÓW×bÑbÓdÐdr+   Úhidden_statesÚkey_value_statesÚpast_key_valueÚattention_maskÚlayer_head_maskÚoutput_attentionsÚreturnc                 ó
  — |du}|j                  «       \  }}	}
| j                  |«      | j                  z  }|r0|�.|d   j                  d   |j                  d   k(  r|d   }|d   }�n
|rE| j	                  | j                  |«      d|«      }| j	                  | j                  |«      d|«      }nÃ|�}| j	                  | j                  |«      d|«      }| j	                  | j                  |«      d|«      }t        j                  |d   |gd¬«      }t        j                  |d   |gd¬«      }nD| j	                  | j                  |«      d|«      }| j	                  | j                  |«      d|«      }| j                  r||f}|| j                  z  d| j                  f} | j	                  ||	|«      j                  |Ž } |j                  |Ž } |j                  |Ž }|j                  d«      }t        j                  ||j                  dd«      «      }|j                  «       || j                  z  |	|fk7  r/t!        d|| j                  z  |	|f› d|j                  «       › �«      ‚|�{|j                  «       |d|	|fk7  r#t!        d	|d|	|f› d|j                  «       › �«      ‚|j                  || j                  |	|«      |z   }|j                  || j                  z  |	|«      }t"        j$                  j'                  |d¬«      }|�›|j                  «       | j                  fk7  r*t!        d
| j                  f› d|j                  «       › �«      ‚|j                  dddd«      |j                  || j                  |	|«      z  }|j                  || j                  z  |	|«      }|r?|j                  || j                  |	|«      }|j                  || j                  z  |	|«      }nd}t"        j$                  j)                  || j(                  | j*                  ¬«      }t        j                  ||«      }|j                  «       || j                  z  |	| j                  fk7  r9t!        d|| j                  z  |	| j                  f› d|j                  «       › �«      ‚|j                  || j                  |	| j                  «      }|j                  dd«      }|j                  ||	| j,                  «      }| j/                  |«      }|||fS )z#Input shape: Batch x Time x ChannelNr   r   r   r"   ©Údimz$Attention weights should be of size z	, but is z!Attention mask should be of size z/Head mask for a single layer should be of size ©ÚpÚtrainingz `attn_output` should be of size )Úsizerd   r`   r$   rk   rb   rc   r;   ÚcatrY   rW   r_   rh   ÚreshapeÚbmmri   r&   r   Ú
functionalÚsoftmaxrX   rx   rV   re   )r4   rl   rm   rn   ro   rp   rq   Úis_cross_attentionr@   Útgt_lenÚ_Úquery_statesÚ
key_statesÚvalue_statesÚ
proj_shapeÚsrc_lenÚattn_weightsÚattn_weights_reshapedÚ
attn_probsÚattn_outputs                       r)   r?   zBlenderbotAttention.forwardŽ   s  € ð .°TÐ9Ðà'×,Ñ,Ó.‰ˆˆW�að —{‘{ =Ó1°D·L±LÑ@ˆñ ØÐ*Ø˜qÑ!×'Ñ'¨Ñ*Ð.>×.DÑ.DÀQÑ.GÒGð (¨Ñ*ˆJØ)¨!Ñ,ŠLÙàŸ™ T§[¡[Ð1AÓ%BÀBÈÓLˆJØŸ;™; t§{¡{Ð3CÓ'DÀbÈ#ÓN‰LØÐ'àŸ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLÜŸ™ N°1Ñ$5°zÐ#BÈÔJˆJÜ Ÿ9™9 n°QÑ&7¸Ð%FÈAÔN‰Lð Ÿ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLà�?Š?ð )¨,Ð7ˆNà˜DŸN™NÑ*¨B°·±Ð>ˆ
ØC�t—{‘{ <°¸#Ó>×CÑCÀZÐPˆØ'�Z×'Ñ'¨Ð4ˆ
Ø+�|×+Ñ+¨ZÐ8ˆà—/‘/ !Ó$ˆÜ—y‘y ¨z×/CÑ/CÀAÀqÓ/IÓJˆà×ÑÓ 3¨¯©Ñ#7¸À'Ð"JÒJÜØ6¸¸d¿n¹nÑ8LÈgÐW^Ð7_Ð6`ð aØ ×%Ñ%Ó'Ð(ð*óð ð
 Ð%Ø×"Ñ"Ó$¨¨a°¸'Ð(BÒBÜ Ø7¸¸aÀÈ'Ð8RÐ7SÐS\Ð]k×]pÑ]pÓ]rÐ\sÐtóð ð (×,Ñ,¨S°$·.±.À'È7ÓSÐVdÑdˆLØ'×,Ñ,¨S°4·>±>Ñ-AÀ7ÈGÓTˆLä—}‘}×,Ñ,¨\¸rÐ,ÓBˆàÐ&Ø×#Ñ#Ó%¨$¯.©.Ð):Ò:Ü ØEÀtÇ~Á~ÐFWÐEXð YØ'×,Ñ,Ó.Ð/ð1óð ð +×/Ñ/°°2°q¸!Ó<¸|×?PÑ?PÐQTÐVZ×VdÑVdÐfmÐovÓ?wÑwˆLØ'×,Ñ,¨S°4·>±>Ñ-AÀ7ÈGÓTˆLáð
 %1×$5Ñ$5°c¸4¿>¹>È7ÐT[Ó$\Ð!Ø0×5Ñ5°c¸D¿N¹NÑ6JÈGÐU\Ó]‰Là$(Ð!ä—]‘]×*Ñ*¨<¸4¿<¹<ÐRV×R_ÑR_Ð*Ó`ˆ
ä—i‘i 
¨LÓ9ˆà×ÑÓ #¨¯©Ñ"6¸ÀÇÁÐ!OÒOÜØ2°C¸$¿.¹.Ñ4HÈ'ÐSW×S`ÑS`Ð3aÐ2bð cØ×$Ñ$Ó&Ð'ð)óð ð
 "×&Ñ& s¨D¯N©N¸GÀTÇ]Á]ÓSˆØ!×+Ñ+¨A¨qÓ1ˆð "×)Ñ)¨#¨w¸¿¹ÓGˆà—m‘m KÓ0ˆàÐ1°>ÐAÐAr+   )ç        FTFN)NNNNF)rC   rD   rE   rF   rG   rR   Úboolr   r   r3   r;   rS   rk   r   r?   rI   rJ   s   @r)   rU   rU   i   sN  ø„ ÙGð Ø ØØØ-1ñCàðCð ðCð ð	Cð
 ðCð ðCð ðCð Ð)Ñ*õCð>e˜UŸ\™\ð e°Cð e¸có eð 48Ø8<Ø15Ø26Ø"'ñvBà—|‘|ðvBð # 5§<¡<Ñ0ðvBð !  u§|¡|Ñ!4Ñ5ð	vBð
 ! §¡Ñ.ðvBð " %§,¡,Ñ/ðvBð  ðvBð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷vBr+   rU   Úeagerc                   ó”   ‡ — e Zd Zdefˆ fd„Z	 d	dej                  dej                  dej                  dedej                  f
d„Zˆ xZ	S )
ÚBlenderbotEncoderLayerr\   c                 ó‚  •— t         ‰| �  «        |j                  | _        t	        |j
                     | j                  |j                  |j                  |¬«      | _        t        j                  | j                  «      | _        |j                  | _        t        |j                     | _        |j                   | _        t        j"                  | j                  |j$                  «      | _        t        j"                  |j$                  | j                  «      | _        t        j                  | j                  «      | _        y )N)rV   rW   rX   r\   )r2   r3   Úd_modelrV   ÚBLENDERBOT_ATTENTION_CLASSESÚ_attn_implementationÚencoder_attention_headsÚattention_dropoutÚ	self_attnr   Ú	LayerNormÚself_attn_layer_normrX   r
   Úactivation_functionÚactivation_fnÚactivation_dropoutra   Úencoder_ffn_dimÚfc1Úfc2Úfinal_layer_norm©r4   r\   r5   s     €r)   r3   zBlenderbotEncoderLayer.__init__  sÜ   ø€ Ü‰ÑÔØŸ™ˆŒä5°f×6QÑ6QÑRØ—n‘nØ×4Ñ4Ø×,Ñ,Øô	
ˆŒô %'§L¡L°·±Ó$@ˆÔ!Ø—~‘~ˆŒÜ# F×$>Ñ$>Ñ?ˆÔØ"(×";Ñ";ˆÔÜ—9‘9˜TŸ^™^¨V×-CÑ-CÓDˆŒÜ—9‘9˜V×3Ñ3°T·^±^ÓDˆŒÜ "§¡¨T¯^©^Ó <ˆÕr+   rl   ro   rp   rq   rr   c                 ó  — |}| j                  |«      }| j                  ||||¬«      \  }}}t        j                  j	                  || j                  | j
                  ¬«      }||z   }|}| j                  |«      }| j                  | j                  |«      «      }t        j                  j	                  || j                  | j
                  ¬«      }| j                  |«      }t        j                  j	                  || j                  | j
                  ¬«      }||z   }|j                  t        j                  k(  rEt        j                  |j                  «      j                  dz
  }t        j                   || |¬«      }|f}	|r|	|fz  }	|	S )a§  
        Args:
            hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
            attention_mask (`torch.FloatTensor`): attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
                `(encoder_attention_heads,)`.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        )rl   ro   rp   rq   rv   iè  )ÚminÚmax)r˜   r–   r   r}   rX   rx   rŸ   rš   r�   r›   rž   r9   r;   Úfloat16Úfinfor£   Úclamp)
r4   rl   ro   rp   rq   Úresidualr‡   r�   Úclamp_valueÚoutputss
             r)   r?   zBlenderbotEncoderLayer.forward  sf  € ð$ !ˆØ×1Ñ1°-Ó@ˆØ)-¯©Ø'Ø)Ø+Ø/ð	 *8ó *
Ñ&ˆ�| Qô Ÿ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆà ˆØ×-Ñ-¨mÓ<ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆÜŸ™×-Ñ-¨m¸t×?VÑ?VÐae×anÑanÐ-ÓoˆØŸ™ Ó/ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆà×Ñ¤%§-¡-Ò/ÜŸ+™+ m×&9Ñ&9Ó:×>Ñ>ÀÑEˆKÜ!ŸK™K¨¸K¸<È[ÔYˆMà Ð"ˆáØ˜�Ñ&ˆGàˆr+   )F)
rC   rD   rE   r   r3   r;   rS   rŒ   r?   rI   rJ   s   @r)   r�   r�     sZ   ø„ ð=Ð/õ =ð. #(ñ.à—|‘|ð.ð Ÿ™ð.ð Ÿ™ð	.ð
  ð.ð 
�‰÷.r+   r�   c                   ó<  ‡ — e Zd Zdefˆ fd„Z	 	 	 	 	 	 	 	 ddej                  deej                     deej                     deej                     deej                     deej                     d	eeej                        d
ee	   dee	   dej                  fd„Z
ˆ xZS )ÚBlenderbotDecoderLayerr\   c                 óN  •— t         ‰| �  «        |j                  | _        t	        |j
                     | j                  |j                  |j                  dd|¬«      | _        |j                  | _	        t        |j                     | _        |j                  | _        t        j                  | j                  «      | _        t	        |j
                     | j                  |j                  |j                  d|¬«      | _        t        j                  | j                  «      | _        t        j&                  | j                  |j(                  «      | _        t        j&                  |j(                  | j                  «      | _        t        j                  | j                  «      | _        y )NT)rV   rW   rX   rY   r[   r\   )rX   rY   r\   )r2   r3   r‘   rV   r’   r“   Údecoder_attention_headsr•   r–   rX   r
   r™   rš   r›   r   r—   r˜   Úencoder_attnÚencoder_attn_layer_normra   Údecoder_ffn_dimr�   rž   rŸ   r    s     €r)   r3   zBlenderbotDecoderLayer.__init__Q  s0  ø€ Ü‰ÑÔØŸ™ˆŒä5°f×6QÑ6QÑRØ—n‘nØ×4Ñ4Ø×,Ñ,ØØØô
ˆŒð —~‘~ˆŒÜ# F×$>Ñ$>Ñ?ˆÔØ"(×";Ñ";ˆÔä$&§L¡L°·±Ó$@ˆÔ!Ü8¸×9TÑ9TÑUØ�N‰NØ×*Ñ*Ø×,Ñ,ØØô
ˆÔô (*§|¡|°D·N±NÓ'CˆÔ$Ü—9‘9˜TŸ^™^¨V×-CÑ-CÓDˆŒÜ—9‘9˜V×3Ñ3°T·^±^ÓDˆŒÜ "§¡¨T¯^©^Ó <ˆÕr+   rl   ro   Úencoder_hidden_statesÚencoder_attention_maskrp   Úcross_attn_layer_head_maskrn   rq   Ú	use_cacherr   c
                 ót  — |}
| j                  |«      }|�|dd nd}| j                  |||||¬«      \  }}}t        j                  j	                  || j                  | j
                  ¬«      }|
|z   }d}d}|�w|}
| j                  |«      }|�|dd nd}| j                  ||||||¬«      \  }}}t        j                  j	                  || j                  | j
                  ¬«      }|
|z   }||z   }|}
| j                  |«      }| j                  | j                  |«      «      }t        j                  j	                  || j                  | j
                  ¬«      }| j                  |«      }t        j                  j	                  || j                  | j
                  ¬«      }|
|z   }|f}|r|||fz  }|	r||fz  }|S )a  
        Args:
            hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
            attention_mask (`torch.FloatTensor`): attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            encoder_hidden_states (`torch.FloatTensor`):
                cross attention input to the layer of shape `(batch, seq_len, embed_dim)`
            encoder_attention_mask (`torch.FloatTensor`): encoder attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
                `(encoder_attention_heads,)`.
            cross_attn_layer_head_mask (`torch.FloatTensor`): mask for cross-attention heads in a given layer of
                size `(decoder_attention_heads,)`.
            past_key_value (`Tuple(torch.FloatTensor)`): cached past key and value projection states
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        Nr   )rl   rn   ro   rp   rq   rv   éþÿÿÿ)rl   rm   ro   rp   rn   rq   )r˜   r–   r   r}   rX   rx   r¯   r®   rŸ   rš   r�   r›   rž   )r4   rl   ro   r±   r²   rp   r³   rn   rq   r´   r§   Úself_attn_past_key_valueÚself_attn_weightsÚpresent_key_valueÚcross_attn_present_key_valueÚcross_attn_weightsÚcross_attn_past_key_valuer©   s                     r)   r?   zBlenderbotDecoderLayer.forwardn  s  € ð< !ˆØ×1Ñ1°-Ó@ˆð :HÐ9S >°"°1Ñ#5ÐY]Ð à>B¿n¹nØ'Ø3Ø)Ø+Ø/ð ?Mó ?
Ñ;ˆÐ(Ð*;ô Ÿ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆð (,Ð$Ø!ÐØ Ð,Ø$ˆHØ ×8Ñ8¸ÓGˆMð @NÐ?Y¨°r°sÑ(;Ð_cÐ%ØNR×N_ÑN_Ø+Ø!6Ø5Ø :Ø8Ø"3ð O`ó OÑKˆMÐ-Ð/Kô ŸM™M×1Ñ1°-À4Ç<Á<ÐZ^×ZgÑZgÐ1ÓhˆMØ$ }Ñ4ˆMð !2Ð4PÑ PÐð !ˆØ×-Ñ-¨mÓ<ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆÜŸ™×-Ñ-¨m¸t×?VÑ?VÐae×anÑanÐ-ÓoˆØŸ™ Ó/ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆà Ð"ˆáØÐ)Ð+=Ð>Ñ>ˆGáØÐ)Ð+Ñ+ˆGàˆr+   )NNNNNNFT)rC   rD   rE   r   r3   r;   rS   r   r   rŒ   r?   rI   rJ   s   @r)   r«   r«   P  sè   ø„ ð=Ð/õ =ð@ 26Ø8<Ø9=Ø26Ø=AØ8<Ø,1Ø$(ñWà—|‘|ðWð ! §¡Ñ.ðWð  (¨¯©Ñ5ð	Wð
 !)¨¯©Ñ 6ðWð " %§,¡,Ñ/ðWð %-¨U¯\©\Ñ$:ðWð !  u§|¡|Ñ!4Ñ5ðWð $ D™>ðWð ˜D‘>ðWð 
�‰÷Wr+   r«   c                   ó.   — e Zd ZeZdZdZd„ Zed„ «       Z	y)ÚBlenderbotPreTrainedModelÚmodelTc                 ó  — | j                   j                  }t        |t        j                  «      rY|j
                  j                  j                  d|¬«       |j                  �%|j                  j                  j                  «        y y t        |t        j                  «      rf|j
                  j                  j                  d|¬«       |j                  �2|j
                  j                  |j                     j                  «        y y y )Nr‹   )ÚmeanÚstd)r\   Úinit_stdÚ
isinstancer   ra   r>   ÚdataÚnormal_rZ   Úzero_Ú	EmbeddingrM   )r4   ÚmodulerÂ   s      r)   Ú_init_weightsz'BlenderbotPreTrainedModel._init_weightsÍ  sÃ   € Ø�k‰k×"Ñ"ˆÜ�fœbŸi™iÔ(Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ð .r+   c                 ó°   — | j                   j                  }t        j                  g d¢dddd|gg| j                  ¬«      }|j                  |«      ||dœ}|S )N)r   é   é
   é   r   r   é   é   r   ©r:   )ro   r   Údecoder_input_ids)r\   r   r;   rf   r:   Úne)r4   Ú	pad_tokenr   Údummy_inputss       r)   rÕ   z&BlenderbotPreTrainedModel.dummy_inputsØ  sZ   € à—K‘K×,Ñ,ˆ	Ü—L‘LÒ"2°Q¸¸2¸qÀ)Ð4LÐ!MÐVZ×VaÑVaÔbˆ	à'Ÿl™l¨9Ó5Ø"Ø!*ñ
ˆð
 Ðr+   N)
rC   rD   rE   r   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingrÊ   ÚpropertyrÕ   © r+   r)   r¾   r¾   È  s,   „ Ø#€LØÐØ&*Ð#ò	?ð ñó ñr+   r¾   aO  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`BlenderbotConfig`]):
            Model configuration class with all the parameters of the model. Initializing with a config file does not
            load the weights associated with the model, only the configuration. Check out the
            [`~PreTrainedModel.from_pretrained`] method to load the model weights.
a„  
    Conversation example:

    ```python
    >>> from transformers import AutoTokenizer, BlenderbotForConditionalGeneration

    >>> mname = "facebook/blenderbot-400M-distill"
    >>> model = BlenderbotForConditionalGeneration.from_pretrained(mname)
    >>> tokenizer = AutoTokenizer.from_pretrained(mname)
    >>> UTTERANCE = "My friends are cool but they eat too many carbs."
    >>> print("Human: ", UTTERANCE)
    Human:  My friends are cool but they eat too many carbs.

    >>> inputs = tokenizer([UTTERANCE], return_tensors="pt")
    >>> reply_ids = model.generate(**inputs)
    >>> print("Bot: ", tokenizer.batch_decode(reply_ids, skip_special_tokens=True)[0])
    Bot: That's unfortunate. Are they trying to lose weight or are they just trying to be healthier?

    >>> REPLY = "I'm not sure"
    >>> print("Human: ", REPLY)
    Human: I'm not sure

    >>> NEXT_UTTERANCE = (
    ...     "My friends are cool but they eat too many carbs.</s> <s>That's unfortunate. "
    ...     "Are they trying to lose weight or are they just trying to be healthier?</s> "
    ...     "<s> I'm not sure."
    ... )
    >>> inputs = tokenizer([NEXT_UTTERANCE], return_tensors="pt")
    >>> next_reply_ids = model.generate(**inputs)
    >>> print("Bot: ", tokenizer.batch_decode(next_reply_ids, skip_special_tokens=True)[0])
    Bot:   I see. Well, it's good that they're trying to change their eating habits.
    ```
al  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
            it.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

            [What are attention masks?](../glossary#attention-mask)
        decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are decoder input IDs?](../glossary#decoder-input-ids)

            Blenderbot uses the `bos_token_id` as the starting token for `decoder_input_ids` generation. If
            `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
            `past_key_values`).
        decoder_attention_mask (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
            be used by default.
        head_mask (`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
            Mask to nullify selected heads of the attention modules in the encoder. Mask values selected in `[0, 1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        decoder_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
            Mask to nullify selected heads of the attention modules in the decoder. Mask values selected in `[0, 1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        cross_attn_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
            Mask to nullify selected heads of the cross-attention modules in the decoder. Mask values selected in `[0,
            1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        encoder_outputs (`tuple(tuple(torch.FloatTensor)`, *optional*):
            Tuple consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*: `attentions`)
            `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) is a sequence of
            hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
        past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
            Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
            `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of shape
            `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.

            Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
            blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.

            If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
            don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
            `decoder_input_ids` of shape `(batch_size, sequence_length)`.
        inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
            This is useful if you want more control over how to convert `input_ids` indices into associated vectors
            than the model's internal embedding lookup matrix.
        decoder_inputs_embeds (`torch.FloatTensor` of shape `(batch_size, target_sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `decoder_input_ids` you can choose to directly pass an embedded
            representation. If `past_key_values` is used, optionally only the last `decoder_inputs_embeds` have to be
            input (see `past_key_values`). This is useful if you want more control over how to convert
            `decoder_input_ids` indices into associated vectors than the model's internal embedding lookup matrix.

            If `decoder_input_ids` and `decoder_inputs_embeds` are both unset, `decoder_inputs_embeds` takes the value
            of `inputs_embeds`.
        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
c                   ó^   ‡ — e Zd ZdZddedeej                     fˆ fd„Z	 	 	 	 	 	 	 dd„Z	ˆ xZ
S )ÚBlenderbotEncoderzì
    Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a
    [`BlenderbotEncoderLayer`].

    Args:
        config: BlenderbotConfig
        embed_tokens (nn.Embedding): output embedding
    r\   Úembed_tokensc                 ó¬  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j
                  }|j                  | _        |j                  | _	        |j                  rt        j                  |«      nd}|�|| _        n(t        |j                  || j                  |¬«      | _        t!        |j                  |«      | _        t%        j&                  t)        |j*                  «      D �cg c]  }t-        |«      ‘Œ c}«      | _        t%        j0                  |j
                  «      | _        d| _        | j7                  «        y c c}w ©NrQ   ©rN   F)r2   r3   rX   Úencoder_layerdropÚ	layerdropr‘   r   rM   Úmax_position_embeddingsÚmax_source_positionsÚscale_embeddingÚmathÚsqrtrÝ   rL   Ú
vocab_sizer-   Úembed_positionsr   Ú
ModuleListÚrangeÚencoder_layersr�   Úlayersr—   Ú
layer_normÚgradient_checkpointingÚ	post_init)r4   r\   rÝ   rV   rN   r�   r5   s         €r)   r3   zBlenderbotEncoder.__init__{  s  ø€ Ü‰Ñ˜Ô à—~‘~ˆŒØ×1Ñ1ˆŒà—N‘Nˆ	Ø!×.Ñ.ˆÔØ$*×$BÑ$BˆÔ!Ø.4×.DÒ.D”d—i‘i 	Ô*È#ˆàÐ#Ø ,ˆDÕä =Ø×!Ñ! 9¨d×.>Ñ.>ÈKô!ˆDÔô  DØ×*Ñ*Øó 
ˆÔô —m‘mÌUÐSY×ShÑShÓMiÖ$jÈÔ%;¸FÕ%CÒ$jÓkˆŒÜŸ,™, v§~¡~Ó6ˆŒà&+ˆÔ#à�‰Õùò %ks   Ã7Ec                 ó8  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|�|�t	        d«      ‚|�8| j                  ||«       |j                  «       }|j                  d|d   «      }n!|�|j                  «       dd }nt	        d«      ‚|€| j                  |«      }| j                  |«      }	||	z   }
t        j                  j                  |
| j                  | j                  ¬«      }
|�t        ||j                  «      }|rdnd}|rdnd}|�_|j                  «       d   t!        | j"                  «      k7  r6t	        dt!        | j"                  «      › d	|j                  «       d   › d
�«      ‚t%        | j"                  «      D ]©  \  }}|r||
fz   }d}| j                  r&t'        j(                  g «      }|| j*                  k  rd}|rd}nW| j,                  r3| j                  r'| j/                  |j0                  |
||�||   nd|«      }n ||
||�||   nd|¬«      }|d   }
|sŒ¡||d   fz   }Œ« | j3                  |
«      }
|r||
fz   }|st5        d„ |
||fD «       «      S t7        |
||¬«      S )a~  
        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
                provide it.

                Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
                [`PreTrainedTokenizer.__call__`] for details.

                [What are input IDs?](../glossary#input-ids)
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            head_mask (`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
                This is useful if you want more control over how to convert `input_ids` indices into associated vectors
                than the model's internal embedding lookup matrix.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more detail.
            return_dict (`bool`, *optional*):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        NzDYou cannot specify both input_ids and inputs_embeds at the same timer"   z5You have to specify either input_ids or inputs_embedsrv   rÚ   r   z&The head_mask should be specified for ú layers, but it is for ú.FT)NN)rp   rq   r   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wr1   rÚ   ©Ú.0Úvs     r)   ú	<genexpr>z,BlenderbotEncoder.forward.<locals>.<genexpr>  s   è ø€ Òe˜qÐWXÑWdœÑeùs   ‚Š©Úlast_hidden_staterl   Ú
attentions)r\   rq   Úoutput_hidden_statesÚuse_return_dictr&   Ú%warn_if_padding_and_no_attention_maskry   rh   rÝ   ré   r   r}   rX   rx   r   r9   Úlenrí   Ú	enumerater;   Úrandrâ   rï   Ú_gradient_checkpointing_funcÚ__call__rî   Útupler   )r4   r   ro   Ú	head_maskÚinputs_embedsrq   rü   Úreturn_dictÚinput_shapeÚ	embed_posrl   Úencoder_statesÚall_attentionsÚidxÚencoder_layerÚto_dropÚdropout_probabilityÚlayer_outputss                     r)   r?   zBlenderbotEncoder.forward˜  sç  € ð\ 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð  ]Ð%>ÜÐcÓdÐdØÐ"Ø×6Ñ6°yÀ.ÔQØ#Ÿ.™.Ó*ˆKØ!Ÿ™ r¨;°r©?Ó;‰IØÐ&Ø'×,Ñ,Ó.¨s°Ð3‰KäÐTÓUÐUàÐ Ø ×-Ñ-¨iÓ8ˆMà×(Ñ(¨Ó5ˆ	à%¨	Ñ1ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-Ódˆð Ð%ä7¸È×H[ÑH[Ó\ˆNá3™¸ˆÙ0™°dˆð Ð Ø�~‰~Ó Ñ"¤c¨$¯+©+Ó&6Ò6Ü Ø<¼SÀÇÁÓ=MÐ<Nð OØ!Ÿ™Ó(¨Ñ+Ð,¨Að/óð ô #,¨D¯K©KÓ"8ò  	FÑˆC�Ù#Ø!/°=Ð2BÑ!B�àˆGØ�}Š}Ü&+§j¡j°£nÐ#Ø&¨¯©Ò7Ø"�GáØ ,‘à×.Ò.°4·=²=Ø$(×$EÑ$EØ%×.Ñ.Ø%Ø&Ø+4Ð+@˜ 3šÀdØ)ó%‘Mñ %2Ø%Ø&Ø;DÐ;P¨°3ªÐVZØ*;ô	%�Mð !.¨aÑ 0�â Ø!/°=ÀÑ3CÐ2EÑ!E‘ðA 	FðF Ÿ™¨Ó6ˆáØ+¨}Ð.>Ñ>ˆNáÜÑe ]°NÀNÐ$SÔeÓeÐeÜØ+¸>ÐVdô
ð 	
r+   r1   )NNNNNNN)rC   rD   rE   rF   r   r   r   rÈ   r3   r?   rI   rJ   s   @r)   rÜ   rÜ   q  sB   ø„ ññÐ/ð ¸xÈÏÉÑ?Uõ ð> ØØØØØ!Ø÷C
r+   rÜ   c                   ót   ‡ — e Zd ZdZddedeej                     fˆ fd„Zd„ Z	d„ Z
	 	 	 	 	 	 	 	 	 	 	 	 d	d„Zˆ xZS )
ÚBlenderbotDecoderzØ
    Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`BlenderbotDecoderLayer`]

    Args:
        config: BlenderbotConfig
        embed_tokens (nn.Embedding): output embedding
    r\   rÝ   c                 óÐ  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j
                  | _        |j                  | _        |j                  rt        j                  |j                  «      nd}|�|| _        n2t        |j                  |j                  | j                  |¬«      | _        t!        |j                  |j                  «      | _        t%        j&                  t)        |j*                  «      D �cg c]  }t-        |«      ‘Œ c}«      | _        t%        j0                  |j                  «      | _        d| _        | j7                  «        y c c}w rß   )r2   r3   rX   Údecoder_layerdroprâ   r   rM   rã   Úmax_target_positionsrå   ræ   rç   r‘   rÝ   rL   rè   r-   ré   r   rê   rë   Údecoder_layersr«   rí   r—   rî   rï   rð   )r4   r\   rÝ   rN   r�   r5   s        €r)   r3   zBlenderbotDecoder.__init__'  s  ø€ Ü‰Ñ˜Ô Ø—~‘~ˆŒØ×1Ñ1ˆŒØ!×.Ñ.ˆÔØ$*×$BÑ$BˆÔ!Ø39×3IÒ3I”d—i‘i §¡Ô/ÈsˆàÐ#Ø ,ˆDÕä =Ø×!Ñ! 6§>¡>°4×3CÑ3CÐQ\ô!ˆDÔô  DØ×*Ñ*Ø�N‰Nó 
ˆÔô —m‘mÌUÐSY×ShÑShÓMiÖ$jÈÔ%;¸FÕ%CÒ$jÓkˆŒÜŸ,™, v§~¡~Ó6ˆŒà&+ˆÔ#à�‰Õùò %ks   Ä	E#c                 ó   — | j                   S r1   ©rÝ   ©r4   s    r)   Úget_input_embeddingsz&BlenderbotDecoder.get_input_embeddingsA  s   € Ø× Ñ Ð r+   c                 ó   — || _         y r1   r  ©r4   Úvalues     r)   Úset_input_embeddingsz&BlenderbotDecoder.set_input_embeddingsD  s
   € Ø!ˆÕr+   c                 óØ  — |
�|
n| j                   j                  }
|�|n| j                   j                  }|	�|	n| j                   j                  }	|�|n| j                   j                  }|�|�t        d«      ‚|�&|j                  «       }|j                  d|d   «      }n!|�|j                  «       dd }nt        d«      ‚|�|d   d   j                  d   nd}|€| j                  |«      }t        ||||«      }|�|�t        ||j                  |d   ¬«      }| j                  ||«      }||z   }t        j                  j!                  || j                   | j"                  ¬«      }| j$                  r%| j"                  r|	rt&        j)                  d	«       d
}	|rdnd}|
rdnd}|
r|�dnd}|	rdnd}t+        ||gddg«      D ]j  \  }}|€Œ	|j                  «       d   t-        | j.                  «      k7  sŒ3t        d|› dt-        | j.                  «      › d|j                  «       d   › d�«      ‚ t1        | j.                  «      D ]Ý  \  }}|r||fz  }| j"                  r%t3        j4                  g «      }|| j6                  k  rŒ?|�||   nd}| j$                  r?| j"                  r3| j9                  |j:                  |||||�||   nd|�||   ndd|
|	«
      }n ||||||�||   nd|�||   nd||
|	¬«	      }|d   }|	r|||
rdnd   fz  }|
sŒÉ||d   fz  }|€ŒÕ||d   fz  }Œß | j=                  |«      }|r||fz  }|	r|nd}|st?        d„ |||||fD «       «      S tA        |||||¬«      S )a*  
        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
                provide it.

                Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
                [`PreTrainedTokenizer.__call__`] for details.

                [What are input IDs?](../glossary#input-ids)
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, encoder_sequence_length, hidden_size)`, *optional*):
                Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention
                of the decoder.
            encoder_attention_mask (`torch.LongTensor` of shape `(batch_size, encoder_sequence_length)`, *optional*):
                Mask to avoid performing cross-attention on padding tokens indices of encoder input_ids. Mask values
                selected in `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            head_mask (`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules in the encoder. Mask values selected in `[0,
                1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            cross_attn_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the cross-attention modules in the decoder to avoid performing
                cross-attention on hidden heads. Mask values selected in `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
                Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
                shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of
                shape `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.

                Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
                cross-attention blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.

                If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those
                that don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of
                all `decoder_input_ids` of shape `(batch_size, sequence_length)`.
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
                This is useful if you want more control over how to convert `input_ids` indices into associated vectors
                than the model's internal embedding lookup matrix.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more detail.
            return_dict (`bool`, *optional*):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        NzTYou cannot specify both decoder_input_ids and decoder_inputs_embeds at the same timer"   zEYou have to specify either decoder_input_ids or decoder_inputs_embedsr   r   )r€   rv   zZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...FrÚ   r  Úcross_attn_head_maskzThe `z` should be specified for rò   ró   )ro   r±   r²   rp   r³   rn   rq   r´   r	   r   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr1   rÚ   rõ   s     r)   rø   z,BlenderbotDecoder.forward.<locals>.<genexpr>  s   è ø€ ò àØ�=ô ñùs   ‚)rú   Úpast_key_valuesrl   rû   Úcross_attentions)!r\   rq   rü   r´   rý   r&   ry   rh   r$   rÝ   r   r   r9   ré   r   r}   rX   rx   rï   ÚloggerÚwarningÚziprÿ   rí   r   r;   r  râ   r  r  rî   r  r   )r4   r   ro   r±   r²   r  r   r"  r  r´   rq   rü   r  r  r7   rB   rl   Úall_hidden_statesÚall_self_attnsÚall_cross_attentionsÚnext_decoder_cacheÚ	attn_maskÚ	mask_namer  Údecoder_layerr  rn   r  Ú
next_caches                                r)   r?   zBlenderbotDecoder.forwardG  sH  € ðb 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð  ]Ð%>ÜÐsÓtÐtØÐ"Ø#Ÿ.™.Ó*ˆKØ!Ÿ™ r¨;°r©?Ó;‰IØÐ&Ø'×,Ñ,Ó.¨s°Ð3‰KäÐdÓeÐeð DSÐC^ °Ñ!3°AÑ!6×!<Ñ!<¸QÒ!?ÐdeÐàÐ Ø ×-Ñ-¨iÓ8ˆMä:Ø˜K¨Ð8Nó
ˆð
 !Ð,Ð1GÐ1Sä%?Ø&¨×(;Ñ(;À[ÐQSÁ_ô&Ð"ð
 ×(Ñ(¨Ð6LÓMˆ	à%¨	Ñ1ˆäŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-Ódˆà×&Ò&¨4¯=ª=ÙÜ—‘Øpôð "�	á"6™B¸DÐÙ0™°dˆÙ&7Ð<QÐ<]™rÐdhÐÙ#,™R°$Ðô %(¨Ð4HÐ(IÈKÐYoÐKpÓ$qò 	Ñ ˆI�yØÑ$Ø—>‘>Ó# AÑ&¬#¨d¯k©kÓ*:Ó:Ü$Ø 	˜{Ð*DÄSÈÏÉÓEUÐDVð WØ%ŸN™NÓ,¨QÑ/Ð0°ð3óð ð	ô #,¨D¯K©KÓ"8ò /	@ÑˆC�á#Ø! mÐ%5Ñ5Ð!Ø�}Š}Ü&+§j¡j°£nÐ#Ø&¨¯©Ò7Øà5DÐ5P˜_¨SÒ1ÐVZˆNà×*Ò*¨t¯}ª}Ø $× AÑ AØ!×*Ñ*Ø!Ø"Ø)Ø*Ø&/Ð&;�I˜c’NÀØ1EÐ1QÐ(¨Ò-ÐW[ØØ%Øó!‘ñ !.Ø!Ø#1Ø*?Ø+AØ7@Ð7L Y¨s¢^ÐRVà5IÐ5UÐ,¨SÒ1Ð[_à#1Ø&7Ø'ô!�ð *¨!Ñ,ˆMáØ" }Ñ:K±QÐQRÑ'SÐ&UÑUÐ"â Ø =°Ñ#3Ð"5Ñ5�à(Ñ4Ø(¨]¸1Ñ-=Ð,?Ñ?Ñ(ð_/	@ðd Ÿ™¨Ó6ˆñ  Ø -Ð!1Ñ1Ðá+4Ñ'¸$ˆ
ÙÜñ à'¨Ð5FÈÐXlÐmôó ð ô
 9Ø+Ø&Ø+Ø%Ø1ô
ð 	
r+   r1   )NNNNNNNNNNNN)rC   rD   rE   rF   r   r   r   rÈ   r3   r  r  r?   rI   rJ   s   @r)   r  r    s[   ø„ ññÐ/ð ¸xÈÏÉÑ?Uõ ò4!ò"ð
 ØØ"Ø#ØØ!ØØØØØ!Ø÷T
r+   r  zXThe bare Blenderbot Model outputting raw hidden-states without any specific head on top.c            %       óp  ‡ — e Zd ZddgZdefˆ fd„Zedeee	e
j                  f      fˆ fd„«       Zd„ Zd„ Zd	„ Zd
„ Z ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej.                     deej0                     deej.                     deej.                     deej0                     deej0                     deej0                     deeeef      deeej8                        deej0                     deej8                     dee   dee   dee   dee   deeej8                     ef   f d„«       «       Zˆ xZS )ÚBlenderbotModelúdecoder.embed_tokens.weightúencoder.embed_tokens.weightr\   c                 óv  •— t         ‰| �  |«       |j                  |j                  }}|j                  rt        j                  |j                  «      nd}t        ||j                  ||¬«      | _	        t        || j                  «      | _        t        || j                  «      | _        | j                  «        y )NrQ   rà   )r2   r3   r   rè   rå   ræ   rç   r‘   rL   ÚsharedrÜ   Úencoderr  Údecoderrð   )r4   r\   rM   rè   rN   r5   s        €r)   r3   zBlenderbotModel.__init__%  s‰   ø€ Ü‰Ñ˜Ô à"(×"5Ñ"5°v×7HÑ7H�ZˆØ39×3IÒ3I”d—i‘i §¡Ô/ÈsˆÜ3°JÀÇÁÐP[ÐitÔuˆŒÜ(¨°·±Ó=ˆŒÜ(¨°·±Ó=ˆŒð 	�‰Õr+   Úpretrained_model_name_or_pathc                 óš   •— |dk(  r/t        j                  dt        «       t        j                  |«      S t        t        | �  |g|¢­i |¤ŽS )Núfacebook/blenderbot-90MzàThe checkpoint `facebook/blenderbot-90M` is deprecated. In the future, please use the identical checkpoint `facebook/small_blenderbot-90M` with `BlenderbotSmallModel.from_pretrained('facebook/small_blenderbot-90M')` instead.)ÚwarningsÚwarnÚFutureWarningr   Úfrom_pretrainedr2   r0  ©Úclsr7  Ú
model_argsÚkwargsr5   s       €r)   r=  zBlenderbotModel.from_pretrained1  sV   ø€ à(Ð,EÒEÜ�M‰Mðdô ô	ô (×7Ñ7Ð8UÓVÐVä”_ cÑ:Ð;XÐpÐ[eÒpÐioÑpÐpr+   c                 ó   — | j                   S r1   )r4  r  s    r)   r  z$BlenderbotModel.get_input_embeddings>  s   € Ø�{‰{Ðr+   c                 ó~   — || _         | j                   | j                  _        | j                   | j                  _        y r1   )r4  r5  rÝ   r6  r  s     r)   r  z$BlenderbotModel.set_input_embeddingsA  s)   € ØˆŒØ$(§K¡Kˆ�‰Ô!Ø$(§K¡Kˆ�‰Õ!r+   c                 ó   — | j                   S r1   )r5  r  s    r)   Úget_encoderzBlenderbotModel.get_encoderF  ó   € Ø�|‰|Ðr+   c                 ó   — | j                   S r1   ©r6  r  s    r)   Úget_decoderzBlenderbotModel.get_decoderI  rF  r+   ©Úoutput_typerÖ   r   ro   rÒ   Údecoder_attention_maskr  Údecoder_head_maskr   Úencoder_outputsr"  r  Údecoder_inputs_embedsr´   rq   rü   r  rr   c                 ó®  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|€| j                  ||||
|||¬«      }nI|rGt        |t        «      s7t        |d   t        |«      dkD  r|d   ndt        |«      dkD  r|d   nd¬«      }| j                  |||d   ||||	|||||¬«      }|s||z   S t        |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  ¬«      S )	aò  
        Returns:

        Example:

        ```python
        >>> from transformers import AutoTokenizer, BlenderbotModel

        >>> model = BlenderbotModel.from_pretrained("facebook/blenderbot-400M-distill")
        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-400M-distill")

        >>> inputs = tokenizer("Studies have been shown that owning a dog is good for you", return_tensors="pt")
        >>> decoder_input_ids = tokenizer("Studies show that", return_tensors="pt").input_ids  # Batch size 1
        >>> outputs = model(input_ids=inputs.input_ids, decoder_input_ids=decoder_input_ids)

        >>> last_hidden_states = outputs.last_hidden_state
        >>> list(last_hidden_states.shape)
        [1, 6, 1280]
        ```N)r   ro   r  r  rq   rü   r  r   r   r   rù   ©r   ro   r±   r²   r  r   r"  r  r´   rq   rü   r  )rú   r"  Údecoder_hidden_statesÚdecoder_attentionsr#  Úencoder_last_hidden_stater±   Úencoder_attentions)r\   rq   rü   r´   rý   r5  rÄ   r   rÿ   r6  r   rú   r"  rl   rû   r#  )r4   r   ro   rÒ   rL  r  rM  r   rN  r"  r  rO  r´   rq   rü   r  Údecoder_outputss                    r)   r?   zBlenderbotModel.forwardL  s‡  € ðN 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐ"Ø"Ÿl™lØ#Ø-Ø#Ø+Ø"3Ø%9Ø'ð +ó ‰Oñ ¤¨O¼_Ô!MÜ-Ø"1°!Ñ"4Ü47¸Ó4HÈ1Ò4L˜o¨aÒ0ÐRVÜ14°_Ó1EÈÒ1I˜?¨1Ò-ÈtôˆOð Ÿ,™,Ø'Ø1Ø"1°!Ñ"4Ø#1Ø'Ø!5Ø+Ø/ØØ/Ø!5Ø#ð 'ó 
ˆñ Ø" _Ñ4Ð4ä!Ø-×?Ñ?Ø+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô	
ð 		
r+   )NNNNNNNNNNNNNNN) rC   rD   rE   Ú_tied_weights_keysr   r3   Úclassmethodr   r   ÚstrÚosÚPathLiker=  r  r  rE  rI  r   ÚBLENDERBOT_INPUTS_DOCSTRINGr   r   Ú_CONFIG_FOR_DOCr;   Ú
LongTensorrS   r   r   r   ÚFloatTensorrŒ   r?   rI   rJ   s   @r)   r0  r0    s  ø„ ð
 8Ð9VÐWÐð
Ð/õ 
ð ð
q¸HÀUÈ3ÐPR×P[ÑP[ÐK[ÑE\Ñ<]ô 
qó ð
qòò0ò
òñ +Ð+FÓGÙÐ+=ÈOÔ\ð 15Ø15Ø8<Ø=AØ,0Ø48Ø7;ØCGØ=AØ04Ø=AØ$(Ø,0Ø/3Ø&*ñ!Z
à˜E×,Ñ,Ñ-ðZ
ð ! §¡Ñ.ðZ
ð $ E×$4Ñ$4Ñ5ð	Z
ð
 !)¨×)9Ñ)9Ñ :ðZ
ð ˜EŸL™LÑ)ðZ
ð $ E§L¡LÑ1ðZ
ð ' u§|¡|Ñ4ðZ
ð " %¨¨Ð(>Ñ"?Ñ@ðZ
ð " $ u×'8Ñ'8Ñ"9Ñ:ðZ
ð   §¡Ñ-ðZ
ð  (¨×(9Ñ(9Ñ:ðZ
ð ˜D‘>ðZ
ð $ D™>ðZ
ð ' t™nðZ
ð  ˜d‘^ð!Z
ð" 
ˆu�U×&Ñ&Ñ'Ð);Ð;Ñ	<ò#Z
ó ]ó HôZ
r+   r0  zRThe Blenderbot Model with a language modeling head. Can be used for summarization.c            (       ó
  ‡ — e Zd ZdZdgZg d¢Zdefˆ fd„Zede	e
eej                  f      fˆ fd„«       Zd„ Zd	„ Z	 d&dede	e   dedej(                  fˆ fd„Zdedd
fd„Zd„ Zd„ Z ee«       eee¬«       ee«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d'de	e jB                     de	e jD                     de	e jB                     de	e jB                     de	e jD                     de	e jD                     de	e jD                     de	e
e#e$f      de	e%e jL                        de	e jD                     de	e jL                     de	e jB                     d e	e   d!e	e   d"e	e   d#e	e   de
e#e jL                     ef   f"d$„«       «       «       Z'e(d%„ «       Z)ˆ xZ*S )(Ú"BlenderbotForConditionalGenerationr¿   Úfinal_logits_bias)r1  r2  úlm_head.weightr\   c                 óx  •— t         ‰| �  |«       t        |«      | _        | j	                  dt        j                  d| j                  j                  j                  f«      «       t        j                  |j                  | j                  j                  j                  d¬«      | _        | j                  «        y )Nrb  r   Fr^   )r2   r3   r0  r¿   Úregister_bufferr;   Úzerosr4  r.   r   ra   r‘   Úlm_headrð   r    s     €r)   r3   z+BlenderbotForConditionalGeneration.__init__³  s€   ø€ Ü‰Ñ˜Ô Ü$ VÓ,ˆŒ
Ø×ÑÐ0´%·+±+¸qÀ$Ç*Á*×BSÑBS×BbÑBbÐ>cÓ2dÔeÜ—y‘y §¡°·±×1BÑ1B×1QÑ1QÐX]Ô^ˆŒð 	�‰Õr+   r7  c                 óš   •— |dk(  r/t        j                  dt        «       t        j                  |«      S t        t        | �  |g|¢­i |¤ŽS )Nr9  zóThe checkpoint `facebook/blenderbot-90M` is deprecated. In the future, please use the identical checkpoint `facebook/small_blenderbot-90M` with `BlenderbotSmallForConditionalGeneration.from_pretrained('facebook/small_blenderbot-90M')` instead.)r:  r;  r<  r   r=  r2   ra  r>  s       €r)   r=  z2BlenderbotForConditionalGeneration.from_pretrained¼  s_   ø€ à(Ð,EÒEÜ�M‰Mðwô ô	ô ;×JÑJÐKhÓiÐiäÔ7¸ÑMØ)ð
Ø,6ò
Ø:@ñ
ð 	
r+   c                 ó6   — | j                   j                  «       S r1   )r¿   rE  r  s    r)   rE  z.BlenderbotForConditionalGeneration.get_encoderË  ó   € Ø�z‰z×%Ñ%Ó'Ð'r+   c                 ó6   — | j                   j                  «       S r1   )r¿   rI  r  s    r)   rI  z.BlenderbotForConditionalGeneration.get_decoderÎ  rj  r+   NÚnew_num_tokensÚpad_to_multiple_ofÚmean_resizingrr   c                 óz   •— t         ‰| �  |||«      }| j                  |j                  j                  d   «       |S )Nr   )r2   Úresize_token_embeddingsÚ_resize_final_logits_biasr>   r$   )r4   rl  rm  rn  Únew_embeddingsr5   s        €r)   rp  z:BlenderbotForConditionalGeneration.resize_token_embeddingsÑ  s?   ø€ ô ™Ñ8¸ÐI[Ð]jÓkˆØ×&Ñ& ~×'<Ñ'<×'BÑ'BÀ1Ñ'EÔFØÐr+   c                 ó6  — | j                   j                  d   }||k  r| j                   d d …d |…f   }nSt        j                  d||z
  f| j                   j                  ¬«      }t        j
                  | j                   |gd¬«      }| j                  d|«       y )Nr"   r   rÑ   rt   rb  )rb  r$   r;   rf  r:   rz   re  )r4   rl  Úold_num_tokensÚnew_biasÚ
extra_biass        r)   rq  z<BlenderbotForConditionalGeneration._resize_final_logits_biasØ  sŒ   € Ø×/Ñ/×5Ñ5°bÑ9ˆØ˜^Ò+Ø×-Ñ-ªa°°.°Ð.@ÑA‰HäŸ™ a¨¸.Ñ)HÐ%IÐRV×RhÑRh×RoÑRoÔpˆJÜ—y‘y $×"8Ñ"8¸*Ð!EÈ1ÔMˆHØ×ÑÐ0°(Õ;r+   c                 ó   — | j                   S r1   ©rg  r  s    r)   Úget_output_embeddingsz8BlenderbotForConditionalGeneration.get_output_embeddingsá  rF  r+   c                 ó   — || _         y r1   rx  ©r4   rr  s     r)   Úset_output_embeddingsz8BlenderbotForConditionalGeneration.set_output_embeddingsä  ó	   € Ø%ˆ�r+   rJ  r   ro   rÒ   rL  r  rM  r   rN  r"  r  rO  Úlabelsr´   rq   rü   r  c                 óÒ  — |�|n| j                   j                  }|�R|rt        j                  d«       d}|€7|€5t	        || j                   j
                  | j                   j                  «      }| j                  |||||||||	|
|||||¬«      }| j                  |d   «      | j                  z   }d}|�Ft        «       } ||j                  d| j                   j                  «      |j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                   |j"                  |j$                  |j&                  |j(                  ¬«	      S )	a¿  
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
            config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
            (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.

        Returns:
        NzJThe `use_cache` argument is changed to `False` since `labels` is provided.F)ro   rÒ   rN  rL  r  rM  r   r"  r  rO  r´   rq   rü   r  r   r"   r   )	ÚlossÚlogitsr"  rR  rS  r#  rT  r±   rU  )r\   rý   r$  r%  r*   r   r    r¿   rg  rb  r   rh   rè   r   r"  rR  rS  r#  rT  r±   rU  )r4   r   ro   rÒ   rL  r  rM  r   rN  r"  r  rO  r~  r´   rq   rü   r  r©   Ú	lm_logitsÚmasked_lm_lossÚloss_fctÚoutputs                         r)   r?   z*BlenderbotForConditionalGeneration.forwardç  s‰  € ð< &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐÙÜ—‘ÐkÔlØˆIØ Ð(Ð-BÐ-JÜ$6Ø˜DŸK™K×4Ñ4°d·k±k×6XÑ6Xó%Ð!ð —*‘*ØØ)Ø/Ø+Ø#9ØØ/Ø!5Ø+Ø'Ø"7ØØ/Ø!5Ø#ð ó 
ˆð" —L‘L ¨¡Ó,¨t×/EÑ/EÑEˆ	àˆØÐÜ'Ó)ˆHÙ% i§n¡n°R¸¿¹×9OÑ9OÓ&PÐRX×R]ÑR]Ð^`ÓRaÓbˆNáØ�\ G¨A¨B KÑ/ˆFØ3AÐ3M�^Ð%¨Ñ.ÐYÐSYÐYäØØØ#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô

ð 
	
r+   c                 ó\   ‡— d}| D ]#  }|t        ˆfd„|d d D «       «      |dd  z   fz  }Œ% |S )NrÚ   c              3   ót   •K  — | ]/  }|j                  d ‰j                  |j                  «      «      –— Œ1 y­w©r   N©Úindex_selectÚtor:   ©rö   Ú
past_stateÚbeam_idxs     €r)   rø   zDBlenderbotForConditionalGeneration._reorder_cache.<locals>.<genexpr>>  s.   øè ø€ ÒrÐU_�j×-Ñ-¨a°·±¸Z×=NÑ=NÓ1O×PÑrùó   ƒ58r   ©r  ©r"  rŽ  Úreordered_pastÚ
layer_pasts    `  r)   Ú_reorder_cachez1BlenderbotForConditionalGeneration._reorder_cache8  sT   ø€ àˆØ)ò 	ˆJàÜÓrÐcmÐnpÐopÐcqÔrÓrØ˜Q˜R�.ñ!ðñ ‰Nð	ð Ðr+   )NT)NNNNNNNNNNNNNNNN)+rC   rD   rE   r×   Ú_keys_to_ignore_on_load_missingrW  r   r3   rX  r   r   rY  rZ  r[  r=  rE  rI  rG   rŒ   r   rÈ   rp  rq  ry  r|  r   r\  r   r   r]  r   ÚBLENDERBOT_GENERATION_EXAMPLEr;   r^  rS   r   r   r   r_  r?   Ústaticmethodr”  rI   rJ   s   @r)   ra  ra  «  s–  ø„ ð  ÐØ':Ð&;Ð#ÚiÐðÐ/õ ð ð
¸HÀUÈ3ÐPR×P[ÑP[ÐK[ÑE\Ñ<]ô 
ó ð
ò(ò(ð dhñØ!ðØ7?À±}ðØ\`ðà	�‰õð<¸ð <Àó <òò&ñ +Ð+FÓGÙ¨?ÈÔYÙÐ5Ó6ð 15Ø15Ø8<Ø=AØ,0Ø48Ø7;ØCGØ=AØ04Ø=AØ-1Ø$(Ø,0Ø/3Ø&*ñ#L
à˜E×,Ñ,Ñ-ðL
ð ! §¡Ñ.ðL
ð $ E×$4Ñ$4Ñ5ð	L
ð
 !)¨×)9Ñ)9Ñ :ðL
ð ˜EŸL™LÑ)ðL
ð $ E§L¡LÑ1ðL
ð ' u§|¡|Ñ4ðL
ð " %¨¨Ð(>Ñ"?Ñ@ðL
ð " $ u×'8Ñ'8Ñ"9Ñ:ðL
ð   §¡Ñ-ðL
ð  (¨×(9Ñ(9Ñ:ðL
ð ˜×)Ñ)Ñ*ðL
ð ˜D‘>ðL
ð $ D™>ðL
ð  ' t™nð!L
ð" ˜d‘^ð#L
ð$ 
ˆu�U×&Ñ&Ñ'¨Ð8Ñ	9ò%L
ó 7ó Zó HðL
ð\ ñó ôr+   ra  c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )ÚBlenderbotDecoderWrapperz½
    This wrapper class is a helper class to correctly load pretrained checkpoints when the causal language model is
    used in combination with the [`EncoderDecoderModel`] framework.
    c                 óD   •— t         ‰| �  |«       t        |«      | _        y r1   )r2   r3   r  r6  r    s     €r)   r3   z!BlenderbotDecoderWrapper.__init__K  s   ø€ Ü‰Ñ˜Ô Ü(¨Ó0ˆ�r+   c                 ó&   —  | j                   |i |¤ŽS r1   rH  )r4   ÚargsrA  s      r)   r?   z BlenderbotDecoderWrapper.forwardO  s   € Øˆt�|‰|˜TÐ, VÑ,Ð,r+   )rC   rD   rE   rF   r3   r?   rI   rJ   s   @r)   r™  r™  E  s   ø„ ñô
1ö-r+   r™  c                    óà  ‡ — e Zd ZdgZˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
 eee¬	«      	 	 	 	 	 	 	 	 	 	 	 	 	 dd
eej                      deej"                     deej$                     deej$                     deej"                     deej"                     deeej$                        deej$                     deej                      dee   dee   dee   dee   deeef   fd„«       Zed„ «       Zˆ xZS )ÚBlenderbotForCausalLMrc  c                 ó  •— t        j                  |«      }d|_        d|_        t        ‰| �  |«       t        |«      | _        t        j                  |j                  |j                  d¬«      | _        | j                  «        y )NTFr^   )ÚcopyÚdeepcopyrY   Úis_encoder_decoderr2   r3   r™  r¿   r   ra   Úhidden_sizerè   rg  rð   r    s     €r)   r3   zBlenderbotForCausalLM.__init__W  sf   ø€ Ü—‘˜vÓ&ˆØ ˆÔØ$)ˆÔ!Ü‰Ñ˜Ô Ü-¨fÓ5ˆŒ
ä—y‘y ×!3Ñ!3°V×5FÑ5FÈUÔSˆŒð 	�‰Õr+   c                 óB   — | j                   j                  j                  S r1   ©r¿   r6  rÝ   r  s    r)   r  z*BlenderbotForCausalLM.get_input_embeddingsc  s   € Ø�z‰z×!Ñ!×.Ñ.Ð.r+   c                 ó:   — || j                   j                  _        y r1   r¥  r  s     r)   r  z*BlenderbotForCausalLM.set_input_embeddingsf  s   € Ø*/ˆ�
‰
×ÑÕ'r+   c                 ó   — | j                   S r1   rx  r  s    r)   ry  z+BlenderbotForCausalLM.get_output_embeddingsi  rF  r+   c                 ó   — || _         y r1   rx  r{  s     r)   r|  z+BlenderbotForCausalLM.set_output_embeddingsl  r}  r+   c                 ó&   — || j                   _        y r1   ©r¿   r6  )r4   r6  s     r)   Úset_decoderz!BlenderbotForCausalLM.set_decodero  s   € Ø$ˆ�
‰
Õr+   c                 ó.   — | j                   j                  S r1   rª  r  s    r)   rI  z!BlenderbotForCausalLM.get_decoderr  s   € Ø�z‰z×!Ñ!Ð!r+   rJ  r   ro   r±   r²   r  r   r"  r  r~  r´   rq   rü   r  rr   c                 óz  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }| j                  j                  |||||||||
|||¬«      }| j                  |d   «      }d}|	�a|	j                  |j                  «      }	t        «       } ||j                  d| j                   j                  «      |	j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  |j                   ¬«      S )a  
        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
                provide it.

                Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
                [`PreTrainedTokenizer.__call__`] for details.

                [What are input IDs?](../glossary#input-ids)
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            encoder_hidden_states  (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention
                if the model is configured as a decoder.
            encoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used
                in the cross-attention if the model is configured as a decoder. Mask values selected in `[0, 1]`:
            head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            cross_attn_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the cross-attention modules. Mask values selected in `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
                Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
                shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of
                shape `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`. The two additional
                tensors are only required when the model is used as a decoder in a Sequence to Sequence model.

                Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
                cross-attention blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.

                If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those
                that don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of
                all `decoder_input_ids` of shape `(batch_size, sequence_length)`.
            labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
                config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
                (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
            use_cache (`bool`, *optional*):
                If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
                (see `past_key_values`).

                - 1 for tokens that are **not masked**,
                - 0 for tokens that are **masked**.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more detail.
            return_dict (`bool`, *optional*):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.

        Returns:

        Example:

        ```python
        >>> from transformers import AutoTokenizer, BlenderbotForCausalLM

        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
        >>> model = BlenderbotForCausalLM.from_pretrained("facebook/blenderbot-400M-distill", add_cross_attention=False)
        >>> assert model.config.is_decoder, f"{model.__class__} has to be configured as a decoder."
        >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
        >>> outputs = model(**inputs)

        >>> logits = outputs.logits
        >>> expected_shape = [1, inputs.input_ids.shape[-1], model.config.vocab_size]
        >>> list(logits.shape) == expected_shape
        True
        ```NrQ  r   r"   r   )r€  r�  r"  rl   rû   r#  )r\   rq   rü   rý   r¿   r6  rg  r‹  r:   r   rh   rè   r   r"  rl   rû   r#  )r4   r   ro   r±   r²   r  r   r"  r  r~  r´   rq   rü   r  r©   r�  r€  r„  r…  s                      r)   r?   zBlenderbotForCausalLM.forwardu  sX  € ðL 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð —*‘*×$Ñ$ØØ)Ø"7Ø#9ØØ!5Ø+Ø'ØØ/Ø!5Ø#ð %ó 
ˆð —‘˜g a™jÓ)ˆàˆØÐØ—Y‘Y˜vŸ}™}Ó-ˆFÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯K©K×,BÑ,BÓCÀVÇ[Á[ÐQSÃ_ÓUˆDáØ�Y ¨¨ Ñ,ˆFØ'+Ð'7�D�7˜VÑ#ÐC¸VÐCä0ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø$×5Ñ5ô
ð 	
r+   c                 óJ   ‡— d}| D ]  }|t        ˆfd„|D «       «      fz  }Œ |S )NrÚ   c              3   ót   •K  — | ]/  }|j                  d ‰j                  |j                  «      «      –— Œ1 y­wrˆ  r‰  rŒ  s     €r)   rø   z7BlenderbotForCausalLM._reorder_cache.<locals>.<genexpr>  s.   øè ø€ ÒnÐU_�j×-Ñ-¨a°·±¸Z×=NÑ=NÓ1O×PÑnùr�  r�  r‘  s    `  r)   r”  z$BlenderbotForCausalLM._reorder_cache  s=   ø€ àˆØ)ò 	ˆJØÜÓnÐcmÔnÓnðñ ‰Nð	ð Ðr+   )NNNNNNNNNNNNN)rC   rD   rE   rW  r3   r  r  ry  r|  r«  rI  r   r   r]  r   r;   r^  rS   r_  r   rŒ   r   r   r?   r—  r”  rI   rJ   s   @r)   rž  rž  T  s¢  ø„ Ø*Ð+Ðô
ò/ò0òò&ò%ò"ñ Ð+LÐ[jÔkð 15Ø15Ø=AØ>BØ,0Ø7;Ø=AØ59Ø-1Ø$(Ø,0Ø/3Ø&*ñN
à˜E×,Ñ,Ñ-ðN
ð ! §¡Ñ.ðN
ð  (¨×(9Ñ(9Ñ:ð	N
ð
 !)¨×):Ñ):Ñ ;ðN
ð ˜EŸL™LÑ)ðN
ð ' u§|¡|Ñ4ðN
ð " $ u×'8Ñ'8Ñ"9Ñ:ðN
ð   × 1Ñ 1Ñ2ðN
ð ˜×)Ñ)Ñ*ðN
ð ˜D‘>ðN
ð $ D™>ðN
ð ' t™nðN
ð ˜d‘^ðN
ð 
ˆuÐ7Ð7Ñ	8òN
ó lðN
ð` ñó ôr+   rž  )rž  ra  r0  r¾   )DrF   r   ræ   rZ  r:  Útypingr   r   r   r   r;   Útorch.utils.checkpointr   Útorch.nnr   Úactivationsr
   Ú
generationr   Úmodeling_attn_mask_utilsr   r   Úmodeling_outputsr   r   r   r   r   Úmodeling_utilsr   Úutilsr   r   r   r   r   Úblenderbot_smallr   r   Úconfiguration_blenderbotr   Ú
get_loggerrC   r$  r]  Ú_CHECKPOINT_FOR_DOCrS   rG   r*   rÈ   r-   rL   ÚModulerU   r’   r�   r«   r¾   ÚBLENDERBOT_START_DOCSTRINGr–  r\  rÜ   r  r0  ra  r™  rž  Ú__all__rÚ   r+   r)   ú<module>rÀ     s¿  ðñ  ã Û Û 	Û ß /Ó /ã Û Ý Ý %å !Ý )ß e÷õ õ .÷õ ÷ ]Ý 6ð 
ˆ×	Ñ	˜HÓ	%€à$€Ø8Ð ð %§,¡,ð ¸cð Ð[^ó ô *¨2¯<©<ô *ô$
= B§L¡Lô 
=ô[B˜"Ÿ)™)ô [Bð| !(Ð)<Ð=Ð ôA˜RŸY™Yô AôJu˜RŸY™Yô uôp ô ð8Ð ð  !Ð ðDXÐ ôvj
Ð1ô j
ôZ}
Ð1ô }
ñ@ Ø^ØóôF
Ð/ó F
ó	ðF
ñR ØXÐZtóôSÐ)BÀOó SóðSôn-Ð8ô -ôyÐ5°ô yòx�r+   