Ë
    T^(h ã                   ó  — d 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
mZmZ ddlmZ ddlmZmZ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 ddlm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)  e%«       rddl*m+Z+ ddl,m-Z-  e«       rddlm.Z.  e&j^                  e0«      Z1dZ2dZ3g d¢Z4dZ5dZ6dZ7 G d„ dejp                  «      Z9 G d„ dejt                  «      Z; G d„ de;«      Z< G d „ d!e;«      Z=e;e<e=d"œZ> G d#„ d$ejt                  «      Z?d%Z@ e#d&e@«       G d'„ d(e «      «       ZAd)ZB G d*„ d+eA«      ZC e#d&e@«       G d,„ d-eA«      «       ZD G d.„ d/eAe«      ZE e#d0e@«       G d1„ d2eA«      «       ZF e#d3e@«       G d4„ d5eA«      «       ZGg d6¢ZHy)7zPyTorch OPT model.é    )ÚListÚOptionalÚTupleÚUnionN)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )ÚACT2FN)ÚCacheÚDynamicCacheÚStaticCache)ÚGenerationMixin)ÚAttentionMaskConverter)Ú!flash_attn_supports_top_left_maskÚis_flash_attn_available)ÚBaseModelOutputWithPastÚCausalLMOutputWithPastÚQuestionAnsweringModelOutputÚ SequenceClassifierOutputWithPast)ÚPreTrainedModel)Úadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚis_torch_flex_attn_availableÚloggingÚreplace_return_docstringsé   )Ú	OPTConfig)Ú	BlockMask)Úmake_flex_block_causal_mask)Ú_flash_attention_forwardzfacebook/opt-350mr    )r   é   i   zArthurZ/opt-350m-dummy-scg\�Âõ(\û?z	'LABEL_0'c                   óx   ‡ — e Zd ZdZdedefˆ fd„Z	 	 d	dej                  dedeej                     fˆ fd„Z	ˆ xZ
S )
ÚOPTLearnedPositionalEmbeddingzN
    This module learns positional embeddings up to a fixed maximum size.
    Únum_embeddingsÚembedding_dimc                 óN   •— d| _         t        ‰| �	  || j                   z   |«       y ©Né   )ÚoffsetÚsuperÚ__init__)Úselfr'   r(   Ú	__class__s      €úb/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/opt/modeling_opt.pyr.   z&OPTLearnedPositionalEmbedding.__init__N   s$   ø€ ð ˆŒÜ‰Ñ˜¨$¯+©+Ñ5°}ÕEó    Úattention_maskÚpast_key_values_lengthÚposition_idsc                 ó°   •— |€8t        j                  |d¬«      }||z  dz
  j                  «       }|dd…|d…f   }t        ‰| �  || j
                  z   «      S )z3`input_ids_shape` is expected to be [bsz x seqlen].Nr   ©Údim)ÚtorchÚcumsumÚlongr-   Úforwardr,   )r/   r3   r4   r5   r0   s       €r1   r<   z%OPTLearnedPositionalEmbedding.forwardT   s^   ø€ ð ÐÜ Ÿ<™<¨¸AÔ>ˆLØ(¨>Ñ9¸AÑ=×CÑCÓEˆLà'ªÐ+AÑ+BÐ(BÑCˆLä‰w‰˜|¨d¯k©kÑ9Ó:Ð:r2   ©r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr.   r9   Ú
LongTensorr   r<   Ú__classcell__©r0   s   @r1   r&   r&   I   s]   ø„ ñðF sð F¸3õ Fð '(Ø37ñ	;à×(Ñ(ð;ð !$ð;ð ˜u×/Ñ/Ñ0÷	;ñ ;r2   r&   c                   óH  ‡ — e Zd ZdZ	 ddedee   fˆ fd„Z	 	 	 	 	 	 ddej                  dee
ej                        deej                     deej                     d	ed
eej                     deej                     de
ej                  eej                     ee   f   fd„Zˆ xZS )ÚOPTAttentionz=Multi-headed attention from 'Attention Is All You Need' paperÚconfigÚ	layer_idxc                 ó  •— t         ‰| �  «        || _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _	        || _
        |€-t        j                  d| j                  j                  › d�«       | j                  | j                  z  | _        d| _        | j                  | j                  z  | j                  k7  r&t#        d| j                  › d| j                  › d�«      ‚| j                  dz  | _        t'        j(                  | j                  | j                  | j                  ¬«      | _        t'        j(                  | j                  | j                  | j                  ¬«      | _        t'        j(                  | j                  | j                  | j                  ¬«      | _        t'        j(                  | j                  | j                  | j                  ¬«      | _        y )	NzInstantiating z¹ without passing a `layer_idx` is not recommended and will lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` when creating this class.Tz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).g      à¿©Úbias)r-   r.   rH   Úhidden_sizeÚ	embed_dimÚnum_attention_headsÚ	num_headsÚattention_dropoutÚdropoutÚenable_biasrI   ÚloggerÚwarning_oncer0   r>   Úhead_dimÚ	is_causalÚ
ValueErrorÚscalingr   ÚLinearÚk_projÚv_projÚq_projÚout_proj)r/   rH   rI   Úkwargsr0   s       €r1   r.   zOPTAttention.__init__h   s  ø€ ô 	‰ÑÔØˆŒØ×+Ñ+ˆŒØ×3Ñ3ˆŒØ×/Ñ/ˆŒØ!×-Ñ-ˆÔØ"ˆŒØÐÜ×ÑØ  §¡×!8Ñ!8Ð 9ð :,ð ,ôð Ÿ™¨$¯.©.Ñ8ˆŒØˆŒà�M‰M˜DŸN™NÑ*¨t¯~©~Ò=ÜØMÈdÏnÉnÐM]Ø$ T§^¡^Ð$4°Bð8óð ð —}‘} dÑ*ˆŒä—i‘i §¡°·±ÀT×EUÑEUÔVˆŒÜ—i‘i §¡°·±ÀT×EUÑEUÔVˆŒÜ—i‘i §¡°·±ÀT×EUÑEUÔVˆŒÜŸ	™	 $§.¡.°$·.±.Àt×GWÑGWÔXˆ�r2   Úhidden_statesÚpast_key_valuer3   Úlayer_head_maskÚoutput_attentionsr5   Úcache_positionÚreturnc                 ól  — |j                  «       \  }}	}
| j                  |«      | j                  z  }|j                  |d| j                  | j
                  «      j                  dd«      }| j                  |«      }| j                  |«      }|j                  |d| j                  | j
                  «      j                  dd«      }|j                  |d| j                  | j
                  «      j                  dd«      }|�#|j                  ||| j                  d|i«      \  }}t        j                  ||j                  dd«      «      }|�#|dd…dd…dd…d|j                  d   …f   }||z   }t        j                  j!                  |dt        j"                  ¬«      j%                  |j&                  «      }|�_|j                  «       | j                  fk7  r*t)        d	| j                  f› d
|j                  «       › �«      ‚|j                  dddd«      |z  }t        j                  j+                  || j*                  | j,                  ¬«      }t        j                  ||«      }|j                  dd«      j/                  «       }|j1                  ||	| j2                  «      }| j5                  |«      }|||fS )ú#Input shape: Batch x Time x Channeléÿÿÿÿr   r+   Nrd   r   éþÿÿÿ)r8   Údtypez/Head mask for a single layer should be of size z	, but is ©ÚpÚtraining)Úsizer]   rY   ÚviewrP   rV   Ú	transposer[   r\   ÚupdaterI   r9   ÚmatmulÚshaper   Ú
functionalÚsoftmaxÚfloat32Útorj   rX   rR   rm   Ú
contiguousÚreshaperN   r^   )r/   r`   ra   r3   rb   rc   r5   rd   ÚbszÚtgt_lenÚ_Úquery_statesÚ
key_statesÚvalue_statesÚattn_weightsÚcausal_maskÚ
attn_probsÚattn_outputs                     r1   r<   zOPTAttention.forward‹   s}  € ð (×,Ñ,Ó.‰ˆˆW�að —{‘{ =Ó1°D·L±LÑ@ˆØ#×(Ñ(¨¨b°$·.±.À$Ç-Á-ÓP×ZÑZÐ[\Ð^_Ó`ˆà—[‘[ Ó/ˆ
Ø—{‘{ =Ó1ˆØ—_‘_ S¨"¨d¯n©n¸d¿m¹mÓL×VÑVÐWXÐZ[Ó\ˆ
Ø#×(Ñ(¨¨b°$·.±.À$Ç-Á-ÓP×ZÑZÐ[\Ð^_Ó`ˆàÐ%à'5×'<Ñ'<Ø˜L¨$¯.©.Ð;KÈ^Ð:\ó(Ñ$ˆJ˜ô —|‘| L°*×2FÑ2FÀqÈ!Ó2LÓMˆØÐ%Ø(ªªAªqÐ2H°J×4DÑ4DÀRÑ4HÐ2HÐ)HÑIˆKØ'¨+Ñ5ˆLô —}‘}×,Ñ,¨\¸rÌÏÉÐ,ÓW×ZÑZÐ[g×[mÑ[mÓnˆàÐ&Ø×#Ñ#Ó%¨$¯.©.Ð):Ò:Ü ØEÀtÇ~Á~ÐFWÐEXð YØ'×,Ñ,Ó.Ð/ð1óð ð +×/Ñ/°°2°q¸!Ó<¸|ÑKˆLä—]‘]×*Ñ*¨<¸4¿<¹<ÐRV×R_ÑR_Ð*Ó`ˆ
Ü—l‘l :¨|Ó<ˆà!×+Ñ+¨A¨qÓ1×<Ñ<Ó>ˆð "×)Ñ)¨#¨w¸¿¹ÓGˆØ—m‘m KÓ0ˆà˜J¨Ð6Ð6r2   ©N©NNNFNN)r>   r?   r@   rA   r    r   rB   r.   r9   ÚTensorr   Úboolr   r<   rD   rE   s   @r1   rG   rG   e   sä   ø„ ÙGð
 $(ñ!Yàð!Yð ˜C‘=õ!YðL 9=Ø15Ø26Ø"'à/3Ø15ñ77à—|‘|ð77ð !  u§|¡|Ñ!4Ñ5ð77ð ! §¡Ñ.ð	77ð
 " %§,¡,Ñ/ð77ð  ð77ð ˜uŸ|™|Ñ,ð77ð ! §¡Ñ.ð77ð 
ˆu�|‰|˜X e§l¡lÑ3°X¸e±_ÐDÑ	E÷77r2   rG   c                   óN  ‡ — e Zd ZdZˆ fd„Z	 	 	 	 	 	 ddej                  deeej                        deej                     deej                     de	deej                     d	eej                     d
eej                  eej                     eeej                        f   fd„Z
ˆ xZS )ÚOptFlashAttention2aB  
    OPT flash attention module. This module inherits from `OPTAttention` as the weights of the module stays untouched.
    The only required change would be on the forward pass where it needs to correctly call the public API of flash
    attention and deal with padding tokens in case the input contains any of them.
    c                 óB   •— t        ‰| �  |i |¤Ž t        «       | _        y r„   )r-   r.   r   Ú_flash_attn_uses_top_left_mask)r/   Úargsr_   r0   s      €r1   r.   zOptFlashAttention2.__init__Ì   s#   ø€ Ü‰Ñ˜$Ð) &Ò)ô
 /PÓ.QˆÕ+r2   r`   ra   r3   rb   rc   r5   rd   re   c                 ó   — |j                  «       \  }}	}
| j                  |«      }|j                  |d| j                  | j                  «      }| j                  |«      }| j                  |«      }|j                  |d| j                  | j                  «      j                  dd«      }|j                  |d| j                  | j                  «      j                  dd«      }|�#|j                  ||| j                  d|i«      \  }}| j                  r| j                  nd}|j                  dd«      }|j                  dd«      }|j                  }|t        j                  k(  rÂt        j                  «       rt        j                   «       }nMt#        | j$                  d«      r| j$                  j&                  }n | j                  j(                  j                  }t*        j-                  d|› d	�«       |j/                  |«      }|j/                  |«      }|j/                  |«      }t1        |||||	||| j2                  | j4                  ¬
«	      }|j7                  ||	| j                  | j                  z  «      }| j9                  |«      }|sd}|||fS )rg   rh   r   r+   Nrd   ç        Ú_pre_quantization_dtypez¾The input hidden states seems to be silently casted in float32, this might be related to the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in ú.)r5   rR   rW   Úuse_top_left_mask)rn   r]   ro   rP   rV   r[   r\   rp   rq   rI   rm   rR   rj   r9   rv   Úis_autocast_enabledÚget_autocast_gpu_dtypeÚhasattrrH   r�   ÚweightrT   rU   rw   r#   rW   r‹   ry   r^   )r/   r`   ra   r3   rb   rc   r5   rd   rz   Úquery_lengthr|   r}   r~   r   Úattn_dropoutÚinput_dtypeÚtarget_dtyperƒ   Úattn_weights_reshapeds                      r1   r<   zOptFlashAttention2.forwardÔ   sM  € ð  -×1Ñ1Ó3Ñˆˆ\˜1à—{‘{ =Ó1ˆØ#×(Ñ(¨¨b°$·.±.À$Ç-Á-ÓPˆà—[‘[ Ó/ˆ
Ø—{‘{ =Ó1ˆØ—_‘_ S¨"¨d¯n©n¸d¿m¹mÓL×VÑVÐWXÐZ[Ó\ˆ
Ø#×(Ñ(¨¨b°$·.±.À$Ç-Á-ÓP×ZÑZÐ[\Ð^_Ó`ˆàÐ%à'5×'<Ñ'<Ø˜L¨$¯.©.Ð;KÈ^Ð:\ó(Ñ$ˆJ˜ð (,§}¢}�t—|’|¸#ˆð  ×)Ñ)¨!¨QÓ/ˆ
Ø#×-Ñ-¨a°Ó3ˆð
 #×(Ñ(ˆØœ%Ÿ-™-Ò'Ü×(Ñ(Ô*Ü$×;Ñ;Ó=‘ä˜Ÿ™Ð&?Ô@Ø#Ÿ{™{×BÑB‘à#Ÿ{™{×1Ñ1×7Ñ7�ä×Ñðà �> ð$ôð (Ÿ?™?¨<Ó8ˆLØ#Ÿ™ |Ó4ˆJØ'Ÿ?™?¨<Ó8ˆLä.ØØØØØØ%Ø Ø—n‘nØ"×AÑAô

ˆð !,× 3Ñ 3°C¸ÀtÇ~Á~ÐX\×XeÑXeÑGeÓ fÐØ—m‘mÐ$9Ó:ˆá Ø$(Ð!àÐ1°>ÐAÐAr2   r…   )r>   r?   r@   rA   r.   r9   r†   r   r   r‡   r<   rD   rE   s   @r1   r‰   r‰   Å   sä   ø„ ñôRð 9=Ø15Ø26Ø"'Ø/3Ø15ñLBà—|‘|ðLBð !  u§|¡|Ñ!4Ñ5ðLBð ! §¡Ñ.ð	LBð
 " %§,¡,Ñ/ðLBð  ðLBð ˜uŸ|™|Ñ,ðLBð ! §¡Ñ.ðLBð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷LBr2   r‰   c                   óH  ‡ — e Zd ZdZ	 	 	 	 	 	 ddej
                  deeej
                        deej
                     deej
                     dedeej
                     deej
                     d	eej
                  eej
                     eeej
                        f   fˆ fd
„Z	ˆ xZ
S )ÚOPTSdpaAttentiona@  
    OPT sdpa attention module. This module inherits from `OPTAttention` as the weights of the module stays untouched.
    The only required change would be on the forward pass where it needs to correctly call the public API of sdpa
    attention and deal with padding tokens in case the input contains any of them.
    r`   ra   r3   rb   rc   r5   rd   re   c                 ó  •— |s|�*t         j                  d«       t        ‰| �  ||||||¬«      S |j	                  «       \  }}	}
| j                  |«      }|j                  |d| j                  | j                  «      j                  dd«      }| j                  |«      }| j                  |«      }|j                  |d| j                  | j                  «      j                  dd«      }|j                  |d| j                  | j                  «      j                  dd«      }|�#|j                  ||| j                  d|i«      \  }}|}|�|d d …d d …d d …d |j                  d   …f   }|€|	dkD  rdnd	}t        j                   j"                  j%                  ||||| j&                  r| j(                  nd
|¬«      }|j                  dd«      j+                  «       }|j                  ||	d«      }| j-                  |«      }|d |fS )Nz¬OPTModel is using SDPA attention, which currently does not support output_attentions=True.failing back to eager attention. remove warning using attn_implementation="eager".)r`   r3   rb   ra   rc   rd   rh   r   r+   rd   ri   TFrŽ   )Ú	attn_maskÚ	dropout_prW   )rT   rU   r-   r<   rn   r]   ro   rP   rV   rp   r[   r\   rq   rI   rs   r9   r   rt   Úscaled_dot_product_attentionrm   rR   rx   r^   )r/   r`   ra   r3   rb   rc   r5   rd   rz   Úq_lenr|   r}   r~   r   r�   rW   rƒ   r0   s                    €r1   r<   zOPTSdpaAttention.forward*  s  ø€ ñ  Ð ;Ü×Ñðeôô
 ‘7‘?Ø+Ø-Ø /Ø-Ø"3Ø-ð #ó ð ð &×*Ñ*Ó,‰ˆˆU�Aà—{‘{ =Ó1ˆØ#×(Ñ(¨¨b°$·.±.À$Ç-Á-ÓP×ZÑZÐ[\Ð^_Ó`ˆà—[‘[ Ó/ˆ
Ø—{‘{ =Ó1ˆØ—_‘_ S¨"¨d¯n©n¸d¿m¹mÓL×VÑVÐWXÐZ[Ó\ˆ
Ø#×(Ñ(¨¨b°$·.±.À$Ç-Á-ÓP×ZÑZÐ[\Ð^_Ó`ˆàÐ%à'5×'<Ñ'<Ø˜L¨$¯.©.Ð;KÈ^Ð:\ó(Ñ$ˆJ˜ð %ˆØÐ%Ø%¢aªªAÐ/E°×1AÑ1AÀ"Ñ1EÐ/EÐ&EÑFˆKð (Ð/°E¸A²I‘DÀ5ˆ	ä—h‘h×)Ñ)×FÑFØØØØ!Ø&*§m¢m�d—l’l¸Øð Gó 
ˆð "×+Ñ+¨A¨qÓ1×<Ñ<Ó>ˆØ!×&Ñ& s¨E°2Ó6ˆØ—m‘m KÓ0ˆà˜D .Ð0Ð0r2   r…   )r>   r?   r@   rA   r9   r†   r   r   r‡   r<   rD   rE   s   @r1   rœ   rœ   #  sÑ   ø„ ñð 9=Ø15Ø26Ø"'Ø/3Ø15ñ>1à—|‘|ð>1ð !  u§|¡|Ñ!4Ñ5ð>1ð ! §¡Ñ.ð	>1ð
 " %§,¡,Ñ/ð>1ð  ð>1ð ˜uŸ|™|Ñ,ð>1ð ! §¡Ñ.ð>1ð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷>1ñ >1r2   rœ   )ÚeagerÚflash_attention_2Úsdpac                   ój  ‡ — e Zd Zddedee   fˆ fd„Z	 	 	 	 	 	 	 ddej                  deej                     deej                     dee	ej                        dee
   d	ee
   d
eej                     deej                     de	ej                  ee	ej                  ej                  f      f   fd„Zˆ xZS )ÚOPTDecoderLayerrH   rI   c                 ó¢  •— t         ‰| �  «        |j                  | _        t	        |j
                     ||¬«      | _        |j                  | _        |j                  | _        t        |j                     | _        t        j                  | j                  |j                  ¬«      | _        t        j                   | j                  |j"                  |j$                  ¬«      | _        t        j                   |j"                  | j                  |j$                  ¬«      | _        t        j                  | j                  |j                  ¬«      | _        y )N)rH   rI   ©Úelementwise_affinerK   )r-   r.   rM   rN   ÚOPT_ATTENTION_CLASSESÚ_attn_implementationÚ	self_attnÚdo_layer_norm_beforerR   r   Úactivation_functionÚactivation_fnr   Ú	LayerNormÚlayer_norm_elementwise_affineÚself_attn_layer_normrZ   Úffn_dimrS   Úfc1Úfc2Úfinal_layer_norm)r/   rH   rI   r0   s      €r1   r.   zOPTDecoderLayer.__init__s  sæ   ø€ Ü‰ÑÔØ×+Ñ+ˆŒä.¨v×/JÑ/JÑKÐSYÐenÔoˆŒà$*×$?Ñ$?ˆÔ!Ø—~‘~ˆŒÜ# F×$>Ñ$>Ñ?ˆÔä$&§L¡LØ�N‰N¨v×/SÑ/Sô%
ˆÔ!ô —9‘9˜TŸ^™^¨V¯^©^À&×BTÑBTÔUˆŒÜ—9‘9˜VŸ^™^¨T¯^©^À&×BTÑBTÔUˆŒÜ "§¡¨T¯^©^ÐPV×PtÑPtÔ uˆÕr2   r`   r3   rb   ra   rc   Ú	use_cacher5   rd   re   c	           	      ó  — |}	| j                   r| j                  |«      }| j                  |||||||¬«      \  }}
}t        j                  j                  || j
                  | j                  ¬«      }|	|z   }| j                   s| j                  |«      }|j                  }|j                  d|j                  d«      «      }|}	| j                   r| j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }t        j                  j                  || j
                  | j                  ¬«      }|	|z   j                  |«      }| j                   s| j                  |«      }|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`, *optional*): 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`, *optional*): 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.
            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`).
            past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
            cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
                Indices depicting the position of the input sequence tokens in the sequence..
        )r`   ra   r5   r3   rb   rc   rd   rk   rh   )r­   r²   r¬   r   rt   rR   rm   rs   ry   rn   r¶   r´   r¯   rµ   ro   )r/   r`   r3   rb   ra   rc   r·   r5   rd   ÚresidualÚself_attn_weightsÚpresent_key_valueÚhidden_states_shapeÚoutputss                 r1   r<   zOPTDecoderLayer.forward„  s£  € ð: !ˆð ×$Ò$Ø ×5Ñ5°mÓDˆMð ?C¿n¹nØ'Ø)Ø%Ø)Ø+Ø/Ø)ð ?Mó ?
Ñ;ˆÐ(Ð*;ô Ÿ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆð ×(Ò(Ø ×5Ñ5°mÓDˆMð ,×1Ñ1ÐØ%×-Ñ-¨b°-×2DÑ2DÀRÓ2HÓIˆØ ˆð ×$Ò$Ø ×1Ñ1°-Ó@ˆMàŸ™ Ó/ˆØ×*Ñ*¨=Ó9ˆàŸ™ Ó/ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-Ódˆà! MÑ1×7Ñ7Ð8KÓLˆð ×(Ò(Ø ×1Ñ1°-Ó@ˆMà Ð"ˆáØÐ)Ð+Ñ+ˆGáØÐ)Ð+Ñ+ˆGàˆr2   r„   )NNNFFNN)r>   r?   r@   r    r   rB   r.   r9   r†   r   r‡   rC   ÚFloatTensorr<   rD   rE   s   @r1   r¦   r¦   r  s  ø„ ñv˜yð v°X¸c±]õ vð( 26Ø26Ø8<Ø,1Ø$)Ø37Ø15ñQà—|‘|ðQð ! §¡Ñ.ðQð " %§,¡,Ñ/ð	Qð
 !  u§|¡|Ñ!4Ñ5ðQð $ D™>ðQð ˜D‘>ðQð ˜u×/Ñ/Ñ0ðQð ! §¡Ñ.ðQð 
ˆu× Ñ  (¨5°×1BÑ1BÀE×DUÑDUÐ1UÑ+VÑ"WÐWÑ	X÷Qr2   r¦   aH  
    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 ([`OPTConfig`]):
            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.
zQThe bare OPT Model outputting raw hidden-states without any specific head on top.c                   ó8   — e Zd ZeZdZdZdgZdZdZ	dZ
dZdZd„ Zy)ÚOPTPreTrainedModelÚmodelTr¦   c                 ó  — | 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)rH   Úinit_stdÚ
isinstancer   rZ   r•   ÚdataÚnormal_rL   Úzero_Ú	EmbeddingÚpadding_idx)r/   ÚmodulerÄ   s      r1   Ú_init_weightsz OPTPreTrainedModel._init_weightsø  sÃ   € Ø�k‰k×"Ñ"ˆÜ�fœbŸi™iÔ(Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ð .r2   N)r>   r?   r@   r    Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_supports_flash_attn_2Ú_supports_sdpaÚ_supports_cache_classÚ_supports_quantized_cacheÚ_supports_static_cacherÍ   © r2   r1   rÀ   rÀ   é  s@   „ ð
 €LØÐØ&*Ð#Ø*Ð+ÐØ!ÐØ€NØ ÐØ $ÐØ!Ðó	?r2   rÀ   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)

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

            If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
            `past_key_values`).

            If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
            and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
            information on the default strategy.
        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**.

        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.
        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.
        position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.n_positions - 1]`. for padding use -1.

            [What are position IDs?](../glossary#position-ids)
        cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
            Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
            this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
            the complete sequence length.
c                   ó<  ‡ — e Zd ZdZdefˆ fd„Zd„ Zd„ Z	 ddej                  dej                  dej                  d	e
d
ef
d„Zedej                  dededej                  dej                   dej                  defd„«       Z	 	 	 	 	 	 	 	 	 	 	 ddeej&                     deej                     deej                     d	eeej*                        deej*                     dee   d
ee   dee   dee   deej&                     deej                     deeef   fd„Zˆ xZS )Ú
OPTDecoderz—
    Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`OPTDecoderLayer`]

    Args:
        config: OPTConfig
    rH   c           	      ó8  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j                  | _        t        j                  |j                  |j                  | j
                  «      | _        t        |j                  |j                  «      | _        |j                  |j                  k7  r2t        j                   |j                  |j                  d¬«      | _        nd | _        |j                  |j                  k7  r2t        j                   |j                  |j                  d¬«      | _        nd | _        |j&                  r=|j(                  s1t        j*                  |j                  |j,                  ¬«      | _        nd | _        t        j0                  t3        |j4                  «      D �cg c]  }t7        ||¬«      ‘Œ c}«      | _        d| _        | j=                  «        y c c}w )NFrK   r¨   )rI   )r-   r.   rR   Ú	layerdropÚpad_token_idrË   Úmax_position_embeddingsÚmax_target_positionsÚ
vocab_sizer   rÊ   Úword_embed_proj_dimÚembed_tokensr&   rM   Úembed_positionsrZ   Úproject_outÚ
project_inr­   Ú_remove_final_layer_normr°   r±   r¶   Ú
ModuleListÚrangeÚnum_hidden_layersr¦   ÚlayersÚgradient_checkpointingÚ	post_init)r/   rH   Úir0   s      €r1   r.   zOPTDecoder.__init__S  s•  ø€ Ü‰Ñ˜Ô Ø—~‘~ˆŒØ×)Ñ)ˆŒØ!×.Ñ.ˆÔØ$*×$BÑ$BˆÔ!Ø ×+Ñ+ˆŒäŸL™L¨×):Ñ):¸F×<VÑ<VÐX\×XhÑXhÓiˆÔÜ<¸V×=[Ñ=[Ð]c×]oÑ]oÓpˆÔà×%Ñ%¨×);Ñ);Ò;Ü!Ÿy™y¨×);Ñ);¸V×=WÑ=WÐ^cÔdˆDÕà#ˆDÔà×%Ñ%¨×);Ñ);Ò;Ü Ÿi™i¨×(BÑ(BÀF×DVÑDVÐ]bÔcˆD�Oà"ˆDŒOð
 ×&Ò&¨v×/NÒ/NÜ$&§L¡LØ×"Ñ"°v×7[Ñ7[ô%ˆDÕ!ð %)ˆDÔ!ä—m‘mÔSXÐY_×YqÑYqÓSrÖ$sÈa¤_°VÀqÖ%IÒ$sÓtˆŒà&+ˆÔ#à�‰Õùò	 %ts   ÇHc                 ó   — | j                   S r„   ©rá   ©r/   s    r1   Úget_input_embeddingszOPTDecoder.get_input_embeddingsx  s   € Ø× Ñ Ð r2   c                 ó   — || _         y r„   rî   ©r/   Úvalues     r1   Úset_input_embeddingszOPTDecoder.set_input_embeddings{  s
   € Ø!ˆÕr2   r3   Úinput_tensorrd   Úpast_key_valuesrc   c           
      óÆ  — | j                   j                  dk(  r|�|dk(  j                  «       r|S y | j                   j                  dk(  r7t        |t        j
                  «      rt        |«      }t        |t        «      r|S |�|j                  «       nd}t        |t        «      }| j                   j                  dk(  r(|s&|s$t        j                  |||| j                  ¬«      ry |j                  |j                  }	}|j                  d   }
|r|j!                  «       }n1t        |t        j
                  «      r|j                  d   n||
z   dz   }| j#                  ||
|||	||j                  d   ¬	«      }| j                   j                  dk(  rQ|�O|j                  j$                  d
v r7|s5t	        j&                  |«      j(                  }t        j*                  ||«      }|S )Nr£   rŽ   Úflex_attentionr   r¤   )Úinputs_embedsr4   Úis_trainingr   rh   )Úsequence_lengthÚtarget_lengthrj   Údevicerd   Ú
batch_size)ÚcudaÚxpu)rH   r«   ÚanyrÆ   r9   r†   r"   r!   Úget_seq_lengthr   r   Ú_ignore_causal_mask_sdparm   rj   rý   rs   Úget_max_cache_shapeÚ5_prepare_4d_causal_attention_mask_with_cache_positionÚtypeÚfinfoÚminÚ_unmask_unattended)r/   r3   rõ   rd   rö   rc   Úpast_seen_tokensÚusing_static_cacherj   rý   rû   rü   r�   Ú	min_dtypes                 r1   Ú_update_causal_maskzOPTDecoder._update_causal_mask  sÖ  € ð �;‰;×+Ñ+Ð/BÒBØÐ)¨~ÀÑ/D×.IÑ.IÔ.KØ%Ð%ØØ�;‰;×+Ñ+Ð/?Ò?Ü˜.¬%¯,©,Ô7Ü!<¸^Ó!L�Ü˜.¬)Ô4Ø%Ð%ð
 @OÐ?Z˜?×9Ñ9Ô;Ð`aÐÜ'¨¼ÓEÐð �;‰;×+Ñ+¨vÒ5Ñ>PÑYjÜ%×>Ñ>ØØ*Ø'7Ø ŸM™Mõ	ð à$×*Ñ*¨L×,?Ñ,?ˆvˆØ&×,Ñ,¨QÑ/ˆÙØ+×?Ñ?ÓA‰Mô ˜n¬e¯l©lÔ;ð ×$Ñ$ RÒ(à%¨Ñ7¸!Ñ;ð ð ×PÑPØØ+Ø'ØØØ)Ø#×)Ñ)¨!Ñ,ð Qó 
ˆð �K‰K×,Ñ,°Ò6ØÐ*Ø×%Ñ%×*Ñ*¨oÑ=Ù%ô
 Ÿ™ EÓ*×.Ñ.ˆIÜ0×CÑCÀKÐQZÓ[ˆKàÐr2   rû   rü   rj   rý   rþ   c                 ó˜  — | �| j                  «       dk(  r| }|S t        j                  |«      j                  }	t        j                  ||f|	||¬«      }|dk7  rt        j
                  |d¬«      }|t        j                  ||¬«      |j                  dd«      kD  z  }|dddd…dd…f   j                  |ddd«      }| �Œ|j                  «       }| j                  d   }
|dd…dd…dd…d|
…f   | dd…dddd…f   j                  |j                  «      z   }|dk(  }|dd…dd…dd…d|
…f   j                  ||	«      |dd…dd…dd…d|
…f<   |S )	a°  
        Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
        `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.

        Args:
            attention_mask (`torch.Tensor`):
                A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape
                `(batch_size, 1, query_length, key_value_length)`.
            sequence_length (`int`):
                The sequence length being processed.
            target_length (`int`):
                The target length: when generating with static cache, the mask should be as long as the static cache,
                to account for the 0 padding, the part of the cache that is not filled yet.
            dtype (`torch.dtype`):
                The dtype to use for the 4D attention mask.
            device (`torch.device`):
                The device to place the 4D attention mask on.
            cache_position (`torch.Tensor`):
                Indices depicting the position of the input sequence tokens in the sequence.
            batch_size (`torch.Tensor`):
                Batch size.
        Né   )Ú
fill_valuerj   rý   r   )Údiagonal©rý   rh   r   )r8   r9   r  r  ÚfullÚtriuÚarangery   ÚexpandÚcloners   rw   rý   Úmasked_fill)r3   rû   rü   rj   rý   rd   rþ   r_   r�   r  Úmask_lengthÚpadding_masks               r1   r  z@OPTDecoder._prepare_4d_causal_attention_mask_with_cache_positionÅ  sy  € ðD Ð%¨.×*<Ñ*<Ó*>À!Ò*Cà(ˆKð* Ðô' Ÿ™ EÓ*×.Ñ.ˆIÜŸ*™*Ø  -Ð0¸YÈeÐ\bôˆKð  !Ò#Ü#Ÿj™j¨¸qÔA�Øœ5Ÿ<™<¨¸fÔEÈ×H^ÑH^Ð_aÐcdÓHeÑeÑeˆKØ% d¨D²!²QÐ&6Ñ7×>Ñ>¸zÈ1ÈbÐRTÓUˆKØÐ)Ø)×/Ñ/Ó1�Ø,×2Ñ2°2Ñ6�Ø*ª1ªa²°L°[°LÐ+@ÑAÀNÒSTÐVZÐ\`ÒbcÐScÑDd×DgÑDgØ×&Ñ&óEñ  �ð  ,¨qÑ0�Ø5@ÂÂAÂqÈ,È;È,ÐAVÑ5W×5cÑ5cØ  )ó6�šAšq¢! \ k \Ð1Ñ2ð Ðr2   Ú	input_idsÚ	head_maskrù   r·   Úoutput_hidden_statesÚreturn_dictr5   re   c                 óF  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|	�|	n| j                   j                  }	|du |duz  rt        d«      ‚| j                  r%| j                  r|rt        j                  d«       d}|�|j                  d|j                  d   «      }|€| j                  |«      }d}|r>t        |t        «      s.d}t        j                   |«      }|€t        j                  d«       |�|j#                  «       nd}|€2t%        j&                  |||j                  d	   z   |j(                  ¬
«      }|€A||j                  d	   z   }t%        j*                  |j                  d   ||j(                  ¬
«      }| j-                  |||||«      }|
€8t%        j.                  |d	¬«      }
|
|z  d	z
  j1                  «       }
|
dd…|d…f   }
| j3                  |||
¬«      }| j4                  �| j5                  |«      }||j7                  |j(                  «      z   }|rdnd}|rdnd}d}t9        |gdg«      D ]j  \  }}|€Œ	|j;                  «       d   t=        | j>                  «      k7  sŒ3t        d|› dt=        | j>                  «      › d|j;                  «       d   › d�«      ‚ tA        | j>                  «      D ]´  \  }}|r||fz  }| j                  r%t%        jB                  g «      }|| jD                  k  rŒ?| j                  r7| j                  r+| jG                  |jH                  |||�||   ndd|||
|«	      }n ||||
|�||   nd||||¬«      }|d   }|r	||rdnd	   }|sŒ¬||d	   fz  }Œ¶ | jJ                  �| jK                  |«      }| jL                  �| jM                  |«      }|r||fz  }|r|nd}|r|jO                  «       }|	stQ        d„ ||||fD «       «      S tS        ||||¬«      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 `(num_hidden_layers, num_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**.

            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

                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.
            position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
                config.n_positions - 1]`. for padding use -1.

                [What are position IDs?](../glossary#position-ids)
            cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
                Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
                this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
                the complete sequence length.
        Nz:You must specify exactly one of input_ids or inputs_embedszX`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`.Frh   TzÞPassing a tuple of `past_key_values` is deprecated and will be removed in Transformers v4.53.0. You should pass an instance of `DynamicCache` instead, e.g. `past_key_values=DynamicCache.from_legacy_cache(past_key_values)`.r   r   r  r7   )r5   r×   r  zThe `z` should be specified for z layers, but it is for r�   )r3   r5   rb   ra   rc   r·   rd   r+   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wr„   r×   )Ú.0Úvs     r1   ú	<genexpr>z%OPTDecoder.forward.<locals>.<genexpr>Ì  s   è ø€ Òt˜qÐfgÑfsœÑtùs   ‚Š©Úlast_hidden_staterö   r`   Ú
attentions)*rH   rc   r  r·   Úuse_return_dictrX   rê   rm   rT   rU   ro   rs   rá   rÆ   r   r   Úfrom_legacy_cacher  r9   r  rý   Úonesr  r:   r;   râ   rä   rw   Úziprn   Úlenré   Ú	enumerateÚrandrÛ   Ú_gradient_checkpointing_funcÚ__call__r¶   rã   Úto_legacy_cacheÚtupler   )r/   r  r3   r  rö   rù   r·   rc   r  r  r5   rd   Úreturn_legacy_cacher
  Ú
seq_lengthr�   Ú
pos_embedsr`   Úall_hidden_statesÚall_self_attnsÚnext_decoder_cacherž   Ú	mask_nameÚidxÚdecoder_layerÚdropout_probabilityÚlayer_outputsÚ
next_caches                               r1   r<   zOPTDecoder.forward   s§  € ðL 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	à%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà˜Ð -°tÐ";Ò<ÜÐYÓZÐZà×&Ò&¨4¯=ª=¹YÜ×ÑØjôð ˆIàÐ Ø!Ÿ™ r¨9¯?©?¸2Ñ+>Ó?ˆIàÐ Ø ×-Ñ-¨iÓ8ˆMà#ÐÙœZ¨¼Ô?Ø"&ÐÜ*×<Ñ<¸_ÓMˆOØÐ&Ü×#Ñ#ðYôð @OÐ?Z˜?×9Ñ9Ô;Ð`aÐØÐ!Ü"Ÿ\™\Ø Ð"2°]×5HÑ5HÈÑ5KÑ"KÐTa×ThÑThôˆNð Ð!Ø)¨M×,?Ñ,?ÀÑ,BÑBˆJÜ"ŸZ™Z¨×(;Ñ(;¸AÑ(>À
ÐS`×SgÑSgÔhˆNà×.Ñ.Ø˜M¨>¸?ÐL]ó
ˆð
 Ðä Ÿ<™<¨¸AÔ>ˆLØ(¨>Ñ9¸AÑ=×CÑCÓEˆLà'ªÐ+;Ñ+<Ð(<Ñ=ˆLà×)Ñ)¨.Ð:JÐYeÐ)Ófˆ
à�?‰?Ð&Ø ŸO™O¨MÓ:ˆMà%¨
¯©°m×6JÑ6JÓ(KÑKˆñ #7™B¸DÐÙ0™°dˆØ!Ðô %(¨¨°k°]Ó$Cò 	Ñ ˆI�yØÑ$Ø—>‘>Ó# AÑ&¬3¨t¯{©{Ó+;Ó<Ü$Ø 	˜{Ð*DÄSÈÏÉÓEUÐDVð WØ%ŸN™NÓ,¨QÑ/Ð0°ð3óð ð	ô #,¨D¯K©KÓ"8ò (	6ÑˆC�á#Ø! mÐ%5Ñ5Ð!à�}Š}Ü&+§j¡j°£nÐ#Ø&¨¯©Ò7Øà×*Ò*¨t¯}ª}Ø $× AÑ AØ!×*Ñ*Ø!ØØ&/Ð&;�I˜c’NÀØØ%ØØ Ø"ó
!‘ñ !.Ø!Ø#.Ø!-Ø7@Ð7L Y¨s¢^ÐRVØ#2Ø&7Ø'Ø#1ô	!�ð *¨!Ñ,ˆMáØ%2Ñ8I±1ÈqÑ%QÐ"â Ø =°Ñ#3Ð"5Ñ5‘ðQ(	6ðT × Ñ Ð,Ø ×1Ñ1°-Ó@ˆMà×ÑÐ'Ø ×,Ñ,¨]Ó;ˆMñ  Ø -Ð!1Ñ1Ðá+4Ñ'¸$ˆ
ÙØ#×3Ñ3Ó5ˆJáÜÑt ]°JÐ@QÐSaÐ$bÔtÓtÐtÜ&Ø+Ø&Ø+Ø%ô	
ð 	
r2   )F©NNNNNNNNNNN)r>   r?   r@   rA   r    r.   rð   rô   r9   r†   r   r‡   r  ÚstaticmethodrB   rj   rý   r  r   rC   r   r¾   r   r   r   r<   rD   rE   s   @r1   rÙ   rÙ   K  så  ø„ ñð#˜yõ #òJ!ò"ð #(ñDàŸ™ðDð —l‘lðDð Ÿ™ð	Dð
 ðDð  óDðL ð7ØŸ™ð7àð7ð ð7ð �{‰{ð	7ð
 —‘ð7ð Ÿ™ð7ð ò7ó ð7ðv 15Ø15Ø,0Ø=AØ59Ø$(Ø,0Ø/3Ø&*Ø37Ø15ñR
à˜E×,Ñ,Ñ-ðR
ð ! §¡Ñ.ðR
ð ˜EŸL™LÑ)ð	R
ð
 " $ u×'8Ñ'8Ñ"9Ñ:ðR
ð   × 1Ñ 1Ñ2ðR
ð ˜D‘>ðR
ð $ D™>ðR
ð ' t™nðR
ð ˜d‘^ðR
ð ˜u×/Ñ/Ñ0ðR
ð ! §¡Ñ.ðR
ð 
ˆuÐ-Ð-Ñ	.÷R
r2   rÙ   c                   ó˜  ‡ — e Zd Zdefˆ fd„Zd„ Zd„ Zd„ Z ee	«       e
eeee¬«      	 	 	 	 	 	 	 	 	 	 	 ddeej"                     deej$                     d	eej$                     d
eeej(                        deej(                     dee   dee   dee   dee   deej"                     deej$                     deeef   fd„«       «       Zˆ xZS )ÚOPTModelrH   c                 ód   •— t         ‰| �  |«       t        |«      | _        | j	                  «        y r„   )r-   r.   rÙ   Údecoderrë   ©r/   rH   r0   s     €r1   r.   zOPTModel.__init__Ú  s&   ø€ Ü‰Ñ˜Ô Ü! &Ó)ˆŒà�‰Õr2   c                 ó.   — | j                   j                  S r„   ©rC  rá   rï   s    r1   rð   zOPTModel.get_input_embeddingsà  s   € Ø�|‰|×(Ñ(Ð(r2   c                 ó&   — || j                   _        y r„   rF  rò   s     r1   rô   zOPTModel.set_input_embeddingsã  s   € Ø$)ˆ�‰Õ!r2   c                 ó   — | j                   S r„   )rC  rï   s    r1   Úget_decoderzOPTModel.get_decoderæ  ó   € Ø�|‰|Ðr2   )Ú
checkpointÚoutput_typerÎ   Úexpected_outputr  r3   r  rö   rù   r·   rc   r  r  r5   rd   re   c                 ó€  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|	�|	n| j                   j                  }	| j                  |||
|||||||	|¬«      }|	s|S t        |j                  |j                  |j                  |j                  ¬«      S )N©r  r3   r5   r  rö   rù   r·   rc   r  r  rd   r$  )rH   rc   r  r·   r'  rC  r   r%  rö   r`   r&  )r/   r  r3   r  rö   rù   r·   rc   r  r  r5   rd   Údecoder_outputss                r1   r<   zOPTModel.forwardé  sÚ   € ð* 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ÿ,™,ØØ)Ø%ØØ+Ø'ØØ/Ø!5Ø#Ø)ð 'ó 
ˆñ Ø"Ð"ä&Ø-×?Ñ?Ø+×;Ñ;Ø)×7Ñ7Ø&×1Ñ1ô	
ð 	
r2   r>  )r>   r?   r@   r    r.   rð   rô   rI  r   ÚOPT_INPUTS_DOCSTRINGr   Ú_CHECKPOINT_FOR_DOCr   Ú_CONFIG_FOR_DOCÚ_EXPECTED_OUTPUT_SHAPEr   r9   rC   r†   r   r¾   r‡   r   r   r<   rD   rE   s   @r1   rA  rA  Õ  sR  ø„ ð
˜yõ ò)ò*òñ +Ð+?Ó@ÙØ&Ø+Ø$Ø.ô	ð 15Ø15Ø,0Ø=AØ59Ø$(Ø,0Ø/3Ø&*Ø37Ø15ñ,
à˜E×,Ñ,Ñ-ð,
ð ! §¡Ñ.ð,
ð ˜EŸL™LÑ)ð	,
ð
 " $ u×'8Ñ'8Ñ"9Ñ:ð,
ð   × 1Ñ 1Ñ2ð,
ð ˜D‘>ð,
ð $ D™>ð,
ð ' t™nð,
ð ˜d‘^ð,
ð ˜u×/Ñ/Ñ0ð,
ð ! §¡Ñ.ð,
ð 
ˆuÐ-Ð-Ñ	.ò,
óó Aô,
r2   rA  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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j                      deej"                     deeef   fd„«       Zed„ «       Zˆ xZS )ÚOPTForCausalLMzlm_head.weightc                 óÆ   •— t         ‰| �  |«       t        |«      | _        t	        j
                  |j                  |j                  d¬«      | _        | j                  «        y ©NFrK   )
r-   r.   rA  rÁ   r   rZ   rà   rß   Úlm_headrë   rD  s     €r1   r.   zOPTForCausalLM.__init__"  sK   ø€ Ü‰Ñ˜Ô Ü˜fÓ%ˆŒ
ô —y‘y ×!;Ñ!;¸V×=NÑ=NÐUZÔ[ˆŒð 	�‰Õr2   c                 óB   — | j                   j                  j                  S r„   ©rÁ   rC  rá   rï   s    r1   rð   z#OPTForCausalLM.get_input_embeddings,  ó   € Ø�z‰z×!Ñ!×.Ñ.Ð.r2   c                 ó:   — || j                   j                  _        y r„   r[  rò   s     r1   rô   z#OPTForCausalLM.set_input_embeddings/  ó   € Ø*/ˆ�
‰
×ÑÕ'r2   c                 ó   — | j                   S r„   ©rY  rï   s    r1   Úget_output_embeddingsz$OPTForCausalLM.get_output_embeddings2  rJ  r2   c                 ó   — || _         y r„   r`  )r/   Únew_embeddingss     r1   Úset_output_embeddingsz$OPTForCausalLM.set_output_embeddings5  s	   € Ø%ˆ�r2   c                 ó&   — || j                   _        y r„   ©rÁ   rC  )r/   rC  s     r1   Úset_decoderzOPTForCausalLM.set_decoder8  s   € Ø$ˆ�
‰
Õr2   c                 ó.   — | j                   j                  S r„   rf  rï   s    r1   rI  zOPTForCausalLM.get_decoder;  s   € Ø�z‰z×!Ñ!Ð!r2   ©rL  rÎ   r  r3   r  rö   rù   Úlabelsr·   rc   r  r  r5   rd   re   c                 óF  — |�|n| j                   j                  }|	�|	n| j                   j                  }	|
�|
n| j                   j                  }
| j                  j                  |||||||||	|
|¬«      }| j                  |d   «      j                  «       }d}|�E|j                  |j                  «      } | j                  ||fd| j                   j                  i|¤Ž}|
s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  ¬«      S )a4  
        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 `(num_hidden_layers, num_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**.

            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)`.
            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.
            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`).
            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.
            position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
                config.n_positions - 1]`. for padding use -1.

                [What are position IDs?](../glossary#position-ids)
            cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
                Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
                this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
                the complete sequence length.

        Returns:

        Example:

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

        >>> model = OPTForCausalLM.from_pretrained("facebook/opt-350m")
        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/opt-350m")

        >>> prompt = "Hey, are you conscious? Can you talk to me?"
        >>> inputs = tokenizer(prompt, return_tensors="pt")

        >>> # Generate
        >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
        >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
        "Hey, are you conscious? Can you talk to me?\nI'm not conscious. I'm just a little bit of a weirdo."
        ```NrO  r   rß   r   ©ÚlossÚlogitsrö   r`   r&  )rH   rc   r  r'  rÁ   rC  rY  rx   rw   rý   Úloss_functionrß   r   rö   r`   r&  )r/   r  r3   r  rö   rù   rj  r·   rc   r  r  r5   rd   r_   r½   rn  rm  Úoutputs                     r1   r<   zOPTForCausalLM.forward>  s[  € ðH 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð —*‘*×$Ñ$ØØ)Ø%ØØ+Ø'ØØ/Ø!5Ø#Ø)ð %ó 
ˆð —‘˜g a™jÓ)×4Ñ4Ó6ˆàˆØÐà—Y‘Y˜vŸ}™}Ó-ˆFØ%�4×%Ñ%ØØñð  Ÿ;™;×1Ñ1ðð ñ	ˆDñ Ø�Y ¨¨ Ñ,ˆFØ'+Ð'7�D�7˜VÑ#ÐC¸VÐCä%ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r2   c                 óJ   ‡— d}| D ]  }|t        ˆfd„|D «       «      fz  }Œ |S )Nr×   c              3   ót   •K  — | ]/  }|j                  d ‰j                  |j                  «      «      –— Œ1 y­wr=   )Úindex_selectrw   rý   )r!  Ú
past_stateÚbeam_idxs     €r1   r#  z0OPTForCausalLM._reorder_cache.<locals>.<genexpr>Õ  s.   øè ø€ ÒnÐU_�j×-Ñ-¨a°·±¸Z×=NÑ=NÓ1O×PÑnùs   ƒ58)r1  )rö   ru  Úreordered_pastÚ
layer_pasts    `  r1   Ú_reorder_cachezOPTForCausalLM._reorder_cacheÐ  s=   ø€ àˆØ)ò 	ˆJØÜÓnÐcmÔnÓnðñ ‰Nð	ð Ðr2   ©NNNNNNNNNNNN)r>   r?   r@   Ú_tied_weights_keysr.   rð   rô   ra  rd  rg  rI  r   r   rS  r   r9   rC   r†   r   r¾   r‡   r   r   r<   r?  rx  rD   rE   s   @r1   rV  rV    s‰  ø„ Ø*Ð+Ðôò/ò0òò&ò%ò"ñ Ð+AÐP_Ô`ð 15Ø15Ø,0Ø=AØ59Ø-1Ø$(Ø,0Ø/3Ø&*Ø37Ø15ñO
à˜E×,Ñ,Ñ-ðO
ð ! §¡Ñ.ðO
ð ˜EŸL™LÑ)ð	O
ð
 " $ u×'8Ñ'8Ñ"9Ñ:ðO
ð   × 1Ñ 1Ñ2ðO
ð ˜×)Ñ)Ñ*ðO
ð ˜D‘>ðO
ð $ D™>ðO
ð ' t™nðO
ð ˜d‘^ðO
ð ˜u×/Ñ/Ñ0ðO
ð ! §¡Ñ.ðO
ð 
ˆuÐ,Ð,Ñ	-òO
ó aðO
ðb ñó ôr2   rV  aÒ  
    The OPT Model transformer with a sequence classification head on top (linear layer).

    [`OPTForSequenceClassification`] uses the last token in order to do the classification, as other causal models
    (e.g. GPT-2) do.

    Since it does classification on the last token, it requires to know the position of the last token. If a
    `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
    no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
    padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
    each row of the batch).
    c                   óš  ‡ — e Zd Zdefˆ fd„Z ee«       eee	e
ee¬«      	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                      deej                      de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j                     deee	f   fd„«       «       Zd„ Zd„ Zˆ xZS )ÚOPTForSequenceClassificationrH   c                 óè   •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        j                  |j                  | j                  d¬«      | _        | j                  «        y rX  )
r-   r.   Ú
num_labelsrA  rÁ   r   rZ   rà   Úscorerë   rD  s     €r1   r.   z%OPTForSequenceClassification.__init__ê  sT   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒÜ˜fÓ%ˆŒ
Ü—Y‘Y˜v×9Ñ9¸4¿?¹?ÐQVÔWˆŒ
ð 	�‰Õr2   )rK  rL  rÎ   rM  Úexpected_lossr  r3   r  rö   rù   rj  r·   rc   r  r  r5   re   c                 óÔ  — |
�|
n| j                   j                  }
| j                  |||||||||	|
¬«
      }|d   }| j                  |«      }|�|j                  dd \  }}n|j                  dd \  }}| j                   j
                  €|dk7  rt        d«      ‚| j                   j
                  €d}nÃ|�“|| j                   j
                  k7  j                  |j                  t        j                  «      }t        j                  |j                  d   |j                  t        j                  ¬«      }||z  j                  d«      }n.d}t        j                  | j                  j                   › d	�«       |t        j                  ||j                  ¬
«      |f   }d}|��‡| j                   j"                  €�| j$                  dk(  rd| j                   _        nl| j$                  dkD  rL|j&                  t        j(                  k(  s|j&                  t        j*                  k(  rd| j                   _        nd| j                   _        | j                   j"                  dk(  rIt-        «       }| j$                  dk(  r& ||j/                  «       |j/                  «       «      }nŒ |||«      }n‚| j                   j"                  dk(  r=t1        «       } ||j3                  d| j$                  «      |j3                  d«      «      }n,| j                   j"                  dk(  rt5        «       } |||«      }|
s|f|dd z   }|�|f|z   S |S t7        |||j8                  |j:                  |j<                  ¬«      S )a�  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
            `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
        N©	rö   r3   r5   r  rù   r·   rc   r  r  r   r+   r   z=Cannot handle batch sizes > 1 if no padding token is defined.rh   )rý   rj   zŠ will not detect padding tokens in `inputs_embeds`. Results may be unexpected if using padding tokens in conjunction with `inputs_embeds.`r  Ú
regressionÚsingle_label_classificationÚmulti_label_classificationrl  )rH   r'  rÁ   r  rs   rÜ   rX   rw   rý   r9   Úint32r  ÚargmaxrT   rU   r0   r>   Úproblem_typer~  rj   r;   rB   r
   Úsqueezer	   ro   r   r   rö   r`   r&  )r/   r  r3   r  rö   rù   rj  r·   rc   r  r  r5   Útransformer_outputsr`   rn  rþ   rû   Úlast_non_pad_tokenÚnon_pad_maskÚtoken_indicesÚpooled_logitsrm  Úloss_fctrp  s                           r1   r<   z$OPTForSequenceClassification.forwardó  s  € ð8 &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà"Ÿj™jØØ+Ø)Ø%ØØ'ØØ/Ø!5Ø#ð )ó 
Ðð ,¨AÑ.ˆØ—‘˜MÓ*ˆàÐ Ø*3¯/©/¸"¸1Ð*=Ñ'ˆJ™à*7×*=Ñ*=¸b¸qÐ*AÑ'ˆJ˜à�;‰;×#Ñ#Ð+°
¸a²ÜÐ\Ó]Ð]Ø�;‰;×#Ñ#Ð+Ø!#ÑØÐ"à%¨¯©×)AÑ)AÑA×EÑEÀfÇmÁmÔUZ×U`ÑU`ÓaˆLÜ!ŸL™L¨¯©¸Ñ)<ÀVÇ]Á]ÔZ_×ZeÑZeÔfˆMØ"/°,Ñ">×!FÑ!FÀrÓ!JÑà!#ÐÜ×ÑØ—>‘>×*Ñ*Ð+ð ,Zð Zôð
 œuŸ|™|¨J¸v¿}¹}ÔMÐOaÐaÑbˆàˆØÑØ�{‰{×'Ñ'Ð/Ø—?‘? aÒ'Ø/;�D—K‘KÕ,Ø—_‘_ qÒ(¨f¯l©l¼e¿j¹jÒ.HÈFÏLÉLÔ\a×\eÑ\eÒLeØ/L�D—K‘KÕ,à/K�D—K‘KÔ,à�{‰{×'Ñ'¨<Ò7Ü"›9�Ø—?‘? aÒ'Ù# M×$9Ñ$9Ó$;¸V¿^¹^Ó=MÓN‘Dá# M°6Ó:‘DØ—‘×)Ñ)Ð-JÒJÜ+Ó-�Ù × 2Ñ 2°2°t·±Ó GÈÏÉÐUWËÓY‘Ø—‘×)Ñ)Ð-IÒIÜ,Ó.�Ù ¨vÓ6�ÙØ#Ð%Ð(;¸A¸BÐ(?Ñ?ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä/ØØ Ø/×?Ñ?Ø-×;Ñ;Ø*×5Ñ5ô
ð 	
r2   c                 óB   — | j                   j                  j                  S r„   r[  rï   s    r1   rð   z1OPTForSequenceClassification.get_input_embeddingsY  r\  r2   c                 ó:   — || j                   j                  _        y r„   r[  rò   s     r1   rô   z1OPTForSequenceClassification.set_input_embeddings\  r^  r2   r>  )r>   r?   r@   r    r.   r   rQ  r   Ú'_CHECKPOINT_FOR_SEQUENCE_CLASSIFICATIONr   rS  Ú_SEQ_CLASS_EXPECTED_OUTPUTÚ_SEQ_CLASS_EXPECTED_LOSSr   r9   rC   r¾   r   r†   r‡   r   r<   rð   rô   rD   rE   s   @r1   r|  r|  Ú  sh  ø„ ð ˜yõ ñ +Ð+?Ó@ÙØ:Ø4Ø$Ø2Ø.ôð 15Ø6:Ø15Ø@DØ59Ø-1Ø$(Ø,0Ø/3Ø&*Ø37ñ\
à˜E×,Ñ,Ñ-ð\
ð ! ×!2Ñ!2Ñ3ð\
ð ˜E×-Ñ-Ñ.ð	\
ð
 " %¨¨e¯l©lÑ(;Ñ"<Ñ=ð\
ð   × 1Ñ 1Ñ2ð\
ð ˜×)Ñ)Ñ*ð\
ð ˜D‘>ð\
ð $ D™>ð\
ð ' t™nð\
ð ˜d‘^ð\
ð ˜u×/Ñ/Ñ0ð\
ð 
ˆuÐ6Ð6Ñ	7ò\
óó Að\
ò|/ö0r2   r|  zì
    The OPT Model transformer with a span classification head on top for extractive question-answering tasks like SQuAD
    (a linear layers on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c                   ó´  ‡ — e Zd Zdefˆ fd„Z ee«       eee	¬«      	 	 	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
eeej                           d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j                     deeef   fd„«       «       Zd„ Zd„ Zˆ xZS )ÚOPTForQuestionAnsweringrH   c                 ó®   •— t         ‰| �  |«       t        |«      | _        t	        j
                  |j                  d«      | _        | j                  «        y r*   )	r-   r.   rA  rÁ   r   rZ   rà   Ú
qa_outputsrë   rD  s     €r1   r.   z OPTForQuestionAnswering.__init__h  s@   ø€ Ü‰Ñ˜Ô Ü˜fÓ%ˆŒ
ÜŸ)™) F×$>Ñ$>ÀÓBˆŒð 	�‰Õr2   ri  r  r3   r  rö   rù   Ústart_positionsÚend_positionsr·   rc   r  r  r5   re   c                 óŽ  — |�|n| j                   j                  }| j                  ||||||||	|
|¬«
      }|d   }| j                  |«      }|j	                  dd¬«      \  }}|j                  d«      j                  «       }|j                  d«      j                  «       }d}|�é|�çt        |j                  «       «      dkD  r|j                  d«      }t        |j                  «       «      dkD  r|j                  d«      }|j                  d«      }|j                  d|«      j                  |j                  «      }|j                  d|«      j                  |j                  «      }t        |¬«      } |||«      } |||«      }||z   dz  }|s||f|dd z   }|�|f|z   S |S t        ||||j                  |j                  ¬	«      S )
aÓ  
        start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the start of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the end of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.

        Returns:

        Example:

        ```python
        >>> from transformers import AutoTokenizer, OPTForQuestionAnswering
        >>> import torch

        >>> torch.manual_seed(4)  # doctest: +IGNORE_RESULT
        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/opt-350m")

        >>> # note: we are loading a OPTForQuestionAnswering from the hub here,
        >>> # so the head will be randomly initialized, hence the predictions will be random
        >>> model = OPTForQuestionAnswering.from_pretrained("facebook/opt-350m")

        >>> question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"

        >>> inputs = tokenizer(question, text, return_tensors="pt")
        >>> with torch.no_grad():
        ...     outputs = model(**inputs)

        >>> answer_start_index = outputs.start_logits.argmax()
        >>> answer_end_index = outputs.end_logits.argmax()

        >>> answer_offset = len(tokenizer(question)[0])

        >>> predict_answer_tokens = inputs.input_ids[
        ...     0, answer_offset + answer_start_index : answer_offset + answer_end_index + 1
        ... ]
        >>> predicted = tokenizer.decode(predict_answer_tokens)
        >>> predicted
        ' a nice puppet'
        ```Nr‚  r   r   rh   r7   )Úignore_indexr+   )rm  Ústart_logitsÚ
end_logitsr`   r&  )rH   r'  rÁ   r˜  Úsplitr‰  rx   r+  rn   Úclamprw   rý   r	   r   r`   r&  )r/   r  r3   r  rö   rù   r™  rš  r·   rc   r  r  r5   rŠ  r`   rn  r�  rž  Ú
total_lossÚignored_indexr�  Ú
start_lossÚend_lossrp  s                           r1   r<   zOPTForQuestionAnswering.forwardp  sè  € ðx &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà"Ÿj™jØØ+Ø)Ø%ØØ'ØØ/Ø!5Ø#ð )ó 
Ðð ,¨AÑ.ˆà—‘ Ó/ˆØ#)§<¡<°°r <Ó#:Ñ ˆ�jØ#×+Ñ+¨BÓ/×:Ñ:Ó<ˆØ×'Ñ'¨Ó+×6Ñ6Ó8ˆ
àˆ
ØÐ&¨=Ð+Dä�?×'Ñ'Ó)Ó*¨QÒ.Ø"1×"9Ñ"9¸"Ó"=�Ü�=×%Ñ%Ó'Ó(¨1Ò,Ø -× 5Ñ 5°bÓ 9�à(×-Ñ-¨aÓ0ˆMØ-×3Ñ3°A°}ÓE×HÑHÈÏÉÓWˆOØ)×/Ñ/°°=ÓA×DÑDÀVÇ]Á]ÓSˆMä'°]ÔCˆHÙ! ,°Ó@ˆJÙ 
¨MÓ:ˆHØ$ xÑ/°1Ñ4ˆJáØ" JÐ/Ð2EÀaÀbÐ2IÑIˆFØ/9Ð/E�Z�M FÑ*ÐQÈ6ÐQä+ØØ%Ø!Ø-×;Ñ;Ø*×5Ñ5ô
ð 	
r2   c                 óB   — | j                   j                  j                  S r„   r[  rï   s    r1   rð   z,OPTForQuestionAnswering.get_input_embeddingsÞ  r\  r2   c                 ó:   — || j                   j                  _        y r„   r[  rò   s     r1   rô   z,OPTForQuestionAnswering.set_input_embeddingsá  r^  r2   ry  )r>   r?   r@   r    r.   r   rQ  r   r   rS  r   r9   rC   r¾   r   r†   r‡   r   r<   rð   rô   rD   rE   s   @r1   r–  r–  `  sw  ø„ ð˜yõ ñ +Ð+?Ó@ÙÐ+GÐVeÔfð 15Ø6:Ø15Ø@DØ59Ø6:Ø48Ø$(Ø,0Ø/3Ø&*Ø37ñj
à˜E×,Ñ,Ñ-ðj
ð ! ×!2Ñ!2Ñ3ðj
ð ˜E×-Ñ-Ñ.ð	j
ð
 " %¨¨e¯l©lÑ(;Ñ"<Ñ=ðj
ð   × 1Ñ 1Ñ2ðj
ð " %×"2Ñ"2Ñ3ðj
ð   × 0Ñ 0Ñ1ðj
ð ˜D‘>ðj
ð $ D™>ðj
ð ' t™nðj
ð ˜d‘^ðj
ð ˜u×/Ñ/Ñ0ðj
ð 
ˆuÐ2Ð2Ñ	3òj
ó gó Aðj
òX/ö0r2   r–  )rV  rA  rÀ   r|  r–  )IrA   Útypingr   r   r   r   r9   Útorch.utils.checkpointr   Útorch.nnr   r	   r
   Úactivationsr   Úcache_utilsr   r   r   Ú
generationr   Úmodeling_attn_mask_utilsr   Úmodeling_flash_attention_utilsr   r   Úmodeling_outputsr   r   r   r   Úmodeling_utilsr   Úutilsr   r   r   r   r   r   Úconfiguration_optr    Ú!torch.nn.attention.flex_attentionr!   Úintegrations.flex_attentionr"   r#   Ú
get_loggerr>   rT   rR  rS  rT  r’  r”  r“  rÊ   r&   ÚModulerG   r‰   rœ   rª   r¦   ÚOPT_START_DOCSTRINGrÀ   rQ  rÙ   rA  rV  r|  r–  Ú__all__r×   r2   r1   ú<module>r¹     sü  ðñ ç /Ó /ã Û Ý ß AÑ Aå !ß ;Ñ ;Ý )õ÷ i÷ó õ .÷÷ õ )ñ  Ô!Ý;åJñ ÔÝJð 
ˆ×	Ñ	˜HÓ	%€à)Ð Ø€ò &Ð ð +FÐ 'ØÐ Ø(Ð ô; B§L¡Lô ;ô8]7�2—9‘9ô ]7ô@[B˜ô [Bô|E1�|ô E1ðR Ø+ØñÐ ôc�b—i‘iô cðLÐ ñ" ØWØóô?˜ó ?ó	ð?ð.DÐ ôNG
Ð#ô G
ñT ØWØóôC
Ð!ó C
ó	ðC
ôLxÐ'¨ô xñv ðð óôt0Ð#5ó t0óðt0ñn ðð óô{0Ð0ó {0óð{0ò|�r2   