+
    œ°³jÔ  ã                   óZ  € ^ RI t^ RIt^ RI Ht ^ RIHt ^ RIt^ RIt^ RI	H
u Ht ^ RIHtH
t
 ^RIHt ^RIHt ^RIHtHtHt ^RIHt ^R	IHtHt ^R
IHt ^RIHtH t H!t! ^RI"H#t# ^RI$H%t% ^RI&H't' ]! 4       '       d   ^ RI(H)t) ]!! 4       '       d   ^ RI*H+t+ ^ RI,H-t- ] ! RR7      ] ! R R]4      4       4       t.RCR R llt/R R lt0R R lt1 ! R R]
Pd                  4      t3R R lt4R  R! lt5 ! R" R#]
Pd                  4      t6 ! R$ R%]
Pd                  4      t7 ! R& R']
Pd                  4      t8RDR( R) llt9 ! R* R+]
Pd                  4      t: ! R, R-]
Pd                  4      t; ! R. R/]
Pd                  4      t< ! R0 R1]
Pd                  4      t= ! R2 R3]
Pd                  4      t> ! R4 R5]4      t? ! R6 R7]
P€                  4      tA ! R8 R9]
Pd                  4      tB ! R: R;]
Pd                  4      tC ! R< R=]
Pd                  4      tD]  ! R> R?]4      4       tE] ! R@R7       ! RA RB]E4      4       tFR?RB.tGR# )Eé    N)ÚCallable)Ú	dataclass)ÚTensorÚnn)Úinitialization)ÚACT2FN)ÚModelOutputÚis_scipy_availableÚrequires_backends)ÚGradientCheckpointingLayer)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚis_accelerate_available)Úmerge_with_config_defaults)Úcapture_outputs©Ú
EomtConfig)Úlinear_sum_assignment)ÚPartialState)Úreducea˜  
    Class for outputs of [`EomtForUniversalSegmentationOutput`].

    This output can be directly passed to [`~EomtImageProcessor.post_process_semantic_segmentation`] or
    [`~EomtImageProcessor.post_process_instance_segmentation`] or
    [`~EomtImageProcessor.post_process_panoptic_segmentation`] to compute final segmentation maps. Please, see
    [`~EomtImageProcessor] for details regarding usage.
    )Úcustom_introc                   óL   a € ] tR t^3t o RtRtRtRtRtRt	Rt
RtV 3R ltRtV tR# )Ú"EomtForUniversalSegmentationOutputaÞ  
loss (`torch.Tensor`, *optional*):
    The computed loss, returned when labels are present.
class_queries_logits (`torch.FloatTensor`):
    A tensor of shape `(batch_size, num_queries, num_labels + 1)` representing the proposed classes for each
    query. Note the `+ 1` is needed because we incorporate the null class.
masks_queries_logits (`torch.FloatTensor`):
    A tensor of shape `(batch_size, num_queries, height, width)` representing the proposed masks for each
    query.
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
    Last hidden states (final feature map) of the last layer.
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
    Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each stage) of
    shape `(batch_size, sequence_length, hidden_size)`. Hidden-states all layers of the model.
attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
    Tuple of `tuple(torch.FloatTensor)` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
    sequence_length)`. Self and Cross Attentions weights from transformer decoder.
patch_offsets (`list[torch.Tensor]`, *optional*):
    list of tuples indicating the image index and start and end positions of patches for semantic segmentation.
Nc                óŒ  <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   S[S[ P                  ,          R,          ;R&   # )	é   NÚlossÚclass_queries_logitsÚmasks_queries_logitsÚlast_hidden_stateÚhidden_statesÚ
attentionsÚpatch_offsets)ÚtorchÚFloatTensorÚtupleÚlistr   )ÚformatÚ__classdict__s   "€Úg/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/eomt/modeling_eomt.pyÚ__annotate__Ú/EomtForUniversalSegmentationOutput.__annotate__3   sÈ   ø‡ ‚ ñB ×
Ñ
˜dÕ
"Ñ)ñC ñD  ×+Ñ+¨dÕ2Ñ9ñE ñF  ×+Ñ+¨dÕ2Ñ9ñG ñH ×(Ñ(¨4Õ/Ñ6ñI ñJ ™×*Ñ*Õ+¨dÕ2Ñ9ñK ñL ‘e×'Ñ'Õ(¨4Õ/Ñ6ñM ñN ™Ÿ™Õ%¨Õ,Ñ3òO ó    © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r    r!   r"   r#   r$   r%   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)r+   s   @r,   r   r   3   s:   ø‡ € ñð* &*€DØ59ÐØ59ÐØ26ÐØ59€MØ26€JØ/3€M÷O ƒ r/   r   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   Úinput_featuresÚpoint_coordinatesÚreturn©r&   r   )r*   s   "r,   r-   r-   ^   s0   € ÷ ñ Ü—L‘LðÜ5:·\±\ðä
‡\�\ñr/   c                óü   € VP                  4       ^8X  d   RpVP                  ^4      p\        P                  P                  P
                  ! V RV,          R,
          3/ VB pV'       d   VP                  ^4      pV# )að  
A wrapper around `torch.nn.functional.grid_sample` to support 3D point_coordinates tensors.

Args:
    input_features (`torch.Tensor` of shape (batch_size, channels, height, width)):
        A tensor that contains features map on a height * width grid
    point_coordinates (`torch.Tensor` of shape (batch_size, num_points, 2) or (batch_size, grid_height, grid_width,:
    2)):
        A tensor that contains [0, 1] * [0, 1] normalized point coordinates
    add_dim (`bool`):
        boolean value to keep track of added dimension

Returns:
    point_features (`torch.Tensor` of shape (batch_size, channels, num_points) or (batch_size, channels,
    height_grid, width_grid):
        A tensor that contains features for points in `point_coordinates`.
Tg       @ç      ð?)ÚdimÚ	unsqueezer&   r   Ú
functionalÚgrid_sampleÚsqueeze)r:   r;   Úadd_dimÚkwargsÚpoint_featuress   &&&, r,   Úsample_pointrH   ^   st   € ð( ×ÑÓ !Ô#ØˆØ-×7Ñ7¸Ó:Ðô —X‘X×(Ñ(×4Ò4°^ÀSÐK\ÕE\Ð_bÕEbÑmÐflÑm€NßØ'×/Ñ/°Ó2ˆàÐr/   c                ó<   € V ^8„  d   QhR\         R\         R\         /# ©r   ÚinputsÚlabelsr<   )r   )r*   s   "r,   r-   r-   ~   s!   € ÷ ñ ¤ð ´ð ¼6ñ r/   c                ó8  € V P                  4       P                  ^4      p ^\        P                  ! WP                  4      ,          pV P                  R4      R,          VP                  R4      R,          ,           p^V^,           V^,           ,          ,
          pV# )a   
A pair wise version of the dice loss, see `dice_loss` for usage.

Args:
    inputs (`torch.Tensor`):
        A tensor representing a mask
    labels (`torch.Tensor`):
        A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
        (0 for the negative class and 1 for the positive class).

Returns:
    `torch.Tensor`: The computed loss between each pairs.
éÿÿÿÿ©ºNNNN)NrP   )ÚsigmoidÚflattenr&   ÚmatmulÚTÚsum)rK   rL   Ú	numeratorÚdenominatorr   s   &&   r,   Úpair_wise_dice_lossrX   ~   sr   € ð �^‰^Ó×%Ñ% aÓ(€FØ”E—L’L ¯©Ó2Õ2€Ià—*‘*˜R“. Õ)¨F¯J©J°r«N¸7Õ,CÕC€KØ�	˜A• +°¥/Õ2Õ2€DØ€Kr/   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# rJ   r=   )r*   s   "r,   r-   r-   ”   s0   € ÷ ñ ´·±ð ÄuÇ|Á|ð ÔX]×XdÑXdñ r/   c                óˆ  € V P                   ^,          p\        P                  ! RR7      pV! V \        P                  ! V 4      4      pV! V \        P
                  ! V 4      4      p\        P                  ! WB,          VP                  4      p\        P                  ! WR,          ^V,
          P                  4      pWg,           pV# )aÂ  
A pair wise version of the cross entropy loss, see `sigmoid_cross_entropy_loss` for usage.

Args:
    inputs (`torch.Tensor`):
        A tensor representing a mask.
    labels (`torch.Tensor`):
        A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
        (0 for the negative class and 1 for the positive class).

Returns:
    loss (`torch.Tensor`): The computed loss between each pairs.
Únone©Ú	reduction)Úshaper   ÚBCEWithLogitsLossr&   Ú	ones_likeÚ
zeros_likerS   rT   )	rK   rL   Úheight_and_widthÚ	criterionÚcross_entropy_loss_posÚcross_entropy_loss_negÚloss_posÚloss_negr   s	   &&       r,   Ú$pair_wise_sigmoid_cross_entropy_lossrh   ”   s‘   € ð —|‘| A•Ðä×$Ò$¨vÔ6€IÙ& v¬u¯ª¸vÓ/FÓGÐÙ& v¬u×/?Ò/?ÀÓ/GÓHÐä�|Š|Ð2ÕEÀvÇxÁxÓP€HÜ�|Š|Ð2ÕEÈÈFÍ
Ç~Á~ÓV€HØÕ€DØ€Kr/   c                   ó€   a a€ ] tR t^°t oRtRV3R lV 3R lllt]P                  ! 4       V3R lR l4       tRt	Vt
V ;t# )ÚEomtHungarianMatcheraa  This class computes an assignment between the labels and the predictions of the network.

For efficiency reasons, the labels don't include the no_object. Because of this, in general, there are more
predictions than labels. In this case, we do a 1-to-1 matching of the best predictions, while the others are
un-matched (and thus treated as non-objects).
c                ó2   <€ V ^8„  d   QhRS[ RS[ RS[ RS[/# )r   Ú
cost_classÚ	cost_maskÚ	cost_diceÚ
num_points)ÚfloatÚint)r*   r+   s   "€r,   r-   Ú!EomtHungarianMatcher.__annotate__¸   s-   ø€ ÷ #ñ #Ùð#Ù27ð#ÙJOð#Ùcfñ#r/   c                ó”   <€ \         SV `  4        V^ 8X  d   V^ 8X  d   V^ 8X  d   \        R4      hW@n        Wn        W n        W0n        R# )aè  Creates the matcher

Params:
    cost_class (`float`, *optional*, defaults to 1.0):
        Relative weight of the classification error in the matching cost.
    cost_mask (`float`, *optional*,  defaults to 1.0):
        This is the relative weight of the focal loss of the binary mask in the matching cost.
    cost_dice (`float`, *optional*, defaults to 1.0):
        This is the relative weight of the dice loss of the binary mask in the matching cost.
    num_points (`int`, *optional*, defaults to 12544):
        No. of points to sample on which the mask loss will be calculated. The same set of K points are
        uniformly sampled for all prediction and ground truth masks to construct the cost matrix for bipartite
        matching.
zAll costs can't be 0N)ÚsuperÚ__init__Ú
ValueErrorro   rl   rm   rn   )Úselfrl   rm   rn   ro   Ú	__class__s   &&&&&€r,   ru   ÚEomtHungarianMatcher.__init__¸   sC   ø€ ô" 	‰ÑÔØ˜Œ?˜y¨Aœ~°)¸q´.ÜÐ3Ó4Ð4à$ŒØ$ŒØ"ŒØ"Žr/   c                ó¨   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[ P                  RS[S[S[,          ,          /# )r   r!   r    Úmask_labelsÚclass_labelsr<   )r&   r   r)   r(   )r*   r+   s   "€r,   r-   rr   Ó   s]   ø€ ÷ Dñ Dá#Ÿl™lðDñ $Ÿl™lðDñ —\‘\ð	Dñ
 —l‘lðDñ 
‰e‘F�mÕ	ñDr/   c           
     ó  € . pVP                   ^ ,          p\        V4       EFü  pW',          P                  R4      pW,          p	VRWG,          3,          ) p
W7,          P                  V	4      pVR,          pV	R,          p	\        P
                  ! ^V P                  ^V	P                  R7      pVP                  VP                   ^ ,          ^^4      p\        W½RR7      P                  ^4      pVP                  V	P                   ^ ,          ^^4      p\        WžRR7      P                  ^4      p	\        W›4      p\        W›4      pV P                  V,          V P                  V
,          ,           V P                  V,          ,           p\        P                   ! V\        P"                  ! R4      4      p\        P$                  ! V\        P"                  ! R	4      4      p\        P&                  ! V^ 4      p\)        VP+                  4       4      pVP-                  V4       EKÿ  	  V UUu. uFR  w  pp\        P.                  ! V\        P0                  R7      \        P.                  ! V\        P0                  R7      3NKT  	  pppV# u uppi )
aß  
Params:
    masks_queries_logits (`torch.Tensor`):
        A tensor of dim `batch_size, num_queries, num_labels` with the classification logits.
    class_queries_logits (`torch.Tensor`):
        A tensor of dim `batch_size, num_queries, height, width` with the predicted masks.
    class_labels (`torch.Tensor`):
        A tensor of dim `num_target_boxes` (where num_target_boxes is the number of ground-truth objects in the
        target) containing the class labels.
    mask_labels (`torch.Tensor`):
        A tensor of dim `num_target_boxes, height, width` containing the target masks.

Returns:
    matched_indices (`list[tuple[Tensor]]`): A list of size batch_size, containing tuples of (index_i, index_j)
    where:
        - index_i is the indices of the selected predictions (in order)
        - index_j is the indices of the corresponding selected labels (in order)
    For each batch element, it holds:
        len(index_i) = len(index_j) = min(num_queries, num_target_boxes).
rP   ©ÚdeviceF©Úalign_cornersg    _ B©ÚdtyperN   rO   g    _ Â)r^   ÚrangeÚsoftmaxÚtor&   Úrandro   r   ÚrepeatrH   rD   rh   rX   rm   rl   rn   ÚminimumÚtensorÚmaximumÚ
nan_to_numr   ÚcpuÚappendÚ	as_tensorÚint64)rw   r!   r    r{   r|   ÚindicesÚ
batch_sizeÚiÚ
pred_probsÚ	pred_maskrl   Útarget_maskr;   Útarget_coordinatesÚpred_coordinatesrm   rn   Úcost_matrixÚassigned_indicesÚjÚmatched_indicess   &&&&&                r,   ÚforwardÚEomtHungarianMatcher.forwardÒ   s  € ð8 *,ˆð *×/Ñ/°Õ2ˆ
Ü�z×"ˆAØ-Õ0×8Ñ8¸Ó<ˆJØ,Õ/ˆIð % Q¨­Ð%7Õ8Ð8ˆJØ%�.×+Ñ+¨IÓ6ˆKØ% gÕ.ˆKØ! 'Õ*ˆIô !&§
¢
¨1¨d¯o©o¸qÈ×IYÑIYÔ ZÐà!2×!9Ñ!9¸+×:KÑ:KÈAÕ:NÐPQÐSTÓ!UÐÜ& {ÐV[Ô\×dÑdÐefÓgˆKà0×7Ñ7¸	¿¹ÈÕ8JÈAÈqÓQÐÜ$ YÐPUÔV×^Ñ^Ð_`ÓaˆIô =¸YÓTˆIä+¨IÓCˆIàŸ.™.¨9Õ4°t·±ÈÕ7SÕSÐVZ×VdÑVdÐgpÕVpÕpˆKäŸ-š-¨´U·\²\À$Ó5GÓHˆKÜŸ-š-¨´U·\²\À%Ó5HÓIˆKÜ×*Ò*¨;¸Ó:ˆKä0EÀkÇoÁoÓFWÓ0XÐØ�N‰NÐ+×,ñ? #ñF hoô
ÙgnÑ_cÐ_`ÐbcŒU�_Š_˜Q¤e§k¡kÔ2´E·O²OÀAÌUÏ[É[Ô4YÓZÑgnð 	ñ 
ð Ðùó
s   È'AJ©rl   rn   rm   ro   )r?   r?   r?   i 1  )r1   r2   r3   r4   r5   ru   r&   Úno_gradr�   r7   r8   Ú__classcell__©rx   r+   s   @@r,   rj   rj   °   s6   ù‡ € ñ÷#õ #ð4 ‡]‚]ƒ_÷Dó ÷Dð Dr/   rj   c                óH   € V ^8„  d   QhR\         R\         R\        R\         /# ©r   rK   rL   Ú	num_masksr<   )r   rq   )r*   s   "r,   r-   r-     s(   € ÷ ñ ”fð ¤fð ¼ð Äñ r/   c                ó8  € V P                  4       P                  ^4      p^W1,          P                  R4      ,          pVP                  R4      VP                  R4      ,           p^V^,           V^,           ,          ,
          pVP                  4       V,          pV# )aø  
Compute the DICE loss, similar to generalized IOU for masks as follows:

$$ \mathcal{L}_{\text{dice}(x, y) = 1 - \frac{2 * x \cap y }{x \cup y + 1}} $$

In practice, since `labels` is a binary mask, (only 0s and 1s), dice can be computed as follow

$$ \mathcal{L}_{\text{dice}(x, y) = 1 - \frac{2 * x * y }{x + y + 1}} $$

Args:
    inputs (`torch.Tensor`):
        A tensor representing a mask.
    labels (`torch.Tensor`):
        A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
        (0 for the negative class and 1 for the positive class).
    num_masks (`int`):
        The number of masks present in the current batch, used for normalization.

Returns:
    `torch.Tensor`: The computed loss.
rN   )rQ   rR   rU   )rK   rL   r¥   ÚprobsrV   rW   r   s   &&&    r,   Ú	dice_lossr¨     sx   € ð, �N‰NÓ×$Ñ$ QÓ'€EØ�U•^×(Ñ(¨Ó,Õ,€IØ—)‘)˜B“- &§*¡*¨R£.Õ0€KØ�	˜A• +°¥/Õ2Õ2€DØ�8‰8‹:˜	Õ!€DØ€Kr/   c                ó„   € V ^8„  d   QhR\         P                  R\         P                  R\        R\         P                  /# r¤   )r&   r   rq   )r*   s   "r,   r-   r-   8  s8   € ÷ ñ ¤u§|¡|ð ¼U¿\¹\ð ÔVYð Ô^c×^jÑ^jñ r/   c                ó�   € \         P                  ! RR7      pV! W4      pVP                  ^4      P                  4       V,          pV# )aX  
Args:
    inputs (`torch.Tensor`):
        A float tensor of arbitrary shape.
    labels (`torch.Tensor`):
        A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
        (0 for the negative class and 1 for the positive class).

Returns:
    loss (`torch.Tensor`): The computed loss.
r[   r\   )r   r_   ÚmeanrU   )rK   rL   r¥   rc   Úcross_entropy_lossr   s   &&&   r,   Úsigmoid_cross_entropy_lossr­   8  sB   € ô ×$Ò$¨vÔ6€IÙ" 6Ó2Ðà×"Ñ" 1Ó%×)Ñ)Ó+¨iÕ7€DØ€Kr/   c                   óÞ   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltV3R lR ltV3R lR	 ltV3R
 lR ltR t	R t
V3R lR ltV3R lR ltRV3R lR lltV3R lR ltRtVtV ;t# )ÚEomtLossiL  c                ó<   <€ V ^8„  d   QhRS[ RS[S[S[3,          /# )r   ÚconfigÚweight_dict)r   ÚdictÚstrrp   )r*   r+   s   "€r,   r-   ÚEomtLoss.__annotate__M  s$   ø€ ÷ !
ñ !
™zð !
¹¹SÁ%¸ZÕ8Hñ !
r/   c                ó  <€ \         SV `  4        \        V R.4       VP                  V n        W n        VP
                  V n        \        P                  ! V P                  ^,           4      pV P                  VR&   \        P                  ! V4      V n        VP                  V n        VP                  V n        VP                  V n        \!        VP"                  VP$                  VP&                  V P                  R7      V n        R# )a   
The Eomt Loss. The loss is computed very similar to DETR. The process happens in two steps: 1) we
compute hungarian assignment between ground truth masks and the outputs of the model 2) we supervise each pair
of matched ground-truth / prediction (supervise class and mask)

Args:
    config (`EomtConfig`):
        The configuration for Eomt model also containing loss calculation specific parameters.
    weight_dict (`dict[str, float]`):
        A dictionary of weights to be applied to the different losses.
ÚscipyrŸ   NrN   )rt   ru   r   Ú
num_labelsr²   Úno_object_weightÚeos_coefr&   Úonesr   ÚBufferÚempty_weightÚtrain_num_pointsro   Úoversample_ratioÚimportance_sample_ratiorj   Úclass_weightÚdice_weightÚmask_weightÚmatcher)rw   r±   r²   r½   rx   s   &&& €r,   ru   ÚEomtLoss.__init__M  sÍ   ø€ ô 	‰ÑÔÜ˜$  	Ô*Ø ×+Ñ+ˆŒØ&Ôð ×/Ñ/ˆŒÜ—z’z $§/¡/°AÕ"5Ó6ˆØŸ=™=ˆ�RÑÜŸIšI lÓ3ˆÔð !×1Ñ1ˆŒØ &× 7Ñ 7ˆÔØ'-×'EÑ'EˆÔ$ä+Ø×*Ñ*Ø×(Ñ(Ø×(Ñ(Ø—‘ô	
ˆŽr/   c                óV   <€ V ^8„  d   QhRS[ S[ S[,          ,          RS[ S[,          /# )r   Úsizesr<   )r)   rq   )r*   r+   s   "€r,   r-   rµ   p  s'   ø€ ÷ ñ ¡$¡t©C¥y¥/ð ±d¹3µiñ r/   c                óˆ   € V^ ,          pVR,           F+  p\        V4       F  w  rE\        W$,          V4      W$&   K  	  K-  	  V# )r   :é   NN)Ú	enumerateÚmax)rw   rÇ   ÚmaxesÚsublistÚindexÚitems   &&    r,   Ú_max_by_axisÚEomtLoss._max_by_axisp  sC   € Ø�a•ˆØ˜R—y�yˆGÜ(¨Ö1‘�Ü" 5¥<°Ó6�“ó  2ñ !ð ˆr/   c                óL   <€ V ^8„  d   QhRS[ S[,          RS[S[S[3,          /# )r   Útensorsr<   )r)   r   r(   )r*   r+   s   "€r,   r-   rµ   x  s)   ø€ ÷ -ñ -±4¹µ<ð -ÁEÉ&ÑRXÈ.ÕDYñ -r/   c                ó¦  € T P                  V Uu. uF  p\        VP                  4      NK  	  up4      p\        V4      .V,           pVw  rVrxV^ ,          P                  p	V^ ,          P
                  p
\        P                  ! WIV
R7      p\        P                  ! WWV3\        P                  V
R7      p\        WV4       F‡  w  r-pVRVP                  ^ ,          1RVP                  ^,          1RVP                  ^,          13,          P                  V4       RVRVP                  ^,          1RVP                  ^,          13&   K‰  	  W¼3# u upi )r   ©rƒ   r   NF)rÐ   r)   r^   Úlenrƒ   r   r&   Úzerosr»   ÚboolÚzipÚcopy_)rw   rÓ   rŠ   Úmax_sizeÚbatch_shaper’   Ú_ÚheightÚwidthrƒ   r   Úpadded_tensorsÚpadding_masksÚpadded_tensorÚpadding_masks   &&             r,   Ú_pad_images_to_max_in_batchÚ$EomtLoss._pad_images_to_max_in_batchx  s'  € à×$Ñ$ÁwÓ%OÁw¸V¤d¨6¯<©<Ö&8ÁwÑ%OÓPˆä˜7“|�n xÕ/ˆØ'2Ñ$ˆ
�vØ˜•
× Ñ ˆØ˜•×"Ñ"ˆÜŸš [ÀfÔMˆÜŸ
š
 J¸Ð#>ÄeÇjÁjÐY_Ô`ˆä36°wÐP]Ö3^Ñ/ˆF <ØÐ+˜FŸL™L¨�OÐ+Ð->¨v¯|©|¸A­Ð->Ð@QÀ&Ç,Á,ÈqÅ/Ð@QÐQÕR×XÑXÐY_Ô`ØAFˆLÐ*˜6Ÿ<™<¨�?Ð*Ð,=¨f¯l©l¸1­oÐ,=Ð=Ó>ñ 4_ð Ð,Ð,ùò &Ps   �Ec          
      ó|   <€ V ^8„  d   QhRS[ RS[S[ ,          RS[S[P                  ,          RS[S[S[ 3,          /# )r   r    r|   r‘   r<   )r   r)   r(   ÚnpÚarrayr³   r´   )r*   r+   s   "€r,   r-   rµ   ‰  sF   ø€ ÷  ñ  Ù$*ð Ù:>¹v½,ð ÙQVÑWY×W_ÑW_ÕQ`ð á	‰c‘6ˆkÕ	ñ r/   c           	     óÔ  € TpVP                   w  rVp\        P                  ! V P                  R7      pV P	                  V4      p	\
        P                  ! \        W#4       U
UUu. uF  w  p
w  r{W«,          NK  	  uppp
4      p\
        P                  ! WV3V P                  \
        P                  VP                  R7      pWÍV	&   VP                  ^^4      pV! Wí4      pRV/pV# u uppp
i )a-  Compute the losses related to the labels using cross entropy.

Args:
    class_queries_logits (`torch.Tensor`):
        A tensor of shape `batch_size, num_queries, num_labels`
    class_labels (`list[torch.Tensor]`):
        List of class labels of shape `(labels)`.
    indices (`tuple[np.array])`:
        The indices computed by the Hungarian matcher.

Returns:
    `dict[str, Tensor]`: A dict of `torch.Tensor` containing the following key:
    - **loss_cross_entropy** -- The loss computed using cross entropy on the predicted and ground truth labels.
)Úweight)Ú
fill_valuerƒ   r   Úloss_cross_entropy)r^   r   ÚCrossEntropyLossr½   Ú$_get_predictions_permutation_indicesr&   ÚcatrÙ   Úfullr¸   r�   r   Ú	transpose)rw   r    r|   r‘   Úpred_logitsr’   Únum_queriesrÝ   rc   ÚidxÚtargetr›   Útarget_classes_oÚtarget_classesÚpred_logits_transposedÚloss_ceÚlossess   &&&&             r,   Úloss_labelsÚEomtLoss.loss_labels‰  sÙ   € ð" +ˆØ%0×%6Ñ%6Ñ"ˆ
 Ü×'Ò'¨t×/@Ñ/@ÔAˆ	Ø×7Ñ7¸Ó@ˆÜ Ÿ9š9Ü-0°Ô-GÕHÑ-G™>˜6¡6 AˆV�YˆYÑ-GÓHó
Ðô ŸšØÐ%°$·/±/ÌÏÉÐ]h×]oÑ]oô
ˆð /�sÑà!,×!6Ñ!6°q¸!Ó!<ÐÙÐ2ÓCˆØ&¨Ð0ˆØˆùô Is   Á#C#c                ó¾   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          RS[S[P
                  ,          RS[RS[S[S[ P                  3,          /# )r   r!   r{   r‘   r¥   r<   )	r&   r   r)   r(   rç   rè   rq   r³   r´   )r*   r+   s   "€r,   r-   rµ   «  s`   ø€ ÷ <ñ <á#Ÿl™lð<ñ ™%Ÿ,™,Õ'ð<ñ ‘r—x‘x•ð	<ñ
 ð<ñ 
‰c‘5—<‘<ÐÕ	 ñ<r/   c           	     óB  a € S P                  V4      pS P                  V4      pW,          pS P                  V4      w  r‰W†,          pVR,          pVR,          p\        P                  ! 4       ;_uu_ 4        S P                  VV 3R lS P                  S P                  S P                  4      p
\        WŠRR7      P                  ^4      pRRR4       \        VX
RR7      P                  ^4      pR\        VXV4      R\        WËV4      /p??V#   + '       g   i     LL; i)a$  Compute the losses related to the masks using sigmoid_cross_entropy_loss and dice loss.

Args:
    masks_queries_logits (`torch.Tensor`):
        A tensor of shape `(batch_size, num_queries, height, width)`.
    mask_labels (`torch.Tensor`):
        List of mask labels of shape `(labels, height, width)`.
    indices (`tuple[np.array])`:
        The indices computed by the Hungarian matcher.
    num_masks (`int)`:
        The number of masks, used for normalization.

Returns:
    losses (`dict[str, Tensor]`): A dict of `torch.Tensor` containing two keys:
    - **loss_mask** -- The loss computed using sigmoid cross entropy loss on the predicted and ground truth.
      masks.
    - **loss_dice** -- The loss computed using dice loss on the predicted on the predicted and ground truth,
      masks.
Nc                 ó&   <€ SP                  V 4      # ©N)Úcalculate_uncertainty)Úlogitsrw   s   &€r,   Ú<lambda>Ú%EomtLoss.loss_masks.<locals>.<lambda>Ö  s   ø€ ˜t×9Ñ9¸&ÔAr/   Fr€   Ú	loss_maskÚ	loss_dicerO   )rî   Ú _get_targets_permutation_indicesrä   r&   r    Úsample_points_using_uncertaintyro   r¿   rÀ   rH   rD   r­   r¨   )rw   r!   r{   r‘   r¥   Úsrc_idxÚtgt_idxÚ
pred_masksÚtarget_masksrÝ   r;   Úpoint_labelsÚpoint_logitsrú   s   f&&&&         r,   Ú
loss_masksÚEomtLoss.loss_masks«  s  ø€ ð4 ×;Ñ;¸GÓDˆØ×7Ñ7¸Ó@ˆà)Õ2ˆ
ð ×:Ñ:¸;ÓG‰ˆØ#Õ,ˆð   Õ(ˆ
Ø# GÕ,ˆô �]Š]�_�_Ø $× DÑ DØÜAØ—‘Ø×%Ñ%Ø×,Ñ,ó!Ðô (¨ÐW\Ô]×eÑeÐfgÓhˆL÷ ô $ JÐ0AÐQVÔW×_Ñ_Ð`aÓbˆð Ô3°LÀ,ÐPYÓZØœ <¸yÓIð
ˆð
 ØØˆ÷) �_ús   Á6ADÄD	c                ó  € \         P                  ! \        V4       UUUu. uF  w  pw  r4\         P                  ! W24      NK   	  uppp4      p\         P                  ! V UUu. uF  w  r4VNK	  	  upp4      pWV3# u upppi u uppi r   ©r&   rï   rÊ   Ú	full_like)rw   r‘   r“   ÚsrcrÝ   Úbatch_indicesÚpredictions_indicess   &&     r,   rî   Ú-EomtLoss._get_predictions_permutation_indicesé  sh   € äŸ	š	ÌiÐX_ÔN`Õ"aÑN`¹{¸qÁ(À3¤5§?¢?°3Ö#:ÑN`Ó"aÓbˆÜ#Ÿiši¹WÔ(E¹W±°#«¹WÒ(EÓFÐØÐ1Ð1ùô #bùÛ(Eó    $A:Á"B
c                ó  € \         P                  ! \        V4       UUUu. uF  w  pw  r4\         P                  ! WB4      NK   	  uppp4      p\         P                  ! V UUu. uF  w  r4VNK	  	  upp4      pWV3# u upppi u uppi r   r  )rw   r‘   r“   rÝ   Útgtr  Útarget_indicess   &&     r,   r  Ú)EomtLoss._get_targets_permutation_indicesï  sg   € äŸ	š	ÌiÐX_ÔN`Õ"aÑN`¹{¸qÁ(À1¤5§?¢?°3Ö#:ÑN`Ó"aÓbˆÜŸš¹Ô#@¹©H¨Q£C¹Ò#@ÓAˆØÐ,Ð,ùô #bùÛ#@r  c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   r  r<   r=   )r*   r+   s   "€r,   r-   rµ   õ  s#   ø€ ÷ "ñ "©E¯L©Lð "¹U¿\¹\ñ "r/   c                ó4   € \         P                  ! V4      ) pV# )a2  
In Eomt paper, uncertainty is estimated as L1 distance between 0.0 and the logit prediction in 'logits'
for the foreground class in `classes`.

Args:
    logits (`torch.Tensor`):
    A tensor of shape (R, 1, ...) for class-specific or class-agnostic, where R is the total number of predicted masks in all images and C is:
    the number of foreground classes. The values are logits.

Returns:
    scores (`torch.Tensor`): A tensor of shape (R, 1, ...) that contains uncertainty scores with the most
    uncertain locations having the highest uncertainty score.
)r&   Úabs)rw   r  Úuncertainty_scoress   && r,   r  ÚEomtLoss.calculate_uncertaintyõ  s   € ô  %Ÿyšy¨Ó0Ð1ÐØ!Ð!r/   c          
      ó`   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[RS[ P                  /# )r   r  ro   r¿   rÀ   r<   )r&   r   rq   rp   )r*   r+   s   "€r,   r-   rµ     sE   ø€ ÷ 5!ñ 5!á—‘ð5!ñ ð	5!ñ
 ð5!ñ "'ð5!ñ 
�‰ñ5!r/   c           
     óÄ  € VP                   ^ ,          p\        W4,          4      p\        P                  ! Wg^VP                  R7      p\        WRR7      p	V! V	4      p
\        WS,          4      pW;,
          p\        P                  ! V
R,          V^R7      ^,          pV\        P                  ! V\        P                  VP                  R7      ,          pWÞR	,          ,          pVP                  R
^4      VP                  R
4      R3,          P                  Wk^4      pV^ 8”  d<   \        P                  ! V\        P                  ! Wl^VP                  R7      .^R7      pV# )að  
This function is meant for sampling points in [0, 1] * [0, 1] coordinate space based on their uncertainty. The
uncertainty is calculated for each point using the passed `uncertainty function` that takes points logit
prediction as input.

Args:
    logits (`float`):
        Logit predictions for P points.
    uncertainty_function:
        A function that takes logit predictions for P points and returns their uncertainties.
    num_points (`int`):
        The number of points P to sample.
    oversample_ratio (`int`):
        Oversampling parameter.
    importance_sample_ratio (`float`):
        Ratio of points that are sampled via importance sampling.

Returns:
    point_coordinates (`torch.Tensor`):
        Coordinates for P sampled points.
r~   Fr€   rP   )Úkr@   rÕ   ©r@   )rP   r   rP   rO   rN   )r^   rq   r&   r‡   r   rH   ÚtopkÚarangeÚlongÚviewrï   )rw   r  Úuncertainty_functionro   r¿   rÀ   Ú	num_boxesÚnum_points_sampledr;   r  Úpoint_uncertaintiesÚnum_uncertain_pointsÚnum_random_pointsrô   Úshifts   &&&&&&         r,   r  Ú(EomtLoss.sample_points_using_uncertainty  s)  € ð< —L‘L •Oˆ	Ü  Õ!>Ó?Ðô "ŸJšJ yÀaÐPV×P]ÑP]Ô^Ðä# FÈUÔSˆá2°<Ó@Ðä"Ð#:Õ#GÓHÐØ&Õ=Ðä�jŠjÐ,¨WÕ5Ð9MÐSTÔUÐVWÕXˆØ"¤U§\¢\°)Ä5Ç:Á:ÐV\×VcÑVcÔ%dÕdˆØ�W�~ÕˆØ-×2Ñ2°2°qÓ9¸#¿(¹(À2»,È¸/ÕJ×OÑOÐPYÐqrÓsÐà˜qÔ Ü %§	¢	Ø"¤E§J¢J¨yÈQÐW]×WdÑWdÔ$eÐfØô!Ðð !Ð r/   c                ó  <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[S[ P                  ,          RS[S[ P                  ,          RS[S[S[ P                  3,          R,          RS[S[S[ P                  3,          /# )r   r!   r    r{   r|   Úauxiliary_predictionsNr<   )r&   r   r)   r³   r´   )r*   r+   s   "€r,   r-   rµ   =  s‚   ø€ ÷ 5ñ 5á#Ÿl™lð5ñ $Ÿl™lð5ñ ™%Ÿ,™,Õ'ð	5ñ
 ™5Ÿ<™<Õ(ð5ñ  $¡C©¯©Ð$5Õ6¸Õ=ð5ñ 
‰c‘5—<‘<ÐÕ	 ñ5r/   c                ó´  € V P                  WW44      pV P                  WD^ ,          P                  R7      p/ V P                  WWg4      CV P	                  W$V4      CpVes   \        V4       Fc  w  ršV
R,          pV
R,          pV P                  WW44      pVP                  4        UUu/ uF  w  rÍV RV	 2VbK  	  pppVP                  V4       Ke  	  V# u uppi )aú  
This performs the loss computation.

Args:
    masks_queries_logits (`torch.Tensor`):
        A tensor of shape `(batch_size, num_queries, height, width)`.
    class_queries_logits (`torch.Tensor`):
        A tensor of shape `(batch_size, num_queries, num_labels)`.
    mask_labels (`torch.Tensor`):
        List of mask labels of shape `(labels, height, width)`.
    class_labels (`list[torch.Tensor]`):
        List of class labels of shape `(labels)`.
    auxiliary_predictions (`dict[str, torch.Tensor]`, *optional*):
        if `use_auxiliary_loss` was set to `true` in [`EomtConfig`], then it contains the logits from
        the inner layers of the EomtMaskedAttentionDecoder.

Returns:
    losses (`dict[str, Tensor]`): A dict of `torch.Tensor` containing three keys:
    - **loss_cross_entropy** -- The loss computed using cross entropy on the predicted and ground truth labels.
    - **loss_mask** -- The loss computed using sigmoid cross_entropy loss on the predicted and ground truth
      masks.
    - **loss_dice** -- The loss computed using dice loss on the predicted on the predicted and ground truth
      masks.
    if `use_auxiliary_loss` was set to `true` in [`EomtConfig`], the dictionary contains additional
    losses for each auxiliary predictions.
r~   r!   r    rÝ   )	rÄ   Úget_num_masksr   r  rû   rÊ   r�   ÚitemsÚupdate)rw   r!   r    r{   r|   r3  r‘   r¥   rú   rô   Úaux_outputsÚ	loss_dictÚkeyÚvalues   &&&&&&        r,   r�   ÚEomtLoss.forward=  sñ   € ðH —,‘,Ð3È;Óeˆà×&Ñ& |È½O×<RÑ<RÐ&ÓSˆ	ð%
Ø�o‰oÐ2ÀÓTð%
à×ÑÐ3À7ÓKð%
ˆð
 !Ò,Ü$-Ð.CÖ$DÑ �Ø'2Ð3IÕ'JÐ$Ø'2Ð3IÕ'JÐ$Ø ŸL™LÐ)=ÐU`Óo�	ØENÇ_Á_ÔEVÔWÑEV±z°s ˜u A c U˜^¨UÒ2ÑEV�	ÑWØ—‘˜iÖ(ñ %Eð ˆùó Xs   Â'Cc                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# )r   r|   r   r<   )r&   r   r   )r*   r+   s   "€r,   r-   rµ   t  s1   ø€ ÷ ñ ©%¯,©,ð ÁÇÁð ÑQV×Q]ÑQ]ñ r/   c                ó@  € \        R V 4       4      p\        P                  ! V\        P                  VR7      p^p\	        4       '       d5   \
        P                  / 8w  d    \        V4      p\        4       P                  p\        P                  ! W4,          ^R7      pV# )z[
Computes the average number of target masks across the batch, for normalization purposes.
c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir   )rÖ   )Ú.0Úclassess   & r,   Ú	<genexpr>Ú)EomtLoss.get_num_masks.<locals>.<genexpr>x  s   é € ÐA±L¨œ˜GŸ˜³Lùs   ‚rÕ   )Úmin)
rU   r&   r�   rp   r   r   Ú_shared_stater   Únum_processesÚclamp)rw   r|   r   r¥   Ú
world_sizes   &&&  r,   r5  ÚEomtLoss.get_num_maskst  sv   € ô ÑA±LÓAÓAˆ	Ü—O’O I´U·[±[ÈÔPˆ	Øˆ
Ü"×$Ò$Ü×)Ñ)¨RÔ/Ü" 9Ó-�	Ü)›^×9Ñ9�
ä—K’K 	Õ 6¸AÔ>ˆ	ØÐr/   )r½   rº   rÀ   rÄ   r¸   ro   r¿   r²   r   )r1   r2   r3   r4   ru   rÐ   rä   rû   r  rî   r  r  r  r�   r5  r7   r8   r¡   r¢   s   @@r,   r¯   r¯   L  ss   ù‡ € ÷!
ó !
÷Fð ÷-ð -÷" ð  ÷D<ð <ò|2ò-÷"ð "÷"5!ð 5!÷n5ò 5÷n÷ ð r/   r¯   c                   óH   a a€ ] tR tRt oRtV 3R ltV3R lR ltRtVtV ;t	# )ÚEomtPatchEmbeddingsi„  zÜ
This class turns `pixel_values` of shape `(batch_size, num_channels, height, width)` into the initial
`hidden_states` (patch embeddings) of shape `(batch_size, seq_length, hidden_size)` to be consumed by a
Transformer.
c                ó  <€ \         SV `  4        VP                  VP                  r2VP                  VP
                  rT\        V\        P                  P                  4      '       d   TMW"3p\        V\        P                  P                  4      '       d   TMW33pV^,          V^,          ,          V^ ,          V^ ,          ,          ,          pW n        W0n        W@n        W`n
        \        P                  ! WEW3R7      V n        R# )rÉ   ©Úkernel_sizeÚstrideN)rt   ru   Ú
image_sizeÚ
patch_sizeÚnum_channelsÚhidden_sizeÚ
isinstanceÚcollectionsÚabcÚIterableÚnum_patchesr   ÚConv2dÚ
projection)rw   r±   rP  rQ  rR  rS  rX  rx   s   &&     €r,   ru   ÚEomtPatchEmbeddings.__init__‹  sÃ   ø€ Ü‰ÑÔØ!'×!2Ñ!2°F×4EÑ4E�JØ$*×$7Ñ$7¸×9KÑ9K�kä#-¨j¼+¿/¹/×:RÑ:R×#SÒ#S‘ZÐZdÐYqˆ
Ü#-¨j¼+¿/¹/×:RÑ:R×#SÒ#S‘ZÐZdÐYqˆ
Ø! !•}¨
°1­Õ5¸*ÀQ½-È:ÐVWÍ=Õ:XÕYˆØ$ŒØ$ŒØ(ÔØ&ÔäŸ)š) LÈ:ÔiˆŽr/   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   Úpixel_valuesr<   r=   )r*   r+   s   "€r,   r-   Ú EomtPatchEmbeddings.__annotate__š  s#   ø€ ÷ ñ ¡E§L¡Lð ±U·\±\ñ r/   c                óä   € VP                   ^,          pW P                  8w  d   \        RV P                   RV R24      hV P                  V4      P	                  ^4      P                  ^^4      pV# )rÉ   zoMake sure that the channel dimension of the pixel values match with the one set in the configuration. Expected z	 but got Ú.)r^   rR  rv   rZ  rR   rñ   )rw   r^  rR  Ú
embeddingss   &&  r,   r�   ÚEomtPatchEmbeddings.forwardš  sx   € Ø#×)Ñ)¨!Õ,ˆØ×,Ñ,Ô,ÜðØ!×.Ñ.Ð/¨y¸¸ÀaðIóð ð —_‘_ \Ó2×:Ñ:¸1Ó=×GÑGÈÈ1ÓMˆ
ØÐr/   )rP  rR  rX  rQ  rZ  ©
r1   r2   r3   r4   r5   ru   r�   r7   r8   r¡   r¢   s   @@r,   rK  rK  „  s   ù‡ € ñõj÷÷ ð r/   rK  c                   óT   a a€ ] tR tRt oRtV3R lV 3R lltV3R lR ltRtVtV ;t	# )ÚEomtEmbeddingsi¥  zE
Construct the CLS token, mask token, position and patch embeddings.
c                ó$   <€ V ^8„  d   QhRS[ RR/# ©r   r±   r<   Nr   )r*   r+   s   "€r,   r-   ÚEomtEmbeddings.__annotate__ª  s   ø€ ÷ cñ c™zð c¨dñ cr/   c                óâ  <€ \         SV `  4        Wn        VP                  V n        \        P
                  ! \        P                  ! ^^VP                  4      4      V n	        \        P
                  ! \        P                  ! ^VP                  VP                  4      4      V n        \        V4      V n        V P                  P                  p\        P                   ! VP"                  4      V n        ^VP                  ,           V n        \        P(                  ! W!P                  4      V n        \        P,                  ! \        P.                  ! V4      P1                  R4      RR7      V n        R# )rÉ   F)Ú
persistentN©rÉ   rN   )rt   ru   r±   rQ  r   Ú	Parameterr&   ÚrandnrS  Ú	cls_tokenr×   Únum_register_tokensÚregister_tokensrK  Úpatch_embeddingsrX  ÚDropoutÚhidden_dropout_probÚdropoutÚnum_prefix_tokensÚ	EmbeddingÚposition_embeddingsr¼   r'  ÚexpandÚposition_ids)rw   r±   rX  rx   s   && €r,   ru   ÚEomtEmbeddings.__init__ª  sô   ø€ Ü‰ÑÔàŒØ ×+Ñ+ˆŒäŸš¤e§k¢k°!°Q¸×8JÑ8JÓ&KÓLˆŒÜ!Ÿ|š|¬E¯KªK¸¸6×;UÑ;UÐW]×WiÑWiÓ,jÓkˆÔä 3°FÓ ;ˆÔØ×+Ñ+×7Ñ7ˆÜ—z’z &×"<Ñ"<Ó=ˆŒØ!" V×%?Ñ%?Õ!?ˆÔÜ#%§<¢<°×=OÑ=OÓ#PˆÔ ÜŸIšI¤e§l¢l°;Ó&?×&FÑ&FÀwÓ&OÐ\aÔbˆÖr/   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r]  r=   )r*   r+   s   "€r,   r-   ri  º  s#   ø€ ÷ ñ ¡E§L¡Lð ±U·\±\ñ r/   c                óÊ  € VP                   w  p  pV P                  P                  P                  P                  pV P                  VP                  VR 7      4      pV P                  P                  VRR4      pV P                  P                  VRR4      pWPP                  V P                  4      ,           p\        P                  ! WgV.^R7      pV P                  V4      pV# )r‚   r%  rN   )r^   rr  rZ  rê   rƒ   r†   ro  ry  rq  rx  rz  r&   rï   ru  )rw   r^  r’   rÝ   Útarget_dtyperb  Ú
cls_tokensrq  s   &&      r,   r�   ÚEomtEmbeddings.forwardº  sÂ   € Ø*×0Ñ0Ñˆ
�A�q˜!Ø×,Ñ,×7Ñ7×>Ñ>×DÑDˆØ×*Ñ*¨<¯?©?À¨?Ó+NÓOˆ
à—^‘^×*Ñ*¨:°r¸2Ó>ˆ
Ø×.Ñ.×5Ñ5°jÀ"ÀbÓIˆà×":Ñ":¸4×;LÑ;LÓ"MÕMˆ
Ü—Y’Y 
¸ZÐHÈaÔPˆ
à—\‘\ *Ó-ˆ
àÐr/   )	ro  r±   ru  rv  rr  rQ  rx  rz  rq  rd  r¢   s   @@r,   rf  rf  ¥  s%   ù‡ € ñ÷có c÷ ÷ ð r/   rf  c                óÞ   € V ^8„  d   QhR\         P                  R\        P                  R\        P                  R\        P                  R\        P                  R,          R\        R\        /# )	r   ÚmoduleÚqueryr:  r;  Úattention_maskNÚscalingru  )r   ÚModuler&   r   rp   )r*   s   "r,   r-   r-   Ê  sg   € ÷ %ñ %Ü�I‰Ið%ä�<‰<ð%ô 
�‰ð%ô �<‰<ð	%ô
 —L‘L 4Õ'ð%ô ð%ô ñ%r/   c                 óÎ  € \         P                  ! WP                  RR4      4      V,          pVe	   W„,           p\        P                  P                  VR\         P                  R7      P                  VP                  4      p\        P                  P                  W†V P                  R7      p\         P                  ! Wƒ4      p	V	P                  ^^4      P                  4       p	W˜3# )rÉ   )r@   rƒ   )ÚpÚtrainingrN   éþÿÿÿ)r&   rS   rñ   r   rB   r…   Úfloat32r†   rƒ   ru  r‰  Ú
contiguous)
r‚  rƒ  r:  r;  r„  r…  ru  rF   Úattn_weightsÚattn_outputs
   &&&&&&&,  r,   Úeager_attention_forwardr�  Ê  s°   € ô —<’< §}¡}°R¸Ó'<Ó=ÀÕG€LØÒ!Ø#Õ4ˆä—=‘=×(Ñ(¨¸2ÄUÇ]Á]Ð(ÓS×VÑVÐW\×WbÑWbÓc€LÜ—=‘=×(Ñ(¨È6Ï?É?Ð(Ó[€Lä—,’,˜|Ó3€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€KàÐ$Ð$r/   c                   óL   a a€ ] tR tRt oRtV 3R ltRV3R lR lltRtVtV ;t	# )ÚEomtAttentioniá  z=Multi-headed attention from 'Attention Is All You Need' paperc                ó<  <€ \         SV `  4        Wn        VP                  V n        VP
                  V n        V P                  V P                  ,          V n        V P                  V P                  ,          V P                  8w  d'   \        R V P                   RV P                   R24      hV P                  R,          V n	        VP                  V n        RV n        \        P                  ! V P                  V P                  4      V n        \        P                  ! V P                  V P                  4      V n        \        P                  ! V P                  V P                  4      V n        \        P                  ! V P                  V P                  4      V n        R# )z;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).FNg      à¿)rt   ru   r±   rS  Ú	embed_dimÚnum_attention_headsÚ	num_headsÚhead_dimrv   ÚscaleÚattention_dropoutru  Ú	is_causalr   ÚLinearÚk_projÚv_projÚq_projÚout_proj©rw   r±   rx   s   &&€r,   ru   ÚEomtAttention.__init__ä  s  ø€ Ü‰ÑÔØŒØ×+Ñ+ˆŒØ×3Ñ3ˆŒØŸ™¨$¯.©.Õ8ˆŒØ�=‰=˜4Ÿ>™>Õ)¨T¯^©^Ô;ÜØMÈdÏnÉnÐM]ð ^Ø—N‘NÐ# 2ð'óð ð —]‘] DÕ(ˆŒ
Ø×/Ñ/ˆŒØˆŒä—i’i §¡°·±Ó?ˆŒÜ—i’i §¡°·±Ó?ˆŒÜ—i’i §¡°·±Ó?ˆŒÜŸ	š	 $§.¡.°$·.±.ÓAˆŽr/   c          	      ó®   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[S[ P                  S[ P                  R,          3,          /# ©r   r#   r„  Nr<   )r&   r   r(   )r*   r+   s   "€r,   r-   ÚEomtAttention.__annotate__ø  sM   ø€ ÷ !)ñ !)á—|‘|ð!)ñ Ÿ™ tÕ+ð!)ñ
 
‰u�|‰|™UŸ\™\¨DÕ0Ð0Õ	1ñ!)r/   c                óº  € VP                   RR p. VORNV P                  N5pV P                  V4      P                  V4      P	                  ^^4      pV P                  V4      P                  V4      P	                  ^^4      pV P                  V4      P                  V4      P	                  ^^4      p\        P                  ! V P                  P                  \        4      p	T	! T TTTTV P                  V P                  V P                  '       g   RMV P                  R7      w  r«V
P                   ! . VORN5!  P#                  4       p
V P%                  V
4      p
W«3# )z#Input shape: Batch x Time x ChannelNç        )r™  r…  ru  rN   )r^   r–  r�  r)  rñ   r›  rœ  r   Úget_interfacer±   Ú_attn_implementationr�  r™  r—  r‰  ru  ÚreshaperŒ  rž  )rw   r#   r„  rF   Úinput_shapeÚhidden_shapeÚqueriesÚkeysÚvaluesÚattention_interfacerŽ  r�  s   &&&,        r,   r�   ÚEomtAttention.forwardø  s8  € ð $×)Ñ)¨#¨2Ð.ˆà8˜Ð8 bÐ8¨$¯-©-Ñ8ˆØ—+‘+˜mÓ,×1Ñ1°,Ó?×IÑIÈ!ÈQÓOˆØ�{‰{˜=Ó)×.Ñ.¨|Ó<×FÑFÀqÈ!ÓLˆØ—‘˜]Ó+×0Ñ0°Ó>×HÑHÈÈAÓNˆä(?×(MÒ(MØ�K‰K×,Ñ,Ô.Eó)
Ðñ %8ØØØØØØ—n‘nØ—J‘JØ#Ÿ}Ÿ}˜}‘C°$·,±,ô	%
Ñ!ˆð "×)Ò)Ð;¨;Ð;¸Ó;×FÑFÓHˆØ—m‘m KÓ0ˆàÐ(Ð(r/   )r±   ru  r“  r–  r™  r›  r•  rž  r�  r—  rœ  r   rd  r¢   s   @@r,   r‘  r‘  á  s   ù‡ € ÙGõB÷(!)÷ !)ò !)r/   r‘  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚEomtLayerScalei  c                ó   <€ V ^8„  d   QhRR/# ©r   r<   Nr0   )r*   r+   s   "€r,   r-   ÚEomtLayerScale.__annotate__  s   ø€ ÷ ^ñ ^ $ñ ^r/   c                ó¸   <€ \         SV `  4        \        P                  ! VP                  \
        P                  ! VP                  4      ,          4      V n        R # r   )	rt   ru   r   rm  Úlayerscale_valuer&   r»   rS  Úlambda1rŸ  s   &&€r,   ru   ÚEomtLayerScale.__init__  s8   ø€ Ü‰ÑÔÜ—|’| F×$;Ñ$;¼e¿jºjÈ×I[ÑI[Ó>\Õ$\Ó]ˆŽr/   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   Úhidden_stater<   r=   )r*   r+   s   "€r,   r-   r´  !  s#   ø€ ÷ +ñ +¡E§L¡Lð +±U·\±\ñ +r/   c                ó&   € WP                   ,          # r   ©r·  ©rw   r»  s   &&r,   r�   ÚEomtLayerScale.forward!  s   € ØŸl™lÕ*Ð*r/   r½  ©	r1   r2   r3   r4   ru   r�   r7   r8   r¡   r¢   s   @@r,   r±  r±    s    ù‡ € ÷^ó ^÷+÷ +ð +r/   r±  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚEomtMLPi%  c                ó   <€ V ^8„  d   QhRR/# r³  r0   )r*   r+   s   "€r,   r-   ÚEomtMLP.__annotate__&  s   ø€ ÷ 	Gñ 	G $ñ 	Gr/   c                óš  <€ \         SV `  4        VP                  ;r#\        VP                  VP                  ,          4      p\
        P                  ! W$R R7      V n        \        VP                  \        4      '       d   \        VP                  ,          V n        MVP                  V n        \
        P                  ! WCR R7      V n        R# )T©ÚbiasN)rt   ru   rS  rq   Ú	mlp_ratior   rš  Úfc1rT  Ú
hidden_actr´   r   Ú
activationÚfc2©rw   r±   Úin_featuresÚout_featuresÚhidden_featuresrx   s   &&   €r,   ru   ÚEomtMLP.__init__&  s�   ø€ Ü‰ÑÔØ%+×%7Ñ%7Ð7ˆÜ˜f×0Ñ0°6×3CÑ3CÕCÓDˆÜ—9’9˜[ÀÔEˆŒÜ�f×'Ñ'¬×-Ò-Ü$ V×%6Ñ%6Õ7ˆD�Oà$×/Ñ/ˆDŒOÜ—9’9˜_ÀÔFˆŽr/   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rº  r=   )r*   r+   s   "€r,   r-   rÄ  1  ó#   ø€ ÷ ñ ¡E§L¡Lð ±U·\±\ñ r/   c                ól   € V P                  V4      pV P                  V4      pV P                  V4      pV# r   )rÉ  rË  rÌ  r¾  s   &&r,   r�   ÚEomtMLP.forward1  s2   € Ø—x‘x Ó-ˆØ—‘ |Ó4ˆØ—x‘x Ó-ˆØÐr/   )rË  rÉ  rÌ  rÀ  r¢   s   @@r,   rÂ  rÂ  %  s    ù‡ € ÷	Gó 	G÷÷ ð r/   rÂ  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚEomtSwiGLUFFNi8  c                ó   <€ V ^8„  d   QhRR/# r³  r0   )r*   r+   s   "€r,   r-   ÚEomtSwiGLUFFN.__annotate__9  s   ø€ ÷ Oñ O $ñ Or/   c                ój  <€ \         SV `  4        VP                  ;r#\        VP                  VP                  ,          4      p\        V^,          ^,          4      ^,           ^,          ^,          p\
        P                  ! V^V,          RR7      V n        \
        P                  ! WCRR7      V n        R# )r   TrÆ  N)	rt   ru   rS  rq   rÈ  r   rš  Ú
weights_inÚweights_outrÍ  s   &&   €r,   ru   ÚEomtSwiGLUFFN.__init__9  s†   ø€ Ü‰ÑÔØ%+×%7Ñ%7Ð7ˆÜ˜f×0Ñ0°6×3CÑ3CÕCÓDˆÜ˜°Õ2°QÕ6Ó7¸!Õ;ÀÕAÀAÕEˆäŸ)š) K°°_Õ1DÈ4ÔPˆŒÜŸ9š9 _ÈÔNˆÖr/   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rº  r=   )r*   r+   s   "€r,   r-   rÙ  B  s#   ø€ ÷ (ñ (¡E§L¡Lð (±U·\±\ñ (r/   c                ó¼   € V P                  V4      pVP                  ^RR7      w  r#\        P                  P	                  V4      V,          pV P                  V4      # )r   r%  rN   )rÛ  Úchunkr   rB   ÚsilurÜ  )rw   r»  Úx1Úx2Úhiddens   &&   r,   r�   ÚEomtSwiGLUFFN.forwardB  sQ   € Ø—‘ |Ó4ˆØ×#Ñ# A¨2Ð#Ó.‰ˆÜ—‘×#Ñ# BÓ'¨"Õ,ˆØ×Ñ Ó'Ð'r/   )rÛ  rÜ  rÀ  r¢   s   @@r,   r×  r×  8  s    ù‡ € ÷Oó O÷(÷ (ð (r/   r×  c                   ój   a a€ ] tR tRt oRtR
V3R lV 3R llltV3R lR ltV3R lR ltR	tVt	V ;t
# )ÚEomtDropPathiI  zÃStochastic depth (DropPath) per sample, for residual blocks.

Identity when ``drop_prob`` is 0 or outside training. See `Deep Networks with Stochastic Depth
<https://arxiv.org/abs/1603.09382>`_.
c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   Ú	drop_probr<   N)rp   )r*   r+   s   "€r,   r-   ÚEomtDropPath.__annotate__P  s   ø€ ÷ #ñ #¡%ð #°$ñ #r/   c                ó0   <€ \         SV `  4        Wn        R # r   )rt   ru   ré  )rw   ré  rx   s   &&€r,   ru   ÚEomtDropPath.__init__P  s   ø€ Ü‰ÑÔØ"Žr/   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   r#   r<   r=   )r*   r+   s   "€r,   r-   rê  T  s#   ø€ ÷ <ñ <¡U§\¡\ð <±e·l±lñ <r/   c                ó˜  € V P                   R 8X  g   V P                  '       g   V# ^V P                   ,
          pVP                  ^ ,          3RVP                  ^,
          ,          ,           p\        P
                  ! W1P                  VP                  R7      p\        P                  ! WB,           4      pVP                  V4      V,          # )r¥  rÕ   )rÉ   )
ré  r‰  r^   Úndimr&   r‡   rƒ   r   ÚfloorÚdiv)rw   r#   Ú	keep_probr^   Úrandom_tensors   &&   r,   r�   ÚEomtDropPath.forwardT  s•   € Ø�>‰>˜SÔ ¨¯¯¨Ø Ð Ø˜Ÿ™Õ&ˆ	Ø×$Ñ$ QÕ'Ð)¨D°M×4FÑ4FÈÕ4JÕ,KÕKˆÜŸ
š
 5×0CÑ0CÈM×L`ÑL`ÔaˆÜŸš MÕ$=Ó>ˆØ× Ñ  Ó+¨mÕ;Ð;r/   c                ó    <€ V ^8„  d   QhRS[ /# )r   r<   )r´   )r*   r+   s   "€r,   r-   rê  ]  s   ø€ ÷ %ñ %™Cñ %r/   c                ó    € R V P                    2# )zp=©ré  ©rw   s   &r,   Ú
extra_reprÚEomtDropPath.extra_repr]  s   € Ø�D—N‘NÐ#Ð$Ð$r/   rø  ©r¥  )r1   r2   r3   r4   r5   ru   r�   rú  r7   r8   r¡   r¢   s   @@r,   rç  rç  I  s-   ù‡ € ñ÷#õ #÷<ð <÷%÷ %ð %r/   rç  c                   óX   a a€ ] tR tRt oRtV3R lV 3R lltRV3R lR lltRtVtV ;t	# )	Ú	EomtLayeria  zCThis corresponds to the Block class in the original implementation.c                ó$   <€ V ^8„  d   QhRS[ RR/# rh  r   )r*   r+   s   "€r,   r-   ÚEomtLayer.__annotate__d  s   ø€ ÷ 3ñ 3™zð 3¨dñ 3r/   c                ó.  <€ \         SV `  4        \        P                  ! VP                  VP
                  R 7      V n        \        V4      V n        \        V4      V n
        VP                  R8”  d   \        VP                  4      M\        P                  ! 4       V n        \        P                  ! VP                  VP
                  R 7      V n        VP                   '       d   \#        V4      V n        M\'        V4      V n        \        V4      V n        R# )©Úepsr¥  N)rt   ru   r   Ú	LayerNormrS  Úlayer_norm_epsÚnorm1r‘  Ú	attentionr±  Úlayer_scale1Údrop_path_raterç  ÚIdentityÚ	drop_pathÚnorm2Úuse_swiglu_ffnr×  ÚmlprÂ  Úlayer_scale2rŸ  s   &&€r,   ru   ÚEomtLayer.__init__d  s¿   ø€ Ü‰ÑÔä—\’\ &×"4Ñ"4¸&×:OÑ:OÔPˆŒ
Ü& vÓ.ˆŒÜ*¨6Ó2ˆÔØ@F×@UÑ@UÐX[Ô@[œ f×&;Ñ&;Ô<Ôac×alÒalÓanˆŒä—\’\ &×"4Ñ"4¸&×:OÑ:OÔPˆŒ
à× × Ð Ü$ VÓ,ˆD�Hä˜v“ˆDŒHÜ*¨6Ó2ˆÖr/   c                óv   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[ P                  /# r¢  r=   )r*   r+   s   "€r,   r-   r   t  s:   ø€ ÷ ñ á—|‘|ðñ Ÿ™ tÕ+ðñ 
�‰ñ	r/   c                ó6  € V P                  V4      pV P                  W24      w  rEV P                  V4      pV P                  V4      V,           pV P	                  V4      pV P                  V4      pV P                  V4      pV P                  V4      V,           pV# r   )r  r  r  r  r  r  r  )rw   r#   r„  Úhidden_states_normÚself_attention_outputrÝ   Úlayer_outputs   &&&    r,   r�   ÚEomtLayer.forwardt  s—   € ð
 "ŸZ™Z¨Ó6ÐØ#'§>¡>Ð2DÓ#UÑ ÐØ $× 1Ñ 1Ð2GÓ HÐð Ÿ™Ð'<Ó=ÀÕMˆð —z‘z -Ó0ˆØ—x‘x Ó-ˆØ×(Ñ(¨Ó6ˆð —~‘~ lÓ3°mÕCˆàÐr/   )r  r  r  r  r  r  r  r   rd  r¢   s   @@r,   rþ  rþ  a  s!   ù‡ € ÙM÷3ó 3÷ ÷ ò r/   rþ  c                   óH   a a€ ] tR tRt oRV 3R lltV3R lR ltRtVtV ;t# )ÚEomtLayerNorm2di‹  c                ó*   <€ \         SV `  WVR 7       R# ))r  Úelementwise_affineN)rt   ru   )rw   rR  r  Úaffinerx   s   &&&&€r,   ru   ÚEomtLayerNorm2d.__init__Œ  s   ø€ Ü‰Ñ˜À6ÐÖJr/   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rº  r=   )r*   r+   s   "€r,   r-   ÚEomtLayerNorm2d.__annotate__�  rÓ  r/   c                óØ   € VP                  ^ ^^^4      p\        P                  ! WP                  V P                  V P
                  V P                  4      pVP                  ^ ^^^4      pV# )r   )ÚpermuteÚFÚ
layer_normÚnormalized_shaperê   rÇ  r  r¾  s   &&r,   r�   ÚEomtLayerNorm2d.forward�  s`   € Ø#×+Ñ+¨A¨q°!°QÓ7ˆÜ—|’| L×2GÑ2GÈÏÉÐVZ×V_ÑV_Ðae×aiÑaiÓjˆØ#×+Ñ+¨A¨q°!°QÓ7ˆØÐr/   r0   )g�íµ ÷Æ°>TrÀ  r¢   s   @@r,   r  r  ‹  s   ù‡ € ÷K÷÷ ð r/   r  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚEomtScaleLayeri–  c                ó    <€ V ^8„  d   QhRS[ /# ©r   r±   r   )r*   r+   s   "€r,   r-   ÚEomtScaleLayer.__annotate__—  s   ø€ ÷ 8ñ 8™zñ 8r/   c           	     ó  <€ \         SV `  4        VP                  p\        P                  ! W"^^R7      V n        \        VP                  ,          V n        \        P                  ! VV^^VRR7      V n
        \        V4      V n        R# )r   rM  F)rN  ÚpaddingÚgroupsrÇ  N)rt   ru   rS  r   ÚConvTranspose2dÚconv1r   rÊ  rË  rY  Úconv2r  Úlayernorm2d©rw   r±   rS  rx   s   && €r,   ru   ÚEomtScaleLayer.__init__—  ss   ø€ Ü‰ÑÔØ×(Ñ(ˆÜ×'Ò'¨ÈaÐXYÔZˆŒ
Ü  ×!2Ñ!2Õ3ˆŒÜ—Y’YØØØØØØô
ˆŒ
ô +¨;Ó7ˆÖr/   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rî  r=   )r*   r+   s   "€r,   r-   r)  §  s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r/   c                óŽ   € V P                  V4      pV P                  V4      pV P                  V4      pV P                  V4      pV# r   )r.  rË  r/  r0  ©rw   r#   s   &&r,   r�   ÚEomtScaleLayer.forward§  sB   € ØŸ
™
 =Ó1ˆØŸ™¨Ó6ˆØŸ
™
 =Ó1ˆØ×(Ñ(¨Ó7ˆØÐr/   )rË  r.  r/  r0  rÀ  r¢   s   @@r,   r&  r&  –  s   ù‡ € ÷8ó 8÷ ÷ ð r/   r&  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚEomtScaleBlocki¯  c                ó    <€ V ^8„  d   QhRS[ /# r(  r   )r*   r+   s   "€r,   r-   ÚEomtScaleBlock.__annotate__°  s   ø€ ÷ ]ñ ]™zñ ]r/   c                óÞ   <€ \         SV `  4        VP                  V n        \        P
                  ! \        V P                  4       Uu. uF  p\        V4      NK  	  up4      V n        R # u upi r   )	rt   ru   Únum_upscale_blocksÚ
num_blocksr   Ú
ModuleListr„   r&  Úblock©rw   r±   rÝ   rx   s   && €r,   ru   ÚEomtScaleBlock.__init__°  sM   ø€ Ü‰ÑÔØ ×3Ñ3ˆŒÜ—]’]ÄEÈ$Ï/É/ÔDZÓ#[ÑDZ¸q¤N°6Ö$:ÑDZÑ#[Ó\ˆŽ
ùÒ#[s   ÁA*c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rî  r=   )r*   r+   s   "€r,   r-   r:  µ  s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r/   c                ó<   € V P                    F  pV! V4      pK  	  V# r   )r?  )rw   r#   r?  s   && r,   r�   ÚEomtScaleBlock.forwardµ  s    € Ø—Z”ZˆEÙ! -Ó0ŠMñ  àÐr/   )r?  r=  rÀ  r¢   s   @@r,   r8  r8  ¯  s    ù‡ € ÷]ó ]÷
÷ ð r/   r8  c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚEomtMaskHeadi»  c                ó    <€ V ^8„  d   QhRS[ /# r(  r   )r*   r+   s   "€r,   r-   ÚEomtMaskHead.__annotate__¼  s   ø€ ÷ 4ñ 4™zñ 4r/   c                ó  <€ \         SV `  4        VP                  p\        P                  ! W"4      V n        \        P                  ! W"4      V n        \        P                  ! W"4      V n        \        VP                  ,          V n
        R # r   )rt   ru   rS  r   rš  rÉ  rÌ  Úfc3r   rÊ  rË  r1  s   && €r,   ru   ÚEomtMaskHead.__init__¼  s[   ø€ Ü‰ÑÔà×(Ñ(ˆÜ—9’9˜[Ó6ˆŒÜ—9’9˜[Ó6ˆŒÜ—9’9˜[Ó6ˆŒÜ  ×!2Ñ!2Õ3ˆŽr/   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rî  r=   )r*   r+   s   "€r,   r-   rH  Å  s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r/   c                ó¨   € V P                  V P                  V4      4      pV P                  V P                  V4      4      pV P                  V4      pV# r   ©rË  rÉ  rÌ  rJ  r5  s   &&r,   r�   ÚEomtMaskHead.forwardÅ  sD   € ØŸ™¨¯©°Ó(?Ó@ˆØŸ™¨¯©°Ó(?Ó@ˆØŸ™ Ó/ˆØÐr/   rN  rÀ  r¢   s   @@r,   rF  rF  »  s   ù‡ € ÷4ó 4÷÷ ð r/   rF  c                   óœ   a a€ ] tR tRt oRtRtRtRtRtR.t	Rt
R]R	]/t]P                  ! 4       V3R
 lV 3R ll4       tV3R ltRtVtV ;t# )ÚEomtPreTrainedModeliÌ  zz
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
Úeomtr^  Frþ  Tr#   r$   c                ó8   <€ V ^8„  d   QhRS[ P                  RR/# )r   r‚  r<   N)r   r†  )r*   r+   s   "€r,   r-   Ú EomtPreTrainedModel.__annotate__à  s   ø€ ÷ /ñ /¡B§I¡Ið /°$ñ /r/   c                ó*  <€ \         SV `  V4       V P                  P                  p\	        V\
        P                  \
        P                  \
        P                  34      '       dÇ   \        P                  ! VP                  \        P                  ! ^4      R7       VP                  e�   \        P
                  P                  P!                  VP                  4      w  r4V^ 8”  d   ^\        P                  ! V4      ,          M^ p\        P"                  ! VP                  V) V4       R# R# \	        V\
        P$                  4      '       d†   \        P&                  ! VP                  R^R7       VP(                  eS   \+        VP                  RR4      '       g4   \        P,                  ! VP                  VP(                  ,          4       R# R# R# \	        V\.        4      '       dL   \1        VR4      '       d8   \        P2                  ! VP4                  V P                  P6                  4       R# R# \	        V\8        4      '       d¥   \        P:                  ! VP<                  RVR7       \        P,                  ! VP>                  4       \        P@                  ! VPB                  \        PD                  ! VPB                  PF                  R,          4      PI                  R	4      4       R# \	        V\J        4      '       dZ   \        PL                  ! VPN                  ^,           4      pVPP                  VR&   \        P@                  ! VPR                  V4       R# \	        V\T        4      '       d#   \        PV                  ! VPX                  4       R# R# )
é   )ÚaNr¥  )r«   ÚstdÚ_is_hf_initializedFr·  rN   rl  )-rt   Ú_init_weightsr±   Úinitializer_rangerT  r   rš  rY  r-  ÚinitÚkaiming_uniform_rê   ÚmathÚsqrtrÇ  r&   Ú_calculate_fan_in_and_fan_outÚuniform_rw  Únormal_Úpadding_idxÚgetattrÚzeros_r±  ÚhasattrÚ	constant_r·  r¶  rf  Útrunc_normal_ro  rq  rÚ   rz  r'  r^   ry  r¯   r»   r¸   rº   r½   ÚEomtForUniversalSegmentationÚones_Úattn_mask_probs)rw   r‚  rX  Úfan_inrÝ   Úboundr½   rx   s   &&     €r,   rZ  Ú!EomtPreTrainedModel._init_weightsß  s@  ø€ ä‰Ñ˜fÔ%Ø�k‰k×+Ñ+ˆÜ�fœrŸy™y¬"¯)©)´R×5GÑ5GÐH×IÒIÜ×!Ò! &§-¡-´4·9²9¸Q³<Õ@Ø�{‰{Ò&Ü!ŸH™HŸM™M×GÑGÈÏÉÓV‘	�Ø17¸!´˜œDŸIšI fÓ-Ö-À�Ü—’˜fŸk™k¨E¨6°5Ö9ñ 'ô ˜¤§¡×-Ò-Ü�LŠL˜Ÿ™¨S°aÕ8à×!Ñ!Ò-´g¸f¿m¹mÐMaÐch×6iÒ6iÜ—’˜FŸM™M¨&×*<Ñ*<Õ=Ö>ñ 7jÑ-ä˜¤×/Ò/Ü�v˜y×)Ò)Ü—’˜vŸ~™~¨t¯{©{×/KÑ/KÖLñ *ä˜¤×/Ò/Ü×Ò˜v×/Ñ/°c¸sÕCÜ�KŠK˜×.Ñ.Ô/Ü�JŠJ�v×*Ñ*¬E¯LªL¸×9LÑ9L×9RÑ9RÐSUÕ9VÓ,W×,^Ñ,^Ð_fÓ,gÖhÜ˜¤×)Ò)Ü Ÿ:š: f×&7Ñ&7¸!Õ&;Ó<ˆLØ%Ÿ™ˆL˜ÑÜ�JŠJ�v×*Ñ*¨LÖ9Ü˜Ô <×=Ò=Ü�JŠJ�v×-Ñ-Ö.ñ >r/   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # r(  r   )r*   r+   s   "€r,   r-   rT  Ì  s   ø‡ ‚ ñ Ñò r/   r0   )Úimage)r1   r2   r3   r4   r5   Úbase_model_prefixÚmain_input_nameÚinput_modalitiesÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_supports_sdparþ  r‘  Ú_can_record_outputsr&   r    rZ  r6   r7   r8   r¡   r¢   s   @@r,   rQ  rQ  Ì  sh   ù‡ € ñð ÐØ$€OØ!ÐØ&+Ð#Ø$˜ÐØ€Nà˜Ø�mðÐð
 ‡]‚]ƒ_÷/ò /ó ð/÷) … r/   rQ  zV
    The EoMT Model with head on top for instance/semantic/panoptic segmentation.
    c                   óÂ   a a€ ] tR tRt oRtV3R lV 3R lltV3R lR ltV3R lR lt]]	]
RV3R	 lR
 ll4       4       4       tR tV3R lR lt]R 4       tRtVtV ;t# )ri  iý  r^  c                ó    <€ V ^8„  d   QhRS[ /# r(  r   )r*   r+   s   "€r,   r-   Ú)EomtForUniversalSegmentation.__annotate__  s   ø€ ÷ ñ ™zñ r/   c                ó  <€ \         SV `  V4       Wn        VP                  V n        \	        V4      V n        \        P                  ! VP                  VP                  R 7      V n
        \        P                  ! VP                  VP                  4      V n        \        P                  ! \        VP                  4       Uu. uF  p\!        V4      NK  	  up4      V n        \%        V4      V n        \)        V4      V n        \        P,                  ! VP                  VP.                  ^,           4      V n        VP2                  VP4                  ,          VP2                  VP4                  ,          3V n        RVP8                  RVP:                  RVP<                  /V n        \A        WP>                  R7      V n!        \        PD                  ! \F        PH                  ! VPJ                  4      4      V n&        V PO                  4        R# u upi )r  rì   r  r  )r±   r²   N)(rt   ru   r±   Únum_hidden_layersrf  rb  r   r  rS  r  Ú	layernormrw  ró   rƒ  r>  r„   rþ  Úlayersr8  Úupscale_blockrF  Ú	mask_headrš  r¸   Úclass_predictorrP  rQ  Ú	grid_sizerÁ   rÃ   rÂ   r²   r¯   rc   r¼   r&   r»   r=  rk  Ú	post_initr@  s   && €r,   ru   Ú%EomtForUniversalSegmentation.__init__  sx  ø€ Ü‰Ñ˜Ô ØŒØ!'×!9Ñ!9ˆÔÜ(¨Ó0ˆŒÜŸš f×&8Ñ&8¸f×>SÑ>SÔTˆŒä—\’\ &×"4Ñ"4°f×6HÑ6HÓIˆŒ
Ü—m’mÄÀf×F^ÑF^Ô@_Ó$`Ñ@_¸1¤Y¨vÖ%6Ñ@_Ñ$`ÓaˆŒä+¨FÓ3ˆÔÜ% fÓ-ˆŒä!Ÿyšy¨×);Ñ);¸V×=NÑ=NÐQRÕ=RÓSˆÔà ×+Ñ+¨v×/@Ñ/@Õ@À&×BSÑBSÐW]×WhÑWhÕBhÐiˆŒà  &×"5Ñ"5Ø˜×+Ñ+Ø˜×+Ñ+ð.
ˆÔô "¨×=MÑ=MÔNˆŒä!Ÿyšy¬¯ª°F×4EÑ4EÓ)FÓGˆÔà�‰Öùò% %as   Ã Hc                ój   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[S[S[ 3,          RS[S[S[ 3,          /# )r   r!   r    r{   r|   r3  r<   )r   r³   r´   )r*   r+   s   "€r,   r-   rz  !  sY   ø€ ÷ ñ á$ðñ %ðñ ð	ñ
 ðñ  $¡C© KÕ0ðñ 
‰c‘6ˆkÕ	ñr/   c                óÊ   € V P                  VVVVVR 7      pV P                  P                  4        F.  w  rxVP                  4        F  w  ršWy9   g   K  W¨,          p
K  	  K0  	  V# )©r!   r    r{   r|   r3  )rc   r²   r6  )rw   r!   r    r{   r|   r3  r9  r:  rê   Úloss_keyr   s   &&&&&&     r,   Úget_loss_dictÚ*EomtForUniversalSegmentation.get_loss_dict!  sj   € ð (,§~¡~Ø!5Ø!5Ø#Ø%Ø"7ð (6ó (
ˆ	ð  ×+Ñ+×1Ñ1Ö3‰KˆCØ"+§/¡/Ö"3‘�Ø–?Ø•N’Dó #4ñ 4ð
 Ðr/   c                ó<   <€ V ^8„  d   QhRS[ S[S[3,          RS[/# )r   r9  r<   )r³   r´   r   )r*   r+   s   "€r,   r-   rz  9  s$   ø€ ÷ 'ñ '¡$¡s©F {Õ"3ð '¹ñ 'r/   c                ó4   € \        VP                  4       4      # r   )rU   r­  )rw   r9  s   &&r,   Úget_lossÚ%EomtForUniversalSegmentation.get_loss9  s   € Ü�9×#Ñ#Ó%Ó&Ð&r/   c                ó¨   <€ V ^8„  d   QhRS[ RS[S[ ,          R,          RS[S[ ,          R,          RS[S[ ,          R,          RS[S[,          RS[/# )r   r^  r{   Nr|   r%   rF   r<   )r   r)   r   r   r   )r*   r+   s   "€r,   r-   rz  ?  sp   ø€ ÷ e
ñ e
áðe
ñ ™&•\ DÕ(ðe
ñ ™6•l TÕ)ð	e
ñ
 ™F•| dÕ*ðe
ñ Ñ+Õ,ðe
ñ 
,ñe
r/   c           	     óº  € RRrvRpVf   \        R4      hV P                  V4      p	\        V P                  4       EF	  w  r«W P                  V P
                  P                  ,
          8X  dr   V P                  P                  R,          P                  V	P                  ^ ,          RR4      P                  V	P                  4      p\        P                  ! WÉ3^R7      p	W P                  V P
                  P                  ,
          8¼  Ed4   V P                  '       gE   V P                   W P                  ,
          V P
                  P                  ,           ,          ^ 8”  EdÞ   V P#                  V	4      pV P%                  V4      w  rïWn3,          pW3,          p\        P&                  ! V	P                  ^ ,          V	P                  ^,          V	P                  ^,          V	P                  \        P(                  R7      p\*        P,                  ! WàP.                  RR7      pVP1                  VP3                  ^ 4      VP3                  ^4      R4      pV P
                  P4                  pVV P                  P6                  ,           pV^ 8„  VRRV1VR13&   V P9                  VV P                   W P                  ,
          V P
                  P                  ,           ,          VVVP                  R7      pVR,          P                  RV P
                  P:                  RR4      pVP=                  4       P?                  V( R4      pV! W˜4      p	EK  	  V P#                  V	4      pV P%                  V4      w  rïWn3,          pW3,          pRpVeI   VeE   R	p\A        Wg4       F3  w  rïV PC                  VVVVRR
7      pVV PE                  V4      ,          pK5  	  \G        VVVVVR7      # )a'  
mask_labels (`list[torch.Tensor]`, *optional*):
    list of mask labels of shape `(num_labels, height, width)` to be fed to a model
class_labels (`list[torch.LongTensor]`, *optional*):
    list of target class labels of shape `(num_labels, height, width)` to be fed to a model. They identify the
    labels of `mask_labels`, e.g. the label of `mask_labels[i][j]` if `class_labels[i][j]`.
patch_offsets (`list[torch.Tensor]`, *optional*):
    list of tuples indicating the image index and start and end positions of patches for semantic segmentation.
Nz You have to specify pixel_valuesrP   r%  )r   rƒ   Úbilinear)ÚsizeÚmode)ÚprobÚnum_query_tokensÚencoder_start_tokensr   r¥  r‡  )r   r!   r    r"   r%   r0   )NrP   rP   rN   )rP   N.g    eÍÍÁ)$rv   rb  rÊ   r~  r|  r±   r=  rƒ  rê   ry  r^   r†   r   r&   rï   r‰  rk  r}  Úpredictr»   rØ   r!  Úinterpolater‚  r)  r’  ró   rv  Ú_disable_attention_maskr”  rp   Úmasked_fillrÙ   r‰  r�  r   )rw   r^  r{   r|   r%   rF   Úmasks_queries_logits_per_layerÚclass_queries_logits_per_layerr„  r#   rô   Úlayer_modulerƒ  Únorm_hidden_statesr!   r    Úinterpolated_logitsr•  r–  Úsequence_outputr   r9  s   &&&&&,                r,   r�   Ú$EomtForUniversalSegmentation.forward<  sƒ  € ð* JLÈRÐ(FØˆàÒÜÐ?Ó@Ð@àŸ™¨Ó5ˆä!*¨4¯;©;×!7ÑˆCØ×,Ñ,¨t¯{©{×/EÑ/EÕEÔEØŸ
™
×)Ñ)¨*Õ5×<Ñ<¸]×=PÑ=PÐQRÕ=SÐUWÐY[Ó\×_Ñ_Ð`m×`tÑ`tÓu�Ü %§	¢	¨5Ð*@ÀaÔ H�à×,Ñ,¨t¯{©{×/EÑ/EÕEÕEØ——� ×!5Ñ!5°c×<RÑ<RÕ6RÐUY×U`ÑU`×UkÑUkÕ6kÕ!lÐopÕ!pà%)§^¡^°MÓ%BÐ"Ø=A¿\¹\ÐJ\Ó=]Ñ:Ð$à.Ð2IÕIÐ.Ø.Ð2IÕIÐ.ä!&§¢Ø!×'Ñ'¨Õ*Ø!×'Ñ'¨Õ*Ø!×'Ñ'¨Õ*Ø(×/Ñ/ÜŸ*™*ô"�ô '(§m¢mÐ4HÏ~É~ÐdnÔ&oÐ#Ø&9×&>Ñ&>Ø'×,Ñ,¨QÓ/Ð1D×1IÑ1IÈ!Ó1LÈbó'Ð#ð $(§;¡;×#:Ñ#:Ð Ø'7¸$¿/¹/×:[Ñ:[Õ'[Ð$ð ObÐdeÑNe�˜qÐ"3Ð#3Ð"3Ð5IÑ5JÐJÑKð "&×!=Ñ!=Ø"Ø×-Ñ-¨c×4JÑ4JÕ.JÈTÏ[É[×McÑMcÕ.cÕdØ%5Ø)=Ø)×0Ñ0ð ">ó "�ð "0°Õ!=×!DÑ!DÀRÈÏÉ×IhÑIhÐjlÐnpÓ!q�Ø!/×!5Ñ!5Ó!7×!CÑ!CÀ^ÀOÐUYÓ!Z�á(¨ÓG‹Mñ] "8ð` Ÿ.™.¨Ó7ˆà59·\±\À/Ó5RÑ2ÐØ&Ð*AÕAÐ&Ø&Ð*AÕAÐ&àˆØÒ" |Ò'?ØˆDÜ>AØ.ö?Ñ:Ð$ð !×.Ñ.Ø)=Ø)=Ø +Ø!-Ø*.ð /ó �	ð ˜Ÿ™ iÓ0Õ0’ñ?ô 2ØØ!5Ø!5Ø-Ø'ô
ð 	
r/   c                ó.   € V P                   P                  # r   )rb  rr  rù  s   &r,   Úget_input_embeddingsÚ1EomtForUniversalSegmentation.get_input_embeddings¦  s   € Ø�‰×/Ñ/Ð/r/   c                ó4   <€ V ^8„  d   QhRS[ P                  /# )r   r  r=   )r*   r+   s   "€r,   r-   rz  ©  s   ø€ ÷ )ñ )™eŸl™lñ )r/   c                óÞ  € VR RV P                   P                  1R 3,          pV P                  V4      pVR V P                   P                  V P                  P                  ,           R1R 3,          pVP                  ^^4      pVP                  ! VP                  ^ ,          R.V P                  O5!  pV P                  V4      pV P                  V4      p\        P                  ! RW$4      pWS3# )rP   Nzbqc, bchw -> bqhwrN   )r±   ró   r�  rb  rv  rñ   r¨  r^   r‚  r€  r  r&   Úeinsum)rw   r  Úquery_tokensÚclass_logitsÚprefix_tokensÚmask_logitss   &&    r,   r—  Ú$EomtForUniversalSegmentation.predict©  sÑ   € Ø˜aÐ!: 4§;¡;×#:Ñ#:Ð!:¸AÐ=Õ>ˆØ×+Ñ+¨LÓ9ˆà˜q $§+¡+×"9Ñ"9¸D¿O¹O×<]Ñ<]Õ"]Ñ"_ÐabÐbÕcˆØ%×/Ñ/°°1Ó5ˆà%×-Ò-¨m×.AÑ.AÀ!Õ.DÀbÐZÈ4Ï>É>ÓZˆà—~‘~ lÓ3ˆØ×*Ñ*¨=Ó9ˆä—l’lÐ#6¸ÓTˆàÐ(Ð(r/   c                ó’   € V^8  d@   \         P                  ! V P                  ^ ,          W$R7      V8„  p^V RRV1VR13,          V&   V # )rÉ   r~   rP   N)r&   r‡   r^   )Ú	attn_maskr”  r•  r–  r   Úrandom_queriess   &&&&& r,   r™  Ú4EomtForUniversalSegmentation._disable_attention_mask¹  sT   € à�!Œ8ä"ŸZšZ¨	¯©¸Õ(:Ð<LÔ\Ð_cÑcˆNð VWˆI�aÐ*Ð*Ð*Ð,@Ñ,AÐAÕBÀ>ÑRàÐr/   )rk  r�  r±   rc   rb  r‚  r}  r~  r€  r|  rƒ  r  r²   )NNN)r1   r2   r3   r4   rr  ru   r‰  r�  r   r   r   r�   r£  r—  Ústaticmethodr™  r7   r8   r¡   r¢   s   @@r,   ri  ri  ý  s   ù‡ € ð %€O÷ó ÷8ð ÷0'ð 'ð  ØØ÷e
ñ e
ó ó ó  ðe
òN0÷)ð )ð  ñó ÷ð r/   ri  )Frü  )HÚcollections.abcrU  r^  r   Údataclassesr   Únumpyrç   r&   Útorch.nn.functionalr   rB   r!  r   Ú r   r\  Úactivationsr   Ú
file_utilsr	   r
   r   Úmodeling_layersr   Úmodeling_utilsr   r   Úprocessing_utilsr   Úutilsr   r   r   Úutils.genericr   Úutils.output_capturingr   Úconfiguration_eomtr   Úscipy.optimizer   Ú
accelerater   Úaccelerate.utilsr   r   rH   rX   rh   r†  rj   r¨   r­   r¯   rK  rf  r�  r‘  r±  rÂ  r×  rç  rþ  r  r  r&  r8  rF  rQ  ri  Ú__all__r0   r/   r,   Ú<module>rÄ     sì  ðó* Û Ý $Ý !ã Û ß Ð ß å &Ý !ß LÑ LÝ 9ß FÝ &ß PÑ PÝ 7Ý 5Ý *ñ ×ÒÝ4á×ÒÝ'Ý'ñ ðô	ð ô4¨ó 4ó ó	ð4÷@õ@õ,ô8g˜2Ÿ9™9ô gõTõ<ô(uˆr�y‰yô uôp	˜"Ÿ)™)ô ôB"�R—Y‘Yô "÷J%ô.8)�B—I‘Iô 8)ôv+�R—Y‘Yô +ôˆb�i‰iô ô&(�B—I‘Iô (ô"%�2—9‘9ô %ô0'Ð*ô 'ôT�b—l‘lô ô�R—Y‘Yô ô2	�R—Y‘Yô 	ô�2—9‘9ô ð" ô-/˜/ó -/ó ð-/ñ` ðôô
@Ð#6ó @óð
@ðF !Ð"@Ð
A‚r/   