+
    œ°³jò4  ã                   ó<  € R t ^ RI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 ^R	IHtHtHtHtHt ^R
IHt ]P0                  ! ]4      t] ! R R]4      4       t]! RR7       ! R R]4      4       t]! RR7       ! R R]]4      4       t. ROtR# )zPyTorch Fuyu model.N)Únn)ÚCache)ÚGenerationMixin)ÚBaseModelOutputWithPoolingÚCausalLMOutputWithPast)ÚPreTrainedModel)Ú	AutoModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚcan_return_tupleÚloggingÚtorch_compilable_check©Ú
FuyuConfigc                   óR   a € ] tR t^ t o RtRtRtRtRtRt	Rt
. tR.tV 3R ltRtV tR# )ÚFuyuPreTrainedModelÚmodelTÚpast_key_valuesc                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # ©é   Úconfigr   )ÚformatÚ__classdict__s   "€Úg/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/fuyu/modeling_fuyu.pyÚ__annotate__Ú FuyuPreTrainedModel.__annotate__    s   ø‡ ‚ áÑò ó    © N)ÚimageÚtext)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Úbase_model_prefixÚinput_modalitiesÚsupports_gradient_checkpointingÚ_supports_attention_backendÚ_supports_flash_attnÚ_supports_sdpaÚ_supports_flex_attnÚ_no_split_modulesÚ_skip_keys_device_placementÚ__annotate_func__Ú__static_attributes__Ú__classdictcell__)r   s   @r   r   r       sF   ø‡ € ð  ÐØ(ÐØ&*Ð#Ø"&ÐØÐØ€NØÐØÐØ#4Ð"5Ð÷ ƒ r   r   zt
    The Fuyu model which consists of a vision backbone and a language model, without a language modeling head.
    )Úcustom_introc                   ó²   a a€ ] tR t^.t oV3R lV 3R lltV3R lR lt]]V3R lR l4       4       tV3R lR lt	]]RV3R	 lR
 ll4       4       t
RtVtV ;t# )Ú	FuyuModelc                ó    <€ V ^8„  d   QhRS[ /# r   r   )r   r   s   "€r   r   ÚFuyuModel.__annotate__4   s   ø€ ÷ ñ ™zñ r   c                óš  <€ \         SV `  V4       VP                  V n        VP                  P
                  V n        \        P                  ! VP                  4      V n        \        P                  ! VP                  VP                  ,          VP                  ,          VP                  4      V n        R V n        V P!                  4        R# )FN)ÚsuperÚ__init__Úpad_token_idÚpadding_idxÚtext_configÚ
vocab_sizer   Úfrom_configÚlanguage_modelr   ÚLinearÚ
patch_sizeÚnum_channelsÚhidden_sizeÚvision_embed_tokensÚgradient_checkpointingÚ	post_init©Úselfr   Ú	__class__s   &&€r   r9   ÚFuyuModel.__init__4   s–   ø€ Ü‰Ñ˜Ô Ø!×.Ñ.ˆÔØ ×,Ñ,×7Ñ7ˆŒÜ'×3Ò3°F×4FÑ4FÓGˆÔÜ#%§9¢9Ø×Ñ × 1Ñ 1Õ1°F×4GÑ4GÕGÈ×I[ÑI[ó$
ˆÔ ð ',ˆÔ#à�‰Ör   c                ó’   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          RS[ P                  RS[ P                  /# )r   Úword_embeddingsÚcontinuous_embeddingsÚimage_patch_input_indicesÚreturn)ÚtorchÚTensorÚlist)r   r   s   "€r   r   r6   A   sH   ø€ ÷ *!ñ *!áŸ™ð*!ñ  $¡E§L¡LÕ1ð*!ñ $)§<¡<ð	*!ñ
 
�‰ñ*!r   c           
     óŽ  € VP                   ^ ,          \        V4      8X  g.   \        R\        V4      : RVP                   ^ ,          : 24      hVP                  4       p\	        VP                   ^ ,          4       FÆ  p\
        P                  ! W5,          ^ 8¬  RR7      ^ ,          pW5,          V,          pVP                   ^ ,          W%,          P                   ^ ,          8”  d2   \        RW%,          P                   : RVP                   : RV R24      hW%,          V,          P                  VP                  4      WEV3&   KÈ  	  V# )	ay  This function places the continuous_embeddings into the word_embeddings at the locations
indicated by image_patch_input_indices. Different batch elements can have different numbers of continuous
embeddings.

Args:
    word_embeddings (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
        Tensor of word embeddings.
    continuous_embeddings (`torch.FloatTensor` of shape `(batch_size, num_patches, hidden_size)`):
        Tensor of continuous embeddings. The length of the list is the batch size. Each entry is shape
        [num_image_embeddings, hidden], and num_image_embeddings needs to match the number of non-negative
        indices in image_patch_input_indices for that batch element.
    image_patch_input_indices (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
        Tensor of indices of the image patches in the input_ids tensor.
z7Batch sizes must match! Got len(continuous_embeddings)=z and word_embeddings.shape[0]=T)Úas_tuplezGNumber of continuous embeddings continuous_embeddings[batch_idx].shape=zA does not match number of continuous token ids src_indices.shape=z in batch element Ú.)	ÚshapeÚlenÚ
ValueErrorÚcloneÚrangerP   ÚnonzeroÚtoÚdevice)rH   rL   rM   rN   Úoutput_embeddingsÚ	batch_idxÚdst_indicesÚsrc_indicess   &&&&    r   Úgather_continuous_embeddingsÚ&FuyuModel.gather_continuous_embeddingsA   sI  € ð(  ×%Ñ% aÕ(¬CÐ0EÓ,FÔFÜØJ¬sÐ3HÓ/IÑ.KÐKjÐQ`×QfÑQfÐghÕQiÑPkÐlóð ð ,×1Ñ1Ó3ÐÜ˜×4Ñ4°QÕ7Ö8ˆIô  Ÿ-š-Ð(AÕ(LÐPQÑ(QÐ\`ÔaÐbcÕdˆKð 4Õ>¸{ÕKˆKà× Ñ  Õ#Ð&;Õ&F×&LÑ&LÈQÕ&OÔOÜ Ø^Ð7LÕ7W×7]Ñ7]Ñ6_ð `IØ6A×6GÑ6GÑ5IÐI[Ð\eÐ[fÐfgðióð ð 9NÕ8XÐYdÕ8e×8hÑ8hØ!×(Ñ(ó9Ð¨Ð4Ó5ñ 9ð  !Ð r   c                ó`   <€ V ^8„  d   QhRS[ P                  RS[S[,          RS[S[,          /# )r   Úpixel_valuesÚkwargsrO   )rP   ÚFloatTensorr	   r
   Útupler   )r   r   s   "€r   r   r6   o   s<   ø€ ÷ Nñ NÙ!×-Ñ-ðNÙ9?Ñ@RÕ9SðNá	Ñ+Õ	+ñNr   c                ó<   € V P                  V4      p\        VR7      # )z–
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
    The tensors corresponding to the input images.
)Úlast_hidden_state)rD   r   )rH   re   rf   Úpatch_embeddingss   &&, r   Úget_image_featuresÚFuyuModel.get_image_featuresm   s!   € ð  ×3Ñ3°LÓAÐÜ)Ð<LÔMÐMr   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# )r   Ú	input_idsÚinputs_embedsÚimage_features)rP   Ú
LongTensorrg   )r   r   s   "€r   r   r6   y   s7   ø€ ÷ "ñ "Ù×)Ñ)ð"Ù:?×:KÑ:Kð"Ù]b×]nÑ]nñ"r   c           
     óX  € Vfo   W P                  4       ! \        P                  ! RV P                  P                  \        P
                  VP                  R7      4      8H  pVP                  R4      pMWP                  P                  8H  pVP                  4       pVP                  ^ ,          VP                  ^,          ,          pVP                  R4      P                  VP                  4      p\        WRP                  R,          ,          VP                  4       8H  RV RV 24       V# )z×
Obtains multimodal placeholder mask from `input_ids` or `inputs_embeds`, and checks that the placeholder token count is
equal to the length of multimodal features. If the lengths are different, an error is raised.
©Údtyper]   z6Image features and image tokens do not match, tokens: z, features: r   éÿÿÿÿ)Úget_input_embeddingsrP   Úfullr   Úimage_token_idÚlongr]   ÚallÚsumrV   Ú	unsqueezer\   r   Únumel)rH   ro   rp   rq   Úspecial_image_maskÚn_image_tokensÚn_image_featuress   &&&&   r   Úget_placeholder_maskÚFuyuModel.get_placeholder_masky   s  € ð ÒØ!.×2KÑ2KÔ2MÜ—
’
˜2˜tŸ{™{×9Ñ9ÄÇÁÐTa×ThÑThÔió3ñ "Ðð "4×!7Ñ!7¸Ó!;Ñà!*¯k©k×.HÑ.HÑ!HÐà+×/Ñ/Ó1ˆØ)×/Ñ/°Õ2°^×5IÑ5IÈ!Õ5LÕLÐØ/×9Ñ9¸"Ó=×@Ñ@À×AUÑAUÓVÐÜØ×0Ñ0°Õ4Õ4¸×8LÑ8LÓ8NÑNØDÀ^ÐDTÐT`ÐaqÐ`rÐsô	
ð "Ð!r   c                ó6  <€ 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[ P                  R,          RS[R,          R	S[S[,          R
S[S[	,          /	# )r   ro   NÚimage_patchesÚattention_maskÚposition_idsr   rp   Ú	use_cacherf   rO   )
rP   rr   rQ   r   rg   Úboolr	   r
   rh   r   )r   r   s   "€r   r   r6   “   s¬   ø€ ÷ 2ñ 2á×#Ñ# dÕ*ð2ñ —|‘| dÕ*ð	2ñ
 Ÿ™ tÕ+ð2ñ ×&Ñ&¨Õ-ð2ñ  �ð2ñ ×(Ñ(¨4Õ/ð2ñ ˜$•;ð2ñ Ñ+Õ,ð2ñ 
Ñ'Õ	'ñ2r   c                ó¨  € VRJ VRJ,          '       d   \        R4      hVf!   V P                  P                  4       ! V4      pVP                  ^,          p	Vfr   Ve   VP                  MVP                  p
Ve   VP                  4       M^ p\        P                  ! W¹V,           \        P                  V
R7      pVP                  ^ 4      pVeh   V P                  VRR7      P                  pVP                  VP                  VP                  4      pV P                  WVR7      pVP                  WÜ4      pV P                  ! RRVRVR	VR
VRV/VB pV# )a  
image_patches (`torch.FloatTensor` of shape `(batch_size, num_total_patches, patch_size_ x patch_size x num_channels)`, *optional*):
    Image patches to be used as continuous embeddings. The patches are flattened and then projected to the
    hidden size of the model.
Nz:You must specify exactly one of input_ids or inputs_embedsrt   T)Úreturn_dict)rp   rq   rp   r†   r‡   r   rˆ   r   )rX   r?   rw   rV   r]   Úget_seq_lengthrP   Úarangerz   r}   rl   rj   r\   ru   r‚   Úmasked_scatter)rH   ro   r…   r†   r‡   r   rp   rˆ   rf   Úseq_lenr]   Úpast_key_values_lengthrk   r   Úoutputss   &&&&&&&&,      r   ÚforwardÚFuyuModel.forward‘   s~  € ð& ˜Ð -°tÐ";×<Ô<ÜÐYÓZÐZàÒ Ø ×/Ñ/×DÑDÔFÀyÓQˆMà×%Ñ% aÕ(ˆàÒØ)2Ò)>�Y×%Ò%ÀM×DXÑDXˆFØIXÒId _×%CÑ%CÔ%EÐjkÐ"Ü Ÿ<š<Ø&Ð2HÕ(HÔPU×PZÑPZÐciôˆLð (×1Ñ1°!Ó4ˆLàÒ$Ø#×6Ñ6°}ÐRVÐ6ÓW×iÑiÐØ/×2Ñ2°=×3GÑ3GÈ×I\ÑI\Ó]ÐØ!%×!:Ñ!:ØÐGWð ";ó "Ðð *×8Ñ8Ð9KÓ^ˆMà×%Ò%ñ 
Ø'ð
à)ð
ð &ð
ð ,ð	
ð
  ð
ð ñ
ˆð ˆr   )rE   r?   r;   rD   r=   )NNNNNNN)r"   r#   r$   r%   r9   rb   r   r   rl   r‚   r’   r0   r1   Ú__classcell__©rI   r   s   @@r   r4   r4   .   sh   ù‡ € ÷ó ÷*!ð *!ðX Ø÷Nó ó ðN÷"ð "ð0 Ø÷2ñ 2ó ó ÷2ð 2r   r4   zz
    Fuyu Model with a language modeling head on top for causal language model conditioned on image patches and text.
    c                   óp   a a€ ] tR t^Èt oRR/tV3R lV 3R llt]]RV3R lR ll4       4       tRt	Vt
V ;t# )	ÚFuyuForCausalLMzlm_head.weightz(model.language_model.embed_tokens.weightc                ó    <€ V ^8„  d   QhRS[ /# r   r   )r   r   s   "€r   r   ÚFuyuForCausalLM.__annotate__Ð   s   ø€ ÷ ñ ™zñ r   c                óò   <€ \         SV `  V4       \        V4      V n        \        P
                  ! VP                  P                  VP                  P                  R R7      V n	        V P                  4        R# )F)ÚbiasN)r8   r9   r4   r   r   r@   r<   rC   r=   Úlm_headrF   rG   s   &&€r   r9   ÚFuyuForCausalLM.__init__Ð   sS   ø€ Ü‰Ñ˜Ô Ü˜vÓ&ˆŒ
Ü—y’y ×!3Ñ!3×!?Ñ!?À×ASÑAS×A^ÑA^ÐejÔkˆŒØ�‰Ör   c                ór  <€ 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[ P                  R,          RS[R,          R	S[ P                  R,          R
S[R,          RS[S[,          RS[	S[
,          /# )r   ro   Nr…   r†   r‡   r   rp   rˆ   ÚlabelsÚlogits_to_keeprf   rO   )rP   rr   rQ   r   rg   r‰   Úintr	   r
   rh   r   )r   r   s   "€r   r   r™   Ø   sÚ   ø€ ÷ L
ñ L
á×#Ñ# dÕ*ðL
ñ —|‘| dÕ*ð	L
ñ
 Ÿ™ tÕ+ðL
ñ ×&Ñ&¨Õ-ðL
ñ  �ðL
ñ ×(Ñ(¨4Õ/ðL
ñ ˜$•;ðL
ñ —‘˜tÕ#ðL
ñ ˜d�
ðL
ñ Ñ+Õ,ðL
ñ 
Ñ'Õ	'ñL
r   c
                ó¨  € V P                   ! RRVRVRVRVRVRVRV/V
B pV^ ,          p\        V	\        4      '       d   \        V	) R4      MT	pV P	                  VR	VR	3,          4      pRpVe7   V P
                  ! RR
VRVRV P                  P                  P                  /V
B p\        VVVP                  VP                  VP                  R7      # )a  
image_patches (`torch.FloatTensor` of shape `(batch_size, num_total_patches, patch_size_ x patch_size x num_channels)`, *optional*):
    Image patches to be used as continuous embeddings. The patches are flattened and then projected to the
    hidden size of the model.
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
    config.text_config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
    (masked), the loss is only computed for the tokens with labels in `[0, ..., config.text_config.vocab_size]`.

Examples:

```python
>>> from transformers import FuyuProcessor, FuyuForCausalLM
>>> from PIL import Image
>>> import httpx
>>> from io import BytesIO

>>> processor = FuyuProcessor.from_pretrained("adept/fuyu-8b")
>>> model = FuyuForCausalLM.from_pretrained("adept/fuyu-8b")

>>> url = "https://huggingface.co/datasets/hf-internal-testing/fixtures-captioning/resolve/main/bus.png"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))
>>> prompt = "Generate a coco-style caption.\n"

>>> inputs = processor(images=image, text=prompt, return_tensors="pt")
>>> outputs = model(**inputs)

>>> generated_ids = model.generate(**inputs, max_new_tokens=7)
>>> generation_text = processor.batch_decode(generated_ids[:, -7:], skip_special_tokens=True)
>>> print(generation_text[0])
A blue bus parked on the side of a road.
```ro   r…   rp   r†   r‡   r   rˆ   N:NNNÚlogitsrŸ   r=   )Úlossr£   r   Úhidden_statesÚ
attentionsr   )r   Ú
isinstancer¡   Úslicerœ   Úloss_functionr   r<   r=   r   r   r¥   r¦   )rH   ro   r…   r†   r‡   r   rp   rˆ   rŸ   r    rf   r‘   r¥   Úslice_indicesr£   r¤   s   &&&&&&&&&&,     r   r’   ÚFuyuForCausalLM.forwardÖ   s  € ðd —*’*ñ 	
Øð	
à'ð	
ð (ð	
ð *ð		
ð
 &ð	
ð ,ð	
ð  ð	
ð ñ	
ˆð   �
ˆä8BÀ>ÔSV×8WÒ8Wœ˜~˜o¨tÔ4Ð]kˆØ—‘˜m¨A¨}¸aÐ,?Õ@ÓAˆàˆØÒØ×%Ò%ñ ØðØ&,ðØ9=¿¹×9PÑ9P×9[Ñ9[ðØ_eñˆDô &ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r   )rœ   r   )	NNNNNNNNé    )r"   r#   r$   r%   Ú_tied_weights_keysr9   r   r   r’   r0   r1   r”   r•   s   @@r   r—   r—   È   sG   ù‡ € ð +Ð,VÐWÐ÷ó ð Ø÷L
ñ L
ó ó ÷L
ð L
r   r—   )r—   r   r4   )Ú__doc__rP   r   Úcache_utilsr   Ú
generationr   Úmodeling_outputsr   r   Úmodeling_utilsr   Úmodels.auto.modeling_autor   Úprocessing_utilsr	   Úutilsr
   r   r   r   r   Úconfiguration_fuyur   Ú
get_loggerr"   Úloggerr   r4   r—   Ú__all__r   r   r   Ú<module>rº      s¶   ðñ ã Ý å  Ý )ß RÝ -Ý 2Ý &ß jÕ jÝ *ð 
×	Ò	˜HÓ	%€ð ô
6˜/ó 
6ó ð
6ñ ðôô
RÐ#ó Róð
Rñj ðôô
W
Ð)¨?ó W
óð
W
òt B‚r   