+
    œ°³jL  ã                   ó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   "Úf/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/integrations/flash_paged.pyÚ__annotate__r      sê   € ÷ Zñ ZÜ�H‰H�O‰OðZä‡|�|ðZô ‡|�|ðZô ‡|�|ð	Zô
 —L‘L 4Õ'ðZô ðZô —<‘<ðZô —<‘<¤$¤s¬E¯L©LÐ'8Õ"9Õ9ðZô ðZô œœS¤#˜X�Õ&ðZô —‘ Õ$ðZô Œ5�<‰<˜ÐÕñZó    c                óp  € VP                   R,          VP                   R,          rÜWÜ8w  d3   \        P                  P                  P	                  V^ WÍ,
          .4      p\        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   VV,          pV	V,          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M$R	V9   d   R	VR	,          /M/ p\/        WW#WWVWú3	/ VB pWÜ8w  d   VRRV13,          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,   )Úshaper   r   Ú
functionalÚpadr   ÚconfigÚ_attn_implementationÚgetattrr    Ú
isinstancer   Úupdater'   ÚgetÚ	transposeÚsqueezeÚ
contiguousÚtoÚint32ÚcloneÚscalingr   Ú_paged_decode_forward)r   r   r	   r
   r   r   r   r   r   r   r   ÚkwargsÚhead_dimÚ
v_head_dimÚflash_attn_varlen_funcÚflash_attn_with_kvcacher    Ú
layer_typeÚcustom_kwargsÚattn_outputÚflash_kwargss   &&&&&&&&&&&,         r   Úpaged_attention_forwardrG      s/  € ðL Ÿ7™7 2�;¨¯©°­ˆjØÔÜ�H‰H×Ñ×#Ñ# A¨¨8Õ+@Ð'AÓBˆô 7XØ�‰×*Ñ*ó7Ñ3Ðô
 &-¨VÐ5EÀu×%MÒ%M‘XÐTZ×TiÑTiÐlmÕTmÐopÐSq€NØ%3°xÔ%?Ñ!ÐEX€JÜ�-¤×&Ò&Ø% jÕ1ˆØ# JÕ/ˆð Óà�|‰|ØØØ×&Ñ&Ø˜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°>ÐCZñ
Økwñ
ˆð ÔØ! # {¨
 {Ð"2Õ3ˆØ˜ÐÐ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   e   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_headsr?   Úvalue_cacheÚpermuter8   Úsizer9   r   r:   Úget_block_table_keyr<   r3   r   r7   )r   r   r	   r
   r   r   r    rB   r   rF   Ú	group_idxÚlayer_idx_in_grouprJ   rK   Ú
batch_sizerL   rE   s   &&&&&&&&&,       r   r=   r=   d   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   rG   ÚcompilerÚdisabler=   rM   r   r   Ú<module>r^      s3   ðÛ å @Ý NõZðz ‡�×Ñô."ó ò."r   