Ë
    T^(hT/ ã                   óÈ  — d dl Z d dlmZ d dlmZmZmZmZ d dlZd dlm	Z	 d dl
mZ ddlmZ ddlmZ dd	lmZmZmZmZ dd
lmZ ddlmZmZmZ ddlmZmZmZmZm Z m!Z! ddl"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z(  ejR                  e*«      Z+e G d„ de«      «       Z, G d„ de	jZ                  «      Z. G d„ de	jZ                  «      Z/ G d„ de	jZ                  «      Z0 G d„ de	jZ                  «      Z1 G d„ de«      Z2 G d„ de	jZ                  «      Z3dZ4 G d „ d!e2«      Z5 G d"„ d#e	jZ                  «      Z6 G d$„ d%e	jZ                  «      Z7 G d&„ d'e	jZ                  «      Z8 G d(„ d)e	jZ                  «      Z9 G d*„ d+e	jZ                  «      Z: G d,„ d-e	jZ                  «      Z; G d.„ d/e	jZ                  «      Z< G d0„ d1e	jZ                  «      Z= G d2„ d3e2«      Z>d4Z?d5Z@ ed6e?«       G d7„ d8e2e«      «       ZAy)9é    N)Ú	dataclass)ÚAnyÚOptionalÚTupleÚUnion)Únn)ÚCrossEntropyLossé   )ÚACT2FN)ÚGenerationMixin)ÚBaseModelOutputÚ)BaseModelOutputWithPastAndCrossAttentionsÚBaseModelOutputWithPoolingÚ,BaseModelOutputWithPoolingAndCrossAttentions)ÚPreTrainedModel)Úapply_chunking_to_forwardÚ find_pruneable_heads_and_indicesÚprune_linear_layer)ÚModelOutputÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsÚ	torch_inté   )ÚAutoModelForCausalLMÚAutoModelForSeq2SeqLMé   )ÚInstructBlipVideoConfigÚInstructBlipVideoQFormerConfigÚInstructBlipVideoVisionConfigc                   ó  — e Zd ZU dZdZeeej                        e	d<   dZ
eeej                        e	d<   dZeej                     e	d<   dZeeej                        e	d<   dZeeej                        e	d<   dee   fd	„Zy)
Ú4InstructBlipVideoForConditionalGenerationModelOutputa.  
    Class defining the outputs of [`InstructBlipVideoForConditionalGeneration`].

    Args:
        loss (`torch.FloatTensor`, *optional*, returned when `labels` is provided, `torch.FloatTensor` of shape `(1,)`):
            Language modeling loss from the language model.
        logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
            Prediction scores of the language modeling head of the language model.
        vision_outputs (`BaseModelOutputWithPooling`):
            Outputs of the vision encoder.
        qformer_outputs (`BaseModelOutputWithPoolingAndCrossAttentions`):
            Outputs of the Q-Former (Querying Transformer).
        language_model_outputs (`CausalLMOutputWithPast` or `Seq2SeqLMOutput`):
            Outputs of the language model.
    NÚlossÚlogitsÚvision_outputsÚqformer_outputsÚlanguage_model_outputsÚreturnc                 óH   ‡ — t        ˆ fd„‰ j                  «       D «       «      S )Nc              3   ód   •K  — | ]'  }|d vr‰|   nt        ‰|«      j                  «       –— Œ) y­w))r&   r'   r(   N)ÚgetattrÚto_tuple)Ú.0ÚkÚselfs     €ú~/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/instructblipvideo/modeling_instructblipvideo.pyú	<genexpr>zPInstructBlipVideoForConditionalGenerationModelOutput.to_tuple.<locals>.<genexpr>T   sB   øè ø€ ò 
ð ð ÐWÑWð �ŠGä˜˜qÓ!×*Ñ*Ó,ó-ñ
ùs   ƒ-0)ÚtupleÚkeys©r0   s   `r1   r-   z=InstructBlipVideoForConditionalGenerationModelOutput.to_tupleS   s%   ø€ Üó 
ð —Y‘Y“[ô	
ó 
ð 	
ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r   r   ÚtorchÚFloatTensorÚ__annotations__r%   r&   r'   r(   r   r-   © r6   r1   r#   r#   ;   s—   … ñð  04€Dˆ(�5˜×*Ñ*Ñ+Ñ
,Ó3Ø15€FˆH�U˜5×,Ñ,Ñ-Ñ.Ó5Ø26€N�H˜U×.Ñ.Ñ/Ó6Ø:>€O�X˜e E×$5Ñ$5Ñ6Ñ7Ó>ØAEÐ˜H U¨5×+<Ñ+<Ñ%=Ñ>ÓEð
˜% ™*ô 
r6   r#   c                   ó¢   ‡ — e Zd Zdefˆ fd„Zdej                  dededej                  fd„Zddej                  d	e
dej                  fd
„Zˆ xZS )Ú!InstructBlipVideoVisionEmbeddingsÚconfigc                 óp  •— t         ‰| �  «        || _        |j                  | _        |j
                  | _        |j                  | _        t        j                  t        j                  dd| j                  «      «      | _        t        j                  d| j                  | j                  | j                  ¬«      | _        | j
                  | j                  z  dz  | _        | j                  dz   | _        t        j                  t        j                  d| j                  | j                  «      «      | _        y )Nr   r
   )Úin_channelsÚout_channelsÚkernel_sizeÚstrider   )ÚsuperÚ__init__rA   Úhidden_sizeÚ	embed_dimÚ
image_sizeÚ
patch_sizer   Ú	Parameterr;   ÚrandnÚclass_embeddingÚConv2dÚpatch_embeddingÚnum_patchesÚnum_positionsÚposition_embedding©r0   rA   Ú	__class__s     €r1   rH   z*InstructBlipVideoVisionEmbeddings.__init__]   sá   ø€ Ü‰ÑÔØˆŒØ×+Ñ+ˆŒØ ×+Ñ+ˆŒØ ×+Ñ+ˆŒä!Ÿ|™|¬E¯K©K¸¸1¸d¿n¹nÓ,MÓNˆÔä!Ÿy™yØ¨¯©ÀDÇOÁOÐ\`×\kÑ\kô 
ˆÔð !ŸO™O¨t¯©Ñ>À1ÑDˆÔØ!×-Ñ-°Ñ1ˆÔä"$§,¡,¬u¯{©{¸1¸d×>PÑ>PÐRV×R`ÑR`Ó/aÓ"bˆÕr6   Ú
embeddingsÚheightÚwidthr)   c                 ó¦  — |j                   d   dz
  }| j                  j                   d   dz
  }t        j                  j	                  «       s||k(  r||k(  r| j                  S | j                  dd…dd…f   }| j                  dd…dd…f   }|j                   d   }|| j
                  z  }	|| j
                  z  }
t        |dz  «      }|j                  d|||«      }|j                  dddd«      }t        j                  j                  ||	|
fdd	¬
«      }|j                  dddd«      j                  dd|«      }t        j                  ||fd¬«      S )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
        r   Néÿÿÿÿg      à?r   r
   r   ÚbicubicF)ÚsizeÚmodeÚalign_corners©Údim)ÚshaperT   r;   ÚjitÚ
is_tracingrL   r   ÚreshapeÚpermuter   Ú
functionalÚinterpolateÚviewÚcat)r0   rW   rX   rY   rR   rS   Úclass_pos_embedÚpatch_pos_embedra   Ú
new_heightÚ	new_widthÚsqrt_num_positionss               r1   Úinterpolate_pos_encodingz:InstructBlipVideoVisionEmbeddings.interpolate_pos_encodingo   s`  € ð !×&Ñ& qÑ)¨AÑ-ˆØ×/Ñ/×5Ñ5°aÑ8¸1Ñ<ˆô �y‰y×#Ñ#Ô%¨+¸Ò*FÈ6ÐUZÊ?Ø×*Ñ*Ð*à×1Ñ1²!°R°a°R°%Ñ8ˆØ×1Ñ1²!°Q±R°%Ñ8ˆà×Ñ˜rÑ"ˆà˜tŸ™Ñ.ˆ
Ø˜TŸ_™_Ñ,ˆ	ä& }°cÑ'9Ó:ÐØ)×1Ñ1°!Ð5GÐI[Ð]`ÓaˆØ)×1Ñ1°!°Q¸¸1Ó=ˆäŸ-™-×3Ñ3ØØ˜iÐ(ØØð	 4ó 
ˆð *×1Ñ1°!°Q¸¸1Ó=×BÑBÀ1ÀbÈ#ÓNˆä�y‰y˜/¨?Ð;ÀÔCÐCr6   Úpixel_valuesrp   c                 ó  — |j                   \  }}}}| j                  j                  j                  }| j                  |j	                  |¬«      «      }|j                  d«      j                  dd«      }| j                  j                  |dd«      j	                  |«      }	t        j                  |	|gd¬«      }
|r| j                  |
||«      }n| j                  }|
|d d …d |
j                  d«      …d d …f   j	                  |«      z   }
|
S )N©Údtyper   r   r[   r`   )rb   rQ   Úweightrt   ÚtoÚflattenÚ	transposerO   Úexpandr;   rj   rp   rT   r]   )r0   rq   rp   Ú
batch_sizeÚ_rX   rY   Útarget_dtypeÚpatch_embedsÚclass_embedsrW   rT   s               r1   Úforwardz)InstructBlipVideoVisionEmbeddings.forward—   sü   € Ø'3×'9Ñ'9Ñ$ˆ
�A�v˜uØ×+Ñ+×2Ñ2×8Ñ8ˆØ×+Ñ+¨L¯O©OÀ,¨OÓ,OÓPˆØ#×+Ñ+¨AÓ.×8Ñ8¸¸AÓ>ˆØ×+Ñ+×2Ñ2°:¸qÀ"ÓE×HÑHÈÓVˆÜ—Y‘Y ¨lÐ;ÀÔCˆ
Ù#Ø!%×!>Ñ!>¸zÈ6ÐSXÓ!YÑà!%×!8Ñ!8ÐØÐ"4²QÐ8L¸*¿/¹/È!Ó:LÐ8LÊaÐ5OÑ"P×"SÑ"SÐT`Ó"aÑaˆ
ØÐr6   ©F)r7   r8   r9   r!   rH   r;   ÚTensorÚintrp   r<   Úboolr   Ú__classcell__©rV   s   @r1   r@   r@   \   sm   ø„ ðcÐ<õ cð$&D°5·<±<ð &DÈð &DÐUXð &DÐ]b×]iÑ]ió &DñP E×$5Ñ$5ð ÐQUð Ðbg×bnÑbn÷ r6   r@   c                   óö   ‡ — e Zd ZdZˆ fd„Zdej                  dedefd„Z	 	 ddej                  de	ej                     d	e	e
   d
eej                  e	ej                     e	eej                        f   fd„Zˆ xZS )ÚInstructBlipVideoAttentionz=Multi-headed attention from 'Attention Is All You Need' paperc                 ó  •— t         ‰| �  «        || _        |j                  | _        |j
                  | _        | j                  | j                  z  | _        | j                  | j                  z  | j                  k7  r&t        d| j                  › d| j                  › d�«      ‚| j                  dz  | _	        t        j                  |j                  «      | _        t        j                  | j                  d| j                  z  d¬«      | _        |j                   ret        j"                  t%        j&                  | j                  «      «      }t        j"                  t%        j&                  | j                  «      «      }nd }d }|�Qt%        j(                  |t%        j*                  |d¬«      |f«      }t        j"                  |«      | j                  _        t        j                  | j                  | j                  «      | _        y )	Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).g      à¿r
   F)Úbias)Úrequires_grad)rG   rH   rA   rI   rJ   Únum_attention_headsÚ	num_headsÚhead_dimÚ
ValueErrorÚscaler   ÚDropoutÚattention_dropoutÚdropoutÚLinearÚqkvÚqkv_biasrM   r;   Úzerosrj   Ú
zeros_liker‰   Ú
projection)r0   rA   Úq_biasÚv_biasr•   rV   s        €r1   rH   z#InstructBlipVideoAttention.__init__©   sv  ø€ Ü‰ÑÔØˆŒØ×+Ñ+ˆŒØ×3Ñ3ˆŒØŸ™¨$¯.©.Ñ8ˆŒØ�=‰=˜4Ÿ>™>Ñ)¨T¯^©^Ò;ÜØMÈdÏnÉnÐM]ð ^Ø—N‘NÐ# 2ð'óð ð —]‘] DÑ(ˆŒ
Ü—z‘z &×":Ñ":Ó;ˆŒô —9‘9˜TŸ^™^¨Q°·±Ñ-?ÀeÔLˆŒà�?Š?Ü—\‘\¤%§+¡+¨d¯n©nÓ"=Ó>ˆFÜ—\‘\¤%§+¡+¨d¯n©nÓ"=Ó>‰FàˆFØˆFàÐÜ—y‘y &¬%×*:Ñ*:¸6ÐQVÔ*WÐY_Ð!`ÓaˆHÜŸL™L¨Ó2ˆD�H‰HŒMäŸ)™) D§N¡N°D·N±NÓCˆ�r6   ÚtensorÚseq_lenÚbszc                 óŽ   — |j                  ||| j                  | j                  «      j                  dd«      j	                  «       S )Nr   r   )ri   rŒ   r�   rx   Ú
contiguous)r0   r›   rœ   r�   s       r1   Ú_shapez!InstructBlipVideoAttention._shapeÇ   s7   € Ø�{‰{˜3 ¨¯©¸¿¹ÓG×QÑQÐRSÐUVÓW×bÑbÓdÐdr6   Úhidden_statesÚ	head_maskÚoutput_attentionsr)   c                 ó¶  — |j                  «       \  }}}| j                  |«      }|j                  ||d| j                  || j                  z  «      j	                  ddddd«      }|d   |d   |d   }
}	}t        j                  ||	j                  dd«      «      }|| j                  z  }t        j                  j                  |d¬«      }| j                  |«      }|�||z  }t        j                  ||
«      j	                  dddd«      }|j                  «       d	d | j                  fz   }|j                  |«      }| j                  |«      }|r||f}|S |d	f}|S )
z#Input shape: Batch x Time x Channelr
   r   r   r   é   r[   éþÿÿÿr`   N)r]   r”   re   rŒ   rf   r;   Úmatmulrx   r�   r   rg   Úsoftmaxr’   rJ   r˜   )r0   r¡   r¢   r£   r�   Útgt_lenrJ   Ú	mixed_qkvÚquery_statesÚ
key_statesÚvalue_statesÚattention_scoresÚattention_probsÚcontext_layerÚnew_context_layer_shapeÚoutputÚoutputss                    r1   r   z"InstructBlipVideoAttention.forwardÊ   su  € ð #0×"4Ñ"4Ó"6ÑˆˆW�ià—H‘H˜]Ó+ˆ	à×%Ñ% c¨7°A°t·~±~ÀyÐTX×TbÑTbÑGbÓc×kÑkØˆq�!�Q˜ó
ˆ	ð 2;¸1±¸yÈ¹|ÈYÐWXÉ\ ,�jˆô !Ÿ<™<¨°j×6JÑ6JÈ2ÈrÓ6RÓSÐà+¨d¯j©jÑ8Ðô Ÿ-™-×/Ñ/Ð0@ÀbÐ/ÓIˆð Ÿ,™, Ó7ˆð Ð Ø-°	Ñ9ˆOäŸ™ _°lÓC×KÑKÈAÈqÐRSÐUVÓWˆà"/×"4Ñ"4Ó"6°s¸Ð";¸t¿~¹~Ð>OÑ"OÐØ%×-Ñ-Ð.EÓFˆà—‘ Ó/ˆá/@�6˜?Ð+ˆàˆð HNÈtÀnˆàˆr6   ©NF)r7   r8   r9   r:   rH   r;   r�   r‚   r    r   rƒ   r   r   r„   r…   s   @r1   r‡   r‡   ¦   s™   ø„ ÙGôDð<e˜UŸ\™\ð e°Cð e¸có eð -1Ø,1ñ	*à—|‘|ð*ð ˜EŸL™LÑ)ð*ð $ D™>ð	*ð
 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷*r6   r‡   c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )ÚInstructBlipVideoMLPc                 ó  •— t         ‰| �  «        || _        t        |j                     | _        t        j                  |j                  |j                  «      | _
        t        j                  |j                  |j                  «      | _        y ©N)rG   rH   rA   r   Ú
hidden_actÚactivation_fnr   r“   rI   Úintermediate_sizeÚfc1Úfc2rU   s     €r1   rH   zInstructBlipVideoMLP.__init__ø   sd   ø€ Ü‰ÑÔØˆŒÜ# F×$5Ñ$5Ñ6ˆÔÜ—9‘9˜V×/Ñ/°×1IÑ1IÓJˆŒÜ—9‘9˜V×5Ñ5°v×7IÑ7IÓJˆ�r6   r¡   r)   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S r¸   )r¼   rº   r½   ©r0   r¡   s     r1   r   zInstructBlipVideoMLP.forwardÿ   s4   € ØŸ™ Ó/ˆØ×*Ñ*¨=Ó9ˆØŸ™ Ó/ˆØÐr6   ©r7   r8   r9   rH   r;   r�   r   r„   r…   s   @r1   r¶   r¶   ÷   s$   ø„ ôKð U§\¡\ð °e·l±l÷ r6   r¶   c            
       óˆ   ‡ — e Zd Zdefˆ fd„Z	 ddej                  dej                  dee   de	ej                     fd„Zˆ xZS )	ÚInstructBlipVideoEncoderLayerrA   c                 óD  •— t         ‰| �  «        |j                  | _        t	        |«      | _        t        j                  | j                  |j                  ¬«      | _	        t        |«      | _        t        j                  | j                  |j                  ¬«      | _        y ©N©Úeps)rG   rH   rI   rJ   r‡   Ú	self_attnr   Ú	LayerNormÚlayer_norm_epsÚlayer_norm1r¶   ÚmlpÚlayer_norm2rU   s     €r1   rH   z&InstructBlipVideoEncoderLayer.__init__  sm   ø€ Ü‰ÑÔØ×+Ñ+ˆŒÜ3°FÓ;ˆŒÜŸ<™<¨¯©¸F×<QÑ<QÔRˆÔÜ'¨Ó/ˆŒÜŸ<™<¨¯©¸F×<QÑ<QÔRˆÕr6   r¡   Úattention_maskr£   r)   c                 óÌ   — |}| j                  |«      }| j                  |||¬«      \  }}||z   }|}| j                  |«      }| j                  |«      }||z   }|f}|r||fz  }|S )aI  
        Args:
            hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
            attention_mask (`torch.FloatTensor`): attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
                `(config.encoder_attention_heads,)`.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        )r¡   r¢   r£   )rÊ   rÇ   rÌ   rË   )r0   r¡   rÍ   r£   ÚresidualÚattn_weightsr³   s          r1   r   z%InstructBlipVideoEncoderLayer.forward  s�   € ð  !ˆà×(Ñ(¨Ó7ˆØ&*§n¡nØ'Ø$Ø/ð '5ó '
Ñ#ˆ�|ð
 &¨Ñ0ˆØ ˆØ×(Ñ(¨Ó7ˆØŸ™ Ó/ˆà%¨Ñ0ˆà Ð"ˆáØ˜�Ñ&ˆGàˆr6   r€   )r7   r8   r9   r   rH   r;   r�   r   rƒ   r   r<   r   r„   r…   s   @r1   rÂ   rÂ     sY   ø„ ðSÐ6õ Sð -2ñ	$à—|‘|ð$ð Ÿ™ð$ð $ D™>ð	$ð
 
ˆu× Ñ Ñ	!÷$r6   rÂ   c                   ó*   — e Zd ZdZeZdZdZg d¢Zd„ Z	y)Ú InstructBlipVideoPreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚblipT)Ú"InstructBlipVideoQFormerEmbeddingsr‡   Ú*InstructBlipVideoQFormerMultiHeadAttentionÚ"InstructBlipVideoQFormerSelfOutputc                 ód  — | j                   j                  }t        |t        j                  «      s4t        |t        j
                  «      st        |t        j                  «      rc|j                  j                  j                  d|¬«       t        |d«      r0|j                  �$|j                  j                  j                  «        t        |t        «      r©t        | j                   d«      r:t        | j                   t        «      s | j                   j                  j                  }t        j                   j#                  |j$                  d|¬«       t        j                   j#                  |j&                  d|¬«       yt        |t        j(                  «      rJ|j                  j                  j                  «        |j                  j                  j+                  d«       yt        |t        j                  «      r2|j                  �%|j                  j                  j                  «        yyy)zInitialize the weightsg        )ÚmeanÚstdr‰   NÚvision_configç      ð?)rA   Úinitializer_rangeÚ
isinstancer   rP   Ú	Embeddingr“   ru   ÚdataÚnormal_Úhasattrr‰   Úzero_r@   r!   rÚ   ÚinitÚtrunc_normal_rT   rO   rÈ   Úfill_)r0   ÚmoduleÚfactors      r1   Ú_init_weightsz.InstructBlipVideoPreTrainedModel._init_weightsG  sp  € à—‘×.Ñ.ˆÜ�fœbŸi™iÔ(¬J°v¼r¿|¹|Ô,LÔPZÐ[aÔce×clÑclÔPmØ�M‰M×Ñ×&Ñ&¨C°VÐ&Ô<Ü�v˜vÔ&¨6¯;©;Ð+BØ—‘× Ñ ×&Ñ&Ô(ä�fÔ?Ô@Ü�t—{‘{ OÔ4¼ZÈÏÉÔUrÔ=sØŸ™×2Ñ2×DÑD�Ü�G‰G×!Ñ! &×";Ñ";À#È6Ð!ÔRÜ�G‰G×!Ñ! &×"8Ñ"8¸sÈÐ!ÕOä˜¤§¡Ô-Ø�K‰K×Ñ×"Ñ"Ô$Ø�M‰M×Ñ×$Ñ$ SÕ)Ü˜¤§	¡	Ô*¨v¯{©{Ð/FØ�K‰K×Ñ×"Ñ"Õ$ð 0GÐ*r6   N)
r7   r8   r9   r:   r   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ_no_split_modulesrè   r>   r6   r1   rÒ   rÒ   6  s'   „ ñð
 +€LØÐØ&*Ð#òÐó%r6   rÒ   c                   ó„   ‡ — e Zd ZdZdefˆ fd„Z	 	 	 	 d
deej                     dee	   dee	   dee	   de
eef   f
d	„Zˆ xZS )ÚInstructBlipVideoEncodera"  
    Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
    [`InstructBlipVideoEncoderLayer`].

    Args:
        config (`InstructBlipVideoConfig`):
            The corresponding vision configuration for the `InstructBlipVideoEncoder`.
    rA   c                 óÐ   •— t         ‰| �  «        || _        t        j                  t        |j                  «      D �cg c]  }t        |«      ‘Œ c}«      | _        d| _	        y c c}w r´   )
rG   rH   rA   r   Ú
ModuleListÚrangeÚnum_hidden_layersrÂ   ÚlayersÚgradient_checkpointing)r0   rA   r{   rV   s      €r1   rH   z!InstructBlipVideoEncoder.__init__f  sQ   ø€ Ü‰ÑÔØˆŒÜ—m‘mÔTYÐZ`×ZrÑZrÓTsÖ$tÈqÔ%BÀ6Õ%JÒ$tÓuˆŒØ&+ˆÕ#ùò %us   ½A#rÍ   r£   Úoutput_hidden_statesÚreturn_dictr)   c                 ó  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|rdnd}|rdnd}|}t	        | j
                  «      D ]`  \  }	}
|r||fz   }| j                  r+| j                  r| j                  |
j                  |||«      }n |
|||¬«      }|d   }|sŒX||d   fz   }Œb |r||fz   }|st        d„ |||fD «       «      S t        |||¬«      S )aŠ  
        Args:
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
                Embedded representation of the inputs. Should be float, not int tokens.
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more detail.
            return_dict (`bool`, *optional*):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        Nr>   ©r£   r   r   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wr¸   r>   ©r.   Úvs     r1   r2   z3InstructBlipVideoEncoder.forward.<locals>.<genexpr>¬  s   è ø€ Òe˜qÐWXÑWdœÑeùs   ‚Š)Úlast_hidden_stater¡   Ú
attentions)rA   r£   rõ   Úuse_return_dictÚ	enumerateró   rô   ÚtrainingÚ_gradient_checkpointing_funcÚ__call__r3   r   )r0   Úinputs_embedsrÍ   r£   rõ   rö   Úencoder_statesÚall_attentionsr¡   ÚidxÚencoder_layerÚlayer_outputss               r1   r   z InstructBlipVideoEncoder.forwardl  sA  € ð8 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆá3™¸ˆÙ0™°dˆà%ˆÜ"+¨D¯K©KÓ"8ò 	FÑˆC�Ù#Ø!/°=Ð2BÑ!B�Ø×*Ò*¨t¯}ª}Ø $× AÑ AØ!×*Ñ*Ø!Ø"Ø%ó	!‘ñ !.Ø!Ø"Ø&7ô!�ð *¨!Ñ,ˆMâ Ø!/°=ÀÑ3CÐ2EÑ!E‘ð)	Fñ,  Ø+¨}Ð.>Ñ>ˆNáÜÑe ]°NÀNÐ$SÔeÓeÐeÜØ+¸>ÐVdô
ð 	
r6   )NNNN)r7   r8   r9   r:   r   rH   r   r;   r�   rƒ   r   r   r   r   r„   r…   s   @r1   rî   rî   \  s   ø„ ñð,Ð6õ ,ð 26Ø,0Ø/3Ø&*ñC
ð ! §¡Ñ.ðC
ð $ D™>ð	C
ð
 ' t™nðC
ð ˜d‘^ðC
ð 
ˆu�oÐ%Ñ	&÷C
r6   rî   a®  
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`InstructBlipVideoProcessor`]. See
            [`InstructBlipVideoProcessor.__call__`] for details.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        interpolate_pos_encoding (`bool`, *optional*, defaults to `False`):
            Whether to interpolate the pre-trained position encodings.
c                   óÄ   ‡ — e Zd ZdZeZdefˆ fd„Z ee«       e	e
e¬«      	 	 	 	 	 ddeej                     dee   dee   dee   ded	eee
f   fd
„«       «       Zd„ Zˆ xZS )ÚInstructBlipVideoVisionModelrq   rA   c                 óö   •— t         ‰| �  |«       || _        |j                  }t	        |«      | _        t        |«      | _        t        j                  ||j                  ¬«      | _        | j                  «        y rÄ   )rG   rH   rA   rI   r@   rW   rî   Úencoderr   rÈ   rÉ   Úpost_layernormÚ	post_init)r0   rA   rJ   rV   s      €r1   rH   z%InstructBlipVideoVisionModel.__init__È  s]   ø€ Ü‰Ñ˜Ô ØˆŒØ×&Ñ&ˆ	ä;¸FÓCˆŒÜ/°Ó7ˆŒÜ Ÿl™l¨9¸&×:OÑ:OÔPˆÔà�‰Õr6   ©Úoutput_typeré   r£   rõ   rö   rp   r)   c                 óÌ  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|€t	        d«      ‚| j                  ||¬«      }| j                  ||||¬«      }|d   }| j                  |«      }|dd…ddd…f   }	| j                  |	«      }	|s
||	f|dd z   S t        ||	|j                  |j                  ¬«      S )z
        Returns:

        Nz You have to specify pixel_values)rp   )r  r£   rõ   rö   r   r   )rü   Úpooler_outputr¡   rý   )rA   r£   rõ   rþ   rŽ   rW   r  r  r   r¡   rý   )
r0   rq   r£   rõ   rö   rp   r¡   Úencoder_outputsrü   Úpooled_outputs
             r1   r   z$InstructBlipVideoVisionModel.forwardÓ  s  € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐÜÐ?Ó@Ð@àŸ™¨ÐOg˜ÓhˆàŸ,™,Ø'Ø/Ø!5Ø#ð	 'ó 
ˆð ,¨AÑ.ÐØ ×/Ñ/Ð0AÓBÐà)ª!¨Q²¨'Ñ2ˆØ×+Ñ+¨MÓ:ˆáØ% }Ð5¸ÈÈÐ8KÑKÐKä)Ø/Ø'Ø)×7Ñ7Ø&×1Ñ1ô	
ð 	
r6   c                 ó   — | j                   S r¸   )rW   r5   s    r1   Úget_input_embeddingsz1InstructBlipVideoVisionModel.get_input_embeddings  s   € Ø�‰Ðr6   ©NNNNF)r7   r8   r9   Úmain_input_namer!   ré   rH   r   Ú)INSTRUCTBLIPVIDEO_VISION_INPUTS_DOCSTRINGr   r   r   r;   r<   rƒ   r   r   r   r  r„   r…   s   @r1   r
  r
  Ä  sº   ø„ Ø$€OØ0€Lð	Ð<õ 	ñ +Ð+TÓUÙÐ+EÐTqÔrð 59Ø,0Ø/3Ø&*Ø).ñ,
à˜u×0Ñ0Ñ1ð,
ð $ D™>ð,
ð ' t™nð	,
ð
 ˜d‘^ð,
ð #'ð,
ð 
ˆuÐ0Ð0Ñ	1ò,
ó só Vð,
ö\r6   r
  c                   óR   ‡ — e Zd Zdˆ fd„	Zd„ Zd„ Zd„ Zd„ Zd„ Z	 	 	 	 	 	 d	d„Z	ˆ xZ
S )
rÕ   c                 ó’  •— t         ‰| �  «        || _        |j                  |j                  z  dk7  r0t        |d«      s$t        d|j                  |j                  fz  «      ‚|j                  | _        t        |j                  |j                  z  «      | _        | j                  | j                  z  | _	        t        j                  |j                  | j                  «      | _        |r_t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        n^t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        t        j                   |j"                  «      | _        t'        |dd«      | _        | j(                  dk(  s| j(                  dk(  rF|j*                  | _        t        j,                  d|j*                  z  d	z
  | j                  «      | _        d
| _        y )Nr   Úembedding_sizezLThe hidden size (%d) is not a multiple of the number of attention heads (%d)Úposition_embedding_typeÚabsoluteÚrelative_keyÚrelative_key_queryr   r   F)rG   rH   rA   rI   r‹   rá   rŽ   r‚   Úattention_head_sizeÚall_head_sizer   r“   ÚqueryÚencoder_hidden_sizeÚkeyÚvaluer�   Úattention_probs_dropout_probr’   r,   r  Úmax_position_embeddingsrÞ   Údistance_embeddingÚsave_attention©r0   rA   Úis_cross_attentionrV   s      €r1   rH   z3InstructBlipVideoQFormerMultiHeadAttention.__init__  sÉ  ø€ Ü‰ÑÔØˆŒØ×Ñ × :Ñ :Ñ:¸aÒ?ÌÐPVÐXhÔHiÜØ^Ø×%Ñ% v×'AÑ'AÐBñCóð ð
 $*×#=Ñ#=ˆÔ Ü#& v×'9Ñ'9¸F×<VÑ<VÑ'VÓ#WˆÔ Ø!×5Ñ5¸×8PÑ8PÑPˆÔä—Y‘Y˜v×1Ñ1°4×3EÑ3EÓFˆŒ
ÙÜ—y‘y ×!;Ñ!;¸T×=OÑ=OÓPˆDŒHÜŸ™ 6×#=Ñ#=¸t×?QÑ?QÓRˆD�Jä—y‘y ×!3Ñ!3°T×5GÑ5GÓHˆDŒHÜŸ™ 6×#5Ñ#5°t×7IÑ7IÓJˆDŒJä—z‘z &×"EÑ"EÓFˆŒÜ'.¨vÐ7PÐR\Ó']ˆÔ$Ø×'Ñ'¨>Ò9¸T×=YÑ=YÐ]qÒ=qØ+1×+IÑ+IˆDÔ(Ü&(§l¡l°1°v×7UÑ7UÑ3UÐXYÑ3YÐ[_×[sÑ[sÓ&tˆDÔ#Ø#ˆÕr6   c                 ó   — || _         y r¸   ©Úattn_gradients)r0   r/  s     r1   Úsave_attn_gradientsz>InstructBlipVideoQFormerMultiHeadAttention.save_attn_gradients$  s
   € Ø,ˆÕr6   c                 ó   — | j                   S r¸   r.  r5   s    r1   Úget_attn_gradientsz=InstructBlipVideoQFormerMultiHeadAttention.get_attn_gradients'  s   € Ø×"Ñ"Ð"r6   c                 ó   — || _         y r¸   ©Úattention_map)r0   r5  s     r1   Úsave_attention_mapz=InstructBlipVideoQFormerMultiHeadAttention.save_attention_map*  s
   € Ø*ˆÕr6   c                 ó   — | j                   S r¸   r4  r5   s    r1   Úget_attention_mapz<InstructBlipVideoQFormerMultiHeadAttention.get_attention_map-  s   € Ø×!Ñ!Ð!r6   c                 ó    — |j                  «       d d | j                  | j                  fz   } |j                  |Ž }|j	                  dddd«      S )Nr[   r   r   r   r
   )r]   r‹   r!  ri   rf   )r0   ÚxÚnew_x_shapes      r1   Útranspose_for_scoresz?InstructBlipVideoQFormerMultiHeadAttention.transpose_for_scores0  sN   € Ø—f‘f“h˜s �m t×'?Ñ'?À×AYÑAYÐ&ZÑZˆØˆA�F‰F�KÐ ˆØ�y‰y˜˜A˜q !Ó$Ð$r6   c                 óÂ  — |d u}|rC| j                  | j                  |«      «      }	| j                  | j                  |«      «      }
|}n»|�y| j                  | j                  |«      «      }	| j                  | j                  |«      «      }
t        j                  |d   |	gd¬«      }	t        j                  |d   |
gd¬«      }
n@| j                  | j                  |«      «      }	| j                  | j                  |«      «      }
| j                  |«      }| j                  |«      }|	|
f}t        j                  ||	j                  dd«      «      }| j                  dk(  s| j                  dk(  �rF|j                  «       d   }t        j                  |t        j                  |j                  ¬	«      j                  dd«      }t        j                  |t        j                  |j                  ¬	«      j                  dd«      }||z
  }| j                  || j                  z   dz
  «      }|j!                  |j"                  ¬
«      }| j                  dk(  rt        j$                  d||«      }||z   }nE| j                  dk(  r6t        j$                  d||«      }t        j$                  d|	|«      }||z   |z   }|t'        j(                  | j*                  «      z  }|j"                  }|�||z   } t-        j.                  d¬«      |«      j!                  |«      }|r8| j0                  r,| j3                  |«       |j5                  | j6                  «       | j9                  |«      }|�||z  }t        j                  ||
«      }|j;                  dddd«      j=                  «       }|j                  «       d d | j>                  fz   } |j                  |Ž }|r||fn|f}||fz   }|S )Nr   r   r`   r   r[   r¦   r  r   ©rt   Údevicers   zbhld,lrd->bhlrzbhrd,lrd->bhlrr
   ) r<  r%  r&  r;   rj   r#  r§   rx   r  r]   ÚarangeÚlongr?  ri   r)  r(  rv   rt   ÚeinsumÚmathÚsqrtr!  r   ÚSoftmaxr*  r6  Úregister_hookr0  r’   rf   rŸ   r"  )r0   r¡   rÍ   r¢   Úencoder_hidden_statesÚencoder_attention_maskÚpast_key_valuer£   r,  Ú	key_layerÚvalue_layerÚmixed_query_layerÚquery_layerr®   Ú
seq_lengthÚposition_ids_lÚposition_ids_rÚdistanceÚpositional_embeddingÚrelative_position_scoresÚrelative_position_scores_queryÚrelative_position_scores_keyÚattention_scores_dtyper¯   Úattention_probs_droppedr°   r±   r³   s                               r1   r   z2InstructBlipVideoQFormerMultiHeadAttention.forward5  s¯  € ð 3¸$Ð>ÐáØ×1Ñ1°$·(±(Ð;PÓ2QÓRˆIØ×3Ñ3°D·J±JÐ?TÓ4UÓVˆKØ3‰NØÐ'Ø×1Ñ1°$·(±(¸=Ó2IÓJˆIØ×3Ñ3°D·J±J¸}Ó4MÓNˆKÜŸ	™	 >°!Ñ#4°iÐ"@ÀaÔHˆIÜŸ)™) ^°AÑ%6¸Ð$DÈ!ÔL‰Kà×1Ñ1°$·(±(¸=Ó2IÓJˆIØ×3Ñ3°D·J±J¸}Ó4MÓNˆKà ŸJ™J }Ó5Ðà×/Ñ/Ð0AÓBˆà# [Ð1ˆô !Ÿ<™<¨°Y×5HÑ5HÈÈRÓ5PÓQÐà×'Ñ'¨>Ò9¸T×=YÑ=YÐ]qÓ=qØ&×+Ñ+Ó-¨aÑ0ˆJÜ"Ÿ\™\¨*¼E¿J¹JÈ}×OcÑOcÔd×iÑiÐjlÐnoÓpˆNÜ"Ÿ\™\¨*¼E¿J¹JÈ}×OcÑOcÔd×iÑiÐjkÐmoÓpˆNØ%¨Ñ6ˆHØ#'×#:Ñ#:¸8Àd×FbÑFbÑ;bÐefÑ;fÓ#gÐ Ø#7×#:Ñ#:À×ARÑARÐ#:Ó#SÐ à×+Ñ+¨~Ò=Ü+0¯<©<Ð8HÈ+ÐWkÓ+lÐ(Ø#3Ð6NÑ#NÑ Ø×-Ñ-Ð1EÒEÜ16·±Ð>NÐP[Ð]qÓ1rÐ.Ü/4¯|©|Ð<LÈiÐYmÓ/nÐ,Ø#3Ð6TÑ#TÐWsÑ#sÐ à+¬d¯i©i¸×8PÑ8PÓ.QÑQÐØ!1×!7Ñ!7ÐàÐ%à/°.Ñ@Ðð -œ"Ÿ*™*¨Ô,Ð-=Ó>×AÑAÐBXÓYˆá $×"5Ò"5Ø×#Ñ# OÔ4Ø×)Ñ)¨$×*BÑ*BÔCð #'§,¡,¨Ó"?Ðð Ð Ø&=À	Ñ&IÐ#äŸ™Ð%<¸kÓJˆà%×-Ñ-¨a°°A°qÓ9×DÑDÓFˆØ"/×"4Ñ"4Ó"6°s¸Ð";¸t×?QÑ?QÐ>SÑ"SÐØ*˜×*Ñ*Ð,CÐDˆá6G�= /Ñ2ÈmÐM]ˆà˜^Ð-Ñ-ˆØˆr6   r€   ©NNNNNF)r7   r8   r9   rH   r0  r2  r6  r8  r<  r   r„   r…   s   @r1   rÕ   rÕ     s;   ø„ õ$ò8-ò#ò+ò"ò%ð ØØ"Ø#ØØ÷Tr6   rÕ   c                   ón   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  dej
                  fd„Zˆ xZS )rÖ   c                 ó(  •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        j                  |j                  |j                  ¬«      | _        t        j                  |j                  «      | _
        y rÄ   )rG   rH   r   r“   rI   ÚdenserÈ   rÉ   r�   Úhidden_dropout_probr’   rU   s     €r1   rH   z+InstructBlipVideoQFormerSelfOutput.__init__�  s`   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z‘z &×"<Ñ"<Ó=ˆ�r6   r¡   Úinput_tensorr)   c                 ór   — | j                  |«      }| j                  |«      }| j                  ||z   «      }|S r¸   ©r[  r’   rÈ   ©r0   r¡   r]  s      r1   r   z*InstructBlipVideoQFormerSelfOutput.forward“  ó7   € ØŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆØŸ™ }°|Ñ'CÓDˆØÐr6   rÀ   r…   s   @r1   rÖ   rÖ   Œ  ó1   ø„ ô>ð U§\¡\ð ÀÇÁð ÐRW×R^ÑR^÷ r6   rÖ   c                   ó  ‡ — e Zd Zdˆ fd„	Zd„ Z	 	 	 	 	 	 ddej                  deej                     deej                     deej                     deej                     dee	e	ej                           d	ee
   d
e	ej                     fd„Zˆ xZS )Ú!InstructBlipVideoQFormerAttentionc                 ó‚   •— t         ‰| �  «        t        ||«      | _        t	        |«      | _        t        «       | _        y r¸   )rG   rH   rÕ   Ú	attentionrÖ   r²   ÚsetÚpruned_headsr+  s      €r1   rH   z*InstructBlipVideoQFormerAttention.__init__›  s3   ø€ Ü‰ÑÔÜCÀFÐL^Ó_ˆŒÜ8¸Ó@ˆŒÜ›EˆÕr6   c                 ó>  — t        |«      dk(  ry t        || j                  j                  | j                  j                  | j
                  «      \  }}t        | j                  j                  |«      | j                  _        t        | j                  j                  |«      | j                  _        t        | j                  j                  |«      | j                  _	        t        | j                  j                  |d¬«      | j                  _        | j                  j                  t        |«      z
  | j                  _        | j                  j                  | j                  j                  z  | j                  _        | j
                  j                  |«      | _        y )Nr   r   r`   )Úlenr   rf  r‹   r!  rh  r   r#  r%  r&  r²   r[  r"  Úunion)r0   ÚheadsÚindexs      r1   Úprune_headsz-InstructBlipVideoQFormerAttention.prune_heads¡  s  € Üˆu‹:˜Š?ØÜ7Ø�4—>‘>×5Ñ5°t·~±~×7YÑ7YÐ[_×[lÑ[ló
‰ˆˆuô
  2°$·.±.×2FÑ2FÈÓNˆ�‰ÔÜ/°·±×0BÑ0BÀEÓJˆ�‰ÔÜ1°$·.±.×2FÑ2FÈÓNˆ�‰ÔÜ.¨t¯{©{×/@Ñ/@À%ÈQÔOˆ�‰Ôð .2¯^©^×-OÑ-OÔRUÐV[ÓR\Ñ-\ˆ�‰Ô*Ø'+§~¡~×'IÑ'IÈDÏNÉN×LnÑLnÑ'nˆ�‰Ô$Ø ×-Ñ-×3Ñ3°EÓ:ˆÕr6   r¡   rÍ   r¢   rG  rH  rI  r£   r)   c           	      óp   — | j                  |||||||«      }| j                  |d   |«      }	|	f|dd  z   }
|
S )Nr   r   )rf  r²   )r0   r¡   rÍ   r¢   rG  rH  rI  r£   Úself_outputsÚattention_outputr³   s              r1   r   z)InstructBlipVideoQFormerAttention.forward³  sW   € ð —~‘~ØØØØ!Ø"ØØó
ˆð  Ÿ;™; |°A¡¸ÓFÐØ#Ð%¨°Q°RÐ(8Ñ8ˆØˆr6   r€   rX  )r7   r8   r9   rH   rn  r;   r�   r   r<   r   rƒ   r   r„   r…   s   @r1   rd  rd  š  sÆ   ø„ õ"ò;ð* 7;Ø15Ø=AØ>BØDHØ,1ñà—|‘|ðð ! ×!2Ñ!2Ñ3ðð ˜E×-Ñ-Ñ.ð	ð
  (¨×(9Ñ(9Ñ:ðð !)¨×):Ñ):Ñ ;ðð !  u¨U×->Ñ->Ñ'?Ñ!@ÑAðð $ D™>ðð 
ˆu�|‰|Ñ	÷r6   rd  c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )Ú$InstructBlipVideoQFormerIntermediatec                 ó  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        t        |j                  t        «      rt        |j                     | _        y |j                  | _        y r¸   )rG   rH   r   r“   rI   r»   r[  rÝ   r¹   Ústrr   Úintermediate_act_fnrU   s     €r1   rH   z-InstructBlipVideoQFormerIntermediate.__init__Ì  s]   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3KÑ3KÓLˆŒ
Ü�f×'Ñ'¬Ô-Ü'-¨f×.?Ñ.?Ñ'@ˆDÕ$à'-×'8Ñ'8ˆDÕ$r6   r¡   r)   c                 óJ   — | j                  |«      }| j                  |«      }|S r¸   )r[  rv  r¿   s     r1   r   z,InstructBlipVideoQFormerIntermediate.forwardÔ  s&   € ØŸ
™
 =Ó1ˆØ×0Ñ0°Ó?ˆØÐr6   rÀ   r…   s   @r1   rs  rs  Ë  s#   ø„ ô9ð U§\¡\ð °e·l±l÷ r6   rs  c                   ón   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  dej
                  fd„Zˆ xZS )ÚInstructBlipVideoQFormerOutputc                 ó(  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        t        j                  |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        y rÄ   )rG   rH   r   r“   r»   rI   r[  rÈ   rÉ   r�   r\  r’   rU   s     €r1   rH   z'InstructBlipVideoQFormerOutput.__init__Û  s`   ø€ Ü‰ÑÔÜ—Y‘Y˜v×7Ñ7¸×9KÑ9KÓLˆŒ
ÜŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z‘z &×"<Ñ"<Ó=ˆ�r6   r¡   r]  r)   c                 ór   — | j                  |«      }| j                  |«      }| j                  ||z   «      }|S r¸   r_  r`  s      r1   r   z&InstructBlipVideoQFormerOutput.forwardá  ra  r6   rÀ   r…   s   @r1   ry  ry  Ú  rb  r6   ry  c                   ó@   ‡ — e Zd Zˆ fd„Z	 	 	 	 	 	 	 dd„Zd„ Zd„ Zˆ xZS )ÚInstructBlipVideoQFormerLayerc                 óf  •— t         ‰| �  «        |j                  | _        d| _        t	        |«      | _        || _        ||j                  z  dk(  rt	        |d¬«      | _        d| _	        nd| _	        t        |«      | _        t        |«      | _        t        |«      | _        t        |«      | _        y )Nr   r   T)r,  F)rG   rH   Úchunk_size_feed_forwardÚseq_len_dimrd  rf  Ú	layer_idxÚcross_attention_frequencyÚcrossattentionÚhas_cross_attentionrs  Úintermediatery  r²   Úintermediate_queryÚoutput_query©r0   rA   r�  rV   s      €r1   rH   z&InstructBlipVideoQFormerLayer.__init__é  s�   ø€ Ü‰ÑÔØ'-×'EÑ'EˆÔ$ØˆÔÜ:¸6ÓBˆŒà"ˆŒà�v×7Ñ7Ñ7¸1Ò<Ü"CÀFÐ_cÔ"dˆDÔØ'+ˆDÕ$à',ˆDÔ$ä@ÀÓHˆÔÜ4°VÓ<ˆŒä"FÀvÓ"NˆÔÜ:¸6ÓBˆÕr6   c	           
      ó’  — |�|d d nd }	| j                  |||||	¬«      }
|
d   }|
dd }|
d   }|dkD  rÛ|d d …d |…d d …f   }| j                  r1|€t        d«      ‚| j                  ||||||¬«      }|d   }||dd z   }t	        | j
                  | j                  | j                  |«      }|j                  d   |kD  r~t	        | j                  | j                  | j                  |d d …|d …d d …f   «      }t        j                  ||gd¬«      }n,t	        | j                  | j                  | j                  |«      }|f|z   }||fz   }|S )	Nr   )r£   rI  r   r   r[   z>encoder_hidden_states must be given for cross-attention layersrø   r`   )rf  r„  rŽ   rƒ  r   Úfeed_forward_chunk_queryr  r€  rb   Úfeed_forward_chunkr;   rj   )r0   r¡   rÍ   r¢   rG  rH  rI  r£   Úquery_lengthÚself_attn_past_key_valueÚself_attention_outputsrq  r³   Úpresent_key_valueÚquery_attention_outputÚcross_attention_outputsÚlayer_outputÚlayer_output_texts                     r1   r   z%InstructBlipVideoQFormerLayer.forwardý  s¸  € ð :HÐ9S >°"°1Ñ#5ÐY]Ð Ø!%§¡ØØØØ/Ø3ð "0ó "
Ðð 2°!Ñ4ÐØ(¨¨2Ð.ˆà2°2Ñ6Ðà˜!ÒØ%5²a¸¸,¸ÊÐ6IÑ%JÐ"à×'Ò'Ø(Ð0Ü$Ð%eÓfÐfØ*.×*=Ñ*=Ø*Ø"ØØ)Ø*Ø&7ð +>ó +Ð'ð *AÀÑ)CÐ&à!Ð$;¸A¸bÐ$AÑA�ä4Ø×-Ñ-Ø×,Ñ,Ø× Ñ Ø&ó	ˆLð  ×%Ñ% aÑ(¨<Ò7Ü$=Ø×+Ñ+Ø×0Ñ0Ø×$Ñ$Ø$¢Q¨©²qÐ%8Ñ9ó	%Ð!ô  %Ÿy™y¨,Ð8IÐ)JÐPQÔR‘ä4Ø×'Ñ'Ø×,Ñ,Ø× Ñ Ø ó	ˆLð  �/ GÑ+ˆàÐ.Ð0Ñ0ˆàˆr6   c                 óL   — | j                  |«      }| j                  ||«      }|S r¸   )r…  r²   ©r0   rq  Úintermediate_outputr’  s       r1   r‹  z0InstructBlipVideoQFormerLayer.feed_forward_chunkD  s,   € Ø"×/Ñ/Ð0@ÓAÐØ—{‘{Ð#6Ð8HÓIˆØÐr6   c                 óL   — | j                  |«      }| j                  ||«      }|S r¸   )r†  r‡  r•  s       r1   rŠ  z6InstructBlipVideoQFormerLayer.feed_forward_chunk_queryI  s.   € Ø"×5Ñ5Ð6FÓGÐØ×(Ñ(Ð)<Ð>NÓOˆØÐr6   )NNNNNFr   )r7   r8   r9   rH   r   r‹  rŠ  r„   r…   s   @r1   r}  r}  è  s1   ø„ ôCð. ØØ"Ø#ØØØóEòNö
r6   r}  c                   ó:   ‡ — e Zd Zˆ fd„Z	 	 	 	 	 	 	 	 	 	 dd„Zˆ xZS )ÚInstructBlipVideoQFormerEncoderc           	      óÒ   •— t         ‰| �  «        || _        t        j                  t        |j                  «      D �cg c]  }t        ||«      ‘Œ c}«      | _        d| _	        y c c}w r´   )
rG   rH   rA   r   rð   rñ   rò   r}  Úlayerrô   rˆ  s      €r1   rH   z(InstructBlipVideoQFormerEncoder.__init__P  sW   ø€ Ü‰ÑÔØˆŒÜ—]‘]ÜOTÐU[×UmÑUmÓOnÖoÀ)Ô*¨6°9Õ=Òoó
ˆŒ
ð ',ˆÕ#ùò ps   ½A$c                 ój  — |	rdnd }|rdnd }|rdnd }|rdnd }t        | j                  j                  «      D ]É  }| j                  |   }|	r||fz   }|�||   nd }|�||   nd }t	        | j                  dd«      rF| j
                  r:|rt        j                  d«       d}| j                  |j                  |||||«      }n |||||||||«      }|d   }|r	||d   fz  }|sŒ«||d   fz   }|j                  sŒÁ||d   fz   }ŒË |	r||fz   }|
st        d	„ |||||fD «       «      S t        |||||¬
«      S )Nr>   rô   FzZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...r   r[   r   r   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr¸   r>   rú   s     r1   r2   z:InstructBlipVideoQFormerEncoder.forward.<locals>.<genexpr>š  s   è ø€ ò 
àð �=ô ñ
ùs   ‚)rü   Úpast_key_valuesr¡   rý   Úcross_attentions)rñ   rA   rò   r›  r,   r   ÚloggerÚwarningr  r  r„  r3   r   )r0   r¡   rÍ   r¢   rG  rH  rž  Ú	use_cacher£   rõ   rö   rŒ  Úall_hidden_statesÚall_self_attentionsÚall_cross_attentionsÚnext_decoder_cacheÚiÚlayer_moduleÚlayer_head_maskrI  r  s                        r1   r   z'InstructBlipVideoQFormerEncoder.forwardX  sÀ  € ñ #7™B¸DÐÙ$5™b¸4ÐÙ%6™r¸DÐá#,™R°$Ðä�t—{‘{×4Ñ4Ó5ò (	VˆAØŸ:™: a™=ˆLÙ#Ø$5¸Ð8HÑ$HÐ!à.7Ð.C˜i¨šlÈˆOØ3BÐ3N˜_¨QÒ/ÐTXˆNä�t—{‘{Ð$<¸eÔDÈÏÊÙÜ—N‘NØtôð !&�IØ $× AÑ AØ ×)Ñ)Ø!Ø"Ø#Ø)Ø*ó!‘ñ !-Ø!Ø"Ø#Ø)Ø*Ø"Ø%Ø ó	!�ð *¨!Ñ,ˆMÙØ" }°RÑ'8Ð&:Ñ:Ð"Ú Ø&9¸]È1Ñ=MÐ<OÑ&OÐ#Ø×3Ó3Ø+?À=ÐQRÑCSÐBUÑ+UÑ(ðQ(	VñT  Ø 1°]Ð4DÑ DÐáÜñ 
ð "Ø&Ø%Ø'Ø(ðô
ó 
ð 
ô 9Ø+Ø.Ø+Ø*Ø1ô
ð 	
r6   )
NNNNNNFFTr   )r7   r8   r9   rH   r   r„   r…   s   @r1   r™  r™  O  s.   ø„ ô,ð ØØ"Ø#ØØØØ"ØØ÷S
r6   r™  c                   ó2   ‡ — e Zd ZdZˆ fd„Z	 	 	 	 dd„Zˆ xZS )rÔ   z;Construct the embeddings from word and position embeddings.c                 óP  •— t         ‰| �  «        t        j                  |j                  |j
                  |j                  ¬«      | _        t        j                  |j                  |j
                  «      | _	        t        j                  |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        | j!                  dt#        j$                  |j                  «      j'                  d«      d¬«       t)        |dd«      | _        || _        y )	N)Úpadding_idxrÅ   Úposition_ids)r   r[   F)Ú
persistentr  r  )rG   rH   r   rÞ   Ú
vocab_sizerI   Úpad_token_idÚword_embeddingsr(  Úposition_embeddingsrÈ   rÉ   Ú	layernormr�   r\  r’   Úregister_bufferr;   r@  ry   r,   r  rA   rU   s     €r1   rH   z+InstructBlipVideoQFormerEmbeddings.__init__±  sÞ   ø€ Ü‰ÑÔÜ!Ÿ|™|¨F×,=Ñ,=¸v×?QÑ?QÐ_e×_rÑ_rÔsˆÔÜ#%§<¡<°×0NÑ0NÐPV×PbÑPbÓ#cˆÔ äŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z‘z &×"<Ñ"<Ó=ˆŒð 	×ÑØœEŸL™L¨×)GÑ)GÓH×OÑOÐPWÓXÐejð 	ô 	
ô (/¨vÐ7PÐR\Ó']ˆÔ$àˆ�r6   c                 ó  — |�|j                  «       d   }nd}|€&| j                  d d …|||z   …f   j                  «       }|�k| j                  |«      }| j                  dk(  r/| j                  |j                  |j                  «      «      }||z   }|�t        j                  ||fd¬«      }n|}|j                  | j                  j                  j                  «      }| j                  |«      }| j                  |«      }|S )Nr   r   r  r`   )r]   r­  Úcloner±  r  r²  rv   r?  r;   rj   r³  ru   rt   r’   )r0   Ú	input_idsr­  Úquery_embedsÚpast_key_values_lengthrN  rW   r²  s           r1   r   z*InstructBlipVideoQFormerEmbeddings.forwardÁ  sÿ   € ð Ð Ø"Ÿ™Ó)¨!Ñ,‰JàˆJàÐØ×,Ñ,ªQÐ0FÈÐVlÑIlÐ0lÐ-lÑm×sÑsÓuˆLàÐ Ø×-Ñ-¨iÓ8ˆJØ×+Ñ+¨zÒ9Ø&*×&>Ñ&>¸|¿¹Èz×O`ÑO`Ó?aÓ&bÐ#Ø'Ð*=Ñ=�
àÐ'Ü"ŸY™Y¨°jÐ'AÀqÔI‘
à%ˆJà—]‘] 4§>¡>×#8Ñ#8×#>Ñ#>Ó?ˆ
Ø—^‘^ JÓ/ˆ
Ø—\‘\ *Ó-ˆ
ØÐr6   )NNNr   )r7   r8   r9   r:   rH   r   r„   r…   s   @r1   rÔ   rÔ   ®  s   ø„ ÙEôð$ ØØØ ÷r6   rÔ   c                   ó  ‡ — e Zd ZdZdefˆ fd„Zd„ Zd„ Zd„ Z	 dde	j                  dee   d	e	j                  d
ede	j                  f
d„Z	 	 	 	 	 	 	 	 	 	 	 dde	j                   dee	j$                     dee	j                      dee	j                     dee	j$                     dee	j$                     dee	j$                     deeee	j$                           dee   dee   dee   dee   deee	j$                     ef   fd„Zˆ xZS )ÚInstructBlipVideoQFormerModelz’
    Querying Transformer (Q-Former), used in InstructBlipVideo. Slightly modified from BLIP-2 as it also takes the
    instruction as input.
    rA   c                 ó’   •— t         ‰| �  |«       || _        t        |«      | _        t        |«      | _        | j                  «        y r¸   )rG   rH   rA   rÔ   rW   r™  r  r  rU   s     €r1   rH   z&InstructBlipVideoQFormerModel.__init__ç  s9   ø€ Ü‰Ñ˜Ô ØˆŒä<¸VÓDˆŒä6°vÓ>ˆŒà�‰Õr6   c                 ó.   — | j                   j                  S r¸   ©rW   r±  r5   s    r1   r  z2InstructBlipVideoQFormerModel.get_input_embeddingsñ  s   € Ø�‰×.Ñ.Ð.r6   c                 ó&   — || j                   _        y r¸   r¾  ©r0   r&  s     r1   Úset_input_embeddingsz2InstructBlipVideoQFormerModel.set_input_embeddingsô  s   € Ø*/ˆ�‰Õ'r6   c                 ó˜   — |j                  «       D ]7  \  }}| j                  j                  |   j                  j	                  |«       Œ9 y)z�
        Prunes heads of the model. heads_to_prune: dict of {layer_num: list of heads to prune in this layer} See base
        class PreTrainedModel
        N)Úitemsr  r›  rf  rn  )r0   Úheads_to_pruner›  rl  s       r1   Ú_prune_headsz*InstructBlipVideoQFormerModel._prune_heads÷  sE   € ð
 +×0Ñ0Ó2ò 	C‰LˆE�5Ø�L‰L×Ñ˜uÑ%×/Ñ/×;Ñ;¸EÕBñ	Cr6   rÍ   Úinput_shaper?  Ú	has_queryr)   c                 ó  — |j                  «       dk(  r|dd…ddd…dd…f   }n=|j                  «       dk(  r|dd…dddd…f   }nt        d|› d|j                  › d�«      ‚|j                  | j                  ¬«      }d|z
  d	z  }|S )
a>  
        Makes broadcastable attention and causal masks so that future and masked tokens are ignored.

        Arguments:
            attention_mask (`torch.Tensor`):
                Mask with ones indicating tokens to attend to, zeros for tokens to ignore.
            input_shape (`Tuple[int]`):
                The shape of the input to the model.
            device: (`torch.device`):
                The device of the input to the model.

        Returns:
            `torch.Tensor` The extended attention mask, with a the same dtype as `attention_mask.dtype`.
        r
   Nr   z!Wrong shape for input_ids (shape z) or attention_mask (shape ú)rs   rÛ   g     ˆÃÀ)ra   rŽ   rb   rv   rt   )r0   rÍ   rÆ  r?  rÇ  Úextended_attention_masks         r1   Úget_extended_attention_maskz9InstructBlipVideoQFormerModel.get_extended_attention_maskÿ  s©   € ð. ×ÑÓ 1Ò$Ø&4²Q¸ºaÂ°]Ñ&CÑ#Ø×ÑÓ! QÒ&ð '5²Q¸¸dÂAÐ5EÑ&FÑ#äØ3°K°=Ð@[Ð\j×\pÑ\pÐ[qÐqrÐsóð ð #:×"<Ñ"<À4Ç:Á:Ð"<Ó"NÐØ#&Ð)@Ñ#@ÀHÑ"LÐØ&Ð&r6   r·  r­  r¸  r¢   rG  rH  rž  r¢  r£   rõ   rö   c                 ó°  — |
�|
n| j                   j                  }
|�|n| j                   j                  }|�|n| j                   j                  }|€|€t	        d«      ‚|�,|d   d   j
                  d   | j                   j                  z
  nd}|�|j
                  d   nd}| j                  ||||¬«      }|j                  «       dd }|\  }}|j                  }|€t        j                  |||z   f|¬«      }| j                  |||«      }|�¬t        |t        «      r|d   j                  «       \  }}}n|j                  «       \  }}}||f}t        |t        «      r|D �cg c]  }| j                  |«      ‘Œ }}n?|€)t        j                  ||¬«      }| j                  |«      }n| j                  |«      }nd}| j!                  || j                   j"                  «      }| j%                  |||||||	|
|||¬	«      }|d   }|dd…ddd…f   }|s
||f|dd z   S t'        |||j(                  |j*                  |j,                  |j.                  ¬
«      S c c}w )a  
        encoder_hidden_states  (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
            the model is configured as a decoder.
        encoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
            the cross-attention if the model is configured as a decoder. Mask values selected in `[0, 1]`:
            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.
        past_key_values (`tuple(tuple(torch.FloatTensor))` of length `config.n_layers` with each tuple having 4 tensors of:
            shape `(batch_size, num_heads, sequence_length - 1, embed_size_per_head)`): Contains precomputed key and
            value hidden states of the attention blocks. Can be used to speed up decoding. If `past_key_values` are
            used, the user can optionally input only the last `decoder_input_ids` (those that don't have their past key
            value states given to this model) of shape `(batch_size, 1)` instead of all `decoder_input_ids` of shape
            `(batch_size, sequence_length)`.
        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).
        Nz7You have to specify query_embeds when input_ids is Noner   r   r   )r·  r­  r¸  r¹  r[   )r?  )
rÍ   r¢   rG  rH  rž  r¢  r£   rõ   rö   rŒ  )rü   r  rž  r¡   rý   rŸ  )rA   r£   rõ   rþ   rŽ   rb   rŒ  rW   r]   r?  r;   ÚonesrË  rÝ   ÚlistÚinvert_attention_maskÚget_head_maskrò   r  r   rž  r¡   rý   rŸ  )r0   r·  rÍ   r­  r¸  r¢   rG  rH  rž  r¢  r£   rõ   rö   r¹  rŒ  Úembedding_outputrÆ  rz   rN  r?  rÊ  Úencoder_batch_sizeÚencoder_sequence_lengthr{   Úencoder_hidden_shapeÚmaskÚencoder_extended_attention_maskr  Úsequence_outputr  s                                 r1   r   z%InstructBlipVideoQFormerModel.forward*  sÉ  € ðD 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐ Ð!5ÜÐVÓWÐWð JYÐIdˆO˜AÑ˜qÑ!×'Ñ'¨Ñ*¨T¯[©[×-EÑ-EÒEÐjkð 	ð 1=Ð0H�|×)Ñ)¨!Ò,ÈaˆàŸ?™?ØØ%Ø%Ø#9ð	 +ó 
Ðð '×+Ñ+Ó-¨c¨rÐ2ˆØ!,Ñˆ
�JØ!×(Ñ(ˆàÐ!Ü"ŸZ™Z¨*°jÐCYÑ6YÐ)ZÐdjÔkˆNð #'×"BÑ"BÀ>ÐS^Ð`fÓ"gÐð !Ð,ÜÐ/´Ô6ØAVÐWXÑAY×A^ÑA^ÓA`Ñ>Ð"Ð$;¹QàAV×A[ÑA[ÓA]Ñ>Ð"Ð$;¸QØ$6Ð8OÐ#PÐ äÐ0´$Ô7Ø`vÖ2wÐX\°4×3MÑ3MÈdÕ3SÐ2wÐ/Ñ2wØ'Ð/Ü).¯©Ð4HÐQWÔ)XÐ&Ø26×2LÑ2LÐMcÓ2dÑ/à26×2LÑ2LÐMcÓ2dÑ/à.2Ð+ð ×&Ñ& y°$·+±+×2OÑ2OÓPˆ	àŸ,™,ØØ2ØØ"7Ø#BØ+ØØ/Ø!5Ø#Ø%ð 'ó 
ˆð *¨!Ñ,ˆØ'ª¨1ªa¨Ñ0ˆáØ# ]Ð3°oÀaÀbÐ6IÑIÐIä;Ø-Ø'Ø+×;Ñ;Ø)×7Ñ7Ø&×1Ñ1Ø,×=Ñ=ô
ð 	
ùòG 3xs   Å!Ir€   )NNNNNNNNNNN)r7   r8   r9   r:   r    rH   r  rÁ  rÅ  r;   r�   r   r‚   r?  rƒ   rË  Ú
LongTensorr   r<   r   r   r   r„   r…   s   @r1   r»  r»  á  s§  ø„ ñð
Ð=õ ò/ò0òCð  ñ)'àŸ™ð)'ð ˜3‘Zð)'ð —‘ð	)'ð
 ð)'ð 
�‰ó)'ð\ 7;Ø37Ø/3Ø15Ø=AØ>BØEIØ$(Ø,0Ø/3Ø&*ñx
à×#Ñ#ðx
ð ! ×!2Ñ!2Ñ3ðx
ð ˜u×/Ñ/Ñ0ð	x
ð
 ˜uŸ|™|Ñ,ðx
ð ˜E×-Ñ-Ñ.ðx
ð  (¨×(9Ñ(9Ñ:ðx
ð !)¨×):Ñ):Ñ ;ðx
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðx
ð ˜D‘>ðx
ð $ D™>ðx
ð ' t™nðx
ð ˜d‘^ðx
ð 
ˆu�U×&Ñ&Ñ'Ð)UÐUÑ	V÷x
r6   r»  aJ  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

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

    Parameters:
        config ([`InstructBlipVideoConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
a¢  
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`InstructBlipVideoProcessor`]. See
            [`InstructBlipVideoProcessor.__call__`] for details.

        qformer_input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of input sequence tokens in the vocabulary of the Q-Former. Input tokens can optionally be provided
            to serve as text prompt, which the Q-Former model will encode.

            Indices can be obtained using [`InstructBlipVideoProcessor`]. See [`InstructBlipVideoProcessor.__call__`] for
            details.

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

        qformer_attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

            [What are attention masks?](../glossary#attention-mask)

        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of input sequence tokens in the vocabulary of the language model. Input tokens can optionally be
            provided to serve as text prompt, which the language model can continue.

            Indices can be obtained using [`InstructBlipVideoProcessor`]. See [`InstructBlipVideoProcessor.__call__`] for
            details.

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

        attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

            [What are attention masks?](../glossary#attention-mask)

        decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary of the language model. Only relevant in case an
            encoder-decoder language model (like T5) is used.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details. [What are decoder input IDs?](../glossary#decoder-input-ids)

        decoder_attention_mask (`torch.BoolTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
            be used by default.

            Only relevant in case an encoder-decoder language model (like T5) is used.

        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        interpolate_pos_encoding (`bool`, *optional*, defaults to `False`):
            Whether to interpolate the pre-trained position encodings.
        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).
a¯  
    InstructBlipVideo Model for generating text given an image and an optional text prompt. The model consists of a vision
    encoder, Querying Transformer (Q-Former) and a language model.

    One can optionally pass `input_ids` to the model, which serve as a text prompt, to make the language model continue
    the prompt. Otherwise, the language model starts generating text from the [BOS] (beginning-of-sequence) token.
    c            !       óÞ  ‡ — e Zd ZeZdZdZdZdZdgZ	defˆ fd„Z
d„ Zd„ Zd	„ Zd
ej                  fd„Zd„ Zd„ Zd„ Zd„ Z ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 ddej6                  dej6                  deej:                     deej6                     deej:                     deej:                     deej:                     dee   dee   deej:                     dee   dedee   d
ee ef   fd„«       «       Z! ejD                  «       	 	 	 	 	 d dej6                  deej:                     deej:                     deej:                     deej:                     ded
ej:                  fd„«       Z#ˆ xZ$S )!Ú)InstructBlipVideoForConditionalGenerationrq   TFÚquery_tokensrA   c                 ó4  •— t         ‰| �  |«       t        |j                  «      | _        t        j                  t        j                  d|j                  |j                  j                  «      «      | _        t        |j                  «      | _        t        j                  |j                  j                  |j                   j                  «      | _        |j$                  r t'        j(                  |j                   «      }nt+        j(                  |j                   «      }|j,                  �%| j,                  j/                  |j,                  «       |j0                  �%| j0                  j/                  |j0                  «       || _        | j5                  «        y )Nr   )rG   rH   r
  rÚ   Úvision_modelr   rM   r;   r–   Únum_query_tokensÚqformer_configrI   rÛ  r»  Úqformerr“   Útext_configÚlanguage_projectionÚuse_decoder_only_language_modelr   Úfrom_configr   rì   ÚextendÚ_keep_in_fp32_modulesÚlanguage_modelr  )r0   rA   rç  rV   s      €r1   rH   z2InstructBlipVideoForConditionalGeneration.__init__  s'  ø€ Ü‰Ñ˜Ô ä8¸×9MÑ9MÓNˆÔäŸL™L¬¯©°Q¸×8OÑ8OÐQW×QfÑQf×QrÑQrÓ)sÓtˆÔÜ4°V×5JÑ5JÓKˆŒä#%§9¡9¨V×-BÑ-B×-NÑ-NÐPV×PbÑPb×PnÑPnÓ#oˆÔ à×1Ò1Ü1×=Ñ=¸f×>PÑ>PÓQ‰Nä2×>Ñ>¸v×?QÑ?QÓRˆNà×+Ñ+Ð7Ø×"Ñ"×)Ñ)¨.×*JÑ*JÔKà×/Ñ/Ð;Ø×&Ñ&×-Ñ-¨n×.RÑ.RÔSà,ˆÔð 	�‰Õr6   c                 ó6   — | j                   j                  «       S r¸   )rç  r  r5   s    r1   r  z>InstructBlipVideoForConditionalGeneration.get_input_embeddings%  s   € Ø×"Ñ"×7Ñ7Ó9Ð9r6   c                 ó:   — | j                   j                  |«       y r¸   )rç  rÁ  rÀ  s     r1   rÁ  z>InstructBlipVideoForConditionalGeneration.set_input_embeddings(  s   € Ø×Ñ×0Ñ0°Õ7r6   c                 ó:   — | j                   j                  |«       y r¸   )rç  Úset_output_embeddings)r0   Únew_embeddingss     r1   rë  z?InstructBlipVideoForConditionalGeneration.set_output_embeddings+  s   € Ø×Ñ×1Ñ1°.ÕAr6   r)   c                 ó6   — | j                   j                  «       S r¸   )rç  Úget_output_embeddingsr5   s    r1   rî  z?InstructBlipVideoForConditionalGeneration.get_output_embeddings.  s   € Ø×"Ñ"×8Ñ8Ó:Ð:r6   c                 ó6   — | j                   j                  «       S r¸   )rç  Úget_encoderr5   s    r1   rð  z5InstructBlipVideoForConditionalGeneration.get_encoder1  ó   € Ø×"Ñ"×.Ñ.Ó0Ð0r6   c                 ó6   — | j                   j                  «       S r¸   )rç  Úget_decoderr5   s    r1   ró  z5InstructBlipVideoForConditionalGeneration.get_decoder4  rñ  r6   c                 óî   — | j                   j                  s_| j                  j                  | j                  j                  _        | j                  j                  | j                  j                  _        y y r¸   )rA   rã  rç  Úsharedr  Úembed_tokensÚdecoderr5   s    r1   Ú_tie_weightsz6InstructBlipVideoForConditionalGeneration._tie_weights7  sT   € Ø�{‰{×:Ò:Ø7;×7JÑ7J×7QÑ7QˆD×Ñ×'Ñ'Ô4Ø7;×7JÑ7J×7QÑ7QˆD×Ñ×'Ñ'Õ4ð ;r6   c                 ó  — | j                   }t        |«      dkD  r:d|vr6t        j                  j	                  «       dkD  rt
        j                  d«       t        | j                  d«      rd| j                  j                  _
        yy)z­
        Some pre-processing hacks to make the model `accelerate` compatible. Check
        https://github.com/huggingface/transformers/pull/21707 for more details.
        r   rç  a   The `language_model` is not in the `hf_device_map` dictionary and you are running your script in a multi-GPU environment. this may lead to unexpected behavior when using `accelerate`. Please pass a `device_map` that contains `language_model` to remove this warning. Please refer to https://github.com/huggingface/blog/blob/main/accelerate-large-models.md for more details on creating a `device_map` for large models.Ú_hf_hookTN)Úhf_device_maprj  r;   ÚcudaÚdevice_countr   r¡  rá   rç  rú  Úio_same_device)r0   rû  s     r1   Ú_preprocess_acceleratez@InstructBlipVideoForConditionalGeneration._preprocess_accelerate<  sy   € ð
 ×*Ñ*ˆäˆ}Ó Ò!Ð&6¸mÑ&KÔPU×PZÑPZ×PgÑPgÓPiÐlmÒPmä�N‰NðMôô �4×&Ñ&¨
Ô3Ø:>ˆD×Ñ×(Ñ(Õ7ð 4r6   r  Úqformer_input_idsÚqformer_attention_maskr·  rÍ   Údecoder_input_idsÚdecoder_attention_maskr£   rõ   Úlabelsrö   rp   r¢  c                 ó~	  — |�|n| j                   j                  }|j                  \  }}}}}|j                  ||z  |||«      }| j	                  |||	||¬«      }|d   }t        j                  |j                  «       dd t
        j                  |j                  ¬«      }| j                  j                  |j                  d   dd«      }t        j                  |j                  «       dd t
        j                  |j                  ¬«      }|€t        j                  |«      }|j                  |d¬«      }|j                  |d¬«      }t        j                  ||gd¬«      }| j                  |||||||	|¬«      }|d   dd…d|j                  d«      …dd…f   }| j!                  |«      }|j                  || j                   j"                  |z  d«      }t        j                  |j                  «       dd t
        j                  |j                  ¬«      } | j$                  j'                  «       |«      }|€t        j                  |«      }t)        | j                   d	d«      �d|| j                   j*                  k(  j-                  d«      j/                  |«      }|j1                  «       j3                  |j                  «      ||<   nyt4        j7                  d
«       t        j                  ||j3                  |j                  «      gd¬«      }t        j                  ||j3                  |j                  «      gd¬«      }| j                   j8                  �r| j%                  ||||	||¬«      }|r|j:                  n|d   }d} |
��|
j3                  |j                  «      }
|dd…|
j                  d«       d…dd…f   }|ddd…dd…f   j=                  «       }!|
ddd…f   j=                  «       j3                  |j                  «      }"t?        d¬«      }# |#|!jA                  d| j                   jB                  jD                  «      |"jA                  d«      «      } n@| j%                  ||||||	||
|¬«	      }|r|jF                  n|d   } |r|j:                  n|d   }|s||||f}$| �| f|$z   S |$S tI        | ||||¬«      S )a¨  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the language modeling loss. Indices should be in `[-100, 0, ..., config.vocab_size -
            1]`. All labels set to `-100` are ignored (masked), the loss is only computed for labels in `[0, ...,
            config.vocab_size]`

        Returns:

        Examples:

        ```python
        >>> from transformers import InstructBlipVideoProcessor, InstructBlipVideoForConditionalGeneration
        >>> import torch
        >>> from huggingface_hub import hf_hub_download
        >>> import av
        >>> import numpy as np

        >>> def read_video_pyav(container, indices):
        ...     '''
        ...     Decode the video with PyAV decoder.
        ...     Args:
        ...         container (`av.container.input.InputContainer`): PyAV container.
        ...         indices (`List[int]`): List of frame indices to decode.
        ...     Returns:
        ...         result (np.ndarray): np array of decoded frames of shape (num_frames, height, width, 3).
        ...     '''
        ...     frames = []
        ...     container.seek(0)
        ...     start_index = indices[0]
        ...     end_index = indices[-1]
        ...     for i, frame in enumerate(container.decode(video=0)):
        ...         if i > end_index:
        ...             break
        ...         if i >= start_index and i in indices:
        ...             frames.append(frame)
        ...     return np.stack([x.to_ndarray(format="rgb24") for x in frames])

        >>> model = InstructBlipVideoForConditionalGeneration.from_pretrained("Salesforce/instructblip-vicuna-7b", device_map="auto")
        >>> processor = InstructBlipVideoProcessor.from_pretrained("Salesforce/instructblip-vicuna-7b")

        >>> file_path = hf_hub_download(
        ...       repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
        ... )
        >>> container = av.open(file_path)

        >>> # sample uniformly 4 frames from the videWhy is this video funny?o
        >>> total_frames = container.streams.video[0].frames
        >>> indices = np.arange(0, total_frames, total_frames / 4).astype(int)
        >>> clip = read_video_pyav(container, indices)

        >>> prompt = "What is happening in the video?"
        >>> inputs = processor(text=prompt, images=clip, return_tensors="pt").to(model.device)

        >>> outputs = model.generate(
        ...     **inputs,
        ...     do_sample=False,
        ...     num_beams=5,
        ...     max_length=256,
        ...     repetition_penalty=1.5,
        ...     length_penalty=1.0,
        ... )
        >>> generated_text = processor.batch_decode(outputs, skip_special_tokens=True)[0].strip()
        >>> print(generated_text)
        "A person is eating a bowl of pasta, and they are using a fork to eat it. The person is sitting at a table, and the plate of pasta is on the table in front"
        ```N)rq   r£   rõ   rö   rp   r   r[   r>  r`   r   )r·  rÍ   r¸  rG  rH  r£   rõ   rö   Úvideo_token_indexáK  Expanding inputs for video tokens in InstructBLIPVideo should be done in processing. Please follow instruction here (https://gist.github.com/zucchini-nlp/65f22892b054dc0d68228af56fbeaac2) to update your InstructBLIPVideo model. Using processors without these attributes in the config is deprecated and will throw an error in v4.47.)r  rÍ   r£   rõ   rö   r¢  .rØ   )Ú	reduction)	r  rÍ   r  r  r£   rõ   rö   r  r¢  )r$   r%   r&   r'   r(   )%rA   rþ   rb   re   rÝ  r;   rÍ  r]   rA  r?  rÛ  ry   Ú	ones_likeÚrepeat_interleaverj   rà  râ  rÞ  rç  r  r,   r  Ú	unsqueezeÚ	expand_asrw   rv   r   Úwarning_oncerã  r%   rŸ   r	   ri   rá  r¯  r$   r#   )%r0   rq   r   r  r·  rÍ   r  r  r£   rõ   r  rö   rp   r¢  rz   ÚframesÚchannelrX   rY   r&   Úimage_embedsÚimage_attention_maskrÛ  Úquery_attention_maskÚquery_outputsÚquery_outputÚlanguage_model_inputsÚlanguage_model_attention_maskr  Úspecial_image_maskr³   r%   r$   Úshift_logitsÚshift_labelsÚloss_fctr²   s%                                        r1   r   z1InstructBlipVideoForConditionalGeneration.forwardP  sÈ  € ðj &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð 6B×5GÑ5GÑ2ˆ
�F˜G V¨UØ#×+Ñ+¨J¸Ñ,?ÀÈ&ÐRWÓXˆà×*Ñ*Ø%Ø/Ø!5Ø#Ø%=ð +ó 
ˆð & aÑ(ˆô  %Ÿz™z¨,×*;Ñ*;Ó*=¸c¸rÐ*BÌ%Ï*É*Ð]i×]pÑ]pÔqÐð ×(Ñ(×/Ñ/°×0BÑ0BÀ1Ñ0EÀrÈ2ÓNˆÜ$Ÿz™z¨,×*;Ñ*;Ó*=¸c¸rÐ*BÌ%Ï*É*Ð]i×]pÑ]pÔqÐà!Ð)Ü%*§_¡_Ð5FÓ%GÐ"à-×?Ñ?ÀÈAÐ?ÓNÐØ!7×!IÑ!IÈ&ÐVWÐ!IÓ!XÐÜ!&§¡Ð,@ÐBXÐ+YÐ_`Ô!aÐØŸ™Ø'Ø1Ø%Ø".Ø#7Ø/Ø!5Ø#ð %ó 	
ˆð % QÑ'ªÐ+A¨\×->Ñ->¸qÓ-AÐ+AÂ1Ð(DÑEˆð !%× 8Ñ 8¸Ó FÐð !6× =Ñ =¸jÈ$Ï+É+×JfÑJfÐioÑJoÐqsÓ tÐÜ(-¯
©
Ø!×&Ñ&Ó(¨¨"Ð-´U·Z±ZÐH]×HdÑHdô)
Ð%ð C˜×+Ñ+×@Ñ@ÓBÀ9ÓMˆØÐ!Ü"Ÿ_™_¨YÓ7ˆNô �4—;‘;Ð 3°TÓ:ÐFØ"+¨t¯{©{×/LÑ/LÑ"L×!WÑ!WÐXZÓ![×!eÑ!eÐfsÓ!tÐØ0E×0MÑ0MÓ0O×0RÑ0RÐS`×SgÑSgÓ0hˆMÐ,Ò-ä×Ñðzôô
 "ŸI™IÐ'<¸m×>NÑ>NÐOd×OkÑOkÓ>lÐ&mÐstÔuˆMÜ"ŸY™YØ.°×0AÑ0AÐB_×BfÑBfÓ0gÐhÐnoôˆNð �;‰;×6Ó6Ø×)Ñ)Ø+Ø-Ø"3Ø%9Ø'Ø#ð *ó ˆGñ (3�W—^’^¸À¹
ˆFØˆDàÑ!ØŸ™ 6§=¡=Ó1�Ø¢ F§K¡K°£N ?Ñ#4²aÐ 7Ñ8�à% c¨3¨B¨3² kÑ2×=Ñ=Ó?�Ø% c¨1©2 g™×9Ñ9Ó;×>Ñ>¸v¿}¹}ÓM�ô ,°fÔ=�á × 1Ñ 1°"°d·k±k×6MÑ6M×6XÑ6XÓ YÐ[g×[lÑ[lÐmoÓ[pÓq‘à×)Ñ)Ø+Ø-Ø"3Ø'=Ø"3Ø%9Ø'ØØ#ð *ó 
ˆGñ $/�7—<’<°G¸A±JˆDÙ'2�W—^’^¸À¹
ˆFáØ˜n¨m¸WÐEˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEäCØØØ)Ø)Ø#*ô
ð 	
r6   c                 óR	  — t        | d«      r| j                  «        |j                  \  }}	}
}}|j                  ||	z  |
||«      }| j	                  |d|¬«      j
                  }t        j                  |j                  «       dd t        j                  |j                  ¬«      }| j                  j                  |j                  d   dd«      }t        j                  |j                  «       dd t        j                  |j                  ¬«      }|€t        j                  |«      }|j                  |	d¬«      }|j                  |	d¬«      }t        j                  ||gd	¬«      }| j!                  |||||d¬
«      }|j
                  dd…d|j                  d	«      …dd…f   }| j#                  |«      }|j                  || j$                  j&                  |	z  d«      }t        j                  |j                  «       dd t        j                  |j                  ¬«      }|€¯| j$                  j(                  j*                  g}t-        | j$                  dd«      �4| j$                  j.                  g| j$                  j&                  z  dz  |z   }t        j0                  |gt        j                  |j                  ¬«      }|j3                  |d	«      }|€t        j                  |«      } | j5                  «       |«      }t-        | j$                  dd«      �d|| j$                  j.                  k(  j7                  d«      j9                  |«      }|j;                  «       j=                  |j                  «      ||<   næt>        jA                  d«       t        j                  ||j=                  |j                  «      gd	¬«      }t        j                  ||j=                  |j                  «      gd	¬«      }| jB                  j$                  jD                  sM|jG                  dd«      |j                  d	   z   d	z
  |d<   |jG                  dd«      |j                  d	   z   |d<   ||dœ}| jB                  j$                  jD                  s||d<    | jB                  jH                  di |¤|¤Ž}|S )a  
        Overrides `generate` function to be able to use the model as a conditional generator.

        Args:
            pixel_values (`torch.FloatTensor` of shape (batch_size, num_channels, height, width) or
                (batch_size, num_frames, num_channels, height, width)): Input images or videos to be processed.
            qformer_input_ids (`torch.LongTensor` of shape (batch_size, sequence_length), *optional*):
                The sequence used as a prompt to be fed to the Q-Former module.
            qformer_attention_mask (`torch.LongTensor` of shape (batch_size, sequence_length), *optional*):
                Mask to avoid performing attention on padding token indices.
            input_ids (`torch.LongTensor` of shape (batch_size, sequence_length), *optional*):
                The sequence used as a prompt for the generation.
            attention_mask (`torch.LongTensor` of shape (batch_size, sequence_length), *optional*):
                Mask to avoid performing attention on padding token indices.
            interpolate_pos_encoding (`bool`, *optional*, defaults to `False`):
                Whether to interpolate the positional encoding of the image embeddings.

        Returns:
            captions (list): A list of strings of length batch_size * num_captions.
        rû  T)rö   rp   Nr[   r>  r   r`   r   )r·  rÍ   r¸  rG  rH  rö   r  r¥   r  Ú
max_lengthé   Ú
min_length)r  rÍ   r·  r>   )%rá   rÿ  rb   re   rÝ  rü   r;   rÍ  r]   rA  r?  rÛ  ry   r	  r
  rj   rà  râ  rA   rÞ  rá  Úbos_token_idr,   r  r›   Úrepeatr  r  r  rw   rv   r   r  rç  Úis_encoder_decoderÚgetÚgenerate)r0   rq   r   r  r·  rÍ   rp   Úgenerate_kwargsrz   r  r  rX   rY   r  r  rÛ  r  r  r  r  Úlanguage_attention_maskÚstart_tokensr  r  Úinputsr³   s                             r1   r#  z2InstructBlipVideoForConditionalGeneration.generate  sb  € ô> �4˜Ô)à×'Ñ'Ô)ð 6B×5GÑ5GÑ2ˆ
�F˜G V¨UØ#×+Ñ+¨J¸Ñ,?ÀÈ&ÐRWÓXˆà×(Ñ(ØØØ%=ð )ó 
÷ Ñ
ð	 	ô
  %Ÿz™z¨,×*;Ñ*;Ó*=¸c¸rÐ*BÌ%Ï*É*Ð]i×]pÑ]pÔqÐà×(Ñ(×/Ñ/°×0BÑ0BÀ1Ñ0EÀrÈ2ÓNˆÜ$Ÿz™z¨,×*;Ñ*;Ó*=¸c¸rÐ*BÌ%Ï*É*Ð]i×]pÑ]pÔqÐØ!Ð)Ü%*§_¡_Ð5FÓ%GÐ"à-×?Ñ?ÀÈAÐ?ÓNÐØ!7×!IÑ!IÈ&ÐVWÐ!IÓ!XÐÜ!&§¡Ð,@ÐBXÐ+YÐ_`Ô!aÐØŸ™Ø'Ø1Ø%Ø".Ø#7Øð %ó 
ˆð %×6Ñ6²qÐ:P¸L×<MÑ<MÈaÓ<PÐ:PÒRSÐ7SÑTˆà $× 8Ñ 8¸Ó FÐð !6× =Ñ =¸jÈ$Ï+É+×JfÑJfÐioÑJoÐqsÓ tÐÜ"'§*¡*Ø!×&Ñ&Ó(¨¨"Ð-´U·Z±ZÐH]×HdÑHdô#
Ðð ÐØ ŸK™K×3Ñ3×@Ñ@ÐAˆLÜ�t—{‘{Ð$7¸Ó>ÐJØ $§¡× =Ñ =Ð>ÀÇÁ×A]ÑA]Ñ]Ð`aÑaÐdpÑp�ÜŸ™ l ^¼5¿:¹:Èl×NaÑNaÔbˆIØ!×(Ñ(¨°QÓ7ˆIàÐ!Ü"Ÿ_™_¨YÓ7ˆNà3˜×1Ñ1Ó3°IÓ>ˆô �4—;‘;Ð 3°TÓ:ÐFØ"+¨t¯{©{×/LÑ/LÑ"L×!WÑ!WÐXZÓ![×!eÑ!eÐfsÓ!tÐØ0E×0MÑ0MÓ0O×0RÑ0RÐS`×SgÑSgÓ0hˆMÐ,Ò-ä×Ñðzôô
 "ŸI™IÐ'<¸m×>NÑ>NÐOd×OkÑOkÓ>lÐ&mÐstÔuˆMÜ"ŸY™YØ(¨.×*;Ñ*;Ð<S×<ZÑ<ZÓ*[Ð\ÐbcôˆNð ×&Ñ&×-Ñ-×@Ò@à#×'Ñ'¨°bÓ9Ð<Q×<WÑ<WÐXYÑ<ZÑZÐ]^Ñ^ð   Ñ-ð 1@×0CÑ0CÀLÐRSÓ0TÐWl×WrÑWrÐstÑWuÑ0u� Ñ-à#0ÀNÑSˆØ×"Ñ"×)Ñ)×<Ò<Ø"+ˆF�;Ñà.�$×%Ñ%×.Ñ.ÑK°ÐK¸?ÑKˆàˆr6   )NNNNNNNNNFNr  )%r7   r8   r9   r   ré   r  Ú_supports_cache_classÚ_supports_static_cacheÚ_supports_quantized_cacheræ  rH   r  rÁ  rë  r   ÚModulerî  rð  ró  rø  rÿ  r   Ú"INSTRUCTBLIPVIDEO_INPUTS_DOCSTRINGr   r#   r!   r;   r<   r   rØ  rƒ   r   r   r   Úno_gradr#  r„   r…   s   @r1   rÚ  rÚ  ù  st  ø„ ð +€LØ$€OØ ÐØ!ÐØ %ÐØ+Ð,ÐðÐ6õ ò4:ò8òBð; r§y¡yó ;ò1ò1òRò
?ñ( +Ð+MÓNÙØHÐWtôð >BØ15Ø59Ø8<Ø=AØ,0Ø/3Ø-1Ø&*Ø).Ø$(ñG
à×'Ñ'ðG
ð !×,Ñ,ðG
ð !)¨×)9Ñ)9Ñ :ð	G
ð
 ˜E×-Ñ-Ñ.ðG
ð ! ×!1Ñ!1Ñ2ðG
ð $ E×$4Ñ$4Ñ5ðG
ð !)¨×)9Ñ)9Ñ :ðG
ð $ D™>ðG
ð ' t™nðG
ð ˜×)Ñ)Ñ*ðG
ð ˜d‘^ðG
ð #'ðG
ð ˜D‘>ðG
ð 
ˆuÐJÐJÑ	KòG
óó OðG
ðR €U‡]�]ƒ_ð 9=Ø=AØ04Ø59Ø).ñqà×'Ñ'ðqð $ E×$4Ñ$4Ñ5ðqð !)¨×)9Ñ)9Ñ :ð	qð
 ˜E×,Ñ,Ñ-ðqð ! ×!1Ñ!1Ñ2ðqð #'ðqð 
×	Ñ	òqó ôqr6   rÚ  )BrC  Údataclassesr   Útypingr   r   r   r   r;   r   Útorch.nnr	   Úactivationsr   Ú
generationr   Úmodeling_outputsr   r   r   r   Úmodeling_utilsr   Úpytorch_utilsr   r   r   Úutilsr   r   r   r   r   r   Úautor   r   Úconfiguration_instructblipvideor   r    r!   Ú
get_loggerr7   r   r#   r+  r@   r‡   r¶   rÂ   rÒ   rî   r  r
  rÕ   rÖ   rd  rs  ry  r}  r™  rÔ   r»  Ú!INSTRUCTBLIPVIDEO_START_DOCSTRINGr,  rÚ  r>   r6   r1   ú<module>r;     sÝ  ðó, Ý !ß .Ó .ã Ý Ý %å !Ý )÷ó õ .ß lÑ l÷÷ ÷ ?÷ñ ð 
ˆ×	Ñ	˜HÓ	%€ð ô
¸;ó 
ó ð
ô@G¨¯	©	ô GôTN §¡ô Nôb˜2Ÿ9™9ô ô- B§I¡Iô -ô`#% ô #%ôLS
˜rŸy™yô S
ðl-Ð )ô$@Ð#Cô @ôFB°·±ô BôJ¨¯©ô ô.¨¯	©	ô .ôb¨2¯9©9ô ô R§Y¡Yô ôd B§I¡Iô dôN\
 b§i¡iô \
ô~0¨¯©ô 0ôfA
Ð$Dô A
ðH%Ð !ðB&Ð "ñJ ðð &ó	ôLÐ0PÐRaó Ló	ñLr6   