
    +h3                        S SK r S SKJr  S SKJrJrJrJrJrJ	r	  S SK
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  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&J'r'J(r(  \" 5       (       a  S SK)J*s  J+r,  Sr-OSr-\R\                  " \/5      r0Sr1\ " S S\5      5       r2 " S S\&\'\(5      r3S\	\Rh                  \\Rh                     4   4S jr5S\	\Rh                  \\Rh                     \Rl                  Rl                  \\Rl                  Rl                     4   S\\7\74   4S jr8S\	\Rh                  \\Rh                     \Rl                  Rl                  \\Rl                  Rl                     4   S\\7\74   4S jr9g)    N)	dataclass)AnyDictListOptionalTupleUnion)CLIPImageProcessorCLIPTextModelCLIPTokenizerCLIPVisionModelWithProjection   )PipelineImageInputVaeImageProcessor)AutoencoderKL)I2VGenXLUNet)DDIMScheduler)
BaseOutputis_torch_xla_availableloggingreplace_example_docstring)randn_tensor)VideoProcessor   )DeprecatedPipelineMixinDiffusionPipelineStableDiffusionMixinTFa  
    Examples:
        ```py
        >>> import torch
        >>> from diffusers import I2VGenXLPipeline
        >>> from diffusers.utils import export_to_gif, load_image

        >>> pipeline = I2VGenXLPipeline.from_pretrained(
        ...     "ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16"
        ... )
        >>> pipeline.enable_model_cpu_offload()

        >>> image_url = (
        ...     "https://huggingface.co/datasets/diffusers/docs-images/resolve/main/i2vgen_xl_images/img_0009.png"
        ... )
        >>> image = load_image(image_url).convert("RGB")

        >>> prompt = "Papers were floating in the air on a table in the library"
        >>> negative_prompt = "Distorted, discontinuous, Ugly, blurry, low resolution, motionless, static, disfigured, disconnected limbs, Ugly faces, incomplete arms"
        >>> generator = torch.manual_seed(8888)

        >>> frames = pipeline(
        ...     prompt=prompt,
        ...     image=image,
        ...     num_inference_steps=50,
        ...     negative_prompt=negative_prompt,
        ...     guidance_scale=9.0,
        ...     generator=generator,
        ... ).frames[0]
        >>> video_path = export_to_gif(frames, "i2v.gif")
        ```
c                       \ rS rSr% Sr\\R                  \R                  \
\
\R                  R                        4   \S'   Srg)I2VGenXLPipelineOutputS   a  
 Output class for image-to-video pipeline.

Args:
     frames (`torch.Tensor`, `np.ndarray`, or List[List[PIL.Image.Image]]):
         List of video outputs - It can be a nested list of length `batch_size,` with each sub-list containing
         denoised
 PIL image sequences of length `num_frames.` It can also be a NumPy array or Torch tensor of shape
`(batch_size, num_frames, channels, height, width)`
frames N)__name__
__module____qualname____firstlineno____doc__r	   torchTensornpndarrayr   PILImage__annotations____static_attributes__r"       j/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/i2vgen_xl/pipeline_i2vgen_xl.pyr   r   S   s5    	 %,,

Dciioo1F,GGHHr0   r   c            ,         ^  \ rS rSrSr SrS\S\S\S\	S\
S	\S
\4U 4S jjr\S 5       r\S 5       r    S+S\\R&                     S\\R&                     S\\   4S jjrS rS,S jrS r   S-S jrS r S,S jr\R8                  " 5       \" \5                          S.S\\ \!\    4   S\"S\\   S\\   S\\   S\S\S\#S \\\ \!\    4      S!\#S"\\   S#\\   S$\\\RH                  \!\RH                     4      S%\\R&                     S\\R&                     S\\R&                     S&\\    S'\%S(\\&\ \'4      S\\   4(S) jj5       5       r(S*r)U =r*$ )/I2VGenXLPipelinec   z0.33.1z&text_encoder->image_encoder->unet->vaevaetext_encoder	tokenizerimage_encoderfeature_extractorunet	schedulerc           
        > [         TU ]  5         U R                  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S9U l
        g )N)r5   r6   r7   r8   r9   r:   r;   r5   r         F)vae_scale_factor	do_resize)super__init__register_modulesgetattrlenr5   configblock_out_channelsr?   r   video_processor)	selfr5   r6   r7   r8   r9   r:   r;   	__class__s	           r1   rB   I2VGenXLPipeline.__init__~   s     	%'/ 	 	
 W^^bdikoVpVpc$((//*L*L&MPQ&Q Rvw-t?T?T`efr0   c                     U R                   $ N_guidance_scalerI   s    r1   guidance_scaleI2VGenXLPipeline.guidance_scale   s    ###r0   c                      U R                   S:  $ )Nr=   rN   rP   s    r1   do_classifier_free_guidance,I2VGenXLPipeline.do_classifier_free_guidance   s    ##a''r0   prompt_embedsnegative_prompt_embeds	clip_skipc                 	   Ub  [        U[        5      (       a  SnO3Ub!  [        U[        5      (       a  [        U5      nOUR                  S   nUGc  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                  R                   (       a  U	R"                  R%                  U5      nOSnUc%  U R                  U
R%                  U5      US9nUS   nOQU R                  U
R%                  U5      USS9nUS
   US-   *    nU R                  R&                  R)                  U5      nU R                  b  U R                  R*                  nO0U R,                  b  U R,                  R*                  nOUR*                  nUR%                  XS9nUR                  u  nnnUR/                  SUS5      nUR1                  X-  US
5      nU R2                  (       Ga  UGc  Uc  S/U-  nOUb;  [5        U5      [5        U5      La$  [7        S[5        U5       S[5        U5       S35      e[        U[        5      (       a  U/nO2U[        U5      :w  a!  [9        SU S[        U5       SU SU S3	5      eUnUR                  S   nU R                  USUSSS9n[        U R                  R                  S5      (       aA  U R                  R                  R                   (       a  UR"                  R%                  U5      nOSnUc/  U R                  UR                  R%                  U5      US9nUS   nO[U R                  UR                  R%                  U5      USS9nUS
   US-   *    nU R                  R&                  R)                  U5      nU R2                  (       aF  UR                  S   nUR%                  XS9nUR/                  SUS5      nUR1                  X-  US
5      nXV4$ )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_videos_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.
    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)paddingrZ   
truncationreturn_tensorslongest)r\   r^   z\The following part of your input was truncated because CLIP can only handle sequences up to z	 tokens: use_attention_mask)attention_mask)rb   output_hidden_states)dtypedevice 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`.)
isinstancestrlistrE   shaper7   model_max_length	input_idsr(   equalbatch_decodeloggerwarninghasattrr6   rF   ra   rb   to
text_modelfinal_layer_normrd   r:   repeatviewrT   type	TypeError
ValueError)rI   promptre   num_videos_per_promptnegative_promptrV   rW   rX   
batch_sizetext_inputstext_input_idsuntruncated_idsremoved_textrb   prompt_embeds_dtypebs_embedseq_len_uncond_tokensrZ   uncond_inputs                        r1   encode_promptI2VGenXLPipeline.encode_prompt   s   J *VS"9"9JJvt$<$<VJ&,,Q/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%((/B(R,22'1%,,Q0EqI%**8+KWVXY +++0F0N&!#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&,,Q/J>>$%# * L t((//1EFF4K\K\KcKcKvKv!-!<!<!?!?!G!%  )-):): **--f5#1 *; *& *@)B&)-):): **--f5nko *; *& *@)CiRSmDT)U&
 *.):):)E)E)V)VWm)n&++,2215G%;%>%>EX%>%h"%;%B%B1F[]^%_"%;%@%@Acelnp%q"44r0   c           	         [        U R                  R                  5       5      R                  n[	        U[
        R                  5      (       dT  U R                  R                  U5      nU R                  R                  U5      nU R                  USSSSSS9R                  nUR                  X$S9nU R                  U5      R                  nUR                  S5      nUR                  u  pgnUR!                  SUS5      nUR#                  Xc-  US5      nU R$                  (       a-  [
        R&                  " U5      n	[
        R(                  " X/5      nU$ )NTFr[   )imagesdo_normalizedo_center_cropr@   
do_rescaler^   re   rd   r=   r`   )nextr8   
parametersrd   rh   r(   r)   rH   pil_to_numpynumpy_to_ptr9   pixel_valuesrs   image_embeds	unsqueezerk   rv   rw   rT   
zeros_likecat)
rI   imagere   r|   rd   image_embeddingsr   r   r   negative_image_embeddingss
             r1   _encode_imageI2VGenXLPipeline._encode_imageK  sA   T''2245;;%..((55e<E((44U;E **!$ # +  l  4--e4AA+55a8  0551+2216KQO+001QSZ\^_++(-(8(89I(J%$yy*C)VWr0   c                    SU R                   R                  R                  -  U-  nUR                  u  p4pVnUR	                  SSSSS5      R                  X5-  XFU5      nUbs  / n[        SUR                  S   U5       H=  n	U R                   R                  XX-    5      R                  n
UR                  U
5        M?     [        R                  " USS9nO%U R                   R                  U5      R                  nX5S4UR                  SS  -   nUS S S 24   R                  U5      R	                  SSSSS5      nUR                  5       nU$ )Nr=   r   r   r      dimr`   )r5   rF   scaling_factorrk   permutereshaperangedecodesampleappendr(   r   float)rI   latentsdecode_chunk_sizer~   channels
num_framesheightwidthr!   iframer   decode_shapevideos                 r1   decode_latentsI2VGenXLPipeline.decode_latentsk  s.   dhhoo444w>:A--7
j%//!Q1a0889PRZdij(F1gmmA.0ABA4I(JKRRe$ C IIf!,EHHOOG,33E"3ekk!"oEdAg&&|4<<Q1aK r0   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eta	generator)setinspect	signaturer;   stepr   keys)rI   r   r   accepts_etaextra_step_kwargsaccepts_generators         r1   prepare_extra_step_kwargs*I2VGenXLPipeline.prepare_extra_step_kwargs  s     s7#4#4T^^5H5H#I#T#T#Y#Y#[\\'*e$ (3w/@/@ATAT/U/`/`/e/e/g+hh-6k*  r0   c                    US-  S:w  d	  US-  S:w  a  [        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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[        R                  5      (       dW  [        U[        R                  R                  5      (       d-  [        U[        5      (       d  [        S[	        U5       35      eg g g )Nr>   r   z7`height` and `width` have to be divisible by 8 but are z and rg   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.z2`prompt` has to be of type `str` or `list` 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` z``image` has to be of type `torch.Tensor` or `PIL.Image.Image` or `List[PIL.Image.Image]` but is )
rz   rh   ri   rj   rx   rk   r(   r)   r,   r-   )rI   r{   r   r   r   r}   rV   rW   s           r1   check_inputsI2VGenXLPipeline.check_inputs  s    A:?eai1nVW]V^^cdicjjklmm-";08N}o ^0 0  ^ 5w  FC)@)@TZ\`IaIaQRVW]R^Q_`aa&+A+M9/9J K*++]_ 
 $)?)K""&<&B&BB --:-@-@,A B.445Q8  5%,,//uciioo66ud++K="  , 7 0r0   c           
         UR                  US9nU R                  R                  U5      R                  R	                  5       nXPR                  R
                  R                  -  nUR                  S5      n/ n[        US-
  5       HB  nUS-   US-
  -  nUR                  [        R                  " US S 2S S 2S S24   5      U-  5        MD     U(       a+  [        R                  " USS9n[        R                  " XV/SS9nUR                  USSSS5      nU R                  (       a  [        R                  " U/S-  5      nU$ )Nre   r   r=   r   )rs   r5   encodelatent_distr   rF   r   r   r   r   r(   	ones_liker   rv   rT   )	rI   r   re   r   r|   image_latentsframe_position_mask	frame_idxscales	            r1   prepare_image_latents&I2VGenXLPipeline.prepare_image_latents  s     '.::AAC%(F(FF &//2 !zA~.I]zA~6E&&u}Q2A2X7N'ORW'WX / "')),?Q"G!II}&JPQRM &,,-BAq!QO++!II}o&9:Mr0   c
                 0   UUUX@R                   -  XPR                   -  4n
[        U[        5      (       a*  [        U5      U:w  a  [	        S[        U5       SU S35      eU	c  [        XXvS9n	OU	R                  U5      n	XR                  R                  -  n	U	$ )Nz/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   re   rd   )	r?   rh   rj   rE   rz   r   rs   r;   init_noise_sigma)rI   r~   num_channels_latentsr   r   r   rd   re   r   r   rk   s              r1   prepare_latents I2VGenXLPipeline.prepare_latents  s      +++***
 i&&3y>Z+GA#i.AQ R&<'gi 
 ?"5fZGjj(G NN;;;r0   r{   r   r   r   
target_fpsr   num_inference_stepsrQ   r}   r   r|   r   r   r   output_typereturn_dictcross_attention_kwargsc                 
   U=(       d-    U R                   R                  R                  U R                  -  nU=(       d-    U R                   R                  R                  U R                  -  nU R	                  XX4XU5        Ub  [        U[        5      (       a  SnO3Ub!  [        U[        5      (       a  [        U5      nOUR                  S   nU R                  nXl        U R                  UUUU	UUUS9u  nnU R                  (       a  [        R                  " UU/5      n[!        X$U45      n[#        UU R$                  R&                  S   U R$                  R&                  S   45      nU R)                  UUU5      n[!        X$U45      nU R*                  R-                  U5      R/                  UUR0                  S9nU R3                  UUUUS9nU R                  (       a'  [        R4                  " XU/5      R/                  U5      nO&[        R4                  " U/5      R/                  U5      nUR7                  UU-  S5      R9                  5       nU R:                  R=                  UUS	9  U R:                  R>                  nU R                   R                  R@                  nU RC                  UU-  UUUUUR0                  UUU5	      nU RE                  X5      n[        U5      XpR:                  RF                  -  -
  nU RI                  US
9 n [K        U5       GH  u  n!n"U R                  (       a  [        R                  " U/S-  5      OUn#U R:                  RM                  U#U"5      n#U R                  U#U"UUUUUSS9S   n$U R                  (       a  U$RO                  S5      u  n%n&U%UU&U%-
  -  -   n$UR                  u  nn'n(pCURQ                  SSSSS5      RS                  UU(-  U'XC5      nU$RQ                  SSSSS5      RS                  UU(-  U'XC5      n$U R:                  RT                  " U$U"U40 UD6RV                  nUSSS24   RS                  UU(U'XC5      RQ                  SSSSS5      nU![        U5      S-
  :X  d)  U!S-   U:  a0  U!S-   U R:                  RF                  -  S:X  a  U RY                  5         [Z        (       d  GM  [\        R^                  " 5         GM     SSS5        US:X  a  Un)O)U Ra                  XS9n*U R*                  Rc                  U*US9n)U Re                  5         U(       d  U)4$ [g        U)S9$ ! , (       d  f       Nc= f)u  
The call function to the pipeline for image-to-video generation with [`I2VGenXLPipeline`].

Args:
    prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts to guide image generation. If not defined, you need to pass `prompt_embeds`.
    image (`PIL.Image.Image` or `List[PIL.Image.Image]` or `torch.Tensor`):
        Image or images to guide image generation. If you provide a tensor, it needs to be compatible with
        [`CLIPImageProcessor`](https://huggingface.co/lambdalabs/sd-image-variations-diffusers/blob/main/feature_extractor/preprocessor_config.json).
    height (`int`, *optional*, defaults to `self.unet.config.sample_size * self.vae_scale_factor`):
        The height in pixels of the generated image.
    width (`int`, *optional*, defaults to `self.unet.config.sample_size * self.vae_scale_factor`):
        The width in pixels of the generated image.
    target_fps (`int`, *optional*):
        Frames per second. The rate at which the generated images shall be exported to a video after
        generation. This is also used as a "micro-condition" while generation.
    num_frames (`int`, *optional*):
        The number of video frames to generate.
    num_inference_steps (`int`, *optional*):
        The number of denoising steps.
    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*):
        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.
    num_videos_per_prompt (`int`, *optional*):
        The number of images to generate per prompt.
    decode_chunk_size (`int`, *optional*):
        The number of frames to decode at a time. The higher the chunk size, the higher the temporal
        consistency between frames, but also the higher the memory consumption. By default, the decoder will
        decode all frames at once for maximal quality. Reduce `decode_chunk_size` to reduce memory usage.
    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 `"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 [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] 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).
    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.

Examples:

Returns:
    [`pipelines.i2vgen_xl.pipeline_i2vgen_xl.I2VGenXLPipelineOutput`] or `tuple`:
        If `return_dict` is `True`, [`pipelines.i2vgen_xl.pipeline_i2vgen_xl.I2VGenXLPipelineOutput`] is
        returned, otherwise a `tuple` is returned where the first element is a list with the generated frames.
Nr=   r   )rV   rW   rX   r   r   r   )re   r   r|   r   )totalr   F)encoder_hidden_statesfpsr   r   r   r   r   r   latent)r   )r   r   )r!   )4r:   rF   sample_sizer?   r   rh   ri   rj   rE   rk   _execution_devicerO   r   rT   r(   r   _center_crop_wide_resize_bilinearr9   	crop_sizer   rH   
preprocessrs   rd   r   tensorrv   ravelr;   set_timesteps	timestepsin_channelsr   r   orderprogress_bar	enumeratescale_model_inputchunkr   r   r   prev_sampleupdateXLA_AVAILABLExm	mark_stepr   postprocess_videomaybe_free_model_hooksr   )+rI   r{   r   r   r   r   r   r   rQ   r}   r   r|   r   r   r   rV   rW   r   r   r   rX   r~   re   cropped_imager   resized_imager   
fps_tensorr   r   r   num_warmup_stepsr   r   tlatent_model_input
noise_prednoise_pred_uncondnoise_pred_textchannelr!   r   video_tensors+                                              r1   __call__I2VGenXLPipeline.__call__  s>   z O499++77$:O:OOM))558M8MM 	&Xno *VS"9"9JJvt$<$<VJ&,,Q/J''  . 150B0B!'#9 1C 1
-- ++!II'=}&MNM
 *%@(D22<<WEtG]G]GgGghpGqr
  --mVEZ[ *%A$$//>AAWgWmWmAn22!"7	 3 
 ++z&>?BB6JJzl366v>J&&z4I'I1MSSU
 	$$%8$HNN,,	  $yy//;;&&.. 

 !::9J y>,?..BVBV,VV%89\!),1AEAaAaUYYy1}%=gn"%)^^%E%EFXZ[%\" "YY&*7""/%5+A % ' 	 	
 339C9I9I!9L6%!2^YjGj5k!kJ >E]]:
GVU!//!Q1a8@@fATV]_dm'//1aA>FFzTZGZ\cejs
 ..--j!WZHYZff "$'*22:vwPU^ffghjkmnpqstuI**A9I/IqSTuX\XfXfXlXlNlpqNq '') =LLNK - :R ("E..w.\L((::[f:gE 	##%8O%U33k :9s   F3T:T::
U)rO   r?   rH   )NNNNrM   )NNN)NNi  i      r  2   g      "@Ng        r=   r=   NNNNpilTNr=   )+r#   r$   r%   r&   _last_supported_versionmodel_cpu_offload_seqr   r   r   r   r
   r   r   rB   propertyrQ   rT   r   r(   r)   intr   r   r   r   r   r   r   no_gradr   EXAMPLE_DOC_STRINGr	   ri   r   r   r   	Generatorboolr   r   r  r/   __classcell__)rJ   s   @r1   r3   r3   c   s   
 '& Egg $g !	g
 5g .g g !g2 $ $ ( ( 049=#'g5  -g5 !) 6g5 C=g5R @.!. #/bD nr2 ]]_12 )-$( ##$&#% #;?/0+,MQ*.049=%* ;?#$+e4c49n%e4 "e4 	e4
 }e4 SMe4 e4 !e4 e4 "%T#Y"78e4 e4  (}e4 $C=e4 E%//43H"HIJe4 %,,'e4   -!e4" !) 6#e4$ c]%e4& 'e4( !)c3h 8)e4* C=+e4 3 e4r0   r3   r   c                 ~   [        U [        5      (       a9  [        U S   [        R                  5      (       a  [        R                  " U S5      n [        U [        R                  5      (       aO  U R
                  S:X  a  U R                  S5      n [        R                  " U 5      n[        R                  " U5      nUn U $ )Nr   r   )
rh   rj   r(   r)   r   ndimr   r   pt_to_numpynumpy_to_pil)r   image_numpy	image_pils      r1   _convert_pt_to_pilr    s    %:eAh#E#E		%#%&&::?OOA&E'33E:%22;?	Lr0   
resolutionc                    [        U 5      n [        U [        5      (       a;  U  Vs/ s H,  o"R                  U[        R
                  R                  5      PM.     n nU $ U R                  U[        R
                  R                  5      n U $ s  snf rM   )r  rh   rj   resizer,   r-   BILINEAR)r   r  us      r1   r   r     sp     u%E%CHI5a*cii&8&895I L Z););<L Js   3Bc                    [        U 5      n [        U [        5      (       a  [        U S   R                  S   US   -  U S   R                  S   US   -  5      nU  Vs/ s HX  o3R                  [        UR                  U-  5      [        UR                  U-  5      4[        R                  R                  S9PMZ     n nU S   R                  US   -
  S-  nU S   R                  US   -
  S-  nU  Vs/ s H   o3R                  XEXAS   -   XQS   -   45      PM"     n nU $ [        U R                  S   US   -  U R                  S   US   -  5      nU R                  [        U R                  U-  5      [        U R                  U-  5      4[        R                  R                  S9n U R                  US   -
  S-  nU R                  US   -
  S-  nU R                  XEXAS   -   XQS   -   45      n U $ s  snf s  snf )Nr   r=   )resampler   )r  rh   rj   minsizer  roundr   r   r,   r-   BOXcrop)r   r  r   r  x1y1s         r1   r   r     s    u%E%E!HMM!$z!}4eAhmmA6FTU6VWpuvpukl5E!12E!((e:K4LMX[XaXaXeXefpuv Ahnnz!},2Ahoo
1-!3SXYSXam!3RQ-5GHISXYEJJqMJqM15::a=:a=3PQeEKK5$895QVAV;WXcfclclcpcpqkkJqM)a/llZ]*q0

BBA$6]8JKL w
 Zs   AG/2'G4):r   dataclassesr   typingr   r   r   r   r   r	   numpyr*   r,   r(   transformersr
   r   r   r   image_processorr   r   modelsr   models.unets.unet_i2vgen_xlr   
schedulersr   utilsr   r   r   r   utils.torch_utilsr   rH   r   pipeline_utilsr   r   r   torch_xla.core.xla_modelcore	xla_modelr   r   
get_loggerr#   rp   r  r   r3   r)   r  r-   r  r   r   r"   r0   r1   <module>r5     ss    ! : :  
  h h D # 7 '  . - ] ] ))MM			H	% D IZ I IB
4B
4ReELL$u||2D$DE 
tELL1399??DDYYZ
hmnqsvnvhw
tELL1399??DDYYZhmnqsvnvhwr0   