+
    ƒ°ñjŽ
  ã                   ó:   € R t ^ RIt^ RIt^ RIHtHt RR R lltR# )a%  HiDream-O1 two-pass attention: tokens [0, ar_len) are causal, [ar_len, T)
attend full K/V. Splitting Q at the boundary avoids the (B, 1, T, T) additive
mask the general-purpose path would build (~500 MB at T~16K) and lets the
gen half hit the user's preferred backend via optimized_attention.
N)ÚAttentionTensorContainerÚoptimized_attentionc                ó$   € V ^8„  d   QhR\         /# )é   Úar_len)Úint)Úformats   "ÚBC:\Ai_Coding\apps\studio\ComfyUI\comfy\ldm\hidream_o1\attention.pyÚ__annotate__r
      s   € ÷ ñ ¤Cñ ó    c                ó    a aa€ RV VV3R llpV# )zÛBuild a two-pass attention callable. AR pass uses SDPA-causal directly, gen pass routes through optimized_attention.
The AR pass goes through SDPA directand bypasses wrappers, it is only ~1% of T at typical edit sizes.
c                 ó  <€ V P                   w  rgr‰W�P                   ^,          8  d6   \        V 4      \        V4      \        V4      r!p \        WW#RRRSSVR7
      p
EM
SV8¼  d'   \        P                  P                  WVRRRVR7      p
MÝS^ 8:  d5   \        V 4      \        V4      \        V4      r!p \        WW#RRRSSVR7
      p
M¢\        P                  P                  V RRRS13,          VRRRS13,          VRRRS13,          RRRVR7      p\        V RRSR13,          4      \        V4      \        V4      r!p \        WW#RRRSSVR7
      p\        P                  ! W¼.^R7      p
V
P                  ^^4      P                  WhWy,          4      # )r   NT)ÚmaskÚskip_reshapeÚskip_output_reshapeÚtransformer_optionsÚpreferred_attentionÚ
enable_gqag        )Ú	attn_maskÚ	dropout_pÚ	is_causalr   :NNN)Údim)
Úshaper   r   ÚcomfyÚopsÚscaled_dot_product_attentionÚtorchÚcatÚ	transposeÚreshape)ÚqÚkÚvÚheadsr   ÚkwargsÚBÚHÚTÚDÚoutÚout_arÚout_genr   r   r   s   &&&&&,       €€€r	   Útwo_pass_attentionÚ3make_two_pass_attention.<locals>.two_pass_attention   s½  ø€ Ø—W‘W‰
ˆˆaà�w‰w�q�zŒ>Ü.¨qÓ1Ô3KÈAÓ3NÔPhÐijÓPk�!ˆAÜ% a¨A¸4ÈdÐhlð  CVð  lð  LVô  WŠCØ�qŒ[Ü—)‘)×8Ñ8¸¸qÈDÐ\_Ðkoð  }GÐ8ó  H‰CØ�qŒ[Ü.¨qÓ1Ô3KÈAÓ3NÔPhÐijÓPk�!ˆAÜ% a¨A¸4ÈdÐhlð  CVð  lð  LVô  W‰Cä—Y‘Y×;Ñ;Ø�!�Q˜˜˜�-Õ  ! A q¨'¨6¨' MÕ"2°A°a¸¸G¸V¸G°mÕ4DØ¨#¸È*ð <ó ˆFô /¨q°°A°v±w°Õ/?Ó@ÔBZÐ[\ÓB]Ô_wÐxyÓ_z�!ˆAÜ)Ø�aØ¨À$Ø$7ÐM`ÐmwôˆGô
 —)’)˜VÐ-°1Ô5ˆCà�}‰}˜Q Ó"×*Ñ*¨1°µÓ7Ð7r   )F© )r   r   r   r,   s   fff r	   Úmake_two_pass_attentionr/      s   ú€ ÷
8ñ 8ð4 Ðr   )NN)Ú__doc__r   Ú	comfy.opsr   Úcomfy.ldm.modules.attentionr   r   r/   r.   r   r	   Ú<module>r3      s   ðñó ã ß U÷ñ r   