+
    ƒ°ñj"`  ã                   óÎ   € R t ^ RIHtHt ^ RIt^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIt^ RIt^RIHtHtHtHtHt ^RIHtHt  ! R	 R
]4      t ! R R]P2                  4      tR# )z^
A general implementation of adaln-modulated VIT-like~(DiT) transformer for video processing.
)ÚOptionalÚTupleN)Ú	rearrange)Únn)Ú
transforms)ÚEnum)Ú
FinalLayerÚGeneralDITTransformerBlockÚ
PatchEmbedÚTimestepEmbeddingÚ	Timesteps)ÚLearnablePosEmbAxisÚVideoRopePosition3DEmbc                   ó   € ] tR t^+tRtRtRtR# )ÚDataTypeÚimageÚvideo© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚIMAGEÚVIDEOÚ__static_attributes__r   ó    Ú:C:\Ai_Coding\apps\studio\ComfyUI\comfy\ldm\cosmos\model.pyr   r   +   s   † Ø€EØ„Er   r   c            	       ó.  a a€ ] tR t^0t oRtRV3R lV 3R llltRR ltRV3R lR lltRV3R lR	 lltRRRRR]	P                  RR3V3R
 lR lltRRRRR]	P                  RRR3	V3R lR lltRRRRR]	P                  RRR3	V3R lR lltRtVtV ;t# )Ú
GeneralDITaò	  
A general implementation of adaln-modulated VIT-like~(DiT) transformer for video processing.

Args:
    max_img_h (int): Maximum height of the input images.
    max_img_w (int): Maximum width of the input images.
    max_frames (int): Maximum number of frames in the video sequence.
    in_channels (int): Number of input channels (e.g., RGB channels for color images).
    out_channels (int): Number of output channels.
    patch_spatial (tuple): Spatial resolution of patches for input processing.
    patch_temporal (int): Temporal resolution of patches for input processing.
    concat_padding_mask (bool): If True, includes a mask channel in the input to handle padding.
    block_config (str): Configuration of the transformer block. See Notes for supported block types.
    model_channels (int): Base number of channels used throughout the model.
    num_blocks (int): Number of transformer blocks.
    num_heads (int): Number of heads in the multi-head attention layers.
    mlp_ratio (float): Expansion ratio for MLP blocks.
    block_x_format (str): Format of input tensor for transformer blocks ('BTHWD' or 'THWBD').
    crossattn_emb_channels (int): Number of embedding channels for cross-attention.
    use_cross_attn_mask (bool): Whether to use mask in cross-attention.
    pos_emb_cls (str): Type of positional embeddings.
    pos_emb_learnable (bool): Whether positional embeddings are learnable.
    pos_emb_interpolation (str): Method for interpolating positional embeddings.
    affline_emb_norm (bool): Whether to normalize affine embeddings.
    use_adaln_lora (bool): Whether to use AdaLN-LoRA.
    adaln_lora_dim (int): Dimension for AdaLN-LoRA.
    rope_h_extrapolation_ratio (float): Height extrapolation ratio for RoPE.
    rope_w_extrapolation_ratio (float): Width extrapolation ratio for RoPE.
    rope_t_extrapolation_ratio (float): Temporal extrapolation ratio for RoPE.
    extra_per_block_abs_pos_emb (bool): Whether to use extra per-block absolute positional embeddings.
    extra_per_block_abs_pos_emb_type (str): Type of extra per-block positional embeddings.
    extra_h_extrapolation_ratio (float): Height extrapolation ratio for extra embeddings.
    extra_w_extrapolation_ratio (float): Width extrapolation ratio for extra embeddings.
    extra_t_extrapolation_ratio (float): Temporal extrapolation ratio for extra embeddings.

Notes:
    Supported block types in block_config:
    * cross_attn, ca: Cross attention
    * full_attn: Full attention on all flattened tokens
    * mlp, ff: Feed forward block
Nc          >      óÒ   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[ RS[RS[ RS[R	S[R
S[ RS[ RS[ RS[RS[RS[ RS[RS[RS[RS[RS[RS[RS[ RS[RS[RS[RS[RS[RS[RS[RS[RR /# )!é   Ú	max_img_hÚ	max_img_wÚ
max_framesÚin_channelsÚout_channelsÚpatch_spatialÚpatch_temporalÚconcat_padding_maskÚblock_configÚmodel_channelsÚ
num_blocksÚ	num_headsÚ	mlp_ratioÚblock_x_formatÚcrossattn_emb_channelsÚuse_cross_attn_maskÚpos_emb_clsÚpos_emb_learnableÚpos_emb_interpolationÚaffline_emb_normÚuse_adaln_loraÚadaln_lora_dimÚrope_h_extrapolation_ratioÚrope_w_extrapolation_ratioÚrope_t_extrapolation_ratioÚextra_per_block_abs_pos_embÚ extra_per_block_abs_pos_emb_typeÚextra_h_extrapolation_ratioÚextra_w_extrapolation_ratioÚextra_t_extrapolation_ratioÚreturnN)ÚintÚtupleÚboolÚstrÚfloat)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚGeneralDIT.__annotate__[   sj  ø€ ÷ x
ñ x
áðx
ñ ðx
ñ ð	x
ñ
 ðx
ñ ðx
ñ ðx
ñ ðx
ñ "ðx
ñ ðx
ñ ðx
ñ ðx
ñ ðx
ñ ðx
ñ  ð!x
ñ$ !$ð%x
ñ& "ð'x
ñ* ð+x
ñ,  ð-x
ñ.  #ð/x
ñ0 ð1x
ñ2 ð3x
ñ4 ð5x
ñ6 %*ð7x
ñ8 %*ð9x
ñ: %*ð;x
ñ< &*ð=x
ñ> +.ð?x
ñ@ &+ðAx
ñB &+ðCx
ñD &+ðEx
ðN 
ñOx
r   c#                ó¶  <€ \         S%V `  4        Wn        W n        W0n        W@n        WPn        W`n        Wpn        WÀn	        W°n
        W n        VV n        W€n        VV n        VV n        VV n        VV n        VV n        VV n        VV n        VV n        VP-                  4       V n        VV n        VV n        VV n        V!V n        R V RV!/p#V'       d
   V^,           MTp\9        VVVV
RV#V"R7      V n        V P=                  V V!R7       Wàn        VV n         VV n!        \D        PF                  ! \I        V
4      \K        WªVV#V"R7      .4      V n&        \D        PN                  ! 4       V n(        \S        V4       F2  p$\U        V
VVV	VV P>                  VVV#V"R7
      V PP                  RV$ 2&   K4  	  V P"                  '       d3   \V        PX                  ! R4       V"P[                  V
R	R
V V!R7      V n.        M\D        P^                  ! 4       V n.        \a        V P                  V P                  V P                  V P                  V P@                  V PB                  V#V"R7      V n1        R# )ÚdeviceÚdtypeF)Úspatial_patch_sizeÚtemporal_patch_sizer$   r%   ÚbiasÚweight_argsÚ
operations)rJ   rK   )r5   rO   rP   )
Úx_dimÚcontext_dimr,   r)   r-   Úx_formatr5   r6   rO   rP   Úblockz-Building affine embedding normalization layerTg�íµ ÷Æ°>)Úelementwise_affineÚepsrJ   rK   )Úhidden_sizerL   rM   r%   r5   r6   rO   rP   N)2ÚsuperÚ__init__r!   r"   r#   r$   r%   r&   r'   r,   r+   r*   r0   r(   r1   r2   r3   r4   r7   r8   r9   r:   Úlowerr;   r<   r=   r>   rK   r
   Ú
x_embedderÚbuild_pos_embedr.   r5   r6   r   Ú
ModuleListr   r   Ú
t_embedderÚ
ModuleDictÚblocksÚranger	   ÚloggingÚdebugÚRMSNormÚaffline_normÚIdentityr   Úfinal_layer)&Úselfr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   Úimage_modelrJ   rK   rP   rO   ÚidxÚ	__class__s&   &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&  €r   rY   ÚGeneralDIT.__init__[   sX  ø€ ôP 	‰ÑÔØ"ŒØ"ŒØ$ŒØ&ÔØ(ÔØ*ÔØ,ÔØ"ŒØ$ŒØ,ÔØ#6ˆÔ Ø#6Ô à&ˆÔØ!2ˆÔØ%:ˆÔ"Ø 0ˆÔØ*DˆÔ'Ø*DˆÔ'Ø*DˆÔ'Ø+FˆÔ(Ø0P×0VÑ0VÓ0XˆÔ-Ø+FˆÔ(Ø+FˆÔ(Ø+FˆÔ(ØˆŒ
Ø ¨°%Ð8ˆç)<�k A–oÀ+ˆÜ$Ø,Ø .Ø#Ø'ØØ#Ø!ô
ˆŒð 	×Ñ F°%ÐÔ8Ø,ÔØ,ˆÔØ,ˆÔÜŸ-š-Ü�~Ó&Ü˜~ÈnÐjuð  CMô  NðPó
ˆŒô
 —m’m“oˆŒä˜Ö$ˆCÜ)CØ$Ø2Ø#Ø)Ø#Ø×,Ñ,Ø-Ø-Ø'Ø%ô*ˆD�K‰K˜% ˜u˜Ó&ñ %ð × × Ð Ü�MŠMÐIÔJØ *× 2Ñ 2°>ÐVZÐ`dÐmsð  |AÐ 2ó  !BˆDÕä "§¢£ˆDÔä%Ø×+Ñ+Ø#×1Ñ1Ø $× 3Ñ 3Ø×*Ñ*Ø×.Ñ.Ø×.Ñ.Ø#Ø!ô	
ˆÖr   c                óD  € V P                   R 8X  d   \        pM\        RV P                    24      h\        P                  ! RV P                    RV 24       \        V P                  V P                  V P                  ,          V P                  V P                  ,          V P                  V P                  ,          V P                  V P                  V P                  V P                  ,          V P                  V P                   V P"                  VR7      pV! R/ VB V n        V P&                  '       dm   V P(                  R9   g   Q RV P(                   24       hV P*                  VR&   V P,                  VR&   V P.                  VR&   WR	&   W$R
&   \1        R/ VB V n        R# R# )Úrope3dzUnknown pos_emb_cls z#Building positional embedding with z class, impl )r*   Úlen_hÚlen_wÚlen_tÚis_learnableÚinterpolationÚhead_dimÚh_extrapolation_ratioÚw_extrapolation_ratioÚt_extrapolation_ratiorJ   z)Unknown extra_per_block_abs_pos_emb_type ru   rv   rw   rJ   rK   Nr   )Ú	learnable)r1   r   Ú
ValueErrorrb   rc   Údictr*   r!   r&   r"   r#   r'   r2   r3   r,   r7   r8   r9   Úpos_embedderr:   r;   r<   r=   r>   r   Úextra_pos_embedder)rh   rJ   rK   Úcls_typeÚkwargss   &&&  r   r\   ÚGeneralDIT.build_pos_embedÕ   s•  € Ø×Ñ˜xÔ'Ü-‰HäÐ3°D×4DÑ4DÐ3EÐFÓGÐGä�ŠÐ;¸D×<LÑ<LÐ;MÈ]Ð[cÐZdÐeÔfÜØ×.Ñ.Ø—.‘. D×$6Ñ$6Õ6Ø—.‘. D×$6Ñ$6Õ6Ø—/‘/ T×%8Ñ%8Õ8Ø×/Ñ/Ø×4Ñ4Ø×(Ñ(¨D¯N©NÕ:Ø"&×"AÑ"AØ"&×"AÑ"AØ"&×"AÑ"AØô
ˆñ %ñ 
Øñ
ˆÔð ×+×+Ð+Ø×8Ñ8ð =ô ð cà:¸4×;`Ñ;`Ð:aÐbócð ð /3×.NÑ.NˆFÐ*Ñ+Ø.2×.NÑ.NˆFÐ*Ñ+Ø.2×.NÑ.NˆFÐ*Ñ+Ø%�8ÑØ#�7‰OÜ&9ñ 'Øñ'ˆDÖ#ñ ,r   c                ó0  <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  S[S[ P                  ,          3,          /# )r    Úx_B_C_T_H_WÚfpsÚpadding_maskÚlatent_conditionÚlatent_condition_sigmar?   )ÚtorchÚTensorr   r   )rE   rF   s   "€r   rG   rH   ú   s†   ø€ ÷ :0ñ :0á—\‘\ð:0ñ ‘e—l‘lÕ#ð:0ñ ™uŸ|™|Õ,ð	:0ñ
 #¡5§<¡<Õ0ð:0ñ !)©¯©Õ 6ð:0ñ 
‰u�|‰|™X¡e§l¡lÕ3Ð3Õ	4ñ:0r   c           
     ó  € V P                   '       Ed   VeR   \        P                  P                  V\	        VP
                  R
R 4      \        P                  P                  R7      pMd\        P                  ! VP
                  ^ ,          ^VP
                  R
,          VP
                  R,          3VP                  VP                  R7      p\        P                  ! WP                  ^4      P                  ^^VP
                  ^,          ^^4      .^R7      pV P                  V4      pV P                   '       d*   V P#                  WbVP                  VP                  R7      pMRpRV P$                  P'                  4       9   d    W`P)                  WbVP                  R7      V3# RV P$                  9   d%   W`P)                  WbVP                  R7      ,           pM"W`P)                  WaP                  R	7      ,           pVRV3# )a  
Prepares an embedded sequence tensor by applying positional embeddings and handling padding masks.

Args:
    x_B_C_T_H_W (torch.Tensor): video
    fps (Optional[torch.Tensor]): Frames per second tensor to be used for positional embedding when required.
                            If None, a default value (`self.base_fps`) will be used.
    padding_mask (Optional[torch.Tensor]): current it is not used

Returns:
    Tuple[torch.Tensor, Optional[torch.Tensor]]:
        - A tensor of shape (B, T, H, W, D) with the embedded sequence.
        - An optional positional embedding tensor, returned only if the positional embedding class
        (`self.pos_emb_cls`) includes 'rope'. Otherwise, None.

Notes:
    - If `self.concat_padding_mask` is True, a padding mask channel is concatenated to the input tensor.
    - The method of applying positional embeddings depends on the value of `self.pos_emb_cls`.
    - If 'rope' is in `self.pos_emb_cls` (case insensitive), the positional embeddings are generated using
        the `self.pos_embedder` with the shape [T, H, W].
    - If "fps_aware" is in `self.pos_emb_cls`, the positional embeddings are generated using the
    `self.pos_embedder` with the fps tensor.
    - Otherwise, the positional embeddings are generated without considering fps.
N)rs   )rK   rJ   )Údim)r‚   rJ   rK   Úrope)r‚   rJ   Ú	fps_aware)rJ   éþÿÿÿéÿÿÿÿ)r(   r   Ú
functionalÚresizeÚlistÚshapeÚInterpolationModeÚNEARESTr†   ÚzerosrK   rJ   ÚcatÚ	unsqueezeÚrepeatr[   r:   r|   r1   rZ   r{   )rh   r�   r‚   rƒ   r„   r…   Úx_B_T_H_W_DÚextra_pos_embs   &&&&&&  r   Úprepare_embedded_sequenceÚ$GeneralDIT.prepare_embedded_sequenceú   sÙ  € ð@ ×#×#Ñ#ØÒ'Ü)×4Ñ4×;Ñ;Ø ¤$ {×'8Ñ'8¸¸Ð'=Ó">Ìj×NjÑNj×NrÑNrð  <ó  ‘ô  %Ÿ{š{¨K×,=Ñ,=¸aÕ,@À!À[×EVÑEVÐWYÕEZÐ\g×\mÑ\mÐnpÕ\qÐ+rð  {F÷  {Lñ  {Lð  U`÷  Ugñ  Ugô   h�äŸ)š)Ø×4Ñ4°QÓ7×>Ñ>¸qÀ!À[×EVÑEVÐWXÕEYÐ[\Ð^_Ó`ÐaÐghôˆKð —o‘o kÓ2ˆà×+×+Ð+Ø ×3Ñ3°KÐQ\×QcÑQcÐkv×k|Ñk|Ð3Ó}‰Mà ˆMà�T×%Ñ%×+Ñ+Ó-Ô-Ø× 1Ñ 1°+È{×OaÑOaÐ 1Ó bÐdqÐqÐqà˜$×*Ñ*Ô*Ø%×(9Ñ(9¸+ÐWb×WiÑWiÐ(9Ó(jÕj‰Kà%×(9Ñ(9¸+×N`ÑN`Ð(9Ó(aÕaˆKà˜D -Ð/Ð/r   c                óþ   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[S[S[S[S[S[3,          RS[S[ P                  ,          RS[S[ P                  ,          RS[ P                  /# )r    r˜   Úemb_B_DÚcrossattn_embÚorigin_shapeÚcrossattn_maskÚadaln_lora_B_3Dr?   )r†   r‡   r   r@   r   )rE   rF   s   "€r   rG   rH   6  sƒ   ø€ ÷ ñ á—\‘\ðñ —‘ðñ —|‘|ð	ñ
 ™C¡¡c©3±Ð3Õ4ðñ !¡§¡Õ.ðñ "¡%§,¡,Õ/ðñ 
�‰ñr   c                óš  € ??Vw  rxršp\        VR 4      pV P                  WÂVR7      pVP                  Wy,          V P                  ,          W P                  ,          V,          V P                  ,          R4      p\        VRV P                  V P                  W P                  ,          W°P                  ,          V P                  VR7      pV# )zB T H W D -> (B T) (H W) D)r¡   z2(B T) (H W) (p1 p2 t C) -> B C (T t) (H p1) (W p2))Úp1Úp2ÚHÚWÚtÚBr�   )r   rg   Úviewr'   r&   )rh   r˜   r�   rž   rŸ   r    r¡   r¨   ÚCÚT_before_patchifyÚH_before_patchifyÚW_before_patchifyÚ	x_BT_HW_DÚx_B_D_T_H_Ws   &&&&&&&       r   Údecoder_headÚGeneralDIT.decoder_head6  sÊ   € ð ˜>ØHTÑEˆÐÐ4EÜ˜kÐ+GÓHˆ	Ø×$Ñ$ YÈÐ$ÓYˆ	ð —N‘NØÕ! T×%8Ñ%8Õ8Ø×!3Ñ!3Õ3Ð6GÕGÈ4×K]ÑK]Õ]Øó
ˆ	ô
  ØØ@Ø×!Ñ!Ø×!Ñ!Ø×#5Ñ#5Õ5Ø×#5Ñ#5Õ5Ø×!Ñ!Øô	
ˆð Ðr   c                ó¾  <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          R	S[S[,          R
S[S[ P                  ,          RS[S[ P                  ,          RS[ P                  /# )r    ÚxÚ	timestepsrž   r    r‚   Ú
image_sizerƒ   Úscalar_featureÚ	data_typer„   r…   r?   ©r†   r‡   r   r   )rE   rF   s   "€r   rG   rH   V  så   ø€ ÷ Oñ Oá�<‰<ðOñ —<‘<ðOñ —|‘|ð	Oñ
 !¡§¡Õ.ðOñ ‘e—l‘lÕ#ðOñ ™UŸ\™\Õ*ðOñ ™uŸ|™|Õ,ðOñ !¡§¡Õ.ðOñ ™HÕ%ðOñ #¡5§<¡<Õ0ðOñ !)©¯©Õ 6ðOñ 
�‰ñOr   c                óŠ  € ?\        V	\        4      '       g   Q R\        V	4       R24       hVP                  pV P	                  VVVV
VR7      w  rïp/ pV P
                  ^,          ! V P
                  ^ ,          ! VP                  4       4      P                  VP                  4      4      w  ppTpVP                  4       VR&   Ve   \        R4      hVP                  4       VR&   V P                  V4      pV P                  '       d|   Ven   \        P                  ! V4      '       gR   V^,
          P                  VP                  4      \        P                  ! VP                  4      P                   ,          pVR,          pMRpV P"                  R,          P$                  R	8X  d>   \'        VR
4      pVe   \'        VR
4      p\'        VR4      pV'       d   \'        VR4      pMNV P"                  R,          P$                  R8X  d   TpM)\)        RV P"                  ^ ,          P$                   24      hRVRVRVRVRVRVRVRV/pV# )zâ
Args:
    x: (B, C, T, H, W) tensor of spatial-temp inputs
    timesteps: (B, ) tensor of timesteps
    crossattn_emb: (B, N, D) tensor of cross-attention embeddings
    crossattn_mask: (B, N) tensor of cross-attention masks
zExpected DataType, got z". We need discuss this flag later.)r‚   rƒ   r„   r…   Útimesteps_B_DNz&Scalar feature is not implemented yet.Úaffline_emb_B_DÚblock0ÚTHWBDzB T H W D -> T H W B DzB M D -> M B Dz
B M -> M BÚBTHWDzUnknown x_format r³   rž   r    Úrope_emb_L_1_1_Dr¡   Úoriginal_shapeÚ$extra_pos_emb_B_T_H_W_D_or_T_H_W_B_D)ºNNNNNrÂ   )Ú
isinstancer   Útyper‘   rš   r^   ÚflattenÚtorK   ÚdetachÚNotImplementedErrorre   r0   r†   Úis_floating_pointÚfinfoÚmaxr`   rS   r   ry   )rh   r³   r´   rž   r    r‚   rµ   rƒ   r¶   r·   r„   r…   r~   rÀ   r˜   r¿   rÁ   Úaffline_scale_log_inforº   r¡   r»   Úoutputs   &&&&&&&&&&&&,         r   Úforward_before_blocksÚ GeneralDIT.forward_before_blocksV  sC  € ð, ÜØ”x÷
ò 
ð 	Yà$¤T¨)£_Ð$5Ð5WÐXó	Yð 
ð Ÿ™ˆØNR×NlÑNlØØØ%Ø-Ø#9ð Omó O
ÑKˆÐ'Kð "$Ðà)-¯©¸Ö);¸D¿O¹OÈAÖ<NÈy×O`ÑO`ÓObÓ<c×<fÑ<fÐgh×gnÑgnÓ<oÓ)pÑ&ˆ�Ø'ˆØ2?×2FÑ2FÓ2HÐ˜Ñ/àÒ%Ü%Ð&NÓOÐOà4C×4JÑ4JÓ4LÐÐ0Ñ1Ø×+Ñ+¨OÓ<ˆà×#×#Ð#ØÒ)´%×2IÒ2IÈ.×2YÒ2YØ"0°1Õ"4×!8Ñ!8¸¿¹Ó!AÄEÇKÂKÐPQ×PWÑPWÓDX×D\ÑD\Õ!\�Ø+Ð,<Õ=‰Nà!ˆNà�;‰;�xÕ ×)Ñ)¨WÔ4Ü˜+Ð'?Ó@ˆAØ3Ò?Ü7@Ø8Ð:Ró8Ð4ô & mÐ5EÓFˆMçÜ!*¨>¸<Ó!H�øà�[‰[˜Õ"×+Ñ+¨wÔ6Ø‰AäÐ0°·±¸Qµ×1HÑ1HÐ0IÐJÓKÐKà�Ø˜Ø˜]Ø˜nØÐ 0Ø˜Ø˜nØ2Ð4Xð	
ˆð ˆr   c                óÎ  <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          R	S[S[,          R
S[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          /# ©r    r³   r´   ÚcontextÚattention_maskr‚   rµ   rƒ   r¶   r·   r„   r…   Úcondition_video_augment_sigmar¸   )rE   rF   s   "€r   rG   rH   §  sÜ   ø€ ÷ "ñ "á�<‰<ð"ñ —<‘<ð"ñ —‘ð	"ñ
 !¡§¡Õ.ð"ñ ‘e—l‘lÕ#ð"ñ ™UŸ\™\Õ*ð"ñ ™uŸ|™|Õ,ð"ñ !¡§¡Õ.ð"ñ ™HÕ%ð"ñ #¡5§<¡<Õ0ð"ñ !)©¯©Õ 6ð"ñ (0±·±Õ'=ñ"r   c                óD  € \         P                  P                  P                  V P                  V \         P                  P                  \         P                  P                  P                  VP                  R / 4      4      4      P                  ! VVVVVVVVV	V
VV3/ VB # )Útransformer_options)
ÚcomfyÚpatcher_extensionÚWrapperExecutorÚnew_class_executorÚ_forwardÚget_all_wrappersÚ
WrappersMPÚDIFFUSION_MODELÚgetÚexecute)rh   r³   r´   rÒ   rÓ   r‚   rµ   rƒ   r¶   r·   r„   r…   rÔ   r~   s   &&&&&&&&&&&&&,r   ÚforwardÚGeneralDIT.forward§  sµ   € ô$ ×&Ñ&×6Ñ6×IÑIØ�M‰MØÜ×#Ñ#×4Ñ4´U×5LÑ5L×5WÑ5W×5gÑ5gÐio×isÑisð  uJð  LNó  jOó  Pó
÷ ‰'ð	ð ØØØØØØØØØ Ø&Ø-ñð  ñ!ð 	r   c                óÎ  <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          R	S[S[,          R
S[S[ P                  ,          RS[S[ P                  ,          RS[S[ P                  ,          /# rÑ   r¸   )rE   rF   s   "€r   rG   rH   Ë  sê   ø€ ÷ ]ñ ]á�<‰<ð]ñ —<‘<ð]ñ —‘ð	]ñ
 !¡§¡Õ.ð]ñ ‘e—l‘lÕ#ð]ñ ™UŸ\™\Õ*ð]ñ ™uŸ|™|Õ,ð]ñ !¡§¡Õ.ð]ñ ™HÕ%ð]ñ #¡5§<¡<Õ0ð]ñ !)©¯©Õ 6ð]ñ (0±·±Õ'=ñ]r   c                óT  € TpTpV P                   ! RRVRVRVRVRVRVRVRVR	V	R
V
RVRV/VB pVR,          VR,          VR,          VR,          VR,          VR,          VR,          3w  pprïpppVR,          P                  VP                  4      p?Ve?   VP                  VP                  8X  g$   Q VP                   RVP                   RV 24       hVP	                  R/ 4      pV P
                  P                  4        F€  w  ppV P
                  R,          P                  VP                  8X  g3   Q RV P
                  ^ ,          P                   RVP                   24       hVe
   VV,          pV! VVVVVVVR7      pK‚  	  \        VR4      pV P                  VVRVRVR7      pV# )a
  
Args:
    x: (B, C, T, H, W) tensor of spatial-temp inputs
    timesteps: (B, ) tensor of timesteps
    crossattn_emb: (B, N, D) tensor of cross-attention embeddings
    crossattn_mask: (B, N) tensor of cross-attention masks
    condition_video_augment_sigma: (B,) used in lvg(long video generation), we add noise with this sigma to
        augment condition input, the lvg model will condition on the condition_video_augment_sigma value;
        we need forward_before_blocks pass to the forward_before_blocks function.
r³   r´   rž   r    r‚   rµ   rƒ   r¶   r·   r„   r…   rÔ   r»   r¿   r¡   rÀ   rÁ   Nz != Ú rÖ   r¼   zFirst block has x_format z, got )r¿   r¡   rÖ   zT H W B D -> B T H W D)r˜   r�   rž   rŸ   r    r¡   r   )
rÎ   rÆ   rK   r‘   rß   r`   ÚitemsrS   r   r°   )rh   r³   r´   rÒ   rÓ   r‚   rµ   rƒ   r¶   r·   r„   r…   rÔ   r~   rž   r    Úinputsr»   r¿   r¡   rÀ   rÁ   rÖ   Ú_rT   r˜   r¯   s   &&&&&&&&&&&&&,             r   rÛ   ÚGeneralDIT._forwardË  sK  € ð:  ˆØ'ˆà×+Ò+ñ 
Øð
àð
ð (ð
ð *ð	
ð
 ð
ð "ð
ð &ð
ð *ð
ð  ð
ð .ð
ð $:ð
ð +Hð
ð ñ
ˆð  �3�KØÐ$Õ%Ø�?Õ#ØÐ#Õ$ØÐ%Õ&ØÐ$Õ%ØÐ#Õ$ðp
Ñlˆˆ?˜MÐ;KÈ_Ð^lð 06Ð6\Õ/]×/`Ñ/`Ðab×ahÑahÓ/iÐ,Øà/Ò;à—‘Ð?×EÑEÔEð]à—'‘'�˜$ÐC×IÑIÐJÈ!ÈNÐK[Ð\ó]ØEð %Ÿj™jÐ)>ÀÓCÐØŸ™×)Ñ)Ö+‰HˆAˆuà—‘˜HÕ%×.Ñ.°%·.±.Ô@ð[à*¨4¯;©;°q­>×+BÑ+BÐ*CÀ6È%Ï.É.ÐIYÐZó[Ø@ð 4Ò?ØÐ9Õ9�ÙØØØØØ!1Ø /Ø$7ôŠAñ ,ô"   Ð#;Ó<ˆà×'Ñ'Ø#Ø#ØØ'ØØ+ð (ó 
ˆð Ðr   )#r6   r4   re   r.   r`   r(   rK   r<   r:   r;   r|   r>   r=   rg   r$   r#   r!   r"   r*   r+   r,   r%   r&   r'   r1   r3   r2   r{   r7   r9   r8   r^   r5   r0   r[   )Tz	FA-CA-MLPi   é
   é   g      @r¾   i   FÚsincosFÚcropFFé   ç      ð?rï   rï   Frì   rï   rï   rï   NNNN)NN)NNNN)r   r   r   r   Ú__doc__rY   r\   rš   r°   r   r   rÎ   rá   rÛ   r   Ú__classdictcell__Ú__classcell__)rk   rF   s   @@r   r   r   0   sÂ   ù‡ € ñ(÷Tx
õ x
ôt#÷J:0ò :0÷xò ðJ 26Ø&*Ø-1Ø/3Ø15Ø(0¯©Ø37Ø9=÷Oò Oðl 26ð '+Ø-1Ø/3Ø15Ø(0¯©Ø37Ø9=Ø@D÷"ò "ðR 26ð '+Ø-1Ø/3Ø15Ø(0¯©Ø37Ø9=Ø@D÷]÷ ]ò ]r   r   )rð   Útypingr   r   r†   Úeinopsr   r   Útorchvisionr   Úenumr   rb   Úcomfy.patcher_extensionr×   r`   r   r	   r
   r   r   Úposition_embeddingr   r   r   ÚModuler   r   r   r   Ú<module>rú      sR   ðñ ÷ #ã Ý Ý Ý "å Û ã ÷õ ÷ Lôˆtô ô
x�—‘ö xr   