
    +h                        S SK r S SKrS SKrS SKJr  S SKJrJrJ	r	J
r
Jr  S SK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JrJrJr  SS	KJ r   S
SK!J"r"J#r#  \" 5       (       a  S SK$J%s  J&r'  Sr(OSr(\RR                  " \*5      r+\" 5       (       a  S SK,J-r-  \" 5       (       a  S SK.r.Sr/0 SSS/_SSS/_SSS/_SSS/_SSS/_SSS/_SSS /_S!S"S#/_S$S"S%/_S&S"S'/_S(S)S'/_S*S)S+/_S,S-S./_S/S-S0/_S1S2S0/_S3S2S4/_S5S6S4/_0 S7S6S8/_S9S8S8/_S:S8S6/_S;S4S6/_S<S4S2/_S=S0S2/_S>S0S-/_S?S.S-/_S@S+S)/_SAS'S)/_SBS%S"/_SCS#S"/_SDS S/_SESS/_SFSS/_SGSS/_Er00 SSHS8/_SSHSI/_SSJS2/_SSJSK/_SSJS-/_SSLSM/_SSLS)/_S!SNSO/_S$SNS"/_S&SNSP/_S(SQSP/_S*SQS/_S,SRSS/_S/SRS/_S1STS/_S3STSU/_S5SVSU/_0 S7SVS/_S9SS/_S:SSV/_S;SUSV/_S<SUST/_S=SST/_S>SSR/_S?SSSR/_S@SSQ/_SASPSQ/_SBS"SN/_SCSOSN/_SDS)SL/_SESMSL/_SFSKSJ/_SGS8SH/_Er10 SSWS/_SSWSX/_SSYST/_SSYSZ/_SSYSR/_SS[S\/_SS[SQ/_S!S]S^/_S$S]SN/_S&S]S_/_S(S`S_/_S*S`SL/_S,SaSb/_S/SaSJ/_S1ScSJ/_S3ScSd/_S5SeSd/_0 S7SeSH/_S9SHSH/_S:SHSe/_S;SdSe/_S<SdSc/_S=SJSc/_S>SJSa/_S?SbSa/_S@SLS`/_SAS_S`/_SBSNS]/_SCS^S]/_SDSQS[/_SES\S[/_SFSZSY/_SGSSW/_Er2    SmSf\	\3   Sg\	\\4\Rj                  4      Sh\	\\3      Si\	\\6      4Sj jjr7 " Sk Sl\"5      r8g)n    N)CallableListOptionalTupleUnion)T5EncoderModelT5Tokenizer   )PixArtImageProcessor)AutoencoderKLPixArtTransformer2DModel)DPMSolverMultistepScheduler)BACKENDS_MAPPING	deprecateis_bs4_availableis_ftfy_availableis_torch_xla_availableloggingreplace_example_docstring)randn_tensor   )DiffusionPipelineImagePipelineOutputTF)BeautifulSoupa  
    Examples:
        ```py
        >>> import torch
        >>> from diffusers import PixArtAlphaPipeline

        >>> # You can replace the checkpoint id with "PixArt-alpha/PixArt-XL-2-512x512" too.
        >>> pipe = PixArtAlphaPipeline.from_pretrained("PixArt-alpha/PixArt-XL-2-1024-MS", torch_dtype=torch.float16)
        >>> # Enable memory optimizations.
        >>> pipe.enable_model_cpu_offload()

        >>> prompt = "A small cactus with a happy face in the Sahara desert."
        >>> image = pipe(prompt).images[0]
        ```
z0.25g      @g      @z0.28g      @z0.32g      @g      @z0.33g      @z0.35g      @z0.4g      @g      @z0.42g      @z0.48g      @g      @z0.5g      @z0.52g      @z0.57g      @z0.6g      @z0.68g      @g      @z0.72g      @z0.78g      @z0.82g      @z0.88g      @z0.94g      @z1.0z1.07z1.13z1.21z1.29z1.38z1.46z1.67z1.75z2.0z2.09z2.4z2.5z3.0z4.0g      p@g      @g      r@g      @g      t@g      @g      v@g      @g      @g      x@g      z@g      @g      |@g      @g      ~@g      `@g      }@g      b@g      {@g      d@g      y@g      f@g      w@g      u@g      h@g      j@g      s@g      l@g      q@g      n@num_inference_stepsdevice	timestepssigmasc                    Ub  Ub  [        S5      eUb  S[        [        R                  " U R                  5      R
                  R                  5       5      ;   nU(       d  [        SU R                   S35      eU R                  " S
X2S.UD6  U R                  n[        U5      nX14$ Ub  S[        [        R                  " U R                  5      R
                  R                  5       5      ;   nU(       d  [        SU R                   S35      eU R                  " S
XBS.UD6  U R                  n[        U5      nX14$ U R                  " U4S	U0UD6  U R                  nX14$ )a  
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.

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

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

ValueErrorsetinspect	signatureset_timesteps
parameterskeys	__class__r   len)	schedulerr   r   r   r   kwargsaccepts_timestepsaccept_sigmass           p/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/pixart_alpha/pipeline_pixart_alpha.pyretrieve_timestepsr/      s}   > !3tuu'3w/@/@AXAX/Y/d/d/i/i/k+ll .y/B/B.C Da b  	M)MfM''	!)n )) 
	 C(9(9):Q:Q(R(](](b(b(d$ee.y/B/B.C D_ `  	GvGG''	!)n )) 	 3MFMfM''	))    c            5         ^  \ rS rSrSr\R                  " S5      rSS/rSr	S\
S\S\S\S	\4
U 4S
 jjr          S.S\\\\   4   S\S\S\S\\R.                     S\\R0                     S\\R0                     S\\R0                     S\\R0                     S\S\4S jjrS r    S/S jrS0S jrS rS1S jr\R>                  " 5       \ " \!5                             S2S\\\\   4   S\S\S\\   S\\"   S \"S\\   S!\\   S"\\   S#\"S$\\\RF                  \\RF                     4      S%\\R0                     S\\R0                     S\\R0                     S\\R0                     S\\R0                     S&\\   S'\S(\\$\\\R0                  /S4      S)\S\S*\S\S+\\%\&4   40S, jj5       5       r'S-r(U =r)$ )3PixArtAlphaPipeline   a^  
Pipeline for text-to-image generation using PixArt-Alpha.

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

Args:
    vae ([`AutoencoderKL`]):
        Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
    text_encoder ([`T5EncoderModel`]):
        Frozen text-encoder. PixArt-Alpha uses
        [T5](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5EncoderModel), specifically the
        [t5-v1_1-xxl](https://huggingface.co/PixArt-alpha/PixArt-alpha/tree/main/t5-v1_1-xxl) variant.
    tokenizer (`T5Tokenizer`):
        Tokenizer of class
        [T5Tokenizer](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5Tokenizer).
    transformer ([`PixArtTransformer2DModel`]):
        A text conditioned `PixArtTransformer2DModel` to denoise the encoded image latents. Initially published as
        [`Transformer2DModel`](https://huggingface.co/PixArt-alpha/PixArt-XL-2-1024-MS/blob/main/transformer/config.json#L2)
        in the config, but the mismatch can be ignored.
    scheduler ([`SchedulerMixin`]):
        A scheduler to be used in combination with `transformer` to denoise the encoded image latents.
u5   [#®•©™&@·º½¾¿¡§~\)\(\]\[\}\{\|\\/\*]{1,}	tokenizertext_encoderztext_encoder->transformer->vaevaetransformerr*   c                   > [         TU ]  5         U R                  XX4US9  [        U SS 5      (       a/  S[	        U R
                  R                  R                  5      S-
  -  OSU l        [        U R                  S9U l
        g )N)r4   r5   r6   r7   r*   r6   r         )vae_scale_factor)super__init__register_modulesgetattrr)   r6   configblock_out_channelsr;   r   image_processor)selfr4   r5   r6   r7   r*   r(   s         r.   r=   PixArtAlphaPipeline.__init__  s|     	hq 	 	
 W^^bdikoVpVpc$((//*L*L&MPQ&Q Rvw3TEZEZ[r0   Npromptdo_classifier_free_guidancenegative_promptnum_images_per_promptr   prompt_embedsnegative_prompt_embedsprompt_attention_masknegative_prompt_attention_maskclean_captionmax_sequence_lengthc           
      $   SU;   a  Sn[        SSUSS9  Uc  U R                  nUnUGc	  U R                  XS9nU R                  USUS	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                  " UU5      (       dB  U R                  R                  USS2US-
  S24   5      n[        R                  SU SU 35        UR                  nUR                  U5      nU R                  UR                  U5      US9nUS   nU R                  b  U R                  R                  nO&U R                  b  U R                  R                  nOSnUR                  UUS9nUR
                  u  nnnUR!                  SUS5      nUR#                  UU-  US5      nUR!                  SU5      nUR#                  UU-  S5      nU(       a  Uc  [%        U[&        5      (       a  U/U-  OUnU R                  UU
S9nUR
                  S   nU R                  USUS	S	S	S
S9nUR                  n	U	R                  U5      n	U R                  UR                  R                  U5      U	S9nUS   nU(       ap  UR
                  S   nUR                  UUS9nUR!                  SUS5      nUR#                  UU-  US5      nU	R!                  SU5      n	U	R#                  UU-  S5      n	OSnSn	XhXy4$ )a  
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 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`). For
        PixArt-Alpha, this should be "".
    do_classifier_free_guidance (`bool`, *optional*, defaults to `True`):
        whether to use classifier free guidance or not
    num_images_per_prompt (`int`, *optional*, defaults to 1):
        number of images that should be generated per prompt
    device: (`torch.device`, *optional*):
        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. For PixArt-Alpha, it's should be the embeddings of the ""
        string.
    clean_caption (`bool`, defaults to `False`):
        If `True`, the function will preprocess and clean the provided caption before encoding.
    max_sequence_length (`int`, defaults to 120): Maximum sequence length to use for the prompt.
mask_featureThe use of `mask_feature` is deprecated. It is no longer used in any computation and that doesn't affect the end results. It will be removed in a future version.1.0.0Fstandard_warnN)rM   
max_lengthTpt)paddingrU   
truncationadd_special_tokensreturn_tensorslongest)rW   rZ   r9   zZThe following part of your input was truncated because T5 can only handle sequences up to z	 tokens: )attention_maskr   dtyper   )rW   rU   rX   return_attention_maskrY   rZ   )r   _execution_device_text_preprocessingr4   	input_idsshapetorchequalbatch_decodeloggerwarningr]   tor5   r_   r7   repeatview
isinstancestr)rC   rE   rF   rG   rH   r   rI   rJ   rK   rL   rM   rN   r+   deprecation_messagerU   text_inputstext_input_idsuntruncated_idsremoved_textr_   bs_embedseq_len_uncond_tokensuncond_inputs                            r.   encode_prompt!PixArtAlphaPipeline.encode_prompt/  s   T V# #Fng/BRWX>++F )
 --f-RF..$%#'# ) K )22N"nnVYW[n\ffO$$R(N,@,@,DDU[[N N  $~~::?1j[\n_aNaKa;bc"|9\N<
 %0$>$>!$9$<$<V$D! --n.?.?.GXm-nM)!,M(%%++E)$$**EE%((uV(D,22'1%,,Q0EqI%**86K+KWVXY 5 < <Q@U V 5 : :8F[;[]_ ` '+A+I<FX[<\<\_-8bqM 44]R_4`M&,,Q/J>>$%&*#'# * L .:-H-H*-K-N-Nv-V*%)%6%6&&))&1B` &7 &" &<A%>"&,2215G%;%>%>USY%>%Z"%;%B%B1F[]^%_"%;%@%@LaAacjln%o"-K-R-RSTVk-l*-K-P-PQY\qQqsu-v*%)"-1*5Kkkr0   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)r"   r#   r$   r*   stepr&   r'   )rC   r}   r|   accepts_etaextra_step_kwargsaccepts_generators         r.   prepare_extra_step_kwargs-PixArtAlphaPipeline.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
                 R   US-  S:w  d	  US-  S:w  a  [        SU SU S35      eUb  Ub6  [        U[        5      (       a  US::  a  [        SU S[        U5       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b  Ub  [        SU SU S
35      eUb  Uc  [        S5      eUb  U	c  [        S5      eUb  Ub  UR                  UR                  :w  a&  [        SUR                   SUR                   S35      eUR                  U	R                  :w  a&  [        SUR                   SU	R                   S35      eg g g )Nr:   r   z7`height` and `width` have to be divisible by 8 but are z and .z5`callback_steps` has to be a positive integer but is z	 of type 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 and `negative_prompt_embeds`: z'Cannot forward both `negative_prompt`: zEMust provide `prompt_attention_mask` when specifying `prompt_embeds`.zWMust provide `negative_prompt_attention_mask` when specifying `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`prompt_attention_mask` and `negative_prompt_attention_mask` must have the same shape when passed directly, but got: `prompt_attention_mask` z% != `negative_prompt_attention_mask` )r!   rm   inttypern   listrd   )
rC   rE   heightwidthrG   callback_stepsrI   rJ   rK   rL   s
             r.   check_inputs PixArtAlphaPipeline.check_inputs  sh    A:?eai1nVW]V^^cdicjjklmm"&
>30O0OSaefSfGGW X(), 
 -";08N}o ^0 0  ^ 5w  FC)@)@TZ\`IaIaQRVW]R^Q_`aa"8"D0 9*++]_ 
 &+A+M9/9J K*++]_ 
 $)>)Fdee!-2P2Xvww$)?)K""&<&B&BB --:-@-@,A B.445Q8 
 %**.L.R.RR 55J5P5P4Q R6<<=Q@  S *L$r0   c                   ^ ^ T(       aT  [        5       (       dE  [        R                  [        S   S   R	                  S5      5        [        R                  S5        SmT(       aT  [        5       (       dE  [        R                  [        S   S   R	                  S5      5        [        R                  S5        Sm[        U[        [        45      (       d  U/nS[        4UU 4S jjnU Vs/ s H
  oC" U5      PM     sn$ s  snf )	Nbs4r\   zSetting `clean_caption=True`z#Setting `clean_caption` to False...Fftfytextc                    > T(       a$  TR                  U 5      n TR                  U 5      n U $ U R                  5       R                  5       n U $ N)_clean_captionlowerstrip)r   rM   rC   s    r.   process8PixArtAlphaPipeline._text_preprocessing.<locals>.process  sH    **40**40 K zz|))+Kr0   )
r   rh   ri   r   formatr   rm   tupler   rn   )rC   r   rM   r   ts   ` `  r.   rb   'PixArtAlphaPipeline._text_preprocessing  s    !1!3!3NN+E226==>\]^NN@A!M!2!4!4NN+F3B7>>?]^_NN@A!M$..6D	# 	 	 %))Dq
D)))s   *C>c                 ^
   [        U5      n[        R                  " U5      nUR                  5       R	                  5       n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[        USS9R                  n[
        R                  " SSU5      n[
        R                  " S	SU5      n[
        R                  " S
SU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " SSU5      n[
        R                  " S SU5      n[
        R                  " S!SU5      n[
        R                  " U R                  SU5      n[
        R                  " S"SU5      n[
        R                  " S#5      n[        [
        R                  " X!5      5      S$:  a  [
        R                  " USU5      n[        R                  " U5      n[        R                   " [        R                   " U5      5      n[
        R                  " S%SU5      n[
        R                  " S&SU5      n[
        R                  " S'SU5      n[
        R                  " S(SU5      n[
        R                  " S)SU5      n[
        R                  " S*SU5      n[
        R                  " S+SU5      n[
        R                  " S,SU5      n[
        R                  " S-SU5      n[
        R                  " S.SU5      n[
        R                  " S/S0U5      n[
        R                  " S1S2U5      n[
        R                  " S3SU5      nUR                  5         [
        R                  " S4S5U5      n[
        R                  " S6SU5      n[
        R                  " S7SU5      n[
        R                  " S8SU5      nUR                  5       $ )9Nz<person>personzk\b((?:https?:(?:\/{1,3}|[a-zA-Z0-9%])|[a-zA-Z0-9.\-]+[.](?:com|co|ru|net|org|edu|gov|it)[\w/-]*\b\/?(?!@))) zh\b((?:www:(?:\/{1,3}|[a-zA-Z0-9%])|[a-zA-Z0-9.\-]+[.](?:com|co|ru|net|org|edu|gov|it)[\w/-]*\b\/?(?!@)))zhtml.parser)featuresz
@[\w\d]+\bz[\u31c0-\u31ef]+z[\u31f0-\u31ff]+z[\u3200-\u32ff]+z[\u3300-\u33ff]+z[\u3400-\u4dbf]+z[\u4dc0-\u4dff]+z[\u4e00-\u9fff]+z|[\u002D\u058A\u05BE\u1400\u1806\u2010-\u2015\u2E17\u2E1A\u2E3A\u2E3B\u2E40\u301C\u3030\u30A0\uFE31\uFE32\uFE58\uFE63\uFF0D]+-u   [`´«»“”¨]"u   [‘’]'z&quot;?z&ampz"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} z\d:\d\d\s+$z\\nz
#\d{1,3}\bz	#\d{5,}\bz
\b\d{6,}\bz0[\S]+\.(?:png|jpg|jpeg|bmp|webp|eps|pdf|apk|mp4)z
[\"\']{2,}z[\.]{2,}z\s+\.\s+z	(?:\-|\_)r
   z\b[a-zA-Z]{1,3}\d{3,15}\bz\b[a-zA-Z]+\d+[a-zA-Z]+\bz\b\d+[a-zA-Z]+\d+\bz!(worldwide\s+)?(free\s+)?shippingz(free\s)?download(\sfree)?z\bclick\b\s(?:for|on)\s\w+z9\b(?:png|jpg|jpeg|bmp|webp|eps|pdf|apk|mp4)(\simage[s]?)?z\bpage\s+\d+\bz*\b\d*[a-zA-Z]+\d+[a-zA-Z]+\d+[a-zA-Z\d]*\bu   \b\d+\.?\d*[xх×]\d+\.?\d*\bz
\b\s+\:\s+z: z(\D[,\./])\bz\1 z\s+z^[\"\']([\w\W]+)[\"\']$z\1z^[\'\_,\-\:;]z[\'\_,\-\:\-\+]$z^\.\S+$)rn   ulunquote_plusr   r   resubr   r   bad_punct_regexcompiler)   findallr   fix_texthtmlunescape)rC   captionregex2s      r.   r   "PixArtAlphaPipeline._clean_caption%  s   g,//'*--/'')&&Xw7&&z

 &&w
  -@EE &&G4 &&,b':&&,b':&&,b':&&,b':&&,b':&&,b':&&,b': && L
 &&-sG<&&c73 &&R1&&"g. &&>WM &&W5 &&g. &&G4&&r73&&G4&&LbRYZ &&g6&&dG4&&--tW=&&dG4 L)rzz&*+a/ffVS'2G--(--g 67&&5r7C&&5r7C&&/W=&&=r7K&&6GD&&6GD&&UWY[bc&&*B8&&FgV&&92wG&&w7&&&':&&g.&&3UGD&&)38&&,c7;&&R1}}r0   c	                 V   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Uc  [        XXeS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}   r   r_   )
r   r;   rm   r   r)   r!   r   rj   r*   init_noise_sigma)
rC   
batch_sizenum_channels_latentsr   r   r_   r   r}   latentsrd   s
             r.   prepare_latents#PixArtAlphaPipeline.prepare_latents  s     K4000J$///	
 i&&3y>Z+GA#i.AQ R&<'gi 
 ?"5fZGjj(G NN;;;r0   r   r   r   guidance_scaler   r   r|   r}   r   output_typereturn_dictcallbackr   use_resolution_binningreturnc                    SU;   a  Sn[        SSUSS9  U=(       d-    U R                  R                  R                  U R                  -  nU	=(       d-    U R                  R                  R                  U R                  -  n	U(       a  U R                  R                  R                  S:X  a  [
        nOaU R                  R                  R                  S:X  a  [        nO6U R                  R                  R                  S:X  a  [        nO[        S	5      eXnnU R                  R                  XUS
9u  pU R                  UUU	UUUUUU5	        Ub  [        U[        5      (       a  SnO3Ub!  [        U[        5      (       a  [        U5      nOUR                   S   nU R"                  nUS:  nU R%                  UUUUUUUUUUUS9u  nnnnU(       a-  [&        R(                  " X/SS9n[&        R(                  " UU/SS9n[+        U R,                  UUXE5      u  pCU R                  R                  R.                  n U R1                  UU-  U UU	UR2                  UUU5      nU R5                  X5      n!SSS.n"U R                  R                  R                  S:X  a  [&        R6                  " X/5      R9                  UU-  S5      n#[&        R6                  " [;        X-  5      /5      R9                  UU-  S5      n$U#R=                  UR2                  US9n#U$R=                  UR2                  US9n$U(       a.  [&        R(                  " U#U#/SS9n#[&        R(                  " U$U$/SS9n$U#U$S.n"[?        [        U5      X0R,                  R@                  -  -
  S5      n%U RC                  US9 n&[E        U5       GH  u  n'n(U(       a  [&        R(                  " U/S-  5      OUn)U R,                  RG                  U)U(5      n)U(n*[&        RH                  " U*5      (       d  U)RJ                  RL                  S:H  n+U)RJ                  RL                  S:H  n,[        U*[:        5      (       a/  U+(       d  U,(       a  [&        RN                  O[&        RP                  n-O.U+(       d  U,(       a  [&        RR                  O[&        RT                  n-[&        R6                  " U*/U-U)RJ                  S9n*O7[        U*R                   5      S:X  a  U*S   R=                  U)RJ                  5      n*U*RW                  U)R                   S   5      n*U R                  U)UUU*U"SS9S   n.U(       a  U.RY                  S5      u  n/n0U/UU0U/-
  -  -   n.U R                  R                  RZ                  S-  U :X  a  U.RY                  SSS9S   n.OU.n.US:X  a'  U R,                  R\                  " U.U(U40 U!DSS0D6S   nO&U R,                  R\                  " U.U(U40 U!DSS0D6S   nU'[        U5      S-
  :X  d)  U'S-   U%:  a`  U'S-   U R,                  R@                  -  S:X  a@  U&R_                  5         Ub-  U'U-  S:X  a$  U'[a        U R,                  SS5      -  n1U" U1U(U5        [b        (       d  GM  [d        Rf                  " 5         GM     SSS5        US:X  db  U Rh                  Rk                  XRh                  R                  Rl                  -  SS9S   n2U(       a  U R                  Ro                  U2WW5      n2OUn2US:X  d  U R                  Rq                  U2US9n2U Rs                  5         U(       d  U24$ [u        U2S9$ ! , (       d  f       N= f)u  
Function invoked when calling the pipeline for generation.

Args:
    prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
        instead.
    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`).
    num_inference_steps (`int`, *optional*, defaults to 100):
        The number of denoising steps. More denoising steps usually lead to a higher quality image 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.
    guidance_scale (`float`, *optional*, defaults to 4.5):
        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.
    num_images_per_prompt (`int`, *optional*, defaults to 1):
        The number of images to generate per prompt.
    height (`int`, *optional*, defaults to self.unet.config.sample_size):
        The height in pixels of the generated image.
    width (`int`, *optional*, defaults to self.unet.config.sample_size):
        The width in pixels of the generated image.
    eta (`float`, *optional*, defaults to 0.0):
        Corresponds to parameter eta (η) in the DDIM paper: https://huggingface.co/papers/2010.02502. Only
        applies to [`schedulers.DDIMScheduler`], will be ignored for others.
    generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
        One or a list of [torch generator(s)](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 will ge 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, *e.g.* prompt weighting. If not
        provided, text embeddings will be generated from `prompt` input argument.
    prompt_attention_mask (`torch.Tensor`, *optional*): Pre-generated attention mask for text embeddings.
    negative_prompt_embeds (`torch.Tensor`, *optional*):
        Pre-generated negative text embeddings. For PixArt-Alpha this negative prompt should be "". If not
        provided, negative_prompt_embeds will be generated from `negative_prompt` input argument.
    negative_prompt_attention_mask (`torch.Tensor`, *optional*):
        Pre-generated attention mask for negative text embeddings.
    output_type (`str`, *optional*, defaults to `"pil"`):
        The output format of the generate image. Choose between
        [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` or `np.array`.
    return_dict (`bool`, *optional*, defaults to `True`):
        Whether or not to return a [`~pipelines.stable_diffusion.IFPipelineOutput`] instead of a plain tuple.
    callback (`Callable`, *optional*):
        A function that will be called every `callback_steps` steps during inference. The function will be
        called with the following arguments: `callback(step: int, timestep: int, latents: torch.Tensor)`.
    callback_steps (`int`, *optional*, defaults to 1):
        The frequency at which the `callback` function will be called. If not specified, the callback will be
        called at every step.
    clean_caption (`bool`, *optional*, defaults to `True`):
        Whether or not to clean the caption before creating embeddings. Requires `beautifulsoup4` and `ftfy` to
        be installed. If the dependencies are not installed, the embeddings will be created from the raw
        prompt.
    use_resolution_binning (`bool` defaults to `True`):
        If set to `True`, the requested height and width are first mapped to the closest resolutions using
        `ASPECT_RATIO_1024_BIN`. After the produced latents are decoded into images, they are resized back to
        the requested resolution. Useful for generating non-square images.
    max_sequence_length (`int` defaults to 120): Maximum sequence length to use with the `prompt`.

Examples:

Returns:
    [`~pipelines.ImagePipelineOutput`] or `tuple`:
        If `return_dict` is `True`, [`~pipelines.ImagePipelineOutput`] is returned, otherwise a `tuple` is
        returned where the first element is a list with the generated images
rP   rQ   rR   FrS      @       zInvalid sample size)ratiosNr9   r   g      ?)	rG   rH   r   rI   rJ   rK   rL   rM   rN   )dim)
resolutionaspect_ratior^   )totalr   mpsnpu)encoder_hidden_statesencoder_attention_masktimestepadded_cond_kwargsr   r   orderlatent)r   )r   )images);r   r7   r@   sample_sizer;   ASPECT_RATIO_1024_BINASPECT_RATIO_512_BINASPECT_RATIO_256_BINr!   rB   classify_height_width_binr   rm   rn   r   r)   rd   ra   ry   re   catr/   r*   in_channelsr   r_   r   tensorrk   floatrj   maxr   progress_bar	enumeratescale_model_input	is_tensorr   r   float32float64int32int64expandchunkout_channelsr~   updater?   XLA_AVAILABLExm	mark_stepr6   decodescaling_factorresize_and_crop_tensorpostprocessmaybe_free_model_hooksr   )3rC   rE   rG   r   r   r   r   rH   r   r   r|   r}   r   rI   rK   rJ   rL   r   r   r   r   rM   r   rN   r+   ro   aspect_ratio_binorig_height
orig_widthr   r   rF   latent_channelsr   r   r   r   num_warmup_stepsr   ir   latent_model_inputcurrent_timestepis_mpsis_npur_   
noise_prednoise_pred_uncondnoise_pred_textstep_idximages3                                                      r.   __call__PixArtAlphaPipeline.__call__  s
   \ V# #Fng/BRWXV4++22>>AVAVVT))00<<t?T?TT!&&22c9#8 !!((44:#7 !!((44:#7  !677&,K 00JJ6aqJrMF"!*
	
 *VS"9"9JJvt$<$<VJ&,,Q/J''
 '5s&:# '+"7'#9"7+I' 3  
	
!"* '!II'=&MSTUM$)II/MOd.ekl$m! *<NN/*
&	
 **11==&&..	
 !::9J ,0F""..#5vo6==jK`>`bcdJ <<v~)>(?@GG
UjHjlmnL#]-@-@PJ'??1D1DV?TL*"YY
J'?QG
$yy,)E1M/9< X s9~0CnnFZFZ0ZZ\]^%89\!),1A\UYYy1}%=bi"%)^^%E%EFXZ[%\"#$ '788 066;;uDF/66;;uDF!"2E::28F06&u{{',||5E4Fe\n\u\u'v$)//0A5'7'='@'@ASAZAZ'[$#3#:#:;M;S;STU;V#W  "--&*7+@-&7 % .  
 /9C9I9I!9L6%!2^YjGj5k!kJ ##**771<O!+!1!1!!1!;A!>J!+J '!+"nn11*aqL]qkpqrstG"nn11*aqL]qkpqrstG I**A9I/IqSTuX\XfXfXlXlNlpqNq '')+N0Ba0G#$(K#K 1g6 =LLNo - :t h&HHOOGhhoo.L.L$LZ_O`abcE%,,CCE:WbcEh&((44U4TE 	##%8O"%00U :9s    K] ]
])rB   r;   )
Tr   r9   NNNNNFx   NNNN)Fr   )Nr      NNg      @r9   NNg        NNNNNNpilTNr9   TTr   )*__name__
__module____qualname____firstlineno____doc__r   r   r   _optional_componentsmodel_cpu_offload_seqr	   r   r   r   r   r=   r   rn   r   boolr   r   re   r   Tensorry   r   r   rb   r   r   no_gradr   EXAMPLE_DOC_STRINGr   	Generatorr   r   r   r   __static_attributes____classcell__)r(   s   @r.   r2   r2      s   0 jj	O  (8<\\ %\ 	\
 .\ /\* -1!%&)-049=8<AE##&Elc49n%El &*El 	El
  #El &El  -El !) 6El  (5El )1(>El El !ElP!0 #"'+AH*2pf, ]]_12 )-!#%#" #/0 $#MQ*.048<9=AE%* GK"'+#&1`1c49n%`1 `1 !	`1
 9`1 U`1 `1  (}`1 `1 }`1 `1 E%//43H"HIJ`1 %,,'`1  -`1  (5`1  !) 6!`1" )1(>#`1$ c]%`1& '`1( 8S#u||$<d$BCD)`1* +`1, -`1. !%/`10 !1`14 
"E)	*5`1 3 `1r0   r2   r  )9r   r#   r   urllib.parseparser   typingr   r   r   r   r   re   transformersr   r	   rB   r   modelsr   r   
schedulersr   utilsr   r   r   r   r   r   r   utils.torch_utilsr   pipeline_utilsr   r   torch_xla.core.xla_modelcore	xla_modelr   r   
get_loggerr  rh   r   r   r   r  r   r   r   r   rn   r   r   r/   r2   r    r0   r.   <module>r     sJ     	  9 9  4 3 = 5   . C ))MM			H	% !  "
UFO"
UFO" UFO" UFO	"
 UFO" 
E6?" UFO" UFO" 
E6?" UFO" UFO" 
E6?" UFO" UFO" UFO"  UFO!"" UFO#"$ UFO%"& 
FF'"( VUO)"* VUO+", VUO-". VUO/"0 VUO1"2 VUO3"4 VUO5"6 VUO7"8 
FE?9": VUO;"< 
FE?="> 
FE??"@ 
FE?A"B 
FE?C" H"
UFO"
UEN" UEN" UEN	"
 UEN" 
E5>" UEN" UEN" 
E5>" UEN" UEN" 
E5>" UEN" UEN" UEN"  UEN!"" UEN#"$ UEN%"& 
E5>'"( UEN)"* UEN+", UEN-". UEN/"0 UEN1"2 UEN3"4 UEN5"6 UEN7"8 
E5>9": UEN;"< 
E5>="> 
E5>?"@ 
E5>A"B 
FE?C" H"
UEN"
UEN" UEN" UEN	"
 UEN" 
E5>" UEN" UEN" 
E5>" UEN" UEN" 
E5>" UEN" UEN" UEN"  UEN!"" UEN#"$ UEN%"& 
E5>'"( UEN)"* UEN+", UEN-". UEN/"0 UEN1"2 UEN3"4 UEN5"6 UEN7"8 
E5>9": UEN;"< 
E5>="> 
E5>?"@ 
E5>A"B 
E5>C" P *.15%)$(8*!#8* U3,-.8* S	"	8*
 T%[!8*v_1+ _1r0   