ó
    oM‡j(}  ã                   ób  • S SK r S SKJrJr  S SKrS SKrS SK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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%\RL                  " \'5      r(\" 5       (       a  S SK)r)Sr*S r+S r,S r- " S S\\5      r.g)é    N)ÚAnyÚCallable)ÚAutoTokenizerÚUMT5EncoderModelé   )ÚMultiPipelineCallbacksÚPipelineCallback)ÚWanLoraLoaderMixin)ÚAutoencoderKLWanÚWanTransformer3DModel)ÚFlowMatchEulerDiscreteScheduler)Úis_ftfy_availableÚis_torch_xla_availableÚloggingÚreplace_example_docstring)Úrandn_tensor)ÚVideoProcessoré   )ÚDiffusionPipelineé   )ÚWanPipelineOutputTFa  
    Examples:
        ```python
        >>> import torch
        >>> from diffusers.utils import export_to_video
        >>> from diffusers import AutoencoderKLWan, WanPipeline
        >>> from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler

        >>> # Available models: Wan-AI/Wan2.1-T2V-14B-Diffusers, Wan-AI/Wan2.1-T2V-1.3B-Diffusers
        >>> model_id = "Wan-AI/Wan2.1-T2V-14B-Diffusers"
        >>> vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
        >>> pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
        >>> flow_shift = 5.0  # 5.0 for 720P, 3.0 for 480P
        >>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
        >>> pipe.to("cuda")

        >>> prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
        >>> negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"

        >>> output = pipe(
        ...     prompt=prompt,
        ...     negative_prompt=negative_prompt,
        ...     height=720,
        ...     width=1280,
        ...     num_frames=81,
        ...     guidance_scale=5.0,
        ... ).frames[0]
        >>> export_to_video(output, "output.mp4", fps=16)
        ```
c                 óÀ   • [        5       (       a  [        R                  " U 5      n [        R                  " [        R                  " U 5      5      n U R                  5       $ ©N)r   ÚftfyÚfix_textÚhtmlÚunescapeÚstrip©Útexts    Ú²C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\diffusers/pipelines/wan/pipeline_wan.pyÚbasic_cleanr"   N   s<   € Ü×ÑÜ�}Š}˜TÓ"ˆÜ�=Š=œŸš tÓ,Ó-€DØ�:‰:‹<Ðó    c                 óV   • [         R                  " SSU 5      n U R                  5       n U $ )Nz\s+Ú )ÚreÚsubr   r   s    r!   Úwhitespace_cleanr(   U   s$   € Ü�6Š6�&˜#˜tÓ$€DØ�:‰:‹<€DØ€Kr#   c                 ó.   • [        [        U 5      5      n U $ r   )r(   r"   r   s    r!   Úprompt_cleanr*   [   s   € ÜœK¨Ó-Ó.€DØ€Kr#   c            )       ó²  ^ • \ rS rSrSrSr/ SQrSS/r    S=S\S	\	S
\
S\S\S-  S\S-  S\S-  S\4U 4S jjjr     S>S\\\   -  S\S\S\R(                  S-  S\R*                  S-  4
S jjr        S?S\\\   -  S\\\   -  S-  S\S\S\R.                  S-  S\R.                  S-  S\S\R(                  S-  S\R*                  S-  4S jjr    S@S jr        SAS \S!\S"\S#\S$\S\R*                  S-  S\R(                  S-  S%\R4                  \\R4                     -  S-  S&\R.                  S-  S'\R.                  4S( jjr\S) 5       r\S* 5       r\S+ 5       r\S, 5       r \S- 5       r!\S. 5       r"\RF                  " 5       \$" \%5      SSSSSS/S0SSSSSSS1SSSS&/S24S\\\   -  S\\\   -  S"\S#\S$\S3\S4\S5\S-  S\S-  S%\R4                  \\R4                     -  S-  S&\R.                  S-  S\R.                  S-  S\R.                  S-  S6\S-  S7\S8\&\\'4   S-  S9\(\\/S4   \)-  \*-  S-  S:\\   S\4&S; jj5       5       r+S<r,U =r-$ )BÚWanPipelineé`   aœ  
Pipeline for text-to-video generation using Wan.

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:
    tokenizer ([`T5Tokenizer`]):
        Tokenizer from [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5Tokenizer),
        specifically the [google/umt5-xxl](https://huggingface.co/google/umt5-xxl) variant.
    text_encoder ([`T5EncoderModel`]):
        [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5EncoderModel), specifically
        the [google/umt5-xxl](https://huggingface.co/google/umt5-xxl) variant.
    transformer ([`WanTransformer3DModel`]):
        Conditional Transformer to denoise the input latents.
    scheduler ([`UniPCMultistepScheduler`]):
        A scheduler to be used in combination with `transformer` to denoise the encoded image latents.
    vae ([`AutoencoderKLWan`]):
        Variational Auto-Encoder (VAE) Model to encode and decode videos to and from latent representations.
    transformer_2 ([`WanTransformer3DModel`], *optional*):
        Conditional Transformer to denoise the input latents during the low-noise stage. If provided, enables
        two-stage denoising where `transformer` handles high-noise stages and `transformer_2` handles low-noise
        stages. If not provided, only `transformer` is used.
    boundary_ratio (`float`, *optional*, defaults to `None`):
        Ratio of total timesteps to use as the boundary for switching between transformers in two-stage denoising.
        The actual boundary timestep is calculated as `boundary_ratio * num_train_timesteps`. When provided,
        `transformer` handles timesteps >= boundary_timestep and `transformer_2` handles timesteps <
        boundary_timestep. If `None`, only `transformer` is used for the entire denoising process.
z-text_encoder->transformer->transformer_2->vae)ÚlatentsÚprompt_embedsÚnegative_prompt_embedsÚtransformerÚtransformer_2NÚ	tokenizerÚtext_encoderÚvaeÚ	schedulerÚboundary_ratioÚexpand_timestepsc	           	      óš  >• [         T	U ]  5         U R                  UUUUUUS9  U R                  US9  U R                  US9  [	        U SS 5      (       a   U R
                  R                  R                  OSU l        [	        U SS 5      (       a   U R
                  R                  R                  OSU l
        [        U R                  S9U l        g )N)r5   r4   r3   r1   r6   r2   )r7   )r8   r5   é   é   )Úvae_scale_factor)ÚsuperÚ__init__Úregister_modulesÚregister_to_configÚgetattrr5   ÚconfigÚscale_factor_temporalÚvae_scale_factor_temporalÚscale_factor_spatialÚvae_scale_factor_spatialr   Úvideo_processor)
Úselfr3   r4   r5   r6   r1   r2   r7   r8   Ú	__class__s
            €r!   r>   ÚWanPipeline.__init__ƒ   sÁ   ø€ ô 	‰ÑÔà×ÑØØ%ØØ#ØØ'ð 	ñ 	
ð 	×Ñ¨~ÐÑ>Ø×ÑÐ1AÐÑBÜRYÐZ^Ð`eÐgk×RlÑRl¨¯©¯©×)NÒ)NÐrsˆÔ&ÜPWÐX\Ð^cÐei×PjÑPj¨¯©¯©×(LÒ(LÐpqˆÔ%Ü-¸t×?\Ñ?\Ñ]ˆÕr#   r   ÚpromptÚnum_videos_per_promptÚmax_sequence_lengthÚdeviceÚdtypec                 óØ  • U=(       d    U R                   nU=(       d    U R                  R                  n[        U[        5      (       a  U/OUnU Vs/ s H  n[        U5      PM     nn[        U5      nU R                  USUSSSSS9nUR                  UR                  p©U
R                  S5      R                  SS9R                  5       nU R                  U	R                  U5      U
R                  U5      5      R                  nUR                  XTS9n[        XË5       VVs/ s H
  u  pmUS U PM     nnn[         R"                  " U Vs/ s HJ  n[         R$                  " XfR'                  X6R)                  S5      -
  UR)                  S5      5      /5      PML     snSS9nUR*                  u  pïnUR-                  SUS5      nUR/                  Xr-  US	5      nU$ s  snf s  snnf s  snf )
NÚ
max_lengthTÚpt)ÚpaddingrQ   Ú
truncationÚadd_special_tokensÚreturn_attention_maskÚreturn_tensorsr   r   )Údim©rO   rN   éÿÿÿÿ)Ú_execution_devicer4   rO   Ú
isinstanceÚstrr*   Úlenr3   Ú	input_idsÚattention_maskÚgtÚsumÚlongÚtoÚlast_hidden_stateÚzipÚtorchÚstackÚcatÚ	new_zerosÚsizeÚshapeÚrepeatÚview)rH   rK   rL   rM   rN   rO   ÚuÚ
batch_sizeÚtext_inputsÚtext_input_idsÚmaskÚseq_lensr/   ÚvÚ_Úseq_lens                   r!   Ú_get_t5_prompt_embedsÚ!WanPipeline._get_t5_prompt_embedsž   sÂ  € ð ×1˜4×1Ñ1ˆØ×0˜×*Ñ*×0Ñ0ˆä'¨´×4Ñ4�&‘¸&ˆÙ+1Ó2ª6 a”,˜q–/©6ˆÐ2Ü˜“[ˆ
à—n‘nØØ Ø*ØØ#Ø"&Øð %ð 
ˆð  +×4Ñ4°k×6PÑ6P˜Ø—7‘7˜1“:—>‘> a�>Ð(×-Ñ-Ó/ˆà×)Ñ)¨.×*;Ñ*;¸FÓ*CÀTÇWÁWÈVÃ_ÓU×gÑgˆØ%×(Ñ(¨uÐ(ÐDˆÜ+.¨}Ô+GÔHÒ+G¡4 1˜˜2˜A›Ñ+GˆÑHÜŸšÙ^kÓlÒ^kÐYZŒU�YŠY˜Ÿ;™;Ð':¿V¹VÀA»YÑ'FÈÏÉÈqË	ÓRÐSÖTÑ^kÑlÐrsñ
ˆð
 &×+Ñ+‰ˆ�AØ%×,Ñ,¨QÐ0EÀqÓIˆØ%×*Ñ*¨:Ñ+MÈwÐXZÓ[ˆàÐùò7 3ùó" Iùâls   ÁGÄ$G!ÅAG'TÚnegative_promptÚdo_classifier_free_guidancer/   r0   c
                 ó2  • U=(       d    U R                   n[        U[        5      (       a  U/OUnUb  [        U5      n
OUR                  S   n
Uc  U R                  UUUUU	S9nU(       a«  Uc¨  U=(       d    Sn[        U[        5      (       a  X¢/-  OUnUb;  [        U5      [        U5      La$  [        S[        U5       S[        U5       S35      eU
[        U5      :w  a!  [        SU S[        U5       S	U SU
 S
3	5      eU R                  UUUUU	S9nXV4$ )ab  
Encodes the prompt into text encoder hidden states.

Args:
    prompt (`str` or `list[str]`, *optional*):
        prompt to be encoded
    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 `guidance_scale` is
        less than `1`).
    do_classifier_free_guidance (`bool`, *optional*, defaults to `True`):
        Whether to use classifier free guidance or not.
    num_videos_per_prompt (`int`, *optional*, defaults to 1):
        Number of videos that should be generated per prompt. torch device to place the resulting embeddings on
    prompt_embeds (`torch.Tensor`, *optional*):
        Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
        provided, text embeddings will be generated from `prompt` input argument.
    negative_prompt_embeds (`torch.Tensor`, *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.
    device: (`torch.device`, *optional*):
        torch device
    dtype: (`torch.dtype`, *optional*):
        torch dtype
r   )rK   rL   rM   rN   rO   Ú z?`negative_prompt` should be the same type to `prompt`, but got z != Ú.z`negative_prompt`: z has batch size z, but `prompt`: zT. Please make sure that passed `negative_prompt` matches the batch size of `prompt`.)	r[   r\   r]   r^   rl   rx   ÚtypeÚ	TypeErrorÚ
ValueError)rH   rK   rz   r{   rL   r/   r0   rM   rN   rO   rp   s              r!   Úencode_promptÚWanPipeline.encode_promptÇ   sk  € ðL ×1˜4×1Ñ1ˆä'¨´×4Ñ4�&‘¸&ˆØÑÜ˜V›‰Jà&×,Ñ,¨QÑ/ˆJàÑ Ø ×6Ñ6ØØ&;Ø$7ØØð 7ð ˆMö 'Ð+AÑ+IØ-×3°ˆOÜ@JÈ?Ô\_×@`Ñ@`˜jÐ+<Ò<ÐfuˆOàÑ!¤d¨6£l¼$¸Ó:OÒ&OÜØUÔVZÐ[jÓVkÐUlð mÜ˜V›�~ Qð(óð ð œs ?Ó3Ó3Ü Ø)¨/Ð):Ð:JÌ3ÈÓK_ÐJ`ð aØ�xÐ/°
¨|ð <3ð3óð ð &*×%?Ñ%?Ø&Ø&;Ø$7ØØð &@ð &Ð"ð Ð4Ð4r#   c	           
      óê  ^ • 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  o™T 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T R                  R                  c  Ub  [        S5      eg g s  sn	f )Né   r   z8`height` and `width` have to be divisible by 16 but are z and r~   c              3   ó@   >#   • U  H  oTR                   ;   v •  M     g 7fr   )Ú_callback_tensor_inputs)Ú.0ÚkrH   s     €r!   Ú	<genexpr>Ú+WanPipeline.check_inputs.<locals>.<genexpr>&  s   øé € ð F
Ú7Y°!�×-Ñ-Ö-Ò7Yùs   ƒ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 `negative_prompt`: z and `negative_prompt_embeds`: 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 z;`negative_prompt` has to be of type `str` or `list` but is zV`guidance_scale_2` is only supported when the pipeline's `boundary_ratio` is not None.)	r�   Úallr‡   r\   r]   Úlistr   rB   r7   )
rH   rK   rz   ÚheightÚwidthr/   r0   Ú"callback_on_step_end_tensor_inputsÚguidance_scale_2r‰   s
   `         r!   Úcheck_inputsÚWanPipeline.check_inputs  s
  ø€ ð �B‰;˜!Ó˜u r™z¨Q›ÜÐWÐX^ÐW_Ð_dÐejÐdkÐklÐmÓnÐnà-Ñ9Ä#ô F
Ù7YóF
÷ C
ñ C
ô ØDÀT×EaÑEaÐDbÐbnñ  |^ó  pHò  |^Ðvwð  ko÷  kGñ  kGñ  bG×pqñ  |^ñ  pHð  oIð  Jóð ð Ñ -Ñ";ÜØ0°°Ð8NÈ}Èoð ^0ð 0óð ð Ñ(Ð-CÑ-OÜØ9¸/Ð9JÐJið  kAð  jBð B0ð 0óð ð ‰^ Ñ 5ÜØwóð ð Ñ¬°F¼C×)@Ñ)@ÌÐTZÔ\`×IaÑIaÜÐQÔRVÐW]ÓR^ÐQ_Ð`ÓaÐaØÑ(Ü˜?¬C×0Ñ0¼ÀOÔUY×9ZÑ9ZäÐZÔ[_Ð`oÓ[pÐZqÐrÓsÐsà�;‰;×%Ñ%Ñ-Ð2BÑ2NÜÐuÓvÐvð 3OÐ-ùò1 pHs   ÁE0Á1E0éà  é@  éQ   rp   Únum_channels_latentsrŽ   r�   Ú
num_framesÚ	generatorr.   Úreturnc
                 óL  • U	b  U	R                  XvS9$ US-
  U R                  -  S-   n
UUU
[        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[        X¸XvS9n	U	$ )N)rN   rO   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™   rN   rO   )	rd   rD   ÚintrF   r\   r�   r^   r�   r   )rH   rp   r—   rŽ   r�   r˜   rO   rN   r™   r.   Únum_latent_framesrl   s               r!   Úprepare_latentsÚWanPipeline.prepare_latentsE  sÄ   € ð ÑØ—:‘: V�:Ð9Ð9à'¨!™^°×0NÑ0NÑNÐQRÑRÐàØ ØÜ�‹K˜4×8Ñ8Ñ8Ü�‹J˜$×7Ñ7Ñ7ð
ˆô �i¤×&Ñ&¬3¨y«>¸ZÓ+GÜØAÄ#ÀiÃ.ÐAQð RØ&˜<Ð'gðióð ô
 ˜uÀ&ÑVˆØˆr#   c                 ó   • U R                   $ r   ©Ú_guidance_scale©rH   s    r!   Úguidance_scaleÚWanPipeline.guidance_scalee  s   € à×#Ñ#Ð#r#   c                 ó    • U R                   S:„  $ )Nç      ð?r¡   r£   s    r!   r{   Ú'WanPipeline.do_classifier_free_guidancei  s   € à×#Ñ# cÑ)Ð)r#   c                 ó   • U R                   $ r   )Ú_num_timestepsr£   s    r!   Únum_timestepsÚWanPipeline.num_timestepsm  s   € à×"Ñ"Ð"r#   c                 ó   • U R                   $ r   )Ú_current_timestepr£   s    r!   Úcurrent_timestepÚWanPipeline.current_timestepq  ó   € à×%Ñ%Ð%r#   c                 ó   • U R                   $ r   )Ú
_interruptr£   s    r!   Ú	interruptÚWanPipeline.interruptu  s   € à�‰Ðr#   c                 ó   • U R                   $ r   )Ú_attention_kwargsr£   s    r!   Úattention_kwargsÚWanPipeline.attention_kwargsy  r±   r#   é2   g      @Únpi   Únum_inference_stepsr¤   r‘   Úoutput_typeÚreturn_dictr¸   Úcallback_on_step_endr�   c                 óV  • [        U[        [        45      (       a  UR                  nU R	                  UUUUUUUU5        XPR
                  -  S:w  aA  [        R                  SU R
                   S35        XPR
                  -  U R
                  -  S-   n[        US5      nU R                  b   U R                  R                  R                  OU R                  R                  R                  nU R                  US   -  nU R                  US   -  nUU-  U-  nUU-  U-  nUU:w  d  UU:w  a+  [        R                  SU SU SU SU S	U SU S
35        UUpCU R                  R                  b  Uc  UnXpl        X€l        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R0                  S   nU R3                  UUU R4                  U	UUUUS9u  pÍU R                  b  U R                  R6                  OU R                  R6                  nUR9                  U5      nUb  UR9                  U5      nU R:                  R=                  UUS9  U R:                  R>                  nU R                  b   U R                  R                  R@                  OU R                  R                  R@                  nU RC                  UU	-  UUUU[D        RF                  UU
U5	      n[D        RH                  " UR0                  [D        RF                  US9n[/        U5      X`R:                  RJ                  -  -
  n[/        U5      U l&        U R:                  RO                  S5        U R                  R                  b8  U R                  R                  U R:                  R                  RP                  -  n OSn U RS                  US9 n![U        U5       GH=  u  n"n#U RV                  (       a  M  U#U l        U b  U#U :¼  a  U R                  n$Un%OU R                  n$Un%UR9                  U5      n&U R                  RX                  (       aV  US   S   SS2SSS2SSS24   U#-  R[                  5       n'U'R]                  S5      R_                  UR0                  S   S5      n(OU#R_                  UR0                  S   5      n(U$Ra                  S5         U$" U&U(UUSS9S   n)SSS5        U R4                  (       a2  U$Ra                  S5         U$" U&U(UUSS9S   n*SSS5        W*U%W)U*-
  -  -   n)U R:                  Rc                  W)U#USS9S   nUb\  0 n+U H  n,[e        5       U,   U+U,'   M     U" U U"U#U+5      n-U-Rg                  SU5      nU-Rg                  SU5      nU-Rg                  SU5      nU"[/        U5      S-
  :X  d)  U"S-   U:”  a0  U"S-   U R:                  RJ                  -  S:X  a  U!Ri                  5         [j        (       d  GM(  [l        Rn                  " 5         GM@     SSS5        SU l        US:X  Gdz  UR9                  U Rp                  R6                  5      n[D        Rr                  " U Rp                  R                  Rt                  5      Rw                  SU Rp                  R                  Rx                  SSS5      R9                  URz                  UR6                  5      n.S[D        Rr                  " U Rp                  R                  R|                  5      Rw                  SU Rp                  R                  Rx                  SSS5      R9                  URz                  UR6                  5      -  n/UU/-  U.-   nU Rp                  R                  USS9S   n0U R€                  Rƒ                  U0US9n0OUn0U R…                  5         U(       d  U04$ [‡        U0S9$ ! , (       d  f       GNø= f! , (       d  f       GNÒ= f! , (       d  f       GNà= f)aª  
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, pass `prompt_embeds` instead.
    negative_prompt (`str` or `list[str]`, *optional*):
        The prompt or prompts to avoid during image generation. If not defined, pass `negative_prompt_embeds`
        instead. Ignored when not using guidance (`guidance_scale` < `1`).
    height (`int`, defaults to `480`):
        The height in pixels of the generated image.
    width (`int`, defaults to `832`):
        The width in pixels of the generated image.
    num_frames (`int`, defaults to `81`):
        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.
    guidance_scale (`float`, defaults to `5.0`):
        Guidance scale as defined in [Classifier-Free Diffusion
        Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` is defined as `w` of equation 2.
        of [Imagen Paper](https://huggingface.co/papers/2205.11487). Guidance scale is enabled by setting
        `guidance_scale > 1`. Higher guidance scale encourages to generate images that are closely linked to
        the text `prompt`, usually at the expense of lower image quality.
    guidance_scale_2 (`float`, *optional*, defaults to `None`):
        Guidance scale for the low-noise stage transformer (`transformer_2`). If `None` and the pipeline's
        `boundary_ratio` is not None, uses the same value as `guidance_scale`. Only used when `transformer_2`
        and the pipeline's `boundary_ratio` are not None.
    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.
    negative_prompt_embeds (`torch.Tensor`, *optional*):
        Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
        not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
    output_type (`str`, *optional*, defaults to `"np"`):
        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 [`WanPipelineOutput`] 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).
    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.
    max_sequence_length (`int`, defaults to `512`):
        The maximum sequence length of the text encoder. If the prompt is longer than this, it will be
        truncated. If the prompt is shorter, it will be padded to this length.

Examples:

Returns:
    [`~WanPipelineOutput`] or `tuple`:
        If `return_dict` is `True`, [`WanPipelineOutput`] 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.
r   z(`num_frames - 1` has to be divisible by z!. Rounding to the nearest number.Nr   z+`height` and `width` must be multiples of (z, z() for proper patchification. Adjusting (z) -> (z).Fr   )rK   rz   r{   rL   r/   r0   rM   rN   )rN   rY   )ÚtotalrZ   Úcond)Úhidden_statesÚtimestepÚencoder_hidden_statesr¸   r¾   Úuncond)r¾   r.   r/   r0   Úlatentr§   )r½   )Úframes)Dr\   r	   r   Útensor_inputsr’   rD   ÚloggerÚwarningÚmaxr1   rB   Ú
patch_sizer2   rF   r7   r¢   Ú_guidance_scale_2r·   r®   r³   r[   r]   r�   r^   rl   r‚   r{   rO   rd   r6   Úset_timestepsÚ	timestepsÚin_channelsrž   rg   Úfloat32ÚonesÚorderrª   Úset_begin_indexÚnum_train_timestepsÚprogress_barÚ	enumerater´   r8   ÚflattenÚ	unsqueezeÚexpandÚcache_contextÚstepÚlocalsÚpopÚupdateÚXLA_AVAILABLEÚxmÚ	mark_stepr5   ÚtensorÚlatents_meanrn   Úz_dimrN   Úlatents_stdÚdecoderG   Úpostprocess_videoÚmaybe_free_model_hooksr   )1rH   rK   rz   rŽ   r�   r˜   r¼   r¤   r‘   rL   r™   r.   r/   r0   r½   r¾   r¸   r¿   r�   rM   rÍ   Úh_multiple_ofÚw_multiple_ofÚcalc_heightÚ
calc_widthrN   rp   Útransformer_dtyperÐ   r—   rs   Únum_warmup_stepsÚboundary_timestepr×   ÚiÚtÚcurrent_modelÚcurrent_guidance_scaleÚlatent_model_inputÚtemp_tsrÄ   Ú
noise_predÚnoise_uncondÚcallback_kwargsr‰   Úcallback_outputsrå   rç   Úvideos1                                                    r!   Ú__call__ÚWanPipeline.__call__}  sÂ  € ôB Ð*Ô-=Ô?UÐ,V×WÑWØ1E×1SÑ1SÐ.ð 	×ÑØØØØØØ"Ø.Øô		
ð ×6Ñ6Ñ6¸!Ó;Ü�N‰NØ:¸4×;YÑ;YÐ:ZÐZ{Ð|ôð $×'EÑ'EÑEÈ×HfÑHfÑfÐijÑjˆJÜ˜ QÓ'ˆ
ð ×ÑÑ+ð ×Ñ×#Ñ#×.Ò.à×#Ñ#×*Ñ*×5Ñ5ð 	ð
 ×5Ñ5¸
À1¹ÑEˆØ×5Ñ5¸
À1¹ÑEˆØ Ñ-°Ñ=ˆØ˜mÑ+¨mÑ;ˆ
Ø�[Ó  E¨ZÓ$7Ü�N‰NØ=¸m¸_ÈBÈ}Èoð ^Ø$˜X R¨ w¨f°[°MÀÀJÀ<ÈrðSôð (¨�Eà�;‰;×%Ñ%Ñ1Ð6FÑ6NØ-Ðà-ÔØ!1ÔØ!1ˆÔØ!%ˆÔØˆŒà×'Ñ'ˆð Ñ¤*¨V´S×"9Ñ"9Ø‰JØÑ¤J¨v´t×$<Ñ$<Ü˜V›‰Jà&×,Ñ,¨QÑ/ˆJð 15×0BÑ0BØØ+Ø(,×(HÑ(HØ"7Ø'Ø#9Ø 3Øð 1Cð 	1
Ñ-ˆð 7;×6FÑ6FÑ6R˜D×,Ñ,×2Ò2ÐX\×XjÑXj×XpÑXpÐØ%×(Ñ(Ð):Ó;ˆØ!Ñ-Ø%;×%>Ñ%>Ð?PÓ%QÐ"ð 	�‰×$Ñ$Ð%8ÀÐ$ÑHØ—N‘N×,Ñ,ˆ	ð
 ×ÑÑ+ð ×Ñ×#Ñ#×/Ò/à×#Ñ#×*Ñ*×6Ñ6ð 	ð
 ×&Ñ&ØÐ.Ñ.Ø ØØØÜ�M‰MØØØó

ˆô �zŠz˜'Ÿ-™-¬u¯}©}ÀVÑLˆô ˜y›>Ð,?Ç.Á.×BVÑBVÑ,VÑVÐÜ! )›nˆÔð 	�‰×&Ñ& qÔ)à�;‰;×%Ñ%Ñ1Ø $§¡× :Ñ :¸T¿^¹^×=RÑ=R×=fÑ=fÑ fÑà $Ðà×ÑÐ%8ÐÑ9¸\Ü! )×,‘��1Ø—>—>Ùà)*�Ô&à$Ñ,°Ð5FÓ0Fà$(×$4Ñ$4�MØ-;Ñ*ð %)×$6Ñ$6�MØ-=Ð*à%,§Z¡ZÐ0AÓ%BÐ"Ø—;‘;×/×/à# A™w q™zª!©S¨q¨S±#°A°#¨+Ñ6¸Ñ:×CÑCÓE�Gà&×0Ñ0°Ó3×:Ñ:¸7¿=¹=ÈÑ;KÈRÓP‘Hà Ÿx™x¨¯©°aÑ(8Ó9�Hà"×0Ñ0°Õ8Ù!.Ø&8Ø!)Ø.;Ø)9Ø$)ñ"ð ñ"�J÷ 9ð ×3×3Ø&×4Ñ4°XÕ>Ù'4Ø*<Ø%-Ø2HØ-=Ø(-ñ(ð ñ(˜÷ ?ð ".Ð0FÈ*ÐWcÑJcÑ0dÑ!d�Jð Ÿ.™.×-Ñ-¨j¸!¸WÐRWÐ-ÐXÐYZÑ[�à'Ñ3Ø&(�OÛ?˜Ü-3«X°a©[˜¨Ó*ñ @á';¸DÀ!ÀQÈÓ'XÐ$à.×2Ñ2°9¸gÓF�GØ$4×$8Ñ$8¸È-Ó$X�MØ-=×-AÑ-AÐBZÐ\rÓ-sÐ*ð œ˜I›¨Ñ*Ó*°°A±Ð9IÓ/IÈqÐSTÉuÐX\×XfÑXf×XlÑXlÑNlÐpqÓNqØ ×'Ñ'Ô)ç •=Ü—L’L—Nñ} -÷ :ðB "&ˆÔà˜hÔ&Ø—j‘j §¡§¡Ó0ˆGä—’˜TŸX™XŸ_™_×9Ñ9Ó:ß‘�a˜Ÿ™Ÿ™×.Ñ.°°1°aÓ8ß‘�G—N‘N G§M¡MÓ2ð ð
 ¤§¢¨T¯X©X¯_©_×-HÑ-HÓ I× NÑ NÈqÐRV×RZÑRZ×RaÑRa×RgÑRgÐijÐlmÐopÓ q× tÑ tØ—‘ §¡ó!ñ ˆKð  Ñ+¨lÑ:ˆGØ—H‘H—O‘O G¸�OÐ?ÀÑBˆEØ×(Ñ(×:Ñ:¸5ÈkÐ:ÐZ‰EàˆEð 	×#Ñ#Ô%æØ�8ˆOä ¨Ñ.Ð.÷A 9Ö8ú÷ ?Ö>ú÷G :Ö9úsD   Ï2D`Ó6_5Ô*`Ô.`Ô<C%`Ø&`ß5
`ß?`à
`à`à
`()	r·   r®   r¢   rÎ   r³   rª   rF   rD   rG   )NNNF)Nr   éâ   NN)NTr   NNrÿ   NN)NNNN)r…   r”   r•   r–   NNNN).Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úmodel_cpu_offload_seqr‡   Ú_optional_componentsr   r   r   r   r   ÚfloatÚboolr>   r]   r�   rœ   rg   rN   rO   rx   ÚTensorr‚   r’   Ú	Generatorrž   Úpropertyr¤   r{   r«   r¯   r´   r¸   Úno_gradr   ÚEXAMPLE_DOC_STRINGÚdictr   r   r	   r   rý   Ú__static_attributes__Ú__classcell__)rI   s   @r!   r,   r,   `   s¶  ø† ñð< LÐÚTÐØ)¨?Ð;Ðð 59Ø6:Ø'+Ø!&ñ^à ð^ð 'ð^ð ð	^ð
 3ð^ð +¨TÑ1ð^ð -¨tÑ3ð^ð  ™ð^ð ÷^ð ^ð: #'Ø%&Ø#&Ø&*Ø$(ñ'à�d˜3‘i‘ð'ð  #ð'ð !ð	'ð
 —‘˜tÑ#ð'ð �{‰{˜TÑ!õ'ðX 37Ø,0Ø%&Ø-1Ø6:Ø#&Ø&*Ø$(ñO5à�d˜3‘i‘ðO5ð ˜t C™y™¨4Ñ/ðO5ð &*ð	O5ð
  #ðO5ð —|‘| dÑ*ðO5ð !&§¡¨tÑ 3ðO5ð !ðO5ð —‘˜tÑ#ðO5ð �{‰{˜TÑ!õO5ðn Ø#Ø+/Øô+wð` %'ØØØØ$(Ø&*ØDHØ'+ñàðð "ðð ð	ð
 ðð ðð �{‰{˜TÑ!ðð —‘˜tÑ#ðð —?‘? T¨%¯/©/Ñ%:Ñ:¸TÑAðð —‘ Ñ$ðð 
�‰õð@ ñ$ó ð$ð ñ*ó ð*ð ñ#ó ð#ð ñ&ó ð&ð ñó ðð ñ&ó ð&ð ‡]‚]ƒ_ÙÐ1Ó2ð #'Ø+/ØØØØ#%Ø #Ø)-Ø,-ØDHØ'+Ø-1Ø6:Ø"&Ø Ø26ØnrØ9B¸Ø#&ñ)g/à�d˜3‘i‘ðg/ð ˜t C™y™ðg/ð ð	g/ð
 ðg/ð ðg/ð !ðg/ð ðg/ð   $™,ðg/ð  # T™zðg/ð —?‘? T¨%¯/©/Ñ%:Ñ:¸TÑAðg/ð —‘ Ñ$ðg/ð —|‘| dÑ*ðg/ð !&§¡¨tÑ 3ðg/ð ˜4‘Zðg/ð  ð!g/ð" ˜s C˜x™.¨4Ñ/ð#g/ð$ '¨¨S z°4Ð'7Ñ8Ð;KÑKÐNdÑdÐgkÑkð%g/ð& -1°©Ið'g/ð( !ô)g/ó 3ó ög/r#   r,   )/r   Útypingr   r   Úregexr&   rg   Útransformersr   r   Ú	callbacksr   r	   Úloadersr
   Úmodelsr   r   Ú
schedulersr   Úutilsr   r   r   r   Úutils.torch_utilsr   rG   r   Úpipeline_utilsr   Úpipeline_outputr   Útorch_xla.core.xla_modelÚcoreÚ	xla_modelrâ   rá   Ú
get_loggerr   rÊ   r   r  r"   r(   r*   r,   © r#   r!   Ú<module>r!     s•   ðó ß  ã Û ß 8ç AÝ )ß =Ý 9ß bÓ bÝ -Ý -Ý .Ý .ñ ×Ñß)Ð)à�Mà€Mà	×	Ò	˜HÓ	%€á×ÑÛðÐ ò@òòô
F	/Ð#Ð%7õ F	/r#   