
    
3jA                        S SK rS SKrSSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJrJr  SS	KJrJrJr  S
SKJr  \R&                  " \5      r    S+S\S\S\S\4S jjr " S S\5      r S,S\S\R6                  S\S\S\R6                  4
S jjrS\R6                  S\S\S\\\4   4S jr " S S\5      r " S S \5      r  " S! S"\5      r! " S# S$\5      r" " S% S&\5      r# " S' S(\5      r$ " S) S*\5      r%g)-    N   )HeliosTransformer3DModel)HeliosScheduler)logging)randn_tensor   )ModularPipelineBlocksPipelineState)ComponentSpec
InputParamOutputParam   )HeliosModularPipelinebase_seq_lenmax_seq_len
base_shift	max_shiftc                 4    XC-
  X!-
  -  nX5U-  -
  nX-  U-   nU$ )N )image_seq_lenr   r   r   r   mbmus           k/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/modular_pipelines/helios/before_denoise.pycalculate_shiftr      s3     
	K$>?A%%A		Q	BI    c                       \ rS rSrSr\S\4S j5       r\S\\	   4S j5       r
\S\\   4S j5       rS r\R                  " 5       S\S	\S\4S
 j5       rSrg)HeliosTextInputStep,   heliosreturnc                      g)Na  Input processing step that:
  1. Determines `batch_size` and `dtype` based on `prompt_embeds`
  2. Adjusts input tensor shapes based on `batch_size` (number of prompts) and `num_videos_per_prompt`

All input tensors are expected to have either batch_size=1 or match the batch_size
of prompt_embeds. The tensors will be duplicated across the batch dimension to
have a final batch_size of batch_size * num_videos_per_prompt.r   selfs    r   descriptionHeliosTextInputStep.description/   s    M	
r   c                 x    [        SS[        SS9[         R                  " S5      [         R                  " S5      /$ )Nnum_videos_per_promptr   z(Number of videos to generate per prompt.default	type_hintr%   prompt_embedsnegative_prompt_embeds)r   inttemplater#   s    r   inputsHeliosTextInputStep.inputs:   sA     'F	 0 89	
 		
r   c                 R    [        S[        SS9[        S[        R                  SS9/$ )N
batch_sizezdNumber of prompts, the final batch size of model inputs should be batch_size * num_videos_per_promptr+   r%   dtypezFData type of model tensor inputs (determined by `prompt_embeds.dtype`))r   r.   torchr5   r#   s    r   intermediate_outputs(HeliosTextInputStep.intermediate_outputsG   s9      C
 ++d
 	
r   c                    UR                   bw  UR                  bi  UR                   R                  UR                  R                  :w  a:  [        SUR                   R                   SUR                  R                   S35      eg g g )Nzu`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but got: `prompt_embeds` z != `negative_prompt_embeds` .)r,   r-   shape
ValueError)r$   
componentsblock_states      r   check_inputs HeliosTextInputStep.check_inputsV   s    $$0[5W5W5c((..+2T2T2Z2ZZ --8-F-F-L-L,M N#::@@AD  [ 6d0r   r=   statec                    U R                  U5      nU R                  X5        UR                  R                  S   Ul        UR                  R
                  Ul        UR                  R                  u  pEnUR                  R                  SUR                  S5      Ul        UR                  R                  UR                  UR                  -  US5      Ul        UR                  b~  UR                  R                  u  pEnUR                  R                  SUR                  S5      Ul	        UR                  R                  UR                  UR                  -  US5      Ul	        U R                  X#5        X4$ )Nr   r   )get_block_stater?   r,   r;   r3   r5   repeatr(   viewr-   set_block_state)r$   r=   rA   r>   _seq_lens         r   __call__HeliosTextInputStep.__call___   sN   **51*2!,!:!:!@!@!C'55;;#1177A$/$=$=$D$DQHiHikl$m!$/$=$=$B$B""[%F%FFQS%
! --9'>>DDMA1<1S1S1Z1Z;44a2K. 2=1S1S1X1X&&)J)JJGUW2K. 	U0  r   r   N)__name__
__module____qualname____firstlineno__
model_namepropertystrr%   listr   r0   r7   r?   r6   no_gradr   r
   rJ   __static_attributes__r   r   r   r   r   ,   s    J
S 
 
 

Z( 

 

 
d3i 
 
 ]]_!#8 ! !S` ! !r   r   
input_nameinput_tensorr3   r(   r!   c           	          [        U[        R                  5      (       d  [        SU  S35      eUR                  S   S:X  a  X#-  nO7UR                  S   U:X  a  UnO![        SU  SU SUR                  S    35      eUR                  USS9nU$ )a  Repeat tensor elements to match the final batch size.

This function expands a tensor's batch dimension to match the final batch size (batch_size * num_videos_per_prompt)
by repeating each element along dimension 0.

The input tensor must have batch size 1 or batch_size. The function will:
- If batch size is 1: repeat each element (batch_size * num_videos_per_prompt) times
- If batch size equals batch_size: repeat each element num_videos_per_prompt times

Args:
    input_name (str): Name of the input tensor (used for error messages)
    input_tensor (torch.Tensor): The tensor to repeat. Must have batch size 1 or batch_size.
    batch_size (int): The base batch size (number of prompts)
    num_videos_per_prompt (int, optional): Number of videos to generate per prompt. Defaults to 1.

Returns:
    torch.Tensor: The repeated tensor with final batch size (batch_size * num_videos_per_prompt)

Raises:
    ValueError: If input_tensor is not a torch.Tensor or has invalid batch size

Examples:
    tensor = torch.tensor([[1, 2, 3]]) # shape: [1, 3] repeated = repeat_tensor_to_batch_size("image", tensor,
    batch_size=2, num_videos_per_prompt=2) repeated # tensor([[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]) - shape:
    [4, 3]

    tensor = torch.tensor([[1, 2, 3], [4, 5, 6]]) # shape: [2, 3] repeated = repeat_tensor_to_batch_size("image",
    tensor, batch_size=2, num_videos_per_prompt=2) repeated # tensor([[1, 2, 3], [1, 2, 3], [4, 5, 6], [4, 5, 6]])
    - shape: [4, 3]
`z` must be a tensorr   r   z!` must have have batch size 1 or z
, but got dim)
isinstancer6   Tensorr<   r;   repeat_interleave)rV   rW   r3   r(   	repeat_bys        r   repeat_tensor_to_batch_sizer`   |   s    J lELL111ZL(:;<< !!6				A	*	,)	
|<ZL
S_SeSefgShRij
 	

  11)1CLr   latentsvae_scale_factor_temporalvae_scale_factor_spatialc                     U R                   S:w  a  [        SU R                    35      eU R                  u    p4pVUS-
  U-  S-   nXR-  nXb-  n	XxU	4$ )a  Calculate image dimensions from latent tensor dimensions.

This function converts latent temporal and spatial dimensions to image temporal and spatial dimensions by
multiplying the latent num_frames/height/width by the VAE scale factor.

Args:
    latents (torch.Tensor): The latent tensor. Must have 4 or 5 dimensions.
        Expected shapes: [batch, channels, height, width] or [batch, channels, frames, height, width]
    vae_scale_factor_temporal (int): The scale factor used by the VAE to compress temporal dimension.
        Typically 4 for most VAEs (video is 4x larger than latents in temporal dimension)
    vae_scale_factor_spatial (int): The scale factor used by the VAE to compress spatial dimension.
        Typically 8 for most VAEs (image is 8x larger than latents in each dimension)

Returns:
    tuple[int, int]: The calculated image dimensions as (height, width)

Raises:
    ValueError: If latents tensor doesn't have 4 or 5 dimensions

   z(latents must have 5 dimensions, but got r   )ndimr<   r;   )
ra   rb   rc   rH   num_latent_frameslatent_heightlatent_width
num_framesheightwidths
             r    calculate_dimension_from_latentsrm      sg    . ||qCGLL>RSS;B==8Aq]#a'+DDqHJ5F3Eu$$r   c                      ^  \ rS rSrSrSr  SS\\   S-  S\\   S-  4U 4S jjjr\	S\
4S	 j5       r\	S\\   4S
 j5       r\	S\\   4S j5       rS\S\S\4S jrSrU =r$ )HeliosAdditionalInputsStep   a  Configurable step that standardizes inputs for the denoising step.

This step handles:
1. For encoded image latents: Computes height/width from latents and expands batch size
2. For additional_batch_inputs: Expands batch dimensions to match final batch size
r    Nimage_latent_inputsadditional_batch_inputsc                   > Uc  [         R                  " S5      /nUc  / n[        U[        5      (       d  [	        S[        U5       35      eU H/  n[        U[         5      (       a  M  [	        S[        U5       35      e   [        U[        5      (       d  [	        S[        U5       35      eU H/  n[        U[         5      (       a  M  [	        S[        U5       35      e   Xl        X l        [        TU ]%  5         g )Nimage_latentsz,image_latent_inputs must be a list, but got z:image_latent_inputs must be a list of InputParam, but got z0additional_batch_inputs must be a list, but got z>additional_batch_inputs must be a list of InputParam, but got )
r   r/   r\   rS   r<   type_image_latent_inputs_additional_batch_inputssuper__init__)r$   rq   rr   input_param	__class__s       r   ry   #HeliosAdditionalInputsStep.__init__   s    
 &#-#6#6#G"H"*&(#-t44KDQdLeKfghh2!+z::$'abfgrbsat%uvv  3 1488OPTUlPmOnopp6!+z::$XY]^iYjXkl   7 %8!(?%r   r!   c                 l   SnSnU R                   (       d  U R                  (       a|  SnU R                   (       a,  USU R                    Vs/ s H  o3R                  PM     sn 3-  nU R                  (       a,  USU R                   Vs/ s H  o3R                  PM     sn 3-  nSnX-   U-   $ s  snf s  snf )NzInput processing step that:
  1. For image latent inputs: Computes height/width from latents and expands batch size
  2. For additional batch inputs: Expands batch dimensions to match final batch size z

Configured inputs:z
  - Image latent inputs: z
  - Additional batch inputs: zN

This block should be placed after the encoder steps and the text input step.)rv   rw   name)r$   summary_sectioninputs_infopplacement_sections        r   r%   &HeliosAdditionalInputsStep.description   s    c 	 $$(E(E2K((!<dNgNg=hNgffNg=h<ijj,,!@RVRoRoApRoQ&&RoAp@qrrn,/@@@ >iAps   
B,B1c                 d    [        SSS9[        SSS9/nXR                  U R                  -   -  nU$ )Nr(   r   )r   r*   r3   T)r   required)r   rv   rw   )r$   r0   s     r   r0   !HeliosAdditionalInputsStep.inputs  s@     3Q?L48
 	++d.K.KKKr   c                 N   [        S[        S9[        S[        S9/nU R                   H4  nUR                  [        UR                  [
        R                  S95        M6     U R                   H4  nUR                  [        UR                  [
        R                  S95        M6     U$ )Nrk   )r+   rl   )r   r.   rv   appendr   r6   r]   rw   )r$   outputsrz   s      r   r7   /HeliosAdditionalInputsStep.intermediate_outputs  s     C03/

  44KNN;{'7'75<<PQ 5  88KNN;{'7'75<<PQ 9 r   r=   rA   c                 ^   U R                  U5      nU R                   H  n[        X4R                  5      nUc  M  [	        XQR
                  UR                  5      u  pgnXsl        Xl        [        UR                  UUR                  UR                  S9n[        X4R                  U5        M     U R                   H]  n[        X4R                  5      n	U	c  M  [        UR                  U	UR                  UR                  S9n	[        X4R                  U	5        M_     U R                  X#5        X4$ )N)rV   rW   r(   r3   )rD   rv   getattrr   rm   rb   rc   rk   rl   r`   r(   r3   setattrrw   rG   )
r$   r=   rA   r>   rz   image_latent_tensorrH   rk   rl   rW   s
             r   rJ   #HeliosAdditionalInputsStep.__call__-  s)   **5144K")+7G7G"H"*  @#%I%I:KnKn Au "( % #>&++0&1&G&G&11	# K!1!13FG) 5,  88K";0@0@AL#6&++)&1&G&G&11	L K!1!1<@ 9 	U0  r   )rw   rv   )NN)rL   rM   rN   rO   __doc__rP   rS   r   ry   rQ   rR   r%   r0   r   r7   r   r
   rJ   rU   __classcell__)r{   s   @r   ro   ro      s     J 8<;?!*-4 "&j!1D!8 < AS A A& Z(   d;&7  (!#8 (! (!S` (! (!r   ro   c                       \ rS rSrSrSr\S\4S j5       r\S\	\
   4S j5       r\S\	\   4S j5       r\R                  " 5       S\S	\S\4S
 j5       rSrg) HeliosAddNoiseToImageLatentsStepiX  zAdds noise to image_latents and fake_image_latents for I2V conditioning.

Applies single-sigma noise to image_latents (using image_noise_sigma range) and single-sigma noise to
fake_image_latents (using video_noise_sigma range).
r    r!   c                      g)Nz{Adds noise to image_latents and fake_image_latents for I2V conditioning. Uses random sigma from configured ranges for each.r   r#   s    r   r%   ,HeliosAddNoiseToImageLatentsStep.descriptiona  s    A	
r   c                    [         R                  " S5      [        SS[        R                  SS9[        SS[        SS	9[        S
S[        SS	9[        SS[        SS	9[        SS[        SS	9[         R                  " S5      /$ )Nrt   fake_image_latentsTz;Fake image latents used as history seed for I2V generation.r   r+   r%   image_noise_sigma_min"~j?%Minimum sigma for image latent noise.r)   image_noise_sigma_maxHzG?%Maximum sigma for image latent noise.video_noise_sigma_minz0Minimum sigma for video/fake-image latent noise.video_noise_sigma_maxz0Maximum sigma for video/fake-image latent noise.	generator)r   r/   r6   r]   floatr#   s    r   r0   'HeliosAddNoiseToImageLatentsStep.inputsh  s     0$,,Y	 'C	 'C	 'N	 'N	 ,A!
 !	
r   c                 `    [         R                  " S5      [        S[        R                  SS9/$ )Nrt   r   zNoisy fake image latentsr4   r   r/   r6   r]   r#   s    r   r7   5HeliosAddNoiseToImageLatentsStep.intermediate_outputs  s.       1,Rlm
 	
r   r=   rA   c                    U R                  U5      nUR                  nUR                  nUR                  n[        R
                  " SXCR                  S9UR                  UR                  -
  -  UR                  -   nU[        UR                  UR                  US9-  SU-
  U-  -   n[        R
                  " SXCR                  S9UR                  UR                  -
  -  UR                  -   nU[        UR                  UR                  US9-  SU-
  U-  -   nUR                  U[        R                  S9Ul        UR                  U[        R                  S9Ul        U R                  X#5        X4$ )Nr   devicer   r   r   r   r5   )rD   _execution_devicert   r   r6   randr   r   r   r   r;   r   r   tofloat32rG   )	r$   r=   rA   r>   r   rt   r   image_noise_sigmafake_image_noise_sigmas	            r   rJ   )HeliosAddNoiseToImageLatentsStep.__call__  s   **51--#11(;; JJq3H3HI00;3T3TTV//0 	 ]-@-@KLaLajp qq$$56 	 JJq3H3HI00;3T3TTV//0 	 #-33{?T?T]cde))-??@ 	 %2$4$4F%--$4$X!);)>)>fTYTaTa)>)b&U0  r   r   NrL   rM   rN   rO   r   rP   rQ   rR   r%   rS   r   r0   r   r7   r6   rT   r   r
   rJ   rU   r   r   r   r   r   X  s     J
S 
 
 "
Z( "
 "
H 
d;&7 
 
 ]]_"!#8 "! "!S` "! "!r   r   c                       \ rS rSrSrSr\S\4S j5       r\S\	\
   4S j5       r\S\	\   4S j5       r\R                  " 5       S\S	\S\4S
 j5       rSrg) HeliosAddNoiseToVideoLatentsStepi  zAdds noise to image_latents and video_latents for V2V conditioning.

Applies single-sigma noise to image_latents (using image_noise_sigma range) and per-frame noise to video_latents in
chunks (using video_noise_sigma range).
r    r!   c                      g)NzAdds noise to image_latents and video_latents for V2V conditioning. Uses single-sigma noise for image_latents and per-frame noise for video chunks.r   r#   s    r   r%   ,HeliosAddNoiseToVideoLatentsStep.description  s    ^	
r   c                 "   [         R                  " S5      [        SS[        R                  SS9[        SS[        SS	9[        S
S[
        SS	9[        SS[
        SS	9[        SS[
        SS	9[        SS[
        SS	9[         R                  " S5      /$ )Nrt   video_latentsTz)Encoded video latents for V2V generation.r   num_latent_frames_per_chunk	   +Number of latent frames per temporal chunk.r)   r   r   r   r   r   r   r   z%Minimum sigma for video latent noise.r   z%Maximum sigma for video latent noise.r   )r   r/   r6   r]   r.   r   r#   s    r   r0   'HeliosAddNoiseToVideoLatentsStep.inputs  s     0,,G	 -I	 'C	 'C	 'C	 'C	 ,M'
 '	
r   c                 `    [         R                  " S5      [        S[        R                  SS9/$ )Nrt   r   zNoisy video latentsr4   r   r#   s    r   r7   5HeliosAddNoiseToVideoLatentsStep.intermediate_outputs  s-       15<<Mbc
 	
r   r=   rA   c                    U R                  U5      nUR                  nUR                  nUR                  nUR                  n[
        R                  " SXCR                  S9UR                  UR                  -
  -  UR                  -   nU[        UR                  UR                  US9-  SU-
  U-  -   n/ n	UR                  S   U-  n
[        U
5       H  nX-  nX-   nUS S 2S S 2X2S S 2S S 24   nUR                  S   n[
        R                  " XUR                  S9UR                  UR                  -
  -  UR                  -   nUR                  SSUSS5      nU[        UR                  UR                  US9-  SU-
  U-  -   nU	R!                  U5        M     [
        R"                  " U	SS9nUR%                  U[
        R&                  S9Ul        UR%                  U[
        R&                  S9Ul        U R)                  X#5        X4$ )Nr   r   r   r   rZ   r   )rD   r   rt   r   r   r6   r   r   r   r   r   r;   ranger   r   rF   r   catr   r   rG   )r$   r=   rA   r>   r   rt   r   r   r   noisy_latents_chunksnum_latent_chunksichunk_start	chunk_endlatent_chunkchunk_framesframe_sigmasnoisy_chunks                     r   rJ   )HeliosAddNoiseToVideoLatentsStep.__call__  s%   **51--#11#11&1&M&M# JJq3H3HI00;3T3TTV//0 	 ]-@-@KLaLajp qq$$56 	  ")//26QQ()A9K#AI(A{/Da)JKL'--a0L

<+BWBWX44{7X7XXZ334 
 (,,Q<AFL |L,>,>+J_J_hnoo|#|34  !''4# *$ 		"6A>$1$4$4F%--$4$X!$1$4$4F%--$4$X!U0  r   r   Nr   r   r   r   r   r     s     J
S 
 
 (
Z( (
 (
T 
d;&7 
 
 ]]_.!#8 .! .!S` .! .!r   r   c                       \ rS rSrSrSr\S\4S j5       r\S\	\
   4S j5       r\S\	\   4S j5       r\S\	\   4S j5       r\R"                  " 5       S	\S
\S\4S j5       rSrg)HeliosPrepareHistoryStepi.  zPPrepares chunk/history indices and initializes history state for the chunk loop.r    r!   c                      g)NzPrepares the chunk loop by computing latent dimensions, number of chunks, history indices, and initializing history state (history_latents, image_latents, latent_chunks).r   r#   s    r   r%   $HeliosPrepareHistoryStep.description3  s    o	
r   c                 $    [        S[        5      /$ )Ntransformer)r   r   r#   s    r   expected_components,HeliosPrepareHistoryStep.expected_components:  s     -)AB
 	
r   c                     [         R                  " SSS9[         R                  " SSS9[        SS[        SS	9[        S
S[        S9[        SS[        SS	9[        S/ SQ[        SS	9[        SS[        SS	9/$ )Nrk   i  )r*   rl   i  rj      z)Total number of video frames to generate.r)   r3   Tr   r+   r   r   r   history_sizes)   r   r   z=Sizes of long/mid/short history buffers for temporal context.keep_first_framez7Whether to keep the first frame as a prefix in history.)r   r/   r.   rS   boolr#   s    r   r0   HeliosPrepareHistoryStep.inputs@  s     #65cSFq |dcB-I	 "[	 "U	'
 	
r   c                 J   [        S[        SS9[        S[        SS9[        S[        SS9[        S[        R
                  S	S
9[        S[        R
                  S	S
9[        S[        R
                  S	S
9[        S[        R
                  S	S
9[        S[        R
                  SS9/$ )Nnum_latent_chunkzNumber of temporal chunksr4   latent_shapez Shape of latent tensor per chunkr   z+Adjusted history sizes (sorted, descending)indices_hidden_statesdenoiser_input_fields)r+   kwargs_typeindices_latents_history_shortindices_latents_history_midindices_latents_history_longhistory_latentsz Initialized zero history latents)r   r.   tuplerS   r6   r]   r#   s    r   r7   -HeliosPrepareHistoryStep.intermediate_outputs]  s     *cGbc%Egh4Ers/5<<Ulm75<<]tu5[rs6%,,\st)U\\Oqr	
 		
r   r=   rA   c           
      T   U R                  U5      nUR                  nUR                  n[        UR                  S5      Ul        [        UR                  SS9nUR                  nUR                  UR                  -  nUR                  UR                  -  n	UR                  S-
  UR                  -  S-   Ul        [        SUR                  UR                  -   S-
  UR                  -  5      Ul        UR                  (       d  UR!                  5       nUS   S-   US'   UR                  (       ak  ["        R$                  " S['        S/UQUR                  P5      5      n
U
R)                  S/UQUR                  PSS9u  nnnnn["        R*                  " X/SS9nOQ["        R$                  " S['        / UQUR                  P5      5      n
U
R)                  / UQUR                  PSS9u  nnnnUUUR                  UU	4Ul        Xcl        UR/                  S5      Ul        UR/                  S5      Ul        UR/                  S5      Ul        UR/                  S5      Ul        ["        R8                  " UU['        U5      UU	U["        R:                  S9Ul        U R?                  X#5        X4$ )Nr   T)reverserC   r   rZ   r   ) rD   r3   r   maxrj   sortedr   num_channels_latentsrk   rc   rl   r   rb   window_num_framesr   r   copyr6   arangesumsplitr   r   	unsqueezer   r   r   r   zerosr   r   rG   )r$   r=   rA   r>   r3   r   r   r   h_latentw_latentindicesindices_prefixr   r   indices_latents_history_1xr   r   s                    r   rJ   !HeliosPrepareHistoryStep.__call__j  s   **51 ++
--!$[%;%;Q!?{88$G)>>%%)L)LL$$
(K(KK 33a700)134)5% (+&&)F)FFJ{OlOll(
$
 ++)..0M -b 1A 5M" ''ll1c1*f}*fk>e>e*f&ghG qZ=Z+2Y2YZ`ab,+*%,1II~6bhi,j)ll1c*cM*c;;b;b*c&deG WW{/V/VW]^_,+-%
  33$
  %2!,A,K,KA,N)4Q4[4[\]4^12M2W2WXY2Z/3O3Y3YZ[3\0&+kk --'
# 	U0  r   r   NrL   rM   rN   rO   r   rP   rQ   rR   r%   rS   r   r   r   r0   r   r7   r6   rT   r   r
   rJ   rU   r   r   r   r   r   .  s    ZJ
S 
 
 
T-%8 
 

 
Z( 
 
8 

d;&7 

 

 ]]_I!#8 I! I!S` I! I!r   r   c                       \ rS rSrSrSr\S\4S j5       r\S\	\
   4S j5       r\S\	\   4S j5       r\R                  " 5       S\S	\S\4S
 j5       rSrg)HeliosI2VSeedHistoryStepi  zSeeds history_latents with fake_image_latents for I2V pipelines.

This small additive step runs after HeliosPrepareHistoryStep and appends fake_image_latents to the initialized
history_latents tensor.
r    r!   c                     g)NzCI2V history seeding: appends fake_image_latents to history_latents.r   r#   s    r   r%   $HeliosI2VSeedHistoryStep.description  s    Tr   c                 f    [        SS[        R                  S9[        SS[        R                  S9/$ )Nr   Tr   r   r   r6   r]   r#   s    r   r0   HeliosI2VSeedHistoryStep.inputs  s0     (45<<P+dellS
 	
r   c                 6    [        S[        R                  SS9/$ )Nr   z.History latents seeded with fake_image_latentsr4   r   r6   r]   r#   s    r   r7   -HeliosI2VSeedHistoryStep.intermediate_outputs  s"     !U\\Gw
 	
r   r=   rA   c                     U R                  U5      n[        R                  " UR                  UR                  /SS9Ul        U R                  X#5        X4$ Nr   rZ   )rD   r6   r   r   r   rG   )r$   r=   rA   r>   s       r   rJ   !HeliosI2VSeedHistoryStep.__call__  sN    **51&+ii1L1LkNlNl0mst&u#U0  r   r   Nr   r   r   r   r   r     s     JUS U U 
Z( 
 
 
d;&7 
 
 ]]_!#8 ! !S` ! !r   r   c                       \ rS rSrSrSr\S\4S j5       r\S\	\
   4S j5       r\S\	\   4S j5       r\R                  " 5       S\S	\S\4S
 j5       rSrg)HeliosV2VSeedHistoryStepi  zSeeds history_latents with video_latents for V2V pipelines.

This step runs after HeliosPrepareHistoryStep and replaces the tail of history_latents with video_latents. If the
video has fewer frames than the history, the beginning of history is preserved.
r    r!   c                     g)NzMV2V history seeding: replaces the tail of history_latents with video_latents.r   r#   s    r   r%   $HeliosV2VSeedHistoryStep.description  s    ^r   c                 f    [        SS[        R                  S9[        SS[        R                  S9/$ )Nr   Tr   r   r  r#   s    r   r0   HeliosV2VSeedHistoryStep.inputs  s/     (45<<PN
 	
r   c                 6    [        S[        R                  SS9/$ )Nr   z)History latents seeded with video_latentsr4   r  r#   s    r   r7   -HeliosV2VSeedHistoryStep.intermediate_outputs  s"     !U\\Gr
 	
r   r=   rA   c           	      .   U R                  U5      nUR                  nUR                  nUR                  S   nUR                  S   nXv:  a.  Xg-
  n[        R
                  " US S 2S S 2S U2S S 2S S 24   U/SS9nOUnXCl        U R                  X#5        X4$ r  )rD   r   r   r;   r6   r   rG   )	r$   r=   rA   r>   r   r   history_framesvideo_frameskeep_framess	            r   rJ   !HeliosV2VSeedHistoryStep.__call__  s    **51%55#11(..q1$**1-((7K#iiA||QPQ9Q)RTa(bhijO+O&5#U0  r   r   Nr   r   r   r   r  r    s     J_S _ _ 
Z( 
 
 
d;&7 
 
 ]]_!#8 ! !S` ! !r   r  c                       \ rS rSrSrSr\S\4S j5       r\S\	\
   4S j5       r\S\	\   4S j5       r\S\	\   4S j5       r\R"                  " 5       S	\S
\S\4S j5       rSrg)HeliosSetTimestepsStepi  z>Computes scheduler parameters (mu, sigmas) for the chunk loop.r    r!   c                     g)NzUComputes scheduler shift parameter (mu) and default sigmas for the Helios chunk loop.r   r#   s    r   r%   "HeliosSetTimestepsStep.description  s    fr   c                 B    [        S[        5      [        S[        5      /$ )Nr   	scheduler)r   r   r   r#   s    r   r   *HeliosSetTimestepsStep.expected_components  s#     -)AB+7
 	
r   c                 v    [        SS[        S9[         R                  " S5      [         R                  " S5      /$ )Nr   Tr   num_inference_stepssigmas)r   r   r/   r#   s    r   r0   HeliosSetTimestepsStep.inputs  s7     ~F 56)
 	
r   c                 >    [        S[        SS9[        S[        SS9/$ )Nr   zScheduler shift parameterr4   r   zSigma schedule for diffusion)r   r   rS   r#   s    r   r7   +HeliosSetTimestepsStep.intermediate_outputs&  s(     ;VWD>\]
 	
r   r=   rA   c           
         U R                  U5      nUR                  R                  R                  nUR                  nUS   US   -  US   -  US   US   -  US   -  -  nUR
                  c-  [        R                  " SSUR                  S-   5      S S Ul        [        UUR                  R                  R                  S	S
5      UR                  R                  R                  SS5      UR                  R                  R                  SS5      UR                  R                  R                  SS5      5      Ul        U R                  X#5        X4$ )NrC   r   r   r   g+?g        base_image_seq_len   max_image_seq_len   r         ?r   ffffff?)rD   r   config
patch_sizer   r   nplinspacer  r   r  getr   rG   )r$   r=   rA   r>   r.  r   r   s          r   rJ   HeliosSetTimestepsStep.__call__-  sB   **51++22==
"//%b)L,<<|B?OOqMJqM)JqM9
 %!#UC9X9X[\9\!]^a_a!bK(  ''++,@#F  ''++,?F  ''++L#>  ''++K>
 	U0  r   r   Nr   r   r   r   r  r    s    HJgS g g 
T-%8 
 
 
Z( 
 
 
d;&7 
 
 ]]_!#8 ! !S` ! !r   r  )r(  r*  r+  r,  )r   )&numpyr/  r6   modelsr   
schedulersr   utilsr   utils.torch_utilsr   modular_pipeliner	   r
   modular_pipeline_utilsr   r   r   r   
get_loggerrL   loggerr.   r   r   r   rR   r]   r`   r   rm   ro   r   r   r   r   r  r  r   r   r   <module>r<     s\     . )  - C K K 3 
		H	% 

 
 	

 
L!/ L!h "#	55,,5 5 	5
 \\5r %\\ %69 %UX %
38_ %F}!!6 }!@_!'< _!Dq!'< q!hF!4 F!R#!4 #!L.!4 .!b6!2 6!r   