+
    œ°³jŸ[ ã                   óÂ  € R t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIt^ RIH	t	 ^RI
Ht ^RI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HtHtH t  ^RI!H"t"H#t#H$t$H%t%H&t& ]PN                  ! ](4      t)Rt*^ t+Rt,]&]$,          ]%,          t-]! RR7      ] ! R R]4      4       4       t.]! RR7      ] ! R R]4      4       4       t/]! RR7      ] ! R R]4      4       4       t0 ! R R]	Pb                  4      t2 ! R R]	Pb                  4      t3 ! R R ]	Pb                  4      t4 ! R! R"]	Pb                  4      t5 ! R# R$]	Pb                  4      t6 ! R% R&]	Pb                  4      t7 ! R' R(]	Pb                  4      t8 ! R) R*]	Pb                  4      t9 ! R+ R,]4      t: ! R- R.]	Pb                  4      t; ! R/ R0]	Pb                  4      t<] ! R1 R2]4      4       t=] ! R3 R4]=4      4       t>] ! R5 R6]=4      4       t?] ! R7 R8]=4      4       t@] ! R9 R:]=4      4       tA ! R; R<]	Pb                  4      tB ! R= R>]	Pb                  4      tC ! R? R@]	Pb                  4      tD]! RAR7       ! RB RC]=4      4       tE ! RD RE]	Pb                  4      tF ! RF RG]	Pb                  4      tG ! RH RI]	Pb                  4      tH ! RJ RK]	Pb                  4      tI]! RLR7       ! RM RN]=4      4       tJ. ROOtKR# )PzPyTorch FLAVA model.N)ÚOrderedDict)Ú	dataclass)ÚAny)Únn)Úinitialization)ÚACT2FN)Úcreate_bidirectional_mask)ÚGradientCheckpointingLayer)ÚBaseModelOutputÚBaseModelOutputWithPooling)ÚPreTrainedModel)ÚUnpack)ÚModelOutputÚTransformersKwargsÚauto_docstringÚcan_return_tupleÚloggingÚ	torch_int)ÚFlavaConfigÚFlavaImageCodebookConfigÚFlavaImageConfigÚFlavaMultimodalConfigÚFlavaTextConfigzfacebook/flava-image-codebookg$(~Œ¹k@a–  
    Output from FlavaModel containing embeddings and outputs from individual encoders.

    Note that `image_embeddings` and `text_embeddings` returned are similar to pooled output returned from a
    transformer. If you want embeddings for contrastive loss or retrieval use a FLAVA model's `image_projection` and
    `text_projection` layers on `image_embeddings` and `text_embeddings` respectively.
    )Úcustom_introc                   óZ   a € ] tR t^4t o RtRtRtRtRtRt	Rt
V 3R lR ltV 3R ltRtV tR# )ÚFlavaModelOutputa¸  
image_embeddings (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when `pixel_values` are present):
    The image embeddings which are basically the pooled output of [`FlavaImageModel`].
image_output (`BaseModelOutputWithPooling`, *optional*, returned when `pixel_values` are present):
    The output of the [`FlavaImageModel`].
text_embeddings (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when `input_ids` are present):
    The text embeddings which are basically the pooled output of [`FlavaTextModel`].
text_output (`BaseModelOutputWithPooling`, *optional*, returned when `input_ids` are present):
    The output of the [`FlavaTextModel`].
multimodal_embeddings (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when `input_ids` and `pixel_values` are present and `skip_multimodal_encoder` is `None` or `False`):
    The multimodal embeddings which are basically the pooled output of [`FlavaTextModel`].
multimodal_output (`BaseModelOutputWithPooling`, returned when `input_ids` and `pixel_values` are present and `skip_multimodal_encoder` is `None` or `False`):
    The output of the [`FlavaMultimodalModel`].
Nc                ó0   <€ V ^8„  d   QhRS[ S[,          /# ©é   Úreturn©Útupler   )ÚformatÚ__classdict__s   "€Úi/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/flava/modeling_flava.pyÚ__annotate__ÚFlavaModelOutput.__annotate__U   s   ø€ ÷ 
ñ 
™%¡�*ñ 
ó    c                ó    a € \         ;QJ d%    . V 3R  lS P                  4        4       F  NK  	  5# ! V 3R  lS P                  4        4       4      # )c              3   óx   <"  € T F/  pVR9  d
   SV,          M\        SV4      P                  4       x € K1  	  R# 5i)Útext_outputN)r*   Úimage_outputÚmultimodal_output©ÚgetattrÚto_tuple)Ú.0ÚkÚselfs   & €r$   Ú	<genexpr>Ú,FlavaModelOutput.to_tuple.<locals>.<genexpr>V   s<   øé € ð 
á �ð Ð TÔTˆD�ŽGÔZaÐbfÐhiÓZj×ZsÑZsÓZuÔuÛ ùs   ƒ7:©r!   Úkeys©r2   s   fr$   r/   ÚFlavaModelOutput.to_tupleU   sA   ø€ ßŒuô 
à—Y‘Y”[ó
�uð 	
ˆuô 
à—Y‘Y”[ó
ó 
ð 	
r'   c                óò   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[R,          ;R&   S[ P                  R,          ;R&   S[R,          ;R&   S[ P                  R,          ;R&   S[R,          ;R&   # )r   NÚimage_embeddingsr+   Útext_embeddingsr*   Úmultimodal_embeddingsr,   )ÚtorchÚFloatTensorr   )r"   r#   s   "€r$   r%   r&   4   sƒ   ø‡ ‚ ñ4 ×'Ñ'¨$Õ.Ñ5ñ5 ñ6 -¨tÕ3Ñ:ñ7 ñ8 ×&Ñ&¨Õ-Ñ4ñ9 ñ: ,¨dÕ2Ñ9ñ; ñ< !×,Ñ,¨tÕ3Ñ:ñ= ñ> 2°DÕ8Ñ?ò? r'   © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r:   r+   r;   r*   r<   r,   r/   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r#   s   @r$   r   r   4   s?   ø‡ € ñð 26ÐØ6:€LØ04€OØ59€KØ6:ÐØ;?Ð÷
ð 
÷C ƒ r'   r   z@
    Class representing pretraining losses from FLAVA model
    c                   óZ   a € ] tR t^\t o RtRtRtRtRtRt	Rt
V 3R lR ltV 3R ltRtV tR# )ÚFlavaLossesas  
mim (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `mim_labels` and `pixel_values` are present, `input_ids_masked` is absent and `mim_weight` > 0.):
    Masked Image Modeling loss as used in BeIT calculated only for unimodal image data.
mlm (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `mlm_labels` and `input_ids_masked` are present, `pixel_values` is absent and `mlm_weight` > 0.):
    Masked Language Modeling loss as used in BERT calculated only for unimodal text data.
itm (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `itm_labels`, `input_ids_masked`, `pixel_values` are present and `itm_weight` > 0.):
    Image Text Matching (ITM) loss calculated for paired image-text data. Note that ITM loss is calculated on
    masked pairs in FLAVA.
global_contrastive (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `input_ids` and `pixel_values` are present and `global_contrastive_weight` > 0.):
    Contrastive loss for image-text similarity similar to CLIP but calculated globally for paired image-text
    data. This is calculated on unmasked images and texts.
mmm_image (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `mim_labels`, `pixel_values` and `input_ids_masked` are present and `mmm_image_weight` > 0.):
    Masked Multimodal Modeling loss's image component calculated on paired image-text data.
mmm_text (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `mlm_labels`, `pixel_values` and `input_ids_masked` are present and `mmm_text_weight` > 0.):
    Masked Multimodal Modeling loss's text component calculated on paired image-text data.
Nc                ó    <€ V ^8„  d   QhRS[ /# r   )Úbool)r"   r#   s   "€r$   r%   ÚFlavaLosses.__annotate__{   s   ø€ ÷ ñ ™$ñ r'   c                óJ   € R pV P                  4        F  pVf   K	  Rp V# 	  V# )TF)Úvalues)r2   Úall_noneÚvs   &  r$   rP   ÚFlavaLosses.all_none{   s0   € ØˆØ—‘–ˆAØŒ}Ø �ØØˆñ	 ð ˆr'   c                ó.  <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   # )r   NÚmimÚmlmÚitmÚglobal_contrastiveÚ	mmm_imageÚmmm_text)r=   r>   )r"   r#   s   "€r$   r%   rM   \   s•   ø‡ ‚ ñ0 
×	Ñ	˜TÕ	!Ñ(ñ1 ñ2 
×	Ñ	˜TÕ	!Ñ(ñ3 ñ4 
×	Ñ	˜TÕ	!Ñ(ñ5 ñ6 ×)Ñ)¨DÕ0Ñ7ñ7 ñ8 × Ñ  4Õ'Ñ.ñ9 ñ: ×Ñ $Õ&Ñ-ò; r'   r?   )r@   rA   rB   rC   rD   rT   rU   rV   rW   rX   rY   rP   rE   rF   rG   rH   s   @r$   rJ   rJ   \   s<   ø‡ € ñð" %)€CØ$(€CØ$(€CØ37ÐØ*.€IØ)-€H÷ð ÷? ƒ r'   rJ   a   
    Output from FlavaForPreTraining containing embeddings, and outputs from individual encoders.

    Note that `image_embeddings` and `text_embeddings` returned are similar to pooled output returned from a
    transformer. If you want embeddings for contrastive loss or retrieval use a FLAVA model's `image_projection` and
    `text_projection` layers on `image_embeddings` and `text_embeddings` respectively.
    c                   ó–   a € ] tR t^„t o RtRtRtRtRtRt	Rt
RtRtRtRtRtRtRtRtRtRtRtRtRtRtRtV 3R lR ltV 3R ltRtV tR# )ÚFlavaForPreTrainingOutputa¢  
loss (`torch.FloatTensor`, *optional*, returned when `return_loss` is True):
    Total loss calculated for this model.
loss_info (`FlavaLosses`):
    Detailed info for FLAVA Pretraining losses. Check `FlavaLosses` class description for the information on
    the keys.
image_embeddings (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when `pixel_values` are present):
    The image embeddings which are basically the pooled output of [`FlavaImageModel`].
image_output (`BaseModelOutputWithPooling`, *optional*, returned when `pixel_values` are present):
    The output of the [`FlavaImageModel`].
text_embeddings (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when `input_ids` are present):
    The text embeddings which are basically the pooled output of [`FlavaTextModel`].
text_output (`BaseModelOutputWithPooling`, *optional*, returned when `input_ids` are present):
    The output of the [`FlavaTextModel`].
multimodal_embeddings (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when `input_ids` and `pixel_values` are present and `skip_unmasked_multimodal_encoder` is `None` or `False`):
    The multimodal embeddings which are basically the pooled output of [`FlavaTextModel`].
multimodal_output (`BaseModelOutputWithPooling`, returned when `input_ids` and `pixel_values` are present and `skip_unmasked_multimodal_encoder` is `None` or `False`):
    The output of the [`FlavaMultimodalModel`].
image_masked_embeddings (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when `pixel_values` are present):
    The image embeddings which are basically the pooled output of [`FlavaImageModel`]. Uses `bool_masked_pos`
    to create masked images.
image_masked_output (`BaseModelOutputWithPooling`, *optional*, returned when `pixel_values` are present):
    The output of the [`FlavaImageModel`]. Uses `bool_masked_pos` to create masked images.
text_masked_embeddings (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when `input_ids_masked` are present):
    The text embeddings which are basically the pooled output of [`FlavaTextModel`].
text_masked_output (`BaseModelOutputWithPooling`, *optional*, returned when `input_ids_masked` are present):
    The output of the [`FlavaTextModel`].
multimodal_masked_embeddings (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when `input_ids` and `pixel_values` are present):
    The multimodal embeddings which are basically the pooled output of [`FlavaTextModel`].
multimodal_masked_output (`BaseModelOutputWithPooling`, *optional*, returned when `input_ids_masked` and `pixel_values` are present):
    The output of the [`FlavaMultimodalModel`].
mim_logits (`torch.FloatTensor` of shape `(batch_size, num_image_patches, image_vocab_size)` or of shape `(total_masked_patches, image_vocab_size)` , *optional*, returned when `pixel_values` are present and `input_ids_masked` are not):
    The logits for MIM unimodal loss. Uses `bool_masked_pos` to get masked patches. The flattened output is
        returned when `bool_masked_pos` has some of the patches masked.
mlm_logits (`torch.FloatTensor` of shape `(batch_size, text_seq_length, text_vocab_size)` or of shape `(total_masked_seq_length, text_vocab_size)`, *optional*, returned when `input_ids_masked` are present and `pixel_values` are not):
    The logits for MLM unimodal loss. The flattened output is returned when `input_ids_masked` has some of
        the tokens masked.
itm_logits (`torch.FloatTensor` of shape `(batch_size, 2)`, *optional*, returned when `input_ids_masked` and `pixel_values` are present):
    The logits for ITM loss. Note that ITM loss is calculated on masked pairs in FLAVA.
contrastive_logits_per_image (`torch.FloatTensor` of shape `(image_batch_size, text_batch_size)`):
    The scaled dot product scores between `image_embeddings` and `text_embeddings` but passed through FLAVA's
    `image_projection` and `text_projection` layers respectively. This represents the image-text similarity
    scores. This is calculated on unmasked images and texts.
contrastive_logits_per_text (`torch.FloatTensor` of shape `(text_batch_size, image_batch_size)`):
    The scaled dot product scores between `text_embeddings` and `image_embeddings` but passed through FLAVA's
    `text_projection` and `image_projection` layers respectively. This is calculated on unmasked images and
    texts.
mmm_image_logits (`torch.FloatTensor` of shape `(batch_size, num_image_patches, image_vocab_size)` or of shape`(total_masked_patches, image_vocab_size)`, *optional*, returned when `pixel_values` and `input_ids_masked` are present):
    The logits for MMM image multimodal loss. Uses `bool_masked_pos` to get masked patches. The flattened
        output is returned when `bool_masked_pos` has some of the patches masked.
mmm_text_logits (`torch.FloatTensor` of shape `(batch_size, text_seq_length, text_vocab_size)` or of shape `(total_masked_seq_length, text_vocab_size)`, *optional*, returned when `pixel_values` and `input_ids_masked` are present):
    The logits for MMM text multimodal loss. The flattened output is returned when `input_ids_masked` has
        some of the tokens masked.
Nc                ó0   <€ V ^8„  d   QhRS[ S[,          /# r   r    )r"   r#   s   "€r$   r%   Ú&FlavaForPreTrainingOutput.__annotate__Ü   s   ø€ ÷ 	tñ 	t™%¡�*ñ 	tr'   c                ó®   a a€ . ROo\         ;QJ d&    . V V3R lS P                  4        4       F  NK  	  5# ! V V3R lS P                  4        4       4      # )r*   c              3   óv   <"  € T F.  qS9  d
   SV,          M\        SV4      P                  4       x € K0  	  R # 5i©Nr-   )r0   r1   r2   Útransformer_outputss   & €€r$   r3   Ú5FlavaForPreTrainingOutput.to_tuple.<locals>.<genexpr>å   s4   øé € ÐsÑgrÐbcÐ)<Ô <�T˜!–WÄ'È$ÐPQÓBR×B[ÑB[ÓB]Ô]Ógrùs   ƒ69)r*   r+   r,   Útext_masked_outputÚimage_masked_outputÚmultimodal_masked_outputr5   )r2   ra   s   f@r$   r/   Ú"FlavaForPreTrainingOutput.to_tupleÜ   sC   ù€ ò
Ð÷ ŒuÕsÐgk×gpÑgpÔgrÓs�uÐsˆuÕsÐgk×gpÑgpÔgrÓsÓsÐsr'   c                óF  <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[;R&   S[ P                  R,          ;R&   S[R,          ;R&   S[ P                  R,          ;R&   S[R,          ;R&   S[ P                  R,          ;R&   S[R,          ;R	&   S[ P                  R,          ;R
&   S[R,          ;R&   S[ P                  R,          ;R&   S[R,          ;R&   S[ P                  R,          ;R&   S[R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   # )r   NÚlossÚ	loss_infor:   r+   r;   r*   r<   r,   Úimage_masked_embeddingsrd   Útext_masked_embeddingsrc   Úmultimodal_masked_embeddingsre   Ú
mim_logitsÚ
mlm_logitsÚ
itm_logitsÚcontrastive_logits_per_imageÚcontrastive_logits_per_textÚmmm_image_logitsÚmmm_text_logits)r=   r>   rJ   r   )r"   r#   s   "€r$   r%   r]   „   sø  ø‡ ‚ ñD ×
Ñ
˜dÕ
"Ñ)ñE ñF Ñ!ñG ñH ×'Ñ'¨$Õ.Ñ5ñI ñJ -¨tÕ3Ñ:ñK ñL ×&Ñ&¨Õ-Ñ4ñM ñN ,¨dÕ2Ñ9ñO ñP !×,Ñ,¨tÕ3Ñ:ñQ ñR 2°DÕ8Ñ?ñS ñT #×.Ñ.°Õ5Ñ<ñU ñV 4°dÕ:ÑAñW ñX "×-Ñ-°Õ4Ñ;ñY ñZ 3°TÕ9Ñ@ñ[ ñ\ #(×"3Ñ"3°dÕ":ÑAñ] ñ^ 9¸4Õ?ÑFñ_ ñ` ×!Ñ! DÕ(Ñ/ña ñb ×!Ñ! DÕ(Ñ/ñc ñd ×!Ñ! DÕ(Ñ/ñe ñf #(×"3Ñ"3°dÕ":ÑAñg ñh "'×!2Ñ!2°TÕ!9Ñ@ñi ñj ×'Ñ'¨$Õ.Ñ5ñk ñl ×&Ñ&¨Õ-Ñ4òm r'   r?   )r@   rA   rB   rC   rD   rh   ri   r:   r+   r;   r*   r<   r,   rj   rd   rk   rc   rl   re   rm   rn   ro   rp   rq   rr   rs   r/   rE   rF   rG   rH   s   @r$   r[   r[   „   s–   ø‡ € ñ5ðn &*€DØ!€IØ15ÐØ6:€LØ04€OØ59€KØ6:ÐØ;?ÐØ8<ÐØ=AÐØ7;ÐØ<@ÐØ=AÐ ØBFÐØ+/€JØ+/€JØ+/€JØ=AÐ Ø<@ÐØ15ÐØ04€O÷	tð 	t÷q ƒ r'   r[   c                   ón   a a€ ] tR t^êt oRtR	V3R lV 3R llltV3R lR ltR
V3R lR lltRtVt	V ;t
# )ÚFlavaImageEmbeddingszZ
Construct the CLS token, position and patch embeddings. Optionally, also the mask token.
c                ó*   <€ V ^8„  d   QhRS[ RS[RR/# )r   ÚconfigÚuse_mask_tokenr   N©r   rL   )r"   r#   s   "€r$   r%   Ú!FlavaImageEmbeddings.__annotate__ï   s$   ø€ ÷ ñ Ñ/ð Áð ÐRVñ r'   c                óð  <€ \         SV `  4        T;'       g    VP                  p\        P                  ! \
        P                  ! ^^VP                  4      4      V n        V'       d7   \        P                  ! \
        P                  ! ^^VP                  4      4      MRV n        \        VP                  VP                  VP                  VP                  R7      V n        V P                  P                  p\        P                  ! \
        P                  ! ^V^,           VP                  4      4      V n        \        P                   ! VP"                  4      V n        VP                  V n        Wn        R# )é   N)Ú
image_sizeÚ
patch_sizeÚnum_channelsÚ	embed_dim)ÚsuperÚ__init__Ú
mask_tokenr   Ú	Parameterr=   ÚzerosÚhidden_sizeÚ	cls_tokenÚPatchEmbeddingsr}   r~   r   Úpatch_embeddingsÚnum_patchesÚposition_embeddingsÚDropoutÚhidden_dropout_probÚdropoutrw   )r2   rw   rx   rŠ   Ú	__class__s   &&& €r$   r‚   ÚFlavaImageEmbeddings.__init__ï   s  ø€ Ü‰ÑÔà'×<Ð<¨6×+<Ñ+<ˆÜŸš¤e§k¢k°!°Q¸×8JÑ8JÓ&KÓLˆŒßQ_œ"Ÿ,š,¤u§{¢{°1°a¸×9KÑ9KÓ'LÔMÐeiˆŒÜ /Ø×(Ñ(Ø×(Ñ(Ø×,Ñ,Ø×(Ñ(ô	!
ˆÔð ×+Ñ+×7Ñ7ˆÜ#%§<¢<´·²¸A¸{ÈQ½ÐPV×PbÑPbÓ0cÓ#dˆÔ Ü—z’z &×"<Ñ"<Ó=ˆŒØ ×+Ñ+ˆŒØŽr'   c                óZ   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[ P                  /# )r   Ú
embeddingsÚheightÚwidthr   )r=   ÚTensorÚint)r"   r#   s   "€r$   r%   rz     s;   ø€ ÷ &Dñ &D±5·<±<ð &DÉð &DÑUXð &DÑ]b×]iÑ]iñ &Dr'   c                óæ  € VP                   ^,          ^,
          pV P                  P                   ^,          ^,
          p\        P                  P	                  4       '       g   WE8X  d   W#8X  d   V P                  # V P                  R,          pV P                  R,          pVP                   R,          pW P
                  ,          p	W0P
                  ,          p
\        VR,          4      pVP                  ^W»V4      pVP                  ^ ^^^4      p\        P                  P                  VWš3RRR7      pVP                  ^ ^^^4      P                  ^RV4      p\        P                  ! Wg3^R7      # )	aÐ  
This method allows to interpolate the pre-trained position encodings, to be able to use the model on higher resolution
images. This method is also adapted to support torch.jit tracing.

Adapted from:
- https://github.com/facebookresearch/dino/blob/de9ee3df6cf39fac952ab558447af1fa1365362a/vision_transformer.py#L174-L194, and
- https://github.com/facebookresearch/dinov2/blob/e1277af2ba9496fbadf7aec6eba56e8d882d1e35/dinov2/models/vision_transformer.py#L179-L211
g      à?ÚbicubicF)ÚsizeÚmodeÚalign_corners©Údim)ºNNN:Nr|   N)rž   ºr|   NNéÿÿÿÿ)Úshaper‹   r=   ÚjitÚ
is_tracingr~   r   ÚreshapeÚpermuter   Ú
functionalÚinterpolateÚviewÚcat)r2   r’   r“   r”   rŠ   Únum_positionsÚclass_pos_embedÚpatch_pos_embedr�   Ú
new_heightÚ	new_widthÚsqrt_num_positionss   &&&&        r$   Úinterpolate_pos_encodingÚ-FlavaImageEmbeddings.interpolate_pos_encoding  sE  € ð !×&Ñ& qÕ)¨AÕ-ˆØ×0Ñ0×6Ñ6°qÕ9¸AÕ=ˆô �y‰y×#Ñ#×%Ò%¨+Ô*FÈ6Ì?Ø×+Ñ+Ð+à×2Ñ2°5Õ9ˆØ×2Ñ2°5Õ9ˆà×Ñ˜rÕ"ˆàŸ™Õ.ˆ
ØŸ_™_Õ,ˆ	ä& }°cÕ'9Ó:ÐØ)×1Ñ1°!Ð5GÐ]`ÓaˆØ)×1Ñ1°!°Q¸¸1Ó=ˆäŸ-™-×3Ñ3ØØÐ(ØØð	 4ó 
ˆð *×1Ñ1°!°Q¸¸1Ó=×BÑBÀ1ÀbÈ#ÓNˆä�yŠy˜/Ð;ÀÔCÐCr'   c                ó|   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[RS[ P                  /# )r   Úpixel_valuesÚbool_masked_posNr°   r   )r=   r•   Ú
BoolTensorrL   )r"   r#   s   "€r$   r%   rz   *  sF   ø€ ÷ ñ á—l‘lðñ ×)Ñ)¨DÕ0ðñ #'ð	ñ
 
�‰ñr'   c                óˆ  € VP                   w  rErgV P                  WR 7      pVP                  4       w  rIp
Ve�   V P                  P	                  WIR4      pVP                  4       ^8X  d"   VP                  VP                  ^ 4      R4      pVP                  R4      P                  V4      pVRV,
          ,          W¼,          ,           pV P                  P	                  VRR4      p\        P                  ! WØ3^R7      pV'       d   W€P                  W†V4      ,           pMW€P                  ,           pV P                  V4      pV# ))r°   g      ð?rœ   r    )r¡   r‰   r™   rƒ   Úexpandr�   r¨   Ú	unsqueezeÚtype_asr‡   r=   r©   r°   r‹   rŽ   )r2   r³   r´   r°   Ú
batch_sizer   r“   r”   r’   Úseq_lenÚ_Úmask_tokensÚmaskÚ
cls_tokenss   &&&&          r$   ÚforwardÚFlavaImageEmbeddings.forward*  s  € ð 3?×2DÑ2DÑ/ˆ
 &Ø×*Ñ*¨<Ð*Ókˆ
à!+§¡Ó!2Ñˆ
˜QØÒ&ØŸ/™/×0Ñ0°ÀbÓIˆKà×"Ñ"Ó$¨Ô)Ø"1×"6Ñ"6°×7KÑ7KÈAÓ7NÐPRÓ"S�à"×,Ñ,¨RÓ0×8Ñ8¸ÓEˆDØ# s¨T¥zÕ2°[Õ5GÕGˆJð —^‘^×*Ñ*¨:°r¸2Ó>ˆ
Ü—Y’Y 
Ð7¸QÔ?ˆ
÷ $Ø#×&CÑ&CÀJÐX]Ó&^Õ^‰Jà#×&>Ñ&>Õ>ˆJà—\‘\ *Ó-ˆ
àÐr'   )r‡   rw   rŽ   rƒ   r‰   r~   r‹   ©F©NF)r@   rA   rB   rC   rD   r‚   r°   rÀ   rF   rG   Ú__classcell__©r�   r#   s   @@r$   ru   ru   ê   s0   ù‡ € ñ÷õ ÷&&Dð &D÷P÷ ò r'   ru   c                   ó\   a a€ ] tR tRt oRt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	# )
rˆ   iN  z
Image to Patch Embedding.
c                óž   <€ V ^8„  d   QhRS[ S[S[ ,          ,          S[S[ S[ 3,          ,          RS[ S[S[ S[ 3,          ,          RS[ RS[ /# )r   r}   r~   r   r€   )r–   Úlistr!   )r"   r#   s   "€r$   r%   ÚPatchEmbeddings.__annotate__S  s[   ø€ ÷ hñ há™$™s�)•O¡e©C±¨H¥oÕ5ðhñ ™%¡¡S �/Õ)ðhñ ð	hñ
 ñhr'   c                óœ  <€ \         SV `  4        \        V\        P                  P
                  4      '       g   W3p\        V\        P                  P
                  4      '       g   W"3pV^,          V^,          ,          V^ ,          V^ ,          ,          ,          pWn        W n        WPn        \        P                  ! W4W"R7      V n        R# )r|   )Úkernel_sizeÚstrideN)r�   r‚   Ú
isinstanceÚcollectionsÚabcÚIterabler}   r~   rŠ   r   ÚConv2dÚ
projection)r2   r}   r~   r   r€   rŠ   r�   s   &&&&& €r$   r‚   ÚPatchEmbeddings.__init__S  s•   ø€ ô 	‰ÑÔÜ˜*¤k§o¡o×&>Ñ&>×?Ò?Ø$Ð1ˆJÜ˜*¤k§o¡o×&>Ñ&>×?Ò?Ø$Ð1ˆJØ! !•}¨
°1­Õ5¸*ÀQ½-È:ÐVWÍ=Õ:XÕYˆØ$ŒØ$ŒØ&ÔäŸ)š) LÈÔgˆŽr'   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# )r   r³   r°   r   )r=   r•   rL   )r"   r#   s   "€r$   r%   rÉ   f  s-   ø€ ÷ 	ñ 	¡E§L¡Lð 	ÉDð 	Ñ]b×]iÑ]iñ 	r'   c                ód  € VP                   w  r4rVV'       gi   WPP                  ^ ,          8w  g   W`P                  ^,          8w  d;   \        RV RV RV P                  ^ ,           RV P                  ^,           R2	4      hV P                  V4      P	                  ^4      P                  ^^4      pV# )é    zInput image size (Ú*z) doesn't match model (z).)r¡   r}   Ú
ValueErrorrÒ   ÚflattenÚ	transpose)r2   r³   r°   rº   r   r“   r”   Úxs   &&&     r$   rÀ   ÚPatchEmbeddings.forwardf  s¥   € Ø2>×2DÑ2DÑ/ˆ
 &ß'ØŸ™¨Õ+Ô+¨u¿¹ÈÕ8JÔ/JÜ Ø(¨¨°°%°ð 9ØŸ™¨Õ+Ð,¨A¨d¯o©o¸aÕ.@Ð-AÀðEóð ð �O‰O˜LÓ)×1Ñ1°!Ó4×>Ñ>¸qÀ!ÓDˆØˆr'   )r}   rŠ   r~   rÒ   )éà   é   é   i   rÂ   ©
r@   rA   rB   rC   rD   r‚   rÀ   rF   rG   rÄ   rÅ   s   @@r$   rˆ   rˆ   N  s%   ù‡ € ñ÷hõ h÷&	÷ 	ò 	r'   rˆ   c                   óL   a a€ ] tR tRt oRtV 3R ltRV3R lR lltRtVtV ;t	# )ÚFlavaTextEmbeddingsir  zGConstruct the embeddings from word, position and token_type embeddings.c                óN  <€ \         SV `  4        \        P                  ! VP                  VP
                  VP                  R 7      V n        \        P                  ! VP                  VP
                  4      V n	        \        P                  ! VP                  VP
                  4      V n        \        P                  ! VP
                  VP                  R7      V n        \        P                  ! VP                  4      V n        \        P"                  ! \$        P&                  ! VP                  4      P)                  R4      RR7      V n        \        P"                  ! \$        P,                  ! V P*                  P/                  4       \$        P0                  R7      RR7      V n        R# ))Úpadding_idx©ÚepsF)Ú
persistent)ÚdtypeN©r|   r    )r�   r‚   r   Ú	EmbeddingÚ
vocab_sizer†   Úpad_token_idÚword_embeddingsÚmax_position_embeddingsr‹   Útype_vocab_sizeÚtoken_type_embeddingsÚ	LayerNormÚlayer_norm_epsrŒ   r�   rŽ   ÚBufferr=   Úaranger·   Úposition_idsr…   r™   ÚlongÚtoken_type_ids©r2   rw   r�   s   &&€r$   r‚   ÚFlavaTextEmbeddings.__init__u  s  ø€ Ü‰ÑÔÜ!Ÿ|š|¨F×,=Ñ,=¸v×?QÑ?QÐ_e×_rÑ_rÔsˆÔÜ#%§<¢<°×0NÑ0NÐPV×PbÑPbÓ#cˆÔ Ü%'§\¢\°&×2HÑ2HÈ&×J\ÑJ\Ó%]ˆÔ"äŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z’z &×"<Ñ"<Ó=ˆŒäŸIšI¤e§l¢l°6×3QÑ3QÓ&R×&YÑ&YÐZaÓ&bÐotÔuˆÔÜ Ÿiši¬¯ª°D×4EÑ4E×4JÑ4JÓ4LÔTY×T^ÑT^Ô(_ÐlqÔrˆÖr'   c                ó’   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          /# )r   Ú	input_idsNr÷   rõ   ©r=   r•   )r"   r#   s   "€r$   r%   Ú FlavaTextEmbeddings.__annotate__�  sD   ø€ ÷  ñ  á—<‘< $Õ&ð ñ Ÿ™ tÕ+ð ñ —l‘l TÕ)ñ	 r'   c                ó@  € VP                  4       pV^,          pVf   V P                  RRV13,          pVf�   \        V R4      '       d4   V P                  RRV13,          pVP	                  V^ ,          V4      pTpM;\
        P                  ! V\
        P                  V P                  P                  R7      pV P                  V4      pV P                  V4      p	W‰,           p
V P                  V4      pW«,          p
V P                  V
4      p
V P                  V
4      p
V
# )r|   Nrž   r÷   )rè   Údevice)r™   rõ   Úhasattrr÷   r·   r=   r…   rö   rÿ   rí   rð   r‹   rñ   rŽ   )r2   rû   r÷   rõ   Úinput_shapeÚ
seq_lengthÚbuffered_token_type_idsÚ buffered_token_type_ids_expandedÚinputs_embedsrð   r’   r‹   s   &&&&        r$   rÀ   ÚFlavaTextEmbeddings.forward�  s  € ð  —n‘nÓ&ˆØ  •^ˆ
àÒØ×,Ñ,¨Q°°°¨^Õ<ˆLð
 Ò!Ü�tÐ-×.Ò.Ø*.×*=Ñ*=¸aÀÀ*À¸nÕ*MÐ'Ø3J×3QÑ3QÐR]Ð^_ÕR`ÐblÓ3mÐ0Ø!A‘ä!&§¢¨[ÄÇ
Á
ÐSW×SdÑSd×SkÑSkÔ!l�à×,Ñ,¨YÓ7ˆØ $× :Ñ :¸>Ó JÐØ"Õ:ˆ
à"×6Ñ6°|ÓDÐØÕ)ˆ
à—^‘^ JÓ/ˆ
Ø—\‘\ *Ó-ˆ
ØÐr'   )rñ   rŽ   r‹   rõ   rð   r÷   rí   ©NNNrà   rÅ   s   @@r$   râ   râ   r  s   ù‡ € ÙQõ
s÷ ÷  ò  r'   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# )ÚFlavaSelfAttentioni¤  c                ó$   <€ V ^8„  d   QhRS[ RR/# ©r   rw   r   N©ÚFlavaPossibleConfigs)r"   r#   s   "€r$   r%   ÚFlavaSelfAttention.__annotate__¥  s    ø€ ÷ Gñ GÑ3ð G¸ñ Gr'   c                óF  <€ \         SV `  4        VP                  VP                  ,          ^ 8w  d9   \	        VR4      '       g'   \        RVP                   RVP                   R24      hVP                  V n        \        VP                  VP                  ,          4      V n        V P                  V P                  ,          V n        \        P                  ! VP                  V P                  VP                  R7      V n        \        P                  ! VP                  V P                  VP                  R7      V n        \        P                  ! VP                  V P                  VP                  R7      V n        \        P                  ! VP                   4      V n        R# )rÖ   Úembedding_sizezThe hidden size z4 is not a multiple of the number of attention heads Ú.©ÚbiasN)r�   r‚   r†   Únum_attention_headsr   rØ   r–   Úattention_head_sizeÚall_head_sizer   ÚLinearÚqkv_biasÚqueryÚkeyÚvaluerŒ   Úattention_probs_dropout_probrŽ   rø   s   &&€r$   r‚   ÚFlavaSelfAttention.__init__¥  s1  ø€ Ü‰ÑÔØ×Ñ × :Ñ :Õ:¸aÔ?ÌÐPVÐXh×HiÒHiÜØ" 6×#5Ñ#5Ð"6ð 7Ø×3Ñ3Ð4°Að7óð ð
 $*×#=Ñ#=ˆÔ Ü#& v×'9Ñ'9¸F×<VÑ<VÕ'VÓ#WˆÔ Ø!×5Ñ5¸×8PÑ8PÕPˆÔä—Y’Y˜v×1Ñ1°4×3EÑ3EÈFÏOÉOÔ\ˆŒ
Ü—9’9˜V×/Ñ/°×1CÑ1CÈ&Ï/É/ÔZˆŒÜ—Y’Y˜v×1Ñ1°4×3EÑ3EÈFÏOÉOÔ\ˆŒ
ä—z’z &×"EÑ"EÓFˆŽr'   c          
      óÚ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[RS[S[ P                  S[ P                  3,          S[S[ P                  ,          ,          /# ©r   Úhidden_statesÚattention_maskNÚoutput_attentionsr   ©r=   r•   rL   r!   )r"   r#   s   "€r$   r%   r  ·  s`   ø€ ÷ #ñ #á—|‘|ð#ñ Ÿ™ tÕ+ð#ñ  ð	#ñ
 
‰u�|‰|™UŸ\™\Ð)Õ	*©U±5·<±<Õ-@Õ	@ñ#r'   c                óz  € VP                   R R p. V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 P                  V4      P                  V4      P	                  ^^4      p\        P                  ! WgP	                  RR4      4      p	V	\        P                  ! V P                  4      ,          p	Ve	   W’,           p	\        P                  P                  V	RR7      p
V P                  V
4      p
\        P                  ! W¨4      pVP                  ^ ^^^4      P!                  4       pVP#                  4       R R V P$                  3,           pVP                  ! V!  pV'       d   Wº3pV# V3pV# )Nrœ   r    éþÿÿÿ)r¡   r  r  r¨   rÚ   r  r  r=   ÚmatmulÚmathÚsqrtr   r¦   ÚsoftmaxrŽ   r¥   Ú
contiguousr™   r  )r2   r   r!  r"  r  Úhidden_shapeÚquery_layerÚ	key_layerÚvalue_layerÚattention_scoresÚattention_probsÚcontext_layerÚnew_context_layer_shapeÚoutputss   &&&&          r$   rÀ   ÚFlavaSelfAttention.forward·  s™  € ð $×)Ñ)¨#¨2Ð.ˆØC˜ÐC bÐC¨$×*BÑ*BÑCˆØ—j‘j Ó/×4Ñ4°\ÓB×LÑLÈQÐPQÓRˆØ—H‘H˜]Ó+×0Ñ0°Ó>×HÑHÈÈAÓNˆ	Ø—j‘j Ó/×4Ñ4°\ÓB×LÑLÈQÐPQÓRˆô !Ÿ<š<¨×5HÑ5HÈÈRÓ5PÓQÐà+¬d¯iªi¸×8PÑ8PÓ.QÕQÐØÒ%à/Õ@Ðô Ÿ-™-×/Ñ/Ð0@ÀbÐ/ÓIˆð Ÿ,™, Ó7ˆäŸš _ÓBˆà%×-Ñ-¨a°°A°qÓ9×DÑDÓFˆØ"/×"4Ñ"4Ó"6°s¸Ð";¸t×?QÑ?QÐ>SÕ"SÐØ%×*Ò*Ð,CÑDˆç6G�=Ð2ˆàˆð O\ÐM]ˆàˆr'   )r  r  rŽ   r  r  r  r  rÃ   ©	r@   rA   rB   rC   r‚   rÀ   rF   rG   rÄ   rÅ   s   @@r$   r	  r	  ¤  s    ù‡ € ÷Gó G÷$#÷ #ò #r'   r	  c                   óT   a a€ ] tR tRt oRtV3R lV 3R lltV3R lR ltRtVtV ;t	# )ÚFlavaSelfOutputiÝ  z©
The residual connection is defined in FlavaLayer (same as ViTLayer) instead of here (as is the case with other
models), due to the layernorm applied before each block.
c                ó$   <€ V ^8„  d   QhRS[ RR/# r  r  )r"   r#   s   "€r$   r%   ÚFlavaSelfOutput.__annotate__ã  ó   ø€ ÷ >ñ >Ñ3ð >¸ñ >r'   c                óÎ   <€ \         SV `  4        \        P                  ! VP                  VP                  4      V n        \        P                  ! VP                  4      V n        R # r`   )	r�   r‚   r   r  r†   ÚdenserŒ   r�   rŽ   rø   s   &&€r$   r‚   ÚFlavaSelfOutput.__init__ã  sB   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
Ü—z’z &×"<Ñ"<Ó=ˆŽr'   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# ©r   r   Úinput_tensorr   rü   )r"   r#   s   "€r$   r%   r9  è  s1   ø€ ÷ ñ ¡U§\¡\ð ÁÇÁð ÑRW×R^ÑR^ñ r'   c                óJ   € V P                  V4      pV P                  V4      pV# r`   ©r<  rŽ   ©r2   r   r@  s   &&&r$   rÀ   ÚFlavaSelfOutput.forwardè  s$   € ØŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆàÐr'   rB  rà   rÅ   s   @@r$   r7  r7  Ý  s#   ù‡ € ñ÷
>ó >÷
÷ ð r'   r7  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# )ÚFlavaAttentioniï  c                ó$   <€ V ^8„  d   QhRS[ RR/# r  r  )r"   r#   s   "€r$   r%   ÚFlavaAttention.__annotate__ð  s   ø€ ÷ .ñ .Ñ3ð .¸ñ .r'   c                ód   <€ \         SV `  4        \        V4      V n        \	        V4      V n        R # r`   )r�   r‚   r	  Ú	attentionr7  Úoutputrø   s   &&€r$   r‚   ÚFlavaAttention.__init__ð  s&   ø€ Ü‰ÑÔÜ+¨FÓ3ˆŒÜ% fÓ-ˆŽr'   c          
      óÚ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[RS[S[ P                  S[ P                  3,          S[S[ P                  ,          ,          /# r  r#  )r"   r#   s   "€r$   r%   rH  õ  s`   ø€ ÷ ñ á—|‘|ðñ Ÿ™ tÕ+ðñ  ð	ñ
 
‰u�|‰|™UŸ\™\Ð)Õ	*©U±5·<±<Õ-@Õ	@ñr'   c                ó€   € V P                  WVR 7      pV P                  V^ ,          V4      pV3VR,          ,           pV# ©)r!  r"  rŸ   ©rJ  rK  )r2   r   r!  r"  Úself_outputsÚattention_outputr3  s   &&&&   r$   rÀ   ÚFlavaAttention.forwardõ  sK   € ð —~‘~ØÐL]ð &ó 
ˆð  Ÿ;™; |°A¥¸ÓFÐà#Ð%¨°RÕ(8Õ8ˆØˆr'   rP  rÃ   r5  rÅ   s   @@r$   rF  rF  ï  s   ù‡ € ÷.ó .÷
÷ ò r'   rF  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚFlavaIntermediatei  c                ó$   <€ V ^8„  d   QhRS[ RR/# r  r  )r"   r#   s   "€r$   r%   ÚFlavaIntermediate.__annotate__  s   ø€ ÷ 9ñ 9Ñ3ð 9¸ñ 9r'   c                ó"  <€ \         SV `  4        \        P                  ! VP                  VP
                  4      V n        \        VP                  \        4      '       d   \        VP                  ,          V n        R # VP                  V n        R # r`   )r�   r‚   r   r  r†   Úintermediate_sizer<  rÍ   Ú
hidden_actÚstrr   Úintermediate_act_fnrø   s   &&€r$   r‚   ÚFlavaIntermediate.__init__  s`   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3KÑ3KÓLˆŒ
Ü�f×'Ñ'¬×-Ò-Ü'-¨f×.?Ñ.?Õ'@ˆDÖ$à'-×'8Ñ'8ˆDÖ$r'   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   r   r   rü   )r"   r#   s   "€r$   r%   rW    s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r'   c                óJ   € V P                  V4      pV P                  V4      pV# r`   ©r<  r\  ©r2   r   s   &&r$   rÀ   ÚFlavaIntermediate.forward  s&   € ØŸ
™
 =Ó1ˆØ×0Ñ0°Ó?ˆàÐr'   r`  r5  rÅ   s   @@r$   rU  rU    s   ù‡ € ÷9ó 9÷÷ ð r'   rU  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚFlavaOutputi  c                ó$   <€ V ^8„  d   QhRS[ RR/# r  r  )r"   r#   s   "€r$   r%   ÚFlavaOutput.__annotate__  r:  r'   c                óÎ   <€ \         SV `  4        \        P                  ! VP                  VP
                  4      V n        \        P                  ! VP                  4      V n	        R # r`   )
r�   r‚   r   r  rY  r†   r<  rŒ   r�   rŽ   rø   s   &&€r$   r‚   ÚFlavaOutput.__init__  sB   ø€ Ü‰ÑÔÜ—Y’Y˜v×7Ñ7¸×9KÑ9KÓLˆŒ
Ü—z’z &×"<Ñ"<Ó=ˆŽr'   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# r?  rü   )r"   r#   s   "€r$   r%   rf    s1   ø€ ÷ ñ ¡U§\¡\ð ÁÇÁð ÑRW×R^ÑR^ñ r'   c                óZ   € V P                  V4      pV P                  V4      pW,           pV# r`   rB  rC  s   &&&r$   rÀ   ÚFlavaOutput.forward  s,   € ØŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆà%Õ4ˆàÐr'   rB  r5  rÅ   s   @@r$   rd  rd    s   ù‡ € ÷>ó >÷÷ ð r'   rd  c                   óX   a a€ ] tR tRt oRt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	# )	Ú
FlavaLayeri&  z?This corresponds to the Block class in the timm implementation.c                ó$   <€ V ^8„  d   QhRS[ RR/# r  r  )r"   r#   s   "€r$   r%   ÚFlavaLayer.__annotate__)  s    ø€ ÷ 
[ñ 
[Ñ3ð 
[¸ñ 
[r'   c                óx  <€ \         SV `  4        VP                  V n        ^V n        \	        V4      V n        \        V4      V n        \        V4      V n	        \        P                  ! VP                  VP                  R7      V n        \        P                  ! VP                  VP                  R7      V n        R# )r|   rå   N)r�   r‚   Úchunk_size_feed_forwardÚseq_len_dimrF  rJ  rU  Úintermediaterd  rK  r   rñ   r†   rò   Úlayernorm_beforeÚlayernorm_afterrø   s   &&€r$   r‚   ÚFlavaLayer.__init__)  s‰   ø€ Ü‰ÑÔØ'-×'EÑ'EˆÔ$ØˆÔÜ'¨Ó/ˆŒÜ-¨fÓ5ˆÔÜ! &Ó)ˆŒô !#§¢¨V×-?Ñ-?ÀV×EZÑEZÔ [ˆÔÜ!Ÿ|š|¨F×,>Ñ,>ÀF×DYÑDYÔZˆÖr'   c          
      óÚ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[RS[S[ P                  S[ P                  3,          S[S[ P                  ,          ,          /# r  r#  )r"   r#   s   "€r$   r%   ro  5  s`   ø€ ÷ ñ á—|‘|ðñ Ÿ™ tÕ+ðñ  ð	ñ
 
‰u�|‰|™UŸ\™\Ð)Õ	*©U±5·<±<Õ-@Õ	@ñr'   c                óú   € V P                  V P                  V4      VVR 7      pV^ ,          pVR,          pWQ,           pV P                  V4      pV P                  V4      pV P	                  Wq4      pV3V,           pV# rO  )rJ  rt  ru  rs  rK  )r2   r   r!  r"  Úself_attention_outputsrR  r3  Úlayer_outputs   &&&&    r$   rÀ   ÚFlavaLayer.forward5  s�   € ð "&§¡Ø×!Ñ! -Ó0Ø)Ø/ð "0ó "
Ðð
 2°!Õ4ÐØ(¨Õ,ˆð )Õ8ˆð ×+Ñ+¨MÓ:ˆØ×(Ñ(¨Ó6ˆð —{‘{ <Ó?ˆà�/ GÕ+ˆàˆr'   )rJ  rq  rs  ru  rt  rK  rr  rÃ   rà   rÅ   s   @@r$   rm  rm  &  s#   ù‡ € ÙI÷
[ó 
[÷÷ ò r'   rm  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# )ÚFlavaEncoderiR  c                ó$   <€ V ^8„  d   QhRS[ RR/# r  ©r   )r"   r#   s   "€r$   r%   ÚFlavaEncoder.__annotate__S  s   ø€ ÷ ,ñ ,™{ð ,¨tñ ,r'   c                óÖ   <€ \         SV `  4        Wn        \        P                  ! \        VP                  4       Uu. uF  p\        V4      NK  	  up4      V n        R V n	        R# u upi )FN)
r�   r‚   rw   r   Ú
ModuleListÚrangeÚnum_hidden_layersrm  ÚlayerÚgradient_checkpointing)r2   rw   r¼   r�   s   && €r$   r‚   ÚFlavaEncoder.__init__S  sR   ø€ Ü‰ÑÔØŒÜ—]’]ÄÀf×F^ÑF^Ô@_Ó#`Ñ@_¸1¤J¨vÖ$6Ñ@_Ñ#`ÓaˆŒ
Ø&+ˆÖ#ùò $as   ½A&c                ó„   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[RS[RS[RS[S[,          /# ©r   r   r!  Nr"  Úoutput_hidden_statesÚreturn_dictr   )r=   r•   rL   r!   r
   )r"   r#   s   "€r$   r%   r€  Y  sY   ø€ ÷ 
ñ 
á—|‘|ð
ñ Ÿ™ tÕ+ð
ñ  ð	
ñ
 #ð
ñ ð
ñ 
‘Õ	 ñ
r'   c                ó”  € V'       d   RMR pV'       d   RMR p\        V P                  4       FB  w  r‰V'       d
   Wa3,           pV	! WV4      p
V
^ ,          pV'       g   K2  Wz^,          3,           pKD  	  V'       d
   Wa3,           pV'       g1   \        ;QJ d    . R WV3 4       F  NK  	  5# ! R WV3 4       4      # \        WVR7      # )Nc              3   ó0   "  € T F  qf   K  Vx € K  	  R # 5ir`   r?   )r0   rQ   s   & r$   r3   Ú'FlavaEncoder.forward.<locals>.<genexpr>s  s   é € ÐmÑ$[˜qŸšÓ$[ùó   ‚Œ
)Úlast_hidden_stater   Ú
attentionsr?   )Ú	enumerater…  r!   r
   )r2   r   r!  r"  rŠ  r‹  Úall_hidden_statesÚall_self_attentionsÚiÚlayer_moduleÚlayer_outputss   &&&&&&     r$   rÀ   ÚFlavaEncoder.forwardY  s¿   € ÷ #7™B¸DÐß$5™b¸4Ðä(¨¯©Ö4‰OˆAß#Ø$5Ð8HÕ$HÐ!á(¨ÐHYÓZˆMà)¨!Õ,ˆMç Ñ Ø&9È1Õ=MÐ<OÕ&OÒ#ñ  5÷  Ø 1Ð4DÕ DÐçß”5Ñm ]ÐGZÑ$[Óm—5Ðm�5Ñm ]ÐGZÑ$[ÓmÓmÐmÜØ+ÐYlô
ð 	
r'   )rw   r†  r…  )NFFTr5  rÅ   s   @@r$   r}  r}  R  s   ù‡ € ÷,ó ,÷
÷ 
ò 
r'   r}  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚFlavaPooleriy  c                ó    <€ V ^8„  d   QhRS[ /# ©r   rw   r  )r"   r#   s   "€r$   r%   ÚFlavaPooler.__annotate__z  s   ø€ ÷ $ñ $Ñ3ñ $r'   c                ó¸   <€ \         SV `  4        \        P                  ! VP                  VP                  4      V n        \        P                  ! 4       V n        R # r`   )r�   r‚   r   r  r†   r<  ÚTanhÚ
activationrø   s   &&€r$   r‚   ÚFlavaPooler.__init__z  s9   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ'š'›)ˆŽr'   c                ó4   <€ V ^8„  d   QhRS[ P                  /# )r   r   rü   )r"   r#   s   "€r$   r%   r�    s   ø€ ÷ ñ ¡U§\¡\ñ r'   c                ó\   € VR,          pV P                  V4      pV P                  V4      pV# )rž   )rž   rÖ   )r<  r   )r2   r   Úfirst_token_tensorÚpooled_outputs   &&  r$   rÀ   ÚFlavaPooler.forward  s2   € ð +¨4Õ0ÐØŸ
™
Ð#5Ó6ˆØŸ™¨Ó6ˆØÐr'   )r   r<  r5  rÅ   s   @@r$   rš  rš  y  s   ù‡ € ÷$ó $÷
÷ ð r'   rš  c                   ó~   a a€ ] tR tRt oRtRtRt]P                  ! 4       V3R lV 3R ll4       t	V3R lt
RtVtV ;t# )	ÚFlavaPreTrainedModeliˆ  ÚflavaTc                ó€   <€ V ^8„  d   QhRS[ P                  S[ P                  ,          S[ P                  ,          RR/# )r   Úmoduler   N)r   r  rÑ   rñ   )r"   r#   s   "€r$   r%   Ú!FlavaPreTrainedModel.__annotate__�  s5   ø€ ÷ Sñ S¡B§I¡I±·	±	Õ$9¹B¿L¹LÕ$Hð SÈTñ Sr'   c                ó  <€ \         SV `  V4       \        V\        4      '       d#   \        P
                  ! VP                  4       R# \        V\        4      '       ds   \        P
                  ! VP                  4       \        P
                  ! VP                  4       VP                  e#   \        P
                  ! VP                  4       R# R# \        V\        4      '       d‚   \        P                  ! VP                  \        P                  ! VP                  P                   R,          4      P#                  R4      4       \        P
                  ! VP$                  4       R# \        V\&        4      '       d7   VP(                  '       d#   \        P
                  ! VP                  4       R# R# \        V\*        4      '       d8   \        P,                  ! VP.                  V P0                  P2                  4       R# R# )zInitialize the weightsNr    ré   )r�   Ú_init_weightsrÍ   ÚFlavaMaskedPredictionHeadÚinitÚzeros_r  ru   r‡   r‹   rƒ   râ   Úcopy_rõ   r=   rô   r¡   r·   r÷   ÚFlavaMultimodalModelÚuse_cls_tokenÚ
FlavaModelÚ	constant_Úlogit_scalerw   Úlogit_scale_init_value)r2   r«  r�   s   &&€r$   r®  Ú"FlavaPreTrainedModel._init_weights�  sA  ø€ ô 	‰Ñ˜fÔ%Ü�fÔ7×8Ò8Ü�KŠK˜Ÿ™Ö$Ü˜Ô 4×5Ò5Ü�KŠK˜×(Ñ(Ô)Ü�KŠK˜×2Ñ2Ô3Ø× Ñ Ò,Ü—’˜F×-Ñ-Ö.ñ -ä˜Ô 3×4Ò4Ü�JŠJ�v×*Ñ*¬E¯LªL¸×9LÑ9L×9RÑ9RÐSUÕ9VÓ,W×,^Ñ,^Ð_fÓ,gÔhÜ�KŠK˜×-Ñ-Ö.Ü˜Ô 4×5Ò5Ø×#×#Ð#Ü—’˜F×,Ñ,Ö-ñ $ä˜¤
×+Ò+Ü�NŠN˜6×-Ñ-¨t¯{©{×/QÑ/QÖRñ ,r'   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rœ  r  )r"   r#   s   "€r$   r%   r¬  ˆ  ó   ø‡ ‚ áÑò r'   r?   )ÚimageÚtext)r@   rA   rB   rC   Úbase_model_prefixÚinput_modalitiesÚsupports_gradient_checkpointingr=   Úno_gradr®  rE   rF   rG   rÄ   rÅ   s   @@r$   r¨  r¨  ˆ  s@   ù‡ € ð  ÐØ(ÐØ&*Ð#à
‡]‚]ƒ_÷Sò Só ðS÷ … r'   r¨  c                   óž   a a€ ] tR tRt oRtRtRtRV3R lV 3R llltV3R lR ltV3R lR	 lt	]
RV3R
 lR ll4       tV3R ltRtVtV ;t# )ÚFlavaImageModeli¤  zflava.image_modelr³   c                ó&   <€ V ^8„  d   QhRS[ RS[/# ©r   rw   Úadd_pooling_layerry   )r"   r#   s   "€r$   r%   ÚFlavaImageModel.__annotate__¬  s   ø€ ÷ ñ Ñ/ð ÁDñ r'   c                ó(  <€ \         SV `  V4       Wn        \        V4      V n        \        V4      V n        \        P                  ! VP                  VP                  R7      V n        V'       d   \        V4      MRV n        V P                  4        R# ©z^
add_pooling_layer (bool, *optional*, defaults to `True`):
    Whether to add a pooling layer
rå   N)r�   r‚   rw   ru   r’   r}  Úencoderr   rñ   r†   rò   Ú	layernormrš  ÚpoolerÚ	post_init©r2   rw   rÆ  r�   s   &&&€r$   r‚   ÚFlavaImageModel.__init__¬  sg   ø€ ô
 	‰Ñ˜Ô àŒä.¨vÓ6ˆŒÜ# FÓ+ˆŒäŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒß->”k &Ô)ÀDˆŒà�‰Ör'   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r   ©r   ÚModule)r"   r#   s   "€r$   r%   rÇ  ½  s   ø€ ÷ 0ñ 0¡b§i¡iñ 0r'   c                ó.   € V P                   P                  # r`   ©r’   r‰   r7   s   &r$   Úget_input_embeddingsÚ$FlavaImageModel.get_input_embeddings½  s   € Ø�‰×/Ñ/Ð/r'   c                ó4   <€ V ^8„  d   QhRS[ P                  /# ©r   r  rÑ  )r"   r#   s   "€r$   r%   rÇ  À  s   ø€ ÷ 1ñ 1©"¯)©)ñ 1r'   c                ó&   € WP                   n        R # r`   rÔ  ©r2   r  s   &&r$   Úset_input_embeddingsÚ$FlavaImageModel.set_input_embeddingsÀ  s   € Ø+0�‰Ö(r'   c                óø   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[R,          RS[ P                  R,          RS[R,          RS[R,          RS[R,          R	S[S[,          /# )
r   r³   Nr´   r°   r!  r"  rŠ  r‹  r   )r=   r•   rµ   rL   r!   r   )r"   r#   s   "€r$   r%   rÇ  Ä  sŽ   ø€ ÷ /
ñ /
á—l‘l TÕ)ð/
ñ ×)Ñ)¨DÕ0ð/
ñ #'¨¥+ð	/
ñ
 Ÿ™ tÕ+ð/
ñ   $�;ð/
ñ # T�kð/
ñ ˜D•[ð/
ñ 
Ñ+Õ	+ñ/
r'   c                ó  € Ve   TMV P                   P                  pVe   TMV P                   P                  pVe   TMV P                   P                  pVf   \	        R4      hV P                  WVR7      p	V P                  V	VVVVR7      p
V
^ ,          pV P                  V4      pV P                  e   V P                  V4      MRpV'       g   W¼3V
R,          ,           # \        VVV
P                  V
P                  R7      # )z­
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, image_num_patches)`):
    Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
Nz You have to specify pixel_values)r´   r°   ©r!  r"  rŠ  r‹  rŸ   ©r�  Úpooler_outputr   r‘  )rw   r"  rŠ  r‹  rØ   r’   rÊ  rË  rÌ  r   r   r‘  )r2   r³   r´   r°   r!  r"  rŠ  r‹  ÚkwargsÚembedding_outputÚencoder_outputsÚsequence_outputr¥  s   &&&&&&&&,    r$   rÀ   ÚFlavaImageModel.forwardÃ  s  € ð  2CÒ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ò$DÑ È$Ï+É+×JjÑJjð 	ð &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆàÒÜÐ?Ó@Ð@àŸ?™?ØÐTlð +ó 
Ðð Ÿ,™,ØØ)Ø/Ø!5Ø#ð 'ó 
ˆð *¨!Õ,ˆØŸ.™.¨Ó9ˆØ8<¿¹Ò8O˜Ÿ™ OÔ4ÐUYˆçØ#Ð3°oÀbÕ6IÕIÐIä)Ø-Ø'Ø)×7Ñ7Ø&×1Ñ1ô	
ð 	
r'   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rœ  )r   )r"   r#   s   "€r$   r%   rÇ  ¤  s   ø‡ ‚ áÑò r'   ©rw   r’   rÊ  rË  rÌ  ©r¼  ©T©NNNNNNN)r@   rA   rB   rC   r¾  Úmain_input_namer¿  r‚   rÕ  rÛ  r   rÀ   rE   rF   rG   rÄ   rÅ   s   @@r$   rÃ  rÃ  ¤  sW   ù‡ € ð ,ÐØ$€OØ!Ð÷õ ÷"0ð 0÷1ð 1ð ÷/
ñ /
ó ð/
÷A … r'   rÃ  c                   óš   a a€ ] tR tRt oRtRtRV3R lV 3R llltV3R lR ltV3R lR lt]	RV3R	 lR
 ll4       t
V3R ltRtVtV ;t# )ÚFlavaTextModeliö  zflava.text_modelc                ó&   <€ V ^8„  d   QhRS[ RS[/# rÅ  )r   rL   )r"   r#   s   "€r$   r%   ÚFlavaTextModel.__annotate__ý  s   ø€ ÷ ñ ™ð Á4ñ r'   c                ó(  <€ \         SV `  V4       Wn        \        V4      V n        \        V4      V n        \        P                  ! VP                  VP                  R7      V n        V'       d   \        V4      MRV n        V P                  4        R# rÉ  )r�   r‚   rw   râ   r’   r}  rÊ  r   rñ   r†   rò   rË  rš  rÌ  rÍ  rÎ  s   &&&€r$   r‚   ÚFlavaTextModel.__init__ý  sg   ø€ ô
 	‰Ñ˜Ô ØŒä-¨fÓ5ˆŒÜ# FÓ+ˆŒäŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒß->”k &Ô)ÀDˆŒà�‰Ör'   c                ó    <€ V ^8„  d   QhRS[ /# r   )rˆ   )r"   r#   s   "€r$   r%   rð    s   ø€ ÷ /ñ /¡oñ /r'   c                ó.   € V P                   P                  # r`   ©r’   rí   r7   s   &r$   rÕ  Ú#FlavaTextModel.get_input_embeddings  s   € Ø�‰×.Ñ.Ð.r'   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rØ  rÑ  )r"   r#   s   "€r$   r%   rð    s   ø€ ÷ 0ñ 0©"¯)©)ñ 0r'   c                ó&   € WP                   n        R # r`   rõ  rÚ  s   &&r$   rÛ  Ú#FlavaTextModel.set_input_embeddings  s   € Ø*/�‰Ö'r'   c                ó  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[R,          RS[R,          R	S[S[,          /# )
r   rû   Nr!  r÷   rõ   r"  rŠ  r‹  r   ©r=   r•   rL   r!   r   )r"   r#   s   "€r$   r%   rð    s‘   ø€ ÷ ?
ñ ?
á—<‘< $Õ&ð?
ñ Ÿ™ tÕ+ð?
ñ Ÿ™ tÕ+ð	?
ñ
 —l‘l TÕ)ð?
ñ   $�;ð?
ñ # T�kð?
ñ ˜D•[ð?
ñ 
Ñ+Õ	+ñ?
r'   c                ó:  € Ve   TMV P                   P                  pVe   TMV P                   P                  pVe   TMV P                   P                  pVf   \	        R4      hV P                  VVVR7      p	\        V P                   V	VR7      pV P                  V	VVVVR7      p
V
^ ,          pV P                  V4      pV P                  e   V P                  V4      MRpV'       g   W¼3V
R,          ,           # \        VVV
P                  V
P                  R7      # )a¡  
input_ids (`torch.LongTensor` of shape `(batch_size, text_seq_length)`):
    Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`AutoTokenizer`]. See
    [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details. [What are input
    IDs?](../glossary#input-ids)
token_type_ids (`torch.LongTensor` of shape `(batch_size, text_seq_length)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
    1]`:
    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    [What are token type IDs?](../glossary#token-type-ids)
NzYou have to specify input_ids)rû   r÷   rõ   ©rw   r  r!  rß  rŸ   rà  )rw   r"  rŠ  r‹  rØ   r’   r   rÊ  rË  rÌ  r   r   r‘  )r2   rû   r!  r÷   rõ   r"  rŠ  r‹  râ  rã  rä  rå  r¥  s   &&&&&&&&,    r$   rÀ   ÚFlavaTextModel.forward  s-  € ð0 2CÒ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ò$DÑ È$Ï+É+×JjÑJjð 	ð &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆàÒÜÐ<Ó=Ð=àŸ?™?ØØ)Ø%ð +ó 
Ðô 3Ø—;‘;Ø*Ø)ô
ˆð Ÿ,™,ØØ)Ø/Ø!5Ø#ð 'ó 
ˆð *¨!Õ,ˆØŸ.™.¨Ó9ˆØ8<¿¹Ò8O˜Ÿ™ OÔ4ÐUYˆçØ#Ð3°oÀbÕ6IÕIÐIä)Ø-Ø'Ø)×7Ñ7Ø&×1Ñ1ô	
ð 	
r'   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rœ  )r   )r"   r#   s   "€r$   r%   rð  ö  s   ø‡ ‚ áÑò r'   rè  )r½  rê  rë  )r@   rA   rB   rC   r¾  r¿  r‚   rÕ  rÛ  r   rÀ   rE   rF   rG   rÄ   rÅ   s   @@r$   rî  rî  ö  sQ   ù‡ € ð +ÐØ Ð÷õ ÷ /ð /÷0ð 0ð ÷?
ñ ?
ó ð?
÷= … r'   rî  c                   óv   a a€ ] tR tRt oRtRtR
V3R lV 3R lllt]RV3R lR ll4       tV3R lt	R	t
VtV ;t# )r³  iV  zflava.multimodal_modelr   c                ó    <€ V ^8„  d   QhRS[ /# rœ  ©r   )r"   r#   s   "€r$   r%   Ú!FlavaMultimodalModel.__annotate__]  s   ø€ ÷ ñ Ñ4ñ r'   c                óØ  <€ \         SV `  V4       Wn        V P                  P                  V n        V P                  '       d<   \        P
                  ! \        P                  ! ^^VP                  4      4      V n	        \        V4      V n        \        P                  ! VP                  VP                  R7      V n        V'       d   \        V4      MRV n        V P#                  4        R# rÉ  )r�   r‚   rw   r´  r   r„   r=   r…   r†   r‡   r}  rÊ  rñ   rò   rË  rš  rÌ  rÍ  rÎ  s   &&&€r$   r‚   ÚFlavaMultimodalModel.__init__]  sœ   ø€ ô
 	‰Ñ˜Ô ØŒØ!Ÿ[™[×6Ñ6ˆÔØ××ÐÜŸ\š\¬%¯+ª+°a¸¸F×<NÑ<NÓ*OÓPˆDŒNä# FÓ+ˆŒäŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒß->”k &Ô)ÀDˆŒà�‰Ör'   c                ó®   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[R,          RS[R,          RS[R,          RS[S[,          /# r‰  rû  )r"   r#   s   "€r$   r%   r  p  sf   ø€ ÷ 3
ñ 3
á—|‘|ð3
ñ Ÿ™ tÕ+ð3
ñ   $�;ð	3
ñ
 # T�kð3
ñ ˜D•[ð3
ñ 
Ñ+Õ	+ñ3
r'   c                ó¼  € Ve   TMV P                   P                  pVe   TMV P                   P                  pVe   TMV P                   P                  pVP	                  4       w  rxp	V P
                  '       d@   V P                  P                  VRR4      p
\        P                  ! W¡3^R7      pV^,          p\        V P                   VVR7      pV P                  VVVVVR7      pV^ ,          pV P                  V4      pV P                  e   V P                  V4      MRpV'       g   WÍ3VR,          ,           # \        VVVP                  VP                   R7      # )z¦
hidden_states (`torch.FloatTensor` of shape `(batch_size, image_num_patches + text_seq_len, hidden_size)`):
    The concatenated hidden states of unimodal encoders.
Nrœ   rý  rß  rŸ   rà  r    )rw   r"  rŠ  r‹  r™   r´  r‡   r·   r=   r©   r   rÊ  rË  rÌ  r   r   r‘  )r2   r   r!  r"  rŠ  r‹  râ  rº   r  r¼   r¿   rä  rå  r¥  s   &&&&&&,       r$   rÀ   ÚFlavaMultimodalModel.forwardo  sO  € ð 2CÒ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ò$DÑ È$Ï+É+×JjÑJjð 	ð &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆà$1×$6Ñ$6Ó$8Ñ!ˆ
 à××ÐØŸ™×.Ñ.¨z¸2¸rÓBˆJÜ!ŸIšI zÐ&AÀqÔIˆMØ˜!�OˆJä2Ø—;‘;Ø'Ø)ô
ˆð Ÿ,™,ØØ)Ø/Ø!5Ø#ð 'ó 
ˆð *¨!Õ,ˆØŸ.™.¨Ó9ˆØ8<¿¹Ò8O˜Ÿ™ OÔ4ÐUYˆçØ#Ð3°oÀbÕ6IÕIÐIä)Ø-Ø'Ø)×7Ñ7Ø&×1Ñ1ô	
ð 	
r'   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rœ  r  )r"   r#   s   "€r$   r%   r  V  s   ø‡ ‚ á!Ñ!ò r'   )r‡   rw   rÊ  rË  rÌ  r´  rê  )NNNN)r@   rA   rB   rC   r¾  rì  r‚   r   rÀ   rE   rF   rG   rÄ   rÅ   s   @@r$   r³  r³  V  s<   ù‡ € ð 1ÐØ%€O÷õ ð$ ÷3
ñ 3
ó ð3
÷5 … r'   r³  c                   ó¾   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4       4       t]]RV3R lR ll4       4       t]RV3R lR	 ll4       t	V3R
 lt
RtVtV ;t# )rµ  i¦  c                ó    <€ V ^8„  d   QhRS[ /# rœ  r  )r"   r#   s   "€r$   r%   ÚFlavaModel.__annotate__ª  s   ø€ ÷ )ñ )™{ñ )r'   c                ó  <€ \         SV `  V4       \        VP                  \        4      '       g#   \        R \        VP                  4       R24      h\        VP                  \        4      '       g#   \        R\        VP                  4       R24      h\        VP                  \        4      '       g*   \        RR\        VP                  4       R2,           4      hVP                  pVP                  pVP                  pVP                  V n        VP                  V n        VP                  V n        VP                  V n        \!        V4      V n        \%        V4      V n        \)        V4      V n        \,        P.                  ! V P                  V P                  4      V n        \,        P.                  ! V P                  V P                  4      V n        \,        P4                  ! \6        P8                  ! V P:                  P<                  4      4      V n        \,        P.                  ! V P                  V P                  4      V n         \,        P.                  ! V P                  V P                  4      V n!        V PE                  4        R# )zLconfig.text_config is expected to be of type FlavaTextConfig but is of type r  zNconfig.image_config is expected to be of type FlavaImageConfig but is of type zMconfig.multimodal_config is expected to be of type FlavaMultimodalConfig but zis of type N)#r�   r‚   rÍ   Útext_configr   Ú	TypeErrorÚtypeÚimage_configr   Úmultimodal_configr   Úprojection_dimr†   Útext_hidden_sizeÚimage_hidden_sizeÚmm_hidden_sizerî  Ú
text_modelrÃ  Úimage_modelr³  Úmultimodal_modelr   r  Úimage_projectionÚtext_projectionr„   r=   Útensorrw   r¸  r·  Úimage_to_mm_projectionÚtext_to_mm_projectionrÍ  )r2   rw   r  r  r  r�   s   &&   €r$   r‚   ÚFlavaModel.__init__ª  sþ  ø€ Ü‰Ñ˜Ô ä˜&×,Ñ,¬o×>Ò>ÜðÜ˜×+Ñ+Ó,Ð-¨Qð0óð ô
 ˜&×-Ñ-Ô/?×@Ò@ÜðÜ˜×,Ñ,Ó-Ð.¨að1óð ô
 ˜&×2Ñ2Ô4I×JÒJÜØ_Ø¤ V×%=Ñ%=Ó >Ð?¸qÐAõBóð ð
 ×(Ñ(ˆØ×*Ñ*ˆØ"×4Ñ4Ðà$×3Ñ3ˆÔØ +× 7Ñ 7ˆÔØ!-×!9Ñ!9ˆÔØ/×;Ñ;ˆÔä(¨Ó5ˆŒÜ*¨<Ó8ˆÔÜ 4Ð5FÓ GˆÔä "§	¢	¨$×*@Ñ*@À$×BUÑBUÓ VˆÔÜ!Ÿyšy¨×)>Ñ)>À×@SÑ@SÓTˆÔÜŸ<š<¬¯ª°T·[±[×5WÑ5WÓ(XÓYˆÔä&(§i¢i°×0FÑ0FÈ×H[ÑH[Ó&\ˆÔ#Ü%'§Y¢Y¨t×/DÑ/DÀd×FYÑFYÓ%ZˆÔ"à�‰Ör'   c                óØ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[S[,          RS[S[,          /# )r   rû   r!  Nr÷   rõ   râ  r   )r=   r•   r   r   r!   r   )r"   r#   s   "€r$   r%   r  ×  sr   ø€ ÷ /ñ /á—<‘<ð/ñ Ÿ™ tÕ+ð/ñ Ÿ™ tÕ+ð	/ñ
 —l‘l TÕ)ð/ñ Ñ+Õ,ð/ñ 
Ñ+Õ	+ñ/r'   c                ó‚   € V P                   ! RRVRVRVRVRR/VB pVP                  pV P                  V4      Vn        V# )aQ  
input_ids (`torch.LongTensor` of shape `(batch_size, text_seq_length)`):
    Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`AutoTokenizer`]. See
    [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details. [What are input
    IDs?](../glossary#input-ids)
token_type_ids (`torch.LongTensor` of shape `(batch_size, text_seq_length)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
    1]`:
    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    [What are token type IDs?](../glossary#token-type-ids)

Examples:

```python
>>> import torch
>>> from transformers import AutoProcessor, FlavaModel

>>> model = FlavaModel.from_pretrained("{0}")
>>> processor = AutoProcessor.from_pretrained("{0}")

>>> inputs = processor(
...     text=["a photo of a cat", "a photo of a dog"], max_length=77, padding="max_length", return_tensors="pt"
... )
>>> with torch.inference_mode():
...     text_features = model.get_text_features(**inputs)
```
rû   r!  r÷   rõ   r‹  Tr?   )r  r�  r  rá  )r2   rû   r!  r÷   rõ   râ  Útext_outputsr�  s   &&&&&,  r$   Úget_text_featuresÚFlavaModel.get_text_featuresÕ  ss   € ðL 48·?²?ñ 4
Øð4
à)ð4
ð *ð4
ð &ð	4
ð
 ð4
ð ñ4
ˆð )×:Ñ:ÐØ%)×%9Ñ%9Ð:KÓ%LˆÔ"àÐr'   c                óÄ   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[R,          RS[ P                  R,          RS[S[,          RS[S[,          /# )r   r³   r´   Nr°   r!  râ  r   )r=   r•   rµ   rL   r   r   r!   r   )r"   r#   s   "€r$   r%   r  
  so   ø€ ÷ *ñ *á—l‘lð*ñ ×)Ñ)¨DÕ0ð*ñ #'¨¥+ð	*ñ
 Ÿ™ tÕ+ð*ñ Ñ+Õ,ð*ñ 
Ñ+Õ	+ñ*r'   c                ó‚   € V P                   ! RRVRVRVRVRR/VB pVP                  pV P                  V4      Vn        V# )a   
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, image_num_patches)`):
    Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).

Examples:

```python
>>> import torch
>>> from transformers import AutoProcessor, FlavaModel
>>> from transformers.image_utils import load_image

>>> model = FlavaModel.from_pretrained("{0}")
>>> processor = AutoProcessor.from_pretrained("{0}")

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = load_image(url)

>>> inputs = processor(images=image, return_tensors="pt")

>>> with torch.inference_mode():
...     image_features = model.get_image_features(**inputs)
```
r³   r´   r!  r°   r‹  Tr?   )r  r�  r  rá  )r2   r³   r´   r°   r!  râ  Úimage_outputsr�  s   &&&&&,  r$   Úget_image_featuresÚFlavaModel.get_image_features  su   € ðB 59×4DÒ4Dñ 5
Ø%ð5
à+ð5
ð *ð5
ð &>ð	5
ð
 ð5
ð ñ5
ˆð *×;Ñ;ÐØ&*×&;Ñ&;Ð<MÓ&NˆÔ#àÐr'   c                óŠ  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          R	S[R,          R
S[R,          RS[RS[R,          RS[S[,          /# )r   rû   Nr³   r!  r÷   r´   rõ   Úimage_attention_maskÚskip_multimodal_encoderr"  rŠ  r‹  r   )r=   Ú
LongTensorr>   r•   rL   r!   r   )r"   r#   s   "€r$   r%   r  7  sè   ø€ ÷ N
ñ N
á×#Ñ# dÕ*ðN
ñ ×'Ñ'¨$Õ.ðN
ñ Ÿ™ tÕ+ð	N
ñ
 Ÿ™ tÕ+ðN
ñ Ÿ™¨Õ,ðN
ñ ×&Ñ&¨Õ-ðN
ñ $Ÿl™l¨TÕ1ðN
ñ "&¨¥ðN
ñ   $�;ðN
ñ #ðN
ñ ˜D•[ðN
ñ 
Ñ!Õ	!ñN
r'   c           
     ó^  € Ve   TMV P                   P                  pV
'       g   \        R4      hRpRpRpRpVeA   V P                  VVVV	V
VR7      pV^ ,          V^,          ríV P	                  VR	,          4      pRpRpRpRpVeC   V P                  VVVVV	V
VR7      pV^ ,          V^,          ppV P                  VR	,          4      pRpRpVe½   Ve¹   V'       g±   Vet   VP                  w  pppV P                  P                  '       d
   V^,          p\        P                  ! VVVP                  R7      p\        P                  ! VV.^R7      pMRp\        P                  ! VV.^R7      pV P                  VVVR7      pV^ ,          pV'       g	   VVVVVV3# \        VVVVVVR7      # )
aß  
input_ids (`torch.LongTensor` of shape `(batch_size, image_num_patches + text_seq_len)`):
    Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`AutoTokenizer`]. See
    [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details. [What are input
    IDs?](../glossary#input-ids)
token_type_ids (`torch.LongTensor` of shape `(batch_size, image_num_patches + text_seq_len)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
    1]`:
    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    [What are token type IDs?](../glossary#token-type-ids)
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, image_num_patches)`):
    Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
image_attention_mask (`torch.Tensor` of shape `(batch_size, image_num_patches)`, *optional*):
    Mask to avoid performing attention on padding pixel values for image inputs. Mask values selected in `[0, 1]`:
    - 1 for pixel values that are real (i.e., **not masked**),
    - 0 for pixel values that are padding (i.e., **masked**).
skip_multimodal_encoder (*bool*, *optional*):
    Skip any calculations for multimodal encoder. Useful if multimodal encoding is not going to be used.

Examples:

```python
>>> from PIL import Image
>>> import httpx
>>> from io import BytesIO
>>> from transformers import AutoProcessor, FlavaModel

>>> model = FlavaModel.from_pretrained("facebook/flava-full")
>>> processor = AutoProcessor.from_pretrained("facebook/flava-full")

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))

>>> inputs = processor(text=["a photo of a cat"], images=image, return_tensors="pt", padding=True)

>>> outputs = model(**inputs)

>>> image_embeddings = outputs.image_embeddings
>>> text_embeddings = outputs.text_embeddings
>>> multimodal_embeddings = outputs.multimodal_embeddings

>>> outputs.image_embeddings.shape
torch.Size([1, 197, 768])

>>> text_embeddings.shape
torch.Size([1, 7, 768])

>>> multimodal_embeddings.shape
torch.Size([1, 205, 768])
```
NzRFLAVA model requires hidden states to work. Please set `output_hidden_states=True`)r³   r´   r!  r"  rŠ  r‹  )rû   r!  rõ   r÷   r"  rŠ  r‹  ©rÿ   rœ   )r!  r‹  )r:   r+   r;   r*   r<   r,   r    )rw   r‹  rØ   r  r  r  r  r¡   r  r´  r=   Úonesrÿ   r©   r   )r2   rû   r³   r!  r÷   r´   rõ   r+  r,  r"  rŠ  r‹  râ  r:   Úimage_statesÚimage_mm_projectionr+   r;   Útext_statesÚtext_mm_projectionr*   r<   r,   rº   r»   r¼   Úattention_mask_imageÚattention_multimodalÚmultimodal_inputs   &&&&&&&&&&&&,                r$   rÀ   ÚFlavaModel.forward6  s
  € ðL &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆß#ÜÐqÓrÐrØÐØˆØ"ÐØˆØÒ#Ø×+Ñ+Ø)Ø /Ø3Ø"3Ø%9Ø'ð ,ó ˆLð .:¸!­_¸lÈ1½o˜là"&×"=Ñ"=¸lÈ2Õ>NÓ"OÐàˆØˆØ!ÐØˆØÒ ØŸ/™/Ø#Ø-Ø)Ø-Ø"3Ø%9Ø'ð *ó ˆKð ,7°q­>¸;Àq½>˜[ˆOà!%×!;Ñ!;¸KÈ½OÓ!LÐà $ÐØ ÐØÒ*Ð/AÒ/M×VmØÒ)Ø)<×)BÑ)BÑ&�
˜G QØ×(Ñ(×6×6Ð6Ø˜q•L�GÜ',§z¢z°*¸gÐNa×NhÑNhÔ'iÐ$Ü',§y¢yÐ2FÈÐ1WÐ]^Ô'_Ñ$à'+Ð$Ü$ŸyšyÐ*=Ð?QÐ)RÐXYÔZÐØ $× 5Ñ 5Ø Ð1EÐS^ð !6ó !Ðð %6°aÕ$8Ð!çà ØØØØ%Ø!ðð ô  Ø-Ø%Ø+Ø#Ø"7Ø/ô
ð 	
r'   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rœ  r  )r"   r#   s   "€r$   r%   r  ¦  r»  r'   )r  r  r  r  r·  r  r  r  r  r  r  r  r  )NNNNNNNNNTN)r@   rA   rB   rC   r‚   r   r   r#  r(  rÀ   rE   rF   rG   rÄ   rÅ   s   @@r$   rµ  rµ  ¦  sx   ù‡ € ÷)ó )ðV Ø÷/ñ /ó ó ð/ðb Ø÷*ñ *ó ó ð*ðX ÷N
ñ N
ó ðN
÷c … r'   rµ  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚFlavaImageCodebookResPathiÈ  c                ó&   <€ V ^8„  d   QhRS[ RS[ /# )r   Úin_sizeÚout_size©r–   )r"   r#   s   "€r$   r%   Ú&FlavaImageCodebookResPath.__annotate__É  s   ø€ ÷ (ñ (¡ð (©sñ (r'   c                ó   <€ \         SV `  4        V^,          p\        4       p\        P                  ! 4       VR&   \        P
                  ! W^^R7      VR&   \        P                  ! 4       VR&   \        P
                  ! WD^^R7      VR&   \        P                  ! 4       VR&   \        P
                  ! WD^^R7      VR&   \        P                  ! 4       VR&   \        P
                  ! WB^^ R7      VR	&   \        P                  ! V4      V n        R
# )é   Úrelu_1©rË   ÚpaddingÚconv_1Úrelu_2Úconv_2Úrelu_3Úconv_3Úrelu_4Úconv_4N)r�   r‚   r   r   ÚReLUrÑ   Ú
SequentialÚpath)r2   r=  r>  râ  Úhid_sizerO  r�   s   &&&,  €r$   r‚   Ú"FlavaImageCodebookResPath.__init__É  sÂ   ø€ Ü‰ÑÔØ˜q•=ˆä‹}ˆÜŸš›ˆˆX‰ÜŸš 7À!ÈQÔOˆˆX‰ÜŸš›ˆˆX‰ÜŸš 8À1ÈaÔPˆˆX‰ÜŸš›ˆˆX‰ÜŸš 8À1ÈaÔPˆˆX‰ÜŸš›ˆˆX‰ÜŸš 8À1ÈaÔPˆˆX‰ä—M’M $Ó'ˆŽ	r'   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   rÛ   r   rü   )r"   r#   s   "€r$   r%   r@  Ù  s#   ø€ ÷ ñ ™Ÿ™ð ©%¯,©,ñ r'   c                ó$   € V P                  V4      # r`   ©rO  ©r2   rÛ   s   &&r$   rÀ   Ú!FlavaImageCodebookResPath.forwardÙ  s   € Ø�y‰y˜‹|Ðr'   rU  r5  rÅ   s   @@r$   r;  r;  È  s   ù‡ € ÷(ó (÷ ÷ ð r'   r;  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚFlavaImageCodebookBlockiÝ  c                ó,   <€ V ^8„  d   QhRS[ RS[ RS[ /# )r   r=  r>  Ú
num_layersr?  )r"   r#   s   "€r$   r%   Ú$FlavaImageCodebookBlock.__annotate__Þ  s'   ø€ ÷ 
Eñ 
E¡ð 
E©sð 
EÁñ 
Er'   c                óì   <€ \         SV `  4        ^V^,          ,          V n        W8w  d    \        P                  ! W^^ R7      V n        M\        P                  ! 4       V n        \        W4      V n        R# )r|   rD  N)	r�   r‚   Ú	post_gainr   rÑ   Úid_pathÚIdentityr;  Úres_path)r2   r=  r>  r[  râ  r�   s   &&&&,€r$   r‚   Ú FlavaImageCodebookBlock.__init__Þ  sQ   ø€ Ü‰ÑÔà˜j¨!�mÕ,ˆŒàÔÜŸ9š9 WÀAÈqÔQˆD�LäŸ;š;›=ˆDŒLä1°'ÓDˆŽr'   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rS  rü   )r"   r#   s   "€r$   r%   r\  ê  s'   ø€ ÷ Cñ C™Ÿ™ð C©%¯,©,ñ Cr'   c                ór   € V P                  V4      V P                  V P                  V4      ,          ,           # r`   ©r_  r^  ra  rV  s   &&r$   rÀ   ÚFlavaImageCodebookBlock.forwardê  s'   € Ø�|‰|˜A‹ §¡°$·-±-ÀÓ2BÕ!BÕBÐBr'   re  r5  rÅ   s   @@r$   rY  rY  Ý  s#   ù‡ € ÷
Eó 
E÷C÷ Cð Cr'   rY  c                   óT   a a€ ] tR tRt oRV3R lV 3R llltV3R lR ltRtVtV ;t# )ÚFlavaImageCodebookLayerGroupiî  c          
      ó8   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[/# )r   Ú
num_blocksr[  r=  r>  Úuse_pool)r–   rL   )r"   r#   s   "€r$   r%   Ú)FlavaImageCodebookLayerGroup.__annotate__ï  s2   ø€ ÷ +ñ +¡3ð +±Cð +Á#ð +ÑQTð +Ñ`dñ +r'   c                óL  <€ \         SV `  4        \        4       p\        V4       F>  pV^ 8X  d   \	        W4V4      VRV^,            2&   K%  \	        WDV4      VRV^,            2&   K@  	  V'       d   \
        P                  ! ^R7      VR&   \
        P                  ! V4      V n        R# )rÖ   Úblock_)rË   ÚpoolN)	r�   r‚   r   rƒ  rY  r   Ú	MaxPool2drN  Úgroup)	r2   rj  r[  r=  r>  rk  Úblocksr•  r�   s	   &&&&&&  €r$   r‚   Ú%FlavaImageCodebookLayerGroup.__init__ï  sŒ   ø€ Ü‰ÑÔÜ“ˆÜ�zÖ"ˆAØ�AŒvÜ+BÀ7ÐV`Ó+a�˜  A¥˜wÐ'Ó(ä+BÀ8ÐWaÓ+b�˜  A¥˜wÐ'Ó(ñ	 #÷ ÜŸ\š\°aÔ8ˆF�6‰Nä—]’] 6Ó*ˆŽ
r'   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rS  rü   )r"   r#   s   "€r$   r%   rl  ý  s#   ø€ ÷ ñ ™Ÿ™ð ©%¯,©,ñ r'   c                ó$   € V P                  V4      # r`   ©rq  rV  s   &&r$   rÀ   Ú$FlavaImageCodebookLayerGroup.forwardý  s   € Ø�z‰z˜!‹}Ðr'   rv  rê  r5  rÅ   s   @@r$   rh  rh  î  s   ù‡ € ÷+õ +÷÷ ð r'   rh  a"  
    The FLAVA's image codebook model inspired from DALL-E's original encoder. Outputs raw hidden states and can be used
    to generate image tokens for an image based on DALL-E's vocab. Used to generate labels for MIM. Use
    `get_codebook_indices` to get image tokens for an image.
    c                   ó�   a a€ ] tR tRt oRtRtRtRtV3R lV 3R lltV3R lR lt	V3R	 lR
 lt
V3R lR ltV3R ltRtVtV ;t# )ÚFlavaImageCodebooki  Úmodelr³   Fc                ó&   <€ V ^8„  d   QhRS[ RS[/# )r   rw   râ  )r   r   )r"   r#   s   "€r$   r%   ÚFlavaImageCodebook.__annotate__  s   ø€ ÷ *,ñ *,á(ð*,ñ ñ*,r'   c                ó:  <€ \         SV `  V4       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 P
                  ,          p\        4       p\        P                  ! 4       VR &   \        P                  ! ^V P                  ,          V P                  ^^ R7      VR&   \        4       p\        P                  ! V P                  ^V P                  ,          ^^R7      VR&   \        V P
                  V^V P                  ,          ^V P                  ,          4      VR&   \        V P
                  V^V P                  ,          ^V P                  ,          4      VR&   \        V P
                  V^V P                  ,          ^V P                  ,          4      VR&   \        V P
                  V^V P                  ,          ^V P                  ,          RR7      VR	&   \        P                  ! V4      VR
&   \        P                  ! V4      V n        V P                  4        V P                  P                   '       d!   V P#                  4        F
  pRVn        K  	  R# R# )ÚrelurD  ÚconvÚinputÚgroup_1Úgroup_2Úgroup_3F)rk  Úgroup_4rK  N)r�   r‚   rw   Ú
num_groupsÚinput_channelsÚnum_blocks_per_groupr†   rë   r   r   rM  rÑ   rh  rN  rr  rÍ  ÚfreezeÚ
parametersÚrequires_grad)r2   rw   râ  r[  Úoutput_blocksrr  Úparamr�   s   &&,    €r$   r‚   ÚFlavaImageCodebook.__init__  s  ø€ ô
 	‰Ñ˜Ô àŒØ ×+Ñ+ˆŒØ$×3Ñ3ˆÔØ$*×$?Ñ$?ˆÔ!Ø!×-Ñ-ˆÔØ ×+Ñ+ˆŒà—_‘_ t×'@Ñ'@Õ@ˆ
ä#›ˆÜ "§¢£	ˆ�fÑÜ "§	¢	¨!¨d×.>Ñ.>Õ*>ÀÇÁÐ]^ÐhiÔ jˆ�fÑä“ˆÜŸ)š) D×$7Ñ$7¸¸T×=MÑ=MÕ9MÐ[\ÐfgÔhˆˆw‰Ü8Ø×%Ñ% z°1°t×7GÑ7GÕ3GÈÈT×M]ÑM]ÕI]ó
ˆˆyÑô 9Ø×%Ñ% z°1°t×7GÑ7GÕ3GÈÈT×M]ÑM]ÕI]ó
ˆˆyÑô 9Ø×%Ñ% z°1°t×7GÑ7GÕ3GÈÈT×M]ÑM]ÕI]ó
ˆˆyÑô 9Ø×%Ñ% z°1°t×7GÑ7GÕ3GÈÈT×M]ÑM]ÕI]Ðhmô
ˆˆyÑô Ÿ=š=¨Ó7ˆˆxÑä—m’m FÓ+ˆŒà�‰Ôà�;‰;××ÐØŸ™Ö*�Ø&+�Ö#ó +ñ r'   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   r³   r   rü   )r"   r#   s   "€r$   r%   r|  <  s#   ø€ ÷ .ñ .±·±ð .Á%Ç,Á,ñ .r'   c                óv   € R \          R\          R2 V P                  V4      p\        P                  ! V^R7      # )aI  
        Args:
            pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
                Pixel values. Codebook pixel values can be obtained using [`AutoImageProcessor`] by passing
                `return_codebook_pixels=True`. See [`FlavaImageProcessor.__call__`] for details.

        Examples:
        ```python
        >>> from PIL import Image
        >>> import httpx
        >>> from io import BytesIO
        >>> from transformers import AutoImageProcessor, FlavaImageCodebook

        >>> model = FlavaImageCodebook.from_pretrained("úE")
        >>> image_processor = AutoImageProcessor.from_pretrained("a¹  ")

        >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
        >>> with httpx.stream("GET", url) as response:
        ...     image = Image.open(BytesIO(response.read()))

        >>> inputs = image_processor([image], return_codebook_pixels=True, return_tensors="pt")
        >>> inputs = dict(pixel_values=inputs.codebook_pixel_values)

        >>> outputs = model.get_codebook_indices(**inputs)
        ```
        )Úaxis)Ú_CHECKPOINT_FOR_CODEBOOK_DOCrr  r=   Úargmax©r2   r³   Úz_logitss   && r$   Úget_codebook_indicesÚ'FlavaImageCodebook.get_codebook_indices<  sI   € ð9ô :VÐ8Vð WCÜC_ÐB`ð a	ñ	ð4 —;‘;˜|Ó,ˆÜ�|Š|˜H¨1Ô-Ð-r'   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r�  rü   )r"   r#   s   "€r$   r%   r|  Z  s#   ø€ ÷ +ñ +©u¯|©|ð +ÁÇÁñ +r'   c                ó^   € V P                  V4      p\        P                  ! ^R7      ! V4      # )r|   rœ   )rr  r   ÚSoftmaxr•  s   && r$   Úget_codebook_probsÚ%FlavaImageCodebook.get_codebook_probsZ  s$   € Ø—;‘;˜|Ó,ˆÜ�zŠz˜aÕ  Ó*Ð*r'   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r�  )r=   r>   r•   )r"   r#   s   "€r$   r%   r|  ^  s%   ø€ ÷ ")ñ ")¡E×$5Ñ$5ð ")ÁEÇLÁLñ ")r'   c                óH  € R \          R\          R2 \        VP                  4      ^8w  d   \        RVP                   R24      hVP                  ^,          V P                  8w  d-   \        RVP                  ^,           RV P                   24      hV P                  V4      # )aJ  
        Args:
            pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
                Pixel values. Codebook pixel values can be obtained using [`AutoImageProcessor`] by passing
                `return_codebook_pixels=True`. See [`FlavaImageProcessor.__call__`] for details.

        Examples:

        ```python
        >>> from PIL import Image
        >>> import httpx
        >>> from io import BytesIO
        >>> from transformers import AutoImageProcessor, FlavaImageCodebook

        >>> model = FlavaImageCodebook.from_pretrained("r‘  aÖ  ")

        >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
        >>> with httpx.stream("GET", url) as response:
        ...     image = Image.open(BytesIO(response.read()))

        >>> inputs = image_processor([image], return_codebook_pixels=True, return_tensors="pt")
        >>> inputs = dict(pixel_values=inputs.codebook_pixel_values)

        >>> outputs = model(**inputs)
        >>> print(outputs.shape)
        (1, 196)
        ```
        zinput shape z
 is not 4dz
input has z channels but model built for )r“  Úlenr¡   rØ   r†  rr  )r2   r³   râ  s   &&,r$   rÀ   ÚFlavaImageCodebook.forward^  s­   € ð9ô :VÐ8Vð WCÜC_ÐB`ð a	ñ	ô: ˆ|×!Ñ!Ó" aÔ'Ü˜|¨L×,>Ñ,>Ð+?¸zÐJÓKÐKØ×Ñ˜aÕ  D×$7Ñ$7Ô7Ü˜z¨,×*<Ñ*<¸QÕ*?Ð)@Ð@^Ð_c×_rÑ_rÐ^sÐtÓuÐuØ�{‰{˜<Ó(Ð(r'   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rœ  )r   )r"   r#   s   "€r$   r%   r|    s   ø‡ ‚ ñ %Ñ$ò r'   )rr  rw   r†   r†  r‡  r…  rë   ré  )r@   rA   rB   rC   r¾  rì  r¿  rÀ  r‚   r—  rœ  rÀ   rE   rF   rG   rÄ   rÅ   s   @@r$   ry  ry    sO   ù‡ € ð  Ðà$€OØ!ÐØ&+Ð#÷*,ó *,÷X.ð .÷<+ð +÷")ð ")÷y … r'   ry  c                   ó8   a a€ ] tR tRt oV 3R ltR tRtVtV ;t# )ÚFlavaPredictionHeadTransformiƒ  c                ó‚  <€ \         SV `  4        \        P                  ! VP                  VP                  4      V n        \        VP                  \        4      '       d   \        VP                  ,          V n
        MVP                  V n
        \        P                  ! VP                  VP                  R 7      V n        R# )rå   N)r�   r‚   r   r  r†   r<  rÍ   rZ  r[  r   Útransform_act_fnrñ   rò   rø   s   &&€r$   r‚   Ú%FlavaPredictionHeadTransform.__init__„  s~   ø€ Ü‰ÑÔÜ—Y’Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
Ü�f×'Ñ'¬×-Ò-Ü$*¨6×+<Ñ+<Õ$=ˆDÕ!à$*×$5Ñ$5ˆDÔ!ÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŽr'   c                ól   € V P                  V4      pV P                  V4      pV P                  V4      pV# r`   )r<  r¦  rñ   ra  s   &&r$   rÀ   Ú$FlavaPredictionHeadTransform.forward�  s4   € ØŸ
™
 =Ó1ˆØ×-Ñ-¨mÓ<ˆØŸ™ }Ó5ˆØÐr'   )rñ   r<  r¦  r5  rÅ   s   @@r$   r¤  r¤  ƒ  s   ù‡ € õU÷ò r'   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# )r¯  i”  c                óR  <€ \         SV `  4        Wn        \        V4      V n        \
        P                  ! VP                  VP                  R R7      V n	        \
        P                  ! \        P                  ! VP                  4      4      V n        Ve   W P                  n        R# R# )Tr  N)r�   r‚   rw   r¤  Ú	transformr   r  r†   rë   Údecoderr„   r=   r…   r  Úweight)r2   rw   r®  r�   s   &&&€r$   r‚   Ú"FlavaMaskedPredictionHead.__init__•  ss   ø€ Ü‰ÑÔØŒÜ5°fÓ=ˆŒÜ—y’y ×!3Ñ!3°V×5FÑ5FÈTÔRˆŒÜ—L’L¤§¢¨V×->Ñ->Ó!?Ó@ˆŒ	ØÒØ"(�L‰LÖñ r'   c                óJ   € V P                  V4      pV P                  V4      pV# r`   )r¬  r­  rV  s   &&r$   rÀ   Ú!FlavaMaskedPredictionHead.forwardž  s"   € Ø�N‰N˜1ÓˆØ�L‰L˜‹OˆØˆr'   )r  rw   r­  r¬  r`   r5  rÅ   s   @@r$   r¯  r¯  ”  s   ù‡ € ÷)÷ò r'   r¯  c                   ó8   a a€ ] tR tRt oV 3R ltR tRtVtV ;t# )ÚFlavaITMHeadi¤  c                óœ   <€ \         SV `  4        Wn        \        V4      V n        \
        P                  ! VP                  ^4      V n        R# )r   N)	r�   r‚   rw   rš  rÌ  r   r  r†   Úseq_relationshiprø   s   &&€r$   r‚   ÚFlavaITMHead.__init__¥  s8   ø€ Ü‰ÑÔØŒÜ! &Ó)ˆŒÜ "§	¢	¨&×*<Ñ*<¸aÓ @ˆÖr'   c                óJ   € V P                  V4      pV P                  V4      pV# r`   )rÌ  rµ  rV  s   &&r$   rÀ   ÚFlavaITMHead.forward«  s$   € Ø�K‰K˜‹NˆØ×!Ñ! !Ó$ˆØˆr'   )rw   rÌ  rµ  r5  rÅ   s   @@r$   r³  r³  ¤  s   ù‡ € õA÷ò r'   r³  c                   ó8   a a€ ] tR tRt oV 3R ltR tRtVtV ;t# )ÚFlavaGlobalContrastiveHeadi±  c                óR   <€ \         SV `  4        Wn        VP                  V n        R # r`   )r�   r‚   rw   Úglobal_backprop_contrastiverø   s   &&€r$   r‚   Ú#FlavaGlobalContrastiveHead.__init__²  s!   ø€ Ü‰ÑÔØŒØ+1×+MÑ+MˆÖ(r'   c                ór  € \         P                  ! V4      p\         P                  P                  4       '       d%   \         P                  P	                  4       '       g:   \         P
                  ! VP                  ^ 4      VP                  R7      pV.pV.pEM�VP                  ^ 4      p\         P                  P                  4       p	V P                  '       dh   \         P                  P                  P                  P                  V4      p\         P                  P                  P                  P                  V4      pMš\        V	4       U
u. uF  p
\         P                  ! V4      NK  	  pp
\        V	4       U
u. uF  p
\         P                  ! V4      NK  	  pp
\         P                  P                  Wa4       \         P                  P                  Wr4       V\         P                  P                  4       ,          \         P
                  ! W�P                  R7      ,           p\         P                   ! V4      p\         P                   ! V4      p\         P"                  ! WP%                  ^ ^4      4      V,          p\         P"                  ! W&P%                  ^ ^4      4      V,          pW¼V3# u up
i u up
i )rÖ   r/  )r=   ÚexpÚdistributedÚis_availableÚis_initializedrô   r™   rÿ   Úget_world_sizer¼  r   r¦   Ú
all_gatherrƒ  Ú
zeros_likeÚget_rankr©   r&  rÚ   )r2   r:   r;   r·  ÚtemperatureÚlabelsÚimage_embeddings_allÚtext_embeddings_allÚlocal_batch_sizeÚ
world_sizer¼   Úlogits_per_imageÚlogits_per_texts   &&&&         r$   rÀ   Ú"FlavaGlobalContrastiveHead.forward·  s  € Ü—i’i Ó,ˆÜ× Ñ ×-Ñ-×/Ò/´u×7HÑ7H×7WÑ7W×7YÒ7YÜ—\’\Ð"2×"7Ñ"7¸Ó":ÐCS×CZÑCZÔ[ˆFØ$4Ð#5Ð Ø#2Ð"3Òà/×4Ñ4°QÓ7ÐÜ×*Ñ*×9Ñ9Ó;ˆJà×/×/Ð/ô (-×'8Ñ'8×';Ñ';×'FÑ'F×'QÑ'QÐRbÓ'cÐ$Ü&+×&7Ñ&7×&:Ñ&:×&EÑ&E×&PÑ&PÐQ`Ó&aÑ#äSXÐYcÔSdÓ'eÑSdÈa¬×(8Ò(8¸Ö(IÑSdÐ$Ð'eÜSXÐYcÔSdÓ&eÑSdÈa¤u×'7Ò'7Ð8HÖ'IÑSdÐ#Ð&eÜ×!Ñ!×,Ñ,Ð-AÔTÜ×!Ñ!×,Ñ,Ð-@ÔRà%¬×(9Ñ(9×(BÑ(BÓ(DÕDÄuÇ|Â|Ø ×)@Ñ)@ôHõ ˆFô  %ŸyšyÐ)=Ó>ÐÜ#ŸišiÐ(;Ó<Ðä Ÿ<š<Ð(8×:WÑ:WÐXYÐ[\Ó:]Ó^ÐalÕlÐÜŸ,š, ×8VÑ8VÐWXÐZ[Ó8\Ó]Ð`kÕkˆà°&Ð8Ð8ùò (fùÚ&es   ÅJ/Å;J4)rw   r¼  r5  rÅ   s   @@r$   rº  rº  ±  s   ù‡ € õN÷
9ò 9r'   rº  zk
    The FLAVA model for pretraining which outputs losses, embeddings, logits and transformer outputs.
    c                   óˆ   a a€ ] tR tRt oRRRRRRRR	/tRV3R
 lV 3R llltV3R lR lt]RV3R lR ll4       tRt	Vt
V ;t# )ÚFlavaForPreTrainingiÙ  zmmm_text_head.biaszmmm_text_head.decoder.biaszmim_head.biaszmim_head.decoder.biaszmlm_head.biaszmlm_head.decoder.biaszmmm_image_head.biaszmmm_image_head.decoder.biasc                óH   <€ V ^8„  d   QhRS[ RS[P                  R,          /# )r   rw   Úimage_codebookN)r   r   rÒ  )r"   r#   s   "€r$   r%   Ú FlavaForPreTraining.__annotate__ç  s$   ø€ ÷ !ñ !™{ð !¹B¿I¹IÈÕ<Lñ !r'   c                ór  <€ \         SV `  V4       \        V4      V n        W n        V P                  f-   VP
                  '       d   \        VP                  4      V n        \        VP                  4      V n
        \        VP                  4      V n        \        V4      V n        \        VP                  4      V n        \        VP                  4      V n        \#        V4      V n        VP                  P&                  V n        VP                  P&                  V n        VP,                  V n        VP.                  V n        VP0                  V n        VP2                  V n        VP4                  V n        VP6                  V n        VP8                  V n        VP:                  V n        V P=                  4        R# )zÒ
image_codebook ([`nn.Module`]):
    If passed, the image codebook will be set to this. Otherwise, it will be initialized using the
    image_codebook_config defined in the config first as the first parameter.
N)r�   r‚   rµ  r©  rÓ  Úinit_codebookry  Úimage_codebook_configr¯  r  Úmim_headr  Úmlm_headr³  Úitm_headÚmmm_image_headÚmmm_text_headrº  Úglobal_contrastive_headrë   Úimage_vocab_sizeÚtext_vocab_sizeÚ
mlm_weightÚ
mim_weightÚglobal_contrastive_weightÚce_ignore_indexÚ
itm_weightÚmmm_image_weightÚmmm_text_weightÚ skip_unmasked_multimodal_encoderrÍ  )r2   rw   rÓ  r�   s   &&&€r$   r‚   ÚFlavaForPreTraining.__init__ç  sR  ø€ ô 	‰Ñ˜Ô Ü Ó'ˆŒ
à,ÔØ×ÑÒ&¨6×+?×+?Ð+?Ü"4°V×5QÑ5QÓ"RˆDÔô 2°&×2EÑ2EÓFˆŒÜ1°&×2DÑ2DÓEˆŒÜ$ VÓ,ˆŒÜ7¸×8KÑ8KÓLˆÔÜ6°v×7IÑ7IÓJˆÔÜ'AÀ&Ó'IˆÔ$à &× 3Ñ 3× >Ñ >ˆÔØ%×1Ñ1×<Ñ<ˆÔØ ×+Ñ+ˆŒØ ×+Ñ+ˆŒØ)/×)IÑ)IˆÔ&Ø%×5Ñ5ˆÔØ ×+Ñ+ˆŒØ &× 7Ñ 7ˆÔØ%×5Ñ5ˆÔØ06×0WÑ0WˆÔ-à�‰Ör'   c                ó4   <€ V ^8„  d   QhRS[ P                  /# )r   rÛ   rü   )r"   r#   s   "€r$   r%   rÔ  
  s   ø€ ÷ ñ ™uŸ|™|ñ r'   c                ór   € VP                  4       ^8”  d"   VP                  VP                  ^ 4      R4      pV# )r   r    )r�   r¨   r™   rV  s   &&r$   Ú_resize_to_2dÚ!FlavaForPreTraining._resize_to_2d
  s,   € Ø�5‰5‹7�QŒ;Ø—‘�q—v‘v˜a“y "Ó%ˆAØˆr'   c          %      óŠ  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          R	S[ P                  R,          R
S[ P                  R,          RS[R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[RS[R,          RS[R,          RS[S[ P                  ,          S[,          /# )r   rû   NÚinput_ids_maskedr³   Úcodebook_pixel_valuesr!  r÷   r´   rõ   r+  rç  Ú
mlm_labelsÚ
mim_labelsÚ
itm_labelsr"  rŠ  r‹  Úreturn_lossr   )r=   r-  r>   r•   rL   r!   r[   )r"   r#   s   "€r$   r%   rÔ    sh  ø€ ÷ p
ñ p
á×#Ñ# dÕ*ðp
ñ  ×*Ñ*¨TÕ1ðp
ñ ×'Ñ'¨$Õ.ð	p
ñ
  %×0Ñ0°4Õ7ðp
ñ Ÿ™ tÕ+ðp
ñ Ÿ™ tÕ+ðp
ñ Ÿ™¨Õ,ðp
ñ ×&Ñ&¨Õ-ðp
ñ $Ÿl™l¨TÕ1ðp
ñ +/°­+ðp
ñ —L‘L 4Õ'ðp
ñ —L‘L 4Õ'ðp
ñ —L‘L 4Õ'ðp
ñ   $�;ðp
ñ  #ð!p
ñ" ˜D•[ð#p
ñ$ ˜D•[ð%p
ñ( 
‰u�|‰|Õ	Ñ8Õ	8ñ)p
r'   c                óä  € Ve   TMV P                   P                  pVe   TMV P                   P                  pV
e   T
MV P                  p
Vf   Ve   \        P                  R4       TpV P                  VVVVVV	V
VVRR7
      pV P                  VVVVV	VVVRR7	      pRpVP                  pVP                  pVP                  pVP                  pVP                  pR;p;p;p;p;p;p p!R;p";p#;p$p%R;p&;p'p(Vf   VeP   VfL   V'       dD   V P                  f   \        R4      hVf   \        R4      hV P                  P                  V4      pV P                  ^ 8”  Ed%   VEe    VEf   Tp)VEe   V P                  V4      pV P                  V4      pV P                   WÇP#                  R4      &   V)RVP%                  ^4      ) R1R3,          p)VP#                  V P                   4      p*VV*,          p+V)V*R3,          p)V P'                  V)4      p"V'       d]   \(        P*                  P-                  V"P/                  R"V P0                  4      V+P/                  R"4      4      pVV P                  ,          pMV P'                  V)4      p"V P2                  ^ 8”  dô   Veð   Vfì   Tp,VeÕ   V P                  V4      pV,RVP%                  ^4      ) R1R3,          p,VP#                  V P                   4      p*VV*,          p-V,V*R3,          p,V P5                  V,4      p#V'       d]   \(        P*                  P-                  V#P/                  R"V P6                  4      V-P/                  R"4      4      pVV P2                  ,          pMV P5                  V,4      p#V P8                  ^ 8”  d®   Veª   V P;                  V4      p&Ve•   VP#                  ^ 4      p.V.V.P=                  4       ( ,          pV'       d4   \(        P*                  P-                  V&V4      p!V!V P8                  ,          p!Ve
   VV,          pVe
   VV,          pVe   VV,          pVV,          pVEe;   V P>                  ^ 8”  Ed)   Tp)VP%                  ^4      ^,
          p/V)R^^V/,           1R3,          p)Veå   V P                  V4      pV P                  V4      pV P                   WÇP#                  R4      &   VP#                  V P                   4      p*VV*,          p+V)V*R3,          p)V PA                  V)4      p%V'       d]   \(        P*                  P-                  V%P/                  R"V P0                  4      V+P/                  R"4      4      pVV P>                  ,          pMV PA                  V)4      p%Veý   V PB                  ^ 8”  dì   Tp,V,RVP%                  ^4      ) R1R3,          p,Ve·   V P                  V4      pVP#                  V P                   4      p*VV*,          p-V,V*R3,          p,V PE                  V,4      p$V'       d]   \(        P*                  P-                  V$P/                  R"V P6                  4      V-P/                  R"4      4      pVV PB                  ,          pMV PE                  V,4      p$VEe�   VEe˜   V PF                  ^ 8”  Ed†   V P                  PI                  VR#,          4      p0\(        P*                  PK                  V0R"R	7      p0V P                  PM                  VR#,          4      p1\(        P*                  PK                  V1R"R	7      p1V PN                  '       d9   V P                  PP                  PR                  PU                  \V        \X        4       V P[                  V1V0V P                  PP                  4      w  p'p(p2Ve   V'V,          p'V(V,          p(V2V,          p2V'       dd   \(        P*                  P-                  V'V24      p3\(        P*                  P-                  V(V24      p4V3V4,           ^,          p V V PF                  ,          p \]        VVV!V VVR
7      p5V'       d7   V5P_                  4       '       g!   \a        R V5Pc                  4        4       4      pV'       Ege   TVPd                  e   VPd                  Pg                  4       MRTVPh                  e   VPh                  Pg                  4       MRVP                  VPj                  e   VPj                  Pg                  4       MRTVPd                  e   VPd                  Pg                  4       MRTVPh                  e   VPh                  Pg                  4       MRTVPj                  e   VPj                  Pg                  4       MRV"V#V&V'V(V%V$3p6V'       d"   V5P_                  4       '       g   VV53V6,           p6\l        ;QJ d    . R V6 4       F  NK  	  5# ! R V6 4       4      # \o        R$/ RVbRV5bRVbRVPd                  bRVbRVPh                  bRVP                  bRVPj                  bRVbRVPd                  bRVbRVPh                  bRVbRVPj                  bRV"bRV#bRV&bRV'bRV(bR V%bR!V$b # )%aÈ  
input_ids (`torch.LongTensor` of shape `(batch_size, text_seq_len)`):
    Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`AutoTokenizer`]. See
    [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details. [What are input
    IDs?](../glossary#input-ids)
input_ids_masked (`torch.LongTensor` of shape `(batch_size, text_seq_len)`):
    Indices of input sequence tokens in the vocabulary. These ones are the masked version of the original task
    to be used with MLM. Indices can be obtained using [`AutoTokenizer`] along with
    [`DataCollatorForMaskedLanguageModeling`]. See [`PreTrainedTokenizer.encode`] and
    [`PreTrainedTokenizer.__call__`] for details. [What are input IDs?](../glossary#input-ids)
codebook_pixel_values (`torch.FloatTensor` of shape `(batch_size, num_image_patches, patch_size, patch_size, 3)`, *optional*):
    Pixel values for image patches that are used to compute the image codebook labels for masked image modeling.
token_type_ids (`torch.LongTensor` of shape `(batch_size, text_seq_len)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
    1]`:
    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    [What are token type IDs?](../glossary#token-type-ids)
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, image_num_patches)`):
    Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
image_attention_mask (`torch.FloatTensor` of shape `(batch_size, image_num_patches)`, *optional*):
    Mask to avoid performing attention on padding token indices specifically for images. 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)
skip_unmasked_multimodal_encoder (*bool*, *optional*):
    Skip any calculations for multimodal encoder for unmasked inputs. FLAVA pretraining doesn't need unmasked
    multimodal embeddings or outputs as of now.
mlm_labels (`torch.LongTensor` of shape `(batch_size, text_seq_len)`, *optional*):
    Labels for computing the left-to-right language and multimodal masked modeling loss (next word prediction).
    Indices should be in `[-100, 0, ..., text_config.vocab_size - 1]` (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,
    ..., text_config.vocab_size - 1]`.
mim_labels (`torch.LongTensor` of shape `(batch_size, image_num_patches)`, *optional*):
    Labels for computing the image and multimodal masked modeling loss. Indices should be in `[-100, 0, ...,
    image_config.vocab_size - 1]`. Tokens with indices set to `-100` are ignored (masked), the loss is only
    computed for the tokens with labels in `[0, ..., image_config.vocab_size - 1]`. If not passed, they are
    generated automatically using the image codebook assigned to the model. By default, it uses
    [`FlavaImageCodebook`]. See [`FlavaImageCodebook`] to understand how to generate mim_labels.
itm_labels (`torch.LongTensor` of shape `(batch_size, 1)`, *optional*):
    Labels for computing the image-text matching loss. 0 means the pairs don't match and 1 means they match.
    The pairs with 0 will be skipped for calculation of MMM and global contrastive losses as well.
return_loss (`bool`, *optional*, default to None):
    Whether to return calculated loss or not.

Examples:
```python
>>> from PIL import Image
>>> import httpx
>>> from io import BytesIO
>>> from transformers import FlavaForPreTraining, AutoProcessor

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))

>>> model = FlavaForPreTraining.from_pretrained("facebook/flava-full")
>>> processor = AutoProcessor.from_pretrained("facebook/flava-full")

>>> text = ["a photo of a cat"]

>>> inputs = processor(
...     images=[image],
...     text=text,
...     return_masks=True,
...     return_codebook_pixels=True,
...     padding=True,
...     max_length=77,
...     return_tensors="pt",
... )


>>> output = model(**inputs)
```
Nzð`input_ids_masked` isn't passed which means MLM loss won't be calculated correctlySetting it to `input_ids` so that model can work. Please pass it if this is unintentional. This is usually OKAY if you are doing inference on unmasked text...T)
rû   r³   r!  r÷   rõ   r+  r,  r"  rŠ  r‹  )	rû   r³   r!  r÷   r+  r´   r"  rŠ  r‹  zÊ`return_loss` is set to True but the image codebook is not initialized and no `mim_labels`  have been passed. Reinstantiate the model with `init_codebook` set to True or pass in your custom `mim_labels`z�`codebook_pixel_value` are required to generate `mim_labels` if loss is expected. Call `AutoProcessor` with `return_codebook_pixels` set to Truerž   rœ   )rT   rU   rV   rW   rX   rY   c              3   ó0   "  € T F  qe   TM^ x € K  	  R # 5ir`   r?   )r0   rh   s   & r$   r3   Ú.FlavaForPreTraining.forward.<locals>.<genexpr>G  s   é € Ð_ÑI^ÀÒ%5™T¸1Ô<ÓI^ùs   ‚c              3   ó0   "  € T F  qf   K  Vx € K  	  R # 5ir`   r?   )r0   rÛ   s   & r$   r3   rö  h  s   é € Ð<¡F˜qŸš£Fùr�  rh   ri   r:   r+   r;   r*   r<   r,   rj   rd   rk   rc   rl   re   rm   rn   ro   rp   rq   rr   rs   r    )rž   rÖ   rž   r?   )8rw   r‹  ró  rç  ÚloggerÚwarningr©  r:   r;   r<   rÓ  ÚRuntimeErrorrØ   r—  rá  rë  rã  Úner™   rØ  r   r¦   Úcross_entropyr¨   rÞ  rà  rÙ  rß  rä  rÚ  Úanyrå  rÛ  ræ  rÜ  râ  r  Ú	normalizer  Útrainingr·  ÚdataÚclamp_ÚLOGIT_SCALE_CLAMP_MINÚLOGIT_SCALE_CLAMP_MAXrÝ  rJ   rP   ÚsumrO   r+   r/   r*   r,   r!   r[   )7r2   rû   rî  r³   rï  r!  r÷   r´   rõ   r+  rç  rð  rñ  rò  r"  rŠ  r‹  ró  râ  Úflava_outputÚflava_masked_outputÚpos_maskr:   r;   rj   rk   rl   Ú
total_lossÚmim_lossÚmlm_lossÚmmm_text_lossÚmmm_image_lossÚgc_lossÚitm_lossrm   rn   rs   rr   ro   rÍ  rÎ  Úsequence_for_imageÚmasked_tokensÚmim_labels_filteredÚsequence_for_textÚmlm_labels_filteredÚ	pos_pairsÚ	end_indexÚtext_embeddingÚimage_embeddingÚ	gc_labelsÚgc_loss_imageÚgc_loss_textÚflava_lossesrK  s7   &&&&&&&&&&&&&&&&&&,                                    r$   rÀ   ÚFlavaForPreTraining.forward  sˆ
  € ðD &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆØ%0Ò%<‘kÀ$Ç+Á+×BYÑBYˆð 0Ò;ñ -à×6Ñ6ð 	)ð Ò#¨	Ò(=Ü�N‰Nð?ôð
  )Ðà—z‘zØØ%Ø)Ø)Ø%Ø!5ð %EØ/Ø!5àð "ó 
ˆð  #Ÿj™jØ&Ø%Ø)Ø)Ø!5Ø+Ø/Ø!5Øð )ó 

Ðð ˆà'×8Ñ8ÐØ&×6Ñ6ˆØ"5×"FÑ"FÐØ!4×!DÑ!DÐØ':×'PÑ'PÐ$àaeÐeˆ
Ðe�XÐe Ðe¨=Ðe¸>ÐeÈGÐV^ØGKÐKˆ
ÐK�ZÐK /Ð4DØ:>Ð>ˆ
Ð>Ð%¨ð #Ò.Ð2NÒ2ZØÒ!§kØ×&Ñ&Ò.Ü&ð;óð ð
 )Ò0Ü$ðYóð ð "×0Ñ0×EÑEÐF[Ó\�
ð �?‰?˜QÕÐ#:Ó#FÐKgÓKoØ!8ÐàÓ%Ø!×/Ñ/°
Ó;�
Ø"&×"4Ñ"4°_Ó"E�Ø7;×7KÑ7K�
×-Ñ-¨dÓ3Ñ4à%7¸¸J¿O¹OÈAÓ<NÐ;NÑ;PÐRSÐ8SÕ%TÐ"Ø *§¡¨d×.BÑ.BÓ C�Ø&0°Õ&?Ð#Ø%7¸ÀqÐ8HÕ%IÐ"Ø!Ÿ]™]Ð+=Ó>�
ßÜ!Ÿ}™}×:Ñ:Ø"Ÿ™¨¨D×,AÑ,AÓBÐDW×D\ÑD\Ð]_ÓD`ó �Hð  §¡Õ/�Høà!Ÿ]™]Ð+=Ó>�
ð �?‰?˜QÔÐ#9Ò#EÐJfÒJnØ 6ÐØÒ%Ø!×/Ñ/°
Ó;�
Ø$5°a¸*¿/¹/È!Ó:LÐ9LÑ9NÐPQÐ6QÕ$RÐ!Ø *§¡¨d×.BÑ.BÓ C�Ø&0°Õ&?Ð#Ø$5°mÀQÐ6FÕ$GÐ!Ø!Ÿ]™]Ð+<Ó=�
ßÜ!Ÿ}™}×:Ñ:Ø"Ÿ™¨¨D×,@Ñ,@ÓAÐCV×C[ÑC[Ð\^ÓC_ó �Hð  §¡Õ/�Høà!Ÿ]™]Ð+<Ó=�
ð �?‰?˜QÔÐ#?Ò#KØŸ™Ð'CÓDˆJàÒ%Ø&ŸM™M¨!Ó,�	à$¨	¯©«Ð'7Õ7�ßÜ!Ÿ}™}×:Ñ:¸:ÀzÓR�HØ §¡Õ/�Hà/Ò;Ø3OÐPXÕ3YÐ0àÒ)Ø!+¨HÕ!5�JàÒ)Ø!+¨HÕ!5�JØ&5°hÕ&?�Oð (Ó3¸×8MÑ8MÐPQÕ8QØ!=ÐØ/×4Ñ4°QÓ7¸!Õ;ˆIØ!3°A°q¸1¸y½=Ð7HÈ!Ð4KÕ!LÐàÒ%Ø!×/Ñ/°
Ó;�
Ø"&×"4Ñ"4°_Ó"E�Ø7;×7KÑ7K�
×-Ñ-¨dÓ3Ñ4à *§¡¨d×.BÑ.BÓ C�Ø&0°Õ&?Ð#Ø%7¸ÀqÐ8HÕ%IÐ"Ø#'×#6Ñ#6Ð7IÓ#JÐ ßÜ%'§]¡]×%@Ñ%@Ø(×-Ñ-¨b°$×2GÑ2GÓHÐJ]×JbÑJbÐceÓJfó&�Nð # d×&;Ñ&;Õ;�Nøà#'×#6Ñ#6Ð7IÓ#JÐ ð (Ò3¸×8LÑ8LÈqÔ8PØ <ÐØ 1°!Ð6L×6QÑ6QÐRSÓ6TÐ5TÑ5VÐXYÐ2YÕ ZÐàÒ%Ø!×/Ñ/°
Ó;�
Ø *§¡¨d×.BÑ.BÓ C�Ø&0°Õ&?Ð#Ø$5°mÀQÐ6FÕ$GÐ!Ø"&×"4Ñ"4Ð5FÓ"G�ßÜ$&§M¡M×$?Ñ$?Ø'×,Ñ,¨R°×1EÑ1EÓFÐH[×H`ÑH`ÐacÓHdó%�Mð " T×%9Ñ%9Õ9�Møà"&×"4Ñ"4Ð5FÓ"G�ð Ó'¨OÓ,GÈD×LjÑLjÐmnÕLnØ!ŸZ™Z×7Ñ7¸ÈÕ8PÓQˆNÜŸ]™]×4Ñ4°^ÈÐ4ÓLˆNà"Ÿj™j×9Ñ9Ð:JÈ7Õ:SÓTˆOÜ Ÿm™m×5Ñ5°oÈ2Ð5ÓNˆOà�}�}ˆ}Ø—
‘
×&Ñ&×+Ñ+×2Ñ2Ô3HÔJ_Ô`à;?×;WÑ;WØ °·±×1GÑ1Gó<Ñ8Ð˜o¨yð
 Ò#Ø#3°HÕ#=Ð Ø"1°(Õ";�Ø% hÕ/�	çÜ "§¡× ;Ñ ;Ð<LÈiÓ X�Ü!Ÿ}™}×:Ñ:¸?ÈIÓV�Ø(¨<Õ7¸1Õ<�Ø˜4×9Ñ9Õ9�ä"ØØØØ&Ø$Ø"ô
ˆ÷ ˜|×4Ñ4×6Ò6ÜÑ_È×I\ÑI\ÔI^Ó_Ó_ˆJçˆ{à Ø8D×8QÑ8QÒ8]�×)Ñ)×2Ñ2Ô4ÐcgØØ7C×7OÑ7OÒ7[�×(Ñ(×1Ñ1Ô3ÐaeØ×2Ñ2Ø=I×=[Ñ=[Ò=g�×.Ñ.×7Ñ7Ô9ÐmqØ'Ø?R×?_Ñ?_Ò?kÐ#×0Ñ0×9Ñ9Ô;ÐquØ&Ø>Q×>]Ñ>]Ò>iÐ#×/Ñ/×8Ñ8Ô:ÐosØ,à&×8Ñ8ÒDð $×5Ñ5×>Ñ>Ô@àØØØØ ØØ Øð+ˆF÷.  <×#8Ñ#8×#:Ò#:àØ ðð õ�÷ ”5Ñ<¡FÓ<—5Ð<�5Ñ<¡FÓ<Ó<Ð<ä(ò 
Ùð
á"ð
ñ .ð
ð &×2Ò2ð	
ñ
 ,ð
ð %×0Ò0ð
ð #/×"DÒ"Dð
ð +×<Ò<ð
ñ %<ð
ð !4× @Ò @ð
ñ $:ð
ð  3×>Ò>ð
ñ *Fð
ð &9×%JÒ%Jð
ñ "ð
ñ  "ð!
ñ" "ð#
ñ$ *:ð%
ñ& )8ð'
ñ( .ð)
ñ* ,ð+
ð 	
r'   )rã  r©  rÝ  râ  rÓ  rÞ  rÚ  rä  rØ  rá  rÙ  rà  rÛ  rå  rÜ  ræ  rç  rß  r`   )NNNNNNNNNNNNNNTNN)r@   rA   rB   rC   Ú_tied_weights_keysr‚   rë  r   rÀ   rF   rG   rÄ   rÅ   s   @@r$   rÑ  rÑ  Ù  s^   ù‡ € ð 	Ð:ØÐ0ØÐ0ØÐ<ð	Ð÷!õ !÷Fð ð
 ÷p
ñ p
ó ÷p
ð p
r'   rÑ  )rÑ  ry  rÃ  rµ  r³  r¨  rî  )LrD   rÎ   r'  r   Údataclassesr   Útypingr   r=   r   Ú r   r°  Úactivationsr   Úmasking_utilsr   Úmodeling_layersr	   Úmodeling_outputsr
   r   Úmodeling_utilsr   Úprocessing_utilsr   Úutilsr   r   r   r   r   r   Úconfiguration_flavar   r   r   r   r   Ú
get_loggerr@   rø  r“  r  r  r  r   rJ   r[   rÒ  ru   rˆ   râ   r	  r7  rF  rU  rd  rm  r}  rš  r¨  rÃ  rî  r³  rµ  r;  rY  rh  ry  r¤  r¯  r³  rº  rÑ  Ú__all__r?   r'   r$   Ú<module>r+     s0  ðñ ã Û Ý #Ý !Ý ã Ý å &Ý !Ý 6Ý 9ß KÝ -Ý &ß j× j÷õ ð 
×	Ò	˜HÓ	%€à>Ð àÐ ØÐ à&Ð)9Õ9Ð<QÕQÐ ñ ðôð ô
�{ó 
ó óð
ñ< ðôð
 ô�+ó ó óðñD ðôð ôWt ó Wtó óðWtôx_˜2Ÿ9™9ô _ôH!�b—i‘iô !ôH/˜"Ÿ)™)ô /ôd6˜Ÿ™ô 6ôr�b—i‘iô ô$�R—Y‘Yô ô,˜Ÿ	™	ô ô"�"—)‘)ô ô )Ð+ô )ôX$
�2—9‘9ô $
ôN�"—)‘)ô ð ôS˜?ó Só ðSð6 ôN
Ð*ó N
ó ðN
ðb ô\
Ð)ó \
ó ð\
ð~ ôL
Ð/ó L
ó ðL
ð^ ô^
Ð%ó ^
ó ð^
ôB	 §	¡	ô ô*C˜bŸi™iô Cô" 2§9¡9ô ñ( ðôôw)Ð-ó w)óðw)ôt 2§9¡9ô ô" §	¡	ô ô 
�2—9‘9ô 
ô%9 §¡ô %9ñP ðôô
b
Ð.ó b
óð
b
òJ‚r'   