
    +h                        S SK r S SKJrJrJrJrJrJrJr  S SK	r
S SKrS SKJrJrJrJr  SSKJrJr  SSKJr  SSKJrJr  SSKJr  SS	KJrJrJr  SS
KJ r   SSK!J"r"  SSK#J$r$  SSK%J&r&  \" 5       (       a  S SK'J(s  J)r*  Sr+OSr+\RX                  " \-5      r.Sr/SSS.r0    SS\\1   S\\\2\Rf                  4      S\\\1      S\\\4      4S jjr5 " S S\$\5      r6g)    N)AnyCallableDictListOptionalTupleUnion)CLIPTextModelCLIPTokenizer
LlamaModelLlamaTokenizerFast   )MultiPipelineCallbacksPipelineCallback)HunyuanVideoLoraLoaderMixin)AutoencoderKLHunyuanVideoHunyuanVideoTransformer3DModel)FlowMatchEulerDiscreteScheduler)is_torch_xla_availableloggingreplace_example_docstring)randn_tensor)VideoProcessor   )DiffusionPipeline   )HunyuanVideoPipelineOutputTFa  
    Examples:
        ```python
        >>> import torch
        >>> from diffusers import HunyuanVideoPipeline, HunyuanVideoTransformer3DModel
        >>> from diffusers.utils import export_to_video

        >>> model_id = "hunyuanvideo-community/HunyuanVideo"
        >>> transformer = HunyuanVideoTransformer3DModel.from_pretrained(
        ...     model_id, subfolder="transformer", torch_dtype=torch.bfloat16
        ... )
        >>> pipe = HunyuanVideoPipeline.from_pretrained(model_id, transformer=transformer, torch_dtype=torch.float16)
        >>> pipe.vae.enable_tiling()
        >>> pipe.to("cuda")

        >>> output = pipe(
        ...     prompt="A cat walks on the grass, realistic",
        ...     height=320,
        ...     width=512,
        ...     num_frames=61,
        ...     num_inference_steps=30,
        ... ).frames[0]
        >>> export_to_video(output, "output.mp4", fps=15)
        ```
a   <|start_header_id|>system<|end_header_id|>

Describe the video by detailing the following aspects: 1. The main content and theme of the video.2. The color, shape, size, texture, quantity, text, and spatial relationships of the objects.3. Actions, events, behaviors temporal relationships, physical movement changes of the objects.4. background environment, light, style and atmosphere.5. camera angles, movements, and transitions used in the video:<|eot_id|><|start_header_id|>user<|end_header_id|>

{}<|eot_id|>_   )template
crop_startnum_inference_stepsdevice	timestepssigmasc                    Ub  Ub  [        S5      eUb  S[        [        R                  " U R                  5      R
                  R                  5       5      ;   nU(       d  [        SU R                   S35      eU R                  " S
X2S.UD6  U R                  n[        U5      nX14$ Ub  S[        [        R                  " U R                  5      R
                  R                  5       5      ;   nU(       d  [        SU R                   S35      eU R                  " S
XBS.UD6  U R                  n[        U5      nX14$ U R                  " U4S	U0UD6  U R                  nX14$ )a  
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.

Args:
    scheduler (`SchedulerMixin`):
        The scheduler to get timesteps from.
    num_inference_steps (`int`):
        The number of diffusion steps used when generating samples with a pre-trained model. If used, `timesteps`
        must be `None`.
    device (`str` or `torch.device`, *optional*):
        The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
    timesteps (`List[int]`, *optional*):
        Custom timesteps used to override the timestep spacing strategy of the scheduler. If `timesteps` is passed,
        `num_inference_steps` and `sigmas` must be `None`.
    sigmas (`List[float]`, *optional*):
        Custom sigmas used to override the timestep spacing strategy of the scheduler. If `sigmas` is passed,
        `num_inference_steps` and `timesteps` must be `None`.

Returns:
    `Tuple[torch.Tensor, int]`: A tuple where the first element is the timestep schedule from the scheduler and the
    second element is the number of inference steps.
zYOnly one of `timesteps` or `sigmas` can be passed. Please choose one to set custom valuesr#   zThe current scheduler class zx's `set_timesteps` does not support custom timestep schedules. Please check whether you are using the correct scheduler.)r#   r"   r$   zv's `set_timesteps` does not support custom sigmas schedules. Please check whether you are using the correct scheduler.)r$   r"   r"    )

ValueErrorsetinspect	signatureset_timesteps
parameterskeys	__class__r#   len)	schedulerr!   r"   r#   r$   kwargsaccepts_timestepsaccept_sigmass           r/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/hunyuan_video/pipeline_hunyuan_video.pyretrieve_timestepsr5   U   s}   > !3tuu'3w/@/@AXAX/Y/d/d/i/i/k+ll .y/B/B.C Da b  	M)MfM''	!)n )) 
	 C(9(9):Q:Q(R(](](b(b(d$ee.y/B/B.C D_ `  	GvGG''	!)n )) 	 3MFMfM''	))    c            9       `  ^  \ rS rSrSrSrSS/rS\S\S\	S	\
S
\S\S\4U 4S jjr     SHS\\\\   4   S\\\4   S\S\\R.                     S\\R0                     S\S\S\\R4                  \R4                  4   4S jjr    SIS\\\\   4   S\S\\R.                     S\\R0                     S\S\R4                  4S jjrS\SSSSSSS4	S\\\\   4   S\\\\   4   S\\\4   S\S\\R4                     S\\R4                     S\\R4                     S\\R.                     S\\R0                     S\4S jjr   SJS jr        SKS#\S$\S%\S&\S'\S\\R0                     S\\R.                     S(\\\R@                  \\R@                     4      S\\R4                     S\R4                  4S) jjr!S* r"S+ r#S, r$S- r%\&S. 5       r'\&S/ 5       r(\&S0 5       r)\&S1 5       r*\&S2 5       r+\RX                  " 5       \-" \.5      SSSSS S!S"S3SS4S5SSSSSSSSSS6S7SSS/\S4S\\\\   4   S\\\\   4   S8\\\\   4   S9\\\\   4   S%\S&\S'\S:\S;\\/   S<\/S=\/S\\   S(\\\R@                  \\R@                     4      S\\R4                     S\\R4                     S\\R4                     S\\R4                     S>\\R4                     S?\\R4                     S@\\R4                     SA\\   SB\0SC\\\\4      SD\\\1\\\/S4   \2\34      SE\\   S\\\4   S\46SF jj5       5       r4SGr5U =r6$ )LHunyuanVideoPipeline   ap  
Pipeline for text-to-video generation using HunyuanVideo.

This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).

Args:
    text_encoder ([`LlamaModel`]):
        [Llava Llama3-8B](https://huggingface.co/xtuner/llava-llama-3-8b-v1_1-transformers).
    tokenizer (`LlamaTokenizer`):
        Tokenizer from [Llava Llama3-8B](https://huggingface.co/xtuner/llava-llama-3-8b-v1_1-transformers).
    transformer ([`HunyuanVideoTransformer3DModel`]):
        Conditional Transformer to denoise the encoded image latents.
    scheduler ([`FlowMatchEulerDiscreteScheduler`]):
        A scheduler to be used in combination with `transformer` to denoise the encoded image latents.
    vae ([`AutoencoderKLHunyuanVideo`]):
        Variational Auto-Encoder (VAE) Model to encode and decode videos to and from latent representations.
    text_encoder_2 ([`CLIPTextModel`]):
        [CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel), specifically
        the [clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14) variant.
    tokenizer_2 (`CLIPTokenizer`):
        Tokenizer of class
        [CLIPTokenizer](https://huggingface.co/docs/transformers/en/model_doc/clip#transformers.CLIPTokenizer).
z.text_encoder->text_encoder_2->transformer->vaelatentsprompt_embedstext_encoder	tokenizertransformervaer0   text_encoder_2tokenizer_2c           
      8  > [         TU ]  5         U R                  UUUUUUUS9  [        U SS 5      (       a  U R                  R
                  OSU l        [        U SS 5      (       a  U R                  R                  OSU l        [        U R                  S9U l
        g )N)r?   r<   r=   r>   r0   r@   rA   r?         )vae_scale_factor)super__init__register_modulesgetattrr?   temporal_compression_ratiovae_scale_factor_temporalspatial_compression_ratiovae_scale_factor_spatialr   video_processor)	selfr<   r=   r>   r?   r0   r@   rA   r.   s	           r4   rG   HunyuanVideoPipeline.__init__   s     	%#)# 	 	
 QXX\^ceiPjPj)L)Lpq&NUVZ\acgNhNh(J(Jno%-t?\?\]r6   r   N   promptprompt_templatenum_videos_per_promptr"   dtypemax_sequence_lengthnum_hidden_layers_to_skipreturnc                    U=(       d    U R                   nU=(       d    U R                  R                  n[        U[        5      (       a  U/OUn[        U5      nU V	s/ s H  oS   R                  U	5      PM     nn	UR                  SS 5      n
U
c.  U R                  US   SSSSSS9nUS   R                  S   n
U
S	-  n
Xj-  nU R                  UUSS
SSSS
S9nUR                  R                  US9nUR                  R                  US9nU R                  UUS
S9R                  US-   *    nUR                  US9nU
b  U
S:  a  US S 2U
S 24   nUS S 2U
S 24   nUR                  u  nnnUR                  SUS5      nUR                  X-  US5      nUR                  SU5      nUR                  X-  U5      nX4$ s  sn	f )Nr   r    
max_lengthptF)paddingreturn_tensorsreturn_lengthreturn_overflowing_tokensreturn_attention_mask	input_idsr   T)rZ   r\   
truncationr]   r^   r_   r`   )r"   )ra   attention_maskoutput_hidden_statesr   )rU   r   )_execution_devicer<   rU   
isinstancestrr/   formatgetr=   shapera   tord   hidden_statesrepeatview)rO   rR   rS   rT   r"   rU   rV   rW   
batch_sizepr    prompt_template_inputtext_inputstext_input_idsprompt_attention_maskr;   _seq_lens                     r4   _get_llama_prompt_embeds-HunyuanVideoPipeline._get_llama_prompt_embeds   s(    14110**00'44&&[
AGHA*-44Q7H$((t<
$(NN
+$##*/&+ %3 %! /{;AA"EJ!OJ)nn* &+"& % 	
 %..111@ + : : = =V = L))$0!% * 
 -3a78	:
 &((u(5!j1n)!Z[.9M$9!Z[.$I! &++7A%,,Q0EqI%**:+MwXZ[ 5 < <Q@U V 5 : ::;]_f g33a Is   F=c                    U=(       d    U R                   nU=(       d    U R                  R                  n[        U[        5      (       a  U/OUn[        U5      nU R                  USUSSS9nUR                  nU R                  USSS9R                  n	U	R                  S   UR                  S   :  a]  [        R                  " X5      (       dB  U R                  R                  U	S S 2US-
  S24   5      n
[        R                  S	U S
U
 35        U R                  UR                  U5      SS9R                  nUR!                  SU5      nUR#                  Xb-  S5      nU$ )NrZ   Tr[   )r\   rZ   rc   r]   longest)r\   r]   rb   r   z\The following part of your input was truncated because CLIP can only handle sequences up to z	 tokens: F)re   )rf   r@   rU   rg   rh   r/   rA   ra   rk   torchequalbatch_decodeloggerwarningrl   pooler_outputrn   ro   )rO   rR   rT   r"   rU   rV   rp   rs   rt   untruncated_idsremoved_textr;   s               r4   _get_clip_prompt_embeds,HunyuanVideoPipeline._get_clip_prompt_embeds	  sm    14112,,22'44&&[
&& * ' 
 %..**69UY*Zdd  $(<(<R(@@UcIuIu++88L_bcLcfhLhIh9ijLNN'(	,A
 ++N,=,=f,E\a+bpp &,,Q0EF%**:+MrRr6   prompt_2pooled_prompt_embedsru   c           	      r    Uc  U R                  UUUUU	U
S9u  pWUc  Uc  UnU R                  UUUU	SS9nXVU4$ )N)r"   rU   rV   M   )rx   r   )rO   rR   r   rS   rT   r;   r   ru   r"   rU   rV   s              r4   encode_prompt"HunyuanVideoPipeline.encode_prompt0  s|      373P3P%$7 4Q 40M  '!#'#?#?%$& $@ $  4IIIr6   c           
      B  ^  US-  S:w  d	  US-  S:w  a  [        SU SU S35      eUbW  [        U 4S jU 5       5      (       d=  [        ST R                   SU Vs/ s H  oT R                  ;  d  M  UPM     sn 35      eUb  Ub  [        S	U S
U S35      eUb  Ub  [        SU S
U S35      eUc  Uc  [        S5      eUbA  [        U[        5      (       d,  [        U[
        5      (       d  [        S[        U5       35      eUbA  [        U[        5      (       d,  [        U[
        5      (       d  [        S[        U5       35      eUbO  [        U[        5      (       d  [        S[        U5       35      eSU;  a  [        SUR                  5        35      eg g s  snf )N   r   z8`height` and `width` have to be divisible by 16 but are z and .c              3   @   >#    U  H  oTR                   ;   v   M     g 7fN)_callback_tensor_inputs).0krO   s     r4   	<genexpr>4HunyuanVideoPipeline.check_inputs.<locals>.<genexpr>a  s      F
7Y!---7Ys   z2`callback_on_step_end_tensor_inputs` has to be in z, but found zCannot forward both `prompt`: z and `prompt_embeds`: z2. Please make sure to only forward one of the two.z Cannot forward both `prompt_2`: zeProvide either `prompt` or `prompt_embeds`. Cannot leave both `prompt` and `prompt_embeds` undefined.z2`prompt` has to be of type `str` or `list` but is z4`prompt_2` has to be of type `str` or `list` but is z2`prompt_template` has to be of type `dict` but is r   zA`prompt_template` has to contain a key `template` but only found )	r'   allr   rg   rh   listtypedictr-   )	rO   rR   r   heightwidthr;   "callback_on_step_end_tensor_inputsrS   r   s	   `        r4   check_inputs!HunyuanVideoPipeline.check_inputsT  s7    B;!urzQWX^W__dejdkklmnn-9# F
7YF
 C
 C
 DTEaEaDbbn  |^  pH  |^vw  ko  kG  kG  bGpq  |^  pH  oI  J  -";08N}o ^0 0  !m&?28*<RS`Ra b0 0  ^ 5w  FC)@)@TZ\`IaIaQRVW]R^Q_`aa!:h+D+DZX`bfMgMgSTXYaTbScdee&ot44 #UVZ[jVkUl!mnn0 WXgXlXlXnWop  1 '- pHs   F1F        rp   num_channels_latentsr   r   
num_frames	generatorc
                 H   U	b  U	R                  XvS9$ UUUS-
  U R                  -  S-   [        U5      U R                  -  [        U5      U R                  -  4n
[	        U[
        5      (       a*  [        U5      U:w  a  [        S[        U5       SU S35      e[        XXvS9n	U	$ )N)r"   rU   r   z/You have passed a list of generators of length z+, but requested an effective batch size of z@. Make sure the batch size matches the length of the generators.)r   r"   rU   )	rl   rK   intrM   rg   r   r/   r'   r   )rO   rp   r   r   r   r   rU   r"   r   r:   rk   s              r4   prepare_latents$HunyuanVideoPipeline.prepare_latents  s     ::V:99  !^ > >>BK4888J$777
 i&&3y>Z+GA#i.AQ R&<'gi 
 u&Vr6   c                 8    U R                   R                  5         g)z
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
N)r?   enable_slicingrO   s    r4   enable_vae_slicing'HunyuanVideoPipeline.enable_vae_slicing      
 	!r6   c                 8    U R                   R                  5         g)z
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
computing decoding in one step.
N)r?   disable_slicingr   s    r4   disable_vae_slicing(HunyuanVideoPipeline.disable_vae_slicing  s    
 	  "r6   c                 8    U R                   R                  5         g)z
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
processing larger images.
N)r?   enable_tilingr   s    r4   enable_vae_tiling&HunyuanVideoPipeline.enable_vae_tiling  s     	 r6   c                 8    U R                   R                  5         g)z
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
computing decoding in one step.
N)r?   disable_tilingr   s    r4   disable_vae_tiling'HunyuanVideoPipeline.disable_vae_tiling  r   r6   c                     U R                   $ r   )_guidance_scaler   s    r4   guidance_scale#HunyuanVideoPipeline.guidance_scale  s    ###r6   c                     U R                   $ r   )_num_timestepsr   s    r4   num_timesteps"HunyuanVideoPipeline.num_timesteps  s    """r6   c                     U R                   $ r   )_attention_kwargsr   s    r4   attention_kwargs%HunyuanVideoPipeline.attention_kwargs      %%%r6   c                     U R                   $ r   )_current_timestepr   s    r4   current_timestep%HunyuanVideoPipeline.current_timestep  r   r6   c                     U R                   $ r   )
_interruptr   s    r4   	interruptHunyuanVideoPipeline.interrupt  s    r6   2         ?g      @pilTnegative_promptnegative_prompt_2r!   r$   true_cfg_scaler   negative_prompt_embedsnegative_pooled_prompt_embedsnegative_prompt_attention_maskoutput_typereturn_dictr   callback_on_step_endr   c                 
   [        U[        [        45      (       a  UR                  nU R	                  UUUUUUU5        USL=(       d    USL=(       a    USLnU
S:  =(       a    UnXl        UU l        SU l        SU l        U R                  nUb  [        U[        5      (       a  SnO3Ub!  [        U[        5      (       a  [        U5      nOUR                  S   nU R                  R                  n U R!                  UUUUUUUUUS9	u  nnnUR#                  U 5      nUR#                  U 5      nUR#                  U 5      nU(       aN  U R!                  UUUUUUUUUS9	u  nnnUR#                  U 5      nUR#                  U 5      nUR#                  U 5      nU	c  [$        R&                  " SSUS-   5      SS OU	n	[)        U R*                  UUU	S	9u  n!nU R                  R,                  R.                  n"U R1                  UU-  U"UUU[2        R4                  UUU5	      n[2        R6                  " U/UR                  S   -  U US
9S-  n#[        U!5      XR*                  R8                  -  -
  n$[        U!5      U l        U R=                  US9 n%[?        U!5       GH  u  n&n'U R@                  (       a  M  U'U l        UR#                  U 5      n(U'RC                  UR                  S   5      R#                  UR                  5      n)U R                  RE                  S5         U R                  U(U)UUUU#USS9S   n*SSS5        U(       aH  U R                  RE                  S5         U R                  U(U)UUUU#USS9S   n+SSS5        W+U
W*U+-
  -  -   n*U R*                  RG                  W*U'USS9S   nUbJ  0 n,U H  n-[I        5       U-   U,U-'   M     U" U U&U'U,5      n.U.RK                  SU5      nU.RK                  SU5      nU&[        U!5      S-
  :X  d)  U&S-   U$:  a0  U&S-   U R*                  R8                  -  S:X  a  U%RM                  5         [N        (       d  GM  [P        RR                  " 5         GM     SSS5        SU l        US:X  d~  UR#                  U RT                  R                  5      U RT                  R,                  RV                  -  nU RT                  RY                  USS9S   n/U RZ                  R]                  U/US9n/OUn/U R_                  5         U(       d  U/4$ [a        U/S9$ ! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       N= f)ai  
The call function to the pipeline for generation.

Args:
    prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
        instead.
    prompt_2 (`str` or `List[str]`, *optional*):
        The prompt or prompts to be sent to `tokenizer_2` and `text_encoder_2`. If not defined, `prompt` is
        will be used instead.
    negative_prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts not to guide the image generation. If not defined, one has to pass
        `negative_prompt_embeds` instead. Ignored when not using guidance (i.e., ignored if `true_cfg_scale` is
        not greater than `1`).
    negative_prompt_2 (`str` or `List[str]`, *optional*):
        The prompt or prompts not to guide the image generation to be sent to `tokenizer_2` and
        `text_encoder_2`. If not defined, `negative_prompt` is used in all the text-encoders.
    height (`int`, defaults to `720`):
        The height in pixels of the generated image.
    width (`int`, defaults to `1280`):
        The width in pixels of the generated image.
    num_frames (`int`, defaults to `129`):
        The number of frames in the generated video.
    num_inference_steps (`int`, defaults to `50`):
        The number of denoising steps. More denoising steps usually lead to a higher quality image at the
        expense of slower inference.
    sigmas (`List[float]`, *optional*):
        Custom sigmas to use for the denoising process with schedulers which support a `sigmas` argument in
        their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is passed
        will be used.
    true_cfg_scale (`float`, *optional*, defaults to 1.0):
        True classifier-free guidance (guidance scale) is enabled when `true_cfg_scale` > 1 and
        `negative_prompt` is provided.
    guidance_scale (`float`, defaults to `6.0`):
        Embedded guiddance scale is enabled by setting `guidance_scale` > 1. Higher `guidance_scale` encourages
        a model to generate images more aligned with `prompt` at the expense of lower image quality.

        Guidance-distilled models approximates true classifer-free guidance for `guidance_scale` > 1. Refer to
        the [paper](https://huggingface.co/papers/2210.03142) to learn more.
    num_videos_per_prompt (`int`, *optional*, defaults to 1):
        The number of images to generate per prompt.
    generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
        A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make
        generation deterministic.
    latents (`torch.Tensor`, *optional*):
        Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
        generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
        tensor is generated by sampling using the supplied random `generator`.
    prompt_embeds (`torch.Tensor`, *optional*):
        Pre-generated text embeddings. Can be used to easily tweak text inputs (prompt weighting). If not
        provided, text embeddings are generated from the `prompt` input argument.
    pooled_prompt_embeds (`torch.FloatTensor`, *optional*):
        Pre-generated pooled text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting.
        If not provided, pooled text embeddings will be generated from `prompt` input argument.
    negative_prompt_embeds (`torch.FloatTensor`, *optional*):
        Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
        weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
        argument.
    negative_pooled_prompt_embeds (`torch.FloatTensor`, *optional*):
        Pre-generated negative pooled text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
        weighting. If not provided, pooled negative_prompt_embeds will be generated from `negative_prompt`
        input argument.
    output_type (`str`, *optional*, defaults to `"pil"`):
        The output format of the generated image. Choose between `PIL.Image` or `np.array`.
    return_dict (`bool`, *optional*, defaults to `True`):
        Whether or not to return a [`HunyuanVideoPipelineOutput`] instead of a plain tuple.
    attention_kwargs (`dict`, *optional*):
        A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
        `self.processor` in
        [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
    clip_skip (`int`, *optional*):
        Number of layers to be skipped from CLIP while computing the prompt embeddings. A value of 1 means that
        the output of the pre-final layer will be used for computing the prompt embeddings.
    callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *optional*):
        A function or a subclass of `PipelineCallback` or `MultiPipelineCallbacks` that is called at the end of
        each denoising step during the inference. with the following arguments: `callback_on_step_end(self:
        DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)`. `callback_kwargs` will include a
        list of all tensors as specified by `callback_on_step_end_tensor_inputs`.
    callback_on_step_end_tensor_inputs (`List`, *optional*):
        The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
        will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
        `._callback_tensor_inputs` attribute of your pipeline class.

Examples:

Returns:
    [`~HunyuanVideoPipelineOutput`] or `tuple`:
        If `return_dict` is `True`, [`HunyuanVideoPipelineOutput`] is returned, otherwise a `tuple` is returned
        where the first element is a list with the generated images and the second element is a list of `bool`s
        indicating whether the corresponding generated image contains "not-safe-for-work" (nsfw) content.
Nr   Fr   )	rR   r   rS   rT   r;   r   ru   r"   rV   r   g        rb   )r$   )rU   r"   g     @@)totalcond)rm   timestepencoder_hidden_statesencoder_attention_maskpooled_projectionsguidancer   r   uncond)r   r:   r;   latent)r   )frames)1rg   r   r   tensor_inputsr   r   r   r   r   rf   rh   r   r/   rk   r>   rU   r   rl   nplinspacer5   r0   configin_channelsr   r|   float32tensororderr   progress_bar	enumerater   expandcache_contextsteplocalspopupdateXLA_AVAILABLExm	mark_stepr?   scaling_factordecoderN   postprocess_videomaybe_free_model_hooksr   )0rO   rR   r   r   r   r   r   r   r!   r$   r   r   rT   r   r:   r;   r   ru   r   r   r   r   r   r   r   r   rS   rV   has_neg_promptdo_true_cfgr"   rp   transformer_dtyper#   r   r   num_warmup_stepsr   itlatent_model_inputr   
noise_predneg_noise_predcallback_kwargsr   callback_outputsvideos0                                                   r4   __call__HunyuanVideoPipeline.__call__  s   | *-=?U,VWW1E1S1S. 	.	
 )4 
"$.\3PX\3\ 	 %q(;^-!1!%'' *VS"9"9JJvt$<$<VJ&,,Q/J !,,22EIEWEW+"7'!5"7 3 FX 
F
B+-B &(():; 5 8 89J K3667HIdhdvdv&* /&;4%B&D$7 ew 
ea"$ACa &<%>%>?P%Q"-K-N-NO`-a*,I,L,LM^,_) IOS#':Q'>?D\b);DNNL_agpv)w&	&  $//66BB&&.. MM

 << 07==3C CK\eklouu y>,?..BVBV,VV!)n%89\!),1>>)*&%,ZZ0A%B"88GMM!$4588G%%33F;!%!1!1&8!).;/D+?!))9$) "2 	" 	"J < ))77A)-)9)9*<%-2H3Q/L%--=(- *: 	* 	* B "0.JQ_D_2`!`J ..--j!WRW-XYZ['3&(O?-3Xa[* @';D!Q'X$.229gFG$4$8$8-$XM I**A9I/IqSTuX\XfXfXlXlNlpqNq '') =LLNi - :n "&h&jj0488??3Q3QQGHHOOGO?BE((::5k:ZEE 	##%8O)77y <; BA/ :9sD   BUT 2*UT26CUU 
T/*U2
U<U
U)r   r   r   r   r   rM   rK   rN   )r   NNrQ   r   )r   NNr   )NNN)    r   r   r   NNNN)7__name__
__module____qualname____firstlineno____doc__model_cpu_offload_seqr   r   r   r   r   r   r
   r   rG   r	   rh   r   r   r   r   r   r|   r"   rU   r   Tensorrx   r   DEFAULT_PROMPT_TEMPLATEr   r   	Generatorr   r   r   r   r   propertyr   r   r   r   r   no_gradr   EXAMPLE_DOC_STRINGfloatboolr   r   r   r
  __static_attributes____classcell__)r.   s   @r4   r8   r8      s,   2 M(/:^ ^ &^ 4	^
 '^ 3^ &^ #^< &')-'+#&)*@4c49n%@4 c3h@4  #	@4
 &@4 $@4 !@4 $'@4 
u||U\\)	*@4J &')-'+#%%c49n%%  #% &	%
 $% !% 
%T +/*A%&047;8<)-'+#&"Jc49n%"J T#Y'"J c3h	"J
  #"J  -"J 'u||4"J  (5"J &"J $"J !"JT +/-d %''+)-MQ*. " 	
   $ & E%//43H"HIJ %,,' 
>"#!" $ $ # # & & & &   ]]_12 )-*.1537#%" # #/0MQ*.047;8<9=@DAE%* 59 9B*A#&=^8c49n%^8 T#Y'^8 sDI~.	^8
 !d3i0^8 ^8 ^8 ^8 !^8 U^8 ^8 ^8  (}^8 E%//43H"HIJ^8 %,,'^8   -!^8" 'u||4#^8$  (5%^8& !) 6'^8( (0'=)^8* )1(>+^8, c]-^8. /^80 #4S>21^82 '(Cd+T124DF\\]
3^88 -1I9^8: c3h;^8< !=^8 3 ^8r6   r8   )NNNN)7r)   typingr   r   r   r   r   r   r	   numpyr   r|   transformersr
   r   r   r   	callbacksr   r   loadersr   modelsr   r   
schedulersr   utilsr   r   r   utils.torch_utilsr   rN   r   pipeline_utilsr   pipeline_outputr   torch_xla.core.xla_modelcore	xla_modelr   r   
get_loggerr  r   r  r  r   rh   r"   r  r5   r8   r&   r6   r4   <module>r,     s     D D D   U U A 2 O 9 O O - - . 7 ))MM			H	% :	C  " *.15%)$(8*!#8* U3,-.8* S	"	8*
 T%[!8*vc	8,.I c	8r6   