+
    QV-j§  ã                   óp   € ^ RI t ^RIHt ^RIHt R R lt] P                  P                  R R l4       tR# )é    N)ÚPagedAttentionCache)Ú!lazy_import_paged_flash_attentionc                ó*  € V ^8„  d   QhR\         P                  P                  R\         P                  R\         P                  R\         P                  R\         P                  R,          R\        R\         P                  R	\         P                  \
        \        \         P                  3,          ,          R
\        R\        \
        \        \        3,          ,          R\         P                  R,          R\        \         P                  R3,          /# )é   ÚmoduleÚqÚkÚvÚattention_maskNÚcacheÚcu_seq_lens_qÚcu_seq_lens_kÚmax_seqlen_qÚmax_seqlen_kÚblock_tableÚreturn)	ÚtorchÚnnÚModuleÚTensorr   ÚdictÚstrÚintÚtuple)Úformats   "Úv/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/integrations/flash_paged.pyÚ__annotate__r      sê   € ÷ Qñ QÜ�H‰H�O‰OðQä‡|�|ðQô ‡|�|ðQô ‡|�|ð	Qô
 —L‘L 4Õ'ðQô ðQô —<‘<ðQô —<‘<¤$¤s¬E¯L©LÐ'8Õ"9Õ9ðQô ðQô œœS¤#˜X�Õ&ðQô —‘ Õ$ðQô Œ5�<‰<˜ÐÕñQó    c                ó’  € \        V P                  P                  4      w  rÍ\        V RR4      '       g   RMV P                  ^,
          ^ 3pVR8X  d   RMRp\        V\        4      '       d   W,          pWŸ,          p	V
Ef    VP                  VVV P                  VR,          VR,          R7      w  r#R	V9   d   R	VP                  R	4      /M/ pV! VP                  ^^4      P                  ^ 4      P                  4       VP                  4       VP                  4       VP                  \        P                  4      VP                  \        P                  4      P!                  4       VV	3R
V P"                  RRRV/VB p\        V\$        4      '       d
   V^ ,          pVR3# R	V9   d   R	VR	,          /M/ p\'        WW#WWWíV
3	/ VB pVR3# )a   Performs the forward pass of attention with paged key-value cache. This function handles the cache updates and
performs the attention computation. For decode-only batches (when block_table is provided), uses
`flash_attn_with_kvcache` for fused attention + cache update. Otherwise uses `flash_attn_varlen_func`.
See the [paged attention guide](https://huggingface.co/docs/transformers/en/paged_attention) for more details.

Args:
    q: (1, nheads, total_q, headdim), where total_q = total number of query tokens in the batch.
    k: (1, nheads_k, total_k, headdim), where total_k = total number of key tokens in the batch.
    v: (1, nheads_k, total_k, headdim), where total_k = total number of key tokens in the batch.
    cu_seq_lens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
       of the sequences in the batch, used to index into q.
    cu_seq_lens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
       of the sequences in the batch, used to index into kv.
    max_seqlen_q: int. Maximum query sequence length in the batch.
    max_seqlen_k: int. Maximum key sequence length in the batch.
    block_table: (num_groups, batch_size, max_blocks_per_seq), dtype int32. Block table for paged KV cache.
        If provided, uses flash_attn_with_kvcache for fused attention + cache update. For each request, the block
        table is a vector of size (max_blocks_per_seq,) with indices indicating the physical location of the cache
        to read from and write to. The kernel, using the cache_seqlens for that request, knows how much cache to
        read and dispatches the read using the block table. Same for the write. If a request has fewer than
        max_blocks_per_seq blocks, the block table is padded with -1s to indicate that the block is not allocated.
Úsliding_windowFÚfull_attentionÚsliding_attentionNÚ
read_indexÚwrite_index)Ú
key_statesÚvalue_statesÚ	layer_idxr#   r$   Ús_auxÚsoftmax_scaleÚcausalTÚwindow_size)éÿÿÿÿr,   )r   ÚconfigÚ_attn_implementationÚgetattrr    Ú
isinstancer   Úupdater'   ÚgetÚ	transposeÚsqueezeÚ
contiguousÚtor   Úint32ÚcloneÚscalingr   Ú_paged_decode_forward)r   r   r	   r
   r   r   r   r   r   r   r   ÚkwargsÚflash_attn_varlen_funcÚflash_attn_with_kvcacher    Ú
layer_typeÚcustom_kwargsÚattn_outputÚflash_kwargss   &&&&&&&&&&&,       r   Úpaged_attention_forwardrB      sÛ  € ôJ 7XØ�‰×*Ñ*ó7Ñ3Ðô
 &-¨VÐ5EÀu×%MÒ%M‘XÐTZ×TiÑTiÐlmÕTmÐopÐSq€NØ%3°xÔ%?Ñ!ÐEX€JÜ�-¤×&Ò&Ø%Õ1ˆØ#Õ/ˆð Óà�|‰|ØØØ×&Ñ&Ø˜lÕ+Ø˜}Õ-ð ó 
‰ˆð ;BÀVÔ:K˜ &§*¡*¨WÓ"5Ñ6ÐQSˆÙ,Ø�K‰K˜˜1Ó×%Ñ% aÓ(×3Ñ3Ó5Ø�L‰L‹NØ�L‰L‹NØ×ÑœUŸ[™[Ó)Ø×ÑœUŸ[™[Ó)×/Ñ/Ó1ØØñ
ð !Ÿ.™.ð
ð ð
ð 'ð
ð ñ
ˆô �k¤5×)Ò)Ø% a�.ˆKð ˜ÐÐð	 6=ÀÔ5F˜ ¨¥Ñ1ÈBˆÜ+Ø�q˜U°>Ð\gñ
Økwñ
ˆð ˜ÐÐr   c                óF  € V ^8„  d   QhR\         P                  P                  R\         P                  R\         P                  R\         P                  R\        R\         P                  R\
        \        \        3,          R\         P                  R	\         P                  /	# )
r   r   r   r	   r
   r   r   r    r   r   )r   r   r   r   r   r   r   )r   s   "r   r   r   \   sŠ   € ÷ ."ñ ."Ü�H‰H�O‰Oð."ä‡|�|ð."ô ‡|�|ð."ô ‡|�|ð	."ô
 ð."ô —<‘<ð."ô œ#œs˜(•Oð."ô —‘ð."ô ‡\�\ñ."r   c	                óˆ  € VP                   V P                  ,          w  r«VP                  V,          P                  RVP                  VP
                  VP                  4      pVP                  V,          P                  RVP                  VP
                  VP                  4      pVP                  ^^ ^^4      P                  4       pVP                  ^^ ^^4      P                  4       pVP                  ^^ ^^4      P                  4       pVP                  ^ 4      pV^V^,            VRV ,
          ^,
          P                  \        P                  4      pWŠ,          W”P                  V4      &   V! RRVRVRVRVRVRVRV P                  R	R
RV/	V	B p\!        V\"        4      '       d
   V^ ,          pVP%                  ^4      # )zaDecode fast path using flash_attn_with_kvcache. Disabled because FA3 has issue with tracing this.Nr   Úk_cacheÚv_cacher	   r
   Úcache_seqlensr)   r*   Tr+   r,   © )Úlayer_index_to_group_indicesr'   Ú	key_cacheÚviewÚ
block_sizeÚnum_key_value_headsÚhead_dimÚvalue_cacheÚpermuter5   Úsizer6   r   r7   Úget_block_table_keyr9   r0   r   r4   )r   r   r	   r
   r   r   r    r=   r   rA   Ú	group_idxÚlayer_idx_in_grouprE   rF   Ú
batch_sizerG   r@   s   &&&&&&&&&,       r   r:   r:   [   sÏ  € ð %*×$FÑ$FÀv×GWÑGWÕ$XÑ!€Ià�o‰oÐ0Õ1×6Ñ6°r¸5×;KÑ;KÈU×MfÑMfÐhm×hvÑhvÓw€GØ×ÑÐ 2Õ3×8Ñ8Ø
ˆE×Ñ˜e×7Ñ7¸¿¹ó€Gð 	
�	‰	�!�Q˜˜1Ó×(Ñ(Ó*€AØ	�	‰	�!�Q˜˜1Ó×(Ñ(Ó*€AØ	�	‰	�!�Q˜˜1Ó×(Ñ(Ó*€Að —‘˜“€JØ" 1 z°A¥~Ð6¸À{È
Ð9SÕSÐVWÕW×[Ñ[Ô\a×\gÑ\gÓh€MàGRÕG]€L×*Ñ*Ð+BÓCÑDá)ñ Ø
ðàðð ðð ð	ð
 ðð $ðð —n‘nðð ðð #ðð ñ€Kô �+œu×%Ò%Ø! !•nˆà×Ñ˜qÓ!Ð!r   )	r   Úgeneration.continuous_batchingr   Úmodeling_flash_attention_utilsr   rB   ÚcompilerÚdisabler:   rH   r   r   Ú<module>rZ      s3   ðÛ å @Ý NõQðh ‡�×Ñô."ó ò."r   