
    +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
Js  Jr  S SKJrJr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JrJrJrJrJ r   SSK!J"r"  SS	K#J$r$  SS
K%J&r&J'r'J(r(J)r)J*r*J+r+  SSK,J-r-J.r.J/r/J0r0J1r1  SSK2J3r3J4r4  SSK5J6r6  SSK7J8r8  SSK9J:r:  SSK;J<r<J=r=  SSK>J?r?  \." 5       (       a  S SK@JAs  JBrC  SrDOSrD\/R                  " \F5      rGSrH S"S\	R                  S\\	R                     S\K4S jjrL    S#S\\M   S\\\K\	R                  4      S\\\M      S\\\O      4S jjrP " S  S!\<\=\\\\8\:\5
      rQg)$    N)AnyCallableDictListOptionalTupleUnion)CLIPImageProcessorCLIPTextModelCLIPTokenizerCLIPVisionModelWithProjection   )PipelineImageInput)FromSingleFileMixinIPAdapterMixinStableDiffusionLoraLoaderMixinTextualInversionLoaderMixin)AutoencoderKLControlNetModelImageProjectionMultiControlNetModelUNet2DConditionModelUNetMotionModel)adjust_lora_scale_text_encoder)MotionAdapter)DDIMSchedulerDPMSolverMultistepSchedulerEulerAncestralDiscreteSchedulerEulerDiscreteSchedulerLMSDiscreteSchedulerPNDMScheduler)USE_PEFT_BACKENDis_torch_xla_availableloggingscale_lora_layersunscale_lora_layers)is_compiled_modulerandn_tensor)VideoProcessor   )FreeInitMixin)AnimateDiffFreeNoiseMixin)DiffusionPipelineStableDiffusionMixin   )AnimateDiffPipelineOutputTFak
  
    Examples:
        ```py
        >>> import torch
        >>> from PIL import Image
        >>> from tqdm.auto import tqdm

        >>> from diffusers import AnimateDiffVideoToVideoControlNetPipeline
        >>> from diffusers.utils import export_to_gif, load_video
        >>> from diffusers import AutoencoderKL, ControlNetModel, MotionAdapter, LCMScheduler

        >>> controlnet = ControlNetModel.from_pretrained(
        ...     "lllyasviel/sd-controlnet-openpose", torch_dtype=torch.float16
        ... )
        >>> motion_adapter = MotionAdapter.from_pretrained("wangfuyun/AnimateLCM")
        >>> vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse", torch_dtype=torch.float16)

        >>> pipe = AnimateDiffVideoToVideoControlNetPipeline.from_pretrained(
        ...     "SG161222/Realistic_Vision_V5.1_noVAE",
        ...     motion_adapter=motion_adapter,
        ...     controlnet=controlnet,
        ...     vae=vae,
        ... ).to(device="cuda", dtype=torch.float16)

        >>> pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config, beta_schedule="linear")
        >>> pipe.load_lora_weights(
        ...     "wangfuyun/AnimateLCM", weight_name="AnimateLCM_sd15_t2v_lora.safetensors", adapter_name="lcm-lora"
        ... )
        >>> pipe.set_adapters(["lcm-lora"], [0.8])

        >>> video = load_video(
        ...     "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/dance.gif"
        ... )
        >>> video = [frame.convert("RGB") for frame in video]

        >>> from controlnet_aux.processor import OpenposeDetector

        >>> open_pose = OpenposeDetector.from_pretrained("lllyasviel/Annotators").to("cuda")
        >>> for frame in tqdm(video):
        ...     conditioning_frames.append(open_pose(frame))

        >>> prompt = "astronaut in space, dancing"
        >>> negative_prompt = "bad quality, worst quality, jpeg artifacts, ugly"

        >>> strength = 0.8
        >>> with torch.inference_mode():
        ...     video = pipe(
        ...         video=video,
        ...         prompt=prompt,
        ...         negative_prompt=negative_prompt,
        ...         num_inference_steps=10,
        ...         guidance_scale=2.0,
        ...         controlnet_conditioning_scale=0.75,
        ...         conditioning_frames=conditioning_frames,
        ...         strength=strength,
        ...         generator=torch.Generator().manual_seed(42),
        ...     ).frames[0]

        >>> video = [frame.resize(conditioning_frames[0].size) for frame in video]
        >>> export_to_gif(video, f"animatediff_vid2vid_controlnet.gif", fps=8)
        ```
encoder_output	generatorsample_modec                    [        U S5      (       a!  US:X  a  U R                  R                  U5      $ [        U S5      (       a   US:X  a  U R                  R                  5       $ [        U S5      (       a  U R                  $ [        S5      e)Nlatent_distsampleargmaxlatentsz3Could not access latents of provided encoder_output)hasattrr5   r6   moder8   AttributeError)r1   r2   r3   s      څ/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/animatediff/pipeline_animatediff_video2video_controlnet.pyretrieve_latentsr=   ~   s}     ~}--+2I))00;;		/	/K84K))..00		+	+%%%RSS    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 valuesrA   zThe current scheduler class zx's `set_timesteps` does not support custom timestep schedules. Please check whether you are using the correct scheduler.)rA   r@   rB   zv's `set_timesteps` does not support custom sigmas schedules. Please check whether you are using the correct scheduler.)rB   r@   r@    )

ValueErrorsetinspect	signatureset_timesteps
parameterskeys	__class__rA   len)	schedulerr?   r@   rA   rB   kwargsaccepts_timestepsaccept_sigmass           r<   retrieve_timestepsrR      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''	))r>   c            @         ^  \ rS rSrSrSr/ SQr/ SQr  STS\S\	S	\
S
\\\4   S\S\\\\   \\   \4   S\\\\\\\4   S\S\4U 4S jjjr     SUS\\R<                     S\\R<                     S\\   S\\    4S jjr!SVS jr"S r#SWS\ S\R<                  4S jjr$SWS\ 4S jjr%S r&            SXS  jr'S! r(            SYS$\\R<                     S%\ S&\ S'\ S(\ S)\\    S*\\RR                     S+\\RT                     S,\\\RV                  \\RV                     4      S-\\R<                     S\ S.\,S\R<                  4S/ jjr-  SZS0 jr.\/S1 5       r0\/S2 5       r1\/S3 5       r2\/S4 5       r3\/S5 5       r4\/S6 5       r5\Rl                  " 5       SSSSS7S#SSS8S9SS"SSSSSSSSS:S;SSS#SSSSS-/S4S$\\\7      S<\\\8\\8   4      S%\\    S&\\    S=\ S>\,S?\\\       S@\\\      SA\SB\SC\\\8\\8   4      SD\\    SE\S,\\\RV                  \\RV                     4      S-\\R<                     S\\R<                     S\\R<                     SF\\7   SG\\\R<                        SH\\\7      SI\\8   SJ\,SK\\9\8\:4      SL\\\\   4   SM\,SN\\\\   4   SO\\\\   4   S\\    SP\\;\ \ \9/S4      SQ\\8   S\ 4>SR jj5       r<SSr=U =r>$ )[)AnimateDiffVideoToVideoControlNetPipeline   a  
Pipeline for video-to-video generation with ControlNet guidance.

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.).

The pipeline also inherits the following loading methods:
    - [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
    - [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_weights`] for loading LoRA weights
    - [`~loaders.StableDiffusionLoraLoaderMixin.save_lora_weights`] for saving LoRA weights
    - [`~loaders.IPAdapterMixin.load_ip_adapter`] for loading IP Adapters

Args:
    vae ([`AutoencoderKL`]):
        Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
    text_encoder ([`CLIPTextModel`]):
        Frozen text-encoder ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)).
    tokenizer (`CLIPTokenizer`):
        A [`~transformers.CLIPTokenizer`] to tokenize text.
    unet ([`UNet2DConditionModel`]):
        A [`UNet2DConditionModel`] used to create a UNetMotionModel to denoise the encoded video latents.
    motion_adapter ([`MotionAdapter`]):
        A [`MotionAdapter`] to be used in combination with `unet` to denoise the encoded video latents.
    controlnet ([`ControlNetModel`] or `List[ControlNetModel]` or `Tuple[ControlNetModel]` or `MultiControlNetModel`):
        Provides additional conditioning to the `unet` during the denoising process. If you set multiple
        ControlNets as a list, the outputs from each ControlNet are added together to create one combined
        additional conditioning.
    scheduler ([`SchedulerMixin`]):
        A scheduler to be used in combination with `unet` to denoise the encoded image latents. Can be one of
        [`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
z&text_encoder->image_encoder->unet->vae)feature_extractorimage_encodermotion_adapter)r8   prompt_embedsnegative_prompt_embedsNvaetext_encoder	tokenizerunetrX   
controlnetrN   rV   rW   c
                   > [         T
U ]  5         [        U[        5      (       a  [        R
                  " XE5      n[        U[        [        45      (       a  [        U5      nU R                  UUUUUUUUU	S9	  [        U SS 5      (       a/  S[        U R                  R                  R                  5      S-
  -  OSU l        [!        U R                  S9U l        [!        U R                  SSS	9U l        g )
N)	r[   r\   r]   r^   rX   r_   rN   rV   rW   r[   r*   r/      )vae_scale_factorTF)rb   do_convert_rgbdo_normalize)super__init__
isinstancer   r   from_unet2dlisttupler   register_modulesgetattrrM   r[   configblock_out_channelsrb   r)   video_processorcontrol_video_processor)selfr[   r\   r]   r^   rX   r_   rN   rV   rW   rL   s             r<   rf   2AnimateDiffVideoToVideoControlNetPipeline.__init__   s    & 	d011"..tDDj4-00-j9J%)!/' 	 
	
 W^^bdikoVpVpc$((//*L*L&MPQ&Q Rvw-t?T?TU'5!224V[(
$r>   rY   rZ   
lora_scale	clip_skipc
                 
   UbS  [        U [        5      (       a>  Xl        [        (       d  [	        U R
                  U5        O[        U R
                  U5        Ub  [        U[        [        45      (       a  Sn
O3Ub!  [        U[        5      (       a  [        U5      n
OUR                  S   n
UGc  [        U [        5      (       a  U R                  XR                  5      nU R                  USU R                  R                  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      (       dj  U R                  R'                  USS2U R                  R                  S-
  S
24   5      n[(        R+                  SU R                  R                   SU 35        [-        U R
                  R.                  S5      (       aA  U R
                  R.                  R0                  (       a  UR2                  R5                  U5      nOSnU	c%  U R                  UR5                  U5      US9nUS   nOQU R                  UR5                  U5      USS9nUS
   U	S-   *    nU R
                  R6                  R9                  U5      nU R
                  b  U R
                  R:                  nO0U R<                  b  U R<                  R:                  nOUR:                  nUR5                  UUS9nUR                  u  nnnUR?                  SUS5      nURA                  UU-  US
5      nU(       Ga  UGc|  Uc  S/U
-  nOUb;  [C        U5      [C        U5      La$  [E        S[C        U5       S[C        U5       S35      e[        U[        5      (       a  U/nO2U
[        U5      :w  a!  [G        SU S[        U5       SU SU
 S3	5      eUn[        U [        5      (       a  U R                  UU R                  5      nUR                  S   nU R                  USUSSS9n[-        U R
                  R.                  S5      (       aA  U R
                  R.                  R0                  (       a  UR2                  R5                  U5      nOSnU R                  UR                   R5                  U5      US9nUS   nU(       aG  UR                  S   nUR5                  UUS9nUR?                  SUS5      nURA                  X-  US
5      nU R
                  b6  [        U [        5      (       a!  [        (       a  [I        U R
                  U5        Xg4$ )a,  
Encodes the prompt into text encoder hidden states.

Args:
    prompt (`str` or `List[str]`, *optional*):
        prompt to be encoded
    device: (`torch.device`):
        torch device
    num_images_per_prompt (`int`):
        number of images that should be generated per prompt
    do_classifier_free_guidance (`bool`):
        whether to use classifier free guidance or not
    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`).
    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.
    lora_scale (`float`, *optional*):
        A LoRA scale that will be applied to all LoRA layers of the text encoder if LoRA layers are loaded.
    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.
Nr/   r   
max_lengthTpt)paddingrv   
truncationreturn_tensorslongest)rx   rz   z\The following part of your input was truncated because CLIP can only handle sequences up to z	 tokens: use_attention_mask)attention_mask)r~   output_hidden_states)dtyper@    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`.)%rg   r   _lora_scaler"   r   r\   r%   strdictri   rM   shaper   maybe_convert_promptr]   model_max_length	input_idstorchequalbatch_decodeloggerwarningr9   rm   r}   r~   to
text_modelfinal_layer_normr   r^   repeatviewtype	TypeErrorrE   r&   )rq   promptr@   num_images_per_promptdo_classifier_free_guidancenegative_promptrY   rZ   rs   rt   
batch_sizetext_inputstext_input_idsuntruncated_idsremoved_textr~   prompt_embeds_dtypebs_embedseq_len_uncond_tokensrv   uncond_inputs                          r<   encode_prompt7AnimateDiffVideoToVideoControlNetPipeline.encode_prompt!  sU   V !j7U&V&V) $#.t/@/@*M!$"3"3Z@*Vc4["A"AJJvt$<$<VJ&,,Q/J $ ;<<226>>J..$>>::# ) K )22N"nnVYW[n\ffO$$R(N,@,@,DDU[[N N  $~~::#At~~'F'F'JR'O$OP  778	,Q
 t((//1EFF4K\K\KcKcKvKv!,!;!;!>!>v!F!%  $ 1 1.2C2CF2K\j 1 k -a 0 $ 1 1"%%f-ncg !2 ! !.b 1IM2B C
 !% 1 1 < < M Mm \("&"3"3"9"9YY""&))//"/"5"5%((/B6(R,22'1%,,Q0EqI%**86K+KWVXY '+A+I&!#z 1#VD<Q(QUVZ[jVkUl mV~Q(  OS11!0 1s?33 )/)::J3K_J` ax/
| <33  !0 $ ;<< $ 9 9- X&,,Q/J>>$%# * L t((//1EFF4K\K\KcKcKvKv!-!<!<!?!?!G!%%)%6%6&&))&1- &7 &" &<A%>"&,2215G%;%>%>EXag%>%h"%;%B%B1F[]^%_"%;%@%@Acelnp%q"($ >??DTDT#D$5$5zB44r>   c                 d   [        U R                  R                  5       5      R                  n[	        U[
        R                  5      (       d  U R                  USS9R                  nUR                  X%S9nU(       aq  U R                  USS9R                  S   nUR                  USS9nU R                  [
        R                  " U5      SS9R                  S   nUR                  USS9nXg4$ U R                  U5      R                  nUR                  USS9n[
        R                  " U5      n	X4$ )	Nrw   )rz   r@   r   T)r   r   dim)nextrW   rJ   r   rg   r   TensorrV   pixel_valuesr   hidden_statesrepeat_interleave
zeros_likeimage_embeds)
rq   imager@   r   r   r   image_enc_hidden_statesuncond_image_enc_hidden_statesr   uncond_image_embedss
             r<   encode_image6AnimateDiffVideoToVideoControlNetPipeline.encode_image  s?   T''2245;;%..**5*FSSE4&*&8&8UY&8&Z&h&hik&l#&=&O&OPekl&O&m#-1-?-?  'd .@ .mB. * .L-]-]%1 .^ .* +JJ--e4AAL'99:OUV9WL"'"2"2<"@44r>   c                 
   / nU(       a  / nUGc&  [        U[        5      (       d  U/n[        U5      [        U R                  R                  R
                  5      :w  aB  [        S[        U5       S[        U R                  R                  R
                  5       S35      e[        XR                  R                  R
                  5       Hh  u  p[        U	[        5      (       + n
U R                  XSU
5      u  pUR                  US S S 24   5        U(       d  MP  WR                  US S S 24   5        Mj     OEU H?  nU(       a$  UR                  S5      u  pWR                  U5        UR                  U5        MA     / n[        U5       Hw  u  p[        R                  " U/U-  SS9nU(       a2  [        R                  " WU   /U-  SS9n[        R                  " X/SS9nUR                  US9nUR                  U5        My     U$ )	NzK`ip_adapter_image` must have same length as the number of IP Adapters. Got z images and z IP Adapters.r/   r*   r   r   )r@   )rg   ri   rM   r^   encoder_hid_projimage_projection_layersrE   zipr   r   appendchunk	enumerater   catr   )rq   ip_adapter_imageip_adapter_image_embedsr@   r   r   r   negative_image_embedssingle_ip_adapter_imageimage_proj_layeroutput_hidden_statesingle_image_embedssingle_negative_image_embedsis                 r<   prepare_ip_adapter_image_embedsIAnimateDiffVideoToVideoControlNetPipeline.prepare_ip_adapter_image_embeds  s9    &$&!"*.55$4#5 #$DII,F,F,^,^(__ abefvbwax  yE  FI  JN  JS  JS  Jd  Jd  J|  J|  F}  E~  ~K  L  >A ))"<"<"T"T>9' +55E*W&W#DHDUDU+Q8KEA# ##$7a$@A..)001MdTUg1VW> (?#.H[HaHabcHdE0)001MN##$78	 (? #%&/&="A"'))-@,ADY,Y_`"a*/4yy:OPQ:R9SVk9kqr/s,&+ii1M0cij&k#"5"8"8"8"G#**+>? '> '&r>      decode_chunk_sizereturnc                     / n[        S[        U5      U5       H=  nXXS-    n[        U R                  R	                  U5      US9nUR                  U5        M?     [        R                  " U5      $ )Nr   )r2   )rangerM   r=   r[   encoder   r   r   )rq   videor2   r   r8   r   batch_videos          r<   encode_video6AnimateDiffVideoToVideoControlNetPipeline.encode_video  sc    q#e*&78AA$9:K*488??;+GS\]KNN;' 9 yy!!r>   c                 F   SU R                   R                  R                  -  U-  nUR                  u  p4pVnUR	                  SSSSS5      R                  X5-  XFU5      n/ n[        SUR                  S   U5       H?  n	XX-    n
U R                   R                  U
5      R                  n
UR                  U
5        MA     [        R                  " U5      nUS S S 24   R                  X5S4UR                  SS  -   5      R	                  SSSSS5      nUR                  5       nU$ )Nr/   r   r*   r      r|   )r[   rm   scaling_factorr   permutereshaper   decoder6   r   r   r   float)rq   r8   r   r   channels
num_framesheightwidthr   r   batch_latentss              r<   decode_latents8AnimateDiffVideoToVideoControlNetPipeline.decode_latents(  s   dhhoo444w>:A--7
j%//!Q1a0889PRZdijq'--*,=>A#(=>M HHOOM:AAMLL' ?
 		% dAg&&
'CekkRSRTo'UV^^_`bcefhiklmr>   c                 n   S[        [        R                  " U R                  R                  5      R
                  R                  5       5      ;   n0 nU(       a  X$S'   S[        [        R                  " U R                  R                  5      R
                  R                  5       5      ;   nU(       a  XS'   U$ )Netar2   )rF   rG   rH   rN   steprJ   rK   )rq   r2   r   accepts_etaextra_step_kwargsaccepts_generators         r<   prepare_extra_step_kwargsCAnimateDiffVideoToVideoControlNetPipeline.prepare_extra_step_kwargs;  s     s7#4#4T^^5H5H#I#T#T#Y#Y#[\\'*e$ (3w/@/@ATAT/U/`/`/e/e/g+hh-6k*  r>         ?        c                    ^ ^ US:  d  US:  a  [        SU 35      eUS-  S:w  d	  US-  S:w  a  [        SU SU S35      eUbX  [        U 4S jU 5       5      (       d>  [        S	T R                   S
U Vs/ s H  nU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c  U	c  [        S5      eUb7  [        U[        [
        [        45      (       d  [        S[        U5       35      eUb  U
b  [        SU SU
 S35      eU	bC  U
b@  U	R                  U
R                  :w  a&  [        SU	R                   SU
R                   S35      eUb  Ub  [        S5      eUb  Ub  [        S5      eUb[  [        U[
        5      (       d  [        S[        U5       35      eUS   R                  S;  a  [        SUS   R                   S35      e[        T R                  [        5      (       aW  [        U[
        5      (       aB  [        R                  S[        T R                  R                  5       S[        U5       S35        [!        ["        S5      =(       a8    [        T R                  [$        R&                  R(                  R*                  5      nUc  [        U5      OUR                  S   n[        T R                  [,        5      (       d0  U(       a  [        T R                  R.                  [,        5      (       aW  [        T[
        5      (       d  [1        S[        T5       35      e[        T5      U:w  a  [        S U S![        T5      < 35      eO[        T R                  [        5      (       d0  U(       a  [        T R                  R.                  [        5      (       a  [        T[
        5      (       a  [        TS   [
        5      (       d  [1        S"[        T5      < 35      e[        TS   5      U:w  a  [        S#U S![        T5      < 35      e[3        U4S$ jT 5       5      (       a  [        S%5      eO e[        T R                  [,        5      (       d0  U(       aJ  [        T R                  R.                  [,        5      (       a!  [        U[4        5      (       d  [1        S&5      eO[        T R                  [        5      (       d0  U(       a  [        T R                  R.                  [        5      (       a  [        U[
        5      (       a#  [3        S' U 5       5      (       a  [        S(5      eOO[        U[
        5      (       a7  [        U5      [        T R                  R                  5      :w  a  [        S)5      eO e[        U[6        [
        45      (       d  U/n[        U[6        [
        45      (       d  U/n[        U5      [        U5      :w  a$  [        S*[        U5       S+[        U5       S,35      e[        T R                  [        5      (       a  [        U5      [        T R                  R                  5      :w  a[  [        S-U S.[        U5       S/[        T R                  R                  5       S0[        T R                  R                  5       S3	5      e[9        UU5       HH  u  nnUU:  a  [        S1U S2U S35      eUS3:  a  [        S1U S435      eUS5:  d  M;  [        S6U S735      e   g s  snf )8Nr   r/   z2The value of strength should in [0.0, 1.0] but is ra   z7`height` and `width` have to be divisible by 8 but are z and r   c              3   @   >#    U  H  oTR                   ;   v   M     g 7fN)_callback_tensor_inputs).0krq   s     r<   	<genexpr>IAnimateDiffVideoToVideoControlNetPipeline.check_inputs.<locals>.<genexpr>e  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.zeProvide either `prompt` or `prompt_embeds`. Cannot leave both `prompt` and `prompt_embeds` undefined.z:`prompt` has to be of type `str`, `list` or `dict` but is z'Cannot forward both `negative_prompt`: z and `negative_prompt_embeds`: zu`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but got: `prompt_embeds` z != `negative_prompt_embeds` z3Only one of `video` or `latents` should be providedzProvide either `ip_adapter_image` or `ip_adapter_image_embeds`. Cannot leave both `ip_adapter_image` and `ip_adapter_image_embeds` defined.z:`ip_adapter_image_embeds` has to be of type `list` but is )r   r   zF`ip_adapter_image_embeds` has to be a list of 3D or 4D tensors but is Dz	You have z! ControlNets and you have passed z= prompts. The conditionings will be fixed across the prompts.scaled_dot_product_attentionr*   z>For single controlnet, `image` must be of type `list` but got zExcepted image to have length z" but got len(conditioning_frames)=z_For multiple controlnets: `image` must be type list of lists but got type(conditioning_frames)=z$Expected length of image sublist as c              3   X   >#    U  H  n[        U5      [        TS    5      :g  v   M!     g7f)r   N)rM   )r   imgconditioning_framess     r<   r   r     s'     ZFYs3s8s#6q#9::FYs   '*zDAll conditioning frame batches for multicontrolnet must be same sizezLFor single controlnet: `controlnet_conditioning_scale` must be type `float`.c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )rg   ri   )r   r   s     r<   r   r     s     R4Qqz!T**4Qs   zEA single batch of multiple conditionings are supported at the moment.zFor multiple controlnets: When `controlnet_conditioning_scale` is specified as `list`, it must have the same length as the number of controlnetsz`control_guidance_start` has z* elements, but `control_guidance_end` has zI elements. Make sure to provide the same number of elements to each list.z`control_guidance_start`: z has z elements but there are z- controlnets available. Make sure to provide zcontrol guidance start: z4 cannot be larger or equal to control guidance end: r   z can't be smaller than 0.r   zcontrol guidance end: z can't be larger than 1.0.)rE   allr   rg   r   ri   r   r   r   ndimr_   r   r   r   rM   netsr9   Fr   _dynamo
eval_frameOptimizedModuler   	_orig_modr   anyr   rj   r   )rq   r   strengthr   r   r   r   r8   r   rY   rZ   r   r   "callback_on_step_end_tensor_inputscontrolnet_conditioning_scalecontrol_guidance_startcontrol_guidance_endr   is_compiledr   startends   `     `               r<   check_inputs6AnimateDiffVideoToVideoControlNetPipeline.check_inputsL  s   & a<8a<QRZQ[\]]A:?eai1nVW]V^^cdicjjklmm-9# F
7YF
 C
 C
 DTEaEaDbbn  |^  pH  |^vw  bc  ko  kG  kG  bGpq  |^  pH  oI  J  -";08N}o ^0 0  ^ 5w  
6Ct;L(M(MYZ^_eZfYghii&+A+M9/9J K*++]_ 
 $)?)K""&<&B&BB --:-@-@,A B.445Q8  !4RSS',C,O ^  #.5t<< PQUVmQnPop  )+00> \]tuv]w]|]|\}}~  doo';<<&$''DOO$8$8 9::[\_`f\g[hST a!?@ 
ZOOU]]55EEF
 $+?SZa8H
 t884??44oFF1488TUYZmUnTop  &':5 #A*MpWZ[nWoVq!rss 6 t(<==4??446JKK1488
K^_`Kacg@h@hv\`at\u[wx  &q)*j8 ::,FiPSTgPhOjk  ZFYZZZ !ghh [ 5 t884??44oFF;UCC noo D t(<==4??446JKK7>>R4QRRR$%lmm S94@@SIfEgkn$$l F !D 
 505$-@@&<%=".>>$8#9 %&#.B*CC/4J0K/LLvwz  |P  xQ  wR  R[  \  doo';<<)*c$//2F2F.GG 01G0HcRhNiMj  kC  DG  HL  HW  HW  H\  H\  D]  C^  ^K  LO  PT  P_  P_  Pd  Pd  Le  Kf  fg  h  46JKJE3| .ug5ijminnop  s{ #;E7B[!\]]Sy #9#>X!YZZ LG pHs   5\\c                     [        [        X-  5      U5      n[        X-
  S5      nX&U R                  R                  -  S  nX!U-
  4$ )Nr   )minintmaxrN   order)rq   r?   rA   r  r@   init_timestept_starts          r<   get_timesteps7AnimateDiffVideoToVideoControlNetPipeline.get_timesteps  sP    C 3 >?ATU)91=(<(<<>?	777r>   r/   Fr   r   r   num_channels_latentsr   timestepr   r@   r2   r8   	add_noisec                    U
c  UR                   S   OU
R                   S   nUUUX R                  -  X0R                  -  4n[        U	[        5      (       a*  [	        U	5      U:w  a  [        S[	        U	5       SU S35      eU
GcZ  U R                  R                  R                  (       a7  UR                  5       nU R                  R                  [        R                  S9  [        U	[        5      (       a@  [        U5       Vs/ s H)  nU R                  X   X   U5      R                  S5      PM+     nnO1U Vs/ s H$  nU R                  UX5      R                  S5      PM&     nn[        R                   " USS9nU R                  R                  R                  (       a  U R                  R                  U5        UR                  U5      nU R                  R                  R"                  U-  nUUR                   S   :  a7  UUR                   S   -  S:X  a!  S	U S
UR                   S    S3n[        U5      eUUR                   S   :  a5  UUR                   S   -  S:w  a  [        SUR                   S    SU S35      e[        R                   " U/SS9n[%        UR                   XUS9nU R&                  R)                  UUU5      R+                  SSSSS5      n
U
$ XR                   :w  a  [        SU< SU
R                   < 35      eU
R                  XS9n
U(       a'  [%        XXS9nU R&                  R)                  U
UU5      n
U
$ s  snf s  snf )Nr/   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   r   zYou have passed z# text prompts (`prompt`), but only zp initial images (`image`). Please make sure to update your script to pass as many initial images as text promptsz'Cannot duplicate `image` of batch size z to z text prompts.)r2   r@   r   r   r   z!`latents` expected to have shape=z, but found latents.shape=)r   rb   rg   ri   rM   rE   r[   rm   force_upcastr   r   r   float32r   r   	unsqueezer   r   r(   rN   r  r   )rq   r   r   r   r  r   r  r   r@   r2   r8   r   r  r   r   r   init_latentsviderror_messagenoises                       r<   prepare_latents9AnimateDiffVideoToVideoControlNetPipeline.prepare_latents  sF    (/U[[^GMM!<L
 +++***
 i&&3y>Z+GA#i.AQ R&<'gi 
 ?xx++%--0)T** #:. . %%eh	>OPZZ[\].   
 nssmrfi 1 1#y T ^ ^_` amrs 99\q9L xx++E"'??51L88??99LHLL..q11j<CUCUVWCX6X\]6] 'zl2UVbVhVhijVkUl m   !//l0033
\EWEWXYEZ8Z^_8_ =l>P>PQR>S=TTXYcXddrs   %yy,Q? !3!3y_deEnn..|UHMUUVWYZ\]_`bcdG  % #EuhFaSZS`S`Rb!cddjjj5G$U\..227E8LW 
  ts   0M	9+Mc
                 |   U R                   R                  XUS9R                  [        R                  S9nUR                  SSSSS5      R                  SS5      nUR                  S   n
U
S:X  a  UnOUnUR                  USS9nUR                  XgS	9nU(       a!  U	(       d  [        R                  " U/S-  5      nU$ )
Nr   r   r  r   r*   r/   r   r   r   r   )
rp   preprocess_videor   r   r  r   flattenr   r   r   )rq   r   r   r   r   num_videos_per_promptr@   r   r   
guess_modevideo_batch_size	repeat_bys               r<   prepare_conditioning_framesEAnimateDiffVideoToVideoControlNetPipeline.prepare_conditioning_framesT  s     ,,==eZ_=`cc-- d 
 aAq!,44Q: ;;q>q "I .I''	q'94&zIIugk*Er>   c                     U R                   $ r   _guidance_scalerq   s    r<   guidance_scale8AnimateDiffVideoToVideoControlNetPipeline.guidance_scalet  s    ###r>   c                     U R                   $ r   )
_clip_skipr3  s    r<   rt   3AnimateDiffVideoToVideoControlNetPipeline.clip_skipx      r>   c                      U R                   S:  $ )Nr/   r1  r3  s    r<   r   EAnimateDiffVideoToVideoControlNetPipeline.do_classifier_free_guidance  s    ##a''r>   c                     U R                   $ r   )_cross_attention_kwargsr3  s    r<   cross_attention_kwargs@AnimateDiffVideoToVideoControlNetPipeline.cross_attention_kwargs  s    +++r>   c                     U R                   $ r   )_num_timestepsr3  s    r<   num_timesteps7AnimateDiffVideoToVideoControlNetPipeline.num_timesteps  s    """r>   c                     U R                   $ r   )
_interruptr3  s    r<   	interrupt3AnimateDiffVideoToVideoControlNetPipeline.interrupt  r9  r>   2   g      @g?pilTr   r?   enforce_inference_stepsrA   rB   r4  r  r   r*  r   r   r   r   output_typereturn_dictr>  r  r+  r  r	  callback_on_step_endr  c                     [        U R                  5      (       a  U R                  R                  OU R                  n [        U[        5      (       d%  [        U[        5      (       a  [        U5      U/-  nO[        U[        5      (       d%  [        U[        5      (       a  [        U5      U/-  nOb[        U[        5      (       dM  [        U[        5      (       d8  [        U [        5      (       a  [        U R                  5      OSn!U!U/-  U!U/-  nnU=(       d-    U R                  R                  R                  U R                  -  nU=(       d-    U R                  R                  R                  U R                  -  nSnU R                  UU
UUUUUUUUUUUUUUS9  Xl        UU l        UU l        SU l        Ub  [        U["        [$        45      (       a  Sn"O3Ub!  [        U[        5      (       a  [        U5      n"OUR&                  S   n"U R(                  n#U R*                  n$U(       dG  [-        U R.                  UU#Xx5      u  puU R1                  XWU
U#5      u  puUSS R3                  U"U-  5      n%OD[5        XZ-  5      n&[-        U R.                  U&U#Xx5      u  nn&Xu* S nUSS R3                  U"U-  5      n%Uc?  U R6                  R9                  XUS9nUR;                  SSSSS	5      nUR=                  U#U$S
9nU R                  R                  R>                  n'U RA                  UUUU'U"U-  U%U$U#UUUUS9nU RB                  b  U RB                  RE                  SS5      OSn(UR&                  S   n)U RF                  (       a0  U RI                  UU)U#UU RJ                  UUUU(U RL                  S9
u  nnOgU RO                  UU#UU RJ                  UUUU(U RL                  S9	u  nnU RJ                  (       a  [P        RR                  " UU/5      nURU                  U)SS9nUc  Ub"  U RW                  UUU#U"U-  U RJ                  5      n*[        U [        5      (       a.  [        U[X        5      (       a  U/[        U R                  5      -  n[        U [Z        5      (       a  U R                  R\                  O"U R                  S   R                  R\                  n+U=(       d    U+n/ n,[_        [        U5      5       H  n-[a        UU5       V.V/s/ s H>  u  n.n/S[Y        U-[        U5      -  U.:  =(       d    U-S-   [        U5      -  U/:  5      -
  PM@     n0n.n/U,Rc                  [        U [Z        5      (       a  U0S   OU05        M     [        U [Z        5      (       a2  U Re                  UUUU"U-  U)-  UU#U R*                  U RJ                  US9	nOg[        U [        5      (       aP  / n1U HE  n2U Re                  U2UUU"U-  U)-  UU#U R*                  U RJ                  US9	n3U1Rc                  U35        MG     U1nO eU Rg                  X5      n4Uc  Ub  SW*0OSn5U Rh                  (       a  U Rj                  OSn6[_        U65       GH  n7U Rh                  (       aB  U Rm                  UU7UU#UR*                  U5      u  p[        U5      nU R1                  XWU
U#5      u  pu[        U5      U l7        [        U5      XPR.                  Rp                  -  -
  n8U Rs                  U Rn                  S9 n9[u        U5       GH  u  n-n:U Rv                  (       a  M  U RJ                  (       a  [P        RR                  " U/S-  5      OUn;U R.                  Ry                  U;U:5      n;U(       aD  U RJ                  (       a3  Un<U R.                  Ry                  U<U:5      n<UR{                  S5      S   n=OU;n<Un=[        U,U-   [        5      (       a(  [a        UU,U-   5       V>V.s/ s H  u  n>n.U>U.-  PM     n?n>n.O$Un@[        U@[        5      (       a  W@S   n@W@U,U-   -  n?[P        R|                  " U<SS5      n<U<R                  SU<R&                  S   U<R&                  S   U<R&                  S	   45      n<U R                  U<U:U=UU?USS9u  nAnBU R                  U;U:UU RB                  U5UAUBS9R                  nCU RJ                  (       a  WCR{                  S5      u  nDnEUDU	UEUD-
  -  -   nCU R.                  R                  " WCU:U40 U4D6R                  nUb\  0 nFU H  nG[        5       UG   WFUG'   M     U" U U-U:WF5      nHUHR                  SU5      nUHR                  SU5      nUHR                  SU5      nU-[        U5      S-
  :X  d)  U-S-   U8:  a0  U-S-   U R.                  Rp                  -  S:X  a  U9R                  5         [        (       d  GM  [        R                  " 5         GM     SSS5        GM     US:X  a  UnO,U R                  UU5      nIU R6                  R                  UIUS9nU R                  5         U(       d  U4$ [        US9$ s  sn/n.f s  sn.n>f ! , (       d  f       GM  = f)u  
The call function to the pipeline for generation.

Args:
    video (`List[PipelineImageInput]`):
        The input video to condition the generation on. Must be a list of images/frames of the video.
    prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts to guide image generation. If not defined, you need to pass `prompt_embeds`.
    height (`int`, *optional*, defaults to `self.unet.config.sample_size * self.vae_scale_factor`):
        The height in pixels of the generated video.
    width (`int`, *optional*, defaults to `self.unet.config.sample_size * self.vae_scale_factor`):
        The width in pixels of the generated video.
    num_inference_steps (`int`, *optional*, defaults to 50):
        The number of denoising steps. More denoising steps usually lead to a higher quality videos at the
        expense of slower inference.
    timesteps (`List[int]`, *optional*):
        Custom timesteps to use for the denoising process with schedulers which support a `timesteps` argument
        in their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is
        passed will be used. Must be in descending order.
    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.
    strength (`float`, *optional*, defaults to 0.8):
        Higher strength leads to more differences between original video and generated video.
    guidance_scale (`float`, *optional*, defaults to 7.5):
        A higher guidance scale value encourages the model to generate images closely linked to the text
        `prompt` at the expense of lower image quality. Guidance scale is enabled when `guidance_scale > 1`.
    negative_prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts to guide what to not include in image generation. If not defined, you need to
        pass `negative_prompt_embeds` instead. Ignored when not using guidance (`guidance_scale < 1`).
    eta (`float`, *optional*, defaults to 0.0):
        Corresponds to parameter eta (η) from the [DDIM](https://huggingface.co/papers/2010.02502) paper. Only
        applies to the [`~schedulers.DDIMScheduler`], and is ignored in other schedulers.
    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 video
        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`. Latents should be of shape
        `(batch_size, num_channel, num_frames, height, width)`.
    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.
    ip_adapter_image: (`PipelineImageInput`, *optional*):
        Optional image input to work with IP Adapters.
    ip_adapter_image_embeds (`List[torch.Tensor]`, *optional*):
        Pre-generated image embeddings for IP-Adapter. It should be a list of length same as number of
        IP-adapters. Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should
        contain the negative image embedding if `do_classifier_free_guidance` is set to `True`. If not
        provided, embeddings are computed from the `ip_adapter_image` input argument.
    conditioning_frames (`List[PipelineImageInput]`, *optional*):
        The ControlNet input condition to provide guidance to the `unet` for generation. If multiple
        ControlNets are specified, images must be passed as a list such that each element of the list can be
        correctly batched for input to a single ControlNet.
    output_type (`str`, *optional*, defaults to `"pil"`):
        The output format of the generated video. Choose between `torch.Tensor`, `PIL.Image` or `np.array`.
    return_dict (`bool`, *optional*, defaults to `True`):
        Whether or not to return a [`AnimateDiffPipelineOutput`] instead of a plain tuple.
    cross_attention_kwargs (`dict`, *optional*):
        A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
        [`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
    controlnet_conditioning_scale (`float` or `List[float]`, *optional*, defaults to 1.0):
        The outputs of the ControlNet are multiplied by `controlnet_conditioning_scale` before they are added
        to the residual in the original `unet`. If multiple ControlNets are specified in `init`, you can set
        the corresponding scale as a list.
    guess_mode (`bool`, *optional*, defaults to `False`):
        The ControlNet encoder tries to recognize the content of the input image even if you remove all
        prompts. A `guidance_scale` value between 3.0 and 5.0 is recommended.
    control_guidance_start (`float` or `List[float]`, *optional*, defaults to 0.0):
        The percentage of total steps at which the ControlNet starts applying.
    control_guidance_end (`float` or `List[float]`, *optional*, defaults to 1.0):
        The percentage of total steps at which the ControlNet stops applying.
    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`, *optional*):
        A function that calls at the end of each denoising steps during the inference. The function is called
        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.
    decode_chunk_size (`int`, defaults to `16`):
        The number of frames to decode at a time when calling `decode_latents` method.

Examples:

Returns:
    [`pipelines.animatediff.pipeline_output.AnimateDiffPipelineOutput`] or `tuple`:
        If `return_dict` is `True`, [`pipelines.animatediff.pipeline_output.AnimateDiffPipelineOutput`] is
        returned, otherwise a `tuple` is returned where the first element is a list with the generated frames.
r/   )r   r  r   r   r   rY   rZ   r   r   r8   r   r   r  r  r  r	  FNr   r'  r*   r   r   r   )r   r   r   r  r   r  r   r@   r2   r8   r   r  scale)
r   r   r@   r*  r   r   rY   rZ   rs   rt   )rY   rZ   rs   rt   )repeatsr   r   )	r   r   r   r   r*  r@   r   r   r+  r   )totalr|   )encoder_hidden_statescontrolnet_condconditioning_scaler+  rL  )rR  r>  added_cond_kwargsdown_block_additional_residualsmid_block_additional_residualr8   rY   rZ   latent)r   rK  )frames)Mr'   r_   r  rg   ri   rM   r   r   r^   rm   sample_sizerb   r  r2  r7  r=  rE  r   r   r   _execution_devicer   rR   rN   r  r   r  ro   r(  r   r   in_channelsr$  r>  getfree_noise_enabled_encode_prompt_free_noiser   rt   r   r   r   r   r   r   r   global_pool_conditionsr   r   r   r.  r   free_init_enabled_free_init_num_iters_apply_free_initrA  r  progress_barr   rF  scale_model_inputr   	transposer   r6   r   prev_samplelocalspopupdateXLA_AVAILABLExm	mark_stepr   postprocess_videomaybe_free_model_hooksr0   )Jrq   r   r   r   r   r?   rJ  rA   rB   r4  r  r   r*  r   r2   r8   rY   rZ   r   r   r   rK  rL  r>  r  r+  r  r	  rt   rM  r  r   r_   multr   r@   r   latent_timestepdenoising_inference_stepsr  text_encoder_lora_scaler   r   r`  controlnet_keepr   sekeepscond_prepared_videosframe_prepared_videor   rU  num_free_init_itersfree_init_iternum_warmup_stepsrd  tlatent_model_inputcontrol_model_inputcontrolnet_prompt_embedsc
cond_scalecontrolnet_cond_scaledown_block_res_samplesmid_block_res_sample
noise_prednoise_pred_uncondnoise_pred_textcallback_kwargsr   callback_outputsvideo_tensorsJ                                                                             r<   __call__2AnimateDiffVideoToVideoControlNetPipeline.__call__  s
   N 3ET__2U2UT__..[_[j[j
 0$77JG[]a<b<b%()=%>BXAY%Y"0$77JG]_c<d<d#&'=#>BVAW#W 2D99*MacgBhBh+5jBV+W+W3z']^D.//,-- %9" O499++77$:O:OOM))558M8MM ! 	+'#9 3-$;/Q*G#9!5! 	 	
&  .#'=$ *Vc4["A"AJJvt$<$<VJ&,,Q/J''

 '-? 3VY.*I .2-?-?@S`hjp-q*I'm22:@U3UVO(+,?,J(K%3E 96940I0 ""6"78I'm22:@U3UVO ?((99%V[9\EMM!Q1a0EHHF%H8E#yy//;;&&!5!$99$/- ' 
" ?C>Y>Y>eD''++GT:ko 	  ]]1%
""484R4R%&;,0,L,L /+'=2.. 5S 51M1 594F4F%00+'=2.. 5G 
51M1 // %		+A=*Q R);;JTU;VM '+B+N?? '2200L j"677JGdfk<l<l-J,KcR\RaRaNb,b) *o66 44#**AA 	
  9#9
s9~&A   68LMMDAq eAI.2Rq1uI6NQR6RSSM   ""z*o/V/V58\ab ' j/22"&"B"B)%(==
J&; &&,0,L,L% #C 
# 
$899#% -!%!A!A !),AAJN*?!$**040P0P) "B 
" %++N; . #75 !::9J
  +/F/R \* 	 <@;Q;Qd77WX#$78N%%%)%:%:^-@&'--Yb&" '*)n#151C1CDWdlnt1u.	"%i.D"9~0CnnFZFZ0ZZ "")<)<"=%i0DAq~~  FJEeEeG9q=)Akr&)-)I)IJ\^_)`&!d&F&F.5+.2nn.N.NObde.f+3@3F3Fq3I!3L0.@+3@0!/!"4d;;8;<Y[jkl[m8n%o8n1a!e8n
%o
0M-%&;TBB4I!4L1%:_Q=O%O
*///:MqRS*T'*=*E*E066q9;N;T;TUV;WYlYrYrstYuv+' DH??+.F(;+5#-$) DS D@*,@ "&*.;/3/J/J*;8N6J "+ " f  77=G=M=Ma=P:)?%6?]nKn9o%o
 #nn11*a^L]^jjG+7*,!CA17!OA. "D+?aO+\("2"6"6y'"J(8(<(<_m(\1A1E1EF^`v1w. C	NQ..AE=M3MSTWXSX\`\j\j\p\pRptuRu$++-$}U 1 >= 9v ("E..w8IJL((::[f:gE 	##%8O(66o` &p' >=s-   AiC(i(=i"G	i(i("i((
i8	)	r7  r=  r2  rE  r   rA  rp   rb   ro   )NN)NNNNNr   )r   )NNNNNNNNNr   r   r   )N@   r  r   r/   NNNNNr   F)FF)?__name__
__module____qualname____firstlineno____doc__model_cpu_offload_seq_optional_componentsr   r   r   r   r	   r   r   r   r   r   r   r   r   r!   r    r   r   r   r
   r   rf   r   r   r   r   r  r   r   r   r   r   r   r  r  r   r@   	Generatorboolr$  r.  propertyr4  rt   r   r>  rB  rF  no_gradr   r   r   r   r   r  __static_attributes____classcell__)rL   s   @r<   rT   rT      s   @ EST$ 157;#)
)
 $)
 !	)

 (/9:)
 &)
 /4+@%BXZnno)
  "+')
)
  .!)
" 5#)
 )
d 049=&*#'t5  -t5 !) 6t5 UOt5 C=t5n52+'\" "U\\ " &!.  # $+/&)" #h[V8 )-$%"&'+)-MQ*.!#P%P P 	P
 "P P 3-P $P &P E%//43H"HIJP %,,'P P P 
Px %*@ $ $   ( ( , , # #   ]]_ 1526 $##%(-)-(, #;?/0MQ*.049=9=@DBF%* ;?CF <?:=#'KO9B!#Ay7D+,-y7 sDI~./y7 	y7
 }y7 !y7 "&y7 DI&y7 e%y7 y7 y7 "%T#Y"78y7  (}y7 y7 E%//43H"HIJy7  %,,'!y7"  -#y7$ !) 6%y7& ##56'y7( "*$u||*<!=)y7* &d+=&>?+y7, c]-y7. /y70 !)c3h 81y72 (-UDK-?'@3y74 5y76 !&eT%[&8 97y78 $E4;$679y7: C=;y7< 'xc40@$0F'GH=y7> -1I?y7@ Ay7 y7r>   rT   )Nr6   )NNNN)RrG   typingr   r   r   r   r   r   r	   r   torch.nn.functionalnn
functionalr   transformersr
   r   r   r   image_processorr   loadersr   r   r   r   modelsr   r   r   r   r   r   models.lorar   models.unets.unet_motion_modelr   
schedulersr   r   r   r   r    r!   utilsr"   r#   r$   r%   r&   utils.torch_utilsr'   r(   ro   r)   free_init_utilsr+   free_noise_utilsr,   pipeline_utilsr-   r.   pipeline_outputr0   torch_xla.core.xla_modelcore	xla_modelrl  rk  
get_loggerr  r   EXAMPLE_DOC_STRINGr   r  r   r=   r  r@   r   rR   rT   rD   r>   r<   <module>r     sR    D D D    h h 1 w w  : ;  o n A - + 8 D 6 ))MM			H	%= D ck
TLL
T-5eoo-F
T\_
T  *.15%)$(8*!#8* U3,-.8* S	"	8*
 T%[!8*vB7"B7r>   