+
    œ°³jq% ã                   óî  € R t ^ RIt^ RIt^ RIt^ RIt^ RIHtHt ^ RIH	t	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIt^ RIHtHt ^ RIHt ^ R	IHt ^ R
IHtHt ^RIHt ^RIHt ^RI H!t!H"t"H#t# ^RI$H%t% ^RI&H't'H(t( ^RI)H*t* ^RI+H,t,H-t- ^RI.H/t/ ^RI0H1t1H2t2H3t3H4t4 ^RI5H6t6H7t7 ^RI8H9t9H:t: ]Pv                  ! ]<4      t=RMR R llt>]3! RR7      ] ! R R]14      4       4       t?RNR lt@ROR ltARPR ltB ! R R ]P†                  4      tD ! R! R"]P†                  4      tE ! R# R$]P†                  4      tF ! R% R&]P†                  4      tG ! R' R(]P†                  4      tH ! R) R*]P†                  4      tI ! R+ R,]P†                  4      tJ ! R- R.]P†                  4      tK ! R/ R0]*4      tL]3 ! R1 R2]-4      4       tM ! R3 R4]P†                  4      tN]IPž                  tPRQtQ ! R5 R6]P†                  ]4      tR ! R7 R8]R4      tS ! R9 R:]R4      tT ! R; R<]R4      tU ! R= R>]P†                  4      tVR?]SR@]TRA]U/tWRB RC ltX ! RD RE]M4      tY]3 ! RF RG]M4      4       tZ]3! RHR7       ! RI RJ]M]%4      4       t[]3 ! RK RL]M4      4       t\. RROt]R# )SzPyTorch UDOP model.N)ÚABCÚabstractmethod)ÚCallableÚSequence)Údeepcopy)Ú	dataclass)ÚAny)ÚTensorÚnn)ÚCrossEntropyLoss©Ú
UdopConfig)ÚSeq2SeqLMOutputÚSeq2SeqModelOutput)Úinitialization)ÚACT2FN)ÚCacheÚDynamicCacheÚEncoderDecoderCache)ÚGenerationMixin)Úcreate_bidirectional_maskÚcreate_causal_mask)ÚGradientCheckpointingLayer)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)ÚModelOutputÚTransformersKwargsÚauto_docstringÚis_torchdynamo_compiling)Úcan_return_tupleÚmerge_with_config_defaults)ÚOutputRecorderÚcapture_outputsc                ó<  € V ^8„  d   QhR\         P                  R\        P                  R\        P                  R\        P                  R\        P                  R,          R\        R,          R\        R	\        P                  R,          R
\
        \        ,          /	# )é   ÚmoduleÚqueryÚkeyÚvalueÚattention_maskNÚscalingÚdropoutÚposition_biasÚkwargs)r
   ÚModuleÚtorchr	   Úfloatr   r   )Úformats   "Úg/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/udop/modeling_udop.pyÚ__annotate__r4   :   sŽ   € ÷ %ñ %Ü�I‰Ið%ä�<‰<ð%ô 
�‰ð%ô �<‰<ð	%ô
 —L‘L 4Õ'ð%ô �T�\ð%ô ð%ô —<‘< $Õ&ð%ô Ô'Õ(ñ%ó    c                 óÎ  € Vf   VP                  R4      R,          p\        P                  ! WP                  ^^4      4      V,          p	Ve	   W—,           p	Ve	   W”,           p	\        P
                  P                  V	RR7      p	\        P
                  P                  W–V P                  R7      p	\        P                  ! W“4      p
V
P                  ^^4      P                  4       p
W©3# )N©Údim)ÚpÚtrainingéÿÿÿÿç      à¿)
Úsizer0   ÚmatmulÚ	transposer
   Ú
functionalÚsoftmaxr,   r:   Ú
contiguous)r&   r'   r(   r)   r*   r+   r,   r-   r.   Úattn_weightsÚattn_outputs   &&&&&&&&,  r3   Úeager_attention_forwardrE   :   s¿   € ð ‚Ø—*‘*˜R“. DÕ(ˆô —<’< §}¡}°Q¸Ó':Ó;¸gÕE€LàÒ Ø#Õ3ˆàÒ!Ø#Õ4ˆä—=‘=×(Ñ(¨¸2Ð(Ó>€LÜ—=‘=×(Ñ(¨È6Ï?É?Ð(Ó[€Lä—,’,˜|Ó3€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€KàÐ$Ð$r5   z�
    Class for the model's outputs that may also contain a past key/values (to speed up sequential decoding). Includes
    an additional attention mask.
    )Úcustom_introc                   óH   a € ] tR t^Zt o RtRtRtRtRtRt	Rt
V 3R ltRtV tR# )Ú BaseModelOutputWithAttentionMaska˜	  
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
    Sequence of hidden-states at the output of the last layer of the model. If `past_key_values` is used only
    the last hidden-state of the sequences of shape `(batch_size, 1, hidden_size)` is output.
attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Attention mask used in the model's forward pass 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**.
past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
    It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

    Contains pre-computed hidden-states (key and values in the
    self-attention blocks and optionally if `config.is_encoder_decoder=True` in the cross-attention blocks)
    that can be used (see `past_key_values` input) to speed up sequential decoding.
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
    Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
    one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of
    the model at the output of each layer plus the optional initial embedding outputs.
attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
    Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
    sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
    the self-attention heads.
cross_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` and `config.add_cross_attention=True` is passed or when `config.output_attentions=True`):
    Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
    sequence_length)`. Attentions weights of the decoder's cross-attention layer, after the attention softmax,
    used to compute the weighted average in the cross-attention heads.
Nc                óJ  <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   # )r%   NÚlast_hidden_stater*   Úpast_key_valuesÚhidden_statesÚ
attentionsÚcross_attentions)r0   ÚFloatTensorr   Útuple)r2   Ú__classdict__s   "€r3   r4   Ú-BaseModelOutputWithAttentionMask.__annotate__Z   s©   ø‡ ‚ ñJ ×(Ñ(¨4Õ/Ñ6ñK ñL ×%Ñ%¨Õ,Ñ3ñM ñN ˜T•\Ñ(ñO ñP ™×*Ñ*Õ+¨dÕ2Ñ9ñQ ñR ‘e×'Ñ'Õ(¨4Õ/Ñ6ñS ñT ™E×-Ñ-Õ.°Õ5Ñ<òU r5   © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rJ   r*   rK   rL   rM   rN   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)rQ   s   @r3   rH   rH   Z   s4   ø‡ € ñð: 37ÐØ/3€NØ$(€OØ59€MØ26€JØ8<Ð÷U ƒ r5   rH   c           	      ó’  € W,          W,          .p\         P                  ! ^ RV^,          ^,           ,          R4      pW2^,          ,          p\         P                  ! ^ RV^ ,          ^,           ,          R4      pWB^ ,          ,          p\         P                  ! VRR P                  V^ ,          ^4      VRR P                  V^,          ^4      P	                  ^ ^4      VR,          P                  V^ ,          ^4      VR,          P                  V^,          ^4      P	                  ^ ^4      .RR7      pVP                  R^4      pV# )é    ç      ð?Nºé   NNr7   r;   )r0   ÚarangeÚstackÚrepeatr?   Úview)Ú
image_sizeÚ
patch_sizeÚimage_feature_pool_shapeÚvisual_bbox_xÚvisual_bbox_yÚvisual_bbox_inputs   &&    r3   Úget_visual_bboxrk   ‡   s2  € Ø *Õ 8¸*Õ:RÐSÐÜ—L’L  CÐ+CÀAÕ+FÈÕ+JÕ$KÈSÓQ€MØ¨aÕ0Õ0€Mä—L’L  CÐ+CÀAÕ+FÈÕ+JÕ$KÈSÓQ€MØ¨aÕ0Õ0€MäŸšà˜#˜2Ð×%Ñ%Ð&>¸qÕ&AÀ1ÓEØ˜#˜2Ð×%Ñ%Ð&>¸qÕ&AÀ1ÓE×OÑOÐPQÐSTÓUØ˜"Õ×$Ñ$Ð%=¸aÕ%@À!ÓDØ˜"Õ×$Ñ$Ð%=¸aÕ%@À!ÓD×NÑNÈqÐRSÓTð		
ð ôÐð *×.Ñ.¨r°1Ó5ÐàÐr5   c                 ó`  € \        V \        P                  4      '       d   V P                  ^ ,          pM!\	        V 4      p\        P
                  ! V 4      p W,
          pV^ 8”  dG   \        P                  ! V.V,          4      P                  V 4      p\        P                  ! W.^ R7      p V RV # )r]   r7   N)	Ú
isinstancer0   r	   ÚshapeÚlenÚtensorrb   ÚtoÚcat)ÚseqÚ
target_lenÚ	pad_valueÚnÚmÚrets   &&&   r3   Úpad_sequencery   ž   sƒ   € Ü�#”u—|‘|×$Ò$Ø�I‰I�a�L‰ä�‹HˆÜ�lŠl˜3ÓˆØ�€AØˆ1„uÜ�kŠk˜9˜+¨�/Ó*×-Ñ-¨cÓ2ˆÜ�iŠi˜˜
¨Ô*ˆØˆ{�
ÐÐr5   c	                óÎ	  € Tp	\         P                  ! \         P                  ! VR	,          VR
,          ,           R,          V	,          4      P                  4       ^ V	^,
          4      p
\         P                  ! \         P                  ! VR,          VR,          ,           R,          V	,          4      P                  4       ^ V	^,
          4      V	,          pW«,           pVP	                  \         P
                  4      pVP                  R4      R8H  VP                  R4      R8H  ,          p\         P                  ! V ^VP                  R4      P                  ^^V P                  R4      4      4      pRWí&   W,          p\         P                  ! V R	,          R4      P                  4       p\         P                  ! \         P                  ! \        V4      4      R,          P                  ^VP                  R4      4      R,          P	                  V4      VR,          .RR7      pVP!                  ^ ^4      p\#        V!  w  ppRVVV3&   \%        \        V4      4       Uu. uF  pV V,          VV,          ,          NK  	  ppVfY   \'        WxR7      pVP                  ^ 4      P                  V P                  ^ 4      ^^4      pVP	                  V P(                  4      p\%        \        V4      4       Uu. uF  pVV,          VV,          ,          NK  	  ppVeL   V Uu. uF?  p\         P*                  ! VP                  ^ 4      VP,                  VP(                  R7      NKA  	  ppV^ 8X  d   V P                  ^4      pMWaP                  ^4      ,
          p\         P.                  ! V Uu. uF+  p\1        VV\         P2                  ! V R,          4      4      NK-  	  up4      p\         P.                  ! V Uu. uF+  p\1        VV\         P2                  ! VR,          4      4      NK-  	  up4      pVeM   \         P.                  ! X Uu. uF+  p\1        VV\         P2                  ! VR,          4      4      NK-  	  up4      p\         P                  ! VV.^4      p\         P                  ! W#.^4      pVe   \         P                  ! VX.^4      pWV3# u upi u upi u upi u upi u upi u upi )a§  
Combine the image and text embeddings for the input to the encoder/decoder of UDOP.

First, the image embeddings are created by checking for each visual patch if it is inside the bounding box of a
token. If it is, the visual patch is combined with the token embedding. Then, the visual bounding boxes are combined
with the text bounding boxes. Finally, the visual bounding boxes are combined with the text attention mask.
g       @ç        r^   Tr7   F)re   rf   ©ÚdtypeÚdevice©ºNNNr€   r]   ©r€   r€   r%   ©r€   r€   r`   ©r€   r€   é   r;   ©r€   N©r€   r€   N)r]   r]   )r0   ÚclipÚfloorÚlongrq   Úfloat64ÚmeanÚgatherÚ	unsqueezerc   r=   Ú	full_likeÚboolrr   ra   ro   ÚflattenÚzipÚrangerk   r~   Úonesr}   rb   ry   Ú
zeros_like)Úimage_embeddingsÚinputs_embedsÚbboxÚvisual_bboxr*   Únum_patchesÚmax_lenre   rf   Úsequence_lengthÚocr_points_xÚocr_points_yÚ
ocr_pointsÚ
target_segÚrepeated_vision_embedsÚ
patch_indsÚindÚrowsÚcolsÚiÚinput_vision_patchesÚitemÚvisual_attention_maskÚinputs_vision_patchess   &&&&&&&&&               r3   Úcombine_image_text_embeddingsrª   «   s,  € ð& "€OÜ—:’:Ü�Š�T˜'•] T¨'¥]Õ2°cÕ9¸OÕKÓL×QÑQÓSÐUVÐXgÐjkÕXkó€Lô 	�
Š
”5—;’;  W¥°°WµÕ =ÀÕDÀÕVÓW×\Ñ\Ó^Ð`aÐcrÐuvÕcvÓwØ
õ	ð ð Õ,€Jà�7‰7”5—=‘=Ó!€DØ—)‘)˜B“- 3Ñ&¨4¯9©9°R«=¸CÑ+?Õ@€JÜ"Ÿ\š\Ø˜!˜Z×1Ñ1°"Ó5×<Ñ<¸QÀÐCS×CXÑCXÐY[ÓC\Ó]óÐð *-ÐÑ&ØÕ+€Mä—’Ð!1°'Õ!:¸DÓA×FÑFÓH€JÜ
�)Š)ä�LŠLœ˜Z›Ó)¨'Õ2×9Ñ9¸!¸Z¿_¹_ÈRÓ=PÓQÐR\Õ]×`Ñ`ÐakÓlØ�zÕ"ð	
ð ô€Cð �+‰+�a˜Ó
€CÜ�c‘�J€Dˆ$Ø"€Jˆt�TˆzÑäHMÌcÐR\ËoÔH^Ó_ÑH^À1Ð,¨QÕ/°
¸1µ×>Ð>ÑH^ÐÐ_àÒÜ%°ÔSˆØ!×+Ñ+¨AÓ.×5Ñ5Ð6F×6KÑ6KÈAÓ6NÐPQÐSTÓUˆØ!—n‘nÐ%5×%<Ñ%<Ó=ˆä:?ÄÀJÃÔ:PÓQÑ:P°Q�;˜q•> *¨Q¥-×0Ð0Ñ:P€KÐQàÒ!ákvó!
ÙkvÐcgŒE�JŠJ�t—y‘y “|¨>×+?Ñ+?È×H]ÑH]×^Ñkvð 	ð !
ð �!„|Ø"×'Ñ'¨Ó*‰à×.Ñ.¨qÓ1Õ1ˆÜ!ŸKšKÙ[oÓpÑ[oÐSWŒ�d˜G¤U×%5Ò%5Ð6FÀtÕ6LÓ%MÖ	NÑ[oÑpóÐô —+’+ÑepÓqÑepÐ]aœ|¨D°'¼5×;KÒ;KÈDÐQUÍJÓ;WÖXÑepÑqÓr€KØÒ!Ü %§¢Ù]rÓsÑ]rÐUYŒ\˜$ ¬×)9Ò)9¸.ÈÕ:NÓ)OÖPÑ]rÑsó!
Ðô —I’I˜}Ð.CÐDÀaÓH€MÜ�9Š9�dÐ(¨!Ó,€DØÒ!ÜŸš NÐ4IÐ#JÈAÓNˆØ Ð.Ð.ùò? `ùò Rùò!
ùò 	qùâqùò ts%   É S	Ë. SÌASÎ#1SÏ/1SÐ?1S"c                   ó<   a a€ ] tR t^þt oRtV 3R ltR tRtVtV ;t	# )ÚUdopPatchEmbeddingsz2D Image to Patch Embeddingsc                ó  <€ \         SV `  4        VP                  VP                  r2VP                  VP
                  rT\        V\        P                  P                  4      '       d   TMW"3p\        V\        P                  P                  4      '       d   TMW33pV^,          V^,          ,          V^ ,          V^ ,          ,          ,          pW n        W0n        W@n        W`n
        \        P                  ! WEW3R7      V n        R# )r`   )Úkernel_sizeÚstrideN)ÚsuperÚ__init__re   rf   Únum_channelsÚhidden_sizerm   ÚcollectionsÚabcÚIterabler™   r
   ÚConv2dÚproj)ÚselfÚconfigre   rf   r²   r³   r™   Ú	__class__s   &&     €r3   r±   ÚUdopPatchEmbeddings.__init__  sÃ   ø€ Ü‰ÑÔØ!'×!2Ñ!2°F×4EÑ4E�JØ$*×$7Ñ$7¸×9KÑ9K�kä#-¨j¼+¿/¹/×:RÑ:R×#SÒ#S‘ZÐZdÐYqˆ
Ü#-¨j¼+¿/¹/×:RÑ:R×#SÒ#S‘ZÐZdÐYqˆ
Ø! !•}¨
°1­Õ5¸*ÀQ½-È:ÐVWÍ=Õ:XÕYˆØ$ŒØ$ŒØ(ÔØ&Ôä—I’I˜lÀZÔcˆŽ	r5   c                óX  € VP                   w  r#rEW@P                  ^ ,          8w  g   WPP                  ^,          8w  d;   \        RV RV RV P                  ^ ,           RV P                  ^,           R2	4      hV P                  V4      pVP	                  ^4      P                  ^^4      pV# )r]   zInput image size (Ú*z) doesn't match model (z).)rn   re   Ú
ValueErrorr¸   r�   r?   )r¹   Úpixel_valuesÚ
batch_sizer²   ÚheightÚwidthÚ
embeddingss   &&     r3   ÚforwardÚUdopPatchEmbeddings.forward  s©   € Ø2>×2DÑ2DÑ/ˆ
 &Ø—_‘_ QÕ'Ô'¨5·O±OÀAÕ4FÔ+FÜØ$ V H¨A¨e¨WÐ4KÈDÏOÉOÐ\]ÕL^ÐK_Ð_`Ðae×apÑapÐqrÕasÐ`tÐtvÐwóð ð —Y‘Y˜|Ó,ˆ
Ø×'Ñ'¨Ó*×4Ñ4°Q¸Ó:ˆ
ØÐr5   )re   r²   r™   rf   r¸   )
rT   rU   rV   rW   rX   r±   rÅ   rZ   r[   Ú__classcell__©r»   rQ   s   @@r3   r¬   r¬   þ   s   ù‡ € Ù&õd÷ò r5   r¬   c                   ó<   a a€ ] tR tRt oRV 3R lltR tRtVtV ;t# )ÚUdopLayerNormi  c                óŽ   <€ \         SV `  4        \        P                  ! \        P
                  ! V4      4      V n        W n        R# )zU
Construct a layernorm module in the Udop style. No bias and no subtraction of mean.
N)r°   r±   r
   Ú	Parameterr0   r“   ÚweightÚvariance_epsilon)r¹   r³   Úepsr»   s   &&&€r3   r±   ÚUdopLayerNorm.__init__  s/   ø€ ô 	‰ÑÔÜ—l’l¤5§:¢:¨kÓ#:Ó;ˆŒØ #Ör5   c                ó¼  € VP                  \        P                  4      P                  ^4      P	                  RRR7      pV\        P
                  ! W P                  ,           4      ,          pV P                  P                  \        P                  \        P                  39   d&   VP                  V P                  P                  4      pV P                  V,          # )r%   T)Úkeepdimr;   )rq   r0   Úfloat32Úpowr‹   ÚrsqrtrÎ   rÍ   r}   Úfloat16Úbfloat16)r¹   rL   Úvariances   && r3   rÅ   ÚUdopLayerNorm.forward%  s™   € ð !×#Ñ#¤E§M¡MÓ2×6Ñ6°qÓ9×>Ñ>¸rÈ4Ð>ÓPˆØ%¬¯ª°H×?TÑ?TÕ4TÓ(UÕUˆð �;‰;×Ñ¤§¡´·±Ð ?Ô?Ø)×,Ñ,¨T¯[©[×->Ñ->Ó?ˆMà�{‰{˜]Õ*Ð*r5   )rÎ   rÍ   )g�íµ ÷Æ°>©	rT   rU   rV   rW   r±   rÅ   rZ   r[   rÇ   rÈ   s   @@r3   rÊ   rÊ     s   ù‡ € ÷$÷+ò +r5   rÊ   c                   óD   a a€ ] tR tRt oV3R lV 3R lltR tRtVtV ;t# )ÚUdopDenseActDensei6  c                ó    <€ V ^8„  d   QhRS[ /# ©r%   rº   r   )r2   rQ   s   "€r3   r4   ÚUdopDenseActDense.__annotate__7  s   ø€ ÷ /ñ /™zñ /r5   c                ón  <€ \         SV `  4        \        P                  ! VP                  VP
                  R R7      V n        \        P                  ! VP
                  VP                  R R7      V n        \        P                  ! VP                  4      V n
        \        VP                  ,          V n        R# ©F©ÚbiasN)r°   r±   r
   ÚLinearÚd_modelÚd_ffÚwiÚwoÚDropoutÚdropout_rater,   r   Údense_act_fnÚact©r¹   rº   r»   s   &&€r3   r±   ÚUdopDenseActDense.__init__7  sn   ø€ Ü‰ÑÔÜ—)’)˜FŸN™N¨F¯K©K¸eÔDˆŒÜ—)’)˜FŸK™K¨¯©¸eÔDˆŒÜ—z’z &×"5Ñ"5Ó6ˆŒÜ˜&×-Ñ-Õ.ˆŽr5   c                ó  € V P                  V4      pV P                  V4      pV P                  V4      p\        V P                  P
                  \        P                  4      '       d’   VP                  V P                  P
                  P                  8w  dc   V P                  P
                  P                  \        P                  8w  d0   VP                  V P                  P
                  P                  4      pV P	                  V4      pV# ©N)rç   rì   r,   rm   rè   rÍ   r0   r	   r}   Úint8rq   )r¹   rL   s   &&r3   rÅ   ÚUdopDenseActDense.forward>  s­   € ØŸ™ Ó.ˆØŸ™ Ó/ˆØŸ™ ]Ó3ˆä�t—w‘w—~‘~¤u§|¡|×4Ò4Ø×#Ñ# t§w¡w§~¡~×';Ñ';Ô;Ø—‘—‘×$Ñ$¬¯
©
Ô2à)×,Ñ,¨T¯W©W¯^©^×-AÑ-AÓBˆMØŸ™ Ó.ˆØÐr5   )rì   r,   rç   rè   rÚ   rÈ   s   @@r3   rÜ   rÜ   6  s   ù‡ € ÷/ó /÷ò r5   rÜ   c                   óD   a a€ ] tR tRt oV3R lV 3R lltR tRtVtV ;t# )ÚUdopDenseGatedActDenseiM  c                ó    <€ V ^8„  d   QhRS[ /# rÞ   r   )r2   rQ   s   "€r3   r4   Ú#UdopDenseGatedActDense.__annotate__N  s   ø€ ÷ /ñ /™zñ /r5   c                óÒ  <€ \         SV `  4        \        P                  ! VP                  VP
                  R R7      V n        \        P                  ! VP                  VP
                  R R7      V n        \        P                  ! VP
                  VP                  R R7      V n        \        P                  ! VP                  4      V n        \        VP                  ,          V n        R# rá   )r°   r±   r
   rä   rå   ræ   Úwi_0Úwi_1rè   ré   rê   r,   r   rë   rì   rí   s   &&€r3   r±   ÚUdopDenseGatedActDense.__init__N  sŠ   ø€ Ü‰ÑÔÜ—I’I˜fŸn™n¨f¯k©kÀÔFˆŒ	Ü—I’I˜fŸn™n¨f¯k©kÀÔFˆŒ	Ü—)’)˜FŸK™K¨¯©¸eÔDˆŒÜ—z’z &×"5Ñ"5Ó6ˆŒÜ˜&×-Ñ-Õ.ˆŽr5   c                óF  € V P                  V P                  V4      4      pV P                  V4      pW#,          pV P                  V4      p\	        V P
                  P                  \        P                  4      '       d’   VP                  V P
                  P                  P                  8w  dc   V P
                  P                  P                  \        P                  8w  d0   VP                  V P
                  P                  P                  4      pV P                  V4      pV# rð   )rì   rø   rù   r,   rm   rè   rÍ   r0   r	   r}   rñ   rq   )r¹   rL   Úhidden_geluÚhidden_linears   &&  r3   rÅ   ÚUdopDenseGatedActDense.forwardV  sÀ   € Ø—h‘h˜tŸy™y¨Ó7Ó8ˆØŸ	™	 -Ó0ˆØ#Õ3ˆØŸ™ ]Ó3ˆô �t—w‘w—~‘~¤u§|¡|×4Ò4Ø×#Ñ# t§w¡w§~¡~×';Ñ';Ô;Ø—‘—‘×$Ñ$¬¯
©
Ô2à)×,Ñ,¨T¯W©W¯^©^×-AÑ-AÓBˆMàŸ™ Ó.ˆØÐr5   )rì   r,   rø   rù   rè   rÚ   rÈ   s   @@r3   rô   rô   M  s   ù‡ € ÷/ó /÷ò r5   rô   c                   óD   a a€ ] tR tRt oV3R lV 3R lltR tRtVtV ;t# )ÚUdopLayerFFik  c                ó    <€ V ^8„  d   QhRS[ /# rÞ   r   )r2   rQ   s   "€r3   r4   ÚUdopLayerFF.__annotate__l  s   ø€ ÷ 7ñ 7™zñ 7r5   c                ó   <€ \         SV `  4        VP                  '       d   \        V4      V n        M\        V4      V n        \        VP                  VP                  R 7      V n	        \        P                  ! VP                  4      V n        R# )©rÏ   N)r°   r±   Úis_gated_actrô   ÚDenseReluDenserÜ   rÊ   rå   Úlayer_norm_epsilonÚ
layer_normr
   ré   rê   r,   rí   s   &&€r3   r±   ÚUdopLayerFF.__init__l  sb   ø€ Ü‰ÑÔØ××ÐÜ"8¸Ó"@ˆDÕä"3°FÓ";ˆDÔä'¨¯©¸F×<UÑ<UÔVˆŒÜ—z’z &×"5Ñ"5Ó6ˆŽr5   c                óx   € V P                  V4      pV P                  V4      pWP                  V4      ,           pV# rð   )r  r  r,   )r¹   rL   Úforwarded_statess   && r3   rÅ   ÚUdopLayerFF.forwardv  s;   € ØŸ?™?¨=Ó9ÐØ×.Ñ.Ð/?Ó@ÐØ%¯©Ð5EÓ(FÕFˆØÐr5   )r  r,   r  rÚ   rÈ   s   @@r3   r   r   k  s   ù‡ € ÷7ó 7÷ò r5   r   c                   óv   a a€ ] tR tRt oR	V3R lV 3R lllt]R
R l4       tRR ltRV3R lR lltRt	Vt
V ;t# )ÚUdopAttentioni~  c                ó:   <€ V ^8„  d   QhRS[ RS[R,          RS[/# )r%   rº   Ú	layer_idxNÚ	is_causal)r   Úintr�   )r2   rQ   s   "€r3   r4   ÚUdopAttention.__annotate__  s-   ø€ ÷ %,ñ %,áð%,ñ ˜•:ð	%,ñ
 ñ%,r5   c                ó<  <€ \         SV `  4        Wn        VP                  V n        W@n        W n        VP                  V n        VP                  V n        VP                  V n        VP                  V n
        VP                  V n        VP                  V n        V P                  V P                  ,          V n        R V n        W0n        Vf@   V P                  '       d.   \$        P'                  RV P(                  P*                   R24       \,        P.                  ! V P                  V P                  RR7      V n        \,        P.                  ! V P                  V P                  RR7      V n        \,        P.                  ! V P                  V P                  RR7      V n        \,        P.                  ! V P                  V P                  RR7      V n        V P
                  '       d1   \,        P8                  ! V P                  V P                  4      V n        RV n        R# )r^   NzInstantiating a decoder z³ without passing `layer_idx` is not recommended and will to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` when creating this class.Frâ   )r°   r±   rº   Ú
is_decoderr  Úhas_relative_attention_biasÚrelative_attention_num_bucketsÚrelative_attention_max_distancerå   Úd_kvÚkey_value_proj_dimÚ	num_headsÚn_headsrê   r,   Ú	inner_dimr+   r  ÚloggerÚwarning_oncer»   rT   r
   rä   ÚqÚkÚvÚoÚ	EmbeddingÚrelative_attention_biasÚgradient_checkpointing)r¹   rº   r  r  r  r»   s   &&&&&€r3   r±   ÚUdopAttention.__init__  s{  ø€ ô 	‰ÑÔØŒØ ×+Ñ+ˆŒØ"ŒØ+FÔ(Ø.4×.SÑ.SˆÔ+Ø/5×/UÑ/UˆÔ,Ø—~‘~ˆŒØ"(§+¡+ˆÔØ×'Ñ'ˆŒØ×*Ñ*ˆŒØŸ™¨×(?Ñ(?Õ?ˆŒàˆŒØ"ŒØÒ §§ Ü×ÑØ*¨4¯>©>×+BÑ+BÐ*Cð D,ð ,ôô —’˜4Ÿ<™<¨¯©¸eÔDˆŒÜ—’˜4Ÿ<™<¨¯©¸eÔDˆŒÜ—’˜4Ÿ<™<¨¯©¸eÔDˆŒÜ—’˜4Ÿ>™>¨4¯<©<¸eÔDˆŒà×+×+Ð+Ü+-¯<ª<¸×8[Ñ8[Ð]a×]iÑ]iÓ+jˆDÔ(à&+ˆÖ#r5   c                óÄ  € ^ pV'       dP   V^,          pW@^ 8„  P                  \        P                  4      V,          ,          p\        P                  ! V 4      p M,\        P                  ! V \        P
                  ! V 4      4      ) p V^,          pW8  pV\        P                  ! V P                  4       V,          4      \        P                  ! W5,          4      ,          W%,
          ,          P                  \        P                  4      ,           p\        P                  ! V\        P                  ! Wr^,
          4      4      pV\        P                  ! W`V4      ,          pV# )aR  
Adapted from Mesh Tensorflow:
https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593

Translate relative position to a bucket number for relative attention. The relative position is defined as
memory_position - query_position, i.e. the distance in tokens from the attending position to the attended-to
position. If bidirectional=False, then positive relative positions are invalid. We use smaller buckets for
small absolute relative_position and larger buckets for larger absolute relative_positions. All relative
positions >=max_distance map to the same bucket. All relative positions <=-max_distance map to the same bucket.
This should allow for more graceful generalization to longer sequences than the model has been trained on

Args:
    relative_position: an int32 Tensor
    bidirectional: a boolean - whether the attention is bidirectional
    num_buckets: an integer
    max_distance: an integer

Returns:
    a Tensor with the same shape as relative_position, containing int32 values in the range [0, num_buckets)
)rq   r0   r‰   ÚabsÚminr”   Úlogr1   ÚmathrŽ   Úwhere)Úrelative_positionÚbidirectionalÚnum_bucketsÚmax_distanceÚrelative_bucketsÚ	max_exactÚis_smallÚrelative_position_if_larges   &&&&    r3   Ú_relative_position_bucketÚ'UdopAttention._relative_position_bucket¦  s  € ð, ÐßØ˜AÕˆKØ°QÑ!6× :Ñ :¼5¿:¹:Ó FÈÕ TÕTÐÜ %§	¢	Ð*;Ó <Ñä!&§¢Ð+<¼e×>NÒ>NÐO`Ó>aÓ!bÐ bÐð   1Õ$ˆ	Ø$Ñ0ˆð &/Ü�IŠIÐ'×-Ñ-Ó/°)Õ;Ó<Ü�hŠh�|Õ/Ó0õ1àÕ&õ(÷ ‰"ŒU�Z‰Z‹.õ	&Ð"ô
 &+§Y¢YØ&¬¯ªÐ8RÐbcÕTcÓ(dó&
Ð"ð 	œEŸKšK¨ÐE_Ó`Õ`ÐØÐr5   c                óú  € Vf!   V P                   P                  P                  p\        P                  ! V\        P
                  VR7      R,          V,           p\        P                  ! V\        P
                  VR7      R,          pWe,
          pV P                  VV P                  '       * V P                  V P                  R7      pV P                  V4      p	V	P                  . RO4      P                  ^ 4      p	V	# )z%Compute binned relative position biasr|   ©r/  r0  r1  r…   ©Nr€   )r%   r]   r`   )r%  rÍ   r~   r0   ra   r‰   r6  r  r  r  Úpermuter�   )
r¹   Úquery_lengthÚ
key_lengthr~   Úpast_seen_tokensÚcontext_positionÚmemory_positionr.  Úrelative_position_bucketÚvaluess
   &&&&&     r3   Úcompute_biasÚUdopAttention.compute_biasÖ  sÍ   € àŠ>Ø×1Ñ1×8Ñ8×?Ñ?ˆFÜ Ÿ<š<¨¼E¿J¹JÈvÔVÐW^Õ_ÐbrÕrÐÜŸ,š, z¼¿¹ÈFÔSÐT[Õ\ˆØ+Õ>ÐØ#'×#AÑ#AØØ#Ÿ™Ô.Ø×;Ñ;Ø×=Ñ=ð	 $Bó $
Ð ð ×-Ñ-Ð.FÓGˆØ—‘¢	Ó*×4Ñ4°QÓ7ˆØˆr5   c                ó0   <€ V ^8„  d   QhRS[ S[,          /# ©r%   r.   ©r   r   )r2   rQ   s   "€r3   r4   r  ç  s    ø€ ÷ X8ñ X8ñ Ñ+Õ,ñX8r5   c           	     óp  € VP                   RR
 p. VOR
NV P                  N5pVe   VP                  V P                  4      M^ p	\	        V	\
        P                  4      '       d   V	P                  4       MT	p	VRJp
V P                  V4      P                  V4      P                  ^^4      pRp\	        V\        4      '       dH   VP                  P                  V P                  4      pV
'       d   VP                  pMVP                  pMTpV
'       d   TMTpV
'       d\   VeX   V'       dP   VP                   V P                  ,          P"                  pVP                   V P                  ,          P$                  pMÛ. VP                   RR
 OR
NV P                  N5pV P'                  V4      P                  V4      P                  ^^4      pV P)                  V4      P                  V4      P                  ^^4      pVeX   VP+                  VVV P                  4      w  ppV
'       d0   \	        V\        4      '       d   RVP                  V P                  &   Vfº   VP                   R,          pV P,                  '       go   \
        P.                  ! ^V P0                  V^,          V3VP2                  VP4                  R7      pV P6                  '       d   V P8                  '       d   RVn        M&V P=                  V^,          VVP2                  V	R7      p\>        P@                  ! V PB                  PD                  \F        4      pT! V VVVV3RV P8                  '       g   RMV PH                  RV PJ                  R	V/VB w  ppVPL                  ! . VOR
N5!  PO                  4       pV PQ                  V4      pVVV3# )zp
Self-attention (if key_value_states is None) or attention over source sentence (provided by key_value_states).
NFT©r~   r}   )r~   r>  r,   r{   r+   r-   r;   éþÿÿÿ))rn   r  Úget_seq_lengthr  rm   r0   r	   Úcloner   rd   r?   r   Ú
is_updatedÚgetÚcross_attention_cacheÚself_attention_cacheÚlayersÚkeysrB  r!  r"  Úupdater  Úzerosr  r~   r}   r&  r:   Úrequires_gradrC  r   Úget_interfacerº   Ú_attn_implementationrE   r,   r+   ÚreshaperB   r#  )r¹   rL   ÚmaskÚkey_value_statesr-   rK   r.   Úinput_shapeÚhidden_shaper>  Úis_cross_attentionÚquery_statesrM  Úcurr_past_key_valuesÚcurrent_statesÚ
key_statesÚvalue_statesÚkv_shaper=  Úattention_interfacerD   rC   s   &&&&&&,               r3   rÅ   ÚUdopAttention.forwardç  sY  € ð $×)Ñ)¨#¨2Ð.ˆØB˜ÐB bÐB¨$×*AÑ*AÑBˆØM\ÒMh˜?×9Ñ9¸$¿.¹.ÔIÐnoÐä7AÐBRÔTY×T`ÑT`×7aÒ7aÐ+×1Ñ1Ô3ÐgwÐð .°TÐ9Ðà—v‘v˜mÓ,×1Ñ1°,Ó?×IÑIÈ!ÈQÓOˆð ˆ
Ü�oÔ':×;Ò;Ø(×3Ñ3×7Ñ7¸¿¹ÓGˆJß!à'6×'LÑ'LÑ$à'6×'KÑ'KÑ$à#2Ð ç-?Ñ)À]ˆß /Ò"=Ç*à-×4Ñ4°T·^±^ÕD×IÑIˆJØ/×6Ñ6°t·~±~ÕF×MÑM‰LàP˜×-Ñ-¨c¨rÐ2ÐP°BÐP¸×8OÑ8OÑPˆHØŸ™ Ó/×4Ñ4°XÓ>×HÑHÈÈAÓNˆJØŸ6™6 .Ó1×6Ñ6°xÓ@×JÑJÈ1ÈaÓPˆLàÒ*Ø+?×+FÑ+FÀzÐS_Ðae×aoÑaoÓ+pÑ(�
˜Lç%¬*°_ÔFY×*ZÒ*ZØAE�O×.Ñ.¨t¯~©~Ñ>ð Ò Ø#×)Ñ)¨"Õ-ˆJØ×3×3Ð3Ü %§¢Ø˜Ÿ™ k°!¥n°jÐAØ'×.Ñ.Ø&×,Ñ,ô!�ð
 ×.×.Ð.°4·=·=°=Ø26�MÔ/øà $× 1Ñ 1Ø •N J°|×7JÑ7JÐ]mð !2ó !�ô )@×(MÒ(MØ�K‰K×,Ñ,Ô.Eó)
Ðñ %8ØØØØØñ
%
ð  $Ÿ}Ÿ}˜}‘C°$·,±,ð
%
ð —L‘Lð
%
ð (ð
%
ð ñ
%
Ñ!ˆ�\ð "×)Ò)Ð;¨;Ð;¸Ó;×FÑFÓHˆØ—f‘f˜[Ó)ˆà˜M¨<Ð7Ð7r5   )rº   rå   r,   r&  r  r  r  r  r!  r  r  r  r#  r   r%  r  r  r+   r"  )FNF)Té    é€   )Nr]   )NNNN)rT   rU   rV   rW   r±   Ústaticmethodr6  rC  rÅ   rZ   r[   rÇ   rÈ   s   @@r3   r  r  ~  s<   ù‡ € ÷%,õ %,ðN ó- ó ð- ô^÷"X8÷ X8ò X8r5   r  c                   óX   a a€ ] tR tRt oRV3R lV 3R llltRV3R lR lltRtVtV ;t# )	ÚUdopLayerSelfAttentioniC  c                ó.   <€ V ^8„  d   QhRS[ R,          /# ©r%   r  N©r  )r2   rQ   s   "€r3   r4   Ú#UdopLayerSelfAttention.__annotate__D  s   ø€ ÷ 	7ñ 	7ÉSÐSWÍZñ 	7r5   c                óö   <€ \         SV `  4        \        VVVVP                  R 7      V n        \        VP                  VP                  R7      V n        \        P                  ! VP                  4      V n        R# )©r  r  r  r  N)r°   r±   r  r  ÚSelfAttentionrÊ   rå   r  r  r
   ré   rê   r,   ©r¹   rº   r  r  r»   s   &&&&€r3   r±   ÚUdopLayerSelfAttention.__init__D  s]   ø€ Ü‰ÑÔÜ*ØØ(CØØ×'Ñ'ô	
ˆÔô (¨¯©¸F×<UÑ<UÔVˆŒÜ—z’z &×"5Ñ"5Ó6ˆŽr5   c                ó0   <€ V ^8„  d   QhRS[ S[,          /# rF  rG  )r2   rQ   s   "€r3   r4   rn  O  s   ø€ ÷ =ñ =ñ Ñ+Õ,ñ=r5   c           	     ó’   € V P                  V4      pV P                  ! V3R VRVRV/VB w  rspWP                  V4      ,           pWsV3# )rY  r-   rK   )r  rq  r,   )	r¹   rL   r*   r-   rK   r.   Únormed_hidden_statesÚattention_outputrC   s	   &&&&&,   r3   rÅ   ÚUdopLayerSelfAttention.forwardO  sr   € ð  $Ÿ™¨}Ó=ÐØ8<×8JÒ8JØ ñ9
àð9
ð (ð9
ð ,ð	9
ð
 ñ9
Ñ5Ð¨ð )¯<©<Ð8HÓ+IÕIÐØ°Ð<Ð<r5   )rq  r,   r  ©FN©NNNrÚ   rÈ   s   @@r3   rj  rj  C  s   ù‡ € ÷	7õ 	7÷=÷ =ò =r5   rj  c                   óX   a a€ ] tR tRt oRV3R lV 3R llltRV3R lR lltRtVtV ;t# )	ÚUdopLayerCrossAttentionid  c                ó.   <€ V ^8„  d   QhRS[ R,          /# rl  rm  )r2   rQ   s   "€r3   r4   Ú$UdopLayerCrossAttention.__annotate__e  s   ø€ ÷ 7ñ 7©#°­*ñ 7r5   c                óâ   <€ \         SV `  4        \        VR VR R7      V n        \	        VP
                  VP                  R7      V n        \        P                  ! VP                  4      V n        R# )Frp  r  N)r°   r±   r  ÚEncDecAttentionrÊ   rå   r  r  r
   ré   rê   r,   )r¹   rº   r  r»   s   &&&€r3   r±   Ú UdopLayerCrossAttention.__init__e  sU   ø€ Ü‰ÑÔÜ,Ø°ÀÐV[ô 
ˆÔô (¨¯©¸F×<UÑ<UÔVˆŒÜ—z’z &×"5Ñ"5Ó6ˆŽr5   c                ó0   <€ V ^8„  d   QhRS[ S[,          /# rF  rG  )r2   rQ   s   "€r3   r4   r~  m  s   ø€ ÷ 9ñ 9ñ Ñ+Õ,ñ9r5   c                ó–   € V P                  V4      pV P                  ! V3R VRVRVRV/VB w  r„p	WP                  V4      ,           p
W¤V	3# )rY  rZ  r-   rK   )r  r€  r,   )r¹   rL   rZ  r*   r-   rK   r.   rv  rw  rC   Úlayer_outputs   &&&&&&,    r3   rÅ   ÚUdopLayerCrossAttention.forwardm  s{   € ð  $Ÿ™¨}Ó=ÐØ8<×8LÒ8LØ ñ9
àð9
ð .ð9
ð (ð	9
ð
 ,ð9
ð ñ9
Ñ5Ð¨ð %§|¡|Ð4DÓ'EÕEˆØ¨LÐ8Ð8r5   )r€  r,   r  rð   rz  rÚ   rÈ   s   @@r3   r|  r|  d  s   ù‡ € ÷7õ 7÷9÷ 9ò 9r5   r|  c                   óX   a a€ ] tR tRt oRV3R lV 3R llltRV3R lR lltRtVtV ;t# )	Ú	UdopBlocki„  c                ó.   <€ V ^8„  d   QhRS[ R,          /# rl  rm  )r2   rQ   s   "€r3   r4   ÚUdopBlock.__annotate__…  s   ø€ ÷ /ñ /ÉSÐSWÍZñ /r5   c                ó|  <€ \         SV `  4        VP                  V n        \        P                  ! 4       V n        V P
                  P                  \        WVR 7      4       V P                  '       d&   V P
                  P                  \        WR7      4       V P
                  P                  \        V4      4       R# )©r  r  )r  N)
r°   r±   r  r
   Ú
ModuleListÚlayerÚappendrj  r|  r   rr  s   &&&&€r3   r±   ÚUdopBlock.__init__…  s‚   ø€ Ü‰ÑÔØ ×+Ñ+ˆŒÜ—]’]“_ˆŒ
Ø�
‰
×ÑÜ"ØÐ[dôô	
ð
 �?�?ˆ?Ø�J‰J×ÑÔ5°fÔRÔSà�
‰
×Ñœ+ fÓ-Ö.r5   c                ó0   <€ V ^8„  d   QhRS[ S[,          /# rF  rG  )r2   rQ   s   "€r3   r4   r‰  “  s    ø€ ÷ =Pñ =Pñ Ñ+Õ,ñ=Pr5   c                óÆ  € V P                   ^ ,          ! V3RVRVRV/VB w  rp
VP                  \        P                  8X  d«   \        P                  ! \        P
                  ! V4      P                  4       \        P                  ! VP                  4      P                  R,
          \        P                  ! VP                  4      P                  4      p\        P                  ! W) VR7      pRpV P                  ;'       d    VRJpV'       dï   V P                   ^,          ! V3RVRVRVRV/VB w  rp
VP                  \        P                  8X  d«   \        P                  ! \        P
                  ! V4      P                  4       \        P                  ! VP                  4      P                  R,
          \        P                  ! VP                  4      P                  4      p\        P                  ! W) VR7      pV P                   R,          ! V4      pVP                  \        P                  8X  d«   \        P                  ! \        P
                  ! V4      P                  4       \        P                  ! VP                  4      P                  R,
          \        P                  ! VP                  4      P                  4      p\        P                  ! W) VR7      pWV3# )	r]   r*   r-   rK   iè  )r*  ÚmaxNrZ  r;   )r�  r}   r0   rÖ   r-  ÚisinfÚanyÚfinfor’  Úclampr  )r¹   rL   r*   r-   Úencoder_hidden_statesÚencoder_attention_maskÚencoder_decoder_position_biasrK   r.   Úself_attn_position_biasÚ_Úclamp_valueÚcross_attn_position_biasÚdo_cross_attentions   &&&&&&&&,     r3   rÅ   ÚUdopBlock.forward“  sP  € ð 59·J±J¸q¶MØñ5
à)ð5
ð (ð5
ð ,ð	5
ð
 ñ5
Ñ1ˆ°ð ×Ñ¤%§-¡-Ô/ÜŸ+š+Ü—’˜MÓ*×.Ñ.Ó0Ü—’˜M×/Ñ/Ó0×4Ñ4°tÕ;Ü—’˜M×/Ñ/Ó0×4Ñ4óˆKô
 "ŸKšK¨¸<È[ÔYˆMà#'Ð Ø!Ÿ_™_×RÐRÐ1FÈdÐ1RÐßØ9=¿¹ÀA¾Øñ:à!6ð:ð  6ð:ð <ð	:ð
 !0ð:ð ñ:Ñ6ˆM°Qð ×"Ñ"¤e§m¡mÔ3Ü#ŸkškÜ—K’K Ó.×2Ñ2Ó4Ü—K’K × 3Ñ 3Ó4×8Ñ8¸4Õ?Ü—K’K × 3Ñ 3Ó4×8Ñ8ó�ô
 !&§¢¨M¸|ÐQ\Ô ]�ð Ÿ
™
 2ž }Ó5ˆð ×Ñ¤%§-¡-Ô/ÜŸ+š+Ü—’˜MÓ*×.Ñ.Ó0Ü—’˜M×/Ñ/Ó0×4Ñ4°tÕ;Ü—’˜M×/Ñ/Ó0×4Ñ4óˆKô
 "ŸKšK¨¸<È[ÔYˆMàÐ7OÐOÐOr5   )r  r�  ry  ©NNNNNNrÚ   rÈ   s   @@r3   r‡  r‡  „  s!   ù‡ € ÷/õ /÷=P÷ =Pò =Pr5   r‡  c            
       óÎ   a a€ ] tR tRt oRtRtRtRtR.tRt	Rt
RtR]! ]^ R7      R]! ]RR7      R	]! ]RR7      /t]P$                  ! 4       V 3R
 l4       tR tV3R ltRtVtV ;t# )ÚUdopPreTrainedModeliÓ  ÚtransformerTFrè   rL   )ÚindexrM   rN   c                ó¶  <€ \         SV `  V4       V P                  P                  p\	        V\
        4      '       d+   \        P                  ! VP                  VR,          4       R# \	        V\        P                  4      '       dV   \        P                  ! VP                  RVR7       VP                  e#   \        P                  ! VP                  4       R# R# \	        V\        4      '       di   V P                  P                  pV P                  P                  p\        P                   ! VP"                  P                  RW#R,          ,          R7       R# \	        V\$        4      '       d7   \        P                   ! VP&                  P                  RVR,          R7       R# \	        V\(        4      '       di   \+        VR4      '       dU   V P                  P,                  '       g7   \        P                   ! VP.                  P                  RVR,          R7       R# R# R# \	        V\0        4      '       Ed_   \        P                   ! VP2                  P                  RW P                  P                  R,          ,          R7       \+        VP2                  R4      '       dC   VP2                  P                  e+   \        P                  ! VP2                  P                  4       \        P                   ! VP4                  P                  RW P                  P6                  R,          ,          R7       \+        VP4                  R4      '       dG   VP4                  P                  e-   \        P                  ! VP4                  P                  4       R# R# R# \	        V\8        4      '       Ed   \        P                   ! VP:                  P                  RW P                  P                  R,          ,          R7       \+        VP:                  R4      '       dC   VP:                  P                  e+   \        P                  ! VP:                  P                  4       \        P                   ! VP<                  P                  RW P                  P                  R,          ,          R7       \+        VP<                  R4      '       dC   VP<                  P                  e+   \        P                  ! VP<                  P                  4       \        P                   ! VP4                  P                  RW P                  P6                  R,          ,          R7       \+        VP4                  R4      '       dG   VP4                  P                  e-   \        P                  ! VP4                  P                  4       R# R# R# \	        V\>        4      '       Ed‰   V P                  P                  pV P                  P@                  pV P                  PB                  p\        P                   ! VPD                  P                  RW#V,          R,          ,          R7       \        P                   ! VPF                  P                  RW#R,          ,          R7       \        P                   ! VPH                  P                  RW#R,          ,          R7       \        P                   ! VPJ                  P                  RW%V,          R,          ,          R7       VPL                  '       d=   \        P                   ! VP"                  P                  RW#R,          ,          R7       R# R# R# )zInitialize the weightsr^   r{   )r‹   ÚstdNÚlm_headrã   r<   )'r°   Ú_init_weightsrº   Úinitializer_factorrm   rÊ   ÚinitÚ	constant_rÍ   r
   r·   Útrunc_normal_rã   Úzeros_ÚRelativePositionBiasBaserå   Únormal_r%  Ú	UdopModelÚsharedÚUdopForConditionalGenerationÚhasattrÚtie_word_embeddingsr§  rÜ   rç   rè   ræ   rô   rø   rù   r  r  r  r   r!  r"  r#  r  )r¹   r&   Úfactorrå   r  r  r»   s   &&    €r3   r¨  Ú!UdopPreTrainedModel._init_weightsæ  sk  ø€ ô 	‰Ñ˜fÔ%Ø—‘×/Ñ/ˆÜ�fœm×,Ò,Ü�NŠN˜6Ÿ=™=¨&°3­,Ö7Ü˜¤§	¡	×*Ò*Ü×Ò˜vŸ}™}°3¸FÕCØ�{‰{Ò&Ü—’˜FŸK™KÖ(ñ 'ä˜Ô 8×9Ò9Ø—[‘[×3Ñ3ˆFØ—k‘k×)Ñ)ˆGÜ�LŠL˜×7Ñ7×>Ñ>ÀSÈfÐeiÕXiÕNj×kÜ˜¤	×*Ò*Ü�LŠL˜Ÿ™×-Ñ-°C¸VÀc½\×JÜ˜Ô <×=Ò=Ü�v˜y×)Ò)°$·+±+×2Q×2QÐ2QÜ—’˜VŸ^™^×2Ñ2¸À&È3Å,×Oñ 3RÑ)ä˜Ô 1×2Ó2Ü�LŠL˜Ÿ™×)Ñ)°¸ÇKÁK×DWÑDWÐ\`ÕC`Õ9aÕbÜ�v—y‘y &×)Ò)¨f¯i©i¯n©nÒ.HÜ—’˜FŸI™IŸN™NÔ+Ü�LŠL˜Ÿ™×)Ñ)°¸ÇKÁK×DTÑDTÐY]ÕC]Õ9^Õ_Ü�v—y‘y &×)Ò)¨f¯i©i¯n©nÒ.HÜ—’˜FŸI™IŸN™NÖ+ñ /IÑ)ä˜Ô 6×7Ó7Ü�LŠL˜Ÿ™×+Ñ+°#¸6ÇkÁk×FYÑFYÐ^bÕEbÕ;cÕdÜ�v—{‘{ F×+Ò+°·±×0@Ñ0@Ò0LÜ—’˜FŸK™K×,Ñ,Ô-Ü�LŠL˜Ÿ™×+Ñ+°#¸6ÇkÁk×FYÑFYÐ^bÕEbÕ;cÕdÜ�v—{‘{ F×+Ò+°·±×0@Ñ0@Ò0LÜ—’˜FŸK™K×,Ñ,Ô-Ü�LŠL˜Ÿ™×)Ñ)°¸ÇKÁK×DTÑDTÐY]ÕC]Õ9^Õ_Ü�v—y‘y &×)Ò)¨f¯i©i¯n©nÒ.HÜ—’˜FŸI™IŸN™NÖ+ñ /IÑ)ä˜¤×.Ó.Ø—k‘k×)Ñ)ˆGØ!%§¡×!1Ñ!1ÐØ—k‘k×+Ñ+ˆGÜ�LŠL˜Ÿ™Ÿ™¨s¸ÐM_ÕC_ÐdhÕBhÕ8iÕjÜ�LŠL˜Ÿ™Ÿ™¨s¸È4Å-Õ8PÕQÜ�LŠL˜Ÿ™Ÿ™¨s¸È4Å-Õ8PÕQÜ�LŠL˜Ÿ™Ÿ™¨s¸ÐM_ÕC_ÐdhÕBhÕ8iÕjØ×1×1Ð1Ü—’˜V×;Ñ;×BÑBÈÐRXÐimÕ\mÕRn×oñ 2ñ /r5   c                ó–  € V P                   P                  pV P                   P                  pVf   Q R4       hVP                  VP                  4      pVRR R13,          P                  4       VR&   W$R&   Vf   Q R4       hVP                  VR8H  V4       \        P                  ! V^ 8¬  4      P                  4       '       g   Q R4       hV# )	Nz�self.model.config.decoder_start_token_id has to be defined. In Udop it is usually set to the pad_token_id. See Udop docs for more information.z1self.model.config.pad_token_id has to be defined.z8Verify that `shifted_input_ids` has only positive valuesr;   ).r_   ).r]   éœÿÿÿ)
rº   Údecoder_start_token_idÚpad_token_idÚ	new_zerosrn   rL  Úmasked_fill_r0   Úallr§   )r¹   Ú	input_idsr¹  rº  Úshifted_input_idss   &&   r3   Ú_shift_rightÚ UdopPreTrainedModel._shift_right  sÒ   € Ø!%§¡×!CÑ!CÐØ—{‘{×/Ñ/ˆà%Ò1ð 	
ð@ó	
Ð1ð &×/Ñ/°	·±Ó@ÐØ%.¨s°C°R°C¨xÕ%8×%>Ñ%>Ó%@Ð˜'Ñ"Ø$:˜&Ñ!àÒ'Ð\Ð)\Ó\Ð'à×&Ñ&Ð'8¸DÑ'@À,ÔOä�yŠyÐ*¨aÑ/Ó0×5Ñ5×7Ò7ÐsÐ9sÓsÐ7à Ð r5   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rÞ   r   )r2   rQ   s   "€r3   r4   Ú UdopPreTrainedModel.__annotate__Ó  s   ø‡ ‚ áÑò r5   rS   )ÚimageÚtextr;   )rT   rU   rV   rW   Úbase_model_prefixÚinput_modalitiesÚsupports_gradient_checkpointingÚ_can_compile_fullgraphÚ_keep_in_fp32_modulesÚ_supports_flash_attnÚ_supports_flex_attnÚ_supports_sdpar"   r‡  rj  r|  Ú_can_record_outputsr0   Úno_gradr¨  rÀ  rY   rZ   r[   rÇ   rÈ   s   @@r3   r¢  r¢  Ó  s’   ù‡ € ð &ÐØ(ÐØ&*Ð#à"ÐØ!˜FÐØ ÐØÐØ€Nð 	™¨	¸Ô;Ø‘nÐ%;À2ÔFØ™NÐ+BÈ"ÔMðÐð ‡]‚]ƒ_ô-pó ð-pò`!÷I … r5   r¢  c                   ó<   a a€ ] tR tRt oRV 3R lltR tRtVtV ;t# )ÚUdopCellEmbeddingsi.  c                óœ   <€ \         SV `  4        Wn        \        P                  ! W4      V n        \        P                  ! W4      V n        R # rð   )r°   r±   Úmax_2d_position_embeddingsr
   r$  Úx_position_embeddingsÚy_position_embeddings)r¹   rÓ  r³   r»   s   &&&€r3   r±   ÚUdopCellEmbeddings.__init__/  s8   ø€ Ü‰ÑÔØ*DÔ'ä%'§\¢\Ð2LÓ%ZˆÔ"Ü%'§\¢\Ð2LÓ%ZˆÖ"r5   c                ó¸  € \         P                  ! VR R4      pWP                  ^,
          ,          P                  4       pVP	                  ^ V P                  ^,
          4      pV P                  VR,          4      pV P                  VR,          4      pV P                  VR,          4      pV P                  VR,          4      pVV,           V,           V,           pV# )r{   r^   r   r‚   r�   rƒ   )r0   r‡   rÓ  r‰   r–  rÔ  rÕ  )r¹   r—   Úleft_position_embeddingsÚupper_position_embeddingsÚright_position_embeddingsÚlower_position_embeddingsrÄ   s   &&     r3   rÅ   ÚUdopCellEmbeddings.forward6  sÍ   € Ü�zŠz˜$  SÓ)ˆØ×7Ñ7¸!Õ;Õ<×BÑBÓDˆð �z‰z˜!˜T×<Ñ<¸qÕ@ÓAˆØ#'×#=Ñ#=¸dÀ7½mÓ#LÐ Ø$(×$>Ñ$>¸tÀG½}Ó$MÐ!Ø$(×$>Ñ$>¸tÀG½}Ó$MÐ!Ø$(×$>Ñ$>¸tÀG½}Ó$MÐ!ð %Ø'õ(à'õ(ð (õ(ð 	ð Ðr5   )rÓ  rÔ  rÕ  )iõ  é   rÚ   rÈ   s   @@r3   rÑ  rÑ  .  s   ù‡ € ÷[÷ò r5   rÑ  c                   óŒ   a a€ ] tR tRt oRtRV 3R llt]RV3R lR ll4       tRV3R lR lltR t	RV3R	 lR
 llt
RtVtV ;t# )r®  iQ  a�  
Base class of relative biases.

Args:
    num_heads (`int`):
        Number of attention heads in the model, it will create embeddings of size `num_heads`, which will be added to the scores of each token pair.
    relative_attention_num_buckets (`int`, *optional*, defaults to 32):
        Pair token metric (distance in the sequence, distance in pixels etc.) will be bucketed, parameter is defining number of such
        buckets.
    bidirectional (`bool`, *optional*, defaults to `True`):
        Whether the distance should be bidirectional for a pair of tokens. If `False`, then distance(tok1, tok2) == distance(tok2, tok1).
    scaling_factor (`int`, *optional*, defaults to 1):
        Defining factor which will be used to scale relative distance.
    max_distance (`int`, *optional*, defaults to 128):
        All distances above this value will end up in the one/same bucket.
    augmentation (`bool`, *optional*, defaults to `False`):
        Whether to multiply relative distances by a random scalar.
    expand (`bool`, *optional*, defaults to `False`):
        Whether to expand an existing pretrained model with subsequent additions of prefix_bucket.
c
                ó:  <€ \         SV `  4        W€n        Wpn        W`n        WPn        W@n        W0n        Wn        W�n	        W n
        V'       d   V P                  '       g   ^M^ p
\        P                  ! V P                  V
,           V P                  4      V n        R# )r%   N)r°   r±   Úprefix_bucketÚaugmentationÚlevelr1  Úscaling_factorr/  r  Úexpandr  r
   r$  r%  )r¹   r  r  r/  rã  r1  râ  rá  rà  rä  Ú
extra_headr»   s   &&&&&&&&&& €r3   r±   Ú!RelativePositionBiasBase.__init__g  sz   ø€ ô 	‰ÑÔØ*ÔØ(ÔØŒ
Ø(ÔØ,ÔØ*ÔØ"ŒØŒØ.LÔ+ß'°··°‘QÀˆ
Ü')§|¢|°D×4WÑ4WÐZdÕ4dÐfj×ftÑftÓ'uˆÖ$r5   c                ó^   <€ V ^8„  d   QhRS[ R,          RS[S[S[3,          R,          RS[ /# ©r%   r*   Nr—   Úreturn©r	   ÚdictÚstrr   )r2   rQ   s   "€r3   r4   Ú%RelativePositionBiasBase.__annotate__�  s:   ø€ ÷ ñ á �ðñ ‘3™�8�n˜tÕ#ðñ 
ñ	r5   c                ó   € R # rð   rS   )r¹   r*   r—   s   &&&r3   Úprepare_inputÚ&RelativePositionBiasBase.prepare_input€  s   € ñ 	r5   c                ó^   <€ V ^8„  d   QhRS[ R,          RS[S[S[3,          R,          RS[ /# rè  rê  )r2   rQ   s   "€r3   r4   rí  ˆ  s5   ø€ ÷ ñ ©°$­ð ÁTÉ#ÉsÈ(Å^ÐVZÕEZð Ñflñ r5   c                ó‚   € V P                  W4      p\        VV P                  V P                  V P                  R 7      pV# )r9  )rï  Úget_relative_position_bucketr/  r  r1  )r¹   r*   r—   r.  Ú	rp_buckets   &&&  r3   Ú
get_bucketÚ#RelativePositionBiasBase.get_bucketˆ  sC   € Ø ×.Ñ.¨~ÓDÐÜ8ØØ×,Ñ,Ø×;Ñ;Ø×*Ñ*ô	
ˆ	ð Ðr5   c                ó8  € VR,          pVR,          pW2,
          P                  4       pV P                  '       d1   V P                  '       d   V\        P                  ! \         ,          pW@P                  ,          pVP                  \        P                  4      # )r€   r†   )r€   Nr€   )
r1   rá  r:   ÚrandomÚuniformÚAUGMENTATION_RANGErã  rq   r0   r‰   )r¹   Ú	positionsr?  r@  r.  s   &&   r3   Úget_relative_positionÚ.RelativePositionBiasBase.get_relative_position’  sv   € Ø$ ZÕ0ÐØ# JÕ/ˆà,Õ?×FÑFÓHÐØ××Ð §§ Ø¤§¢Ô1CÐ!DÕDÐØ×0Ñ0Õ0Ðà ×#Ñ#¤E§J¡JÓ/Ð/r5   c                ó^   <€ V ^8„  d   QhRS[ R,          RS[S[S[3,          R,          RS[ /# rè  rê  )r2   rQ   s   "€r3   r4   rí  �  s5   ø€ ÷ ñ ¡f¨t¥mð Á$ÁsÉCÀxÅ.ÐSWÕBWð Ñciñ r5   c                óT  € V P                   '       d¶   V P                  '       d¤   \        P                  ! V P                  ^,           V P
                  4      pV P                  P                  P                  VP                  P                  RV P                  % RVP                  P                  V P                  R% W0n        RV n         V P                  W4      pV P                  '       dÍ   VP                  ^ 4      ^8X  d9   VP                  ^ 4      ^8”  d#   VP                  VP                  ^ 4      ^^4      pVR,          ^ 8  pVP                  R4      p\        VP                  4       P                  4       4       F6  w  rxV P                  WGRV1VR13&   V P                  ^,           WGVR1RV13&   K8  	  VP!                  ^ V P                  P"                  ^,
          4      pV P                  V4      p	V	P%                  4       ^8w  d   \'        R4      hV	P)                  . RO4      p	V	# )r%   Ngš™™™™™¹?Fz Wrong dimension of values tensorr‚   r;   )r]   r„   r`   r%   )rä  rà  r
   r$  r  r  r%  rÍ   Údatarõ  r=   rc   ÚsumÚ	enumerateÚcpuÚnumpyr–  Únum_embeddingsr8   r¿   r;  )
r¹   r*   r—   Únew_biasrô  Ú	is_prefixÚ
num_prefixÚidxÚnum_prefix_rowrB  s
   &&&       r3   rÅ   Ú RelativePositionBiasBase.forward�  sÆ  € à�;�;ˆ;˜4×-×-Ð-Ü—|’| D×$GÑ$GÈ!Õ$KÈTÏ^É^Ó\ˆHØJN×JfÑJf×JmÑJm×JrÑJrˆH�O‰O× Ñ Ð!F 4×#FÑ#FÐGØJMˆH�O‰O× Ñ  ×!DÑ!DÐ!FÐGØ+3Ô(ØˆDŒKà—O‘O NÓ9ˆ	à××ÐØ�~‰~˜aÓ  AÔ%¨.×*=Ñ*=¸aÓ*@À1Ô*DØ%×,Ñ,¨^×-@Ñ-@ÀÓ-CÀQÈÓJ�	à˜W�¨Ñ)ˆIØ"Ÿ™ rÓ*ˆJÜ'0°·±Ó1A×1GÑ1GÓ1IÖ'JÑ#�ØCG×CfÑCf�	˜ ˜°±Ð?Ñ@ØCG×CfÑCfÐijÕCj�	˜~™°°°Ð?Ó@ñ (Kð
 —O‘O A t×'CÑ'C×'RÑ'RÐUVÕ'VÓWˆ	Ø×5Ñ5°iÓ@ˆØ�:‰:‹<˜1ÔÜÐ?Ó@Ð@Ø—‘¢Ó-ˆàˆr5   )
rá  r/  rä  râ  r1  r  rà  r%  r  rã  )	Nrf  Tr`   rg  ÚtokensFFF©NN)rT   rU   rV   rW   rX   r±   r   rï  rõ  rü  rÅ   rZ   r[   rÇ   rÈ   s   @@r3   r®  r®  Q  sG   ù‡ € ñ÷*vð2 ÷ñ ó ð÷ò ò	0÷÷ ò r5   r®  c                   óL   a a€ ] tR tRt oRV 3R lltRV3R lR lltRtVtV ;t# )ÚRelativePositionBias1Di¼  c                ó0   <€ \         SV `  ! RRVRV/VB  R# )zš
Reimplementation of T5 relative position bias. Distance between given tokens is their distance in the sequence.
Parameters are the same as in base class
rã  r1  NrS   ©r°   r±   ©r¹   rã  r1  r.   r»   s   &&&,€r3   r±   ÚRelativePositionBias1D.__init__½  ó    ø€ ô
 	‰ÒÑ\¨Ð\À\Ð\ÐU[Ô\r5   c                ó^   <€ V ^8„  d   QhRS[ R,          RS[S[S[3,          R,          RS[ /# rè  rê  )r2   rQ   s   "€r3   r4   Ú#RelativePositionBias1D.__annotate__Ä  s6   ø€ ÷ !ñ !©F°T­Mð !ÉÉSÑRUÈXÍÐY]ÕH]ð !Ñioñ !r5   c                óê   € V P                   ^8w  d   \        R4      hV P                  \        P                  ! VP                  ^4      \        P                  VP                  R7      R,          4      pV# )r`   zNo need to scale 1d featuresr|   r:  )rã  r¿   rü  r0   ra   r=   r‰   r~   )r¹   r*   r—   r.  s   &&& r3   rï  Ú$RelativePositionBias1D.prepare_inputÄ  s`   € Ø×Ñ !Ô#ÜÐ;Ó<Ð<Ø ×6Ñ6Ü�LŠL˜×,Ñ,¨QÓ/´u·z±zÈ.×J_ÑJ_Ô`ÐahÕió
Ðð !Ð r5   rS   )r`   rg  r  ©	rT   rU   rV   rW   r±   rï  rZ   r[   rÇ   rÈ   s   @@r3   r  r  ¼  s   ù‡ € ÷]÷!÷ !ò !r5   r  c                   óL   a a€ ] tR tRt oRV 3R lltRV3R lR lltRtVtV ;t# )ÚRelativePositionBiasHorizontaliÎ  c                ó0   <€ \         SV `  ! RRVRV/VB  R# )zv
Represents in the bucket embeddings horizontal distance between two tokens. Parameters are the same as in base
class
rã  r1  NrS   r  r  s   &&&,€r3   r±   Ú'RelativePositionBiasHorizontal.__init__Ï  r  r5   c                ó^   <€ V ^8„  d   QhRS[ R,          RS[S[S[3,          R,          RS[ /# rè  rê  )r2   rQ   s   "€r3   r4   Ú+RelativePositionBiasHorizontal.__annotate__Ö  s6   ø€ ÷ ?ñ ?©F°T­Mð ?ÉÉSÑRUÈXÍÐY]ÕH]ð ?Ñioñ ?r5   c                ó¶   € V P                   R 8”  g   \        R4      hVf   \        R4      hVRR^ ^.3,          P                  RR7      pV P                  V4      # )r^   úENeed to scale the values of bboxes, as there are in small (0,1) rangez6Bbox is required for horizontal relative position biasr€   r7   r;   ©rã  r¿   r‹   rü  )r¹   r*   r—   Úhorizontal_positions   &&& r3   rï  Ú,RelativePositionBiasHorizontal.prepare_inputÖ  sb   € Ø×"Ñ" SÔ(ÜÐdÓeÐeØŠ<ÜÐUÓVÐVà&*¨1¨a°!°Q°¨<Õ&8×&=Ñ&=À"Ð&=Ó&EÐà×)Ñ)Ð*=Ó>Ð>r5   rS   ©éd   r&  r  r  rÈ   s   @@r3   r  r  Î  s   ù‡ € ÷]÷?÷ ?ò ?r5   r  c                   óL   a a€ ] tR tRt oRV 3R lltRV3R lR lltRtVtV ;t# )ÚRelativePositionBiasVerticaliá  c                ó0   <€ \         SV `  ! RRVRV/VB  R# )zt
Represents in the bucket embeddings vertical distance between two tokens. Parameters are the same as in base
class
rã  r1  NrS   r  r  s   &&&,€r3   r±   Ú%RelativePositionBiasVertical.__init__â  r  r5   c                ó^   <€ V ^8„  d   QhRS[ R,          RS[S[S[3,          R,          RS[ /# rè  rê  )r2   rQ   s   "€r3   r4   Ú)RelativePositionBiasVertical.__annotate__é  s6   ø€ ÷ =ñ =©F°T­Mð =ÉÉSÑRUÈXÍÐY]ÕH]ð =Ñioñ =r5   c                ó¶   € V P                   R 8”  g   \        R4      hVf   \        R4      hVRR^^.3,          P                  RR7      pV P                  V4      # )r^   r!  z4Bbox is required for vertical relative position biasr€   r7   r;   r"  )r¹   r*   r—   Úvertical_positions   &&& r3   rï  Ú*RelativePositionBiasVertical.prepare_inputé  sb   € Ø×"Ñ" SÔ(ÜÐdÓeÐeØŠ<ÜÐSÓTÐTà$(¨¨A°°1¨v¨Õ$6×$;Ñ$;ÀÐ$;Ó$CÐà×)Ñ)Ð*;Ó<Ð<r5   rS   r%  r  r  rÈ   s   @@r3   r(  r(  á  s   ù‡ € ÷]÷=÷ =ò =r5   r(  c                   óT   a a€ ] tR tRt oV3R lV 3R lltRV3R lR lltRtVtV ;t# )ÚRelativePositionBiasAggregatediô  c                ó0   <€ V ^8„  d   QhRS[ S[,          /# )r%   Úmodules)r   r®  )r2   rQ   s   "€r3   r4   Ú+RelativePositionBiasAggregated.__annotate__õ  s   ø€ ÷ 	-ñ 	-¡Ñ)AÕ Bñ 	-r5   c                óZ   <€ \         SV `  4        \        P                  ! V4      V n        R# )zŽ
Class which sums up various computed biases.

Args:
    modules (Sequence[RelativePositionBiasBase]):
        List of relative bias modules.
N)r°   r±   r
   rŒ  Úbiases)r¹   r3  r»   s   &&€r3   r±   Ú'RelativePositionBiasAggregated.__init__õ  s    ø€ ô 	‰ÑÔÜ—m’m GÓ,ˆŽr5   c                ón   <€ V ^8„  d   QhRS[ R,          RS[S[S[3,          R,          RS[S[ ,          /# rè  )r	   rë  rì  r   r1   )r2   rQ   s   "€r3   r4   r4     s;   ø€ ÷ ñ ¡f¨t¥mð Á$ÁsÉCÀxÅ.ÐSWÕBWð ÑchÑkqÕcqñ r5   c                óN   € R pV P                    F  pV! W4      V,           pK  	  V# )r{   ©r6  )r¹   r*   r—   Úoutputrã   s   &&&  r3   rÅ   Ú&RelativePositionBiasAggregated.forward   s+   € ØˆØ—K”KˆDÙ˜.Ó/°&Õ8ŠFñ  ð ˆr5   r:  r  rÚ   rÈ   s   @@r3   r1  r1  ô  s   ù‡ € ÷	-ó 	-÷÷ ò r5   r1  Ú1dÚ
horizontalÚverticalc                óF   € V ^8„  d   QhR\         R\        \        ,          /# ©r%   rº   ré  )r   r   r®  )r2   s   "r3   r4   r4     s    € ÷ ñ ¤ð ´Ô9QÕ0Rñ r5   c                ón  € . p\        V R4      '       d¡   V P                   F�  p\        V4      pVP                  R4      p\        V R4      '       d   V P                  MV P
                  pRV9   d   VR,          V8w  d   \        R4      hMWSR&   VP                  \        V,          ! R/ VB 4       K’  	  V# )zˆ
Creates empty list or one/multiple relative biases.

:param config: Model's configuration :return: Sequence with created bias modules.
Úrelative_bias_argsÚtyper  z4Number of heads must match num of heads in the modelrS   )	r³  rC  r   Úpopr  Únum_attention_headsr¿   rŽ  ÚBIAS_CLASSES)rº   Ú	bias_listÚbias_kwargs_orgÚbias_kwargsÚ	bias_typeÚmodel_num_headss   &     r3   Úcreate_relative_biasrM    s²   € ð €IÜˆvÐ+×,Ò,Ø%×8Ô8ˆOÜ" ?Ó3ˆKØ#Ÿ™¨Ó/ˆIÜ29¸&À+×2NÒ2N˜f×.Ò.ÐTZ×TnÑTnˆOØ˜kÔ)Ø˜{Õ+¨Ô>Ü$Ð%[Ó\Ð\ð ?ð ,;˜KÑ(Ø×Ñœ\¨)Ö4ÑC°{ÑCÖDñ  9ð Ðr5   c                   óˆ   a a€ ] tR tRt oRtV 3R lt]V3R lR l4       tR tR t	]
]RV3R lR	 ll4       4       tR
tVtV ;t# )Ú	UdopStacki%  z{
This class is based on `T5Stack`, but modified to take into account the image modality as well as 2D position
embeddings.
c                óð  <€ \         SV `  V4       \        P                  ! VP                  VP
                  4      V n        \        V4      V n        VP                  V n	        VP                  V n
        \        P                  ! \        V P                  4       Uu. uF  p\        V\        V^ 8H  4      VR7      NK  	  up4      V n        \!        VP
                  VP"                  R7      V n        \        P&                  ! VP(                  4      V n        V P                  '       g&   \-        VP.                  VP0                  4      V n        V P5                  V4      V n        V P9                  4        R# u upi )r]   r‹  r  N)r°   r±   r
   r$  Ú
vocab_sizerå   Úembed_tokensr¬   Úembed_patchesr  Ú
num_layersrŒ  r’   r‡  r�   ÚblockrÊ   r  Úfinal_layer_normré   rê   r,   rÑ  rÓ  r³   Úcell_2d_embeddingÚ_get_relative_biasÚrelative_biasÚ	post_init)r¹   rº   r¥   r»   s   && €r3   r±   ÚUdopStack.__init__+  s  ø€ Ü‰Ñ˜Ô äŸLšL¨×):Ñ):¸F¿N¹NÓKˆÔÜ0°Ó8ˆÔØ ×+Ñ+ˆŒØ ×+Ñ+ˆŒä—]’]Ü_dÐei×etÑetÔ_uÓvÑ_uÐZ[ŒY�v¼4ÀÀQÁ»<ÐST×UÑ_uÑvó
ˆŒ
ô !.¨f¯n©nÀ&×B[ÑB[Ô \ˆÔä—z’z &×"5Ñ"5Ó6ˆŒà��ˆÜ%7¸×8YÑ8YÐ[a×[mÑ[mÓ%nˆDÔ"ð "×4Ñ4°VÓ<ˆÔØ�‰Öùò ws   Â#E3c                ó&   <€ V ^8„  d   QhRS[ RS[/# rA  )r   r1  )r2   rQ   s   "€r3   r4   ÚUdopStack.__annotate__B  s    ø€ ÷ Bñ B¡:ð BÑ2Pñ Br5   c                ó.   € \        V 4      p\        V4      # rð   )rM  r1  )rº   Úrelative_bias_lists   & r3   rX  ÚUdopStack._get_relative_biasA  s   € ä1°&Ó9ÐÜ-Ð.@ÓAÐAr5   c                ó   € V P                   # rð   ©rR  ©r¹   s   &r3   Úget_output_embeddingsÚUdopStack.get_output_embeddingsF  s   € Ø× Ñ Ð r5   c                ó   € Wn         R # rð   rb  ©r¹   Únew_embeddingss   &&r3   Úset_input_embeddingsÚUdopStack.set_input_embeddingsI  s   € Ø*Ör5   c                ó6   <€ V ^8„  d   QhRS[ S[,          RS[/# )r%   r.   ré  )r   r   rH   )r2   rQ   s   "€r3   r4   r]  N  s+   ø€ ÷ P
ñ P
ñ Ñ+Õ,ðP
ñ 
*ñP
r5   c                óT	  € VR J VR J,          '       d)   V P                   '       d   RMRp\        RV RV R24      hVEe   \        P                  ! V4      ^ 8X  dè   \        P                  ! RV P
                  P                  VP                  VP                  R7      p\        P                  ! RVP                  VP                  R7      p\        P                  ! RVP                  VP                  R7      p\        P                  ! VR,          4      P                  V P                  4      p
\        P                  R4       Ve+   VP                  4       pVP                  RVR,          4      pMVP                  4       R R pVf   V P!                  V4      pVe   V P#                  V4      p	V	eƒ   V P
                  P$                  V P
                  P&                  ,          p\)        V	VVVVV^ V P
                  P$                  V P
                  P&                  4	      w  rcpVP                  4       R R pV P                   '       g   Ve   W`P+                  V4      ,          pVw  ppVRJ d   V P                   '       g   Q R	V  R
24       hV P                   '       du   V'       dl   Vfh   V P
                  P,                  '       d6   \/        \1        V P
                  R7      \1        V P
                  R7      4      pM+\1        V P
                  R7      pMV P                   '       g   R pVe   VP3                  4       M^ pVf=   \5        4       '       g-   VV,           p\        P6                  ! VVVP                  R7      pV P
                  P                   '       d   \9        V P
                  VVVR7      pM\;        V P
                  VVR7      pV P                   '       d   Ve   \;        V P
                  VVVR7      pMR pV P                   '       d   R p
MV P=                  W#R7      p
R pTpV P?                  V4      pV P@                   F5  pV! VVV
VVV3RV/VB w  pppTp
V P                   '       g   K-  Vf   K3  TpK7  	  V PC                  V4      pV P?                  V4      p\E        VVVR7      # )NÚdecoder_Ú z You must specify exactly one of zinput_ids or r–   rI  zEmpty batchTz)`use_cache` can only be set to `True` if z is used as a decoder)rº   )r~   )rº   r–   r*   rK   )rº   r–   r*   )rº   r–   r*   r—  )r*   r—   rK   )rJ   r*   rK   )é   rÝ  )ro  rÝ  ro  )r€   NNr€   r;   )#r  r¿   r0   ÚnumelÚfullrº   rº  r~   r}   rT  r”   rq   r  Úwarningr=   rd   rR  rS  re   rf   rª   rW  Úis_encoder_decoderr   r   rK  r   r“   r   r   rY  r,   rU  rV  rH   )r¹   r¾  r*   r—   r—  r˜  r–   rÀ   r˜   r•   r-   rK   Ú	use_cacher.   Úerr_msg_prefixr[  r™   rÁ   Ú
seq_lengthÚpast_key_values_lengthÚmask_seq_lengthÚcausal_maskÚencoder_extended_attention_maskr™  rL   Úlayer_moduleÚself_attention_position_biasÚcross_attention_position_biass   &&&&&&&&&&&&&,              r3   rÅ   ÚUdopStack.forwardL  s(  € ð( ˜Ð -°tÐ";×<Ô<Ø+/¯?¯?¨?™ZÀˆNÜØ2°>Ð2BÀ-ÐP^ÐO_Ð_lÐmóð ð Ó ¤U§[¢[°Ó%;¸qÔ%@ÜŸ
š
 9¨d¯k©k×.FÑ.FÈy×O_ÑO_Ðgp×gvÑgvÔwˆIÜ"Ÿ[š[¨¸9×;KÑ;KÐS\×SbÑSbÔcˆNÜ—;’;˜|°I×4DÑ4DÈIÏOÉOÔ\ˆDÜ!×,Ò,¨^Ð<LÕ-MÓN×QÑQÐRV×R\ÑR\Ó]ˆMÜ�N‰N˜=Ô)àÒ Ø#Ÿ.™.Ó*ˆKØ!Ÿ™ r¨;°r­?Ó;‰Ià'×,Ñ,Ó.¨s°Ð3ˆKàÒ Ø ×-Ñ-¨iÓ8ˆMàÒ#Ø#×1Ñ1°,Ó?ÐàÒ'àŸ+™+×0Ñ0°D·K±K×4JÑ4JÕJˆKÜ2OØ ØØØØØØØ—‘×&Ñ&Ø—‘×&Ñ&ó
3Ñ/ˆM ð (×,Ñ,Ó.¨s°Ð3ˆKà��ˆ 4Ò#3Ø×3Ñ3°DÓ9Õ9ˆMà!,Ñˆ
�Jà˜ÓØ—?—?�?ÐkÐ&OÐPTÈvÐUjÐ$kÓk�?à�?�?ˆ?ß˜_Ò4Ø—;‘;×1×1Ð1Ü&9Ü$¨D¯K©KÔ8¼,ÈdÏkÉkÔ:Zó'‘Oô '3¸$¿+¹+Ô&F�OøØ——�ð #ˆOàETÒE` ×!?Ñ!?Ô!AÐfgÐØÒ!Ô*B×*DÒ*Dà4°zÕAˆOÜ"ŸZšZ¨
°OÈM×L`ÑL`ÔaˆNà�;‰;×!×!Ð!Ü,Ø—{‘{Ø+Ø-Ø /ô	‰Kô 4Ø—{‘{Ø+Ø-ôˆKð �?�?ˆ?Ð5ÒAÜ.GØ—{‘{Ø+Ø5Ø&;ô	/Ñ+ð /3Ð+à�?�?ˆ?Ø ‰Mà ×.Ñ.¸nÐ.ÓXˆMØ(,Ð%à%ˆàŸ™ ]Ó3ˆà ŸJœJˆLÙYeØØØØ%Ø/Ø-ñ	Zð !0ð	Zð ñ	ZÑVˆMÐ7Ð9Vð 9ˆMØ��ŠÐ#8Ô#DØ0MÒ-ñ 'ð" ×-Ñ-¨mÓ<ˆØŸ™ ]Ó3ˆä/Ø+Ø)Ø+ô
ð 	
r5   )	rU  rW  r,   rS  rR  rV  r  rT  rY  ©NNNNNNNNNNNN)rT   rU   rV   rW   rX   r±   rh  rX  rd  ri  r!   r#   rÅ   rZ   r[   rÇ   rÈ   s   @@r3   rO  rO  %  sY   ù‡ € ñõ
ð, ÷Bó ðBò!ò+ð  Ø÷P
ñ P
ó ó  ÷P
ð P
r5   rO  c                   ó|   a a€ ] tR tRt oRRRRRRRR/tV 3R	 ltR
 tR t]]	RV3R lR ll4       4       t
RtVtV ;t# )r°  iá  úencoder.embed_tokens.weightúshared.weightúdecoder.embed_tokens.weightú!encoder.embed_patches.proj.weightúpatch_embed.proj.weightúencoder.embed_patches.proj.biasúpatch_embed.proj.biasc                ó~  <€ \         SV `  V4       \        P                  ! VP                  VP
                  4      V n        \        V4      V n        \        V4      pR Vn
        R Vn        \        V4      V n        \        V4      pRVn
        VP                  Vn        \        V4      V n        V P#                  4        R# )FTN)r°   r±   r
   r$  rQ  rå   r±  r¬   Úpatch_embedr   r  rt  rO  ÚencoderÚnum_decoder_layersrT  ÚdecoderrZ  ©r¹   rº   Úencoder_configÚdecoder_configr»   s   &&  €r3   r±   ÚUdopModel.__init__ê  s™   ø€ Ü‰Ñ˜Ô ô —l’l 6×#4Ñ#4°f·n±nÓEˆŒÜ.¨vÓ6ˆÔä! &Ó)ˆØ$)ˆÔ!Ø#(ˆÔ Ü  Ó0ˆŒä! &Ó)ˆØ$(ˆÔ!Ø$*×$=Ñ$=ˆÔ!Ü  Ó0ˆŒð 	�‰Ör5   c                ó   € V P                   # rð   ©r±  rc  s   &r3   Úget_input_embeddingsÚUdopModel.get_input_embeddingsþ  ó   € Ø�{‰{Ðr5   c                ó~   € Wn         V P                  P                  V4       V P                  P                  V4       R # rð   ©r±  rŠ  ri  rŒ  rg  s   &&r3   ri  ÚUdopModel.set_input_embeddings  ó+   € Ø$ŒØ�‰×)Ñ)¨.Ô9Ø�‰×)Ñ)¨.Ö9r5   c                óR  <€ V ^8„  d   QhRS[ R,          RS[ R,          RS[S[S[3,          R,          RS[ R,          RS[S[S[3,          R,          RS[ R,          RS[ R,          R	S[ R,          R
S[ R,          RS[R,          RS[ R,          RS[R,          RS[S[,          RS[/# )r%   r¾  Nr*   r—   rÀ   r˜   Údecoder_input_idsÚdecoder_attention_maskr–   Úencoder_outputsrK   Údecoder_inputs_embedsrt  r.   ré  )	r	   rë  rì  r   r   r�   r   r   r   )r2   rQ   s   "€r3   r4   ÚUdopModel.__annotate__  sï   ø€ ÷ i
ñ i
á˜D•=ði
ñ  �ði
ñ ‘3™�8�n˜tÕ#ð	i
ñ
 ˜t•mði
ñ ™#™s˜(•^ dÕ*ði
ñ " D�=ði
ñ !'¨¥ði
ñ  •}ði
ñ   $�ði
ñ  �ði
ñ  &¨�}ði
ñ ˜$•;ði
ñ Ñ+Õ,ði
ñ 
ñi
r5   c                óv  € V	f   V P                   ! RRVRVRVRVRVRV/VB p	V	^ ,          pV	P                  pV P                  ! RRVRVRVRV
RVR	VR
V/VB p\        VP                  VP
                  VP                  VP                  VP                  V	P                  V	P                  V	P                  R7      # )aá
  
bbox (`torch.LongTensor` of shape `({0}, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner.

    Note that `sequence_length = token_sequence_length + patch_sequence_length + 1` where `1` is for [CLS]
    token. See `pixel_values` for `patch_sequence_length`.
visual_bbox (`torch.LongTensor` of shape `(batch_size, patch_sequence_length, 4)`, *optional*):
    Bounding boxes of each patch in the image. If not provided, bounding boxes are created in the model.
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) T5 uses the `pad_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`). To know more on how to prepare
    `decoder_input_ids` for pretraining take a look at [T5 Training](./t5#training).
decoder_attention_mask (`torch.BoolTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
    Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
    be used by default.

Example:

```python
>>> from transformers import AutoProcessor, AutoModel
>>> from datasets import load_dataset
>>> import torch

>>> # load model and processor
>>> # in this case, we already have performed OCR ourselves
>>> # so we initialize the processor with `apply_ocr=False`
>>> processor = AutoProcessor.from_pretrained("microsoft/udop-large", apply_ocr=False)
>>> model = AutoModel.from_pretrained("microsoft/udop-large")

>>> # load an example image, along with the words and coordinates
>>> # which were extracted using an OCR engine
>>> dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train")
>>> example = dataset[0]
>>> image = example["image"]
>>> words = example["tokens"]
>>> boxes = example["bboxes"]
>>> inputs = processor(image, words, boxes=boxes, return_tensors="pt")

>>> decoder_input_ids = torch.tensor([[model.config.decoder_start_token_id]])

>>> # forward pass
>>> outputs = model(**inputs, decoder_input_ids=decoder_input_ids)
>>> last_hidden_states = outputs.last_hidden_state
>>> list(last_hidden_states.shape)
[1, 1, 1024]
```r¾  r*   r—   rÀ   r˜   r–   rK   r—  r˜  rt  )rJ   rK   Údecoder_hidden_statesÚdecoder_attentionsrN   Úencoder_last_hidden_stater—  Úencoder_attentionsrS   )	rŠ  r*   rŒ  r   rJ   rK   rL   rM   rN   )r¹   r¾  r*   r—   rÀ   r˜   r›  rœ  r–   r�  rK   rž  rt  r.   rL   r˜  Údecoder_outputss   &&&&&&&&&&&&&,   r3   rÅ   ÚUdopModel.forward  s&  € ðP Ò"Ø"Ÿlšlñ Ø#ðà-ðð ðð *ð	ð
 (ðð ,ðð ñˆOð (¨Õ*ˆØ!0×!?Ñ!?Ðð Ÿ,š,ñ 	
Ø'ð	
à1ð	
ð 0ð	
ð ,ð		
ð
 #0ð	
ð $:ð	
ð  ð	
ð ñ	
ˆô "Ø-×?Ñ?Ø+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô	
ð 		
r5   )rŒ  rŠ  r‰  r±  r  ©rT   rU   rV   rW   Ú_tied_weights_keysr±   r“  ri  r    r   rÅ   rZ   r[   rÇ   rÈ   s   @@r3   r°  r°  á  s^   ù‡ € ð 	& Ø% Ø+Ð-FØ)Ð+Bð	Ðõò(ò:ð
 Ø÷i
ñ i
ó ó ÷i
ð i
r5   r°  a  
    The UDOP encoder-decoder Transformer with a language modeling head on top, enabling to generate text given document
    images and an optional prompt.

    This class is based on [`T5ForConditionalGeneration`], extended to deal with images and layout (2D) data.
    c                   óˆ   a a€ ] tR tRt oRRRRRRRRR	R
RR
RR/tV 3R ltR tR t]]	RV3R lR ll4       4       t
RtVtV ;t# )r²  it  r�  r‚  rƒ  r„  r…  r†  r‡  ú=encoder.relative_bias.biases.0.relative_attention_bias.weightúDencoder.block.0.layer.0.SelfAttention.relative_attention_bias.weightz=decoder.relative_bias.biases.0.relative_attention_bias.weightzlm_head.weightc                óâ  <€ \         SV `  V4       \        P                  ! VP                  VP
                  4      V n        \        V4      V n        \        V4      pR Vn
        R Vn        \        V4      V n        \        V4      pRVn
        VP                  Vn        \        V4      V n        \        P"                  ! VP
                  VP                  R R7      V n        V P'                  4        R# )FTrâ   N)r°   r±   r
   r$  rQ  rå   r±  r¬   r‰  r   r  rt  rO  rŠ  r‹  rT  rŒ  rä   r§  rZ  r�  s   &&  €r3   r±   Ú%UdopForConditionalGeneration.__init__‡  s¹   ø€ Ü‰Ñ˜Ô ô —l’l 6×#4Ñ#4°f·n±nÓEˆŒÜ.¨vÓ6ˆÔä! &Ó)ˆØ$)ˆÔ!Ø#(ˆÔ Ü  Ó0ˆŒä! &Ó)ˆØ$(ˆÔ!Ø$*×$=Ñ$=ˆÔ!Ü  Ó0ˆŒô —y’y §¡°×1BÑ1BÈÔOˆŒð 	�‰Ör5   c                ó   € V P                   # rð   r’  rc  s   &r3   r“  Ú1UdopForConditionalGeneration.get_input_embeddingsž  r•  r5   c                ó~   € Wn         V P                  P                  V4       V P                  P                  V4       R # rð   r—  rg  s   &&r3   ri  Ú1UdopForConditionalGeneration.set_input_embeddings¡  r™  r5   c                óf  <€ V ^8„  d   QhRS[ R,          RS[ R,          RS[S[S[3,          R,          RS[ R,          RS[S[S[3,          R,          RS[ R,          RS[ R,          R	S[ R,          R
S[ R,          RS[R,          RS[ R,          RS[R,          RS[ R,          RS[S[,          RS[/# )r%   r¾  Nr*   r—   rÀ   r˜   r›  rœ  r–   r�  rK   rž  rt  Úlabelsr.   ré  )	r	   rë  rì  r   r   r�   r   r   r   )r2   rQ   s   "€r3   r4   Ú)UdopForConditionalGeneration.__annotate__¨  sþ   ø€ ÷ ~
ñ ~
á˜D•=ð~
ñ  �ð~
ñ ‘3™�8�n˜tÕ#ð	~
ñ
 ˜t•mð~
ñ ™#™s˜(•^ dÕ*ð~
ñ " D�=ð~
ñ !'¨¥ð~
ñ  •}ð~
ñ   $�ð~
ñ  �ð~
ñ  &¨�}ð~
ñ ˜$•;ð~
ñ ˜•ð~
ñ Ñ+Õ,ð~
ñ  
ñ!~
r5   c                óÜ  € Vf   Ve   V P                  V4      pV	f   V P                  ! RRVRVRVRVRVRV/VB p	V	^ ,          pV	P                  pV P                  ! RRVRVRVRV
R	VR
VRV/VB pV^ ,          pV P                  P
                  '       d%   VV P                  P                  R,          ,          pV P                  V4      pRpVeD   \        RR7      pV! VP                  RVP                  R4      4      VP                  R4      4      p\        VVVP                  VP                  VP                  VP                  V	P                   V	P                  V	P                  R7	      # )a°  
bbox (`torch.LongTensor` of shape `({0}, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner.

    Note that `sequence_length = token_sequence_length + patch_sequence_length + 1` where `1` is for [CLS]
    token. See `pixel_values` for `patch_sequence_length`.
visual_bbox (`torch.LongTensor` of shape `(batch_size, patch_sequence_length, 4)`, *optional*):
    Bounding boxes of each patch in the image. If not provided, bounding boxes are created in the model.
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) T5 uses the `pad_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`). To know more on how to prepare
    `decoder_input_ids` for pretraining take a look at [T5 Training](./t5#training).
decoder_attention_mask (`torch.BoolTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
    Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
    be used by default.
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
    Labels for computing the language modeling loss. Indices should be in `[-100, 0, ..., config.vocab_size -
    1]`. All labels set to `-100` are ignored (masked), the loss is only computed for labels in `[0, ...,
    config.vocab_size]`.

Examples:

```python
>>> from transformers import AutoProcessor, UdopForConditionalGeneration
>>> from datasets import load_dataset

>>> # load model and processor
>>> # in this case, we already have performed OCR ourselves
>>> # so we initialize the processor with `apply_ocr=False`
>>> processor = AutoProcessor.from_pretrained("microsoft/udop-large", apply_ocr=False)
>>> model = UdopForConditionalGeneration.from_pretrained("microsoft/udop-large")

>>> # load an example image, along with the words and coordinates
>>> # which were extracted using an OCR engine
>>> dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train")
>>> example = dataset[0]
>>> image = example["image"]
>>> words = example["tokens"]
>>> boxes = example["bboxes"]

>>> # one can use the various task prefixes (prompts) used during pre-training
>>> # e.g. the task prefix for DocVQA is "Question answering. "
>>> question = "Question answering. What is the date on the form?"
>>> encoding = processor(image, question, text_pair=words, boxes=boxes, return_tensors="pt")

>>> # autoregressive generation
>>> predicted_ids = model.generate(**encoding)
>>> print(processor.batch_decode(predicted_ids, skip_special_tokens=True)[0])
9/30/92
```Nr¾  r—   r˜   rÀ   r*   r–   rK   r—  r˜  rt  )Úignore_index)	ÚlossÚlogitsrK   r¡  r¢  rN   r£  r—  r¤  rS   r<   r¸  r;   )rÀ  rŠ  r*   rŒ  rº   r´  rå   r§  r   rd   r=   r   rK   rL   rM   rN   rJ   )r¹   r¾  r*   r—   rÀ   r˜   r›  rœ  r–   r�  rK   rž  rt  r³  r.   rL   r˜  r¥  Úsequence_outputÚ	lm_logitsr·  Úloss_fcts   &&&&&&&&&&&&&&,       r3   rÅ   Ú$UdopForConditionalGeneration.forward¦  sÀ  € ðX Ò$¨Ò);Ø $× 1Ñ 1°&Ó 9Ðð Ò"Ø"Ÿlšlñ Ø#ðàðð (ðð *ð	ð
  .ðð ,ðð ñˆOð (¨Õ*ˆØ!0×!?Ñ!?Ðð Ÿ,š,ñ 	
Ø'ð	
à1ð	
ð 0ð	
ð ,ð		
ð
 #0ð	
ð $:ð	
ð  ð	
ð ñ	
ˆð *¨!Õ,ˆà�;‰;×*×*Ð*Ø-°·±×1DÑ1DÀdÕ1JÕKˆOà—L‘L Ó1ˆ	àˆØÒÜ'°TÔ:ˆHÙ˜IŸN™N¨2¨y¯~©~¸bÓ/AÓBÀFÇKÁKÐPRÃOÓTˆDäØØØ+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô

ð 
	
r5   )rŒ  rŠ  r§  r‰  r±  )NNNNNNNNNNNNNr§  rÈ   s   @@r3   r²  r²  t  sw   ù‡ € ð 	& Ø% Ø+Ð-FØ)Ð+BØGð  JPØGð  JPØ˜/ðÐõò.ò:ð
 Ø÷~
ñ ~
ó ó ÷~
ð ~
r5   r²  c                   óˆ   a a€ ] tR tRt oRRRRRRRR	/tV3R
 lV 3R lltR tR t]]	RV3R lR ll4       4       t
RtVtV ;t# )ÚUdopEncoderModeli)  r�  r‚  r„  r…  r†  r‡  rª  r«  c                ó    <€ V ^8„  d   QhRS[ /# rÞ   r   )r2   rQ   s   "€r3   r4   ÚUdopEncoderModel.__annotate__2  s   ø€ ÷ ñ ™zñ r5   c                ó&  <€ \         SV `  V4       \        P                  ! VP                  VP
                  4      V n        \        V4      V n        \        V4      pR Vn
        R Vn        R Vn        \        V4      V n        V P                  4        R# ry  )r°   r±   r
   r$  rQ  rå   r±  r¬   r‰  r   r  rt  rs  rO  rŠ  rZ  )r¹   rº   rŽ  r»   s   && €r3   r±   ÚUdopEncoderModel.__init__2  su   ø€ Ü‰Ñ˜Ô ô —l’l 6×#4Ñ#4°f·n±nÓEˆŒÜ.¨vÓ6ˆÔä! &Ó)ˆØ$)ˆÔ!Ø#(ˆÔ Ø,1ˆÔ)Ü  Ó0ˆŒð 	�‰Ör5   c                ó   € V P                   # rð   r’  rc  s   &r3   r“  Ú%UdopEncoderModel.get_input_embeddingsB  r•  r5   c                óH   € Wn         V P                  P                  V4       R # rð   )r±  rŠ  ri  rg  s   &&r3   ri  Ú%UdopEncoderModel.set_input_embeddingsE  s   € Ø$ŒØ�‰×)Ñ)¨.Ö9r5   c                óÚ   <€ V ^8„  d   QhRS[ R,          RS[S[S[3,          R,          RS[ R,          RS[ R,          RS[S[S[3,          R,          RS[ R,          RS[S[,          R	S[/# )
r%   r¾  Nr—   r*   rÀ   r˜   r–   r.   ré  )r	   rë  rì  r   r   r   rH   )r2   rQ   s   "€r3   r4   rÀ  K  s•   ø€ ÷ Añ Aá˜D•=ðAñ ‘3™�8�n˜tÕ#ðAñ  �ð	Añ
 ˜t•mðAñ ™#™s˜(•^ dÕ*ðAñ  •}ðAñ Ñ+Õ,ðAñ 
*ñAr5   c                óB   € V P                   ! RRVRVRVRVRVRV/VB pV# )a®  
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
    Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
    should be able to pad the inputs on both the right and the left.

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

    To know more on how to prepare `input_ids` for pretraining take a look a [T5 Training](./t5#training).
bbox (`torch.LongTensor` of shape `({0}, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner.

    Note that `sequence_length = token_sequence_length + patch_sequence_length + 1` where `1` is for [CLS]
    token. See `pixel_values` for `patch_sequence_length`.
visual_bbox (`torch.LongTensor` of shape `(batch_size, patch_sequence_length, 4)`, *optional*):
    Bounding boxes of each patch in the image. If not provided, bounding boxes are created in the model.

Example:

```python
>>> from transformers import AutoProcessor, UdopEncoderModel
>>> from huggingface_hub import hf_hub_download
>>> from datasets import load_dataset

>>> # load model and processor
>>> # in this case, we already have performed OCR ourselves
>>> # so we initialize the processor with `apply_ocr=False`
>>> processor = AutoProcessor.from_pretrained("microsoft/udop-large", apply_ocr=False)
>>> model = UdopEncoderModel.from_pretrained("microsoft/udop-large")

>>> # load an example image, along with the words and coordinates
>>> # which were extracted using an OCR engine
>>> dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train")
>>> example = dataset[0]
>>> image = example["image"]
>>> words = example["tokens"]
>>> boxes = example["bboxes"]
>>> encoding = processor(image, words, boxes=boxes, return_tensors="pt")

>>> outputs = model(**encoding)
>>> last_hidden_states = outputs.last_hidden_state
```r¾  r—   r˜   rÀ   r*   r–   rS   )rŠ  )	r¹   r¾  r—   r*   rÀ   r˜   r–   r.   r�  s	   &&&&&&&, r3   rÅ   ÚUdopEncoderModel.forwardI  s]   € ðr Ÿ,š,ñ 
Øð
àð
ð $ð
ð &ð	
ð
 *ð
ð (ð
ð ñ
ˆð Ðr5   )rŠ  r‰  r±  r   r§  rÈ   s   @@r3   r¾  r¾  )  sh   ù‡ € ð 	& Ø+Ð-FØ)Ð+BØGð  JPð	Ð÷ó ò ò:ð Ø÷Añ Aó ó ÷Að Ar5   r¾  )Nr{   N)éà   é   )r]   )Né   r]   rÊ  rË  )gš™™™™™é?g      ô?)r²  r¢  r°  r¾  )^rX   r´   Úloggingr,  rø  rµ   r   r   Úcollections.abcr   r   Úcopyr   Údataclassesr   Útypingr   r0   r	   r
   Útorch.nnr   Útransformersr   Útransformers.modeling_outputsr   r   rn  r   rª  Úactivationsr   Úcache_utilsr   r   r   Ú
generationr   Úmasking_utilsr   r   Úmodeling_layersr   Úmodeling_utilsr   r   Úprocessing_utilsr   Úutilsr   r   r   r   Úutils.genericr    r!   Úutils.output_capturingr"   r#   Ú	getLoggerrT   r  rE   rH   rk   ry   rª   r/   r¬   rÊ   rÜ   rô   r   r  rj  r|  r‡  r¢  rÑ  r6  ró  rú  r®  r  r  r(  r1  rG  rM  rO  r°  r²  r¾  Ú__all__rS   r5   r3   Ú<module>rá     s‰  ðñ ã Û Û Û ß #ß .Ý Ý !Ý ã ß Ý %å #÷õ
 'Ý !ß CÑ CÝ )ß JÝ 9ß FÝ &÷ó ÷ Jß Eð 
×	Ò	˜8Ó	$€÷%ñ@ ðôð ô#= {ó #=ó óð#=ôLô.
ôP/ôf˜"Ÿ)™)ô ô<+�B—I‘Iô +ô4˜Ÿ	™	ô ô.˜RŸY™Yô ô<�"—)‘)ô ô&A8�B—I‘Iô A8ôJ=˜RŸY™Yô =ôB9˜bŸi™iô 9ô@LPÐ*ô LPð^ ôW!˜/ó W!ó ðW!ôt˜Ÿ™ô ð>  -×FÑFÐ Ø!Ð ôh˜rŸy™y¨#ô hôV!Ð5ô !ô$?Ð%=ô ?ô&=Ð#;ô =ô& R§Y¡Yô ð* 	Ð
 ØÐ0ØÐ,ð€õô,y
Ð#ô y
ðx ôO
Ð#ó O
ó ðO
ñd ðôôj
Ð#6¸ó j
óðj
ðZ ôbÐ*ó bó ðbòJ c‚r5   