+
    ƒ°ñj»  ã                   ó”   € R t ^ RIt^ RIHu Ht ^ RIHt  ! R R]P                  4      t ! R R]P                  4      tR t	R	R lt
R# )
z˜LTX 2.4 DurationHead: predicts the natural shot duration (in seconds) from
the caption connector token outputs, without running the diffusion pipeline.
N)Únnc                   ó@   a a€ ] tR t^
t oRtRV 3R lltR tRtVtV ;t	# )ÚAttentionPoolerzACross-attend ``num_queries`` learnable tokens against ``tokens``.c                óÈ   <€ \         SV `  4        W n        \        P                  ! \
        P                  ! W!4      4      V n        \        P                  ! WR R7      V n	        R# )T)Ú	embed_dimÚ	num_headsÚbatch_firstN)
ÚsuperÚ__init__Únum_queriesr   Ú	ParameterÚtorchÚemptyÚquery_tokensÚMultiheadAttentionÚ
cross_attn)ÚselfÚ
hidden_dimr   r   Ú	__class__s   &&&&€ÚFC:\Ai_Coding\apps\studio\ComfyUI\comfy\ldm\lightricks\duration_head.pyr
   ÚAttentionPooler.__init__   sC   ø€ Ü‰ÑÔØ&ÔÜŸLšL¬¯ª°[Ó)MÓNˆÔÜ×/Ò/¸*ÐgkÔlˆŽó    c                ó¬   € V P                   P                  ^ 4      P                  VP                  ^ ,          RR4      pV P	                  W!VRR7      w  r4V# )é    F)Úneed_weightséÿÿÿÿ)r   Ú	unsqueezeÚexpandÚshaper   )r   ÚtokensÚqueriesÚpooledÚ_s   &&   r   ÚforwardÚAttentionPooler.forward   sJ   € Ø×#Ñ#×-Ñ-¨aÓ0×7Ñ7¸¿¹ÀQ½ÈÈRÓPˆØ—O‘O G°VÈ%�OÓP‰	ˆØˆr   )r   r   r   )é   é   é   ©
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r
   r#   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r   Ú__classdict__s   @@r   r   r   
   s   ù‡ € ÙK÷m÷ò r   r   c                   óD   a a€ ] tR t^t oRtRV 3R lltRR ltRtVtV ;t	# )ÚDurationHeadz?Predict duration in seconds from one or both connector outputs.c                óì  <€ \         SV `  4        \        P                  ! W4      V n        \        P
                  ! \        P                  ! V4      4      V n        \        P                  ! W#4      V n	        \        P
                  ! \        P                  ! V4      4      V n
        \        W4VR 7      V n        \        P                  ! W4,          V4      V n        \        P                  ! V^4      V n        R# ))r   r   r   N)r	   r
   r   ÚLinearÚvideo_input_projr   r   r   Úvideo_modality_embÚaudio_input_projÚaudio_modality_embr   Úattention_poolerÚ
mlp_hiddenÚmlp_out)r   Úvideo_cross_attention_dimÚaudio_cross_attention_dimÚpooler_hidden_dimr   Únum_pooler_headsr<   r   s   &&&&&&&€r   r
   ÚDurationHead.__init__   s¦   ø€ ô 	‰ÑÔÜ "§	¢	Ð*CÓ WˆÔÜ"$§,¢,¬u¯{ª{Ð;LÓ/MÓ"NˆÔÜ "§	¢	Ð*CÓ WˆÔÜ"$§,¢,¬u¯{ª{Ð;LÓ/MÓ"NˆÔÜ /Ø(ÐM]ô!_ˆÔäŸ)š)Ð$5Õ$CÀZÓPˆŒÜ—y’y ¨QÓ/ˆŽr   c                ó>  € . pVe2   VP                  V P                  V4      V P                  ,           4       Ve2   VP                  V P                  V4      V P                  ,           4       V'       g   \        R4      hV P                  \        P                  ! V^R7      4      pVP                  VP                  ^ ,          R4      p\        P                  ! V P                  V4      RR7      pV P                  V4      P                  R4      P!                  4       # )zƒ``video_tokens``: (B, T_v, 4096), ``audio_tokens``: (B, T_a, 2048);
at least one required. Returns duration in seconds, shape (B,).zADurationHead requires at least one of video_tokens / audio_tokens)ÚdimÚtanh)Úapproximater   )Úappendr7   r8   r9   r:   Ú
ValueErrorr;   r   ÚcatÚreshaper   ÚFÚgelur<   r=   ÚsqueezeÚexp)r   Úvideo_tokensÚaudio_tokensÚtoken_groupsr!   Úhiddens   &&&   r   r#   ÚDurationHead.forward/   sÛ   € ð ˆØÒ#Ø×Ñ × 5Ñ 5°lÓ CÀd×F]ÑF]Õ ]Ô^ØÒ#Ø×Ñ × 5Ñ 5°lÓ CÀd×F]ÑF]Õ ]Ô^ßÜÐ`ÓaÐaØ×&Ñ&¤u§y¢y°À1Ô'EÓFˆØ—‘ §¡¨Q¥°Ó4ˆÜ—’˜Ÿ™¨Ó/¸VÔDˆØ�|‰|˜FÓ#×+Ñ+¨BÓ/×3Ñ3Ó5Ð5r   )r;   r9   r:   r<   r=   r7   r8   )i   i   r%   r&   r'   r%   )NNr(   r1   s   @@r   r4   r4      s   ù‡ € ÙI÷0÷&6ô 6r   r4   c           	      óÎ   € R FX  pV P                  4        UUu/ uF-  w  r#VP                  V4      '       g   K  V\        V4      R VbK/  	  pppV'       g   KV  Vu # 	  V # u uppi )ú$model.diffusion_model.duration_head.N)rU   zduration_head.)ÚitemsÚ
startswithÚlen)ÚsdÚprefixÚkÚvÚstrippeds   &    r   Únormalize_state_dictr^   ?   s]   € ÛLˆØ35·8±8´:ÔV±:©4¨1ÀÇÁÈf×AUÔ&�A”c˜&“k�l�O QÒ&±:ˆÑVß‰8ØŠOñ Mð €Iùó Ws
   ™A!¹A!c           	     óD  € \        ^\        W!,          4      4      p\        W1,          4      p\        V\        \        W,          4      V4      4      pV^,
          V,          V,          ^,           pW…8  d+   \        V^,
          ) V,          ) V,          ^,           V4      pV# )zÛConvert seconds to a frame count clamped to ``[min_seconds, max_seconds]``
and snapped (floor) to the VAE's ``8k + 1`` causal temporal grid; snapping
that undershoots the minimum bumps up to the next grid point instead.)ÚmaxÚroundÚmin)	ÚsecondsÚ
frame_rateÚmin_secondsÚmax_secondsÚ
time_scaleÚ
min_framesÚ
max_framesÚ
raw_framesÚframess	   &&&&&    r   Úseconds_to_num_framesrl   G   sˆ   € ô �Qœ˜kÕ6Ó7Ó8€JÜ�{Õ/Ó0€JÜ�Z¤¤U¨7Õ+?Ó%@À*Ó!MÓN€JØ˜1�n Õ+¨jÕ8¸1Õ<€FØÔÜ˜ a�Ð(¨JÕ6Ð7¸*ÕDÀqÕHÈ*ÓUˆØ€Mr   )é   )r-   r   Útorch.nn.functionalr   Ú
functionalrK   ÚModuler   r4   r^   rl   © r   r   Ú<module>rr      sC   ðñó ß Ð Ý ô�b—i‘iô ô#6�2—9‘9ô #6òLö
r   