+
    œ°³jøJ  ã                  ó  € R t ^ RIHt ^ RIt^ RIHu Ht ^RIH	t	 ^RI
Ht ^RIHt ]P                  ! ]4      tRR R lltRR R	 lltRR
 R lltRR R lltRR R lltRR R lltRR R lltRR R lltRR R lltR# )uÿ  Vision utility functions for pre-computing very dynamic and
data-dependent tensors that can break model graph capturing.

All functions are standalone (no model weights) and compute tensors from
`grid_thw` + config scalars. They are used by vision encoders and can be
precomputed before `torch.compile` / `torch.export` tracing since they
use untraceable ops (`repeat_interleave`, `.tolist()`, `nonzero()`, loops).

Each `get_*` accepts an optional `kwargs` dict; if it contains the
precomputed tensor under the natural key (`"cu_seqlens"`, `"position_ids"`,
â€¦), the function pops and returns it instead of computing. Vision encoders
write `x = get_vision_x(..., kwargs=kwargs)` and the matching key is
removed from the caller's kwargs as a side-effect of the pop.
)ÚannotationsN)ÚPreTrainedConfig)Úlogging)Úget_max_seqlenc               ó(   € V ^8„  d   QhRRRRRRRR/# )é   Úgrid_thwútorch.TensorÚmerge_temporalÚboolÚkwargsúdict | NoneÚreturn© )Úformats   "ÚZ/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/vision_utils.pyÚ__annotate__r   *   s2   € ÷ Fñ FØðFØ,0ðFØBMðFàñFó    c                óÐ  € Ve   VP                  RR4      ;pe   V# \        P                  P                  4       '       d   V P                  M\        P
                  pV'       d'   V R,          V R,          ,          V R,          ,          pM3\        P                  ! V R,          V R,          ,          V R,          4      p\        P                  ! VP                  ^ VR7      R^ R7      # )	u«  Get cumulative sequence lengths from vision grid info, or pop from `kwargs` if precomputed.

Args:
    grid_thw: `(num_images_or_videos, 3)` â€” temporal, height, width per entry.
    merge_temporal: when `False` (default), each frame is its own attention segment (`h * w`
        per frame, `t` segments per entry â€” the qwen2_vl / glm4v convention). When `True`,
        the whole clip is a single segment (`t * h * w`), i.e. attention spans all frames
        jointly (the kimi_k25 convention).
    kwargs: optional caller kwargs â€” if it contains `"cu_seqlens"` it is popped and returned.

Returns:
    `cu_seqlens`: `(num_segments + 1,)` int32 cumulative sequence boundaries.
NÚ
cu_seqlens)ÚdimÚdtype)Úvalue©ºNNNé    ©r   é   ©r   r   ©r   r   )
ÚpopÚtorchÚjitÚ
is_tracingr   Úint32Úrepeat_interleaveÚFÚpadÚcumsum)r   r
   r   r   r   Úseqlenss   &&&   r   Úget_vision_cu_seqlensr*   *   s¨   € ð  Ò¨V¯Z©Z¸ÀdÓ-KÐK˜zÒXØÐÜ#Ÿi™i×2Ñ2×4Ò4ˆH�NŠN¼%¿+¹+€EßØ˜4•. 8¨D¥>Õ1°H¸TµNÕB‰ä×)Ò)¨(°4­.¸8ÀD½>Õ*IÈ8ÐTXÍ>ÓZˆÜ�5Š5�—‘ A¨U�Ó3°VÀ1ÔEÐEr   c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   r   r	   Úconfigr   r
   r   r   r   r   ztuple[torch.Tensor, int | None]r   )r   s   "r   r   r   D   s:   € ÷ 
"ñ 
"Øð
"àð
"ð ð
"ð ð	
"ð
 %ñ
"r   c                ó<   € \        WVR7      p\        WAVR7      pWE3# )z¹Get cumulative and maximum sequence lengths for packed vision attention. ``merge_temporal`` is
forwarded to [`get_vision_cu_seqlens`] (``True`` for clip-level attention, e.g. kimi_k25).)r
   r   )r   )r*   r   )r   r,   r
   r   r   Ú
max_seqlens   &&&&  r   Úget_vision_attention_seqlensr/   D   s&   € ô ' xÐW]Ô^€JÜ 
¸6ÔB€JØÐ!Ð!r   c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R/# )
r   r   r	   Úspatial_merge_sizezint | torch.TensorÚinclude_temporalr   r   r   r   r   )r   s   "r   r   r   Q   s:   € ÷ .*ñ .*Øð.*à*ð.*ð ð.*ð ð	.*ð
 ñ.*r   c           
     óV  € Ve   VP                  RR4      ;pe   V# V P                  p\        V\        4      '       d2   \        P
                  ! V.VR7      P                  \        V 4      4      p. p\        V P                  4       VP                  4       4       EFt  w  w  rgr‰\        P                  ! \        P                  ! WuR7      \        P                  ! W…R7      RR7      w  r«Wy,          W˜V	,          V	3pV
P                  V4      P                  ^^4      P                  4       p
VP                  V4      P                  ^^4      P                  4       pV'       dw   \        P                  ! WeR7      P                  Wx,          4      pVP!                  \        P"                  ! WÚP%                  V4      VP%                  V4      .RR7      4       EK<  VP!                  \        P"                  ! W«.RR7      P%                  V^4      4       EKw  	  \        P&                  ! V^ R7      # )uË  Get position IDs for vision rotary embeddings, or pop from `kwargs` if precomputed.

Args:
    grid_thw: `(num_images_or_videos, 3)`
    spatial_merge_size: merge block size â€” either a single `int` (same for all images)
        or a `(num_images_or_videos,)` tensor (per-image).
    kwargs: optional caller kwargs â€” if it contains `"position_ids"` it is popped and returned.
    include_temporal: when ``True``, prepend a temporal-index column and return
        `(total_tokens, 3)` â€” for encoders whose rotary embedding rotates T/H/W axes
        (minimax_m3_vl). When ``False`` (default), return `(total_tokens, 2)` for the
        2-axis (h, w) case (qwen2_5_vl / qwen3_vl / glm4v / paddleocr_vl); the h/w
        indices are still repeated ``t`` times for video inputs.

Returns:
    `position_ids`: `(total_tokens, 3)` long if ``include_temporal`` else `(total_tokens, 2)`,
    with the spatial indices laid out block-major over ``mÃ—m`` spatial-merge blocks.
NÚposition_ids©ÚdeviceÚij)Úindexing©r   éÿÿÿÿ)r    r6   Ú
isinstanceÚintr!   ÚtensorÚexpandÚlenÚzipÚtolistÚmeshgridÚarangeÚreshapeÚ	transposeÚflattenr%   ÚappendÚstackÚrepeatÚcat)r   r1   r2   r   r4   r6   ÚtÚhÚwÚ
merge_sizeÚhpos_idsÚwpos_idsÚblock_shapeÚtpos_idss   &&&&          r   Úget_vision_position_idsrS   Q   s¬  € ð. Ò¨v¯z©z¸.È$Ó/OÐO˜|Ò\ØÐà�_‰_€FÜÐ$¤c×*Ò*Ü"Ÿ\š\Ð+=Ð*>ÀvÔN×UÑUÔVYÐZbÓVcÓdÐà€LÜ!$ X§_¡_Ó%6Ð8J×8QÑ8QÓ8S×!TÑ‰	ˆˆqÜ"Ÿ^š^Ü�LŠL˜Ô*Ü�LŠL˜Ô*Øô
Ñˆð
 •¨
¸µOÀZÐPˆØ×#Ñ# KÓ0×:Ñ:¸1¸aÓ@×HÑHÓJˆØ×#Ñ# KÓ0×:Ñ:¸1¸aÓ@×HÑHÓJˆßÜ—|’| AÔ5×GÑGÈÍÓNˆHØ×Ñ¤§¢¨X·±ÀqÓ7IÈ8Ï?É?Ð[\ÓK]Ð,^ÐdfÔ g×hà×Ñ¤§¢¨XÐ,@ÀbÔ I× PÑ PÐQRÐTUÓ V×Wñ "Uô �9Š9�\ qÔ)Ð)r   c               ó0   € V ^8„  d   QhRRRRRRRRRRR	R
/# )r   r   r	   r1   r<   Úwindow_sizeÚ
patch_sizer   r   r   ú!tuple[torch.Tensor, torch.Tensor]r   )r   s   "r   r   r   ‚   sD   € ÷ :+ñ :+Øð:+àð:+ð ð:+ð ð	:+ð
 ð:+ð 'ñ:+r   c                ó
  € Ve0   VP                  RR4      pVP                  RR4      pVe   Ve   WV3# . p^ .p^ pW!,          V,          pV^,          p	V P                  4        EF¼  w  r«p\        V
4      \        V4      \        V4      rËp
W±,          pWÁ,          p\        P                  ! W­,          V,          4      P                  W­V4      pW�V,          ,
          pWŽV,          ,
          pVV,           V,          pVV,           V,          p\        P                  ! V^ V^ V3RR4      pVP                  V
VVVV4      pVP                  ^ ^^^^4      P                  V
VV,          Wˆ4      pVR8g  P                  ^^.4      P                  R4      pVP                  R4      pVVR8g  ,          pVP                  VV,           4       VP                  ^ 4      V	,          VR,          ,           pVP                  VP                  4       4       WzV,          V,          ,          pEK¿  	  \        P                  ! V^ R7      p\        P                  ! W`P                  \        P                   R7      p\        P"                  ! V4      pWV3# )	ux  Get window attention indices, or pop `"window_index"`/`"cu_window_seqlens"` from `kwargs` if both precomputed.

Args:
    grid_thw: `(num_images_or_videos, 3)`
    spatial_merge_size: merge block size from vision config.
    window_size: window size from vision config.
    patch_size: patch size from vision config.
    kwargs: optional caller kwargs â€” if it contains both `"window_index"` and `"cu_window_seqlens"` they are popped and returned.

Returns:
    `window_index`: `(total_tokens,)` long â€” reorder indices for windowed attention.
    `cu_window_seqlens`: `(num_windows + 1,)` int32 â€” cumulative window boundaries.
NÚwindow_indexÚcu_window_seqlensÚconstantr9   )r6   r   iœÿÿÿr:   )r    rA   r<   r!   rC   rD   r&   r'   ÚpermuteÚsumrG   r(   ÚextendrJ   r=   r6   r$   Úunique_consecutive)r   r1   rU   rV   r   rY   rZ   Úwindow_index_idÚvit_merger_window_sizeÚspatial_merge_unitÚgrid_tÚgrid_hÚgrid_wÚ
llm_grid_hÚ
llm_grid_wÚindexÚpad_hÚpad_wÚnum_windows_hÚnum_windows_wÚindex_paddedr)   Ú	index_newÚcu_seqlens_tmps   &&&&&                   r   Úget_vision_window_indexrp   ‚   s`  € ð( ÒØ—z‘z .°$Ó7ˆØ"ŸJ™JÐ':¸DÓAÐØÒ#Ð(9Ò(EØÐ2Ð2Ø€LØ ˜cÐØ€OØ(Õ>À*ÕLÐØ+¨QÕ.Ðà"*§/¡/×"3Ñˆ˜Ü!$ V£¬c°&«k¼3¸v»;˜ˆØÕ1ˆ
ØÕ1ˆ
Ü—’˜VÕ0°:Õ=Ó>×FÑFÀvÐ[eÓfˆØ&Ð6LÕ)LÕLˆØ&Ð6LÕ)LÕLˆØ# eÕ+Ð0FÕFˆØ# eÕ+Ð0FÕFˆÜ—u’u˜U Q¨¨q°%Ð$8¸*ÀdÓKˆØ#×+Ñ+Ø�MÐ#9¸=ÐJ`ó
ˆð $×+Ñ+¨A¨q°!°Q¸Ó:×BÑBØ�M MÕ1Ð3Ió
ˆð   4Ñ'×,Ñ,¨a°¨VÓ4×<Ñ<¸RÓ@ˆØ#×+Ñ+¨BÓ/ˆØ  °Ñ!5Õ6ˆ	Ø×Ñ˜I¨Õ7Ô8Ø Ÿ™¨Ó*Ð-?Õ?ÐBSÐTVÕBWÕWˆØ× Ñ  ×!6Ñ!6Ó!8Ô9Ø JÕ.°Õ;Õ;‹ñ- #4ô0 —9’9˜\¨qÔ1€LÜŸšÐ%6¿¹ÔV[×VaÑVaÔbÐÜ×0Ò0Ð1BÓCÐØÐ*Ð*r   c               ó4   € V ^8„  d   QhRRRRRRRRRR	R
RRR/# )r   rh   r	   ÚsizeÚsider<   ÚmodeÚstrÚalign_cornersr   Úpaddingr   rW   r   )r   s   "r   r   r   ¿   sD   € ÷ %ñ %Øð%Ø+ð%Ø36ð%Ø>Að%ØRVð%Øadð%à&ñ%r   c                ó\  € V P                  \        P                  4      p V'       d5   W^,
          ,          \        P                  ! V^,
          ^R7      ,          pMV R,           V,          V,          R,
          p\        P                  ! V4      pVR8X  d%   \        P
                  ! ^ ^V P                  R7      pM;VR8X  d%   \        P
                  ! R	^V P                  R7      pM\        RV: R24      hVP                  4       R
,          V,           p	V	P                  ^ V^,
          4      p
VR
,          VR
,          ,
          V,
          P                  4       pVR8X  d   ^V,
          P                  ^ R7      pM�RpV^,           V,          V^,           ,
          V,          V,          ^,           pWÛ,          ^V,          ,
          V,          ^V,          ,           V,          ^V,          ,
          p\        P                  ! V^8*  Wï4      pVR8X  d   WÉ^ 8¬  W’^,
          8*  ,          ,          pW¬3# )u÷  Per-axis interpolation taps into a `side`-length source table and their weights, for `index`
target positions on an axis of length `size`. `mode` selects the kernel width â€” 2 taps
(`"bilinear"`) or 4 taps (`"bicubic"`, Keys convolution kernel with `a=-0.75`). `size` may be a
scalar or a per-element tensor (ragged batches). `padding` controls out-of-range taps: `"border"`
clamps to the edge value (like `F.interpolate`), `"zeros"` gives them zero weight (like
`F.grid_sample(padding_mode="zeros")`).)Úming      à?Úbilinearr5   ÚbicubiczUnsupported interpolation mode z$ (expected 'bilinear' or 'bicubic').Úzerosr:   ©r   Ng      è¿)Útor!   Úfloat32ÚclampÚfloorrC   r6   Ú
ValueErrorÚlongÚabsÚwhere)rh   rr   rs   rt   rv   rw   Úsrcr�   ÚoffsetsÚraw_tapsÚtapsÚdistanceÚweightsÚaÚnearÚfars   &&&&&&          r   Ú _interpolation_axis_taps_weightsr�   ¿   s°  € ð �H‰H”U—]‘]Ó#€Eßð ˜a•xÕ ¤5§;¢;¨t°a­x¸QÔ#?Õ?‰à�s�{˜dÕ" TÕ)¨CÕ/ˆÜ�KŠK˜Ó€EØˆzÔÜ—,’,˜q !¨E¯L©LÔ9‰Ø	�Ô	Ü—,’,˜r 1¨U¯\©\Ô:‰äÐ:¸4¹(ÐBfÐgÓhÐhØ�z‰z‹|˜GÕ$ wÕ.€HØ�>‰>˜!˜T A�XÓ&€DØ�G•˜u W�~Õ-°Õ7×<Ñ<Ó>€HØˆzÔØ�x•<×&Ñ&¨1Ð&Ó-‰àˆØ�Q•˜(Õ" a¨!¥eÕ,°Õ8¸8ÕCÀaÕGˆØ•˜q 1�uÕ$¨Õ0°1°qµ5Õ8¸HÕDÀqÈ1ÅuÕLˆÜ—+’+˜h¨!™m¨TÓ7ˆØ�'Ôð ¨!™m°À1½HÑ0DÕEÕFˆØˆ=Ðr   c               ó8   € V ^8„  d   QhRRRRRRRRR	RR
RRRRR/# )r   r   r	   Únum_grid_per_sider<   rt   ru   rv   r   r1   rw   r   r   r   rW   r   )r   s   "r   r   r   ç   sb   € ÷ Bñ BØðBàðBð ðBð ð	Bð
 ðBð ðBð ðBð 'ñBr   c                óL  € Ve0   VP                  RR4      pVP                  RR4      pVe   Ve   Wx3# Tp	Tp
V P                  pV R,          V R,          ,          V R,          ,          p\        P                  ! V R,          V4      p\        P                  ! V R,          V4      p\        P                  ! \        P
                  ! VP                  ^ 4      RR R	4      V4      p\        P                  ! VP                  4       VR7      V,
          WÞ,          ,          pWê,          pVV
,          pVV
,          V
,          pVWª,          ,          V,          pVWª,          V,          ,          pVV
,          V,           pVV
,          V,           p\        VWÙW#V4      w  pp\        VWéW#V4      w  ppVP                  ^,          pVR
,          V	,          VR,          ,           P                  RVV,          4      pVR
,          VR,          ,          P                  RVV,          4      pVV3# )uÙ  Per-patch gather indices/weights that resample a square learned `(num_grid_per_side,
num_grid_per_side)` position-embedding table to each image's `(h, w)` grid, or pop
`"interp_indices"`/`"interp_weights"` from `kwargs` if both precomputed.

Reproduces `F.interpolate(mode=mode, align_corners=align_corners)` as `(total_patches, n_taps)`
indices + weights (`n_taps` = 4 for `"bilinear"`, 16 for `"bicubic"` â€” the Keys kernel with
`a=-0.75`), consumed by a fused `F.embedding_bag` or a weighted `embedding` sum. Fully vectorised
over packed patches (ragged `(h, w)` handled with `repeat_interleave`, no per-image loop), so it
supports dynamic shapes like the other grid_thw precompute helpers. `spatial_merge_size > 1`
emits patches in spatial-merge-block order (for encoders that consume merged tokens); `1` keeps
raster order.

Args:
    grid_thw: `(num_images_or_videos, 3)` â€” temporal, height, width per entry.
    num_grid_per_side: `int(num_position_embeddings ** 0.5)` from the vision config.
    mode: `"bilinear"` or `"bicubic"`.
    align_corners: matches the corresponding `F.interpolate` flag.
    spatial_merge_size: merge block size; `1` keeps raster patch order.
    kwargs: optional caller kwargs â€” if it contains both `"interp_indices"` and `"interp_weights"`
        they are popped and returned.

Returns:
    `indices`: `(total_thw, n_taps)` long â€” gather indices into the flattened pos_embed table.
    `weights`: `(total_thw, n_taps)` float â€” interpolation weights.
NÚinterp_indicesÚinterp_weightsr5   r   r   r   r:   r   )r   r   N)r   Nr   )r    r6   r!   r%   r&   r'   r(   rC   r]   r�   ÚshaperD   )r   r‘   rt   rv   r1   rw   r   r“   r”   rs   Úmerger6   ÚcountsÚheightsÚwidthsÚstartsÚwithinÚblocks_wÚin_colÚin_rowÚ	block_colÚ	block_rowÚrowÚcolÚh_tapsÚ	h_weightsÚw_tapsÚ	w_weightsÚnÚindicesr‹   s   &&&&&&&                        r   Ú,get_vision_interpolation_indices_and_weightsr©   ç   sÞ  € ðD ÒØŸ™Ð$4°dÓ;ˆØŸ™Ð$4°dÓ;ˆØÒ%¨.Ò*DØ!Ð1Ð1à€DØ€EØ�_‰_€Fà�d�^˜h t�nÕ,¨x¸­~Õ=€FÜ×%Ò% h¨t¥n°fÓ=€GÜ×$Ò$ X¨d¥^°VÓ<€FÜ×$Ò$¤Q§U¢U¨6¯=©=¸Ó+;¸C¸RÐ+@À&Ó%IÈ6ÓR€Fä�lŠl˜6Ÿ:™:›<°Ô7¸&Õ@ÀWÕEUÕV€Fð �€HØ�e�^€FØ˜�o Õ&€FØ˜E�MÕ*¨hÕ6€IØ˜5�=¨8Õ3Õ4€IØ
�eÕ
˜fÕ
$€CØ
�eÕ
˜fÕ
$€Cä8¸¸gÈTÐbiÓjÑ€FˆIÜ8¸¸fÈDÐahÓiÑ€FˆIØ�‰�Q�€Aà�jÕ! DÕ(¨6°*Õ+=Õ=×FÑFÀrÈ1ÈqÍ5ÓQ€GØ˜Õ$ y°Õ'<Õ<×EÑEÀbÈ!ÈaÍ%ÓP€GØ�GÐÐr   c               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )r   r   r	   r‘   r<   r1   rv   r   r   r   r   rW   r   )r   s   "r   r   r   ,  sD   € ÷ <ñ <Øð<àð<ð ð<ð ð	<ð
 ð<ð 'ñ<r   c                óü   € \         P                  R4       Ve0   VP                  RR4      pVP                  RR4      pVe   Ve   WV3# \        WRRVR7      w  rxVP	                  ^ ^4      VP	                  ^ ^4      3# )uÒ   Deprecated â€” use [`get_vision_interpolation_indices_and_weights`] with `mode="bilinear"`,
`align_corners=True`. Returns the legacy `(4, total_thw)` layout (transpose of the unified helper's
`(total_thw, 4)`).a  `get_vision_bilinear_indices_and_weights` is deprecated and will be removed in v5.17. Use `get_vision_interpolation_indices_and_weights(..., mode='bilinear', align_corners=True)` instead (it returns `(total_thw, n_taps)`, the transpose of this function's output).NÚbilinear_indicesÚbilinear_weightsrz   T)rt   rv   r1   )ÚloggerÚwarning_oncer    r©   rE   )	r   r‘   r1   rv   r   r¬   r­   r¨   r‹   s	   &&&&&    r   Ú'get_vision_bilinear_indices_and_weightsr°   ,  s—   € ô ×Ñð	_ôð
 ÒØ!Ÿ:™:Ð&8¸$Ó?ÐØ!Ÿ:™:Ð&8¸$Ó?ÐØÒ'Ð,<Ò,HØ#Ð5Ð5ÜCØ¨*ÀDÐ]oôÑ€Gð ×Ñ˜Q Ó" G×$5Ñ$5°a¸Ó$;Ð;Ð;r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Útarget_sizesr	   Únum_patches_per_sider<   r   r   r   r   )r   s   "r   r   r   F  s,   € ÷ #ñ #Øð#Ø69ð#ØCNð#àñ#r   c                ón  € Ve   VP                  RR4      ;pe   V# V P                  p\        P                  ! ^V,          R^V,          VR7      p. pV P	                  4        Fº  w  rx\        V4      \        V4      r‡\        P                  ! WtR7      V,          p	\        P                  ! W„R7      V,          p
\        P                  ! W•RR7      p\        P                  ! W¥RR7      pVP                  VR,          V,          V,           P                  4       4       K¼  	  \        P                  ! V4      # )uå  Get nearest-neighbor position IDs into a `num_patches_per_side**2` 2-D table, or pop
from `kwargs` if precomputed.

For each image of size `(h, w)`, maps fractional grid coordinates `i/h` to the nearest
bucket on a `num_patches_per_side` grid (via `bucketize`) and flattens to 1-D embedding
indices, concatenated across all images. Used by NaViT-style packers (e.g. MiniCPM-V).

Args:
    target_sizes: `(num_images, 2)` int â€” `(h, w)` per image.
    num_patches_per_side: side length of the learned 2-D position-embedding grid.
    kwargs: optional caller kwargs â€” if it contains `"position_ids"` it is popped and returned.

Returns:
    `position_ids`: `(sum(h_i * w_i),)` long â€” flat indices into a `num_patches_per_side**2` table.
Nr4   g      ð?r5   T)Úrightr}   )
r    r6   r!   rC   rA   r<   Ú	bucketizerG   rF   rJ   )r²   r³   r   Úpos_idsr6   Ú
boundariesÚpos_ids_listÚheightÚwidthÚh_coordsÚw_coordsÚbucket_hÚbucket_ws   &&&          r   Úget_vision_nearest_position_idsrÀ   F  s÷   € ð$ Ò¨&¯*©*°^ÀTÓ*JÐJ˜wÒWØˆØ× Ñ €FÜ—’˜aÐ"6Õ6¸¸QÐAUÕ=UÐ^dÔe€JØ€LØ%×,Ñ,Ö.‰ˆÜ˜F›¤S¨£Z�Ü—<’< Ô6¸Õ?ˆÜ—<’< Ô5¸Õ=ˆÜ—?’? 8¸tÔDˆÜ—?’? 8¸tÔDˆØ×Ñ˜X gÕ.Ð1EÕEÈÕP×YÑYÓ[Ö\ñ /ô �9Š9�\Ó"Ð"r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r²   r	   Úwindow_kernel_sizeztuple[int, int]r   r   r   r   )r   s   "r   r   r   g  s2   € ÷ bñ bØðbØ4CðbØMXðbàñbr   c                óÞ   € Ve   VP                  RR4      ;pe   V# Vw  rE\        V R,          P                  4       4      V,          \        V R,          P                  4       4      V,          3# )u¬  Get post-window-merge `(merged_h, merged_w)` Python ints, or pop from `kwargs` if precomputed.

`.view()` needs Python ints, but `target_sizes[0].item()` is non-traceable. Callers must pop
the precomputed value from `kwargs` when running under `torch.export`. Assumes uniform
`target_sizes` across the batch (standard NaViT preprocessing output).

Args:
    target_sizes: `(num_images, 2)` int â€” `(h, w)` per image.
    window_kernel_size: `(window_h, window_w)` window-attention kernel.
    kwargs: optional caller kwargs â€” if it contains `"merged_shape"` it is popped and returned.

Returns:
    `(merged_h, merged_w)`: per-image grid size after window merging, as Python ints.
NÚmerged_shape)r   r   )r   r   )r    r<   Úitem)r²   rÂ   r   ÚmergedÚwindow_hÚwindow_ws   &&&   r   Úget_vision_merged_shaperÉ   g  sh   € ð" Ò¨¯©°NÀDÓ)IÐI˜vÒVØˆØ+Ñ€HÜˆ|˜DÕ!×&Ñ&Ó(Ó)¨XÕ5´s¸<ÈÕ;M×;RÑ;RÓ;TÓ7UÐYaÕ7aÐaÐar   )FN)N)Úborder)rz   Fr   rÊ   N)TN)Ú__doc__Ú
__future__r   r!   Útorch.nn.functionalÚnnÚ
functionalr&   Úconfiguration_utilsr   Úutilsr   Úutils.genericr   Ú
get_loggerÚ__name__r®   r*   r/   rS   rp   r�   r©   r°   rÀ   rÉ   r   r   r   Ú<module>rÕ      sn   ðñõ #ã ß Ð å 1Ý Ý )ð 
×	Ò	˜HÓ	%€÷F÷4
"÷.*÷b:+÷z%÷PB÷J<÷4#÷Bbñ br   